Annotation of loncom/interface/domainprefs.pm, revision 1.199
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.199 ! raeburn 4: # $Id: domainprefs.pm,v 1.198 2013/07/09 00:17:22 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',
1.198 raeburn 2448: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 2449: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2450: coursecredits => 'Credits can be specified for courses',
2451: );
1.198 raeburn 2452: my %staticdefaults = (
2453: anonsurvey_threshold => 10,
2454: uploadquota => 500,
2455: );
1.139 raeburn 2456: if ($position eq 'top') {
2457: %defaultchecked = ('canuse_pdfforms' => 'off');
1.192 raeburn 2458: @toggles = ('canuse_pdfforms');
1.139 raeburn 2459: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2460: \%choices,$itemcount);
1.139 raeburn 2461: } else {
2462: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.198 raeburn 2463: my ($currdefresponder,$def_official_credits,$def_unofficial_credits,%curruploadquota);
1.192 raeburn 2464: my $currusecredits = 0;
1.198 raeburn 2465: my @types = ('official','unofficial','community');
1.139 raeburn 2466: if (ref($settings) eq 'HASH') {
2467: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 2468: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2469: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2470: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2471: }
2472: }
1.192 raeburn 2473: if (ref($settings->{'coursecredits'}) eq 'HASH') {
2474: $def_official_credits = $settings->{'coursecredits'}->{'official'};
2475: $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
2476: if (($def_official_credits ne '') || ($def_unofficial_credits ne '')) {
2477: $currusecredits = 1;
2478: }
2479: }
1.139 raeburn 2480: }
2481: if (!$currdefresponder) {
1.198 raeburn 2482: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 2483: } elsif ($currdefresponder < 1) {
2484: $currdefresponder = 1;
2485: }
1.198 raeburn 2486: foreach my $type (@types) {
2487: if ($curruploadquota{$type} eq '') {
2488: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
2489: }
2490: }
1.139 raeburn 2491: $datatable .=
1.192 raeburn 2492: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2493: $choices{'anonsurvey_threshold'}.
1.139 raeburn 2494: '</span></td>'.
2495: '<td class="LC_right_item"><span class="LC_nobreak">'.
2496: '<input type="text" name="anonsurvey_threshold"'.
2497: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.198 raeburn 2498: '</td></tr>'."\n".
2499: '<tr><td><span class="LC_nobreak">'.
2500: $choices{'uploadquota'}.
2501: '</span></td>'.
2502: '<td align="right" class="LC_right_item">'.
2503: '<table><tr>';
2504: foreach my $type (@types) {
2505: $datatable .= '<td align="center">'.&mt($type).'<br />'.
2506: '<input type="text" name="uploadquota_'.$type.'"'.
2507: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
2508: }
2509: $datatable .= '</tr></table></td></tr>'."\n";
2510: $itemcount += 2;
1.192 raeburn 2511: my $onclick = 'toggleCredits(this.form);';
2512: my $display = 'none';
2513: if ($currusecredits) {
2514: $display = 'block';
2515: }
2516: my $additional = '<div id="credits" style="display: '.$display.'">'.
2517: '<span class="LC_nobreak">'.
2518: &mt('Default credits for official courses [_1]',
2519: '<input type="text" name="official_credits" value="'.
2520: $def_official_credits.'" size="3" />').
2521: '</span><br />'.
2522: '<span class="LC_nobreak">'.
2523: &mt('Default credits for unofficial courses [_1]',
2524: '<input type="text" name="unofficial_credits" value="'.
2525: $def_unofficial_credits.'" size="3" />').
2526: '</span></div>'."\n";
2527: %defaultchecked = ('coursecredits' => 'off');
2528: @toggles = ('coursecredits');
2529: my $current = {
2530: 'coursecredits' => $currusecredits,
2531: };
2532: (my $table,$itemcount) =
2533: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
2534: \%choices,$itemcount,$onclick,$additional);
2535: $datatable .= $table;
1.139 raeburn 2536: }
1.192 raeburn 2537: $$rowtotal += $itemcount;
1.121 raeburn 2538: return $datatable;
1.118 jms 2539: }
2540:
1.137 raeburn 2541: sub print_usersessions {
2542: my ($position,$dom,$settings,$rowtotal) = @_;
2543: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2544: my (%by_ip,%by_location,@intdoms);
2545: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 2546:
2547: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 2548: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 2549: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 2550: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 2551: my $itemcount = 1;
2552: if ($position eq 'top') {
1.152 raeburn 2553: if (keys(%serverhomes) > 1) {
1.145 raeburn 2554: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 2555: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 2556: } else {
1.140 raeburn 2557: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2558: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 2559: }
1.137 raeburn 2560: } else {
1.145 raeburn 2561: if (keys(%by_location) == 0) {
2562: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2563: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 2564: } else {
2565: my %lt = &usersession_titles();
2566: my $numinrow = 5;
2567: my $prefix;
2568: my @types;
2569: if ($position eq 'bottom') {
2570: $prefix = 'remote';
2571: @types = ('version','excludedomain','includedomain');
2572: } else {
2573: $prefix = 'hosted';
2574: @types = ('excludedomain','includedomain');
2575: }
2576: my (%current,%checkedon,%checkedoff);
2577: my @lcversions = &Apache::lonnet::all_loncaparevs();
2578: my @locations = sort(keys(%by_location));
2579: foreach my $type (@types) {
2580: $checkedon{$type} = '';
2581: $checkedoff{$type} = ' checked="checked"';
2582: }
2583: if (ref($settings) eq 'HASH') {
2584: if (ref($settings->{$prefix}) eq 'HASH') {
2585: foreach my $key (keys(%{$settings->{$prefix}})) {
2586: $current{$key} = $settings->{$prefix}{$key};
2587: if ($key eq 'version') {
2588: if ($current{$key} ne '') {
2589: $checkedon{$key} = ' checked="checked"';
2590: $checkedoff{$key} = '';
2591: }
2592: } elsif (ref($current{$key}) eq 'ARRAY') {
2593: $checkedon{$key} = ' checked="checked"';
2594: $checkedoff{$key} = '';
2595: }
1.137 raeburn 2596: }
2597: }
2598: }
1.145 raeburn 2599: foreach my $type (@types) {
2600: next if ($type ne 'version' && !@locations);
2601: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2602: $datatable .= '<tr'.$css_class.'>
2603: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2604: <span class="LC_nobreak">
2605: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2606: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2607: if ($type eq 'version') {
2608: my $selector = '<select name="'.$prefix.'_version">';
2609: foreach my $version (@lcversions) {
2610: my $selected = '';
2611: if ($current{'version'} eq $version) {
2612: $selected = ' selected="selected"';
2613: }
2614: $selector .= ' <option value="'.$version.'"'.
2615: $selected.'>'.$version.'</option>';
2616: }
2617: $selector .= '</select> ';
2618: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2619: } else {
2620: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2621: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2622: ' />'.(' 'x2).
2623: '<input type="button" value="'.&mt('uncheck all').'" '.
2624: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2625: "\n".
2626: '</div><div><table>';
2627: my $rem;
2628: for (my $i=0; $i<@locations; $i++) {
2629: my ($showloc,$value,$checkedtype);
2630: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2631: my $ip = $by_location{$locations[$i]}->[0];
2632: if (ref($by_ip{$ip}) eq 'ARRAY') {
2633: $value = join(':',@{$by_ip{$ip}});
2634: $showloc = join(', ',@{$by_ip{$ip}});
2635: if (ref($current{$type}) eq 'ARRAY') {
2636: foreach my $loc (@{$by_ip{$ip}}) {
2637: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2638: $checkedtype = ' checked="checked"';
2639: last;
2640: }
2641: }
1.138 raeburn 2642: }
2643: }
2644: }
1.145 raeburn 2645: $rem = $i%($numinrow);
2646: if ($rem == 0) {
2647: if ($i > 0) {
2648: $datatable .= '</tr>';
2649: }
2650: $datatable .= '<tr>';
2651: }
2652: $datatable .= '<td class="LC_left_item">'.
2653: '<span class="LC_nobreak"><label>'.
2654: '<input type="checkbox" name="'.$prefix.'_'.$type.
2655: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2656: '</label></span></td>';
1.137 raeburn 2657: }
1.145 raeburn 2658: $rem = @locations%($numinrow);
2659: my $colsleft = $numinrow - $rem;
2660: if ($colsleft > 1 ) {
2661: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2662: ' </td>';
2663: } elsif ($colsleft == 1) {
2664: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 2665: }
1.145 raeburn 2666: $datatable .= '</tr></table>';
1.137 raeburn 2667: }
1.145 raeburn 2668: $datatable .= '</td></tr>';
2669: $itemcount ++;
1.137 raeburn 2670: }
2671: }
2672: }
2673: $$rowtotal += $itemcount;
2674: return $datatable;
2675: }
2676:
1.138 raeburn 2677: sub build_location_hashes {
2678: my ($intdoms,$by_ip,$by_location) = @_;
2679: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2680: (ref($by_location) eq 'HASH'));
2681: my %iphost = &Apache::lonnet::get_iphost();
2682: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2683: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2684: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2685: foreach my $id (@{$iphost{$primary_ip}}) {
2686: my $intdom = &Apache::lonnet::internet_dom($id);
2687: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2688: push(@{$intdoms},$intdom);
2689: }
2690: }
2691: }
2692: foreach my $ip (keys(%iphost)) {
2693: if (ref($iphost{$ip}) eq 'ARRAY') {
2694: foreach my $id (@{$iphost{$ip}}) {
2695: my $location = &Apache::lonnet::internet_dom($id);
2696: if ($location) {
2697: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2698: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2699: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2700: push(@{$by_ip->{$ip}},$location);
2701: }
2702: } else {
2703: $by_ip->{$ip} = [$location];
2704: }
2705: }
2706: }
2707: }
2708: }
2709: foreach my $ip (sort(keys(%{$by_ip}))) {
2710: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2711: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2712: my $first = $by_ip->{$ip}->[0];
2713: if (ref($by_location->{$first}) eq 'ARRAY') {
2714: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2715: push(@{$by_location->{$first}},$ip);
2716: }
2717: } else {
2718: $by_location->{$first} = [$ip];
2719: }
2720: }
2721: }
2722: return;
2723: }
2724:
1.145 raeburn 2725: sub current_offloads_to {
2726: my ($dom,$settings,$servers) = @_;
2727: my (%spareid,%otherdomconfigs);
1.152 raeburn 2728: if (ref($servers) eq 'HASH') {
1.145 raeburn 2729: foreach my $lonhost (sort(keys(%{$servers}))) {
2730: my $gotspares;
1.152 raeburn 2731: if (ref($settings) eq 'HASH') {
2732: if (ref($settings->{'spares'}) eq 'HASH') {
2733: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
2734: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
2735: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
2736: $gotspares = 1;
2737: }
1.145 raeburn 2738: }
2739: }
2740: unless ($gotspares) {
2741: my $gotspares;
2742: my $serverhomeID =
2743: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
2744: my $serverhomedom =
2745: &Apache::lonnet::host_domain($serverhomeID);
2746: if ($serverhomedom ne $dom) {
2747: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
2748: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2749: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2750: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2751: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2752: $gotspares = 1;
2753: }
2754: }
2755: } else {
2756: $otherdomconfigs{$serverhomedom} =
2757: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
2758: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
2759: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2760: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2761: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
2762: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2763: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2764: $gotspares = 1;
2765: }
2766: }
2767: }
2768: }
2769: }
2770: }
2771: }
2772: unless ($gotspares) {
2773: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
2774: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2775: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2776: } else {
2777: my $server_hostname = &Apache::lonnet::hostname($lonhost);
2778: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
2779: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
2780: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2781: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2782: } else {
1.150 raeburn 2783: my %what = (
2784: spareid => 1,
2785: );
2786: my ($result,$returnhash) =
2787: &Apache::lonnet::get_remote_globals($lonhost,\%what);
2788: if ($result eq 'ok') {
2789: if (ref($returnhash) eq 'HASH') {
2790: if (ref($returnhash->{'spareid'}) eq 'HASH') {
2791: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
2792: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
2793: }
2794: }
1.145 raeburn 2795: }
2796: }
2797: }
2798: }
2799: }
2800: }
2801: return %spareid;
2802: }
2803:
2804: sub spares_row {
1.152 raeburn 2805: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 2806: my $css_class;
2807: my $numinrow = 4;
2808: my $itemcount = 1;
2809: my $datatable;
1.152 raeburn 2810: my %typetitles = &sparestype_titles();
2811: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 2812: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 2813: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
2814: my ($othercontrol,$serverdom);
2815: if ($serverhome ne $server) {
2816: $serverdom = &Apache::lonnet::host_domain($serverhome);
2817: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2818: } else {
2819: $serverdom = &Apache::lonnet::host_domain($server);
2820: if ($serverdom ne $dom) {
2821: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2822: }
2823: }
2824: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 2825: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2826: $datatable .= '<tr'.$css_class.'>
2827: <td rowspan="2">
1.183 bisitz 2828: <span class="LC_nobreak">'.
2829: &mt('[_1] when busy, offloads to:'
2830: ,'<b>'.$server.'</b>').
2831: "\n";
1.145 raeburn 2832: my (%current,%canselect);
1.152 raeburn 2833: my @choices =
2834: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
2835: foreach my $type ('primary','default') {
2836: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 2837: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
2838: my @spares = @{$spareid->{$server}{$type}};
2839: if (@spares > 0) {
1.152 raeburn 2840: if ($othercontrol) {
2841: $current{$type} = join(', ',@spares);
2842: } else {
2843: $current{$type} .= '<table>';
2844: my $numspares = scalar(@spares);
2845: for (my $i=0; $i<@spares; $i++) {
2846: my $rem = $i%($numinrow);
2847: if ($rem == 0) {
2848: if ($i > 0) {
2849: $current{$type} .= '</tr>';
2850: }
2851: $current{$type} .= '<tr>';
1.145 raeburn 2852: }
1.152 raeburn 2853: $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'".');" /> '.
2854: $spareid->{$server}{$type}[$i].
2855: '</label></td>'."\n";
2856: }
2857: my $rem = @spares%($numinrow);
2858: my $colsleft = $numinrow - $rem;
2859: if ($colsleft > 1 ) {
2860: $current{$type} .= '<td colspan="'.$colsleft.
2861: '" class="LC_left_item">'.
2862: ' </td>';
2863: } elsif ($colsleft == 1) {
2864: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 2865: }
1.152 raeburn 2866: $current{$type} .= '</tr></table>';
1.150 raeburn 2867: }
1.145 raeburn 2868: }
2869: }
2870: if ($current{$type} eq '') {
2871: $current{$type} = &mt('None specified');
2872: }
1.152 raeburn 2873: if ($othercontrol) {
2874: if ($type eq 'primary') {
2875: $canselect{$type} = $othercontrol;
2876: }
2877: } else {
2878: $canselect{$type} =
2879: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
2880: '<select name="newspare_'.$type.'_'.$server.'" '.
2881: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
2882: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
2883: if (@choices > 0) {
2884: foreach my $lonhost (@choices) {
2885: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
2886: }
2887: }
2888: $canselect{$type} .= '</select>'."\n";
2889: }
2890: } else {
2891: $current{$type} = &mt('Could not be determined');
2892: if ($type eq 'primary') {
2893: $canselect{$type} = $othercontrol;
2894: }
1.145 raeburn 2895: }
1.152 raeburn 2896: if ($type eq 'default') {
2897: $datatable .= '<tr'.$css_class.'>';
2898: }
2899: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
2900: '<td>'.$current{$type}.'</td>'."\n".
2901: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 2902: }
2903: $itemcount ++;
2904: }
2905: }
2906: $$rowtotal += $itemcount;
2907: return $datatable;
2908: }
2909:
1.152 raeburn 2910: sub possible_newspares {
2911: my ($server,$currspares,$serverhomes,$altids) = @_;
2912: my $serverhostname = &Apache::lonnet::hostname($server);
2913: my %excluded;
2914: if ($serverhostname ne '') {
2915: %excluded = (
2916: $serverhostname => 1,
2917: );
2918: }
2919: if (ref($currspares) eq 'HASH') {
2920: foreach my $type (keys(%{$currspares})) {
2921: if (ref($currspares->{$type}) eq 'ARRAY') {
2922: if (@{$currspares->{$type}} > 0) {
2923: foreach my $curr (@{$currspares->{$type}}) {
2924: my $hostname = &Apache::lonnet::hostname($curr);
2925: $excluded{$hostname} = 1;
2926: }
2927: }
2928: }
2929: }
2930: }
2931: my @choices;
2932: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
2933: if (keys(%{$serverhomes}) > 1) {
2934: foreach my $name (sort(keys(%{$serverhomes}))) {
2935: unless ($excluded{$name}) {
2936: if (exists($altids->{$serverhomes->{$name}})) {
2937: push(@choices,$altids->{$serverhomes->{$name}});
2938: } else {
2939: push(@choices,$serverhomes->{$name});
1.145 raeburn 2940: }
2941: }
2942: }
2943: }
2944: }
1.152 raeburn 2945: return sort(@choices);
1.145 raeburn 2946: }
2947:
1.150 raeburn 2948: sub print_loadbalancing {
2949: my ($dom,$settings,$rowtotal) = @_;
2950: my $primary_id = &Apache::lonnet::domain($dom,'primary');
2951: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2952: my $numinrow = 1;
2953: my $datatable;
2954: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 2955: my (%currbalancer,%currtargets,%currrules,%existing);
2956: if (ref($settings) eq 'HASH') {
2957: %existing = %{$settings};
2958: }
2959: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
2960: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
2961: \%currtargets,\%currrules);
1.150 raeburn 2962: } else {
2963: return;
2964: }
2965: my ($othertitle,$usertypes,$types) =
2966: &Apache::loncommon::sorted_inst_types($dom);
2967: my $rownum = 6;
2968: if (ref($types) eq 'ARRAY') {
2969: $rownum += scalar(@{$types});
2970: }
1.171 raeburn 2971: my @css_class = ('LC_odd_row','LC_even_row');
2972: my $balnum = 0;
2973: my $islast;
2974: my (@toshow,$disabledtext);
2975: if (keys(%currbalancer) > 0) {
2976: @toshow = sort(keys(%currbalancer));
2977: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
2978: push(@toshow,'');
2979: }
2980: } else {
2981: @toshow = ('');
2982: $disabledtext = &mt('No existing load balancer');
2983: }
2984: foreach my $lonhost (@toshow) {
2985: if ($balnum == scalar(@toshow)-1) {
2986: $islast = 1;
2987: } else {
2988: $islast = 0;
2989: }
2990: my $cssidx = $balnum%2;
2991: my $targets_div_style = 'display: none';
2992: my $disabled_div_style = 'display: block';
2993: my $homedom_div_style = 'display: none';
2994: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
2995: '<td rowspan="'.$rownum.'" valign="top">'.
2996: '<p>';
2997: if ($lonhost eq '') {
2998: $datatable .= '<span class="LC_nobreak">';
2999: if (keys(%currbalancer) > 0) {
3000: $datatable .= &mt('Add balancer:');
3001: } else {
3002: $datatable .= &mt('Enable balancer:');
3003: }
3004: $datatable .= ' '.
3005: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3006: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3007: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3008: '<option value="" selected="selected">'.&mt('None').
3009: '</option>'."\n";
3010: foreach my $server (sort(keys(%servers))) {
3011: next if ($currbalancer{$server});
3012: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3013: }
3014: $datatable .=
3015: '</select>'."\n".
3016: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3017: } else {
3018: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3019: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3020: &mt('Stop balancing').'</label>'.
3021: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3022: $targets_div_style = 'display: block';
3023: $disabled_div_style = 'display: none';
3024: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3025: $homedom_div_style = 'display: block';
3026: }
3027: }
3028: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3029: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3030: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3031: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3032: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3033: my @sparestypes = ('primary','default');
3034: my %typetitles = &sparestype_titles();
3035: foreach my $sparetype (@sparestypes) {
3036: my $targettable;
3037: for (my $i=0; $i<$numspares; $i++) {
3038: my $checked;
3039: if (ref($currtargets{$lonhost}) eq 'HASH') {
3040: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3041: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3042: $checked = ' checked="checked"';
3043: }
3044: }
3045: }
3046: my ($chkboxval,$disabled);
3047: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3048: $chkboxval = $spares[$i];
3049: }
3050: if (exists($currbalancer{$spares[$i]})) {
3051: $disabled = ' disabled="disabled"';
3052: }
3053: $targettable .=
3054: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3055: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3056: '</span></label></td>';
3057: my $rem = $i%($numinrow);
3058: if ($rem == 0) {
3059: if (($i > 0) && ($i < $numspares-1)) {
3060: $targettable .= '</tr>';
3061: }
3062: if ($i < $numspares-1) {
3063: $targettable .= '<tr>';
1.150 raeburn 3064: }
3065: }
3066: }
1.171 raeburn 3067: if ($targettable ne '') {
3068: my $rem = $numspares%($numinrow);
3069: my $colsleft = $numinrow - $rem;
3070: if ($colsleft > 1 ) {
3071: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3072: ' </td>';
3073: } elsif ($colsleft == 1) {
3074: $targettable .= '<td class="LC_left_item"> </td>';
3075: }
3076: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3077: '<table><tr>'.$targettable.'</tr></table><br />';
3078: }
3079: }
3080: $datatable .= '</div></td></tr>'.
3081: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3082: $othertitle,$usertypes,$types,\%servers,
3083: \%currbalancer,$lonhost,
3084: $targets_div_style,$homedom_div_style,
3085: $css_class[$cssidx],$balnum,$islast);
3086: $$rowtotal += $rownum;
3087: $balnum ++;
3088: }
3089: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3090: return $datatable;
3091: }
3092:
3093: sub get_loadbalancers_config {
3094: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3095: return unless ((ref($servers) eq 'HASH') &&
3096: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3097: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3098: if (keys(%{$existing}) > 0) {
3099: my $oldlonhost;
3100: foreach my $key (sort(keys(%{$existing}))) {
3101: if ($key eq 'lonhost') {
3102: $oldlonhost = $existing->{'lonhost'};
3103: $currbalancer->{$oldlonhost} = 1;
3104: } elsif ($key eq 'targets') {
3105: if ($oldlonhost) {
3106: $currtargets->{$oldlonhost} = $existing->{'targets'};
3107: }
3108: } elsif ($key eq 'rules') {
3109: if ($oldlonhost) {
3110: $currrules->{$oldlonhost} = $existing->{'rules'};
3111: }
3112: } elsif (ref($existing->{$key}) eq 'HASH') {
3113: $currbalancer->{$key} = 1;
3114: $currtargets->{$key} = $existing->{$key}{'targets'};
3115: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3116: }
3117: }
1.171 raeburn 3118: } else {
3119: my ($balancerref,$targetsref) =
3120: &Apache::lonnet::get_lonbalancer_config($servers);
3121: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3122: foreach my $server (sort(keys(%{$balancerref}))) {
3123: $currbalancer->{$server} = 1;
3124: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3125: }
3126: }
3127: }
1.171 raeburn 3128: return;
1.150 raeburn 3129: }
3130:
3131: sub loadbalancing_rules {
3132: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 3133: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3134: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3135: my $output;
1.171 raeburn 3136: my $num = 0;
1.150 raeburn 3137: my ($alltypes,$othertypes,$titles) =
3138: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3139: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3140: foreach my $type (@{$alltypes}) {
1.171 raeburn 3141: $num ++;
1.150 raeburn 3142: my $current;
3143: if (ref($currrules) eq 'HASH') {
3144: $current = $currrules->{$type};
3145: }
3146: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 3147: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3148: $current = '';
3149: }
3150: }
3151: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 3152: $servers,$currbalancer,$lonhost,$dom,
3153: $targets_div_style,$homedom_div_style,
3154: $css_class,$balnum,$num,$islast);
1.150 raeburn 3155: }
3156: }
3157: return $output;
3158: }
3159:
3160: sub loadbalancing_titles {
3161: my ($dom,$intdom,$usertypes,$types) = @_;
3162: my %othertypes = (
3163: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3164: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3165: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3166: '_LC_external' => &mt('Users not from [_1]',$intdom),
3167: );
3168: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
3169: if (ref($types) eq 'ARRAY') {
3170: unshift(@alltypes,@{$types},'default');
3171: }
3172: my %titles;
3173: foreach my $type (@alltypes) {
3174: if ($type =~ /^_LC_/) {
3175: $titles{$type} = $othertypes{$type};
3176: } elsif ($type eq 'default') {
3177: $titles{$type} = &mt('All users from [_1]',$dom);
3178: if (ref($types) eq 'ARRAY') {
3179: if (@{$types} > 0) {
3180: $titles{$type} = &mt('Other users from [_1]',$dom);
3181: }
3182: }
3183: } elsif (ref($usertypes) eq 'HASH') {
3184: $titles{$type} = $usertypes->{$type};
3185: }
3186: }
3187: return (\@alltypes,\%othertypes,\%titles);
3188: }
3189:
3190: sub loadbalance_rule_row {
1.171 raeburn 3191: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3192: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.150 raeburn 3193: my @rulenames = ('default','homeserver');
3194: my %ruletitles = &offloadtype_text();
3195: if ($type eq '_LC_external') {
3196: push(@rulenames,'externalbalancer');
3197: } else {
3198: push(@rulenames,'specific');
3199: }
1.161 raeburn 3200: push(@rulenames,'none');
1.150 raeburn 3201: my $style = $targets_div_style;
3202: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
3203: $style = $homedom_div_style;
3204: }
1.171 raeburn 3205: my $space;
3206: if ($islast && $num == 1) {
3207: $space = '<div display="inline-block"> </div>';
3208: }
1.150 raeburn 3209: my $output =
1.171 raeburn 3210: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3211: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3212: '<td valaign="top">'.$space.
3213: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3214: for (my $i=0; $i<@rulenames; $i++) {
3215: my $rule = $rulenames[$i];
3216: my ($checked,$extra);
3217: if ($rulenames[$i] eq 'default') {
3218: $rule = '';
3219: }
3220: if ($rulenames[$i] eq 'specific') {
3221: if (ref($servers) eq 'HASH') {
3222: my $default;
3223: if (($current ne '') && (exists($servers->{$current}))) {
3224: $checked = ' checked="checked"';
3225: }
3226: unless ($checked) {
3227: $default = ' selected="selected"';
3228: }
1.171 raeburn 3229: $extra =
3230: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3231: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3232: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3233: '<option value=""'.$default.'></option>'."\n";
3234: foreach my $server (sort(keys(%{$servers}))) {
3235: if (ref($currbalancer) eq 'HASH') {
3236: next if (exists($currbalancer->{$server}));
3237: }
1.150 raeburn 3238: my $selected;
1.171 raeburn 3239: if ($server eq $current) {
1.150 raeburn 3240: $selected = ' selected="selected"';
3241: }
1.171 raeburn 3242: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3243: }
3244: $extra .= '</select>';
3245: }
3246: } elsif ($rule eq $current) {
3247: $checked = ' checked="checked"';
3248: }
3249: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 3250: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3251: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3252: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3253: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3254: '</label>'.$extra.'</span><br />'."\n";
3255: }
3256: $output .= '</div></td></tr>'."\n";
3257: return $output;
3258: }
3259:
3260: sub offloadtype_text {
3261: my %ruletitles = &Apache::lonlocal::texthash (
3262: 'default' => 'Offloads to default destinations',
3263: 'homeserver' => "Offloads to user's home server",
3264: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3265: 'specific' => 'Offloads to specific server',
1.161 raeburn 3266: 'none' => 'No offload',
1.150 raeburn 3267: );
3268: return %ruletitles;
3269: }
3270:
3271: sub sparestype_titles {
3272: my %typestitles = &Apache::lonlocal::texthash (
3273: 'primary' => 'primary',
3274: 'default' => 'default',
3275: );
3276: return %typestitles;
3277: }
3278:
1.28 raeburn 3279: sub contact_titles {
3280: my %titles = &Apache::lonlocal::texthash (
3281: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3282: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3283: 'errormail' => 'Error reports to be e-mailed to',
3284: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3285: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3286: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3287: 'requestsmail' => 'E-mail from course requests requiring approval',
1.190 raeburn 3288: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.28 raeburn 3289: );
3290: my %short_titles = &Apache::lonlocal::texthash (
3291: adminemail => 'Admin E-mail address',
3292: supportemail => 'Support E-mail',
3293: );
3294: return (\%titles,\%short_titles);
3295: }
3296:
1.72 raeburn 3297: sub tool_titles {
3298: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 3299: aboutme => 'Personal web page',
1.86 raeburn 3300: blog => 'Blog',
1.162 raeburn 3301: webdav => 'WebDAV',
1.86 raeburn 3302: portfolio => 'Portfolio',
1.88 bisitz 3303: official => 'Official courses (with institutional codes)',
3304: unofficial => 'Unofficial courses',
1.98 raeburn 3305: community => 'Communities',
1.86 raeburn 3306: );
1.72 raeburn 3307: return %titles;
3308: }
3309:
1.101 raeburn 3310: sub courserequest_titles {
3311: my %titles = &Apache::lonlocal::texthash (
3312: official => 'Official',
3313: unofficial => 'Unofficial',
3314: community => 'Communities',
3315: norequest => 'Not allowed',
1.104 raeburn 3316: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3317: validate => 'With validation',
3318: autolimit => 'Numerical limit',
1.103 raeburn 3319: unlimited => '(blank for unlimited)',
1.101 raeburn 3320: );
3321: return %titles;
3322: }
3323:
1.163 raeburn 3324: sub authorrequest_titles {
3325: my %titles = &Apache::lonlocal::texthash (
3326: norequest => 'Not allowed',
3327: approval => 'Approval by Dom. Coord.',
3328: automatic => 'Automatic approval',
3329: );
3330: return %titles;
3331: }
3332:
1.101 raeburn 3333: sub courserequest_conditions {
3334: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3335: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 3336: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 3337: );
3338: return %conditions;
3339: }
3340:
3341:
1.27 raeburn 3342: sub print_usercreation {
1.30 raeburn 3343: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3344: my $numinrow = 4;
1.28 raeburn 3345: my $datatable;
3346: if ($position eq 'top') {
1.30 raeburn 3347: $$rowtotal ++;
1.34 raeburn 3348: my $rowcount = 0;
1.32 raeburn 3349: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3350: if (ref($rules) eq 'HASH') {
3351: if (keys(%{$rules}) > 0) {
1.32 raeburn 3352: $datatable .= &user_formats_row('username',$settings,$rules,
3353: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3354: $$rowtotal ++;
1.32 raeburn 3355: $rowcount ++;
3356: }
3357: }
3358: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3359: if (ref($idrules) eq 'HASH') {
3360: if (keys(%{$idrules}) > 0) {
3361: $datatable .= &user_formats_row('id',$settings,$idrules,
3362: $idruleorder,$numinrow,$rowcount);
3363: $$rowtotal ++;
3364: $rowcount ++;
1.28 raeburn 3365: }
3366: }
1.43 raeburn 3367: my ($emailrules,$emailruleorder) =
3368: &Apache::lonnet::inst_userrules($dom,'email');
3369: if (ref($emailrules) eq 'HASH') {
3370: if (keys(%{$emailrules}) > 0) {
3371: $datatable .= &user_formats_row('email',$settings,$emailrules,
3372: $emailruleorder,$numinrow,$rowcount);
3373: $$rowtotal ++;
3374: $rowcount ++;
3375: }
3376: }
1.39 raeburn 3377: if ($rowcount == 0) {
3378: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3379: $$rowtotal ++;
3380: $rowcount ++;
3381: }
1.34 raeburn 3382: } elsif ($position eq 'middle') {
1.100 raeburn 3383: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 3384: my ($rules,$ruleorder) =
3385: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3386: my %lt = &usercreation_types();
3387: my %checked;
1.50 raeburn 3388: my @selfcreate;
1.34 raeburn 3389: if (ref($settings) eq 'HASH') {
3390: if (ref($settings->{'cancreate'}) eq 'HASH') {
3391: foreach my $item (@creators) {
3392: $checked{$item} = $settings->{'cancreate'}{$item};
3393: }
1.50 raeburn 3394: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3395: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3396: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3397: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3398: @selfcreate = ('email','login','sso');
3399: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3400: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3401: }
3402: }
1.34 raeburn 3403: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3404: foreach my $item (@creators) {
3405: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3406: $checked{$item} = 'none';
3407: }
3408: }
3409: }
3410: }
3411: my $rownum = 0;
3412: foreach my $item (@creators) {
3413: $rownum ++;
1.50 raeburn 3414: if ($item ne 'selfcreate') {
3415: if ($checked{$item} eq '') {
1.43 raeburn 3416: $checked{$item} = 'any';
3417: }
1.34 raeburn 3418: }
3419: my $css_class;
3420: if ($rownum%2) {
3421: $css_class = '';
3422: } else {
3423: $css_class = ' class="LC_odd_row" ';
3424: }
3425: $datatable .= '<tr'.$css_class.'>'.
3426: '<td><span class="LC_nobreak">'.$lt{$item}.
3427: '</span></td><td align="right">';
1.50 raeburn 3428: my @options;
1.45 raeburn 3429: if ($item eq 'selfcreate') {
1.43 raeburn 3430: push(@options,('email','login','sso'));
3431: } else {
1.50 raeburn 3432: @options = ('any');
1.43 raeburn 3433: if (ref($rules) eq 'HASH') {
3434: if (keys(%{$rules}) > 0) {
3435: push(@options,('official','unofficial'));
3436: }
1.37 raeburn 3437: }
1.50 raeburn 3438: push(@options,'none');
1.37 raeburn 3439: }
3440: foreach my $option (@options) {
1.50 raeburn 3441: my $type = 'radio';
1.34 raeburn 3442: my $check = ' ';
1.50 raeburn 3443: if ($item eq 'selfcreate') {
3444: $type = 'checkbox';
3445: if (grep(/^\Q$option\E$/,@selfcreate)) {
3446: $check = ' checked="checked" ';
3447: }
3448: } else {
3449: if ($checked{$item} eq $option) {
3450: $check = ' checked="checked" ';
3451: }
1.34 raeburn 3452: }
3453: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3454: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3455: $item.'" value="'.$option.'"'.$check.'/> '.
3456: $lt{$option}.'</label> </span>';
3457: }
3458: $datatable .= '</td></tr>';
3459: }
1.93 raeburn 3460: my ($othertitle,$usertypes,$types) =
3461: &Apache::loncommon::sorted_inst_types($dom);
1.165 raeburn 3462: my $createsettings;
3463: if (ref($settings) eq 'HASH') {
3464: $createsettings = $settings->{cancreate};
3465: }
1.93 raeburn 3466: if (ref($usertypes) eq 'HASH') {
3467: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 3468: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 3469: $dom,$numinrow,$othertitle,
3470: 'statustocreate');
3471: $$rowtotal ++;
1.169 raeburn 3472: $rownum ++;
1.93 raeburn 3473: }
3474: }
1.169 raeburn 3475: $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
1.28 raeburn 3476: } else {
3477: my @contexts = ('author','course','domain');
3478: my @authtypes = ('int','krb4','krb5','loc');
3479: my %checked;
3480: if (ref($settings) eq 'HASH') {
3481: if (ref($settings->{'authtypes'}) eq 'HASH') {
3482: foreach my $item (@contexts) {
3483: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3484: foreach my $auth (@authtypes) {
3485: if ($settings->{'authtypes'}{$item}{$auth}) {
3486: $checked{$item}{$auth} = ' checked="checked" ';
3487: }
3488: }
3489: }
3490: }
1.27 raeburn 3491: }
1.35 raeburn 3492: } else {
3493: foreach my $item (@contexts) {
1.36 raeburn 3494: foreach my $auth (@authtypes) {
1.35 raeburn 3495: $checked{$item}{$auth} = ' checked="checked" ';
3496: }
3497: }
1.27 raeburn 3498: }
1.28 raeburn 3499: my %title = &context_names();
3500: my %authname = &authtype_names();
3501: my $rownum = 0;
3502: my $css_class;
3503: foreach my $item (@contexts) {
3504: if ($rownum%2) {
3505: $css_class = '';
3506: } else {
3507: $css_class = ' class="LC_odd_row" ';
3508: }
1.30 raeburn 3509: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3510: '<td>'.$title{$item}.
3511: '</td><td class="LC_left_item">'.
3512: '<span class="LC_nobreak">';
3513: foreach my $auth (@authtypes) {
3514: $datatable .= '<label>'.
3515: '<input type="checkbox" name="'.$item.'_auth" '.
3516: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3517: $authname{$auth}.'</label> ';
3518: }
3519: $datatable .= '</span></td></tr>';
3520: $rownum ++;
1.27 raeburn 3521: }
1.30 raeburn 3522: $$rowtotal += $rownum;
1.27 raeburn 3523: }
3524: return $datatable;
3525: }
3526:
1.165 raeburn 3527: sub captcha_choice {
1.169 raeburn 3528: my ($context,$settings,$itemcount) = @_;
1.165 raeburn 3529: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
3530: my %lt = &captcha_phrases();
3531: $keyentry = 'hidden';
3532: if ($context eq 'cancreate') {
3533: $rowname = &mt('CAPTCHA validation (e-mail as username)');
1.169 raeburn 3534: } elsif ($context eq 'login') {
3535: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 3536: }
3537: if (ref($settings) eq 'HASH') {
3538: if ($settings->{'captcha'}) {
3539: $checked{$settings->{'captcha'}} = ' checked="checked"';
3540: } else {
3541: $checked{'original'} = ' checked="checked"';
3542: }
3543: if ($settings->{'captcha'} eq 'recaptcha') {
3544: $pubtext = $lt{'pub'};
3545: $privtext = $lt{'priv'};
3546: $keyentry = 'text';
3547: }
3548: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
3549: $currpub = $settings->{'recaptchakeys'}{'public'};
3550: $currpriv = $settings->{'recaptchakeys'}{'private'};
3551: }
3552: } else {
3553: $checked{'original'} = ' checked="checked"';
3554: }
1.169 raeburn 3555: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3556: my $output = '<tr'.$css_class.'>'.
3557: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 3558: '<table><tr><td>'."\n";
3559: foreach my $option ('original','recaptcha','notused') {
3560: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
3561: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
3562: $lt{$option}.'</label></span>';
3563: unless ($option eq 'notused') {
3564: $output .= (' 'x2)."\n";
3565: }
3566: }
3567: #
3568: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
3569: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
3570: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
3571: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
3572: #
3573: $output .= '</td></tr>'."\n".
3574: '<tr><td>'."\n".
3575: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
3576: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
3577: $currpub.'" size="40" /></span><br />'."\n".
3578: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
3579: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
3580: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
3581: '</td></tr>';
3582: return $output;
3583: }
3584:
1.32 raeburn 3585: sub user_formats_row {
3586: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3587: my $output;
3588: my %text = (
3589: 'username' => 'new usernames',
3590: 'id' => 'IDs',
1.45 raeburn 3591: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3592: );
3593: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3594: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3595: '<td><span class="LC_nobreak">';
3596: if ($type eq 'email') {
3597: $output .= &mt("Formats disallowed for $text{$type}: ");
3598: } else {
3599: $output .= &mt("Format rules to check for $text{$type}: ");
3600: }
3601: $output .= '</span></td>'.
3602: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3603: my $rem;
3604: if (ref($ruleorder) eq 'ARRAY') {
3605: for (my $i=0; $i<@{$ruleorder}; $i++) {
3606: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3607: my $rem = $i%($numinrow);
3608: if ($rem == 0) {
3609: if ($i > 0) {
3610: $output .= '</tr>';
3611: }
3612: $output .= '<tr>';
3613: }
3614: my $check = ' ';
1.39 raeburn 3615: if (ref($settings) eq 'HASH') {
3616: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3617: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3618: $check = ' checked="checked" ';
3619: }
1.27 raeburn 3620: }
3621: }
3622: $output .= '<td class="LC_left_item">'.
3623: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3624: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 3625: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3626: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3627: }
3628: }
3629: $rem = @{$ruleorder}%($numinrow);
3630: }
3631: my $colsleft = $numinrow - $rem;
3632: if ($colsleft > 1 ) {
3633: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3634: ' </td>';
3635: } elsif ($colsleft == 1) {
3636: $output .= '<td class="LC_left_item"> </td>';
3637: }
3638: $output .= '</tr></table></td></tr>';
3639: return $output;
3640: }
3641:
1.34 raeburn 3642: sub usercreation_types {
3643: my %lt = &Apache::lonlocal::texthash (
3644: author => 'When adding a co-author',
3645: course => 'When adding a user to a course',
1.100 raeburn 3646: requestcrs => 'When requesting a course',
1.45 raeburn 3647: selfcreate => 'User creates own account',
1.34 raeburn 3648: any => 'Any',
3649: official => 'Institutional only ',
3650: unofficial => 'Non-institutional only',
1.85 schafran 3651: email => 'E-mail address',
1.43 raeburn 3652: login => 'Institutional Login',
3653: sso => 'SSO',
1.34 raeburn 3654: none => 'None',
3655: );
3656: return %lt;
1.48 raeburn 3657: }
1.34 raeburn 3658:
1.28 raeburn 3659: sub authtype_names {
3660: my %lt = &Apache::lonlocal::texthash(
3661: int => 'Internal',
3662: krb4 => 'Kerberos 4',
3663: krb5 => 'Kerberos 5',
3664: loc => 'Local',
3665: );
3666: return %lt;
3667: }
3668:
3669: sub context_names {
3670: my %context_title = &Apache::lonlocal::texthash(
3671: author => 'Creating users when an Author',
3672: course => 'Creating users when in a course',
3673: domain => 'Creating users when a Domain Coordinator',
3674: );
3675: return %context_title;
3676: }
3677:
1.33 raeburn 3678: sub print_usermodification {
3679: my ($position,$dom,$settings,$rowtotal) = @_;
3680: my $numinrow = 4;
3681: my ($context,$datatable,$rowcount);
3682: if ($position eq 'top') {
3683: $rowcount = 0;
3684: $context = 'author';
3685: foreach my $role ('ca','aa') {
3686: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3687: $numinrow,$rowcount);
3688: $$rowtotal ++;
3689: $rowcount ++;
3690: }
1.63 raeburn 3691: } elsif ($position eq 'middle') {
1.33 raeburn 3692: $context = 'course';
3693: $rowcount = 0;
3694: foreach my $role ('st','ep','ta','in','cr') {
3695: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3696: $numinrow,$rowcount);
3697: $$rowtotal ++;
3698: $rowcount ++;
3699: }
1.63 raeburn 3700: } elsif ($position eq 'bottom') {
3701: $context = 'selfcreate';
3702: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3703: $usertypes->{'default'} = $othertitle;
3704: if (ref($types) eq 'ARRAY') {
3705: push(@{$types},'default');
3706: $usertypes->{'default'} = $othertitle;
3707: foreach my $status (@{$types}) {
3708: $datatable .= &modifiable_userdata_row($context,$status,$settings,
3709: $numinrow,$rowcount,$usertypes);
3710: $$rowtotal ++;
3711: $rowcount ++;
3712: }
3713: }
1.33 raeburn 3714: }
3715: return $datatable;
3716: }
3717:
1.43 raeburn 3718: sub print_defaults {
3719: my ($dom,$rowtotal) = @_;
1.68 raeburn 3720: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 3721: 'datelocale_def','portal_def');
1.43 raeburn 3722: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 3723: my $titles = &defaults_titles($dom);
1.43 raeburn 3724: my $rownum = 0;
3725: my ($datatable,$css_class);
3726: foreach my $item (@items) {
3727: if ($rownum%2) {
3728: $css_class = '';
3729: } else {
3730: $css_class = ' class="LC_odd_row" ';
3731: }
3732: $datatable .= '<tr'.$css_class.'>'.
3733: '<td><span class="LC_nobreak">'.$titles->{$item}.
3734: '</span></td><td class="LC_right_item">';
3735: if ($item eq 'auth_def') {
3736: my @authtypes = ('internal','krb4','krb5','localauth');
3737: my %shortauth = (
3738: internal => 'int',
3739: krb4 => 'krb4',
3740: krb5 => 'krb5',
3741: localauth => 'loc'
3742: );
3743: my %authnames = &authtype_names();
3744: foreach my $auth (@authtypes) {
3745: my $checked = ' ';
3746: if ($domdefaults{$item} eq $auth) {
3747: $checked = ' checked="checked" ';
3748: }
3749: $datatable .= '<label><input type="radio" name="'.$item.
3750: '" value="'.$auth.'"'.$checked.'/>'.
3751: $authnames{$shortauth{$auth}}.'</label> ';
3752: }
1.54 raeburn 3753: } elsif ($item eq 'timezone_def') {
3754: my $includeempty = 1;
3755: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68 raeburn 3756: } elsif ($item eq 'datelocale_def') {
3757: my $includeempty = 1;
3758: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.167 raeburn 3759: } elsif ($item eq 'lang_def') {
1.168 raeburn 3760: my %langchoices = &get_languages_hash();
3761: $langchoices{''} = 'No language preference';
1.167 raeburn 3762: %langchoices = &Apache::lonlocal::texthash(%langchoices);
3763: $datatable .= &Apache::loncommon::select_form($domdefaults{$item},$item,
3764: \%langchoices);
1.43 raeburn 3765: } else {
1.141 raeburn 3766: my $size;
3767: if ($item eq 'portal_def') {
3768: $size = ' size="25"';
3769: }
1.43 raeburn 3770: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.141 raeburn 3771: $domdefaults{$item}.'"'.$size.' />';
1.43 raeburn 3772: }
3773: $datatable .= '</td></tr>';
3774: $rownum ++;
3775: }
3776: $$rowtotal += $rownum;
3777: return $datatable;
3778: }
3779:
1.168 raeburn 3780: sub get_languages_hash {
3781: my %langchoices;
3782: foreach my $id (&Apache::loncommon::languageids()) {
3783: my $code = &Apache::loncommon::supportedlanguagecode($id);
3784: if ($code ne '') {
3785: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
3786: }
3787: }
3788: return %langchoices;
3789: }
3790:
1.43 raeburn 3791: sub defaults_titles {
1.141 raeburn 3792: my ($dom) = @_;
1.43 raeburn 3793: my %titles = &Apache::lonlocal::texthash (
3794: 'auth_def' => 'Default authentication type',
3795: 'auth_arg_def' => 'Default authentication argument',
3796: 'lang_def' => 'Default language',
1.54 raeburn 3797: 'timezone_def' => 'Default timezone',
1.68 raeburn 3798: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 3799: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 3800: );
1.141 raeburn 3801: if ($dom) {
3802: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
3803: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
3804: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
3805: $protocol = 'http' if ($protocol ne 'https');
3806: if ($uint_dom) {
3807: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
3808: $uint_dom);
3809: }
3810: }
1.43 raeburn 3811: return (\%titles);
3812: }
3813:
1.46 raeburn 3814: sub print_scantronformat {
3815: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
3816: my $itemcount = 1;
1.60 raeburn 3817: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
3818: %confhash);
1.46 raeburn 3819: my $switchserver = &check_switchserver($dom,$confname);
3820: my %lt = &Apache::lonlocal::texthash (
1.95 www 3821: default => 'Default bubblesheet format file error',
3822: custom => 'Custom bubblesheet format file error',
1.46 raeburn 3823: );
3824: my %scantronfiles = (
3825: default => 'default.tab',
3826: custom => 'custom.tab',
3827: );
3828: foreach my $key (keys(%scantronfiles)) {
3829: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
3830: .$scantronfiles{$key};
3831: }
3832: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
3833: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
3834: if (!$switchserver) {
3835: my $servadm = $r->dir_config('lonAdmEMail');
3836: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
3837: if ($configuserok eq 'ok') {
3838: if ($author_ok eq 'ok') {
3839: my %legacyfile = (
3840: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
3841: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
3842: );
3843: my %md5chk;
3844: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3845: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
3846: chomp($md5chk{$type});
1.46 raeburn 3847: }
3848: if ($md5chk{'default'} ne $md5chk{'custom'}) {
3849: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3850: ($scantronurls{$type},my $error) =
1.46 raeburn 3851: &legacy_scantronformat($r,$dom,$confname,
3852: $type,$legacyfile{$type},
3853: $scantronurls{$type},
3854: $scantronfiles{$type});
1.60 raeburn 3855: if ($error ne '') {
3856: $error{$type} = $error;
3857: }
3858: }
3859: if (keys(%error) == 0) {
3860: $is_custom = 1;
3861: $confhash{'scantron'}{'scantronformat'} =
3862: $scantronurls{'custom'};
3863: my $putresult =
3864: &Apache::lonnet::put_dom('configuration',
3865: \%confhash,$dom);
3866: if ($putresult ne 'ok') {
3867: $error{'custom'} =
3868: '<span class="LC_error">'.
3869: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3870: }
1.46 raeburn 3871: }
3872: } else {
1.60 raeburn 3873: ($scantronurls{'default'},my $error) =
1.46 raeburn 3874: &legacy_scantronformat($r,$dom,$confname,
3875: 'default',$legacyfile{'default'},
3876: $scantronurls{'default'},
3877: $scantronfiles{'default'});
1.60 raeburn 3878: if ($error eq '') {
3879: $confhash{'scantron'}{'scantronformat'} = '';
3880: my $putresult =
3881: &Apache::lonnet::put_dom('configuration',
3882: \%confhash,$dom);
3883: if ($putresult ne 'ok') {
3884: $error{'default'} =
3885: '<span class="LC_error">'.
3886: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3887: }
3888: } else {
3889: $error{'default'} = $error;
3890: }
1.46 raeburn 3891: }
3892: }
3893: }
3894: } else {
1.95 www 3895: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 3896: }
3897: }
3898: if (ref($settings) eq 'HASH') {
3899: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
3900: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
3901: if ((!@info) || ($info[0] eq 'no_such_dir')) {
3902: $scantronurl = '';
3903: } else {
3904: $scantronurl = $settings->{'scantronformat'};
3905: }
3906: $is_custom = 1;
3907: } else {
3908: $scantronurl = $scantronurls{'default'};
3909: }
3910: } else {
1.60 raeburn 3911: if ($is_custom) {
3912: $scantronurl = $scantronurls{'custom'};
3913: } else {
3914: $scantronurl = $scantronurls{'default'};
3915: }
1.46 raeburn 3916: }
3917: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3918: $datatable .= '<tr'.$css_class.'>';
3919: if (!$is_custom) {
1.65 raeburn 3920: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
3921: '<span class="LC_nobreak">';
1.46 raeburn 3922: if ($scantronurl) {
1.199 ! raeburn 3923: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
! 3924: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 3925: } else {
3926: $datatable = &mt('File unavailable for display');
3927: }
1.65 raeburn 3928: $datatable .= '</span></td>';
1.60 raeburn 3929: if (keys(%error) == 0) {
3930: $datatable .= '<td valign="bottom">';
3931: if (!$switchserver) {
3932: $datatable .= &mt('Upload:').'<br />';
3933: }
3934: } else {
3935: my $errorstr;
3936: foreach my $key (sort(keys(%error))) {
3937: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3938: }
3939: $datatable .= '<td>'.$errorstr;
3940: }
1.46 raeburn 3941: } else {
3942: if (keys(%error) > 0) {
3943: my $errorstr;
3944: foreach my $key (sort(keys(%error))) {
3945: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3946: }
1.60 raeburn 3947: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 3948: } elsif ($scantronurl) {
1.199 ! raeburn 3949: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
! 3950: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 3951: $datatable .= '<td><span class="LC_nobreak">'.
1.199 ! raeburn 3952: $link.
! 3953: '<label><input type="checkbox" name="scantronformat_del"'.
! 3954: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 3955: '<td><span class="LC_nobreak"> '.
3956: &mt('Replace:').'</span><br />';
1.46 raeburn 3957: }
3958: }
3959: if (keys(%error) == 0) {
3960: if ($switchserver) {
3961: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3962: } else {
1.65 raeburn 3963: $datatable .='<span class="LC_nobreak"> '.
3964: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 3965: }
3966: }
3967: $datatable .= '</td></tr>';
3968: $$rowtotal ++;
3969: return $datatable;
3970: }
3971:
3972: sub legacy_scantronformat {
3973: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
3974: my ($url,$error);
3975: my @statinfo = &Apache::lonnet::stat_file($newurl);
3976: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
3977: (my $result,$url) =
3978: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
3979: '','',$newfile);
3980: if ($result ne 'ok') {
1.130 raeburn 3981: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 3982: }
3983: }
3984: return ($url,$error);
3985: }
1.43 raeburn 3986:
1.49 raeburn 3987: sub print_coursecategories {
1.57 raeburn 3988: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
3989: my $datatable;
3990: if ($position eq 'top') {
3991: my $toggle_cats_crs = ' ';
3992: my $toggle_cats_dom = ' checked="checked" ';
3993: my $can_cat_crs = ' ';
3994: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 3995: my $toggle_catscomm_comm = ' ';
3996: my $toggle_catscomm_dom = ' checked="checked" ';
3997: my $can_catcomm_comm = ' ';
3998: my $can_catcomm_dom = ' checked="checked" ';
3999:
1.57 raeburn 4000: if (ref($settings) eq 'HASH') {
4001: if ($settings->{'togglecats'} eq 'crs') {
4002: $toggle_cats_crs = $toggle_cats_dom;
4003: $toggle_cats_dom = ' ';
4004: }
4005: if ($settings->{'categorize'} eq 'crs') {
4006: $can_cat_crs = $can_cat_dom;
4007: $can_cat_dom = ' ';
4008: }
1.120 raeburn 4009: if ($settings->{'togglecatscomm'} eq 'comm') {
4010: $toggle_catscomm_comm = $toggle_catscomm_dom;
4011: $toggle_catscomm_dom = ' ';
4012: }
4013: if ($settings->{'categorizecomm'} eq 'comm') {
4014: $can_catcomm_comm = $can_catcomm_dom;
4015: $can_catcomm_dom = ' ';
4016: }
1.57 raeburn 4017: }
4018: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 4019: togglecats => 'Show/Hide a course in catalog',
4020: togglecatscomm => 'Show/Hide a community in catalog',
4021: categorize => 'Assign a category to a course',
4022: categorizecomm => 'Assign a category to a community',
1.57 raeburn 4023: );
4024: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 4025: dom => 'Set in Domain',
4026: crs => 'Set in Course',
4027: comm => 'Set in Community',
1.57 raeburn 4028: );
4029: $datatable = '<tr class="LC_odd_row">'.
4030: '<td>'.$title{'togglecats'}.'</td>'.
4031: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4032: '<input type="radio" name="togglecats"'.
4033: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4034: '<label><input type="radio" name="togglecats"'.
4035: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
4036: '</tr><tr>'.
4037: '<td>'.$title{'categorize'}.'</td>'.
4038: '<td class="LC_right_item"><span class="LC_nobreak">'.
4039: '<label><input type="radio" name="categorize"'.
4040: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4041: '<label><input type="radio" name="categorize"'.
4042: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 4043: '</tr><tr class="LC_odd_row">'.
4044: '<td>'.$title{'togglecatscomm'}.'</td>'.
4045: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4046: '<input type="radio" name="togglecatscomm"'.
4047: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4048: '<label><input type="radio" name="togglecatscomm"'.
4049: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4050: '</tr><tr>'.
4051: '<td>'.$title{'categorizecomm'}.'</td>'.
4052: '<td class="LC_right_item"><span class="LC_nobreak">'.
4053: '<label><input type="radio" name="categorizecomm"'.
4054: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4055: '<label><input type="radio" name="categorizecomm"'.
4056: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 4057: '</tr>';
1.120 raeburn 4058: $$rowtotal += 4;
1.57 raeburn 4059: } else {
4060: my $css_class;
4061: my $itemcount = 1;
4062: my $cathash;
4063: if (ref($settings) eq 'HASH') {
4064: $cathash = $settings->{'cats'};
4065: }
4066: if (ref($cathash) eq 'HASH') {
4067: my (@cats,@trails,%allitems,%idx,@jsarray);
4068: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4069: \%allitems,\%idx,\@jsarray);
4070: my $maxdepth = scalar(@cats);
4071: my $colattrib = '';
4072: if ($maxdepth > 2) {
4073: $colattrib = ' colspan="2" ';
4074: }
4075: my @path;
4076: if (@cats > 0) {
4077: if (ref($cats[0]) eq 'ARRAY') {
4078: my $numtop = @{$cats[0]};
4079: my $maxnum = $numtop;
1.120 raeburn 4080: my %default_names = (
4081: instcode => &mt('Official courses'),
4082: communities => &mt('Communities'),
4083: );
4084:
4085: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4086: ($cathash->{'instcode::0'} eq '') ||
4087: (!grep(/^communities$/,@{$cats[0]})) ||
4088: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4089: $maxnum ++;
4090: }
4091: my $lastidx;
4092: for (my $i=0; $i<$numtop; $i++) {
4093: my $parent = $cats[0][$i];
4094: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4095: my $item = &escape($parent).'::0';
4096: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4097: $lastidx = $idx{$item};
4098: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4099: .'<select name="'.$item.'"'.$chgstr.'>';
4100: for (my $k=0; $k<=$maxnum; $k++) {
4101: my $vpos = $k+1;
4102: my $selstr;
4103: if ($k == $i) {
4104: $selstr = ' selected="selected" ';
4105: }
4106: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4107: }
4108: $datatable .= '</select></td><td>';
1.120 raeburn 4109: if ($parent eq 'instcode' || $parent eq 'communities') {
4110: $datatable .= '<span class="LC_nobreak">'
4111: .$default_names{$parent}.'</span>';
4112: if ($parent eq 'instcode') {
4113: $datatable .= '<br /><span class="LC_nobreak">('
4114: .&mt('with institutional codes')
4115: .')</span></td><td'.$colattrib.'>';
4116: } else {
4117: $datatable .= '<table><tr><td>';
4118: }
4119: $datatable .= '<span class="LC_nobreak">'
4120: .'<label><input type="radio" name="'
4121: .$parent.'" value="1" checked="checked" />'
4122: .&mt('Display').'</label>';
4123: if ($parent eq 'instcode') {
4124: $datatable .= ' ';
4125: } else {
4126: $datatable .= '</span></td></tr><tr><td>'
4127: .'<span class="LC_nobreak">';
4128: }
4129: $datatable .= '<label><input type="radio" name="'
4130: .$parent.'" value="0" />'
4131: .&mt('Do not display').'</label></span>';
4132: if ($parent eq 'communities') {
4133: $datatable .= '</td></tr></table>';
4134: }
4135: $datatable .= '</td>';
1.57 raeburn 4136: } else {
4137: $datatable .= $parent
4138: .' <label><input type="checkbox" name="deletecategory" '
4139: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4140: }
4141: my $depth = 1;
4142: push(@path,$parent);
4143: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4144: pop(@path);
4145: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4146: $itemcount ++;
4147: }
1.48 raeburn 4148: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 4149: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4150: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 4151: for (my $k=0; $k<=$maxnum; $k++) {
4152: my $vpos = $k+1;
4153: my $selstr;
1.57 raeburn 4154: if ($k == $numtop) {
1.48 raeburn 4155: $selstr = ' selected="selected" ';
4156: }
4157: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4158: }
1.59 bisitz 4159: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 4160: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4161: .'</tr>'."\n";
1.48 raeburn 4162: $itemcount ++;
1.120 raeburn 4163: foreach my $default ('instcode','communities') {
4164: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4165: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4166: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4167: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4168: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4169: for (my $k=0; $k<=$maxnum; $k++) {
4170: my $vpos = $k+1;
4171: my $selstr;
4172: if ($k == $maxnum) {
4173: $selstr = ' selected="selected" ';
4174: }
4175: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 4176: }
1.120 raeburn 4177: $datatable .= '</select></span></td>'.
4178: '<td><span class="LC_nobreak">'.
4179: $default_names{$default}.'</span>';
4180: if ($default eq 'instcode') {
4181: $datatable .= '<br /><span class="LC_nobreak">('
4182: .&mt('with institutional codes').')</span>';
4183: }
4184: $datatable .= '</td>'
4185: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4186: .&mt('Display').'</label> '
4187: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
4188: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 4189: }
4190: }
4191: }
1.57 raeburn 4192: } else {
4193: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 4194: }
4195: } else {
1.57 raeburn 4196: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
4197: .&initialize_categories($itemcount);
1.48 raeburn 4198: }
1.57 raeburn 4199: $$rowtotal += $itemcount;
1.48 raeburn 4200: }
4201: return $datatable;
4202: }
4203:
1.69 raeburn 4204: sub print_serverstatuses {
4205: my ($dom,$settings,$rowtotal) = @_;
4206: my $datatable;
4207: my @pages = &serverstatus_pages();
4208: my (%namedaccess,%machineaccess);
4209: foreach my $type (@pages) {
4210: $namedaccess{$type} = '';
4211: $machineaccess{$type}= '';
4212: }
4213: if (ref($settings) eq 'HASH') {
4214: foreach my $type (@pages) {
4215: if (exists($settings->{$type})) {
4216: if (ref($settings->{$type}) eq 'HASH') {
4217: foreach my $key (keys(%{$settings->{$type}})) {
4218: if ($key eq 'namedusers') {
4219: $namedaccess{$type} = $settings->{$type}->{$key};
4220: } elsif ($key eq 'machines') {
4221: $machineaccess{$type} = $settings->{$type}->{$key};
4222: }
4223: }
4224: }
4225: }
4226: }
4227: }
1.81 raeburn 4228: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 4229: my $rownum = 0;
4230: my $css_class;
4231: foreach my $type (@pages) {
4232: $rownum ++;
4233: $css_class = $rownum%2?' class="LC_odd_row"':'';
4234: $datatable .= '<tr'.$css_class.'>'.
4235: '<td><span class="LC_nobreak">'.
4236: $titles->{$type}.'</span></td>'.
4237: '<td class="LC_left_item">'.
4238: '<input type="text" name="'.$type.'_namedusers" '.
4239: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
4240: '<td class="LC_right_item">'.
4241: '<span class="LC_nobreak">'.
4242: '<input type="text" name="'.$type.'_machines" '.
4243: 'value="'.$machineaccess{$type}.'" size="10" />'.
4244: '</td></tr>'."\n";
4245: }
4246: $$rowtotal += $rownum;
4247: return $datatable;
4248: }
4249:
4250: sub serverstatus_pages {
4251: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.189 raeburn 4252: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.156 raeburn 4253: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69 raeburn 4254: }
4255:
1.49 raeburn 4256: sub coursecategories_javascript {
4257: my ($settings) = @_;
1.57 raeburn 4258: my ($output,$jstext,$cathash);
1.49 raeburn 4259: if (ref($settings) eq 'HASH') {
1.57 raeburn 4260: $cathash = $settings->{'cats'};
4261: }
4262: if (ref($cathash) eq 'HASH') {
1.49 raeburn 4263: my (@cats,@jsarray,%idx);
1.57 raeburn 4264: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 4265: if (@jsarray > 0) {
4266: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
4267: for (my $i=0; $i<@jsarray; $i++) {
4268: if (ref($jsarray[$i]) eq 'ARRAY') {
4269: my $catstr = join('","',@{$jsarray[$i]});
4270: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
4271: }
4272: }
4273: }
4274: } else {
4275: $jstext = ' var categories = Array(1);'."\n".
4276: ' categories[0] = Array("instcode_pos");'."\n";
4277: }
1.120 raeburn 4278: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
4279: my $communities_reserved = &mt('The name: "communities" is a reserved category');
4280: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 4281: $output = <<"ENDSCRIPT";
4282: <script type="text/javascript">
1.109 raeburn 4283: // <![CDATA[
1.49 raeburn 4284: function reorderCats(form,parent,item,idx) {
4285: var changedVal;
4286: $jstext
4287: var newpos = 'addcategory_pos';
4288: var current = new Array;
4289: if (parent == '') {
4290: var has_instcode = 0;
4291: var maxtop = categories[idx].length;
4292: for (var j=0; j<maxtop; j++) {
4293: if (categories[idx][j] == 'instcode::0') {
4294: has_instcode == 1;
4295: }
4296: }
4297: if (has_instcode == 0) {
4298: categories[idx][maxtop] = 'instcode_pos';
4299: }
4300: } else {
4301: newpos += '_'+parent;
4302: }
4303: var maxh = 1 + categories[idx].length;
4304: var current = new Array;
4305: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4306: if (item == newpos) {
4307: changedVal = newitemVal;
4308: } else {
4309: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4310: current[newitemVal] = newpos;
4311: }
4312: for (var i=0; i<categories[idx].length; i++) {
4313: var elementName = categories[idx][i];
4314: if (elementName != item) {
4315: if (form.elements[elementName]) {
4316: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4317: current[currVal] = elementName;
4318: }
4319: }
4320: }
4321: var oldVal;
4322: for (var j=0; j<maxh; j++) {
4323: if (current[j] == undefined) {
4324: oldVal = j;
4325: }
4326: }
4327: if (oldVal < changedVal) {
4328: for (var k=oldVal+1; k<=changedVal ; k++) {
4329: var elementName = current[k];
4330: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4331: }
4332: } else {
4333: for (var k=changedVal; k<oldVal; k++) {
4334: var elementName = current[k];
4335: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4336: }
4337: }
4338: return;
4339: }
1.120 raeburn 4340:
4341: function categoryCheck(form) {
4342: if (form.elements['addcategory_name'].value == 'instcode') {
4343: alert('$instcode_reserved\\n$choose_again');
4344: return false;
4345: }
4346: if (form.elements['addcategory_name'].value == 'communities') {
4347: alert('$communities_reserved\\n$choose_again');
4348: return false;
4349: }
4350: return true;
4351: }
4352:
1.109 raeburn 4353: // ]]>
1.49 raeburn 4354: </script>
4355:
4356: ENDSCRIPT
4357: return $output;
4358: }
4359:
1.48 raeburn 4360: sub initialize_categories {
4361: my ($itemcount) = @_;
1.120 raeburn 4362: my ($datatable,$css_class,$chgstr);
4363: my %default_names = (
4364: instcode => 'Official courses (with institutional codes)',
4365: communities => 'Communities',
4366: );
4367: my $select0 = ' selected="selected"';
4368: my $select1 = '';
4369: foreach my $default ('instcode','communities') {
4370: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4371: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
4372: if ($default eq 'communities') {
4373: $select1 = $select0;
4374: $select0 = '';
4375: }
4376: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4377: .'<select name="'.$default.'_pos">'
4378: .'<option value="0"'.$select0.'>1</option>'
4379: .'<option value="1"'.$select1.'>2</option>'
4380: .'<option value="2">3</option></select> '
4381: .$default_names{$default}
4382: .'</span></td><td><span class="LC_nobreak">'
4383: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4384: .&mt('Display').'</label> <label>'
4385: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 4386: .'</label></span></td></tr>';
1.120 raeburn 4387: $itemcount ++;
4388: }
1.48 raeburn 4389: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 4390: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 4391: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 4392: .'<select name="addcategory_pos"'.$chgstr.'>'
4393: .'<option value="0">1</option>'
4394: .'<option value="1">2</option>'
4395: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 4396: .&mt('Add category').'</td><td>'.&mt('Name:')
4397: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4398: return $datatable;
4399: }
4400:
4401: sub build_category_rows {
1.49 raeburn 4402: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4403: my ($text,$name,$item,$chgstr);
1.48 raeburn 4404: if (ref($cats) eq 'ARRAY') {
4405: my $maxdepth = scalar(@{$cats});
4406: if (ref($cats->[$depth]) eq 'HASH') {
4407: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4408: my $numchildren = @{$cats->[$depth]{$parent}};
4409: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4410: $text .= '<td><table class="LC_datatable">';
1.49 raeburn 4411: my ($idxnum,$parent_name,$parent_item);
4412: my $higher = $depth - 1;
4413: if ($higher == 0) {
4414: $parent_name = &escape($parent).'::'.$higher;
4415: } else {
4416: if (ref($path) eq 'ARRAY') {
4417: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4418: }
4419: }
4420: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4421: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4422: if ($j < $numchildren) {
1.48 raeburn 4423: $name = $cats->[$depth]{$parent}[$j];
4424: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4425: $idxnum = $idx->{$item};
4426: } else {
4427: $name = $parent_name;
4428: $item = $parent_item;
1.48 raeburn 4429: }
1.49 raeburn 4430: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4431: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4432: for (my $i=0; $i<=$numchildren; $i++) {
4433: my $vpos = $i+1;
4434: my $selstr;
4435: if ($j == $i) {
4436: $selstr = ' selected="selected" ';
4437: }
4438: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4439: }
4440: $text .= '</select> ';
4441: if ($j < $numchildren) {
4442: my $deeper = $depth+1;
4443: $text .= $name.' '
4444: .'<label><input type="checkbox" name="deletecategory" value="'
4445: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4446: if(ref($path) eq 'ARRAY') {
4447: push(@{$path},$name);
1.49 raeburn 4448: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4449: pop(@{$path});
4450: }
4451: } else {
1.59 bisitz 4452: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4453: if ($j == $numchildren) {
4454: $text .= $name;
4455: } else {
4456: $text .= $item;
4457: }
4458: $text .= '" value="" />';
4459: }
4460: $text .= '</td></tr>';
4461: }
4462: $text .= '</table></td>';
4463: } else {
4464: my $higher = $depth-1;
4465: if ($higher == 0) {
4466: $name = &escape($parent).'::'.$higher;
4467: } else {
4468: if (ref($path) eq 'ARRAY') {
4469: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4470: }
4471: }
4472: my $colspan;
4473: if ($parent ne 'instcode') {
4474: $colspan = $maxdepth - $depth - 1;
4475: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4476: }
4477: }
4478: }
4479: }
4480: return $text;
4481: }
4482:
1.33 raeburn 4483: sub modifiable_userdata_row {
1.63 raeburn 4484: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 4485: my $rolename;
1.63 raeburn 4486: if ($context eq 'selfcreate') {
4487: if (ref($usertypes) eq 'HASH') {
4488: $rolename = $usertypes->{$role};
4489: } else {
4490: $rolename = $role;
4491: }
1.33 raeburn 4492: } else {
1.63 raeburn 4493: if ($role eq 'cr') {
4494: $rolename = &mt('Custom role');
4495: } else {
4496: $rolename = &Apache::lonnet::plaintext($role);
4497: }
1.33 raeburn 4498: }
4499: my @fields = ('lastname','firstname','middlename','generation',
4500: 'permanentemail','id');
4501: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4502: my $output;
4503: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4504: $output = '<tr '.$css_class.'>'.
4505: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4506: '<td class="LC_left_item" colspan="2"><table>';
4507: my $rem;
4508: my %checks;
4509: if (ref($settings) eq 'HASH') {
4510: if (ref($settings->{$context}) eq 'HASH') {
4511: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4512: foreach my $field (@fields) {
4513: if ($settings->{$context}->{$role}->{$field}) {
4514: $checks{$field} = ' checked="checked" ';
4515: }
4516: }
4517: }
4518: }
4519: }
4520: for (my $i=0; $i<@fields; $i++) {
4521: my $rem = $i%($numinrow);
4522: if ($rem == 0) {
4523: if ($i > 0) {
4524: $output .= '</tr>';
4525: }
4526: $output .= '<tr>';
4527: }
4528: my $check = ' ';
4529: if (exists($checks{$fields[$i]})) {
4530: $check = $checks{$fields[$i]}
4531: } else {
4532: if ($role eq 'st') {
4533: if (ref($settings) ne 'HASH') {
4534: $check = ' checked="checked" ';
4535: }
4536: }
4537: }
4538: $output .= '<td class="LC_left_item">'.
4539: '<span class="LC_nobreak"><label>'.
4540: '<input type="checkbox" name="canmodify_'.$role.'" '.
4541: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4542: '</label></span></td>';
4543: $rem = @fields%($numinrow);
4544: }
4545: my $colsleft = $numinrow - $rem;
4546: if ($colsleft > 1 ) {
4547: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4548: ' </td>';
4549: } elsif ($colsleft == 1) {
4550: $output .= '<td class="LC_left_item"> </td>';
4551: }
4552: $output .= '</tr></table></td></tr>';
4553: return $output;
4554: }
1.28 raeburn 4555:
1.93 raeburn 4556: sub insttypes_row {
4557: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
4558: my %lt = &Apache::lonlocal::texthash (
4559: cansearch => 'Users allowed to search',
4560: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4561: lockablenames => 'User preference to lock name',
1.93 raeburn 4562: );
4563: my $showdom;
4564: if ($context eq 'cansearch') {
4565: $showdom = ' ('.$dom.')';
4566: }
1.165 raeburn 4567: my $class = 'LC_left_item';
4568: if ($context eq 'statustocreate') {
4569: $class = 'LC_right_item';
4570: }
1.25 raeburn 4571: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 4572: '<td>'.$lt{$context}.$showdom.
1.165 raeburn 4573: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 4574: my $rem;
4575: if (ref($types) eq 'ARRAY') {
4576: for (my $i=0; $i<@{$types}; $i++) {
4577: if (defined($usertypes->{$types->[$i]})) {
4578: my $rem = $i%($numinrow);
4579: if ($rem == 0) {
4580: if ($i > 0) {
4581: $output .= '</tr>';
4582: }
4583: $output .= '<tr>';
1.23 raeburn 4584: }
1.26 raeburn 4585: my $check = ' ';
1.99 raeburn 4586: if (ref($settings) eq 'HASH') {
4587: if (ref($settings->{$context}) eq 'ARRAY') {
4588: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4589: $check = ' checked="checked" ';
4590: }
4591: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4592: $check = ' checked="checked" ';
4593: }
1.23 raeburn 4594: }
1.26 raeburn 4595: $output .= '<td class="LC_left_item">'.
4596: '<span class="LC_nobreak"><label>'.
1.93 raeburn 4597: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 4598: 'value="'.$types->[$i].'"'.$check.'/>'.
4599: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 4600: }
4601: }
1.26 raeburn 4602: $rem = @{$types}%($numinrow);
1.23 raeburn 4603: }
4604: my $colsleft = $numinrow - $rem;
1.131 raeburn 4605: if (($rem == 0) && (@{$types} > 0)) {
4606: $output .= '<tr>';
4607: }
1.23 raeburn 4608: if ($colsleft > 1) {
1.25 raeburn 4609: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 4610: } else {
1.25 raeburn 4611: $output .= '<td class="LC_left_item">';
1.23 raeburn 4612: }
4613: my $defcheck = ' ';
1.99 raeburn 4614: if (ref($settings) eq 'HASH') {
4615: if (ref($settings->{$context}) eq 'ARRAY') {
4616: if (grep(/^default$/,@{$settings->{$context}})) {
4617: $defcheck = ' checked="checked" ';
4618: }
4619: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4620: $defcheck = ' checked="checked" ';
4621: }
1.23 raeburn 4622: }
1.25 raeburn 4623: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 4624: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 4625: 'value="default"'.$defcheck.'/>'.
4626: $othertitle.'</label></span></td>'.
4627: '</tr></table></td></tr>';
4628: return $output;
1.23 raeburn 4629: }
4630:
4631: sub sorted_searchtitles {
4632: my %searchtitles = &Apache::lonlocal::texthash(
4633: 'uname' => 'username',
4634: 'lastname' => 'last name',
4635: 'lastfirst' => 'last name, first name',
4636: );
4637: my @titleorder = ('uname','lastname','lastfirst');
4638: return (\%searchtitles,\@titleorder);
4639: }
4640:
1.25 raeburn 4641: sub sorted_searchtypes {
4642: my %srchtypes_desc = (
4643: exact => 'is exact match',
4644: contains => 'contains ..',
4645: begins => 'begins with ..',
4646: );
4647: my @srchtypeorder = ('exact','begins','contains');
4648: return (\%srchtypes_desc,\@srchtypeorder);
4649: }
4650:
1.3 raeburn 4651: sub usertype_update_row {
4652: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
4653: my $datatable;
4654: my $numinrow = 4;
4655: foreach my $type (@{$types}) {
4656: if (defined($usertypes->{$type})) {
4657: $$rownums ++;
4658: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
4659: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
4660: '</td><td class="LC_left_item"><table>';
4661: for (my $i=0; $i<@{$fields}; $i++) {
4662: my $rem = $i%($numinrow);
4663: if ($rem == 0) {
4664: if ($i > 0) {
4665: $datatable .= '</tr>';
4666: }
4667: $datatable .= '<tr>';
4668: }
4669: my $check = ' ';
1.39 raeburn 4670: if (ref($settings) eq 'HASH') {
4671: if (ref($settings->{'fields'}) eq 'HASH') {
4672: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
4673: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
4674: $check = ' checked="checked" ';
4675: }
1.3 raeburn 4676: }
4677: }
4678: }
4679:
4680: if ($i == @{$fields}-1) {
4681: my $colsleft = $numinrow - $rem;
4682: if ($colsleft > 1) {
4683: $datatable .= '<td colspan="'.$colsleft.'">';
4684: } else {
4685: $datatable .= '<td>';
4686: }
4687: } else {
4688: $datatable .= '<td>';
4689: }
1.8 raeburn 4690: $datatable .= '<span class="LC_nobreak"><label>'.
4691: '<input type="checkbox" name="updateable_'.$type.
4692: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
4693: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 4694: }
4695: $datatable .= '</tr></table></td></tr>';
4696: }
4697: }
4698: return $datatable;
1.1 raeburn 4699: }
4700:
4701: sub modify_login {
1.9 raeburn 4702: my ($r,$dom,$confname,%domconfig) = @_;
1.168 raeburn 4703: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
4704: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
4705: %title = ( coursecatalog => 'Display course catalog',
4706: adminmail => 'Display administrator E-mail address',
1.188 raeburn 4707: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 4708: newuser => 'Link for visitors to create a user account',
4709: loginheader => 'Log-in box header');
4710: @offon = ('off','on');
1.112 raeburn 4711: if (ref($domconfig{login}) eq 'HASH') {
4712: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
4713: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
4714: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
4715: }
4716: }
4717: }
1.9 raeburn 4718: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
4719: \%domconfig,\%loginhash);
1.188 raeburn 4720: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 4721: foreach my $item (@toggles) {
4722: $loginhash{login}{$item} = $env{'form.'.$item};
4723: }
1.41 raeburn 4724: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 4725: if (ref($colchanges{'login'}) eq 'HASH') {
4726: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
4727: \%loginhash);
4728: }
1.110 raeburn 4729:
1.149 raeburn 4730: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 4731: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 4732: if (keys(%servers) > 1) {
4733: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 4734: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
4735: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
4736: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
4737: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
4738: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
4739: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4740: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4741: $changes{'loginvia'}{$lonhost} = 1;
4742: } else {
4743: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
4744: $changes{'loginvia'}{$lonhost} = 1;
4745: }
4746: } else {
4747: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4748: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4749: $changes{'loginvia'}{$lonhost} = 1;
4750: }
4751: }
4752: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
4753: foreach my $item (@loginvia_attribs) {
4754: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
4755: }
4756: } else {
4757: foreach my $item (@loginvia_attribs) {
4758: my $new = $env{'form.'.$lonhost.'_'.$item};
4759: if (($item eq 'serverpath') && ($new eq 'custom')) {
4760: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
4761: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4762: $new = '/';
4763: }
4764: }
4765: if (($item eq 'custompath') &&
4766: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4767: $new = '';
4768: }
4769: if ($new ne $curr_loginvia{$lonhost}{$item}) {
4770: $changes{'loginvia'}{$lonhost} = 1;
4771: }
4772: if ($item eq 'exempt') {
4773: $new =~ s/^\s+//;
4774: $new =~ s/\s+$//;
4775: my @poss_ips = split(/\s*[,:]\s*/,$new);
4776: my @okips;
4777: foreach my $ip (@poss_ips) {
4778: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
4779: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
4780: push(@okips,$ip);
4781: }
4782: }
4783: }
4784: if (@okips > 0) {
4785: $new = join(',',@okips);
4786: } else {
4787: $new = '';
4788: }
4789: }
4790: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4791: }
4792: }
1.112 raeburn 4793: } else {
1.128 raeburn 4794: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4795: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 4796: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 4797: foreach my $item (@loginvia_attribs) {
4798: my $new = $env{'form.'.$lonhost.'_'.$item};
4799: if (($item eq 'serverpath') && ($new eq 'custom')) {
4800: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4801: $new = '/';
4802: }
4803: }
4804: if (($item eq 'custompath') &&
4805: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4806: $new = '';
4807: }
4808: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4809: }
1.110 raeburn 4810: }
4811: }
4812: }
4813: }
1.119 raeburn 4814:
1.168 raeburn 4815: my $servadm = $r->dir_config('lonAdmEMail');
4816: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
4817: if (ref($domconfig{'login'}) eq 'HASH') {
4818: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
4819: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
4820: if ($lang eq 'nolang') {
4821: push(@currlangs,$lang);
4822: } elsif (defined($langchoices{$lang})) {
4823: push(@currlangs,$lang);
4824: } else {
4825: next;
4826: }
4827: }
4828: }
4829: }
4830: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
4831: if (@currlangs > 0) {
4832: foreach my $lang (@currlangs) {
4833: if (grep(/^\Q$lang\E$/,@delurls)) {
4834: $changes{'helpurl'}{$lang} = 1;
4835: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
4836: $changes{'helpurl'}{$lang} = 1;
4837: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
4838: push(@newlangs,$lang);
4839: } else {
4840: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4841: }
4842: }
4843: }
4844: unless (grep(/^nolang$/,@currlangs)) {
4845: if ($env{'form.loginhelpurl_nolang.filename'}) {
4846: $changes{'helpurl'}{'nolang'} = 1;
4847: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
4848: push(@newlangs,'nolang');
4849: }
4850: }
4851: if ($env{'form.loginhelpurl_add_lang'}) {
4852: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
4853: ($env{'form.loginhelpurl_add_file.filename'})) {
4854: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
4855: $addedfile = $env{'form.loginhelpurl_add_lang'};
4856: }
4857: }
4858: if ((@newlangs > 0) || ($addedfile)) {
4859: my $error;
4860: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
4861: if ($configuserok eq 'ok') {
4862: if ($switchserver) {
4863: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
4864: } elsif ($author_ok eq 'ok') {
4865: my @allnew = @newlangs;
4866: if ($addedfile ne '') {
4867: push(@allnew,$addedfile);
4868: }
4869: foreach my $lang (@allnew) {
4870: my $formelem = 'loginhelpurl_'.$lang;
4871: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
4872: $formelem = 'loginhelpurl_add_file';
4873: }
4874: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
4875: "help/$lang",'','',$newfile{$lang});
4876: if ($result eq 'ok') {
4877: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
4878: $changes{'helpurl'}{$lang} = 1;
4879: } else {
4880: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
4881: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
4882: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
4883: (!grep(/^\Q$lang\E$/,@delurls))) {
4884:
4885: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4886: }
4887: }
4888: }
4889: } else {
4890: $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);
4891: }
4892: } else {
4893: $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);
4894: }
4895: if ($error) {
4896: &Apache::lonnet::logthis($error);
4897: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
4898: }
4899: }
1.169 raeburn 4900: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 4901:
4902: my $defaulthelpfile = '/adm/loginproblems.html';
4903: my $defaulttext = &mt('Default in use');
4904:
1.1 raeburn 4905: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
4906: $dom);
4907: if ($putresult eq 'ok') {
1.188 raeburn 4908: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 4909: my %defaultchecked = (
4910: 'coursecatalog' => 'on',
1.188 raeburn 4911: 'helpdesk' => 'on',
1.42 raeburn 4912: 'adminmail' => 'off',
1.43 raeburn 4913: 'newuser' => 'off',
1.42 raeburn 4914: );
1.55 raeburn 4915: if (ref($domconfig{'login'}) eq 'HASH') {
4916: foreach my $item (@toggles) {
4917: if ($defaultchecked{$item} eq 'on') {
4918: if (($domconfig{'login'}{$item} eq '0') &&
4919: ($env{'form.'.$item} eq '1')) {
4920: $changes{$item} = 1;
4921: } elsif (($domconfig{'login'}{$item} eq '' ||
4922: $domconfig{'login'}{$item} eq '1') &&
4923: ($env{'form.'.$item} eq '0')) {
4924: $changes{$item} = 1;
4925: }
4926: } elsif ($defaultchecked{$item} eq 'off') {
4927: if (($domconfig{'login'}{$item} eq '1') &&
4928: ($env{'form.'.$item} eq '0')) {
4929: $changes{$item} = 1;
4930: } elsif (($domconfig{'login'}{$item} eq '' ||
4931: $domconfig{'login'}{$item} eq '0') &&
4932: ($env{'form.'.$item} eq '1')) {
4933: $changes{$item} = 1;
4934: }
1.42 raeburn 4935: }
4936: }
1.41 raeburn 4937: }
1.6 raeburn 4938: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 4939: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 4940: $resulttext = &mt('Changes made:').'<ul>';
4941: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 4942: if ($item eq 'loginvia') {
1.112 raeburn 4943: if (ref($changes{$item}) eq 'HASH') {
4944: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
4945: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 4946: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
4947: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
4948: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
4949: $protocol = 'http' if ($protocol ne 'https');
4950: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
4951:
4952: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
4953: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
4954: } else {
4955: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
4956: }
4957: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
4958: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
4959: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
4960: }
4961: $resulttext .= '</li>';
4962: } else {
4963: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
4964: }
1.112 raeburn 4965: } else {
1.128 raeburn 4966: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 4967: }
4968: }
1.128 raeburn 4969: $resulttext .= '</ul></li>';
1.112 raeburn 4970: }
1.168 raeburn 4971: } elsif ($item eq 'helpurl') {
4972: if (ref($changes{$item}) eq 'HASH') {
4973: foreach my $lang (sort(keys(%{$changes{$item}}))) {
4974: if (grep(/^\Q$lang\E$/,@delurls)) {
4975: my ($chg,$link);
4976: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
4977: if ($lang eq 'nolang') {
4978: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
4979: } else {
4980: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
4981: }
4982: $resulttext .= '<li>'.$chg.'</li>';
4983: } else {
4984: my $chg;
4985: if ($lang eq 'nolang') {
4986: $chg = &mt('custom log-in help file for no preferred language');
4987: } else {
4988: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
4989: }
4990: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
4991: $loginhash{'login'}{'helpurl'}{$lang}.
4992: '?inhibitmenu=yes',$chg,600,500).
4993: '</li>';
4994: }
4995: }
4996: }
1.169 raeburn 4997: } elsif ($item eq 'captcha') {
4998: if (ref($loginhash{'login'}) eq 'HASH') {
4999: my $chgtxt;
5000: if ($loginhash{'login'}{$item} eq 'notused') {
5001: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
5002: } else {
5003: my %captchas = &captcha_phrases();
5004: if ($captchas{$loginhash{'login'}{$item}}) {
5005: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
5006: } else {
5007: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
5008: }
5009: }
5010: $resulttext .= '<li>'.$chgtxt.'</li>';
5011: }
5012: } elsif ($item eq 'recaptchakeys') {
5013: if (ref($loginhash{'login'}) eq 'HASH') {
5014: my ($privkey,$pubkey);
5015: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
5016: $pubkey = $loginhash{'login'}{$item}{'public'};
5017: $privkey = $loginhash{'login'}{$item}{'private'};
5018: }
5019: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
5020: if (!$pubkey) {
5021: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
5022: } else {
5023: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
5024: }
5025: if (!$privkey) {
5026: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
5027: } else {
5028: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
5029: }
5030: $chgtxt .= '</ul>';
5031: $resulttext .= '<li>'.$chgtxt.'</li>';
5032: }
1.41 raeburn 5033: } else {
5034: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
5035: }
1.1 raeburn 5036: }
1.6 raeburn 5037: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 5038: } else {
5039: $resulttext = &mt('No changes made to log-in page settings');
5040: }
5041: } else {
1.11 albertel 5042: $resulttext = '<span class="LC_error">'.
5043: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5044: }
1.6 raeburn 5045: if ($errors) {
1.9 raeburn 5046: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 5047: $errors.'</ul>';
5048: }
5049: return $resulttext;
5050: }
5051:
5052: sub color_font_choices {
5053: my %choices =
5054: &Apache::lonlocal::texthash (
5055: img => "Header",
5056: bgs => "Background colors",
5057: links => "Link colors",
1.55 raeburn 5058: images => "Images",
1.6 raeburn 5059: font => "Font color",
1.97 tempelho 5060: fontmenu => "Font Menu",
1.76 raeburn 5061: pgbg => "Page",
1.6 raeburn 5062: tabbg => "Header",
5063: sidebg => "Border",
5064: link => "Link",
5065: alink => "Active link",
5066: vlink => "Visited link",
5067: );
5068: return %choices;
5069: }
5070:
5071: sub modify_rolecolors {
1.9 raeburn 5072: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 5073: my ($resulttext,%rolehash);
5074: $rolehash{'rolecolors'} = {};
1.55 raeburn 5075: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
5076: if ($domconfig{'rolecolors'} eq '') {
5077: $domconfig{'rolecolors'} = {};
5078: }
5079: }
1.9 raeburn 5080: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 5081: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
5082: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
5083: $dom);
5084: if ($putresult eq 'ok') {
5085: if (keys(%changes) > 0) {
1.41 raeburn 5086: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 5087: $resulttext = &display_colorchgs($dom,\%changes,$roles,
5088: $rolehash{'rolecolors'});
5089: } else {
5090: $resulttext = &mt('No changes made to default color schemes');
5091: }
5092: } else {
1.11 albertel 5093: $resulttext = '<span class="LC_error">'.
5094: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 5095: }
5096: if ($errors) {
5097: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5098: $errors.'</ul>';
5099: }
5100: return $resulttext;
5101: }
5102:
5103: sub modify_colors {
1.9 raeburn 5104: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 5105: my (%changes,%choices);
1.51 raeburn 5106: my @bgs;
1.6 raeburn 5107: my @links = ('link','alink','vlink');
1.41 raeburn 5108: my @logintext;
1.6 raeburn 5109: my @images;
5110: my $servadm = $r->dir_config('lonAdmEMail');
5111: my $errors;
5112: foreach my $role (@{$roles}) {
5113: if ($role eq 'login') {
1.12 raeburn 5114: %choices = &login_choices();
1.41 raeburn 5115: @logintext = ('textcol','bgcol');
1.12 raeburn 5116: } else {
5117: %choices = &color_font_choices();
1.107 raeburn 5118: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
1.12 raeburn 5119: }
5120: if ($role eq 'login') {
1.41 raeburn 5121: @images = ('img','logo','domlogo','login');
1.51 raeburn 5122: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 5123: } else {
5124: @images = ('img');
1.51 raeburn 5125: @bgs = ('pgbg','tabbg','sidebg');
1.6 raeburn 5126: }
5127: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 5128: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 5129: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5130: }
1.46 raeburn 5131: my ($configuserok,$author_ok,$switchserver) =
5132: &config_check($dom,$confname,$servadm);
1.9 raeburn 5133: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 5134: if (ref($domconfig->{$role}) ne 'HASH') {
5135: $domconfig->{$role} = {};
5136: }
1.8 raeburn 5137: foreach my $img (@images) {
1.70 raeburn 5138: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
5139: if (defined($env{'form.login_showlogo_'.$img})) {
5140: $confhash->{$role}{'showlogo'}{$img} = 1;
5141: } else {
5142: $confhash->{$role}{'showlogo'}{$img} = 0;
5143: }
5144: }
1.18 albertel 5145: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
5146: && !defined($domconfig->{$role}{$img})
5147: && !$env{'form.'.$role.'_del_'.$img}
5148: && $env{'form.'.$role.'_import_'.$img}) {
5149: # import the old configured image from the .tab setting
5150: # if they haven't provided a new one
5151: $domconfig->{$role}{$img} =
5152: $env{'form.'.$role.'_import_'.$img};
5153: }
1.6 raeburn 5154: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 5155: my $error;
1.6 raeburn 5156: if ($configuserok eq 'ok') {
1.9 raeburn 5157: if ($switchserver) {
1.12 raeburn 5158: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 5159: } else {
5160: if ($author_ok eq 'ok') {
5161: my ($result,$logourl) =
5162: &publishlogo($r,'upload',$role.'_'.$img,
5163: $dom,$confname,$img,$width,$height);
5164: if ($result eq 'ok') {
5165: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 5166: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5167: } else {
1.12 raeburn 5168: $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 5169: }
5170: } else {
1.46 raeburn 5171: $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 5172: }
5173: }
5174: } else {
1.46 raeburn 5175: $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 5176: }
5177: if ($error) {
1.8 raeburn 5178: &Apache::lonnet::logthis($error);
1.11 albertel 5179: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 5180: }
5181: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 5182: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
5183: my $error;
5184: if ($configuserok eq 'ok') {
5185: # is confname an author?
5186: if ($switchserver eq '') {
5187: if ($author_ok eq 'ok') {
5188: my ($result,$logourl) =
5189: &publishlogo($r,'copy',$domconfig->{$role}{$img},
5190: $dom,$confname,$img,$width,$height);
5191: if ($result eq 'ok') {
5192: $confhash->{$role}{$img} = $logourl;
1.18 albertel 5193: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5194: }
5195: }
5196: }
5197: }
1.6 raeburn 5198: }
5199: }
5200: }
5201: if (ref($domconfig) eq 'HASH') {
5202: if (ref($domconfig->{$role}) eq 'HASH') {
5203: foreach my $img (@images) {
5204: if ($domconfig->{$role}{$img} ne '') {
5205: if ($env{'form.'.$role.'_del_'.$img}) {
5206: $confhash->{$role}{$img} = '';
1.12 raeburn 5207: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5208: } else {
1.9 raeburn 5209: if ($confhash->{$role}{$img} eq '') {
5210: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
5211: }
1.6 raeburn 5212: }
5213: } else {
5214: if ($env{'form.'.$role.'_del_'.$img}) {
5215: $confhash->{$role}{$img} = '';
1.12 raeburn 5216: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5217: }
5218: }
1.70 raeburn 5219: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
5220: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
5221: if ($confhash->{$role}{'showlogo'}{$img} ne
5222: $domconfig->{$role}{'showlogo'}{$img}) {
5223: $changes{$role}{'showlogo'}{$img} = 1;
5224: }
5225: } else {
5226: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5227: $changes{$role}{'showlogo'}{$img} = 1;
5228: }
5229: }
5230: }
5231: }
1.6 raeburn 5232: if ($domconfig->{$role}{'font'} ne '') {
5233: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
5234: $changes{$role}{'font'} = 1;
5235: }
5236: } else {
5237: if ($confhash->{$role}{'font'}) {
5238: $changes{$role}{'font'} = 1;
5239: }
5240: }
1.107 raeburn 5241: if ($role ne 'login') {
5242: if ($domconfig->{$role}{'fontmenu'} ne '') {
5243: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
5244: $changes{$role}{'fontmenu'} = 1;
5245: }
5246: } else {
5247: if ($confhash->{$role}{'fontmenu'}) {
5248: $changes{$role}{'fontmenu'} = 1;
5249: }
1.97 tempelho 5250: }
5251: }
1.6 raeburn 5252: foreach my $item (@bgs) {
5253: if ($domconfig->{$role}{$item} ne '') {
5254: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5255: $changes{$role}{'bgs'}{$item} = 1;
5256: }
5257: } else {
5258: if ($confhash->{$role}{$item}) {
5259: $changes{$role}{'bgs'}{$item} = 1;
5260: }
5261: }
5262: }
5263: foreach my $item (@links) {
5264: if ($domconfig->{$role}{$item} ne '') {
5265: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5266: $changes{$role}{'links'}{$item} = 1;
5267: }
5268: } else {
5269: if ($confhash->{$role}{$item}) {
5270: $changes{$role}{'links'}{$item} = 1;
5271: }
5272: }
5273: }
1.41 raeburn 5274: foreach my $item (@logintext) {
5275: if ($domconfig->{$role}{$item} ne '') {
5276: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5277: $changes{$role}{'logintext'}{$item} = 1;
5278: }
5279: } else {
5280: if ($confhash->{$role}{$item}) {
5281: $changes{$role}{'logintext'}{$item} = 1;
5282: }
5283: }
5284: }
1.6 raeburn 5285: } else {
5286: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5287: \@logintext,$confhash,\%changes);
1.6 raeburn 5288: }
5289: } else {
5290: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5291: \@logintext,$confhash,\%changes);
1.6 raeburn 5292: }
5293: }
5294: return ($errors,%changes);
5295: }
5296:
1.46 raeburn 5297: sub config_check {
5298: my ($dom,$confname,$servadm) = @_;
5299: my ($configuserok,$author_ok,$switchserver,%currroles);
5300: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
5301: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
5302: $confname,$servadm);
5303: if ($configuserok eq 'ok') {
5304: $switchserver = &check_switchserver($dom,$confname);
5305: if ($switchserver eq '') {
5306: $author_ok = &check_authorstatus($dom,$confname,%currroles);
5307: }
5308: }
5309: return ($configuserok,$author_ok,$switchserver);
5310: }
5311:
1.6 raeburn 5312: sub default_change_checker {
1.41 raeburn 5313: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 5314: foreach my $item (@{$links}) {
5315: if ($confhash->{$role}{$item}) {
5316: $changes->{$role}{'links'}{$item} = 1;
5317: }
5318: }
5319: foreach my $item (@{$bgs}) {
5320: if ($confhash->{$role}{$item}) {
5321: $changes->{$role}{'bgs'}{$item} = 1;
5322: }
5323: }
1.41 raeburn 5324: foreach my $item (@{$logintext}) {
5325: if ($confhash->{$role}{$item}) {
5326: $changes->{$role}{'logintext'}{$item} = 1;
5327: }
5328: }
1.6 raeburn 5329: foreach my $img (@{$images}) {
5330: if ($env{'form.'.$role.'_del_'.$img}) {
5331: $confhash->{$role}{$img} = '';
1.12 raeburn 5332: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 5333: }
1.70 raeburn 5334: if ($role eq 'login') {
5335: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5336: $changes->{$role}{'showlogo'}{$img} = 1;
5337: }
5338: }
1.6 raeburn 5339: }
5340: if ($confhash->{$role}{'font'}) {
5341: $changes->{$role}{'font'} = 1;
5342: }
1.48 raeburn 5343: }
1.6 raeburn 5344:
5345: sub display_colorchgs {
5346: my ($dom,$changes,$roles,$confhash) = @_;
5347: my (%choices,$resulttext);
5348: if (!grep(/^login$/,@{$roles})) {
5349: $resulttext = &mt('Changes made:').'<br />';
5350: }
5351: foreach my $role (@{$roles}) {
5352: if ($role eq 'login') {
5353: %choices = &login_choices();
5354: } else {
5355: %choices = &color_font_choices();
5356: }
5357: if (ref($changes->{$role}) eq 'HASH') {
5358: if ($role ne 'login') {
5359: $resulttext .= '<h4>'.&mt($role).'</h4>';
5360: }
5361: foreach my $key (sort(keys(%{$changes->{$role}}))) {
5362: if ($role ne 'login') {
5363: $resulttext .= '<ul>';
5364: }
5365: if (ref($changes->{$role}{$key}) eq 'HASH') {
5366: if ($role ne 'login') {
5367: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
5368: }
5369: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 5370: if (($role eq 'login') && ($key eq 'showlogo')) {
5371: if ($confhash->{$role}{$key}{$item}) {
5372: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
5373: } else {
5374: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
5375: }
5376: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 5377: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
5378: } else {
1.12 raeburn 5379: my $newitem = $confhash->{$role}{$item};
5380: if ($key eq 'images') {
5381: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
5382: }
5383: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 5384: }
5385: }
5386: if ($role ne 'login') {
5387: $resulttext .= '</ul></li>';
5388: }
5389: } else {
5390: if ($confhash->{$role}{$key} eq '') {
5391: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
5392: } else {
5393: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
5394: }
5395: }
5396: if ($role ne 'login') {
5397: $resulttext .= '</ul>';
5398: }
5399: }
5400: }
5401: }
1.3 raeburn 5402: return $resulttext;
1.1 raeburn 5403: }
5404:
1.9 raeburn 5405: sub thumb_dimensions {
5406: return ('200','50');
5407: }
5408:
1.16 raeburn 5409: sub check_dimensions {
5410: my ($inputfile) = @_;
5411: my ($fullwidth,$fullheight);
5412: if ($inputfile =~ m|^[/\w.\-]+$|) {
5413: if (open(PIPE,"identify $inputfile 2>&1 |")) {
5414: my $imageinfo = <PIPE>;
5415: if (!close(PIPE)) {
5416: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
5417: }
5418: chomp($imageinfo);
5419: my ($fullsize) =
1.21 raeburn 5420: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 5421: if ($fullsize) {
5422: ($fullwidth,$fullheight) = split(/x/,$fullsize);
5423: }
5424: }
5425: }
5426: return ($fullwidth,$fullheight);
5427: }
5428:
1.9 raeburn 5429: sub check_configuser {
5430: my ($uhome,$dom,$confname,$servadm) = @_;
5431: my ($configuserok,%currroles);
5432: if ($uhome eq 'no_host') {
5433: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
5434: my $configpass = &LONCAPA::Enrollment::create_password();
5435: $configuserok =
5436: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
5437: $configpass,'','','','','',undef,$servadm);
5438: } else {
5439: $configuserok = 'ok';
5440: %currroles =
5441: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
5442: }
5443: return ($configuserok,%currroles);
5444: }
5445:
5446: sub check_authorstatus {
5447: my ($dom,$confname,%currroles) = @_;
5448: my $author_ok;
1.40 raeburn 5449: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 5450: my $start = time;
5451: my $end = 0;
5452: $author_ok =
5453: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 5454: 'au',$end,$start,'','','domconfig');
1.9 raeburn 5455: } else {
5456: $author_ok = 'ok';
5457: }
5458: return $author_ok;
5459: }
5460:
5461: sub publishlogo {
1.46 raeburn 5462: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 5463: my ($output,$fname,$logourl);
5464: if ($action eq 'upload') {
5465: $fname=$env{'form.'.$formname.'.filename'};
5466: chop($env{'form.'.$formname});
5467: } else {
5468: ($fname) = ($formname =~ /([^\/]+)$/);
5469: }
1.46 raeburn 5470: if ($savefileas ne '') {
5471: $fname = $savefileas;
5472: }
1.9 raeburn 5473: $fname=&Apache::lonnet::clean_filename($fname);
5474: # See if there is anything left
5475: unless ($fname) { return ('error: no uploaded file'); }
5476: $fname="$subdir/$fname";
1.164 raeburn 5477: my $docroot=$r->dir_config('lonDocRoot');
5478: my $filepath="$docroot/priv";
5479: my $relpath = "$dom/$confname";
1.9 raeburn 5480: my ($fnamepath,$file,$fetchthumb);
5481: $file=$fname;
5482: if ($fname=~m|/|) {
5483: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
5484: }
1.164 raeburn 5485: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 5486: my $count;
1.164 raeburn 5487: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 5488: $filepath.="/$parts[$count]";
5489: if ((-e $filepath)!=1) {
5490: mkdir($filepath,02770);
5491: }
5492: }
5493: # Check for bad extension and disallow upload
5494: if ($file=~/\.(\w+)$/ &&
5495: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
5496: $output =
5497: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
5498: } elsif ($file=~/\.(\w+)$/ &&
5499: !defined(&Apache::loncommon::fileembstyle($1))) {
5500: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
5501: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 5502: $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 5503: } elsif (-d "$filepath/$file") {
1.195 bisitz 5504: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 5505: } else {
5506: my $source = $filepath.'/'.$file;
5507: my $logfile;
5508: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 5509: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 5510: }
5511: print $logfile
5512: "\n================= Publish ".localtime()." ================\n".
5513: $env{'user.name'}.':'.$env{'user.domain'}."\n";
5514: # Save the file
5515: if (!open(FH,'>'.$source)) {
5516: &Apache::lonnet::logthis('Failed to create '.$source);
5517: return (&mt('Failed to create file'));
5518: }
5519: if ($action eq 'upload') {
5520: if (!print FH ($env{'form.'.$formname})) {
5521: &Apache::lonnet::logthis('Failed to write to '.$source);
5522: return (&mt('Failed to write file'));
5523: }
5524: } else {
5525: my $original = &Apache::lonnet::filelocation('',$formname);
5526: if(!copy($original,$source)) {
5527: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
5528: return (&mt('Failed to write file'));
5529: }
5530: }
5531: close(FH);
5532: chmod(0660, $source); # Permissions to rw-rw---.
5533:
5534: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
5535: my $copyfile=$targetdir.'/'.$file;
5536:
5537: my @parts=split(/\//,$targetdir);
5538: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
5539: for (my $count=5;$count<=$#parts;$count++) {
5540: $path.="/$parts[$count]";
5541: if (!-e $path) {
5542: print $logfile "\nCreating directory ".$path;
5543: mkdir($path,02770);
5544: }
5545: }
5546: my $versionresult;
5547: if (-e $copyfile) {
5548: $versionresult = &logo_versioning($targetdir,$file,$logfile);
5549: } else {
5550: $versionresult = 'ok';
5551: }
5552: if ($versionresult eq 'ok') {
5553: if (copy($source,$copyfile)) {
5554: print $logfile "\nCopied original source to ".$copyfile."\n";
5555: $output = 'ok';
5556: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 5557: push(@{$modified_urls},[$copyfile,$source]);
5558: my $metaoutput =
5559: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
5560: unless ($registered_cleanup) {
5561: my $handlers = $r->get_handlers('PerlCleanupHandler');
5562: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5563: $registered_cleanup=1;
5564: }
1.9 raeburn 5565: } else {
5566: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
5567: $output = &mt('Failed to copy file to RES space').", $!";
5568: }
5569: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5570: my $inputfile = $filepath.'/'.$file;
5571: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 5572: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5573: if ($fullwidth ne '' && $fullheight ne '') {
5574: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5575: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5576: system("convert -sample $thumbsize $inputfile $outfile");
5577: chmod(0660, $filepath.'/tn-'.$file);
5578: if (-e $outfile) {
5579: my $copyfile=$targetdir.'/tn-'.$file;
5580: if (copy($outfile,$copyfile)) {
5581: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 5582: my $thumb_metaoutput =
5583: &write_metadata($dom,$confname,$formname,
5584: $targetdir,'tn-'.$file,$logfile);
5585: push(@{$modified_urls},[$copyfile,$outfile]);
5586: unless ($registered_cleanup) {
5587: my $handlers = $r->get_handlers('PerlCleanupHandler');
5588: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5589: $registered_cleanup=1;
5590: }
1.16 raeburn 5591: } else {
5592: print $logfile "\nUnable to write ".$copyfile.
5593: ':'.$!."\n";
5594: }
5595: }
1.9 raeburn 5596: }
5597: }
5598: }
5599: } else {
5600: $output = $versionresult;
5601: }
5602: }
5603: return ($output,$logourl);
5604: }
5605:
5606: sub logo_versioning {
5607: my ($targetdir,$file,$logfile) = @_;
5608: my $target = $targetdir.'/'.$file;
5609: my ($maxversion,$fn,$extn,$output);
5610: $maxversion = 0;
5611: if ($file =~ /^(.+)\.(\w+)$/) {
5612: $fn=$1;
5613: $extn=$2;
5614: }
5615: opendir(DIR,$targetdir);
5616: while (my $filename=readdir(DIR)) {
5617: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
5618: $maxversion=($1>$maxversion)?$1:$maxversion;
5619: }
5620: }
5621: $maxversion++;
5622: print $logfile "\nCreating old version ".$maxversion."\n";
5623: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
5624: if (copy($target,$copyfile)) {
5625: print $logfile "Copied old target to ".$copyfile."\n";
5626: $copyfile=$copyfile.'.meta';
5627: if (copy($target.'.meta',$copyfile)) {
5628: print $logfile "Copied old target metadata to ".$copyfile."\n";
5629: $output = 'ok';
5630: } else {
5631: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
5632: $output = &mt('Failed to copy old meta').", $!, ";
5633: }
5634: } else {
5635: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
5636: $output = &mt('Failed to copy old target').", $!, ";
5637: }
5638: return $output;
5639: }
5640:
5641: sub write_metadata {
5642: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
5643: my (%metadatafields,%metadatakeys,$output);
5644: $metadatafields{'title'}=$formname;
5645: $metadatafields{'creationdate'}=time;
5646: $metadatafields{'lastrevisiondate'}=time;
5647: $metadatafields{'copyright'}='public';
5648: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
5649: $env{'user.domain'};
5650: $metadatafields{'authorspace'}=$confname.':'.$dom;
5651: $metadatafields{'domain'}=$dom;
5652: {
5653: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
5654: my $mfh;
1.155 raeburn 5655: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 5656: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 5657: unless ($_=~/\./) {
5658: my $unikey=$_;
5659: $unikey=~/^([A-Za-z]+)/;
5660: my $tag=$1;
5661: $tag=~tr/A-Z/a-z/;
5662: print $mfh "\n\<$tag";
5663: foreach (split(/\,/,$metadatakeys{$unikey})) {
5664: my $value=$metadatafields{$unikey.'.'.$_};
5665: $value=~s/\"/\'\'/g;
5666: print $mfh ' '.$_.'="'.$value.'"';
5667: }
5668: print $mfh '>'.
5669: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
5670: .'</'.$tag.'>';
5671: }
5672: }
5673: $output = 'ok';
5674: print $logfile "\nWrote metadata";
5675: close($mfh);
5676: } else {
5677: print $logfile "\nFailed to open metadata file";
1.9 raeburn 5678: $output = &mt('Could not write metadata');
5679: }
5680: }
1.155 raeburn 5681: return $output;
5682: }
5683:
5684: sub notifysubscribed {
5685: foreach my $targetsource (@{$modified_urls}){
5686: next unless (ref($targetsource) eq 'ARRAY');
5687: my ($target,$source)=@{$targetsource};
5688: if ($source ne '') {
5689: if (open(my $logfh,'>>'.$source.'.log')) {
5690: print $logfh "\nCleanup phase: Notifications\n";
5691: my @subscribed=&subscribed_hosts($target);
5692: foreach my $subhost (@subscribed) {
5693: print $logfh "\nNotifying host ".$subhost.':';
5694: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
5695: print $logfh $reply;
5696: }
5697: my @subscribedmeta=&subscribed_hosts("$target.meta");
5698: foreach my $subhost (@subscribedmeta) {
5699: print $logfh "\nNotifying host for metadata only ".$subhost.':';
5700: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
5701: $subhost);
5702: print $logfh $reply;
5703: }
5704: print $logfh "\n============ Done ============\n";
1.160 raeburn 5705: close($logfh);
1.155 raeburn 5706: }
5707: }
5708: }
5709: return OK;
5710: }
5711:
5712: sub subscribed_hosts {
5713: my ($target) = @_;
5714: my @subscribed;
5715: if (open(my $fh,"<$target.subscription")) {
5716: while (my $subline=<$fh>) {
5717: if ($subline =~ /^($match_lonid):/) {
5718: my $host = $1;
5719: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
5720: unless (grep(/^\Q$host\E$/,@subscribed)) {
5721: push(@subscribed,$host);
5722: }
5723: }
5724: }
5725: }
5726: }
5727: return @subscribed;
1.9 raeburn 5728: }
5729:
5730: sub check_switchserver {
5731: my ($dom,$confname) = @_;
5732: my ($allowed,$switchserver);
5733: my $home = &Apache::lonnet::homeserver($confname,$dom);
5734: if ($home eq 'no_host') {
5735: $home = &Apache::lonnet::domain($dom,'primary');
5736: }
5737: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 5738: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
5739: if (!$allowed) {
1.180 raeburn 5740: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 5741: }
5742: return $switchserver;
5743: }
5744:
1.1 raeburn 5745: sub modify_quotas {
1.86 raeburn 5746: my ($dom,$action,%domconfig) = @_;
1.101 raeburn 5747: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
5748: %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86 raeburn 5749: if ($action eq 'quotas') {
5750: $context = 'tools';
1.163 raeburn 5751: } else {
1.86 raeburn 5752: $context = $action;
5753: }
5754: if ($context eq 'requestcourses') {
1.98 raeburn 5755: @usertools = ('official','unofficial','community');
1.106 raeburn 5756: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 5757: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
5758: %titles = &courserequest_titles();
5759: $toolregexp = join('|',@usertools);
5760: %conditions = &courserequest_conditions();
1.163 raeburn 5761: } elsif ($context eq 'requestauthor') {
5762: @usertools = ('author');
5763: %titles = &authorrequest_titles();
1.86 raeburn 5764: } else {
1.162 raeburn 5765: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 5766: %titles = &tool_titles();
1.86 raeburn 5767: }
1.72 raeburn 5768: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44 raeburn 5769: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5770: foreach my $key (keys(%env)) {
1.101 raeburn 5771: if ($context eq 'requestcourses') {
5772: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
5773: my $item = $1;
5774: my $type = $2;
5775: if ($type =~ /^limit_(.+)/) {
5776: $limithash{$item}{$1} = $env{$key};
5777: } else {
5778: $confhash{$item}{$type} = $env{$key};
5779: }
5780: }
1.163 raeburn 5781: } elsif ($context eq 'requestauthor') {
5782: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
5783: $confhash{$1} = $env{$key};
5784: }
1.101 raeburn 5785: } else {
1.86 raeburn 5786: if ($key =~ /^form\.quota_(.+)$/) {
5787: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 5788: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
5789: $confhash{'authorquota'}{$1} = $env{$key};
5790: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 5791: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
5792: }
1.72 raeburn 5793: }
5794: }
1.163 raeburn 5795: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.102 raeburn 5796: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
5797: @approvalnotify = sort(@approvalnotify);
5798: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
5799: if (ref($domconfig{$action}) eq 'HASH') {
5800: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
5801: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
5802: $changes{'notify'}{'approval'} = 1;
5803: }
5804: } else {
1.144 raeburn 5805: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5806: $changes{'notify'}{'approval'} = 1;
5807: }
5808: }
5809: } else {
1.144 raeburn 5810: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5811: $changes{'notify'}{'approval'} = 1;
5812: }
5813: }
5814: } else {
1.86 raeburn 5815: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 5816: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 5817: }
1.72 raeburn 5818: foreach my $item (@usertools) {
5819: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 5820: my $unset;
1.101 raeburn 5821: if ($context eq 'requestcourses') {
1.104 raeburn 5822: $unset = '0';
5823: if ($type eq '_LC_adv') {
5824: $unset = '';
5825: }
1.101 raeburn 5826: if ($confhash{$item}{$type} eq 'autolimit') {
5827: $confhash{$item}{$type} .= '=';
5828: unless ($limithash{$item}{$type} =~ /\D/) {
5829: $confhash{$item}{$type} .= $limithash{$item}{$type};
5830: }
5831: }
1.163 raeburn 5832: } elsif ($context eq 'requestauthor') {
5833: $unset = '0';
5834: if ($type eq '_LC_adv') {
5835: $unset = '';
5836: }
1.72 raeburn 5837: } else {
1.101 raeburn 5838: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
5839: $confhash{$item}{$type} = 1;
5840: } else {
5841: $confhash{$item}{$type} = 0;
5842: }
1.72 raeburn 5843: }
1.86 raeburn 5844: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 5845: if ($action eq 'requestauthor') {
5846: if ($domconfig{$action}{$type} ne $confhash{$type}) {
5847: $changes{$type} = 1;
5848: }
5849: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 5850: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
5851: $changes{$item}{$type} = 1;
5852: }
5853: } else {
5854: if ($context eq 'requestcourses') {
1.104 raeburn 5855: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 5856: $changes{$item}{$type} = 1;
5857: }
5858: } else {
5859: if (!$confhash{$item}{$type}) {
5860: $changes{$item}{$type} = 1;
5861: }
5862: }
5863: }
5864: } else {
5865: if ($context eq 'requestcourses') {
1.104 raeburn 5866: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 5867: $changes{$item}{$type} = 1;
5868: }
1.163 raeburn 5869: } elsif ($context eq 'requestauthor') {
5870: if ($confhash{$type} ne $unset) {
5871: $changes{$type} = 1;
5872: }
1.72 raeburn 5873: } else {
5874: if (!$confhash{$item}{$type}) {
5875: $changes{$item}{$type} = 1;
5876: }
5877: }
5878: }
1.1 raeburn 5879: }
5880: }
1.163 raeburn 5881: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 5882: if (ref($domconfig{'quotas'}) eq 'HASH') {
5883: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5884: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
5885: if (exists($confhash{'defaultquota'}{$key})) {
5886: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
5887: $changes{'defaultquota'}{$key} = 1;
5888: }
5889: } else {
5890: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 5891: }
5892: }
1.86 raeburn 5893: } else {
5894: foreach my $key (keys(%{$domconfig{'quotas'}})) {
5895: if (exists($confhash{'defaultquota'}{$key})) {
5896: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
5897: $changes{'defaultquota'}{$key} = 1;
5898: }
5899: } else {
5900: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 5901: }
1.1 raeburn 5902: }
5903: }
1.197 raeburn 5904: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
5905: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
5906: if (exists($confhash{'authorquota'}{$key})) {
5907: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
5908: $changes{'authorquota'}{$key} = 1;
5909: }
5910: } else {
5911: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
5912: }
5913: }
5914: }
1.1 raeburn 5915: }
1.86 raeburn 5916: if (ref($confhash{'defaultquota'}) eq 'HASH') {
5917: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
5918: if (ref($domconfig{'quotas'}) eq 'HASH') {
5919: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5920: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
5921: $changes{'defaultquota'}{$key} = 1;
5922: }
5923: } else {
5924: if (!exists($domconfig{'quotas'}{$key})) {
5925: $changes{'defaultquota'}{$key} = 1;
5926: }
1.72 raeburn 5927: }
5928: } else {
1.86 raeburn 5929: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 5930: }
1.1 raeburn 5931: }
5932: }
1.197 raeburn 5933: if (ref($confhash{'authorquota'}) eq 'HASH') {
5934: foreach my $key (keys(%{$confhash{'authorquota'}})) {
5935: if (ref($domconfig{'quotas'}) eq 'HASH') {
5936: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
5937: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
5938: $changes{'authorquota'}{$key} = 1;
5939: }
5940: } else {
5941: $changes{'authorquota'}{$key} = 1;
5942: }
5943: } else {
5944: $changes{'authorquota'}{$key} = 1;
5945: }
5946: }
5947: }
1.1 raeburn 5948: }
1.72 raeburn 5949:
1.163 raeburn 5950: if ($context eq 'requestauthor') {
5951: $domdefaults{'requestauthor'} = \%confhash;
5952: } else {
5953: foreach my $key (keys(%confhash)) {
5954: $domdefaults{$key} = $confhash{$key};
5955: }
1.72 raeburn 5956: }
1.163 raeburn 5957:
1.1 raeburn 5958: my %quotahash = (
1.86 raeburn 5959: $action => { %confhash }
1.1 raeburn 5960: );
5961: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
5962: $dom);
5963: if ($putresult eq 'ok') {
5964: if (keys(%changes) > 0) {
1.72 raeburn 5965: my $cachetime = 24*60*60;
5966: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
5967:
1.1 raeburn 5968: $resulttext = &mt('Changes made:').'<ul>';
1.163 raeburn 5969: unless (($context eq 'requestcourses') ||
5970: ($context eq 'requestauthor')) {
1.86 raeburn 5971: if (ref($changes{'defaultquota'}) eq 'HASH') {
5972: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
5973: foreach my $type (@{$types},'default') {
5974: if (defined($changes{'defaultquota'}{$type})) {
5975: my $typetitle = $usertypes->{$type};
5976: if ($type eq 'default') {
5977: $typetitle = $othertitle;
5978: }
5979: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 5980: }
5981: }
1.86 raeburn 5982: $resulttext .= '</ul></li>';
1.72 raeburn 5983: }
1.197 raeburn 5984: if (ref($changes{'authorquota'}) eq 'HASH') {
5985: $resulttext .= '<li>'.&mt('Authoring space default quotas').'<ul>';
5986: foreach my $type (@{$types},'default') {
5987: if (defined($changes{'authorquota'}{$type})) {
5988: my $typetitle = $usertypes->{$type};
5989: if ($type eq 'default') {
5990: $typetitle = $othertitle;
5991: }
5992: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
5993: }
5994: }
5995: $resulttext .= '</ul></li>';
5996: }
1.72 raeburn 5997: }
1.80 raeburn 5998: my %newenv;
1.72 raeburn 5999: foreach my $item (@usertools) {
1.163 raeburn 6000: my (%haschgs,%inconf);
6001: if ($context eq 'requestauthor') {
6002: %haschgs = %changes;
6003: %inconf = %confhash;
6004: } else {
6005: if (ref($changes{$item}) eq 'HASH') {
6006: %haschgs = %{$changes{$item}};
6007: }
6008: if (ref($confhash{$item}) eq 'HASH') {
6009: %inconf = %{$confhash{$item}};
6010: }
6011: }
6012: if (keys(%haschgs) > 0) {
1.80 raeburn 6013: my $newacc =
6014: &Apache::lonnet::usertools_access($env{'user.name'},
6015: $env{'user.domain'},
1.86 raeburn 6016: $item,'reload',$context);
1.163 raeburn 6017: if (($context eq 'requestcourses') ||
6018: ($context eq 'requestauthor')) {
1.108 raeburn 6019: if ($env{'environment.canrequest.'.$item} ne $newacc) {
6020: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 6021: }
6022: } else {
6023: if ($env{'environment.availabletools.'.$item} ne $newacc) {
6024: $newenv{'environment.availabletools.'.$item} = $newacc;
6025: }
1.80 raeburn 6026: }
1.163 raeburn 6027: unless ($context eq 'requestauthor') {
6028: $resulttext .= '<li>'.$titles{$item}.'<ul>';
6029: }
1.72 raeburn 6030: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 6031: if ($haschgs{$type}) {
1.72 raeburn 6032: my $typetitle = $usertypes->{$type};
6033: if ($type eq 'default') {
6034: $typetitle = $othertitle;
6035: } elsif ($type eq '_LC_adv') {
6036: $typetitle = 'LON-CAPA Advanced Users';
6037: }
1.163 raeburn 6038: if ($inconf{$type}) {
1.101 raeburn 6039: if ($context eq 'requestcourses') {
6040: my $cond;
1.163 raeburn 6041: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 6042: if ($1 eq '') {
6043: $cond = &mt('(Automatic processing of any request).');
6044: } else {
6045: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
6046: }
6047: } else {
1.163 raeburn 6048: $cond = $conditions{$inconf{$type}};
1.101 raeburn 6049: }
6050: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 6051: } elsif ($context eq 'requestauthor') {
6052: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
6053: $titles{$inconf{$type}},$typetitle);
6054:
1.101 raeburn 6055: } else {
6056: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
6057: }
1.72 raeburn 6058: } else {
1.104 raeburn 6059: if ($type eq '_LC_adv') {
1.163 raeburn 6060: if ($inconf{$type} eq '0') {
1.104 raeburn 6061: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6062: } else {
6063: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
6064: }
6065: } else {
6066: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6067: }
1.72 raeburn 6068: }
6069: }
1.26 raeburn 6070: }
1.163 raeburn 6071: unless ($context eq 'requestauthor') {
6072: $resulttext .= '</ul></li>';
6073: }
1.26 raeburn 6074: }
1.1 raeburn 6075: }
1.163 raeburn 6076: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 6077: if (ref($changes{'notify'}) eq 'HASH') {
6078: if ($changes{'notify'}{'approval'}) {
6079: if (ref($confhash{'notify'}) eq 'HASH') {
6080: if ($confhash{'notify'}{'approval'}) {
6081: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
6082: } else {
1.163 raeburn 6083: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 6084: }
6085: }
6086: }
6087: }
6088: }
1.1 raeburn 6089: $resulttext .= '</ul>';
1.80 raeburn 6090: if (keys(%newenv)) {
6091: &Apache::lonnet::appenv(\%newenv);
6092: }
1.1 raeburn 6093: } else {
1.86 raeburn 6094: if ($context eq 'requestcourses') {
6095: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 6096: } elsif ($context eq 'requestauthor') {
6097: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 6098: } else {
1.90 weissno 6099: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 6100: }
1.1 raeburn 6101: }
6102: } else {
1.11 albertel 6103: $resulttext = '<span class="LC_error">'.
6104: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6105: }
1.3 raeburn 6106: return $resulttext;
1.1 raeburn 6107: }
6108:
1.3 raeburn 6109: sub modify_autoenroll {
6110: my ($dom,%domconfig) = @_;
1.1 raeburn 6111: my ($resulttext,%changes);
6112: my %currautoenroll;
6113: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6114: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
6115: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
6116: }
6117: }
6118: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
6119: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 6120: sender => 'Sender for notification messages',
6121: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 6122: my @offon = ('off','on');
1.17 raeburn 6123: my $sender_uname = $env{'form.sender_uname'};
6124: my $sender_domain = $env{'form.sender_domain'};
6125: if ($sender_domain eq '') {
6126: $sender_uname = '';
6127: } elsif ($sender_uname eq '') {
6128: $sender_domain = '';
6129: }
1.129 raeburn 6130: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 6131: my %autoenrollhash = (
1.129 raeburn 6132: autoenroll => { 'run' => $env{'form.autoenroll_run'},
6133: 'sender_uname' => $sender_uname,
6134: 'sender_domain' => $sender_domain,
6135: 'co-owners' => $coowners,
1.1 raeburn 6136: }
6137: );
1.4 raeburn 6138: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
6139: $dom);
1.1 raeburn 6140: if ($putresult eq 'ok') {
6141: if (exists($currautoenroll{'run'})) {
6142: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
6143: $changes{'run'} = 1;
6144: }
6145: } elsif ($autorun) {
6146: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 6147: $changes{'run'} = 1;
1.1 raeburn 6148: }
6149: }
1.17 raeburn 6150: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 6151: $changes{'sender'} = 1;
6152: }
1.17 raeburn 6153: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 6154: $changes{'sender'} = 1;
6155: }
1.129 raeburn 6156: if ($currautoenroll{'co-owners'} ne '') {
6157: if ($currautoenroll{'co-owners'} ne $coowners) {
6158: $changes{'coowners'} = 1;
6159: }
6160: } elsif ($coowners) {
6161: $changes{'coowners'} = 1;
6162: }
1.1 raeburn 6163: if (keys(%changes) > 0) {
6164: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 6165: if ($changes{'run'}) {
1.1 raeburn 6166: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
6167: }
6168: if ($changes{'sender'}) {
1.17 raeburn 6169: if ($sender_uname eq '' || $sender_domain eq '') {
6170: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
6171: } else {
6172: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
6173: }
1.1 raeburn 6174: }
1.129 raeburn 6175: if ($changes{'coowners'}) {
6176: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
6177: &Apache::loncommon::devalidate_domconfig_cache($dom);
6178: }
1.1 raeburn 6179: $resulttext .= '</ul>';
6180: } else {
6181: $resulttext = &mt('No changes made to auto-enrollment settings');
6182: }
6183: } else {
1.11 albertel 6184: $resulttext = '<span class="LC_error">'.
6185: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6186: }
1.3 raeburn 6187: return $resulttext;
1.1 raeburn 6188: }
6189:
6190: sub modify_autoupdate {
1.3 raeburn 6191: my ($dom,%domconfig) = @_;
1.1 raeburn 6192: my ($resulttext,%currautoupdate,%fields,%changes);
6193: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
6194: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
6195: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
6196: }
6197: }
6198: my @offon = ('off','on');
6199: my %title = &Apache::lonlocal::texthash (
6200: run => 'Auto-update:',
6201: classlists => 'Updates to user information in classlists?'
6202: );
1.44 raeburn 6203: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6204: my %fieldtitles = &Apache::lonlocal::texthash (
6205: id => 'Student/Employee ID',
1.20 raeburn 6206: permanentemail => 'E-mail address',
1.1 raeburn 6207: lastname => 'Last Name',
6208: firstname => 'First Name',
6209: middlename => 'Middle Name',
1.132 raeburn 6210: generation => 'Generation',
1.1 raeburn 6211: );
1.142 raeburn 6212: $othertitle = &mt('All users');
1.1 raeburn 6213: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 6214: $othertitle = &mt('Other users');
1.1 raeburn 6215: }
6216: foreach my $key (keys(%env)) {
6217: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 6218: my ($usertype,$item) = ($1,$2);
6219: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
6220: if ($usertype eq 'default') {
6221: push(@{$fields{$1}},$2);
6222: } elsif (ref($types) eq 'ARRAY') {
6223: if (grep(/^\Q$usertype\E$/,@{$types})) {
6224: push(@{$fields{$1}},$2);
6225: }
6226: }
6227: }
1.1 raeburn 6228: }
6229: }
1.131 raeburn 6230: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
6231: @lockablenames = sort(@lockablenames);
6232: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
6233: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6234: if (@changed) {
6235: $changes{'lockablenames'} = 1;
6236: }
6237: } else {
6238: if (@lockablenames) {
6239: $changes{'lockablenames'} = 1;
6240: }
6241: }
1.1 raeburn 6242: my %updatehash = (
6243: autoupdate => { run => $env{'form.autoupdate_run'},
6244: classlists => $env{'form.classlists'},
6245: fields => {%fields},
1.131 raeburn 6246: lockablenames => \@lockablenames,
1.1 raeburn 6247: }
6248: );
6249: foreach my $key (keys(%currautoupdate)) {
6250: if (($key eq 'run') || ($key eq 'classlists')) {
6251: if (exists($updatehash{autoupdate}{$key})) {
6252: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
6253: $changes{$key} = 1;
6254: }
6255: }
6256: } elsif ($key eq 'fields') {
6257: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 6258: foreach my $item (@{$types},'default') {
1.1 raeburn 6259: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
6260: my $change = 0;
6261: foreach my $type (@{$currautoupdate{$key}{$item}}) {
6262: if (!exists($fields{$item})) {
6263: $change = 1;
1.132 raeburn 6264: last;
1.1 raeburn 6265: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 6266: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 6267: $change = 1;
1.132 raeburn 6268: last;
1.1 raeburn 6269: }
6270: }
6271: }
6272: if ($change) {
6273: push(@{$changes{$key}},$item);
6274: }
1.26 raeburn 6275: }
1.1 raeburn 6276: }
6277: }
1.131 raeburn 6278: } elsif ($key eq 'lockablenames') {
6279: if (ref($currautoupdate{$key}) eq 'ARRAY') {
6280: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6281: if (@changed) {
6282: $changes{'lockablenames'} = 1;
6283: }
6284: } else {
6285: if (@lockablenames) {
6286: $changes{'lockablenames'} = 1;
6287: }
6288: }
6289: }
6290: }
6291: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
6292: if (@lockablenames) {
6293: $changes{'lockablenames'} = 1;
1.1 raeburn 6294: }
6295: }
1.26 raeburn 6296: foreach my $item (@{$types},'default') {
6297: if (defined($fields{$item})) {
6298: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 6299: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
6300: my $change = 0;
6301: if (ref($fields{$item}) eq 'ARRAY') {
6302: foreach my $type (@{$fields{$item}}) {
6303: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
6304: $change = 1;
6305: last;
6306: }
6307: }
6308: }
6309: if ($change) {
6310: push(@{$changes{'fields'}},$item);
6311: }
6312: } else {
1.26 raeburn 6313: push(@{$changes{'fields'}},$item);
6314: }
6315: } else {
6316: push(@{$changes{'fields'}},$item);
1.1 raeburn 6317: }
6318: }
6319: }
6320: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
6321: $dom);
6322: if ($putresult eq 'ok') {
6323: if (keys(%changes) > 0) {
6324: $resulttext = &mt('Changes made:').'<ul>';
6325: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 6326: if ($key eq 'lockablenames') {
6327: $resulttext .= '<li>';
6328: if (@lockablenames) {
6329: $usertypes->{'default'} = $othertitle;
6330: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
6331: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
6332: } else {
6333: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
6334: }
6335: $resulttext .= '</li>';
6336: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 6337: foreach my $item (@{$changes{$key}}) {
6338: my @newvalues;
6339: foreach my $type (@{$fields{$item}}) {
6340: push(@newvalues,$fieldtitles{$type});
6341: }
1.3 raeburn 6342: my $newvaluestr;
6343: if (@newvalues > 0) {
6344: $newvaluestr = join(', ',@newvalues);
6345: } else {
6346: $newvaluestr = &mt('none');
1.6 raeburn 6347: }
1.1 raeburn 6348: if ($item eq 'default') {
1.26 raeburn 6349: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 6350: } else {
1.26 raeburn 6351: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 6352: }
6353: }
6354: } else {
6355: my $newvalue;
6356: if ($key eq 'run') {
6357: $newvalue = $offon[$env{'form.autoupdate_run'}];
6358: } else {
6359: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 6360: }
1.1 raeburn 6361: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
6362: }
6363: }
6364: $resulttext .= '</ul>';
6365: } else {
1.3 raeburn 6366: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 6367: }
6368: } else {
1.11 albertel 6369: $resulttext = '<span class="LC_error">'.
6370: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6371: }
1.3 raeburn 6372: return $resulttext;
1.1 raeburn 6373: }
6374:
1.125 raeburn 6375: sub modify_autocreate {
6376: my ($dom,%domconfig) = @_;
6377: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
6378: if (ref($domconfig{'autocreate'}) eq 'HASH') {
6379: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
6380: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
6381: }
6382: }
6383: my %title= ( xml => 'Auto-creation of courses in XML course description files',
6384: req => 'Auto-creation of validated requests for official courses',
6385: xmldc => 'Identity of course creator of courses from XML files',
6386: );
6387: my @types = ('xml','req');
6388: foreach my $item (@types) {
6389: $newvals{$item} = $env{'form.autocreate_'.$item};
6390: $newvals{$item} =~ s/\D//g;
6391: $newvals{$item} = 0 if ($newvals{$item} eq '');
6392: }
6393: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
6394: my %domcoords = &get_active_dcs($dom);
6395: unless (exists($domcoords{$newvals{'xmldc'}})) {
6396: $newvals{'xmldc'} = '';
6397: }
6398: %autocreatehash = (
6399: autocreate => { xml => $newvals{'xml'},
6400: req => $newvals{'req'},
6401: }
6402: );
6403: if ($newvals{'xmldc'} ne '') {
6404: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
6405: }
6406: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
6407: $dom);
6408: if ($putresult eq 'ok') {
6409: my @items = @types;
6410: if ($newvals{'xml'}) {
6411: push(@items,'xmldc');
6412: }
6413: foreach my $item (@items) {
6414: if (exists($currautocreate{$item})) {
6415: if ($currautocreate{$item} ne $newvals{$item}) {
6416: $changes{$item} = 1;
6417: }
6418: } elsif ($newvals{$item}) {
6419: $changes{$item} = 1;
6420: }
6421: }
6422: if (keys(%changes) > 0) {
6423: my @offon = ('off','on');
6424: $resulttext = &mt('Changes made:').'<ul>';
6425: foreach my $item (@types) {
6426: if ($changes{$item}) {
6427: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 6428: $resulttext .= '<li>'.
6429: &mt("$title{$item} set to [_1]$newtxt [_2]",
6430: '<b>','</b>').
6431: '</li>';
1.125 raeburn 6432: }
6433: }
6434: if ($changes{'xmldc'}) {
6435: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
6436: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 6437: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 6438: }
6439: $resulttext .= '</ul>';
6440: } else {
6441: $resulttext = &mt('No changes made to auto-creation settings');
6442: }
6443: } else {
6444: $resulttext = '<span class="LC_error">'.
6445: &mt('An error occurred: [_1]',$putresult).'</span>';
6446: }
6447: return $resulttext;
6448: }
6449:
1.23 raeburn 6450: sub modify_directorysrch {
6451: my ($dom,%domconfig) = @_;
6452: my ($resulttext,%changes);
6453: my %currdirsrch;
6454: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
6455: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
6456: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
6457: }
6458: }
6459: my %title = ( available => 'Directory search available',
1.24 raeburn 6460: localonly => 'Other domains can search',
1.23 raeburn 6461: searchby => 'Search types',
6462: searchtypes => 'Search latitude');
6463: my @offon = ('off','on');
1.24 raeburn 6464: my @otherdoms = ('Yes','No');
1.23 raeburn 6465:
1.25 raeburn 6466: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 6467: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
6468: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
6469:
1.44 raeburn 6470: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 6471: if (keys(%{$usertypes}) == 0) {
6472: @cansearch = ('default');
6473: } else {
6474: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
6475: foreach my $type (@{$currdirsrch{'cansearch'}}) {
6476: if (!grep(/^\Q$type\E$/,@cansearch)) {
6477: push(@{$changes{'cansearch'}},$type);
6478: }
1.23 raeburn 6479: }
1.26 raeburn 6480: foreach my $type (@cansearch) {
6481: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
6482: push(@{$changes{'cansearch'}},$type);
6483: }
1.23 raeburn 6484: }
1.26 raeburn 6485: } else {
6486: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 6487: }
6488: }
6489:
6490: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
6491: foreach my $by (@{$currdirsrch{'searchby'}}) {
6492: if (!grep(/^\Q$by\E$/,@searchby)) {
6493: push(@{$changes{'searchby'}},$by);
6494: }
6495: }
6496: foreach my $by (@searchby) {
6497: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
6498: push(@{$changes{'searchby'}},$by);
6499: }
6500: }
6501: } else {
6502: push(@{$changes{'searchby'}},@searchby);
6503: }
1.25 raeburn 6504:
6505: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
6506: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
6507: if (!grep(/^\Q$type\E$/,@searchtypes)) {
6508: push(@{$changes{'searchtypes'}},$type);
6509: }
6510: }
6511: foreach my $type (@searchtypes) {
6512: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
6513: push(@{$changes{'searchtypes'}},$type);
6514: }
6515: }
6516: } else {
6517: if (exists($currdirsrch{'searchtypes'})) {
6518: foreach my $type (@searchtypes) {
6519: if ($type ne $currdirsrch{'searchtypes'}) {
6520: push(@{$changes{'searchtypes'}},$type);
6521: }
6522: }
6523: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
6524: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
6525: }
6526: } else {
6527: push(@{$changes{'searchtypes'}},@searchtypes);
6528: }
6529: }
6530:
1.23 raeburn 6531: my %dirsrch_hash = (
6532: directorysrch => { available => $env{'form.dirsrch_available'},
6533: cansearch => \@cansearch,
1.24 raeburn 6534: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 6535: searchby => \@searchby,
1.25 raeburn 6536: searchtypes => \@searchtypes,
1.23 raeburn 6537: }
6538: );
6539: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
6540: $dom);
6541: if ($putresult eq 'ok') {
6542: if (exists($currdirsrch{'available'})) {
6543: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
6544: $changes{'available'} = 1;
6545: }
6546: } else {
6547: if ($env{'form.dirsrch_available'} eq '1') {
6548: $changes{'available'} = 1;
6549: }
6550: }
1.24 raeburn 6551: if (exists($currdirsrch{'localonly'})) {
6552: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
6553: $changes{'localonly'} = 1;
6554: }
6555: } else {
6556: if ($env{'form.dirsrch_localonly'} eq '1') {
6557: $changes{'localonly'} = 1;
6558: }
6559: }
1.23 raeburn 6560: if (keys(%changes) > 0) {
6561: $resulttext = &mt('Changes made:').'<ul>';
6562: if ($changes{'available'}) {
6563: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
6564: }
1.24 raeburn 6565: if ($changes{'localonly'}) {
6566: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
6567: }
6568:
1.23 raeburn 6569: if (ref($changes{'cansearch'}) eq 'ARRAY') {
6570: my $chgtext;
1.26 raeburn 6571: if (ref($usertypes) eq 'HASH') {
6572: if (keys(%{$usertypes}) > 0) {
6573: foreach my $type (@{$types}) {
6574: if (grep(/^\Q$type\E$/,@cansearch)) {
6575: $chgtext .= $usertypes->{$type}.'; ';
6576: }
6577: }
6578: if (grep(/^default$/,@cansearch)) {
6579: $chgtext .= $othertitle;
6580: } else {
6581: $chgtext =~ s/\; $//;
6582: }
1.178 raeburn 6583: $resulttext .=
6584: '<li>'.
6585: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
6586: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
6587: '</li>';
1.23 raeburn 6588: }
6589: }
6590: }
6591: if (ref($changes{'searchby'}) eq 'ARRAY') {
6592: my ($searchtitles,$titleorder) = &sorted_searchtitles();
6593: my $chgtext;
6594: foreach my $type (@{$titleorder}) {
6595: if (grep(/^\Q$type\E$/,@searchby)) {
6596: if (defined($searchtitles->{$type})) {
6597: $chgtext .= $searchtitles->{$type}.'; ';
6598: }
6599: }
6600: }
6601: $chgtext =~ s/\; $//;
6602: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
6603: }
1.25 raeburn 6604: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
6605: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
6606: my $chgtext;
6607: foreach my $type (@{$srchtypeorder}) {
6608: if (grep(/^\Q$type\E$/,@searchtypes)) {
6609: if (defined($srchtypes_desc->{$type})) {
6610: $chgtext .= $srchtypes_desc->{$type}.'; ';
6611: }
6612: }
6613: }
6614: $chgtext =~ s/\; $//;
1.178 raeburn 6615: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 6616: }
6617: $resulttext .= '</ul>';
6618: } else {
6619: $resulttext = &mt('No changes made to institution directory search settings');
6620: }
6621: } else {
6622: $resulttext = '<span class="LC_error">'.
1.27 raeburn 6623: &mt('An error occurred: [_1]',$putresult).'</span>';
6624: }
6625: return $resulttext;
6626: }
6627:
1.28 raeburn 6628: sub modify_contacts {
6629: my ($dom,%domconfig) = @_;
6630: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
6631: if (ref($domconfig{'contacts'}) eq 'HASH') {
6632: foreach my $key (keys(%{$domconfig{'contacts'}})) {
6633: $currsetting{$key} = $domconfig{'contacts'}{$key};
6634: }
6635: }
1.134 raeburn 6636: my (%others,%to,%bcc);
1.28 raeburn 6637: my @contacts = ('supportemail','adminemail');
1.102 raeburn 6638: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.190 raeburn 6639: 'requestsmail','updatesmail');
1.28 raeburn 6640: foreach my $type (@mailings) {
6641: @{$newsetting{$type}} =
6642: &Apache::loncommon::get_env_multiple('form.'.$type);
6643: foreach my $item (@contacts) {
6644: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
6645: $contacts_hash{contacts}{$type}{$item} = 1;
6646: } else {
6647: $contacts_hash{contacts}{$type}{$item} = 0;
6648: }
6649: }
6650: $others{$type} = $env{'form.'.$type.'_others'};
6651: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 6652: if ($type eq 'helpdeskmail') {
6653: $bcc{$type} = $env{'form.'.$type.'_bcc'};
6654: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
6655: }
1.28 raeburn 6656: }
6657: foreach my $item (@contacts) {
6658: $to{$item} = $env{'form.'.$item};
6659: $contacts_hash{'contacts'}{$item} = $to{$item};
6660: }
6661: if (keys(%currsetting) > 0) {
6662: foreach my $item (@contacts) {
6663: if ($to{$item} ne $currsetting{$item}) {
6664: $changes{$item} = 1;
6665: }
6666: }
6667: foreach my $type (@mailings) {
6668: foreach my $item (@contacts) {
6669: if (ref($currsetting{$type}) eq 'HASH') {
6670: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
6671: push(@{$changes{$type}},$item);
6672: }
6673: } else {
6674: push(@{$changes{$type}},@{$newsetting{$type}});
6675: }
6676: }
6677: if ($others{$type} ne $currsetting{$type}{'others'}) {
6678: push(@{$changes{$type}},'others');
6679: }
1.134 raeburn 6680: if ($type eq 'helpdeskmail') {
6681: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
6682: push(@{$changes{$type}},'bcc');
6683: }
6684: }
1.28 raeburn 6685: }
6686: } else {
6687: my %default;
6688: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
6689: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
6690: $default{'errormail'} = 'adminemail';
6691: $default{'packagesmail'} = 'adminemail';
6692: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 6693: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 6694: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 6695: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 6696: foreach my $item (@contacts) {
6697: if ($to{$item} ne $default{$item}) {
6698: $changes{$item} = 1;
6699: }
6700: }
6701: foreach my $type (@mailings) {
6702: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
6703:
6704: push(@{$changes{$type}},@{$newsetting{$type}});
6705: }
6706: if ($others{$type} ne '') {
6707: push(@{$changes{$type}},'others');
1.134 raeburn 6708: }
6709: if ($type eq 'helpdeskmail') {
6710: if ($bcc{$type} ne '') {
6711: push(@{$changes{$type}},'bcc');
6712: }
6713: }
1.28 raeburn 6714: }
6715: }
6716: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
6717: $dom);
6718: if ($putresult eq 'ok') {
6719: if (keys(%changes) > 0) {
6720: my ($titles,$short_titles) = &contact_titles();
6721: $resulttext = &mt('Changes made:').'<ul>';
6722: foreach my $item (@contacts) {
6723: if ($changes{$item}) {
6724: $resulttext .= '<li>'.$titles->{$item}.
6725: &mt(' set to: ').
6726: '<span class="LC_cusr_emph">'.
6727: $to{$item}.'</span></li>';
6728: }
6729: }
6730: foreach my $type (@mailings) {
6731: if (ref($changes{$type}) eq 'ARRAY') {
6732: $resulttext .= '<li>'.$titles->{$type}.': ';
6733: my @text;
6734: foreach my $item (@{$newsetting{$type}}) {
6735: push(@text,$short_titles->{$item});
6736: }
6737: if ($others{$type} ne '') {
6738: push(@text,$others{$type});
6739: }
6740: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 6741: join(', ',@text).'</span>';
6742: if ($type eq 'helpdeskmail') {
6743: if ($bcc{$type} ne '') {
6744: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
6745: }
6746: }
6747: $resulttext .= '</li>';
1.28 raeburn 6748: }
6749: }
6750: $resulttext .= '</ul>';
6751: } else {
1.34 raeburn 6752: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 6753: }
6754: } else {
6755: $resulttext = '<span class="LC_error">'.
6756: &mt('An error occurred: [_1].',$putresult).'</span>';
6757: }
6758: return $resulttext;
6759: }
6760:
6761: sub modify_usercreation {
1.27 raeburn 6762: my ($dom,%domconfig) = @_;
1.34 raeburn 6763: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 6764: my $warningmsg;
1.27 raeburn 6765: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6766: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
6767: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
6768: }
6769: }
6770: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 6771: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 6772: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 6773: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 6774: foreach my $item(@contexts) {
1.45 raeburn 6775: if ($item eq 'selfcreate') {
1.50 raeburn 6776: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 6777: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6778: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 6779: if (ref($cancreate{$item}) eq 'ARRAY') {
6780: if (grep(/^login$/,@{$cancreate{$item}})) {
6781: $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.');
6782: }
1.43 raeburn 6783: }
6784: }
1.50 raeburn 6785: } else {
6786: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 6787: }
1.34 raeburn 6788: }
1.93 raeburn 6789: my ($othertitle,$usertypes,$types) =
6790: &Apache::loncommon::sorted_inst_types($dom);
6791: if (ref($types) eq 'ARRAY') {
6792: if (@{$types} > 0) {
6793: @{$cancreate{'statustocreate'}} =
6794: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 raeburn 6795: } else {
6796: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 6797: }
6798: push(@contexts,'statustocreate');
6799: }
1.165 raeburn 6800: &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
1.34 raeburn 6801: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
6802: foreach my $item (@contexts) {
1.93 raeburn 6803: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
6804: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 6805: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 raeburn 6806: if (ref($cancreate{$item}) eq 'ARRAY') {
6807: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
6808: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6809: push(@{$changes{'cancreate'}},$item);
6810: }
1.50 raeburn 6811: }
6812: }
6813: }
6814: } else {
6815: if ($curr_usercreation{'cancreate'}{$item} eq '') {
6816: if (@{$cancreate{$item}} > 0) {
6817: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6818: push(@{$changes{'cancreate'}},$item);
6819: }
6820: }
6821: } else {
6822: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
6823: if (@{$cancreate{$item}} < 3) {
6824: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6825: push(@{$changes{'cancreate'}},$item);
6826: }
6827: }
6828: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
6829: if (@{$cancreate{$item}} > 0) {
6830: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6831: push(@{$changes{'cancreate'}},$item);
6832: }
6833: }
6834: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
6835: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6836: push(@{$changes{'cancreate'}},$item);
6837: }
6838: }
6839: }
6840: }
6841: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6842: foreach my $type (@{$cancreate{$item}}) {
6843: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
6844: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
6845: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6846: push(@{$changes{'cancreate'}},$item);
6847: }
6848: }
6849: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
6850: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
6851: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
6852: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6853: push(@{$changes{'cancreate'}},$item);
6854: }
6855: }
6856: }
6857: }
6858: }
6859: } else {
6860: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
6861: push(@{$changes{'cancreate'}},$item);
6862: }
6863: }
1.27 raeburn 6864: }
1.34 raeburn 6865: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
6866: foreach my $item (@contexts) {
1.43 raeburn 6867: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 6868: if ($cancreate{$item} ne 'any') {
6869: push(@{$changes{'cancreate'}},$item);
6870: }
6871: } else {
6872: if ($cancreate{$item} ne 'none') {
6873: push(@{$changes{'cancreate'}},$item);
6874: }
1.27 raeburn 6875: }
6876: }
6877: } else {
1.43 raeburn 6878: foreach my $item (@contexts) {
1.34 raeburn 6879: push(@{$changes{'cancreate'}},$item);
6880: }
1.27 raeburn 6881: }
1.34 raeburn 6882:
1.27 raeburn 6883: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
6884: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
6885: if (!grep(/^\Q$type\E$/,@username_rule)) {
6886: push(@{$changes{'username_rule'}},$type);
6887: }
6888: }
6889: foreach my $type (@username_rule) {
6890: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
6891: push(@{$changes{'username_rule'}},$type);
6892: }
6893: }
6894: } else {
6895: push(@{$changes{'username_rule'}},@username_rule);
6896: }
6897:
1.32 raeburn 6898: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
6899: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
6900: if (!grep(/^\Q$type\E$/,@id_rule)) {
6901: push(@{$changes{'id_rule'}},$type);
6902: }
6903: }
6904: foreach my $type (@id_rule) {
6905: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
6906: push(@{$changes{'id_rule'}},$type);
6907: }
6908: }
6909: } else {
6910: push(@{$changes{'id_rule'}},@id_rule);
6911: }
6912:
1.43 raeburn 6913: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
6914: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
6915: if (!grep(/^\Q$type\E$/,@email_rule)) {
6916: push(@{$changes{'email_rule'}},$type);
6917: }
6918: }
6919: foreach my $type (@email_rule) {
6920: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
6921: push(@{$changes{'email_rule'}},$type);
6922: }
6923: }
6924: } else {
6925: push(@{$changes{'email_rule'}},@email_rule);
6926: }
6927:
6928: my @authen_contexts = ('author','course','domain');
1.28 raeburn 6929: my @authtypes = ('int','krb4','krb5','loc');
6930: my %authhash;
1.43 raeburn 6931: foreach my $item (@authen_contexts) {
1.28 raeburn 6932: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
6933: foreach my $auth (@authtypes) {
6934: if (grep(/^\Q$auth\E$/,@authallowed)) {
6935: $authhash{$item}{$auth} = 1;
6936: } else {
6937: $authhash{$item}{$auth} = 0;
6938: }
6939: }
6940: }
6941: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 6942: foreach my $item (@authen_contexts) {
1.28 raeburn 6943: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
6944: foreach my $auth (@authtypes) {
6945: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
6946: push(@{$changes{'authtypes'}},$item);
6947: last;
6948: }
6949: }
6950: }
6951: }
6952: } else {
1.43 raeburn 6953: foreach my $item (@authen_contexts) {
1.28 raeburn 6954: push(@{$changes{'authtypes'}},$item);
6955: }
6956: }
6957:
1.27 raeburn 6958: my %usercreation_hash = (
1.28 raeburn 6959: usercreation => {
1.34 raeburn 6960: cancreate => \%cancreate,
1.27 raeburn 6961: username_rule => \@username_rule,
1.32 raeburn 6962: id_rule => \@id_rule,
1.43 raeburn 6963: email_rule => \@email_rule,
1.32 raeburn 6964: authtypes => \%authhash,
1.27 raeburn 6965: }
6966: );
6967:
6968: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
6969: $dom);
1.50 raeburn 6970:
6971: my %selfcreatetypes = (
6972: sso => 'users authenticated by institutional single sign on',
6973: login => 'users authenticated by institutional log-in',
6974: email => 'users who provide a valid e-mail address for use as the username',
6975: );
1.27 raeburn 6976: if ($putresult eq 'ok') {
6977: if (keys(%changes) > 0) {
6978: $resulttext = &mt('Changes made:').'<ul>';
6979: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 6980: my %lt = &usercreation_types();
6981: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 6982: my $chgtext;
1.165 raeburn 6983: unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
1.100 raeburn 6984: $chgtext = $lt{$type}.', ';
6985: }
1.45 raeburn 6986: if ($type eq 'selfcreate') {
1.50 raeburn 6987: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 6988: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 6989: } else {
1.100 raeburn 6990: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 6991: foreach my $case (@{$cancreate{$type}}) {
6992: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
6993: }
6994: $chgtext .= '</ul>';
1.100 raeburn 6995: if (ref($cancreate{$type}) eq 'ARRAY') {
6996: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
6997: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
6998: if (@{$cancreate{'statustocreate'}} == 0) {
6999: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
7000: }
7001: }
7002: }
7003: }
1.43 raeburn 7004: }
1.93 raeburn 7005: } elsif ($type eq 'statustocreate') {
1.96 raeburn 7006: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
7007: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
7008: if (@{$cancreate{'selfcreate'}} > 0) {
7009: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 7010:
7011: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 7012: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 7013: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
7014: }
1.96 raeburn 7015: } elsif (ref($usertypes) eq 'HASH') {
7016: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 7017: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
7018: } else {
7019: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
7020: }
7021: $chgtext .= '<ul>';
7022: foreach my $case (@{$cancreate{$type}}) {
7023: if ($case eq 'default') {
7024: $chgtext .= '<li>'.$othertitle.'</li>';
7025: } else {
7026: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 7027: }
7028: }
1.100 raeburn 7029: $chgtext .= '</ul>';
7030: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
7031: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
7032: }
7033: }
7034: } else {
7035: if (@{$cancreate{$type}} == 0) {
7036: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
7037: } else {
7038: $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 7039: }
7040: }
7041: }
1.165 raeburn 7042: } elsif ($type eq 'captcha') {
7043: if ($cancreate{$type} eq 'notused') {
7044: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
7045: } else {
7046: my %captchas = &captcha_phrases();
7047: if ($captchas{$cancreate{$type}}) {
7048: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
7049: } else {
7050: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
7051: }
7052: }
7053: } elsif ($type eq 'recaptchakeys') {
7054: my ($privkey,$pubkey);
7055: if (ref($cancreate{$type}) eq 'HASH') {
7056: $pubkey = $cancreate{$type}{'public'};
7057: $privkey = $cancreate{$type}{'private'};
7058: }
7059: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
7060: if (!$pubkey) {
7061: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
7062: } else {
7063: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7064: }
7065: if (!$privkey) {
7066: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
7067: } else {
7068: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
7069: }
7070: $chgtext .= '</ul>';
1.43 raeburn 7071: } else {
7072: if ($cancreate{$type} eq 'none') {
7073: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
7074: } elsif ($cancreate{$type} eq 'any') {
7075: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
7076: } elsif ($cancreate{$type} eq 'official') {
7077: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
7078: } elsif ($cancreate{$type} eq 'unofficial') {
7079: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
7080: }
1.34 raeburn 7081: }
7082: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 7083: }
7084: }
7085: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 7086: my ($rules,$ruleorder) =
7087: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 7088: my $chgtext = '<ul>';
7089: foreach my $type (@username_rule) {
7090: if (ref($rules->{$type}) eq 'HASH') {
7091: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
7092: }
7093: }
7094: $chgtext .= '</ul>';
7095: if (@username_rule > 0) {
7096: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7097: } else {
1.28 raeburn 7098: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 7099: }
7100: }
1.32 raeburn 7101: if (ref($changes{'id_rule'}) eq 'ARRAY') {
7102: my ($idrules,$idruleorder) =
7103: &Apache::lonnet::inst_userrules($dom,'id');
7104: my $chgtext = '<ul>';
7105: foreach my $type (@id_rule) {
7106: if (ref($idrules->{$type}) eq 'HASH') {
7107: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
7108: }
7109: }
7110: $chgtext .= '</ul>';
7111: if (@id_rule > 0) {
7112: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7113: } else {
7114: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
7115: }
7116: }
1.43 raeburn 7117: if (ref($changes{'email_rule'}) eq 'ARRAY') {
7118: my ($emailrules,$emailruleorder) =
7119: &Apache::lonnet::inst_userrules($dom,'email');
7120: my $chgtext = '<ul>';
7121: foreach my $type (@email_rule) {
7122: if (ref($emailrules->{$type}) eq 'HASH') {
7123: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
7124: }
7125: }
7126: $chgtext .= '</ul>';
7127: if (@email_rule > 0) {
7128: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
7129: } else {
7130: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
7131: }
7132: }
7133:
1.28 raeburn 7134: my %authname = &authtype_names();
7135: my %context_title = &context_names();
7136: if (ref($changes{'authtypes'}) eq 'ARRAY') {
7137: my $chgtext = '<ul>';
7138: foreach my $type (@{$changes{'authtypes'}}) {
7139: my @allowed;
7140: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
7141: foreach my $auth (@authtypes) {
7142: if ($authhash{$type}{$auth}) {
7143: push(@allowed,$authname{$auth});
7144: }
7145: }
1.43 raeburn 7146: if (@allowed > 0) {
7147: $chgtext .= join(', ',@allowed).'</li>';
7148: } else {
7149: $chgtext .= &mt('none').'</li>';
7150: }
1.28 raeburn 7151: }
7152: $chgtext .= '</ul>';
7153: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
7154: $resulttext .= '</li>';
7155: }
1.27 raeburn 7156: $resulttext .= '</ul>';
7157: } else {
1.28 raeburn 7158: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 7159: }
7160: } else {
7161: $resulttext = '<span class="LC_error">'.
1.23 raeburn 7162: &mt('An error occurred: [_1]',$putresult).'</span>';
7163: }
1.43 raeburn 7164: if ($warningmsg ne '') {
7165: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
7166: }
1.23 raeburn 7167: return $resulttext;
7168: }
7169:
1.165 raeburn 7170: sub process_captcha {
7171: my ($container,$changes,$newsettings,$current) = @_;
7172: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
7173: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
7174: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
7175: $newsettings->{'captcha'} = 'original';
7176: }
7177: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.169 raeburn 7178: if ($container eq 'cancreate') {
7179: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7180: push(@{$changes->{'cancreate'}},'captcha');
7181: } elsif (!defined($changes->{'cancreate'})) {
7182: $changes->{'cancreate'} = ['captcha'];
7183: }
7184: } else {
7185: $changes->{'captcha'} = 1;
1.165 raeburn 7186: }
7187: }
7188: my ($newpub,$newpriv,$currpub,$currpriv);
7189: if ($newsettings->{'captcha'} eq 'recaptcha') {
7190: $newpub = $env{'form.'.$container.'_recaptchapub'};
7191: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.169 raeburn 7192: $newpub =~ s/\W//g;
7193: $newpriv =~ s/\W//g;
7194: $newsettings->{'recaptchakeys'} = {
7195: public => $newpub,
7196: private => $newpriv,
7197: };
1.165 raeburn 7198: }
7199: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
7200: $currpub = $current->{'recaptchakeys'}{'public'};
7201: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 7202: unless ($newsettings->{'captcha'} eq 'recaptcha') {
7203: $newsettings->{'recaptchakeys'} = {
7204: public => '',
7205: private => '',
7206: }
7207: }
1.165 raeburn 7208: }
7209: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 7210: if ($container eq 'cancreate') {
7211: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7212: push(@{$changes->{'cancreate'}},'recaptchakeys');
7213: } elsif (!defined($changes->{'cancreate'})) {
7214: $changes->{'cancreate'} = ['recaptchakeys'];
7215: }
7216: } else {
7217: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 7218: }
7219: }
7220: return;
7221: }
7222:
1.33 raeburn 7223: sub modify_usermodification {
7224: my ($dom,%domconfig) = @_;
7225: my ($resulttext,%curr_usermodification,%changes);
7226: if (ref($domconfig{'usermodification'}) eq 'HASH') {
7227: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
7228: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
7229: }
7230: }
1.63 raeburn 7231: my @contexts = ('author','course','selfcreate');
1.33 raeburn 7232: my %context_title = (
7233: author => 'In author context',
7234: course => 'In course context',
1.63 raeburn 7235: selfcreate => 'When self creating account',
1.33 raeburn 7236: );
7237: my @fields = ('lastname','firstname','middlename','generation',
7238: 'permanentemail','id');
7239: my %roles = (
7240: author => ['ca','aa'],
7241: course => ['st','ep','ta','in','cr'],
7242: );
1.63 raeburn 7243: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7244: if (ref($types) eq 'ARRAY') {
7245: push(@{$types},'default');
7246: $usertypes->{'default'} = $othertitle;
7247: }
7248: $roles{'selfcreate'} = $types;
1.33 raeburn 7249: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7250: my %modifyhash;
7251: foreach my $context (@contexts) {
7252: foreach my $role (@{$roles{$context}}) {
7253: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
7254: foreach my $item (@fields) {
7255: if (grep(/^\Q$item\E$/,@modifiable)) {
7256: $modifyhash{$context}{$role}{$item} = 1;
7257: } else {
7258: $modifyhash{$context}{$role}{$item} = 0;
7259: }
7260: }
7261: }
7262: if (ref($curr_usermodification{$context}) eq 'HASH') {
7263: foreach my $role (@{$roles{$context}}) {
7264: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
7265: foreach my $field (@fields) {
7266: if ($modifyhash{$context}{$role}{$field} ne
7267: $curr_usermodification{$context}{$role}{$field}) {
7268: push(@{$changes{$context}},$role);
7269: last;
7270: }
7271: }
7272: }
7273: }
7274: } else {
7275: foreach my $context (@contexts) {
7276: foreach my $role (@{$roles{$context}}) {
7277: push(@{$changes{$context}},$role);
7278: }
7279: }
7280: }
7281: }
7282: my %usermodification_hash = (
7283: usermodification => \%modifyhash,
7284: );
7285: my $putresult = &Apache::lonnet::put_dom('configuration',
7286: \%usermodification_hash,$dom);
7287: if ($putresult eq 'ok') {
7288: if (keys(%changes) > 0) {
7289: $resulttext = &mt('Changes made: ').'<ul>';
7290: foreach my $context (@contexts) {
7291: if (ref($changes{$context}) eq 'ARRAY') {
7292: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
7293: if (ref($changes{$context}) eq 'ARRAY') {
7294: foreach my $role (@{$changes{$context}}) {
7295: my $rolename;
1.63 raeburn 7296: if ($context eq 'selfcreate') {
7297: $rolename = $role;
7298: if (ref($usertypes) eq 'HASH') {
7299: if ($usertypes->{$role} ne '') {
7300: $rolename = $usertypes->{$role};
7301: }
7302: }
1.33 raeburn 7303: } else {
1.63 raeburn 7304: if ($role eq 'cr') {
7305: $rolename = &mt('Custom');
7306: } else {
7307: $rolename = &Apache::lonnet::plaintext($role);
7308: }
1.33 raeburn 7309: }
7310: my @modifiable;
1.63 raeburn 7311: if ($context eq 'selfcreate') {
1.126 bisitz 7312: $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 7313: } else {
7314: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
7315: }
1.33 raeburn 7316: foreach my $field (@fields) {
7317: if ($modifyhash{$context}{$role}{$field}) {
7318: push(@modifiable,$fieldtitles{$field});
7319: }
7320: }
7321: if (@modifiable > 0) {
7322: $resulttext .= join(', ',@modifiable);
7323: } else {
7324: $resulttext .= &mt('none');
7325: }
7326: $resulttext .= '</li>';
7327: }
7328: $resulttext .= '</ul></li>';
7329: }
7330: }
7331: }
7332: $resulttext .= '</ul>';
7333: } else {
7334: $resulttext = &mt('No changes made to user modification settings');
7335: }
7336: } else {
7337: $resulttext = '<span class="LC_error">'.
7338: &mt('An error occurred: [_1]',$putresult).'</span>';
7339: }
7340: return $resulttext;
7341: }
7342:
1.43 raeburn 7343: sub modify_defaults {
7344: my ($dom,$r) = @_;
7345: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
7346: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 7347: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 7348: my @authtypes = ('internal','krb4','krb5','localauth');
7349: foreach my $item (@items) {
7350: $newvalues{$item} = $env{'form.'.$item};
7351: if ($item eq 'auth_def') {
7352: if ($newvalues{$item} ne '') {
7353: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
7354: push(@errors,$item);
7355: }
7356: }
7357: } elsif ($item eq 'lang_def') {
7358: if ($newvalues{$item} ne '') {
7359: if ($newvalues{$item} =~ /^(\w+)/) {
7360: my $langcode = $1;
1.103 raeburn 7361: if ($langcode ne 'x_chef') {
7362: if (code2language($langcode) eq '') {
7363: push(@errors,$item);
7364: }
1.43 raeburn 7365: }
7366: } else {
7367: push(@errors,$item);
7368: }
7369: }
1.54 raeburn 7370: } elsif ($item eq 'timezone_def') {
7371: if ($newvalues{$item} ne '') {
1.62 raeburn 7372: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 7373: push(@errors,$item);
7374: }
7375: }
1.68 raeburn 7376: } elsif ($item eq 'datelocale_def') {
7377: if ($newvalues{$item} ne '') {
7378: my @datelocale_ids = DateTime::Locale->ids();
7379: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
7380: push(@errors,$item);
7381: }
7382: }
1.141 raeburn 7383: } elsif ($item eq 'portal_def') {
7384: if ($newvalues{$item} ne '') {
7385: 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])\/?$/) {
7386: push(@errors,$item);
7387: }
7388: }
1.43 raeburn 7389: }
7390: if (grep(/^\Q$item\E$/,@errors)) {
7391: $newvalues{$item} = $domdefaults{$item};
7392: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
7393: $changes{$item} = 1;
7394: }
1.72 raeburn 7395: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 7396: }
7397: my %defaults_hash = (
1.72 raeburn 7398: defaults => \%newvalues,
7399: );
1.43 raeburn 7400: my $title = &defaults_titles();
7401: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
7402: $dom);
7403: if ($putresult eq 'ok') {
7404: if (keys(%changes) > 0) {
7405: $resulttext = &mt('Changes made:').'<ul>';
7406: my $version = $r->dir_config('lonVersion');
7407: 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";
7408: foreach my $item (sort(keys(%changes))) {
7409: my $value = $env{'form.'.$item};
7410: if ($value eq '') {
7411: $value = &mt('none');
7412: } elsif ($item eq 'auth_def') {
7413: my %authnames = &authtype_names();
7414: my %shortauth = (
7415: internal => 'int',
7416: krb4 => 'krb4',
7417: krb5 => 'krb5',
7418: localauth => 'loc',
7419: );
7420: $value = $authnames{$shortauth{$value}};
7421: }
7422: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
7423: $mailmsgtext .= "$title->{$item} set to $value\n";
7424: }
7425: $resulttext .= '</ul>';
7426: $mailmsgtext .= "\n";
7427: my $cachetime = 24*60*60;
1.72 raeburn 7428: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68 raeburn 7429: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54 raeburn 7430: my $sysmail = $r->dir_config('lonSysEMail');
7431: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
7432: }
1.43 raeburn 7433: } else {
1.54 raeburn 7434: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 7435: }
7436: } else {
7437: $resulttext = '<span class="LC_error">'.
7438: &mt('An error occurred: [_1]',$putresult).'</span>';
7439: }
7440: if (@errors > 0) {
7441: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
7442: foreach my $item (@errors) {
7443: $resulttext .= ' "'.$title->{$item}.'",';
7444: }
7445: $resulttext =~ s/,$//;
7446: }
7447: return $resulttext;
7448: }
7449:
1.46 raeburn 7450: sub modify_scantron {
1.48 raeburn 7451: my ($r,$dom,$confname,%domconfig) = @_;
1.46 raeburn 7452: my ($resulttext,%confhash,%changes,$errors);
7453: my $custom = 'custom.tab';
7454: my $default = 'default.tab';
7455: my $servadm = $r->dir_config('lonAdmEMail');
7456: my ($configuserok,$author_ok,$switchserver) =
7457: &config_check($dom,$confname,$servadm);
7458: if ($env{'form.scantronformat.filename'} ne '') {
7459: my $error;
7460: if ($configuserok eq 'ok') {
7461: if ($switchserver) {
1.130 raeburn 7462: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 7463: } else {
7464: if ($author_ok eq 'ok') {
7465: my ($result,$scantronurl) =
7466: &publishlogo($r,'upload','scantronformat',$dom,
7467: $confname,'scantron','','',$custom);
7468: if ($result eq 'ok') {
7469: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 7470: $changes{'scantronformat'} = 1;
1.46 raeburn 7471: } else {
7472: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
7473: }
7474: } else {
7475: $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);
7476: }
7477: }
7478: } else {
7479: $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);
7480: }
7481: if ($error) {
7482: &Apache::lonnet::logthis($error);
7483: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7484: }
7485: }
1.48 raeburn 7486: if (ref($domconfig{'scantron'}) eq 'HASH') {
7487: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
7488: if ($env{'form.scantronformat_del'}) {
7489: $confhash{'scantron'}{'scantronformat'} = '';
7490: $changes{'scantronformat'} = 1;
1.46 raeburn 7491: }
7492: }
7493: }
7494: if (keys(%confhash) > 0) {
7495: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
7496: $dom);
7497: if ($putresult eq 'ok') {
7498: if (keys(%changes) > 0) {
1.48 raeburn 7499: if (ref($confhash{'scantron'}) eq 'HASH') {
7500: $resulttext = &mt('Changes made:').'<ul>';
7501: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 7502: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 7503: } else {
1.130 raeburn 7504: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 7505: }
1.48 raeburn 7506: $resulttext .= '</ul>';
7507: } else {
1.130 raeburn 7508: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 7509: }
7510: $resulttext .= '</ul>';
7511: &Apache::loncommon::devalidate_domconfig_cache($dom);
7512: } else {
1.130 raeburn 7513: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7514: }
7515: } else {
7516: $resulttext = '<span class="LC_error">'.
7517: &mt('An error occurred: [_1]',$putresult).'</span>';
7518: }
7519: } else {
1.130 raeburn 7520: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7521: }
7522: if ($errors) {
7523: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7524: $errors.'</ul>';
7525: }
7526: return $resulttext;
7527: }
7528:
1.48 raeburn 7529: sub modify_coursecategories {
7530: my ($dom,%domconfig) = @_;
1.57 raeburn 7531: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
7532: $cathash);
1.48 raeburn 7533: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 7534: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 7535: $cathash = $domconfig{'coursecategories'}{'cats'};
7536: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
7537: $changes{'togglecats'} = 1;
7538: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
7539: }
7540: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
7541: $changes{'categorize'} = 1;
7542: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
7543: }
1.120 raeburn 7544: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
7545: $changes{'togglecatscomm'} = 1;
7546: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
7547: }
7548: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
7549: $changes{'categorizecomm'} = 1;
7550: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
7551: }
1.57 raeburn 7552: } else {
7553: $changes{'togglecats'} = 1;
7554: $changes{'categorize'} = 1;
1.124 raeburn 7555: $changes{'togglecatscomm'} = 1;
7556: $changes{'categorizecomm'} = 1;
1.87 raeburn 7557: $domconfig{'coursecategories'} = {
7558: togglecats => $env{'form.togglecats'},
7559: categorize => $env{'form.categorize'},
1.124 raeburn 7560: togglecatscomm => $env{'form.togglecatscomm'},
7561: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 7562: };
1.57 raeburn 7563: }
7564: if (ref($cathash) eq 'HASH') {
7565: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 7566: push (@deletecategory,'instcode::0');
7567: }
1.120 raeburn 7568: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
7569: push(@deletecategory,'communities::0');
7570: }
1.48 raeburn 7571: }
1.57 raeburn 7572: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
7573: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7574: if (@deletecategory > 0) {
7575: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 7576: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 7577: foreach my $item (@deletecategory) {
1.57 raeburn 7578: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
7579: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 7580: $deletions{$item} = 1;
1.57 raeburn 7581: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 7582: }
7583: }
7584: }
1.57 raeburn 7585: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 7586: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 7587: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 7588: $reorderings{$item} = 1;
1.57 raeburn 7589: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 7590: }
7591: if ($env{'form.addcategory_name_'.$item} ne '') {
7592: my $newcat = $env{'form.addcategory_name_'.$item};
7593: my $newdepth = $depth+1;
7594: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7595: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 7596: $adds{$newitem} = 1;
7597: }
7598: if ($env{'form.subcat_'.$item} ne '') {
7599: my $newcat = $env{'form.subcat_'.$item};
7600: my $newdepth = $depth+1;
7601: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7602: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 7603: $adds{$newitem} = 1;
7604: }
7605: }
7606: }
7607: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 7608: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7609: my $newitem = 'instcode::0';
1.57 raeburn 7610: if ($cathash->{$newitem} eq '') {
7611: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7612: $adds{$newitem} = 1;
7613: }
7614: } else {
7615: my $newitem = 'instcode::0';
1.57 raeburn 7616: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7617: $adds{$newitem} = 1;
7618: }
7619: }
1.120 raeburn 7620: if ($env{'form.communities'} eq '1') {
7621: if (ref($cathash) eq 'HASH') {
7622: my $newitem = 'communities::0';
7623: if ($cathash->{$newitem} eq '') {
7624: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7625: $adds{$newitem} = 1;
7626: }
7627: } else {
7628: my $newitem = 'communities::0';
7629: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7630: $adds{$newitem} = 1;
7631: }
7632: }
1.48 raeburn 7633: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 7634: if (($env{'form.addcategory_name'} ne 'instcode') &&
7635: ($env{'form.addcategory_name'} ne 'communities')) {
7636: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
7637: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
7638: $adds{$newitem} = 1;
7639: }
1.48 raeburn 7640: }
1.57 raeburn 7641: my $putresult;
1.48 raeburn 7642: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7643: if (keys(%deletions) > 0) {
7644: foreach my $key (keys(%deletions)) {
7645: if ($predelallitems{$key} ne '') {
7646: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
7647: }
7648: }
7649: }
7650: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 7651: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 7652: if (ref($chkcats[0]) eq 'ARRAY') {
7653: my $depth = 0;
7654: my $chg = 0;
7655: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
7656: my $name = $chkcats[0][$i];
7657: my $item;
7658: if ($name eq '') {
7659: $chg ++;
7660: } else {
7661: $item = &escape($name).'::0';
7662: if ($chg) {
1.57 raeburn 7663: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 7664: }
7665: $depth ++;
1.57 raeburn 7666: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 7667: $depth --;
7668: }
7669: }
7670: }
1.57 raeburn 7671: }
7672: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7673: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 7674: if ($putresult eq 'ok') {
1.57 raeburn 7675: my %title = (
1.120 raeburn 7676: togglecats => 'Show/Hide a course in catalog',
7677: categorize => 'Assign a category to a course',
7678: togglecatscomm => 'Show/Hide a community in catalog',
7679: categorizecomm => 'Assign a category to a community',
1.57 raeburn 7680: );
7681: my %level = (
1.120 raeburn 7682: dom => 'set in Domain ("Modify Course/Community")',
7683: crs => 'set in Course ("Course Configuration")',
7684: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 7685: );
1.48 raeburn 7686: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 7687: if ($changes{'togglecats'}) {
7688: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
7689: }
7690: if ($changes{'categorize'}) {
7691: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 7692: }
1.120 raeburn 7693: if ($changes{'togglecatscomm'}) {
7694: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
7695: }
7696: if ($changes{'categorizecomm'}) {
7697: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
7698: }
1.57 raeburn 7699: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7700: my $cathash;
7701: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
7702: $cathash = $domconfig{'coursecategories'}{'cats'};
7703: } else {
7704: $cathash = {};
7705: }
7706: my (@cats,@trails,%allitems);
7707: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
7708: if (keys(%deletions) > 0) {
7709: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
7710: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
7711: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
7712: }
7713: $resulttext .= '</ul></li>';
7714: }
7715: if (keys(%reorderings) > 0) {
7716: my %sort_by_trail;
7717: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
7718: foreach my $key (keys(%reorderings)) {
7719: if ($allitems{$key} ne '') {
7720: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7721: }
1.48 raeburn 7722: }
1.57 raeburn 7723: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7724: $resulttext .= '<li>'.$trails[$trail].'</li>';
7725: }
7726: $resulttext .= '</ul></li>';
1.48 raeburn 7727: }
1.57 raeburn 7728: if (keys(%adds) > 0) {
7729: my %sort_by_trail;
7730: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
7731: foreach my $key (keys(%adds)) {
7732: if ($allitems{$key} ne '') {
7733: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7734: }
7735: }
7736: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7737: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 7738: }
1.57 raeburn 7739: $resulttext .= '</ul></li>';
1.48 raeburn 7740: }
7741: }
7742: $resulttext .= '</ul>';
7743: } else {
7744: $resulttext = '<span class="LC_error">'.
1.57 raeburn 7745: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 7746: }
7747: } else {
1.120 raeburn 7748: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 7749: }
7750: return $resulttext;
7751: }
7752:
1.69 raeburn 7753: sub modify_serverstatuses {
7754: my ($dom,%domconfig) = @_;
7755: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
7756: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
7757: %currserverstatus = %{$domconfig{'serverstatuses'}};
7758: }
7759: my @pages = &serverstatus_pages();
7760: foreach my $type (@pages) {
7761: $newserverstatus{$type}{'namedusers'} = '';
7762: $newserverstatus{$type}{'machines'} = '';
7763: if (defined($env{'form.'.$type.'_namedusers'})) {
7764: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
7765: my @okusers;
7766: foreach my $user (@users) {
7767: my ($uname,$udom) = split(/:/,$user);
7768: if (($udom =~ /^$match_domain$/) &&
7769: (&Apache::lonnet::domain($udom)) &&
7770: ($uname =~ /^$match_username$/)) {
7771: if (!grep(/^\Q$user\E/,@okusers)) {
7772: push(@okusers,$user);
7773: }
7774: }
7775: }
7776: if (@okusers > 0) {
7777: @okusers = sort(@okusers);
7778: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
7779: }
7780: }
7781: if (defined($env{'form.'.$type.'_machines'})) {
7782: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
7783: my @okmachines;
7784: foreach my $ip (@machines) {
7785: my @parts = split(/\./,$ip);
7786: next if (@parts < 4);
7787: my $badip = 0;
7788: for (my $i=0; $i<4; $i++) {
7789: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
7790: $badip = 1;
7791: last;
7792: }
7793: }
7794: if (!$badip) {
7795: push(@okmachines,$ip);
7796: }
7797: }
7798: @okmachines = sort(@okmachines);
7799: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
7800: }
7801: }
7802: my %serverstatushash = (
7803: serverstatuses => \%newserverstatus,
7804: );
7805: foreach my $type (@pages) {
1.83 raeburn 7806: foreach my $setting ('namedusers','machines') {
1.84 raeburn 7807: my (@current,@new);
1.83 raeburn 7808: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 7809: if ($currserverstatus{$type}{$setting} ne '') {
7810: @current = split(/,/,$currserverstatus{$type}{$setting});
7811: }
7812: }
7813: if ($newserverstatus{$type}{$setting} ne '') {
7814: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 7815: }
7816: if (@current > 0) {
7817: if (@new > 0) {
7818: foreach my $item (@current) {
7819: if (!grep(/^\Q$item\E$/,@new)) {
7820: $changes{$type}{$setting} = 1;
1.82 raeburn 7821: last;
7822: }
7823: }
1.84 raeburn 7824: foreach my $item (@new) {
7825: if (!grep(/^\Q$item\E$/,@current)) {
7826: $changes{$type}{$setting} = 1;
7827: last;
1.82 raeburn 7828: }
7829: }
7830: } else {
1.83 raeburn 7831: $changes{$type}{$setting} = 1;
1.69 raeburn 7832: }
1.83 raeburn 7833: } elsif (@new > 0) {
7834: $changes{$type}{$setting} = 1;
1.69 raeburn 7835: }
7836: }
7837: }
7838: if (keys(%changes) > 0) {
1.81 raeburn 7839: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7840: my $putresult = &Apache::lonnet::put_dom('configuration',
7841: \%serverstatushash,$dom);
7842: if ($putresult eq 'ok') {
7843: $resulttext .= &mt('Changes made:').'<ul>';
7844: foreach my $type (@pages) {
1.84 raeburn 7845: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 7846: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 7847: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 7848: if ($newserverstatus{$type}{'namedusers'} eq '') {
7849: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
7850: } else {
7851: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
7852: }
1.84 raeburn 7853: }
7854: if ($changes{$type}{'machines'}) {
1.69 raeburn 7855: if ($newserverstatus{$type}{'machines'} eq '') {
7856: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
7857: } else {
7858: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
7859: }
7860:
7861: }
7862: $resulttext .= '</ul></li>';
7863: }
7864: }
7865: $resulttext .= '</ul>';
7866: } else {
7867: $resulttext = '<span class="LC_error">'.
7868: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
7869:
7870: }
7871: } else {
7872: $resulttext = &mt('No changes made to access to server status pages');
7873: }
7874: return $resulttext;
7875: }
7876:
1.118 jms 7877: sub modify_helpsettings {
1.122 jms 7878: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 7879: my ($resulttext,$errors,%changes,%helphash);
7880: my %defaultchecked = ('submitbugs' => 'on');
7881: my @offon = ('off','on');
1.118 jms 7882: my @toggles = ('submitbugs');
7883: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7884: foreach my $item (@toggles) {
1.166 raeburn 7885: if ($defaultchecked{$item} eq 'on') {
7886: if ($domconfig{'helpsettings'}{$item} eq '') {
7887: if ($env{'form.'.$item} eq '0') {
7888: $changes{$item} = 1;
7889: }
7890: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7891: $changes{$item} = 1;
7892: }
7893: } elsif ($defaultchecked{$item} eq 'off') {
7894: if ($domconfig{'helpsettings'}{$item} eq '') {
7895: if ($env{'form.'.$item} eq '1') {
7896: $changes{$item} = 1;
7897: }
7898: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7899: $changes{$item} = 1;
7900: }
7901: }
7902: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
7903: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
7904: }
7905: }
1.118 jms 7906: }
1.123 jms 7907: my $putresult;
7908: if (keys(%changes) > 0) {
1.166 raeburn 7909: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 7910: if ($putresult eq 'ok') {
1.166 raeburn 7911: $resulttext = &mt('Changes made:').'<ul>';
7912: foreach my $item (sort(keys(%changes))) {
7913: if ($item eq 'submitbugs') {
7914: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
7915: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
7916: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
7917: }
7918: }
7919: $resulttext .= '</ul>';
7920: } else {
7921: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 7922: $errors .= '<li><span class="LC_error">'.
7923: &mt('An error occurred storing the settings: [_1]',
7924: $putresult).'</span></li>';
1.166 raeburn 7925: }
1.118 jms 7926: }
7927: if ($errors) {
1.168 raeburn 7928: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 7929: $errors.'</ul>';
7930: }
7931: return $resulttext;
7932: }
7933:
1.121 raeburn 7934: sub modify_coursedefaults {
7935: my ($dom,%domconfig) = @_;
7936: my ($resulttext,$errors,%changes,%defaultshash);
7937: my %defaultchecked = ('canuse_pdfforms' => 'off');
7938: my @toggles = ('canuse_pdfforms');
1.198 raeburn 7939: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
7940: 'uploadquota_community');
7941: my @types = ('official','unofficial','community');
7942: my %staticdefaults = (
7943: anonsurvey_threshold => 10,
7944: uploadquota => 500,
7945: );
1.121 raeburn 7946:
7947: $defaultshash{'coursedefaults'} = {};
7948:
7949: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
7950: if ($domconfig{'coursedefaults'} eq '') {
7951: $domconfig{'coursedefaults'} = {};
7952: }
7953: }
7954:
7955: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
7956: foreach my $item (@toggles) {
7957: if ($defaultchecked{$item} eq 'on') {
7958: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7959: ($env{'form.'.$item} eq '0')) {
7960: $changes{$item} = 1;
1.192 raeburn 7961: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 7962: $changes{$item} = 1;
7963: }
7964: } elsif ($defaultchecked{$item} eq 'off') {
7965: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7966: ($env{'form.'.$item} eq '1')) {
7967: $changes{$item} = 1;
7968: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
7969: $changes{$item} = 1;
7970: }
7971: }
7972: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
7973: }
1.198 raeburn 7974: foreach my $item (@numbers) {
7975: my ($currdef,$newdef);
7976: my $newdef = $env{'form.'.$item};
7977: if ($item eq 'anonsurvey_threshold') {
7978: $currdef = $domconfig{'coursedefaults'}{$item};
7979: $newdef =~ s/\D//g;
7980: if ($newdef eq '' || $newdef < 1) {
7981: $newdef = 1;
7982: }
7983: $defaultshash{'coursedefaults'}{$item} = $newdef;
7984: } else {
7985: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
7986: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
7987: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
7988: }
7989: $newdef =~ s/[^\w.\-]//g;
7990: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
7991: }
7992: if ($currdef ne $newdef) {
7993: my $staticdef;
7994: if ($item eq 'anonsurvey_threshold') {
7995: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
7996: $changes{$item} = 1;
7997: }
7998: } else {
7999: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
8000: $changes{'uploadquota'} = 1;
8001: }
8002: }
1.139 raeburn 8003: }
8004: }
1.192 raeburn 8005: my $officialcreds = $env{'form.official_credits'};
8006: $officialcreds =~ s/^[^\d\.]//g;
8007: my $unofficialcreds = $env{'form.unofficial_credits'};
8008: $unofficialcreds =~ s/^[^\d\.]//g;
8009: if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
8010: ($env{'form.coursecredits'} eq '1')) {
8011: $changes{'coursecredits'} = 1;
8012: } else {
8013: if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
8014: ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds)) {
8015: $changes{'coursecredits'} = 1;
8016: }
8017: }
8018: $defaultshash{'coursedefaults'}{'coursecredits'} = {
8019: official => $officialcreds,
8020: unofficial => $unofficialcreds,
8021: }
1.121 raeburn 8022: }
8023: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8024: $dom);
8025: if ($putresult eq 'ok') {
1.192 raeburn 8026: my %domdefaults;
1.121 raeburn 8027: if (keys(%changes) > 0) {
1.198 raeburn 8028: if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) || ($changes{'uploadquota'})) {
1.192 raeburn 8029: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
8030: if ($changes{'canuse_pdfforms'}) {
8031: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
8032: }
8033: if ($changes{'coursecredits'}) {
8034: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
8035: $domdefaults{'officialcredits'} =
8036: $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
8037: $domdefaults{'unofficialcredits'} =
8038: $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
8039: }
8040: }
1.198 raeburn 8041: if ($changes{'uploadquota'}) {
8042: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8043: foreach my $type (@types) {
8044: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
8045: }
8046: }
8047: }
1.121 raeburn 8048: my $cachetime = 24*60*60;
8049: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
8050: }
8051: $resulttext = &mt('Changes made:').'<ul>';
8052: foreach my $item (sort(keys(%changes))) {
8053: if ($item eq 'canuse_pdfforms') {
8054: if ($env{'form.'.$item} eq '1') {
8055: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
8056: } else {
8057: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
8058: }
1.139 raeburn 8059: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 8060: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 8061: } elsif ($item eq 'uploadquota') {
8062: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8063: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
8064: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
8065: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
8066: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
8067: '</ul>'.
8068: '</li>';
8069: } else {
8070: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
8071: }
1.192 raeburn 8072: } elsif ($item eq 'coursecredits') {
8073: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
8074: if (($domdefaults{'officialcredits'} eq '') &&
8075: ($domdefaults{'unofficialcredits'} eq '')) {
8076: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
8077: } else {
8078: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
8079: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
8080: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
8081: '</ul>'.
8082: '</li>';
8083: }
8084: } else {
8085: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
8086: }
1.140 raeburn 8087: }
1.121 raeburn 8088: }
8089: $resulttext .= '</ul>';
8090: } else {
8091: $resulttext = &mt('No changes made to course defaults');
8092: }
8093: } else {
8094: $resulttext = '<span class="LC_error">'.
8095: &mt('An error occurred: [_1]',$putresult).'</span>';
8096: }
8097: return $resulttext;
8098: }
8099:
1.137 raeburn 8100: sub modify_usersessions {
8101: my ($dom,%domconfig) = @_;
1.145 raeburn 8102: my @hostingtypes = ('version','excludedomain','includedomain');
8103: my @offloadtypes = ('primary','default');
8104: my %types = (
8105: remote => \@hostingtypes,
8106: hosted => \@hostingtypes,
8107: spares => \@offloadtypes,
8108: );
8109: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 8110: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 8111: my (%by_ip,%by_location,@intdoms);
8112: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
8113: my @locations = sort(keys(%by_location));
1.137 raeburn 8114: my (%defaultshash,%changes);
8115: foreach my $prefix (@prefixes) {
8116: $defaultshash{'usersessions'}{$prefix} = {};
8117: }
8118: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
8119: my $resulttext;
1.138 raeburn 8120: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 8121: foreach my $prefix (@prefixes) {
1.145 raeburn 8122: next if ($prefix eq 'spares');
8123: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 8124: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
8125: if ($type eq 'version') {
8126: my $value = $env{'form.'.$prefix.'_'.$type};
8127: my $okvalue;
8128: if ($value ne '') {
8129: if (grep(/^\Q$value\E$/,@lcversions)) {
8130: $okvalue = $value;
8131: }
8132: }
8133: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8134: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
8135: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
8136: if ($inuse == 0) {
8137: $changes{$prefix}{$type} = 1;
8138: } else {
8139: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
8140: $changes{$prefix}{$type} = 1;
8141: }
8142: if ($okvalue ne '') {
8143: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8144: }
8145: }
8146: } else {
8147: if (($inuse == 1) && ($okvalue ne '')) {
8148: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8149: $changes{$prefix}{$type} = 1;
8150: }
8151: }
8152: } else {
8153: if (($inuse == 1) && ($okvalue ne '')) {
8154: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8155: $changes{$prefix}{$type} = 1;
8156: }
8157: }
8158: } else {
8159: if (($inuse == 1) && ($okvalue ne '')) {
8160: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8161: $changes{$prefix}{$type} = 1;
8162: }
8163: }
8164: } else {
8165: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
8166: my @okvals;
8167: foreach my $val (@vals) {
1.138 raeburn 8168: if ($val =~ /:/) {
8169: my @items = split(/:/,$val);
8170: foreach my $item (@items) {
8171: if (ref($by_location{$item}) eq 'ARRAY') {
8172: push(@okvals,$item);
8173: }
8174: }
8175: } else {
8176: if (ref($by_location{$val}) eq 'ARRAY') {
8177: push(@okvals,$val);
8178: }
1.137 raeburn 8179: }
8180: }
8181: @okvals = sort(@okvals);
8182: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8183: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
8184: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8185: if ($inuse == 0) {
8186: $changes{$prefix}{$type} = 1;
8187: } else {
8188: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8189: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
8190: if (@changed > 0) {
8191: $changes{$prefix}{$type} = 1;
8192: }
8193: }
8194: } else {
8195: if ($inuse == 1) {
8196: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8197: $changes{$prefix}{$type} = 1;
8198: }
8199: }
8200: } else {
8201: if ($inuse == 1) {
8202: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8203: $changes{$prefix}{$type} = 1;
8204: }
8205: }
8206: } else {
8207: if ($inuse == 1) {
8208: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8209: $changes{$prefix}{$type} = 1;
8210: }
8211: }
8212: }
8213: }
8214: }
1.145 raeburn 8215:
8216: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 8217: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 8218: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
8219: my $savespares;
8220:
8221: foreach my $lonhost (sort(keys(%servers))) {
8222: my $serverhomeID =
8223: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 8224: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 8225: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
8226: my %spareschg;
8227: foreach my $type (@{$types{'spares'}}) {
8228: my @okspares;
8229: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
8230: foreach my $server (@checked) {
1.152 raeburn 8231: if (&Apache::lonnet::hostname($server) ne '') {
8232: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
8233: unless (grep(/^\Q$server\E$/,@okspares)) {
8234: push(@okspares,$server);
8235: }
1.145 raeburn 8236: }
8237: }
8238: }
8239: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
8240: my $newspare;
1.152 raeburn 8241: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
8242: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 8243: $newspare = $new;
8244: }
8245: }
1.152 raeburn 8246: my @spares;
8247: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
8248: @spares = sort(@okspares,$newspare);
8249: } else {
8250: @spares = sort(@okspares);
8251: }
8252: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 8253: if (ref($spareid{$lonhost}) eq 'HASH') {
8254: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 8255: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 8256: if (@diffs > 0) {
8257: $spareschg{$type} = 1;
8258: }
8259: }
8260: }
8261: }
8262: if (keys(%spareschg) > 0) {
8263: $changes{'spares'}{$lonhost} = \%spareschg;
8264: }
8265: }
8266:
8267: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8268: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
8269: if (ref($changes{'spares'}) eq 'HASH') {
8270: if (keys(%{$changes{'spares'}}) > 0) {
8271: $savespares = 1;
8272: }
8273: }
8274: } else {
8275: $savespares = 1;
8276: }
8277: }
8278:
1.147 raeburn 8279: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
8280: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 8281: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8282: $dom);
8283: if ($putresult eq 'ok') {
8284: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8285: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
8286: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
8287: }
8288: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
8289: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
8290: }
8291: }
8292: my $cachetime = 24*60*60;
8293: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.147 raeburn 8294: if (keys(%changes) > 0) {
8295: my %lt = &usersession_titles();
8296: $resulttext = &mt('Changes made:').'<ul>';
8297: foreach my $prefix (@prefixes) {
8298: if (ref($changes{$prefix}) eq 'HASH') {
8299: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
8300: if ($prefix eq 'spares') {
8301: if (ref($changes{$prefix}) eq 'HASH') {
8302: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
8303: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 8304: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
8305: &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
1.147 raeburn 8306: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
8307: foreach my $type (@{$types{$prefix}}) {
8308: if ($changes{$prefix}{$lonhost}{$type}) {
8309: my $offloadto = &mt('None');
8310: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
8311: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
8312: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
8313: }
1.145 raeburn 8314: }
1.147 raeburn 8315: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 8316: }
1.137 raeburn 8317: }
8318: }
1.147 raeburn 8319: $resulttext .= '</li>';
1.137 raeburn 8320: }
8321: }
1.147 raeburn 8322: } else {
8323: foreach my $type (@{$types{$prefix}}) {
8324: if (defined($changes{$prefix}{$type})) {
8325: my $newvalue;
8326: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8327: if (ref($defaultshash{'usersessions'}{$prefix})) {
8328: if ($type eq 'version') {
8329: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
8330: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8331: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
8332: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
8333: }
1.145 raeburn 8334: }
8335: }
8336: }
1.147 raeburn 8337: if ($newvalue eq '') {
8338: if ($type eq 'version') {
8339: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
8340: } else {
8341: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
8342: }
1.145 raeburn 8343: } else {
1.147 raeburn 8344: if ($type eq 'version') {
8345: $newvalue .= ' '.&mt('(or later)');
8346: }
8347: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 8348: }
1.137 raeburn 8349: }
8350: }
8351: }
1.147 raeburn 8352: $resulttext .= '</ul>';
1.137 raeburn 8353: }
8354: }
1.147 raeburn 8355: $resulttext .= '</ul>';
8356: } else {
8357: $resulttext = $nochgmsg;
1.137 raeburn 8358: }
8359: } else {
8360: $resulttext = '<span class="LC_error">'.
8361: &mt('An error occurred: [_1]',$putresult).'</span>';
8362: }
8363: } else {
1.147 raeburn 8364: $resulttext = $nochgmsg;
1.137 raeburn 8365: }
8366: return $resulttext;
8367: }
8368:
1.150 raeburn 8369: sub modify_loadbalancing {
8370: my ($dom,%domconfig) = @_;
8371: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8372: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8373: my ($othertitle,$usertypes,$types) =
8374: &Apache::loncommon::sorted_inst_types($dom);
8375: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8376: my @sparestypes = ('primary','default');
8377: my %typetitles = &sparestype_titles();
8378: my $resulttext;
1.171 raeburn 8379: my (%currbalancer,%currtargets,%currrules,%existing);
8380: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8381: %existing = %{$domconfig{'loadbalancing'}};
8382: }
8383: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
8384: \%currtargets,\%currrules);
8385: my ($saveloadbalancing,%defaultshash,%changes);
8386: my ($alltypes,$othertypes,$titles) =
8387: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8388: my %ruletitles = &offloadtype_text();
8389: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
8390: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
8391: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
8392: if ($balancer eq '') {
8393: next;
8394: }
8395: if (!exists($servers{$balancer})) {
8396: if (exists($currbalancer{$balancer})) {
8397: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 8398: }
1.171 raeburn 8399: next;
8400: }
8401: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
8402: push(@{$changes{'delete'}},$balancer);
8403: next;
8404: }
8405: if (!exists($currbalancer{$balancer})) {
8406: push(@{$changes{'add'}},$balancer);
8407: }
8408: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
8409: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
8410: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
8411: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8412: $saveloadbalancing = 1;
8413: }
8414: foreach my $sparetype (@sparestypes) {
8415: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
8416: my @offloadto;
8417: foreach my $target (@targets) {
8418: if (($servers{$target}) && ($target ne $balancer)) {
8419: if ($sparetype eq 'default') {
8420: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
8421: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 8422: }
8423: }
1.171 raeburn 8424: unless(grep(/^\Q$target\E$/,@offloadto)) {
8425: push(@offloadto,$target);
8426: }
1.150 raeburn 8427: }
1.171 raeburn 8428: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 8429: }
8430: }
1.171 raeburn 8431: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 8432: foreach my $sparetype (@sparestypes) {
1.171 raeburn 8433: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
8434: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 8435: if (@targetdiffs > 0) {
1.171 raeburn 8436: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8437: }
1.171 raeburn 8438: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8439: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8440: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8441: }
8442: }
8443: }
8444: } else {
1.171 raeburn 8445: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
8446: foreach my $sparetype (@sparestypes) {
8447: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8448: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8449: $changes{'curr'}{$balancer}{'targets'} = 1;
8450: }
1.150 raeburn 8451: }
8452: }
8453: }
8454: }
8455: my $ishomedom;
1.171 raeburn 8456: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
8457: $ishomedom = 1;
1.150 raeburn 8458: }
8459: if (ref($alltypes) eq 'ARRAY') {
8460: foreach my $type (@{$alltypes}) {
8461: my $rule;
1.171 raeburn 8462: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 8463: (!$ishomedom)) {
1.171 raeburn 8464: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
8465: }
8466: if ($rule eq 'specific') {
8467: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 8468: }
1.171 raeburn 8469: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
8470: if (ref($currrules{$balancer}) eq 'HASH') {
8471: if ($rule ne $currrules{$balancer}{$type}) {
8472: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8473: }
8474: } elsif ($rule ne '') {
1.171 raeburn 8475: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8476: }
8477: }
8478: }
1.171 raeburn 8479: }
8480: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
8481: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
8482: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
8483: $defaultshash{'loadbalancing'} = {};
8484: }
8485: my $putresult = &Apache::lonnet::put_dom('configuration',
8486: \%defaultshash,$dom);
8487:
8488: if ($putresult eq 'ok') {
8489: if (keys(%changes) > 0) {
8490: if (ref($changes{'delete'}) eq 'ARRAY') {
8491: foreach my $balancer (sort(@{$changes{'delete'}})) {
8492: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.150 raeburn 8493: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
8494: }
1.171 raeburn 8495: }
8496: if (ref($changes{'add'}) eq 'ARRAY') {
8497: foreach my $balancer (sort(@{$changes{'add'}})) {
8498: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
8499: }
8500: }
8501: if (ref($changes{'curr'}) eq 'HASH') {
8502: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
8503: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
8504: if ($changes{'curr'}{$balancer}{'targets'}) {
8505: my %offloadstr;
8506: foreach my $sparetype (@sparestypes) {
8507: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8508: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8509: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
8510: }
8511: }
1.150 raeburn 8512: }
1.171 raeburn 8513: if (keys(%offloadstr) == 0) {
8514: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 8515: } else {
1.171 raeburn 8516: my $showoffload;
8517: foreach my $sparetype (@sparestypes) {
8518: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
8519: if (defined($offloadstr{$sparetype})) {
8520: $showoffload .= $offloadstr{$sparetype};
8521: } else {
8522: $showoffload .= &mt('None');
8523: }
8524: $showoffload .= (' 'x3);
8525: }
8526: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 8527: }
8528: }
8529: }
1.171 raeburn 8530: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
8531: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
8532: foreach my $type (@{$alltypes}) {
8533: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
8534: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
8535: my $balancetext;
8536: if ($rule eq '') {
8537: $balancetext = $ruletitles{'default'};
8538: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
8539: $balancetext = $ruletitles{$rule};
8540: } else {
8541: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
8542: }
8543: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 8544: }
8545: }
8546: }
8547: }
1.171 raeburn 8548: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
1.150 raeburn 8549: }
1.171 raeburn 8550: }
8551: if ($resulttext ne '') {
8552: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 8553: } else {
8554: $resulttext = $nochgmsg;
8555: }
8556: } else {
1.171 raeburn 8557: $resulttext = $nochgmsg;
1.150 raeburn 8558: }
8559: } else {
1.171 raeburn 8560: $resulttext = '<span class="LC_error">'.
8561: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 8562: }
8563: } else {
1.171 raeburn 8564: $resulttext = $nochgmsg;
1.150 raeburn 8565: }
8566: return $resulttext;
8567: }
8568:
1.48 raeburn 8569: sub recurse_check {
8570: my ($chkcats,$categories,$depth,$name) = @_;
8571: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
8572: my $chg = 0;
8573: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
8574: my $category = $chkcats->[$depth]{$name}[$j];
8575: my $item;
8576: if ($category eq '') {
8577: $chg ++;
8578: } else {
8579: my $deeper = $depth + 1;
8580: $item = &escape($category).':'.&escape($name).':'.$depth;
8581: if ($chg) {
8582: $categories->{$item} -= $chg;
8583: }
8584: &recurse_check($chkcats,$categories,$deeper,$category);
8585: $deeper --;
8586: }
8587: }
8588: }
8589: return;
8590: }
8591:
8592: sub recurse_cat_deletes {
8593: my ($item,$coursecategories,$deletions) = @_;
8594: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8595: my $subdepth = $depth + 1;
8596: if (ref($coursecategories) eq 'HASH') {
8597: foreach my $subitem (keys(%{$coursecategories})) {
8598: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
8599: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
8600: delete($coursecategories->{$subitem});
8601: $deletions->{$subitem} = 1;
8602: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 8603: }
1.48 raeburn 8604: }
8605: }
8606: return;
8607: }
8608:
1.125 raeburn 8609: sub get_active_dcs {
8610: my ($dom) = @_;
1.191 raeburn 8611: my $now = time;
8612: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 8613: my %domcoords;
8614: my $numdcs = 0;
8615: foreach my $server (keys(%dompersonnel)) {
8616: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
8617: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.191 raeburn 8618: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 8619: }
8620: }
8621: return %domcoords;
8622: }
8623:
8624: sub active_dc_picker {
1.191 raeburn 8625: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.125 raeburn 8626: my %domcoords = &get_active_dcs($dom);
1.191 raeburn 8627: my @domcoord = keys(%domcoords);
8628: if (keys(%currhash)) {
8629: foreach my $dc (keys(%currhash)) {
8630: unless (exists($domcoords{$dc})) {
8631: push(@domcoord,$dc);
8632: }
8633: }
8634: }
8635: @domcoord = sort(@domcoord);
8636: my $numdcs = scalar(@domcoord);
8637: my $rows = 0;
8638: my $table;
1.125 raeburn 8639: if ($numdcs > 1) {
1.191 raeburn 8640: $table = '<table>';
8641: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 8642: my $rem = $i%($numinrow);
8643: if ($rem == 0) {
8644: if ($i > 0) {
1.191 raeburn 8645: $table .= '</tr>';
1.125 raeburn 8646: }
1.191 raeburn 8647: $table .= '<tr>';
8648: $rows ++;
1.125 raeburn 8649: }
1.191 raeburn 8650: my $check = '';
8651: if ($inputtype eq 'radio') {
8652: if (keys(%currhash) == 0) {
8653: if (!$i) {
8654: $check = ' checked="checked"';
8655: }
8656: } elsif (exists($currhash{$domcoord[$i]})) {
8657: $check = ' checked="checked"';
8658: }
8659: } else {
8660: if (exists($currhash{$domcoord[$i]})) {
8661: $check = ' checked="checked"';
1.125 raeburn 8662: }
8663: }
1.191 raeburn 8664: if ($i == @domcoord - 1) {
1.125 raeburn 8665: my $colsleft = $numinrow - $rem;
8666: if ($colsleft > 1) {
1.191 raeburn 8667: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 8668: } else {
1.191 raeburn 8669: $table .= '<td class="LC_left_item">';
1.125 raeburn 8670: }
8671: } else {
1.191 raeburn 8672: $table .= '<td class="LC_left_item">';
8673: }
8674: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
8675: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
8676: $table .= '<span class="LC_nobreak"><label>'.
8677: '<input type="'.$inputtype.'" name="'.$name.'"'.
8678: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
8679: if ($user ne $dcname.':'.$dcdom) {
8680: $table .= ' ('.$dcname.':'.$dcdom.')'.
8681: '</label></span></td>';
8682: }
8683: }
8684: $table .= '</tr></table>';
8685: } elsif ($numdcs == 1) {
8686: if ($inputtype eq 'radio') {
8687: $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />';
8688: } else {
8689: my $check;
8690: if (exists($currhash{$domcoord[0]})) {
8691: $check = ' checked="checked"';
1.125 raeburn 8692: }
1.191 raeburn 8693: $table .= '<input type="checkbox" name="'.$name.'" '.
8694: 'value="'.$domcoord[0].'"'.$check.' />';
8695: $rows ++;
1.125 raeburn 8696: }
8697: }
1.191 raeburn 8698: return ($numdcs,$table,$rows);
1.125 raeburn 8699: }
8700:
1.137 raeburn 8701: sub usersession_titles {
8702: return &Apache::lonlocal::texthash(
8703: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
8704: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 8705: spares => 'Servers offloaded to, when busy',
1.137 raeburn 8706: version => 'LON-CAPA version requirement',
1.138 raeburn 8707: excludedomain => 'Allow all, but exclude specific domains',
8708: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 8709: primary => 'Primary (checked first)',
1.154 raeburn 8710: default => 'Default',
1.137 raeburn 8711: );
8712: }
8713:
1.152 raeburn 8714: sub id_for_thisdom {
8715: my (%servers) = @_;
8716: my %altids;
8717: foreach my $server (keys(%servers)) {
8718: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
8719: if ($serverhome ne $server) {
8720: $altids{$serverhome} = $server;
8721: }
8722: }
8723: return %altids;
8724: }
8725:
1.150 raeburn 8726: sub count_servers {
8727: my ($currbalancer,%servers) = @_;
8728: my (@spares,$numspares);
8729: foreach my $lonhost (sort(keys(%servers))) {
8730: next if ($currbalancer eq $lonhost);
8731: push(@spares,$lonhost);
8732: }
8733: if ($currbalancer) {
8734: $numspares = scalar(@spares);
8735: } else {
8736: $numspares = scalar(@spares) - 1;
8737: }
8738: return ($numspares,@spares);
8739: }
8740:
8741: sub lonbalance_targets_js {
1.171 raeburn 8742: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 8743: my $select = &mt('Select');
8744: my ($alltargets,$allishome,$allinsttypes,@alltypes);
8745: if (ref($servers) eq 'HASH') {
8746: $alltargets = join("','",sort(keys(%{$servers})));
8747: my @homedoms;
8748: foreach my $server (sort(keys(%{$servers}))) {
8749: if (&Apache::lonnet::host_domain($server) eq $dom) {
8750: push(@homedoms,'1');
8751: } else {
8752: push(@homedoms,'0');
8753: }
8754: }
8755: $allishome = join("','",@homedoms);
8756: }
8757: if (ref($types) eq 'ARRAY') {
8758: if (@{$types} > 0) {
8759: @alltypes = @{$types};
8760: }
8761: }
8762: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
8763: $allinsttypes = join("','",@alltypes);
1.171 raeburn 8764: my (%currbalancer,%currtargets,%currrules,%existing);
8765: if (ref($settings) eq 'HASH') {
8766: %existing = %{$settings};
8767: }
8768: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
8769: \%currtargets,\%currrules);
8770: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 8771: return <<"END";
8772:
8773: <script type="text/javascript">
8774: // <![CDATA[
8775:
1.171 raeburn 8776: currBalancers = new Array('$balancers');
8777:
8778: function toggleTargets(balnum) {
8779: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8780: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
8781: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
8782: var prevbalancer = prevhostitem.value;
8783: var baltotal = document.getElementById('loadbalancing_total').value;
8784: prevhostitem.value = balancer;
8785: if (prevbalancer != '') {
8786: var prevIdx = currBalancers.indexOf(prevbalancer);
8787: if (prevIdx != -1) {
8788: currBalancers.splice(prevIdx,1);
8789: }
8790: }
1.150 raeburn 8791: if (balancer == '') {
1.171 raeburn 8792: hideSpares(balnum);
1.150 raeburn 8793: } else {
1.171 raeburn 8794: var currIdx = currBalancers.indexOf(balancer);
8795: if (currIdx == -1) {
8796: currBalancers.push(balancer);
8797: }
1.150 raeburn 8798: var homedoms = new Array('$allishome');
1.171 raeburn 8799: var ishomedom = homedoms[lonhostitem.selectedIndex];
8800: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 8801: }
1.171 raeburn 8802: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 8803: return;
8804: }
8805:
1.171 raeburn 8806: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 8807: var alltargets = new Array('$alltargets');
8808: var insttypes = new Array('$allinsttypes');
1.151 raeburn 8809: var offloadtypes = new Array('primary','default');
8810:
1.171 raeburn 8811: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
8812: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 8813:
1.151 raeburn 8814: for (var i=0; i<offloadtypes.length; i++) {
8815: var count = 0;
8816: for (var j=0; j<alltargets.length; j++) {
8817: if (alltargets[j] != balancer) {
1.171 raeburn 8818: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
8819: item.value = alltargets[j];
8820: item.style.textAlign='left';
8821: item.style.textFace='normal';
8822: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
8823: if (currBalancers.indexOf(alltargets[j]) == -1) {
8824: item.disabled = '';
8825: } else {
8826: item.disabled = 'disabled';
8827: item.checked = false;
8828: }
1.151 raeburn 8829: count ++;
8830: }
1.150 raeburn 8831: }
8832: }
1.151 raeburn 8833: for (var k=0; k<insttypes.length; k++) {
8834: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 8835: if (ishomedom == 1) {
1.171 raeburn 8836: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8837: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8838: } else {
1.171 raeburn 8839: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8840: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 8841:
8842: }
8843: } else {
1.171 raeburn 8844: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8845: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8846: }
1.151 raeburn 8847: if ((insttypes[k] != '_LC_external') &&
8848: ((insttypes[k] != '_LC_internetdom') ||
8849: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 8850: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
8851: item.options.length = 0;
8852: item.options[0] = new Option("","",true,true);
8853: var idx = 0;
1.151 raeburn 8854: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 8855: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
8856: idx ++;
8857: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
8858:
1.150 raeburn 8859: }
8860: }
8861: }
8862: }
8863: return;
8864: }
8865:
1.171 raeburn 8866: function hideSpares(balnum) {
1.150 raeburn 8867: var alltargets = new Array('$alltargets');
8868: var insttypes = new Array('$allinsttypes');
8869: var offloadtypes = new Array('primary','default');
8870:
1.171 raeburn 8871: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
8872: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 8873:
8874: var total = alltargets.length - 1;
8875: for (var i=0; i<offloadtypes; i++) {
8876: for (var j=0; j<total; j++) {
1.171 raeburn 8877: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
8878: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
8879: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 8880: }
1.150 raeburn 8881: }
8882: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 8883: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8884: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 8885: if (insttypes[k] != '_LC_external') {
1.171 raeburn 8886: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
8887: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 8888: }
8889: }
8890: return;
8891: }
8892:
1.171 raeburn 8893: function checkOffloads(item,balnum,type) {
1.150 raeburn 8894: var alltargets = new Array('$alltargets');
8895: var offloadtypes = new Array('primary','default');
8896: if (item.checked) {
8897: var total = alltargets.length - 1;
8898: var other;
8899: if (type == offloadtypes[0]) {
1.151 raeburn 8900: other = offloadtypes[1];
1.150 raeburn 8901: } else {
1.151 raeburn 8902: other = offloadtypes[0];
1.150 raeburn 8903: }
8904: for (var i=0; i<total; i++) {
1.171 raeburn 8905: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 8906: if (server == item.value) {
1.171 raeburn 8907: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
8908: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 8909: }
8910: }
8911: }
8912: }
8913: return;
8914: }
8915:
1.171 raeburn 8916: function singleServerToggle(balnum,type) {
8917: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 8918: if (offloadtoSelIdx == 0) {
1.171 raeburn 8919: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
8920: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 8921:
8922: } else {
1.171 raeburn 8923: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
8924: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 8925: }
8926: return;
8927: }
8928:
1.171 raeburn 8929: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 8930: if (type == '_LC_external') {
1.171 raeburn 8931: return;
1.150 raeburn 8932: }
1.171 raeburn 8933: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 8934: for (var i=0; i<typesRules.length; i++) {
8935: if (formname.elements[typesRules[i]].checked) {
8936: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 8937: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
8938: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 8939: } else {
1.171 raeburn 8940: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
8941: }
8942: }
8943: }
8944: return;
8945: }
8946:
8947: function balancerDeleteChange(balnum) {
8948: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8949: var baltotal = document.getElementById('loadbalancing_total').value;
8950: var addtarget;
8951: var removetarget;
8952: var action = 'delete';
8953: if (document.getElementById('loadbalancing_delete_'+balnum)) {
8954: var lonhost = hostitem.value;
8955: var currIdx = currBalancers.indexOf(lonhost);
8956: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
8957: if (currIdx != -1) {
8958: currBalancers.splice(currIdx,1);
8959: }
8960: addtarget = lonhost;
8961: } else {
8962: if (currIdx == -1) {
8963: currBalancers.push(lonhost);
8964: }
8965: removetarget = lonhost;
8966: action = 'undelete';
8967: }
8968: balancerChange(balnum,baltotal,action,addtarget,removetarget);
8969: }
8970: return;
8971: }
8972:
8973: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
8974: if (baltotal > 1) {
8975: var offloadtypes = new Array('primary','default');
8976: var alltargets = new Array('$alltargets');
8977: var insttypes = new Array('$allinsttypes');
8978: for (var i=0; i<baltotal; i++) {
8979: if (i != balnum) {
8980: for (var j=0; j<offloadtypes.length; j++) {
8981: var total = alltargets.length - 1;
8982: for (var k=0; k<total; k++) {
8983: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
8984: var server = serveritem.value;
8985: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
8986: if (server == addtarget) {
8987: serveritem.disabled = '';
8988: }
8989: }
8990: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
8991: if (server == removetarget) {
8992: serveritem.disabled = 'disabled';
8993: serveritem.checked = false;
8994: }
8995: }
8996: }
8997: }
8998: for (var j=0; j<insttypes.length; j++) {
8999: if (insttypes[j] != '_LC_external') {
9000: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
9001: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
9002: var currSel = singleserver.selectedIndex;
9003: var currVal = singleserver.options[currSel].value;
9004: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
9005: var numoptions = singleserver.options.length;
9006: var needsnew = 1;
9007: for (var k=0; k<numoptions; k++) {
9008: if (singleserver.options[k] == addtarget) {
9009: needsnew = 0;
9010: break;
9011: }
9012: }
9013: if (needsnew == 1) {
9014: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
9015: }
9016: }
9017: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
9018: singleserver.options.length = 0;
9019: if ((currVal) && (currVal != removetarget)) {
9020: singleserver.options[0] = new Option("","",false,false);
9021: } else {
9022: singleserver.options[0] = new Option("","",true,true);
9023: }
9024: var idx = 0;
9025: for (var m=0; m<alltargets.length; m++) {
9026: if (currBalancers.indexOf(alltargets[m]) == -1) {
9027: idx ++;
9028: if (currVal == alltargets[m]) {
9029: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
9030: } else {
9031: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
9032: }
9033: }
9034: }
9035: }
9036: }
9037: }
9038: }
1.150 raeburn 9039: }
9040: }
9041: }
9042: return;
9043: }
9044:
1.152 raeburn 9045: // ]]>
9046: </script>
9047:
9048: END
9049: }
9050:
9051: sub new_spares_js {
9052: my @sparestypes = ('primary','default');
9053: my $types = join("','",@sparestypes);
9054: my $select = &mt('Select');
9055: return <<"END";
9056:
9057: <script type="text/javascript">
9058: // <![CDATA[
9059:
9060: function updateNewSpares(formname,lonhost) {
9061: var types = new Array('$types');
9062: var include = new Array();
9063: var exclude = new Array();
9064: for (var i=0; i<types.length; i++) {
9065: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
9066: for (var j=0; j<spareboxes.length; j++) {
9067: if (formname.elements[spareboxes[j]].checked) {
9068: exclude.push(formname.elements[spareboxes[j]].value);
9069: } else {
9070: include.push(formname.elements[spareboxes[j]].value);
9071: }
9072: }
9073: }
9074: for (var i=0; i<types.length; i++) {
9075: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
9076: var selIdx = newSpare.selectedIndex;
9077: var currnew = newSpare.options[selIdx].value;
9078: var okSpares = new Array();
9079: for (var j=0; j<newSpare.options.length; j++) {
9080: var possible = newSpare.options[j].value;
9081: if (possible != '') {
9082: if (exclude.indexOf(possible) == -1) {
9083: okSpares.push(possible);
9084: } else {
9085: if (currnew == possible) {
9086: selIdx = 0;
9087: }
9088: }
9089: }
9090: }
9091: for (var k=0; k<include.length; k++) {
9092: if (okSpares.indexOf(include[k]) == -1) {
9093: okSpares.push(include[k]);
9094: }
9095: }
9096: okSpares.sort();
9097: newSpare.options.length = 0;
9098: if (selIdx == 0) {
9099: newSpare.options[0] = new Option("$select","",true,true);
9100: } else {
9101: newSpare.options[0] = new Option("$select","",false,false);
9102: }
9103: for (var m=0; m<okSpares.length; m++) {
9104: var idx = m+1;
9105: var selThis = 0;
9106: if (selIdx != 0) {
9107: if (okSpares[m] == currnew) {
9108: selThis = 1;
9109: }
9110: }
9111: if (selThis == 1) {
9112: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
9113: } else {
9114: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
9115: }
9116: }
9117: }
9118: return;
9119: }
9120:
9121: function checkNewSpares(lonhost,type) {
9122: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
9123: var chosen = newSpare.options[newSpare.selectedIndex].value;
9124: if (chosen != '') {
9125: var othertype;
9126: var othernewSpare;
9127: if (type == 'primary') {
9128: othernewSpare = document.getElementById('newspare_default_'+lonhost);
9129: }
9130: if (type == 'default') {
9131: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
9132: }
9133: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
9134: othernewSpare.selectedIndex = 0;
9135: }
9136: }
9137: return;
9138: }
9139:
9140: // ]]>
9141: </script>
9142:
9143: END
9144:
9145: }
9146:
9147: sub common_domprefs_js {
9148: return <<"END";
9149:
9150: <script type="text/javascript">
9151: // <![CDATA[
9152:
1.150 raeburn 9153: function getIndicesByName(formname,item) {
1.152 raeburn 9154: var group = new Array();
1.150 raeburn 9155: for (var i=0;i<formname.elements.length;i++) {
9156: if (formname.elements[i].name == item) {
1.152 raeburn 9157: group.push(formname.elements[i].id);
1.150 raeburn 9158: }
9159: }
1.152 raeburn 9160: return group;
1.150 raeburn 9161: }
9162:
9163: // ]]>
9164: </script>
9165:
9166: END
1.152 raeburn 9167:
1.150 raeburn 9168: }
9169:
1.165 raeburn 9170: sub recaptcha_js {
9171: my %lt = &captcha_phrases();
9172: return <<"END";
9173:
9174: <script type="text/javascript">
9175: // <![CDATA[
9176:
9177: function updateCaptcha(caller,context) {
9178: var privitem;
9179: var pubitem;
9180: var privtext;
9181: var pubtext;
9182: if (document.getElementById(context+'_recaptchapub')) {
9183: pubitem = document.getElementById(context+'_recaptchapub');
9184: } else {
9185: return;
9186: }
9187: if (document.getElementById(context+'_recaptchapriv')) {
9188: privitem = document.getElementById(context+'_recaptchapriv');
9189: } else {
9190: return;
9191: }
9192: if (document.getElementById(context+'_recaptchapubtxt')) {
9193: pubtext = document.getElementById(context+'_recaptchapubtxt');
9194: } else {
9195: return;
9196: }
9197: if (document.getElementById(context+'_recaptchaprivtxt')) {
9198: privtext = document.getElementById(context+'_recaptchaprivtxt');
9199: } else {
9200: return;
9201: }
9202: if (caller.checked) {
9203: if (caller.value == 'recaptcha') {
9204: pubitem.type = 'text';
9205: privitem.type = 'text';
9206: pubitem.size = '40';
9207: privitem.size = '40';
9208: pubtext.innerHTML = "$lt{'pub'}";
9209: privtext.innerHTML = "$lt{'priv'}";
9210: } else {
9211: pubitem.type = 'hidden';
9212: privitem.type = 'hidden';
9213: pubtext.innerHTML = '';
9214: privtext.innerHTML = '';
9215: }
9216: }
9217: return;
9218: }
9219:
9220: // ]]>
9221: </script>
9222:
9223: END
9224:
9225: }
9226:
1.192 raeburn 9227: sub credits_js {
9228: return <<"END";
9229:
9230: <script type="text/javascript">
9231: // <![CDATA[
9232:
9233: function toggleCredits(domForm) {
9234: if (document.getElementById('credits')) {
9235: creditsitem = document.getElementById('credits');
9236: var creditsLength = domForm.coursecredits.length;
9237: if (creditsLength) {
9238: var currval;
9239: for (var i=0; i<creditsLength; i++) {
9240: if (domForm.coursecredits[i].checked) {
9241: currval = domForm.coursecredits[i].value;
9242: }
9243: }
9244: if (currval == 1) {
9245: creditsitem.style.display = 'block';
9246: } else {
9247: creditsitem.style.display = 'none';
9248: }
9249: }
9250: }
9251: return;
9252: }
9253:
9254: // ]]>
9255: </script>
9256:
9257: END
9258:
9259: }
9260:
1.165 raeburn 9261: sub captcha_phrases {
9262: return &Apache::lonlocal::texthash (
9263: priv => 'Private key',
9264: pub => 'Public key',
9265: original => 'original (CAPTCHA)',
9266: recaptcha => 'successor (ReCAPTCHA)',
9267: notused => 'unused',
9268: );
9269: }
9270:
1.3 raeburn 9271: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>