Annotation of loncom/interface/domainprefs.pm, revision 1.221
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.221 ! raeburn 4: # $Id: domainprefs.pm,v 1.220 2014/01/01 16:00:11 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ##############################################################
30:
1.101 raeburn 31: =pod
32:
33: =head1 NAME
34:
35: Apache::domainprefs.pm
36:
37: =head1 SYNOPSIS
38:
39: Handles configuration of a LON-CAPA domain.
40:
41: This is part of the LearningOnline Network with CAPA project
42: described at http://www.lon-capa.org.
43:
44:
45: =head1 OVERVIEW
46:
47: Each institution using LON-CAPA will typically have a single domain designated
1.183 bisitz 48: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 49: may define a default set of logos and a color scheme which can be used to "brand"
50: the LON-CAPA instance. In addition, an institution will typically have a language
51: and timezone which are used for the majority of courses.
52:
53: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
54: host of other domain-wide settings which determine the types of functionality
55: available to users and courses in the domain.
56:
57: There is also a mechanism to configure cataloging of courses in the domain, and
58: controls on the operation of automated processes which govern such things as
59: roster updates, user directory updates and processing of course requests.
60:
61: The domain coordination manual which is built dynamically on install/update of
62: LON-CAPA from the relevant help items provides more information about domain
63: configuration.
64:
65: Most of the domain settings are stored in the configuration.db GDBM file which is
66: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
67: where $dom is the domain. The configuration.db stores settings in a number of
68: frozen hashes of hashes. In a few cases, domain information must be uploaded to
69: the domain as files (e.g., image files for logos etc., or plain text files for
70: bubblesheet formats). In this case the domainprefs.pm must be running in a user
71: session hosted on the primary library server in the domain, as these files are
72: stored in author space belonging to a special $dom-domainconfig user.
73:
74: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
75: the current settings, and provides an interface to make modifications.
76:
77: =head1 SUBROUTINES
78:
79: =over
80:
81: =item print_quotas()
82:
83: Inputs: 4
84:
85: $dom,$settings,$rowtotal,$action.
86:
87: $dom is the domain, $settings is a reference to a hash of current settings for
88: the current context, $rowtotal is a reference to the scalar used to record the
1.210 raeburn 89: number of rows displayed on the page, and $action is the context (quotas,
1.163 raeburn 90: requestcourses or requestauthor).
1.101 raeburn 91:
92: The print_quotas routine was orginally created to display/store information
93: about default quota sizes for portfolio spaces for the different types of
94: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
95: but is now also used to manage availability of user tools:
96: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.197 raeburn 97: used by course owners to request creation of a course, and to display/store
98: default quota sizes for authoring spaces.
1.101 raeburn 99:
100: Outputs: 1
101:
102: $datatable - HTML containing form elements which allow settings to be changed.
103:
104: In the case of course requests, radio buttons are displayed for each institutional
105: affiliate type (and also default, and _LC_adv) for each of the course types
1.216 raeburn 106: (official, unofficial, community, and textbook). In each case the radio buttons
107: allow the selection of one of four values:
1.101 raeburn 108:
1.104 raeburn 109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 110: which have the following effects:
111:
112: 0
113:
114: =over
115:
116: - course requests are not allowed for this course types/affiliation
117:
118: =back
119:
1.104 raeburn 120: approval
1.101 raeburn 121:
122: =over
123:
124: - course requests must be approved by a Doman Coordinator in the
125: course's domain
126:
127: =back
128:
129: validate
130:
131: =over
132:
133: - an institutional validation (e.g., check requestor is instructor
134: of record) needs to be passed before the course will be created. The required
135: validation is in localenroll.pm on the primary library server for the course
136: domain.
137:
138: =back
139:
140: autolimit
141:
142: =over
143:
1.143 raeburn 144: - course requests will be processed automatically up to a limit of
1.101 raeburn 145: N requests for the course type for the particular requestor.
146: If N is undefined, there is no limit to the number of course requests
147: which a course owner may submit and have processed automatically.
148:
149: =back
150:
151: =item modify_quotas()
152:
153: =back
154:
155: =cut
156:
1.1 raeburn 157: package Apache::domainprefs;
158:
159: use strict;
160: use Apache::Constants qw(:common :http);
161: use Apache::lonnet;
162: use Apache::loncommon();
163: use Apache::lonhtmlcommon();
164: use Apache::lonlocal;
1.43 raeburn 165: use Apache::lonmsg();
1.91 raeburn 166: use Apache::lonconfigsettings;
1.69 raeburn 167: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 168: use LONCAPA::Enrollment;
1.81 raeburn 169: use LONCAPA::lonauthcgi();
1.9 raeburn 170: use File::Copy;
1.43 raeburn 171: use Locale::Language;
1.62 raeburn 172: use DateTime::TimeZone;
1.68 raeburn 173: use DateTime::Locale;
1.1 raeburn 174:
1.155 raeburn 175: my $registered_cleanup;
176: my $modified_urls;
177:
1.1 raeburn 178: sub handler {
179: my $r=shift;
180: if ($r->header_only) {
181: &Apache::loncommon::content_type($r,'text/html');
182: $r->send_http_header;
183: return OK;
184: }
185:
1.91 raeburn 186: my $context = 'domain';
1.1 raeburn 187: my $dom = $env{'request.role.domain'};
1.5 albertel 188: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 189: if (&Apache::lonnet::allowed('mau',$dom)) {
190: &Apache::loncommon::content_type($r,'text/html');
191: $r->send_http_header;
192: } else {
193: $env{'user.error.msg'}=
194: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
195: return HTTP_NOT_ACCEPTABLE;
196: }
1.155 raeburn 197:
198: $registered_cleanup=0;
199: @{$modified_urls}=();
200:
1.1 raeburn 201: &Apache::lonhtmlcommon::clear_breadcrumbs();
202: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 203: ['phase','actions']);
1.30 raeburn 204: my $phase = 'pickactions';
1.3 raeburn 205: if ( exists($env{'form.phase'}) ) {
206: $phase = $env{'form.phase'};
207: }
1.150 raeburn 208: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 209: my %domconfig =
1.6 raeburn 210: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 211: 'quotas','autoenroll','autoupdate','autocreate',
212: 'directorysrch','usercreation','usermodification',
213: 'contacts','defaults','scantron','coursecategories',
214: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 215: 'coursedefaults','usersessions','loadbalancing',
216: 'requestauthor'],$dom);
1.43 raeburn 217: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 218: 'autoupdate','autocreate','directorysrch','contacts',
1.48 raeburn 219: 'usercreation','usermodification','scantron',
1.163 raeburn 220: 'requestcourses','requestauthor','coursecategories',
221: 'serverstatuses','helpsettings',
1.137 raeburn 222: 'coursedefaults','usersessions');
1.171 raeburn 223: my %existing;
224: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
225: %existing = %{$domconfig{'loadbalancing'}};
226: }
227: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 228: push(@prefs_order,'loadbalancing');
229: }
1.30 raeburn 230: my %prefs = (
231: 'rolecolors' =>
232: { text => 'Default color schemes',
1.67 raeburn 233: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 234: header => [{col1 => 'Student Settings',
235: col2 => '',},
236: {col1 => 'Coordinator Settings',
237: col2 => '',},
238: {col1 => 'Author Settings',
239: col2 => '',},
240: {col1 => 'Administrator Settings',
241: col2 => '',}],
242: },
1.110 raeburn 243: 'login' =>
1.30 raeburn 244: { text => 'Log-in page options',
1.67 raeburn 245: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 246: header => [{col1 => 'Log-in Page Items',
247: col2 => '',},
248: {col1 => 'Log-in Help',
249: col2 => 'Value'}],
1.30 raeburn 250: },
1.43 raeburn 251: 'defaults' =>
1.141 raeburn 252: { text => 'Default authentication/language/timezone/portal',
1.67 raeburn 253: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 254: header => [{col1 => 'Setting',
255: col2 => 'Value'}],
256: },
1.30 raeburn 257: 'quotas' =>
1.197 raeburn 258: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 259: help => 'Domain_Configuration_Quotas',
1.77 raeburn 260: header => [{col1 => 'User affiliation',
1.72 raeburn 261: col2 => 'Available tools',
1.213 raeburn 262: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.30 raeburn 263: },
264: 'autoenroll' =>
265: { text => 'Auto-enrollment settings',
1.67 raeburn 266: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 267: header => [{col1 => 'Configuration setting',
268: col2 => 'Value(s)'}],
269: },
270: 'autoupdate' =>
271: { text => 'Auto-update settings',
1.67 raeburn 272: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 273: header => [{col1 => 'Setting',
274: col2 => 'Value',},
1.131 raeburn 275: {col1 => 'Setting',
276: col2 => 'Affiliation'},
1.43 raeburn 277: {col1 => 'User population',
1.131 raeburn 278: col2 => 'Updateable user data'}],
1.30 raeburn 279: },
1.125 raeburn 280: 'autocreate' =>
281: { text => 'Auto-course creation settings',
282: help => 'Domain_Configuration_Auto_Creation',
283: header => [{col1 => 'Configuration Setting',
284: col2 => 'Value',}],
285: },
1.30 raeburn 286: 'directorysrch' =>
287: { text => 'Institutional directory searches',
1.67 raeburn 288: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 289: header => [{col1 => 'Setting',
290: col2 => 'Value',}],
291: },
292: 'contacts' =>
293: { text => 'Contact Information',
1.67 raeburn 294: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 295: header => [{col1 => 'Setting',
296: col2 => 'Value',}],
297: },
298:
299: 'usercreation' =>
300: { text => 'User creation',
1.67 raeburn 301: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 302: header => [{col1 => 'Format rule type',
303: col2 => 'Format rules in force'},
1.34 raeburn 304: {col1 => 'User account creation',
305: col2 => 'Usernames which may be created',},
1.30 raeburn 306: {col1 => 'Context',
1.43 raeburn 307: col2 => 'Assignable authentication types'}],
1.30 raeburn 308: },
1.69 raeburn 309: 'usermodification' =>
1.33 raeburn 310: { text => 'User modification',
1.67 raeburn 311: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 312: header => [{col1 => 'Target user has role',
313: col2 => 'User information updateable in author context'},
314: {col1 => 'Target user has role',
1.63 raeburn 315: col2 => 'User information updateable in course context'},
316: {col1 => "Status of user",
317: col2 => 'Information settable when self-creating account (if directory data blank)'}],
1.33 raeburn 318: },
1.69 raeburn 319: 'scantron' =>
1.95 www 320: { text => 'Bubblesheet format file',
1.67 raeburn 321: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 322: header => [ {col1 => 'Item',
323: col2 => '',
324: }],
325: },
1.86 raeburn 326: 'requestcourses' =>
327: {text => 'Request creation of courses',
328: help => 'Domain_Configuration_Request_Courses',
329: header => [{col1 => 'User affiliation',
1.102 raeburn 330: col2 => 'Availability/Processing of requests',},
331: {col1 => 'Setting',
1.216 raeburn 332: col2 => 'Value'},
333: {col1 => 'Available textbooks',
334: col2 => ''}],
1.86 raeburn 335: },
1.163 raeburn 336: 'requestauthor' =>
337: {text => 'Request authoring space',
338: help => 'Domain_Configuration_Request_Author',
339: header => [{col1 => 'User affiliation',
340: col2 => 'Availability/Processing of requests',},
341: {col1 => 'Setting',
342: col2 => 'Value'}],
343: },
1.69 raeburn 344: 'coursecategories' =>
1.120 raeburn 345: { text => 'Cataloging of courses/communities',
1.67 raeburn 346: help => 'Domain_Configuration_Cataloging_Courses',
1.69 raeburn 347: header => [{col1 => 'Category settings',
1.57 raeburn 348: col2 => '',},
349: {col1 => 'Categories',
350: col2 => '',
351: }],
1.69 raeburn 352: },
353: 'serverstatuses' =>
1.77 raeburn 354: {text => 'Access to server status pages',
1.69 raeburn 355: help => 'Domain_Configuration_Server_Status',
356: header => [{col1 => 'Status Page',
357: col2 => 'Other named users',
358: col3 => 'Specific IPs',
359: }],
360: },
1.118 jms 361: 'helpsettings' =>
362: {text => 'Help page settings',
363: help => 'Domain_Configuration_Help_Settings',
1.166 raeburn 364: header => [{col1 => 'Help Settings (logged-in users)',
365: col2 => 'Value'}],
1.118 jms 366: },
1.121 raeburn 367: 'coursedefaults' =>
368: {text => 'Course/Community defaults',
369: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 370: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
371: col2 => 'Value',},
372: {col1 => 'Defaults which can be overridden for each course by a DC',
373: col2 => 'Value',},],
1.121 raeburn 374: },
1.120 raeburn 375: 'privacy' =>
376: {text => 'User Privacy',
377: help => 'Domain_Configuration_User_Privacy',
378: header => [{col1 => 'Setting',
379: col2 => 'Value',}],
380: },
1.141 raeburn 381: 'usersessions' =>
1.145 raeburn 382: {text => 'User session hosting/offloading',
1.137 raeburn 383: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 384: header => [{col1 => 'Domain server',
385: col2 => 'Servers to offload sessions to when busy'},
386: {col1 => 'Hosting of users from other domains',
1.137 raeburn 387: col2 => 'Rules'},
388: {col1 => "Hosting domain's own users elsewhere",
389: col2 => 'Rules'}],
390: },
1.150 raeburn 391: 'loadbalancing' =>
1.185 raeburn 392: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 393: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 394: header => [{col1 => 'Balancers',
1.150 raeburn 395: col2 => 'Default destinations',
1.183 bisitz 396: col3 => 'User affiliation',
1.150 raeburn 397: col4 => 'Overrides'},
398: ],
399: },
1.3 raeburn 400: );
1.110 raeburn 401: if (keys(%servers) > 1) {
402: $prefs{'login'} = { text => 'Log-in page options',
403: help => 'Domain_Configuration_Login_Page',
404: header => [{col1 => 'Log-in Service',
405: col2 => 'Server Setting',},
406: {col1 => 'Log-in Page Items',
1.168 raeburn 407: col2 => ''},
408: {col1 => 'Log-in Help',
409: col2 => 'Value'}],
1.110 raeburn 410: };
411: }
1.174 foxr 412:
1.6 raeburn 413: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 414: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 415: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 416: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 417: text=>"Settings to display/modify"});
1.9 raeburn 418: my $confname = $dom.'-domainconfig';
1.174 foxr 419:
1.3 raeburn 420: if ($phase eq 'process') {
1.212 raeburn 421: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
422: \%prefs,\%domconfig,$confname,\@roles);
423: if (ref($result) eq 'HASH') {
1.205 raeburn 424: $r->rflush();
1.212 raeburn 425: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 426: }
1.30 raeburn 427: } elsif ($phase eq 'display') {
1.192 raeburn 428: my $js = &recaptcha_js().
429: &credits_js();
1.171 raeburn 430: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 431: my ($othertitle,$usertypes,$types) =
432: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 433: $js .= &lonbalance_targets_js($dom,$types,\%servers,
434: $domconfig{'loadbalancing'}).
1.170 raeburn 435: &new_spares_js().
436: &common_domprefs_js().
437: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 438: }
1.216 raeburn 439: if (grep(/^requestcourses$/,@actions)) {
440: my $javascript_validations;
441: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
442: $js .= <<END;
443: <script type="text/javascript">
444: $javascript_validations
445: </script>
446: $coursebrowserjs
447: END
448: }
1.150 raeburn 449: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 450: } else {
1.180 raeburn 451: # check if domconfig user exists for the domain.
452: my $servadm = $r->dir_config('lonAdmEMail');
453: my ($configuserok,$author_ok,$switchserver) =
454: &config_check($dom,$confname,$servadm);
455: unless ($configuserok eq 'ok') {
1.181 raeburn 456: &Apache::lonconfigsettings::print_header($r,$phase,$context);
457: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 458: $confname).
1.181 raeburn 459: '<br />'
460: );
1.180 raeburn 461: if ($switchserver) {
1.181 raeburn 462: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
463: '<br />'.
464: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
465: '<br />'.
466: &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
467: '<br />'.
468: &mt('To do that now, use the following link: [_1]',$switchserver)
469: );
470: } else {
471: $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
472: '<br />'.
473: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
474: );
1.180 raeburn 475: }
476: $r->print(&Apache::loncommon::end_page());
477: return OK;
478: }
1.21 raeburn 479: if (keys(%domconfig) == 0) {
480: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 481: my @ids=&Apache::lonnet::current_machine_ids();
482: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 483: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 484: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 485: my $custom_img_count = 0;
486: foreach my $img (@loginimages) {
487: if ($designhash{$dom.'.login.'.$img} ne '') {
488: $custom_img_count ++;
489: }
490: }
491: foreach my $role (@roles) {
492: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
493: $custom_img_count ++;
494: }
495: }
496: if ($custom_img_count > 0) {
1.94 raeburn 497: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 498: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 499: $r->print(
500: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
501: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
502: &mt("Thereafter, (with a Domain Coordinator role selected in the domain) you will be able to update settings when logged in to any server in the LON-CAPA network.").'<br />'.
503: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
504: if ($switch_server) {
1.30 raeburn 505: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 506: }
1.91 raeburn 507: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 508: return OK;
509: }
510: }
511: }
1.91 raeburn 512: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 513: }
514: return OK;
515: }
516:
517: sub process_changes {
1.205 raeburn 518: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 519: my %domconfig;
520: if (ref($values) eq 'HASH') {
521: %domconfig = %{$values};
522: }
1.3 raeburn 523: my $output;
524: if ($action eq 'login') {
1.205 raeburn 525: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 526: } elsif ($action eq 'rolecolors') {
1.9 raeburn 527: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 528: $lastactref,%domconfig);
1.3 raeburn 529: } elsif ($action eq 'quotas') {
1.216 raeburn 530: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 531: } elsif ($action eq 'autoenroll') {
1.205 raeburn 532: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 533: } elsif ($action eq 'autoupdate') {
534: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 535: } elsif ($action eq 'autocreate') {
536: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 537: } elsif ($action eq 'directorysrch') {
538: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 539: } elsif ($action eq 'usercreation') {
1.28 raeburn 540: $output = &modify_usercreation($dom,%domconfig);
1.33 raeburn 541: } elsif ($action eq 'usermodification') {
542: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 543: } elsif ($action eq 'contacts') {
1.205 raeburn 544: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 545: } elsif ($action eq 'defaults') {
1.212 raeburn 546: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 547: } elsif ($action eq 'scantron') {
1.205 raeburn 548: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 549: } elsif ($action eq 'coursecategories') {
550: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 551: } elsif ($action eq 'serverstatuses') {
552: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 553: } elsif ($action eq 'requestcourses') {
1.216 raeburn 554: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 555: } elsif ($action eq 'requestauthor') {
1.216 raeburn 556: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 557: } elsif ($action eq 'helpsettings') {
1.122 jms 558: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121 raeburn 559: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 560: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.137 raeburn 561: } elsif ($action eq 'usersessions') {
1.212 raeburn 562: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 563: } elsif ($action eq 'loadbalancing') {
564: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 565: }
566: return $output;
567: }
568:
569: sub print_config_box {
1.9 raeburn 570: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 571: my $rowtotal = 0;
1.49 raeburn 572: my $output;
573: if ($action eq 'coursecategories') {
574: $output = &coursecategories_javascript($settings);
1.91 raeburn 575: }
1.49 raeburn 576: $output .=
1.30 raeburn 577: '<table class="LC_nested_outer">
1.3 raeburn 578: <tr>
1.66 raeburn 579: <th align="left" valign="middle"><span class="LC_nobreak">'.
580: &mt($item->{text}).' '.
581: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
582: '</tr>';
1.30 raeburn 583: $rowtotal ++;
1.110 raeburn 584: my $numheaders = 1;
585: if (ref($item->{'header'}) eq 'ARRAY') {
586: $numheaders = scalar(@{$item->{'header'}});
587: }
588: if ($numheaders > 1) {
1.64 raeburn 589: my $colspan = '';
1.145 raeburn 590: my $rightcolspan = '';
1.210 raeburn 591: if (($action eq 'rolecolors') || ($action eq 'coursecategories') ||
1.168 raeburn 592: (($action eq 'login') && ($numheaders < 3))) {
1.64 raeburn 593: $colspan = ' colspan="2"';
594: }
1.145 raeburn 595: if ($action eq 'usersessions') {
596: $rightcolspan = ' colspan="3"';
597: }
1.30 raeburn 598: $output .= '
1.3 raeburn 599: <tr>
600: <td>
601: <table class="LC_nested">
602: <tr class="LC_info_row">
1.59 bisitz 603: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 604: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 605: </tr>';
1.69 raeburn 606: $rowtotal ++;
1.6 raeburn 607: if ($action eq 'autoupdate') {
1.30 raeburn 608: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 609: } elsif ($action eq 'usercreation') {
1.33 raeburn 610: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
611: } elsif ($action eq 'usermodification') {
612: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57 raeburn 613: } elsif ($action eq 'coursecategories') {
614: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 615: } elsif ($action eq 'login') {
1.168 raeburn 616: if ($numheaders == 3) {
617: $colspan = ' colspan="2"';
618: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
619: } else {
620: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
621: }
1.102 raeburn 622: } elsif ($action eq 'requestcourses') {
623: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.163 raeburn 624: } elsif ($action eq 'requestauthor') {
625: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.137 raeburn 626: } elsif ($action eq 'usersessions') {
627: $output .= &print_usersessions('top',$dom,$settings,\$rowtotal);
1.122 jms 628: } elsif ($action eq 'rolecolors') {
1.30 raeburn 629: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.139 raeburn 630: } elsif ($action eq 'coursedefaults') {
631: $output .= &print_coursedefaults('top',$dom,$settings,\$rowtotal);
1.6 raeburn 632: }
1.30 raeburn 633: $output .= '
1.6 raeburn 634: </table>
635: </td>
636: </tr>
637: <tr>
638: <td>
639: <table class="LC_nested">
640: <tr class="LC_info_row">
1.59 bisitz 641: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57 raeburn 642: $output .= '
1.59 bisitz 643: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 644: </tr>';
645: $rowtotal ++;
1.6 raeburn 646: if ($action eq 'autoupdate') {
1.131 raeburn 647: $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
648: </table>
649: </td>
650: </tr>
651: <tr>
652: <td>
653: <table class="LC_nested">
654: <tr class="LC_info_row">
655: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
656: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
657: &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
658: $rowtotal ++;
1.28 raeburn 659: } elsif ($action eq 'usercreation') {
1.34 raeburn 660: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
661: </table>
662: </td>
663: </tr>
664: <tr>
665: <td>
666: <table class="LC_nested">
667: <tr class="LC_info_row">
1.59 bisitz 668: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
669: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.34 raeburn 670: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
671: $rowtotal ++;
1.33 raeburn 672: } elsif ($action eq 'usermodification') {
1.63 raeburn 673: $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
674: </table>
675: </td>
676: </tr>
677: <tr>
678: <td>
679: <table class="LC_nested">
680: <tr class="LC_info_row">
681: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 682: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.63 raeburn 683: &print_usermodification('bottom',$dom,$settings,\$rowtotal);
684: $rowtotal ++;
1.57 raeburn 685: } elsif ($action eq 'coursecategories') {
686: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 687: } elsif ($action eq 'login') {
1.168 raeburn 688: if ($numheaders == 3) {
689: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
690: </table>
691: </td>
692: </tr>
693: <tr>
694: <td>
695: <table class="LC_nested">
696: <tr class="LC_info_row">
697: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 698: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 699: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
700: $rowtotal ++;
701: } else {
702: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
703: }
1.102 raeburn 704: } elsif ($action eq 'requestcourses') {
1.216 raeburn 705: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal).
706: &print_studentcode($settings,\$rowtotal).'
707: </table>
708: </td>
709: </tr>
710: <tr>
711: <td>
712: <table class="LC_nested">
713: <tr class="LC_info_row">
714: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
715: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
716: &print_textbookcourses($dom,$settings,\$rowtotal);
1.163 raeburn 717: } elsif ($action eq 'requestauthor') {
718: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.137 raeburn 719: } elsif ($action eq 'usersessions') {
1.145 raeburn 720: $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
721: </table>
722: </td>
723: </tr>
724: <tr>
725: <td>
726: <table class="LC_nested">
727: <tr class="LC_info_row">
728: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
729: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
730: &print_usersessions('bottom',$dom,$settings,\$rowtotal);
731: $rowtotal ++;
1.139 raeburn 732: } elsif ($action eq 'coursedefaults') {
733: $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.122 jms 734: } elsif ($action eq 'rolecolors') {
1.30 raeburn 735: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 736: </table>
737: </td>
738: </tr>
739: <tr>
740: <td>
741: <table class="LC_nested">
742: <tr class="LC_info_row">
1.69 raeburn 743: <td class="LC_left_item"'.$colspan.' valign="top">'.
744: &mt($item->{'header'}->[2]->{'col1'}).'</td>
745: <td class="LC_right_item" valign="top">'.
746: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 747: </tr>'.
1.30 raeburn 748: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 749: </table>
750: </td>
751: </tr>
752: <tr>
753: <td>
754: <table class="LC_nested">
755: <tr class="LC_info_row">
1.59 bisitz 756: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
757: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 758: </tr>'.
1.30 raeburn 759: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
760: $rowtotal += 2;
1.6 raeburn 761: }
1.3 raeburn 762: } else {
1.30 raeburn 763: $output .= '
1.3 raeburn 764: <tr>
765: <td>
766: <table class="LC_nested">
1.30 raeburn 767: <tr class="LC_info_row">';
1.24 raeburn 768: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 769: $output .= '
1.59 bisitz 770: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 771: } elsif ($action eq 'serverstatuses') {
772: $output .= '
773: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
774: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
775:
1.6 raeburn 776: } else {
1.30 raeburn 777: $output .= '
1.69 raeburn 778: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
779: }
1.72 raeburn 780: if (defined($item->{'header'}->[0]->{'col3'})) {
781: $output .= '<td class="LC_left_item" valign="top">'.
782: &mt($item->{'header'}->[0]->{'col2'});
783: if ($action eq 'serverstatuses') {
784: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
785: }
1.69 raeburn 786: } else {
787: $output .= '<td class="LC_right_item" valign="top">'.
788: &mt($item->{'header'}->[0]->{'col2'});
789: }
790: $output .= '</td>';
791: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 792: if (defined($item->{'header'}->[0]->{'col4'})) {
793: $output .= '<td class="LC_left_item" valign="top">'.
794: &mt($item->{'header'}->[0]->{'col3'});
795: } else {
796: $output .= '<td class="LC_right_item" valign="top">'.
797: &mt($item->{'header'}->[0]->{'col3'});
798: }
1.69 raeburn 799: if ($action eq 'serverstatuses') {
800: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
801: }
802: $output .= '</td>';
1.6 raeburn 803: }
1.150 raeburn 804: if ($item->{'header'}->[0]->{'col4'}) {
805: $output .= '<td class="LC_right_item" valign="top">'.
806: &mt($item->{'header'}->[0]->{'col4'});
807: }
1.69 raeburn 808: $output .= '</tr>';
1.48 raeburn 809: $rowtotal ++;
1.168 raeburn 810: if ($action eq 'quotas') {
1.86 raeburn 811: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3 raeburn 812: } elsif ($action eq 'autoenroll') {
1.30 raeburn 813: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125 raeburn 814: } elsif ($action eq 'autocreate') {
815: $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23 raeburn 816: } elsif ($action eq 'directorysrch') {
1.30 raeburn 817: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 818: } elsif ($action eq 'contacts') {
1.30 raeburn 819: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 raeburn 820: } elsif ($action eq 'defaults') {
1.212 raeburn 821: $output .= &print_defaults($dom,$settings,\$rowtotal);
1.46 raeburn 822: } elsif ($action eq 'scantron') {
823: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69 raeburn 824: } elsif ($action eq 'serverstatuses') {
825: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118 jms 826: } elsif ($action eq 'helpsettings') {
1.168 raeburn 827: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.150 raeburn 828: } elsif ($action eq 'loadbalancing') {
829: $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.121 raeburn 830: }
1.3 raeburn 831: }
1.30 raeburn 832: $output .= '
1.3 raeburn 833: </table>
834: </td>
835: </tr>
1.30 raeburn 836: </table><br />';
837: return ($output,$rowtotal);
1.1 raeburn 838: }
839:
1.3 raeburn 840: sub print_login {
1.168 raeburn 841: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 842: my ($css_class,$datatable);
1.6 raeburn 843: my %choices = &login_choices();
1.110 raeburn 844:
1.168 raeburn 845: if ($caller eq 'service') {
1.149 raeburn 846: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 847: my $choice = $choices{'disallowlogin'};
848: $css_class = ' class="LC_odd_row"';
1.128 raeburn 849: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 850: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 851: '<th>'.$choices{'server'}.'</th>'.
852: '<th>'.$choices{'serverpath'}.'</th>'.
853: '<th>'.$choices{'custompath'}.'</th>'.
854: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 855: my %disallowed;
856: if (ref($settings) eq 'HASH') {
857: if (ref($settings->{'loginvia'}) eq 'HASH') {
858: %disallowed = %{$settings->{'loginvia'}};
859: }
860: }
861: foreach my $lonhost (sort(keys(%servers))) {
862: my $direct = 'selected="selected"';
1.128 raeburn 863: if (ref($disallowed{$lonhost}) eq 'HASH') {
864: if ($disallowed{$lonhost}{'server'} ne '') {
865: $direct = '';
866: }
1.110 raeburn 867: }
1.115 raeburn 868: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 869: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 870: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
871: '</option>';
1.184 raeburn 872: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 873: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 874: my $selected = '';
1.128 raeburn 875: if (ref($disallowed{$lonhost}) eq 'HASH') {
876: if ($hostid eq $disallowed{$lonhost}{'server'}) {
877: $selected = 'selected="selected"';
878: }
1.110 raeburn 879: }
880: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
881: $servers{$hostid}.'</option>';
882: }
1.128 raeburn 883: $datatable .= '</select></td>'.
884: '<td><select name="'.$lonhost.'_serverpath">';
885: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
886: my $pathname = $path;
887: if ($path eq 'custom') {
888: $pathname = &mt('Custom Path').' ->';
889: }
890: my $selected = '';
891: if (ref($disallowed{$lonhost}) eq 'HASH') {
892: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
893: $selected = 'selected="selected"';
894: }
895: } elsif ($path eq '') {
896: $selected = 'selected="selected"';
897: }
898: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
899: }
900: $datatable .= '</select></td>';
901: my ($custom,$exempt);
902: if (ref($disallowed{$lonhost}) eq 'HASH') {
903: $custom = $disallowed{$lonhost}{'custompath'};
904: $exempt = $disallowed{$lonhost}{'exempt'};
905: }
906: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
907: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
908: '</tr>';
1.110 raeburn 909: }
910: $datatable .= '</table></td></tr>';
911: return $datatable;
1.168 raeburn 912: } elsif ($caller eq 'page') {
913: my %defaultchecked = (
914: 'coursecatalog' => 'on',
1.188 raeburn 915: 'helpdesk' => 'on',
1.168 raeburn 916: 'adminmail' => 'off',
917: 'newuser' => 'off',
918: );
1.188 raeburn 919: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 920: my (%checkedon,%checkedoff);
1.42 raeburn 921: foreach my $item (@toggles) {
1.168 raeburn 922: if ($defaultchecked{$item} eq 'on') {
923: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 924: $checkedoff{$item} = ' ';
1.168 raeburn 925: } elsif ($defaultchecked{$item} eq 'off') {
926: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 927: $checkedon{$item} = ' ';
928: }
1.1 raeburn 929: }
1.168 raeburn 930: my @images = ('img','logo','domlogo','login');
931: my @logintext = ('textcol','bgcol');
932: my @bgs = ('pgbg','mainbg','sidebg');
933: my @links = ('link','alink','vlink');
934: my %designhash = &Apache::loncommon::get_domainconf($dom);
935: my %defaultdesign = %Apache::loncommon::defaultdesign;
936: my (%is_custom,%designs);
937: my %defaults = (
938: font => $defaultdesign{'login.font'},
939: );
1.6 raeburn 940: foreach my $item (@images) {
1.168 raeburn 941: $defaults{$item} = $defaultdesign{'login.'.$item};
942: $defaults{'showlogo'}{$item} = 1;
943: }
944: foreach my $item (@bgs) {
945: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 946: }
1.41 raeburn 947: foreach my $item (@logintext) {
1.168 raeburn 948: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 949: }
1.168 raeburn 950: foreach my $item (@links) {
951: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 952: }
1.168 raeburn 953: if (ref($settings) eq 'HASH') {
954: foreach my $item (@toggles) {
955: if ($settings->{$item} eq '1') {
956: $checkedon{$item} = ' checked="checked" ';
957: $checkedoff{$item} = ' ';
958: } elsif ($settings->{$item} eq '0') {
959: $checkedoff{$item} = ' checked="checked" ';
960: $checkedon{$item} = ' ';
961: }
962: }
963: foreach my $item (@images) {
964: if (defined($settings->{$item})) {
965: $designs{$item} = $settings->{$item};
966: $is_custom{$item} = 1;
967: }
968: if (defined($settings->{'showlogo'}{$item})) {
969: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
970: }
971: }
972: foreach my $item (@logintext) {
973: if ($settings->{$item} ne '') {
974: $designs{'logintext'}{$item} = $settings->{$item};
975: $is_custom{$item} = 1;
976: }
977: }
978: if ($settings->{'font'} ne '') {
979: $designs{'font'} = $settings->{'font'};
980: $is_custom{'font'} = 1;
981: }
982: foreach my $item (@bgs) {
983: if ($settings->{$item} ne '') {
984: $designs{'bgs'}{$item} = $settings->{$item};
985: $is_custom{$item} = 1;
986: }
987: }
988: foreach my $item (@links) {
989: if ($settings->{$item} ne '') {
990: $designs{'links'}{$item} = $settings->{$item};
991: $is_custom{$item} = 1;
992: }
993: }
994: } else {
995: if ($designhash{$dom.'.login.font'} ne '') {
996: $designs{'font'} = $designhash{$dom.'.login.font'};
997: $is_custom{'font'} = 1;
998: }
999: foreach my $item (@images) {
1000: if ($designhash{$dom.'.login.'.$item} ne '') {
1001: $designs{$item} = $designhash{$dom.'.login.'.$item};
1002: $is_custom{$item} = 1;
1003: }
1004: }
1005: foreach my $item (@bgs) {
1006: if ($designhash{$dom.'.login.'.$item} ne '') {
1007: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1008: $is_custom{$item} = 1;
1009: }
1.6 raeburn 1010: }
1.168 raeburn 1011: foreach my $item (@links) {
1012: if ($designhash{$dom.'.login.'.$item} ne '') {
1013: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1014: $is_custom{$item} = 1;
1015: }
1.6 raeburn 1016: }
1017: }
1.168 raeburn 1018: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1019: logo => 'Institution Logo',
1020: domlogo => 'Domain Logo',
1021: login => 'Login box');
1022: my $itemcount = 1;
1023: foreach my $item (@toggles) {
1024: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1025: $datatable .=
1026: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1027: '</td><td>'.
1028: '<span class="LC_nobreak"><label><input type="radio" name="'.
1029: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1030: '</label> <label><input type="radio" name="'.$item.'"'.
1031: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1032: '</tr>';
1033: $itemcount ++;
1.6 raeburn 1034: }
1.168 raeburn 1035: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1036: $datatable .= '</tr></table></td></tr>';
1037: } elsif ($caller eq 'help') {
1038: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1039: my $switchserver = &check_switchserver($dom,$confname);
1040: my $itemcount = 1;
1041: $defaulturl = '/adm/loginproblems.html';
1042: $defaulttype = 'default';
1043: %lt = &Apache::lonlocal::texthash (
1044: del => 'Delete?',
1045: rep => 'Replace:',
1046: upl => 'Upload:',
1047: default => 'Default',
1048: custom => 'Custom',
1049: );
1050: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1051: my @currlangs;
1052: if (ref($settings) eq 'HASH') {
1053: if (ref($settings->{'helpurl'}) eq 'HASH') {
1054: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1055: next if ($settings->{'helpurl'}{$key} eq '');
1056: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1057: $type{$key} = 'custom';
1058: unless ($key eq 'nolang') {
1059: push(@currlangs,$key);
1060: }
1061: }
1062: } elsif ($settings->{'helpurl'} ne '') {
1063: $type{'nolang'} = 'custom';
1064: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1065: }
1066: }
1.168 raeburn 1067: foreach my $lang ('nolang',sort(@currlangs)) {
1068: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1069: $datatable .= '<tr'.$css_class.'>';
1070: if ($url{$lang} eq '') {
1071: $url{$lang} = $defaulturl;
1072: }
1073: if ($type{$lang} eq '') {
1074: $type{$lang} = $defaulttype;
1075: }
1076: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1077: if ($lang eq 'nolang') {
1078: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1079: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1080: } else {
1081: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1082: $langchoices{$lang},
1083: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1084: }
1085: $datatable .= '</span></td>'."\n".
1086: '<td class="LC_left_item">';
1087: if ($type{$lang} eq 'custom') {
1088: $datatable .= '<span class="LC_nobreak"><label>'.
1089: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1090: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1091: } else {
1092: $datatable .= $lt{'upl'};
1093: }
1094: $datatable .='<br />';
1095: if ($switchserver) {
1096: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1097: } else {
1098: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1099: }
1.168 raeburn 1100: $datatable .= '</td></tr>';
1101: $itemcount ++;
1.6 raeburn 1102: }
1.168 raeburn 1103: my @addlangs;
1104: foreach my $lang (sort(keys(%langchoices))) {
1105: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1106: push(@addlangs,$lang);
1107: }
1108: if (@addlangs > 0) {
1109: my %toadd;
1110: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1111: $toadd{''} = &mt('Select');
1112: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1113: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1114: &mt('Add log-in help page for a specific language:').' '.
1115: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1116: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1117: if ($switchserver) {
1118: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1119: } else {
1120: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1121: }
1.168 raeburn 1122: $datatable .= '</td></tr>';
1.169 raeburn 1123: $itemcount ++;
1.6 raeburn 1124: }
1.169 raeburn 1125: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1 raeburn 1126: }
1.6 raeburn 1127: return $datatable;
1128: }
1129:
1130: sub login_choices {
1131: my %choices =
1132: &Apache::lonlocal::texthash (
1.116 bisitz 1133: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1134: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1135: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1136: disallowlogin => "Login page requests redirected",
1137: hostid => "Server",
1.128 raeburn 1138: server => "Redirect to:",
1139: serverpath => "Path",
1140: custompath => "Custom",
1141: exempt => "Exempt IP(s)",
1.110 raeburn 1142: directlogin => "No redirect",
1143: newuser => "Link to create a user account",
1144: img => "Header",
1145: logo => "Main Logo",
1146: domlogo => "Domain Logo",
1147: login => "Log-in Header",
1148: textcol => "Text color",
1149: bgcol => "Box color",
1150: bgs => "Background colors",
1151: links => "Link colors",
1152: font => "Font color",
1153: pgbg => "Header",
1154: mainbg => "Page",
1155: sidebg => "Login box",
1156: link => "Link",
1157: alink => "Active link",
1158: vlink => "Visited link",
1.6 raeburn 1159: );
1160: return %choices;
1161: }
1162:
1163: sub print_rolecolors {
1.30 raeburn 1164: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1165: my %choices = &color_font_choices();
1166: my @bgs = ('pgbg','tabbg','sidebg');
1167: my @links = ('link','alink','vlink');
1168: my @images = ('img');
1169: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1170: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1171: my %defaultdesign = %Apache::loncommon::defaultdesign;
1172: my (%is_custom,%designs);
1.200 raeburn 1173: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1174: if (ref($settings) eq 'HASH') {
1175: if (ref($settings->{$role}) eq 'HASH') {
1176: if ($settings->{$role}->{'img'} ne '') {
1177: $designs{'img'} = $settings->{$role}->{'img'};
1178: $is_custom{'img'} = 1;
1179: }
1180: if ($settings->{$role}->{'font'} ne '') {
1181: $designs{'font'} = $settings->{$role}->{'font'};
1182: $is_custom{'font'} = 1;
1183: }
1.97 tempelho 1184: if ($settings->{$role}->{'fontmenu'} ne '') {
1185: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1186: $is_custom{'fontmenu'} = 1;
1187: }
1.6 raeburn 1188: foreach my $item (@bgs) {
1189: if ($settings->{$role}->{$item} ne '') {
1190: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1191: $is_custom{$item} = 1;
1192: }
1193: }
1194: foreach my $item (@links) {
1195: if ($settings->{$role}->{$item} ne '') {
1196: $designs{'links'}{$item} = $settings->{$role}->{$item};
1197: $is_custom{$item} = 1;
1198: }
1199: }
1200: }
1201: } else {
1202: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1203: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1204: $is_custom{'img'} = 1;
1205: }
1.97 tempelho 1206: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1207: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1208: $is_custom{'fontmenu'} = 1;
1209: }
1.6 raeburn 1210: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1211: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1212: $is_custom{'font'} = 1;
1213: }
1214: foreach my $item (@bgs) {
1215: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1216: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1217: $is_custom{$item} = 1;
1218:
1219: }
1220: }
1221: foreach my $item (@links) {
1222: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1223: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1224: $is_custom{$item} = 1;
1225: }
1226: }
1227: }
1228: my $itemcount = 1;
1.30 raeburn 1229: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1230: $datatable .= '</tr></table></td></tr>';
1231: return $datatable;
1232: }
1233:
1.200 raeburn 1234: sub role_defaults {
1235: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1236: my %defaults;
1237: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1238: return %defaults;
1239: }
1240: my %defaultdesign = %Apache::loncommon::defaultdesign;
1241: if ($role eq 'login') {
1242: %defaults = (
1243: font => $defaultdesign{$role.'.font'},
1244: );
1245: if (ref($logintext) eq 'ARRAY') {
1246: foreach my $item (@{$logintext}) {
1247: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1248: }
1249: }
1250: foreach my $item (@{$images}) {
1251: $defaults{'showlogo'}{$item} = 1;
1252: }
1253: } else {
1254: %defaults = (
1255: img => $defaultdesign{$role.'.img'},
1256: font => $defaultdesign{$role.'.font'},
1257: fontmenu => $defaultdesign{$role.'.fontmenu'},
1258: );
1259: }
1260: foreach my $item (@{$bgs}) {
1261: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1262: }
1263: foreach my $item (@{$links}) {
1264: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1265: }
1266: foreach my $item (@{$images}) {
1267: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1268: }
1269: return %defaults;
1270: }
1271:
1.6 raeburn 1272: sub display_color_options {
1.9 raeburn 1273: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1274: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1275: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1276: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1277: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1278: '<td>'.$choices->{'font'}.'</td>';
1279: if (!$is_custom->{'font'}) {
1.30 raeburn 1280: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1281: } else {
1282: $datatable .= '<td> </td>';
1283: }
1.174 foxr 1284: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1285:
1.8 raeburn 1286: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1287: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1288: ' value="'.$current_color.'" /> '.
1.174 foxr 1289: ' </td></tr>';
1.107 raeburn 1290: unless ($role eq 'login') {
1291: $datatable .= '<tr'.$css_class.'>'.
1292: '<td>'.$choices->{'fontmenu'}.'</td>';
1293: if (!$is_custom->{'fontmenu'}) {
1294: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1295: } else {
1296: $datatable .= '<td> </td>';
1297: }
1.202 raeburn 1298: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1299: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1300: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1301: '<input class="colorchooser" type="text" size="10" name="'
1302: .$role.'_fontmenu"'.
1303: ' value="'.$current_color.'" /> '.
1304: ' </td></tr>';
1.97 tempelho 1305: }
1.9 raeburn 1306: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1307: foreach my $img (@{$images}) {
1.18 albertel 1308: $itemcount ++;
1.6 raeburn 1309: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1310: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1311: '<td>'.$choices->{$img};
1.41 raeburn 1312: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1313: if ($role eq 'login') {
1314: if ($img eq 'login') {
1315: $login_hdr_pick =
1.135 bisitz 1316: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1317: $logincolors =
1318: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1319: $designs,$defaults);
1.70 raeburn 1320: } elsif ($img ne 'domlogo') {
1321: $datatable.= &logo_display_options($img,$defaults,$designs);
1322: }
1323: }
1324: $datatable .= '</td>';
1.6 raeburn 1325: if ($designs->{$img} ne '') {
1326: $imgfile = $designs->{$img};
1.18 albertel 1327: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1328: } else {
1329: $imgfile = $defaults->{$img};
1330: }
1331: if ($imgfile) {
1.9 raeburn 1332: my ($showfile,$fullsize);
1333: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1334: my $urldir = $1;
1335: my $filename = $2;
1336: my @info = &Apache::lonnet::stat_file($designs->{$img});
1337: if (@info) {
1338: my $thumbfile = 'tn-'.$filename;
1339: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1340: if (@thumb) {
1341: $showfile = $urldir.'/'.$thumbfile;
1342: } else {
1343: $showfile = $imgfile;
1344: }
1345: } else {
1346: $showfile = '';
1347: }
1348: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1349: $showfile = $imgfile;
1.6 raeburn 1350: my $imgdir = $1;
1351: my $filename = $2;
1.159 raeburn 1352: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1353: $showfile = "/$imgdir/tn-".$filename;
1354: } else {
1.159 raeburn 1355: my $input = $londocroot.$imgfile;
1356: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1357: if (!-e $output) {
1.9 raeburn 1358: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1359: my ($fullwidth,$fullheight) = &check_dimensions($input);
1360: if ($fullwidth ne '' && $fullheight ne '') {
1361: if ($fullwidth > $width && $fullheight > $height) {
1362: my $size = $width.'x'.$height;
1363: system("convert -sample $size $input $output");
1.159 raeburn 1364: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1365: }
1366: }
1.6 raeburn 1367: }
1368: }
1.16 raeburn 1369: }
1.6 raeburn 1370: if ($showfile) {
1.40 raeburn 1371: if ($showfile =~ m{^/(adm|res)/}) {
1372: if ($showfile =~ m{^/res/}) {
1373: my $local_showfile =
1374: &Apache::lonnet::filelocation('',$showfile);
1375: &Apache::lonnet::repcopy($local_showfile);
1376: }
1377: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1378: }
1379: if ($imgfile) {
1380: if ($imgfile =~ m{^/(adm|res)/}) {
1381: if ($imgfile =~ m{^/res/}) {
1382: my $local_imgfile =
1383: &Apache::lonnet::filelocation('',$imgfile);
1384: &Apache::lonnet::repcopy($local_imgfile);
1385: }
1386: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1387: } else {
1388: $fullsize = $imgfile;
1389: }
1390: }
1.41 raeburn 1391: $datatable .= '<td>';
1392: if ($img eq 'login') {
1.135 bisitz 1393: $datatable .= $login_hdr_pick;
1394: }
1.41 raeburn 1395: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1396: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1397: } else {
1.201 raeburn 1398: $datatable .= '<td> </td><td class="LC_left_item">'.
1399: &mt('Upload:').'<br />';
1.6 raeburn 1400: }
1401: } else {
1.201 raeburn 1402: $datatable .= '<td> </td><td class="LC_left_item">'.
1403: &mt('Upload:').'<br />';
1.6 raeburn 1404: }
1.9 raeburn 1405: if ($switchserver) {
1406: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1407: } else {
1.135 bisitz 1408: if ($img ne 'login') { # suppress file selection for Log-in header
1409: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1410: }
1.9 raeburn 1411: }
1412: $datatable .= '</td></tr>';
1.6 raeburn 1413: }
1414: $itemcount ++;
1415: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1416: $datatable .= '<tr'.$css_class.'>'.
1417: '<td>'.$choices->{'bgs'}.'</td>';
1418: my $bgs_def;
1419: foreach my $item (@{$bgs}) {
1420: if (!$is_custom->{$item}) {
1.70 raeburn 1421: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span id="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 1422: }
1423: }
1424: if ($bgs_def) {
1.8 raeburn 1425: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1426: } else {
1427: $datatable .= '<td> </td>';
1428: }
1429: $datatable .= '<td class="LC_right_item">'.
1430: '<table border="0"><tr>';
1.174 foxr 1431:
1.6 raeburn 1432: foreach my $item (@{$bgs}) {
1.201 raeburn 1433: $datatable .= '<td align="center">'.$choices->{$item};
1.174 foxr 1434: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1435: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1436: $datatable .= ' ';
1.6 raeburn 1437: }
1.174 foxr 1438: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1439: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1440: }
1441: $datatable .= '</tr></table></td></tr>';
1442: $itemcount ++;
1443: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1444: $datatable .= '<tr'.$css_class.'>'.
1445: '<td>'.$choices->{'links'}.'</td>';
1446: my $links_def;
1447: foreach my $item (@{$links}) {
1448: if (!$is_custom->{$item}) {
1.30 raeburn 1449: $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 1450: }
1451: }
1452: if ($links_def) {
1.8 raeburn 1453: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1454: } else {
1455: $datatable .= '<td> </td>';
1456: }
1457: $datatable .= '<td class="LC_right_item">'.
1458: '<table border="0"><tr>';
1459: foreach my $item (@{$links}) {
1.174 foxr 1460: my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
1.201 raeburn 1461: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1462: if ($designs->{'links'}{$item}) {
1.174 foxr 1463: $datatable.=' ';
1.6 raeburn 1464: }
1.174 foxr 1465: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1466: '" /></td>';
1467: }
1.30 raeburn 1468: $$rowtotal += $itemcount;
1.3 raeburn 1469: return $datatable;
1470: }
1471:
1.70 raeburn 1472: sub logo_display_options {
1473: my ($img,$defaults,$designs) = @_;
1474: my $checkedon;
1475: if (ref($defaults) eq 'HASH') {
1476: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1477: if ($defaults->{'showlogo'}{$img}) {
1478: $checkedon = 'checked="checked" ';
1479: }
1480: }
1481: }
1482: if (ref($designs) eq 'HASH') {
1483: if (ref($designs->{'showlogo'}) eq 'HASH') {
1484: if (defined($designs->{'showlogo'}{$img})) {
1485: if ($designs->{'showlogo'}{$img} == 0) {
1486: $checkedon = '';
1487: } elsif ($designs->{'showlogo'}{$img} == 1) {
1488: $checkedon = 'checked="checked" ';
1489: }
1490: }
1491: }
1492: }
1493: return '<br /><label> <input type="checkbox" name="'.
1494: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1495: &mt('show').'</label>'."\n";
1496: }
1497:
1.41 raeburn 1498: sub login_header_options {
1.135 bisitz 1499: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1500: my $output = '';
1.41 raeburn 1501: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1502: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1503: if (!$is_custom->{'textcol'}) {
1504: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1505: ' ';
1506: }
1507: if (!$is_custom->{'bgcol'}) {
1508: $output .= $choices->{'bgcol'}.': '.
1509: '<span id="css_'.$role.'_font" style="background-color: '.
1510: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1511: }
1512: $output .= '<br />';
1513: }
1514: $output .='<br />';
1515: return $output;
1516: }
1517:
1518: sub login_text_colors {
1.201 raeburn 1519: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1520: my $color_menu = '<table border="0"><tr>';
1521: foreach my $item (@{$logintext}) {
1.201 raeburn 1522: $color_menu .= '<td align="center">'.$choices->{$item};
1523: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1524: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1525: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1526: }
1527: $color_menu .= '</tr></table><br />';
1528: return $color_menu;
1529: }
1530:
1531: sub image_changes {
1532: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1533: my $output;
1.135 bisitz 1534: if ($img eq 'login') {
1535: # suppress image for Log-in header
1536: } elsif (!$is_custom) {
1.70 raeburn 1537: if ($img ne 'domlogo') {
1.41 raeburn 1538: $output .= &mt('Default image:').'<br />';
1539: } else {
1540: $output .= &mt('Default in use:').'<br />';
1541: }
1542: }
1.135 bisitz 1543: if ($img eq 'login') { # suppress image for Log-in header
1544: $output .= '<td>'.$logincolors;
1.41 raeburn 1545: } else {
1.135 bisitz 1546: if ($img_import) {
1547: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1548: }
1549: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1550: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1551: if ($is_custom) {
1552: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1553: '<input type="checkbox" name="'.
1554: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1555: '</label> '.&mt('Replace:').'</span><br />';
1556: } else {
1.201 raeburn 1557: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1558: }
1.41 raeburn 1559: }
1560: return $output;
1561: }
1562:
1.3 raeburn 1563: sub print_quotas {
1.86 raeburn 1564: my ($dom,$settings,$rowtotal,$action) = @_;
1565: my $context;
1566: if ($action eq 'quotas') {
1567: $context = 'tools';
1568: } else {
1569: $context = $action;
1570: }
1.197 raeburn 1571: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1572: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1573: my $typecount = 0;
1.101 raeburn 1574: my ($css_class,%titles);
1.86 raeburn 1575: if ($context eq 'requestcourses') {
1.216 raeburn 1576: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1577: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1578: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1579: %titles = &courserequest_titles();
1.163 raeburn 1580: } elsif ($context eq 'requestauthor') {
1581: @usertools = ('author');
1582: @options = ('norequest','approval','automatic');
1.210 raeburn 1583: %titles = &authorrequest_titles();
1.86 raeburn 1584: } else {
1.162 raeburn 1585: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1586: %titles = &tool_titles();
1.86 raeburn 1587: }
1.26 raeburn 1588: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1589: foreach my $type (@{$types}) {
1.197 raeburn 1590: my ($currdefquota,$currauthorquota);
1.163 raeburn 1591: unless (($context eq 'requestcourses') ||
1592: ($context eq 'requestauthor')) {
1.86 raeburn 1593: if (ref($settings) eq 'HASH') {
1594: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1595: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1596: } else {
1597: $currdefquota = $settings->{$type};
1598: }
1.197 raeburn 1599: if (ref($settings->{authorquota}) eq 'HASH') {
1600: $currauthorquota = $settings->{authorquota}->{$type};
1601: }
1.78 raeburn 1602: }
1.72 raeburn 1603: }
1.3 raeburn 1604: if (defined($usertypes->{$type})) {
1605: $typecount ++;
1606: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1607: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1608: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1609: '<td class="LC_left_item">';
1.101 raeburn 1610: if ($context eq 'requestcourses') {
1611: $datatable .= '<table><tr>';
1612: }
1613: my %cell;
1.72 raeburn 1614: foreach my $item (@usertools) {
1.101 raeburn 1615: if ($context eq 'requestcourses') {
1616: my ($curroption,$currlimit);
1617: if (ref($settings) eq 'HASH') {
1618: if (ref($settings->{$item}) eq 'HASH') {
1619: $curroption = $settings->{$item}->{$type};
1620: if ($curroption =~ /^autolimit=(\d*)$/) {
1621: $currlimit = $1;
1622: }
1623: }
1624: }
1625: if (!$curroption) {
1626: $curroption = 'norequest';
1627: }
1628: $datatable .= '<th>'.$titles{$item}.'</th>';
1629: foreach my $option (@options) {
1630: my $val = $option;
1631: if ($option eq 'norequest') {
1632: $val = 0;
1633: }
1634: if ($option eq 'validate') {
1635: my $canvalidate = 0;
1636: if (ref($validations{$item}) eq 'HASH') {
1637: if ($validations{$item}{$type}) {
1638: $canvalidate = 1;
1639: }
1640: }
1641: next if (!$canvalidate);
1642: }
1643: my $checked = '';
1644: if ($option eq $curroption) {
1645: $checked = ' checked="checked"';
1646: } elsif ($option eq 'autolimit') {
1647: if ($curroption =~ /^autolimit/) {
1648: $checked = ' checked="checked"';
1649: }
1650: }
1651: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1652: '<input type="radio" name="crsreq_'.$item.
1653: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1654: $titles{$option}.'</label>';
1.101 raeburn 1655: if ($option eq 'autolimit') {
1.127 raeburn 1656: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1657: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1658: 'value="'.$currlimit.'" />';
1.101 raeburn 1659: }
1.127 raeburn 1660: $cell{$item} .= '</span> ';
1.103 raeburn 1661: if ($option eq 'autolimit') {
1.127 raeburn 1662: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1663: }
1.101 raeburn 1664: }
1.163 raeburn 1665: } elsif ($context eq 'requestauthor') {
1666: my $curroption;
1667: if (ref($settings) eq 'HASH') {
1668: $curroption = $settings->{$type};
1669: }
1670: if (!$curroption) {
1671: $curroption = 'norequest';
1672: }
1673: foreach my $option (@options) {
1674: my $val = $option;
1675: if ($option eq 'norequest') {
1676: $val = 0;
1677: }
1678: my $checked = '';
1679: if ($option eq $curroption) {
1680: $checked = ' checked="checked"';
1681: }
1682: $datatable .= '<span class="LC_nobreak"><label>'.
1683: '<input type="radio" name="authorreq_'.$type.
1684: '" value="'.$val.'"'.$checked.' />'.
1685: $titles{$option}.'</label></span> ';
1686: }
1.101 raeburn 1687: } else {
1688: my $checked = 'checked="checked" ';
1689: if (ref($settings) eq 'HASH') {
1690: if (ref($settings->{$item}) eq 'HASH') {
1691: if ($settings->{$item}->{$type} == 0) {
1692: $checked = '';
1693: } elsif ($settings->{$item}->{$type} == 1) {
1694: $checked = 'checked="checked" ';
1695: }
1.78 raeburn 1696: }
1.72 raeburn 1697: }
1.101 raeburn 1698: $datatable .= '<span class="LC_nobreak"><label>'.
1699: '<input type="checkbox" name="'.$context.'_'.$item.
1700: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1701: '</label></span> ';
1.72 raeburn 1702: }
1.101 raeburn 1703: }
1704: if ($context eq 'requestcourses') {
1705: $datatable .= '</tr><tr>';
1706: foreach my $item (@usertools) {
1.106 raeburn 1707: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1708: }
1709: $datatable .= '</tr></table>';
1.72 raeburn 1710: }
1.86 raeburn 1711: $datatable .= '</td>';
1.163 raeburn 1712: unless (($context eq 'requestcourses') ||
1713: ($context eq 'requestauthor')) {
1.86 raeburn 1714: $datatable .=
1.197 raeburn 1715: '<td class="LC_right_item">'.
1716: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1717: '<input type="text" name="quota_'.$type.
1.72 raeburn 1718: '" value="'.$currdefquota.
1.197 raeburn 1719: '" size="5" /></span>'.(' ' x 2).
1720: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1721: '<input type="text" name="authorquota_'.$type.
1722: '" value="'.$currauthorquota.
1723: '" size="5" /></span></td>';
1.86 raeburn 1724: }
1725: $datatable .= '</tr>';
1.3 raeburn 1726: }
1727: }
1728: }
1.163 raeburn 1729: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1730: $defaultquota = '20';
1.197 raeburn 1731: $authorquota = '500';
1.86 raeburn 1732: if (ref($settings) eq 'HASH') {
1733: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1734: $defaultquota = $settings->{'defaultquota'}->{'default'};
1735: } elsif (defined($settings->{'default'})) {
1736: $defaultquota = $settings->{'default'};
1737: }
1.197 raeburn 1738: if (ref($settings->{'authorquota'}) eq 'HASH') {
1739: $authorquota = $settings->{'authorquota'}->{'default'};
1740: }
1.3 raeburn 1741: }
1742: }
1743: $typecount ++;
1744: $css_class = $typecount%2?' class="LC_odd_row"':'';
1745: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1746: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1747: '<td class="LC_left_item">';
1.101 raeburn 1748: if ($context eq 'requestcourses') {
1749: $datatable .= '<table><tr>';
1750: }
1751: my %defcell;
1.72 raeburn 1752: foreach my $item (@usertools) {
1.101 raeburn 1753: if ($context eq 'requestcourses') {
1754: my ($curroption,$currlimit);
1755: if (ref($settings) eq 'HASH') {
1756: if (ref($settings->{$item}) eq 'HASH') {
1757: $curroption = $settings->{$item}->{'default'};
1758: if ($curroption =~ /^autolimit=(\d*)$/) {
1759: $currlimit = $1;
1760: }
1761: }
1762: }
1763: if (!$curroption) {
1764: $curroption = 'norequest';
1765: }
1766: $datatable .= '<th>'.$titles{$item}.'</th>';
1767: foreach my $option (@options) {
1768: my $val = $option;
1769: if ($option eq 'norequest') {
1770: $val = 0;
1771: }
1772: if ($option eq 'validate') {
1773: my $canvalidate = 0;
1774: if (ref($validations{$item}) eq 'HASH') {
1775: if ($validations{$item}{'default'}) {
1776: $canvalidate = 1;
1777: }
1778: }
1779: next if (!$canvalidate);
1780: }
1781: my $checked = '';
1782: if ($option eq $curroption) {
1783: $checked = ' checked="checked"';
1784: } elsif ($option eq 'autolimit') {
1785: if ($curroption =~ /^autolimit/) {
1786: $checked = ' checked="checked"';
1787: }
1788: }
1789: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1790: '<input type="radio" name="crsreq_'.$item.
1791: '_default" value="'.$val.'"'.$checked.' />'.
1792: $titles{$option}.'</label>';
1793: if ($option eq 'autolimit') {
1.127 raeburn 1794: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1795: $item.'_limit_default" size="1" '.
1796: 'value="'.$currlimit.'" />';
1797: }
1.127 raeburn 1798: $defcell{$item} .= '</span> ';
1.104 raeburn 1799: if ($option eq 'autolimit') {
1.127 raeburn 1800: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1801: }
1.101 raeburn 1802: }
1.163 raeburn 1803: } elsif ($context eq 'requestauthor') {
1804: my $curroption;
1805: if (ref($settings) eq 'HASH') {
1.172 raeburn 1806: $curroption = $settings->{'default'};
1.163 raeburn 1807: }
1808: if (!$curroption) {
1809: $curroption = 'norequest';
1810: }
1811: foreach my $option (@options) {
1812: my $val = $option;
1813: if ($option eq 'norequest') {
1814: $val = 0;
1815: }
1816: my $checked = '';
1817: if ($option eq $curroption) {
1818: $checked = ' checked="checked"';
1819: }
1820: $datatable .= '<span class="LC_nobreak"><label>'.
1821: '<input type="radio" name="authorreq_default"'.
1822: ' value="'.$val.'"'.$checked.' />'.
1823: $titles{$option}.'</label></span> ';
1824: }
1.101 raeburn 1825: } else {
1826: my $checked = 'checked="checked" ';
1827: if (ref($settings) eq 'HASH') {
1828: if (ref($settings->{$item}) eq 'HASH') {
1829: if ($settings->{$item}->{'default'} == 0) {
1830: $checked = '';
1831: } elsif ($settings->{$item}->{'default'} == 1) {
1832: $checked = 'checked="checked" ';
1833: }
1.78 raeburn 1834: }
1.72 raeburn 1835: }
1.101 raeburn 1836: $datatable .= '<span class="LC_nobreak"><label>'.
1837: '<input type="checkbox" name="'.$context.'_'.$item.
1838: '" value="default" '.$checked.'/>'.$titles{$item}.
1839: '</label></span> ';
1840: }
1841: }
1842: if ($context eq 'requestcourses') {
1843: $datatable .= '</tr><tr>';
1844: foreach my $item (@usertools) {
1.106 raeburn 1845: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1846: }
1.101 raeburn 1847: $datatable .= '</tr></table>';
1.72 raeburn 1848: }
1.86 raeburn 1849: $datatable .= '</td>';
1.163 raeburn 1850: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 1851: $datatable .= '<td class="LC_right_item">'.
1852: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 1853: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 1854: $defaultquota.'" size="5" /></span>'.(' ' x2).
1855: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1856: '<input type="text" name="authorquota" value="'.
1857: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 1858: }
1859: $datatable .= '</tr>';
1.72 raeburn 1860: $typecount ++;
1861: $css_class = $typecount%2?' class="LC_odd_row"':'';
1862: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 1863: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 1864: if ($context eq 'requestcourses') {
1.109 raeburn 1865: $datatable .= &mt('(overrides affiliation, if set)').
1866: '</td>'.
1867: '<td class="LC_left_item">'.
1868: '<table><tr>';
1.101 raeburn 1869: } else {
1.109 raeburn 1870: $datatable .= &mt('(overrides affiliation, if checked)').
1871: '</td>'.
1872: '<td class="LC_left_item" colspan="2">'.
1873: '<br />';
1.101 raeburn 1874: }
1875: my %advcell;
1.72 raeburn 1876: foreach my $item (@usertools) {
1.101 raeburn 1877: if ($context eq 'requestcourses') {
1878: my ($curroption,$currlimit);
1879: if (ref($settings) eq 'HASH') {
1880: if (ref($settings->{$item}) eq 'HASH') {
1881: $curroption = $settings->{$item}->{'_LC_adv'};
1882: if ($curroption =~ /^autolimit=(\d*)$/) {
1883: $currlimit = $1;
1884: }
1885: }
1886: }
1887: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1888: my $checked = '';
1889: if ($curroption eq '') {
1890: $checked = ' checked="checked"';
1891: }
1892: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1893: '<input type="radio" name="crsreq_'.$item.
1894: '__LC_adv" value=""'.$checked.' />'.
1895: &mt('No override set').'</label></span> ';
1.101 raeburn 1896: foreach my $option (@options) {
1897: my $val = $option;
1898: if ($option eq 'norequest') {
1899: $val = 0;
1900: }
1901: if ($option eq 'validate') {
1902: my $canvalidate = 0;
1903: if (ref($validations{$item}) eq 'HASH') {
1904: if ($validations{$item}{'_LC_adv'}) {
1905: $canvalidate = 1;
1906: }
1907: }
1908: next if (!$canvalidate);
1909: }
1910: my $checked = '';
1.104 raeburn 1911: if ($val eq $curroption) {
1.101 raeburn 1912: $checked = ' checked="checked"';
1913: } elsif ($option eq 'autolimit') {
1914: if ($curroption =~ /^autolimit/) {
1915: $checked = ' checked="checked"';
1916: }
1917: }
1918: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1919: '<input type="radio" name="crsreq_'.$item.
1920: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1921: $titles{$option}.'</label>';
1922: if ($option eq 'autolimit') {
1.127 raeburn 1923: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1924: $item.'_limit__LC_adv" size="1" '.
1925: 'value="'.$currlimit.'" />';
1926: }
1.127 raeburn 1927: $advcell{$item} .= '</span> ';
1.104 raeburn 1928: if ($option eq 'autolimit') {
1.127 raeburn 1929: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1930: }
1.101 raeburn 1931: }
1.163 raeburn 1932: } elsif ($context eq 'requestauthor') {
1933: my $curroption;
1934: if (ref($settings) eq 'HASH') {
1935: $curroption = $settings->{'_LC_adv'};
1936: }
1937: my $checked = '';
1938: if ($curroption eq '') {
1939: $checked = ' checked="checked"';
1940: }
1941: $datatable .= '<span class="LC_nobreak"><label>'.
1942: '<input type="radio" name="authorreq__LC_adv"'.
1943: ' value=""'.$checked.' />'.
1944: &mt('No override set').'</label></span> ';
1945: foreach my $option (@options) {
1946: my $val = $option;
1947: if ($option eq 'norequest') {
1948: $val = 0;
1949: }
1950: my $checked = '';
1951: if ($val eq $curroption) {
1952: $checked = ' checked="checked"';
1953: }
1954: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 1955: '<input type="radio" name="authorreq__LC_adv"'.
1956: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 1957: $titles{$option}.'</label></span> ';
1958: }
1.101 raeburn 1959: } else {
1960: my $checked = 'checked="checked" ';
1961: if (ref($settings) eq 'HASH') {
1962: if (ref($settings->{$item}) eq 'HASH') {
1963: if ($settings->{$item}->{'_LC_adv'} == 0) {
1964: $checked = '';
1965: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1966: $checked = 'checked="checked" ';
1967: }
1.79 raeburn 1968: }
1.72 raeburn 1969: }
1.101 raeburn 1970: $datatable .= '<span class="LC_nobreak"><label>'.
1971: '<input type="checkbox" name="'.$context.'_'.$item.
1972: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1973: '</label></span> ';
1974: }
1975: }
1976: if ($context eq 'requestcourses') {
1977: $datatable .= '</tr><tr>';
1978: foreach my $item (@usertools) {
1.106 raeburn 1979: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1980: }
1.101 raeburn 1981: $datatable .= '</tr></table>';
1.72 raeburn 1982: }
1.98 raeburn 1983: $datatable .= '</td></tr>';
1.30 raeburn 1984: $$rowtotal += $typecount;
1.3 raeburn 1985: return $datatable;
1986: }
1987:
1.163 raeburn 1988: sub print_requestmail {
1989: my ($dom,$action,$settings,$rowtotal) = @_;
1.208 raeburn 1990: my ($now,$datatable,%currapp);
1.102 raeburn 1991: $now = time;
1992: if (ref($settings) eq 'HASH') {
1993: if (ref($settings->{'notify'}) eq 'HASH') {
1994: if ($settings->{'notify'}{'approval'} ne '') {
1.191 raeburn 1995: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 1996: }
1997: }
1998: }
1.191 raeburn 1999: my $numinrow = 2;
1.102 raeburn 2000: my $css_class = 'class="LC_odd_row"';
1.163 raeburn 2001: my $text;
2002: if ($action eq 'requestcourses') {
2003: $text = &mt('Receive notification of course requests requiring approval');
2004: } else {
2005: $text = &mt('Receive notification of authoring space requests requiring approval')
2006: }
2007: $datatable = '<tr '.$css_class.'>'.
2008: ' <td>'.$text.'</td>'.
1.102 raeburn 2009: ' <td class="LC_left_item">';
1.191 raeburn 2010: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
2011: 'reqapprovalnotify',%currapp);
2012: if ($numdc > 0) {
2013: $datatable .= $table;
1.102 raeburn 2014: } else {
2015: $datatable .= &mt('There are no active Domain Coordinators');
2016: }
2017: $datatable .='</td></tr>';
2018: $$rowtotal += $rows;
2019: return $datatable;
2020: }
2021:
1.216 raeburn 2022: sub print_studentcode {
2023: my ($settings,$rowtotal) = @_;
2024: my $rownum = 0;
1.218 raeburn 2025: my ($output,%current);
2026: my @crstypes = ('official','unofficial','community','textbook');
2027: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2028: foreach my $type (@crstypes) {
2029: $current{$type} = $settings->{'uniquecode'}{$type};
2030: }
2031: }
2032: $output .= '<tr>'.
2033: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2034: '<td class="LC_left_item">';
2035: foreach my $type (@crstypes) {
2036: my $check = ' ';
2037: if ($current{$type}) {
2038: $check = ' checked="checked" ';
2039: }
2040: $output .= '<span class="LC_nobreak"><label>'.
2041: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2042: &mt($type).'</label></span>'.(' 'x2).' ';
2043: }
2044: $output .= '</td></tr>';
2045: $$rowtotal ++;
2046: return $output;
1.216 raeburn 2047: }
2048:
2049: sub print_textbookcourses {
2050: my ($dom,$settings,$rowtotal) = @_;
2051: my $rownum = 0;
2052: my $css_class;
2053: my $itemcount = 1;
2054: my $maxnum = 0;
2055: my $bookshash;
2056: if (ref($settings) eq 'HASH') {
2057: $bookshash = $settings->{'textbooks'};
2058: }
2059: my %ordered;
2060: if (ref($bookshash) eq 'HASH') {
2061: foreach my $item (keys(%{$bookshash})) {
2062: if (ref($bookshash->{$item}) eq 'HASH') {
2063: my $num = $bookshash->{$item}{'order'};
2064: $ordered{$num} = $item;
2065: }
2066: }
2067: }
2068: my $confname = $dom.'-domainconfig';
2069: my $switchserver = &check_switchserver($dom,$confname);
2070: my $maxnum = scalar(keys(%ordered));
1.217 raeburn 2071: my $datatable = &textbookcourses_javascript(\%ordered);
1.216 raeburn 2072: if (keys(%ordered)) {
2073: my @items = sort { $a <=> $b } keys(%ordered);
2074: for (my $i=0; $i<@items; $i++) {
2075: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2076: my $key = $ordered{$items[$i]};
2077: my %coursehash=&Apache::lonnet::coursedescription($key);
2078: my $coursetitle = $coursehash{'description'};
2079: my ($subject,$title,$author,$image,$imgsrc,$cdom,$cnum);
2080: if (ref($bookshash->{$key}) eq 'HASH') {
2081: $subject = $bookshash->{$key}->{'subject'};
2082: $title = $bookshash->{$key}->{'title'};
2083: $author = $bookshash->{$key}->{'author'};
2084: $image = $bookshash->{$key}->{'image'};
2085: if ($image ne '') {
2086: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2087: my $imagethumb = "$path/tn-".$imagefile;
2088: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2089: }
2090: }
1.217 raeburn 2091: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$key'".');"';
1.216 raeburn 2092: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
2093: .'<select name="'.$key.'"'.$chgstr.'>';
2094: for (my $k=0; $k<=$maxnum; $k++) {
2095: my $vpos = $k+1;
2096: my $selstr;
2097: if ($k == $i) {
2098: $selstr = ' selected="selected" ';
2099: }
2100: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2101: }
2102: $datatable .= '</select>'.(' 'x2).
2103: '<label><input type="checkbox" name="book_del" value="'.$key.'" />'.
2104: &mt('Delete?').'</label></span></td>'.
2105: '<td colspan="2">'.
2106: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="book_subject_'.$i.'" value="'.$subject.'" /></span> '.
2107: (' 'x2).
2108: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="book_title_'.$i.'" value="'.$title.'" /></span> '.
2109: (' 'x2).
2110: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="book_author_'.$i.'" value="'.$author.'" /></span> '.
2111: (' 'x2).
2112: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2113: if ($image) {
2114: $datatable .= '<span class="LC_nobreak">'.
2115: $imgsrc.
2116: '<label><input type="checkbox" name="book_image_del"'.
2117: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2118: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2119: }
2120: if ($switchserver) {
2121: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2122: } else {
2123: $datatable .= '<input type="file" name="book_image_'.$i.'" value="" />';
2124: }
2125: $datatable .= '<input type="hidden" name="book_id_'.$i.'" value="'.$key.'" /></span> '.
2126: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2127: $coursetitle.'</span></td></tr>'."\n";
2128: $itemcount ++;
2129: }
2130: }
2131: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.217 raeburn 2132: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'addbook_pos'".');"';
1.216 raeburn 2133: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
2134: '<input type="hidden" name="book_maxnum" value="'.$maxnum.'" />'."\n".
2135: '<select name="addbook_pos"'.$chgstr.'>';
2136: for (my $k=0; $k<$maxnum+1; $k++) {
2137: my $vpos = $k+1;
2138: my $selstr;
2139: if ($k == $maxnum) {
2140: $selstr = ' selected="selected" ';
2141: }
2142: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2143: }
2144: $datatable .= '</select> '."\n".
2145: '<input type="checkbox" name="addbook" value="1" />'.&mt('Add').'</td>'."\n".
2146: '<td colspan="2">'.
2147: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="addbook_subject" value="" /></span> '."\n".
2148: (' 'x2).
2149: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="addbook_title" value="" /></span> '."\n".
2150: (' 'x2).
2151: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="addbook_author" value="" /></span> '."\n".
2152: (' 'x2).
2153: '<span class="LC_nobreak">'.&mt('Image:').' ';
2154: if ($switchserver) {
2155: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2156: } else {
2157: $datatable .= '<input type="file" name="addbook_image" value="" />';
2158: }
2159: $datatable .= '</span>'."\n".
2160: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2161: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'addbook_cdom').
2162: '<input type="text" size="25" name="addbook_cnum" value="" />'.
2163: &Apache::loncommon::selectcourse_link
2164: ('display','addbook_cnum','addbook_cdom',undef,undef,undef,'Course');
2165: '</span></td>'."\n".
2166: '</tr>'."\n";
2167: $itemcount ++;
2168: return $datatable;
2169: }
2170:
1.217 raeburn 2171: sub textbookcourses_javascript {
2172: my ($textbooks) = @_;
2173: return unless(ref($textbooks) eq 'HASH');
2174: my $num = scalar(keys(%{$textbooks}));
2175: my @jsarray;
2176: foreach my $item (sort {$a <=> $b } (keys(%{$textbooks}))) {
2177: push(@jsarray,$textbooks->{$item});
2178: }
2179: my $jstext = ' var textbooks = Array('."'".join("','",@jsarray)."'".');'."\n";
2180: return <<"ENDSCRIPT";
2181: <script type="text/javascript">
2182: // <![CDATA[
2183: function reorderBooks(form,item) {
2184: var changedVal;
2185: $jstext
2186: var newpos = 'addbook_pos';
2187: var current = new Array;
2188: var maxh = 1 + $num;
2189: var current = new Array;
2190: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2191: if (item == newpos) {
2192: changedVal = newitemVal;
2193: } else {
2194: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2195: current[newitemVal] = newpos;
2196: }
2197: for (var i=0; i<textbooks.length; i++) {
2198: var elementName = textbooks[i];
2199: if (elementName != item) {
2200: if (form.elements[elementName]) {
2201: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2202: current[currVal] = elementName;
2203: }
2204: }
2205: }
2206: var oldVal;
2207: for (var j=0; j<maxh; j++) {
2208: if (current[j] == undefined) {
2209: oldVal = j;
2210: }
2211: }
2212: if (oldVal < changedVal) {
2213: for (var k=oldVal+1; k<=changedVal ; k++) {
2214: var elementName = current[k];
2215: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2216: }
2217: } else {
2218: for (var k=changedVal; k<oldVal; k++) {
2219: var elementName = current[k];
2220: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2221: }
2222: }
2223: return;
2224: }
2225:
2226: // ]]>
2227: </script>
2228:
2229: ENDSCRIPT
2230: }
2231:
1.3 raeburn 2232: sub print_autoenroll {
1.30 raeburn 2233: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2234: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 2235: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 2236: if (ref($settings) eq 'HASH') {
2237: if (exists($settings->{'run'})) {
2238: if ($settings->{'run'} eq '0') {
2239: $runoff = ' checked="checked" ';
2240: $runon = ' ';
2241: } else {
2242: $runon = ' checked="checked" ';
2243: $runoff = ' ';
2244: }
2245: } else {
2246: if ($autorun) {
2247: $runon = ' checked="checked" ';
2248: $runoff = ' ';
2249: } else {
2250: $runoff = ' checked="checked" ';
2251: $runon = ' ';
2252: }
2253: }
1.129 raeburn 2254: if (exists($settings->{'co-owners'})) {
2255: if ($settings->{'co-owners'} eq '0') {
2256: $coownersoff = ' checked="checked" ';
2257: $coownerson = ' ';
2258: } else {
2259: $coownerson = ' checked="checked" ';
2260: $coownersoff = ' ';
2261: }
2262: } else {
2263: $coownersoff = ' checked="checked" ';
2264: $coownerson = ' ';
2265: }
1.3 raeburn 2266: if (exists($settings->{'sender_domain'})) {
2267: $defdom = $settings->{'sender_domain'};
2268: }
1.14 raeburn 2269: } else {
2270: if ($autorun) {
2271: $runon = ' checked="checked" ';
2272: $runoff = ' ';
2273: } else {
2274: $runoff = ' checked="checked" ';
2275: $runon = ' ';
2276: }
1.3 raeburn 2277: }
2278: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2279: my $notif_sender;
2280: if (ref($settings) eq 'HASH') {
2281: $notif_sender = $settings->{'sender_uname'};
2282: }
1.3 raeburn 2283: my $datatable='<tr class="LC_odd_row">'.
2284: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2285: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2286: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2287: $runon.' value="1" />'.&mt('Yes').'</label> '.
2288: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2289: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2290: '</tr><tr>'.
2291: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2292: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2293: &mt('username').': '.
2294: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2295: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2296: ': '.$domform.'</span></td></tr>'.
2297: '<tr class="LC_odd_row">'.
2298: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2299: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2300: '<input type="radio" name="autoassign_coowners"'.
2301: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2302: '<label><input type="radio" name="autoassign_coowners"'.
2303: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2304: '</tr>';
2305: $$rowtotal += 3;
1.3 raeburn 2306: return $datatable;
2307: }
2308:
2309: sub print_autoupdate {
1.30 raeburn 2310: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2311: my $datatable;
2312: if ($position eq 'top') {
2313: my $updateon = ' ';
2314: my $updateoff = ' checked="checked" ';
2315: my $classlistson = ' ';
2316: my $classlistsoff = ' checked="checked" ';
2317: if (ref($settings) eq 'HASH') {
2318: if ($settings->{'run'} eq '1') {
2319: $updateon = $updateoff;
2320: $updateoff = ' ';
2321: }
2322: if ($settings->{'classlists'} eq '1') {
2323: $classlistson = $classlistsoff;
2324: $classlistsoff = ' ';
2325: }
2326: }
2327: my %title = (
2328: run => 'Auto-update active?',
2329: classlists => 'Update information in classlists?',
2330: );
2331: $datatable = '<tr class="LC_odd_row">'.
2332: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2333: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2334: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2335: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2336: '<label><input type="radio" name="autoupdate_run"'.
2337: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2338: '</tr><tr>'.
2339: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2340: '<td class="LC_right_item"><span class="LC_nobreak">'.
2341: '<label><input type="radio" name="classlists"'.
2342: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2343: '<label><input type="radio" name="classlists"'.
2344: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2345: '</tr>';
1.30 raeburn 2346: $$rowtotal += 2;
1.131 raeburn 2347: } elsif ($position eq 'middle') {
2348: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2349: my $numinrow = 3;
2350: my $locknamesettings;
2351: $datatable .= &insttypes_row($settings,$types,$usertypes,
2352: $dom,$numinrow,$othertitle,
2353: 'lockablenames');
2354: $$rowtotal ++;
1.3 raeburn 2355: } else {
1.44 raeburn 2356: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2357: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2358: 'permanentemail','id');
1.33 raeburn 2359: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2360: my $numrows = 0;
1.26 raeburn 2361: if (ref($types) eq 'ARRAY') {
2362: if (@{$types} > 0) {
2363: $datatable =
2364: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2365: \@fields,$types,\$numrows);
1.30 raeburn 2366: $$rowtotal += @{$types};
1.26 raeburn 2367: }
1.3 raeburn 2368: }
2369: $datatable .=
2370: &usertype_update_row($settings,{'default' => $othertitle},
2371: \%fieldtitles,\@fields,['default'],
2372: \$numrows);
1.30 raeburn 2373: $$rowtotal ++;
1.3 raeburn 2374: }
2375: return $datatable;
2376: }
2377:
1.125 raeburn 2378: sub print_autocreate {
2379: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 2380: my (%createon,%createoff,%currhash);
1.125 raeburn 2381: my @types = ('xml','req');
2382: if (ref($settings) eq 'HASH') {
2383: foreach my $item (@types) {
2384: $createoff{$item} = ' checked="checked" ';
2385: $createon{$item} = ' ';
2386: if (exists($settings->{$item})) {
2387: if ($settings->{$item}) {
2388: $createon{$item} = ' checked="checked" ';
2389: $createoff{$item} = ' ';
2390: }
2391: }
2392: }
1.210 raeburn 2393: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 2394: $currhash{$settings->{'xmldc'}} = 1;
2395: }
1.125 raeburn 2396: } else {
2397: foreach my $item (@types) {
2398: $createoff{$item} = ' checked="checked" ';
2399: $createon{$item} = ' ';
2400: }
2401: }
2402: $$rowtotal += 2;
1.191 raeburn 2403: my $numinrow = 2;
1.125 raeburn 2404: my $datatable='<tr class="LC_odd_row">'.
2405: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2406: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2407: '<input type="radio" name="autocreate_xml"'.
2408: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2409: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2410: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2411: '</td></tr><tr>'.
2412: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2413: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2414: '<input type="radio" name="autocreate_req"'.
2415: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2416: '<label><input type="radio" name="autocreate_req"'.
2417: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 2418: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2419: 'autocreate_xmldc',%currhash);
1.125 raeburn 2420: if ($numdc > 1) {
1.143 raeburn 2421: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2422: &mt('Course creation processed as: (choose Dom. Coord.)').
2423: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2424: } else {
1.143 raeburn 2425: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2426: }
1.191 raeburn 2427: $$rowtotal += $rows;
1.125 raeburn 2428: return $datatable;
2429: }
2430:
1.23 raeburn 2431: sub print_directorysrch {
1.30 raeburn 2432: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2433: my $srchon = ' ';
2434: my $srchoff = ' checked="checked" ';
1.25 raeburn 2435: my ($exacton,$containson,$beginson);
1.24 raeburn 2436: my $localon = ' ';
2437: my $localoff = ' checked="checked" ';
1.23 raeburn 2438: if (ref($settings) eq 'HASH') {
2439: if ($settings->{'available'} eq '1') {
2440: $srchon = $srchoff;
2441: $srchoff = ' ';
2442: }
1.24 raeburn 2443: if ($settings->{'localonly'} eq '1') {
2444: $localon = $localoff;
2445: $localoff = ' ';
2446: }
1.25 raeburn 2447: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2448: foreach my $type (@{$settings->{'searchtypes'}}) {
2449: if ($type eq 'exact') {
2450: $exacton = ' checked="checked" ';
2451: } elsif ($type eq 'contains') {
2452: $containson = ' checked="checked" ';
2453: } elsif ($type eq 'begins') {
2454: $beginson = ' checked="checked" ';
2455: }
2456: }
2457: } else {
2458: if ($settings->{'searchtypes'} eq 'exact') {
2459: $exacton = ' checked="checked" ';
2460: } elsif ($settings->{'searchtypes'} eq 'contains') {
2461: $containson = ' checked="checked" ';
2462: } elsif ($settings->{'searchtypes'} eq 'specify') {
2463: $exacton = ' checked="checked" ';
2464: $containson = ' checked="checked" ';
2465: }
1.23 raeburn 2466: }
2467: }
2468: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2469: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2470:
2471: my $numinrow = 4;
1.26 raeburn 2472: my $cansrchrow = 0;
1.23 raeburn 2473: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2474: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2475: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2476: '<input type="radio" name="dirsrch_available"'.
2477: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2478: '<label><input type="radio" name="dirsrch_available"'.
2479: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2480: '</tr><tr>'.
1.30 raeburn 2481: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2482: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2483: '<input type="radio" name="dirsrch_localonly"'.
2484: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2485: '<label><input type="radio" name="dirsrch_localonly"'.
2486: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2487: '</tr>';
1.30 raeburn 2488: $$rowtotal += 2;
1.26 raeburn 2489: if (ref($usertypes) eq 'HASH') {
2490: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2491: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2492: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2493: $cansrchrow = 1;
2494: }
2495: }
2496: if ($cansrchrow) {
1.30 raeburn 2497: $$rowtotal ++;
1.26 raeburn 2498: $datatable .= '<tr>';
2499: } else {
2500: $datatable .= '<tr class="LC_odd_row">';
2501: }
1.30 raeburn 2502: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2503: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2504: foreach my $title (@{$titleorder}) {
2505: if (defined($searchtitles->{$title})) {
2506: my $check = ' ';
1.93 raeburn 2507: if (ref($settings) eq 'HASH') {
1.39 raeburn 2508: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2509: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2510: $check = ' checked="checked" ';
2511: }
1.25 raeburn 2512: }
2513: }
2514: $datatable .= '<td class="LC_left_item">'.
2515: '<span class="LC_nobreak"><label>'.
2516: '<input type="checkbox" name="searchby" '.
2517: 'value="'.$title.'"'.$check.'/>'.
2518: $searchtitles->{$title}.'</label></span></td>';
2519: }
2520: }
1.26 raeburn 2521: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2522: $$rowtotal ++;
1.26 raeburn 2523: if ($cansrchrow) {
2524: $datatable .= '<tr class="LC_odd_row">';
2525: } else {
2526: $datatable .= '<tr>';
2527: }
1.30 raeburn 2528: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2529: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2530: '<span class="LC_nobreak"><label>'.
2531: '<input type="checkbox" name="searchtypes" '.
2532: $exacton.' value="exact" />'.&mt('Exact match').
2533: '</label> '.
2534: '<label><input type="checkbox" name="searchtypes" '.
2535: $beginson.' value="begins" />'.&mt('Begins with').
2536: '</label> '.
2537: '<label><input type="checkbox" name="searchtypes" '.
2538: $containson.' value="contains" />'.&mt('Contains').
2539: '</label></span></td></tr>';
1.30 raeburn 2540: $$rowtotal ++;
1.25 raeburn 2541: return $datatable;
2542: }
2543:
1.28 raeburn 2544: sub print_contacts {
1.30 raeburn 2545: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2546: my $datatable;
2547: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2548: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2549: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.203 raeburn 2550: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2551: foreach my $type (@mailings) {
2552: $otheremails{$type} = '';
2553: }
1.134 raeburn 2554: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2555: if (ref($settings) eq 'HASH') {
2556: foreach my $item (@contacts) {
2557: if (exists($settings->{$item})) {
2558: $to{$item} = $settings->{$item};
2559: }
2560: }
2561: foreach my $type (@mailings) {
2562: if (exists($settings->{$type})) {
2563: if (ref($settings->{$type}) eq 'HASH') {
2564: foreach my $item (@contacts) {
2565: if ($settings->{$type}{$item}) {
2566: $checked{$type}{$item} = ' checked="checked" ';
2567: }
2568: }
2569: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2570: if ($type eq 'helpdeskmail') {
2571: $bccemails{$type} = $settings->{$type}{'bcc'};
2572: }
1.28 raeburn 2573: }
1.89 raeburn 2574: } elsif ($type eq 'lonstatusmail') {
2575: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2576: }
2577: }
2578: } else {
2579: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2580: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2581: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2582: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2583: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2584: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2585: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.190 raeburn 2586: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
1.203 raeburn 2587: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2588: }
2589: my ($titles,$short_titles) = &contact_titles();
2590: my $rownum = 0;
2591: my $css_class;
2592: foreach my $item (@contacts) {
1.69 raeburn 2593: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2594: $datatable .= '<tr'.$css_class.'>'.
2595: '<td><span class="LC_nobreak">'.$titles->{$item}.
2596: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2597: '<input type="text" name="'.$item.'" value="'.
2598: $to{$item}.'" /></td></tr>';
1.203 raeburn 2599: $rownum ++;
1.28 raeburn 2600: }
2601: foreach my $type (@mailings) {
1.69 raeburn 2602: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2603: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2604: '<td><span class="LC_nobreak">'.
2605: $titles->{$type}.': </span></td>'.
1.28 raeburn 2606: '<td class="LC_left_item">'.
2607: '<span class="LC_nobreak">';
2608: foreach my $item (@contacts) {
2609: $datatable .= '<label>'.
2610: '<input type="checkbox" name="'.$type.'"'.
2611: $checked{$type}{$item}.
2612: ' value="'.$item.'" />'.$short_titles->{$item}.
2613: '</label> ';
2614: }
2615: $datatable .= '</span><br />'.&mt('Others').': '.
2616: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2617: 'value="'.$otheremails{$type}.'" />';
2618: if ($type eq 'helpdeskmail') {
1.136 raeburn 2619: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2620: '<input type="text" name="'.$type.'_bcc" '.
2621: 'value="'.$bccemails{$type}.'" />';
2622: }
2623: $datatable .= '</td></tr>'."\n";
1.203 raeburn 2624: $rownum ++;
1.28 raeburn 2625: }
1.203 raeburn 2626: my %choices;
2627: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2628: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2629: &mt('LON-CAPA core group - MSU'),600,500));
2630: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2631: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2632: &mt('LON-CAPA core group - MSU'),600,500));
2633: my @toggles = ('reporterrors','reportupdates');
2634: my %defaultchecked = ('reporterrors' => 'on',
2635: 'reportupdates' => 'on');
2636: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2637: \%choices,$rownum);
2638: $datatable .= $reports;
1.30 raeburn 2639: $$rowtotal += $rownum;
1.28 raeburn 2640: return $datatable;
2641: }
2642:
1.118 jms 2643: sub print_helpsettings {
1.168 raeburn 2644: my ($dom,$confname,$settings,$rowtotal) = @_;
2645: my ($datatable,$itemcount);
1.166 raeburn 2646: $itemcount = 1;
1.168 raeburn 2647: my (%choices,%defaultchecked,@toggles);
2648: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2649: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2650: &mt('LON-CAPA bug tracker'),600,500));
2651: %defaultchecked = ('submitbugs' => 'on');
2652: @toggles = ('submitbugs',);
1.166 raeburn 2653:
1.168 raeburn 2654: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2655: \%choices,$itemcount);
1.166 raeburn 2656: return $datatable;
1.121 raeburn 2657: }
2658:
2659: sub radiobutton_prefs {
1.192 raeburn 2660: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
2661: $additional) = @_;
1.121 raeburn 2662: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2663: (ref($choices) eq 'HASH'));
2664:
1.170 raeburn 2665: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 2666:
2667: foreach my $item (@{$toggles}) {
2668: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2669: $checkedon{$item} = ' checked="checked" ';
2670: $checkedoff{$item} = ' ';
1.121 raeburn 2671: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2672: $checkedoff{$item} = ' checked="checked" ';
2673: $checkedon{$item} = ' ';
2674: }
2675: }
2676: if (ref($settings) eq 'HASH') {
1.121 raeburn 2677: foreach my $item (@{$toggles}) {
1.118 jms 2678: if ($settings->{$item} eq '1') {
2679: $checkedon{$item} = ' checked="checked" ';
2680: $checkedoff{$item} = ' ';
2681: } elsif ($settings->{$item} eq '0') {
2682: $checkedoff{$item} = ' checked="checked" ';
2683: $checkedon{$item} = ' ';
2684: }
2685: }
1.121 raeburn 2686: }
1.192 raeburn 2687: if ($onclick) {
2688: $onclick = ' onclick="'.$onclick.'"';
2689: }
1.121 raeburn 2690: foreach my $item (@{$toggles}) {
1.118 jms 2691: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2692: $datatable .=
1.192 raeburn 2693: '<tr'.$css_class.'><td valign="top">'.
2694: '<span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2695: '</span></td>'.
2696: '<td class="LC_right_item"><span class="LC_nobreak">'.
2697: '<label><input type="radio" name="'.
1.192 raeburn 2698: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2699: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 2700: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2701: '</span>'.$additional.
2702: '</td>'.
1.118 jms 2703: '</tr>';
2704: $itemcount ++;
1.121 raeburn 2705: }
2706: return ($datatable,$itemcount);
2707: }
2708:
2709: sub print_coursedefaults {
1.139 raeburn 2710: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 2711: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2712: my $itemcount = 1;
1.192 raeburn 2713: my %choices = &Apache::lonlocal::texthash (
2714: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 2715: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 2716: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2717: coursecredits => 'Credits can be specified for courses',
2718: );
1.198 raeburn 2719: my %staticdefaults = (
2720: anonsurvey_threshold => 10,
2721: uploadquota => 500,
2722: );
1.139 raeburn 2723: if ($position eq 'top') {
2724: %defaultchecked = ('canuse_pdfforms' => 'off');
1.192 raeburn 2725: @toggles = ('canuse_pdfforms');
1.139 raeburn 2726: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2727: \%choices,$itemcount);
1.139 raeburn 2728: } else {
2729: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.216 raeburn 2730: my ($currdefresponder,$def_official_credits,$def_unofficial_credits,$def_textbook_credits,
2731: %curruploadquota);
1.192 raeburn 2732: my $currusecredits = 0;
1.216 raeburn 2733: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 2734: if (ref($settings) eq 'HASH') {
2735: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 2736: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2737: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2738: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2739: }
2740: }
1.192 raeburn 2741: if (ref($settings->{'coursecredits'}) eq 'HASH') {
2742: $def_official_credits = $settings->{'coursecredits'}->{'official'};
2743: $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
1.216 raeburn 2744: $def_textbook_credits = $settings->{'coursecredits'}->{'textbook'};
2745: if (($def_official_credits ne '') || ($def_unofficial_credits ne '') ||
2746: ($def_textbook_credits ne '')) {
1.192 raeburn 2747: $currusecredits = 1;
2748: }
2749: }
1.139 raeburn 2750: }
2751: if (!$currdefresponder) {
1.198 raeburn 2752: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 2753: } elsif ($currdefresponder < 1) {
2754: $currdefresponder = 1;
2755: }
1.198 raeburn 2756: foreach my $type (@types) {
2757: if ($curruploadquota{$type} eq '') {
2758: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
2759: }
2760: }
1.139 raeburn 2761: $datatable .=
1.192 raeburn 2762: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2763: $choices{'anonsurvey_threshold'}.
1.139 raeburn 2764: '</span></td>'.
2765: '<td class="LC_right_item"><span class="LC_nobreak">'.
2766: '<input type="text" name="anonsurvey_threshold"'.
2767: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.198 raeburn 2768: '</td></tr>'."\n".
2769: '<tr><td><span class="LC_nobreak">'.
2770: $choices{'uploadquota'}.
2771: '</span></td>'.
2772: '<td align="right" class="LC_right_item">'.
2773: '<table><tr>';
2774: foreach my $type (@types) {
2775: $datatable .= '<td align="center">'.&mt($type).'<br />'.
2776: '<input type="text" name="uploadquota_'.$type.'"'.
2777: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
2778: }
2779: $datatable .= '</tr></table></td></tr>'."\n";
2780: $itemcount += 2;
1.192 raeburn 2781: my $onclick = 'toggleCredits(this.form);';
1.210 raeburn 2782: my $display = 'none';
1.192 raeburn 2783: if ($currusecredits) {
2784: $display = 'block';
2785: }
2786: my $additional = '<div id="credits" style="display: '.$display.'">'.
2787: '<span class="LC_nobreak">'.
2788: &mt('Default credits for official courses [_1]',
2789: '<input type="text" name="official_credits" value="'.
2790: $def_official_credits.'" size="3" />').
2791: '</span><br />'.
2792: '<span class="LC_nobreak">'.
2793: &mt('Default credits for unofficial courses [_1]',
2794: '<input type="text" name="unofficial_credits" value="'.
2795: $def_unofficial_credits.'" size="3" />').
1.216 raeburn 2796: '</span><br />'.
2797: '<span class="LC_nobreak">'.
2798: &mt('Default credits for textbook courses [_1]',
2799: '<input type="text" name="textbook_credits" value="'.
2800: $def_textbook_credits.'" size="3" />').
1.192 raeburn 2801: '</span></div>'."\n";
2802: %defaultchecked = ('coursecredits' => 'off');
2803: @toggles = ('coursecredits');
2804: my $current = {
2805: 'coursecredits' => $currusecredits,
2806: };
2807: (my $table,$itemcount) =
2808: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
2809: \%choices,$itemcount,$onclick,$additional);
2810: $datatable .= $table;
1.139 raeburn 2811: }
1.192 raeburn 2812: $$rowtotal += $itemcount;
1.121 raeburn 2813: return $datatable;
1.118 jms 2814: }
2815:
1.137 raeburn 2816: sub print_usersessions {
2817: my ($position,$dom,$settings,$rowtotal) = @_;
2818: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2819: my (%by_ip,%by_location,@intdoms);
2820: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 2821:
2822: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 2823: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 2824: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 2825: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 2826: my $itemcount = 1;
2827: if ($position eq 'top') {
1.152 raeburn 2828: if (keys(%serverhomes) > 1) {
1.145 raeburn 2829: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 2830: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 2831: } else {
1.140 raeburn 2832: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2833: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 2834: }
1.137 raeburn 2835: } else {
1.145 raeburn 2836: if (keys(%by_location) == 0) {
2837: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2838: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 2839: } else {
2840: my %lt = &usersession_titles();
2841: my $numinrow = 5;
2842: my $prefix;
2843: my @types;
2844: if ($position eq 'bottom') {
2845: $prefix = 'remote';
2846: @types = ('version','excludedomain','includedomain');
2847: } else {
2848: $prefix = 'hosted';
2849: @types = ('excludedomain','includedomain');
2850: }
2851: my (%current,%checkedon,%checkedoff);
2852: my @lcversions = &Apache::lonnet::all_loncaparevs();
2853: my @locations = sort(keys(%by_location));
2854: foreach my $type (@types) {
2855: $checkedon{$type} = '';
2856: $checkedoff{$type} = ' checked="checked"';
2857: }
2858: if (ref($settings) eq 'HASH') {
2859: if (ref($settings->{$prefix}) eq 'HASH') {
2860: foreach my $key (keys(%{$settings->{$prefix}})) {
2861: $current{$key} = $settings->{$prefix}{$key};
2862: if ($key eq 'version') {
2863: if ($current{$key} ne '') {
2864: $checkedon{$key} = ' checked="checked"';
2865: $checkedoff{$key} = '';
2866: }
2867: } elsif (ref($current{$key}) eq 'ARRAY') {
2868: $checkedon{$key} = ' checked="checked"';
2869: $checkedoff{$key} = '';
2870: }
1.137 raeburn 2871: }
2872: }
2873: }
1.145 raeburn 2874: foreach my $type (@types) {
2875: next if ($type ne 'version' && !@locations);
2876: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2877: $datatable .= '<tr'.$css_class.'>
2878: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2879: <span class="LC_nobreak">
2880: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2881: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2882: if ($type eq 'version') {
2883: my $selector = '<select name="'.$prefix.'_version">';
2884: foreach my $version (@lcversions) {
2885: my $selected = '';
2886: if ($current{'version'} eq $version) {
2887: $selected = ' selected="selected"';
2888: }
2889: $selector .= ' <option value="'.$version.'"'.
2890: $selected.'>'.$version.'</option>';
2891: }
2892: $selector .= '</select> ';
2893: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2894: } else {
2895: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2896: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2897: ' />'.(' 'x2).
2898: '<input type="button" value="'.&mt('uncheck all').'" '.
2899: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2900: "\n".
2901: '</div><div><table>';
2902: my $rem;
2903: for (my $i=0; $i<@locations; $i++) {
2904: my ($showloc,$value,$checkedtype);
2905: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2906: my $ip = $by_location{$locations[$i]}->[0];
2907: if (ref($by_ip{$ip}) eq 'ARRAY') {
2908: $value = join(':',@{$by_ip{$ip}});
2909: $showloc = join(', ',@{$by_ip{$ip}});
2910: if (ref($current{$type}) eq 'ARRAY') {
2911: foreach my $loc (@{$by_ip{$ip}}) {
2912: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2913: $checkedtype = ' checked="checked"';
2914: last;
2915: }
2916: }
1.138 raeburn 2917: }
2918: }
2919: }
1.145 raeburn 2920: $rem = $i%($numinrow);
2921: if ($rem == 0) {
2922: if ($i > 0) {
2923: $datatable .= '</tr>';
2924: }
2925: $datatable .= '<tr>';
2926: }
2927: $datatable .= '<td class="LC_left_item">'.
2928: '<span class="LC_nobreak"><label>'.
2929: '<input type="checkbox" name="'.$prefix.'_'.$type.
2930: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2931: '</label></span></td>';
1.137 raeburn 2932: }
1.145 raeburn 2933: $rem = @locations%($numinrow);
2934: my $colsleft = $numinrow - $rem;
2935: if ($colsleft > 1 ) {
2936: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2937: ' </td>';
2938: } elsif ($colsleft == 1) {
2939: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 2940: }
1.145 raeburn 2941: $datatable .= '</tr></table>';
1.137 raeburn 2942: }
1.145 raeburn 2943: $datatable .= '</td></tr>';
2944: $itemcount ++;
1.137 raeburn 2945: }
2946: }
2947: }
2948: $$rowtotal += $itemcount;
2949: return $datatable;
2950: }
2951:
1.138 raeburn 2952: sub build_location_hashes {
2953: my ($intdoms,$by_ip,$by_location) = @_;
2954: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2955: (ref($by_location) eq 'HASH'));
2956: my %iphost = &Apache::lonnet::get_iphost();
2957: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2958: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2959: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2960: foreach my $id (@{$iphost{$primary_ip}}) {
2961: my $intdom = &Apache::lonnet::internet_dom($id);
2962: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2963: push(@{$intdoms},$intdom);
2964: }
2965: }
2966: }
2967: foreach my $ip (keys(%iphost)) {
2968: if (ref($iphost{$ip}) eq 'ARRAY') {
2969: foreach my $id (@{$iphost{$ip}}) {
2970: my $location = &Apache::lonnet::internet_dom($id);
2971: if ($location) {
2972: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2973: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2974: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2975: push(@{$by_ip->{$ip}},$location);
2976: }
2977: } else {
2978: $by_ip->{$ip} = [$location];
2979: }
2980: }
2981: }
2982: }
2983: }
2984: foreach my $ip (sort(keys(%{$by_ip}))) {
2985: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2986: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2987: my $first = $by_ip->{$ip}->[0];
2988: if (ref($by_location->{$first}) eq 'ARRAY') {
2989: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2990: push(@{$by_location->{$first}},$ip);
2991: }
2992: } else {
2993: $by_location->{$first} = [$ip];
2994: }
2995: }
2996: }
2997: return;
2998: }
2999:
1.145 raeburn 3000: sub current_offloads_to {
3001: my ($dom,$settings,$servers) = @_;
3002: my (%spareid,%otherdomconfigs);
1.152 raeburn 3003: if (ref($servers) eq 'HASH') {
1.145 raeburn 3004: foreach my $lonhost (sort(keys(%{$servers}))) {
3005: my $gotspares;
1.152 raeburn 3006: if (ref($settings) eq 'HASH') {
3007: if (ref($settings->{'spares'}) eq 'HASH') {
3008: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
3009: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
3010: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
3011: $gotspares = 1;
3012: }
1.145 raeburn 3013: }
3014: }
3015: unless ($gotspares) {
3016: my $gotspares;
3017: my $serverhomeID =
3018: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
3019: my $serverhomedom =
3020: &Apache::lonnet::host_domain($serverhomeID);
3021: if ($serverhomedom ne $dom) {
3022: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
3023: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3024: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3025: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3026: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3027: $gotspares = 1;
3028: }
3029: }
3030: } else {
3031: $otherdomconfigs{$serverhomedom} =
3032: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
3033: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
3034: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3035: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3036: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
3037: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3038: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3039: $gotspares = 1;
3040: }
3041: }
3042: }
3043: }
3044: }
3045: }
3046: }
3047: unless ($gotspares) {
3048: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
3049: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3050: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3051: } else {
3052: my $server_hostname = &Apache::lonnet::hostname($lonhost);
3053: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
3054: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
3055: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3056: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3057: } else {
1.150 raeburn 3058: my %what = (
3059: spareid => 1,
3060: );
3061: my ($result,$returnhash) =
3062: &Apache::lonnet::get_remote_globals($lonhost,\%what);
3063: if ($result eq 'ok') {
3064: if (ref($returnhash) eq 'HASH') {
3065: if (ref($returnhash->{'spareid'}) eq 'HASH') {
3066: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
3067: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
3068: }
3069: }
1.145 raeburn 3070: }
3071: }
3072: }
3073: }
3074: }
3075: }
3076: return %spareid;
3077: }
3078:
3079: sub spares_row {
1.152 raeburn 3080: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 3081: my $css_class;
3082: my $numinrow = 4;
3083: my $itemcount = 1;
3084: my $datatable;
1.152 raeburn 3085: my %typetitles = &sparestype_titles();
3086: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 3087: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 3088: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
3089: my ($othercontrol,$serverdom);
3090: if ($serverhome ne $server) {
3091: $serverdom = &Apache::lonnet::host_domain($serverhome);
3092: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3093: } else {
3094: $serverdom = &Apache::lonnet::host_domain($server);
3095: if ($serverdom ne $dom) {
3096: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3097: }
3098: }
3099: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 3100: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3101: $datatable .= '<tr'.$css_class.'>
3102: <td rowspan="2">
1.183 bisitz 3103: <span class="LC_nobreak">'.
3104: &mt('[_1] when busy, offloads to:'
3105: ,'<b>'.$server.'</b>').
3106: "\n";
1.145 raeburn 3107: my (%current,%canselect);
1.152 raeburn 3108: my @choices =
3109: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
3110: foreach my $type ('primary','default') {
3111: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 3112: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
3113: my @spares = @{$spareid->{$server}{$type}};
3114: if (@spares > 0) {
1.152 raeburn 3115: if ($othercontrol) {
3116: $current{$type} = join(', ',@spares);
3117: } else {
3118: $current{$type} .= '<table>';
3119: my $numspares = scalar(@spares);
3120: for (my $i=0; $i<@spares; $i++) {
3121: my $rem = $i%($numinrow);
3122: if ($rem == 0) {
3123: if ($i > 0) {
3124: $current{$type} .= '</tr>';
3125: }
3126: $current{$type} .= '<tr>';
1.145 raeburn 3127: }
1.152 raeburn 3128: $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'".');" /> '.
3129: $spareid->{$server}{$type}[$i].
3130: '</label></td>'."\n";
3131: }
3132: my $rem = @spares%($numinrow);
3133: my $colsleft = $numinrow - $rem;
3134: if ($colsleft > 1 ) {
3135: $current{$type} .= '<td colspan="'.$colsleft.
3136: '" class="LC_left_item">'.
3137: ' </td>';
3138: } elsif ($colsleft == 1) {
3139: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 3140: }
1.152 raeburn 3141: $current{$type} .= '</tr></table>';
1.150 raeburn 3142: }
1.145 raeburn 3143: }
3144: }
3145: if ($current{$type} eq '') {
3146: $current{$type} = &mt('None specified');
3147: }
1.152 raeburn 3148: if ($othercontrol) {
3149: if ($type eq 'primary') {
3150: $canselect{$type} = $othercontrol;
3151: }
3152: } else {
3153: $canselect{$type} =
3154: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
3155: '<select name="newspare_'.$type.'_'.$server.'" '.
3156: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
3157: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
3158: if (@choices > 0) {
3159: foreach my $lonhost (@choices) {
3160: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
3161: }
3162: }
3163: $canselect{$type} .= '</select>'."\n";
3164: }
3165: } else {
3166: $current{$type} = &mt('Could not be determined');
3167: if ($type eq 'primary') {
3168: $canselect{$type} = $othercontrol;
3169: }
1.145 raeburn 3170: }
1.152 raeburn 3171: if ($type eq 'default') {
3172: $datatable .= '<tr'.$css_class.'>';
3173: }
3174: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
3175: '<td>'.$current{$type}.'</td>'."\n".
3176: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 3177: }
3178: $itemcount ++;
3179: }
3180: }
3181: $$rowtotal += $itemcount;
3182: return $datatable;
3183: }
3184:
1.152 raeburn 3185: sub possible_newspares {
3186: my ($server,$currspares,$serverhomes,$altids) = @_;
3187: my $serverhostname = &Apache::lonnet::hostname($server);
3188: my %excluded;
3189: if ($serverhostname ne '') {
3190: %excluded = (
3191: $serverhostname => 1,
3192: );
3193: }
3194: if (ref($currspares) eq 'HASH') {
3195: foreach my $type (keys(%{$currspares})) {
3196: if (ref($currspares->{$type}) eq 'ARRAY') {
3197: if (@{$currspares->{$type}} > 0) {
3198: foreach my $curr (@{$currspares->{$type}}) {
3199: my $hostname = &Apache::lonnet::hostname($curr);
3200: $excluded{$hostname} = 1;
3201: }
3202: }
3203: }
3204: }
3205: }
3206: my @choices;
3207: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
3208: if (keys(%{$serverhomes}) > 1) {
3209: foreach my $name (sort(keys(%{$serverhomes}))) {
3210: unless ($excluded{$name}) {
3211: if (exists($altids->{$serverhomes->{$name}})) {
3212: push(@choices,$altids->{$serverhomes->{$name}});
3213: } else {
3214: push(@choices,$serverhomes->{$name});
1.145 raeburn 3215: }
3216: }
3217: }
3218: }
3219: }
1.152 raeburn 3220: return sort(@choices);
1.145 raeburn 3221: }
3222:
1.150 raeburn 3223: sub print_loadbalancing {
3224: my ($dom,$settings,$rowtotal) = @_;
3225: my $primary_id = &Apache::lonnet::domain($dom,'primary');
3226: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3227: my $numinrow = 1;
3228: my $datatable;
3229: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 3230: my (%currbalancer,%currtargets,%currrules,%existing);
3231: if (ref($settings) eq 'HASH') {
3232: %existing = %{$settings};
3233: }
3234: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
3235: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
3236: \%currtargets,\%currrules);
1.150 raeburn 3237: } else {
3238: return;
3239: }
3240: my ($othertitle,$usertypes,$types) =
3241: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 3242: my $rownum = 8;
1.150 raeburn 3243: if (ref($types) eq 'ARRAY') {
3244: $rownum += scalar(@{$types});
3245: }
1.171 raeburn 3246: my @css_class = ('LC_odd_row','LC_even_row');
3247: my $balnum = 0;
3248: my $islast;
3249: my (@toshow,$disabledtext);
3250: if (keys(%currbalancer) > 0) {
3251: @toshow = sort(keys(%currbalancer));
3252: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
3253: push(@toshow,'');
3254: }
3255: } else {
3256: @toshow = ('');
3257: $disabledtext = &mt('No existing load balancer');
3258: }
3259: foreach my $lonhost (@toshow) {
3260: if ($balnum == scalar(@toshow)-1) {
3261: $islast = 1;
3262: } else {
3263: $islast = 0;
3264: }
3265: my $cssidx = $balnum%2;
3266: my $targets_div_style = 'display: none';
3267: my $disabled_div_style = 'display: block';
3268: my $homedom_div_style = 'display: none';
3269: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3270: '<td rowspan="'.$rownum.'" valign="top">'.
3271: '<p>';
3272: if ($lonhost eq '') {
1.210 raeburn 3273: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 3274: if (keys(%currbalancer) > 0) {
3275: $datatable .= &mt('Add balancer:');
3276: } else {
3277: $datatable .= &mt('Enable balancer:');
3278: }
3279: $datatable .= ' '.
3280: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3281: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3282: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3283: '<option value="" selected="selected">'.&mt('None').
3284: '</option>'."\n";
3285: foreach my $server (sort(keys(%servers))) {
3286: next if ($currbalancer{$server});
3287: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3288: }
1.210 raeburn 3289: $datatable .=
1.171 raeburn 3290: '</select>'."\n".
3291: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3292: } else {
3293: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3294: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3295: &mt('Stop balancing').'</label>'.
3296: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3297: $targets_div_style = 'display: block';
3298: $disabled_div_style = 'display: none';
3299: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3300: $homedom_div_style = 'display: block';
3301: }
3302: }
3303: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3304: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3305: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3306: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3307: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3308: my @sparestypes = ('primary','default');
3309: my %typetitles = &sparestype_titles();
3310: foreach my $sparetype (@sparestypes) {
3311: my $targettable;
3312: for (my $i=0; $i<$numspares; $i++) {
3313: my $checked;
3314: if (ref($currtargets{$lonhost}) eq 'HASH') {
3315: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3316: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3317: $checked = ' checked="checked"';
3318: }
3319: }
3320: }
3321: my ($chkboxval,$disabled);
3322: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3323: $chkboxval = $spares[$i];
3324: }
3325: if (exists($currbalancer{$spares[$i]})) {
3326: $disabled = ' disabled="disabled"';
3327: }
1.210 raeburn 3328: $targettable .=
1.171 raeburn 3329: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3330: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3331: '</span></label></td>';
3332: my $rem = $i%($numinrow);
3333: if ($rem == 0) {
3334: if (($i > 0) && ($i < $numspares-1)) {
3335: $targettable .= '</tr>';
3336: }
3337: if ($i < $numspares-1) {
3338: $targettable .= '<tr>';
1.150 raeburn 3339: }
3340: }
3341: }
1.171 raeburn 3342: if ($targettable ne '') {
3343: my $rem = $numspares%($numinrow);
3344: my $colsleft = $numinrow - $rem;
3345: if ($colsleft > 1 ) {
3346: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3347: ' </td>';
3348: } elsif ($colsleft == 1) {
3349: $targettable .= '<td class="LC_left_item"> </td>';
3350: }
3351: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3352: '<table><tr>'.$targettable.'</tr></table><br />';
3353: }
3354: }
3355: $datatable .= '</div></td></tr>'.
3356: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3357: $othertitle,$usertypes,$types,\%servers,
3358: \%currbalancer,$lonhost,
3359: $targets_div_style,$homedom_div_style,
3360: $css_class[$cssidx],$balnum,$islast);
3361: $$rowtotal += $rownum;
3362: $balnum ++;
3363: }
3364: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3365: return $datatable;
3366: }
3367:
3368: sub get_loadbalancers_config {
3369: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3370: return unless ((ref($servers) eq 'HASH') &&
3371: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3372: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3373: if (keys(%{$existing}) > 0) {
3374: my $oldlonhost;
3375: foreach my $key (sort(keys(%{$existing}))) {
3376: if ($key eq 'lonhost') {
3377: $oldlonhost = $existing->{'lonhost'};
3378: $currbalancer->{$oldlonhost} = 1;
3379: } elsif ($key eq 'targets') {
3380: if ($oldlonhost) {
3381: $currtargets->{$oldlonhost} = $existing->{'targets'};
3382: }
3383: } elsif ($key eq 'rules') {
3384: if ($oldlonhost) {
3385: $currrules->{$oldlonhost} = $existing->{'rules'};
3386: }
3387: } elsif (ref($existing->{$key}) eq 'HASH') {
3388: $currbalancer->{$key} = 1;
3389: $currtargets->{$key} = $existing->{$key}{'targets'};
3390: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3391: }
3392: }
1.171 raeburn 3393: } else {
3394: my ($balancerref,$targetsref) =
3395: &Apache::lonnet::get_lonbalancer_config($servers);
3396: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3397: foreach my $server (sort(keys(%{$balancerref}))) {
3398: $currbalancer->{$server} = 1;
3399: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3400: }
3401: }
3402: }
1.171 raeburn 3403: return;
1.150 raeburn 3404: }
3405:
3406: sub loadbalancing_rules {
3407: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 3408: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3409: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3410: my $output;
1.171 raeburn 3411: my $num = 0;
1.210 raeburn 3412: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3413: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3414: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3415: foreach my $type (@{$alltypes}) {
1.171 raeburn 3416: $num ++;
1.150 raeburn 3417: my $current;
3418: if (ref($currrules) eq 'HASH') {
3419: $current = $currrules->{$type};
3420: }
1.209 raeburn 3421: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.171 raeburn 3422: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3423: $current = '';
3424: }
3425: }
3426: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 3427: $servers,$currbalancer,$lonhost,$dom,
3428: $targets_div_style,$homedom_div_style,
3429: $css_class,$balnum,$num,$islast);
1.150 raeburn 3430: }
3431: }
3432: return $output;
3433: }
3434:
3435: sub loadbalancing_titles {
3436: my ($dom,$intdom,$usertypes,$types) = @_;
3437: my %othertypes = (
3438: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3439: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3440: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3441: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 3442: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
3443: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 3444: );
1.209 raeburn 3445: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 3446: if (ref($types) eq 'ARRAY') {
3447: unshift(@alltypes,@{$types},'default');
3448: }
3449: my %titles;
3450: foreach my $type (@alltypes) {
3451: if ($type =~ /^_LC_/) {
3452: $titles{$type} = $othertypes{$type};
3453: } elsif ($type eq 'default') {
3454: $titles{$type} = &mt('All users from [_1]',$dom);
3455: if (ref($types) eq 'ARRAY') {
3456: if (@{$types} > 0) {
3457: $titles{$type} = &mt('Other users from [_1]',$dom);
3458: }
3459: }
3460: } elsif (ref($usertypes) eq 'HASH') {
3461: $titles{$type} = $usertypes->{$type};
3462: }
3463: }
3464: return (\@alltypes,\%othertypes,\%titles);
3465: }
3466:
3467: sub loadbalance_rule_row {
1.171 raeburn 3468: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3469: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 3470: my @rulenames;
1.150 raeburn 3471: my %ruletitles = &offloadtype_text();
1.209 raeburn 3472: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
3473: @rulenames = ('balancer','offloadedto');
1.150 raeburn 3474: } else {
1.209 raeburn 3475: @rulenames = ('default','homeserver');
3476: if ($type eq '_LC_external') {
3477: push(@rulenames,'externalbalancer');
3478: } else {
3479: push(@rulenames,'specific');
3480: }
3481: push(@rulenames,'none');
1.150 raeburn 3482: }
3483: my $style = $targets_div_style;
1.209 raeburn 3484: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.150 raeburn 3485: $style = $homedom_div_style;
3486: }
1.171 raeburn 3487: my $space;
3488: if ($islast && $num == 1) {
3489: $space = '<div display="inline-block"> </div>';
3490: }
1.210 raeburn 3491: my $output =
1.171 raeburn 3492: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3493: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3494: '<td valaign="top">'.$space.
3495: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3496: for (my $i=0; $i<@rulenames; $i++) {
3497: my $rule = $rulenames[$i];
3498: my ($checked,$extra);
3499: if ($rulenames[$i] eq 'default') {
3500: $rule = '';
3501: }
3502: if ($rulenames[$i] eq 'specific') {
3503: if (ref($servers) eq 'HASH') {
3504: my $default;
3505: if (($current ne '') && (exists($servers->{$current}))) {
3506: $checked = ' checked="checked"';
3507: }
3508: unless ($checked) {
3509: $default = ' selected="selected"';
3510: }
1.210 raeburn 3511: $extra =
1.171 raeburn 3512: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3513: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3514: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3515: '<option value=""'.$default.'></option>'."\n";
3516: foreach my $server (sort(keys(%{$servers}))) {
3517: if (ref($currbalancer) eq 'HASH') {
3518: next if (exists($currbalancer->{$server}));
3519: }
1.150 raeburn 3520: my $selected;
1.171 raeburn 3521: if ($server eq $current) {
1.150 raeburn 3522: $selected = ' selected="selected"';
3523: }
1.171 raeburn 3524: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3525: }
3526: $extra .= '</select>';
3527: }
3528: } elsif ($rule eq $current) {
3529: $checked = ' checked="checked"';
3530: }
3531: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 3532: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3533: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3534: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3535: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3536: '</label>'.$extra.'</span><br />'."\n";
3537: }
3538: $output .= '</div></td></tr>'."\n";
3539: return $output;
3540: }
3541:
3542: sub offloadtype_text {
3543: my %ruletitles = &Apache::lonlocal::texthash (
3544: 'default' => 'Offloads to default destinations',
3545: 'homeserver' => "Offloads to user's home server",
3546: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3547: 'specific' => 'Offloads to specific server',
1.161 raeburn 3548: 'none' => 'No offload',
1.209 raeburn 3549: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
3550: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.150 raeburn 3551: );
3552: return %ruletitles;
3553: }
3554:
3555: sub sparestype_titles {
3556: my %typestitles = &Apache::lonlocal::texthash (
3557: 'primary' => 'primary',
3558: 'default' => 'default',
3559: );
3560: return %typestitles;
3561: }
3562:
1.28 raeburn 3563: sub contact_titles {
3564: my %titles = &Apache::lonlocal::texthash (
3565: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3566: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3567: 'errormail' => 'Error reports to be e-mailed to',
3568: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3569: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3570: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3571: 'requestsmail' => 'E-mail from course requests requiring approval',
1.190 raeburn 3572: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 3573: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 3574: );
3575: my %short_titles = &Apache::lonlocal::texthash (
3576: adminemail => 'Admin E-mail address',
3577: supportemail => 'Support E-mail',
3578: );
3579: return (\%titles,\%short_titles);
3580: }
3581:
1.72 raeburn 3582: sub tool_titles {
3583: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 3584: aboutme => 'Personal web page',
1.86 raeburn 3585: blog => 'Blog',
1.162 raeburn 3586: webdav => 'WebDAV',
1.86 raeburn 3587: portfolio => 'Portfolio',
1.88 bisitz 3588: official => 'Official courses (with institutional codes)',
3589: unofficial => 'Unofficial courses',
1.98 raeburn 3590: community => 'Communities',
1.216 raeburn 3591: textbook => 'Textbook courses',
1.86 raeburn 3592: );
1.72 raeburn 3593: return %titles;
3594: }
3595:
1.101 raeburn 3596: sub courserequest_titles {
3597: my %titles = &Apache::lonlocal::texthash (
3598: official => 'Official',
3599: unofficial => 'Unofficial',
3600: community => 'Communities',
1.216 raeburn 3601: textbook => 'Textbook',
1.101 raeburn 3602: norequest => 'Not allowed',
1.104 raeburn 3603: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3604: validate => 'With validation',
3605: autolimit => 'Numerical limit',
1.103 raeburn 3606: unlimited => '(blank for unlimited)',
1.101 raeburn 3607: );
3608: return %titles;
3609: }
3610:
1.163 raeburn 3611: sub authorrequest_titles {
3612: my %titles = &Apache::lonlocal::texthash (
3613: norequest => 'Not allowed',
3614: approval => 'Approval by Dom. Coord.',
3615: automatic => 'Automatic approval',
3616: );
3617: return %titles;
1.210 raeburn 3618: }
1.163 raeburn 3619:
1.101 raeburn 3620: sub courserequest_conditions {
3621: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3622: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 3623: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 3624: );
3625: return %conditions;
3626: }
3627:
3628:
1.27 raeburn 3629: sub print_usercreation {
1.30 raeburn 3630: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3631: my $numinrow = 4;
1.28 raeburn 3632: my $datatable;
3633: if ($position eq 'top') {
1.30 raeburn 3634: $$rowtotal ++;
1.34 raeburn 3635: my $rowcount = 0;
1.32 raeburn 3636: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3637: if (ref($rules) eq 'HASH') {
3638: if (keys(%{$rules}) > 0) {
1.32 raeburn 3639: $datatable .= &user_formats_row('username',$settings,$rules,
3640: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3641: $$rowtotal ++;
1.32 raeburn 3642: $rowcount ++;
3643: }
3644: }
3645: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3646: if (ref($idrules) eq 'HASH') {
3647: if (keys(%{$idrules}) > 0) {
3648: $datatable .= &user_formats_row('id',$settings,$idrules,
3649: $idruleorder,$numinrow,$rowcount);
3650: $$rowtotal ++;
3651: $rowcount ++;
1.28 raeburn 3652: }
3653: }
1.43 raeburn 3654: my ($emailrules,$emailruleorder) =
3655: &Apache::lonnet::inst_userrules($dom,'email');
3656: if (ref($emailrules) eq 'HASH') {
3657: if (keys(%{$emailrules}) > 0) {
3658: $datatable .= &user_formats_row('email',$settings,$emailrules,
3659: $emailruleorder,$numinrow,$rowcount);
3660: $$rowtotal ++;
3661: $rowcount ++;
3662: }
3663: }
1.39 raeburn 3664: if ($rowcount == 0) {
3665: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3666: $$rowtotal ++;
3667: $rowcount ++;
3668: }
1.34 raeburn 3669: } elsif ($position eq 'middle') {
1.100 raeburn 3670: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 3671: my ($rules,$ruleorder) =
3672: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3673: my %lt = &usercreation_types();
3674: my %checked;
1.50 raeburn 3675: my @selfcreate;
1.34 raeburn 3676: if (ref($settings) eq 'HASH') {
3677: if (ref($settings->{'cancreate'}) eq 'HASH') {
3678: foreach my $item (@creators) {
3679: $checked{$item} = $settings->{'cancreate'}{$item};
3680: }
1.50 raeburn 3681: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3682: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3683: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3684: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3685: @selfcreate = ('email','login','sso');
3686: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3687: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3688: }
3689: }
1.34 raeburn 3690: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3691: foreach my $item (@creators) {
3692: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3693: $checked{$item} = 'none';
3694: }
3695: }
3696: }
3697: }
3698: my $rownum = 0;
3699: foreach my $item (@creators) {
3700: $rownum ++;
1.50 raeburn 3701: if ($item ne 'selfcreate') {
3702: if ($checked{$item} eq '') {
1.43 raeburn 3703: $checked{$item} = 'any';
3704: }
1.34 raeburn 3705: }
3706: my $css_class;
3707: if ($rownum%2) {
3708: $css_class = '';
3709: } else {
3710: $css_class = ' class="LC_odd_row" ';
3711: }
3712: $datatable .= '<tr'.$css_class.'>'.
3713: '<td><span class="LC_nobreak">'.$lt{$item}.
3714: '</span></td><td align="right">';
1.50 raeburn 3715: my @options;
1.45 raeburn 3716: if ($item eq 'selfcreate') {
1.43 raeburn 3717: push(@options,('email','login','sso'));
3718: } else {
1.50 raeburn 3719: @options = ('any');
1.43 raeburn 3720: if (ref($rules) eq 'HASH') {
3721: if (keys(%{$rules}) > 0) {
3722: push(@options,('official','unofficial'));
3723: }
1.37 raeburn 3724: }
1.50 raeburn 3725: push(@options,'none');
1.37 raeburn 3726: }
3727: foreach my $option (@options) {
1.50 raeburn 3728: my $type = 'radio';
1.34 raeburn 3729: my $check = ' ';
1.50 raeburn 3730: if ($item eq 'selfcreate') {
3731: $type = 'checkbox';
3732: if (grep(/^\Q$option\E$/,@selfcreate)) {
3733: $check = ' checked="checked" ';
3734: }
3735: } else {
3736: if ($checked{$item} eq $option) {
3737: $check = ' checked="checked" ';
3738: }
1.34 raeburn 3739: }
3740: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3741: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3742: $item.'" value="'.$option.'"'.$check.'/> '.
3743: $lt{$option}.'</label> </span>';
3744: }
3745: $datatable .= '</td></tr>';
3746: }
1.93 raeburn 3747: my ($othertitle,$usertypes,$types) =
3748: &Apache::loncommon::sorted_inst_types($dom);
1.165 raeburn 3749: my $createsettings;
3750: if (ref($settings) eq 'HASH') {
3751: $createsettings = $settings->{cancreate};
3752: }
1.93 raeburn 3753: if (ref($usertypes) eq 'HASH') {
3754: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 3755: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 3756: $dom,$numinrow,$othertitle,
3757: 'statustocreate');
3758: $$rowtotal ++;
1.169 raeburn 3759: $rownum ++;
1.93 raeburn 3760: }
3761: }
1.169 raeburn 3762: $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
1.28 raeburn 3763: } else {
3764: my @contexts = ('author','course','domain');
3765: my @authtypes = ('int','krb4','krb5','loc');
3766: my %checked;
3767: if (ref($settings) eq 'HASH') {
3768: if (ref($settings->{'authtypes'}) eq 'HASH') {
3769: foreach my $item (@contexts) {
3770: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3771: foreach my $auth (@authtypes) {
3772: if ($settings->{'authtypes'}{$item}{$auth}) {
3773: $checked{$item}{$auth} = ' checked="checked" ';
3774: }
3775: }
3776: }
3777: }
1.27 raeburn 3778: }
1.35 raeburn 3779: } else {
3780: foreach my $item (@contexts) {
1.36 raeburn 3781: foreach my $auth (@authtypes) {
1.35 raeburn 3782: $checked{$item}{$auth} = ' checked="checked" ';
3783: }
3784: }
1.27 raeburn 3785: }
1.28 raeburn 3786: my %title = &context_names();
3787: my %authname = &authtype_names();
3788: my $rownum = 0;
3789: my $css_class;
3790: foreach my $item (@contexts) {
3791: if ($rownum%2) {
3792: $css_class = '';
3793: } else {
3794: $css_class = ' class="LC_odd_row" ';
3795: }
1.30 raeburn 3796: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3797: '<td>'.$title{$item}.
3798: '</td><td class="LC_left_item">'.
3799: '<span class="LC_nobreak">';
3800: foreach my $auth (@authtypes) {
3801: $datatable .= '<label>'.
3802: '<input type="checkbox" name="'.$item.'_auth" '.
3803: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3804: $authname{$auth}.'</label> ';
3805: }
3806: $datatable .= '</span></td></tr>';
3807: $rownum ++;
1.27 raeburn 3808: }
1.30 raeburn 3809: $$rowtotal += $rownum;
1.27 raeburn 3810: }
3811: return $datatable;
3812: }
3813:
1.165 raeburn 3814: sub captcha_choice {
1.169 raeburn 3815: my ($context,$settings,$itemcount) = @_;
1.165 raeburn 3816: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
3817: my %lt = &captcha_phrases();
3818: $keyentry = 'hidden';
3819: if ($context eq 'cancreate') {
3820: $rowname = &mt('CAPTCHA validation (e-mail as username)');
1.169 raeburn 3821: } elsif ($context eq 'login') {
3822: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 3823: }
3824: if (ref($settings) eq 'HASH') {
3825: if ($settings->{'captcha'}) {
3826: $checked{$settings->{'captcha'}} = ' checked="checked"';
3827: } else {
3828: $checked{'original'} = ' checked="checked"';
3829: }
3830: if ($settings->{'captcha'} eq 'recaptcha') {
3831: $pubtext = $lt{'pub'};
3832: $privtext = $lt{'priv'};
3833: $keyentry = 'text';
3834: }
3835: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
3836: $currpub = $settings->{'recaptchakeys'}{'public'};
3837: $currpriv = $settings->{'recaptchakeys'}{'private'};
3838: }
3839: } else {
3840: $checked{'original'} = ' checked="checked"';
3841: }
1.169 raeburn 3842: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3843: my $output = '<tr'.$css_class.'>'.
3844: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 3845: '<table><tr><td>'."\n";
3846: foreach my $option ('original','recaptcha','notused') {
3847: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
3848: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
3849: $lt{$option}.'</label></span>';
3850: unless ($option eq 'notused') {
3851: $output .= (' 'x2)."\n";
3852: }
3853: }
3854: #
3855: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
3856: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 3857: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 3858: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 3859: #
1.165 raeburn 3860: $output .= '</td></tr>'."\n".
3861: '<tr><td>'."\n".
3862: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
3863: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
3864: $currpub.'" size="40" /></span><br />'."\n".
3865: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
3866: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
3867: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
3868: '</td></tr>';
3869: return $output;
3870: }
3871:
1.32 raeburn 3872: sub user_formats_row {
3873: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3874: my $output;
3875: my %text = (
3876: 'username' => 'new usernames',
3877: 'id' => 'IDs',
1.45 raeburn 3878: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3879: );
3880: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3881: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3882: '<td><span class="LC_nobreak">';
3883: if ($type eq 'email') {
3884: $output .= &mt("Formats disallowed for $text{$type}: ");
3885: } else {
3886: $output .= &mt("Format rules to check for $text{$type}: ");
3887: }
3888: $output .= '</span></td>'.
3889: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3890: my $rem;
3891: if (ref($ruleorder) eq 'ARRAY') {
3892: for (my $i=0; $i<@{$ruleorder}; $i++) {
3893: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3894: my $rem = $i%($numinrow);
3895: if ($rem == 0) {
3896: if ($i > 0) {
3897: $output .= '</tr>';
3898: }
3899: $output .= '<tr>';
3900: }
3901: my $check = ' ';
1.39 raeburn 3902: if (ref($settings) eq 'HASH') {
3903: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3904: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3905: $check = ' checked="checked" ';
3906: }
1.27 raeburn 3907: }
3908: }
3909: $output .= '<td class="LC_left_item">'.
3910: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3911: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 3912: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3913: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3914: }
3915: }
3916: $rem = @{$ruleorder}%($numinrow);
3917: }
3918: my $colsleft = $numinrow - $rem;
3919: if ($colsleft > 1 ) {
3920: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3921: ' </td>';
3922: } elsif ($colsleft == 1) {
3923: $output .= '<td class="LC_left_item"> </td>';
3924: }
3925: $output .= '</tr></table></td></tr>';
3926: return $output;
3927: }
3928:
1.34 raeburn 3929: sub usercreation_types {
3930: my %lt = &Apache::lonlocal::texthash (
3931: author => 'When adding a co-author',
3932: course => 'When adding a user to a course',
1.100 raeburn 3933: requestcrs => 'When requesting a course',
1.45 raeburn 3934: selfcreate => 'User creates own account',
1.34 raeburn 3935: any => 'Any',
3936: official => 'Institutional only ',
3937: unofficial => 'Non-institutional only',
1.85 schafran 3938: email => 'E-mail address',
1.43 raeburn 3939: login => 'Institutional Login',
3940: sso => 'SSO',
1.34 raeburn 3941: none => 'None',
3942: );
3943: return %lt;
1.48 raeburn 3944: }
1.34 raeburn 3945:
1.28 raeburn 3946: sub authtype_names {
3947: my %lt = &Apache::lonlocal::texthash(
3948: int => 'Internal',
3949: krb4 => 'Kerberos 4',
3950: krb5 => 'Kerberos 5',
3951: loc => 'Local',
3952: );
3953: return %lt;
3954: }
3955:
3956: sub context_names {
3957: my %context_title = &Apache::lonlocal::texthash(
3958: author => 'Creating users when an Author',
3959: course => 'Creating users when in a course',
3960: domain => 'Creating users when a Domain Coordinator',
3961: );
3962: return %context_title;
3963: }
3964:
1.33 raeburn 3965: sub print_usermodification {
3966: my ($position,$dom,$settings,$rowtotal) = @_;
3967: my $numinrow = 4;
3968: my ($context,$datatable,$rowcount);
3969: if ($position eq 'top') {
3970: $rowcount = 0;
3971: $context = 'author';
3972: foreach my $role ('ca','aa') {
3973: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3974: $numinrow,$rowcount);
3975: $$rowtotal ++;
3976: $rowcount ++;
3977: }
1.63 raeburn 3978: } elsif ($position eq 'middle') {
1.33 raeburn 3979: $context = 'course';
3980: $rowcount = 0;
3981: foreach my $role ('st','ep','ta','in','cr') {
3982: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3983: $numinrow,$rowcount);
3984: $$rowtotal ++;
3985: $rowcount ++;
3986: }
1.63 raeburn 3987: } elsif ($position eq 'bottom') {
3988: $context = 'selfcreate';
3989: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3990: $usertypes->{'default'} = $othertitle;
3991: if (ref($types) eq 'ARRAY') {
3992: push(@{$types},'default');
3993: $usertypes->{'default'} = $othertitle;
3994: foreach my $status (@{$types}) {
3995: $datatable .= &modifiable_userdata_row($context,$status,$settings,
3996: $numinrow,$rowcount,$usertypes);
3997: $$rowtotal ++;
3998: $rowcount ++;
3999: }
4000: }
1.33 raeburn 4001: }
4002: return $datatable;
4003: }
4004:
1.43 raeburn 4005: sub print_defaults {
1.212 raeburn 4006: my ($dom,$settings,$rowtotal) = @_;
1.68 raeburn 4007: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 4008: 'datelocale_def','portal_def');
1.212 raeburn 4009: my %defaults;
4010: if (ref($settings) eq 'HASH') {
1.213 raeburn 4011: %defaults = %{$settings};
1.212 raeburn 4012: } else {
4013: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
4014: foreach my $item (@items) {
4015: $defaults{$item} = $domdefaults{$item};
4016: }
4017: }
1.141 raeburn 4018: my $titles = &defaults_titles($dom);
1.43 raeburn 4019: my $rownum = 0;
4020: my ($datatable,$css_class);
4021: foreach my $item (@items) {
4022: if ($rownum%2) {
4023: $css_class = '';
4024: } else {
4025: $css_class = ' class="LC_odd_row" ';
4026: }
4027: $datatable .= '<tr'.$css_class.'>'.
4028: '<td><span class="LC_nobreak">'.$titles->{$item}.
4029: '</span></td><td class="LC_right_item">';
4030: if ($item eq 'auth_def') {
4031: my @authtypes = ('internal','krb4','krb5','localauth');
4032: my %shortauth = (
4033: internal => 'int',
4034: krb4 => 'krb4',
4035: krb5 => 'krb5',
4036: localauth => 'loc'
4037: );
4038: my %authnames = &authtype_names();
4039: foreach my $auth (@authtypes) {
4040: my $checked = ' ';
1.212 raeburn 4041: if ($defaults{$item} eq $auth) {
1.43 raeburn 4042: $checked = ' checked="checked" ';
4043: }
4044: $datatable .= '<label><input type="radio" name="'.$item.
4045: '" value="'.$auth.'"'.$checked.'/>'.
4046: $authnames{$shortauth{$auth}}.'</label> ';
4047: }
1.54 raeburn 4048: } elsif ($item eq 'timezone_def') {
4049: my $includeempty = 1;
1.212 raeburn 4050: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
1.68 raeburn 4051: } elsif ($item eq 'datelocale_def') {
4052: my $includeempty = 1;
1.212 raeburn 4053: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
1.167 raeburn 4054: } elsif ($item eq 'lang_def') {
1.168 raeburn 4055: my %langchoices = &get_languages_hash();
4056: $langchoices{''} = 'No language preference';
1.167 raeburn 4057: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.212 raeburn 4058: $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,
1.167 raeburn 4059: \%langchoices);
1.43 raeburn 4060: } else {
1.141 raeburn 4061: my $size;
4062: if ($item eq 'portal_def') {
4063: $size = ' size="25"';
4064: }
1.43 raeburn 4065: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.212 raeburn 4066: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 4067: }
4068: $datatable .= '</td></tr>';
4069: $rownum ++;
4070: }
4071: $$rowtotal += $rownum;
4072: return $datatable;
4073: }
4074:
1.168 raeburn 4075: sub get_languages_hash {
4076: my %langchoices;
4077: foreach my $id (&Apache::loncommon::languageids()) {
4078: my $code = &Apache::loncommon::supportedlanguagecode($id);
4079: if ($code ne '') {
4080: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
4081: }
4082: }
4083: return %langchoices;
4084: }
4085:
1.43 raeburn 4086: sub defaults_titles {
1.141 raeburn 4087: my ($dom) = @_;
1.43 raeburn 4088: my %titles = &Apache::lonlocal::texthash (
4089: 'auth_def' => 'Default authentication type',
4090: 'auth_arg_def' => 'Default authentication argument',
4091: 'lang_def' => 'Default language',
1.54 raeburn 4092: 'timezone_def' => 'Default timezone',
1.68 raeburn 4093: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 4094: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 4095: );
1.141 raeburn 4096: if ($dom) {
4097: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
4098: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
4099: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
4100: $protocol = 'http' if ($protocol ne 'https');
4101: if ($uint_dom) {
4102: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
4103: $uint_dom);
4104: }
4105: }
1.43 raeburn 4106: return (\%titles);
4107: }
4108:
1.46 raeburn 4109: sub print_scantronformat {
4110: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
4111: my $itemcount = 1;
1.60 raeburn 4112: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
4113: %confhash);
1.46 raeburn 4114: my $switchserver = &check_switchserver($dom,$confname);
4115: my %lt = &Apache::lonlocal::texthash (
1.95 www 4116: default => 'Default bubblesheet format file error',
4117: custom => 'Custom bubblesheet format file error',
1.46 raeburn 4118: );
4119: my %scantronfiles = (
4120: default => 'default.tab',
4121: custom => 'custom.tab',
4122: );
4123: foreach my $key (keys(%scantronfiles)) {
4124: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
4125: .$scantronfiles{$key};
4126: }
4127: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
4128: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
4129: if (!$switchserver) {
4130: my $servadm = $r->dir_config('lonAdmEMail');
4131: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
4132: if ($configuserok eq 'ok') {
4133: if ($author_ok eq 'ok') {
4134: my %legacyfile = (
4135: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
4136: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
4137: );
4138: my %md5chk;
4139: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4140: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
4141: chomp($md5chk{$type});
1.46 raeburn 4142: }
4143: if ($md5chk{'default'} ne $md5chk{'custom'}) {
4144: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4145: ($scantronurls{$type},my $error) =
1.46 raeburn 4146: &legacy_scantronformat($r,$dom,$confname,
4147: $type,$legacyfile{$type},
4148: $scantronurls{$type},
4149: $scantronfiles{$type});
1.60 raeburn 4150: if ($error ne '') {
4151: $error{$type} = $error;
4152: }
4153: }
4154: if (keys(%error) == 0) {
4155: $is_custom = 1;
4156: $confhash{'scantron'}{'scantronformat'} =
4157: $scantronurls{'custom'};
4158: my $putresult =
4159: &Apache::lonnet::put_dom('configuration',
4160: \%confhash,$dom);
4161: if ($putresult ne 'ok') {
4162: $error{'custom'} =
4163: '<span class="LC_error">'.
4164: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4165: }
1.46 raeburn 4166: }
4167: } else {
1.60 raeburn 4168: ($scantronurls{'default'},my $error) =
1.46 raeburn 4169: &legacy_scantronformat($r,$dom,$confname,
4170: 'default',$legacyfile{'default'},
4171: $scantronurls{'default'},
4172: $scantronfiles{'default'});
1.60 raeburn 4173: if ($error eq '') {
4174: $confhash{'scantron'}{'scantronformat'} = '';
4175: my $putresult =
4176: &Apache::lonnet::put_dom('configuration',
4177: \%confhash,$dom);
4178: if ($putresult ne 'ok') {
4179: $error{'default'} =
4180: '<span class="LC_error">'.
4181: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4182: }
4183: } else {
4184: $error{'default'} = $error;
4185: }
1.46 raeburn 4186: }
4187: }
4188: }
4189: } else {
1.95 www 4190: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 4191: }
4192: }
4193: if (ref($settings) eq 'HASH') {
4194: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
4195: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
4196: if ((!@info) || ($info[0] eq 'no_such_dir')) {
4197: $scantronurl = '';
4198: } else {
4199: $scantronurl = $settings->{'scantronformat'};
4200: }
4201: $is_custom = 1;
4202: } else {
4203: $scantronurl = $scantronurls{'default'};
4204: }
4205: } else {
1.60 raeburn 4206: if ($is_custom) {
4207: $scantronurl = $scantronurls{'custom'};
4208: } else {
4209: $scantronurl = $scantronurls{'default'};
4210: }
1.46 raeburn 4211: }
4212: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4213: $datatable .= '<tr'.$css_class.'>';
4214: if (!$is_custom) {
1.65 raeburn 4215: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
4216: '<span class="LC_nobreak">';
1.46 raeburn 4217: if ($scantronurl) {
1.199 raeburn 4218: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
4219: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 4220: } else {
4221: $datatable = &mt('File unavailable for display');
4222: }
1.65 raeburn 4223: $datatable .= '</span></td>';
1.60 raeburn 4224: if (keys(%error) == 0) {
4225: $datatable .= '<td valign="bottom">';
4226: if (!$switchserver) {
4227: $datatable .= &mt('Upload:').'<br />';
4228: }
4229: } else {
4230: my $errorstr;
4231: foreach my $key (sort(keys(%error))) {
4232: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4233: }
4234: $datatable .= '<td>'.$errorstr;
4235: }
1.46 raeburn 4236: } else {
4237: if (keys(%error) > 0) {
4238: my $errorstr;
4239: foreach my $key (sort(keys(%error))) {
4240: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4241: }
1.60 raeburn 4242: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 4243: } elsif ($scantronurl) {
1.199 raeburn 4244: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
4245: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 4246: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 4247: $link.
4248: '<label><input type="checkbox" name="scantronformat_del"'.
4249: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 4250: '<td><span class="LC_nobreak"> '.
4251: &mt('Replace:').'</span><br />';
1.46 raeburn 4252: }
4253: }
4254: if (keys(%error) == 0) {
4255: if ($switchserver) {
4256: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4257: } else {
1.65 raeburn 4258: $datatable .='<span class="LC_nobreak"> '.
4259: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 4260: }
4261: }
4262: $datatable .= '</td></tr>';
4263: $$rowtotal ++;
4264: return $datatable;
4265: }
4266:
4267: sub legacy_scantronformat {
4268: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
4269: my ($url,$error);
4270: my @statinfo = &Apache::lonnet::stat_file($newurl);
4271: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
4272: (my $result,$url) =
4273: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
4274: '','',$newfile);
4275: if ($result ne 'ok') {
1.130 raeburn 4276: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 4277: }
4278: }
4279: return ($url,$error);
4280: }
1.43 raeburn 4281:
1.49 raeburn 4282: sub print_coursecategories {
1.57 raeburn 4283: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
4284: my $datatable;
4285: if ($position eq 'top') {
4286: my $toggle_cats_crs = ' ';
4287: my $toggle_cats_dom = ' checked="checked" ';
4288: my $can_cat_crs = ' ';
4289: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 4290: my $toggle_catscomm_comm = ' ';
4291: my $toggle_catscomm_dom = ' checked="checked" ';
4292: my $can_catcomm_comm = ' ';
4293: my $can_catcomm_dom = ' checked="checked" ';
4294:
1.57 raeburn 4295: if (ref($settings) eq 'HASH') {
4296: if ($settings->{'togglecats'} eq 'crs') {
4297: $toggle_cats_crs = $toggle_cats_dom;
4298: $toggle_cats_dom = ' ';
4299: }
4300: if ($settings->{'categorize'} eq 'crs') {
4301: $can_cat_crs = $can_cat_dom;
4302: $can_cat_dom = ' ';
4303: }
1.120 raeburn 4304: if ($settings->{'togglecatscomm'} eq 'comm') {
4305: $toggle_catscomm_comm = $toggle_catscomm_dom;
4306: $toggle_catscomm_dom = ' ';
4307: }
4308: if ($settings->{'categorizecomm'} eq 'comm') {
4309: $can_catcomm_comm = $can_catcomm_dom;
4310: $can_catcomm_dom = ' ';
4311: }
1.57 raeburn 4312: }
4313: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 4314: togglecats => 'Show/Hide a course in catalog',
4315: togglecatscomm => 'Show/Hide a community in catalog',
4316: categorize => 'Assign a category to a course',
4317: categorizecomm => 'Assign a category to a community',
1.57 raeburn 4318: );
4319: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 4320: dom => 'Set in Domain',
4321: crs => 'Set in Course',
4322: comm => 'Set in Community',
1.57 raeburn 4323: );
4324: $datatable = '<tr class="LC_odd_row">'.
4325: '<td>'.$title{'togglecats'}.'</td>'.
4326: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4327: '<input type="radio" name="togglecats"'.
4328: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4329: '<label><input type="radio" name="togglecats"'.
4330: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
4331: '</tr><tr>'.
4332: '<td>'.$title{'categorize'}.'</td>'.
4333: '<td class="LC_right_item"><span class="LC_nobreak">'.
4334: '<label><input type="radio" name="categorize"'.
4335: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4336: '<label><input type="radio" name="categorize"'.
4337: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 4338: '</tr><tr class="LC_odd_row">'.
4339: '<td>'.$title{'togglecatscomm'}.'</td>'.
4340: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4341: '<input type="radio" name="togglecatscomm"'.
4342: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4343: '<label><input type="radio" name="togglecatscomm"'.
4344: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4345: '</tr><tr>'.
4346: '<td>'.$title{'categorizecomm'}.'</td>'.
4347: '<td class="LC_right_item"><span class="LC_nobreak">'.
4348: '<label><input type="radio" name="categorizecomm"'.
4349: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4350: '<label><input type="radio" name="categorizecomm"'.
4351: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 4352: '</tr>';
1.120 raeburn 4353: $$rowtotal += 4;
1.57 raeburn 4354: } else {
4355: my $css_class;
4356: my $itemcount = 1;
4357: my $cathash;
4358: if (ref($settings) eq 'HASH') {
4359: $cathash = $settings->{'cats'};
4360: }
4361: if (ref($cathash) eq 'HASH') {
4362: my (@cats,@trails,%allitems,%idx,@jsarray);
4363: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4364: \%allitems,\%idx,\@jsarray);
4365: my $maxdepth = scalar(@cats);
4366: my $colattrib = '';
4367: if ($maxdepth > 2) {
4368: $colattrib = ' colspan="2" ';
4369: }
4370: my @path;
4371: if (@cats > 0) {
4372: if (ref($cats[0]) eq 'ARRAY') {
4373: my $numtop = @{$cats[0]};
4374: my $maxnum = $numtop;
1.120 raeburn 4375: my %default_names = (
4376: instcode => &mt('Official courses'),
4377: communities => &mt('Communities'),
4378: );
4379:
4380: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4381: ($cathash->{'instcode::0'} eq '') ||
4382: (!grep(/^communities$/,@{$cats[0]})) ||
4383: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4384: $maxnum ++;
4385: }
4386: my $lastidx;
4387: for (my $i=0; $i<$numtop; $i++) {
4388: my $parent = $cats[0][$i];
4389: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4390: my $item = &escape($parent).'::0';
4391: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4392: $lastidx = $idx{$item};
4393: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4394: .'<select name="'.$item.'"'.$chgstr.'>';
4395: for (my $k=0; $k<=$maxnum; $k++) {
4396: my $vpos = $k+1;
4397: my $selstr;
4398: if ($k == $i) {
4399: $selstr = ' selected="selected" ';
4400: }
4401: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4402: }
1.214 raeburn 4403: $datatable .= '</select></span></td><td>';
1.120 raeburn 4404: if ($parent eq 'instcode' || $parent eq 'communities') {
4405: $datatable .= '<span class="LC_nobreak">'
4406: .$default_names{$parent}.'</span>';
4407: if ($parent eq 'instcode') {
4408: $datatable .= '<br /><span class="LC_nobreak">('
4409: .&mt('with institutional codes')
4410: .')</span></td><td'.$colattrib.'>';
4411: } else {
4412: $datatable .= '<table><tr><td>';
4413: }
4414: $datatable .= '<span class="LC_nobreak">'
4415: .'<label><input type="radio" name="'
4416: .$parent.'" value="1" checked="checked" />'
4417: .&mt('Display').'</label>';
4418: if ($parent eq 'instcode') {
4419: $datatable .= ' ';
4420: } else {
4421: $datatable .= '</span></td></tr><tr><td>'
4422: .'<span class="LC_nobreak">';
4423: }
4424: $datatable .= '<label><input type="radio" name="'
4425: .$parent.'" value="0" />'
4426: .&mt('Do not display').'</label></span>';
4427: if ($parent eq 'communities') {
4428: $datatable .= '</td></tr></table>';
4429: }
4430: $datatable .= '</td>';
1.57 raeburn 4431: } else {
4432: $datatable .= $parent
1.214 raeburn 4433: .' <span class="LC_nobreak"><label>'
4434: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 4435: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4436: }
4437: my $depth = 1;
4438: push(@path,$parent);
4439: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4440: pop(@path);
4441: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4442: $itemcount ++;
4443: }
1.48 raeburn 4444: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 4445: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4446: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 4447: for (my $k=0; $k<=$maxnum; $k++) {
4448: my $vpos = $k+1;
4449: my $selstr;
1.57 raeburn 4450: if ($k == $numtop) {
1.48 raeburn 4451: $selstr = ' selected="selected" ';
4452: }
4453: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4454: }
1.59 bisitz 4455: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 4456: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4457: .'</tr>'."\n";
1.48 raeburn 4458: $itemcount ++;
1.120 raeburn 4459: foreach my $default ('instcode','communities') {
4460: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4461: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4462: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4463: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4464: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4465: for (my $k=0; $k<=$maxnum; $k++) {
4466: my $vpos = $k+1;
4467: my $selstr;
4468: if ($k == $maxnum) {
4469: $selstr = ' selected="selected" ';
4470: }
4471: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 4472: }
1.120 raeburn 4473: $datatable .= '</select></span></td>'.
4474: '<td><span class="LC_nobreak">'.
4475: $default_names{$default}.'</span>';
4476: if ($default eq 'instcode') {
4477: $datatable .= '<br /><span class="LC_nobreak">('
4478: .&mt('with institutional codes').')</span>';
4479: }
4480: $datatable .= '</td>'
4481: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4482: .&mt('Display').'</label> '
4483: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
4484: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 4485: }
4486: }
4487: }
1.57 raeburn 4488: } else {
4489: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 4490: }
4491: } else {
1.57 raeburn 4492: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
4493: .&initialize_categories($itemcount);
1.48 raeburn 4494: }
1.57 raeburn 4495: $$rowtotal += $itemcount;
1.48 raeburn 4496: }
4497: return $datatable;
4498: }
4499:
1.69 raeburn 4500: sub print_serverstatuses {
4501: my ($dom,$settings,$rowtotal) = @_;
4502: my $datatable;
4503: my @pages = &serverstatus_pages();
4504: my (%namedaccess,%machineaccess);
4505: foreach my $type (@pages) {
4506: $namedaccess{$type} = '';
4507: $machineaccess{$type}= '';
4508: }
4509: if (ref($settings) eq 'HASH') {
4510: foreach my $type (@pages) {
4511: if (exists($settings->{$type})) {
4512: if (ref($settings->{$type}) eq 'HASH') {
4513: foreach my $key (keys(%{$settings->{$type}})) {
4514: if ($key eq 'namedusers') {
4515: $namedaccess{$type} = $settings->{$type}->{$key};
4516: } elsif ($key eq 'machines') {
4517: $machineaccess{$type} = $settings->{$type}->{$key};
4518: }
4519: }
4520: }
4521: }
4522: }
4523: }
1.81 raeburn 4524: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 4525: my $rownum = 0;
4526: my $css_class;
4527: foreach my $type (@pages) {
4528: $rownum ++;
4529: $css_class = $rownum%2?' class="LC_odd_row"':'';
4530: $datatable .= '<tr'.$css_class.'>'.
4531: '<td><span class="LC_nobreak">'.
4532: $titles->{$type}.'</span></td>'.
4533: '<td class="LC_left_item">'.
4534: '<input type="text" name="'.$type.'_namedusers" '.
4535: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
4536: '<td class="LC_right_item">'.
4537: '<span class="LC_nobreak">'.
4538: '<input type="text" name="'.$type.'_machines" '.
4539: 'value="'.$machineaccess{$type}.'" size="10" />'.
4540: '</td></tr>'."\n";
4541: }
4542: $$rowtotal += $rownum;
4543: return $datatable;
4544: }
4545:
4546: sub serverstatus_pages {
4547: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.189 raeburn 4548: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.221 ! raeburn 4549: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
! 4550: 'uniquecodes');
1.69 raeburn 4551: }
4552:
1.49 raeburn 4553: sub coursecategories_javascript {
4554: my ($settings) = @_;
1.57 raeburn 4555: my ($output,$jstext,$cathash);
1.49 raeburn 4556: if (ref($settings) eq 'HASH') {
1.57 raeburn 4557: $cathash = $settings->{'cats'};
4558: }
4559: if (ref($cathash) eq 'HASH') {
1.49 raeburn 4560: my (@cats,@jsarray,%idx);
1.57 raeburn 4561: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 4562: if (@jsarray > 0) {
4563: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
4564: for (my $i=0; $i<@jsarray; $i++) {
4565: if (ref($jsarray[$i]) eq 'ARRAY') {
4566: my $catstr = join('","',@{$jsarray[$i]});
4567: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
4568: }
4569: }
4570: }
4571: } else {
4572: $jstext = ' var categories = Array(1);'."\n".
4573: ' categories[0] = Array("instcode_pos");'."\n";
4574: }
1.120 raeburn 4575: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
4576: my $communities_reserved = &mt('The name: "communities" is a reserved category');
4577: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 4578: $output = <<"ENDSCRIPT";
4579: <script type="text/javascript">
1.109 raeburn 4580: // <![CDATA[
1.49 raeburn 4581: function reorderCats(form,parent,item,idx) {
4582: var changedVal;
4583: $jstext
4584: var newpos = 'addcategory_pos';
4585: var current = new Array;
4586: if (parent == '') {
4587: var has_instcode = 0;
4588: var maxtop = categories[idx].length;
4589: for (var j=0; j<maxtop; j++) {
4590: if (categories[idx][j] == 'instcode::0') {
4591: has_instcode == 1;
4592: }
4593: }
4594: if (has_instcode == 0) {
4595: categories[idx][maxtop] = 'instcode_pos';
4596: }
4597: } else {
4598: newpos += '_'+parent;
4599: }
4600: var maxh = 1 + categories[idx].length;
4601: var current = new Array;
4602: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4603: if (item == newpos) {
4604: changedVal = newitemVal;
4605: } else {
4606: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4607: current[newitemVal] = newpos;
4608: }
4609: for (var i=0; i<categories[idx].length; i++) {
4610: var elementName = categories[idx][i];
4611: if (elementName != item) {
4612: if (form.elements[elementName]) {
4613: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4614: current[currVal] = elementName;
4615: }
4616: }
4617: }
4618: var oldVal;
4619: for (var j=0; j<maxh; j++) {
4620: if (current[j] == undefined) {
4621: oldVal = j;
4622: }
4623: }
4624: if (oldVal < changedVal) {
4625: for (var k=oldVal+1; k<=changedVal ; k++) {
4626: var elementName = current[k];
4627: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4628: }
4629: } else {
4630: for (var k=changedVal; k<oldVal; k++) {
4631: var elementName = current[k];
4632: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4633: }
4634: }
4635: return;
4636: }
1.120 raeburn 4637:
4638: function categoryCheck(form) {
4639: if (form.elements['addcategory_name'].value == 'instcode') {
4640: alert('$instcode_reserved\\n$choose_again');
4641: return false;
4642: }
4643: if (form.elements['addcategory_name'].value == 'communities') {
4644: alert('$communities_reserved\\n$choose_again');
4645: return false;
4646: }
4647: return true;
4648: }
4649:
1.109 raeburn 4650: // ]]>
1.49 raeburn 4651: </script>
4652:
4653: ENDSCRIPT
4654: return $output;
4655: }
4656:
1.48 raeburn 4657: sub initialize_categories {
4658: my ($itemcount) = @_;
1.120 raeburn 4659: my ($datatable,$css_class,$chgstr);
4660: my %default_names = (
4661: instcode => 'Official courses (with institutional codes)',
4662: communities => 'Communities',
4663: );
4664: my $select0 = ' selected="selected"';
4665: my $select1 = '';
4666: foreach my $default ('instcode','communities') {
4667: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4668: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
4669: if ($default eq 'communities') {
4670: $select1 = $select0;
4671: $select0 = '';
4672: }
4673: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4674: .'<select name="'.$default.'_pos">'
4675: .'<option value="0"'.$select0.'>1</option>'
4676: .'<option value="1"'.$select1.'>2</option>'
4677: .'<option value="2">3</option></select> '
4678: .$default_names{$default}
4679: .'</span></td><td><span class="LC_nobreak">'
4680: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4681: .&mt('Display').'</label> <label>'
4682: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 4683: .'</label></span></td></tr>';
1.120 raeburn 4684: $itemcount ++;
4685: }
1.48 raeburn 4686: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 4687: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 4688: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 4689: .'<select name="addcategory_pos"'.$chgstr.'>'
4690: .'<option value="0">1</option>'
4691: .'<option value="1">2</option>'
4692: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 4693: .&mt('Add category').'</td><td>'.&mt('Name:')
4694: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4695: return $datatable;
4696: }
4697:
4698: sub build_category_rows {
1.49 raeburn 4699: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4700: my ($text,$name,$item,$chgstr);
1.48 raeburn 4701: if (ref($cats) eq 'ARRAY') {
4702: my $maxdepth = scalar(@{$cats});
4703: if (ref($cats->[$depth]) eq 'HASH') {
4704: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4705: my $numchildren = @{$cats->[$depth]{$parent}};
4706: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 4707: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 4708: my ($idxnum,$parent_name,$parent_item);
4709: my $higher = $depth - 1;
4710: if ($higher == 0) {
4711: $parent_name = &escape($parent).'::'.$higher;
4712: } else {
4713: if (ref($path) eq 'ARRAY') {
4714: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4715: }
4716: }
4717: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4718: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4719: if ($j < $numchildren) {
1.48 raeburn 4720: $name = $cats->[$depth]{$parent}[$j];
4721: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4722: $idxnum = $idx->{$item};
4723: } else {
4724: $name = $parent_name;
4725: $item = $parent_item;
1.48 raeburn 4726: }
1.49 raeburn 4727: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4728: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4729: for (my $i=0; $i<=$numchildren; $i++) {
4730: my $vpos = $i+1;
4731: my $selstr;
4732: if ($j == $i) {
4733: $selstr = ' selected="selected" ';
4734: }
4735: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4736: }
4737: $text .= '</select> ';
4738: if ($j < $numchildren) {
4739: my $deeper = $depth+1;
4740: $text .= $name.' '
4741: .'<label><input type="checkbox" name="deletecategory" value="'
4742: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4743: if(ref($path) eq 'ARRAY') {
4744: push(@{$path},$name);
1.49 raeburn 4745: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4746: pop(@{$path});
4747: }
4748: } else {
1.59 bisitz 4749: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4750: if ($j == $numchildren) {
4751: $text .= $name;
4752: } else {
4753: $text .= $item;
4754: }
4755: $text .= '" value="" />';
4756: }
4757: $text .= '</td></tr>';
4758: }
4759: $text .= '</table></td>';
4760: } else {
4761: my $higher = $depth-1;
4762: if ($higher == 0) {
4763: $name = &escape($parent).'::'.$higher;
4764: } else {
4765: if (ref($path) eq 'ARRAY') {
4766: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4767: }
4768: }
4769: my $colspan;
4770: if ($parent ne 'instcode') {
4771: $colspan = $maxdepth - $depth - 1;
4772: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4773: }
4774: }
4775: }
4776: }
4777: return $text;
4778: }
4779:
1.33 raeburn 4780: sub modifiable_userdata_row {
1.63 raeburn 4781: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 4782: my $rolename;
1.63 raeburn 4783: if ($context eq 'selfcreate') {
4784: if (ref($usertypes) eq 'HASH') {
4785: $rolename = $usertypes->{$role};
4786: } else {
4787: $rolename = $role;
4788: }
1.33 raeburn 4789: } else {
1.63 raeburn 4790: if ($role eq 'cr') {
4791: $rolename = &mt('Custom role');
4792: } else {
4793: $rolename = &Apache::lonnet::plaintext($role);
4794: }
1.33 raeburn 4795: }
4796: my @fields = ('lastname','firstname','middlename','generation',
4797: 'permanentemail','id');
4798: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4799: my $output;
4800: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4801: $output = '<tr '.$css_class.'>'.
4802: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4803: '<td class="LC_left_item" colspan="2"><table>';
4804: my $rem;
4805: my %checks;
4806: if (ref($settings) eq 'HASH') {
4807: if (ref($settings->{$context}) eq 'HASH') {
4808: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4809: foreach my $field (@fields) {
4810: if ($settings->{$context}->{$role}->{$field}) {
4811: $checks{$field} = ' checked="checked" ';
4812: }
4813: }
4814: }
4815: }
4816: }
4817: for (my $i=0; $i<@fields; $i++) {
4818: my $rem = $i%($numinrow);
4819: if ($rem == 0) {
4820: if ($i > 0) {
4821: $output .= '</tr>';
4822: }
4823: $output .= '<tr>';
4824: }
4825: my $check = ' ';
4826: if (exists($checks{$fields[$i]})) {
4827: $check = $checks{$fields[$i]}
4828: } else {
4829: if ($role eq 'st') {
4830: if (ref($settings) ne 'HASH') {
4831: $check = ' checked="checked" ';
4832: }
4833: }
4834: }
4835: $output .= '<td class="LC_left_item">'.
4836: '<span class="LC_nobreak"><label>'.
4837: '<input type="checkbox" name="canmodify_'.$role.'" '.
4838: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4839: '</label></span></td>';
4840: $rem = @fields%($numinrow);
4841: }
4842: my $colsleft = $numinrow - $rem;
4843: if ($colsleft > 1 ) {
4844: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4845: ' </td>';
4846: } elsif ($colsleft == 1) {
4847: $output .= '<td class="LC_left_item"> </td>';
4848: }
4849: $output .= '</tr></table></td></tr>';
4850: return $output;
4851: }
1.28 raeburn 4852:
1.93 raeburn 4853: sub insttypes_row {
4854: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
4855: my %lt = &Apache::lonlocal::texthash (
4856: cansearch => 'Users allowed to search',
4857: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4858: lockablenames => 'User preference to lock name',
1.93 raeburn 4859: );
4860: my $showdom;
4861: if ($context eq 'cansearch') {
4862: $showdom = ' ('.$dom.')';
4863: }
1.165 raeburn 4864: my $class = 'LC_left_item';
4865: if ($context eq 'statustocreate') {
4866: $class = 'LC_right_item';
4867: }
1.25 raeburn 4868: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 4869: '<td>'.$lt{$context}.$showdom.
1.165 raeburn 4870: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 4871: my $rem;
4872: if (ref($types) eq 'ARRAY') {
4873: for (my $i=0; $i<@{$types}; $i++) {
4874: if (defined($usertypes->{$types->[$i]})) {
4875: my $rem = $i%($numinrow);
4876: if ($rem == 0) {
4877: if ($i > 0) {
4878: $output .= '</tr>';
4879: }
4880: $output .= '<tr>';
1.23 raeburn 4881: }
1.26 raeburn 4882: my $check = ' ';
1.99 raeburn 4883: if (ref($settings) eq 'HASH') {
4884: if (ref($settings->{$context}) eq 'ARRAY') {
4885: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4886: $check = ' checked="checked" ';
4887: }
4888: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4889: $check = ' checked="checked" ';
4890: }
1.23 raeburn 4891: }
1.26 raeburn 4892: $output .= '<td class="LC_left_item">'.
4893: '<span class="LC_nobreak"><label>'.
1.93 raeburn 4894: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 4895: 'value="'.$types->[$i].'"'.$check.'/>'.
4896: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 4897: }
4898: }
1.26 raeburn 4899: $rem = @{$types}%($numinrow);
1.23 raeburn 4900: }
4901: my $colsleft = $numinrow - $rem;
1.131 raeburn 4902: if (($rem == 0) && (@{$types} > 0)) {
4903: $output .= '<tr>';
4904: }
1.23 raeburn 4905: if ($colsleft > 1) {
1.25 raeburn 4906: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 4907: } else {
1.25 raeburn 4908: $output .= '<td class="LC_left_item">';
1.23 raeburn 4909: }
4910: my $defcheck = ' ';
1.99 raeburn 4911: if (ref($settings) eq 'HASH') {
4912: if (ref($settings->{$context}) eq 'ARRAY') {
4913: if (grep(/^default$/,@{$settings->{$context}})) {
4914: $defcheck = ' checked="checked" ';
4915: }
4916: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4917: $defcheck = ' checked="checked" ';
4918: }
1.23 raeburn 4919: }
1.25 raeburn 4920: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 4921: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 4922: 'value="default"'.$defcheck.'/>'.
4923: $othertitle.'</label></span></td>'.
4924: '</tr></table></td></tr>';
4925: return $output;
1.23 raeburn 4926: }
4927:
4928: sub sorted_searchtitles {
4929: my %searchtitles = &Apache::lonlocal::texthash(
4930: 'uname' => 'username',
4931: 'lastname' => 'last name',
4932: 'lastfirst' => 'last name, first name',
4933: );
4934: my @titleorder = ('uname','lastname','lastfirst');
4935: return (\%searchtitles,\@titleorder);
4936: }
4937:
1.25 raeburn 4938: sub sorted_searchtypes {
4939: my %srchtypes_desc = (
4940: exact => 'is exact match',
4941: contains => 'contains ..',
4942: begins => 'begins with ..',
4943: );
4944: my @srchtypeorder = ('exact','begins','contains');
4945: return (\%srchtypes_desc,\@srchtypeorder);
4946: }
4947:
1.3 raeburn 4948: sub usertype_update_row {
4949: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
4950: my $datatable;
4951: my $numinrow = 4;
4952: foreach my $type (@{$types}) {
4953: if (defined($usertypes->{$type})) {
4954: $$rownums ++;
4955: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
4956: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
4957: '</td><td class="LC_left_item"><table>';
4958: for (my $i=0; $i<@{$fields}; $i++) {
4959: my $rem = $i%($numinrow);
4960: if ($rem == 0) {
4961: if ($i > 0) {
4962: $datatable .= '</tr>';
4963: }
4964: $datatable .= '<tr>';
4965: }
4966: my $check = ' ';
1.39 raeburn 4967: if (ref($settings) eq 'HASH') {
4968: if (ref($settings->{'fields'}) eq 'HASH') {
4969: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
4970: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
4971: $check = ' checked="checked" ';
4972: }
1.3 raeburn 4973: }
4974: }
4975: }
4976:
4977: if ($i == @{$fields}-1) {
4978: my $colsleft = $numinrow - $rem;
4979: if ($colsleft > 1) {
4980: $datatable .= '<td colspan="'.$colsleft.'">';
4981: } else {
4982: $datatable .= '<td>';
4983: }
4984: } else {
4985: $datatable .= '<td>';
4986: }
1.8 raeburn 4987: $datatable .= '<span class="LC_nobreak"><label>'.
4988: '<input type="checkbox" name="updateable_'.$type.
4989: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
4990: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 4991: }
4992: $datatable .= '</tr></table></td></tr>';
4993: }
4994: }
4995: return $datatable;
1.1 raeburn 4996: }
4997:
4998: sub modify_login {
1.205 raeburn 4999: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 5000: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
5001: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
5002: %title = ( coursecatalog => 'Display course catalog',
5003: adminmail => 'Display administrator E-mail address',
1.188 raeburn 5004: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 5005: newuser => 'Link for visitors to create a user account',
5006: loginheader => 'Log-in box header');
5007: @offon = ('off','on');
1.112 raeburn 5008: if (ref($domconfig{login}) eq 'HASH') {
5009: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
5010: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
5011: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
5012: }
5013: }
5014: }
1.9 raeburn 5015: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
5016: \%domconfig,\%loginhash);
1.188 raeburn 5017: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5018: foreach my $item (@toggles) {
5019: $loginhash{login}{$item} = $env{'form.'.$item};
5020: }
1.41 raeburn 5021: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 5022: if (ref($colchanges{'login'}) eq 'HASH') {
5023: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
5024: \%loginhash);
5025: }
1.110 raeburn 5026:
1.149 raeburn 5027: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 5028: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 5029: if (keys(%servers) > 1) {
5030: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 5031: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
5032: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
5033: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
5034: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
5035: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
5036: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5037: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5038: $changes{'loginvia'}{$lonhost} = 1;
5039: } else {
5040: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
5041: $changes{'loginvia'}{$lonhost} = 1;
5042: }
5043: } else {
5044: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5045: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5046: $changes{'loginvia'}{$lonhost} = 1;
5047: }
5048: }
5049: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
5050: foreach my $item (@loginvia_attribs) {
5051: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
5052: }
5053: } else {
5054: foreach my $item (@loginvia_attribs) {
5055: my $new = $env{'form.'.$lonhost.'_'.$item};
5056: if (($item eq 'serverpath') && ($new eq 'custom')) {
5057: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
5058: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5059: $new = '/';
5060: }
5061: }
5062: if (($item eq 'custompath') &&
5063: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5064: $new = '';
5065: }
5066: if ($new ne $curr_loginvia{$lonhost}{$item}) {
5067: $changes{'loginvia'}{$lonhost} = 1;
5068: }
5069: if ($item eq 'exempt') {
5070: $new =~ s/^\s+//;
5071: $new =~ s/\s+$//;
5072: my @poss_ips = split(/\s*[,:]\s*/,$new);
5073: my @okips;
5074: foreach my $ip (@poss_ips) {
5075: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
5076: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
5077: push(@okips,$ip);
5078: }
5079: }
5080: }
5081: if (@okips > 0) {
5082: $new = join(',',@okips);
5083: } else {
5084: $new = '';
5085: }
5086: }
5087: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5088: }
5089: }
1.112 raeburn 5090: } else {
1.128 raeburn 5091: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5092: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 5093: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 5094: foreach my $item (@loginvia_attribs) {
5095: my $new = $env{'form.'.$lonhost.'_'.$item};
5096: if (($item eq 'serverpath') && ($new eq 'custom')) {
5097: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5098: $new = '/';
5099: }
5100: }
5101: if (($item eq 'custompath') &&
5102: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5103: $new = '';
5104: }
5105: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5106: }
1.110 raeburn 5107: }
5108: }
5109: }
5110: }
1.119 raeburn 5111:
1.168 raeburn 5112: my $servadm = $r->dir_config('lonAdmEMail');
5113: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
5114: if (ref($domconfig{'login'}) eq 'HASH') {
5115: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
5116: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
5117: if ($lang eq 'nolang') {
5118: push(@currlangs,$lang);
5119: } elsif (defined($langchoices{$lang})) {
5120: push(@currlangs,$lang);
5121: } else {
5122: next;
5123: }
5124: }
5125: }
5126: }
5127: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
5128: if (@currlangs > 0) {
5129: foreach my $lang (@currlangs) {
5130: if (grep(/^\Q$lang\E$/,@delurls)) {
5131: $changes{'helpurl'}{$lang} = 1;
5132: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
5133: $changes{'helpurl'}{$lang} = 1;
5134: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
5135: push(@newlangs,$lang);
5136: } else {
5137: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5138: }
5139: }
5140: }
5141: unless (grep(/^nolang$/,@currlangs)) {
5142: if ($env{'form.loginhelpurl_nolang.filename'}) {
5143: $changes{'helpurl'}{'nolang'} = 1;
5144: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
5145: push(@newlangs,'nolang');
5146: }
5147: }
5148: if ($env{'form.loginhelpurl_add_lang'}) {
5149: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
5150: ($env{'form.loginhelpurl_add_file.filename'})) {
5151: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
5152: $addedfile = $env{'form.loginhelpurl_add_lang'};
5153: }
5154: }
5155: if ((@newlangs > 0) || ($addedfile)) {
5156: my $error;
5157: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
5158: if ($configuserok eq 'ok') {
5159: if ($switchserver) {
5160: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
5161: } elsif ($author_ok eq 'ok') {
5162: my @allnew = @newlangs;
5163: if ($addedfile ne '') {
5164: push(@allnew,$addedfile);
5165: }
5166: foreach my $lang (@allnew) {
5167: my $formelem = 'loginhelpurl_'.$lang;
5168: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
5169: $formelem = 'loginhelpurl_add_file';
5170: }
5171: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
5172: "help/$lang",'','',$newfile{$lang});
5173: if ($result eq 'ok') {
5174: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
5175: $changes{'helpurl'}{$lang} = 1;
5176: } else {
5177: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
5178: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 5179: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 5180: (!grep(/^\Q$lang\E$/,@delurls))) {
5181:
5182: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5183: }
5184: }
5185: }
5186: } else {
5187: $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);
5188: }
5189: } else {
5190: $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);
5191: }
5192: if ($error) {
5193: &Apache::lonnet::logthis($error);
5194: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
5195: }
5196: }
1.169 raeburn 5197: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 5198:
5199: my $defaulthelpfile = '/adm/loginproblems.html';
5200: my $defaulttext = &mt('Default in use');
5201:
1.1 raeburn 5202: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
5203: $dom);
5204: if ($putresult eq 'ok') {
1.188 raeburn 5205: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5206: my %defaultchecked = (
5207: 'coursecatalog' => 'on',
1.188 raeburn 5208: 'helpdesk' => 'on',
1.42 raeburn 5209: 'adminmail' => 'off',
1.43 raeburn 5210: 'newuser' => 'off',
1.42 raeburn 5211: );
1.55 raeburn 5212: if (ref($domconfig{'login'}) eq 'HASH') {
5213: foreach my $item (@toggles) {
5214: if ($defaultchecked{$item} eq 'on') {
5215: if (($domconfig{'login'}{$item} eq '0') &&
5216: ($env{'form.'.$item} eq '1')) {
5217: $changes{$item} = 1;
5218: } elsif (($domconfig{'login'}{$item} eq '' ||
5219: $domconfig{'login'}{$item} eq '1') &&
5220: ($env{'form.'.$item} eq '0')) {
5221: $changes{$item} = 1;
5222: }
5223: } elsif ($defaultchecked{$item} eq 'off') {
5224: if (($domconfig{'login'}{$item} eq '1') &&
5225: ($env{'form.'.$item} eq '0')) {
5226: $changes{$item} = 1;
5227: } elsif (($domconfig{'login'}{$item} eq '' ||
5228: $domconfig{'login'}{$item} eq '0') &&
5229: ($env{'form.'.$item} eq '1')) {
5230: $changes{$item} = 1;
5231: }
1.42 raeburn 5232: }
5233: }
1.41 raeburn 5234: }
1.6 raeburn 5235: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 5236: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 5237: if (ref($lastactref) eq 'HASH') {
5238: $lastactref->{'domainconfig'} = 1;
5239: }
1.1 raeburn 5240: $resulttext = &mt('Changes made:').'<ul>';
5241: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 5242: if ($item eq 'loginvia') {
1.112 raeburn 5243: if (ref($changes{$item}) eq 'HASH') {
5244: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
5245: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 5246: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
5247: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
5248: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
5249: $protocol = 'http' if ($protocol ne 'https');
5250: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
5251:
5252: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
5253: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
5254: } else {
5255: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
5256: }
5257: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
5258: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
5259: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
5260: }
5261: $resulttext .= '</li>';
5262: } else {
5263: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
5264: }
1.112 raeburn 5265: } else {
1.128 raeburn 5266: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 5267: }
5268: }
1.128 raeburn 5269: $resulttext .= '</ul></li>';
1.112 raeburn 5270: }
1.168 raeburn 5271: } elsif ($item eq 'helpurl') {
5272: if (ref($changes{$item}) eq 'HASH') {
5273: foreach my $lang (sort(keys(%{$changes{$item}}))) {
5274: if (grep(/^\Q$lang\E$/,@delurls)) {
5275: my ($chg,$link);
5276: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
5277: if ($lang eq 'nolang') {
5278: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
5279: } else {
5280: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
5281: }
5282: $resulttext .= '<li>'.$chg.'</li>';
5283: } else {
5284: my $chg;
5285: if ($lang eq 'nolang') {
5286: $chg = &mt('custom log-in help file for no preferred language');
5287: } else {
5288: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
5289: }
5290: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
5291: $loginhash{'login'}{'helpurl'}{$lang}.
5292: '?inhibitmenu=yes',$chg,600,500).
5293: '</li>';
5294: }
5295: }
5296: }
1.169 raeburn 5297: } elsif ($item eq 'captcha') {
5298: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 5299: my $chgtxt;
1.169 raeburn 5300: if ($loginhash{'login'}{$item} eq 'notused') {
5301: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
5302: } else {
5303: my %captchas = &captcha_phrases();
5304: if ($captchas{$loginhash{'login'}{$item}}) {
5305: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
5306: } else {
5307: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
5308: }
5309: }
5310: $resulttext .= '<li>'.$chgtxt.'</li>';
5311: }
5312: } elsif ($item eq 'recaptchakeys') {
5313: if (ref($loginhash{'login'}) eq 'HASH') {
5314: my ($privkey,$pubkey);
5315: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
5316: $pubkey = $loginhash{'login'}{$item}{'public'};
5317: $privkey = $loginhash{'login'}{$item}{'private'};
5318: }
5319: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
5320: if (!$pubkey) {
5321: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
5322: } else {
5323: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
5324: }
5325: if (!$privkey) {
5326: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
5327: } else {
5328: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
5329: }
5330: $chgtxt .= '</ul>';
5331: $resulttext .= '<li>'.$chgtxt.'</li>';
5332: }
1.41 raeburn 5333: } else {
5334: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
5335: }
1.1 raeburn 5336: }
1.6 raeburn 5337: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 5338: } else {
5339: $resulttext = &mt('No changes made to log-in page settings');
5340: }
5341: } else {
1.11 albertel 5342: $resulttext = '<span class="LC_error">'.
5343: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5344: }
1.6 raeburn 5345: if ($errors) {
1.9 raeburn 5346: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 5347: $errors.'</ul>';
5348: }
5349: return $resulttext;
5350: }
5351:
5352: sub color_font_choices {
5353: my %choices =
5354: &Apache::lonlocal::texthash (
5355: img => "Header",
5356: bgs => "Background colors",
5357: links => "Link colors",
1.55 raeburn 5358: images => "Images",
1.6 raeburn 5359: font => "Font color",
1.201 raeburn 5360: fontmenu => "Font menu",
1.76 raeburn 5361: pgbg => "Page",
1.6 raeburn 5362: tabbg => "Header",
5363: sidebg => "Border",
5364: link => "Link",
5365: alink => "Active link",
5366: vlink => "Visited link",
5367: );
5368: return %choices;
5369: }
5370:
5371: sub modify_rolecolors {
1.205 raeburn 5372: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 5373: my ($resulttext,%rolehash);
5374: $rolehash{'rolecolors'} = {};
1.55 raeburn 5375: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
5376: if ($domconfig{'rolecolors'} eq '') {
5377: $domconfig{'rolecolors'} = {};
5378: }
5379: }
1.9 raeburn 5380: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 5381: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
5382: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
5383: $dom);
5384: if ($putresult eq 'ok') {
5385: if (keys(%changes) > 0) {
1.41 raeburn 5386: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 5387: if (ref($lastactref) eq 'HASH') {
5388: $lastactref->{'domainconfig'} = 1;
5389: }
1.6 raeburn 5390: $resulttext = &display_colorchgs($dom,\%changes,$roles,
5391: $rolehash{'rolecolors'});
5392: } else {
5393: $resulttext = &mt('No changes made to default color schemes');
5394: }
5395: } else {
1.11 albertel 5396: $resulttext = '<span class="LC_error">'.
5397: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 5398: }
5399: if ($errors) {
5400: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5401: $errors.'</ul>';
5402: }
5403: return $resulttext;
5404: }
5405:
5406: sub modify_colors {
1.9 raeburn 5407: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 5408: my (%changes,%choices);
1.51 raeburn 5409: my @bgs;
1.6 raeburn 5410: my @links = ('link','alink','vlink');
1.41 raeburn 5411: my @logintext;
1.6 raeburn 5412: my @images;
5413: my $servadm = $r->dir_config('lonAdmEMail');
5414: my $errors;
1.200 raeburn 5415: my %defaults;
1.6 raeburn 5416: foreach my $role (@{$roles}) {
5417: if ($role eq 'login') {
1.12 raeburn 5418: %choices = &login_choices();
1.41 raeburn 5419: @logintext = ('textcol','bgcol');
1.12 raeburn 5420: } else {
5421: %choices = &color_font_choices();
5422: }
5423: if ($role eq 'login') {
1.41 raeburn 5424: @images = ('img','logo','domlogo','login');
1.51 raeburn 5425: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 5426: } else {
5427: @images = ('img');
1.200 raeburn 5428: @bgs = ('pgbg','tabbg','sidebg');
5429: }
5430: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
5431: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
5432: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
5433: }
5434: if ($role eq 'login') {
5435: foreach my $item (@logintext) {
5436: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'logintext'}{$item}) {
5437: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5438: }
5439: }
5440: } else {
5441: unless($env{'form.'.$role.'_fontmenu'} eq $defaults{'fontmenu'}) {
5442: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
5443: }
1.6 raeburn 5444: }
1.200 raeburn 5445: foreach my $item (@bgs) {
5446: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'bgs'}{$item} ) {
5447: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5448: }
5449: }
5450: foreach my $item (@links) {
5451: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'links'}{$item}) {
5452: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5453: }
1.6 raeburn 5454: }
1.46 raeburn 5455: my ($configuserok,$author_ok,$switchserver) =
5456: &config_check($dom,$confname,$servadm);
1.9 raeburn 5457: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 5458: if (ref($domconfig->{$role}) ne 'HASH') {
5459: $domconfig->{$role} = {};
5460: }
1.8 raeburn 5461: foreach my $img (@images) {
1.70 raeburn 5462: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
5463: if (defined($env{'form.login_showlogo_'.$img})) {
5464: $confhash->{$role}{'showlogo'}{$img} = 1;
5465: } else {
5466: $confhash->{$role}{'showlogo'}{$img} = 0;
5467: }
5468: }
1.18 albertel 5469: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
5470: && !defined($domconfig->{$role}{$img})
5471: && !$env{'form.'.$role.'_del_'.$img}
5472: && $env{'form.'.$role.'_import_'.$img}) {
5473: # import the old configured image from the .tab setting
5474: # if they haven't provided a new one
5475: $domconfig->{$role}{$img} =
5476: $env{'form.'.$role.'_import_'.$img};
5477: }
1.6 raeburn 5478: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 5479: my $error;
1.6 raeburn 5480: if ($configuserok eq 'ok') {
1.9 raeburn 5481: if ($switchserver) {
1.12 raeburn 5482: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 5483: } else {
5484: if ($author_ok eq 'ok') {
5485: my ($result,$logourl) =
5486: &publishlogo($r,'upload',$role.'_'.$img,
5487: $dom,$confname,$img,$width,$height);
5488: if ($result eq 'ok') {
5489: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 5490: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5491: } else {
1.12 raeburn 5492: $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 5493: }
5494: } else {
1.46 raeburn 5495: $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 5496: }
5497: }
5498: } else {
1.46 raeburn 5499: $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 5500: }
5501: if ($error) {
1.8 raeburn 5502: &Apache::lonnet::logthis($error);
1.11 albertel 5503: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 5504: }
5505: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 5506: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
5507: my $error;
5508: if ($configuserok eq 'ok') {
5509: # is confname an author?
5510: if ($switchserver eq '') {
5511: if ($author_ok eq 'ok') {
5512: my ($result,$logourl) =
5513: &publishlogo($r,'copy',$domconfig->{$role}{$img},
5514: $dom,$confname,$img,$width,$height);
5515: if ($result eq 'ok') {
5516: $confhash->{$role}{$img} = $logourl;
1.18 albertel 5517: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5518: }
5519: }
5520: }
5521: }
1.6 raeburn 5522: }
5523: }
5524: }
5525: if (ref($domconfig) eq 'HASH') {
5526: if (ref($domconfig->{$role}) eq 'HASH') {
5527: foreach my $img (@images) {
5528: if ($domconfig->{$role}{$img} ne '') {
5529: if ($env{'form.'.$role.'_del_'.$img}) {
5530: $confhash->{$role}{$img} = '';
1.12 raeburn 5531: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5532: } else {
1.9 raeburn 5533: if ($confhash->{$role}{$img} eq '') {
5534: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
5535: }
1.6 raeburn 5536: }
5537: } else {
5538: if ($env{'form.'.$role.'_del_'.$img}) {
5539: $confhash->{$role}{$img} = '';
1.12 raeburn 5540: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5541: }
5542: }
1.70 raeburn 5543: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
5544: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
5545: if ($confhash->{$role}{'showlogo'}{$img} ne
5546: $domconfig->{$role}{'showlogo'}{$img}) {
5547: $changes{$role}{'showlogo'}{$img} = 1;
5548: }
5549: } else {
5550: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5551: $changes{$role}{'showlogo'}{$img} = 1;
5552: }
5553: }
5554: }
5555: }
1.6 raeburn 5556: if ($domconfig->{$role}{'font'} ne '') {
5557: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
5558: $changes{$role}{'font'} = 1;
5559: }
5560: } else {
5561: if ($confhash->{$role}{'font'}) {
5562: $changes{$role}{'font'} = 1;
5563: }
5564: }
1.107 raeburn 5565: if ($role ne 'login') {
5566: if ($domconfig->{$role}{'fontmenu'} ne '') {
5567: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
5568: $changes{$role}{'fontmenu'} = 1;
5569: }
5570: } else {
5571: if ($confhash->{$role}{'fontmenu'}) {
5572: $changes{$role}{'fontmenu'} = 1;
5573: }
1.97 tempelho 5574: }
5575: }
1.6 raeburn 5576: foreach my $item (@bgs) {
5577: if ($domconfig->{$role}{$item} ne '') {
5578: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5579: $changes{$role}{'bgs'}{$item} = 1;
5580: }
5581: } else {
5582: if ($confhash->{$role}{$item}) {
5583: $changes{$role}{'bgs'}{$item} = 1;
5584: }
5585: }
5586: }
5587: foreach my $item (@links) {
5588: if ($domconfig->{$role}{$item} ne '') {
5589: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5590: $changes{$role}{'links'}{$item} = 1;
5591: }
5592: } else {
5593: if ($confhash->{$role}{$item}) {
5594: $changes{$role}{'links'}{$item} = 1;
5595: }
5596: }
5597: }
1.41 raeburn 5598: foreach my $item (@logintext) {
5599: if ($domconfig->{$role}{$item} ne '') {
5600: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5601: $changes{$role}{'logintext'}{$item} = 1;
5602: }
5603: } else {
5604: if ($confhash->{$role}{$item}) {
5605: $changes{$role}{'logintext'}{$item} = 1;
5606: }
5607: }
5608: }
1.6 raeburn 5609: } else {
5610: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5611: \@logintext,$confhash,\%changes);
1.6 raeburn 5612: }
5613: } else {
5614: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5615: \@logintext,$confhash,\%changes);
1.6 raeburn 5616: }
5617: }
5618: return ($errors,%changes);
5619: }
5620:
1.46 raeburn 5621: sub config_check {
5622: my ($dom,$confname,$servadm) = @_;
5623: my ($configuserok,$author_ok,$switchserver,%currroles);
5624: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
5625: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
5626: $confname,$servadm);
5627: if ($configuserok eq 'ok') {
5628: $switchserver = &check_switchserver($dom,$confname);
5629: if ($switchserver eq '') {
5630: $author_ok = &check_authorstatus($dom,$confname,%currroles);
5631: }
5632: }
5633: return ($configuserok,$author_ok,$switchserver);
5634: }
5635:
1.6 raeburn 5636: sub default_change_checker {
1.41 raeburn 5637: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 5638: foreach my $item (@{$links}) {
5639: if ($confhash->{$role}{$item}) {
5640: $changes->{$role}{'links'}{$item} = 1;
5641: }
5642: }
5643: foreach my $item (@{$bgs}) {
5644: if ($confhash->{$role}{$item}) {
5645: $changes->{$role}{'bgs'}{$item} = 1;
5646: }
5647: }
1.41 raeburn 5648: foreach my $item (@{$logintext}) {
5649: if ($confhash->{$role}{$item}) {
5650: $changes->{$role}{'logintext'}{$item} = 1;
5651: }
5652: }
1.6 raeburn 5653: foreach my $img (@{$images}) {
5654: if ($env{'form.'.$role.'_del_'.$img}) {
5655: $confhash->{$role}{$img} = '';
1.12 raeburn 5656: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 5657: }
1.70 raeburn 5658: if ($role eq 'login') {
5659: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5660: $changes->{$role}{'showlogo'}{$img} = 1;
5661: }
5662: }
1.6 raeburn 5663: }
5664: if ($confhash->{$role}{'font'}) {
5665: $changes->{$role}{'font'} = 1;
5666: }
1.48 raeburn 5667: }
1.6 raeburn 5668:
5669: sub display_colorchgs {
5670: my ($dom,$changes,$roles,$confhash) = @_;
5671: my (%choices,$resulttext);
5672: if (!grep(/^login$/,@{$roles})) {
5673: $resulttext = &mt('Changes made:').'<br />';
5674: }
5675: foreach my $role (@{$roles}) {
5676: if ($role eq 'login') {
5677: %choices = &login_choices();
5678: } else {
5679: %choices = &color_font_choices();
5680: }
5681: if (ref($changes->{$role}) eq 'HASH') {
5682: if ($role ne 'login') {
5683: $resulttext .= '<h4>'.&mt($role).'</h4>';
5684: }
5685: foreach my $key (sort(keys(%{$changes->{$role}}))) {
5686: if ($role ne 'login') {
5687: $resulttext .= '<ul>';
5688: }
5689: if (ref($changes->{$role}{$key}) eq 'HASH') {
5690: if ($role ne 'login') {
5691: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
5692: }
5693: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 5694: if (($role eq 'login') && ($key eq 'showlogo')) {
5695: if ($confhash->{$role}{$key}{$item}) {
5696: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
5697: } else {
5698: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
5699: }
5700: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 5701: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
5702: } else {
1.12 raeburn 5703: my $newitem = $confhash->{$role}{$item};
5704: if ($key eq 'images') {
5705: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
5706: }
5707: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 5708: }
5709: }
5710: if ($role ne 'login') {
5711: $resulttext .= '</ul></li>';
5712: }
5713: } else {
5714: if ($confhash->{$role}{$key} eq '') {
5715: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
5716: } else {
5717: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
5718: }
5719: }
5720: if ($role ne 'login') {
5721: $resulttext .= '</ul>';
5722: }
5723: }
5724: }
5725: }
1.3 raeburn 5726: return $resulttext;
1.1 raeburn 5727: }
5728:
1.9 raeburn 5729: sub thumb_dimensions {
5730: return ('200','50');
5731: }
5732:
1.16 raeburn 5733: sub check_dimensions {
5734: my ($inputfile) = @_;
5735: my ($fullwidth,$fullheight);
5736: if ($inputfile =~ m|^[/\w.\-]+$|) {
5737: if (open(PIPE,"identify $inputfile 2>&1 |")) {
5738: my $imageinfo = <PIPE>;
5739: if (!close(PIPE)) {
5740: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
5741: }
5742: chomp($imageinfo);
5743: my ($fullsize) =
1.21 raeburn 5744: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 5745: if ($fullsize) {
5746: ($fullwidth,$fullheight) = split(/x/,$fullsize);
5747: }
5748: }
5749: }
5750: return ($fullwidth,$fullheight);
5751: }
5752:
1.9 raeburn 5753: sub check_configuser {
5754: my ($uhome,$dom,$confname,$servadm) = @_;
5755: my ($configuserok,%currroles);
5756: if ($uhome eq 'no_host') {
5757: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
5758: my $configpass = &LONCAPA::Enrollment::create_password();
5759: $configuserok =
5760: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
5761: $configpass,'','','','','',undef,$servadm);
5762: } else {
5763: $configuserok = 'ok';
5764: %currroles =
5765: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
5766: }
5767: return ($configuserok,%currroles);
5768: }
5769:
5770: sub check_authorstatus {
5771: my ($dom,$confname,%currroles) = @_;
5772: my $author_ok;
1.40 raeburn 5773: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 5774: my $start = time;
5775: my $end = 0;
5776: $author_ok =
5777: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 5778: 'au',$end,$start,'','','domconfig');
1.9 raeburn 5779: } else {
5780: $author_ok = 'ok';
5781: }
5782: return $author_ok;
5783: }
5784:
5785: sub publishlogo {
1.46 raeburn 5786: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 5787: my ($output,$fname,$logourl);
5788: if ($action eq 'upload') {
5789: $fname=$env{'form.'.$formname.'.filename'};
5790: chop($env{'form.'.$formname});
5791: } else {
5792: ($fname) = ($formname =~ /([^\/]+)$/);
5793: }
1.46 raeburn 5794: if ($savefileas ne '') {
5795: $fname = $savefileas;
5796: }
1.9 raeburn 5797: $fname=&Apache::lonnet::clean_filename($fname);
5798: # See if there is anything left
5799: unless ($fname) { return ('error: no uploaded file'); }
5800: $fname="$subdir/$fname";
1.210 raeburn 5801: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 5802: my $filepath="$docroot/priv";
5803: my $relpath = "$dom/$confname";
1.9 raeburn 5804: my ($fnamepath,$file,$fetchthumb);
5805: $file=$fname;
5806: if ($fname=~m|/|) {
5807: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
5808: }
1.164 raeburn 5809: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 5810: my $count;
1.164 raeburn 5811: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 5812: $filepath.="/$parts[$count]";
5813: if ((-e $filepath)!=1) {
5814: mkdir($filepath,02770);
5815: }
5816: }
5817: # Check for bad extension and disallow upload
5818: if ($file=~/\.(\w+)$/ &&
5819: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
5820: $output =
1.207 bisitz 5821: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 5822: } elsif ($file=~/\.(\w+)$/ &&
5823: !defined(&Apache::loncommon::fileembstyle($1))) {
5824: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
5825: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 5826: $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 5827: } elsif (-d "$filepath/$file") {
1.195 bisitz 5828: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 5829: } else {
5830: my $source = $filepath.'/'.$file;
5831: my $logfile;
5832: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 5833: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 5834: }
5835: print $logfile
5836: "\n================= Publish ".localtime()." ================\n".
5837: $env{'user.name'}.':'.$env{'user.domain'}."\n";
5838: # Save the file
5839: if (!open(FH,'>'.$source)) {
5840: &Apache::lonnet::logthis('Failed to create '.$source);
5841: return (&mt('Failed to create file'));
5842: }
5843: if ($action eq 'upload') {
5844: if (!print FH ($env{'form.'.$formname})) {
5845: &Apache::lonnet::logthis('Failed to write to '.$source);
5846: return (&mt('Failed to write file'));
5847: }
5848: } else {
5849: my $original = &Apache::lonnet::filelocation('',$formname);
5850: if(!copy($original,$source)) {
5851: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
5852: return (&mt('Failed to write file'));
5853: }
5854: }
5855: close(FH);
5856: chmod(0660, $source); # Permissions to rw-rw---.
5857:
5858: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
5859: my $copyfile=$targetdir.'/'.$file;
5860:
5861: my @parts=split(/\//,$targetdir);
5862: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
5863: for (my $count=5;$count<=$#parts;$count++) {
5864: $path.="/$parts[$count]";
5865: if (!-e $path) {
5866: print $logfile "\nCreating directory ".$path;
5867: mkdir($path,02770);
5868: }
5869: }
5870: my $versionresult;
5871: if (-e $copyfile) {
5872: $versionresult = &logo_versioning($targetdir,$file,$logfile);
5873: } else {
5874: $versionresult = 'ok';
5875: }
5876: if ($versionresult eq 'ok') {
5877: if (copy($source,$copyfile)) {
5878: print $logfile "\nCopied original source to ".$copyfile."\n";
5879: $output = 'ok';
5880: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 5881: push(@{$modified_urls},[$copyfile,$source]);
5882: my $metaoutput =
5883: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
5884: unless ($registered_cleanup) {
5885: my $handlers = $r->get_handlers('PerlCleanupHandler');
5886: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5887: $registered_cleanup=1;
5888: }
1.9 raeburn 5889: } else {
5890: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
5891: $output = &mt('Failed to copy file to RES space').", $!";
5892: }
5893: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5894: my $inputfile = $filepath.'/'.$file;
5895: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 5896: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5897: if ($fullwidth ne '' && $fullheight ne '') {
5898: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5899: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5900: system("convert -sample $thumbsize $inputfile $outfile");
5901: chmod(0660, $filepath.'/tn-'.$file);
5902: if (-e $outfile) {
5903: my $copyfile=$targetdir.'/tn-'.$file;
5904: if (copy($outfile,$copyfile)) {
5905: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 5906: my $thumb_metaoutput =
5907: &write_metadata($dom,$confname,$formname,
5908: $targetdir,'tn-'.$file,$logfile);
5909: push(@{$modified_urls},[$copyfile,$outfile]);
5910: unless ($registered_cleanup) {
5911: my $handlers = $r->get_handlers('PerlCleanupHandler');
5912: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5913: $registered_cleanup=1;
5914: }
1.16 raeburn 5915: } else {
5916: print $logfile "\nUnable to write ".$copyfile.
5917: ':'.$!."\n";
5918: }
5919: }
1.9 raeburn 5920: }
5921: }
5922: }
5923: } else {
5924: $output = $versionresult;
5925: }
5926: }
5927: return ($output,$logourl);
5928: }
5929:
5930: sub logo_versioning {
5931: my ($targetdir,$file,$logfile) = @_;
5932: my $target = $targetdir.'/'.$file;
5933: my ($maxversion,$fn,$extn,$output);
5934: $maxversion = 0;
5935: if ($file =~ /^(.+)\.(\w+)$/) {
5936: $fn=$1;
5937: $extn=$2;
5938: }
5939: opendir(DIR,$targetdir);
5940: while (my $filename=readdir(DIR)) {
5941: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
5942: $maxversion=($1>$maxversion)?$1:$maxversion;
5943: }
5944: }
5945: $maxversion++;
5946: print $logfile "\nCreating old version ".$maxversion."\n";
5947: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
5948: if (copy($target,$copyfile)) {
5949: print $logfile "Copied old target to ".$copyfile."\n";
5950: $copyfile=$copyfile.'.meta';
5951: if (copy($target.'.meta',$copyfile)) {
5952: print $logfile "Copied old target metadata to ".$copyfile."\n";
5953: $output = 'ok';
5954: } else {
5955: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
5956: $output = &mt('Failed to copy old meta').", $!, ";
5957: }
5958: } else {
5959: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
5960: $output = &mt('Failed to copy old target').", $!, ";
5961: }
5962: return $output;
5963: }
5964:
5965: sub write_metadata {
5966: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
5967: my (%metadatafields,%metadatakeys,$output);
5968: $metadatafields{'title'}=$formname;
5969: $metadatafields{'creationdate'}=time;
5970: $metadatafields{'lastrevisiondate'}=time;
5971: $metadatafields{'copyright'}='public';
5972: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
5973: $env{'user.domain'};
5974: $metadatafields{'authorspace'}=$confname.':'.$dom;
5975: $metadatafields{'domain'}=$dom;
5976: {
5977: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
5978: my $mfh;
1.155 raeburn 5979: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 5980: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 5981: unless ($_=~/\./) {
5982: my $unikey=$_;
5983: $unikey=~/^([A-Za-z]+)/;
5984: my $tag=$1;
5985: $tag=~tr/A-Z/a-z/;
5986: print $mfh "\n\<$tag";
5987: foreach (split(/\,/,$metadatakeys{$unikey})) {
5988: my $value=$metadatafields{$unikey.'.'.$_};
5989: $value=~s/\"/\'\'/g;
5990: print $mfh ' '.$_.'="'.$value.'"';
5991: }
5992: print $mfh '>'.
5993: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
5994: .'</'.$tag.'>';
5995: }
5996: }
5997: $output = 'ok';
5998: print $logfile "\nWrote metadata";
5999: close($mfh);
6000: } else {
6001: print $logfile "\nFailed to open metadata file";
1.9 raeburn 6002: $output = &mt('Could not write metadata');
6003: }
6004: }
1.155 raeburn 6005: return $output;
6006: }
6007:
6008: sub notifysubscribed {
6009: foreach my $targetsource (@{$modified_urls}){
6010: next unless (ref($targetsource) eq 'ARRAY');
6011: my ($target,$source)=@{$targetsource};
6012: if ($source ne '') {
6013: if (open(my $logfh,'>>'.$source.'.log')) {
6014: print $logfh "\nCleanup phase: Notifications\n";
6015: my @subscribed=&subscribed_hosts($target);
6016: foreach my $subhost (@subscribed) {
6017: print $logfh "\nNotifying host ".$subhost.':';
6018: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
6019: print $logfh $reply;
6020: }
6021: my @subscribedmeta=&subscribed_hosts("$target.meta");
6022: foreach my $subhost (@subscribedmeta) {
6023: print $logfh "\nNotifying host for metadata only ".$subhost.':';
6024: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
6025: $subhost);
6026: print $logfh $reply;
6027: }
6028: print $logfh "\n============ Done ============\n";
1.160 raeburn 6029: close($logfh);
1.155 raeburn 6030: }
6031: }
6032: }
6033: return OK;
6034: }
6035:
6036: sub subscribed_hosts {
6037: my ($target) = @_;
6038: my @subscribed;
6039: if (open(my $fh,"<$target.subscription")) {
6040: while (my $subline=<$fh>) {
6041: if ($subline =~ /^($match_lonid):/) {
6042: my $host = $1;
6043: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
6044: unless (grep(/^\Q$host\E$/,@subscribed)) {
6045: push(@subscribed,$host);
6046: }
6047: }
6048: }
6049: }
6050: }
6051: return @subscribed;
1.9 raeburn 6052: }
6053:
6054: sub check_switchserver {
6055: my ($dom,$confname) = @_;
6056: my ($allowed,$switchserver);
6057: my $home = &Apache::lonnet::homeserver($confname,$dom);
6058: if ($home eq 'no_host') {
6059: $home = &Apache::lonnet::domain($dom,'primary');
6060: }
6061: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 6062: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
6063: if (!$allowed) {
1.180 raeburn 6064: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 6065: }
6066: return $switchserver;
6067: }
6068:
1.1 raeburn 6069: sub modify_quotas {
1.216 raeburn 6070: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 6071: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 6072: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
6073: $author_ok,$switchserver,$errors);
1.86 raeburn 6074: if ($action eq 'quotas') {
6075: $context = 'tools';
1.163 raeburn 6076: } else {
1.86 raeburn 6077: $context = $action;
6078: }
6079: if ($context eq 'requestcourses') {
1.216 raeburn 6080: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 6081: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 6082: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
6083: %titles = &courserequest_titles();
6084: $toolregexp = join('|',@usertools);
6085: %conditions = &courserequest_conditions();
1.216 raeburn 6086: $confname = $dom.'-domainconfig';
6087: my $servadm = $r->dir_config('lonAdmEMail');
6088: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.163 raeburn 6089: } elsif ($context eq 'requestauthor') {
6090: @usertools = ('author');
6091: %titles = &authorrequest_titles();
1.86 raeburn 6092: } else {
1.162 raeburn 6093: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 6094: %titles = &tool_titles();
1.86 raeburn 6095: }
1.212 raeburn 6096: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 6097: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6098: foreach my $key (keys(%env)) {
1.101 raeburn 6099: if ($context eq 'requestcourses') {
6100: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
6101: my $item = $1;
6102: my $type = $2;
6103: if ($type =~ /^limit_(.+)/) {
6104: $limithash{$item}{$1} = $env{$key};
6105: } else {
6106: $confhash{$item}{$type} = $env{$key};
6107: }
6108: }
1.163 raeburn 6109: } elsif ($context eq 'requestauthor') {
6110: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
6111: $confhash{$1} = $env{$key};
6112: }
1.101 raeburn 6113: } else {
1.86 raeburn 6114: if ($key =~ /^form\.quota_(.+)$/) {
6115: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 6116: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
6117: $confhash{'authorquota'}{$1} = $env{$key};
6118: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 6119: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
6120: }
1.72 raeburn 6121: }
6122: }
1.163 raeburn 6123: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.102 raeburn 6124: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
6125: @approvalnotify = sort(@approvalnotify);
6126: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.218 raeburn 6127: my @crstypes = ('official','unofficial','community','textbook');
6128: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
6129: foreach my $type (@hasuniquecode) {
6130: if (grep(/^\Q$type\E$/,@crstypes)) {
6131: $confhash{'uniquecode'}{$type} = 1;
6132: }
1.216 raeburn 6133: }
6134: my ($newbook,@allpos);
6135: if ($context eq 'requestcourses') {
6136: if ($env{'form.addbook'}) {
6137: if (($env{'form.addbook_cnum'} =~ /^$match_courseid$/) &&
6138: ($env{'form.addbook_cdom'} =~ /^$match_domain$/)) {
6139: if (&Apache::lonnet::homeserver($env{'form.addbook_cnum'},
6140: $env{'form.addbook_cdom'}) eq 'no_host') {
6141: $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
6142: '</span></li>';
6143: } else {
6144: $newbook = $env{'form.addbook_cdom'}.'_'.$env{'form.addbook_cnum'};
6145: my $position = $env{'form.addbook_pos'};
6146: $position =~ s/\D+//g;
6147: if ($position ne '') {
6148: $allpos[$position] = $newbook;
6149: }
6150: }
6151: } else {
6152: $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
6153: '</span></li>';
6154: }
6155: }
6156: }
1.102 raeburn 6157: if (ref($domconfig{$action}) eq 'HASH') {
6158: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
6159: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
6160: $changes{'notify'}{'approval'} = 1;
6161: }
6162: } else {
1.144 raeburn 6163: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6164: $changes{'notify'}{'approval'} = 1;
6165: }
6166: }
1.218 raeburn 6167: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
6168: if (ref($confhash{'uniquecode'}) eq 'HASH') {
6169: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
6170: unless ($confhash{'uniquecode'}{$crstype}) {
6171: $changes{'uniquecode'} = 1;
6172: }
6173: }
6174: unless ($changes{'uniquecode'}) {
6175: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
6176: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
6177: $changes{'uniquecode'} = 1;
6178: }
6179: }
6180: }
6181: } else {
6182: $changes{'uniquecode'} = 1;
6183: }
6184: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
6185: $changes{'uniquecode'} = 1;
1.216 raeburn 6186: }
6187: if ($context eq 'requestcourses') {
6188: if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
6189: my %deletions;
6190: my @todelete = &Apache::loncommon::get_env_multiple('form.book_del');
6191: if (@todelete) {
6192: map { $deletions{$_} = 1; } @todelete;
6193: }
6194: my %imgdeletions;
6195: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.book_image_del');
6196: if (@todeleteimages) {
6197: map { $imgdeletions{$_} = 1; } @todeleteimages;
6198: }
6199: my $maxnum = $env{'form.book_maxnum'};
6200: for (my $i=0; $i<=$maxnum; $i++) {
6201: my $key = $env{'form.book_id_'.$i};
6202: if (ref($domconfig{$action}{'textbooks'}{$key}) eq 'HASH') {
6203: if ($deletions{$key}) {
6204: if ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
6205: #FIXME need to obsolete item in RES space
6206: }
6207: next;
6208: } else {
6209: my $newpos = $env{'form.'.$key};
6210: $newpos =~ s/\D+//g;
6211: foreach my $item ('subject','title','author') {
6212: $confhash{'textbooks'}{$key}{$item} = $env{'form.book_'.$item.'_'.$i};
6213: if ($domconfig{$action}{'textbooks'}{$key}{$item} ne $confhash{'textbooks'}{$key}{$item}) {
6214: $changes{'textbooks'}{$key} = 1;
6215: }
6216: }
6217: $allpos[$newpos] = $key;
6218: }
6219: if ($imgdeletions{$key}) {
6220: $changes{'textbooks'}{$key} = 1;
6221: #FIXME need to obsolete item in RES space
6222: } elsif ($env{'form.book_image_'.$i.'.filename'}) {
6223: my ($cdom,$cnum) = split(/_/,$key);
6224: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,'book_image_'.$i,
6225: $cdom,$cnum,$configuserok,
6226: $switchserver,$author_ok);
6227: if ($imgurl) {
6228: $confhash{'textbooks'}{$key}{'image'} = $imgurl;
6229: $changes{'textbooks'}{$key} = 1;
6230: }
6231: if ($error) {
6232: &Apache::lonnet::logthis($error);
6233: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6234: }
6235: } elsif ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
6236: $confhash{'textbooks'}{$key}{'image'} =
6237: $domconfig{$action}{'textbooks'}{$key}{'image'};
6238: }
6239: }
6240: }
6241: }
6242: }
1.102 raeburn 6243: } else {
1.144 raeburn 6244: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6245: $changes{'notify'}{'approval'} = 1;
6246: }
1.218 raeburn 6247: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 6248: $changes{'uniquecode'} = 1;
6249: }
6250: }
6251: if ($context eq 'requestcourses') {
6252: if ($newbook) {
6253: $changes{'textbooks'}{$newbook} = 1;
6254: foreach my $item ('subject','title','author') {
6255: $env{'form.addbook_'.$item} =~ s/(`)/'/g;
6256: if ($env{'form.addbook_'.$item}) {
6257: $confhash{'textbooks'}{$newbook}{$item} = $env{'form.addbook_'.$item};
6258: }
6259: }
6260: if ($env{'form.addbook_image.filename'} ne '') {
6261: my ($cdom,$cnum) = split(/_/,$newbook);
6262: my ($imageurl,$error) =
6263: &process_textbook_image($r,$dom,$confname,'addbook_image',$cdom,$cnum,$configuserok,
6264: $switchserver,$author_ok);
6265: if ($imageurl) {
6266: $confhash{'textbooks'}{$newbook}{'image'} = $imageurl;
6267: }
6268: if ($error) {
6269: &Apache::lonnet::logthis($error);
6270: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6271: }
6272: }
6273: }
6274: if (@allpos > 0) {
6275: my $idx = 0;
6276: foreach my $item (@allpos) {
6277: if ($item ne '') {
6278: $confhash{'textbooks'}{$item}{'order'} = $idx;
6279: if (ref($domconfig{$action}) eq 'HASH') {
6280: if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
6281: if (ref($domconfig{$action}{'textbooks'}{$item}) eq 'HASH') {
6282: if ($domconfig{$action}{'textbooks'}{$item}{'order'} ne $idx) {
6283: $changes{'textbooks'}{$item} = 1;
6284: }
6285: }
6286: }
6287: }
6288: $idx ++;
6289: }
6290: }
6291: }
1.102 raeburn 6292: }
6293: } else {
1.86 raeburn 6294: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 6295: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 6296: }
1.72 raeburn 6297: foreach my $item (@usertools) {
6298: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 6299: my $unset;
1.101 raeburn 6300: if ($context eq 'requestcourses') {
1.104 raeburn 6301: $unset = '0';
6302: if ($type eq '_LC_adv') {
6303: $unset = '';
6304: }
1.101 raeburn 6305: if ($confhash{$item}{$type} eq 'autolimit') {
6306: $confhash{$item}{$type} .= '=';
6307: unless ($limithash{$item}{$type} =~ /\D/) {
6308: $confhash{$item}{$type} .= $limithash{$item}{$type};
6309: }
6310: }
1.163 raeburn 6311: } elsif ($context eq 'requestauthor') {
6312: $unset = '0';
6313: if ($type eq '_LC_adv') {
6314: $unset = '';
6315: }
1.72 raeburn 6316: } else {
1.101 raeburn 6317: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
6318: $confhash{$item}{$type} = 1;
6319: } else {
6320: $confhash{$item}{$type} = 0;
6321: }
1.72 raeburn 6322: }
1.86 raeburn 6323: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 6324: if ($action eq 'requestauthor') {
6325: if ($domconfig{$action}{$type} ne $confhash{$type}) {
6326: $changes{$type} = 1;
6327: }
6328: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 6329: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
6330: $changes{$item}{$type} = 1;
6331: }
6332: } else {
6333: if ($context eq 'requestcourses') {
1.104 raeburn 6334: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 6335: $changes{$item}{$type} = 1;
6336: }
6337: } else {
6338: if (!$confhash{$item}{$type}) {
6339: $changes{$item}{$type} = 1;
6340: }
6341: }
6342: }
6343: } else {
6344: if ($context eq 'requestcourses') {
1.104 raeburn 6345: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 6346: $changes{$item}{$type} = 1;
6347: }
1.163 raeburn 6348: } elsif ($context eq 'requestauthor') {
6349: if ($confhash{$type} ne $unset) {
6350: $changes{$type} = 1;
6351: }
1.72 raeburn 6352: } else {
6353: if (!$confhash{$item}{$type}) {
6354: $changes{$item}{$type} = 1;
6355: }
6356: }
6357: }
1.1 raeburn 6358: }
6359: }
1.163 raeburn 6360: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 6361: if (ref($domconfig{'quotas'}) eq 'HASH') {
6362: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
6363: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
6364: if (exists($confhash{'defaultquota'}{$key})) {
6365: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
6366: $changes{'defaultquota'}{$key} = 1;
6367: }
6368: } else {
6369: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 6370: }
6371: }
1.86 raeburn 6372: } else {
6373: foreach my $key (keys(%{$domconfig{'quotas'}})) {
6374: if (exists($confhash{'defaultquota'}{$key})) {
6375: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
6376: $changes{'defaultquota'}{$key} = 1;
6377: }
6378: } else {
6379: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 6380: }
1.1 raeburn 6381: }
6382: }
1.197 raeburn 6383: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
6384: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
6385: if (exists($confhash{'authorquota'}{$key})) {
6386: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
6387: $changes{'authorquota'}{$key} = 1;
6388: }
6389: } else {
6390: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
6391: }
6392: }
6393: }
1.1 raeburn 6394: }
1.86 raeburn 6395: if (ref($confhash{'defaultquota'}) eq 'HASH') {
6396: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
6397: if (ref($domconfig{'quotas'}) eq 'HASH') {
6398: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
6399: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
6400: $changes{'defaultquota'}{$key} = 1;
6401: }
6402: } else {
6403: if (!exists($domconfig{'quotas'}{$key})) {
6404: $changes{'defaultquota'}{$key} = 1;
6405: }
1.72 raeburn 6406: }
6407: } else {
1.86 raeburn 6408: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 6409: }
1.1 raeburn 6410: }
6411: }
1.197 raeburn 6412: if (ref($confhash{'authorquota'}) eq 'HASH') {
6413: foreach my $key (keys(%{$confhash{'authorquota'}})) {
6414: if (ref($domconfig{'quotas'}) eq 'HASH') {
6415: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
6416: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
6417: $changes{'authorquota'}{$key} = 1;
6418: }
6419: } else {
6420: $changes{'authorquota'}{$key} = 1;
6421: }
6422: } else {
6423: $changes{'authorquota'}{$key} = 1;
6424: }
6425: }
6426: }
1.1 raeburn 6427: }
1.72 raeburn 6428:
1.163 raeburn 6429: if ($context eq 'requestauthor') {
6430: $domdefaults{'requestauthor'} = \%confhash;
6431: } else {
6432: foreach my $key (keys(%confhash)) {
1.216 raeburn 6433: unless (($context eq 'requestcourses') && ($key eq 'textbooks')) {
6434: $domdefaults{$key} = $confhash{$key};
6435: }
1.163 raeburn 6436: }
1.72 raeburn 6437: }
1.163 raeburn 6438:
1.1 raeburn 6439: my %quotahash = (
1.86 raeburn 6440: $action => { %confhash }
1.1 raeburn 6441: );
6442: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
6443: $dom);
6444: if ($putresult eq 'ok') {
6445: if (keys(%changes) > 0) {
1.72 raeburn 6446: my $cachetime = 24*60*60;
6447: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 6448: if (ref($lastactref) eq 'HASH') {
6449: $lastactref->{'domdefaults'} = 1;
6450: }
1.1 raeburn 6451: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 6452: unless (($context eq 'requestcourses') ||
1.163 raeburn 6453: ($context eq 'requestauthor')) {
1.86 raeburn 6454: if (ref($changes{'defaultquota'}) eq 'HASH') {
6455: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
6456: foreach my $type (@{$types},'default') {
6457: if (defined($changes{'defaultquota'}{$type})) {
6458: my $typetitle = $usertypes->{$type};
6459: if ($type eq 'default') {
6460: $typetitle = $othertitle;
6461: }
1.213 raeburn 6462: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 6463: }
6464: }
1.86 raeburn 6465: $resulttext .= '</ul></li>';
1.72 raeburn 6466: }
1.197 raeburn 6467: if (ref($changes{'authorquota'}) eq 'HASH') {
6468: $resulttext .= '<li>'.&mt('Authoring space default quotas').'<ul>';
6469: foreach my $type (@{$types},'default') {
6470: if (defined($changes{'authorquota'}{$type})) {
6471: my $typetitle = $usertypes->{$type};
6472: if ($type eq 'default') {
6473: $typetitle = $othertitle;
6474: }
1.213 raeburn 6475: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 6476: }
6477: }
6478: $resulttext .= '</ul></li>';
6479: }
1.72 raeburn 6480: }
1.80 raeburn 6481: my %newenv;
1.72 raeburn 6482: foreach my $item (@usertools) {
1.163 raeburn 6483: my (%haschgs,%inconf);
6484: if ($context eq 'requestauthor') {
6485: %haschgs = %changes;
1.210 raeburn 6486: %inconf = %confhash;
1.163 raeburn 6487: } else {
6488: if (ref($changes{$item}) eq 'HASH') {
6489: %haschgs = %{$changes{$item}};
6490: }
6491: if (ref($confhash{$item}) eq 'HASH') {
6492: %inconf = %{$confhash{$item}};
6493: }
6494: }
6495: if (keys(%haschgs) > 0) {
1.80 raeburn 6496: my $newacc =
6497: &Apache::lonnet::usertools_access($env{'user.name'},
6498: $env{'user.domain'},
1.86 raeburn 6499: $item,'reload',$context);
1.210 raeburn 6500: if (($context eq 'requestcourses') ||
1.163 raeburn 6501: ($context eq 'requestauthor')) {
1.108 raeburn 6502: if ($env{'environment.canrequest.'.$item} ne $newacc) {
6503: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 6504: }
6505: } else {
6506: if ($env{'environment.availabletools.'.$item} ne $newacc) {
6507: $newenv{'environment.availabletools.'.$item} = $newacc;
6508: }
1.80 raeburn 6509: }
1.163 raeburn 6510: unless ($context eq 'requestauthor') {
6511: $resulttext .= '<li>'.$titles{$item}.'<ul>';
6512: }
1.72 raeburn 6513: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 6514: if ($haschgs{$type}) {
1.72 raeburn 6515: my $typetitle = $usertypes->{$type};
6516: if ($type eq 'default') {
6517: $typetitle = $othertitle;
6518: } elsif ($type eq '_LC_adv') {
6519: $typetitle = 'LON-CAPA Advanced Users';
6520: }
1.163 raeburn 6521: if ($inconf{$type}) {
1.101 raeburn 6522: if ($context eq 'requestcourses') {
6523: my $cond;
1.163 raeburn 6524: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 6525: if ($1 eq '') {
6526: $cond = &mt('(Automatic processing of any request).');
6527: } else {
6528: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
6529: }
6530: } else {
1.163 raeburn 6531: $cond = $conditions{$inconf{$type}};
1.101 raeburn 6532: }
6533: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 6534: } elsif ($context eq 'requestauthor') {
6535: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
6536: $titles{$inconf{$type}},$typetitle);
6537:
1.101 raeburn 6538: } else {
6539: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
6540: }
1.72 raeburn 6541: } else {
1.104 raeburn 6542: if ($type eq '_LC_adv') {
1.163 raeburn 6543: if ($inconf{$type} eq '0') {
1.104 raeburn 6544: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6545: } else {
6546: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
6547: }
6548: } else {
6549: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6550: }
1.72 raeburn 6551: }
6552: }
1.26 raeburn 6553: }
1.163 raeburn 6554: unless ($context eq 'requestauthor') {
6555: $resulttext .= '</ul></li>';
6556: }
1.26 raeburn 6557: }
1.1 raeburn 6558: }
1.163 raeburn 6559: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 6560: if (ref($changes{'notify'}) eq 'HASH') {
6561: if ($changes{'notify'}{'approval'}) {
6562: if (ref($confhash{'notify'}) eq 'HASH') {
6563: if ($confhash{'notify'}{'approval'}) {
6564: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
6565: } else {
1.163 raeburn 6566: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 6567: }
6568: }
6569: }
6570: }
6571: }
1.216 raeburn 6572: if ($action eq 'requestcourses') {
6573: my @offon = ('off','on');
6574: if ($changes{'uniquecode'}) {
1.218 raeburn 6575: if (ref($confhash{'uniquecode'}) eq 'HASH') {
6576: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
6577: $resulttext .= '<li>'.
6578: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
6579: '</li>';
6580: } else {
6581: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
6582: '</li>';
6583: }
1.216 raeburn 6584: }
6585: if (ref($changes{'textbooks'}) eq 'HASH') {
6586: $resulttext .= '<li>'.&mt('Available textbooks updated').'<ul>';
6587: foreach my $key (sort(keys(%{$changes{'textbooks'}}))) {
6588: my %coursehash = &Apache::lonnet::coursedescription($key);
6589: my $coursetitle = $coursehash{'description'};
6590: my $position = $confhash{'textbooks'}{$key}{'order'} + 1;
6591: $resulttext .= '<li>';
6592: foreach my $item ('subject','title','author') {
6593: my $name = $item.':';
6594: $name =~ s/^(\w)/\U$1/;
6595: $resulttext .= &mt($name).' '.$confhash{'textbooks'}{$key}{$item}.'<br />';
6596: }
6597: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
6598: if ($confhash{'textbooks'}{$key}{'image'}) {
6599: $resulttext .= ' '.&mt('Image: [_1]',
6600: '<img src="'.$confhash{'textbooks'}{$key}{'image'}.'"'.
6601: ' alt="Textbook cover" />').'<br />';
6602: }
6603: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
6604: }
6605: $resulttext .= '</ul></li>';
6606: }
6607: }
1.1 raeburn 6608: $resulttext .= '</ul>';
1.80 raeburn 6609: if (keys(%newenv)) {
6610: &Apache::lonnet::appenv(\%newenv);
6611: }
1.1 raeburn 6612: } else {
1.86 raeburn 6613: if ($context eq 'requestcourses') {
6614: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 6615: } elsif ($context eq 'requestauthor') {
6616: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 6617: } else {
1.90 weissno 6618: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 6619: }
1.1 raeburn 6620: }
6621: } else {
1.11 albertel 6622: $resulttext = '<span class="LC_error">'.
6623: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6624: }
1.216 raeburn 6625: if ($errors) {
6626: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
6627: '<ul>'.$errors.'</ul></p>';
6628: }
1.3 raeburn 6629: return $resulttext;
1.1 raeburn 6630: }
6631:
1.216 raeburn 6632: sub process_textbook_image {
6633: my ($r,$dom,$confname,$caller,$cdom,$cnum,$configuserok,$switchserver,$author_ok) = @_;
6634: my $filename = $env{'form.'.$caller.'.filename'};
6635: my ($error,$url);
6636: my ($width,$height) = (50,50);
6637: if ($configuserok eq 'ok') {
6638: if ($switchserver) {
6639: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
6640: $switchserver);
6641: } elsif ($author_ok eq 'ok') {
6642: my ($result,$imageurl) =
6643: &publishlogo($r,'upload',$caller,$dom,$confname,
6644: "textbooks/$dom/$cnum/cover",$width,$height);
6645: if ($result eq 'ok') {
6646: $url = $imageurl;
6647: } else {
6648: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
6649: }
6650: } else {
6651: $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);
6652: }
6653: } else {
6654: $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);
6655: }
6656: return ($url,$error);
6657: }
6658:
1.3 raeburn 6659: sub modify_autoenroll {
1.205 raeburn 6660: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 6661: my ($resulttext,%changes);
6662: my %currautoenroll;
6663: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6664: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
6665: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
6666: }
6667: }
6668: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
6669: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 6670: sender => 'Sender for notification messages',
6671: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 6672: my @offon = ('off','on');
1.17 raeburn 6673: my $sender_uname = $env{'form.sender_uname'};
6674: my $sender_domain = $env{'form.sender_domain'};
6675: if ($sender_domain eq '') {
6676: $sender_uname = '';
6677: } elsif ($sender_uname eq '') {
6678: $sender_domain = '';
6679: }
1.129 raeburn 6680: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 6681: my %autoenrollhash = (
1.129 raeburn 6682: autoenroll => { 'run' => $env{'form.autoenroll_run'},
6683: 'sender_uname' => $sender_uname,
6684: 'sender_domain' => $sender_domain,
6685: 'co-owners' => $coowners,
1.1 raeburn 6686: }
6687: );
1.4 raeburn 6688: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
6689: $dom);
1.1 raeburn 6690: if ($putresult eq 'ok') {
6691: if (exists($currautoenroll{'run'})) {
6692: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
6693: $changes{'run'} = 1;
6694: }
6695: } elsif ($autorun) {
6696: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 6697: $changes{'run'} = 1;
1.1 raeburn 6698: }
6699: }
1.17 raeburn 6700: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 6701: $changes{'sender'} = 1;
6702: }
1.17 raeburn 6703: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 6704: $changes{'sender'} = 1;
6705: }
1.129 raeburn 6706: if ($currautoenroll{'co-owners'} ne '') {
6707: if ($currautoenroll{'co-owners'} ne $coowners) {
6708: $changes{'coowners'} = 1;
6709: }
6710: } elsif ($coowners) {
6711: $changes{'coowners'} = 1;
6712: }
1.1 raeburn 6713: if (keys(%changes) > 0) {
6714: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 6715: if ($changes{'run'}) {
1.1 raeburn 6716: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
6717: }
6718: if ($changes{'sender'}) {
1.17 raeburn 6719: if ($sender_uname eq '' || $sender_domain eq '') {
6720: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
6721: } else {
6722: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
6723: }
1.1 raeburn 6724: }
1.129 raeburn 6725: if ($changes{'coowners'}) {
6726: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
6727: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 6728: if (ref($lastactref) eq 'HASH') {
6729: $lastactref->{'domainconfig'} = 1;
6730: }
1.129 raeburn 6731: }
1.1 raeburn 6732: $resulttext .= '</ul>';
6733: } else {
6734: $resulttext = &mt('No changes made to auto-enrollment settings');
6735: }
6736: } else {
1.11 albertel 6737: $resulttext = '<span class="LC_error">'.
6738: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6739: }
1.3 raeburn 6740: return $resulttext;
1.1 raeburn 6741: }
6742:
6743: sub modify_autoupdate {
1.3 raeburn 6744: my ($dom,%domconfig) = @_;
1.1 raeburn 6745: my ($resulttext,%currautoupdate,%fields,%changes);
6746: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
6747: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
6748: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
6749: }
6750: }
6751: my @offon = ('off','on');
6752: my %title = &Apache::lonlocal::texthash (
6753: run => 'Auto-update:',
6754: classlists => 'Updates to user information in classlists?'
6755: );
1.44 raeburn 6756: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6757: my %fieldtitles = &Apache::lonlocal::texthash (
6758: id => 'Student/Employee ID',
1.20 raeburn 6759: permanentemail => 'E-mail address',
1.1 raeburn 6760: lastname => 'Last Name',
6761: firstname => 'First Name',
6762: middlename => 'Middle Name',
1.132 raeburn 6763: generation => 'Generation',
1.1 raeburn 6764: );
1.142 raeburn 6765: $othertitle = &mt('All users');
1.1 raeburn 6766: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 6767: $othertitle = &mt('Other users');
1.1 raeburn 6768: }
6769: foreach my $key (keys(%env)) {
6770: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 6771: my ($usertype,$item) = ($1,$2);
6772: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
6773: if ($usertype eq 'default') {
6774: push(@{$fields{$1}},$2);
6775: } elsif (ref($types) eq 'ARRAY') {
6776: if (grep(/^\Q$usertype\E$/,@{$types})) {
6777: push(@{$fields{$1}},$2);
6778: }
6779: }
6780: }
1.1 raeburn 6781: }
6782: }
1.131 raeburn 6783: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
6784: @lockablenames = sort(@lockablenames);
6785: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
6786: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6787: if (@changed) {
6788: $changes{'lockablenames'} = 1;
6789: }
6790: } else {
6791: if (@lockablenames) {
6792: $changes{'lockablenames'} = 1;
6793: }
6794: }
1.1 raeburn 6795: my %updatehash = (
6796: autoupdate => { run => $env{'form.autoupdate_run'},
6797: classlists => $env{'form.classlists'},
6798: fields => {%fields},
1.131 raeburn 6799: lockablenames => \@lockablenames,
1.1 raeburn 6800: }
6801: );
6802: foreach my $key (keys(%currautoupdate)) {
6803: if (($key eq 'run') || ($key eq 'classlists')) {
6804: if (exists($updatehash{autoupdate}{$key})) {
6805: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
6806: $changes{$key} = 1;
6807: }
6808: }
6809: } elsif ($key eq 'fields') {
6810: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 6811: foreach my $item (@{$types},'default') {
1.1 raeburn 6812: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
6813: my $change = 0;
6814: foreach my $type (@{$currautoupdate{$key}{$item}}) {
6815: if (!exists($fields{$item})) {
6816: $change = 1;
1.132 raeburn 6817: last;
1.1 raeburn 6818: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 6819: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 6820: $change = 1;
1.132 raeburn 6821: last;
1.1 raeburn 6822: }
6823: }
6824: }
6825: if ($change) {
6826: push(@{$changes{$key}},$item);
6827: }
1.26 raeburn 6828: }
1.1 raeburn 6829: }
6830: }
1.131 raeburn 6831: } elsif ($key eq 'lockablenames') {
6832: if (ref($currautoupdate{$key}) eq 'ARRAY') {
6833: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6834: if (@changed) {
6835: $changes{'lockablenames'} = 1;
6836: }
6837: } else {
6838: if (@lockablenames) {
6839: $changes{'lockablenames'} = 1;
6840: }
6841: }
6842: }
6843: }
6844: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
6845: if (@lockablenames) {
6846: $changes{'lockablenames'} = 1;
1.1 raeburn 6847: }
6848: }
1.26 raeburn 6849: foreach my $item (@{$types},'default') {
6850: if (defined($fields{$item})) {
6851: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 6852: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
6853: my $change = 0;
6854: if (ref($fields{$item}) eq 'ARRAY') {
6855: foreach my $type (@{$fields{$item}}) {
6856: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
6857: $change = 1;
6858: last;
6859: }
6860: }
6861: }
6862: if ($change) {
6863: push(@{$changes{'fields'}},$item);
6864: }
6865: } else {
1.26 raeburn 6866: push(@{$changes{'fields'}},$item);
6867: }
6868: } else {
6869: push(@{$changes{'fields'}},$item);
1.1 raeburn 6870: }
6871: }
6872: }
6873: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
6874: $dom);
6875: if ($putresult eq 'ok') {
6876: if (keys(%changes) > 0) {
6877: $resulttext = &mt('Changes made:').'<ul>';
6878: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 6879: if ($key eq 'lockablenames') {
6880: $resulttext .= '<li>';
6881: if (@lockablenames) {
6882: $usertypes->{'default'} = $othertitle;
6883: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
6884: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
6885: } else {
6886: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
6887: }
6888: $resulttext .= '</li>';
6889: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 6890: foreach my $item (@{$changes{$key}}) {
6891: my @newvalues;
6892: foreach my $type (@{$fields{$item}}) {
6893: push(@newvalues,$fieldtitles{$type});
6894: }
1.3 raeburn 6895: my $newvaluestr;
6896: if (@newvalues > 0) {
6897: $newvaluestr = join(', ',@newvalues);
6898: } else {
6899: $newvaluestr = &mt('none');
1.6 raeburn 6900: }
1.1 raeburn 6901: if ($item eq 'default') {
1.26 raeburn 6902: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 6903: } else {
1.26 raeburn 6904: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 6905: }
6906: }
6907: } else {
6908: my $newvalue;
6909: if ($key eq 'run') {
6910: $newvalue = $offon[$env{'form.autoupdate_run'}];
6911: } else {
6912: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 6913: }
1.1 raeburn 6914: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
6915: }
6916: }
6917: $resulttext .= '</ul>';
6918: } else {
1.3 raeburn 6919: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 6920: }
6921: } else {
1.11 albertel 6922: $resulttext = '<span class="LC_error">'.
6923: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6924: }
1.3 raeburn 6925: return $resulttext;
1.1 raeburn 6926: }
6927:
1.125 raeburn 6928: sub modify_autocreate {
6929: my ($dom,%domconfig) = @_;
6930: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
6931: if (ref($domconfig{'autocreate'}) eq 'HASH') {
6932: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
6933: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
6934: }
6935: }
6936: my %title= ( xml => 'Auto-creation of courses in XML course description files',
6937: req => 'Auto-creation of validated requests for official courses',
6938: xmldc => 'Identity of course creator of courses from XML files',
6939: );
6940: my @types = ('xml','req');
6941: foreach my $item (@types) {
6942: $newvals{$item} = $env{'form.autocreate_'.$item};
6943: $newvals{$item} =~ s/\D//g;
6944: $newvals{$item} = 0 if ($newvals{$item} eq '');
6945: }
6946: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
6947: my %domcoords = &get_active_dcs($dom);
6948: unless (exists($domcoords{$newvals{'xmldc'}})) {
6949: $newvals{'xmldc'} = '';
6950: }
6951: %autocreatehash = (
6952: autocreate => { xml => $newvals{'xml'},
6953: req => $newvals{'req'},
6954: }
6955: );
6956: if ($newvals{'xmldc'} ne '') {
6957: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
6958: }
6959: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
6960: $dom);
6961: if ($putresult eq 'ok') {
6962: my @items = @types;
6963: if ($newvals{'xml'}) {
6964: push(@items,'xmldc');
6965: }
6966: foreach my $item (@items) {
6967: if (exists($currautocreate{$item})) {
6968: if ($currautocreate{$item} ne $newvals{$item}) {
6969: $changes{$item} = 1;
6970: }
6971: } elsif ($newvals{$item}) {
6972: $changes{$item} = 1;
6973: }
6974: }
6975: if (keys(%changes) > 0) {
6976: my @offon = ('off','on');
6977: $resulttext = &mt('Changes made:').'<ul>';
6978: foreach my $item (@types) {
6979: if ($changes{$item}) {
6980: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 6981: $resulttext .= '<li>'.
6982: &mt("$title{$item} set to [_1]$newtxt [_2]",
6983: '<b>','</b>').
6984: '</li>';
1.125 raeburn 6985: }
6986: }
6987: if ($changes{'xmldc'}) {
6988: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
6989: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 6990: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 6991: }
6992: $resulttext .= '</ul>';
6993: } else {
6994: $resulttext = &mt('No changes made to auto-creation settings');
6995: }
6996: } else {
6997: $resulttext = '<span class="LC_error">'.
6998: &mt('An error occurred: [_1]',$putresult).'</span>';
6999: }
7000: return $resulttext;
7001: }
7002:
1.23 raeburn 7003: sub modify_directorysrch {
7004: my ($dom,%domconfig) = @_;
7005: my ($resulttext,%changes);
7006: my %currdirsrch;
7007: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
7008: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
7009: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
7010: }
7011: }
7012: my %title = ( available => 'Directory search available',
1.24 raeburn 7013: localonly => 'Other domains can search',
1.23 raeburn 7014: searchby => 'Search types',
7015: searchtypes => 'Search latitude');
7016: my @offon = ('off','on');
1.24 raeburn 7017: my @otherdoms = ('Yes','No');
1.23 raeburn 7018:
1.25 raeburn 7019: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 7020: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
7021: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
7022:
1.44 raeburn 7023: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 7024: if (keys(%{$usertypes}) == 0) {
7025: @cansearch = ('default');
7026: } else {
7027: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
7028: foreach my $type (@{$currdirsrch{'cansearch'}}) {
7029: if (!grep(/^\Q$type\E$/,@cansearch)) {
7030: push(@{$changes{'cansearch'}},$type);
7031: }
1.23 raeburn 7032: }
1.26 raeburn 7033: foreach my $type (@cansearch) {
7034: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
7035: push(@{$changes{'cansearch'}},$type);
7036: }
1.23 raeburn 7037: }
1.26 raeburn 7038: } else {
7039: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 7040: }
7041: }
7042:
7043: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
7044: foreach my $by (@{$currdirsrch{'searchby'}}) {
7045: if (!grep(/^\Q$by\E$/,@searchby)) {
7046: push(@{$changes{'searchby'}},$by);
7047: }
7048: }
7049: foreach my $by (@searchby) {
7050: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
7051: push(@{$changes{'searchby'}},$by);
7052: }
7053: }
7054: } else {
7055: push(@{$changes{'searchby'}},@searchby);
7056: }
1.25 raeburn 7057:
7058: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
7059: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
7060: if (!grep(/^\Q$type\E$/,@searchtypes)) {
7061: push(@{$changes{'searchtypes'}},$type);
7062: }
7063: }
7064: foreach my $type (@searchtypes) {
7065: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
7066: push(@{$changes{'searchtypes'}},$type);
7067: }
7068: }
7069: } else {
7070: if (exists($currdirsrch{'searchtypes'})) {
7071: foreach my $type (@searchtypes) {
7072: if ($type ne $currdirsrch{'searchtypes'}) {
7073: push(@{$changes{'searchtypes'}},$type);
7074: }
7075: }
7076: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
7077: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
7078: }
7079: } else {
7080: push(@{$changes{'searchtypes'}},@searchtypes);
7081: }
7082: }
7083:
1.23 raeburn 7084: my %dirsrch_hash = (
7085: directorysrch => { available => $env{'form.dirsrch_available'},
7086: cansearch => \@cansearch,
1.24 raeburn 7087: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 7088: searchby => \@searchby,
1.25 raeburn 7089: searchtypes => \@searchtypes,
1.23 raeburn 7090: }
7091: );
7092: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
7093: $dom);
7094: if ($putresult eq 'ok') {
7095: if (exists($currdirsrch{'available'})) {
7096: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
7097: $changes{'available'} = 1;
7098: }
7099: } else {
7100: if ($env{'form.dirsrch_available'} eq '1') {
7101: $changes{'available'} = 1;
7102: }
7103: }
1.24 raeburn 7104: if (exists($currdirsrch{'localonly'})) {
7105: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
7106: $changes{'localonly'} = 1;
7107: }
7108: } else {
7109: if ($env{'form.dirsrch_localonly'} eq '1') {
7110: $changes{'localonly'} = 1;
7111: }
7112: }
1.23 raeburn 7113: if (keys(%changes) > 0) {
7114: $resulttext = &mt('Changes made:').'<ul>';
7115: if ($changes{'available'}) {
7116: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
7117: }
1.24 raeburn 7118: if ($changes{'localonly'}) {
7119: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
7120: }
7121:
1.23 raeburn 7122: if (ref($changes{'cansearch'}) eq 'ARRAY') {
7123: my $chgtext;
1.26 raeburn 7124: if (ref($usertypes) eq 'HASH') {
7125: if (keys(%{$usertypes}) > 0) {
7126: foreach my $type (@{$types}) {
7127: if (grep(/^\Q$type\E$/,@cansearch)) {
7128: $chgtext .= $usertypes->{$type}.'; ';
7129: }
7130: }
7131: if (grep(/^default$/,@cansearch)) {
7132: $chgtext .= $othertitle;
7133: } else {
7134: $chgtext =~ s/\; $//;
7135: }
1.210 raeburn 7136: $resulttext .=
1.178 raeburn 7137: '<li>'.
7138: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
7139: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
7140: '</li>';
1.23 raeburn 7141: }
7142: }
7143: }
7144: if (ref($changes{'searchby'}) eq 'ARRAY') {
7145: my ($searchtitles,$titleorder) = &sorted_searchtitles();
7146: my $chgtext;
7147: foreach my $type (@{$titleorder}) {
7148: if (grep(/^\Q$type\E$/,@searchby)) {
7149: if (defined($searchtitles->{$type})) {
7150: $chgtext .= $searchtitles->{$type}.'; ';
7151: }
7152: }
7153: }
7154: $chgtext =~ s/\; $//;
7155: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
7156: }
1.25 raeburn 7157: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
7158: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
7159: my $chgtext;
7160: foreach my $type (@{$srchtypeorder}) {
7161: if (grep(/^\Q$type\E$/,@searchtypes)) {
7162: if (defined($srchtypes_desc->{$type})) {
7163: $chgtext .= $srchtypes_desc->{$type}.'; ';
7164: }
7165: }
7166: }
7167: $chgtext =~ s/\; $//;
1.178 raeburn 7168: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 7169: }
7170: $resulttext .= '</ul>';
7171: } else {
7172: $resulttext = &mt('No changes made to institution directory search settings');
7173: }
7174: } else {
7175: $resulttext = '<span class="LC_error">'.
1.27 raeburn 7176: &mt('An error occurred: [_1]',$putresult).'</span>';
7177: }
7178: return $resulttext;
7179: }
7180:
1.28 raeburn 7181: sub modify_contacts {
1.205 raeburn 7182: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 7183: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
7184: if (ref($domconfig{'contacts'}) eq 'HASH') {
7185: foreach my $key (keys(%{$domconfig{'contacts'}})) {
7186: $currsetting{$key} = $domconfig{'contacts'}{$key};
7187: }
7188: }
1.134 raeburn 7189: my (%others,%to,%bcc);
1.28 raeburn 7190: my @contacts = ('supportemail','adminemail');
1.102 raeburn 7191: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.203 raeburn 7192: 'requestsmail','updatesmail','idconflictsmail');
7193: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 7194: foreach my $type (@mailings) {
7195: @{$newsetting{$type}} =
7196: &Apache::loncommon::get_env_multiple('form.'.$type);
7197: foreach my $item (@contacts) {
7198: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
7199: $contacts_hash{contacts}{$type}{$item} = 1;
7200: } else {
7201: $contacts_hash{contacts}{$type}{$item} = 0;
7202: }
7203: }
7204: $others{$type} = $env{'form.'.$type.'_others'};
7205: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 7206: if ($type eq 'helpdeskmail') {
7207: $bcc{$type} = $env{'form.'.$type.'_bcc'};
7208: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
7209: }
1.28 raeburn 7210: }
7211: foreach my $item (@contacts) {
7212: $to{$item} = $env{'form.'.$item};
7213: $contacts_hash{'contacts'}{$item} = $to{$item};
7214: }
1.203 raeburn 7215: foreach my $item (@toggles) {
7216: if ($env{'form.'.$item} =~ /^(0|1)$/) {
7217: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
7218: }
7219: }
1.28 raeburn 7220: if (keys(%currsetting) > 0) {
7221: foreach my $item (@contacts) {
7222: if ($to{$item} ne $currsetting{$item}) {
7223: $changes{$item} = 1;
7224: }
7225: }
7226: foreach my $type (@mailings) {
7227: foreach my $item (@contacts) {
7228: if (ref($currsetting{$type}) eq 'HASH') {
7229: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
7230: push(@{$changes{$type}},$item);
7231: }
7232: } else {
7233: push(@{$changes{$type}},@{$newsetting{$type}});
7234: }
7235: }
7236: if ($others{$type} ne $currsetting{$type}{'others'}) {
7237: push(@{$changes{$type}},'others');
7238: }
1.134 raeburn 7239: if ($type eq 'helpdeskmail') {
7240: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
7241: push(@{$changes{$type}},'bcc');
7242: }
7243: }
1.28 raeburn 7244: }
7245: } else {
7246: my %default;
7247: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
7248: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
7249: $default{'errormail'} = 'adminemail';
7250: $default{'packagesmail'} = 'adminemail';
7251: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 7252: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 7253: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 7254: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 7255: foreach my $item (@contacts) {
7256: if ($to{$item} ne $default{$item}) {
7257: $changes{$item} = 1;
1.203 raeburn 7258: }
1.28 raeburn 7259: }
7260: foreach my $type (@mailings) {
7261: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
7262:
7263: push(@{$changes{$type}},@{$newsetting{$type}});
7264: }
7265: if ($others{$type} ne '') {
7266: push(@{$changes{$type}},'others');
1.134 raeburn 7267: }
7268: if ($type eq 'helpdeskmail') {
7269: if ($bcc{$type} ne '') {
7270: push(@{$changes{$type}},'bcc');
7271: }
7272: }
1.28 raeburn 7273: }
7274: }
1.203 raeburn 7275: foreach my $item (@toggles) {
7276: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
7277: $changes{$item} = 1;
7278: } elsif ((!$env{'form.'.$item}) &&
7279: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
7280: $changes{$item} = 1;
7281: }
7282: }
1.28 raeburn 7283: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
7284: $dom);
7285: if ($putresult eq 'ok') {
7286: if (keys(%changes) > 0) {
1.205 raeburn 7287: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7288: if (ref($lastactref) eq 'HASH') {
7289: $lastactref->{'domainconfig'} = 1;
7290: }
1.28 raeburn 7291: my ($titles,$short_titles) = &contact_titles();
7292: $resulttext = &mt('Changes made:').'<ul>';
7293: foreach my $item (@contacts) {
7294: if ($changes{$item}) {
7295: $resulttext .= '<li>'.$titles->{$item}.
7296: &mt(' set to: ').
7297: '<span class="LC_cusr_emph">'.
7298: $to{$item}.'</span></li>';
7299: }
7300: }
7301: foreach my $type (@mailings) {
7302: if (ref($changes{$type}) eq 'ARRAY') {
7303: $resulttext .= '<li>'.$titles->{$type}.': ';
7304: my @text;
7305: foreach my $item (@{$newsetting{$type}}) {
7306: push(@text,$short_titles->{$item});
7307: }
7308: if ($others{$type} ne '') {
7309: push(@text,$others{$type});
7310: }
7311: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 7312: join(', ',@text).'</span>';
7313: if ($type eq 'helpdeskmail') {
7314: if ($bcc{$type} ne '') {
7315: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
7316: }
7317: }
7318: $resulttext .= '</li>';
1.28 raeburn 7319: }
7320: }
1.203 raeburn 7321: my @offon = ('off','on');
7322: if ($changes{'reporterrors'}) {
7323: $resulttext .= '<li>'.
7324: &mt('E-mail error reports to [_1] set to "'.
7325: $offon[$env{'form.reporterrors'}].'".',
7326: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
7327: &mt('LON-CAPA core group - MSU'),600,500)).
7328: '</li>';
7329: }
7330: if ($changes{'reportupdates'}) {
7331: $resulttext .= '<li>'.
7332: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
7333: $offon[$env{'form.reportupdates'}].'".',
7334: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
7335: &mt('LON-CAPA core group - MSU'),600,500)).
7336: '</li>';
7337: }
1.28 raeburn 7338: $resulttext .= '</ul>';
7339: } else {
1.34 raeburn 7340: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 7341: }
7342: } else {
7343: $resulttext = '<span class="LC_error">'.
7344: &mt('An error occurred: [_1].',$putresult).'</span>';
7345: }
7346: return $resulttext;
7347: }
7348:
7349: sub modify_usercreation {
1.27 raeburn 7350: my ($dom,%domconfig) = @_;
1.34 raeburn 7351: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 7352: my $warningmsg;
1.27 raeburn 7353: if (ref($domconfig{'usercreation'}) eq 'HASH') {
7354: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
7355: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
7356: }
7357: }
7358: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 7359: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 7360: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 7361: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 7362: foreach my $item(@contexts) {
1.45 raeburn 7363: if ($item eq 'selfcreate') {
1.50 raeburn 7364: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.212 raeburn 7365: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.43 raeburn 7366: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 7367: if (ref($cancreate{$item}) eq 'ARRAY') {
7368: if (grep(/^login$/,@{$cancreate{$item}})) {
7369: $warningmsg = &mt('Although account creation has been set to be available for institutional logins, currently default authentication in this domain has not been set to support this.').' '.&mt('You need to set the default authentication type to Kerberos 4 or 5 (with a Kerberos domain specified), or to Local authentication, if the localauth module has been customized in your domain to authenticate institutional logins.');
7370: }
1.43 raeburn 7371: }
7372: }
1.50 raeburn 7373: } else {
7374: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 7375: }
1.34 raeburn 7376: }
1.93 raeburn 7377: my ($othertitle,$usertypes,$types) =
7378: &Apache::loncommon::sorted_inst_types($dom);
7379: if (ref($types) eq 'ARRAY') {
7380: if (@{$types} > 0) {
7381: @{$cancreate{'statustocreate'}} =
7382: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 raeburn 7383: } else {
7384: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 7385: }
7386: push(@contexts,'statustocreate');
7387: }
1.165 raeburn 7388: &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
1.34 raeburn 7389: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
7390: foreach my $item (@contexts) {
1.93 raeburn 7391: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
7392: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 7393: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 raeburn 7394: if (ref($cancreate{$item}) eq 'ARRAY') {
7395: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
7396: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7397: push(@{$changes{'cancreate'}},$item);
7398: }
1.50 raeburn 7399: }
7400: }
7401: }
7402: } else {
7403: if ($curr_usercreation{'cancreate'}{$item} eq '') {
7404: if (@{$cancreate{$item}} > 0) {
7405: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7406: push(@{$changes{'cancreate'}},$item);
7407: }
7408: }
7409: } else {
7410: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
7411: if (@{$cancreate{$item}} < 3) {
7412: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7413: push(@{$changes{'cancreate'}},$item);
7414: }
7415: }
7416: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
7417: if (@{$cancreate{$item}} > 0) {
7418: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7419: push(@{$changes{'cancreate'}},$item);
7420: }
7421: }
7422: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
7423: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7424: push(@{$changes{'cancreate'}},$item);
7425: }
7426: }
7427: }
7428: }
7429: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7430: foreach my $type (@{$cancreate{$item}}) {
7431: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
7432: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
7433: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7434: push(@{$changes{'cancreate'}},$item);
7435: }
7436: }
7437: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
7438: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
7439: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
7440: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7441: push(@{$changes{'cancreate'}},$item);
7442: }
7443: }
7444: }
7445: }
7446: }
7447: } else {
7448: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
7449: push(@{$changes{'cancreate'}},$item);
7450: }
7451: }
1.27 raeburn 7452: }
1.34 raeburn 7453: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
7454: foreach my $item (@contexts) {
1.43 raeburn 7455: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 7456: if ($cancreate{$item} ne 'any') {
7457: push(@{$changes{'cancreate'}},$item);
7458: }
7459: } else {
7460: if ($cancreate{$item} ne 'none') {
7461: push(@{$changes{'cancreate'}},$item);
7462: }
1.27 raeburn 7463: }
7464: }
7465: } else {
1.43 raeburn 7466: foreach my $item (@contexts) {
1.34 raeburn 7467: push(@{$changes{'cancreate'}},$item);
7468: }
1.27 raeburn 7469: }
1.34 raeburn 7470:
1.27 raeburn 7471: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
7472: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
7473: if (!grep(/^\Q$type\E$/,@username_rule)) {
7474: push(@{$changes{'username_rule'}},$type);
7475: }
7476: }
7477: foreach my $type (@username_rule) {
7478: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
7479: push(@{$changes{'username_rule'}},$type);
7480: }
7481: }
7482: } else {
7483: push(@{$changes{'username_rule'}},@username_rule);
7484: }
7485:
1.32 raeburn 7486: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
7487: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
7488: if (!grep(/^\Q$type\E$/,@id_rule)) {
7489: push(@{$changes{'id_rule'}},$type);
7490: }
7491: }
7492: foreach my $type (@id_rule) {
7493: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
7494: push(@{$changes{'id_rule'}},$type);
7495: }
7496: }
7497: } else {
7498: push(@{$changes{'id_rule'}},@id_rule);
7499: }
7500:
1.43 raeburn 7501: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
7502: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
7503: if (!grep(/^\Q$type\E$/,@email_rule)) {
7504: push(@{$changes{'email_rule'}},$type);
7505: }
7506: }
7507: foreach my $type (@email_rule) {
7508: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
7509: push(@{$changes{'email_rule'}},$type);
7510: }
7511: }
7512: } else {
7513: push(@{$changes{'email_rule'}},@email_rule);
7514: }
7515:
7516: my @authen_contexts = ('author','course','domain');
1.28 raeburn 7517: my @authtypes = ('int','krb4','krb5','loc');
7518: my %authhash;
1.43 raeburn 7519: foreach my $item (@authen_contexts) {
1.28 raeburn 7520: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
7521: foreach my $auth (@authtypes) {
7522: if (grep(/^\Q$auth\E$/,@authallowed)) {
7523: $authhash{$item}{$auth} = 1;
7524: } else {
7525: $authhash{$item}{$auth} = 0;
7526: }
7527: }
7528: }
7529: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 7530: foreach my $item (@authen_contexts) {
1.28 raeburn 7531: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
7532: foreach my $auth (@authtypes) {
7533: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
7534: push(@{$changes{'authtypes'}},$item);
7535: last;
7536: }
7537: }
7538: }
7539: }
7540: } else {
1.43 raeburn 7541: foreach my $item (@authen_contexts) {
1.28 raeburn 7542: push(@{$changes{'authtypes'}},$item);
7543: }
7544: }
7545:
1.27 raeburn 7546: my %usercreation_hash = (
1.28 raeburn 7547: usercreation => {
1.34 raeburn 7548: cancreate => \%cancreate,
1.27 raeburn 7549: username_rule => \@username_rule,
1.32 raeburn 7550: id_rule => \@id_rule,
1.43 raeburn 7551: email_rule => \@email_rule,
1.32 raeburn 7552: authtypes => \%authhash,
1.27 raeburn 7553: }
7554: );
7555:
7556: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
7557: $dom);
1.50 raeburn 7558:
7559: my %selfcreatetypes = (
7560: sso => 'users authenticated by institutional single sign on',
7561: login => 'users authenticated by institutional log-in',
7562: email => 'users who provide a valid e-mail address for use as the username',
7563: );
1.27 raeburn 7564: if ($putresult eq 'ok') {
7565: if (keys(%changes) > 0) {
7566: $resulttext = &mt('Changes made:').'<ul>';
7567: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 7568: my %lt = &usercreation_types();
7569: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 7570: my $chgtext;
1.165 raeburn 7571: unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
1.100 raeburn 7572: $chgtext = $lt{$type}.', ';
7573: }
1.45 raeburn 7574: if ($type eq 'selfcreate') {
1.50 raeburn 7575: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 7576: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 7577: } else {
1.100 raeburn 7578: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 7579: foreach my $case (@{$cancreate{$type}}) {
7580: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
7581: }
7582: $chgtext .= '</ul>';
1.100 raeburn 7583: if (ref($cancreate{$type}) eq 'ARRAY') {
7584: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
7585: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
7586: if (@{$cancreate{'statustocreate'}} == 0) {
7587: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
7588: }
7589: }
7590: }
7591: }
1.43 raeburn 7592: }
1.93 raeburn 7593: } elsif ($type eq 'statustocreate') {
1.96 raeburn 7594: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
7595: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
7596: if (@{$cancreate{'selfcreate'}} > 0) {
7597: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 7598:
7599: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 7600: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 7601: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
7602: }
1.96 raeburn 7603: } elsif (ref($usertypes) eq 'HASH') {
7604: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 7605: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
7606: } else {
7607: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
7608: }
7609: $chgtext .= '<ul>';
7610: foreach my $case (@{$cancreate{$type}}) {
7611: if ($case eq 'default') {
7612: $chgtext .= '<li>'.$othertitle.'</li>';
7613: } else {
7614: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 7615: }
7616: }
1.100 raeburn 7617: $chgtext .= '</ul>';
7618: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
7619: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
7620: }
7621: }
7622: } else {
7623: if (@{$cancreate{$type}} == 0) {
7624: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
7625: } else {
7626: $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 7627: }
7628: }
7629: }
1.165 raeburn 7630: } elsif ($type eq 'captcha') {
7631: if ($cancreate{$type} eq 'notused') {
7632: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
7633: } else {
7634: my %captchas = &captcha_phrases();
7635: if ($captchas{$cancreate{$type}}) {
7636: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
7637: } else {
1.210 raeburn 7638: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 7639: }
7640: }
7641: } elsif ($type eq 'recaptchakeys') {
7642: my ($privkey,$pubkey);
7643: if (ref($cancreate{$type}) eq 'HASH') {
7644: $pubkey = $cancreate{$type}{'public'};
7645: $privkey = $cancreate{$type}{'private'};
7646: }
7647: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
7648: if (!$pubkey) {
7649: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
7650: } else {
7651: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7652: }
7653: if (!$privkey) {
7654: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
7655: } else {
7656: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
7657: }
7658: $chgtext .= '</ul>';
1.43 raeburn 7659: } else {
7660: if ($cancreate{$type} eq 'none') {
7661: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
7662: } elsif ($cancreate{$type} eq 'any') {
7663: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
7664: } elsif ($cancreate{$type} eq 'official') {
7665: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
7666: } elsif ($cancreate{$type} eq 'unofficial') {
7667: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
7668: }
1.34 raeburn 7669: }
7670: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 7671: }
7672: }
7673: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 7674: my ($rules,$ruleorder) =
7675: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 7676: my $chgtext = '<ul>';
7677: foreach my $type (@username_rule) {
7678: if (ref($rules->{$type}) eq 'HASH') {
7679: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
7680: }
7681: }
7682: $chgtext .= '</ul>';
7683: if (@username_rule > 0) {
7684: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7685: } else {
1.28 raeburn 7686: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 7687: }
7688: }
1.32 raeburn 7689: if (ref($changes{'id_rule'}) eq 'ARRAY') {
7690: my ($idrules,$idruleorder) =
7691: &Apache::lonnet::inst_userrules($dom,'id');
7692: my $chgtext = '<ul>';
7693: foreach my $type (@id_rule) {
7694: if (ref($idrules->{$type}) eq 'HASH') {
7695: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
7696: }
7697: }
7698: $chgtext .= '</ul>';
7699: if (@id_rule > 0) {
7700: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7701: } else {
7702: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
7703: }
7704: }
1.43 raeburn 7705: if (ref($changes{'email_rule'}) eq 'ARRAY') {
7706: my ($emailrules,$emailruleorder) =
7707: &Apache::lonnet::inst_userrules($dom,'email');
7708: my $chgtext = '<ul>';
7709: foreach my $type (@email_rule) {
7710: if (ref($emailrules->{$type}) eq 'HASH') {
7711: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
7712: }
7713: }
7714: $chgtext .= '</ul>';
7715: if (@email_rule > 0) {
7716: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
7717: } else {
7718: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
7719: }
7720: }
7721:
1.28 raeburn 7722: my %authname = &authtype_names();
7723: my %context_title = &context_names();
7724: if (ref($changes{'authtypes'}) eq 'ARRAY') {
7725: my $chgtext = '<ul>';
7726: foreach my $type (@{$changes{'authtypes'}}) {
7727: my @allowed;
7728: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
7729: foreach my $auth (@authtypes) {
7730: if ($authhash{$type}{$auth}) {
7731: push(@allowed,$authname{$auth});
7732: }
7733: }
1.43 raeburn 7734: if (@allowed > 0) {
7735: $chgtext .= join(', ',@allowed).'</li>';
7736: } else {
7737: $chgtext .= &mt('none').'</li>';
7738: }
1.28 raeburn 7739: }
7740: $chgtext .= '</ul>';
7741: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
7742: $resulttext .= '</li>';
7743: }
1.27 raeburn 7744: $resulttext .= '</ul>';
7745: } else {
1.28 raeburn 7746: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 7747: }
7748: } else {
7749: $resulttext = '<span class="LC_error">'.
1.23 raeburn 7750: &mt('An error occurred: [_1]',$putresult).'</span>';
7751: }
1.43 raeburn 7752: if ($warningmsg ne '') {
7753: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
7754: }
1.23 raeburn 7755: return $resulttext;
7756: }
7757:
1.165 raeburn 7758: sub process_captcha {
7759: my ($container,$changes,$newsettings,$current) = @_;
7760: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
7761: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
7762: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
7763: $newsettings->{'captcha'} = 'original';
7764: }
7765: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 7766: if ($container eq 'cancreate') {
1.169 raeburn 7767: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7768: push(@{$changes->{'cancreate'}},'captcha');
7769: } elsif (!defined($changes->{'cancreate'})) {
7770: $changes->{'cancreate'} = ['captcha'];
7771: }
7772: } else {
7773: $changes->{'captcha'} = 1;
1.165 raeburn 7774: }
7775: }
7776: my ($newpub,$newpriv,$currpub,$currpriv);
7777: if ($newsettings->{'captcha'} eq 'recaptcha') {
7778: $newpub = $env{'form.'.$container.'_recaptchapub'};
7779: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.169 raeburn 7780: $newpub =~ s/\W//g;
7781: $newpriv =~ s/\W//g;
7782: $newsettings->{'recaptchakeys'} = {
7783: public => $newpub,
7784: private => $newpriv,
7785: };
1.165 raeburn 7786: }
7787: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
7788: $currpub = $current->{'recaptchakeys'}{'public'};
7789: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 7790: unless ($newsettings->{'captcha'} eq 'recaptcha') {
7791: $newsettings->{'recaptchakeys'} = {
7792: public => '',
7793: private => '',
7794: }
7795: }
1.165 raeburn 7796: }
7797: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 7798: if ($container eq 'cancreate') {
7799: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7800: push(@{$changes->{'cancreate'}},'recaptchakeys');
7801: } elsif (!defined($changes->{'cancreate'})) {
7802: $changes->{'cancreate'} = ['recaptchakeys'];
7803: }
7804: } else {
1.210 raeburn 7805: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 7806: }
7807: }
7808: return;
7809: }
7810:
1.33 raeburn 7811: sub modify_usermodification {
7812: my ($dom,%domconfig) = @_;
7813: my ($resulttext,%curr_usermodification,%changes);
7814: if (ref($domconfig{'usermodification'}) eq 'HASH') {
7815: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
7816: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
7817: }
7818: }
1.63 raeburn 7819: my @contexts = ('author','course','selfcreate');
1.33 raeburn 7820: my %context_title = (
7821: author => 'In author context',
7822: course => 'In course context',
1.63 raeburn 7823: selfcreate => 'When self creating account',
1.33 raeburn 7824: );
7825: my @fields = ('lastname','firstname','middlename','generation',
7826: 'permanentemail','id');
7827: my %roles = (
7828: author => ['ca','aa'],
7829: course => ['st','ep','ta','in','cr'],
7830: );
1.63 raeburn 7831: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7832: if (ref($types) eq 'ARRAY') {
7833: push(@{$types},'default');
7834: $usertypes->{'default'} = $othertitle;
7835: }
7836: $roles{'selfcreate'} = $types;
1.33 raeburn 7837: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7838: my %modifyhash;
7839: foreach my $context (@contexts) {
7840: foreach my $role (@{$roles{$context}}) {
7841: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
7842: foreach my $item (@fields) {
7843: if (grep(/^\Q$item\E$/,@modifiable)) {
7844: $modifyhash{$context}{$role}{$item} = 1;
7845: } else {
7846: $modifyhash{$context}{$role}{$item} = 0;
7847: }
7848: }
7849: }
7850: if (ref($curr_usermodification{$context}) eq 'HASH') {
7851: foreach my $role (@{$roles{$context}}) {
7852: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
7853: foreach my $field (@fields) {
7854: if ($modifyhash{$context}{$role}{$field} ne
7855: $curr_usermodification{$context}{$role}{$field}) {
7856: push(@{$changes{$context}},$role);
7857: last;
7858: }
7859: }
7860: }
7861: }
7862: } else {
7863: foreach my $context (@contexts) {
7864: foreach my $role (@{$roles{$context}}) {
7865: push(@{$changes{$context}},$role);
7866: }
7867: }
7868: }
7869: }
7870: my %usermodification_hash = (
7871: usermodification => \%modifyhash,
7872: );
7873: my $putresult = &Apache::lonnet::put_dom('configuration',
7874: \%usermodification_hash,$dom);
7875: if ($putresult eq 'ok') {
7876: if (keys(%changes) > 0) {
7877: $resulttext = &mt('Changes made: ').'<ul>';
7878: foreach my $context (@contexts) {
7879: if (ref($changes{$context}) eq 'ARRAY') {
7880: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
7881: if (ref($changes{$context}) eq 'ARRAY') {
7882: foreach my $role (@{$changes{$context}}) {
7883: my $rolename;
1.63 raeburn 7884: if ($context eq 'selfcreate') {
7885: $rolename = $role;
7886: if (ref($usertypes) eq 'HASH') {
7887: if ($usertypes->{$role} ne '') {
7888: $rolename = $usertypes->{$role};
7889: }
7890: }
1.33 raeburn 7891: } else {
1.63 raeburn 7892: if ($role eq 'cr') {
7893: $rolename = &mt('Custom');
7894: } else {
7895: $rolename = &Apache::lonnet::plaintext($role);
7896: }
1.33 raeburn 7897: }
7898: my @modifiable;
1.63 raeburn 7899: if ($context eq 'selfcreate') {
1.126 bisitz 7900: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Self-creation of account by users with status: [_1]',$rolename).'</span> - '.&mt('modifiable fields (if institutional data blank): ');
1.63 raeburn 7901: } else {
7902: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
7903: }
1.33 raeburn 7904: foreach my $field (@fields) {
7905: if ($modifyhash{$context}{$role}{$field}) {
7906: push(@modifiable,$fieldtitles{$field});
7907: }
7908: }
7909: if (@modifiable > 0) {
7910: $resulttext .= join(', ',@modifiable);
7911: } else {
7912: $resulttext .= &mt('none');
7913: }
7914: $resulttext .= '</li>';
7915: }
7916: $resulttext .= '</ul></li>';
7917: }
7918: }
7919: }
7920: $resulttext .= '</ul>';
7921: } else {
7922: $resulttext = &mt('No changes made to user modification settings');
7923: }
7924: } else {
7925: $resulttext = '<span class="LC_error">'.
7926: &mt('An error occurred: [_1]',$putresult).'</span>';
7927: }
7928: return $resulttext;
7929: }
7930:
1.43 raeburn 7931: sub modify_defaults {
1.212 raeburn 7932: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 7933: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 7934: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 7935: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 7936: my @authtypes = ('internal','krb4','krb5','localauth');
7937: foreach my $item (@items) {
7938: $newvalues{$item} = $env{'form.'.$item};
7939: if ($item eq 'auth_def') {
7940: if ($newvalues{$item} ne '') {
7941: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
7942: push(@errors,$item);
7943: }
7944: }
7945: } elsif ($item eq 'lang_def') {
7946: if ($newvalues{$item} ne '') {
7947: if ($newvalues{$item} =~ /^(\w+)/) {
7948: my $langcode = $1;
1.103 raeburn 7949: if ($langcode ne 'x_chef') {
7950: if (code2language($langcode) eq '') {
7951: push(@errors,$item);
7952: }
1.43 raeburn 7953: }
7954: } else {
7955: push(@errors,$item);
7956: }
7957: }
1.54 raeburn 7958: } elsif ($item eq 'timezone_def') {
7959: if ($newvalues{$item} ne '') {
1.62 raeburn 7960: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 7961: push(@errors,$item);
7962: }
7963: }
1.68 raeburn 7964: } elsif ($item eq 'datelocale_def') {
7965: if ($newvalues{$item} ne '') {
7966: my @datelocale_ids = DateTime::Locale->ids();
7967: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
7968: push(@errors,$item);
7969: }
7970: }
1.141 raeburn 7971: } elsif ($item eq 'portal_def') {
7972: if ($newvalues{$item} ne '') {
7973: 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])\/?$/) {
7974: push(@errors,$item);
7975: }
7976: }
1.43 raeburn 7977: }
7978: if (grep(/^\Q$item\E$/,@errors)) {
7979: $newvalues{$item} = $domdefaults{$item};
7980: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
7981: $changes{$item} = 1;
7982: }
1.72 raeburn 7983: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 7984: }
7985: my %defaults_hash = (
1.72 raeburn 7986: defaults => \%newvalues,
7987: );
1.43 raeburn 7988: my $title = &defaults_titles();
7989: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
7990: $dom);
7991: if ($putresult eq 'ok') {
7992: if (keys(%changes) > 0) {
7993: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 7994: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 7995: 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";
7996: foreach my $item (sort(keys(%changes))) {
7997: my $value = $env{'form.'.$item};
7998: if ($value eq '') {
7999: $value = &mt('none');
8000: } elsif ($item eq 'auth_def') {
8001: my %authnames = &authtype_names();
8002: my %shortauth = (
8003: internal => 'int',
8004: krb4 => 'krb4',
8005: krb5 => 'krb5',
8006: localauth => 'loc',
8007: );
8008: $value = $authnames{$shortauth{$value}};
8009: }
8010: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
8011: $mailmsgtext .= "$title->{$item} set to $value\n";
8012: }
8013: $resulttext .= '</ul>';
8014: $mailmsgtext .= "\n";
8015: my $cachetime = 24*60*60;
1.72 raeburn 8016: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 8017: if (ref($lastactref) eq 'HASH') {
8018: $lastactref->{'domdefaults'} = 1;
8019: }
1.68 raeburn 8020: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 8021: my $notify = 1;
8022: if (ref($domconfig{'contacts'}) eq 'HASH') {
8023: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
8024: $notify = 0;
8025: }
8026: }
8027: if ($notify) {
8028: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
8029: "LON-CAPA Domain Settings Change - $dom",
8030: $mailmsgtext);
8031: }
1.54 raeburn 8032: }
1.43 raeburn 8033: } else {
1.54 raeburn 8034: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 8035: }
8036: } else {
8037: $resulttext = '<span class="LC_error">'.
8038: &mt('An error occurred: [_1]',$putresult).'</span>';
8039: }
8040: if (@errors > 0) {
8041: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
8042: foreach my $item (@errors) {
8043: $resulttext .= ' "'.$title->{$item}.'",';
8044: }
8045: $resulttext =~ s/,$//;
8046: }
8047: return $resulttext;
8048: }
8049:
1.46 raeburn 8050: sub modify_scantron {
1.205 raeburn 8051: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 8052: my ($resulttext,%confhash,%changes,$errors);
8053: my $custom = 'custom.tab';
8054: my $default = 'default.tab';
8055: my $servadm = $r->dir_config('lonAdmEMail');
8056: my ($configuserok,$author_ok,$switchserver) =
8057: &config_check($dom,$confname,$servadm);
8058: if ($env{'form.scantronformat.filename'} ne '') {
8059: my $error;
8060: if ($configuserok eq 'ok') {
8061: if ($switchserver) {
1.130 raeburn 8062: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 8063: } else {
8064: if ($author_ok eq 'ok') {
8065: my ($result,$scantronurl) =
8066: &publishlogo($r,'upload','scantronformat',$dom,
8067: $confname,'scantron','','',$custom);
8068: if ($result eq 'ok') {
8069: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 8070: $changes{'scantronformat'} = 1;
1.46 raeburn 8071: } else {
8072: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
8073: }
8074: } else {
8075: $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);
8076: }
8077: }
8078: } else {
8079: $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);
8080: }
8081: if ($error) {
8082: &Apache::lonnet::logthis($error);
8083: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8084: }
8085: }
1.48 raeburn 8086: if (ref($domconfig{'scantron'}) eq 'HASH') {
8087: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
8088: if ($env{'form.scantronformat_del'}) {
8089: $confhash{'scantron'}{'scantronformat'} = '';
8090: $changes{'scantronformat'} = 1;
1.46 raeburn 8091: }
8092: }
8093: }
8094: if (keys(%confhash) > 0) {
8095: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
8096: $dom);
8097: if ($putresult eq 'ok') {
8098: if (keys(%changes) > 0) {
1.48 raeburn 8099: if (ref($confhash{'scantron'}) eq 'HASH') {
8100: $resulttext = &mt('Changes made:').'<ul>';
8101: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 8102: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 8103: } else {
1.130 raeburn 8104: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 8105: }
1.48 raeburn 8106: $resulttext .= '</ul>';
8107: } else {
1.130 raeburn 8108: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 8109: }
8110: $resulttext .= '</ul>';
8111: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 8112: if (ref($lastactref) eq 'HASH') {
8113: $lastactref->{'domainconfig'} = 1;
8114: }
1.46 raeburn 8115: } else {
1.130 raeburn 8116: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 8117: }
8118: } else {
8119: $resulttext = '<span class="LC_error">'.
8120: &mt('An error occurred: [_1]',$putresult).'</span>';
8121: }
8122: } else {
1.130 raeburn 8123: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 8124: }
8125: if ($errors) {
8126: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
8127: $errors.'</ul>';
8128: }
8129: return $resulttext;
8130: }
8131:
1.48 raeburn 8132: sub modify_coursecategories {
8133: my ($dom,%domconfig) = @_;
1.57 raeburn 8134: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
8135: $cathash);
1.48 raeburn 8136: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 8137: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 8138: $cathash = $domconfig{'coursecategories'}{'cats'};
8139: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
8140: $changes{'togglecats'} = 1;
8141: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
8142: }
8143: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
8144: $changes{'categorize'} = 1;
8145: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
8146: }
1.120 raeburn 8147: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
8148: $changes{'togglecatscomm'} = 1;
8149: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
8150: }
8151: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
8152: $changes{'categorizecomm'} = 1;
8153: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
8154: }
1.57 raeburn 8155: } else {
8156: $changes{'togglecats'} = 1;
8157: $changes{'categorize'} = 1;
1.124 raeburn 8158: $changes{'togglecatscomm'} = 1;
8159: $changes{'categorizecomm'} = 1;
1.87 raeburn 8160: $domconfig{'coursecategories'} = {
8161: togglecats => $env{'form.togglecats'},
8162: categorize => $env{'form.categorize'},
1.124 raeburn 8163: togglecatscomm => $env{'form.togglecatscomm'},
8164: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 8165: };
1.57 raeburn 8166: }
8167: if (ref($cathash) eq 'HASH') {
8168: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 8169: push (@deletecategory,'instcode::0');
8170: }
1.120 raeburn 8171: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
8172: push(@deletecategory,'communities::0');
8173: }
1.48 raeburn 8174: }
1.57 raeburn 8175: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
8176: if (ref($cathash) eq 'HASH') {
1.48 raeburn 8177: if (@deletecategory > 0) {
8178: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 8179: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 8180: foreach my $item (@deletecategory) {
1.57 raeburn 8181: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
8182: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 8183: $deletions{$item} = 1;
1.57 raeburn 8184: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 8185: }
8186: }
8187: }
1.57 raeburn 8188: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 8189: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 8190: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 8191: $reorderings{$item} = 1;
1.57 raeburn 8192: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 8193: }
8194: if ($env{'form.addcategory_name_'.$item} ne '') {
8195: my $newcat = $env{'form.addcategory_name_'.$item};
8196: my $newdepth = $depth+1;
8197: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 8198: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 8199: $adds{$newitem} = 1;
8200: }
8201: if ($env{'form.subcat_'.$item} ne '') {
8202: my $newcat = $env{'form.subcat_'.$item};
8203: my $newdepth = $depth+1;
8204: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 8205: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 8206: $adds{$newitem} = 1;
8207: }
8208: }
8209: }
8210: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 8211: if (ref($cathash) eq 'HASH') {
1.48 raeburn 8212: my $newitem = 'instcode::0';
1.57 raeburn 8213: if ($cathash->{$newitem} eq '') {
8214: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 8215: $adds{$newitem} = 1;
8216: }
8217: } else {
8218: my $newitem = 'instcode::0';
1.57 raeburn 8219: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 8220: $adds{$newitem} = 1;
8221: }
8222: }
1.120 raeburn 8223: if ($env{'form.communities'} eq '1') {
8224: if (ref($cathash) eq 'HASH') {
8225: my $newitem = 'communities::0';
8226: if ($cathash->{$newitem} eq '') {
8227: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
8228: $adds{$newitem} = 1;
8229: }
8230: } else {
8231: my $newitem = 'communities::0';
8232: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
8233: $adds{$newitem} = 1;
8234: }
8235: }
1.48 raeburn 8236: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 8237: if (($env{'form.addcategory_name'} ne 'instcode') &&
8238: ($env{'form.addcategory_name'} ne 'communities')) {
8239: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
8240: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
8241: $adds{$newitem} = 1;
8242: }
1.48 raeburn 8243: }
1.57 raeburn 8244: my $putresult;
1.48 raeburn 8245: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
8246: if (keys(%deletions) > 0) {
8247: foreach my $key (keys(%deletions)) {
8248: if ($predelallitems{$key} ne '') {
8249: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
8250: }
8251: }
8252: }
8253: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 8254: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 8255: if (ref($chkcats[0]) eq 'ARRAY') {
8256: my $depth = 0;
8257: my $chg = 0;
8258: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
8259: my $name = $chkcats[0][$i];
8260: my $item;
8261: if ($name eq '') {
8262: $chg ++;
8263: } else {
8264: $item = &escape($name).'::0';
8265: if ($chg) {
1.57 raeburn 8266: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 8267: }
8268: $depth ++;
1.57 raeburn 8269: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 8270: $depth --;
8271: }
8272: }
8273: }
1.57 raeburn 8274: }
8275: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
8276: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 8277: if ($putresult eq 'ok') {
1.57 raeburn 8278: my %title = (
1.120 raeburn 8279: togglecats => 'Show/Hide a course in catalog',
8280: categorize => 'Assign a category to a course',
8281: togglecatscomm => 'Show/Hide a community in catalog',
8282: categorizecomm => 'Assign a category to a community',
1.57 raeburn 8283: );
8284: my %level = (
1.120 raeburn 8285: dom => 'set in Domain ("Modify Course/Community")',
8286: crs => 'set in Course ("Course Configuration")',
8287: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 8288: );
1.48 raeburn 8289: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 8290: if ($changes{'togglecats'}) {
8291: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
8292: }
8293: if ($changes{'categorize'}) {
8294: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 8295: }
1.120 raeburn 8296: if ($changes{'togglecatscomm'}) {
8297: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
8298: }
8299: if ($changes{'categorizecomm'}) {
8300: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
8301: }
1.57 raeburn 8302: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
8303: my $cathash;
8304: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
8305: $cathash = $domconfig{'coursecategories'}{'cats'};
8306: } else {
8307: $cathash = {};
8308: }
8309: my (@cats,@trails,%allitems);
8310: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
8311: if (keys(%deletions) > 0) {
8312: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
8313: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
8314: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
8315: }
8316: $resulttext .= '</ul></li>';
8317: }
8318: if (keys(%reorderings) > 0) {
8319: my %sort_by_trail;
8320: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
8321: foreach my $key (keys(%reorderings)) {
8322: if ($allitems{$key} ne '') {
8323: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
8324: }
1.48 raeburn 8325: }
1.57 raeburn 8326: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
8327: $resulttext .= '<li>'.$trails[$trail].'</li>';
8328: }
8329: $resulttext .= '</ul></li>';
1.48 raeburn 8330: }
1.57 raeburn 8331: if (keys(%adds) > 0) {
8332: my %sort_by_trail;
8333: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
8334: foreach my $key (keys(%adds)) {
8335: if ($allitems{$key} ne '') {
8336: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
8337: }
8338: }
8339: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
8340: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 8341: }
1.57 raeburn 8342: $resulttext .= '</ul></li>';
1.48 raeburn 8343: }
8344: }
8345: $resulttext .= '</ul>';
8346: } else {
8347: $resulttext = '<span class="LC_error">'.
1.57 raeburn 8348: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 8349: }
8350: } else {
1.120 raeburn 8351: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 8352: }
8353: return $resulttext;
8354: }
8355:
1.69 raeburn 8356: sub modify_serverstatuses {
8357: my ($dom,%domconfig) = @_;
8358: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
8359: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
8360: %currserverstatus = %{$domconfig{'serverstatuses'}};
8361: }
8362: my @pages = &serverstatus_pages();
8363: foreach my $type (@pages) {
8364: $newserverstatus{$type}{'namedusers'} = '';
8365: $newserverstatus{$type}{'machines'} = '';
8366: if (defined($env{'form.'.$type.'_namedusers'})) {
8367: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
8368: my @okusers;
8369: foreach my $user (@users) {
8370: my ($uname,$udom) = split(/:/,$user);
8371: if (($udom =~ /^$match_domain$/) &&
8372: (&Apache::lonnet::domain($udom)) &&
8373: ($uname =~ /^$match_username$/)) {
8374: if (!grep(/^\Q$user\E/,@okusers)) {
8375: push(@okusers,$user);
8376: }
8377: }
8378: }
8379: if (@okusers > 0) {
8380: @okusers = sort(@okusers);
8381: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
8382: }
8383: }
8384: if (defined($env{'form.'.$type.'_machines'})) {
8385: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
8386: my @okmachines;
8387: foreach my $ip (@machines) {
8388: my @parts = split(/\./,$ip);
8389: next if (@parts < 4);
8390: my $badip = 0;
8391: for (my $i=0; $i<4; $i++) {
8392: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
8393: $badip = 1;
8394: last;
8395: }
8396: }
8397: if (!$badip) {
8398: push(@okmachines,$ip);
8399: }
8400: }
8401: @okmachines = sort(@okmachines);
8402: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
8403: }
8404: }
8405: my %serverstatushash = (
8406: serverstatuses => \%newserverstatus,
8407: );
8408: foreach my $type (@pages) {
1.83 raeburn 8409: foreach my $setting ('namedusers','machines') {
1.84 raeburn 8410: my (@current,@new);
1.83 raeburn 8411: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 8412: if ($currserverstatus{$type}{$setting} ne '') {
8413: @current = split(/,/,$currserverstatus{$type}{$setting});
8414: }
8415: }
8416: if ($newserverstatus{$type}{$setting} ne '') {
8417: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 8418: }
8419: if (@current > 0) {
8420: if (@new > 0) {
8421: foreach my $item (@current) {
8422: if (!grep(/^\Q$item\E$/,@new)) {
8423: $changes{$type}{$setting} = 1;
1.82 raeburn 8424: last;
8425: }
8426: }
1.84 raeburn 8427: foreach my $item (@new) {
8428: if (!grep(/^\Q$item\E$/,@current)) {
8429: $changes{$type}{$setting} = 1;
8430: last;
1.82 raeburn 8431: }
8432: }
8433: } else {
1.83 raeburn 8434: $changes{$type}{$setting} = 1;
1.69 raeburn 8435: }
1.83 raeburn 8436: } elsif (@new > 0) {
8437: $changes{$type}{$setting} = 1;
1.69 raeburn 8438: }
8439: }
8440: }
8441: if (keys(%changes) > 0) {
1.81 raeburn 8442: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 8443: my $putresult = &Apache::lonnet::put_dom('configuration',
8444: \%serverstatushash,$dom);
8445: if ($putresult eq 'ok') {
8446: $resulttext .= &mt('Changes made:').'<ul>';
8447: foreach my $type (@pages) {
1.84 raeburn 8448: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 8449: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 8450: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 8451: if ($newserverstatus{$type}{'namedusers'} eq '') {
8452: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
8453: } else {
8454: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
8455: }
1.84 raeburn 8456: }
8457: if ($changes{$type}{'machines'}) {
1.69 raeburn 8458: if ($newserverstatus{$type}{'machines'} eq '') {
8459: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
8460: } else {
8461: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
8462: }
8463:
8464: }
8465: $resulttext .= '</ul></li>';
8466: }
8467: }
8468: $resulttext .= '</ul>';
8469: } else {
8470: $resulttext = '<span class="LC_error">'.
8471: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
8472:
8473: }
8474: } else {
8475: $resulttext = &mt('No changes made to access to server status pages');
8476: }
8477: return $resulttext;
8478: }
8479:
1.118 jms 8480: sub modify_helpsettings {
1.122 jms 8481: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 8482: my ($resulttext,$errors,%changes,%helphash);
8483: my %defaultchecked = ('submitbugs' => 'on');
8484: my @offon = ('off','on');
1.118 jms 8485: my @toggles = ('submitbugs');
8486: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8487: foreach my $item (@toggles) {
1.166 raeburn 8488: if ($defaultchecked{$item} eq 'on') {
8489: if ($domconfig{'helpsettings'}{$item} eq '') {
8490: if ($env{'form.'.$item} eq '0') {
8491: $changes{$item} = 1;
8492: }
8493: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
8494: $changes{$item} = 1;
8495: }
8496: } elsif ($defaultchecked{$item} eq 'off') {
8497: if ($domconfig{'helpsettings'}{$item} eq '') {
8498: if ($env{'form.'.$item} eq '1') {
8499: $changes{$item} = 1;
8500: }
8501: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
8502: $changes{$item} = 1;
8503: }
8504: }
1.210 raeburn 8505: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
1.166 raeburn 8506: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
8507: }
8508: }
1.118 jms 8509: }
1.123 jms 8510: my $putresult;
8511: if (keys(%changes) > 0) {
1.166 raeburn 8512: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 8513: if ($putresult eq 'ok') {
1.166 raeburn 8514: $resulttext = &mt('Changes made:').'<ul>';
8515: foreach my $item (sort(keys(%changes))) {
8516: if ($item eq 'submitbugs') {
8517: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
8518: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
8519: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
8520: }
8521: }
8522: $resulttext .= '</ul>';
8523: } else {
8524: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 8525: $errors .= '<li><span class="LC_error">'.
8526: &mt('An error occurred storing the settings: [_1]',
8527: $putresult).'</span></li>';
1.166 raeburn 8528: }
1.118 jms 8529: }
8530: if ($errors) {
1.168 raeburn 8531: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 8532: $errors.'</ul>';
8533: }
8534: return $resulttext;
8535: }
8536:
1.121 raeburn 8537: sub modify_coursedefaults {
1.212 raeburn 8538: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 8539: my ($resulttext,$errors,%changes,%defaultshash);
8540: my %defaultchecked = ('canuse_pdfforms' => 'off');
8541: my @toggles = ('canuse_pdfforms');
1.198 raeburn 8542: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.216 raeburn 8543: 'uploadquota_community','uploadquota_textbook');
8544: my @types = ('official','unofficial','community','textbook');
1.198 raeburn 8545: my %staticdefaults = (
8546: anonsurvey_threshold => 10,
8547: uploadquota => 500,
8548: );
1.121 raeburn 8549:
8550: $defaultshash{'coursedefaults'} = {};
8551:
8552: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
8553: if ($domconfig{'coursedefaults'} eq '') {
8554: $domconfig{'coursedefaults'} = {};
8555: }
8556: }
8557:
8558: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
8559: foreach my $item (@toggles) {
8560: if ($defaultchecked{$item} eq 'on') {
8561: if (($domconfig{'coursedefaults'}{$item} eq '') &&
8562: ($env{'form.'.$item} eq '0')) {
8563: $changes{$item} = 1;
1.192 raeburn 8564: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 8565: $changes{$item} = 1;
8566: }
8567: } elsif ($defaultchecked{$item} eq 'off') {
8568: if (($domconfig{'coursedefaults'}{$item} eq '') &&
8569: ($env{'form.'.$item} eq '1')) {
8570: $changes{$item} = 1;
8571: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
8572: $changes{$item} = 1;
8573: }
8574: }
8575: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
8576: }
1.198 raeburn 8577: foreach my $item (@numbers) {
8578: my ($currdef,$newdef);
1.208 raeburn 8579: $newdef = $env{'form.'.$item};
1.198 raeburn 8580: if ($item eq 'anonsurvey_threshold') {
8581: $currdef = $domconfig{'coursedefaults'}{$item};
8582: $newdef =~ s/\D//g;
8583: if ($newdef eq '' || $newdef < 1) {
8584: $newdef = 1;
8585: }
8586: $defaultshash{'coursedefaults'}{$item} = $newdef;
8587: } else {
8588: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
8589: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8590: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
8591: }
8592: $newdef =~ s/[^\w.\-]//g;
8593: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
8594: }
8595: if ($currdef ne $newdef) {
8596: my $staticdef;
8597: if ($item eq 'anonsurvey_threshold') {
8598: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
8599: $changes{$item} = 1;
8600: }
8601: } else {
8602: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
8603: $changes{'uploadquota'} = 1;
8604: }
8605: }
1.139 raeburn 8606: }
8607: }
1.192 raeburn 8608: my $officialcreds = $env{'form.official_credits'};
1.216 raeburn 8609: $officialcreds =~ s/[^\d.]+//g;
1.192 raeburn 8610: my $unofficialcreds = $env{'form.unofficial_credits'};
1.216 raeburn 8611: $unofficialcreds =~ s/[^\d.]+//g;
8612: my $textbookcreds = $env{'form.textbook_credits'};
8613: $textbookcreds =~ s/[^\d.]+//g;
1.192 raeburn 8614: if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
8615: ($env{'form.coursecredits'} eq '1')) {
8616: $changes{'coursecredits'} = 1;
8617: } else {
8618: if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
1.216 raeburn 8619: ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds) ||
8620: ($domconfig{'coursedefaults'}{'coursecredits'}{'textbook'} ne $textbookcreds)) {
1.192 raeburn 8621: $changes{'coursecredits'} = 1;
8622: }
8623: }
8624: $defaultshash{'coursedefaults'}{'coursecredits'} = {
8625: official => $officialcreds,
8626: unofficial => $unofficialcreds,
1.216 raeburn 8627: textbook => $textbookcreds,
1.192 raeburn 8628: }
1.121 raeburn 8629: }
8630: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8631: $dom);
8632: if ($putresult eq 'ok') {
8633: if (keys(%changes) > 0) {
1.213 raeburn 8634: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.198 raeburn 8635: if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) || ($changes{'uploadquota'})) {
1.192 raeburn 8636: if ($changes{'canuse_pdfforms'}) {
8637: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
8638: }
8639: if ($changes{'coursecredits'}) {
8640: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
8641: $domdefaults{'officialcredits'} =
8642: $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
8643: $domdefaults{'unofficialcredits'} =
8644: $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
1.216 raeburn 8645: $domdefaults{'textbookcredits'} =
8646: $domdefaults{'coursedefaults'}{'coursecredits'}{'textbook'};
1.192 raeburn 8647: }
8648: }
1.198 raeburn 8649: if ($changes{'uploadquota'}) {
8650: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8651: foreach my $type (@types) {
8652: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
8653: }
8654: }
8655: }
1.121 raeburn 8656: my $cachetime = 24*60*60;
8657: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 8658: if (ref($lastactref) eq 'HASH') {
8659: $lastactref->{'domdefaults'} = 1;
8660: }
1.121 raeburn 8661: }
8662: $resulttext = &mt('Changes made:').'<ul>';
8663: foreach my $item (sort(keys(%changes))) {
8664: if ($item eq 'canuse_pdfforms') {
8665: if ($env{'form.'.$item} eq '1') {
8666: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
8667: } else {
8668: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
8669: }
1.139 raeburn 8670: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 8671: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 8672: } elsif ($item eq 'uploadquota') {
8673: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8674: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
8675: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
8676: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 8677: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
8678:
1.198 raeburn 8679: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
8680: '</ul>'.
8681: '</li>';
8682: } else {
8683: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
8684: }
1.192 raeburn 8685: } elsif ($item eq 'coursecredits') {
8686: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
8687: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 8688: ($domdefaults{'unofficialcredits'} eq '') &&
8689: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 8690: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
8691: } else {
8692: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
8693: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
8694: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 8695: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 8696: '</ul>'.
8697: '</li>';
8698: }
8699: } else {
8700: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
8701: }
1.140 raeburn 8702: }
1.121 raeburn 8703: }
8704: $resulttext .= '</ul>';
8705: } else {
8706: $resulttext = &mt('No changes made to course defaults');
8707: }
8708: } else {
8709: $resulttext = '<span class="LC_error">'.
8710: &mt('An error occurred: [_1]',$putresult).'</span>';
8711: }
8712: return $resulttext;
8713: }
8714:
1.137 raeburn 8715: sub modify_usersessions {
1.212 raeburn 8716: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 8717: my @hostingtypes = ('version','excludedomain','includedomain');
8718: my @offloadtypes = ('primary','default');
8719: my %types = (
8720: remote => \@hostingtypes,
8721: hosted => \@hostingtypes,
8722: spares => \@offloadtypes,
8723: );
8724: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 8725: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 8726: my (%by_ip,%by_location,@intdoms);
8727: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
8728: my @locations = sort(keys(%by_location));
1.137 raeburn 8729: my (%defaultshash,%changes);
8730: foreach my $prefix (@prefixes) {
8731: $defaultshash{'usersessions'}{$prefix} = {};
8732: }
1.212 raeburn 8733: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 8734: my $resulttext;
1.138 raeburn 8735: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 8736: foreach my $prefix (@prefixes) {
1.145 raeburn 8737: next if ($prefix eq 'spares');
8738: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 8739: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
8740: if ($type eq 'version') {
8741: my $value = $env{'form.'.$prefix.'_'.$type};
8742: my $okvalue;
8743: if ($value ne '') {
8744: if (grep(/^\Q$value\E$/,@lcversions)) {
8745: $okvalue = $value;
8746: }
8747: }
8748: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8749: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
8750: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
8751: if ($inuse == 0) {
8752: $changes{$prefix}{$type} = 1;
8753: } else {
8754: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
8755: $changes{$prefix}{$type} = 1;
8756: }
8757: if ($okvalue ne '') {
8758: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8759: }
8760: }
8761: } else {
8762: if (($inuse == 1) && ($okvalue ne '')) {
8763: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8764: $changes{$prefix}{$type} = 1;
8765: }
8766: }
8767: } else {
8768: if (($inuse == 1) && ($okvalue ne '')) {
8769: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8770: $changes{$prefix}{$type} = 1;
8771: }
8772: }
8773: } else {
8774: if (($inuse == 1) && ($okvalue ne '')) {
8775: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8776: $changes{$prefix}{$type} = 1;
8777: }
8778: }
8779: } else {
8780: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
8781: my @okvals;
8782: foreach my $val (@vals) {
1.138 raeburn 8783: if ($val =~ /:/) {
8784: my @items = split(/:/,$val);
8785: foreach my $item (@items) {
8786: if (ref($by_location{$item}) eq 'ARRAY') {
8787: push(@okvals,$item);
8788: }
8789: }
8790: } else {
8791: if (ref($by_location{$val}) eq 'ARRAY') {
8792: push(@okvals,$val);
8793: }
1.137 raeburn 8794: }
8795: }
8796: @okvals = sort(@okvals);
8797: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8798: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
8799: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8800: if ($inuse == 0) {
8801: $changes{$prefix}{$type} = 1;
8802: } else {
8803: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8804: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
8805: if (@changed > 0) {
8806: $changes{$prefix}{$type} = 1;
8807: }
8808: }
8809: } else {
8810: if ($inuse == 1) {
8811: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8812: $changes{$prefix}{$type} = 1;
8813: }
8814: }
8815: } else {
8816: if ($inuse == 1) {
8817: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8818: $changes{$prefix}{$type} = 1;
8819: }
8820: }
8821: } else {
8822: if ($inuse == 1) {
8823: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8824: $changes{$prefix}{$type} = 1;
8825: }
8826: }
8827: }
8828: }
8829: }
1.145 raeburn 8830:
8831: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 8832: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 8833: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
8834: my $savespares;
8835:
8836: foreach my $lonhost (sort(keys(%servers))) {
8837: my $serverhomeID =
8838: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 8839: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 8840: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
8841: my %spareschg;
8842: foreach my $type (@{$types{'spares'}}) {
8843: my @okspares;
8844: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
8845: foreach my $server (@checked) {
1.152 raeburn 8846: if (&Apache::lonnet::hostname($server) ne '') {
8847: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
8848: unless (grep(/^\Q$server\E$/,@okspares)) {
8849: push(@okspares,$server);
8850: }
1.145 raeburn 8851: }
8852: }
8853: }
8854: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
8855: my $newspare;
1.152 raeburn 8856: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
8857: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 8858: $newspare = $new;
8859: }
8860: }
1.152 raeburn 8861: my @spares;
8862: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
8863: @spares = sort(@okspares,$newspare);
8864: } else {
8865: @spares = sort(@okspares);
8866: }
8867: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 8868: if (ref($spareid{$lonhost}) eq 'HASH') {
8869: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 8870: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 8871: if (@diffs > 0) {
8872: $spareschg{$type} = 1;
8873: }
8874: }
8875: }
8876: }
8877: if (keys(%spareschg) > 0) {
8878: $changes{'spares'}{$lonhost} = \%spareschg;
8879: }
8880: }
8881:
8882: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8883: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
8884: if (ref($changes{'spares'}) eq 'HASH') {
8885: if (keys(%{$changes{'spares'}}) > 0) {
8886: $savespares = 1;
8887: }
8888: }
8889: } else {
8890: $savespares = 1;
8891: }
8892: }
8893:
1.147 raeburn 8894: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
8895: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 8896: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8897: $dom);
8898: if ($putresult eq 'ok') {
8899: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8900: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
8901: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
8902: }
8903: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
8904: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
8905: }
8906: }
8907: my $cachetime = 24*60*60;
8908: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 8909: if (ref($lastactref) eq 'HASH') {
8910: $lastactref->{'domdefaults'} = 1;
8911: }
1.147 raeburn 8912: if (keys(%changes) > 0) {
8913: my %lt = &usersession_titles();
8914: $resulttext = &mt('Changes made:').'<ul>';
8915: foreach my $prefix (@prefixes) {
8916: if (ref($changes{$prefix}) eq 'HASH') {
8917: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
8918: if ($prefix eq 'spares') {
8919: if (ref($changes{$prefix}) eq 'HASH') {
8920: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
8921: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 8922: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 8923: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
8924: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 8925: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
8926: foreach my $type (@{$types{$prefix}}) {
8927: if ($changes{$prefix}{$lonhost}{$type}) {
8928: my $offloadto = &mt('None');
8929: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
8930: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
8931: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
8932: }
1.145 raeburn 8933: }
1.147 raeburn 8934: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 8935: }
1.137 raeburn 8936: }
8937: }
1.147 raeburn 8938: $resulttext .= '</li>';
1.137 raeburn 8939: }
8940: }
1.147 raeburn 8941: } else {
8942: foreach my $type (@{$types{$prefix}}) {
8943: if (defined($changes{$prefix}{$type})) {
8944: my $newvalue;
8945: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8946: if (ref($defaultshash{'usersessions'}{$prefix})) {
8947: if ($type eq 'version') {
8948: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
8949: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8950: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
8951: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
8952: }
1.145 raeburn 8953: }
8954: }
8955: }
1.147 raeburn 8956: if ($newvalue eq '') {
8957: if ($type eq 'version') {
8958: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
8959: } else {
8960: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
8961: }
1.145 raeburn 8962: } else {
1.147 raeburn 8963: if ($type eq 'version') {
8964: $newvalue .= ' '.&mt('(or later)');
8965: }
8966: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 8967: }
1.137 raeburn 8968: }
8969: }
8970: }
1.147 raeburn 8971: $resulttext .= '</ul>';
1.137 raeburn 8972: }
8973: }
1.147 raeburn 8974: $resulttext .= '</ul>';
8975: } else {
8976: $resulttext = $nochgmsg;
1.137 raeburn 8977: }
8978: } else {
8979: $resulttext = '<span class="LC_error">'.
8980: &mt('An error occurred: [_1]',$putresult).'</span>';
8981: }
8982: } else {
1.147 raeburn 8983: $resulttext = $nochgmsg;
1.137 raeburn 8984: }
8985: return $resulttext;
8986: }
8987:
1.150 raeburn 8988: sub modify_loadbalancing {
8989: my ($dom,%domconfig) = @_;
8990: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8991: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8992: my ($othertitle,$usertypes,$types) =
8993: &Apache::loncommon::sorted_inst_types($dom);
8994: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8995: my @sparestypes = ('primary','default');
8996: my %typetitles = &sparestype_titles();
8997: my $resulttext;
1.171 raeburn 8998: my (%currbalancer,%currtargets,%currrules,%existing);
8999: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
9000: %existing = %{$domconfig{'loadbalancing'}};
9001: }
9002: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
9003: \%currtargets,\%currrules);
9004: my ($saveloadbalancing,%defaultshash,%changes);
9005: my ($alltypes,$othertypes,$titles) =
9006: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
9007: my %ruletitles = &offloadtype_text();
9008: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
9009: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
9010: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
9011: if ($balancer eq '') {
9012: next;
9013: }
1.210 raeburn 9014: if (!exists($servers{$balancer})) {
1.171 raeburn 9015: if (exists($currbalancer{$balancer})) {
9016: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 9017: }
1.171 raeburn 9018: next;
9019: }
9020: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
9021: push(@{$changes{'delete'}},$balancer);
9022: next;
9023: }
9024: if (!exists($currbalancer{$balancer})) {
9025: push(@{$changes{'add'}},$balancer);
9026: }
9027: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
9028: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
9029: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
9030: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
9031: $saveloadbalancing = 1;
9032: }
9033: foreach my $sparetype (@sparestypes) {
9034: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
9035: my @offloadto;
9036: foreach my $target (@targets) {
9037: if (($servers{$target}) && ($target ne $balancer)) {
9038: if ($sparetype eq 'default') {
9039: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
9040: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 9041: }
9042: }
1.171 raeburn 9043: unless(grep(/^\Q$target\E$/,@offloadto)) {
9044: push(@offloadto,$target);
9045: }
1.150 raeburn 9046: }
1.171 raeburn 9047: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 9048: }
9049: }
1.171 raeburn 9050: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 9051: foreach my $sparetype (@sparestypes) {
1.171 raeburn 9052: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
9053: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 9054: if (@targetdiffs > 0) {
1.171 raeburn 9055: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 9056: }
1.171 raeburn 9057: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
9058: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
9059: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 9060: }
9061: }
9062: }
9063: } else {
1.171 raeburn 9064: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 9065: foreach my $sparetype (@sparestypes) {
1.171 raeburn 9066: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
9067: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
9068: $changes{'curr'}{$balancer}{'targets'} = 1;
9069: }
1.150 raeburn 9070: }
9071: }
1.210 raeburn 9072: }
1.150 raeburn 9073: }
9074: my $ishomedom;
1.171 raeburn 9075: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
9076: $ishomedom = 1;
1.150 raeburn 9077: }
9078: if (ref($alltypes) eq 'ARRAY') {
9079: foreach my $type (@{$alltypes}) {
9080: my $rule;
1.210 raeburn 9081: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 9082: (!$ishomedom)) {
1.171 raeburn 9083: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
9084: }
9085: if ($rule eq 'specific') {
9086: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 9087: }
1.171 raeburn 9088: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
9089: if (ref($currrules{$balancer}) eq 'HASH') {
9090: if ($rule ne $currrules{$balancer}{$type}) {
9091: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 9092: }
9093: } elsif ($rule ne '') {
1.171 raeburn 9094: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 9095: }
9096: }
9097: }
1.171 raeburn 9098: }
9099: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
9100: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
9101: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
9102: $defaultshash{'loadbalancing'} = {};
9103: }
9104: my $putresult = &Apache::lonnet::put_dom('configuration',
9105: \%defaultshash,$dom);
9106: if ($putresult eq 'ok') {
9107: if (keys(%changes) > 0) {
9108: if (ref($changes{'delete'}) eq 'ARRAY') {
9109: foreach my $balancer (sort(@{$changes{'delete'}})) {
9110: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.211 raeburn 9111: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
9112: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 9113: }
1.171 raeburn 9114: }
9115: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 9116: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 9117: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
9118: }
9119: }
9120: if (ref($changes{'curr'}) eq 'HASH') {
9121: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
9122: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
9123: if ($changes{'curr'}{$balancer}{'targets'}) {
9124: my %offloadstr;
9125: foreach my $sparetype (@sparestypes) {
9126: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
9127: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
9128: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
9129: }
9130: }
1.150 raeburn 9131: }
1.171 raeburn 9132: if (keys(%offloadstr) == 0) {
9133: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 9134: } else {
1.171 raeburn 9135: my $showoffload;
9136: foreach my $sparetype (@sparestypes) {
9137: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
9138: if (defined($offloadstr{$sparetype})) {
9139: $showoffload .= $offloadstr{$sparetype};
9140: } else {
9141: $showoffload .= &mt('None');
9142: }
9143: $showoffload .= (' 'x3);
9144: }
9145: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 9146: }
9147: }
9148: }
1.171 raeburn 9149: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
9150: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
9151: foreach my $type (@{$alltypes}) {
9152: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
9153: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
9154: my $balancetext;
9155: if ($rule eq '') {
9156: $balancetext = $ruletitles{'default'};
1.209 raeburn 9157: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
9158: ($rule eq 'balancer') || ($rule eq 'offloadedto')) {
1.171 raeburn 9159: $balancetext = $ruletitles{$rule};
9160: } else {
9161: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
9162: }
1.210 raeburn 9163: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 9164: }
9165: }
9166: }
9167: }
1.215 raeburn 9168: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
1.211 raeburn 9169: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 9170: }
1.171 raeburn 9171: }
9172: if ($resulttext ne '') {
9173: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 9174: } else {
9175: $resulttext = $nochgmsg;
9176: }
9177: } else {
1.171 raeburn 9178: $resulttext = $nochgmsg;
1.150 raeburn 9179: }
9180: } else {
1.171 raeburn 9181: $resulttext = '<span class="LC_error">'.
9182: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 9183: }
9184: } else {
1.171 raeburn 9185: $resulttext = $nochgmsg;
1.150 raeburn 9186: }
9187: return $resulttext;
9188: }
9189:
1.48 raeburn 9190: sub recurse_check {
9191: my ($chkcats,$categories,$depth,$name) = @_;
9192: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
9193: my $chg = 0;
9194: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
9195: my $category = $chkcats->[$depth]{$name}[$j];
9196: my $item;
9197: if ($category eq '') {
9198: $chg ++;
9199: } else {
9200: my $deeper = $depth + 1;
9201: $item = &escape($category).':'.&escape($name).':'.$depth;
9202: if ($chg) {
9203: $categories->{$item} -= $chg;
9204: }
9205: &recurse_check($chkcats,$categories,$deeper,$category);
9206: $deeper --;
9207: }
9208: }
9209: }
9210: return;
9211: }
9212:
9213: sub recurse_cat_deletes {
9214: my ($item,$coursecategories,$deletions) = @_;
9215: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9216: my $subdepth = $depth + 1;
9217: if (ref($coursecategories) eq 'HASH') {
9218: foreach my $subitem (keys(%{$coursecategories})) {
9219: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
9220: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
9221: delete($coursecategories->{$subitem});
9222: $deletions->{$subitem} = 1;
9223: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 9224: }
1.48 raeburn 9225: }
9226: }
9227: return;
9228: }
9229:
1.125 raeburn 9230: sub get_active_dcs {
9231: my ($dom) = @_;
1.191 raeburn 9232: my $now = time;
9233: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 9234: my %domcoords;
9235: my $numdcs = 0;
9236: foreach my $server (keys(%dompersonnel)) {
9237: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
9238: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.191 raeburn 9239: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 9240: }
9241: }
9242: return %domcoords;
9243: }
9244:
9245: sub active_dc_picker {
1.191 raeburn 9246: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.125 raeburn 9247: my %domcoords = &get_active_dcs($dom);
1.191 raeburn 9248: my @domcoord = keys(%domcoords);
9249: if (keys(%currhash)) {
9250: foreach my $dc (keys(%currhash)) {
9251: unless (exists($domcoords{$dc})) {
9252: push(@domcoord,$dc);
9253: }
9254: }
9255: }
9256: @domcoord = sort(@domcoord);
1.210 raeburn 9257: my $numdcs = scalar(@domcoord);
1.191 raeburn 9258: my $rows = 0;
9259: my $table;
1.125 raeburn 9260: if ($numdcs > 1) {
1.191 raeburn 9261: $table = '<table>';
9262: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 9263: my $rem = $i%($numinrow);
9264: if ($rem == 0) {
9265: if ($i > 0) {
1.191 raeburn 9266: $table .= '</tr>';
1.125 raeburn 9267: }
1.191 raeburn 9268: $table .= '<tr>';
9269: $rows ++;
1.125 raeburn 9270: }
1.191 raeburn 9271: my $check = '';
9272: if ($inputtype eq 'radio') {
9273: if (keys(%currhash) == 0) {
9274: if (!$i) {
9275: $check = ' checked="checked"';
9276: }
9277: } elsif (exists($currhash{$domcoord[$i]})) {
9278: $check = ' checked="checked"';
9279: }
9280: } else {
9281: if (exists($currhash{$domcoord[$i]})) {
9282: $check = ' checked="checked"';
1.125 raeburn 9283: }
9284: }
1.191 raeburn 9285: if ($i == @domcoord - 1) {
1.125 raeburn 9286: my $colsleft = $numinrow - $rem;
9287: if ($colsleft > 1) {
1.191 raeburn 9288: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 9289: } else {
1.191 raeburn 9290: $table .= '<td class="LC_left_item">';
1.125 raeburn 9291: }
9292: } else {
1.191 raeburn 9293: $table .= '<td class="LC_left_item">';
9294: }
9295: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
9296: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
9297: $table .= '<span class="LC_nobreak"><label>'.
9298: '<input type="'.$inputtype.'" name="'.$name.'"'.
9299: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
9300: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 9301: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 9302: }
1.219 raeburn 9303: $table .= '</label></span></td>';
1.191 raeburn 9304: }
9305: $table .= '</tr></table>';
9306: } elsif ($numdcs == 1) {
1.219 raeburn 9307: my ($dcname,$dcdom) = split(':',$domcoord[0]);
9308: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 9309: if ($inputtype eq 'radio') {
1.219 raeburn 9310: $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
9311: if ($user ne $dcname.':'.$dcdom) {
9312: $table .= ' ('.$dcname.':'.$dcdom.')';
9313: }
1.191 raeburn 9314: } else {
9315: my $check;
9316: if (exists($currhash{$domcoord[0]})) {
9317: $check = ' checked="checked"';
1.125 raeburn 9318: }
1.219 raeburn 9319: $table .= '<span class="LC_nobreak"><label>'.
9320: '<input type="checkbox" name="'.$name.'" '.
9321: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
9322: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 9323: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 9324: }
1.220 raeburn 9325: $table .= '</label></span>';
1.191 raeburn 9326: $rows ++;
1.125 raeburn 9327: }
9328: }
1.191 raeburn 9329: return ($numdcs,$table,$rows);
1.125 raeburn 9330: }
9331:
1.137 raeburn 9332: sub usersession_titles {
9333: return &Apache::lonlocal::texthash(
9334: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
9335: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 9336: spares => 'Servers offloaded to, when busy',
1.137 raeburn 9337: version => 'LON-CAPA version requirement',
1.138 raeburn 9338: excludedomain => 'Allow all, but exclude specific domains',
9339: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 9340: primary => 'Primary (checked first)',
1.154 raeburn 9341: default => 'Default',
1.137 raeburn 9342: );
9343: }
9344:
1.152 raeburn 9345: sub id_for_thisdom {
9346: my (%servers) = @_;
9347: my %altids;
9348: foreach my $server (keys(%servers)) {
9349: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
9350: if ($serverhome ne $server) {
9351: $altids{$serverhome} = $server;
9352: }
9353: }
9354: return %altids;
9355: }
9356:
1.150 raeburn 9357: sub count_servers {
9358: my ($currbalancer,%servers) = @_;
9359: my (@spares,$numspares);
9360: foreach my $lonhost (sort(keys(%servers))) {
9361: next if ($currbalancer eq $lonhost);
9362: push(@spares,$lonhost);
9363: }
9364: if ($currbalancer) {
9365: $numspares = scalar(@spares);
9366: } else {
9367: $numspares = scalar(@spares) - 1;
9368: }
9369: return ($numspares,@spares);
9370: }
9371:
9372: sub lonbalance_targets_js {
1.171 raeburn 9373: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 9374: my $select = &mt('Select');
9375: my ($alltargets,$allishome,$allinsttypes,@alltypes);
9376: if (ref($servers) eq 'HASH') {
9377: $alltargets = join("','",sort(keys(%{$servers})));
9378: my @homedoms;
9379: foreach my $server (sort(keys(%{$servers}))) {
9380: if (&Apache::lonnet::host_domain($server) eq $dom) {
9381: push(@homedoms,'1');
9382: } else {
9383: push(@homedoms,'0');
9384: }
9385: }
9386: $allishome = join("','",@homedoms);
9387: }
9388: if (ref($types) eq 'ARRAY') {
9389: if (@{$types} > 0) {
9390: @alltypes = @{$types};
9391: }
9392: }
9393: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
9394: $allinsttypes = join("','",@alltypes);
1.171 raeburn 9395: my (%currbalancer,%currtargets,%currrules,%existing);
9396: if (ref($settings) eq 'HASH') {
9397: %existing = %{$settings};
9398: }
9399: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
9400: \%currtargets,\%currrules);
1.210 raeburn 9401: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 9402: return <<"END";
9403:
9404: <script type="text/javascript">
9405: // <![CDATA[
9406:
1.171 raeburn 9407: currBalancers = new Array('$balancers');
9408:
9409: function toggleTargets(balnum) {
9410: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
9411: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
9412: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
9413: var prevbalancer = prevhostitem.value;
9414: var baltotal = document.getElementById('loadbalancing_total').value;
9415: prevhostitem.value = balancer;
9416: if (prevbalancer != '') {
9417: var prevIdx = currBalancers.indexOf(prevbalancer);
9418: if (prevIdx != -1) {
9419: currBalancers.splice(prevIdx,1);
9420: }
9421: }
1.150 raeburn 9422: if (balancer == '') {
1.171 raeburn 9423: hideSpares(balnum);
1.150 raeburn 9424: } else {
1.171 raeburn 9425: var currIdx = currBalancers.indexOf(balancer);
9426: if (currIdx == -1) {
9427: currBalancers.push(balancer);
9428: }
1.150 raeburn 9429: var homedoms = new Array('$allishome');
1.171 raeburn 9430: var ishomedom = homedoms[lonhostitem.selectedIndex];
9431: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 9432: }
1.171 raeburn 9433: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 9434: return;
9435: }
9436:
1.171 raeburn 9437: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 9438: var alltargets = new Array('$alltargets');
9439: var insttypes = new Array('$allinsttypes');
1.151 raeburn 9440: var offloadtypes = new Array('primary','default');
9441:
1.171 raeburn 9442: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
9443: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 9444:
1.151 raeburn 9445: for (var i=0; i<offloadtypes.length; i++) {
9446: var count = 0;
9447: for (var j=0; j<alltargets.length; j++) {
9448: if (alltargets[j] != balancer) {
1.171 raeburn 9449: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
9450: item.value = alltargets[j];
9451: item.style.textAlign='left';
9452: item.style.textFace='normal';
9453: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
9454: if (currBalancers.indexOf(alltargets[j]) == -1) {
9455: item.disabled = '';
9456: } else {
9457: item.disabled = 'disabled';
9458: item.checked = false;
9459: }
1.151 raeburn 9460: count ++;
9461: }
1.150 raeburn 9462: }
9463: }
1.151 raeburn 9464: for (var k=0; k<insttypes.length; k++) {
9465: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 9466: if (ishomedom == 1) {
1.171 raeburn 9467: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
9468: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 9469: } else {
1.171 raeburn 9470: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
9471: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 9472: }
9473: } else {
1.171 raeburn 9474: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
9475: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 9476: }
1.151 raeburn 9477: if ((insttypes[k] != '_LC_external') &&
9478: ((insttypes[k] != '_LC_internetdom') ||
9479: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 9480: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
9481: item.options.length = 0;
9482: item.options[0] = new Option("","",true,true);
1.210 raeburn 9483: var idx = 0;
1.151 raeburn 9484: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 9485: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
9486: idx ++;
9487: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 9488: }
9489: }
9490: }
9491: }
9492: return;
9493: }
9494:
1.171 raeburn 9495: function hideSpares(balnum) {
1.150 raeburn 9496: var alltargets = new Array('$alltargets');
9497: var insttypes = new Array('$allinsttypes');
9498: var offloadtypes = new Array('primary','default');
9499:
1.171 raeburn 9500: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
9501: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 9502:
9503: var total = alltargets.length - 1;
9504: for (var i=0; i<offloadtypes; i++) {
9505: for (var j=0; j<total; j++) {
1.171 raeburn 9506: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
9507: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
9508: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 9509: }
1.150 raeburn 9510: }
9511: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 9512: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
9513: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 9514: if (insttypes[k] != '_LC_external') {
1.171 raeburn 9515: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
9516: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 9517: }
9518: }
9519: return;
9520: }
9521:
1.171 raeburn 9522: function checkOffloads(item,balnum,type) {
1.150 raeburn 9523: var alltargets = new Array('$alltargets');
9524: var offloadtypes = new Array('primary','default');
9525: if (item.checked) {
9526: var total = alltargets.length - 1;
9527: var other;
9528: if (type == offloadtypes[0]) {
1.151 raeburn 9529: other = offloadtypes[1];
1.150 raeburn 9530: } else {
1.151 raeburn 9531: other = offloadtypes[0];
1.150 raeburn 9532: }
9533: for (var i=0; i<total; i++) {
1.171 raeburn 9534: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 9535: if (server == item.value) {
1.171 raeburn 9536: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
9537: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 9538: }
9539: }
9540: }
9541: }
9542: return;
9543: }
9544:
1.171 raeburn 9545: function singleServerToggle(balnum,type) {
9546: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 9547: if (offloadtoSelIdx == 0) {
1.171 raeburn 9548: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
9549: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 9550:
9551: } else {
1.171 raeburn 9552: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
9553: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 9554: }
9555: return;
9556: }
9557:
1.171 raeburn 9558: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 9559: if (type == '_LC_external') {
1.171 raeburn 9560: return;
1.150 raeburn 9561: }
1.171 raeburn 9562: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 9563: for (var i=0; i<typesRules.length; i++) {
9564: if (formname.elements[typesRules[i]].checked) {
9565: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 9566: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
9567: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 9568: } else {
1.171 raeburn 9569: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
9570: }
9571: }
9572: }
9573: return;
9574: }
9575:
9576: function balancerDeleteChange(balnum) {
9577: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
9578: var baltotal = document.getElementById('loadbalancing_total').value;
9579: var addtarget;
9580: var removetarget;
9581: var action = 'delete';
9582: if (document.getElementById('loadbalancing_delete_'+balnum)) {
9583: var lonhost = hostitem.value;
9584: var currIdx = currBalancers.indexOf(lonhost);
9585: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
9586: if (currIdx != -1) {
9587: currBalancers.splice(currIdx,1);
9588: }
9589: addtarget = lonhost;
9590: } else {
9591: if (currIdx == -1) {
9592: currBalancers.push(lonhost);
9593: }
9594: removetarget = lonhost;
9595: action = 'undelete';
9596: }
9597: balancerChange(balnum,baltotal,action,addtarget,removetarget);
9598: }
9599: return;
9600: }
9601:
9602: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
9603: if (baltotal > 1) {
9604: var offloadtypes = new Array('primary','default');
9605: var alltargets = new Array('$alltargets');
9606: var insttypes = new Array('$allinsttypes');
9607: for (var i=0; i<baltotal; i++) {
9608: if (i != balnum) {
9609: for (var j=0; j<offloadtypes.length; j++) {
9610: var total = alltargets.length - 1;
9611: for (var k=0; k<total; k++) {
9612: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
9613: var server = serveritem.value;
9614: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
9615: if (server == addtarget) {
9616: serveritem.disabled = '';
9617: }
9618: }
9619: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
9620: if (server == removetarget) {
9621: serveritem.disabled = 'disabled';
9622: serveritem.checked = false;
9623: }
9624: }
9625: }
9626: }
9627: for (var j=0; j<insttypes.length; j++) {
9628: if (insttypes[j] != '_LC_external') {
9629: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
9630: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
9631: var currSel = singleserver.selectedIndex;
9632: var currVal = singleserver.options[currSel].value;
9633: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
9634: var numoptions = singleserver.options.length;
9635: var needsnew = 1;
9636: for (var k=0; k<numoptions; k++) {
9637: if (singleserver.options[k] == addtarget) {
9638: needsnew = 0;
9639: break;
9640: }
9641: }
9642: if (needsnew == 1) {
9643: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
9644: }
9645: }
9646: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
9647: singleserver.options.length = 0;
9648: if ((currVal) && (currVal != removetarget)) {
9649: singleserver.options[0] = new Option("","",false,false);
9650: } else {
9651: singleserver.options[0] = new Option("","",true,true);
9652: }
9653: var idx = 0;
9654: for (var m=0; m<alltargets.length; m++) {
9655: if (currBalancers.indexOf(alltargets[m]) == -1) {
9656: idx ++;
9657: if (currVal == alltargets[m]) {
9658: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
9659: } else {
9660: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
9661: }
9662: }
9663: }
9664: }
9665: }
9666: }
9667: }
1.150 raeburn 9668: }
9669: }
9670: }
9671: return;
9672: }
9673:
1.152 raeburn 9674: // ]]>
9675: </script>
9676:
9677: END
9678: }
9679:
9680: sub new_spares_js {
9681: my @sparestypes = ('primary','default');
9682: my $types = join("','",@sparestypes);
9683: my $select = &mt('Select');
9684: return <<"END";
9685:
9686: <script type="text/javascript">
9687: // <![CDATA[
9688:
9689: function updateNewSpares(formname,lonhost) {
9690: var types = new Array('$types');
9691: var include = new Array();
9692: var exclude = new Array();
9693: for (var i=0; i<types.length; i++) {
9694: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
9695: for (var j=0; j<spareboxes.length; j++) {
9696: if (formname.elements[spareboxes[j]].checked) {
9697: exclude.push(formname.elements[spareboxes[j]].value);
9698: } else {
9699: include.push(formname.elements[spareboxes[j]].value);
9700: }
9701: }
9702: }
9703: for (var i=0; i<types.length; i++) {
9704: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
9705: var selIdx = newSpare.selectedIndex;
9706: var currnew = newSpare.options[selIdx].value;
9707: var okSpares = new Array();
9708: for (var j=0; j<newSpare.options.length; j++) {
9709: var possible = newSpare.options[j].value;
9710: if (possible != '') {
9711: if (exclude.indexOf(possible) == -1) {
9712: okSpares.push(possible);
9713: } else {
9714: if (currnew == possible) {
9715: selIdx = 0;
9716: }
9717: }
9718: }
9719: }
9720: for (var k=0; k<include.length; k++) {
9721: if (okSpares.indexOf(include[k]) == -1) {
9722: okSpares.push(include[k]);
9723: }
9724: }
9725: okSpares.sort();
9726: newSpare.options.length = 0;
9727: if (selIdx == 0) {
9728: newSpare.options[0] = new Option("$select","",true,true);
9729: } else {
9730: newSpare.options[0] = new Option("$select","",false,false);
9731: }
9732: for (var m=0; m<okSpares.length; m++) {
9733: var idx = m+1;
9734: var selThis = 0;
9735: if (selIdx != 0) {
9736: if (okSpares[m] == currnew) {
9737: selThis = 1;
9738: }
9739: }
9740: if (selThis == 1) {
9741: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
9742: } else {
9743: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
9744: }
9745: }
9746: }
9747: return;
9748: }
9749:
9750: function checkNewSpares(lonhost,type) {
9751: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
9752: var chosen = newSpare.options[newSpare.selectedIndex].value;
9753: if (chosen != '') {
9754: var othertype;
9755: var othernewSpare;
9756: if (type == 'primary') {
9757: othernewSpare = document.getElementById('newspare_default_'+lonhost);
9758: }
9759: if (type == 'default') {
9760: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
9761: }
9762: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
9763: othernewSpare.selectedIndex = 0;
9764: }
9765: }
9766: return;
9767: }
9768:
9769: // ]]>
9770: </script>
9771:
9772: END
9773:
9774: }
9775:
9776: sub common_domprefs_js {
9777: return <<"END";
9778:
9779: <script type="text/javascript">
9780: // <![CDATA[
9781:
1.150 raeburn 9782: function getIndicesByName(formname,item) {
1.152 raeburn 9783: var group = new Array();
1.150 raeburn 9784: for (var i=0;i<formname.elements.length;i++) {
9785: if (formname.elements[i].name == item) {
1.152 raeburn 9786: group.push(formname.elements[i].id);
1.150 raeburn 9787: }
9788: }
1.152 raeburn 9789: return group;
1.150 raeburn 9790: }
9791:
9792: // ]]>
9793: </script>
9794:
9795: END
1.152 raeburn 9796:
1.150 raeburn 9797: }
9798:
1.165 raeburn 9799: sub recaptcha_js {
9800: my %lt = &captcha_phrases();
9801: return <<"END";
9802:
9803: <script type="text/javascript">
9804: // <![CDATA[
9805:
9806: function updateCaptcha(caller,context) {
9807: var privitem;
9808: var pubitem;
9809: var privtext;
9810: var pubtext;
9811: if (document.getElementById(context+'_recaptchapub')) {
9812: pubitem = document.getElementById(context+'_recaptchapub');
9813: } else {
9814: return;
9815: }
9816: if (document.getElementById(context+'_recaptchapriv')) {
9817: privitem = document.getElementById(context+'_recaptchapriv');
9818: } else {
9819: return;
9820: }
9821: if (document.getElementById(context+'_recaptchapubtxt')) {
9822: pubtext = document.getElementById(context+'_recaptchapubtxt');
9823: } else {
9824: return;
9825: }
9826: if (document.getElementById(context+'_recaptchaprivtxt')) {
9827: privtext = document.getElementById(context+'_recaptchaprivtxt');
9828: } else {
9829: return;
9830: }
9831: if (caller.checked) {
9832: if (caller.value == 'recaptcha') {
9833: pubitem.type = 'text';
9834: privitem.type = 'text';
9835: pubitem.size = '40';
9836: privitem.size = '40';
9837: pubtext.innerHTML = "$lt{'pub'}";
9838: privtext.innerHTML = "$lt{'priv'}";
9839: } else {
9840: pubitem.type = 'hidden';
9841: privitem.type = 'hidden';
9842: pubtext.innerHTML = '';
9843: privtext.innerHTML = '';
9844: }
9845: }
9846: return;
9847: }
9848:
9849: // ]]>
9850: </script>
9851:
9852: END
9853:
9854: }
9855:
1.192 raeburn 9856: sub credits_js {
9857: return <<"END";
9858:
9859: <script type="text/javascript">
9860: // <![CDATA[
9861:
9862: function toggleCredits(domForm) {
9863: if (document.getElementById('credits')) {
9864: creditsitem = document.getElementById('credits');
9865: var creditsLength = domForm.coursecredits.length;
9866: if (creditsLength) {
9867: var currval;
9868: for (var i=0; i<creditsLength; i++) {
9869: if (domForm.coursecredits[i].checked) {
9870: currval = domForm.coursecredits[i].value;
9871: }
9872: }
9873: if (currval == 1) {
9874: creditsitem.style.display = 'block';
9875: } else {
9876: creditsitem.style.display = 'none';
9877: }
9878: }
9879: }
9880: return;
9881: }
9882:
9883: // ]]>
9884: </script>
9885:
9886: END
9887:
9888: }
9889:
1.165 raeburn 9890: sub captcha_phrases {
9891: return &Apache::lonlocal::texthash (
9892: priv => 'Private key',
9893: pub => 'Public key',
9894: original => 'original (CAPTCHA)',
9895: recaptcha => 'successor (ReCAPTCHA)',
9896: notused => 'unused',
9897: );
9898: }
9899:
1.205 raeburn 9900: sub devalidate_remote_domconfs {
1.212 raeburn 9901: my ($dom,$cachekeys) = @_;
9902: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 9903: my %servers = &Apache::lonnet::internet_dom_servers($dom);
9904: my %thismachine;
9905: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.212 raeburn 9906: my @posscached = ('domainconfig','domdefaults');
1.205 raeburn 9907: if (keys(%servers) > 1) {
9908: foreach my $server (keys(%servers)) {
9909: next if ($thismachine{$server});
1.212 raeburn 9910: my @cached;
9911: foreach my $name (@posscached) {
9912: if ($cachekeys->{$name}) {
9913: push(@cached,&escape($name).':'.&escape($dom));
9914: }
9915: }
9916: if (@cached) {
9917: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
9918: }
1.205 raeburn 9919: }
9920: }
9921: return;
9922: }
9923:
1.3 raeburn 9924: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>