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