Annotation of loncom/interface/domainprefs.pm, revision 1.224
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.224 ! raeburn 4: # $Id: domainprefs.pm,v 1.223 2014/01/08 17:18:11 bisitz 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
1.223 bisitz 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.224 ! raeburn 219: 'usercreation','selfcreation','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: 'usercreation' =>
299: { text => 'User creation',
1.67 raeburn 300: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 301: header => [{col1 => 'Format rule type',
302: col2 => 'Format rules in force'},
1.34 raeburn 303: {col1 => 'User account creation',
304: col2 => 'Usernames which may be created',},
1.30 raeburn 305: {col1 => 'Context',
1.43 raeburn 306: col2 => 'Assignable authentication types'}],
1.30 raeburn 307: },
1.224 ! raeburn 308: 'selfcreation' =>
! 309: { text => 'Users self-creating accounts',
! 310: help => 'Domain_Configuration_Self_Creation',
! 311: header => [{col1 => 'Self-creation with institutional username',
! 312: col2 => 'Enabled?'},
! 313: {col1 => 'Institutional user type (login/SSO self-creation)',
! 314: col2 => 'Information user can enter'},
! 315: {col1 => 'Self-creation with e-mail as username',
! 316: col2 => 'Settings'}],
! 317: },
1.69 raeburn 318: 'usermodification' =>
1.33 raeburn 319: { text => 'User modification',
1.67 raeburn 320: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 321: header => [{col1 => 'Target user has role',
322: col2 => 'User information updateable in author context'},
323: {col1 => 'Target user has role',
1.224 ! raeburn 324: col2 => 'User information updateable in course context'}],
1.33 raeburn 325: },
1.69 raeburn 326: 'scantron' =>
1.95 www 327: { text => 'Bubblesheet format file',
1.67 raeburn 328: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 329: header => [ {col1 => 'Item',
330: col2 => '',
331: }],
332: },
1.86 raeburn 333: 'requestcourses' =>
334: {text => 'Request creation of courses',
335: help => 'Domain_Configuration_Request_Courses',
336: header => [{col1 => 'User affiliation',
1.102 raeburn 337: col2 => 'Availability/Processing of requests',},
338: {col1 => 'Setting',
1.216 raeburn 339: col2 => 'Value'},
340: {col1 => 'Available textbooks',
341: col2 => ''}],
1.86 raeburn 342: },
1.163 raeburn 343: 'requestauthor' =>
1.223 bisitz 344: {text => 'Request Authoring Space',
1.163 raeburn 345: help => 'Domain_Configuration_Request_Author',
346: header => [{col1 => 'User affiliation',
347: col2 => 'Availability/Processing of requests',},
348: {col1 => 'Setting',
349: col2 => 'Value'}],
350: },
1.69 raeburn 351: 'coursecategories' =>
1.120 raeburn 352: { text => 'Cataloging of courses/communities',
1.67 raeburn 353: help => 'Domain_Configuration_Cataloging_Courses',
1.69 raeburn 354: header => [{col1 => 'Category settings',
1.57 raeburn 355: col2 => '',},
356: {col1 => 'Categories',
357: col2 => '',
358: }],
1.69 raeburn 359: },
360: 'serverstatuses' =>
1.77 raeburn 361: {text => 'Access to server status pages',
1.69 raeburn 362: help => 'Domain_Configuration_Server_Status',
363: header => [{col1 => 'Status Page',
364: col2 => 'Other named users',
365: col3 => 'Specific IPs',
366: }],
367: },
1.118 jms 368: 'helpsettings' =>
369: {text => 'Help page settings',
370: help => 'Domain_Configuration_Help_Settings',
1.166 raeburn 371: header => [{col1 => 'Help Settings (logged-in users)',
372: col2 => 'Value'}],
1.118 jms 373: },
1.121 raeburn 374: 'coursedefaults' =>
375: {text => 'Course/Community defaults',
376: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 377: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
378: col2 => 'Value',},
379: {col1 => 'Defaults which can be overridden for each course by a DC',
380: col2 => 'Value',},],
1.121 raeburn 381: },
1.120 raeburn 382: 'privacy' =>
383: {text => 'User Privacy',
384: help => 'Domain_Configuration_User_Privacy',
385: header => [{col1 => 'Setting',
386: col2 => 'Value',}],
387: },
1.141 raeburn 388: 'usersessions' =>
1.145 raeburn 389: {text => 'User session hosting/offloading',
1.137 raeburn 390: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 391: header => [{col1 => 'Domain server',
392: col2 => 'Servers to offload sessions to when busy'},
393: {col1 => 'Hosting of users from other domains',
1.137 raeburn 394: col2 => 'Rules'},
395: {col1 => "Hosting domain's own users elsewhere",
396: col2 => 'Rules'}],
397: },
1.150 raeburn 398: 'loadbalancing' =>
1.185 raeburn 399: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 400: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 401: header => [{col1 => 'Balancers',
1.150 raeburn 402: col2 => 'Default destinations',
1.183 bisitz 403: col3 => 'User affiliation',
1.150 raeburn 404: col4 => 'Overrides'},
405: ],
406: },
1.3 raeburn 407: );
1.110 raeburn 408: if (keys(%servers) > 1) {
409: $prefs{'login'} = { text => 'Log-in page options',
410: help => 'Domain_Configuration_Login_Page',
411: header => [{col1 => 'Log-in Service',
412: col2 => 'Server Setting',},
413: {col1 => 'Log-in Page Items',
1.168 raeburn 414: col2 => ''},
415: {col1 => 'Log-in Help',
416: col2 => 'Value'}],
1.110 raeburn 417: };
418: }
1.174 foxr 419:
1.6 raeburn 420: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 421: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 422: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 423: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 424: text=>"Settings to display/modify"});
1.9 raeburn 425: my $confname = $dom.'-domainconfig';
1.174 foxr 426:
1.3 raeburn 427: if ($phase eq 'process') {
1.212 raeburn 428: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
429: \%prefs,\%domconfig,$confname,\@roles);
1.224 ! raeburn 430: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 431: $r->rflush();
1.212 raeburn 432: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 433: }
1.30 raeburn 434: } elsif ($phase eq 'display') {
1.192 raeburn 435: my $js = &recaptcha_js().
436: &credits_js();
1.171 raeburn 437: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 438: my ($othertitle,$usertypes,$types) =
439: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 440: $js .= &lonbalance_targets_js($dom,$types,\%servers,
441: $domconfig{'loadbalancing'}).
1.170 raeburn 442: &new_spares_js().
443: &common_domprefs_js().
444: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 445: }
1.216 raeburn 446: if (grep(/^requestcourses$/,@actions)) {
447: my $javascript_validations;
448: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
449: $js .= <<END;
450: <script type="text/javascript">
451: $javascript_validations
452: </script>
453: $coursebrowserjs
454: END
455: }
1.150 raeburn 456: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 457: } else {
1.180 raeburn 458: # check if domconfig user exists for the domain.
459: my $servadm = $r->dir_config('lonAdmEMail');
460: my ($configuserok,$author_ok,$switchserver) =
461: &config_check($dom,$confname,$servadm);
462: unless ($configuserok eq 'ok') {
1.181 raeburn 463: &Apache::lonconfigsettings::print_header($r,$phase,$context);
464: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 465: $confname).
1.181 raeburn 466: '<br />'
467: );
1.180 raeburn 468: if ($switchserver) {
1.181 raeburn 469: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
470: '<br />'.
471: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
472: '<br />'.
473: &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).
474: '<br />'.
475: &mt('To do that now, use the following link: [_1]',$switchserver)
476: );
477: } else {
478: $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.').
479: '<br />'.
480: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
481: );
1.180 raeburn 482: }
483: $r->print(&Apache::loncommon::end_page());
484: return OK;
485: }
1.21 raeburn 486: if (keys(%domconfig) == 0) {
487: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 488: my @ids=&Apache::lonnet::current_machine_ids();
489: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 490: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 491: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 492: my $custom_img_count = 0;
493: foreach my $img (@loginimages) {
494: if ($designhash{$dom.'.login.'.$img} ne '') {
495: $custom_img_count ++;
496: }
497: }
498: foreach my $role (@roles) {
499: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
500: $custom_img_count ++;
501: }
502: }
503: if ($custom_img_count > 0) {
1.94 raeburn 504: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 505: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 506: $r->print(
507: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
508: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
509: &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 />'.
510: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
511: if ($switch_server) {
1.30 raeburn 512: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 513: }
1.91 raeburn 514: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 515: return OK;
516: }
517: }
518: }
1.91 raeburn 519: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 520: }
521: return OK;
522: }
523:
524: sub process_changes {
1.205 raeburn 525: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 526: my %domconfig;
527: if (ref($values) eq 'HASH') {
528: %domconfig = %{$values};
529: }
1.3 raeburn 530: my $output;
531: if ($action eq 'login') {
1.205 raeburn 532: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 533: } elsif ($action eq 'rolecolors') {
1.9 raeburn 534: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 535: $lastactref,%domconfig);
1.3 raeburn 536: } elsif ($action eq 'quotas') {
1.216 raeburn 537: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 538: } elsif ($action eq 'autoenroll') {
1.205 raeburn 539: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 540: } elsif ($action eq 'autoupdate') {
541: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 542: } elsif ($action eq 'autocreate') {
543: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 544: } elsif ($action eq 'directorysrch') {
545: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 546: } elsif ($action eq 'usercreation') {
1.28 raeburn 547: $output = &modify_usercreation($dom,%domconfig);
1.224 ! raeburn 548: } elsif ($action eq 'selfcreation') {
! 549: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 550: } elsif ($action eq 'usermodification') {
551: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 552: } elsif ($action eq 'contacts') {
1.205 raeburn 553: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 554: } elsif ($action eq 'defaults') {
1.212 raeburn 555: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 556: } elsif ($action eq 'scantron') {
1.205 raeburn 557: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 558: } elsif ($action eq 'coursecategories') {
559: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 560: } elsif ($action eq 'serverstatuses') {
561: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 562: } elsif ($action eq 'requestcourses') {
1.216 raeburn 563: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 564: } elsif ($action eq 'requestauthor') {
1.216 raeburn 565: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 566: } elsif ($action eq 'helpsettings') {
1.122 jms 567: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121 raeburn 568: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 569: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.137 raeburn 570: } elsif ($action eq 'usersessions') {
1.212 raeburn 571: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 572: } elsif ($action eq 'loadbalancing') {
573: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 574: }
575: return $output;
576: }
577:
578: sub print_config_box {
1.9 raeburn 579: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 580: my $rowtotal = 0;
1.49 raeburn 581: my $output;
582: if ($action eq 'coursecategories') {
583: $output = &coursecategories_javascript($settings);
1.91 raeburn 584: }
1.49 raeburn 585: $output .=
1.30 raeburn 586: '<table class="LC_nested_outer">
1.3 raeburn 587: <tr>
1.66 raeburn 588: <th align="left" valign="middle"><span class="LC_nobreak">'.
589: &mt($item->{text}).' '.
590: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
591: '</tr>';
1.30 raeburn 592: $rowtotal ++;
1.110 raeburn 593: my $numheaders = 1;
594: if (ref($item->{'header'}) eq 'ARRAY') {
595: $numheaders = scalar(@{$item->{'header'}});
596: }
597: if ($numheaders > 1) {
1.64 raeburn 598: my $colspan = '';
1.145 raeburn 599: my $rightcolspan = '';
1.210 raeburn 600: if (($action eq 'rolecolors') || ($action eq 'coursecategories') ||
1.168 raeburn 601: (($action eq 'login') && ($numheaders < 3))) {
1.64 raeburn 602: $colspan = ' colspan="2"';
603: }
1.145 raeburn 604: if ($action eq 'usersessions') {
605: $rightcolspan = ' colspan="3"';
606: }
1.30 raeburn 607: $output .= '
1.3 raeburn 608: <tr>
609: <td>
610: <table class="LC_nested">
611: <tr class="LC_info_row">
1.59 bisitz 612: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 613: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 614: </tr>';
1.69 raeburn 615: $rowtotal ++;
1.6 raeburn 616: if ($action eq 'autoupdate') {
1.30 raeburn 617: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 618: } elsif ($action eq 'usercreation') {
1.33 raeburn 619: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
1.224 ! raeburn 620: } elsif ($action eq 'selfcreation') {
! 621: $output .= &print_selfcreation('top',$dom,$settings,\$rowtotal);
1.33 raeburn 622: } elsif ($action eq 'usermodification') {
623: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57 raeburn 624: } elsif ($action eq 'coursecategories') {
625: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 626: } elsif ($action eq 'login') {
1.168 raeburn 627: if ($numheaders == 3) {
628: $colspan = ' colspan="2"';
629: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
630: } else {
631: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
632: }
1.102 raeburn 633: } elsif ($action eq 'requestcourses') {
634: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.163 raeburn 635: } elsif ($action eq 'requestauthor') {
636: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.137 raeburn 637: } elsif ($action eq 'usersessions') {
638: $output .= &print_usersessions('top',$dom,$settings,\$rowtotal);
1.122 jms 639: } elsif ($action eq 'rolecolors') {
1.30 raeburn 640: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.139 raeburn 641: } elsif ($action eq 'coursedefaults') {
642: $output .= &print_coursedefaults('top',$dom,$settings,\$rowtotal);
1.6 raeburn 643: }
1.30 raeburn 644: $output .= '
1.6 raeburn 645: </table>
646: </td>
647: </tr>
648: <tr>
649: <td>
650: <table class="LC_nested">
651: <tr class="LC_info_row">
1.59 bisitz 652: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57 raeburn 653: $output .= '
1.59 bisitz 654: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 655: </tr>';
656: $rowtotal ++;
1.6 raeburn 657: if ($action eq 'autoupdate') {
1.131 raeburn 658: $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
659: </table>
660: </td>
661: </tr>
662: <tr>
663: <td>
664: <table class="LC_nested">
665: <tr class="LC_info_row">
666: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
667: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
668: &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
669: $rowtotal ++;
1.28 raeburn 670: } elsif ($action eq 'usercreation') {
1.34 raeburn 671: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
672: </table>
673: </td>
674: </tr>
675: <tr>
676: <td>
677: <table class="LC_nested">
678: <tr class="LC_info_row">
1.59 bisitz 679: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
680: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.34 raeburn 681: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
682: $rowtotal ++;
1.224 ! raeburn 683: } elsif ($action eq 'selfcreation') {
! 684: $output .= &print_selfcreation('middle',$dom,$settings,\$rowtotal).'
1.63 raeburn 685: </table>
686: </td>
687: </tr>
688: <tr>
689: <td>
690: <table class="LC_nested">
691: <tr class="LC_info_row">
692: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 ! raeburn 693: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
! 694: </tr>'.
! 695: &print_selfcreation('bottom',$dom,$settings,\$rowtotal);
1.63 raeburn 696: $rowtotal ++;
1.224 ! raeburn 697: } elsif ($action eq 'usermodification') {
! 698: $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal);
1.57 raeburn 699: } elsif ($action eq 'coursecategories') {
700: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 701: } elsif ($action eq 'login') {
1.168 raeburn 702: if ($numheaders == 3) {
703: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
704: </table>
705: </td>
706: </tr>
707: <tr>
708: <td>
709: <table class="LC_nested">
710: <tr class="LC_info_row">
711: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 712: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 713: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
714: $rowtotal ++;
715: } else {
716: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
717: }
1.102 raeburn 718: } elsif ($action eq 'requestcourses') {
1.216 raeburn 719: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal).
720: &print_studentcode($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_textbookcourses($dom,$settings,\$rowtotal);
1.163 raeburn 731: } elsif ($action eq 'requestauthor') {
732: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.137 raeburn 733: } elsif ($action eq 'usersessions') {
1.145 raeburn 734: $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
735: </table>
736: </td>
737: </tr>
738: <tr>
739: <td>
740: <table class="LC_nested">
741: <tr class="LC_info_row">
742: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
743: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
744: &print_usersessions('bottom',$dom,$settings,\$rowtotal);
745: $rowtotal ++;
1.139 raeburn 746: } elsif ($action eq 'coursedefaults') {
747: $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.122 jms 748: } elsif ($action eq 'rolecolors') {
1.30 raeburn 749: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 750: </table>
751: </td>
752: </tr>
753: <tr>
754: <td>
755: <table class="LC_nested">
756: <tr class="LC_info_row">
1.69 raeburn 757: <td class="LC_left_item"'.$colspan.' valign="top">'.
758: &mt($item->{'header'}->[2]->{'col1'}).'</td>
759: <td class="LC_right_item" valign="top">'.
760: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 761: </tr>'.
1.30 raeburn 762: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 763: </table>
764: </td>
765: </tr>
766: <tr>
767: <td>
768: <table class="LC_nested">
769: <tr class="LC_info_row">
1.59 bisitz 770: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
771: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 772: </tr>'.
1.30 raeburn 773: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
774: $rowtotal += 2;
1.6 raeburn 775: }
1.3 raeburn 776: } else {
1.30 raeburn 777: $output .= '
1.3 raeburn 778: <tr>
779: <td>
780: <table class="LC_nested">
1.30 raeburn 781: <tr class="LC_info_row">';
1.24 raeburn 782: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 783: $output .= '
1.59 bisitz 784: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 785: } elsif ($action eq 'serverstatuses') {
786: $output .= '
787: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
788: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
789:
1.6 raeburn 790: } else {
1.30 raeburn 791: $output .= '
1.69 raeburn 792: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
793: }
1.72 raeburn 794: if (defined($item->{'header'}->[0]->{'col3'})) {
795: $output .= '<td class="LC_left_item" valign="top">'.
796: &mt($item->{'header'}->[0]->{'col2'});
797: if ($action eq 'serverstatuses') {
798: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
799: }
1.69 raeburn 800: } else {
801: $output .= '<td class="LC_right_item" valign="top">'.
802: &mt($item->{'header'}->[0]->{'col2'});
803: }
804: $output .= '</td>';
805: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 806: if (defined($item->{'header'}->[0]->{'col4'})) {
807: $output .= '<td class="LC_left_item" valign="top">'.
808: &mt($item->{'header'}->[0]->{'col3'});
809: } else {
810: $output .= '<td class="LC_right_item" valign="top">'.
811: &mt($item->{'header'}->[0]->{'col3'});
812: }
1.69 raeburn 813: if ($action eq 'serverstatuses') {
814: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
815: }
816: $output .= '</td>';
1.6 raeburn 817: }
1.150 raeburn 818: if ($item->{'header'}->[0]->{'col4'}) {
819: $output .= '<td class="LC_right_item" valign="top">'.
820: &mt($item->{'header'}->[0]->{'col4'});
821: }
1.69 raeburn 822: $output .= '</tr>';
1.48 raeburn 823: $rowtotal ++;
1.168 raeburn 824: if ($action eq 'quotas') {
1.86 raeburn 825: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3 raeburn 826: } elsif ($action eq 'autoenroll') {
1.30 raeburn 827: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125 raeburn 828: } elsif ($action eq 'autocreate') {
829: $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23 raeburn 830: } elsif ($action eq 'directorysrch') {
1.30 raeburn 831: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 832: } elsif ($action eq 'contacts') {
1.30 raeburn 833: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 raeburn 834: } elsif ($action eq 'defaults') {
1.212 raeburn 835: $output .= &print_defaults($dom,$settings,\$rowtotal);
1.46 raeburn 836: } elsif ($action eq 'scantron') {
837: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69 raeburn 838: } elsif ($action eq 'serverstatuses') {
839: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118 jms 840: } elsif ($action eq 'helpsettings') {
1.168 raeburn 841: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.150 raeburn 842: } elsif ($action eq 'loadbalancing') {
843: $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.121 raeburn 844: }
1.3 raeburn 845: }
1.30 raeburn 846: $output .= '
1.3 raeburn 847: </table>
848: </td>
849: </tr>
1.30 raeburn 850: </table><br />';
851: return ($output,$rowtotal);
1.1 raeburn 852: }
853:
1.3 raeburn 854: sub print_login {
1.168 raeburn 855: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 856: my ($css_class,$datatable);
1.6 raeburn 857: my %choices = &login_choices();
1.110 raeburn 858:
1.168 raeburn 859: if ($caller eq 'service') {
1.149 raeburn 860: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 861: my $choice = $choices{'disallowlogin'};
862: $css_class = ' class="LC_odd_row"';
1.128 raeburn 863: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 864: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 865: '<th>'.$choices{'server'}.'</th>'.
866: '<th>'.$choices{'serverpath'}.'</th>'.
867: '<th>'.$choices{'custompath'}.'</th>'.
868: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 869: my %disallowed;
870: if (ref($settings) eq 'HASH') {
871: if (ref($settings->{'loginvia'}) eq 'HASH') {
872: %disallowed = %{$settings->{'loginvia'}};
873: }
874: }
875: foreach my $lonhost (sort(keys(%servers))) {
876: my $direct = 'selected="selected"';
1.128 raeburn 877: if (ref($disallowed{$lonhost}) eq 'HASH') {
878: if ($disallowed{$lonhost}{'server'} ne '') {
879: $direct = '';
880: }
1.110 raeburn 881: }
1.115 raeburn 882: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 883: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 884: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
885: '</option>';
1.184 raeburn 886: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 887: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 888: my $selected = '';
1.128 raeburn 889: if (ref($disallowed{$lonhost}) eq 'HASH') {
890: if ($hostid eq $disallowed{$lonhost}{'server'}) {
891: $selected = 'selected="selected"';
892: }
1.110 raeburn 893: }
894: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
895: $servers{$hostid}.'</option>';
896: }
1.128 raeburn 897: $datatable .= '</select></td>'.
898: '<td><select name="'.$lonhost.'_serverpath">';
899: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
900: my $pathname = $path;
901: if ($path eq 'custom') {
902: $pathname = &mt('Custom Path').' ->';
903: }
904: my $selected = '';
905: if (ref($disallowed{$lonhost}) eq 'HASH') {
906: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
907: $selected = 'selected="selected"';
908: }
909: } elsif ($path eq '') {
910: $selected = 'selected="selected"';
911: }
912: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
913: }
914: $datatable .= '</select></td>';
915: my ($custom,$exempt);
916: if (ref($disallowed{$lonhost}) eq 'HASH') {
917: $custom = $disallowed{$lonhost}{'custompath'};
918: $exempt = $disallowed{$lonhost}{'exempt'};
919: }
920: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
921: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
922: '</tr>';
1.110 raeburn 923: }
924: $datatable .= '</table></td></tr>';
925: return $datatable;
1.168 raeburn 926: } elsif ($caller eq 'page') {
927: my %defaultchecked = (
928: 'coursecatalog' => 'on',
1.188 raeburn 929: 'helpdesk' => 'on',
1.168 raeburn 930: 'adminmail' => 'off',
931: 'newuser' => 'off',
932: );
1.188 raeburn 933: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 934: my (%checkedon,%checkedoff);
1.42 raeburn 935: foreach my $item (@toggles) {
1.168 raeburn 936: if ($defaultchecked{$item} eq 'on') {
937: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 938: $checkedoff{$item} = ' ';
1.168 raeburn 939: } elsif ($defaultchecked{$item} eq 'off') {
940: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 941: $checkedon{$item} = ' ';
942: }
1.1 raeburn 943: }
1.168 raeburn 944: my @images = ('img','logo','domlogo','login');
945: my @logintext = ('textcol','bgcol');
946: my @bgs = ('pgbg','mainbg','sidebg');
947: my @links = ('link','alink','vlink');
948: my %designhash = &Apache::loncommon::get_domainconf($dom);
949: my %defaultdesign = %Apache::loncommon::defaultdesign;
950: my (%is_custom,%designs);
951: my %defaults = (
952: font => $defaultdesign{'login.font'},
953: );
1.6 raeburn 954: foreach my $item (@images) {
1.168 raeburn 955: $defaults{$item} = $defaultdesign{'login.'.$item};
956: $defaults{'showlogo'}{$item} = 1;
957: }
958: foreach my $item (@bgs) {
959: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 960: }
1.41 raeburn 961: foreach my $item (@logintext) {
1.168 raeburn 962: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 963: }
1.168 raeburn 964: foreach my $item (@links) {
965: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 966: }
1.168 raeburn 967: if (ref($settings) eq 'HASH') {
968: foreach my $item (@toggles) {
969: if ($settings->{$item} eq '1') {
970: $checkedon{$item} = ' checked="checked" ';
971: $checkedoff{$item} = ' ';
972: } elsif ($settings->{$item} eq '0') {
973: $checkedoff{$item} = ' checked="checked" ';
974: $checkedon{$item} = ' ';
975: }
976: }
977: foreach my $item (@images) {
978: if (defined($settings->{$item})) {
979: $designs{$item} = $settings->{$item};
980: $is_custom{$item} = 1;
981: }
982: if (defined($settings->{'showlogo'}{$item})) {
983: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
984: }
985: }
986: foreach my $item (@logintext) {
987: if ($settings->{$item} ne '') {
988: $designs{'logintext'}{$item} = $settings->{$item};
989: $is_custom{$item} = 1;
990: }
991: }
992: if ($settings->{'font'} ne '') {
993: $designs{'font'} = $settings->{'font'};
994: $is_custom{'font'} = 1;
995: }
996: foreach my $item (@bgs) {
997: if ($settings->{$item} ne '') {
998: $designs{'bgs'}{$item} = $settings->{$item};
999: $is_custom{$item} = 1;
1000: }
1001: }
1002: foreach my $item (@links) {
1003: if ($settings->{$item} ne '') {
1004: $designs{'links'}{$item} = $settings->{$item};
1005: $is_custom{$item} = 1;
1006: }
1007: }
1008: } else {
1009: if ($designhash{$dom.'.login.font'} ne '') {
1010: $designs{'font'} = $designhash{$dom.'.login.font'};
1011: $is_custom{'font'} = 1;
1012: }
1013: foreach my $item (@images) {
1014: if ($designhash{$dom.'.login.'.$item} ne '') {
1015: $designs{$item} = $designhash{$dom.'.login.'.$item};
1016: $is_custom{$item} = 1;
1017: }
1018: }
1019: foreach my $item (@bgs) {
1020: if ($designhash{$dom.'.login.'.$item} ne '') {
1021: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1022: $is_custom{$item} = 1;
1023: }
1.6 raeburn 1024: }
1.168 raeburn 1025: foreach my $item (@links) {
1026: if ($designhash{$dom.'.login.'.$item} ne '') {
1027: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1028: $is_custom{$item} = 1;
1029: }
1.6 raeburn 1030: }
1031: }
1.168 raeburn 1032: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1033: logo => 'Institution Logo',
1034: domlogo => 'Domain Logo',
1035: login => 'Login box');
1036: my $itemcount = 1;
1037: foreach my $item (@toggles) {
1038: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1039: $datatable .=
1040: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1041: '</td><td>'.
1042: '<span class="LC_nobreak"><label><input type="radio" name="'.
1043: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1044: '</label> <label><input type="radio" name="'.$item.'"'.
1045: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1046: '</tr>';
1047: $itemcount ++;
1.6 raeburn 1048: }
1.168 raeburn 1049: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1050: $datatable .= '</tr></table></td></tr>';
1051: } elsif ($caller eq 'help') {
1052: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1053: my $switchserver = &check_switchserver($dom,$confname);
1054: my $itemcount = 1;
1055: $defaulturl = '/adm/loginproblems.html';
1056: $defaulttype = 'default';
1057: %lt = &Apache::lonlocal::texthash (
1058: del => 'Delete?',
1059: rep => 'Replace:',
1060: upl => 'Upload:',
1061: default => 'Default',
1062: custom => 'Custom',
1063: );
1064: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1065: my @currlangs;
1066: if (ref($settings) eq 'HASH') {
1067: if (ref($settings->{'helpurl'}) eq 'HASH') {
1068: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1069: next if ($settings->{'helpurl'}{$key} eq '');
1070: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1071: $type{$key} = 'custom';
1072: unless ($key eq 'nolang') {
1073: push(@currlangs,$key);
1074: }
1075: }
1076: } elsif ($settings->{'helpurl'} ne '') {
1077: $type{'nolang'} = 'custom';
1078: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1079: }
1080: }
1.168 raeburn 1081: foreach my $lang ('nolang',sort(@currlangs)) {
1082: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1083: $datatable .= '<tr'.$css_class.'>';
1084: if ($url{$lang} eq '') {
1085: $url{$lang} = $defaulturl;
1086: }
1087: if ($type{$lang} eq '') {
1088: $type{$lang} = $defaulttype;
1089: }
1090: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1091: if ($lang eq 'nolang') {
1092: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1093: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1094: } else {
1095: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1096: $langchoices{$lang},
1097: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1098: }
1099: $datatable .= '</span></td>'."\n".
1100: '<td class="LC_left_item">';
1101: if ($type{$lang} eq 'custom') {
1102: $datatable .= '<span class="LC_nobreak"><label>'.
1103: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1104: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1105: } else {
1106: $datatable .= $lt{'upl'};
1107: }
1108: $datatable .='<br />';
1109: if ($switchserver) {
1110: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1111: } else {
1112: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1113: }
1.168 raeburn 1114: $datatable .= '</td></tr>';
1115: $itemcount ++;
1.6 raeburn 1116: }
1.168 raeburn 1117: my @addlangs;
1118: foreach my $lang (sort(keys(%langchoices))) {
1119: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1120: push(@addlangs,$lang);
1121: }
1122: if (@addlangs > 0) {
1123: my %toadd;
1124: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1125: $toadd{''} = &mt('Select');
1126: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1127: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1128: &mt('Add log-in help page for a specific language:').' '.
1129: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1130: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1131: if ($switchserver) {
1132: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1133: } else {
1134: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1135: }
1.168 raeburn 1136: $datatable .= '</td></tr>';
1.169 raeburn 1137: $itemcount ++;
1.6 raeburn 1138: }
1.169 raeburn 1139: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1 raeburn 1140: }
1.6 raeburn 1141: return $datatable;
1142: }
1143:
1144: sub login_choices {
1145: my %choices =
1146: &Apache::lonlocal::texthash (
1.116 bisitz 1147: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1148: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1149: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1150: disallowlogin => "Login page requests redirected",
1151: hostid => "Server",
1.128 raeburn 1152: server => "Redirect to:",
1153: serverpath => "Path",
1154: custompath => "Custom",
1155: exempt => "Exempt IP(s)",
1.110 raeburn 1156: directlogin => "No redirect",
1157: newuser => "Link to create a user account",
1158: img => "Header",
1159: logo => "Main Logo",
1160: domlogo => "Domain Logo",
1161: login => "Log-in Header",
1162: textcol => "Text color",
1163: bgcol => "Box color",
1164: bgs => "Background colors",
1165: links => "Link colors",
1166: font => "Font color",
1167: pgbg => "Header",
1168: mainbg => "Page",
1169: sidebg => "Login box",
1170: link => "Link",
1171: alink => "Active link",
1172: vlink => "Visited link",
1.6 raeburn 1173: );
1174: return %choices;
1175: }
1176:
1177: sub print_rolecolors {
1.30 raeburn 1178: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1179: my %choices = &color_font_choices();
1180: my @bgs = ('pgbg','tabbg','sidebg');
1181: my @links = ('link','alink','vlink');
1182: my @images = ('img');
1183: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1184: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1185: my %defaultdesign = %Apache::loncommon::defaultdesign;
1186: my (%is_custom,%designs);
1.200 raeburn 1187: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1188: if (ref($settings) eq 'HASH') {
1189: if (ref($settings->{$role}) eq 'HASH') {
1190: if ($settings->{$role}->{'img'} ne '') {
1191: $designs{'img'} = $settings->{$role}->{'img'};
1192: $is_custom{'img'} = 1;
1193: }
1194: if ($settings->{$role}->{'font'} ne '') {
1195: $designs{'font'} = $settings->{$role}->{'font'};
1196: $is_custom{'font'} = 1;
1197: }
1.97 tempelho 1198: if ($settings->{$role}->{'fontmenu'} ne '') {
1199: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1200: $is_custom{'fontmenu'} = 1;
1201: }
1.6 raeburn 1202: foreach my $item (@bgs) {
1203: if ($settings->{$role}->{$item} ne '') {
1204: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1205: $is_custom{$item} = 1;
1206: }
1207: }
1208: foreach my $item (@links) {
1209: if ($settings->{$role}->{$item} ne '') {
1210: $designs{'links'}{$item} = $settings->{$role}->{$item};
1211: $is_custom{$item} = 1;
1212: }
1213: }
1214: }
1215: } else {
1216: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1217: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1218: $is_custom{'img'} = 1;
1219: }
1.97 tempelho 1220: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1221: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1222: $is_custom{'fontmenu'} = 1;
1223: }
1.6 raeburn 1224: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1225: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1226: $is_custom{'font'} = 1;
1227: }
1228: foreach my $item (@bgs) {
1229: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1230: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1231: $is_custom{$item} = 1;
1232:
1233: }
1234: }
1235: foreach my $item (@links) {
1236: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1237: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1238: $is_custom{$item} = 1;
1239: }
1240: }
1241: }
1242: my $itemcount = 1;
1.30 raeburn 1243: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1244: $datatable .= '</tr></table></td></tr>';
1245: return $datatable;
1246: }
1247:
1.200 raeburn 1248: sub role_defaults {
1249: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1250: my %defaults;
1251: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1252: return %defaults;
1253: }
1254: my %defaultdesign = %Apache::loncommon::defaultdesign;
1255: if ($role eq 'login') {
1256: %defaults = (
1257: font => $defaultdesign{$role.'.font'},
1258: );
1259: if (ref($logintext) eq 'ARRAY') {
1260: foreach my $item (@{$logintext}) {
1261: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1262: }
1263: }
1264: foreach my $item (@{$images}) {
1265: $defaults{'showlogo'}{$item} = 1;
1266: }
1267: } else {
1268: %defaults = (
1269: img => $defaultdesign{$role.'.img'},
1270: font => $defaultdesign{$role.'.font'},
1271: fontmenu => $defaultdesign{$role.'.fontmenu'},
1272: );
1273: }
1274: foreach my $item (@{$bgs}) {
1275: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1276: }
1277: foreach my $item (@{$links}) {
1278: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1279: }
1280: foreach my $item (@{$images}) {
1281: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1282: }
1283: return %defaults;
1284: }
1285:
1.6 raeburn 1286: sub display_color_options {
1.9 raeburn 1287: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1288: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1289: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1290: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1291: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1292: '<td>'.$choices->{'font'}.'</td>';
1293: if (!$is_custom->{'font'}) {
1.30 raeburn 1294: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1295: } else {
1296: $datatable .= '<td> </td>';
1297: }
1.174 foxr 1298: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1299:
1.8 raeburn 1300: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1301: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1302: ' value="'.$current_color.'" /> '.
1.174 foxr 1303: ' </td></tr>';
1.107 raeburn 1304: unless ($role eq 'login') {
1305: $datatable .= '<tr'.$css_class.'>'.
1306: '<td>'.$choices->{'fontmenu'}.'</td>';
1307: if (!$is_custom->{'fontmenu'}) {
1308: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1309: } else {
1310: $datatable .= '<td> </td>';
1311: }
1.202 raeburn 1312: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1313: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1314: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1315: '<input class="colorchooser" type="text" size="10" name="'
1316: .$role.'_fontmenu"'.
1317: ' value="'.$current_color.'" /> '.
1318: ' </td></tr>';
1.97 tempelho 1319: }
1.9 raeburn 1320: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1321: foreach my $img (@{$images}) {
1.18 albertel 1322: $itemcount ++;
1.6 raeburn 1323: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1324: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1325: '<td>'.$choices->{$img};
1.41 raeburn 1326: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1327: if ($role eq 'login') {
1328: if ($img eq 'login') {
1329: $login_hdr_pick =
1.135 bisitz 1330: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1331: $logincolors =
1332: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1333: $designs,$defaults);
1.70 raeburn 1334: } elsif ($img ne 'domlogo') {
1335: $datatable.= &logo_display_options($img,$defaults,$designs);
1336: }
1337: }
1338: $datatable .= '</td>';
1.6 raeburn 1339: if ($designs->{$img} ne '') {
1340: $imgfile = $designs->{$img};
1.18 albertel 1341: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1342: } else {
1343: $imgfile = $defaults->{$img};
1344: }
1345: if ($imgfile) {
1.9 raeburn 1346: my ($showfile,$fullsize);
1347: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1348: my $urldir = $1;
1349: my $filename = $2;
1350: my @info = &Apache::lonnet::stat_file($designs->{$img});
1351: if (@info) {
1352: my $thumbfile = 'tn-'.$filename;
1353: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1354: if (@thumb) {
1355: $showfile = $urldir.'/'.$thumbfile;
1356: } else {
1357: $showfile = $imgfile;
1358: }
1359: } else {
1360: $showfile = '';
1361: }
1362: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1363: $showfile = $imgfile;
1.6 raeburn 1364: my $imgdir = $1;
1365: my $filename = $2;
1.159 raeburn 1366: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1367: $showfile = "/$imgdir/tn-".$filename;
1368: } else {
1.159 raeburn 1369: my $input = $londocroot.$imgfile;
1370: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1371: if (!-e $output) {
1.9 raeburn 1372: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1373: my ($fullwidth,$fullheight) = &check_dimensions($input);
1374: if ($fullwidth ne '' && $fullheight ne '') {
1375: if ($fullwidth > $width && $fullheight > $height) {
1376: my $size = $width.'x'.$height;
1377: system("convert -sample $size $input $output");
1.159 raeburn 1378: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1379: }
1380: }
1.6 raeburn 1381: }
1382: }
1.16 raeburn 1383: }
1.6 raeburn 1384: if ($showfile) {
1.40 raeburn 1385: if ($showfile =~ m{^/(adm|res)/}) {
1386: if ($showfile =~ m{^/res/}) {
1387: my $local_showfile =
1388: &Apache::lonnet::filelocation('',$showfile);
1389: &Apache::lonnet::repcopy($local_showfile);
1390: }
1391: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1392: }
1393: if ($imgfile) {
1394: if ($imgfile =~ m{^/(adm|res)/}) {
1395: if ($imgfile =~ m{^/res/}) {
1396: my $local_imgfile =
1397: &Apache::lonnet::filelocation('',$imgfile);
1398: &Apache::lonnet::repcopy($local_imgfile);
1399: }
1400: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1401: } else {
1402: $fullsize = $imgfile;
1403: }
1404: }
1.41 raeburn 1405: $datatable .= '<td>';
1406: if ($img eq 'login') {
1.135 bisitz 1407: $datatable .= $login_hdr_pick;
1408: }
1.41 raeburn 1409: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1410: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1411: } else {
1.201 raeburn 1412: $datatable .= '<td> </td><td class="LC_left_item">'.
1413: &mt('Upload:').'<br />';
1.6 raeburn 1414: }
1415: } else {
1.201 raeburn 1416: $datatable .= '<td> </td><td class="LC_left_item">'.
1417: &mt('Upload:').'<br />';
1.6 raeburn 1418: }
1.9 raeburn 1419: if ($switchserver) {
1420: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1421: } else {
1.135 bisitz 1422: if ($img ne 'login') { # suppress file selection for Log-in header
1423: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1424: }
1.9 raeburn 1425: }
1426: $datatable .= '</td></tr>';
1.6 raeburn 1427: }
1428: $itemcount ++;
1429: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1430: $datatable .= '<tr'.$css_class.'>'.
1431: '<td>'.$choices->{'bgs'}.'</td>';
1432: my $bgs_def;
1433: foreach my $item (@{$bgs}) {
1434: if (!$is_custom->{$item}) {
1.70 raeburn 1435: $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 1436: }
1437: }
1438: if ($bgs_def) {
1.8 raeburn 1439: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1440: } else {
1441: $datatable .= '<td> </td>';
1442: }
1443: $datatable .= '<td class="LC_right_item">'.
1444: '<table border="0"><tr>';
1.174 foxr 1445:
1.6 raeburn 1446: foreach my $item (@{$bgs}) {
1.201 raeburn 1447: $datatable .= '<td align="center">'.$choices->{$item};
1.174 foxr 1448: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1449: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1450: $datatable .= ' ';
1.6 raeburn 1451: }
1.174 foxr 1452: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1453: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1454: }
1455: $datatable .= '</tr></table></td></tr>';
1456: $itemcount ++;
1457: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1458: $datatable .= '<tr'.$css_class.'>'.
1459: '<td>'.$choices->{'links'}.'</td>';
1460: my $links_def;
1461: foreach my $item (@{$links}) {
1462: if (!$is_custom->{$item}) {
1.30 raeburn 1463: $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 1464: }
1465: }
1466: if ($links_def) {
1.8 raeburn 1467: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1468: } else {
1469: $datatable .= '<td> </td>';
1470: }
1471: $datatable .= '<td class="LC_right_item">'.
1472: '<table border="0"><tr>';
1473: foreach my $item (@{$links}) {
1.174 foxr 1474: my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
1.201 raeburn 1475: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1476: if ($designs->{'links'}{$item}) {
1.174 foxr 1477: $datatable.=' ';
1.6 raeburn 1478: }
1.174 foxr 1479: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1480: '" /></td>';
1481: }
1.30 raeburn 1482: $$rowtotal += $itemcount;
1.3 raeburn 1483: return $datatable;
1484: }
1485:
1.70 raeburn 1486: sub logo_display_options {
1487: my ($img,$defaults,$designs) = @_;
1488: my $checkedon;
1489: if (ref($defaults) eq 'HASH') {
1490: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1491: if ($defaults->{'showlogo'}{$img}) {
1492: $checkedon = 'checked="checked" ';
1493: }
1494: }
1495: }
1496: if (ref($designs) eq 'HASH') {
1497: if (ref($designs->{'showlogo'}) eq 'HASH') {
1498: if (defined($designs->{'showlogo'}{$img})) {
1499: if ($designs->{'showlogo'}{$img} == 0) {
1500: $checkedon = '';
1501: } elsif ($designs->{'showlogo'}{$img} == 1) {
1502: $checkedon = 'checked="checked" ';
1503: }
1504: }
1505: }
1506: }
1507: return '<br /><label> <input type="checkbox" name="'.
1508: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1509: &mt('show').'</label>'."\n";
1510: }
1511:
1.41 raeburn 1512: sub login_header_options {
1.135 bisitz 1513: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1514: my $output = '';
1.41 raeburn 1515: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1516: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1517: if (!$is_custom->{'textcol'}) {
1518: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1519: ' ';
1520: }
1521: if (!$is_custom->{'bgcol'}) {
1522: $output .= $choices->{'bgcol'}.': '.
1523: '<span id="css_'.$role.'_font" style="background-color: '.
1524: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1525: }
1526: $output .= '<br />';
1527: }
1528: $output .='<br />';
1529: return $output;
1530: }
1531:
1532: sub login_text_colors {
1.201 raeburn 1533: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1534: my $color_menu = '<table border="0"><tr>';
1535: foreach my $item (@{$logintext}) {
1.201 raeburn 1536: $color_menu .= '<td align="center">'.$choices->{$item};
1537: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1538: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1539: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1540: }
1541: $color_menu .= '</tr></table><br />';
1542: return $color_menu;
1543: }
1544:
1545: sub image_changes {
1546: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1547: my $output;
1.135 bisitz 1548: if ($img eq 'login') {
1549: # suppress image for Log-in header
1550: } elsif (!$is_custom) {
1.70 raeburn 1551: if ($img ne 'domlogo') {
1.41 raeburn 1552: $output .= &mt('Default image:').'<br />';
1553: } else {
1554: $output .= &mt('Default in use:').'<br />';
1555: }
1556: }
1.135 bisitz 1557: if ($img eq 'login') { # suppress image for Log-in header
1558: $output .= '<td>'.$logincolors;
1.41 raeburn 1559: } else {
1.135 bisitz 1560: if ($img_import) {
1561: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1562: }
1563: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1564: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1565: if ($is_custom) {
1566: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1567: '<input type="checkbox" name="'.
1568: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1569: '</label> '.&mt('Replace:').'</span><br />';
1570: } else {
1.201 raeburn 1571: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1572: }
1.41 raeburn 1573: }
1574: return $output;
1575: }
1576:
1.3 raeburn 1577: sub print_quotas {
1.86 raeburn 1578: my ($dom,$settings,$rowtotal,$action) = @_;
1579: my $context;
1580: if ($action eq 'quotas') {
1581: $context = 'tools';
1582: } else {
1583: $context = $action;
1584: }
1.197 raeburn 1585: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1586: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1587: my $typecount = 0;
1.101 raeburn 1588: my ($css_class,%titles);
1.86 raeburn 1589: if ($context eq 'requestcourses') {
1.216 raeburn 1590: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1591: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1592: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1593: %titles = &courserequest_titles();
1.163 raeburn 1594: } elsif ($context eq 'requestauthor') {
1595: @usertools = ('author');
1596: @options = ('norequest','approval','automatic');
1.210 raeburn 1597: %titles = &authorrequest_titles();
1.86 raeburn 1598: } else {
1.162 raeburn 1599: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1600: %titles = &tool_titles();
1.86 raeburn 1601: }
1.26 raeburn 1602: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1603: foreach my $type (@{$types}) {
1.197 raeburn 1604: my ($currdefquota,$currauthorquota);
1.163 raeburn 1605: unless (($context eq 'requestcourses') ||
1606: ($context eq 'requestauthor')) {
1.86 raeburn 1607: if (ref($settings) eq 'HASH') {
1608: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1609: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1610: } else {
1611: $currdefquota = $settings->{$type};
1612: }
1.197 raeburn 1613: if (ref($settings->{authorquota}) eq 'HASH') {
1614: $currauthorquota = $settings->{authorquota}->{$type};
1615: }
1.78 raeburn 1616: }
1.72 raeburn 1617: }
1.3 raeburn 1618: if (defined($usertypes->{$type})) {
1619: $typecount ++;
1620: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1621: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1622: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1623: '<td class="LC_left_item">';
1.101 raeburn 1624: if ($context eq 'requestcourses') {
1625: $datatable .= '<table><tr>';
1626: }
1627: my %cell;
1.72 raeburn 1628: foreach my $item (@usertools) {
1.101 raeburn 1629: if ($context eq 'requestcourses') {
1630: my ($curroption,$currlimit);
1631: if (ref($settings) eq 'HASH') {
1632: if (ref($settings->{$item}) eq 'HASH') {
1633: $curroption = $settings->{$item}->{$type};
1634: if ($curroption =~ /^autolimit=(\d*)$/) {
1635: $currlimit = $1;
1636: }
1637: }
1638: }
1639: if (!$curroption) {
1640: $curroption = 'norequest';
1641: }
1642: $datatable .= '<th>'.$titles{$item}.'</th>';
1643: foreach my $option (@options) {
1644: my $val = $option;
1645: if ($option eq 'norequest') {
1646: $val = 0;
1647: }
1648: if ($option eq 'validate') {
1649: my $canvalidate = 0;
1650: if (ref($validations{$item}) eq 'HASH') {
1651: if ($validations{$item}{$type}) {
1652: $canvalidate = 1;
1653: }
1654: }
1655: next if (!$canvalidate);
1656: }
1657: my $checked = '';
1658: if ($option eq $curroption) {
1659: $checked = ' checked="checked"';
1660: } elsif ($option eq 'autolimit') {
1661: if ($curroption =~ /^autolimit/) {
1662: $checked = ' checked="checked"';
1663: }
1664: }
1665: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1666: '<input type="radio" name="crsreq_'.$item.
1667: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1668: $titles{$option}.'</label>';
1.101 raeburn 1669: if ($option eq 'autolimit') {
1.127 raeburn 1670: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1671: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1672: 'value="'.$currlimit.'" />';
1.101 raeburn 1673: }
1.127 raeburn 1674: $cell{$item} .= '</span> ';
1.103 raeburn 1675: if ($option eq 'autolimit') {
1.127 raeburn 1676: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1677: }
1.101 raeburn 1678: }
1.163 raeburn 1679: } elsif ($context eq 'requestauthor') {
1680: my $curroption;
1681: if (ref($settings) eq 'HASH') {
1682: $curroption = $settings->{$type};
1683: }
1684: if (!$curroption) {
1685: $curroption = 'norequest';
1686: }
1687: foreach my $option (@options) {
1688: my $val = $option;
1689: if ($option eq 'norequest') {
1690: $val = 0;
1691: }
1692: my $checked = '';
1693: if ($option eq $curroption) {
1694: $checked = ' checked="checked"';
1695: }
1696: $datatable .= '<span class="LC_nobreak"><label>'.
1697: '<input type="radio" name="authorreq_'.$type.
1698: '" value="'.$val.'"'.$checked.' />'.
1699: $titles{$option}.'</label></span> ';
1700: }
1.101 raeburn 1701: } else {
1702: my $checked = 'checked="checked" ';
1703: if (ref($settings) eq 'HASH') {
1704: if (ref($settings->{$item}) eq 'HASH') {
1705: if ($settings->{$item}->{$type} == 0) {
1706: $checked = '';
1707: } elsif ($settings->{$item}->{$type} == 1) {
1708: $checked = 'checked="checked" ';
1709: }
1.78 raeburn 1710: }
1.72 raeburn 1711: }
1.101 raeburn 1712: $datatable .= '<span class="LC_nobreak"><label>'.
1713: '<input type="checkbox" name="'.$context.'_'.$item.
1714: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1715: '</label></span> ';
1.72 raeburn 1716: }
1.101 raeburn 1717: }
1718: if ($context eq 'requestcourses') {
1719: $datatable .= '</tr><tr>';
1720: foreach my $item (@usertools) {
1.106 raeburn 1721: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1722: }
1723: $datatable .= '</tr></table>';
1.72 raeburn 1724: }
1.86 raeburn 1725: $datatable .= '</td>';
1.163 raeburn 1726: unless (($context eq 'requestcourses') ||
1727: ($context eq 'requestauthor')) {
1.86 raeburn 1728: $datatable .=
1.197 raeburn 1729: '<td class="LC_right_item">'.
1730: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1731: '<input type="text" name="quota_'.$type.
1.72 raeburn 1732: '" value="'.$currdefquota.
1.197 raeburn 1733: '" size="5" /></span>'.(' ' x 2).
1734: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1735: '<input type="text" name="authorquota_'.$type.
1736: '" value="'.$currauthorquota.
1737: '" size="5" /></span></td>';
1.86 raeburn 1738: }
1739: $datatable .= '</tr>';
1.3 raeburn 1740: }
1741: }
1742: }
1.163 raeburn 1743: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1744: $defaultquota = '20';
1.197 raeburn 1745: $authorquota = '500';
1.86 raeburn 1746: if (ref($settings) eq 'HASH') {
1747: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1748: $defaultquota = $settings->{'defaultquota'}->{'default'};
1749: } elsif (defined($settings->{'default'})) {
1750: $defaultquota = $settings->{'default'};
1751: }
1.197 raeburn 1752: if (ref($settings->{'authorquota'}) eq 'HASH') {
1753: $authorquota = $settings->{'authorquota'}->{'default'};
1754: }
1.3 raeburn 1755: }
1756: }
1757: $typecount ++;
1758: $css_class = $typecount%2?' class="LC_odd_row"':'';
1759: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1760: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1761: '<td class="LC_left_item">';
1.101 raeburn 1762: if ($context eq 'requestcourses') {
1763: $datatable .= '<table><tr>';
1764: }
1765: my %defcell;
1.72 raeburn 1766: foreach my $item (@usertools) {
1.101 raeburn 1767: if ($context eq 'requestcourses') {
1768: my ($curroption,$currlimit);
1769: if (ref($settings) eq 'HASH') {
1770: if (ref($settings->{$item}) eq 'HASH') {
1771: $curroption = $settings->{$item}->{'default'};
1772: if ($curroption =~ /^autolimit=(\d*)$/) {
1773: $currlimit = $1;
1774: }
1775: }
1776: }
1777: if (!$curroption) {
1778: $curroption = 'norequest';
1779: }
1780: $datatable .= '<th>'.$titles{$item}.'</th>';
1781: foreach my $option (@options) {
1782: my $val = $option;
1783: if ($option eq 'norequest') {
1784: $val = 0;
1785: }
1786: if ($option eq 'validate') {
1787: my $canvalidate = 0;
1788: if (ref($validations{$item}) eq 'HASH') {
1789: if ($validations{$item}{'default'}) {
1790: $canvalidate = 1;
1791: }
1792: }
1793: next if (!$canvalidate);
1794: }
1795: my $checked = '';
1796: if ($option eq $curroption) {
1797: $checked = ' checked="checked"';
1798: } elsif ($option eq 'autolimit') {
1799: if ($curroption =~ /^autolimit/) {
1800: $checked = ' checked="checked"';
1801: }
1802: }
1803: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1804: '<input type="radio" name="crsreq_'.$item.
1805: '_default" value="'.$val.'"'.$checked.' />'.
1806: $titles{$option}.'</label>';
1807: if ($option eq 'autolimit') {
1.127 raeburn 1808: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1809: $item.'_limit_default" size="1" '.
1810: 'value="'.$currlimit.'" />';
1811: }
1.127 raeburn 1812: $defcell{$item} .= '</span> ';
1.104 raeburn 1813: if ($option eq 'autolimit') {
1.127 raeburn 1814: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1815: }
1.101 raeburn 1816: }
1.163 raeburn 1817: } elsif ($context eq 'requestauthor') {
1818: my $curroption;
1819: if (ref($settings) eq 'HASH') {
1.172 raeburn 1820: $curroption = $settings->{'default'};
1.163 raeburn 1821: }
1822: if (!$curroption) {
1823: $curroption = 'norequest';
1824: }
1825: foreach my $option (@options) {
1826: my $val = $option;
1827: if ($option eq 'norequest') {
1828: $val = 0;
1829: }
1830: my $checked = '';
1831: if ($option eq $curroption) {
1832: $checked = ' checked="checked"';
1833: }
1834: $datatable .= '<span class="LC_nobreak"><label>'.
1835: '<input type="radio" name="authorreq_default"'.
1836: ' value="'.$val.'"'.$checked.' />'.
1837: $titles{$option}.'</label></span> ';
1838: }
1.101 raeburn 1839: } else {
1840: my $checked = 'checked="checked" ';
1841: if (ref($settings) eq 'HASH') {
1842: if (ref($settings->{$item}) eq 'HASH') {
1843: if ($settings->{$item}->{'default'} == 0) {
1844: $checked = '';
1845: } elsif ($settings->{$item}->{'default'} == 1) {
1846: $checked = 'checked="checked" ';
1847: }
1.78 raeburn 1848: }
1.72 raeburn 1849: }
1.101 raeburn 1850: $datatable .= '<span class="LC_nobreak"><label>'.
1851: '<input type="checkbox" name="'.$context.'_'.$item.
1852: '" value="default" '.$checked.'/>'.$titles{$item}.
1853: '</label></span> ';
1854: }
1855: }
1856: if ($context eq 'requestcourses') {
1857: $datatable .= '</tr><tr>';
1858: foreach my $item (@usertools) {
1.106 raeburn 1859: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1860: }
1.101 raeburn 1861: $datatable .= '</tr></table>';
1.72 raeburn 1862: }
1.86 raeburn 1863: $datatable .= '</td>';
1.163 raeburn 1864: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 1865: $datatable .= '<td class="LC_right_item">'.
1866: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 1867: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 1868: $defaultquota.'" size="5" /></span>'.(' ' x2).
1869: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1870: '<input type="text" name="authorquota" value="'.
1871: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 1872: }
1873: $datatable .= '</tr>';
1.72 raeburn 1874: $typecount ++;
1875: $css_class = $typecount%2?' class="LC_odd_row"':'';
1876: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 1877: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 1878: if ($context eq 'requestcourses') {
1.109 raeburn 1879: $datatable .= &mt('(overrides affiliation, if set)').
1880: '</td>'.
1881: '<td class="LC_left_item">'.
1882: '<table><tr>';
1.101 raeburn 1883: } else {
1.109 raeburn 1884: $datatable .= &mt('(overrides affiliation, if checked)').
1885: '</td>'.
1886: '<td class="LC_left_item" colspan="2">'.
1887: '<br />';
1.101 raeburn 1888: }
1889: my %advcell;
1.72 raeburn 1890: foreach my $item (@usertools) {
1.101 raeburn 1891: if ($context eq 'requestcourses') {
1892: my ($curroption,$currlimit);
1893: if (ref($settings) eq 'HASH') {
1894: if (ref($settings->{$item}) eq 'HASH') {
1895: $curroption = $settings->{$item}->{'_LC_adv'};
1896: if ($curroption =~ /^autolimit=(\d*)$/) {
1897: $currlimit = $1;
1898: }
1899: }
1900: }
1901: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1902: my $checked = '';
1903: if ($curroption eq '') {
1904: $checked = ' checked="checked"';
1905: }
1906: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1907: '<input type="radio" name="crsreq_'.$item.
1908: '__LC_adv" value=""'.$checked.' />'.
1909: &mt('No override set').'</label></span> ';
1.101 raeburn 1910: foreach my $option (@options) {
1911: my $val = $option;
1912: if ($option eq 'norequest') {
1913: $val = 0;
1914: }
1915: if ($option eq 'validate') {
1916: my $canvalidate = 0;
1917: if (ref($validations{$item}) eq 'HASH') {
1918: if ($validations{$item}{'_LC_adv'}) {
1919: $canvalidate = 1;
1920: }
1921: }
1922: next if (!$canvalidate);
1923: }
1924: my $checked = '';
1.104 raeburn 1925: if ($val eq $curroption) {
1.101 raeburn 1926: $checked = ' checked="checked"';
1927: } elsif ($option eq 'autolimit') {
1928: if ($curroption =~ /^autolimit/) {
1929: $checked = ' checked="checked"';
1930: }
1931: }
1932: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1933: '<input type="radio" name="crsreq_'.$item.
1934: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1935: $titles{$option}.'</label>';
1936: if ($option eq 'autolimit') {
1.127 raeburn 1937: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1938: $item.'_limit__LC_adv" size="1" '.
1939: 'value="'.$currlimit.'" />';
1940: }
1.127 raeburn 1941: $advcell{$item} .= '</span> ';
1.104 raeburn 1942: if ($option eq 'autolimit') {
1.127 raeburn 1943: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1944: }
1.101 raeburn 1945: }
1.163 raeburn 1946: } elsif ($context eq 'requestauthor') {
1947: my $curroption;
1948: if (ref($settings) eq 'HASH') {
1949: $curroption = $settings->{'_LC_adv'};
1950: }
1951: my $checked = '';
1952: if ($curroption eq '') {
1953: $checked = ' checked="checked"';
1954: }
1955: $datatable .= '<span class="LC_nobreak"><label>'.
1956: '<input type="radio" name="authorreq__LC_adv"'.
1957: ' value=""'.$checked.' />'.
1958: &mt('No override set').'</label></span> ';
1959: foreach my $option (@options) {
1960: my $val = $option;
1961: if ($option eq 'norequest') {
1962: $val = 0;
1963: }
1964: my $checked = '';
1965: if ($val eq $curroption) {
1966: $checked = ' checked="checked"';
1967: }
1968: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 1969: '<input type="radio" name="authorreq__LC_adv"'.
1970: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 1971: $titles{$option}.'</label></span> ';
1972: }
1.101 raeburn 1973: } else {
1974: my $checked = 'checked="checked" ';
1975: if (ref($settings) eq 'HASH') {
1976: if (ref($settings->{$item}) eq 'HASH') {
1977: if ($settings->{$item}->{'_LC_adv'} == 0) {
1978: $checked = '';
1979: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1980: $checked = 'checked="checked" ';
1981: }
1.79 raeburn 1982: }
1.72 raeburn 1983: }
1.101 raeburn 1984: $datatable .= '<span class="LC_nobreak"><label>'.
1985: '<input type="checkbox" name="'.$context.'_'.$item.
1986: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1987: '</label></span> ';
1988: }
1989: }
1990: if ($context eq 'requestcourses') {
1991: $datatable .= '</tr><tr>';
1992: foreach my $item (@usertools) {
1.106 raeburn 1993: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1994: }
1.101 raeburn 1995: $datatable .= '</tr></table>';
1.72 raeburn 1996: }
1.98 raeburn 1997: $datatable .= '</td></tr>';
1.30 raeburn 1998: $$rowtotal += $typecount;
1.3 raeburn 1999: return $datatable;
2000: }
2001:
1.163 raeburn 2002: sub print_requestmail {
2003: my ($dom,$action,$settings,$rowtotal) = @_;
1.208 raeburn 2004: my ($now,$datatable,%currapp);
1.102 raeburn 2005: $now = time;
2006: if (ref($settings) eq 'HASH') {
2007: if (ref($settings->{'notify'}) eq 'HASH') {
2008: if ($settings->{'notify'}{'approval'} ne '') {
1.224 ! raeburn 2009: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2010: }
2011: }
2012: }
1.191 raeburn 2013: my $numinrow = 2;
1.224 ! raeburn 2014: my $css_class;
! 2015: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.163 raeburn 2016: my $text;
2017: if ($action eq 'requestcourses') {
2018: $text = &mt('Receive notification of course requests requiring approval');
1.224 ! raeburn 2019: } elsif ($action eq 'requestauthor') {
! 2020: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2021: } else {
1.224 ! raeburn 2022: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2023: }
1.224 ! raeburn 2024: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2025: ' <td>'.$text.'</td>'.
1.102 raeburn 2026: ' <td class="LC_left_item">';
1.191 raeburn 2027: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 ! raeburn 2028: $action.'notifyapproval',%currapp);
1.191 raeburn 2029: if ($numdc > 0) {
2030: $datatable .= $table;
1.102 raeburn 2031: } else {
2032: $datatable .= &mt('There are no active Domain Coordinators');
2033: }
2034: $datatable .='</td></tr>';
2035: $$rowtotal += $rows;
2036: return $datatable;
2037: }
2038:
1.216 raeburn 2039: sub print_studentcode {
2040: my ($settings,$rowtotal) = @_;
2041: my $rownum = 0;
1.218 raeburn 2042: my ($output,%current);
2043: my @crstypes = ('official','unofficial','community','textbook');
2044: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2045: foreach my $type (@crstypes) {
2046: $current{$type} = $settings->{'uniquecode'}{$type};
2047: }
2048: }
2049: $output .= '<tr>'.
2050: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2051: '<td class="LC_left_item">';
2052: foreach my $type (@crstypes) {
2053: my $check = ' ';
2054: if ($current{$type}) {
2055: $check = ' checked="checked" ';
2056: }
2057: $output .= '<span class="LC_nobreak"><label>'.
2058: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2059: &mt($type).'</label></span>'.(' 'x2).' ';
2060: }
2061: $output .= '</td></tr>';
2062: $$rowtotal ++;
2063: return $output;
1.216 raeburn 2064: }
2065:
2066: sub print_textbookcourses {
2067: my ($dom,$settings,$rowtotal) = @_;
2068: my $rownum = 0;
2069: my $css_class;
2070: my $itemcount = 1;
2071: my $maxnum = 0;
2072: my $bookshash;
2073: if (ref($settings) eq 'HASH') {
2074: $bookshash = $settings->{'textbooks'};
2075: }
2076: my %ordered;
2077: if (ref($bookshash) eq 'HASH') {
2078: foreach my $item (keys(%{$bookshash})) {
2079: if (ref($bookshash->{$item}) eq 'HASH') {
2080: my $num = $bookshash->{$item}{'order'};
2081: $ordered{$num} = $item;
2082: }
2083: }
2084: }
2085: my $confname = $dom.'-domainconfig';
2086: my $switchserver = &check_switchserver($dom,$confname);
2087: my $maxnum = scalar(keys(%ordered));
1.217 raeburn 2088: my $datatable = &textbookcourses_javascript(\%ordered);
1.216 raeburn 2089: if (keys(%ordered)) {
2090: my @items = sort { $a <=> $b } keys(%ordered);
2091: for (my $i=0; $i<@items; $i++) {
2092: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2093: my $key = $ordered{$items[$i]};
2094: my %coursehash=&Apache::lonnet::coursedescription($key);
2095: my $coursetitle = $coursehash{'description'};
2096: my ($subject,$title,$author,$image,$imgsrc,$cdom,$cnum);
2097: if (ref($bookshash->{$key}) eq 'HASH') {
2098: $subject = $bookshash->{$key}->{'subject'};
2099: $title = $bookshash->{$key}->{'title'};
2100: $author = $bookshash->{$key}->{'author'};
2101: $image = $bookshash->{$key}->{'image'};
2102: if ($image ne '') {
2103: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2104: my $imagethumb = "$path/tn-".$imagefile;
2105: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2106: }
2107: }
1.217 raeburn 2108: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$key'".');"';
1.216 raeburn 2109: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
2110: .'<select name="'.$key.'"'.$chgstr.'>';
2111: for (my $k=0; $k<=$maxnum; $k++) {
2112: my $vpos = $k+1;
2113: my $selstr;
2114: if ($k == $i) {
2115: $selstr = ' selected="selected" ';
2116: }
2117: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2118: }
2119: $datatable .= '</select>'.(' 'x2).
2120: '<label><input type="checkbox" name="book_del" value="'.$key.'" />'.
2121: &mt('Delete?').'</label></span></td>'.
2122: '<td colspan="2">'.
2123: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="book_subject_'.$i.'" value="'.$subject.'" /></span> '.
2124: (' 'x2).
2125: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="book_title_'.$i.'" value="'.$title.'" /></span> '.
2126: (' 'x2).
2127: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="book_author_'.$i.'" value="'.$author.'" /></span> '.
2128: (' 'x2).
2129: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2130: if ($image) {
2131: $datatable .= '<span class="LC_nobreak">'.
2132: $imgsrc.
2133: '<label><input type="checkbox" name="book_image_del"'.
2134: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2135: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2136: }
2137: if ($switchserver) {
2138: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2139: } else {
2140: $datatable .= '<input type="file" name="book_image_'.$i.'" value="" />';
2141: }
2142: $datatable .= '<input type="hidden" name="book_id_'.$i.'" value="'.$key.'" /></span> '.
2143: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2144: $coursetitle.'</span></td></tr>'."\n";
2145: $itemcount ++;
2146: }
2147: }
2148: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.217 raeburn 2149: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'addbook_pos'".');"';
1.216 raeburn 2150: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
2151: '<input type="hidden" name="book_maxnum" value="'.$maxnum.'" />'."\n".
2152: '<select name="addbook_pos"'.$chgstr.'>';
2153: for (my $k=0; $k<$maxnum+1; $k++) {
2154: my $vpos = $k+1;
2155: my $selstr;
2156: if ($k == $maxnum) {
2157: $selstr = ' selected="selected" ';
2158: }
2159: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2160: }
2161: $datatable .= '</select> '."\n".
2162: '<input type="checkbox" name="addbook" value="1" />'.&mt('Add').'</td>'."\n".
2163: '<td colspan="2">'.
2164: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="addbook_subject" value="" /></span> '."\n".
2165: (' 'x2).
2166: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="addbook_title" value="" /></span> '."\n".
2167: (' 'x2).
2168: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="addbook_author" value="" /></span> '."\n".
2169: (' 'x2).
2170: '<span class="LC_nobreak">'.&mt('Image:').' ';
2171: if ($switchserver) {
2172: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2173: } else {
2174: $datatable .= '<input type="file" name="addbook_image" value="" />';
2175: }
2176: $datatable .= '</span>'."\n".
2177: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2178: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'addbook_cdom').
2179: '<input type="text" size="25" name="addbook_cnum" value="" />'.
2180: &Apache::loncommon::selectcourse_link
2181: ('display','addbook_cnum','addbook_cdom',undef,undef,undef,'Course');
2182: '</span></td>'."\n".
2183: '</tr>'."\n";
2184: $itemcount ++;
2185: return $datatable;
2186: }
2187:
1.217 raeburn 2188: sub textbookcourses_javascript {
2189: my ($textbooks) = @_;
2190: return unless(ref($textbooks) eq 'HASH');
2191: my $num = scalar(keys(%{$textbooks}));
2192: my @jsarray;
2193: foreach my $item (sort {$a <=> $b } (keys(%{$textbooks}))) {
2194: push(@jsarray,$textbooks->{$item});
2195: }
2196: my $jstext = ' var textbooks = Array('."'".join("','",@jsarray)."'".');'."\n";
2197: return <<"ENDSCRIPT";
2198: <script type="text/javascript">
2199: // <![CDATA[
2200: function reorderBooks(form,item) {
2201: var changedVal;
2202: $jstext
2203: var newpos = 'addbook_pos';
2204: var current = new Array;
2205: var maxh = 1 + $num;
2206: var current = new Array;
2207: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2208: if (item == newpos) {
2209: changedVal = newitemVal;
2210: } else {
2211: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2212: current[newitemVal] = newpos;
2213: }
2214: for (var i=0; i<textbooks.length; i++) {
2215: var elementName = textbooks[i];
2216: if (elementName != item) {
2217: if (form.elements[elementName]) {
2218: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2219: current[currVal] = elementName;
2220: }
2221: }
2222: }
2223: var oldVal;
2224: for (var j=0; j<maxh; j++) {
2225: if (current[j] == undefined) {
2226: oldVal = j;
2227: }
2228: }
2229: if (oldVal < changedVal) {
2230: for (var k=oldVal+1; k<=changedVal ; k++) {
2231: var elementName = current[k];
2232: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2233: }
2234: } else {
2235: for (var k=changedVal; k<oldVal; k++) {
2236: var elementName = current[k];
2237: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2238: }
2239: }
2240: return;
2241: }
2242:
2243: // ]]>
2244: </script>
2245:
2246: ENDSCRIPT
2247: }
2248:
1.3 raeburn 2249: sub print_autoenroll {
1.30 raeburn 2250: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2251: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 2252: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 2253: if (ref($settings) eq 'HASH') {
2254: if (exists($settings->{'run'})) {
2255: if ($settings->{'run'} eq '0') {
2256: $runoff = ' checked="checked" ';
2257: $runon = ' ';
2258: } else {
2259: $runon = ' checked="checked" ';
2260: $runoff = ' ';
2261: }
2262: } else {
2263: if ($autorun) {
2264: $runon = ' checked="checked" ';
2265: $runoff = ' ';
2266: } else {
2267: $runoff = ' checked="checked" ';
2268: $runon = ' ';
2269: }
2270: }
1.129 raeburn 2271: if (exists($settings->{'co-owners'})) {
2272: if ($settings->{'co-owners'} eq '0') {
2273: $coownersoff = ' checked="checked" ';
2274: $coownerson = ' ';
2275: } else {
2276: $coownerson = ' checked="checked" ';
2277: $coownersoff = ' ';
2278: }
2279: } else {
2280: $coownersoff = ' checked="checked" ';
2281: $coownerson = ' ';
2282: }
1.3 raeburn 2283: if (exists($settings->{'sender_domain'})) {
2284: $defdom = $settings->{'sender_domain'};
2285: }
1.14 raeburn 2286: } else {
2287: if ($autorun) {
2288: $runon = ' checked="checked" ';
2289: $runoff = ' ';
2290: } else {
2291: $runoff = ' checked="checked" ';
2292: $runon = ' ';
2293: }
1.3 raeburn 2294: }
2295: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2296: my $notif_sender;
2297: if (ref($settings) eq 'HASH') {
2298: $notif_sender = $settings->{'sender_uname'};
2299: }
1.3 raeburn 2300: my $datatable='<tr class="LC_odd_row">'.
2301: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2302: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2303: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2304: $runon.' value="1" />'.&mt('Yes').'</label> '.
2305: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2306: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2307: '</tr><tr>'.
2308: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2309: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2310: &mt('username').': '.
2311: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2312: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2313: ': '.$domform.'</span></td></tr>'.
2314: '<tr class="LC_odd_row">'.
2315: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2316: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2317: '<input type="radio" name="autoassign_coowners"'.
2318: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2319: '<label><input type="radio" name="autoassign_coowners"'.
2320: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2321: '</tr>';
2322: $$rowtotal += 3;
1.3 raeburn 2323: return $datatable;
2324: }
2325:
2326: sub print_autoupdate {
1.30 raeburn 2327: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2328: my $datatable;
2329: if ($position eq 'top') {
2330: my $updateon = ' ';
2331: my $updateoff = ' checked="checked" ';
2332: my $classlistson = ' ';
2333: my $classlistsoff = ' checked="checked" ';
2334: if (ref($settings) eq 'HASH') {
2335: if ($settings->{'run'} eq '1') {
2336: $updateon = $updateoff;
2337: $updateoff = ' ';
2338: }
2339: if ($settings->{'classlists'} eq '1') {
2340: $classlistson = $classlistsoff;
2341: $classlistsoff = ' ';
2342: }
2343: }
2344: my %title = (
2345: run => 'Auto-update active?',
2346: classlists => 'Update information in classlists?',
2347: );
2348: $datatable = '<tr class="LC_odd_row">'.
2349: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2350: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2351: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2352: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2353: '<label><input type="radio" name="autoupdate_run"'.
2354: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2355: '</tr><tr>'.
2356: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2357: '<td class="LC_right_item"><span class="LC_nobreak">'.
2358: '<label><input type="radio" name="classlists"'.
2359: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2360: '<label><input type="radio" name="classlists"'.
2361: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2362: '</tr>';
1.30 raeburn 2363: $$rowtotal += 2;
1.131 raeburn 2364: } elsif ($position eq 'middle') {
2365: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2366: my $numinrow = 3;
2367: my $locknamesettings;
2368: $datatable .= &insttypes_row($settings,$types,$usertypes,
2369: $dom,$numinrow,$othertitle,
2370: 'lockablenames');
2371: $$rowtotal ++;
1.3 raeburn 2372: } else {
1.44 raeburn 2373: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2374: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2375: 'permanentemail','id');
1.33 raeburn 2376: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2377: my $numrows = 0;
1.26 raeburn 2378: if (ref($types) eq 'ARRAY') {
2379: if (@{$types} > 0) {
2380: $datatable =
2381: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2382: \@fields,$types,\$numrows);
1.30 raeburn 2383: $$rowtotal += @{$types};
1.26 raeburn 2384: }
1.3 raeburn 2385: }
2386: $datatable .=
2387: &usertype_update_row($settings,{'default' => $othertitle},
2388: \%fieldtitles,\@fields,['default'],
2389: \$numrows);
1.30 raeburn 2390: $$rowtotal ++;
1.3 raeburn 2391: }
2392: return $datatable;
2393: }
2394:
1.125 raeburn 2395: sub print_autocreate {
2396: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 2397: my (%createon,%createoff,%currhash);
1.125 raeburn 2398: my @types = ('xml','req');
2399: if (ref($settings) eq 'HASH') {
2400: foreach my $item (@types) {
2401: $createoff{$item} = ' checked="checked" ';
2402: $createon{$item} = ' ';
2403: if (exists($settings->{$item})) {
2404: if ($settings->{$item}) {
2405: $createon{$item} = ' checked="checked" ';
2406: $createoff{$item} = ' ';
2407: }
2408: }
2409: }
1.210 raeburn 2410: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 2411: $currhash{$settings->{'xmldc'}} = 1;
2412: }
1.125 raeburn 2413: } else {
2414: foreach my $item (@types) {
2415: $createoff{$item} = ' checked="checked" ';
2416: $createon{$item} = ' ';
2417: }
2418: }
2419: $$rowtotal += 2;
1.191 raeburn 2420: my $numinrow = 2;
1.125 raeburn 2421: my $datatable='<tr class="LC_odd_row">'.
2422: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2423: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2424: '<input type="radio" name="autocreate_xml"'.
2425: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2426: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2427: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2428: '</td></tr><tr>'.
2429: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2430: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2431: '<input type="radio" name="autocreate_req"'.
2432: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2433: '<label><input type="radio" name="autocreate_req"'.
2434: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 2435: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2436: 'autocreate_xmldc',%currhash);
1.125 raeburn 2437: if ($numdc > 1) {
1.143 raeburn 2438: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2439: &mt('Course creation processed as: (choose Dom. Coord.)').
2440: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2441: } else {
1.143 raeburn 2442: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2443: }
1.191 raeburn 2444: $$rowtotal += $rows;
1.125 raeburn 2445: return $datatable;
2446: }
2447:
1.23 raeburn 2448: sub print_directorysrch {
1.30 raeburn 2449: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2450: my $srchon = ' ';
2451: my $srchoff = ' checked="checked" ';
1.25 raeburn 2452: my ($exacton,$containson,$beginson);
1.24 raeburn 2453: my $localon = ' ';
2454: my $localoff = ' checked="checked" ';
1.23 raeburn 2455: if (ref($settings) eq 'HASH') {
2456: if ($settings->{'available'} eq '1') {
2457: $srchon = $srchoff;
2458: $srchoff = ' ';
2459: }
1.24 raeburn 2460: if ($settings->{'localonly'} eq '1') {
2461: $localon = $localoff;
2462: $localoff = ' ';
2463: }
1.25 raeburn 2464: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2465: foreach my $type (@{$settings->{'searchtypes'}}) {
2466: if ($type eq 'exact') {
2467: $exacton = ' checked="checked" ';
2468: } elsif ($type eq 'contains') {
2469: $containson = ' checked="checked" ';
2470: } elsif ($type eq 'begins') {
2471: $beginson = ' checked="checked" ';
2472: }
2473: }
2474: } else {
2475: if ($settings->{'searchtypes'} eq 'exact') {
2476: $exacton = ' checked="checked" ';
2477: } elsif ($settings->{'searchtypes'} eq 'contains') {
2478: $containson = ' checked="checked" ';
2479: } elsif ($settings->{'searchtypes'} eq 'specify') {
2480: $exacton = ' checked="checked" ';
2481: $containson = ' checked="checked" ';
2482: }
1.23 raeburn 2483: }
2484: }
2485: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2486: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2487:
2488: my $numinrow = 4;
1.26 raeburn 2489: my $cansrchrow = 0;
1.23 raeburn 2490: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2491: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2492: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2493: '<input type="radio" name="dirsrch_available"'.
2494: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2495: '<label><input type="radio" name="dirsrch_available"'.
2496: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2497: '</tr><tr>'.
1.30 raeburn 2498: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2499: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2500: '<input type="radio" name="dirsrch_localonly"'.
2501: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2502: '<label><input type="radio" name="dirsrch_localonly"'.
2503: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2504: '</tr>';
1.30 raeburn 2505: $$rowtotal += 2;
1.26 raeburn 2506: if (ref($usertypes) eq 'HASH') {
2507: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2508: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2509: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2510: $cansrchrow = 1;
2511: }
2512: }
2513: if ($cansrchrow) {
1.30 raeburn 2514: $$rowtotal ++;
1.26 raeburn 2515: $datatable .= '<tr>';
2516: } else {
2517: $datatable .= '<tr class="LC_odd_row">';
2518: }
1.30 raeburn 2519: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2520: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2521: foreach my $title (@{$titleorder}) {
2522: if (defined($searchtitles->{$title})) {
2523: my $check = ' ';
1.93 raeburn 2524: if (ref($settings) eq 'HASH') {
1.39 raeburn 2525: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2526: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2527: $check = ' checked="checked" ';
2528: }
1.25 raeburn 2529: }
2530: }
2531: $datatable .= '<td class="LC_left_item">'.
2532: '<span class="LC_nobreak"><label>'.
2533: '<input type="checkbox" name="searchby" '.
2534: 'value="'.$title.'"'.$check.'/>'.
2535: $searchtitles->{$title}.'</label></span></td>';
2536: }
2537: }
1.26 raeburn 2538: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2539: $$rowtotal ++;
1.26 raeburn 2540: if ($cansrchrow) {
2541: $datatable .= '<tr class="LC_odd_row">';
2542: } else {
2543: $datatable .= '<tr>';
2544: }
1.30 raeburn 2545: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2546: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2547: '<span class="LC_nobreak"><label>'.
2548: '<input type="checkbox" name="searchtypes" '.
2549: $exacton.' value="exact" />'.&mt('Exact match').
2550: '</label> '.
2551: '<label><input type="checkbox" name="searchtypes" '.
2552: $beginson.' value="begins" />'.&mt('Begins with').
2553: '</label> '.
2554: '<label><input type="checkbox" name="searchtypes" '.
2555: $containson.' value="contains" />'.&mt('Contains').
2556: '</label></span></td></tr>';
1.30 raeburn 2557: $$rowtotal ++;
1.25 raeburn 2558: return $datatable;
2559: }
2560:
1.28 raeburn 2561: sub print_contacts {
1.30 raeburn 2562: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2563: my $datatable;
2564: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2565: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2566: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.203 raeburn 2567: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2568: foreach my $type (@mailings) {
2569: $otheremails{$type} = '';
2570: }
1.134 raeburn 2571: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2572: if (ref($settings) eq 'HASH') {
2573: foreach my $item (@contacts) {
2574: if (exists($settings->{$item})) {
2575: $to{$item} = $settings->{$item};
2576: }
2577: }
2578: foreach my $type (@mailings) {
2579: if (exists($settings->{$type})) {
2580: if (ref($settings->{$type}) eq 'HASH') {
2581: foreach my $item (@contacts) {
2582: if ($settings->{$type}{$item}) {
2583: $checked{$type}{$item} = ' checked="checked" ';
2584: }
2585: }
2586: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2587: if ($type eq 'helpdeskmail') {
2588: $bccemails{$type} = $settings->{$type}{'bcc'};
2589: }
1.28 raeburn 2590: }
1.89 raeburn 2591: } elsif ($type eq 'lonstatusmail') {
2592: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2593: }
2594: }
2595: } else {
2596: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2597: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2598: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2599: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2600: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2601: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2602: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.190 raeburn 2603: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
1.203 raeburn 2604: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2605: }
2606: my ($titles,$short_titles) = &contact_titles();
2607: my $rownum = 0;
2608: my $css_class;
2609: foreach my $item (@contacts) {
1.69 raeburn 2610: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2611: $datatable .= '<tr'.$css_class.'>'.
2612: '<td><span class="LC_nobreak">'.$titles->{$item}.
2613: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2614: '<input type="text" name="'.$item.'" value="'.
2615: $to{$item}.'" /></td></tr>';
1.203 raeburn 2616: $rownum ++;
1.28 raeburn 2617: }
2618: foreach my $type (@mailings) {
1.69 raeburn 2619: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2620: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2621: '<td><span class="LC_nobreak">'.
2622: $titles->{$type}.': </span></td>'.
1.28 raeburn 2623: '<td class="LC_left_item">'.
2624: '<span class="LC_nobreak">';
2625: foreach my $item (@contacts) {
2626: $datatable .= '<label>'.
2627: '<input type="checkbox" name="'.$type.'"'.
2628: $checked{$type}{$item}.
2629: ' value="'.$item.'" />'.$short_titles->{$item}.
2630: '</label> ';
2631: }
2632: $datatable .= '</span><br />'.&mt('Others').': '.
2633: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2634: 'value="'.$otheremails{$type}.'" />';
2635: if ($type eq 'helpdeskmail') {
1.136 raeburn 2636: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2637: '<input type="text" name="'.$type.'_bcc" '.
2638: 'value="'.$bccemails{$type}.'" />';
2639: }
2640: $datatable .= '</td></tr>'."\n";
1.203 raeburn 2641: $rownum ++;
1.28 raeburn 2642: }
1.203 raeburn 2643: my %choices;
2644: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2645: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2646: &mt('LON-CAPA core group - MSU'),600,500));
2647: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2648: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2649: &mt('LON-CAPA core group - MSU'),600,500));
2650: my @toggles = ('reporterrors','reportupdates');
2651: my %defaultchecked = ('reporterrors' => 'on',
2652: 'reportupdates' => 'on');
2653: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2654: \%choices,$rownum);
2655: $datatable .= $reports;
1.30 raeburn 2656: $$rowtotal += $rownum;
1.28 raeburn 2657: return $datatable;
2658: }
2659:
1.118 jms 2660: sub print_helpsettings {
1.168 raeburn 2661: my ($dom,$confname,$settings,$rowtotal) = @_;
2662: my ($datatable,$itemcount);
1.166 raeburn 2663: $itemcount = 1;
1.168 raeburn 2664: my (%choices,%defaultchecked,@toggles);
2665: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2666: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2667: &mt('LON-CAPA bug tracker'),600,500));
2668: %defaultchecked = ('submitbugs' => 'on');
2669: @toggles = ('submitbugs',);
1.166 raeburn 2670:
1.168 raeburn 2671: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2672: \%choices,$itemcount);
1.166 raeburn 2673: return $datatable;
1.121 raeburn 2674: }
2675:
2676: sub radiobutton_prefs {
1.192 raeburn 2677: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
2678: $additional) = @_;
1.121 raeburn 2679: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2680: (ref($choices) eq 'HASH'));
2681:
1.170 raeburn 2682: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 2683:
2684: foreach my $item (@{$toggles}) {
2685: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2686: $checkedon{$item} = ' checked="checked" ';
2687: $checkedoff{$item} = ' ';
1.121 raeburn 2688: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2689: $checkedoff{$item} = ' checked="checked" ';
2690: $checkedon{$item} = ' ';
2691: }
2692: }
2693: if (ref($settings) eq 'HASH') {
1.121 raeburn 2694: foreach my $item (@{$toggles}) {
1.118 jms 2695: if ($settings->{$item} eq '1') {
2696: $checkedon{$item} = ' checked="checked" ';
2697: $checkedoff{$item} = ' ';
2698: } elsif ($settings->{$item} eq '0') {
2699: $checkedoff{$item} = ' checked="checked" ';
2700: $checkedon{$item} = ' ';
2701: }
2702: }
1.121 raeburn 2703: }
1.192 raeburn 2704: if ($onclick) {
2705: $onclick = ' onclick="'.$onclick.'"';
2706: }
1.121 raeburn 2707: foreach my $item (@{$toggles}) {
1.118 jms 2708: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2709: $datatable .=
1.192 raeburn 2710: '<tr'.$css_class.'><td valign="top">'.
2711: '<span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2712: '</span></td>'.
2713: '<td class="LC_right_item"><span class="LC_nobreak">'.
2714: '<label><input type="radio" name="'.
1.192 raeburn 2715: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2716: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 2717: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2718: '</span>'.$additional.
2719: '</td>'.
1.118 jms 2720: '</tr>';
2721: $itemcount ++;
1.121 raeburn 2722: }
2723: return ($datatable,$itemcount);
2724: }
2725:
2726: sub print_coursedefaults {
1.139 raeburn 2727: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 2728: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2729: my $itemcount = 1;
1.192 raeburn 2730: my %choices = &Apache::lonlocal::texthash (
2731: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 2732: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 2733: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2734: coursecredits => 'Credits can be specified for courses',
2735: );
1.198 raeburn 2736: my %staticdefaults = (
2737: anonsurvey_threshold => 10,
2738: uploadquota => 500,
2739: );
1.139 raeburn 2740: if ($position eq 'top') {
2741: %defaultchecked = ('canuse_pdfforms' => 'off');
1.192 raeburn 2742: @toggles = ('canuse_pdfforms');
1.139 raeburn 2743: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2744: \%choices,$itemcount);
1.139 raeburn 2745: } else {
2746: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.216 raeburn 2747: my ($currdefresponder,$def_official_credits,$def_unofficial_credits,$def_textbook_credits,
2748: %curruploadquota);
1.192 raeburn 2749: my $currusecredits = 0;
1.216 raeburn 2750: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 2751: if (ref($settings) eq 'HASH') {
2752: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 2753: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2754: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2755: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2756: }
2757: }
1.192 raeburn 2758: if (ref($settings->{'coursecredits'}) eq 'HASH') {
2759: $def_official_credits = $settings->{'coursecredits'}->{'official'};
2760: $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
1.216 raeburn 2761: $def_textbook_credits = $settings->{'coursecredits'}->{'textbook'};
2762: if (($def_official_credits ne '') || ($def_unofficial_credits ne '') ||
2763: ($def_textbook_credits ne '')) {
1.192 raeburn 2764: $currusecredits = 1;
2765: }
2766: }
1.139 raeburn 2767: }
2768: if (!$currdefresponder) {
1.198 raeburn 2769: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 2770: } elsif ($currdefresponder < 1) {
2771: $currdefresponder = 1;
2772: }
1.198 raeburn 2773: foreach my $type (@types) {
2774: if ($curruploadquota{$type} eq '') {
2775: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
2776: }
2777: }
1.139 raeburn 2778: $datatable .=
1.192 raeburn 2779: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2780: $choices{'anonsurvey_threshold'}.
1.139 raeburn 2781: '</span></td>'.
2782: '<td class="LC_right_item"><span class="LC_nobreak">'.
2783: '<input type="text" name="anonsurvey_threshold"'.
2784: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.198 raeburn 2785: '</td></tr>'."\n".
2786: '<tr><td><span class="LC_nobreak">'.
2787: $choices{'uploadquota'}.
2788: '</span></td>'.
2789: '<td align="right" class="LC_right_item">'.
2790: '<table><tr>';
2791: foreach my $type (@types) {
2792: $datatable .= '<td align="center">'.&mt($type).'<br />'.
2793: '<input type="text" name="uploadquota_'.$type.'"'.
2794: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
2795: }
2796: $datatable .= '</tr></table></td></tr>'."\n";
2797: $itemcount += 2;
1.192 raeburn 2798: my $onclick = 'toggleCredits(this.form);';
1.210 raeburn 2799: my $display = 'none';
1.192 raeburn 2800: if ($currusecredits) {
2801: $display = 'block';
2802: }
2803: my $additional = '<div id="credits" style="display: '.$display.'">'.
2804: '<span class="LC_nobreak">'.
2805: &mt('Default credits for official courses [_1]',
2806: '<input type="text" name="official_credits" value="'.
2807: $def_official_credits.'" size="3" />').
2808: '</span><br />'.
2809: '<span class="LC_nobreak">'.
2810: &mt('Default credits for unofficial courses [_1]',
2811: '<input type="text" name="unofficial_credits" value="'.
2812: $def_unofficial_credits.'" size="3" />').
1.216 raeburn 2813: '</span><br />'.
2814: '<span class="LC_nobreak">'.
2815: &mt('Default credits for textbook courses [_1]',
2816: '<input type="text" name="textbook_credits" value="'.
2817: $def_textbook_credits.'" size="3" />').
1.192 raeburn 2818: '</span></div>'."\n";
2819: %defaultchecked = ('coursecredits' => 'off');
2820: @toggles = ('coursecredits');
2821: my $current = {
2822: 'coursecredits' => $currusecredits,
2823: };
2824: (my $table,$itemcount) =
2825: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
2826: \%choices,$itemcount,$onclick,$additional);
2827: $datatable .= $table;
1.139 raeburn 2828: }
1.192 raeburn 2829: $$rowtotal += $itemcount;
1.121 raeburn 2830: return $datatable;
1.118 jms 2831: }
2832:
1.137 raeburn 2833: sub print_usersessions {
2834: my ($position,$dom,$settings,$rowtotal) = @_;
2835: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2836: my (%by_ip,%by_location,@intdoms);
2837: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 2838:
2839: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 2840: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 2841: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 2842: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 2843: my $itemcount = 1;
2844: if ($position eq 'top') {
1.152 raeburn 2845: if (keys(%serverhomes) > 1) {
1.145 raeburn 2846: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 2847: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 2848: } else {
1.140 raeburn 2849: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2850: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 2851: }
1.137 raeburn 2852: } else {
1.145 raeburn 2853: if (keys(%by_location) == 0) {
2854: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2855: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 2856: } else {
2857: my %lt = &usersession_titles();
2858: my $numinrow = 5;
2859: my $prefix;
2860: my @types;
2861: if ($position eq 'bottom') {
2862: $prefix = 'remote';
2863: @types = ('version','excludedomain','includedomain');
2864: } else {
2865: $prefix = 'hosted';
2866: @types = ('excludedomain','includedomain');
2867: }
2868: my (%current,%checkedon,%checkedoff);
2869: my @lcversions = &Apache::lonnet::all_loncaparevs();
2870: my @locations = sort(keys(%by_location));
2871: foreach my $type (@types) {
2872: $checkedon{$type} = '';
2873: $checkedoff{$type} = ' checked="checked"';
2874: }
2875: if (ref($settings) eq 'HASH') {
2876: if (ref($settings->{$prefix}) eq 'HASH') {
2877: foreach my $key (keys(%{$settings->{$prefix}})) {
2878: $current{$key} = $settings->{$prefix}{$key};
2879: if ($key eq 'version') {
2880: if ($current{$key} ne '') {
2881: $checkedon{$key} = ' checked="checked"';
2882: $checkedoff{$key} = '';
2883: }
2884: } elsif (ref($current{$key}) eq 'ARRAY') {
2885: $checkedon{$key} = ' checked="checked"';
2886: $checkedoff{$key} = '';
2887: }
1.137 raeburn 2888: }
2889: }
2890: }
1.145 raeburn 2891: foreach my $type (@types) {
2892: next if ($type ne 'version' && !@locations);
2893: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2894: $datatable .= '<tr'.$css_class.'>
2895: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2896: <span class="LC_nobreak">
2897: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2898: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2899: if ($type eq 'version') {
2900: my $selector = '<select name="'.$prefix.'_version">';
2901: foreach my $version (@lcversions) {
2902: my $selected = '';
2903: if ($current{'version'} eq $version) {
2904: $selected = ' selected="selected"';
2905: }
2906: $selector .= ' <option value="'.$version.'"'.
2907: $selected.'>'.$version.'</option>';
2908: }
2909: $selector .= '</select> ';
2910: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2911: } else {
2912: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2913: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2914: ' />'.(' 'x2).
2915: '<input type="button" value="'.&mt('uncheck all').'" '.
2916: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2917: "\n".
2918: '</div><div><table>';
2919: my $rem;
2920: for (my $i=0; $i<@locations; $i++) {
2921: my ($showloc,$value,$checkedtype);
2922: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2923: my $ip = $by_location{$locations[$i]}->[0];
2924: if (ref($by_ip{$ip}) eq 'ARRAY') {
2925: $value = join(':',@{$by_ip{$ip}});
2926: $showloc = join(', ',@{$by_ip{$ip}});
2927: if (ref($current{$type}) eq 'ARRAY') {
2928: foreach my $loc (@{$by_ip{$ip}}) {
2929: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2930: $checkedtype = ' checked="checked"';
2931: last;
2932: }
2933: }
1.138 raeburn 2934: }
2935: }
2936: }
1.145 raeburn 2937: $rem = $i%($numinrow);
2938: if ($rem == 0) {
2939: if ($i > 0) {
2940: $datatable .= '</tr>';
2941: }
2942: $datatable .= '<tr>';
2943: }
2944: $datatable .= '<td class="LC_left_item">'.
2945: '<span class="LC_nobreak"><label>'.
2946: '<input type="checkbox" name="'.$prefix.'_'.$type.
2947: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2948: '</label></span></td>';
1.137 raeburn 2949: }
1.145 raeburn 2950: $rem = @locations%($numinrow);
2951: my $colsleft = $numinrow - $rem;
2952: if ($colsleft > 1 ) {
2953: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2954: ' </td>';
2955: } elsif ($colsleft == 1) {
2956: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 2957: }
1.145 raeburn 2958: $datatable .= '</tr></table>';
1.137 raeburn 2959: }
1.145 raeburn 2960: $datatable .= '</td></tr>';
2961: $itemcount ++;
1.137 raeburn 2962: }
2963: }
2964: }
2965: $$rowtotal += $itemcount;
2966: return $datatable;
2967: }
2968:
1.138 raeburn 2969: sub build_location_hashes {
2970: my ($intdoms,$by_ip,$by_location) = @_;
2971: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2972: (ref($by_location) eq 'HASH'));
2973: my %iphost = &Apache::lonnet::get_iphost();
2974: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2975: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2976: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2977: foreach my $id (@{$iphost{$primary_ip}}) {
2978: my $intdom = &Apache::lonnet::internet_dom($id);
2979: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2980: push(@{$intdoms},$intdom);
2981: }
2982: }
2983: }
2984: foreach my $ip (keys(%iphost)) {
2985: if (ref($iphost{$ip}) eq 'ARRAY') {
2986: foreach my $id (@{$iphost{$ip}}) {
2987: my $location = &Apache::lonnet::internet_dom($id);
2988: if ($location) {
2989: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2990: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2991: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2992: push(@{$by_ip->{$ip}},$location);
2993: }
2994: } else {
2995: $by_ip->{$ip} = [$location];
2996: }
2997: }
2998: }
2999: }
3000: }
3001: foreach my $ip (sort(keys(%{$by_ip}))) {
3002: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3003: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
3004: my $first = $by_ip->{$ip}->[0];
3005: if (ref($by_location->{$first}) eq 'ARRAY') {
3006: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
3007: push(@{$by_location->{$first}},$ip);
3008: }
3009: } else {
3010: $by_location->{$first} = [$ip];
3011: }
3012: }
3013: }
3014: return;
3015: }
3016:
1.145 raeburn 3017: sub current_offloads_to {
3018: my ($dom,$settings,$servers) = @_;
3019: my (%spareid,%otherdomconfigs);
1.152 raeburn 3020: if (ref($servers) eq 'HASH') {
1.145 raeburn 3021: foreach my $lonhost (sort(keys(%{$servers}))) {
3022: my $gotspares;
1.152 raeburn 3023: if (ref($settings) eq 'HASH') {
3024: if (ref($settings->{'spares'}) eq 'HASH') {
3025: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
3026: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
3027: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
3028: $gotspares = 1;
3029: }
1.145 raeburn 3030: }
3031: }
3032: unless ($gotspares) {
3033: my $gotspares;
3034: my $serverhomeID =
3035: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
3036: my $serverhomedom =
3037: &Apache::lonnet::host_domain($serverhomeID);
3038: if ($serverhomedom ne $dom) {
3039: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
3040: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3041: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3042: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3043: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3044: $gotspares = 1;
3045: }
3046: }
3047: } else {
3048: $otherdomconfigs{$serverhomedom} =
3049: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
3050: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
3051: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3052: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3053: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
3054: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3055: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3056: $gotspares = 1;
3057: }
3058: }
3059: }
3060: }
3061: }
3062: }
3063: }
3064: unless ($gotspares) {
3065: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
3066: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3067: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3068: } else {
3069: my $server_hostname = &Apache::lonnet::hostname($lonhost);
3070: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
3071: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
3072: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3073: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3074: } else {
1.150 raeburn 3075: my %what = (
3076: spareid => 1,
3077: );
3078: my ($result,$returnhash) =
3079: &Apache::lonnet::get_remote_globals($lonhost,\%what);
3080: if ($result eq 'ok') {
3081: if (ref($returnhash) eq 'HASH') {
3082: if (ref($returnhash->{'spareid'}) eq 'HASH') {
3083: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
3084: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
3085: }
3086: }
1.145 raeburn 3087: }
3088: }
3089: }
3090: }
3091: }
3092: }
3093: return %spareid;
3094: }
3095:
3096: sub spares_row {
1.152 raeburn 3097: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 3098: my $css_class;
3099: my $numinrow = 4;
3100: my $itemcount = 1;
3101: my $datatable;
1.152 raeburn 3102: my %typetitles = &sparestype_titles();
3103: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 3104: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 3105: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
3106: my ($othercontrol,$serverdom);
3107: if ($serverhome ne $server) {
3108: $serverdom = &Apache::lonnet::host_domain($serverhome);
3109: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3110: } else {
3111: $serverdom = &Apache::lonnet::host_domain($server);
3112: if ($serverdom ne $dom) {
3113: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3114: }
3115: }
3116: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 3117: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3118: $datatable .= '<tr'.$css_class.'>
3119: <td rowspan="2">
1.183 bisitz 3120: <span class="LC_nobreak">'.
3121: &mt('[_1] when busy, offloads to:'
3122: ,'<b>'.$server.'</b>').
3123: "\n";
1.145 raeburn 3124: my (%current,%canselect);
1.152 raeburn 3125: my @choices =
3126: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
3127: foreach my $type ('primary','default') {
3128: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 3129: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
3130: my @spares = @{$spareid->{$server}{$type}};
3131: if (@spares > 0) {
1.152 raeburn 3132: if ($othercontrol) {
3133: $current{$type} = join(', ',@spares);
3134: } else {
3135: $current{$type} .= '<table>';
3136: my $numspares = scalar(@spares);
3137: for (my $i=0; $i<@spares; $i++) {
3138: my $rem = $i%($numinrow);
3139: if ($rem == 0) {
3140: if ($i > 0) {
3141: $current{$type} .= '</tr>';
3142: }
3143: $current{$type} .= '<tr>';
1.145 raeburn 3144: }
1.152 raeburn 3145: $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'".');" /> '.
3146: $spareid->{$server}{$type}[$i].
3147: '</label></td>'."\n";
3148: }
3149: my $rem = @spares%($numinrow);
3150: my $colsleft = $numinrow - $rem;
3151: if ($colsleft > 1 ) {
3152: $current{$type} .= '<td colspan="'.$colsleft.
3153: '" class="LC_left_item">'.
3154: ' </td>';
3155: } elsif ($colsleft == 1) {
3156: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 3157: }
1.152 raeburn 3158: $current{$type} .= '</tr></table>';
1.150 raeburn 3159: }
1.145 raeburn 3160: }
3161: }
3162: if ($current{$type} eq '') {
3163: $current{$type} = &mt('None specified');
3164: }
1.152 raeburn 3165: if ($othercontrol) {
3166: if ($type eq 'primary') {
3167: $canselect{$type} = $othercontrol;
3168: }
3169: } else {
3170: $canselect{$type} =
3171: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
3172: '<select name="newspare_'.$type.'_'.$server.'" '.
3173: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
3174: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
3175: if (@choices > 0) {
3176: foreach my $lonhost (@choices) {
3177: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
3178: }
3179: }
3180: $canselect{$type} .= '</select>'."\n";
3181: }
3182: } else {
3183: $current{$type} = &mt('Could not be determined');
3184: if ($type eq 'primary') {
3185: $canselect{$type} = $othercontrol;
3186: }
1.145 raeburn 3187: }
1.152 raeburn 3188: if ($type eq 'default') {
3189: $datatable .= '<tr'.$css_class.'>';
3190: }
3191: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
3192: '<td>'.$current{$type}.'</td>'."\n".
3193: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 3194: }
3195: $itemcount ++;
3196: }
3197: }
3198: $$rowtotal += $itemcount;
3199: return $datatable;
3200: }
3201:
1.152 raeburn 3202: sub possible_newspares {
3203: my ($server,$currspares,$serverhomes,$altids) = @_;
3204: my $serverhostname = &Apache::lonnet::hostname($server);
3205: my %excluded;
3206: if ($serverhostname ne '') {
3207: %excluded = (
3208: $serverhostname => 1,
3209: );
3210: }
3211: if (ref($currspares) eq 'HASH') {
3212: foreach my $type (keys(%{$currspares})) {
3213: if (ref($currspares->{$type}) eq 'ARRAY') {
3214: if (@{$currspares->{$type}} > 0) {
3215: foreach my $curr (@{$currspares->{$type}}) {
3216: my $hostname = &Apache::lonnet::hostname($curr);
3217: $excluded{$hostname} = 1;
3218: }
3219: }
3220: }
3221: }
3222: }
3223: my @choices;
3224: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
3225: if (keys(%{$serverhomes}) > 1) {
3226: foreach my $name (sort(keys(%{$serverhomes}))) {
3227: unless ($excluded{$name}) {
3228: if (exists($altids->{$serverhomes->{$name}})) {
3229: push(@choices,$altids->{$serverhomes->{$name}});
3230: } else {
3231: push(@choices,$serverhomes->{$name});
1.145 raeburn 3232: }
3233: }
3234: }
3235: }
3236: }
1.152 raeburn 3237: return sort(@choices);
1.145 raeburn 3238: }
3239:
1.150 raeburn 3240: sub print_loadbalancing {
3241: my ($dom,$settings,$rowtotal) = @_;
3242: my $primary_id = &Apache::lonnet::domain($dom,'primary');
3243: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3244: my $numinrow = 1;
3245: my $datatable;
3246: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 3247: my (%currbalancer,%currtargets,%currrules,%existing);
3248: if (ref($settings) eq 'HASH') {
3249: %existing = %{$settings};
3250: }
3251: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
3252: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
3253: \%currtargets,\%currrules);
1.150 raeburn 3254: } else {
3255: return;
3256: }
3257: my ($othertitle,$usertypes,$types) =
3258: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 3259: my $rownum = 8;
1.150 raeburn 3260: if (ref($types) eq 'ARRAY') {
3261: $rownum += scalar(@{$types});
3262: }
1.171 raeburn 3263: my @css_class = ('LC_odd_row','LC_even_row');
3264: my $balnum = 0;
3265: my $islast;
3266: my (@toshow,$disabledtext);
3267: if (keys(%currbalancer) > 0) {
3268: @toshow = sort(keys(%currbalancer));
3269: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
3270: push(@toshow,'');
3271: }
3272: } else {
3273: @toshow = ('');
3274: $disabledtext = &mt('No existing load balancer');
3275: }
3276: foreach my $lonhost (@toshow) {
3277: if ($balnum == scalar(@toshow)-1) {
3278: $islast = 1;
3279: } else {
3280: $islast = 0;
3281: }
3282: my $cssidx = $balnum%2;
3283: my $targets_div_style = 'display: none';
3284: my $disabled_div_style = 'display: block';
3285: my $homedom_div_style = 'display: none';
3286: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3287: '<td rowspan="'.$rownum.'" valign="top">'.
3288: '<p>';
3289: if ($lonhost eq '') {
1.210 raeburn 3290: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 3291: if (keys(%currbalancer) > 0) {
3292: $datatable .= &mt('Add balancer:');
3293: } else {
3294: $datatable .= &mt('Enable balancer:');
3295: }
3296: $datatable .= ' '.
3297: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3298: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3299: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3300: '<option value="" selected="selected">'.&mt('None').
3301: '</option>'."\n";
3302: foreach my $server (sort(keys(%servers))) {
3303: next if ($currbalancer{$server});
3304: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3305: }
1.210 raeburn 3306: $datatable .=
1.171 raeburn 3307: '</select>'."\n".
3308: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3309: } else {
3310: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3311: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3312: &mt('Stop balancing').'</label>'.
3313: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3314: $targets_div_style = 'display: block';
3315: $disabled_div_style = 'display: none';
3316: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3317: $homedom_div_style = 'display: block';
3318: }
3319: }
3320: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3321: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3322: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3323: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3324: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3325: my @sparestypes = ('primary','default');
3326: my %typetitles = &sparestype_titles();
3327: foreach my $sparetype (@sparestypes) {
3328: my $targettable;
3329: for (my $i=0; $i<$numspares; $i++) {
3330: my $checked;
3331: if (ref($currtargets{$lonhost}) eq 'HASH') {
3332: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3333: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3334: $checked = ' checked="checked"';
3335: }
3336: }
3337: }
3338: my ($chkboxval,$disabled);
3339: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3340: $chkboxval = $spares[$i];
3341: }
3342: if (exists($currbalancer{$spares[$i]})) {
3343: $disabled = ' disabled="disabled"';
3344: }
1.210 raeburn 3345: $targettable .=
1.171 raeburn 3346: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3347: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3348: '</span></label></td>';
3349: my $rem = $i%($numinrow);
3350: if ($rem == 0) {
3351: if (($i > 0) && ($i < $numspares-1)) {
3352: $targettable .= '</tr>';
3353: }
3354: if ($i < $numspares-1) {
3355: $targettable .= '<tr>';
1.150 raeburn 3356: }
3357: }
3358: }
1.171 raeburn 3359: if ($targettable ne '') {
3360: my $rem = $numspares%($numinrow);
3361: my $colsleft = $numinrow - $rem;
3362: if ($colsleft > 1 ) {
3363: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3364: ' </td>';
3365: } elsif ($colsleft == 1) {
3366: $targettable .= '<td class="LC_left_item"> </td>';
3367: }
3368: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3369: '<table><tr>'.$targettable.'</tr></table><br />';
3370: }
3371: }
3372: $datatable .= '</div></td></tr>'.
3373: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3374: $othertitle,$usertypes,$types,\%servers,
3375: \%currbalancer,$lonhost,
3376: $targets_div_style,$homedom_div_style,
3377: $css_class[$cssidx],$balnum,$islast);
3378: $$rowtotal += $rownum;
3379: $balnum ++;
3380: }
3381: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3382: return $datatable;
3383: }
3384:
3385: sub get_loadbalancers_config {
3386: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3387: return unless ((ref($servers) eq 'HASH') &&
3388: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3389: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3390: if (keys(%{$existing}) > 0) {
3391: my $oldlonhost;
3392: foreach my $key (sort(keys(%{$existing}))) {
3393: if ($key eq 'lonhost') {
3394: $oldlonhost = $existing->{'lonhost'};
3395: $currbalancer->{$oldlonhost} = 1;
3396: } elsif ($key eq 'targets') {
3397: if ($oldlonhost) {
3398: $currtargets->{$oldlonhost} = $existing->{'targets'};
3399: }
3400: } elsif ($key eq 'rules') {
3401: if ($oldlonhost) {
3402: $currrules->{$oldlonhost} = $existing->{'rules'};
3403: }
3404: } elsif (ref($existing->{$key}) eq 'HASH') {
3405: $currbalancer->{$key} = 1;
3406: $currtargets->{$key} = $existing->{$key}{'targets'};
3407: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3408: }
3409: }
1.171 raeburn 3410: } else {
3411: my ($balancerref,$targetsref) =
3412: &Apache::lonnet::get_lonbalancer_config($servers);
3413: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3414: foreach my $server (sort(keys(%{$balancerref}))) {
3415: $currbalancer->{$server} = 1;
3416: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3417: }
3418: }
3419: }
1.171 raeburn 3420: return;
1.150 raeburn 3421: }
3422:
3423: sub loadbalancing_rules {
3424: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 3425: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3426: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3427: my $output;
1.171 raeburn 3428: my $num = 0;
1.210 raeburn 3429: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3430: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3431: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3432: foreach my $type (@{$alltypes}) {
1.171 raeburn 3433: $num ++;
1.150 raeburn 3434: my $current;
3435: if (ref($currrules) eq 'HASH') {
3436: $current = $currrules->{$type};
3437: }
1.209 raeburn 3438: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.171 raeburn 3439: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3440: $current = '';
3441: }
3442: }
3443: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 3444: $servers,$currbalancer,$lonhost,$dom,
3445: $targets_div_style,$homedom_div_style,
3446: $css_class,$balnum,$num,$islast);
1.150 raeburn 3447: }
3448: }
3449: return $output;
3450: }
3451:
3452: sub loadbalancing_titles {
3453: my ($dom,$intdom,$usertypes,$types) = @_;
3454: my %othertypes = (
3455: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3456: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3457: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3458: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 3459: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
3460: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 3461: );
1.209 raeburn 3462: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 3463: if (ref($types) eq 'ARRAY') {
3464: unshift(@alltypes,@{$types},'default');
3465: }
3466: my %titles;
3467: foreach my $type (@alltypes) {
3468: if ($type =~ /^_LC_/) {
3469: $titles{$type} = $othertypes{$type};
3470: } elsif ($type eq 'default') {
3471: $titles{$type} = &mt('All users from [_1]',$dom);
3472: if (ref($types) eq 'ARRAY') {
3473: if (@{$types} > 0) {
3474: $titles{$type} = &mt('Other users from [_1]',$dom);
3475: }
3476: }
3477: } elsif (ref($usertypes) eq 'HASH') {
3478: $titles{$type} = $usertypes->{$type};
3479: }
3480: }
3481: return (\@alltypes,\%othertypes,\%titles);
3482: }
3483:
3484: sub loadbalance_rule_row {
1.171 raeburn 3485: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3486: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 3487: my @rulenames;
1.150 raeburn 3488: my %ruletitles = &offloadtype_text();
1.209 raeburn 3489: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
3490: @rulenames = ('balancer','offloadedto');
1.150 raeburn 3491: } else {
1.209 raeburn 3492: @rulenames = ('default','homeserver');
3493: if ($type eq '_LC_external') {
3494: push(@rulenames,'externalbalancer');
3495: } else {
3496: push(@rulenames,'specific');
3497: }
3498: push(@rulenames,'none');
1.150 raeburn 3499: }
3500: my $style = $targets_div_style;
1.209 raeburn 3501: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.150 raeburn 3502: $style = $homedom_div_style;
3503: }
1.171 raeburn 3504: my $space;
3505: if ($islast && $num == 1) {
3506: $space = '<div display="inline-block"> </div>';
3507: }
1.210 raeburn 3508: my $output =
1.171 raeburn 3509: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3510: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3511: '<td valaign="top">'.$space.
3512: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3513: for (my $i=0; $i<@rulenames; $i++) {
3514: my $rule = $rulenames[$i];
3515: my ($checked,$extra);
3516: if ($rulenames[$i] eq 'default') {
3517: $rule = '';
3518: }
3519: if ($rulenames[$i] eq 'specific') {
3520: if (ref($servers) eq 'HASH') {
3521: my $default;
3522: if (($current ne '') && (exists($servers->{$current}))) {
3523: $checked = ' checked="checked"';
3524: }
3525: unless ($checked) {
3526: $default = ' selected="selected"';
3527: }
1.210 raeburn 3528: $extra =
1.171 raeburn 3529: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3530: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3531: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3532: '<option value=""'.$default.'></option>'."\n";
3533: foreach my $server (sort(keys(%{$servers}))) {
3534: if (ref($currbalancer) eq 'HASH') {
3535: next if (exists($currbalancer->{$server}));
3536: }
1.150 raeburn 3537: my $selected;
1.171 raeburn 3538: if ($server eq $current) {
1.150 raeburn 3539: $selected = ' selected="selected"';
3540: }
1.171 raeburn 3541: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3542: }
3543: $extra .= '</select>';
3544: }
3545: } elsif ($rule eq $current) {
3546: $checked = ' checked="checked"';
3547: }
3548: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 3549: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3550: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3551: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3552: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3553: '</label>'.$extra.'</span><br />'."\n";
3554: }
3555: $output .= '</div></td></tr>'."\n";
3556: return $output;
3557: }
3558:
3559: sub offloadtype_text {
3560: my %ruletitles = &Apache::lonlocal::texthash (
3561: 'default' => 'Offloads to default destinations',
3562: 'homeserver' => "Offloads to user's home server",
3563: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3564: 'specific' => 'Offloads to specific server',
1.161 raeburn 3565: 'none' => 'No offload',
1.209 raeburn 3566: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
3567: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.150 raeburn 3568: );
3569: return %ruletitles;
3570: }
3571:
3572: sub sparestype_titles {
3573: my %typestitles = &Apache::lonlocal::texthash (
3574: 'primary' => 'primary',
3575: 'default' => 'default',
3576: );
3577: return %typestitles;
3578: }
3579:
1.28 raeburn 3580: sub contact_titles {
3581: my %titles = &Apache::lonlocal::texthash (
3582: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3583: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3584: 'errormail' => 'Error reports to be e-mailed to',
3585: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3586: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3587: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3588: 'requestsmail' => 'E-mail from course requests requiring approval',
1.190 raeburn 3589: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 3590: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 3591: );
3592: my %short_titles = &Apache::lonlocal::texthash (
3593: adminemail => 'Admin E-mail address',
3594: supportemail => 'Support E-mail',
3595: );
3596: return (\%titles,\%short_titles);
3597: }
3598:
1.72 raeburn 3599: sub tool_titles {
3600: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 3601: aboutme => 'Personal web page',
1.86 raeburn 3602: blog => 'Blog',
1.162 raeburn 3603: webdav => 'WebDAV',
1.86 raeburn 3604: portfolio => 'Portfolio',
1.88 bisitz 3605: official => 'Official courses (with institutional codes)',
3606: unofficial => 'Unofficial courses',
1.98 raeburn 3607: community => 'Communities',
1.216 raeburn 3608: textbook => 'Textbook courses',
1.86 raeburn 3609: );
1.72 raeburn 3610: return %titles;
3611: }
3612:
1.101 raeburn 3613: sub courserequest_titles {
3614: my %titles = &Apache::lonlocal::texthash (
3615: official => 'Official',
3616: unofficial => 'Unofficial',
3617: community => 'Communities',
1.216 raeburn 3618: textbook => 'Textbook',
1.101 raeburn 3619: norequest => 'Not allowed',
1.104 raeburn 3620: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3621: validate => 'With validation',
3622: autolimit => 'Numerical limit',
1.103 raeburn 3623: unlimited => '(blank for unlimited)',
1.101 raeburn 3624: );
3625: return %titles;
3626: }
3627:
1.163 raeburn 3628: sub authorrequest_titles {
3629: my %titles = &Apache::lonlocal::texthash (
3630: norequest => 'Not allowed',
3631: approval => 'Approval by Dom. Coord.',
3632: automatic => 'Automatic approval',
3633: );
3634: return %titles;
1.210 raeburn 3635: }
1.163 raeburn 3636:
1.101 raeburn 3637: sub courserequest_conditions {
3638: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3639: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 3640: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 3641: );
3642: return %conditions;
3643: }
3644:
3645:
1.27 raeburn 3646: sub print_usercreation {
1.30 raeburn 3647: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3648: my $numinrow = 4;
1.28 raeburn 3649: my $datatable;
3650: if ($position eq 'top') {
1.30 raeburn 3651: $$rowtotal ++;
1.34 raeburn 3652: my $rowcount = 0;
1.32 raeburn 3653: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3654: if (ref($rules) eq 'HASH') {
3655: if (keys(%{$rules}) > 0) {
1.32 raeburn 3656: $datatable .= &user_formats_row('username',$settings,$rules,
3657: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3658: $$rowtotal ++;
1.32 raeburn 3659: $rowcount ++;
3660: }
3661: }
3662: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3663: if (ref($idrules) eq 'HASH') {
3664: if (keys(%{$idrules}) > 0) {
3665: $datatable .= &user_formats_row('id',$settings,$idrules,
3666: $idruleorder,$numinrow,$rowcount);
3667: $$rowtotal ++;
3668: $rowcount ++;
1.28 raeburn 3669: }
3670: }
1.39 raeburn 3671: if ($rowcount == 0) {
3672: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3673: $$rowtotal ++;
3674: $rowcount ++;
3675: }
1.34 raeburn 3676: } elsif ($position eq 'middle') {
1.224 ! raeburn 3677: my @creators = ('author','course','requestcrs');
1.37 raeburn 3678: my ($rules,$ruleorder) =
3679: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3680: my %lt = &usercreation_types();
3681: my %checked;
3682: if (ref($settings) eq 'HASH') {
3683: if (ref($settings->{'cancreate'}) eq 'HASH') {
3684: foreach my $item (@creators) {
3685: $checked{$item} = $settings->{'cancreate'}{$item};
3686: }
3687: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3688: foreach my $item (@creators) {
3689: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3690: $checked{$item} = 'none';
3691: }
3692: }
3693: }
3694: }
3695: my $rownum = 0;
3696: foreach my $item (@creators) {
3697: $rownum ++;
1.224 ! raeburn 3698: if ($checked{$item} eq '') {
! 3699: $checked{$item} = 'any';
1.34 raeburn 3700: }
3701: my $css_class;
3702: if ($rownum%2) {
3703: $css_class = '';
3704: } else {
3705: $css_class = ' class="LC_odd_row" ';
3706: }
3707: $datatable .= '<tr'.$css_class.'>'.
3708: '<td><span class="LC_nobreak">'.$lt{$item}.
3709: '</span></td><td align="right">';
1.224 ! raeburn 3710: my @options = ('any');
! 3711: if (ref($rules) eq 'HASH') {
! 3712: if (keys(%{$rules}) > 0) {
! 3713: push(@options,('official','unofficial'));
1.37 raeburn 3714: }
3715: }
1.224 ! raeburn 3716: push(@options,'none');
1.37 raeburn 3717: foreach my $option (@options) {
1.50 raeburn 3718: my $type = 'radio';
1.34 raeburn 3719: my $check = ' ';
1.224 ! raeburn 3720: if ($checked{$item} eq $option) {
! 3721: $check = ' checked="checked" ';
1.34 raeburn 3722: }
3723: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3724: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3725: $item.'" value="'.$option.'"'.$check.'/> '.
3726: $lt{$option}.'</label> </span>';
3727: }
3728: $datatable .= '</td></tr>';
3729: }
1.28 raeburn 3730: } else {
3731: my @contexts = ('author','course','domain');
3732: my @authtypes = ('int','krb4','krb5','loc');
3733: my %checked;
3734: if (ref($settings) eq 'HASH') {
3735: if (ref($settings->{'authtypes'}) eq 'HASH') {
3736: foreach my $item (@contexts) {
3737: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3738: foreach my $auth (@authtypes) {
3739: if ($settings->{'authtypes'}{$item}{$auth}) {
3740: $checked{$item}{$auth} = ' checked="checked" ';
3741: }
3742: }
3743: }
3744: }
1.27 raeburn 3745: }
1.35 raeburn 3746: } else {
3747: foreach my $item (@contexts) {
1.36 raeburn 3748: foreach my $auth (@authtypes) {
1.35 raeburn 3749: $checked{$item}{$auth} = ' checked="checked" ';
3750: }
3751: }
1.27 raeburn 3752: }
1.28 raeburn 3753: my %title = &context_names();
3754: my %authname = &authtype_names();
3755: my $rownum = 0;
3756: my $css_class;
3757: foreach my $item (@contexts) {
3758: if ($rownum%2) {
3759: $css_class = '';
3760: } else {
3761: $css_class = ' class="LC_odd_row" ';
3762: }
1.30 raeburn 3763: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3764: '<td>'.$title{$item}.
3765: '</td><td class="LC_left_item">'.
3766: '<span class="LC_nobreak">';
3767: foreach my $auth (@authtypes) {
3768: $datatable .= '<label>'.
3769: '<input type="checkbox" name="'.$item.'_auth" '.
3770: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3771: $authname{$auth}.'</label> ';
3772: }
3773: $datatable .= '</span></td></tr>';
3774: $rownum ++;
1.27 raeburn 3775: }
1.30 raeburn 3776: $$rowtotal += $rownum;
1.27 raeburn 3777: }
3778: return $datatable;
3779: }
3780:
1.224 ! raeburn 3781: sub print_selfcreation {
! 3782: my ($position,$dom,$settings,$rowtotal) = @_;
! 3783: my (@selfcreate,$createsettings,$datatable);
! 3784: if (ref($settings) eq 'HASH') {
! 3785: if (ref($settings->{'cancreate'}) eq 'HASH') {
! 3786: $createsettings = $settings->{'cancreate'};
! 3787: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
! 3788: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
! 3789: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
! 3790: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
! 3791: @selfcreate = ('email','login','sso');
! 3792: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
! 3793: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
! 3794: }
! 3795: }
! 3796: }
! 3797: }
! 3798: my %radiohash;
! 3799: my $rownum = 0;
! 3800: my $numinrow = 4;
! 3801: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
! 3802: if ($position eq 'top') {
! 3803: my %choices = &Apache::lonlocal::texthash (
! 3804: cancreate_login => 'Institutional Login',
! 3805: cancreate_sso => 'Institutional Single Sign On',
! 3806: );
! 3807: my @toggles = sort(keys(%choices));
! 3808: my %defaultchecked = (
! 3809: 'cancreate_login' => 'off',
! 3810: 'cancreate_sso' => 'off',
! 3811: );
! 3812: my $itemcount = 1;
! 3813: my $onclick;
! 3814: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
! 3815: \%choices,$itemcount,$onclick);
! 3816: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
! 3817:
! 3818: if (ref($usertypes) eq 'HASH') {
! 3819: if (keys(%{$usertypes}) > 0) {
! 3820: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
! 3821: $dom,$numinrow,$othertitle,
! 3822: 'statustocreate',$rownum);
! 3823: $rownum ++;
! 3824: $$rowtotal ++;
! 3825: }
! 3826: }
! 3827: } elsif ($position eq 'middle') {
! 3828: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
! 3829: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
! 3830: $usertypes->{'default'} = $othertitle;
! 3831: if (ref($types) eq 'ARRAY') {
! 3832: push(@{$types},'default');
! 3833: $usertypes->{'default'} = $othertitle;
! 3834: foreach my $status (@{$types}) {
! 3835: $rownum ++;
! 3836: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
! 3837: $numinrow,$rownum,$usertypes);
! 3838: $$rowtotal ++;
! 3839: }
! 3840: }
! 3841: } else {
! 3842: my $css_class = $rownum%2?' class="LC_odd_row"':'';
! 3843: my %choices =
! 3844: &Apache::lonlocal::texthash(
! 3845: email => 'Approved automatically',
! 3846: emailapproval => 'Queued for approval by DC',
! 3847: off => 'Not enabled',
! 3848: );
! 3849: $datatable .= '<tr'.$css_class.'>'.
! 3850: '<td>'.&mt('E-mail address as username').
! 3851: '</td><td class="LC_left_item">'.
! 3852: '<span class="LC_nobreak">';
! 3853: foreach my $option ('email','emailapproval','off') {
! 3854: my $checked;
! 3855: if ($option eq 'email') {
! 3856: if ($radiohash{'cancreate_email'}) {
! 3857: $checked = 'checked="checked"';
! 3858: }
! 3859: } elsif ($option eq 'emailapproval') {
! 3860: if ($radiohash{'cancreate_emailapproval'}) {
! 3861: $checked = 'checked="checked"';
! 3862: }
! 3863: } else {
! 3864: if ((!$radiohash{'cancreate_email'}) && (!$radiohash{'cancreate_emailapproval'})) {
! 3865: $checked = 'checked="checked"';
! 3866: }
! 3867: }
! 3868: $datatable .= '<label>'.
! 3869: '<input type="radio" name="cancreate_email" '.
! 3870: $checked.' value="'.$option.'" />'.
! 3871: $choices{$option}.'</label> ';
! 3872: }
! 3873: $$rowtotal ++;
! 3874: $rownum ++;
! 3875: $datatable .= '</span></td></tr>'.
! 3876: &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
! 3877: $rownum ++;
! 3878: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
! 3879: $numinrow = 2;
! 3880: $datatable .= &modifiable_userdata_row('cancreate','emailusername',$settings,
! 3881: $numinrow,$rownum,undef,$infofields,$infotitles);
! 3882: $$rowtotal ++;
! 3883: $rownum ++;
! 3884: my ($emailrules,$emailruleorder) =
! 3885: &Apache::lonnet::inst_userrules($dom,'email');
! 3886: if (ref($emailrules) eq 'HASH') {
! 3887: if (keys(%{$emailrules}) > 0) {
! 3888: $datatable .= &user_formats_row('email',$settings,$emailrules,
! 3889: $emailruleorder,$numinrow,$rownum);
! 3890: $rownum ++;
! 3891: $$rowtotal ++;
! 3892: }
! 3893: }
! 3894: $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
! 3895: }
! 3896: return $datatable;
! 3897: }
! 3898:
1.165 raeburn 3899: sub captcha_choice {
1.169 raeburn 3900: my ($context,$settings,$itemcount) = @_;
1.165 raeburn 3901: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
3902: my %lt = &captcha_phrases();
3903: $keyentry = 'hidden';
3904: if ($context eq 'cancreate') {
1.224 ! raeburn 3905: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 3906: } elsif ($context eq 'login') {
3907: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 3908: }
3909: if (ref($settings) eq 'HASH') {
3910: if ($settings->{'captcha'}) {
3911: $checked{$settings->{'captcha'}} = ' checked="checked"';
3912: } else {
3913: $checked{'original'} = ' checked="checked"';
3914: }
3915: if ($settings->{'captcha'} eq 'recaptcha') {
3916: $pubtext = $lt{'pub'};
3917: $privtext = $lt{'priv'};
3918: $keyentry = 'text';
3919: }
3920: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
3921: $currpub = $settings->{'recaptchakeys'}{'public'};
3922: $currpriv = $settings->{'recaptchakeys'}{'private'};
3923: }
3924: } else {
3925: $checked{'original'} = ' checked="checked"';
3926: }
1.169 raeburn 3927: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3928: my $output = '<tr'.$css_class.'>'.
3929: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 3930: '<table><tr><td>'."\n";
3931: foreach my $option ('original','recaptcha','notused') {
3932: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
3933: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
3934: $lt{$option}.'</label></span>';
3935: unless ($option eq 'notused') {
3936: $output .= (' 'x2)."\n";
3937: }
3938: }
3939: #
3940: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
3941: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 3942: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 3943: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 3944: #
1.165 raeburn 3945: $output .= '</td></tr>'."\n".
3946: '<tr><td>'."\n".
3947: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
3948: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
3949: $currpub.'" size="40" /></span><br />'."\n".
3950: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
3951: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
3952: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
3953: '</td></tr>';
3954: return $output;
3955: }
3956:
1.32 raeburn 3957: sub user_formats_row {
3958: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3959: my $output;
3960: my %text = (
3961: 'username' => 'new usernames',
3962: 'id' => 'IDs',
1.45 raeburn 3963: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3964: );
3965: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3966: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3967: '<td><span class="LC_nobreak">';
3968: if ($type eq 'email') {
3969: $output .= &mt("Formats disallowed for $text{$type}: ");
3970: } else {
3971: $output .= &mt("Format rules to check for $text{$type}: ");
3972: }
3973: $output .= '</span></td>'.
3974: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3975: my $rem;
3976: if (ref($ruleorder) eq 'ARRAY') {
3977: for (my $i=0; $i<@{$ruleorder}; $i++) {
3978: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3979: my $rem = $i%($numinrow);
3980: if ($rem == 0) {
3981: if ($i > 0) {
3982: $output .= '</tr>';
3983: }
3984: $output .= '<tr>';
3985: }
3986: my $check = ' ';
1.39 raeburn 3987: if (ref($settings) eq 'HASH') {
3988: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3989: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3990: $check = ' checked="checked" ';
3991: }
1.27 raeburn 3992: }
3993: }
3994: $output .= '<td class="LC_left_item">'.
3995: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3996: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 3997: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3998: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3999: }
4000: }
4001: $rem = @{$ruleorder}%($numinrow);
4002: }
4003: my $colsleft = $numinrow - $rem;
4004: if ($colsleft > 1 ) {
4005: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4006: ' </td>';
4007: } elsif ($colsleft == 1) {
4008: $output .= '<td class="LC_left_item"> </td>';
4009: }
4010: $output .= '</tr></table></td></tr>';
4011: return $output;
4012: }
4013:
1.34 raeburn 4014: sub usercreation_types {
4015: my %lt = &Apache::lonlocal::texthash (
4016: author => 'When adding a co-author',
4017: course => 'When adding a user to a course',
1.100 raeburn 4018: requestcrs => 'When requesting a course',
1.34 raeburn 4019: any => 'Any',
4020: official => 'Institutional only ',
4021: unofficial => 'Non-institutional only',
4022: none => 'None',
4023: );
4024: return %lt;
1.48 raeburn 4025: }
1.34 raeburn 4026:
1.224 ! raeburn 4027: sub selfcreation_types {
! 4028: my %lt = &Apache::lonlocal::texthash (
! 4029: selfcreate => 'User creates own account',
! 4030: any => 'Any',
! 4031: official => 'Institutional only ',
! 4032: unofficial => 'Non-institutional only',
! 4033: email => 'E-mail address',
! 4034: login => 'Institutional Login',
! 4035: sso => 'SSO',
! 4036: );
! 4037: }
! 4038:
1.28 raeburn 4039: sub authtype_names {
4040: my %lt = &Apache::lonlocal::texthash(
4041: int => 'Internal',
4042: krb4 => 'Kerberos 4',
4043: krb5 => 'Kerberos 5',
4044: loc => 'Local',
4045: );
4046: return %lt;
4047: }
4048:
4049: sub context_names {
4050: my %context_title = &Apache::lonlocal::texthash(
4051: author => 'Creating users when an Author',
4052: course => 'Creating users when in a course',
4053: domain => 'Creating users when a Domain Coordinator',
4054: );
4055: return %context_title;
4056: }
4057:
1.33 raeburn 4058: sub print_usermodification {
4059: my ($position,$dom,$settings,$rowtotal) = @_;
4060: my $numinrow = 4;
4061: my ($context,$datatable,$rowcount);
4062: if ($position eq 'top') {
4063: $rowcount = 0;
4064: $context = 'author';
4065: foreach my $role ('ca','aa') {
4066: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4067: $numinrow,$rowcount);
4068: $$rowtotal ++;
4069: $rowcount ++;
4070: }
1.63 raeburn 4071: } elsif ($position eq 'middle') {
1.33 raeburn 4072: $context = 'course';
4073: $rowcount = 0;
4074: foreach my $role ('st','ep','ta','in','cr') {
4075: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4076: $numinrow,$rowcount);
4077: $$rowtotal ++;
4078: $rowcount ++;
4079: }
4080: }
4081: return $datatable;
4082: }
4083:
1.43 raeburn 4084: sub print_defaults {
1.212 raeburn 4085: my ($dom,$settings,$rowtotal) = @_;
1.68 raeburn 4086: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 4087: 'datelocale_def','portal_def');
1.212 raeburn 4088: my %defaults;
4089: if (ref($settings) eq 'HASH') {
1.213 raeburn 4090: %defaults = %{$settings};
1.212 raeburn 4091: } else {
4092: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
4093: foreach my $item (@items) {
4094: $defaults{$item} = $domdefaults{$item};
4095: }
4096: }
1.141 raeburn 4097: my $titles = &defaults_titles($dom);
1.43 raeburn 4098: my $rownum = 0;
4099: my ($datatable,$css_class);
4100: foreach my $item (@items) {
4101: if ($rownum%2) {
4102: $css_class = '';
4103: } else {
4104: $css_class = ' class="LC_odd_row" ';
4105: }
4106: $datatable .= '<tr'.$css_class.'>'.
4107: '<td><span class="LC_nobreak">'.$titles->{$item}.
4108: '</span></td><td class="LC_right_item">';
4109: if ($item eq 'auth_def') {
4110: my @authtypes = ('internal','krb4','krb5','localauth');
4111: my %shortauth = (
4112: internal => 'int',
4113: krb4 => 'krb4',
4114: krb5 => 'krb5',
4115: localauth => 'loc'
4116: );
4117: my %authnames = &authtype_names();
4118: foreach my $auth (@authtypes) {
4119: my $checked = ' ';
1.212 raeburn 4120: if ($defaults{$item} eq $auth) {
1.43 raeburn 4121: $checked = ' checked="checked" ';
4122: }
4123: $datatable .= '<label><input type="radio" name="'.$item.
4124: '" value="'.$auth.'"'.$checked.'/>'.
4125: $authnames{$shortauth{$auth}}.'</label> ';
4126: }
1.54 raeburn 4127: } elsif ($item eq 'timezone_def') {
4128: my $includeempty = 1;
1.212 raeburn 4129: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
1.68 raeburn 4130: } elsif ($item eq 'datelocale_def') {
4131: my $includeempty = 1;
1.212 raeburn 4132: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
1.167 raeburn 4133: } elsif ($item eq 'lang_def') {
1.168 raeburn 4134: my %langchoices = &get_languages_hash();
4135: $langchoices{''} = 'No language preference';
1.167 raeburn 4136: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.212 raeburn 4137: $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,
1.167 raeburn 4138: \%langchoices);
1.43 raeburn 4139: } else {
1.141 raeburn 4140: my $size;
4141: if ($item eq 'portal_def') {
4142: $size = ' size="25"';
4143: }
1.43 raeburn 4144: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.212 raeburn 4145: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 4146: }
4147: $datatable .= '</td></tr>';
4148: $rownum ++;
4149: }
4150: $$rowtotal += $rownum;
4151: return $datatable;
4152: }
4153:
1.168 raeburn 4154: sub get_languages_hash {
4155: my %langchoices;
4156: foreach my $id (&Apache::loncommon::languageids()) {
4157: my $code = &Apache::loncommon::supportedlanguagecode($id);
4158: if ($code ne '') {
4159: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
4160: }
4161: }
4162: return %langchoices;
4163: }
4164:
1.43 raeburn 4165: sub defaults_titles {
1.141 raeburn 4166: my ($dom) = @_;
1.43 raeburn 4167: my %titles = &Apache::lonlocal::texthash (
4168: 'auth_def' => 'Default authentication type',
4169: 'auth_arg_def' => 'Default authentication argument',
4170: 'lang_def' => 'Default language',
1.54 raeburn 4171: 'timezone_def' => 'Default timezone',
1.68 raeburn 4172: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 4173: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 4174: );
1.141 raeburn 4175: if ($dom) {
4176: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
4177: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
4178: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
4179: $protocol = 'http' if ($protocol ne 'https');
4180: if ($uint_dom) {
4181: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
4182: $uint_dom);
4183: }
4184: }
1.43 raeburn 4185: return (\%titles);
4186: }
4187:
1.46 raeburn 4188: sub print_scantronformat {
4189: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
4190: my $itemcount = 1;
1.60 raeburn 4191: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
4192: %confhash);
1.46 raeburn 4193: my $switchserver = &check_switchserver($dom,$confname);
4194: my %lt = &Apache::lonlocal::texthash (
1.95 www 4195: default => 'Default bubblesheet format file error',
4196: custom => 'Custom bubblesheet format file error',
1.46 raeburn 4197: );
4198: my %scantronfiles = (
4199: default => 'default.tab',
4200: custom => 'custom.tab',
4201: );
4202: foreach my $key (keys(%scantronfiles)) {
4203: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
4204: .$scantronfiles{$key};
4205: }
4206: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
4207: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
4208: if (!$switchserver) {
4209: my $servadm = $r->dir_config('lonAdmEMail');
4210: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
4211: if ($configuserok eq 'ok') {
4212: if ($author_ok eq 'ok') {
4213: my %legacyfile = (
4214: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
4215: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
4216: );
4217: my %md5chk;
4218: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4219: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
4220: chomp($md5chk{$type});
1.46 raeburn 4221: }
4222: if ($md5chk{'default'} ne $md5chk{'custom'}) {
4223: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4224: ($scantronurls{$type},my $error) =
1.46 raeburn 4225: &legacy_scantronformat($r,$dom,$confname,
4226: $type,$legacyfile{$type},
4227: $scantronurls{$type},
4228: $scantronfiles{$type});
1.60 raeburn 4229: if ($error ne '') {
4230: $error{$type} = $error;
4231: }
4232: }
4233: if (keys(%error) == 0) {
4234: $is_custom = 1;
4235: $confhash{'scantron'}{'scantronformat'} =
4236: $scantronurls{'custom'};
4237: my $putresult =
4238: &Apache::lonnet::put_dom('configuration',
4239: \%confhash,$dom);
4240: if ($putresult ne 'ok') {
4241: $error{'custom'} =
4242: '<span class="LC_error">'.
4243: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4244: }
1.46 raeburn 4245: }
4246: } else {
1.60 raeburn 4247: ($scantronurls{'default'},my $error) =
1.46 raeburn 4248: &legacy_scantronformat($r,$dom,$confname,
4249: 'default',$legacyfile{'default'},
4250: $scantronurls{'default'},
4251: $scantronfiles{'default'});
1.60 raeburn 4252: if ($error eq '') {
4253: $confhash{'scantron'}{'scantronformat'} = '';
4254: my $putresult =
4255: &Apache::lonnet::put_dom('configuration',
4256: \%confhash,$dom);
4257: if ($putresult ne 'ok') {
4258: $error{'default'} =
4259: '<span class="LC_error">'.
4260: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4261: }
4262: } else {
4263: $error{'default'} = $error;
4264: }
1.46 raeburn 4265: }
4266: }
4267: }
4268: } else {
1.95 www 4269: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 4270: }
4271: }
4272: if (ref($settings) eq 'HASH') {
4273: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
4274: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
4275: if ((!@info) || ($info[0] eq 'no_such_dir')) {
4276: $scantronurl = '';
4277: } else {
4278: $scantronurl = $settings->{'scantronformat'};
4279: }
4280: $is_custom = 1;
4281: } else {
4282: $scantronurl = $scantronurls{'default'};
4283: }
4284: } else {
1.60 raeburn 4285: if ($is_custom) {
4286: $scantronurl = $scantronurls{'custom'};
4287: } else {
4288: $scantronurl = $scantronurls{'default'};
4289: }
1.46 raeburn 4290: }
4291: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4292: $datatable .= '<tr'.$css_class.'>';
4293: if (!$is_custom) {
1.65 raeburn 4294: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
4295: '<span class="LC_nobreak">';
1.46 raeburn 4296: if ($scantronurl) {
1.199 raeburn 4297: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
4298: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 4299: } else {
4300: $datatable = &mt('File unavailable for display');
4301: }
1.65 raeburn 4302: $datatable .= '</span></td>';
1.60 raeburn 4303: if (keys(%error) == 0) {
4304: $datatable .= '<td valign="bottom">';
4305: if (!$switchserver) {
4306: $datatable .= &mt('Upload:').'<br />';
4307: }
4308: } else {
4309: my $errorstr;
4310: foreach my $key (sort(keys(%error))) {
4311: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4312: }
4313: $datatable .= '<td>'.$errorstr;
4314: }
1.46 raeburn 4315: } else {
4316: if (keys(%error) > 0) {
4317: my $errorstr;
4318: foreach my $key (sort(keys(%error))) {
4319: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4320: }
1.60 raeburn 4321: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 4322: } elsif ($scantronurl) {
1.199 raeburn 4323: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
4324: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 4325: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 4326: $link.
4327: '<label><input type="checkbox" name="scantronformat_del"'.
4328: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 4329: '<td><span class="LC_nobreak"> '.
4330: &mt('Replace:').'</span><br />';
1.46 raeburn 4331: }
4332: }
4333: if (keys(%error) == 0) {
4334: if ($switchserver) {
4335: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4336: } else {
1.65 raeburn 4337: $datatable .='<span class="LC_nobreak"> '.
4338: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 4339: }
4340: }
4341: $datatable .= '</td></tr>';
4342: $$rowtotal ++;
4343: return $datatable;
4344: }
4345:
4346: sub legacy_scantronformat {
4347: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
4348: my ($url,$error);
4349: my @statinfo = &Apache::lonnet::stat_file($newurl);
4350: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
4351: (my $result,$url) =
4352: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
4353: '','',$newfile);
4354: if ($result ne 'ok') {
1.130 raeburn 4355: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 4356: }
4357: }
4358: return ($url,$error);
4359: }
1.43 raeburn 4360:
1.49 raeburn 4361: sub print_coursecategories {
1.57 raeburn 4362: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
4363: my $datatable;
4364: if ($position eq 'top') {
4365: my $toggle_cats_crs = ' ';
4366: my $toggle_cats_dom = ' checked="checked" ';
4367: my $can_cat_crs = ' ';
4368: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 4369: my $toggle_catscomm_comm = ' ';
4370: my $toggle_catscomm_dom = ' checked="checked" ';
4371: my $can_catcomm_comm = ' ';
4372: my $can_catcomm_dom = ' checked="checked" ';
4373:
1.57 raeburn 4374: if (ref($settings) eq 'HASH') {
4375: if ($settings->{'togglecats'} eq 'crs') {
4376: $toggle_cats_crs = $toggle_cats_dom;
4377: $toggle_cats_dom = ' ';
4378: }
4379: if ($settings->{'categorize'} eq 'crs') {
4380: $can_cat_crs = $can_cat_dom;
4381: $can_cat_dom = ' ';
4382: }
1.120 raeburn 4383: if ($settings->{'togglecatscomm'} eq 'comm') {
4384: $toggle_catscomm_comm = $toggle_catscomm_dom;
4385: $toggle_catscomm_dom = ' ';
4386: }
4387: if ($settings->{'categorizecomm'} eq 'comm') {
4388: $can_catcomm_comm = $can_catcomm_dom;
4389: $can_catcomm_dom = ' ';
4390: }
1.57 raeburn 4391: }
4392: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 4393: togglecats => 'Show/Hide a course in catalog',
4394: togglecatscomm => 'Show/Hide a community in catalog',
4395: categorize => 'Assign a category to a course',
4396: categorizecomm => 'Assign a category to a community',
1.57 raeburn 4397: );
4398: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 4399: dom => 'Set in Domain',
4400: crs => 'Set in Course',
4401: comm => 'Set in Community',
1.57 raeburn 4402: );
4403: $datatable = '<tr class="LC_odd_row">'.
4404: '<td>'.$title{'togglecats'}.'</td>'.
4405: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4406: '<input type="radio" name="togglecats"'.
4407: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4408: '<label><input type="radio" name="togglecats"'.
4409: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
4410: '</tr><tr>'.
4411: '<td>'.$title{'categorize'}.'</td>'.
4412: '<td class="LC_right_item"><span class="LC_nobreak">'.
4413: '<label><input type="radio" name="categorize"'.
4414: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4415: '<label><input type="radio" name="categorize"'.
4416: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 4417: '</tr><tr class="LC_odd_row">'.
4418: '<td>'.$title{'togglecatscomm'}.'</td>'.
4419: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4420: '<input type="radio" name="togglecatscomm"'.
4421: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4422: '<label><input type="radio" name="togglecatscomm"'.
4423: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4424: '</tr><tr>'.
4425: '<td>'.$title{'categorizecomm'}.'</td>'.
4426: '<td class="LC_right_item"><span class="LC_nobreak">'.
4427: '<label><input type="radio" name="categorizecomm"'.
4428: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4429: '<label><input type="radio" name="categorizecomm"'.
4430: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 4431: '</tr>';
1.120 raeburn 4432: $$rowtotal += 4;
1.57 raeburn 4433: } else {
4434: my $css_class;
4435: my $itemcount = 1;
4436: my $cathash;
4437: if (ref($settings) eq 'HASH') {
4438: $cathash = $settings->{'cats'};
4439: }
4440: if (ref($cathash) eq 'HASH') {
4441: my (@cats,@trails,%allitems,%idx,@jsarray);
4442: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4443: \%allitems,\%idx,\@jsarray);
4444: my $maxdepth = scalar(@cats);
4445: my $colattrib = '';
4446: if ($maxdepth > 2) {
4447: $colattrib = ' colspan="2" ';
4448: }
4449: my @path;
4450: if (@cats > 0) {
4451: if (ref($cats[0]) eq 'ARRAY') {
4452: my $numtop = @{$cats[0]};
4453: my $maxnum = $numtop;
1.120 raeburn 4454: my %default_names = (
4455: instcode => &mt('Official courses'),
4456: communities => &mt('Communities'),
4457: );
4458:
4459: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4460: ($cathash->{'instcode::0'} eq '') ||
4461: (!grep(/^communities$/,@{$cats[0]})) ||
4462: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4463: $maxnum ++;
4464: }
4465: my $lastidx;
4466: for (my $i=0; $i<$numtop; $i++) {
4467: my $parent = $cats[0][$i];
4468: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4469: my $item = &escape($parent).'::0';
4470: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4471: $lastidx = $idx{$item};
4472: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4473: .'<select name="'.$item.'"'.$chgstr.'>';
4474: for (my $k=0; $k<=$maxnum; $k++) {
4475: my $vpos = $k+1;
4476: my $selstr;
4477: if ($k == $i) {
4478: $selstr = ' selected="selected" ';
4479: }
4480: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4481: }
1.214 raeburn 4482: $datatable .= '</select></span></td><td>';
1.120 raeburn 4483: if ($parent eq 'instcode' || $parent eq 'communities') {
4484: $datatable .= '<span class="LC_nobreak">'
4485: .$default_names{$parent}.'</span>';
4486: if ($parent eq 'instcode') {
4487: $datatable .= '<br /><span class="LC_nobreak">('
4488: .&mt('with institutional codes')
4489: .')</span></td><td'.$colattrib.'>';
4490: } else {
4491: $datatable .= '<table><tr><td>';
4492: }
4493: $datatable .= '<span class="LC_nobreak">'
4494: .'<label><input type="radio" name="'
4495: .$parent.'" value="1" checked="checked" />'
4496: .&mt('Display').'</label>';
4497: if ($parent eq 'instcode') {
4498: $datatable .= ' ';
4499: } else {
4500: $datatable .= '</span></td></tr><tr><td>'
4501: .'<span class="LC_nobreak">';
4502: }
4503: $datatable .= '<label><input type="radio" name="'
4504: .$parent.'" value="0" />'
4505: .&mt('Do not display').'</label></span>';
4506: if ($parent eq 'communities') {
4507: $datatable .= '</td></tr></table>';
4508: }
4509: $datatable .= '</td>';
1.57 raeburn 4510: } else {
4511: $datatable .= $parent
1.214 raeburn 4512: .' <span class="LC_nobreak"><label>'
4513: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 4514: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4515: }
4516: my $depth = 1;
4517: push(@path,$parent);
4518: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4519: pop(@path);
4520: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4521: $itemcount ++;
4522: }
1.48 raeburn 4523: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 4524: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4525: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 4526: for (my $k=0; $k<=$maxnum; $k++) {
4527: my $vpos = $k+1;
4528: my $selstr;
1.57 raeburn 4529: if ($k == $numtop) {
1.48 raeburn 4530: $selstr = ' selected="selected" ';
4531: }
4532: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4533: }
1.59 bisitz 4534: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 4535: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4536: .'</tr>'."\n";
1.48 raeburn 4537: $itemcount ++;
1.120 raeburn 4538: foreach my $default ('instcode','communities') {
4539: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4540: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4541: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4542: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4543: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4544: for (my $k=0; $k<=$maxnum; $k++) {
4545: my $vpos = $k+1;
4546: my $selstr;
4547: if ($k == $maxnum) {
4548: $selstr = ' selected="selected" ';
4549: }
4550: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 4551: }
1.120 raeburn 4552: $datatable .= '</select></span></td>'.
4553: '<td><span class="LC_nobreak">'.
4554: $default_names{$default}.'</span>';
4555: if ($default eq 'instcode') {
4556: $datatable .= '<br /><span class="LC_nobreak">('
4557: .&mt('with institutional codes').')</span>';
4558: }
4559: $datatable .= '</td>'
4560: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4561: .&mt('Display').'</label> '
4562: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
4563: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 4564: }
4565: }
4566: }
1.57 raeburn 4567: } else {
4568: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 4569: }
4570: } else {
1.57 raeburn 4571: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
4572: .&initialize_categories($itemcount);
1.48 raeburn 4573: }
1.57 raeburn 4574: $$rowtotal += $itemcount;
1.48 raeburn 4575: }
4576: return $datatable;
4577: }
4578:
1.69 raeburn 4579: sub print_serverstatuses {
4580: my ($dom,$settings,$rowtotal) = @_;
4581: my $datatable;
4582: my @pages = &serverstatus_pages();
4583: my (%namedaccess,%machineaccess);
4584: foreach my $type (@pages) {
4585: $namedaccess{$type} = '';
4586: $machineaccess{$type}= '';
4587: }
4588: if (ref($settings) eq 'HASH') {
4589: foreach my $type (@pages) {
4590: if (exists($settings->{$type})) {
4591: if (ref($settings->{$type}) eq 'HASH') {
4592: foreach my $key (keys(%{$settings->{$type}})) {
4593: if ($key eq 'namedusers') {
4594: $namedaccess{$type} = $settings->{$type}->{$key};
4595: } elsif ($key eq 'machines') {
4596: $machineaccess{$type} = $settings->{$type}->{$key};
4597: }
4598: }
4599: }
4600: }
4601: }
4602: }
1.81 raeburn 4603: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 4604: my $rownum = 0;
4605: my $css_class;
4606: foreach my $type (@pages) {
4607: $rownum ++;
4608: $css_class = $rownum%2?' class="LC_odd_row"':'';
4609: $datatable .= '<tr'.$css_class.'>'.
4610: '<td><span class="LC_nobreak">'.
4611: $titles->{$type}.'</span></td>'.
4612: '<td class="LC_left_item">'.
4613: '<input type="text" name="'.$type.'_namedusers" '.
4614: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
4615: '<td class="LC_right_item">'.
4616: '<span class="LC_nobreak">'.
4617: '<input type="text" name="'.$type.'_machines" '.
4618: 'value="'.$machineaccess{$type}.'" size="10" />'.
4619: '</td></tr>'."\n";
4620: }
4621: $$rowtotal += $rownum;
4622: return $datatable;
4623: }
4624:
4625: sub serverstatus_pages {
4626: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.189 raeburn 4627: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.221 raeburn 4628: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
4629: 'uniquecodes');
1.69 raeburn 4630: }
4631:
1.49 raeburn 4632: sub coursecategories_javascript {
4633: my ($settings) = @_;
1.57 raeburn 4634: my ($output,$jstext,$cathash);
1.49 raeburn 4635: if (ref($settings) eq 'HASH') {
1.57 raeburn 4636: $cathash = $settings->{'cats'};
4637: }
4638: if (ref($cathash) eq 'HASH') {
1.49 raeburn 4639: my (@cats,@jsarray,%idx);
1.57 raeburn 4640: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 4641: if (@jsarray > 0) {
4642: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
4643: for (my $i=0; $i<@jsarray; $i++) {
4644: if (ref($jsarray[$i]) eq 'ARRAY') {
4645: my $catstr = join('","',@{$jsarray[$i]});
4646: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
4647: }
4648: }
4649: }
4650: } else {
4651: $jstext = ' var categories = Array(1);'."\n".
4652: ' categories[0] = Array("instcode_pos");'."\n";
4653: }
1.120 raeburn 4654: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
4655: my $communities_reserved = &mt('The name: "communities" is a reserved category');
4656: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 4657: $output = <<"ENDSCRIPT";
4658: <script type="text/javascript">
1.109 raeburn 4659: // <![CDATA[
1.49 raeburn 4660: function reorderCats(form,parent,item,idx) {
4661: var changedVal;
4662: $jstext
4663: var newpos = 'addcategory_pos';
4664: var current = new Array;
4665: if (parent == '') {
4666: var has_instcode = 0;
4667: var maxtop = categories[idx].length;
4668: for (var j=0; j<maxtop; j++) {
4669: if (categories[idx][j] == 'instcode::0') {
4670: has_instcode == 1;
4671: }
4672: }
4673: if (has_instcode == 0) {
4674: categories[idx][maxtop] = 'instcode_pos';
4675: }
4676: } else {
4677: newpos += '_'+parent;
4678: }
4679: var maxh = 1 + categories[idx].length;
4680: var current = new Array;
4681: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4682: if (item == newpos) {
4683: changedVal = newitemVal;
4684: } else {
4685: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4686: current[newitemVal] = newpos;
4687: }
4688: for (var i=0; i<categories[idx].length; i++) {
4689: var elementName = categories[idx][i];
4690: if (elementName != item) {
4691: if (form.elements[elementName]) {
4692: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4693: current[currVal] = elementName;
4694: }
4695: }
4696: }
4697: var oldVal;
4698: for (var j=0; j<maxh; j++) {
4699: if (current[j] == undefined) {
4700: oldVal = j;
4701: }
4702: }
4703: if (oldVal < changedVal) {
4704: for (var k=oldVal+1; k<=changedVal ; k++) {
4705: var elementName = current[k];
4706: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4707: }
4708: } else {
4709: for (var k=changedVal; k<oldVal; k++) {
4710: var elementName = current[k];
4711: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4712: }
4713: }
4714: return;
4715: }
1.120 raeburn 4716:
4717: function categoryCheck(form) {
4718: if (form.elements['addcategory_name'].value == 'instcode') {
4719: alert('$instcode_reserved\\n$choose_again');
4720: return false;
4721: }
4722: if (form.elements['addcategory_name'].value == 'communities') {
4723: alert('$communities_reserved\\n$choose_again');
4724: return false;
4725: }
4726: return true;
4727: }
4728:
1.109 raeburn 4729: // ]]>
1.49 raeburn 4730: </script>
4731:
4732: ENDSCRIPT
4733: return $output;
4734: }
4735:
1.48 raeburn 4736: sub initialize_categories {
4737: my ($itemcount) = @_;
1.120 raeburn 4738: my ($datatable,$css_class,$chgstr);
4739: my %default_names = (
4740: instcode => 'Official courses (with institutional codes)',
4741: communities => 'Communities',
4742: );
4743: my $select0 = ' selected="selected"';
4744: my $select1 = '';
4745: foreach my $default ('instcode','communities') {
4746: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4747: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
4748: if ($default eq 'communities') {
4749: $select1 = $select0;
4750: $select0 = '';
4751: }
4752: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4753: .'<select name="'.$default.'_pos">'
4754: .'<option value="0"'.$select0.'>1</option>'
4755: .'<option value="1"'.$select1.'>2</option>'
4756: .'<option value="2">3</option></select> '
4757: .$default_names{$default}
4758: .'</span></td><td><span class="LC_nobreak">'
4759: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4760: .&mt('Display').'</label> <label>'
4761: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 4762: .'</label></span></td></tr>';
1.120 raeburn 4763: $itemcount ++;
4764: }
1.48 raeburn 4765: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 4766: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 4767: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 4768: .'<select name="addcategory_pos"'.$chgstr.'>'
4769: .'<option value="0">1</option>'
4770: .'<option value="1">2</option>'
4771: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 4772: .&mt('Add category').'</td><td>'.&mt('Name:')
4773: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4774: return $datatable;
4775: }
4776:
4777: sub build_category_rows {
1.49 raeburn 4778: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4779: my ($text,$name,$item,$chgstr);
1.48 raeburn 4780: if (ref($cats) eq 'ARRAY') {
4781: my $maxdepth = scalar(@{$cats});
4782: if (ref($cats->[$depth]) eq 'HASH') {
4783: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4784: my $numchildren = @{$cats->[$depth]{$parent}};
4785: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 4786: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 4787: my ($idxnum,$parent_name,$parent_item);
4788: my $higher = $depth - 1;
4789: if ($higher == 0) {
4790: $parent_name = &escape($parent).'::'.$higher;
4791: } else {
4792: if (ref($path) eq 'ARRAY') {
4793: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4794: }
4795: }
4796: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4797: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4798: if ($j < $numchildren) {
1.48 raeburn 4799: $name = $cats->[$depth]{$parent}[$j];
4800: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4801: $idxnum = $idx->{$item};
4802: } else {
4803: $name = $parent_name;
4804: $item = $parent_item;
1.48 raeburn 4805: }
1.49 raeburn 4806: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4807: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4808: for (my $i=0; $i<=$numchildren; $i++) {
4809: my $vpos = $i+1;
4810: my $selstr;
4811: if ($j == $i) {
4812: $selstr = ' selected="selected" ';
4813: }
4814: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4815: }
4816: $text .= '</select> ';
4817: if ($j < $numchildren) {
4818: my $deeper = $depth+1;
4819: $text .= $name.' '
4820: .'<label><input type="checkbox" name="deletecategory" value="'
4821: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4822: if(ref($path) eq 'ARRAY') {
4823: push(@{$path},$name);
1.49 raeburn 4824: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4825: pop(@{$path});
4826: }
4827: } else {
1.59 bisitz 4828: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4829: if ($j == $numchildren) {
4830: $text .= $name;
4831: } else {
4832: $text .= $item;
4833: }
4834: $text .= '" value="" />';
4835: }
4836: $text .= '</td></tr>';
4837: }
4838: $text .= '</table></td>';
4839: } else {
4840: my $higher = $depth-1;
4841: if ($higher == 0) {
4842: $name = &escape($parent).'::'.$higher;
4843: } else {
4844: if (ref($path) eq 'ARRAY') {
4845: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4846: }
4847: }
4848: my $colspan;
4849: if ($parent ne 'instcode') {
4850: $colspan = $maxdepth - $depth - 1;
4851: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4852: }
4853: }
4854: }
4855: }
4856: return $text;
4857: }
4858:
1.33 raeburn 4859: sub modifiable_userdata_row {
1.224 ! raeburn 4860: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
1.33 raeburn 4861: my $rolename;
1.224 ! raeburn 4862: if ($context eq 'cancreate') {
! 4863: if ($role eq 'emailusername') {
! 4864: $rolename = &mt('Data user provides');
! 4865: }
! 4866: } elsif ($context eq 'selfcreate') {
1.63 raeburn 4867: if (ref($usertypes) eq 'HASH') {
4868: $rolename = $usertypes->{$role};
4869: } else {
4870: $rolename = $role;
4871: }
1.33 raeburn 4872: } else {
1.63 raeburn 4873: if ($role eq 'cr') {
4874: $rolename = &mt('Custom role');
4875: } else {
4876: $rolename = &Apache::lonnet::plaintext($role);
4877: }
1.33 raeburn 4878: }
1.224 ! raeburn 4879: my (@fields,%fieldtitles);
! 4880: if (ref($fieldsref) eq 'ARRAY') {
! 4881: @fields = @{$fieldsref};
! 4882: } else {
! 4883: @fields = ('lastname','firstname','middlename','generation',
! 4884: 'permanentemail','id');
! 4885: }
! 4886: if ((ref($titlesref) eq 'HASH')) {
! 4887: %fieldtitles = %{$titlesref};
! 4888: } else {
! 4889: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
! 4890: }
1.33 raeburn 4891: my $output;
4892: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4893: $output = '<tr '.$css_class.'>'.
4894: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4895: '<td class="LC_left_item" colspan="2"><table>';
4896: my $rem;
4897: my %checks;
4898: if (ref($settings) eq 'HASH') {
4899: if (ref($settings->{$context}) eq 'HASH') {
4900: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4901: foreach my $field (@fields) {
4902: if ($settings->{$context}->{$role}->{$field}) {
4903: $checks{$field} = ' checked="checked" ';
4904: }
4905: }
4906: }
4907: }
4908: }
4909: for (my $i=0; $i<@fields; $i++) {
4910: my $rem = $i%($numinrow);
4911: if ($rem == 0) {
4912: if ($i > 0) {
4913: $output .= '</tr>';
4914: }
4915: $output .= '<tr>';
4916: }
4917: my $check = ' ';
4918: if (exists($checks{$fields[$i]})) {
4919: $check = $checks{$fields[$i]}
4920: } else {
4921: if ($role eq 'st') {
4922: if (ref($settings) ne 'HASH') {
4923: $check = ' checked="checked" ';
4924: }
4925: }
4926: }
4927: $output .= '<td class="LC_left_item">'.
4928: '<span class="LC_nobreak"><label>'.
4929: '<input type="checkbox" name="canmodify_'.$role.'" '.
4930: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4931: '</label></span></td>';
4932: $rem = @fields%($numinrow);
4933: }
4934: my $colsleft = $numinrow - $rem;
4935: if ($colsleft > 1 ) {
4936: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4937: ' </td>';
4938: } elsif ($colsleft == 1) {
4939: $output .= '<td class="LC_left_item"> </td>';
4940: }
4941: $output .= '</tr></table></td></tr>';
4942: return $output;
4943: }
1.28 raeburn 4944:
1.93 raeburn 4945: sub insttypes_row {
1.224 ! raeburn 4946: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 4947: my %lt = &Apache::lonlocal::texthash (
4948: cansearch => 'Users allowed to search',
4949: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4950: lockablenames => 'User preference to lock name',
1.93 raeburn 4951: );
4952: my $showdom;
4953: if ($context eq 'cansearch') {
4954: $showdom = ' ('.$dom.')';
4955: }
1.165 raeburn 4956: my $class = 'LC_left_item';
4957: if ($context eq 'statustocreate') {
4958: $class = 'LC_right_item';
4959: }
1.224 ! raeburn 4960: my $css_class = ' class="LC_odd_row"';
! 4961: if ($rownum ne '') {
! 4962: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
! 4963: }
! 4964: print STDERR "rownum ||$rownum|| an css_class ||".$css_class."||\n";
! 4965: my $output = '<tr'.$css_class.'>'.
! 4966: '<td>'.$lt{$context}.$showdom.
! 4967: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 4968: my $rem;
4969: if (ref($types) eq 'ARRAY') {
4970: for (my $i=0; $i<@{$types}; $i++) {
4971: if (defined($usertypes->{$types->[$i]})) {
4972: my $rem = $i%($numinrow);
4973: if ($rem == 0) {
4974: if ($i > 0) {
4975: $output .= '</tr>';
4976: }
4977: $output .= '<tr>';
1.23 raeburn 4978: }
1.26 raeburn 4979: my $check = ' ';
1.99 raeburn 4980: if (ref($settings) eq 'HASH') {
4981: if (ref($settings->{$context}) eq 'ARRAY') {
4982: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4983: $check = ' checked="checked" ';
4984: }
4985: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4986: $check = ' checked="checked" ';
4987: }
1.23 raeburn 4988: }
1.26 raeburn 4989: $output .= '<td class="LC_left_item">'.
4990: '<span class="LC_nobreak"><label>'.
1.93 raeburn 4991: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 4992: 'value="'.$types->[$i].'"'.$check.'/>'.
4993: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 4994: }
4995: }
1.26 raeburn 4996: $rem = @{$types}%($numinrow);
1.23 raeburn 4997: }
4998: my $colsleft = $numinrow - $rem;
1.131 raeburn 4999: if (($rem == 0) && (@{$types} > 0)) {
5000: $output .= '<tr>';
5001: }
1.23 raeburn 5002: if ($colsleft > 1) {
1.25 raeburn 5003: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 5004: } else {
1.25 raeburn 5005: $output .= '<td class="LC_left_item">';
1.23 raeburn 5006: }
5007: my $defcheck = ' ';
1.99 raeburn 5008: if (ref($settings) eq 'HASH') {
5009: if (ref($settings->{$context}) eq 'ARRAY') {
5010: if (grep(/^default$/,@{$settings->{$context}})) {
5011: $defcheck = ' checked="checked" ';
5012: }
5013: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5014: $defcheck = ' checked="checked" ';
5015: }
1.23 raeburn 5016: }
1.25 raeburn 5017: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 5018: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 5019: 'value="default"'.$defcheck.'/>'.
5020: $othertitle.'</label></span></td>'.
5021: '</tr></table></td></tr>';
5022: return $output;
1.23 raeburn 5023: }
5024:
5025: sub sorted_searchtitles {
5026: my %searchtitles = &Apache::lonlocal::texthash(
5027: 'uname' => 'username',
5028: 'lastname' => 'last name',
5029: 'lastfirst' => 'last name, first name',
5030: );
5031: my @titleorder = ('uname','lastname','lastfirst');
5032: return (\%searchtitles,\@titleorder);
5033: }
5034:
1.25 raeburn 5035: sub sorted_searchtypes {
5036: my %srchtypes_desc = (
5037: exact => 'is exact match',
5038: contains => 'contains ..',
5039: begins => 'begins with ..',
5040: );
5041: my @srchtypeorder = ('exact','begins','contains');
5042: return (\%srchtypes_desc,\@srchtypeorder);
5043: }
5044:
1.3 raeburn 5045: sub usertype_update_row {
5046: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
5047: my $datatable;
5048: my $numinrow = 4;
5049: foreach my $type (@{$types}) {
5050: if (defined($usertypes->{$type})) {
5051: $$rownums ++;
5052: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
5053: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
5054: '</td><td class="LC_left_item"><table>';
5055: for (my $i=0; $i<@{$fields}; $i++) {
5056: my $rem = $i%($numinrow);
5057: if ($rem == 0) {
5058: if ($i > 0) {
5059: $datatable .= '</tr>';
5060: }
5061: $datatable .= '<tr>';
5062: }
5063: my $check = ' ';
1.39 raeburn 5064: if (ref($settings) eq 'HASH') {
5065: if (ref($settings->{'fields'}) eq 'HASH') {
5066: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
5067: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
5068: $check = ' checked="checked" ';
5069: }
1.3 raeburn 5070: }
5071: }
5072: }
5073:
5074: if ($i == @{$fields}-1) {
5075: my $colsleft = $numinrow - $rem;
5076: if ($colsleft > 1) {
5077: $datatable .= '<td colspan="'.$colsleft.'">';
5078: } else {
5079: $datatable .= '<td>';
5080: }
5081: } else {
5082: $datatable .= '<td>';
5083: }
1.8 raeburn 5084: $datatable .= '<span class="LC_nobreak"><label>'.
5085: '<input type="checkbox" name="updateable_'.$type.
5086: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
5087: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 5088: }
5089: $datatable .= '</tr></table></td></tr>';
5090: }
5091: }
5092: return $datatable;
1.1 raeburn 5093: }
5094:
5095: sub modify_login {
1.205 raeburn 5096: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 5097: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
5098: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
5099: %title = ( coursecatalog => 'Display course catalog',
5100: adminmail => 'Display administrator E-mail address',
1.188 raeburn 5101: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 5102: newuser => 'Link for visitors to create a user account',
5103: loginheader => 'Log-in box header');
5104: @offon = ('off','on');
1.112 raeburn 5105: if (ref($domconfig{login}) eq 'HASH') {
5106: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
5107: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
5108: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
5109: }
5110: }
5111: }
1.9 raeburn 5112: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
5113: \%domconfig,\%loginhash);
1.188 raeburn 5114: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5115: foreach my $item (@toggles) {
5116: $loginhash{login}{$item} = $env{'form.'.$item};
5117: }
1.41 raeburn 5118: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 5119: if (ref($colchanges{'login'}) eq 'HASH') {
5120: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
5121: \%loginhash);
5122: }
1.110 raeburn 5123:
1.149 raeburn 5124: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 5125: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 5126: if (keys(%servers) > 1) {
5127: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 5128: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
5129: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
5130: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
5131: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
5132: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
5133: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5134: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5135: $changes{'loginvia'}{$lonhost} = 1;
5136: } else {
5137: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
5138: $changes{'loginvia'}{$lonhost} = 1;
5139: }
5140: } else {
5141: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5142: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5143: $changes{'loginvia'}{$lonhost} = 1;
5144: }
5145: }
5146: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
5147: foreach my $item (@loginvia_attribs) {
5148: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
5149: }
5150: } else {
5151: foreach my $item (@loginvia_attribs) {
5152: my $new = $env{'form.'.$lonhost.'_'.$item};
5153: if (($item eq 'serverpath') && ($new eq 'custom')) {
5154: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
5155: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5156: $new = '/';
5157: }
5158: }
5159: if (($item eq 'custompath') &&
5160: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5161: $new = '';
5162: }
5163: if ($new ne $curr_loginvia{$lonhost}{$item}) {
5164: $changes{'loginvia'}{$lonhost} = 1;
5165: }
5166: if ($item eq 'exempt') {
5167: $new =~ s/^\s+//;
5168: $new =~ s/\s+$//;
5169: my @poss_ips = split(/\s*[,:]\s*/,$new);
5170: my @okips;
5171: foreach my $ip (@poss_ips) {
5172: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
5173: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
5174: push(@okips,$ip);
5175: }
5176: }
5177: }
5178: if (@okips > 0) {
5179: $new = join(',',@okips);
5180: } else {
5181: $new = '';
5182: }
5183: }
5184: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5185: }
5186: }
1.112 raeburn 5187: } else {
1.128 raeburn 5188: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5189: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 5190: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 5191: foreach my $item (@loginvia_attribs) {
5192: my $new = $env{'form.'.$lonhost.'_'.$item};
5193: if (($item eq 'serverpath') && ($new eq 'custom')) {
5194: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5195: $new = '/';
5196: }
5197: }
5198: if (($item eq 'custompath') &&
5199: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5200: $new = '';
5201: }
5202: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5203: }
1.110 raeburn 5204: }
5205: }
5206: }
5207: }
1.119 raeburn 5208:
1.168 raeburn 5209: my $servadm = $r->dir_config('lonAdmEMail');
5210: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
5211: if (ref($domconfig{'login'}) eq 'HASH') {
5212: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
5213: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
5214: if ($lang eq 'nolang') {
5215: push(@currlangs,$lang);
5216: } elsif (defined($langchoices{$lang})) {
5217: push(@currlangs,$lang);
5218: } else {
5219: next;
5220: }
5221: }
5222: }
5223: }
5224: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
5225: if (@currlangs > 0) {
5226: foreach my $lang (@currlangs) {
5227: if (grep(/^\Q$lang\E$/,@delurls)) {
5228: $changes{'helpurl'}{$lang} = 1;
5229: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
5230: $changes{'helpurl'}{$lang} = 1;
5231: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
5232: push(@newlangs,$lang);
5233: } else {
5234: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5235: }
5236: }
5237: }
5238: unless (grep(/^nolang$/,@currlangs)) {
5239: if ($env{'form.loginhelpurl_nolang.filename'}) {
5240: $changes{'helpurl'}{'nolang'} = 1;
5241: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
5242: push(@newlangs,'nolang');
5243: }
5244: }
5245: if ($env{'form.loginhelpurl_add_lang'}) {
5246: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
5247: ($env{'form.loginhelpurl_add_file.filename'})) {
5248: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
5249: $addedfile = $env{'form.loginhelpurl_add_lang'};
5250: }
5251: }
5252: if ((@newlangs > 0) || ($addedfile)) {
5253: my $error;
5254: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
5255: if ($configuserok eq 'ok') {
5256: if ($switchserver) {
5257: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
5258: } elsif ($author_ok eq 'ok') {
5259: my @allnew = @newlangs;
5260: if ($addedfile ne '') {
5261: push(@allnew,$addedfile);
5262: }
5263: foreach my $lang (@allnew) {
5264: my $formelem = 'loginhelpurl_'.$lang;
5265: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
5266: $formelem = 'loginhelpurl_add_file';
5267: }
5268: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
5269: "help/$lang",'','',$newfile{$lang});
5270: if ($result eq 'ok') {
5271: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
5272: $changes{'helpurl'}{$lang} = 1;
5273: } else {
5274: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
5275: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 5276: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 5277: (!grep(/^\Q$lang\E$/,@delurls))) {
5278:
5279: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5280: }
5281: }
5282: }
5283: } else {
5284: $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);
5285: }
5286: } else {
5287: $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);
5288: }
5289: if ($error) {
5290: &Apache::lonnet::logthis($error);
5291: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
5292: }
5293: }
1.169 raeburn 5294: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 5295:
5296: my $defaulthelpfile = '/adm/loginproblems.html';
5297: my $defaulttext = &mt('Default in use');
5298:
1.1 raeburn 5299: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
5300: $dom);
5301: if ($putresult eq 'ok') {
1.188 raeburn 5302: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5303: my %defaultchecked = (
5304: 'coursecatalog' => 'on',
1.188 raeburn 5305: 'helpdesk' => 'on',
1.42 raeburn 5306: 'adminmail' => 'off',
1.43 raeburn 5307: 'newuser' => 'off',
1.42 raeburn 5308: );
1.55 raeburn 5309: if (ref($domconfig{'login'}) eq 'HASH') {
5310: foreach my $item (@toggles) {
5311: if ($defaultchecked{$item} eq 'on') {
5312: if (($domconfig{'login'}{$item} eq '0') &&
5313: ($env{'form.'.$item} eq '1')) {
5314: $changes{$item} = 1;
5315: } elsif (($domconfig{'login'}{$item} eq '' ||
5316: $domconfig{'login'}{$item} eq '1') &&
5317: ($env{'form.'.$item} eq '0')) {
5318: $changes{$item} = 1;
5319: }
5320: } elsif ($defaultchecked{$item} eq 'off') {
5321: if (($domconfig{'login'}{$item} eq '1') &&
5322: ($env{'form.'.$item} eq '0')) {
5323: $changes{$item} = 1;
5324: } elsif (($domconfig{'login'}{$item} eq '' ||
5325: $domconfig{'login'}{$item} eq '0') &&
5326: ($env{'form.'.$item} eq '1')) {
5327: $changes{$item} = 1;
5328: }
1.42 raeburn 5329: }
5330: }
1.41 raeburn 5331: }
1.6 raeburn 5332: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 5333: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 5334: if (ref($lastactref) eq 'HASH') {
5335: $lastactref->{'domainconfig'} = 1;
5336: }
1.1 raeburn 5337: $resulttext = &mt('Changes made:').'<ul>';
5338: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 5339: if ($item eq 'loginvia') {
1.112 raeburn 5340: if (ref($changes{$item}) eq 'HASH') {
5341: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
5342: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 5343: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
5344: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
5345: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
5346: $protocol = 'http' if ($protocol ne 'https');
5347: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
5348:
5349: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
5350: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
5351: } else {
5352: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
5353: }
5354: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
5355: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
5356: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
5357: }
5358: $resulttext .= '</li>';
5359: } else {
5360: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
5361: }
1.112 raeburn 5362: } else {
1.128 raeburn 5363: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 5364: }
5365: }
1.128 raeburn 5366: $resulttext .= '</ul></li>';
1.112 raeburn 5367: }
1.168 raeburn 5368: } elsif ($item eq 'helpurl') {
5369: if (ref($changes{$item}) eq 'HASH') {
5370: foreach my $lang (sort(keys(%{$changes{$item}}))) {
5371: if (grep(/^\Q$lang\E$/,@delurls)) {
5372: my ($chg,$link);
5373: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
5374: if ($lang eq 'nolang') {
5375: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
5376: } else {
5377: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
5378: }
5379: $resulttext .= '<li>'.$chg.'</li>';
5380: } else {
5381: my $chg;
5382: if ($lang eq 'nolang') {
5383: $chg = &mt('custom log-in help file for no preferred language');
5384: } else {
5385: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
5386: }
5387: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
5388: $loginhash{'login'}{'helpurl'}{$lang}.
5389: '?inhibitmenu=yes',$chg,600,500).
5390: '</li>';
5391: }
5392: }
5393: }
1.169 raeburn 5394: } elsif ($item eq 'captcha') {
5395: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 5396: my $chgtxt;
1.169 raeburn 5397: if ($loginhash{'login'}{$item} eq 'notused') {
5398: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
5399: } else {
5400: my %captchas = &captcha_phrases();
5401: if ($captchas{$loginhash{'login'}{$item}}) {
5402: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
5403: } else {
5404: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
5405: }
5406: }
5407: $resulttext .= '<li>'.$chgtxt.'</li>';
5408: }
5409: } elsif ($item eq 'recaptchakeys') {
5410: if (ref($loginhash{'login'}) eq 'HASH') {
5411: my ($privkey,$pubkey);
5412: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
5413: $pubkey = $loginhash{'login'}{$item}{'public'};
5414: $privkey = $loginhash{'login'}{$item}{'private'};
5415: }
5416: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
5417: if (!$pubkey) {
5418: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
5419: } else {
5420: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
5421: }
5422: if (!$privkey) {
5423: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
5424: } else {
5425: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
5426: }
5427: $chgtxt .= '</ul>';
5428: $resulttext .= '<li>'.$chgtxt.'</li>';
5429: }
1.41 raeburn 5430: } else {
5431: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
5432: }
1.1 raeburn 5433: }
1.6 raeburn 5434: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 5435: } else {
5436: $resulttext = &mt('No changes made to log-in page settings');
5437: }
5438: } else {
1.11 albertel 5439: $resulttext = '<span class="LC_error">'.
5440: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5441: }
1.6 raeburn 5442: if ($errors) {
1.9 raeburn 5443: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 5444: $errors.'</ul>';
5445: }
5446: return $resulttext;
5447: }
5448:
5449: sub color_font_choices {
5450: my %choices =
5451: &Apache::lonlocal::texthash (
5452: img => "Header",
5453: bgs => "Background colors",
5454: links => "Link colors",
1.55 raeburn 5455: images => "Images",
1.6 raeburn 5456: font => "Font color",
1.201 raeburn 5457: fontmenu => "Font menu",
1.76 raeburn 5458: pgbg => "Page",
1.6 raeburn 5459: tabbg => "Header",
5460: sidebg => "Border",
5461: link => "Link",
5462: alink => "Active link",
5463: vlink => "Visited link",
5464: );
5465: return %choices;
5466: }
5467:
5468: sub modify_rolecolors {
1.205 raeburn 5469: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 5470: my ($resulttext,%rolehash);
5471: $rolehash{'rolecolors'} = {};
1.55 raeburn 5472: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
5473: if ($domconfig{'rolecolors'} eq '') {
5474: $domconfig{'rolecolors'} = {};
5475: }
5476: }
1.9 raeburn 5477: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 5478: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
5479: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
5480: $dom);
5481: if ($putresult eq 'ok') {
5482: if (keys(%changes) > 0) {
1.41 raeburn 5483: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 5484: if (ref($lastactref) eq 'HASH') {
5485: $lastactref->{'domainconfig'} = 1;
5486: }
1.6 raeburn 5487: $resulttext = &display_colorchgs($dom,\%changes,$roles,
5488: $rolehash{'rolecolors'});
5489: } else {
5490: $resulttext = &mt('No changes made to default color schemes');
5491: }
5492: } else {
1.11 albertel 5493: $resulttext = '<span class="LC_error">'.
5494: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 5495: }
5496: if ($errors) {
5497: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5498: $errors.'</ul>';
5499: }
5500: return $resulttext;
5501: }
5502:
5503: sub modify_colors {
1.9 raeburn 5504: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 5505: my (%changes,%choices);
1.51 raeburn 5506: my @bgs;
1.6 raeburn 5507: my @links = ('link','alink','vlink');
1.41 raeburn 5508: my @logintext;
1.6 raeburn 5509: my @images;
5510: my $servadm = $r->dir_config('lonAdmEMail');
5511: my $errors;
1.200 raeburn 5512: my %defaults;
1.6 raeburn 5513: foreach my $role (@{$roles}) {
5514: if ($role eq 'login') {
1.12 raeburn 5515: %choices = &login_choices();
1.41 raeburn 5516: @logintext = ('textcol','bgcol');
1.12 raeburn 5517: } else {
5518: %choices = &color_font_choices();
5519: }
5520: if ($role eq 'login') {
1.41 raeburn 5521: @images = ('img','logo','domlogo','login');
1.51 raeburn 5522: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 5523: } else {
5524: @images = ('img');
1.200 raeburn 5525: @bgs = ('pgbg','tabbg','sidebg');
5526: }
5527: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
5528: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
5529: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
5530: }
5531: if ($role eq 'login') {
5532: foreach my $item (@logintext) {
5533: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'logintext'}{$item}) {
5534: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5535: }
5536: }
5537: } else {
5538: unless($env{'form.'.$role.'_fontmenu'} eq $defaults{'fontmenu'}) {
5539: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
5540: }
1.6 raeburn 5541: }
1.200 raeburn 5542: foreach my $item (@bgs) {
5543: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'bgs'}{$item} ) {
5544: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5545: }
5546: }
5547: foreach my $item (@links) {
5548: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'links'}{$item}) {
5549: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5550: }
1.6 raeburn 5551: }
1.46 raeburn 5552: my ($configuserok,$author_ok,$switchserver) =
5553: &config_check($dom,$confname,$servadm);
1.9 raeburn 5554: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 5555: if (ref($domconfig->{$role}) ne 'HASH') {
5556: $domconfig->{$role} = {};
5557: }
1.8 raeburn 5558: foreach my $img (@images) {
1.70 raeburn 5559: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
5560: if (defined($env{'form.login_showlogo_'.$img})) {
5561: $confhash->{$role}{'showlogo'}{$img} = 1;
5562: } else {
5563: $confhash->{$role}{'showlogo'}{$img} = 0;
5564: }
5565: }
1.18 albertel 5566: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
5567: && !defined($domconfig->{$role}{$img})
5568: && !$env{'form.'.$role.'_del_'.$img}
5569: && $env{'form.'.$role.'_import_'.$img}) {
5570: # import the old configured image from the .tab setting
5571: # if they haven't provided a new one
5572: $domconfig->{$role}{$img} =
5573: $env{'form.'.$role.'_import_'.$img};
5574: }
1.6 raeburn 5575: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 5576: my $error;
1.6 raeburn 5577: if ($configuserok eq 'ok') {
1.9 raeburn 5578: if ($switchserver) {
1.12 raeburn 5579: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 5580: } else {
5581: if ($author_ok eq 'ok') {
5582: my ($result,$logourl) =
5583: &publishlogo($r,'upload',$role.'_'.$img,
5584: $dom,$confname,$img,$width,$height);
5585: if ($result eq 'ok') {
5586: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 5587: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5588: } else {
1.12 raeburn 5589: $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 5590: }
5591: } else {
1.46 raeburn 5592: $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 5593: }
5594: }
5595: } else {
1.46 raeburn 5596: $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 5597: }
5598: if ($error) {
1.8 raeburn 5599: &Apache::lonnet::logthis($error);
1.11 albertel 5600: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 5601: }
5602: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 5603: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
5604: my $error;
5605: if ($configuserok eq 'ok') {
5606: # is confname an author?
5607: if ($switchserver eq '') {
5608: if ($author_ok eq 'ok') {
5609: my ($result,$logourl) =
5610: &publishlogo($r,'copy',$domconfig->{$role}{$img},
5611: $dom,$confname,$img,$width,$height);
5612: if ($result eq 'ok') {
5613: $confhash->{$role}{$img} = $logourl;
1.18 albertel 5614: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5615: }
5616: }
5617: }
5618: }
1.6 raeburn 5619: }
5620: }
5621: }
5622: if (ref($domconfig) eq 'HASH') {
5623: if (ref($domconfig->{$role}) eq 'HASH') {
5624: foreach my $img (@images) {
5625: if ($domconfig->{$role}{$img} ne '') {
5626: if ($env{'form.'.$role.'_del_'.$img}) {
5627: $confhash->{$role}{$img} = '';
1.12 raeburn 5628: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5629: } else {
1.9 raeburn 5630: if ($confhash->{$role}{$img} eq '') {
5631: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
5632: }
1.6 raeburn 5633: }
5634: } else {
5635: if ($env{'form.'.$role.'_del_'.$img}) {
5636: $confhash->{$role}{$img} = '';
1.12 raeburn 5637: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5638: }
5639: }
1.70 raeburn 5640: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
5641: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
5642: if ($confhash->{$role}{'showlogo'}{$img} ne
5643: $domconfig->{$role}{'showlogo'}{$img}) {
5644: $changes{$role}{'showlogo'}{$img} = 1;
5645: }
5646: } else {
5647: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5648: $changes{$role}{'showlogo'}{$img} = 1;
5649: }
5650: }
5651: }
5652: }
1.6 raeburn 5653: if ($domconfig->{$role}{'font'} ne '') {
5654: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
5655: $changes{$role}{'font'} = 1;
5656: }
5657: } else {
5658: if ($confhash->{$role}{'font'}) {
5659: $changes{$role}{'font'} = 1;
5660: }
5661: }
1.107 raeburn 5662: if ($role ne 'login') {
5663: if ($domconfig->{$role}{'fontmenu'} ne '') {
5664: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
5665: $changes{$role}{'fontmenu'} = 1;
5666: }
5667: } else {
5668: if ($confhash->{$role}{'fontmenu'}) {
5669: $changes{$role}{'fontmenu'} = 1;
5670: }
1.97 tempelho 5671: }
5672: }
1.6 raeburn 5673: foreach my $item (@bgs) {
5674: if ($domconfig->{$role}{$item} ne '') {
5675: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5676: $changes{$role}{'bgs'}{$item} = 1;
5677: }
5678: } else {
5679: if ($confhash->{$role}{$item}) {
5680: $changes{$role}{'bgs'}{$item} = 1;
5681: }
5682: }
5683: }
5684: foreach my $item (@links) {
5685: if ($domconfig->{$role}{$item} ne '') {
5686: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5687: $changes{$role}{'links'}{$item} = 1;
5688: }
5689: } else {
5690: if ($confhash->{$role}{$item}) {
5691: $changes{$role}{'links'}{$item} = 1;
5692: }
5693: }
5694: }
1.41 raeburn 5695: foreach my $item (@logintext) {
5696: if ($domconfig->{$role}{$item} ne '') {
5697: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5698: $changes{$role}{'logintext'}{$item} = 1;
5699: }
5700: } else {
5701: if ($confhash->{$role}{$item}) {
5702: $changes{$role}{'logintext'}{$item} = 1;
5703: }
5704: }
5705: }
1.6 raeburn 5706: } else {
5707: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5708: \@logintext,$confhash,\%changes);
1.6 raeburn 5709: }
5710: } else {
5711: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5712: \@logintext,$confhash,\%changes);
1.6 raeburn 5713: }
5714: }
5715: return ($errors,%changes);
5716: }
5717:
1.46 raeburn 5718: sub config_check {
5719: my ($dom,$confname,$servadm) = @_;
5720: my ($configuserok,$author_ok,$switchserver,%currroles);
5721: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
5722: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
5723: $confname,$servadm);
5724: if ($configuserok eq 'ok') {
5725: $switchserver = &check_switchserver($dom,$confname);
5726: if ($switchserver eq '') {
5727: $author_ok = &check_authorstatus($dom,$confname,%currroles);
5728: }
5729: }
5730: return ($configuserok,$author_ok,$switchserver);
5731: }
5732:
1.6 raeburn 5733: sub default_change_checker {
1.41 raeburn 5734: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 5735: foreach my $item (@{$links}) {
5736: if ($confhash->{$role}{$item}) {
5737: $changes->{$role}{'links'}{$item} = 1;
5738: }
5739: }
5740: foreach my $item (@{$bgs}) {
5741: if ($confhash->{$role}{$item}) {
5742: $changes->{$role}{'bgs'}{$item} = 1;
5743: }
5744: }
1.41 raeburn 5745: foreach my $item (@{$logintext}) {
5746: if ($confhash->{$role}{$item}) {
5747: $changes->{$role}{'logintext'}{$item} = 1;
5748: }
5749: }
1.6 raeburn 5750: foreach my $img (@{$images}) {
5751: if ($env{'form.'.$role.'_del_'.$img}) {
5752: $confhash->{$role}{$img} = '';
1.12 raeburn 5753: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 5754: }
1.70 raeburn 5755: if ($role eq 'login') {
5756: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5757: $changes->{$role}{'showlogo'}{$img} = 1;
5758: }
5759: }
1.6 raeburn 5760: }
5761: if ($confhash->{$role}{'font'}) {
5762: $changes->{$role}{'font'} = 1;
5763: }
1.48 raeburn 5764: }
1.6 raeburn 5765:
5766: sub display_colorchgs {
5767: my ($dom,$changes,$roles,$confhash) = @_;
5768: my (%choices,$resulttext);
5769: if (!grep(/^login$/,@{$roles})) {
5770: $resulttext = &mt('Changes made:').'<br />';
5771: }
5772: foreach my $role (@{$roles}) {
5773: if ($role eq 'login') {
5774: %choices = &login_choices();
5775: } else {
5776: %choices = &color_font_choices();
5777: }
5778: if (ref($changes->{$role}) eq 'HASH') {
5779: if ($role ne 'login') {
5780: $resulttext .= '<h4>'.&mt($role).'</h4>';
5781: }
5782: foreach my $key (sort(keys(%{$changes->{$role}}))) {
5783: if ($role ne 'login') {
5784: $resulttext .= '<ul>';
5785: }
5786: if (ref($changes->{$role}{$key}) eq 'HASH') {
5787: if ($role ne 'login') {
5788: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
5789: }
5790: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 5791: if (($role eq 'login') && ($key eq 'showlogo')) {
5792: if ($confhash->{$role}{$key}{$item}) {
5793: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
5794: } else {
5795: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
5796: }
5797: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 5798: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
5799: } else {
1.12 raeburn 5800: my $newitem = $confhash->{$role}{$item};
5801: if ($key eq 'images') {
5802: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
5803: }
5804: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 5805: }
5806: }
5807: if ($role ne 'login') {
5808: $resulttext .= '</ul></li>';
5809: }
5810: } else {
5811: if ($confhash->{$role}{$key} eq '') {
5812: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
5813: } else {
5814: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
5815: }
5816: }
5817: if ($role ne 'login') {
5818: $resulttext .= '</ul>';
5819: }
5820: }
5821: }
5822: }
1.3 raeburn 5823: return $resulttext;
1.1 raeburn 5824: }
5825:
1.9 raeburn 5826: sub thumb_dimensions {
5827: return ('200','50');
5828: }
5829:
1.16 raeburn 5830: sub check_dimensions {
5831: my ($inputfile) = @_;
5832: my ($fullwidth,$fullheight);
5833: if ($inputfile =~ m|^[/\w.\-]+$|) {
5834: if (open(PIPE,"identify $inputfile 2>&1 |")) {
5835: my $imageinfo = <PIPE>;
5836: if (!close(PIPE)) {
5837: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
5838: }
5839: chomp($imageinfo);
5840: my ($fullsize) =
1.21 raeburn 5841: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 5842: if ($fullsize) {
5843: ($fullwidth,$fullheight) = split(/x/,$fullsize);
5844: }
5845: }
5846: }
5847: return ($fullwidth,$fullheight);
5848: }
5849:
1.9 raeburn 5850: sub check_configuser {
5851: my ($uhome,$dom,$confname,$servadm) = @_;
5852: my ($configuserok,%currroles);
5853: if ($uhome eq 'no_host') {
5854: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
5855: my $configpass = &LONCAPA::Enrollment::create_password();
5856: $configuserok =
5857: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
5858: $configpass,'','','','','',undef,$servadm);
5859: } else {
5860: $configuserok = 'ok';
5861: %currroles =
5862: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
5863: }
5864: return ($configuserok,%currroles);
5865: }
5866:
5867: sub check_authorstatus {
5868: my ($dom,$confname,%currroles) = @_;
5869: my $author_ok;
1.40 raeburn 5870: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 5871: my $start = time;
5872: my $end = 0;
5873: $author_ok =
5874: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 5875: 'au',$end,$start,'','','domconfig');
1.9 raeburn 5876: } else {
5877: $author_ok = 'ok';
5878: }
5879: return $author_ok;
5880: }
5881:
5882: sub publishlogo {
1.46 raeburn 5883: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 5884: my ($output,$fname,$logourl);
5885: if ($action eq 'upload') {
5886: $fname=$env{'form.'.$formname.'.filename'};
5887: chop($env{'form.'.$formname});
5888: } else {
5889: ($fname) = ($formname =~ /([^\/]+)$/);
5890: }
1.46 raeburn 5891: if ($savefileas ne '') {
5892: $fname = $savefileas;
5893: }
1.9 raeburn 5894: $fname=&Apache::lonnet::clean_filename($fname);
5895: # See if there is anything left
5896: unless ($fname) { return ('error: no uploaded file'); }
5897: $fname="$subdir/$fname";
1.210 raeburn 5898: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 5899: my $filepath="$docroot/priv";
5900: my $relpath = "$dom/$confname";
1.9 raeburn 5901: my ($fnamepath,$file,$fetchthumb);
5902: $file=$fname;
5903: if ($fname=~m|/|) {
5904: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
5905: }
1.164 raeburn 5906: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 5907: my $count;
1.164 raeburn 5908: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 5909: $filepath.="/$parts[$count]";
5910: if ((-e $filepath)!=1) {
5911: mkdir($filepath,02770);
5912: }
5913: }
5914: # Check for bad extension and disallow upload
5915: if ($file=~/\.(\w+)$/ &&
5916: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
5917: $output =
1.207 bisitz 5918: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 5919: } elsif ($file=~/\.(\w+)$/ &&
5920: !defined(&Apache::loncommon::fileembstyle($1))) {
5921: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
5922: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 5923: $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 5924: } elsif (-d "$filepath/$file") {
1.195 bisitz 5925: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 5926: } else {
5927: my $source = $filepath.'/'.$file;
5928: my $logfile;
5929: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 5930: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 5931: }
5932: print $logfile
5933: "\n================= Publish ".localtime()." ================\n".
5934: $env{'user.name'}.':'.$env{'user.domain'}."\n";
5935: # Save the file
5936: if (!open(FH,'>'.$source)) {
5937: &Apache::lonnet::logthis('Failed to create '.$source);
5938: return (&mt('Failed to create file'));
5939: }
5940: if ($action eq 'upload') {
5941: if (!print FH ($env{'form.'.$formname})) {
5942: &Apache::lonnet::logthis('Failed to write to '.$source);
5943: return (&mt('Failed to write file'));
5944: }
5945: } else {
5946: my $original = &Apache::lonnet::filelocation('',$formname);
5947: if(!copy($original,$source)) {
5948: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
5949: return (&mt('Failed to write file'));
5950: }
5951: }
5952: close(FH);
5953: chmod(0660, $source); # Permissions to rw-rw---.
5954:
5955: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
5956: my $copyfile=$targetdir.'/'.$file;
5957:
5958: my @parts=split(/\//,$targetdir);
5959: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
5960: for (my $count=5;$count<=$#parts;$count++) {
5961: $path.="/$parts[$count]";
5962: if (!-e $path) {
5963: print $logfile "\nCreating directory ".$path;
5964: mkdir($path,02770);
5965: }
5966: }
5967: my $versionresult;
5968: if (-e $copyfile) {
5969: $versionresult = &logo_versioning($targetdir,$file,$logfile);
5970: } else {
5971: $versionresult = 'ok';
5972: }
5973: if ($versionresult eq 'ok') {
5974: if (copy($source,$copyfile)) {
5975: print $logfile "\nCopied original source to ".$copyfile."\n";
5976: $output = 'ok';
5977: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 5978: push(@{$modified_urls},[$copyfile,$source]);
5979: my $metaoutput =
5980: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
5981: unless ($registered_cleanup) {
5982: my $handlers = $r->get_handlers('PerlCleanupHandler');
5983: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5984: $registered_cleanup=1;
5985: }
1.9 raeburn 5986: } else {
5987: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
5988: $output = &mt('Failed to copy file to RES space').", $!";
5989: }
5990: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5991: my $inputfile = $filepath.'/'.$file;
5992: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 5993: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5994: if ($fullwidth ne '' && $fullheight ne '') {
5995: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5996: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5997: system("convert -sample $thumbsize $inputfile $outfile");
5998: chmod(0660, $filepath.'/tn-'.$file);
5999: if (-e $outfile) {
6000: my $copyfile=$targetdir.'/tn-'.$file;
6001: if (copy($outfile,$copyfile)) {
6002: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 6003: my $thumb_metaoutput =
6004: &write_metadata($dom,$confname,$formname,
6005: $targetdir,'tn-'.$file,$logfile);
6006: push(@{$modified_urls},[$copyfile,$outfile]);
6007: unless ($registered_cleanup) {
6008: my $handlers = $r->get_handlers('PerlCleanupHandler');
6009: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6010: $registered_cleanup=1;
6011: }
1.16 raeburn 6012: } else {
6013: print $logfile "\nUnable to write ".$copyfile.
6014: ':'.$!."\n";
6015: }
6016: }
1.9 raeburn 6017: }
6018: }
6019: }
6020: } else {
6021: $output = $versionresult;
6022: }
6023: }
6024: return ($output,$logourl);
6025: }
6026:
6027: sub logo_versioning {
6028: my ($targetdir,$file,$logfile) = @_;
6029: my $target = $targetdir.'/'.$file;
6030: my ($maxversion,$fn,$extn,$output);
6031: $maxversion = 0;
6032: if ($file =~ /^(.+)\.(\w+)$/) {
6033: $fn=$1;
6034: $extn=$2;
6035: }
6036: opendir(DIR,$targetdir);
6037: while (my $filename=readdir(DIR)) {
6038: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
6039: $maxversion=($1>$maxversion)?$1:$maxversion;
6040: }
6041: }
6042: $maxversion++;
6043: print $logfile "\nCreating old version ".$maxversion."\n";
6044: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
6045: if (copy($target,$copyfile)) {
6046: print $logfile "Copied old target to ".$copyfile."\n";
6047: $copyfile=$copyfile.'.meta';
6048: if (copy($target.'.meta',$copyfile)) {
6049: print $logfile "Copied old target metadata to ".$copyfile."\n";
6050: $output = 'ok';
6051: } else {
6052: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
6053: $output = &mt('Failed to copy old meta').", $!, ";
6054: }
6055: } else {
6056: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
6057: $output = &mt('Failed to copy old target').", $!, ";
6058: }
6059: return $output;
6060: }
6061:
6062: sub write_metadata {
6063: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
6064: my (%metadatafields,%metadatakeys,$output);
6065: $metadatafields{'title'}=$formname;
6066: $metadatafields{'creationdate'}=time;
6067: $metadatafields{'lastrevisiondate'}=time;
6068: $metadatafields{'copyright'}='public';
6069: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
6070: $env{'user.domain'};
6071: $metadatafields{'authorspace'}=$confname.':'.$dom;
6072: $metadatafields{'domain'}=$dom;
6073: {
6074: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
6075: my $mfh;
1.155 raeburn 6076: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 6077: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 6078: unless ($_=~/\./) {
6079: my $unikey=$_;
6080: $unikey=~/^([A-Za-z]+)/;
6081: my $tag=$1;
6082: $tag=~tr/A-Z/a-z/;
6083: print $mfh "\n\<$tag";
6084: foreach (split(/\,/,$metadatakeys{$unikey})) {
6085: my $value=$metadatafields{$unikey.'.'.$_};
6086: $value=~s/\"/\'\'/g;
6087: print $mfh ' '.$_.'="'.$value.'"';
6088: }
6089: print $mfh '>'.
6090: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
6091: .'</'.$tag.'>';
6092: }
6093: }
6094: $output = 'ok';
6095: print $logfile "\nWrote metadata";
6096: close($mfh);
6097: } else {
6098: print $logfile "\nFailed to open metadata file";
1.9 raeburn 6099: $output = &mt('Could not write metadata');
6100: }
6101: }
1.155 raeburn 6102: return $output;
6103: }
6104:
6105: sub notifysubscribed {
6106: foreach my $targetsource (@{$modified_urls}){
6107: next unless (ref($targetsource) eq 'ARRAY');
6108: my ($target,$source)=@{$targetsource};
6109: if ($source ne '') {
6110: if (open(my $logfh,'>>'.$source.'.log')) {
6111: print $logfh "\nCleanup phase: Notifications\n";
6112: my @subscribed=&subscribed_hosts($target);
6113: foreach my $subhost (@subscribed) {
6114: print $logfh "\nNotifying host ".$subhost.':';
6115: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
6116: print $logfh $reply;
6117: }
6118: my @subscribedmeta=&subscribed_hosts("$target.meta");
6119: foreach my $subhost (@subscribedmeta) {
6120: print $logfh "\nNotifying host for metadata only ".$subhost.':';
6121: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
6122: $subhost);
6123: print $logfh $reply;
6124: }
6125: print $logfh "\n============ Done ============\n";
1.160 raeburn 6126: close($logfh);
1.155 raeburn 6127: }
6128: }
6129: }
6130: return OK;
6131: }
6132:
6133: sub subscribed_hosts {
6134: my ($target) = @_;
6135: my @subscribed;
6136: if (open(my $fh,"<$target.subscription")) {
6137: while (my $subline=<$fh>) {
6138: if ($subline =~ /^($match_lonid):/) {
6139: my $host = $1;
6140: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
6141: unless (grep(/^\Q$host\E$/,@subscribed)) {
6142: push(@subscribed,$host);
6143: }
6144: }
6145: }
6146: }
6147: }
6148: return @subscribed;
1.9 raeburn 6149: }
6150:
6151: sub check_switchserver {
6152: my ($dom,$confname) = @_;
6153: my ($allowed,$switchserver);
6154: my $home = &Apache::lonnet::homeserver($confname,$dom);
6155: if ($home eq 'no_host') {
6156: $home = &Apache::lonnet::domain($dom,'primary');
6157: }
6158: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 6159: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
6160: if (!$allowed) {
1.180 raeburn 6161: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 6162: }
6163: return $switchserver;
6164: }
6165:
1.1 raeburn 6166: sub modify_quotas {
1.216 raeburn 6167: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 6168: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 6169: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
6170: $author_ok,$switchserver,$errors);
1.86 raeburn 6171: if ($action eq 'quotas') {
6172: $context = 'tools';
1.163 raeburn 6173: } else {
1.86 raeburn 6174: $context = $action;
6175: }
6176: if ($context eq 'requestcourses') {
1.216 raeburn 6177: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 6178: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 6179: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
6180: %titles = &courserequest_titles();
6181: $toolregexp = join('|',@usertools);
6182: %conditions = &courserequest_conditions();
1.216 raeburn 6183: $confname = $dom.'-domainconfig';
6184: my $servadm = $r->dir_config('lonAdmEMail');
6185: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.163 raeburn 6186: } elsif ($context eq 'requestauthor') {
6187: @usertools = ('author');
6188: %titles = &authorrequest_titles();
1.86 raeburn 6189: } else {
1.162 raeburn 6190: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 6191: %titles = &tool_titles();
1.86 raeburn 6192: }
1.212 raeburn 6193: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 6194: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6195: foreach my $key (keys(%env)) {
1.101 raeburn 6196: if ($context eq 'requestcourses') {
6197: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
6198: my $item = $1;
6199: my $type = $2;
6200: if ($type =~ /^limit_(.+)/) {
6201: $limithash{$item}{$1} = $env{$key};
6202: } else {
6203: $confhash{$item}{$type} = $env{$key};
6204: }
6205: }
1.163 raeburn 6206: } elsif ($context eq 'requestauthor') {
6207: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
6208: $confhash{$1} = $env{$key};
6209: }
1.101 raeburn 6210: } else {
1.86 raeburn 6211: if ($key =~ /^form\.quota_(.+)$/) {
6212: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 6213: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
6214: $confhash{'authorquota'}{$1} = $env{$key};
6215: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 6216: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
6217: }
1.72 raeburn 6218: }
6219: }
1.163 raeburn 6220: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 ! raeburn 6221: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 6222: @approvalnotify = sort(@approvalnotify);
6223: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.218 raeburn 6224: my @crstypes = ('official','unofficial','community','textbook');
6225: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
6226: foreach my $type (@hasuniquecode) {
6227: if (grep(/^\Q$type\E$/,@crstypes)) {
6228: $confhash{'uniquecode'}{$type} = 1;
6229: }
1.216 raeburn 6230: }
6231: my ($newbook,@allpos);
6232: if ($context eq 'requestcourses') {
6233: if ($env{'form.addbook'}) {
6234: if (($env{'form.addbook_cnum'} =~ /^$match_courseid$/) &&
6235: ($env{'form.addbook_cdom'} =~ /^$match_domain$/)) {
6236: if (&Apache::lonnet::homeserver($env{'form.addbook_cnum'},
6237: $env{'form.addbook_cdom'}) eq 'no_host') {
6238: $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
6239: '</span></li>';
6240: } else {
6241: $newbook = $env{'form.addbook_cdom'}.'_'.$env{'form.addbook_cnum'};
6242: my $position = $env{'form.addbook_pos'};
6243: $position =~ s/\D+//g;
6244: if ($position ne '') {
6245: $allpos[$position] = $newbook;
6246: }
6247: }
6248: } else {
6249: $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
6250: '</span></li>';
6251: }
6252: }
6253: }
1.102 raeburn 6254: if (ref($domconfig{$action}) eq 'HASH') {
6255: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
6256: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
6257: $changes{'notify'}{'approval'} = 1;
6258: }
6259: } else {
1.144 raeburn 6260: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6261: $changes{'notify'}{'approval'} = 1;
6262: }
6263: }
1.218 raeburn 6264: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
6265: if (ref($confhash{'uniquecode'}) eq 'HASH') {
6266: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
6267: unless ($confhash{'uniquecode'}{$crstype}) {
6268: $changes{'uniquecode'} = 1;
6269: }
6270: }
6271: unless ($changes{'uniquecode'}) {
6272: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
6273: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
6274: $changes{'uniquecode'} = 1;
6275: }
6276: }
6277: }
6278: } else {
6279: $changes{'uniquecode'} = 1;
6280: }
6281: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
6282: $changes{'uniquecode'} = 1;
1.216 raeburn 6283: }
6284: if ($context eq 'requestcourses') {
6285: if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
6286: my %deletions;
6287: my @todelete = &Apache::loncommon::get_env_multiple('form.book_del');
6288: if (@todelete) {
6289: map { $deletions{$_} = 1; } @todelete;
6290: }
6291: my %imgdeletions;
6292: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.book_image_del');
6293: if (@todeleteimages) {
6294: map { $imgdeletions{$_} = 1; } @todeleteimages;
6295: }
6296: my $maxnum = $env{'form.book_maxnum'};
6297: for (my $i=0; $i<=$maxnum; $i++) {
6298: my $key = $env{'form.book_id_'.$i};
6299: if (ref($domconfig{$action}{'textbooks'}{$key}) eq 'HASH') {
6300: if ($deletions{$key}) {
6301: if ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
6302: #FIXME need to obsolete item in RES space
6303: }
6304: next;
6305: } else {
6306: my $newpos = $env{'form.'.$key};
6307: $newpos =~ s/\D+//g;
6308: foreach my $item ('subject','title','author') {
6309: $confhash{'textbooks'}{$key}{$item} = $env{'form.book_'.$item.'_'.$i};
6310: if ($domconfig{$action}{'textbooks'}{$key}{$item} ne $confhash{'textbooks'}{$key}{$item}) {
6311: $changes{'textbooks'}{$key} = 1;
6312: }
6313: }
6314: $allpos[$newpos] = $key;
6315: }
6316: if ($imgdeletions{$key}) {
6317: $changes{'textbooks'}{$key} = 1;
6318: #FIXME need to obsolete item in RES space
6319: } elsif ($env{'form.book_image_'.$i.'.filename'}) {
6320: my ($cdom,$cnum) = split(/_/,$key);
6321: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,'book_image_'.$i,
6322: $cdom,$cnum,$configuserok,
6323: $switchserver,$author_ok);
6324: if ($imgurl) {
6325: $confhash{'textbooks'}{$key}{'image'} = $imgurl;
6326: $changes{'textbooks'}{$key} = 1;
6327: }
6328: if ($error) {
6329: &Apache::lonnet::logthis($error);
6330: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6331: }
6332: } elsif ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
6333: $confhash{'textbooks'}{$key}{'image'} =
6334: $domconfig{$action}{'textbooks'}{$key}{'image'};
6335: }
6336: }
6337: }
6338: }
6339: }
1.102 raeburn 6340: } else {
1.144 raeburn 6341: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6342: $changes{'notify'}{'approval'} = 1;
6343: }
1.218 raeburn 6344: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 6345: $changes{'uniquecode'} = 1;
6346: }
6347: }
6348: if ($context eq 'requestcourses') {
6349: if ($newbook) {
6350: $changes{'textbooks'}{$newbook} = 1;
6351: foreach my $item ('subject','title','author') {
6352: $env{'form.addbook_'.$item} =~ s/(`)/'/g;
6353: if ($env{'form.addbook_'.$item}) {
6354: $confhash{'textbooks'}{$newbook}{$item} = $env{'form.addbook_'.$item};
6355: }
6356: }
6357: if ($env{'form.addbook_image.filename'} ne '') {
6358: my ($cdom,$cnum) = split(/_/,$newbook);
6359: my ($imageurl,$error) =
6360: &process_textbook_image($r,$dom,$confname,'addbook_image',$cdom,$cnum,$configuserok,
6361: $switchserver,$author_ok);
6362: if ($imageurl) {
6363: $confhash{'textbooks'}{$newbook}{'image'} = $imageurl;
6364: }
6365: if ($error) {
6366: &Apache::lonnet::logthis($error);
6367: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6368: }
6369: }
6370: }
6371: if (@allpos > 0) {
6372: my $idx = 0;
6373: foreach my $item (@allpos) {
6374: if ($item ne '') {
6375: $confhash{'textbooks'}{$item}{'order'} = $idx;
6376: if (ref($domconfig{$action}) eq 'HASH') {
6377: if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
6378: if (ref($domconfig{$action}{'textbooks'}{$item}) eq 'HASH') {
6379: if ($domconfig{$action}{'textbooks'}{$item}{'order'} ne $idx) {
6380: $changes{'textbooks'}{$item} = 1;
6381: }
6382: }
6383: }
6384: }
6385: $idx ++;
6386: }
6387: }
6388: }
1.102 raeburn 6389: }
6390: } else {
1.86 raeburn 6391: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 6392: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 6393: }
1.72 raeburn 6394: foreach my $item (@usertools) {
6395: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 6396: my $unset;
1.101 raeburn 6397: if ($context eq 'requestcourses') {
1.104 raeburn 6398: $unset = '0';
6399: if ($type eq '_LC_adv') {
6400: $unset = '';
6401: }
1.101 raeburn 6402: if ($confhash{$item}{$type} eq 'autolimit') {
6403: $confhash{$item}{$type} .= '=';
6404: unless ($limithash{$item}{$type} =~ /\D/) {
6405: $confhash{$item}{$type} .= $limithash{$item}{$type};
6406: }
6407: }
1.163 raeburn 6408: } elsif ($context eq 'requestauthor') {
6409: $unset = '0';
6410: if ($type eq '_LC_adv') {
6411: $unset = '';
6412: }
1.72 raeburn 6413: } else {
1.101 raeburn 6414: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
6415: $confhash{$item}{$type} = 1;
6416: } else {
6417: $confhash{$item}{$type} = 0;
6418: }
1.72 raeburn 6419: }
1.86 raeburn 6420: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 6421: if ($action eq 'requestauthor') {
6422: if ($domconfig{$action}{$type} ne $confhash{$type}) {
6423: $changes{$type} = 1;
6424: }
6425: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 6426: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
6427: $changes{$item}{$type} = 1;
6428: }
6429: } else {
6430: if ($context eq 'requestcourses') {
1.104 raeburn 6431: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 6432: $changes{$item}{$type} = 1;
6433: }
6434: } else {
6435: if (!$confhash{$item}{$type}) {
6436: $changes{$item}{$type} = 1;
6437: }
6438: }
6439: }
6440: } else {
6441: if ($context eq 'requestcourses') {
1.104 raeburn 6442: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 6443: $changes{$item}{$type} = 1;
6444: }
1.163 raeburn 6445: } elsif ($context eq 'requestauthor') {
6446: if ($confhash{$type} ne $unset) {
6447: $changes{$type} = 1;
6448: }
1.72 raeburn 6449: } else {
6450: if (!$confhash{$item}{$type}) {
6451: $changes{$item}{$type} = 1;
6452: }
6453: }
6454: }
1.1 raeburn 6455: }
6456: }
1.163 raeburn 6457: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 6458: if (ref($domconfig{'quotas'}) eq 'HASH') {
6459: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
6460: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
6461: if (exists($confhash{'defaultquota'}{$key})) {
6462: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
6463: $changes{'defaultquota'}{$key} = 1;
6464: }
6465: } else {
6466: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 6467: }
6468: }
1.86 raeburn 6469: } else {
6470: foreach my $key (keys(%{$domconfig{'quotas'}})) {
6471: if (exists($confhash{'defaultquota'}{$key})) {
6472: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
6473: $changes{'defaultquota'}{$key} = 1;
6474: }
6475: } else {
6476: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 6477: }
1.1 raeburn 6478: }
6479: }
1.197 raeburn 6480: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
6481: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
6482: if (exists($confhash{'authorquota'}{$key})) {
6483: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
6484: $changes{'authorquota'}{$key} = 1;
6485: }
6486: } else {
6487: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
6488: }
6489: }
6490: }
1.1 raeburn 6491: }
1.86 raeburn 6492: if (ref($confhash{'defaultquota'}) eq 'HASH') {
6493: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
6494: if (ref($domconfig{'quotas'}) eq 'HASH') {
6495: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
6496: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
6497: $changes{'defaultquota'}{$key} = 1;
6498: }
6499: } else {
6500: if (!exists($domconfig{'quotas'}{$key})) {
6501: $changes{'defaultquota'}{$key} = 1;
6502: }
1.72 raeburn 6503: }
6504: } else {
1.86 raeburn 6505: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 6506: }
1.1 raeburn 6507: }
6508: }
1.197 raeburn 6509: if (ref($confhash{'authorquota'}) eq 'HASH') {
6510: foreach my $key (keys(%{$confhash{'authorquota'}})) {
6511: if (ref($domconfig{'quotas'}) eq 'HASH') {
6512: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
6513: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
6514: $changes{'authorquota'}{$key} = 1;
6515: }
6516: } else {
6517: $changes{'authorquota'}{$key} = 1;
6518: }
6519: } else {
6520: $changes{'authorquota'}{$key} = 1;
6521: }
6522: }
6523: }
1.1 raeburn 6524: }
1.72 raeburn 6525:
1.163 raeburn 6526: if ($context eq 'requestauthor') {
6527: $domdefaults{'requestauthor'} = \%confhash;
6528: } else {
6529: foreach my $key (keys(%confhash)) {
1.216 raeburn 6530: unless (($context eq 'requestcourses') && ($key eq 'textbooks')) {
6531: $domdefaults{$key} = $confhash{$key};
6532: }
1.163 raeburn 6533: }
1.72 raeburn 6534: }
1.163 raeburn 6535:
1.1 raeburn 6536: my %quotahash = (
1.86 raeburn 6537: $action => { %confhash }
1.1 raeburn 6538: );
6539: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
6540: $dom);
6541: if ($putresult eq 'ok') {
6542: if (keys(%changes) > 0) {
1.72 raeburn 6543: my $cachetime = 24*60*60;
6544: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 6545: if (ref($lastactref) eq 'HASH') {
6546: $lastactref->{'domdefaults'} = 1;
6547: }
1.1 raeburn 6548: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 6549: unless (($context eq 'requestcourses') ||
1.163 raeburn 6550: ($context eq 'requestauthor')) {
1.86 raeburn 6551: if (ref($changes{'defaultquota'}) eq 'HASH') {
6552: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
6553: foreach my $type (@{$types},'default') {
6554: if (defined($changes{'defaultquota'}{$type})) {
6555: my $typetitle = $usertypes->{$type};
6556: if ($type eq 'default') {
6557: $typetitle = $othertitle;
6558: }
1.213 raeburn 6559: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 6560: }
6561: }
1.86 raeburn 6562: $resulttext .= '</ul></li>';
1.72 raeburn 6563: }
1.197 raeburn 6564: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 6565: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 6566: foreach my $type (@{$types},'default') {
6567: if (defined($changes{'authorquota'}{$type})) {
6568: my $typetitle = $usertypes->{$type};
6569: if ($type eq 'default') {
6570: $typetitle = $othertitle;
6571: }
1.213 raeburn 6572: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 6573: }
6574: }
6575: $resulttext .= '</ul></li>';
6576: }
1.72 raeburn 6577: }
1.80 raeburn 6578: my %newenv;
1.72 raeburn 6579: foreach my $item (@usertools) {
1.163 raeburn 6580: my (%haschgs,%inconf);
6581: if ($context eq 'requestauthor') {
6582: %haschgs = %changes;
1.210 raeburn 6583: %inconf = %confhash;
1.163 raeburn 6584: } else {
6585: if (ref($changes{$item}) eq 'HASH') {
6586: %haschgs = %{$changes{$item}};
6587: }
6588: if (ref($confhash{$item}) eq 'HASH') {
6589: %inconf = %{$confhash{$item}};
6590: }
6591: }
6592: if (keys(%haschgs) > 0) {
1.80 raeburn 6593: my $newacc =
6594: &Apache::lonnet::usertools_access($env{'user.name'},
6595: $env{'user.domain'},
1.86 raeburn 6596: $item,'reload',$context);
1.210 raeburn 6597: if (($context eq 'requestcourses') ||
1.163 raeburn 6598: ($context eq 'requestauthor')) {
1.108 raeburn 6599: if ($env{'environment.canrequest.'.$item} ne $newacc) {
6600: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 6601: }
6602: } else {
6603: if ($env{'environment.availabletools.'.$item} ne $newacc) {
6604: $newenv{'environment.availabletools.'.$item} = $newacc;
6605: }
1.80 raeburn 6606: }
1.163 raeburn 6607: unless ($context eq 'requestauthor') {
6608: $resulttext .= '<li>'.$titles{$item}.'<ul>';
6609: }
1.72 raeburn 6610: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 6611: if ($haschgs{$type}) {
1.72 raeburn 6612: my $typetitle = $usertypes->{$type};
6613: if ($type eq 'default') {
6614: $typetitle = $othertitle;
6615: } elsif ($type eq '_LC_adv') {
6616: $typetitle = 'LON-CAPA Advanced Users';
6617: }
1.163 raeburn 6618: if ($inconf{$type}) {
1.101 raeburn 6619: if ($context eq 'requestcourses') {
6620: my $cond;
1.163 raeburn 6621: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 6622: if ($1 eq '') {
6623: $cond = &mt('(Automatic processing of any request).');
6624: } else {
6625: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
6626: }
6627: } else {
1.163 raeburn 6628: $cond = $conditions{$inconf{$type}};
1.101 raeburn 6629: }
6630: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 6631: } elsif ($context eq 'requestauthor') {
6632: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
6633: $titles{$inconf{$type}},$typetitle);
6634:
1.101 raeburn 6635: } else {
6636: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
6637: }
1.72 raeburn 6638: } else {
1.104 raeburn 6639: if ($type eq '_LC_adv') {
1.163 raeburn 6640: if ($inconf{$type} eq '0') {
1.104 raeburn 6641: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6642: } else {
6643: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
6644: }
6645: } else {
6646: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6647: }
1.72 raeburn 6648: }
6649: }
1.26 raeburn 6650: }
1.163 raeburn 6651: unless ($context eq 'requestauthor') {
6652: $resulttext .= '</ul></li>';
6653: }
1.26 raeburn 6654: }
1.1 raeburn 6655: }
1.163 raeburn 6656: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 6657: if (ref($changes{'notify'}) eq 'HASH') {
6658: if ($changes{'notify'}{'approval'}) {
6659: if (ref($confhash{'notify'}) eq 'HASH') {
6660: if ($confhash{'notify'}{'approval'}) {
6661: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
6662: } else {
1.163 raeburn 6663: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 6664: }
6665: }
6666: }
6667: }
6668: }
1.216 raeburn 6669: if ($action eq 'requestcourses') {
6670: my @offon = ('off','on');
6671: if ($changes{'uniquecode'}) {
1.218 raeburn 6672: if (ref($confhash{'uniquecode'}) eq 'HASH') {
6673: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
6674: $resulttext .= '<li>'.
6675: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
6676: '</li>';
6677: } else {
6678: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
6679: '</li>';
6680: }
1.216 raeburn 6681: }
6682: if (ref($changes{'textbooks'}) eq 'HASH') {
6683: $resulttext .= '<li>'.&mt('Available textbooks updated').'<ul>';
6684: foreach my $key (sort(keys(%{$changes{'textbooks'}}))) {
6685: my %coursehash = &Apache::lonnet::coursedescription($key);
6686: my $coursetitle = $coursehash{'description'};
6687: my $position = $confhash{'textbooks'}{$key}{'order'} + 1;
6688: $resulttext .= '<li>';
6689: foreach my $item ('subject','title','author') {
6690: my $name = $item.':';
6691: $name =~ s/^(\w)/\U$1/;
6692: $resulttext .= &mt($name).' '.$confhash{'textbooks'}{$key}{$item}.'<br />';
6693: }
6694: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
6695: if ($confhash{'textbooks'}{$key}{'image'}) {
6696: $resulttext .= ' '.&mt('Image: [_1]',
6697: '<img src="'.$confhash{'textbooks'}{$key}{'image'}.'"'.
6698: ' alt="Textbook cover" />').'<br />';
6699: }
6700: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
6701: }
6702: $resulttext .= '</ul></li>';
6703: }
6704: }
1.1 raeburn 6705: $resulttext .= '</ul>';
1.80 raeburn 6706: if (keys(%newenv)) {
6707: &Apache::lonnet::appenv(\%newenv);
6708: }
1.1 raeburn 6709: } else {
1.86 raeburn 6710: if ($context eq 'requestcourses') {
6711: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 6712: } elsif ($context eq 'requestauthor') {
6713: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 6714: } else {
1.90 weissno 6715: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 6716: }
1.1 raeburn 6717: }
6718: } else {
1.11 albertel 6719: $resulttext = '<span class="LC_error">'.
6720: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6721: }
1.216 raeburn 6722: if ($errors) {
6723: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
6724: '<ul>'.$errors.'</ul></p>';
6725: }
1.3 raeburn 6726: return $resulttext;
1.1 raeburn 6727: }
6728:
1.216 raeburn 6729: sub process_textbook_image {
6730: my ($r,$dom,$confname,$caller,$cdom,$cnum,$configuserok,$switchserver,$author_ok) = @_;
6731: my $filename = $env{'form.'.$caller.'.filename'};
6732: my ($error,$url);
6733: my ($width,$height) = (50,50);
6734: if ($configuserok eq 'ok') {
6735: if ($switchserver) {
6736: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
6737: $switchserver);
6738: } elsif ($author_ok eq 'ok') {
6739: my ($result,$imageurl) =
6740: &publishlogo($r,'upload',$caller,$dom,$confname,
6741: "textbooks/$dom/$cnum/cover",$width,$height);
6742: if ($result eq 'ok') {
6743: $url = $imageurl;
6744: } else {
6745: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
6746: }
6747: } else {
6748: $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);
6749: }
6750: } else {
6751: $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);
6752: }
6753: return ($url,$error);
6754: }
6755:
1.3 raeburn 6756: sub modify_autoenroll {
1.205 raeburn 6757: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 6758: my ($resulttext,%changes);
6759: my %currautoenroll;
6760: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6761: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
6762: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
6763: }
6764: }
6765: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
6766: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 6767: sender => 'Sender for notification messages',
6768: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 6769: my @offon = ('off','on');
1.17 raeburn 6770: my $sender_uname = $env{'form.sender_uname'};
6771: my $sender_domain = $env{'form.sender_domain'};
6772: if ($sender_domain eq '') {
6773: $sender_uname = '';
6774: } elsif ($sender_uname eq '') {
6775: $sender_domain = '';
6776: }
1.129 raeburn 6777: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 6778: my %autoenrollhash = (
1.129 raeburn 6779: autoenroll => { 'run' => $env{'form.autoenroll_run'},
6780: 'sender_uname' => $sender_uname,
6781: 'sender_domain' => $sender_domain,
6782: 'co-owners' => $coowners,
1.1 raeburn 6783: }
6784: );
1.4 raeburn 6785: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
6786: $dom);
1.1 raeburn 6787: if ($putresult eq 'ok') {
6788: if (exists($currautoenroll{'run'})) {
6789: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
6790: $changes{'run'} = 1;
6791: }
6792: } elsif ($autorun) {
6793: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 6794: $changes{'run'} = 1;
1.1 raeburn 6795: }
6796: }
1.17 raeburn 6797: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 6798: $changes{'sender'} = 1;
6799: }
1.17 raeburn 6800: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 6801: $changes{'sender'} = 1;
6802: }
1.129 raeburn 6803: if ($currautoenroll{'co-owners'} ne '') {
6804: if ($currautoenroll{'co-owners'} ne $coowners) {
6805: $changes{'coowners'} = 1;
6806: }
6807: } elsif ($coowners) {
6808: $changes{'coowners'} = 1;
6809: }
1.1 raeburn 6810: if (keys(%changes) > 0) {
6811: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 6812: if ($changes{'run'}) {
1.1 raeburn 6813: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
6814: }
6815: if ($changes{'sender'}) {
1.17 raeburn 6816: if ($sender_uname eq '' || $sender_domain eq '') {
6817: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
6818: } else {
6819: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
6820: }
1.1 raeburn 6821: }
1.129 raeburn 6822: if ($changes{'coowners'}) {
6823: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
6824: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 6825: if (ref($lastactref) eq 'HASH') {
6826: $lastactref->{'domainconfig'} = 1;
6827: }
1.129 raeburn 6828: }
1.1 raeburn 6829: $resulttext .= '</ul>';
6830: } else {
6831: $resulttext = &mt('No changes made to auto-enrollment settings');
6832: }
6833: } else {
1.11 albertel 6834: $resulttext = '<span class="LC_error">'.
6835: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6836: }
1.3 raeburn 6837: return $resulttext;
1.1 raeburn 6838: }
6839:
6840: sub modify_autoupdate {
1.3 raeburn 6841: my ($dom,%domconfig) = @_;
1.1 raeburn 6842: my ($resulttext,%currautoupdate,%fields,%changes);
6843: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
6844: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
6845: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
6846: }
6847: }
6848: my @offon = ('off','on');
6849: my %title = &Apache::lonlocal::texthash (
6850: run => 'Auto-update:',
6851: classlists => 'Updates to user information in classlists?'
6852: );
1.44 raeburn 6853: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6854: my %fieldtitles = &Apache::lonlocal::texthash (
6855: id => 'Student/Employee ID',
1.20 raeburn 6856: permanentemail => 'E-mail address',
1.1 raeburn 6857: lastname => 'Last Name',
6858: firstname => 'First Name',
6859: middlename => 'Middle Name',
1.132 raeburn 6860: generation => 'Generation',
1.1 raeburn 6861: );
1.142 raeburn 6862: $othertitle = &mt('All users');
1.1 raeburn 6863: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 6864: $othertitle = &mt('Other users');
1.1 raeburn 6865: }
6866: foreach my $key (keys(%env)) {
6867: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 6868: my ($usertype,$item) = ($1,$2);
6869: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
6870: if ($usertype eq 'default') {
6871: push(@{$fields{$1}},$2);
6872: } elsif (ref($types) eq 'ARRAY') {
6873: if (grep(/^\Q$usertype\E$/,@{$types})) {
6874: push(@{$fields{$1}},$2);
6875: }
6876: }
6877: }
1.1 raeburn 6878: }
6879: }
1.131 raeburn 6880: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
6881: @lockablenames = sort(@lockablenames);
6882: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
6883: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6884: if (@changed) {
6885: $changes{'lockablenames'} = 1;
6886: }
6887: } else {
6888: if (@lockablenames) {
6889: $changes{'lockablenames'} = 1;
6890: }
6891: }
1.1 raeburn 6892: my %updatehash = (
6893: autoupdate => { run => $env{'form.autoupdate_run'},
6894: classlists => $env{'form.classlists'},
6895: fields => {%fields},
1.131 raeburn 6896: lockablenames => \@lockablenames,
1.1 raeburn 6897: }
6898: );
6899: foreach my $key (keys(%currautoupdate)) {
6900: if (($key eq 'run') || ($key eq 'classlists')) {
6901: if (exists($updatehash{autoupdate}{$key})) {
6902: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
6903: $changes{$key} = 1;
6904: }
6905: }
6906: } elsif ($key eq 'fields') {
6907: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 6908: foreach my $item (@{$types},'default') {
1.1 raeburn 6909: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
6910: my $change = 0;
6911: foreach my $type (@{$currautoupdate{$key}{$item}}) {
6912: if (!exists($fields{$item})) {
6913: $change = 1;
1.132 raeburn 6914: last;
1.1 raeburn 6915: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 6916: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 6917: $change = 1;
1.132 raeburn 6918: last;
1.1 raeburn 6919: }
6920: }
6921: }
6922: if ($change) {
6923: push(@{$changes{$key}},$item);
6924: }
1.26 raeburn 6925: }
1.1 raeburn 6926: }
6927: }
1.131 raeburn 6928: } elsif ($key eq 'lockablenames') {
6929: if (ref($currautoupdate{$key}) eq 'ARRAY') {
6930: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6931: if (@changed) {
6932: $changes{'lockablenames'} = 1;
6933: }
6934: } else {
6935: if (@lockablenames) {
6936: $changes{'lockablenames'} = 1;
6937: }
6938: }
6939: }
6940: }
6941: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
6942: if (@lockablenames) {
6943: $changes{'lockablenames'} = 1;
1.1 raeburn 6944: }
6945: }
1.26 raeburn 6946: foreach my $item (@{$types},'default') {
6947: if (defined($fields{$item})) {
6948: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 6949: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
6950: my $change = 0;
6951: if (ref($fields{$item}) eq 'ARRAY') {
6952: foreach my $type (@{$fields{$item}}) {
6953: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
6954: $change = 1;
6955: last;
6956: }
6957: }
6958: }
6959: if ($change) {
6960: push(@{$changes{'fields'}},$item);
6961: }
6962: } else {
1.26 raeburn 6963: push(@{$changes{'fields'}},$item);
6964: }
6965: } else {
6966: push(@{$changes{'fields'}},$item);
1.1 raeburn 6967: }
6968: }
6969: }
6970: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
6971: $dom);
6972: if ($putresult eq 'ok') {
6973: if (keys(%changes) > 0) {
6974: $resulttext = &mt('Changes made:').'<ul>';
6975: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 6976: if ($key eq 'lockablenames') {
6977: $resulttext .= '<li>';
6978: if (@lockablenames) {
6979: $usertypes->{'default'} = $othertitle;
6980: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
6981: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
6982: } else {
6983: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
6984: }
6985: $resulttext .= '</li>';
6986: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 6987: foreach my $item (@{$changes{$key}}) {
6988: my @newvalues;
6989: foreach my $type (@{$fields{$item}}) {
6990: push(@newvalues,$fieldtitles{$type});
6991: }
1.3 raeburn 6992: my $newvaluestr;
6993: if (@newvalues > 0) {
6994: $newvaluestr = join(', ',@newvalues);
6995: } else {
6996: $newvaluestr = &mt('none');
1.6 raeburn 6997: }
1.1 raeburn 6998: if ($item eq 'default') {
1.26 raeburn 6999: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 7000: } else {
1.26 raeburn 7001: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 7002: }
7003: }
7004: } else {
7005: my $newvalue;
7006: if ($key eq 'run') {
7007: $newvalue = $offon[$env{'form.autoupdate_run'}];
7008: } else {
7009: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 7010: }
1.1 raeburn 7011: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
7012: }
7013: }
7014: $resulttext .= '</ul>';
7015: } else {
1.3 raeburn 7016: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 7017: }
7018: } else {
1.11 albertel 7019: $resulttext = '<span class="LC_error">'.
7020: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7021: }
1.3 raeburn 7022: return $resulttext;
1.1 raeburn 7023: }
7024:
1.125 raeburn 7025: sub modify_autocreate {
7026: my ($dom,%domconfig) = @_;
7027: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
7028: if (ref($domconfig{'autocreate'}) eq 'HASH') {
7029: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
7030: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
7031: }
7032: }
7033: my %title= ( xml => 'Auto-creation of courses in XML course description files',
7034: req => 'Auto-creation of validated requests for official courses',
7035: xmldc => 'Identity of course creator of courses from XML files',
7036: );
7037: my @types = ('xml','req');
7038: foreach my $item (@types) {
7039: $newvals{$item} = $env{'form.autocreate_'.$item};
7040: $newvals{$item} =~ s/\D//g;
7041: $newvals{$item} = 0 if ($newvals{$item} eq '');
7042: }
7043: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
7044: my %domcoords = &get_active_dcs($dom);
7045: unless (exists($domcoords{$newvals{'xmldc'}})) {
7046: $newvals{'xmldc'} = '';
7047: }
7048: %autocreatehash = (
7049: autocreate => { xml => $newvals{'xml'},
7050: req => $newvals{'req'},
7051: }
7052: );
7053: if ($newvals{'xmldc'} ne '') {
7054: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
7055: }
7056: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
7057: $dom);
7058: if ($putresult eq 'ok') {
7059: my @items = @types;
7060: if ($newvals{'xml'}) {
7061: push(@items,'xmldc');
7062: }
7063: foreach my $item (@items) {
7064: if (exists($currautocreate{$item})) {
7065: if ($currautocreate{$item} ne $newvals{$item}) {
7066: $changes{$item} = 1;
7067: }
7068: } elsif ($newvals{$item}) {
7069: $changes{$item} = 1;
7070: }
7071: }
7072: if (keys(%changes) > 0) {
7073: my @offon = ('off','on');
7074: $resulttext = &mt('Changes made:').'<ul>';
7075: foreach my $item (@types) {
7076: if ($changes{$item}) {
7077: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 7078: $resulttext .= '<li>'.
7079: &mt("$title{$item} set to [_1]$newtxt [_2]",
7080: '<b>','</b>').
7081: '</li>';
1.125 raeburn 7082: }
7083: }
7084: if ($changes{'xmldc'}) {
7085: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
7086: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 7087: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 7088: }
7089: $resulttext .= '</ul>';
7090: } else {
7091: $resulttext = &mt('No changes made to auto-creation settings');
7092: }
7093: } else {
7094: $resulttext = '<span class="LC_error">'.
7095: &mt('An error occurred: [_1]',$putresult).'</span>';
7096: }
7097: return $resulttext;
7098: }
7099:
1.23 raeburn 7100: sub modify_directorysrch {
7101: my ($dom,%domconfig) = @_;
7102: my ($resulttext,%changes);
7103: my %currdirsrch;
7104: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
7105: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
7106: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
7107: }
7108: }
7109: my %title = ( available => 'Directory search available',
1.24 raeburn 7110: localonly => 'Other domains can search',
1.23 raeburn 7111: searchby => 'Search types',
7112: searchtypes => 'Search latitude');
7113: my @offon = ('off','on');
1.24 raeburn 7114: my @otherdoms = ('Yes','No');
1.23 raeburn 7115:
1.25 raeburn 7116: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 7117: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
7118: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
7119:
1.44 raeburn 7120: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 7121: if (keys(%{$usertypes}) == 0) {
7122: @cansearch = ('default');
7123: } else {
7124: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
7125: foreach my $type (@{$currdirsrch{'cansearch'}}) {
7126: if (!grep(/^\Q$type\E$/,@cansearch)) {
7127: push(@{$changes{'cansearch'}},$type);
7128: }
1.23 raeburn 7129: }
1.26 raeburn 7130: foreach my $type (@cansearch) {
7131: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
7132: push(@{$changes{'cansearch'}},$type);
7133: }
1.23 raeburn 7134: }
1.26 raeburn 7135: } else {
7136: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 7137: }
7138: }
7139:
7140: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
7141: foreach my $by (@{$currdirsrch{'searchby'}}) {
7142: if (!grep(/^\Q$by\E$/,@searchby)) {
7143: push(@{$changes{'searchby'}},$by);
7144: }
7145: }
7146: foreach my $by (@searchby) {
7147: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
7148: push(@{$changes{'searchby'}},$by);
7149: }
7150: }
7151: } else {
7152: push(@{$changes{'searchby'}},@searchby);
7153: }
1.25 raeburn 7154:
7155: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
7156: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
7157: if (!grep(/^\Q$type\E$/,@searchtypes)) {
7158: push(@{$changes{'searchtypes'}},$type);
7159: }
7160: }
7161: foreach my $type (@searchtypes) {
7162: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
7163: push(@{$changes{'searchtypes'}},$type);
7164: }
7165: }
7166: } else {
7167: if (exists($currdirsrch{'searchtypes'})) {
7168: foreach my $type (@searchtypes) {
7169: if ($type ne $currdirsrch{'searchtypes'}) {
7170: push(@{$changes{'searchtypes'}},$type);
7171: }
7172: }
7173: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
7174: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
7175: }
7176: } else {
7177: push(@{$changes{'searchtypes'}},@searchtypes);
7178: }
7179: }
7180:
1.23 raeburn 7181: my %dirsrch_hash = (
7182: directorysrch => { available => $env{'form.dirsrch_available'},
7183: cansearch => \@cansearch,
1.24 raeburn 7184: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 7185: searchby => \@searchby,
1.25 raeburn 7186: searchtypes => \@searchtypes,
1.23 raeburn 7187: }
7188: );
7189: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
7190: $dom);
7191: if ($putresult eq 'ok') {
7192: if (exists($currdirsrch{'available'})) {
7193: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
7194: $changes{'available'} = 1;
7195: }
7196: } else {
7197: if ($env{'form.dirsrch_available'} eq '1') {
7198: $changes{'available'} = 1;
7199: }
7200: }
1.24 raeburn 7201: if (exists($currdirsrch{'localonly'})) {
7202: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
7203: $changes{'localonly'} = 1;
7204: }
7205: } else {
7206: if ($env{'form.dirsrch_localonly'} eq '1') {
7207: $changes{'localonly'} = 1;
7208: }
7209: }
1.23 raeburn 7210: if (keys(%changes) > 0) {
7211: $resulttext = &mt('Changes made:').'<ul>';
7212: if ($changes{'available'}) {
7213: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
7214: }
1.24 raeburn 7215: if ($changes{'localonly'}) {
7216: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
7217: }
7218:
1.23 raeburn 7219: if (ref($changes{'cansearch'}) eq 'ARRAY') {
7220: my $chgtext;
1.26 raeburn 7221: if (ref($usertypes) eq 'HASH') {
7222: if (keys(%{$usertypes}) > 0) {
7223: foreach my $type (@{$types}) {
7224: if (grep(/^\Q$type\E$/,@cansearch)) {
7225: $chgtext .= $usertypes->{$type}.'; ';
7226: }
7227: }
7228: if (grep(/^default$/,@cansearch)) {
7229: $chgtext .= $othertitle;
7230: } else {
7231: $chgtext =~ s/\; $//;
7232: }
1.210 raeburn 7233: $resulttext .=
1.178 raeburn 7234: '<li>'.
7235: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
7236: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
7237: '</li>';
1.23 raeburn 7238: }
7239: }
7240: }
7241: if (ref($changes{'searchby'}) eq 'ARRAY') {
7242: my ($searchtitles,$titleorder) = &sorted_searchtitles();
7243: my $chgtext;
7244: foreach my $type (@{$titleorder}) {
7245: if (grep(/^\Q$type\E$/,@searchby)) {
7246: if (defined($searchtitles->{$type})) {
7247: $chgtext .= $searchtitles->{$type}.'; ';
7248: }
7249: }
7250: }
7251: $chgtext =~ s/\; $//;
7252: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
7253: }
1.25 raeburn 7254: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
7255: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
7256: my $chgtext;
7257: foreach my $type (@{$srchtypeorder}) {
7258: if (grep(/^\Q$type\E$/,@searchtypes)) {
7259: if (defined($srchtypes_desc->{$type})) {
7260: $chgtext .= $srchtypes_desc->{$type}.'; ';
7261: }
7262: }
7263: }
7264: $chgtext =~ s/\; $//;
1.178 raeburn 7265: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 7266: }
7267: $resulttext .= '</ul>';
7268: } else {
7269: $resulttext = &mt('No changes made to institution directory search settings');
7270: }
7271: } else {
7272: $resulttext = '<span class="LC_error">'.
1.27 raeburn 7273: &mt('An error occurred: [_1]',$putresult).'</span>';
7274: }
7275: return $resulttext;
7276: }
7277:
1.28 raeburn 7278: sub modify_contacts {
1.205 raeburn 7279: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 7280: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
7281: if (ref($domconfig{'contacts'}) eq 'HASH') {
7282: foreach my $key (keys(%{$domconfig{'contacts'}})) {
7283: $currsetting{$key} = $domconfig{'contacts'}{$key};
7284: }
7285: }
1.134 raeburn 7286: my (%others,%to,%bcc);
1.28 raeburn 7287: my @contacts = ('supportemail','adminemail');
1.102 raeburn 7288: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.203 raeburn 7289: 'requestsmail','updatesmail','idconflictsmail');
7290: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 7291: foreach my $type (@mailings) {
7292: @{$newsetting{$type}} =
7293: &Apache::loncommon::get_env_multiple('form.'.$type);
7294: foreach my $item (@contacts) {
7295: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
7296: $contacts_hash{contacts}{$type}{$item} = 1;
7297: } else {
7298: $contacts_hash{contacts}{$type}{$item} = 0;
7299: }
7300: }
7301: $others{$type} = $env{'form.'.$type.'_others'};
7302: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 7303: if ($type eq 'helpdeskmail') {
7304: $bcc{$type} = $env{'form.'.$type.'_bcc'};
7305: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
7306: }
1.28 raeburn 7307: }
7308: foreach my $item (@contacts) {
7309: $to{$item} = $env{'form.'.$item};
7310: $contacts_hash{'contacts'}{$item} = $to{$item};
7311: }
1.203 raeburn 7312: foreach my $item (@toggles) {
7313: if ($env{'form.'.$item} =~ /^(0|1)$/) {
7314: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
7315: }
7316: }
1.28 raeburn 7317: if (keys(%currsetting) > 0) {
7318: foreach my $item (@contacts) {
7319: if ($to{$item} ne $currsetting{$item}) {
7320: $changes{$item} = 1;
7321: }
7322: }
7323: foreach my $type (@mailings) {
7324: foreach my $item (@contacts) {
7325: if (ref($currsetting{$type}) eq 'HASH') {
7326: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
7327: push(@{$changes{$type}},$item);
7328: }
7329: } else {
7330: push(@{$changes{$type}},@{$newsetting{$type}});
7331: }
7332: }
7333: if ($others{$type} ne $currsetting{$type}{'others'}) {
7334: push(@{$changes{$type}},'others');
7335: }
1.134 raeburn 7336: if ($type eq 'helpdeskmail') {
7337: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
7338: push(@{$changes{$type}},'bcc');
7339: }
7340: }
1.28 raeburn 7341: }
7342: } else {
7343: my %default;
7344: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
7345: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
7346: $default{'errormail'} = 'adminemail';
7347: $default{'packagesmail'} = 'adminemail';
7348: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 7349: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 7350: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 7351: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 7352: foreach my $item (@contacts) {
7353: if ($to{$item} ne $default{$item}) {
7354: $changes{$item} = 1;
1.203 raeburn 7355: }
1.28 raeburn 7356: }
7357: foreach my $type (@mailings) {
7358: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
7359:
7360: push(@{$changes{$type}},@{$newsetting{$type}});
7361: }
7362: if ($others{$type} ne '') {
7363: push(@{$changes{$type}},'others');
1.134 raeburn 7364: }
7365: if ($type eq 'helpdeskmail') {
7366: if ($bcc{$type} ne '') {
7367: push(@{$changes{$type}},'bcc');
7368: }
7369: }
1.28 raeburn 7370: }
7371: }
1.203 raeburn 7372: foreach my $item (@toggles) {
7373: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
7374: $changes{$item} = 1;
7375: } elsif ((!$env{'form.'.$item}) &&
7376: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
7377: $changes{$item} = 1;
7378: }
7379: }
1.28 raeburn 7380: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
7381: $dom);
7382: if ($putresult eq 'ok') {
7383: if (keys(%changes) > 0) {
1.205 raeburn 7384: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7385: if (ref($lastactref) eq 'HASH') {
7386: $lastactref->{'domainconfig'} = 1;
7387: }
1.28 raeburn 7388: my ($titles,$short_titles) = &contact_titles();
7389: $resulttext = &mt('Changes made:').'<ul>';
7390: foreach my $item (@contacts) {
7391: if ($changes{$item}) {
7392: $resulttext .= '<li>'.$titles->{$item}.
7393: &mt(' set to: ').
7394: '<span class="LC_cusr_emph">'.
7395: $to{$item}.'</span></li>';
7396: }
7397: }
7398: foreach my $type (@mailings) {
7399: if (ref($changes{$type}) eq 'ARRAY') {
7400: $resulttext .= '<li>'.$titles->{$type}.': ';
7401: my @text;
7402: foreach my $item (@{$newsetting{$type}}) {
7403: push(@text,$short_titles->{$item});
7404: }
7405: if ($others{$type} ne '') {
7406: push(@text,$others{$type});
7407: }
7408: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 7409: join(', ',@text).'</span>';
7410: if ($type eq 'helpdeskmail') {
7411: if ($bcc{$type} ne '') {
7412: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
7413: }
7414: }
7415: $resulttext .= '</li>';
1.28 raeburn 7416: }
7417: }
1.203 raeburn 7418: my @offon = ('off','on');
7419: if ($changes{'reporterrors'}) {
7420: $resulttext .= '<li>'.
7421: &mt('E-mail error reports to [_1] set to "'.
7422: $offon[$env{'form.reporterrors'}].'".',
7423: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
7424: &mt('LON-CAPA core group - MSU'),600,500)).
7425: '</li>';
7426: }
7427: if ($changes{'reportupdates'}) {
7428: $resulttext .= '<li>'.
7429: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
7430: $offon[$env{'form.reportupdates'}].'".',
7431: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
7432: &mt('LON-CAPA core group - MSU'),600,500)).
7433: '</li>';
7434: }
1.28 raeburn 7435: $resulttext .= '</ul>';
7436: } else {
1.34 raeburn 7437: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 7438: }
7439: } else {
7440: $resulttext = '<span class="LC_error">'.
7441: &mt('An error occurred: [_1].',$putresult).'</span>';
7442: }
7443: return $resulttext;
7444: }
7445:
7446: sub modify_usercreation {
1.27 raeburn 7447: my ($dom,%domconfig) = @_;
1.224 ! raeburn 7448: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 7449: my $warningmsg;
1.27 raeburn 7450: if (ref($domconfig{'usercreation'}) eq 'HASH') {
7451: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 ! raeburn 7452: if ($key eq 'cancreate') {
! 7453: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
! 7454: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
! 7455: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
! 7456: ($item eq 'captcha') || ($item eq 'recaptchakeys')) {
! 7457: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
! 7458: } else {
! 7459: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
! 7460: }
! 7461: }
! 7462: }
! 7463: } elsif ($key eq 'email_rule') {
! 7464: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
! 7465: } else {
! 7466: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
! 7467: }
1.27 raeburn 7468: }
7469: }
7470: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 7471: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 ! raeburn 7472: my @contexts = ('author','course','requestcrs');
1.34 raeburn 7473: foreach my $item(@contexts) {
1.224 ! raeburn 7474: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 7475: }
1.34 raeburn 7476: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
7477: foreach my $item (@contexts) {
1.224 ! raeburn 7478: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
! 7479: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 7480: }
1.27 raeburn 7481: }
1.34 raeburn 7482: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
7483: foreach my $item (@contexts) {
1.43 raeburn 7484: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 7485: if ($cancreate{$item} ne 'any') {
7486: push(@{$changes{'cancreate'}},$item);
7487: }
7488: } else {
7489: if ($cancreate{$item} ne 'none') {
7490: push(@{$changes{'cancreate'}},$item);
7491: }
1.27 raeburn 7492: }
7493: }
7494: } else {
1.43 raeburn 7495: foreach my $item (@contexts) {
1.34 raeburn 7496: push(@{$changes{'cancreate'}},$item);
7497: }
1.27 raeburn 7498: }
1.34 raeburn 7499:
1.27 raeburn 7500: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
7501: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
7502: if (!grep(/^\Q$type\E$/,@username_rule)) {
7503: push(@{$changes{'username_rule'}},$type);
7504: }
7505: }
7506: foreach my $type (@username_rule) {
7507: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
7508: push(@{$changes{'username_rule'}},$type);
7509: }
7510: }
7511: } else {
7512: push(@{$changes{'username_rule'}},@username_rule);
7513: }
7514:
1.32 raeburn 7515: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
7516: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
7517: if (!grep(/^\Q$type\E$/,@id_rule)) {
7518: push(@{$changes{'id_rule'}},$type);
7519: }
7520: }
7521: foreach my $type (@id_rule) {
7522: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
7523: push(@{$changes{'id_rule'}},$type);
7524: }
7525: }
7526: } else {
7527: push(@{$changes{'id_rule'}},@id_rule);
7528: }
7529:
1.43 raeburn 7530: my @authen_contexts = ('author','course','domain');
1.28 raeburn 7531: my @authtypes = ('int','krb4','krb5','loc');
7532: my %authhash;
1.43 raeburn 7533: foreach my $item (@authen_contexts) {
1.28 raeburn 7534: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
7535: foreach my $auth (@authtypes) {
7536: if (grep(/^\Q$auth\E$/,@authallowed)) {
7537: $authhash{$item}{$auth} = 1;
7538: } else {
7539: $authhash{$item}{$auth} = 0;
7540: }
7541: }
7542: }
7543: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 7544: foreach my $item (@authen_contexts) {
1.28 raeburn 7545: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
7546: foreach my $auth (@authtypes) {
7547: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
7548: push(@{$changes{'authtypes'}},$item);
7549: last;
7550: }
7551: }
7552: }
7553: }
7554: } else {
1.43 raeburn 7555: foreach my $item (@authen_contexts) {
1.28 raeburn 7556: push(@{$changes{'authtypes'}},$item);
7557: }
7558: }
7559:
1.224 ! raeburn 7560: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
! 7561: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
! 7562: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
! 7563: $save_usercreate{'id_rule'} = \@id_rule;
! 7564: $save_usercreate{'username_rule'} = \@username_rule,
! 7565: $save_usercreate{'authtypes'} = \%authhash;
! 7566:
1.27 raeburn 7567: my %usercreation_hash = (
1.224 ! raeburn 7568: usercreation => \%save_usercreate,
! 7569: );
1.27 raeburn 7570:
7571: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
7572: $dom);
1.50 raeburn 7573:
1.224 ! raeburn 7574: if ($putresult eq 'ok') {
! 7575: if (keys(%changes) > 0) {
! 7576: $resulttext = &mt('Changes made:').'<ul>';
! 7577: if (ref($changes{'cancreate'}) eq 'ARRAY') {
! 7578: my %lt = &usercreation_types();
! 7579: foreach my $type (@{$changes{'cancreate'}}) {
! 7580: my $chgtext = $lt{$type}.', ';
! 7581: if ($cancreate{$type} eq 'none') {
! 7582: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
! 7583: } elsif ($cancreate{$type} eq 'any') {
! 7584: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
! 7585: } elsif ($cancreate{$type} eq 'official') {
! 7586: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
! 7587: } elsif ($cancreate{$type} eq 'unofficial') {
! 7588: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
! 7589: }
! 7590: $resulttext .= '<li>'.$chgtext.'</li>';
! 7591: }
! 7592: }
! 7593: if (ref($changes{'username_rule'}) eq 'ARRAY') {
! 7594: my ($rules,$ruleorder) =
! 7595: &Apache::lonnet::inst_userrules($dom,'username');
! 7596: my $chgtext = '<ul>';
! 7597: foreach my $type (@username_rule) {
! 7598: if (ref($rules->{$type}) eq 'HASH') {
! 7599: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
! 7600: }
! 7601: }
! 7602: $chgtext .= '</ul>';
! 7603: if (@username_rule > 0) {
! 7604: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
! 7605: } else {
! 7606: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
! 7607: }
! 7608: }
! 7609: if (ref($changes{'id_rule'}) eq 'ARRAY') {
! 7610: my ($idrules,$idruleorder) =
! 7611: &Apache::lonnet::inst_userrules($dom,'id');
! 7612: my $chgtext = '<ul>';
! 7613: foreach my $type (@id_rule) {
! 7614: if (ref($idrules->{$type}) eq 'HASH') {
! 7615: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
! 7616: }
! 7617: }
! 7618: $chgtext .= '</ul>';
! 7619: if (@id_rule > 0) {
! 7620: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
! 7621: } else {
! 7622: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
! 7623: }
! 7624: }
! 7625: my %authname = &authtype_names();
! 7626: my %context_title = &context_names();
! 7627: if (ref($changes{'authtypes'}) eq 'ARRAY') {
! 7628: my $chgtext = '<ul>';
! 7629: foreach my $type (@{$changes{'authtypes'}}) {
! 7630: my @allowed;
! 7631: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
! 7632: foreach my $auth (@authtypes) {
! 7633: if ($authhash{$type}{$auth}) {
! 7634: push(@allowed,$authname{$auth});
! 7635: }
! 7636: }
! 7637: if (@allowed > 0) {
! 7638: $chgtext .= join(', ',@allowed).'</li>';
! 7639: } else {
! 7640: $chgtext .= &mt('none').'</li>';
! 7641: }
! 7642: }
! 7643: $chgtext .= '</ul>';
! 7644: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
! 7645: $resulttext .= '</li>';
! 7646: }
! 7647: $resulttext .= '</ul>';
! 7648: } else {
! 7649: $resulttext = &mt('No changes made to user creation settings');
! 7650: }
! 7651: } else {
! 7652: $resulttext = '<span class="LC_error">'.
! 7653: &mt('An error occurred: [_1]',$putresult).'</span>';
! 7654: }
! 7655: if ($warningmsg ne '') {
! 7656: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
! 7657: }
! 7658: return $resulttext;
! 7659: }
! 7660:
! 7661: sub modify_selfcreation {
! 7662: my ($dom,%domconfig) = @_;
! 7663: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
! 7664: my (%save_usercreate,%save_usermodify);
! 7665: #
! 7666: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
! 7667: #
! 7668: if (ref($domconfig{'usercreation'}) eq 'HASH') {
! 7669: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
! 7670: if ($key eq 'cancreate') {
! 7671: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
! 7672: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
! 7673: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
! 7674: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
! 7675: ($item eq 'emailusername') || ($item eq 'notify')) {
! 7676: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
! 7677: } else {
! 7678: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
! 7679: }
! 7680: }
! 7681: }
! 7682: } elsif ($key eq 'email_rule') {
! 7683: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
! 7684: } else {
! 7685: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
! 7686: }
! 7687: }
! 7688: }
! 7689: #
! 7690: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
! 7691: #
! 7692: if (ref($domconfig{'usermodification'}) eq 'HASH') {
! 7693: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
! 7694: if ($key eq 'selfcreate') {
! 7695: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
! 7696: } else {
! 7697: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
! 7698: }
! 7699: }
! 7700: }
! 7701:
! 7702: my @contexts = ('selfcreate');
! 7703: @{$cancreate{'selfcreate'}} = ();
! 7704: %{$cancreate{'emailusername'}} = ();
! 7705: @{$cancreate{'statustocreate'}} = ();
1.50 raeburn 7706: my %selfcreatetypes = (
7707: sso => 'users authenticated by institutional single sign on',
7708: login => 'users authenticated by institutional log-in',
1.224 ! raeburn 7709: email => 'users who provide a valid e-mail address for use as username (automatic creation)',
! 7710: emailapproval => 'users who provide a valid e-mail address for use as username (queued for Domain Coordinator review)',
1.50 raeburn 7711: );
1.224 ! raeburn 7712: #
! 7713: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
! 7714: # is permitted.
! 7715: #
! 7716: foreach my $item ('login','sso','email') {
! 7717: if ($item eq 'email') {
! 7718: if ($env{'form.cancreate_email'} eq 'email') {
! 7719: push(@{$cancreate{'selfcreate'}},'email');
! 7720: } elsif ($env{'form.cancreate_email'} eq 'emailapproval') {
! 7721: push(@{$cancreate{'selfcreate'}},'emailapproval');
! 7722: }
! 7723: } else {
! 7724: if ($env{'form.cancreate_'.$item}) {
! 7725: push(@{$cancreate{'selfcreate'}},$item);
! 7726: }
! 7727: }
! 7728: }
! 7729: my (@email_rule,%userinfo,%savecaptcha);
! 7730: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
! 7731: #
! 7732: # Populate $cancreate{'emailusername'} hash ref with information types (if new user will provide data
! 7733: # value set to one), if self-creation with e-mail address permitted.
! 7734: #
! 7735: if (($env{'form.cancreate_email'} eq 'email') || ($env{'form.cancreate_email'} eq 'emailapproval')) {
! 7736: push(@contexts,'emailusername');
! 7737: map { $userinfo{$_} = 1; } &Apache::loncommon::get_env_multiple('form.canmodify_emailusername');
! 7738: if (ref($infofields) eq 'ARRAY') {
! 7739: foreach my $field (@{$infofields}) {
! 7740: if ($userinfo{$field}) {
! 7741: $cancreate{'emailusername'}{$field} = 1;
! 7742: }
! 7743: }
! 7744: }
! 7745:
! 7746: #
! 7747: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
! 7748: # queued requests for self-creation of account using e-mail address as username
! 7749: #
! 7750:
! 7751: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
! 7752: @approvalnotify = sort(@approvalnotify);
! 7753: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
! 7754: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
! 7755: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
! 7756: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
! 7757: push(@{$changes{'cancreate'}},'notify');
! 7758: }
! 7759: } else {
! 7760: if ($cancreate{'notify'}{'approval'}) {
! 7761: push(@{$changes{'cancreate'}},'notify');
! 7762: }
! 7763: }
! 7764: } elsif ($cancreate{'notify'}{'approval'}) {
! 7765: push(@{$changes{'cancreate'}},'notify');
! 7766: }
! 7767:
! 7768: #
! 7769: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
! 7770: #
! 7771: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
! 7772: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
! 7773: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
! 7774: if (@{$curr_usercreation{'email_rule'}} > 0) {
! 7775: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
! 7776: if (!grep(/^\Q$type\E$/,@email_rule)) {
! 7777: push(@{$changes{'email_rule'}},$type);
! 7778: }
! 7779: }
! 7780: }
! 7781: if (@email_rule > 0) {
! 7782: foreach my $type (@email_rule) {
! 7783: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
! 7784: push(@{$changes{'email_rule'}},$type);
! 7785: }
! 7786: }
! 7787: }
! 7788: } elsif (@email_rule > 0) {
! 7789: push(@{$changes{'email_rule'}},@email_rule);
! 7790: }
! 7791: }
! 7792: #
! 7793: # Check if domain default is set appropriately, if selef-creation of accounts is to be available for
! 7794: # institutional log-in.
! 7795: #
! 7796: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
! 7797: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
! 7798: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
! 7799: ($domdefaults{'auth_def'} eq 'localauth'))) {
! 7800: $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.').' '.
! 7801: &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.');
! 7802: }
! 7803: }
! 7804: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
! 7805: my @fields = ('lastname','firstname','middlename','generation',
! 7806: 'permanentemail','id');
! 7807: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
! 7808: #
! 7809: # Where usernames may created for institutional log-in and/or institutional single sign on:
! 7810: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
! 7811: # may self-create accounts
! 7812: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
! 7813: # which the user may supply, if institutional data is unavailable.
! 7814: #
! 7815: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
! 7816: if (ref($types) eq 'ARRAY') {
! 7817: if (@{$types} > 0) {
! 7818: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
! 7819: push(@contexts,'statustocreate');
! 7820: } else {
! 7821: undef($cancreate{'statustocreate'});
! 7822: }
! 7823: push(@{$types},'default');
! 7824: $usertypes->{'default'} = $othertitle;
! 7825: foreach my $type (@{$types}) {
! 7826: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
! 7827: foreach my $field (@fields) {
! 7828: if (grep(/^\Q$field\E$/,@modifiable)) {
! 7829: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
! 7830: } else {
! 7831: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
! 7832: }
! 7833: }
! 7834: }
! 7835: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
! 7836: foreach my $type (@{$types}) {
! 7837: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
! 7838: foreach my $field (@fields) {
! 7839: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
! 7840: $curr_usermodify{'selfcreate'}{$type}{$field}) {
! 7841: push(@{$changes{'selfcreate'}},$type);
! 7842: last;
! 7843: }
! 7844: }
! 7845: }
! 7846: }
! 7847: } else {
! 7848: foreach my $type (@{$types}) {
! 7849: push(@{$changes{'selfcreate'}},$type);
! 7850: }
! 7851: }
! 7852: }
! 7853: }
! 7854: foreach my $item (@contexts) {
! 7855: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
! 7856: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
! 7857: if (ref($cancreate{$item}) eq 'ARRAY') {
! 7858: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
! 7859: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
! 7860: push(@{$changes{'cancreate'}},$item);
! 7861: }
! 7862: }
! 7863: }
! 7864: }
! 7865: if (ref($cancreate{$item}) eq 'ARRAY') {
! 7866: foreach my $type (@{$cancreate{$item}}) {
! 7867: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
! 7868: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
! 7869: push(@{$changes{'cancreate'}},$item);
! 7870: }
! 7871: }
! 7872: }
! 7873: }
! 7874: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
! 7875: if (ref($cancreate{$item}) eq 'HASH') {
! 7876: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
! 7877: if (!$cancreate{$item}{$curr}) {
! 7878: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
! 7879: push(@{$changes{'cancreate'}},$item);
! 7880: }
! 7881: }
! 7882: }
! 7883: foreach my $field (keys(%{$cancreate{$item}})) {
! 7884: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
! 7885: print STDERR "field $field in cancreate but not in curr\n";
! 7886: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
! 7887: push(@{$changes{'cancreate'}},$item);
! 7888: }
! 7889: }
! 7890: }
! 7891: }
! 7892: } elsif ($curr_usercreation{'cancreate'}{$item}) {
! 7893: if (ref($cancreate{$item}) eq 'ARRAY') {
! 7894: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
! 7895: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
! 7896: push(@{$changes{'cancreate'}},$item);
! 7897: }
! 7898: }
! 7899: } elsif (ref($cancreate{$item}) eq 'HASH') {
! 7900: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
! 7901: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
! 7902: push(@{$changes{'cancreate'}},$item);
! 7903: }
! 7904: }
! 7905: }
! 7906: } elsif ($item eq 'emailusername') {
! 7907: if (keys(%userinfo) > 0) {
! 7908: push(@{$changes{'cancreate'}},$item);
! 7909: }
! 7910: }
! 7911: }
! 7912: #
! 7913: # Populate %save_usercreate hash with updates to self-creation configuration.
! 7914: #
! 7915: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
! 7916: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
! 7917: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
! 7918: if (ref($cancreate{'notify'}) eq 'HASH') {
! 7919: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
! 7920: }
! 7921: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
! 7922: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
! 7923: }
! 7924: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
! 7925: $save_usercreate{'emailrule'} = \@email_rule;
! 7926:
! 7927: my %userconfig_hash = (
! 7928: usercreation => \%save_usercreate,
! 7929: usermodification => \%save_usermodify,
! 7930: );
! 7931: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
! 7932: $dom);
! 7933: #
! 7934: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
! 7935: #
1.27 raeburn 7936: if ($putresult eq 'ok') {
7937: if (keys(%changes) > 0) {
7938: $resulttext = &mt('Changes made:').'<ul>';
7939: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 ! raeburn 7940: my %lt = &selfcreation_types();
1.34 raeburn 7941: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 7942: my $chgtext;
1.45 raeburn 7943: if ($type eq 'selfcreate') {
1.50 raeburn 7944: if (@{$cancreate{$type}} == 0) {
1.224 ! raeburn 7945: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 7946: } else {
1.224 ! raeburn 7947: $chgtext .= &mt('Self-creation of a new account is permitted for:').
! 7948: '<ul>';
1.50 raeburn 7949: foreach my $case (@{$cancreate{$type}}) {
7950: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
7951: }
7952: $chgtext .= '</ul>';
1.100 raeburn 7953: if (ref($cancreate{$type}) eq 'ARRAY') {
7954: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
7955: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
7956: if (@{$cancreate{'statustocreate'}} == 0) {
1.224 ! raeburn 7957: $chgtext .= '<br />'.
! 7958: '<span class="LC_warning">'.
! 7959: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
! 7960: '</span>';
1.100 raeburn 7961: }
7962: }
7963: }
7964: }
1.43 raeburn 7965: }
1.93 raeburn 7966: } elsif ($type eq 'statustocreate') {
1.96 raeburn 7967: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
7968: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
7969: if (@{$cancreate{'selfcreate'}} > 0) {
7970: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 7971: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 7972: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 ! raeburn 7973: $chgtext .= '<br />'.
! 7974: '<span class="LC_warning">'.
! 7975: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
! 7976: '</span>';
! 7977: }
1.96 raeburn 7978: } elsif (ref($usertypes) eq 'HASH') {
7979: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 7980: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
7981: } else {
7982: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
7983: }
7984: $chgtext .= '<ul>';
7985: foreach my $case (@{$cancreate{$type}}) {
7986: if ($case eq 'default') {
7987: $chgtext .= '<li>'.$othertitle.'</li>';
7988: } else {
7989: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 7990: }
7991: }
1.100 raeburn 7992: $chgtext .= '</ul>';
7993: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.224 ! raeburn 7994: $chgtext .= '<br /><span class="LC_warning">'.
! 7995: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
! 7996: '</span>';
1.100 raeburn 7997: }
7998: }
7999: } else {
8000: if (@{$cancreate{$type}} == 0) {
8001: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
8002: } else {
8003: $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 8004: }
8005: }
8006: }
1.165 raeburn 8007: } elsif ($type eq 'captcha') {
1.224 ! raeburn 8008: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 8009: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
8010: } else {
8011: my %captchas = &captcha_phrases();
1.224 ! raeburn 8012: if ($captchas{$savecaptcha{$type}}) {
! 8013: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 8014: } else {
1.210 raeburn 8015: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 8016: }
8017: }
8018: } elsif ($type eq 'recaptchakeys') {
8019: my ($privkey,$pubkey);
1.224 ! raeburn 8020: if (ref($savecaptcha{$type}) eq 'HASH') {
! 8021: $pubkey = $savecaptcha{$type}{'public'};
! 8022: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 8023: }
8024: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
8025: if (!$pubkey) {
8026: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
8027: } else {
8028: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
8029: }
8030: if (!$privkey) {
8031: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
8032: } else {
8033: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
8034: }
8035: $chgtext .= '</ul>';
1.224 ! raeburn 8036: } elsif ($type eq 'emailusername') {
! 8037: if (ref($cancreate{'emailusername'}) eq 'HASH') {
! 8038: if (keys(%{$cancreate{'emailusername'}}) > 0) {
! 8039: $chgtext .= &mt('When self-creating account with e-mail as username, user will provide the following information:').
! 8040: '<ul>';
! 8041: foreach my $field (@{$infofields}) {
! 8042: if ($cancreate{'emailusername'}{$field}) {
! 8043: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
! 8044: }
! 8045: }
! 8046: $chgtext .= '</ul>';
! 8047: } else {
! 8048: $chgtext .= &mt('When self creating account with e-mail as username, user will not provide any information besides e-mail address');
! 8049: }
! 8050: }
! 8051: } elsif ($type eq 'notify') {
! 8052: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
! 8053: if (ref($changes{'cancreate'}) eq 'ARRAY') {
! 8054: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
! 8055: if ($cancreate{'notify'}{'approval'}) {
! 8056: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
! 8057: }
! 8058: }
1.43 raeburn 8059: }
1.34 raeburn 8060: }
1.224 ! raeburn 8061: if ($chgtext) {
! 8062: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 8063: }
8064: }
8065: }
1.43 raeburn 8066: if (ref($changes{'email_rule'}) eq 'ARRAY') {
8067: my ($emailrules,$emailruleorder) =
8068: &Apache::lonnet::inst_userrules($dom,'email');
8069: my $chgtext = '<ul>';
8070: foreach my $type (@email_rule) {
8071: if (ref($emailrules->{$type}) eq 'HASH') {
8072: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
8073: }
8074: }
8075: $chgtext .= '</ul>';
8076: if (@email_rule > 0) {
1.224 ! raeburn 8077: $resulttext .= '<li>'.
! 8078: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
! 8079: $chgtext.
! 8080: '</li>';
1.43 raeburn 8081: } else {
1.224 ! raeburn 8082: $resulttext .= '<li>'.
! 8083: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
! 8084: '</li>';
1.43 raeburn 8085: }
8086: }
1.224 ! raeburn 8087: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
! 8088: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
! 8089: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
! 8090: foreach my $type (@{$changes{'selfcreate'}}) {
! 8091: my $typename = $type;
! 8092: if (ref($usertypes) eq 'HASH') {
! 8093: if ($usertypes->{$type} ne '') {
! 8094: $typename = $usertypes->{$type};
! 8095: }
! 8096: }
! 8097: my @modifiable;
! 8098: $resulttext .= '<li>'.
! 8099: &mt('Self-creation of account by users with status: [_1]',
! 8100: '<span class="LC_cusr_emph">'.$typename.'</span>').
! 8101: ' - '.&mt('modifiable fields (if institutional data blank): ');
! 8102: foreach my $field (@fields) {
! 8103: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
! 8104: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 8105: }
8106: }
1.224 ! raeburn 8107: if (@modifiable > 0) {
! 8108: $resulttext .= join(', ',@modifiable);
1.43 raeburn 8109: } else {
1.224 ! raeburn 8110: $resulttext .= &mt('none');
1.43 raeburn 8111: }
1.224 ! raeburn 8112: $resulttext .= '</li>';
1.28 raeburn 8113: }
1.224 ! raeburn 8114: $resulttext .= '</ul></li>';
1.28 raeburn 8115: }
1.27 raeburn 8116: $resulttext .= '</ul>';
8117: } else {
1.224 ! raeburn 8118: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 8119: }
8120: } else {
8121: $resulttext = '<span class="LC_error">'.
1.23 raeburn 8122: &mt('An error occurred: [_1]',$putresult).'</span>';
8123: }
1.43 raeburn 8124: if ($warningmsg ne '') {
8125: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
8126: }
1.23 raeburn 8127: return $resulttext;
8128: }
8129:
1.165 raeburn 8130: sub process_captcha {
8131: my ($container,$changes,$newsettings,$current) = @_;
8132: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
8133: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
8134: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
8135: $newsettings->{'captcha'} = 'original';
8136: }
8137: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 8138: if ($container eq 'cancreate') {
1.169 raeburn 8139: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
8140: push(@{$changes->{'cancreate'}},'captcha');
8141: } elsif (!defined($changes->{'cancreate'})) {
8142: $changes->{'cancreate'} = ['captcha'];
8143: }
8144: } else {
8145: $changes->{'captcha'} = 1;
1.165 raeburn 8146: }
8147: }
8148: my ($newpub,$newpriv,$currpub,$currpriv);
8149: if ($newsettings->{'captcha'} eq 'recaptcha') {
8150: $newpub = $env{'form.'.$container.'_recaptchapub'};
8151: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.169 raeburn 8152: $newpub =~ s/\W//g;
8153: $newpriv =~ s/\W//g;
8154: $newsettings->{'recaptchakeys'} = {
8155: public => $newpub,
8156: private => $newpriv,
8157: };
1.165 raeburn 8158: }
8159: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
8160: $currpub = $current->{'recaptchakeys'}{'public'};
8161: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 8162: unless ($newsettings->{'captcha'} eq 'recaptcha') {
8163: $newsettings->{'recaptchakeys'} = {
8164: public => '',
8165: private => '',
8166: }
8167: }
1.165 raeburn 8168: }
8169: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 8170: if ($container eq 'cancreate') {
8171: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
8172: push(@{$changes->{'cancreate'}},'recaptchakeys');
8173: } elsif (!defined($changes->{'cancreate'})) {
8174: $changes->{'cancreate'} = ['recaptchakeys'];
8175: }
8176: } else {
1.210 raeburn 8177: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 8178: }
8179: }
8180: return;
8181: }
8182:
1.33 raeburn 8183: sub modify_usermodification {
8184: my ($dom,%domconfig) = @_;
1.224 ! raeburn 8185: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 8186: if (ref($domconfig{'usermodification'}) eq 'HASH') {
8187: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 ! raeburn 8188: if ($key eq 'selfcreate') {
! 8189: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
! 8190: } else {
! 8191: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
! 8192: }
1.33 raeburn 8193: }
8194: }
1.224 ! raeburn 8195: my @contexts = ('author','course');
1.33 raeburn 8196: my %context_title = (
8197: author => 'In author context',
8198: course => 'In course context',
8199: );
8200: my @fields = ('lastname','firstname','middlename','generation',
8201: 'permanentemail','id');
8202: my %roles = (
8203: author => ['ca','aa'],
8204: course => ['st','ep','ta','in','cr'],
8205: );
8206: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8207: foreach my $context (@contexts) {
8208: foreach my $role (@{$roles{$context}}) {
8209: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
8210: foreach my $item (@fields) {
8211: if (grep(/^\Q$item\E$/,@modifiable)) {
8212: $modifyhash{$context}{$role}{$item} = 1;
8213: } else {
8214: $modifyhash{$context}{$role}{$item} = 0;
8215: }
8216: }
8217: }
8218: if (ref($curr_usermodification{$context}) eq 'HASH') {
8219: foreach my $role (@{$roles{$context}}) {
8220: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
8221: foreach my $field (@fields) {
8222: if ($modifyhash{$context}{$role}{$field} ne
8223: $curr_usermodification{$context}{$role}{$field}) {
8224: push(@{$changes{$context}},$role);
8225: last;
8226: }
8227: }
8228: }
8229: }
8230: } else {
8231: foreach my $context (@contexts) {
8232: foreach my $role (@{$roles{$context}}) {
8233: push(@{$changes{$context}},$role);
8234: }
8235: }
8236: }
8237: }
1.224 ! raeburn 8238: # FIXME need to ensure selfcreate stuff is preserved
1.33 raeburn 8239: my %usermodification_hash = (
8240: usermodification => \%modifyhash,
8241: );
8242: my $putresult = &Apache::lonnet::put_dom('configuration',
8243: \%usermodification_hash,$dom);
8244: if ($putresult eq 'ok') {
8245: if (keys(%changes) > 0) {
8246: $resulttext = &mt('Changes made: ').'<ul>';
8247: foreach my $context (@contexts) {
8248: if (ref($changes{$context}) eq 'ARRAY') {
8249: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
8250: if (ref($changes{$context}) eq 'ARRAY') {
8251: foreach my $role (@{$changes{$context}}) {
8252: my $rolename;
1.224 ! raeburn 8253: if ($role eq 'cr') {
! 8254: $rolename = &mt('Custom');
1.33 raeburn 8255: } else {
1.224 ! raeburn 8256: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 8257: }
8258: my @modifiable;
1.224 ! raeburn 8259: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 8260: foreach my $field (@fields) {
8261: if ($modifyhash{$context}{$role}{$field}) {
8262: push(@modifiable,$fieldtitles{$field});
8263: }
8264: }
8265: if (@modifiable > 0) {
8266: $resulttext .= join(', ',@modifiable);
8267: } else {
8268: $resulttext .= &mt('none');
8269: }
8270: $resulttext .= '</li>';
8271: }
8272: $resulttext .= '</ul></li>';
8273: }
8274: }
8275: }
8276: $resulttext .= '</ul>';
8277: } else {
8278: $resulttext = &mt('No changes made to user modification settings');
8279: }
8280: } else {
8281: $resulttext = '<span class="LC_error">'.
8282: &mt('An error occurred: [_1]',$putresult).'</span>';
8283: }
8284: return $resulttext;
8285: }
8286:
1.43 raeburn 8287: sub modify_defaults {
1.212 raeburn 8288: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 8289: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 8290: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 8291: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 8292: my @authtypes = ('internal','krb4','krb5','localauth');
8293: foreach my $item (@items) {
8294: $newvalues{$item} = $env{'form.'.$item};
8295: if ($item eq 'auth_def') {
8296: if ($newvalues{$item} ne '') {
8297: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
8298: push(@errors,$item);
8299: }
8300: }
8301: } elsif ($item eq 'lang_def') {
8302: if ($newvalues{$item} ne '') {
8303: if ($newvalues{$item} =~ /^(\w+)/) {
8304: my $langcode = $1;
1.103 raeburn 8305: if ($langcode ne 'x_chef') {
8306: if (code2language($langcode) eq '') {
8307: push(@errors,$item);
8308: }
1.43 raeburn 8309: }
8310: } else {
8311: push(@errors,$item);
8312: }
8313: }
1.54 raeburn 8314: } elsif ($item eq 'timezone_def') {
8315: if ($newvalues{$item} ne '') {
1.62 raeburn 8316: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 8317: push(@errors,$item);
8318: }
8319: }
1.68 raeburn 8320: } elsif ($item eq 'datelocale_def') {
8321: if ($newvalues{$item} ne '') {
8322: my @datelocale_ids = DateTime::Locale->ids();
8323: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
8324: push(@errors,$item);
8325: }
8326: }
1.141 raeburn 8327: } elsif ($item eq 'portal_def') {
8328: if ($newvalues{$item} ne '') {
8329: 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])\/?$/) {
8330: push(@errors,$item);
8331: }
8332: }
1.43 raeburn 8333: }
8334: if (grep(/^\Q$item\E$/,@errors)) {
8335: $newvalues{$item} = $domdefaults{$item};
8336: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
8337: $changes{$item} = 1;
8338: }
1.72 raeburn 8339: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 8340: }
8341: my %defaults_hash = (
1.72 raeburn 8342: defaults => \%newvalues,
8343: );
1.43 raeburn 8344: my $title = &defaults_titles();
8345: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
8346: $dom);
8347: if ($putresult eq 'ok') {
8348: if (keys(%changes) > 0) {
8349: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 8350: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 8351: 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";
8352: foreach my $item (sort(keys(%changes))) {
8353: my $value = $env{'form.'.$item};
8354: if ($value eq '') {
8355: $value = &mt('none');
8356: } elsif ($item eq 'auth_def') {
8357: my %authnames = &authtype_names();
8358: my %shortauth = (
8359: internal => 'int',
8360: krb4 => 'krb4',
8361: krb5 => 'krb5',
8362: localauth => 'loc',
8363: );
8364: $value = $authnames{$shortauth{$value}};
8365: }
8366: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
8367: $mailmsgtext .= "$title->{$item} set to $value\n";
8368: }
8369: $resulttext .= '</ul>';
8370: $mailmsgtext .= "\n";
8371: my $cachetime = 24*60*60;
1.72 raeburn 8372: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 8373: if (ref($lastactref) eq 'HASH') {
8374: $lastactref->{'domdefaults'} = 1;
8375: }
1.68 raeburn 8376: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 8377: my $notify = 1;
8378: if (ref($domconfig{'contacts'}) eq 'HASH') {
8379: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
8380: $notify = 0;
8381: }
8382: }
8383: if ($notify) {
8384: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
8385: "LON-CAPA Domain Settings Change - $dom",
8386: $mailmsgtext);
8387: }
1.54 raeburn 8388: }
1.43 raeburn 8389: } else {
1.54 raeburn 8390: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 8391: }
8392: } else {
8393: $resulttext = '<span class="LC_error">'.
8394: &mt('An error occurred: [_1]',$putresult).'</span>';
8395: }
8396: if (@errors > 0) {
8397: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
8398: foreach my $item (@errors) {
8399: $resulttext .= ' "'.$title->{$item}.'",';
8400: }
8401: $resulttext =~ s/,$//;
8402: }
8403: return $resulttext;
8404: }
8405:
1.46 raeburn 8406: sub modify_scantron {
1.205 raeburn 8407: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 8408: my ($resulttext,%confhash,%changes,$errors);
8409: my $custom = 'custom.tab';
8410: my $default = 'default.tab';
8411: my $servadm = $r->dir_config('lonAdmEMail');
8412: my ($configuserok,$author_ok,$switchserver) =
8413: &config_check($dom,$confname,$servadm);
8414: if ($env{'form.scantronformat.filename'} ne '') {
8415: my $error;
8416: if ($configuserok eq 'ok') {
8417: if ($switchserver) {
1.130 raeburn 8418: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 8419: } else {
8420: if ($author_ok eq 'ok') {
8421: my ($result,$scantronurl) =
8422: &publishlogo($r,'upload','scantronformat',$dom,
8423: $confname,'scantron','','',$custom);
8424: if ($result eq 'ok') {
8425: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 8426: $changes{'scantronformat'} = 1;
1.46 raeburn 8427: } else {
8428: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
8429: }
8430: } else {
8431: $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);
8432: }
8433: }
8434: } else {
8435: $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);
8436: }
8437: if ($error) {
8438: &Apache::lonnet::logthis($error);
8439: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8440: }
8441: }
1.48 raeburn 8442: if (ref($domconfig{'scantron'}) eq 'HASH') {
8443: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
8444: if ($env{'form.scantronformat_del'}) {
8445: $confhash{'scantron'}{'scantronformat'} = '';
8446: $changes{'scantronformat'} = 1;
1.46 raeburn 8447: }
8448: }
8449: }
8450: if (keys(%confhash) > 0) {
8451: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
8452: $dom);
8453: if ($putresult eq 'ok') {
8454: if (keys(%changes) > 0) {
1.48 raeburn 8455: if (ref($confhash{'scantron'}) eq 'HASH') {
8456: $resulttext = &mt('Changes made:').'<ul>';
8457: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 8458: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 8459: } else {
1.130 raeburn 8460: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 8461: }
1.48 raeburn 8462: $resulttext .= '</ul>';
8463: } else {
1.130 raeburn 8464: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 8465: }
8466: $resulttext .= '</ul>';
8467: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 8468: if (ref($lastactref) eq 'HASH') {
8469: $lastactref->{'domainconfig'} = 1;
8470: }
1.46 raeburn 8471: } else {
1.130 raeburn 8472: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 8473: }
8474: } else {
8475: $resulttext = '<span class="LC_error">'.
8476: &mt('An error occurred: [_1]',$putresult).'</span>';
8477: }
8478: } else {
1.130 raeburn 8479: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 8480: }
8481: if ($errors) {
8482: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
8483: $errors.'</ul>';
8484: }
8485: return $resulttext;
8486: }
8487:
1.48 raeburn 8488: sub modify_coursecategories {
8489: my ($dom,%domconfig) = @_;
1.57 raeburn 8490: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
8491: $cathash);
1.48 raeburn 8492: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 8493: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 8494: $cathash = $domconfig{'coursecategories'}{'cats'};
8495: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
8496: $changes{'togglecats'} = 1;
8497: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
8498: }
8499: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
8500: $changes{'categorize'} = 1;
8501: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
8502: }
1.120 raeburn 8503: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
8504: $changes{'togglecatscomm'} = 1;
8505: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
8506: }
8507: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
8508: $changes{'categorizecomm'} = 1;
8509: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
8510: }
1.57 raeburn 8511: } else {
8512: $changes{'togglecats'} = 1;
8513: $changes{'categorize'} = 1;
1.124 raeburn 8514: $changes{'togglecatscomm'} = 1;
8515: $changes{'categorizecomm'} = 1;
1.87 raeburn 8516: $domconfig{'coursecategories'} = {
8517: togglecats => $env{'form.togglecats'},
8518: categorize => $env{'form.categorize'},
1.124 raeburn 8519: togglecatscomm => $env{'form.togglecatscomm'},
8520: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 8521: };
1.57 raeburn 8522: }
8523: if (ref($cathash) eq 'HASH') {
8524: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 8525: push (@deletecategory,'instcode::0');
8526: }
1.120 raeburn 8527: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
8528: push(@deletecategory,'communities::0');
8529: }
1.48 raeburn 8530: }
1.57 raeburn 8531: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
8532: if (ref($cathash) eq 'HASH') {
1.48 raeburn 8533: if (@deletecategory > 0) {
8534: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 8535: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 8536: foreach my $item (@deletecategory) {
1.57 raeburn 8537: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
8538: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 8539: $deletions{$item} = 1;
1.57 raeburn 8540: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 8541: }
8542: }
8543: }
1.57 raeburn 8544: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 8545: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 8546: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 8547: $reorderings{$item} = 1;
1.57 raeburn 8548: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 8549: }
8550: if ($env{'form.addcategory_name_'.$item} ne '') {
8551: my $newcat = $env{'form.addcategory_name_'.$item};
8552: my $newdepth = $depth+1;
8553: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 8554: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 8555: $adds{$newitem} = 1;
8556: }
8557: if ($env{'form.subcat_'.$item} ne '') {
8558: my $newcat = $env{'form.subcat_'.$item};
8559: my $newdepth = $depth+1;
8560: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 8561: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 8562: $adds{$newitem} = 1;
8563: }
8564: }
8565: }
8566: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 8567: if (ref($cathash) eq 'HASH') {
1.48 raeburn 8568: my $newitem = 'instcode::0';
1.57 raeburn 8569: if ($cathash->{$newitem} eq '') {
8570: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 8571: $adds{$newitem} = 1;
8572: }
8573: } else {
8574: my $newitem = 'instcode::0';
1.57 raeburn 8575: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 8576: $adds{$newitem} = 1;
8577: }
8578: }
1.120 raeburn 8579: if ($env{'form.communities'} eq '1') {
8580: if (ref($cathash) eq 'HASH') {
8581: my $newitem = 'communities::0';
8582: if ($cathash->{$newitem} eq '') {
8583: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
8584: $adds{$newitem} = 1;
8585: }
8586: } else {
8587: my $newitem = 'communities::0';
8588: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
8589: $adds{$newitem} = 1;
8590: }
8591: }
1.48 raeburn 8592: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 8593: if (($env{'form.addcategory_name'} ne 'instcode') &&
8594: ($env{'form.addcategory_name'} ne 'communities')) {
8595: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
8596: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
8597: $adds{$newitem} = 1;
8598: }
1.48 raeburn 8599: }
1.57 raeburn 8600: my $putresult;
1.48 raeburn 8601: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
8602: if (keys(%deletions) > 0) {
8603: foreach my $key (keys(%deletions)) {
8604: if ($predelallitems{$key} ne '') {
8605: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
8606: }
8607: }
8608: }
8609: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 8610: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 8611: if (ref($chkcats[0]) eq 'ARRAY') {
8612: my $depth = 0;
8613: my $chg = 0;
8614: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
8615: my $name = $chkcats[0][$i];
8616: my $item;
8617: if ($name eq '') {
8618: $chg ++;
8619: } else {
8620: $item = &escape($name).'::0';
8621: if ($chg) {
1.57 raeburn 8622: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 8623: }
8624: $depth ++;
1.57 raeburn 8625: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 8626: $depth --;
8627: }
8628: }
8629: }
1.57 raeburn 8630: }
8631: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
8632: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 8633: if ($putresult eq 'ok') {
1.57 raeburn 8634: my %title = (
1.120 raeburn 8635: togglecats => 'Show/Hide a course in catalog',
8636: categorize => 'Assign a category to a course',
8637: togglecatscomm => 'Show/Hide a community in catalog',
8638: categorizecomm => 'Assign a category to a community',
1.57 raeburn 8639: );
8640: my %level = (
1.120 raeburn 8641: dom => 'set in Domain ("Modify Course/Community")',
8642: crs => 'set in Course ("Course Configuration")',
8643: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 8644: );
1.48 raeburn 8645: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 8646: if ($changes{'togglecats'}) {
8647: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
8648: }
8649: if ($changes{'categorize'}) {
8650: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 8651: }
1.120 raeburn 8652: if ($changes{'togglecatscomm'}) {
8653: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
8654: }
8655: if ($changes{'categorizecomm'}) {
8656: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
8657: }
1.57 raeburn 8658: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
8659: my $cathash;
8660: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
8661: $cathash = $domconfig{'coursecategories'}{'cats'};
8662: } else {
8663: $cathash = {};
8664: }
8665: my (@cats,@trails,%allitems);
8666: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
8667: if (keys(%deletions) > 0) {
8668: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
8669: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
8670: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
8671: }
8672: $resulttext .= '</ul></li>';
8673: }
8674: if (keys(%reorderings) > 0) {
8675: my %sort_by_trail;
8676: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
8677: foreach my $key (keys(%reorderings)) {
8678: if ($allitems{$key} ne '') {
8679: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
8680: }
1.48 raeburn 8681: }
1.57 raeburn 8682: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
8683: $resulttext .= '<li>'.$trails[$trail].'</li>';
8684: }
8685: $resulttext .= '</ul></li>';
1.48 raeburn 8686: }
1.57 raeburn 8687: if (keys(%adds) > 0) {
8688: my %sort_by_trail;
8689: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
8690: foreach my $key (keys(%adds)) {
8691: if ($allitems{$key} ne '') {
8692: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
8693: }
8694: }
8695: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
8696: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 8697: }
1.57 raeburn 8698: $resulttext .= '</ul></li>';
1.48 raeburn 8699: }
8700: }
8701: $resulttext .= '</ul>';
8702: } else {
8703: $resulttext = '<span class="LC_error">'.
1.57 raeburn 8704: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 8705: }
8706: } else {
1.120 raeburn 8707: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 8708: }
8709: return $resulttext;
8710: }
8711:
1.69 raeburn 8712: sub modify_serverstatuses {
8713: my ($dom,%domconfig) = @_;
8714: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
8715: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
8716: %currserverstatus = %{$domconfig{'serverstatuses'}};
8717: }
8718: my @pages = &serverstatus_pages();
8719: foreach my $type (@pages) {
8720: $newserverstatus{$type}{'namedusers'} = '';
8721: $newserverstatus{$type}{'machines'} = '';
8722: if (defined($env{'form.'.$type.'_namedusers'})) {
8723: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
8724: my @okusers;
8725: foreach my $user (@users) {
8726: my ($uname,$udom) = split(/:/,$user);
8727: if (($udom =~ /^$match_domain$/) &&
8728: (&Apache::lonnet::domain($udom)) &&
8729: ($uname =~ /^$match_username$/)) {
8730: if (!grep(/^\Q$user\E/,@okusers)) {
8731: push(@okusers,$user);
8732: }
8733: }
8734: }
8735: if (@okusers > 0) {
8736: @okusers = sort(@okusers);
8737: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
8738: }
8739: }
8740: if (defined($env{'form.'.$type.'_machines'})) {
8741: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
8742: my @okmachines;
8743: foreach my $ip (@machines) {
8744: my @parts = split(/\./,$ip);
8745: next if (@parts < 4);
8746: my $badip = 0;
8747: for (my $i=0; $i<4; $i++) {
8748: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
8749: $badip = 1;
8750: last;
8751: }
8752: }
8753: if (!$badip) {
8754: push(@okmachines,$ip);
8755: }
8756: }
8757: @okmachines = sort(@okmachines);
8758: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
8759: }
8760: }
8761: my %serverstatushash = (
8762: serverstatuses => \%newserverstatus,
8763: );
8764: foreach my $type (@pages) {
1.83 raeburn 8765: foreach my $setting ('namedusers','machines') {
1.84 raeburn 8766: my (@current,@new);
1.83 raeburn 8767: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 8768: if ($currserverstatus{$type}{$setting} ne '') {
8769: @current = split(/,/,$currserverstatus{$type}{$setting});
8770: }
8771: }
8772: if ($newserverstatus{$type}{$setting} ne '') {
8773: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 8774: }
8775: if (@current > 0) {
8776: if (@new > 0) {
8777: foreach my $item (@current) {
8778: if (!grep(/^\Q$item\E$/,@new)) {
8779: $changes{$type}{$setting} = 1;
1.82 raeburn 8780: last;
8781: }
8782: }
1.84 raeburn 8783: foreach my $item (@new) {
8784: if (!grep(/^\Q$item\E$/,@current)) {
8785: $changes{$type}{$setting} = 1;
8786: last;
1.82 raeburn 8787: }
8788: }
8789: } else {
1.83 raeburn 8790: $changes{$type}{$setting} = 1;
1.69 raeburn 8791: }
1.83 raeburn 8792: } elsif (@new > 0) {
8793: $changes{$type}{$setting} = 1;
1.69 raeburn 8794: }
8795: }
8796: }
8797: if (keys(%changes) > 0) {
1.81 raeburn 8798: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 8799: my $putresult = &Apache::lonnet::put_dom('configuration',
8800: \%serverstatushash,$dom);
8801: if ($putresult eq 'ok') {
8802: $resulttext .= &mt('Changes made:').'<ul>';
8803: foreach my $type (@pages) {
1.84 raeburn 8804: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 8805: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 8806: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 8807: if ($newserverstatus{$type}{'namedusers'} eq '') {
8808: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
8809: } else {
8810: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
8811: }
1.84 raeburn 8812: }
8813: if ($changes{$type}{'machines'}) {
1.69 raeburn 8814: if ($newserverstatus{$type}{'machines'} eq '') {
8815: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
8816: } else {
8817: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
8818: }
8819:
8820: }
8821: $resulttext .= '</ul></li>';
8822: }
8823: }
8824: $resulttext .= '</ul>';
8825: } else {
8826: $resulttext = '<span class="LC_error">'.
8827: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
8828:
8829: }
8830: } else {
8831: $resulttext = &mt('No changes made to access to server status pages');
8832: }
8833: return $resulttext;
8834: }
8835:
1.118 jms 8836: sub modify_helpsettings {
1.122 jms 8837: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 8838: my ($resulttext,$errors,%changes,%helphash);
8839: my %defaultchecked = ('submitbugs' => 'on');
8840: my @offon = ('off','on');
1.118 jms 8841: my @toggles = ('submitbugs');
8842: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8843: foreach my $item (@toggles) {
1.166 raeburn 8844: if ($defaultchecked{$item} eq 'on') {
8845: if ($domconfig{'helpsettings'}{$item} eq '') {
8846: if ($env{'form.'.$item} eq '0') {
8847: $changes{$item} = 1;
8848: }
8849: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
8850: $changes{$item} = 1;
8851: }
8852: } elsif ($defaultchecked{$item} eq 'off') {
8853: if ($domconfig{'helpsettings'}{$item} eq '') {
8854: if ($env{'form.'.$item} eq '1') {
8855: $changes{$item} = 1;
8856: }
8857: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
8858: $changes{$item} = 1;
8859: }
8860: }
1.210 raeburn 8861: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
1.166 raeburn 8862: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
8863: }
8864: }
1.118 jms 8865: }
1.123 jms 8866: my $putresult;
8867: if (keys(%changes) > 0) {
1.166 raeburn 8868: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 8869: if ($putresult eq 'ok') {
1.166 raeburn 8870: $resulttext = &mt('Changes made:').'<ul>';
8871: foreach my $item (sort(keys(%changes))) {
8872: if ($item eq 'submitbugs') {
8873: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
8874: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
8875: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
8876: }
8877: }
8878: $resulttext .= '</ul>';
8879: } else {
8880: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 8881: $errors .= '<li><span class="LC_error">'.
8882: &mt('An error occurred storing the settings: [_1]',
8883: $putresult).'</span></li>';
1.166 raeburn 8884: }
1.118 jms 8885: }
8886: if ($errors) {
1.168 raeburn 8887: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 8888: $errors.'</ul>';
8889: }
8890: return $resulttext;
8891: }
8892:
1.121 raeburn 8893: sub modify_coursedefaults {
1.212 raeburn 8894: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 8895: my ($resulttext,$errors,%changes,%defaultshash);
8896: my %defaultchecked = ('canuse_pdfforms' => 'off');
8897: my @toggles = ('canuse_pdfforms');
1.198 raeburn 8898: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.216 raeburn 8899: 'uploadquota_community','uploadquota_textbook');
8900: my @types = ('official','unofficial','community','textbook');
1.198 raeburn 8901: my %staticdefaults = (
8902: anonsurvey_threshold => 10,
8903: uploadquota => 500,
8904: );
1.121 raeburn 8905:
8906: $defaultshash{'coursedefaults'} = {};
8907:
8908: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
8909: if ($domconfig{'coursedefaults'} eq '') {
8910: $domconfig{'coursedefaults'} = {};
8911: }
8912: }
8913:
8914: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
8915: foreach my $item (@toggles) {
8916: if ($defaultchecked{$item} eq 'on') {
8917: if (($domconfig{'coursedefaults'}{$item} eq '') &&
8918: ($env{'form.'.$item} eq '0')) {
8919: $changes{$item} = 1;
1.192 raeburn 8920: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 8921: $changes{$item} = 1;
8922: }
8923: } elsif ($defaultchecked{$item} eq 'off') {
8924: if (($domconfig{'coursedefaults'}{$item} eq '') &&
8925: ($env{'form.'.$item} eq '1')) {
8926: $changes{$item} = 1;
8927: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
8928: $changes{$item} = 1;
8929: }
8930: }
8931: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
8932: }
1.198 raeburn 8933: foreach my $item (@numbers) {
8934: my ($currdef,$newdef);
1.208 raeburn 8935: $newdef = $env{'form.'.$item};
1.198 raeburn 8936: if ($item eq 'anonsurvey_threshold') {
8937: $currdef = $domconfig{'coursedefaults'}{$item};
8938: $newdef =~ s/\D//g;
8939: if ($newdef eq '' || $newdef < 1) {
8940: $newdef = 1;
8941: }
8942: $defaultshash{'coursedefaults'}{$item} = $newdef;
8943: } else {
8944: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
8945: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8946: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
8947: }
8948: $newdef =~ s/[^\w.\-]//g;
8949: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
8950: }
8951: if ($currdef ne $newdef) {
8952: my $staticdef;
8953: if ($item eq 'anonsurvey_threshold') {
8954: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
8955: $changes{$item} = 1;
8956: }
8957: } else {
8958: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
8959: $changes{'uploadquota'} = 1;
8960: }
8961: }
1.139 raeburn 8962: }
8963: }
1.192 raeburn 8964: my $officialcreds = $env{'form.official_credits'};
1.216 raeburn 8965: $officialcreds =~ s/[^\d.]+//g;
1.192 raeburn 8966: my $unofficialcreds = $env{'form.unofficial_credits'};
1.216 raeburn 8967: $unofficialcreds =~ s/[^\d.]+//g;
8968: my $textbookcreds = $env{'form.textbook_credits'};
8969: $textbookcreds =~ s/[^\d.]+//g;
1.192 raeburn 8970: if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
8971: ($env{'form.coursecredits'} eq '1')) {
8972: $changes{'coursecredits'} = 1;
8973: } else {
8974: if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
1.216 raeburn 8975: ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds) ||
8976: ($domconfig{'coursedefaults'}{'coursecredits'}{'textbook'} ne $textbookcreds)) {
1.192 raeburn 8977: $changes{'coursecredits'} = 1;
8978: }
8979: }
8980: $defaultshash{'coursedefaults'}{'coursecredits'} = {
8981: official => $officialcreds,
8982: unofficial => $unofficialcreds,
1.216 raeburn 8983: textbook => $textbookcreds,
1.192 raeburn 8984: }
1.121 raeburn 8985: }
8986: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8987: $dom);
8988: if ($putresult eq 'ok') {
8989: if (keys(%changes) > 0) {
1.213 raeburn 8990: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.198 raeburn 8991: if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) || ($changes{'uploadquota'})) {
1.192 raeburn 8992: if ($changes{'canuse_pdfforms'}) {
8993: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
8994: }
8995: if ($changes{'coursecredits'}) {
8996: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
8997: $domdefaults{'officialcredits'} =
8998: $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
8999: $domdefaults{'unofficialcredits'} =
9000: $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
1.216 raeburn 9001: $domdefaults{'textbookcredits'} =
9002: $domdefaults{'coursedefaults'}{'coursecredits'}{'textbook'};
1.192 raeburn 9003: }
9004: }
1.198 raeburn 9005: if ($changes{'uploadquota'}) {
9006: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
9007: foreach my $type (@types) {
9008: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
9009: }
9010: }
9011: }
1.121 raeburn 9012: my $cachetime = 24*60*60;
9013: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 9014: if (ref($lastactref) eq 'HASH') {
9015: $lastactref->{'domdefaults'} = 1;
9016: }
1.121 raeburn 9017: }
9018: $resulttext = &mt('Changes made:').'<ul>';
9019: foreach my $item (sort(keys(%changes))) {
9020: if ($item eq 'canuse_pdfforms') {
9021: if ($env{'form.'.$item} eq '1') {
9022: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
9023: } else {
9024: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
9025: }
1.139 raeburn 9026: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 9027: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 9028: } elsif ($item eq 'uploadquota') {
9029: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
9030: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
9031: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
9032: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 9033: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
9034:
1.198 raeburn 9035: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
9036: '</ul>'.
9037: '</li>';
9038: } else {
9039: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
9040: }
1.192 raeburn 9041: } elsif ($item eq 'coursecredits') {
9042: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
9043: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 9044: ($domdefaults{'unofficialcredits'} eq '') &&
9045: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 9046: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
9047: } else {
9048: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
9049: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
9050: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 9051: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 9052: '</ul>'.
9053: '</li>';
9054: }
9055: } else {
9056: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
9057: }
1.140 raeburn 9058: }
1.121 raeburn 9059: }
9060: $resulttext .= '</ul>';
9061: } else {
9062: $resulttext = &mt('No changes made to course defaults');
9063: }
9064: } else {
9065: $resulttext = '<span class="LC_error">'.
9066: &mt('An error occurred: [_1]',$putresult).'</span>';
9067: }
9068: return $resulttext;
9069: }
9070:
1.137 raeburn 9071: sub modify_usersessions {
1.212 raeburn 9072: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 9073: my @hostingtypes = ('version','excludedomain','includedomain');
9074: my @offloadtypes = ('primary','default');
9075: my %types = (
9076: remote => \@hostingtypes,
9077: hosted => \@hostingtypes,
9078: spares => \@offloadtypes,
9079: );
9080: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 9081: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 9082: my (%by_ip,%by_location,@intdoms);
9083: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
9084: my @locations = sort(keys(%by_location));
1.137 raeburn 9085: my (%defaultshash,%changes);
9086: foreach my $prefix (@prefixes) {
9087: $defaultshash{'usersessions'}{$prefix} = {};
9088: }
1.212 raeburn 9089: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 9090: my $resulttext;
1.138 raeburn 9091: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 9092: foreach my $prefix (@prefixes) {
1.145 raeburn 9093: next if ($prefix eq 'spares');
9094: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 9095: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
9096: if ($type eq 'version') {
9097: my $value = $env{'form.'.$prefix.'_'.$type};
9098: my $okvalue;
9099: if ($value ne '') {
9100: if (grep(/^\Q$value\E$/,@lcversions)) {
9101: $okvalue = $value;
9102: }
9103: }
9104: if (ref($domconfig{'usersessions'}) eq 'HASH') {
9105: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
9106: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
9107: if ($inuse == 0) {
9108: $changes{$prefix}{$type} = 1;
9109: } else {
9110: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
9111: $changes{$prefix}{$type} = 1;
9112: }
9113: if ($okvalue ne '') {
9114: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
9115: }
9116: }
9117: } else {
9118: if (($inuse == 1) && ($okvalue ne '')) {
9119: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
9120: $changes{$prefix}{$type} = 1;
9121: }
9122: }
9123: } else {
9124: if (($inuse == 1) && ($okvalue ne '')) {
9125: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
9126: $changes{$prefix}{$type} = 1;
9127: }
9128: }
9129: } else {
9130: if (($inuse == 1) && ($okvalue ne '')) {
9131: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
9132: $changes{$prefix}{$type} = 1;
9133: }
9134: }
9135: } else {
9136: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
9137: my @okvals;
9138: foreach my $val (@vals) {
1.138 raeburn 9139: if ($val =~ /:/) {
9140: my @items = split(/:/,$val);
9141: foreach my $item (@items) {
9142: if (ref($by_location{$item}) eq 'ARRAY') {
9143: push(@okvals,$item);
9144: }
9145: }
9146: } else {
9147: if (ref($by_location{$val}) eq 'ARRAY') {
9148: push(@okvals,$val);
9149: }
1.137 raeburn 9150: }
9151: }
9152: @okvals = sort(@okvals);
9153: if (ref($domconfig{'usersessions'}) eq 'HASH') {
9154: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
9155: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
9156: if ($inuse == 0) {
9157: $changes{$prefix}{$type} = 1;
9158: } else {
9159: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
9160: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
9161: if (@changed > 0) {
9162: $changes{$prefix}{$type} = 1;
9163: }
9164: }
9165: } else {
9166: if ($inuse == 1) {
9167: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
9168: $changes{$prefix}{$type} = 1;
9169: }
9170: }
9171: } else {
9172: if ($inuse == 1) {
9173: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
9174: $changes{$prefix}{$type} = 1;
9175: }
9176: }
9177: } else {
9178: if ($inuse == 1) {
9179: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
9180: $changes{$prefix}{$type} = 1;
9181: }
9182: }
9183: }
9184: }
9185: }
1.145 raeburn 9186:
9187: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 9188: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 9189: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
9190: my $savespares;
9191:
9192: foreach my $lonhost (sort(keys(%servers))) {
9193: my $serverhomeID =
9194: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 9195: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 9196: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
9197: my %spareschg;
9198: foreach my $type (@{$types{'spares'}}) {
9199: my @okspares;
9200: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
9201: foreach my $server (@checked) {
1.152 raeburn 9202: if (&Apache::lonnet::hostname($server) ne '') {
9203: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
9204: unless (grep(/^\Q$server\E$/,@okspares)) {
9205: push(@okspares,$server);
9206: }
1.145 raeburn 9207: }
9208: }
9209: }
9210: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
9211: my $newspare;
1.152 raeburn 9212: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
9213: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 9214: $newspare = $new;
9215: }
9216: }
1.152 raeburn 9217: my @spares;
9218: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
9219: @spares = sort(@okspares,$newspare);
9220: } else {
9221: @spares = sort(@okspares);
9222: }
9223: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 9224: if (ref($spareid{$lonhost}) eq 'HASH') {
9225: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 9226: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 9227: if (@diffs > 0) {
9228: $spareschg{$type} = 1;
9229: }
9230: }
9231: }
9232: }
9233: if (keys(%spareschg) > 0) {
9234: $changes{'spares'}{$lonhost} = \%spareschg;
9235: }
9236: }
9237:
9238: if (ref($domconfig{'usersessions'}) eq 'HASH') {
9239: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
9240: if (ref($changes{'spares'}) eq 'HASH') {
9241: if (keys(%{$changes{'spares'}}) > 0) {
9242: $savespares = 1;
9243: }
9244: }
9245: } else {
9246: $savespares = 1;
9247: }
9248: }
9249:
1.147 raeburn 9250: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
9251: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 9252: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
9253: $dom);
9254: if ($putresult eq 'ok') {
9255: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
9256: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
9257: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
9258: }
9259: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
9260: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
9261: }
9262: }
9263: my $cachetime = 24*60*60;
9264: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 9265: if (ref($lastactref) eq 'HASH') {
9266: $lastactref->{'domdefaults'} = 1;
9267: }
1.147 raeburn 9268: if (keys(%changes) > 0) {
9269: my %lt = &usersession_titles();
9270: $resulttext = &mt('Changes made:').'<ul>';
9271: foreach my $prefix (@prefixes) {
9272: if (ref($changes{$prefix}) eq 'HASH') {
9273: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
9274: if ($prefix eq 'spares') {
9275: if (ref($changes{$prefix}) eq 'HASH') {
9276: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
9277: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 9278: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 9279: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
9280: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 9281: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
9282: foreach my $type (@{$types{$prefix}}) {
9283: if ($changes{$prefix}{$lonhost}{$type}) {
9284: my $offloadto = &mt('None');
9285: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
9286: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
9287: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
9288: }
1.145 raeburn 9289: }
1.147 raeburn 9290: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 9291: }
1.137 raeburn 9292: }
9293: }
1.147 raeburn 9294: $resulttext .= '</li>';
1.137 raeburn 9295: }
9296: }
1.147 raeburn 9297: } else {
9298: foreach my $type (@{$types{$prefix}}) {
9299: if (defined($changes{$prefix}{$type})) {
9300: my $newvalue;
9301: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
9302: if (ref($defaultshash{'usersessions'}{$prefix})) {
9303: if ($type eq 'version') {
9304: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
9305: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
9306: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
9307: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
9308: }
1.145 raeburn 9309: }
9310: }
9311: }
1.147 raeburn 9312: if ($newvalue eq '') {
9313: if ($type eq 'version') {
9314: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
9315: } else {
9316: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
9317: }
1.145 raeburn 9318: } else {
1.147 raeburn 9319: if ($type eq 'version') {
9320: $newvalue .= ' '.&mt('(or later)');
9321: }
9322: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 9323: }
1.137 raeburn 9324: }
9325: }
9326: }
1.147 raeburn 9327: $resulttext .= '</ul>';
1.137 raeburn 9328: }
9329: }
1.147 raeburn 9330: $resulttext .= '</ul>';
9331: } else {
9332: $resulttext = $nochgmsg;
1.137 raeburn 9333: }
9334: } else {
9335: $resulttext = '<span class="LC_error">'.
9336: &mt('An error occurred: [_1]',$putresult).'</span>';
9337: }
9338: } else {
1.147 raeburn 9339: $resulttext = $nochgmsg;
1.137 raeburn 9340: }
9341: return $resulttext;
9342: }
9343:
1.150 raeburn 9344: sub modify_loadbalancing {
9345: my ($dom,%domconfig) = @_;
9346: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9347: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9348: my ($othertitle,$usertypes,$types) =
9349: &Apache::loncommon::sorted_inst_types($dom);
9350: my %servers = &Apache::lonnet::internet_dom_servers($dom);
9351: my @sparestypes = ('primary','default');
9352: my %typetitles = &sparestype_titles();
9353: my $resulttext;
1.171 raeburn 9354: my (%currbalancer,%currtargets,%currrules,%existing);
9355: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
9356: %existing = %{$domconfig{'loadbalancing'}};
9357: }
9358: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
9359: \%currtargets,\%currrules);
9360: my ($saveloadbalancing,%defaultshash,%changes);
9361: my ($alltypes,$othertypes,$titles) =
9362: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
9363: my %ruletitles = &offloadtype_text();
9364: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
9365: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
9366: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
9367: if ($balancer eq '') {
9368: next;
9369: }
1.210 raeburn 9370: if (!exists($servers{$balancer})) {
1.171 raeburn 9371: if (exists($currbalancer{$balancer})) {
9372: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 9373: }
1.171 raeburn 9374: next;
9375: }
9376: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
9377: push(@{$changes{'delete'}},$balancer);
9378: next;
9379: }
9380: if (!exists($currbalancer{$balancer})) {
9381: push(@{$changes{'add'}},$balancer);
9382: }
9383: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
9384: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
9385: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
9386: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
9387: $saveloadbalancing = 1;
9388: }
9389: foreach my $sparetype (@sparestypes) {
9390: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
9391: my @offloadto;
9392: foreach my $target (@targets) {
9393: if (($servers{$target}) && ($target ne $balancer)) {
9394: if ($sparetype eq 'default') {
9395: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
9396: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 9397: }
9398: }
1.171 raeburn 9399: unless(grep(/^\Q$target\E$/,@offloadto)) {
9400: push(@offloadto,$target);
9401: }
1.150 raeburn 9402: }
1.171 raeburn 9403: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 9404: }
9405: }
1.171 raeburn 9406: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 9407: foreach my $sparetype (@sparestypes) {
1.171 raeburn 9408: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
9409: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 9410: if (@targetdiffs > 0) {
1.171 raeburn 9411: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 9412: }
1.171 raeburn 9413: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
9414: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
9415: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 9416: }
9417: }
9418: }
9419: } else {
1.171 raeburn 9420: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 9421: foreach my $sparetype (@sparestypes) {
1.171 raeburn 9422: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
9423: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
9424: $changes{'curr'}{$balancer}{'targets'} = 1;
9425: }
1.150 raeburn 9426: }
9427: }
1.210 raeburn 9428: }
1.150 raeburn 9429: }
9430: my $ishomedom;
1.171 raeburn 9431: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
9432: $ishomedom = 1;
1.150 raeburn 9433: }
9434: if (ref($alltypes) eq 'ARRAY') {
9435: foreach my $type (@{$alltypes}) {
9436: my $rule;
1.210 raeburn 9437: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 9438: (!$ishomedom)) {
1.171 raeburn 9439: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
9440: }
9441: if ($rule eq 'specific') {
9442: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 9443: }
1.171 raeburn 9444: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
9445: if (ref($currrules{$balancer}) eq 'HASH') {
9446: if ($rule ne $currrules{$balancer}{$type}) {
9447: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 9448: }
9449: } elsif ($rule ne '') {
1.171 raeburn 9450: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 9451: }
9452: }
9453: }
1.171 raeburn 9454: }
9455: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
9456: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
9457: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
9458: $defaultshash{'loadbalancing'} = {};
9459: }
9460: my $putresult = &Apache::lonnet::put_dom('configuration',
9461: \%defaultshash,$dom);
9462: if ($putresult eq 'ok') {
9463: if (keys(%changes) > 0) {
9464: if (ref($changes{'delete'}) eq 'ARRAY') {
9465: foreach my $balancer (sort(@{$changes{'delete'}})) {
9466: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.211 raeburn 9467: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
9468: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 9469: }
1.171 raeburn 9470: }
9471: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 9472: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 9473: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
9474: }
9475: }
9476: if (ref($changes{'curr'}) eq 'HASH') {
9477: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
9478: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
9479: if ($changes{'curr'}{$balancer}{'targets'}) {
9480: my %offloadstr;
9481: foreach my $sparetype (@sparestypes) {
9482: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
9483: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
9484: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
9485: }
9486: }
1.150 raeburn 9487: }
1.171 raeburn 9488: if (keys(%offloadstr) == 0) {
9489: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 9490: } else {
1.171 raeburn 9491: my $showoffload;
9492: foreach my $sparetype (@sparestypes) {
9493: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
9494: if (defined($offloadstr{$sparetype})) {
9495: $showoffload .= $offloadstr{$sparetype};
9496: } else {
9497: $showoffload .= &mt('None');
9498: }
9499: $showoffload .= (' 'x3);
9500: }
9501: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 9502: }
9503: }
9504: }
1.171 raeburn 9505: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
9506: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
9507: foreach my $type (@{$alltypes}) {
9508: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
9509: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
9510: my $balancetext;
9511: if ($rule eq '') {
9512: $balancetext = $ruletitles{'default'};
1.209 raeburn 9513: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
9514: ($rule eq 'balancer') || ($rule eq 'offloadedto')) {
1.171 raeburn 9515: $balancetext = $ruletitles{$rule};
9516: } else {
9517: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
9518: }
1.210 raeburn 9519: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 9520: }
9521: }
9522: }
9523: }
1.215 raeburn 9524: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
1.211 raeburn 9525: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 9526: }
1.171 raeburn 9527: }
9528: if ($resulttext ne '') {
9529: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 9530: } else {
9531: $resulttext = $nochgmsg;
9532: }
9533: } else {
1.171 raeburn 9534: $resulttext = $nochgmsg;
1.150 raeburn 9535: }
9536: } else {
1.171 raeburn 9537: $resulttext = '<span class="LC_error">'.
9538: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 9539: }
9540: } else {
1.171 raeburn 9541: $resulttext = $nochgmsg;
1.150 raeburn 9542: }
9543: return $resulttext;
9544: }
9545:
1.48 raeburn 9546: sub recurse_check {
9547: my ($chkcats,$categories,$depth,$name) = @_;
9548: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
9549: my $chg = 0;
9550: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
9551: my $category = $chkcats->[$depth]{$name}[$j];
9552: my $item;
9553: if ($category eq '') {
9554: $chg ++;
9555: } else {
9556: my $deeper = $depth + 1;
9557: $item = &escape($category).':'.&escape($name).':'.$depth;
9558: if ($chg) {
9559: $categories->{$item} -= $chg;
9560: }
9561: &recurse_check($chkcats,$categories,$deeper,$category);
9562: $deeper --;
9563: }
9564: }
9565: }
9566: return;
9567: }
9568:
9569: sub recurse_cat_deletes {
9570: my ($item,$coursecategories,$deletions) = @_;
9571: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9572: my $subdepth = $depth + 1;
9573: if (ref($coursecategories) eq 'HASH') {
9574: foreach my $subitem (keys(%{$coursecategories})) {
9575: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
9576: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
9577: delete($coursecategories->{$subitem});
9578: $deletions->{$subitem} = 1;
9579: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 9580: }
1.48 raeburn 9581: }
9582: }
9583: return;
9584: }
9585:
1.125 raeburn 9586: sub get_active_dcs {
9587: my ($dom) = @_;
1.191 raeburn 9588: my $now = time;
9589: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 9590: my %domcoords;
9591: my $numdcs = 0;
9592: foreach my $server (keys(%dompersonnel)) {
9593: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
9594: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.191 raeburn 9595: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 9596: }
9597: }
9598: return %domcoords;
9599: }
9600:
9601: sub active_dc_picker {
1.191 raeburn 9602: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.125 raeburn 9603: my %domcoords = &get_active_dcs($dom);
1.191 raeburn 9604: my @domcoord = keys(%domcoords);
9605: if (keys(%currhash)) {
9606: foreach my $dc (keys(%currhash)) {
9607: unless (exists($domcoords{$dc})) {
9608: push(@domcoord,$dc);
9609: }
9610: }
9611: }
9612: @domcoord = sort(@domcoord);
1.210 raeburn 9613: my $numdcs = scalar(@domcoord);
1.191 raeburn 9614: my $rows = 0;
9615: my $table;
1.125 raeburn 9616: if ($numdcs > 1) {
1.191 raeburn 9617: $table = '<table>';
9618: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 9619: my $rem = $i%($numinrow);
9620: if ($rem == 0) {
9621: if ($i > 0) {
1.191 raeburn 9622: $table .= '</tr>';
1.125 raeburn 9623: }
1.191 raeburn 9624: $table .= '<tr>';
9625: $rows ++;
1.125 raeburn 9626: }
1.191 raeburn 9627: my $check = '';
9628: if ($inputtype eq 'radio') {
9629: if (keys(%currhash) == 0) {
9630: if (!$i) {
9631: $check = ' checked="checked"';
9632: }
9633: } elsif (exists($currhash{$domcoord[$i]})) {
9634: $check = ' checked="checked"';
9635: }
9636: } else {
9637: if (exists($currhash{$domcoord[$i]})) {
9638: $check = ' checked="checked"';
1.125 raeburn 9639: }
9640: }
1.191 raeburn 9641: if ($i == @domcoord - 1) {
1.125 raeburn 9642: my $colsleft = $numinrow - $rem;
9643: if ($colsleft > 1) {
1.191 raeburn 9644: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 9645: } else {
1.191 raeburn 9646: $table .= '<td class="LC_left_item">';
1.125 raeburn 9647: }
9648: } else {
1.191 raeburn 9649: $table .= '<td class="LC_left_item">';
9650: }
9651: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
9652: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
9653: $table .= '<span class="LC_nobreak"><label>'.
9654: '<input type="'.$inputtype.'" name="'.$name.'"'.
9655: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
9656: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 9657: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 9658: }
1.219 raeburn 9659: $table .= '</label></span></td>';
1.191 raeburn 9660: }
9661: $table .= '</tr></table>';
9662: } elsif ($numdcs == 1) {
1.219 raeburn 9663: my ($dcname,$dcdom) = split(':',$domcoord[0]);
9664: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 9665: if ($inputtype eq 'radio') {
1.219 raeburn 9666: $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
9667: if ($user ne $dcname.':'.$dcdom) {
9668: $table .= ' ('.$dcname.':'.$dcdom.')';
9669: }
1.191 raeburn 9670: } else {
9671: my $check;
9672: if (exists($currhash{$domcoord[0]})) {
9673: $check = ' checked="checked"';
1.125 raeburn 9674: }
1.219 raeburn 9675: $table .= '<span class="LC_nobreak"><label>'.
9676: '<input type="checkbox" name="'.$name.'" '.
9677: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
9678: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 9679: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 9680: }
1.220 raeburn 9681: $table .= '</label></span>';
1.191 raeburn 9682: $rows ++;
1.125 raeburn 9683: }
9684: }
1.191 raeburn 9685: return ($numdcs,$table,$rows);
1.125 raeburn 9686: }
9687:
1.137 raeburn 9688: sub usersession_titles {
9689: return &Apache::lonlocal::texthash(
9690: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
9691: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 9692: spares => 'Servers offloaded to, when busy',
1.137 raeburn 9693: version => 'LON-CAPA version requirement',
1.138 raeburn 9694: excludedomain => 'Allow all, but exclude specific domains',
9695: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 9696: primary => 'Primary (checked first)',
1.154 raeburn 9697: default => 'Default',
1.137 raeburn 9698: );
9699: }
9700:
1.152 raeburn 9701: sub id_for_thisdom {
9702: my (%servers) = @_;
9703: my %altids;
9704: foreach my $server (keys(%servers)) {
9705: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
9706: if ($serverhome ne $server) {
9707: $altids{$serverhome} = $server;
9708: }
9709: }
9710: return %altids;
9711: }
9712:
1.150 raeburn 9713: sub count_servers {
9714: my ($currbalancer,%servers) = @_;
9715: my (@spares,$numspares);
9716: foreach my $lonhost (sort(keys(%servers))) {
9717: next if ($currbalancer eq $lonhost);
9718: push(@spares,$lonhost);
9719: }
9720: if ($currbalancer) {
9721: $numspares = scalar(@spares);
9722: } else {
9723: $numspares = scalar(@spares) - 1;
9724: }
9725: return ($numspares,@spares);
9726: }
9727:
9728: sub lonbalance_targets_js {
1.171 raeburn 9729: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 9730: my $select = &mt('Select');
9731: my ($alltargets,$allishome,$allinsttypes,@alltypes);
9732: if (ref($servers) eq 'HASH') {
9733: $alltargets = join("','",sort(keys(%{$servers})));
9734: my @homedoms;
9735: foreach my $server (sort(keys(%{$servers}))) {
9736: if (&Apache::lonnet::host_domain($server) eq $dom) {
9737: push(@homedoms,'1');
9738: } else {
9739: push(@homedoms,'0');
9740: }
9741: }
9742: $allishome = join("','",@homedoms);
9743: }
9744: if (ref($types) eq 'ARRAY') {
9745: if (@{$types} > 0) {
9746: @alltypes = @{$types};
9747: }
9748: }
9749: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
9750: $allinsttypes = join("','",@alltypes);
1.171 raeburn 9751: my (%currbalancer,%currtargets,%currrules,%existing);
9752: if (ref($settings) eq 'HASH') {
9753: %existing = %{$settings};
9754: }
9755: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
9756: \%currtargets,\%currrules);
1.210 raeburn 9757: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 9758: return <<"END";
9759:
9760: <script type="text/javascript">
9761: // <![CDATA[
9762:
1.171 raeburn 9763: currBalancers = new Array('$balancers');
9764:
9765: function toggleTargets(balnum) {
9766: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
9767: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
9768: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
9769: var prevbalancer = prevhostitem.value;
9770: var baltotal = document.getElementById('loadbalancing_total').value;
9771: prevhostitem.value = balancer;
9772: if (prevbalancer != '') {
9773: var prevIdx = currBalancers.indexOf(prevbalancer);
9774: if (prevIdx != -1) {
9775: currBalancers.splice(prevIdx,1);
9776: }
9777: }
1.150 raeburn 9778: if (balancer == '') {
1.171 raeburn 9779: hideSpares(balnum);
1.150 raeburn 9780: } else {
1.171 raeburn 9781: var currIdx = currBalancers.indexOf(balancer);
9782: if (currIdx == -1) {
9783: currBalancers.push(balancer);
9784: }
1.150 raeburn 9785: var homedoms = new Array('$allishome');
1.171 raeburn 9786: var ishomedom = homedoms[lonhostitem.selectedIndex];
9787: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 9788: }
1.171 raeburn 9789: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 9790: return;
9791: }
9792:
1.171 raeburn 9793: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 9794: var alltargets = new Array('$alltargets');
9795: var insttypes = new Array('$allinsttypes');
1.151 raeburn 9796: var offloadtypes = new Array('primary','default');
9797:
1.171 raeburn 9798: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
9799: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 9800:
1.151 raeburn 9801: for (var i=0; i<offloadtypes.length; i++) {
9802: var count = 0;
9803: for (var j=0; j<alltargets.length; j++) {
9804: if (alltargets[j] != balancer) {
1.171 raeburn 9805: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
9806: item.value = alltargets[j];
9807: item.style.textAlign='left';
9808: item.style.textFace='normal';
9809: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
9810: if (currBalancers.indexOf(alltargets[j]) == -1) {
9811: item.disabled = '';
9812: } else {
9813: item.disabled = 'disabled';
9814: item.checked = false;
9815: }
1.151 raeburn 9816: count ++;
9817: }
1.150 raeburn 9818: }
9819: }
1.151 raeburn 9820: for (var k=0; k<insttypes.length; k++) {
9821: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 9822: if (ishomedom == 1) {
1.171 raeburn 9823: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
9824: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 9825: } else {
1.171 raeburn 9826: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
9827: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 9828: }
9829: } else {
1.171 raeburn 9830: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
9831: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 9832: }
1.151 raeburn 9833: if ((insttypes[k] != '_LC_external') &&
9834: ((insttypes[k] != '_LC_internetdom') ||
9835: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 9836: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
9837: item.options.length = 0;
9838: item.options[0] = new Option("","",true,true);
1.210 raeburn 9839: var idx = 0;
1.151 raeburn 9840: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 9841: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
9842: idx ++;
9843: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 9844: }
9845: }
9846: }
9847: }
9848: return;
9849: }
9850:
1.171 raeburn 9851: function hideSpares(balnum) {
1.150 raeburn 9852: var alltargets = new Array('$alltargets');
9853: var insttypes = new Array('$allinsttypes');
9854: var offloadtypes = new Array('primary','default');
9855:
1.171 raeburn 9856: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
9857: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 9858:
9859: var total = alltargets.length - 1;
9860: for (var i=0; i<offloadtypes; i++) {
9861: for (var j=0; j<total; j++) {
1.171 raeburn 9862: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
9863: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
9864: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 9865: }
1.150 raeburn 9866: }
9867: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 9868: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
9869: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 9870: if (insttypes[k] != '_LC_external') {
1.171 raeburn 9871: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
9872: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 9873: }
9874: }
9875: return;
9876: }
9877:
1.171 raeburn 9878: function checkOffloads(item,balnum,type) {
1.150 raeburn 9879: var alltargets = new Array('$alltargets');
9880: var offloadtypes = new Array('primary','default');
9881: if (item.checked) {
9882: var total = alltargets.length - 1;
9883: var other;
9884: if (type == offloadtypes[0]) {
1.151 raeburn 9885: other = offloadtypes[1];
1.150 raeburn 9886: } else {
1.151 raeburn 9887: other = offloadtypes[0];
1.150 raeburn 9888: }
9889: for (var i=0; i<total; i++) {
1.171 raeburn 9890: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 9891: if (server == item.value) {
1.171 raeburn 9892: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
9893: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 9894: }
9895: }
9896: }
9897: }
9898: return;
9899: }
9900:
1.171 raeburn 9901: function singleServerToggle(balnum,type) {
9902: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 9903: if (offloadtoSelIdx == 0) {
1.171 raeburn 9904: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
9905: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 9906:
9907: } else {
1.171 raeburn 9908: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
9909: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 9910: }
9911: return;
9912: }
9913:
1.171 raeburn 9914: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 9915: if (type == '_LC_external') {
1.171 raeburn 9916: return;
1.150 raeburn 9917: }
1.171 raeburn 9918: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 9919: for (var i=0; i<typesRules.length; i++) {
9920: if (formname.elements[typesRules[i]].checked) {
9921: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 9922: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
9923: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 9924: } else {
1.171 raeburn 9925: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
9926: }
9927: }
9928: }
9929: return;
9930: }
9931:
9932: function balancerDeleteChange(balnum) {
9933: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
9934: var baltotal = document.getElementById('loadbalancing_total').value;
9935: var addtarget;
9936: var removetarget;
9937: var action = 'delete';
9938: if (document.getElementById('loadbalancing_delete_'+balnum)) {
9939: var lonhost = hostitem.value;
9940: var currIdx = currBalancers.indexOf(lonhost);
9941: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
9942: if (currIdx != -1) {
9943: currBalancers.splice(currIdx,1);
9944: }
9945: addtarget = lonhost;
9946: } else {
9947: if (currIdx == -1) {
9948: currBalancers.push(lonhost);
9949: }
9950: removetarget = lonhost;
9951: action = 'undelete';
9952: }
9953: balancerChange(balnum,baltotal,action,addtarget,removetarget);
9954: }
9955: return;
9956: }
9957:
9958: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
9959: if (baltotal > 1) {
9960: var offloadtypes = new Array('primary','default');
9961: var alltargets = new Array('$alltargets');
9962: var insttypes = new Array('$allinsttypes');
9963: for (var i=0; i<baltotal; i++) {
9964: if (i != balnum) {
9965: for (var j=0; j<offloadtypes.length; j++) {
9966: var total = alltargets.length - 1;
9967: for (var k=0; k<total; k++) {
9968: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
9969: var server = serveritem.value;
9970: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
9971: if (server == addtarget) {
9972: serveritem.disabled = '';
9973: }
9974: }
9975: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
9976: if (server == removetarget) {
9977: serveritem.disabled = 'disabled';
9978: serveritem.checked = false;
9979: }
9980: }
9981: }
9982: }
9983: for (var j=0; j<insttypes.length; j++) {
9984: if (insttypes[j] != '_LC_external') {
9985: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
9986: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
9987: var currSel = singleserver.selectedIndex;
9988: var currVal = singleserver.options[currSel].value;
9989: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
9990: var numoptions = singleserver.options.length;
9991: var needsnew = 1;
9992: for (var k=0; k<numoptions; k++) {
9993: if (singleserver.options[k] == addtarget) {
9994: needsnew = 0;
9995: break;
9996: }
9997: }
9998: if (needsnew == 1) {
9999: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
10000: }
10001: }
10002: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
10003: singleserver.options.length = 0;
10004: if ((currVal) && (currVal != removetarget)) {
10005: singleserver.options[0] = new Option("","",false,false);
10006: } else {
10007: singleserver.options[0] = new Option("","",true,true);
10008: }
10009: var idx = 0;
10010: for (var m=0; m<alltargets.length; m++) {
10011: if (currBalancers.indexOf(alltargets[m]) == -1) {
10012: idx ++;
10013: if (currVal == alltargets[m]) {
10014: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
10015: } else {
10016: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
10017: }
10018: }
10019: }
10020: }
10021: }
10022: }
10023: }
1.150 raeburn 10024: }
10025: }
10026: }
10027: return;
10028: }
10029:
1.152 raeburn 10030: // ]]>
10031: </script>
10032:
10033: END
10034: }
10035:
10036: sub new_spares_js {
10037: my @sparestypes = ('primary','default');
10038: my $types = join("','",@sparestypes);
10039: my $select = &mt('Select');
10040: return <<"END";
10041:
10042: <script type="text/javascript">
10043: // <![CDATA[
10044:
10045: function updateNewSpares(formname,lonhost) {
10046: var types = new Array('$types');
10047: var include = new Array();
10048: var exclude = new Array();
10049: for (var i=0; i<types.length; i++) {
10050: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
10051: for (var j=0; j<spareboxes.length; j++) {
10052: if (formname.elements[spareboxes[j]].checked) {
10053: exclude.push(formname.elements[spareboxes[j]].value);
10054: } else {
10055: include.push(formname.elements[spareboxes[j]].value);
10056: }
10057: }
10058: }
10059: for (var i=0; i<types.length; i++) {
10060: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
10061: var selIdx = newSpare.selectedIndex;
10062: var currnew = newSpare.options[selIdx].value;
10063: var okSpares = new Array();
10064: for (var j=0; j<newSpare.options.length; j++) {
10065: var possible = newSpare.options[j].value;
10066: if (possible != '') {
10067: if (exclude.indexOf(possible) == -1) {
10068: okSpares.push(possible);
10069: } else {
10070: if (currnew == possible) {
10071: selIdx = 0;
10072: }
10073: }
10074: }
10075: }
10076: for (var k=0; k<include.length; k++) {
10077: if (okSpares.indexOf(include[k]) == -1) {
10078: okSpares.push(include[k]);
10079: }
10080: }
10081: okSpares.sort();
10082: newSpare.options.length = 0;
10083: if (selIdx == 0) {
10084: newSpare.options[0] = new Option("$select","",true,true);
10085: } else {
10086: newSpare.options[0] = new Option("$select","",false,false);
10087: }
10088: for (var m=0; m<okSpares.length; m++) {
10089: var idx = m+1;
10090: var selThis = 0;
10091: if (selIdx != 0) {
10092: if (okSpares[m] == currnew) {
10093: selThis = 1;
10094: }
10095: }
10096: if (selThis == 1) {
10097: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
10098: } else {
10099: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
10100: }
10101: }
10102: }
10103: return;
10104: }
10105:
10106: function checkNewSpares(lonhost,type) {
10107: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
10108: var chosen = newSpare.options[newSpare.selectedIndex].value;
10109: if (chosen != '') {
10110: var othertype;
10111: var othernewSpare;
10112: if (type == 'primary') {
10113: othernewSpare = document.getElementById('newspare_default_'+lonhost);
10114: }
10115: if (type == 'default') {
10116: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
10117: }
10118: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
10119: othernewSpare.selectedIndex = 0;
10120: }
10121: }
10122: return;
10123: }
10124:
10125: // ]]>
10126: </script>
10127:
10128: END
10129:
10130: }
10131:
10132: sub common_domprefs_js {
10133: return <<"END";
10134:
10135: <script type="text/javascript">
10136: // <![CDATA[
10137:
1.150 raeburn 10138: function getIndicesByName(formname,item) {
1.152 raeburn 10139: var group = new Array();
1.150 raeburn 10140: for (var i=0;i<formname.elements.length;i++) {
10141: if (formname.elements[i].name == item) {
1.152 raeburn 10142: group.push(formname.elements[i].id);
1.150 raeburn 10143: }
10144: }
1.152 raeburn 10145: return group;
1.150 raeburn 10146: }
10147:
10148: // ]]>
10149: </script>
10150:
10151: END
1.152 raeburn 10152:
1.150 raeburn 10153: }
10154:
1.165 raeburn 10155: sub recaptcha_js {
10156: my %lt = &captcha_phrases();
10157: return <<"END";
10158:
10159: <script type="text/javascript">
10160: // <![CDATA[
10161:
10162: function updateCaptcha(caller,context) {
10163: var privitem;
10164: var pubitem;
10165: var privtext;
10166: var pubtext;
10167: if (document.getElementById(context+'_recaptchapub')) {
10168: pubitem = document.getElementById(context+'_recaptchapub');
10169: } else {
10170: return;
10171: }
10172: if (document.getElementById(context+'_recaptchapriv')) {
10173: privitem = document.getElementById(context+'_recaptchapriv');
10174: } else {
10175: return;
10176: }
10177: if (document.getElementById(context+'_recaptchapubtxt')) {
10178: pubtext = document.getElementById(context+'_recaptchapubtxt');
10179: } else {
10180: return;
10181: }
10182: if (document.getElementById(context+'_recaptchaprivtxt')) {
10183: privtext = document.getElementById(context+'_recaptchaprivtxt');
10184: } else {
10185: return;
10186: }
10187: if (caller.checked) {
10188: if (caller.value == 'recaptcha') {
10189: pubitem.type = 'text';
10190: privitem.type = 'text';
10191: pubitem.size = '40';
10192: privitem.size = '40';
10193: pubtext.innerHTML = "$lt{'pub'}";
10194: privtext.innerHTML = "$lt{'priv'}";
10195: } else {
10196: pubitem.type = 'hidden';
10197: privitem.type = 'hidden';
10198: pubtext.innerHTML = '';
10199: privtext.innerHTML = '';
10200: }
10201: }
10202: return;
10203: }
10204:
10205: // ]]>
10206: </script>
10207:
10208: END
10209:
10210: }
10211:
1.192 raeburn 10212: sub credits_js {
10213: return <<"END";
10214:
10215: <script type="text/javascript">
10216: // <![CDATA[
10217:
10218: function toggleCredits(domForm) {
10219: if (document.getElementById('credits')) {
10220: creditsitem = document.getElementById('credits');
10221: var creditsLength = domForm.coursecredits.length;
10222: if (creditsLength) {
10223: var currval;
10224: for (var i=0; i<creditsLength; i++) {
10225: if (domForm.coursecredits[i].checked) {
10226: currval = domForm.coursecredits[i].value;
10227: }
10228: }
10229: if (currval == 1) {
10230: creditsitem.style.display = 'block';
10231: } else {
10232: creditsitem.style.display = 'none';
10233: }
10234: }
10235: }
10236: return;
10237: }
10238:
10239: // ]]>
10240: </script>
10241:
10242: END
10243:
10244: }
10245:
1.165 raeburn 10246: sub captcha_phrases {
10247: return &Apache::lonlocal::texthash (
10248: priv => 'Private key',
10249: pub => 'Public key',
10250: original => 'original (CAPTCHA)',
10251: recaptcha => 'successor (ReCAPTCHA)',
10252: notused => 'unused',
10253: );
10254: }
10255:
1.205 raeburn 10256: sub devalidate_remote_domconfs {
1.212 raeburn 10257: my ($dom,$cachekeys) = @_;
10258: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 10259: my %servers = &Apache::lonnet::internet_dom_servers($dom);
10260: my %thismachine;
10261: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.212 raeburn 10262: my @posscached = ('domainconfig','domdefaults');
1.205 raeburn 10263: if (keys(%servers) > 1) {
10264: foreach my $server (keys(%servers)) {
10265: next if ($thismachine{$server});
1.212 raeburn 10266: my @cached;
10267: foreach my $name (@posscached) {
10268: if ($cachekeys->{$name}) {
10269: push(@cached,&escape($name).':'.&escape($dom));
10270: }
10271: }
10272: if (@cached) {
10273: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
10274: }
1.205 raeburn 10275: }
10276: }
10277: return;
10278: }
10279:
1.3 raeburn 10280: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>