Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.30
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.30! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.29 2013/12/23 14:34:35 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
1.160.6.30! raeburn 106: (official, unofficial, community, and textbook). In each case the radio buttons
! 107: allow the selection of one of four values:
1.101 raeburn 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.28 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',
1.160.6.30! raeburn 330: col2 => 'Value'},
! 331: {col1 => 'Available textbooks',
! 332: col2 => ''}],
1.86 raeburn 333: },
1.160.6.5 raeburn 334: 'requestauthor' =>
335: {text => 'Request authoring space',
336: help => 'Domain_Configuration_Request_Author',
337: header => [{col1 => 'User affiliation',
338: col2 => 'Availability/Processing of requests',},
339: {col1 => 'Setting',
340: col2 => 'Value'}],
341: },
1.69 raeburn 342: 'coursecategories' =>
1.120 raeburn 343: { text => 'Cataloging of courses/communities',
1.67 raeburn 344: help => 'Domain_Configuration_Cataloging_Courses',
1.69 raeburn 345: header => [{col1 => 'Category settings',
1.57 raeburn 346: col2 => '',},
347: {col1 => 'Categories',
348: col2 => '',
349: }],
1.69 raeburn 350: },
351: 'serverstatuses' =>
1.77 raeburn 352: {text => 'Access to server status pages',
1.69 raeburn 353: help => 'Domain_Configuration_Server_Status',
354: header => [{col1 => 'Status Page',
355: col2 => 'Other named users',
356: col3 => 'Specific IPs',
357: }],
358: },
1.160.6.16 raeburn 359: 'coursedefaults' =>
360: {text => 'Course/Community defaults',
361: help => 'Domain_Configuration_Course_Defaults',
362: header => [{col1 => 'Defaults which can be overridden for each course by a DC',
363: col2 => 'Value',},],
364: },
1.141 raeburn 365: 'usersessions' =>
1.145 raeburn 366: {text => 'User session hosting/offloading',
1.137 raeburn 367: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 368: header => [{col1 => 'Domain server',
369: col2 => 'Servers to offload sessions to when busy'},
370: {col1 => 'Hosting of users from other domains',
1.137 raeburn 371: col2 => 'Rules'},
372: {col1 => "Hosting domain's own users elsewhere",
373: col2 => 'Rules'}],
374: },
1.150 raeburn 375: 'loadbalancing' =>
1.160.6.7 raeburn 376: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 377: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 378: header => [{col1 => 'Balancers',
1.150 raeburn 379: col2 => 'Default destinations',
1.160.6.13 raeburn 380: col3 => 'User affiliation',
1.150 raeburn 381: col4 => 'Overrides'},
382: ],
383: },
1.3 raeburn 384: );
1.110 raeburn 385: if (keys(%servers) > 1) {
386: $prefs{'login'} = { text => 'Log-in page options',
387: help => 'Domain_Configuration_Login_Page',
388: header => [{col1 => 'Log-in Service',
389: col2 => 'Server Setting',},
390: {col1 => 'Log-in Page Items',
1.160.6.5 raeburn 391: col2 => ''},
392: {col1 => 'Log-in Help',
393: col2 => 'Value'}],
1.110 raeburn 394: };
395: }
1.160.6.13 raeburn 396:
1.6 raeburn 397: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 398: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 399: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 400: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 401: text=>"Settings to display/modify"});
1.9 raeburn 402: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 403:
1.3 raeburn 404: if ($phase eq 'process') {
1.160.6.27 raeburn 405: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
406: \%prefs,\%domconfig,$confname,\@roles);
407: if (ref($result) eq 'HASH') {
1.160.6.24 raeburn 408: $r->rflush();
1.160.6.27 raeburn 409: &devalidate_remote_domconfs($dom,$result);
1.160.6.24 raeburn 410: }
1.30 raeburn 411: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 412: my $js = &recaptcha_js().
1.160.6.26 raeburn 413: &credits_js();
1.160.6.7 raeburn 414: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 415: my ($othertitle,$usertypes,$types) =
416: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 417: $js .= &lonbalance_targets_js($dom,$types,\%servers,
418: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 419: &new_spares_js().
420: &common_domprefs_js().
421: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 422: }
1.160.6.30! raeburn 423: if (grep(/^requestcourses$/,@actions)) {
! 424: my $javascript_validations;
! 425: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
! 426: $js .= <<END;
! 427: <script type="text/javascript">
! 428: $javascript_validations
! 429: </script>
! 430: $coursebrowserjs
! 431: END
! 432: }
1.150 raeburn 433: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 434: } else {
1.160.6.11 raeburn 435: # check if domconfig user exists for the domain.
436: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 437: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 438: &config_check($dom,$confname,$servadm);
439: unless ($configuserok eq 'ok') {
440: &Apache::lonconfigsettings::print_header($r,$phase,$context);
441: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
442: $confname).
443: '<br />'
444: );
445: if ($switchserver) {
446: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
447: '<br />'.
448: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
449: '<br />'.
450: &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).
451: '<br />'.
452: &mt('To do that now, use the following link: [_1]',$switchserver)
453: );
454: } else {
455: $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.').
456: '<br />'.
457: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
458: );
459: }
460: $r->print(&Apache::loncommon::end_page());
461: return OK;
462: }
1.21 raeburn 463: if (keys(%domconfig) == 0) {
464: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 465: my @ids=&Apache::lonnet::current_machine_ids();
466: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 467: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 468: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 469: my $custom_img_count = 0;
470: foreach my $img (@loginimages) {
471: if ($designhash{$dom.'.login.'.$img} ne '') {
472: $custom_img_count ++;
473: }
474: }
475: foreach my $role (@roles) {
476: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
477: $custom_img_count ++;
478: }
479: }
480: if ($custom_img_count > 0) {
1.94 raeburn 481: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 482: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 483: $r->print(
484: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
485: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
486: &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 />'.
487: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
488: if ($switch_server) {
1.30 raeburn 489: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 490: }
1.91 raeburn 491: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 492: return OK;
493: }
494: }
495: }
1.91 raeburn 496: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 497: }
498: return OK;
499: }
500:
501: sub process_changes {
1.160.6.24 raeburn 502: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 503: my %domconfig;
504: if (ref($values) eq 'HASH') {
505: %domconfig = %{$values};
506: }
1.3 raeburn 507: my $output;
508: if ($action eq 'login') {
1.160.6.24 raeburn 509: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 510: } elsif ($action eq 'rolecolors') {
1.9 raeburn 511: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 512: $lastactref,%domconfig);
1.3 raeburn 513: } elsif ($action eq 'quotas') {
1.160.6.30! raeburn 514: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 515: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 516: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 517: } elsif ($action eq 'autoupdate') {
518: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 519: } elsif ($action eq 'autocreate') {
520: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 521: } elsif ($action eq 'directorysrch') {
522: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 523: } elsif ($action eq 'usercreation') {
1.28 raeburn 524: $output = &modify_usercreation($dom,%domconfig);
1.33 raeburn 525: } elsif ($action eq 'usermodification') {
526: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 527: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 528: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 529: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 530: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 531: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 532: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 533: } elsif ($action eq 'coursecategories') {
534: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 535: } elsif ($action eq 'serverstatuses') {
536: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 537: } elsif ($action eq 'requestcourses') {
1.160.6.30! raeburn 538: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 539: } elsif ($action eq 'requestauthor') {
1.160.6.30! raeburn 540: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.16 raeburn 541: } elsif ($action eq 'coursedefaults') {
1.160.6.27 raeburn 542: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.137 raeburn 543: } elsif ($action eq 'usersessions') {
1.160.6.27 raeburn 544: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 545: } elsif ($action eq 'loadbalancing') {
546: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 547: }
548: return $output;
549: }
550:
551: sub print_config_box {
1.9 raeburn 552: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 553: my $rowtotal = 0;
1.49 raeburn 554: my $output;
555: if ($action eq 'coursecategories') {
556: $output = &coursecategories_javascript($settings);
1.91 raeburn 557: }
1.49 raeburn 558: $output .=
1.30 raeburn 559: '<table class="LC_nested_outer">
1.3 raeburn 560: <tr>
1.66 raeburn 561: <th align="left" valign="middle"><span class="LC_nobreak">'.
562: &mt($item->{text}).' '.
563: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
564: '</tr>';
1.30 raeburn 565: $rowtotal ++;
1.110 raeburn 566: my $numheaders = 1;
567: if (ref($item->{'header'}) eq 'ARRAY') {
568: $numheaders = scalar(@{$item->{'header'}});
569: }
570: if ($numheaders > 1) {
1.64 raeburn 571: my $colspan = '';
1.145 raeburn 572: my $rightcolspan = '';
1.160.6.5 raeburn 573: if (($action eq 'rolecolors') || ($action eq 'coursecategories') ||
574: (($action eq 'login') && ($numheaders < 3))) {
1.64 raeburn 575: $colspan = ' colspan="2"';
576: }
1.145 raeburn 577: if ($action eq 'usersessions') {
578: $rightcolspan = ' colspan="3"';
579: }
1.30 raeburn 580: $output .= '
1.3 raeburn 581: <tr>
582: <td>
583: <table class="LC_nested">
584: <tr class="LC_info_row">
1.59 bisitz 585: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 586: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 587: </tr>';
1.69 raeburn 588: $rowtotal ++;
1.6 raeburn 589: if ($action eq 'autoupdate') {
1.30 raeburn 590: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 591: } elsif ($action eq 'usercreation') {
1.33 raeburn 592: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
593: } elsif ($action eq 'usermodification') {
594: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57 raeburn 595: } elsif ($action eq 'coursecategories') {
596: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 597: } elsif ($action eq 'login') {
1.160.6.5 raeburn 598: if ($numheaders == 3) {
599: $colspan = ' colspan="2"';
600: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
601: } else {
602: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
603: }
1.102 raeburn 604: } elsif ($action eq 'requestcourses') {
605: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.5 raeburn 606: } elsif ($action eq 'requestauthor') {
607: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.137 raeburn 608: } elsif ($action eq 'usersessions') {
609: $output .= &print_usersessions('top',$dom,$settings,\$rowtotal);
1.122 jms 610: } elsif ($action eq 'rolecolors') {
1.30 raeburn 611: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 612: }
1.30 raeburn 613: $output .= '
1.6 raeburn 614: </table>
615: </td>
616: </tr>
617: <tr>
618: <td>
619: <table class="LC_nested">
620: <tr class="LC_info_row">
1.59 bisitz 621: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57 raeburn 622: $output .= '
1.59 bisitz 623: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 624: </tr>';
625: $rowtotal ++;
1.6 raeburn 626: if ($action eq 'autoupdate') {
1.131 raeburn 627: $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
628: </table>
629: </td>
630: </tr>
631: <tr>
632: <td>
633: <table class="LC_nested">
634: <tr class="LC_info_row">
635: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
636: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
637: &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
638: $rowtotal ++;
1.28 raeburn 639: } elsif ($action eq 'usercreation') {
1.34 raeburn 640: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
641: </table>
642: </td>
643: </tr>
644: <tr>
645: <td>
646: <table class="LC_nested">
647: <tr class="LC_info_row">
1.59 bisitz 648: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
649: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.34 raeburn 650: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
651: $rowtotal ++;
1.33 raeburn 652: } elsif ($action eq 'usermodification') {
1.63 raeburn 653: $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
654: </table>
655: </td>
656: </tr>
657: <tr>
658: <td>
659: <table class="LC_nested">
660: <tr class="LC_info_row">
661: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30! raeburn 662: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.63 raeburn 663: &print_usermodification('bottom',$dom,$settings,\$rowtotal);
664: $rowtotal ++;
1.57 raeburn 665: } elsif ($action eq 'coursecategories') {
666: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 667: } elsif ($action eq 'login') {
1.160.6.5 raeburn 668: if ($numheaders == 3) {
669: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
670: </table>
671: </td>
672: </tr>
673: <tr>
674: <td>
675: <table class="LC_nested">
676: <tr class="LC_info_row">
677: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30! raeburn 678: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 679: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
680: $rowtotal ++;
681: } else {
682: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
683: }
1.102 raeburn 684: } elsif ($action eq 'requestcourses') {
1.160.6.30! raeburn 685: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal).
! 686: &print_studentcode($settings,\$rowtotal).'
! 687: </table>
! 688: </td>
! 689: </tr>
! 690: <tr>
! 691: <td>
! 692: <table class="LC_nested">
! 693: <tr class="LC_info_row">
! 694: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
! 695: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
! 696: &print_textbookcourses($dom,$settings,\$rowtotal);
1.160.6.5 raeburn 697: } elsif ($action eq 'requestauthor') {
698: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.137 raeburn 699: } elsif ($action eq 'usersessions') {
1.145 raeburn 700: $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
701: </table>
702: </td>
703: </tr>
704: <tr>
705: <td>
706: <table class="LC_nested">
707: <tr class="LC_info_row">
708: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
709: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
710: &print_usersessions('bottom',$dom,$settings,\$rowtotal);
711: $rowtotal ++;
1.122 jms 712: } elsif ($action eq 'rolecolors') {
1.30 raeburn 713: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 714: </table>
715: </td>
716: </tr>
717: <tr>
718: <td>
719: <table class="LC_nested">
720: <tr class="LC_info_row">
1.69 raeburn 721: <td class="LC_left_item"'.$colspan.' valign="top">'.
722: &mt($item->{'header'}->[2]->{'col1'}).'</td>
723: <td class="LC_right_item" valign="top">'.
724: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 725: </tr>'.
1.30 raeburn 726: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 727: </table>
728: </td>
729: </tr>
730: <tr>
731: <td>
732: <table class="LC_nested">
733: <tr class="LC_info_row">
1.59 bisitz 734: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
735: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 736: </tr>'.
1.30 raeburn 737: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
738: $rowtotal += 2;
1.6 raeburn 739: }
1.3 raeburn 740: } else {
1.30 raeburn 741: $output .= '
1.3 raeburn 742: <tr>
743: <td>
744: <table class="LC_nested">
1.30 raeburn 745: <tr class="LC_info_row">';
1.24 raeburn 746: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 747: $output .= '
1.59 bisitz 748: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 749: } elsif ($action eq 'serverstatuses') {
750: $output .= '
751: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
752: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
753:
1.6 raeburn 754: } else {
1.30 raeburn 755: $output .= '
1.69 raeburn 756: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
757: }
1.72 raeburn 758: if (defined($item->{'header'}->[0]->{'col3'})) {
759: $output .= '<td class="LC_left_item" valign="top">'.
760: &mt($item->{'header'}->[0]->{'col2'});
761: if ($action eq 'serverstatuses') {
762: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
763: }
1.69 raeburn 764: } else {
765: $output .= '<td class="LC_right_item" valign="top">'.
766: &mt($item->{'header'}->[0]->{'col2'});
767: }
768: $output .= '</td>';
769: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 770: if (defined($item->{'header'}->[0]->{'col4'})) {
771: $output .= '<td class="LC_left_item" valign="top">'.
772: &mt($item->{'header'}->[0]->{'col3'});
773: } else {
774: $output .= '<td class="LC_right_item" valign="top">'.
775: &mt($item->{'header'}->[0]->{'col3'});
776: }
1.69 raeburn 777: if ($action eq 'serverstatuses') {
778: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
779: }
780: $output .= '</td>';
1.6 raeburn 781: }
1.150 raeburn 782: if ($item->{'header'}->[0]->{'col4'}) {
783: $output .= '<td class="LC_right_item" valign="top">'.
784: &mt($item->{'header'}->[0]->{'col4'});
785: }
1.69 raeburn 786: $output .= '</tr>';
1.48 raeburn 787: $rowtotal ++;
1.160.6.5 raeburn 788: if ($action eq 'quotas') {
1.86 raeburn 789: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3 raeburn 790: } elsif ($action eq 'autoenroll') {
1.30 raeburn 791: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125 raeburn 792: } elsif ($action eq 'autocreate') {
793: $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23 raeburn 794: } elsif ($action eq 'directorysrch') {
1.30 raeburn 795: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 796: } elsif ($action eq 'contacts') {
1.30 raeburn 797: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 raeburn 798: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 799: $output .= &print_defaults($dom,$settings,\$rowtotal);
1.46 raeburn 800: } elsif ($action eq 'scantron') {
801: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69 raeburn 802: } elsif ($action eq 'serverstatuses') {
803: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118 jms 804: } elsif ($action eq 'helpsettings') {
1.160.6.5 raeburn 805: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.150 raeburn 806: } elsif ($action eq 'loadbalancing') {
807: $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.160.6.16 raeburn 808: } elsif ($action eq 'coursedefaults') {
809: $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.121 raeburn 810: }
1.3 raeburn 811: }
1.30 raeburn 812: $output .= '
1.3 raeburn 813: </table>
814: </td>
815: </tr>
1.30 raeburn 816: </table><br />';
817: return ($output,$rowtotal);
1.1 raeburn 818: }
819:
1.3 raeburn 820: sub print_login {
1.160.6.5 raeburn 821: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 822: my ($css_class,$datatable);
1.6 raeburn 823: my %choices = &login_choices();
1.110 raeburn 824:
1.160.6.5 raeburn 825: if ($caller eq 'service') {
1.149 raeburn 826: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 827: my $choice = $choices{'disallowlogin'};
828: $css_class = ' class="LC_odd_row"';
1.128 raeburn 829: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 830: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 831: '<th>'.$choices{'server'}.'</th>'.
832: '<th>'.$choices{'serverpath'}.'</th>'.
833: '<th>'.$choices{'custompath'}.'</th>'.
834: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 835: my %disallowed;
836: if (ref($settings) eq 'HASH') {
837: if (ref($settings->{'loginvia'}) eq 'HASH') {
838: %disallowed = %{$settings->{'loginvia'}};
839: }
840: }
841: foreach my $lonhost (sort(keys(%servers))) {
842: my $direct = 'selected="selected"';
1.128 raeburn 843: if (ref($disallowed{$lonhost}) eq 'HASH') {
844: if ($disallowed{$lonhost}{'server'} ne '') {
845: $direct = '';
846: }
1.110 raeburn 847: }
1.115 raeburn 848: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 849: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 850: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
851: '</option>';
1.160.6.13 raeburn 852: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 853: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 854: my $selected = '';
1.128 raeburn 855: if (ref($disallowed{$lonhost}) eq 'HASH') {
856: if ($hostid eq $disallowed{$lonhost}{'server'}) {
857: $selected = 'selected="selected"';
858: }
1.110 raeburn 859: }
860: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
861: $servers{$hostid}.'</option>';
862: }
1.128 raeburn 863: $datatable .= '</select></td>'.
864: '<td><select name="'.$lonhost.'_serverpath">';
865: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
866: my $pathname = $path;
867: if ($path eq 'custom') {
868: $pathname = &mt('Custom Path').' ->';
869: }
870: my $selected = '';
871: if (ref($disallowed{$lonhost}) eq 'HASH') {
872: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
873: $selected = 'selected="selected"';
874: }
875: } elsif ($path eq '') {
876: $selected = 'selected="selected"';
877: }
878: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
879: }
880: $datatable .= '</select></td>';
881: my ($custom,$exempt);
882: if (ref($disallowed{$lonhost}) eq 'HASH') {
883: $custom = $disallowed{$lonhost}{'custompath'};
884: $exempt = $disallowed{$lonhost}{'exempt'};
885: }
886: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
887: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
888: '</tr>';
1.110 raeburn 889: }
890: $datatable .= '</table></td></tr>';
891: return $datatable;
1.160.6.5 raeburn 892: } elsif ($caller eq 'page') {
893: my %defaultchecked = (
894: 'coursecatalog' => 'on',
1.160.6.14 raeburn 895: 'helpdesk' => 'on',
1.160.6.5 raeburn 896: 'adminmail' => 'off',
897: 'newuser' => 'off',
898: );
1.160.6.14 raeburn 899: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 900: my (%checkedon,%checkedoff);
1.42 raeburn 901: foreach my $item (@toggles) {
1.160.6.5 raeburn 902: if ($defaultchecked{$item} eq 'on') {
903: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 904: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 905: } elsif ($defaultchecked{$item} eq 'off') {
906: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 907: $checkedon{$item} = ' ';
908: }
1.1 raeburn 909: }
1.160.6.5 raeburn 910: my @images = ('img','logo','domlogo','login');
911: my @logintext = ('textcol','bgcol');
912: my @bgs = ('pgbg','mainbg','sidebg');
913: my @links = ('link','alink','vlink');
914: my %designhash = &Apache::loncommon::get_domainconf($dom);
915: my %defaultdesign = %Apache::loncommon::defaultdesign;
916: my (%is_custom,%designs);
917: my %defaults = (
918: font => $defaultdesign{'login.font'},
919: );
1.6 raeburn 920: foreach my $item (@images) {
1.160.6.5 raeburn 921: $defaults{$item} = $defaultdesign{'login.'.$item};
922: $defaults{'showlogo'}{$item} = 1;
923: }
924: foreach my $item (@bgs) {
925: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 926: }
1.41 raeburn 927: foreach my $item (@logintext) {
1.160.6.5 raeburn 928: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 929: }
1.160.6.5 raeburn 930: foreach my $item (@links) {
931: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 932: }
1.160.6.5 raeburn 933: if (ref($settings) eq 'HASH') {
934: foreach my $item (@toggles) {
935: if ($settings->{$item} eq '1') {
936: $checkedon{$item} = ' checked="checked" ';
937: $checkedoff{$item} = ' ';
938: } elsif ($settings->{$item} eq '0') {
939: $checkedoff{$item} = ' checked="checked" ';
940: $checkedon{$item} = ' ';
941: }
1.6 raeburn 942: }
1.160.6.5 raeburn 943: foreach my $item (@images) {
944: if (defined($settings->{$item})) {
945: $designs{$item} = $settings->{$item};
946: $is_custom{$item} = 1;
947: }
948: if (defined($settings->{'showlogo'}{$item})) {
949: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
950: }
951: }
952: foreach my $item (@logintext) {
953: if ($settings->{$item} ne '') {
954: $designs{'logintext'}{$item} = $settings->{$item};
955: $is_custom{$item} = 1;
956: }
957: }
958: if ($settings->{'font'} ne '') {
959: $designs{'font'} = $settings->{'font'};
960: $is_custom{'font'} = 1;
961: }
962: foreach my $item (@bgs) {
963: if ($settings->{$item} ne '') {
964: $designs{'bgs'}{$item} = $settings->{$item};
965: $is_custom{$item} = 1;
966: }
967: }
968: foreach my $item (@links) {
969: if ($settings->{$item} ne '') {
970: $designs{'links'}{$item} = $settings->{$item};
971: $is_custom{$item} = 1;
972: }
973: }
974: } else {
975: if ($designhash{$dom.'.login.font'} ne '') {
976: $designs{'font'} = $designhash{$dom.'.login.font'};
977: $is_custom{'font'} = 1;
978: }
979: foreach my $item (@images) {
980: if ($designhash{$dom.'.login.'.$item} ne '') {
981: $designs{$item} = $designhash{$dom.'.login.'.$item};
982: $is_custom{$item} = 1;
983: }
984: }
985: foreach my $item (@bgs) {
986: if ($designhash{$dom.'.login.'.$item} ne '') {
987: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
988: $is_custom{$item} = 1;
989: }
990: }
991: foreach my $item (@links) {
992: if ($designhash{$dom.'.login.'.$item} ne '') {
993: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
994: $is_custom{$item} = 1;
995: }
1.6 raeburn 996: }
997: }
1.160.6.5 raeburn 998: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
999: logo => 'Institution Logo',
1000: domlogo => 'Domain Logo',
1001: login => 'Login box');
1002: my $itemcount = 1;
1003: foreach my $item (@toggles) {
1004: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1005: $datatable .=
1006: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1007: '</td><td>'.
1008: '<span class="LC_nobreak"><label><input type="radio" name="'.
1009: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1010: '</label> <label><input type="radio" name="'.$item.'"'.
1011: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1012: '</tr>';
1013: $itemcount ++;
1.6 raeburn 1014: }
1.160.6.5 raeburn 1015: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1016: $datatable .= '</tr></table></td></tr>';
1017: } elsif ($caller eq 'help') {
1018: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1019: my $switchserver = &check_switchserver($dom,$confname);
1020: my $itemcount = 1;
1021: $defaulturl = '/adm/loginproblems.html';
1022: $defaulttype = 'default';
1023: %lt = &Apache::lonlocal::texthash (
1024: del => 'Delete?',
1025: rep => 'Replace:',
1026: upl => 'Upload:',
1027: default => 'Default',
1028: custom => 'Custom',
1029: );
1030: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1031: my @currlangs;
1032: if (ref($settings) eq 'HASH') {
1033: if (ref($settings->{'helpurl'}) eq 'HASH') {
1034: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1035: next if ($settings->{'helpurl'}{$key} eq '');
1036: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1037: $type{$key} = 'custom';
1038: unless ($key eq 'nolang') {
1039: push(@currlangs,$key);
1040: }
1041: }
1042: } elsif ($settings->{'helpurl'} ne '') {
1043: $type{'nolang'} = 'custom';
1044: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1045: }
1046: }
1.160.6.5 raeburn 1047: foreach my $lang ('nolang',sort(@currlangs)) {
1048: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1049: $datatable .= '<tr'.$css_class.'>';
1050: if ($url{$lang} eq '') {
1051: $url{$lang} = $defaulturl;
1052: }
1053: if ($type{$lang} eq '') {
1054: $type{$lang} = $defaulttype;
1055: }
1056: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1057: if ($lang eq 'nolang') {
1058: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1059: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1060: } else {
1061: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1062: $langchoices{$lang},
1063: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1064: }
1065: $datatable .= '</span></td>'."\n".
1066: '<td class="LC_left_item">';
1067: if ($type{$lang} eq 'custom') {
1068: $datatable .= '<span class="LC_nobreak"><label>'.
1069: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1070: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1071: } else {
1072: $datatable .= $lt{'upl'};
1073: }
1074: $datatable .='<br />';
1075: if ($switchserver) {
1076: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1077: } else {
1078: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1079: }
1.160.6.5 raeburn 1080: $datatable .= '</td></tr>';
1081: $itemcount ++;
1.6 raeburn 1082: }
1.160.6.5 raeburn 1083: my @addlangs;
1084: foreach my $lang (sort(keys(%langchoices))) {
1085: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1086: push(@addlangs,$lang);
1087: }
1088: if (@addlangs > 0) {
1089: my %toadd;
1090: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1091: $toadd{''} = &mt('Select');
1092: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1093: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1094: &mt('Add log-in help page for a specific language:').' '.
1095: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1096: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1097: if ($switchserver) {
1098: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1099: } else {
1100: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1101: }
1.160.6.5 raeburn 1102: $datatable .= '</td></tr>';
1103: $itemcount ++;
1.6 raeburn 1104: }
1.160.6.5 raeburn 1105: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1 raeburn 1106: }
1.6 raeburn 1107: return $datatable;
1108: }
1109:
1110: sub login_choices {
1111: my %choices =
1112: &Apache::lonlocal::texthash (
1.116 bisitz 1113: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1114: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1115: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1116: disallowlogin => "Login page requests redirected",
1117: hostid => "Server",
1.128 raeburn 1118: server => "Redirect to:",
1119: serverpath => "Path",
1120: custompath => "Custom",
1121: exempt => "Exempt IP(s)",
1.110 raeburn 1122: directlogin => "No redirect",
1123: newuser => "Link to create a user account",
1124: img => "Header",
1125: logo => "Main Logo",
1126: domlogo => "Domain Logo",
1127: login => "Log-in Header",
1128: textcol => "Text color",
1129: bgcol => "Box color",
1130: bgs => "Background colors",
1131: links => "Link colors",
1132: font => "Font color",
1133: pgbg => "Header",
1134: mainbg => "Page",
1135: sidebg => "Login box",
1136: link => "Link",
1137: alink => "Active link",
1138: vlink => "Visited link",
1.6 raeburn 1139: );
1140: return %choices;
1141: }
1142:
1143: sub print_rolecolors {
1.30 raeburn 1144: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1145: my %choices = &color_font_choices();
1146: my @bgs = ('pgbg','tabbg','sidebg');
1147: my @links = ('link','alink','vlink');
1148: my @images = ('img');
1149: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1150: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1151: my %defaultdesign = %Apache::loncommon::defaultdesign;
1152: my (%is_custom,%designs);
1.160.6.22 raeburn 1153: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1154: if (ref($settings) eq 'HASH') {
1155: if (ref($settings->{$role}) eq 'HASH') {
1156: if ($settings->{$role}->{'img'} ne '') {
1157: $designs{'img'} = $settings->{$role}->{'img'};
1158: $is_custom{'img'} = 1;
1159: }
1160: if ($settings->{$role}->{'font'} ne '') {
1161: $designs{'font'} = $settings->{$role}->{'font'};
1162: $is_custom{'font'} = 1;
1163: }
1.97 tempelho 1164: if ($settings->{$role}->{'fontmenu'} ne '') {
1165: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1166: $is_custom{'fontmenu'} = 1;
1167: }
1.6 raeburn 1168: foreach my $item (@bgs) {
1169: if ($settings->{$role}->{$item} ne '') {
1170: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1171: $is_custom{$item} = 1;
1172: }
1173: }
1174: foreach my $item (@links) {
1175: if ($settings->{$role}->{$item} ne '') {
1176: $designs{'links'}{$item} = $settings->{$role}->{$item};
1177: $is_custom{$item} = 1;
1178: }
1179: }
1180: }
1181: } else {
1182: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1183: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1184: $is_custom{'img'} = 1;
1185: }
1.97 tempelho 1186: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1187: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1188: $is_custom{'fontmenu'} = 1;
1189: }
1.6 raeburn 1190: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1191: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1192: $is_custom{'font'} = 1;
1193: }
1194: foreach my $item (@bgs) {
1195: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1196: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1197: $is_custom{$item} = 1;
1198:
1199: }
1200: }
1201: foreach my $item (@links) {
1202: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1203: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1204: $is_custom{$item} = 1;
1205: }
1206: }
1207: }
1208: my $itemcount = 1;
1.30 raeburn 1209: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1210: $datatable .= '</tr></table></td></tr>';
1211: return $datatable;
1212: }
1213:
1.160.6.22 raeburn 1214: sub role_defaults {
1215: my ($role,$bgs,$links,$images,$logintext) = @_;
1216: my %defaults;
1217: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1218: return %defaults;
1219: }
1220: my %defaultdesign = %Apache::loncommon::defaultdesign;
1221: if ($role eq 'login') {
1222: %defaults = (
1223: font => $defaultdesign{$role.'.font'},
1224: );
1225: if (ref($logintext) eq 'ARRAY') {
1226: foreach my $item (@{$logintext}) {
1227: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1228: }
1229: }
1230: foreach my $item (@{$images}) {
1231: $defaults{'showlogo'}{$item} = 1;
1232: }
1233: } else {
1234: %defaults = (
1235: img => $defaultdesign{$role.'.img'},
1236: font => $defaultdesign{$role.'.font'},
1237: fontmenu => $defaultdesign{$role.'.fontmenu'},
1238: );
1239: }
1240: foreach my $item (@{$bgs}) {
1241: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1242: }
1243: foreach my $item (@{$links}) {
1244: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1245: }
1246: foreach my $item (@{$images}) {
1247: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1248: }
1249: return %defaults;
1250: }
1251:
1.6 raeburn 1252: sub display_color_options {
1.9 raeburn 1253: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1254: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1255: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1256: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1257: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1258: '<td>'.$choices->{'font'}.'</td>';
1259: if (!$is_custom->{'font'}) {
1.30 raeburn 1260: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1261: } else {
1262: $datatable .= '<td> </td>';
1263: }
1.160.6.9 raeburn 1264: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1265:
1.8 raeburn 1266: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1267: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1268: ' value="'.$current_color.'" /> '.
1269: ' </td></tr>';
1.107 raeburn 1270: unless ($role eq 'login') {
1271: $datatable .= '<tr'.$css_class.'>'.
1272: '<td>'.$choices->{'fontmenu'}.'</td>';
1273: if (!$is_custom->{'fontmenu'}) {
1274: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1275: } else {
1276: $datatable .= '<td> </td>';
1277: }
1.160.6.22 raeburn 1278: $current_color = $designs->{'fontmenu'} ?
1279: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1280: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1281: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1282: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1283: ' value="'.$current_color.'" /> '.
1284: ' </td></tr>';
1.97 tempelho 1285: }
1.9 raeburn 1286: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1287: foreach my $img (@{$images}) {
1.18 albertel 1288: $itemcount ++;
1.6 raeburn 1289: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1290: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1291: '<td>'.$choices->{$img};
1.41 raeburn 1292: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1293: if ($role eq 'login') {
1294: if ($img eq 'login') {
1295: $login_hdr_pick =
1.135 bisitz 1296: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1297: $logincolors =
1298: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1299: $designs,$defaults);
1.70 raeburn 1300: } elsif ($img ne 'domlogo') {
1301: $datatable.= &logo_display_options($img,$defaults,$designs);
1302: }
1303: }
1304: $datatable .= '</td>';
1.6 raeburn 1305: if ($designs->{$img} ne '') {
1306: $imgfile = $designs->{$img};
1.18 albertel 1307: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1308: } else {
1309: $imgfile = $defaults->{$img};
1310: }
1311: if ($imgfile) {
1.9 raeburn 1312: my ($showfile,$fullsize);
1313: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1314: my $urldir = $1;
1315: my $filename = $2;
1316: my @info = &Apache::lonnet::stat_file($designs->{$img});
1317: if (@info) {
1318: my $thumbfile = 'tn-'.$filename;
1319: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1320: if (@thumb) {
1321: $showfile = $urldir.'/'.$thumbfile;
1322: } else {
1323: $showfile = $imgfile;
1324: }
1325: } else {
1326: $showfile = '';
1327: }
1328: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1329: $showfile = $imgfile;
1.6 raeburn 1330: my $imgdir = $1;
1331: my $filename = $2;
1.159 raeburn 1332: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1333: $showfile = "/$imgdir/tn-".$filename;
1334: } else {
1.159 raeburn 1335: my $input = $londocroot.$imgfile;
1336: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1337: if (!-e $output) {
1.9 raeburn 1338: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1339: my ($fullwidth,$fullheight) = &check_dimensions($input);
1340: if ($fullwidth ne '' && $fullheight ne '') {
1341: if ($fullwidth > $width && $fullheight > $height) {
1342: my $size = $width.'x'.$height;
1343: system("convert -sample $size $input $output");
1.159 raeburn 1344: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1345: }
1346: }
1.6 raeburn 1347: }
1348: }
1.16 raeburn 1349: }
1.6 raeburn 1350: if ($showfile) {
1.40 raeburn 1351: if ($showfile =~ m{^/(adm|res)/}) {
1352: if ($showfile =~ m{^/res/}) {
1353: my $local_showfile =
1354: &Apache::lonnet::filelocation('',$showfile);
1355: &Apache::lonnet::repcopy($local_showfile);
1356: }
1357: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1358: }
1359: if ($imgfile) {
1360: if ($imgfile =~ m{^/(adm|res)/}) {
1361: if ($imgfile =~ m{^/res/}) {
1362: my $local_imgfile =
1363: &Apache::lonnet::filelocation('',$imgfile);
1364: &Apache::lonnet::repcopy($local_imgfile);
1365: }
1366: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1367: } else {
1368: $fullsize = $imgfile;
1369: }
1370: }
1.41 raeburn 1371: $datatable .= '<td>';
1372: if ($img eq 'login') {
1.135 bisitz 1373: $datatable .= $login_hdr_pick;
1374: }
1.41 raeburn 1375: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1376: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1377: } else {
1.160.6.22 raeburn 1378: $datatable .= '<td> </td><td class="LC_left_item">'.
1379: &mt('Upload:').'<br />';
1.6 raeburn 1380: }
1381: } else {
1.160.6.22 raeburn 1382: $datatable .= '<td> </td><td class="LC_left_item">'.
1383: &mt('Upload:').'<br />';
1.6 raeburn 1384: }
1.9 raeburn 1385: if ($switchserver) {
1386: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1387: } else {
1.135 bisitz 1388: if ($img ne 'login') { # suppress file selection for Log-in header
1389: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1390: }
1.9 raeburn 1391: }
1392: $datatable .= '</td></tr>';
1.6 raeburn 1393: }
1394: $itemcount ++;
1395: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1396: $datatable .= '<tr'.$css_class.'>'.
1397: '<td>'.$choices->{'bgs'}.'</td>';
1398: my $bgs_def;
1399: foreach my $item (@{$bgs}) {
1400: if (!$is_custom->{$item}) {
1.70 raeburn 1401: $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 1402: }
1403: }
1404: if ($bgs_def) {
1.8 raeburn 1405: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1406: } else {
1407: $datatable .= '<td> </td>';
1408: }
1409: $datatable .= '<td class="LC_right_item">'.
1410: '<table border="0"><tr>';
1.160.6.13 raeburn 1411:
1.6 raeburn 1412: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1413: $datatable .= '<td align="center">'.$choices->{$item};
1414: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1415: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1416: $datatable .= ' ';
1.6 raeburn 1417: }
1.160.6.9 raeburn 1418: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1419: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1420: }
1421: $datatable .= '</tr></table></td></tr>';
1422: $itemcount ++;
1423: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1424: $datatable .= '<tr'.$css_class.'>'.
1425: '<td>'.$choices->{'links'}.'</td>';
1426: my $links_def;
1427: foreach my $item (@{$links}) {
1428: if (!$is_custom->{$item}) {
1.30 raeburn 1429: $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 1430: }
1431: }
1432: if ($links_def) {
1.8 raeburn 1433: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1434: } else {
1435: $datatable .= '<td> </td>';
1436: }
1437: $datatable .= '<td class="LC_right_item">'.
1438: '<table border="0"><tr>';
1439: foreach my $item (@{$links}) {
1.160.6.22 raeburn 1440: my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
1441: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1442: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1443: $datatable.=' ';
1.6 raeburn 1444: }
1.160.6.9 raeburn 1445: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1446: '" /></td>';
1447: }
1.30 raeburn 1448: $$rowtotal += $itemcount;
1.3 raeburn 1449: return $datatable;
1450: }
1451:
1.70 raeburn 1452: sub logo_display_options {
1453: my ($img,$defaults,$designs) = @_;
1454: my $checkedon;
1455: if (ref($defaults) eq 'HASH') {
1456: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1457: if ($defaults->{'showlogo'}{$img}) {
1458: $checkedon = 'checked="checked" ';
1459: }
1460: }
1461: }
1462: if (ref($designs) eq 'HASH') {
1463: if (ref($designs->{'showlogo'}) eq 'HASH') {
1464: if (defined($designs->{'showlogo'}{$img})) {
1465: if ($designs->{'showlogo'}{$img} == 0) {
1466: $checkedon = '';
1467: } elsif ($designs->{'showlogo'}{$img} == 1) {
1468: $checkedon = 'checked="checked" ';
1469: }
1470: }
1471: }
1472: }
1473: return '<br /><label> <input type="checkbox" name="'.
1474: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1475: &mt('show').'</label>'."\n";
1476: }
1477:
1.41 raeburn 1478: sub login_header_options {
1.135 bisitz 1479: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1480: my $output = '';
1.41 raeburn 1481: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1482: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1483: if (!$is_custom->{'textcol'}) {
1484: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1485: ' ';
1486: }
1487: if (!$is_custom->{'bgcol'}) {
1488: $output .= $choices->{'bgcol'}.': '.
1489: '<span id="css_'.$role.'_font" style="background-color: '.
1490: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1491: }
1492: $output .= '<br />';
1493: }
1494: $output .='<br />';
1495: return $output;
1496: }
1497:
1498: sub login_text_colors {
1.160.6.22 raeburn 1499: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1500: my $color_menu = '<table border="0"><tr>';
1501: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 1502: $color_menu .= '<td align="center">'.$choices->{$item};
1503: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1504: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1505: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1506: }
1507: $color_menu .= '</tr></table><br />';
1508: return $color_menu;
1509: }
1510:
1511: sub image_changes {
1512: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1513: my $output;
1.135 bisitz 1514: if ($img eq 'login') {
1515: # suppress image for Log-in header
1516: } elsif (!$is_custom) {
1.70 raeburn 1517: if ($img ne 'domlogo') {
1.41 raeburn 1518: $output .= &mt('Default image:').'<br />';
1519: } else {
1520: $output .= &mt('Default in use:').'<br />';
1521: }
1522: }
1.135 bisitz 1523: if ($img eq 'login') { # suppress image for Log-in header
1524: $output .= '<td>'.$logincolors;
1.41 raeburn 1525: } else {
1.135 bisitz 1526: if ($img_import) {
1527: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1528: }
1529: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1530: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1531: if ($is_custom) {
1532: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1533: '<input type="checkbox" name="'.
1534: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1535: '</label> '.&mt('Replace:').'</span><br />';
1536: } else {
1.160.6.22 raeburn 1537: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1538: }
1.41 raeburn 1539: }
1540: return $output;
1541: }
1542:
1.3 raeburn 1543: sub print_quotas {
1.86 raeburn 1544: my ($dom,$settings,$rowtotal,$action) = @_;
1545: my $context;
1546: if ($action eq 'quotas') {
1547: $context = 'tools';
1548: } else {
1549: $context = $action;
1550: }
1.160.6.20 raeburn 1551: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1552: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1553: my $typecount = 0;
1.101 raeburn 1554: my ($css_class,%titles);
1.86 raeburn 1555: if ($context eq 'requestcourses') {
1.160.6.30! raeburn 1556: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1557: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1558: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1559: %titles = &courserequest_titles();
1.160.6.5 raeburn 1560: } elsif ($context eq 'requestauthor') {
1561: @usertools = ('author');
1562: @options = ('norequest','approval','automatic');
1563: %titles = &authorrequest_titles();
1.86 raeburn 1564: } else {
1.160.6.4 raeburn 1565: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1566: %titles = &tool_titles();
1.86 raeburn 1567: }
1.26 raeburn 1568: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1569: foreach my $type (@{$types}) {
1.160.6.20 raeburn 1570: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 1571: unless (($context eq 'requestcourses') ||
1572: ($context eq 'requestauthor')) {
1.86 raeburn 1573: if (ref($settings) eq 'HASH') {
1574: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 1575: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1576: } else {
1577: $currdefquota = $settings->{$type};
1578: }
1.160.6.20 raeburn 1579: if (ref($settings->{authorquota}) eq 'HASH') {
1580: $currauthorquota = $settings->{authorquota}->{$type};
1581: }
1.78 raeburn 1582: }
1.72 raeburn 1583: }
1.3 raeburn 1584: if (defined($usertypes->{$type})) {
1585: $typecount ++;
1586: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1587: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1588: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1589: '<td class="LC_left_item">';
1.101 raeburn 1590: if ($context eq 'requestcourses') {
1591: $datatable .= '<table><tr>';
1592: }
1593: my %cell;
1.72 raeburn 1594: foreach my $item (@usertools) {
1.101 raeburn 1595: if ($context eq 'requestcourses') {
1596: my ($curroption,$currlimit);
1597: if (ref($settings) eq 'HASH') {
1598: if (ref($settings->{$item}) eq 'HASH') {
1599: $curroption = $settings->{$item}->{$type};
1600: if ($curroption =~ /^autolimit=(\d*)$/) {
1601: $currlimit = $1;
1602: }
1603: }
1604: }
1605: if (!$curroption) {
1606: $curroption = 'norequest';
1607: }
1608: $datatable .= '<th>'.$titles{$item}.'</th>';
1609: foreach my $option (@options) {
1610: my $val = $option;
1611: if ($option eq 'norequest') {
1612: $val = 0;
1613: }
1614: if ($option eq 'validate') {
1615: my $canvalidate = 0;
1616: if (ref($validations{$item}) eq 'HASH') {
1617: if ($validations{$item}{$type}) {
1618: $canvalidate = 1;
1619: }
1620: }
1621: next if (!$canvalidate);
1622: }
1623: my $checked = '';
1624: if ($option eq $curroption) {
1625: $checked = ' checked="checked"';
1626: } elsif ($option eq 'autolimit') {
1627: if ($curroption =~ /^autolimit/) {
1628: $checked = ' checked="checked"';
1629: }
1630: }
1631: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1632: '<input type="radio" name="crsreq_'.$item.
1633: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1634: $titles{$option}.'</label>';
1.101 raeburn 1635: if ($option eq 'autolimit') {
1.127 raeburn 1636: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1637: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1638: 'value="'.$currlimit.'" />';
1.101 raeburn 1639: }
1.127 raeburn 1640: $cell{$item} .= '</span> ';
1.103 raeburn 1641: if ($option eq 'autolimit') {
1.127 raeburn 1642: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1643: }
1.101 raeburn 1644: }
1.160.6.5 raeburn 1645: } elsif ($context eq 'requestauthor') {
1646: my $curroption;
1647: if (ref($settings) eq 'HASH') {
1648: $curroption = $settings->{$type};
1649: }
1650: if (!$curroption) {
1651: $curroption = 'norequest';
1652: }
1653: foreach my $option (@options) {
1654: my $val = $option;
1655: if ($option eq 'norequest') {
1656: $val = 0;
1657: }
1658: my $checked = '';
1659: if ($option eq $curroption) {
1660: $checked = ' checked="checked"';
1661: }
1662: $datatable .= '<span class="LC_nobreak"><label>'.
1663: '<input type="radio" name="authorreq_'.$type.
1664: '" value="'.$val.'"'.$checked.' />'.
1665: $titles{$option}.'</label></span> ';
1666: }
1.101 raeburn 1667: } else {
1668: my $checked = 'checked="checked" ';
1669: if (ref($settings) eq 'HASH') {
1670: if (ref($settings->{$item}) eq 'HASH') {
1671: if ($settings->{$item}->{$type} == 0) {
1672: $checked = '';
1673: } elsif ($settings->{$item}->{$type} == 1) {
1674: $checked = 'checked="checked" ';
1675: }
1.78 raeburn 1676: }
1.72 raeburn 1677: }
1.101 raeburn 1678: $datatable .= '<span class="LC_nobreak"><label>'.
1679: '<input type="checkbox" name="'.$context.'_'.$item.
1680: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1681: '</label></span> ';
1.72 raeburn 1682: }
1.101 raeburn 1683: }
1684: if ($context eq 'requestcourses') {
1685: $datatable .= '</tr><tr>';
1686: foreach my $item (@usertools) {
1.106 raeburn 1687: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1688: }
1689: $datatable .= '</tr></table>';
1.72 raeburn 1690: }
1.86 raeburn 1691: $datatable .= '</td>';
1.160.6.5 raeburn 1692: unless (($context eq 'requestcourses') ||
1693: ($context eq 'requestauthor')) {
1.86 raeburn 1694: $datatable .=
1.160.6.20 raeburn 1695: '<td class="LC_right_item">'.
1696: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1697: '<input type="text" name="quota_'.$type.
1.72 raeburn 1698: '" value="'.$currdefquota.
1.160.6.20 raeburn 1699: '" size="5" /></span>'.(' ' x 2).
1700: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1701: '<input type="text" name="authorquota_'.$type.
1702: '" value="'.$currauthorquota.
1703: '" size="5" /></span></td>';
1.86 raeburn 1704: }
1705: $datatable .= '</tr>';
1.3 raeburn 1706: }
1707: }
1708: }
1.160.6.5 raeburn 1709: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1710: $defaultquota = '20';
1.160.6.20 raeburn 1711: $authorquota = '500';
1.86 raeburn 1712: if (ref($settings) eq 'HASH') {
1713: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1714: $defaultquota = $settings->{'defaultquota'}->{'default'};
1715: } elsif (defined($settings->{'default'})) {
1716: $defaultquota = $settings->{'default'};
1717: }
1.160.6.20 raeburn 1718: if (ref($settings->{'authorquota'}) eq 'HASH') {
1719: $authorquota = $settings->{'authorquota'}->{'default'};
1720: }
1.3 raeburn 1721: }
1722: }
1723: $typecount ++;
1724: $css_class = $typecount%2?' class="LC_odd_row"':'';
1725: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1726: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1727: '<td class="LC_left_item">';
1.101 raeburn 1728: if ($context eq 'requestcourses') {
1729: $datatable .= '<table><tr>';
1730: }
1731: my %defcell;
1.72 raeburn 1732: foreach my $item (@usertools) {
1.101 raeburn 1733: if ($context eq 'requestcourses') {
1734: my ($curroption,$currlimit);
1735: if (ref($settings) eq 'HASH') {
1736: if (ref($settings->{$item}) eq 'HASH') {
1737: $curroption = $settings->{$item}->{'default'};
1738: if ($curroption =~ /^autolimit=(\d*)$/) {
1739: $currlimit = $1;
1740: }
1741: }
1742: }
1743: if (!$curroption) {
1744: $curroption = 'norequest';
1745: }
1746: $datatable .= '<th>'.$titles{$item}.'</th>';
1747: foreach my $option (@options) {
1748: my $val = $option;
1749: if ($option eq 'norequest') {
1750: $val = 0;
1751: }
1752: if ($option eq 'validate') {
1753: my $canvalidate = 0;
1754: if (ref($validations{$item}) eq 'HASH') {
1755: if ($validations{$item}{'default'}) {
1756: $canvalidate = 1;
1757: }
1758: }
1759: next if (!$canvalidate);
1760: }
1761: my $checked = '';
1762: if ($option eq $curroption) {
1763: $checked = ' checked="checked"';
1764: } elsif ($option eq 'autolimit') {
1765: if ($curroption =~ /^autolimit/) {
1766: $checked = ' checked="checked"';
1767: }
1768: }
1769: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1770: '<input type="radio" name="crsreq_'.$item.
1771: '_default" value="'.$val.'"'.$checked.' />'.
1772: $titles{$option}.'</label>';
1773: if ($option eq 'autolimit') {
1.127 raeburn 1774: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1775: $item.'_limit_default" size="1" '.
1776: 'value="'.$currlimit.'" />';
1777: }
1.127 raeburn 1778: $defcell{$item} .= '</span> ';
1.104 raeburn 1779: if ($option eq 'autolimit') {
1.127 raeburn 1780: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1781: }
1.101 raeburn 1782: }
1.160.6.5 raeburn 1783: } elsif ($context eq 'requestauthor') {
1784: my $curroption;
1785: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 1786: $curroption = $settings->{'default'};
1.160.6.5 raeburn 1787: }
1788: if (!$curroption) {
1789: $curroption = 'norequest';
1790: }
1791: foreach my $option (@options) {
1792: my $val = $option;
1793: if ($option eq 'norequest') {
1794: $val = 0;
1795: }
1796: my $checked = '';
1797: if ($option eq $curroption) {
1798: $checked = ' checked="checked"';
1799: }
1800: $datatable .= '<span class="LC_nobreak"><label>'.
1801: '<input type="radio" name="authorreq_default"'.
1802: ' value="'.$val.'"'.$checked.' />'.
1803: $titles{$option}.'</label></span> ';
1804: }
1.101 raeburn 1805: } else {
1806: my $checked = 'checked="checked" ';
1807: if (ref($settings) eq 'HASH') {
1808: if (ref($settings->{$item}) eq 'HASH') {
1809: if ($settings->{$item}->{'default'} == 0) {
1810: $checked = '';
1811: } elsif ($settings->{$item}->{'default'} == 1) {
1812: $checked = 'checked="checked" ';
1813: }
1.78 raeburn 1814: }
1.72 raeburn 1815: }
1.101 raeburn 1816: $datatable .= '<span class="LC_nobreak"><label>'.
1817: '<input type="checkbox" name="'.$context.'_'.$item.
1818: '" value="default" '.$checked.'/>'.$titles{$item}.
1819: '</label></span> ';
1820: }
1821: }
1822: if ($context eq 'requestcourses') {
1823: $datatable .= '</tr><tr>';
1824: foreach my $item (@usertools) {
1.106 raeburn 1825: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1826: }
1.101 raeburn 1827: $datatable .= '</tr></table>';
1.72 raeburn 1828: }
1.86 raeburn 1829: $datatable .= '</td>';
1.160.6.5 raeburn 1830: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 1831: $datatable .= '<td class="LC_right_item">'.
1832: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 1833: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 1834: $defaultquota.'" size="5" /></span>'.(' ' x2).
1835: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1836: '<input type="text" name="authorquota" value="'.
1837: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 1838: }
1839: $datatable .= '</tr>';
1.72 raeburn 1840: $typecount ++;
1841: $css_class = $typecount%2?' class="LC_odd_row"':'';
1842: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 1843: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 1844: if ($context eq 'requestcourses') {
1.109 raeburn 1845: $datatable .= &mt('(overrides affiliation, if set)').
1846: '</td>'.
1847: '<td class="LC_left_item">'.
1848: '<table><tr>';
1.101 raeburn 1849: } else {
1.109 raeburn 1850: $datatable .= &mt('(overrides affiliation, if checked)').
1851: '</td>'.
1852: '<td class="LC_left_item" colspan="2">'.
1853: '<br />';
1.101 raeburn 1854: }
1855: my %advcell;
1.72 raeburn 1856: foreach my $item (@usertools) {
1.101 raeburn 1857: if ($context eq 'requestcourses') {
1858: my ($curroption,$currlimit);
1859: if (ref($settings) eq 'HASH') {
1860: if (ref($settings->{$item}) eq 'HASH') {
1861: $curroption = $settings->{$item}->{'_LC_adv'};
1862: if ($curroption =~ /^autolimit=(\d*)$/) {
1863: $currlimit = $1;
1864: }
1865: }
1866: }
1867: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1868: my $checked = '';
1869: if ($curroption eq '') {
1870: $checked = ' checked="checked"';
1871: }
1872: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1873: '<input type="radio" name="crsreq_'.$item.
1874: '__LC_adv" value=""'.$checked.' />'.
1875: &mt('No override set').'</label></span> ';
1.101 raeburn 1876: foreach my $option (@options) {
1877: my $val = $option;
1878: if ($option eq 'norequest') {
1879: $val = 0;
1880: }
1881: if ($option eq 'validate') {
1882: my $canvalidate = 0;
1883: if (ref($validations{$item}) eq 'HASH') {
1884: if ($validations{$item}{'_LC_adv'}) {
1885: $canvalidate = 1;
1886: }
1887: }
1888: next if (!$canvalidate);
1889: }
1890: my $checked = '';
1.104 raeburn 1891: if ($val eq $curroption) {
1.101 raeburn 1892: $checked = ' checked="checked"';
1893: } elsif ($option eq 'autolimit') {
1894: if ($curroption =~ /^autolimit/) {
1895: $checked = ' checked="checked"';
1896: }
1897: }
1898: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1899: '<input type="radio" name="crsreq_'.$item.
1900: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1901: $titles{$option}.'</label>';
1902: if ($option eq 'autolimit') {
1.127 raeburn 1903: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1904: $item.'_limit__LC_adv" size="1" '.
1905: 'value="'.$currlimit.'" />';
1906: }
1.127 raeburn 1907: $advcell{$item} .= '</span> ';
1.104 raeburn 1908: if ($option eq 'autolimit') {
1.127 raeburn 1909: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1910: }
1.101 raeburn 1911: }
1.160.6.5 raeburn 1912: } elsif ($context eq 'requestauthor') {
1913: my $curroption;
1914: if (ref($settings) eq 'HASH') {
1915: $curroption = $settings->{'_LC_adv'};
1916: }
1917: my $checked = '';
1918: if ($curroption eq '') {
1919: $checked = ' checked="checked"';
1920: }
1921: $datatable .= '<span class="LC_nobreak"><label>'.
1922: '<input type="radio" name="authorreq__LC_adv"'.
1923: ' value=""'.$checked.' />'.
1924: &mt('No override set').'</label></span> ';
1925: foreach my $option (@options) {
1926: my $val = $option;
1927: if ($option eq 'norequest') {
1928: $val = 0;
1929: }
1930: my $checked = '';
1931: if ($val eq $curroption) {
1932: $checked = ' checked="checked"';
1933: }
1934: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 1935: '<input type="radio" name="authorreq__LC_adv"'.
1936: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 1937: $titles{$option}.'</label></span> ';
1938: }
1.101 raeburn 1939: } else {
1940: my $checked = 'checked="checked" ';
1941: if (ref($settings) eq 'HASH') {
1942: if (ref($settings->{$item}) eq 'HASH') {
1943: if ($settings->{$item}->{'_LC_adv'} == 0) {
1944: $checked = '';
1945: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1946: $checked = 'checked="checked" ';
1947: }
1.79 raeburn 1948: }
1.72 raeburn 1949: }
1.101 raeburn 1950: $datatable .= '<span class="LC_nobreak"><label>'.
1951: '<input type="checkbox" name="'.$context.'_'.$item.
1952: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1953: '</label></span> ';
1954: }
1955: }
1956: if ($context eq 'requestcourses') {
1957: $datatable .= '</tr><tr>';
1958: foreach my $item (@usertools) {
1.106 raeburn 1959: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1960: }
1.101 raeburn 1961: $datatable .= '</tr></table>';
1.72 raeburn 1962: }
1.98 raeburn 1963: $datatable .= '</td></tr>';
1.30 raeburn 1964: $$rowtotal += $typecount;
1.3 raeburn 1965: return $datatable;
1966: }
1967:
1.160.6.5 raeburn 1968: sub print_requestmail {
1969: my ($dom,$action,$settings,$rowtotal) = @_;
1.160.6.25 raeburn 1970: my ($now,$datatable,%currapp);
1.102 raeburn 1971: $now = time;
1972: if (ref($settings) eq 'HASH') {
1973: if (ref($settings->{'notify'}) eq 'HASH') {
1974: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.16 raeburn 1975: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 1976: }
1977: }
1978: }
1.160.6.16 raeburn 1979: my $numinrow = 2;
1.102 raeburn 1980: my $css_class = 'class="LC_odd_row"';
1.160.6.5 raeburn 1981: my $text;
1982: if ($action eq 'requestcourses') {
1983: $text = &mt('Receive notification of course requests requiring approval');
1984: } else {
1985: $text = &mt('Receive notification of authoring space requests requiring approval')
1986: }
1987: $datatable = '<tr '.$css_class.'>'.
1988: ' <td>'.$text.'</td>'.
1.102 raeburn 1989: ' <td class="LC_left_item">';
1.160.6.16 raeburn 1990: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1991: 'reqapprovalnotify',%currapp);
1992: if ($numdc > 0) {
1993: $datatable .= $table;
1.102 raeburn 1994: } else {
1995: $datatable .= &mt('There are no active Domain Coordinators');
1996: }
1997: $datatable .='</td></tr>';
1998: $$rowtotal += $rows;
1999: return $datatable;
2000: }
2001:
1.160.6.30! raeburn 2002: sub print_studentcode {
! 2003: my ($settings,$rowtotal) = @_;
! 2004: my $rownum = 0;
! 2005: my ($output,%current);
! 2006: my @crstypes = ('official','unofficial','community','textbook');
! 2007: if (ref($settings->{'uniquecode'}) eq 'HASH') {
! 2008: foreach my $type (@crstypes) {
! 2009: $current{$type} = $settings->{'uniquecode'}{$type};
! 2010: }
! 2011: }
! 2012: $output .= '<tr>'.
! 2013: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
! 2014: '<td class="LC_left_item">';
! 2015: foreach my $type (@crstypes) {
! 2016: my $check = ' ';
! 2017: if ($current{$type}) {
! 2018: $check = ' checked="checked" ';
! 2019: }
! 2020: $output .= '<span class="LC_nobreak"><label>'.
! 2021: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
! 2022: &mt($type).'</label></span>'.(' 'x2).' ';
! 2023: }
! 2024: $output .= '</td></tr>';
! 2025: $$rowtotal ++;
! 2026: return $output;
! 2027: }
! 2028:
! 2029: sub print_textbookcourses {
! 2030: my ($dom,$settings,$rowtotal) = @_;
! 2031: my $rownum = 0;
! 2032: my $css_class;
! 2033: my $itemcount = 1;
! 2034: my $maxnum = 0;
! 2035: my $bookshash;
! 2036: if (ref($settings) eq 'HASH') {
! 2037: $bookshash = $settings->{'textbooks'};
! 2038: }
! 2039: my %ordered;
! 2040: if (ref($bookshash) eq 'HASH') {
! 2041: foreach my $item (keys(%{$bookshash})) {
! 2042: if (ref($bookshash->{$item}) eq 'HASH') {
! 2043: my $num = $bookshash->{$item}{'order'};
! 2044: $ordered{$num} = $item;
! 2045: }
! 2046: }
! 2047: }
! 2048: my $confname = $dom.'-domainconfig';
! 2049: my $switchserver = &check_switchserver($dom,$confname);
! 2050: my $maxnum = scalar(keys(%ordered));
! 2051: my $datatable = &textbookcourses_javascript(\%ordered);
! 2052: if (keys(%ordered)) {
! 2053: my @items = sort { $a <=> $b } keys(%ordered);
! 2054: for (my $i=0; $i<@items; $i++) {
! 2055: $css_class = $itemcount%2?' class="LC_odd_row"':'';
! 2056: my $key = $ordered{$items[$i]};
! 2057: my %coursehash=&Apache::lonnet::coursedescription($key);
! 2058: my $coursetitle = $coursehash{'description'};
! 2059: my ($subject,$title,$author,$image,$imgsrc,$cdom,$cnum);
! 2060: if (ref($bookshash->{$key}) eq 'HASH') {
! 2061: $subject = $bookshash->{$key}->{'subject'};
! 2062: $title = $bookshash->{$key}->{'title'};
! 2063: $author = $bookshash->{$key}->{'author'};
! 2064: $image = $bookshash->{$key}->{'image'};
! 2065: if ($image ne '') {
! 2066: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
! 2067: my $imagethumb = "$path/tn-".$imagefile;
! 2068: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
! 2069: }
! 2070: }
! 2071: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$key'".');"';
! 2072: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
! 2073: .'<select name="'.$key.'"'.$chgstr.'>';
! 2074: for (my $k=0; $k<=$maxnum; $k++) {
! 2075: my $vpos = $k+1;
! 2076: my $selstr;
! 2077: if ($k == $i) {
! 2078: $selstr = ' selected="selected" ';
! 2079: }
! 2080: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
! 2081: }
! 2082: $datatable .= '</select>'.(' 'x2).
! 2083: '<label><input type="checkbox" name="book_del" value="'.$key.'" />'.
! 2084: &mt('Delete?').'</label></span></td>'.
! 2085: '<td colspan="2">'.
! 2086: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="book_subject_'.$i.'" value="'.$subject.'" /></span> '.
! 2087: (' 'x2).
! 2088: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="book_title_'.$i.'" value="'.$title.'" /></span> '.
! 2089: (' 'x2).
! 2090: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="book_author_'.$i.'" value="'.$author.'" /></span> '.
! 2091: (' 'x2).
! 2092: '<span class="LC_nobreak">'.&mt('Thumbnail:');
! 2093: if ($image) {
! 2094: $datatable .= '<span class="LC_nobreak">'.
! 2095: $imgsrc.
! 2096: '<label><input type="checkbox" name="book_image_del"'.
! 2097: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
! 2098: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
! 2099: }
! 2100: if ($switchserver) {
! 2101: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
! 2102: } else {
! 2103: $datatable .= '<input type="file" name="book_image_'.$i.'" value="" />';
! 2104: }
! 2105: $datatable .= '<input type="hidden" name="book_id_'.$i.'" value="'.$key.'" /></span> '.
! 2106: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
! 2107: $coursetitle.'</span></td></tr>'."\n";
! 2108: $itemcount ++;
! 2109: }
! 2110: }
! 2111: $css_class = $itemcount%2?' class="LC_odd_row"':'';
! 2112: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'addbook_pos'".');"';
! 2113: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
! 2114: '<input type="hidden" name="book_maxnum" value="'.$maxnum.'" />'."\n".
! 2115: '<select name="addbook_pos"'.$chgstr.'>';
! 2116: for (my $k=0; $k<$maxnum+1; $k++) {
! 2117: my $vpos = $k+1;
! 2118: my $selstr;
! 2119: if ($k == $maxnum) {
! 2120: $selstr = ' selected="selected" ';
! 2121: }
! 2122: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
! 2123: }
! 2124: $datatable .= '</select> '."\n".
! 2125: '<input type="checkbox" name="addbook" value="1" />'.&mt('Add').'</td>'."\n".
! 2126: '<td colspan="2">'.
! 2127: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="addbook_subject" value="" /></span> '."\n".
! 2128: (' 'x2).
! 2129: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="addbook_title" value="" /></span> '."\n".
! 2130: (' 'x2).
! 2131: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="addbook_author" value="" /></span> '."\n".
! 2132: (' 'x2).
! 2133: '<span class="LC_nobreak">'.&mt('Image:').' ';
! 2134: if ($switchserver) {
! 2135: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
! 2136: } else {
! 2137: $datatable .= '<input type="file" name="addbook_image" value="" />';
! 2138: }
! 2139: $datatable .= '</span>'."\n".
! 2140: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
! 2141: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'addbook_cdom').
! 2142: '<input type="text" size="25" name="addbook_cnum" value="" />'.
! 2143: &Apache::loncommon::selectcourse_link
! 2144: ('display','addbook_cnum','addbook_cdom',undef,undef,undef,'Course');
! 2145: '</span></td>'."\n".
! 2146: '</tr>'."\n";
! 2147: $itemcount ++;
! 2148: return $datatable;
! 2149: }
! 2150:
! 2151: sub textbookcourses_javascript {
! 2152: my ($textbooks) = @_;
! 2153: return unless(ref($textbooks) eq 'HASH');
! 2154: my $num = scalar(keys(%{$textbooks}));
! 2155: my @jsarray;
! 2156: foreach my $item (sort {$a <=> $b } (keys(%{$textbooks}))) {
! 2157: push(@jsarray,$textbooks->{$item});
! 2158: }
! 2159: my $jstext = ' var textbooks = Array('."'".join("','",@jsarray)."'".');'."\n";
! 2160: return <<"ENDSCRIPT";
! 2161: <script type="text/javascript">
! 2162: // <![CDATA[
! 2163: function reorderBooks(form,item) {
! 2164: var changedVal;
! 2165: $jstext
! 2166: var newpos = 'addbook_pos';
! 2167: var current = new Array;
! 2168: var maxh = 1 + $num;
! 2169: var current = new Array;
! 2170: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
! 2171: if (item == newpos) {
! 2172: changedVal = newitemVal;
! 2173: } else {
! 2174: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
! 2175: current[newitemVal] = newpos;
! 2176: }
! 2177: for (var i=0; i<textbooks.length; i++) {
! 2178: var elementName = textbooks[i];
! 2179: if (elementName != item) {
! 2180: if (form.elements[elementName]) {
! 2181: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
! 2182: current[currVal] = elementName;
! 2183: }
! 2184: }
! 2185: }
! 2186: var oldVal;
! 2187: for (var j=0; j<maxh; j++) {
! 2188: if (current[j] == undefined) {
! 2189: oldVal = j;
! 2190: }
! 2191: }
! 2192: if (oldVal < changedVal) {
! 2193: for (var k=oldVal+1; k<=changedVal ; k++) {
! 2194: var elementName = current[k];
! 2195: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
! 2196: }
! 2197: } else {
! 2198: for (var k=changedVal; k<oldVal; k++) {
! 2199: var elementName = current[k];
! 2200: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
! 2201: }
! 2202: }
! 2203: return;
! 2204: }
! 2205:
! 2206: // ]]>
! 2207: </script>
! 2208:
! 2209: ENDSCRIPT
! 2210: }
! 2211:
1.3 raeburn 2212: sub print_autoenroll {
1.30 raeburn 2213: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2214: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 2215: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 2216: if (ref($settings) eq 'HASH') {
2217: if (exists($settings->{'run'})) {
2218: if ($settings->{'run'} eq '0') {
2219: $runoff = ' checked="checked" ';
2220: $runon = ' ';
2221: } else {
2222: $runon = ' checked="checked" ';
2223: $runoff = ' ';
2224: }
2225: } else {
2226: if ($autorun) {
2227: $runon = ' checked="checked" ';
2228: $runoff = ' ';
2229: } else {
2230: $runoff = ' checked="checked" ';
2231: $runon = ' ';
2232: }
2233: }
1.129 raeburn 2234: if (exists($settings->{'co-owners'})) {
2235: if ($settings->{'co-owners'} eq '0') {
2236: $coownersoff = ' checked="checked" ';
2237: $coownerson = ' ';
2238: } else {
2239: $coownerson = ' checked="checked" ';
2240: $coownersoff = ' ';
2241: }
2242: } else {
2243: $coownersoff = ' checked="checked" ';
2244: $coownerson = ' ';
2245: }
1.3 raeburn 2246: if (exists($settings->{'sender_domain'})) {
2247: $defdom = $settings->{'sender_domain'};
2248: }
1.14 raeburn 2249: } else {
2250: if ($autorun) {
2251: $runon = ' checked="checked" ';
2252: $runoff = ' ';
2253: } else {
2254: $runoff = ' checked="checked" ';
2255: $runon = ' ';
2256: }
1.3 raeburn 2257: }
2258: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2259: my $notif_sender;
2260: if (ref($settings) eq 'HASH') {
2261: $notif_sender = $settings->{'sender_uname'};
2262: }
1.3 raeburn 2263: my $datatable='<tr class="LC_odd_row">'.
2264: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2265: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2266: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2267: $runon.' value="1" />'.&mt('Yes').'</label> '.
2268: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2269: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2270: '</tr><tr>'.
2271: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2272: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2273: &mt('username').': '.
2274: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2275: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2276: ': '.$domform.'</span></td></tr>'.
2277: '<tr class="LC_odd_row">'.
2278: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2279: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2280: '<input type="radio" name="autoassign_coowners"'.
2281: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2282: '<label><input type="radio" name="autoassign_coowners"'.
2283: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2284: '</tr>';
2285: $$rowtotal += 3;
1.3 raeburn 2286: return $datatable;
2287: }
2288:
2289: sub print_autoupdate {
1.30 raeburn 2290: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2291: my $datatable;
2292: if ($position eq 'top') {
2293: my $updateon = ' ';
2294: my $updateoff = ' checked="checked" ';
2295: my $classlistson = ' ';
2296: my $classlistsoff = ' checked="checked" ';
2297: if (ref($settings) eq 'HASH') {
2298: if ($settings->{'run'} eq '1') {
2299: $updateon = $updateoff;
2300: $updateoff = ' ';
2301: }
2302: if ($settings->{'classlists'} eq '1') {
2303: $classlistson = $classlistsoff;
2304: $classlistsoff = ' ';
2305: }
2306: }
2307: my %title = (
2308: run => 'Auto-update active?',
2309: classlists => 'Update information in classlists?',
2310: );
2311: $datatable = '<tr class="LC_odd_row">'.
2312: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2313: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2314: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2315: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2316: '<label><input type="radio" name="autoupdate_run"'.
2317: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2318: '</tr><tr>'.
2319: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2320: '<td class="LC_right_item"><span class="LC_nobreak">'.
2321: '<label><input type="radio" name="classlists"'.
2322: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2323: '<label><input type="radio" name="classlists"'.
2324: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2325: '</tr>';
1.30 raeburn 2326: $$rowtotal += 2;
1.131 raeburn 2327: } elsif ($position eq 'middle') {
2328: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2329: my $numinrow = 3;
2330: my $locknamesettings;
2331: $datatable .= &insttypes_row($settings,$types,$usertypes,
2332: $dom,$numinrow,$othertitle,
2333: 'lockablenames');
2334: $$rowtotal ++;
1.3 raeburn 2335: } else {
1.44 raeburn 2336: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2337: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2338: 'permanentemail','id');
1.33 raeburn 2339: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2340: my $numrows = 0;
1.26 raeburn 2341: if (ref($types) eq 'ARRAY') {
2342: if (@{$types} > 0) {
2343: $datatable =
2344: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2345: \@fields,$types,\$numrows);
1.30 raeburn 2346: $$rowtotal += @{$types};
1.26 raeburn 2347: }
1.3 raeburn 2348: }
2349: $datatable .=
2350: &usertype_update_row($settings,{'default' => $othertitle},
2351: \%fieldtitles,\@fields,['default'],
2352: \$numrows);
1.30 raeburn 2353: $$rowtotal ++;
1.3 raeburn 2354: }
2355: return $datatable;
2356: }
2357:
1.125 raeburn 2358: sub print_autocreate {
2359: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2360: my (%createon,%createoff,%currhash);
1.125 raeburn 2361: my @types = ('xml','req');
2362: if (ref($settings) eq 'HASH') {
2363: foreach my $item (@types) {
2364: $createoff{$item} = ' checked="checked" ';
2365: $createon{$item} = ' ';
2366: if (exists($settings->{$item})) {
2367: if ($settings->{$item}) {
2368: $createon{$item} = ' checked="checked" ';
2369: $createoff{$item} = ' ';
2370: }
2371: }
2372: }
1.160.6.16 raeburn 2373: if ($settings->{'xmldc'} ne '') {
2374: $currhash{$settings->{'xmldc'}} = 1;
2375: }
1.125 raeburn 2376: } else {
2377: foreach my $item (@types) {
2378: $createoff{$item} = ' checked="checked" ';
2379: $createon{$item} = ' ';
2380: }
2381: }
2382: $$rowtotal += 2;
1.160.6.16 raeburn 2383: my $numinrow = 2;
1.125 raeburn 2384: my $datatable='<tr class="LC_odd_row">'.
2385: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2386: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2387: '<input type="radio" name="autocreate_xml"'.
2388: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2389: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2390: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2391: '</td></tr><tr>'.
2392: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2393: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2394: '<input type="radio" name="autocreate_req"'.
2395: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2396: '<label><input type="radio" name="autocreate_req"'.
2397: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 2398: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2399: 'autocreate_xmldc',%currhash);
1.125 raeburn 2400: if ($numdc > 1) {
1.143 raeburn 2401: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2402: &mt('Course creation processed as: (choose Dom. Coord.)').
2403: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2404: } else {
1.143 raeburn 2405: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2406: }
1.160.6.16 raeburn 2407: $$rowtotal += $rows;
1.125 raeburn 2408: return $datatable;
2409: }
2410:
1.23 raeburn 2411: sub print_directorysrch {
1.30 raeburn 2412: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2413: my $srchon = ' ';
2414: my $srchoff = ' checked="checked" ';
1.25 raeburn 2415: my ($exacton,$containson,$beginson);
1.24 raeburn 2416: my $localon = ' ';
2417: my $localoff = ' checked="checked" ';
1.23 raeburn 2418: if (ref($settings) eq 'HASH') {
2419: if ($settings->{'available'} eq '1') {
2420: $srchon = $srchoff;
2421: $srchoff = ' ';
2422: }
1.24 raeburn 2423: if ($settings->{'localonly'} eq '1') {
2424: $localon = $localoff;
2425: $localoff = ' ';
2426: }
1.25 raeburn 2427: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2428: foreach my $type (@{$settings->{'searchtypes'}}) {
2429: if ($type eq 'exact') {
2430: $exacton = ' checked="checked" ';
2431: } elsif ($type eq 'contains') {
2432: $containson = ' checked="checked" ';
2433: } elsif ($type eq 'begins') {
2434: $beginson = ' checked="checked" ';
2435: }
2436: }
2437: } else {
2438: if ($settings->{'searchtypes'} eq 'exact') {
2439: $exacton = ' checked="checked" ';
2440: } elsif ($settings->{'searchtypes'} eq 'contains') {
2441: $containson = ' checked="checked" ';
2442: } elsif ($settings->{'searchtypes'} eq 'specify') {
2443: $exacton = ' checked="checked" ';
2444: $containson = ' checked="checked" ';
2445: }
1.23 raeburn 2446: }
2447: }
2448: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2449: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2450:
2451: my $numinrow = 4;
1.26 raeburn 2452: my $cansrchrow = 0;
1.23 raeburn 2453: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2454: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2455: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2456: '<input type="radio" name="dirsrch_available"'.
2457: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2458: '<label><input type="radio" name="dirsrch_available"'.
2459: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2460: '</tr><tr>'.
1.30 raeburn 2461: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2462: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2463: '<input type="radio" name="dirsrch_localonly"'.
2464: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2465: '<label><input type="radio" name="dirsrch_localonly"'.
2466: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2467: '</tr>';
1.30 raeburn 2468: $$rowtotal += 2;
1.26 raeburn 2469: if (ref($usertypes) eq 'HASH') {
2470: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2471: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2472: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2473: $cansrchrow = 1;
2474: }
2475: }
2476: if ($cansrchrow) {
1.30 raeburn 2477: $$rowtotal ++;
1.26 raeburn 2478: $datatable .= '<tr>';
2479: } else {
2480: $datatable .= '<tr class="LC_odd_row">';
2481: }
1.30 raeburn 2482: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2483: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2484: foreach my $title (@{$titleorder}) {
2485: if (defined($searchtitles->{$title})) {
2486: my $check = ' ';
1.93 raeburn 2487: if (ref($settings) eq 'HASH') {
1.39 raeburn 2488: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2489: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2490: $check = ' checked="checked" ';
2491: }
1.25 raeburn 2492: }
2493: }
2494: $datatable .= '<td class="LC_left_item">'.
2495: '<span class="LC_nobreak"><label>'.
2496: '<input type="checkbox" name="searchby" '.
2497: 'value="'.$title.'"'.$check.'/>'.
2498: $searchtitles->{$title}.'</label></span></td>';
2499: }
2500: }
1.26 raeburn 2501: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2502: $$rowtotal ++;
1.26 raeburn 2503: if ($cansrchrow) {
2504: $datatable .= '<tr class="LC_odd_row">';
2505: } else {
2506: $datatable .= '<tr>';
2507: }
1.30 raeburn 2508: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2509: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2510: '<span class="LC_nobreak"><label>'.
2511: '<input type="checkbox" name="searchtypes" '.
2512: $exacton.' value="exact" />'.&mt('Exact match').
2513: '</label> '.
2514: '<label><input type="checkbox" name="searchtypes" '.
2515: $beginson.' value="begins" />'.&mt('Begins with').
2516: '</label> '.
2517: '<label><input type="checkbox" name="searchtypes" '.
2518: $containson.' value="contains" />'.&mt('Contains').
2519: '</label></span></td></tr>';
1.30 raeburn 2520: $$rowtotal ++;
1.25 raeburn 2521: return $datatable;
2522: }
2523:
1.28 raeburn 2524: sub print_contacts {
1.30 raeburn 2525: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2526: my $datatable;
2527: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2528: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2529: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.160.6.23 raeburn 2530: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2531: foreach my $type (@mailings) {
2532: $otheremails{$type} = '';
2533: }
1.134 raeburn 2534: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2535: if (ref($settings) eq 'HASH') {
2536: foreach my $item (@contacts) {
2537: if (exists($settings->{$item})) {
2538: $to{$item} = $settings->{$item};
2539: }
2540: }
2541: foreach my $type (@mailings) {
2542: if (exists($settings->{$type})) {
2543: if (ref($settings->{$type}) eq 'HASH') {
2544: foreach my $item (@contacts) {
2545: if ($settings->{$type}{$item}) {
2546: $checked{$type}{$item} = ' checked="checked" ';
2547: }
2548: }
2549: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2550: if ($type eq 'helpdeskmail') {
2551: $bccemails{$type} = $settings->{$type}{'bcc'};
2552: }
1.28 raeburn 2553: }
1.89 raeburn 2554: } elsif ($type eq 'lonstatusmail') {
2555: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2556: }
2557: }
2558: } else {
2559: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2560: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2561: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2562: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2563: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2564: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2565: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.23 raeburn 2566: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
2567: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2568: }
2569: my ($titles,$short_titles) = &contact_titles();
2570: my $rownum = 0;
2571: my $css_class;
2572: foreach my $item (@contacts) {
1.69 raeburn 2573: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2574: $datatable .= '<tr'.$css_class.'>'.
2575: '<td><span class="LC_nobreak">'.$titles->{$item}.
2576: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2577: '<input type="text" name="'.$item.'" value="'.
2578: $to{$item}.'" /></td></tr>';
1.160.6.23 raeburn 2579: $rownum ++;
1.28 raeburn 2580: }
2581: foreach my $type (@mailings) {
1.69 raeburn 2582: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2583: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2584: '<td><span class="LC_nobreak">'.
2585: $titles->{$type}.': </span></td>'.
1.28 raeburn 2586: '<td class="LC_left_item">'.
2587: '<span class="LC_nobreak">';
2588: foreach my $item (@contacts) {
2589: $datatable .= '<label>'.
2590: '<input type="checkbox" name="'.$type.'"'.
2591: $checked{$type}{$item}.
2592: ' value="'.$item.'" />'.$short_titles->{$item}.
2593: '</label> ';
2594: }
2595: $datatable .= '</span><br />'.&mt('Others').': '.
2596: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2597: 'value="'.$otheremails{$type}.'" />';
2598: if ($type eq 'helpdeskmail') {
1.136 raeburn 2599: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2600: '<input type="text" name="'.$type.'_bcc" '.
2601: 'value="'.$bccemails{$type}.'" />';
2602: }
2603: $datatable .= '</td></tr>'."\n";
1.160.6.23 raeburn 2604: $rownum ++;
1.28 raeburn 2605: }
1.160.6.23 raeburn 2606: my %choices;
2607: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2608: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2609: &mt('LON-CAPA core group - MSU'),600,500));
2610: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2611: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2612: &mt('LON-CAPA core group - MSU'),600,500));
2613: my @toggles = ('reporterrors','reportupdates');
2614: my %defaultchecked = ('reporterrors' => 'on',
2615: 'reportupdates' => 'on');
2616: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2617: \%choices,$rownum);
2618: $datatable .= $reports;
1.30 raeburn 2619: $$rowtotal += $rownum;
1.28 raeburn 2620: return $datatable;
2621: }
2622:
1.118 jms 2623: sub print_helpsettings {
1.160.6.5 raeburn 2624: my ($dom,$confname,$settings,$rowtotal) = @_;
2625: my ($datatable,$itemcount);
2626: $itemcount = 1;
2627: my (%choices,%defaultchecked,@toggles);
2628: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2629: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2630: &mt('LON-CAPA bug tracker'),600,500));
2631: %defaultchecked = ('submitbugs' => 'on');
2632: @toggles = ('submitbugs',);
1.122 jms 2633:
1.160.6.5 raeburn 2634: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2635: \%choices,$itemcount);
2636: return $datatable;
1.121 raeburn 2637: }
2638:
2639: sub radiobutton_prefs {
1.160.6.16 raeburn 2640: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
2641: $additional) = @_;
1.121 raeburn 2642: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2643: (ref($choices) eq 'HASH'));
2644:
2645: my (%checkedon,%checkedoff,$datatable,$css_class);
2646:
2647: foreach my $item (@{$toggles}) {
2648: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2649: $checkedon{$item} = ' checked="checked" ';
2650: $checkedoff{$item} = ' ';
1.121 raeburn 2651: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2652: $checkedoff{$item} = ' checked="checked" ';
2653: $checkedon{$item} = ' ';
2654: }
2655: }
2656: if (ref($settings) eq 'HASH') {
1.121 raeburn 2657: foreach my $item (@{$toggles}) {
1.118 jms 2658: if ($settings->{$item} eq '1') {
2659: $checkedon{$item} = ' checked="checked" ';
2660: $checkedoff{$item} = ' ';
2661: } elsif ($settings->{$item} eq '0') {
2662: $checkedoff{$item} = ' checked="checked" ';
2663: $checkedon{$item} = ' ';
2664: }
2665: }
1.121 raeburn 2666: }
1.160.6.16 raeburn 2667: if ($onclick) {
2668: $onclick = ' onclick="'.$onclick.'"';
2669: }
1.121 raeburn 2670: foreach my $item (@{$toggles}) {
1.118 jms 2671: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2672: $datatable .=
1.160.6.16 raeburn 2673: '<tr'.$css_class.'><td valign="top">'.
2674: '<span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2675: '</span></td>'.
2676: '<td class="LC_right_item"><span class="LC_nobreak">'.
2677: '<label><input type="radio" name="'.
1.160.6.16 raeburn 2678: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2679: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 2680: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2681: '</span>'.$additional.
2682: '</td>'.
1.118 jms 2683: '</tr>';
2684: $itemcount ++;
1.121 raeburn 2685: }
2686: return ($datatable,$itemcount);
2687: }
2688:
2689: sub print_coursedefaults {
1.139 raeburn 2690: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2691: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2692: my $itemcount = 1;
1.160.6.16 raeburn 2693: my %choices = &Apache::lonlocal::texthash (
2694: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.160.6.21 raeburn 2695: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 2696: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2697: coursecredits => 'Credits can be specified for courses',
2698: );
1.160.6.21 raeburn 2699: my %staticdefaults = (
2700: anonsurvey_threshold => 10,
2701: uploadquota => 500,
2702: );
1.139 raeburn 2703: if ($position eq 'top') {
2704: %defaultchecked = ('canuse_pdfforms' => 'off');
1.160.6.16 raeburn 2705: @toggles = ('canuse_pdfforms');
1.139 raeburn 2706: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2707: \%choices,$itemcount);
1.139 raeburn 2708: } else {
2709: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.30! raeburn 2710: my ($currdefresponder,$def_official_credits,$def_unofficial_credits,$def_textbook_credits,
! 2711: %curruploadquota);
1.160.6.16 raeburn 2712: my $currusecredits = 0;
1.160.6.30! raeburn 2713: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 2714: if (ref($settings) eq 'HASH') {
2715: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 2716: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2717: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2718: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2719: }
2720: }
1.160.6.16 raeburn 2721: if (ref($settings->{'coursecredits'}) eq 'HASH') {
2722: $def_official_credits = $settings->{'coursecredits'}->{'official'};
2723: $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
1.160.6.30! raeburn 2724: $def_textbook_credits = $settings->{'coursecredits'}->{'textbook'};
! 2725: if (($def_official_credits ne '') || ($def_unofficial_credits ne '') ||
! 2726: ($def_textbook_credits ne '')) {
1.160.6.16 raeburn 2727: $currusecredits = 1;
2728: }
2729: }
1.139 raeburn 2730: }
2731: if (!$currdefresponder) {
1.160.6.21 raeburn 2732: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 2733: } elsif ($currdefresponder < 1) {
2734: $currdefresponder = 1;
2735: }
1.160.6.21 raeburn 2736: foreach my $type (@types) {
2737: if ($curruploadquota{$type} eq '') {
2738: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
2739: }
2740: }
1.139 raeburn 2741: $datatable .=
1.160.6.16 raeburn 2742: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2743: $choices{'anonsurvey_threshold'}.
1.139 raeburn 2744: '</span></td>'.
2745: '<td class="LC_right_item"><span class="LC_nobreak">'.
2746: '<input type="text" name="anonsurvey_threshold"'.
2747: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.21 raeburn 2748: '</td></tr>'."\n".
2749: '<tr><td><span class="LC_nobreak">'.
2750: $choices{'uploadquota'}.
2751: '</span></td>'.
2752: '<td align="right" class="LC_right_item">'.
2753: '<table><tr>';
2754: foreach my $type (@types) {
2755: $datatable .= '<td align="center">'.&mt($type).'<br />'.
2756: '<input type="text" name="uploadquota_'.$type.'"'.
2757: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
2758: }
2759: $datatable .= '</tr></table></td></tr>'."\n";
2760: $itemcount += 2;
1.160.6.16 raeburn 2761: my $onclick = 'toggleCredits(this.form);';
2762: my $display = 'none';
2763: if ($currusecredits) {
2764: $display = 'block';
2765: }
2766: my $additional = '<div id="credits" style="display: '.$display.'">'.
2767: '<span class="LC_nobreak">'.
2768: &mt('Default credits for official courses [_1]',
2769: '<input type="text" name="official_credits" value="'.
2770: $def_official_credits.'" size="3" />').
2771: '</span><br />'.
2772: '<span class="LC_nobreak">'.
2773: &mt('Default credits for unofficial courses [_1]',
2774: '<input type="text" name="unofficial_credits" value="'.
2775: $def_unofficial_credits.'" size="3" />').
1.160.6.30! raeburn 2776: '</span><br />'.
! 2777: '<span class="LC_nobreak">'.
! 2778: &mt('Default credits for textbook courses [_1]',
! 2779: '<input type="text" name="textbook_credits" value="'.
! 2780: $def_textbook_credits.'" size="3" />').
1.160.6.16 raeburn 2781: '</span></div>'."\n";
2782: %defaultchecked = ('coursecredits' => 'off');
2783: @toggles = ('coursecredits');
2784: my $current = {
2785: 'coursecredits' => $currusecredits,
2786: };
2787: (my $table,$itemcount) =
2788: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
2789: \%choices,$itemcount,$onclick,$additional);
2790: $datatable .= $table;
1.139 raeburn 2791: }
1.160.6.16 raeburn 2792: $$rowtotal += $itemcount;
1.121 raeburn 2793: return $datatable;
1.118 jms 2794: }
2795:
1.137 raeburn 2796: sub print_usersessions {
2797: my ($position,$dom,$settings,$rowtotal) = @_;
2798: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2799: my (%by_ip,%by_location,@intdoms);
2800: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 2801:
2802: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 2803: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 2804: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 2805: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 2806: my $itemcount = 1;
2807: if ($position eq 'top') {
1.152 raeburn 2808: if (keys(%serverhomes) > 1) {
1.145 raeburn 2809: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 2810: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 2811: } else {
1.140 raeburn 2812: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2813: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 2814: }
1.137 raeburn 2815: } else {
1.145 raeburn 2816: if (keys(%by_location) == 0) {
2817: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2818: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 2819: } else {
2820: my %lt = &usersession_titles();
2821: my $numinrow = 5;
2822: my $prefix;
2823: my @types;
2824: if ($position eq 'bottom') {
2825: $prefix = 'remote';
2826: @types = ('version','excludedomain','includedomain');
2827: } else {
2828: $prefix = 'hosted';
2829: @types = ('excludedomain','includedomain');
2830: }
2831: my (%current,%checkedon,%checkedoff);
2832: my @lcversions = &Apache::lonnet::all_loncaparevs();
2833: my @locations = sort(keys(%by_location));
2834: foreach my $type (@types) {
2835: $checkedon{$type} = '';
2836: $checkedoff{$type} = ' checked="checked"';
2837: }
2838: if (ref($settings) eq 'HASH') {
2839: if (ref($settings->{$prefix}) eq 'HASH') {
2840: foreach my $key (keys(%{$settings->{$prefix}})) {
2841: $current{$key} = $settings->{$prefix}{$key};
2842: if ($key eq 'version') {
2843: if ($current{$key} ne '') {
2844: $checkedon{$key} = ' checked="checked"';
2845: $checkedoff{$key} = '';
2846: }
2847: } elsif (ref($current{$key}) eq 'ARRAY') {
2848: $checkedon{$key} = ' checked="checked"';
2849: $checkedoff{$key} = '';
2850: }
1.137 raeburn 2851: }
2852: }
2853: }
1.145 raeburn 2854: foreach my $type (@types) {
2855: next if ($type ne 'version' && !@locations);
2856: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2857: $datatable .= '<tr'.$css_class.'>
2858: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2859: <span class="LC_nobreak">
2860: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2861: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2862: if ($type eq 'version') {
2863: my $selector = '<select name="'.$prefix.'_version">';
2864: foreach my $version (@lcversions) {
2865: my $selected = '';
2866: if ($current{'version'} eq $version) {
2867: $selected = ' selected="selected"';
2868: }
2869: $selector .= ' <option value="'.$version.'"'.
2870: $selected.'>'.$version.'</option>';
2871: }
2872: $selector .= '</select> ';
2873: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2874: } else {
2875: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2876: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2877: ' />'.(' 'x2).
2878: '<input type="button" value="'.&mt('uncheck all').'" '.
2879: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2880: "\n".
2881: '</div><div><table>';
2882: my $rem;
2883: for (my $i=0; $i<@locations; $i++) {
2884: my ($showloc,$value,$checkedtype);
2885: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2886: my $ip = $by_location{$locations[$i]}->[0];
2887: if (ref($by_ip{$ip}) eq 'ARRAY') {
2888: $value = join(':',@{$by_ip{$ip}});
2889: $showloc = join(', ',@{$by_ip{$ip}});
2890: if (ref($current{$type}) eq 'ARRAY') {
2891: foreach my $loc (@{$by_ip{$ip}}) {
2892: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2893: $checkedtype = ' checked="checked"';
2894: last;
2895: }
2896: }
1.138 raeburn 2897: }
2898: }
2899: }
1.145 raeburn 2900: $rem = $i%($numinrow);
2901: if ($rem == 0) {
2902: if ($i > 0) {
2903: $datatable .= '</tr>';
2904: }
2905: $datatable .= '<tr>';
2906: }
2907: $datatable .= '<td class="LC_left_item">'.
2908: '<span class="LC_nobreak"><label>'.
2909: '<input type="checkbox" name="'.$prefix.'_'.$type.
2910: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2911: '</label></span></td>';
1.137 raeburn 2912: }
1.145 raeburn 2913: $rem = @locations%($numinrow);
2914: my $colsleft = $numinrow - $rem;
2915: if ($colsleft > 1 ) {
2916: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2917: ' </td>';
2918: } elsif ($colsleft == 1) {
2919: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 2920: }
1.145 raeburn 2921: $datatable .= '</tr></table>';
1.137 raeburn 2922: }
1.145 raeburn 2923: $datatable .= '</td></tr>';
2924: $itemcount ++;
1.137 raeburn 2925: }
2926: }
2927: }
2928: $$rowtotal += $itemcount;
2929: return $datatable;
2930: }
2931:
1.138 raeburn 2932: sub build_location_hashes {
2933: my ($intdoms,$by_ip,$by_location) = @_;
2934: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2935: (ref($by_location) eq 'HASH'));
2936: my %iphost = &Apache::lonnet::get_iphost();
2937: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2938: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2939: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2940: foreach my $id (@{$iphost{$primary_ip}}) {
2941: my $intdom = &Apache::lonnet::internet_dom($id);
2942: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2943: push(@{$intdoms},$intdom);
2944: }
2945: }
2946: }
2947: foreach my $ip (keys(%iphost)) {
2948: if (ref($iphost{$ip}) eq 'ARRAY') {
2949: foreach my $id (@{$iphost{$ip}}) {
2950: my $location = &Apache::lonnet::internet_dom($id);
2951: if ($location) {
2952: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2953: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2954: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2955: push(@{$by_ip->{$ip}},$location);
2956: }
2957: } else {
2958: $by_ip->{$ip} = [$location];
2959: }
2960: }
2961: }
2962: }
2963: }
2964: foreach my $ip (sort(keys(%{$by_ip}))) {
2965: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2966: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2967: my $first = $by_ip->{$ip}->[0];
2968: if (ref($by_location->{$first}) eq 'ARRAY') {
2969: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2970: push(@{$by_location->{$first}},$ip);
2971: }
2972: } else {
2973: $by_location->{$first} = [$ip];
2974: }
2975: }
2976: }
2977: return;
2978: }
2979:
1.145 raeburn 2980: sub current_offloads_to {
2981: my ($dom,$settings,$servers) = @_;
2982: my (%spareid,%otherdomconfigs);
1.152 raeburn 2983: if (ref($servers) eq 'HASH') {
1.145 raeburn 2984: foreach my $lonhost (sort(keys(%{$servers}))) {
2985: my $gotspares;
1.152 raeburn 2986: if (ref($settings) eq 'HASH') {
2987: if (ref($settings->{'spares'}) eq 'HASH') {
2988: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
2989: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
2990: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
2991: $gotspares = 1;
2992: }
1.145 raeburn 2993: }
2994: }
2995: unless ($gotspares) {
2996: my $gotspares;
2997: my $serverhomeID =
2998: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
2999: my $serverhomedom =
3000: &Apache::lonnet::host_domain($serverhomeID);
3001: if ($serverhomedom ne $dom) {
3002: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
3003: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3004: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3005: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3006: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3007: $gotspares = 1;
3008: }
3009: }
3010: } else {
3011: $otherdomconfigs{$serverhomedom} =
3012: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
3013: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
3014: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3015: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3016: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
3017: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3018: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3019: $gotspares = 1;
3020: }
3021: }
3022: }
3023: }
3024: }
3025: }
3026: }
3027: unless ($gotspares) {
3028: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
3029: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3030: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3031: } else {
3032: my $server_hostname = &Apache::lonnet::hostname($lonhost);
3033: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
3034: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
3035: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3036: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3037: } else {
1.150 raeburn 3038: my %what = (
3039: spareid => 1,
3040: );
3041: my ($result,$returnhash) =
3042: &Apache::lonnet::get_remote_globals($lonhost,\%what);
3043: if ($result eq 'ok') {
3044: if (ref($returnhash) eq 'HASH') {
3045: if (ref($returnhash->{'spareid'}) eq 'HASH') {
3046: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
3047: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
3048: }
3049: }
1.145 raeburn 3050: }
3051: }
3052: }
3053: }
3054: }
3055: }
3056: return %spareid;
3057: }
3058:
3059: sub spares_row {
1.152 raeburn 3060: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 3061: my $css_class;
3062: my $numinrow = 4;
3063: my $itemcount = 1;
3064: my $datatable;
1.152 raeburn 3065: my %typetitles = &sparestype_titles();
3066: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 3067: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 3068: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
3069: my ($othercontrol,$serverdom);
3070: if ($serverhome ne $server) {
3071: $serverdom = &Apache::lonnet::host_domain($serverhome);
3072: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3073: } else {
3074: $serverdom = &Apache::lonnet::host_domain($server);
3075: if ($serverdom ne $dom) {
3076: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3077: }
3078: }
3079: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 3080: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3081: $datatable .= '<tr'.$css_class.'>
3082: <td rowspan="2">
1.160.6.13 raeburn 3083: <span class="LC_nobreak">'.
3084: &mt('[_1] when busy, offloads to:'
3085: ,'<b>'.$server.'</b>').
3086: "\n";
1.145 raeburn 3087: my (%current,%canselect);
1.152 raeburn 3088: my @choices =
3089: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
3090: foreach my $type ('primary','default') {
3091: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 3092: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
3093: my @spares = @{$spareid->{$server}{$type}};
3094: if (@spares > 0) {
1.152 raeburn 3095: if ($othercontrol) {
3096: $current{$type} = join(', ',@spares);
3097: } else {
3098: $current{$type} .= '<table>';
3099: my $numspares = scalar(@spares);
3100: for (my $i=0; $i<@spares; $i++) {
3101: my $rem = $i%($numinrow);
3102: if ($rem == 0) {
3103: if ($i > 0) {
3104: $current{$type} .= '</tr>';
3105: }
3106: $current{$type} .= '<tr>';
1.145 raeburn 3107: }
1.152 raeburn 3108: $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'".');" /> '.
3109: $spareid->{$server}{$type}[$i].
3110: '</label></td>'."\n";
3111: }
3112: my $rem = @spares%($numinrow);
3113: my $colsleft = $numinrow - $rem;
3114: if ($colsleft > 1 ) {
3115: $current{$type} .= '<td colspan="'.$colsleft.
3116: '" class="LC_left_item">'.
3117: ' </td>';
3118: } elsif ($colsleft == 1) {
3119: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 3120: }
1.152 raeburn 3121: $current{$type} .= '</tr></table>';
1.150 raeburn 3122: }
1.145 raeburn 3123: }
3124: }
3125: if ($current{$type} eq '') {
3126: $current{$type} = &mt('None specified');
3127: }
1.152 raeburn 3128: if ($othercontrol) {
3129: if ($type eq 'primary') {
3130: $canselect{$type} = $othercontrol;
3131: }
3132: } else {
3133: $canselect{$type} =
3134: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
3135: '<select name="newspare_'.$type.'_'.$server.'" '.
3136: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
3137: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
3138: if (@choices > 0) {
3139: foreach my $lonhost (@choices) {
3140: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
3141: }
3142: }
3143: $canselect{$type} .= '</select>'."\n";
3144: }
3145: } else {
3146: $current{$type} = &mt('Could not be determined');
3147: if ($type eq 'primary') {
3148: $canselect{$type} = $othercontrol;
3149: }
1.145 raeburn 3150: }
1.152 raeburn 3151: if ($type eq 'default') {
3152: $datatable .= '<tr'.$css_class.'>';
3153: }
3154: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
3155: '<td>'.$current{$type}.'</td>'."\n".
3156: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 3157: }
3158: $itemcount ++;
3159: }
3160: }
3161: $$rowtotal += $itemcount;
3162: return $datatable;
3163: }
3164:
1.152 raeburn 3165: sub possible_newspares {
3166: my ($server,$currspares,$serverhomes,$altids) = @_;
3167: my $serverhostname = &Apache::lonnet::hostname($server);
3168: my %excluded;
3169: if ($serverhostname ne '') {
3170: %excluded = (
3171: $serverhostname => 1,
3172: );
3173: }
3174: if (ref($currspares) eq 'HASH') {
3175: foreach my $type (keys(%{$currspares})) {
3176: if (ref($currspares->{$type}) eq 'ARRAY') {
3177: if (@{$currspares->{$type}} > 0) {
3178: foreach my $curr (@{$currspares->{$type}}) {
3179: my $hostname = &Apache::lonnet::hostname($curr);
3180: $excluded{$hostname} = 1;
3181: }
3182: }
3183: }
3184: }
3185: }
3186: my @choices;
3187: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
3188: if (keys(%{$serverhomes}) > 1) {
3189: foreach my $name (sort(keys(%{$serverhomes}))) {
3190: unless ($excluded{$name}) {
3191: if (exists($altids->{$serverhomes->{$name}})) {
3192: push(@choices,$altids->{$serverhomes->{$name}});
3193: } else {
3194: push(@choices,$serverhomes->{$name});
1.145 raeburn 3195: }
3196: }
3197: }
3198: }
3199: }
1.152 raeburn 3200: return sort(@choices);
1.145 raeburn 3201: }
3202:
1.150 raeburn 3203: sub print_loadbalancing {
3204: my ($dom,$settings,$rowtotal) = @_;
3205: my $primary_id = &Apache::lonnet::domain($dom,'primary');
3206: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3207: my $numinrow = 1;
3208: my $datatable;
3209: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7 raeburn 3210: my (%currbalancer,%currtargets,%currrules,%existing);
3211: if (ref($settings) eq 'HASH') {
3212: %existing = %{$settings};
3213: }
3214: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
3215: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
3216: \%currtargets,\%currrules);
1.150 raeburn 3217: } else {
3218: return;
3219: }
3220: my ($othertitle,$usertypes,$types) =
3221: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 3222: my $rownum = 8;
1.150 raeburn 3223: if (ref($types) eq 'ARRAY') {
3224: $rownum += scalar(@{$types});
3225: }
1.160.6.7 raeburn 3226: my @css_class = ('LC_odd_row','LC_even_row');
3227: my $balnum = 0;
3228: my $islast;
3229: my (@toshow,$disabledtext);
3230: if (keys(%currbalancer) > 0) {
3231: @toshow = sort(keys(%currbalancer));
3232: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
3233: push(@toshow,'');
3234: }
3235: } else {
3236: @toshow = ('');
3237: $disabledtext = &mt('No existing load balancer');
3238: }
3239: foreach my $lonhost (@toshow) {
3240: if ($balnum == scalar(@toshow)-1) {
3241: $islast = 1;
3242: } else {
3243: $islast = 0;
3244: }
3245: my $cssidx = $balnum%2;
3246: my $targets_div_style = 'display: none';
3247: my $disabled_div_style = 'display: block';
3248: my $homedom_div_style = 'display: none';
3249: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3250: '<td rowspan="'.$rownum.'" valign="top">'.
3251: '<p>';
3252: if ($lonhost eq '') {
3253: $datatable .= '<span class="LC_nobreak">';
3254: if (keys(%currbalancer) > 0) {
3255: $datatable .= &mt('Add balancer:');
3256: } else {
3257: $datatable .= &mt('Enable balancer:');
3258: }
3259: $datatable .= ' '.
3260: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3261: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3262: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3263: '<option value="" selected="selected">'.&mt('None').
3264: '</option>'."\n";
3265: foreach my $server (sort(keys(%servers))) {
3266: next if ($currbalancer{$server});
3267: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3268: }
3269: $datatable .=
3270: '</select>'."\n".
3271: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3272: } else {
3273: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3274: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3275: &mt('Stop balancing').'</label>'.
3276: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3277: $targets_div_style = 'display: block';
3278: $disabled_div_style = 'display: none';
3279: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3280: $homedom_div_style = 'display: block';
3281: }
3282: }
3283: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3284: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3285: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3286: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3287: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3288: my @sparestypes = ('primary','default');
3289: my %typetitles = &sparestype_titles();
3290: foreach my $sparetype (@sparestypes) {
3291: my $targettable;
3292: for (my $i=0; $i<$numspares; $i++) {
3293: my $checked;
3294: if (ref($currtargets{$lonhost}) eq 'HASH') {
3295: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3296: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3297: $checked = ' checked="checked"';
3298: }
3299: }
3300: }
3301: my ($chkboxval,$disabled);
3302: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3303: $chkboxval = $spares[$i];
3304: }
3305: if (exists($currbalancer{$spares[$i]})) {
3306: $disabled = ' disabled="disabled"';
3307: }
3308: $targettable .=
3309: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3310: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3311: '</span></label></td>';
3312: my $rem = $i%($numinrow);
3313: if ($rem == 0) {
3314: if (($i > 0) && ($i < $numspares-1)) {
3315: $targettable .= '</tr>';
3316: }
3317: if ($i < $numspares-1) {
3318: $targettable .= '<tr>';
1.150 raeburn 3319: }
3320: }
3321: }
1.160.6.7 raeburn 3322: if ($targettable ne '') {
3323: my $rem = $numspares%($numinrow);
3324: my $colsleft = $numinrow - $rem;
3325: if ($colsleft > 1 ) {
3326: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3327: ' </td>';
3328: } elsif ($colsleft == 1) {
3329: $targettable .= '<td class="LC_left_item"> </td>';
3330: }
3331: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3332: '<table><tr>'.$targettable.'</tr></table><br />';
3333: }
3334: }
3335: $datatable .= '</div></td></tr>'.
3336: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3337: $othertitle,$usertypes,$types,\%servers,
3338: \%currbalancer,$lonhost,
3339: $targets_div_style,$homedom_div_style,
3340: $css_class[$cssidx],$balnum,$islast);
3341: $$rowtotal += $rownum;
3342: $balnum ++;
3343: }
3344: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3345: return $datatable;
3346: }
3347:
3348: sub get_loadbalancers_config {
3349: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3350: return unless ((ref($servers) eq 'HASH') &&
3351: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3352: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3353: if (keys(%{$existing}) > 0) {
3354: my $oldlonhost;
3355: foreach my $key (sort(keys(%{$existing}))) {
3356: if ($key eq 'lonhost') {
3357: $oldlonhost = $existing->{'lonhost'};
3358: $currbalancer->{$oldlonhost} = 1;
3359: } elsif ($key eq 'targets') {
3360: if ($oldlonhost) {
3361: $currtargets->{$oldlonhost} = $existing->{'targets'};
3362: }
3363: } elsif ($key eq 'rules') {
3364: if ($oldlonhost) {
3365: $currrules->{$oldlonhost} = $existing->{'rules'};
3366: }
3367: } elsif (ref($existing->{$key}) eq 'HASH') {
3368: $currbalancer->{$key} = 1;
3369: $currtargets->{$key} = $existing->{$key}{'targets'};
3370: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3371: }
3372: }
1.160.6.7 raeburn 3373: } else {
3374: my ($balancerref,$targetsref) =
3375: &Apache::lonnet::get_lonbalancer_config($servers);
3376: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3377: foreach my $server (sort(keys(%{$balancerref}))) {
3378: $currbalancer->{$server} = 1;
3379: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3380: }
3381: }
3382: }
1.160.6.7 raeburn 3383: return;
1.150 raeburn 3384: }
3385:
3386: sub loadbalancing_rules {
3387: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 3388: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3389: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3390: my $output;
1.160.6.7 raeburn 3391: my $num = 0;
3392: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3393: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3394: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3395: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 3396: $num ++;
1.150 raeburn 3397: my $current;
3398: if (ref($currrules) eq 'HASH') {
3399: $current = $currrules->{$type};
3400: }
1.160.6.26 raeburn 3401: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.160.6.7 raeburn 3402: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3403: $current = '';
3404: }
3405: }
3406: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 3407: $servers,$currbalancer,$lonhost,$dom,
3408: $targets_div_style,$homedom_div_style,
3409: $css_class,$balnum,$num,$islast);
1.150 raeburn 3410: }
3411: }
3412: return $output;
3413: }
3414:
3415: sub loadbalancing_titles {
3416: my ($dom,$intdom,$usertypes,$types) = @_;
3417: my %othertypes = (
3418: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3419: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3420: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3421: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 3422: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
3423: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 3424: );
1.160.6.26 raeburn 3425: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 3426: if (ref($types) eq 'ARRAY') {
3427: unshift(@alltypes,@{$types},'default');
3428: }
3429: my %titles;
3430: foreach my $type (@alltypes) {
3431: if ($type =~ /^_LC_/) {
3432: $titles{$type} = $othertypes{$type};
3433: } elsif ($type eq 'default') {
3434: $titles{$type} = &mt('All users from [_1]',$dom);
3435: if (ref($types) eq 'ARRAY') {
3436: if (@{$types} > 0) {
3437: $titles{$type} = &mt('Other users from [_1]',$dom);
3438: }
3439: }
3440: } elsif (ref($usertypes) eq 'HASH') {
3441: $titles{$type} = $usertypes->{$type};
3442: }
3443: }
3444: return (\@alltypes,\%othertypes,\%titles);
3445: }
3446:
3447: sub loadbalance_rule_row {
1.160.6.7 raeburn 3448: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3449: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 3450: my @rulenames;
1.150 raeburn 3451: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 3452: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
3453: @rulenames = ('balancer','offloadedto');
1.150 raeburn 3454: } else {
1.160.6.26 raeburn 3455: @rulenames = ('default','homeserver');
3456: if ($type eq '_LC_external') {
3457: push(@rulenames,'externalbalancer');
3458: } else {
3459: push(@rulenames,'specific');
3460: }
3461: push(@rulenames,'none');
1.150 raeburn 3462: }
3463: my $style = $targets_div_style;
1.160.6.26 raeburn 3464: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.150 raeburn 3465: $style = $homedom_div_style;
3466: }
1.160.6.7 raeburn 3467: my $space;
3468: if ($islast && $num == 1) {
3469: $space = '<div display="inline-block"> </div>';
3470: }
3471: my $output =
3472: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3473: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3474: '<td valaign="top">'.$space.
3475: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3476: for (my $i=0; $i<@rulenames; $i++) {
3477: my $rule = $rulenames[$i];
3478: my ($checked,$extra);
3479: if ($rulenames[$i] eq 'default') {
3480: $rule = '';
3481: }
3482: if ($rulenames[$i] eq 'specific') {
3483: if (ref($servers) eq 'HASH') {
3484: my $default;
3485: if (($current ne '') && (exists($servers->{$current}))) {
3486: $checked = ' checked="checked"';
3487: }
3488: unless ($checked) {
3489: $default = ' selected="selected"';
3490: }
1.160.6.7 raeburn 3491: $extra =
3492: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3493: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3494: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3495: '<option value=""'.$default.'></option>'."\n";
3496: foreach my $server (sort(keys(%{$servers}))) {
3497: if (ref($currbalancer) eq 'HASH') {
3498: next if (exists($currbalancer->{$server}));
3499: }
1.150 raeburn 3500: my $selected;
1.160.6.7 raeburn 3501: if ($server eq $current) {
1.150 raeburn 3502: $selected = ' selected="selected"';
3503: }
1.160.6.7 raeburn 3504: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3505: }
3506: $extra .= '</select>';
3507: }
3508: } elsif ($rule eq $current) {
3509: $checked = ' checked="checked"';
3510: }
3511: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 3512: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3513: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3514: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3515: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3516: '</label>'.$extra.'</span><br />'."\n";
3517: }
3518: $output .= '</div></td></tr>'."\n";
3519: return $output;
3520: }
3521:
3522: sub offloadtype_text {
3523: my %ruletitles = &Apache::lonlocal::texthash (
3524: 'default' => 'Offloads to default destinations',
3525: 'homeserver' => "Offloads to user's home server",
3526: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3527: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 3528: 'none' => 'No offload',
1.160.6.26 raeburn 3529: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
3530: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.150 raeburn 3531: );
3532: return %ruletitles;
3533: }
3534:
3535: sub sparestype_titles {
3536: my %typestitles = &Apache::lonlocal::texthash (
3537: 'primary' => 'primary',
3538: 'default' => 'default',
3539: );
3540: return %typestitles;
3541: }
3542:
1.28 raeburn 3543: sub contact_titles {
3544: my %titles = &Apache::lonlocal::texthash (
3545: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3546: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3547: 'errormail' => 'Error reports to be e-mailed to',
3548: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3549: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3550: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3551: 'requestsmail' => 'E-mail from course requests requiring approval',
1.160.6.15 raeburn 3552: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 3553: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 3554: );
3555: my %short_titles = &Apache::lonlocal::texthash (
3556: adminemail => 'Admin E-mail address',
3557: supportemail => 'Support E-mail',
3558: );
3559: return (\%titles,\%short_titles);
3560: }
3561:
1.72 raeburn 3562: sub tool_titles {
3563: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 3564: aboutme => 'Personal web page',
1.86 raeburn 3565: blog => 'Blog',
1.160.6.4 raeburn 3566: webdav => 'WebDAV',
1.86 raeburn 3567: portfolio => 'Portfolio',
1.88 bisitz 3568: official => 'Official courses (with institutional codes)',
3569: unofficial => 'Unofficial courses',
1.98 raeburn 3570: community => 'Communities',
1.160.6.30! raeburn 3571: textbook => 'Textbook courses',
1.86 raeburn 3572: );
1.72 raeburn 3573: return %titles;
3574: }
3575:
1.101 raeburn 3576: sub courserequest_titles {
3577: my %titles = &Apache::lonlocal::texthash (
3578: official => 'Official',
3579: unofficial => 'Unofficial',
3580: community => 'Communities',
1.160.6.30! raeburn 3581: textbook => 'Textbook',
1.101 raeburn 3582: norequest => 'Not allowed',
1.104 raeburn 3583: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3584: validate => 'With validation',
3585: autolimit => 'Numerical limit',
1.103 raeburn 3586: unlimited => '(blank for unlimited)',
1.101 raeburn 3587: );
3588: return %titles;
3589: }
3590:
1.160.6.5 raeburn 3591: sub authorrequest_titles {
3592: my %titles = &Apache::lonlocal::texthash (
3593: norequest => 'Not allowed',
3594: approval => 'Approval by Dom. Coord.',
3595: automatic => 'Automatic approval',
3596: );
3597: return %titles;
3598: }
3599:
1.101 raeburn 3600: sub courserequest_conditions {
3601: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3602: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 3603: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 3604: );
3605: return %conditions;
3606: }
3607:
3608:
1.27 raeburn 3609: sub print_usercreation {
1.30 raeburn 3610: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3611: my $numinrow = 4;
1.28 raeburn 3612: my $datatable;
3613: if ($position eq 'top') {
1.30 raeburn 3614: $$rowtotal ++;
1.34 raeburn 3615: my $rowcount = 0;
1.32 raeburn 3616: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3617: if (ref($rules) eq 'HASH') {
3618: if (keys(%{$rules}) > 0) {
1.32 raeburn 3619: $datatable .= &user_formats_row('username',$settings,$rules,
3620: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3621: $$rowtotal ++;
1.32 raeburn 3622: $rowcount ++;
3623: }
3624: }
3625: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3626: if (ref($idrules) eq 'HASH') {
3627: if (keys(%{$idrules}) > 0) {
3628: $datatable .= &user_formats_row('id',$settings,$idrules,
3629: $idruleorder,$numinrow,$rowcount);
3630: $$rowtotal ++;
3631: $rowcount ++;
1.28 raeburn 3632: }
3633: }
1.43 raeburn 3634: my ($emailrules,$emailruleorder) =
3635: &Apache::lonnet::inst_userrules($dom,'email');
3636: if (ref($emailrules) eq 'HASH') {
3637: if (keys(%{$emailrules}) > 0) {
3638: $datatable .= &user_formats_row('email',$settings,$emailrules,
3639: $emailruleorder,$numinrow,$rowcount);
3640: $$rowtotal ++;
3641: $rowcount ++;
3642: }
3643: }
1.39 raeburn 3644: if ($rowcount == 0) {
3645: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3646: $$rowtotal ++;
3647: $rowcount ++;
3648: }
1.34 raeburn 3649: } elsif ($position eq 'middle') {
1.100 raeburn 3650: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 3651: my ($rules,$ruleorder) =
3652: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3653: my %lt = &usercreation_types();
3654: my %checked;
1.50 raeburn 3655: my @selfcreate;
1.34 raeburn 3656: if (ref($settings) eq 'HASH') {
3657: if (ref($settings->{'cancreate'}) eq 'HASH') {
3658: foreach my $item (@creators) {
3659: $checked{$item} = $settings->{'cancreate'}{$item};
3660: }
1.50 raeburn 3661: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3662: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3663: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3664: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3665: @selfcreate = ('email','login','sso');
3666: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3667: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3668: }
3669: }
1.34 raeburn 3670: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3671: foreach my $item (@creators) {
3672: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3673: $checked{$item} = 'none';
3674: }
3675: }
3676: }
3677: }
3678: my $rownum = 0;
3679: foreach my $item (@creators) {
3680: $rownum ++;
1.50 raeburn 3681: if ($item ne 'selfcreate') {
3682: if ($checked{$item} eq '') {
1.43 raeburn 3683: $checked{$item} = 'any';
3684: }
1.34 raeburn 3685: }
3686: my $css_class;
3687: if ($rownum%2) {
3688: $css_class = '';
3689: } else {
3690: $css_class = ' class="LC_odd_row" ';
3691: }
3692: $datatable .= '<tr'.$css_class.'>'.
3693: '<td><span class="LC_nobreak">'.$lt{$item}.
3694: '</span></td><td align="right">';
1.50 raeburn 3695: my @options;
1.45 raeburn 3696: if ($item eq 'selfcreate') {
1.43 raeburn 3697: push(@options,('email','login','sso'));
3698: } else {
1.50 raeburn 3699: @options = ('any');
1.43 raeburn 3700: if (ref($rules) eq 'HASH') {
3701: if (keys(%{$rules}) > 0) {
3702: push(@options,('official','unofficial'));
3703: }
1.37 raeburn 3704: }
1.50 raeburn 3705: push(@options,'none');
1.37 raeburn 3706: }
3707: foreach my $option (@options) {
1.50 raeburn 3708: my $type = 'radio';
1.34 raeburn 3709: my $check = ' ';
1.50 raeburn 3710: if ($item eq 'selfcreate') {
3711: $type = 'checkbox';
3712: if (grep(/^\Q$option\E$/,@selfcreate)) {
3713: $check = ' checked="checked" ';
3714: }
3715: } else {
3716: if ($checked{$item} eq $option) {
3717: $check = ' checked="checked" ';
3718: }
1.34 raeburn 3719: }
3720: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3721: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3722: $item.'" value="'.$option.'"'.$check.'/> '.
3723: $lt{$option}.'</label> </span>';
3724: }
3725: $datatable .= '</td></tr>';
3726: }
1.93 raeburn 3727: my ($othertitle,$usertypes,$types) =
3728: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.5 raeburn 3729: my $createsettings;
3730: if (ref($settings) eq 'HASH') {
3731: $createsettings = $settings->{cancreate};
3732: }
1.93 raeburn 3733: if (ref($usertypes) eq 'HASH') {
3734: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 3735: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 3736: $dom,$numinrow,$othertitle,
3737: 'statustocreate');
3738: $$rowtotal ++;
1.160.6.5 raeburn 3739: $rownum ++;
1.93 raeburn 3740: }
3741: }
1.160.6.5 raeburn 3742: $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
1.28 raeburn 3743: } else {
3744: my @contexts = ('author','course','domain');
3745: my @authtypes = ('int','krb4','krb5','loc');
3746: my %checked;
3747: if (ref($settings) eq 'HASH') {
3748: if (ref($settings->{'authtypes'}) eq 'HASH') {
3749: foreach my $item (@contexts) {
3750: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3751: foreach my $auth (@authtypes) {
3752: if ($settings->{'authtypes'}{$item}{$auth}) {
3753: $checked{$item}{$auth} = ' checked="checked" ';
3754: }
3755: }
3756: }
3757: }
1.27 raeburn 3758: }
1.35 raeburn 3759: } else {
3760: foreach my $item (@contexts) {
1.36 raeburn 3761: foreach my $auth (@authtypes) {
1.35 raeburn 3762: $checked{$item}{$auth} = ' checked="checked" ';
3763: }
3764: }
1.27 raeburn 3765: }
1.28 raeburn 3766: my %title = &context_names();
3767: my %authname = &authtype_names();
3768: my $rownum = 0;
3769: my $css_class;
3770: foreach my $item (@contexts) {
3771: if ($rownum%2) {
3772: $css_class = '';
3773: } else {
3774: $css_class = ' class="LC_odd_row" ';
3775: }
1.30 raeburn 3776: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3777: '<td>'.$title{$item}.
3778: '</td><td class="LC_left_item">'.
3779: '<span class="LC_nobreak">';
3780: foreach my $auth (@authtypes) {
3781: $datatable .= '<label>'.
3782: '<input type="checkbox" name="'.$item.'_auth" '.
3783: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3784: $authname{$auth}.'</label> ';
3785: }
3786: $datatable .= '</span></td></tr>';
3787: $rownum ++;
1.27 raeburn 3788: }
1.30 raeburn 3789: $$rowtotal += $rownum;
1.27 raeburn 3790: }
3791: return $datatable;
3792: }
3793:
1.160.6.5 raeburn 3794: sub captcha_choice {
3795: my ($context,$settings,$itemcount) = @_;
3796: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
3797: my %lt = &captcha_phrases();
3798: $keyentry = 'hidden';
3799: if ($context eq 'cancreate') {
3800: $rowname = &mt('CAPTCHA validation (e-mail as username)');
3801: } elsif ($context eq 'login') {
3802: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
3803: }
3804: if (ref($settings) eq 'HASH') {
3805: if ($settings->{'captcha'}) {
3806: $checked{$settings->{'captcha'}} = ' checked="checked"';
3807: } else {
3808: $checked{'original'} = ' checked="checked"';
3809: }
3810: if ($settings->{'captcha'} eq 'recaptcha') {
3811: $pubtext = $lt{'pub'};
3812: $privtext = $lt{'priv'};
3813: $keyentry = 'text';
3814: }
3815: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
3816: $currpub = $settings->{'recaptchakeys'}{'public'};
3817: $currpriv = $settings->{'recaptchakeys'}{'private'};
3818: }
3819: } else {
3820: $checked{'original'} = ' checked="checked"';
3821: }
3822: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3823: my $output = '<tr'.$css_class.'>'.
3824: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
3825: '<table><tr><td>'."\n";
3826: foreach my $option ('original','recaptcha','notused') {
3827: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
3828: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
3829: $lt{$option}.'</label></span>';
3830: unless ($option eq 'notused') {
3831: $output .= (' 'x2)."\n";
3832: }
3833: }
3834: #
3835: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
3836: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
3837: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
3838: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
3839: #
3840: $output .= '</td></tr>'."\n".
3841: '<tr><td>'."\n".
3842: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
3843: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
3844: $currpub.'" size="40" /></span><br />'."\n".
3845: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
3846: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
3847: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
3848: '</td></tr>';
3849: return $output;
3850: }
3851:
1.32 raeburn 3852: sub user_formats_row {
3853: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3854: my $output;
3855: my %text = (
3856: 'username' => 'new usernames',
3857: 'id' => 'IDs',
1.45 raeburn 3858: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3859: );
3860: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3861: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3862: '<td><span class="LC_nobreak">';
3863: if ($type eq 'email') {
3864: $output .= &mt("Formats disallowed for $text{$type}: ");
3865: } else {
3866: $output .= &mt("Format rules to check for $text{$type}: ");
3867: }
3868: $output .= '</span></td>'.
3869: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3870: my $rem;
3871: if (ref($ruleorder) eq 'ARRAY') {
3872: for (my $i=0; $i<@{$ruleorder}; $i++) {
3873: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3874: my $rem = $i%($numinrow);
3875: if ($rem == 0) {
3876: if ($i > 0) {
3877: $output .= '</tr>';
3878: }
3879: $output .= '<tr>';
3880: }
3881: my $check = ' ';
1.39 raeburn 3882: if (ref($settings) eq 'HASH') {
3883: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3884: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3885: $check = ' checked="checked" ';
3886: }
1.27 raeburn 3887: }
3888: }
3889: $output .= '<td class="LC_left_item">'.
3890: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3891: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 3892: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3893: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3894: }
3895: }
3896: $rem = @{$ruleorder}%($numinrow);
3897: }
3898: my $colsleft = $numinrow - $rem;
3899: if ($colsleft > 1 ) {
3900: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3901: ' </td>';
3902: } elsif ($colsleft == 1) {
3903: $output .= '<td class="LC_left_item"> </td>';
3904: }
3905: $output .= '</tr></table></td></tr>';
3906: return $output;
3907: }
3908:
1.34 raeburn 3909: sub usercreation_types {
3910: my %lt = &Apache::lonlocal::texthash (
3911: author => 'When adding a co-author',
3912: course => 'When adding a user to a course',
1.100 raeburn 3913: requestcrs => 'When requesting a course',
1.45 raeburn 3914: selfcreate => 'User creates own account',
1.34 raeburn 3915: any => 'Any',
3916: official => 'Institutional only ',
3917: unofficial => 'Non-institutional only',
1.85 schafran 3918: email => 'E-mail address',
1.43 raeburn 3919: login => 'Institutional Login',
3920: sso => 'SSO',
1.34 raeburn 3921: none => 'None',
3922: );
3923: return %lt;
1.48 raeburn 3924: }
1.34 raeburn 3925:
1.28 raeburn 3926: sub authtype_names {
3927: my %lt = &Apache::lonlocal::texthash(
3928: int => 'Internal',
3929: krb4 => 'Kerberos 4',
3930: krb5 => 'Kerberos 5',
3931: loc => 'Local',
3932: );
3933: return %lt;
3934: }
3935:
3936: sub context_names {
3937: my %context_title = &Apache::lonlocal::texthash(
3938: author => 'Creating users when an Author',
3939: course => 'Creating users when in a course',
3940: domain => 'Creating users when a Domain Coordinator',
3941: );
3942: return %context_title;
3943: }
3944:
1.33 raeburn 3945: sub print_usermodification {
3946: my ($position,$dom,$settings,$rowtotal) = @_;
3947: my $numinrow = 4;
3948: my ($context,$datatable,$rowcount);
3949: if ($position eq 'top') {
3950: $rowcount = 0;
3951: $context = 'author';
3952: foreach my $role ('ca','aa') {
3953: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3954: $numinrow,$rowcount);
3955: $$rowtotal ++;
3956: $rowcount ++;
3957: }
1.63 raeburn 3958: } elsif ($position eq 'middle') {
1.33 raeburn 3959: $context = 'course';
3960: $rowcount = 0;
3961: foreach my $role ('st','ep','ta','in','cr') {
3962: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3963: $numinrow,$rowcount);
3964: $$rowtotal ++;
3965: $rowcount ++;
3966: }
1.63 raeburn 3967: } elsif ($position eq 'bottom') {
3968: $context = 'selfcreate';
3969: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3970: $usertypes->{'default'} = $othertitle;
3971: if (ref($types) eq 'ARRAY') {
3972: push(@{$types},'default');
3973: $usertypes->{'default'} = $othertitle;
3974: foreach my $status (@{$types}) {
3975: $datatable .= &modifiable_userdata_row($context,$status,$settings,
3976: $numinrow,$rowcount,$usertypes);
3977: $$rowtotal ++;
3978: $rowcount ++;
3979: }
3980: }
1.33 raeburn 3981: }
3982: return $datatable;
3983: }
3984:
1.43 raeburn 3985: sub print_defaults {
1.160.6.27 raeburn 3986: my ($dom,$settings,$rowtotal) = @_;
1.68 raeburn 3987: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 3988: 'datelocale_def','portal_def');
1.160.6.27 raeburn 3989: my %defaults;
3990: if (ref($settings) eq 'HASH') {
3991: %defaults = %{$settings};
3992: } else {
3993: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
3994: foreach my $item (@items) {
3995: $defaults{$item} = $domdefaults{$item};
3996: }
3997: }
1.141 raeburn 3998: my $titles = &defaults_titles($dom);
1.43 raeburn 3999: my $rownum = 0;
4000: my ($datatable,$css_class);
4001: foreach my $item (@items) {
4002: if ($rownum%2) {
4003: $css_class = '';
4004: } else {
4005: $css_class = ' class="LC_odd_row" ';
4006: }
4007: $datatable .= '<tr'.$css_class.'>'.
4008: '<td><span class="LC_nobreak">'.$titles->{$item}.
4009: '</span></td><td class="LC_right_item">';
4010: if ($item eq 'auth_def') {
4011: my @authtypes = ('internal','krb4','krb5','localauth');
4012: my %shortauth = (
4013: internal => 'int',
4014: krb4 => 'krb4',
4015: krb5 => 'krb5',
4016: localauth => 'loc'
4017: );
4018: my %authnames = &authtype_names();
4019: foreach my $auth (@authtypes) {
4020: my $checked = ' ';
1.160.6.27 raeburn 4021: if ($defaults{$item} eq $auth) {
1.43 raeburn 4022: $checked = ' checked="checked" ';
4023: }
4024: $datatable .= '<label><input type="radio" name="'.$item.
4025: '" value="'.$auth.'"'.$checked.'/>'.
4026: $authnames{$shortauth{$auth}}.'</label> ';
4027: }
1.54 raeburn 4028: } elsif ($item eq 'timezone_def') {
4029: my $includeempty = 1;
1.160.6.27 raeburn 4030: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
1.68 raeburn 4031: } elsif ($item eq 'datelocale_def') {
4032: my $includeempty = 1;
1.160.6.27 raeburn 4033: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
1.160.6.5 raeburn 4034: } elsif ($item eq 'lang_def') {
4035: my %langchoices = &get_languages_hash();
4036: $langchoices{''} = 'No language preference';
4037: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.160.6.27 raeburn 4038: $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,
1.160.6.5 raeburn 4039: \%langchoices);
1.43 raeburn 4040: } else {
1.141 raeburn 4041: my $size;
4042: if ($item eq 'portal_def') {
4043: $size = ' size="25"';
4044: }
1.43 raeburn 4045: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.160.6.27 raeburn 4046: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 4047: }
4048: $datatable .= '</td></tr>';
4049: $rownum ++;
4050: }
4051: $$rowtotal += $rownum;
4052: return $datatable;
4053: }
4054:
1.160.6.5 raeburn 4055: sub get_languages_hash {
4056: my %langchoices;
4057: foreach my $id (&Apache::loncommon::languageids()) {
4058: my $code = &Apache::loncommon::supportedlanguagecode($id);
4059: if ($code ne '') {
4060: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
4061: }
4062: }
4063: return %langchoices;
4064: }
4065:
1.43 raeburn 4066: sub defaults_titles {
1.141 raeburn 4067: my ($dom) = @_;
1.43 raeburn 4068: my %titles = &Apache::lonlocal::texthash (
4069: 'auth_def' => 'Default authentication type',
4070: 'auth_arg_def' => 'Default authentication argument',
4071: 'lang_def' => 'Default language',
1.54 raeburn 4072: 'timezone_def' => 'Default timezone',
1.68 raeburn 4073: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 4074: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 4075: );
1.141 raeburn 4076: if ($dom) {
4077: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
4078: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
4079: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
4080: $protocol = 'http' if ($protocol ne 'https');
4081: if ($uint_dom) {
4082: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
4083: $uint_dom);
4084: }
4085: }
1.43 raeburn 4086: return (\%titles);
4087: }
4088:
1.46 raeburn 4089: sub print_scantronformat {
4090: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
4091: my $itemcount = 1;
1.60 raeburn 4092: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
4093: %confhash);
1.46 raeburn 4094: my $switchserver = &check_switchserver($dom,$confname);
4095: my %lt = &Apache::lonlocal::texthash (
1.95 www 4096: default => 'Default bubblesheet format file error',
4097: custom => 'Custom bubblesheet format file error',
1.46 raeburn 4098: );
4099: my %scantronfiles = (
4100: default => 'default.tab',
4101: custom => 'custom.tab',
4102: );
4103: foreach my $key (keys(%scantronfiles)) {
4104: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
4105: .$scantronfiles{$key};
4106: }
4107: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
4108: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
4109: if (!$switchserver) {
4110: my $servadm = $r->dir_config('lonAdmEMail');
4111: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
4112: if ($configuserok eq 'ok') {
4113: if ($author_ok eq 'ok') {
4114: my %legacyfile = (
4115: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
4116: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
4117: );
4118: my %md5chk;
4119: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4120: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
4121: chomp($md5chk{$type});
1.46 raeburn 4122: }
4123: if ($md5chk{'default'} ne $md5chk{'custom'}) {
4124: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4125: ($scantronurls{$type},my $error) =
1.46 raeburn 4126: &legacy_scantronformat($r,$dom,$confname,
4127: $type,$legacyfile{$type},
4128: $scantronurls{$type},
4129: $scantronfiles{$type});
1.60 raeburn 4130: if ($error ne '') {
4131: $error{$type} = $error;
4132: }
4133: }
4134: if (keys(%error) == 0) {
4135: $is_custom = 1;
4136: $confhash{'scantron'}{'scantronformat'} =
4137: $scantronurls{'custom'};
4138: my $putresult =
4139: &Apache::lonnet::put_dom('configuration',
4140: \%confhash,$dom);
4141: if ($putresult ne 'ok') {
4142: $error{'custom'} =
4143: '<span class="LC_error">'.
4144: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4145: }
1.46 raeburn 4146: }
4147: } else {
1.60 raeburn 4148: ($scantronurls{'default'},my $error) =
1.46 raeburn 4149: &legacy_scantronformat($r,$dom,$confname,
4150: 'default',$legacyfile{'default'},
4151: $scantronurls{'default'},
4152: $scantronfiles{'default'});
1.60 raeburn 4153: if ($error eq '') {
4154: $confhash{'scantron'}{'scantronformat'} = '';
4155: my $putresult =
4156: &Apache::lonnet::put_dom('configuration',
4157: \%confhash,$dom);
4158: if ($putresult ne 'ok') {
4159: $error{'default'} =
4160: '<span class="LC_error">'.
4161: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4162: }
4163: } else {
4164: $error{'default'} = $error;
4165: }
1.46 raeburn 4166: }
4167: }
4168: }
4169: } else {
1.95 www 4170: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 4171: }
4172: }
4173: if (ref($settings) eq 'HASH') {
4174: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
4175: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
4176: if ((!@info) || ($info[0] eq 'no_such_dir')) {
4177: $scantronurl = '';
4178: } else {
4179: $scantronurl = $settings->{'scantronformat'};
4180: }
4181: $is_custom = 1;
4182: } else {
4183: $scantronurl = $scantronurls{'default'};
4184: }
4185: } else {
1.60 raeburn 4186: if ($is_custom) {
4187: $scantronurl = $scantronurls{'custom'};
4188: } else {
4189: $scantronurl = $scantronurls{'default'};
4190: }
1.46 raeburn 4191: }
4192: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4193: $datatable .= '<tr'.$css_class.'>';
4194: if (!$is_custom) {
1.65 raeburn 4195: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
4196: '<span class="LC_nobreak">';
1.46 raeburn 4197: if ($scantronurl) {
1.160.6.21 raeburn 4198: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
4199: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 4200: } else {
4201: $datatable = &mt('File unavailable for display');
4202: }
1.65 raeburn 4203: $datatable .= '</span></td>';
1.60 raeburn 4204: if (keys(%error) == 0) {
4205: $datatable .= '<td valign="bottom">';
4206: if (!$switchserver) {
4207: $datatable .= &mt('Upload:').'<br />';
4208: }
4209: } else {
4210: my $errorstr;
4211: foreach my $key (sort(keys(%error))) {
4212: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4213: }
4214: $datatable .= '<td>'.$errorstr;
4215: }
1.46 raeburn 4216: } else {
4217: if (keys(%error) > 0) {
4218: my $errorstr;
4219: foreach my $key (sort(keys(%error))) {
4220: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4221: }
1.60 raeburn 4222: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 4223: } elsif ($scantronurl) {
1.160.6.26 raeburn 4224: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 4225: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 4226: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 4227: $link.
4228: '<label><input type="checkbox" name="scantronformat_del"'.
4229: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 4230: '<td><span class="LC_nobreak"> '.
4231: &mt('Replace:').'</span><br />';
1.46 raeburn 4232: }
4233: }
4234: if (keys(%error) == 0) {
4235: if ($switchserver) {
4236: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4237: } else {
1.65 raeburn 4238: $datatable .='<span class="LC_nobreak"> '.
4239: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 4240: }
4241: }
4242: $datatable .= '</td></tr>';
4243: $$rowtotal ++;
4244: return $datatable;
4245: }
4246:
4247: sub legacy_scantronformat {
4248: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
4249: my ($url,$error);
4250: my @statinfo = &Apache::lonnet::stat_file($newurl);
4251: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
4252: (my $result,$url) =
4253: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
4254: '','',$newfile);
4255: if ($result ne 'ok') {
1.130 raeburn 4256: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 4257: }
4258: }
4259: return ($url,$error);
4260: }
1.43 raeburn 4261:
1.49 raeburn 4262: sub print_coursecategories {
1.57 raeburn 4263: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
4264: my $datatable;
4265: if ($position eq 'top') {
4266: my $toggle_cats_crs = ' ';
4267: my $toggle_cats_dom = ' checked="checked" ';
4268: my $can_cat_crs = ' ';
4269: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 4270: my $toggle_catscomm_comm = ' ';
4271: my $toggle_catscomm_dom = ' checked="checked" ';
4272: my $can_catcomm_comm = ' ';
4273: my $can_catcomm_dom = ' checked="checked" ';
4274:
1.57 raeburn 4275: if (ref($settings) eq 'HASH') {
4276: if ($settings->{'togglecats'} eq 'crs') {
4277: $toggle_cats_crs = $toggle_cats_dom;
4278: $toggle_cats_dom = ' ';
4279: }
4280: if ($settings->{'categorize'} eq 'crs') {
4281: $can_cat_crs = $can_cat_dom;
4282: $can_cat_dom = ' ';
4283: }
1.120 raeburn 4284: if ($settings->{'togglecatscomm'} eq 'comm') {
4285: $toggle_catscomm_comm = $toggle_catscomm_dom;
4286: $toggle_catscomm_dom = ' ';
4287: }
4288: if ($settings->{'categorizecomm'} eq 'comm') {
4289: $can_catcomm_comm = $can_catcomm_dom;
4290: $can_catcomm_dom = ' ';
4291: }
1.57 raeburn 4292: }
4293: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 4294: togglecats => 'Show/Hide a course in catalog',
4295: togglecatscomm => 'Show/Hide a community in catalog',
4296: categorize => 'Assign a category to a course',
4297: categorizecomm => 'Assign a category to a community',
1.57 raeburn 4298: );
4299: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 4300: dom => 'Set in Domain',
4301: crs => 'Set in Course',
4302: comm => 'Set in Community',
1.57 raeburn 4303: );
4304: $datatable = '<tr class="LC_odd_row">'.
4305: '<td>'.$title{'togglecats'}.'</td>'.
4306: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4307: '<input type="radio" name="togglecats"'.
4308: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4309: '<label><input type="radio" name="togglecats"'.
4310: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
4311: '</tr><tr>'.
4312: '<td>'.$title{'categorize'}.'</td>'.
4313: '<td class="LC_right_item"><span class="LC_nobreak">'.
4314: '<label><input type="radio" name="categorize"'.
4315: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4316: '<label><input type="radio" name="categorize"'.
4317: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 4318: '</tr><tr class="LC_odd_row">'.
4319: '<td>'.$title{'togglecatscomm'}.'</td>'.
4320: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4321: '<input type="radio" name="togglecatscomm"'.
4322: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4323: '<label><input type="radio" name="togglecatscomm"'.
4324: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4325: '</tr><tr>'.
4326: '<td>'.$title{'categorizecomm'}.'</td>'.
4327: '<td class="LC_right_item"><span class="LC_nobreak">'.
4328: '<label><input type="radio" name="categorizecomm"'.
4329: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4330: '<label><input type="radio" name="categorizecomm"'.
4331: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 4332: '</tr>';
1.120 raeburn 4333: $$rowtotal += 4;
1.57 raeburn 4334: } else {
4335: my $css_class;
4336: my $itemcount = 1;
4337: my $cathash;
4338: if (ref($settings) eq 'HASH') {
4339: $cathash = $settings->{'cats'};
4340: }
4341: if (ref($cathash) eq 'HASH') {
4342: my (@cats,@trails,%allitems,%idx,@jsarray);
4343: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4344: \%allitems,\%idx,\@jsarray);
4345: my $maxdepth = scalar(@cats);
4346: my $colattrib = '';
4347: if ($maxdepth > 2) {
4348: $colattrib = ' colspan="2" ';
4349: }
4350: my @path;
4351: if (@cats > 0) {
4352: if (ref($cats[0]) eq 'ARRAY') {
4353: my $numtop = @{$cats[0]};
4354: my $maxnum = $numtop;
1.120 raeburn 4355: my %default_names = (
4356: instcode => &mt('Official courses'),
4357: communities => &mt('Communities'),
4358: );
4359:
4360: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4361: ($cathash->{'instcode::0'} eq '') ||
4362: (!grep(/^communities$/,@{$cats[0]})) ||
4363: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4364: $maxnum ++;
4365: }
4366: my $lastidx;
4367: for (my $i=0; $i<$numtop; $i++) {
4368: my $parent = $cats[0][$i];
4369: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4370: my $item = &escape($parent).'::0';
4371: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4372: $lastidx = $idx{$item};
4373: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4374: .'<select name="'.$item.'"'.$chgstr.'>';
4375: for (my $k=0; $k<=$maxnum; $k++) {
4376: my $vpos = $k+1;
4377: my $selstr;
4378: if ($k == $i) {
4379: $selstr = ' selected="selected" ';
4380: }
4381: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4382: }
1.160.6.29 raeburn 4383: $datatable .= '</select></span></td><td>';
1.120 raeburn 4384: if ($parent eq 'instcode' || $parent eq 'communities') {
4385: $datatable .= '<span class="LC_nobreak">'
4386: .$default_names{$parent}.'</span>';
4387: if ($parent eq 'instcode') {
4388: $datatable .= '<br /><span class="LC_nobreak">('
4389: .&mt('with institutional codes')
4390: .')</span></td><td'.$colattrib.'>';
4391: } else {
4392: $datatable .= '<table><tr><td>';
4393: }
4394: $datatable .= '<span class="LC_nobreak">'
4395: .'<label><input type="radio" name="'
4396: .$parent.'" value="1" checked="checked" />'
4397: .&mt('Display').'</label>';
4398: if ($parent eq 'instcode') {
4399: $datatable .= ' ';
4400: } else {
4401: $datatable .= '</span></td></tr><tr><td>'
4402: .'<span class="LC_nobreak">';
4403: }
4404: $datatable .= '<label><input type="radio" name="'
4405: .$parent.'" value="0" />'
4406: .&mt('Do not display').'</label></span>';
4407: if ($parent eq 'communities') {
4408: $datatable .= '</td></tr></table>';
4409: }
4410: $datatable .= '</td>';
1.57 raeburn 4411: } else {
4412: $datatable .= $parent
1.160.6.29 raeburn 4413: .' <span class="LC_nobreak"><label>'
4414: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 4415: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4416: }
4417: my $depth = 1;
4418: push(@path,$parent);
4419: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4420: pop(@path);
4421: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4422: $itemcount ++;
4423: }
1.48 raeburn 4424: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 4425: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4426: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 4427: for (my $k=0; $k<=$maxnum; $k++) {
4428: my $vpos = $k+1;
4429: my $selstr;
1.57 raeburn 4430: if ($k == $numtop) {
1.48 raeburn 4431: $selstr = ' selected="selected" ';
4432: }
4433: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4434: }
1.59 bisitz 4435: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 4436: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4437: .'</tr>'."\n";
1.48 raeburn 4438: $itemcount ++;
1.120 raeburn 4439: foreach my $default ('instcode','communities') {
4440: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4441: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4442: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4443: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4444: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4445: for (my $k=0; $k<=$maxnum; $k++) {
4446: my $vpos = $k+1;
4447: my $selstr;
4448: if ($k == $maxnum) {
4449: $selstr = ' selected="selected" ';
4450: }
4451: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 4452: }
1.120 raeburn 4453: $datatable .= '</select></span></td>'.
4454: '<td><span class="LC_nobreak">'.
4455: $default_names{$default}.'</span>';
4456: if ($default eq 'instcode') {
4457: $datatable .= '<br /><span class="LC_nobreak">('
4458: .&mt('with institutional codes').')</span>';
4459: }
4460: $datatable .= '</td>'
4461: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4462: .&mt('Display').'</label> '
4463: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
4464: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 4465: }
4466: }
4467: }
1.57 raeburn 4468: } else {
4469: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 4470: }
4471: } else {
1.57 raeburn 4472: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
4473: .&initialize_categories($itemcount);
1.48 raeburn 4474: }
1.57 raeburn 4475: $$rowtotal += $itemcount;
1.48 raeburn 4476: }
4477: return $datatable;
4478: }
4479:
1.69 raeburn 4480: sub print_serverstatuses {
4481: my ($dom,$settings,$rowtotal) = @_;
4482: my $datatable;
4483: my @pages = &serverstatus_pages();
4484: my (%namedaccess,%machineaccess);
4485: foreach my $type (@pages) {
4486: $namedaccess{$type} = '';
4487: $machineaccess{$type}= '';
4488: }
4489: if (ref($settings) eq 'HASH') {
4490: foreach my $type (@pages) {
4491: if (exists($settings->{$type})) {
4492: if (ref($settings->{$type}) eq 'HASH') {
4493: foreach my $key (keys(%{$settings->{$type}})) {
4494: if ($key eq 'namedusers') {
4495: $namedaccess{$type} = $settings->{$type}->{$key};
4496: } elsif ($key eq 'machines') {
4497: $machineaccess{$type} = $settings->{$type}->{$key};
4498: }
4499: }
4500: }
4501: }
4502: }
4503: }
1.81 raeburn 4504: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 4505: my $rownum = 0;
4506: my $css_class;
4507: foreach my $type (@pages) {
4508: $rownum ++;
4509: $css_class = $rownum%2?' class="LC_odd_row"':'';
4510: $datatable .= '<tr'.$css_class.'>'.
4511: '<td><span class="LC_nobreak">'.
4512: $titles->{$type}.'</span></td>'.
4513: '<td class="LC_left_item">'.
4514: '<input type="text" name="'.$type.'_namedusers" '.
4515: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
4516: '<td class="LC_right_item">'.
4517: '<span class="LC_nobreak">'.
4518: '<input type="text" name="'.$type.'_machines" '.
4519: 'value="'.$machineaccess{$type}.'" size="10" />'.
4520: '</td></tr>'."\n";
4521: }
4522: $$rowtotal += $rownum;
4523: return $datatable;
4524: }
4525:
4526: sub serverstatus_pages {
4527: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 4528: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.156 raeburn 4529: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69 raeburn 4530: }
4531:
1.49 raeburn 4532: sub coursecategories_javascript {
4533: my ($settings) = @_;
1.57 raeburn 4534: my ($output,$jstext,$cathash);
1.49 raeburn 4535: if (ref($settings) eq 'HASH') {
1.57 raeburn 4536: $cathash = $settings->{'cats'};
4537: }
4538: if (ref($cathash) eq 'HASH') {
1.49 raeburn 4539: my (@cats,@jsarray,%idx);
1.57 raeburn 4540: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 4541: if (@jsarray > 0) {
4542: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
4543: for (my $i=0; $i<@jsarray; $i++) {
4544: if (ref($jsarray[$i]) eq 'ARRAY') {
4545: my $catstr = join('","',@{$jsarray[$i]});
4546: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
4547: }
4548: }
4549: }
4550: } else {
4551: $jstext = ' var categories = Array(1);'."\n".
4552: ' categories[0] = Array("instcode_pos");'."\n";
4553: }
1.120 raeburn 4554: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
4555: my $communities_reserved = &mt('The name: "communities" is a reserved category');
4556: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 4557: $output = <<"ENDSCRIPT";
4558: <script type="text/javascript">
1.109 raeburn 4559: // <![CDATA[
1.49 raeburn 4560: function reorderCats(form,parent,item,idx) {
4561: var changedVal;
4562: $jstext
4563: var newpos = 'addcategory_pos';
4564: var current = new Array;
4565: if (parent == '') {
4566: var has_instcode = 0;
4567: var maxtop = categories[idx].length;
4568: for (var j=0; j<maxtop; j++) {
4569: if (categories[idx][j] == 'instcode::0') {
4570: has_instcode == 1;
4571: }
4572: }
4573: if (has_instcode == 0) {
4574: categories[idx][maxtop] = 'instcode_pos';
4575: }
4576: } else {
4577: newpos += '_'+parent;
4578: }
4579: var maxh = 1 + categories[idx].length;
4580: var current = new Array;
4581: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4582: if (item == newpos) {
4583: changedVal = newitemVal;
4584: } else {
4585: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4586: current[newitemVal] = newpos;
4587: }
4588: for (var i=0; i<categories[idx].length; i++) {
4589: var elementName = categories[idx][i];
4590: if (elementName != item) {
4591: if (form.elements[elementName]) {
4592: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4593: current[currVal] = elementName;
4594: }
4595: }
4596: }
4597: var oldVal;
4598: for (var j=0; j<maxh; j++) {
4599: if (current[j] == undefined) {
4600: oldVal = j;
4601: }
4602: }
4603: if (oldVal < changedVal) {
4604: for (var k=oldVal+1; k<=changedVal ; k++) {
4605: var elementName = current[k];
4606: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4607: }
4608: } else {
4609: for (var k=changedVal; k<oldVal; k++) {
4610: var elementName = current[k];
4611: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4612: }
4613: }
4614: return;
4615: }
1.120 raeburn 4616:
4617: function categoryCheck(form) {
4618: if (form.elements['addcategory_name'].value == 'instcode') {
4619: alert('$instcode_reserved\\n$choose_again');
4620: return false;
4621: }
4622: if (form.elements['addcategory_name'].value == 'communities') {
4623: alert('$communities_reserved\\n$choose_again');
4624: return false;
4625: }
4626: return true;
4627: }
4628:
1.109 raeburn 4629: // ]]>
1.49 raeburn 4630: </script>
4631:
4632: ENDSCRIPT
4633: return $output;
4634: }
4635:
1.48 raeburn 4636: sub initialize_categories {
4637: my ($itemcount) = @_;
1.120 raeburn 4638: my ($datatable,$css_class,$chgstr);
4639: my %default_names = (
4640: instcode => 'Official courses (with institutional codes)',
4641: communities => 'Communities',
4642: );
4643: my $select0 = ' selected="selected"';
4644: my $select1 = '';
4645: foreach my $default ('instcode','communities') {
4646: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4647: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
4648: if ($default eq 'communities') {
4649: $select1 = $select0;
4650: $select0 = '';
4651: }
4652: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4653: .'<select name="'.$default.'_pos">'
4654: .'<option value="0"'.$select0.'>1</option>'
4655: .'<option value="1"'.$select1.'>2</option>'
4656: .'<option value="2">3</option></select> '
4657: .$default_names{$default}
4658: .'</span></td><td><span class="LC_nobreak">'
4659: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4660: .&mt('Display').'</label> <label>'
4661: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 4662: .'</label></span></td></tr>';
1.120 raeburn 4663: $itemcount ++;
4664: }
1.48 raeburn 4665: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 4666: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 4667: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 4668: .'<select name="addcategory_pos"'.$chgstr.'>'
4669: .'<option value="0">1</option>'
4670: .'<option value="1">2</option>'
4671: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 4672: .&mt('Add category').'</td><td>'.&mt('Name:')
4673: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4674: return $datatable;
4675: }
4676:
4677: sub build_category_rows {
1.49 raeburn 4678: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4679: my ($text,$name,$item,$chgstr);
1.48 raeburn 4680: if (ref($cats) eq 'ARRAY') {
4681: my $maxdepth = scalar(@{$cats});
4682: if (ref($cats->[$depth]) eq 'HASH') {
4683: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4684: my $numchildren = @{$cats->[$depth]{$parent}};
4685: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 4686: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 4687: my ($idxnum,$parent_name,$parent_item);
4688: my $higher = $depth - 1;
4689: if ($higher == 0) {
4690: $parent_name = &escape($parent).'::'.$higher;
4691: } else {
4692: if (ref($path) eq 'ARRAY') {
4693: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4694: }
4695: }
4696: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4697: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4698: if ($j < $numchildren) {
1.48 raeburn 4699: $name = $cats->[$depth]{$parent}[$j];
4700: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4701: $idxnum = $idx->{$item};
4702: } else {
4703: $name = $parent_name;
4704: $item = $parent_item;
1.48 raeburn 4705: }
1.49 raeburn 4706: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4707: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4708: for (my $i=0; $i<=$numchildren; $i++) {
4709: my $vpos = $i+1;
4710: my $selstr;
4711: if ($j == $i) {
4712: $selstr = ' selected="selected" ';
4713: }
4714: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4715: }
4716: $text .= '</select> ';
4717: if ($j < $numchildren) {
4718: my $deeper = $depth+1;
4719: $text .= $name.' '
4720: .'<label><input type="checkbox" name="deletecategory" value="'
4721: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4722: if(ref($path) eq 'ARRAY') {
4723: push(@{$path},$name);
1.49 raeburn 4724: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4725: pop(@{$path});
4726: }
4727: } else {
1.59 bisitz 4728: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4729: if ($j == $numchildren) {
4730: $text .= $name;
4731: } else {
4732: $text .= $item;
4733: }
4734: $text .= '" value="" />';
4735: }
4736: $text .= '</td></tr>';
4737: }
4738: $text .= '</table></td>';
4739: } else {
4740: my $higher = $depth-1;
4741: if ($higher == 0) {
4742: $name = &escape($parent).'::'.$higher;
4743: } else {
4744: if (ref($path) eq 'ARRAY') {
4745: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4746: }
4747: }
4748: my $colspan;
4749: if ($parent ne 'instcode') {
4750: $colspan = $maxdepth - $depth - 1;
4751: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4752: }
4753: }
4754: }
4755: }
4756: return $text;
4757: }
4758:
1.33 raeburn 4759: sub modifiable_userdata_row {
1.63 raeburn 4760: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 4761: my $rolename;
1.63 raeburn 4762: if ($context eq 'selfcreate') {
4763: if (ref($usertypes) eq 'HASH') {
4764: $rolename = $usertypes->{$role};
4765: } else {
4766: $rolename = $role;
4767: }
1.33 raeburn 4768: } else {
1.63 raeburn 4769: if ($role eq 'cr') {
4770: $rolename = &mt('Custom role');
4771: } else {
4772: $rolename = &Apache::lonnet::plaintext($role);
4773: }
1.33 raeburn 4774: }
4775: my @fields = ('lastname','firstname','middlename','generation',
4776: 'permanentemail','id');
4777: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4778: my $output;
4779: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4780: $output = '<tr '.$css_class.'>'.
4781: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4782: '<td class="LC_left_item" colspan="2"><table>';
4783: my $rem;
4784: my %checks;
4785: if (ref($settings) eq 'HASH') {
4786: if (ref($settings->{$context}) eq 'HASH') {
4787: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4788: foreach my $field (@fields) {
4789: if ($settings->{$context}->{$role}->{$field}) {
4790: $checks{$field} = ' checked="checked" ';
4791: }
4792: }
4793: }
4794: }
4795: }
4796: for (my $i=0; $i<@fields; $i++) {
4797: my $rem = $i%($numinrow);
4798: if ($rem == 0) {
4799: if ($i > 0) {
4800: $output .= '</tr>';
4801: }
4802: $output .= '<tr>';
4803: }
4804: my $check = ' ';
4805: if (exists($checks{$fields[$i]})) {
4806: $check = $checks{$fields[$i]}
4807: } else {
4808: if ($role eq 'st') {
4809: if (ref($settings) ne 'HASH') {
4810: $check = ' checked="checked" ';
4811: }
4812: }
4813: }
4814: $output .= '<td class="LC_left_item">'.
4815: '<span class="LC_nobreak"><label>'.
4816: '<input type="checkbox" name="canmodify_'.$role.'" '.
4817: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4818: '</label></span></td>';
4819: $rem = @fields%($numinrow);
4820: }
4821: my $colsleft = $numinrow - $rem;
4822: if ($colsleft > 1 ) {
4823: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4824: ' </td>';
4825: } elsif ($colsleft == 1) {
4826: $output .= '<td class="LC_left_item"> </td>';
4827: }
4828: $output .= '</tr></table></td></tr>';
4829: return $output;
4830: }
1.28 raeburn 4831:
1.93 raeburn 4832: sub insttypes_row {
4833: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
4834: my %lt = &Apache::lonlocal::texthash (
4835: cansearch => 'Users allowed to search',
4836: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4837: lockablenames => 'User preference to lock name',
1.93 raeburn 4838: );
4839: my $showdom;
4840: if ($context eq 'cansearch') {
4841: $showdom = ' ('.$dom.')';
4842: }
1.160.6.5 raeburn 4843: my $class = 'LC_left_item';
4844: if ($context eq 'statustocreate') {
4845: $class = 'LC_right_item';
4846: }
1.25 raeburn 4847: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 4848: '<td>'.$lt{$context}.$showdom.
1.160.6.5 raeburn 4849: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 4850: my $rem;
4851: if (ref($types) eq 'ARRAY') {
4852: for (my $i=0; $i<@{$types}; $i++) {
4853: if (defined($usertypes->{$types->[$i]})) {
4854: my $rem = $i%($numinrow);
4855: if ($rem == 0) {
4856: if ($i > 0) {
4857: $output .= '</tr>';
4858: }
4859: $output .= '<tr>';
1.23 raeburn 4860: }
1.26 raeburn 4861: my $check = ' ';
1.99 raeburn 4862: if (ref($settings) eq 'HASH') {
4863: if (ref($settings->{$context}) eq 'ARRAY') {
4864: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4865: $check = ' checked="checked" ';
4866: }
4867: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4868: $check = ' checked="checked" ';
4869: }
1.23 raeburn 4870: }
1.26 raeburn 4871: $output .= '<td class="LC_left_item">'.
4872: '<span class="LC_nobreak"><label>'.
1.93 raeburn 4873: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 4874: 'value="'.$types->[$i].'"'.$check.'/>'.
4875: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 4876: }
4877: }
1.26 raeburn 4878: $rem = @{$types}%($numinrow);
1.23 raeburn 4879: }
4880: my $colsleft = $numinrow - $rem;
1.131 raeburn 4881: if (($rem == 0) && (@{$types} > 0)) {
4882: $output .= '<tr>';
4883: }
1.23 raeburn 4884: if ($colsleft > 1) {
1.25 raeburn 4885: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 4886: } else {
1.25 raeburn 4887: $output .= '<td class="LC_left_item">';
1.23 raeburn 4888: }
4889: my $defcheck = ' ';
1.99 raeburn 4890: if (ref($settings) eq 'HASH') {
4891: if (ref($settings->{$context}) eq 'ARRAY') {
4892: if (grep(/^default$/,@{$settings->{$context}})) {
4893: $defcheck = ' checked="checked" ';
4894: }
4895: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4896: $defcheck = ' checked="checked" ';
4897: }
1.23 raeburn 4898: }
1.25 raeburn 4899: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 4900: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 4901: 'value="default"'.$defcheck.'/>'.
4902: $othertitle.'</label></span></td>'.
4903: '</tr></table></td></tr>';
4904: return $output;
1.23 raeburn 4905: }
4906:
4907: sub sorted_searchtitles {
4908: my %searchtitles = &Apache::lonlocal::texthash(
4909: 'uname' => 'username',
4910: 'lastname' => 'last name',
4911: 'lastfirst' => 'last name, first name',
4912: );
4913: my @titleorder = ('uname','lastname','lastfirst');
4914: return (\%searchtitles,\@titleorder);
4915: }
4916:
1.25 raeburn 4917: sub sorted_searchtypes {
4918: my %srchtypes_desc = (
4919: exact => 'is exact match',
4920: contains => 'contains ..',
4921: begins => 'begins with ..',
4922: );
4923: my @srchtypeorder = ('exact','begins','contains');
4924: return (\%srchtypes_desc,\@srchtypeorder);
4925: }
4926:
1.3 raeburn 4927: sub usertype_update_row {
4928: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
4929: my $datatable;
4930: my $numinrow = 4;
4931: foreach my $type (@{$types}) {
4932: if (defined($usertypes->{$type})) {
4933: $$rownums ++;
4934: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
4935: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
4936: '</td><td class="LC_left_item"><table>';
4937: for (my $i=0; $i<@{$fields}; $i++) {
4938: my $rem = $i%($numinrow);
4939: if ($rem == 0) {
4940: if ($i > 0) {
4941: $datatable .= '</tr>';
4942: }
4943: $datatable .= '<tr>';
4944: }
4945: my $check = ' ';
1.39 raeburn 4946: if (ref($settings) eq 'HASH') {
4947: if (ref($settings->{'fields'}) eq 'HASH') {
4948: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
4949: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
4950: $check = ' checked="checked" ';
4951: }
1.3 raeburn 4952: }
4953: }
4954: }
4955:
4956: if ($i == @{$fields}-1) {
4957: my $colsleft = $numinrow - $rem;
4958: if ($colsleft > 1) {
4959: $datatable .= '<td colspan="'.$colsleft.'">';
4960: } else {
4961: $datatable .= '<td>';
4962: }
4963: } else {
4964: $datatable .= '<td>';
4965: }
1.8 raeburn 4966: $datatable .= '<span class="LC_nobreak"><label>'.
4967: '<input type="checkbox" name="updateable_'.$type.
4968: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
4969: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 4970: }
4971: $datatable .= '</tr></table></td></tr>';
4972: }
4973: }
4974: return $datatable;
1.1 raeburn 4975: }
4976:
4977: sub modify_login {
1.160.6.24 raeburn 4978: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 4979: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
4980: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
4981: %title = ( coursecatalog => 'Display course catalog',
4982: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 4983: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 4984: newuser => 'Link for visitors to create a user account',
4985: loginheader => 'Log-in box header');
4986: @offon = ('off','on');
1.112 raeburn 4987: if (ref($domconfig{login}) eq 'HASH') {
4988: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
4989: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
4990: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
4991: }
4992: }
4993: }
1.9 raeburn 4994: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
4995: \%domconfig,\%loginhash);
1.160.6.14 raeburn 4996: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 4997: foreach my $item (@toggles) {
4998: $loginhash{login}{$item} = $env{'form.'.$item};
4999: }
1.41 raeburn 5000: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 5001: if (ref($colchanges{'login'}) eq 'HASH') {
5002: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
5003: \%loginhash);
5004: }
1.110 raeburn 5005:
1.149 raeburn 5006: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 5007: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 5008: if (keys(%servers) > 1) {
5009: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 5010: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
5011: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
5012: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
5013: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
5014: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
5015: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5016: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5017: $changes{'loginvia'}{$lonhost} = 1;
5018: } else {
5019: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
5020: $changes{'loginvia'}{$lonhost} = 1;
5021: }
5022: } else {
5023: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5024: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5025: $changes{'loginvia'}{$lonhost} = 1;
5026: }
5027: }
5028: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
5029: foreach my $item (@loginvia_attribs) {
5030: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
5031: }
5032: } else {
5033: foreach my $item (@loginvia_attribs) {
5034: my $new = $env{'form.'.$lonhost.'_'.$item};
5035: if (($item eq 'serverpath') && ($new eq 'custom')) {
5036: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
5037: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5038: $new = '/';
5039: }
5040: }
5041: if (($item eq 'custompath') &&
5042: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5043: $new = '';
5044: }
5045: if ($new ne $curr_loginvia{$lonhost}{$item}) {
5046: $changes{'loginvia'}{$lonhost} = 1;
5047: }
5048: if ($item eq 'exempt') {
5049: $new =~ s/^\s+//;
5050: $new =~ s/\s+$//;
5051: my @poss_ips = split(/\s*[,:]\s*/,$new);
5052: my @okips;
5053: foreach my $ip (@poss_ips) {
5054: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
5055: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
5056: push(@okips,$ip);
5057: }
5058: }
5059: }
5060: if (@okips > 0) {
5061: $new = join(',',@okips);
5062: } else {
5063: $new = '';
5064: }
5065: }
5066: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5067: }
5068: }
1.112 raeburn 5069: } else {
1.128 raeburn 5070: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5071: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 5072: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 5073: foreach my $item (@loginvia_attribs) {
5074: my $new = $env{'form.'.$lonhost.'_'.$item};
5075: if (($item eq 'serverpath') && ($new eq 'custom')) {
5076: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5077: $new = '/';
5078: }
5079: }
5080: if (($item eq 'custompath') &&
5081: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5082: $new = '';
5083: }
5084: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5085: }
1.110 raeburn 5086: }
5087: }
5088: }
5089: }
1.119 raeburn 5090:
1.160.6.5 raeburn 5091: my $servadm = $r->dir_config('lonAdmEMail');
5092: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
5093: if (ref($domconfig{'login'}) eq 'HASH') {
5094: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
5095: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
5096: if ($lang eq 'nolang') {
5097: push(@currlangs,$lang);
5098: } elsif (defined($langchoices{$lang})) {
5099: push(@currlangs,$lang);
5100: } else {
5101: next;
5102: }
5103: }
5104: }
5105: }
5106: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
5107: if (@currlangs > 0) {
5108: foreach my $lang (@currlangs) {
5109: if (grep(/^\Q$lang\E$/,@delurls)) {
5110: $changes{'helpurl'}{$lang} = 1;
5111: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
5112: $changes{'helpurl'}{$lang} = 1;
5113: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
5114: push(@newlangs,$lang);
5115: } else {
5116: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5117: }
5118: }
5119: }
5120: unless (grep(/^nolang$/,@currlangs)) {
5121: if ($env{'form.loginhelpurl_nolang.filename'}) {
5122: $changes{'helpurl'}{'nolang'} = 1;
5123: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
5124: push(@newlangs,'nolang');
5125: }
5126: }
5127: if ($env{'form.loginhelpurl_add_lang'}) {
5128: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
5129: ($env{'form.loginhelpurl_add_file.filename'})) {
5130: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
5131: $addedfile = $env{'form.loginhelpurl_add_lang'};
5132: }
5133: }
5134: if ((@newlangs > 0) || ($addedfile)) {
5135: my $error;
5136: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
5137: if ($configuserok eq 'ok') {
5138: if ($switchserver) {
5139: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
5140: } elsif ($author_ok eq 'ok') {
5141: my @allnew = @newlangs;
5142: if ($addedfile ne '') {
5143: push(@allnew,$addedfile);
5144: }
5145: foreach my $lang (@allnew) {
5146: my $formelem = 'loginhelpurl_'.$lang;
5147: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
5148: $formelem = 'loginhelpurl_add_file';
5149: }
5150: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
5151: "help/$lang",'','',$newfile{$lang});
5152: if ($result eq 'ok') {
5153: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
5154: $changes{'helpurl'}{$lang} = 1;
5155: } else {
5156: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
5157: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
5158: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
5159: (!grep(/^\Q$lang\E$/,@delurls))) {
5160:
5161: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5162: }
5163: }
5164: }
5165: } else {
5166: $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);
5167: }
5168: } else {
5169: $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);
5170: }
5171: if ($error) {
5172: &Apache::lonnet::logthis($error);
5173: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
5174: }
5175: }
5176: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
5177:
5178: my $defaulthelpfile = '/adm/loginproblems.html';
5179: my $defaulttext = &mt('Default in use');
5180:
1.1 raeburn 5181: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
5182: $dom);
5183: if ($putresult eq 'ok') {
1.160.6.14 raeburn 5184: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5185: my %defaultchecked = (
5186: 'coursecatalog' => 'on',
1.160.6.14 raeburn 5187: 'helpdesk' => 'on',
1.42 raeburn 5188: 'adminmail' => 'off',
1.43 raeburn 5189: 'newuser' => 'off',
1.42 raeburn 5190: );
1.55 raeburn 5191: if (ref($domconfig{'login'}) eq 'HASH') {
5192: foreach my $item (@toggles) {
5193: if ($defaultchecked{$item} eq 'on') {
5194: if (($domconfig{'login'}{$item} eq '0') &&
5195: ($env{'form.'.$item} eq '1')) {
5196: $changes{$item} = 1;
5197: } elsif (($domconfig{'login'}{$item} eq '' ||
5198: $domconfig{'login'}{$item} eq '1') &&
5199: ($env{'form.'.$item} eq '0')) {
5200: $changes{$item} = 1;
5201: }
5202: } elsif ($defaultchecked{$item} eq 'off') {
5203: if (($domconfig{'login'}{$item} eq '1') &&
5204: ($env{'form.'.$item} eq '0')) {
5205: $changes{$item} = 1;
5206: } elsif (($domconfig{'login'}{$item} eq '' ||
5207: $domconfig{'login'}{$item} eq '0') &&
5208: ($env{'form.'.$item} eq '1')) {
5209: $changes{$item} = 1;
5210: }
1.42 raeburn 5211: }
5212: }
1.41 raeburn 5213: }
1.6 raeburn 5214: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 5215: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 5216: if (ref($lastactref) eq 'HASH') {
5217: $lastactref->{'domainconfig'} = 1;
5218: }
1.1 raeburn 5219: $resulttext = &mt('Changes made:').'<ul>';
5220: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 5221: if ($item eq 'loginvia') {
1.112 raeburn 5222: if (ref($changes{$item}) eq 'HASH') {
5223: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
5224: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 5225: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
5226: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
5227: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
5228: $protocol = 'http' if ($protocol ne 'https');
5229: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
5230:
5231: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
5232: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
5233: } else {
5234: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
5235: }
5236: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
5237: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
5238: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
5239: }
5240: $resulttext .= '</li>';
5241: } else {
5242: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
5243: }
1.112 raeburn 5244: } else {
1.128 raeburn 5245: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 5246: }
5247: }
1.128 raeburn 5248: $resulttext .= '</ul></li>';
1.112 raeburn 5249: }
1.160.6.5 raeburn 5250: } elsif ($item eq 'helpurl') {
5251: if (ref($changes{$item}) eq 'HASH') {
5252: foreach my $lang (sort(keys(%{$changes{$item}}))) {
5253: if (grep(/^\Q$lang\E$/,@delurls)) {
5254: my ($chg,$link);
5255: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
5256: if ($lang eq 'nolang') {
5257: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
5258: } else {
5259: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
5260: }
5261: $resulttext .= '<li>'.$chg.'</li>';
5262: } else {
5263: my $chg;
5264: if ($lang eq 'nolang') {
5265: $chg = &mt('custom log-in help file for no preferred language');
5266: } else {
5267: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
5268: }
5269: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
5270: $loginhash{'login'}{'helpurl'}{$lang}.
5271: '?inhibitmenu=yes',$chg,600,500).
5272: '</li>';
5273: }
5274: }
5275: }
5276: } elsif ($item eq 'captcha') {
5277: if (ref($loginhash{'login'}) eq 'HASH') {
5278: my $chgtxt;
5279: if ($loginhash{'login'}{$item} eq 'notused') {
5280: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
5281: } else {
5282: my %captchas = &captcha_phrases();
5283: if ($captchas{$loginhash{'login'}{$item}}) {
5284: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
5285: } else {
5286: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
5287: }
5288: }
5289: $resulttext .= '<li>'.$chgtxt.'</li>';
5290: }
5291: } elsif ($item eq 'recaptchakeys') {
5292: if (ref($loginhash{'login'}) eq 'HASH') {
5293: my ($privkey,$pubkey);
5294: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
5295: $pubkey = $loginhash{'login'}{$item}{'public'};
5296: $privkey = $loginhash{'login'}{$item}{'private'};
5297: }
5298: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
5299: if (!$pubkey) {
5300: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
5301: } else {
5302: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
5303: }
5304: if (!$privkey) {
5305: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
5306: } else {
5307: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
5308: }
5309: $chgtxt .= '</ul>';
5310: $resulttext .= '<li>'.$chgtxt.'</li>';
5311: }
1.41 raeburn 5312: } else {
5313: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
5314: }
1.1 raeburn 5315: }
1.6 raeburn 5316: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 5317: } else {
5318: $resulttext = &mt('No changes made to log-in page settings');
5319: }
5320: } else {
1.11 albertel 5321: $resulttext = '<span class="LC_error">'.
5322: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5323: }
1.6 raeburn 5324: if ($errors) {
1.9 raeburn 5325: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 5326: $errors.'</ul>';
5327: }
5328: return $resulttext;
5329: }
5330:
5331: sub color_font_choices {
5332: my %choices =
5333: &Apache::lonlocal::texthash (
5334: img => "Header",
5335: bgs => "Background colors",
5336: links => "Link colors",
1.55 raeburn 5337: images => "Images",
1.6 raeburn 5338: font => "Font color",
1.160.6.22 raeburn 5339: fontmenu => "Font menu",
1.76 raeburn 5340: pgbg => "Page",
1.6 raeburn 5341: tabbg => "Header",
5342: sidebg => "Border",
5343: link => "Link",
5344: alink => "Active link",
5345: vlink => "Visited link",
5346: );
5347: return %choices;
5348: }
5349:
5350: sub modify_rolecolors {
1.160.6.24 raeburn 5351: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 5352: my ($resulttext,%rolehash);
5353: $rolehash{'rolecolors'} = {};
1.55 raeburn 5354: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
5355: if ($domconfig{'rolecolors'} eq '') {
5356: $domconfig{'rolecolors'} = {};
5357: }
5358: }
1.9 raeburn 5359: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 5360: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
5361: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
5362: $dom);
5363: if ($putresult eq 'ok') {
5364: if (keys(%changes) > 0) {
1.41 raeburn 5365: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 5366: if (ref($lastactref) eq 'HASH') {
5367: $lastactref->{'domainconfig'} = 1;
5368: }
1.6 raeburn 5369: $resulttext = &display_colorchgs($dom,\%changes,$roles,
5370: $rolehash{'rolecolors'});
5371: } else {
5372: $resulttext = &mt('No changes made to default color schemes');
5373: }
5374: } else {
1.11 albertel 5375: $resulttext = '<span class="LC_error">'.
5376: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 5377: }
5378: if ($errors) {
5379: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5380: $errors.'</ul>';
5381: }
5382: return $resulttext;
5383: }
5384:
5385: sub modify_colors {
1.9 raeburn 5386: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 5387: my (%changes,%choices);
1.51 raeburn 5388: my @bgs;
1.6 raeburn 5389: my @links = ('link','alink','vlink');
1.41 raeburn 5390: my @logintext;
1.6 raeburn 5391: my @images;
5392: my $servadm = $r->dir_config('lonAdmEMail');
5393: my $errors;
1.160.6.22 raeburn 5394: my %defaults;
1.6 raeburn 5395: foreach my $role (@{$roles}) {
5396: if ($role eq 'login') {
1.12 raeburn 5397: %choices = &login_choices();
1.41 raeburn 5398: @logintext = ('textcol','bgcol');
1.12 raeburn 5399: } else {
5400: %choices = &color_font_choices();
5401: }
5402: if ($role eq 'login') {
1.41 raeburn 5403: @images = ('img','logo','domlogo','login');
1.51 raeburn 5404: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 5405: } else {
5406: @images = ('img');
1.160.6.22 raeburn 5407: @bgs = ('pgbg','tabbg','sidebg');
5408: }
5409: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
5410: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
5411: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
5412: }
5413: if ($role eq 'login') {
5414: foreach my $item (@logintext) {
5415: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'logintext'}{$item}) {
5416: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5417: }
5418: }
5419: } else {
5420: unless($env{'form.'.$role.'_fontmenu'} eq $defaults{'fontmenu'}) {
5421: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
5422: }
1.6 raeburn 5423: }
1.160.6.22 raeburn 5424: foreach my $item (@bgs) {
5425: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'bgs'}{$item} ) {
5426: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5427: }
5428: }
5429: foreach my $item (@links) {
5430: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'links'}{$item}) {
5431: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5432: }
1.6 raeburn 5433: }
1.46 raeburn 5434: my ($configuserok,$author_ok,$switchserver) =
5435: &config_check($dom,$confname,$servadm);
1.9 raeburn 5436: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 5437: if (ref($domconfig->{$role}) ne 'HASH') {
5438: $domconfig->{$role} = {};
5439: }
1.8 raeburn 5440: foreach my $img (@images) {
1.70 raeburn 5441: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
5442: if (defined($env{'form.login_showlogo_'.$img})) {
5443: $confhash->{$role}{'showlogo'}{$img} = 1;
5444: } else {
5445: $confhash->{$role}{'showlogo'}{$img} = 0;
5446: }
5447: }
1.18 albertel 5448: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
5449: && !defined($domconfig->{$role}{$img})
5450: && !$env{'form.'.$role.'_del_'.$img}
5451: && $env{'form.'.$role.'_import_'.$img}) {
5452: # import the old configured image from the .tab setting
5453: # if they haven't provided a new one
5454: $domconfig->{$role}{$img} =
5455: $env{'form.'.$role.'_import_'.$img};
5456: }
1.6 raeburn 5457: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 5458: my $error;
1.6 raeburn 5459: if ($configuserok eq 'ok') {
1.9 raeburn 5460: if ($switchserver) {
1.12 raeburn 5461: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 5462: } else {
5463: if ($author_ok eq 'ok') {
5464: my ($result,$logourl) =
5465: &publishlogo($r,'upload',$role.'_'.$img,
5466: $dom,$confname,$img,$width,$height);
5467: if ($result eq 'ok') {
5468: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 5469: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5470: } else {
1.12 raeburn 5471: $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 5472: }
5473: } else {
1.46 raeburn 5474: $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 5475: }
5476: }
5477: } else {
1.46 raeburn 5478: $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 5479: }
5480: if ($error) {
1.8 raeburn 5481: &Apache::lonnet::logthis($error);
1.11 albertel 5482: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 5483: }
5484: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 5485: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
5486: my $error;
5487: if ($configuserok eq 'ok') {
5488: # is confname an author?
5489: if ($switchserver eq '') {
5490: if ($author_ok eq 'ok') {
5491: my ($result,$logourl) =
5492: &publishlogo($r,'copy',$domconfig->{$role}{$img},
5493: $dom,$confname,$img,$width,$height);
5494: if ($result eq 'ok') {
5495: $confhash->{$role}{$img} = $logourl;
1.18 albertel 5496: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5497: }
5498: }
5499: }
5500: }
1.6 raeburn 5501: }
5502: }
5503: }
5504: if (ref($domconfig) eq 'HASH') {
5505: if (ref($domconfig->{$role}) eq 'HASH') {
5506: foreach my $img (@images) {
5507: if ($domconfig->{$role}{$img} ne '') {
5508: if ($env{'form.'.$role.'_del_'.$img}) {
5509: $confhash->{$role}{$img} = '';
1.12 raeburn 5510: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5511: } else {
1.9 raeburn 5512: if ($confhash->{$role}{$img} eq '') {
5513: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
5514: }
1.6 raeburn 5515: }
5516: } else {
5517: if ($env{'form.'.$role.'_del_'.$img}) {
5518: $confhash->{$role}{$img} = '';
1.12 raeburn 5519: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5520: }
5521: }
1.70 raeburn 5522: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
5523: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
5524: if ($confhash->{$role}{'showlogo'}{$img} ne
5525: $domconfig->{$role}{'showlogo'}{$img}) {
5526: $changes{$role}{'showlogo'}{$img} = 1;
5527: }
5528: } else {
5529: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5530: $changes{$role}{'showlogo'}{$img} = 1;
5531: }
5532: }
5533: }
5534: }
1.6 raeburn 5535: if ($domconfig->{$role}{'font'} ne '') {
5536: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
5537: $changes{$role}{'font'} = 1;
5538: }
5539: } else {
5540: if ($confhash->{$role}{'font'}) {
5541: $changes{$role}{'font'} = 1;
5542: }
5543: }
1.107 raeburn 5544: if ($role ne 'login') {
5545: if ($domconfig->{$role}{'fontmenu'} ne '') {
5546: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
5547: $changes{$role}{'fontmenu'} = 1;
5548: }
5549: } else {
5550: if ($confhash->{$role}{'fontmenu'}) {
5551: $changes{$role}{'fontmenu'} = 1;
5552: }
1.97 tempelho 5553: }
5554: }
1.6 raeburn 5555: foreach my $item (@bgs) {
5556: if ($domconfig->{$role}{$item} ne '') {
5557: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5558: $changes{$role}{'bgs'}{$item} = 1;
5559: }
5560: } else {
5561: if ($confhash->{$role}{$item}) {
5562: $changes{$role}{'bgs'}{$item} = 1;
5563: }
5564: }
5565: }
5566: foreach my $item (@links) {
5567: if ($domconfig->{$role}{$item} ne '') {
5568: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5569: $changes{$role}{'links'}{$item} = 1;
5570: }
5571: } else {
5572: if ($confhash->{$role}{$item}) {
5573: $changes{$role}{'links'}{$item} = 1;
5574: }
5575: }
5576: }
1.41 raeburn 5577: foreach my $item (@logintext) {
5578: if ($domconfig->{$role}{$item} ne '') {
5579: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5580: $changes{$role}{'logintext'}{$item} = 1;
5581: }
5582: } else {
5583: if ($confhash->{$role}{$item}) {
5584: $changes{$role}{'logintext'}{$item} = 1;
5585: }
5586: }
5587: }
1.6 raeburn 5588: } else {
5589: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5590: \@logintext,$confhash,\%changes);
1.6 raeburn 5591: }
5592: } else {
5593: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5594: \@logintext,$confhash,\%changes);
1.6 raeburn 5595: }
5596: }
5597: return ($errors,%changes);
5598: }
5599:
1.46 raeburn 5600: sub config_check {
5601: my ($dom,$confname,$servadm) = @_;
5602: my ($configuserok,$author_ok,$switchserver,%currroles);
5603: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
5604: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
5605: $confname,$servadm);
5606: if ($configuserok eq 'ok') {
5607: $switchserver = &check_switchserver($dom,$confname);
5608: if ($switchserver eq '') {
5609: $author_ok = &check_authorstatus($dom,$confname,%currroles);
5610: }
5611: }
5612: return ($configuserok,$author_ok,$switchserver);
5613: }
5614:
1.6 raeburn 5615: sub default_change_checker {
1.41 raeburn 5616: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 5617: foreach my $item (@{$links}) {
5618: if ($confhash->{$role}{$item}) {
5619: $changes->{$role}{'links'}{$item} = 1;
5620: }
5621: }
5622: foreach my $item (@{$bgs}) {
5623: if ($confhash->{$role}{$item}) {
5624: $changes->{$role}{'bgs'}{$item} = 1;
5625: }
5626: }
1.41 raeburn 5627: foreach my $item (@{$logintext}) {
5628: if ($confhash->{$role}{$item}) {
5629: $changes->{$role}{'logintext'}{$item} = 1;
5630: }
5631: }
1.6 raeburn 5632: foreach my $img (@{$images}) {
5633: if ($env{'form.'.$role.'_del_'.$img}) {
5634: $confhash->{$role}{$img} = '';
1.12 raeburn 5635: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 5636: }
1.70 raeburn 5637: if ($role eq 'login') {
5638: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5639: $changes->{$role}{'showlogo'}{$img} = 1;
5640: }
5641: }
1.6 raeburn 5642: }
5643: if ($confhash->{$role}{'font'}) {
5644: $changes->{$role}{'font'} = 1;
5645: }
1.48 raeburn 5646: }
1.6 raeburn 5647:
5648: sub display_colorchgs {
5649: my ($dom,$changes,$roles,$confhash) = @_;
5650: my (%choices,$resulttext);
5651: if (!grep(/^login$/,@{$roles})) {
5652: $resulttext = &mt('Changes made:').'<br />';
5653: }
5654: foreach my $role (@{$roles}) {
5655: if ($role eq 'login') {
5656: %choices = &login_choices();
5657: } else {
5658: %choices = &color_font_choices();
5659: }
5660: if (ref($changes->{$role}) eq 'HASH') {
5661: if ($role ne 'login') {
5662: $resulttext .= '<h4>'.&mt($role).'</h4>';
5663: }
5664: foreach my $key (sort(keys(%{$changes->{$role}}))) {
5665: if ($role ne 'login') {
5666: $resulttext .= '<ul>';
5667: }
5668: if (ref($changes->{$role}{$key}) eq 'HASH') {
5669: if ($role ne 'login') {
5670: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
5671: }
5672: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 5673: if (($role eq 'login') && ($key eq 'showlogo')) {
5674: if ($confhash->{$role}{$key}{$item}) {
5675: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
5676: } else {
5677: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
5678: }
5679: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 5680: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
5681: } else {
1.12 raeburn 5682: my $newitem = $confhash->{$role}{$item};
5683: if ($key eq 'images') {
5684: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
5685: }
5686: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 5687: }
5688: }
5689: if ($role ne 'login') {
5690: $resulttext .= '</ul></li>';
5691: }
5692: } else {
5693: if ($confhash->{$role}{$key} eq '') {
5694: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
5695: } else {
5696: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
5697: }
5698: }
5699: if ($role ne 'login') {
5700: $resulttext .= '</ul>';
5701: }
5702: }
5703: }
5704: }
1.3 raeburn 5705: return $resulttext;
1.1 raeburn 5706: }
5707:
1.9 raeburn 5708: sub thumb_dimensions {
5709: return ('200','50');
5710: }
5711:
1.16 raeburn 5712: sub check_dimensions {
5713: my ($inputfile) = @_;
5714: my ($fullwidth,$fullheight);
5715: if ($inputfile =~ m|^[/\w.\-]+$|) {
5716: if (open(PIPE,"identify $inputfile 2>&1 |")) {
5717: my $imageinfo = <PIPE>;
5718: if (!close(PIPE)) {
5719: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
5720: }
5721: chomp($imageinfo);
5722: my ($fullsize) =
1.21 raeburn 5723: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 5724: if ($fullsize) {
5725: ($fullwidth,$fullheight) = split(/x/,$fullsize);
5726: }
5727: }
5728: }
5729: return ($fullwidth,$fullheight);
5730: }
5731:
1.9 raeburn 5732: sub check_configuser {
5733: my ($uhome,$dom,$confname,$servadm) = @_;
5734: my ($configuserok,%currroles);
5735: if ($uhome eq 'no_host') {
5736: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
5737: my $configpass = &LONCAPA::Enrollment::create_password();
5738: $configuserok =
5739: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
5740: $configpass,'','','','','',undef,$servadm);
5741: } else {
5742: $configuserok = 'ok';
5743: %currroles =
5744: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
5745: }
5746: return ($configuserok,%currroles);
5747: }
5748:
5749: sub check_authorstatus {
5750: my ($dom,$confname,%currroles) = @_;
5751: my $author_ok;
1.40 raeburn 5752: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 5753: my $start = time;
5754: my $end = 0;
5755: $author_ok =
5756: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 5757: 'au',$end,$start,'','','domconfig');
1.9 raeburn 5758: } else {
5759: $author_ok = 'ok';
5760: }
5761: return $author_ok;
5762: }
5763:
5764: sub publishlogo {
1.46 raeburn 5765: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 5766: my ($output,$fname,$logourl);
5767: if ($action eq 'upload') {
5768: $fname=$env{'form.'.$formname.'.filename'};
5769: chop($env{'form.'.$formname});
5770: } else {
5771: ($fname) = ($formname =~ /([^\/]+)$/);
5772: }
1.46 raeburn 5773: if ($savefileas ne '') {
5774: $fname = $savefileas;
5775: }
1.9 raeburn 5776: $fname=&Apache::lonnet::clean_filename($fname);
5777: # See if there is anything left
5778: unless ($fname) { return ('error: no uploaded file'); }
5779: $fname="$subdir/$fname";
1.160.6.5 raeburn 5780: my $docroot=$r->dir_config('lonDocRoot');
5781: my $filepath="$docroot/priv";
5782: my $relpath = "$dom/$confname";
1.9 raeburn 5783: my ($fnamepath,$file,$fetchthumb);
5784: $file=$fname;
5785: if ($fname=~m|/|) {
5786: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
5787: }
1.160.6.26 raeburn 5788: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 5789: my $count;
1.160.6.5 raeburn 5790: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 5791: $filepath.="/$parts[$count]";
5792: if ((-e $filepath)!=1) {
5793: mkdir($filepath,02770);
5794: }
5795: }
5796: # Check for bad extension and disallow upload
5797: if ($file=~/\.(\w+)$/ &&
5798: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
5799: $output =
1.160.6.25 raeburn 5800: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 5801: } elsif ($file=~/\.(\w+)$/ &&
5802: !defined(&Apache::loncommon::fileembstyle($1))) {
5803: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
5804: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 5805: $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 5806: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 5807: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 5808: } else {
5809: my $source = $filepath.'/'.$file;
5810: my $logfile;
5811: if (!open($logfile,">>$source".'.log')) {
1.160.6.19 raeburn 5812: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 5813: }
5814: print $logfile
5815: "\n================= Publish ".localtime()." ================\n".
5816: $env{'user.name'}.':'.$env{'user.domain'}."\n";
5817: # Save the file
5818: if (!open(FH,'>'.$source)) {
5819: &Apache::lonnet::logthis('Failed to create '.$source);
5820: return (&mt('Failed to create file'));
5821: }
5822: if ($action eq 'upload') {
5823: if (!print FH ($env{'form.'.$formname})) {
5824: &Apache::lonnet::logthis('Failed to write to '.$source);
5825: return (&mt('Failed to write file'));
5826: }
5827: } else {
5828: my $original = &Apache::lonnet::filelocation('',$formname);
5829: if(!copy($original,$source)) {
5830: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
5831: return (&mt('Failed to write file'));
5832: }
5833: }
5834: close(FH);
5835: chmod(0660, $source); # Permissions to rw-rw---.
5836:
5837: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
5838: my $copyfile=$targetdir.'/'.$file;
5839:
5840: my @parts=split(/\//,$targetdir);
5841: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
5842: for (my $count=5;$count<=$#parts;$count++) {
5843: $path.="/$parts[$count]";
5844: if (!-e $path) {
5845: print $logfile "\nCreating directory ".$path;
5846: mkdir($path,02770);
5847: }
5848: }
5849: my $versionresult;
5850: if (-e $copyfile) {
5851: $versionresult = &logo_versioning($targetdir,$file,$logfile);
5852: } else {
5853: $versionresult = 'ok';
5854: }
5855: if ($versionresult eq 'ok') {
5856: if (copy($source,$copyfile)) {
5857: print $logfile "\nCopied original source to ".$copyfile."\n";
5858: $output = 'ok';
5859: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 5860: push(@{$modified_urls},[$copyfile,$source]);
5861: my $metaoutput =
5862: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
5863: unless ($registered_cleanup) {
5864: my $handlers = $r->get_handlers('PerlCleanupHandler');
5865: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5866: $registered_cleanup=1;
5867: }
1.9 raeburn 5868: } else {
5869: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
5870: $output = &mt('Failed to copy file to RES space').", $!";
5871: }
5872: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5873: my $inputfile = $filepath.'/'.$file;
5874: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 5875: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5876: if ($fullwidth ne '' && $fullheight ne '') {
5877: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5878: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5879: system("convert -sample $thumbsize $inputfile $outfile");
5880: chmod(0660, $filepath.'/tn-'.$file);
5881: if (-e $outfile) {
5882: my $copyfile=$targetdir.'/tn-'.$file;
5883: if (copy($outfile,$copyfile)) {
5884: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 5885: my $thumb_metaoutput =
5886: &write_metadata($dom,$confname,$formname,
5887: $targetdir,'tn-'.$file,$logfile);
5888: push(@{$modified_urls},[$copyfile,$outfile]);
5889: unless ($registered_cleanup) {
5890: my $handlers = $r->get_handlers('PerlCleanupHandler');
5891: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5892: $registered_cleanup=1;
5893: }
1.16 raeburn 5894: } else {
5895: print $logfile "\nUnable to write ".$copyfile.
5896: ':'.$!."\n";
5897: }
5898: }
1.9 raeburn 5899: }
5900: }
5901: }
5902: } else {
5903: $output = $versionresult;
5904: }
5905: }
5906: return ($output,$logourl);
5907: }
5908:
5909: sub logo_versioning {
5910: my ($targetdir,$file,$logfile) = @_;
5911: my $target = $targetdir.'/'.$file;
5912: my ($maxversion,$fn,$extn,$output);
5913: $maxversion = 0;
5914: if ($file =~ /^(.+)\.(\w+)$/) {
5915: $fn=$1;
5916: $extn=$2;
5917: }
5918: opendir(DIR,$targetdir);
5919: while (my $filename=readdir(DIR)) {
5920: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
5921: $maxversion=($1>$maxversion)?$1:$maxversion;
5922: }
5923: }
5924: $maxversion++;
5925: print $logfile "\nCreating old version ".$maxversion."\n";
5926: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
5927: if (copy($target,$copyfile)) {
5928: print $logfile "Copied old target to ".$copyfile."\n";
5929: $copyfile=$copyfile.'.meta';
5930: if (copy($target.'.meta',$copyfile)) {
5931: print $logfile "Copied old target metadata to ".$copyfile."\n";
5932: $output = 'ok';
5933: } else {
5934: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
5935: $output = &mt('Failed to copy old meta').", $!, ";
5936: }
5937: } else {
5938: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
5939: $output = &mt('Failed to copy old target').", $!, ";
5940: }
5941: return $output;
5942: }
5943:
5944: sub write_metadata {
5945: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
5946: my (%metadatafields,%metadatakeys,$output);
5947: $metadatafields{'title'}=$formname;
5948: $metadatafields{'creationdate'}=time;
5949: $metadatafields{'lastrevisiondate'}=time;
5950: $metadatafields{'copyright'}='public';
5951: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
5952: $env{'user.domain'};
5953: $metadatafields{'authorspace'}=$confname.':'.$dom;
5954: $metadatafields{'domain'}=$dom;
5955: {
5956: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
5957: my $mfh;
1.155 raeburn 5958: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 5959: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 5960: unless ($_=~/\./) {
5961: my $unikey=$_;
5962: $unikey=~/^([A-Za-z]+)/;
5963: my $tag=$1;
5964: $tag=~tr/A-Z/a-z/;
5965: print $mfh "\n\<$tag";
5966: foreach (split(/\,/,$metadatakeys{$unikey})) {
5967: my $value=$metadatafields{$unikey.'.'.$_};
5968: $value=~s/\"/\'\'/g;
5969: print $mfh ' '.$_.'="'.$value.'"';
5970: }
5971: print $mfh '>'.
5972: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
5973: .'</'.$tag.'>';
5974: }
5975: }
5976: $output = 'ok';
5977: print $logfile "\nWrote metadata";
5978: close($mfh);
5979: } else {
5980: print $logfile "\nFailed to open metadata file";
1.9 raeburn 5981: $output = &mt('Could not write metadata');
5982: }
5983: }
1.155 raeburn 5984: return $output;
5985: }
5986:
5987: sub notifysubscribed {
5988: foreach my $targetsource (@{$modified_urls}){
5989: next unless (ref($targetsource) eq 'ARRAY');
5990: my ($target,$source)=@{$targetsource};
5991: if ($source ne '') {
5992: if (open(my $logfh,'>>'.$source.'.log')) {
5993: print $logfh "\nCleanup phase: Notifications\n";
5994: my @subscribed=&subscribed_hosts($target);
5995: foreach my $subhost (@subscribed) {
5996: print $logfh "\nNotifying host ".$subhost.':';
5997: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
5998: print $logfh $reply;
5999: }
6000: my @subscribedmeta=&subscribed_hosts("$target.meta");
6001: foreach my $subhost (@subscribedmeta) {
6002: print $logfh "\nNotifying host for metadata only ".$subhost.':';
6003: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
6004: $subhost);
6005: print $logfh $reply;
6006: }
6007: print $logfh "\n============ Done ============\n";
1.160 raeburn 6008: close($logfh);
1.155 raeburn 6009: }
6010: }
6011: }
6012: return OK;
6013: }
6014:
6015: sub subscribed_hosts {
6016: my ($target) = @_;
6017: my @subscribed;
6018: if (open(my $fh,"<$target.subscription")) {
6019: while (my $subline=<$fh>) {
6020: if ($subline =~ /^($match_lonid):/) {
6021: my $host = $1;
6022: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
6023: unless (grep(/^\Q$host\E$/,@subscribed)) {
6024: push(@subscribed,$host);
6025: }
6026: }
6027: }
6028: }
6029: }
6030: return @subscribed;
1.9 raeburn 6031: }
6032:
6033: sub check_switchserver {
6034: my ($dom,$confname) = @_;
6035: my ($allowed,$switchserver);
6036: my $home = &Apache::lonnet::homeserver($confname,$dom);
6037: if ($home eq 'no_host') {
6038: $home = &Apache::lonnet::domain($dom,'primary');
6039: }
6040: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 6041: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
6042: if (!$allowed) {
1.160.6.11 raeburn 6043: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 6044: }
6045: return $switchserver;
6046: }
6047:
1.1 raeburn 6048: sub modify_quotas {
1.160.6.30! raeburn 6049: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 6050: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30! raeburn 6051: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
! 6052: $author_ok,$switchserver,$errors);
1.86 raeburn 6053: if ($action eq 'quotas') {
6054: $context = 'tools';
1.160.6.26 raeburn 6055: } else {
1.86 raeburn 6056: $context = $action;
6057: }
6058: if ($context eq 'requestcourses') {
1.160.6.30! raeburn 6059: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 6060: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 6061: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
6062: %titles = &courserequest_titles();
6063: $toolregexp = join('|',@usertools);
6064: %conditions = &courserequest_conditions();
1.160.6.30! raeburn 6065: $confname = $dom.'-domainconfig';
! 6066: my $servadm = $r->dir_config('lonAdmEMail');
! 6067: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.5 raeburn 6068: } elsif ($context eq 'requestauthor') {
6069: @usertools = ('author');
6070: %titles = &authorrequest_titles();
1.86 raeburn 6071: } else {
1.160.6.4 raeburn 6072: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 6073: %titles = &tool_titles();
1.86 raeburn 6074: }
1.160.6.27 raeburn 6075: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 6076: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6077: foreach my $key (keys(%env)) {
1.101 raeburn 6078: if ($context eq 'requestcourses') {
6079: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
6080: my $item = $1;
6081: my $type = $2;
6082: if ($type =~ /^limit_(.+)/) {
6083: $limithash{$item}{$1} = $env{$key};
6084: } else {
6085: $confhash{$item}{$type} = $env{$key};
6086: }
6087: }
1.160.6.5 raeburn 6088: } elsif ($context eq 'requestauthor') {
6089: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
6090: $confhash{$1} = $env{$key};
6091: }
1.101 raeburn 6092: } else {
1.86 raeburn 6093: if ($key =~ /^form\.quota_(.+)$/) {
6094: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 6095: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
6096: $confhash{'authorquota'}{$1} = $env{$key};
6097: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 6098: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
6099: }
1.72 raeburn 6100: }
6101: }
1.160.6.5 raeburn 6102: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.102 raeburn 6103: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
6104: @approvalnotify = sort(@approvalnotify);
6105: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30! raeburn 6106: my @crstypes = ('official','unofficial','community','textbook');
! 6107: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
! 6108: foreach my $type (@hasuniquecode) {
! 6109: if (grep(/^\Q$type\E$/,@crstypes)) {
! 6110: $confhash{'uniquecode'}{$type} = 1;
! 6111: }
! 6112: }
! 6113: my ($newbook,@allpos);
! 6114: if ($context eq 'requestcourses') {
! 6115: if ($env{'form.addbook'}) {
! 6116: if (($env{'form.addbook_cnum'} =~ /^$match_courseid$/) &&
! 6117: ($env{'form.addbook_cdom'} =~ /^$match_domain$/)) {
! 6118: if (&Apache::lonnet::homeserver($env{'form.addbook_cnum'},
! 6119: $env{'form.addbook_cdom'}) eq 'no_host') {
! 6120: $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
! 6121: '</span></li>';
! 6122: } else {
! 6123: $newbook = $env{'form.addbook_cdom'}.'_'.$env{'form.addbook_cnum'};
! 6124: my $position = $env{'form.addbook_pos'};
! 6125: $position =~ s/\D+//g;
! 6126: if ($position ne '') {
! 6127: $allpos[$position] = $newbook;
! 6128: }
! 6129: }
! 6130: } else {
! 6131: $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
! 6132: '</span></li>';
! 6133: }
! 6134: }
! 6135: }
1.102 raeburn 6136: if (ref($domconfig{$action}) eq 'HASH') {
6137: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
6138: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
6139: $changes{'notify'}{'approval'} = 1;
6140: }
6141: } else {
1.144 raeburn 6142: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6143: $changes{'notify'}{'approval'} = 1;
6144: }
6145: }
1.160.6.30! raeburn 6146: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
! 6147: if (ref($confhash{'uniquecode'}) eq 'HASH') {
! 6148: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
! 6149: unless ($confhash{'uniquecode'}{$crstype}) {
! 6150: $changes{'uniquecode'} = 1;
! 6151: }
! 6152: }
! 6153: unless ($changes{'uniquecode'}) {
! 6154: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
! 6155: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
! 6156: $changes{'uniquecode'} = 1;
! 6157: }
! 6158: }
! 6159: }
! 6160: } else {
! 6161: $changes{'uniquecode'} = 1;
! 6162: }
! 6163: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
! 6164: $changes{'uniquecode'} = 1;
! 6165: }
! 6166: if ($context eq 'requestcourses') {
! 6167: if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
! 6168: my %deletions;
! 6169: my @todelete = &Apache::loncommon::get_env_multiple('form.book_del');
! 6170: if (@todelete) {
! 6171: map { $deletions{$_} = 1; } @todelete;
! 6172: }
! 6173: my %imgdeletions;
! 6174: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.book_image_del');
! 6175: if (@todeleteimages) {
! 6176: map { $imgdeletions{$_} = 1; } @todeleteimages;
! 6177: }
! 6178: my $maxnum = $env{'form.book_maxnum'};
! 6179: for (my $i=0; $i<=$maxnum; $i++) {
! 6180: my $key = $env{'form.book_id_'.$i};
! 6181: if (ref($domconfig{$action}{'textbooks'}{$key}) eq 'HASH') {
! 6182: if ($deletions{$key}) {
! 6183: if ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
! 6184: #FIXME need to obsolete item in RES space
! 6185: }
! 6186: next;
! 6187: } else {
! 6188: my $newpos = $env{'form.'.$key};
! 6189: $newpos =~ s/\D+//g;
! 6190: foreach my $item ('subject','title','author') {
! 6191: $confhash{'textbooks'}{$key}{$item} = $env{'form.book_'.$item.'_'.$i};
! 6192: if ($domconfig{$action}{'textbooks'}{$key}{$item} ne $confhash{'textbooks'}{$key}{$item}) {
! 6193: $changes{'textbooks'}{$key} = 1;
! 6194: }
! 6195: }
! 6196: $allpos[$newpos] = $key;
! 6197: }
! 6198: if ($imgdeletions{$key}) {
! 6199: $changes{'textbooks'}{$key} = 1;
! 6200: #FIXME need to obsolete item in RES space
! 6201: } elsif ($env{'form.book_image_'.$i.'.filename'}) {
! 6202: my ($cdom,$cnum) = split(/_/,$key);
! 6203: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,'book_image_'.$i,
! 6204: $cdom,$cnum,$configuserok,
! 6205: $switchserver,$author_ok);
! 6206: if ($imgurl) {
! 6207: $confhash{'textbooks'}{$key}{'image'} = $imgurl;
! 6208: $changes{'textbooks'}{$key} = 1;
! 6209: }
! 6210: if ($error) {
! 6211: &Apache::lonnet::logthis($error);
! 6212: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
! 6213: }
! 6214: } elsif ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
! 6215: $confhash{'textbooks'}{$key}{'image'} =
! 6216: $domconfig{$action}{'textbooks'}{$key}{'image'};
! 6217: }
! 6218: }
! 6219: }
! 6220: }
! 6221: }
1.102 raeburn 6222: } else {
1.144 raeburn 6223: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6224: $changes{'notify'}{'approval'} = 1;
6225: }
1.160.6.30! raeburn 6226: if (ref($confhash{'uniquecode'} eq 'HASH')) {
! 6227: $changes{'uniquecode'} = 1;
! 6228: }
! 6229: }
! 6230: if ($context eq 'requestcourses') {
! 6231: if ($newbook) {
! 6232: $changes{'textbooks'}{$newbook} = 1;
! 6233: foreach my $item ('subject','title','author') {
! 6234: $env{'form.addbook_'.$item} =~ s/(`)/'/g;
! 6235: if ($env{'form.addbook_'.$item}) {
! 6236: $confhash{'textbooks'}{$newbook}{$item} = $env{'form.addbook_'.$item};
! 6237: }
! 6238: }
! 6239: if ($env{'form.addbook_image.filename'} ne '') {
! 6240: my ($cdom,$cnum) = split(/_/,$newbook);
! 6241: my ($imageurl,$error) =
! 6242: &process_textbook_image($r,$dom,$confname,'addbook_image',$cdom,$cnum,$configuserok,
! 6243: $switchserver,$author_ok);
! 6244: if ($imageurl) {
! 6245: $confhash{'textbooks'}{$newbook}{'image'} = $imageurl;
! 6246: }
! 6247: if ($error) {
! 6248: &Apache::lonnet::logthis($error);
! 6249: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
! 6250: }
! 6251: }
! 6252: }
! 6253: if (@allpos > 0) {
! 6254: my $idx = 0;
! 6255: foreach my $item (@allpos) {
! 6256: if ($item ne '') {
! 6257: $confhash{'textbooks'}{$item}{'order'} = $idx;
! 6258: if (ref($domconfig{$action}) eq 'HASH') {
! 6259: if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
! 6260: if (ref($domconfig{$action}{'textbooks'}{$item}) eq 'HASH') {
! 6261: if ($domconfig{$action}{'textbooks'}{$item}{'order'} ne $idx) {
! 6262: $changes{'textbooks'}{$item} = 1;
! 6263: }
! 6264: }
! 6265: }
! 6266: }
! 6267: $idx ++;
! 6268: }
! 6269: }
! 6270: }
1.102 raeburn 6271: }
6272: } else {
1.86 raeburn 6273: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 6274: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 6275: }
1.72 raeburn 6276: foreach my $item (@usertools) {
6277: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 6278: my $unset;
1.101 raeburn 6279: if ($context eq 'requestcourses') {
1.104 raeburn 6280: $unset = '0';
6281: if ($type eq '_LC_adv') {
6282: $unset = '';
6283: }
1.101 raeburn 6284: if ($confhash{$item}{$type} eq 'autolimit') {
6285: $confhash{$item}{$type} .= '=';
6286: unless ($limithash{$item}{$type} =~ /\D/) {
6287: $confhash{$item}{$type} .= $limithash{$item}{$type};
6288: }
6289: }
1.160.6.5 raeburn 6290: } elsif ($context eq 'requestauthor') {
6291: $unset = '0';
6292: if ($type eq '_LC_adv') {
6293: $unset = '';
6294: }
1.72 raeburn 6295: } else {
1.101 raeburn 6296: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
6297: $confhash{$item}{$type} = 1;
6298: } else {
6299: $confhash{$item}{$type} = 0;
6300: }
1.72 raeburn 6301: }
1.86 raeburn 6302: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 6303: if ($action eq 'requestauthor') {
6304: if ($domconfig{$action}{$type} ne $confhash{$type}) {
6305: $changes{$type} = 1;
6306: }
6307: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 6308: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
6309: $changes{$item}{$type} = 1;
6310: }
6311: } else {
6312: if ($context eq 'requestcourses') {
1.104 raeburn 6313: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 6314: $changes{$item}{$type} = 1;
6315: }
6316: } else {
6317: if (!$confhash{$item}{$type}) {
6318: $changes{$item}{$type} = 1;
6319: }
6320: }
6321: }
6322: } else {
6323: if ($context eq 'requestcourses') {
1.104 raeburn 6324: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 6325: $changes{$item}{$type} = 1;
6326: }
1.160.6.5 raeburn 6327: } elsif ($context eq 'requestauthor') {
6328: if ($confhash{$type} ne $unset) {
6329: $changes{$type} = 1;
6330: }
1.72 raeburn 6331: } else {
6332: if (!$confhash{$item}{$type}) {
6333: $changes{$item}{$type} = 1;
6334: }
6335: }
6336: }
1.1 raeburn 6337: }
6338: }
1.160.6.5 raeburn 6339: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 6340: if (ref($domconfig{'quotas'}) eq 'HASH') {
6341: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
6342: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
6343: if (exists($confhash{'defaultquota'}{$key})) {
6344: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
6345: $changes{'defaultquota'}{$key} = 1;
6346: }
6347: } else {
6348: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 6349: }
6350: }
1.86 raeburn 6351: } else {
6352: foreach my $key (keys(%{$domconfig{'quotas'}})) {
6353: if (exists($confhash{'defaultquota'}{$key})) {
6354: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
6355: $changes{'defaultquota'}{$key} = 1;
6356: }
6357: } else {
6358: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 6359: }
1.1 raeburn 6360: }
6361: }
1.160.6.20 raeburn 6362: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
6363: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
6364: if (exists($confhash{'authorquota'}{$key})) {
6365: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
6366: $changes{'authorquota'}{$key} = 1;
6367: }
6368: } else {
6369: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
6370: }
6371: }
6372: }
1.1 raeburn 6373: }
1.86 raeburn 6374: if (ref($confhash{'defaultquota'}) eq 'HASH') {
6375: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
6376: if (ref($domconfig{'quotas'}) eq 'HASH') {
6377: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
6378: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
6379: $changes{'defaultquota'}{$key} = 1;
6380: }
6381: } else {
6382: if (!exists($domconfig{'quotas'}{$key})) {
6383: $changes{'defaultquota'}{$key} = 1;
6384: }
1.72 raeburn 6385: }
6386: } else {
1.86 raeburn 6387: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 6388: }
1.1 raeburn 6389: }
6390: }
1.160.6.20 raeburn 6391: if (ref($confhash{'authorquota'}) eq 'HASH') {
6392: foreach my $key (keys(%{$confhash{'authorquota'}})) {
6393: if (ref($domconfig{'quotas'}) eq 'HASH') {
6394: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
6395: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
6396: $changes{'authorquota'}{$key} = 1;
6397: }
6398: } else {
6399: $changes{'authorquota'}{$key} = 1;
6400: }
6401: } else {
6402: $changes{'authorquota'}{$key} = 1;
6403: }
6404: }
6405: }
1.1 raeburn 6406: }
1.72 raeburn 6407:
1.160.6.5 raeburn 6408: if ($context eq 'requestauthor') {
6409: $domdefaults{'requestauthor'} = \%confhash;
6410: } else {
6411: foreach my $key (keys(%confhash)) {
1.160.6.30! raeburn 6412: unless (($context eq 'requestcourses') && ($key eq 'textbooks')) {
! 6413: $domdefaults{$key} = $confhash{$key};
! 6414: }
1.160.6.5 raeburn 6415: }
1.72 raeburn 6416: }
1.160.6.5 raeburn 6417:
1.1 raeburn 6418: my %quotahash = (
1.86 raeburn 6419: $action => { %confhash }
1.1 raeburn 6420: );
6421: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
6422: $dom);
6423: if ($putresult eq 'ok') {
6424: if (keys(%changes) > 0) {
1.72 raeburn 6425: my $cachetime = 24*60*60;
6426: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 6427: if (ref($lastactref) eq 'HASH') {
6428: $lastactref->{'domdefaults'} = 1;
6429: }
1.1 raeburn 6430: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 6431: unless (($context eq 'requestcourses') ||
6432: ($context eq 'requestauthor')) {
1.86 raeburn 6433: if (ref($changes{'defaultquota'}) eq 'HASH') {
6434: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
6435: foreach my $type (@{$types},'default') {
6436: if (defined($changes{'defaultquota'}{$type})) {
6437: my $typetitle = $usertypes->{$type};
6438: if ($type eq 'default') {
6439: $typetitle = $othertitle;
6440: }
1.160.6.28 raeburn 6441: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 6442: }
6443: }
1.86 raeburn 6444: $resulttext .= '</ul></li>';
1.72 raeburn 6445: }
1.160.6.20 raeburn 6446: if (ref($changes{'authorquota'}) eq 'HASH') {
6447: $resulttext .= '<li>'.&mt('Authoring space default quotas').'<ul>';
6448: foreach my $type (@{$types},'default') {
6449: if (defined($changes{'authorquota'}{$type})) {
6450: my $typetitle = $usertypes->{$type};
6451: if ($type eq 'default') {
6452: $typetitle = $othertitle;
6453: }
1.160.6.28 raeburn 6454: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 6455: }
6456: }
6457: $resulttext .= '</ul></li>';
6458: }
1.72 raeburn 6459: }
1.80 raeburn 6460: my %newenv;
1.72 raeburn 6461: foreach my $item (@usertools) {
1.160.6.5 raeburn 6462: my (%haschgs,%inconf);
6463: if ($context eq 'requestauthor') {
6464: %haschgs = %changes;
6465: %inconf = %confhash;
6466: } else {
6467: if (ref($changes{$item}) eq 'HASH') {
6468: %haschgs = %{$changes{$item}};
6469: }
6470: if (ref($confhash{$item}) eq 'HASH') {
6471: %inconf = %{$confhash{$item}};
6472: }
6473: }
6474: if (keys(%haschgs) > 0) {
1.80 raeburn 6475: my $newacc =
6476: &Apache::lonnet::usertools_access($env{'user.name'},
6477: $env{'user.domain'},
1.86 raeburn 6478: $item,'reload',$context);
1.160.6.5 raeburn 6479: if (($context eq 'requestcourses') ||
6480: ($context eq 'requestauthor')) {
1.108 raeburn 6481: if ($env{'environment.canrequest.'.$item} ne $newacc) {
6482: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 6483: }
6484: } else {
6485: if ($env{'environment.availabletools.'.$item} ne $newacc) {
6486: $newenv{'environment.availabletools.'.$item} = $newacc;
6487: }
1.80 raeburn 6488: }
1.160.6.5 raeburn 6489: unless ($context eq 'requestauthor') {
6490: $resulttext .= '<li>'.$titles{$item}.'<ul>';
6491: }
1.72 raeburn 6492: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 6493: if ($haschgs{$type}) {
1.72 raeburn 6494: my $typetitle = $usertypes->{$type};
6495: if ($type eq 'default') {
6496: $typetitle = $othertitle;
6497: } elsif ($type eq '_LC_adv') {
6498: $typetitle = 'LON-CAPA Advanced Users';
6499: }
1.160.6.5 raeburn 6500: if ($inconf{$type}) {
1.101 raeburn 6501: if ($context eq 'requestcourses') {
6502: my $cond;
1.160.6.5 raeburn 6503: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 6504: if ($1 eq '') {
6505: $cond = &mt('(Automatic processing of any request).');
6506: } else {
6507: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
6508: }
6509: } else {
1.160.6.5 raeburn 6510: $cond = $conditions{$inconf{$type}};
1.101 raeburn 6511: }
6512: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 6513: } elsif ($context eq 'requestauthor') {
6514: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
6515: $titles{$inconf{$type}},$typetitle);
6516:
1.101 raeburn 6517: } else {
6518: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
6519: }
1.72 raeburn 6520: } else {
1.104 raeburn 6521: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 6522: if ($inconf{$type} eq '0') {
1.104 raeburn 6523: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6524: } else {
6525: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
6526: }
6527: } else {
6528: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6529: }
1.72 raeburn 6530: }
6531: }
1.26 raeburn 6532: }
1.160.6.5 raeburn 6533: unless ($context eq 'requestauthor') {
6534: $resulttext .= '</ul></li>';
6535: }
1.26 raeburn 6536: }
1.1 raeburn 6537: }
1.160.6.5 raeburn 6538: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 6539: if (ref($changes{'notify'}) eq 'HASH') {
6540: if ($changes{'notify'}{'approval'}) {
6541: if (ref($confhash{'notify'}) eq 'HASH') {
6542: if ($confhash{'notify'}{'approval'}) {
6543: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
6544: } else {
1.160.6.5 raeburn 6545: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 6546: }
6547: }
6548: }
6549: }
6550: }
1.160.6.30! raeburn 6551: if ($action eq 'requestcourses') {
! 6552: my @offon = ('off','on');
! 6553: if ($changes{'uniquecode'}) {
! 6554: if (ref($confhash{'uniquecode'}) eq 'HASH') {
! 6555: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
! 6556: $resulttext .= '<li>'.
! 6557: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
! 6558: '</li>';
! 6559: } else {
! 6560: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
! 6561: '</li>';
! 6562: }
! 6563: }
! 6564: if (ref($changes{'textbooks'}) eq 'HASH') {
! 6565: $resulttext .= '<li>'.&mt('Available textbooks updated').'<ul>';
! 6566: foreach my $key (sort(keys(%{$changes{'textbooks'}}))) {
! 6567: my %coursehash = &Apache::lonnet::coursedescription($key);
! 6568: my $coursetitle = $coursehash{'description'};
! 6569: my $position = $confhash{'textbooks'}{$key}{'order'} + 1;
! 6570: $resulttext .= '<li>';
! 6571: foreach my $item ('subject','title','author') {
! 6572: my $name = $item.':';
! 6573: $name =~ s/^(\w)/\U$1/;
! 6574: $resulttext .= &mt($name).' '.$confhash{'textbooks'}{$key}{$item}.'<br />';
! 6575: }
! 6576: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
! 6577: if ($confhash{'textbooks'}{$key}{'image'}) {
! 6578: $resulttext .= ' '.&mt('Image: [_1]',
! 6579: '<img src="'.$confhash{'textbooks'}{$key}{'image'}.'"'.
! 6580: ' alt="Textbook cover" />').'<br />';
! 6581: }
! 6582: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
! 6583: }
! 6584: $resulttext .= '</ul></li>';
! 6585: }
! 6586: }
1.1 raeburn 6587: $resulttext .= '</ul>';
1.80 raeburn 6588: if (keys(%newenv)) {
6589: &Apache::lonnet::appenv(\%newenv);
6590: }
1.1 raeburn 6591: } else {
1.86 raeburn 6592: if ($context eq 'requestcourses') {
6593: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 6594: } elsif ($context eq 'requestauthor') {
6595: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 6596: } else {
1.90 weissno 6597: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 6598: }
1.1 raeburn 6599: }
6600: } else {
1.11 albertel 6601: $resulttext = '<span class="LC_error">'.
6602: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6603: }
1.160.6.30! raeburn 6604: if ($errors) {
! 6605: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
! 6606: '<ul>'.$errors.'</ul></p>';
! 6607: }
1.3 raeburn 6608: return $resulttext;
1.1 raeburn 6609: }
6610:
1.160.6.30! raeburn 6611: sub process_textbook_image {
! 6612: my ($r,$dom,$confname,$caller,$cdom,$cnum,$configuserok,$switchserver,$author_ok) = @_;
! 6613: my $filename = $env{'form.'.$caller.'.filename'};
! 6614: my ($error,$url);
! 6615: my ($width,$height) = (50,50);
! 6616: if ($configuserok eq 'ok') {
! 6617: if ($switchserver) {
! 6618: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
! 6619: $switchserver);
! 6620: } elsif ($author_ok eq 'ok') {
! 6621: my ($result,$imageurl) =
! 6622: &publishlogo($r,'upload',$caller,$dom,$confname,
! 6623: "textbooks/$dom/$cnum/cover",$width,$height);
! 6624: if ($result eq 'ok') {
! 6625: $url = $imageurl;
! 6626: } else {
! 6627: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
! 6628: }
! 6629: } else {
! 6630: $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].",$filename,$confname,$dom,$author_ok);
! 6631: }
! 6632: } else {
! 6633: $error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$filename,$confname,$dom,$configuserok);
! 6634: }
! 6635: return ($url,$error);
! 6636: }
! 6637:
1.3 raeburn 6638: sub modify_autoenroll {
1.160.6.24 raeburn 6639: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 6640: my ($resulttext,%changes);
6641: my %currautoenroll;
6642: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6643: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
6644: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
6645: }
6646: }
6647: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
6648: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 6649: sender => 'Sender for notification messages',
6650: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 6651: my @offon = ('off','on');
1.17 raeburn 6652: my $sender_uname = $env{'form.sender_uname'};
6653: my $sender_domain = $env{'form.sender_domain'};
6654: if ($sender_domain eq '') {
6655: $sender_uname = '';
6656: } elsif ($sender_uname eq '') {
6657: $sender_domain = '';
6658: }
1.129 raeburn 6659: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 6660: my %autoenrollhash = (
1.129 raeburn 6661: autoenroll => { 'run' => $env{'form.autoenroll_run'},
6662: 'sender_uname' => $sender_uname,
6663: 'sender_domain' => $sender_domain,
6664: 'co-owners' => $coowners,
1.1 raeburn 6665: }
6666: );
1.4 raeburn 6667: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
6668: $dom);
1.1 raeburn 6669: if ($putresult eq 'ok') {
6670: if (exists($currautoenroll{'run'})) {
6671: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
6672: $changes{'run'} = 1;
6673: }
6674: } elsif ($autorun) {
6675: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 6676: $changes{'run'} = 1;
1.1 raeburn 6677: }
6678: }
1.17 raeburn 6679: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 6680: $changes{'sender'} = 1;
6681: }
1.17 raeburn 6682: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 6683: $changes{'sender'} = 1;
6684: }
1.129 raeburn 6685: if ($currautoenroll{'co-owners'} ne '') {
6686: if ($currautoenroll{'co-owners'} ne $coowners) {
6687: $changes{'coowners'} = 1;
6688: }
6689: } elsif ($coowners) {
6690: $changes{'coowners'} = 1;
6691: }
1.1 raeburn 6692: if (keys(%changes) > 0) {
6693: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 6694: if ($changes{'run'}) {
1.1 raeburn 6695: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
6696: }
6697: if ($changes{'sender'}) {
1.17 raeburn 6698: if ($sender_uname eq '' || $sender_domain eq '') {
6699: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
6700: } else {
6701: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
6702: }
1.1 raeburn 6703: }
1.129 raeburn 6704: if ($changes{'coowners'}) {
6705: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
6706: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 6707: if (ref($lastactref) eq 'HASH') {
6708: $lastactref->{'domainconfig'} = 1;
6709: }
1.129 raeburn 6710: }
1.1 raeburn 6711: $resulttext .= '</ul>';
6712: } else {
6713: $resulttext = &mt('No changes made to auto-enrollment settings');
6714: }
6715: } else {
1.11 albertel 6716: $resulttext = '<span class="LC_error">'.
6717: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6718: }
1.3 raeburn 6719: return $resulttext;
1.1 raeburn 6720: }
6721:
6722: sub modify_autoupdate {
1.3 raeburn 6723: my ($dom,%domconfig) = @_;
1.1 raeburn 6724: my ($resulttext,%currautoupdate,%fields,%changes);
6725: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
6726: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
6727: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
6728: }
6729: }
6730: my @offon = ('off','on');
6731: my %title = &Apache::lonlocal::texthash (
6732: run => 'Auto-update:',
6733: classlists => 'Updates to user information in classlists?'
6734: );
1.44 raeburn 6735: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6736: my %fieldtitles = &Apache::lonlocal::texthash (
6737: id => 'Student/Employee ID',
1.20 raeburn 6738: permanentemail => 'E-mail address',
1.1 raeburn 6739: lastname => 'Last Name',
6740: firstname => 'First Name',
6741: middlename => 'Middle Name',
1.132 raeburn 6742: generation => 'Generation',
1.1 raeburn 6743: );
1.142 raeburn 6744: $othertitle = &mt('All users');
1.1 raeburn 6745: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 6746: $othertitle = &mt('Other users');
1.1 raeburn 6747: }
6748: foreach my $key (keys(%env)) {
6749: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 6750: my ($usertype,$item) = ($1,$2);
6751: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
6752: if ($usertype eq 'default') {
6753: push(@{$fields{$1}},$2);
6754: } elsif (ref($types) eq 'ARRAY') {
6755: if (grep(/^\Q$usertype\E$/,@{$types})) {
6756: push(@{$fields{$1}},$2);
6757: }
6758: }
6759: }
1.1 raeburn 6760: }
6761: }
1.131 raeburn 6762: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
6763: @lockablenames = sort(@lockablenames);
6764: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
6765: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6766: if (@changed) {
6767: $changes{'lockablenames'} = 1;
6768: }
6769: } else {
6770: if (@lockablenames) {
6771: $changes{'lockablenames'} = 1;
6772: }
6773: }
1.1 raeburn 6774: my %updatehash = (
6775: autoupdate => { run => $env{'form.autoupdate_run'},
6776: classlists => $env{'form.classlists'},
6777: fields => {%fields},
1.131 raeburn 6778: lockablenames => \@lockablenames,
1.1 raeburn 6779: }
6780: );
6781: foreach my $key (keys(%currautoupdate)) {
6782: if (($key eq 'run') || ($key eq 'classlists')) {
6783: if (exists($updatehash{autoupdate}{$key})) {
6784: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
6785: $changes{$key} = 1;
6786: }
6787: }
6788: } elsif ($key eq 'fields') {
6789: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 6790: foreach my $item (@{$types},'default') {
1.1 raeburn 6791: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
6792: my $change = 0;
6793: foreach my $type (@{$currautoupdate{$key}{$item}}) {
6794: if (!exists($fields{$item})) {
6795: $change = 1;
1.132 raeburn 6796: last;
1.1 raeburn 6797: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 6798: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 6799: $change = 1;
1.132 raeburn 6800: last;
1.1 raeburn 6801: }
6802: }
6803: }
6804: if ($change) {
6805: push(@{$changes{$key}},$item);
6806: }
1.26 raeburn 6807: }
1.1 raeburn 6808: }
6809: }
1.131 raeburn 6810: } elsif ($key eq 'lockablenames') {
6811: if (ref($currautoupdate{$key}) eq 'ARRAY') {
6812: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6813: if (@changed) {
6814: $changes{'lockablenames'} = 1;
6815: }
6816: } else {
6817: if (@lockablenames) {
6818: $changes{'lockablenames'} = 1;
6819: }
6820: }
6821: }
6822: }
6823: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
6824: if (@lockablenames) {
6825: $changes{'lockablenames'} = 1;
1.1 raeburn 6826: }
6827: }
1.26 raeburn 6828: foreach my $item (@{$types},'default') {
6829: if (defined($fields{$item})) {
6830: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 6831: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
6832: my $change = 0;
6833: if (ref($fields{$item}) eq 'ARRAY') {
6834: foreach my $type (@{$fields{$item}}) {
6835: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
6836: $change = 1;
6837: last;
6838: }
6839: }
6840: }
6841: if ($change) {
6842: push(@{$changes{'fields'}},$item);
6843: }
6844: } else {
1.26 raeburn 6845: push(@{$changes{'fields'}},$item);
6846: }
6847: } else {
6848: push(@{$changes{'fields'}},$item);
1.1 raeburn 6849: }
6850: }
6851: }
6852: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
6853: $dom);
6854: if ($putresult eq 'ok') {
6855: if (keys(%changes) > 0) {
6856: $resulttext = &mt('Changes made:').'<ul>';
6857: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 6858: if ($key eq 'lockablenames') {
6859: $resulttext .= '<li>';
6860: if (@lockablenames) {
6861: $usertypes->{'default'} = $othertitle;
6862: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
6863: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
6864: } else {
6865: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
6866: }
6867: $resulttext .= '</li>';
6868: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 6869: foreach my $item (@{$changes{$key}}) {
6870: my @newvalues;
6871: foreach my $type (@{$fields{$item}}) {
6872: push(@newvalues,$fieldtitles{$type});
6873: }
1.3 raeburn 6874: my $newvaluestr;
6875: if (@newvalues > 0) {
6876: $newvaluestr = join(', ',@newvalues);
6877: } else {
6878: $newvaluestr = &mt('none');
1.6 raeburn 6879: }
1.1 raeburn 6880: if ($item eq 'default') {
1.26 raeburn 6881: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 6882: } else {
1.26 raeburn 6883: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 6884: }
6885: }
6886: } else {
6887: my $newvalue;
6888: if ($key eq 'run') {
6889: $newvalue = $offon[$env{'form.autoupdate_run'}];
6890: } else {
6891: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 6892: }
1.1 raeburn 6893: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
6894: }
6895: }
6896: $resulttext .= '</ul>';
6897: } else {
1.3 raeburn 6898: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 6899: }
6900: } else {
1.11 albertel 6901: $resulttext = '<span class="LC_error">'.
6902: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6903: }
1.3 raeburn 6904: return $resulttext;
1.1 raeburn 6905: }
6906:
1.125 raeburn 6907: sub modify_autocreate {
6908: my ($dom,%domconfig) = @_;
6909: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
6910: if (ref($domconfig{'autocreate'}) eq 'HASH') {
6911: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
6912: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
6913: }
6914: }
6915: my %title= ( xml => 'Auto-creation of courses in XML course description files',
6916: req => 'Auto-creation of validated requests for official courses',
6917: xmldc => 'Identity of course creator of courses from XML files',
6918: );
6919: my @types = ('xml','req');
6920: foreach my $item (@types) {
6921: $newvals{$item} = $env{'form.autocreate_'.$item};
6922: $newvals{$item} =~ s/\D//g;
6923: $newvals{$item} = 0 if ($newvals{$item} eq '');
6924: }
6925: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
6926: my %domcoords = &get_active_dcs($dom);
6927: unless (exists($domcoords{$newvals{'xmldc'}})) {
6928: $newvals{'xmldc'} = '';
6929: }
6930: %autocreatehash = (
6931: autocreate => { xml => $newvals{'xml'},
6932: req => $newvals{'req'},
6933: }
6934: );
6935: if ($newvals{'xmldc'} ne '') {
6936: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
6937: }
6938: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
6939: $dom);
6940: if ($putresult eq 'ok') {
6941: my @items = @types;
6942: if ($newvals{'xml'}) {
6943: push(@items,'xmldc');
6944: }
6945: foreach my $item (@items) {
6946: if (exists($currautocreate{$item})) {
6947: if ($currautocreate{$item} ne $newvals{$item}) {
6948: $changes{$item} = 1;
6949: }
6950: } elsif ($newvals{$item}) {
6951: $changes{$item} = 1;
6952: }
6953: }
6954: if (keys(%changes) > 0) {
6955: my @offon = ('off','on');
6956: $resulttext = &mt('Changes made:').'<ul>';
6957: foreach my $item (@types) {
6958: if ($changes{$item}) {
6959: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 6960: $resulttext .= '<li>'.
6961: &mt("$title{$item} set to [_1]$newtxt [_2]",
6962: '<b>','</b>').
6963: '</li>';
1.125 raeburn 6964: }
6965: }
6966: if ($changes{'xmldc'}) {
6967: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
6968: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 6969: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 6970: }
6971: $resulttext .= '</ul>';
6972: } else {
6973: $resulttext = &mt('No changes made to auto-creation settings');
6974: }
6975: } else {
6976: $resulttext = '<span class="LC_error">'.
6977: &mt('An error occurred: [_1]',$putresult).'</span>';
6978: }
6979: return $resulttext;
6980: }
6981:
1.23 raeburn 6982: sub modify_directorysrch {
6983: my ($dom,%domconfig) = @_;
6984: my ($resulttext,%changes);
6985: my %currdirsrch;
6986: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
6987: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
6988: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
6989: }
6990: }
6991: my %title = ( available => 'Directory search available',
1.24 raeburn 6992: localonly => 'Other domains can search',
1.23 raeburn 6993: searchby => 'Search types',
6994: searchtypes => 'Search latitude');
6995: my @offon = ('off','on');
1.24 raeburn 6996: my @otherdoms = ('Yes','No');
1.23 raeburn 6997:
1.25 raeburn 6998: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 6999: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
7000: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
7001:
1.44 raeburn 7002: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 7003: if (keys(%{$usertypes}) == 0) {
7004: @cansearch = ('default');
7005: } else {
7006: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
7007: foreach my $type (@{$currdirsrch{'cansearch'}}) {
7008: if (!grep(/^\Q$type\E$/,@cansearch)) {
7009: push(@{$changes{'cansearch'}},$type);
7010: }
1.23 raeburn 7011: }
1.26 raeburn 7012: foreach my $type (@cansearch) {
7013: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
7014: push(@{$changes{'cansearch'}},$type);
7015: }
1.23 raeburn 7016: }
1.26 raeburn 7017: } else {
7018: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 7019: }
7020: }
7021:
7022: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
7023: foreach my $by (@{$currdirsrch{'searchby'}}) {
7024: if (!grep(/^\Q$by\E$/,@searchby)) {
7025: push(@{$changes{'searchby'}},$by);
7026: }
7027: }
7028: foreach my $by (@searchby) {
7029: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
7030: push(@{$changes{'searchby'}},$by);
7031: }
7032: }
7033: } else {
7034: push(@{$changes{'searchby'}},@searchby);
7035: }
1.25 raeburn 7036:
7037: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
7038: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
7039: if (!grep(/^\Q$type\E$/,@searchtypes)) {
7040: push(@{$changes{'searchtypes'}},$type);
7041: }
7042: }
7043: foreach my $type (@searchtypes) {
7044: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
7045: push(@{$changes{'searchtypes'}},$type);
7046: }
7047: }
7048: } else {
7049: if (exists($currdirsrch{'searchtypes'})) {
7050: foreach my $type (@searchtypes) {
7051: if ($type ne $currdirsrch{'searchtypes'}) {
7052: push(@{$changes{'searchtypes'}},$type);
7053: }
7054: }
7055: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
7056: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
7057: }
7058: } else {
7059: push(@{$changes{'searchtypes'}},@searchtypes);
7060: }
7061: }
7062:
1.23 raeburn 7063: my %dirsrch_hash = (
7064: directorysrch => { available => $env{'form.dirsrch_available'},
7065: cansearch => \@cansearch,
1.24 raeburn 7066: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 7067: searchby => \@searchby,
1.25 raeburn 7068: searchtypes => \@searchtypes,
1.23 raeburn 7069: }
7070: );
7071: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
7072: $dom);
7073: if ($putresult eq 'ok') {
7074: if (exists($currdirsrch{'available'})) {
7075: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
7076: $changes{'available'} = 1;
7077: }
7078: } else {
7079: if ($env{'form.dirsrch_available'} eq '1') {
7080: $changes{'available'} = 1;
7081: }
7082: }
1.24 raeburn 7083: if (exists($currdirsrch{'localonly'})) {
7084: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
7085: $changes{'localonly'} = 1;
7086: }
7087: } else {
7088: if ($env{'form.dirsrch_localonly'} eq '1') {
7089: $changes{'localonly'} = 1;
7090: }
7091: }
1.23 raeburn 7092: if (keys(%changes) > 0) {
7093: $resulttext = &mt('Changes made:').'<ul>';
7094: if ($changes{'available'}) {
7095: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
7096: }
1.24 raeburn 7097: if ($changes{'localonly'}) {
7098: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
7099: }
7100:
1.23 raeburn 7101: if (ref($changes{'cansearch'}) eq 'ARRAY') {
7102: my $chgtext;
1.26 raeburn 7103: if (ref($usertypes) eq 'HASH') {
7104: if (keys(%{$usertypes}) > 0) {
7105: foreach my $type (@{$types}) {
7106: if (grep(/^\Q$type\E$/,@cansearch)) {
7107: $chgtext .= $usertypes->{$type}.'; ';
7108: }
7109: }
7110: if (grep(/^default$/,@cansearch)) {
7111: $chgtext .= $othertitle;
7112: } else {
7113: $chgtext =~ s/\; $//;
7114: }
1.160.6.13 raeburn 7115: $resulttext .=
7116: '<li>'.
7117: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
7118: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
7119: '</li>';
1.23 raeburn 7120: }
7121: }
7122: }
7123: if (ref($changes{'searchby'}) eq 'ARRAY') {
7124: my ($searchtitles,$titleorder) = &sorted_searchtitles();
7125: my $chgtext;
7126: foreach my $type (@{$titleorder}) {
7127: if (grep(/^\Q$type\E$/,@searchby)) {
7128: if (defined($searchtitles->{$type})) {
7129: $chgtext .= $searchtitles->{$type}.'; ';
7130: }
7131: }
7132: }
7133: $chgtext =~ s/\; $//;
7134: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
7135: }
1.25 raeburn 7136: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
7137: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
7138: my $chgtext;
7139: foreach my $type (@{$srchtypeorder}) {
7140: if (grep(/^\Q$type\E$/,@searchtypes)) {
7141: if (defined($srchtypes_desc->{$type})) {
7142: $chgtext .= $srchtypes_desc->{$type}.'; ';
7143: }
7144: }
7145: }
7146: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 7147: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 7148: }
7149: $resulttext .= '</ul>';
7150: } else {
7151: $resulttext = &mt('No changes made to institution directory search settings');
7152: }
7153: } else {
7154: $resulttext = '<span class="LC_error">'.
1.27 raeburn 7155: &mt('An error occurred: [_1]',$putresult).'</span>';
7156: }
7157: return $resulttext;
7158: }
7159:
1.28 raeburn 7160: sub modify_contacts {
1.160.6.24 raeburn 7161: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 7162: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
7163: if (ref($domconfig{'contacts'}) eq 'HASH') {
7164: foreach my $key (keys(%{$domconfig{'contacts'}})) {
7165: $currsetting{$key} = $domconfig{'contacts'}{$key};
7166: }
7167: }
1.134 raeburn 7168: my (%others,%to,%bcc);
1.28 raeburn 7169: my @contacts = ('supportemail','adminemail');
1.102 raeburn 7170: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.160.6.23 raeburn 7171: 'requestsmail','updatesmail','idconflictsmail');
7172: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 7173: foreach my $type (@mailings) {
7174: @{$newsetting{$type}} =
7175: &Apache::loncommon::get_env_multiple('form.'.$type);
7176: foreach my $item (@contacts) {
7177: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
7178: $contacts_hash{contacts}{$type}{$item} = 1;
7179: } else {
7180: $contacts_hash{contacts}{$type}{$item} = 0;
7181: }
7182: }
7183: $others{$type} = $env{'form.'.$type.'_others'};
7184: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 7185: if ($type eq 'helpdeskmail') {
7186: $bcc{$type} = $env{'form.'.$type.'_bcc'};
7187: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
7188: }
1.28 raeburn 7189: }
7190: foreach my $item (@contacts) {
7191: $to{$item} = $env{'form.'.$item};
7192: $contacts_hash{'contacts'}{$item} = $to{$item};
7193: }
1.160.6.23 raeburn 7194: foreach my $item (@toggles) {
7195: if ($env{'form.'.$item} =~ /^(0|1)$/) {
7196: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
7197: }
7198: }
1.28 raeburn 7199: if (keys(%currsetting) > 0) {
7200: foreach my $item (@contacts) {
7201: if ($to{$item} ne $currsetting{$item}) {
7202: $changes{$item} = 1;
7203: }
7204: }
7205: foreach my $type (@mailings) {
7206: foreach my $item (@contacts) {
7207: if (ref($currsetting{$type}) eq 'HASH') {
7208: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
7209: push(@{$changes{$type}},$item);
7210: }
7211: } else {
7212: push(@{$changes{$type}},@{$newsetting{$type}});
7213: }
7214: }
7215: if ($others{$type} ne $currsetting{$type}{'others'}) {
7216: push(@{$changes{$type}},'others');
7217: }
1.134 raeburn 7218: if ($type eq 'helpdeskmail') {
7219: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
7220: push(@{$changes{$type}},'bcc');
7221: }
7222: }
1.28 raeburn 7223: }
7224: } else {
7225: my %default;
7226: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
7227: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
7228: $default{'errormail'} = 'adminemail';
7229: $default{'packagesmail'} = 'adminemail';
7230: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 7231: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 7232: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 7233: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 7234: foreach my $item (@contacts) {
7235: if ($to{$item} ne $default{$item}) {
7236: $changes{$item} = 1;
1.160.6.23 raeburn 7237: }
1.28 raeburn 7238: }
7239: foreach my $type (@mailings) {
7240: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
7241:
7242: push(@{$changes{$type}},@{$newsetting{$type}});
7243: }
7244: if ($others{$type} ne '') {
7245: push(@{$changes{$type}},'others');
1.134 raeburn 7246: }
7247: if ($type eq 'helpdeskmail') {
7248: if ($bcc{$type} ne '') {
7249: push(@{$changes{$type}},'bcc');
7250: }
7251: }
1.28 raeburn 7252: }
7253: }
1.160.6.23 raeburn 7254: foreach my $item (@toggles) {
7255: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
7256: $changes{$item} = 1;
7257: } elsif ((!$env{'form.'.$item}) &&
7258: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
7259: $changes{$item} = 1;
7260: }
7261: }
1.28 raeburn 7262: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
7263: $dom);
7264: if ($putresult eq 'ok') {
7265: if (keys(%changes) > 0) {
1.160.6.24 raeburn 7266: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7267: if (ref($lastactref) eq 'HASH') {
7268: $lastactref->{'domainconfig'} = 1;
7269: }
1.28 raeburn 7270: my ($titles,$short_titles) = &contact_titles();
7271: $resulttext = &mt('Changes made:').'<ul>';
7272: foreach my $item (@contacts) {
7273: if ($changes{$item}) {
7274: $resulttext .= '<li>'.$titles->{$item}.
7275: &mt(' set to: ').
7276: '<span class="LC_cusr_emph">'.
7277: $to{$item}.'</span></li>';
7278: }
7279: }
7280: foreach my $type (@mailings) {
7281: if (ref($changes{$type}) eq 'ARRAY') {
7282: $resulttext .= '<li>'.$titles->{$type}.': ';
7283: my @text;
7284: foreach my $item (@{$newsetting{$type}}) {
7285: push(@text,$short_titles->{$item});
7286: }
7287: if ($others{$type} ne '') {
7288: push(@text,$others{$type});
7289: }
7290: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 7291: join(', ',@text).'</span>';
7292: if ($type eq 'helpdeskmail') {
7293: if ($bcc{$type} ne '') {
7294: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
7295: }
7296: }
7297: $resulttext .= '</li>';
1.28 raeburn 7298: }
7299: }
1.160.6.23 raeburn 7300: my @offon = ('off','on');
7301: if ($changes{'reporterrors'}) {
7302: $resulttext .= '<li>'.
7303: &mt('E-mail error reports to [_1] set to "'.
7304: $offon[$env{'form.reporterrors'}].'".',
7305: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
7306: &mt('LON-CAPA core group - MSU'),600,500)).
7307: '</li>';
7308: }
7309: if ($changes{'reportupdates'}) {
7310: $resulttext .= '<li>'.
7311: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
7312: $offon[$env{'form.reportupdates'}].'".',
7313: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
7314: &mt('LON-CAPA core group - MSU'),600,500)).
7315: '</li>';
7316: }
1.28 raeburn 7317: $resulttext .= '</ul>';
7318: } else {
1.34 raeburn 7319: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 7320: }
7321: } else {
7322: $resulttext = '<span class="LC_error">'.
7323: &mt('An error occurred: [_1].',$putresult).'</span>';
7324: }
7325: return $resulttext;
7326: }
7327:
7328: sub modify_usercreation {
1.27 raeburn 7329: my ($dom,%domconfig) = @_;
1.34 raeburn 7330: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 7331: my $warningmsg;
1.27 raeburn 7332: if (ref($domconfig{'usercreation'}) eq 'HASH') {
7333: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
7334: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
7335: }
7336: }
7337: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 7338: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 7339: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 7340: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 7341: foreach my $item(@contexts) {
1.45 raeburn 7342: if ($item eq 'selfcreate') {
1.50 raeburn 7343: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.160.6.27 raeburn 7344: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.43 raeburn 7345: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 7346: if (ref($cancreate{$item}) eq 'ARRAY') {
7347: if (grep(/^login$/,@{$cancreate{$item}})) {
7348: $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.');
7349: }
1.43 raeburn 7350: }
7351: }
1.50 raeburn 7352: } else {
7353: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 7354: }
1.34 raeburn 7355: }
1.93 raeburn 7356: my ($othertitle,$usertypes,$types) =
7357: &Apache::loncommon::sorted_inst_types($dom);
7358: if (ref($types) eq 'ARRAY') {
7359: if (@{$types} > 0) {
7360: @{$cancreate{'statustocreate'}} =
7361: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 raeburn 7362: } else {
7363: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 7364: }
7365: push(@contexts,'statustocreate');
7366: }
1.160.6.5 raeburn 7367: &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
1.34 raeburn 7368: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
7369: foreach my $item (@contexts) {
1.93 raeburn 7370: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
7371: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 7372: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 raeburn 7373: if (ref($cancreate{$item}) eq 'ARRAY') {
7374: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
7375: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7376: push(@{$changes{'cancreate'}},$item);
7377: }
1.50 raeburn 7378: }
7379: }
7380: }
7381: } else {
7382: if ($curr_usercreation{'cancreate'}{$item} eq '') {
7383: if (@{$cancreate{$item}} > 0) {
7384: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7385: push(@{$changes{'cancreate'}},$item);
7386: }
7387: }
7388: } else {
7389: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
7390: if (@{$cancreate{$item}} < 3) {
7391: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7392: push(@{$changes{'cancreate'}},$item);
7393: }
7394: }
7395: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
7396: if (@{$cancreate{$item}} > 0) {
7397: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7398: push(@{$changes{'cancreate'}},$item);
7399: }
7400: }
7401: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
7402: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7403: push(@{$changes{'cancreate'}},$item);
7404: }
7405: }
7406: }
7407: }
7408: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7409: foreach my $type (@{$cancreate{$item}}) {
7410: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
7411: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
7412: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7413: push(@{$changes{'cancreate'}},$item);
7414: }
7415: }
7416: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
7417: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
7418: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
7419: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7420: push(@{$changes{'cancreate'}},$item);
7421: }
7422: }
7423: }
7424: }
7425: }
7426: } else {
7427: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
7428: push(@{$changes{'cancreate'}},$item);
7429: }
7430: }
1.27 raeburn 7431: }
1.34 raeburn 7432: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
7433: foreach my $item (@contexts) {
1.43 raeburn 7434: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 7435: if ($cancreate{$item} ne 'any') {
7436: push(@{$changes{'cancreate'}},$item);
7437: }
7438: } else {
7439: if ($cancreate{$item} ne 'none') {
7440: push(@{$changes{'cancreate'}},$item);
7441: }
1.27 raeburn 7442: }
7443: }
7444: } else {
1.43 raeburn 7445: foreach my $item (@contexts) {
1.34 raeburn 7446: push(@{$changes{'cancreate'}},$item);
7447: }
1.27 raeburn 7448: }
1.34 raeburn 7449:
1.27 raeburn 7450: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
7451: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
7452: if (!grep(/^\Q$type\E$/,@username_rule)) {
7453: push(@{$changes{'username_rule'}},$type);
7454: }
7455: }
7456: foreach my $type (@username_rule) {
7457: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
7458: push(@{$changes{'username_rule'}},$type);
7459: }
7460: }
7461: } else {
7462: push(@{$changes{'username_rule'}},@username_rule);
7463: }
7464:
1.32 raeburn 7465: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
7466: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
7467: if (!grep(/^\Q$type\E$/,@id_rule)) {
7468: push(@{$changes{'id_rule'}},$type);
7469: }
7470: }
7471: foreach my $type (@id_rule) {
7472: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
7473: push(@{$changes{'id_rule'}},$type);
7474: }
7475: }
7476: } else {
7477: push(@{$changes{'id_rule'}},@id_rule);
7478: }
7479:
1.43 raeburn 7480: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
7481: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
7482: if (!grep(/^\Q$type\E$/,@email_rule)) {
7483: push(@{$changes{'email_rule'}},$type);
7484: }
7485: }
7486: foreach my $type (@email_rule) {
7487: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
7488: push(@{$changes{'email_rule'}},$type);
7489: }
7490: }
7491: } else {
7492: push(@{$changes{'email_rule'}},@email_rule);
7493: }
7494:
7495: my @authen_contexts = ('author','course','domain');
1.28 raeburn 7496: my @authtypes = ('int','krb4','krb5','loc');
7497: my %authhash;
1.43 raeburn 7498: foreach my $item (@authen_contexts) {
1.28 raeburn 7499: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
7500: foreach my $auth (@authtypes) {
7501: if (grep(/^\Q$auth\E$/,@authallowed)) {
7502: $authhash{$item}{$auth} = 1;
7503: } else {
7504: $authhash{$item}{$auth} = 0;
7505: }
7506: }
7507: }
7508: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 7509: foreach my $item (@authen_contexts) {
1.28 raeburn 7510: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
7511: foreach my $auth (@authtypes) {
7512: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
7513: push(@{$changes{'authtypes'}},$item);
7514: last;
7515: }
7516: }
7517: }
7518: }
7519: } else {
1.43 raeburn 7520: foreach my $item (@authen_contexts) {
1.28 raeburn 7521: push(@{$changes{'authtypes'}},$item);
7522: }
7523: }
7524:
1.27 raeburn 7525: my %usercreation_hash = (
1.28 raeburn 7526: usercreation => {
1.34 raeburn 7527: cancreate => \%cancreate,
1.27 raeburn 7528: username_rule => \@username_rule,
1.32 raeburn 7529: id_rule => \@id_rule,
1.43 raeburn 7530: email_rule => \@email_rule,
1.32 raeburn 7531: authtypes => \%authhash,
1.27 raeburn 7532: }
7533: );
7534:
7535: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
7536: $dom);
1.50 raeburn 7537:
7538: my %selfcreatetypes = (
7539: sso => 'users authenticated by institutional single sign on',
7540: login => 'users authenticated by institutional log-in',
7541: email => 'users who provide a valid e-mail address for use as the username',
7542: );
1.27 raeburn 7543: if ($putresult eq 'ok') {
7544: if (keys(%changes) > 0) {
7545: $resulttext = &mt('Changes made:').'<ul>';
7546: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 7547: my %lt = &usercreation_types();
7548: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 7549: my $chgtext;
1.160.6.5 raeburn 7550: unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
1.100 raeburn 7551: $chgtext = $lt{$type}.', ';
7552: }
1.45 raeburn 7553: if ($type eq 'selfcreate') {
1.50 raeburn 7554: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 7555: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 7556: } else {
1.100 raeburn 7557: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 7558: foreach my $case (@{$cancreate{$type}}) {
7559: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
7560: }
7561: $chgtext .= '</ul>';
1.100 raeburn 7562: if (ref($cancreate{$type}) eq 'ARRAY') {
7563: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
7564: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
7565: if (@{$cancreate{'statustocreate'}} == 0) {
7566: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
7567: }
7568: }
7569: }
7570: }
1.43 raeburn 7571: }
1.93 raeburn 7572: } elsif ($type eq 'statustocreate') {
1.96 raeburn 7573: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
7574: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
7575: if (@{$cancreate{'selfcreate'}} > 0) {
7576: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 7577:
7578: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 7579: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 7580: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
7581: }
1.96 raeburn 7582: } elsif (ref($usertypes) eq 'HASH') {
7583: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 7584: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
7585: } else {
7586: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
7587: }
7588: $chgtext .= '<ul>';
7589: foreach my $case (@{$cancreate{$type}}) {
7590: if ($case eq 'default') {
7591: $chgtext .= '<li>'.$othertitle.'</li>';
7592: } else {
7593: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 7594: }
7595: }
1.100 raeburn 7596: $chgtext .= '</ul>';
7597: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
7598: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
7599: }
7600: }
7601: } else {
7602: if (@{$cancreate{$type}} == 0) {
7603: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
7604: } else {
7605: $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 7606: }
7607: }
7608: }
1.160.6.5 raeburn 7609: } elsif ($type eq 'captcha') {
7610: if ($cancreate{$type} eq 'notused') {
7611: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
7612: } else {
7613: my %captchas = &captcha_phrases();
7614: if ($captchas{$cancreate{$type}}) {
7615: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
7616: } else {
7617: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
7618: }
7619: }
7620: } elsif ($type eq 'recaptchakeys') {
7621: my ($privkey,$pubkey);
7622: if (ref($cancreate{$type}) eq 'HASH') {
7623: $pubkey = $cancreate{$type}{'public'};
7624: $privkey = $cancreate{$type}{'private'};
7625: }
7626: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
7627: if (!$pubkey) {
7628: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
7629: } else {
7630: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7631: }
7632: if (!$privkey) {
7633: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
7634: } else {
7635: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
7636: }
7637: $chgtext .= '</ul>';
1.43 raeburn 7638: } else {
7639: if ($cancreate{$type} eq 'none') {
7640: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
7641: } elsif ($cancreate{$type} eq 'any') {
7642: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
7643: } elsif ($cancreate{$type} eq 'official') {
7644: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
7645: } elsif ($cancreate{$type} eq 'unofficial') {
7646: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
7647: }
1.34 raeburn 7648: }
7649: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 7650: }
7651: }
7652: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 7653: my ($rules,$ruleorder) =
7654: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 7655: my $chgtext = '<ul>';
7656: foreach my $type (@username_rule) {
7657: if (ref($rules->{$type}) eq 'HASH') {
7658: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
7659: }
7660: }
7661: $chgtext .= '</ul>';
7662: if (@username_rule > 0) {
7663: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7664: } else {
1.28 raeburn 7665: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 7666: }
7667: }
1.32 raeburn 7668: if (ref($changes{'id_rule'}) eq 'ARRAY') {
7669: my ($idrules,$idruleorder) =
7670: &Apache::lonnet::inst_userrules($dom,'id');
7671: my $chgtext = '<ul>';
7672: foreach my $type (@id_rule) {
7673: if (ref($idrules->{$type}) eq 'HASH') {
7674: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
7675: }
7676: }
7677: $chgtext .= '</ul>';
7678: if (@id_rule > 0) {
7679: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7680: } else {
7681: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
7682: }
7683: }
1.43 raeburn 7684: if (ref($changes{'email_rule'}) eq 'ARRAY') {
7685: my ($emailrules,$emailruleorder) =
7686: &Apache::lonnet::inst_userrules($dom,'email');
7687: my $chgtext = '<ul>';
7688: foreach my $type (@email_rule) {
7689: if (ref($emailrules->{$type}) eq 'HASH') {
7690: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
7691: }
7692: }
7693: $chgtext .= '</ul>';
7694: if (@email_rule > 0) {
7695: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
7696: } else {
7697: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
7698: }
7699: }
7700:
1.28 raeburn 7701: my %authname = &authtype_names();
7702: my %context_title = &context_names();
7703: if (ref($changes{'authtypes'}) eq 'ARRAY') {
7704: my $chgtext = '<ul>';
7705: foreach my $type (@{$changes{'authtypes'}}) {
7706: my @allowed;
7707: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
7708: foreach my $auth (@authtypes) {
7709: if ($authhash{$type}{$auth}) {
7710: push(@allowed,$authname{$auth});
7711: }
7712: }
1.43 raeburn 7713: if (@allowed > 0) {
7714: $chgtext .= join(', ',@allowed).'</li>';
7715: } else {
7716: $chgtext .= &mt('none').'</li>';
7717: }
1.28 raeburn 7718: }
7719: $chgtext .= '</ul>';
7720: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
7721: $resulttext .= '</li>';
7722: }
1.27 raeburn 7723: $resulttext .= '</ul>';
7724: } else {
1.28 raeburn 7725: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 7726: }
7727: } else {
7728: $resulttext = '<span class="LC_error">'.
1.23 raeburn 7729: &mt('An error occurred: [_1]',$putresult).'</span>';
7730: }
1.43 raeburn 7731: if ($warningmsg ne '') {
7732: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
7733: }
1.23 raeburn 7734: return $resulttext;
7735: }
7736:
1.160.6.5 raeburn 7737: sub process_captcha {
7738: my ($container,$changes,$newsettings,$current) = @_;
7739: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
7740: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
7741: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
7742: $newsettings->{'captcha'} = 'original';
7743: }
7744: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
7745: if ($container eq 'cancreate') {
7746: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7747: push(@{$changes->{'cancreate'}},'captcha');
7748: } elsif (!defined($changes->{'cancreate'})) {
7749: $changes->{'cancreate'} = ['captcha'];
7750: }
7751: } else {
7752: $changes->{'captcha'} = 1;
7753: }
7754: }
7755: my ($newpub,$newpriv,$currpub,$currpriv);
7756: if ($newsettings->{'captcha'} eq 'recaptcha') {
7757: $newpub = $env{'form.'.$container.'_recaptchapub'};
7758: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
7759: $newpub =~ s/\W//g;
7760: $newpriv =~ s/\W//g;
7761: $newsettings->{'recaptchakeys'} = {
7762: public => $newpub,
7763: private => $newpriv,
7764: };
7765: }
7766: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
7767: $currpub = $current->{'recaptchakeys'}{'public'};
7768: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 7769: unless ($newsettings->{'captcha'} eq 'recaptcha') {
7770: $newsettings->{'recaptchakeys'} = {
7771: public => '',
7772: private => '',
7773: }
7774: }
1.160.6.5 raeburn 7775: }
7776: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
7777: if ($container eq 'cancreate') {
7778: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7779: push(@{$changes->{'cancreate'}},'recaptchakeys');
7780: } elsif (!defined($changes->{'cancreate'})) {
7781: $changes->{'cancreate'} = ['recaptchakeys'];
7782: }
7783: } else {
7784: $changes->{'recaptchakeys'} = 1;
7785: }
7786: }
7787: return;
7788: }
7789:
1.33 raeburn 7790: sub modify_usermodification {
7791: my ($dom,%domconfig) = @_;
7792: my ($resulttext,%curr_usermodification,%changes);
7793: if (ref($domconfig{'usermodification'}) eq 'HASH') {
7794: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
7795: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
7796: }
7797: }
1.63 raeburn 7798: my @contexts = ('author','course','selfcreate');
1.33 raeburn 7799: my %context_title = (
7800: author => 'In author context',
7801: course => 'In course context',
1.63 raeburn 7802: selfcreate => 'When self creating account',
1.33 raeburn 7803: );
7804: my @fields = ('lastname','firstname','middlename','generation',
7805: 'permanentemail','id');
7806: my %roles = (
7807: author => ['ca','aa'],
7808: course => ['st','ep','ta','in','cr'],
7809: );
1.63 raeburn 7810: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7811: if (ref($types) eq 'ARRAY') {
7812: push(@{$types},'default');
7813: $usertypes->{'default'} = $othertitle;
7814: }
7815: $roles{'selfcreate'} = $types;
1.33 raeburn 7816: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7817: my %modifyhash;
7818: foreach my $context (@contexts) {
7819: foreach my $role (@{$roles{$context}}) {
7820: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
7821: foreach my $item (@fields) {
7822: if (grep(/^\Q$item\E$/,@modifiable)) {
7823: $modifyhash{$context}{$role}{$item} = 1;
7824: } else {
7825: $modifyhash{$context}{$role}{$item} = 0;
7826: }
7827: }
7828: }
7829: if (ref($curr_usermodification{$context}) eq 'HASH') {
7830: foreach my $role (@{$roles{$context}}) {
7831: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
7832: foreach my $field (@fields) {
7833: if ($modifyhash{$context}{$role}{$field} ne
7834: $curr_usermodification{$context}{$role}{$field}) {
7835: push(@{$changes{$context}},$role);
7836: last;
7837: }
7838: }
7839: }
7840: }
7841: } else {
7842: foreach my $context (@contexts) {
7843: foreach my $role (@{$roles{$context}}) {
7844: push(@{$changes{$context}},$role);
7845: }
7846: }
7847: }
7848: }
7849: my %usermodification_hash = (
7850: usermodification => \%modifyhash,
7851: );
7852: my $putresult = &Apache::lonnet::put_dom('configuration',
7853: \%usermodification_hash,$dom);
7854: if ($putresult eq 'ok') {
7855: if (keys(%changes) > 0) {
7856: $resulttext = &mt('Changes made: ').'<ul>';
7857: foreach my $context (@contexts) {
7858: if (ref($changes{$context}) eq 'ARRAY') {
7859: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
7860: if (ref($changes{$context}) eq 'ARRAY') {
7861: foreach my $role (@{$changes{$context}}) {
7862: my $rolename;
1.63 raeburn 7863: if ($context eq 'selfcreate') {
7864: $rolename = $role;
7865: if (ref($usertypes) eq 'HASH') {
7866: if ($usertypes->{$role} ne '') {
7867: $rolename = $usertypes->{$role};
7868: }
7869: }
1.33 raeburn 7870: } else {
1.63 raeburn 7871: if ($role eq 'cr') {
7872: $rolename = &mt('Custom');
7873: } else {
7874: $rolename = &Apache::lonnet::plaintext($role);
7875: }
1.33 raeburn 7876: }
7877: my @modifiable;
1.63 raeburn 7878: if ($context eq 'selfcreate') {
1.126 bisitz 7879: $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 7880: } else {
7881: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
7882: }
1.33 raeburn 7883: foreach my $field (@fields) {
7884: if ($modifyhash{$context}{$role}{$field}) {
7885: push(@modifiable,$fieldtitles{$field});
7886: }
7887: }
7888: if (@modifiable > 0) {
7889: $resulttext .= join(', ',@modifiable);
7890: } else {
7891: $resulttext .= &mt('none');
7892: }
7893: $resulttext .= '</li>';
7894: }
7895: $resulttext .= '</ul></li>';
7896: }
7897: }
7898: }
7899: $resulttext .= '</ul>';
7900: } else {
7901: $resulttext = &mt('No changes made to user modification settings');
7902: }
7903: } else {
7904: $resulttext = '<span class="LC_error">'.
7905: &mt('An error occurred: [_1]',$putresult).'</span>';
7906: }
7907: return $resulttext;
7908: }
7909:
1.43 raeburn 7910: sub modify_defaults {
1.160.6.27 raeburn 7911: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 7912: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 7913: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 7914: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 7915: my @authtypes = ('internal','krb4','krb5','localauth');
7916: foreach my $item (@items) {
7917: $newvalues{$item} = $env{'form.'.$item};
7918: if ($item eq 'auth_def') {
7919: if ($newvalues{$item} ne '') {
7920: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
7921: push(@errors,$item);
7922: }
7923: }
7924: } elsif ($item eq 'lang_def') {
7925: if ($newvalues{$item} ne '') {
7926: if ($newvalues{$item} =~ /^(\w+)/) {
7927: my $langcode = $1;
1.103 raeburn 7928: if ($langcode ne 'x_chef') {
7929: if (code2language($langcode) eq '') {
7930: push(@errors,$item);
7931: }
1.43 raeburn 7932: }
7933: } else {
7934: push(@errors,$item);
7935: }
7936: }
1.54 raeburn 7937: } elsif ($item eq 'timezone_def') {
7938: if ($newvalues{$item} ne '') {
1.62 raeburn 7939: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 7940: push(@errors,$item);
7941: }
7942: }
1.68 raeburn 7943: } elsif ($item eq 'datelocale_def') {
7944: if ($newvalues{$item} ne '') {
7945: my @datelocale_ids = DateTime::Locale->ids();
7946: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
7947: push(@errors,$item);
7948: }
7949: }
1.141 raeburn 7950: } elsif ($item eq 'portal_def') {
7951: if ($newvalues{$item} ne '') {
7952: 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])\/?$/) {
7953: push(@errors,$item);
7954: }
7955: }
1.43 raeburn 7956: }
7957: if (grep(/^\Q$item\E$/,@errors)) {
7958: $newvalues{$item} = $domdefaults{$item};
7959: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
7960: $changes{$item} = 1;
7961: }
1.72 raeburn 7962: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 7963: }
7964: my %defaults_hash = (
1.72 raeburn 7965: defaults => \%newvalues,
7966: );
1.43 raeburn 7967: my $title = &defaults_titles();
7968: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
7969: $dom);
7970: if ($putresult eq 'ok') {
7971: if (keys(%changes) > 0) {
7972: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 7973: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 7974: 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";
7975: foreach my $item (sort(keys(%changes))) {
7976: my $value = $env{'form.'.$item};
7977: if ($value eq '') {
7978: $value = &mt('none');
7979: } elsif ($item eq 'auth_def') {
7980: my %authnames = &authtype_names();
7981: my %shortauth = (
7982: internal => 'int',
7983: krb4 => 'krb4',
7984: krb5 => 'krb5',
7985: localauth => 'loc',
7986: );
7987: $value = $authnames{$shortauth{$value}};
7988: }
7989: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
7990: $mailmsgtext .= "$title->{$item} set to $value\n";
7991: }
7992: $resulttext .= '</ul>';
7993: $mailmsgtext .= "\n";
7994: my $cachetime = 24*60*60;
1.72 raeburn 7995: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 7996: if (ref($lastactref) eq 'HASH') {
7997: $lastactref->{'domdefaults'} = 1;
7998: }
1.68 raeburn 7999: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 8000: my $notify = 1;
8001: if (ref($domconfig{'contacts'}) eq 'HASH') {
8002: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
8003: $notify = 0;
8004: }
8005: }
8006: if ($notify) {
8007: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
8008: "LON-CAPA Domain Settings Change - $dom",
8009: $mailmsgtext);
8010: }
1.54 raeburn 8011: }
1.43 raeburn 8012: } else {
1.54 raeburn 8013: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 8014: }
8015: } else {
8016: $resulttext = '<span class="LC_error">'.
8017: &mt('An error occurred: [_1]',$putresult).'</span>';
8018: }
8019: if (@errors > 0) {
8020: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
8021: foreach my $item (@errors) {
8022: $resulttext .= ' "'.$title->{$item}.'",';
8023: }
8024: $resulttext =~ s/,$//;
8025: }
8026: return $resulttext;
8027: }
8028:
1.46 raeburn 8029: sub modify_scantron {
1.160.6.24 raeburn 8030: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 8031: my ($resulttext,%confhash,%changes,$errors);
8032: my $custom = 'custom.tab';
8033: my $default = 'default.tab';
8034: my $servadm = $r->dir_config('lonAdmEMail');
8035: my ($configuserok,$author_ok,$switchserver) =
8036: &config_check($dom,$confname,$servadm);
8037: if ($env{'form.scantronformat.filename'} ne '') {
8038: my $error;
8039: if ($configuserok eq 'ok') {
8040: if ($switchserver) {
1.130 raeburn 8041: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 8042: } else {
8043: if ($author_ok eq 'ok') {
8044: my ($result,$scantronurl) =
8045: &publishlogo($r,'upload','scantronformat',$dom,
8046: $confname,'scantron','','',$custom);
8047: if ($result eq 'ok') {
8048: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 8049: $changes{'scantronformat'} = 1;
1.46 raeburn 8050: } else {
8051: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
8052: }
8053: } else {
8054: $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);
8055: }
8056: }
8057: } else {
8058: $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);
8059: }
8060: if ($error) {
8061: &Apache::lonnet::logthis($error);
8062: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8063: }
8064: }
1.48 raeburn 8065: if (ref($domconfig{'scantron'}) eq 'HASH') {
8066: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
8067: if ($env{'form.scantronformat_del'}) {
8068: $confhash{'scantron'}{'scantronformat'} = '';
8069: $changes{'scantronformat'} = 1;
1.46 raeburn 8070: }
8071: }
8072: }
8073: if (keys(%confhash) > 0) {
8074: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
8075: $dom);
8076: if ($putresult eq 'ok') {
8077: if (keys(%changes) > 0) {
1.48 raeburn 8078: if (ref($confhash{'scantron'}) eq 'HASH') {
8079: $resulttext = &mt('Changes made:').'<ul>';
8080: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 8081: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 8082: } else {
1.130 raeburn 8083: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 8084: }
1.48 raeburn 8085: $resulttext .= '</ul>';
8086: } else {
1.130 raeburn 8087: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 8088: }
8089: $resulttext .= '</ul>';
8090: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8091: if (ref($lastactref) eq 'HASH') {
8092: $lastactref->{'domainconfig'} = 1;
8093: }
1.46 raeburn 8094: } else {
1.130 raeburn 8095: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 8096: }
8097: } else {
8098: $resulttext = '<span class="LC_error">'.
8099: &mt('An error occurred: [_1]',$putresult).'</span>';
8100: }
8101: } else {
1.130 raeburn 8102: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 8103: }
8104: if ($errors) {
8105: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
8106: $errors.'</ul>';
8107: }
8108: return $resulttext;
8109: }
8110:
1.48 raeburn 8111: sub modify_coursecategories {
8112: my ($dom,%domconfig) = @_;
1.57 raeburn 8113: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
8114: $cathash);
1.48 raeburn 8115: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 8116: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 8117: $cathash = $domconfig{'coursecategories'}{'cats'};
8118: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
8119: $changes{'togglecats'} = 1;
8120: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
8121: }
8122: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
8123: $changes{'categorize'} = 1;
8124: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
8125: }
1.120 raeburn 8126: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
8127: $changes{'togglecatscomm'} = 1;
8128: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
8129: }
8130: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
8131: $changes{'categorizecomm'} = 1;
8132: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
8133: }
1.57 raeburn 8134: } else {
8135: $changes{'togglecats'} = 1;
8136: $changes{'categorize'} = 1;
1.124 raeburn 8137: $changes{'togglecatscomm'} = 1;
8138: $changes{'categorizecomm'} = 1;
1.87 raeburn 8139: $domconfig{'coursecategories'} = {
8140: togglecats => $env{'form.togglecats'},
8141: categorize => $env{'form.categorize'},
1.124 raeburn 8142: togglecatscomm => $env{'form.togglecatscomm'},
8143: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 8144: };
1.57 raeburn 8145: }
8146: if (ref($cathash) eq 'HASH') {
8147: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 8148: push (@deletecategory,'instcode::0');
8149: }
1.120 raeburn 8150: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
8151: push(@deletecategory,'communities::0');
8152: }
1.48 raeburn 8153: }
1.57 raeburn 8154: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
8155: if (ref($cathash) eq 'HASH') {
1.48 raeburn 8156: if (@deletecategory > 0) {
8157: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 8158: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 8159: foreach my $item (@deletecategory) {
1.57 raeburn 8160: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
8161: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 8162: $deletions{$item} = 1;
1.57 raeburn 8163: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 8164: }
8165: }
8166: }
1.57 raeburn 8167: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 8168: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 8169: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 8170: $reorderings{$item} = 1;
1.57 raeburn 8171: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 8172: }
8173: if ($env{'form.addcategory_name_'.$item} ne '') {
8174: my $newcat = $env{'form.addcategory_name_'.$item};
8175: my $newdepth = $depth+1;
8176: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 8177: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 8178: $adds{$newitem} = 1;
8179: }
8180: if ($env{'form.subcat_'.$item} ne '') {
8181: my $newcat = $env{'form.subcat_'.$item};
8182: my $newdepth = $depth+1;
8183: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 8184: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 8185: $adds{$newitem} = 1;
8186: }
8187: }
8188: }
8189: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 8190: if (ref($cathash) eq 'HASH') {
1.48 raeburn 8191: my $newitem = 'instcode::0';
1.57 raeburn 8192: if ($cathash->{$newitem} eq '') {
8193: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 8194: $adds{$newitem} = 1;
8195: }
8196: } else {
8197: my $newitem = 'instcode::0';
1.57 raeburn 8198: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 8199: $adds{$newitem} = 1;
8200: }
8201: }
1.120 raeburn 8202: if ($env{'form.communities'} eq '1') {
8203: if (ref($cathash) eq 'HASH') {
8204: my $newitem = 'communities::0';
8205: if ($cathash->{$newitem} eq '') {
8206: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
8207: $adds{$newitem} = 1;
8208: }
8209: } else {
8210: my $newitem = 'communities::0';
8211: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
8212: $adds{$newitem} = 1;
8213: }
8214: }
1.48 raeburn 8215: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 8216: if (($env{'form.addcategory_name'} ne 'instcode') &&
8217: ($env{'form.addcategory_name'} ne 'communities')) {
8218: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
8219: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
8220: $adds{$newitem} = 1;
8221: }
1.48 raeburn 8222: }
1.57 raeburn 8223: my $putresult;
1.48 raeburn 8224: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
8225: if (keys(%deletions) > 0) {
8226: foreach my $key (keys(%deletions)) {
8227: if ($predelallitems{$key} ne '') {
8228: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
8229: }
8230: }
8231: }
8232: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 8233: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 8234: if (ref($chkcats[0]) eq 'ARRAY') {
8235: my $depth = 0;
8236: my $chg = 0;
8237: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
8238: my $name = $chkcats[0][$i];
8239: my $item;
8240: if ($name eq '') {
8241: $chg ++;
8242: } else {
8243: $item = &escape($name).'::0';
8244: if ($chg) {
1.57 raeburn 8245: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 8246: }
8247: $depth ++;
1.57 raeburn 8248: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 8249: $depth --;
8250: }
8251: }
8252: }
1.57 raeburn 8253: }
8254: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
8255: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 8256: if ($putresult eq 'ok') {
1.57 raeburn 8257: my %title = (
1.120 raeburn 8258: togglecats => 'Show/Hide a course in catalog',
8259: categorize => 'Assign a category to a course',
8260: togglecatscomm => 'Show/Hide a community in catalog',
8261: categorizecomm => 'Assign a category to a community',
1.57 raeburn 8262: );
8263: my %level = (
1.120 raeburn 8264: dom => 'set in Domain ("Modify Course/Community")',
8265: crs => 'set in Course ("Course Configuration")',
8266: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 8267: );
1.48 raeburn 8268: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 8269: if ($changes{'togglecats'}) {
8270: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
8271: }
8272: if ($changes{'categorize'}) {
8273: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 8274: }
1.120 raeburn 8275: if ($changes{'togglecatscomm'}) {
8276: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
8277: }
8278: if ($changes{'categorizecomm'}) {
8279: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
8280: }
1.57 raeburn 8281: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
8282: my $cathash;
8283: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
8284: $cathash = $domconfig{'coursecategories'}{'cats'};
8285: } else {
8286: $cathash = {};
8287: }
8288: my (@cats,@trails,%allitems);
8289: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
8290: if (keys(%deletions) > 0) {
8291: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
8292: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
8293: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
8294: }
8295: $resulttext .= '</ul></li>';
8296: }
8297: if (keys(%reorderings) > 0) {
8298: my %sort_by_trail;
8299: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
8300: foreach my $key (keys(%reorderings)) {
8301: if ($allitems{$key} ne '') {
8302: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
8303: }
1.48 raeburn 8304: }
1.57 raeburn 8305: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
8306: $resulttext .= '<li>'.$trails[$trail].'</li>';
8307: }
8308: $resulttext .= '</ul></li>';
1.48 raeburn 8309: }
1.57 raeburn 8310: if (keys(%adds) > 0) {
8311: my %sort_by_trail;
8312: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
8313: foreach my $key (keys(%adds)) {
8314: if ($allitems{$key} ne '') {
8315: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
8316: }
8317: }
8318: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
8319: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 8320: }
1.57 raeburn 8321: $resulttext .= '</ul></li>';
1.48 raeburn 8322: }
8323: }
8324: $resulttext .= '</ul>';
8325: } else {
8326: $resulttext = '<span class="LC_error">'.
1.57 raeburn 8327: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 8328: }
8329: } else {
1.120 raeburn 8330: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 8331: }
8332: return $resulttext;
8333: }
8334:
1.69 raeburn 8335: sub modify_serverstatuses {
8336: my ($dom,%domconfig) = @_;
8337: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
8338: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
8339: %currserverstatus = %{$domconfig{'serverstatuses'}};
8340: }
8341: my @pages = &serverstatus_pages();
8342: foreach my $type (@pages) {
8343: $newserverstatus{$type}{'namedusers'} = '';
8344: $newserverstatus{$type}{'machines'} = '';
8345: if (defined($env{'form.'.$type.'_namedusers'})) {
8346: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
8347: my @okusers;
8348: foreach my $user (@users) {
8349: my ($uname,$udom) = split(/:/,$user);
8350: if (($udom =~ /^$match_domain$/) &&
8351: (&Apache::lonnet::domain($udom)) &&
8352: ($uname =~ /^$match_username$/)) {
8353: if (!grep(/^\Q$user\E/,@okusers)) {
8354: push(@okusers,$user);
8355: }
8356: }
8357: }
8358: if (@okusers > 0) {
8359: @okusers = sort(@okusers);
8360: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
8361: }
8362: }
8363: if (defined($env{'form.'.$type.'_machines'})) {
8364: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
8365: my @okmachines;
8366: foreach my $ip (@machines) {
8367: my @parts = split(/\./,$ip);
8368: next if (@parts < 4);
8369: my $badip = 0;
8370: for (my $i=0; $i<4; $i++) {
8371: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
8372: $badip = 1;
8373: last;
8374: }
8375: }
8376: if (!$badip) {
8377: push(@okmachines,$ip);
8378: }
8379: }
8380: @okmachines = sort(@okmachines);
8381: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
8382: }
8383: }
8384: my %serverstatushash = (
8385: serverstatuses => \%newserverstatus,
8386: );
8387: foreach my $type (@pages) {
1.83 raeburn 8388: foreach my $setting ('namedusers','machines') {
1.84 raeburn 8389: my (@current,@new);
1.83 raeburn 8390: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 8391: if ($currserverstatus{$type}{$setting} ne '') {
8392: @current = split(/,/,$currserverstatus{$type}{$setting});
8393: }
8394: }
8395: if ($newserverstatus{$type}{$setting} ne '') {
8396: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 8397: }
8398: if (@current > 0) {
8399: if (@new > 0) {
8400: foreach my $item (@current) {
8401: if (!grep(/^\Q$item\E$/,@new)) {
8402: $changes{$type}{$setting} = 1;
1.82 raeburn 8403: last;
8404: }
8405: }
1.84 raeburn 8406: foreach my $item (@new) {
8407: if (!grep(/^\Q$item\E$/,@current)) {
8408: $changes{$type}{$setting} = 1;
8409: last;
1.82 raeburn 8410: }
8411: }
8412: } else {
1.83 raeburn 8413: $changes{$type}{$setting} = 1;
1.69 raeburn 8414: }
1.83 raeburn 8415: } elsif (@new > 0) {
8416: $changes{$type}{$setting} = 1;
1.69 raeburn 8417: }
8418: }
8419: }
8420: if (keys(%changes) > 0) {
1.81 raeburn 8421: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 8422: my $putresult = &Apache::lonnet::put_dom('configuration',
8423: \%serverstatushash,$dom);
8424: if ($putresult eq 'ok') {
8425: $resulttext .= &mt('Changes made:').'<ul>';
8426: foreach my $type (@pages) {
1.84 raeburn 8427: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 8428: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 8429: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 8430: if ($newserverstatus{$type}{'namedusers'} eq '') {
8431: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
8432: } else {
8433: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
8434: }
1.84 raeburn 8435: }
8436: if ($changes{$type}{'machines'}) {
1.69 raeburn 8437: if ($newserverstatus{$type}{'machines'} eq '') {
8438: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
8439: } else {
8440: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
8441: }
8442:
8443: }
8444: $resulttext .= '</ul></li>';
8445: }
8446: }
8447: $resulttext .= '</ul>';
8448: } else {
8449: $resulttext = '<span class="LC_error">'.
8450: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
8451:
8452: }
8453: } else {
8454: $resulttext = &mt('No changes made to access to server status pages');
8455: }
8456: return $resulttext;
8457: }
8458:
1.118 jms 8459: sub modify_helpsettings {
1.122 jms 8460: my ($r,$dom,$confname,%domconfig) = @_;
1.160.6.5 raeburn 8461: my ($resulttext,$errors,%changes,%helphash);
8462: my %defaultchecked = ('submitbugs' => 'on');
8463: my @offon = ('off','on');
1.118 jms 8464: my @toggles = ('submitbugs');
8465: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8466: foreach my $item (@toggles) {
1.160.6.5 raeburn 8467: if ($defaultchecked{$item} eq 'on') {
8468: if ($domconfig{'helpsettings'}{$item} eq '') {
8469: if ($env{'form.'.$item} eq '0') {
8470: $changes{$item} = 1;
8471: }
8472: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
8473: $changes{$item} = 1;
8474: }
8475: } elsif ($defaultchecked{$item} eq 'off') {
8476: if ($domconfig{'helpsettings'}{$item} eq '') {
8477: if ($env{'form.'.$item} eq '1') {
8478: $changes{$item} = 1;
8479: }
8480: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
8481: $changes{$item} = 1;
8482: }
1.160.6.26 raeburn 8483: }
1.160.6.5 raeburn 8484: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
8485: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
1.122 jms 8486: }
8487: }
1.118 jms 8488: }
1.123 jms 8489: my $putresult;
8490: if (keys(%changes) > 0) {
1.160.6.5 raeburn 8491: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
8492: if ($putresult eq 'ok') {
8493: $resulttext = &mt('Changes made:').'<ul>';
8494: foreach my $item (sort(keys(%changes))) {
8495: if ($item eq 'submitbugs') {
8496: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
8497: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
8498: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
8499: }
8500: }
8501: $resulttext .= '</ul>';
8502: } else {
8503: $resulttext = &mt('No changes made to help settings');
8504: $errors .= '<li><span class="LC_error">'.
8505: &mt('An error occurred storing the settings: [_1]',
8506: $putresult).'</span></li>';
8507: }
1.118 jms 8508: }
8509: if ($errors) {
1.160.6.5 raeburn 8510: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 8511: $errors.'</ul>';
8512: }
8513: return $resulttext;
8514: }
8515:
1.121 raeburn 8516: sub modify_coursedefaults {
1.160.6.27 raeburn 8517: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 8518: my ($resulttext,$errors,%changes,%defaultshash);
8519: my %defaultchecked = ('canuse_pdfforms' => 'off');
8520: my @toggles = ('canuse_pdfforms');
1.160.6.21 raeburn 8521: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.30! raeburn 8522: 'uploadquota_community','uploadquota_textbook');
! 8523: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 8524: my %staticdefaults = (
8525: anonsurvey_threshold => 10,
8526: uploadquota => 500,
8527: );
1.121 raeburn 8528:
8529: $defaultshash{'coursedefaults'} = {};
8530:
8531: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
8532: if ($domconfig{'coursedefaults'} eq '') {
8533: $domconfig{'coursedefaults'} = {};
8534: }
8535: }
8536:
8537: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
8538: foreach my $item (@toggles) {
8539: if ($defaultchecked{$item} eq 'on') {
8540: if (($domconfig{'coursedefaults'}{$item} eq '') &&
8541: ($env{'form.'.$item} eq '0')) {
8542: $changes{$item} = 1;
1.160.6.16 raeburn 8543: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 8544: $changes{$item} = 1;
8545: }
8546: } elsif ($defaultchecked{$item} eq 'off') {
8547: if (($domconfig{'coursedefaults'}{$item} eq '') &&
8548: ($env{'form.'.$item} eq '1')) {
8549: $changes{$item} = 1;
8550: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
8551: $changes{$item} = 1;
8552: }
8553: }
8554: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
8555: }
1.160.6.21 raeburn 8556: foreach my $item (@numbers) {
8557: my ($currdef,$newdef);
1.160.6.26 raeburn 8558: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 8559: if ($item eq 'anonsurvey_threshold') {
8560: $currdef = $domconfig{'coursedefaults'}{$item};
8561: $newdef =~ s/\D//g;
8562: if ($newdef eq '' || $newdef < 1) {
8563: $newdef = 1;
8564: }
8565: $defaultshash{'coursedefaults'}{$item} = $newdef;
8566: } else {
8567: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
8568: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8569: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
8570: }
8571: $newdef =~ s/[^\w.\-]//g;
8572: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
8573: }
8574: if ($currdef ne $newdef) {
8575: my $staticdef;
8576: if ($item eq 'anonsurvey_threshold') {
8577: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
8578: $changes{$item} = 1;
8579: }
8580: } else {
8581: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
8582: $changes{'uploadquota'} = 1;
8583: }
8584: }
1.139 raeburn 8585: }
8586: }
1.160.6.16 raeburn 8587: my $officialcreds = $env{'form.official_credits'};
1.160.6.30! raeburn 8588: $officialcreds =~ s/[^\d.]+//g;
1.160.6.16 raeburn 8589: my $unofficialcreds = $env{'form.unofficial_credits'};
1.160.6.30! raeburn 8590: $unofficialcreds =~ s/[^\d.]+//g;
! 8591: my $textbookcreds = $env{'form.textbook_credits'};
! 8592: $textbookcreds =~ s/[^\d.]+//g;
1.160.6.16 raeburn 8593: if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
8594: ($env{'form.coursecredits'} eq '1')) {
8595: $changes{'coursecredits'} = 1;
8596: } else {
8597: if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
1.160.6.30! raeburn 8598: ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds) ||
! 8599: ($domconfig{'coursedefaults'}{'coursecredits'}{'textbook'} ne $textbookcreds)) {
1.160.6.16 raeburn 8600: $changes{'coursecredits'} = 1;
8601: }
8602: }
8603: $defaultshash{'coursedefaults'}{'coursecredits'} = {
8604: official => $officialcreds,
8605: unofficial => $unofficialcreds,
1.160.6.30! raeburn 8606: textbook => $textbookcreds,
1.160.6.16 raeburn 8607: }
1.121 raeburn 8608: }
8609: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8610: $dom);
8611: if ($putresult eq 'ok') {
8612: if (keys(%changes) > 0) {
1.160.6.27 raeburn 8613: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.21 raeburn 8614: if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) || ($changes{'uploadquota'})) {
1.160.6.16 raeburn 8615: if ($changes{'canuse_pdfforms'}) {
8616: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
8617: }
8618: if ($changes{'coursecredits'}) {
8619: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
8620: $domdefaults{'officialcredits'} =
8621: $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
8622: $domdefaults{'unofficialcredits'} =
8623: $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
1.160.6.30! raeburn 8624: $domdefaults{'textbookcredits'} =
! 8625: $domdefaults{'coursedefaults'}{'coursecredits'}{'textbook'};
1.160.6.16 raeburn 8626: }
8627: }
1.160.6.21 raeburn 8628: if ($changes{'uploadquota'}) {
8629: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8630: foreach my $type (@types) {
8631: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
8632: }
8633: }
8634: }
1.121 raeburn 8635: my $cachetime = 24*60*60;
8636: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 8637: if (ref($lastactref) eq 'HASH') {
8638: $lastactref->{'domdefaults'} = 1;
8639: }
1.121 raeburn 8640: }
8641: $resulttext = &mt('Changes made:').'<ul>';
8642: foreach my $item (sort(keys(%changes))) {
8643: if ($item eq 'canuse_pdfforms') {
8644: if ($env{'form.'.$item} eq '1') {
8645: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
8646: } else {
8647: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
8648: }
1.139 raeburn 8649: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 8650: $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 8651: } elsif ($item eq 'uploadquota') {
8652: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8653: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
8654: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
8655: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30! raeburn 8656: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
! 8657:
1.160.6.21 raeburn 8658: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
8659: '</ul>'.
8660: '</li>';
8661: } else {
8662: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
8663: }
1.160.6.16 raeburn 8664: } elsif ($item eq 'coursecredits') {
8665: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
8666: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30! raeburn 8667: ($domdefaults{'unofficialcredits'} eq '') &&
! 8668: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 8669: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
8670: } else {
8671: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
8672: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
8673: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30! raeburn 8674: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 8675: '</ul>'.
8676: '</li>';
8677: }
8678: } else {
8679: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
8680: }
1.140 raeburn 8681: }
1.121 raeburn 8682: }
8683: $resulttext .= '</ul>';
8684: } else {
8685: $resulttext = &mt('No changes made to course defaults');
8686: }
8687: } else {
8688: $resulttext = '<span class="LC_error">'.
8689: &mt('An error occurred: [_1]',$putresult).'</span>';
8690: }
8691: return $resulttext;
8692: }
8693:
1.137 raeburn 8694: sub modify_usersessions {
1.160.6.27 raeburn 8695: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 8696: my @hostingtypes = ('version','excludedomain','includedomain');
8697: my @offloadtypes = ('primary','default');
8698: my %types = (
8699: remote => \@hostingtypes,
8700: hosted => \@hostingtypes,
8701: spares => \@offloadtypes,
8702: );
8703: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 8704: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 8705: my (%by_ip,%by_location,@intdoms);
8706: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
8707: my @locations = sort(keys(%by_location));
1.137 raeburn 8708: my (%defaultshash,%changes);
8709: foreach my $prefix (@prefixes) {
8710: $defaultshash{'usersessions'}{$prefix} = {};
8711: }
1.160.6.27 raeburn 8712: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 8713: my $resulttext;
1.138 raeburn 8714: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 8715: foreach my $prefix (@prefixes) {
1.145 raeburn 8716: next if ($prefix eq 'spares');
8717: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 8718: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
8719: if ($type eq 'version') {
8720: my $value = $env{'form.'.$prefix.'_'.$type};
8721: my $okvalue;
8722: if ($value ne '') {
8723: if (grep(/^\Q$value\E$/,@lcversions)) {
8724: $okvalue = $value;
8725: }
8726: }
8727: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8728: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
8729: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
8730: if ($inuse == 0) {
8731: $changes{$prefix}{$type} = 1;
8732: } else {
8733: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
8734: $changes{$prefix}{$type} = 1;
8735: }
8736: if ($okvalue ne '') {
8737: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8738: }
8739: }
8740: } else {
8741: if (($inuse == 1) && ($okvalue ne '')) {
8742: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8743: $changes{$prefix}{$type} = 1;
8744: }
8745: }
8746: } else {
8747: if (($inuse == 1) && ($okvalue ne '')) {
8748: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8749: $changes{$prefix}{$type} = 1;
8750: }
8751: }
8752: } else {
8753: if (($inuse == 1) && ($okvalue ne '')) {
8754: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8755: $changes{$prefix}{$type} = 1;
8756: }
8757: }
8758: } else {
8759: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
8760: my @okvals;
8761: foreach my $val (@vals) {
1.138 raeburn 8762: if ($val =~ /:/) {
8763: my @items = split(/:/,$val);
8764: foreach my $item (@items) {
8765: if (ref($by_location{$item}) eq 'ARRAY') {
8766: push(@okvals,$item);
8767: }
8768: }
8769: } else {
8770: if (ref($by_location{$val}) eq 'ARRAY') {
8771: push(@okvals,$val);
8772: }
1.137 raeburn 8773: }
8774: }
8775: @okvals = sort(@okvals);
8776: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8777: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
8778: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8779: if ($inuse == 0) {
8780: $changes{$prefix}{$type} = 1;
8781: } else {
8782: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8783: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
8784: if (@changed > 0) {
8785: $changes{$prefix}{$type} = 1;
8786: }
8787: }
8788: } else {
8789: if ($inuse == 1) {
8790: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8791: $changes{$prefix}{$type} = 1;
8792: }
8793: }
8794: } else {
8795: if ($inuse == 1) {
8796: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8797: $changes{$prefix}{$type} = 1;
8798: }
8799: }
8800: } else {
8801: if ($inuse == 1) {
8802: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8803: $changes{$prefix}{$type} = 1;
8804: }
8805: }
8806: }
8807: }
8808: }
1.145 raeburn 8809:
8810: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 8811: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 8812: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
8813: my $savespares;
8814:
8815: foreach my $lonhost (sort(keys(%servers))) {
8816: my $serverhomeID =
8817: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 8818: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 8819: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
8820: my %spareschg;
8821: foreach my $type (@{$types{'spares'}}) {
8822: my @okspares;
8823: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
8824: foreach my $server (@checked) {
1.152 raeburn 8825: if (&Apache::lonnet::hostname($server) ne '') {
8826: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
8827: unless (grep(/^\Q$server\E$/,@okspares)) {
8828: push(@okspares,$server);
8829: }
1.145 raeburn 8830: }
8831: }
8832: }
8833: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
8834: my $newspare;
1.152 raeburn 8835: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
8836: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 8837: $newspare = $new;
8838: }
8839: }
1.152 raeburn 8840: my @spares;
8841: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
8842: @spares = sort(@okspares,$newspare);
8843: } else {
8844: @spares = sort(@okspares);
8845: }
8846: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 8847: if (ref($spareid{$lonhost}) eq 'HASH') {
8848: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 8849: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 8850: if (@diffs > 0) {
8851: $spareschg{$type} = 1;
8852: }
8853: }
8854: }
8855: }
8856: if (keys(%spareschg) > 0) {
8857: $changes{'spares'}{$lonhost} = \%spareschg;
8858: }
8859: }
8860:
8861: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8862: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
8863: if (ref($changes{'spares'}) eq 'HASH') {
8864: if (keys(%{$changes{'spares'}}) > 0) {
8865: $savespares = 1;
8866: }
8867: }
8868: } else {
8869: $savespares = 1;
8870: }
8871: }
8872:
1.147 raeburn 8873: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
8874: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 8875: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8876: $dom);
8877: if ($putresult eq 'ok') {
8878: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8879: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
8880: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
8881: }
8882: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
8883: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
8884: }
8885: }
8886: my $cachetime = 24*60*60;
8887: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 8888: if (ref($lastactref) eq 'HASH') {
8889: $lastactref->{'domdefaults'} = 1;
8890: }
1.147 raeburn 8891: if (keys(%changes) > 0) {
8892: my %lt = &usersession_titles();
8893: $resulttext = &mt('Changes made:').'<ul>';
8894: foreach my $prefix (@prefixes) {
8895: if (ref($changes{$prefix}) eq 'HASH') {
8896: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
8897: if ($prefix eq 'spares') {
8898: if (ref($changes{$prefix}) eq 'HASH') {
8899: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
8900: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 8901: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 8902: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
8903: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 8904: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
8905: foreach my $type (@{$types{$prefix}}) {
8906: if ($changes{$prefix}{$lonhost}{$type}) {
8907: my $offloadto = &mt('None');
8908: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
8909: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
8910: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
8911: }
1.145 raeburn 8912: }
1.147 raeburn 8913: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 8914: }
1.137 raeburn 8915: }
8916: }
1.147 raeburn 8917: $resulttext .= '</li>';
1.137 raeburn 8918: }
8919: }
1.147 raeburn 8920: } else {
8921: foreach my $type (@{$types{$prefix}}) {
8922: if (defined($changes{$prefix}{$type})) {
8923: my $newvalue;
8924: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8925: if (ref($defaultshash{'usersessions'}{$prefix})) {
8926: if ($type eq 'version') {
8927: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
8928: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8929: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
8930: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
8931: }
1.145 raeburn 8932: }
8933: }
8934: }
1.147 raeburn 8935: if ($newvalue eq '') {
8936: if ($type eq 'version') {
8937: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
8938: } else {
8939: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
8940: }
1.145 raeburn 8941: } else {
1.147 raeburn 8942: if ($type eq 'version') {
8943: $newvalue .= ' '.&mt('(or later)');
8944: }
8945: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 8946: }
1.137 raeburn 8947: }
8948: }
8949: }
1.147 raeburn 8950: $resulttext .= '</ul>';
1.137 raeburn 8951: }
8952: }
1.147 raeburn 8953: $resulttext .= '</ul>';
8954: } else {
8955: $resulttext = $nochgmsg;
1.137 raeburn 8956: }
8957: } else {
8958: $resulttext = '<span class="LC_error">'.
8959: &mt('An error occurred: [_1]',$putresult).'</span>';
8960: }
8961: } else {
1.147 raeburn 8962: $resulttext = $nochgmsg;
1.137 raeburn 8963: }
8964: return $resulttext;
8965: }
8966:
1.150 raeburn 8967: sub modify_loadbalancing {
8968: my ($dom,%domconfig) = @_;
8969: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8970: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8971: my ($othertitle,$usertypes,$types) =
8972: &Apache::loncommon::sorted_inst_types($dom);
8973: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8974: my @sparestypes = ('primary','default');
8975: my %typetitles = &sparestype_titles();
8976: my $resulttext;
1.160.6.7 raeburn 8977: my (%currbalancer,%currtargets,%currrules,%existing);
8978: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8979: %existing = %{$domconfig{'loadbalancing'}};
8980: }
8981: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
8982: \%currtargets,\%currrules);
8983: my ($saveloadbalancing,%defaultshash,%changes);
8984: my ($alltypes,$othertypes,$titles) =
8985: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8986: my %ruletitles = &offloadtype_text();
8987: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
8988: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
8989: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
8990: if ($balancer eq '') {
8991: next;
8992: }
8993: if (!exists($servers{$balancer})) {
8994: if (exists($currbalancer{$balancer})) {
8995: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 8996: }
1.160.6.7 raeburn 8997: next;
8998: }
8999: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
9000: push(@{$changes{'delete'}},$balancer);
9001: next;
9002: }
9003: if (!exists($currbalancer{$balancer})) {
9004: push(@{$changes{'add'}},$balancer);
9005: }
9006: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
9007: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
9008: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
9009: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
9010: $saveloadbalancing = 1;
9011: }
9012: foreach my $sparetype (@sparestypes) {
9013: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
9014: my @offloadto;
9015: foreach my $target (@targets) {
9016: if (($servers{$target}) && ($target ne $balancer)) {
9017: if ($sparetype eq 'default') {
9018: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
9019: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 9020: }
9021: }
1.160.6.7 raeburn 9022: unless(grep(/^\Q$target\E$/,@offloadto)) {
9023: push(@offloadto,$target);
9024: }
1.150 raeburn 9025: }
1.160.6.7 raeburn 9026: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 9027: }
9028: }
1.160.6.7 raeburn 9029: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 9030: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 9031: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
9032: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 9033: if (@targetdiffs > 0) {
1.160.6.7 raeburn 9034: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 9035: }
1.160.6.7 raeburn 9036: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
9037: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
9038: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 9039: }
9040: }
9041: }
9042: } else {
1.160.6.7 raeburn 9043: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
9044: foreach my $sparetype (@sparestypes) {
9045: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
9046: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
9047: $changes{'curr'}{$balancer}{'targets'} = 1;
9048: }
1.150 raeburn 9049: }
9050: }
1.160.6.7 raeburn 9051: }
1.150 raeburn 9052: }
9053: my $ishomedom;
1.160.6.7 raeburn 9054: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
9055: $ishomedom = 1;
1.150 raeburn 9056: }
9057: if (ref($alltypes) eq 'ARRAY') {
9058: foreach my $type (@{$alltypes}) {
9059: my $rule;
1.160.6.7 raeburn 9060: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 9061: (!$ishomedom)) {
1.160.6.7 raeburn 9062: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
9063: }
9064: if ($rule eq 'specific') {
9065: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 9066: }
1.160.6.7 raeburn 9067: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
9068: if (ref($currrules{$balancer}) eq 'HASH') {
9069: if ($rule ne $currrules{$balancer}{$type}) {
9070: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 9071: }
9072: } elsif ($rule ne '') {
1.160.6.7 raeburn 9073: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 9074: }
9075: }
9076: }
1.160.6.7 raeburn 9077: }
9078: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
9079: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
9080: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
9081: $defaultshash{'loadbalancing'} = {};
9082: }
9083: my $putresult = &Apache::lonnet::put_dom('configuration',
9084: \%defaultshash,$dom);
9085: if ($putresult eq 'ok') {
9086: if (keys(%changes) > 0) {
9087: if (ref($changes{'delete'}) eq 'ARRAY') {
9088: foreach my $balancer (sort(@{$changes{'delete'}})) {
9089: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.27 raeburn 9090: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
9091: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 9092: }
1.160.6.7 raeburn 9093: }
9094: if (ref($changes{'add'}) eq 'ARRAY') {
9095: foreach my $balancer (sort(@{$changes{'add'}})) {
9096: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
9097: }
9098: }
9099: if (ref($changes{'curr'}) eq 'HASH') {
9100: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
9101: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
9102: if ($changes{'curr'}{$balancer}{'targets'}) {
9103: my %offloadstr;
9104: foreach my $sparetype (@sparestypes) {
9105: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
9106: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
9107: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
9108: }
9109: }
1.150 raeburn 9110: }
1.160.6.7 raeburn 9111: if (keys(%offloadstr) == 0) {
9112: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 9113: } else {
1.160.6.7 raeburn 9114: my $showoffload;
9115: foreach my $sparetype (@sparestypes) {
9116: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
9117: if (defined($offloadstr{$sparetype})) {
9118: $showoffload .= $offloadstr{$sparetype};
9119: } else {
9120: $showoffload .= &mt('None');
9121: }
9122: $showoffload .= (' 'x3);
9123: }
9124: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 9125: }
9126: }
9127: }
1.160.6.7 raeburn 9128: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
9129: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
9130: foreach my $type (@{$alltypes}) {
9131: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
9132: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
9133: my $balancetext;
9134: if ($rule eq '') {
9135: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 9136: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
9137: ($rule eq 'balancer') || ($rule eq 'offloadedto')) {
1.160.6.7 raeburn 9138: $balancetext = $ruletitles{$rule};
9139: } else {
9140: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
9141: }
1.160.6.26 raeburn 9142: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 9143: }
9144: }
9145: }
9146: }
1.160.6.29 raeburn 9147: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
1.160.6.27 raeburn 9148: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 9149: }
1.160.6.7 raeburn 9150: }
9151: if ($resulttext ne '') {
9152: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 9153: } else {
9154: $resulttext = $nochgmsg;
9155: }
9156: } else {
1.160.6.7 raeburn 9157: $resulttext = $nochgmsg;
1.150 raeburn 9158: }
9159: } else {
1.160.6.7 raeburn 9160: $resulttext = '<span class="LC_error">'.
9161: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 9162: }
9163: } else {
1.160.6.7 raeburn 9164: $resulttext = $nochgmsg;
1.150 raeburn 9165: }
9166: return $resulttext;
9167: }
9168:
1.48 raeburn 9169: sub recurse_check {
9170: my ($chkcats,$categories,$depth,$name) = @_;
9171: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
9172: my $chg = 0;
9173: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
9174: my $category = $chkcats->[$depth]{$name}[$j];
9175: my $item;
9176: if ($category eq '') {
9177: $chg ++;
9178: } else {
9179: my $deeper = $depth + 1;
9180: $item = &escape($category).':'.&escape($name).':'.$depth;
9181: if ($chg) {
9182: $categories->{$item} -= $chg;
9183: }
9184: &recurse_check($chkcats,$categories,$deeper,$category);
9185: $deeper --;
9186: }
9187: }
9188: }
9189: return;
9190: }
9191:
9192: sub recurse_cat_deletes {
9193: my ($item,$coursecategories,$deletions) = @_;
9194: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9195: my $subdepth = $depth + 1;
9196: if (ref($coursecategories) eq 'HASH') {
9197: foreach my $subitem (keys(%{$coursecategories})) {
9198: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
9199: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
9200: delete($coursecategories->{$subitem});
9201: $deletions->{$subitem} = 1;
9202: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 9203: }
1.48 raeburn 9204: }
9205: }
9206: return;
9207: }
9208:
1.125 raeburn 9209: sub get_active_dcs {
9210: my ($dom) = @_;
1.160.6.16 raeburn 9211: my $now = time;
9212: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 9213: my %domcoords;
9214: my $numdcs = 0;
9215: foreach my $server (keys(%dompersonnel)) {
9216: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
9217: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.160.6.16 raeburn 9218: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 9219: }
9220: }
9221: return %domcoords;
9222: }
9223:
9224: sub active_dc_picker {
1.160.6.16 raeburn 9225: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.125 raeburn 9226: my %domcoords = &get_active_dcs($dom);
1.160.6.16 raeburn 9227: my @domcoord = keys(%domcoords);
9228: if (keys(%currhash)) {
9229: foreach my $dc (keys(%currhash)) {
9230: unless (exists($domcoords{$dc})) {
9231: push(@domcoord,$dc);
9232: }
9233: }
9234: }
9235: @domcoord = sort(@domcoord);
9236: my $numdcs = scalar(@domcoord);
9237: my $rows = 0;
9238: my $table;
1.125 raeburn 9239: if ($numdcs > 1) {
1.160.6.16 raeburn 9240: $table = '<table>';
9241: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 9242: my $rem = $i%($numinrow);
9243: if ($rem == 0) {
9244: if ($i > 0) {
1.160.6.16 raeburn 9245: $table .= '</tr>';
1.125 raeburn 9246: }
1.160.6.16 raeburn 9247: $table .= '<tr>';
9248: $rows ++;
1.125 raeburn 9249: }
1.160.6.16 raeburn 9250: my $check = '';
9251: if ($inputtype eq 'radio') {
9252: if (keys(%currhash) == 0) {
9253: if (!$i) {
9254: $check = ' checked="checked"';
9255: }
9256: } elsif (exists($currhash{$domcoord[$i]})) {
9257: $check = ' checked="checked"';
9258: }
9259: } else {
9260: if (exists($currhash{$domcoord[$i]})) {
9261: $check = ' checked="checked"';
1.125 raeburn 9262: }
9263: }
1.160.6.16 raeburn 9264: if ($i == @domcoord - 1) {
1.125 raeburn 9265: my $colsleft = $numinrow - $rem;
9266: if ($colsleft > 1) {
1.160.6.16 raeburn 9267: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 9268: } else {
1.160.6.16 raeburn 9269: $table .= '<td class="LC_left_item">';
1.125 raeburn 9270: }
9271: } else {
1.160.6.16 raeburn 9272: $table .= '<td class="LC_left_item">';
9273: }
9274: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
9275: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
9276: $table .= '<span class="LC_nobreak"><label>'.
9277: '<input type="'.$inputtype.'" name="'.$name.'"'.
9278: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
9279: if ($user ne $dcname.':'.$dcdom) {
9280: $table .= ' ('.$dcname.':'.$dcdom.')'.
9281: '</label></span></td>';
1.125 raeburn 9282: }
9283: }
1.160.6.16 raeburn 9284: $table .= '</tr></table>';
9285: } elsif ($numdcs == 1) {
9286: if ($inputtype eq 'radio') {
9287: $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />';
9288: } else {
9289: my $check;
9290: if (exists($currhash{$domcoord[0]})) {
9291: $check = ' checked="checked"';
9292: }
9293: $table .= '<input type="checkbox" name="'.$name.'" '.
9294: 'value="'.$domcoord[0].'"'.$check.' />';
9295: $rows ++;
9296: }
1.125 raeburn 9297: }
1.160.6.16 raeburn 9298: return ($numdcs,$table,$rows);
1.125 raeburn 9299: }
9300:
1.137 raeburn 9301: sub usersession_titles {
9302: return &Apache::lonlocal::texthash(
9303: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
9304: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 9305: spares => 'Servers offloaded to, when busy',
1.137 raeburn 9306: version => 'LON-CAPA version requirement',
1.138 raeburn 9307: excludedomain => 'Allow all, but exclude specific domains',
9308: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 9309: primary => 'Primary (checked first)',
1.154 raeburn 9310: default => 'Default',
1.137 raeburn 9311: );
9312: }
9313:
1.152 raeburn 9314: sub id_for_thisdom {
9315: my (%servers) = @_;
9316: my %altids;
9317: foreach my $server (keys(%servers)) {
9318: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
9319: if ($serverhome ne $server) {
9320: $altids{$serverhome} = $server;
9321: }
9322: }
9323: return %altids;
9324: }
9325:
1.150 raeburn 9326: sub count_servers {
9327: my ($currbalancer,%servers) = @_;
9328: my (@spares,$numspares);
9329: foreach my $lonhost (sort(keys(%servers))) {
9330: next if ($currbalancer eq $lonhost);
9331: push(@spares,$lonhost);
9332: }
9333: if ($currbalancer) {
9334: $numspares = scalar(@spares);
9335: } else {
9336: $numspares = scalar(@spares) - 1;
9337: }
9338: return ($numspares,@spares);
9339: }
9340:
9341: sub lonbalance_targets_js {
1.160.6.7 raeburn 9342: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 9343: my $select = &mt('Select');
9344: my ($alltargets,$allishome,$allinsttypes,@alltypes);
9345: if (ref($servers) eq 'HASH') {
9346: $alltargets = join("','",sort(keys(%{$servers})));
9347: my @homedoms;
9348: foreach my $server (sort(keys(%{$servers}))) {
9349: if (&Apache::lonnet::host_domain($server) eq $dom) {
9350: push(@homedoms,'1');
9351: } else {
9352: push(@homedoms,'0');
9353: }
9354: }
9355: $allishome = join("','",@homedoms);
9356: }
9357: if (ref($types) eq 'ARRAY') {
9358: if (@{$types} > 0) {
9359: @alltypes = @{$types};
9360: }
9361: }
9362: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
9363: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 9364: my (%currbalancer,%currtargets,%currrules,%existing);
9365: if (ref($settings) eq 'HASH') {
9366: %existing = %{$settings};
9367: }
9368: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
9369: \%currtargets,\%currrules);
9370: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 9371: return <<"END";
9372:
9373: <script type="text/javascript">
9374: // <![CDATA[
9375:
1.160.6.7 raeburn 9376: currBalancers = new Array('$balancers');
9377:
9378: function toggleTargets(balnum) {
9379: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
9380: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
9381: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
9382: var prevbalancer = prevhostitem.value;
9383: var baltotal = document.getElementById('loadbalancing_total').value;
9384: prevhostitem.value = balancer;
9385: if (prevbalancer != '') {
9386: var prevIdx = currBalancers.indexOf(prevbalancer);
9387: if (prevIdx != -1) {
9388: currBalancers.splice(prevIdx,1);
9389: }
9390: }
1.150 raeburn 9391: if (balancer == '') {
1.160.6.7 raeburn 9392: hideSpares(balnum);
1.150 raeburn 9393: } else {
1.160.6.7 raeburn 9394: var currIdx = currBalancers.indexOf(balancer);
9395: if (currIdx == -1) {
9396: currBalancers.push(balancer);
9397: }
1.150 raeburn 9398: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 9399: var ishomedom = homedoms[lonhostitem.selectedIndex];
9400: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 9401: }
1.160.6.7 raeburn 9402: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 9403: return;
9404: }
9405:
1.160.6.7 raeburn 9406: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 9407: var alltargets = new Array('$alltargets');
9408: var insttypes = new Array('$allinsttypes');
1.151 raeburn 9409: var offloadtypes = new Array('primary','default');
9410:
1.160.6.7 raeburn 9411: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
9412: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 9413:
1.151 raeburn 9414: for (var i=0; i<offloadtypes.length; i++) {
9415: var count = 0;
9416: for (var j=0; j<alltargets.length; j++) {
9417: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 9418: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
9419: item.value = alltargets[j];
9420: item.style.textAlign='left';
9421: item.style.textFace='normal';
9422: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
9423: if (currBalancers.indexOf(alltargets[j]) == -1) {
9424: item.disabled = '';
9425: } else {
9426: item.disabled = 'disabled';
9427: item.checked = false;
9428: }
1.151 raeburn 9429: count ++;
9430: }
1.150 raeburn 9431: }
9432: }
1.151 raeburn 9433: for (var k=0; k<insttypes.length; k++) {
9434: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 9435: if (ishomedom == 1) {
1.160.6.7 raeburn 9436: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
9437: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 9438: } else {
1.160.6.7 raeburn 9439: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
9440: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 9441: }
9442: } else {
1.160.6.7 raeburn 9443: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
9444: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 9445: }
1.151 raeburn 9446: if ((insttypes[k] != '_LC_external') &&
9447: ((insttypes[k] != '_LC_internetdom') ||
9448: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 9449: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
9450: item.options.length = 0;
9451: item.options[0] = new Option("","",true,true);
9452: var idx = 0;
1.151 raeburn 9453: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 9454: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
9455: idx ++;
9456: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 9457: }
9458: }
9459: }
9460: }
9461: return;
9462: }
9463:
1.160.6.7 raeburn 9464: function hideSpares(balnum) {
1.150 raeburn 9465: var alltargets = new Array('$alltargets');
9466: var insttypes = new Array('$allinsttypes');
9467: var offloadtypes = new Array('primary','default');
9468:
1.160.6.7 raeburn 9469: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
9470: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 9471:
9472: var total = alltargets.length - 1;
9473: for (var i=0; i<offloadtypes; i++) {
9474: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 9475: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
9476: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
9477: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 9478: }
1.150 raeburn 9479: }
9480: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 9481: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
9482: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 9483: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 9484: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
9485: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 9486: }
9487: }
9488: return;
9489: }
9490:
1.160.6.7 raeburn 9491: function checkOffloads(item,balnum,type) {
1.150 raeburn 9492: var alltargets = new Array('$alltargets');
9493: var offloadtypes = new Array('primary','default');
9494: if (item.checked) {
9495: var total = alltargets.length - 1;
9496: var other;
9497: if (type == offloadtypes[0]) {
1.151 raeburn 9498: other = offloadtypes[1];
1.150 raeburn 9499: } else {
1.151 raeburn 9500: other = offloadtypes[0];
1.150 raeburn 9501: }
9502: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 9503: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 9504: if (server == item.value) {
1.160.6.7 raeburn 9505: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
9506: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 9507: }
9508: }
9509: }
9510: }
9511: return;
9512: }
9513:
1.160.6.7 raeburn 9514: function singleServerToggle(balnum,type) {
9515: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 9516: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 9517: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
9518: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 9519:
9520: } else {
1.160.6.7 raeburn 9521: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
9522: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 9523: }
9524: return;
9525: }
9526:
1.160.6.7 raeburn 9527: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 9528: if (type == '_LC_external') {
1.160.6.26 raeburn 9529: return;
1.150 raeburn 9530: }
1.160.6.7 raeburn 9531: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 9532: for (var i=0; i<typesRules.length; i++) {
9533: if (formname.elements[typesRules[i]].checked) {
9534: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 9535: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
9536: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 9537: } else {
1.160.6.7 raeburn 9538: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
9539: }
9540: }
9541: }
9542: return;
9543: }
9544:
9545: function balancerDeleteChange(balnum) {
9546: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
9547: var baltotal = document.getElementById('loadbalancing_total').value;
9548: var addtarget;
9549: var removetarget;
9550: var action = 'delete';
9551: if (document.getElementById('loadbalancing_delete_'+balnum)) {
9552: var lonhost = hostitem.value;
9553: var currIdx = currBalancers.indexOf(lonhost);
9554: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
9555: if (currIdx != -1) {
9556: currBalancers.splice(currIdx,1);
9557: }
9558: addtarget = lonhost;
9559: } else {
9560: if (currIdx == -1) {
9561: currBalancers.push(lonhost);
9562: }
9563: removetarget = lonhost;
9564: action = 'undelete';
9565: }
9566: balancerChange(balnum,baltotal,action,addtarget,removetarget);
9567: }
9568: return;
9569: }
9570:
9571: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
9572: if (baltotal > 1) {
9573: var offloadtypes = new Array('primary','default');
9574: var alltargets = new Array('$alltargets');
9575: var insttypes = new Array('$allinsttypes');
9576: for (var i=0; i<baltotal; i++) {
9577: if (i != balnum) {
9578: for (var j=0; j<offloadtypes.length; j++) {
9579: var total = alltargets.length - 1;
9580: for (var k=0; k<total; k++) {
9581: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
9582: var server = serveritem.value;
9583: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
9584: if (server == addtarget) {
9585: serveritem.disabled = '';
9586: }
9587: }
9588: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
9589: if (server == removetarget) {
9590: serveritem.disabled = 'disabled';
9591: serveritem.checked = false;
9592: }
9593: }
9594: }
9595: }
9596: for (var j=0; j<insttypes.length; j++) {
9597: if (insttypes[j] != '_LC_external') {
9598: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
9599: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
9600: var currSel = singleserver.selectedIndex;
9601: var currVal = singleserver.options[currSel].value;
9602: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
9603: var numoptions = singleserver.options.length;
9604: var needsnew = 1;
9605: for (var k=0; k<numoptions; k++) {
9606: if (singleserver.options[k] == addtarget) {
9607: needsnew = 0;
9608: break;
9609: }
9610: }
9611: if (needsnew == 1) {
9612: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
9613: }
9614: }
9615: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
9616: singleserver.options.length = 0;
9617: if ((currVal) && (currVal != removetarget)) {
9618: singleserver.options[0] = new Option("","",false,false);
9619: } else {
9620: singleserver.options[0] = new Option("","",true,true);
9621: }
9622: var idx = 0;
9623: for (var m=0; m<alltargets.length; m++) {
9624: if (currBalancers.indexOf(alltargets[m]) == -1) {
9625: idx ++;
9626: if (currVal == alltargets[m]) {
9627: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
9628: } else {
9629: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
9630: }
9631: }
9632: }
9633: }
9634: }
9635: }
9636: }
1.150 raeburn 9637: }
9638: }
9639: }
9640: return;
9641: }
9642:
1.152 raeburn 9643: // ]]>
9644: </script>
9645:
9646: END
9647: }
9648:
9649: sub new_spares_js {
9650: my @sparestypes = ('primary','default');
9651: my $types = join("','",@sparestypes);
9652: my $select = &mt('Select');
9653: return <<"END";
9654:
9655: <script type="text/javascript">
9656: // <![CDATA[
9657:
9658: function updateNewSpares(formname,lonhost) {
9659: var types = new Array('$types');
9660: var include = new Array();
9661: var exclude = new Array();
9662: for (var i=0; i<types.length; i++) {
9663: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
9664: for (var j=0; j<spareboxes.length; j++) {
9665: if (formname.elements[spareboxes[j]].checked) {
9666: exclude.push(formname.elements[spareboxes[j]].value);
9667: } else {
9668: include.push(formname.elements[spareboxes[j]].value);
9669: }
9670: }
9671: }
9672: for (var i=0; i<types.length; i++) {
9673: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
9674: var selIdx = newSpare.selectedIndex;
9675: var currnew = newSpare.options[selIdx].value;
9676: var okSpares = new Array();
9677: for (var j=0; j<newSpare.options.length; j++) {
9678: var possible = newSpare.options[j].value;
9679: if (possible != '') {
9680: if (exclude.indexOf(possible) == -1) {
9681: okSpares.push(possible);
9682: } else {
9683: if (currnew == possible) {
9684: selIdx = 0;
9685: }
9686: }
9687: }
9688: }
9689: for (var k=0; k<include.length; k++) {
9690: if (okSpares.indexOf(include[k]) == -1) {
9691: okSpares.push(include[k]);
9692: }
9693: }
9694: okSpares.sort();
9695: newSpare.options.length = 0;
9696: if (selIdx == 0) {
9697: newSpare.options[0] = new Option("$select","",true,true);
9698: } else {
9699: newSpare.options[0] = new Option("$select","",false,false);
9700: }
9701: for (var m=0; m<okSpares.length; m++) {
9702: var idx = m+1;
9703: var selThis = 0;
9704: if (selIdx != 0) {
9705: if (okSpares[m] == currnew) {
9706: selThis = 1;
9707: }
9708: }
9709: if (selThis == 1) {
9710: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
9711: } else {
9712: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
9713: }
9714: }
9715: }
9716: return;
9717: }
9718:
9719: function checkNewSpares(lonhost,type) {
9720: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
9721: var chosen = newSpare.options[newSpare.selectedIndex].value;
9722: if (chosen != '') {
9723: var othertype;
9724: var othernewSpare;
9725: if (type == 'primary') {
9726: othernewSpare = document.getElementById('newspare_default_'+lonhost);
9727: }
9728: if (type == 'default') {
9729: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
9730: }
9731: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
9732: othernewSpare.selectedIndex = 0;
9733: }
9734: }
9735: return;
9736: }
9737:
9738: // ]]>
9739: </script>
9740:
9741: END
9742:
9743: }
9744:
9745: sub common_domprefs_js {
9746: return <<"END";
9747:
9748: <script type="text/javascript">
9749: // <![CDATA[
9750:
1.150 raeburn 9751: function getIndicesByName(formname,item) {
1.152 raeburn 9752: var group = new Array();
1.150 raeburn 9753: for (var i=0;i<formname.elements.length;i++) {
9754: if (formname.elements[i].name == item) {
1.152 raeburn 9755: group.push(formname.elements[i].id);
1.150 raeburn 9756: }
9757: }
1.152 raeburn 9758: return group;
1.150 raeburn 9759: }
9760:
9761: // ]]>
9762: </script>
9763:
9764: END
1.152 raeburn 9765:
1.150 raeburn 9766: }
9767:
1.160.6.5 raeburn 9768: sub recaptcha_js {
9769: my %lt = &captcha_phrases();
9770: return <<"END";
9771:
9772: <script type="text/javascript">
9773: // <![CDATA[
9774:
9775: function updateCaptcha(caller,context) {
9776: var privitem;
9777: var pubitem;
9778: var privtext;
9779: var pubtext;
9780: if (document.getElementById(context+'_recaptchapub')) {
9781: pubitem = document.getElementById(context+'_recaptchapub');
9782: } else {
9783: return;
9784: }
9785: if (document.getElementById(context+'_recaptchapriv')) {
9786: privitem = document.getElementById(context+'_recaptchapriv');
9787: } else {
9788: return;
9789: }
9790: if (document.getElementById(context+'_recaptchapubtxt')) {
9791: pubtext = document.getElementById(context+'_recaptchapubtxt');
9792: } else {
9793: return;
9794: }
9795: if (document.getElementById(context+'_recaptchaprivtxt')) {
9796: privtext = document.getElementById(context+'_recaptchaprivtxt');
9797: } else {
9798: return;
9799: }
9800: if (caller.checked) {
9801: if (caller.value == 'recaptcha') {
9802: pubitem.type = 'text';
9803: privitem.type = 'text';
9804: pubitem.size = '40';
9805: privitem.size = '40';
9806: pubtext.innerHTML = "$lt{'pub'}";
9807: privtext.innerHTML = "$lt{'priv'}";
9808: } else {
9809: pubitem.type = 'hidden';
9810: privitem.type = 'hidden';
9811: pubtext.innerHTML = '';
9812: privtext.innerHTML = '';
9813: }
9814: }
9815: return;
9816: }
9817:
9818: // ]]>
9819: </script>
9820:
9821: END
9822:
9823: }
9824:
1.160.6.16 raeburn 9825: sub credits_js {
9826: return <<"END";
9827:
9828: <script type="text/javascript">
9829: // <![CDATA[
9830:
9831: function toggleCredits(domForm) {
9832: if (document.getElementById('credits')) {
9833: creditsitem = document.getElementById('credits');
9834: var creditsLength = domForm.coursecredits.length;
9835: if (creditsLength) {
9836: var currval;
9837: for (var i=0; i<creditsLength; i++) {
9838: if (domForm.coursecredits[i].checked) {
9839: currval = domForm.coursecredits[i].value;
9840: }
9841: }
9842: if (currval == 1) {
9843: creditsitem.style.display = 'block';
9844: } else {
9845: creditsitem.style.display = 'none';
9846: }
9847: }
9848: }
9849: return;
9850: }
9851:
9852: // ]]>
9853: </script>
9854:
9855: END
9856:
9857: }
9858:
1.160.6.5 raeburn 9859: sub captcha_phrases {
9860: return &Apache::lonlocal::texthash (
9861: priv => 'Private key',
9862: pub => 'Public key',
9863: original => 'original (CAPTCHA)',
9864: recaptcha => 'successor (ReCAPTCHA)',
9865: notused => 'unused',
9866: );
9867: }
9868:
1.160.6.24 raeburn 9869: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 9870: my ($dom,$cachekeys) = @_;
9871: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 9872: my %servers = &Apache::lonnet::internet_dom_servers($dom);
9873: my %thismachine;
9874: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.27 raeburn 9875: my @posscached = ('domainconfig','domdefaults');
1.160.6.24 raeburn 9876: if (keys(%servers) > 1) {
9877: foreach my $server (keys(%servers)) {
9878: next if ($thismachine{$server});
1.160.6.27 raeburn 9879: my @cached;
9880: foreach my $name (@posscached) {
9881: if ($cachekeys->{$name}) {
9882: push(@cached,&escape($name).':'.&escape($dom));
9883: }
9884: }
9885: if (@cached) {
9886: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
9887: }
1.160.6.24 raeburn 9888: }
9889: }
9890: return;
9891: }
9892:
1.3 raeburn 9893: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>