Annotation of loncom/interface/domainprefs.pm, revision 1.216
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.216 ! raeburn 4: # $Id: domainprefs.pm,v 1.215 2013/12/23 13:20: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.183 bisitz 48: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 49: may define a default set of logos and a color scheme which can be used to "brand"
50: the LON-CAPA instance. In addition, an institution will typically have a language
51: and timezone which are used for the majority of courses.
52:
53: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
54: host of other domain-wide settings which determine the types of functionality
55: available to users and courses in the domain.
56:
57: There is also a mechanism to configure cataloging of courses in the domain, and
58: controls on the operation of automated processes which govern such things as
59: roster updates, user directory updates and processing of course requests.
60:
61: The domain coordination manual which is built dynamically on install/update of
62: LON-CAPA from the relevant help items provides more information about domain
63: configuration.
64:
65: Most of the domain settings are stored in the configuration.db GDBM file which is
66: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
67: where $dom is the domain. The configuration.db stores settings in a number of
68: frozen hashes of hashes. In a few cases, domain information must be uploaded to
69: the domain as files (e.g., image files for logos etc., or plain text files for
70: bubblesheet formats). In this case the domainprefs.pm must be running in a user
71: session hosted on the primary library server in the domain, as these files are
72: stored in author space belonging to a special $dom-domainconfig user.
73:
74: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
75: the current settings, and provides an interface to make modifications.
76:
77: =head1 SUBROUTINES
78:
79: =over
80:
81: =item print_quotas()
82:
83: Inputs: 4
84:
85: $dom,$settings,$rowtotal,$action.
86:
87: $dom is the domain, $settings is a reference to a hash of current settings for
88: the current context, $rowtotal is a reference to the scalar used to record the
1.210 raeburn 89: number of rows displayed on the page, and $action is the context (quotas,
1.163 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.197 raeburn 97: used by course owners to request creation of a course, and to display/store
98: default quota sizes for authoring spaces.
1.101 raeburn 99:
100: Outputs: 1
101:
102: $datatable - HTML containing form elements which allow settings to be changed.
103:
104: In the case of course requests, radio buttons are displayed for each institutional
105: affiliate type (and also default, and _LC_adv) for each of the course types
1.216 ! 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',
214: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 215: 'coursedefaults','usersessions','loadbalancing',
216: 'requestauthor'],$dom);
1.43 raeburn 217: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 218: 'autoupdate','autocreate','directorysrch','contacts',
1.48 raeburn 219: 'usercreation','usermodification','scantron',
1.163 raeburn 220: 'requestcourses','requestauthor','coursecategories',
221: 'serverstatuses','helpsettings',
1.137 raeburn 222: 'coursedefaults','usersessions');
1.171 raeburn 223: my %existing;
224: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
225: %existing = %{$domconfig{'loadbalancing'}};
226: }
227: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 228: push(@prefs_order,'loadbalancing');
229: }
1.30 raeburn 230: my %prefs = (
231: 'rolecolors' =>
232: { text => 'Default color schemes',
1.67 raeburn 233: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 234: header => [{col1 => 'Student Settings',
235: col2 => '',},
236: {col1 => 'Coordinator Settings',
237: col2 => '',},
238: {col1 => 'Author Settings',
239: col2 => '',},
240: {col1 => 'Administrator Settings',
241: col2 => '',}],
242: },
1.110 raeburn 243: 'login' =>
1.30 raeburn 244: { text => 'Log-in page options',
1.67 raeburn 245: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 246: header => [{col1 => 'Log-in Page Items',
247: col2 => '',},
248: {col1 => 'Log-in Help',
249: col2 => 'Value'}],
1.30 raeburn 250: },
1.43 raeburn 251: 'defaults' =>
1.141 raeburn 252: { text => 'Default authentication/language/timezone/portal',
1.67 raeburn 253: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 254: header => [{col1 => 'Setting',
255: col2 => 'Value'}],
256: },
1.30 raeburn 257: 'quotas' =>
1.197 raeburn 258: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 259: help => 'Domain_Configuration_Quotas',
1.77 raeburn 260: header => [{col1 => 'User affiliation',
1.72 raeburn 261: col2 => 'Available tools',
1.213 raeburn 262: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.30 raeburn 263: },
264: 'autoenroll' =>
265: { text => 'Auto-enrollment settings',
1.67 raeburn 266: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 267: header => [{col1 => 'Configuration setting',
268: col2 => 'Value(s)'}],
269: },
270: 'autoupdate' =>
271: { text => 'Auto-update settings',
1.67 raeburn 272: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 273: header => [{col1 => 'Setting',
274: col2 => 'Value',},
1.131 raeburn 275: {col1 => 'Setting',
276: col2 => 'Affiliation'},
1.43 raeburn 277: {col1 => 'User population',
1.131 raeburn 278: col2 => 'Updateable user data'}],
1.30 raeburn 279: },
1.125 raeburn 280: 'autocreate' =>
281: { text => 'Auto-course creation settings',
282: help => 'Domain_Configuration_Auto_Creation',
283: header => [{col1 => 'Configuration Setting',
284: col2 => 'Value',}],
285: },
1.30 raeburn 286: 'directorysrch' =>
287: { text => 'Institutional directory searches',
1.67 raeburn 288: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 289: header => [{col1 => 'Setting',
290: col2 => 'Value',}],
291: },
292: 'contacts' =>
293: { text => 'Contact Information',
1.67 raeburn 294: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 295: header => [{col1 => 'Setting',
296: col2 => 'Value',}],
297: },
298:
299: 'usercreation' =>
300: { text => 'User creation',
1.67 raeburn 301: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 302: header => [{col1 => 'Format rule type',
303: col2 => 'Format rules in force'},
1.34 raeburn 304: {col1 => 'User account creation',
305: col2 => 'Usernames which may be created',},
1.30 raeburn 306: {col1 => 'Context',
1.43 raeburn 307: col2 => 'Assignable authentication types'}],
1.30 raeburn 308: },
1.69 raeburn 309: 'usermodification' =>
1.33 raeburn 310: { text => 'User modification',
1.67 raeburn 311: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 312: header => [{col1 => 'Target user has role',
313: col2 => 'User information updateable in author context'},
314: {col1 => 'Target user has role',
1.63 raeburn 315: col2 => 'User information updateable in course context'},
316: {col1 => "Status of user",
317: col2 => 'Information settable when self-creating account (if directory data blank)'}],
1.33 raeburn 318: },
1.69 raeburn 319: 'scantron' =>
1.95 www 320: { text => 'Bubblesheet format file',
1.67 raeburn 321: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 322: header => [ {col1 => 'Item',
323: col2 => '',
324: }],
325: },
1.86 raeburn 326: 'requestcourses' =>
327: {text => 'Request creation of courses',
328: help => 'Domain_Configuration_Request_Courses',
329: header => [{col1 => 'User affiliation',
1.102 raeburn 330: col2 => 'Availability/Processing of requests',},
331: {col1 => 'Setting',
1.216 ! raeburn 332: col2 => 'Value'},
! 333: {col1 => 'Available textbooks',
! 334: col2 => ''}],
1.86 raeburn 335: },
1.163 raeburn 336: 'requestauthor' =>
337: {text => 'Request authoring space',
338: help => 'Domain_Configuration_Request_Author',
339: header => [{col1 => 'User affiliation',
340: col2 => 'Availability/Processing of requests',},
341: {col1 => 'Setting',
342: col2 => 'Value'}],
343: },
1.69 raeburn 344: 'coursecategories' =>
1.120 raeburn 345: { text => 'Cataloging of courses/communities',
1.67 raeburn 346: help => 'Domain_Configuration_Cataloging_Courses',
1.69 raeburn 347: header => [{col1 => 'Category settings',
1.57 raeburn 348: col2 => '',},
349: {col1 => 'Categories',
350: col2 => '',
351: }],
1.69 raeburn 352: },
353: 'serverstatuses' =>
1.77 raeburn 354: {text => 'Access to server status pages',
1.69 raeburn 355: help => 'Domain_Configuration_Server_Status',
356: header => [{col1 => 'Status Page',
357: col2 => 'Other named users',
358: col3 => 'Specific IPs',
359: }],
360: },
1.118 jms 361: 'helpsettings' =>
362: {text => 'Help page settings',
363: help => 'Domain_Configuration_Help_Settings',
1.166 raeburn 364: header => [{col1 => 'Help Settings (logged-in users)',
365: col2 => 'Value'}],
1.118 jms 366: },
1.121 raeburn 367: 'coursedefaults' =>
368: {text => 'Course/Community defaults',
369: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 370: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
371: col2 => 'Value',},
372: {col1 => 'Defaults which can be overridden for each course by a DC',
373: col2 => 'Value',},],
1.121 raeburn 374: },
1.120 raeburn 375: 'privacy' =>
376: {text => 'User Privacy',
377: help => 'Domain_Configuration_User_Privacy',
378: header => [{col1 => 'Setting',
379: col2 => 'Value',}],
380: },
1.141 raeburn 381: 'usersessions' =>
1.145 raeburn 382: {text => 'User session hosting/offloading',
1.137 raeburn 383: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 384: header => [{col1 => 'Domain server',
385: col2 => 'Servers to offload sessions to when busy'},
386: {col1 => 'Hosting of users from other domains',
1.137 raeburn 387: col2 => 'Rules'},
388: {col1 => "Hosting domain's own users elsewhere",
389: col2 => 'Rules'}],
390: },
1.150 raeburn 391: 'loadbalancing' =>
1.185 raeburn 392: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 393: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 394: header => [{col1 => 'Balancers',
1.150 raeburn 395: col2 => 'Default destinations',
1.183 bisitz 396: col3 => 'User affiliation',
1.150 raeburn 397: col4 => 'Overrides'},
398: ],
399: },
1.3 raeburn 400: );
1.110 raeburn 401: if (keys(%servers) > 1) {
402: $prefs{'login'} = { text => 'Log-in page options',
403: help => 'Domain_Configuration_Login_Page',
404: header => [{col1 => 'Log-in Service',
405: col2 => 'Server Setting',},
406: {col1 => 'Log-in Page Items',
1.168 raeburn 407: col2 => ''},
408: {col1 => 'Log-in Help',
409: col2 => 'Value'}],
1.110 raeburn 410: };
411: }
1.174 foxr 412:
1.6 raeburn 413: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 414: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 415: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 416: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 417: text=>"Settings to display/modify"});
1.9 raeburn 418: my $confname = $dom.'-domainconfig';
1.174 foxr 419:
1.3 raeburn 420: if ($phase eq 'process') {
1.212 raeburn 421: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
422: \%prefs,\%domconfig,$confname,\@roles);
423: if (ref($result) eq 'HASH') {
1.205 raeburn 424: $r->rflush();
1.212 raeburn 425: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 426: }
1.30 raeburn 427: } elsif ($phase eq 'display') {
1.192 raeburn 428: my $js = &recaptcha_js().
429: &credits_js();
1.171 raeburn 430: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 431: my ($othertitle,$usertypes,$types) =
432: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 433: $js .= &lonbalance_targets_js($dom,$types,\%servers,
434: $domconfig{'loadbalancing'}).
1.170 raeburn 435: &new_spares_js().
436: &common_domprefs_js().
437: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 438: }
1.216 ! raeburn 439: if (grep(/^requestcourses$/,@actions)) {
! 440: my $javascript_validations;
! 441: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
! 442: $js .= <<END;
! 443: <script type="text/javascript">
! 444: $javascript_validations
! 445: </script>
! 446: $coursebrowserjs
! 447: END
! 448: }
1.150 raeburn 449: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 450: } else {
1.180 raeburn 451: # check if domconfig user exists for the domain.
452: my $servadm = $r->dir_config('lonAdmEMail');
453: my ($configuserok,$author_ok,$switchserver) =
454: &config_check($dom,$confname,$servadm);
455: unless ($configuserok eq 'ok') {
1.181 raeburn 456: &Apache::lonconfigsettings::print_header($r,$phase,$context);
457: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 458: $confname).
1.181 raeburn 459: '<br />'
460: );
1.180 raeburn 461: if ($switchserver) {
1.181 raeburn 462: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
463: '<br />'.
464: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
465: '<br />'.
466: &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).
467: '<br />'.
468: &mt('To do that now, use the following link: [_1]',$switchserver)
469: );
470: } else {
471: $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.').
472: '<br />'.
473: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
474: );
1.180 raeburn 475: }
476: $r->print(&Apache::loncommon::end_page());
477: return OK;
478: }
1.21 raeburn 479: if (keys(%domconfig) == 0) {
480: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 481: my @ids=&Apache::lonnet::current_machine_ids();
482: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 483: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 484: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 485: my $custom_img_count = 0;
486: foreach my $img (@loginimages) {
487: if ($designhash{$dom.'.login.'.$img} ne '') {
488: $custom_img_count ++;
489: }
490: }
491: foreach my $role (@roles) {
492: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
493: $custom_img_count ++;
494: }
495: }
496: if ($custom_img_count > 0) {
1.94 raeburn 497: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 498: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 499: $r->print(
500: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
501: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
502: &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 />'.
503: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
504: if ($switch_server) {
1.30 raeburn 505: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 506: }
1.91 raeburn 507: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 508: return OK;
509: }
510: }
511: }
1.91 raeburn 512: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 513: }
514: return OK;
515: }
516:
517: sub process_changes {
1.205 raeburn 518: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 519: my %domconfig;
520: if (ref($values) eq 'HASH') {
521: %domconfig = %{$values};
522: }
1.3 raeburn 523: my $output;
524: if ($action eq 'login') {
1.205 raeburn 525: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 526: } elsif ($action eq 'rolecolors') {
1.9 raeburn 527: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 528: $lastactref,%domconfig);
1.3 raeburn 529: } elsif ($action eq 'quotas') {
1.216 ! raeburn 530: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 531: } elsif ($action eq 'autoenroll') {
1.205 raeburn 532: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 533: } elsif ($action eq 'autoupdate') {
534: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 535: } elsif ($action eq 'autocreate') {
536: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 537: } elsif ($action eq 'directorysrch') {
538: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 539: } elsif ($action eq 'usercreation') {
1.28 raeburn 540: $output = &modify_usercreation($dom,%domconfig);
1.33 raeburn 541: } elsif ($action eq 'usermodification') {
542: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 543: } elsif ($action eq 'contacts') {
1.205 raeburn 544: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 545: } elsif ($action eq 'defaults') {
1.212 raeburn 546: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 547: } elsif ($action eq 'scantron') {
1.205 raeburn 548: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 549: } elsif ($action eq 'coursecategories') {
550: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 551: } elsif ($action eq 'serverstatuses') {
552: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 553: } elsif ($action eq 'requestcourses') {
1.216 ! raeburn 554: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 555: } elsif ($action eq 'requestauthor') {
1.216 ! raeburn 556: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 557: } elsif ($action eq 'helpsettings') {
1.122 jms 558: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121 raeburn 559: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 560: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.137 raeburn 561: } elsif ($action eq 'usersessions') {
1.212 raeburn 562: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 563: } elsif ($action eq 'loadbalancing') {
564: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 565: }
566: return $output;
567: }
568:
569: sub print_config_box {
1.9 raeburn 570: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 571: my $rowtotal = 0;
1.49 raeburn 572: my $output;
573: if ($action eq 'coursecategories') {
574: $output = &coursecategories_javascript($settings);
1.91 raeburn 575: }
1.49 raeburn 576: $output .=
1.30 raeburn 577: '<table class="LC_nested_outer">
1.3 raeburn 578: <tr>
1.66 raeburn 579: <th align="left" valign="middle"><span class="LC_nobreak">'.
580: &mt($item->{text}).' '.
581: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
582: '</tr>';
1.30 raeburn 583: $rowtotal ++;
1.110 raeburn 584: my $numheaders = 1;
585: if (ref($item->{'header'}) eq 'ARRAY') {
586: $numheaders = scalar(@{$item->{'header'}});
587: }
588: if ($numheaders > 1) {
1.64 raeburn 589: my $colspan = '';
1.145 raeburn 590: my $rightcolspan = '';
1.210 raeburn 591: if (($action eq 'rolecolors') || ($action eq 'coursecategories') ||
1.168 raeburn 592: (($action eq 'login') && ($numheaders < 3))) {
1.64 raeburn 593: $colspan = ' colspan="2"';
594: }
1.145 raeburn 595: if ($action eq 'usersessions') {
596: $rightcolspan = ' colspan="3"';
597: }
1.30 raeburn 598: $output .= '
1.3 raeburn 599: <tr>
600: <td>
601: <table class="LC_nested">
602: <tr class="LC_info_row">
1.59 bisitz 603: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 604: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 605: </tr>';
1.69 raeburn 606: $rowtotal ++;
1.6 raeburn 607: if ($action eq 'autoupdate') {
1.30 raeburn 608: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 609: } elsif ($action eq 'usercreation') {
1.33 raeburn 610: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
611: } elsif ($action eq 'usermodification') {
612: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57 raeburn 613: } elsif ($action eq 'coursecategories') {
614: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 615: } elsif ($action eq 'login') {
1.168 raeburn 616: if ($numheaders == 3) {
617: $colspan = ' colspan="2"';
618: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
619: } else {
620: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
621: }
1.102 raeburn 622: } elsif ($action eq 'requestcourses') {
623: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.163 raeburn 624: } elsif ($action eq 'requestauthor') {
625: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.137 raeburn 626: } elsif ($action eq 'usersessions') {
627: $output .= &print_usersessions('top',$dom,$settings,\$rowtotal);
1.122 jms 628: } elsif ($action eq 'rolecolors') {
1.30 raeburn 629: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.139 raeburn 630: } elsif ($action eq 'coursedefaults') {
631: $output .= &print_coursedefaults('top',$dom,$settings,\$rowtotal);
1.6 raeburn 632: }
1.30 raeburn 633: $output .= '
1.6 raeburn 634: </table>
635: </td>
636: </tr>
637: <tr>
638: <td>
639: <table class="LC_nested">
640: <tr class="LC_info_row">
1.59 bisitz 641: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57 raeburn 642: $output .= '
1.59 bisitz 643: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 644: </tr>';
645: $rowtotal ++;
1.6 raeburn 646: if ($action eq 'autoupdate') {
1.131 raeburn 647: $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
648: </table>
649: </td>
650: </tr>
651: <tr>
652: <td>
653: <table class="LC_nested">
654: <tr class="LC_info_row">
655: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
656: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
657: &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
658: $rowtotal ++;
1.28 raeburn 659: } elsif ($action eq 'usercreation') {
1.34 raeburn 660: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
661: </table>
662: </td>
663: </tr>
664: <tr>
665: <td>
666: <table class="LC_nested">
667: <tr class="LC_info_row">
1.59 bisitz 668: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
669: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.34 raeburn 670: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
671: $rowtotal ++;
1.33 raeburn 672: } elsif ($action eq 'usermodification') {
1.63 raeburn 673: $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
674: </table>
675: </td>
676: </tr>
677: <tr>
678: <td>
679: <table class="LC_nested">
680: <tr class="LC_info_row">
681: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 ! raeburn 682: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.63 raeburn 683: &print_usermodification('bottom',$dom,$settings,\$rowtotal);
684: $rowtotal ++;
1.57 raeburn 685: } elsif ($action eq 'coursecategories') {
686: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 687: } elsif ($action eq 'login') {
1.168 raeburn 688: if ($numheaders == 3) {
689: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
690: </table>
691: </td>
692: </tr>
693: <tr>
694: <td>
695: <table class="LC_nested">
696: <tr class="LC_info_row">
697: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 ! raeburn 698: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 699: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
700: $rowtotal ++;
701: } else {
702: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
703: }
1.102 raeburn 704: } elsif ($action eq 'requestcourses') {
1.216 ! raeburn 705: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal).
! 706: &print_studentcode($settings,\$rowtotal).'
! 707: </table>
! 708: </td>
! 709: </tr>
! 710: <tr>
! 711: <td>
! 712: <table class="LC_nested">
! 713: <tr class="LC_info_row">
! 714: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
! 715: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
! 716: &print_textbookcourses($dom,$settings,\$rowtotal);
1.163 raeburn 717: } elsif ($action eq 'requestauthor') {
718: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.137 raeburn 719: } elsif ($action eq 'usersessions') {
1.145 raeburn 720: $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
721: </table>
722: </td>
723: </tr>
724: <tr>
725: <td>
726: <table class="LC_nested">
727: <tr class="LC_info_row">
728: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
729: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
730: &print_usersessions('bottom',$dom,$settings,\$rowtotal);
731: $rowtotal ++;
1.139 raeburn 732: } elsif ($action eq 'coursedefaults') {
733: $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.122 jms 734: } elsif ($action eq 'rolecolors') {
1.30 raeburn 735: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 736: </table>
737: </td>
738: </tr>
739: <tr>
740: <td>
741: <table class="LC_nested">
742: <tr class="LC_info_row">
1.69 raeburn 743: <td class="LC_left_item"'.$colspan.' valign="top">'.
744: &mt($item->{'header'}->[2]->{'col1'}).'</td>
745: <td class="LC_right_item" valign="top">'.
746: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 747: </tr>'.
1.30 raeburn 748: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 749: </table>
750: </td>
751: </tr>
752: <tr>
753: <td>
754: <table class="LC_nested">
755: <tr class="LC_info_row">
1.59 bisitz 756: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
757: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 758: </tr>'.
1.30 raeburn 759: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
760: $rowtotal += 2;
1.6 raeburn 761: }
1.3 raeburn 762: } else {
1.30 raeburn 763: $output .= '
1.3 raeburn 764: <tr>
765: <td>
766: <table class="LC_nested">
1.30 raeburn 767: <tr class="LC_info_row">';
1.24 raeburn 768: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 769: $output .= '
1.59 bisitz 770: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 771: } elsif ($action eq 'serverstatuses') {
772: $output .= '
773: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
774: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
775:
1.6 raeburn 776: } else {
1.30 raeburn 777: $output .= '
1.69 raeburn 778: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
779: }
1.72 raeburn 780: if (defined($item->{'header'}->[0]->{'col3'})) {
781: $output .= '<td class="LC_left_item" valign="top">'.
782: &mt($item->{'header'}->[0]->{'col2'});
783: if ($action eq 'serverstatuses') {
784: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
785: }
1.69 raeburn 786: } else {
787: $output .= '<td class="LC_right_item" valign="top">'.
788: &mt($item->{'header'}->[0]->{'col2'});
789: }
790: $output .= '</td>';
791: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 792: if (defined($item->{'header'}->[0]->{'col4'})) {
793: $output .= '<td class="LC_left_item" valign="top">'.
794: &mt($item->{'header'}->[0]->{'col3'});
795: } else {
796: $output .= '<td class="LC_right_item" valign="top">'.
797: &mt($item->{'header'}->[0]->{'col3'});
798: }
1.69 raeburn 799: if ($action eq 'serverstatuses') {
800: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
801: }
802: $output .= '</td>';
1.6 raeburn 803: }
1.150 raeburn 804: if ($item->{'header'}->[0]->{'col4'}) {
805: $output .= '<td class="LC_right_item" valign="top">'.
806: &mt($item->{'header'}->[0]->{'col4'});
807: }
1.69 raeburn 808: $output .= '</tr>';
1.48 raeburn 809: $rowtotal ++;
1.168 raeburn 810: if ($action eq 'quotas') {
1.86 raeburn 811: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3 raeburn 812: } elsif ($action eq 'autoenroll') {
1.30 raeburn 813: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125 raeburn 814: } elsif ($action eq 'autocreate') {
815: $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23 raeburn 816: } elsif ($action eq 'directorysrch') {
1.30 raeburn 817: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 818: } elsif ($action eq 'contacts') {
1.30 raeburn 819: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 raeburn 820: } elsif ($action eq 'defaults') {
1.212 raeburn 821: $output .= &print_defaults($dom,$settings,\$rowtotal);
1.46 raeburn 822: } elsif ($action eq 'scantron') {
823: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69 raeburn 824: } elsif ($action eq 'serverstatuses') {
825: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118 jms 826: } elsif ($action eq 'helpsettings') {
1.168 raeburn 827: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.150 raeburn 828: } elsif ($action eq 'loadbalancing') {
829: $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.121 raeburn 830: }
1.3 raeburn 831: }
1.30 raeburn 832: $output .= '
1.3 raeburn 833: </table>
834: </td>
835: </tr>
1.30 raeburn 836: </table><br />';
837: return ($output,$rowtotal);
1.1 raeburn 838: }
839:
1.3 raeburn 840: sub print_login {
1.168 raeburn 841: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 842: my ($css_class,$datatable);
1.6 raeburn 843: my %choices = &login_choices();
1.110 raeburn 844:
1.168 raeburn 845: if ($caller eq 'service') {
1.149 raeburn 846: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 847: my $choice = $choices{'disallowlogin'};
848: $css_class = ' class="LC_odd_row"';
1.128 raeburn 849: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 850: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 851: '<th>'.$choices{'server'}.'</th>'.
852: '<th>'.$choices{'serverpath'}.'</th>'.
853: '<th>'.$choices{'custompath'}.'</th>'.
854: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 855: my %disallowed;
856: if (ref($settings) eq 'HASH') {
857: if (ref($settings->{'loginvia'}) eq 'HASH') {
858: %disallowed = %{$settings->{'loginvia'}};
859: }
860: }
861: foreach my $lonhost (sort(keys(%servers))) {
862: my $direct = 'selected="selected"';
1.128 raeburn 863: if (ref($disallowed{$lonhost}) eq 'HASH') {
864: if ($disallowed{$lonhost}{'server'} ne '') {
865: $direct = '';
866: }
1.110 raeburn 867: }
1.115 raeburn 868: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 869: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 870: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
871: '</option>';
1.184 raeburn 872: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 873: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 874: my $selected = '';
1.128 raeburn 875: if (ref($disallowed{$lonhost}) eq 'HASH') {
876: if ($hostid eq $disallowed{$lonhost}{'server'}) {
877: $selected = 'selected="selected"';
878: }
1.110 raeburn 879: }
880: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
881: $servers{$hostid}.'</option>';
882: }
1.128 raeburn 883: $datatable .= '</select></td>'.
884: '<td><select name="'.$lonhost.'_serverpath">';
885: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
886: my $pathname = $path;
887: if ($path eq 'custom') {
888: $pathname = &mt('Custom Path').' ->';
889: }
890: my $selected = '';
891: if (ref($disallowed{$lonhost}) eq 'HASH') {
892: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
893: $selected = 'selected="selected"';
894: }
895: } elsif ($path eq '') {
896: $selected = 'selected="selected"';
897: }
898: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
899: }
900: $datatable .= '</select></td>';
901: my ($custom,$exempt);
902: if (ref($disallowed{$lonhost}) eq 'HASH') {
903: $custom = $disallowed{$lonhost}{'custompath'};
904: $exempt = $disallowed{$lonhost}{'exempt'};
905: }
906: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
907: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
908: '</tr>';
1.110 raeburn 909: }
910: $datatable .= '</table></td></tr>';
911: return $datatable;
1.168 raeburn 912: } elsif ($caller eq 'page') {
913: my %defaultchecked = (
914: 'coursecatalog' => 'on',
1.188 raeburn 915: 'helpdesk' => 'on',
1.168 raeburn 916: 'adminmail' => 'off',
917: 'newuser' => 'off',
918: );
1.188 raeburn 919: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 920: my (%checkedon,%checkedoff);
1.42 raeburn 921: foreach my $item (@toggles) {
1.168 raeburn 922: if ($defaultchecked{$item} eq 'on') {
923: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 924: $checkedoff{$item} = ' ';
1.168 raeburn 925: } elsif ($defaultchecked{$item} eq 'off') {
926: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 927: $checkedon{$item} = ' ';
928: }
1.1 raeburn 929: }
1.168 raeburn 930: my @images = ('img','logo','domlogo','login');
931: my @logintext = ('textcol','bgcol');
932: my @bgs = ('pgbg','mainbg','sidebg');
933: my @links = ('link','alink','vlink');
934: my %designhash = &Apache::loncommon::get_domainconf($dom);
935: my %defaultdesign = %Apache::loncommon::defaultdesign;
936: my (%is_custom,%designs);
937: my %defaults = (
938: font => $defaultdesign{'login.font'},
939: );
1.6 raeburn 940: foreach my $item (@images) {
1.168 raeburn 941: $defaults{$item} = $defaultdesign{'login.'.$item};
942: $defaults{'showlogo'}{$item} = 1;
943: }
944: foreach my $item (@bgs) {
945: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 946: }
1.41 raeburn 947: foreach my $item (@logintext) {
1.168 raeburn 948: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 949: }
1.168 raeburn 950: foreach my $item (@links) {
951: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 952: }
1.168 raeburn 953: if (ref($settings) eq 'HASH') {
954: foreach my $item (@toggles) {
955: if ($settings->{$item} eq '1') {
956: $checkedon{$item} = ' checked="checked" ';
957: $checkedoff{$item} = ' ';
958: } elsif ($settings->{$item} eq '0') {
959: $checkedoff{$item} = ' checked="checked" ';
960: $checkedon{$item} = ' ';
961: }
962: }
963: foreach my $item (@images) {
964: if (defined($settings->{$item})) {
965: $designs{$item} = $settings->{$item};
966: $is_custom{$item} = 1;
967: }
968: if (defined($settings->{'showlogo'}{$item})) {
969: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
970: }
971: }
972: foreach my $item (@logintext) {
973: if ($settings->{$item} ne '') {
974: $designs{'logintext'}{$item} = $settings->{$item};
975: $is_custom{$item} = 1;
976: }
977: }
978: if ($settings->{'font'} ne '') {
979: $designs{'font'} = $settings->{'font'};
980: $is_custom{'font'} = 1;
981: }
982: foreach my $item (@bgs) {
983: if ($settings->{$item} ne '') {
984: $designs{'bgs'}{$item} = $settings->{$item};
985: $is_custom{$item} = 1;
986: }
987: }
988: foreach my $item (@links) {
989: if ($settings->{$item} ne '') {
990: $designs{'links'}{$item} = $settings->{$item};
991: $is_custom{$item} = 1;
992: }
993: }
994: } else {
995: if ($designhash{$dom.'.login.font'} ne '') {
996: $designs{'font'} = $designhash{$dom.'.login.font'};
997: $is_custom{'font'} = 1;
998: }
999: foreach my $item (@images) {
1000: if ($designhash{$dom.'.login.'.$item} ne '') {
1001: $designs{$item} = $designhash{$dom.'.login.'.$item};
1002: $is_custom{$item} = 1;
1003: }
1004: }
1005: foreach my $item (@bgs) {
1006: if ($designhash{$dom.'.login.'.$item} ne '') {
1007: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1008: $is_custom{$item} = 1;
1009: }
1.6 raeburn 1010: }
1.168 raeburn 1011: foreach my $item (@links) {
1012: if ($designhash{$dom.'.login.'.$item} ne '') {
1013: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1014: $is_custom{$item} = 1;
1015: }
1.6 raeburn 1016: }
1017: }
1.168 raeburn 1018: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1019: logo => 'Institution Logo',
1020: domlogo => 'Domain Logo',
1021: login => 'Login box');
1022: my $itemcount = 1;
1023: foreach my $item (@toggles) {
1024: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1025: $datatable .=
1026: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1027: '</td><td>'.
1028: '<span class="LC_nobreak"><label><input type="radio" name="'.
1029: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1030: '</label> <label><input type="radio" name="'.$item.'"'.
1031: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1032: '</tr>';
1033: $itemcount ++;
1.6 raeburn 1034: }
1.168 raeburn 1035: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1036: $datatable .= '</tr></table></td></tr>';
1037: } elsif ($caller eq 'help') {
1038: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1039: my $switchserver = &check_switchserver($dom,$confname);
1040: my $itemcount = 1;
1041: $defaulturl = '/adm/loginproblems.html';
1042: $defaulttype = 'default';
1043: %lt = &Apache::lonlocal::texthash (
1044: del => 'Delete?',
1045: rep => 'Replace:',
1046: upl => 'Upload:',
1047: default => 'Default',
1048: custom => 'Custom',
1049: );
1050: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1051: my @currlangs;
1052: if (ref($settings) eq 'HASH') {
1053: if (ref($settings->{'helpurl'}) eq 'HASH') {
1054: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1055: next if ($settings->{'helpurl'}{$key} eq '');
1056: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1057: $type{$key} = 'custom';
1058: unless ($key eq 'nolang') {
1059: push(@currlangs,$key);
1060: }
1061: }
1062: } elsif ($settings->{'helpurl'} ne '') {
1063: $type{'nolang'} = 'custom';
1064: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1065: }
1066: }
1.168 raeburn 1067: foreach my $lang ('nolang',sort(@currlangs)) {
1068: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1069: $datatable .= '<tr'.$css_class.'>';
1070: if ($url{$lang} eq '') {
1071: $url{$lang} = $defaulturl;
1072: }
1073: if ($type{$lang} eq '') {
1074: $type{$lang} = $defaulttype;
1075: }
1076: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1077: if ($lang eq 'nolang') {
1078: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1079: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1080: } else {
1081: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1082: $langchoices{$lang},
1083: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1084: }
1085: $datatable .= '</span></td>'."\n".
1086: '<td class="LC_left_item">';
1087: if ($type{$lang} eq 'custom') {
1088: $datatable .= '<span class="LC_nobreak"><label>'.
1089: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1090: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1091: } else {
1092: $datatable .= $lt{'upl'};
1093: }
1094: $datatable .='<br />';
1095: if ($switchserver) {
1096: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1097: } else {
1098: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1099: }
1.168 raeburn 1100: $datatable .= '</td></tr>';
1101: $itemcount ++;
1.6 raeburn 1102: }
1.168 raeburn 1103: my @addlangs;
1104: foreach my $lang (sort(keys(%langchoices))) {
1105: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1106: push(@addlangs,$lang);
1107: }
1108: if (@addlangs > 0) {
1109: my %toadd;
1110: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1111: $toadd{''} = &mt('Select');
1112: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1113: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1114: &mt('Add log-in help page for a specific language:').' '.
1115: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1116: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1117: if ($switchserver) {
1118: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1119: } else {
1120: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1121: }
1.168 raeburn 1122: $datatable .= '</td></tr>';
1.169 raeburn 1123: $itemcount ++;
1.6 raeburn 1124: }
1.169 raeburn 1125: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1 raeburn 1126: }
1.6 raeburn 1127: return $datatable;
1128: }
1129:
1130: sub login_choices {
1131: my %choices =
1132: &Apache::lonlocal::texthash (
1.116 bisitz 1133: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1134: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1135: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1136: disallowlogin => "Login page requests redirected",
1137: hostid => "Server",
1.128 raeburn 1138: server => "Redirect to:",
1139: serverpath => "Path",
1140: custompath => "Custom",
1141: exempt => "Exempt IP(s)",
1.110 raeburn 1142: directlogin => "No redirect",
1143: newuser => "Link to create a user account",
1144: img => "Header",
1145: logo => "Main Logo",
1146: domlogo => "Domain Logo",
1147: login => "Log-in Header",
1148: textcol => "Text color",
1149: bgcol => "Box color",
1150: bgs => "Background colors",
1151: links => "Link colors",
1152: font => "Font color",
1153: pgbg => "Header",
1154: mainbg => "Page",
1155: sidebg => "Login box",
1156: link => "Link",
1157: alink => "Active link",
1158: vlink => "Visited link",
1.6 raeburn 1159: );
1160: return %choices;
1161: }
1162:
1163: sub print_rolecolors {
1.30 raeburn 1164: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1165: my %choices = &color_font_choices();
1166: my @bgs = ('pgbg','tabbg','sidebg');
1167: my @links = ('link','alink','vlink');
1168: my @images = ('img');
1169: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1170: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1171: my %defaultdesign = %Apache::loncommon::defaultdesign;
1172: my (%is_custom,%designs);
1.200 raeburn 1173: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1174: if (ref($settings) eq 'HASH') {
1175: if (ref($settings->{$role}) eq 'HASH') {
1176: if ($settings->{$role}->{'img'} ne '') {
1177: $designs{'img'} = $settings->{$role}->{'img'};
1178: $is_custom{'img'} = 1;
1179: }
1180: if ($settings->{$role}->{'font'} ne '') {
1181: $designs{'font'} = $settings->{$role}->{'font'};
1182: $is_custom{'font'} = 1;
1183: }
1.97 tempelho 1184: if ($settings->{$role}->{'fontmenu'} ne '') {
1185: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1186: $is_custom{'fontmenu'} = 1;
1187: }
1.6 raeburn 1188: foreach my $item (@bgs) {
1189: if ($settings->{$role}->{$item} ne '') {
1190: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1191: $is_custom{$item} = 1;
1192: }
1193: }
1194: foreach my $item (@links) {
1195: if ($settings->{$role}->{$item} ne '') {
1196: $designs{'links'}{$item} = $settings->{$role}->{$item};
1197: $is_custom{$item} = 1;
1198: }
1199: }
1200: }
1201: } else {
1202: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1203: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1204: $is_custom{'img'} = 1;
1205: }
1.97 tempelho 1206: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1207: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1208: $is_custom{'fontmenu'} = 1;
1209: }
1.6 raeburn 1210: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1211: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1212: $is_custom{'font'} = 1;
1213: }
1214: foreach my $item (@bgs) {
1215: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1216: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1217: $is_custom{$item} = 1;
1218:
1219: }
1220: }
1221: foreach my $item (@links) {
1222: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1223: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1224: $is_custom{$item} = 1;
1225: }
1226: }
1227: }
1228: my $itemcount = 1;
1.30 raeburn 1229: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1230: $datatable .= '</tr></table></td></tr>';
1231: return $datatable;
1232: }
1233:
1.200 raeburn 1234: sub role_defaults {
1235: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1236: my %defaults;
1237: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1238: return %defaults;
1239: }
1240: my %defaultdesign = %Apache::loncommon::defaultdesign;
1241: if ($role eq 'login') {
1242: %defaults = (
1243: font => $defaultdesign{$role.'.font'},
1244: );
1245: if (ref($logintext) eq 'ARRAY') {
1246: foreach my $item (@{$logintext}) {
1247: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1248: }
1249: }
1250: foreach my $item (@{$images}) {
1251: $defaults{'showlogo'}{$item} = 1;
1252: }
1253: } else {
1254: %defaults = (
1255: img => $defaultdesign{$role.'.img'},
1256: font => $defaultdesign{$role.'.font'},
1257: fontmenu => $defaultdesign{$role.'.fontmenu'},
1258: );
1259: }
1260: foreach my $item (@{$bgs}) {
1261: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1262: }
1263: foreach my $item (@{$links}) {
1264: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1265: }
1266: foreach my $item (@{$images}) {
1267: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1268: }
1269: return %defaults;
1270: }
1271:
1.6 raeburn 1272: sub display_color_options {
1.9 raeburn 1273: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1274: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1275: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1276: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1277: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1278: '<td>'.$choices->{'font'}.'</td>';
1279: if (!$is_custom->{'font'}) {
1.30 raeburn 1280: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1281: } else {
1282: $datatable .= '<td> </td>';
1283: }
1.174 foxr 1284: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1285:
1.8 raeburn 1286: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1287: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1288: ' value="'.$current_color.'" /> '.
1.174 foxr 1289: ' </td></tr>';
1.107 raeburn 1290: unless ($role eq 'login') {
1291: $datatable .= '<tr'.$css_class.'>'.
1292: '<td>'.$choices->{'fontmenu'}.'</td>';
1293: if (!$is_custom->{'fontmenu'}) {
1294: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1295: } else {
1296: $datatable .= '<td> </td>';
1297: }
1.202 raeburn 1298: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1299: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1300: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1301: '<input class="colorchooser" type="text" size="10" name="'
1302: .$role.'_fontmenu"'.
1303: ' value="'.$current_color.'" /> '.
1304: ' </td></tr>';
1.97 tempelho 1305: }
1.9 raeburn 1306: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1307: foreach my $img (@{$images}) {
1.18 albertel 1308: $itemcount ++;
1.6 raeburn 1309: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1310: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1311: '<td>'.$choices->{$img};
1.41 raeburn 1312: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1313: if ($role eq 'login') {
1314: if ($img eq 'login') {
1315: $login_hdr_pick =
1.135 bisitz 1316: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1317: $logincolors =
1318: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1319: $designs,$defaults);
1.70 raeburn 1320: } elsif ($img ne 'domlogo') {
1321: $datatable.= &logo_display_options($img,$defaults,$designs);
1322: }
1323: }
1324: $datatable .= '</td>';
1.6 raeburn 1325: if ($designs->{$img} ne '') {
1326: $imgfile = $designs->{$img};
1.18 albertel 1327: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1328: } else {
1329: $imgfile = $defaults->{$img};
1330: }
1331: if ($imgfile) {
1.9 raeburn 1332: my ($showfile,$fullsize);
1333: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1334: my $urldir = $1;
1335: my $filename = $2;
1336: my @info = &Apache::lonnet::stat_file($designs->{$img});
1337: if (@info) {
1338: my $thumbfile = 'tn-'.$filename;
1339: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1340: if (@thumb) {
1341: $showfile = $urldir.'/'.$thumbfile;
1342: } else {
1343: $showfile = $imgfile;
1344: }
1345: } else {
1346: $showfile = '';
1347: }
1348: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1349: $showfile = $imgfile;
1.6 raeburn 1350: my $imgdir = $1;
1351: my $filename = $2;
1.159 raeburn 1352: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1353: $showfile = "/$imgdir/tn-".$filename;
1354: } else {
1.159 raeburn 1355: my $input = $londocroot.$imgfile;
1356: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1357: if (!-e $output) {
1.9 raeburn 1358: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1359: my ($fullwidth,$fullheight) = &check_dimensions($input);
1360: if ($fullwidth ne '' && $fullheight ne '') {
1361: if ($fullwidth > $width && $fullheight > $height) {
1362: my $size = $width.'x'.$height;
1363: system("convert -sample $size $input $output");
1.159 raeburn 1364: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1365: }
1366: }
1.6 raeburn 1367: }
1368: }
1.16 raeburn 1369: }
1.6 raeburn 1370: if ($showfile) {
1.40 raeburn 1371: if ($showfile =~ m{^/(adm|res)/}) {
1372: if ($showfile =~ m{^/res/}) {
1373: my $local_showfile =
1374: &Apache::lonnet::filelocation('',$showfile);
1375: &Apache::lonnet::repcopy($local_showfile);
1376: }
1377: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1378: }
1379: if ($imgfile) {
1380: if ($imgfile =~ m{^/(adm|res)/}) {
1381: if ($imgfile =~ m{^/res/}) {
1382: my $local_imgfile =
1383: &Apache::lonnet::filelocation('',$imgfile);
1384: &Apache::lonnet::repcopy($local_imgfile);
1385: }
1386: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1387: } else {
1388: $fullsize = $imgfile;
1389: }
1390: }
1.41 raeburn 1391: $datatable .= '<td>';
1392: if ($img eq 'login') {
1.135 bisitz 1393: $datatable .= $login_hdr_pick;
1394: }
1.41 raeburn 1395: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1396: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1397: } else {
1.201 raeburn 1398: $datatable .= '<td> </td><td class="LC_left_item">'.
1399: &mt('Upload:').'<br />';
1.6 raeburn 1400: }
1401: } else {
1.201 raeburn 1402: $datatable .= '<td> </td><td class="LC_left_item">'.
1403: &mt('Upload:').'<br />';
1.6 raeburn 1404: }
1.9 raeburn 1405: if ($switchserver) {
1406: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1407: } else {
1.135 bisitz 1408: if ($img ne 'login') { # suppress file selection for Log-in header
1409: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1410: }
1.9 raeburn 1411: }
1412: $datatable .= '</td></tr>';
1.6 raeburn 1413: }
1414: $itemcount ++;
1415: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1416: $datatable .= '<tr'.$css_class.'>'.
1417: '<td>'.$choices->{'bgs'}.'</td>';
1418: my $bgs_def;
1419: foreach my $item (@{$bgs}) {
1420: if (!$is_custom->{$item}) {
1.70 raeburn 1421: $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 1422: }
1423: }
1424: if ($bgs_def) {
1.8 raeburn 1425: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1426: } else {
1427: $datatable .= '<td> </td>';
1428: }
1429: $datatable .= '<td class="LC_right_item">'.
1430: '<table border="0"><tr>';
1.174 foxr 1431:
1.6 raeburn 1432: foreach my $item (@{$bgs}) {
1.201 raeburn 1433: $datatable .= '<td align="center">'.$choices->{$item};
1.174 foxr 1434: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1435: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1436: $datatable .= ' ';
1.6 raeburn 1437: }
1.174 foxr 1438: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1439: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1440: }
1441: $datatable .= '</tr></table></td></tr>';
1442: $itemcount ++;
1443: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1444: $datatable .= '<tr'.$css_class.'>'.
1445: '<td>'.$choices->{'links'}.'</td>';
1446: my $links_def;
1447: foreach my $item (@{$links}) {
1448: if (!$is_custom->{$item}) {
1.30 raeburn 1449: $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 1450: }
1451: }
1452: if ($links_def) {
1.8 raeburn 1453: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1454: } else {
1455: $datatable .= '<td> </td>';
1456: }
1457: $datatable .= '<td class="LC_right_item">'.
1458: '<table border="0"><tr>';
1459: foreach my $item (@{$links}) {
1.174 foxr 1460: my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
1.201 raeburn 1461: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1462: if ($designs->{'links'}{$item}) {
1.174 foxr 1463: $datatable.=' ';
1.6 raeburn 1464: }
1.174 foxr 1465: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1466: '" /></td>';
1467: }
1.30 raeburn 1468: $$rowtotal += $itemcount;
1.3 raeburn 1469: return $datatable;
1470: }
1471:
1.70 raeburn 1472: sub logo_display_options {
1473: my ($img,$defaults,$designs) = @_;
1474: my $checkedon;
1475: if (ref($defaults) eq 'HASH') {
1476: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1477: if ($defaults->{'showlogo'}{$img}) {
1478: $checkedon = 'checked="checked" ';
1479: }
1480: }
1481: }
1482: if (ref($designs) eq 'HASH') {
1483: if (ref($designs->{'showlogo'}) eq 'HASH') {
1484: if (defined($designs->{'showlogo'}{$img})) {
1485: if ($designs->{'showlogo'}{$img} == 0) {
1486: $checkedon = '';
1487: } elsif ($designs->{'showlogo'}{$img} == 1) {
1488: $checkedon = 'checked="checked" ';
1489: }
1490: }
1491: }
1492: }
1493: return '<br /><label> <input type="checkbox" name="'.
1494: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1495: &mt('show').'</label>'."\n";
1496: }
1497:
1.41 raeburn 1498: sub login_header_options {
1.135 bisitz 1499: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1500: my $output = '';
1.41 raeburn 1501: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1502: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1503: if (!$is_custom->{'textcol'}) {
1504: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1505: ' ';
1506: }
1507: if (!$is_custom->{'bgcol'}) {
1508: $output .= $choices->{'bgcol'}.': '.
1509: '<span id="css_'.$role.'_font" style="background-color: '.
1510: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1511: }
1512: $output .= '<br />';
1513: }
1514: $output .='<br />';
1515: return $output;
1516: }
1517:
1518: sub login_text_colors {
1.201 raeburn 1519: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1520: my $color_menu = '<table border="0"><tr>';
1521: foreach my $item (@{$logintext}) {
1.201 raeburn 1522: $color_menu .= '<td align="center">'.$choices->{$item};
1523: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1524: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1525: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1526: }
1527: $color_menu .= '</tr></table><br />';
1528: return $color_menu;
1529: }
1530:
1531: sub image_changes {
1532: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1533: my $output;
1.135 bisitz 1534: if ($img eq 'login') {
1535: # suppress image for Log-in header
1536: } elsif (!$is_custom) {
1.70 raeburn 1537: if ($img ne 'domlogo') {
1.41 raeburn 1538: $output .= &mt('Default image:').'<br />';
1539: } else {
1540: $output .= &mt('Default in use:').'<br />';
1541: }
1542: }
1.135 bisitz 1543: if ($img eq 'login') { # suppress image for Log-in header
1544: $output .= '<td>'.$logincolors;
1.41 raeburn 1545: } else {
1.135 bisitz 1546: if ($img_import) {
1547: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1548: }
1549: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1550: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1551: if ($is_custom) {
1552: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1553: '<input type="checkbox" name="'.
1554: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1555: '</label> '.&mt('Replace:').'</span><br />';
1556: } else {
1.201 raeburn 1557: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1558: }
1.41 raeburn 1559: }
1560: return $output;
1561: }
1562:
1.3 raeburn 1563: sub print_quotas {
1.86 raeburn 1564: my ($dom,$settings,$rowtotal,$action) = @_;
1565: my $context;
1566: if ($action eq 'quotas') {
1567: $context = 'tools';
1568: } else {
1569: $context = $action;
1570: }
1.197 raeburn 1571: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1572: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1573: my $typecount = 0;
1.101 raeburn 1574: my ($css_class,%titles);
1.86 raeburn 1575: if ($context eq 'requestcourses') {
1.216 ! raeburn 1576: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1577: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1578: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1579: %titles = &courserequest_titles();
1.163 raeburn 1580: } elsif ($context eq 'requestauthor') {
1581: @usertools = ('author');
1582: @options = ('norequest','approval','automatic');
1.210 raeburn 1583: %titles = &authorrequest_titles();
1.86 raeburn 1584: } else {
1.162 raeburn 1585: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1586: %titles = &tool_titles();
1.86 raeburn 1587: }
1.26 raeburn 1588: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1589: foreach my $type (@{$types}) {
1.197 raeburn 1590: my ($currdefquota,$currauthorquota);
1.163 raeburn 1591: unless (($context eq 'requestcourses') ||
1592: ($context eq 'requestauthor')) {
1.86 raeburn 1593: if (ref($settings) eq 'HASH') {
1594: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1595: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1596: } else {
1597: $currdefquota = $settings->{$type};
1598: }
1.197 raeburn 1599: if (ref($settings->{authorquota}) eq 'HASH') {
1600: $currauthorquota = $settings->{authorquota}->{$type};
1601: }
1.78 raeburn 1602: }
1.72 raeburn 1603: }
1.3 raeburn 1604: if (defined($usertypes->{$type})) {
1605: $typecount ++;
1606: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1607: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1608: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1609: '<td class="LC_left_item">';
1.101 raeburn 1610: if ($context eq 'requestcourses') {
1611: $datatable .= '<table><tr>';
1612: }
1613: my %cell;
1.72 raeburn 1614: foreach my $item (@usertools) {
1.101 raeburn 1615: if ($context eq 'requestcourses') {
1616: my ($curroption,$currlimit);
1617: if (ref($settings) eq 'HASH') {
1618: if (ref($settings->{$item}) eq 'HASH') {
1619: $curroption = $settings->{$item}->{$type};
1620: if ($curroption =~ /^autolimit=(\d*)$/) {
1621: $currlimit = $1;
1622: }
1623: }
1624: }
1625: if (!$curroption) {
1626: $curroption = 'norequest';
1627: }
1628: $datatable .= '<th>'.$titles{$item}.'</th>';
1629: foreach my $option (@options) {
1630: my $val = $option;
1631: if ($option eq 'norequest') {
1632: $val = 0;
1633: }
1634: if ($option eq 'validate') {
1635: my $canvalidate = 0;
1636: if (ref($validations{$item}) eq 'HASH') {
1637: if ($validations{$item}{$type}) {
1638: $canvalidate = 1;
1639: }
1640: }
1641: next if (!$canvalidate);
1642: }
1643: my $checked = '';
1644: if ($option eq $curroption) {
1645: $checked = ' checked="checked"';
1646: } elsif ($option eq 'autolimit') {
1647: if ($curroption =~ /^autolimit/) {
1648: $checked = ' checked="checked"';
1649: }
1650: }
1651: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1652: '<input type="radio" name="crsreq_'.$item.
1653: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1654: $titles{$option}.'</label>';
1.101 raeburn 1655: if ($option eq 'autolimit') {
1.127 raeburn 1656: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1657: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1658: 'value="'.$currlimit.'" />';
1.101 raeburn 1659: }
1.127 raeburn 1660: $cell{$item} .= '</span> ';
1.103 raeburn 1661: if ($option eq 'autolimit') {
1.127 raeburn 1662: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1663: }
1.101 raeburn 1664: }
1.163 raeburn 1665: } elsif ($context eq 'requestauthor') {
1666: my $curroption;
1667: if (ref($settings) eq 'HASH') {
1668: $curroption = $settings->{$type};
1669: }
1670: if (!$curroption) {
1671: $curroption = 'norequest';
1672: }
1673: foreach my $option (@options) {
1674: my $val = $option;
1675: if ($option eq 'norequest') {
1676: $val = 0;
1677: }
1678: my $checked = '';
1679: if ($option eq $curroption) {
1680: $checked = ' checked="checked"';
1681: }
1682: $datatable .= '<span class="LC_nobreak"><label>'.
1683: '<input type="radio" name="authorreq_'.$type.
1684: '" value="'.$val.'"'.$checked.' />'.
1685: $titles{$option}.'</label></span> ';
1686: }
1.101 raeburn 1687: } else {
1688: my $checked = 'checked="checked" ';
1689: if (ref($settings) eq 'HASH') {
1690: if (ref($settings->{$item}) eq 'HASH') {
1691: if ($settings->{$item}->{$type} == 0) {
1692: $checked = '';
1693: } elsif ($settings->{$item}->{$type} == 1) {
1694: $checked = 'checked="checked" ';
1695: }
1.78 raeburn 1696: }
1.72 raeburn 1697: }
1.101 raeburn 1698: $datatable .= '<span class="LC_nobreak"><label>'.
1699: '<input type="checkbox" name="'.$context.'_'.$item.
1700: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1701: '</label></span> ';
1.72 raeburn 1702: }
1.101 raeburn 1703: }
1704: if ($context eq 'requestcourses') {
1705: $datatable .= '</tr><tr>';
1706: foreach my $item (@usertools) {
1.106 raeburn 1707: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1708: }
1709: $datatable .= '</tr></table>';
1.72 raeburn 1710: }
1.86 raeburn 1711: $datatable .= '</td>';
1.163 raeburn 1712: unless (($context eq 'requestcourses') ||
1713: ($context eq 'requestauthor')) {
1.86 raeburn 1714: $datatable .=
1.197 raeburn 1715: '<td class="LC_right_item">'.
1716: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1717: '<input type="text" name="quota_'.$type.
1.72 raeburn 1718: '" value="'.$currdefquota.
1.197 raeburn 1719: '" size="5" /></span>'.(' ' x 2).
1720: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1721: '<input type="text" name="authorquota_'.$type.
1722: '" value="'.$currauthorquota.
1723: '" size="5" /></span></td>';
1.86 raeburn 1724: }
1725: $datatable .= '</tr>';
1.3 raeburn 1726: }
1727: }
1728: }
1.163 raeburn 1729: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1730: $defaultquota = '20';
1.197 raeburn 1731: $authorquota = '500';
1.86 raeburn 1732: if (ref($settings) eq 'HASH') {
1733: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1734: $defaultquota = $settings->{'defaultquota'}->{'default'};
1735: } elsif (defined($settings->{'default'})) {
1736: $defaultquota = $settings->{'default'};
1737: }
1.197 raeburn 1738: if (ref($settings->{'authorquota'}) eq 'HASH') {
1739: $authorquota = $settings->{'authorquota'}->{'default'};
1740: }
1.3 raeburn 1741: }
1742: }
1743: $typecount ++;
1744: $css_class = $typecount%2?' class="LC_odd_row"':'';
1745: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1746: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1747: '<td class="LC_left_item">';
1.101 raeburn 1748: if ($context eq 'requestcourses') {
1749: $datatable .= '<table><tr>';
1750: }
1751: my %defcell;
1.72 raeburn 1752: foreach my $item (@usertools) {
1.101 raeburn 1753: if ($context eq 'requestcourses') {
1754: my ($curroption,$currlimit);
1755: if (ref($settings) eq 'HASH') {
1756: if (ref($settings->{$item}) eq 'HASH') {
1757: $curroption = $settings->{$item}->{'default'};
1758: if ($curroption =~ /^autolimit=(\d*)$/) {
1759: $currlimit = $1;
1760: }
1761: }
1762: }
1763: if (!$curroption) {
1764: $curroption = 'norequest';
1765: }
1766: $datatable .= '<th>'.$titles{$item}.'</th>';
1767: foreach my $option (@options) {
1768: my $val = $option;
1769: if ($option eq 'norequest') {
1770: $val = 0;
1771: }
1772: if ($option eq 'validate') {
1773: my $canvalidate = 0;
1774: if (ref($validations{$item}) eq 'HASH') {
1775: if ($validations{$item}{'default'}) {
1776: $canvalidate = 1;
1777: }
1778: }
1779: next if (!$canvalidate);
1780: }
1781: my $checked = '';
1782: if ($option eq $curroption) {
1783: $checked = ' checked="checked"';
1784: } elsif ($option eq 'autolimit') {
1785: if ($curroption =~ /^autolimit/) {
1786: $checked = ' checked="checked"';
1787: }
1788: }
1789: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1790: '<input type="radio" name="crsreq_'.$item.
1791: '_default" value="'.$val.'"'.$checked.' />'.
1792: $titles{$option}.'</label>';
1793: if ($option eq 'autolimit') {
1.127 raeburn 1794: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1795: $item.'_limit_default" size="1" '.
1796: 'value="'.$currlimit.'" />';
1797: }
1.127 raeburn 1798: $defcell{$item} .= '</span> ';
1.104 raeburn 1799: if ($option eq 'autolimit') {
1.127 raeburn 1800: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1801: }
1.101 raeburn 1802: }
1.163 raeburn 1803: } elsif ($context eq 'requestauthor') {
1804: my $curroption;
1805: if (ref($settings) eq 'HASH') {
1.172 raeburn 1806: $curroption = $settings->{'default'};
1.163 raeburn 1807: }
1808: if (!$curroption) {
1809: $curroption = 'norequest';
1810: }
1811: foreach my $option (@options) {
1812: my $val = $option;
1813: if ($option eq 'norequest') {
1814: $val = 0;
1815: }
1816: my $checked = '';
1817: if ($option eq $curroption) {
1818: $checked = ' checked="checked"';
1819: }
1820: $datatable .= '<span class="LC_nobreak"><label>'.
1821: '<input type="radio" name="authorreq_default"'.
1822: ' value="'.$val.'"'.$checked.' />'.
1823: $titles{$option}.'</label></span> ';
1824: }
1.101 raeburn 1825: } else {
1826: my $checked = 'checked="checked" ';
1827: if (ref($settings) eq 'HASH') {
1828: if (ref($settings->{$item}) eq 'HASH') {
1829: if ($settings->{$item}->{'default'} == 0) {
1830: $checked = '';
1831: } elsif ($settings->{$item}->{'default'} == 1) {
1832: $checked = 'checked="checked" ';
1833: }
1.78 raeburn 1834: }
1.72 raeburn 1835: }
1.101 raeburn 1836: $datatable .= '<span class="LC_nobreak"><label>'.
1837: '<input type="checkbox" name="'.$context.'_'.$item.
1838: '" value="default" '.$checked.'/>'.$titles{$item}.
1839: '</label></span> ';
1840: }
1841: }
1842: if ($context eq 'requestcourses') {
1843: $datatable .= '</tr><tr>';
1844: foreach my $item (@usertools) {
1.106 raeburn 1845: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1846: }
1.101 raeburn 1847: $datatable .= '</tr></table>';
1.72 raeburn 1848: }
1.86 raeburn 1849: $datatable .= '</td>';
1.163 raeburn 1850: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 1851: $datatable .= '<td class="LC_right_item">'.
1852: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 1853: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 1854: $defaultquota.'" size="5" /></span>'.(' ' x2).
1855: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1856: '<input type="text" name="authorquota" value="'.
1857: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 1858: }
1859: $datatable .= '</tr>';
1.72 raeburn 1860: $typecount ++;
1861: $css_class = $typecount%2?' class="LC_odd_row"':'';
1862: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 1863: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 1864: if ($context eq 'requestcourses') {
1.109 raeburn 1865: $datatable .= &mt('(overrides affiliation, if set)').
1866: '</td>'.
1867: '<td class="LC_left_item">'.
1868: '<table><tr>';
1.101 raeburn 1869: } else {
1.109 raeburn 1870: $datatable .= &mt('(overrides affiliation, if checked)').
1871: '</td>'.
1872: '<td class="LC_left_item" colspan="2">'.
1873: '<br />';
1.101 raeburn 1874: }
1875: my %advcell;
1.72 raeburn 1876: foreach my $item (@usertools) {
1.101 raeburn 1877: if ($context eq 'requestcourses') {
1878: my ($curroption,$currlimit);
1879: if (ref($settings) eq 'HASH') {
1880: if (ref($settings->{$item}) eq 'HASH') {
1881: $curroption = $settings->{$item}->{'_LC_adv'};
1882: if ($curroption =~ /^autolimit=(\d*)$/) {
1883: $currlimit = $1;
1884: }
1885: }
1886: }
1887: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1888: my $checked = '';
1889: if ($curroption eq '') {
1890: $checked = ' checked="checked"';
1891: }
1892: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1893: '<input type="radio" name="crsreq_'.$item.
1894: '__LC_adv" value=""'.$checked.' />'.
1895: &mt('No override set').'</label></span> ';
1.101 raeburn 1896: foreach my $option (@options) {
1897: my $val = $option;
1898: if ($option eq 'norequest') {
1899: $val = 0;
1900: }
1901: if ($option eq 'validate') {
1902: my $canvalidate = 0;
1903: if (ref($validations{$item}) eq 'HASH') {
1904: if ($validations{$item}{'_LC_adv'}) {
1905: $canvalidate = 1;
1906: }
1907: }
1908: next if (!$canvalidate);
1909: }
1910: my $checked = '';
1.104 raeburn 1911: if ($val eq $curroption) {
1.101 raeburn 1912: $checked = ' checked="checked"';
1913: } elsif ($option eq 'autolimit') {
1914: if ($curroption =~ /^autolimit/) {
1915: $checked = ' checked="checked"';
1916: }
1917: }
1918: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1919: '<input type="radio" name="crsreq_'.$item.
1920: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1921: $titles{$option}.'</label>';
1922: if ($option eq 'autolimit') {
1.127 raeburn 1923: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1924: $item.'_limit__LC_adv" size="1" '.
1925: 'value="'.$currlimit.'" />';
1926: }
1.127 raeburn 1927: $advcell{$item} .= '</span> ';
1.104 raeburn 1928: if ($option eq 'autolimit') {
1.127 raeburn 1929: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1930: }
1.101 raeburn 1931: }
1.163 raeburn 1932: } elsif ($context eq 'requestauthor') {
1933: my $curroption;
1934: if (ref($settings) eq 'HASH') {
1935: $curroption = $settings->{'_LC_adv'};
1936: }
1937: my $checked = '';
1938: if ($curroption eq '') {
1939: $checked = ' checked="checked"';
1940: }
1941: $datatable .= '<span class="LC_nobreak"><label>'.
1942: '<input type="radio" name="authorreq__LC_adv"'.
1943: ' value=""'.$checked.' />'.
1944: &mt('No override set').'</label></span> ';
1945: foreach my $option (@options) {
1946: my $val = $option;
1947: if ($option eq 'norequest') {
1948: $val = 0;
1949: }
1950: my $checked = '';
1951: if ($val eq $curroption) {
1952: $checked = ' checked="checked"';
1953: }
1954: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 1955: '<input type="radio" name="authorreq__LC_adv"'.
1956: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 1957: $titles{$option}.'</label></span> ';
1958: }
1.101 raeburn 1959: } else {
1960: my $checked = 'checked="checked" ';
1961: if (ref($settings) eq 'HASH') {
1962: if (ref($settings->{$item}) eq 'HASH') {
1963: if ($settings->{$item}->{'_LC_adv'} == 0) {
1964: $checked = '';
1965: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1966: $checked = 'checked="checked" ';
1967: }
1.79 raeburn 1968: }
1.72 raeburn 1969: }
1.101 raeburn 1970: $datatable .= '<span class="LC_nobreak"><label>'.
1971: '<input type="checkbox" name="'.$context.'_'.$item.
1972: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1973: '</label></span> ';
1974: }
1975: }
1976: if ($context eq 'requestcourses') {
1977: $datatable .= '</tr><tr>';
1978: foreach my $item (@usertools) {
1.106 raeburn 1979: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1980: }
1.101 raeburn 1981: $datatable .= '</tr></table>';
1.72 raeburn 1982: }
1.98 raeburn 1983: $datatable .= '</td></tr>';
1.30 raeburn 1984: $$rowtotal += $typecount;
1.3 raeburn 1985: return $datatable;
1986: }
1987:
1.163 raeburn 1988: sub print_requestmail {
1989: my ($dom,$action,$settings,$rowtotal) = @_;
1.208 raeburn 1990: my ($now,$datatable,%currapp);
1.102 raeburn 1991: $now = time;
1992: if (ref($settings) eq 'HASH') {
1993: if (ref($settings->{'notify'}) eq 'HASH') {
1994: if ($settings->{'notify'}{'approval'} ne '') {
1.191 raeburn 1995: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 1996: }
1997: }
1998: }
1.191 raeburn 1999: my $numinrow = 2;
1.102 raeburn 2000: my $css_class = 'class="LC_odd_row"';
1.163 raeburn 2001: my $text;
2002: if ($action eq 'requestcourses') {
2003: $text = &mt('Receive notification of course requests requiring approval');
2004: } else {
2005: $text = &mt('Receive notification of authoring space requests requiring approval')
2006: }
2007: $datatable = '<tr '.$css_class.'>'.
2008: ' <td>'.$text.'</td>'.
1.102 raeburn 2009: ' <td class="LC_left_item">';
1.191 raeburn 2010: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
2011: 'reqapprovalnotify',%currapp);
2012: if ($numdc > 0) {
2013: $datatable .= $table;
1.102 raeburn 2014: } else {
2015: $datatable .= &mt('There are no active Domain Coordinators');
2016: }
2017: $datatable .='</td></tr>';
2018: $$rowtotal += $rows;
2019: return $datatable;
2020: }
2021:
1.216 ! raeburn 2022: sub print_studentcode {
! 2023: my ($settings,$rowtotal) = @_;
! 2024: my $rownum = 0;
! 2025: my %choices;
! 2026: $choices{'uniquecode'} = &mt('Generate unique six character code as course identifier?');
! 2027: my @toggles = ('uniquecode');
! 2028: my %defaultchecked = ('uniquecode' => 'off');
! 2029: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
! 2030: \%choices,$rownum);
! 2031: $$rowtotal += $rownum;
! 2032: return $reports;
! 2033: }
! 2034:
! 2035: sub print_textbookcourses {
! 2036: my ($dom,$settings,$rowtotal) = @_;
! 2037: my $rownum = 0;
! 2038: my $css_class;
! 2039: my $itemcount = 1;
! 2040: my $maxnum = 0;
! 2041: my $bookshash;
! 2042: if (ref($settings) eq 'HASH') {
! 2043: $bookshash = $settings->{'textbooks'};
! 2044: }
! 2045: my %ordered;
! 2046: if (ref($bookshash) eq 'HASH') {
! 2047: foreach my $item (keys(%{$bookshash})) {
! 2048: if (ref($bookshash->{$item}) eq 'HASH') {
! 2049: my $num = $bookshash->{$item}{'order'};
! 2050: $ordered{$num} = $item;
! 2051: }
! 2052: }
! 2053: }
! 2054: my $confname = $dom.'-domainconfig';
! 2055: my $switchserver = &check_switchserver($dom,$confname);
! 2056: my $maxnum = scalar(keys(%ordered));
! 2057: my $datatable;
! 2058: if (keys(%ordered)) {
! 2059: my @items = sort { $a <=> $b } keys(%ordered);
! 2060: for (my $i=0; $i<@items; $i++) {
! 2061: $css_class = $itemcount%2?' class="LC_odd_row"':'';
! 2062: my $key = $ordered{$items[$i]};
! 2063: my %coursehash=&Apache::lonnet::coursedescription($key);
! 2064: my $coursetitle = $coursehash{'description'};
! 2065: my ($subject,$title,$author,$image,$imgsrc,$cdom,$cnum);
! 2066: if (ref($bookshash->{$key}) eq 'HASH') {
! 2067: $subject = $bookshash->{$key}->{'subject'};
! 2068: $title = $bookshash->{$key}->{'title'};
! 2069: $author = $bookshash->{$key}->{'author'};
! 2070: $image = $bookshash->{$key}->{'image'};
! 2071: if ($image ne '') {
! 2072: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
! 2073: my $imagethumb = "$path/tn-".$imagefile;
! 2074: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
! 2075: }
! 2076: }
! 2077: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'','$key','$i'".');"';
! 2078: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
! 2079: .'<select name="'.$key.'"'.$chgstr.'>';
! 2080: for (my $k=0; $k<=$maxnum; $k++) {
! 2081: my $vpos = $k+1;
! 2082: my $selstr;
! 2083: if ($k == $i) {
! 2084: $selstr = ' selected="selected" ';
! 2085: }
! 2086: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
! 2087: }
! 2088: $datatable .= '</select>'.(' 'x2).
! 2089: '<label><input type="checkbox" name="book_del" value="'.$key.'" />'.
! 2090: &mt('Delete?').'</label></span></td>'.
! 2091: '<td colspan="2">'.
! 2092: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="book_subject_'.$i.'" value="'.$subject.'" /></span> '.
! 2093: (' 'x2).
! 2094: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="book_title_'.$i.'" value="'.$title.'" /></span> '.
! 2095: (' 'x2).
! 2096: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="book_author_'.$i.'" value="'.$author.'" /></span> '.
! 2097: (' 'x2).
! 2098: '<span class="LC_nobreak">'.&mt('Thumbnail:');
! 2099: if ($image) {
! 2100: $datatable .= '<span class="LC_nobreak">'.
! 2101: $imgsrc.
! 2102: '<label><input type="checkbox" name="book_image_del"'.
! 2103: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
! 2104: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
! 2105: }
! 2106: if ($switchserver) {
! 2107: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
! 2108: } else {
! 2109: $datatable .= '<input type="file" name="book_image_'.$i.'" value="" />';
! 2110: }
! 2111: $datatable .= '<input type="hidden" name="book_id_'.$i.'" value="'.$key.'" /></span> '.
! 2112: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
! 2113: $coursetitle.'</span></td></tr>'."\n";
! 2114: $itemcount ++;
! 2115: }
! 2116: }
! 2117: $css_class = $itemcount%2?' class="LC_odd_row"':'';
! 2118: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'','addbook_pos','$maxnum'".');"';
! 2119: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
! 2120: '<input type="hidden" name="book_maxnum" value="'.$maxnum.'" />'."\n".
! 2121: '<select name="addbook_pos"'.$chgstr.'>';
! 2122: for (my $k=0; $k<$maxnum+1; $k++) {
! 2123: my $vpos = $k+1;
! 2124: my $selstr;
! 2125: if ($k == $maxnum) {
! 2126: $selstr = ' selected="selected" ';
! 2127: }
! 2128: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
! 2129: }
! 2130: $datatable .= '</select> '."\n".
! 2131: '<input type="checkbox" name="addbook" value="1" />'.&mt('Add').'</td>'."\n".
! 2132: '<td colspan="2">'.
! 2133: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="addbook_subject" value="" /></span> '."\n".
! 2134: (' 'x2).
! 2135: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="addbook_title" value="" /></span> '."\n".
! 2136: (' 'x2).
! 2137: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="addbook_author" value="" /></span> '."\n".
! 2138: (' 'x2).
! 2139: '<span class="LC_nobreak">'.&mt('Image:').' ';
! 2140: if ($switchserver) {
! 2141: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
! 2142: } else {
! 2143: $datatable .= '<input type="file" name="addbook_image" value="" />';
! 2144: }
! 2145: $datatable .= '</span>'."\n".
! 2146: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
! 2147: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'addbook_cdom').
! 2148: '<input type="text" size="25" name="addbook_cnum" value="" />'.
! 2149: &Apache::loncommon::selectcourse_link
! 2150: ('display','addbook_cnum','addbook_cdom',undef,undef,undef,'Course');
! 2151: '</span></td>'."\n".
! 2152: '</tr>'."\n";
! 2153: $itemcount ++;
! 2154: return $datatable;
! 2155: }
! 2156:
1.3 raeburn 2157: sub print_autoenroll {
1.30 raeburn 2158: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2159: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 2160: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 2161: if (ref($settings) eq 'HASH') {
2162: if (exists($settings->{'run'})) {
2163: if ($settings->{'run'} eq '0') {
2164: $runoff = ' checked="checked" ';
2165: $runon = ' ';
2166: } else {
2167: $runon = ' checked="checked" ';
2168: $runoff = ' ';
2169: }
2170: } else {
2171: if ($autorun) {
2172: $runon = ' checked="checked" ';
2173: $runoff = ' ';
2174: } else {
2175: $runoff = ' checked="checked" ';
2176: $runon = ' ';
2177: }
2178: }
1.129 raeburn 2179: if (exists($settings->{'co-owners'})) {
2180: if ($settings->{'co-owners'} eq '0') {
2181: $coownersoff = ' checked="checked" ';
2182: $coownerson = ' ';
2183: } else {
2184: $coownerson = ' checked="checked" ';
2185: $coownersoff = ' ';
2186: }
2187: } else {
2188: $coownersoff = ' checked="checked" ';
2189: $coownerson = ' ';
2190: }
1.3 raeburn 2191: if (exists($settings->{'sender_domain'})) {
2192: $defdom = $settings->{'sender_domain'};
2193: }
1.14 raeburn 2194: } else {
2195: if ($autorun) {
2196: $runon = ' checked="checked" ';
2197: $runoff = ' ';
2198: } else {
2199: $runoff = ' checked="checked" ';
2200: $runon = ' ';
2201: }
1.3 raeburn 2202: }
2203: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2204: my $notif_sender;
2205: if (ref($settings) eq 'HASH') {
2206: $notif_sender = $settings->{'sender_uname'};
2207: }
1.3 raeburn 2208: my $datatable='<tr class="LC_odd_row">'.
2209: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2210: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2211: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2212: $runon.' value="1" />'.&mt('Yes').'</label> '.
2213: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2214: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2215: '</tr><tr>'.
2216: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2217: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2218: &mt('username').': '.
2219: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2220: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2221: ': '.$domform.'</span></td></tr>'.
2222: '<tr class="LC_odd_row">'.
2223: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2224: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2225: '<input type="radio" name="autoassign_coowners"'.
2226: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2227: '<label><input type="radio" name="autoassign_coowners"'.
2228: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2229: '</tr>';
2230: $$rowtotal += 3;
1.3 raeburn 2231: return $datatable;
2232: }
2233:
2234: sub print_autoupdate {
1.30 raeburn 2235: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2236: my $datatable;
2237: if ($position eq 'top') {
2238: my $updateon = ' ';
2239: my $updateoff = ' checked="checked" ';
2240: my $classlistson = ' ';
2241: my $classlistsoff = ' checked="checked" ';
2242: if (ref($settings) eq 'HASH') {
2243: if ($settings->{'run'} eq '1') {
2244: $updateon = $updateoff;
2245: $updateoff = ' ';
2246: }
2247: if ($settings->{'classlists'} eq '1') {
2248: $classlistson = $classlistsoff;
2249: $classlistsoff = ' ';
2250: }
2251: }
2252: my %title = (
2253: run => 'Auto-update active?',
2254: classlists => 'Update information in classlists?',
2255: );
2256: $datatable = '<tr class="LC_odd_row">'.
2257: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2258: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2259: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2260: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2261: '<label><input type="radio" name="autoupdate_run"'.
2262: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2263: '</tr><tr>'.
2264: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2265: '<td class="LC_right_item"><span class="LC_nobreak">'.
2266: '<label><input type="radio" name="classlists"'.
2267: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2268: '<label><input type="radio" name="classlists"'.
2269: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2270: '</tr>';
1.30 raeburn 2271: $$rowtotal += 2;
1.131 raeburn 2272: } elsif ($position eq 'middle') {
2273: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2274: my $numinrow = 3;
2275: my $locknamesettings;
2276: $datatable .= &insttypes_row($settings,$types,$usertypes,
2277: $dom,$numinrow,$othertitle,
2278: 'lockablenames');
2279: $$rowtotal ++;
1.3 raeburn 2280: } else {
1.44 raeburn 2281: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2282: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2283: 'permanentemail','id');
1.33 raeburn 2284: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2285: my $numrows = 0;
1.26 raeburn 2286: if (ref($types) eq 'ARRAY') {
2287: if (@{$types} > 0) {
2288: $datatable =
2289: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2290: \@fields,$types,\$numrows);
1.30 raeburn 2291: $$rowtotal += @{$types};
1.26 raeburn 2292: }
1.3 raeburn 2293: }
2294: $datatable .=
2295: &usertype_update_row($settings,{'default' => $othertitle},
2296: \%fieldtitles,\@fields,['default'],
2297: \$numrows);
1.30 raeburn 2298: $$rowtotal ++;
1.3 raeburn 2299: }
2300: return $datatable;
2301: }
2302:
1.125 raeburn 2303: sub print_autocreate {
2304: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 2305: my (%createon,%createoff,%currhash);
1.125 raeburn 2306: my @types = ('xml','req');
2307: if (ref($settings) eq 'HASH') {
2308: foreach my $item (@types) {
2309: $createoff{$item} = ' checked="checked" ';
2310: $createon{$item} = ' ';
2311: if (exists($settings->{$item})) {
2312: if ($settings->{$item}) {
2313: $createon{$item} = ' checked="checked" ';
2314: $createoff{$item} = ' ';
2315: }
2316: }
2317: }
1.210 raeburn 2318: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 2319: $currhash{$settings->{'xmldc'}} = 1;
2320: }
1.125 raeburn 2321: } else {
2322: foreach my $item (@types) {
2323: $createoff{$item} = ' checked="checked" ';
2324: $createon{$item} = ' ';
2325: }
2326: }
2327: $$rowtotal += 2;
1.191 raeburn 2328: my $numinrow = 2;
1.125 raeburn 2329: my $datatable='<tr class="LC_odd_row">'.
2330: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2331: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2332: '<input type="radio" name="autocreate_xml"'.
2333: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2334: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2335: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2336: '</td></tr><tr>'.
2337: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2338: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2339: '<input type="radio" name="autocreate_req"'.
2340: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2341: '<label><input type="radio" name="autocreate_req"'.
2342: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 2343: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2344: 'autocreate_xmldc',%currhash);
1.125 raeburn 2345: if ($numdc > 1) {
1.143 raeburn 2346: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2347: &mt('Course creation processed as: (choose Dom. Coord.)').
2348: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2349: } else {
1.143 raeburn 2350: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2351: }
1.191 raeburn 2352: $$rowtotal += $rows;
1.125 raeburn 2353: return $datatable;
2354: }
2355:
1.23 raeburn 2356: sub print_directorysrch {
1.30 raeburn 2357: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2358: my $srchon = ' ';
2359: my $srchoff = ' checked="checked" ';
1.25 raeburn 2360: my ($exacton,$containson,$beginson);
1.24 raeburn 2361: my $localon = ' ';
2362: my $localoff = ' checked="checked" ';
1.23 raeburn 2363: if (ref($settings) eq 'HASH') {
2364: if ($settings->{'available'} eq '1') {
2365: $srchon = $srchoff;
2366: $srchoff = ' ';
2367: }
1.24 raeburn 2368: if ($settings->{'localonly'} eq '1') {
2369: $localon = $localoff;
2370: $localoff = ' ';
2371: }
1.25 raeburn 2372: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2373: foreach my $type (@{$settings->{'searchtypes'}}) {
2374: if ($type eq 'exact') {
2375: $exacton = ' checked="checked" ';
2376: } elsif ($type eq 'contains') {
2377: $containson = ' checked="checked" ';
2378: } elsif ($type eq 'begins') {
2379: $beginson = ' checked="checked" ';
2380: }
2381: }
2382: } else {
2383: if ($settings->{'searchtypes'} eq 'exact') {
2384: $exacton = ' checked="checked" ';
2385: } elsif ($settings->{'searchtypes'} eq 'contains') {
2386: $containson = ' checked="checked" ';
2387: } elsif ($settings->{'searchtypes'} eq 'specify') {
2388: $exacton = ' checked="checked" ';
2389: $containson = ' checked="checked" ';
2390: }
1.23 raeburn 2391: }
2392: }
2393: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2394: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2395:
2396: my $numinrow = 4;
1.26 raeburn 2397: my $cansrchrow = 0;
1.23 raeburn 2398: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2399: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2400: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2401: '<input type="radio" name="dirsrch_available"'.
2402: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2403: '<label><input type="radio" name="dirsrch_available"'.
2404: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2405: '</tr><tr>'.
1.30 raeburn 2406: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2407: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2408: '<input type="radio" name="dirsrch_localonly"'.
2409: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2410: '<label><input type="radio" name="dirsrch_localonly"'.
2411: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2412: '</tr>';
1.30 raeburn 2413: $$rowtotal += 2;
1.26 raeburn 2414: if (ref($usertypes) eq 'HASH') {
2415: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2416: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2417: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2418: $cansrchrow = 1;
2419: }
2420: }
2421: if ($cansrchrow) {
1.30 raeburn 2422: $$rowtotal ++;
1.26 raeburn 2423: $datatable .= '<tr>';
2424: } else {
2425: $datatable .= '<tr class="LC_odd_row">';
2426: }
1.30 raeburn 2427: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2428: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2429: foreach my $title (@{$titleorder}) {
2430: if (defined($searchtitles->{$title})) {
2431: my $check = ' ';
1.93 raeburn 2432: if (ref($settings) eq 'HASH') {
1.39 raeburn 2433: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2434: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2435: $check = ' checked="checked" ';
2436: }
1.25 raeburn 2437: }
2438: }
2439: $datatable .= '<td class="LC_left_item">'.
2440: '<span class="LC_nobreak"><label>'.
2441: '<input type="checkbox" name="searchby" '.
2442: 'value="'.$title.'"'.$check.'/>'.
2443: $searchtitles->{$title}.'</label></span></td>';
2444: }
2445: }
1.26 raeburn 2446: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2447: $$rowtotal ++;
1.26 raeburn 2448: if ($cansrchrow) {
2449: $datatable .= '<tr class="LC_odd_row">';
2450: } else {
2451: $datatable .= '<tr>';
2452: }
1.30 raeburn 2453: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2454: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2455: '<span class="LC_nobreak"><label>'.
2456: '<input type="checkbox" name="searchtypes" '.
2457: $exacton.' value="exact" />'.&mt('Exact match').
2458: '</label> '.
2459: '<label><input type="checkbox" name="searchtypes" '.
2460: $beginson.' value="begins" />'.&mt('Begins with').
2461: '</label> '.
2462: '<label><input type="checkbox" name="searchtypes" '.
2463: $containson.' value="contains" />'.&mt('Contains').
2464: '</label></span></td></tr>';
1.30 raeburn 2465: $$rowtotal ++;
1.25 raeburn 2466: return $datatable;
2467: }
2468:
1.28 raeburn 2469: sub print_contacts {
1.30 raeburn 2470: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2471: my $datatable;
2472: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2473: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2474: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.203 raeburn 2475: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2476: foreach my $type (@mailings) {
2477: $otheremails{$type} = '';
2478: }
1.134 raeburn 2479: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2480: if (ref($settings) eq 'HASH') {
2481: foreach my $item (@contacts) {
2482: if (exists($settings->{$item})) {
2483: $to{$item} = $settings->{$item};
2484: }
2485: }
2486: foreach my $type (@mailings) {
2487: if (exists($settings->{$type})) {
2488: if (ref($settings->{$type}) eq 'HASH') {
2489: foreach my $item (@contacts) {
2490: if ($settings->{$type}{$item}) {
2491: $checked{$type}{$item} = ' checked="checked" ';
2492: }
2493: }
2494: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2495: if ($type eq 'helpdeskmail') {
2496: $bccemails{$type} = $settings->{$type}{'bcc'};
2497: }
1.28 raeburn 2498: }
1.89 raeburn 2499: } elsif ($type eq 'lonstatusmail') {
2500: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2501: }
2502: }
2503: } else {
2504: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2505: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2506: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2507: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2508: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2509: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2510: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.190 raeburn 2511: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
1.203 raeburn 2512: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2513: }
2514: my ($titles,$short_titles) = &contact_titles();
2515: my $rownum = 0;
2516: my $css_class;
2517: foreach my $item (@contacts) {
1.69 raeburn 2518: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2519: $datatable .= '<tr'.$css_class.'>'.
2520: '<td><span class="LC_nobreak">'.$titles->{$item}.
2521: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2522: '<input type="text" name="'.$item.'" value="'.
2523: $to{$item}.'" /></td></tr>';
1.203 raeburn 2524: $rownum ++;
1.28 raeburn 2525: }
2526: foreach my $type (@mailings) {
1.69 raeburn 2527: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2528: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2529: '<td><span class="LC_nobreak">'.
2530: $titles->{$type}.': </span></td>'.
1.28 raeburn 2531: '<td class="LC_left_item">'.
2532: '<span class="LC_nobreak">';
2533: foreach my $item (@contacts) {
2534: $datatable .= '<label>'.
2535: '<input type="checkbox" name="'.$type.'"'.
2536: $checked{$type}{$item}.
2537: ' value="'.$item.'" />'.$short_titles->{$item}.
2538: '</label> ';
2539: }
2540: $datatable .= '</span><br />'.&mt('Others').': '.
2541: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2542: 'value="'.$otheremails{$type}.'" />';
2543: if ($type eq 'helpdeskmail') {
1.136 raeburn 2544: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2545: '<input type="text" name="'.$type.'_bcc" '.
2546: 'value="'.$bccemails{$type}.'" />';
2547: }
2548: $datatable .= '</td></tr>'."\n";
1.203 raeburn 2549: $rownum ++;
1.28 raeburn 2550: }
1.203 raeburn 2551: my %choices;
2552: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2553: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2554: &mt('LON-CAPA core group - MSU'),600,500));
2555: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2556: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2557: &mt('LON-CAPA core group - MSU'),600,500));
2558: my @toggles = ('reporterrors','reportupdates');
2559: my %defaultchecked = ('reporterrors' => 'on',
2560: 'reportupdates' => 'on');
2561: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2562: \%choices,$rownum);
2563: $datatable .= $reports;
1.30 raeburn 2564: $$rowtotal += $rownum;
1.28 raeburn 2565: return $datatable;
2566: }
2567:
1.118 jms 2568: sub print_helpsettings {
1.168 raeburn 2569: my ($dom,$confname,$settings,$rowtotal) = @_;
2570: my ($datatable,$itemcount);
1.166 raeburn 2571: $itemcount = 1;
1.168 raeburn 2572: my (%choices,%defaultchecked,@toggles);
2573: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2574: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2575: &mt('LON-CAPA bug tracker'),600,500));
2576: %defaultchecked = ('submitbugs' => 'on');
2577: @toggles = ('submitbugs',);
1.166 raeburn 2578:
1.168 raeburn 2579: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2580: \%choices,$itemcount);
1.166 raeburn 2581: return $datatable;
1.121 raeburn 2582: }
2583:
2584: sub radiobutton_prefs {
1.192 raeburn 2585: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
2586: $additional) = @_;
1.121 raeburn 2587: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2588: (ref($choices) eq 'HASH'));
2589:
1.170 raeburn 2590: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 2591:
2592: foreach my $item (@{$toggles}) {
2593: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2594: $checkedon{$item} = ' checked="checked" ';
2595: $checkedoff{$item} = ' ';
1.121 raeburn 2596: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2597: $checkedoff{$item} = ' checked="checked" ';
2598: $checkedon{$item} = ' ';
2599: }
2600: }
2601: if (ref($settings) eq 'HASH') {
1.121 raeburn 2602: foreach my $item (@{$toggles}) {
1.118 jms 2603: if ($settings->{$item} eq '1') {
2604: $checkedon{$item} = ' checked="checked" ';
2605: $checkedoff{$item} = ' ';
2606: } elsif ($settings->{$item} eq '0') {
2607: $checkedoff{$item} = ' checked="checked" ';
2608: $checkedon{$item} = ' ';
2609: }
2610: }
1.121 raeburn 2611: }
1.192 raeburn 2612: if ($onclick) {
2613: $onclick = ' onclick="'.$onclick.'"';
2614: }
1.121 raeburn 2615: foreach my $item (@{$toggles}) {
1.118 jms 2616: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2617: $datatable .=
1.192 raeburn 2618: '<tr'.$css_class.'><td valign="top">'.
2619: '<span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2620: '</span></td>'.
2621: '<td class="LC_right_item"><span class="LC_nobreak">'.
2622: '<label><input type="radio" name="'.
1.192 raeburn 2623: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2624: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 2625: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2626: '</span>'.$additional.
2627: '</td>'.
1.118 jms 2628: '</tr>';
2629: $itemcount ++;
1.121 raeburn 2630: }
2631: return ($datatable,$itemcount);
2632: }
2633:
2634: sub print_coursedefaults {
1.139 raeburn 2635: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 2636: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2637: my $itemcount = 1;
1.192 raeburn 2638: my %choices = &Apache::lonlocal::texthash (
2639: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 2640: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 2641: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2642: coursecredits => 'Credits can be specified for courses',
2643: );
1.198 raeburn 2644: my %staticdefaults = (
2645: anonsurvey_threshold => 10,
2646: uploadquota => 500,
2647: );
1.139 raeburn 2648: if ($position eq 'top') {
2649: %defaultchecked = ('canuse_pdfforms' => 'off');
1.192 raeburn 2650: @toggles = ('canuse_pdfforms');
1.139 raeburn 2651: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2652: \%choices,$itemcount);
1.139 raeburn 2653: } else {
2654: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.216 ! raeburn 2655: my ($currdefresponder,$def_official_credits,$def_unofficial_credits,$def_textbook_credits,
! 2656: %curruploadquota);
1.192 raeburn 2657: my $currusecredits = 0;
1.216 ! raeburn 2658: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 2659: if (ref($settings) eq 'HASH') {
2660: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 2661: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2662: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2663: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2664: }
2665: }
1.192 raeburn 2666: if (ref($settings->{'coursecredits'}) eq 'HASH') {
2667: $def_official_credits = $settings->{'coursecredits'}->{'official'};
2668: $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
1.216 ! raeburn 2669: $def_textbook_credits = $settings->{'coursecredits'}->{'textbook'};
! 2670: if (($def_official_credits ne '') || ($def_unofficial_credits ne '') ||
! 2671: ($def_textbook_credits ne '')) {
1.192 raeburn 2672: $currusecredits = 1;
2673: }
2674: }
1.139 raeburn 2675: }
2676: if (!$currdefresponder) {
1.198 raeburn 2677: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 2678: } elsif ($currdefresponder < 1) {
2679: $currdefresponder = 1;
2680: }
1.198 raeburn 2681: foreach my $type (@types) {
2682: if ($curruploadquota{$type} eq '') {
2683: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
2684: }
2685: }
1.139 raeburn 2686: $datatable .=
1.192 raeburn 2687: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2688: $choices{'anonsurvey_threshold'}.
1.139 raeburn 2689: '</span></td>'.
2690: '<td class="LC_right_item"><span class="LC_nobreak">'.
2691: '<input type="text" name="anonsurvey_threshold"'.
2692: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.198 raeburn 2693: '</td></tr>'."\n".
2694: '<tr><td><span class="LC_nobreak">'.
2695: $choices{'uploadquota'}.
2696: '</span></td>'.
2697: '<td align="right" class="LC_right_item">'.
2698: '<table><tr>';
2699: foreach my $type (@types) {
2700: $datatable .= '<td align="center">'.&mt($type).'<br />'.
2701: '<input type="text" name="uploadquota_'.$type.'"'.
2702: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
2703: }
2704: $datatable .= '</tr></table></td></tr>'."\n";
2705: $itemcount += 2;
1.192 raeburn 2706: my $onclick = 'toggleCredits(this.form);';
1.210 raeburn 2707: my $display = 'none';
1.192 raeburn 2708: if ($currusecredits) {
2709: $display = 'block';
2710: }
2711: my $additional = '<div id="credits" style="display: '.$display.'">'.
2712: '<span class="LC_nobreak">'.
2713: &mt('Default credits for official courses [_1]',
2714: '<input type="text" name="official_credits" value="'.
2715: $def_official_credits.'" size="3" />').
2716: '</span><br />'.
2717: '<span class="LC_nobreak">'.
2718: &mt('Default credits for unofficial courses [_1]',
2719: '<input type="text" name="unofficial_credits" value="'.
2720: $def_unofficial_credits.'" size="3" />').
1.216 ! raeburn 2721: '</span><br />'.
! 2722: '<span class="LC_nobreak">'.
! 2723: &mt('Default credits for textbook courses [_1]',
! 2724: '<input type="text" name="textbook_credits" value="'.
! 2725: $def_textbook_credits.'" size="3" />').
1.192 raeburn 2726: '</span></div>'."\n";
2727: %defaultchecked = ('coursecredits' => 'off');
2728: @toggles = ('coursecredits');
2729: my $current = {
2730: 'coursecredits' => $currusecredits,
2731: };
2732: (my $table,$itemcount) =
2733: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
2734: \%choices,$itemcount,$onclick,$additional);
2735: $datatable .= $table;
1.139 raeburn 2736: }
1.192 raeburn 2737: $$rowtotal += $itemcount;
1.121 raeburn 2738: return $datatable;
1.118 jms 2739: }
2740:
1.137 raeburn 2741: sub print_usersessions {
2742: my ($position,$dom,$settings,$rowtotal) = @_;
2743: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2744: my (%by_ip,%by_location,@intdoms);
2745: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 2746:
2747: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 2748: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 2749: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 2750: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 2751: my $itemcount = 1;
2752: if ($position eq 'top') {
1.152 raeburn 2753: if (keys(%serverhomes) > 1) {
1.145 raeburn 2754: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 2755: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 2756: } else {
1.140 raeburn 2757: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2758: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 2759: }
1.137 raeburn 2760: } else {
1.145 raeburn 2761: if (keys(%by_location) == 0) {
2762: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2763: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 2764: } else {
2765: my %lt = &usersession_titles();
2766: my $numinrow = 5;
2767: my $prefix;
2768: my @types;
2769: if ($position eq 'bottom') {
2770: $prefix = 'remote';
2771: @types = ('version','excludedomain','includedomain');
2772: } else {
2773: $prefix = 'hosted';
2774: @types = ('excludedomain','includedomain');
2775: }
2776: my (%current,%checkedon,%checkedoff);
2777: my @lcversions = &Apache::lonnet::all_loncaparevs();
2778: my @locations = sort(keys(%by_location));
2779: foreach my $type (@types) {
2780: $checkedon{$type} = '';
2781: $checkedoff{$type} = ' checked="checked"';
2782: }
2783: if (ref($settings) eq 'HASH') {
2784: if (ref($settings->{$prefix}) eq 'HASH') {
2785: foreach my $key (keys(%{$settings->{$prefix}})) {
2786: $current{$key} = $settings->{$prefix}{$key};
2787: if ($key eq 'version') {
2788: if ($current{$key} ne '') {
2789: $checkedon{$key} = ' checked="checked"';
2790: $checkedoff{$key} = '';
2791: }
2792: } elsif (ref($current{$key}) eq 'ARRAY') {
2793: $checkedon{$key} = ' checked="checked"';
2794: $checkedoff{$key} = '';
2795: }
1.137 raeburn 2796: }
2797: }
2798: }
1.145 raeburn 2799: foreach my $type (@types) {
2800: next if ($type ne 'version' && !@locations);
2801: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2802: $datatable .= '<tr'.$css_class.'>
2803: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2804: <span class="LC_nobreak">
2805: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2806: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2807: if ($type eq 'version') {
2808: my $selector = '<select name="'.$prefix.'_version">';
2809: foreach my $version (@lcversions) {
2810: my $selected = '';
2811: if ($current{'version'} eq $version) {
2812: $selected = ' selected="selected"';
2813: }
2814: $selector .= ' <option value="'.$version.'"'.
2815: $selected.'>'.$version.'</option>';
2816: }
2817: $selector .= '</select> ';
2818: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2819: } else {
2820: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2821: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2822: ' />'.(' 'x2).
2823: '<input type="button" value="'.&mt('uncheck all').'" '.
2824: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2825: "\n".
2826: '</div><div><table>';
2827: my $rem;
2828: for (my $i=0; $i<@locations; $i++) {
2829: my ($showloc,$value,$checkedtype);
2830: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2831: my $ip = $by_location{$locations[$i]}->[0];
2832: if (ref($by_ip{$ip}) eq 'ARRAY') {
2833: $value = join(':',@{$by_ip{$ip}});
2834: $showloc = join(', ',@{$by_ip{$ip}});
2835: if (ref($current{$type}) eq 'ARRAY') {
2836: foreach my $loc (@{$by_ip{$ip}}) {
2837: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2838: $checkedtype = ' checked="checked"';
2839: last;
2840: }
2841: }
1.138 raeburn 2842: }
2843: }
2844: }
1.145 raeburn 2845: $rem = $i%($numinrow);
2846: if ($rem == 0) {
2847: if ($i > 0) {
2848: $datatable .= '</tr>';
2849: }
2850: $datatable .= '<tr>';
2851: }
2852: $datatable .= '<td class="LC_left_item">'.
2853: '<span class="LC_nobreak"><label>'.
2854: '<input type="checkbox" name="'.$prefix.'_'.$type.
2855: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2856: '</label></span></td>';
1.137 raeburn 2857: }
1.145 raeburn 2858: $rem = @locations%($numinrow);
2859: my $colsleft = $numinrow - $rem;
2860: if ($colsleft > 1 ) {
2861: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2862: ' </td>';
2863: } elsif ($colsleft == 1) {
2864: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 2865: }
1.145 raeburn 2866: $datatable .= '</tr></table>';
1.137 raeburn 2867: }
1.145 raeburn 2868: $datatable .= '</td></tr>';
2869: $itemcount ++;
1.137 raeburn 2870: }
2871: }
2872: }
2873: $$rowtotal += $itemcount;
2874: return $datatable;
2875: }
2876:
1.138 raeburn 2877: sub build_location_hashes {
2878: my ($intdoms,$by_ip,$by_location) = @_;
2879: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2880: (ref($by_location) eq 'HASH'));
2881: my %iphost = &Apache::lonnet::get_iphost();
2882: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2883: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2884: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2885: foreach my $id (@{$iphost{$primary_ip}}) {
2886: my $intdom = &Apache::lonnet::internet_dom($id);
2887: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2888: push(@{$intdoms},$intdom);
2889: }
2890: }
2891: }
2892: foreach my $ip (keys(%iphost)) {
2893: if (ref($iphost{$ip}) eq 'ARRAY') {
2894: foreach my $id (@{$iphost{$ip}}) {
2895: my $location = &Apache::lonnet::internet_dom($id);
2896: if ($location) {
2897: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2898: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2899: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2900: push(@{$by_ip->{$ip}},$location);
2901: }
2902: } else {
2903: $by_ip->{$ip} = [$location];
2904: }
2905: }
2906: }
2907: }
2908: }
2909: foreach my $ip (sort(keys(%{$by_ip}))) {
2910: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2911: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2912: my $first = $by_ip->{$ip}->[0];
2913: if (ref($by_location->{$first}) eq 'ARRAY') {
2914: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2915: push(@{$by_location->{$first}},$ip);
2916: }
2917: } else {
2918: $by_location->{$first} = [$ip];
2919: }
2920: }
2921: }
2922: return;
2923: }
2924:
1.145 raeburn 2925: sub current_offloads_to {
2926: my ($dom,$settings,$servers) = @_;
2927: my (%spareid,%otherdomconfigs);
1.152 raeburn 2928: if (ref($servers) eq 'HASH') {
1.145 raeburn 2929: foreach my $lonhost (sort(keys(%{$servers}))) {
2930: my $gotspares;
1.152 raeburn 2931: if (ref($settings) eq 'HASH') {
2932: if (ref($settings->{'spares'}) eq 'HASH') {
2933: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
2934: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
2935: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
2936: $gotspares = 1;
2937: }
1.145 raeburn 2938: }
2939: }
2940: unless ($gotspares) {
2941: my $gotspares;
2942: my $serverhomeID =
2943: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
2944: my $serverhomedom =
2945: &Apache::lonnet::host_domain($serverhomeID);
2946: if ($serverhomedom ne $dom) {
2947: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
2948: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2949: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2950: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2951: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2952: $gotspares = 1;
2953: }
2954: }
2955: } else {
2956: $otherdomconfigs{$serverhomedom} =
2957: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
2958: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
2959: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2960: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2961: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
2962: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2963: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2964: $gotspares = 1;
2965: }
2966: }
2967: }
2968: }
2969: }
2970: }
2971: }
2972: unless ($gotspares) {
2973: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
2974: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2975: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2976: } else {
2977: my $server_hostname = &Apache::lonnet::hostname($lonhost);
2978: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
2979: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
2980: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2981: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2982: } else {
1.150 raeburn 2983: my %what = (
2984: spareid => 1,
2985: );
2986: my ($result,$returnhash) =
2987: &Apache::lonnet::get_remote_globals($lonhost,\%what);
2988: if ($result eq 'ok') {
2989: if (ref($returnhash) eq 'HASH') {
2990: if (ref($returnhash->{'spareid'}) eq 'HASH') {
2991: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
2992: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
2993: }
2994: }
1.145 raeburn 2995: }
2996: }
2997: }
2998: }
2999: }
3000: }
3001: return %spareid;
3002: }
3003:
3004: sub spares_row {
1.152 raeburn 3005: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 3006: my $css_class;
3007: my $numinrow = 4;
3008: my $itemcount = 1;
3009: my $datatable;
1.152 raeburn 3010: my %typetitles = &sparestype_titles();
3011: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 3012: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 3013: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
3014: my ($othercontrol,$serverdom);
3015: if ($serverhome ne $server) {
3016: $serverdom = &Apache::lonnet::host_domain($serverhome);
3017: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3018: } else {
3019: $serverdom = &Apache::lonnet::host_domain($server);
3020: if ($serverdom ne $dom) {
3021: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3022: }
3023: }
3024: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 3025: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3026: $datatable .= '<tr'.$css_class.'>
3027: <td rowspan="2">
1.183 bisitz 3028: <span class="LC_nobreak">'.
3029: &mt('[_1] when busy, offloads to:'
3030: ,'<b>'.$server.'</b>').
3031: "\n";
1.145 raeburn 3032: my (%current,%canselect);
1.152 raeburn 3033: my @choices =
3034: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
3035: foreach my $type ('primary','default') {
3036: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 3037: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
3038: my @spares = @{$spareid->{$server}{$type}};
3039: if (@spares > 0) {
1.152 raeburn 3040: if ($othercontrol) {
3041: $current{$type} = join(', ',@spares);
3042: } else {
3043: $current{$type} .= '<table>';
3044: my $numspares = scalar(@spares);
3045: for (my $i=0; $i<@spares; $i++) {
3046: my $rem = $i%($numinrow);
3047: if ($rem == 0) {
3048: if ($i > 0) {
3049: $current{$type} .= '</tr>';
3050: }
3051: $current{$type} .= '<tr>';
1.145 raeburn 3052: }
1.152 raeburn 3053: $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'".');" /> '.
3054: $spareid->{$server}{$type}[$i].
3055: '</label></td>'."\n";
3056: }
3057: my $rem = @spares%($numinrow);
3058: my $colsleft = $numinrow - $rem;
3059: if ($colsleft > 1 ) {
3060: $current{$type} .= '<td colspan="'.$colsleft.
3061: '" class="LC_left_item">'.
3062: ' </td>';
3063: } elsif ($colsleft == 1) {
3064: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 3065: }
1.152 raeburn 3066: $current{$type} .= '</tr></table>';
1.150 raeburn 3067: }
1.145 raeburn 3068: }
3069: }
3070: if ($current{$type} eq '') {
3071: $current{$type} = &mt('None specified');
3072: }
1.152 raeburn 3073: if ($othercontrol) {
3074: if ($type eq 'primary') {
3075: $canselect{$type} = $othercontrol;
3076: }
3077: } else {
3078: $canselect{$type} =
3079: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
3080: '<select name="newspare_'.$type.'_'.$server.'" '.
3081: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
3082: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
3083: if (@choices > 0) {
3084: foreach my $lonhost (@choices) {
3085: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
3086: }
3087: }
3088: $canselect{$type} .= '</select>'."\n";
3089: }
3090: } else {
3091: $current{$type} = &mt('Could not be determined');
3092: if ($type eq 'primary') {
3093: $canselect{$type} = $othercontrol;
3094: }
1.145 raeburn 3095: }
1.152 raeburn 3096: if ($type eq 'default') {
3097: $datatable .= '<tr'.$css_class.'>';
3098: }
3099: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
3100: '<td>'.$current{$type}.'</td>'."\n".
3101: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 3102: }
3103: $itemcount ++;
3104: }
3105: }
3106: $$rowtotal += $itemcount;
3107: return $datatable;
3108: }
3109:
1.152 raeburn 3110: sub possible_newspares {
3111: my ($server,$currspares,$serverhomes,$altids) = @_;
3112: my $serverhostname = &Apache::lonnet::hostname($server);
3113: my %excluded;
3114: if ($serverhostname ne '') {
3115: %excluded = (
3116: $serverhostname => 1,
3117: );
3118: }
3119: if (ref($currspares) eq 'HASH') {
3120: foreach my $type (keys(%{$currspares})) {
3121: if (ref($currspares->{$type}) eq 'ARRAY') {
3122: if (@{$currspares->{$type}} > 0) {
3123: foreach my $curr (@{$currspares->{$type}}) {
3124: my $hostname = &Apache::lonnet::hostname($curr);
3125: $excluded{$hostname} = 1;
3126: }
3127: }
3128: }
3129: }
3130: }
3131: my @choices;
3132: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
3133: if (keys(%{$serverhomes}) > 1) {
3134: foreach my $name (sort(keys(%{$serverhomes}))) {
3135: unless ($excluded{$name}) {
3136: if (exists($altids->{$serverhomes->{$name}})) {
3137: push(@choices,$altids->{$serverhomes->{$name}});
3138: } else {
3139: push(@choices,$serverhomes->{$name});
1.145 raeburn 3140: }
3141: }
3142: }
3143: }
3144: }
1.152 raeburn 3145: return sort(@choices);
1.145 raeburn 3146: }
3147:
1.150 raeburn 3148: sub print_loadbalancing {
3149: my ($dom,$settings,$rowtotal) = @_;
3150: my $primary_id = &Apache::lonnet::domain($dom,'primary');
3151: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3152: my $numinrow = 1;
3153: my $datatable;
3154: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 3155: my (%currbalancer,%currtargets,%currrules,%existing);
3156: if (ref($settings) eq 'HASH') {
3157: %existing = %{$settings};
3158: }
3159: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
3160: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
3161: \%currtargets,\%currrules);
1.150 raeburn 3162: } else {
3163: return;
3164: }
3165: my ($othertitle,$usertypes,$types) =
3166: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 3167: my $rownum = 8;
1.150 raeburn 3168: if (ref($types) eq 'ARRAY') {
3169: $rownum += scalar(@{$types});
3170: }
1.171 raeburn 3171: my @css_class = ('LC_odd_row','LC_even_row');
3172: my $balnum = 0;
3173: my $islast;
3174: my (@toshow,$disabledtext);
3175: if (keys(%currbalancer) > 0) {
3176: @toshow = sort(keys(%currbalancer));
3177: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
3178: push(@toshow,'');
3179: }
3180: } else {
3181: @toshow = ('');
3182: $disabledtext = &mt('No existing load balancer');
3183: }
3184: foreach my $lonhost (@toshow) {
3185: if ($balnum == scalar(@toshow)-1) {
3186: $islast = 1;
3187: } else {
3188: $islast = 0;
3189: }
3190: my $cssidx = $balnum%2;
3191: my $targets_div_style = 'display: none';
3192: my $disabled_div_style = 'display: block';
3193: my $homedom_div_style = 'display: none';
3194: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3195: '<td rowspan="'.$rownum.'" valign="top">'.
3196: '<p>';
3197: if ($lonhost eq '') {
1.210 raeburn 3198: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 3199: if (keys(%currbalancer) > 0) {
3200: $datatable .= &mt('Add balancer:');
3201: } else {
3202: $datatable .= &mt('Enable balancer:');
3203: }
3204: $datatable .= ' '.
3205: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3206: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3207: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3208: '<option value="" selected="selected">'.&mt('None').
3209: '</option>'."\n";
3210: foreach my $server (sort(keys(%servers))) {
3211: next if ($currbalancer{$server});
3212: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3213: }
1.210 raeburn 3214: $datatable .=
1.171 raeburn 3215: '</select>'."\n".
3216: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3217: } else {
3218: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3219: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3220: &mt('Stop balancing').'</label>'.
3221: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3222: $targets_div_style = 'display: block';
3223: $disabled_div_style = 'display: none';
3224: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3225: $homedom_div_style = 'display: block';
3226: }
3227: }
3228: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3229: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3230: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3231: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3232: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3233: my @sparestypes = ('primary','default');
3234: my %typetitles = &sparestype_titles();
3235: foreach my $sparetype (@sparestypes) {
3236: my $targettable;
3237: for (my $i=0; $i<$numspares; $i++) {
3238: my $checked;
3239: if (ref($currtargets{$lonhost}) eq 'HASH') {
3240: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3241: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3242: $checked = ' checked="checked"';
3243: }
3244: }
3245: }
3246: my ($chkboxval,$disabled);
3247: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3248: $chkboxval = $spares[$i];
3249: }
3250: if (exists($currbalancer{$spares[$i]})) {
3251: $disabled = ' disabled="disabled"';
3252: }
1.210 raeburn 3253: $targettable .=
1.171 raeburn 3254: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3255: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3256: '</span></label></td>';
3257: my $rem = $i%($numinrow);
3258: if ($rem == 0) {
3259: if (($i > 0) && ($i < $numspares-1)) {
3260: $targettable .= '</tr>';
3261: }
3262: if ($i < $numspares-1) {
3263: $targettable .= '<tr>';
1.150 raeburn 3264: }
3265: }
3266: }
1.171 raeburn 3267: if ($targettable ne '') {
3268: my $rem = $numspares%($numinrow);
3269: my $colsleft = $numinrow - $rem;
3270: if ($colsleft > 1 ) {
3271: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3272: ' </td>';
3273: } elsif ($colsleft == 1) {
3274: $targettable .= '<td class="LC_left_item"> </td>';
3275: }
3276: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3277: '<table><tr>'.$targettable.'</tr></table><br />';
3278: }
3279: }
3280: $datatable .= '</div></td></tr>'.
3281: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3282: $othertitle,$usertypes,$types,\%servers,
3283: \%currbalancer,$lonhost,
3284: $targets_div_style,$homedom_div_style,
3285: $css_class[$cssidx],$balnum,$islast);
3286: $$rowtotal += $rownum;
3287: $balnum ++;
3288: }
3289: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3290: return $datatable;
3291: }
3292:
3293: sub get_loadbalancers_config {
3294: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3295: return unless ((ref($servers) eq 'HASH') &&
3296: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3297: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3298: if (keys(%{$existing}) > 0) {
3299: my $oldlonhost;
3300: foreach my $key (sort(keys(%{$existing}))) {
3301: if ($key eq 'lonhost') {
3302: $oldlonhost = $existing->{'lonhost'};
3303: $currbalancer->{$oldlonhost} = 1;
3304: } elsif ($key eq 'targets') {
3305: if ($oldlonhost) {
3306: $currtargets->{$oldlonhost} = $existing->{'targets'};
3307: }
3308: } elsif ($key eq 'rules') {
3309: if ($oldlonhost) {
3310: $currrules->{$oldlonhost} = $existing->{'rules'};
3311: }
3312: } elsif (ref($existing->{$key}) eq 'HASH') {
3313: $currbalancer->{$key} = 1;
3314: $currtargets->{$key} = $existing->{$key}{'targets'};
3315: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3316: }
3317: }
1.171 raeburn 3318: } else {
3319: my ($balancerref,$targetsref) =
3320: &Apache::lonnet::get_lonbalancer_config($servers);
3321: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3322: foreach my $server (sort(keys(%{$balancerref}))) {
3323: $currbalancer->{$server} = 1;
3324: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3325: }
3326: }
3327: }
1.171 raeburn 3328: return;
1.150 raeburn 3329: }
3330:
3331: sub loadbalancing_rules {
3332: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 3333: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3334: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3335: my $output;
1.171 raeburn 3336: my $num = 0;
1.210 raeburn 3337: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3338: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3339: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3340: foreach my $type (@{$alltypes}) {
1.171 raeburn 3341: $num ++;
1.150 raeburn 3342: my $current;
3343: if (ref($currrules) eq 'HASH') {
3344: $current = $currrules->{$type};
3345: }
1.209 raeburn 3346: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.171 raeburn 3347: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3348: $current = '';
3349: }
3350: }
3351: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 3352: $servers,$currbalancer,$lonhost,$dom,
3353: $targets_div_style,$homedom_div_style,
3354: $css_class,$balnum,$num,$islast);
1.150 raeburn 3355: }
3356: }
3357: return $output;
3358: }
3359:
3360: sub loadbalancing_titles {
3361: my ($dom,$intdom,$usertypes,$types) = @_;
3362: my %othertypes = (
3363: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3364: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3365: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3366: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 3367: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
3368: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 3369: );
1.209 raeburn 3370: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 3371: if (ref($types) eq 'ARRAY') {
3372: unshift(@alltypes,@{$types},'default');
3373: }
3374: my %titles;
3375: foreach my $type (@alltypes) {
3376: if ($type =~ /^_LC_/) {
3377: $titles{$type} = $othertypes{$type};
3378: } elsif ($type eq 'default') {
3379: $titles{$type} = &mt('All users from [_1]',$dom);
3380: if (ref($types) eq 'ARRAY') {
3381: if (@{$types} > 0) {
3382: $titles{$type} = &mt('Other users from [_1]',$dom);
3383: }
3384: }
3385: } elsif (ref($usertypes) eq 'HASH') {
3386: $titles{$type} = $usertypes->{$type};
3387: }
3388: }
3389: return (\@alltypes,\%othertypes,\%titles);
3390: }
3391:
3392: sub loadbalance_rule_row {
1.171 raeburn 3393: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3394: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 3395: my @rulenames;
1.150 raeburn 3396: my %ruletitles = &offloadtype_text();
1.209 raeburn 3397: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
3398: @rulenames = ('balancer','offloadedto');
1.150 raeburn 3399: } else {
1.209 raeburn 3400: @rulenames = ('default','homeserver');
3401: if ($type eq '_LC_external') {
3402: push(@rulenames,'externalbalancer');
3403: } else {
3404: push(@rulenames,'specific');
3405: }
3406: push(@rulenames,'none');
1.150 raeburn 3407: }
3408: my $style = $targets_div_style;
1.209 raeburn 3409: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.150 raeburn 3410: $style = $homedom_div_style;
3411: }
1.171 raeburn 3412: my $space;
3413: if ($islast && $num == 1) {
3414: $space = '<div display="inline-block"> </div>';
3415: }
1.210 raeburn 3416: my $output =
1.171 raeburn 3417: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3418: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3419: '<td valaign="top">'.$space.
3420: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3421: for (my $i=0; $i<@rulenames; $i++) {
3422: my $rule = $rulenames[$i];
3423: my ($checked,$extra);
3424: if ($rulenames[$i] eq 'default') {
3425: $rule = '';
3426: }
3427: if ($rulenames[$i] eq 'specific') {
3428: if (ref($servers) eq 'HASH') {
3429: my $default;
3430: if (($current ne '') && (exists($servers->{$current}))) {
3431: $checked = ' checked="checked"';
3432: }
3433: unless ($checked) {
3434: $default = ' selected="selected"';
3435: }
1.210 raeburn 3436: $extra =
1.171 raeburn 3437: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3438: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3439: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3440: '<option value=""'.$default.'></option>'."\n";
3441: foreach my $server (sort(keys(%{$servers}))) {
3442: if (ref($currbalancer) eq 'HASH') {
3443: next if (exists($currbalancer->{$server}));
3444: }
1.150 raeburn 3445: my $selected;
1.171 raeburn 3446: if ($server eq $current) {
1.150 raeburn 3447: $selected = ' selected="selected"';
3448: }
1.171 raeburn 3449: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3450: }
3451: $extra .= '</select>';
3452: }
3453: } elsif ($rule eq $current) {
3454: $checked = ' checked="checked"';
3455: }
3456: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 3457: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3458: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3459: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3460: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3461: '</label>'.$extra.'</span><br />'."\n";
3462: }
3463: $output .= '</div></td></tr>'."\n";
3464: return $output;
3465: }
3466:
3467: sub offloadtype_text {
3468: my %ruletitles = &Apache::lonlocal::texthash (
3469: 'default' => 'Offloads to default destinations',
3470: 'homeserver' => "Offloads to user's home server",
3471: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3472: 'specific' => 'Offloads to specific server',
1.161 raeburn 3473: 'none' => 'No offload',
1.209 raeburn 3474: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
3475: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.150 raeburn 3476: );
3477: return %ruletitles;
3478: }
3479:
3480: sub sparestype_titles {
3481: my %typestitles = &Apache::lonlocal::texthash (
3482: 'primary' => 'primary',
3483: 'default' => 'default',
3484: );
3485: return %typestitles;
3486: }
3487:
1.28 raeburn 3488: sub contact_titles {
3489: my %titles = &Apache::lonlocal::texthash (
3490: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3491: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3492: 'errormail' => 'Error reports to be e-mailed to',
3493: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3494: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3495: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3496: 'requestsmail' => 'E-mail from course requests requiring approval',
1.190 raeburn 3497: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 3498: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 3499: );
3500: my %short_titles = &Apache::lonlocal::texthash (
3501: adminemail => 'Admin E-mail address',
3502: supportemail => 'Support E-mail',
3503: );
3504: return (\%titles,\%short_titles);
3505: }
3506:
1.72 raeburn 3507: sub tool_titles {
3508: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 3509: aboutme => 'Personal web page',
1.86 raeburn 3510: blog => 'Blog',
1.162 raeburn 3511: webdav => 'WebDAV',
1.86 raeburn 3512: portfolio => 'Portfolio',
1.88 bisitz 3513: official => 'Official courses (with institutional codes)',
3514: unofficial => 'Unofficial courses',
1.98 raeburn 3515: community => 'Communities',
1.216 ! raeburn 3516: textbook => 'Textbook courses',
1.86 raeburn 3517: );
1.72 raeburn 3518: return %titles;
3519: }
3520:
1.101 raeburn 3521: sub courserequest_titles {
3522: my %titles = &Apache::lonlocal::texthash (
3523: official => 'Official',
3524: unofficial => 'Unofficial',
3525: community => 'Communities',
1.216 ! raeburn 3526: textbook => 'Textbook',
1.101 raeburn 3527: norequest => 'Not allowed',
1.104 raeburn 3528: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3529: validate => 'With validation',
3530: autolimit => 'Numerical limit',
1.103 raeburn 3531: unlimited => '(blank for unlimited)',
1.101 raeburn 3532: );
3533: return %titles;
3534: }
3535:
1.163 raeburn 3536: sub authorrequest_titles {
3537: my %titles = &Apache::lonlocal::texthash (
3538: norequest => 'Not allowed',
3539: approval => 'Approval by Dom. Coord.',
3540: automatic => 'Automatic approval',
3541: );
3542: return %titles;
1.210 raeburn 3543: }
1.163 raeburn 3544:
1.101 raeburn 3545: sub courserequest_conditions {
3546: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3547: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 3548: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 3549: );
3550: return %conditions;
3551: }
3552:
3553:
1.27 raeburn 3554: sub print_usercreation {
1.30 raeburn 3555: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3556: my $numinrow = 4;
1.28 raeburn 3557: my $datatable;
3558: if ($position eq 'top') {
1.30 raeburn 3559: $$rowtotal ++;
1.34 raeburn 3560: my $rowcount = 0;
1.32 raeburn 3561: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3562: if (ref($rules) eq 'HASH') {
3563: if (keys(%{$rules}) > 0) {
1.32 raeburn 3564: $datatable .= &user_formats_row('username',$settings,$rules,
3565: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3566: $$rowtotal ++;
1.32 raeburn 3567: $rowcount ++;
3568: }
3569: }
3570: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3571: if (ref($idrules) eq 'HASH') {
3572: if (keys(%{$idrules}) > 0) {
3573: $datatable .= &user_formats_row('id',$settings,$idrules,
3574: $idruleorder,$numinrow,$rowcount);
3575: $$rowtotal ++;
3576: $rowcount ++;
1.28 raeburn 3577: }
3578: }
1.43 raeburn 3579: my ($emailrules,$emailruleorder) =
3580: &Apache::lonnet::inst_userrules($dom,'email');
3581: if (ref($emailrules) eq 'HASH') {
3582: if (keys(%{$emailrules}) > 0) {
3583: $datatable .= &user_formats_row('email',$settings,$emailrules,
3584: $emailruleorder,$numinrow,$rowcount);
3585: $$rowtotal ++;
3586: $rowcount ++;
3587: }
3588: }
1.39 raeburn 3589: if ($rowcount == 0) {
3590: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3591: $$rowtotal ++;
3592: $rowcount ++;
3593: }
1.34 raeburn 3594: } elsif ($position eq 'middle') {
1.100 raeburn 3595: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 3596: my ($rules,$ruleorder) =
3597: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3598: my %lt = &usercreation_types();
3599: my %checked;
1.50 raeburn 3600: my @selfcreate;
1.34 raeburn 3601: if (ref($settings) eq 'HASH') {
3602: if (ref($settings->{'cancreate'}) eq 'HASH') {
3603: foreach my $item (@creators) {
3604: $checked{$item} = $settings->{'cancreate'}{$item};
3605: }
1.50 raeburn 3606: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3607: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3608: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3609: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3610: @selfcreate = ('email','login','sso');
3611: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3612: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3613: }
3614: }
1.34 raeburn 3615: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3616: foreach my $item (@creators) {
3617: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3618: $checked{$item} = 'none';
3619: }
3620: }
3621: }
3622: }
3623: my $rownum = 0;
3624: foreach my $item (@creators) {
3625: $rownum ++;
1.50 raeburn 3626: if ($item ne 'selfcreate') {
3627: if ($checked{$item} eq '') {
1.43 raeburn 3628: $checked{$item} = 'any';
3629: }
1.34 raeburn 3630: }
3631: my $css_class;
3632: if ($rownum%2) {
3633: $css_class = '';
3634: } else {
3635: $css_class = ' class="LC_odd_row" ';
3636: }
3637: $datatable .= '<tr'.$css_class.'>'.
3638: '<td><span class="LC_nobreak">'.$lt{$item}.
3639: '</span></td><td align="right">';
1.50 raeburn 3640: my @options;
1.45 raeburn 3641: if ($item eq 'selfcreate') {
1.43 raeburn 3642: push(@options,('email','login','sso'));
3643: } else {
1.50 raeburn 3644: @options = ('any');
1.43 raeburn 3645: if (ref($rules) eq 'HASH') {
3646: if (keys(%{$rules}) > 0) {
3647: push(@options,('official','unofficial'));
3648: }
1.37 raeburn 3649: }
1.50 raeburn 3650: push(@options,'none');
1.37 raeburn 3651: }
3652: foreach my $option (@options) {
1.50 raeburn 3653: my $type = 'radio';
1.34 raeburn 3654: my $check = ' ';
1.50 raeburn 3655: if ($item eq 'selfcreate') {
3656: $type = 'checkbox';
3657: if (grep(/^\Q$option\E$/,@selfcreate)) {
3658: $check = ' checked="checked" ';
3659: }
3660: } else {
3661: if ($checked{$item} eq $option) {
3662: $check = ' checked="checked" ';
3663: }
1.34 raeburn 3664: }
3665: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3666: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3667: $item.'" value="'.$option.'"'.$check.'/> '.
3668: $lt{$option}.'</label> </span>';
3669: }
3670: $datatable .= '</td></tr>';
3671: }
1.93 raeburn 3672: my ($othertitle,$usertypes,$types) =
3673: &Apache::loncommon::sorted_inst_types($dom);
1.165 raeburn 3674: my $createsettings;
3675: if (ref($settings) eq 'HASH') {
3676: $createsettings = $settings->{cancreate};
3677: }
1.93 raeburn 3678: if (ref($usertypes) eq 'HASH') {
3679: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 3680: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 3681: $dom,$numinrow,$othertitle,
3682: 'statustocreate');
3683: $$rowtotal ++;
1.169 raeburn 3684: $rownum ++;
1.93 raeburn 3685: }
3686: }
1.169 raeburn 3687: $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
1.28 raeburn 3688: } else {
3689: my @contexts = ('author','course','domain');
3690: my @authtypes = ('int','krb4','krb5','loc');
3691: my %checked;
3692: if (ref($settings) eq 'HASH') {
3693: if (ref($settings->{'authtypes'}) eq 'HASH') {
3694: foreach my $item (@contexts) {
3695: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3696: foreach my $auth (@authtypes) {
3697: if ($settings->{'authtypes'}{$item}{$auth}) {
3698: $checked{$item}{$auth} = ' checked="checked" ';
3699: }
3700: }
3701: }
3702: }
1.27 raeburn 3703: }
1.35 raeburn 3704: } else {
3705: foreach my $item (@contexts) {
1.36 raeburn 3706: foreach my $auth (@authtypes) {
1.35 raeburn 3707: $checked{$item}{$auth} = ' checked="checked" ';
3708: }
3709: }
1.27 raeburn 3710: }
1.28 raeburn 3711: my %title = &context_names();
3712: my %authname = &authtype_names();
3713: my $rownum = 0;
3714: my $css_class;
3715: foreach my $item (@contexts) {
3716: if ($rownum%2) {
3717: $css_class = '';
3718: } else {
3719: $css_class = ' class="LC_odd_row" ';
3720: }
1.30 raeburn 3721: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3722: '<td>'.$title{$item}.
3723: '</td><td class="LC_left_item">'.
3724: '<span class="LC_nobreak">';
3725: foreach my $auth (@authtypes) {
3726: $datatable .= '<label>'.
3727: '<input type="checkbox" name="'.$item.'_auth" '.
3728: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3729: $authname{$auth}.'</label> ';
3730: }
3731: $datatable .= '</span></td></tr>';
3732: $rownum ++;
1.27 raeburn 3733: }
1.30 raeburn 3734: $$rowtotal += $rownum;
1.27 raeburn 3735: }
3736: return $datatable;
3737: }
3738:
1.165 raeburn 3739: sub captcha_choice {
1.169 raeburn 3740: my ($context,$settings,$itemcount) = @_;
1.165 raeburn 3741: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
3742: my %lt = &captcha_phrases();
3743: $keyentry = 'hidden';
3744: if ($context eq 'cancreate') {
3745: $rowname = &mt('CAPTCHA validation (e-mail as username)');
1.169 raeburn 3746: } elsif ($context eq 'login') {
3747: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 3748: }
3749: if (ref($settings) eq 'HASH') {
3750: if ($settings->{'captcha'}) {
3751: $checked{$settings->{'captcha'}} = ' checked="checked"';
3752: } else {
3753: $checked{'original'} = ' checked="checked"';
3754: }
3755: if ($settings->{'captcha'} eq 'recaptcha') {
3756: $pubtext = $lt{'pub'};
3757: $privtext = $lt{'priv'};
3758: $keyentry = 'text';
3759: }
3760: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
3761: $currpub = $settings->{'recaptchakeys'}{'public'};
3762: $currpriv = $settings->{'recaptchakeys'}{'private'};
3763: }
3764: } else {
3765: $checked{'original'} = ' checked="checked"';
3766: }
1.169 raeburn 3767: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3768: my $output = '<tr'.$css_class.'>'.
3769: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 3770: '<table><tr><td>'."\n";
3771: foreach my $option ('original','recaptcha','notused') {
3772: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
3773: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
3774: $lt{$option}.'</label></span>';
3775: unless ($option eq 'notused') {
3776: $output .= (' 'x2)."\n";
3777: }
3778: }
3779: #
3780: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
3781: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 3782: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 3783: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 3784: #
1.165 raeburn 3785: $output .= '</td></tr>'."\n".
3786: '<tr><td>'."\n".
3787: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
3788: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
3789: $currpub.'" size="40" /></span><br />'."\n".
3790: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
3791: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
3792: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
3793: '</td></tr>';
3794: return $output;
3795: }
3796:
1.32 raeburn 3797: sub user_formats_row {
3798: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3799: my $output;
3800: my %text = (
3801: 'username' => 'new usernames',
3802: 'id' => 'IDs',
1.45 raeburn 3803: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3804: );
3805: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3806: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3807: '<td><span class="LC_nobreak">';
3808: if ($type eq 'email') {
3809: $output .= &mt("Formats disallowed for $text{$type}: ");
3810: } else {
3811: $output .= &mt("Format rules to check for $text{$type}: ");
3812: }
3813: $output .= '</span></td>'.
3814: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3815: my $rem;
3816: if (ref($ruleorder) eq 'ARRAY') {
3817: for (my $i=0; $i<@{$ruleorder}; $i++) {
3818: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3819: my $rem = $i%($numinrow);
3820: if ($rem == 0) {
3821: if ($i > 0) {
3822: $output .= '</tr>';
3823: }
3824: $output .= '<tr>';
3825: }
3826: my $check = ' ';
1.39 raeburn 3827: if (ref($settings) eq 'HASH') {
3828: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3829: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3830: $check = ' checked="checked" ';
3831: }
1.27 raeburn 3832: }
3833: }
3834: $output .= '<td class="LC_left_item">'.
3835: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3836: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 3837: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3838: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3839: }
3840: }
3841: $rem = @{$ruleorder}%($numinrow);
3842: }
3843: my $colsleft = $numinrow - $rem;
3844: if ($colsleft > 1 ) {
3845: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3846: ' </td>';
3847: } elsif ($colsleft == 1) {
3848: $output .= '<td class="LC_left_item"> </td>';
3849: }
3850: $output .= '</tr></table></td></tr>';
3851: return $output;
3852: }
3853:
1.34 raeburn 3854: sub usercreation_types {
3855: my %lt = &Apache::lonlocal::texthash (
3856: author => 'When adding a co-author',
3857: course => 'When adding a user to a course',
1.100 raeburn 3858: requestcrs => 'When requesting a course',
1.45 raeburn 3859: selfcreate => 'User creates own account',
1.34 raeburn 3860: any => 'Any',
3861: official => 'Institutional only ',
3862: unofficial => 'Non-institutional only',
1.85 schafran 3863: email => 'E-mail address',
1.43 raeburn 3864: login => 'Institutional Login',
3865: sso => 'SSO',
1.34 raeburn 3866: none => 'None',
3867: );
3868: return %lt;
1.48 raeburn 3869: }
1.34 raeburn 3870:
1.28 raeburn 3871: sub authtype_names {
3872: my %lt = &Apache::lonlocal::texthash(
3873: int => 'Internal',
3874: krb4 => 'Kerberos 4',
3875: krb5 => 'Kerberos 5',
3876: loc => 'Local',
3877: );
3878: return %lt;
3879: }
3880:
3881: sub context_names {
3882: my %context_title = &Apache::lonlocal::texthash(
3883: author => 'Creating users when an Author',
3884: course => 'Creating users when in a course',
3885: domain => 'Creating users when a Domain Coordinator',
3886: );
3887: return %context_title;
3888: }
3889:
1.33 raeburn 3890: sub print_usermodification {
3891: my ($position,$dom,$settings,$rowtotal) = @_;
3892: my $numinrow = 4;
3893: my ($context,$datatable,$rowcount);
3894: if ($position eq 'top') {
3895: $rowcount = 0;
3896: $context = 'author';
3897: foreach my $role ('ca','aa') {
3898: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3899: $numinrow,$rowcount);
3900: $$rowtotal ++;
3901: $rowcount ++;
3902: }
1.63 raeburn 3903: } elsif ($position eq 'middle') {
1.33 raeburn 3904: $context = 'course';
3905: $rowcount = 0;
3906: foreach my $role ('st','ep','ta','in','cr') {
3907: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3908: $numinrow,$rowcount);
3909: $$rowtotal ++;
3910: $rowcount ++;
3911: }
1.63 raeburn 3912: } elsif ($position eq 'bottom') {
3913: $context = 'selfcreate';
3914: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3915: $usertypes->{'default'} = $othertitle;
3916: if (ref($types) eq 'ARRAY') {
3917: push(@{$types},'default');
3918: $usertypes->{'default'} = $othertitle;
3919: foreach my $status (@{$types}) {
3920: $datatable .= &modifiable_userdata_row($context,$status,$settings,
3921: $numinrow,$rowcount,$usertypes);
3922: $$rowtotal ++;
3923: $rowcount ++;
3924: }
3925: }
1.33 raeburn 3926: }
3927: return $datatable;
3928: }
3929:
1.43 raeburn 3930: sub print_defaults {
1.212 raeburn 3931: my ($dom,$settings,$rowtotal) = @_;
1.68 raeburn 3932: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 3933: 'datelocale_def','portal_def');
1.212 raeburn 3934: my %defaults;
3935: if (ref($settings) eq 'HASH') {
1.213 raeburn 3936: %defaults = %{$settings};
1.212 raeburn 3937: } else {
3938: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
3939: foreach my $item (@items) {
3940: $defaults{$item} = $domdefaults{$item};
3941: }
3942: }
1.141 raeburn 3943: my $titles = &defaults_titles($dom);
1.43 raeburn 3944: my $rownum = 0;
3945: my ($datatable,$css_class);
3946: foreach my $item (@items) {
3947: if ($rownum%2) {
3948: $css_class = '';
3949: } else {
3950: $css_class = ' class="LC_odd_row" ';
3951: }
3952: $datatable .= '<tr'.$css_class.'>'.
3953: '<td><span class="LC_nobreak">'.$titles->{$item}.
3954: '</span></td><td class="LC_right_item">';
3955: if ($item eq 'auth_def') {
3956: my @authtypes = ('internal','krb4','krb5','localauth');
3957: my %shortauth = (
3958: internal => 'int',
3959: krb4 => 'krb4',
3960: krb5 => 'krb5',
3961: localauth => 'loc'
3962: );
3963: my %authnames = &authtype_names();
3964: foreach my $auth (@authtypes) {
3965: my $checked = ' ';
1.212 raeburn 3966: if ($defaults{$item} eq $auth) {
1.43 raeburn 3967: $checked = ' checked="checked" ';
3968: }
3969: $datatable .= '<label><input type="radio" name="'.$item.
3970: '" value="'.$auth.'"'.$checked.'/>'.
3971: $authnames{$shortauth{$auth}}.'</label> ';
3972: }
1.54 raeburn 3973: } elsif ($item eq 'timezone_def') {
3974: my $includeempty = 1;
1.212 raeburn 3975: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
1.68 raeburn 3976: } elsif ($item eq 'datelocale_def') {
3977: my $includeempty = 1;
1.212 raeburn 3978: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
1.167 raeburn 3979: } elsif ($item eq 'lang_def') {
1.168 raeburn 3980: my %langchoices = &get_languages_hash();
3981: $langchoices{''} = 'No language preference';
1.167 raeburn 3982: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.212 raeburn 3983: $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,
1.167 raeburn 3984: \%langchoices);
1.43 raeburn 3985: } else {
1.141 raeburn 3986: my $size;
3987: if ($item eq 'portal_def') {
3988: $size = ' size="25"';
3989: }
1.43 raeburn 3990: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.212 raeburn 3991: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 3992: }
3993: $datatable .= '</td></tr>';
3994: $rownum ++;
3995: }
3996: $$rowtotal += $rownum;
3997: return $datatable;
3998: }
3999:
1.168 raeburn 4000: sub get_languages_hash {
4001: my %langchoices;
4002: foreach my $id (&Apache::loncommon::languageids()) {
4003: my $code = &Apache::loncommon::supportedlanguagecode($id);
4004: if ($code ne '') {
4005: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
4006: }
4007: }
4008: return %langchoices;
4009: }
4010:
1.43 raeburn 4011: sub defaults_titles {
1.141 raeburn 4012: my ($dom) = @_;
1.43 raeburn 4013: my %titles = &Apache::lonlocal::texthash (
4014: 'auth_def' => 'Default authentication type',
4015: 'auth_arg_def' => 'Default authentication argument',
4016: 'lang_def' => 'Default language',
1.54 raeburn 4017: 'timezone_def' => 'Default timezone',
1.68 raeburn 4018: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 4019: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 4020: );
1.141 raeburn 4021: if ($dom) {
4022: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
4023: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
4024: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
4025: $protocol = 'http' if ($protocol ne 'https');
4026: if ($uint_dom) {
4027: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
4028: $uint_dom);
4029: }
4030: }
1.43 raeburn 4031: return (\%titles);
4032: }
4033:
1.46 raeburn 4034: sub print_scantronformat {
4035: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
4036: my $itemcount = 1;
1.60 raeburn 4037: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
4038: %confhash);
1.46 raeburn 4039: my $switchserver = &check_switchserver($dom,$confname);
4040: my %lt = &Apache::lonlocal::texthash (
1.95 www 4041: default => 'Default bubblesheet format file error',
4042: custom => 'Custom bubblesheet format file error',
1.46 raeburn 4043: );
4044: my %scantronfiles = (
4045: default => 'default.tab',
4046: custom => 'custom.tab',
4047: );
4048: foreach my $key (keys(%scantronfiles)) {
4049: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
4050: .$scantronfiles{$key};
4051: }
4052: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
4053: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
4054: if (!$switchserver) {
4055: my $servadm = $r->dir_config('lonAdmEMail');
4056: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
4057: if ($configuserok eq 'ok') {
4058: if ($author_ok eq 'ok') {
4059: my %legacyfile = (
4060: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
4061: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
4062: );
4063: my %md5chk;
4064: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4065: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
4066: chomp($md5chk{$type});
1.46 raeburn 4067: }
4068: if ($md5chk{'default'} ne $md5chk{'custom'}) {
4069: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4070: ($scantronurls{$type},my $error) =
1.46 raeburn 4071: &legacy_scantronformat($r,$dom,$confname,
4072: $type,$legacyfile{$type},
4073: $scantronurls{$type},
4074: $scantronfiles{$type});
1.60 raeburn 4075: if ($error ne '') {
4076: $error{$type} = $error;
4077: }
4078: }
4079: if (keys(%error) == 0) {
4080: $is_custom = 1;
4081: $confhash{'scantron'}{'scantronformat'} =
4082: $scantronurls{'custom'};
4083: my $putresult =
4084: &Apache::lonnet::put_dom('configuration',
4085: \%confhash,$dom);
4086: if ($putresult ne 'ok') {
4087: $error{'custom'} =
4088: '<span class="LC_error">'.
4089: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4090: }
1.46 raeburn 4091: }
4092: } else {
1.60 raeburn 4093: ($scantronurls{'default'},my $error) =
1.46 raeburn 4094: &legacy_scantronformat($r,$dom,$confname,
4095: 'default',$legacyfile{'default'},
4096: $scantronurls{'default'},
4097: $scantronfiles{'default'});
1.60 raeburn 4098: if ($error eq '') {
4099: $confhash{'scantron'}{'scantronformat'} = '';
4100: my $putresult =
4101: &Apache::lonnet::put_dom('configuration',
4102: \%confhash,$dom);
4103: if ($putresult ne 'ok') {
4104: $error{'default'} =
4105: '<span class="LC_error">'.
4106: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4107: }
4108: } else {
4109: $error{'default'} = $error;
4110: }
1.46 raeburn 4111: }
4112: }
4113: }
4114: } else {
1.95 www 4115: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 4116: }
4117: }
4118: if (ref($settings) eq 'HASH') {
4119: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
4120: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
4121: if ((!@info) || ($info[0] eq 'no_such_dir')) {
4122: $scantronurl = '';
4123: } else {
4124: $scantronurl = $settings->{'scantronformat'};
4125: }
4126: $is_custom = 1;
4127: } else {
4128: $scantronurl = $scantronurls{'default'};
4129: }
4130: } else {
1.60 raeburn 4131: if ($is_custom) {
4132: $scantronurl = $scantronurls{'custom'};
4133: } else {
4134: $scantronurl = $scantronurls{'default'};
4135: }
1.46 raeburn 4136: }
4137: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4138: $datatable .= '<tr'.$css_class.'>';
4139: if (!$is_custom) {
1.65 raeburn 4140: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
4141: '<span class="LC_nobreak">';
1.46 raeburn 4142: if ($scantronurl) {
1.199 raeburn 4143: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
4144: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 4145: } else {
4146: $datatable = &mt('File unavailable for display');
4147: }
1.65 raeburn 4148: $datatable .= '</span></td>';
1.60 raeburn 4149: if (keys(%error) == 0) {
4150: $datatable .= '<td valign="bottom">';
4151: if (!$switchserver) {
4152: $datatable .= &mt('Upload:').'<br />';
4153: }
4154: } else {
4155: my $errorstr;
4156: foreach my $key (sort(keys(%error))) {
4157: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4158: }
4159: $datatable .= '<td>'.$errorstr;
4160: }
1.46 raeburn 4161: } else {
4162: if (keys(%error) > 0) {
4163: my $errorstr;
4164: foreach my $key (sort(keys(%error))) {
4165: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4166: }
1.60 raeburn 4167: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 4168: } elsif ($scantronurl) {
1.199 raeburn 4169: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
4170: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 4171: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 4172: $link.
4173: '<label><input type="checkbox" name="scantronformat_del"'.
4174: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 4175: '<td><span class="LC_nobreak"> '.
4176: &mt('Replace:').'</span><br />';
1.46 raeburn 4177: }
4178: }
4179: if (keys(%error) == 0) {
4180: if ($switchserver) {
4181: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4182: } else {
1.65 raeburn 4183: $datatable .='<span class="LC_nobreak"> '.
4184: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 4185: }
4186: }
4187: $datatable .= '</td></tr>';
4188: $$rowtotal ++;
4189: return $datatable;
4190: }
4191:
4192: sub legacy_scantronformat {
4193: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
4194: my ($url,$error);
4195: my @statinfo = &Apache::lonnet::stat_file($newurl);
4196: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
4197: (my $result,$url) =
4198: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
4199: '','',$newfile);
4200: if ($result ne 'ok') {
1.130 raeburn 4201: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 4202: }
4203: }
4204: return ($url,$error);
4205: }
1.43 raeburn 4206:
1.49 raeburn 4207: sub print_coursecategories {
1.57 raeburn 4208: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
4209: my $datatable;
4210: if ($position eq 'top') {
4211: my $toggle_cats_crs = ' ';
4212: my $toggle_cats_dom = ' checked="checked" ';
4213: my $can_cat_crs = ' ';
4214: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 4215: my $toggle_catscomm_comm = ' ';
4216: my $toggle_catscomm_dom = ' checked="checked" ';
4217: my $can_catcomm_comm = ' ';
4218: my $can_catcomm_dom = ' checked="checked" ';
4219:
1.57 raeburn 4220: if (ref($settings) eq 'HASH') {
4221: if ($settings->{'togglecats'} eq 'crs') {
4222: $toggle_cats_crs = $toggle_cats_dom;
4223: $toggle_cats_dom = ' ';
4224: }
4225: if ($settings->{'categorize'} eq 'crs') {
4226: $can_cat_crs = $can_cat_dom;
4227: $can_cat_dom = ' ';
4228: }
1.120 raeburn 4229: if ($settings->{'togglecatscomm'} eq 'comm') {
4230: $toggle_catscomm_comm = $toggle_catscomm_dom;
4231: $toggle_catscomm_dom = ' ';
4232: }
4233: if ($settings->{'categorizecomm'} eq 'comm') {
4234: $can_catcomm_comm = $can_catcomm_dom;
4235: $can_catcomm_dom = ' ';
4236: }
1.57 raeburn 4237: }
4238: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 4239: togglecats => 'Show/Hide a course in catalog',
4240: togglecatscomm => 'Show/Hide a community in catalog',
4241: categorize => 'Assign a category to a course',
4242: categorizecomm => 'Assign a category to a community',
1.57 raeburn 4243: );
4244: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 4245: dom => 'Set in Domain',
4246: crs => 'Set in Course',
4247: comm => 'Set in Community',
1.57 raeburn 4248: );
4249: $datatable = '<tr class="LC_odd_row">'.
4250: '<td>'.$title{'togglecats'}.'</td>'.
4251: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4252: '<input type="radio" name="togglecats"'.
4253: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4254: '<label><input type="radio" name="togglecats"'.
4255: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
4256: '</tr><tr>'.
4257: '<td>'.$title{'categorize'}.'</td>'.
4258: '<td class="LC_right_item"><span class="LC_nobreak">'.
4259: '<label><input type="radio" name="categorize"'.
4260: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4261: '<label><input type="radio" name="categorize"'.
4262: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 4263: '</tr><tr class="LC_odd_row">'.
4264: '<td>'.$title{'togglecatscomm'}.'</td>'.
4265: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4266: '<input type="radio" name="togglecatscomm"'.
4267: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4268: '<label><input type="radio" name="togglecatscomm"'.
4269: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4270: '</tr><tr>'.
4271: '<td>'.$title{'categorizecomm'}.'</td>'.
4272: '<td class="LC_right_item"><span class="LC_nobreak">'.
4273: '<label><input type="radio" name="categorizecomm"'.
4274: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4275: '<label><input type="radio" name="categorizecomm"'.
4276: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 4277: '</tr>';
1.120 raeburn 4278: $$rowtotal += 4;
1.57 raeburn 4279: } else {
4280: my $css_class;
4281: my $itemcount = 1;
4282: my $cathash;
4283: if (ref($settings) eq 'HASH') {
4284: $cathash = $settings->{'cats'};
4285: }
4286: if (ref($cathash) eq 'HASH') {
4287: my (@cats,@trails,%allitems,%idx,@jsarray);
4288: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4289: \%allitems,\%idx,\@jsarray);
4290: my $maxdepth = scalar(@cats);
4291: my $colattrib = '';
4292: if ($maxdepth > 2) {
4293: $colattrib = ' colspan="2" ';
4294: }
4295: my @path;
4296: if (@cats > 0) {
4297: if (ref($cats[0]) eq 'ARRAY') {
4298: my $numtop = @{$cats[0]};
4299: my $maxnum = $numtop;
1.120 raeburn 4300: my %default_names = (
4301: instcode => &mt('Official courses'),
4302: communities => &mt('Communities'),
4303: );
4304:
4305: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4306: ($cathash->{'instcode::0'} eq '') ||
4307: (!grep(/^communities$/,@{$cats[0]})) ||
4308: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4309: $maxnum ++;
4310: }
4311: my $lastidx;
4312: for (my $i=0; $i<$numtop; $i++) {
4313: my $parent = $cats[0][$i];
4314: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4315: my $item = &escape($parent).'::0';
4316: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4317: $lastidx = $idx{$item};
4318: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4319: .'<select name="'.$item.'"'.$chgstr.'>';
4320: for (my $k=0; $k<=$maxnum; $k++) {
4321: my $vpos = $k+1;
4322: my $selstr;
4323: if ($k == $i) {
4324: $selstr = ' selected="selected" ';
4325: }
4326: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4327: }
1.214 raeburn 4328: $datatable .= '</select></span></td><td>';
1.120 raeburn 4329: if ($parent eq 'instcode' || $parent eq 'communities') {
4330: $datatable .= '<span class="LC_nobreak">'
4331: .$default_names{$parent}.'</span>';
4332: if ($parent eq 'instcode') {
4333: $datatable .= '<br /><span class="LC_nobreak">('
4334: .&mt('with institutional codes')
4335: .')</span></td><td'.$colattrib.'>';
4336: } else {
4337: $datatable .= '<table><tr><td>';
4338: }
4339: $datatable .= '<span class="LC_nobreak">'
4340: .'<label><input type="radio" name="'
4341: .$parent.'" value="1" checked="checked" />'
4342: .&mt('Display').'</label>';
4343: if ($parent eq 'instcode') {
4344: $datatable .= ' ';
4345: } else {
4346: $datatable .= '</span></td></tr><tr><td>'
4347: .'<span class="LC_nobreak">';
4348: }
4349: $datatable .= '<label><input type="radio" name="'
4350: .$parent.'" value="0" />'
4351: .&mt('Do not display').'</label></span>';
4352: if ($parent eq 'communities') {
4353: $datatable .= '</td></tr></table>';
4354: }
4355: $datatable .= '</td>';
1.57 raeburn 4356: } else {
4357: $datatable .= $parent
1.214 raeburn 4358: .' <span class="LC_nobreak"><label>'
4359: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 4360: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4361: }
4362: my $depth = 1;
4363: push(@path,$parent);
4364: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4365: pop(@path);
4366: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4367: $itemcount ++;
4368: }
1.48 raeburn 4369: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 4370: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4371: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 4372: for (my $k=0; $k<=$maxnum; $k++) {
4373: my $vpos = $k+1;
4374: my $selstr;
1.57 raeburn 4375: if ($k == $numtop) {
1.48 raeburn 4376: $selstr = ' selected="selected" ';
4377: }
4378: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4379: }
1.59 bisitz 4380: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 4381: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4382: .'</tr>'."\n";
1.48 raeburn 4383: $itemcount ++;
1.120 raeburn 4384: foreach my $default ('instcode','communities') {
4385: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4386: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4387: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4388: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4389: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4390: for (my $k=0; $k<=$maxnum; $k++) {
4391: my $vpos = $k+1;
4392: my $selstr;
4393: if ($k == $maxnum) {
4394: $selstr = ' selected="selected" ';
4395: }
4396: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 4397: }
1.120 raeburn 4398: $datatable .= '</select></span></td>'.
4399: '<td><span class="LC_nobreak">'.
4400: $default_names{$default}.'</span>';
4401: if ($default eq 'instcode') {
4402: $datatable .= '<br /><span class="LC_nobreak">('
4403: .&mt('with institutional codes').')</span>';
4404: }
4405: $datatable .= '</td>'
4406: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4407: .&mt('Display').'</label> '
4408: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
4409: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 4410: }
4411: }
4412: }
1.57 raeburn 4413: } else {
4414: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 4415: }
4416: } else {
1.57 raeburn 4417: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
4418: .&initialize_categories($itemcount);
1.48 raeburn 4419: }
1.57 raeburn 4420: $$rowtotal += $itemcount;
1.48 raeburn 4421: }
4422: return $datatable;
4423: }
4424:
1.69 raeburn 4425: sub print_serverstatuses {
4426: my ($dom,$settings,$rowtotal) = @_;
4427: my $datatable;
4428: my @pages = &serverstatus_pages();
4429: my (%namedaccess,%machineaccess);
4430: foreach my $type (@pages) {
4431: $namedaccess{$type} = '';
4432: $machineaccess{$type}= '';
4433: }
4434: if (ref($settings) eq 'HASH') {
4435: foreach my $type (@pages) {
4436: if (exists($settings->{$type})) {
4437: if (ref($settings->{$type}) eq 'HASH') {
4438: foreach my $key (keys(%{$settings->{$type}})) {
4439: if ($key eq 'namedusers') {
4440: $namedaccess{$type} = $settings->{$type}->{$key};
4441: } elsif ($key eq 'machines') {
4442: $machineaccess{$type} = $settings->{$type}->{$key};
4443: }
4444: }
4445: }
4446: }
4447: }
4448: }
1.81 raeburn 4449: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 4450: my $rownum = 0;
4451: my $css_class;
4452: foreach my $type (@pages) {
4453: $rownum ++;
4454: $css_class = $rownum%2?' class="LC_odd_row"':'';
4455: $datatable .= '<tr'.$css_class.'>'.
4456: '<td><span class="LC_nobreak">'.
4457: $titles->{$type}.'</span></td>'.
4458: '<td class="LC_left_item">'.
4459: '<input type="text" name="'.$type.'_namedusers" '.
4460: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
4461: '<td class="LC_right_item">'.
4462: '<span class="LC_nobreak">'.
4463: '<input type="text" name="'.$type.'_machines" '.
4464: 'value="'.$machineaccess{$type}.'" size="10" />'.
4465: '</td></tr>'."\n";
4466: }
4467: $$rowtotal += $rownum;
4468: return $datatable;
4469: }
4470:
4471: sub serverstatus_pages {
4472: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.189 raeburn 4473: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.156 raeburn 4474: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69 raeburn 4475: }
4476:
1.49 raeburn 4477: sub coursecategories_javascript {
4478: my ($settings) = @_;
1.57 raeburn 4479: my ($output,$jstext,$cathash);
1.49 raeburn 4480: if (ref($settings) eq 'HASH') {
1.57 raeburn 4481: $cathash = $settings->{'cats'};
4482: }
4483: if (ref($cathash) eq 'HASH') {
1.49 raeburn 4484: my (@cats,@jsarray,%idx);
1.57 raeburn 4485: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 4486: if (@jsarray > 0) {
4487: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
4488: for (my $i=0; $i<@jsarray; $i++) {
4489: if (ref($jsarray[$i]) eq 'ARRAY') {
4490: my $catstr = join('","',@{$jsarray[$i]});
4491: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
4492: }
4493: }
4494: }
4495: } else {
4496: $jstext = ' var categories = Array(1);'."\n".
4497: ' categories[0] = Array("instcode_pos");'."\n";
4498: }
1.120 raeburn 4499: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
4500: my $communities_reserved = &mt('The name: "communities" is a reserved category');
4501: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 4502: $output = <<"ENDSCRIPT";
4503: <script type="text/javascript">
1.109 raeburn 4504: // <![CDATA[
1.49 raeburn 4505: function reorderCats(form,parent,item,idx) {
4506: var changedVal;
4507: $jstext
4508: var newpos = 'addcategory_pos';
4509: var current = new Array;
4510: if (parent == '') {
4511: var has_instcode = 0;
4512: var maxtop = categories[idx].length;
4513: for (var j=0; j<maxtop; j++) {
4514: if (categories[idx][j] == 'instcode::0') {
4515: has_instcode == 1;
4516: }
4517: }
4518: if (has_instcode == 0) {
4519: categories[idx][maxtop] = 'instcode_pos';
4520: }
4521: } else {
4522: newpos += '_'+parent;
4523: }
4524: var maxh = 1 + categories[idx].length;
4525: var current = new Array;
4526: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4527: if (item == newpos) {
4528: changedVal = newitemVal;
4529: } else {
4530: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4531: current[newitemVal] = newpos;
4532: }
4533: for (var i=0; i<categories[idx].length; i++) {
4534: var elementName = categories[idx][i];
4535: if (elementName != item) {
4536: if (form.elements[elementName]) {
4537: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4538: current[currVal] = elementName;
4539: }
4540: }
4541: }
4542: var oldVal;
4543: for (var j=0; j<maxh; j++) {
4544: if (current[j] == undefined) {
4545: oldVal = j;
4546: }
4547: }
4548: if (oldVal < changedVal) {
4549: for (var k=oldVal+1; k<=changedVal ; k++) {
4550: var elementName = current[k];
4551: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4552: }
4553: } else {
4554: for (var k=changedVal; k<oldVal; k++) {
4555: var elementName = current[k];
4556: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4557: }
4558: }
4559: return;
4560: }
1.120 raeburn 4561:
4562: function categoryCheck(form) {
4563: if (form.elements['addcategory_name'].value == 'instcode') {
4564: alert('$instcode_reserved\\n$choose_again');
4565: return false;
4566: }
4567: if (form.elements['addcategory_name'].value == 'communities') {
4568: alert('$communities_reserved\\n$choose_again');
4569: return false;
4570: }
4571: return true;
4572: }
4573:
1.109 raeburn 4574: // ]]>
1.49 raeburn 4575: </script>
4576:
4577: ENDSCRIPT
4578: return $output;
4579: }
4580:
1.48 raeburn 4581: sub initialize_categories {
4582: my ($itemcount) = @_;
1.120 raeburn 4583: my ($datatable,$css_class,$chgstr);
4584: my %default_names = (
4585: instcode => 'Official courses (with institutional codes)',
4586: communities => 'Communities',
4587: );
4588: my $select0 = ' selected="selected"';
4589: my $select1 = '';
4590: foreach my $default ('instcode','communities') {
4591: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4592: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
4593: if ($default eq 'communities') {
4594: $select1 = $select0;
4595: $select0 = '';
4596: }
4597: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4598: .'<select name="'.$default.'_pos">'
4599: .'<option value="0"'.$select0.'>1</option>'
4600: .'<option value="1"'.$select1.'>2</option>'
4601: .'<option value="2">3</option></select> '
4602: .$default_names{$default}
4603: .'</span></td><td><span class="LC_nobreak">'
4604: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4605: .&mt('Display').'</label> <label>'
4606: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 4607: .'</label></span></td></tr>';
1.120 raeburn 4608: $itemcount ++;
4609: }
1.48 raeburn 4610: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 4611: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 4612: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 4613: .'<select name="addcategory_pos"'.$chgstr.'>'
4614: .'<option value="0">1</option>'
4615: .'<option value="1">2</option>'
4616: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 4617: .&mt('Add category').'</td><td>'.&mt('Name:')
4618: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4619: return $datatable;
4620: }
4621:
4622: sub build_category_rows {
1.49 raeburn 4623: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4624: my ($text,$name,$item,$chgstr);
1.48 raeburn 4625: if (ref($cats) eq 'ARRAY') {
4626: my $maxdepth = scalar(@{$cats});
4627: if (ref($cats->[$depth]) eq 'HASH') {
4628: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4629: my $numchildren = @{$cats->[$depth]{$parent}};
4630: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 4631: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 4632: my ($idxnum,$parent_name,$parent_item);
4633: my $higher = $depth - 1;
4634: if ($higher == 0) {
4635: $parent_name = &escape($parent).'::'.$higher;
4636: } else {
4637: if (ref($path) eq 'ARRAY') {
4638: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4639: }
4640: }
4641: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4642: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4643: if ($j < $numchildren) {
1.48 raeburn 4644: $name = $cats->[$depth]{$parent}[$j];
4645: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4646: $idxnum = $idx->{$item};
4647: } else {
4648: $name = $parent_name;
4649: $item = $parent_item;
1.48 raeburn 4650: }
1.49 raeburn 4651: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4652: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4653: for (my $i=0; $i<=$numchildren; $i++) {
4654: my $vpos = $i+1;
4655: my $selstr;
4656: if ($j == $i) {
4657: $selstr = ' selected="selected" ';
4658: }
4659: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4660: }
4661: $text .= '</select> ';
4662: if ($j < $numchildren) {
4663: my $deeper = $depth+1;
4664: $text .= $name.' '
4665: .'<label><input type="checkbox" name="deletecategory" value="'
4666: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4667: if(ref($path) eq 'ARRAY') {
4668: push(@{$path},$name);
1.49 raeburn 4669: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4670: pop(@{$path});
4671: }
4672: } else {
1.59 bisitz 4673: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4674: if ($j == $numchildren) {
4675: $text .= $name;
4676: } else {
4677: $text .= $item;
4678: }
4679: $text .= '" value="" />';
4680: }
4681: $text .= '</td></tr>';
4682: }
4683: $text .= '</table></td>';
4684: } else {
4685: my $higher = $depth-1;
4686: if ($higher == 0) {
4687: $name = &escape($parent).'::'.$higher;
4688: } else {
4689: if (ref($path) eq 'ARRAY') {
4690: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4691: }
4692: }
4693: my $colspan;
4694: if ($parent ne 'instcode') {
4695: $colspan = $maxdepth - $depth - 1;
4696: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4697: }
4698: }
4699: }
4700: }
4701: return $text;
4702: }
4703:
1.33 raeburn 4704: sub modifiable_userdata_row {
1.63 raeburn 4705: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 4706: my $rolename;
1.63 raeburn 4707: if ($context eq 'selfcreate') {
4708: if (ref($usertypes) eq 'HASH') {
4709: $rolename = $usertypes->{$role};
4710: } else {
4711: $rolename = $role;
4712: }
1.33 raeburn 4713: } else {
1.63 raeburn 4714: if ($role eq 'cr') {
4715: $rolename = &mt('Custom role');
4716: } else {
4717: $rolename = &Apache::lonnet::plaintext($role);
4718: }
1.33 raeburn 4719: }
4720: my @fields = ('lastname','firstname','middlename','generation',
4721: 'permanentemail','id');
4722: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4723: my $output;
4724: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4725: $output = '<tr '.$css_class.'>'.
4726: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4727: '<td class="LC_left_item" colspan="2"><table>';
4728: my $rem;
4729: my %checks;
4730: if (ref($settings) eq 'HASH') {
4731: if (ref($settings->{$context}) eq 'HASH') {
4732: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4733: foreach my $field (@fields) {
4734: if ($settings->{$context}->{$role}->{$field}) {
4735: $checks{$field} = ' checked="checked" ';
4736: }
4737: }
4738: }
4739: }
4740: }
4741: for (my $i=0; $i<@fields; $i++) {
4742: my $rem = $i%($numinrow);
4743: if ($rem == 0) {
4744: if ($i > 0) {
4745: $output .= '</tr>';
4746: }
4747: $output .= '<tr>';
4748: }
4749: my $check = ' ';
4750: if (exists($checks{$fields[$i]})) {
4751: $check = $checks{$fields[$i]}
4752: } else {
4753: if ($role eq 'st') {
4754: if (ref($settings) ne 'HASH') {
4755: $check = ' checked="checked" ';
4756: }
4757: }
4758: }
4759: $output .= '<td class="LC_left_item">'.
4760: '<span class="LC_nobreak"><label>'.
4761: '<input type="checkbox" name="canmodify_'.$role.'" '.
4762: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4763: '</label></span></td>';
4764: $rem = @fields%($numinrow);
4765: }
4766: my $colsleft = $numinrow - $rem;
4767: if ($colsleft > 1 ) {
4768: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4769: ' </td>';
4770: } elsif ($colsleft == 1) {
4771: $output .= '<td class="LC_left_item"> </td>';
4772: }
4773: $output .= '</tr></table></td></tr>';
4774: return $output;
4775: }
1.28 raeburn 4776:
1.93 raeburn 4777: sub insttypes_row {
4778: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
4779: my %lt = &Apache::lonlocal::texthash (
4780: cansearch => 'Users allowed to search',
4781: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4782: lockablenames => 'User preference to lock name',
1.93 raeburn 4783: );
4784: my $showdom;
4785: if ($context eq 'cansearch') {
4786: $showdom = ' ('.$dom.')';
4787: }
1.165 raeburn 4788: my $class = 'LC_left_item';
4789: if ($context eq 'statustocreate') {
4790: $class = 'LC_right_item';
4791: }
1.25 raeburn 4792: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 4793: '<td>'.$lt{$context}.$showdom.
1.165 raeburn 4794: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 4795: my $rem;
4796: if (ref($types) eq 'ARRAY') {
4797: for (my $i=0; $i<@{$types}; $i++) {
4798: if (defined($usertypes->{$types->[$i]})) {
4799: my $rem = $i%($numinrow);
4800: if ($rem == 0) {
4801: if ($i > 0) {
4802: $output .= '</tr>';
4803: }
4804: $output .= '<tr>';
1.23 raeburn 4805: }
1.26 raeburn 4806: my $check = ' ';
1.99 raeburn 4807: if (ref($settings) eq 'HASH') {
4808: if (ref($settings->{$context}) eq 'ARRAY') {
4809: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4810: $check = ' checked="checked" ';
4811: }
4812: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4813: $check = ' checked="checked" ';
4814: }
1.23 raeburn 4815: }
1.26 raeburn 4816: $output .= '<td class="LC_left_item">'.
4817: '<span class="LC_nobreak"><label>'.
1.93 raeburn 4818: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 4819: 'value="'.$types->[$i].'"'.$check.'/>'.
4820: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 4821: }
4822: }
1.26 raeburn 4823: $rem = @{$types}%($numinrow);
1.23 raeburn 4824: }
4825: my $colsleft = $numinrow - $rem;
1.131 raeburn 4826: if (($rem == 0) && (@{$types} > 0)) {
4827: $output .= '<tr>';
4828: }
1.23 raeburn 4829: if ($colsleft > 1) {
1.25 raeburn 4830: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 4831: } else {
1.25 raeburn 4832: $output .= '<td class="LC_left_item">';
1.23 raeburn 4833: }
4834: my $defcheck = ' ';
1.99 raeburn 4835: if (ref($settings) eq 'HASH') {
4836: if (ref($settings->{$context}) eq 'ARRAY') {
4837: if (grep(/^default$/,@{$settings->{$context}})) {
4838: $defcheck = ' checked="checked" ';
4839: }
4840: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4841: $defcheck = ' checked="checked" ';
4842: }
1.23 raeburn 4843: }
1.25 raeburn 4844: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 4845: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 4846: 'value="default"'.$defcheck.'/>'.
4847: $othertitle.'</label></span></td>'.
4848: '</tr></table></td></tr>';
4849: return $output;
1.23 raeburn 4850: }
4851:
4852: sub sorted_searchtitles {
4853: my %searchtitles = &Apache::lonlocal::texthash(
4854: 'uname' => 'username',
4855: 'lastname' => 'last name',
4856: 'lastfirst' => 'last name, first name',
4857: );
4858: my @titleorder = ('uname','lastname','lastfirst');
4859: return (\%searchtitles,\@titleorder);
4860: }
4861:
1.25 raeburn 4862: sub sorted_searchtypes {
4863: my %srchtypes_desc = (
4864: exact => 'is exact match',
4865: contains => 'contains ..',
4866: begins => 'begins with ..',
4867: );
4868: my @srchtypeorder = ('exact','begins','contains');
4869: return (\%srchtypes_desc,\@srchtypeorder);
4870: }
4871:
1.3 raeburn 4872: sub usertype_update_row {
4873: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
4874: my $datatable;
4875: my $numinrow = 4;
4876: foreach my $type (@{$types}) {
4877: if (defined($usertypes->{$type})) {
4878: $$rownums ++;
4879: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
4880: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
4881: '</td><td class="LC_left_item"><table>';
4882: for (my $i=0; $i<@{$fields}; $i++) {
4883: my $rem = $i%($numinrow);
4884: if ($rem == 0) {
4885: if ($i > 0) {
4886: $datatable .= '</tr>';
4887: }
4888: $datatable .= '<tr>';
4889: }
4890: my $check = ' ';
1.39 raeburn 4891: if (ref($settings) eq 'HASH') {
4892: if (ref($settings->{'fields'}) eq 'HASH') {
4893: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
4894: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
4895: $check = ' checked="checked" ';
4896: }
1.3 raeburn 4897: }
4898: }
4899: }
4900:
4901: if ($i == @{$fields}-1) {
4902: my $colsleft = $numinrow - $rem;
4903: if ($colsleft > 1) {
4904: $datatable .= '<td colspan="'.$colsleft.'">';
4905: } else {
4906: $datatable .= '<td>';
4907: }
4908: } else {
4909: $datatable .= '<td>';
4910: }
1.8 raeburn 4911: $datatable .= '<span class="LC_nobreak"><label>'.
4912: '<input type="checkbox" name="updateable_'.$type.
4913: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
4914: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 4915: }
4916: $datatable .= '</tr></table></td></tr>';
4917: }
4918: }
4919: return $datatable;
1.1 raeburn 4920: }
4921:
4922: sub modify_login {
1.205 raeburn 4923: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 4924: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
4925: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
4926: %title = ( coursecatalog => 'Display course catalog',
4927: adminmail => 'Display administrator E-mail address',
1.188 raeburn 4928: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 4929: newuser => 'Link for visitors to create a user account',
4930: loginheader => 'Log-in box header');
4931: @offon = ('off','on');
1.112 raeburn 4932: if (ref($domconfig{login}) eq 'HASH') {
4933: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
4934: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
4935: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
4936: }
4937: }
4938: }
1.9 raeburn 4939: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
4940: \%domconfig,\%loginhash);
1.188 raeburn 4941: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 4942: foreach my $item (@toggles) {
4943: $loginhash{login}{$item} = $env{'form.'.$item};
4944: }
1.41 raeburn 4945: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 4946: if (ref($colchanges{'login'}) eq 'HASH') {
4947: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
4948: \%loginhash);
4949: }
1.110 raeburn 4950:
1.149 raeburn 4951: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 4952: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 4953: if (keys(%servers) > 1) {
4954: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 4955: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
4956: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
4957: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
4958: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
4959: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
4960: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4961: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4962: $changes{'loginvia'}{$lonhost} = 1;
4963: } else {
4964: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
4965: $changes{'loginvia'}{$lonhost} = 1;
4966: }
4967: } else {
4968: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4969: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4970: $changes{'loginvia'}{$lonhost} = 1;
4971: }
4972: }
4973: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
4974: foreach my $item (@loginvia_attribs) {
4975: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
4976: }
4977: } else {
4978: foreach my $item (@loginvia_attribs) {
4979: my $new = $env{'form.'.$lonhost.'_'.$item};
4980: if (($item eq 'serverpath') && ($new eq 'custom')) {
4981: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
4982: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4983: $new = '/';
4984: }
4985: }
4986: if (($item eq 'custompath') &&
4987: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4988: $new = '';
4989: }
4990: if ($new ne $curr_loginvia{$lonhost}{$item}) {
4991: $changes{'loginvia'}{$lonhost} = 1;
4992: }
4993: if ($item eq 'exempt') {
4994: $new =~ s/^\s+//;
4995: $new =~ s/\s+$//;
4996: my @poss_ips = split(/\s*[,:]\s*/,$new);
4997: my @okips;
4998: foreach my $ip (@poss_ips) {
4999: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
5000: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
5001: push(@okips,$ip);
5002: }
5003: }
5004: }
5005: if (@okips > 0) {
5006: $new = join(',',@okips);
5007: } else {
5008: $new = '';
5009: }
5010: }
5011: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5012: }
5013: }
1.112 raeburn 5014: } else {
1.128 raeburn 5015: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5016: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 5017: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 5018: foreach my $item (@loginvia_attribs) {
5019: my $new = $env{'form.'.$lonhost.'_'.$item};
5020: if (($item eq 'serverpath') && ($new eq 'custom')) {
5021: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5022: $new = '/';
5023: }
5024: }
5025: if (($item eq 'custompath') &&
5026: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5027: $new = '';
5028: }
5029: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5030: }
1.110 raeburn 5031: }
5032: }
5033: }
5034: }
1.119 raeburn 5035:
1.168 raeburn 5036: my $servadm = $r->dir_config('lonAdmEMail');
5037: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
5038: if (ref($domconfig{'login'}) eq 'HASH') {
5039: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
5040: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
5041: if ($lang eq 'nolang') {
5042: push(@currlangs,$lang);
5043: } elsif (defined($langchoices{$lang})) {
5044: push(@currlangs,$lang);
5045: } else {
5046: next;
5047: }
5048: }
5049: }
5050: }
5051: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
5052: if (@currlangs > 0) {
5053: foreach my $lang (@currlangs) {
5054: if (grep(/^\Q$lang\E$/,@delurls)) {
5055: $changes{'helpurl'}{$lang} = 1;
5056: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
5057: $changes{'helpurl'}{$lang} = 1;
5058: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
5059: push(@newlangs,$lang);
5060: } else {
5061: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5062: }
5063: }
5064: }
5065: unless (grep(/^nolang$/,@currlangs)) {
5066: if ($env{'form.loginhelpurl_nolang.filename'}) {
5067: $changes{'helpurl'}{'nolang'} = 1;
5068: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
5069: push(@newlangs,'nolang');
5070: }
5071: }
5072: if ($env{'form.loginhelpurl_add_lang'}) {
5073: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
5074: ($env{'form.loginhelpurl_add_file.filename'})) {
5075: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
5076: $addedfile = $env{'form.loginhelpurl_add_lang'};
5077: }
5078: }
5079: if ((@newlangs > 0) || ($addedfile)) {
5080: my $error;
5081: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
5082: if ($configuserok eq 'ok') {
5083: if ($switchserver) {
5084: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
5085: } elsif ($author_ok eq 'ok') {
5086: my @allnew = @newlangs;
5087: if ($addedfile ne '') {
5088: push(@allnew,$addedfile);
5089: }
5090: foreach my $lang (@allnew) {
5091: my $formelem = 'loginhelpurl_'.$lang;
5092: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
5093: $formelem = 'loginhelpurl_add_file';
5094: }
5095: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
5096: "help/$lang",'','',$newfile{$lang});
5097: if ($result eq 'ok') {
5098: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
5099: $changes{'helpurl'}{$lang} = 1;
5100: } else {
5101: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
5102: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 5103: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 5104: (!grep(/^\Q$lang\E$/,@delurls))) {
5105:
5106: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5107: }
5108: }
5109: }
5110: } else {
5111: $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);
5112: }
5113: } else {
5114: $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);
5115: }
5116: if ($error) {
5117: &Apache::lonnet::logthis($error);
5118: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
5119: }
5120: }
1.169 raeburn 5121: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 5122:
5123: my $defaulthelpfile = '/adm/loginproblems.html';
5124: my $defaulttext = &mt('Default in use');
5125:
1.1 raeburn 5126: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
5127: $dom);
5128: if ($putresult eq 'ok') {
1.188 raeburn 5129: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5130: my %defaultchecked = (
5131: 'coursecatalog' => 'on',
1.188 raeburn 5132: 'helpdesk' => 'on',
1.42 raeburn 5133: 'adminmail' => 'off',
1.43 raeburn 5134: 'newuser' => 'off',
1.42 raeburn 5135: );
1.55 raeburn 5136: if (ref($domconfig{'login'}) eq 'HASH') {
5137: foreach my $item (@toggles) {
5138: if ($defaultchecked{$item} eq 'on') {
5139: if (($domconfig{'login'}{$item} eq '0') &&
5140: ($env{'form.'.$item} eq '1')) {
5141: $changes{$item} = 1;
5142: } elsif (($domconfig{'login'}{$item} eq '' ||
5143: $domconfig{'login'}{$item} eq '1') &&
5144: ($env{'form.'.$item} eq '0')) {
5145: $changes{$item} = 1;
5146: }
5147: } elsif ($defaultchecked{$item} eq 'off') {
5148: if (($domconfig{'login'}{$item} eq '1') &&
5149: ($env{'form.'.$item} eq '0')) {
5150: $changes{$item} = 1;
5151: } elsif (($domconfig{'login'}{$item} eq '' ||
5152: $domconfig{'login'}{$item} eq '0') &&
5153: ($env{'form.'.$item} eq '1')) {
5154: $changes{$item} = 1;
5155: }
1.42 raeburn 5156: }
5157: }
1.41 raeburn 5158: }
1.6 raeburn 5159: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 5160: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 5161: if (ref($lastactref) eq 'HASH') {
5162: $lastactref->{'domainconfig'} = 1;
5163: }
1.1 raeburn 5164: $resulttext = &mt('Changes made:').'<ul>';
5165: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 5166: if ($item eq 'loginvia') {
1.112 raeburn 5167: if (ref($changes{$item}) eq 'HASH') {
5168: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
5169: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 5170: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
5171: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
5172: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
5173: $protocol = 'http' if ($protocol ne 'https');
5174: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
5175:
5176: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
5177: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
5178: } else {
5179: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
5180: }
5181: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
5182: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
5183: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
5184: }
5185: $resulttext .= '</li>';
5186: } else {
5187: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
5188: }
1.112 raeburn 5189: } else {
1.128 raeburn 5190: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 5191: }
5192: }
1.128 raeburn 5193: $resulttext .= '</ul></li>';
1.112 raeburn 5194: }
1.168 raeburn 5195: } elsif ($item eq 'helpurl') {
5196: if (ref($changes{$item}) eq 'HASH') {
5197: foreach my $lang (sort(keys(%{$changes{$item}}))) {
5198: if (grep(/^\Q$lang\E$/,@delurls)) {
5199: my ($chg,$link);
5200: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
5201: if ($lang eq 'nolang') {
5202: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
5203: } else {
5204: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
5205: }
5206: $resulttext .= '<li>'.$chg.'</li>';
5207: } else {
5208: my $chg;
5209: if ($lang eq 'nolang') {
5210: $chg = &mt('custom log-in help file for no preferred language');
5211: } else {
5212: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
5213: }
5214: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
5215: $loginhash{'login'}{'helpurl'}{$lang}.
5216: '?inhibitmenu=yes',$chg,600,500).
5217: '</li>';
5218: }
5219: }
5220: }
1.169 raeburn 5221: } elsif ($item eq 'captcha') {
5222: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 5223: my $chgtxt;
1.169 raeburn 5224: if ($loginhash{'login'}{$item} eq 'notused') {
5225: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
5226: } else {
5227: my %captchas = &captcha_phrases();
5228: if ($captchas{$loginhash{'login'}{$item}}) {
5229: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
5230: } else {
5231: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
5232: }
5233: }
5234: $resulttext .= '<li>'.$chgtxt.'</li>';
5235: }
5236: } elsif ($item eq 'recaptchakeys') {
5237: if (ref($loginhash{'login'}) eq 'HASH') {
5238: my ($privkey,$pubkey);
5239: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
5240: $pubkey = $loginhash{'login'}{$item}{'public'};
5241: $privkey = $loginhash{'login'}{$item}{'private'};
5242: }
5243: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
5244: if (!$pubkey) {
5245: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
5246: } else {
5247: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
5248: }
5249: if (!$privkey) {
5250: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
5251: } else {
5252: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
5253: }
5254: $chgtxt .= '</ul>';
5255: $resulttext .= '<li>'.$chgtxt.'</li>';
5256: }
1.41 raeburn 5257: } else {
5258: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
5259: }
1.1 raeburn 5260: }
1.6 raeburn 5261: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 5262: } else {
5263: $resulttext = &mt('No changes made to log-in page settings');
5264: }
5265: } else {
1.11 albertel 5266: $resulttext = '<span class="LC_error">'.
5267: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5268: }
1.6 raeburn 5269: if ($errors) {
1.9 raeburn 5270: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 5271: $errors.'</ul>';
5272: }
5273: return $resulttext;
5274: }
5275:
5276: sub color_font_choices {
5277: my %choices =
5278: &Apache::lonlocal::texthash (
5279: img => "Header",
5280: bgs => "Background colors",
5281: links => "Link colors",
1.55 raeburn 5282: images => "Images",
1.6 raeburn 5283: font => "Font color",
1.201 raeburn 5284: fontmenu => "Font menu",
1.76 raeburn 5285: pgbg => "Page",
1.6 raeburn 5286: tabbg => "Header",
5287: sidebg => "Border",
5288: link => "Link",
5289: alink => "Active link",
5290: vlink => "Visited link",
5291: );
5292: return %choices;
5293: }
5294:
5295: sub modify_rolecolors {
1.205 raeburn 5296: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 5297: my ($resulttext,%rolehash);
5298: $rolehash{'rolecolors'} = {};
1.55 raeburn 5299: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
5300: if ($domconfig{'rolecolors'} eq '') {
5301: $domconfig{'rolecolors'} = {};
5302: }
5303: }
1.9 raeburn 5304: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 5305: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
5306: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
5307: $dom);
5308: if ($putresult eq 'ok') {
5309: if (keys(%changes) > 0) {
1.41 raeburn 5310: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 5311: if (ref($lastactref) eq 'HASH') {
5312: $lastactref->{'domainconfig'} = 1;
5313: }
1.6 raeburn 5314: $resulttext = &display_colorchgs($dom,\%changes,$roles,
5315: $rolehash{'rolecolors'});
5316: } else {
5317: $resulttext = &mt('No changes made to default color schemes');
5318: }
5319: } else {
1.11 albertel 5320: $resulttext = '<span class="LC_error">'.
5321: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 5322: }
5323: if ($errors) {
5324: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5325: $errors.'</ul>';
5326: }
5327: return $resulttext;
5328: }
5329:
5330: sub modify_colors {
1.9 raeburn 5331: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 5332: my (%changes,%choices);
1.51 raeburn 5333: my @bgs;
1.6 raeburn 5334: my @links = ('link','alink','vlink');
1.41 raeburn 5335: my @logintext;
1.6 raeburn 5336: my @images;
5337: my $servadm = $r->dir_config('lonAdmEMail');
5338: my $errors;
1.200 raeburn 5339: my %defaults;
1.6 raeburn 5340: foreach my $role (@{$roles}) {
5341: if ($role eq 'login') {
1.12 raeburn 5342: %choices = &login_choices();
1.41 raeburn 5343: @logintext = ('textcol','bgcol');
1.12 raeburn 5344: } else {
5345: %choices = &color_font_choices();
5346: }
5347: if ($role eq 'login') {
1.41 raeburn 5348: @images = ('img','logo','domlogo','login');
1.51 raeburn 5349: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 5350: } else {
5351: @images = ('img');
1.200 raeburn 5352: @bgs = ('pgbg','tabbg','sidebg');
5353: }
5354: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
5355: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
5356: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
5357: }
5358: if ($role eq 'login') {
5359: foreach my $item (@logintext) {
5360: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'logintext'}{$item}) {
5361: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5362: }
5363: }
5364: } else {
5365: unless($env{'form.'.$role.'_fontmenu'} eq $defaults{'fontmenu'}) {
5366: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
5367: }
1.6 raeburn 5368: }
1.200 raeburn 5369: foreach my $item (@bgs) {
5370: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'bgs'}{$item} ) {
5371: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5372: }
5373: }
5374: foreach my $item (@links) {
5375: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'links'}{$item}) {
5376: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5377: }
1.6 raeburn 5378: }
1.46 raeburn 5379: my ($configuserok,$author_ok,$switchserver) =
5380: &config_check($dom,$confname,$servadm);
1.9 raeburn 5381: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 5382: if (ref($domconfig->{$role}) ne 'HASH') {
5383: $domconfig->{$role} = {};
5384: }
1.8 raeburn 5385: foreach my $img (@images) {
1.70 raeburn 5386: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
5387: if (defined($env{'form.login_showlogo_'.$img})) {
5388: $confhash->{$role}{'showlogo'}{$img} = 1;
5389: } else {
5390: $confhash->{$role}{'showlogo'}{$img} = 0;
5391: }
5392: }
1.18 albertel 5393: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
5394: && !defined($domconfig->{$role}{$img})
5395: && !$env{'form.'.$role.'_del_'.$img}
5396: && $env{'form.'.$role.'_import_'.$img}) {
5397: # import the old configured image from the .tab setting
5398: # if they haven't provided a new one
5399: $domconfig->{$role}{$img} =
5400: $env{'form.'.$role.'_import_'.$img};
5401: }
1.6 raeburn 5402: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 5403: my $error;
1.6 raeburn 5404: if ($configuserok eq 'ok') {
1.9 raeburn 5405: if ($switchserver) {
1.12 raeburn 5406: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 5407: } else {
5408: if ($author_ok eq 'ok') {
5409: my ($result,$logourl) =
5410: &publishlogo($r,'upload',$role.'_'.$img,
5411: $dom,$confname,$img,$width,$height);
5412: if ($result eq 'ok') {
5413: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 5414: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5415: } else {
1.12 raeburn 5416: $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 5417: }
5418: } else {
1.46 raeburn 5419: $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 5420: }
5421: }
5422: } else {
1.46 raeburn 5423: $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 5424: }
5425: if ($error) {
1.8 raeburn 5426: &Apache::lonnet::logthis($error);
1.11 albertel 5427: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 5428: }
5429: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 5430: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
5431: my $error;
5432: if ($configuserok eq 'ok') {
5433: # is confname an author?
5434: if ($switchserver eq '') {
5435: if ($author_ok eq 'ok') {
5436: my ($result,$logourl) =
5437: &publishlogo($r,'copy',$domconfig->{$role}{$img},
5438: $dom,$confname,$img,$width,$height);
5439: if ($result eq 'ok') {
5440: $confhash->{$role}{$img} = $logourl;
1.18 albertel 5441: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5442: }
5443: }
5444: }
5445: }
1.6 raeburn 5446: }
5447: }
5448: }
5449: if (ref($domconfig) eq 'HASH') {
5450: if (ref($domconfig->{$role}) eq 'HASH') {
5451: foreach my $img (@images) {
5452: if ($domconfig->{$role}{$img} ne '') {
5453: if ($env{'form.'.$role.'_del_'.$img}) {
5454: $confhash->{$role}{$img} = '';
1.12 raeburn 5455: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5456: } else {
1.9 raeburn 5457: if ($confhash->{$role}{$img} eq '') {
5458: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
5459: }
1.6 raeburn 5460: }
5461: } else {
5462: if ($env{'form.'.$role.'_del_'.$img}) {
5463: $confhash->{$role}{$img} = '';
1.12 raeburn 5464: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5465: }
5466: }
1.70 raeburn 5467: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
5468: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
5469: if ($confhash->{$role}{'showlogo'}{$img} ne
5470: $domconfig->{$role}{'showlogo'}{$img}) {
5471: $changes{$role}{'showlogo'}{$img} = 1;
5472: }
5473: } else {
5474: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5475: $changes{$role}{'showlogo'}{$img} = 1;
5476: }
5477: }
5478: }
5479: }
1.6 raeburn 5480: if ($domconfig->{$role}{'font'} ne '') {
5481: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
5482: $changes{$role}{'font'} = 1;
5483: }
5484: } else {
5485: if ($confhash->{$role}{'font'}) {
5486: $changes{$role}{'font'} = 1;
5487: }
5488: }
1.107 raeburn 5489: if ($role ne 'login') {
5490: if ($domconfig->{$role}{'fontmenu'} ne '') {
5491: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
5492: $changes{$role}{'fontmenu'} = 1;
5493: }
5494: } else {
5495: if ($confhash->{$role}{'fontmenu'}) {
5496: $changes{$role}{'fontmenu'} = 1;
5497: }
1.97 tempelho 5498: }
5499: }
1.6 raeburn 5500: foreach my $item (@bgs) {
5501: if ($domconfig->{$role}{$item} ne '') {
5502: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5503: $changes{$role}{'bgs'}{$item} = 1;
5504: }
5505: } else {
5506: if ($confhash->{$role}{$item}) {
5507: $changes{$role}{'bgs'}{$item} = 1;
5508: }
5509: }
5510: }
5511: foreach my $item (@links) {
5512: if ($domconfig->{$role}{$item} ne '') {
5513: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5514: $changes{$role}{'links'}{$item} = 1;
5515: }
5516: } else {
5517: if ($confhash->{$role}{$item}) {
5518: $changes{$role}{'links'}{$item} = 1;
5519: }
5520: }
5521: }
1.41 raeburn 5522: foreach my $item (@logintext) {
5523: if ($domconfig->{$role}{$item} ne '') {
5524: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5525: $changes{$role}{'logintext'}{$item} = 1;
5526: }
5527: } else {
5528: if ($confhash->{$role}{$item}) {
5529: $changes{$role}{'logintext'}{$item} = 1;
5530: }
5531: }
5532: }
1.6 raeburn 5533: } else {
5534: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5535: \@logintext,$confhash,\%changes);
1.6 raeburn 5536: }
5537: } else {
5538: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5539: \@logintext,$confhash,\%changes);
1.6 raeburn 5540: }
5541: }
5542: return ($errors,%changes);
5543: }
5544:
1.46 raeburn 5545: sub config_check {
5546: my ($dom,$confname,$servadm) = @_;
5547: my ($configuserok,$author_ok,$switchserver,%currroles);
5548: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
5549: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
5550: $confname,$servadm);
5551: if ($configuserok eq 'ok') {
5552: $switchserver = &check_switchserver($dom,$confname);
5553: if ($switchserver eq '') {
5554: $author_ok = &check_authorstatus($dom,$confname,%currroles);
5555: }
5556: }
5557: return ($configuserok,$author_ok,$switchserver);
5558: }
5559:
1.6 raeburn 5560: sub default_change_checker {
1.41 raeburn 5561: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 5562: foreach my $item (@{$links}) {
5563: if ($confhash->{$role}{$item}) {
5564: $changes->{$role}{'links'}{$item} = 1;
5565: }
5566: }
5567: foreach my $item (@{$bgs}) {
5568: if ($confhash->{$role}{$item}) {
5569: $changes->{$role}{'bgs'}{$item} = 1;
5570: }
5571: }
1.41 raeburn 5572: foreach my $item (@{$logintext}) {
5573: if ($confhash->{$role}{$item}) {
5574: $changes->{$role}{'logintext'}{$item} = 1;
5575: }
5576: }
1.6 raeburn 5577: foreach my $img (@{$images}) {
5578: if ($env{'form.'.$role.'_del_'.$img}) {
5579: $confhash->{$role}{$img} = '';
1.12 raeburn 5580: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 5581: }
1.70 raeburn 5582: if ($role eq 'login') {
5583: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5584: $changes->{$role}{'showlogo'}{$img} = 1;
5585: }
5586: }
1.6 raeburn 5587: }
5588: if ($confhash->{$role}{'font'}) {
5589: $changes->{$role}{'font'} = 1;
5590: }
1.48 raeburn 5591: }
1.6 raeburn 5592:
5593: sub display_colorchgs {
5594: my ($dom,$changes,$roles,$confhash) = @_;
5595: my (%choices,$resulttext);
5596: if (!grep(/^login$/,@{$roles})) {
5597: $resulttext = &mt('Changes made:').'<br />';
5598: }
5599: foreach my $role (@{$roles}) {
5600: if ($role eq 'login') {
5601: %choices = &login_choices();
5602: } else {
5603: %choices = &color_font_choices();
5604: }
5605: if (ref($changes->{$role}) eq 'HASH') {
5606: if ($role ne 'login') {
5607: $resulttext .= '<h4>'.&mt($role).'</h4>';
5608: }
5609: foreach my $key (sort(keys(%{$changes->{$role}}))) {
5610: if ($role ne 'login') {
5611: $resulttext .= '<ul>';
5612: }
5613: if (ref($changes->{$role}{$key}) eq 'HASH') {
5614: if ($role ne 'login') {
5615: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
5616: }
5617: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 5618: if (($role eq 'login') && ($key eq 'showlogo')) {
5619: if ($confhash->{$role}{$key}{$item}) {
5620: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
5621: } else {
5622: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
5623: }
5624: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 5625: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
5626: } else {
1.12 raeburn 5627: my $newitem = $confhash->{$role}{$item};
5628: if ($key eq 'images') {
5629: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
5630: }
5631: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 5632: }
5633: }
5634: if ($role ne 'login') {
5635: $resulttext .= '</ul></li>';
5636: }
5637: } else {
5638: if ($confhash->{$role}{$key} eq '') {
5639: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
5640: } else {
5641: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
5642: }
5643: }
5644: if ($role ne 'login') {
5645: $resulttext .= '</ul>';
5646: }
5647: }
5648: }
5649: }
1.3 raeburn 5650: return $resulttext;
1.1 raeburn 5651: }
5652:
1.9 raeburn 5653: sub thumb_dimensions {
5654: return ('200','50');
5655: }
5656:
1.16 raeburn 5657: sub check_dimensions {
5658: my ($inputfile) = @_;
5659: my ($fullwidth,$fullheight);
5660: if ($inputfile =~ m|^[/\w.\-]+$|) {
5661: if (open(PIPE,"identify $inputfile 2>&1 |")) {
5662: my $imageinfo = <PIPE>;
5663: if (!close(PIPE)) {
5664: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
5665: }
5666: chomp($imageinfo);
5667: my ($fullsize) =
1.21 raeburn 5668: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 5669: if ($fullsize) {
5670: ($fullwidth,$fullheight) = split(/x/,$fullsize);
5671: }
5672: }
5673: }
5674: return ($fullwidth,$fullheight);
5675: }
5676:
1.9 raeburn 5677: sub check_configuser {
5678: my ($uhome,$dom,$confname,$servadm) = @_;
5679: my ($configuserok,%currroles);
5680: if ($uhome eq 'no_host') {
5681: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
5682: my $configpass = &LONCAPA::Enrollment::create_password();
5683: $configuserok =
5684: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
5685: $configpass,'','','','','',undef,$servadm);
5686: } else {
5687: $configuserok = 'ok';
5688: %currroles =
5689: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
5690: }
5691: return ($configuserok,%currroles);
5692: }
5693:
5694: sub check_authorstatus {
5695: my ($dom,$confname,%currroles) = @_;
5696: my $author_ok;
1.40 raeburn 5697: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 5698: my $start = time;
5699: my $end = 0;
5700: $author_ok =
5701: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 5702: 'au',$end,$start,'','','domconfig');
1.9 raeburn 5703: } else {
5704: $author_ok = 'ok';
5705: }
5706: return $author_ok;
5707: }
5708:
5709: sub publishlogo {
1.46 raeburn 5710: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 5711: my ($output,$fname,$logourl);
5712: if ($action eq 'upload') {
5713: $fname=$env{'form.'.$formname.'.filename'};
5714: chop($env{'form.'.$formname});
5715: } else {
5716: ($fname) = ($formname =~ /([^\/]+)$/);
5717: }
1.46 raeburn 5718: if ($savefileas ne '') {
5719: $fname = $savefileas;
5720: }
1.9 raeburn 5721: $fname=&Apache::lonnet::clean_filename($fname);
5722: # See if there is anything left
5723: unless ($fname) { return ('error: no uploaded file'); }
5724: $fname="$subdir/$fname";
1.210 raeburn 5725: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 5726: my $filepath="$docroot/priv";
5727: my $relpath = "$dom/$confname";
1.9 raeburn 5728: my ($fnamepath,$file,$fetchthumb);
5729: $file=$fname;
5730: if ($fname=~m|/|) {
5731: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
5732: }
1.164 raeburn 5733: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 5734: my $count;
1.164 raeburn 5735: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 5736: $filepath.="/$parts[$count]";
5737: if ((-e $filepath)!=1) {
5738: mkdir($filepath,02770);
5739: }
5740: }
5741: # Check for bad extension and disallow upload
5742: if ($file=~/\.(\w+)$/ &&
5743: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
5744: $output =
1.207 bisitz 5745: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 5746: } elsif ($file=~/\.(\w+)$/ &&
5747: !defined(&Apache::loncommon::fileembstyle($1))) {
5748: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
5749: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 5750: $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 5751: } elsif (-d "$filepath/$file") {
1.195 bisitz 5752: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 5753: } else {
5754: my $source = $filepath.'/'.$file;
5755: my $logfile;
5756: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 5757: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 5758: }
5759: print $logfile
5760: "\n================= Publish ".localtime()." ================\n".
5761: $env{'user.name'}.':'.$env{'user.domain'}."\n";
5762: # Save the file
5763: if (!open(FH,'>'.$source)) {
5764: &Apache::lonnet::logthis('Failed to create '.$source);
5765: return (&mt('Failed to create file'));
5766: }
5767: if ($action eq 'upload') {
5768: if (!print FH ($env{'form.'.$formname})) {
5769: &Apache::lonnet::logthis('Failed to write to '.$source);
5770: return (&mt('Failed to write file'));
5771: }
5772: } else {
5773: my $original = &Apache::lonnet::filelocation('',$formname);
5774: if(!copy($original,$source)) {
5775: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
5776: return (&mt('Failed to write file'));
5777: }
5778: }
5779: close(FH);
5780: chmod(0660, $source); # Permissions to rw-rw---.
5781:
5782: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
5783: my $copyfile=$targetdir.'/'.$file;
5784:
5785: my @parts=split(/\//,$targetdir);
5786: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
5787: for (my $count=5;$count<=$#parts;$count++) {
5788: $path.="/$parts[$count]";
5789: if (!-e $path) {
5790: print $logfile "\nCreating directory ".$path;
5791: mkdir($path,02770);
5792: }
5793: }
5794: my $versionresult;
5795: if (-e $copyfile) {
5796: $versionresult = &logo_versioning($targetdir,$file,$logfile);
5797: } else {
5798: $versionresult = 'ok';
5799: }
5800: if ($versionresult eq 'ok') {
5801: if (copy($source,$copyfile)) {
5802: print $logfile "\nCopied original source to ".$copyfile."\n";
5803: $output = 'ok';
5804: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 5805: push(@{$modified_urls},[$copyfile,$source]);
5806: my $metaoutput =
5807: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
5808: unless ($registered_cleanup) {
5809: my $handlers = $r->get_handlers('PerlCleanupHandler');
5810: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5811: $registered_cleanup=1;
5812: }
1.9 raeburn 5813: } else {
5814: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
5815: $output = &mt('Failed to copy file to RES space').", $!";
5816: }
5817: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5818: my $inputfile = $filepath.'/'.$file;
5819: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 5820: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5821: if ($fullwidth ne '' && $fullheight ne '') {
5822: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5823: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5824: system("convert -sample $thumbsize $inputfile $outfile");
5825: chmod(0660, $filepath.'/tn-'.$file);
5826: if (-e $outfile) {
5827: my $copyfile=$targetdir.'/tn-'.$file;
5828: if (copy($outfile,$copyfile)) {
5829: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 5830: my $thumb_metaoutput =
5831: &write_metadata($dom,$confname,$formname,
5832: $targetdir,'tn-'.$file,$logfile);
5833: push(@{$modified_urls},[$copyfile,$outfile]);
5834: unless ($registered_cleanup) {
5835: my $handlers = $r->get_handlers('PerlCleanupHandler');
5836: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5837: $registered_cleanup=1;
5838: }
1.16 raeburn 5839: } else {
5840: print $logfile "\nUnable to write ".$copyfile.
5841: ':'.$!."\n";
5842: }
5843: }
1.9 raeburn 5844: }
5845: }
5846: }
5847: } else {
5848: $output = $versionresult;
5849: }
5850: }
5851: return ($output,$logourl);
5852: }
5853:
5854: sub logo_versioning {
5855: my ($targetdir,$file,$logfile) = @_;
5856: my $target = $targetdir.'/'.$file;
5857: my ($maxversion,$fn,$extn,$output);
5858: $maxversion = 0;
5859: if ($file =~ /^(.+)\.(\w+)$/) {
5860: $fn=$1;
5861: $extn=$2;
5862: }
5863: opendir(DIR,$targetdir);
5864: while (my $filename=readdir(DIR)) {
5865: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
5866: $maxversion=($1>$maxversion)?$1:$maxversion;
5867: }
5868: }
5869: $maxversion++;
5870: print $logfile "\nCreating old version ".$maxversion."\n";
5871: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
5872: if (copy($target,$copyfile)) {
5873: print $logfile "Copied old target to ".$copyfile."\n";
5874: $copyfile=$copyfile.'.meta';
5875: if (copy($target.'.meta',$copyfile)) {
5876: print $logfile "Copied old target metadata to ".$copyfile."\n";
5877: $output = 'ok';
5878: } else {
5879: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
5880: $output = &mt('Failed to copy old meta').", $!, ";
5881: }
5882: } else {
5883: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
5884: $output = &mt('Failed to copy old target').", $!, ";
5885: }
5886: return $output;
5887: }
5888:
5889: sub write_metadata {
5890: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
5891: my (%metadatafields,%metadatakeys,$output);
5892: $metadatafields{'title'}=$formname;
5893: $metadatafields{'creationdate'}=time;
5894: $metadatafields{'lastrevisiondate'}=time;
5895: $metadatafields{'copyright'}='public';
5896: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
5897: $env{'user.domain'};
5898: $metadatafields{'authorspace'}=$confname.':'.$dom;
5899: $metadatafields{'domain'}=$dom;
5900: {
5901: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
5902: my $mfh;
1.155 raeburn 5903: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 5904: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 5905: unless ($_=~/\./) {
5906: my $unikey=$_;
5907: $unikey=~/^([A-Za-z]+)/;
5908: my $tag=$1;
5909: $tag=~tr/A-Z/a-z/;
5910: print $mfh "\n\<$tag";
5911: foreach (split(/\,/,$metadatakeys{$unikey})) {
5912: my $value=$metadatafields{$unikey.'.'.$_};
5913: $value=~s/\"/\'\'/g;
5914: print $mfh ' '.$_.'="'.$value.'"';
5915: }
5916: print $mfh '>'.
5917: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
5918: .'</'.$tag.'>';
5919: }
5920: }
5921: $output = 'ok';
5922: print $logfile "\nWrote metadata";
5923: close($mfh);
5924: } else {
5925: print $logfile "\nFailed to open metadata file";
1.9 raeburn 5926: $output = &mt('Could not write metadata');
5927: }
5928: }
1.155 raeburn 5929: return $output;
5930: }
5931:
5932: sub notifysubscribed {
5933: foreach my $targetsource (@{$modified_urls}){
5934: next unless (ref($targetsource) eq 'ARRAY');
5935: my ($target,$source)=@{$targetsource};
5936: if ($source ne '') {
5937: if (open(my $logfh,'>>'.$source.'.log')) {
5938: print $logfh "\nCleanup phase: Notifications\n";
5939: my @subscribed=&subscribed_hosts($target);
5940: foreach my $subhost (@subscribed) {
5941: print $logfh "\nNotifying host ".$subhost.':';
5942: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
5943: print $logfh $reply;
5944: }
5945: my @subscribedmeta=&subscribed_hosts("$target.meta");
5946: foreach my $subhost (@subscribedmeta) {
5947: print $logfh "\nNotifying host for metadata only ".$subhost.':';
5948: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
5949: $subhost);
5950: print $logfh $reply;
5951: }
5952: print $logfh "\n============ Done ============\n";
1.160 raeburn 5953: close($logfh);
1.155 raeburn 5954: }
5955: }
5956: }
5957: return OK;
5958: }
5959:
5960: sub subscribed_hosts {
5961: my ($target) = @_;
5962: my @subscribed;
5963: if (open(my $fh,"<$target.subscription")) {
5964: while (my $subline=<$fh>) {
5965: if ($subline =~ /^($match_lonid):/) {
5966: my $host = $1;
5967: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
5968: unless (grep(/^\Q$host\E$/,@subscribed)) {
5969: push(@subscribed,$host);
5970: }
5971: }
5972: }
5973: }
5974: }
5975: return @subscribed;
1.9 raeburn 5976: }
5977:
5978: sub check_switchserver {
5979: my ($dom,$confname) = @_;
5980: my ($allowed,$switchserver);
5981: my $home = &Apache::lonnet::homeserver($confname,$dom);
5982: if ($home eq 'no_host') {
5983: $home = &Apache::lonnet::domain($dom,'primary');
5984: }
5985: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 5986: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
5987: if (!$allowed) {
1.180 raeburn 5988: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 5989: }
5990: return $switchserver;
5991: }
5992:
1.1 raeburn 5993: sub modify_quotas {
1.216 ! raeburn 5994: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 5995: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 ! raeburn 5996: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
! 5997: $author_ok,$switchserver,$errors);
1.86 raeburn 5998: if ($action eq 'quotas') {
5999: $context = 'tools';
1.163 raeburn 6000: } else {
1.86 raeburn 6001: $context = $action;
6002: }
6003: if ($context eq 'requestcourses') {
1.216 ! raeburn 6004: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 6005: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 6006: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
6007: %titles = &courserequest_titles();
6008: $toolregexp = join('|',@usertools);
6009: %conditions = &courserequest_conditions();
1.216 ! raeburn 6010: $confname = $dom.'-domainconfig';
! 6011: my $servadm = $r->dir_config('lonAdmEMail');
! 6012: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.163 raeburn 6013: } elsif ($context eq 'requestauthor') {
6014: @usertools = ('author');
6015: %titles = &authorrequest_titles();
1.86 raeburn 6016: } else {
1.162 raeburn 6017: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 6018: %titles = &tool_titles();
1.86 raeburn 6019: }
1.212 raeburn 6020: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 6021: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6022: foreach my $key (keys(%env)) {
1.101 raeburn 6023: if ($context eq 'requestcourses') {
6024: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
6025: my $item = $1;
6026: my $type = $2;
6027: if ($type =~ /^limit_(.+)/) {
6028: $limithash{$item}{$1} = $env{$key};
6029: } else {
6030: $confhash{$item}{$type} = $env{$key};
6031: }
6032: }
1.163 raeburn 6033: } elsif ($context eq 'requestauthor') {
6034: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
6035: $confhash{$1} = $env{$key};
6036: }
1.101 raeburn 6037: } else {
1.86 raeburn 6038: if ($key =~ /^form\.quota_(.+)$/) {
6039: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 6040: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
6041: $confhash{'authorquota'}{$1} = $env{$key};
6042: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 6043: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
6044: }
1.72 raeburn 6045: }
6046: }
1.163 raeburn 6047: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.102 raeburn 6048: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
6049: @approvalnotify = sort(@approvalnotify);
6050: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.216 ! raeburn 6051: if ($env{'form.uniquecode'}) {
! 6052: $confhash{'uniquecode'} = 1;
! 6053: } else {
! 6054: $confhash{'uniquecode'} = '';
! 6055: }
! 6056: my ($newbook,@allpos);
! 6057: if ($context eq 'requestcourses') {
! 6058: if ($env{'form.addbook'}) {
! 6059: if (($env{'form.addbook_cnum'} =~ /^$match_courseid$/) &&
! 6060: ($env{'form.addbook_cdom'} =~ /^$match_domain$/)) {
! 6061: if (&Apache::lonnet::homeserver($env{'form.addbook_cnum'},
! 6062: $env{'form.addbook_cdom'}) eq 'no_host') {
! 6063: $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
! 6064: '</span></li>';
! 6065: } else {
! 6066: $newbook = $env{'form.addbook_cdom'}.'_'.$env{'form.addbook_cnum'};
! 6067: my $position = $env{'form.addbook_pos'};
! 6068: $position =~ s/\D+//g;
! 6069: if ($position ne '') {
! 6070: $allpos[$position] = $newbook;
! 6071: }
! 6072: }
! 6073: } else {
! 6074: $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
! 6075: '</span></li>';
! 6076: }
! 6077: }
! 6078: }
1.102 raeburn 6079: if (ref($domconfig{$action}) eq 'HASH') {
6080: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
6081: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
6082: $changes{'notify'}{'approval'} = 1;
6083: }
6084: } else {
1.144 raeburn 6085: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6086: $changes{'notify'}{'approval'} = 1;
6087: }
6088: }
1.216 ! raeburn 6089: if ($domconfig{$action}{'uniquecode'}) {
! 6090: unless ($confhash{'uniquecode'}) {
! 6091: $changes{'uniquecode'} = 1;
! 6092: }
! 6093: } else {
! 6094: if ($confhash{'uniquecode'}) {
! 6095: $changes{'uniquecode'} = 1;
! 6096: }
! 6097: }
! 6098: if ($context eq 'requestcourses') {
! 6099: if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
! 6100: my %deletions;
! 6101: my @todelete = &Apache::loncommon::get_env_multiple('form.book_del');
! 6102: if (@todelete) {
! 6103: map { $deletions{$_} = 1; } @todelete;
! 6104: }
! 6105: my %imgdeletions;
! 6106: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.book_image_del');
! 6107: if (@todeleteimages) {
! 6108: map { $imgdeletions{$_} = 1; } @todeleteimages;
! 6109: }
! 6110: my $maxnum = $env{'form.book_maxnum'};
! 6111: for (my $i=0; $i<=$maxnum; $i++) {
! 6112: my $key = $env{'form.book_id_'.$i};
! 6113: if (ref($domconfig{$action}{'textbooks'}{$key}) eq 'HASH') {
! 6114: if ($deletions{$key}) {
! 6115: if ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
! 6116: #FIXME need to obsolete item in RES space
! 6117: }
! 6118: next;
! 6119: } else {
! 6120: my $newpos = $env{'form.'.$key};
! 6121: $newpos =~ s/\D+//g;
! 6122: foreach my $item ('subject','title','author') {
! 6123: $confhash{'textbooks'}{$key}{$item} = $env{'form.book_'.$item.'_'.$i};
! 6124: if ($domconfig{$action}{'textbooks'}{$key}{$item} ne $confhash{'textbooks'}{$key}{$item}) {
! 6125: $changes{'textbooks'}{$key} = 1;
! 6126: }
! 6127: }
! 6128: $allpos[$newpos] = $key;
! 6129: }
! 6130: if ($imgdeletions{$key}) {
! 6131: $changes{'textbooks'}{$key} = 1;
! 6132: #FIXME need to obsolete item in RES space
! 6133: } elsif ($env{'form.book_image_'.$i.'.filename'}) {
! 6134: my ($cdom,$cnum) = split(/_/,$key);
! 6135: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,'book_image_'.$i,
! 6136: $cdom,$cnum,$configuserok,
! 6137: $switchserver,$author_ok);
! 6138: if ($imgurl) {
! 6139: $confhash{'textbooks'}{$key}{'image'} = $imgurl;
! 6140: $changes{'textbooks'}{$key} = 1;
! 6141: }
! 6142: if ($error) {
! 6143: &Apache::lonnet::logthis($error);
! 6144: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
! 6145: }
! 6146: } elsif ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
! 6147: $confhash{'textbooks'}{$key}{'image'} =
! 6148: $domconfig{$action}{'textbooks'}{$key}{'image'};
! 6149: }
! 6150: }
! 6151: }
! 6152: }
! 6153: }
1.102 raeburn 6154: } else {
1.144 raeburn 6155: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6156: $changes{'notify'}{'approval'} = 1;
6157: }
1.216 ! raeburn 6158: if ($confhash{'uniquecode'}) {
! 6159: $changes{'uniquecode'} = 1;
! 6160: }
! 6161: }
! 6162: if ($context eq 'requestcourses') {
! 6163: if ($newbook) {
! 6164: $changes{'textbooks'}{$newbook} = 1;
! 6165: foreach my $item ('subject','title','author') {
! 6166: $env{'form.addbook_'.$item} =~ s/(`)/'/g;
! 6167: if ($env{'form.addbook_'.$item}) {
! 6168: $confhash{'textbooks'}{$newbook}{$item} = $env{'form.addbook_'.$item};
! 6169: }
! 6170: }
! 6171: if ($env{'form.addbook_image.filename'} ne '') {
! 6172: my ($cdom,$cnum) = split(/_/,$newbook);
! 6173: my ($imageurl,$error) =
! 6174: &process_textbook_image($r,$dom,$confname,'addbook_image',$cdom,$cnum,$configuserok,
! 6175: $switchserver,$author_ok);
! 6176: if ($imageurl) {
! 6177: $confhash{'textbooks'}{$newbook}{'image'} = $imageurl;
! 6178: }
! 6179: if ($error) {
! 6180: &Apache::lonnet::logthis($error);
! 6181: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
! 6182: }
! 6183: }
! 6184: }
! 6185: if (@allpos > 0) {
! 6186: my $idx = 0;
! 6187: foreach my $item (@allpos) {
! 6188: if ($item ne '') {
! 6189: $confhash{'textbooks'}{$item}{'order'} = $idx;
! 6190: if (ref($domconfig{$action}) eq 'HASH') {
! 6191: if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
! 6192: if (ref($domconfig{$action}{'textbooks'}{$item}) eq 'HASH') {
! 6193: if ($domconfig{$action}{'textbooks'}{$item}{'order'} ne $idx) {
! 6194: $changes{'textbooks'}{$item} = 1;
! 6195: }
! 6196: }
! 6197: }
! 6198: }
! 6199: $idx ++;
! 6200: }
! 6201: }
! 6202: }
1.102 raeburn 6203: }
6204: } else {
1.86 raeburn 6205: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 6206: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 6207: }
1.72 raeburn 6208: foreach my $item (@usertools) {
6209: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 6210: my $unset;
1.101 raeburn 6211: if ($context eq 'requestcourses') {
1.104 raeburn 6212: $unset = '0';
6213: if ($type eq '_LC_adv') {
6214: $unset = '';
6215: }
1.101 raeburn 6216: if ($confhash{$item}{$type} eq 'autolimit') {
6217: $confhash{$item}{$type} .= '=';
6218: unless ($limithash{$item}{$type} =~ /\D/) {
6219: $confhash{$item}{$type} .= $limithash{$item}{$type};
6220: }
6221: }
1.163 raeburn 6222: } elsif ($context eq 'requestauthor') {
6223: $unset = '0';
6224: if ($type eq '_LC_adv') {
6225: $unset = '';
6226: }
1.72 raeburn 6227: } else {
1.101 raeburn 6228: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
6229: $confhash{$item}{$type} = 1;
6230: } else {
6231: $confhash{$item}{$type} = 0;
6232: }
1.72 raeburn 6233: }
1.86 raeburn 6234: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 6235: if ($action eq 'requestauthor') {
6236: if ($domconfig{$action}{$type} ne $confhash{$type}) {
6237: $changes{$type} = 1;
6238: }
6239: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 6240: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
6241: $changes{$item}{$type} = 1;
6242: }
6243: } else {
6244: if ($context eq 'requestcourses') {
1.104 raeburn 6245: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 6246: $changes{$item}{$type} = 1;
6247: }
6248: } else {
6249: if (!$confhash{$item}{$type}) {
6250: $changes{$item}{$type} = 1;
6251: }
6252: }
6253: }
6254: } else {
6255: if ($context eq 'requestcourses') {
1.104 raeburn 6256: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 6257: $changes{$item}{$type} = 1;
6258: }
1.163 raeburn 6259: } elsif ($context eq 'requestauthor') {
6260: if ($confhash{$type} ne $unset) {
6261: $changes{$type} = 1;
6262: }
1.72 raeburn 6263: } else {
6264: if (!$confhash{$item}{$type}) {
6265: $changes{$item}{$type} = 1;
6266: }
6267: }
6268: }
1.1 raeburn 6269: }
6270: }
1.163 raeburn 6271: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 6272: if (ref($domconfig{'quotas'}) eq 'HASH') {
6273: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
6274: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
6275: if (exists($confhash{'defaultquota'}{$key})) {
6276: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
6277: $changes{'defaultquota'}{$key} = 1;
6278: }
6279: } else {
6280: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 6281: }
6282: }
1.86 raeburn 6283: } else {
6284: foreach my $key (keys(%{$domconfig{'quotas'}})) {
6285: if (exists($confhash{'defaultquota'}{$key})) {
6286: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
6287: $changes{'defaultquota'}{$key} = 1;
6288: }
6289: } else {
6290: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 6291: }
1.1 raeburn 6292: }
6293: }
1.197 raeburn 6294: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
6295: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
6296: if (exists($confhash{'authorquota'}{$key})) {
6297: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
6298: $changes{'authorquota'}{$key} = 1;
6299: }
6300: } else {
6301: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
6302: }
6303: }
6304: }
1.1 raeburn 6305: }
1.86 raeburn 6306: if (ref($confhash{'defaultquota'}) eq 'HASH') {
6307: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
6308: if (ref($domconfig{'quotas'}) eq 'HASH') {
6309: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
6310: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
6311: $changes{'defaultquota'}{$key} = 1;
6312: }
6313: } else {
6314: if (!exists($domconfig{'quotas'}{$key})) {
6315: $changes{'defaultquota'}{$key} = 1;
6316: }
1.72 raeburn 6317: }
6318: } else {
1.86 raeburn 6319: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 6320: }
1.1 raeburn 6321: }
6322: }
1.197 raeburn 6323: if (ref($confhash{'authorquota'}) eq 'HASH') {
6324: foreach my $key (keys(%{$confhash{'authorquota'}})) {
6325: if (ref($domconfig{'quotas'}) eq 'HASH') {
6326: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
6327: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
6328: $changes{'authorquota'}{$key} = 1;
6329: }
6330: } else {
6331: $changes{'authorquota'}{$key} = 1;
6332: }
6333: } else {
6334: $changes{'authorquota'}{$key} = 1;
6335: }
6336: }
6337: }
1.1 raeburn 6338: }
1.72 raeburn 6339:
1.163 raeburn 6340: if ($context eq 'requestauthor') {
6341: $domdefaults{'requestauthor'} = \%confhash;
6342: } else {
6343: foreach my $key (keys(%confhash)) {
1.216 ! raeburn 6344: unless (($context eq 'requestcourses') && ($key eq 'textbooks')) {
! 6345: $domdefaults{$key} = $confhash{$key};
! 6346: }
1.163 raeburn 6347: }
1.72 raeburn 6348: }
1.163 raeburn 6349:
1.1 raeburn 6350: my %quotahash = (
1.86 raeburn 6351: $action => { %confhash }
1.1 raeburn 6352: );
6353: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
6354: $dom);
6355: if ($putresult eq 'ok') {
6356: if (keys(%changes) > 0) {
1.72 raeburn 6357: my $cachetime = 24*60*60;
6358: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 6359: if (ref($lastactref) eq 'HASH') {
6360: $lastactref->{'domdefaults'} = 1;
6361: }
1.1 raeburn 6362: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 6363: unless (($context eq 'requestcourses') ||
1.163 raeburn 6364: ($context eq 'requestauthor')) {
1.86 raeburn 6365: if (ref($changes{'defaultquota'}) eq 'HASH') {
6366: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
6367: foreach my $type (@{$types},'default') {
6368: if (defined($changes{'defaultquota'}{$type})) {
6369: my $typetitle = $usertypes->{$type};
6370: if ($type eq 'default') {
6371: $typetitle = $othertitle;
6372: }
1.213 raeburn 6373: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 6374: }
6375: }
1.86 raeburn 6376: $resulttext .= '</ul></li>';
1.72 raeburn 6377: }
1.197 raeburn 6378: if (ref($changes{'authorquota'}) eq 'HASH') {
6379: $resulttext .= '<li>'.&mt('Authoring space default quotas').'<ul>';
6380: foreach my $type (@{$types},'default') {
6381: if (defined($changes{'authorquota'}{$type})) {
6382: my $typetitle = $usertypes->{$type};
6383: if ($type eq 'default') {
6384: $typetitle = $othertitle;
6385: }
1.213 raeburn 6386: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 6387: }
6388: }
6389: $resulttext .= '</ul></li>';
6390: }
1.72 raeburn 6391: }
1.80 raeburn 6392: my %newenv;
1.72 raeburn 6393: foreach my $item (@usertools) {
1.163 raeburn 6394: my (%haschgs,%inconf);
6395: if ($context eq 'requestauthor') {
6396: %haschgs = %changes;
1.210 raeburn 6397: %inconf = %confhash;
1.163 raeburn 6398: } else {
6399: if (ref($changes{$item}) eq 'HASH') {
6400: %haschgs = %{$changes{$item}};
6401: }
6402: if (ref($confhash{$item}) eq 'HASH') {
6403: %inconf = %{$confhash{$item}};
6404: }
6405: }
6406: if (keys(%haschgs) > 0) {
1.80 raeburn 6407: my $newacc =
6408: &Apache::lonnet::usertools_access($env{'user.name'},
6409: $env{'user.domain'},
1.86 raeburn 6410: $item,'reload',$context);
1.210 raeburn 6411: if (($context eq 'requestcourses') ||
1.163 raeburn 6412: ($context eq 'requestauthor')) {
1.108 raeburn 6413: if ($env{'environment.canrequest.'.$item} ne $newacc) {
6414: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 6415: }
6416: } else {
6417: if ($env{'environment.availabletools.'.$item} ne $newacc) {
6418: $newenv{'environment.availabletools.'.$item} = $newacc;
6419: }
1.80 raeburn 6420: }
1.163 raeburn 6421: unless ($context eq 'requestauthor') {
6422: $resulttext .= '<li>'.$titles{$item}.'<ul>';
6423: }
1.72 raeburn 6424: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 6425: if ($haschgs{$type}) {
1.72 raeburn 6426: my $typetitle = $usertypes->{$type};
6427: if ($type eq 'default') {
6428: $typetitle = $othertitle;
6429: } elsif ($type eq '_LC_adv') {
6430: $typetitle = 'LON-CAPA Advanced Users';
6431: }
1.163 raeburn 6432: if ($inconf{$type}) {
1.101 raeburn 6433: if ($context eq 'requestcourses') {
6434: my $cond;
1.163 raeburn 6435: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 6436: if ($1 eq '') {
6437: $cond = &mt('(Automatic processing of any request).');
6438: } else {
6439: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
6440: }
6441: } else {
1.163 raeburn 6442: $cond = $conditions{$inconf{$type}};
1.101 raeburn 6443: }
6444: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 6445: } elsif ($context eq 'requestauthor') {
6446: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
6447: $titles{$inconf{$type}},$typetitle);
6448:
1.101 raeburn 6449: } else {
6450: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
6451: }
1.72 raeburn 6452: } else {
1.104 raeburn 6453: if ($type eq '_LC_adv') {
1.163 raeburn 6454: if ($inconf{$type} eq '0') {
1.104 raeburn 6455: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6456: } else {
6457: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
6458: }
6459: } else {
6460: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6461: }
1.72 raeburn 6462: }
6463: }
1.26 raeburn 6464: }
1.163 raeburn 6465: unless ($context eq 'requestauthor') {
6466: $resulttext .= '</ul></li>';
6467: }
1.26 raeburn 6468: }
1.1 raeburn 6469: }
1.163 raeburn 6470: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 6471: if (ref($changes{'notify'}) eq 'HASH') {
6472: if ($changes{'notify'}{'approval'}) {
6473: if (ref($confhash{'notify'}) eq 'HASH') {
6474: if ($confhash{'notify'}{'approval'}) {
6475: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
6476: } else {
1.163 raeburn 6477: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 6478: }
6479: }
6480: }
6481: }
6482: }
1.216 ! raeburn 6483: if ($action eq 'requestcourses') {
! 6484: my @offon = ('off','on');
! 6485: if ($changes{'uniquecode'}) {
! 6486: $resulttext .= '<li>'.
! 6487: &mt('Generation of six character code as course identifier for distribution to students set to '.
! 6488: $offon[$env{'form.uniquecode'}]).
! 6489: '</li>';
! 6490: }
! 6491: if (ref($changes{'textbooks'}) eq 'HASH') {
! 6492: $resulttext .= '<li>'.&mt('Available textbooks updated').'<ul>';
! 6493: foreach my $key (sort(keys(%{$changes{'textbooks'}}))) {
! 6494: my %coursehash = &Apache::lonnet::coursedescription($key);
! 6495: my $coursetitle = $coursehash{'description'};
! 6496: my $position = $confhash{'textbooks'}{$key}{'order'} + 1;
! 6497: $resulttext .= '<li>';
! 6498: foreach my $item ('subject','title','author') {
! 6499: my $name = $item.':';
! 6500: $name =~ s/^(\w)/\U$1/;
! 6501: $resulttext .= &mt($name).' '.$confhash{'textbooks'}{$key}{$item}.'<br />';
! 6502: }
! 6503: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
! 6504: if ($confhash{'textbooks'}{$key}{'image'}) {
! 6505: $resulttext .= ' '.&mt('Image: [_1]',
! 6506: '<img src="'.$confhash{'textbooks'}{$key}{'image'}.'"'.
! 6507: ' alt="Textbook cover" />').'<br />';
! 6508: }
! 6509: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
! 6510: }
! 6511: $resulttext .= '</ul></li>';
! 6512: }
! 6513: }
1.1 raeburn 6514: $resulttext .= '</ul>';
1.80 raeburn 6515: if (keys(%newenv)) {
6516: &Apache::lonnet::appenv(\%newenv);
6517: }
1.1 raeburn 6518: } else {
1.86 raeburn 6519: if ($context eq 'requestcourses') {
6520: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 6521: } elsif ($context eq 'requestauthor') {
6522: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 6523: } else {
1.90 weissno 6524: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 6525: }
1.1 raeburn 6526: }
6527: } else {
1.11 albertel 6528: $resulttext = '<span class="LC_error">'.
6529: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6530: }
1.216 ! raeburn 6531: if ($errors) {
! 6532: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
! 6533: '<ul>'.$errors.'</ul></p>';
! 6534: }
1.3 raeburn 6535: return $resulttext;
1.1 raeburn 6536: }
6537:
1.216 ! raeburn 6538: sub process_textbook_image {
! 6539: my ($r,$dom,$confname,$caller,$cdom,$cnum,$configuserok,$switchserver,$author_ok) = @_;
! 6540: my $filename = $env{'form.'.$caller.'.filename'};
! 6541: my ($error,$url);
! 6542: my ($width,$height) = (50,50);
! 6543: if ($configuserok eq 'ok') {
! 6544: if ($switchserver) {
! 6545: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
! 6546: $switchserver);
! 6547: } elsif ($author_ok eq 'ok') {
! 6548: my ($result,$imageurl) =
! 6549: &publishlogo($r,'upload',$caller,$dom,$confname,
! 6550: "textbooks/$dom/$cnum/cover",$width,$height);
! 6551: if ($result eq 'ok') {
! 6552: $url = $imageurl;
! 6553: } else {
! 6554: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
! 6555: }
! 6556: } else {
! 6557: $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);
! 6558: }
! 6559: } else {
! 6560: $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);
! 6561: }
! 6562: return ($url,$error);
! 6563: }
! 6564:
1.3 raeburn 6565: sub modify_autoenroll {
1.205 raeburn 6566: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 6567: my ($resulttext,%changes);
6568: my %currautoenroll;
6569: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6570: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
6571: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
6572: }
6573: }
6574: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
6575: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 6576: sender => 'Sender for notification messages',
6577: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 6578: my @offon = ('off','on');
1.17 raeburn 6579: my $sender_uname = $env{'form.sender_uname'};
6580: my $sender_domain = $env{'form.sender_domain'};
6581: if ($sender_domain eq '') {
6582: $sender_uname = '';
6583: } elsif ($sender_uname eq '') {
6584: $sender_domain = '';
6585: }
1.129 raeburn 6586: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 6587: my %autoenrollhash = (
1.129 raeburn 6588: autoenroll => { 'run' => $env{'form.autoenroll_run'},
6589: 'sender_uname' => $sender_uname,
6590: 'sender_domain' => $sender_domain,
6591: 'co-owners' => $coowners,
1.1 raeburn 6592: }
6593: );
1.4 raeburn 6594: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
6595: $dom);
1.1 raeburn 6596: if ($putresult eq 'ok') {
6597: if (exists($currautoenroll{'run'})) {
6598: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
6599: $changes{'run'} = 1;
6600: }
6601: } elsif ($autorun) {
6602: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 6603: $changes{'run'} = 1;
1.1 raeburn 6604: }
6605: }
1.17 raeburn 6606: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 6607: $changes{'sender'} = 1;
6608: }
1.17 raeburn 6609: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 6610: $changes{'sender'} = 1;
6611: }
1.129 raeburn 6612: if ($currautoenroll{'co-owners'} ne '') {
6613: if ($currautoenroll{'co-owners'} ne $coowners) {
6614: $changes{'coowners'} = 1;
6615: }
6616: } elsif ($coowners) {
6617: $changes{'coowners'} = 1;
6618: }
1.1 raeburn 6619: if (keys(%changes) > 0) {
6620: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 6621: if ($changes{'run'}) {
1.1 raeburn 6622: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
6623: }
6624: if ($changes{'sender'}) {
1.17 raeburn 6625: if ($sender_uname eq '' || $sender_domain eq '') {
6626: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
6627: } else {
6628: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
6629: }
1.1 raeburn 6630: }
1.129 raeburn 6631: if ($changes{'coowners'}) {
6632: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
6633: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 6634: if (ref($lastactref) eq 'HASH') {
6635: $lastactref->{'domainconfig'} = 1;
6636: }
1.129 raeburn 6637: }
1.1 raeburn 6638: $resulttext .= '</ul>';
6639: } else {
6640: $resulttext = &mt('No changes made to auto-enrollment settings');
6641: }
6642: } else {
1.11 albertel 6643: $resulttext = '<span class="LC_error">'.
6644: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6645: }
1.3 raeburn 6646: return $resulttext;
1.1 raeburn 6647: }
6648:
6649: sub modify_autoupdate {
1.3 raeburn 6650: my ($dom,%domconfig) = @_;
1.1 raeburn 6651: my ($resulttext,%currautoupdate,%fields,%changes);
6652: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
6653: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
6654: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
6655: }
6656: }
6657: my @offon = ('off','on');
6658: my %title = &Apache::lonlocal::texthash (
6659: run => 'Auto-update:',
6660: classlists => 'Updates to user information in classlists?'
6661: );
1.44 raeburn 6662: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6663: my %fieldtitles = &Apache::lonlocal::texthash (
6664: id => 'Student/Employee ID',
1.20 raeburn 6665: permanentemail => 'E-mail address',
1.1 raeburn 6666: lastname => 'Last Name',
6667: firstname => 'First Name',
6668: middlename => 'Middle Name',
1.132 raeburn 6669: generation => 'Generation',
1.1 raeburn 6670: );
1.142 raeburn 6671: $othertitle = &mt('All users');
1.1 raeburn 6672: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 6673: $othertitle = &mt('Other users');
1.1 raeburn 6674: }
6675: foreach my $key (keys(%env)) {
6676: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 6677: my ($usertype,$item) = ($1,$2);
6678: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
6679: if ($usertype eq 'default') {
6680: push(@{$fields{$1}},$2);
6681: } elsif (ref($types) eq 'ARRAY') {
6682: if (grep(/^\Q$usertype\E$/,@{$types})) {
6683: push(@{$fields{$1}},$2);
6684: }
6685: }
6686: }
1.1 raeburn 6687: }
6688: }
1.131 raeburn 6689: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
6690: @lockablenames = sort(@lockablenames);
6691: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
6692: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6693: if (@changed) {
6694: $changes{'lockablenames'} = 1;
6695: }
6696: } else {
6697: if (@lockablenames) {
6698: $changes{'lockablenames'} = 1;
6699: }
6700: }
1.1 raeburn 6701: my %updatehash = (
6702: autoupdate => { run => $env{'form.autoupdate_run'},
6703: classlists => $env{'form.classlists'},
6704: fields => {%fields},
1.131 raeburn 6705: lockablenames => \@lockablenames,
1.1 raeburn 6706: }
6707: );
6708: foreach my $key (keys(%currautoupdate)) {
6709: if (($key eq 'run') || ($key eq 'classlists')) {
6710: if (exists($updatehash{autoupdate}{$key})) {
6711: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
6712: $changes{$key} = 1;
6713: }
6714: }
6715: } elsif ($key eq 'fields') {
6716: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 6717: foreach my $item (@{$types},'default') {
1.1 raeburn 6718: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
6719: my $change = 0;
6720: foreach my $type (@{$currautoupdate{$key}{$item}}) {
6721: if (!exists($fields{$item})) {
6722: $change = 1;
1.132 raeburn 6723: last;
1.1 raeburn 6724: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 6725: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 6726: $change = 1;
1.132 raeburn 6727: last;
1.1 raeburn 6728: }
6729: }
6730: }
6731: if ($change) {
6732: push(@{$changes{$key}},$item);
6733: }
1.26 raeburn 6734: }
1.1 raeburn 6735: }
6736: }
1.131 raeburn 6737: } elsif ($key eq 'lockablenames') {
6738: if (ref($currautoupdate{$key}) eq 'ARRAY') {
6739: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6740: if (@changed) {
6741: $changes{'lockablenames'} = 1;
6742: }
6743: } else {
6744: if (@lockablenames) {
6745: $changes{'lockablenames'} = 1;
6746: }
6747: }
6748: }
6749: }
6750: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
6751: if (@lockablenames) {
6752: $changes{'lockablenames'} = 1;
1.1 raeburn 6753: }
6754: }
1.26 raeburn 6755: foreach my $item (@{$types},'default') {
6756: if (defined($fields{$item})) {
6757: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 6758: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
6759: my $change = 0;
6760: if (ref($fields{$item}) eq 'ARRAY') {
6761: foreach my $type (@{$fields{$item}}) {
6762: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
6763: $change = 1;
6764: last;
6765: }
6766: }
6767: }
6768: if ($change) {
6769: push(@{$changes{'fields'}},$item);
6770: }
6771: } else {
1.26 raeburn 6772: push(@{$changes{'fields'}},$item);
6773: }
6774: } else {
6775: push(@{$changes{'fields'}},$item);
1.1 raeburn 6776: }
6777: }
6778: }
6779: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
6780: $dom);
6781: if ($putresult eq 'ok') {
6782: if (keys(%changes) > 0) {
6783: $resulttext = &mt('Changes made:').'<ul>';
6784: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 6785: if ($key eq 'lockablenames') {
6786: $resulttext .= '<li>';
6787: if (@lockablenames) {
6788: $usertypes->{'default'} = $othertitle;
6789: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
6790: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
6791: } else {
6792: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
6793: }
6794: $resulttext .= '</li>';
6795: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 6796: foreach my $item (@{$changes{$key}}) {
6797: my @newvalues;
6798: foreach my $type (@{$fields{$item}}) {
6799: push(@newvalues,$fieldtitles{$type});
6800: }
1.3 raeburn 6801: my $newvaluestr;
6802: if (@newvalues > 0) {
6803: $newvaluestr = join(', ',@newvalues);
6804: } else {
6805: $newvaluestr = &mt('none');
1.6 raeburn 6806: }
1.1 raeburn 6807: if ($item eq 'default') {
1.26 raeburn 6808: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 6809: } else {
1.26 raeburn 6810: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 6811: }
6812: }
6813: } else {
6814: my $newvalue;
6815: if ($key eq 'run') {
6816: $newvalue = $offon[$env{'form.autoupdate_run'}];
6817: } else {
6818: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 6819: }
1.1 raeburn 6820: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
6821: }
6822: }
6823: $resulttext .= '</ul>';
6824: } else {
1.3 raeburn 6825: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 6826: }
6827: } else {
1.11 albertel 6828: $resulttext = '<span class="LC_error">'.
6829: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6830: }
1.3 raeburn 6831: return $resulttext;
1.1 raeburn 6832: }
6833:
1.125 raeburn 6834: sub modify_autocreate {
6835: my ($dom,%domconfig) = @_;
6836: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
6837: if (ref($domconfig{'autocreate'}) eq 'HASH') {
6838: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
6839: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
6840: }
6841: }
6842: my %title= ( xml => 'Auto-creation of courses in XML course description files',
6843: req => 'Auto-creation of validated requests for official courses',
6844: xmldc => 'Identity of course creator of courses from XML files',
6845: );
6846: my @types = ('xml','req');
6847: foreach my $item (@types) {
6848: $newvals{$item} = $env{'form.autocreate_'.$item};
6849: $newvals{$item} =~ s/\D//g;
6850: $newvals{$item} = 0 if ($newvals{$item} eq '');
6851: }
6852: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
6853: my %domcoords = &get_active_dcs($dom);
6854: unless (exists($domcoords{$newvals{'xmldc'}})) {
6855: $newvals{'xmldc'} = '';
6856: }
6857: %autocreatehash = (
6858: autocreate => { xml => $newvals{'xml'},
6859: req => $newvals{'req'},
6860: }
6861: );
6862: if ($newvals{'xmldc'} ne '') {
6863: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
6864: }
6865: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
6866: $dom);
6867: if ($putresult eq 'ok') {
6868: my @items = @types;
6869: if ($newvals{'xml'}) {
6870: push(@items,'xmldc');
6871: }
6872: foreach my $item (@items) {
6873: if (exists($currautocreate{$item})) {
6874: if ($currautocreate{$item} ne $newvals{$item}) {
6875: $changes{$item} = 1;
6876: }
6877: } elsif ($newvals{$item}) {
6878: $changes{$item} = 1;
6879: }
6880: }
6881: if (keys(%changes) > 0) {
6882: my @offon = ('off','on');
6883: $resulttext = &mt('Changes made:').'<ul>';
6884: foreach my $item (@types) {
6885: if ($changes{$item}) {
6886: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 6887: $resulttext .= '<li>'.
6888: &mt("$title{$item} set to [_1]$newtxt [_2]",
6889: '<b>','</b>').
6890: '</li>';
1.125 raeburn 6891: }
6892: }
6893: if ($changes{'xmldc'}) {
6894: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
6895: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 6896: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 6897: }
6898: $resulttext .= '</ul>';
6899: } else {
6900: $resulttext = &mt('No changes made to auto-creation settings');
6901: }
6902: } else {
6903: $resulttext = '<span class="LC_error">'.
6904: &mt('An error occurred: [_1]',$putresult).'</span>';
6905: }
6906: return $resulttext;
6907: }
6908:
1.23 raeburn 6909: sub modify_directorysrch {
6910: my ($dom,%domconfig) = @_;
6911: my ($resulttext,%changes);
6912: my %currdirsrch;
6913: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
6914: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
6915: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
6916: }
6917: }
6918: my %title = ( available => 'Directory search available',
1.24 raeburn 6919: localonly => 'Other domains can search',
1.23 raeburn 6920: searchby => 'Search types',
6921: searchtypes => 'Search latitude');
6922: my @offon = ('off','on');
1.24 raeburn 6923: my @otherdoms = ('Yes','No');
1.23 raeburn 6924:
1.25 raeburn 6925: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 6926: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
6927: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
6928:
1.44 raeburn 6929: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 6930: if (keys(%{$usertypes}) == 0) {
6931: @cansearch = ('default');
6932: } else {
6933: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
6934: foreach my $type (@{$currdirsrch{'cansearch'}}) {
6935: if (!grep(/^\Q$type\E$/,@cansearch)) {
6936: push(@{$changes{'cansearch'}},$type);
6937: }
1.23 raeburn 6938: }
1.26 raeburn 6939: foreach my $type (@cansearch) {
6940: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
6941: push(@{$changes{'cansearch'}},$type);
6942: }
1.23 raeburn 6943: }
1.26 raeburn 6944: } else {
6945: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 6946: }
6947: }
6948:
6949: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
6950: foreach my $by (@{$currdirsrch{'searchby'}}) {
6951: if (!grep(/^\Q$by\E$/,@searchby)) {
6952: push(@{$changes{'searchby'}},$by);
6953: }
6954: }
6955: foreach my $by (@searchby) {
6956: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
6957: push(@{$changes{'searchby'}},$by);
6958: }
6959: }
6960: } else {
6961: push(@{$changes{'searchby'}},@searchby);
6962: }
1.25 raeburn 6963:
6964: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
6965: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
6966: if (!grep(/^\Q$type\E$/,@searchtypes)) {
6967: push(@{$changes{'searchtypes'}},$type);
6968: }
6969: }
6970: foreach my $type (@searchtypes) {
6971: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
6972: push(@{$changes{'searchtypes'}},$type);
6973: }
6974: }
6975: } else {
6976: if (exists($currdirsrch{'searchtypes'})) {
6977: foreach my $type (@searchtypes) {
6978: if ($type ne $currdirsrch{'searchtypes'}) {
6979: push(@{$changes{'searchtypes'}},$type);
6980: }
6981: }
6982: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
6983: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
6984: }
6985: } else {
6986: push(@{$changes{'searchtypes'}},@searchtypes);
6987: }
6988: }
6989:
1.23 raeburn 6990: my %dirsrch_hash = (
6991: directorysrch => { available => $env{'form.dirsrch_available'},
6992: cansearch => \@cansearch,
1.24 raeburn 6993: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 6994: searchby => \@searchby,
1.25 raeburn 6995: searchtypes => \@searchtypes,
1.23 raeburn 6996: }
6997: );
6998: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
6999: $dom);
7000: if ($putresult eq 'ok') {
7001: if (exists($currdirsrch{'available'})) {
7002: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
7003: $changes{'available'} = 1;
7004: }
7005: } else {
7006: if ($env{'form.dirsrch_available'} eq '1') {
7007: $changes{'available'} = 1;
7008: }
7009: }
1.24 raeburn 7010: if (exists($currdirsrch{'localonly'})) {
7011: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
7012: $changes{'localonly'} = 1;
7013: }
7014: } else {
7015: if ($env{'form.dirsrch_localonly'} eq '1') {
7016: $changes{'localonly'} = 1;
7017: }
7018: }
1.23 raeburn 7019: if (keys(%changes) > 0) {
7020: $resulttext = &mt('Changes made:').'<ul>';
7021: if ($changes{'available'}) {
7022: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
7023: }
1.24 raeburn 7024: if ($changes{'localonly'}) {
7025: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
7026: }
7027:
1.23 raeburn 7028: if (ref($changes{'cansearch'}) eq 'ARRAY') {
7029: my $chgtext;
1.26 raeburn 7030: if (ref($usertypes) eq 'HASH') {
7031: if (keys(%{$usertypes}) > 0) {
7032: foreach my $type (@{$types}) {
7033: if (grep(/^\Q$type\E$/,@cansearch)) {
7034: $chgtext .= $usertypes->{$type}.'; ';
7035: }
7036: }
7037: if (grep(/^default$/,@cansearch)) {
7038: $chgtext .= $othertitle;
7039: } else {
7040: $chgtext =~ s/\; $//;
7041: }
1.210 raeburn 7042: $resulttext .=
1.178 raeburn 7043: '<li>'.
7044: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
7045: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
7046: '</li>';
1.23 raeburn 7047: }
7048: }
7049: }
7050: if (ref($changes{'searchby'}) eq 'ARRAY') {
7051: my ($searchtitles,$titleorder) = &sorted_searchtitles();
7052: my $chgtext;
7053: foreach my $type (@{$titleorder}) {
7054: if (grep(/^\Q$type\E$/,@searchby)) {
7055: if (defined($searchtitles->{$type})) {
7056: $chgtext .= $searchtitles->{$type}.'; ';
7057: }
7058: }
7059: }
7060: $chgtext =~ s/\; $//;
7061: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
7062: }
1.25 raeburn 7063: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
7064: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
7065: my $chgtext;
7066: foreach my $type (@{$srchtypeorder}) {
7067: if (grep(/^\Q$type\E$/,@searchtypes)) {
7068: if (defined($srchtypes_desc->{$type})) {
7069: $chgtext .= $srchtypes_desc->{$type}.'; ';
7070: }
7071: }
7072: }
7073: $chgtext =~ s/\; $//;
1.178 raeburn 7074: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 7075: }
7076: $resulttext .= '</ul>';
7077: } else {
7078: $resulttext = &mt('No changes made to institution directory search settings');
7079: }
7080: } else {
7081: $resulttext = '<span class="LC_error">'.
1.27 raeburn 7082: &mt('An error occurred: [_1]',$putresult).'</span>';
7083: }
7084: return $resulttext;
7085: }
7086:
1.28 raeburn 7087: sub modify_contacts {
1.205 raeburn 7088: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 7089: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
7090: if (ref($domconfig{'contacts'}) eq 'HASH') {
7091: foreach my $key (keys(%{$domconfig{'contacts'}})) {
7092: $currsetting{$key} = $domconfig{'contacts'}{$key};
7093: }
7094: }
1.134 raeburn 7095: my (%others,%to,%bcc);
1.28 raeburn 7096: my @contacts = ('supportemail','adminemail');
1.102 raeburn 7097: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.203 raeburn 7098: 'requestsmail','updatesmail','idconflictsmail');
7099: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 7100: foreach my $type (@mailings) {
7101: @{$newsetting{$type}} =
7102: &Apache::loncommon::get_env_multiple('form.'.$type);
7103: foreach my $item (@contacts) {
7104: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
7105: $contacts_hash{contacts}{$type}{$item} = 1;
7106: } else {
7107: $contacts_hash{contacts}{$type}{$item} = 0;
7108: }
7109: }
7110: $others{$type} = $env{'form.'.$type.'_others'};
7111: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 7112: if ($type eq 'helpdeskmail') {
7113: $bcc{$type} = $env{'form.'.$type.'_bcc'};
7114: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
7115: }
1.28 raeburn 7116: }
7117: foreach my $item (@contacts) {
7118: $to{$item} = $env{'form.'.$item};
7119: $contacts_hash{'contacts'}{$item} = $to{$item};
7120: }
1.203 raeburn 7121: foreach my $item (@toggles) {
7122: if ($env{'form.'.$item} =~ /^(0|1)$/) {
7123: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
7124: }
7125: }
1.28 raeburn 7126: if (keys(%currsetting) > 0) {
7127: foreach my $item (@contacts) {
7128: if ($to{$item} ne $currsetting{$item}) {
7129: $changes{$item} = 1;
7130: }
7131: }
7132: foreach my $type (@mailings) {
7133: foreach my $item (@contacts) {
7134: if (ref($currsetting{$type}) eq 'HASH') {
7135: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
7136: push(@{$changes{$type}},$item);
7137: }
7138: } else {
7139: push(@{$changes{$type}},@{$newsetting{$type}});
7140: }
7141: }
7142: if ($others{$type} ne $currsetting{$type}{'others'}) {
7143: push(@{$changes{$type}},'others');
7144: }
1.134 raeburn 7145: if ($type eq 'helpdeskmail') {
7146: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
7147: push(@{$changes{$type}},'bcc');
7148: }
7149: }
1.28 raeburn 7150: }
7151: } else {
7152: my %default;
7153: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
7154: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
7155: $default{'errormail'} = 'adminemail';
7156: $default{'packagesmail'} = 'adminemail';
7157: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 7158: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 7159: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 7160: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 7161: foreach my $item (@contacts) {
7162: if ($to{$item} ne $default{$item}) {
7163: $changes{$item} = 1;
1.203 raeburn 7164: }
1.28 raeburn 7165: }
7166: foreach my $type (@mailings) {
7167: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
7168:
7169: push(@{$changes{$type}},@{$newsetting{$type}});
7170: }
7171: if ($others{$type} ne '') {
7172: push(@{$changes{$type}},'others');
1.134 raeburn 7173: }
7174: if ($type eq 'helpdeskmail') {
7175: if ($bcc{$type} ne '') {
7176: push(@{$changes{$type}},'bcc');
7177: }
7178: }
1.28 raeburn 7179: }
7180: }
1.203 raeburn 7181: foreach my $item (@toggles) {
7182: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
7183: $changes{$item} = 1;
7184: } elsif ((!$env{'form.'.$item}) &&
7185: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
7186: $changes{$item} = 1;
7187: }
7188: }
1.28 raeburn 7189: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
7190: $dom);
7191: if ($putresult eq 'ok') {
7192: if (keys(%changes) > 0) {
1.205 raeburn 7193: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7194: if (ref($lastactref) eq 'HASH') {
7195: $lastactref->{'domainconfig'} = 1;
7196: }
1.28 raeburn 7197: my ($titles,$short_titles) = &contact_titles();
7198: $resulttext = &mt('Changes made:').'<ul>';
7199: foreach my $item (@contacts) {
7200: if ($changes{$item}) {
7201: $resulttext .= '<li>'.$titles->{$item}.
7202: &mt(' set to: ').
7203: '<span class="LC_cusr_emph">'.
7204: $to{$item}.'</span></li>';
7205: }
7206: }
7207: foreach my $type (@mailings) {
7208: if (ref($changes{$type}) eq 'ARRAY') {
7209: $resulttext .= '<li>'.$titles->{$type}.': ';
7210: my @text;
7211: foreach my $item (@{$newsetting{$type}}) {
7212: push(@text,$short_titles->{$item});
7213: }
7214: if ($others{$type} ne '') {
7215: push(@text,$others{$type});
7216: }
7217: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 7218: join(', ',@text).'</span>';
7219: if ($type eq 'helpdeskmail') {
7220: if ($bcc{$type} ne '') {
7221: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
7222: }
7223: }
7224: $resulttext .= '</li>';
1.28 raeburn 7225: }
7226: }
1.203 raeburn 7227: my @offon = ('off','on');
7228: if ($changes{'reporterrors'}) {
7229: $resulttext .= '<li>'.
7230: &mt('E-mail error reports to [_1] set to "'.
7231: $offon[$env{'form.reporterrors'}].'".',
7232: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
7233: &mt('LON-CAPA core group - MSU'),600,500)).
7234: '</li>';
7235: }
7236: if ($changes{'reportupdates'}) {
7237: $resulttext .= '<li>'.
7238: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
7239: $offon[$env{'form.reportupdates'}].'".',
7240: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
7241: &mt('LON-CAPA core group - MSU'),600,500)).
7242: '</li>';
7243: }
1.28 raeburn 7244: $resulttext .= '</ul>';
7245: } else {
1.34 raeburn 7246: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 7247: }
7248: } else {
7249: $resulttext = '<span class="LC_error">'.
7250: &mt('An error occurred: [_1].',$putresult).'</span>';
7251: }
7252: return $resulttext;
7253: }
7254:
7255: sub modify_usercreation {
1.27 raeburn 7256: my ($dom,%domconfig) = @_;
1.34 raeburn 7257: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 7258: my $warningmsg;
1.27 raeburn 7259: if (ref($domconfig{'usercreation'}) eq 'HASH') {
7260: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
7261: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
7262: }
7263: }
7264: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 7265: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 7266: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 7267: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 7268: foreach my $item(@contexts) {
1.45 raeburn 7269: if ($item eq 'selfcreate') {
1.50 raeburn 7270: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.212 raeburn 7271: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.43 raeburn 7272: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 7273: if (ref($cancreate{$item}) eq 'ARRAY') {
7274: if (grep(/^login$/,@{$cancreate{$item}})) {
7275: $warningmsg = &mt('Although account creation has been set to be available for institutional logins, currently default authentication in this domain has not been set to support this.').' '.&mt('You need to set the default authentication type to Kerberos 4 or 5 (with a Kerberos domain specified), or to Local authentication, if the localauth module has been customized in your domain to authenticate institutional logins.');
7276: }
1.43 raeburn 7277: }
7278: }
1.50 raeburn 7279: } else {
7280: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 7281: }
1.34 raeburn 7282: }
1.93 raeburn 7283: my ($othertitle,$usertypes,$types) =
7284: &Apache::loncommon::sorted_inst_types($dom);
7285: if (ref($types) eq 'ARRAY') {
7286: if (@{$types} > 0) {
7287: @{$cancreate{'statustocreate'}} =
7288: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 raeburn 7289: } else {
7290: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 7291: }
7292: push(@contexts,'statustocreate');
7293: }
1.165 raeburn 7294: &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
1.34 raeburn 7295: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
7296: foreach my $item (@contexts) {
1.93 raeburn 7297: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
7298: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 7299: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 raeburn 7300: if (ref($cancreate{$item}) eq 'ARRAY') {
7301: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
7302: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7303: push(@{$changes{'cancreate'}},$item);
7304: }
1.50 raeburn 7305: }
7306: }
7307: }
7308: } else {
7309: if ($curr_usercreation{'cancreate'}{$item} eq '') {
7310: if (@{$cancreate{$item}} > 0) {
7311: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7312: push(@{$changes{'cancreate'}},$item);
7313: }
7314: }
7315: } else {
7316: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
7317: if (@{$cancreate{$item}} < 3) {
7318: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7319: push(@{$changes{'cancreate'}},$item);
7320: }
7321: }
7322: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
7323: if (@{$cancreate{$item}} > 0) {
7324: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7325: push(@{$changes{'cancreate'}},$item);
7326: }
7327: }
7328: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
7329: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7330: push(@{$changes{'cancreate'}},$item);
7331: }
7332: }
7333: }
7334: }
7335: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7336: foreach my $type (@{$cancreate{$item}}) {
7337: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
7338: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
7339: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7340: push(@{$changes{'cancreate'}},$item);
7341: }
7342: }
7343: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
7344: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
7345: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
7346: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7347: push(@{$changes{'cancreate'}},$item);
7348: }
7349: }
7350: }
7351: }
7352: }
7353: } else {
7354: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
7355: push(@{$changes{'cancreate'}},$item);
7356: }
7357: }
1.27 raeburn 7358: }
1.34 raeburn 7359: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
7360: foreach my $item (@contexts) {
1.43 raeburn 7361: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 7362: if ($cancreate{$item} ne 'any') {
7363: push(@{$changes{'cancreate'}},$item);
7364: }
7365: } else {
7366: if ($cancreate{$item} ne 'none') {
7367: push(@{$changes{'cancreate'}},$item);
7368: }
1.27 raeburn 7369: }
7370: }
7371: } else {
1.43 raeburn 7372: foreach my $item (@contexts) {
1.34 raeburn 7373: push(@{$changes{'cancreate'}},$item);
7374: }
1.27 raeburn 7375: }
1.34 raeburn 7376:
1.27 raeburn 7377: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
7378: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
7379: if (!grep(/^\Q$type\E$/,@username_rule)) {
7380: push(@{$changes{'username_rule'}},$type);
7381: }
7382: }
7383: foreach my $type (@username_rule) {
7384: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
7385: push(@{$changes{'username_rule'}},$type);
7386: }
7387: }
7388: } else {
7389: push(@{$changes{'username_rule'}},@username_rule);
7390: }
7391:
1.32 raeburn 7392: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
7393: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
7394: if (!grep(/^\Q$type\E$/,@id_rule)) {
7395: push(@{$changes{'id_rule'}},$type);
7396: }
7397: }
7398: foreach my $type (@id_rule) {
7399: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
7400: push(@{$changes{'id_rule'}},$type);
7401: }
7402: }
7403: } else {
7404: push(@{$changes{'id_rule'}},@id_rule);
7405: }
7406:
1.43 raeburn 7407: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
7408: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
7409: if (!grep(/^\Q$type\E$/,@email_rule)) {
7410: push(@{$changes{'email_rule'}},$type);
7411: }
7412: }
7413: foreach my $type (@email_rule) {
7414: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
7415: push(@{$changes{'email_rule'}},$type);
7416: }
7417: }
7418: } else {
7419: push(@{$changes{'email_rule'}},@email_rule);
7420: }
7421:
7422: my @authen_contexts = ('author','course','domain');
1.28 raeburn 7423: my @authtypes = ('int','krb4','krb5','loc');
7424: my %authhash;
1.43 raeburn 7425: foreach my $item (@authen_contexts) {
1.28 raeburn 7426: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
7427: foreach my $auth (@authtypes) {
7428: if (grep(/^\Q$auth\E$/,@authallowed)) {
7429: $authhash{$item}{$auth} = 1;
7430: } else {
7431: $authhash{$item}{$auth} = 0;
7432: }
7433: }
7434: }
7435: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 7436: foreach my $item (@authen_contexts) {
1.28 raeburn 7437: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
7438: foreach my $auth (@authtypes) {
7439: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
7440: push(@{$changes{'authtypes'}},$item);
7441: last;
7442: }
7443: }
7444: }
7445: }
7446: } else {
1.43 raeburn 7447: foreach my $item (@authen_contexts) {
1.28 raeburn 7448: push(@{$changes{'authtypes'}},$item);
7449: }
7450: }
7451:
1.27 raeburn 7452: my %usercreation_hash = (
1.28 raeburn 7453: usercreation => {
1.34 raeburn 7454: cancreate => \%cancreate,
1.27 raeburn 7455: username_rule => \@username_rule,
1.32 raeburn 7456: id_rule => \@id_rule,
1.43 raeburn 7457: email_rule => \@email_rule,
1.32 raeburn 7458: authtypes => \%authhash,
1.27 raeburn 7459: }
7460: );
7461:
7462: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
7463: $dom);
1.50 raeburn 7464:
7465: my %selfcreatetypes = (
7466: sso => 'users authenticated by institutional single sign on',
7467: login => 'users authenticated by institutional log-in',
7468: email => 'users who provide a valid e-mail address for use as the username',
7469: );
1.27 raeburn 7470: if ($putresult eq 'ok') {
7471: if (keys(%changes) > 0) {
7472: $resulttext = &mt('Changes made:').'<ul>';
7473: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 7474: my %lt = &usercreation_types();
7475: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 7476: my $chgtext;
1.165 raeburn 7477: unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
1.100 raeburn 7478: $chgtext = $lt{$type}.', ';
7479: }
1.45 raeburn 7480: if ($type eq 'selfcreate') {
1.50 raeburn 7481: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 7482: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 7483: } else {
1.100 raeburn 7484: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 7485: foreach my $case (@{$cancreate{$type}}) {
7486: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
7487: }
7488: $chgtext .= '</ul>';
1.100 raeburn 7489: if (ref($cancreate{$type}) eq 'ARRAY') {
7490: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
7491: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
7492: if (@{$cancreate{'statustocreate'}} == 0) {
7493: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
7494: }
7495: }
7496: }
7497: }
1.43 raeburn 7498: }
1.93 raeburn 7499: } elsif ($type eq 'statustocreate') {
1.96 raeburn 7500: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
7501: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
7502: if (@{$cancreate{'selfcreate'}} > 0) {
7503: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 7504:
7505: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 7506: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 7507: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
7508: }
1.96 raeburn 7509: } elsif (ref($usertypes) eq 'HASH') {
7510: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 7511: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
7512: } else {
7513: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
7514: }
7515: $chgtext .= '<ul>';
7516: foreach my $case (@{$cancreate{$type}}) {
7517: if ($case eq 'default') {
7518: $chgtext .= '<li>'.$othertitle.'</li>';
7519: } else {
7520: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 7521: }
7522: }
1.100 raeburn 7523: $chgtext .= '</ul>';
7524: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
7525: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
7526: }
7527: }
7528: } else {
7529: if (@{$cancreate{$type}} == 0) {
7530: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
7531: } else {
7532: $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 7533: }
7534: }
7535: }
1.165 raeburn 7536: } elsif ($type eq 'captcha') {
7537: if ($cancreate{$type} eq 'notused') {
7538: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
7539: } else {
7540: my %captchas = &captcha_phrases();
7541: if ($captchas{$cancreate{$type}}) {
7542: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
7543: } else {
1.210 raeburn 7544: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 7545: }
7546: }
7547: } elsif ($type eq 'recaptchakeys') {
7548: my ($privkey,$pubkey);
7549: if (ref($cancreate{$type}) eq 'HASH') {
7550: $pubkey = $cancreate{$type}{'public'};
7551: $privkey = $cancreate{$type}{'private'};
7552: }
7553: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
7554: if (!$pubkey) {
7555: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
7556: } else {
7557: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7558: }
7559: if (!$privkey) {
7560: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
7561: } else {
7562: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
7563: }
7564: $chgtext .= '</ul>';
1.43 raeburn 7565: } else {
7566: if ($cancreate{$type} eq 'none') {
7567: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
7568: } elsif ($cancreate{$type} eq 'any') {
7569: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
7570: } elsif ($cancreate{$type} eq 'official') {
7571: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
7572: } elsif ($cancreate{$type} eq 'unofficial') {
7573: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
7574: }
1.34 raeburn 7575: }
7576: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 7577: }
7578: }
7579: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 7580: my ($rules,$ruleorder) =
7581: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 7582: my $chgtext = '<ul>';
7583: foreach my $type (@username_rule) {
7584: if (ref($rules->{$type}) eq 'HASH') {
7585: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
7586: }
7587: }
7588: $chgtext .= '</ul>';
7589: if (@username_rule > 0) {
7590: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7591: } else {
1.28 raeburn 7592: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 7593: }
7594: }
1.32 raeburn 7595: if (ref($changes{'id_rule'}) eq 'ARRAY') {
7596: my ($idrules,$idruleorder) =
7597: &Apache::lonnet::inst_userrules($dom,'id');
7598: my $chgtext = '<ul>';
7599: foreach my $type (@id_rule) {
7600: if (ref($idrules->{$type}) eq 'HASH') {
7601: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
7602: }
7603: }
7604: $chgtext .= '</ul>';
7605: if (@id_rule > 0) {
7606: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7607: } else {
7608: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
7609: }
7610: }
1.43 raeburn 7611: if (ref($changes{'email_rule'}) eq 'ARRAY') {
7612: my ($emailrules,$emailruleorder) =
7613: &Apache::lonnet::inst_userrules($dom,'email');
7614: my $chgtext = '<ul>';
7615: foreach my $type (@email_rule) {
7616: if (ref($emailrules->{$type}) eq 'HASH') {
7617: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
7618: }
7619: }
7620: $chgtext .= '</ul>';
7621: if (@email_rule > 0) {
7622: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
7623: } else {
7624: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
7625: }
7626: }
7627:
1.28 raeburn 7628: my %authname = &authtype_names();
7629: my %context_title = &context_names();
7630: if (ref($changes{'authtypes'}) eq 'ARRAY') {
7631: my $chgtext = '<ul>';
7632: foreach my $type (@{$changes{'authtypes'}}) {
7633: my @allowed;
7634: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
7635: foreach my $auth (@authtypes) {
7636: if ($authhash{$type}{$auth}) {
7637: push(@allowed,$authname{$auth});
7638: }
7639: }
1.43 raeburn 7640: if (@allowed > 0) {
7641: $chgtext .= join(', ',@allowed).'</li>';
7642: } else {
7643: $chgtext .= &mt('none').'</li>';
7644: }
1.28 raeburn 7645: }
7646: $chgtext .= '</ul>';
7647: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
7648: $resulttext .= '</li>';
7649: }
1.27 raeburn 7650: $resulttext .= '</ul>';
7651: } else {
1.28 raeburn 7652: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 7653: }
7654: } else {
7655: $resulttext = '<span class="LC_error">'.
1.23 raeburn 7656: &mt('An error occurred: [_1]',$putresult).'</span>';
7657: }
1.43 raeburn 7658: if ($warningmsg ne '') {
7659: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
7660: }
1.23 raeburn 7661: return $resulttext;
7662: }
7663:
1.165 raeburn 7664: sub process_captcha {
7665: my ($container,$changes,$newsettings,$current) = @_;
7666: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
7667: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
7668: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
7669: $newsettings->{'captcha'} = 'original';
7670: }
7671: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 7672: if ($container eq 'cancreate') {
1.169 raeburn 7673: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7674: push(@{$changes->{'cancreate'}},'captcha');
7675: } elsif (!defined($changes->{'cancreate'})) {
7676: $changes->{'cancreate'} = ['captcha'];
7677: }
7678: } else {
7679: $changes->{'captcha'} = 1;
1.165 raeburn 7680: }
7681: }
7682: my ($newpub,$newpriv,$currpub,$currpriv);
7683: if ($newsettings->{'captcha'} eq 'recaptcha') {
7684: $newpub = $env{'form.'.$container.'_recaptchapub'};
7685: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.169 raeburn 7686: $newpub =~ s/\W//g;
7687: $newpriv =~ s/\W//g;
7688: $newsettings->{'recaptchakeys'} = {
7689: public => $newpub,
7690: private => $newpriv,
7691: };
1.165 raeburn 7692: }
7693: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
7694: $currpub = $current->{'recaptchakeys'}{'public'};
7695: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 7696: unless ($newsettings->{'captcha'} eq 'recaptcha') {
7697: $newsettings->{'recaptchakeys'} = {
7698: public => '',
7699: private => '',
7700: }
7701: }
1.165 raeburn 7702: }
7703: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 7704: if ($container eq 'cancreate') {
7705: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7706: push(@{$changes->{'cancreate'}},'recaptchakeys');
7707: } elsif (!defined($changes->{'cancreate'})) {
7708: $changes->{'cancreate'} = ['recaptchakeys'];
7709: }
7710: } else {
1.210 raeburn 7711: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 7712: }
7713: }
7714: return;
7715: }
7716:
1.33 raeburn 7717: sub modify_usermodification {
7718: my ($dom,%domconfig) = @_;
7719: my ($resulttext,%curr_usermodification,%changes);
7720: if (ref($domconfig{'usermodification'}) eq 'HASH') {
7721: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
7722: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
7723: }
7724: }
1.63 raeburn 7725: my @contexts = ('author','course','selfcreate');
1.33 raeburn 7726: my %context_title = (
7727: author => 'In author context',
7728: course => 'In course context',
1.63 raeburn 7729: selfcreate => 'When self creating account',
1.33 raeburn 7730: );
7731: my @fields = ('lastname','firstname','middlename','generation',
7732: 'permanentemail','id');
7733: my %roles = (
7734: author => ['ca','aa'],
7735: course => ['st','ep','ta','in','cr'],
7736: );
1.63 raeburn 7737: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7738: if (ref($types) eq 'ARRAY') {
7739: push(@{$types},'default');
7740: $usertypes->{'default'} = $othertitle;
7741: }
7742: $roles{'selfcreate'} = $types;
1.33 raeburn 7743: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7744: my %modifyhash;
7745: foreach my $context (@contexts) {
7746: foreach my $role (@{$roles{$context}}) {
7747: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
7748: foreach my $item (@fields) {
7749: if (grep(/^\Q$item\E$/,@modifiable)) {
7750: $modifyhash{$context}{$role}{$item} = 1;
7751: } else {
7752: $modifyhash{$context}{$role}{$item} = 0;
7753: }
7754: }
7755: }
7756: if (ref($curr_usermodification{$context}) eq 'HASH') {
7757: foreach my $role (@{$roles{$context}}) {
7758: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
7759: foreach my $field (@fields) {
7760: if ($modifyhash{$context}{$role}{$field} ne
7761: $curr_usermodification{$context}{$role}{$field}) {
7762: push(@{$changes{$context}},$role);
7763: last;
7764: }
7765: }
7766: }
7767: }
7768: } else {
7769: foreach my $context (@contexts) {
7770: foreach my $role (@{$roles{$context}}) {
7771: push(@{$changes{$context}},$role);
7772: }
7773: }
7774: }
7775: }
7776: my %usermodification_hash = (
7777: usermodification => \%modifyhash,
7778: );
7779: my $putresult = &Apache::lonnet::put_dom('configuration',
7780: \%usermodification_hash,$dom);
7781: if ($putresult eq 'ok') {
7782: if (keys(%changes) > 0) {
7783: $resulttext = &mt('Changes made: ').'<ul>';
7784: foreach my $context (@contexts) {
7785: if (ref($changes{$context}) eq 'ARRAY') {
7786: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
7787: if (ref($changes{$context}) eq 'ARRAY') {
7788: foreach my $role (@{$changes{$context}}) {
7789: my $rolename;
1.63 raeburn 7790: if ($context eq 'selfcreate') {
7791: $rolename = $role;
7792: if (ref($usertypes) eq 'HASH') {
7793: if ($usertypes->{$role} ne '') {
7794: $rolename = $usertypes->{$role};
7795: }
7796: }
1.33 raeburn 7797: } else {
1.63 raeburn 7798: if ($role eq 'cr') {
7799: $rolename = &mt('Custom');
7800: } else {
7801: $rolename = &Apache::lonnet::plaintext($role);
7802: }
1.33 raeburn 7803: }
7804: my @modifiable;
1.63 raeburn 7805: if ($context eq 'selfcreate') {
1.126 bisitz 7806: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Self-creation of account by users with status: [_1]',$rolename).'</span> - '.&mt('modifiable fields (if institutional data blank): ');
1.63 raeburn 7807: } else {
7808: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
7809: }
1.33 raeburn 7810: foreach my $field (@fields) {
7811: if ($modifyhash{$context}{$role}{$field}) {
7812: push(@modifiable,$fieldtitles{$field});
7813: }
7814: }
7815: if (@modifiable > 0) {
7816: $resulttext .= join(', ',@modifiable);
7817: } else {
7818: $resulttext .= &mt('none');
7819: }
7820: $resulttext .= '</li>';
7821: }
7822: $resulttext .= '</ul></li>';
7823: }
7824: }
7825: }
7826: $resulttext .= '</ul>';
7827: } else {
7828: $resulttext = &mt('No changes made to user modification settings');
7829: }
7830: } else {
7831: $resulttext = '<span class="LC_error">'.
7832: &mt('An error occurred: [_1]',$putresult).'</span>';
7833: }
7834: return $resulttext;
7835: }
7836:
1.43 raeburn 7837: sub modify_defaults {
1.212 raeburn 7838: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 7839: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 7840: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 7841: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 7842: my @authtypes = ('internal','krb4','krb5','localauth');
7843: foreach my $item (@items) {
7844: $newvalues{$item} = $env{'form.'.$item};
7845: if ($item eq 'auth_def') {
7846: if ($newvalues{$item} ne '') {
7847: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
7848: push(@errors,$item);
7849: }
7850: }
7851: } elsif ($item eq 'lang_def') {
7852: if ($newvalues{$item} ne '') {
7853: if ($newvalues{$item} =~ /^(\w+)/) {
7854: my $langcode = $1;
1.103 raeburn 7855: if ($langcode ne 'x_chef') {
7856: if (code2language($langcode) eq '') {
7857: push(@errors,$item);
7858: }
1.43 raeburn 7859: }
7860: } else {
7861: push(@errors,$item);
7862: }
7863: }
1.54 raeburn 7864: } elsif ($item eq 'timezone_def') {
7865: if ($newvalues{$item} ne '') {
1.62 raeburn 7866: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 7867: push(@errors,$item);
7868: }
7869: }
1.68 raeburn 7870: } elsif ($item eq 'datelocale_def') {
7871: if ($newvalues{$item} ne '') {
7872: my @datelocale_ids = DateTime::Locale->ids();
7873: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
7874: push(@errors,$item);
7875: }
7876: }
1.141 raeburn 7877: } elsif ($item eq 'portal_def') {
7878: if ($newvalues{$item} ne '') {
7879: 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])\/?$/) {
7880: push(@errors,$item);
7881: }
7882: }
1.43 raeburn 7883: }
7884: if (grep(/^\Q$item\E$/,@errors)) {
7885: $newvalues{$item} = $domdefaults{$item};
7886: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
7887: $changes{$item} = 1;
7888: }
1.72 raeburn 7889: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 7890: }
7891: my %defaults_hash = (
1.72 raeburn 7892: defaults => \%newvalues,
7893: );
1.43 raeburn 7894: my $title = &defaults_titles();
7895: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
7896: $dom);
7897: if ($putresult eq 'ok') {
7898: if (keys(%changes) > 0) {
7899: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 7900: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 7901: 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";
7902: foreach my $item (sort(keys(%changes))) {
7903: my $value = $env{'form.'.$item};
7904: if ($value eq '') {
7905: $value = &mt('none');
7906: } elsif ($item eq 'auth_def') {
7907: my %authnames = &authtype_names();
7908: my %shortauth = (
7909: internal => 'int',
7910: krb4 => 'krb4',
7911: krb5 => 'krb5',
7912: localauth => 'loc',
7913: );
7914: $value = $authnames{$shortauth{$value}};
7915: }
7916: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
7917: $mailmsgtext .= "$title->{$item} set to $value\n";
7918: }
7919: $resulttext .= '</ul>';
7920: $mailmsgtext .= "\n";
7921: my $cachetime = 24*60*60;
1.72 raeburn 7922: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 7923: if (ref($lastactref) eq 'HASH') {
7924: $lastactref->{'domdefaults'} = 1;
7925: }
1.68 raeburn 7926: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 7927: my $notify = 1;
7928: if (ref($domconfig{'contacts'}) eq 'HASH') {
7929: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
7930: $notify = 0;
7931: }
7932: }
7933: if ($notify) {
7934: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
7935: "LON-CAPA Domain Settings Change - $dom",
7936: $mailmsgtext);
7937: }
1.54 raeburn 7938: }
1.43 raeburn 7939: } else {
1.54 raeburn 7940: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 7941: }
7942: } else {
7943: $resulttext = '<span class="LC_error">'.
7944: &mt('An error occurred: [_1]',$putresult).'</span>';
7945: }
7946: if (@errors > 0) {
7947: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
7948: foreach my $item (@errors) {
7949: $resulttext .= ' "'.$title->{$item}.'",';
7950: }
7951: $resulttext =~ s/,$//;
7952: }
7953: return $resulttext;
7954: }
7955:
1.46 raeburn 7956: sub modify_scantron {
1.205 raeburn 7957: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 7958: my ($resulttext,%confhash,%changes,$errors);
7959: my $custom = 'custom.tab';
7960: my $default = 'default.tab';
7961: my $servadm = $r->dir_config('lonAdmEMail');
7962: my ($configuserok,$author_ok,$switchserver) =
7963: &config_check($dom,$confname,$servadm);
7964: if ($env{'form.scantronformat.filename'} ne '') {
7965: my $error;
7966: if ($configuserok eq 'ok') {
7967: if ($switchserver) {
1.130 raeburn 7968: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 7969: } else {
7970: if ($author_ok eq 'ok') {
7971: my ($result,$scantronurl) =
7972: &publishlogo($r,'upload','scantronformat',$dom,
7973: $confname,'scantron','','',$custom);
7974: if ($result eq 'ok') {
7975: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 7976: $changes{'scantronformat'} = 1;
1.46 raeburn 7977: } else {
7978: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
7979: }
7980: } else {
7981: $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);
7982: }
7983: }
7984: } else {
7985: $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);
7986: }
7987: if ($error) {
7988: &Apache::lonnet::logthis($error);
7989: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7990: }
7991: }
1.48 raeburn 7992: if (ref($domconfig{'scantron'}) eq 'HASH') {
7993: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
7994: if ($env{'form.scantronformat_del'}) {
7995: $confhash{'scantron'}{'scantronformat'} = '';
7996: $changes{'scantronformat'} = 1;
1.46 raeburn 7997: }
7998: }
7999: }
8000: if (keys(%confhash) > 0) {
8001: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
8002: $dom);
8003: if ($putresult eq 'ok') {
8004: if (keys(%changes) > 0) {
1.48 raeburn 8005: if (ref($confhash{'scantron'}) eq 'HASH') {
8006: $resulttext = &mt('Changes made:').'<ul>';
8007: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 8008: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 8009: } else {
1.130 raeburn 8010: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 8011: }
1.48 raeburn 8012: $resulttext .= '</ul>';
8013: } else {
1.130 raeburn 8014: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 8015: }
8016: $resulttext .= '</ul>';
8017: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 8018: if (ref($lastactref) eq 'HASH') {
8019: $lastactref->{'domainconfig'} = 1;
8020: }
1.46 raeburn 8021: } else {
1.130 raeburn 8022: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 8023: }
8024: } else {
8025: $resulttext = '<span class="LC_error">'.
8026: &mt('An error occurred: [_1]',$putresult).'</span>';
8027: }
8028: } else {
1.130 raeburn 8029: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 8030: }
8031: if ($errors) {
8032: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
8033: $errors.'</ul>';
8034: }
8035: return $resulttext;
8036: }
8037:
1.48 raeburn 8038: sub modify_coursecategories {
8039: my ($dom,%domconfig) = @_;
1.57 raeburn 8040: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
8041: $cathash);
1.48 raeburn 8042: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 8043: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 8044: $cathash = $domconfig{'coursecategories'}{'cats'};
8045: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
8046: $changes{'togglecats'} = 1;
8047: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
8048: }
8049: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
8050: $changes{'categorize'} = 1;
8051: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
8052: }
1.120 raeburn 8053: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
8054: $changes{'togglecatscomm'} = 1;
8055: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
8056: }
8057: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
8058: $changes{'categorizecomm'} = 1;
8059: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
8060: }
1.57 raeburn 8061: } else {
8062: $changes{'togglecats'} = 1;
8063: $changes{'categorize'} = 1;
1.124 raeburn 8064: $changes{'togglecatscomm'} = 1;
8065: $changes{'categorizecomm'} = 1;
1.87 raeburn 8066: $domconfig{'coursecategories'} = {
8067: togglecats => $env{'form.togglecats'},
8068: categorize => $env{'form.categorize'},
1.124 raeburn 8069: togglecatscomm => $env{'form.togglecatscomm'},
8070: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 8071: };
1.57 raeburn 8072: }
8073: if (ref($cathash) eq 'HASH') {
8074: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 8075: push (@deletecategory,'instcode::0');
8076: }
1.120 raeburn 8077: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
8078: push(@deletecategory,'communities::0');
8079: }
1.48 raeburn 8080: }
1.57 raeburn 8081: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
8082: if (ref($cathash) eq 'HASH') {
1.48 raeburn 8083: if (@deletecategory > 0) {
8084: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 8085: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 8086: foreach my $item (@deletecategory) {
1.57 raeburn 8087: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
8088: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 8089: $deletions{$item} = 1;
1.57 raeburn 8090: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 8091: }
8092: }
8093: }
1.57 raeburn 8094: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 8095: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 8096: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 8097: $reorderings{$item} = 1;
1.57 raeburn 8098: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 8099: }
8100: if ($env{'form.addcategory_name_'.$item} ne '') {
8101: my $newcat = $env{'form.addcategory_name_'.$item};
8102: my $newdepth = $depth+1;
8103: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 8104: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 8105: $adds{$newitem} = 1;
8106: }
8107: if ($env{'form.subcat_'.$item} ne '') {
8108: my $newcat = $env{'form.subcat_'.$item};
8109: my $newdepth = $depth+1;
8110: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 8111: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 8112: $adds{$newitem} = 1;
8113: }
8114: }
8115: }
8116: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 8117: if (ref($cathash) eq 'HASH') {
1.48 raeburn 8118: my $newitem = 'instcode::0';
1.57 raeburn 8119: if ($cathash->{$newitem} eq '') {
8120: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 8121: $adds{$newitem} = 1;
8122: }
8123: } else {
8124: my $newitem = 'instcode::0';
1.57 raeburn 8125: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 8126: $adds{$newitem} = 1;
8127: }
8128: }
1.120 raeburn 8129: if ($env{'form.communities'} eq '1') {
8130: if (ref($cathash) eq 'HASH') {
8131: my $newitem = 'communities::0';
8132: if ($cathash->{$newitem} eq '') {
8133: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
8134: $adds{$newitem} = 1;
8135: }
8136: } else {
8137: my $newitem = 'communities::0';
8138: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
8139: $adds{$newitem} = 1;
8140: }
8141: }
1.48 raeburn 8142: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 8143: if (($env{'form.addcategory_name'} ne 'instcode') &&
8144: ($env{'form.addcategory_name'} ne 'communities')) {
8145: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
8146: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
8147: $adds{$newitem} = 1;
8148: }
1.48 raeburn 8149: }
1.57 raeburn 8150: my $putresult;
1.48 raeburn 8151: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
8152: if (keys(%deletions) > 0) {
8153: foreach my $key (keys(%deletions)) {
8154: if ($predelallitems{$key} ne '') {
8155: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
8156: }
8157: }
8158: }
8159: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 8160: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 8161: if (ref($chkcats[0]) eq 'ARRAY') {
8162: my $depth = 0;
8163: my $chg = 0;
8164: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
8165: my $name = $chkcats[0][$i];
8166: my $item;
8167: if ($name eq '') {
8168: $chg ++;
8169: } else {
8170: $item = &escape($name).'::0';
8171: if ($chg) {
1.57 raeburn 8172: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 8173: }
8174: $depth ++;
1.57 raeburn 8175: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 8176: $depth --;
8177: }
8178: }
8179: }
1.57 raeburn 8180: }
8181: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
8182: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 8183: if ($putresult eq 'ok') {
1.57 raeburn 8184: my %title = (
1.120 raeburn 8185: togglecats => 'Show/Hide a course in catalog',
8186: categorize => 'Assign a category to a course',
8187: togglecatscomm => 'Show/Hide a community in catalog',
8188: categorizecomm => 'Assign a category to a community',
1.57 raeburn 8189: );
8190: my %level = (
1.120 raeburn 8191: dom => 'set in Domain ("Modify Course/Community")',
8192: crs => 'set in Course ("Course Configuration")',
8193: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 8194: );
1.48 raeburn 8195: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 8196: if ($changes{'togglecats'}) {
8197: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
8198: }
8199: if ($changes{'categorize'}) {
8200: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 8201: }
1.120 raeburn 8202: if ($changes{'togglecatscomm'}) {
8203: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
8204: }
8205: if ($changes{'categorizecomm'}) {
8206: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
8207: }
1.57 raeburn 8208: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
8209: my $cathash;
8210: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
8211: $cathash = $domconfig{'coursecategories'}{'cats'};
8212: } else {
8213: $cathash = {};
8214: }
8215: my (@cats,@trails,%allitems);
8216: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
8217: if (keys(%deletions) > 0) {
8218: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
8219: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
8220: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
8221: }
8222: $resulttext .= '</ul></li>';
8223: }
8224: if (keys(%reorderings) > 0) {
8225: my %sort_by_trail;
8226: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
8227: foreach my $key (keys(%reorderings)) {
8228: if ($allitems{$key} ne '') {
8229: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
8230: }
1.48 raeburn 8231: }
1.57 raeburn 8232: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
8233: $resulttext .= '<li>'.$trails[$trail].'</li>';
8234: }
8235: $resulttext .= '</ul></li>';
1.48 raeburn 8236: }
1.57 raeburn 8237: if (keys(%adds) > 0) {
8238: my %sort_by_trail;
8239: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
8240: foreach my $key (keys(%adds)) {
8241: if ($allitems{$key} ne '') {
8242: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
8243: }
8244: }
8245: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
8246: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 8247: }
1.57 raeburn 8248: $resulttext .= '</ul></li>';
1.48 raeburn 8249: }
8250: }
8251: $resulttext .= '</ul>';
8252: } else {
8253: $resulttext = '<span class="LC_error">'.
1.57 raeburn 8254: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 8255: }
8256: } else {
1.120 raeburn 8257: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 8258: }
8259: return $resulttext;
8260: }
8261:
1.69 raeburn 8262: sub modify_serverstatuses {
8263: my ($dom,%domconfig) = @_;
8264: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
8265: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
8266: %currserverstatus = %{$domconfig{'serverstatuses'}};
8267: }
8268: my @pages = &serverstatus_pages();
8269: foreach my $type (@pages) {
8270: $newserverstatus{$type}{'namedusers'} = '';
8271: $newserverstatus{$type}{'machines'} = '';
8272: if (defined($env{'form.'.$type.'_namedusers'})) {
8273: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
8274: my @okusers;
8275: foreach my $user (@users) {
8276: my ($uname,$udom) = split(/:/,$user);
8277: if (($udom =~ /^$match_domain$/) &&
8278: (&Apache::lonnet::domain($udom)) &&
8279: ($uname =~ /^$match_username$/)) {
8280: if (!grep(/^\Q$user\E/,@okusers)) {
8281: push(@okusers,$user);
8282: }
8283: }
8284: }
8285: if (@okusers > 0) {
8286: @okusers = sort(@okusers);
8287: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
8288: }
8289: }
8290: if (defined($env{'form.'.$type.'_machines'})) {
8291: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
8292: my @okmachines;
8293: foreach my $ip (@machines) {
8294: my @parts = split(/\./,$ip);
8295: next if (@parts < 4);
8296: my $badip = 0;
8297: for (my $i=0; $i<4; $i++) {
8298: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
8299: $badip = 1;
8300: last;
8301: }
8302: }
8303: if (!$badip) {
8304: push(@okmachines,$ip);
8305: }
8306: }
8307: @okmachines = sort(@okmachines);
8308: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
8309: }
8310: }
8311: my %serverstatushash = (
8312: serverstatuses => \%newserverstatus,
8313: );
8314: foreach my $type (@pages) {
1.83 raeburn 8315: foreach my $setting ('namedusers','machines') {
1.84 raeburn 8316: my (@current,@new);
1.83 raeburn 8317: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 8318: if ($currserverstatus{$type}{$setting} ne '') {
8319: @current = split(/,/,$currserverstatus{$type}{$setting});
8320: }
8321: }
8322: if ($newserverstatus{$type}{$setting} ne '') {
8323: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 8324: }
8325: if (@current > 0) {
8326: if (@new > 0) {
8327: foreach my $item (@current) {
8328: if (!grep(/^\Q$item\E$/,@new)) {
8329: $changes{$type}{$setting} = 1;
1.82 raeburn 8330: last;
8331: }
8332: }
1.84 raeburn 8333: foreach my $item (@new) {
8334: if (!grep(/^\Q$item\E$/,@current)) {
8335: $changes{$type}{$setting} = 1;
8336: last;
1.82 raeburn 8337: }
8338: }
8339: } else {
1.83 raeburn 8340: $changes{$type}{$setting} = 1;
1.69 raeburn 8341: }
1.83 raeburn 8342: } elsif (@new > 0) {
8343: $changes{$type}{$setting} = 1;
1.69 raeburn 8344: }
8345: }
8346: }
8347: if (keys(%changes) > 0) {
1.81 raeburn 8348: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 8349: my $putresult = &Apache::lonnet::put_dom('configuration',
8350: \%serverstatushash,$dom);
8351: if ($putresult eq 'ok') {
8352: $resulttext .= &mt('Changes made:').'<ul>';
8353: foreach my $type (@pages) {
1.84 raeburn 8354: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 8355: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 8356: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 8357: if ($newserverstatus{$type}{'namedusers'} eq '') {
8358: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
8359: } else {
8360: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
8361: }
1.84 raeburn 8362: }
8363: if ($changes{$type}{'machines'}) {
1.69 raeburn 8364: if ($newserverstatus{$type}{'machines'} eq '') {
8365: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
8366: } else {
8367: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
8368: }
8369:
8370: }
8371: $resulttext .= '</ul></li>';
8372: }
8373: }
8374: $resulttext .= '</ul>';
8375: } else {
8376: $resulttext = '<span class="LC_error">'.
8377: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
8378:
8379: }
8380: } else {
8381: $resulttext = &mt('No changes made to access to server status pages');
8382: }
8383: return $resulttext;
8384: }
8385:
1.118 jms 8386: sub modify_helpsettings {
1.122 jms 8387: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 8388: my ($resulttext,$errors,%changes,%helphash);
8389: my %defaultchecked = ('submitbugs' => 'on');
8390: my @offon = ('off','on');
1.118 jms 8391: my @toggles = ('submitbugs');
8392: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8393: foreach my $item (@toggles) {
1.166 raeburn 8394: if ($defaultchecked{$item} eq 'on') {
8395: if ($domconfig{'helpsettings'}{$item} eq '') {
8396: if ($env{'form.'.$item} eq '0') {
8397: $changes{$item} = 1;
8398: }
8399: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
8400: $changes{$item} = 1;
8401: }
8402: } elsif ($defaultchecked{$item} eq 'off') {
8403: if ($domconfig{'helpsettings'}{$item} eq '') {
8404: if ($env{'form.'.$item} eq '1') {
8405: $changes{$item} = 1;
8406: }
8407: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
8408: $changes{$item} = 1;
8409: }
8410: }
1.210 raeburn 8411: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
1.166 raeburn 8412: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
8413: }
8414: }
1.118 jms 8415: }
1.123 jms 8416: my $putresult;
8417: if (keys(%changes) > 0) {
1.166 raeburn 8418: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 8419: if ($putresult eq 'ok') {
1.166 raeburn 8420: $resulttext = &mt('Changes made:').'<ul>';
8421: foreach my $item (sort(keys(%changes))) {
8422: if ($item eq 'submitbugs') {
8423: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
8424: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
8425: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
8426: }
8427: }
8428: $resulttext .= '</ul>';
8429: } else {
8430: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 8431: $errors .= '<li><span class="LC_error">'.
8432: &mt('An error occurred storing the settings: [_1]',
8433: $putresult).'</span></li>';
1.166 raeburn 8434: }
1.118 jms 8435: }
8436: if ($errors) {
1.168 raeburn 8437: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 8438: $errors.'</ul>';
8439: }
8440: return $resulttext;
8441: }
8442:
1.121 raeburn 8443: sub modify_coursedefaults {
1.212 raeburn 8444: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 8445: my ($resulttext,$errors,%changes,%defaultshash);
8446: my %defaultchecked = ('canuse_pdfforms' => 'off');
8447: my @toggles = ('canuse_pdfforms');
1.198 raeburn 8448: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.216 ! raeburn 8449: 'uploadquota_community','uploadquota_textbook');
! 8450: my @types = ('official','unofficial','community','textbook');
1.198 raeburn 8451: my %staticdefaults = (
8452: anonsurvey_threshold => 10,
8453: uploadquota => 500,
8454: );
1.121 raeburn 8455:
8456: $defaultshash{'coursedefaults'} = {};
8457:
8458: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
8459: if ($domconfig{'coursedefaults'} eq '') {
8460: $domconfig{'coursedefaults'} = {};
8461: }
8462: }
8463:
8464: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
8465: foreach my $item (@toggles) {
8466: if ($defaultchecked{$item} eq 'on') {
8467: if (($domconfig{'coursedefaults'}{$item} eq '') &&
8468: ($env{'form.'.$item} eq '0')) {
8469: $changes{$item} = 1;
1.192 raeburn 8470: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 8471: $changes{$item} = 1;
8472: }
8473: } elsif ($defaultchecked{$item} eq 'off') {
8474: if (($domconfig{'coursedefaults'}{$item} eq '') &&
8475: ($env{'form.'.$item} eq '1')) {
8476: $changes{$item} = 1;
8477: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
8478: $changes{$item} = 1;
8479: }
8480: }
8481: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
8482: }
1.198 raeburn 8483: foreach my $item (@numbers) {
8484: my ($currdef,$newdef);
1.208 raeburn 8485: $newdef = $env{'form.'.$item};
1.198 raeburn 8486: if ($item eq 'anonsurvey_threshold') {
8487: $currdef = $domconfig{'coursedefaults'}{$item};
8488: $newdef =~ s/\D//g;
8489: if ($newdef eq '' || $newdef < 1) {
8490: $newdef = 1;
8491: }
8492: $defaultshash{'coursedefaults'}{$item} = $newdef;
8493: } else {
8494: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
8495: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8496: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
8497: }
8498: $newdef =~ s/[^\w.\-]//g;
8499: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
8500: }
8501: if ($currdef ne $newdef) {
8502: my $staticdef;
8503: if ($item eq 'anonsurvey_threshold') {
8504: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
8505: $changes{$item} = 1;
8506: }
8507: } else {
8508: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
8509: $changes{'uploadquota'} = 1;
8510: }
8511: }
1.139 raeburn 8512: }
8513: }
1.192 raeburn 8514: my $officialcreds = $env{'form.official_credits'};
1.216 ! raeburn 8515: $officialcreds =~ s/[^\d.]+//g;
1.192 raeburn 8516: my $unofficialcreds = $env{'form.unofficial_credits'};
1.216 ! raeburn 8517: $unofficialcreds =~ s/[^\d.]+//g;
! 8518: my $textbookcreds = $env{'form.textbook_credits'};
! 8519: $textbookcreds =~ s/[^\d.]+//g;
1.192 raeburn 8520: if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
8521: ($env{'form.coursecredits'} eq '1')) {
8522: $changes{'coursecredits'} = 1;
8523: } else {
8524: if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
1.216 ! raeburn 8525: ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds) ||
! 8526: ($domconfig{'coursedefaults'}{'coursecredits'}{'textbook'} ne $textbookcreds)) {
1.192 raeburn 8527: $changes{'coursecredits'} = 1;
8528: }
8529: }
8530: $defaultshash{'coursedefaults'}{'coursecredits'} = {
8531: official => $officialcreds,
8532: unofficial => $unofficialcreds,
1.216 ! raeburn 8533: textbook => $textbookcreds,
1.192 raeburn 8534: }
1.121 raeburn 8535: }
8536: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8537: $dom);
8538: if ($putresult eq 'ok') {
8539: if (keys(%changes) > 0) {
1.213 raeburn 8540: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.198 raeburn 8541: if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) || ($changes{'uploadquota'})) {
1.192 raeburn 8542: if ($changes{'canuse_pdfforms'}) {
8543: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
8544: }
8545: if ($changes{'coursecredits'}) {
8546: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
8547: $domdefaults{'officialcredits'} =
8548: $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
8549: $domdefaults{'unofficialcredits'} =
8550: $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
1.216 ! raeburn 8551: $domdefaults{'textbookcredits'} =
! 8552: $domdefaults{'coursedefaults'}{'coursecredits'}{'textbook'};
1.192 raeburn 8553: }
8554: }
1.198 raeburn 8555: if ($changes{'uploadquota'}) {
8556: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8557: foreach my $type (@types) {
8558: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
8559: }
8560: }
8561: }
1.121 raeburn 8562: my $cachetime = 24*60*60;
8563: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 8564: if (ref($lastactref) eq 'HASH') {
8565: $lastactref->{'domdefaults'} = 1;
8566: }
1.121 raeburn 8567: }
8568: $resulttext = &mt('Changes made:').'<ul>';
8569: foreach my $item (sort(keys(%changes))) {
8570: if ($item eq 'canuse_pdfforms') {
8571: if ($env{'form.'.$item} eq '1') {
8572: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
8573: } else {
8574: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
8575: }
1.139 raeburn 8576: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 8577: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 8578: } elsif ($item eq 'uploadquota') {
8579: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8580: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
8581: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
8582: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 ! raeburn 8583: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
! 8584:
1.198 raeburn 8585: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
8586: '</ul>'.
8587: '</li>';
8588: } else {
8589: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
8590: }
1.192 raeburn 8591: } elsif ($item eq 'coursecredits') {
8592: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
8593: if (($domdefaults{'officialcredits'} eq '') &&
1.216 ! raeburn 8594: ($domdefaults{'unofficialcredits'} eq '') &&
! 8595: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 8596: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
8597: } else {
8598: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
8599: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
8600: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 ! raeburn 8601: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 8602: '</ul>'.
8603: '</li>';
8604: }
8605: } else {
8606: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
8607: }
1.140 raeburn 8608: }
1.121 raeburn 8609: }
8610: $resulttext .= '</ul>';
8611: } else {
8612: $resulttext = &mt('No changes made to course defaults');
8613: }
8614: } else {
8615: $resulttext = '<span class="LC_error">'.
8616: &mt('An error occurred: [_1]',$putresult).'</span>';
8617: }
8618: return $resulttext;
8619: }
8620:
1.137 raeburn 8621: sub modify_usersessions {
1.212 raeburn 8622: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 8623: my @hostingtypes = ('version','excludedomain','includedomain');
8624: my @offloadtypes = ('primary','default');
8625: my %types = (
8626: remote => \@hostingtypes,
8627: hosted => \@hostingtypes,
8628: spares => \@offloadtypes,
8629: );
8630: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 8631: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 8632: my (%by_ip,%by_location,@intdoms);
8633: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
8634: my @locations = sort(keys(%by_location));
1.137 raeburn 8635: my (%defaultshash,%changes);
8636: foreach my $prefix (@prefixes) {
8637: $defaultshash{'usersessions'}{$prefix} = {};
8638: }
1.212 raeburn 8639: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 8640: my $resulttext;
1.138 raeburn 8641: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 8642: foreach my $prefix (@prefixes) {
1.145 raeburn 8643: next if ($prefix eq 'spares');
8644: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 8645: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
8646: if ($type eq 'version') {
8647: my $value = $env{'form.'.$prefix.'_'.$type};
8648: my $okvalue;
8649: if ($value ne '') {
8650: if (grep(/^\Q$value\E$/,@lcversions)) {
8651: $okvalue = $value;
8652: }
8653: }
8654: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8655: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
8656: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
8657: if ($inuse == 0) {
8658: $changes{$prefix}{$type} = 1;
8659: } else {
8660: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
8661: $changes{$prefix}{$type} = 1;
8662: }
8663: if ($okvalue ne '') {
8664: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8665: }
8666: }
8667: } else {
8668: if (($inuse == 1) && ($okvalue ne '')) {
8669: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8670: $changes{$prefix}{$type} = 1;
8671: }
8672: }
8673: } else {
8674: if (($inuse == 1) && ($okvalue ne '')) {
8675: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8676: $changes{$prefix}{$type} = 1;
8677: }
8678: }
8679: } else {
8680: if (($inuse == 1) && ($okvalue ne '')) {
8681: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8682: $changes{$prefix}{$type} = 1;
8683: }
8684: }
8685: } else {
8686: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
8687: my @okvals;
8688: foreach my $val (@vals) {
1.138 raeburn 8689: if ($val =~ /:/) {
8690: my @items = split(/:/,$val);
8691: foreach my $item (@items) {
8692: if (ref($by_location{$item}) eq 'ARRAY') {
8693: push(@okvals,$item);
8694: }
8695: }
8696: } else {
8697: if (ref($by_location{$val}) eq 'ARRAY') {
8698: push(@okvals,$val);
8699: }
1.137 raeburn 8700: }
8701: }
8702: @okvals = sort(@okvals);
8703: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8704: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
8705: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8706: if ($inuse == 0) {
8707: $changes{$prefix}{$type} = 1;
8708: } else {
8709: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8710: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
8711: if (@changed > 0) {
8712: $changes{$prefix}{$type} = 1;
8713: }
8714: }
8715: } else {
8716: if ($inuse == 1) {
8717: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8718: $changes{$prefix}{$type} = 1;
8719: }
8720: }
8721: } else {
8722: if ($inuse == 1) {
8723: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8724: $changes{$prefix}{$type} = 1;
8725: }
8726: }
8727: } else {
8728: if ($inuse == 1) {
8729: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8730: $changes{$prefix}{$type} = 1;
8731: }
8732: }
8733: }
8734: }
8735: }
1.145 raeburn 8736:
8737: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 8738: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 8739: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
8740: my $savespares;
8741:
8742: foreach my $lonhost (sort(keys(%servers))) {
8743: my $serverhomeID =
8744: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 8745: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 8746: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
8747: my %spareschg;
8748: foreach my $type (@{$types{'spares'}}) {
8749: my @okspares;
8750: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
8751: foreach my $server (@checked) {
1.152 raeburn 8752: if (&Apache::lonnet::hostname($server) ne '') {
8753: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
8754: unless (grep(/^\Q$server\E$/,@okspares)) {
8755: push(@okspares,$server);
8756: }
1.145 raeburn 8757: }
8758: }
8759: }
8760: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
8761: my $newspare;
1.152 raeburn 8762: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
8763: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 8764: $newspare = $new;
8765: }
8766: }
1.152 raeburn 8767: my @spares;
8768: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
8769: @spares = sort(@okspares,$newspare);
8770: } else {
8771: @spares = sort(@okspares);
8772: }
8773: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 8774: if (ref($spareid{$lonhost}) eq 'HASH') {
8775: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 8776: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 8777: if (@diffs > 0) {
8778: $spareschg{$type} = 1;
8779: }
8780: }
8781: }
8782: }
8783: if (keys(%spareschg) > 0) {
8784: $changes{'spares'}{$lonhost} = \%spareschg;
8785: }
8786: }
8787:
8788: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8789: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
8790: if (ref($changes{'spares'}) eq 'HASH') {
8791: if (keys(%{$changes{'spares'}}) > 0) {
8792: $savespares = 1;
8793: }
8794: }
8795: } else {
8796: $savespares = 1;
8797: }
8798: }
8799:
1.147 raeburn 8800: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
8801: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 8802: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8803: $dom);
8804: if ($putresult eq 'ok') {
8805: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8806: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
8807: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
8808: }
8809: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
8810: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
8811: }
8812: }
8813: my $cachetime = 24*60*60;
8814: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 8815: if (ref($lastactref) eq 'HASH') {
8816: $lastactref->{'domdefaults'} = 1;
8817: }
1.147 raeburn 8818: if (keys(%changes) > 0) {
8819: my %lt = &usersession_titles();
8820: $resulttext = &mt('Changes made:').'<ul>';
8821: foreach my $prefix (@prefixes) {
8822: if (ref($changes{$prefix}) eq 'HASH') {
8823: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
8824: if ($prefix eq 'spares') {
8825: if (ref($changes{$prefix}) eq 'HASH') {
8826: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
8827: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 8828: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 8829: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
8830: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 8831: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
8832: foreach my $type (@{$types{$prefix}}) {
8833: if ($changes{$prefix}{$lonhost}{$type}) {
8834: my $offloadto = &mt('None');
8835: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
8836: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
8837: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
8838: }
1.145 raeburn 8839: }
1.147 raeburn 8840: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 8841: }
1.137 raeburn 8842: }
8843: }
1.147 raeburn 8844: $resulttext .= '</li>';
1.137 raeburn 8845: }
8846: }
1.147 raeburn 8847: } else {
8848: foreach my $type (@{$types{$prefix}}) {
8849: if (defined($changes{$prefix}{$type})) {
8850: my $newvalue;
8851: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8852: if (ref($defaultshash{'usersessions'}{$prefix})) {
8853: if ($type eq 'version') {
8854: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
8855: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8856: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
8857: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
8858: }
1.145 raeburn 8859: }
8860: }
8861: }
1.147 raeburn 8862: if ($newvalue eq '') {
8863: if ($type eq 'version') {
8864: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
8865: } else {
8866: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
8867: }
1.145 raeburn 8868: } else {
1.147 raeburn 8869: if ($type eq 'version') {
8870: $newvalue .= ' '.&mt('(or later)');
8871: }
8872: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 8873: }
1.137 raeburn 8874: }
8875: }
8876: }
1.147 raeburn 8877: $resulttext .= '</ul>';
1.137 raeburn 8878: }
8879: }
1.147 raeburn 8880: $resulttext .= '</ul>';
8881: } else {
8882: $resulttext = $nochgmsg;
1.137 raeburn 8883: }
8884: } else {
8885: $resulttext = '<span class="LC_error">'.
8886: &mt('An error occurred: [_1]',$putresult).'</span>';
8887: }
8888: } else {
1.147 raeburn 8889: $resulttext = $nochgmsg;
1.137 raeburn 8890: }
8891: return $resulttext;
8892: }
8893:
1.150 raeburn 8894: sub modify_loadbalancing {
8895: my ($dom,%domconfig) = @_;
8896: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8897: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8898: my ($othertitle,$usertypes,$types) =
8899: &Apache::loncommon::sorted_inst_types($dom);
8900: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8901: my @sparestypes = ('primary','default');
8902: my %typetitles = &sparestype_titles();
8903: my $resulttext;
1.171 raeburn 8904: my (%currbalancer,%currtargets,%currrules,%existing);
8905: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8906: %existing = %{$domconfig{'loadbalancing'}};
8907: }
8908: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
8909: \%currtargets,\%currrules);
8910: my ($saveloadbalancing,%defaultshash,%changes);
8911: my ($alltypes,$othertypes,$titles) =
8912: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8913: my %ruletitles = &offloadtype_text();
8914: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
8915: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
8916: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
8917: if ($balancer eq '') {
8918: next;
8919: }
1.210 raeburn 8920: if (!exists($servers{$balancer})) {
1.171 raeburn 8921: if (exists($currbalancer{$balancer})) {
8922: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 8923: }
1.171 raeburn 8924: next;
8925: }
8926: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
8927: push(@{$changes{'delete'}},$balancer);
8928: next;
8929: }
8930: if (!exists($currbalancer{$balancer})) {
8931: push(@{$changes{'add'}},$balancer);
8932: }
8933: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
8934: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
8935: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
8936: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8937: $saveloadbalancing = 1;
8938: }
8939: foreach my $sparetype (@sparestypes) {
8940: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
8941: my @offloadto;
8942: foreach my $target (@targets) {
8943: if (($servers{$target}) && ($target ne $balancer)) {
8944: if ($sparetype eq 'default') {
8945: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
8946: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 8947: }
8948: }
1.171 raeburn 8949: unless(grep(/^\Q$target\E$/,@offloadto)) {
8950: push(@offloadto,$target);
8951: }
1.150 raeburn 8952: }
1.171 raeburn 8953: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 8954: }
8955: }
1.171 raeburn 8956: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 8957: foreach my $sparetype (@sparestypes) {
1.171 raeburn 8958: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
8959: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 8960: if (@targetdiffs > 0) {
1.171 raeburn 8961: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8962: }
1.171 raeburn 8963: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8964: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8965: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8966: }
8967: }
8968: }
8969: } else {
1.171 raeburn 8970: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 8971: foreach my $sparetype (@sparestypes) {
1.171 raeburn 8972: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8973: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8974: $changes{'curr'}{$balancer}{'targets'} = 1;
8975: }
1.150 raeburn 8976: }
8977: }
1.210 raeburn 8978: }
1.150 raeburn 8979: }
8980: my $ishomedom;
1.171 raeburn 8981: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
8982: $ishomedom = 1;
1.150 raeburn 8983: }
8984: if (ref($alltypes) eq 'ARRAY') {
8985: foreach my $type (@{$alltypes}) {
8986: my $rule;
1.210 raeburn 8987: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 8988: (!$ishomedom)) {
1.171 raeburn 8989: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
8990: }
8991: if ($rule eq 'specific') {
8992: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 8993: }
1.171 raeburn 8994: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
8995: if (ref($currrules{$balancer}) eq 'HASH') {
8996: if ($rule ne $currrules{$balancer}{$type}) {
8997: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8998: }
8999: } elsif ($rule ne '') {
1.171 raeburn 9000: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 9001: }
9002: }
9003: }
1.171 raeburn 9004: }
9005: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
9006: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
9007: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
9008: $defaultshash{'loadbalancing'} = {};
9009: }
9010: my $putresult = &Apache::lonnet::put_dom('configuration',
9011: \%defaultshash,$dom);
9012: if ($putresult eq 'ok') {
9013: if (keys(%changes) > 0) {
9014: if (ref($changes{'delete'}) eq 'ARRAY') {
9015: foreach my $balancer (sort(@{$changes{'delete'}})) {
9016: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.211 raeburn 9017: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
9018: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 9019: }
1.171 raeburn 9020: }
9021: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 9022: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 9023: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
9024: }
9025: }
9026: if (ref($changes{'curr'}) eq 'HASH') {
9027: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
9028: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
9029: if ($changes{'curr'}{$balancer}{'targets'}) {
9030: my %offloadstr;
9031: foreach my $sparetype (@sparestypes) {
9032: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
9033: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
9034: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
9035: }
9036: }
1.150 raeburn 9037: }
1.171 raeburn 9038: if (keys(%offloadstr) == 0) {
9039: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 9040: } else {
1.171 raeburn 9041: my $showoffload;
9042: foreach my $sparetype (@sparestypes) {
9043: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
9044: if (defined($offloadstr{$sparetype})) {
9045: $showoffload .= $offloadstr{$sparetype};
9046: } else {
9047: $showoffload .= &mt('None');
9048: }
9049: $showoffload .= (' 'x3);
9050: }
9051: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 9052: }
9053: }
9054: }
1.171 raeburn 9055: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
9056: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
9057: foreach my $type (@{$alltypes}) {
9058: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
9059: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
9060: my $balancetext;
9061: if ($rule eq '') {
9062: $balancetext = $ruletitles{'default'};
1.209 raeburn 9063: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
9064: ($rule eq 'balancer') || ($rule eq 'offloadedto')) {
1.171 raeburn 9065: $balancetext = $ruletitles{$rule};
9066: } else {
9067: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
9068: }
1.210 raeburn 9069: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 9070: }
9071: }
9072: }
9073: }
1.215 raeburn 9074: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
1.211 raeburn 9075: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 9076: }
1.171 raeburn 9077: }
9078: if ($resulttext ne '') {
9079: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 9080: } else {
9081: $resulttext = $nochgmsg;
9082: }
9083: } else {
1.171 raeburn 9084: $resulttext = $nochgmsg;
1.150 raeburn 9085: }
9086: } else {
1.171 raeburn 9087: $resulttext = '<span class="LC_error">'.
9088: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 9089: }
9090: } else {
1.171 raeburn 9091: $resulttext = $nochgmsg;
1.150 raeburn 9092: }
9093: return $resulttext;
9094: }
9095:
1.48 raeburn 9096: sub recurse_check {
9097: my ($chkcats,$categories,$depth,$name) = @_;
9098: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
9099: my $chg = 0;
9100: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
9101: my $category = $chkcats->[$depth]{$name}[$j];
9102: my $item;
9103: if ($category eq '') {
9104: $chg ++;
9105: } else {
9106: my $deeper = $depth + 1;
9107: $item = &escape($category).':'.&escape($name).':'.$depth;
9108: if ($chg) {
9109: $categories->{$item} -= $chg;
9110: }
9111: &recurse_check($chkcats,$categories,$deeper,$category);
9112: $deeper --;
9113: }
9114: }
9115: }
9116: return;
9117: }
9118:
9119: sub recurse_cat_deletes {
9120: my ($item,$coursecategories,$deletions) = @_;
9121: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9122: my $subdepth = $depth + 1;
9123: if (ref($coursecategories) eq 'HASH') {
9124: foreach my $subitem (keys(%{$coursecategories})) {
9125: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
9126: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
9127: delete($coursecategories->{$subitem});
9128: $deletions->{$subitem} = 1;
9129: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 9130: }
1.48 raeburn 9131: }
9132: }
9133: return;
9134: }
9135:
1.125 raeburn 9136: sub get_active_dcs {
9137: my ($dom) = @_;
1.191 raeburn 9138: my $now = time;
9139: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 9140: my %domcoords;
9141: my $numdcs = 0;
9142: foreach my $server (keys(%dompersonnel)) {
9143: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
9144: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.191 raeburn 9145: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 9146: }
9147: }
9148: return %domcoords;
9149: }
9150:
9151: sub active_dc_picker {
1.191 raeburn 9152: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.125 raeburn 9153: my %domcoords = &get_active_dcs($dom);
1.191 raeburn 9154: my @domcoord = keys(%domcoords);
9155: if (keys(%currhash)) {
9156: foreach my $dc (keys(%currhash)) {
9157: unless (exists($domcoords{$dc})) {
9158: push(@domcoord,$dc);
9159: }
9160: }
9161: }
9162: @domcoord = sort(@domcoord);
1.210 raeburn 9163: my $numdcs = scalar(@domcoord);
1.191 raeburn 9164: my $rows = 0;
9165: my $table;
1.125 raeburn 9166: if ($numdcs > 1) {
1.191 raeburn 9167: $table = '<table>';
9168: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 9169: my $rem = $i%($numinrow);
9170: if ($rem == 0) {
9171: if ($i > 0) {
1.191 raeburn 9172: $table .= '</tr>';
1.125 raeburn 9173: }
1.191 raeburn 9174: $table .= '<tr>';
9175: $rows ++;
1.125 raeburn 9176: }
1.191 raeburn 9177: my $check = '';
9178: if ($inputtype eq 'radio') {
9179: if (keys(%currhash) == 0) {
9180: if (!$i) {
9181: $check = ' checked="checked"';
9182: }
9183: } elsif (exists($currhash{$domcoord[$i]})) {
9184: $check = ' checked="checked"';
9185: }
9186: } else {
9187: if (exists($currhash{$domcoord[$i]})) {
9188: $check = ' checked="checked"';
1.125 raeburn 9189: }
9190: }
1.191 raeburn 9191: if ($i == @domcoord - 1) {
1.125 raeburn 9192: my $colsleft = $numinrow - $rem;
9193: if ($colsleft > 1) {
1.191 raeburn 9194: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 9195: } else {
1.191 raeburn 9196: $table .= '<td class="LC_left_item">';
1.125 raeburn 9197: }
9198: } else {
1.191 raeburn 9199: $table .= '<td class="LC_left_item">';
9200: }
9201: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
9202: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
9203: $table .= '<span class="LC_nobreak"><label>'.
9204: '<input type="'.$inputtype.'" name="'.$name.'"'.
9205: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
9206: if ($user ne $dcname.':'.$dcdom) {
9207: $table .= ' ('.$dcname.':'.$dcdom.')'.
9208: '</label></span></td>';
9209: }
9210: }
9211: $table .= '</tr></table>';
9212: } elsif ($numdcs == 1) {
9213: if ($inputtype eq 'radio') {
9214: $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />';
9215: } else {
9216: my $check;
9217: if (exists($currhash{$domcoord[0]})) {
9218: $check = ' checked="checked"';
1.125 raeburn 9219: }
1.191 raeburn 9220: $table .= '<input type="checkbox" name="'.$name.'" '.
9221: 'value="'.$domcoord[0].'"'.$check.' />';
9222: $rows ++;
1.125 raeburn 9223: }
9224: }
1.191 raeburn 9225: return ($numdcs,$table,$rows);
1.125 raeburn 9226: }
9227:
1.137 raeburn 9228: sub usersession_titles {
9229: return &Apache::lonlocal::texthash(
9230: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
9231: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 9232: spares => 'Servers offloaded to, when busy',
1.137 raeburn 9233: version => 'LON-CAPA version requirement',
1.138 raeburn 9234: excludedomain => 'Allow all, but exclude specific domains',
9235: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 9236: primary => 'Primary (checked first)',
1.154 raeburn 9237: default => 'Default',
1.137 raeburn 9238: );
9239: }
9240:
1.152 raeburn 9241: sub id_for_thisdom {
9242: my (%servers) = @_;
9243: my %altids;
9244: foreach my $server (keys(%servers)) {
9245: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
9246: if ($serverhome ne $server) {
9247: $altids{$serverhome} = $server;
9248: }
9249: }
9250: return %altids;
9251: }
9252:
1.150 raeburn 9253: sub count_servers {
9254: my ($currbalancer,%servers) = @_;
9255: my (@spares,$numspares);
9256: foreach my $lonhost (sort(keys(%servers))) {
9257: next if ($currbalancer eq $lonhost);
9258: push(@spares,$lonhost);
9259: }
9260: if ($currbalancer) {
9261: $numspares = scalar(@spares);
9262: } else {
9263: $numspares = scalar(@spares) - 1;
9264: }
9265: return ($numspares,@spares);
9266: }
9267:
9268: sub lonbalance_targets_js {
1.171 raeburn 9269: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 9270: my $select = &mt('Select');
9271: my ($alltargets,$allishome,$allinsttypes,@alltypes);
9272: if (ref($servers) eq 'HASH') {
9273: $alltargets = join("','",sort(keys(%{$servers})));
9274: my @homedoms;
9275: foreach my $server (sort(keys(%{$servers}))) {
9276: if (&Apache::lonnet::host_domain($server) eq $dom) {
9277: push(@homedoms,'1');
9278: } else {
9279: push(@homedoms,'0');
9280: }
9281: }
9282: $allishome = join("','",@homedoms);
9283: }
9284: if (ref($types) eq 'ARRAY') {
9285: if (@{$types} > 0) {
9286: @alltypes = @{$types};
9287: }
9288: }
9289: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
9290: $allinsttypes = join("','",@alltypes);
1.171 raeburn 9291: my (%currbalancer,%currtargets,%currrules,%existing);
9292: if (ref($settings) eq 'HASH') {
9293: %existing = %{$settings};
9294: }
9295: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
9296: \%currtargets,\%currrules);
1.210 raeburn 9297: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 9298: return <<"END";
9299:
9300: <script type="text/javascript">
9301: // <![CDATA[
9302:
1.171 raeburn 9303: currBalancers = new Array('$balancers');
9304:
9305: function toggleTargets(balnum) {
9306: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
9307: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
9308: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
9309: var prevbalancer = prevhostitem.value;
9310: var baltotal = document.getElementById('loadbalancing_total').value;
9311: prevhostitem.value = balancer;
9312: if (prevbalancer != '') {
9313: var prevIdx = currBalancers.indexOf(prevbalancer);
9314: if (prevIdx != -1) {
9315: currBalancers.splice(prevIdx,1);
9316: }
9317: }
1.150 raeburn 9318: if (balancer == '') {
1.171 raeburn 9319: hideSpares(balnum);
1.150 raeburn 9320: } else {
1.171 raeburn 9321: var currIdx = currBalancers.indexOf(balancer);
9322: if (currIdx == -1) {
9323: currBalancers.push(balancer);
9324: }
1.150 raeburn 9325: var homedoms = new Array('$allishome');
1.171 raeburn 9326: var ishomedom = homedoms[lonhostitem.selectedIndex];
9327: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 9328: }
1.171 raeburn 9329: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 9330: return;
9331: }
9332:
1.171 raeburn 9333: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 9334: var alltargets = new Array('$alltargets');
9335: var insttypes = new Array('$allinsttypes');
1.151 raeburn 9336: var offloadtypes = new Array('primary','default');
9337:
1.171 raeburn 9338: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
9339: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 9340:
1.151 raeburn 9341: for (var i=0; i<offloadtypes.length; i++) {
9342: var count = 0;
9343: for (var j=0; j<alltargets.length; j++) {
9344: if (alltargets[j] != balancer) {
1.171 raeburn 9345: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
9346: item.value = alltargets[j];
9347: item.style.textAlign='left';
9348: item.style.textFace='normal';
9349: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
9350: if (currBalancers.indexOf(alltargets[j]) == -1) {
9351: item.disabled = '';
9352: } else {
9353: item.disabled = 'disabled';
9354: item.checked = false;
9355: }
1.151 raeburn 9356: count ++;
9357: }
1.150 raeburn 9358: }
9359: }
1.151 raeburn 9360: for (var k=0; k<insttypes.length; k++) {
9361: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 9362: if (ishomedom == 1) {
1.171 raeburn 9363: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
9364: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 9365: } else {
1.171 raeburn 9366: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
9367: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 9368: }
9369: } else {
1.171 raeburn 9370: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
9371: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 9372: }
1.151 raeburn 9373: if ((insttypes[k] != '_LC_external') &&
9374: ((insttypes[k] != '_LC_internetdom') ||
9375: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 9376: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
9377: item.options.length = 0;
9378: item.options[0] = new Option("","",true,true);
1.210 raeburn 9379: var idx = 0;
1.151 raeburn 9380: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 9381: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
9382: idx ++;
9383: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 9384: }
9385: }
9386: }
9387: }
9388: return;
9389: }
9390:
1.171 raeburn 9391: function hideSpares(balnum) {
1.150 raeburn 9392: var alltargets = new Array('$alltargets');
9393: var insttypes = new Array('$allinsttypes');
9394: var offloadtypes = new Array('primary','default');
9395:
1.171 raeburn 9396: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
9397: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 9398:
9399: var total = alltargets.length - 1;
9400: for (var i=0; i<offloadtypes; i++) {
9401: for (var j=0; j<total; j++) {
1.171 raeburn 9402: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
9403: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
9404: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 9405: }
1.150 raeburn 9406: }
9407: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 9408: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
9409: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 9410: if (insttypes[k] != '_LC_external') {
1.171 raeburn 9411: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
9412: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 9413: }
9414: }
9415: return;
9416: }
9417:
1.171 raeburn 9418: function checkOffloads(item,balnum,type) {
1.150 raeburn 9419: var alltargets = new Array('$alltargets');
9420: var offloadtypes = new Array('primary','default');
9421: if (item.checked) {
9422: var total = alltargets.length - 1;
9423: var other;
9424: if (type == offloadtypes[0]) {
1.151 raeburn 9425: other = offloadtypes[1];
1.150 raeburn 9426: } else {
1.151 raeburn 9427: other = offloadtypes[0];
1.150 raeburn 9428: }
9429: for (var i=0; i<total; i++) {
1.171 raeburn 9430: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 9431: if (server == item.value) {
1.171 raeburn 9432: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
9433: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 9434: }
9435: }
9436: }
9437: }
9438: return;
9439: }
9440:
1.171 raeburn 9441: function singleServerToggle(balnum,type) {
9442: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 9443: if (offloadtoSelIdx == 0) {
1.171 raeburn 9444: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
9445: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 9446:
9447: } else {
1.171 raeburn 9448: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
9449: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 9450: }
9451: return;
9452: }
9453:
1.171 raeburn 9454: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 9455: if (type == '_LC_external') {
1.171 raeburn 9456: return;
1.150 raeburn 9457: }
1.171 raeburn 9458: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 9459: for (var i=0; i<typesRules.length; i++) {
9460: if (formname.elements[typesRules[i]].checked) {
9461: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 9462: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
9463: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 9464: } else {
1.171 raeburn 9465: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
9466: }
9467: }
9468: }
9469: return;
9470: }
9471:
9472: function balancerDeleteChange(balnum) {
9473: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
9474: var baltotal = document.getElementById('loadbalancing_total').value;
9475: var addtarget;
9476: var removetarget;
9477: var action = 'delete';
9478: if (document.getElementById('loadbalancing_delete_'+balnum)) {
9479: var lonhost = hostitem.value;
9480: var currIdx = currBalancers.indexOf(lonhost);
9481: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
9482: if (currIdx != -1) {
9483: currBalancers.splice(currIdx,1);
9484: }
9485: addtarget = lonhost;
9486: } else {
9487: if (currIdx == -1) {
9488: currBalancers.push(lonhost);
9489: }
9490: removetarget = lonhost;
9491: action = 'undelete';
9492: }
9493: balancerChange(balnum,baltotal,action,addtarget,removetarget);
9494: }
9495: return;
9496: }
9497:
9498: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
9499: if (baltotal > 1) {
9500: var offloadtypes = new Array('primary','default');
9501: var alltargets = new Array('$alltargets');
9502: var insttypes = new Array('$allinsttypes');
9503: for (var i=0; i<baltotal; i++) {
9504: if (i != balnum) {
9505: for (var j=0; j<offloadtypes.length; j++) {
9506: var total = alltargets.length - 1;
9507: for (var k=0; k<total; k++) {
9508: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
9509: var server = serveritem.value;
9510: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
9511: if (server == addtarget) {
9512: serveritem.disabled = '';
9513: }
9514: }
9515: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
9516: if (server == removetarget) {
9517: serveritem.disabled = 'disabled';
9518: serveritem.checked = false;
9519: }
9520: }
9521: }
9522: }
9523: for (var j=0; j<insttypes.length; j++) {
9524: if (insttypes[j] != '_LC_external') {
9525: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
9526: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
9527: var currSel = singleserver.selectedIndex;
9528: var currVal = singleserver.options[currSel].value;
9529: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
9530: var numoptions = singleserver.options.length;
9531: var needsnew = 1;
9532: for (var k=0; k<numoptions; k++) {
9533: if (singleserver.options[k] == addtarget) {
9534: needsnew = 0;
9535: break;
9536: }
9537: }
9538: if (needsnew == 1) {
9539: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
9540: }
9541: }
9542: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
9543: singleserver.options.length = 0;
9544: if ((currVal) && (currVal != removetarget)) {
9545: singleserver.options[0] = new Option("","",false,false);
9546: } else {
9547: singleserver.options[0] = new Option("","",true,true);
9548: }
9549: var idx = 0;
9550: for (var m=0; m<alltargets.length; m++) {
9551: if (currBalancers.indexOf(alltargets[m]) == -1) {
9552: idx ++;
9553: if (currVal == alltargets[m]) {
9554: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
9555: } else {
9556: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
9557: }
9558: }
9559: }
9560: }
9561: }
9562: }
9563: }
1.150 raeburn 9564: }
9565: }
9566: }
9567: return;
9568: }
9569:
1.152 raeburn 9570: // ]]>
9571: </script>
9572:
9573: END
9574: }
9575:
9576: sub new_spares_js {
9577: my @sparestypes = ('primary','default');
9578: my $types = join("','",@sparestypes);
9579: my $select = &mt('Select');
9580: return <<"END";
9581:
9582: <script type="text/javascript">
9583: // <![CDATA[
9584:
9585: function updateNewSpares(formname,lonhost) {
9586: var types = new Array('$types');
9587: var include = new Array();
9588: var exclude = new Array();
9589: for (var i=0; i<types.length; i++) {
9590: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
9591: for (var j=0; j<spareboxes.length; j++) {
9592: if (formname.elements[spareboxes[j]].checked) {
9593: exclude.push(formname.elements[spareboxes[j]].value);
9594: } else {
9595: include.push(formname.elements[spareboxes[j]].value);
9596: }
9597: }
9598: }
9599: for (var i=0; i<types.length; i++) {
9600: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
9601: var selIdx = newSpare.selectedIndex;
9602: var currnew = newSpare.options[selIdx].value;
9603: var okSpares = new Array();
9604: for (var j=0; j<newSpare.options.length; j++) {
9605: var possible = newSpare.options[j].value;
9606: if (possible != '') {
9607: if (exclude.indexOf(possible) == -1) {
9608: okSpares.push(possible);
9609: } else {
9610: if (currnew == possible) {
9611: selIdx = 0;
9612: }
9613: }
9614: }
9615: }
9616: for (var k=0; k<include.length; k++) {
9617: if (okSpares.indexOf(include[k]) == -1) {
9618: okSpares.push(include[k]);
9619: }
9620: }
9621: okSpares.sort();
9622: newSpare.options.length = 0;
9623: if (selIdx == 0) {
9624: newSpare.options[0] = new Option("$select","",true,true);
9625: } else {
9626: newSpare.options[0] = new Option("$select","",false,false);
9627: }
9628: for (var m=0; m<okSpares.length; m++) {
9629: var idx = m+1;
9630: var selThis = 0;
9631: if (selIdx != 0) {
9632: if (okSpares[m] == currnew) {
9633: selThis = 1;
9634: }
9635: }
9636: if (selThis == 1) {
9637: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
9638: } else {
9639: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
9640: }
9641: }
9642: }
9643: return;
9644: }
9645:
9646: function checkNewSpares(lonhost,type) {
9647: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
9648: var chosen = newSpare.options[newSpare.selectedIndex].value;
9649: if (chosen != '') {
9650: var othertype;
9651: var othernewSpare;
9652: if (type == 'primary') {
9653: othernewSpare = document.getElementById('newspare_default_'+lonhost);
9654: }
9655: if (type == 'default') {
9656: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
9657: }
9658: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
9659: othernewSpare.selectedIndex = 0;
9660: }
9661: }
9662: return;
9663: }
9664:
9665: // ]]>
9666: </script>
9667:
9668: END
9669:
9670: }
9671:
9672: sub common_domprefs_js {
9673: return <<"END";
9674:
9675: <script type="text/javascript">
9676: // <![CDATA[
9677:
1.150 raeburn 9678: function getIndicesByName(formname,item) {
1.152 raeburn 9679: var group = new Array();
1.150 raeburn 9680: for (var i=0;i<formname.elements.length;i++) {
9681: if (formname.elements[i].name == item) {
1.152 raeburn 9682: group.push(formname.elements[i].id);
1.150 raeburn 9683: }
9684: }
1.152 raeburn 9685: return group;
1.150 raeburn 9686: }
9687:
9688: // ]]>
9689: </script>
9690:
9691: END
1.152 raeburn 9692:
1.150 raeburn 9693: }
9694:
1.165 raeburn 9695: sub recaptcha_js {
9696: my %lt = &captcha_phrases();
9697: return <<"END";
9698:
9699: <script type="text/javascript">
9700: // <![CDATA[
9701:
9702: function updateCaptcha(caller,context) {
9703: var privitem;
9704: var pubitem;
9705: var privtext;
9706: var pubtext;
9707: if (document.getElementById(context+'_recaptchapub')) {
9708: pubitem = document.getElementById(context+'_recaptchapub');
9709: } else {
9710: return;
9711: }
9712: if (document.getElementById(context+'_recaptchapriv')) {
9713: privitem = document.getElementById(context+'_recaptchapriv');
9714: } else {
9715: return;
9716: }
9717: if (document.getElementById(context+'_recaptchapubtxt')) {
9718: pubtext = document.getElementById(context+'_recaptchapubtxt');
9719: } else {
9720: return;
9721: }
9722: if (document.getElementById(context+'_recaptchaprivtxt')) {
9723: privtext = document.getElementById(context+'_recaptchaprivtxt');
9724: } else {
9725: return;
9726: }
9727: if (caller.checked) {
9728: if (caller.value == 'recaptcha') {
9729: pubitem.type = 'text';
9730: privitem.type = 'text';
9731: pubitem.size = '40';
9732: privitem.size = '40';
9733: pubtext.innerHTML = "$lt{'pub'}";
9734: privtext.innerHTML = "$lt{'priv'}";
9735: } else {
9736: pubitem.type = 'hidden';
9737: privitem.type = 'hidden';
9738: pubtext.innerHTML = '';
9739: privtext.innerHTML = '';
9740: }
9741: }
9742: return;
9743: }
9744:
9745: // ]]>
9746: </script>
9747:
9748: END
9749:
9750: }
9751:
1.192 raeburn 9752: sub credits_js {
9753: return <<"END";
9754:
9755: <script type="text/javascript">
9756: // <![CDATA[
9757:
9758: function toggleCredits(domForm) {
9759: if (document.getElementById('credits')) {
9760: creditsitem = document.getElementById('credits');
9761: var creditsLength = domForm.coursecredits.length;
9762: if (creditsLength) {
9763: var currval;
9764: for (var i=0; i<creditsLength; i++) {
9765: if (domForm.coursecredits[i].checked) {
9766: currval = domForm.coursecredits[i].value;
9767: }
9768: }
9769: if (currval == 1) {
9770: creditsitem.style.display = 'block';
9771: } else {
9772: creditsitem.style.display = 'none';
9773: }
9774: }
9775: }
9776: return;
9777: }
9778:
9779: // ]]>
9780: </script>
9781:
9782: END
9783:
9784: }
9785:
1.165 raeburn 9786: sub captcha_phrases {
9787: return &Apache::lonlocal::texthash (
9788: priv => 'Private key',
9789: pub => 'Public key',
9790: original => 'original (CAPTCHA)',
9791: recaptcha => 'successor (ReCAPTCHA)',
9792: notused => 'unused',
9793: );
9794: }
9795:
1.205 raeburn 9796: sub devalidate_remote_domconfs {
1.212 raeburn 9797: my ($dom,$cachekeys) = @_;
9798: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 9799: my %servers = &Apache::lonnet::internet_dom_servers($dom);
9800: my %thismachine;
9801: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.212 raeburn 9802: my @posscached = ('domainconfig','domdefaults');
1.205 raeburn 9803: if (keys(%servers) > 1) {
9804: foreach my $server (keys(%servers)) {
9805: next if ($thismachine{$server});
1.212 raeburn 9806: my @cached;
9807: foreach my $name (@posscached) {
9808: if ($cachekeys->{$name}) {
9809: push(@cached,&escape($name).':'.&escape($dom));
9810: }
9811: }
9812: if (@cached) {
9813: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
9814: }
1.205 raeburn 9815: }
9816: }
9817: return;
9818: }
9819:
1.3 raeburn 9820: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>