Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.27
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.27! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.26 2013/09/29 06:55:58 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.160.6.13 raeburn 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.160.6.27! raeburn 89: number of rows displayed on the page, and $action is the context (quotas,
1.160.6.5 raeburn 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.160.6.20 raeburn 97: used by course owners to request creation of a course, and to display/store
98: default quota sizes for authoring spaces.
99:
1.101 raeburn 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',
1.160.6.16 raeburn 214: 'serverstatuses','requestcourses','coursedefaults',
215: 'usersessions','loadbalancing','requestauthor'],$dom);
1.43 raeburn 216: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 217: 'autoupdate','autocreate','directorysrch','contacts',
1.48 raeburn 218: 'usercreation','usermodification','scantron',
1.160.6.5 raeburn 219: 'requestcourses','requestauthor','coursecategories',
1.160.6.16 raeburn 220: 'serverstatuses','coursedefaults','usersessions');
1.160.6.7 raeburn 221: my %existing;
222: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
223: %existing = %{$domconfig{'loadbalancing'}};
224: }
225: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 226: push(@prefs_order,'loadbalancing');
227: }
1.30 raeburn 228: my %prefs = (
229: 'rolecolors' =>
230: { text => 'Default color schemes',
1.67 raeburn 231: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 232: header => [{col1 => 'Student Settings',
233: col2 => '',},
234: {col1 => 'Coordinator Settings',
235: col2 => '',},
236: {col1 => 'Author Settings',
237: col2 => '',},
238: {col1 => 'Administrator Settings',
239: col2 => '',}],
240: },
1.110 raeburn 241: 'login' =>
1.30 raeburn 242: { text => 'Log-in page options',
1.67 raeburn 243: help => 'Domain_Configuration_Login_Page',
1.160.6.5 raeburn 244: header => [{col1 => 'Log-in Page Items',
245: col2 => '',},
246: {col1 => 'Log-in Help',
247: col2 => 'Value'}],
1.30 raeburn 248: },
1.43 raeburn 249: 'defaults' =>
1.141 raeburn 250: { text => 'Default authentication/language/timezone/portal',
1.67 raeburn 251: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 252: header => [{col1 => 'Setting',
253: col2 => 'Value'}],
254: },
1.30 raeburn 255: 'quotas' =>
1.160.6.20 raeburn 256: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 257: help => 'Domain_Configuration_Quotas',
1.77 raeburn 258: header => [{col1 => 'User affiliation',
1.72 raeburn 259: col2 => 'Available tools',
1.160.6.20 raeburn 260: col3 => 'Quotas, Mb; (Authoring requires role)',}],
1.30 raeburn 261: },
262: 'autoenroll' =>
263: { text => 'Auto-enrollment settings',
1.67 raeburn 264: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 265: header => [{col1 => 'Configuration setting',
266: col2 => 'Value(s)'}],
267: },
268: 'autoupdate' =>
269: { text => 'Auto-update settings',
1.67 raeburn 270: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 271: header => [{col1 => 'Setting',
272: col2 => 'Value',},
1.131 raeburn 273: {col1 => 'Setting',
274: col2 => 'Affiliation'},
1.43 raeburn 275: {col1 => 'User population',
1.131 raeburn 276: col2 => 'Updateable user data'}],
1.30 raeburn 277: },
1.125 raeburn 278: 'autocreate' =>
279: { text => 'Auto-course creation settings',
280: help => 'Domain_Configuration_Auto_Creation',
281: header => [{col1 => 'Configuration Setting',
282: col2 => 'Value',}],
283: },
1.30 raeburn 284: 'directorysrch' =>
285: { text => 'Institutional directory searches',
1.67 raeburn 286: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 287: header => [{col1 => 'Setting',
288: col2 => 'Value',}],
289: },
290: 'contacts' =>
291: { text => 'Contact Information',
1.67 raeburn 292: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 293: header => [{col1 => 'Setting',
294: col2 => 'Value',}],
295: },
296:
297: 'usercreation' =>
298: { text => 'User creation',
1.67 raeburn 299: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 300: header => [{col1 => 'Format rule type',
301: col2 => 'Format rules in force'},
1.34 raeburn 302: {col1 => 'User account creation',
303: col2 => 'Usernames which may be created',},
1.30 raeburn 304: {col1 => 'Context',
1.43 raeburn 305: col2 => 'Assignable authentication types'}],
1.30 raeburn 306: },
1.69 raeburn 307: 'usermodification' =>
1.33 raeburn 308: { text => 'User modification',
1.67 raeburn 309: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 310: header => [{col1 => 'Target user has role',
311: col2 => 'User information updateable in author context'},
312: {col1 => 'Target user has role',
1.63 raeburn 313: col2 => 'User information updateable in course context'},
314: {col1 => "Status of user",
315: col2 => 'Information settable when self-creating account (if directory data blank)'}],
1.33 raeburn 316: },
1.69 raeburn 317: 'scantron' =>
1.95 www 318: { text => 'Bubblesheet format file',
1.67 raeburn 319: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 320: header => [ {col1 => 'Item',
321: col2 => '',
322: }],
323: },
1.86 raeburn 324: 'requestcourses' =>
325: {text => 'Request creation of courses',
326: help => 'Domain_Configuration_Request_Courses',
327: header => [{col1 => 'User affiliation',
1.102 raeburn 328: col2 => 'Availability/Processing of requests',},
329: {col1 => 'Setting',
330: col2 => 'Value'}],
1.86 raeburn 331: },
1.160.6.5 raeburn 332: 'requestauthor' =>
333: {text => 'Request authoring space',
334: help => 'Domain_Configuration_Request_Author',
335: header => [{col1 => 'User affiliation',
336: col2 => 'Availability/Processing of requests',},
337: {col1 => 'Setting',
338: col2 => 'Value'}],
339: },
1.69 raeburn 340: 'coursecategories' =>
1.120 raeburn 341: { text => 'Cataloging of courses/communities',
1.67 raeburn 342: help => 'Domain_Configuration_Cataloging_Courses',
1.69 raeburn 343: header => [{col1 => 'Category settings',
1.57 raeburn 344: col2 => '',},
345: {col1 => 'Categories',
346: col2 => '',
347: }],
1.69 raeburn 348: },
349: 'serverstatuses' =>
1.77 raeburn 350: {text => 'Access to server status pages',
1.69 raeburn 351: help => 'Domain_Configuration_Server_Status',
352: header => [{col1 => 'Status Page',
353: col2 => 'Other named users',
354: col3 => 'Specific IPs',
355: }],
356: },
1.160.6.16 raeburn 357: 'coursedefaults' =>
358: {text => 'Course/Community defaults',
359: help => 'Domain_Configuration_Course_Defaults',
360: header => [{col1 => 'Defaults which can be overridden for each course by a DC',
361: col2 => 'Value',},],
362: },
1.141 raeburn 363: 'usersessions' =>
1.145 raeburn 364: {text => 'User session hosting/offloading',
1.137 raeburn 365: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 366: header => [{col1 => 'Domain server',
367: col2 => 'Servers to offload sessions to when busy'},
368: {col1 => 'Hosting of users from other domains',
1.137 raeburn 369: col2 => 'Rules'},
370: {col1 => "Hosting domain's own users elsewhere",
371: col2 => 'Rules'}],
372: },
1.150 raeburn 373: 'loadbalancing' =>
1.160.6.7 raeburn 374: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 375: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 376: header => [{col1 => 'Balancers',
1.150 raeburn 377: col2 => 'Default destinations',
1.160.6.13 raeburn 378: col3 => 'User affiliation',
1.150 raeburn 379: col4 => 'Overrides'},
380: ],
381: },
1.3 raeburn 382: );
1.110 raeburn 383: if (keys(%servers) > 1) {
384: $prefs{'login'} = { text => 'Log-in page options',
385: help => 'Domain_Configuration_Login_Page',
386: header => [{col1 => 'Log-in Service',
387: col2 => 'Server Setting',},
388: {col1 => 'Log-in Page Items',
1.160.6.5 raeburn 389: col2 => ''},
390: {col1 => 'Log-in Help',
391: col2 => 'Value'}],
1.110 raeburn 392: };
393: }
1.160.6.13 raeburn 394:
1.6 raeburn 395: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 396: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 397: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 398: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 399: text=>"Settings to display/modify"});
1.9 raeburn 400: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 401:
1.3 raeburn 402: if ($phase eq 'process') {
1.160.6.27! raeburn 403: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
! 404: \%prefs,\%domconfig,$confname,\@roles);
! 405: if (ref($result) eq 'HASH') {
1.160.6.24 raeburn 406: $r->rflush();
1.160.6.27! raeburn 407: &devalidate_remote_domconfs($dom,$result);
1.160.6.24 raeburn 408: }
1.30 raeburn 409: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 410: my $js = &recaptcha_js().
1.160.6.26 raeburn 411: &credits_js();
1.160.6.7 raeburn 412: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 413: my ($othertitle,$usertypes,$types) =
414: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 415: $js .= &lonbalance_targets_js($dom,$types,\%servers,
416: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 417: &new_spares_js().
418: &common_domprefs_js().
419: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 420: }
1.150 raeburn 421: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 422: } else {
1.160.6.11 raeburn 423: # check if domconfig user exists for the domain.
424: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 425: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 426: &config_check($dom,$confname,$servadm);
427: unless ($configuserok eq 'ok') {
428: &Apache::lonconfigsettings::print_header($r,$phase,$context);
429: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
430: $confname).
431: '<br />'
432: );
433: if ($switchserver) {
434: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
435: '<br />'.
436: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
437: '<br />'.
438: &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).
439: '<br />'.
440: &mt('To do that now, use the following link: [_1]',$switchserver)
441: );
442: } else {
443: $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.').
444: '<br />'.
445: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
446: );
447: }
448: $r->print(&Apache::loncommon::end_page());
449: return OK;
450: }
1.21 raeburn 451: if (keys(%domconfig) == 0) {
452: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 453: my @ids=&Apache::lonnet::current_machine_ids();
454: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 455: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 456: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 457: my $custom_img_count = 0;
458: foreach my $img (@loginimages) {
459: if ($designhash{$dom.'.login.'.$img} ne '') {
460: $custom_img_count ++;
461: }
462: }
463: foreach my $role (@roles) {
464: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
465: $custom_img_count ++;
466: }
467: }
468: if ($custom_img_count > 0) {
1.94 raeburn 469: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 470: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 471: $r->print(
472: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
473: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
474: &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 />'.
475: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
476: if ($switch_server) {
1.30 raeburn 477: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 478: }
1.91 raeburn 479: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 480: return OK;
481: }
482: }
483: }
1.91 raeburn 484: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 485: }
486: return OK;
487: }
488:
489: sub process_changes {
1.160.6.24 raeburn 490: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 491: my %domconfig;
492: if (ref($values) eq 'HASH') {
493: %domconfig = %{$values};
494: }
1.3 raeburn 495: my $output;
496: if ($action eq 'login') {
1.160.6.24 raeburn 497: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 498: } elsif ($action eq 'rolecolors') {
1.9 raeburn 499: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 500: $lastactref,%domconfig);
1.3 raeburn 501: } elsif ($action eq 'quotas') {
1.160.6.27! raeburn 502: $output = &modify_quotas($dom,$action,$lastactref,%domconfig);
1.3 raeburn 503: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 504: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 505: } elsif ($action eq 'autoupdate') {
506: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 507: } elsif ($action eq 'autocreate') {
508: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 509: } elsif ($action eq 'directorysrch') {
510: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 511: } elsif ($action eq 'usercreation') {
1.28 raeburn 512: $output = &modify_usercreation($dom,%domconfig);
1.33 raeburn 513: } elsif ($action eq 'usermodification') {
514: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 515: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 516: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 517: } elsif ($action eq 'defaults') {
1.160.6.27! raeburn 518: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 519: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 520: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 521: } elsif ($action eq 'coursecategories') {
522: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 523: } elsif ($action eq 'serverstatuses') {
524: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 525: } elsif ($action eq 'requestcourses') {
1.160.6.27! raeburn 526: $output = &modify_quotas($dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 527: } elsif ($action eq 'requestauthor') {
1.160.6.27! raeburn 528: $output = &modify_quotas($dom,$action,$lastactref,%domconfig);
1.160.6.16 raeburn 529: } elsif ($action eq 'coursedefaults') {
1.160.6.27! raeburn 530: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.137 raeburn 531: } elsif ($action eq 'usersessions') {
1.160.6.27! raeburn 532: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 533: } elsif ($action eq 'loadbalancing') {
534: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 535: }
536: return $output;
537: }
538:
539: sub print_config_box {
1.9 raeburn 540: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 541: my $rowtotal = 0;
1.49 raeburn 542: my $output;
543: if ($action eq 'coursecategories') {
544: $output = &coursecategories_javascript($settings);
1.91 raeburn 545: }
1.49 raeburn 546: $output .=
1.30 raeburn 547: '<table class="LC_nested_outer">
1.3 raeburn 548: <tr>
1.66 raeburn 549: <th align="left" valign="middle"><span class="LC_nobreak">'.
550: &mt($item->{text}).' '.
551: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
552: '</tr>';
1.30 raeburn 553: $rowtotal ++;
1.110 raeburn 554: my $numheaders = 1;
555: if (ref($item->{'header'}) eq 'ARRAY') {
556: $numheaders = scalar(@{$item->{'header'}});
557: }
558: if ($numheaders > 1) {
1.64 raeburn 559: my $colspan = '';
1.145 raeburn 560: my $rightcolspan = '';
1.160.6.5 raeburn 561: if (($action eq 'rolecolors') || ($action eq 'coursecategories') ||
562: (($action eq 'login') && ($numheaders < 3))) {
1.64 raeburn 563: $colspan = ' colspan="2"';
564: }
1.145 raeburn 565: if ($action eq 'usersessions') {
566: $rightcolspan = ' colspan="3"';
567: }
1.30 raeburn 568: $output .= '
1.3 raeburn 569: <tr>
570: <td>
571: <table class="LC_nested">
572: <tr class="LC_info_row">
1.59 bisitz 573: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 574: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 575: </tr>';
1.69 raeburn 576: $rowtotal ++;
1.6 raeburn 577: if ($action eq 'autoupdate') {
1.30 raeburn 578: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 579: } elsif ($action eq 'usercreation') {
1.33 raeburn 580: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
581: } elsif ($action eq 'usermodification') {
582: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57 raeburn 583: } elsif ($action eq 'coursecategories') {
584: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 585: } elsif ($action eq 'login') {
1.160.6.5 raeburn 586: if ($numheaders == 3) {
587: $colspan = ' colspan="2"';
588: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
589: } else {
590: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
591: }
1.102 raeburn 592: } elsif ($action eq 'requestcourses') {
593: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.5 raeburn 594: } elsif ($action eq 'requestauthor') {
595: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.137 raeburn 596: } elsif ($action eq 'usersessions') {
597: $output .= &print_usersessions('top',$dom,$settings,\$rowtotal);
1.122 jms 598: } elsif ($action eq 'rolecolors') {
1.30 raeburn 599: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 600: }
1.30 raeburn 601: $output .= '
1.6 raeburn 602: </table>
603: </td>
604: </tr>
605: <tr>
606: <td>
607: <table class="LC_nested">
608: <tr class="LC_info_row">
1.59 bisitz 609: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57 raeburn 610: $output .= '
1.59 bisitz 611: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 612: </tr>';
613: $rowtotal ++;
1.6 raeburn 614: if ($action eq 'autoupdate') {
1.131 raeburn 615: $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
616: </table>
617: </td>
618: </tr>
619: <tr>
620: <td>
621: <table class="LC_nested">
622: <tr class="LC_info_row">
623: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
624: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
625: &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
626: $rowtotal ++;
1.28 raeburn 627: } elsif ($action eq 'usercreation') {
1.34 raeburn 628: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
629: </table>
630: </td>
631: </tr>
632: <tr>
633: <td>
634: <table class="LC_nested">
635: <tr class="LC_info_row">
1.59 bisitz 636: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
637: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.34 raeburn 638: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
639: $rowtotal ++;
1.33 raeburn 640: } elsif ($action eq 'usermodification') {
1.63 raeburn 641: $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
642: </table>
643: </td>
644: </tr>
645: <tr>
646: <td>
647: <table class="LC_nested">
648: <tr class="LC_info_row">
649: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
650: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
651: &print_usermodification('bottom',$dom,$settings,\$rowtotal);
652: $rowtotal ++;
1.57 raeburn 653: } elsif ($action eq 'coursecategories') {
654: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 655: } elsif ($action eq 'login') {
1.160.6.5 raeburn 656: if ($numheaders == 3) {
657: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
658: </table>
659: </td>
660: </tr>
661: <tr>
662: <td>
663: <table class="LC_nested">
664: <tr class="LC_info_row">
665: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
666: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
667: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
668: $rowtotal ++;
669: } else {
670: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
671: }
1.102 raeburn 672: } elsif ($action eq 'requestcourses') {
1.160.6.5 raeburn 673: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
674: } elsif ($action eq 'requestauthor') {
675: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.137 raeburn 676: } elsif ($action eq 'usersessions') {
1.145 raeburn 677: $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
678: </table>
679: </td>
680: </tr>
681: <tr>
682: <td>
683: <table class="LC_nested">
684: <tr class="LC_info_row">
685: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
686: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
687: &print_usersessions('bottom',$dom,$settings,\$rowtotal);
688: $rowtotal ++;
1.122 jms 689: } elsif ($action eq 'rolecolors') {
1.30 raeburn 690: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 691: </table>
692: </td>
693: </tr>
694: <tr>
695: <td>
696: <table class="LC_nested">
697: <tr class="LC_info_row">
1.69 raeburn 698: <td class="LC_left_item"'.$colspan.' valign="top">'.
699: &mt($item->{'header'}->[2]->{'col1'}).'</td>
700: <td class="LC_right_item" valign="top">'.
701: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 702: </tr>'.
1.30 raeburn 703: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 704: </table>
705: </td>
706: </tr>
707: <tr>
708: <td>
709: <table class="LC_nested">
710: <tr class="LC_info_row">
1.59 bisitz 711: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
712: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 713: </tr>'.
1.30 raeburn 714: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
715: $rowtotal += 2;
1.6 raeburn 716: }
1.3 raeburn 717: } else {
1.30 raeburn 718: $output .= '
1.3 raeburn 719: <tr>
720: <td>
721: <table class="LC_nested">
1.30 raeburn 722: <tr class="LC_info_row">';
1.24 raeburn 723: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 724: $output .= '
1.59 bisitz 725: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 726: } elsif ($action eq 'serverstatuses') {
727: $output .= '
728: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
729: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
730:
1.6 raeburn 731: } else {
1.30 raeburn 732: $output .= '
1.69 raeburn 733: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
734: }
1.72 raeburn 735: if (defined($item->{'header'}->[0]->{'col3'})) {
736: $output .= '<td class="LC_left_item" valign="top">'.
737: &mt($item->{'header'}->[0]->{'col2'});
738: if ($action eq 'serverstatuses') {
739: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
740: }
1.69 raeburn 741: } else {
742: $output .= '<td class="LC_right_item" valign="top">'.
743: &mt($item->{'header'}->[0]->{'col2'});
744: }
745: $output .= '</td>';
746: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 747: if (defined($item->{'header'}->[0]->{'col4'})) {
748: $output .= '<td class="LC_left_item" valign="top">'.
749: &mt($item->{'header'}->[0]->{'col3'});
750: } else {
751: $output .= '<td class="LC_right_item" valign="top">'.
752: &mt($item->{'header'}->[0]->{'col3'});
753: }
1.69 raeburn 754: if ($action eq 'serverstatuses') {
755: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
756: }
757: $output .= '</td>';
1.6 raeburn 758: }
1.150 raeburn 759: if ($item->{'header'}->[0]->{'col4'}) {
760: $output .= '<td class="LC_right_item" valign="top">'.
761: &mt($item->{'header'}->[0]->{'col4'});
762: }
1.69 raeburn 763: $output .= '</tr>';
1.48 raeburn 764: $rowtotal ++;
1.160.6.5 raeburn 765: if ($action eq 'quotas') {
1.86 raeburn 766: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3 raeburn 767: } elsif ($action eq 'autoenroll') {
1.30 raeburn 768: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125 raeburn 769: } elsif ($action eq 'autocreate') {
770: $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23 raeburn 771: } elsif ($action eq 'directorysrch') {
1.30 raeburn 772: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 773: } elsif ($action eq 'contacts') {
1.30 raeburn 774: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 raeburn 775: } elsif ($action eq 'defaults') {
1.160.6.27! raeburn 776: $output .= &print_defaults($dom,$settings,\$rowtotal);
1.46 raeburn 777: } elsif ($action eq 'scantron') {
778: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69 raeburn 779: } elsif ($action eq 'serverstatuses') {
780: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118 jms 781: } elsif ($action eq 'helpsettings') {
1.160.6.5 raeburn 782: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.150 raeburn 783: } elsif ($action eq 'loadbalancing') {
784: $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.160.6.16 raeburn 785: } elsif ($action eq 'coursedefaults') {
786: $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.121 raeburn 787: }
1.3 raeburn 788: }
1.30 raeburn 789: $output .= '
1.3 raeburn 790: </table>
791: </td>
792: </tr>
1.30 raeburn 793: </table><br />';
794: return ($output,$rowtotal);
1.1 raeburn 795: }
796:
1.3 raeburn 797: sub print_login {
1.160.6.5 raeburn 798: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 799: my ($css_class,$datatable);
1.6 raeburn 800: my %choices = &login_choices();
1.110 raeburn 801:
1.160.6.5 raeburn 802: if ($caller eq 'service') {
1.149 raeburn 803: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 804: my $choice = $choices{'disallowlogin'};
805: $css_class = ' class="LC_odd_row"';
1.128 raeburn 806: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 807: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 808: '<th>'.$choices{'server'}.'</th>'.
809: '<th>'.$choices{'serverpath'}.'</th>'.
810: '<th>'.$choices{'custompath'}.'</th>'.
811: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 812: my %disallowed;
813: if (ref($settings) eq 'HASH') {
814: if (ref($settings->{'loginvia'}) eq 'HASH') {
815: %disallowed = %{$settings->{'loginvia'}};
816: }
817: }
818: foreach my $lonhost (sort(keys(%servers))) {
819: my $direct = 'selected="selected"';
1.128 raeburn 820: if (ref($disallowed{$lonhost}) eq 'HASH') {
821: if ($disallowed{$lonhost}{'server'} ne '') {
822: $direct = '';
823: }
1.110 raeburn 824: }
1.115 raeburn 825: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 826: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 827: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
828: '</option>';
1.160.6.13 raeburn 829: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 830: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 831: my $selected = '';
1.128 raeburn 832: if (ref($disallowed{$lonhost}) eq 'HASH') {
833: if ($hostid eq $disallowed{$lonhost}{'server'}) {
834: $selected = 'selected="selected"';
835: }
1.110 raeburn 836: }
837: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
838: $servers{$hostid}.'</option>';
839: }
1.128 raeburn 840: $datatable .= '</select></td>'.
841: '<td><select name="'.$lonhost.'_serverpath">';
842: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
843: my $pathname = $path;
844: if ($path eq 'custom') {
845: $pathname = &mt('Custom Path').' ->';
846: }
847: my $selected = '';
848: if (ref($disallowed{$lonhost}) eq 'HASH') {
849: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
850: $selected = 'selected="selected"';
851: }
852: } elsif ($path eq '') {
853: $selected = 'selected="selected"';
854: }
855: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
856: }
857: $datatable .= '</select></td>';
858: my ($custom,$exempt);
859: if (ref($disallowed{$lonhost}) eq 'HASH') {
860: $custom = $disallowed{$lonhost}{'custompath'};
861: $exempt = $disallowed{$lonhost}{'exempt'};
862: }
863: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
864: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
865: '</tr>';
1.110 raeburn 866: }
867: $datatable .= '</table></td></tr>';
868: return $datatable;
1.160.6.5 raeburn 869: } elsif ($caller eq 'page') {
870: my %defaultchecked = (
871: 'coursecatalog' => 'on',
1.160.6.14 raeburn 872: 'helpdesk' => 'on',
1.160.6.5 raeburn 873: 'adminmail' => 'off',
874: 'newuser' => 'off',
875: );
1.160.6.14 raeburn 876: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 877: my (%checkedon,%checkedoff);
1.42 raeburn 878: foreach my $item (@toggles) {
1.160.6.5 raeburn 879: if ($defaultchecked{$item} eq 'on') {
880: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 881: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 882: } elsif ($defaultchecked{$item} eq 'off') {
883: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 884: $checkedon{$item} = ' ';
885: }
1.1 raeburn 886: }
1.160.6.5 raeburn 887: my @images = ('img','logo','domlogo','login');
888: my @logintext = ('textcol','bgcol');
889: my @bgs = ('pgbg','mainbg','sidebg');
890: my @links = ('link','alink','vlink');
891: my %designhash = &Apache::loncommon::get_domainconf($dom);
892: my %defaultdesign = %Apache::loncommon::defaultdesign;
893: my (%is_custom,%designs);
894: my %defaults = (
895: font => $defaultdesign{'login.font'},
896: );
1.6 raeburn 897: foreach my $item (@images) {
1.160.6.5 raeburn 898: $defaults{$item} = $defaultdesign{'login.'.$item};
899: $defaults{'showlogo'}{$item} = 1;
900: }
901: foreach my $item (@bgs) {
902: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 903: }
1.41 raeburn 904: foreach my $item (@logintext) {
1.160.6.5 raeburn 905: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 906: }
1.160.6.5 raeburn 907: foreach my $item (@links) {
908: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 909: }
1.160.6.5 raeburn 910: if (ref($settings) eq 'HASH') {
911: foreach my $item (@toggles) {
912: if ($settings->{$item} eq '1') {
913: $checkedon{$item} = ' checked="checked" ';
914: $checkedoff{$item} = ' ';
915: } elsif ($settings->{$item} eq '0') {
916: $checkedoff{$item} = ' checked="checked" ';
917: $checkedon{$item} = ' ';
918: }
1.6 raeburn 919: }
1.160.6.5 raeburn 920: foreach my $item (@images) {
921: if (defined($settings->{$item})) {
922: $designs{$item} = $settings->{$item};
923: $is_custom{$item} = 1;
924: }
925: if (defined($settings->{'showlogo'}{$item})) {
926: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
927: }
928: }
929: foreach my $item (@logintext) {
930: if ($settings->{$item} ne '') {
931: $designs{'logintext'}{$item} = $settings->{$item};
932: $is_custom{$item} = 1;
933: }
934: }
935: if ($settings->{'font'} ne '') {
936: $designs{'font'} = $settings->{'font'};
937: $is_custom{'font'} = 1;
938: }
939: foreach my $item (@bgs) {
940: if ($settings->{$item} ne '') {
941: $designs{'bgs'}{$item} = $settings->{$item};
942: $is_custom{$item} = 1;
943: }
944: }
945: foreach my $item (@links) {
946: if ($settings->{$item} ne '') {
947: $designs{'links'}{$item} = $settings->{$item};
948: $is_custom{$item} = 1;
949: }
950: }
951: } else {
952: if ($designhash{$dom.'.login.font'} ne '') {
953: $designs{'font'} = $designhash{$dom.'.login.font'};
954: $is_custom{'font'} = 1;
955: }
956: foreach my $item (@images) {
957: if ($designhash{$dom.'.login.'.$item} ne '') {
958: $designs{$item} = $designhash{$dom.'.login.'.$item};
959: $is_custom{$item} = 1;
960: }
961: }
962: foreach my $item (@bgs) {
963: if ($designhash{$dom.'.login.'.$item} ne '') {
964: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
965: $is_custom{$item} = 1;
966: }
967: }
968: foreach my $item (@links) {
969: if ($designhash{$dom.'.login.'.$item} ne '') {
970: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
971: $is_custom{$item} = 1;
972: }
1.6 raeburn 973: }
974: }
1.160.6.5 raeburn 975: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
976: logo => 'Institution Logo',
977: domlogo => 'Domain Logo',
978: login => 'Login box');
979: my $itemcount = 1;
980: foreach my $item (@toggles) {
981: $css_class = $itemcount%2?' class="LC_odd_row"':'';
982: $datatable .=
983: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
984: '</td><td>'.
985: '<span class="LC_nobreak"><label><input type="radio" name="'.
986: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
987: '</label> <label><input type="radio" name="'.$item.'"'.
988: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
989: '</tr>';
990: $itemcount ++;
1.6 raeburn 991: }
1.160.6.5 raeburn 992: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
993: $datatable .= '</tr></table></td></tr>';
994: } elsif ($caller eq 'help') {
995: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
996: my $switchserver = &check_switchserver($dom,$confname);
997: my $itemcount = 1;
998: $defaulturl = '/adm/loginproblems.html';
999: $defaulttype = 'default';
1000: %lt = &Apache::lonlocal::texthash (
1001: del => 'Delete?',
1002: rep => 'Replace:',
1003: upl => 'Upload:',
1004: default => 'Default',
1005: custom => 'Custom',
1006: );
1007: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1008: my @currlangs;
1009: if (ref($settings) eq 'HASH') {
1010: if (ref($settings->{'helpurl'}) eq 'HASH') {
1011: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1012: next if ($settings->{'helpurl'}{$key} eq '');
1013: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1014: $type{$key} = 'custom';
1015: unless ($key eq 'nolang') {
1016: push(@currlangs,$key);
1017: }
1018: }
1019: } elsif ($settings->{'helpurl'} ne '') {
1020: $type{'nolang'} = 'custom';
1021: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1022: }
1023: }
1.160.6.5 raeburn 1024: foreach my $lang ('nolang',sort(@currlangs)) {
1025: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1026: $datatable .= '<tr'.$css_class.'>';
1027: if ($url{$lang} eq '') {
1028: $url{$lang} = $defaulturl;
1029: }
1030: if ($type{$lang} eq '') {
1031: $type{$lang} = $defaulttype;
1032: }
1033: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1034: if ($lang eq 'nolang') {
1035: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1036: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1037: } else {
1038: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1039: $langchoices{$lang},
1040: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1041: }
1042: $datatable .= '</span></td>'."\n".
1043: '<td class="LC_left_item">';
1044: if ($type{$lang} eq 'custom') {
1045: $datatable .= '<span class="LC_nobreak"><label>'.
1046: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1047: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1048: } else {
1049: $datatable .= $lt{'upl'};
1050: }
1051: $datatable .='<br />';
1052: if ($switchserver) {
1053: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1054: } else {
1055: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1056: }
1.160.6.5 raeburn 1057: $datatable .= '</td></tr>';
1058: $itemcount ++;
1.6 raeburn 1059: }
1.160.6.5 raeburn 1060: my @addlangs;
1061: foreach my $lang (sort(keys(%langchoices))) {
1062: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1063: push(@addlangs,$lang);
1064: }
1065: if (@addlangs > 0) {
1066: my %toadd;
1067: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1068: $toadd{''} = &mt('Select');
1069: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1070: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1071: &mt('Add log-in help page for a specific language:').' '.
1072: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1073: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1074: if ($switchserver) {
1075: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1076: } else {
1077: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1078: }
1.160.6.5 raeburn 1079: $datatable .= '</td></tr>';
1080: $itemcount ++;
1.6 raeburn 1081: }
1.160.6.5 raeburn 1082: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1 raeburn 1083: }
1.6 raeburn 1084: return $datatable;
1085: }
1086:
1087: sub login_choices {
1088: my %choices =
1089: &Apache::lonlocal::texthash (
1.116 bisitz 1090: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1091: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1092: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1093: disallowlogin => "Login page requests redirected",
1094: hostid => "Server",
1.128 raeburn 1095: server => "Redirect to:",
1096: serverpath => "Path",
1097: custompath => "Custom",
1098: exempt => "Exempt IP(s)",
1.110 raeburn 1099: directlogin => "No redirect",
1100: newuser => "Link to create a user account",
1101: img => "Header",
1102: logo => "Main Logo",
1103: domlogo => "Domain Logo",
1104: login => "Log-in Header",
1105: textcol => "Text color",
1106: bgcol => "Box color",
1107: bgs => "Background colors",
1108: links => "Link colors",
1109: font => "Font color",
1110: pgbg => "Header",
1111: mainbg => "Page",
1112: sidebg => "Login box",
1113: link => "Link",
1114: alink => "Active link",
1115: vlink => "Visited link",
1.6 raeburn 1116: );
1117: return %choices;
1118: }
1119:
1120: sub print_rolecolors {
1.30 raeburn 1121: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1122: my %choices = &color_font_choices();
1123: my @bgs = ('pgbg','tabbg','sidebg');
1124: my @links = ('link','alink','vlink');
1125: my @images = ('img');
1126: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1127: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1128: my %defaultdesign = %Apache::loncommon::defaultdesign;
1129: my (%is_custom,%designs);
1.160.6.22 raeburn 1130: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1131: if (ref($settings) eq 'HASH') {
1132: if (ref($settings->{$role}) eq 'HASH') {
1133: if ($settings->{$role}->{'img'} ne '') {
1134: $designs{'img'} = $settings->{$role}->{'img'};
1135: $is_custom{'img'} = 1;
1136: }
1137: if ($settings->{$role}->{'font'} ne '') {
1138: $designs{'font'} = $settings->{$role}->{'font'};
1139: $is_custom{'font'} = 1;
1140: }
1.97 tempelho 1141: if ($settings->{$role}->{'fontmenu'} ne '') {
1142: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1143: $is_custom{'fontmenu'} = 1;
1144: }
1.6 raeburn 1145: foreach my $item (@bgs) {
1146: if ($settings->{$role}->{$item} ne '') {
1147: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1148: $is_custom{$item} = 1;
1149: }
1150: }
1151: foreach my $item (@links) {
1152: if ($settings->{$role}->{$item} ne '') {
1153: $designs{'links'}{$item} = $settings->{$role}->{$item};
1154: $is_custom{$item} = 1;
1155: }
1156: }
1157: }
1158: } else {
1159: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1160: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1161: $is_custom{'img'} = 1;
1162: }
1.97 tempelho 1163: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1164: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1165: $is_custom{'fontmenu'} = 1;
1166: }
1.6 raeburn 1167: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1168: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1169: $is_custom{'font'} = 1;
1170: }
1171: foreach my $item (@bgs) {
1172: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1173: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1174: $is_custom{$item} = 1;
1175:
1176: }
1177: }
1178: foreach my $item (@links) {
1179: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1180: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1181: $is_custom{$item} = 1;
1182: }
1183: }
1184: }
1185: my $itemcount = 1;
1.30 raeburn 1186: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1187: $datatable .= '</tr></table></td></tr>';
1188: return $datatable;
1189: }
1190:
1.160.6.22 raeburn 1191: sub role_defaults {
1192: my ($role,$bgs,$links,$images,$logintext) = @_;
1193: my %defaults;
1194: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1195: return %defaults;
1196: }
1197: my %defaultdesign = %Apache::loncommon::defaultdesign;
1198: if ($role eq 'login') {
1199: %defaults = (
1200: font => $defaultdesign{$role.'.font'},
1201: );
1202: if (ref($logintext) eq 'ARRAY') {
1203: foreach my $item (@{$logintext}) {
1204: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1205: }
1206: }
1207: foreach my $item (@{$images}) {
1208: $defaults{'showlogo'}{$item} = 1;
1209: }
1210: } else {
1211: %defaults = (
1212: img => $defaultdesign{$role.'.img'},
1213: font => $defaultdesign{$role.'.font'},
1214: fontmenu => $defaultdesign{$role.'.fontmenu'},
1215: );
1216: }
1217: foreach my $item (@{$bgs}) {
1218: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1219: }
1220: foreach my $item (@{$links}) {
1221: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1222: }
1223: foreach my $item (@{$images}) {
1224: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1225: }
1226: return %defaults;
1227: }
1228:
1.6 raeburn 1229: sub display_color_options {
1.9 raeburn 1230: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1231: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1232: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1233: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1234: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1235: '<td>'.$choices->{'font'}.'</td>';
1236: if (!$is_custom->{'font'}) {
1.30 raeburn 1237: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1238: } else {
1239: $datatable .= '<td> </td>';
1240: }
1.160.6.9 raeburn 1241: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1242:
1.8 raeburn 1243: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1244: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1245: ' value="'.$current_color.'" /> '.
1246: ' </td></tr>';
1.107 raeburn 1247: unless ($role eq 'login') {
1248: $datatable .= '<tr'.$css_class.'>'.
1249: '<td>'.$choices->{'fontmenu'}.'</td>';
1250: if (!$is_custom->{'fontmenu'}) {
1251: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1252: } else {
1253: $datatable .= '<td> </td>';
1254: }
1.160.6.22 raeburn 1255: $current_color = $designs->{'fontmenu'} ?
1256: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1257: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1258: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1259: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1260: ' value="'.$current_color.'" /> '.
1261: ' </td></tr>';
1.97 tempelho 1262: }
1.9 raeburn 1263: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1264: foreach my $img (@{$images}) {
1.18 albertel 1265: $itemcount ++;
1.6 raeburn 1266: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1267: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1268: '<td>'.$choices->{$img};
1.41 raeburn 1269: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1270: if ($role eq 'login') {
1271: if ($img eq 'login') {
1272: $login_hdr_pick =
1.135 bisitz 1273: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1274: $logincolors =
1275: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1276: $designs,$defaults);
1.70 raeburn 1277: } elsif ($img ne 'domlogo') {
1278: $datatable.= &logo_display_options($img,$defaults,$designs);
1279: }
1280: }
1281: $datatable .= '</td>';
1.6 raeburn 1282: if ($designs->{$img} ne '') {
1283: $imgfile = $designs->{$img};
1.18 albertel 1284: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1285: } else {
1286: $imgfile = $defaults->{$img};
1287: }
1288: if ($imgfile) {
1.9 raeburn 1289: my ($showfile,$fullsize);
1290: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1291: my $urldir = $1;
1292: my $filename = $2;
1293: my @info = &Apache::lonnet::stat_file($designs->{$img});
1294: if (@info) {
1295: my $thumbfile = 'tn-'.$filename;
1296: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1297: if (@thumb) {
1298: $showfile = $urldir.'/'.$thumbfile;
1299: } else {
1300: $showfile = $imgfile;
1301: }
1302: } else {
1303: $showfile = '';
1304: }
1305: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1306: $showfile = $imgfile;
1.6 raeburn 1307: my $imgdir = $1;
1308: my $filename = $2;
1.159 raeburn 1309: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1310: $showfile = "/$imgdir/tn-".$filename;
1311: } else {
1.159 raeburn 1312: my $input = $londocroot.$imgfile;
1313: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1314: if (!-e $output) {
1.9 raeburn 1315: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1316: my ($fullwidth,$fullheight) = &check_dimensions($input);
1317: if ($fullwidth ne '' && $fullheight ne '') {
1318: if ($fullwidth > $width && $fullheight > $height) {
1319: my $size = $width.'x'.$height;
1320: system("convert -sample $size $input $output");
1.159 raeburn 1321: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1322: }
1323: }
1.6 raeburn 1324: }
1325: }
1.16 raeburn 1326: }
1.6 raeburn 1327: if ($showfile) {
1.40 raeburn 1328: if ($showfile =~ m{^/(adm|res)/}) {
1329: if ($showfile =~ m{^/res/}) {
1330: my $local_showfile =
1331: &Apache::lonnet::filelocation('',$showfile);
1332: &Apache::lonnet::repcopy($local_showfile);
1333: }
1334: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1335: }
1336: if ($imgfile) {
1337: if ($imgfile =~ m{^/(adm|res)/}) {
1338: if ($imgfile =~ m{^/res/}) {
1339: my $local_imgfile =
1340: &Apache::lonnet::filelocation('',$imgfile);
1341: &Apache::lonnet::repcopy($local_imgfile);
1342: }
1343: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1344: } else {
1345: $fullsize = $imgfile;
1346: }
1347: }
1.41 raeburn 1348: $datatable .= '<td>';
1349: if ($img eq 'login') {
1.135 bisitz 1350: $datatable .= $login_hdr_pick;
1351: }
1.41 raeburn 1352: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1353: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1354: } else {
1.160.6.22 raeburn 1355: $datatable .= '<td> </td><td class="LC_left_item">'.
1356: &mt('Upload:').'<br />';
1.6 raeburn 1357: }
1358: } else {
1.160.6.22 raeburn 1359: $datatable .= '<td> </td><td class="LC_left_item">'.
1360: &mt('Upload:').'<br />';
1.6 raeburn 1361: }
1.9 raeburn 1362: if ($switchserver) {
1363: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1364: } else {
1.135 bisitz 1365: if ($img ne 'login') { # suppress file selection for Log-in header
1366: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1367: }
1.9 raeburn 1368: }
1369: $datatable .= '</td></tr>';
1.6 raeburn 1370: }
1371: $itemcount ++;
1372: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1373: $datatable .= '<tr'.$css_class.'>'.
1374: '<td>'.$choices->{'bgs'}.'</td>';
1375: my $bgs_def;
1376: foreach my $item (@{$bgs}) {
1377: if (!$is_custom->{$item}) {
1.70 raeburn 1378: $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 1379: }
1380: }
1381: if ($bgs_def) {
1.8 raeburn 1382: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1383: } else {
1384: $datatable .= '<td> </td>';
1385: }
1386: $datatable .= '<td class="LC_right_item">'.
1387: '<table border="0"><tr>';
1.160.6.13 raeburn 1388:
1.6 raeburn 1389: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1390: $datatable .= '<td align="center">'.$choices->{$item};
1391: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1392: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1393: $datatable .= ' ';
1.6 raeburn 1394: }
1.160.6.9 raeburn 1395: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1396: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1397: }
1398: $datatable .= '</tr></table></td></tr>';
1399: $itemcount ++;
1400: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1401: $datatable .= '<tr'.$css_class.'>'.
1402: '<td>'.$choices->{'links'}.'</td>';
1403: my $links_def;
1404: foreach my $item (@{$links}) {
1405: if (!$is_custom->{$item}) {
1.30 raeburn 1406: $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 1407: }
1408: }
1409: if ($links_def) {
1.8 raeburn 1410: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1411: } else {
1412: $datatable .= '<td> </td>';
1413: }
1414: $datatable .= '<td class="LC_right_item">'.
1415: '<table border="0"><tr>';
1416: foreach my $item (@{$links}) {
1.160.6.22 raeburn 1417: my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
1418: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1419: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1420: $datatable.=' ';
1.6 raeburn 1421: }
1.160.6.9 raeburn 1422: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1423: '" /></td>';
1424: }
1.30 raeburn 1425: $$rowtotal += $itemcount;
1.3 raeburn 1426: return $datatable;
1427: }
1428:
1.70 raeburn 1429: sub logo_display_options {
1430: my ($img,$defaults,$designs) = @_;
1431: my $checkedon;
1432: if (ref($defaults) eq 'HASH') {
1433: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1434: if ($defaults->{'showlogo'}{$img}) {
1435: $checkedon = 'checked="checked" ';
1436: }
1437: }
1438: }
1439: if (ref($designs) eq 'HASH') {
1440: if (ref($designs->{'showlogo'}) eq 'HASH') {
1441: if (defined($designs->{'showlogo'}{$img})) {
1442: if ($designs->{'showlogo'}{$img} == 0) {
1443: $checkedon = '';
1444: } elsif ($designs->{'showlogo'}{$img} == 1) {
1445: $checkedon = 'checked="checked" ';
1446: }
1447: }
1448: }
1449: }
1450: return '<br /><label> <input type="checkbox" name="'.
1451: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1452: &mt('show').'</label>'."\n";
1453: }
1454:
1.41 raeburn 1455: sub login_header_options {
1.135 bisitz 1456: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1457: my $output = '';
1.41 raeburn 1458: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1459: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1460: if (!$is_custom->{'textcol'}) {
1461: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1462: ' ';
1463: }
1464: if (!$is_custom->{'bgcol'}) {
1465: $output .= $choices->{'bgcol'}.': '.
1466: '<span id="css_'.$role.'_font" style="background-color: '.
1467: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1468: }
1469: $output .= '<br />';
1470: }
1471: $output .='<br />';
1472: return $output;
1473: }
1474:
1475: sub login_text_colors {
1.160.6.22 raeburn 1476: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1477: my $color_menu = '<table border="0"><tr>';
1478: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 1479: $color_menu .= '<td align="center">'.$choices->{$item};
1480: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1481: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1482: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1483: }
1484: $color_menu .= '</tr></table><br />';
1485: return $color_menu;
1486: }
1487:
1488: sub image_changes {
1489: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1490: my $output;
1.135 bisitz 1491: if ($img eq 'login') {
1492: # suppress image for Log-in header
1493: } elsif (!$is_custom) {
1.70 raeburn 1494: if ($img ne 'domlogo') {
1.41 raeburn 1495: $output .= &mt('Default image:').'<br />';
1496: } else {
1497: $output .= &mt('Default in use:').'<br />';
1498: }
1499: }
1.135 bisitz 1500: if ($img eq 'login') { # suppress image for Log-in header
1501: $output .= '<td>'.$logincolors;
1.41 raeburn 1502: } else {
1.135 bisitz 1503: if ($img_import) {
1504: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1505: }
1506: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1507: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1508: if ($is_custom) {
1509: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1510: '<input type="checkbox" name="'.
1511: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1512: '</label> '.&mt('Replace:').'</span><br />';
1513: } else {
1.160.6.22 raeburn 1514: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1515: }
1.41 raeburn 1516: }
1517: return $output;
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.160.6.20 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.160.6.5 raeburn 1537: } elsif ($context eq 'requestauthor') {
1538: @usertools = ('author');
1539: @options = ('norequest','approval','automatic');
1540: %titles = &authorrequest_titles();
1.86 raeburn 1541: } else {
1.160.6.4 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.160.6.20 raeburn 1547: my ($currdefquota,$currauthorquota);
1.160.6.5 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.160.6.20 raeburn 1552: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1553: } else {
1554: $currdefquota = $settings->{$type};
1555: }
1.160.6.20 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.160.6.5 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.160.6.5 raeburn 1669: unless (($context eq 'requestcourses') ||
1670: ($context eq 'requestauthor')) {
1.86 raeburn 1671: $datatable .=
1.160.6.20 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.160.6.20 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.160.6.5 raeburn 1686: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1687: $defaultquota = '20';
1.160.6.20 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.160.6.20 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.160.6.5 raeburn 1760: } elsif ($context eq 'requestauthor') {
1761: my $curroption;
1762: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 1763: $curroption = $settings->{'default'};
1.160.6.5 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.160.6.5 raeburn 1807: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 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.160.6.20 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.160.6.20 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.160.6.5 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.160.6.8 raeburn 1912: '<input type="radio" name="authorreq__LC_adv"'.
1913: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 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.160.6.5 raeburn 1945: sub print_requestmail {
1946: my ($dom,$action,$settings,$rowtotal) = @_;
1.160.6.25 raeburn 1947: my ($now,$datatable,%currapp);
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.160.6.16 raeburn 1952: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 1953: }
1954: }
1955: }
1.160.6.16 raeburn 1956: my $numinrow = 2;
1.102 raeburn 1957: my $css_class = 'class="LC_odd_row"';
1.160.6.5 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.160.6.16 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.160.6.16 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.160.6.16 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.160.6.16 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.160.6.16 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.160.6.16 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.160.6.23 raeburn 2297: 'requestsmail','updatesmail','idconflictsmail');
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.160.6.23 raeburn 2333: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
2334: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2335: }
2336: my ($titles,$short_titles) = &contact_titles();
2337: my $rownum = 0;
2338: my $css_class;
2339: foreach my $item (@contacts) {
1.69 raeburn 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>';
1.160.6.23 raeburn 2346: $rownum ++;
1.28 raeburn 2347: }
2348: foreach my $type (@mailings) {
1.69 raeburn 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.160.6.23 raeburn 2371: $rownum ++;
1.28 raeburn 2372: }
1.160.6.23 raeburn 2373: my %choices;
2374: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2375: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2376: &mt('LON-CAPA core group - MSU'),600,500));
2377: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2378: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2379: &mt('LON-CAPA core group - MSU'),600,500));
2380: my @toggles = ('reporterrors','reportupdates');
2381: my %defaultchecked = ('reporterrors' => 'on',
2382: 'reportupdates' => 'on');
2383: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2384: \%choices,$rownum);
2385: $datatable .= $reports;
1.30 raeburn 2386: $$rowtotal += $rownum;
1.28 raeburn 2387: return $datatable;
2388: }
2389:
1.118 jms 2390: sub print_helpsettings {
1.160.6.5 raeburn 2391: my ($dom,$confname,$settings,$rowtotal) = @_;
2392: my ($datatable,$itemcount);
2393: $itemcount = 1;
2394: my (%choices,%defaultchecked,@toggles);
2395: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2396: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2397: &mt('LON-CAPA bug tracker'),600,500));
2398: %defaultchecked = ('submitbugs' => 'on');
2399: @toggles = ('submitbugs',);
1.122 jms 2400:
1.160.6.5 raeburn 2401: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2402: \%choices,$itemcount);
2403: return $datatable;
1.121 raeburn 2404: }
2405:
2406: sub radiobutton_prefs {
1.160.6.16 raeburn 2407: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
2408: $additional) = @_;
1.121 raeburn 2409: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2410: (ref($choices) eq 'HASH'));
2411:
2412: my (%checkedon,%checkedoff,$datatable,$css_class);
2413:
2414: foreach my $item (@{$toggles}) {
2415: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2416: $checkedon{$item} = ' checked="checked" ';
2417: $checkedoff{$item} = ' ';
1.121 raeburn 2418: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2419: $checkedoff{$item} = ' checked="checked" ';
2420: $checkedon{$item} = ' ';
2421: }
2422: }
2423: if (ref($settings) eq 'HASH') {
1.121 raeburn 2424: foreach my $item (@{$toggles}) {
1.118 jms 2425: if ($settings->{$item} eq '1') {
2426: $checkedon{$item} = ' checked="checked" ';
2427: $checkedoff{$item} = ' ';
2428: } elsif ($settings->{$item} eq '0') {
2429: $checkedoff{$item} = ' checked="checked" ';
2430: $checkedon{$item} = ' ';
2431: }
2432: }
1.121 raeburn 2433: }
1.160.6.16 raeburn 2434: if ($onclick) {
2435: $onclick = ' onclick="'.$onclick.'"';
2436: }
1.121 raeburn 2437: foreach my $item (@{$toggles}) {
1.118 jms 2438: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2439: $datatable .=
1.160.6.16 raeburn 2440: '<tr'.$css_class.'><td valign="top">'.
2441: '<span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2442: '</span></td>'.
2443: '<td class="LC_right_item"><span class="LC_nobreak">'.
2444: '<label><input type="radio" name="'.
1.160.6.16 raeburn 2445: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2446: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 2447: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2448: '</span>'.$additional.
2449: '</td>'.
1.118 jms 2450: '</tr>';
2451: $itemcount ++;
1.121 raeburn 2452: }
2453: return ($datatable,$itemcount);
2454: }
2455:
2456: sub print_coursedefaults {
1.139 raeburn 2457: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2458: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2459: my $itemcount = 1;
1.160.6.16 raeburn 2460: my %choices = &Apache::lonlocal::texthash (
2461: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.160.6.21 raeburn 2462: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 2463: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2464: coursecredits => 'Credits can be specified for courses',
2465: );
1.160.6.21 raeburn 2466: my %staticdefaults = (
2467: anonsurvey_threshold => 10,
2468: uploadquota => 500,
2469: );
1.139 raeburn 2470: if ($position eq 'top') {
2471: %defaultchecked = ('canuse_pdfforms' => 'off');
1.160.6.16 raeburn 2472: @toggles = ('canuse_pdfforms');
1.139 raeburn 2473: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2474: \%choices,$itemcount);
1.139 raeburn 2475: } else {
2476: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.21 raeburn 2477: my ($currdefresponder,$def_official_credits,$def_unofficial_credits,%curruploadquota);
1.160.6.16 raeburn 2478: my $currusecredits = 0;
1.160.6.21 raeburn 2479: my @types = ('official','unofficial','community');
1.139 raeburn 2480: if (ref($settings) eq 'HASH') {
2481: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 2482: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2483: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2484: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2485: }
2486: }
1.160.6.16 raeburn 2487: if (ref($settings->{'coursecredits'}) eq 'HASH') {
2488: $def_official_credits = $settings->{'coursecredits'}->{'official'};
2489: $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
2490: if (($def_official_credits ne '') || ($def_unofficial_credits ne '')) {
2491: $currusecredits = 1;
2492: }
2493: }
1.139 raeburn 2494: }
2495: if (!$currdefresponder) {
1.160.6.21 raeburn 2496: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 2497: } elsif ($currdefresponder < 1) {
2498: $currdefresponder = 1;
2499: }
1.160.6.21 raeburn 2500: foreach my $type (@types) {
2501: if ($curruploadquota{$type} eq '') {
2502: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
2503: }
2504: }
1.139 raeburn 2505: $datatable .=
1.160.6.16 raeburn 2506: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2507: $choices{'anonsurvey_threshold'}.
1.139 raeburn 2508: '</span></td>'.
2509: '<td class="LC_right_item"><span class="LC_nobreak">'.
2510: '<input type="text" name="anonsurvey_threshold"'.
2511: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.21 raeburn 2512: '</td></tr>'."\n".
2513: '<tr><td><span class="LC_nobreak">'.
2514: $choices{'uploadquota'}.
2515: '</span></td>'.
2516: '<td align="right" class="LC_right_item">'.
2517: '<table><tr>';
2518: foreach my $type (@types) {
2519: $datatable .= '<td align="center">'.&mt($type).'<br />'.
2520: '<input type="text" name="uploadquota_'.$type.'"'.
2521: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
2522: }
2523: $datatable .= '</tr></table></td></tr>'."\n";
2524: $itemcount += 2;
1.160.6.16 raeburn 2525: my $onclick = 'toggleCredits(this.form);';
2526: my $display = 'none';
2527: if ($currusecredits) {
2528: $display = 'block';
2529: }
2530: my $additional = '<div id="credits" style="display: '.$display.'">'.
2531: '<span class="LC_nobreak">'.
2532: &mt('Default credits for official courses [_1]',
2533: '<input type="text" name="official_credits" value="'.
2534: $def_official_credits.'" size="3" />').
2535: '</span><br />'.
2536: '<span class="LC_nobreak">'.
2537: &mt('Default credits for unofficial courses [_1]',
2538: '<input type="text" name="unofficial_credits" value="'.
2539: $def_unofficial_credits.'" size="3" />').
2540: '</span></div>'."\n";
2541: %defaultchecked = ('coursecredits' => 'off');
2542: @toggles = ('coursecredits');
2543: my $current = {
2544: 'coursecredits' => $currusecredits,
2545: };
2546: (my $table,$itemcount) =
2547: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
2548: \%choices,$itemcount,$onclick,$additional);
2549: $datatable .= $table;
1.139 raeburn 2550: }
1.160.6.16 raeburn 2551: $$rowtotal += $itemcount;
1.121 raeburn 2552: return $datatable;
1.118 jms 2553: }
2554:
1.137 raeburn 2555: sub print_usersessions {
2556: my ($position,$dom,$settings,$rowtotal) = @_;
2557: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2558: my (%by_ip,%by_location,@intdoms);
2559: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 2560:
2561: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 2562: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 2563: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 2564: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 2565: my $itemcount = 1;
2566: if ($position eq 'top') {
1.152 raeburn 2567: if (keys(%serverhomes) > 1) {
1.145 raeburn 2568: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 2569: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 2570: } else {
1.140 raeburn 2571: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2572: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 2573: }
1.137 raeburn 2574: } else {
1.145 raeburn 2575: if (keys(%by_location) == 0) {
2576: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2577: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 2578: } else {
2579: my %lt = &usersession_titles();
2580: my $numinrow = 5;
2581: my $prefix;
2582: my @types;
2583: if ($position eq 'bottom') {
2584: $prefix = 'remote';
2585: @types = ('version','excludedomain','includedomain');
2586: } else {
2587: $prefix = 'hosted';
2588: @types = ('excludedomain','includedomain');
2589: }
2590: my (%current,%checkedon,%checkedoff);
2591: my @lcversions = &Apache::lonnet::all_loncaparevs();
2592: my @locations = sort(keys(%by_location));
2593: foreach my $type (@types) {
2594: $checkedon{$type} = '';
2595: $checkedoff{$type} = ' checked="checked"';
2596: }
2597: if (ref($settings) eq 'HASH') {
2598: if (ref($settings->{$prefix}) eq 'HASH') {
2599: foreach my $key (keys(%{$settings->{$prefix}})) {
2600: $current{$key} = $settings->{$prefix}{$key};
2601: if ($key eq 'version') {
2602: if ($current{$key} ne '') {
2603: $checkedon{$key} = ' checked="checked"';
2604: $checkedoff{$key} = '';
2605: }
2606: } elsif (ref($current{$key}) eq 'ARRAY') {
2607: $checkedon{$key} = ' checked="checked"';
2608: $checkedoff{$key} = '';
2609: }
1.137 raeburn 2610: }
2611: }
2612: }
1.145 raeburn 2613: foreach my $type (@types) {
2614: next if ($type ne 'version' && !@locations);
2615: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2616: $datatable .= '<tr'.$css_class.'>
2617: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2618: <span class="LC_nobreak">
2619: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2620: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2621: if ($type eq 'version') {
2622: my $selector = '<select name="'.$prefix.'_version">';
2623: foreach my $version (@lcversions) {
2624: my $selected = '';
2625: if ($current{'version'} eq $version) {
2626: $selected = ' selected="selected"';
2627: }
2628: $selector .= ' <option value="'.$version.'"'.
2629: $selected.'>'.$version.'</option>';
2630: }
2631: $selector .= '</select> ';
2632: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2633: } else {
2634: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2635: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2636: ' />'.(' 'x2).
2637: '<input type="button" value="'.&mt('uncheck all').'" '.
2638: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2639: "\n".
2640: '</div><div><table>';
2641: my $rem;
2642: for (my $i=0; $i<@locations; $i++) {
2643: my ($showloc,$value,$checkedtype);
2644: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2645: my $ip = $by_location{$locations[$i]}->[0];
2646: if (ref($by_ip{$ip}) eq 'ARRAY') {
2647: $value = join(':',@{$by_ip{$ip}});
2648: $showloc = join(', ',@{$by_ip{$ip}});
2649: if (ref($current{$type}) eq 'ARRAY') {
2650: foreach my $loc (@{$by_ip{$ip}}) {
2651: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2652: $checkedtype = ' checked="checked"';
2653: last;
2654: }
2655: }
1.138 raeburn 2656: }
2657: }
2658: }
1.145 raeburn 2659: $rem = $i%($numinrow);
2660: if ($rem == 0) {
2661: if ($i > 0) {
2662: $datatable .= '</tr>';
2663: }
2664: $datatable .= '<tr>';
2665: }
2666: $datatable .= '<td class="LC_left_item">'.
2667: '<span class="LC_nobreak"><label>'.
2668: '<input type="checkbox" name="'.$prefix.'_'.$type.
2669: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2670: '</label></span></td>';
1.137 raeburn 2671: }
1.145 raeburn 2672: $rem = @locations%($numinrow);
2673: my $colsleft = $numinrow - $rem;
2674: if ($colsleft > 1 ) {
2675: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2676: ' </td>';
2677: } elsif ($colsleft == 1) {
2678: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 2679: }
1.145 raeburn 2680: $datatable .= '</tr></table>';
1.137 raeburn 2681: }
1.145 raeburn 2682: $datatable .= '</td></tr>';
2683: $itemcount ++;
1.137 raeburn 2684: }
2685: }
2686: }
2687: $$rowtotal += $itemcount;
2688: return $datatable;
2689: }
2690:
1.138 raeburn 2691: sub build_location_hashes {
2692: my ($intdoms,$by_ip,$by_location) = @_;
2693: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2694: (ref($by_location) eq 'HASH'));
2695: my %iphost = &Apache::lonnet::get_iphost();
2696: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2697: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2698: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2699: foreach my $id (@{$iphost{$primary_ip}}) {
2700: my $intdom = &Apache::lonnet::internet_dom($id);
2701: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2702: push(@{$intdoms},$intdom);
2703: }
2704: }
2705: }
2706: foreach my $ip (keys(%iphost)) {
2707: if (ref($iphost{$ip}) eq 'ARRAY') {
2708: foreach my $id (@{$iphost{$ip}}) {
2709: my $location = &Apache::lonnet::internet_dom($id);
2710: if ($location) {
2711: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2712: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2713: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2714: push(@{$by_ip->{$ip}},$location);
2715: }
2716: } else {
2717: $by_ip->{$ip} = [$location];
2718: }
2719: }
2720: }
2721: }
2722: }
2723: foreach my $ip (sort(keys(%{$by_ip}))) {
2724: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2725: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2726: my $first = $by_ip->{$ip}->[0];
2727: if (ref($by_location->{$first}) eq 'ARRAY') {
2728: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2729: push(@{$by_location->{$first}},$ip);
2730: }
2731: } else {
2732: $by_location->{$first} = [$ip];
2733: }
2734: }
2735: }
2736: return;
2737: }
2738:
1.145 raeburn 2739: sub current_offloads_to {
2740: my ($dom,$settings,$servers) = @_;
2741: my (%spareid,%otherdomconfigs);
1.152 raeburn 2742: if (ref($servers) eq 'HASH') {
1.145 raeburn 2743: foreach my $lonhost (sort(keys(%{$servers}))) {
2744: my $gotspares;
1.152 raeburn 2745: if (ref($settings) eq 'HASH') {
2746: if (ref($settings->{'spares'}) eq 'HASH') {
2747: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
2748: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
2749: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
2750: $gotspares = 1;
2751: }
1.145 raeburn 2752: }
2753: }
2754: unless ($gotspares) {
2755: my $gotspares;
2756: my $serverhomeID =
2757: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
2758: my $serverhomedom =
2759: &Apache::lonnet::host_domain($serverhomeID);
2760: if ($serverhomedom ne $dom) {
2761: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
2762: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2763: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2764: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2765: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2766: $gotspares = 1;
2767: }
2768: }
2769: } else {
2770: $otherdomconfigs{$serverhomedom} =
2771: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
2772: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
2773: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2774: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2775: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
2776: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2777: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2778: $gotspares = 1;
2779: }
2780: }
2781: }
2782: }
2783: }
2784: }
2785: }
2786: unless ($gotspares) {
2787: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
2788: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2789: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2790: } else {
2791: my $server_hostname = &Apache::lonnet::hostname($lonhost);
2792: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
2793: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
2794: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2795: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2796: } else {
1.150 raeburn 2797: my %what = (
2798: spareid => 1,
2799: );
2800: my ($result,$returnhash) =
2801: &Apache::lonnet::get_remote_globals($lonhost,\%what);
2802: if ($result eq 'ok') {
2803: if (ref($returnhash) eq 'HASH') {
2804: if (ref($returnhash->{'spareid'}) eq 'HASH') {
2805: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
2806: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
2807: }
2808: }
1.145 raeburn 2809: }
2810: }
2811: }
2812: }
2813: }
2814: }
2815: return %spareid;
2816: }
2817:
2818: sub spares_row {
1.152 raeburn 2819: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 2820: my $css_class;
2821: my $numinrow = 4;
2822: my $itemcount = 1;
2823: my $datatable;
1.152 raeburn 2824: my %typetitles = &sparestype_titles();
2825: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 2826: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 2827: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
2828: my ($othercontrol,$serverdom);
2829: if ($serverhome ne $server) {
2830: $serverdom = &Apache::lonnet::host_domain($serverhome);
2831: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2832: } else {
2833: $serverdom = &Apache::lonnet::host_domain($server);
2834: if ($serverdom ne $dom) {
2835: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2836: }
2837: }
2838: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 2839: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2840: $datatable .= '<tr'.$css_class.'>
2841: <td rowspan="2">
1.160.6.13 raeburn 2842: <span class="LC_nobreak">'.
2843: &mt('[_1] when busy, offloads to:'
2844: ,'<b>'.$server.'</b>').
2845: "\n";
1.145 raeburn 2846: my (%current,%canselect);
1.152 raeburn 2847: my @choices =
2848: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
2849: foreach my $type ('primary','default') {
2850: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 2851: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
2852: my @spares = @{$spareid->{$server}{$type}};
2853: if (@spares > 0) {
1.152 raeburn 2854: if ($othercontrol) {
2855: $current{$type} = join(', ',@spares);
2856: } else {
2857: $current{$type} .= '<table>';
2858: my $numspares = scalar(@spares);
2859: for (my $i=0; $i<@spares; $i++) {
2860: my $rem = $i%($numinrow);
2861: if ($rem == 0) {
2862: if ($i > 0) {
2863: $current{$type} .= '</tr>';
2864: }
2865: $current{$type} .= '<tr>';
1.145 raeburn 2866: }
1.152 raeburn 2867: $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'".');" /> '.
2868: $spareid->{$server}{$type}[$i].
2869: '</label></td>'."\n";
2870: }
2871: my $rem = @spares%($numinrow);
2872: my $colsleft = $numinrow - $rem;
2873: if ($colsleft > 1 ) {
2874: $current{$type} .= '<td colspan="'.$colsleft.
2875: '" class="LC_left_item">'.
2876: ' </td>';
2877: } elsif ($colsleft == 1) {
2878: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 2879: }
1.152 raeburn 2880: $current{$type} .= '</tr></table>';
1.150 raeburn 2881: }
1.145 raeburn 2882: }
2883: }
2884: if ($current{$type} eq '') {
2885: $current{$type} = &mt('None specified');
2886: }
1.152 raeburn 2887: if ($othercontrol) {
2888: if ($type eq 'primary') {
2889: $canselect{$type} = $othercontrol;
2890: }
2891: } else {
2892: $canselect{$type} =
2893: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
2894: '<select name="newspare_'.$type.'_'.$server.'" '.
2895: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
2896: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
2897: if (@choices > 0) {
2898: foreach my $lonhost (@choices) {
2899: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
2900: }
2901: }
2902: $canselect{$type} .= '</select>'."\n";
2903: }
2904: } else {
2905: $current{$type} = &mt('Could not be determined');
2906: if ($type eq 'primary') {
2907: $canselect{$type} = $othercontrol;
2908: }
1.145 raeburn 2909: }
1.152 raeburn 2910: if ($type eq 'default') {
2911: $datatable .= '<tr'.$css_class.'>';
2912: }
2913: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
2914: '<td>'.$current{$type}.'</td>'."\n".
2915: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 2916: }
2917: $itemcount ++;
2918: }
2919: }
2920: $$rowtotal += $itemcount;
2921: return $datatable;
2922: }
2923:
1.152 raeburn 2924: sub possible_newspares {
2925: my ($server,$currspares,$serverhomes,$altids) = @_;
2926: my $serverhostname = &Apache::lonnet::hostname($server);
2927: my %excluded;
2928: if ($serverhostname ne '') {
2929: %excluded = (
2930: $serverhostname => 1,
2931: );
2932: }
2933: if (ref($currspares) eq 'HASH') {
2934: foreach my $type (keys(%{$currspares})) {
2935: if (ref($currspares->{$type}) eq 'ARRAY') {
2936: if (@{$currspares->{$type}} > 0) {
2937: foreach my $curr (@{$currspares->{$type}}) {
2938: my $hostname = &Apache::lonnet::hostname($curr);
2939: $excluded{$hostname} = 1;
2940: }
2941: }
2942: }
2943: }
2944: }
2945: my @choices;
2946: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
2947: if (keys(%{$serverhomes}) > 1) {
2948: foreach my $name (sort(keys(%{$serverhomes}))) {
2949: unless ($excluded{$name}) {
2950: if (exists($altids->{$serverhomes->{$name}})) {
2951: push(@choices,$altids->{$serverhomes->{$name}});
2952: } else {
2953: push(@choices,$serverhomes->{$name});
1.145 raeburn 2954: }
2955: }
2956: }
2957: }
2958: }
1.152 raeburn 2959: return sort(@choices);
1.145 raeburn 2960: }
2961:
1.150 raeburn 2962: sub print_loadbalancing {
2963: my ($dom,$settings,$rowtotal) = @_;
2964: my $primary_id = &Apache::lonnet::domain($dom,'primary');
2965: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2966: my $numinrow = 1;
2967: my $datatable;
2968: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7 raeburn 2969: my (%currbalancer,%currtargets,%currrules,%existing);
2970: if (ref($settings) eq 'HASH') {
2971: %existing = %{$settings};
2972: }
2973: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
2974: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
2975: \%currtargets,\%currrules);
1.150 raeburn 2976: } else {
2977: return;
2978: }
2979: my ($othertitle,$usertypes,$types) =
2980: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 2981: my $rownum = 8;
1.150 raeburn 2982: if (ref($types) eq 'ARRAY') {
2983: $rownum += scalar(@{$types});
2984: }
1.160.6.7 raeburn 2985: my @css_class = ('LC_odd_row','LC_even_row');
2986: my $balnum = 0;
2987: my $islast;
2988: my (@toshow,$disabledtext);
2989: if (keys(%currbalancer) > 0) {
2990: @toshow = sort(keys(%currbalancer));
2991: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
2992: push(@toshow,'');
2993: }
2994: } else {
2995: @toshow = ('');
2996: $disabledtext = &mt('No existing load balancer');
2997: }
2998: foreach my $lonhost (@toshow) {
2999: if ($balnum == scalar(@toshow)-1) {
3000: $islast = 1;
3001: } else {
3002: $islast = 0;
3003: }
3004: my $cssidx = $balnum%2;
3005: my $targets_div_style = 'display: none';
3006: my $disabled_div_style = 'display: block';
3007: my $homedom_div_style = 'display: none';
3008: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3009: '<td rowspan="'.$rownum.'" valign="top">'.
3010: '<p>';
3011: if ($lonhost eq '') {
3012: $datatable .= '<span class="LC_nobreak">';
3013: if (keys(%currbalancer) > 0) {
3014: $datatable .= &mt('Add balancer:');
3015: } else {
3016: $datatable .= &mt('Enable balancer:');
3017: }
3018: $datatable .= ' '.
3019: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3020: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3021: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3022: '<option value="" selected="selected">'.&mt('None').
3023: '</option>'."\n";
3024: foreach my $server (sort(keys(%servers))) {
3025: next if ($currbalancer{$server});
3026: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3027: }
3028: $datatable .=
3029: '</select>'."\n".
3030: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3031: } else {
3032: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3033: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3034: &mt('Stop balancing').'</label>'.
3035: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3036: $targets_div_style = 'display: block';
3037: $disabled_div_style = 'display: none';
3038: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3039: $homedom_div_style = 'display: block';
3040: }
3041: }
3042: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3043: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3044: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3045: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3046: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3047: my @sparestypes = ('primary','default');
3048: my %typetitles = &sparestype_titles();
3049: foreach my $sparetype (@sparestypes) {
3050: my $targettable;
3051: for (my $i=0; $i<$numspares; $i++) {
3052: my $checked;
3053: if (ref($currtargets{$lonhost}) eq 'HASH') {
3054: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3055: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3056: $checked = ' checked="checked"';
3057: }
3058: }
3059: }
3060: my ($chkboxval,$disabled);
3061: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3062: $chkboxval = $spares[$i];
3063: }
3064: if (exists($currbalancer{$spares[$i]})) {
3065: $disabled = ' disabled="disabled"';
3066: }
3067: $targettable .=
3068: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3069: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3070: '</span></label></td>';
3071: my $rem = $i%($numinrow);
3072: if ($rem == 0) {
3073: if (($i > 0) && ($i < $numspares-1)) {
3074: $targettable .= '</tr>';
3075: }
3076: if ($i < $numspares-1) {
3077: $targettable .= '<tr>';
1.150 raeburn 3078: }
3079: }
3080: }
1.160.6.7 raeburn 3081: if ($targettable ne '') {
3082: my $rem = $numspares%($numinrow);
3083: my $colsleft = $numinrow - $rem;
3084: if ($colsleft > 1 ) {
3085: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3086: ' </td>';
3087: } elsif ($colsleft == 1) {
3088: $targettable .= '<td class="LC_left_item"> </td>';
3089: }
3090: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3091: '<table><tr>'.$targettable.'</tr></table><br />';
3092: }
3093: }
3094: $datatable .= '</div></td></tr>'.
3095: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3096: $othertitle,$usertypes,$types,\%servers,
3097: \%currbalancer,$lonhost,
3098: $targets_div_style,$homedom_div_style,
3099: $css_class[$cssidx],$balnum,$islast);
3100: $$rowtotal += $rownum;
3101: $balnum ++;
3102: }
3103: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3104: return $datatable;
3105: }
3106:
3107: sub get_loadbalancers_config {
3108: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3109: return unless ((ref($servers) eq 'HASH') &&
3110: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3111: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3112: if (keys(%{$existing}) > 0) {
3113: my $oldlonhost;
3114: foreach my $key (sort(keys(%{$existing}))) {
3115: if ($key eq 'lonhost') {
3116: $oldlonhost = $existing->{'lonhost'};
3117: $currbalancer->{$oldlonhost} = 1;
3118: } elsif ($key eq 'targets') {
3119: if ($oldlonhost) {
3120: $currtargets->{$oldlonhost} = $existing->{'targets'};
3121: }
3122: } elsif ($key eq 'rules') {
3123: if ($oldlonhost) {
3124: $currrules->{$oldlonhost} = $existing->{'rules'};
3125: }
3126: } elsif (ref($existing->{$key}) eq 'HASH') {
3127: $currbalancer->{$key} = 1;
3128: $currtargets->{$key} = $existing->{$key}{'targets'};
3129: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3130: }
3131: }
1.160.6.7 raeburn 3132: } else {
3133: my ($balancerref,$targetsref) =
3134: &Apache::lonnet::get_lonbalancer_config($servers);
3135: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3136: foreach my $server (sort(keys(%{$balancerref}))) {
3137: $currbalancer->{$server} = 1;
3138: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3139: }
3140: }
3141: }
1.160.6.7 raeburn 3142: return;
1.150 raeburn 3143: }
3144:
3145: sub loadbalancing_rules {
3146: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 3147: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3148: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3149: my $output;
1.160.6.7 raeburn 3150: my $num = 0;
3151: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3152: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3153: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3154: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 3155: $num ++;
1.150 raeburn 3156: my $current;
3157: if (ref($currrules) eq 'HASH') {
3158: $current = $currrules->{$type};
3159: }
1.160.6.26 raeburn 3160: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.160.6.7 raeburn 3161: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3162: $current = '';
3163: }
3164: }
3165: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 3166: $servers,$currbalancer,$lonhost,$dom,
3167: $targets_div_style,$homedom_div_style,
3168: $css_class,$balnum,$num,$islast);
1.150 raeburn 3169: }
3170: }
3171: return $output;
3172: }
3173:
3174: sub loadbalancing_titles {
3175: my ($dom,$intdom,$usertypes,$types) = @_;
3176: my %othertypes = (
3177: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3178: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3179: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3180: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 3181: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
3182: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 3183: );
1.160.6.26 raeburn 3184: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 3185: if (ref($types) eq 'ARRAY') {
3186: unshift(@alltypes,@{$types},'default');
3187: }
3188: my %titles;
3189: foreach my $type (@alltypes) {
3190: if ($type =~ /^_LC_/) {
3191: $titles{$type} = $othertypes{$type};
3192: } elsif ($type eq 'default') {
3193: $titles{$type} = &mt('All users from [_1]',$dom);
3194: if (ref($types) eq 'ARRAY') {
3195: if (@{$types} > 0) {
3196: $titles{$type} = &mt('Other users from [_1]',$dom);
3197: }
3198: }
3199: } elsif (ref($usertypes) eq 'HASH') {
3200: $titles{$type} = $usertypes->{$type};
3201: }
3202: }
3203: return (\@alltypes,\%othertypes,\%titles);
3204: }
3205:
3206: sub loadbalance_rule_row {
1.160.6.7 raeburn 3207: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3208: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 3209: my @rulenames;
1.150 raeburn 3210: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 3211: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
3212: @rulenames = ('balancer','offloadedto');
1.150 raeburn 3213: } else {
1.160.6.26 raeburn 3214: @rulenames = ('default','homeserver');
3215: if ($type eq '_LC_external') {
3216: push(@rulenames,'externalbalancer');
3217: } else {
3218: push(@rulenames,'specific');
3219: }
3220: push(@rulenames,'none');
1.150 raeburn 3221: }
3222: my $style = $targets_div_style;
1.160.6.26 raeburn 3223: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.150 raeburn 3224: $style = $homedom_div_style;
3225: }
1.160.6.7 raeburn 3226: my $space;
3227: if ($islast && $num == 1) {
3228: $space = '<div display="inline-block"> </div>';
3229: }
3230: my $output =
3231: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3232: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3233: '<td valaign="top">'.$space.
3234: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3235: for (my $i=0; $i<@rulenames; $i++) {
3236: my $rule = $rulenames[$i];
3237: my ($checked,$extra);
3238: if ($rulenames[$i] eq 'default') {
3239: $rule = '';
3240: }
3241: if ($rulenames[$i] eq 'specific') {
3242: if (ref($servers) eq 'HASH') {
3243: my $default;
3244: if (($current ne '') && (exists($servers->{$current}))) {
3245: $checked = ' checked="checked"';
3246: }
3247: unless ($checked) {
3248: $default = ' selected="selected"';
3249: }
1.160.6.7 raeburn 3250: $extra =
3251: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3252: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3253: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3254: '<option value=""'.$default.'></option>'."\n";
3255: foreach my $server (sort(keys(%{$servers}))) {
3256: if (ref($currbalancer) eq 'HASH') {
3257: next if (exists($currbalancer->{$server}));
3258: }
1.150 raeburn 3259: my $selected;
1.160.6.7 raeburn 3260: if ($server eq $current) {
1.150 raeburn 3261: $selected = ' selected="selected"';
3262: }
1.160.6.7 raeburn 3263: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3264: }
3265: $extra .= '</select>';
3266: }
3267: } elsif ($rule eq $current) {
3268: $checked = ' checked="checked"';
3269: }
3270: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 3271: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3272: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3273: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3274: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3275: '</label>'.$extra.'</span><br />'."\n";
3276: }
3277: $output .= '</div></td></tr>'."\n";
3278: return $output;
3279: }
3280:
3281: sub offloadtype_text {
3282: my %ruletitles = &Apache::lonlocal::texthash (
3283: 'default' => 'Offloads to default destinations',
3284: 'homeserver' => "Offloads to user's home server",
3285: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3286: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 3287: 'none' => 'No offload',
1.160.6.26 raeburn 3288: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
3289: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.150 raeburn 3290: );
3291: return %ruletitles;
3292: }
3293:
3294: sub sparestype_titles {
3295: my %typestitles = &Apache::lonlocal::texthash (
3296: 'primary' => 'primary',
3297: 'default' => 'default',
3298: );
3299: return %typestitles;
3300: }
3301:
1.28 raeburn 3302: sub contact_titles {
3303: my %titles = &Apache::lonlocal::texthash (
3304: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3305: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3306: 'errormail' => 'Error reports to be e-mailed to',
3307: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3308: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3309: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3310: 'requestsmail' => 'E-mail from course requests requiring approval',
1.160.6.15 raeburn 3311: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 3312: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 3313: );
3314: my %short_titles = &Apache::lonlocal::texthash (
3315: adminemail => 'Admin E-mail address',
3316: supportemail => 'Support E-mail',
3317: );
3318: return (\%titles,\%short_titles);
3319: }
3320:
1.72 raeburn 3321: sub tool_titles {
3322: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 3323: aboutme => 'Personal web page',
1.86 raeburn 3324: blog => 'Blog',
1.160.6.4 raeburn 3325: webdav => 'WebDAV',
1.86 raeburn 3326: portfolio => 'Portfolio',
1.88 bisitz 3327: official => 'Official courses (with institutional codes)',
3328: unofficial => 'Unofficial courses',
1.98 raeburn 3329: community => 'Communities',
1.86 raeburn 3330: );
1.72 raeburn 3331: return %titles;
3332: }
3333:
1.101 raeburn 3334: sub courserequest_titles {
3335: my %titles = &Apache::lonlocal::texthash (
3336: official => 'Official',
3337: unofficial => 'Unofficial',
3338: community => 'Communities',
3339: norequest => 'Not allowed',
1.104 raeburn 3340: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3341: validate => 'With validation',
3342: autolimit => 'Numerical limit',
1.103 raeburn 3343: unlimited => '(blank for unlimited)',
1.101 raeburn 3344: );
3345: return %titles;
3346: }
3347:
1.160.6.5 raeburn 3348: sub authorrequest_titles {
3349: my %titles = &Apache::lonlocal::texthash (
3350: norequest => 'Not allowed',
3351: approval => 'Approval by Dom. Coord.',
3352: automatic => 'Automatic approval',
3353: );
3354: return %titles;
3355: }
3356:
1.101 raeburn 3357: sub courserequest_conditions {
3358: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3359: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 3360: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 3361: );
3362: return %conditions;
3363: }
3364:
3365:
1.27 raeburn 3366: sub print_usercreation {
1.30 raeburn 3367: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3368: my $numinrow = 4;
1.28 raeburn 3369: my $datatable;
3370: if ($position eq 'top') {
1.30 raeburn 3371: $$rowtotal ++;
1.34 raeburn 3372: my $rowcount = 0;
1.32 raeburn 3373: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3374: if (ref($rules) eq 'HASH') {
3375: if (keys(%{$rules}) > 0) {
1.32 raeburn 3376: $datatable .= &user_formats_row('username',$settings,$rules,
3377: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3378: $$rowtotal ++;
1.32 raeburn 3379: $rowcount ++;
3380: }
3381: }
3382: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3383: if (ref($idrules) eq 'HASH') {
3384: if (keys(%{$idrules}) > 0) {
3385: $datatable .= &user_formats_row('id',$settings,$idrules,
3386: $idruleorder,$numinrow,$rowcount);
3387: $$rowtotal ++;
3388: $rowcount ++;
1.28 raeburn 3389: }
3390: }
1.43 raeburn 3391: my ($emailrules,$emailruleorder) =
3392: &Apache::lonnet::inst_userrules($dom,'email');
3393: if (ref($emailrules) eq 'HASH') {
3394: if (keys(%{$emailrules}) > 0) {
3395: $datatable .= &user_formats_row('email',$settings,$emailrules,
3396: $emailruleorder,$numinrow,$rowcount);
3397: $$rowtotal ++;
3398: $rowcount ++;
3399: }
3400: }
1.39 raeburn 3401: if ($rowcount == 0) {
3402: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3403: $$rowtotal ++;
3404: $rowcount ++;
3405: }
1.34 raeburn 3406: } elsif ($position eq 'middle') {
1.100 raeburn 3407: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 3408: my ($rules,$ruleorder) =
3409: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3410: my %lt = &usercreation_types();
3411: my %checked;
1.50 raeburn 3412: my @selfcreate;
1.34 raeburn 3413: if (ref($settings) eq 'HASH') {
3414: if (ref($settings->{'cancreate'}) eq 'HASH') {
3415: foreach my $item (@creators) {
3416: $checked{$item} = $settings->{'cancreate'}{$item};
3417: }
1.50 raeburn 3418: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3419: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3420: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3421: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3422: @selfcreate = ('email','login','sso');
3423: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3424: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3425: }
3426: }
1.34 raeburn 3427: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3428: foreach my $item (@creators) {
3429: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3430: $checked{$item} = 'none';
3431: }
3432: }
3433: }
3434: }
3435: my $rownum = 0;
3436: foreach my $item (@creators) {
3437: $rownum ++;
1.50 raeburn 3438: if ($item ne 'selfcreate') {
3439: if ($checked{$item} eq '') {
1.43 raeburn 3440: $checked{$item} = 'any';
3441: }
1.34 raeburn 3442: }
3443: my $css_class;
3444: if ($rownum%2) {
3445: $css_class = '';
3446: } else {
3447: $css_class = ' class="LC_odd_row" ';
3448: }
3449: $datatable .= '<tr'.$css_class.'>'.
3450: '<td><span class="LC_nobreak">'.$lt{$item}.
3451: '</span></td><td align="right">';
1.50 raeburn 3452: my @options;
1.45 raeburn 3453: if ($item eq 'selfcreate') {
1.43 raeburn 3454: push(@options,('email','login','sso'));
3455: } else {
1.50 raeburn 3456: @options = ('any');
1.43 raeburn 3457: if (ref($rules) eq 'HASH') {
3458: if (keys(%{$rules}) > 0) {
3459: push(@options,('official','unofficial'));
3460: }
1.37 raeburn 3461: }
1.50 raeburn 3462: push(@options,'none');
1.37 raeburn 3463: }
3464: foreach my $option (@options) {
1.50 raeburn 3465: my $type = 'radio';
1.34 raeburn 3466: my $check = ' ';
1.50 raeburn 3467: if ($item eq 'selfcreate') {
3468: $type = 'checkbox';
3469: if (grep(/^\Q$option\E$/,@selfcreate)) {
3470: $check = ' checked="checked" ';
3471: }
3472: } else {
3473: if ($checked{$item} eq $option) {
3474: $check = ' checked="checked" ';
3475: }
1.34 raeburn 3476: }
3477: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3478: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3479: $item.'" value="'.$option.'"'.$check.'/> '.
3480: $lt{$option}.'</label> </span>';
3481: }
3482: $datatable .= '</td></tr>';
3483: }
1.93 raeburn 3484: my ($othertitle,$usertypes,$types) =
3485: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.5 raeburn 3486: my $createsettings;
3487: if (ref($settings) eq 'HASH') {
3488: $createsettings = $settings->{cancreate};
3489: }
1.93 raeburn 3490: if (ref($usertypes) eq 'HASH') {
3491: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 3492: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 3493: $dom,$numinrow,$othertitle,
3494: 'statustocreate');
3495: $$rowtotal ++;
1.160.6.5 raeburn 3496: $rownum ++;
1.93 raeburn 3497: }
3498: }
1.160.6.5 raeburn 3499: $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
1.28 raeburn 3500: } else {
3501: my @contexts = ('author','course','domain');
3502: my @authtypes = ('int','krb4','krb5','loc');
3503: my %checked;
3504: if (ref($settings) eq 'HASH') {
3505: if (ref($settings->{'authtypes'}) eq 'HASH') {
3506: foreach my $item (@contexts) {
3507: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3508: foreach my $auth (@authtypes) {
3509: if ($settings->{'authtypes'}{$item}{$auth}) {
3510: $checked{$item}{$auth} = ' checked="checked" ';
3511: }
3512: }
3513: }
3514: }
1.27 raeburn 3515: }
1.35 raeburn 3516: } else {
3517: foreach my $item (@contexts) {
1.36 raeburn 3518: foreach my $auth (@authtypes) {
1.35 raeburn 3519: $checked{$item}{$auth} = ' checked="checked" ';
3520: }
3521: }
1.27 raeburn 3522: }
1.28 raeburn 3523: my %title = &context_names();
3524: my %authname = &authtype_names();
3525: my $rownum = 0;
3526: my $css_class;
3527: foreach my $item (@contexts) {
3528: if ($rownum%2) {
3529: $css_class = '';
3530: } else {
3531: $css_class = ' class="LC_odd_row" ';
3532: }
1.30 raeburn 3533: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3534: '<td>'.$title{$item}.
3535: '</td><td class="LC_left_item">'.
3536: '<span class="LC_nobreak">';
3537: foreach my $auth (@authtypes) {
3538: $datatable .= '<label>'.
3539: '<input type="checkbox" name="'.$item.'_auth" '.
3540: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3541: $authname{$auth}.'</label> ';
3542: }
3543: $datatable .= '</span></td></tr>';
3544: $rownum ++;
1.27 raeburn 3545: }
1.30 raeburn 3546: $$rowtotal += $rownum;
1.27 raeburn 3547: }
3548: return $datatable;
3549: }
3550:
1.160.6.5 raeburn 3551: sub captcha_choice {
3552: my ($context,$settings,$itemcount) = @_;
3553: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
3554: my %lt = &captcha_phrases();
3555: $keyentry = 'hidden';
3556: if ($context eq 'cancreate') {
3557: $rowname = &mt('CAPTCHA validation (e-mail as username)');
3558: } elsif ($context eq 'login') {
3559: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
3560: }
3561: if (ref($settings) eq 'HASH') {
3562: if ($settings->{'captcha'}) {
3563: $checked{$settings->{'captcha'}} = ' checked="checked"';
3564: } else {
3565: $checked{'original'} = ' checked="checked"';
3566: }
3567: if ($settings->{'captcha'} eq 'recaptcha') {
3568: $pubtext = $lt{'pub'};
3569: $privtext = $lt{'priv'};
3570: $keyentry = 'text';
3571: }
3572: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
3573: $currpub = $settings->{'recaptchakeys'}{'public'};
3574: $currpriv = $settings->{'recaptchakeys'}{'private'};
3575: }
3576: } else {
3577: $checked{'original'} = ' checked="checked"';
3578: }
3579: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3580: my $output = '<tr'.$css_class.'>'.
3581: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
3582: '<table><tr><td>'."\n";
3583: foreach my $option ('original','recaptcha','notused') {
3584: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
3585: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
3586: $lt{$option}.'</label></span>';
3587: unless ($option eq 'notused') {
3588: $output .= (' 'x2)."\n";
3589: }
3590: }
3591: #
3592: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
3593: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
3594: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
3595: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
3596: #
3597: $output .= '</td></tr>'."\n".
3598: '<tr><td>'."\n".
3599: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
3600: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
3601: $currpub.'" size="40" /></span><br />'."\n".
3602: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
3603: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
3604: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
3605: '</td></tr>';
3606: return $output;
3607: }
3608:
1.32 raeburn 3609: sub user_formats_row {
3610: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3611: my $output;
3612: my %text = (
3613: 'username' => 'new usernames',
3614: 'id' => 'IDs',
1.45 raeburn 3615: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3616: );
3617: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3618: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3619: '<td><span class="LC_nobreak">';
3620: if ($type eq 'email') {
3621: $output .= &mt("Formats disallowed for $text{$type}: ");
3622: } else {
3623: $output .= &mt("Format rules to check for $text{$type}: ");
3624: }
3625: $output .= '</span></td>'.
3626: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3627: my $rem;
3628: if (ref($ruleorder) eq 'ARRAY') {
3629: for (my $i=0; $i<@{$ruleorder}; $i++) {
3630: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3631: my $rem = $i%($numinrow);
3632: if ($rem == 0) {
3633: if ($i > 0) {
3634: $output .= '</tr>';
3635: }
3636: $output .= '<tr>';
3637: }
3638: my $check = ' ';
1.39 raeburn 3639: if (ref($settings) eq 'HASH') {
3640: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3641: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3642: $check = ' checked="checked" ';
3643: }
1.27 raeburn 3644: }
3645: }
3646: $output .= '<td class="LC_left_item">'.
3647: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3648: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 3649: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3650: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3651: }
3652: }
3653: $rem = @{$ruleorder}%($numinrow);
3654: }
3655: my $colsleft = $numinrow - $rem;
3656: if ($colsleft > 1 ) {
3657: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3658: ' </td>';
3659: } elsif ($colsleft == 1) {
3660: $output .= '<td class="LC_left_item"> </td>';
3661: }
3662: $output .= '</tr></table></td></tr>';
3663: return $output;
3664: }
3665:
1.34 raeburn 3666: sub usercreation_types {
3667: my %lt = &Apache::lonlocal::texthash (
3668: author => 'When adding a co-author',
3669: course => 'When adding a user to a course',
1.100 raeburn 3670: requestcrs => 'When requesting a course',
1.45 raeburn 3671: selfcreate => 'User creates own account',
1.34 raeburn 3672: any => 'Any',
3673: official => 'Institutional only ',
3674: unofficial => 'Non-institutional only',
1.85 schafran 3675: email => 'E-mail address',
1.43 raeburn 3676: login => 'Institutional Login',
3677: sso => 'SSO',
1.34 raeburn 3678: none => 'None',
3679: );
3680: return %lt;
1.48 raeburn 3681: }
1.34 raeburn 3682:
1.28 raeburn 3683: sub authtype_names {
3684: my %lt = &Apache::lonlocal::texthash(
3685: int => 'Internal',
3686: krb4 => 'Kerberos 4',
3687: krb5 => 'Kerberos 5',
3688: loc => 'Local',
3689: );
3690: return %lt;
3691: }
3692:
3693: sub context_names {
3694: my %context_title = &Apache::lonlocal::texthash(
3695: author => 'Creating users when an Author',
3696: course => 'Creating users when in a course',
3697: domain => 'Creating users when a Domain Coordinator',
3698: );
3699: return %context_title;
3700: }
3701:
1.33 raeburn 3702: sub print_usermodification {
3703: my ($position,$dom,$settings,$rowtotal) = @_;
3704: my $numinrow = 4;
3705: my ($context,$datatable,$rowcount);
3706: if ($position eq 'top') {
3707: $rowcount = 0;
3708: $context = 'author';
3709: foreach my $role ('ca','aa') {
3710: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3711: $numinrow,$rowcount);
3712: $$rowtotal ++;
3713: $rowcount ++;
3714: }
1.63 raeburn 3715: } elsif ($position eq 'middle') {
1.33 raeburn 3716: $context = 'course';
3717: $rowcount = 0;
3718: foreach my $role ('st','ep','ta','in','cr') {
3719: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3720: $numinrow,$rowcount);
3721: $$rowtotal ++;
3722: $rowcount ++;
3723: }
1.63 raeburn 3724: } elsif ($position eq 'bottom') {
3725: $context = 'selfcreate';
3726: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3727: $usertypes->{'default'} = $othertitle;
3728: if (ref($types) eq 'ARRAY') {
3729: push(@{$types},'default');
3730: $usertypes->{'default'} = $othertitle;
3731: foreach my $status (@{$types}) {
3732: $datatable .= &modifiable_userdata_row($context,$status,$settings,
3733: $numinrow,$rowcount,$usertypes);
3734: $$rowtotal ++;
3735: $rowcount ++;
3736: }
3737: }
1.33 raeburn 3738: }
3739: return $datatable;
3740: }
3741:
1.43 raeburn 3742: sub print_defaults {
1.160.6.27! raeburn 3743: my ($dom,$settings,$rowtotal) = @_;
1.68 raeburn 3744: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 3745: 'datelocale_def','portal_def');
1.160.6.27! raeburn 3746: my %defaults;
! 3747: if (ref($settings) eq 'HASH') {
! 3748: %defaults = %{$settings};
! 3749: } else {
! 3750: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
! 3751: foreach my $item (@items) {
! 3752: $defaults{$item} = $domdefaults{$item};
! 3753: }
! 3754: }
1.141 raeburn 3755: my $titles = &defaults_titles($dom);
1.43 raeburn 3756: my $rownum = 0;
3757: my ($datatable,$css_class);
3758: foreach my $item (@items) {
3759: if ($rownum%2) {
3760: $css_class = '';
3761: } else {
3762: $css_class = ' class="LC_odd_row" ';
3763: }
3764: $datatable .= '<tr'.$css_class.'>'.
3765: '<td><span class="LC_nobreak">'.$titles->{$item}.
3766: '</span></td><td class="LC_right_item">';
3767: if ($item eq 'auth_def') {
3768: my @authtypes = ('internal','krb4','krb5','localauth');
3769: my %shortauth = (
3770: internal => 'int',
3771: krb4 => 'krb4',
3772: krb5 => 'krb5',
3773: localauth => 'loc'
3774: );
3775: my %authnames = &authtype_names();
3776: foreach my $auth (@authtypes) {
3777: my $checked = ' ';
1.160.6.27! raeburn 3778: if ($defaults{$item} eq $auth) {
1.43 raeburn 3779: $checked = ' checked="checked" ';
3780: }
3781: $datatable .= '<label><input type="radio" name="'.$item.
3782: '" value="'.$auth.'"'.$checked.'/>'.
3783: $authnames{$shortauth{$auth}}.'</label> ';
3784: }
1.54 raeburn 3785: } elsif ($item eq 'timezone_def') {
3786: my $includeempty = 1;
1.160.6.27! raeburn 3787: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
1.68 raeburn 3788: } elsif ($item eq 'datelocale_def') {
3789: my $includeempty = 1;
1.160.6.27! raeburn 3790: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
1.160.6.5 raeburn 3791: } elsif ($item eq 'lang_def') {
3792: my %langchoices = &get_languages_hash();
3793: $langchoices{''} = 'No language preference';
3794: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.160.6.27! raeburn 3795: $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,
1.160.6.5 raeburn 3796: \%langchoices);
1.43 raeburn 3797: } else {
1.141 raeburn 3798: my $size;
3799: if ($item eq 'portal_def') {
3800: $size = ' size="25"';
3801: }
1.43 raeburn 3802: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.160.6.27! raeburn 3803: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 3804: }
3805: $datatable .= '</td></tr>';
3806: $rownum ++;
3807: }
3808: $$rowtotal += $rownum;
3809: return $datatable;
3810: }
3811:
1.160.6.5 raeburn 3812: sub get_languages_hash {
3813: my %langchoices;
3814: foreach my $id (&Apache::loncommon::languageids()) {
3815: my $code = &Apache::loncommon::supportedlanguagecode($id);
3816: if ($code ne '') {
3817: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
3818: }
3819: }
3820: return %langchoices;
3821: }
3822:
1.43 raeburn 3823: sub defaults_titles {
1.141 raeburn 3824: my ($dom) = @_;
1.43 raeburn 3825: my %titles = &Apache::lonlocal::texthash (
3826: 'auth_def' => 'Default authentication type',
3827: 'auth_arg_def' => 'Default authentication argument',
3828: 'lang_def' => 'Default language',
1.54 raeburn 3829: 'timezone_def' => 'Default timezone',
1.68 raeburn 3830: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 3831: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 3832: );
1.141 raeburn 3833: if ($dom) {
3834: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
3835: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
3836: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
3837: $protocol = 'http' if ($protocol ne 'https');
3838: if ($uint_dom) {
3839: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
3840: $uint_dom);
3841: }
3842: }
1.43 raeburn 3843: return (\%titles);
3844: }
3845:
1.46 raeburn 3846: sub print_scantronformat {
3847: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
3848: my $itemcount = 1;
1.60 raeburn 3849: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
3850: %confhash);
1.46 raeburn 3851: my $switchserver = &check_switchserver($dom,$confname);
3852: my %lt = &Apache::lonlocal::texthash (
1.95 www 3853: default => 'Default bubblesheet format file error',
3854: custom => 'Custom bubblesheet format file error',
1.46 raeburn 3855: );
3856: my %scantronfiles = (
3857: default => 'default.tab',
3858: custom => 'custom.tab',
3859: );
3860: foreach my $key (keys(%scantronfiles)) {
3861: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
3862: .$scantronfiles{$key};
3863: }
3864: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
3865: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
3866: if (!$switchserver) {
3867: my $servadm = $r->dir_config('lonAdmEMail');
3868: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
3869: if ($configuserok eq 'ok') {
3870: if ($author_ok eq 'ok') {
3871: my %legacyfile = (
3872: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
3873: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
3874: );
3875: my %md5chk;
3876: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3877: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
3878: chomp($md5chk{$type});
1.46 raeburn 3879: }
3880: if ($md5chk{'default'} ne $md5chk{'custom'}) {
3881: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3882: ($scantronurls{$type},my $error) =
1.46 raeburn 3883: &legacy_scantronformat($r,$dom,$confname,
3884: $type,$legacyfile{$type},
3885: $scantronurls{$type},
3886: $scantronfiles{$type});
1.60 raeburn 3887: if ($error ne '') {
3888: $error{$type} = $error;
3889: }
3890: }
3891: if (keys(%error) == 0) {
3892: $is_custom = 1;
3893: $confhash{'scantron'}{'scantronformat'} =
3894: $scantronurls{'custom'};
3895: my $putresult =
3896: &Apache::lonnet::put_dom('configuration',
3897: \%confhash,$dom);
3898: if ($putresult ne 'ok') {
3899: $error{'custom'} =
3900: '<span class="LC_error">'.
3901: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3902: }
1.46 raeburn 3903: }
3904: } else {
1.60 raeburn 3905: ($scantronurls{'default'},my $error) =
1.46 raeburn 3906: &legacy_scantronformat($r,$dom,$confname,
3907: 'default',$legacyfile{'default'},
3908: $scantronurls{'default'},
3909: $scantronfiles{'default'});
1.60 raeburn 3910: if ($error eq '') {
3911: $confhash{'scantron'}{'scantronformat'} = '';
3912: my $putresult =
3913: &Apache::lonnet::put_dom('configuration',
3914: \%confhash,$dom);
3915: if ($putresult ne 'ok') {
3916: $error{'default'} =
3917: '<span class="LC_error">'.
3918: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3919: }
3920: } else {
3921: $error{'default'} = $error;
3922: }
1.46 raeburn 3923: }
3924: }
3925: }
3926: } else {
1.95 www 3927: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 3928: }
3929: }
3930: if (ref($settings) eq 'HASH') {
3931: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
3932: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
3933: if ((!@info) || ($info[0] eq 'no_such_dir')) {
3934: $scantronurl = '';
3935: } else {
3936: $scantronurl = $settings->{'scantronformat'};
3937: }
3938: $is_custom = 1;
3939: } else {
3940: $scantronurl = $scantronurls{'default'};
3941: }
3942: } else {
1.60 raeburn 3943: if ($is_custom) {
3944: $scantronurl = $scantronurls{'custom'};
3945: } else {
3946: $scantronurl = $scantronurls{'default'};
3947: }
1.46 raeburn 3948: }
3949: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3950: $datatable .= '<tr'.$css_class.'>';
3951: if (!$is_custom) {
1.65 raeburn 3952: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
3953: '<span class="LC_nobreak">';
1.46 raeburn 3954: if ($scantronurl) {
1.160.6.21 raeburn 3955: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
3956: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 3957: } else {
3958: $datatable = &mt('File unavailable for display');
3959: }
1.65 raeburn 3960: $datatable .= '</span></td>';
1.60 raeburn 3961: if (keys(%error) == 0) {
3962: $datatable .= '<td valign="bottom">';
3963: if (!$switchserver) {
3964: $datatable .= &mt('Upload:').'<br />';
3965: }
3966: } else {
3967: my $errorstr;
3968: foreach my $key (sort(keys(%error))) {
3969: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3970: }
3971: $datatable .= '<td>'.$errorstr;
3972: }
1.46 raeburn 3973: } else {
3974: if (keys(%error) > 0) {
3975: my $errorstr;
3976: foreach my $key (sort(keys(%error))) {
3977: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3978: }
1.60 raeburn 3979: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 3980: } elsif ($scantronurl) {
1.160.6.26 raeburn 3981: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 3982: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 3983: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 3984: $link.
3985: '<label><input type="checkbox" name="scantronformat_del"'.
3986: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 3987: '<td><span class="LC_nobreak"> '.
3988: &mt('Replace:').'</span><br />';
1.46 raeburn 3989: }
3990: }
3991: if (keys(%error) == 0) {
3992: if ($switchserver) {
3993: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3994: } else {
1.65 raeburn 3995: $datatable .='<span class="LC_nobreak"> '.
3996: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 3997: }
3998: }
3999: $datatable .= '</td></tr>';
4000: $$rowtotal ++;
4001: return $datatable;
4002: }
4003:
4004: sub legacy_scantronformat {
4005: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
4006: my ($url,$error);
4007: my @statinfo = &Apache::lonnet::stat_file($newurl);
4008: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
4009: (my $result,$url) =
4010: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
4011: '','',$newfile);
4012: if ($result ne 'ok') {
1.130 raeburn 4013: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 4014: }
4015: }
4016: return ($url,$error);
4017: }
1.43 raeburn 4018:
1.49 raeburn 4019: sub print_coursecategories {
1.57 raeburn 4020: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
4021: my $datatable;
4022: if ($position eq 'top') {
4023: my $toggle_cats_crs = ' ';
4024: my $toggle_cats_dom = ' checked="checked" ';
4025: my $can_cat_crs = ' ';
4026: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 4027: my $toggle_catscomm_comm = ' ';
4028: my $toggle_catscomm_dom = ' checked="checked" ';
4029: my $can_catcomm_comm = ' ';
4030: my $can_catcomm_dom = ' checked="checked" ';
4031:
1.57 raeburn 4032: if (ref($settings) eq 'HASH') {
4033: if ($settings->{'togglecats'} eq 'crs') {
4034: $toggle_cats_crs = $toggle_cats_dom;
4035: $toggle_cats_dom = ' ';
4036: }
4037: if ($settings->{'categorize'} eq 'crs') {
4038: $can_cat_crs = $can_cat_dom;
4039: $can_cat_dom = ' ';
4040: }
1.120 raeburn 4041: if ($settings->{'togglecatscomm'} eq 'comm') {
4042: $toggle_catscomm_comm = $toggle_catscomm_dom;
4043: $toggle_catscomm_dom = ' ';
4044: }
4045: if ($settings->{'categorizecomm'} eq 'comm') {
4046: $can_catcomm_comm = $can_catcomm_dom;
4047: $can_catcomm_dom = ' ';
4048: }
1.57 raeburn 4049: }
4050: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 4051: togglecats => 'Show/Hide a course in catalog',
4052: togglecatscomm => 'Show/Hide a community in catalog',
4053: categorize => 'Assign a category to a course',
4054: categorizecomm => 'Assign a category to a community',
1.57 raeburn 4055: );
4056: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 4057: dom => 'Set in Domain',
4058: crs => 'Set in Course',
4059: comm => 'Set in Community',
1.57 raeburn 4060: );
4061: $datatable = '<tr class="LC_odd_row">'.
4062: '<td>'.$title{'togglecats'}.'</td>'.
4063: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4064: '<input type="radio" name="togglecats"'.
4065: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4066: '<label><input type="radio" name="togglecats"'.
4067: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
4068: '</tr><tr>'.
4069: '<td>'.$title{'categorize'}.'</td>'.
4070: '<td class="LC_right_item"><span class="LC_nobreak">'.
4071: '<label><input type="radio" name="categorize"'.
4072: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4073: '<label><input type="radio" name="categorize"'.
4074: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 4075: '</tr><tr class="LC_odd_row">'.
4076: '<td>'.$title{'togglecatscomm'}.'</td>'.
4077: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4078: '<input type="radio" name="togglecatscomm"'.
4079: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4080: '<label><input type="radio" name="togglecatscomm"'.
4081: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4082: '</tr><tr>'.
4083: '<td>'.$title{'categorizecomm'}.'</td>'.
4084: '<td class="LC_right_item"><span class="LC_nobreak">'.
4085: '<label><input type="radio" name="categorizecomm"'.
4086: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4087: '<label><input type="radio" name="categorizecomm"'.
4088: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 4089: '</tr>';
1.120 raeburn 4090: $$rowtotal += 4;
1.57 raeburn 4091: } else {
4092: my $css_class;
4093: my $itemcount = 1;
4094: my $cathash;
4095: if (ref($settings) eq 'HASH') {
4096: $cathash = $settings->{'cats'};
4097: }
4098: if (ref($cathash) eq 'HASH') {
4099: my (@cats,@trails,%allitems,%idx,@jsarray);
4100: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4101: \%allitems,\%idx,\@jsarray);
4102: my $maxdepth = scalar(@cats);
4103: my $colattrib = '';
4104: if ($maxdepth > 2) {
4105: $colattrib = ' colspan="2" ';
4106: }
4107: my @path;
4108: if (@cats > 0) {
4109: if (ref($cats[0]) eq 'ARRAY') {
4110: my $numtop = @{$cats[0]};
4111: my $maxnum = $numtop;
1.120 raeburn 4112: my %default_names = (
4113: instcode => &mt('Official courses'),
4114: communities => &mt('Communities'),
4115: );
4116:
4117: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4118: ($cathash->{'instcode::0'} eq '') ||
4119: (!grep(/^communities$/,@{$cats[0]})) ||
4120: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4121: $maxnum ++;
4122: }
4123: my $lastidx;
4124: for (my $i=0; $i<$numtop; $i++) {
4125: my $parent = $cats[0][$i];
4126: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4127: my $item = &escape($parent).'::0';
4128: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4129: $lastidx = $idx{$item};
4130: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4131: .'<select name="'.$item.'"'.$chgstr.'>';
4132: for (my $k=0; $k<=$maxnum; $k++) {
4133: my $vpos = $k+1;
4134: my $selstr;
4135: if ($k == $i) {
4136: $selstr = ' selected="selected" ';
4137: }
4138: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4139: }
4140: $datatable .= '</select></td><td>';
1.120 raeburn 4141: if ($parent eq 'instcode' || $parent eq 'communities') {
4142: $datatable .= '<span class="LC_nobreak">'
4143: .$default_names{$parent}.'</span>';
4144: if ($parent eq 'instcode') {
4145: $datatable .= '<br /><span class="LC_nobreak">('
4146: .&mt('with institutional codes')
4147: .')</span></td><td'.$colattrib.'>';
4148: } else {
4149: $datatable .= '<table><tr><td>';
4150: }
4151: $datatable .= '<span class="LC_nobreak">'
4152: .'<label><input type="radio" name="'
4153: .$parent.'" value="1" checked="checked" />'
4154: .&mt('Display').'</label>';
4155: if ($parent eq 'instcode') {
4156: $datatable .= ' ';
4157: } else {
4158: $datatable .= '</span></td></tr><tr><td>'
4159: .'<span class="LC_nobreak">';
4160: }
4161: $datatable .= '<label><input type="radio" name="'
4162: .$parent.'" value="0" />'
4163: .&mt('Do not display').'</label></span>';
4164: if ($parent eq 'communities') {
4165: $datatable .= '</td></tr></table>';
4166: }
4167: $datatable .= '</td>';
1.57 raeburn 4168: } else {
4169: $datatable .= $parent
4170: .' <label><input type="checkbox" name="deletecategory" '
4171: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4172: }
4173: my $depth = 1;
4174: push(@path,$parent);
4175: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4176: pop(@path);
4177: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4178: $itemcount ++;
4179: }
1.48 raeburn 4180: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 4181: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4182: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 4183: for (my $k=0; $k<=$maxnum; $k++) {
4184: my $vpos = $k+1;
4185: my $selstr;
1.57 raeburn 4186: if ($k == $numtop) {
1.48 raeburn 4187: $selstr = ' selected="selected" ';
4188: }
4189: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4190: }
1.59 bisitz 4191: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 4192: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4193: .'</tr>'."\n";
1.48 raeburn 4194: $itemcount ++;
1.120 raeburn 4195: foreach my $default ('instcode','communities') {
4196: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4197: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4198: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4199: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4200: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4201: for (my $k=0; $k<=$maxnum; $k++) {
4202: my $vpos = $k+1;
4203: my $selstr;
4204: if ($k == $maxnum) {
4205: $selstr = ' selected="selected" ';
4206: }
4207: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 4208: }
1.120 raeburn 4209: $datatable .= '</select></span></td>'.
4210: '<td><span class="LC_nobreak">'.
4211: $default_names{$default}.'</span>';
4212: if ($default eq 'instcode') {
4213: $datatable .= '<br /><span class="LC_nobreak">('
4214: .&mt('with institutional codes').')</span>';
4215: }
4216: $datatable .= '</td>'
4217: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4218: .&mt('Display').'</label> '
4219: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
4220: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 4221: }
4222: }
4223: }
1.57 raeburn 4224: } else {
4225: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 4226: }
4227: } else {
1.57 raeburn 4228: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
4229: .&initialize_categories($itemcount);
1.48 raeburn 4230: }
1.57 raeburn 4231: $$rowtotal += $itemcount;
1.48 raeburn 4232: }
4233: return $datatable;
4234: }
4235:
1.69 raeburn 4236: sub print_serverstatuses {
4237: my ($dom,$settings,$rowtotal) = @_;
4238: my $datatable;
4239: my @pages = &serverstatus_pages();
4240: my (%namedaccess,%machineaccess);
4241: foreach my $type (@pages) {
4242: $namedaccess{$type} = '';
4243: $machineaccess{$type}= '';
4244: }
4245: if (ref($settings) eq 'HASH') {
4246: foreach my $type (@pages) {
4247: if (exists($settings->{$type})) {
4248: if (ref($settings->{$type}) eq 'HASH') {
4249: foreach my $key (keys(%{$settings->{$type}})) {
4250: if ($key eq 'namedusers') {
4251: $namedaccess{$type} = $settings->{$type}->{$key};
4252: } elsif ($key eq 'machines') {
4253: $machineaccess{$type} = $settings->{$type}->{$key};
4254: }
4255: }
4256: }
4257: }
4258: }
4259: }
1.81 raeburn 4260: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 4261: my $rownum = 0;
4262: my $css_class;
4263: foreach my $type (@pages) {
4264: $rownum ++;
4265: $css_class = $rownum%2?' class="LC_odd_row"':'';
4266: $datatable .= '<tr'.$css_class.'>'.
4267: '<td><span class="LC_nobreak">'.
4268: $titles->{$type}.'</span></td>'.
4269: '<td class="LC_left_item">'.
4270: '<input type="text" name="'.$type.'_namedusers" '.
4271: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
4272: '<td class="LC_right_item">'.
4273: '<span class="LC_nobreak">'.
4274: '<input type="text" name="'.$type.'_machines" '.
4275: 'value="'.$machineaccess{$type}.'" size="10" />'.
4276: '</td></tr>'."\n";
4277: }
4278: $$rowtotal += $rownum;
4279: return $datatable;
4280: }
4281:
4282: sub serverstatus_pages {
4283: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 4284: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.156 raeburn 4285: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69 raeburn 4286: }
4287:
1.49 raeburn 4288: sub coursecategories_javascript {
4289: my ($settings) = @_;
1.57 raeburn 4290: my ($output,$jstext,$cathash);
1.49 raeburn 4291: if (ref($settings) eq 'HASH') {
1.57 raeburn 4292: $cathash = $settings->{'cats'};
4293: }
4294: if (ref($cathash) eq 'HASH') {
1.49 raeburn 4295: my (@cats,@jsarray,%idx);
1.57 raeburn 4296: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 4297: if (@jsarray > 0) {
4298: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
4299: for (my $i=0; $i<@jsarray; $i++) {
4300: if (ref($jsarray[$i]) eq 'ARRAY') {
4301: my $catstr = join('","',@{$jsarray[$i]});
4302: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
4303: }
4304: }
4305: }
4306: } else {
4307: $jstext = ' var categories = Array(1);'."\n".
4308: ' categories[0] = Array("instcode_pos");'."\n";
4309: }
1.120 raeburn 4310: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
4311: my $communities_reserved = &mt('The name: "communities" is a reserved category');
4312: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 4313: $output = <<"ENDSCRIPT";
4314: <script type="text/javascript">
1.109 raeburn 4315: // <![CDATA[
1.49 raeburn 4316: function reorderCats(form,parent,item,idx) {
4317: var changedVal;
4318: $jstext
4319: var newpos = 'addcategory_pos';
4320: var current = new Array;
4321: if (parent == '') {
4322: var has_instcode = 0;
4323: var maxtop = categories[idx].length;
4324: for (var j=0; j<maxtop; j++) {
4325: if (categories[idx][j] == 'instcode::0') {
4326: has_instcode == 1;
4327: }
4328: }
4329: if (has_instcode == 0) {
4330: categories[idx][maxtop] = 'instcode_pos';
4331: }
4332: } else {
4333: newpos += '_'+parent;
4334: }
4335: var maxh = 1 + categories[idx].length;
4336: var current = new Array;
4337: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4338: if (item == newpos) {
4339: changedVal = newitemVal;
4340: } else {
4341: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4342: current[newitemVal] = newpos;
4343: }
4344: for (var i=0; i<categories[idx].length; i++) {
4345: var elementName = categories[idx][i];
4346: if (elementName != item) {
4347: if (form.elements[elementName]) {
4348: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4349: current[currVal] = elementName;
4350: }
4351: }
4352: }
4353: var oldVal;
4354: for (var j=0; j<maxh; j++) {
4355: if (current[j] == undefined) {
4356: oldVal = j;
4357: }
4358: }
4359: if (oldVal < changedVal) {
4360: for (var k=oldVal+1; k<=changedVal ; k++) {
4361: var elementName = current[k];
4362: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4363: }
4364: } else {
4365: for (var k=changedVal; k<oldVal; k++) {
4366: var elementName = current[k];
4367: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4368: }
4369: }
4370: return;
4371: }
1.120 raeburn 4372:
4373: function categoryCheck(form) {
4374: if (form.elements['addcategory_name'].value == 'instcode') {
4375: alert('$instcode_reserved\\n$choose_again');
4376: return false;
4377: }
4378: if (form.elements['addcategory_name'].value == 'communities') {
4379: alert('$communities_reserved\\n$choose_again');
4380: return false;
4381: }
4382: return true;
4383: }
4384:
1.109 raeburn 4385: // ]]>
1.49 raeburn 4386: </script>
4387:
4388: ENDSCRIPT
4389: return $output;
4390: }
4391:
1.48 raeburn 4392: sub initialize_categories {
4393: my ($itemcount) = @_;
1.120 raeburn 4394: my ($datatable,$css_class,$chgstr);
4395: my %default_names = (
4396: instcode => 'Official courses (with institutional codes)',
4397: communities => 'Communities',
4398: );
4399: my $select0 = ' selected="selected"';
4400: my $select1 = '';
4401: foreach my $default ('instcode','communities') {
4402: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4403: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
4404: if ($default eq 'communities') {
4405: $select1 = $select0;
4406: $select0 = '';
4407: }
4408: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4409: .'<select name="'.$default.'_pos">'
4410: .'<option value="0"'.$select0.'>1</option>'
4411: .'<option value="1"'.$select1.'>2</option>'
4412: .'<option value="2">3</option></select> '
4413: .$default_names{$default}
4414: .'</span></td><td><span class="LC_nobreak">'
4415: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4416: .&mt('Display').'</label> <label>'
4417: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 4418: .'</label></span></td></tr>';
1.120 raeburn 4419: $itemcount ++;
4420: }
1.48 raeburn 4421: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 4422: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 4423: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 4424: .'<select name="addcategory_pos"'.$chgstr.'>'
4425: .'<option value="0">1</option>'
4426: .'<option value="1">2</option>'
4427: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 4428: .&mt('Add category').'</td><td>'.&mt('Name:')
4429: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4430: return $datatable;
4431: }
4432:
4433: sub build_category_rows {
1.49 raeburn 4434: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4435: my ($text,$name,$item,$chgstr);
1.48 raeburn 4436: if (ref($cats) eq 'ARRAY') {
4437: my $maxdepth = scalar(@{$cats});
4438: if (ref($cats->[$depth]) eq 'HASH') {
4439: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4440: my $numchildren = @{$cats->[$depth]{$parent}};
4441: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 4442: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 4443: my ($idxnum,$parent_name,$parent_item);
4444: my $higher = $depth - 1;
4445: if ($higher == 0) {
4446: $parent_name = &escape($parent).'::'.$higher;
4447: } else {
4448: if (ref($path) eq 'ARRAY') {
4449: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4450: }
4451: }
4452: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4453: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4454: if ($j < $numchildren) {
1.48 raeburn 4455: $name = $cats->[$depth]{$parent}[$j];
4456: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4457: $idxnum = $idx->{$item};
4458: } else {
4459: $name = $parent_name;
4460: $item = $parent_item;
1.48 raeburn 4461: }
1.49 raeburn 4462: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4463: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4464: for (my $i=0; $i<=$numchildren; $i++) {
4465: my $vpos = $i+1;
4466: my $selstr;
4467: if ($j == $i) {
4468: $selstr = ' selected="selected" ';
4469: }
4470: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4471: }
4472: $text .= '</select> ';
4473: if ($j < $numchildren) {
4474: my $deeper = $depth+1;
4475: $text .= $name.' '
4476: .'<label><input type="checkbox" name="deletecategory" value="'
4477: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4478: if(ref($path) eq 'ARRAY') {
4479: push(@{$path},$name);
1.49 raeburn 4480: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4481: pop(@{$path});
4482: }
4483: } else {
1.59 bisitz 4484: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4485: if ($j == $numchildren) {
4486: $text .= $name;
4487: } else {
4488: $text .= $item;
4489: }
4490: $text .= '" value="" />';
4491: }
4492: $text .= '</td></tr>';
4493: }
4494: $text .= '</table></td>';
4495: } else {
4496: my $higher = $depth-1;
4497: if ($higher == 0) {
4498: $name = &escape($parent).'::'.$higher;
4499: } else {
4500: if (ref($path) eq 'ARRAY') {
4501: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4502: }
4503: }
4504: my $colspan;
4505: if ($parent ne 'instcode') {
4506: $colspan = $maxdepth - $depth - 1;
4507: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4508: }
4509: }
4510: }
4511: }
4512: return $text;
4513: }
4514:
1.33 raeburn 4515: sub modifiable_userdata_row {
1.63 raeburn 4516: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 4517: my $rolename;
1.63 raeburn 4518: if ($context eq 'selfcreate') {
4519: if (ref($usertypes) eq 'HASH') {
4520: $rolename = $usertypes->{$role};
4521: } else {
4522: $rolename = $role;
4523: }
1.33 raeburn 4524: } else {
1.63 raeburn 4525: if ($role eq 'cr') {
4526: $rolename = &mt('Custom role');
4527: } else {
4528: $rolename = &Apache::lonnet::plaintext($role);
4529: }
1.33 raeburn 4530: }
4531: my @fields = ('lastname','firstname','middlename','generation',
4532: 'permanentemail','id');
4533: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4534: my $output;
4535: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4536: $output = '<tr '.$css_class.'>'.
4537: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4538: '<td class="LC_left_item" colspan="2"><table>';
4539: my $rem;
4540: my %checks;
4541: if (ref($settings) eq 'HASH') {
4542: if (ref($settings->{$context}) eq 'HASH') {
4543: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4544: foreach my $field (@fields) {
4545: if ($settings->{$context}->{$role}->{$field}) {
4546: $checks{$field} = ' checked="checked" ';
4547: }
4548: }
4549: }
4550: }
4551: }
4552: for (my $i=0; $i<@fields; $i++) {
4553: my $rem = $i%($numinrow);
4554: if ($rem == 0) {
4555: if ($i > 0) {
4556: $output .= '</tr>';
4557: }
4558: $output .= '<tr>';
4559: }
4560: my $check = ' ';
4561: if (exists($checks{$fields[$i]})) {
4562: $check = $checks{$fields[$i]}
4563: } else {
4564: if ($role eq 'st') {
4565: if (ref($settings) ne 'HASH') {
4566: $check = ' checked="checked" ';
4567: }
4568: }
4569: }
4570: $output .= '<td class="LC_left_item">'.
4571: '<span class="LC_nobreak"><label>'.
4572: '<input type="checkbox" name="canmodify_'.$role.'" '.
4573: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4574: '</label></span></td>';
4575: $rem = @fields%($numinrow);
4576: }
4577: my $colsleft = $numinrow - $rem;
4578: if ($colsleft > 1 ) {
4579: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4580: ' </td>';
4581: } elsif ($colsleft == 1) {
4582: $output .= '<td class="LC_left_item"> </td>';
4583: }
4584: $output .= '</tr></table></td></tr>';
4585: return $output;
4586: }
1.28 raeburn 4587:
1.93 raeburn 4588: sub insttypes_row {
4589: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
4590: my %lt = &Apache::lonlocal::texthash (
4591: cansearch => 'Users allowed to search',
4592: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4593: lockablenames => 'User preference to lock name',
1.93 raeburn 4594: );
4595: my $showdom;
4596: if ($context eq 'cansearch') {
4597: $showdom = ' ('.$dom.')';
4598: }
1.160.6.5 raeburn 4599: my $class = 'LC_left_item';
4600: if ($context eq 'statustocreate') {
4601: $class = 'LC_right_item';
4602: }
1.25 raeburn 4603: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 4604: '<td>'.$lt{$context}.$showdom.
1.160.6.5 raeburn 4605: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 4606: my $rem;
4607: if (ref($types) eq 'ARRAY') {
4608: for (my $i=0; $i<@{$types}; $i++) {
4609: if (defined($usertypes->{$types->[$i]})) {
4610: my $rem = $i%($numinrow);
4611: if ($rem == 0) {
4612: if ($i > 0) {
4613: $output .= '</tr>';
4614: }
4615: $output .= '<tr>';
1.23 raeburn 4616: }
1.26 raeburn 4617: my $check = ' ';
1.99 raeburn 4618: if (ref($settings) eq 'HASH') {
4619: if (ref($settings->{$context}) eq 'ARRAY') {
4620: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4621: $check = ' checked="checked" ';
4622: }
4623: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4624: $check = ' checked="checked" ';
4625: }
1.23 raeburn 4626: }
1.26 raeburn 4627: $output .= '<td class="LC_left_item">'.
4628: '<span class="LC_nobreak"><label>'.
1.93 raeburn 4629: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 4630: 'value="'.$types->[$i].'"'.$check.'/>'.
4631: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 4632: }
4633: }
1.26 raeburn 4634: $rem = @{$types}%($numinrow);
1.23 raeburn 4635: }
4636: my $colsleft = $numinrow - $rem;
1.131 raeburn 4637: if (($rem == 0) && (@{$types} > 0)) {
4638: $output .= '<tr>';
4639: }
1.23 raeburn 4640: if ($colsleft > 1) {
1.25 raeburn 4641: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 4642: } else {
1.25 raeburn 4643: $output .= '<td class="LC_left_item">';
1.23 raeburn 4644: }
4645: my $defcheck = ' ';
1.99 raeburn 4646: if (ref($settings) eq 'HASH') {
4647: if (ref($settings->{$context}) eq 'ARRAY') {
4648: if (grep(/^default$/,@{$settings->{$context}})) {
4649: $defcheck = ' checked="checked" ';
4650: }
4651: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4652: $defcheck = ' checked="checked" ';
4653: }
1.23 raeburn 4654: }
1.25 raeburn 4655: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 4656: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 4657: 'value="default"'.$defcheck.'/>'.
4658: $othertitle.'</label></span></td>'.
4659: '</tr></table></td></tr>';
4660: return $output;
1.23 raeburn 4661: }
4662:
4663: sub sorted_searchtitles {
4664: my %searchtitles = &Apache::lonlocal::texthash(
4665: 'uname' => 'username',
4666: 'lastname' => 'last name',
4667: 'lastfirst' => 'last name, first name',
4668: );
4669: my @titleorder = ('uname','lastname','lastfirst');
4670: return (\%searchtitles,\@titleorder);
4671: }
4672:
1.25 raeburn 4673: sub sorted_searchtypes {
4674: my %srchtypes_desc = (
4675: exact => 'is exact match',
4676: contains => 'contains ..',
4677: begins => 'begins with ..',
4678: );
4679: my @srchtypeorder = ('exact','begins','contains');
4680: return (\%srchtypes_desc,\@srchtypeorder);
4681: }
4682:
1.3 raeburn 4683: sub usertype_update_row {
4684: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
4685: my $datatable;
4686: my $numinrow = 4;
4687: foreach my $type (@{$types}) {
4688: if (defined($usertypes->{$type})) {
4689: $$rownums ++;
4690: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
4691: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
4692: '</td><td class="LC_left_item"><table>';
4693: for (my $i=0; $i<@{$fields}; $i++) {
4694: my $rem = $i%($numinrow);
4695: if ($rem == 0) {
4696: if ($i > 0) {
4697: $datatable .= '</tr>';
4698: }
4699: $datatable .= '<tr>';
4700: }
4701: my $check = ' ';
1.39 raeburn 4702: if (ref($settings) eq 'HASH') {
4703: if (ref($settings->{'fields'}) eq 'HASH') {
4704: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
4705: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
4706: $check = ' checked="checked" ';
4707: }
1.3 raeburn 4708: }
4709: }
4710: }
4711:
4712: if ($i == @{$fields}-1) {
4713: my $colsleft = $numinrow - $rem;
4714: if ($colsleft > 1) {
4715: $datatable .= '<td colspan="'.$colsleft.'">';
4716: } else {
4717: $datatable .= '<td>';
4718: }
4719: } else {
4720: $datatable .= '<td>';
4721: }
1.8 raeburn 4722: $datatable .= '<span class="LC_nobreak"><label>'.
4723: '<input type="checkbox" name="updateable_'.$type.
4724: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
4725: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 4726: }
4727: $datatable .= '</tr></table></td></tr>';
4728: }
4729: }
4730: return $datatable;
1.1 raeburn 4731: }
4732:
4733: sub modify_login {
1.160.6.24 raeburn 4734: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 4735: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
4736: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
4737: %title = ( coursecatalog => 'Display course catalog',
4738: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 4739: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 4740: newuser => 'Link for visitors to create a user account',
4741: loginheader => 'Log-in box header');
4742: @offon = ('off','on');
1.112 raeburn 4743: if (ref($domconfig{login}) eq 'HASH') {
4744: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
4745: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
4746: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
4747: }
4748: }
4749: }
1.9 raeburn 4750: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
4751: \%domconfig,\%loginhash);
1.160.6.14 raeburn 4752: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 4753: foreach my $item (@toggles) {
4754: $loginhash{login}{$item} = $env{'form.'.$item};
4755: }
1.41 raeburn 4756: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 4757: if (ref($colchanges{'login'}) eq 'HASH') {
4758: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
4759: \%loginhash);
4760: }
1.110 raeburn 4761:
1.149 raeburn 4762: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 4763: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 4764: if (keys(%servers) > 1) {
4765: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 4766: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
4767: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
4768: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
4769: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
4770: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
4771: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4772: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4773: $changes{'loginvia'}{$lonhost} = 1;
4774: } else {
4775: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
4776: $changes{'loginvia'}{$lonhost} = 1;
4777: }
4778: } else {
4779: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4780: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4781: $changes{'loginvia'}{$lonhost} = 1;
4782: }
4783: }
4784: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
4785: foreach my $item (@loginvia_attribs) {
4786: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
4787: }
4788: } else {
4789: foreach my $item (@loginvia_attribs) {
4790: my $new = $env{'form.'.$lonhost.'_'.$item};
4791: if (($item eq 'serverpath') && ($new eq 'custom')) {
4792: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
4793: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4794: $new = '/';
4795: }
4796: }
4797: if (($item eq 'custompath') &&
4798: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4799: $new = '';
4800: }
4801: if ($new ne $curr_loginvia{$lonhost}{$item}) {
4802: $changes{'loginvia'}{$lonhost} = 1;
4803: }
4804: if ($item eq 'exempt') {
4805: $new =~ s/^\s+//;
4806: $new =~ s/\s+$//;
4807: my @poss_ips = split(/\s*[,:]\s*/,$new);
4808: my @okips;
4809: foreach my $ip (@poss_ips) {
4810: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
4811: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
4812: push(@okips,$ip);
4813: }
4814: }
4815: }
4816: if (@okips > 0) {
4817: $new = join(',',@okips);
4818: } else {
4819: $new = '';
4820: }
4821: }
4822: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4823: }
4824: }
1.112 raeburn 4825: } else {
1.128 raeburn 4826: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4827: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 4828: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 4829: foreach my $item (@loginvia_attribs) {
4830: my $new = $env{'form.'.$lonhost.'_'.$item};
4831: if (($item eq 'serverpath') && ($new eq 'custom')) {
4832: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4833: $new = '/';
4834: }
4835: }
4836: if (($item eq 'custompath') &&
4837: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4838: $new = '';
4839: }
4840: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4841: }
1.110 raeburn 4842: }
4843: }
4844: }
4845: }
1.119 raeburn 4846:
1.160.6.5 raeburn 4847: my $servadm = $r->dir_config('lonAdmEMail');
4848: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
4849: if (ref($domconfig{'login'}) eq 'HASH') {
4850: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
4851: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
4852: if ($lang eq 'nolang') {
4853: push(@currlangs,$lang);
4854: } elsif (defined($langchoices{$lang})) {
4855: push(@currlangs,$lang);
4856: } else {
4857: next;
4858: }
4859: }
4860: }
4861: }
4862: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
4863: if (@currlangs > 0) {
4864: foreach my $lang (@currlangs) {
4865: if (grep(/^\Q$lang\E$/,@delurls)) {
4866: $changes{'helpurl'}{$lang} = 1;
4867: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
4868: $changes{'helpurl'}{$lang} = 1;
4869: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
4870: push(@newlangs,$lang);
4871: } else {
4872: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4873: }
4874: }
4875: }
4876: unless (grep(/^nolang$/,@currlangs)) {
4877: if ($env{'form.loginhelpurl_nolang.filename'}) {
4878: $changes{'helpurl'}{'nolang'} = 1;
4879: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
4880: push(@newlangs,'nolang');
4881: }
4882: }
4883: if ($env{'form.loginhelpurl_add_lang'}) {
4884: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
4885: ($env{'form.loginhelpurl_add_file.filename'})) {
4886: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
4887: $addedfile = $env{'form.loginhelpurl_add_lang'};
4888: }
4889: }
4890: if ((@newlangs > 0) || ($addedfile)) {
4891: my $error;
4892: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
4893: if ($configuserok eq 'ok') {
4894: if ($switchserver) {
4895: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
4896: } elsif ($author_ok eq 'ok') {
4897: my @allnew = @newlangs;
4898: if ($addedfile ne '') {
4899: push(@allnew,$addedfile);
4900: }
4901: foreach my $lang (@allnew) {
4902: my $formelem = 'loginhelpurl_'.$lang;
4903: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
4904: $formelem = 'loginhelpurl_add_file';
4905: }
4906: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
4907: "help/$lang",'','',$newfile{$lang});
4908: if ($result eq 'ok') {
4909: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
4910: $changes{'helpurl'}{$lang} = 1;
4911: } else {
4912: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
4913: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
4914: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
4915: (!grep(/^\Q$lang\E$/,@delurls))) {
4916:
4917: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4918: }
4919: }
4920: }
4921: } else {
4922: $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);
4923: }
4924: } else {
4925: $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);
4926: }
4927: if ($error) {
4928: &Apache::lonnet::logthis($error);
4929: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
4930: }
4931: }
4932: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
4933:
4934: my $defaulthelpfile = '/adm/loginproblems.html';
4935: my $defaulttext = &mt('Default in use');
4936:
1.1 raeburn 4937: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
4938: $dom);
4939: if ($putresult eq 'ok') {
1.160.6.14 raeburn 4940: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 4941: my %defaultchecked = (
4942: 'coursecatalog' => 'on',
1.160.6.14 raeburn 4943: 'helpdesk' => 'on',
1.42 raeburn 4944: 'adminmail' => 'off',
1.43 raeburn 4945: 'newuser' => 'off',
1.42 raeburn 4946: );
1.55 raeburn 4947: if (ref($domconfig{'login'}) eq 'HASH') {
4948: foreach my $item (@toggles) {
4949: if ($defaultchecked{$item} eq 'on') {
4950: if (($domconfig{'login'}{$item} eq '0') &&
4951: ($env{'form.'.$item} eq '1')) {
4952: $changes{$item} = 1;
4953: } elsif (($domconfig{'login'}{$item} eq '' ||
4954: $domconfig{'login'}{$item} eq '1') &&
4955: ($env{'form.'.$item} eq '0')) {
4956: $changes{$item} = 1;
4957: }
4958: } elsif ($defaultchecked{$item} eq 'off') {
4959: if (($domconfig{'login'}{$item} eq '1') &&
4960: ($env{'form.'.$item} eq '0')) {
4961: $changes{$item} = 1;
4962: } elsif (($domconfig{'login'}{$item} eq '' ||
4963: $domconfig{'login'}{$item} eq '0') &&
4964: ($env{'form.'.$item} eq '1')) {
4965: $changes{$item} = 1;
4966: }
1.42 raeburn 4967: }
4968: }
1.41 raeburn 4969: }
1.6 raeburn 4970: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 4971: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27! raeburn 4972: if (ref($lastactref) eq 'HASH') {
! 4973: $lastactref->{'domainconfig'} = 1;
! 4974: }
1.1 raeburn 4975: $resulttext = &mt('Changes made:').'<ul>';
4976: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 4977: if ($item eq 'loginvia') {
1.112 raeburn 4978: if (ref($changes{$item}) eq 'HASH') {
4979: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
4980: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 4981: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
4982: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
4983: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
4984: $protocol = 'http' if ($protocol ne 'https');
4985: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
4986:
4987: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
4988: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
4989: } else {
4990: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
4991: }
4992: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
4993: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
4994: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
4995: }
4996: $resulttext .= '</li>';
4997: } else {
4998: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
4999: }
1.112 raeburn 5000: } else {
1.128 raeburn 5001: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 5002: }
5003: }
1.128 raeburn 5004: $resulttext .= '</ul></li>';
1.112 raeburn 5005: }
1.160.6.5 raeburn 5006: } elsif ($item eq 'helpurl') {
5007: if (ref($changes{$item}) eq 'HASH') {
5008: foreach my $lang (sort(keys(%{$changes{$item}}))) {
5009: if (grep(/^\Q$lang\E$/,@delurls)) {
5010: my ($chg,$link);
5011: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
5012: if ($lang eq 'nolang') {
5013: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
5014: } else {
5015: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
5016: }
5017: $resulttext .= '<li>'.$chg.'</li>';
5018: } else {
5019: my $chg;
5020: if ($lang eq 'nolang') {
5021: $chg = &mt('custom log-in help file for no preferred language');
5022: } else {
5023: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
5024: }
5025: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
5026: $loginhash{'login'}{'helpurl'}{$lang}.
5027: '?inhibitmenu=yes',$chg,600,500).
5028: '</li>';
5029: }
5030: }
5031: }
5032: } elsif ($item eq 'captcha') {
5033: if (ref($loginhash{'login'}) eq 'HASH') {
5034: my $chgtxt;
5035: if ($loginhash{'login'}{$item} eq 'notused') {
5036: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
5037: } else {
5038: my %captchas = &captcha_phrases();
5039: if ($captchas{$loginhash{'login'}{$item}}) {
5040: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
5041: } else {
5042: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
5043: }
5044: }
5045: $resulttext .= '<li>'.$chgtxt.'</li>';
5046: }
5047: } elsif ($item eq 'recaptchakeys') {
5048: if (ref($loginhash{'login'}) eq 'HASH') {
5049: my ($privkey,$pubkey);
5050: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
5051: $pubkey = $loginhash{'login'}{$item}{'public'};
5052: $privkey = $loginhash{'login'}{$item}{'private'};
5053: }
5054: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
5055: if (!$pubkey) {
5056: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
5057: } else {
5058: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
5059: }
5060: if (!$privkey) {
5061: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
5062: } else {
5063: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
5064: }
5065: $chgtxt .= '</ul>';
5066: $resulttext .= '<li>'.$chgtxt.'</li>';
5067: }
1.41 raeburn 5068: } else {
5069: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
5070: }
1.1 raeburn 5071: }
1.6 raeburn 5072: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 5073: } else {
5074: $resulttext = &mt('No changes made to log-in page settings');
5075: }
5076: } else {
1.11 albertel 5077: $resulttext = '<span class="LC_error">'.
5078: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5079: }
1.6 raeburn 5080: if ($errors) {
1.9 raeburn 5081: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 5082: $errors.'</ul>';
5083: }
5084: return $resulttext;
5085: }
5086:
5087: sub color_font_choices {
5088: my %choices =
5089: &Apache::lonlocal::texthash (
5090: img => "Header",
5091: bgs => "Background colors",
5092: links => "Link colors",
1.55 raeburn 5093: images => "Images",
1.6 raeburn 5094: font => "Font color",
1.160.6.22 raeburn 5095: fontmenu => "Font menu",
1.76 raeburn 5096: pgbg => "Page",
1.6 raeburn 5097: tabbg => "Header",
5098: sidebg => "Border",
5099: link => "Link",
5100: alink => "Active link",
5101: vlink => "Visited link",
5102: );
5103: return %choices;
5104: }
5105:
5106: sub modify_rolecolors {
1.160.6.24 raeburn 5107: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 5108: my ($resulttext,%rolehash);
5109: $rolehash{'rolecolors'} = {};
1.55 raeburn 5110: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
5111: if ($domconfig{'rolecolors'} eq '') {
5112: $domconfig{'rolecolors'} = {};
5113: }
5114: }
1.9 raeburn 5115: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 5116: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
5117: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
5118: $dom);
5119: if ($putresult eq 'ok') {
5120: if (keys(%changes) > 0) {
1.41 raeburn 5121: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27! raeburn 5122: if (ref($lastactref) eq 'HASH') {
! 5123: $lastactref->{'domainconfig'} = 1;
! 5124: }
1.6 raeburn 5125: $resulttext = &display_colorchgs($dom,\%changes,$roles,
5126: $rolehash{'rolecolors'});
5127: } else {
5128: $resulttext = &mt('No changes made to default color schemes');
5129: }
5130: } else {
1.11 albertel 5131: $resulttext = '<span class="LC_error">'.
5132: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 5133: }
5134: if ($errors) {
5135: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5136: $errors.'</ul>';
5137: }
5138: return $resulttext;
5139: }
5140:
5141: sub modify_colors {
1.9 raeburn 5142: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 5143: my (%changes,%choices);
1.51 raeburn 5144: my @bgs;
1.6 raeburn 5145: my @links = ('link','alink','vlink');
1.41 raeburn 5146: my @logintext;
1.6 raeburn 5147: my @images;
5148: my $servadm = $r->dir_config('lonAdmEMail');
5149: my $errors;
1.160.6.22 raeburn 5150: my %defaults;
1.6 raeburn 5151: foreach my $role (@{$roles}) {
5152: if ($role eq 'login') {
1.12 raeburn 5153: %choices = &login_choices();
1.41 raeburn 5154: @logintext = ('textcol','bgcol');
1.12 raeburn 5155: } else {
5156: %choices = &color_font_choices();
5157: }
5158: if ($role eq 'login') {
1.41 raeburn 5159: @images = ('img','logo','domlogo','login');
1.51 raeburn 5160: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 5161: } else {
5162: @images = ('img');
1.160.6.22 raeburn 5163: @bgs = ('pgbg','tabbg','sidebg');
5164: }
5165: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
5166: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
5167: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
5168: }
5169: if ($role eq 'login') {
5170: foreach my $item (@logintext) {
5171: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'logintext'}{$item}) {
5172: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5173: }
5174: }
5175: } else {
5176: unless($env{'form.'.$role.'_fontmenu'} eq $defaults{'fontmenu'}) {
5177: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
5178: }
1.6 raeburn 5179: }
1.160.6.22 raeburn 5180: foreach my $item (@bgs) {
5181: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'bgs'}{$item} ) {
5182: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5183: }
5184: }
5185: foreach my $item (@links) {
5186: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'links'}{$item}) {
5187: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5188: }
1.6 raeburn 5189: }
1.46 raeburn 5190: my ($configuserok,$author_ok,$switchserver) =
5191: &config_check($dom,$confname,$servadm);
1.9 raeburn 5192: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 5193: if (ref($domconfig->{$role}) ne 'HASH') {
5194: $domconfig->{$role} = {};
5195: }
1.8 raeburn 5196: foreach my $img (@images) {
1.70 raeburn 5197: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
5198: if (defined($env{'form.login_showlogo_'.$img})) {
5199: $confhash->{$role}{'showlogo'}{$img} = 1;
5200: } else {
5201: $confhash->{$role}{'showlogo'}{$img} = 0;
5202: }
5203: }
1.18 albertel 5204: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
5205: && !defined($domconfig->{$role}{$img})
5206: && !$env{'form.'.$role.'_del_'.$img}
5207: && $env{'form.'.$role.'_import_'.$img}) {
5208: # import the old configured image from the .tab setting
5209: # if they haven't provided a new one
5210: $domconfig->{$role}{$img} =
5211: $env{'form.'.$role.'_import_'.$img};
5212: }
1.6 raeburn 5213: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 5214: my $error;
1.6 raeburn 5215: if ($configuserok eq 'ok') {
1.9 raeburn 5216: if ($switchserver) {
1.12 raeburn 5217: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 5218: } else {
5219: if ($author_ok eq 'ok') {
5220: my ($result,$logourl) =
5221: &publishlogo($r,'upload',$role.'_'.$img,
5222: $dom,$confname,$img,$width,$height);
5223: if ($result eq 'ok') {
5224: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 5225: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5226: } else {
1.12 raeburn 5227: $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 5228: }
5229: } else {
1.46 raeburn 5230: $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 5231: }
5232: }
5233: } else {
1.46 raeburn 5234: $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 5235: }
5236: if ($error) {
1.8 raeburn 5237: &Apache::lonnet::logthis($error);
1.11 albertel 5238: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 5239: }
5240: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 5241: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
5242: my $error;
5243: if ($configuserok eq 'ok') {
5244: # is confname an author?
5245: if ($switchserver eq '') {
5246: if ($author_ok eq 'ok') {
5247: my ($result,$logourl) =
5248: &publishlogo($r,'copy',$domconfig->{$role}{$img},
5249: $dom,$confname,$img,$width,$height);
5250: if ($result eq 'ok') {
5251: $confhash->{$role}{$img} = $logourl;
1.18 albertel 5252: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5253: }
5254: }
5255: }
5256: }
1.6 raeburn 5257: }
5258: }
5259: }
5260: if (ref($domconfig) eq 'HASH') {
5261: if (ref($domconfig->{$role}) eq 'HASH') {
5262: foreach my $img (@images) {
5263: if ($domconfig->{$role}{$img} ne '') {
5264: if ($env{'form.'.$role.'_del_'.$img}) {
5265: $confhash->{$role}{$img} = '';
1.12 raeburn 5266: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5267: } else {
1.9 raeburn 5268: if ($confhash->{$role}{$img} eq '') {
5269: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
5270: }
1.6 raeburn 5271: }
5272: } else {
5273: if ($env{'form.'.$role.'_del_'.$img}) {
5274: $confhash->{$role}{$img} = '';
1.12 raeburn 5275: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5276: }
5277: }
1.70 raeburn 5278: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
5279: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
5280: if ($confhash->{$role}{'showlogo'}{$img} ne
5281: $domconfig->{$role}{'showlogo'}{$img}) {
5282: $changes{$role}{'showlogo'}{$img} = 1;
5283: }
5284: } else {
5285: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5286: $changes{$role}{'showlogo'}{$img} = 1;
5287: }
5288: }
5289: }
5290: }
1.6 raeburn 5291: if ($domconfig->{$role}{'font'} ne '') {
5292: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
5293: $changes{$role}{'font'} = 1;
5294: }
5295: } else {
5296: if ($confhash->{$role}{'font'}) {
5297: $changes{$role}{'font'} = 1;
5298: }
5299: }
1.107 raeburn 5300: if ($role ne 'login') {
5301: if ($domconfig->{$role}{'fontmenu'} ne '') {
5302: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
5303: $changes{$role}{'fontmenu'} = 1;
5304: }
5305: } else {
5306: if ($confhash->{$role}{'fontmenu'}) {
5307: $changes{$role}{'fontmenu'} = 1;
5308: }
1.97 tempelho 5309: }
5310: }
1.6 raeburn 5311: foreach my $item (@bgs) {
5312: if ($domconfig->{$role}{$item} ne '') {
5313: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5314: $changes{$role}{'bgs'}{$item} = 1;
5315: }
5316: } else {
5317: if ($confhash->{$role}{$item}) {
5318: $changes{$role}{'bgs'}{$item} = 1;
5319: }
5320: }
5321: }
5322: foreach my $item (@links) {
5323: if ($domconfig->{$role}{$item} ne '') {
5324: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5325: $changes{$role}{'links'}{$item} = 1;
5326: }
5327: } else {
5328: if ($confhash->{$role}{$item}) {
5329: $changes{$role}{'links'}{$item} = 1;
5330: }
5331: }
5332: }
1.41 raeburn 5333: foreach my $item (@logintext) {
5334: if ($domconfig->{$role}{$item} ne '') {
5335: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5336: $changes{$role}{'logintext'}{$item} = 1;
5337: }
5338: } else {
5339: if ($confhash->{$role}{$item}) {
5340: $changes{$role}{'logintext'}{$item} = 1;
5341: }
5342: }
5343: }
1.6 raeburn 5344: } else {
5345: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5346: \@logintext,$confhash,\%changes);
1.6 raeburn 5347: }
5348: } else {
5349: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5350: \@logintext,$confhash,\%changes);
1.6 raeburn 5351: }
5352: }
5353: return ($errors,%changes);
5354: }
5355:
1.46 raeburn 5356: sub config_check {
5357: my ($dom,$confname,$servadm) = @_;
5358: my ($configuserok,$author_ok,$switchserver,%currroles);
5359: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
5360: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
5361: $confname,$servadm);
5362: if ($configuserok eq 'ok') {
5363: $switchserver = &check_switchserver($dom,$confname);
5364: if ($switchserver eq '') {
5365: $author_ok = &check_authorstatus($dom,$confname,%currroles);
5366: }
5367: }
5368: return ($configuserok,$author_ok,$switchserver);
5369: }
5370:
1.6 raeburn 5371: sub default_change_checker {
1.41 raeburn 5372: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 5373: foreach my $item (@{$links}) {
5374: if ($confhash->{$role}{$item}) {
5375: $changes->{$role}{'links'}{$item} = 1;
5376: }
5377: }
5378: foreach my $item (@{$bgs}) {
5379: if ($confhash->{$role}{$item}) {
5380: $changes->{$role}{'bgs'}{$item} = 1;
5381: }
5382: }
1.41 raeburn 5383: foreach my $item (@{$logintext}) {
5384: if ($confhash->{$role}{$item}) {
5385: $changes->{$role}{'logintext'}{$item} = 1;
5386: }
5387: }
1.6 raeburn 5388: foreach my $img (@{$images}) {
5389: if ($env{'form.'.$role.'_del_'.$img}) {
5390: $confhash->{$role}{$img} = '';
1.12 raeburn 5391: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 5392: }
1.70 raeburn 5393: if ($role eq 'login') {
5394: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5395: $changes->{$role}{'showlogo'}{$img} = 1;
5396: }
5397: }
1.6 raeburn 5398: }
5399: if ($confhash->{$role}{'font'}) {
5400: $changes->{$role}{'font'} = 1;
5401: }
1.48 raeburn 5402: }
1.6 raeburn 5403:
5404: sub display_colorchgs {
5405: my ($dom,$changes,$roles,$confhash) = @_;
5406: my (%choices,$resulttext);
5407: if (!grep(/^login$/,@{$roles})) {
5408: $resulttext = &mt('Changes made:').'<br />';
5409: }
5410: foreach my $role (@{$roles}) {
5411: if ($role eq 'login') {
5412: %choices = &login_choices();
5413: } else {
5414: %choices = &color_font_choices();
5415: }
5416: if (ref($changes->{$role}) eq 'HASH') {
5417: if ($role ne 'login') {
5418: $resulttext .= '<h4>'.&mt($role).'</h4>';
5419: }
5420: foreach my $key (sort(keys(%{$changes->{$role}}))) {
5421: if ($role ne 'login') {
5422: $resulttext .= '<ul>';
5423: }
5424: if (ref($changes->{$role}{$key}) eq 'HASH') {
5425: if ($role ne 'login') {
5426: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
5427: }
5428: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 5429: if (($role eq 'login') && ($key eq 'showlogo')) {
5430: if ($confhash->{$role}{$key}{$item}) {
5431: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
5432: } else {
5433: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
5434: }
5435: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 5436: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
5437: } else {
1.12 raeburn 5438: my $newitem = $confhash->{$role}{$item};
5439: if ($key eq 'images') {
5440: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
5441: }
5442: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 5443: }
5444: }
5445: if ($role ne 'login') {
5446: $resulttext .= '</ul></li>';
5447: }
5448: } else {
5449: if ($confhash->{$role}{$key} eq '') {
5450: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
5451: } else {
5452: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
5453: }
5454: }
5455: if ($role ne 'login') {
5456: $resulttext .= '</ul>';
5457: }
5458: }
5459: }
5460: }
1.3 raeburn 5461: return $resulttext;
1.1 raeburn 5462: }
5463:
1.9 raeburn 5464: sub thumb_dimensions {
5465: return ('200','50');
5466: }
5467:
1.16 raeburn 5468: sub check_dimensions {
5469: my ($inputfile) = @_;
5470: my ($fullwidth,$fullheight);
5471: if ($inputfile =~ m|^[/\w.\-]+$|) {
5472: if (open(PIPE,"identify $inputfile 2>&1 |")) {
5473: my $imageinfo = <PIPE>;
5474: if (!close(PIPE)) {
5475: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
5476: }
5477: chomp($imageinfo);
5478: my ($fullsize) =
1.21 raeburn 5479: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 5480: if ($fullsize) {
5481: ($fullwidth,$fullheight) = split(/x/,$fullsize);
5482: }
5483: }
5484: }
5485: return ($fullwidth,$fullheight);
5486: }
5487:
1.9 raeburn 5488: sub check_configuser {
5489: my ($uhome,$dom,$confname,$servadm) = @_;
5490: my ($configuserok,%currroles);
5491: if ($uhome eq 'no_host') {
5492: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
5493: my $configpass = &LONCAPA::Enrollment::create_password();
5494: $configuserok =
5495: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
5496: $configpass,'','','','','',undef,$servadm);
5497: } else {
5498: $configuserok = 'ok';
5499: %currroles =
5500: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
5501: }
5502: return ($configuserok,%currroles);
5503: }
5504:
5505: sub check_authorstatus {
5506: my ($dom,$confname,%currroles) = @_;
5507: my $author_ok;
1.40 raeburn 5508: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 5509: my $start = time;
5510: my $end = 0;
5511: $author_ok =
5512: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 5513: 'au',$end,$start,'','','domconfig');
1.9 raeburn 5514: } else {
5515: $author_ok = 'ok';
5516: }
5517: return $author_ok;
5518: }
5519:
5520: sub publishlogo {
1.46 raeburn 5521: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 5522: my ($output,$fname,$logourl);
5523: if ($action eq 'upload') {
5524: $fname=$env{'form.'.$formname.'.filename'};
5525: chop($env{'form.'.$formname});
5526: } else {
5527: ($fname) = ($formname =~ /([^\/]+)$/);
5528: }
1.46 raeburn 5529: if ($savefileas ne '') {
5530: $fname = $savefileas;
5531: }
1.9 raeburn 5532: $fname=&Apache::lonnet::clean_filename($fname);
5533: # See if there is anything left
5534: unless ($fname) { return ('error: no uploaded file'); }
5535: $fname="$subdir/$fname";
1.160.6.5 raeburn 5536: my $docroot=$r->dir_config('lonDocRoot');
5537: my $filepath="$docroot/priv";
5538: my $relpath = "$dom/$confname";
1.9 raeburn 5539: my ($fnamepath,$file,$fetchthumb);
5540: $file=$fname;
5541: if ($fname=~m|/|) {
5542: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
5543: }
1.160.6.26 raeburn 5544: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 5545: my $count;
1.160.6.5 raeburn 5546: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 5547: $filepath.="/$parts[$count]";
5548: if ((-e $filepath)!=1) {
5549: mkdir($filepath,02770);
5550: }
5551: }
5552: # Check for bad extension and disallow upload
5553: if ($file=~/\.(\w+)$/ &&
5554: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
5555: $output =
1.160.6.25 raeburn 5556: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 5557: } elsif ($file=~/\.(\w+)$/ &&
5558: !defined(&Apache::loncommon::fileembstyle($1))) {
5559: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
5560: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 5561: $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 5562: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 5563: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 5564: } else {
5565: my $source = $filepath.'/'.$file;
5566: my $logfile;
5567: if (!open($logfile,">>$source".'.log')) {
1.160.6.19 raeburn 5568: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 5569: }
5570: print $logfile
5571: "\n================= Publish ".localtime()." ================\n".
5572: $env{'user.name'}.':'.$env{'user.domain'}."\n";
5573: # Save the file
5574: if (!open(FH,'>'.$source)) {
5575: &Apache::lonnet::logthis('Failed to create '.$source);
5576: return (&mt('Failed to create file'));
5577: }
5578: if ($action eq 'upload') {
5579: if (!print FH ($env{'form.'.$formname})) {
5580: &Apache::lonnet::logthis('Failed to write to '.$source);
5581: return (&mt('Failed to write file'));
5582: }
5583: } else {
5584: my $original = &Apache::lonnet::filelocation('',$formname);
5585: if(!copy($original,$source)) {
5586: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
5587: return (&mt('Failed to write file'));
5588: }
5589: }
5590: close(FH);
5591: chmod(0660, $source); # Permissions to rw-rw---.
5592:
5593: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
5594: my $copyfile=$targetdir.'/'.$file;
5595:
5596: my @parts=split(/\//,$targetdir);
5597: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
5598: for (my $count=5;$count<=$#parts;$count++) {
5599: $path.="/$parts[$count]";
5600: if (!-e $path) {
5601: print $logfile "\nCreating directory ".$path;
5602: mkdir($path,02770);
5603: }
5604: }
5605: my $versionresult;
5606: if (-e $copyfile) {
5607: $versionresult = &logo_versioning($targetdir,$file,$logfile);
5608: } else {
5609: $versionresult = 'ok';
5610: }
5611: if ($versionresult eq 'ok') {
5612: if (copy($source,$copyfile)) {
5613: print $logfile "\nCopied original source to ".$copyfile."\n";
5614: $output = 'ok';
5615: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 5616: push(@{$modified_urls},[$copyfile,$source]);
5617: my $metaoutput =
5618: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
5619: unless ($registered_cleanup) {
5620: my $handlers = $r->get_handlers('PerlCleanupHandler');
5621: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5622: $registered_cleanup=1;
5623: }
1.9 raeburn 5624: } else {
5625: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
5626: $output = &mt('Failed to copy file to RES space').", $!";
5627: }
5628: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5629: my $inputfile = $filepath.'/'.$file;
5630: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 5631: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5632: if ($fullwidth ne '' && $fullheight ne '') {
5633: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5634: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5635: system("convert -sample $thumbsize $inputfile $outfile");
5636: chmod(0660, $filepath.'/tn-'.$file);
5637: if (-e $outfile) {
5638: my $copyfile=$targetdir.'/tn-'.$file;
5639: if (copy($outfile,$copyfile)) {
5640: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 5641: my $thumb_metaoutput =
5642: &write_metadata($dom,$confname,$formname,
5643: $targetdir,'tn-'.$file,$logfile);
5644: push(@{$modified_urls},[$copyfile,$outfile]);
5645: unless ($registered_cleanup) {
5646: my $handlers = $r->get_handlers('PerlCleanupHandler');
5647: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5648: $registered_cleanup=1;
5649: }
1.16 raeburn 5650: } else {
5651: print $logfile "\nUnable to write ".$copyfile.
5652: ':'.$!."\n";
5653: }
5654: }
1.9 raeburn 5655: }
5656: }
5657: }
5658: } else {
5659: $output = $versionresult;
5660: }
5661: }
5662: return ($output,$logourl);
5663: }
5664:
5665: sub logo_versioning {
5666: my ($targetdir,$file,$logfile) = @_;
5667: my $target = $targetdir.'/'.$file;
5668: my ($maxversion,$fn,$extn,$output);
5669: $maxversion = 0;
5670: if ($file =~ /^(.+)\.(\w+)$/) {
5671: $fn=$1;
5672: $extn=$2;
5673: }
5674: opendir(DIR,$targetdir);
5675: while (my $filename=readdir(DIR)) {
5676: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
5677: $maxversion=($1>$maxversion)?$1:$maxversion;
5678: }
5679: }
5680: $maxversion++;
5681: print $logfile "\nCreating old version ".$maxversion."\n";
5682: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
5683: if (copy($target,$copyfile)) {
5684: print $logfile "Copied old target to ".$copyfile."\n";
5685: $copyfile=$copyfile.'.meta';
5686: if (copy($target.'.meta',$copyfile)) {
5687: print $logfile "Copied old target metadata to ".$copyfile."\n";
5688: $output = 'ok';
5689: } else {
5690: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
5691: $output = &mt('Failed to copy old meta').", $!, ";
5692: }
5693: } else {
5694: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
5695: $output = &mt('Failed to copy old target').", $!, ";
5696: }
5697: return $output;
5698: }
5699:
5700: sub write_metadata {
5701: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
5702: my (%metadatafields,%metadatakeys,$output);
5703: $metadatafields{'title'}=$formname;
5704: $metadatafields{'creationdate'}=time;
5705: $metadatafields{'lastrevisiondate'}=time;
5706: $metadatafields{'copyright'}='public';
5707: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
5708: $env{'user.domain'};
5709: $metadatafields{'authorspace'}=$confname.':'.$dom;
5710: $metadatafields{'domain'}=$dom;
5711: {
5712: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
5713: my $mfh;
1.155 raeburn 5714: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 5715: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 5716: unless ($_=~/\./) {
5717: my $unikey=$_;
5718: $unikey=~/^([A-Za-z]+)/;
5719: my $tag=$1;
5720: $tag=~tr/A-Z/a-z/;
5721: print $mfh "\n\<$tag";
5722: foreach (split(/\,/,$metadatakeys{$unikey})) {
5723: my $value=$metadatafields{$unikey.'.'.$_};
5724: $value=~s/\"/\'\'/g;
5725: print $mfh ' '.$_.'="'.$value.'"';
5726: }
5727: print $mfh '>'.
5728: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
5729: .'</'.$tag.'>';
5730: }
5731: }
5732: $output = 'ok';
5733: print $logfile "\nWrote metadata";
5734: close($mfh);
5735: } else {
5736: print $logfile "\nFailed to open metadata file";
1.9 raeburn 5737: $output = &mt('Could not write metadata');
5738: }
5739: }
1.155 raeburn 5740: return $output;
5741: }
5742:
5743: sub notifysubscribed {
5744: foreach my $targetsource (@{$modified_urls}){
5745: next unless (ref($targetsource) eq 'ARRAY');
5746: my ($target,$source)=@{$targetsource};
5747: if ($source ne '') {
5748: if (open(my $logfh,'>>'.$source.'.log')) {
5749: print $logfh "\nCleanup phase: Notifications\n";
5750: my @subscribed=&subscribed_hosts($target);
5751: foreach my $subhost (@subscribed) {
5752: print $logfh "\nNotifying host ".$subhost.':';
5753: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
5754: print $logfh $reply;
5755: }
5756: my @subscribedmeta=&subscribed_hosts("$target.meta");
5757: foreach my $subhost (@subscribedmeta) {
5758: print $logfh "\nNotifying host for metadata only ".$subhost.':';
5759: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
5760: $subhost);
5761: print $logfh $reply;
5762: }
5763: print $logfh "\n============ Done ============\n";
1.160 raeburn 5764: close($logfh);
1.155 raeburn 5765: }
5766: }
5767: }
5768: return OK;
5769: }
5770:
5771: sub subscribed_hosts {
5772: my ($target) = @_;
5773: my @subscribed;
5774: if (open(my $fh,"<$target.subscription")) {
5775: while (my $subline=<$fh>) {
5776: if ($subline =~ /^($match_lonid):/) {
5777: my $host = $1;
5778: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
5779: unless (grep(/^\Q$host\E$/,@subscribed)) {
5780: push(@subscribed,$host);
5781: }
5782: }
5783: }
5784: }
5785: }
5786: return @subscribed;
1.9 raeburn 5787: }
5788:
5789: sub check_switchserver {
5790: my ($dom,$confname) = @_;
5791: my ($allowed,$switchserver);
5792: my $home = &Apache::lonnet::homeserver($confname,$dom);
5793: if ($home eq 'no_host') {
5794: $home = &Apache::lonnet::domain($dom,'primary');
5795: }
5796: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 5797: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
5798: if (!$allowed) {
1.160.6.11 raeburn 5799: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 5800: }
5801: return $switchserver;
5802: }
5803:
1.1 raeburn 5804: sub modify_quotas {
1.160.6.27! raeburn 5805: my ($dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 5806: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
5807: %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86 raeburn 5808: if ($action eq 'quotas') {
5809: $context = 'tools';
1.160.6.26 raeburn 5810: } else {
1.86 raeburn 5811: $context = $action;
5812: }
5813: if ($context eq 'requestcourses') {
1.98 raeburn 5814: @usertools = ('official','unofficial','community');
1.106 raeburn 5815: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 5816: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
5817: %titles = &courserequest_titles();
5818: $toolregexp = join('|',@usertools);
5819: %conditions = &courserequest_conditions();
1.160.6.5 raeburn 5820: } elsif ($context eq 'requestauthor') {
5821: @usertools = ('author');
5822: %titles = &authorrequest_titles();
1.86 raeburn 5823: } else {
1.160.6.4 raeburn 5824: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 5825: %titles = &tool_titles();
1.86 raeburn 5826: }
1.160.6.27! raeburn 5827: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 5828: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5829: foreach my $key (keys(%env)) {
1.101 raeburn 5830: if ($context eq 'requestcourses') {
5831: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
5832: my $item = $1;
5833: my $type = $2;
5834: if ($type =~ /^limit_(.+)/) {
5835: $limithash{$item}{$1} = $env{$key};
5836: } else {
5837: $confhash{$item}{$type} = $env{$key};
5838: }
5839: }
1.160.6.5 raeburn 5840: } elsif ($context eq 'requestauthor') {
5841: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
5842: $confhash{$1} = $env{$key};
5843: }
1.101 raeburn 5844: } else {
1.86 raeburn 5845: if ($key =~ /^form\.quota_(.+)$/) {
5846: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 5847: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
5848: $confhash{'authorquota'}{$1} = $env{$key};
5849: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 5850: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
5851: }
1.72 raeburn 5852: }
5853: }
1.160.6.5 raeburn 5854: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.102 raeburn 5855: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
5856: @approvalnotify = sort(@approvalnotify);
5857: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
5858: if (ref($domconfig{$action}) eq 'HASH') {
5859: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
5860: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
5861: $changes{'notify'}{'approval'} = 1;
5862: }
5863: } else {
1.144 raeburn 5864: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5865: $changes{'notify'}{'approval'} = 1;
5866: }
5867: }
5868: } else {
1.144 raeburn 5869: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5870: $changes{'notify'}{'approval'} = 1;
5871: }
5872: }
5873: } else {
1.86 raeburn 5874: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 5875: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 5876: }
1.72 raeburn 5877: foreach my $item (@usertools) {
5878: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 5879: my $unset;
1.101 raeburn 5880: if ($context eq 'requestcourses') {
1.104 raeburn 5881: $unset = '0';
5882: if ($type eq '_LC_adv') {
5883: $unset = '';
5884: }
1.101 raeburn 5885: if ($confhash{$item}{$type} eq 'autolimit') {
5886: $confhash{$item}{$type} .= '=';
5887: unless ($limithash{$item}{$type} =~ /\D/) {
5888: $confhash{$item}{$type} .= $limithash{$item}{$type};
5889: }
5890: }
1.160.6.5 raeburn 5891: } elsif ($context eq 'requestauthor') {
5892: $unset = '0';
5893: if ($type eq '_LC_adv') {
5894: $unset = '';
5895: }
1.72 raeburn 5896: } else {
1.101 raeburn 5897: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
5898: $confhash{$item}{$type} = 1;
5899: } else {
5900: $confhash{$item}{$type} = 0;
5901: }
1.72 raeburn 5902: }
1.86 raeburn 5903: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 5904: if ($action eq 'requestauthor') {
5905: if ($domconfig{$action}{$type} ne $confhash{$type}) {
5906: $changes{$type} = 1;
5907: }
5908: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 5909: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
5910: $changes{$item}{$type} = 1;
5911: }
5912: } else {
5913: if ($context eq 'requestcourses') {
1.104 raeburn 5914: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 5915: $changes{$item}{$type} = 1;
5916: }
5917: } else {
5918: if (!$confhash{$item}{$type}) {
5919: $changes{$item}{$type} = 1;
5920: }
5921: }
5922: }
5923: } else {
5924: if ($context eq 'requestcourses') {
1.104 raeburn 5925: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 5926: $changes{$item}{$type} = 1;
5927: }
1.160.6.5 raeburn 5928: } elsif ($context eq 'requestauthor') {
5929: if ($confhash{$type} ne $unset) {
5930: $changes{$type} = 1;
5931: }
1.72 raeburn 5932: } else {
5933: if (!$confhash{$item}{$type}) {
5934: $changes{$item}{$type} = 1;
5935: }
5936: }
5937: }
1.1 raeburn 5938: }
5939: }
1.160.6.5 raeburn 5940: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 5941: if (ref($domconfig{'quotas'}) eq 'HASH') {
5942: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5943: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
5944: if (exists($confhash{'defaultquota'}{$key})) {
5945: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
5946: $changes{'defaultquota'}{$key} = 1;
5947: }
5948: } else {
5949: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 5950: }
5951: }
1.86 raeburn 5952: } else {
5953: foreach my $key (keys(%{$domconfig{'quotas'}})) {
5954: if (exists($confhash{'defaultquota'}{$key})) {
5955: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
5956: $changes{'defaultquota'}{$key} = 1;
5957: }
5958: } else {
5959: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 5960: }
1.1 raeburn 5961: }
5962: }
1.160.6.20 raeburn 5963: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
5964: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
5965: if (exists($confhash{'authorquota'}{$key})) {
5966: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
5967: $changes{'authorquota'}{$key} = 1;
5968: }
5969: } else {
5970: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
5971: }
5972: }
5973: }
1.1 raeburn 5974: }
1.86 raeburn 5975: if (ref($confhash{'defaultquota'}) eq 'HASH') {
5976: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
5977: if (ref($domconfig{'quotas'}) eq 'HASH') {
5978: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5979: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
5980: $changes{'defaultquota'}{$key} = 1;
5981: }
5982: } else {
5983: if (!exists($domconfig{'quotas'}{$key})) {
5984: $changes{'defaultquota'}{$key} = 1;
5985: }
1.72 raeburn 5986: }
5987: } else {
1.86 raeburn 5988: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 5989: }
1.1 raeburn 5990: }
5991: }
1.160.6.20 raeburn 5992: if (ref($confhash{'authorquota'}) eq 'HASH') {
5993: foreach my $key (keys(%{$confhash{'authorquota'}})) {
5994: if (ref($domconfig{'quotas'}) eq 'HASH') {
5995: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
5996: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
5997: $changes{'authorquota'}{$key} = 1;
5998: }
5999: } else {
6000: $changes{'authorquota'}{$key} = 1;
6001: }
6002: } else {
6003: $changes{'authorquota'}{$key} = 1;
6004: }
6005: }
6006: }
1.1 raeburn 6007: }
1.72 raeburn 6008:
1.160.6.5 raeburn 6009: if ($context eq 'requestauthor') {
6010: $domdefaults{'requestauthor'} = \%confhash;
6011: } else {
6012: foreach my $key (keys(%confhash)) {
6013: $domdefaults{$key} = $confhash{$key};
6014: }
1.72 raeburn 6015: }
1.160.6.5 raeburn 6016:
1.1 raeburn 6017: my %quotahash = (
1.86 raeburn 6018: $action => { %confhash }
1.1 raeburn 6019: );
6020: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
6021: $dom);
6022: if ($putresult eq 'ok') {
6023: if (keys(%changes) > 0) {
1.72 raeburn 6024: my $cachetime = 24*60*60;
6025: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27! raeburn 6026: if (ref($lastactref) eq 'HASH') {
! 6027: $lastactref->{'domdefaults'} = 1;
! 6028: }
1.1 raeburn 6029: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 6030: unless (($context eq 'requestcourses') ||
6031: ($context eq 'requestauthor')) {
1.86 raeburn 6032: if (ref($changes{'defaultquota'}) eq 'HASH') {
6033: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
6034: foreach my $type (@{$types},'default') {
6035: if (defined($changes{'defaultquota'}{$type})) {
6036: my $typetitle = $usertypes->{$type};
6037: if ($type eq 'default') {
6038: $typetitle = $othertitle;
6039: }
6040: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 6041: }
6042: }
1.86 raeburn 6043: $resulttext .= '</ul></li>';
1.72 raeburn 6044: }
1.160.6.20 raeburn 6045: if (ref($changes{'authorquota'}) eq 'HASH') {
6046: $resulttext .= '<li>'.&mt('Authoring space default quotas').'<ul>';
6047: foreach my $type (@{$types},'default') {
6048: if (defined($changes{'authorquota'}{$type})) {
6049: my $typetitle = $usertypes->{$type};
6050: if ($type eq 'default') {
6051: $typetitle = $othertitle;
6052: }
6053: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
6054: }
6055: }
6056: $resulttext .= '</ul></li>';
6057: }
1.72 raeburn 6058: }
1.80 raeburn 6059: my %newenv;
1.72 raeburn 6060: foreach my $item (@usertools) {
1.160.6.5 raeburn 6061: my (%haschgs,%inconf);
6062: if ($context eq 'requestauthor') {
6063: %haschgs = %changes;
6064: %inconf = %confhash;
6065: } else {
6066: if (ref($changes{$item}) eq 'HASH') {
6067: %haschgs = %{$changes{$item}};
6068: }
6069: if (ref($confhash{$item}) eq 'HASH') {
6070: %inconf = %{$confhash{$item}};
6071: }
6072: }
6073: if (keys(%haschgs) > 0) {
1.80 raeburn 6074: my $newacc =
6075: &Apache::lonnet::usertools_access($env{'user.name'},
6076: $env{'user.domain'},
1.86 raeburn 6077: $item,'reload',$context);
1.160.6.5 raeburn 6078: if (($context eq 'requestcourses') ||
6079: ($context eq 'requestauthor')) {
1.108 raeburn 6080: if ($env{'environment.canrequest.'.$item} ne $newacc) {
6081: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 6082: }
6083: } else {
6084: if ($env{'environment.availabletools.'.$item} ne $newacc) {
6085: $newenv{'environment.availabletools.'.$item} = $newacc;
6086: }
1.80 raeburn 6087: }
1.160.6.5 raeburn 6088: unless ($context eq 'requestauthor') {
6089: $resulttext .= '<li>'.$titles{$item}.'<ul>';
6090: }
1.72 raeburn 6091: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 6092: if ($haschgs{$type}) {
1.72 raeburn 6093: my $typetitle = $usertypes->{$type};
6094: if ($type eq 'default') {
6095: $typetitle = $othertitle;
6096: } elsif ($type eq '_LC_adv') {
6097: $typetitle = 'LON-CAPA Advanced Users';
6098: }
1.160.6.5 raeburn 6099: if ($inconf{$type}) {
1.101 raeburn 6100: if ($context eq 'requestcourses') {
6101: my $cond;
1.160.6.5 raeburn 6102: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 6103: if ($1 eq '') {
6104: $cond = &mt('(Automatic processing of any request).');
6105: } else {
6106: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
6107: }
6108: } else {
1.160.6.5 raeburn 6109: $cond = $conditions{$inconf{$type}};
1.101 raeburn 6110: }
6111: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 6112: } elsif ($context eq 'requestauthor') {
6113: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
6114: $titles{$inconf{$type}},$typetitle);
6115:
1.101 raeburn 6116: } else {
6117: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
6118: }
1.72 raeburn 6119: } else {
1.104 raeburn 6120: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 6121: if ($inconf{$type} eq '0') {
1.104 raeburn 6122: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6123: } else {
6124: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
6125: }
6126: } else {
6127: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6128: }
1.72 raeburn 6129: }
6130: }
1.26 raeburn 6131: }
1.160.6.5 raeburn 6132: unless ($context eq 'requestauthor') {
6133: $resulttext .= '</ul></li>';
6134: }
1.26 raeburn 6135: }
1.1 raeburn 6136: }
1.160.6.5 raeburn 6137: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 6138: if (ref($changes{'notify'}) eq 'HASH') {
6139: if ($changes{'notify'}{'approval'}) {
6140: if (ref($confhash{'notify'}) eq 'HASH') {
6141: if ($confhash{'notify'}{'approval'}) {
6142: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
6143: } else {
1.160.6.5 raeburn 6144: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 6145: }
6146: }
6147: }
6148: }
6149: }
1.1 raeburn 6150: $resulttext .= '</ul>';
1.80 raeburn 6151: if (keys(%newenv)) {
6152: &Apache::lonnet::appenv(\%newenv);
6153: }
1.1 raeburn 6154: } else {
1.86 raeburn 6155: if ($context eq 'requestcourses') {
6156: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 6157: } elsif ($context eq 'requestauthor') {
6158: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 6159: } else {
1.90 weissno 6160: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 6161: }
1.1 raeburn 6162: }
6163: } else {
1.11 albertel 6164: $resulttext = '<span class="LC_error">'.
6165: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6166: }
1.3 raeburn 6167: return $resulttext;
1.1 raeburn 6168: }
6169:
1.3 raeburn 6170: sub modify_autoenroll {
1.160.6.24 raeburn 6171: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 6172: my ($resulttext,%changes);
6173: my %currautoenroll;
6174: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6175: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
6176: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
6177: }
6178: }
6179: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
6180: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 6181: sender => 'Sender for notification messages',
6182: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 6183: my @offon = ('off','on');
1.17 raeburn 6184: my $sender_uname = $env{'form.sender_uname'};
6185: my $sender_domain = $env{'form.sender_domain'};
6186: if ($sender_domain eq '') {
6187: $sender_uname = '';
6188: } elsif ($sender_uname eq '') {
6189: $sender_domain = '';
6190: }
1.129 raeburn 6191: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 6192: my %autoenrollhash = (
1.129 raeburn 6193: autoenroll => { 'run' => $env{'form.autoenroll_run'},
6194: 'sender_uname' => $sender_uname,
6195: 'sender_domain' => $sender_domain,
6196: 'co-owners' => $coowners,
1.1 raeburn 6197: }
6198: );
1.4 raeburn 6199: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
6200: $dom);
1.1 raeburn 6201: if ($putresult eq 'ok') {
6202: if (exists($currautoenroll{'run'})) {
6203: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
6204: $changes{'run'} = 1;
6205: }
6206: } elsif ($autorun) {
6207: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 6208: $changes{'run'} = 1;
1.1 raeburn 6209: }
6210: }
1.17 raeburn 6211: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 6212: $changes{'sender'} = 1;
6213: }
1.17 raeburn 6214: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 6215: $changes{'sender'} = 1;
6216: }
1.129 raeburn 6217: if ($currautoenroll{'co-owners'} ne '') {
6218: if ($currautoenroll{'co-owners'} ne $coowners) {
6219: $changes{'coowners'} = 1;
6220: }
6221: } elsif ($coowners) {
6222: $changes{'coowners'} = 1;
6223: }
1.1 raeburn 6224: if (keys(%changes) > 0) {
6225: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 6226: if ($changes{'run'}) {
1.1 raeburn 6227: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
6228: }
6229: if ($changes{'sender'}) {
1.17 raeburn 6230: if ($sender_uname eq '' || $sender_domain eq '') {
6231: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
6232: } else {
6233: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
6234: }
1.1 raeburn 6235: }
1.129 raeburn 6236: if ($changes{'coowners'}) {
6237: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
6238: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27! raeburn 6239: if (ref($lastactref) eq 'HASH') {
! 6240: $lastactref->{'domainconfig'} = 1;
! 6241: }
1.129 raeburn 6242: }
1.1 raeburn 6243: $resulttext .= '</ul>';
6244: } else {
6245: $resulttext = &mt('No changes made to auto-enrollment settings');
6246: }
6247: } else {
1.11 albertel 6248: $resulttext = '<span class="LC_error">'.
6249: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6250: }
1.3 raeburn 6251: return $resulttext;
1.1 raeburn 6252: }
6253:
6254: sub modify_autoupdate {
1.3 raeburn 6255: my ($dom,%domconfig) = @_;
1.1 raeburn 6256: my ($resulttext,%currautoupdate,%fields,%changes);
6257: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
6258: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
6259: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
6260: }
6261: }
6262: my @offon = ('off','on');
6263: my %title = &Apache::lonlocal::texthash (
6264: run => 'Auto-update:',
6265: classlists => 'Updates to user information in classlists?'
6266: );
1.44 raeburn 6267: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6268: my %fieldtitles = &Apache::lonlocal::texthash (
6269: id => 'Student/Employee ID',
1.20 raeburn 6270: permanentemail => 'E-mail address',
1.1 raeburn 6271: lastname => 'Last Name',
6272: firstname => 'First Name',
6273: middlename => 'Middle Name',
1.132 raeburn 6274: generation => 'Generation',
1.1 raeburn 6275: );
1.142 raeburn 6276: $othertitle = &mt('All users');
1.1 raeburn 6277: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 6278: $othertitle = &mt('Other users');
1.1 raeburn 6279: }
6280: foreach my $key (keys(%env)) {
6281: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 6282: my ($usertype,$item) = ($1,$2);
6283: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
6284: if ($usertype eq 'default') {
6285: push(@{$fields{$1}},$2);
6286: } elsif (ref($types) eq 'ARRAY') {
6287: if (grep(/^\Q$usertype\E$/,@{$types})) {
6288: push(@{$fields{$1}},$2);
6289: }
6290: }
6291: }
1.1 raeburn 6292: }
6293: }
1.131 raeburn 6294: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
6295: @lockablenames = sort(@lockablenames);
6296: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
6297: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6298: if (@changed) {
6299: $changes{'lockablenames'} = 1;
6300: }
6301: } else {
6302: if (@lockablenames) {
6303: $changes{'lockablenames'} = 1;
6304: }
6305: }
1.1 raeburn 6306: my %updatehash = (
6307: autoupdate => { run => $env{'form.autoupdate_run'},
6308: classlists => $env{'form.classlists'},
6309: fields => {%fields},
1.131 raeburn 6310: lockablenames => \@lockablenames,
1.1 raeburn 6311: }
6312: );
6313: foreach my $key (keys(%currautoupdate)) {
6314: if (($key eq 'run') || ($key eq 'classlists')) {
6315: if (exists($updatehash{autoupdate}{$key})) {
6316: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
6317: $changes{$key} = 1;
6318: }
6319: }
6320: } elsif ($key eq 'fields') {
6321: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 6322: foreach my $item (@{$types},'default') {
1.1 raeburn 6323: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
6324: my $change = 0;
6325: foreach my $type (@{$currautoupdate{$key}{$item}}) {
6326: if (!exists($fields{$item})) {
6327: $change = 1;
1.132 raeburn 6328: last;
1.1 raeburn 6329: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 6330: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 6331: $change = 1;
1.132 raeburn 6332: last;
1.1 raeburn 6333: }
6334: }
6335: }
6336: if ($change) {
6337: push(@{$changes{$key}},$item);
6338: }
1.26 raeburn 6339: }
1.1 raeburn 6340: }
6341: }
1.131 raeburn 6342: } elsif ($key eq 'lockablenames') {
6343: if (ref($currautoupdate{$key}) eq 'ARRAY') {
6344: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6345: if (@changed) {
6346: $changes{'lockablenames'} = 1;
6347: }
6348: } else {
6349: if (@lockablenames) {
6350: $changes{'lockablenames'} = 1;
6351: }
6352: }
6353: }
6354: }
6355: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
6356: if (@lockablenames) {
6357: $changes{'lockablenames'} = 1;
1.1 raeburn 6358: }
6359: }
1.26 raeburn 6360: foreach my $item (@{$types},'default') {
6361: if (defined($fields{$item})) {
6362: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 6363: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
6364: my $change = 0;
6365: if (ref($fields{$item}) eq 'ARRAY') {
6366: foreach my $type (@{$fields{$item}}) {
6367: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
6368: $change = 1;
6369: last;
6370: }
6371: }
6372: }
6373: if ($change) {
6374: push(@{$changes{'fields'}},$item);
6375: }
6376: } else {
1.26 raeburn 6377: push(@{$changes{'fields'}},$item);
6378: }
6379: } else {
6380: push(@{$changes{'fields'}},$item);
1.1 raeburn 6381: }
6382: }
6383: }
6384: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
6385: $dom);
6386: if ($putresult eq 'ok') {
6387: if (keys(%changes) > 0) {
6388: $resulttext = &mt('Changes made:').'<ul>';
6389: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 6390: if ($key eq 'lockablenames') {
6391: $resulttext .= '<li>';
6392: if (@lockablenames) {
6393: $usertypes->{'default'} = $othertitle;
6394: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
6395: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
6396: } else {
6397: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
6398: }
6399: $resulttext .= '</li>';
6400: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 6401: foreach my $item (@{$changes{$key}}) {
6402: my @newvalues;
6403: foreach my $type (@{$fields{$item}}) {
6404: push(@newvalues,$fieldtitles{$type});
6405: }
1.3 raeburn 6406: my $newvaluestr;
6407: if (@newvalues > 0) {
6408: $newvaluestr = join(', ',@newvalues);
6409: } else {
6410: $newvaluestr = &mt('none');
1.6 raeburn 6411: }
1.1 raeburn 6412: if ($item eq 'default') {
1.26 raeburn 6413: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 6414: } else {
1.26 raeburn 6415: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 6416: }
6417: }
6418: } else {
6419: my $newvalue;
6420: if ($key eq 'run') {
6421: $newvalue = $offon[$env{'form.autoupdate_run'}];
6422: } else {
6423: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 6424: }
1.1 raeburn 6425: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
6426: }
6427: }
6428: $resulttext .= '</ul>';
6429: } else {
1.3 raeburn 6430: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 6431: }
6432: } else {
1.11 albertel 6433: $resulttext = '<span class="LC_error">'.
6434: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6435: }
1.3 raeburn 6436: return $resulttext;
1.1 raeburn 6437: }
6438:
1.125 raeburn 6439: sub modify_autocreate {
6440: my ($dom,%domconfig) = @_;
6441: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
6442: if (ref($domconfig{'autocreate'}) eq 'HASH') {
6443: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
6444: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
6445: }
6446: }
6447: my %title= ( xml => 'Auto-creation of courses in XML course description files',
6448: req => 'Auto-creation of validated requests for official courses',
6449: xmldc => 'Identity of course creator of courses from XML files',
6450: );
6451: my @types = ('xml','req');
6452: foreach my $item (@types) {
6453: $newvals{$item} = $env{'form.autocreate_'.$item};
6454: $newvals{$item} =~ s/\D//g;
6455: $newvals{$item} = 0 if ($newvals{$item} eq '');
6456: }
6457: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
6458: my %domcoords = &get_active_dcs($dom);
6459: unless (exists($domcoords{$newvals{'xmldc'}})) {
6460: $newvals{'xmldc'} = '';
6461: }
6462: %autocreatehash = (
6463: autocreate => { xml => $newvals{'xml'},
6464: req => $newvals{'req'},
6465: }
6466: );
6467: if ($newvals{'xmldc'} ne '') {
6468: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
6469: }
6470: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
6471: $dom);
6472: if ($putresult eq 'ok') {
6473: my @items = @types;
6474: if ($newvals{'xml'}) {
6475: push(@items,'xmldc');
6476: }
6477: foreach my $item (@items) {
6478: if (exists($currautocreate{$item})) {
6479: if ($currautocreate{$item} ne $newvals{$item}) {
6480: $changes{$item} = 1;
6481: }
6482: } elsif ($newvals{$item}) {
6483: $changes{$item} = 1;
6484: }
6485: }
6486: if (keys(%changes) > 0) {
6487: my @offon = ('off','on');
6488: $resulttext = &mt('Changes made:').'<ul>';
6489: foreach my $item (@types) {
6490: if ($changes{$item}) {
6491: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 6492: $resulttext .= '<li>'.
6493: &mt("$title{$item} set to [_1]$newtxt [_2]",
6494: '<b>','</b>').
6495: '</li>';
1.125 raeburn 6496: }
6497: }
6498: if ($changes{'xmldc'}) {
6499: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
6500: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 6501: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 6502: }
6503: $resulttext .= '</ul>';
6504: } else {
6505: $resulttext = &mt('No changes made to auto-creation settings');
6506: }
6507: } else {
6508: $resulttext = '<span class="LC_error">'.
6509: &mt('An error occurred: [_1]',$putresult).'</span>';
6510: }
6511: return $resulttext;
6512: }
6513:
1.23 raeburn 6514: sub modify_directorysrch {
6515: my ($dom,%domconfig) = @_;
6516: my ($resulttext,%changes);
6517: my %currdirsrch;
6518: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
6519: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
6520: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
6521: }
6522: }
6523: my %title = ( available => 'Directory search available',
1.24 raeburn 6524: localonly => 'Other domains can search',
1.23 raeburn 6525: searchby => 'Search types',
6526: searchtypes => 'Search latitude');
6527: my @offon = ('off','on');
1.24 raeburn 6528: my @otherdoms = ('Yes','No');
1.23 raeburn 6529:
1.25 raeburn 6530: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 6531: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
6532: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
6533:
1.44 raeburn 6534: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 6535: if (keys(%{$usertypes}) == 0) {
6536: @cansearch = ('default');
6537: } else {
6538: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
6539: foreach my $type (@{$currdirsrch{'cansearch'}}) {
6540: if (!grep(/^\Q$type\E$/,@cansearch)) {
6541: push(@{$changes{'cansearch'}},$type);
6542: }
1.23 raeburn 6543: }
1.26 raeburn 6544: foreach my $type (@cansearch) {
6545: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
6546: push(@{$changes{'cansearch'}},$type);
6547: }
1.23 raeburn 6548: }
1.26 raeburn 6549: } else {
6550: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 6551: }
6552: }
6553:
6554: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
6555: foreach my $by (@{$currdirsrch{'searchby'}}) {
6556: if (!grep(/^\Q$by\E$/,@searchby)) {
6557: push(@{$changes{'searchby'}},$by);
6558: }
6559: }
6560: foreach my $by (@searchby) {
6561: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
6562: push(@{$changes{'searchby'}},$by);
6563: }
6564: }
6565: } else {
6566: push(@{$changes{'searchby'}},@searchby);
6567: }
1.25 raeburn 6568:
6569: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
6570: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
6571: if (!grep(/^\Q$type\E$/,@searchtypes)) {
6572: push(@{$changes{'searchtypes'}},$type);
6573: }
6574: }
6575: foreach my $type (@searchtypes) {
6576: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
6577: push(@{$changes{'searchtypes'}},$type);
6578: }
6579: }
6580: } else {
6581: if (exists($currdirsrch{'searchtypes'})) {
6582: foreach my $type (@searchtypes) {
6583: if ($type ne $currdirsrch{'searchtypes'}) {
6584: push(@{$changes{'searchtypes'}},$type);
6585: }
6586: }
6587: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
6588: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
6589: }
6590: } else {
6591: push(@{$changes{'searchtypes'}},@searchtypes);
6592: }
6593: }
6594:
1.23 raeburn 6595: my %dirsrch_hash = (
6596: directorysrch => { available => $env{'form.dirsrch_available'},
6597: cansearch => \@cansearch,
1.24 raeburn 6598: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 6599: searchby => \@searchby,
1.25 raeburn 6600: searchtypes => \@searchtypes,
1.23 raeburn 6601: }
6602: );
6603: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
6604: $dom);
6605: if ($putresult eq 'ok') {
6606: if (exists($currdirsrch{'available'})) {
6607: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
6608: $changes{'available'} = 1;
6609: }
6610: } else {
6611: if ($env{'form.dirsrch_available'} eq '1') {
6612: $changes{'available'} = 1;
6613: }
6614: }
1.24 raeburn 6615: if (exists($currdirsrch{'localonly'})) {
6616: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
6617: $changes{'localonly'} = 1;
6618: }
6619: } else {
6620: if ($env{'form.dirsrch_localonly'} eq '1') {
6621: $changes{'localonly'} = 1;
6622: }
6623: }
1.23 raeburn 6624: if (keys(%changes) > 0) {
6625: $resulttext = &mt('Changes made:').'<ul>';
6626: if ($changes{'available'}) {
6627: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
6628: }
1.24 raeburn 6629: if ($changes{'localonly'}) {
6630: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
6631: }
6632:
1.23 raeburn 6633: if (ref($changes{'cansearch'}) eq 'ARRAY') {
6634: my $chgtext;
1.26 raeburn 6635: if (ref($usertypes) eq 'HASH') {
6636: if (keys(%{$usertypes}) > 0) {
6637: foreach my $type (@{$types}) {
6638: if (grep(/^\Q$type\E$/,@cansearch)) {
6639: $chgtext .= $usertypes->{$type}.'; ';
6640: }
6641: }
6642: if (grep(/^default$/,@cansearch)) {
6643: $chgtext .= $othertitle;
6644: } else {
6645: $chgtext =~ s/\; $//;
6646: }
1.160.6.13 raeburn 6647: $resulttext .=
6648: '<li>'.
6649: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
6650: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
6651: '</li>';
1.23 raeburn 6652: }
6653: }
6654: }
6655: if (ref($changes{'searchby'}) eq 'ARRAY') {
6656: my ($searchtitles,$titleorder) = &sorted_searchtitles();
6657: my $chgtext;
6658: foreach my $type (@{$titleorder}) {
6659: if (grep(/^\Q$type\E$/,@searchby)) {
6660: if (defined($searchtitles->{$type})) {
6661: $chgtext .= $searchtitles->{$type}.'; ';
6662: }
6663: }
6664: }
6665: $chgtext =~ s/\; $//;
6666: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
6667: }
1.25 raeburn 6668: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
6669: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
6670: my $chgtext;
6671: foreach my $type (@{$srchtypeorder}) {
6672: if (grep(/^\Q$type\E$/,@searchtypes)) {
6673: if (defined($srchtypes_desc->{$type})) {
6674: $chgtext .= $srchtypes_desc->{$type}.'; ';
6675: }
6676: }
6677: }
6678: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 6679: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 6680: }
6681: $resulttext .= '</ul>';
6682: } else {
6683: $resulttext = &mt('No changes made to institution directory search settings');
6684: }
6685: } else {
6686: $resulttext = '<span class="LC_error">'.
1.27 raeburn 6687: &mt('An error occurred: [_1]',$putresult).'</span>';
6688: }
6689: return $resulttext;
6690: }
6691:
1.28 raeburn 6692: sub modify_contacts {
1.160.6.24 raeburn 6693: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 6694: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
6695: if (ref($domconfig{'contacts'}) eq 'HASH') {
6696: foreach my $key (keys(%{$domconfig{'contacts'}})) {
6697: $currsetting{$key} = $domconfig{'contacts'}{$key};
6698: }
6699: }
1.134 raeburn 6700: my (%others,%to,%bcc);
1.28 raeburn 6701: my @contacts = ('supportemail','adminemail');
1.102 raeburn 6702: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.160.6.23 raeburn 6703: 'requestsmail','updatesmail','idconflictsmail');
6704: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 6705: foreach my $type (@mailings) {
6706: @{$newsetting{$type}} =
6707: &Apache::loncommon::get_env_multiple('form.'.$type);
6708: foreach my $item (@contacts) {
6709: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
6710: $contacts_hash{contacts}{$type}{$item} = 1;
6711: } else {
6712: $contacts_hash{contacts}{$type}{$item} = 0;
6713: }
6714: }
6715: $others{$type} = $env{'form.'.$type.'_others'};
6716: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 6717: if ($type eq 'helpdeskmail') {
6718: $bcc{$type} = $env{'form.'.$type.'_bcc'};
6719: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
6720: }
1.28 raeburn 6721: }
6722: foreach my $item (@contacts) {
6723: $to{$item} = $env{'form.'.$item};
6724: $contacts_hash{'contacts'}{$item} = $to{$item};
6725: }
1.160.6.23 raeburn 6726: foreach my $item (@toggles) {
6727: if ($env{'form.'.$item} =~ /^(0|1)$/) {
6728: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
6729: }
6730: }
1.28 raeburn 6731: if (keys(%currsetting) > 0) {
6732: foreach my $item (@contacts) {
6733: if ($to{$item} ne $currsetting{$item}) {
6734: $changes{$item} = 1;
6735: }
6736: }
6737: foreach my $type (@mailings) {
6738: foreach my $item (@contacts) {
6739: if (ref($currsetting{$type}) eq 'HASH') {
6740: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
6741: push(@{$changes{$type}},$item);
6742: }
6743: } else {
6744: push(@{$changes{$type}},@{$newsetting{$type}});
6745: }
6746: }
6747: if ($others{$type} ne $currsetting{$type}{'others'}) {
6748: push(@{$changes{$type}},'others');
6749: }
1.134 raeburn 6750: if ($type eq 'helpdeskmail') {
6751: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
6752: push(@{$changes{$type}},'bcc');
6753: }
6754: }
1.28 raeburn 6755: }
6756: } else {
6757: my %default;
6758: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
6759: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
6760: $default{'errormail'} = 'adminemail';
6761: $default{'packagesmail'} = 'adminemail';
6762: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 6763: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 6764: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 6765: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 6766: foreach my $item (@contacts) {
6767: if ($to{$item} ne $default{$item}) {
6768: $changes{$item} = 1;
1.160.6.23 raeburn 6769: }
1.28 raeburn 6770: }
6771: foreach my $type (@mailings) {
6772: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
6773:
6774: push(@{$changes{$type}},@{$newsetting{$type}});
6775: }
6776: if ($others{$type} ne '') {
6777: push(@{$changes{$type}},'others');
1.134 raeburn 6778: }
6779: if ($type eq 'helpdeskmail') {
6780: if ($bcc{$type} ne '') {
6781: push(@{$changes{$type}},'bcc');
6782: }
6783: }
1.28 raeburn 6784: }
6785: }
1.160.6.23 raeburn 6786: foreach my $item (@toggles) {
6787: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
6788: $changes{$item} = 1;
6789: } elsif ((!$env{'form.'.$item}) &&
6790: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
6791: $changes{$item} = 1;
6792: }
6793: }
1.28 raeburn 6794: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
6795: $dom);
6796: if ($putresult eq 'ok') {
6797: if (keys(%changes) > 0) {
1.160.6.24 raeburn 6798: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27! raeburn 6799: if (ref($lastactref) eq 'HASH') {
! 6800: $lastactref->{'domainconfig'} = 1;
! 6801: }
1.28 raeburn 6802: my ($titles,$short_titles) = &contact_titles();
6803: $resulttext = &mt('Changes made:').'<ul>';
6804: foreach my $item (@contacts) {
6805: if ($changes{$item}) {
6806: $resulttext .= '<li>'.$titles->{$item}.
6807: &mt(' set to: ').
6808: '<span class="LC_cusr_emph">'.
6809: $to{$item}.'</span></li>';
6810: }
6811: }
6812: foreach my $type (@mailings) {
6813: if (ref($changes{$type}) eq 'ARRAY') {
6814: $resulttext .= '<li>'.$titles->{$type}.': ';
6815: my @text;
6816: foreach my $item (@{$newsetting{$type}}) {
6817: push(@text,$short_titles->{$item});
6818: }
6819: if ($others{$type} ne '') {
6820: push(@text,$others{$type});
6821: }
6822: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 6823: join(', ',@text).'</span>';
6824: if ($type eq 'helpdeskmail') {
6825: if ($bcc{$type} ne '') {
6826: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
6827: }
6828: }
6829: $resulttext .= '</li>';
1.28 raeburn 6830: }
6831: }
1.160.6.23 raeburn 6832: my @offon = ('off','on');
6833: if ($changes{'reporterrors'}) {
6834: $resulttext .= '<li>'.
6835: &mt('E-mail error reports to [_1] set to "'.
6836: $offon[$env{'form.reporterrors'}].'".',
6837: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
6838: &mt('LON-CAPA core group - MSU'),600,500)).
6839: '</li>';
6840: }
6841: if ($changes{'reportupdates'}) {
6842: $resulttext .= '<li>'.
6843: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
6844: $offon[$env{'form.reportupdates'}].'".',
6845: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
6846: &mt('LON-CAPA core group - MSU'),600,500)).
6847: '</li>';
6848: }
1.28 raeburn 6849: $resulttext .= '</ul>';
6850: } else {
1.34 raeburn 6851: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 6852: }
6853: } else {
6854: $resulttext = '<span class="LC_error">'.
6855: &mt('An error occurred: [_1].',$putresult).'</span>';
6856: }
6857: return $resulttext;
6858: }
6859:
6860: sub modify_usercreation {
1.27 raeburn 6861: my ($dom,%domconfig) = @_;
1.34 raeburn 6862: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 6863: my $warningmsg;
1.27 raeburn 6864: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6865: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
6866: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
6867: }
6868: }
6869: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 6870: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 6871: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 6872: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 6873: foreach my $item(@contexts) {
1.45 raeburn 6874: if ($item eq 'selfcreate') {
1.50 raeburn 6875: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.160.6.27! raeburn 6876: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.43 raeburn 6877: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 6878: if (ref($cancreate{$item}) eq 'ARRAY') {
6879: if (grep(/^login$/,@{$cancreate{$item}})) {
6880: $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.');
6881: }
1.43 raeburn 6882: }
6883: }
1.50 raeburn 6884: } else {
6885: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 6886: }
1.34 raeburn 6887: }
1.93 raeburn 6888: my ($othertitle,$usertypes,$types) =
6889: &Apache::loncommon::sorted_inst_types($dom);
6890: if (ref($types) eq 'ARRAY') {
6891: if (@{$types} > 0) {
6892: @{$cancreate{'statustocreate'}} =
6893: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 raeburn 6894: } else {
6895: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 6896: }
6897: push(@contexts,'statustocreate');
6898: }
1.160.6.5 raeburn 6899: &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
1.34 raeburn 6900: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
6901: foreach my $item (@contexts) {
1.93 raeburn 6902: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
6903: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 6904: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 raeburn 6905: if (ref($cancreate{$item}) eq 'ARRAY') {
6906: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
6907: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6908: push(@{$changes{'cancreate'}},$item);
6909: }
1.50 raeburn 6910: }
6911: }
6912: }
6913: } else {
6914: if ($curr_usercreation{'cancreate'}{$item} eq '') {
6915: if (@{$cancreate{$item}} > 0) {
6916: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6917: push(@{$changes{'cancreate'}},$item);
6918: }
6919: }
6920: } else {
6921: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
6922: if (@{$cancreate{$item}} < 3) {
6923: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6924: push(@{$changes{'cancreate'}},$item);
6925: }
6926: }
6927: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
6928: if (@{$cancreate{$item}} > 0) {
6929: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6930: push(@{$changes{'cancreate'}},$item);
6931: }
6932: }
6933: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
6934: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6935: push(@{$changes{'cancreate'}},$item);
6936: }
6937: }
6938: }
6939: }
6940: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6941: foreach my $type (@{$cancreate{$item}}) {
6942: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
6943: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
6944: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6945: push(@{$changes{'cancreate'}},$item);
6946: }
6947: }
6948: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
6949: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
6950: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
6951: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6952: push(@{$changes{'cancreate'}},$item);
6953: }
6954: }
6955: }
6956: }
6957: }
6958: } else {
6959: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
6960: push(@{$changes{'cancreate'}},$item);
6961: }
6962: }
1.27 raeburn 6963: }
1.34 raeburn 6964: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
6965: foreach my $item (@contexts) {
1.43 raeburn 6966: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 6967: if ($cancreate{$item} ne 'any') {
6968: push(@{$changes{'cancreate'}},$item);
6969: }
6970: } else {
6971: if ($cancreate{$item} ne 'none') {
6972: push(@{$changes{'cancreate'}},$item);
6973: }
1.27 raeburn 6974: }
6975: }
6976: } else {
1.43 raeburn 6977: foreach my $item (@contexts) {
1.34 raeburn 6978: push(@{$changes{'cancreate'}},$item);
6979: }
1.27 raeburn 6980: }
1.34 raeburn 6981:
1.27 raeburn 6982: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
6983: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
6984: if (!grep(/^\Q$type\E$/,@username_rule)) {
6985: push(@{$changes{'username_rule'}},$type);
6986: }
6987: }
6988: foreach my $type (@username_rule) {
6989: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
6990: push(@{$changes{'username_rule'}},$type);
6991: }
6992: }
6993: } else {
6994: push(@{$changes{'username_rule'}},@username_rule);
6995: }
6996:
1.32 raeburn 6997: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
6998: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
6999: if (!grep(/^\Q$type\E$/,@id_rule)) {
7000: push(@{$changes{'id_rule'}},$type);
7001: }
7002: }
7003: foreach my $type (@id_rule) {
7004: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
7005: push(@{$changes{'id_rule'}},$type);
7006: }
7007: }
7008: } else {
7009: push(@{$changes{'id_rule'}},@id_rule);
7010: }
7011:
1.43 raeburn 7012: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
7013: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
7014: if (!grep(/^\Q$type\E$/,@email_rule)) {
7015: push(@{$changes{'email_rule'}},$type);
7016: }
7017: }
7018: foreach my $type (@email_rule) {
7019: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
7020: push(@{$changes{'email_rule'}},$type);
7021: }
7022: }
7023: } else {
7024: push(@{$changes{'email_rule'}},@email_rule);
7025: }
7026:
7027: my @authen_contexts = ('author','course','domain');
1.28 raeburn 7028: my @authtypes = ('int','krb4','krb5','loc');
7029: my %authhash;
1.43 raeburn 7030: foreach my $item (@authen_contexts) {
1.28 raeburn 7031: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
7032: foreach my $auth (@authtypes) {
7033: if (grep(/^\Q$auth\E$/,@authallowed)) {
7034: $authhash{$item}{$auth} = 1;
7035: } else {
7036: $authhash{$item}{$auth} = 0;
7037: }
7038: }
7039: }
7040: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 7041: foreach my $item (@authen_contexts) {
1.28 raeburn 7042: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
7043: foreach my $auth (@authtypes) {
7044: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
7045: push(@{$changes{'authtypes'}},$item);
7046: last;
7047: }
7048: }
7049: }
7050: }
7051: } else {
1.43 raeburn 7052: foreach my $item (@authen_contexts) {
1.28 raeburn 7053: push(@{$changes{'authtypes'}},$item);
7054: }
7055: }
7056:
1.27 raeburn 7057: my %usercreation_hash = (
1.28 raeburn 7058: usercreation => {
1.34 raeburn 7059: cancreate => \%cancreate,
1.27 raeburn 7060: username_rule => \@username_rule,
1.32 raeburn 7061: id_rule => \@id_rule,
1.43 raeburn 7062: email_rule => \@email_rule,
1.32 raeburn 7063: authtypes => \%authhash,
1.27 raeburn 7064: }
7065: );
7066:
7067: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
7068: $dom);
1.50 raeburn 7069:
7070: my %selfcreatetypes = (
7071: sso => 'users authenticated by institutional single sign on',
7072: login => 'users authenticated by institutional log-in',
7073: email => 'users who provide a valid e-mail address for use as the username',
7074: );
1.27 raeburn 7075: if ($putresult eq 'ok') {
7076: if (keys(%changes) > 0) {
7077: $resulttext = &mt('Changes made:').'<ul>';
7078: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 7079: my %lt = &usercreation_types();
7080: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 7081: my $chgtext;
1.160.6.5 raeburn 7082: unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
1.100 raeburn 7083: $chgtext = $lt{$type}.', ';
7084: }
1.45 raeburn 7085: if ($type eq 'selfcreate') {
1.50 raeburn 7086: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 7087: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 7088: } else {
1.100 raeburn 7089: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 7090: foreach my $case (@{$cancreate{$type}}) {
7091: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
7092: }
7093: $chgtext .= '</ul>';
1.100 raeburn 7094: if (ref($cancreate{$type}) eq 'ARRAY') {
7095: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
7096: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
7097: if (@{$cancreate{'statustocreate'}} == 0) {
7098: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
7099: }
7100: }
7101: }
7102: }
1.43 raeburn 7103: }
1.93 raeburn 7104: } elsif ($type eq 'statustocreate') {
1.96 raeburn 7105: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
7106: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
7107: if (@{$cancreate{'selfcreate'}} > 0) {
7108: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 7109:
7110: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 7111: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 7112: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
7113: }
1.96 raeburn 7114: } elsif (ref($usertypes) eq 'HASH') {
7115: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 7116: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
7117: } else {
7118: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
7119: }
7120: $chgtext .= '<ul>';
7121: foreach my $case (@{$cancreate{$type}}) {
7122: if ($case eq 'default') {
7123: $chgtext .= '<li>'.$othertitle.'</li>';
7124: } else {
7125: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 7126: }
7127: }
1.100 raeburn 7128: $chgtext .= '</ul>';
7129: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
7130: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
7131: }
7132: }
7133: } else {
7134: if (@{$cancreate{$type}} == 0) {
7135: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
7136: } else {
7137: $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 7138: }
7139: }
7140: }
1.160.6.5 raeburn 7141: } elsif ($type eq 'captcha') {
7142: if ($cancreate{$type} eq 'notused') {
7143: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
7144: } else {
7145: my %captchas = &captcha_phrases();
7146: if ($captchas{$cancreate{$type}}) {
7147: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
7148: } else {
7149: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
7150: }
7151: }
7152: } elsif ($type eq 'recaptchakeys') {
7153: my ($privkey,$pubkey);
7154: if (ref($cancreate{$type}) eq 'HASH') {
7155: $pubkey = $cancreate{$type}{'public'};
7156: $privkey = $cancreate{$type}{'private'};
7157: }
7158: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
7159: if (!$pubkey) {
7160: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
7161: } else {
7162: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7163: }
7164: if (!$privkey) {
7165: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
7166: } else {
7167: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
7168: }
7169: $chgtext .= '</ul>';
1.43 raeburn 7170: } else {
7171: if ($cancreate{$type} eq 'none') {
7172: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
7173: } elsif ($cancreate{$type} eq 'any') {
7174: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
7175: } elsif ($cancreate{$type} eq 'official') {
7176: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
7177: } elsif ($cancreate{$type} eq 'unofficial') {
7178: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
7179: }
1.34 raeburn 7180: }
7181: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 7182: }
7183: }
7184: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 7185: my ($rules,$ruleorder) =
7186: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 7187: my $chgtext = '<ul>';
7188: foreach my $type (@username_rule) {
7189: if (ref($rules->{$type}) eq 'HASH') {
7190: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
7191: }
7192: }
7193: $chgtext .= '</ul>';
7194: if (@username_rule > 0) {
7195: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7196: } else {
1.28 raeburn 7197: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 7198: }
7199: }
1.32 raeburn 7200: if (ref($changes{'id_rule'}) eq 'ARRAY') {
7201: my ($idrules,$idruleorder) =
7202: &Apache::lonnet::inst_userrules($dom,'id');
7203: my $chgtext = '<ul>';
7204: foreach my $type (@id_rule) {
7205: if (ref($idrules->{$type}) eq 'HASH') {
7206: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
7207: }
7208: }
7209: $chgtext .= '</ul>';
7210: if (@id_rule > 0) {
7211: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7212: } else {
7213: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
7214: }
7215: }
1.43 raeburn 7216: if (ref($changes{'email_rule'}) eq 'ARRAY') {
7217: my ($emailrules,$emailruleorder) =
7218: &Apache::lonnet::inst_userrules($dom,'email');
7219: my $chgtext = '<ul>';
7220: foreach my $type (@email_rule) {
7221: if (ref($emailrules->{$type}) eq 'HASH') {
7222: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
7223: }
7224: }
7225: $chgtext .= '</ul>';
7226: if (@email_rule > 0) {
7227: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
7228: } else {
7229: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
7230: }
7231: }
7232:
1.28 raeburn 7233: my %authname = &authtype_names();
7234: my %context_title = &context_names();
7235: if (ref($changes{'authtypes'}) eq 'ARRAY') {
7236: my $chgtext = '<ul>';
7237: foreach my $type (@{$changes{'authtypes'}}) {
7238: my @allowed;
7239: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
7240: foreach my $auth (@authtypes) {
7241: if ($authhash{$type}{$auth}) {
7242: push(@allowed,$authname{$auth});
7243: }
7244: }
1.43 raeburn 7245: if (@allowed > 0) {
7246: $chgtext .= join(', ',@allowed).'</li>';
7247: } else {
7248: $chgtext .= &mt('none').'</li>';
7249: }
1.28 raeburn 7250: }
7251: $chgtext .= '</ul>';
7252: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
7253: $resulttext .= '</li>';
7254: }
1.27 raeburn 7255: $resulttext .= '</ul>';
7256: } else {
1.28 raeburn 7257: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 7258: }
7259: } else {
7260: $resulttext = '<span class="LC_error">'.
1.23 raeburn 7261: &mt('An error occurred: [_1]',$putresult).'</span>';
7262: }
1.43 raeburn 7263: if ($warningmsg ne '') {
7264: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
7265: }
1.23 raeburn 7266: return $resulttext;
7267: }
7268:
1.160.6.5 raeburn 7269: sub process_captcha {
7270: my ($container,$changes,$newsettings,$current) = @_;
7271: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
7272: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
7273: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
7274: $newsettings->{'captcha'} = 'original';
7275: }
7276: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
7277: if ($container eq 'cancreate') {
7278: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7279: push(@{$changes->{'cancreate'}},'captcha');
7280: } elsif (!defined($changes->{'cancreate'})) {
7281: $changes->{'cancreate'} = ['captcha'];
7282: }
7283: } else {
7284: $changes->{'captcha'} = 1;
7285: }
7286: }
7287: my ($newpub,$newpriv,$currpub,$currpriv);
7288: if ($newsettings->{'captcha'} eq 'recaptcha') {
7289: $newpub = $env{'form.'.$container.'_recaptchapub'};
7290: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
7291: $newpub =~ s/\W//g;
7292: $newpriv =~ s/\W//g;
7293: $newsettings->{'recaptchakeys'} = {
7294: public => $newpub,
7295: private => $newpriv,
7296: };
7297: }
7298: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
7299: $currpub = $current->{'recaptchakeys'}{'public'};
7300: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 7301: unless ($newsettings->{'captcha'} eq 'recaptcha') {
7302: $newsettings->{'recaptchakeys'} = {
7303: public => '',
7304: private => '',
7305: }
7306: }
1.160.6.5 raeburn 7307: }
7308: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
7309: if ($container eq 'cancreate') {
7310: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7311: push(@{$changes->{'cancreate'}},'recaptchakeys');
7312: } elsif (!defined($changes->{'cancreate'})) {
7313: $changes->{'cancreate'} = ['recaptchakeys'];
7314: }
7315: } else {
7316: $changes->{'recaptchakeys'} = 1;
7317: }
7318: }
7319: return;
7320: }
7321:
1.33 raeburn 7322: sub modify_usermodification {
7323: my ($dom,%domconfig) = @_;
7324: my ($resulttext,%curr_usermodification,%changes);
7325: if (ref($domconfig{'usermodification'}) eq 'HASH') {
7326: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
7327: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
7328: }
7329: }
1.63 raeburn 7330: my @contexts = ('author','course','selfcreate');
1.33 raeburn 7331: my %context_title = (
7332: author => 'In author context',
7333: course => 'In course context',
1.63 raeburn 7334: selfcreate => 'When self creating account',
1.33 raeburn 7335: );
7336: my @fields = ('lastname','firstname','middlename','generation',
7337: 'permanentemail','id');
7338: my %roles = (
7339: author => ['ca','aa'],
7340: course => ['st','ep','ta','in','cr'],
7341: );
1.63 raeburn 7342: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7343: if (ref($types) eq 'ARRAY') {
7344: push(@{$types},'default');
7345: $usertypes->{'default'} = $othertitle;
7346: }
7347: $roles{'selfcreate'} = $types;
1.33 raeburn 7348: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7349: my %modifyhash;
7350: foreach my $context (@contexts) {
7351: foreach my $role (@{$roles{$context}}) {
7352: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
7353: foreach my $item (@fields) {
7354: if (grep(/^\Q$item\E$/,@modifiable)) {
7355: $modifyhash{$context}{$role}{$item} = 1;
7356: } else {
7357: $modifyhash{$context}{$role}{$item} = 0;
7358: }
7359: }
7360: }
7361: if (ref($curr_usermodification{$context}) eq 'HASH') {
7362: foreach my $role (@{$roles{$context}}) {
7363: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
7364: foreach my $field (@fields) {
7365: if ($modifyhash{$context}{$role}{$field} ne
7366: $curr_usermodification{$context}{$role}{$field}) {
7367: push(@{$changes{$context}},$role);
7368: last;
7369: }
7370: }
7371: }
7372: }
7373: } else {
7374: foreach my $context (@contexts) {
7375: foreach my $role (@{$roles{$context}}) {
7376: push(@{$changes{$context}},$role);
7377: }
7378: }
7379: }
7380: }
7381: my %usermodification_hash = (
7382: usermodification => \%modifyhash,
7383: );
7384: my $putresult = &Apache::lonnet::put_dom('configuration',
7385: \%usermodification_hash,$dom);
7386: if ($putresult eq 'ok') {
7387: if (keys(%changes) > 0) {
7388: $resulttext = &mt('Changes made: ').'<ul>';
7389: foreach my $context (@contexts) {
7390: if (ref($changes{$context}) eq 'ARRAY') {
7391: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
7392: if (ref($changes{$context}) eq 'ARRAY') {
7393: foreach my $role (@{$changes{$context}}) {
7394: my $rolename;
1.63 raeburn 7395: if ($context eq 'selfcreate') {
7396: $rolename = $role;
7397: if (ref($usertypes) eq 'HASH') {
7398: if ($usertypes->{$role} ne '') {
7399: $rolename = $usertypes->{$role};
7400: }
7401: }
1.33 raeburn 7402: } else {
1.63 raeburn 7403: if ($role eq 'cr') {
7404: $rolename = &mt('Custom');
7405: } else {
7406: $rolename = &Apache::lonnet::plaintext($role);
7407: }
1.33 raeburn 7408: }
7409: my @modifiable;
1.63 raeburn 7410: if ($context eq 'selfcreate') {
1.126 bisitz 7411: $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 7412: } else {
7413: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
7414: }
1.33 raeburn 7415: foreach my $field (@fields) {
7416: if ($modifyhash{$context}{$role}{$field}) {
7417: push(@modifiable,$fieldtitles{$field});
7418: }
7419: }
7420: if (@modifiable > 0) {
7421: $resulttext .= join(', ',@modifiable);
7422: } else {
7423: $resulttext .= &mt('none');
7424: }
7425: $resulttext .= '</li>';
7426: }
7427: $resulttext .= '</ul></li>';
7428: }
7429: }
7430: }
7431: $resulttext .= '</ul>';
7432: } else {
7433: $resulttext = &mt('No changes made to user modification settings');
7434: }
7435: } else {
7436: $resulttext = '<span class="LC_error">'.
7437: &mt('An error occurred: [_1]',$putresult).'</span>';
7438: }
7439: return $resulttext;
7440: }
7441:
1.43 raeburn 7442: sub modify_defaults {
1.160.6.27! raeburn 7443: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 7444: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27! raeburn 7445: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 7446: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 7447: my @authtypes = ('internal','krb4','krb5','localauth');
7448: foreach my $item (@items) {
7449: $newvalues{$item} = $env{'form.'.$item};
7450: if ($item eq 'auth_def') {
7451: if ($newvalues{$item} ne '') {
7452: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
7453: push(@errors,$item);
7454: }
7455: }
7456: } elsif ($item eq 'lang_def') {
7457: if ($newvalues{$item} ne '') {
7458: if ($newvalues{$item} =~ /^(\w+)/) {
7459: my $langcode = $1;
1.103 raeburn 7460: if ($langcode ne 'x_chef') {
7461: if (code2language($langcode) eq '') {
7462: push(@errors,$item);
7463: }
1.43 raeburn 7464: }
7465: } else {
7466: push(@errors,$item);
7467: }
7468: }
1.54 raeburn 7469: } elsif ($item eq 'timezone_def') {
7470: if ($newvalues{$item} ne '') {
1.62 raeburn 7471: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 7472: push(@errors,$item);
7473: }
7474: }
1.68 raeburn 7475: } elsif ($item eq 'datelocale_def') {
7476: if ($newvalues{$item} ne '') {
7477: my @datelocale_ids = DateTime::Locale->ids();
7478: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
7479: push(@errors,$item);
7480: }
7481: }
1.141 raeburn 7482: } elsif ($item eq 'portal_def') {
7483: if ($newvalues{$item} ne '') {
7484: 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])\/?$/) {
7485: push(@errors,$item);
7486: }
7487: }
1.43 raeburn 7488: }
7489: if (grep(/^\Q$item\E$/,@errors)) {
7490: $newvalues{$item} = $domdefaults{$item};
7491: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
7492: $changes{$item} = 1;
7493: }
1.72 raeburn 7494: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 7495: }
7496: my %defaults_hash = (
1.72 raeburn 7497: defaults => \%newvalues,
7498: );
1.43 raeburn 7499: my $title = &defaults_titles();
7500: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
7501: $dom);
7502: if ($putresult eq 'ok') {
7503: if (keys(%changes) > 0) {
7504: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27! raeburn 7505: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 7506: 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";
7507: foreach my $item (sort(keys(%changes))) {
7508: my $value = $env{'form.'.$item};
7509: if ($value eq '') {
7510: $value = &mt('none');
7511: } elsif ($item eq 'auth_def') {
7512: my %authnames = &authtype_names();
7513: my %shortauth = (
7514: internal => 'int',
7515: krb4 => 'krb4',
7516: krb5 => 'krb5',
7517: localauth => 'loc',
7518: );
7519: $value = $authnames{$shortauth{$value}};
7520: }
7521: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
7522: $mailmsgtext .= "$title->{$item} set to $value\n";
7523: }
7524: $resulttext .= '</ul>';
7525: $mailmsgtext .= "\n";
7526: my $cachetime = 24*60*60;
1.72 raeburn 7527: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27! raeburn 7528: if (ref($lastactref) eq 'HASH') {
! 7529: $lastactref->{'domdefaults'} = 1;
! 7530: }
1.68 raeburn 7531: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 7532: my $notify = 1;
7533: if (ref($domconfig{'contacts'}) eq 'HASH') {
7534: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
7535: $notify = 0;
7536: }
7537: }
7538: if ($notify) {
7539: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
7540: "LON-CAPA Domain Settings Change - $dom",
7541: $mailmsgtext);
7542: }
1.54 raeburn 7543: }
1.43 raeburn 7544: } else {
1.54 raeburn 7545: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 7546: }
7547: } else {
7548: $resulttext = '<span class="LC_error">'.
7549: &mt('An error occurred: [_1]',$putresult).'</span>';
7550: }
7551: if (@errors > 0) {
7552: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
7553: foreach my $item (@errors) {
7554: $resulttext .= ' "'.$title->{$item}.'",';
7555: }
7556: $resulttext =~ s/,$//;
7557: }
7558: return $resulttext;
7559: }
7560:
1.46 raeburn 7561: sub modify_scantron {
1.160.6.24 raeburn 7562: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 7563: my ($resulttext,%confhash,%changes,$errors);
7564: my $custom = 'custom.tab';
7565: my $default = 'default.tab';
7566: my $servadm = $r->dir_config('lonAdmEMail');
7567: my ($configuserok,$author_ok,$switchserver) =
7568: &config_check($dom,$confname,$servadm);
7569: if ($env{'form.scantronformat.filename'} ne '') {
7570: my $error;
7571: if ($configuserok eq 'ok') {
7572: if ($switchserver) {
1.130 raeburn 7573: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 7574: } else {
7575: if ($author_ok eq 'ok') {
7576: my ($result,$scantronurl) =
7577: &publishlogo($r,'upload','scantronformat',$dom,
7578: $confname,'scantron','','',$custom);
7579: if ($result eq 'ok') {
7580: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 7581: $changes{'scantronformat'} = 1;
1.46 raeburn 7582: } else {
7583: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
7584: }
7585: } else {
7586: $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);
7587: }
7588: }
7589: } else {
7590: $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);
7591: }
7592: if ($error) {
7593: &Apache::lonnet::logthis($error);
7594: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7595: }
7596: }
1.48 raeburn 7597: if (ref($domconfig{'scantron'}) eq 'HASH') {
7598: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
7599: if ($env{'form.scantronformat_del'}) {
7600: $confhash{'scantron'}{'scantronformat'} = '';
7601: $changes{'scantronformat'} = 1;
1.46 raeburn 7602: }
7603: }
7604: }
7605: if (keys(%confhash) > 0) {
7606: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
7607: $dom);
7608: if ($putresult eq 'ok') {
7609: if (keys(%changes) > 0) {
1.48 raeburn 7610: if (ref($confhash{'scantron'}) eq 'HASH') {
7611: $resulttext = &mt('Changes made:').'<ul>';
7612: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 7613: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 7614: } else {
1.130 raeburn 7615: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 7616: }
1.48 raeburn 7617: $resulttext .= '</ul>';
7618: } else {
1.130 raeburn 7619: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 7620: }
7621: $resulttext .= '</ul>';
7622: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27! raeburn 7623: if (ref($lastactref) eq 'HASH') {
! 7624: $lastactref->{'domainconfig'} = 1;
! 7625: }
1.46 raeburn 7626: } else {
1.130 raeburn 7627: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7628: }
7629: } else {
7630: $resulttext = '<span class="LC_error">'.
7631: &mt('An error occurred: [_1]',$putresult).'</span>';
7632: }
7633: } else {
1.130 raeburn 7634: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7635: }
7636: if ($errors) {
7637: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7638: $errors.'</ul>';
7639: }
7640: return $resulttext;
7641: }
7642:
1.48 raeburn 7643: sub modify_coursecategories {
7644: my ($dom,%domconfig) = @_;
1.57 raeburn 7645: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
7646: $cathash);
1.48 raeburn 7647: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 7648: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 7649: $cathash = $domconfig{'coursecategories'}{'cats'};
7650: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
7651: $changes{'togglecats'} = 1;
7652: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
7653: }
7654: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
7655: $changes{'categorize'} = 1;
7656: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
7657: }
1.120 raeburn 7658: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
7659: $changes{'togglecatscomm'} = 1;
7660: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
7661: }
7662: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
7663: $changes{'categorizecomm'} = 1;
7664: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
7665: }
1.57 raeburn 7666: } else {
7667: $changes{'togglecats'} = 1;
7668: $changes{'categorize'} = 1;
1.124 raeburn 7669: $changes{'togglecatscomm'} = 1;
7670: $changes{'categorizecomm'} = 1;
1.87 raeburn 7671: $domconfig{'coursecategories'} = {
7672: togglecats => $env{'form.togglecats'},
7673: categorize => $env{'form.categorize'},
1.124 raeburn 7674: togglecatscomm => $env{'form.togglecatscomm'},
7675: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 7676: };
1.57 raeburn 7677: }
7678: if (ref($cathash) eq 'HASH') {
7679: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 7680: push (@deletecategory,'instcode::0');
7681: }
1.120 raeburn 7682: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
7683: push(@deletecategory,'communities::0');
7684: }
1.48 raeburn 7685: }
1.57 raeburn 7686: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
7687: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7688: if (@deletecategory > 0) {
7689: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 7690: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 7691: foreach my $item (@deletecategory) {
1.57 raeburn 7692: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
7693: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 7694: $deletions{$item} = 1;
1.57 raeburn 7695: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 7696: }
7697: }
7698: }
1.57 raeburn 7699: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 7700: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 7701: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 7702: $reorderings{$item} = 1;
1.57 raeburn 7703: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 7704: }
7705: if ($env{'form.addcategory_name_'.$item} ne '') {
7706: my $newcat = $env{'form.addcategory_name_'.$item};
7707: my $newdepth = $depth+1;
7708: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7709: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 7710: $adds{$newitem} = 1;
7711: }
7712: if ($env{'form.subcat_'.$item} ne '') {
7713: my $newcat = $env{'form.subcat_'.$item};
7714: my $newdepth = $depth+1;
7715: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7716: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 7717: $adds{$newitem} = 1;
7718: }
7719: }
7720: }
7721: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 7722: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7723: my $newitem = 'instcode::0';
1.57 raeburn 7724: if ($cathash->{$newitem} eq '') {
7725: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7726: $adds{$newitem} = 1;
7727: }
7728: } else {
7729: my $newitem = 'instcode::0';
1.57 raeburn 7730: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7731: $adds{$newitem} = 1;
7732: }
7733: }
1.120 raeburn 7734: if ($env{'form.communities'} eq '1') {
7735: if (ref($cathash) eq 'HASH') {
7736: my $newitem = 'communities::0';
7737: if ($cathash->{$newitem} eq '') {
7738: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7739: $adds{$newitem} = 1;
7740: }
7741: } else {
7742: my $newitem = 'communities::0';
7743: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7744: $adds{$newitem} = 1;
7745: }
7746: }
1.48 raeburn 7747: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 7748: if (($env{'form.addcategory_name'} ne 'instcode') &&
7749: ($env{'form.addcategory_name'} ne 'communities')) {
7750: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
7751: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
7752: $adds{$newitem} = 1;
7753: }
1.48 raeburn 7754: }
1.57 raeburn 7755: my $putresult;
1.48 raeburn 7756: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7757: if (keys(%deletions) > 0) {
7758: foreach my $key (keys(%deletions)) {
7759: if ($predelallitems{$key} ne '') {
7760: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
7761: }
7762: }
7763: }
7764: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 7765: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 7766: if (ref($chkcats[0]) eq 'ARRAY') {
7767: my $depth = 0;
7768: my $chg = 0;
7769: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
7770: my $name = $chkcats[0][$i];
7771: my $item;
7772: if ($name eq '') {
7773: $chg ++;
7774: } else {
7775: $item = &escape($name).'::0';
7776: if ($chg) {
1.57 raeburn 7777: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 7778: }
7779: $depth ++;
1.57 raeburn 7780: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 7781: $depth --;
7782: }
7783: }
7784: }
1.57 raeburn 7785: }
7786: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7787: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 7788: if ($putresult eq 'ok') {
1.57 raeburn 7789: my %title = (
1.120 raeburn 7790: togglecats => 'Show/Hide a course in catalog',
7791: categorize => 'Assign a category to a course',
7792: togglecatscomm => 'Show/Hide a community in catalog',
7793: categorizecomm => 'Assign a category to a community',
1.57 raeburn 7794: );
7795: my %level = (
1.120 raeburn 7796: dom => 'set in Domain ("Modify Course/Community")',
7797: crs => 'set in Course ("Course Configuration")',
7798: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 7799: );
1.48 raeburn 7800: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 7801: if ($changes{'togglecats'}) {
7802: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
7803: }
7804: if ($changes{'categorize'}) {
7805: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 7806: }
1.120 raeburn 7807: if ($changes{'togglecatscomm'}) {
7808: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
7809: }
7810: if ($changes{'categorizecomm'}) {
7811: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
7812: }
1.57 raeburn 7813: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7814: my $cathash;
7815: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
7816: $cathash = $domconfig{'coursecategories'}{'cats'};
7817: } else {
7818: $cathash = {};
7819: }
7820: my (@cats,@trails,%allitems);
7821: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
7822: if (keys(%deletions) > 0) {
7823: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
7824: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
7825: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
7826: }
7827: $resulttext .= '</ul></li>';
7828: }
7829: if (keys(%reorderings) > 0) {
7830: my %sort_by_trail;
7831: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
7832: foreach my $key (keys(%reorderings)) {
7833: if ($allitems{$key} ne '') {
7834: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7835: }
1.48 raeburn 7836: }
1.57 raeburn 7837: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7838: $resulttext .= '<li>'.$trails[$trail].'</li>';
7839: }
7840: $resulttext .= '</ul></li>';
1.48 raeburn 7841: }
1.57 raeburn 7842: if (keys(%adds) > 0) {
7843: my %sort_by_trail;
7844: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
7845: foreach my $key (keys(%adds)) {
7846: if ($allitems{$key} ne '') {
7847: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7848: }
7849: }
7850: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7851: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 7852: }
1.57 raeburn 7853: $resulttext .= '</ul></li>';
1.48 raeburn 7854: }
7855: }
7856: $resulttext .= '</ul>';
7857: } else {
7858: $resulttext = '<span class="LC_error">'.
1.57 raeburn 7859: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 7860: }
7861: } else {
1.120 raeburn 7862: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 7863: }
7864: return $resulttext;
7865: }
7866:
1.69 raeburn 7867: sub modify_serverstatuses {
7868: my ($dom,%domconfig) = @_;
7869: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
7870: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
7871: %currserverstatus = %{$domconfig{'serverstatuses'}};
7872: }
7873: my @pages = &serverstatus_pages();
7874: foreach my $type (@pages) {
7875: $newserverstatus{$type}{'namedusers'} = '';
7876: $newserverstatus{$type}{'machines'} = '';
7877: if (defined($env{'form.'.$type.'_namedusers'})) {
7878: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
7879: my @okusers;
7880: foreach my $user (@users) {
7881: my ($uname,$udom) = split(/:/,$user);
7882: if (($udom =~ /^$match_domain$/) &&
7883: (&Apache::lonnet::domain($udom)) &&
7884: ($uname =~ /^$match_username$/)) {
7885: if (!grep(/^\Q$user\E/,@okusers)) {
7886: push(@okusers,$user);
7887: }
7888: }
7889: }
7890: if (@okusers > 0) {
7891: @okusers = sort(@okusers);
7892: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
7893: }
7894: }
7895: if (defined($env{'form.'.$type.'_machines'})) {
7896: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
7897: my @okmachines;
7898: foreach my $ip (@machines) {
7899: my @parts = split(/\./,$ip);
7900: next if (@parts < 4);
7901: my $badip = 0;
7902: for (my $i=0; $i<4; $i++) {
7903: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
7904: $badip = 1;
7905: last;
7906: }
7907: }
7908: if (!$badip) {
7909: push(@okmachines,$ip);
7910: }
7911: }
7912: @okmachines = sort(@okmachines);
7913: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
7914: }
7915: }
7916: my %serverstatushash = (
7917: serverstatuses => \%newserverstatus,
7918: );
7919: foreach my $type (@pages) {
1.83 raeburn 7920: foreach my $setting ('namedusers','machines') {
1.84 raeburn 7921: my (@current,@new);
1.83 raeburn 7922: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 7923: if ($currserverstatus{$type}{$setting} ne '') {
7924: @current = split(/,/,$currserverstatus{$type}{$setting});
7925: }
7926: }
7927: if ($newserverstatus{$type}{$setting} ne '') {
7928: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 7929: }
7930: if (@current > 0) {
7931: if (@new > 0) {
7932: foreach my $item (@current) {
7933: if (!grep(/^\Q$item\E$/,@new)) {
7934: $changes{$type}{$setting} = 1;
1.82 raeburn 7935: last;
7936: }
7937: }
1.84 raeburn 7938: foreach my $item (@new) {
7939: if (!grep(/^\Q$item\E$/,@current)) {
7940: $changes{$type}{$setting} = 1;
7941: last;
1.82 raeburn 7942: }
7943: }
7944: } else {
1.83 raeburn 7945: $changes{$type}{$setting} = 1;
1.69 raeburn 7946: }
1.83 raeburn 7947: } elsif (@new > 0) {
7948: $changes{$type}{$setting} = 1;
1.69 raeburn 7949: }
7950: }
7951: }
7952: if (keys(%changes) > 0) {
1.81 raeburn 7953: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7954: my $putresult = &Apache::lonnet::put_dom('configuration',
7955: \%serverstatushash,$dom);
7956: if ($putresult eq 'ok') {
7957: $resulttext .= &mt('Changes made:').'<ul>';
7958: foreach my $type (@pages) {
1.84 raeburn 7959: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 7960: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 7961: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 7962: if ($newserverstatus{$type}{'namedusers'} eq '') {
7963: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
7964: } else {
7965: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
7966: }
1.84 raeburn 7967: }
7968: if ($changes{$type}{'machines'}) {
1.69 raeburn 7969: if ($newserverstatus{$type}{'machines'} eq '') {
7970: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
7971: } else {
7972: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
7973: }
7974:
7975: }
7976: $resulttext .= '</ul></li>';
7977: }
7978: }
7979: $resulttext .= '</ul>';
7980: } else {
7981: $resulttext = '<span class="LC_error">'.
7982: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
7983:
7984: }
7985: } else {
7986: $resulttext = &mt('No changes made to access to server status pages');
7987: }
7988: return $resulttext;
7989: }
7990:
1.118 jms 7991: sub modify_helpsettings {
1.122 jms 7992: my ($r,$dom,$confname,%domconfig) = @_;
1.160.6.5 raeburn 7993: my ($resulttext,$errors,%changes,%helphash);
7994: my %defaultchecked = ('submitbugs' => 'on');
7995: my @offon = ('off','on');
1.118 jms 7996: my @toggles = ('submitbugs');
7997: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7998: foreach my $item (@toggles) {
1.160.6.5 raeburn 7999: if ($defaultchecked{$item} eq 'on') {
8000: if ($domconfig{'helpsettings'}{$item} eq '') {
8001: if ($env{'form.'.$item} eq '0') {
8002: $changes{$item} = 1;
8003: }
8004: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
8005: $changes{$item} = 1;
8006: }
8007: } elsif ($defaultchecked{$item} eq 'off') {
8008: if ($domconfig{'helpsettings'}{$item} eq '') {
8009: if ($env{'form.'.$item} eq '1') {
8010: $changes{$item} = 1;
8011: }
8012: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
8013: $changes{$item} = 1;
8014: }
1.160.6.26 raeburn 8015: }
1.160.6.5 raeburn 8016: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
8017: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
1.122 jms 8018: }
8019: }
1.118 jms 8020: }
1.123 jms 8021: my $putresult;
8022: if (keys(%changes) > 0) {
1.160.6.5 raeburn 8023: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
8024: if ($putresult eq 'ok') {
8025: $resulttext = &mt('Changes made:').'<ul>';
8026: foreach my $item (sort(keys(%changes))) {
8027: if ($item eq 'submitbugs') {
8028: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
8029: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
8030: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
8031: }
8032: }
8033: $resulttext .= '</ul>';
8034: } else {
8035: $resulttext = &mt('No changes made to help settings');
8036: $errors .= '<li><span class="LC_error">'.
8037: &mt('An error occurred storing the settings: [_1]',
8038: $putresult).'</span></li>';
8039: }
1.118 jms 8040: }
8041: if ($errors) {
1.160.6.5 raeburn 8042: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 8043: $errors.'</ul>';
8044: }
8045: return $resulttext;
8046: }
8047:
1.121 raeburn 8048: sub modify_coursedefaults {
1.160.6.27! raeburn 8049: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 8050: my ($resulttext,$errors,%changes,%defaultshash);
8051: my %defaultchecked = ('canuse_pdfforms' => 'off');
8052: my @toggles = ('canuse_pdfforms');
1.160.6.21 raeburn 8053: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
8054: 'uploadquota_community');
8055: my @types = ('official','unofficial','community');
8056: my %staticdefaults = (
8057: anonsurvey_threshold => 10,
8058: uploadquota => 500,
8059: );
1.121 raeburn 8060:
8061: $defaultshash{'coursedefaults'} = {};
8062:
8063: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
8064: if ($domconfig{'coursedefaults'} eq '') {
8065: $domconfig{'coursedefaults'} = {};
8066: }
8067: }
8068:
8069: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
8070: foreach my $item (@toggles) {
8071: if ($defaultchecked{$item} eq 'on') {
8072: if (($domconfig{'coursedefaults'}{$item} eq '') &&
8073: ($env{'form.'.$item} eq '0')) {
8074: $changes{$item} = 1;
1.160.6.16 raeburn 8075: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 8076: $changes{$item} = 1;
8077: }
8078: } elsif ($defaultchecked{$item} eq 'off') {
8079: if (($domconfig{'coursedefaults'}{$item} eq '') &&
8080: ($env{'form.'.$item} eq '1')) {
8081: $changes{$item} = 1;
8082: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
8083: $changes{$item} = 1;
8084: }
8085: }
8086: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
8087: }
1.160.6.21 raeburn 8088: foreach my $item (@numbers) {
8089: my ($currdef,$newdef);
1.160.6.26 raeburn 8090: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 8091: if ($item eq 'anonsurvey_threshold') {
8092: $currdef = $domconfig{'coursedefaults'}{$item};
8093: $newdef =~ s/\D//g;
8094: if ($newdef eq '' || $newdef < 1) {
8095: $newdef = 1;
8096: }
8097: $defaultshash{'coursedefaults'}{$item} = $newdef;
8098: } else {
8099: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
8100: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8101: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
8102: }
8103: $newdef =~ s/[^\w.\-]//g;
8104: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
8105: }
8106: if ($currdef ne $newdef) {
8107: my $staticdef;
8108: if ($item eq 'anonsurvey_threshold') {
8109: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
8110: $changes{$item} = 1;
8111: }
8112: } else {
8113: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
8114: $changes{'uploadquota'} = 1;
8115: }
8116: }
1.139 raeburn 8117: }
8118: }
1.160.6.16 raeburn 8119: my $officialcreds = $env{'form.official_credits'};
8120: $officialcreds =~ s/^[^\d\.]//g;
8121: my $unofficialcreds = $env{'form.unofficial_credits'};
8122: $unofficialcreds =~ s/^[^\d\.]//g;
8123: if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
8124: ($env{'form.coursecredits'} eq '1')) {
8125: $changes{'coursecredits'} = 1;
8126: } else {
8127: if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
8128: ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds)) {
8129: $changes{'coursecredits'} = 1;
8130: }
8131: }
8132: $defaultshash{'coursedefaults'}{'coursecredits'} = {
8133: official => $officialcreds,
8134: unofficial => $unofficialcreds,
8135: }
1.121 raeburn 8136: }
8137: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8138: $dom);
8139: if ($putresult eq 'ok') {
8140: if (keys(%changes) > 0) {
1.160.6.27! raeburn 8141: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.21 raeburn 8142: if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) || ($changes{'uploadquota'})) {
1.160.6.16 raeburn 8143: if ($changes{'canuse_pdfforms'}) {
8144: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
8145: }
8146: if ($changes{'coursecredits'}) {
8147: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
8148: $domdefaults{'officialcredits'} =
8149: $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
8150: $domdefaults{'unofficialcredits'} =
8151: $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
8152: }
8153: }
1.160.6.21 raeburn 8154: if ($changes{'uploadquota'}) {
8155: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8156: foreach my $type (@types) {
8157: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
8158: }
8159: }
8160: }
1.121 raeburn 8161: my $cachetime = 24*60*60;
8162: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27! raeburn 8163: if (ref($lastactref) eq 'HASH') {
! 8164: $lastactref->{'domdefaults'} = 1;
! 8165: }
1.121 raeburn 8166: }
8167: $resulttext = &mt('Changes made:').'<ul>';
8168: foreach my $item (sort(keys(%changes))) {
8169: if ($item eq 'canuse_pdfforms') {
8170: if ($env{'form.'.$item} eq '1') {
8171: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
8172: } else {
8173: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
8174: }
1.139 raeburn 8175: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 8176: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.160.6.21 raeburn 8177: } elsif ($item eq 'uploadquota') {
8178: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8179: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
8180: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
8181: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
8182: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
8183: '</ul>'.
8184: '</li>';
8185: } else {
8186: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
8187: }
1.160.6.16 raeburn 8188: } elsif ($item eq 'coursecredits') {
8189: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
8190: if (($domdefaults{'officialcredits'} eq '') &&
8191: ($domdefaults{'unofficialcredits'} eq '')) {
8192: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
8193: } else {
8194: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
8195: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
8196: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
8197: '</ul>'.
8198: '</li>';
8199: }
8200: } else {
8201: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
8202: }
1.140 raeburn 8203: }
1.121 raeburn 8204: }
8205: $resulttext .= '</ul>';
8206: } else {
8207: $resulttext = &mt('No changes made to course defaults');
8208: }
8209: } else {
8210: $resulttext = '<span class="LC_error">'.
8211: &mt('An error occurred: [_1]',$putresult).'</span>';
8212: }
8213: return $resulttext;
8214: }
8215:
1.137 raeburn 8216: sub modify_usersessions {
1.160.6.27! raeburn 8217: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 8218: my @hostingtypes = ('version','excludedomain','includedomain');
8219: my @offloadtypes = ('primary','default');
8220: my %types = (
8221: remote => \@hostingtypes,
8222: hosted => \@hostingtypes,
8223: spares => \@offloadtypes,
8224: );
8225: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 8226: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 8227: my (%by_ip,%by_location,@intdoms);
8228: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
8229: my @locations = sort(keys(%by_location));
1.137 raeburn 8230: my (%defaultshash,%changes);
8231: foreach my $prefix (@prefixes) {
8232: $defaultshash{'usersessions'}{$prefix} = {};
8233: }
1.160.6.27! raeburn 8234: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 8235: my $resulttext;
1.138 raeburn 8236: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 8237: foreach my $prefix (@prefixes) {
1.145 raeburn 8238: next if ($prefix eq 'spares');
8239: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 8240: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
8241: if ($type eq 'version') {
8242: my $value = $env{'form.'.$prefix.'_'.$type};
8243: my $okvalue;
8244: if ($value ne '') {
8245: if (grep(/^\Q$value\E$/,@lcversions)) {
8246: $okvalue = $value;
8247: }
8248: }
8249: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8250: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
8251: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
8252: if ($inuse == 0) {
8253: $changes{$prefix}{$type} = 1;
8254: } else {
8255: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
8256: $changes{$prefix}{$type} = 1;
8257: }
8258: if ($okvalue ne '') {
8259: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8260: }
8261: }
8262: } else {
8263: if (($inuse == 1) && ($okvalue ne '')) {
8264: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8265: $changes{$prefix}{$type} = 1;
8266: }
8267: }
8268: } else {
8269: if (($inuse == 1) && ($okvalue ne '')) {
8270: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8271: $changes{$prefix}{$type} = 1;
8272: }
8273: }
8274: } else {
8275: if (($inuse == 1) && ($okvalue ne '')) {
8276: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8277: $changes{$prefix}{$type} = 1;
8278: }
8279: }
8280: } else {
8281: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
8282: my @okvals;
8283: foreach my $val (@vals) {
1.138 raeburn 8284: if ($val =~ /:/) {
8285: my @items = split(/:/,$val);
8286: foreach my $item (@items) {
8287: if (ref($by_location{$item}) eq 'ARRAY') {
8288: push(@okvals,$item);
8289: }
8290: }
8291: } else {
8292: if (ref($by_location{$val}) eq 'ARRAY') {
8293: push(@okvals,$val);
8294: }
1.137 raeburn 8295: }
8296: }
8297: @okvals = sort(@okvals);
8298: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8299: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
8300: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8301: if ($inuse == 0) {
8302: $changes{$prefix}{$type} = 1;
8303: } else {
8304: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8305: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
8306: if (@changed > 0) {
8307: $changes{$prefix}{$type} = 1;
8308: }
8309: }
8310: } else {
8311: if ($inuse == 1) {
8312: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8313: $changes{$prefix}{$type} = 1;
8314: }
8315: }
8316: } else {
8317: if ($inuse == 1) {
8318: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8319: $changes{$prefix}{$type} = 1;
8320: }
8321: }
8322: } else {
8323: if ($inuse == 1) {
8324: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8325: $changes{$prefix}{$type} = 1;
8326: }
8327: }
8328: }
8329: }
8330: }
1.145 raeburn 8331:
8332: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 8333: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 8334: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
8335: my $savespares;
8336:
8337: foreach my $lonhost (sort(keys(%servers))) {
8338: my $serverhomeID =
8339: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 8340: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 8341: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
8342: my %spareschg;
8343: foreach my $type (@{$types{'spares'}}) {
8344: my @okspares;
8345: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
8346: foreach my $server (@checked) {
1.152 raeburn 8347: if (&Apache::lonnet::hostname($server) ne '') {
8348: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
8349: unless (grep(/^\Q$server\E$/,@okspares)) {
8350: push(@okspares,$server);
8351: }
1.145 raeburn 8352: }
8353: }
8354: }
8355: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
8356: my $newspare;
1.152 raeburn 8357: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
8358: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 8359: $newspare = $new;
8360: }
8361: }
1.152 raeburn 8362: my @spares;
8363: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
8364: @spares = sort(@okspares,$newspare);
8365: } else {
8366: @spares = sort(@okspares);
8367: }
8368: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 8369: if (ref($spareid{$lonhost}) eq 'HASH') {
8370: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 8371: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 8372: if (@diffs > 0) {
8373: $spareschg{$type} = 1;
8374: }
8375: }
8376: }
8377: }
8378: if (keys(%spareschg) > 0) {
8379: $changes{'spares'}{$lonhost} = \%spareschg;
8380: }
8381: }
8382:
8383: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8384: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
8385: if (ref($changes{'spares'}) eq 'HASH') {
8386: if (keys(%{$changes{'spares'}}) > 0) {
8387: $savespares = 1;
8388: }
8389: }
8390: } else {
8391: $savespares = 1;
8392: }
8393: }
8394:
1.147 raeburn 8395: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
8396: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 8397: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8398: $dom);
8399: if ($putresult eq 'ok') {
8400: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8401: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
8402: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
8403: }
8404: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
8405: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
8406: }
8407: }
8408: my $cachetime = 24*60*60;
8409: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27! raeburn 8410: if (ref($lastactref) eq 'HASH') {
! 8411: $lastactref->{'domdefaults'} = 1;
! 8412: }
1.147 raeburn 8413: if (keys(%changes) > 0) {
8414: my %lt = &usersession_titles();
8415: $resulttext = &mt('Changes made:').'<ul>';
8416: foreach my $prefix (@prefixes) {
8417: if (ref($changes{$prefix}) eq 'HASH') {
8418: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
8419: if ($prefix eq 'spares') {
8420: if (ref($changes{$prefix}) eq 'HASH') {
8421: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
8422: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 8423: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27! raeburn 8424: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
! 8425: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 8426: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
8427: foreach my $type (@{$types{$prefix}}) {
8428: if ($changes{$prefix}{$lonhost}{$type}) {
8429: my $offloadto = &mt('None');
8430: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
8431: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
8432: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
8433: }
1.145 raeburn 8434: }
1.147 raeburn 8435: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 8436: }
1.137 raeburn 8437: }
8438: }
1.147 raeburn 8439: $resulttext .= '</li>';
1.137 raeburn 8440: }
8441: }
1.147 raeburn 8442: } else {
8443: foreach my $type (@{$types{$prefix}}) {
8444: if (defined($changes{$prefix}{$type})) {
8445: my $newvalue;
8446: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8447: if (ref($defaultshash{'usersessions'}{$prefix})) {
8448: if ($type eq 'version') {
8449: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
8450: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8451: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
8452: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
8453: }
1.145 raeburn 8454: }
8455: }
8456: }
1.147 raeburn 8457: if ($newvalue eq '') {
8458: if ($type eq 'version') {
8459: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
8460: } else {
8461: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
8462: }
1.145 raeburn 8463: } else {
1.147 raeburn 8464: if ($type eq 'version') {
8465: $newvalue .= ' '.&mt('(or later)');
8466: }
8467: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 8468: }
1.137 raeburn 8469: }
8470: }
8471: }
1.147 raeburn 8472: $resulttext .= '</ul>';
1.137 raeburn 8473: }
8474: }
1.147 raeburn 8475: $resulttext .= '</ul>';
8476: } else {
8477: $resulttext = $nochgmsg;
1.137 raeburn 8478: }
8479: } else {
8480: $resulttext = '<span class="LC_error">'.
8481: &mt('An error occurred: [_1]',$putresult).'</span>';
8482: }
8483: } else {
1.147 raeburn 8484: $resulttext = $nochgmsg;
1.137 raeburn 8485: }
8486: return $resulttext;
8487: }
8488:
1.150 raeburn 8489: sub modify_loadbalancing {
8490: my ($dom,%domconfig) = @_;
8491: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8492: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8493: my ($othertitle,$usertypes,$types) =
8494: &Apache::loncommon::sorted_inst_types($dom);
8495: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8496: my @sparestypes = ('primary','default');
8497: my %typetitles = &sparestype_titles();
8498: my $resulttext;
1.160.6.7 raeburn 8499: my (%currbalancer,%currtargets,%currrules,%existing);
8500: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8501: %existing = %{$domconfig{'loadbalancing'}};
8502: }
8503: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
8504: \%currtargets,\%currrules);
8505: my ($saveloadbalancing,%defaultshash,%changes);
8506: my ($alltypes,$othertypes,$titles) =
8507: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8508: my %ruletitles = &offloadtype_text();
8509: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
8510: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
8511: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
8512: if ($balancer eq '') {
8513: next;
8514: }
8515: if (!exists($servers{$balancer})) {
8516: if (exists($currbalancer{$balancer})) {
8517: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 8518: }
1.160.6.7 raeburn 8519: next;
8520: }
8521: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
8522: push(@{$changes{'delete'}},$balancer);
8523: next;
8524: }
8525: if (!exists($currbalancer{$balancer})) {
8526: push(@{$changes{'add'}},$balancer);
8527: }
8528: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
8529: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
8530: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
8531: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8532: $saveloadbalancing = 1;
8533: }
8534: foreach my $sparetype (@sparestypes) {
8535: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
8536: my @offloadto;
8537: foreach my $target (@targets) {
8538: if (($servers{$target}) && ($target ne $balancer)) {
8539: if ($sparetype eq 'default') {
8540: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
8541: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 8542: }
8543: }
1.160.6.7 raeburn 8544: unless(grep(/^\Q$target\E$/,@offloadto)) {
8545: push(@offloadto,$target);
8546: }
1.150 raeburn 8547: }
1.160.6.7 raeburn 8548: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 8549: }
8550: }
1.160.6.7 raeburn 8551: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 8552: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 8553: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
8554: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 8555: if (@targetdiffs > 0) {
1.160.6.7 raeburn 8556: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8557: }
1.160.6.7 raeburn 8558: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8559: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8560: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8561: }
8562: }
8563: }
8564: } else {
1.160.6.7 raeburn 8565: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
8566: foreach my $sparetype (@sparestypes) {
8567: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8568: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8569: $changes{'curr'}{$balancer}{'targets'} = 1;
8570: }
1.150 raeburn 8571: }
8572: }
1.160.6.7 raeburn 8573: }
1.150 raeburn 8574: }
8575: my $ishomedom;
1.160.6.7 raeburn 8576: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
8577: $ishomedom = 1;
1.150 raeburn 8578: }
8579: if (ref($alltypes) eq 'ARRAY') {
8580: foreach my $type (@{$alltypes}) {
8581: my $rule;
1.160.6.7 raeburn 8582: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 8583: (!$ishomedom)) {
1.160.6.7 raeburn 8584: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
8585: }
8586: if ($rule eq 'specific') {
8587: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 8588: }
1.160.6.7 raeburn 8589: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
8590: if (ref($currrules{$balancer}) eq 'HASH') {
8591: if ($rule ne $currrules{$balancer}{$type}) {
8592: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8593: }
8594: } elsif ($rule ne '') {
1.160.6.7 raeburn 8595: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8596: }
8597: }
8598: }
1.160.6.7 raeburn 8599: }
8600: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
8601: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
8602: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
8603: $defaultshash{'loadbalancing'} = {};
8604: }
8605: my $putresult = &Apache::lonnet::put_dom('configuration',
8606: \%defaultshash,$dom);
8607: if ($putresult eq 'ok') {
8608: if (keys(%changes) > 0) {
8609: if (ref($changes{'delete'}) eq 'ARRAY') {
8610: foreach my $balancer (sort(@{$changes{'delete'}})) {
8611: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.27! raeburn 8612: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
! 8613: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 8614: }
1.160.6.7 raeburn 8615: }
8616: if (ref($changes{'add'}) eq 'ARRAY') {
8617: foreach my $balancer (sort(@{$changes{'add'}})) {
8618: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
8619: }
8620: }
8621: if (ref($changes{'curr'}) eq 'HASH') {
8622: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
8623: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
8624: if ($changes{'curr'}{$balancer}{'targets'}) {
8625: my %offloadstr;
8626: foreach my $sparetype (@sparestypes) {
8627: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8628: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8629: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
8630: }
8631: }
1.150 raeburn 8632: }
1.160.6.7 raeburn 8633: if (keys(%offloadstr) == 0) {
8634: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 8635: } else {
1.160.6.7 raeburn 8636: my $showoffload;
8637: foreach my $sparetype (@sparestypes) {
8638: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
8639: if (defined($offloadstr{$sparetype})) {
8640: $showoffload .= $offloadstr{$sparetype};
8641: } else {
8642: $showoffload .= &mt('None');
8643: }
8644: $showoffload .= (' 'x3);
8645: }
8646: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 8647: }
8648: }
8649: }
1.160.6.7 raeburn 8650: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
8651: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
8652: foreach my $type (@{$alltypes}) {
8653: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
8654: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
8655: my $balancetext;
8656: if ($rule eq '') {
8657: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 8658: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
8659: ($rule eq 'balancer') || ($rule eq 'offloadedto')) {
1.160.6.7 raeburn 8660: $balancetext = $ruletitles{$rule};
8661: } else {
8662: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
8663: }
1.160.6.26 raeburn 8664: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 8665: }
8666: }
8667: }
8668: }
1.160.6.27! raeburn 8669: my $cachekey = &scape('loadbalancing').':'.&escape($dom);
! 8670: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 8671: }
1.160.6.7 raeburn 8672: }
8673: if ($resulttext ne '') {
8674: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 8675: } else {
8676: $resulttext = $nochgmsg;
8677: }
8678: } else {
1.160.6.7 raeburn 8679: $resulttext = $nochgmsg;
1.150 raeburn 8680: }
8681: } else {
1.160.6.7 raeburn 8682: $resulttext = '<span class="LC_error">'.
8683: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 8684: }
8685: } else {
1.160.6.7 raeburn 8686: $resulttext = $nochgmsg;
1.150 raeburn 8687: }
8688: return $resulttext;
8689: }
8690:
1.48 raeburn 8691: sub recurse_check {
8692: my ($chkcats,$categories,$depth,$name) = @_;
8693: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
8694: my $chg = 0;
8695: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
8696: my $category = $chkcats->[$depth]{$name}[$j];
8697: my $item;
8698: if ($category eq '') {
8699: $chg ++;
8700: } else {
8701: my $deeper = $depth + 1;
8702: $item = &escape($category).':'.&escape($name).':'.$depth;
8703: if ($chg) {
8704: $categories->{$item} -= $chg;
8705: }
8706: &recurse_check($chkcats,$categories,$deeper,$category);
8707: $deeper --;
8708: }
8709: }
8710: }
8711: return;
8712: }
8713:
8714: sub recurse_cat_deletes {
8715: my ($item,$coursecategories,$deletions) = @_;
8716: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8717: my $subdepth = $depth + 1;
8718: if (ref($coursecategories) eq 'HASH') {
8719: foreach my $subitem (keys(%{$coursecategories})) {
8720: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
8721: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
8722: delete($coursecategories->{$subitem});
8723: $deletions->{$subitem} = 1;
8724: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 8725: }
1.48 raeburn 8726: }
8727: }
8728: return;
8729: }
8730:
1.125 raeburn 8731: sub get_active_dcs {
8732: my ($dom) = @_;
1.160.6.16 raeburn 8733: my $now = time;
8734: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 8735: my %domcoords;
8736: my $numdcs = 0;
8737: foreach my $server (keys(%dompersonnel)) {
8738: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
8739: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.160.6.16 raeburn 8740: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 8741: }
8742: }
8743: return %domcoords;
8744: }
8745:
8746: sub active_dc_picker {
1.160.6.16 raeburn 8747: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.125 raeburn 8748: my %domcoords = &get_active_dcs($dom);
1.160.6.16 raeburn 8749: my @domcoord = keys(%domcoords);
8750: if (keys(%currhash)) {
8751: foreach my $dc (keys(%currhash)) {
8752: unless (exists($domcoords{$dc})) {
8753: push(@domcoord,$dc);
8754: }
8755: }
8756: }
8757: @domcoord = sort(@domcoord);
8758: my $numdcs = scalar(@domcoord);
8759: my $rows = 0;
8760: my $table;
1.125 raeburn 8761: if ($numdcs > 1) {
1.160.6.16 raeburn 8762: $table = '<table>';
8763: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 8764: my $rem = $i%($numinrow);
8765: if ($rem == 0) {
8766: if ($i > 0) {
1.160.6.16 raeburn 8767: $table .= '</tr>';
1.125 raeburn 8768: }
1.160.6.16 raeburn 8769: $table .= '<tr>';
8770: $rows ++;
1.125 raeburn 8771: }
1.160.6.16 raeburn 8772: my $check = '';
8773: if ($inputtype eq 'radio') {
8774: if (keys(%currhash) == 0) {
8775: if (!$i) {
8776: $check = ' checked="checked"';
8777: }
8778: } elsif (exists($currhash{$domcoord[$i]})) {
8779: $check = ' checked="checked"';
8780: }
8781: } else {
8782: if (exists($currhash{$domcoord[$i]})) {
8783: $check = ' checked="checked"';
1.125 raeburn 8784: }
8785: }
1.160.6.16 raeburn 8786: if ($i == @domcoord - 1) {
1.125 raeburn 8787: my $colsleft = $numinrow - $rem;
8788: if ($colsleft > 1) {
1.160.6.16 raeburn 8789: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 8790: } else {
1.160.6.16 raeburn 8791: $table .= '<td class="LC_left_item">';
1.125 raeburn 8792: }
8793: } else {
1.160.6.16 raeburn 8794: $table .= '<td class="LC_left_item">';
8795: }
8796: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
8797: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
8798: $table .= '<span class="LC_nobreak"><label>'.
8799: '<input type="'.$inputtype.'" name="'.$name.'"'.
8800: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
8801: if ($user ne $dcname.':'.$dcdom) {
8802: $table .= ' ('.$dcname.':'.$dcdom.')'.
8803: '</label></span></td>';
1.125 raeburn 8804: }
8805: }
1.160.6.16 raeburn 8806: $table .= '</tr></table>';
8807: } elsif ($numdcs == 1) {
8808: if ($inputtype eq 'radio') {
8809: $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />';
8810: } else {
8811: my $check;
8812: if (exists($currhash{$domcoord[0]})) {
8813: $check = ' checked="checked"';
8814: }
8815: $table .= '<input type="checkbox" name="'.$name.'" '.
8816: 'value="'.$domcoord[0].'"'.$check.' />';
8817: $rows ++;
8818: }
1.125 raeburn 8819: }
1.160.6.16 raeburn 8820: return ($numdcs,$table,$rows);
1.125 raeburn 8821: }
8822:
1.137 raeburn 8823: sub usersession_titles {
8824: return &Apache::lonlocal::texthash(
8825: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
8826: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 8827: spares => 'Servers offloaded to, when busy',
1.137 raeburn 8828: version => 'LON-CAPA version requirement',
1.138 raeburn 8829: excludedomain => 'Allow all, but exclude specific domains',
8830: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 8831: primary => 'Primary (checked first)',
1.154 raeburn 8832: default => 'Default',
1.137 raeburn 8833: );
8834: }
8835:
1.152 raeburn 8836: sub id_for_thisdom {
8837: my (%servers) = @_;
8838: my %altids;
8839: foreach my $server (keys(%servers)) {
8840: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
8841: if ($serverhome ne $server) {
8842: $altids{$serverhome} = $server;
8843: }
8844: }
8845: return %altids;
8846: }
8847:
1.150 raeburn 8848: sub count_servers {
8849: my ($currbalancer,%servers) = @_;
8850: my (@spares,$numspares);
8851: foreach my $lonhost (sort(keys(%servers))) {
8852: next if ($currbalancer eq $lonhost);
8853: push(@spares,$lonhost);
8854: }
8855: if ($currbalancer) {
8856: $numspares = scalar(@spares);
8857: } else {
8858: $numspares = scalar(@spares) - 1;
8859: }
8860: return ($numspares,@spares);
8861: }
8862:
8863: sub lonbalance_targets_js {
1.160.6.7 raeburn 8864: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 8865: my $select = &mt('Select');
8866: my ($alltargets,$allishome,$allinsttypes,@alltypes);
8867: if (ref($servers) eq 'HASH') {
8868: $alltargets = join("','",sort(keys(%{$servers})));
8869: my @homedoms;
8870: foreach my $server (sort(keys(%{$servers}))) {
8871: if (&Apache::lonnet::host_domain($server) eq $dom) {
8872: push(@homedoms,'1');
8873: } else {
8874: push(@homedoms,'0');
8875: }
8876: }
8877: $allishome = join("','",@homedoms);
8878: }
8879: if (ref($types) eq 'ARRAY') {
8880: if (@{$types} > 0) {
8881: @alltypes = @{$types};
8882: }
8883: }
8884: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
8885: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 8886: my (%currbalancer,%currtargets,%currrules,%existing);
8887: if (ref($settings) eq 'HASH') {
8888: %existing = %{$settings};
8889: }
8890: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
8891: \%currtargets,\%currrules);
8892: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 8893: return <<"END";
8894:
8895: <script type="text/javascript">
8896: // <![CDATA[
8897:
1.160.6.7 raeburn 8898: currBalancers = new Array('$balancers');
8899:
8900: function toggleTargets(balnum) {
8901: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8902: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
8903: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
8904: var prevbalancer = prevhostitem.value;
8905: var baltotal = document.getElementById('loadbalancing_total').value;
8906: prevhostitem.value = balancer;
8907: if (prevbalancer != '') {
8908: var prevIdx = currBalancers.indexOf(prevbalancer);
8909: if (prevIdx != -1) {
8910: currBalancers.splice(prevIdx,1);
8911: }
8912: }
1.150 raeburn 8913: if (balancer == '') {
1.160.6.7 raeburn 8914: hideSpares(balnum);
1.150 raeburn 8915: } else {
1.160.6.7 raeburn 8916: var currIdx = currBalancers.indexOf(balancer);
8917: if (currIdx == -1) {
8918: currBalancers.push(balancer);
8919: }
1.150 raeburn 8920: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 8921: var ishomedom = homedoms[lonhostitem.selectedIndex];
8922: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 8923: }
1.160.6.7 raeburn 8924: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 8925: return;
8926: }
8927:
1.160.6.7 raeburn 8928: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 8929: var alltargets = new Array('$alltargets');
8930: var insttypes = new Array('$allinsttypes');
1.151 raeburn 8931: var offloadtypes = new Array('primary','default');
8932:
1.160.6.7 raeburn 8933: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
8934: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 8935:
1.151 raeburn 8936: for (var i=0; i<offloadtypes.length; i++) {
8937: var count = 0;
8938: for (var j=0; j<alltargets.length; j++) {
8939: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 8940: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
8941: item.value = alltargets[j];
8942: item.style.textAlign='left';
8943: item.style.textFace='normal';
8944: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
8945: if (currBalancers.indexOf(alltargets[j]) == -1) {
8946: item.disabled = '';
8947: } else {
8948: item.disabled = 'disabled';
8949: item.checked = false;
8950: }
1.151 raeburn 8951: count ++;
8952: }
1.150 raeburn 8953: }
8954: }
1.151 raeburn 8955: for (var k=0; k<insttypes.length; k++) {
8956: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 8957: if (ishomedom == 1) {
1.160.6.7 raeburn 8958: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8959: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8960: } else {
1.160.6.7 raeburn 8961: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8962: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 8963: }
8964: } else {
1.160.6.7 raeburn 8965: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8966: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8967: }
1.151 raeburn 8968: if ((insttypes[k] != '_LC_external') &&
8969: ((insttypes[k] != '_LC_internetdom') ||
8970: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 8971: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
8972: item.options.length = 0;
8973: item.options[0] = new Option("","",true,true);
8974: var idx = 0;
1.151 raeburn 8975: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 8976: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
8977: idx ++;
8978: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 8979: }
8980: }
8981: }
8982: }
8983: return;
8984: }
8985:
1.160.6.7 raeburn 8986: function hideSpares(balnum) {
1.150 raeburn 8987: var alltargets = new Array('$alltargets');
8988: var insttypes = new Array('$allinsttypes');
8989: var offloadtypes = new Array('primary','default');
8990:
1.160.6.7 raeburn 8991: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
8992: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 8993:
8994: var total = alltargets.length - 1;
8995: for (var i=0; i<offloadtypes; i++) {
8996: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 8997: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
8998: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
8999: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 9000: }
1.150 raeburn 9001: }
9002: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 9003: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
9004: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 9005: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 9006: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
9007: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 9008: }
9009: }
9010: return;
9011: }
9012:
1.160.6.7 raeburn 9013: function checkOffloads(item,balnum,type) {
1.150 raeburn 9014: var alltargets = new Array('$alltargets');
9015: var offloadtypes = new Array('primary','default');
9016: if (item.checked) {
9017: var total = alltargets.length - 1;
9018: var other;
9019: if (type == offloadtypes[0]) {
1.151 raeburn 9020: other = offloadtypes[1];
1.150 raeburn 9021: } else {
1.151 raeburn 9022: other = offloadtypes[0];
1.150 raeburn 9023: }
9024: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 9025: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 9026: if (server == item.value) {
1.160.6.7 raeburn 9027: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
9028: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 9029: }
9030: }
9031: }
9032: }
9033: return;
9034: }
9035:
1.160.6.7 raeburn 9036: function singleServerToggle(balnum,type) {
9037: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 9038: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 9039: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
9040: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 9041:
9042: } else {
1.160.6.7 raeburn 9043: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
9044: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 9045: }
9046: return;
9047: }
9048:
1.160.6.7 raeburn 9049: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 9050: if (type == '_LC_external') {
1.160.6.26 raeburn 9051: return;
1.150 raeburn 9052: }
1.160.6.7 raeburn 9053: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 9054: for (var i=0; i<typesRules.length; i++) {
9055: if (formname.elements[typesRules[i]].checked) {
9056: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 9057: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
9058: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 9059: } else {
1.160.6.7 raeburn 9060: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
9061: }
9062: }
9063: }
9064: return;
9065: }
9066:
9067: function balancerDeleteChange(balnum) {
9068: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
9069: var baltotal = document.getElementById('loadbalancing_total').value;
9070: var addtarget;
9071: var removetarget;
9072: var action = 'delete';
9073: if (document.getElementById('loadbalancing_delete_'+balnum)) {
9074: var lonhost = hostitem.value;
9075: var currIdx = currBalancers.indexOf(lonhost);
9076: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
9077: if (currIdx != -1) {
9078: currBalancers.splice(currIdx,1);
9079: }
9080: addtarget = lonhost;
9081: } else {
9082: if (currIdx == -1) {
9083: currBalancers.push(lonhost);
9084: }
9085: removetarget = lonhost;
9086: action = 'undelete';
9087: }
9088: balancerChange(balnum,baltotal,action,addtarget,removetarget);
9089: }
9090: return;
9091: }
9092:
9093: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
9094: if (baltotal > 1) {
9095: var offloadtypes = new Array('primary','default');
9096: var alltargets = new Array('$alltargets');
9097: var insttypes = new Array('$allinsttypes');
9098: for (var i=0; i<baltotal; i++) {
9099: if (i != balnum) {
9100: for (var j=0; j<offloadtypes.length; j++) {
9101: var total = alltargets.length - 1;
9102: for (var k=0; k<total; k++) {
9103: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
9104: var server = serveritem.value;
9105: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
9106: if (server == addtarget) {
9107: serveritem.disabled = '';
9108: }
9109: }
9110: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
9111: if (server == removetarget) {
9112: serveritem.disabled = 'disabled';
9113: serveritem.checked = false;
9114: }
9115: }
9116: }
9117: }
9118: for (var j=0; j<insttypes.length; j++) {
9119: if (insttypes[j] != '_LC_external') {
9120: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
9121: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
9122: var currSel = singleserver.selectedIndex;
9123: var currVal = singleserver.options[currSel].value;
9124: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
9125: var numoptions = singleserver.options.length;
9126: var needsnew = 1;
9127: for (var k=0; k<numoptions; k++) {
9128: if (singleserver.options[k] == addtarget) {
9129: needsnew = 0;
9130: break;
9131: }
9132: }
9133: if (needsnew == 1) {
9134: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
9135: }
9136: }
9137: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
9138: singleserver.options.length = 0;
9139: if ((currVal) && (currVal != removetarget)) {
9140: singleserver.options[0] = new Option("","",false,false);
9141: } else {
9142: singleserver.options[0] = new Option("","",true,true);
9143: }
9144: var idx = 0;
9145: for (var m=0; m<alltargets.length; m++) {
9146: if (currBalancers.indexOf(alltargets[m]) == -1) {
9147: idx ++;
9148: if (currVal == alltargets[m]) {
9149: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
9150: } else {
9151: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
9152: }
9153: }
9154: }
9155: }
9156: }
9157: }
9158: }
1.150 raeburn 9159: }
9160: }
9161: }
9162: return;
9163: }
9164:
1.152 raeburn 9165: // ]]>
9166: </script>
9167:
9168: END
9169: }
9170:
9171: sub new_spares_js {
9172: my @sparestypes = ('primary','default');
9173: my $types = join("','",@sparestypes);
9174: my $select = &mt('Select');
9175: return <<"END";
9176:
9177: <script type="text/javascript">
9178: // <![CDATA[
9179:
9180: function updateNewSpares(formname,lonhost) {
9181: var types = new Array('$types');
9182: var include = new Array();
9183: var exclude = new Array();
9184: for (var i=0; i<types.length; i++) {
9185: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
9186: for (var j=0; j<spareboxes.length; j++) {
9187: if (formname.elements[spareboxes[j]].checked) {
9188: exclude.push(formname.elements[spareboxes[j]].value);
9189: } else {
9190: include.push(formname.elements[spareboxes[j]].value);
9191: }
9192: }
9193: }
9194: for (var i=0; i<types.length; i++) {
9195: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
9196: var selIdx = newSpare.selectedIndex;
9197: var currnew = newSpare.options[selIdx].value;
9198: var okSpares = new Array();
9199: for (var j=0; j<newSpare.options.length; j++) {
9200: var possible = newSpare.options[j].value;
9201: if (possible != '') {
9202: if (exclude.indexOf(possible) == -1) {
9203: okSpares.push(possible);
9204: } else {
9205: if (currnew == possible) {
9206: selIdx = 0;
9207: }
9208: }
9209: }
9210: }
9211: for (var k=0; k<include.length; k++) {
9212: if (okSpares.indexOf(include[k]) == -1) {
9213: okSpares.push(include[k]);
9214: }
9215: }
9216: okSpares.sort();
9217: newSpare.options.length = 0;
9218: if (selIdx == 0) {
9219: newSpare.options[0] = new Option("$select","",true,true);
9220: } else {
9221: newSpare.options[0] = new Option("$select","",false,false);
9222: }
9223: for (var m=0; m<okSpares.length; m++) {
9224: var idx = m+1;
9225: var selThis = 0;
9226: if (selIdx != 0) {
9227: if (okSpares[m] == currnew) {
9228: selThis = 1;
9229: }
9230: }
9231: if (selThis == 1) {
9232: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
9233: } else {
9234: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
9235: }
9236: }
9237: }
9238: return;
9239: }
9240:
9241: function checkNewSpares(lonhost,type) {
9242: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
9243: var chosen = newSpare.options[newSpare.selectedIndex].value;
9244: if (chosen != '') {
9245: var othertype;
9246: var othernewSpare;
9247: if (type == 'primary') {
9248: othernewSpare = document.getElementById('newspare_default_'+lonhost);
9249: }
9250: if (type == 'default') {
9251: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
9252: }
9253: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
9254: othernewSpare.selectedIndex = 0;
9255: }
9256: }
9257: return;
9258: }
9259:
9260: // ]]>
9261: </script>
9262:
9263: END
9264:
9265: }
9266:
9267: sub common_domprefs_js {
9268: return <<"END";
9269:
9270: <script type="text/javascript">
9271: // <![CDATA[
9272:
1.150 raeburn 9273: function getIndicesByName(formname,item) {
1.152 raeburn 9274: var group = new Array();
1.150 raeburn 9275: for (var i=0;i<formname.elements.length;i++) {
9276: if (formname.elements[i].name == item) {
1.152 raeburn 9277: group.push(formname.elements[i].id);
1.150 raeburn 9278: }
9279: }
1.152 raeburn 9280: return group;
1.150 raeburn 9281: }
9282:
9283: // ]]>
9284: </script>
9285:
9286: END
1.152 raeburn 9287:
1.150 raeburn 9288: }
9289:
1.160.6.5 raeburn 9290: sub recaptcha_js {
9291: my %lt = &captcha_phrases();
9292: return <<"END";
9293:
9294: <script type="text/javascript">
9295: // <![CDATA[
9296:
9297: function updateCaptcha(caller,context) {
9298: var privitem;
9299: var pubitem;
9300: var privtext;
9301: var pubtext;
9302: if (document.getElementById(context+'_recaptchapub')) {
9303: pubitem = document.getElementById(context+'_recaptchapub');
9304: } else {
9305: return;
9306: }
9307: if (document.getElementById(context+'_recaptchapriv')) {
9308: privitem = document.getElementById(context+'_recaptchapriv');
9309: } else {
9310: return;
9311: }
9312: if (document.getElementById(context+'_recaptchapubtxt')) {
9313: pubtext = document.getElementById(context+'_recaptchapubtxt');
9314: } else {
9315: return;
9316: }
9317: if (document.getElementById(context+'_recaptchaprivtxt')) {
9318: privtext = document.getElementById(context+'_recaptchaprivtxt');
9319: } else {
9320: return;
9321: }
9322: if (caller.checked) {
9323: if (caller.value == 'recaptcha') {
9324: pubitem.type = 'text';
9325: privitem.type = 'text';
9326: pubitem.size = '40';
9327: privitem.size = '40';
9328: pubtext.innerHTML = "$lt{'pub'}";
9329: privtext.innerHTML = "$lt{'priv'}";
9330: } else {
9331: pubitem.type = 'hidden';
9332: privitem.type = 'hidden';
9333: pubtext.innerHTML = '';
9334: privtext.innerHTML = '';
9335: }
9336: }
9337: return;
9338: }
9339:
9340: // ]]>
9341: </script>
9342:
9343: END
9344:
9345: }
9346:
1.160.6.16 raeburn 9347: sub credits_js {
9348: return <<"END";
9349:
9350: <script type="text/javascript">
9351: // <![CDATA[
9352:
9353: function toggleCredits(domForm) {
9354: if (document.getElementById('credits')) {
9355: creditsitem = document.getElementById('credits');
9356: var creditsLength = domForm.coursecredits.length;
9357: if (creditsLength) {
9358: var currval;
9359: for (var i=0; i<creditsLength; i++) {
9360: if (domForm.coursecredits[i].checked) {
9361: currval = domForm.coursecredits[i].value;
9362: }
9363: }
9364: if (currval == 1) {
9365: creditsitem.style.display = 'block';
9366: } else {
9367: creditsitem.style.display = 'none';
9368: }
9369: }
9370: }
9371: return;
9372: }
9373:
9374: // ]]>
9375: </script>
9376:
9377: END
9378:
9379: }
9380:
1.160.6.5 raeburn 9381: sub captcha_phrases {
9382: return &Apache::lonlocal::texthash (
9383: priv => 'Private key',
9384: pub => 'Public key',
9385: original => 'original (CAPTCHA)',
9386: recaptcha => 'successor (ReCAPTCHA)',
9387: notused => 'unused',
9388: );
9389: }
9390:
1.160.6.24 raeburn 9391: sub devalidate_remote_domconfs {
1.160.6.27! raeburn 9392: my ($dom,$cachekeys) = @_;
! 9393: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 9394: my %servers = &Apache::lonnet::internet_dom_servers($dom);
9395: my %thismachine;
9396: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.27! raeburn 9397: my @posscached = ('domainconfig','domdefaults');
1.160.6.24 raeburn 9398: if (keys(%servers) > 1) {
9399: foreach my $server (keys(%servers)) {
9400: next if ($thismachine{$server});
1.160.6.27! raeburn 9401: my @cached;
! 9402: foreach my $name (@posscached) {
! 9403: if ($cachekeys->{$name}) {
! 9404: push(@cached,&escape($name).':'.&escape($dom));
! 9405: }
! 9406: }
! 9407: if (@cached) {
! 9408: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
! 9409: }
1.160.6.24 raeburn 9410: }
9411: }
9412: return;
9413: }
9414:
1.3 raeburn 9415: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>