Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.34
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.34! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.33 2014/01/06 14:08:31 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
1.160.6.34! raeburn 98: default quota sizes for Authoring Spaces.
1.160.6.20 raeburn 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.160.6.34! raeburn 218: 'usercreation','selfcreation','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: 'usercreation' =>
297: { text => 'User creation',
1.67 raeburn 298: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 299: header => [{col1 => 'Format rule type',
300: col2 => 'Format rules in force'},
1.34 raeburn 301: {col1 => 'User account creation',
302: col2 => 'Usernames which may be created',},
1.30 raeburn 303: {col1 => 'Context',
1.43 raeburn 304: col2 => 'Assignable authentication types'}],
1.30 raeburn 305: },
1.160.6.34! raeburn 306: 'selfcreation' =>
! 307: { text => 'Users self-creating accounts',
! 308: help => 'Domain_Configuration_Self_Creation',
! 309: header => [{col1 => 'Self-creation with institutional username',
! 310: col2 => 'Enabled?'},
! 311: {col1 => 'Institutional user type (login/SSO self-creation)',
! 312: col2 => 'Information user can enter'},
! 313: {col1 => 'Self-creation with e-mail as username',
! 314: col2 => 'Settings'}],
! 315: },
1.69 raeburn 316: 'usermodification' =>
1.33 raeburn 317: { text => 'User modification',
1.67 raeburn 318: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 319: header => [{col1 => 'Target user has role',
320: col2 => 'User information updateable in author context'},
321: {col1 => 'Target user has role',
1.160.6.34! raeburn 322: col2 => 'User information updateable in course context'}],
1.33 raeburn 323: },
1.69 raeburn 324: 'scantron' =>
1.95 www 325: { text => 'Bubblesheet format file',
1.67 raeburn 326: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 327: header => [ {col1 => 'Item',
328: col2 => '',
329: }],
330: },
1.86 raeburn 331: 'requestcourses' =>
332: {text => 'Request creation of courses',
333: help => 'Domain_Configuration_Request_Courses',
334: header => [{col1 => 'User affiliation',
1.102 raeburn 335: col2 => 'Availability/Processing of requests',},
336: {col1 => 'Setting',
1.160.6.30 raeburn 337: col2 => 'Value'},
338: {col1 => 'Available textbooks',
339: col2 => ''}],
1.86 raeburn 340: },
1.160.6.5 raeburn 341: 'requestauthor' =>
1.160.6.34! raeburn 342: {text => 'Request Authoring Space',
1.160.6.5 raeburn 343: help => 'Domain_Configuration_Request_Author',
344: header => [{col1 => 'User affiliation',
345: col2 => 'Availability/Processing of requests',},
346: {col1 => 'Setting',
347: col2 => 'Value'}],
348: },
1.69 raeburn 349: 'coursecategories' =>
1.120 raeburn 350: { text => 'Cataloging of courses/communities',
1.67 raeburn 351: help => 'Domain_Configuration_Cataloging_Courses',
1.69 raeburn 352: header => [{col1 => 'Category settings',
1.57 raeburn 353: col2 => '',},
354: {col1 => 'Categories',
355: col2 => '',
356: }],
1.69 raeburn 357: },
358: 'serverstatuses' =>
1.77 raeburn 359: {text => 'Access to server status pages',
1.69 raeburn 360: help => 'Domain_Configuration_Server_Status',
361: header => [{col1 => 'Status Page',
362: col2 => 'Other named users',
363: col3 => 'Specific IPs',
364: }],
365: },
1.160.6.16 raeburn 366: 'coursedefaults' =>
367: {text => 'Course/Community defaults',
368: help => 'Domain_Configuration_Course_Defaults',
369: header => [{col1 => 'Defaults which can be overridden for each course by a DC',
370: col2 => 'Value',},],
371: },
1.141 raeburn 372: 'usersessions' =>
1.145 raeburn 373: {text => 'User session hosting/offloading',
1.137 raeburn 374: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 375: header => [{col1 => 'Domain server',
376: col2 => 'Servers to offload sessions to when busy'},
377: {col1 => 'Hosting of users from other domains',
1.137 raeburn 378: col2 => 'Rules'},
379: {col1 => "Hosting domain's own users elsewhere",
380: col2 => 'Rules'}],
381: },
1.150 raeburn 382: 'loadbalancing' =>
1.160.6.7 raeburn 383: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 384: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 385: header => [{col1 => 'Balancers',
1.150 raeburn 386: col2 => 'Default destinations',
1.160.6.13 raeburn 387: col3 => 'User affiliation',
1.150 raeburn 388: col4 => 'Overrides'},
389: ],
390: },
1.3 raeburn 391: );
1.110 raeburn 392: if (keys(%servers) > 1) {
393: $prefs{'login'} = { text => 'Log-in page options',
394: help => 'Domain_Configuration_Login_Page',
395: header => [{col1 => 'Log-in Service',
396: col2 => 'Server Setting',},
397: {col1 => 'Log-in Page Items',
1.160.6.5 raeburn 398: col2 => ''},
399: {col1 => 'Log-in Help',
400: col2 => 'Value'}],
1.110 raeburn 401: };
402: }
1.160.6.13 raeburn 403:
1.6 raeburn 404: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 405: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 406: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 407: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 408: text=>"Settings to display/modify"});
1.9 raeburn 409: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 410:
1.3 raeburn 411: if ($phase eq 'process') {
1.160.6.27 raeburn 412: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
413: \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33 raeburn 414: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24 raeburn 415: $r->rflush();
1.160.6.27 raeburn 416: &devalidate_remote_domconfs($dom,$result);
1.160.6.24 raeburn 417: }
1.30 raeburn 418: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 419: my $js = &recaptcha_js().
1.160.6.26 raeburn 420: &credits_js();
1.160.6.7 raeburn 421: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 422: my ($othertitle,$usertypes,$types) =
423: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 424: $js .= &lonbalance_targets_js($dom,$types,\%servers,
425: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 426: &new_spares_js().
427: &common_domprefs_js().
428: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 429: }
1.160.6.30 raeburn 430: if (grep(/^requestcourses$/,@actions)) {
431: my $javascript_validations;
432: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
433: $js .= <<END;
434: <script type="text/javascript">
435: $javascript_validations
436: </script>
437: $coursebrowserjs
438: END
439: }
1.150 raeburn 440: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 441: } else {
1.160.6.11 raeburn 442: # check if domconfig user exists for the domain.
443: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 444: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 445: &config_check($dom,$confname,$servadm);
446: unless ($configuserok eq 'ok') {
447: &Apache::lonconfigsettings::print_header($r,$phase,$context);
448: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
449: $confname).
450: '<br />'
451: );
452: if ($switchserver) {
453: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
454: '<br />'.
455: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
456: '<br />'.
457: &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).
458: '<br />'.
459: &mt('To do that now, use the following link: [_1]',$switchserver)
460: );
461: } else {
462: $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.').
463: '<br />'.
464: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
465: );
466: }
467: $r->print(&Apache::loncommon::end_page());
468: return OK;
469: }
1.21 raeburn 470: if (keys(%domconfig) == 0) {
471: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 472: my @ids=&Apache::lonnet::current_machine_ids();
473: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 474: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 475: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 476: my $custom_img_count = 0;
477: foreach my $img (@loginimages) {
478: if ($designhash{$dom.'.login.'.$img} ne '') {
479: $custom_img_count ++;
480: }
481: }
482: foreach my $role (@roles) {
483: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
484: $custom_img_count ++;
485: }
486: }
487: if ($custom_img_count > 0) {
1.94 raeburn 488: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 489: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 490: $r->print(
491: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
492: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
493: &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 />'.
494: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
495: if ($switch_server) {
1.30 raeburn 496: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 497: }
1.91 raeburn 498: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 499: return OK;
500: }
501: }
502: }
1.91 raeburn 503: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 504: }
505: return OK;
506: }
507:
508: sub process_changes {
1.160.6.24 raeburn 509: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 510: my %domconfig;
511: if (ref($values) eq 'HASH') {
512: %domconfig = %{$values};
513: }
1.3 raeburn 514: my $output;
515: if ($action eq 'login') {
1.160.6.24 raeburn 516: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 517: } elsif ($action eq 'rolecolors') {
1.9 raeburn 518: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 519: $lastactref,%domconfig);
1.3 raeburn 520: } elsif ($action eq 'quotas') {
1.160.6.30 raeburn 521: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 522: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 523: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 524: } elsif ($action eq 'autoupdate') {
525: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 526: } elsif ($action eq 'autocreate') {
527: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 528: } elsif ($action eq 'directorysrch') {
529: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 530: } elsif ($action eq 'usercreation') {
1.28 raeburn 531: $output = &modify_usercreation($dom,%domconfig);
1.160.6.34! raeburn 532: } elsif ($action eq 'selfcreation') {
! 533: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 534: } elsif ($action eq 'usermodification') {
535: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 536: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 537: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 538: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 539: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 540: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 541: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 542: } elsif ($action eq 'coursecategories') {
543: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 544: } elsif ($action eq 'serverstatuses') {
545: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 546: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 547: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 548: } elsif ($action eq 'requestauthor') {
1.160.6.30 raeburn 549: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.16 raeburn 550: } elsif ($action eq 'coursedefaults') {
1.160.6.27 raeburn 551: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.137 raeburn 552: } elsif ($action eq 'usersessions') {
1.160.6.27 raeburn 553: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 554: } elsif ($action eq 'loadbalancing') {
555: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 556: }
557: return $output;
558: }
559:
560: sub print_config_box {
1.9 raeburn 561: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 562: my $rowtotal = 0;
1.49 raeburn 563: my $output;
564: if ($action eq 'coursecategories') {
565: $output = &coursecategories_javascript($settings);
1.91 raeburn 566: }
1.49 raeburn 567: $output .=
1.30 raeburn 568: '<table class="LC_nested_outer">
1.3 raeburn 569: <tr>
1.66 raeburn 570: <th align="left" valign="middle"><span class="LC_nobreak">'.
571: &mt($item->{text}).' '.
572: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
573: '</tr>';
1.30 raeburn 574: $rowtotal ++;
1.110 raeburn 575: my $numheaders = 1;
576: if (ref($item->{'header'}) eq 'ARRAY') {
577: $numheaders = scalar(@{$item->{'header'}});
578: }
579: if ($numheaders > 1) {
1.64 raeburn 580: my $colspan = '';
1.145 raeburn 581: my $rightcolspan = '';
1.160.6.5 raeburn 582: if (($action eq 'rolecolors') || ($action eq 'coursecategories') ||
583: (($action eq 'login') && ($numheaders < 3))) {
1.64 raeburn 584: $colspan = ' colspan="2"';
585: }
1.145 raeburn 586: if ($action eq 'usersessions') {
587: $rightcolspan = ' colspan="3"';
588: }
1.30 raeburn 589: $output .= '
1.3 raeburn 590: <tr>
591: <td>
592: <table class="LC_nested">
593: <tr class="LC_info_row">
1.59 bisitz 594: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 595: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 596: </tr>';
1.69 raeburn 597: $rowtotal ++;
1.6 raeburn 598: if ($action eq 'autoupdate') {
1.30 raeburn 599: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 600: } elsif ($action eq 'usercreation') {
1.33 raeburn 601: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
1.160.6.34! raeburn 602: } elsif ($action eq 'selfcreation') {
! 603: $output .= &print_selfcreation('top',$dom,$settings,\$rowtotal);
1.33 raeburn 604: } elsif ($action eq 'usermodification') {
605: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57 raeburn 606: } elsif ($action eq 'coursecategories') {
607: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 608: } elsif ($action eq 'login') {
1.160.6.5 raeburn 609: if ($numheaders == 3) {
610: $colspan = ' colspan="2"';
611: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
612: } else {
613: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
614: }
1.102 raeburn 615: } elsif ($action eq 'requestcourses') {
616: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.5 raeburn 617: } elsif ($action eq 'requestauthor') {
618: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.137 raeburn 619: } elsif ($action eq 'usersessions') {
620: $output .= &print_usersessions('top',$dom,$settings,\$rowtotal);
1.122 jms 621: } elsif ($action eq 'rolecolors') {
1.30 raeburn 622: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 623: }
1.30 raeburn 624: $output .= '
1.6 raeburn 625: </table>
626: </td>
627: </tr>
628: <tr>
629: <td>
630: <table class="LC_nested">
631: <tr class="LC_info_row">
1.59 bisitz 632: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57 raeburn 633: $output .= '
1.59 bisitz 634: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 635: </tr>';
636: $rowtotal ++;
1.6 raeburn 637: if ($action eq 'autoupdate') {
1.131 raeburn 638: $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
639: </table>
640: </td>
641: </tr>
642: <tr>
643: <td>
644: <table class="LC_nested">
645: <tr class="LC_info_row">
646: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
647: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
648: &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
649: $rowtotal ++;
1.28 raeburn 650: } elsif ($action eq 'usercreation') {
1.34 raeburn 651: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
652: </table>
653: </td>
654: </tr>
655: <tr>
656: <td>
657: <table class="LC_nested">
658: <tr class="LC_info_row">
1.59 bisitz 659: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
660: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.34 raeburn 661: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
662: $rowtotal ++;
1.160.6.34! raeburn 663: } elsif ($action eq 'selfcreation') {
! 664: $output .= &print_selfcreation('middle',$dom,$settings,\$rowtotal).'
1.63 raeburn 665: </table>
666: </td>
667: </tr>
668: <tr>
669: <td>
670: <table class="LC_nested">
671: <tr class="LC_info_row">
672: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34! raeburn 673: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
! 674: </tr>'.
! 675: &print_selfcreation('bottom',$dom,$settings,\$rowtotal);
1.63 raeburn 676: $rowtotal ++;
1.160.6.34! raeburn 677: } elsif ($action eq 'usermodification') {
! 678: $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal);
1.57 raeburn 679: } elsif ($action eq 'coursecategories') {
680: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 681: } elsif ($action eq 'login') {
1.160.6.5 raeburn 682: if ($numheaders == 3) {
683: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
684: </table>
685: </td>
686: </tr>
687: <tr>
688: <td>
689: <table class="LC_nested">
690: <tr class="LC_info_row">
691: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30 raeburn 692: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 693: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
694: $rowtotal ++;
695: } else {
696: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
697: }
1.102 raeburn 698: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 699: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal).
700: &print_studentcode($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_textbookcourses($dom,$settings,\$rowtotal);
1.160.6.5 raeburn 711: } elsif ($action eq 'requestauthor') {
712: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.137 raeburn 713: } elsif ($action eq 'usersessions') {
1.145 raeburn 714: $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
715: </table>
716: </td>
717: </tr>
718: <tr>
719: <td>
720: <table class="LC_nested">
721: <tr class="LC_info_row">
722: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
723: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
724: &print_usersessions('bottom',$dom,$settings,\$rowtotal);
725: $rowtotal ++;
1.122 jms 726: } elsif ($action eq 'rolecolors') {
1.30 raeburn 727: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 728: </table>
729: </td>
730: </tr>
731: <tr>
732: <td>
733: <table class="LC_nested">
734: <tr class="LC_info_row">
1.69 raeburn 735: <td class="LC_left_item"'.$colspan.' valign="top">'.
736: &mt($item->{'header'}->[2]->{'col1'}).'</td>
737: <td class="LC_right_item" valign="top">'.
738: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 739: </tr>'.
1.30 raeburn 740: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 741: </table>
742: </td>
743: </tr>
744: <tr>
745: <td>
746: <table class="LC_nested">
747: <tr class="LC_info_row">
1.59 bisitz 748: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
749: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 750: </tr>'.
1.30 raeburn 751: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
752: $rowtotal += 2;
1.6 raeburn 753: }
1.3 raeburn 754: } else {
1.30 raeburn 755: $output .= '
1.3 raeburn 756: <tr>
757: <td>
758: <table class="LC_nested">
1.30 raeburn 759: <tr class="LC_info_row">';
1.24 raeburn 760: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 761: $output .= '
1.59 bisitz 762: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 763: } elsif ($action eq 'serverstatuses') {
764: $output .= '
765: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
766: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
767:
1.6 raeburn 768: } else {
1.30 raeburn 769: $output .= '
1.69 raeburn 770: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
771: }
1.72 raeburn 772: if (defined($item->{'header'}->[0]->{'col3'})) {
773: $output .= '<td class="LC_left_item" valign="top">'.
774: &mt($item->{'header'}->[0]->{'col2'});
775: if ($action eq 'serverstatuses') {
776: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
777: }
1.69 raeburn 778: } else {
779: $output .= '<td class="LC_right_item" valign="top">'.
780: &mt($item->{'header'}->[0]->{'col2'});
781: }
782: $output .= '</td>';
783: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 784: if (defined($item->{'header'}->[0]->{'col4'})) {
785: $output .= '<td class="LC_left_item" valign="top">'.
786: &mt($item->{'header'}->[0]->{'col3'});
787: } else {
788: $output .= '<td class="LC_right_item" valign="top">'.
789: &mt($item->{'header'}->[0]->{'col3'});
790: }
1.69 raeburn 791: if ($action eq 'serverstatuses') {
792: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
793: }
794: $output .= '</td>';
1.6 raeburn 795: }
1.150 raeburn 796: if ($item->{'header'}->[0]->{'col4'}) {
797: $output .= '<td class="LC_right_item" valign="top">'.
798: &mt($item->{'header'}->[0]->{'col4'});
799: }
1.69 raeburn 800: $output .= '</tr>';
1.48 raeburn 801: $rowtotal ++;
1.160.6.5 raeburn 802: if ($action eq 'quotas') {
1.86 raeburn 803: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3 raeburn 804: } elsif ($action eq 'autoenroll') {
1.30 raeburn 805: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125 raeburn 806: } elsif ($action eq 'autocreate') {
807: $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23 raeburn 808: } elsif ($action eq 'directorysrch') {
1.30 raeburn 809: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 810: } elsif ($action eq 'contacts') {
1.30 raeburn 811: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 raeburn 812: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 813: $output .= &print_defaults($dom,$settings,\$rowtotal);
1.46 raeburn 814: } elsif ($action eq 'scantron') {
815: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69 raeburn 816: } elsif ($action eq 'serverstatuses') {
817: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118 jms 818: } elsif ($action eq 'helpsettings') {
1.160.6.5 raeburn 819: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.150 raeburn 820: } elsif ($action eq 'loadbalancing') {
821: $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.160.6.16 raeburn 822: } elsif ($action eq 'coursedefaults') {
823: $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.121 raeburn 824: }
1.3 raeburn 825: }
1.30 raeburn 826: $output .= '
1.3 raeburn 827: </table>
828: </td>
829: </tr>
1.30 raeburn 830: </table><br />';
831: return ($output,$rowtotal);
1.1 raeburn 832: }
833:
1.3 raeburn 834: sub print_login {
1.160.6.5 raeburn 835: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 836: my ($css_class,$datatable);
1.6 raeburn 837: my %choices = &login_choices();
1.110 raeburn 838:
1.160.6.5 raeburn 839: if ($caller eq 'service') {
1.149 raeburn 840: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 841: my $choice = $choices{'disallowlogin'};
842: $css_class = ' class="LC_odd_row"';
1.128 raeburn 843: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 844: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 845: '<th>'.$choices{'server'}.'</th>'.
846: '<th>'.$choices{'serverpath'}.'</th>'.
847: '<th>'.$choices{'custompath'}.'</th>'.
848: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 849: my %disallowed;
850: if (ref($settings) eq 'HASH') {
851: if (ref($settings->{'loginvia'}) eq 'HASH') {
852: %disallowed = %{$settings->{'loginvia'}};
853: }
854: }
855: foreach my $lonhost (sort(keys(%servers))) {
856: my $direct = 'selected="selected"';
1.128 raeburn 857: if (ref($disallowed{$lonhost}) eq 'HASH') {
858: if ($disallowed{$lonhost}{'server'} ne '') {
859: $direct = '';
860: }
1.110 raeburn 861: }
1.115 raeburn 862: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 863: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 864: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
865: '</option>';
1.160.6.13 raeburn 866: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 867: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 868: my $selected = '';
1.128 raeburn 869: if (ref($disallowed{$lonhost}) eq 'HASH') {
870: if ($hostid eq $disallowed{$lonhost}{'server'}) {
871: $selected = 'selected="selected"';
872: }
1.110 raeburn 873: }
874: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
875: $servers{$hostid}.'</option>';
876: }
1.128 raeburn 877: $datatable .= '</select></td>'.
878: '<td><select name="'.$lonhost.'_serverpath">';
879: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
880: my $pathname = $path;
881: if ($path eq 'custom') {
882: $pathname = &mt('Custom Path').' ->';
883: }
884: my $selected = '';
885: if (ref($disallowed{$lonhost}) eq 'HASH') {
886: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
887: $selected = 'selected="selected"';
888: }
889: } elsif ($path eq '') {
890: $selected = 'selected="selected"';
891: }
892: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
893: }
894: $datatable .= '</select></td>';
895: my ($custom,$exempt);
896: if (ref($disallowed{$lonhost}) eq 'HASH') {
897: $custom = $disallowed{$lonhost}{'custompath'};
898: $exempt = $disallowed{$lonhost}{'exempt'};
899: }
900: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
901: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
902: '</tr>';
1.110 raeburn 903: }
904: $datatable .= '</table></td></tr>';
905: return $datatable;
1.160.6.5 raeburn 906: } elsif ($caller eq 'page') {
907: my %defaultchecked = (
908: 'coursecatalog' => 'on',
1.160.6.14 raeburn 909: 'helpdesk' => 'on',
1.160.6.5 raeburn 910: 'adminmail' => 'off',
911: 'newuser' => 'off',
912: );
1.160.6.14 raeburn 913: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 914: my (%checkedon,%checkedoff);
1.42 raeburn 915: foreach my $item (@toggles) {
1.160.6.5 raeburn 916: if ($defaultchecked{$item} eq 'on') {
917: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 918: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 919: } elsif ($defaultchecked{$item} eq 'off') {
920: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 921: $checkedon{$item} = ' ';
922: }
1.1 raeburn 923: }
1.160.6.5 raeburn 924: my @images = ('img','logo','domlogo','login');
925: my @logintext = ('textcol','bgcol');
926: my @bgs = ('pgbg','mainbg','sidebg');
927: my @links = ('link','alink','vlink');
928: my %designhash = &Apache::loncommon::get_domainconf($dom);
929: my %defaultdesign = %Apache::loncommon::defaultdesign;
930: my (%is_custom,%designs);
931: my %defaults = (
932: font => $defaultdesign{'login.font'},
933: );
1.6 raeburn 934: foreach my $item (@images) {
1.160.6.5 raeburn 935: $defaults{$item} = $defaultdesign{'login.'.$item};
936: $defaults{'showlogo'}{$item} = 1;
937: }
938: foreach my $item (@bgs) {
939: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 940: }
1.41 raeburn 941: foreach my $item (@logintext) {
1.160.6.5 raeburn 942: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 943: }
1.160.6.5 raeburn 944: foreach my $item (@links) {
945: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 946: }
1.160.6.5 raeburn 947: if (ref($settings) eq 'HASH') {
948: foreach my $item (@toggles) {
949: if ($settings->{$item} eq '1') {
950: $checkedon{$item} = ' checked="checked" ';
951: $checkedoff{$item} = ' ';
952: } elsif ($settings->{$item} eq '0') {
953: $checkedoff{$item} = ' checked="checked" ';
954: $checkedon{$item} = ' ';
955: }
1.6 raeburn 956: }
1.160.6.5 raeburn 957: foreach my $item (@images) {
958: if (defined($settings->{$item})) {
959: $designs{$item} = $settings->{$item};
960: $is_custom{$item} = 1;
961: }
962: if (defined($settings->{'showlogo'}{$item})) {
963: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
964: }
965: }
966: foreach my $item (@logintext) {
967: if ($settings->{$item} ne '') {
968: $designs{'logintext'}{$item} = $settings->{$item};
969: $is_custom{$item} = 1;
970: }
971: }
972: if ($settings->{'font'} ne '') {
973: $designs{'font'} = $settings->{'font'};
974: $is_custom{'font'} = 1;
975: }
976: foreach my $item (@bgs) {
977: if ($settings->{$item} ne '') {
978: $designs{'bgs'}{$item} = $settings->{$item};
979: $is_custom{$item} = 1;
980: }
981: }
982: foreach my $item (@links) {
983: if ($settings->{$item} ne '') {
984: $designs{'links'}{$item} = $settings->{$item};
985: $is_custom{$item} = 1;
986: }
987: }
988: } else {
989: if ($designhash{$dom.'.login.font'} ne '') {
990: $designs{'font'} = $designhash{$dom.'.login.font'};
991: $is_custom{'font'} = 1;
992: }
993: foreach my $item (@images) {
994: if ($designhash{$dom.'.login.'.$item} ne '') {
995: $designs{$item} = $designhash{$dom.'.login.'.$item};
996: $is_custom{$item} = 1;
997: }
998: }
999: foreach my $item (@bgs) {
1000: if ($designhash{$dom.'.login.'.$item} ne '') {
1001: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1002: $is_custom{$item} = 1;
1003: }
1004: }
1005: foreach my $item (@links) {
1006: if ($designhash{$dom.'.login.'.$item} ne '') {
1007: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1008: $is_custom{$item} = 1;
1009: }
1.6 raeburn 1010: }
1011: }
1.160.6.5 raeburn 1012: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1013: logo => 'Institution Logo',
1014: domlogo => 'Domain Logo',
1015: login => 'Login box');
1016: my $itemcount = 1;
1017: foreach my $item (@toggles) {
1018: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1019: $datatable .=
1020: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1021: '</td><td>'.
1022: '<span class="LC_nobreak"><label><input type="radio" name="'.
1023: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1024: '</label> <label><input type="radio" name="'.$item.'"'.
1025: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1026: '</tr>';
1027: $itemcount ++;
1.6 raeburn 1028: }
1.160.6.5 raeburn 1029: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1030: $datatable .= '</tr></table></td></tr>';
1031: } elsif ($caller eq 'help') {
1032: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1033: my $switchserver = &check_switchserver($dom,$confname);
1034: my $itemcount = 1;
1035: $defaulturl = '/adm/loginproblems.html';
1036: $defaulttype = 'default';
1037: %lt = &Apache::lonlocal::texthash (
1038: del => 'Delete?',
1039: rep => 'Replace:',
1040: upl => 'Upload:',
1041: default => 'Default',
1042: custom => 'Custom',
1043: );
1044: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1045: my @currlangs;
1046: if (ref($settings) eq 'HASH') {
1047: if (ref($settings->{'helpurl'}) eq 'HASH') {
1048: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1049: next if ($settings->{'helpurl'}{$key} eq '');
1050: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1051: $type{$key} = 'custom';
1052: unless ($key eq 'nolang') {
1053: push(@currlangs,$key);
1054: }
1055: }
1056: } elsif ($settings->{'helpurl'} ne '') {
1057: $type{'nolang'} = 'custom';
1058: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1059: }
1060: }
1.160.6.5 raeburn 1061: foreach my $lang ('nolang',sort(@currlangs)) {
1062: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1063: $datatable .= '<tr'.$css_class.'>';
1064: if ($url{$lang} eq '') {
1065: $url{$lang} = $defaulturl;
1066: }
1067: if ($type{$lang} eq '') {
1068: $type{$lang} = $defaulttype;
1069: }
1070: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1071: if ($lang eq 'nolang') {
1072: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1073: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1074: } else {
1075: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1076: $langchoices{$lang},
1077: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1078: }
1079: $datatable .= '</span></td>'."\n".
1080: '<td class="LC_left_item">';
1081: if ($type{$lang} eq 'custom') {
1082: $datatable .= '<span class="LC_nobreak"><label>'.
1083: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1084: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1085: } else {
1086: $datatable .= $lt{'upl'};
1087: }
1088: $datatable .='<br />';
1089: if ($switchserver) {
1090: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1091: } else {
1092: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1093: }
1.160.6.5 raeburn 1094: $datatable .= '</td></tr>';
1095: $itemcount ++;
1.6 raeburn 1096: }
1.160.6.5 raeburn 1097: my @addlangs;
1098: foreach my $lang (sort(keys(%langchoices))) {
1099: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1100: push(@addlangs,$lang);
1101: }
1102: if (@addlangs > 0) {
1103: my %toadd;
1104: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1105: $toadd{''} = &mt('Select');
1106: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1107: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1108: &mt('Add log-in help page for a specific language:').' '.
1109: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1110: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1111: if ($switchserver) {
1112: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1113: } else {
1114: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1115: }
1.160.6.5 raeburn 1116: $datatable .= '</td></tr>';
1117: $itemcount ++;
1.6 raeburn 1118: }
1.160.6.5 raeburn 1119: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1 raeburn 1120: }
1.6 raeburn 1121: return $datatable;
1122: }
1123:
1124: sub login_choices {
1125: my %choices =
1126: &Apache::lonlocal::texthash (
1.116 bisitz 1127: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1128: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1129: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1130: disallowlogin => "Login page requests redirected",
1131: hostid => "Server",
1.128 raeburn 1132: server => "Redirect to:",
1133: serverpath => "Path",
1134: custompath => "Custom",
1135: exempt => "Exempt IP(s)",
1.110 raeburn 1136: directlogin => "No redirect",
1137: newuser => "Link to create a user account",
1138: img => "Header",
1139: logo => "Main Logo",
1140: domlogo => "Domain Logo",
1141: login => "Log-in Header",
1142: textcol => "Text color",
1143: bgcol => "Box color",
1144: bgs => "Background colors",
1145: links => "Link colors",
1146: font => "Font color",
1147: pgbg => "Header",
1148: mainbg => "Page",
1149: sidebg => "Login box",
1150: link => "Link",
1151: alink => "Active link",
1152: vlink => "Visited link",
1.6 raeburn 1153: );
1154: return %choices;
1155: }
1156:
1157: sub print_rolecolors {
1.30 raeburn 1158: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1159: my %choices = &color_font_choices();
1160: my @bgs = ('pgbg','tabbg','sidebg');
1161: my @links = ('link','alink','vlink');
1162: my @images = ('img');
1163: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1164: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1165: my %defaultdesign = %Apache::loncommon::defaultdesign;
1166: my (%is_custom,%designs);
1.160.6.22 raeburn 1167: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1168: if (ref($settings) eq 'HASH') {
1169: if (ref($settings->{$role}) eq 'HASH') {
1170: if ($settings->{$role}->{'img'} ne '') {
1171: $designs{'img'} = $settings->{$role}->{'img'};
1172: $is_custom{'img'} = 1;
1173: }
1174: if ($settings->{$role}->{'font'} ne '') {
1175: $designs{'font'} = $settings->{$role}->{'font'};
1176: $is_custom{'font'} = 1;
1177: }
1.97 tempelho 1178: if ($settings->{$role}->{'fontmenu'} ne '') {
1179: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1180: $is_custom{'fontmenu'} = 1;
1181: }
1.6 raeburn 1182: foreach my $item (@bgs) {
1183: if ($settings->{$role}->{$item} ne '') {
1184: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1185: $is_custom{$item} = 1;
1186: }
1187: }
1188: foreach my $item (@links) {
1189: if ($settings->{$role}->{$item} ne '') {
1190: $designs{'links'}{$item} = $settings->{$role}->{$item};
1191: $is_custom{$item} = 1;
1192: }
1193: }
1194: }
1195: } else {
1196: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1197: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1198: $is_custom{'img'} = 1;
1199: }
1.97 tempelho 1200: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1201: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1202: $is_custom{'fontmenu'} = 1;
1203: }
1.6 raeburn 1204: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1205: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1206: $is_custom{'font'} = 1;
1207: }
1208: foreach my $item (@bgs) {
1209: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1210: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1211: $is_custom{$item} = 1;
1212:
1213: }
1214: }
1215: foreach my $item (@links) {
1216: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1217: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1218: $is_custom{$item} = 1;
1219: }
1220: }
1221: }
1222: my $itemcount = 1;
1.30 raeburn 1223: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1224: $datatable .= '</tr></table></td></tr>';
1225: return $datatable;
1226: }
1227:
1.160.6.22 raeburn 1228: sub role_defaults {
1229: my ($role,$bgs,$links,$images,$logintext) = @_;
1230: my %defaults;
1231: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1232: return %defaults;
1233: }
1234: my %defaultdesign = %Apache::loncommon::defaultdesign;
1235: if ($role eq 'login') {
1236: %defaults = (
1237: font => $defaultdesign{$role.'.font'},
1238: );
1239: if (ref($logintext) eq 'ARRAY') {
1240: foreach my $item (@{$logintext}) {
1241: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1242: }
1243: }
1244: foreach my $item (@{$images}) {
1245: $defaults{'showlogo'}{$item} = 1;
1246: }
1247: } else {
1248: %defaults = (
1249: img => $defaultdesign{$role.'.img'},
1250: font => $defaultdesign{$role.'.font'},
1251: fontmenu => $defaultdesign{$role.'.fontmenu'},
1252: );
1253: }
1254: foreach my $item (@{$bgs}) {
1255: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1256: }
1257: foreach my $item (@{$links}) {
1258: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1259: }
1260: foreach my $item (@{$images}) {
1261: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1262: }
1263: return %defaults;
1264: }
1265:
1.6 raeburn 1266: sub display_color_options {
1.9 raeburn 1267: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1268: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1269: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1270: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1271: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1272: '<td>'.$choices->{'font'}.'</td>';
1273: if (!$is_custom->{'font'}) {
1.30 raeburn 1274: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1275: } else {
1276: $datatable .= '<td> </td>';
1277: }
1.160.6.9 raeburn 1278: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1279:
1.8 raeburn 1280: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1281: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1282: ' value="'.$current_color.'" /> '.
1283: ' </td></tr>';
1.107 raeburn 1284: unless ($role eq 'login') {
1285: $datatable .= '<tr'.$css_class.'>'.
1286: '<td>'.$choices->{'fontmenu'}.'</td>';
1287: if (!$is_custom->{'fontmenu'}) {
1288: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1289: } else {
1290: $datatable .= '<td> </td>';
1291: }
1.160.6.22 raeburn 1292: $current_color = $designs->{'fontmenu'} ?
1293: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1294: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1295: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1296: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1297: ' value="'.$current_color.'" /> '.
1298: ' </td></tr>';
1.97 tempelho 1299: }
1.9 raeburn 1300: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1301: foreach my $img (@{$images}) {
1.18 albertel 1302: $itemcount ++;
1.6 raeburn 1303: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1304: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1305: '<td>'.$choices->{$img};
1.41 raeburn 1306: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1307: if ($role eq 'login') {
1308: if ($img eq 'login') {
1309: $login_hdr_pick =
1.135 bisitz 1310: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1311: $logincolors =
1312: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1313: $designs,$defaults);
1.70 raeburn 1314: } elsif ($img ne 'domlogo') {
1315: $datatable.= &logo_display_options($img,$defaults,$designs);
1316: }
1317: }
1318: $datatable .= '</td>';
1.6 raeburn 1319: if ($designs->{$img} ne '') {
1320: $imgfile = $designs->{$img};
1.18 albertel 1321: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1322: } else {
1323: $imgfile = $defaults->{$img};
1324: }
1325: if ($imgfile) {
1.9 raeburn 1326: my ($showfile,$fullsize);
1327: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1328: my $urldir = $1;
1329: my $filename = $2;
1330: my @info = &Apache::lonnet::stat_file($designs->{$img});
1331: if (@info) {
1332: my $thumbfile = 'tn-'.$filename;
1333: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1334: if (@thumb) {
1335: $showfile = $urldir.'/'.$thumbfile;
1336: } else {
1337: $showfile = $imgfile;
1338: }
1339: } else {
1340: $showfile = '';
1341: }
1342: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1343: $showfile = $imgfile;
1.6 raeburn 1344: my $imgdir = $1;
1345: my $filename = $2;
1.159 raeburn 1346: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1347: $showfile = "/$imgdir/tn-".$filename;
1348: } else {
1.159 raeburn 1349: my $input = $londocroot.$imgfile;
1350: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1351: if (!-e $output) {
1.9 raeburn 1352: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1353: my ($fullwidth,$fullheight) = &check_dimensions($input);
1354: if ($fullwidth ne '' && $fullheight ne '') {
1355: if ($fullwidth > $width && $fullheight > $height) {
1356: my $size = $width.'x'.$height;
1357: system("convert -sample $size $input $output");
1.159 raeburn 1358: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1359: }
1360: }
1.6 raeburn 1361: }
1362: }
1.16 raeburn 1363: }
1.6 raeburn 1364: if ($showfile) {
1.40 raeburn 1365: if ($showfile =~ m{^/(adm|res)/}) {
1366: if ($showfile =~ m{^/res/}) {
1367: my $local_showfile =
1368: &Apache::lonnet::filelocation('',$showfile);
1369: &Apache::lonnet::repcopy($local_showfile);
1370: }
1371: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1372: }
1373: if ($imgfile) {
1374: if ($imgfile =~ m{^/(adm|res)/}) {
1375: if ($imgfile =~ m{^/res/}) {
1376: my $local_imgfile =
1377: &Apache::lonnet::filelocation('',$imgfile);
1378: &Apache::lonnet::repcopy($local_imgfile);
1379: }
1380: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1381: } else {
1382: $fullsize = $imgfile;
1383: }
1384: }
1.41 raeburn 1385: $datatable .= '<td>';
1386: if ($img eq 'login') {
1.135 bisitz 1387: $datatable .= $login_hdr_pick;
1388: }
1.41 raeburn 1389: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1390: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1391: } else {
1.160.6.22 raeburn 1392: $datatable .= '<td> </td><td class="LC_left_item">'.
1393: &mt('Upload:').'<br />';
1.6 raeburn 1394: }
1395: } else {
1.160.6.22 raeburn 1396: $datatable .= '<td> </td><td class="LC_left_item">'.
1397: &mt('Upload:').'<br />';
1.6 raeburn 1398: }
1.9 raeburn 1399: if ($switchserver) {
1400: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1401: } else {
1.135 bisitz 1402: if ($img ne 'login') { # suppress file selection for Log-in header
1403: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1404: }
1.9 raeburn 1405: }
1406: $datatable .= '</td></tr>';
1.6 raeburn 1407: }
1408: $itemcount ++;
1409: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1410: $datatable .= '<tr'.$css_class.'>'.
1411: '<td>'.$choices->{'bgs'}.'</td>';
1412: my $bgs_def;
1413: foreach my $item (@{$bgs}) {
1414: if (!$is_custom->{$item}) {
1.70 raeburn 1415: $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 1416: }
1417: }
1418: if ($bgs_def) {
1.8 raeburn 1419: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1420: } else {
1421: $datatable .= '<td> </td>';
1422: }
1423: $datatable .= '<td class="LC_right_item">'.
1424: '<table border="0"><tr>';
1.160.6.13 raeburn 1425:
1.6 raeburn 1426: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1427: $datatable .= '<td align="center">'.$choices->{$item};
1428: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1429: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1430: $datatable .= ' ';
1.6 raeburn 1431: }
1.160.6.9 raeburn 1432: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1433: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1434: }
1435: $datatable .= '</tr></table></td></tr>';
1436: $itemcount ++;
1437: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1438: $datatable .= '<tr'.$css_class.'>'.
1439: '<td>'.$choices->{'links'}.'</td>';
1440: my $links_def;
1441: foreach my $item (@{$links}) {
1442: if (!$is_custom->{$item}) {
1.30 raeburn 1443: $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 1444: }
1445: }
1446: if ($links_def) {
1.8 raeburn 1447: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1448: } else {
1449: $datatable .= '<td> </td>';
1450: }
1451: $datatable .= '<td class="LC_right_item">'.
1452: '<table border="0"><tr>';
1453: foreach my $item (@{$links}) {
1.160.6.22 raeburn 1454: my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
1455: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1456: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1457: $datatable.=' ';
1.6 raeburn 1458: }
1.160.6.9 raeburn 1459: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1460: '" /></td>';
1461: }
1.30 raeburn 1462: $$rowtotal += $itemcount;
1.3 raeburn 1463: return $datatable;
1464: }
1465:
1.70 raeburn 1466: sub logo_display_options {
1467: my ($img,$defaults,$designs) = @_;
1468: my $checkedon;
1469: if (ref($defaults) eq 'HASH') {
1470: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1471: if ($defaults->{'showlogo'}{$img}) {
1472: $checkedon = 'checked="checked" ';
1473: }
1474: }
1475: }
1476: if (ref($designs) eq 'HASH') {
1477: if (ref($designs->{'showlogo'}) eq 'HASH') {
1478: if (defined($designs->{'showlogo'}{$img})) {
1479: if ($designs->{'showlogo'}{$img} == 0) {
1480: $checkedon = '';
1481: } elsif ($designs->{'showlogo'}{$img} == 1) {
1482: $checkedon = 'checked="checked" ';
1483: }
1484: }
1485: }
1486: }
1487: return '<br /><label> <input type="checkbox" name="'.
1488: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1489: &mt('show').'</label>'."\n";
1490: }
1491:
1.41 raeburn 1492: sub login_header_options {
1.135 bisitz 1493: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1494: my $output = '';
1.41 raeburn 1495: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1496: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1497: if (!$is_custom->{'textcol'}) {
1498: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1499: ' ';
1500: }
1501: if (!$is_custom->{'bgcol'}) {
1502: $output .= $choices->{'bgcol'}.': '.
1503: '<span id="css_'.$role.'_font" style="background-color: '.
1504: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1505: }
1506: $output .= '<br />';
1507: }
1508: $output .='<br />';
1509: return $output;
1510: }
1511:
1512: sub login_text_colors {
1.160.6.22 raeburn 1513: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1514: my $color_menu = '<table border="0"><tr>';
1515: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 1516: $color_menu .= '<td align="center">'.$choices->{$item};
1517: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1518: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1519: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1520: }
1521: $color_menu .= '</tr></table><br />';
1522: return $color_menu;
1523: }
1524:
1525: sub image_changes {
1526: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1527: my $output;
1.135 bisitz 1528: if ($img eq 'login') {
1529: # suppress image for Log-in header
1530: } elsif (!$is_custom) {
1.70 raeburn 1531: if ($img ne 'domlogo') {
1.41 raeburn 1532: $output .= &mt('Default image:').'<br />';
1533: } else {
1534: $output .= &mt('Default in use:').'<br />';
1535: }
1536: }
1.135 bisitz 1537: if ($img eq 'login') { # suppress image for Log-in header
1538: $output .= '<td>'.$logincolors;
1.41 raeburn 1539: } else {
1.135 bisitz 1540: if ($img_import) {
1541: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1542: }
1543: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1544: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1545: if ($is_custom) {
1546: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1547: '<input type="checkbox" name="'.
1548: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1549: '</label> '.&mt('Replace:').'</span><br />';
1550: } else {
1.160.6.22 raeburn 1551: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1552: }
1.41 raeburn 1553: }
1554: return $output;
1555: }
1556:
1.3 raeburn 1557: sub print_quotas {
1.86 raeburn 1558: my ($dom,$settings,$rowtotal,$action) = @_;
1559: my $context;
1560: if ($action eq 'quotas') {
1561: $context = 'tools';
1562: } else {
1563: $context = $action;
1564: }
1.160.6.20 raeburn 1565: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1566: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1567: my $typecount = 0;
1.101 raeburn 1568: my ($css_class,%titles);
1.86 raeburn 1569: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 1570: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1571: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1572: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1573: %titles = &courserequest_titles();
1.160.6.5 raeburn 1574: } elsif ($context eq 'requestauthor') {
1575: @usertools = ('author');
1576: @options = ('norequest','approval','automatic');
1577: %titles = &authorrequest_titles();
1.86 raeburn 1578: } else {
1.160.6.4 raeburn 1579: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1580: %titles = &tool_titles();
1.86 raeburn 1581: }
1.26 raeburn 1582: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1583: foreach my $type (@{$types}) {
1.160.6.20 raeburn 1584: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 1585: unless (($context eq 'requestcourses') ||
1586: ($context eq 'requestauthor')) {
1.86 raeburn 1587: if (ref($settings) eq 'HASH') {
1588: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 1589: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1590: } else {
1591: $currdefquota = $settings->{$type};
1592: }
1.160.6.20 raeburn 1593: if (ref($settings->{authorquota}) eq 'HASH') {
1594: $currauthorquota = $settings->{authorquota}->{$type};
1595: }
1.78 raeburn 1596: }
1.72 raeburn 1597: }
1.3 raeburn 1598: if (defined($usertypes->{$type})) {
1599: $typecount ++;
1600: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1601: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1602: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1603: '<td class="LC_left_item">';
1.101 raeburn 1604: if ($context eq 'requestcourses') {
1605: $datatable .= '<table><tr>';
1606: }
1607: my %cell;
1.72 raeburn 1608: foreach my $item (@usertools) {
1.101 raeburn 1609: if ($context eq 'requestcourses') {
1610: my ($curroption,$currlimit);
1611: if (ref($settings) eq 'HASH') {
1612: if (ref($settings->{$item}) eq 'HASH') {
1613: $curroption = $settings->{$item}->{$type};
1614: if ($curroption =~ /^autolimit=(\d*)$/) {
1615: $currlimit = $1;
1616: }
1617: }
1618: }
1619: if (!$curroption) {
1620: $curroption = 'norequest';
1621: }
1622: $datatable .= '<th>'.$titles{$item}.'</th>';
1623: foreach my $option (@options) {
1624: my $val = $option;
1625: if ($option eq 'norequest') {
1626: $val = 0;
1627: }
1628: if ($option eq 'validate') {
1629: my $canvalidate = 0;
1630: if (ref($validations{$item}) eq 'HASH') {
1631: if ($validations{$item}{$type}) {
1632: $canvalidate = 1;
1633: }
1634: }
1635: next if (!$canvalidate);
1636: }
1637: my $checked = '';
1638: if ($option eq $curroption) {
1639: $checked = ' checked="checked"';
1640: } elsif ($option eq 'autolimit') {
1641: if ($curroption =~ /^autolimit/) {
1642: $checked = ' checked="checked"';
1643: }
1644: }
1645: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1646: '<input type="radio" name="crsreq_'.$item.
1647: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1648: $titles{$option}.'</label>';
1.101 raeburn 1649: if ($option eq 'autolimit') {
1.127 raeburn 1650: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1651: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1652: 'value="'.$currlimit.'" />';
1.101 raeburn 1653: }
1.127 raeburn 1654: $cell{$item} .= '</span> ';
1.103 raeburn 1655: if ($option eq 'autolimit') {
1.127 raeburn 1656: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1657: }
1.101 raeburn 1658: }
1.160.6.5 raeburn 1659: } elsif ($context eq 'requestauthor') {
1660: my $curroption;
1661: if (ref($settings) eq 'HASH') {
1662: $curroption = $settings->{$type};
1663: }
1664: if (!$curroption) {
1665: $curroption = 'norequest';
1666: }
1667: foreach my $option (@options) {
1668: my $val = $option;
1669: if ($option eq 'norequest') {
1670: $val = 0;
1671: }
1672: my $checked = '';
1673: if ($option eq $curroption) {
1674: $checked = ' checked="checked"';
1675: }
1676: $datatable .= '<span class="LC_nobreak"><label>'.
1677: '<input type="radio" name="authorreq_'.$type.
1678: '" value="'.$val.'"'.$checked.' />'.
1679: $titles{$option}.'</label></span> ';
1680: }
1.101 raeburn 1681: } else {
1682: my $checked = 'checked="checked" ';
1683: if (ref($settings) eq 'HASH') {
1684: if (ref($settings->{$item}) eq 'HASH') {
1685: if ($settings->{$item}->{$type} == 0) {
1686: $checked = '';
1687: } elsif ($settings->{$item}->{$type} == 1) {
1688: $checked = 'checked="checked" ';
1689: }
1.78 raeburn 1690: }
1.72 raeburn 1691: }
1.101 raeburn 1692: $datatable .= '<span class="LC_nobreak"><label>'.
1693: '<input type="checkbox" name="'.$context.'_'.$item.
1694: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1695: '</label></span> ';
1.72 raeburn 1696: }
1.101 raeburn 1697: }
1698: if ($context eq 'requestcourses') {
1699: $datatable .= '</tr><tr>';
1700: foreach my $item (@usertools) {
1.106 raeburn 1701: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1702: }
1703: $datatable .= '</tr></table>';
1.72 raeburn 1704: }
1.86 raeburn 1705: $datatable .= '</td>';
1.160.6.5 raeburn 1706: unless (($context eq 'requestcourses') ||
1707: ($context eq 'requestauthor')) {
1.86 raeburn 1708: $datatable .=
1.160.6.20 raeburn 1709: '<td class="LC_right_item">'.
1710: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1711: '<input type="text" name="quota_'.$type.
1.72 raeburn 1712: '" value="'.$currdefquota.
1.160.6.20 raeburn 1713: '" size="5" /></span>'.(' ' x 2).
1714: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1715: '<input type="text" name="authorquota_'.$type.
1716: '" value="'.$currauthorquota.
1717: '" size="5" /></span></td>';
1.86 raeburn 1718: }
1719: $datatable .= '</tr>';
1.3 raeburn 1720: }
1721: }
1722: }
1.160.6.5 raeburn 1723: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1724: $defaultquota = '20';
1.160.6.20 raeburn 1725: $authorquota = '500';
1.86 raeburn 1726: if (ref($settings) eq 'HASH') {
1727: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1728: $defaultquota = $settings->{'defaultquota'}->{'default'};
1729: } elsif (defined($settings->{'default'})) {
1730: $defaultquota = $settings->{'default'};
1731: }
1.160.6.20 raeburn 1732: if (ref($settings->{'authorquota'}) eq 'HASH') {
1733: $authorquota = $settings->{'authorquota'}->{'default'};
1734: }
1.3 raeburn 1735: }
1736: }
1737: $typecount ++;
1738: $css_class = $typecount%2?' class="LC_odd_row"':'';
1739: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1740: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1741: '<td class="LC_left_item">';
1.101 raeburn 1742: if ($context eq 'requestcourses') {
1743: $datatable .= '<table><tr>';
1744: }
1745: my %defcell;
1.72 raeburn 1746: foreach my $item (@usertools) {
1.101 raeburn 1747: if ($context eq 'requestcourses') {
1748: my ($curroption,$currlimit);
1749: if (ref($settings) eq 'HASH') {
1750: if (ref($settings->{$item}) eq 'HASH') {
1751: $curroption = $settings->{$item}->{'default'};
1752: if ($curroption =~ /^autolimit=(\d*)$/) {
1753: $currlimit = $1;
1754: }
1755: }
1756: }
1757: if (!$curroption) {
1758: $curroption = 'norequest';
1759: }
1760: $datatable .= '<th>'.$titles{$item}.'</th>';
1761: foreach my $option (@options) {
1762: my $val = $option;
1763: if ($option eq 'norequest') {
1764: $val = 0;
1765: }
1766: if ($option eq 'validate') {
1767: my $canvalidate = 0;
1768: if (ref($validations{$item}) eq 'HASH') {
1769: if ($validations{$item}{'default'}) {
1770: $canvalidate = 1;
1771: }
1772: }
1773: next if (!$canvalidate);
1774: }
1775: my $checked = '';
1776: if ($option eq $curroption) {
1777: $checked = ' checked="checked"';
1778: } elsif ($option eq 'autolimit') {
1779: if ($curroption =~ /^autolimit/) {
1780: $checked = ' checked="checked"';
1781: }
1782: }
1783: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1784: '<input type="radio" name="crsreq_'.$item.
1785: '_default" value="'.$val.'"'.$checked.' />'.
1786: $titles{$option}.'</label>';
1787: if ($option eq 'autolimit') {
1.127 raeburn 1788: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1789: $item.'_limit_default" size="1" '.
1790: 'value="'.$currlimit.'" />';
1791: }
1.127 raeburn 1792: $defcell{$item} .= '</span> ';
1.104 raeburn 1793: if ($option eq 'autolimit') {
1.127 raeburn 1794: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1795: }
1.101 raeburn 1796: }
1.160.6.5 raeburn 1797: } elsif ($context eq 'requestauthor') {
1798: my $curroption;
1799: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 1800: $curroption = $settings->{'default'};
1.160.6.5 raeburn 1801: }
1802: if (!$curroption) {
1803: $curroption = 'norequest';
1804: }
1805: foreach my $option (@options) {
1806: my $val = $option;
1807: if ($option eq 'norequest') {
1808: $val = 0;
1809: }
1810: my $checked = '';
1811: if ($option eq $curroption) {
1812: $checked = ' checked="checked"';
1813: }
1814: $datatable .= '<span class="LC_nobreak"><label>'.
1815: '<input type="radio" name="authorreq_default"'.
1816: ' value="'.$val.'"'.$checked.' />'.
1817: $titles{$option}.'</label></span> ';
1818: }
1.101 raeburn 1819: } else {
1820: my $checked = 'checked="checked" ';
1821: if (ref($settings) eq 'HASH') {
1822: if (ref($settings->{$item}) eq 'HASH') {
1823: if ($settings->{$item}->{'default'} == 0) {
1824: $checked = '';
1825: } elsif ($settings->{$item}->{'default'} == 1) {
1826: $checked = 'checked="checked" ';
1827: }
1.78 raeburn 1828: }
1.72 raeburn 1829: }
1.101 raeburn 1830: $datatable .= '<span class="LC_nobreak"><label>'.
1831: '<input type="checkbox" name="'.$context.'_'.$item.
1832: '" value="default" '.$checked.'/>'.$titles{$item}.
1833: '</label></span> ';
1834: }
1835: }
1836: if ($context eq 'requestcourses') {
1837: $datatable .= '</tr><tr>';
1838: foreach my $item (@usertools) {
1.106 raeburn 1839: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1840: }
1.101 raeburn 1841: $datatable .= '</tr></table>';
1.72 raeburn 1842: }
1.86 raeburn 1843: $datatable .= '</td>';
1.160.6.5 raeburn 1844: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 1845: $datatable .= '<td class="LC_right_item">'.
1846: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 1847: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 1848: $defaultquota.'" size="5" /></span>'.(' ' x2).
1849: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1850: '<input type="text" name="authorquota" value="'.
1851: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 1852: }
1853: $datatable .= '</tr>';
1.72 raeburn 1854: $typecount ++;
1855: $css_class = $typecount%2?' class="LC_odd_row"':'';
1856: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 1857: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 1858: if ($context eq 'requestcourses') {
1.109 raeburn 1859: $datatable .= &mt('(overrides affiliation, if set)').
1860: '</td>'.
1861: '<td class="LC_left_item">'.
1862: '<table><tr>';
1.101 raeburn 1863: } else {
1.109 raeburn 1864: $datatable .= &mt('(overrides affiliation, if checked)').
1865: '</td>'.
1866: '<td class="LC_left_item" colspan="2">'.
1867: '<br />';
1.101 raeburn 1868: }
1869: my %advcell;
1.72 raeburn 1870: foreach my $item (@usertools) {
1.101 raeburn 1871: if ($context eq 'requestcourses') {
1872: my ($curroption,$currlimit);
1873: if (ref($settings) eq 'HASH') {
1874: if (ref($settings->{$item}) eq 'HASH') {
1875: $curroption = $settings->{$item}->{'_LC_adv'};
1876: if ($curroption =~ /^autolimit=(\d*)$/) {
1877: $currlimit = $1;
1878: }
1879: }
1880: }
1881: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1882: my $checked = '';
1883: if ($curroption eq '') {
1884: $checked = ' checked="checked"';
1885: }
1886: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1887: '<input type="radio" name="crsreq_'.$item.
1888: '__LC_adv" value=""'.$checked.' />'.
1889: &mt('No override set').'</label></span> ';
1.101 raeburn 1890: foreach my $option (@options) {
1891: my $val = $option;
1892: if ($option eq 'norequest') {
1893: $val = 0;
1894: }
1895: if ($option eq 'validate') {
1896: my $canvalidate = 0;
1897: if (ref($validations{$item}) eq 'HASH') {
1898: if ($validations{$item}{'_LC_adv'}) {
1899: $canvalidate = 1;
1900: }
1901: }
1902: next if (!$canvalidate);
1903: }
1904: my $checked = '';
1.104 raeburn 1905: if ($val eq $curroption) {
1.101 raeburn 1906: $checked = ' checked="checked"';
1907: } elsif ($option eq 'autolimit') {
1908: if ($curroption =~ /^autolimit/) {
1909: $checked = ' checked="checked"';
1910: }
1911: }
1912: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1913: '<input type="radio" name="crsreq_'.$item.
1914: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1915: $titles{$option}.'</label>';
1916: if ($option eq 'autolimit') {
1.127 raeburn 1917: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1918: $item.'_limit__LC_adv" size="1" '.
1919: 'value="'.$currlimit.'" />';
1920: }
1.127 raeburn 1921: $advcell{$item} .= '</span> ';
1.104 raeburn 1922: if ($option eq 'autolimit') {
1.127 raeburn 1923: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1924: }
1.101 raeburn 1925: }
1.160.6.5 raeburn 1926: } elsif ($context eq 'requestauthor') {
1927: my $curroption;
1928: if (ref($settings) eq 'HASH') {
1929: $curroption = $settings->{'_LC_adv'};
1930: }
1931: my $checked = '';
1932: if ($curroption eq '') {
1933: $checked = ' checked="checked"';
1934: }
1935: $datatable .= '<span class="LC_nobreak"><label>'.
1936: '<input type="radio" name="authorreq__LC_adv"'.
1937: ' value=""'.$checked.' />'.
1938: &mt('No override set').'</label></span> ';
1939: foreach my $option (@options) {
1940: my $val = $option;
1941: if ($option eq 'norequest') {
1942: $val = 0;
1943: }
1944: my $checked = '';
1945: if ($val eq $curroption) {
1946: $checked = ' checked="checked"';
1947: }
1948: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 1949: '<input type="radio" name="authorreq__LC_adv"'.
1950: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 1951: $titles{$option}.'</label></span> ';
1952: }
1.101 raeburn 1953: } else {
1954: my $checked = 'checked="checked" ';
1955: if (ref($settings) eq 'HASH') {
1956: if (ref($settings->{$item}) eq 'HASH') {
1957: if ($settings->{$item}->{'_LC_adv'} == 0) {
1958: $checked = '';
1959: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1960: $checked = 'checked="checked" ';
1961: }
1.79 raeburn 1962: }
1.72 raeburn 1963: }
1.101 raeburn 1964: $datatable .= '<span class="LC_nobreak"><label>'.
1965: '<input type="checkbox" name="'.$context.'_'.$item.
1966: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1967: '</label></span> ';
1968: }
1969: }
1970: if ($context eq 'requestcourses') {
1971: $datatable .= '</tr><tr>';
1972: foreach my $item (@usertools) {
1.106 raeburn 1973: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1974: }
1.101 raeburn 1975: $datatable .= '</tr></table>';
1.72 raeburn 1976: }
1.98 raeburn 1977: $datatable .= '</td></tr>';
1.30 raeburn 1978: $$rowtotal += $typecount;
1.3 raeburn 1979: return $datatable;
1980: }
1981:
1.160.6.5 raeburn 1982: sub print_requestmail {
1983: my ($dom,$action,$settings,$rowtotal) = @_;
1.160.6.25 raeburn 1984: my ($now,$datatable,%currapp);
1.102 raeburn 1985: $now = time;
1986: if (ref($settings) eq 'HASH') {
1987: if (ref($settings->{'notify'}) eq 'HASH') {
1988: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34! raeburn 1989: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 1990: }
1991: }
1992: }
1.160.6.16 raeburn 1993: my $numinrow = 2;
1.160.6.34! raeburn 1994: my $css_class;
! 1995: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.160.6.5 raeburn 1996: my $text;
1997: if ($action eq 'requestcourses') {
1998: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34! raeburn 1999: } elsif ($action eq 'requestauthor') {
! 2000: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2001: } else {
1.160.6.34! raeburn 2002: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2003: }
1.160.6.34! raeburn 2004: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2005: ' <td>'.$text.'</td>'.
1.102 raeburn 2006: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2007: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34! raeburn 2008: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2009: if ($numdc > 0) {
2010: $datatable .= $table;
1.102 raeburn 2011: } else {
2012: $datatable .= &mt('There are no active Domain Coordinators');
2013: }
2014: $datatable .='</td></tr>';
2015: $$rowtotal += $rows;
2016: return $datatable;
2017: }
2018:
1.160.6.30 raeburn 2019: sub print_studentcode {
2020: my ($settings,$rowtotal) = @_;
2021: my $rownum = 0;
2022: my ($output,%current);
2023: my @crstypes = ('official','unofficial','community','textbook');
2024: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2025: foreach my $type (@crstypes) {
2026: $current{$type} = $settings->{'uniquecode'}{$type};
2027: }
2028: }
2029: $output .= '<tr>'.
2030: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2031: '<td class="LC_left_item">';
2032: foreach my $type (@crstypes) {
2033: my $check = ' ';
2034: if ($current{$type}) {
2035: $check = ' checked="checked" ';
2036: }
2037: $output .= '<span class="LC_nobreak"><label>'.
2038: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2039: &mt($type).'</label></span>'.(' 'x2).' ';
2040: }
2041: $output .= '</td></tr>';
2042: $$rowtotal ++;
2043: return $output;
2044: }
2045:
2046: sub print_textbookcourses {
2047: my ($dom,$settings,$rowtotal) = @_;
2048: my $rownum = 0;
2049: my $css_class;
2050: my $itemcount = 1;
2051: my $maxnum = 0;
2052: my $bookshash;
2053: if (ref($settings) eq 'HASH') {
2054: $bookshash = $settings->{'textbooks'};
2055: }
2056: my %ordered;
2057: if (ref($bookshash) eq 'HASH') {
2058: foreach my $item (keys(%{$bookshash})) {
2059: if (ref($bookshash->{$item}) eq 'HASH') {
2060: my $num = $bookshash->{$item}{'order'};
2061: $ordered{$num} = $item;
2062: }
2063: }
2064: }
2065: my $confname = $dom.'-domainconfig';
2066: my $switchserver = &check_switchserver($dom,$confname);
2067: my $maxnum = scalar(keys(%ordered));
2068: my $datatable = &textbookcourses_javascript(\%ordered);
2069: if (keys(%ordered)) {
2070: my @items = sort { $a <=> $b } keys(%ordered);
2071: for (my $i=0; $i<@items; $i++) {
2072: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2073: my $key = $ordered{$items[$i]};
2074: my %coursehash=&Apache::lonnet::coursedescription($key);
2075: my $coursetitle = $coursehash{'description'};
2076: my ($subject,$title,$author,$image,$imgsrc,$cdom,$cnum);
2077: if (ref($bookshash->{$key}) eq 'HASH') {
2078: $subject = $bookshash->{$key}->{'subject'};
2079: $title = $bookshash->{$key}->{'title'};
2080: $author = $bookshash->{$key}->{'author'};
2081: $image = $bookshash->{$key}->{'image'};
2082: if ($image ne '') {
2083: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2084: my $imagethumb = "$path/tn-".$imagefile;
2085: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2086: }
2087: }
2088: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$key'".');"';
2089: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
2090: .'<select name="'.$key.'"'.$chgstr.'>';
2091: for (my $k=0; $k<=$maxnum; $k++) {
2092: my $vpos = $k+1;
2093: my $selstr;
2094: if ($k == $i) {
2095: $selstr = ' selected="selected" ';
2096: }
2097: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2098: }
2099: $datatable .= '</select>'.(' 'x2).
2100: '<label><input type="checkbox" name="book_del" value="'.$key.'" />'.
2101: &mt('Delete?').'</label></span></td>'.
2102: '<td colspan="2">'.
2103: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="book_subject_'.$i.'" value="'.$subject.'" /></span> '.
2104: (' 'x2).
2105: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="book_title_'.$i.'" value="'.$title.'" /></span> '.
2106: (' 'x2).
2107: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="book_author_'.$i.'" value="'.$author.'" /></span> '.
2108: (' 'x2).
2109: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2110: if ($image) {
2111: $datatable .= '<span class="LC_nobreak">'.
2112: $imgsrc.
2113: '<label><input type="checkbox" name="book_image_del"'.
2114: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2115: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2116: }
2117: if ($switchserver) {
2118: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2119: } else {
2120: $datatable .= '<input type="file" name="book_image_'.$i.'" value="" />';
2121: }
2122: $datatable .= '<input type="hidden" name="book_id_'.$i.'" value="'.$key.'" /></span> '.
2123: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2124: $coursetitle.'</span></td></tr>'."\n";
2125: $itemcount ++;
2126: }
2127: }
2128: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2129: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'addbook_pos'".');"';
2130: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
2131: '<input type="hidden" name="book_maxnum" value="'.$maxnum.'" />'."\n".
2132: '<select name="addbook_pos"'.$chgstr.'>';
2133: for (my $k=0; $k<$maxnum+1; $k++) {
2134: my $vpos = $k+1;
2135: my $selstr;
2136: if ($k == $maxnum) {
2137: $selstr = ' selected="selected" ';
2138: }
2139: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2140: }
2141: $datatable .= '</select> '."\n".
2142: '<input type="checkbox" name="addbook" value="1" />'.&mt('Add').'</td>'."\n".
2143: '<td colspan="2">'.
2144: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="addbook_subject" value="" /></span> '."\n".
2145: (' 'x2).
2146: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="addbook_title" value="" /></span> '."\n".
2147: (' 'x2).
2148: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="addbook_author" value="" /></span> '."\n".
2149: (' 'x2).
2150: '<span class="LC_nobreak">'.&mt('Image:').' ';
2151: if ($switchserver) {
2152: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2153: } else {
2154: $datatable .= '<input type="file" name="addbook_image" value="" />';
2155: }
2156: $datatable .= '</span>'."\n".
2157: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2158: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'addbook_cdom').
2159: '<input type="text" size="25" name="addbook_cnum" value="" />'.
2160: &Apache::loncommon::selectcourse_link
2161: ('display','addbook_cnum','addbook_cdom',undef,undef,undef,'Course');
2162: '</span></td>'."\n".
2163: '</tr>'."\n";
2164: $itemcount ++;
2165: return $datatable;
2166: }
2167:
2168: sub textbookcourses_javascript {
2169: my ($textbooks) = @_;
2170: return unless(ref($textbooks) eq 'HASH');
2171: my $num = scalar(keys(%{$textbooks}));
2172: my @jsarray;
2173: foreach my $item (sort {$a <=> $b } (keys(%{$textbooks}))) {
2174: push(@jsarray,$textbooks->{$item});
2175: }
2176: my $jstext = ' var textbooks = Array('."'".join("','",@jsarray)."'".');'."\n";
2177: return <<"ENDSCRIPT";
2178: <script type="text/javascript">
2179: // <![CDATA[
2180: function reorderBooks(form,item) {
2181: var changedVal;
2182: $jstext
2183: var newpos = 'addbook_pos';
2184: var current = new Array;
2185: var maxh = 1 + $num;
2186: var current = new Array;
2187: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2188: if (item == newpos) {
2189: changedVal = newitemVal;
2190: } else {
2191: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2192: current[newitemVal] = newpos;
2193: }
2194: for (var i=0; i<textbooks.length; i++) {
2195: var elementName = textbooks[i];
2196: if (elementName != item) {
2197: if (form.elements[elementName]) {
2198: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2199: current[currVal] = elementName;
2200: }
2201: }
2202: }
2203: var oldVal;
2204: for (var j=0; j<maxh; j++) {
2205: if (current[j] == undefined) {
2206: oldVal = j;
2207: }
2208: }
2209: if (oldVal < changedVal) {
2210: for (var k=oldVal+1; k<=changedVal ; k++) {
2211: var elementName = current[k];
2212: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2213: }
2214: } else {
2215: for (var k=changedVal; k<oldVal; k++) {
2216: var elementName = current[k];
2217: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2218: }
2219: }
2220: return;
2221: }
2222:
2223: // ]]>
2224: </script>
2225:
2226: ENDSCRIPT
2227: }
2228:
1.3 raeburn 2229: sub print_autoenroll {
1.30 raeburn 2230: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2231: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 2232: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 2233: if (ref($settings) eq 'HASH') {
2234: if (exists($settings->{'run'})) {
2235: if ($settings->{'run'} eq '0') {
2236: $runoff = ' checked="checked" ';
2237: $runon = ' ';
2238: } else {
2239: $runon = ' checked="checked" ';
2240: $runoff = ' ';
2241: }
2242: } else {
2243: if ($autorun) {
2244: $runon = ' checked="checked" ';
2245: $runoff = ' ';
2246: } else {
2247: $runoff = ' checked="checked" ';
2248: $runon = ' ';
2249: }
2250: }
1.129 raeburn 2251: if (exists($settings->{'co-owners'})) {
2252: if ($settings->{'co-owners'} eq '0') {
2253: $coownersoff = ' checked="checked" ';
2254: $coownerson = ' ';
2255: } else {
2256: $coownerson = ' checked="checked" ';
2257: $coownersoff = ' ';
2258: }
2259: } else {
2260: $coownersoff = ' checked="checked" ';
2261: $coownerson = ' ';
2262: }
1.3 raeburn 2263: if (exists($settings->{'sender_domain'})) {
2264: $defdom = $settings->{'sender_domain'};
2265: }
1.14 raeburn 2266: } else {
2267: if ($autorun) {
2268: $runon = ' checked="checked" ';
2269: $runoff = ' ';
2270: } else {
2271: $runoff = ' checked="checked" ';
2272: $runon = ' ';
2273: }
1.3 raeburn 2274: }
2275: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2276: my $notif_sender;
2277: if (ref($settings) eq 'HASH') {
2278: $notif_sender = $settings->{'sender_uname'};
2279: }
1.3 raeburn 2280: my $datatable='<tr class="LC_odd_row">'.
2281: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2282: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2283: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2284: $runon.' value="1" />'.&mt('Yes').'</label> '.
2285: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2286: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2287: '</tr><tr>'.
2288: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2289: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2290: &mt('username').': '.
2291: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2292: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2293: ': '.$domform.'</span></td></tr>'.
2294: '<tr class="LC_odd_row">'.
2295: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2296: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2297: '<input type="radio" name="autoassign_coowners"'.
2298: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2299: '<label><input type="radio" name="autoassign_coowners"'.
2300: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2301: '</tr>';
2302: $$rowtotal += 3;
1.3 raeburn 2303: return $datatable;
2304: }
2305:
2306: sub print_autoupdate {
1.30 raeburn 2307: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2308: my $datatable;
2309: if ($position eq 'top') {
2310: my $updateon = ' ';
2311: my $updateoff = ' checked="checked" ';
2312: my $classlistson = ' ';
2313: my $classlistsoff = ' checked="checked" ';
2314: if (ref($settings) eq 'HASH') {
2315: if ($settings->{'run'} eq '1') {
2316: $updateon = $updateoff;
2317: $updateoff = ' ';
2318: }
2319: if ($settings->{'classlists'} eq '1') {
2320: $classlistson = $classlistsoff;
2321: $classlistsoff = ' ';
2322: }
2323: }
2324: my %title = (
2325: run => 'Auto-update active?',
2326: classlists => 'Update information in classlists?',
2327: );
2328: $datatable = '<tr class="LC_odd_row">'.
2329: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2330: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2331: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2332: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2333: '<label><input type="radio" name="autoupdate_run"'.
2334: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2335: '</tr><tr>'.
2336: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2337: '<td class="LC_right_item"><span class="LC_nobreak">'.
2338: '<label><input type="radio" name="classlists"'.
2339: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2340: '<label><input type="radio" name="classlists"'.
2341: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2342: '</tr>';
1.30 raeburn 2343: $$rowtotal += 2;
1.131 raeburn 2344: } elsif ($position eq 'middle') {
2345: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2346: my $numinrow = 3;
2347: my $locknamesettings;
2348: $datatable .= &insttypes_row($settings,$types,$usertypes,
2349: $dom,$numinrow,$othertitle,
2350: 'lockablenames');
2351: $$rowtotal ++;
1.3 raeburn 2352: } else {
1.44 raeburn 2353: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2354: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2355: 'permanentemail','id');
1.33 raeburn 2356: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2357: my $numrows = 0;
1.26 raeburn 2358: if (ref($types) eq 'ARRAY') {
2359: if (@{$types} > 0) {
2360: $datatable =
2361: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2362: \@fields,$types,\$numrows);
1.30 raeburn 2363: $$rowtotal += @{$types};
1.26 raeburn 2364: }
1.3 raeburn 2365: }
2366: $datatable .=
2367: &usertype_update_row($settings,{'default' => $othertitle},
2368: \%fieldtitles,\@fields,['default'],
2369: \$numrows);
1.30 raeburn 2370: $$rowtotal ++;
1.3 raeburn 2371: }
2372: return $datatable;
2373: }
2374:
1.125 raeburn 2375: sub print_autocreate {
2376: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2377: my (%createon,%createoff,%currhash);
1.125 raeburn 2378: my @types = ('xml','req');
2379: if (ref($settings) eq 'HASH') {
2380: foreach my $item (@types) {
2381: $createoff{$item} = ' checked="checked" ';
2382: $createon{$item} = ' ';
2383: if (exists($settings->{$item})) {
2384: if ($settings->{$item}) {
2385: $createon{$item} = ' checked="checked" ';
2386: $createoff{$item} = ' ';
2387: }
2388: }
2389: }
1.160.6.16 raeburn 2390: if ($settings->{'xmldc'} ne '') {
2391: $currhash{$settings->{'xmldc'}} = 1;
2392: }
1.125 raeburn 2393: } else {
2394: foreach my $item (@types) {
2395: $createoff{$item} = ' checked="checked" ';
2396: $createon{$item} = ' ';
2397: }
2398: }
2399: $$rowtotal += 2;
1.160.6.16 raeburn 2400: my $numinrow = 2;
1.125 raeburn 2401: my $datatable='<tr class="LC_odd_row">'.
2402: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2403: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2404: '<input type="radio" name="autocreate_xml"'.
2405: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2406: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2407: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2408: '</td></tr><tr>'.
2409: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2410: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2411: '<input type="radio" name="autocreate_req"'.
2412: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2413: '<label><input type="radio" name="autocreate_req"'.
2414: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 2415: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2416: 'autocreate_xmldc',%currhash);
1.125 raeburn 2417: if ($numdc > 1) {
1.143 raeburn 2418: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2419: &mt('Course creation processed as: (choose Dom. Coord.)').
2420: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2421: } else {
1.143 raeburn 2422: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2423: }
1.160.6.16 raeburn 2424: $$rowtotal += $rows;
1.125 raeburn 2425: return $datatable;
2426: }
2427:
1.23 raeburn 2428: sub print_directorysrch {
1.30 raeburn 2429: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2430: my $srchon = ' ';
2431: my $srchoff = ' checked="checked" ';
1.25 raeburn 2432: my ($exacton,$containson,$beginson);
1.24 raeburn 2433: my $localon = ' ';
2434: my $localoff = ' checked="checked" ';
1.23 raeburn 2435: if (ref($settings) eq 'HASH') {
2436: if ($settings->{'available'} eq '1') {
2437: $srchon = $srchoff;
2438: $srchoff = ' ';
2439: }
1.24 raeburn 2440: if ($settings->{'localonly'} eq '1') {
2441: $localon = $localoff;
2442: $localoff = ' ';
2443: }
1.25 raeburn 2444: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2445: foreach my $type (@{$settings->{'searchtypes'}}) {
2446: if ($type eq 'exact') {
2447: $exacton = ' checked="checked" ';
2448: } elsif ($type eq 'contains') {
2449: $containson = ' checked="checked" ';
2450: } elsif ($type eq 'begins') {
2451: $beginson = ' checked="checked" ';
2452: }
2453: }
2454: } else {
2455: if ($settings->{'searchtypes'} eq 'exact') {
2456: $exacton = ' checked="checked" ';
2457: } elsif ($settings->{'searchtypes'} eq 'contains') {
2458: $containson = ' checked="checked" ';
2459: } elsif ($settings->{'searchtypes'} eq 'specify') {
2460: $exacton = ' checked="checked" ';
2461: $containson = ' checked="checked" ';
2462: }
1.23 raeburn 2463: }
2464: }
2465: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2466: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2467:
2468: my $numinrow = 4;
1.26 raeburn 2469: my $cansrchrow = 0;
1.23 raeburn 2470: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2471: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2472: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2473: '<input type="radio" name="dirsrch_available"'.
2474: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2475: '<label><input type="radio" name="dirsrch_available"'.
2476: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2477: '</tr><tr>'.
1.30 raeburn 2478: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2479: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2480: '<input type="radio" name="dirsrch_localonly"'.
2481: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2482: '<label><input type="radio" name="dirsrch_localonly"'.
2483: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2484: '</tr>';
1.30 raeburn 2485: $$rowtotal += 2;
1.26 raeburn 2486: if (ref($usertypes) eq 'HASH') {
2487: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2488: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2489: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2490: $cansrchrow = 1;
2491: }
2492: }
2493: if ($cansrchrow) {
1.30 raeburn 2494: $$rowtotal ++;
1.26 raeburn 2495: $datatable .= '<tr>';
2496: } else {
2497: $datatable .= '<tr class="LC_odd_row">';
2498: }
1.30 raeburn 2499: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2500: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2501: foreach my $title (@{$titleorder}) {
2502: if (defined($searchtitles->{$title})) {
2503: my $check = ' ';
1.93 raeburn 2504: if (ref($settings) eq 'HASH') {
1.39 raeburn 2505: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2506: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2507: $check = ' checked="checked" ';
2508: }
1.25 raeburn 2509: }
2510: }
2511: $datatable .= '<td class="LC_left_item">'.
2512: '<span class="LC_nobreak"><label>'.
2513: '<input type="checkbox" name="searchby" '.
2514: 'value="'.$title.'"'.$check.'/>'.
2515: $searchtitles->{$title}.'</label></span></td>';
2516: }
2517: }
1.26 raeburn 2518: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2519: $$rowtotal ++;
1.26 raeburn 2520: if ($cansrchrow) {
2521: $datatable .= '<tr class="LC_odd_row">';
2522: } else {
2523: $datatable .= '<tr>';
2524: }
1.30 raeburn 2525: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2526: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2527: '<span class="LC_nobreak"><label>'.
2528: '<input type="checkbox" name="searchtypes" '.
2529: $exacton.' value="exact" />'.&mt('Exact match').
2530: '</label> '.
2531: '<label><input type="checkbox" name="searchtypes" '.
2532: $beginson.' value="begins" />'.&mt('Begins with').
2533: '</label> '.
2534: '<label><input type="checkbox" name="searchtypes" '.
2535: $containson.' value="contains" />'.&mt('Contains').
2536: '</label></span></td></tr>';
1.30 raeburn 2537: $$rowtotal ++;
1.25 raeburn 2538: return $datatable;
2539: }
2540:
1.28 raeburn 2541: sub print_contacts {
1.30 raeburn 2542: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2543: my $datatable;
2544: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2545: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2546: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.160.6.23 raeburn 2547: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2548: foreach my $type (@mailings) {
2549: $otheremails{$type} = '';
2550: }
1.134 raeburn 2551: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2552: if (ref($settings) eq 'HASH') {
2553: foreach my $item (@contacts) {
2554: if (exists($settings->{$item})) {
2555: $to{$item} = $settings->{$item};
2556: }
2557: }
2558: foreach my $type (@mailings) {
2559: if (exists($settings->{$type})) {
2560: if (ref($settings->{$type}) eq 'HASH') {
2561: foreach my $item (@contacts) {
2562: if ($settings->{$type}{$item}) {
2563: $checked{$type}{$item} = ' checked="checked" ';
2564: }
2565: }
2566: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2567: if ($type eq 'helpdeskmail') {
2568: $bccemails{$type} = $settings->{$type}{'bcc'};
2569: }
1.28 raeburn 2570: }
1.89 raeburn 2571: } elsif ($type eq 'lonstatusmail') {
2572: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2573: }
2574: }
2575: } else {
2576: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2577: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2578: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2579: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2580: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2581: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2582: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.23 raeburn 2583: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
2584: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2585: }
2586: my ($titles,$short_titles) = &contact_titles();
2587: my $rownum = 0;
2588: my $css_class;
2589: foreach my $item (@contacts) {
1.69 raeburn 2590: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2591: $datatable .= '<tr'.$css_class.'>'.
2592: '<td><span class="LC_nobreak">'.$titles->{$item}.
2593: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2594: '<input type="text" name="'.$item.'" value="'.
2595: $to{$item}.'" /></td></tr>';
1.160.6.23 raeburn 2596: $rownum ++;
1.28 raeburn 2597: }
2598: foreach my $type (@mailings) {
1.69 raeburn 2599: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2600: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2601: '<td><span class="LC_nobreak">'.
2602: $titles->{$type}.': </span></td>'.
1.28 raeburn 2603: '<td class="LC_left_item">'.
2604: '<span class="LC_nobreak">';
2605: foreach my $item (@contacts) {
2606: $datatable .= '<label>'.
2607: '<input type="checkbox" name="'.$type.'"'.
2608: $checked{$type}{$item}.
2609: ' value="'.$item.'" />'.$short_titles->{$item}.
2610: '</label> ';
2611: }
2612: $datatable .= '</span><br />'.&mt('Others').': '.
2613: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2614: 'value="'.$otheremails{$type}.'" />';
2615: if ($type eq 'helpdeskmail') {
1.136 raeburn 2616: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2617: '<input type="text" name="'.$type.'_bcc" '.
2618: 'value="'.$bccemails{$type}.'" />';
2619: }
2620: $datatable .= '</td></tr>'."\n";
1.160.6.23 raeburn 2621: $rownum ++;
1.28 raeburn 2622: }
1.160.6.23 raeburn 2623: my %choices;
2624: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2625: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2626: &mt('LON-CAPA core group - MSU'),600,500));
2627: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2628: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2629: &mt('LON-CAPA core group - MSU'),600,500));
2630: my @toggles = ('reporterrors','reportupdates');
2631: my %defaultchecked = ('reporterrors' => 'on',
2632: 'reportupdates' => 'on');
2633: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2634: \%choices,$rownum);
2635: $datatable .= $reports;
1.30 raeburn 2636: $$rowtotal += $rownum;
1.28 raeburn 2637: return $datatable;
2638: }
2639:
1.118 jms 2640: sub print_helpsettings {
1.160.6.5 raeburn 2641: my ($dom,$confname,$settings,$rowtotal) = @_;
2642: my ($datatable,$itemcount);
2643: $itemcount = 1;
2644: my (%choices,%defaultchecked,@toggles);
2645: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2646: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2647: &mt('LON-CAPA bug tracker'),600,500));
2648: %defaultchecked = ('submitbugs' => 'on');
2649: @toggles = ('submitbugs',);
1.122 jms 2650:
1.160.6.5 raeburn 2651: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2652: \%choices,$itemcount);
2653: return $datatable;
1.121 raeburn 2654: }
2655:
2656: sub radiobutton_prefs {
1.160.6.16 raeburn 2657: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
2658: $additional) = @_;
1.121 raeburn 2659: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2660: (ref($choices) eq 'HASH'));
2661:
2662: my (%checkedon,%checkedoff,$datatable,$css_class);
2663:
2664: foreach my $item (@{$toggles}) {
2665: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2666: $checkedon{$item} = ' checked="checked" ';
2667: $checkedoff{$item} = ' ';
1.121 raeburn 2668: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2669: $checkedoff{$item} = ' checked="checked" ';
2670: $checkedon{$item} = ' ';
2671: }
2672: }
2673: if (ref($settings) eq 'HASH') {
1.121 raeburn 2674: foreach my $item (@{$toggles}) {
1.118 jms 2675: if ($settings->{$item} eq '1') {
2676: $checkedon{$item} = ' checked="checked" ';
2677: $checkedoff{$item} = ' ';
2678: } elsif ($settings->{$item} eq '0') {
2679: $checkedoff{$item} = ' checked="checked" ';
2680: $checkedon{$item} = ' ';
2681: }
2682: }
1.121 raeburn 2683: }
1.160.6.16 raeburn 2684: if ($onclick) {
2685: $onclick = ' onclick="'.$onclick.'"';
2686: }
1.121 raeburn 2687: foreach my $item (@{$toggles}) {
1.118 jms 2688: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2689: $datatable .=
1.160.6.16 raeburn 2690: '<tr'.$css_class.'><td valign="top">'.
2691: '<span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2692: '</span></td>'.
2693: '<td class="LC_right_item"><span class="LC_nobreak">'.
2694: '<label><input type="radio" name="'.
1.160.6.16 raeburn 2695: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2696: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 2697: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2698: '</span>'.$additional.
2699: '</td>'.
1.118 jms 2700: '</tr>';
2701: $itemcount ++;
1.121 raeburn 2702: }
2703: return ($datatable,$itemcount);
2704: }
2705:
2706: sub print_coursedefaults {
1.139 raeburn 2707: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2708: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2709: my $itemcount = 1;
1.160.6.16 raeburn 2710: my %choices = &Apache::lonlocal::texthash (
2711: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.160.6.21 raeburn 2712: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 2713: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2714: coursecredits => 'Credits can be specified for courses',
2715: );
1.160.6.21 raeburn 2716: my %staticdefaults = (
2717: anonsurvey_threshold => 10,
2718: uploadquota => 500,
2719: );
1.139 raeburn 2720: if ($position eq 'top') {
2721: %defaultchecked = ('canuse_pdfforms' => 'off');
1.160.6.16 raeburn 2722: @toggles = ('canuse_pdfforms');
1.139 raeburn 2723: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2724: \%choices,$itemcount);
1.139 raeburn 2725: } else {
2726: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.30 raeburn 2727: my ($currdefresponder,$def_official_credits,$def_unofficial_credits,$def_textbook_credits,
2728: %curruploadquota);
1.160.6.16 raeburn 2729: my $currusecredits = 0;
1.160.6.30 raeburn 2730: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 2731: if (ref($settings) eq 'HASH') {
2732: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 2733: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2734: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2735: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2736: }
2737: }
1.160.6.16 raeburn 2738: if (ref($settings->{'coursecredits'}) eq 'HASH') {
2739: $def_official_credits = $settings->{'coursecredits'}->{'official'};
2740: $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
1.160.6.30 raeburn 2741: $def_textbook_credits = $settings->{'coursecredits'}->{'textbook'};
2742: if (($def_official_credits ne '') || ($def_unofficial_credits ne '') ||
2743: ($def_textbook_credits ne '')) {
1.160.6.16 raeburn 2744: $currusecredits = 1;
2745: }
2746: }
1.139 raeburn 2747: }
2748: if (!$currdefresponder) {
1.160.6.21 raeburn 2749: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 2750: } elsif ($currdefresponder < 1) {
2751: $currdefresponder = 1;
2752: }
1.160.6.21 raeburn 2753: foreach my $type (@types) {
2754: if ($curruploadquota{$type} eq '') {
2755: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
2756: }
2757: }
1.139 raeburn 2758: $datatable .=
1.160.6.16 raeburn 2759: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2760: $choices{'anonsurvey_threshold'}.
1.139 raeburn 2761: '</span></td>'.
2762: '<td class="LC_right_item"><span class="LC_nobreak">'.
2763: '<input type="text" name="anonsurvey_threshold"'.
2764: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.21 raeburn 2765: '</td></tr>'."\n".
2766: '<tr><td><span class="LC_nobreak">'.
2767: $choices{'uploadquota'}.
2768: '</span></td>'.
2769: '<td align="right" class="LC_right_item">'.
2770: '<table><tr>';
2771: foreach my $type (@types) {
2772: $datatable .= '<td align="center">'.&mt($type).'<br />'.
2773: '<input type="text" name="uploadquota_'.$type.'"'.
2774: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
2775: }
2776: $datatable .= '</tr></table></td></tr>'."\n";
2777: $itemcount += 2;
1.160.6.16 raeburn 2778: my $onclick = 'toggleCredits(this.form);';
2779: my $display = 'none';
2780: if ($currusecredits) {
2781: $display = 'block';
2782: }
2783: my $additional = '<div id="credits" style="display: '.$display.'">'.
2784: '<span class="LC_nobreak">'.
2785: &mt('Default credits for official courses [_1]',
2786: '<input type="text" name="official_credits" value="'.
2787: $def_official_credits.'" size="3" />').
2788: '</span><br />'.
2789: '<span class="LC_nobreak">'.
2790: &mt('Default credits for unofficial courses [_1]',
2791: '<input type="text" name="unofficial_credits" value="'.
2792: $def_unofficial_credits.'" size="3" />').
1.160.6.30 raeburn 2793: '</span><br />'.
2794: '<span class="LC_nobreak">'.
2795: &mt('Default credits for textbook courses [_1]',
2796: '<input type="text" name="textbook_credits" value="'.
2797: $def_textbook_credits.'" size="3" />').
1.160.6.16 raeburn 2798: '</span></div>'."\n";
2799: %defaultchecked = ('coursecredits' => 'off');
2800: @toggles = ('coursecredits');
2801: my $current = {
2802: 'coursecredits' => $currusecredits,
2803: };
2804: (my $table,$itemcount) =
2805: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
2806: \%choices,$itemcount,$onclick,$additional);
2807: $datatable .= $table;
1.139 raeburn 2808: }
1.160.6.16 raeburn 2809: $$rowtotal += $itemcount;
1.121 raeburn 2810: return $datatable;
1.118 jms 2811: }
2812:
1.137 raeburn 2813: sub print_usersessions {
2814: my ($position,$dom,$settings,$rowtotal) = @_;
2815: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2816: my (%by_ip,%by_location,@intdoms);
2817: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 2818:
2819: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 2820: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 2821: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 2822: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 2823: my $itemcount = 1;
2824: if ($position eq 'top') {
1.152 raeburn 2825: if (keys(%serverhomes) > 1) {
1.145 raeburn 2826: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 2827: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 2828: } else {
1.140 raeburn 2829: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2830: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 2831: }
1.137 raeburn 2832: } else {
1.145 raeburn 2833: if (keys(%by_location) == 0) {
2834: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2835: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 2836: } else {
2837: my %lt = &usersession_titles();
2838: my $numinrow = 5;
2839: my $prefix;
2840: my @types;
2841: if ($position eq 'bottom') {
2842: $prefix = 'remote';
2843: @types = ('version','excludedomain','includedomain');
2844: } else {
2845: $prefix = 'hosted';
2846: @types = ('excludedomain','includedomain');
2847: }
2848: my (%current,%checkedon,%checkedoff);
2849: my @lcversions = &Apache::lonnet::all_loncaparevs();
2850: my @locations = sort(keys(%by_location));
2851: foreach my $type (@types) {
2852: $checkedon{$type} = '';
2853: $checkedoff{$type} = ' checked="checked"';
2854: }
2855: if (ref($settings) eq 'HASH') {
2856: if (ref($settings->{$prefix}) eq 'HASH') {
2857: foreach my $key (keys(%{$settings->{$prefix}})) {
2858: $current{$key} = $settings->{$prefix}{$key};
2859: if ($key eq 'version') {
2860: if ($current{$key} ne '') {
2861: $checkedon{$key} = ' checked="checked"';
2862: $checkedoff{$key} = '';
2863: }
2864: } elsif (ref($current{$key}) eq 'ARRAY') {
2865: $checkedon{$key} = ' checked="checked"';
2866: $checkedoff{$key} = '';
2867: }
1.137 raeburn 2868: }
2869: }
2870: }
1.145 raeburn 2871: foreach my $type (@types) {
2872: next if ($type ne 'version' && !@locations);
2873: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2874: $datatable .= '<tr'.$css_class.'>
2875: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2876: <span class="LC_nobreak">
2877: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2878: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2879: if ($type eq 'version') {
2880: my $selector = '<select name="'.$prefix.'_version">';
2881: foreach my $version (@lcversions) {
2882: my $selected = '';
2883: if ($current{'version'} eq $version) {
2884: $selected = ' selected="selected"';
2885: }
2886: $selector .= ' <option value="'.$version.'"'.
2887: $selected.'>'.$version.'</option>';
2888: }
2889: $selector .= '</select> ';
2890: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2891: } else {
2892: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2893: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2894: ' />'.(' 'x2).
2895: '<input type="button" value="'.&mt('uncheck all').'" '.
2896: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2897: "\n".
2898: '</div><div><table>';
2899: my $rem;
2900: for (my $i=0; $i<@locations; $i++) {
2901: my ($showloc,$value,$checkedtype);
2902: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2903: my $ip = $by_location{$locations[$i]}->[0];
2904: if (ref($by_ip{$ip}) eq 'ARRAY') {
2905: $value = join(':',@{$by_ip{$ip}});
2906: $showloc = join(', ',@{$by_ip{$ip}});
2907: if (ref($current{$type}) eq 'ARRAY') {
2908: foreach my $loc (@{$by_ip{$ip}}) {
2909: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2910: $checkedtype = ' checked="checked"';
2911: last;
2912: }
2913: }
1.138 raeburn 2914: }
2915: }
2916: }
1.145 raeburn 2917: $rem = $i%($numinrow);
2918: if ($rem == 0) {
2919: if ($i > 0) {
2920: $datatable .= '</tr>';
2921: }
2922: $datatable .= '<tr>';
2923: }
2924: $datatable .= '<td class="LC_left_item">'.
2925: '<span class="LC_nobreak"><label>'.
2926: '<input type="checkbox" name="'.$prefix.'_'.$type.
2927: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2928: '</label></span></td>';
1.137 raeburn 2929: }
1.145 raeburn 2930: $rem = @locations%($numinrow);
2931: my $colsleft = $numinrow - $rem;
2932: if ($colsleft > 1 ) {
2933: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2934: ' </td>';
2935: } elsif ($colsleft == 1) {
2936: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 2937: }
1.145 raeburn 2938: $datatable .= '</tr></table>';
1.137 raeburn 2939: }
1.145 raeburn 2940: $datatable .= '</td></tr>';
2941: $itemcount ++;
1.137 raeburn 2942: }
2943: }
2944: }
2945: $$rowtotal += $itemcount;
2946: return $datatable;
2947: }
2948:
1.138 raeburn 2949: sub build_location_hashes {
2950: my ($intdoms,$by_ip,$by_location) = @_;
2951: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2952: (ref($by_location) eq 'HASH'));
2953: my %iphost = &Apache::lonnet::get_iphost();
2954: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2955: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2956: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2957: foreach my $id (@{$iphost{$primary_ip}}) {
2958: my $intdom = &Apache::lonnet::internet_dom($id);
2959: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2960: push(@{$intdoms},$intdom);
2961: }
2962: }
2963: }
2964: foreach my $ip (keys(%iphost)) {
2965: if (ref($iphost{$ip}) eq 'ARRAY') {
2966: foreach my $id (@{$iphost{$ip}}) {
2967: my $location = &Apache::lonnet::internet_dom($id);
2968: if ($location) {
2969: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2970: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2971: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2972: push(@{$by_ip->{$ip}},$location);
2973: }
2974: } else {
2975: $by_ip->{$ip} = [$location];
2976: }
2977: }
2978: }
2979: }
2980: }
2981: foreach my $ip (sort(keys(%{$by_ip}))) {
2982: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2983: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2984: my $first = $by_ip->{$ip}->[0];
2985: if (ref($by_location->{$first}) eq 'ARRAY') {
2986: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2987: push(@{$by_location->{$first}},$ip);
2988: }
2989: } else {
2990: $by_location->{$first} = [$ip];
2991: }
2992: }
2993: }
2994: return;
2995: }
2996:
1.145 raeburn 2997: sub current_offloads_to {
2998: my ($dom,$settings,$servers) = @_;
2999: my (%spareid,%otherdomconfigs);
1.152 raeburn 3000: if (ref($servers) eq 'HASH') {
1.145 raeburn 3001: foreach my $lonhost (sort(keys(%{$servers}))) {
3002: my $gotspares;
1.152 raeburn 3003: if (ref($settings) eq 'HASH') {
3004: if (ref($settings->{'spares'}) eq 'HASH') {
3005: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
3006: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
3007: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
3008: $gotspares = 1;
3009: }
1.145 raeburn 3010: }
3011: }
3012: unless ($gotspares) {
3013: my $gotspares;
3014: my $serverhomeID =
3015: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
3016: my $serverhomedom =
3017: &Apache::lonnet::host_domain($serverhomeID);
3018: if ($serverhomedom ne $dom) {
3019: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
3020: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3021: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3022: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3023: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3024: $gotspares = 1;
3025: }
3026: }
3027: } else {
3028: $otherdomconfigs{$serverhomedom} =
3029: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
3030: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
3031: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3032: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3033: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
3034: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3035: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3036: $gotspares = 1;
3037: }
3038: }
3039: }
3040: }
3041: }
3042: }
3043: }
3044: unless ($gotspares) {
3045: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
3046: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3047: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3048: } else {
3049: my $server_hostname = &Apache::lonnet::hostname($lonhost);
3050: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
3051: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
3052: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3053: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3054: } else {
1.150 raeburn 3055: my %what = (
3056: spareid => 1,
3057: );
3058: my ($result,$returnhash) =
3059: &Apache::lonnet::get_remote_globals($lonhost,\%what);
3060: if ($result eq 'ok') {
3061: if (ref($returnhash) eq 'HASH') {
3062: if (ref($returnhash->{'spareid'}) eq 'HASH') {
3063: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
3064: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
3065: }
3066: }
1.145 raeburn 3067: }
3068: }
3069: }
3070: }
3071: }
3072: }
3073: return %spareid;
3074: }
3075:
3076: sub spares_row {
1.152 raeburn 3077: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 3078: my $css_class;
3079: my $numinrow = 4;
3080: my $itemcount = 1;
3081: my $datatable;
1.152 raeburn 3082: my %typetitles = &sparestype_titles();
3083: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 3084: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 3085: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
3086: my ($othercontrol,$serverdom);
3087: if ($serverhome ne $server) {
3088: $serverdom = &Apache::lonnet::host_domain($serverhome);
3089: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3090: } else {
3091: $serverdom = &Apache::lonnet::host_domain($server);
3092: if ($serverdom ne $dom) {
3093: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3094: }
3095: }
3096: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 3097: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3098: $datatable .= '<tr'.$css_class.'>
3099: <td rowspan="2">
1.160.6.13 raeburn 3100: <span class="LC_nobreak">'.
3101: &mt('[_1] when busy, offloads to:'
3102: ,'<b>'.$server.'</b>').
3103: "\n";
1.145 raeburn 3104: my (%current,%canselect);
1.152 raeburn 3105: my @choices =
3106: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
3107: foreach my $type ('primary','default') {
3108: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 3109: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
3110: my @spares = @{$spareid->{$server}{$type}};
3111: if (@spares > 0) {
1.152 raeburn 3112: if ($othercontrol) {
3113: $current{$type} = join(', ',@spares);
3114: } else {
3115: $current{$type} .= '<table>';
3116: my $numspares = scalar(@spares);
3117: for (my $i=0; $i<@spares; $i++) {
3118: my $rem = $i%($numinrow);
3119: if ($rem == 0) {
3120: if ($i > 0) {
3121: $current{$type} .= '</tr>';
3122: }
3123: $current{$type} .= '<tr>';
1.145 raeburn 3124: }
1.152 raeburn 3125: $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'".');" /> '.
3126: $spareid->{$server}{$type}[$i].
3127: '</label></td>'."\n";
3128: }
3129: my $rem = @spares%($numinrow);
3130: my $colsleft = $numinrow - $rem;
3131: if ($colsleft > 1 ) {
3132: $current{$type} .= '<td colspan="'.$colsleft.
3133: '" class="LC_left_item">'.
3134: ' </td>';
3135: } elsif ($colsleft == 1) {
3136: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 3137: }
1.152 raeburn 3138: $current{$type} .= '</tr></table>';
1.150 raeburn 3139: }
1.145 raeburn 3140: }
3141: }
3142: if ($current{$type} eq '') {
3143: $current{$type} = &mt('None specified');
3144: }
1.152 raeburn 3145: if ($othercontrol) {
3146: if ($type eq 'primary') {
3147: $canselect{$type} = $othercontrol;
3148: }
3149: } else {
3150: $canselect{$type} =
3151: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
3152: '<select name="newspare_'.$type.'_'.$server.'" '.
3153: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
3154: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
3155: if (@choices > 0) {
3156: foreach my $lonhost (@choices) {
3157: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
3158: }
3159: }
3160: $canselect{$type} .= '</select>'."\n";
3161: }
3162: } else {
3163: $current{$type} = &mt('Could not be determined');
3164: if ($type eq 'primary') {
3165: $canselect{$type} = $othercontrol;
3166: }
1.145 raeburn 3167: }
1.152 raeburn 3168: if ($type eq 'default') {
3169: $datatable .= '<tr'.$css_class.'>';
3170: }
3171: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
3172: '<td>'.$current{$type}.'</td>'."\n".
3173: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 3174: }
3175: $itemcount ++;
3176: }
3177: }
3178: $$rowtotal += $itemcount;
3179: return $datatable;
3180: }
3181:
1.152 raeburn 3182: sub possible_newspares {
3183: my ($server,$currspares,$serverhomes,$altids) = @_;
3184: my $serverhostname = &Apache::lonnet::hostname($server);
3185: my %excluded;
3186: if ($serverhostname ne '') {
3187: %excluded = (
3188: $serverhostname => 1,
3189: );
3190: }
3191: if (ref($currspares) eq 'HASH') {
3192: foreach my $type (keys(%{$currspares})) {
3193: if (ref($currspares->{$type}) eq 'ARRAY') {
3194: if (@{$currspares->{$type}} > 0) {
3195: foreach my $curr (@{$currspares->{$type}}) {
3196: my $hostname = &Apache::lonnet::hostname($curr);
3197: $excluded{$hostname} = 1;
3198: }
3199: }
3200: }
3201: }
3202: }
3203: my @choices;
3204: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
3205: if (keys(%{$serverhomes}) > 1) {
3206: foreach my $name (sort(keys(%{$serverhomes}))) {
3207: unless ($excluded{$name}) {
3208: if (exists($altids->{$serverhomes->{$name}})) {
3209: push(@choices,$altids->{$serverhomes->{$name}});
3210: } else {
3211: push(@choices,$serverhomes->{$name});
1.145 raeburn 3212: }
3213: }
3214: }
3215: }
3216: }
1.152 raeburn 3217: return sort(@choices);
1.145 raeburn 3218: }
3219:
1.150 raeburn 3220: sub print_loadbalancing {
3221: my ($dom,$settings,$rowtotal) = @_;
3222: my $primary_id = &Apache::lonnet::domain($dom,'primary');
3223: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3224: my $numinrow = 1;
3225: my $datatable;
3226: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7 raeburn 3227: my (%currbalancer,%currtargets,%currrules,%existing);
3228: if (ref($settings) eq 'HASH') {
3229: %existing = %{$settings};
3230: }
3231: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
3232: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
3233: \%currtargets,\%currrules);
1.150 raeburn 3234: } else {
3235: return;
3236: }
3237: my ($othertitle,$usertypes,$types) =
3238: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 3239: my $rownum = 8;
1.150 raeburn 3240: if (ref($types) eq 'ARRAY') {
3241: $rownum += scalar(@{$types});
3242: }
1.160.6.7 raeburn 3243: my @css_class = ('LC_odd_row','LC_even_row');
3244: my $balnum = 0;
3245: my $islast;
3246: my (@toshow,$disabledtext);
3247: if (keys(%currbalancer) > 0) {
3248: @toshow = sort(keys(%currbalancer));
3249: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
3250: push(@toshow,'');
3251: }
3252: } else {
3253: @toshow = ('');
3254: $disabledtext = &mt('No existing load balancer');
3255: }
3256: foreach my $lonhost (@toshow) {
3257: if ($balnum == scalar(@toshow)-1) {
3258: $islast = 1;
3259: } else {
3260: $islast = 0;
3261: }
3262: my $cssidx = $balnum%2;
3263: my $targets_div_style = 'display: none';
3264: my $disabled_div_style = 'display: block';
3265: my $homedom_div_style = 'display: none';
3266: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3267: '<td rowspan="'.$rownum.'" valign="top">'.
3268: '<p>';
3269: if ($lonhost eq '') {
3270: $datatable .= '<span class="LC_nobreak">';
3271: if (keys(%currbalancer) > 0) {
3272: $datatable .= &mt('Add balancer:');
3273: } else {
3274: $datatable .= &mt('Enable balancer:');
3275: }
3276: $datatable .= ' '.
3277: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3278: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3279: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3280: '<option value="" selected="selected">'.&mt('None').
3281: '</option>'."\n";
3282: foreach my $server (sort(keys(%servers))) {
3283: next if ($currbalancer{$server});
3284: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3285: }
3286: $datatable .=
3287: '</select>'."\n".
3288: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3289: } else {
3290: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3291: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3292: &mt('Stop balancing').'</label>'.
3293: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3294: $targets_div_style = 'display: block';
3295: $disabled_div_style = 'display: none';
3296: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3297: $homedom_div_style = 'display: block';
3298: }
3299: }
3300: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3301: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3302: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3303: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3304: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3305: my @sparestypes = ('primary','default');
3306: my %typetitles = &sparestype_titles();
3307: foreach my $sparetype (@sparestypes) {
3308: my $targettable;
3309: for (my $i=0; $i<$numspares; $i++) {
3310: my $checked;
3311: if (ref($currtargets{$lonhost}) eq 'HASH') {
3312: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3313: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3314: $checked = ' checked="checked"';
3315: }
3316: }
3317: }
3318: my ($chkboxval,$disabled);
3319: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3320: $chkboxval = $spares[$i];
3321: }
3322: if (exists($currbalancer{$spares[$i]})) {
3323: $disabled = ' disabled="disabled"';
3324: }
3325: $targettable .=
3326: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3327: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3328: '</span></label></td>';
3329: my $rem = $i%($numinrow);
3330: if ($rem == 0) {
3331: if (($i > 0) && ($i < $numspares-1)) {
3332: $targettable .= '</tr>';
3333: }
3334: if ($i < $numspares-1) {
3335: $targettable .= '<tr>';
1.150 raeburn 3336: }
3337: }
3338: }
1.160.6.7 raeburn 3339: if ($targettable ne '') {
3340: my $rem = $numspares%($numinrow);
3341: my $colsleft = $numinrow - $rem;
3342: if ($colsleft > 1 ) {
3343: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3344: ' </td>';
3345: } elsif ($colsleft == 1) {
3346: $targettable .= '<td class="LC_left_item"> </td>';
3347: }
3348: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3349: '<table><tr>'.$targettable.'</tr></table><br />';
3350: }
3351: }
3352: $datatable .= '</div></td></tr>'.
3353: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3354: $othertitle,$usertypes,$types,\%servers,
3355: \%currbalancer,$lonhost,
3356: $targets_div_style,$homedom_div_style,
3357: $css_class[$cssidx],$balnum,$islast);
3358: $$rowtotal += $rownum;
3359: $balnum ++;
3360: }
3361: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3362: return $datatable;
3363: }
3364:
3365: sub get_loadbalancers_config {
3366: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3367: return unless ((ref($servers) eq 'HASH') &&
3368: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3369: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3370: if (keys(%{$existing}) > 0) {
3371: my $oldlonhost;
3372: foreach my $key (sort(keys(%{$existing}))) {
3373: if ($key eq 'lonhost') {
3374: $oldlonhost = $existing->{'lonhost'};
3375: $currbalancer->{$oldlonhost} = 1;
3376: } elsif ($key eq 'targets') {
3377: if ($oldlonhost) {
3378: $currtargets->{$oldlonhost} = $existing->{'targets'};
3379: }
3380: } elsif ($key eq 'rules') {
3381: if ($oldlonhost) {
3382: $currrules->{$oldlonhost} = $existing->{'rules'};
3383: }
3384: } elsif (ref($existing->{$key}) eq 'HASH') {
3385: $currbalancer->{$key} = 1;
3386: $currtargets->{$key} = $existing->{$key}{'targets'};
3387: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3388: }
3389: }
1.160.6.7 raeburn 3390: } else {
3391: my ($balancerref,$targetsref) =
3392: &Apache::lonnet::get_lonbalancer_config($servers);
3393: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3394: foreach my $server (sort(keys(%{$balancerref}))) {
3395: $currbalancer->{$server} = 1;
3396: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3397: }
3398: }
3399: }
1.160.6.7 raeburn 3400: return;
1.150 raeburn 3401: }
3402:
3403: sub loadbalancing_rules {
3404: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 3405: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3406: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3407: my $output;
1.160.6.7 raeburn 3408: my $num = 0;
3409: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3410: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3411: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3412: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 3413: $num ++;
1.150 raeburn 3414: my $current;
3415: if (ref($currrules) eq 'HASH') {
3416: $current = $currrules->{$type};
3417: }
1.160.6.26 raeburn 3418: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.160.6.7 raeburn 3419: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3420: $current = '';
3421: }
3422: }
3423: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 3424: $servers,$currbalancer,$lonhost,$dom,
3425: $targets_div_style,$homedom_div_style,
3426: $css_class,$balnum,$num,$islast);
1.150 raeburn 3427: }
3428: }
3429: return $output;
3430: }
3431:
3432: sub loadbalancing_titles {
3433: my ($dom,$intdom,$usertypes,$types) = @_;
3434: my %othertypes = (
3435: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3436: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3437: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3438: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 3439: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
3440: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 3441: );
1.160.6.26 raeburn 3442: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 3443: if (ref($types) eq 'ARRAY') {
3444: unshift(@alltypes,@{$types},'default');
3445: }
3446: my %titles;
3447: foreach my $type (@alltypes) {
3448: if ($type =~ /^_LC_/) {
3449: $titles{$type} = $othertypes{$type};
3450: } elsif ($type eq 'default') {
3451: $titles{$type} = &mt('All users from [_1]',$dom);
3452: if (ref($types) eq 'ARRAY') {
3453: if (@{$types} > 0) {
3454: $titles{$type} = &mt('Other users from [_1]',$dom);
3455: }
3456: }
3457: } elsif (ref($usertypes) eq 'HASH') {
3458: $titles{$type} = $usertypes->{$type};
3459: }
3460: }
3461: return (\@alltypes,\%othertypes,\%titles);
3462: }
3463:
3464: sub loadbalance_rule_row {
1.160.6.7 raeburn 3465: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3466: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 3467: my @rulenames;
1.150 raeburn 3468: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 3469: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
3470: @rulenames = ('balancer','offloadedto');
1.150 raeburn 3471: } else {
1.160.6.26 raeburn 3472: @rulenames = ('default','homeserver');
3473: if ($type eq '_LC_external') {
3474: push(@rulenames,'externalbalancer');
3475: } else {
3476: push(@rulenames,'specific');
3477: }
3478: push(@rulenames,'none');
1.150 raeburn 3479: }
3480: my $style = $targets_div_style;
1.160.6.26 raeburn 3481: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.150 raeburn 3482: $style = $homedom_div_style;
3483: }
1.160.6.7 raeburn 3484: my $space;
3485: if ($islast && $num == 1) {
3486: $space = '<div display="inline-block"> </div>';
3487: }
3488: my $output =
3489: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3490: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3491: '<td valaign="top">'.$space.
3492: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3493: for (my $i=0; $i<@rulenames; $i++) {
3494: my $rule = $rulenames[$i];
3495: my ($checked,$extra);
3496: if ($rulenames[$i] eq 'default') {
3497: $rule = '';
3498: }
3499: if ($rulenames[$i] eq 'specific') {
3500: if (ref($servers) eq 'HASH') {
3501: my $default;
3502: if (($current ne '') && (exists($servers->{$current}))) {
3503: $checked = ' checked="checked"';
3504: }
3505: unless ($checked) {
3506: $default = ' selected="selected"';
3507: }
1.160.6.7 raeburn 3508: $extra =
3509: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3510: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3511: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3512: '<option value=""'.$default.'></option>'."\n";
3513: foreach my $server (sort(keys(%{$servers}))) {
3514: if (ref($currbalancer) eq 'HASH') {
3515: next if (exists($currbalancer->{$server}));
3516: }
1.150 raeburn 3517: my $selected;
1.160.6.7 raeburn 3518: if ($server eq $current) {
1.150 raeburn 3519: $selected = ' selected="selected"';
3520: }
1.160.6.7 raeburn 3521: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3522: }
3523: $extra .= '</select>';
3524: }
3525: } elsif ($rule eq $current) {
3526: $checked = ' checked="checked"';
3527: }
3528: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 3529: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3530: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3531: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3532: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3533: '</label>'.$extra.'</span><br />'."\n";
3534: }
3535: $output .= '</div></td></tr>'."\n";
3536: return $output;
3537: }
3538:
3539: sub offloadtype_text {
3540: my %ruletitles = &Apache::lonlocal::texthash (
3541: 'default' => 'Offloads to default destinations',
3542: 'homeserver' => "Offloads to user's home server",
3543: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3544: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 3545: 'none' => 'No offload',
1.160.6.26 raeburn 3546: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
3547: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.150 raeburn 3548: );
3549: return %ruletitles;
3550: }
3551:
3552: sub sparestype_titles {
3553: my %typestitles = &Apache::lonlocal::texthash (
3554: 'primary' => 'primary',
3555: 'default' => 'default',
3556: );
3557: return %typestitles;
3558: }
3559:
1.28 raeburn 3560: sub contact_titles {
3561: my %titles = &Apache::lonlocal::texthash (
3562: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3563: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3564: 'errormail' => 'Error reports to be e-mailed to',
3565: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3566: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3567: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3568: 'requestsmail' => 'E-mail from course requests requiring approval',
1.160.6.15 raeburn 3569: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 3570: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 3571: );
3572: my %short_titles = &Apache::lonlocal::texthash (
3573: adminemail => 'Admin E-mail address',
3574: supportemail => 'Support E-mail',
3575: );
3576: return (\%titles,\%short_titles);
3577: }
3578:
1.72 raeburn 3579: sub tool_titles {
3580: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 3581: aboutme => 'Personal web page',
1.86 raeburn 3582: blog => 'Blog',
1.160.6.4 raeburn 3583: webdav => 'WebDAV',
1.86 raeburn 3584: portfolio => 'Portfolio',
1.88 bisitz 3585: official => 'Official courses (with institutional codes)',
3586: unofficial => 'Unofficial courses',
1.98 raeburn 3587: community => 'Communities',
1.160.6.30 raeburn 3588: textbook => 'Textbook courses',
1.86 raeburn 3589: );
1.72 raeburn 3590: return %titles;
3591: }
3592:
1.101 raeburn 3593: sub courserequest_titles {
3594: my %titles = &Apache::lonlocal::texthash (
3595: official => 'Official',
3596: unofficial => 'Unofficial',
3597: community => 'Communities',
1.160.6.30 raeburn 3598: textbook => 'Textbook',
1.101 raeburn 3599: norequest => 'Not allowed',
1.104 raeburn 3600: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3601: validate => 'With validation',
3602: autolimit => 'Numerical limit',
1.103 raeburn 3603: unlimited => '(blank for unlimited)',
1.101 raeburn 3604: );
3605: return %titles;
3606: }
3607:
1.160.6.5 raeburn 3608: sub authorrequest_titles {
3609: my %titles = &Apache::lonlocal::texthash (
3610: norequest => 'Not allowed',
3611: approval => 'Approval by Dom. Coord.',
3612: automatic => 'Automatic approval',
3613: );
3614: return %titles;
3615: }
3616:
1.101 raeburn 3617: sub courserequest_conditions {
3618: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3619: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 3620: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 3621: );
3622: return %conditions;
3623: }
3624:
3625:
1.27 raeburn 3626: sub print_usercreation {
1.30 raeburn 3627: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3628: my $numinrow = 4;
1.28 raeburn 3629: my $datatable;
3630: if ($position eq 'top') {
1.30 raeburn 3631: $$rowtotal ++;
1.34 raeburn 3632: my $rowcount = 0;
1.32 raeburn 3633: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3634: if (ref($rules) eq 'HASH') {
3635: if (keys(%{$rules}) > 0) {
1.32 raeburn 3636: $datatable .= &user_formats_row('username',$settings,$rules,
3637: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3638: $$rowtotal ++;
1.32 raeburn 3639: $rowcount ++;
3640: }
3641: }
3642: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3643: if (ref($idrules) eq 'HASH') {
3644: if (keys(%{$idrules}) > 0) {
3645: $datatable .= &user_formats_row('id',$settings,$idrules,
3646: $idruleorder,$numinrow,$rowcount);
3647: $$rowtotal ++;
3648: $rowcount ++;
1.28 raeburn 3649: }
3650: }
1.39 raeburn 3651: if ($rowcount == 0) {
3652: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3653: $$rowtotal ++;
3654: $rowcount ++;
3655: }
1.34 raeburn 3656: } elsif ($position eq 'middle') {
1.160.6.34! raeburn 3657: my @creators = ('author','course','requestcrs');
1.37 raeburn 3658: my ($rules,$ruleorder) =
3659: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3660: my %lt = &usercreation_types();
3661: my %checked;
3662: if (ref($settings) eq 'HASH') {
3663: if (ref($settings->{'cancreate'}) eq 'HASH') {
3664: foreach my $item (@creators) {
3665: $checked{$item} = $settings->{'cancreate'}{$item};
3666: }
3667: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3668: foreach my $item (@creators) {
3669: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3670: $checked{$item} = 'none';
3671: }
3672: }
3673: }
3674: }
3675: my $rownum = 0;
3676: foreach my $item (@creators) {
3677: $rownum ++;
1.160.6.34! raeburn 3678: if ($checked{$item} eq '') {
! 3679: $checked{$item} = 'any';
1.34 raeburn 3680: }
3681: my $css_class;
3682: if ($rownum%2) {
3683: $css_class = '';
3684: } else {
3685: $css_class = ' class="LC_odd_row" ';
3686: }
3687: $datatable .= '<tr'.$css_class.'>'.
3688: '<td><span class="LC_nobreak">'.$lt{$item}.
3689: '</span></td><td align="right">';
1.160.6.34! raeburn 3690: my @options = ('any');
! 3691: if (ref($rules) eq 'HASH') {
! 3692: if (keys(%{$rules}) > 0) {
! 3693: push(@options,('official','unofficial'));
1.37 raeburn 3694: }
3695: }
1.160.6.34! raeburn 3696: push(@options,'none');
1.37 raeburn 3697: foreach my $option (@options) {
1.50 raeburn 3698: my $type = 'radio';
1.34 raeburn 3699: my $check = ' ';
1.160.6.34! raeburn 3700: if ($checked{$item} eq $option) {
! 3701: $check = ' checked="checked" ';
1.34 raeburn 3702: }
3703: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3704: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3705: $item.'" value="'.$option.'"'.$check.'/> '.
3706: $lt{$option}.'</label> </span>';
3707: }
3708: $datatable .= '</td></tr>';
3709: }
1.28 raeburn 3710: } else {
3711: my @contexts = ('author','course','domain');
3712: my @authtypes = ('int','krb4','krb5','loc');
3713: my %checked;
3714: if (ref($settings) eq 'HASH') {
3715: if (ref($settings->{'authtypes'}) eq 'HASH') {
3716: foreach my $item (@contexts) {
3717: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3718: foreach my $auth (@authtypes) {
3719: if ($settings->{'authtypes'}{$item}{$auth}) {
3720: $checked{$item}{$auth} = ' checked="checked" ';
3721: }
3722: }
3723: }
3724: }
1.27 raeburn 3725: }
1.35 raeburn 3726: } else {
3727: foreach my $item (@contexts) {
1.36 raeburn 3728: foreach my $auth (@authtypes) {
1.35 raeburn 3729: $checked{$item}{$auth} = ' checked="checked" ';
3730: }
3731: }
1.27 raeburn 3732: }
1.28 raeburn 3733: my %title = &context_names();
3734: my %authname = &authtype_names();
3735: my $rownum = 0;
3736: my $css_class;
3737: foreach my $item (@contexts) {
3738: if ($rownum%2) {
3739: $css_class = '';
3740: } else {
3741: $css_class = ' class="LC_odd_row" ';
3742: }
1.30 raeburn 3743: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3744: '<td>'.$title{$item}.
3745: '</td><td class="LC_left_item">'.
3746: '<span class="LC_nobreak">';
3747: foreach my $auth (@authtypes) {
3748: $datatable .= '<label>'.
3749: '<input type="checkbox" name="'.$item.'_auth" '.
3750: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3751: $authname{$auth}.'</label> ';
3752: }
3753: $datatable .= '</span></td></tr>';
3754: $rownum ++;
1.27 raeburn 3755: }
1.30 raeburn 3756: $$rowtotal += $rownum;
1.27 raeburn 3757: }
3758: return $datatable;
3759: }
3760:
1.160.6.34! raeburn 3761: sub print_selfcreation {
! 3762: my ($position,$dom,$settings,$rowtotal) = @_;
! 3763: my (@selfcreate,$createsettings,$datatable);
! 3764: if (ref($settings) eq 'HASH') {
! 3765: if (ref($settings->{'cancreate'}) eq 'HASH') {
! 3766: $createsettings = $settings->{'cancreate'};
! 3767: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
! 3768: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
! 3769: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
! 3770: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
! 3771: @selfcreate = ('email','login','sso');
! 3772: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
! 3773: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
! 3774: }
! 3775: }
! 3776: }
! 3777: }
! 3778: my %radiohash;
! 3779: my $rownum = 0;
! 3780: my $numinrow = 4;
! 3781: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
! 3782: if ($position eq 'top') {
! 3783: my %choices = &Apache::lonlocal::texthash (
! 3784: cancreate_login => 'Institutional Login',
! 3785: cancreate_sso => 'Institutional Single Sign On',
! 3786: );
! 3787: my @toggles = sort(keys(%choices));
! 3788: my %defaultchecked = (
! 3789: 'cancreate_login' => 'off',
! 3790: 'cancreate_sso' => 'off',
! 3791: );
! 3792: my $itemcount = 1;
! 3793: my $onclick;
! 3794: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
! 3795: \%choices,$itemcount,$onclick);
! 3796: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
! 3797:
! 3798: if (ref($usertypes) eq 'HASH') {
! 3799: if (keys(%{$usertypes}) > 0) {
! 3800: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
! 3801: $dom,$numinrow,$othertitle,
! 3802: 'statustocreate',$rownum);
! 3803: $rownum ++;
! 3804: $$rowtotal ++;
! 3805: }
! 3806: }
! 3807: } elsif ($position eq 'middle') {
! 3808: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
! 3809: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
! 3810: $usertypes->{'default'} = $othertitle;
! 3811: if (ref($types) eq 'ARRAY') {
! 3812: push(@{$types},'default');
! 3813: $usertypes->{'default'} = $othertitle;
! 3814: foreach my $status (@{$types}) {
! 3815: $rownum ++;
! 3816: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
! 3817: $numinrow,$rownum,$usertypes);
! 3818: $$rowtotal ++;
! 3819: }
! 3820: }
! 3821: } else {
! 3822: my $css_class = $rownum%2?' class="LC_odd_row"':'';
! 3823: my %choices =
! 3824: &Apache::lonlocal::texthash(
! 3825: email => 'Approved automatically',
! 3826: emailapproval => 'Queued for approval by DC',
! 3827: off => 'Not enabled',
! 3828: );
! 3829: $datatable .= '<tr'.$css_class.'>'.
! 3830: '<td>'.&mt('E-mail address as username').
! 3831: '</td><td class="LC_left_item">'.
! 3832: '<span class="LC_nobreak">';
! 3833: foreach my $option ('email','emailapproval','off') {
! 3834: my $checked;
! 3835: if ($option eq 'email') {
! 3836: if ($radiohash{'cancreate_email'}) {
! 3837: $checked = 'checked="checked"';
! 3838: }
! 3839: } elsif ($option eq 'emailapproval') {
! 3840: if ($radiohash{'cancreate_emailapproval'}) {
! 3841: $checked = 'checked="checked"';
! 3842: }
! 3843: } else {
! 3844: if ((!$radiohash{'cancreate_email'}) && (!$radiohash{'cancreate_emailapproval'})) {
! 3845: $checked = 'checked="checked"';
! 3846: }
! 3847: }
! 3848: $datatable .= '<label>'.
! 3849: '<input type="radio" name="cancreate_email" '.
! 3850: $checked.' value="'.$option.'" />'.
! 3851: $choices{$option}.'</label> ';
! 3852: }
! 3853: $$rowtotal ++;
! 3854: $rownum ++;
! 3855: $datatable .= '</span></td></tr>'.
! 3856: &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
! 3857: $rownum ++;
! 3858: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
! 3859: $numinrow = 2;
! 3860: $datatable .= &modifiable_userdata_row('cancreate','emailusername',$settings,
! 3861: $numinrow,$rownum,undef,$infofields,$infotitles);
! 3862: $$rowtotal ++;
! 3863: $rownum ++;
! 3864: my ($emailrules,$emailruleorder) =
! 3865: &Apache::lonnet::inst_userrules($dom,'email');
! 3866: if (ref($emailrules) eq 'HASH') {
! 3867: if (keys(%{$emailrules}) > 0) {
! 3868: $datatable .= &user_formats_row('email',$settings,$emailrules,
! 3869: $emailruleorder,$numinrow,$rownum);
! 3870: $rownum ++;
! 3871: $$rowtotal ++;
! 3872: }
! 3873: }
! 3874: $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
! 3875: }
! 3876: return $datatable;
! 3877: }
! 3878:
1.160.6.5 raeburn 3879: sub captcha_choice {
3880: my ($context,$settings,$itemcount) = @_;
3881: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
3882: my %lt = &captcha_phrases();
3883: $keyentry = 'hidden';
3884: if ($context eq 'cancreate') {
1.160.6.34! raeburn 3885: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 3886: } elsif ($context eq 'login') {
3887: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
3888: }
3889: if (ref($settings) eq 'HASH') {
3890: if ($settings->{'captcha'}) {
3891: $checked{$settings->{'captcha'}} = ' checked="checked"';
3892: } else {
3893: $checked{'original'} = ' checked="checked"';
3894: }
3895: if ($settings->{'captcha'} eq 'recaptcha') {
3896: $pubtext = $lt{'pub'};
3897: $privtext = $lt{'priv'};
3898: $keyentry = 'text';
3899: }
3900: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
3901: $currpub = $settings->{'recaptchakeys'}{'public'};
3902: $currpriv = $settings->{'recaptchakeys'}{'private'};
3903: }
3904: } else {
3905: $checked{'original'} = ' checked="checked"';
3906: }
3907: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3908: my $output = '<tr'.$css_class.'>'.
3909: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
3910: '<table><tr><td>'."\n";
3911: foreach my $option ('original','recaptcha','notused') {
3912: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
3913: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
3914: $lt{$option}.'</label></span>';
3915: unless ($option eq 'notused') {
3916: $output .= (' 'x2)."\n";
3917: }
3918: }
3919: #
3920: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
3921: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
3922: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
3923: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
3924: #
3925: $output .= '</td></tr>'."\n".
3926: '<tr><td>'."\n".
3927: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
3928: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
3929: $currpub.'" size="40" /></span><br />'."\n".
3930: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
3931: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
3932: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
3933: '</td></tr>';
3934: return $output;
3935: }
3936:
1.32 raeburn 3937: sub user_formats_row {
3938: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3939: my $output;
3940: my %text = (
3941: 'username' => 'new usernames',
3942: 'id' => 'IDs',
1.45 raeburn 3943: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3944: );
3945: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3946: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3947: '<td><span class="LC_nobreak">';
3948: if ($type eq 'email') {
3949: $output .= &mt("Formats disallowed for $text{$type}: ");
3950: } else {
3951: $output .= &mt("Format rules to check for $text{$type}: ");
3952: }
3953: $output .= '</span></td>'.
3954: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3955: my $rem;
3956: if (ref($ruleorder) eq 'ARRAY') {
3957: for (my $i=0; $i<@{$ruleorder}; $i++) {
3958: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3959: my $rem = $i%($numinrow);
3960: if ($rem == 0) {
3961: if ($i > 0) {
3962: $output .= '</tr>';
3963: }
3964: $output .= '<tr>';
3965: }
3966: my $check = ' ';
1.39 raeburn 3967: if (ref($settings) eq 'HASH') {
3968: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3969: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3970: $check = ' checked="checked" ';
3971: }
1.27 raeburn 3972: }
3973: }
3974: $output .= '<td class="LC_left_item">'.
3975: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3976: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 3977: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3978: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3979: }
3980: }
3981: $rem = @{$ruleorder}%($numinrow);
3982: }
3983: my $colsleft = $numinrow - $rem;
3984: if ($colsleft > 1 ) {
3985: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3986: ' </td>';
3987: } elsif ($colsleft == 1) {
3988: $output .= '<td class="LC_left_item"> </td>';
3989: }
3990: $output .= '</tr></table></td></tr>';
3991: return $output;
3992: }
3993:
1.34 raeburn 3994: sub usercreation_types {
3995: my %lt = &Apache::lonlocal::texthash (
3996: author => 'When adding a co-author',
3997: course => 'When adding a user to a course',
1.100 raeburn 3998: requestcrs => 'When requesting a course',
1.34 raeburn 3999: any => 'Any',
4000: official => 'Institutional only ',
4001: unofficial => 'Non-institutional only',
4002: none => 'None',
4003: );
4004: return %lt;
1.48 raeburn 4005: }
1.34 raeburn 4006:
1.160.6.34! raeburn 4007: sub selfcreation_types {
! 4008: my %lt = &Apache::lonlocal::texthash (
! 4009: selfcreate => 'User creates own account',
! 4010: any => 'Any',
! 4011: official => 'Institutional only ',
! 4012: unofficial => 'Non-institutional only',
! 4013: email => 'E-mail address',
! 4014: login => 'Institutional Login',
! 4015: sso => 'SSO',
! 4016: );
! 4017: }
! 4018:
1.28 raeburn 4019: sub authtype_names {
4020: my %lt = &Apache::lonlocal::texthash(
4021: int => 'Internal',
4022: krb4 => 'Kerberos 4',
4023: krb5 => 'Kerberos 5',
4024: loc => 'Local',
4025: );
4026: return %lt;
4027: }
4028:
4029: sub context_names {
4030: my %context_title = &Apache::lonlocal::texthash(
4031: author => 'Creating users when an Author',
4032: course => 'Creating users when in a course',
4033: domain => 'Creating users when a Domain Coordinator',
4034: );
4035: return %context_title;
4036: }
4037:
1.33 raeburn 4038: sub print_usermodification {
4039: my ($position,$dom,$settings,$rowtotal) = @_;
4040: my $numinrow = 4;
4041: my ($context,$datatable,$rowcount);
4042: if ($position eq 'top') {
4043: $rowcount = 0;
4044: $context = 'author';
4045: foreach my $role ('ca','aa') {
4046: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4047: $numinrow,$rowcount);
4048: $$rowtotal ++;
4049: $rowcount ++;
4050: }
1.63 raeburn 4051: } elsif ($position eq 'middle') {
1.33 raeburn 4052: $context = 'course';
4053: $rowcount = 0;
4054: foreach my $role ('st','ep','ta','in','cr') {
4055: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4056: $numinrow,$rowcount);
4057: $$rowtotal ++;
4058: $rowcount ++;
4059: }
4060: }
4061: return $datatable;
4062: }
4063:
1.43 raeburn 4064: sub print_defaults {
1.160.6.27 raeburn 4065: my ($dom,$settings,$rowtotal) = @_;
1.68 raeburn 4066: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 4067: 'datelocale_def','portal_def');
1.160.6.27 raeburn 4068: my %defaults;
4069: if (ref($settings) eq 'HASH') {
4070: %defaults = %{$settings};
4071: } else {
4072: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
4073: foreach my $item (@items) {
4074: $defaults{$item} = $domdefaults{$item};
4075: }
4076: }
1.141 raeburn 4077: my $titles = &defaults_titles($dom);
1.43 raeburn 4078: my $rownum = 0;
4079: my ($datatable,$css_class);
4080: foreach my $item (@items) {
4081: if ($rownum%2) {
4082: $css_class = '';
4083: } else {
4084: $css_class = ' class="LC_odd_row" ';
4085: }
4086: $datatable .= '<tr'.$css_class.'>'.
4087: '<td><span class="LC_nobreak">'.$titles->{$item}.
4088: '</span></td><td class="LC_right_item">';
4089: if ($item eq 'auth_def') {
4090: my @authtypes = ('internal','krb4','krb5','localauth');
4091: my %shortauth = (
4092: internal => 'int',
4093: krb4 => 'krb4',
4094: krb5 => 'krb5',
4095: localauth => 'loc'
4096: );
4097: my %authnames = &authtype_names();
4098: foreach my $auth (@authtypes) {
4099: my $checked = ' ';
1.160.6.27 raeburn 4100: if ($defaults{$item} eq $auth) {
1.43 raeburn 4101: $checked = ' checked="checked" ';
4102: }
4103: $datatable .= '<label><input type="radio" name="'.$item.
4104: '" value="'.$auth.'"'.$checked.'/>'.
4105: $authnames{$shortauth{$auth}}.'</label> ';
4106: }
1.54 raeburn 4107: } elsif ($item eq 'timezone_def') {
4108: my $includeempty = 1;
1.160.6.27 raeburn 4109: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
1.68 raeburn 4110: } elsif ($item eq 'datelocale_def') {
4111: my $includeempty = 1;
1.160.6.27 raeburn 4112: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
1.160.6.5 raeburn 4113: } elsif ($item eq 'lang_def') {
4114: my %langchoices = &get_languages_hash();
4115: $langchoices{''} = 'No language preference';
4116: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.160.6.27 raeburn 4117: $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,
1.160.6.5 raeburn 4118: \%langchoices);
1.43 raeburn 4119: } else {
1.141 raeburn 4120: my $size;
4121: if ($item eq 'portal_def') {
4122: $size = ' size="25"';
4123: }
1.43 raeburn 4124: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.160.6.27 raeburn 4125: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 4126: }
4127: $datatable .= '</td></tr>';
4128: $rownum ++;
4129: }
4130: $$rowtotal += $rownum;
4131: return $datatable;
4132: }
4133:
1.160.6.5 raeburn 4134: sub get_languages_hash {
4135: my %langchoices;
4136: foreach my $id (&Apache::loncommon::languageids()) {
4137: my $code = &Apache::loncommon::supportedlanguagecode($id);
4138: if ($code ne '') {
4139: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
4140: }
4141: }
4142: return %langchoices;
4143: }
4144:
1.43 raeburn 4145: sub defaults_titles {
1.141 raeburn 4146: my ($dom) = @_;
1.43 raeburn 4147: my %titles = &Apache::lonlocal::texthash (
4148: 'auth_def' => 'Default authentication type',
4149: 'auth_arg_def' => 'Default authentication argument',
4150: 'lang_def' => 'Default language',
1.54 raeburn 4151: 'timezone_def' => 'Default timezone',
1.68 raeburn 4152: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 4153: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 4154: );
1.141 raeburn 4155: if ($dom) {
4156: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
4157: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
4158: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
4159: $protocol = 'http' if ($protocol ne 'https');
4160: if ($uint_dom) {
4161: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
4162: $uint_dom);
4163: }
4164: }
1.43 raeburn 4165: return (\%titles);
4166: }
4167:
1.46 raeburn 4168: sub print_scantronformat {
4169: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
4170: my $itemcount = 1;
1.60 raeburn 4171: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
4172: %confhash);
1.46 raeburn 4173: my $switchserver = &check_switchserver($dom,$confname);
4174: my %lt = &Apache::lonlocal::texthash (
1.95 www 4175: default => 'Default bubblesheet format file error',
4176: custom => 'Custom bubblesheet format file error',
1.46 raeburn 4177: );
4178: my %scantronfiles = (
4179: default => 'default.tab',
4180: custom => 'custom.tab',
4181: );
4182: foreach my $key (keys(%scantronfiles)) {
4183: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
4184: .$scantronfiles{$key};
4185: }
4186: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
4187: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
4188: if (!$switchserver) {
4189: my $servadm = $r->dir_config('lonAdmEMail');
4190: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
4191: if ($configuserok eq 'ok') {
4192: if ($author_ok eq 'ok') {
4193: my %legacyfile = (
4194: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
4195: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
4196: );
4197: my %md5chk;
4198: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4199: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
4200: chomp($md5chk{$type});
1.46 raeburn 4201: }
4202: if ($md5chk{'default'} ne $md5chk{'custom'}) {
4203: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4204: ($scantronurls{$type},my $error) =
1.46 raeburn 4205: &legacy_scantronformat($r,$dom,$confname,
4206: $type,$legacyfile{$type},
4207: $scantronurls{$type},
4208: $scantronfiles{$type});
1.60 raeburn 4209: if ($error ne '') {
4210: $error{$type} = $error;
4211: }
4212: }
4213: if (keys(%error) == 0) {
4214: $is_custom = 1;
4215: $confhash{'scantron'}{'scantronformat'} =
4216: $scantronurls{'custom'};
4217: my $putresult =
4218: &Apache::lonnet::put_dom('configuration',
4219: \%confhash,$dom);
4220: if ($putresult ne 'ok') {
4221: $error{'custom'} =
4222: '<span class="LC_error">'.
4223: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4224: }
1.46 raeburn 4225: }
4226: } else {
1.60 raeburn 4227: ($scantronurls{'default'},my $error) =
1.46 raeburn 4228: &legacy_scantronformat($r,$dom,$confname,
4229: 'default',$legacyfile{'default'},
4230: $scantronurls{'default'},
4231: $scantronfiles{'default'});
1.60 raeburn 4232: if ($error eq '') {
4233: $confhash{'scantron'}{'scantronformat'} = '';
4234: my $putresult =
4235: &Apache::lonnet::put_dom('configuration',
4236: \%confhash,$dom);
4237: if ($putresult ne 'ok') {
4238: $error{'default'} =
4239: '<span class="LC_error">'.
4240: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4241: }
4242: } else {
4243: $error{'default'} = $error;
4244: }
1.46 raeburn 4245: }
4246: }
4247: }
4248: } else {
1.95 www 4249: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 4250: }
4251: }
4252: if (ref($settings) eq 'HASH') {
4253: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
4254: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
4255: if ((!@info) || ($info[0] eq 'no_such_dir')) {
4256: $scantronurl = '';
4257: } else {
4258: $scantronurl = $settings->{'scantronformat'};
4259: }
4260: $is_custom = 1;
4261: } else {
4262: $scantronurl = $scantronurls{'default'};
4263: }
4264: } else {
1.60 raeburn 4265: if ($is_custom) {
4266: $scantronurl = $scantronurls{'custom'};
4267: } else {
4268: $scantronurl = $scantronurls{'default'};
4269: }
1.46 raeburn 4270: }
4271: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4272: $datatable .= '<tr'.$css_class.'>';
4273: if (!$is_custom) {
1.65 raeburn 4274: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
4275: '<span class="LC_nobreak">';
1.46 raeburn 4276: if ($scantronurl) {
1.160.6.21 raeburn 4277: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
4278: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 4279: } else {
4280: $datatable = &mt('File unavailable for display');
4281: }
1.65 raeburn 4282: $datatable .= '</span></td>';
1.60 raeburn 4283: if (keys(%error) == 0) {
4284: $datatable .= '<td valign="bottom">';
4285: if (!$switchserver) {
4286: $datatable .= &mt('Upload:').'<br />';
4287: }
4288: } else {
4289: my $errorstr;
4290: foreach my $key (sort(keys(%error))) {
4291: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4292: }
4293: $datatable .= '<td>'.$errorstr;
4294: }
1.46 raeburn 4295: } else {
4296: if (keys(%error) > 0) {
4297: my $errorstr;
4298: foreach my $key (sort(keys(%error))) {
4299: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4300: }
1.60 raeburn 4301: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 4302: } elsif ($scantronurl) {
1.160.6.26 raeburn 4303: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 4304: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 4305: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 4306: $link.
4307: '<label><input type="checkbox" name="scantronformat_del"'.
4308: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 4309: '<td><span class="LC_nobreak"> '.
4310: &mt('Replace:').'</span><br />';
1.46 raeburn 4311: }
4312: }
4313: if (keys(%error) == 0) {
4314: if ($switchserver) {
4315: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4316: } else {
1.65 raeburn 4317: $datatable .='<span class="LC_nobreak"> '.
4318: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 4319: }
4320: }
4321: $datatable .= '</td></tr>';
4322: $$rowtotal ++;
4323: return $datatable;
4324: }
4325:
4326: sub legacy_scantronformat {
4327: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
4328: my ($url,$error);
4329: my @statinfo = &Apache::lonnet::stat_file($newurl);
4330: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
4331: (my $result,$url) =
4332: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
4333: '','',$newfile);
4334: if ($result ne 'ok') {
1.130 raeburn 4335: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 4336: }
4337: }
4338: return ($url,$error);
4339: }
1.43 raeburn 4340:
1.49 raeburn 4341: sub print_coursecategories {
1.57 raeburn 4342: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
4343: my $datatable;
4344: if ($position eq 'top') {
4345: my $toggle_cats_crs = ' ';
4346: my $toggle_cats_dom = ' checked="checked" ';
4347: my $can_cat_crs = ' ';
4348: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 4349: my $toggle_catscomm_comm = ' ';
4350: my $toggle_catscomm_dom = ' checked="checked" ';
4351: my $can_catcomm_comm = ' ';
4352: my $can_catcomm_dom = ' checked="checked" ';
4353:
1.57 raeburn 4354: if (ref($settings) eq 'HASH') {
4355: if ($settings->{'togglecats'} eq 'crs') {
4356: $toggle_cats_crs = $toggle_cats_dom;
4357: $toggle_cats_dom = ' ';
4358: }
4359: if ($settings->{'categorize'} eq 'crs') {
4360: $can_cat_crs = $can_cat_dom;
4361: $can_cat_dom = ' ';
4362: }
1.120 raeburn 4363: if ($settings->{'togglecatscomm'} eq 'comm') {
4364: $toggle_catscomm_comm = $toggle_catscomm_dom;
4365: $toggle_catscomm_dom = ' ';
4366: }
4367: if ($settings->{'categorizecomm'} eq 'comm') {
4368: $can_catcomm_comm = $can_catcomm_dom;
4369: $can_catcomm_dom = ' ';
4370: }
1.57 raeburn 4371: }
4372: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 4373: togglecats => 'Show/Hide a course in catalog',
4374: togglecatscomm => 'Show/Hide a community in catalog',
4375: categorize => 'Assign a category to a course',
4376: categorizecomm => 'Assign a category to a community',
1.57 raeburn 4377: );
4378: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 4379: dom => 'Set in Domain',
4380: crs => 'Set in Course',
4381: comm => 'Set in Community',
1.57 raeburn 4382: );
4383: $datatable = '<tr class="LC_odd_row">'.
4384: '<td>'.$title{'togglecats'}.'</td>'.
4385: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4386: '<input type="radio" name="togglecats"'.
4387: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4388: '<label><input type="radio" name="togglecats"'.
4389: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
4390: '</tr><tr>'.
4391: '<td>'.$title{'categorize'}.'</td>'.
4392: '<td class="LC_right_item"><span class="LC_nobreak">'.
4393: '<label><input type="radio" name="categorize"'.
4394: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4395: '<label><input type="radio" name="categorize"'.
4396: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 4397: '</tr><tr class="LC_odd_row">'.
4398: '<td>'.$title{'togglecatscomm'}.'</td>'.
4399: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4400: '<input type="radio" name="togglecatscomm"'.
4401: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4402: '<label><input type="radio" name="togglecatscomm"'.
4403: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4404: '</tr><tr>'.
4405: '<td>'.$title{'categorizecomm'}.'</td>'.
4406: '<td class="LC_right_item"><span class="LC_nobreak">'.
4407: '<label><input type="radio" name="categorizecomm"'.
4408: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4409: '<label><input type="radio" name="categorizecomm"'.
4410: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 4411: '</tr>';
1.120 raeburn 4412: $$rowtotal += 4;
1.57 raeburn 4413: } else {
4414: my $css_class;
4415: my $itemcount = 1;
4416: my $cathash;
4417: if (ref($settings) eq 'HASH') {
4418: $cathash = $settings->{'cats'};
4419: }
4420: if (ref($cathash) eq 'HASH') {
4421: my (@cats,@trails,%allitems,%idx,@jsarray);
4422: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4423: \%allitems,\%idx,\@jsarray);
4424: my $maxdepth = scalar(@cats);
4425: my $colattrib = '';
4426: if ($maxdepth > 2) {
4427: $colattrib = ' colspan="2" ';
4428: }
4429: my @path;
4430: if (@cats > 0) {
4431: if (ref($cats[0]) eq 'ARRAY') {
4432: my $numtop = @{$cats[0]};
4433: my $maxnum = $numtop;
1.120 raeburn 4434: my %default_names = (
4435: instcode => &mt('Official courses'),
4436: communities => &mt('Communities'),
4437: );
4438:
4439: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4440: ($cathash->{'instcode::0'} eq '') ||
4441: (!grep(/^communities$/,@{$cats[0]})) ||
4442: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4443: $maxnum ++;
4444: }
4445: my $lastidx;
4446: for (my $i=0; $i<$numtop; $i++) {
4447: my $parent = $cats[0][$i];
4448: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4449: my $item = &escape($parent).'::0';
4450: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4451: $lastidx = $idx{$item};
4452: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4453: .'<select name="'.$item.'"'.$chgstr.'>';
4454: for (my $k=0; $k<=$maxnum; $k++) {
4455: my $vpos = $k+1;
4456: my $selstr;
4457: if ($k == $i) {
4458: $selstr = ' selected="selected" ';
4459: }
4460: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4461: }
1.160.6.29 raeburn 4462: $datatable .= '</select></span></td><td>';
1.120 raeburn 4463: if ($parent eq 'instcode' || $parent eq 'communities') {
4464: $datatable .= '<span class="LC_nobreak">'
4465: .$default_names{$parent}.'</span>';
4466: if ($parent eq 'instcode') {
4467: $datatable .= '<br /><span class="LC_nobreak">('
4468: .&mt('with institutional codes')
4469: .')</span></td><td'.$colattrib.'>';
4470: } else {
4471: $datatable .= '<table><tr><td>';
4472: }
4473: $datatable .= '<span class="LC_nobreak">'
4474: .'<label><input type="radio" name="'
4475: .$parent.'" value="1" checked="checked" />'
4476: .&mt('Display').'</label>';
4477: if ($parent eq 'instcode') {
4478: $datatable .= ' ';
4479: } else {
4480: $datatable .= '</span></td></tr><tr><td>'
4481: .'<span class="LC_nobreak">';
4482: }
4483: $datatable .= '<label><input type="radio" name="'
4484: .$parent.'" value="0" />'
4485: .&mt('Do not display').'</label></span>';
4486: if ($parent eq 'communities') {
4487: $datatable .= '</td></tr></table>';
4488: }
4489: $datatable .= '</td>';
1.57 raeburn 4490: } else {
4491: $datatable .= $parent
1.160.6.29 raeburn 4492: .' <span class="LC_nobreak"><label>'
4493: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 4494: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4495: }
4496: my $depth = 1;
4497: push(@path,$parent);
4498: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4499: pop(@path);
4500: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4501: $itemcount ++;
4502: }
1.48 raeburn 4503: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 4504: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4505: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 4506: for (my $k=0; $k<=$maxnum; $k++) {
4507: my $vpos = $k+1;
4508: my $selstr;
1.57 raeburn 4509: if ($k == $numtop) {
1.48 raeburn 4510: $selstr = ' selected="selected" ';
4511: }
4512: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4513: }
1.59 bisitz 4514: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 4515: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4516: .'</tr>'."\n";
1.48 raeburn 4517: $itemcount ++;
1.120 raeburn 4518: foreach my $default ('instcode','communities') {
4519: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4520: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4521: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4522: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4523: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4524: for (my $k=0; $k<=$maxnum; $k++) {
4525: my $vpos = $k+1;
4526: my $selstr;
4527: if ($k == $maxnum) {
4528: $selstr = ' selected="selected" ';
4529: }
4530: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 4531: }
1.120 raeburn 4532: $datatable .= '</select></span></td>'.
4533: '<td><span class="LC_nobreak">'.
4534: $default_names{$default}.'</span>';
4535: if ($default eq 'instcode') {
4536: $datatable .= '<br /><span class="LC_nobreak">('
4537: .&mt('with institutional codes').')</span>';
4538: }
4539: $datatable .= '</td>'
4540: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4541: .&mt('Display').'</label> '
4542: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
4543: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 4544: }
4545: }
4546: }
1.57 raeburn 4547: } else {
4548: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 4549: }
4550: } else {
1.57 raeburn 4551: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
4552: .&initialize_categories($itemcount);
1.48 raeburn 4553: }
1.57 raeburn 4554: $$rowtotal += $itemcount;
1.48 raeburn 4555: }
4556: return $datatable;
4557: }
4558:
1.69 raeburn 4559: sub print_serverstatuses {
4560: my ($dom,$settings,$rowtotal) = @_;
4561: my $datatable;
4562: my @pages = &serverstatus_pages();
4563: my (%namedaccess,%machineaccess);
4564: foreach my $type (@pages) {
4565: $namedaccess{$type} = '';
4566: $machineaccess{$type}= '';
4567: }
4568: if (ref($settings) eq 'HASH') {
4569: foreach my $type (@pages) {
4570: if (exists($settings->{$type})) {
4571: if (ref($settings->{$type}) eq 'HASH') {
4572: foreach my $key (keys(%{$settings->{$type}})) {
4573: if ($key eq 'namedusers') {
4574: $namedaccess{$type} = $settings->{$type}->{$key};
4575: } elsif ($key eq 'machines') {
4576: $machineaccess{$type} = $settings->{$type}->{$key};
4577: }
4578: }
4579: }
4580: }
4581: }
4582: }
1.81 raeburn 4583: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 4584: my $rownum = 0;
4585: my $css_class;
4586: foreach my $type (@pages) {
4587: $rownum ++;
4588: $css_class = $rownum%2?' class="LC_odd_row"':'';
4589: $datatable .= '<tr'.$css_class.'>'.
4590: '<td><span class="LC_nobreak">'.
4591: $titles->{$type}.'</span></td>'.
4592: '<td class="LC_left_item">'.
4593: '<input type="text" name="'.$type.'_namedusers" '.
4594: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
4595: '<td class="LC_right_item">'.
4596: '<span class="LC_nobreak">'.
4597: '<input type="text" name="'.$type.'_machines" '.
4598: 'value="'.$machineaccess{$type}.'" size="10" />'.
4599: '</td></tr>'."\n";
4600: }
4601: $$rowtotal += $rownum;
4602: return $datatable;
4603: }
4604:
4605: sub serverstatus_pages {
4606: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 4607: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 4608: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
4609: 'uniquecodes');
1.69 raeburn 4610: }
4611:
1.49 raeburn 4612: sub coursecategories_javascript {
4613: my ($settings) = @_;
1.57 raeburn 4614: my ($output,$jstext,$cathash);
1.49 raeburn 4615: if (ref($settings) eq 'HASH') {
1.57 raeburn 4616: $cathash = $settings->{'cats'};
4617: }
4618: if (ref($cathash) eq 'HASH') {
1.49 raeburn 4619: my (@cats,@jsarray,%idx);
1.57 raeburn 4620: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 4621: if (@jsarray > 0) {
4622: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
4623: for (my $i=0; $i<@jsarray; $i++) {
4624: if (ref($jsarray[$i]) eq 'ARRAY') {
4625: my $catstr = join('","',@{$jsarray[$i]});
4626: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
4627: }
4628: }
4629: }
4630: } else {
4631: $jstext = ' var categories = Array(1);'."\n".
4632: ' categories[0] = Array("instcode_pos");'."\n";
4633: }
1.120 raeburn 4634: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
4635: my $communities_reserved = &mt('The name: "communities" is a reserved category');
4636: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 4637: $output = <<"ENDSCRIPT";
4638: <script type="text/javascript">
1.109 raeburn 4639: // <![CDATA[
1.49 raeburn 4640: function reorderCats(form,parent,item,idx) {
4641: var changedVal;
4642: $jstext
4643: var newpos = 'addcategory_pos';
4644: var current = new Array;
4645: if (parent == '') {
4646: var has_instcode = 0;
4647: var maxtop = categories[idx].length;
4648: for (var j=0; j<maxtop; j++) {
4649: if (categories[idx][j] == 'instcode::0') {
4650: has_instcode == 1;
4651: }
4652: }
4653: if (has_instcode == 0) {
4654: categories[idx][maxtop] = 'instcode_pos';
4655: }
4656: } else {
4657: newpos += '_'+parent;
4658: }
4659: var maxh = 1 + categories[idx].length;
4660: var current = new Array;
4661: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4662: if (item == newpos) {
4663: changedVal = newitemVal;
4664: } else {
4665: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4666: current[newitemVal] = newpos;
4667: }
4668: for (var i=0; i<categories[idx].length; i++) {
4669: var elementName = categories[idx][i];
4670: if (elementName != item) {
4671: if (form.elements[elementName]) {
4672: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4673: current[currVal] = elementName;
4674: }
4675: }
4676: }
4677: var oldVal;
4678: for (var j=0; j<maxh; j++) {
4679: if (current[j] == undefined) {
4680: oldVal = j;
4681: }
4682: }
4683: if (oldVal < changedVal) {
4684: for (var k=oldVal+1; k<=changedVal ; k++) {
4685: var elementName = current[k];
4686: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4687: }
4688: } else {
4689: for (var k=changedVal; k<oldVal; k++) {
4690: var elementName = current[k];
4691: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4692: }
4693: }
4694: return;
4695: }
1.120 raeburn 4696:
4697: function categoryCheck(form) {
4698: if (form.elements['addcategory_name'].value == 'instcode') {
4699: alert('$instcode_reserved\\n$choose_again');
4700: return false;
4701: }
4702: if (form.elements['addcategory_name'].value == 'communities') {
4703: alert('$communities_reserved\\n$choose_again');
4704: return false;
4705: }
4706: return true;
4707: }
4708:
1.109 raeburn 4709: // ]]>
1.49 raeburn 4710: </script>
4711:
4712: ENDSCRIPT
4713: return $output;
4714: }
4715:
1.48 raeburn 4716: sub initialize_categories {
4717: my ($itemcount) = @_;
1.120 raeburn 4718: my ($datatable,$css_class,$chgstr);
4719: my %default_names = (
4720: instcode => 'Official courses (with institutional codes)',
4721: communities => 'Communities',
4722: );
4723: my $select0 = ' selected="selected"';
4724: my $select1 = '';
4725: foreach my $default ('instcode','communities') {
4726: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4727: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
4728: if ($default eq 'communities') {
4729: $select1 = $select0;
4730: $select0 = '';
4731: }
4732: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4733: .'<select name="'.$default.'_pos">'
4734: .'<option value="0"'.$select0.'>1</option>'
4735: .'<option value="1"'.$select1.'>2</option>'
4736: .'<option value="2">3</option></select> '
4737: .$default_names{$default}
4738: .'</span></td><td><span class="LC_nobreak">'
4739: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4740: .&mt('Display').'</label> <label>'
4741: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 4742: .'</label></span></td></tr>';
1.120 raeburn 4743: $itemcount ++;
4744: }
1.48 raeburn 4745: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 4746: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 4747: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 4748: .'<select name="addcategory_pos"'.$chgstr.'>'
4749: .'<option value="0">1</option>'
4750: .'<option value="1">2</option>'
4751: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 4752: .&mt('Add category').'</td><td>'.&mt('Name:')
4753: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4754: return $datatable;
4755: }
4756:
4757: sub build_category_rows {
1.49 raeburn 4758: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4759: my ($text,$name,$item,$chgstr);
1.48 raeburn 4760: if (ref($cats) eq 'ARRAY') {
4761: my $maxdepth = scalar(@{$cats});
4762: if (ref($cats->[$depth]) eq 'HASH') {
4763: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4764: my $numchildren = @{$cats->[$depth]{$parent}};
4765: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 4766: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 4767: my ($idxnum,$parent_name,$parent_item);
4768: my $higher = $depth - 1;
4769: if ($higher == 0) {
4770: $parent_name = &escape($parent).'::'.$higher;
4771: } else {
4772: if (ref($path) eq 'ARRAY') {
4773: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4774: }
4775: }
4776: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4777: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4778: if ($j < $numchildren) {
1.48 raeburn 4779: $name = $cats->[$depth]{$parent}[$j];
4780: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4781: $idxnum = $idx->{$item};
4782: } else {
4783: $name = $parent_name;
4784: $item = $parent_item;
1.48 raeburn 4785: }
1.49 raeburn 4786: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4787: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4788: for (my $i=0; $i<=$numchildren; $i++) {
4789: my $vpos = $i+1;
4790: my $selstr;
4791: if ($j == $i) {
4792: $selstr = ' selected="selected" ';
4793: }
4794: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4795: }
4796: $text .= '</select> ';
4797: if ($j < $numchildren) {
4798: my $deeper = $depth+1;
4799: $text .= $name.' '
4800: .'<label><input type="checkbox" name="deletecategory" value="'
4801: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4802: if(ref($path) eq 'ARRAY') {
4803: push(@{$path},$name);
1.49 raeburn 4804: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4805: pop(@{$path});
4806: }
4807: } else {
1.59 bisitz 4808: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4809: if ($j == $numchildren) {
4810: $text .= $name;
4811: } else {
4812: $text .= $item;
4813: }
4814: $text .= '" value="" />';
4815: }
4816: $text .= '</td></tr>';
4817: }
4818: $text .= '</table></td>';
4819: } else {
4820: my $higher = $depth-1;
4821: if ($higher == 0) {
4822: $name = &escape($parent).'::'.$higher;
4823: } else {
4824: if (ref($path) eq 'ARRAY') {
4825: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4826: }
4827: }
4828: my $colspan;
4829: if ($parent ne 'instcode') {
4830: $colspan = $maxdepth - $depth - 1;
4831: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4832: }
4833: }
4834: }
4835: }
4836: return $text;
4837: }
4838:
1.33 raeburn 4839: sub modifiable_userdata_row {
1.160.6.34! raeburn 4840: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
1.33 raeburn 4841: my $rolename;
1.160.6.34! raeburn 4842: if ($context eq 'cancreate') {
! 4843: if ($role eq 'emailusername') {
! 4844: $rolename = &mt('Data user provides');
! 4845: }
! 4846: } elsif ($context eq 'selfcreate') {
1.63 raeburn 4847: if (ref($usertypes) eq 'HASH') {
4848: $rolename = $usertypes->{$role};
4849: } else {
4850: $rolename = $role;
4851: }
1.33 raeburn 4852: } else {
1.63 raeburn 4853: if ($role eq 'cr') {
4854: $rolename = &mt('Custom role');
4855: } else {
4856: $rolename = &Apache::lonnet::plaintext($role);
4857: }
1.33 raeburn 4858: }
1.160.6.34! raeburn 4859: my (@fields,%fieldtitles);
! 4860: if (ref($fieldsref) eq 'ARRAY') {
! 4861: @fields = @{$fieldsref};
! 4862: } else {
! 4863: @fields = ('lastname','firstname','middlename','generation',
! 4864: 'permanentemail','id');
! 4865: }
! 4866: if ((ref($titlesref) eq 'HASH')) {
! 4867: %fieldtitles = %{$titlesref};
! 4868: } else {
! 4869: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
! 4870: }
1.33 raeburn 4871: my $output;
4872: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4873: $output = '<tr '.$css_class.'>'.
4874: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4875: '<td class="LC_left_item" colspan="2"><table>';
4876: my $rem;
4877: my %checks;
4878: if (ref($settings) eq 'HASH') {
4879: if (ref($settings->{$context}) eq 'HASH') {
4880: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4881: foreach my $field (@fields) {
4882: if ($settings->{$context}->{$role}->{$field}) {
4883: $checks{$field} = ' checked="checked" ';
4884: }
4885: }
4886: }
4887: }
4888: }
4889: for (my $i=0; $i<@fields; $i++) {
4890: my $rem = $i%($numinrow);
4891: if ($rem == 0) {
4892: if ($i > 0) {
4893: $output .= '</tr>';
4894: }
4895: $output .= '<tr>';
4896: }
4897: my $check = ' ';
4898: if (exists($checks{$fields[$i]})) {
4899: $check = $checks{$fields[$i]}
4900: } else {
4901: if ($role eq 'st') {
4902: if (ref($settings) ne 'HASH') {
4903: $check = ' checked="checked" ';
4904: }
4905: }
4906: }
4907: $output .= '<td class="LC_left_item">'.
4908: '<span class="LC_nobreak"><label>'.
4909: '<input type="checkbox" name="canmodify_'.$role.'" '.
4910: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4911: '</label></span></td>';
4912: $rem = @fields%($numinrow);
4913: }
4914: my $colsleft = $numinrow - $rem;
4915: if ($colsleft > 1 ) {
4916: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4917: ' </td>';
4918: } elsif ($colsleft == 1) {
4919: $output .= '<td class="LC_left_item"> </td>';
4920: }
4921: $output .= '</tr></table></td></tr>';
4922: return $output;
4923: }
1.28 raeburn 4924:
1.93 raeburn 4925: sub insttypes_row {
1.160.6.34! raeburn 4926: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 4927: my %lt = &Apache::lonlocal::texthash (
4928: cansearch => 'Users allowed to search',
4929: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4930: lockablenames => 'User preference to lock name',
1.93 raeburn 4931: );
4932: my $showdom;
4933: if ($context eq 'cansearch') {
4934: $showdom = ' ('.$dom.')';
4935: }
1.160.6.5 raeburn 4936: my $class = 'LC_left_item';
4937: if ($context eq 'statustocreate') {
4938: $class = 'LC_right_item';
4939: }
1.160.6.34! raeburn 4940: my $css_class = ' class="LC_odd_row"';
! 4941: if ($rownum ne '') {
! 4942: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
! 4943: }
! 4944: my $output = '<tr'.$css_class.'>'.
! 4945: '<td>'.$lt{$context}.$showdom.
! 4946: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 4947: my $rem;
4948: if (ref($types) eq 'ARRAY') {
4949: for (my $i=0; $i<@{$types}; $i++) {
4950: if (defined($usertypes->{$types->[$i]})) {
4951: my $rem = $i%($numinrow);
4952: if ($rem == 0) {
4953: if ($i > 0) {
4954: $output .= '</tr>';
4955: }
4956: $output .= '<tr>';
1.23 raeburn 4957: }
1.26 raeburn 4958: my $check = ' ';
1.99 raeburn 4959: if (ref($settings) eq 'HASH') {
4960: if (ref($settings->{$context}) eq 'ARRAY') {
4961: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4962: $check = ' checked="checked" ';
4963: }
4964: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4965: $check = ' checked="checked" ';
4966: }
1.23 raeburn 4967: }
1.26 raeburn 4968: $output .= '<td class="LC_left_item">'.
4969: '<span class="LC_nobreak"><label>'.
1.93 raeburn 4970: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 4971: 'value="'.$types->[$i].'"'.$check.'/>'.
4972: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 4973: }
4974: }
1.26 raeburn 4975: $rem = @{$types}%($numinrow);
1.23 raeburn 4976: }
4977: my $colsleft = $numinrow - $rem;
1.131 raeburn 4978: if (($rem == 0) && (@{$types} > 0)) {
4979: $output .= '<tr>';
4980: }
1.23 raeburn 4981: if ($colsleft > 1) {
1.25 raeburn 4982: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 4983: } else {
1.25 raeburn 4984: $output .= '<td class="LC_left_item">';
1.23 raeburn 4985: }
4986: my $defcheck = ' ';
1.99 raeburn 4987: if (ref($settings) eq 'HASH') {
4988: if (ref($settings->{$context}) eq 'ARRAY') {
4989: if (grep(/^default$/,@{$settings->{$context}})) {
4990: $defcheck = ' checked="checked" ';
4991: }
4992: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4993: $defcheck = ' checked="checked" ';
4994: }
1.23 raeburn 4995: }
1.25 raeburn 4996: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 4997: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 4998: 'value="default"'.$defcheck.'/>'.
4999: $othertitle.'</label></span></td>'.
5000: '</tr></table></td></tr>';
5001: return $output;
1.23 raeburn 5002: }
5003:
5004: sub sorted_searchtitles {
5005: my %searchtitles = &Apache::lonlocal::texthash(
5006: 'uname' => 'username',
5007: 'lastname' => 'last name',
5008: 'lastfirst' => 'last name, first name',
5009: );
5010: my @titleorder = ('uname','lastname','lastfirst');
5011: return (\%searchtitles,\@titleorder);
5012: }
5013:
1.25 raeburn 5014: sub sorted_searchtypes {
5015: my %srchtypes_desc = (
5016: exact => 'is exact match',
5017: contains => 'contains ..',
5018: begins => 'begins with ..',
5019: );
5020: my @srchtypeorder = ('exact','begins','contains');
5021: return (\%srchtypes_desc,\@srchtypeorder);
5022: }
5023:
1.3 raeburn 5024: sub usertype_update_row {
5025: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
5026: my $datatable;
5027: my $numinrow = 4;
5028: foreach my $type (@{$types}) {
5029: if (defined($usertypes->{$type})) {
5030: $$rownums ++;
5031: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
5032: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
5033: '</td><td class="LC_left_item"><table>';
5034: for (my $i=0; $i<@{$fields}; $i++) {
5035: my $rem = $i%($numinrow);
5036: if ($rem == 0) {
5037: if ($i > 0) {
5038: $datatable .= '</tr>';
5039: }
5040: $datatable .= '<tr>';
5041: }
5042: my $check = ' ';
1.39 raeburn 5043: if (ref($settings) eq 'HASH') {
5044: if (ref($settings->{'fields'}) eq 'HASH') {
5045: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
5046: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
5047: $check = ' checked="checked" ';
5048: }
1.3 raeburn 5049: }
5050: }
5051: }
5052:
5053: if ($i == @{$fields}-1) {
5054: my $colsleft = $numinrow - $rem;
5055: if ($colsleft > 1) {
5056: $datatable .= '<td colspan="'.$colsleft.'">';
5057: } else {
5058: $datatable .= '<td>';
5059: }
5060: } else {
5061: $datatable .= '<td>';
5062: }
1.8 raeburn 5063: $datatable .= '<span class="LC_nobreak"><label>'.
5064: '<input type="checkbox" name="updateable_'.$type.
5065: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
5066: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 5067: }
5068: $datatable .= '</tr></table></td></tr>';
5069: }
5070: }
5071: return $datatable;
1.1 raeburn 5072: }
5073:
5074: sub modify_login {
1.160.6.24 raeburn 5075: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 5076: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
5077: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
5078: %title = ( coursecatalog => 'Display course catalog',
5079: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 5080: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 5081: newuser => 'Link for visitors to create a user account',
5082: loginheader => 'Log-in box header');
5083: @offon = ('off','on');
1.112 raeburn 5084: if (ref($domconfig{login}) eq 'HASH') {
5085: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
5086: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
5087: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
5088: }
5089: }
5090: }
1.9 raeburn 5091: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
5092: \%domconfig,\%loginhash);
1.160.6.14 raeburn 5093: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5094: foreach my $item (@toggles) {
5095: $loginhash{login}{$item} = $env{'form.'.$item};
5096: }
1.41 raeburn 5097: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 5098: if (ref($colchanges{'login'}) eq 'HASH') {
5099: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
5100: \%loginhash);
5101: }
1.110 raeburn 5102:
1.149 raeburn 5103: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 5104: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 5105: if (keys(%servers) > 1) {
5106: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 5107: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
5108: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
5109: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
5110: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
5111: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
5112: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5113: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5114: $changes{'loginvia'}{$lonhost} = 1;
5115: } else {
5116: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
5117: $changes{'loginvia'}{$lonhost} = 1;
5118: }
5119: } else {
5120: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5121: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5122: $changes{'loginvia'}{$lonhost} = 1;
5123: }
5124: }
5125: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
5126: foreach my $item (@loginvia_attribs) {
5127: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
5128: }
5129: } else {
5130: foreach my $item (@loginvia_attribs) {
5131: my $new = $env{'form.'.$lonhost.'_'.$item};
5132: if (($item eq 'serverpath') && ($new eq 'custom')) {
5133: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
5134: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5135: $new = '/';
5136: }
5137: }
5138: if (($item eq 'custompath') &&
5139: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5140: $new = '';
5141: }
5142: if ($new ne $curr_loginvia{$lonhost}{$item}) {
5143: $changes{'loginvia'}{$lonhost} = 1;
5144: }
5145: if ($item eq 'exempt') {
5146: $new =~ s/^\s+//;
5147: $new =~ s/\s+$//;
5148: my @poss_ips = split(/\s*[,:]\s*/,$new);
5149: my @okips;
5150: foreach my $ip (@poss_ips) {
5151: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
5152: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
5153: push(@okips,$ip);
5154: }
5155: }
5156: }
5157: if (@okips > 0) {
5158: $new = join(',',@okips);
5159: } else {
5160: $new = '';
5161: }
5162: }
5163: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5164: }
5165: }
1.112 raeburn 5166: } else {
1.128 raeburn 5167: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5168: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 5169: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 5170: foreach my $item (@loginvia_attribs) {
5171: my $new = $env{'form.'.$lonhost.'_'.$item};
5172: if (($item eq 'serverpath') && ($new eq 'custom')) {
5173: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5174: $new = '/';
5175: }
5176: }
5177: if (($item eq 'custompath') &&
5178: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5179: $new = '';
5180: }
5181: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5182: }
1.110 raeburn 5183: }
5184: }
5185: }
5186: }
1.119 raeburn 5187:
1.160.6.5 raeburn 5188: my $servadm = $r->dir_config('lonAdmEMail');
5189: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
5190: if (ref($domconfig{'login'}) eq 'HASH') {
5191: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
5192: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
5193: if ($lang eq 'nolang') {
5194: push(@currlangs,$lang);
5195: } elsif (defined($langchoices{$lang})) {
5196: push(@currlangs,$lang);
5197: } else {
5198: next;
5199: }
5200: }
5201: }
5202: }
5203: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
5204: if (@currlangs > 0) {
5205: foreach my $lang (@currlangs) {
5206: if (grep(/^\Q$lang\E$/,@delurls)) {
5207: $changes{'helpurl'}{$lang} = 1;
5208: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
5209: $changes{'helpurl'}{$lang} = 1;
5210: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
5211: push(@newlangs,$lang);
5212: } else {
5213: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5214: }
5215: }
5216: }
5217: unless (grep(/^nolang$/,@currlangs)) {
5218: if ($env{'form.loginhelpurl_nolang.filename'}) {
5219: $changes{'helpurl'}{'nolang'} = 1;
5220: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
5221: push(@newlangs,'nolang');
5222: }
5223: }
5224: if ($env{'form.loginhelpurl_add_lang'}) {
5225: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
5226: ($env{'form.loginhelpurl_add_file.filename'})) {
5227: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
5228: $addedfile = $env{'form.loginhelpurl_add_lang'};
5229: }
5230: }
5231: if ((@newlangs > 0) || ($addedfile)) {
5232: my $error;
5233: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
5234: if ($configuserok eq 'ok') {
5235: if ($switchserver) {
5236: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
5237: } elsif ($author_ok eq 'ok') {
5238: my @allnew = @newlangs;
5239: if ($addedfile ne '') {
5240: push(@allnew,$addedfile);
5241: }
5242: foreach my $lang (@allnew) {
5243: my $formelem = 'loginhelpurl_'.$lang;
5244: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
5245: $formelem = 'loginhelpurl_add_file';
5246: }
5247: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
5248: "help/$lang",'','',$newfile{$lang});
5249: if ($result eq 'ok') {
5250: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
5251: $changes{'helpurl'}{$lang} = 1;
5252: } else {
5253: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
5254: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
5255: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
5256: (!grep(/^\Q$lang\E$/,@delurls))) {
5257:
5258: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5259: }
5260: }
5261: }
5262: } else {
5263: $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);
5264: }
5265: } else {
5266: $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);
5267: }
5268: if ($error) {
5269: &Apache::lonnet::logthis($error);
5270: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
5271: }
5272: }
5273: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
5274:
5275: my $defaulthelpfile = '/adm/loginproblems.html';
5276: my $defaulttext = &mt('Default in use');
5277:
1.1 raeburn 5278: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
5279: $dom);
5280: if ($putresult eq 'ok') {
1.160.6.14 raeburn 5281: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5282: my %defaultchecked = (
5283: 'coursecatalog' => 'on',
1.160.6.14 raeburn 5284: 'helpdesk' => 'on',
1.42 raeburn 5285: 'adminmail' => 'off',
1.43 raeburn 5286: 'newuser' => 'off',
1.42 raeburn 5287: );
1.55 raeburn 5288: if (ref($domconfig{'login'}) eq 'HASH') {
5289: foreach my $item (@toggles) {
5290: if ($defaultchecked{$item} eq 'on') {
5291: if (($domconfig{'login'}{$item} eq '0') &&
5292: ($env{'form.'.$item} eq '1')) {
5293: $changes{$item} = 1;
5294: } elsif (($domconfig{'login'}{$item} eq '' ||
5295: $domconfig{'login'}{$item} eq '1') &&
5296: ($env{'form.'.$item} eq '0')) {
5297: $changes{$item} = 1;
5298: }
5299: } elsif ($defaultchecked{$item} eq 'off') {
5300: if (($domconfig{'login'}{$item} eq '1') &&
5301: ($env{'form.'.$item} eq '0')) {
5302: $changes{$item} = 1;
5303: } elsif (($domconfig{'login'}{$item} eq '' ||
5304: $domconfig{'login'}{$item} eq '0') &&
5305: ($env{'form.'.$item} eq '1')) {
5306: $changes{$item} = 1;
5307: }
1.42 raeburn 5308: }
5309: }
1.41 raeburn 5310: }
1.6 raeburn 5311: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 5312: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 5313: if (ref($lastactref) eq 'HASH') {
5314: $lastactref->{'domainconfig'} = 1;
5315: }
1.1 raeburn 5316: $resulttext = &mt('Changes made:').'<ul>';
5317: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 5318: if ($item eq 'loginvia') {
1.112 raeburn 5319: if (ref($changes{$item}) eq 'HASH') {
5320: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
5321: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 5322: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
5323: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
5324: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
5325: $protocol = 'http' if ($protocol ne 'https');
5326: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
5327:
5328: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
5329: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
5330: } else {
5331: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
5332: }
5333: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
5334: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
5335: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
5336: }
5337: $resulttext .= '</li>';
5338: } else {
5339: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
5340: }
1.112 raeburn 5341: } else {
1.128 raeburn 5342: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 5343: }
5344: }
1.128 raeburn 5345: $resulttext .= '</ul></li>';
1.112 raeburn 5346: }
1.160.6.5 raeburn 5347: } elsif ($item eq 'helpurl') {
5348: if (ref($changes{$item}) eq 'HASH') {
5349: foreach my $lang (sort(keys(%{$changes{$item}}))) {
5350: if (grep(/^\Q$lang\E$/,@delurls)) {
5351: my ($chg,$link);
5352: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
5353: if ($lang eq 'nolang') {
5354: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
5355: } else {
5356: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
5357: }
5358: $resulttext .= '<li>'.$chg.'</li>';
5359: } else {
5360: my $chg;
5361: if ($lang eq 'nolang') {
5362: $chg = &mt('custom log-in help file for no preferred language');
5363: } else {
5364: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
5365: }
5366: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
5367: $loginhash{'login'}{'helpurl'}{$lang}.
5368: '?inhibitmenu=yes',$chg,600,500).
5369: '</li>';
5370: }
5371: }
5372: }
5373: } elsif ($item eq 'captcha') {
5374: if (ref($loginhash{'login'}) eq 'HASH') {
5375: my $chgtxt;
5376: if ($loginhash{'login'}{$item} eq 'notused') {
5377: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
5378: } else {
5379: my %captchas = &captcha_phrases();
5380: if ($captchas{$loginhash{'login'}{$item}}) {
5381: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
5382: } else {
5383: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
5384: }
5385: }
5386: $resulttext .= '<li>'.$chgtxt.'</li>';
5387: }
5388: } elsif ($item eq 'recaptchakeys') {
5389: if (ref($loginhash{'login'}) eq 'HASH') {
5390: my ($privkey,$pubkey);
5391: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
5392: $pubkey = $loginhash{'login'}{$item}{'public'};
5393: $privkey = $loginhash{'login'}{$item}{'private'};
5394: }
5395: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
5396: if (!$pubkey) {
5397: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
5398: } else {
5399: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
5400: }
5401: if (!$privkey) {
5402: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
5403: } else {
5404: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
5405: }
5406: $chgtxt .= '</ul>';
5407: $resulttext .= '<li>'.$chgtxt.'</li>';
5408: }
1.41 raeburn 5409: } else {
5410: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
5411: }
1.1 raeburn 5412: }
1.6 raeburn 5413: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 5414: } else {
5415: $resulttext = &mt('No changes made to log-in page settings');
5416: }
5417: } else {
1.11 albertel 5418: $resulttext = '<span class="LC_error">'.
5419: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5420: }
1.6 raeburn 5421: if ($errors) {
1.9 raeburn 5422: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 5423: $errors.'</ul>';
5424: }
5425: return $resulttext;
5426: }
5427:
5428: sub color_font_choices {
5429: my %choices =
5430: &Apache::lonlocal::texthash (
5431: img => "Header",
5432: bgs => "Background colors",
5433: links => "Link colors",
1.55 raeburn 5434: images => "Images",
1.6 raeburn 5435: font => "Font color",
1.160.6.22 raeburn 5436: fontmenu => "Font menu",
1.76 raeburn 5437: pgbg => "Page",
1.6 raeburn 5438: tabbg => "Header",
5439: sidebg => "Border",
5440: link => "Link",
5441: alink => "Active link",
5442: vlink => "Visited link",
5443: );
5444: return %choices;
5445: }
5446:
5447: sub modify_rolecolors {
1.160.6.24 raeburn 5448: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 5449: my ($resulttext,%rolehash);
5450: $rolehash{'rolecolors'} = {};
1.55 raeburn 5451: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
5452: if ($domconfig{'rolecolors'} eq '') {
5453: $domconfig{'rolecolors'} = {};
5454: }
5455: }
1.9 raeburn 5456: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 5457: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
5458: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
5459: $dom);
5460: if ($putresult eq 'ok') {
5461: if (keys(%changes) > 0) {
1.41 raeburn 5462: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 5463: if (ref($lastactref) eq 'HASH') {
5464: $lastactref->{'domainconfig'} = 1;
5465: }
1.6 raeburn 5466: $resulttext = &display_colorchgs($dom,\%changes,$roles,
5467: $rolehash{'rolecolors'});
5468: } else {
5469: $resulttext = &mt('No changes made to default color schemes');
5470: }
5471: } else {
1.11 albertel 5472: $resulttext = '<span class="LC_error">'.
5473: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 5474: }
5475: if ($errors) {
5476: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5477: $errors.'</ul>';
5478: }
5479: return $resulttext;
5480: }
5481:
5482: sub modify_colors {
1.9 raeburn 5483: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 5484: my (%changes,%choices);
1.51 raeburn 5485: my @bgs;
1.6 raeburn 5486: my @links = ('link','alink','vlink');
1.41 raeburn 5487: my @logintext;
1.6 raeburn 5488: my @images;
5489: my $servadm = $r->dir_config('lonAdmEMail');
5490: my $errors;
1.160.6.22 raeburn 5491: my %defaults;
1.6 raeburn 5492: foreach my $role (@{$roles}) {
5493: if ($role eq 'login') {
1.12 raeburn 5494: %choices = &login_choices();
1.41 raeburn 5495: @logintext = ('textcol','bgcol');
1.12 raeburn 5496: } else {
5497: %choices = &color_font_choices();
5498: }
5499: if ($role eq 'login') {
1.41 raeburn 5500: @images = ('img','logo','domlogo','login');
1.51 raeburn 5501: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 5502: } else {
5503: @images = ('img');
1.160.6.22 raeburn 5504: @bgs = ('pgbg','tabbg','sidebg');
5505: }
5506: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
5507: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
5508: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
5509: }
5510: if ($role eq 'login') {
5511: foreach my $item (@logintext) {
5512: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'logintext'}{$item}) {
5513: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5514: }
5515: }
5516: } else {
5517: unless($env{'form.'.$role.'_fontmenu'} eq $defaults{'fontmenu'}) {
5518: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
5519: }
1.6 raeburn 5520: }
1.160.6.22 raeburn 5521: foreach my $item (@bgs) {
5522: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'bgs'}{$item} ) {
5523: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5524: }
5525: }
5526: foreach my $item (@links) {
5527: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'links'}{$item}) {
5528: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5529: }
1.6 raeburn 5530: }
1.46 raeburn 5531: my ($configuserok,$author_ok,$switchserver) =
5532: &config_check($dom,$confname,$servadm);
1.9 raeburn 5533: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 5534: if (ref($domconfig->{$role}) ne 'HASH') {
5535: $domconfig->{$role} = {};
5536: }
1.8 raeburn 5537: foreach my $img (@images) {
1.70 raeburn 5538: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
5539: if (defined($env{'form.login_showlogo_'.$img})) {
5540: $confhash->{$role}{'showlogo'}{$img} = 1;
5541: } else {
5542: $confhash->{$role}{'showlogo'}{$img} = 0;
5543: }
5544: }
1.18 albertel 5545: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
5546: && !defined($domconfig->{$role}{$img})
5547: && !$env{'form.'.$role.'_del_'.$img}
5548: && $env{'form.'.$role.'_import_'.$img}) {
5549: # import the old configured image from the .tab setting
5550: # if they haven't provided a new one
5551: $domconfig->{$role}{$img} =
5552: $env{'form.'.$role.'_import_'.$img};
5553: }
1.6 raeburn 5554: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 5555: my $error;
1.6 raeburn 5556: if ($configuserok eq 'ok') {
1.9 raeburn 5557: if ($switchserver) {
1.12 raeburn 5558: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 5559: } else {
5560: if ($author_ok eq 'ok') {
5561: my ($result,$logourl) =
5562: &publishlogo($r,'upload',$role.'_'.$img,
5563: $dom,$confname,$img,$width,$height);
5564: if ($result eq 'ok') {
5565: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 5566: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5567: } else {
1.12 raeburn 5568: $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 5569: }
5570: } else {
1.46 raeburn 5571: $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 5572: }
5573: }
5574: } else {
1.46 raeburn 5575: $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 5576: }
5577: if ($error) {
1.8 raeburn 5578: &Apache::lonnet::logthis($error);
1.11 albertel 5579: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 5580: }
5581: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 5582: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
5583: my $error;
5584: if ($configuserok eq 'ok') {
5585: # is confname an author?
5586: if ($switchserver eq '') {
5587: if ($author_ok eq 'ok') {
5588: my ($result,$logourl) =
5589: &publishlogo($r,'copy',$domconfig->{$role}{$img},
5590: $dom,$confname,$img,$width,$height);
5591: if ($result eq 'ok') {
5592: $confhash->{$role}{$img} = $logourl;
1.18 albertel 5593: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5594: }
5595: }
5596: }
5597: }
1.6 raeburn 5598: }
5599: }
5600: }
5601: if (ref($domconfig) eq 'HASH') {
5602: if (ref($domconfig->{$role}) eq 'HASH') {
5603: foreach my $img (@images) {
5604: if ($domconfig->{$role}{$img} ne '') {
5605: if ($env{'form.'.$role.'_del_'.$img}) {
5606: $confhash->{$role}{$img} = '';
1.12 raeburn 5607: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5608: } else {
1.9 raeburn 5609: if ($confhash->{$role}{$img} eq '') {
5610: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
5611: }
1.6 raeburn 5612: }
5613: } else {
5614: if ($env{'form.'.$role.'_del_'.$img}) {
5615: $confhash->{$role}{$img} = '';
1.12 raeburn 5616: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5617: }
5618: }
1.70 raeburn 5619: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
5620: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
5621: if ($confhash->{$role}{'showlogo'}{$img} ne
5622: $domconfig->{$role}{'showlogo'}{$img}) {
5623: $changes{$role}{'showlogo'}{$img} = 1;
5624: }
5625: } else {
5626: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5627: $changes{$role}{'showlogo'}{$img} = 1;
5628: }
5629: }
5630: }
5631: }
1.6 raeburn 5632: if ($domconfig->{$role}{'font'} ne '') {
5633: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
5634: $changes{$role}{'font'} = 1;
5635: }
5636: } else {
5637: if ($confhash->{$role}{'font'}) {
5638: $changes{$role}{'font'} = 1;
5639: }
5640: }
1.107 raeburn 5641: if ($role ne 'login') {
5642: if ($domconfig->{$role}{'fontmenu'} ne '') {
5643: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
5644: $changes{$role}{'fontmenu'} = 1;
5645: }
5646: } else {
5647: if ($confhash->{$role}{'fontmenu'}) {
5648: $changes{$role}{'fontmenu'} = 1;
5649: }
1.97 tempelho 5650: }
5651: }
1.6 raeburn 5652: foreach my $item (@bgs) {
5653: if ($domconfig->{$role}{$item} ne '') {
5654: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5655: $changes{$role}{'bgs'}{$item} = 1;
5656: }
5657: } else {
5658: if ($confhash->{$role}{$item}) {
5659: $changes{$role}{'bgs'}{$item} = 1;
5660: }
5661: }
5662: }
5663: foreach my $item (@links) {
5664: if ($domconfig->{$role}{$item} ne '') {
5665: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5666: $changes{$role}{'links'}{$item} = 1;
5667: }
5668: } else {
5669: if ($confhash->{$role}{$item}) {
5670: $changes{$role}{'links'}{$item} = 1;
5671: }
5672: }
5673: }
1.41 raeburn 5674: foreach my $item (@logintext) {
5675: if ($domconfig->{$role}{$item} ne '') {
5676: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5677: $changes{$role}{'logintext'}{$item} = 1;
5678: }
5679: } else {
5680: if ($confhash->{$role}{$item}) {
5681: $changes{$role}{'logintext'}{$item} = 1;
5682: }
5683: }
5684: }
1.6 raeburn 5685: } else {
5686: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5687: \@logintext,$confhash,\%changes);
1.6 raeburn 5688: }
5689: } else {
5690: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5691: \@logintext,$confhash,\%changes);
1.6 raeburn 5692: }
5693: }
5694: return ($errors,%changes);
5695: }
5696:
1.46 raeburn 5697: sub config_check {
5698: my ($dom,$confname,$servadm) = @_;
5699: my ($configuserok,$author_ok,$switchserver,%currroles);
5700: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
5701: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
5702: $confname,$servadm);
5703: if ($configuserok eq 'ok') {
5704: $switchserver = &check_switchserver($dom,$confname);
5705: if ($switchserver eq '') {
5706: $author_ok = &check_authorstatus($dom,$confname,%currroles);
5707: }
5708: }
5709: return ($configuserok,$author_ok,$switchserver);
5710: }
5711:
1.6 raeburn 5712: sub default_change_checker {
1.41 raeburn 5713: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 5714: foreach my $item (@{$links}) {
5715: if ($confhash->{$role}{$item}) {
5716: $changes->{$role}{'links'}{$item} = 1;
5717: }
5718: }
5719: foreach my $item (@{$bgs}) {
5720: if ($confhash->{$role}{$item}) {
5721: $changes->{$role}{'bgs'}{$item} = 1;
5722: }
5723: }
1.41 raeburn 5724: foreach my $item (@{$logintext}) {
5725: if ($confhash->{$role}{$item}) {
5726: $changes->{$role}{'logintext'}{$item} = 1;
5727: }
5728: }
1.6 raeburn 5729: foreach my $img (@{$images}) {
5730: if ($env{'form.'.$role.'_del_'.$img}) {
5731: $confhash->{$role}{$img} = '';
1.12 raeburn 5732: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 5733: }
1.70 raeburn 5734: if ($role eq 'login') {
5735: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5736: $changes->{$role}{'showlogo'}{$img} = 1;
5737: }
5738: }
1.6 raeburn 5739: }
5740: if ($confhash->{$role}{'font'}) {
5741: $changes->{$role}{'font'} = 1;
5742: }
1.48 raeburn 5743: }
1.6 raeburn 5744:
5745: sub display_colorchgs {
5746: my ($dom,$changes,$roles,$confhash) = @_;
5747: my (%choices,$resulttext);
5748: if (!grep(/^login$/,@{$roles})) {
5749: $resulttext = &mt('Changes made:').'<br />';
5750: }
5751: foreach my $role (@{$roles}) {
5752: if ($role eq 'login') {
5753: %choices = &login_choices();
5754: } else {
5755: %choices = &color_font_choices();
5756: }
5757: if (ref($changes->{$role}) eq 'HASH') {
5758: if ($role ne 'login') {
5759: $resulttext .= '<h4>'.&mt($role).'</h4>';
5760: }
5761: foreach my $key (sort(keys(%{$changes->{$role}}))) {
5762: if ($role ne 'login') {
5763: $resulttext .= '<ul>';
5764: }
5765: if (ref($changes->{$role}{$key}) eq 'HASH') {
5766: if ($role ne 'login') {
5767: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
5768: }
5769: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 5770: if (($role eq 'login') && ($key eq 'showlogo')) {
5771: if ($confhash->{$role}{$key}{$item}) {
5772: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
5773: } else {
5774: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
5775: }
5776: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 5777: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
5778: } else {
1.12 raeburn 5779: my $newitem = $confhash->{$role}{$item};
5780: if ($key eq 'images') {
5781: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
5782: }
5783: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 5784: }
5785: }
5786: if ($role ne 'login') {
5787: $resulttext .= '</ul></li>';
5788: }
5789: } else {
5790: if ($confhash->{$role}{$key} eq '') {
5791: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
5792: } else {
5793: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
5794: }
5795: }
5796: if ($role ne 'login') {
5797: $resulttext .= '</ul>';
5798: }
5799: }
5800: }
5801: }
1.3 raeburn 5802: return $resulttext;
1.1 raeburn 5803: }
5804:
1.9 raeburn 5805: sub thumb_dimensions {
5806: return ('200','50');
5807: }
5808:
1.16 raeburn 5809: sub check_dimensions {
5810: my ($inputfile) = @_;
5811: my ($fullwidth,$fullheight);
5812: if ($inputfile =~ m|^[/\w.\-]+$|) {
5813: if (open(PIPE,"identify $inputfile 2>&1 |")) {
5814: my $imageinfo = <PIPE>;
5815: if (!close(PIPE)) {
5816: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
5817: }
5818: chomp($imageinfo);
5819: my ($fullsize) =
1.21 raeburn 5820: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 5821: if ($fullsize) {
5822: ($fullwidth,$fullheight) = split(/x/,$fullsize);
5823: }
5824: }
5825: }
5826: return ($fullwidth,$fullheight);
5827: }
5828:
1.9 raeburn 5829: sub check_configuser {
5830: my ($uhome,$dom,$confname,$servadm) = @_;
5831: my ($configuserok,%currroles);
5832: if ($uhome eq 'no_host') {
5833: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
5834: my $configpass = &LONCAPA::Enrollment::create_password();
5835: $configuserok =
5836: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
5837: $configpass,'','','','','',undef,$servadm);
5838: } else {
5839: $configuserok = 'ok';
5840: %currroles =
5841: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
5842: }
5843: return ($configuserok,%currroles);
5844: }
5845:
5846: sub check_authorstatus {
5847: my ($dom,$confname,%currroles) = @_;
5848: my $author_ok;
1.40 raeburn 5849: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 5850: my $start = time;
5851: my $end = 0;
5852: $author_ok =
5853: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 5854: 'au',$end,$start,'','','domconfig');
1.9 raeburn 5855: } else {
5856: $author_ok = 'ok';
5857: }
5858: return $author_ok;
5859: }
5860:
5861: sub publishlogo {
1.46 raeburn 5862: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 5863: my ($output,$fname,$logourl);
5864: if ($action eq 'upload') {
5865: $fname=$env{'form.'.$formname.'.filename'};
5866: chop($env{'form.'.$formname});
5867: } else {
5868: ($fname) = ($formname =~ /([^\/]+)$/);
5869: }
1.46 raeburn 5870: if ($savefileas ne '') {
5871: $fname = $savefileas;
5872: }
1.9 raeburn 5873: $fname=&Apache::lonnet::clean_filename($fname);
5874: # See if there is anything left
5875: unless ($fname) { return ('error: no uploaded file'); }
5876: $fname="$subdir/$fname";
1.160.6.5 raeburn 5877: my $docroot=$r->dir_config('lonDocRoot');
5878: my $filepath="$docroot/priv";
5879: my $relpath = "$dom/$confname";
1.9 raeburn 5880: my ($fnamepath,$file,$fetchthumb);
5881: $file=$fname;
5882: if ($fname=~m|/|) {
5883: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
5884: }
1.160.6.26 raeburn 5885: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 5886: my $count;
1.160.6.5 raeburn 5887: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 5888: $filepath.="/$parts[$count]";
5889: if ((-e $filepath)!=1) {
5890: mkdir($filepath,02770);
5891: }
5892: }
5893: # Check for bad extension and disallow upload
5894: if ($file=~/\.(\w+)$/ &&
5895: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
5896: $output =
1.160.6.25 raeburn 5897: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 5898: } elsif ($file=~/\.(\w+)$/ &&
5899: !defined(&Apache::loncommon::fileembstyle($1))) {
5900: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
5901: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 5902: $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 5903: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 5904: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 5905: } else {
5906: my $source = $filepath.'/'.$file;
5907: my $logfile;
5908: if (!open($logfile,">>$source".'.log')) {
1.160.6.19 raeburn 5909: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 5910: }
5911: print $logfile
5912: "\n================= Publish ".localtime()." ================\n".
5913: $env{'user.name'}.':'.$env{'user.domain'}."\n";
5914: # Save the file
5915: if (!open(FH,'>'.$source)) {
5916: &Apache::lonnet::logthis('Failed to create '.$source);
5917: return (&mt('Failed to create file'));
5918: }
5919: if ($action eq 'upload') {
5920: if (!print FH ($env{'form.'.$formname})) {
5921: &Apache::lonnet::logthis('Failed to write to '.$source);
5922: return (&mt('Failed to write file'));
5923: }
5924: } else {
5925: my $original = &Apache::lonnet::filelocation('',$formname);
5926: if(!copy($original,$source)) {
5927: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
5928: return (&mt('Failed to write file'));
5929: }
5930: }
5931: close(FH);
5932: chmod(0660, $source); # Permissions to rw-rw---.
5933:
5934: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
5935: my $copyfile=$targetdir.'/'.$file;
5936:
5937: my @parts=split(/\//,$targetdir);
5938: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
5939: for (my $count=5;$count<=$#parts;$count++) {
5940: $path.="/$parts[$count]";
5941: if (!-e $path) {
5942: print $logfile "\nCreating directory ".$path;
5943: mkdir($path,02770);
5944: }
5945: }
5946: my $versionresult;
5947: if (-e $copyfile) {
5948: $versionresult = &logo_versioning($targetdir,$file,$logfile);
5949: } else {
5950: $versionresult = 'ok';
5951: }
5952: if ($versionresult eq 'ok') {
5953: if (copy($source,$copyfile)) {
5954: print $logfile "\nCopied original source to ".$copyfile."\n";
5955: $output = 'ok';
5956: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 5957: push(@{$modified_urls},[$copyfile,$source]);
5958: my $metaoutput =
5959: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
5960: unless ($registered_cleanup) {
5961: my $handlers = $r->get_handlers('PerlCleanupHandler');
5962: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5963: $registered_cleanup=1;
5964: }
1.9 raeburn 5965: } else {
5966: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
5967: $output = &mt('Failed to copy file to RES space').", $!";
5968: }
5969: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5970: my $inputfile = $filepath.'/'.$file;
5971: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 5972: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5973: if ($fullwidth ne '' && $fullheight ne '') {
5974: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5975: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5976: system("convert -sample $thumbsize $inputfile $outfile");
5977: chmod(0660, $filepath.'/tn-'.$file);
5978: if (-e $outfile) {
5979: my $copyfile=$targetdir.'/tn-'.$file;
5980: if (copy($outfile,$copyfile)) {
5981: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 5982: my $thumb_metaoutput =
5983: &write_metadata($dom,$confname,$formname,
5984: $targetdir,'tn-'.$file,$logfile);
5985: push(@{$modified_urls},[$copyfile,$outfile]);
5986: unless ($registered_cleanup) {
5987: my $handlers = $r->get_handlers('PerlCleanupHandler');
5988: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5989: $registered_cleanup=1;
5990: }
1.16 raeburn 5991: } else {
5992: print $logfile "\nUnable to write ".$copyfile.
5993: ':'.$!."\n";
5994: }
5995: }
1.9 raeburn 5996: }
5997: }
5998: }
5999: } else {
6000: $output = $versionresult;
6001: }
6002: }
6003: return ($output,$logourl);
6004: }
6005:
6006: sub logo_versioning {
6007: my ($targetdir,$file,$logfile) = @_;
6008: my $target = $targetdir.'/'.$file;
6009: my ($maxversion,$fn,$extn,$output);
6010: $maxversion = 0;
6011: if ($file =~ /^(.+)\.(\w+)$/) {
6012: $fn=$1;
6013: $extn=$2;
6014: }
6015: opendir(DIR,$targetdir);
6016: while (my $filename=readdir(DIR)) {
6017: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
6018: $maxversion=($1>$maxversion)?$1:$maxversion;
6019: }
6020: }
6021: $maxversion++;
6022: print $logfile "\nCreating old version ".$maxversion."\n";
6023: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
6024: if (copy($target,$copyfile)) {
6025: print $logfile "Copied old target to ".$copyfile."\n";
6026: $copyfile=$copyfile.'.meta';
6027: if (copy($target.'.meta',$copyfile)) {
6028: print $logfile "Copied old target metadata to ".$copyfile."\n";
6029: $output = 'ok';
6030: } else {
6031: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
6032: $output = &mt('Failed to copy old meta').", $!, ";
6033: }
6034: } else {
6035: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
6036: $output = &mt('Failed to copy old target').", $!, ";
6037: }
6038: return $output;
6039: }
6040:
6041: sub write_metadata {
6042: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
6043: my (%metadatafields,%metadatakeys,$output);
6044: $metadatafields{'title'}=$formname;
6045: $metadatafields{'creationdate'}=time;
6046: $metadatafields{'lastrevisiondate'}=time;
6047: $metadatafields{'copyright'}='public';
6048: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
6049: $env{'user.domain'};
6050: $metadatafields{'authorspace'}=$confname.':'.$dom;
6051: $metadatafields{'domain'}=$dom;
6052: {
6053: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
6054: my $mfh;
1.155 raeburn 6055: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 6056: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 6057: unless ($_=~/\./) {
6058: my $unikey=$_;
6059: $unikey=~/^([A-Za-z]+)/;
6060: my $tag=$1;
6061: $tag=~tr/A-Z/a-z/;
6062: print $mfh "\n\<$tag";
6063: foreach (split(/\,/,$metadatakeys{$unikey})) {
6064: my $value=$metadatafields{$unikey.'.'.$_};
6065: $value=~s/\"/\'\'/g;
6066: print $mfh ' '.$_.'="'.$value.'"';
6067: }
6068: print $mfh '>'.
6069: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
6070: .'</'.$tag.'>';
6071: }
6072: }
6073: $output = 'ok';
6074: print $logfile "\nWrote metadata";
6075: close($mfh);
6076: } else {
6077: print $logfile "\nFailed to open metadata file";
1.9 raeburn 6078: $output = &mt('Could not write metadata');
6079: }
6080: }
1.155 raeburn 6081: return $output;
6082: }
6083:
6084: sub notifysubscribed {
6085: foreach my $targetsource (@{$modified_urls}){
6086: next unless (ref($targetsource) eq 'ARRAY');
6087: my ($target,$source)=@{$targetsource};
6088: if ($source ne '') {
6089: if (open(my $logfh,'>>'.$source.'.log')) {
6090: print $logfh "\nCleanup phase: Notifications\n";
6091: my @subscribed=&subscribed_hosts($target);
6092: foreach my $subhost (@subscribed) {
6093: print $logfh "\nNotifying host ".$subhost.':';
6094: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
6095: print $logfh $reply;
6096: }
6097: my @subscribedmeta=&subscribed_hosts("$target.meta");
6098: foreach my $subhost (@subscribedmeta) {
6099: print $logfh "\nNotifying host for metadata only ".$subhost.':';
6100: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
6101: $subhost);
6102: print $logfh $reply;
6103: }
6104: print $logfh "\n============ Done ============\n";
1.160 raeburn 6105: close($logfh);
1.155 raeburn 6106: }
6107: }
6108: }
6109: return OK;
6110: }
6111:
6112: sub subscribed_hosts {
6113: my ($target) = @_;
6114: my @subscribed;
6115: if (open(my $fh,"<$target.subscription")) {
6116: while (my $subline=<$fh>) {
6117: if ($subline =~ /^($match_lonid):/) {
6118: my $host = $1;
6119: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
6120: unless (grep(/^\Q$host\E$/,@subscribed)) {
6121: push(@subscribed,$host);
6122: }
6123: }
6124: }
6125: }
6126: }
6127: return @subscribed;
1.9 raeburn 6128: }
6129:
6130: sub check_switchserver {
6131: my ($dom,$confname) = @_;
6132: my ($allowed,$switchserver);
6133: my $home = &Apache::lonnet::homeserver($confname,$dom);
6134: if ($home eq 'no_host') {
6135: $home = &Apache::lonnet::domain($dom,'primary');
6136: }
6137: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 6138: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
6139: if (!$allowed) {
1.160.6.11 raeburn 6140: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 6141: }
6142: return $switchserver;
6143: }
6144:
1.1 raeburn 6145: sub modify_quotas {
1.160.6.30 raeburn 6146: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 6147: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 6148: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
6149: $author_ok,$switchserver,$errors);
1.86 raeburn 6150: if ($action eq 'quotas') {
6151: $context = 'tools';
1.160.6.26 raeburn 6152: } else {
1.86 raeburn 6153: $context = $action;
6154: }
6155: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 6156: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 6157: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 6158: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
6159: %titles = &courserequest_titles();
6160: $toolregexp = join('|',@usertools);
6161: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 6162: $confname = $dom.'-domainconfig';
6163: my $servadm = $r->dir_config('lonAdmEMail');
6164: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.5 raeburn 6165: } elsif ($context eq 'requestauthor') {
6166: @usertools = ('author');
6167: %titles = &authorrequest_titles();
1.86 raeburn 6168: } else {
1.160.6.4 raeburn 6169: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 6170: %titles = &tool_titles();
1.86 raeburn 6171: }
1.160.6.27 raeburn 6172: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 6173: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6174: foreach my $key (keys(%env)) {
1.101 raeburn 6175: if ($context eq 'requestcourses') {
6176: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
6177: my $item = $1;
6178: my $type = $2;
6179: if ($type =~ /^limit_(.+)/) {
6180: $limithash{$item}{$1} = $env{$key};
6181: } else {
6182: $confhash{$item}{$type} = $env{$key};
6183: }
6184: }
1.160.6.5 raeburn 6185: } elsif ($context eq 'requestauthor') {
6186: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
6187: $confhash{$1} = $env{$key};
6188: }
1.101 raeburn 6189: } else {
1.86 raeburn 6190: if ($key =~ /^form\.quota_(.+)$/) {
6191: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 6192: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
6193: $confhash{'authorquota'}{$1} = $env{$key};
6194: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 6195: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
6196: }
1.72 raeburn 6197: }
6198: }
1.160.6.5 raeburn 6199: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34! raeburn 6200: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 6201: @approvalnotify = sort(@approvalnotify);
6202: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 6203: my @crstypes = ('official','unofficial','community','textbook');
6204: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
6205: foreach my $type (@hasuniquecode) {
6206: if (grep(/^\Q$type\E$/,@crstypes)) {
6207: $confhash{'uniquecode'}{$type} = 1;
6208: }
6209: }
6210: my ($newbook,@allpos);
6211: if ($context eq 'requestcourses') {
6212: if ($env{'form.addbook'}) {
6213: if (($env{'form.addbook_cnum'} =~ /^$match_courseid$/) &&
6214: ($env{'form.addbook_cdom'} =~ /^$match_domain$/)) {
6215: if (&Apache::lonnet::homeserver($env{'form.addbook_cnum'},
6216: $env{'form.addbook_cdom'}) eq 'no_host') {
6217: $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
6218: '</span></li>';
6219: } else {
6220: $newbook = $env{'form.addbook_cdom'}.'_'.$env{'form.addbook_cnum'};
6221: my $position = $env{'form.addbook_pos'};
6222: $position =~ s/\D+//g;
6223: if ($position ne '') {
6224: $allpos[$position] = $newbook;
6225: }
6226: }
6227: } else {
6228: $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
6229: '</span></li>';
6230: }
6231: }
6232: }
1.102 raeburn 6233: if (ref($domconfig{$action}) eq 'HASH') {
6234: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
6235: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
6236: $changes{'notify'}{'approval'} = 1;
6237: }
6238: } else {
1.144 raeburn 6239: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6240: $changes{'notify'}{'approval'} = 1;
6241: }
6242: }
1.160.6.30 raeburn 6243: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
6244: if (ref($confhash{'uniquecode'}) eq 'HASH') {
6245: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
6246: unless ($confhash{'uniquecode'}{$crstype}) {
6247: $changes{'uniquecode'} = 1;
6248: }
6249: }
6250: unless ($changes{'uniquecode'}) {
6251: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
6252: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
6253: $changes{'uniquecode'} = 1;
6254: }
6255: }
6256: }
6257: } else {
6258: $changes{'uniquecode'} = 1;
6259: }
6260: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
6261: $changes{'uniquecode'} = 1;
6262: }
6263: if ($context eq 'requestcourses') {
6264: if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
6265: my %deletions;
6266: my @todelete = &Apache::loncommon::get_env_multiple('form.book_del');
6267: if (@todelete) {
6268: map { $deletions{$_} = 1; } @todelete;
6269: }
6270: my %imgdeletions;
6271: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.book_image_del');
6272: if (@todeleteimages) {
6273: map { $imgdeletions{$_} = 1; } @todeleteimages;
6274: }
6275: my $maxnum = $env{'form.book_maxnum'};
6276: for (my $i=0; $i<=$maxnum; $i++) {
6277: my $key = $env{'form.book_id_'.$i};
6278: if (ref($domconfig{$action}{'textbooks'}{$key}) eq 'HASH') {
6279: if ($deletions{$key}) {
6280: if ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
6281: #FIXME need to obsolete item in RES space
6282: }
6283: next;
6284: } else {
6285: my $newpos = $env{'form.'.$key};
6286: $newpos =~ s/\D+//g;
6287: foreach my $item ('subject','title','author') {
6288: $confhash{'textbooks'}{$key}{$item} = $env{'form.book_'.$item.'_'.$i};
6289: if ($domconfig{$action}{'textbooks'}{$key}{$item} ne $confhash{'textbooks'}{$key}{$item}) {
6290: $changes{'textbooks'}{$key} = 1;
6291: }
6292: }
6293: $allpos[$newpos] = $key;
6294: }
6295: if ($imgdeletions{$key}) {
6296: $changes{'textbooks'}{$key} = 1;
6297: #FIXME need to obsolete item in RES space
6298: } elsif ($env{'form.book_image_'.$i.'.filename'}) {
6299: my ($cdom,$cnum) = split(/_/,$key);
6300: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,'book_image_'.$i,
6301: $cdom,$cnum,$configuserok,
6302: $switchserver,$author_ok);
6303: if ($imgurl) {
6304: $confhash{'textbooks'}{$key}{'image'} = $imgurl;
6305: $changes{'textbooks'}{$key} = 1;
6306: }
6307: if ($error) {
6308: &Apache::lonnet::logthis($error);
6309: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6310: }
6311: } elsif ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
6312: $confhash{'textbooks'}{$key}{'image'} =
6313: $domconfig{$action}{'textbooks'}{$key}{'image'};
6314: }
6315: }
6316: }
6317: }
6318: }
1.102 raeburn 6319: } else {
1.144 raeburn 6320: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6321: $changes{'notify'}{'approval'} = 1;
6322: }
1.160.6.30 raeburn 6323: if (ref($confhash{'uniquecode'} eq 'HASH')) {
6324: $changes{'uniquecode'} = 1;
6325: }
6326: }
6327: if ($context eq 'requestcourses') {
6328: if ($newbook) {
6329: $changes{'textbooks'}{$newbook} = 1;
6330: foreach my $item ('subject','title','author') {
6331: $env{'form.addbook_'.$item} =~ s/(`)/'/g;
6332: if ($env{'form.addbook_'.$item}) {
6333: $confhash{'textbooks'}{$newbook}{$item} = $env{'form.addbook_'.$item};
6334: }
6335: }
6336: if ($env{'form.addbook_image.filename'} ne '') {
6337: my ($cdom,$cnum) = split(/_/,$newbook);
6338: my ($imageurl,$error) =
6339: &process_textbook_image($r,$dom,$confname,'addbook_image',$cdom,$cnum,$configuserok,
6340: $switchserver,$author_ok);
6341: if ($imageurl) {
6342: $confhash{'textbooks'}{$newbook}{'image'} = $imageurl;
6343: }
6344: if ($error) {
6345: &Apache::lonnet::logthis($error);
6346: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6347: }
6348: }
6349: }
6350: if (@allpos > 0) {
6351: my $idx = 0;
6352: foreach my $item (@allpos) {
6353: if ($item ne '') {
6354: $confhash{'textbooks'}{$item}{'order'} = $idx;
6355: if (ref($domconfig{$action}) eq 'HASH') {
6356: if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
6357: if (ref($domconfig{$action}{'textbooks'}{$item}) eq 'HASH') {
6358: if ($domconfig{$action}{'textbooks'}{$item}{'order'} ne $idx) {
6359: $changes{'textbooks'}{$item} = 1;
6360: }
6361: }
6362: }
6363: }
6364: $idx ++;
6365: }
6366: }
6367: }
1.102 raeburn 6368: }
6369: } else {
1.86 raeburn 6370: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 6371: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 6372: }
1.72 raeburn 6373: foreach my $item (@usertools) {
6374: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 6375: my $unset;
1.101 raeburn 6376: if ($context eq 'requestcourses') {
1.104 raeburn 6377: $unset = '0';
6378: if ($type eq '_LC_adv') {
6379: $unset = '';
6380: }
1.101 raeburn 6381: if ($confhash{$item}{$type} eq 'autolimit') {
6382: $confhash{$item}{$type} .= '=';
6383: unless ($limithash{$item}{$type} =~ /\D/) {
6384: $confhash{$item}{$type} .= $limithash{$item}{$type};
6385: }
6386: }
1.160.6.5 raeburn 6387: } elsif ($context eq 'requestauthor') {
6388: $unset = '0';
6389: if ($type eq '_LC_adv') {
6390: $unset = '';
6391: }
1.72 raeburn 6392: } else {
1.101 raeburn 6393: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
6394: $confhash{$item}{$type} = 1;
6395: } else {
6396: $confhash{$item}{$type} = 0;
6397: }
1.72 raeburn 6398: }
1.86 raeburn 6399: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 6400: if ($action eq 'requestauthor') {
6401: if ($domconfig{$action}{$type} ne $confhash{$type}) {
6402: $changes{$type} = 1;
6403: }
6404: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 6405: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
6406: $changes{$item}{$type} = 1;
6407: }
6408: } else {
6409: if ($context eq 'requestcourses') {
1.104 raeburn 6410: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 6411: $changes{$item}{$type} = 1;
6412: }
6413: } else {
6414: if (!$confhash{$item}{$type}) {
6415: $changes{$item}{$type} = 1;
6416: }
6417: }
6418: }
6419: } else {
6420: if ($context eq 'requestcourses') {
1.104 raeburn 6421: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 6422: $changes{$item}{$type} = 1;
6423: }
1.160.6.5 raeburn 6424: } elsif ($context eq 'requestauthor') {
6425: if ($confhash{$type} ne $unset) {
6426: $changes{$type} = 1;
6427: }
1.72 raeburn 6428: } else {
6429: if (!$confhash{$item}{$type}) {
6430: $changes{$item}{$type} = 1;
6431: }
6432: }
6433: }
1.1 raeburn 6434: }
6435: }
1.160.6.5 raeburn 6436: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 6437: if (ref($domconfig{'quotas'}) eq 'HASH') {
6438: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
6439: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
6440: if (exists($confhash{'defaultquota'}{$key})) {
6441: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
6442: $changes{'defaultquota'}{$key} = 1;
6443: }
6444: } else {
6445: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 6446: }
6447: }
1.86 raeburn 6448: } else {
6449: foreach my $key (keys(%{$domconfig{'quotas'}})) {
6450: if (exists($confhash{'defaultquota'}{$key})) {
6451: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
6452: $changes{'defaultquota'}{$key} = 1;
6453: }
6454: } else {
6455: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 6456: }
1.1 raeburn 6457: }
6458: }
1.160.6.20 raeburn 6459: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
6460: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
6461: if (exists($confhash{'authorquota'}{$key})) {
6462: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
6463: $changes{'authorquota'}{$key} = 1;
6464: }
6465: } else {
6466: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
6467: }
6468: }
6469: }
1.1 raeburn 6470: }
1.86 raeburn 6471: if (ref($confhash{'defaultquota'}) eq 'HASH') {
6472: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
6473: if (ref($domconfig{'quotas'}) eq 'HASH') {
6474: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
6475: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
6476: $changes{'defaultquota'}{$key} = 1;
6477: }
6478: } else {
6479: if (!exists($domconfig{'quotas'}{$key})) {
6480: $changes{'defaultquota'}{$key} = 1;
6481: }
1.72 raeburn 6482: }
6483: } else {
1.86 raeburn 6484: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 6485: }
1.1 raeburn 6486: }
6487: }
1.160.6.20 raeburn 6488: if (ref($confhash{'authorquota'}) eq 'HASH') {
6489: foreach my $key (keys(%{$confhash{'authorquota'}})) {
6490: if (ref($domconfig{'quotas'}) eq 'HASH') {
6491: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
6492: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
6493: $changes{'authorquota'}{$key} = 1;
6494: }
6495: } else {
6496: $changes{'authorquota'}{$key} = 1;
6497: }
6498: } else {
6499: $changes{'authorquota'}{$key} = 1;
6500: }
6501: }
6502: }
1.1 raeburn 6503: }
1.72 raeburn 6504:
1.160.6.5 raeburn 6505: if ($context eq 'requestauthor') {
6506: $domdefaults{'requestauthor'} = \%confhash;
6507: } else {
6508: foreach my $key (keys(%confhash)) {
1.160.6.30 raeburn 6509: unless (($context eq 'requestcourses') && ($key eq 'textbooks')) {
6510: $domdefaults{$key} = $confhash{$key};
6511: }
1.160.6.5 raeburn 6512: }
1.72 raeburn 6513: }
1.160.6.5 raeburn 6514:
1.1 raeburn 6515: my %quotahash = (
1.86 raeburn 6516: $action => { %confhash }
1.1 raeburn 6517: );
6518: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
6519: $dom);
6520: if ($putresult eq 'ok') {
6521: if (keys(%changes) > 0) {
1.72 raeburn 6522: my $cachetime = 24*60*60;
6523: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 6524: if (ref($lastactref) eq 'HASH') {
6525: $lastactref->{'domdefaults'} = 1;
6526: }
1.1 raeburn 6527: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 6528: unless (($context eq 'requestcourses') ||
6529: ($context eq 'requestauthor')) {
1.86 raeburn 6530: if (ref($changes{'defaultquota'}) eq 'HASH') {
6531: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
6532: foreach my $type (@{$types},'default') {
6533: if (defined($changes{'defaultquota'}{$type})) {
6534: my $typetitle = $usertypes->{$type};
6535: if ($type eq 'default') {
6536: $typetitle = $othertitle;
6537: }
1.160.6.28 raeburn 6538: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 6539: }
6540: }
1.86 raeburn 6541: $resulttext .= '</ul></li>';
1.72 raeburn 6542: }
1.160.6.20 raeburn 6543: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34! raeburn 6544: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 6545: foreach my $type (@{$types},'default') {
6546: if (defined($changes{'authorquota'}{$type})) {
6547: my $typetitle = $usertypes->{$type};
6548: if ($type eq 'default') {
6549: $typetitle = $othertitle;
6550: }
1.160.6.28 raeburn 6551: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 6552: }
6553: }
6554: $resulttext .= '</ul></li>';
6555: }
1.72 raeburn 6556: }
1.80 raeburn 6557: my %newenv;
1.72 raeburn 6558: foreach my $item (@usertools) {
1.160.6.5 raeburn 6559: my (%haschgs,%inconf);
6560: if ($context eq 'requestauthor') {
6561: %haschgs = %changes;
6562: %inconf = %confhash;
6563: } else {
6564: if (ref($changes{$item}) eq 'HASH') {
6565: %haschgs = %{$changes{$item}};
6566: }
6567: if (ref($confhash{$item}) eq 'HASH') {
6568: %inconf = %{$confhash{$item}};
6569: }
6570: }
6571: if (keys(%haschgs) > 0) {
1.80 raeburn 6572: my $newacc =
6573: &Apache::lonnet::usertools_access($env{'user.name'},
6574: $env{'user.domain'},
1.86 raeburn 6575: $item,'reload',$context);
1.160.6.5 raeburn 6576: if (($context eq 'requestcourses') ||
6577: ($context eq 'requestauthor')) {
1.108 raeburn 6578: if ($env{'environment.canrequest.'.$item} ne $newacc) {
6579: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 6580: }
6581: } else {
6582: if ($env{'environment.availabletools.'.$item} ne $newacc) {
6583: $newenv{'environment.availabletools.'.$item} = $newacc;
6584: }
1.80 raeburn 6585: }
1.160.6.5 raeburn 6586: unless ($context eq 'requestauthor') {
6587: $resulttext .= '<li>'.$titles{$item}.'<ul>';
6588: }
1.72 raeburn 6589: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 6590: if ($haschgs{$type}) {
1.72 raeburn 6591: my $typetitle = $usertypes->{$type};
6592: if ($type eq 'default') {
6593: $typetitle = $othertitle;
6594: } elsif ($type eq '_LC_adv') {
6595: $typetitle = 'LON-CAPA Advanced Users';
6596: }
1.160.6.5 raeburn 6597: if ($inconf{$type}) {
1.101 raeburn 6598: if ($context eq 'requestcourses') {
6599: my $cond;
1.160.6.5 raeburn 6600: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 6601: if ($1 eq '') {
6602: $cond = &mt('(Automatic processing of any request).');
6603: } else {
6604: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
6605: }
6606: } else {
1.160.6.5 raeburn 6607: $cond = $conditions{$inconf{$type}};
1.101 raeburn 6608: }
6609: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 6610: } elsif ($context eq 'requestauthor') {
6611: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
6612: $titles{$inconf{$type}},$typetitle);
6613:
1.101 raeburn 6614: } else {
6615: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
6616: }
1.72 raeburn 6617: } else {
1.104 raeburn 6618: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 6619: if ($inconf{$type} eq '0') {
1.104 raeburn 6620: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6621: } else {
6622: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
6623: }
6624: } else {
6625: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6626: }
1.72 raeburn 6627: }
6628: }
1.26 raeburn 6629: }
1.160.6.5 raeburn 6630: unless ($context eq 'requestauthor') {
6631: $resulttext .= '</ul></li>';
6632: }
1.26 raeburn 6633: }
1.1 raeburn 6634: }
1.160.6.5 raeburn 6635: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 6636: if (ref($changes{'notify'}) eq 'HASH') {
6637: if ($changes{'notify'}{'approval'}) {
6638: if (ref($confhash{'notify'}) eq 'HASH') {
6639: if ($confhash{'notify'}{'approval'}) {
6640: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
6641: } else {
1.160.6.5 raeburn 6642: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 6643: }
6644: }
6645: }
6646: }
6647: }
1.160.6.30 raeburn 6648: if ($action eq 'requestcourses') {
6649: my @offon = ('off','on');
6650: if ($changes{'uniquecode'}) {
6651: if (ref($confhash{'uniquecode'}) eq 'HASH') {
6652: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
6653: $resulttext .= '<li>'.
6654: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
6655: '</li>';
6656: } else {
6657: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
6658: '</li>';
6659: }
6660: }
6661: if (ref($changes{'textbooks'}) eq 'HASH') {
6662: $resulttext .= '<li>'.&mt('Available textbooks updated').'<ul>';
6663: foreach my $key (sort(keys(%{$changes{'textbooks'}}))) {
6664: my %coursehash = &Apache::lonnet::coursedescription($key);
6665: my $coursetitle = $coursehash{'description'};
6666: my $position = $confhash{'textbooks'}{$key}{'order'} + 1;
6667: $resulttext .= '<li>';
6668: foreach my $item ('subject','title','author') {
6669: my $name = $item.':';
6670: $name =~ s/^(\w)/\U$1/;
6671: $resulttext .= &mt($name).' '.$confhash{'textbooks'}{$key}{$item}.'<br />';
6672: }
6673: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
6674: if ($confhash{'textbooks'}{$key}{'image'}) {
6675: $resulttext .= ' '.&mt('Image: [_1]',
6676: '<img src="'.$confhash{'textbooks'}{$key}{'image'}.'"'.
6677: ' alt="Textbook cover" />').'<br />';
6678: }
6679: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
6680: }
6681: $resulttext .= '</ul></li>';
6682: }
6683: }
1.1 raeburn 6684: $resulttext .= '</ul>';
1.80 raeburn 6685: if (keys(%newenv)) {
6686: &Apache::lonnet::appenv(\%newenv);
6687: }
1.1 raeburn 6688: } else {
1.86 raeburn 6689: if ($context eq 'requestcourses') {
6690: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 6691: } elsif ($context eq 'requestauthor') {
6692: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 6693: } else {
1.90 weissno 6694: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 6695: }
1.1 raeburn 6696: }
6697: } else {
1.11 albertel 6698: $resulttext = '<span class="LC_error">'.
6699: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6700: }
1.160.6.30 raeburn 6701: if ($errors) {
6702: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
6703: '<ul>'.$errors.'</ul></p>';
6704: }
1.3 raeburn 6705: return $resulttext;
1.1 raeburn 6706: }
6707:
1.160.6.30 raeburn 6708: sub process_textbook_image {
6709: my ($r,$dom,$confname,$caller,$cdom,$cnum,$configuserok,$switchserver,$author_ok) = @_;
6710: my $filename = $env{'form.'.$caller.'.filename'};
6711: my ($error,$url);
6712: my ($width,$height) = (50,50);
6713: if ($configuserok eq 'ok') {
6714: if ($switchserver) {
6715: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
6716: $switchserver);
6717: } elsif ($author_ok eq 'ok') {
6718: my ($result,$imageurl) =
6719: &publishlogo($r,'upload',$caller,$dom,$confname,
6720: "textbooks/$dom/$cnum/cover",$width,$height);
6721: if ($result eq 'ok') {
6722: $url = $imageurl;
6723: } else {
6724: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
6725: }
6726: } else {
6727: $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);
6728: }
6729: } else {
6730: $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);
6731: }
6732: return ($url,$error);
6733: }
6734:
1.3 raeburn 6735: sub modify_autoenroll {
1.160.6.24 raeburn 6736: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 6737: my ($resulttext,%changes);
6738: my %currautoenroll;
6739: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6740: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
6741: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
6742: }
6743: }
6744: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
6745: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 6746: sender => 'Sender for notification messages',
6747: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 6748: my @offon = ('off','on');
1.17 raeburn 6749: my $sender_uname = $env{'form.sender_uname'};
6750: my $sender_domain = $env{'form.sender_domain'};
6751: if ($sender_domain eq '') {
6752: $sender_uname = '';
6753: } elsif ($sender_uname eq '') {
6754: $sender_domain = '';
6755: }
1.129 raeburn 6756: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 6757: my %autoenrollhash = (
1.129 raeburn 6758: autoenroll => { 'run' => $env{'form.autoenroll_run'},
6759: 'sender_uname' => $sender_uname,
6760: 'sender_domain' => $sender_domain,
6761: 'co-owners' => $coowners,
1.1 raeburn 6762: }
6763: );
1.4 raeburn 6764: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
6765: $dom);
1.1 raeburn 6766: if ($putresult eq 'ok') {
6767: if (exists($currautoenroll{'run'})) {
6768: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
6769: $changes{'run'} = 1;
6770: }
6771: } elsif ($autorun) {
6772: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 6773: $changes{'run'} = 1;
1.1 raeburn 6774: }
6775: }
1.17 raeburn 6776: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 6777: $changes{'sender'} = 1;
6778: }
1.17 raeburn 6779: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 6780: $changes{'sender'} = 1;
6781: }
1.129 raeburn 6782: if ($currautoenroll{'co-owners'} ne '') {
6783: if ($currautoenroll{'co-owners'} ne $coowners) {
6784: $changes{'coowners'} = 1;
6785: }
6786: } elsif ($coowners) {
6787: $changes{'coowners'} = 1;
6788: }
1.1 raeburn 6789: if (keys(%changes) > 0) {
6790: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 6791: if ($changes{'run'}) {
1.1 raeburn 6792: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
6793: }
6794: if ($changes{'sender'}) {
1.17 raeburn 6795: if ($sender_uname eq '' || $sender_domain eq '') {
6796: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
6797: } else {
6798: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
6799: }
1.1 raeburn 6800: }
1.129 raeburn 6801: if ($changes{'coowners'}) {
6802: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
6803: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 6804: if (ref($lastactref) eq 'HASH') {
6805: $lastactref->{'domainconfig'} = 1;
6806: }
1.129 raeburn 6807: }
1.1 raeburn 6808: $resulttext .= '</ul>';
6809: } else {
6810: $resulttext = &mt('No changes made to auto-enrollment settings');
6811: }
6812: } else {
1.11 albertel 6813: $resulttext = '<span class="LC_error">'.
6814: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6815: }
1.3 raeburn 6816: return $resulttext;
1.1 raeburn 6817: }
6818:
6819: sub modify_autoupdate {
1.3 raeburn 6820: my ($dom,%domconfig) = @_;
1.1 raeburn 6821: my ($resulttext,%currautoupdate,%fields,%changes);
6822: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
6823: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
6824: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
6825: }
6826: }
6827: my @offon = ('off','on');
6828: my %title = &Apache::lonlocal::texthash (
6829: run => 'Auto-update:',
6830: classlists => 'Updates to user information in classlists?'
6831: );
1.44 raeburn 6832: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6833: my %fieldtitles = &Apache::lonlocal::texthash (
6834: id => 'Student/Employee ID',
1.20 raeburn 6835: permanentemail => 'E-mail address',
1.1 raeburn 6836: lastname => 'Last Name',
6837: firstname => 'First Name',
6838: middlename => 'Middle Name',
1.132 raeburn 6839: generation => 'Generation',
1.1 raeburn 6840: );
1.142 raeburn 6841: $othertitle = &mt('All users');
1.1 raeburn 6842: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 6843: $othertitle = &mt('Other users');
1.1 raeburn 6844: }
6845: foreach my $key (keys(%env)) {
6846: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 6847: my ($usertype,$item) = ($1,$2);
6848: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
6849: if ($usertype eq 'default') {
6850: push(@{$fields{$1}},$2);
6851: } elsif (ref($types) eq 'ARRAY') {
6852: if (grep(/^\Q$usertype\E$/,@{$types})) {
6853: push(@{$fields{$1}},$2);
6854: }
6855: }
6856: }
1.1 raeburn 6857: }
6858: }
1.131 raeburn 6859: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
6860: @lockablenames = sort(@lockablenames);
6861: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
6862: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6863: if (@changed) {
6864: $changes{'lockablenames'} = 1;
6865: }
6866: } else {
6867: if (@lockablenames) {
6868: $changes{'lockablenames'} = 1;
6869: }
6870: }
1.1 raeburn 6871: my %updatehash = (
6872: autoupdate => { run => $env{'form.autoupdate_run'},
6873: classlists => $env{'form.classlists'},
6874: fields => {%fields},
1.131 raeburn 6875: lockablenames => \@lockablenames,
1.1 raeburn 6876: }
6877: );
6878: foreach my $key (keys(%currautoupdate)) {
6879: if (($key eq 'run') || ($key eq 'classlists')) {
6880: if (exists($updatehash{autoupdate}{$key})) {
6881: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
6882: $changes{$key} = 1;
6883: }
6884: }
6885: } elsif ($key eq 'fields') {
6886: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 6887: foreach my $item (@{$types},'default') {
1.1 raeburn 6888: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
6889: my $change = 0;
6890: foreach my $type (@{$currautoupdate{$key}{$item}}) {
6891: if (!exists($fields{$item})) {
6892: $change = 1;
1.132 raeburn 6893: last;
1.1 raeburn 6894: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 6895: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 6896: $change = 1;
1.132 raeburn 6897: last;
1.1 raeburn 6898: }
6899: }
6900: }
6901: if ($change) {
6902: push(@{$changes{$key}},$item);
6903: }
1.26 raeburn 6904: }
1.1 raeburn 6905: }
6906: }
1.131 raeburn 6907: } elsif ($key eq 'lockablenames') {
6908: if (ref($currautoupdate{$key}) eq 'ARRAY') {
6909: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6910: if (@changed) {
6911: $changes{'lockablenames'} = 1;
6912: }
6913: } else {
6914: if (@lockablenames) {
6915: $changes{'lockablenames'} = 1;
6916: }
6917: }
6918: }
6919: }
6920: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
6921: if (@lockablenames) {
6922: $changes{'lockablenames'} = 1;
1.1 raeburn 6923: }
6924: }
1.26 raeburn 6925: foreach my $item (@{$types},'default') {
6926: if (defined($fields{$item})) {
6927: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 6928: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
6929: my $change = 0;
6930: if (ref($fields{$item}) eq 'ARRAY') {
6931: foreach my $type (@{$fields{$item}}) {
6932: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
6933: $change = 1;
6934: last;
6935: }
6936: }
6937: }
6938: if ($change) {
6939: push(@{$changes{'fields'}},$item);
6940: }
6941: } else {
1.26 raeburn 6942: push(@{$changes{'fields'}},$item);
6943: }
6944: } else {
6945: push(@{$changes{'fields'}},$item);
1.1 raeburn 6946: }
6947: }
6948: }
6949: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
6950: $dom);
6951: if ($putresult eq 'ok') {
6952: if (keys(%changes) > 0) {
6953: $resulttext = &mt('Changes made:').'<ul>';
6954: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 6955: if ($key eq 'lockablenames') {
6956: $resulttext .= '<li>';
6957: if (@lockablenames) {
6958: $usertypes->{'default'} = $othertitle;
6959: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
6960: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
6961: } else {
6962: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
6963: }
6964: $resulttext .= '</li>';
6965: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 6966: foreach my $item (@{$changes{$key}}) {
6967: my @newvalues;
6968: foreach my $type (@{$fields{$item}}) {
6969: push(@newvalues,$fieldtitles{$type});
6970: }
1.3 raeburn 6971: my $newvaluestr;
6972: if (@newvalues > 0) {
6973: $newvaluestr = join(', ',@newvalues);
6974: } else {
6975: $newvaluestr = &mt('none');
1.6 raeburn 6976: }
1.1 raeburn 6977: if ($item eq 'default') {
1.26 raeburn 6978: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 6979: } else {
1.26 raeburn 6980: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 6981: }
6982: }
6983: } else {
6984: my $newvalue;
6985: if ($key eq 'run') {
6986: $newvalue = $offon[$env{'form.autoupdate_run'}];
6987: } else {
6988: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 6989: }
1.1 raeburn 6990: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
6991: }
6992: }
6993: $resulttext .= '</ul>';
6994: } else {
1.3 raeburn 6995: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 6996: }
6997: } else {
1.11 albertel 6998: $resulttext = '<span class="LC_error">'.
6999: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7000: }
1.3 raeburn 7001: return $resulttext;
1.1 raeburn 7002: }
7003:
1.125 raeburn 7004: sub modify_autocreate {
7005: my ($dom,%domconfig) = @_;
7006: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
7007: if (ref($domconfig{'autocreate'}) eq 'HASH') {
7008: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
7009: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
7010: }
7011: }
7012: my %title= ( xml => 'Auto-creation of courses in XML course description files',
7013: req => 'Auto-creation of validated requests for official courses',
7014: xmldc => 'Identity of course creator of courses from XML files',
7015: );
7016: my @types = ('xml','req');
7017: foreach my $item (@types) {
7018: $newvals{$item} = $env{'form.autocreate_'.$item};
7019: $newvals{$item} =~ s/\D//g;
7020: $newvals{$item} = 0 if ($newvals{$item} eq '');
7021: }
7022: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
7023: my %domcoords = &get_active_dcs($dom);
7024: unless (exists($domcoords{$newvals{'xmldc'}})) {
7025: $newvals{'xmldc'} = '';
7026: }
7027: %autocreatehash = (
7028: autocreate => { xml => $newvals{'xml'},
7029: req => $newvals{'req'},
7030: }
7031: );
7032: if ($newvals{'xmldc'} ne '') {
7033: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
7034: }
7035: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
7036: $dom);
7037: if ($putresult eq 'ok') {
7038: my @items = @types;
7039: if ($newvals{'xml'}) {
7040: push(@items,'xmldc');
7041: }
7042: foreach my $item (@items) {
7043: if (exists($currautocreate{$item})) {
7044: if ($currautocreate{$item} ne $newvals{$item}) {
7045: $changes{$item} = 1;
7046: }
7047: } elsif ($newvals{$item}) {
7048: $changes{$item} = 1;
7049: }
7050: }
7051: if (keys(%changes) > 0) {
7052: my @offon = ('off','on');
7053: $resulttext = &mt('Changes made:').'<ul>';
7054: foreach my $item (@types) {
7055: if ($changes{$item}) {
7056: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 7057: $resulttext .= '<li>'.
7058: &mt("$title{$item} set to [_1]$newtxt [_2]",
7059: '<b>','</b>').
7060: '</li>';
1.125 raeburn 7061: }
7062: }
7063: if ($changes{'xmldc'}) {
7064: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
7065: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 7066: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 7067: }
7068: $resulttext .= '</ul>';
7069: } else {
7070: $resulttext = &mt('No changes made to auto-creation settings');
7071: }
7072: } else {
7073: $resulttext = '<span class="LC_error">'.
7074: &mt('An error occurred: [_1]',$putresult).'</span>';
7075: }
7076: return $resulttext;
7077: }
7078:
1.23 raeburn 7079: sub modify_directorysrch {
7080: my ($dom,%domconfig) = @_;
7081: my ($resulttext,%changes);
7082: my %currdirsrch;
7083: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
7084: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
7085: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
7086: }
7087: }
7088: my %title = ( available => 'Directory search available',
1.24 raeburn 7089: localonly => 'Other domains can search',
1.23 raeburn 7090: searchby => 'Search types',
7091: searchtypes => 'Search latitude');
7092: my @offon = ('off','on');
1.24 raeburn 7093: my @otherdoms = ('Yes','No');
1.23 raeburn 7094:
1.25 raeburn 7095: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 7096: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
7097: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
7098:
1.44 raeburn 7099: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 7100: if (keys(%{$usertypes}) == 0) {
7101: @cansearch = ('default');
7102: } else {
7103: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
7104: foreach my $type (@{$currdirsrch{'cansearch'}}) {
7105: if (!grep(/^\Q$type\E$/,@cansearch)) {
7106: push(@{$changes{'cansearch'}},$type);
7107: }
1.23 raeburn 7108: }
1.26 raeburn 7109: foreach my $type (@cansearch) {
7110: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
7111: push(@{$changes{'cansearch'}},$type);
7112: }
1.23 raeburn 7113: }
1.26 raeburn 7114: } else {
7115: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 7116: }
7117: }
7118:
7119: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
7120: foreach my $by (@{$currdirsrch{'searchby'}}) {
7121: if (!grep(/^\Q$by\E$/,@searchby)) {
7122: push(@{$changes{'searchby'}},$by);
7123: }
7124: }
7125: foreach my $by (@searchby) {
7126: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
7127: push(@{$changes{'searchby'}},$by);
7128: }
7129: }
7130: } else {
7131: push(@{$changes{'searchby'}},@searchby);
7132: }
1.25 raeburn 7133:
7134: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
7135: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
7136: if (!grep(/^\Q$type\E$/,@searchtypes)) {
7137: push(@{$changes{'searchtypes'}},$type);
7138: }
7139: }
7140: foreach my $type (@searchtypes) {
7141: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
7142: push(@{$changes{'searchtypes'}},$type);
7143: }
7144: }
7145: } else {
7146: if (exists($currdirsrch{'searchtypes'})) {
7147: foreach my $type (@searchtypes) {
7148: if ($type ne $currdirsrch{'searchtypes'}) {
7149: push(@{$changes{'searchtypes'}},$type);
7150: }
7151: }
7152: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
7153: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
7154: }
7155: } else {
7156: push(@{$changes{'searchtypes'}},@searchtypes);
7157: }
7158: }
7159:
1.23 raeburn 7160: my %dirsrch_hash = (
7161: directorysrch => { available => $env{'form.dirsrch_available'},
7162: cansearch => \@cansearch,
1.24 raeburn 7163: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 7164: searchby => \@searchby,
1.25 raeburn 7165: searchtypes => \@searchtypes,
1.23 raeburn 7166: }
7167: );
7168: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
7169: $dom);
7170: if ($putresult eq 'ok') {
7171: if (exists($currdirsrch{'available'})) {
7172: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
7173: $changes{'available'} = 1;
7174: }
7175: } else {
7176: if ($env{'form.dirsrch_available'} eq '1') {
7177: $changes{'available'} = 1;
7178: }
7179: }
1.24 raeburn 7180: if (exists($currdirsrch{'localonly'})) {
7181: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
7182: $changes{'localonly'} = 1;
7183: }
7184: } else {
7185: if ($env{'form.dirsrch_localonly'} eq '1') {
7186: $changes{'localonly'} = 1;
7187: }
7188: }
1.23 raeburn 7189: if (keys(%changes) > 0) {
7190: $resulttext = &mt('Changes made:').'<ul>';
7191: if ($changes{'available'}) {
7192: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
7193: }
1.24 raeburn 7194: if ($changes{'localonly'}) {
7195: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
7196: }
7197:
1.23 raeburn 7198: if (ref($changes{'cansearch'}) eq 'ARRAY') {
7199: my $chgtext;
1.26 raeburn 7200: if (ref($usertypes) eq 'HASH') {
7201: if (keys(%{$usertypes}) > 0) {
7202: foreach my $type (@{$types}) {
7203: if (grep(/^\Q$type\E$/,@cansearch)) {
7204: $chgtext .= $usertypes->{$type}.'; ';
7205: }
7206: }
7207: if (grep(/^default$/,@cansearch)) {
7208: $chgtext .= $othertitle;
7209: } else {
7210: $chgtext =~ s/\; $//;
7211: }
1.160.6.13 raeburn 7212: $resulttext .=
7213: '<li>'.
7214: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
7215: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
7216: '</li>';
1.23 raeburn 7217: }
7218: }
7219: }
7220: if (ref($changes{'searchby'}) eq 'ARRAY') {
7221: my ($searchtitles,$titleorder) = &sorted_searchtitles();
7222: my $chgtext;
7223: foreach my $type (@{$titleorder}) {
7224: if (grep(/^\Q$type\E$/,@searchby)) {
7225: if (defined($searchtitles->{$type})) {
7226: $chgtext .= $searchtitles->{$type}.'; ';
7227: }
7228: }
7229: }
7230: $chgtext =~ s/\; $//;
7231: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
7232: }
1.25 raeburn 7233: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
7234: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
7235: my $chgtext;
7236: foreach my $type (@{$srchtypeorder}) {
7237: if (grep(/^\Q$type\E$/,@searchtypes)) {
7238: if (defined($srchtypes_desc->{$type})) {
7239: $chgtext .= $srchtypes_desc->{$type}.'; ';
7240: }
7241: }
7242: }
7243: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 7244: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 7245: }
7246: $resulttext .= '</ul>';
7247: } else {
7248: $resulttext = &mt('No changes made to institution directory search settings');
7249: }
7250: } else {
7251: $resulttext = '<span class="LC_error">'.
1.27 raeburn 7252: &mt('An error occurred: [_1]',$putresult).'</span>';
7253: }
7254: return $resulttext;
7255: }
7256:
1.28 raeburn 7257: sub modify_contacts {
1.160.6.24 raeburn 7258: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 7259: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
7260: if (ref($domconfig{'contacts'}) eq 'HASH') {
7261: foreach my $key (keys(%{$domconfig{'contacts'}})) {
7262: $currsetting{$key} = $domconfig{'contacts'}{$key};
7263: }
7264: }
1.134 raeburn 7265: my (%others,%to,%bcc);
1.28 raeburn 7266: my @contacts = ('supportemail','adminemail');
1.102 raeburn 7267: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.160.6.23 raeburn 7268: 'requestsmail','updatesmail','idconflictsmail');
7269: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 7270: foreach my $type (@mailings) {
7271: @{$newsetting{$type}} =
7272: &Apache::loncommon::get_env_multiple('form.'.$type);
7273: foreach my $item (@contacts) {
7274: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
7275: $contacts_hash{contacts}{$type}{$item} = 1;
7276: } else {
7277: $contacts_hash{contacts}{$type}{$item} = 0;
7278: }
7279: }
7280: $others{$type} = $env{'form.'.$type.'_others'};
7281: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 7282: if ($type eq 'helpdeskmail') {
7283: $bcc{$type} = $env{'form.'.$type.'_bcc'};
7284: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
7285: }
1.28 raeburn 7286: }
7287: foreach my $item (@contacts) {
7288: $to{$item} = $env{'form.'.$item};
7289: $contacts_hash{'contacts'}{$item} = $to{$item};
7290: }
1.160.6.23 raeburn 7291: foreach my $item (@toggles) {
7292: if ($env{'form.'.$item} =~ /^(0|1)$/) {
7293: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
7294: }
7295: }
1.28 raeburn 7296: if (keys(%currsetting) > 0) {
7297: foreach my $item (@contacts) {
7298: if ($to{$item} ne $currsetting{$item}) {
7299: $changes{$item} = 1;
7300: }
7301: }
7302: foreach my $type (@mailings) {
7303: foreach my $item (@contacts) {
7304: if (ref($currsetting{$type}) eq 'HASH') {
7305: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
7306: push(@{$changes{$type}},$item);
7307: }
7308: } else {
7309: push(@{$changes{$type}},@{$newsetting{$type}});
7310: }
7311: }
7312: if ($others{$type} ne $currsetting{$type}{'others'}) {
7313: push(@{$changes{$type}},'others');
7314: }
1.134 raeburn 7315: if ($type eq 'helpdeskmail') {
7316: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
7317: push(@{$changes{$type}},'bcc');
7318: }
7319: }
1.28 raeburn 7320: }
7321: } else {
7322: my %default;
7323: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
7324: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
7325: $default{'errormail'} = 'adminemail';
7326: $default{'packagesmail'} = 'adminemail';
7327: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 7328: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 7329: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 7330: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 7331: foreach my $item (@contacts) {
7332: if ($to{$item} ne $default{$item}) {
7333: $changes{$item} = 1;
1.160.6.23 raeburn 7334: }
1.28 raeburn 7335: }
7336: foreach my $type (@mailings) {
7337: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
7338:
7339: push(@{$changes{$type}},@{$newsetting{$type}});
7340: }
7341: if ($others{$type} ne '') {
7342: push(@{$changes{$type}},'others');
1.134 raeburn 7343: }
7344: if ($type eq 'helpdeskmail') {
7345: if ($bcc{$type} ne '') {
7346: push(@{$changes{$type}},'bcc');
7347: }
7348: }
1.28 raeburn 7349: }
7350: }
1.160.6.23 raeburn 7351: foreach my $item (@toggles) {
7352: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
7353: $changes{$item} = 1;
7354: } elsif ((!$env{'form.'.$item}) &&
7355: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
7356: $changes{$item} = 1;
7357: }
7358: }
1.28 raeburn 7359: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
7360: $dom);
7361: if ($putresult eq 'ok') {
7362: if (keys(%changes) > 0) {
1.160.6.24 raeburn 7363: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7364: if (ref($lastactref) eq 'HASH') {
7365: $lastactref->{'domainconfig'} = 1;
7366: }
1.28 raeburn 7367: my ($titles,$short_titles) = &contact_titles();
7368: $resulttext = &mt('Changes made:').'<ul>';
7369: foreach my $item (@contacts) {
7370: if ($changes{$item}) {
7371: $resulttext .= '<li>'.$titles->{$item}.
7372: &mt(' set to: ').
7373: '<span class="LC_cusr_emph">'.
7374: $to{$item}.'</span></li>';
7375: }
7376: }
7377: foreach my $type (@mailings) {
7378: if (ref($changes{$type}) eq 'ARRAY') {
7379: $resulttext .= '<li>'.$titles->{$type}.': ';
7380: my @text;
7381: foreach my $item (@{$newsetting{$type}}) {
7382: push(@text,$short_titles->{$item});
7383: }
7384: if ($others{$type} ne '') {
7385: push(@text,$others{$type});
7386: }
7387: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 7388: join(', ',@text).'</span>';
7389: if ($type eq 'helpdeskmail') {
7390: if ($bcc{$type} ne '') {
7391: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
7392: }
7393: }
7394: $resulttext .= '</li>';
1.28 raeburn 7395: }
7396: }
1.160.6.23 raeburn 7397: my @offon = ('off','on');
7398: if ($changes{'reporterrors'}) {
7399: $resulttext .= '<li>'.
7400: &mt('E-mail error reports to [_1] set to "'.
7401: $offon[$env{'form.reporterrors'}].'".',
7402: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
7403: &mt('LON-CAPA core group - MSU'),600,500)).
7404: '</li>';
7405: }
7406: if ($changes{'reportupdates'}) {
7407: $resulttext .= '<li>'.
7408: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
7409: $offon[$env{'form.reportupdates'}].'".',
7410: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
7411: &mt('LON-CAPA core group - MSU'),600,500)).
7412: '</li>';
7413: }
1.28 raeburn 7414: $resulttext .= '</ul>';
7415: } else {
1.34 raeburn 7416: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 7417: }
7418: } else {
7419: $resulttext = '<span class="LC_error">'.
7420: &mt('An error occurred: [_1].',$putresult).'</span>';
7421: }
7422: return $resulttext;
7423: }
7424:
7425: sub modify_usercreation {
1.27 raeburn 7426: my ($dom,%domconfig) = @_;
1.160.6.34! raeburn 7427: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 7428: my $warningmsg;
1.27 raeburn 7429: if (ref($domconfig{'usercreation'}) eq 'HASH') {
7430: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34! raeburn 7431: if ($key eq 'cancreate') {
! 7432: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
! 7433: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
! 7434: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
! 7435: ($item eq 'captcha') || ($item eq 'recaptchakeys')) {
! 7436: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
! 7437: } else {
! 7438: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
! 7439: }
1.50 raeburn 7440: }
1.43 raeburn 7441: }
1.160.6.34! raeburn 7442: } elsif ($key eq 'email_rule') {
! 7443: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
! 7444: } else {
! 7445: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 7446: }
7447: }
1.34 raeburn 7448: }
1.160.6.34! raeburn 7449: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
! 7450: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
! 7451: my @contexts = ('author','course','requestcrs');
! 7452: foreach my $item(@contexts) {
! 7453: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 7454: }
1.34 raeburn 7455: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
7456: foreach my $item (@contexts) {
1.160.6.34! raeburn 7457: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
! 7458: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 7459: }
1.27 raeburn 7460: }
1.34 raeburn 7461: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
7462: foreach my $item (@contexts) {
1.43 raeburn 7463: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 7464: if ($cancreate{$item} ne 'any') {
7465: push(@{$changes{'cancreate'}},$item);
7466: }
7467: } else {
7468: if ($cancreate{$item} ne 'none') {
7469: push(@{$changes{'cancreate'}},$item);
7470: }
1.27 raeburn 7471: }
7472: }
7473: } else {
1.43 raeburn 7474: foreach my $item (@contexts) {
1.34 raeburn 7475: push(@{$changes{'cancreate'}},$item);
7476: }
1.27 raeburn 7477: }
1.34 raeburn 7478:
1.27 raeburn 7479: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
7480: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
7481: if (!grep(/^\Q$type\E$/,@username_rule)) {
7482: push(@{$changes{'username_rule'}},$type);
7483: }
7484: }
7485: foreach my $type (@username_rule) {
7486: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
7487: push(@{$changes{'username_rule'}},$type);
7488: }
7489: }
7490: } else {
7491: push(@{$changes{'username_rule'}},@username_rule);
7492: }
7493:
1.32 raeburn 7494: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
7495: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
7496: if (!grep(/^\Q$type\E$/,@id_rule)) {
7497: push(@{$changes{'id_rule'}},$type);
7498: }
7499: }
7500: foreach my $type (@id_rule) {
7501: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
7502: push(@{$changes{'id_rule'}},$type);
7503: }
7504: }
7505: } else {
7506: push(@{$changes{'id_rule'}},@id_rule);
7507: }
7508:
1.43 raeburn 7509: my @authen_contexts = ('author','course','domain');
1.28 raeburn 7510: my @authtypes = ('int','krb4','krb5','loc');
7511: my %authhash;
1.43 raeburn 7512: foreach my $item (@authen_contexts) {
1.28 raeburn 7513: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
7514: foreach my $auth (@authtypes) {
7515: if (grep(/^\Q$auth\E$/,@authallowed)) {
7516: $authhash{$item}{$auth} = 1;
7517: } else {
7518: $authhash{$item}{$auth} = 0;
7519: }
7520: }
7521: }
7522: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 7523: foreach my $item (@authen_contexts) {
1.28 raeburn 7524: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
7525: foreach my $auth (@authtypes) {
7526: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
7527: push(@{$changes{'authtypes'}},$item);
7528: last;
7529: }
7530: }
7531: }
7532: }
7533: } else {
1.43 raeburn 7534: foreach my $item (@authen_contexts) {
1.28 raeburn 7535: push(@{$changes{'authtypes'}},$item);
7536: }
7537: }
7538:
1.160.6.34! raeburn 7539: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
! 7540: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
! 7541: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
! 7542: $save_usercreate{'id_rule'} = \@id_rule;
! 7543: $save_usercreate{'username_rule'} = \@username_rule,
! 7544: $save_usercreate{'authtypes'} = \%authhash;
! 7545:
1.27 raeburn 7546: my %usercreation_hash = (
1.160.6.34! raeburn 7547: usercreation => \%save_usercreate,
! 7548: );
1.27 raeburn 7549:
7550: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
7551: $dom);
1.50 raeburn 7552:
1.160.6.34! raeburn 7553: if ($putresult eq 'ok') {
! 7554: if (keys(%changes) > 0) {
! 7555: $resulttext = &mt('Changes made:').'<ul>';
! 7556: if (ref($changes{'cancreate'}) eq 'ARRAY') {
! 7557: my %lt = &usercreation_types();
! 7558: foreach my $type (@{$changes{'cancreate'}}) {
! 7559: my $chgtext = $lt{$type}.', ';
! 7560: if ($cancreate{$type} eq 'none') {
! 7561: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
! 7562: } elsif ($cancreate{$type} eq 'any') {
! 7563: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
! 7564: } elsif ($cancreate{$type} eq 'official') {
! 7565: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
! 7566: } elsif ($cancreate{$type} eq 'unofficial') {
! 7567: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
! 7568: }
! 7569: $resulttext .= '<li>'.$chgtext.'</li>';
! 7570: }
! 7571: }
! 7572: if (ref($changes{'username_rule'}) eq 'ARRAY') {
! 7573: my ($rules,$ruleorder) =
! 7574: &Apache::lonnet::inst_userrules($dom,'username');
! 7575: my $chgtext = '<ul>';
! 7576: foreach my $type (@username_rule) {
! 7577: if (ref($rules->{$type}) eq 'HASH') {
! 7578: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
! 7579: }
! 7580: }
! 7581: $chgtext .= '</ul>';
! 7582: if (@username_rule > 0) {
! 7583: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
! 7584: } else {
! 7585: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
! 7586: }
! 7587: }
! 7588: if (ref($changes{'id_rule'}) eq 'ARRAY') {
! 7589: my ($idrules,$idruleorder) =
! 7590: &Apache::lonnet::inst_userrules($dom,'id');
! 7591: my $chgtext = '<ul>';
! 7592: foreach my $type (@id_rule) {
! 7593: if (ref($idrules->{$type}) eq 'HASH') {
! 7594: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
! 7595: }
! 7596: }
! 7597: $chgtext .= '</ul>';
! 7598: if (@id_rule > 0) {
! 7599: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
! 7600: } else {
! 7601: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
! 7602: }
! 7603: }
! 7604: my %authname = &authtype_names();
! 7605: my %context_title = &context_names();
! 7606: if (ref($changes{'authtypes'}) eq 'ARRAY') {
! 7607: my $chgtext = '<ul>';
! 7608: foreach my $type (@{$changes{'authtypes'}}) {
! 7609: my @allowed;
! 7610: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
! 7611: foreach my $auth (@authtypes) {
! 7612: if ($authhash{$type}{$auth}) {
! 7613: push(@allowed,$authname{$auth});
! 7614: }
! 7615: }
! 7616: if (@allowed > 0) {
! 7617: $chgtext .= join(', ',@allowed).'</li>';
! 7618: } else {
! 7619: $chgtext .= &mt('none').'</li>';
! 7620: }
! 7621: }
! 7622: $chgtext .= '</ul>';
! 7623: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
! 7624: $resulttext .= '</li>';
! 7625: }
! 7626: $resulttext .= '</ul>';
! 7627: } else {
! 7628: $resulttext = &mt('No changes made to user creation settings');
! 7629: }
! 7630: } else {
! 7631: $resulttext = '<span class="LC_error">'.
! 7632: &mt('An error occurred: [_1]',$putresult).'</span>';
! 7633: }
! 7634: if ($warningmsg ne '') {
! 7635: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
! 7636: }
! 7637: return $resulttext;
! 7638: }
! 7639:
! 7640: sub modify_selfcreation {
! 7641: my ($dom,%domconfig) = @_;
! 7642: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
! 7643: my (%save_usercreate,%save_usermodify);
! 7644: #
! 7645: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
! 7646: #
! 7647: if (ref($domconfig{'usercreation'}) eq 'HASH') {
! 7648: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
! 7649: if ($key eq 'cancreate') {
! 7650: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
! 7651: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
! 7652: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
! 7653: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
! 7654: ($item eq 'emailusername') || ($item eq 'notify')) {
! 7655: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
! 7656: } else {
! 7657: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
! 7658: }
! 7659: }
! 7660: }
! 7661: } elsif ($key eq 'email_rule') {
! 7662: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
! 7663: } else {
! 7664: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
! 7665: }
! 7666: }
! 7667: }
! 7668: #
! 7669: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
! 7670: #
! 7671: if (ref($domconfig{'usermodification'}) eq 'HASH') {
! 7672: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
! 7673: if ($key eq 'selfcreate') {
! 7674: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
! 7675: } else {
! 7676: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
! 7677: }
! 7678: }
! 7679: }
! 7680:
! 7681: my @contexts = ('selfcreate');
! 7682: @{$cancreate{'selfcreate'}} = ();
! 7683: %{$cancreate{'emailusername'}} = ();
! 7684: @{$cancreate{'statustocreate'}} = ();
1.50 raeburn 7685: my %selfcreatetypes = (
7686: sso => 'users authenticated by institutional single sign on',
7687: login => 'users authenticated by institutional log-in',
1.160.6.34! raeburn 7688: email => 'users who provide a valid e-mail address for use as username (automatic creation)',
! 7689: emailapproval => 'users who provide a valid e-mail address for use as username (queued for Domain Coordinator review)',
1.50 raeburn 7690: );
1.160.6.34! raeburn 7691: #
! 7692: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
! 7693: # is permitted.
! 7694: #
! 7695: foreach my $item ('login','sso','email') {
! 7696: if ($item eq 'email') {
! 7697: if ($env{'form.cancreate_email'} eq 'email') {
! 7698: push(@{$cancreate{'selfcreate'}},'email');
! 7699: } elsif ($env{'form.cancreate_email'} eq 'emailapproval') {
! 7700: push(@{$cancreate{'selfcreate'}},'emailapproval');
! 7701: }
! 7702: } else {
! 7703: if ($env{'form.cancreate_'.$item}) {
! 7704: push(@{$cancreate{'selfcreate'}},$item);
! 7705: }
! 7706: }
! 7707: }
! 7708: my (@email_rule,%userinfo,%savecaptcha);
! 7709: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
! 7710: #
! 7711: # Populate $cancreate{'emailusername'} hash ref with information types (if new user will provide data
! 7712: # value set to one), if self-creation with e-mail address permitted.
! 7713: #
! 7714: if (($env{'form.cancreate_email'} eq 'email') || ($env{'form.cancreate_email'} eq 'emailapproval')) {
! 7715: push(@contexts,'emailusername');
! 7716: map { $userinfo{$_} = 1; } &Apache::loncommon::get_env_multiple('form.canmodify_emailusername');
! 7717: if (ref($infofields) eq 'ARRAY') {
! 7718: foreach my $field (@{$infofields}) {
! 7719: if ($userinfo{$field}) {
! 7720: $cancreate{'emailusername'}{$field} = 1;
! 7721: }
! 7722: }
! 7723: }
! 7724:
! 7725: #
! 7726: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
! 7727: # queued requests for self-creation of account using e-mail address as username
! 7728: #
! 7729:
! 7730: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
! 7731: @approvalnotify = sort(@approvalnotify);
! 7732: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
! 7733: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
! 7734: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
! 7735: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
! 7736: push(@{$changes{'cancreate'}},'notify');
! 7737: }
! 7738: } else {
! 7739: if ($cancreate{'notify'}{'approval'}) {
! 7740: push(@{$changes{'cancreate'}},'notify');
! 7741: }
! 7742: }
! 7743: } elsif ($cancreate{'notify'}{'approval'}) {
! 7744: push(@{$changes{'cancreate'}},'notify');
! 7745: }
! 7746:
! 7747: #
! 7748: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
! 7749: #
! 7750: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
! 7751: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
! 7752: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
! 7753: if (@{$curr_usercreation{'email_rule'}} > 0) {
! 7754: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
! 7755: if (!grep(/^\Q$type\E$/,@email_rule)) {
! 7756: push(@{$changes{'email_rule'}},$type);
! 7757: }
! 7758: }
! 7759: }
! 7760: if (@email_rule > 0) {
! 7761: foreach my $type (@email_rule) {
! 7762: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
! 7763: push(@{$changes{'email_rule'}},$type);
! 7764: }
! 7765: }
! 7766: }
! 7767: } elsif (@email_rule > 0) {
! 7768: push(@{$changes{'email_rule'}},@email_rule);
! 7769: }
! 7770: }
! 7771: #
! 7772: # Check if domain default is set appropriately, if selef-creation of accounts is to be available for
! 7773: # institutional log-in.
! 7774: #
! 7775: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
! 7776: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
! 7777: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
! 7778: ($domdefaults{'auth_def'} eq 'localauth'))) {
! 7779: $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.').' '.
! 7780: &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.');
! 7781: }
! 7782: }
! 7783: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
! 7784: my @fields = ('lastname','firstname','middlename','generation',
! 7785: 'permanentemail','id');
! 7786: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
! 7787: #
! 7788: # Where usernames may created for institutional log-in and/or institutional single sign on:
! 7789: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
! 7790: # may self-create accounts
! 7791: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
! 7792: # which the user may supply, if institutional data is unavailable.
! 7793: #
! 7794: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
! 7795: if (ref($types) eq 'ARRAY') {
! 7796: if (@{$types} > 0) {
! 7797: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
! 7798: push(@contexts,'statustocreate');
! 7799: } else {
! 7800: undef($cancreate{'statustocreate'});
! 7801: }
! 7802: push(@{$types},'default');
! 7803: $usertypes->{'default'} = $othertitle;
! 7804: foreach my $type (@{$types}) {
! 7805: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
! 7806: foreach my $field (@fields) {
! 7807: if (grep(/^\Q$field\E$/,@modifiable)) {
! 7808: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
! 7809: } else {
! 7810: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
! 7811: }
! 7812: }
! 7813: }
! 7814: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
! 7815: foreach my $type (@{$types}) {
! 7816: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
! 7817: foreach my $field (@fields) {
! 7818: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
! 7819: $curr_usermodify{'selfcreate'}{$type}{$field}) {
! 7820: push(@{$changes{'selfcreate'}},$type);
! 7821: last;
! 7822: }
! 7823: }
! 7824: }
! 7825: }
! 7826: } else {
! 7827: foreach my $type (@{$types}) {
! 7828: push(@{$changes{'selfcreate'}},$type);
! 7829: }
! 7830: }
! 7831: }
! 7832: }
! 7833: foreach my $item (@contexts) {
! 7834: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
! 7835: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
! 7836: if (ref($cancreate{$item}) eq 'ARRAY') {
! 7837: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
! 7838: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
! 7839: push(@{$changes{'cancreate'}},$item);
! 7840: }
! 7841: }
! 7842: }
! 7843: }
! 7844: if (ref($cancreate{$item}) eq 'ARRAY') {
! 7845: foreach my $type (@{$cancreate{$item}}) {
! 7846: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
! 7847: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
! 7848: push(@{$changes{'cancreate'}},$item);
! 7849: }
! 7850: }
! 7851: }
! 7852: }
! 7853: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
! 7854: if (ref($cancreate{$item}) eq 'HASH') {
! 7855: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
! 7856: if (!$cancreate{$item}{$curr}) {
! 7857: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
! 7858: push(@{$changes{'cancreate'}},$item);
! 7859: }
! 7860: }
! 7861: }
! 7862: foreach my $field (keys(%{$cancreate{$item}})) {
! 7863: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
! 7864: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
! 7865: push(@{$changes{'cancreate'}},$item);
! 7866: }
! 7867: }
! 7868: }
! 7869: }
! 7870: } elsif ($curr_usercreation{'cancreate'}{$item}) {
! 7871: if (ref($cancreate{$item}) eq 'ARRAY') {
! 7872: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
! 7873: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
! 7874: push(@{$changes{'cancreate'}},$item);
! 7875: }
! 7876: }
! 7877: } elsif (ref($cancreate{$item}) eq 'HASH') {
! 7878: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
! 7879: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
! 7880: push(@{$changes{'cancreate'}},$item);
! 7881: }
! 7882: }
! 7883: }
! 7884: } elsif ($item eq 'emailusername') {
! 7885: if (keys(%userinfo) > 0) {
! 7886: push(@{$changes{'cancreate'}},$item);
! 7887: }
! 7888: }
! 7889: }
! 7890: #
! 7891: # Populate %save_usercreate hash with updates to self-creation configuration.
! 7892: #
! 7893: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
! 7894: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
! 7895: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
! 7896: if (ref($cancreate{'notify'}) eq 'HASH') {
! 7897: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
! 7898: }
! 7899: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
! 7900: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
! 7901: }
! 7902: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
! 7903: $save_usercreate{'emailrule'} = \@email_rule;
! 7904:
! 7905: my %userconfig_hash = (
! 7906: usercreation => \%save_usercreate,
! 7907: usermodification => \%save_usermodify,
! 7908: );
! 7909: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
! 7910: $dom);
! 7911: #
! 7912: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
! 7913: #
1.27 raeburn 7914: if ($putresult eq 'ok') {
7915: if (keys(%changes) > 0) {
7916: $resulttext = &mt('Changes made:').'<ul>';
7917: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34! raeburn 7918: my %lt = &selfcreation_types();
1.34 raeburn 7919: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 7920: my $chgtext;
1.45 raeburn 7921: if ($type eq 'selfcreate') {
1.50 raeburn 7922: if (@{$cancreate{$type}} == 0) {
1.160.6.34! raeburn 7923: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 7924: } else {
1.160.6.34! raeburn 7925: $chgtext .= &mt('Self-creation of a new account is permitted for:').
! 7926: '<ul>';
1.50 raeburn 7927: foreach my $case (@{$cancreate{$type}}) {
7928: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
7929: }
7930: $chgtext .= '</ul>';
1.100 raeburn 7931: if (ref($cancreate{$type}) eq 'ARRAY') {
7932: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
7933: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
7934: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.34! raeburn 7935: $chgtext .= '<br />'.
! 7936: '<span class="LC_warning">'.
! 7937: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
! 7938: '</span>';
1.100 raeburn 7939: }
7940: }
7941: }
7942: }
1.43 raeburn 7943: }
1.93 raeburn 7944: } elsif ($type eq 'statustocreate') {
1.96 raeburn 7945: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
7946: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
7947: if (@{$cancreate{'selfcreate'}} > 0) {
7948: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 7949: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 7950: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34! raeburn 7951: $chgtext .= '<br />'.
! 7952: '<span class="LC_warning">'.
! 7953: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
! 7954: '</span>';
! 7955: }
1.96 raeburn 7956: } elsif (ref($usertypes) eq 'HASH') {
7957: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 7958: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
7959: } else {
7960: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
7961: }
7962: $chgtext .= '<ul>';
7963: foreach my $case (@{$cancreate{$type}}) {
7964: if ($case eq 'default') {
7965: $chgtext .= '<li>'.$othertitle.'</li>';
7966: } else {
7967: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 7968: }
7969: }
1.100 raeburn 7970: $chgtext .= '</ul>';
7971: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34! raeburn 7972: $chgtext .= '<br /><span class="LC_warning">'.
! 7973: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
! 7974: '</span>';
1.100 raeburn 7975: }
7976: }
7977: } else {
7978: if (@{$cancreate{$type}} == 0) {
7979: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
7980: } else {
7981: $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 7982: }
7983: }
7984: }
1.160.6.5 raeburn 7985: } elsif ($type eq 'captcha') {
1.160.6.34! raeburn 7986: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 7987: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
7988: } else {
7989: my %captchas = &captcha_phrases();
1.160.6.34! raeburn 7990: if ($captchas{$savecaptcha{$type}}) {
! 7991: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 7992: } else {
7993: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
7994: }
7995: }
7996: } elsif ($type eq 'recaptchakeys') {
7997: my ($privkey,$pubkey);
1.160.6.34! raeburn 7998: if (ref($savecaptcha{$type}) eq 'HASH') {
! 7999: $pubkey = $savecaptcha{$type}{'public'};
! 8000: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 8001: }
8002: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
8003: if (!$pubkey) {
8004: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
8005: } else {
8006: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
8007: }
8008: if (!$privkey) {
8009: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
8010: } else {
8011: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
8012: }
8013: $chgtext .= '</ul>';
1.160.6.34! raeburn 8014: } elsif ($type eq 'emailusername') {
! 8015: if (ref($cancreate{'emailusername'}) eq 'HASH') {
! 8016: if (keys(%{$cancreate{'emailusername'}}) > 0) {
! 8017: $chgtext .= &mt('When self-creating account with e-mail as username, user will provide the following information:').
! 8018: '<ul>';
! 8019: foreach my $field (@{$infofields}) {
! 8020: if ($cancreate{'emailusername'}{$field}) {
! 8021: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
! 8022: }
! 8023: }
! 8024: $chgtext .= '</ul>';
! 8025: } else {
! 8026: $chgtext .= &mt('When self creating account with e-mail as username, user will not provide any information besides e-mail address');
! 8027: }
! 8028: }
! 8029: } elsif ($type eq 'notify') {
! 8030: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
! 8031: if (ref($changes{'cancreate'}) eq 'ARRAY') {
! 8032: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
! 8033: if ($cancreate{'notify'}{'approval'}) {
! 8034: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
! 8035: }
! 8036: }
1.43 raeburn 8037: }
1.34 raeburn 8038: }
1.160.6.34! raeburn 8039: if ($chgtext) {
! 8040: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 8041: }
8042: }
8043: }
1.43 raeburn 8044: if (ref($changes{'email_rule'}) eq 'ARRAY') {
8045: my ($emailrules,$emailruleorder) =
8046: &Apache::lonnet::inst_userrules($dom,'email');
8047: my $chgtext = '<ul>';
8048: foreach my $type (@email_rule) {
8049: if (ref($emailrules->{$type}) eq 'HASH') {
8050: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
8051: }
8052: }
8053: $chgtext .= '</ul>';
8054: if (@email_rule > 0) {
1.160.6.34! raeburn 8055: $resulttext .= '<li>'.
! 8056: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
! 8057: $chgtext.
! 8058: '</li>';
1.43 raeburn 8059: } else {
1.160.6.34! raeburn 8060: $resulttext .= '<li>'.
! 8061: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
! 8062: '</li>';
1.43 raeburn 8063: }
8064: }
1.160.6.34! raeburn 8065: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
! 8066: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
! 8067: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
! 8068: foreach my $type (@{$changes{'selfcreate'}}) {
! 8069: my $typename = $type;
! 8070: if (ref($usertypes) eq 'HASH') {
! 8071: if ($usertypes->{$type} ne '') {
! 8072: $typename = $usertypes->{$type};
1.28 raeburn 8073: }
8074: }
1.160.6.34! raeburn 8075: my @modifiable;
! 8076: $resulttext .= '<li>'.
! 8077: &mt('Self-creation of account by users with status: [_1]',
! 8078: '<span class="LC_cusr_emph">'.$typename.'</span>').
! 8079: ' - '.&mt('modifiable fields (if institutional data blank): ');
! 8080: foreach my $field (@fields) {
! 8081: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
! 8082: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
! 8083: }
! 8084: }
! 8085: if (@modifiable > 0) {
! 8086: $resulttext .= join(', ',@modifiable);
1.43 raeburn 8087: } else {
1.160.6.34! raeburn 8088: $resulttext .= &mt('none');
1.43 raeburn 8089: }
1.160.6.34! raeburn 8090: $resulttext .= '</li>';
1.28 raeburn 8091: }
1.160.6.34! raeburn 8092: $resulttext .= '</ul></li>';
1.28 raeburn 8093: }
1.27 raeburn 8094: $resulttext .= '</ul>';
8095: } else {
1.160.6.34! raeburn 8096: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 8097: }
8098: } else {
8099: $resulttext = '<span class="LC_error">'.
1.23 raeburn 8100: &mt('An error occurred: [_1]',$putresult).'</span>';
8101: }
1.43 raeburn 8102: if ($warningmsg ne '') {
8103: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
8104: }
1.23 raeburn 8105: return $resulttext;
8106: }
8107:
1.160.6.5 raeburn 8108: sub process_captcha {
8109: my ($container,$changes,$newsettings,$current) = @_;
8110: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
8111: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
8112: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
8113: $newsettings->{'captcha'} = 'original';
8114: }
8115: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
8116: if ($container eq 'cancreate') {
8117: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
8118: push(@{$changes->{'cancreate'}},'captcha');
8119: } elsif (!defined($changes->{'cancreate'})) {
8120: $changes->{'cancreate'} = ['captcha'];
8121: }
8122: } else {
8123: $changes->{'captcha'} = 1;
8124: }
8125: }
8126: my ($newpub,$newpriv,$currpub,$currpriv);
8127: if ($newsettings->{'captcha'} eq 'recaptcha') {
8128: $newpub = $env{'form.'.$container.'_recaptchapub'};
8129: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
8130: $newpub =~ s/\W//g;
8131: $newpriv =~ s/\W//g;
8132: $newsettings->{'recaptchakeys'} = {
8133: public => $newpub,
8134: private => $newpriv,
8135: };
8136: }
8137: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
8138: $currpub = $current->{'recaptchakeys'}{'public'};
8139: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 8140: unless ($newsettings->{'captcha'} eq 'recaptcha') {
8141: $newsettings->{'recaptchakeys'} = {
8142: public => '',
8143: private => '',
8144: }
8145: }
1.160.6.5 raeburn 8146: }
8147: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
8148: if ($container eq 'cancreate') {
8149: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
8150: push(@{$changes->{'cancreate'}},'recaptchakeys');
8151: } elsif (!defined($changes->{'cancreate'})) {
8152: $changes->{'cancreate'} = ['recaptchakeys'];
8153: }
8154: } else {
8155: $changes->{'recaptchakeys'} = 1;
8156: }
8157: }
8158: return;
8159: }
8160:
1.33 raeburn 8161: sub modify_usermodification {
8162: my ($dom,%domconfig) = @_;
1.160.6.34! raeburn 8163: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 8164: if (ref($domconfig{'usermodification'}) eq 'HASH') {
8165: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34! raeburn 8166: if ($key eq 'selfcreate') {
! 8167: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
! 8168: } else {
! 8169: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
! 8170: }
1.33 raeburn 8171: }
8172: }
1.160.6.34! raeburn 8173: my @contexts = ('author','course');
1.33 raeburn 8174: my %context_title = (
8175: author => 'In author context',
8176: course => 'In course context',
8177: );
8178: my @fields = ('lastname','firstname','middlename','generation',
8179: 'permanentemail','id');
8180: my %roles = (
8181: author => ['ca','aa'],
8182: course => ['st','ep','ta','in','cr'],
8183: );
8184: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8185: foreach my $context (@contexts) {
8186: foreach my $role (@{$roles{$context}}) {
8187: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
8188: foreach my $item (@fields) {
8189: if (grep(/^\Q$item\E$/,@modifiable)) {
8190: $modifyhash{$context}{$role}{$item} = 1;
8191: } else {
8192: $modifyhash{$context}{$role}{$item} = 0;
8193: }
8194: }
8195: }
8196: if (ref($curr_usermodification{$context}) eq 'HASH') {
8197: foreach my $role (@{$roles{$context}}) {
8198: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
8199: foreach my $field (@fields) {
8200: if ($modifyhash{$context}{$role}{$field} ne
8201: $curr_usermodification{$context}{$role}{$field}) {
8202: push(@{$changes{$context}},$role);
8203: last;
8204: }
8205: }
8206: }
8207: }
8208: } else {
8209: foreach my $context (@contexts) {
8210: foreach my $role (@{$roles{$context}}) {
8211: push(@{$changes{$context}},$role);
8212: }
8213: }
8214: }
8215: }
8216: my %usermodification_hash = (
8217: usermodification => \%modifyhash,
8218: );
8219: my $putresult = &Apache::lonnet::put_dom('configuration',
8220: \%usermodification_hash,$dom);
8221: if ($putresult eq 'ok') {
8222: if (keys(%changes) > 0) {
8223: $resulttext = &mt('Changes made: ').'<ul>';
8224: foreach my $context (@contexts) {
8225: if (ref($changes{$context}) eq 'ARRAY') {
8226: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
8227: if (ref($changes{$context}) eq 'ARRAY') {
8228: foreach my $role (@{$changes{$context}}) {
8229: my $rolename;
1.160.6.34! raeburn 8230: if ($role eq 'cr') {
! 8231: $rolename = &mt('Custom');
1.33 raeburn 8232: } else {
1.160.6.34! raeburn 8233: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 8234: }
8235: my @modifiable;
1.160.6.34! raeburn 8236: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 8237: foreach my $field (@fields) {
8238: if ($modifyhash{$context}{$role}{$field}) {
8239: push(@modifiable,$fieldtitles{$field});
8240: }
8241: }
8242: if (@modifiable > 0) {
8243: $resulttext .= join(', ',@modifiable);
8244: } else {
8245: $resulttext .= &mt('none');
8246: }
8247: $resulttext .= '</li>';
8248: }
8249: $resulttext .= '</ul></li>';
8250: }
8251: }
8252: }
8253: $resulttext .= '</ul>';
8254: } else {
8255: $resulttext = &mt('No changes made to user modification settings');
8256: }
8257: } else {
8258: $resulttext = '<span class="LC_error">'.
8259: &mt('An error occurred: [_1]',$putresult).'</span>';
8260: }
8261: return $resulttext;
8262: }
8263:
1.43 raeburn 8264: sub modify_defaults {
1.160.6.27 raeburn 8265: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 8266: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 8267: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 8268: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 8269: my @authtypes = ('internal','krb4','krb5','localauth');
8270: foreach my $item (@items) {
8271: $newvalues{$item} = $env{'form.'.$item};
8272: if ($item eq 'auth_def') {
8273: if ($newvalues{$item} ne '') {
8274: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
8275: push(@errors,$item);
8276: }
8277: }
8278: } elsif ($item eq 'lang_def') {
8279: if ($newvalues{$item} ne '') {
8280: if ($newvalues{$item} =~ /^(\w+)/) {
8281: my $langcode = $1;
1.103 raeburn 8282: if ($langcode ne 'x_chef') {
8283: if (code2language($langcode) eq '') {
8284: push(@errors,$item);
8285: }
1.43 raeburn 8286: }
8287: } else {
8288: push(@errors,$item);
8289: }
8290: }
1.54 raeburn 8291: } elsif ($item eq 'timezone_def') {
8292: if ($newvalues{$item} ne '') {
1.62 raeburn 8293: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 8294: push(@errors,$item);
8295: }
8296: }
1.68 raeburn 8297: } elsif ($item eq 'datelocale_def') {
8298: if ($newvalues{$item} ne '') {
8299: my @datelocale_ids = DateTime::Locale->ids();
8300: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
8301: push(@errors,$item);
8302: }
8303: }
1.141 raeburn 8304: } elsif ($item eq 'portal_def') {
8305: if ($newvalues{$item} ne '') {
8306: 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])\/?$/) {
8307: push(@errors,$item);
8308: }
8309: }
1.43 raeburn 8310: }
8311: if (grep(/^\Q$item\E$/,@errors)) {
8312: $newvalues{$item} = $domdefaults{$item};
8313: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
8314: $changes{$item} = 1;
8315: }
1.72 raeburn 8316: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 8317: }
8318: my %defaults_hash = (
1.72 raeburn 8319: defaults => \%newvalues,
8320: );
1.43 raeburn 8321: my $title = &defaults_titles();
8322: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
8323: $dom);
8324: if ($putresult eq 'ok') {
8325: if (keys(%changes) > 0) {
8326: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 8327: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 8328: 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";
8329: foreach my $item (sort(keys(%changes))) {
8330: my $value = $env{'form.'.$item};
8331: if ($value eq '') {
8332: $value = &mt('none');
8333: } elsif ($item eq 'auth_def') {
8334: my %authnames = &authtype_names();
8335: my %shortauth = (
8336: internal => 'int',
8337: krb4 => 'krb4',
8338: krb5 => 'krb5',
8339: localauth => 'loc',
8340: );
8341: $value = $authnames{$shortauth{$value}};
8342: }
8343: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
8344: $mailmsgtext .= "$title->{$item} set to $value\n";
8345: }
8346: $resulttext .= '</ul>';
8347: $mailmsgtext .= "\n";
8348: my $cachetime = 24*60*60;
1.72 raeburn 8349: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 8350: if (ref($lastactref) eq 'HASH') {
8351: $lastactref->{'domdefaults'} = 1;
8352: }
1.68 raeburn 8353: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 8354: my $notify = 1;
8355: if (ref($domconfig{'contacts'}) eq 'HASH') {
8356: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
8357: $notify = 0;
8358: }
8359: }
8360: if ($notify) {
8361: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
8362: "LON-CAPA Domain Settings Change - $dom",
8363: $mailmsgtext);
8364: }
1.54 raeburn 8365: }
1.43 raeburn 8366: } else {
1.54 raeburn 8367: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 8368: }
8369: } else {
8370: $resulttext = '<span class="LC_error">'.
8371: &mt('An error occurred: [_1]',$putresult).'</span>';
8372: }
8373: if (@errors > 0) {
8374: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
8375: foreach my $item (@errors) {
8376: $resulttext .= ' "'.$title->{$item}.'",';
8377: }
8378: $resulttext =~ s/,$//;
8379: }
8380: return $resulttext;
8381: }
8382:
1.46 raeburn 8383: sub modify_scantron {
1.160.6.24 raeburn 8384: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 8385: my ($resulttext,%confhash,%changes,$errors);
8386: my $custom = 'custom.tab';
8387: my $default = 'default.tab';
8388: my $servadm = $r->dir_config('lonAdmEMail');
8389: my ($configuserok,$author_ok,$switchserver) =
8390: &config_check($dom,$confname,$servadm);
8391: if ($env{'form.scantronformat.filename'} ne '') {
8392: my $error;
8393: if ($configuserok eq 'ok') {
8394: if ($switchserver) {
1.130 raeburn 8395: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 8396: } else {
8397: if ($author_ok eq 'ok') {
8398: my ($result,$scantronurl) =
8399: &publishlogo($r,'upload','scantronformat',$dom,
8400: $confname,'scantron','','',$custom);
8401: if ($result eq 'ok') {
8402: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 8403: $changes{'scantronformat'} = 1;
1.46 raeburn 8404: } else {
8405: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
8406: }
8407: } else {
8408: $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);
8409: }
8410: }
8411: } else {
8412: $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);
8413: }
8414: if ($error) {
8415: &Apache::lonnet::logthis($error);
8416: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8417: }
8418: }
1.48 raeburn 8419: if (ref($domconfig{'scantron'}) eq 'HASH') {
8420: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
8421: if ($env{'form.scantronformat_del'}) {
8422: $confhash{'scantron'}{'scantronformat'} = '';
8423: $changes{'scantronformat'} = 1;
1.46 raeburn 8424: }
8425: }
8426: }
8427: if (keys(%confhash) > 0) {
8428: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
8429: $dom);
8430: if ($putresult eq 'ok') {
8431: if (keys(%changes) > 0) {
1.48 raeburn 8432: if (ref($confhash{'scantron'}) eq 'HASH') {
8433: $resulttext = &mt('Changes made:').'<ul>';
8434: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 8435: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 8436: } else {
1.130 raeburn 8437: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 8438: }
1.48 raeburn 8439: $resulttext .= '</ul>';
8440: } else {
1.130 raeburn 8441: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 8442: }
8443: $resulttext .= '</ul>';
8444: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8445: if (ref($lastactref) eq 'HASH') {
8446: $lastactref->{'domainconfig'} = 1;
8447: }
1.46 raeburn 8448: } else {
1.130 raeburn 8449: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 8450: }
8451: } else {
8452: $resulttext = '<span class="LC_error">'.
8453: &mt('An error occurred: [_1]',$putresult).'</span>';
8454: }
8455: } else {
1.130 raeburn 8456: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 8457: }
8458: if ($errors) {
8459: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
8460: $errors.'</ul>';
8461: }
8462: return $resulttext;
8463: }
8464:
1.48 raeburn 8465: sub modify_coursecategories {
8466: my ($dom,%domconfig) = @_;
1.57 raeburn 8467: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
8468: $cathash);
1.48 raeburn 8469: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 8470: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 8471: $cathash = $domconfig{'coursecategories'}{'cats'};
8472: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
8473: $changes{'togglecats'} = 1;
8474: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
8475: }
8476: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
8477: $changes{'categorize'} = 1;
8478: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
8479: }
1.120 raeburn 8480: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
8481: $changes{'togglecatscomm'} = 1;
8482: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
8483: }
8484: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
8485: $changes{'categorizecomm'} = 1;
8486: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
8487: }
1.57 raeburn 8488: } else {
8489: $changes{'togglecats'} = 1;
8490: $changes{'categorize'} = 1;
1.124 raeburn 8491: $changes{'togglecatscomm'} = 1;
8492: $changes{'categorizecomm'} = 1;
1.87 raeburn 8493: $domconfig{'coursecategories'} = {
8494: togglecats => $env{'form.togglecats'},
8495: categorize => $env{'form.categorize'},
1.124 raeburn 8496: togglecatscomm => $env{'form.togglecatscomm'},
8497: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 8498: };
1.57 raeburn 8499: }
8500: if (ref($cathash) eq 'HASH') {
8501: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 8502: push (@deletecategory,'instcode::0');
8503: }
1.120 raeburn 8504: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
8505: push(@deletecategory,'communities::0');
8506: }
1.48 raeburn 8507: }
1.57 raeburn 8508: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
8509: if (ref($cathash) eq 'HASH') {
1.48 raeburn 8510: if (@deletecategory > 0) {
8511: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 8512: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 8513: foreach my $item (@deletecategory) {
1.57 raeburn 8514: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
8515: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 8516: $deletions{$item} = 1;
1.57 raeburn 8517: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 8518: }
8519: }
8520: }
1.57 raeburn 8521: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 8522: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 8523: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 8524: $reorderings{$item} = 1;
1.57 raeburn 8525: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 8526: }
8527: if ($env{'form.addcategory_name_'.$item} ne '') {
8528: my $newcat = $env{'form.addcategory_name_'.$item};
8529: my $newdepth = $depth+1;
8530: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 8531: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 8532: $adds{$newitem} = 1;
8533: }
8534: if ($env{'form.subcat_'.$item} ne '') {
8535: my $newcat = $env{'form.subcat_'.$item};
8536: my $newdepth = $depth+1;
8537: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 8538: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 8539: $adds{$newitem} = 1;
8540: }
8541: }
8542: }
8543: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 8544: if (ref($cathash) eq 'HASH') {
1.48 raeburn 8545: my $newitem = 'instcode::0';
1.57 raeburn 8546: if ($cathash->{$newitem} eq '') {
8547: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 8548: $adds{$newitem} = 1;
8549: }
8550: } else {
8551: my $newitem = 'instcode::0';
1.57 raeburn 8552: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 8553: $adds{$newitem} = 1;
8554: }
8555: }
1.120 raeburn 8556: if ($env{'form.communities'} eq '1') {
8557: if (ref($cathash) eq 'HASH') {
8558: my $newitem = 'communities::0';
8559: if ($cathash->{$newitem} eq '') {
8560: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
8561: $adds{$newitem} = 1;
8562: }
8563: } else {
8564: my $newitem = 'communities::0';
8565: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
8566: $adds{$newitem} = 1;
8567: }
8568: }
1.48 raeburn 8569: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 8570: if (($env{'form.addcategory_name'} ne 'instcode') &&
8571: ($env{'form.addcategory_name'} ne 'communities')) {
8572: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
8573: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
8574: $adds{$newitem} = 1;
8575: }
1.48 raeburn 8576: }
1.57 raeburn 8577: my $putresult;
1.48 raeburn 8578: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
8579: if (keys(%deletions) > 0) {
8580: foreach my $key (keys(%deletions)) {
8581: if ($predelallitems{$key} ne '') {
8582: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
8583: }
8584: }
8585: }
8586: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 8587: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 8588: if (ref($chkcats[0]) eq 'ARRAY') {
8589: my $depth = 0;
8590: my $chg = 0;
8591: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
8592: my $name = $chkcats[0][$i];
8593: my $item;
8594: if ($name eq '') {
8595: $chg ++;
8596: } else {
8597: $item = &escape($name).'::0';
8598: if ($chg) {
1.57 raeburn 8599: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 8600: }
8601: $depth ++;
1.57 raeburn 8602: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 8603: $depth --;
8604: }
8605: }
8606: }
1.57 raeburn 8607: }
8608: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
8609: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 8610: if ($putresult eq 'ok') {
1.57 raeburn 8611: my %title = (
1.120 raeburn 8612: togglecats => 'Show/Hide a course in catalog',
8613: categorize => 'Assign a category to a course',
8614: togglecatscomm => 'Show/Hide a community in catalog',
8615: categorizecomm => 'Assign a category to a community',
1.57 raeburn 8616: );
8617: my %level = (
1.120 raeburn 8618: dom => 'set in Domain ("Modify Course/Community")',
8619: crs => 'set in Course ("Course Configuration")',
8620: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 8621: );
1.48 raeburn 8622: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 8623: if ($changes{'togglecats'}) {
8624: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
8625: }
8626: if ($changes{'categorize'}) {
8627: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 8628: }
1.120 raeburn 8629: if ($changes{'togglecatscomm'}) {
8630: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
8631: }
8632: if ($changes{'categorizecomm'}) {
8633: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
8634: }
1.57 raeburn 8635: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
8636: my $cathash;
8637: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
8638: $cathash = $domconfig{'coursecategories'}{'cats'};
8639: } else {
8640: $cathash = {};
8641: }
8642: my (@cats,@trails,%allitems);
8643: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
8644: if (keys(%deletions) > 0) {
8645: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
8646: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
8647: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
8648: }
8649: $resulttext .= '</ul></li>';
8650: }
8651: if (keys(%reorderings) > 0) {
8652: my %sort_by_trail;
8653: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
8654: foreach my $key (keys(%reorderings)) {
8655: if ($allitems{$key} ne '') {
8656: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
8657: }
1.48 raeburn 8658: }
1.57 raeburn 8659: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
8660: $resulttext .= '<li>'.$trails[$trail].'</li>';
8661: }
8662: $resulttext .= '</ul></li>';
1.48 raeburn 8663: }
1.57 raeburn 8664: if (keys(%adds) > 0) {
8665: my %sort_by_trail;
8666: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
8667: foreach my $key (keys(%adds)) {
8668: if ($allitems{$key} ne '') {
8669: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
8670: }
8671: }
8672: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
8673: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 8674: }
1.57 raeburn 8675: $resulttext .= '</ul></li>';
1.48 raeburn 8676: }
8677: }
8678: $resulttext .= '</ul>';
8679: } else {
8680: $resulttext = '<span class="LC_error">'.
1.57 raeburn 8681: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 8682: }
8683: } else {
1.120 raeburn 8684: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 8685: }
8686: return $resulttext;
8687: }
8688:
1.69 raeburn 8689: sub modify_serverstatuses {
8690: my ($dom,%domconfig) = @_;
8691: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
8692: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
8693: %currserverstatus = %{$domconfig{'serverstatuses'}};
8694: }
8695: my @pages = &serverstatus_pages();
8696: foreach my $type (@pages) {
8697: $newserverstatus{$type}{'namedusers'} = '';
8698: $newserverstatus{$type}{'machines'} = '';
8699: if (defined($env{'form.'.$type.'_namedusers'})) {
8700: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
8701: my @okusers;
8702: foreach my $user (@users) {
8703: my ($uname,$udom) = split(/:/,$user);
8704: if (($udom =~ /^$match_domain$/) &&
8705: (&Apache::lonnet::domain($udom)) &&
8706: ($uname =~ /^$match_username$/)) {
8707: if (!grep(/^\Q$user\E/,@okusers)) {
8708: push(@okusers,$user);
8709: }
8710: }
8711: }
8712: if (@okusers > 0) {
8713: @okusers = sort(@okusers);
8714: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
8715: }
8716: }
8717: if (defined($env{'form.'.$type.'_machines'})) {
8718: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
8719: my @okmachines;
8720: foreach my $ip (@machines) {
8721: my @parts = split(/\./,$ip);
8722: next if (@parts < 4);
8723: my $badip = 0;
8724: for (my $i=0; $i<4; $i++) {
8725: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
8726: $badip = 1;
8727: last;
8728: }
8729: }
8730: if (!$badip) {
8731: push(@okmachines,$ip);
8732: }
8733: }
8734: @okmachines = sort(@okmachines);
8735: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
8736: }
8737: }
8738: my %serverstatushash = (
8739: serverstatuses => \%newserverstatus,
8740: );
8741: foreach my $type (@pages) {
1.83 raeburn 8742: foreach my $setting ('namedusers','machines') {
1.84 raeburn 8743: my (@current,@new);
1.83 raeburn 8744: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 8745: if ($currserverstatus{$type}{$setting} ne '') {
8746: @current = split(/,/,$currserverstatus{$type}{$setting});
8747: }
8748: }
8749: if ($newserverstatus{$type}{$setting} ne '') {
8750: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 8751: }
8752: if (@current > 0) {
8753: if (@new > 0) {
8754: foreach my $item (@current) {
8755: if (!grep(/^\Q$item\E$/,@new)) {
8756: $changes{$type}{$setting} = 1;
1.82 raeburn 8757: last;
8758: }
8759: }
1.84 raeburn 8760: foreach my $item (@new) {
8761: if (!grep(/^\Q$item\E$/,@current)) {
8762: $changes{$type}{$setting} = 1;
8763: last;
1.82 raeburn 8764: }
8765: }
8766: } else {
1.83 raeburn 8767: $changes{$type}{$setting} = 1;
1.69 raeburn 8768: }
1.83 raeburn 8769: } elsif (@new > 0) {
8770: $changes{$type}{$setting} = 1;
1.69 raeburn 8771: }
8772: }
8773: }
8774: if (keys(%changes) > 0) {
1.81 raeburn 8775: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 8776: my $putresult = &Apache::lonnet::put_dom('configuration',
8777: \%serverstatushash,$dom);
8778: if ($putresult eq 'ok') {
8779: $resulttext .= &mt('Changes made:').'<ul>';
8780: foreach my $type (@pages) {
1.84 raeburn 8781: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 8782: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 8783: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 8784: if ($newserverstatus{$type}{'namedusers'} eq '') {
8785: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
8786: } else {
8787: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
8788: }
1.84 raeburn 8789: }
8790: if ($changes{$type}{'machines'}) {
1.69 raeburn 8791: if ($newserverstatus{$type}{'machines'} eq '') {
8792: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
8793: } else {
8794: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
8795: }
8796:
8797: }
8798: $resulttext .= '</ul></li>';
8799: }
8800: }
8801: $resulttext .= '</ul>';
8802: } else {
8803: $resulttext = '<span class="LC_error">'.
8804: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
8805:
8806: }
8807: } else {
8808: $resulttext = &mt('No changes made to access to server status pages');
8809: }
8810: return $resulttext;
8811: }
8812:
1.118 jms 8813: sub modify_helpsettings {
1.122 jms 8814: my ($r,$dom,$confname,%domconfig) = @_;
1.160.6.5 raeburn 8815: my ($resulttext,$errors,%changes,%helphash);
8816: my %defaultchecked = ('submitbugs' => 'on');
8817: my @offon = ('off','on');
1.118 jms 8818: my @toggles = ('submitbugs');
8819: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8820: foreach my $item (@toggles) {
1.160.6.5 raeburn 8821: if ($defaultchecked{$item} eq 'on') {
8822: if ($domconfig{'helpsettings'}{$item} eq '') {
8823: if ($env{'form.'.$item} eq '0') {
8824: $changes{$item} = 1;
8825: }
8826: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
8827: $changes{$item} = 1;
8828: }
8829: } elsif ($defaultchecked{$item} eq 'off') {
8830: if ($domconfig{'helpsettings'}{$item} eq '') {
8831: if ($env{'form.'.$item} eq '1') {
8832: $changes{$item} = 1;
8833: }
8834: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
8835: $changes{$item} = 1;
8836: }
1.160.6.26 raeburn 8837: }
1.160.6.5 raeburn 8838: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
8839: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
1.122 jms 8840: }
8841: }
1.118 jms 8842: }
1.123 jms 8843: my $putresult;
8844: if (keys(%changes) > 0) {
1.160.6.5 raeburn 8845: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
8846: if ($putresult eq 'ok') {
8847: $resulttext = &mt('Changes made:').'<ul>';
8848: foreach my $item (sort(keys(%changes))) {
8849: if ($item eq 'submitbugs') {
8850: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
8851: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
8852: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
8853: }
8854: }
8855: $resulttext .= '</ul>';
8856: } else {
8857: $resulttext = &mt('No changes made to help settings');
8858: $errors .= '<li><span class="LC_error">'.
8859: &mt('An error occurred storing the settings: [_1]',
8860: $putresult).'</span></li>';
8861: }
1.118 jms 8862: }
8863: if ($errors) {
1.160.6.5 raeburn 8864: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 8865: $errors.'</ul>';
8866: }
8867: return $resulttext;
8868: }
8869:
1.121 raeburn 8870: sub modify_coursedefaults {
1.160.6.27 raeburn 8871: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 8872: my ($resulttext,$errors,%changes,%defaultshash);
8873: my %defaultchecked = ('canuse_pdfforms' => 'off');
8874: my @toggles = ('canuse_pdfforms');
1.160.6.21 raeburn 8875: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.30 raeburn 8876: 'uploadquota_community','uploadquota_textbook');
8877: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 8878: my %staticdefaults = (
8879: anonsurvey_threshold => 10,
8880: uploadquota => 500,
8881: );
1.121 raeburn 8882:
8883: $defaultshash{'coursedefaults'} = {};
8884:
8885: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
8886: if ($domconfig{'coursedefaults'} eq '') {
8887: $domconfig{'coursedefaults'} = {};
8888: }
8889: }
8890:
8891: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
8892: foreach my $item (@toggles) {
8893: if ($defaultchecked{$item} eq 'on') {
8894: if (($domconfig{'coursedefaults'}{$item} eq '') &&
8895: ($env{'form.'.$item} eq '0')) {
8896: $changes{$item} = 1;
1.160.6.16 raeburn 8897: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 8898: $changes{$item} = 1;
8899: }
8900: } elsif ($defaultchecked{$item} eq 'off') {
8901: if (($domconfig{'coursedefaults'}{$item} eq '') &&
8902: ($env{'form.'.$item} eq '1')) {
8903: $changes{$item} = 1;
8904: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
8905: $changes{$item} = 1;
8906: }
8907: }
8908: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
8909: }
1.160.6.21 raeburn 8910: foreach my $item (@numbers) {
8911: my ($currdef,$newdef);
1.160.6.26 raeburn 8912: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 8913: if ($item eq 'anonsurvey_threshold') {
8914: $currdef = $domconfig{'coursedefaults'}{$item};
8915: $newdef =~ s/\D//g;
8916: if ($newdef eq '' || $newdef < 1) {
8917: $newdef = 1;
8918: }
8919: $defaultshash{'coursedefaults'}{$item} = $newdef;
8920: } else {
8921: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
8922: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8923: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
8924: }
8925: $newdef =~ s/[^\w.\-]//g;
8926: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
8927: }
8928: if ($currdef ne $newdef) {
8929: my $staticdef;
8930: if ($item eq 'anonsurvey_threshold') {
8931: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
8932: $changes{$item} = 1;
8933: }
8934: } else {
8935: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
8936: $changes{'uploadquota'} = 1;
8937: }
8938: }
1.139 raeburn 8939: }
8940: }
1.160.6.16 raeburn 8941: my $officialcreds = $env{'form.official_credits'};
1.160.6.30 raeburn 8942: $officialcreds =~ s/[^\d.]+//g;
1.160.6.16 raeburn 8943: my $unofficialcreds = $env{'form.unofficial_credits'};
1.160.6.30 raeburn 8944: $unofficialcreds =~ s/[^\d.]+//g;
8945: my $textbookcreds = $env{'form.textbook_credits'};
8946: $textbookcreds =~ s/[^\d.]+//g;
1.160.6.16 raeburn 8947: if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
8948: ($env{'form.coursecredits'} eq '1')) {
8949: $changes{'coursecredits'} = 1;
8950: } else {
8951: if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
1.160.6.30 raeburn 8952: ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds) ||
8953: ($domconfig{'coursedefaults'}{'coursecredits'}{'textbook'} ne $textbookcreds)) {
1.160.6.16 raeburn 8954: $changes{'coursecredits'} = 1;
8955: }
8956: }
8957: $defaultshash{'coursedefaults'}{'coursecredits'} = {
8958: official => $officialcreds,
8959: unofficial => $unofficialcreds,
1.160.6.30 raeburn 8960: textbook => $textbookcreds,
1.160.6.16 raeburn 8961: }
1.121 raeburn 8962: }
8963: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8964: $dom);
8965: if ($putresult eq 'ok') {
8966: if (keys(%changes) > 0) {
1.160.6.27 raeburn 8967: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.21 raeburn 8968: if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) || ($changes{'uploadquota'})) {
1.160.6.16 raeburn 8969: if ($changes{'canuse_pdfforms'}) {
8970: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
8971: }
8972: if ($changes{'coursecredits'}) {
8973: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
8974: $domdefaults{'officialcredits'} =
8975: $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
8976: $domdefaults{'unofficialcredits'} =
8977: $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
1.160.6.30 raeburn 8978: $domdefaults{'textbookcredits'} =
8979: $domdefaults{'coursedefaults'}{'coursecredits'}{'textbook'};
1.160.6.16 raeburn 8980: }
8981: }
1.160.6.21 raeburn 8982: if ($changes{'uploadquota'}) {
8983: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8984: foreach my $type (@types) {
8985: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
8986: }
8987: }
8988: }
1.121 raeburn 8989: my $cachetime = 24*60*60;
8990: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 8991: if (ref($lastactref) eq 'HASH') {
8992: $lastactref->{'domdefaults'} = 1;
8993: }
1.121 raeburn 8994: }
8995: $resulttext = &mt('Changes made:').'<ul>';
8996: foreach my $item (sort(keys(%changes))) {
8997: if ($item eq 'canuse_pdfforms') {
8998: if ($env{'form.'.$item} eq '1') {
8999: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
9000: } else {
9001: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
9002: }
1.139 raeburn 9003: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 9004: $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 9005: } elsif ($item eq 'uploadquota') {
9006: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
9007: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
9008: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
9009: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 9010: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
9011:
1.160.6.21 raeburn 9012: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
9013: '</ul>'.
9014: '</li>';
9015: } else {
9016: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
9017: }
1.160.6.16 raeburn 9018: } elsif ($item eq 'coursecredits') {
9019: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
9020: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 9021: ($domdefaults{'unofficialcredits'} eq '') &&
9022: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 9023: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
9024: } else {
9025: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
9026: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
9027: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 9028: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 9029: '</ul>'.
9030: '</li>';
9031: }
9032: } else {
9033: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
9034: }
1.140 raeburn 9035: }
1.121 raeburn 9036: }
9037: $resulttext .= '</ul>';
9038: } else {
9039: $resulttext = &mt('No changes made to course defaults');
9040: }
9041: } else {
9042: $resulttext = '<span class="LC_error">'.
9043: &mt('An error occurred: [_1]',$putresult).'</span>';
9044: }
9045: return $resulttext;
9046: }
9047:
1.137 raeburn 9048: sub modify_usersessions {
1.160.6.27 raeburn 9049: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 9050: my @hostingtypes = ('version','excludedomain','includedomain');
9051: my @offloadtypes = ('primary','default');
9052: my %types = (
9053: remote => \@hostingtypes,
9054: hosted => \@hostingtypes,
9055: spares => \@offloadtypes,
9056: );
9057: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 9058: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 9059: my (%by_ip,%by_location,@intdoms);
9060: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
9061: my @locations = sort(keys(%by_location));
1.137 raeburn 9062: my (%defaultshash,%changes);
9063: foreach my $prefix (@prefixes) {
9064: $defaultshash{'usersessions'}{$prefix} = {};
9065: }
1.160.6.27 raeburn 9066: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 9067: my $resulttext;
1.138 raeburn 9068: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 9069: foreach my $prefix (@prefixes) {
1.145 raeburn 9070: next if ($prefix eq 'spares');
9071: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 9072: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
9073: if ($type eq 'version') {
9074: my $value = $env{'form.'.$prefix.'_'.$type};
9075: my $okvalue;
9076: if ($value ne '') {
9077: if (grep(/^\Q$value\E$/,@lcversions)) {
9078: $okvalue = $value;
9079: }
9080: }
9081: if (ref($domconfig{'usersessions'}) eq 'HASH') {
9082: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
9083: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
9084: if ($inuse == 0) {
9085: $changes{$prefix}{$type} = 1;
9086: } else {
9087: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
9088: $changes{$prefix}{$type} = 1;
9089: }
9090: if ($okvalue ne '') {
9091: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
9092: }
9093: }
9094: } else {
9095: if (($inuse == 1) && ($okvalue ne '')) {
9096: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
9097: $changes{$prefix}{$type} = 1;
9098: }
9099: }
9100: } else {
9101: if (($inuse == 1) && ($okvalue ne '')) {
9102: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
9103: $changes{$prefix}{$type} = 1;
9104: }
9105: }
9106: } else {
9107: if (($inuse == 1) && ($okvalue ne '')) {
9108: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
9109: $changes{$prefix}{$type} = 1;
9110: }
9111: }
9112: } else {
9113: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
9114: my @okvals;
9115: foreach my $val (@vals) {
1.138 raeburn 9116: if ($val =~ /:/) {
9117: my @items = split(/:/,$val);
9118: foreach my $item (@items) {
9119: if (ref($by_location{$item}) eq 'ARRAY') {
9120: push(@okvals,$item);
9121: }
9122: }
9123: } else {
9124: if (ref($by_location{$val}) eq 'ARRAY') {
9125: push(@okvals,$val);
9126: }
1.137 raeburn 9127: }
9128: }
9129: @okvals = sort(@okvals);
9130: if (ref($domconfig{'usersessions'}) eq 'HASH') {
9131: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
9132: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
9133: if ($inuse == 0) {
9134: $changes{$prefix}{$type} = 1;
9135: } else {
9136: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
9137: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
9138: if (@changed > 0) {
9139: $changes{$prefix}{$type} = 1;
9140: }
9141: }
9142: } else {
9143: if ($inuse == 1) {
9144: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
9145: $changes{$prefix}{$type} = 1;
9146: }
9147: }
9148: } else {
9149: if ($inuse == 1) {
9150: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
9151: $changes{$prefix}{$type} = 1;
9152: }
9153: }
9154: } else {
9155: if ($inuse == 1) {
9156: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
9157: $changes{$prefix}{$type} = 1;
9158: }
9159: }
9160: }
9161: }
9162: }
1.145 raeburn 9163:
9164: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 9165: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 9166: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
9167: my $savespares;
9168:
9169: foreach my $lonhost (sort(keys(%servers))) {
9170: my $serverhomeID =
9171: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 9172: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 9173: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
9174: my %spareschg;
9175: foreach my $type (@{$types{'spares'}}) {
9176: my @okspares;
9177: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
9178: foreach my $server (@checked) {
1.152 raeburn 9179: if (&Apache::lonnet::hostname($server) ne '') {
9180: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
9181: unless (grep(/^\Q$server\E$/,@okspares)) {
9182: push(@okspares,$server);
9183: }
1.145 raeburn 9184: }
9185: }
9186: }
9187: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
9188: my $newspare;
1.152 raeburn 9189: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
9190: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 9191: $newspare = $new;
9192: }
9193: }
1.152 raeburn 9194: my @spares;
9195: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
9196: @spares = sort(@okspares,$newspare);
9197: } else {
9198: @spares = sort(@okspares);
9199: }
9200: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 9201: if (ref($spareid{$lonhost}) eq 'HASH') {
9202: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 9203: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 9204: if (@diffs > 0) {
9205: $spareschg{$type} = 1;
9206: }
9207: }
9208: }
9209: }
9210: if (keys(%spareschg) > 0) {
9211: $changes{'spares'}{$lonhost} = \%spareschg;
9212: }
9213: }
9214:
9215: if (ref($domconfig{'usersessions'}) eq 'HASH') {
9216: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
9217: if (ref($changes{'spares'}) eq 'HASH') {
9218: if (keys(%{$changes{'spares'}}) > 0) {
9219: $savespares = 1;
9220: }
9221: }
9222: } else {
9223: $savespares = 1;
9224: }
9225: }
9226:
1.147 raeburn 9227: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
9228: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 9229: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
9230: $dom);
9231: if ($putresult eq 'ok') {
9232: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
9233: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
9234: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
9235: }
9236: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
9237: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
9238: }
9239: }
9240: my $cachetime = 24*60*60;
9241: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 9242: if (ref($lastactref) eq 'HASH') {
9243: $lastactref->{'domdefaults'} = 1;
9244: }
1.147 raeburn 9245: if (keys(%changes) > 0) {
9246: my %lt = &usersession_titles();
9247: $resulttext = &mt('Changes made:').'<ul>';
9248: foreach my $prefix (@prefixes) {
9249: if (ref($changes{$prefix}) eq 'HASH') {
9250: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
9251: if ($prefix eq 'spares') {
9252: if (ref($changes{$prefix}) eq 'HASH') {
9253: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
9254: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 9255: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 9256: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
9257: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 9258: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
9259: foreach my $type (@{$types{$prefix}}) {
9260: if ($changes{$prefix}{$lonhost}{$type}) {
9261: my $offloadto = &mt('None');
9262: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
9263: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
9264: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
9265: }
1.145 raeburn 9266: }
1.147 raeburn 9267: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 9268: }
1.137 raeburn 9269: }
9270: }
1.147 raeburn 9271: $resulttext .= '</li>';
1.137 raeburn 9272: }
9273: }
1.147 raeburn 9274: } else {
9275: foreach my $type (@{$types{$prefix}}) {
9276: if (defined($changes{$prefix}{$type})) {
9277: my $newvalue;
9278: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
9279: if (ref($defaultshash{'usersessions'}{$prefix})) {
9280: if ($type eq 'version') {
9281: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
9282: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
9283: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
9284: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
9285: }
1.145 raeburn 9286: }
9287: }
9288: }
1.147 raeburn 9289: if ($newvalue eq '') {
9290: if ($type eq 'version') {
9291: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
9292: } else {
9293: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
9294: }
1.145 raeburn 9295: } else {
1.147 raeburn 9296: if ($type eq 'version') {
9297: $newvalue .= ' '.&mt('(or later)');
9298: }
9299: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 9300: }
1.137 raeburn 9301: }
9302: }
9303: }
1.147 raeburn 9304: $resulttext .= '</ul>';
1.137 raeburn 9305: }
9306: }
1.147 raeburn 9307: $resulttext .= '</ul>';
9308: } else {
9309: $resulttext = $nochgmsg;
1.137 raeburn 9310: }
9311: } else {
9312: $resulttext = '<span class="LC_error">'.
9313: &mt('An error occurred: [_1]',$putresult).'</span>';
9314: }
9315: } else {
1.147 raeburn 9316: $resulttext = $nochgmsg;
1.137 raeburn 9317: }
9318: return $resulttext;
9319: }
9320:
1.150 raeburn 9321: sub modify_loadbalancing {
9322: my ($dom,%domconfig) = @_;
9323: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9324: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9325: my ($othertitle,$usertypes,$types) =
9326: &Apache::loncommon::sorted_inst_types($dom);
9327: my %servers = &Apache::lonnet::internet_dom_servers($dom);
9328: my @sparestypes = ('primary','default');
9329: my %typetitles = &sparestype_titles();
9330: my $resulttext;
1.160.6.7 raeburn 9331: my (%currbalancer,%currtargets,%currrules,%existing);
9332: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
9333: %existing = %{$domconfig{'loadbalancing'}};
9334: }
9335: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
9336: \%currtargets,\%currrules);
9337: my ($saveloadbalancing,%defaultshash,%changes);
9338: my ($alltypes,$othertypes,$titles) =
9339: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
9340: my %ruletitles = &offloadtype_text();
9341: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
9342: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
9343: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
9344: if ($balancer eq '') {
9345: next;
9346: }
9347: if (!exists($servers{$balancer})) {
9348: if (exists($currbalancer{$balancer})) {
9349: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 9350: }
1.160.6.7 raeburn 9351: next;
9352: }
9353: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
9354: push(@{$changes{'delete'}},$balancer);
9355: next;
9356: }
9357: if (!exists($currbalancer{$balancer})) {
9358: push(@{$changes{'add'}},$balancer);
9359: }
9360: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
9361: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
9362: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
9363: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
9364: $saveloadbalancing = 1;
9365: }
9366: foreach my $sparetype (@sparestypes) {
9367: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
9368: my @offloadto;
9369: foreach my $target (@targets) {
9370: if (($servers{$target}) && ($target ne $balancer)) {
9371: if ($sparetype eq 'default') {
9372: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
9373: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 9374: }
9375: }
1.160.6.7 raeburn 9376: unless(grep(/^\Q$target\E$/,@offloadto)) {
9377: push(@offloadto,$target);
9378: }
1.150 raeburn 9379: }
1.160.6.7 raeburn 9380: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 9381: }
9382: }
1.160.6.7 raeburn 9383: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 9384: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 9385: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
9386: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 9387: if (@targetdiffs > 0) {
1.160.6.7 raeburn 9388: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 9389: }
1.160.6.7 raeburn 9390: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
9391: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
9392: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 9393: }
9394: }
9395: }
9396: } else {
1.160.6.7 raeburn 9397: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
9398: foreach my $sparetype (@sparestypes) {
9399: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
9400: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
9401: $changes{'curr'}{$balancer}{'targets'} = 1;
9402: }
1.150 raeburn 9403: }
9404: }
1.160.6.7 raeburn 9405: }
1.150 raeburn 9406: }
9407: my $ishomedom;
1.160.6.7 raeburn 9408: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
9409: $ishomedom = 1;
1.150 raeburn 9410: }
9411: if (ref($alltypes) eq 'ARRAY') {
9412: foreach my $type (@{$alltypes}) {
9413: my $rule;
1.160.6.7 raeburn 9414: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 9415: (!$ishomedom)) {
1.160.6.7 raeburn 9416: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
9417: }
9418: if ($rule eq 'specific') {
9419: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 9420: }
1.160.6.7 raeburn 9421: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
9422: if (ref($currrules{$balancer}) eq 'HASH') {
9423: if ($rule ne $currrules{$balancer}{$type}) {
9424: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 9425: }
9426: } elsif ($rule ne '') {
1.160.6.7 raeburn 9427: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 9428: }
9429: }
9430: }
1.160.6.7 raeburn 9431: }
9432: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
9433: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
9434: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
9435: $defaultshash{'loadbalancing'} = {};
9436: }
9437: my $putresult = &Apache::lonnet::put_dom('configuration',
9438: \%defaultshash,$dom);
9439: if ($putresult eq 'ok') {
9440: if (keys(%changes) > 0) {
9441: if (ref($changes{'delete'}) eq 'ARRAY') {
9442: foreach my $balancer (sort(@{$changes{'delete'}})) {
9443: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.27 raeburn 9444: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
9445: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 9446: }
1.160.6.7 raeburn 9447: }
9448: if (ref($changes{'add'}) eq 'ARRAY') {
9449: foreach my $balancer (sort(@{$changes{'add'}})) {
9450: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
9451: }
9452: }
9453: if (ref($changes{'curr'}) eq 'HASH') {
9454: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
9455: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
9456: if ($changes{'curr'}{$balancer}{'targets'}) {
9457: my %offloadstr;
9458: foreach my $sparetype (@sparestypes) {
9459: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
9460: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
9461: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
9462: }
9463: }
1.150 raeburn 9464: }
1.160.6.7 raeburn 9465: if (keys(%offloadstr) == 0) {
9466: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 9467: } else {
1.160.6.7 raeburn 9468: my $showoffload;
9469: foreach my $sparetype (@sparestypes) {
9470: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
9471: if (defined($offloadstr{$sparetype})) {
9472: $showoffload .= $offloadstr{$sparetype};
9473: } else {
9474: $showoffload .= &mt('None');
9475: }
9476: $showoffload .= (' 'x3);
9477: }
9478: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 9479: }
9480: }
9481: }
1.160.6.7 raeburn 9482: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
9483: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
9484: foreach my $type (@{$alltypes}) {
9485: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
9486: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
9487: my $balancetext;
9488: if ($rule eq '') {
9489: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 9490: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
9491: ($rule eq 'balancer') || ($rule eq 'offloadedto')) {
1.160.6.7 raeburn 9492: $balancetext = $ruletitles{$rule};
9493: } else {
9494: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
9495: }
1.160.6.26 raeburn 9496: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 9497: }
9498: }
9499: }
9500: }
1.160.6.29 raeburn 9501: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
1.160.6.27 raeburn 9502: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 9503: }
1.160.6.7 raeburn 9504: }
9505: if ($resulttext ne '') {
9506: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 9507: } else {
9508: $resulttext = $nochgmsg;
9509: }
9510: } else {
1.160.6.7 raeburn 9511: $resulttext = $nochgmsg;
1.150 raeburn 9512: }
9513: } else {
1.160.6.7 raeburn 9514: $resulttext = '<span class="LC_error">'.
9515: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 9516: }
9517: } else {
1.160.6.7 raeburn 9518: $resulttext = $nochgmsg;
1.150 raeburn 9519: }
9520: return $resulttext;
9521: }
9522:
1.48 raeburn 9523: sub recurse_check {
9524: my ($chkcats,$categories,$depth,$name) = @_;
9525: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
9526: my $chg = 0;
9527: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
9528: my $category = $chkcats->[$depth]{$name}[$j];
9529: my $item;
9530: if ($category eq '') {
9531: $chg ++;
9532: } else {
9533: my $deeper = $depth + 1;
9534: $item = &escape($category).':'.&escape($name).':'.$depth;
9535: if ($chg) {
9536: $categories->{$item} -= $chg;
9537: }
9538: &recurse_check($chkcats,$categories,$deeper,$category);
9539: $deeper --;
9540: }
9541: }
9542: }
9543: return;
9544: }
9545:
9546: sub recurse_cat_deletes {
9547: my ($item,$coursecategories,$deletions) = @_;
9548: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9549: my $subdepth = $depth + 1;
9550: if (ref($coursecategories) eq 'HASH') {
9551: foreach my $subitem (keys(%{$coursecategories})) {
9552: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
9553: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
9554: delete($coursecategories->{$subitem});
9555: $deletions->{$subitem} = 1;
9556: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 9557: }
1.48 raeburn 9558: }
9559: }
9560: return;
9561: }
9562:
1.125 raeburn 9563: sub get_active_dcs {
9564: my ($dom) = @_;
1.160.6.16 raeburn 9565: my $now = time;
9566: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 9567: my %domcoords;
9568: my $numdcs = 0;
9569: foreach my $server (keys(%dompersonnel)) {
9570: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
9571: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.160.6.16 raeburn 9572: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 9573: }
9574: }
9575: return %domcoords;
9576: }
9577:
9578: sub active_dc_picker {
1.160.6.16 raeburn 9579: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.125 raeburn 9580: my %domcoords = &get_active_dcs($dom);
1.160.6.16 raeburn 9581: my @domcoord = keys(%domcoords);
9582: if (keys(%currhash)) {
9583: foreach my $dc (keys(%currhash)) {
9584: unless (exists($domcoords{$dc})) {
9585: push(@domcoord,$dc);
9586: }
9587: }
9588: }
9589: @domcoord = sort(@domcoord);
9590: my $numdcs = scalar(@domcoord);
9591: my $rows = 0;
9592: my $table;
1.125 raeburn 9593: if ($numdcs > 1) {
1.160.6.16 raeburn 9594: $table = '<table>';
9595: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 9596: my $rem = $i%($numinrow);
9597: if ($rem == 0) {
9598: if ($i > 0) {
1.160.6.16 raeburn 9599: $table .= '</tr>';
1.125 raeburn 9600: }
1.160.6.16 raeburn 9601: $table .= '<tr>';
9602: $rows ++;
1.125 raeburn 9603: }
1.160.6.16 raeburn 9604: my $check = '';
9605: if ($inputtype eq 'radio') {
9606: if (keys(%currhash) == 0) {
9607: if (!$i) {
9608: $check = ' checked="checked"';
9609: }
9610: } elsif (exists($currhash{$domcoord[$i]})) {
9611: $check = ' checked="checked"';
9612: }
9613: } else {
9614: if (exists($currhash{$domcoord[$i]})) {
9615: $check = ' checked="checked"';
1.125 raeburn 9616: }
9617: }
1.160.6.16 raeburn 9618: if ($i == @domcoord - 1) {
1.125 raeburn 9619: my $colsleft = $numinrow - $rem;
9620: if ($colsleft > 1) {
1.160.6.16 raeburn 9621: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 9622: } else {
1.160.6.16 raeburn 9623: $table .= '<td class="LC_left_item">';
1.125 raeburn 9624: }
9625: } else {
1.160.6.16 raeburn 9626: $table .= '<td class="LC_left_item">';
9627: }
9628: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
9629: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
9630: $table .= '<span class="LC_nobreak"><label>'.
9631: '<input type="'.$inputtype.'" name="'.$name.'"'.
9632: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
9633: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 9634: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 9635: }
1.160.6.33 raeburn 9636: $table .= '</label></span></td>';
1.125 raeburn 9637: }
1.160.6.16 raeburn 9638: $table .= '</tr></table>';
9639: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 9640: my ($dcname,$dcdom) = split(':',$domcoord[0]);
9641: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 9642: if ($inputtype eq 'radio') {
1.160.6.31 raeburn 9643: $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
9644: if ($user ne $dcname.':'.$dcdom) {
9645: $table .= ' ('.$dcname.':'.$dcdom.')';
9646: }
1.160.6.16 raeburn 9647: } else {
9648: my $check;
9649: if (exists($currhash{$domcoord[0]})) {
9650: $check = ' checked="checked"';
9651: }
1.160.6.31 raeburn 9652: $table .= '<span class="LC_nobreak"><label>'.
9653: '<input type="checkbox" name="'.$name.'" '.
9654: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
9655: if ($user ne $dcname.':'.$dcdom) {
9656: $table .= ' ('.$dcname.':'.$dcdom.')';
9657: }
9658: $table .= '</label></span>';
1.160.6.16 raeburn 9659: $rows ++;
9660: }
1.125 raeburn 9661: }
1.160.6.16 raeburn 9662: return ($numdcs,$table,$rows);
1.125 raeburn 9663: }
9664:
1.137 raeburn 9665: sub usersession_titles {
9666: return &Apache::lonlocal::texthash(
9667: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
9668: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 9669: spares => 'Servers offloaded to, when busy',
1.137 raeburn 9670: version => 'LON-CAPA version requirement',
1.138 raeburn 9671: excludedomain => 'Allow all, but exclude specific domains',
9672: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 9673: primary => 'Primary (checked first)',
1.154 raeburn 9674: default => 'Default',
1.137 raeburn 9675: );
9676: }
9677:
1.152 raeburn 9678: sub id_for_thisdom {
9679: my (%servers) = @_;
9680: my %altids;
9681: foreach my $server (keys(%servers)) {
9682: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
9683: if ($serverhome ne $server) {
9684: $altids{$serverhome} = $server;
9685: }
9686: }
9687: return %altids;
9688: }
9689:
1.150 raeburn 9690: sub count_servers {
9691: my ($currbalancer,%servers) = @_;
9692: my (@spares,$numspares);
9693: foreach my $lonhost (sort(keys(%servers))) {
9694: next if ($currbalancer eq $lonhost);
9695: push(@spares,$lonhost);
9696: }
9697: if ($currbalancer) {
9698: $numspares = scalar(@spares);
9699: } else {
9700: $numspares = scalar(@spares) - 1;
9701: }
9702: return ($numspares,@spares);
9703: }
9704:
9705: sub lonbalance_targets_js {
1.160.6.7 raeburn 9706: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 9707: my $select = &mt('Select');
9708: my ($alltargets,$allishome,$allinsttypes,@alltypes);
9709: if (ref($servers) eq 'HASH') {
9710: $alltargets = join("','",sort(keys(%{$servers})));
9711: my @homedoms;
9712: foreach my $server (sort(keys(%{$servers}))) {
9713: if (&Apache::lonnet::host_domain($server) eq $dom) {
9714: push(@homedoms,'1');
9715: } else {
9716: push(@homedoms,'0');
9717: }
9718: }
9719: $allishome = join("','",@homedoms);
9720: }
9721: if (ref($types) eq 'ARRAY') {
9722: if (@{$types} > 0) {
9723: @alltypes = @{$types};
9724: }
9725: }
9726: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
9727: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 9728: my (%currbalancer,%currtargets,%currrules,%existing);
9729: if (ref($settings) eq 'HASH') {
9730: %existing = %{$settings};
9731: }
9732: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
9733: \%currtargets,\%currrules);
9734: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 9735: return <<"END";
9736:
9737: <script type="text/javascript">
9738: // <![CDATA[
9739:
1.160.6.7 raeburn 9740: currBalancers = new Array('$balancers');
9741:
9742: function toggleTargets(balnum) {
9743: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
9744: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
9745: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
9746: var prevbalancer = prevhostitem.value;
9747: var baltotal = document.getElementById('loadbalancing_total').value;
9748: prevhostitem.value = balancer;
9749: if (prevbalancer != '') {
9750: var prevIdx = currBalancers.indexOf(prevbalancer);
9751: if (prevIdx != -1) {
9752: currBalancers.splice(prevIdx,1);
9753: }
9754: }
1.150 raeburn 9755: if (balancer == '') {
1.160.6.7 raeburn 9756: hideSpares(balnum);
1.150 raeburn 9757: } else {
1.160.6.7 raeburn 9758: var currIdx = currBalancers.indexOf(balancer);
9759: if (currIdx == -1) {
9760: currBalancers.push(balancer);
9761: }
1.150 raeburn 9762: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 9763: var ishomedom = homedoms[lonhostitem.selectedIndex];
9764: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 9765: }
1.160.6.7 raeburn 9766: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 9767: return;
9768: }
9769:
1.160.6.7 raeburn 9770: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 9771: var alltargets = new Array('$alltargets');
9772: var insttypes = new Array('$allinsttypes');
1.151 raeburn 9773: var offloadtypes = new Array('primary','default');
9774:
1.160.6.7 raeburn 9775: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
9776: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 9777:
1.151 raeburn 9778: for (var i=0; i<offloadtypes.length; i++) {
9779: var count = 0;
9780: for (var j=0; j<alltargets.length; j++) {
9781: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 9782: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
9783: item.value = alltargets[j];
9784: item.style.textAlign='left';
9785: item.style.textFace='normal';
9786: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
9787: if (currBalancers.indexOf(alltargets[j]) == -1) {
9788: item.disabled = '';
9789: } else {
9790: item.disabled = 'disabled';
9791: item.checked = false;
9792: }
1.151 raeburn 9793: count ++;
9794: }
1.150 raeburn 9795: }
9796: }
1.151 raeburn 9797: for (var k=0; k<insttypes.length; k++) {
9798: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 9799: if (ishomedom == 1) {
1.160.6.7 raeburn 9800: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
9801: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 9802: } else {
1.160.6.7 raeburn 9803: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
9804: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 9805: }
9806: } else {
1.160.6.7 raeburn 9807: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
9808: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 9809: }
1.151 raeburn 9810: if ((insttypes[k] != '_LC_external') &&
9811: ((insttypes[k] != '_LC_internetdom') ||
9812: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 9813: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
9814: item.options.length = 0;
9815: item.options[0] = new Option("","",true,true);
9816: var idx = 0;
1.151 raeburn 9817: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 9818: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
9819: idx ++;
9820: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 9821: }
9822: }
9823: }
9824: }
9825: return;
9826: }
9827:
1.160.6.7 raeburn 9828: function hideSpares(balnum) {
1.150 raeburn 9829: var alltargets = new Array('$alltargets');
9830: var insttypes = new Array('$allinsttypes');
9831: var offloadtypes = new Array('primary','default');
9832:
1.160.6.7 raeburn 9833: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
9834: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 9835:
9836: var total = alltargets.length - 1;
9837: for (var i=0; i<offloadtypes; i++) {
9838: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 9839: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
9840: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
9841: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 9842: }
1.150 raeburn 9843: }
9844: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 9845: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
9846: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 9847: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 9848: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
9849: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 9850: }
9851: }
9852: return;
9853: }
9854:
1.160.6.7 raeburn 9855: function checkOffloads(item,balnum,type) {
1.150 raeburn 9856: var alltargets = new Array('$alltargets');
9857: var offloadtypes = new Array('primary','default');
9858: if (item.checked) {
9859: var total = alltargets.length - 1;
9860: var other;
9861: if (type == offloadtypes[0]) {
1.151 raeburn 9862: other = offloadtypes[1];
1.150 raeburn 9863: } else {
1.151 raeburn 9864: other = offloadtypes[0];
1.150 raeburn 9865: }
9866: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 9867: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 9868: if (server == item.value) {
1.160.6.7 raeburn 9869: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
9870: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 9871: }
9872: }
9873: }
9874: }
9875: return;
9876: }
9877:
1.160.6.7 raeburn 9878: function singleServerToggle(balnum,type) {
9879: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 9880: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 9881: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
9882: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 9883:
9884: } else {
1.160.6.7 raeburn 9885: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
9886: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 9887: }
9888: return;
9889: }
9890:
1.160.6.7 raeburn 9891: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 9892: if (type == '_LC_external') {
1.160.6.26 raeburn 9893: return;
1.150 raeburn 9894: }
1.160.6.7 raeburn 9895: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 9896: for (var i=0; i<typesRules.length; i++) {
9897: if (formname.elements[typesRules[i]].checked) {
9898: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 9899: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
9900: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 9901: } else {
1.160.6.7 raeburn 9902: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
9903: }
9904: }
9905: }
9906: return;
9907: }
9908:
9909: function balancerDeleteChange(balnum) {
9910: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
9911: var baltotal = document.getElementById('loadbalancing_total').value;
9912: var addtarget;
9913: var removetarget;
9914: var action = 'delete';
9915: if (document.getElementById('loadbalancing_delete_'+balnum)) {
9916: var lonhost = hostitem.value;
9917: var currIdx = currBalancers.indexOf(lonhost);
9918: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
9919: if (currIdx != -1) {
9920: currBalancers.splice(currIdx,1);
9921: }
9922: addtarget = lonhost;
9923: } else {
9924: if (currIdx == -1) {
9925: currBalancers.push(lonhost);
9926: }
9927: removetarget = lonhost;
9928: action = 'undelete';
9929: }
9930: balancerChange(balnum,baltotal,action,addtarget,removetarget);
9931: }
9932: return;
9933: }
9934:
9935: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
9936: if (baltotal > 1) {
9937: var offloadtypes = new Array('primary','default');
9938: var alltargets = new Array('$alltargets');
9939: var insttypes = new Array('$allinsttypes');
9940: for (var i=0; i<baltotal; i++) {
9941: if (i != balnum) {
9942: for (var j=0; j<offloadtypes.length; j++) {
9943: var total = alltargets.length - 1;
9944: for (var k=0; k<total; k++) {
9945: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
9946: var server = serveritem.value;
9947: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
9948: if (server == addtarget) {
9949: serveritem.disabled = '';
9950: }
9951: }
9952: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
9953: if (server == removetarget) {
9954: serveritem.disabled = 'disabled';
9955: serveritem.checked = false;
9956: }
9957: }
9958: }
9959: }
9960: for (var j=0; j<insttypes.length; j++) {
9961: if (insttypes[j] != '_LC_external') {
9962: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
9963: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
9964: var currSel = singleserver.selectedIndex;
9965: var currVal = singleserver.options[currSel].value;
9966: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
9967: var numoptions = singleserver.options.length;
9968: var needsnew = 1;
9969: for (var k=0; k<numoptions; k++) {
9970: if (singleserver.options[k] == addtarget) {
9971: needsnew = 0;
9972: break;
9973: }
9974: }
9975: if (needsnew == 1) {
9976: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
9977: }
9978: }
9979: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
9980: singleserver.options.length = 0;
9981: if ((currVal) && (currVal != removetarget)) {
9982: singleserver.options[0] = new Option("","",false,false);
9983: } else {
9984: singleserver.options[0] = new Option("","",true,true);
9985: }
9986: var idx = 0;
9987: for (var m=0; m<alltargets.length; m++) {
9988: if (currBalancers.indexOf(alltargets[m]) == -1) {
9989: idx ++;
9990: if (currVal == alltargets[m]) {
9991: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
9992: } else {
9993: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
9994: }
9995: }
9996: }
9997: }
9998: }
9999: }
10000: }
1.150 raeburn 10001: }
10002: }
10003: }
10004: return;
10005: }
10006:
1.152 raeburn 10007: // ]]>
10008: </script>
10009:
10010: END
10011: }
10012:
10013: sub new_spares_js {
10014: my @sparestypes = ('primary','default');
10015: my $types = join("','",@sparestypes);
10016: my $select = &mt('Select');
10017: return <<"END";
10018:
10019: <script type="text/javascript">
10020: // <![CDATA[
10021:
10022: function updateNewSpares(formname,lonhost) {
10023: var types = new Array('$types');
10024: var include = new Array();
10025: var exclude = new Array();
10026: for (var i=0; i<types.length; i++) {
10027: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
10028: for (var j=0; j<spareboxes.length; j++) {
10029: if (formname.elements[spareboxes[j]].checked) {
10030: exclude.push(formname.elements[spareboxes[j]].value);
10031: } else {
10032: include.push(formname.elements[spareboxes[j]].value);
10033: }
10034: }
10035: }
10036: for (var i=0; i<types.length; i++) {
10037: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
10038: var selIdx = newSpare.selectedIndex;
10039: var currnew = newSpare.options[selIdx].value;
10040: var okSpares = new Array();
10041: for (var j=0; j<newSpare.options.length; j++) {
10042: var possible = newSpare.options[j].value;
10043: if (possible != '') {
10044: if (exclude.indexOf(possible) == -1) {
10045: okSpares.push(possible);
10046: } else {
10047: if (currnew == possible) {
10048: selIdx = 0;
10049: }
10050: }
10051: }
10052: }
10053: for (var k=0; k<include.length; k++) {
10054: if (okSpares.indexOf(include[k]) == -1) {
10055: okSpares.push(include[k]);
10056: }
10057: }
10058: okSpares.sort();
10059: newSpare.options.length = 0;
10060: if (selIdx == 0) {
10061: newSpare.options[0] = new Option("$select","",true,true);
10062: } else {
10063: newSpare.options[0] = new Option("$select","",false,false);
10064: }
10065: for (var m=0; m<okSpares.length; m++) {
10066: var idx = m+1;
10067: var selThis = 0;
10068: if (selIdx != 0) {
10069: if (okSpares[m] == currnew) {
10070: selThis = 1;
10071: }
10072: }
10073: if (selThis == 1) {
10074: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
10075: } else {
10076: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
10077: }
10078: }
10079: }
10080: return;
10081: }
10082:
10083: function checkNewSpares(lonhost,type) {
10084: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
10085: var chosen = newSpare.options[newSpare.selectedIndex].value;
10086: if (chosen != '') {
10087: var othertype;
10088: var othernewSpare;
10089: if (type == 'primary') {
10090: othernewSpare = document.getElementById('newspare_default_'+lonhost);
10091: }
10092: if (type == 'default') {
10093: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
10094: }
10095: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
10096: othernewSpare.selectedIndex = 0;
10097: }
10098: }
10099: return;
10100: }
10101:
10102: // ]]>
10103: </script>
10104:
10105: END
10106:
10107: }
10108:
10109: sub common_domprefs_js {
10110: return <<"END";
10111:
10112: <script type="text/javascript">
10113: // <![CDATA[
10114:
1.150 raeburn 10115: function getIndicesByName(formname,item) {
1.152 raeburn 10116: var group = new Array();
1.150 raeburn 10117: for (var i=0;i<formname.elements.length;i++) {
10118: if (formname.elements[i].name == item) {
1.152 raeburn 10119: group.push(formname.elements[i].id);
1.150 raeburn 10120: }
10121: }
1.152 raeburn 10122: return group;
1.150 raeburn 10123: }
10124:
10125: // ]]>
10126: </script>
10127:
10128: END
1.152 raeburn 10129:
1.150 raeburn 10130: }
10131:
1.160.6.5 raeburn 10132: sub recaptcha_js {
10133: my %lt = &captcha_phrases();
10134: return <<"END";
10135:
10136: <script type="text/javascript">
10137: // <![CDATA[
10138:
10139: function updateCaptcha(caller,context) {
10140: var privitem;
10141: var pubitem;
10142: var privtext;
10143: var pubtext;
10144: if (document.getElementById(context+'_recaptchapub')) {
10145: pubitem = document.getElementById(context+'_recaptchapub');
10146: } else {
10147: return;
10148: }
10149: if (document.getElementById(context+'_recaptchapriv')) {
10150: privitem = document.getElementById(context+'_recaptchapriv');
10151: } else {
10152: return;
10153: }
10154: if (document.getElementById(context+'_recaptchapubtxt')) {
10155: pubtext = document.getElementById(context+'_recaptchapubtxt');
10156: } else {
10157: return;
10158: }
10159: if (document.getElementById(context+'_recaptchaprivtxt')) {
10160: privtext = document.getElementById(context+'_recaptchaprivtxt');
10161: } else {
10162: return;
10163: }
10164: if (caller.checked) {
10165: if (caller.value == 'recaptcha') {
10166: pubitem.type = 'text';
10167: privitem.type = 'text';
10168: pubitem.size = '40';
10169: privitem.size = '40';
10170: pubtext.innerHTML = "$lt{'pub'}";
10171: privtext.innerHTML = "$lt{'priv'}";
10172: } else {
10173: pubitem.type = 'hidden';
10174: privitem.type = 'hidden';
10175: pubtext.innerHTML = '';
10176: privtext.innerHTML = '';
10177: }
10178: }
10179: return;
10180: }
10181:
10182: // ]]>
10183: </script>
10184:
10185: END
10186:
10187: }
10188:
1.160.6.16 raeburn 10189: sub credits_js {
10190: return <<"END";
10191:
10192: <script type="text/javascript">
10193: // <![CDATA[
10194:
10195: function toggleCredits(domForm) {
10196: if (document.getElementById('credits')) {
10197: creditsitem = document.getElementById('credits');
10198: var creditsLength = domForm.coursecredits.length;
10199: if (creditsLength) {
10200: var currval;
10201: for (var i=0; i<creditsLength; i++) {
10202: if (domForm.coursecredits[i].checked) {
10203: currval = domForm.coursecredits[i].value;
10204: }
10205: }
10206: if (currval == 1) {
10207: creditsitem.style.display = 'block';
10208: } else {
10209: creditsitem.style.display = 'none';
10210: }
10211: }
10212: }
10213: return;
10214: }
10215:
10216: // ]]>
10217: </script>
10218:
10219: END
10220:
10221: }
10222:
1.160.6.5 raeburn 10223: sub captcha_phrases {
10224: return &Apache::lonlocal::texthash (
10225: priv => 'Private key',
10226: pub => 'Public key',
10227: original => 'original (CAPTCHA)',
10228: recaptcha => 'successor (ReCAPTCHA)',
10229: notused => 'unused',
10230: );
10231: }
10232:
1.160.6.24 raeburn 10233: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 10234: my ($dom,$cachekeys) = @_;
10235: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 10236: my %servers = &Apache::lonnet::internet_dom_servers($dom);
10237: my %thismachine;
10238: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.27 raeburn 10239: my @posscached = ('domainconfig','domdefaults');
1.160.6.24 raeburn 10240: if (keys(%servers) > 1) {
10241: foreach my $server (keys(%servers)) {
10242: next if ($thismachine{$server});
1.160.6.27 raeburn 10243: my @cached;
10244: foreach my $name (@posscached) {
10245: if ($cachekeys->{$name}) {
10246: push(@cached,&escape($name).':'.&escape($dom));
10247: }
10248: }
10249: if (@cached) {
10250: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
10251: }
1.160.6.24 raeburn 10252: }
10253: }
10254: return;
10255: }
10256:
1.3 raeburn 10257: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>