Annotation of loncom/interface/domainprefs.pm, revision 1.218
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.218 ! raeburn 4: # $Id: domainprefs.pm,v 1.217 2013/12/24 21:59:36 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.156 raeburn 4549: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69 raeburn 4550: }
4551:
1.49 raeburn 4552: sub coursecategories_javascript {
4553: my ($settings) = @_;
1.57 raeburn 4554: my ($output,$jstext,$cathash);
1.49 raeburn 4555: if (ref($settings) eq 'HASH') {
1.57 raeburn 4556: $cathash = $settings->{'cats'};
4557: }
4558: if (ref($cathash) eq 'HASH') {
1.49 raeburn 4559: my (@cats,@jsarray,%idx);
1.57 raeburn 4560: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 4561: if (@jsarray > 0) {
4562: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
4563: for (my $i=0; $i<@jsarray; $i++) {
4564: if (ref($jsarray[$i]) eq 'ARRAY') {
4565: my $catstr = join('","',@{$jsarray[$i]});
4566: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
4567: }
4568: }
4569: }
4570: } else {
4571: $jstext = ' var categories = Array(1);'."\n".
4572: ' categories[0] = Array("instcode_pos");'."\n";
4573: }
1.120 raeburn 4574: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
4575: my $communities_reserved = &mt('The name: "communities" is a reserved category');
4576: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 4577: $output = <<"ENDSCRIPT";
4578: <script type="text/javascript">
1.109 raeburn 4579: // <![CDATA[
1.49 raeburn 4580: function reorderCats(form,parent,item,idx) {
4581: var changedVal;
4582: $jstext
4583: var newpos = 'addcategory_pos';
4584: var current = new Array;
4585: if (parent == '') {
4586: var has_instcode = 0;
4587: var maxtop = categories[idx].length;
4588: for (var j=0; j<maxtop; j++) {
4589: if (categories[idx][j] == 'instcode::0') {
4590: has_instcode == 1;
4591: }
4592: }
4593: if (has_instcode == 0) {
4594: categories[idx][maxtop] = 'instcode_pos';
4595: }
4596: } else {
4597: newpos += '_'+parent;
4598: }
4599: var maxh = 1 + categories[idx].length;
4600: var current = new Array;
4601: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4602: if (item == newpos) {
4603: changedVal = newitemVal;
4604: } else {
4605: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4606: current[newitemVal] = newpos;
4607: }
4608: for (var i=0; i<categories[idx].length; i++) {
4609: var elementName = categories[idx][i];
4610: if (elementName != item) {
4611: if (form.elements[elementName]) {
4612: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4613: current[currVal] = elementName;
4614: }
4615: }
4616: }
4617: var oldVal;
4618: for (var j=0; j<maxh; j++) {
4619: if (current[j] == undefined) {
4620: oldVal = j;
4621: }
4622: }
4623: if (oldVal < changedVal) {
4624: for (var k=oldVal+1; k<=changedVal ; k++) {
4625: var elementName = current[k];
4626: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4627: }
4628: } else {
4629: for (var k=changedVal; k<oldVal; k++) {
4630: var elementName = current[k];
4631: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4632: }
4633: }
4634: return;
4635: }
1.120 raeburn 4636:
4637: function categoryCheck(form) {
4638: if (form.elements['addcategory_name'].value == 'instcode') {
4639: alert('$instcode_reserved\\n$choose_again');
4640: return false;
4641: }
4642: if (form.elements['addcategory_name'].value == 'communities') {
4643: alert('$communities_reserved\\n$choose_again');
4644: return false;
4645: }
4646: return true;
4647: }
4648:
1.109 raeburn 4649: // ]]>
1.49 raeburn 4650: </script>
4651:
4652: ENDSCRIPT
4653: return $output;
4654: }
4655:
1.48 raeburn 4656: sub initialize_categories {
4657: my ($itemcount) = @_;
1.120 raeburn 4658: my ($datatable,$css_class,$chgstr);
4659: my %default_names = (
4660: instcode => 'Official courses (with institutional codes)',
4661: communities => 'Communities',
4662: );
4663: my $select0 = ' selected="selected"';
4664: my $select1 = '';
4665: foreach my $default ('instcode','communities') {
4666: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4667: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
4668: if ($default eq 'communities') {
4669: $select1 = $select0;
4670: $select0 = '';
4671: }
4672: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4673: .'<select name="'.$default.'_pos">'
4674: .'<option value="0"'.$select0.'>1</option>'
4675: .'<option value="1"'.$select1.'>2</option>'
4676: .'<option value="2">3</option></select> '
4677: .$default_names{$default}
4678: .'</span></td><td><span class="LC_nobreak">'
4679: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4680: .&mt('Display').'</label> <label>'
4681: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 4682: .'</label></span></td></tr>';
1.120 raeburn 4683: $itemcount ++;
4684: }
1.48 raeburn 4685: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 4686: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 4687: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 4688: .'<select name="addcategory_pos"'.$chgstr.'>'
4689: .'<option value="0">1</option>'
4690: .'<option value="1">2</option>'
4691: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 4692: .&mt('Add category').'</td><td>'.&mt('Name:')
4693: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4694: return $datatable;
4695: }
4696:
4697: sub build_category_rows {
1.49 raeburn 4698: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4699: my ($text,$name,$item,$chgstr);
1.48 raeburn 4700: if (ref($cats) eq 'ARRAY') {
4701: my $maxdepth = scalar(@{$cats});
4702: if (ref($cats->[$depth]) eq 'HASH') {
4703: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4704: my $numchildren = @{$cats->[$depth]{$parent}};
4705: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 4706: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 4707: my ($idxnum,$parent_name,$parent_item);
4708: my $higher = $depth - 1;
4709: if ($higher == 0) {
4710: $parent_name = &escape($parent).'::'.$higher;
4711: } else {
4712: if (ref($path) eq 'ARRAY') {
4713: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4714: }
4715: }
4716: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4717: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4718: if ($j < $numchildren) {
1.48 raeburn 4719: $name = $cats->[$depth]{$parent}[$j];
4720: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4721: $idxnum = $idx->{$item};
4722: } else {
4723: $name = $parent_name;
4724: $item = $parent_item;
1.48 raeburn 4725: }
1.49 raeburn 4726: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4727: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4728: for (my $i=0; $i<=$numchildren; $i++) {
4729: my $vpos = $i+1;
4730: my $selstr;
4731: if ($j == $i) {
4732: $selstr = ' selected="selected" ';
4733: }
4734: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4735: }
4736: $text .= '</select> ';
4737: if ($j < $numchildren) {
4738: my $deeper = $depth+1;
4739: $text .= $name.' '
4740: .'<label><input type="checkbox" name="deletecategory" value="'
4741: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4742: if(ref($path) eq 'ARRAY') {
4743: push(@{$path},$name);
1.49 raeburn 4744: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4745: pop(@{$path});
4746: }
4747: } else {
1.59 bisitz 4748: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4749: if ($j == $numchildren) {
4750: $text .= $name;
4751: } else {
4752: $text .= $item;
4753: }
4754: $text .= '" value="" />';
4755: }
4756: $text .= '</td></tr>';
4757: }
4758: $text .= '</table></td>';
4759: } else {
4760: my $higher = $depth-1;
4761: if ($higher == 0) {
4762: $name = &escape($parent).'::'.$higher;
4763: } else {
4764: if (ref($path) eq 'ARRAY') {
4765: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4766: }
4767: }
4768: my $colspan;
4769: if ($parent ne 'instcode') {
4770: $colspan = $maxdepth - $depth - 1;
4771: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4772: }
4773: }
4774: }
4775: }
4776: return $text;
4777: }
4778:
1.33 raeburn 4779: sub modifiable_userdata_row {
1.63 raeburn 4780: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 4781: my $rolename;
1.63 raeburn 4782: if ($context eq 'selfcreate') {
4783: if (ref($usertypes) eq 'HASH') {
4784: $rolename = $usertypes->{$role};
4785: } else {
4786: $rolename = $role;
4787: }
1.33 raeburn 4788: } else {
1.63 raeburn 4789: if ($role eq 'cr') {
4790: $rolename = &mt('Custom role');
4791: } else {
4792: $rolename = &Apache::lonnet::plaintext($role);
4793: }
1.33 raeburn 4794: }
4795: my @fields = ('lastname','firstname','middlename','generation',
4796: 'permanentemail','id');
4797: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4798: my $output;
4799: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4800: $output = '<tr '.$css_class.'>'.
4801: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4802: '<td class="LC_left_item" colspan="2"><table>';
4803: my $rem;
4804: my %checks;
4805: if (ref($settings) eq 'HASH') {
4806: if (ref($settings->{$context}) eq 'HASH') {
4807: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4808: foreach my $field (@fields) {
4809: if ($settings->{$context}->{$role}->{$field}) {
4810: $checks{$field} = ' checked="checked" ';
4811: }
4812: }
4813: }
4814: }
4815: }
4816: for (my $i=0; $i<@fields; $i++) {
4817: my $rem = $i%($numinrow);
4818: if ($rem == 0) {
4819: if ($i > 0) {
4820: $output .= '</tr>';
4821: }
4822: $output .= '<tr>';
4823: }
4824: my $check = ' ';
4825: if (exists($checks{$fields[$i]})) {
4826: $check = $checks{$fields[$i]}
4827: } else {
4828: if ($role eq 'st') {
4829: if (ref($settings) ne 'HASH') {
4830: $check = ' checked="checked" ';
4831: }
4832: }
4833: }
4834: $output .= '<td class="LC_left_item">'.
4835: '<span class="LC_nobreak"><label>'.
4836: '<input type="checkbox" name="canmodify_'.$role.'" '.
4837: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4838: '</label></span></td>';
4839: $rem = @fields%($numinrow);
4840: }
4841: my $colsleft = $numinrow - $rem;
4842: if ($colsleft > 1 ) {
4843: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4844: ' </td>';
4845: } elsif ($colsleft == 1) {
4846: $output .= '<td class="LC_left_item"> </td>';
4847: }
4848: $output .= '</tr></table></td></tr>';
4849: return $output;
4850: }
1.28 raeburn 4851:
1.93 raeburn 4852: sub insttypes_row {
4853: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
4854: my %lt = &Apache::lonlocal::texthash (
4855: cansearch => 'Users allowed to search',
4856: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4857: lockablenames => 'User preference to lock name',
1.93 raeburn 4858: );
4859: my $showdom;
4860: if ($context eq 'cansearch') {
4861: $showdom = ' ('.$dom.')';
4862: }
1.165 raeburn 4863: my $class = 'LC_left_item';
4864: if ($context eq 'statustocreate') {
4865: $class = 'LC_right_item';
4866: }
1.25 raeburn 4867: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 4868: '<td>'.$lt{$context}.$showdom.
1.165 raeburn 4869: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 4870: my $rem;
4871: if (ref($types) eq 'ARRAY') {
4872: for (my $i=0; $i<@{$types}; $i++) {
4873: if (defined($usertypes->{$types->[$i]})) {
4874: my $rem = $i%($numinrow);
4875: if ($rem == 0) {
4876: if ($i > 0) {
4877: $output .= '</tr>';
4878: }
4879: $output .= '<tr>';
1.23 raeburn 4880: }
1.26 raeburn 4881: my $check = ' ';
1.99 raeburn 4882: if (ref($settings) eq 'HASH') {
4883: if (ref($settings->{$context}) eq 'ARRAY') {
4884: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4885: $check = ' checked="checked" ';
4886: }
4887: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4888: $check = ' checked="checked" ';
4889: }
1.23 raeburn 4890: }
1.26 raeburn 4891: $output .= '<td class="LC_left_item">'.
4892: '<span class="LC_nobreak"><label>'.
1.93 raeburn 4893: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 4894: 'value="'.$types->[$i].'"'.$check.'/>'.
4895: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 4896: }
4897: }
1.26 raeburn 4898: $rem = @{$types}%($numinrow);
1.23 raeburn 4899: }
4900: my $colsleft = $numinrow - $rem;
1.131 raeburn 4901: if (($rem == 0) && (@{$types} > 0)) {
4902: $output .= '<tr>';
4903: }
1.23 raeburn 4904: if ($colsleft > 1) {
1.25 raeburn 4905: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 4906: } else {
1.25 raeburn 4907: $output .= '<td class="LC_left_item">';
1.23 raeburn 4908: }
4909: my $defcheck = ' ';
1.99 raeburn 4910: if (ref($settings) eq 'HASH') {
4911: if (ref($settings->{$context}) eq 'ARRAY') {
4912: if (grep(/^default$/,@{$settings->{$context}})) {
4913: $defcheck = ' checked="checked" ';
4914: }
4915: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4916: $defcheck = ' checked="checked" ';
4917: }
1.23 raeburn 4918: }
1.25 raeburn 4919: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 4920: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 4921: 'value="default"'.$defcheck.'/>'.
4922: $othertitle.'</label></span></td>'.
4923: '</tr></table></td></tr>';
4924: return $output;
1.23 raeburn 4925: }
4926:
4927: sub sorted_searchtitles {
4928: my %searchtitles = &Apache::lonlocal::texthash(
4929: 'uname' => 'username',
4930: 'lastname' => 'last name',
4931: 'lastfirst' => 'last name, first name',
4932: );
4933: my @titleorder = ('uname','lastname','lastfirst');
4934: return (\%searchtitles,\@titleorder);
4935: }
4936:
1.25 raeburn 4937: sub sorted_searchtypes {
4938: my %srchtypes_desc = (
4939: exact => 'is exact match',
4940: contains => 'contains ..',
4941: begins => 'begins with ..',
4942: );
4943: my @srchtypeorder = ('exact','begins','contains');
4944: return (\%srchtypes_desc,\@srchtypeorder);
4945: }
4946:
1.3 raeburn 4947: sub usertype_update_row {
4948: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
4949: my $datatable;
4950: my $numinrow = 4;
4951: foreach my $type (@{$types}) {
4952: if (defined($usertypes->{$type})) {
4953: $$rownums ++;
4954: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
4955: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
4956: '</td><td class="LC_left_item"><table>';
4957: for (my $i=0; $i<@{$fields}; $i++) {
4958: my $rem = $i%($numinrow);
4959: if ($rem == 0) {
4960: if ($i > 0) {
4961: $datatable .= '</tr>';
4962: }
4963: $datatable .= '<tr>';
4964: }
4965: my $check = ' ';
1.39 raeburn 4966: if (ref($settings) eq 'HASH') {
4967: if (ref($settings->{'fields'}) eq 'HASH') {
4968: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
4969: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
4970: $check = ' checked="checked" ';
4971: }
1.3 raeburn 4972: }
4973: }
4974: }
4975:
4976: if ($i == @{$fields}-1) {
4977: my $colsleft = $numinrow - $rem;
4978: if ($colsleft > 1) {
4979: $datatable .= '<td colspan="'.$colsleft.'">';
4980: } else {
4981: $datatable .= '<td>';
4982: }
4983: } else {
4984: $datatable .= '<td>';
4985: }
1.8 raeburn 4986: $datatable .= '<span class="LC_nobreak"><label>'.
4987: '<input type="checkbox" name="updateable_'.$type.
4988: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
4989: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 4990: }
4991: $datatable .= '</tr></table></td></tr>';
4992: }
4993: }
4994: return $datatable;
1.1 raeburn 4995: }
4996:
4997: sub modify_login {
1.205 raeburn 4998: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 4999: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
5000: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
5001: %title = ( coursecatalog => 'Display course catalog',
5002: adminmail => 'Display administrator E-mail address',
1.188 raeburn 5003: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 5004: newuser => 'Link for visitors to create a user account',
5005: loginheader => 'Log-in box header');
5006: @offon = ('off','on');
1.112 raeburn 5007: if (ref($domconfig{login}) eq 'HASH') {
5008: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
5009: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
5010: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
5011: }
5012: }
5013: }
1.9 raeburn 5014: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
5015: \%domconfig,\%loginhash);
1.188 raeburn 5016: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5017: foreach my $item (@toggles) {
5018: $loginhash{login}{$item} = $env{'form.'.$item};
5019: }
1.41 raeburn 5020: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 5021: if (ref($colchanges{'login'}) eq 'HASH') {
5022: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
5023: \%loginhash);
5024: }
1.110 raeburn 5025:
1.149 raeburn 5026: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 5027: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 5028: if (keys(%servers) > 1) {
5029: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 5030: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
5031: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
5032: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
5033: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
5034: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
5035: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5036: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5037: $changes{'loginvia'}{$lonhost} = 1;
5038: } else {
5039: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
5040: $changes{'loginvia'}{$lonhost} = 1;
5041: }
5042: } else {
5043: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5044: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5045: $changes{'loginvia'}{$lonhost} = 1;
5046: }
5047: }
5048: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
5049: foreach my $item (@loginvia_attribs) {
5050: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
5051: }
5052: } else {
5053: foreach my $item (@loginvia_attribs) {
5054: my $new = $env{'form.'.$lonhost.'_'.$item};
5055: if (($item eq 'serverpath') && ($new eq 'custom')) {
5056: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
5057: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5058: $new = '/';
5059: }
5060: }
5061: if (($item eq 'custompath') &&
5062: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5063: $new = '';
5064: }
5065: if ($new ne $curr_loginvia{$lonhost}{$item}) {
5066: $changes{'loginvia'}{$lonhost} = 1;
5067: }
5068: if ($item eq 'exempt') {
5069: $new =~ s/^\s+//;
5070: $new =~ s/\s+$//;
5071: my @poss_ips = split(/\s*[,:]\s*/,$new);
5072: my @okips;
5073: foreach my $ip (@poss_ips) {
5074: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
5075: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
5076: push(@okips,$ip);
5077: }
5078: }
5079: }
5080: if (@okips > 0) {
5081: $new = join(',',@okips);
5082: } else {
5083: $new = '';
5084: }
5085: }
5086: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5087: }
5088: }
1.112 raeburn 5089: } else {
1.128 raeburn 5090: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5091: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 5092: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 5093: foreach my $item (@loginvia_attribs) {
5094: my $new = $env{'form.'.$lonhost.'_'.$item};
5095: if (($item eq 'serverpath') && ($new eq 'custom')) {
5096: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5097: $new = '/';
5098: }
5099: }
5100: if (($item eq 'custompath') &&
5101: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5102: $new = '';
5103: }
5104: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5105: }
1.110 raeburn 5106: }
5107: }
5108: }
5109: }
1.119 raeburn 5110:
1.168 raeburn 5111: my $servadm = $r->dir_config('lonAdmEMail');
5112: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
5113: if (ref($domconfig{'login'}) eq 'HASH') {
5114: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
5115: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
5116: if ($lang eq 'nolang') {
5117: push(@currlangs,$lang);
5118: } elsif (defined($langchoices{$lang})) {
5119: push(@currlangs,$lang);
5120: } else {
5121: next;
5122: }
5123: }
5124: }
5125: }
5126: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
5127: if (@currlangs > 0) {
5128: foreach my $lang (@currlangs) {
5129: if (grep(/^\Q$lang\E$/,@delurls)) {
5130: $changes{'helpurl'}{$lang} = 1;
5131: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
5132: $changes{'helpurl'}{$lang} = 1;
5133: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
5134: push(@newlangs,$lang);
5135: } else {
5136: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5137: }
5138: }
5139: }
5140: unless (grep(/^nolang$/,@currlangs)) {
5141: if ($env{'form.loginhelpurl_nolang.filename'}) {
5142: $changes{'helpurl'}{'nolang'} = 1;
5143: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
5144: push(@newlangs,'nolang');
5145: }
5146: }
5147: if ($env{'form.loginhelpurl_add_lang'}) {
5148: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
5149: ($env{'form.loginhelpurl_add_file.filename'})) {
5150: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
5151: $addedfile = $env{'form.loginhelpurl_add_lang'};
5152: }
5153: }
5154: if ((@newlangs > 0) || ($addedfile)) {
5155: my $error;
5156: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
5157: if ($configuserok eq 'ok') {
5158: if ($switchserver) {
5159: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
5160: } elsif ($author_ok eq 'ok') {
5161: my @allnew = @newlangs;
5162: if ($addedfile ne '') {
5163: push(@allnew,$addedfile);
5164: }
5165: foreach my $lang (@allnew) {
5166: my $formelem = 'loginhelpurl_'.$lang;
5167: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
5168: $formelem = 'loginhelpurl_add_file';
5169: }
5170: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
5171: "help/$lang",'','',$newfile{$lang});
5172: if ($result eq 'ok') {
5173: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
5174: $changes{'helpurl'}{$lang} = 1;
5175: } else {
5176: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
5177: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 5178: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 5179: (!grep(/^\Q$lang\E$/,@delurls))) {
5180:
5181: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5182: }
5183: }
5184: }
5185: } else {
5186: $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);
5187: }
5188: } else {
5189: $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);
5190: }
5191: if ($error) {
5192: &Apache::lonnet::logthis($error);
5193: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
5194: }
5195: }
1.169 raeburn 5196: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 5197:
5198: my $defaulthelpfile = '/adm/loginproblems.html';
5199: my $defaulttext = &mt('Default in use');
5200:
1.1 raeburn 5201: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
5202: $dom);
5203: if ($putresult eq 'ok') {
1.188 raeburn 5204: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5205: my %defaultchecked = (
5206: 'coursecatalog' => 'on',
1.188 raeburn 5207: 'helpdesk' => 'on',
1.42 raeburn 5208: 'adminmail' => 'off',
1.43 raeburn 5209: 'newuser' => 'off',
1.42 raeburn 5210: );
1.55 raeburn 5211: if (ref($domconfig{'login'}) eq 'HASH') {
5212: foreach my $item (@toggles) {
5213: if ($defaultchecked{$item} eq 'on') {
5214: if (($domconfig{'login'}{$item} eq '0') &&
5215: ($env{'form.'.$item} eq '1')) {
5216: $changes{$item} = 1;
5217: } elsif (($domconfig{'login'}{$item} eq '' ||
5218: $domconfig{'login'}{$item} eq '1') &&
5219: ($env{'form.'.$item} eq '0')) {
5220: $changes{$item} = 1;
5221: }
5222: } elsif ($defaultchecked{$item} eq 'off') {
5223: if (($domconfig{'login'}{$item} eq '1') &&
5224: ($env{'form.'.$item} eq '0')) {
5225: $changes{$item} = 1;
5226: } elsif (($domconfig{'login'}{$item} eq '' ||
5227: $domconfig{'login'}{$item} eq '0') &&
5228: ($env{'form.'.$item} eq '1')) {
5229: $changes{$item} = 1;
5230: }
1.42 raeburn 5231: }
5232: }
1.41 raeburn 5233: }
1.6 raeburn 5234: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 5235: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 5236: if (ref($lastactref) eq 'HASH') {
5237: $lastactref->{'domainconfig'} = 1;
5238: }
1.1 raeburn 5239: $resulttext = &mt('Changes made:').'<ul>';
5240: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 5241: if ($item eq 'loginvia') {
1.112 raeburn 5242: if (ref($changes{$item}) eq 'HASH') {
5243: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
5244: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 5245: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
5246: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
5247: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
5248: $protocol = 'http' if ($protocol ne 'https');
5249: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
5250:
5251: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
5252: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
5253: } else {
5254: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
5255: }
5256: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
5257: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
5258: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
5259: }
5260: $resulttext .= '</li>';
5261: } else {
5262: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
5263: }
1.112 raeburn 5264: } else {
1.128 raeburn 5265: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 5266: }
5267: }
1.128 raeburn 5268: $resulttext .= '</ul></li>';
1.112 raeburn 5269: }
1.168 raeburn 5270: } elsif ($item eq 'helpurl') {
5271: if (ref($changes{$item}) eq 'HASH') {
5272: foreach my $lang (sort(keys(%{$changes{$item}}))) {
5273: if (grep(/^\Q$lang\E$/,@delurls)) {
5274: my ($chg,$link);
5275: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
5276: if ($lang eq 'nolang') {
5277: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
5278: } else {
5279: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
5280: }
5281: $resulttext .= '<li>'.$chg.'</li>';
5282: } else {
5283: my $chg;
5284: if ($lang eq 'nolang') {
5285: $chg = &mt('custom log-in help file for no preferred language');
5286: } else {
5287: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
5288: }
5289: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
5290: $loginhash{'login'}{'helpurl'}{$lang}.
5291: '?inhibitmenu=yes',$chg,600,500).
5292: '</li>';
5293: }
5294: }
5295: }
1.169 raeburn 5296: } elsif ($item eq 'captcha') {
5297: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 5298: my $chgtxt;
1.169 raeburn 5299: if ($loginhash{'login'}{$item} eq 'notused') {
5300: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
5301: } else {
5302: my %captchas = &captcha_phrases();
5303: if ($captchas{$loginhash{'login'}{$item}}) {
5304: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
5305: } else {
5306: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
5307: }
5308: }
5309: $resulttext .= '<li>'.$chgtxt.'</li>';
5310: }
5311: } elsif ($item eq 'recaptchakeys') {
5312: if (ref($loginhash{'login'}) eq 'HASH') {
5313: my ($privkey,$pubkey);
5314: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
5315: $pubkey = $loginhash{'login'}{$item}{'public'};
5316: $privkey = $loginhash{'login'}{$item}{'private'};
5317: }
5318: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
5319: if (!$pubkey) {
5320: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
5321: } else {
5322: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
5323: }
5324: if (!$privkey) {
5325: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
5326: } else {
5327: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
5328: }
5329: $chgtxt .= '</ul>';
5330: $resulttext .= '<li>'.$chgtxt.'</li>';
5331: }
1.41 raeburn 5332: } else {
5333: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
5334: }
1.1 raeburn 5335: }
1.6 raeburn 5336: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 5337: } else {
5338: $resulttext = &mt('No changes made to log-in page settings');
5339: }
5340: } else {
1.11 albertel 5341: $resulttext = '<span class="LC_error">'.
5342: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5343: }
1.6 raeburn 5344: if ($errors) {
1.9 raeburn 5345: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 5346: $errors.'</ul>';
5347: }
5348: return $resulttext;
5349: }
5350:
5351: sub color_font_choices {
5352: my %choices =
5353: &Apache::lonlocal::texthash (
5354: img => "Header",
5355: bgs => "Background colors",
5356: links => "Link colors",
1.55 raeburn 5357: images => "Images",
1.6 raeburn 5358: font => "Font color",
1.201 raeburn 5359: fontmenu => "Font menu",
1.76 raeburn 5360: pgbg => "Page",
1.6 raeburn 5361: tabbg => "Header",
5362: sidebg => "Border",
5363: link => "Link",
5364: alink => "Active link",
5365: vlink => "Visited link",
5366: );
5367: return %choices;
5368: }
5369:
5370: sub modify_rolecolors {
1.205 raeburn 5371: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 5372: my ($resulttext,%rolehash);
5373: $rolehash{'rolecolors'} = {};
1.55 raeburn 5374: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
5375: if ($domconfig{'rolecolors'} eq '') {
5376: $domconfig{'rolecolors'} = {};
5377: }
5378: }
1.9 raeburn 5379: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 5380: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
5381: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
5382: $dom);
5383: if ($putresult eq 'ok') {
5384: if (keys(%changes) > 0) {
1.41 raeburn 5385: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 5386: if (ref($lastactref) eq 'HASH') {
5387: $lastactref->{'domainconfig'} = 1;
5388: }
1.6 raeburn 5389: $resulttext = &display_colorchgs($dom,\%changes,$roles,
5390: $rolehash{'rolecolors'});
5391: } else {
5392: $resulttext = &mt('No changes made to default color schemes');
5393: }
5394: } else {
1.11 albertel 5395: $resulttext = '<span class="LC_error">'.
5396: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 5397: }
5398: if ($errors) {
5399: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5400: $errors.'</ul>';
5401: }
5402: return $resulttext;
5403: }
5404:
5405: sub modify_colors {
1.9 raeburn 5406: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 5407: my (%changes,%choices);
1.51 raeburn 5408: my @bgs;
1.6 raeburn 5409: my @links = ('link','alink','vlink');
1.41 raeburn 5410: my @logintext;
1.6 raeburn 5411: my @images;
5412: my $servadm = $r->dir_config('lonAdmEMail');
5413: my $errors;
1.200 raeburn 5414: my %defaults;
1.6 raeburn 5415: foreach my $role (@{$roles}) {
5416: if ($role eq 'login') {
1.12 raeburn 5417: %choices = &login_choices();
1.41 raeburn 5418: @logintext = ('textcol','bgcol');
1.12 raeburn 5419: } else {
5420: %choices = &color_font_choices();
5421: }
5422: if ($role eq 'login') {
1.41 raeburn 5423: @images = ('img','logo','domlogo','login');
1.51 raeburn 5424: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 5425: } else {
5426: @images = ('img');
1.200 raeburn 5427: @bgs = ('pgbg','tabbg','sidebg');
5428: }
5429: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
5430: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
5431: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
5432: }
5433: if ($role eq 'login') {
5434: foreach my $item (@logintext) {
5435: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'logintext'}{$item}) {
5436: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5437: }
5438: }
5439: } else {
5440: unless($env{'form.'.$role.'_fontmenu'} eq $defaults{'fontmenu'}) {
5441: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
5442: }
1.6 raeburn 5443: }
1.200 raeburn 5444: foreach my $item (@bgs) {
5445: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'bgs'}{$item} ) {
5446: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5447: }
5448: }
5449: foreach my $item (@links) {
5450: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'links'}{$item}) {
5451: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5452: }
1.6 raeburn 5453: }
1.46 raeburn 5454: my ($configuserok,$author_ok,$switchserver) =
5455: &config_check($dom,$confname,$servadm);
1.9 raeburn 5456: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 5457: if (ref($domconfig->{$role}) ne 'HASH') {
5458: $domconfig->{$role} = {};
5459: }
1.8 raeburn 5460: foreach my $img (@images) {
1.70 raeburn 5461: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
5462: if (defined($env{'form.login_showlogo_'.$img})) {
5463: $confhash->{$role}{'showlogo'}{$img} = 1;
5464: } else {
5465: $confhash->{$role}{'showlogo'}{$img} = 0;
5466: }
5467: }
1.18 albertel 5468: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
5469: && !defined($domconfig->{$role}{$img})
5470: && !$env{'form.'.$role.'_del_'.$img}
5471: && $env{'form.'.$role.'_import_'.$img}) {
5472: # import the old configured image from the .tab setting
5473: # if they haven't provided a new one
5474: $domconfig->{$role}{$img} =
5475: $env{'form.'.$role.'_import_'.$img};
5476: }
1.6 raeburn 5477: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 5478: my $error;
1.6 raeburn 5479: if ($configuserok eq 'ok') {
1.9 raeburn 5480: if ($switchserver) {
1.12 raeburn 5481: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 5482: } else {
5483: if ($author_ok eq 'ok') {
5484: my ($result,$logourl) =
5485: &publishlogo($r,'upload',$role.'_'.$img,
5486: $dom,$confname,$img,$width,$height);
5487: if ($result eq 'ok') {
5488: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 5489: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5490: } else {
1.12 raeburn 5491: $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 5492: }
5493: } else {
1.46 raeburn 5494: $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 5495: }
5496: }
5497: } else {
1.46 raeburn 5498: $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 5499: }
5500: if ($error) {
1.8 raeburn 5501: &Apache::lonnet::logthis($error);
1.11 albertel 5502: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 5503: }
5504: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 5505: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
5506: my $error;
5507: if ($configuserok eq 'ok') {
5508: # is confname an author?
5509: if ($switchserver eq '') {
5510: if ($author_ok eq 'ok') {
5511: my ($result,$logourl) =
5512: &publishlogo($r,'copy',$domconfig->{$role}{$img},
5513: $dom,$confname,$img,$width,$height);
5514: if ($result eq 'ok') {
5515: $confhash->{$role}{$img} = $logourl;
1.18 albertel 5516: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5517: }
5518: }
5519: }
5520: }
1.6 raeburn 5521: }
5522: }
5523: }
5524: if (ref($domconfig) eq 'HASH') {
5525: if (ref($domconfig->{$role}) eq 'HASH') {
5526: foreach my $img (@images) {
5527: if ($domconfig->{$role}{$img} ne '') {
5528: if ($env{'form.'.$role.'_del_'.$img}) {
5529: $confhash->{$role}{$img} = '';
1.12 raeburn 5530: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5531: } else {
1.9 raeburn 5532: if ($confhash->{$role}{$img} eq '') {
5533: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
5534: }
1.6 raeburn 5535: }
5536: } else {
5537: if ($env{'form.'.$role.'_del_'.$img}) {
5538: $confhash->{$role}{$img} = '';
1.12 raeburn 5539: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5540: }
5541: }
1.70 raeburn 5542: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
5543: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
5544: if ($confhash->{$role}{'showlogo'}{$img} ne
5545: $domconfig->{$role}{'showlogo'}{$img}) {
5546: $changes{$role}{'showlogo'}{$img} = 1;
5547: }
5548: } else {
5549: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5550: $changes{$role}{'showlogo'}{$img} = 1;
5551: }
5552: }
5553: }
5554: }
1.6 raeburn 5555: if ($domconfig->{$role}{'font'} ne '') {
5556: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
5557: $changes{$role}{'font'} = 1;
5558: }
5559: } else {
5560: if ($confhash->{$role}{'font'}) {
5561: $changes{$role}{'font'} = 1;
5562: }
5563: }
1.107 raeburn 5564: if ($role ne 'login') {
5565: if ($domconfig->{$role}{'fontmenu'} ne '') {
5566: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
5567: $changes{$role}{'fontmenu'} = 1;
5568: }
5569: } else {
5570: if ($confhash->{$role}{'fontmenu'}) {
5571: $changes{$role}{'fontmenu'} = 1;
5572: }
1.97 tempelho 5573: }
5574: }
1.6 raeburn 5575: foreach my $item (@bgs) {
5576: if ($domconfig->{$role}{$item} ne '') {
5577: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5578: $changes{$role}{'bgs'}{$item} = 1;
5579: }
5580: } else {
5581: if ($confhash->{$role}{$item}) {
5582: $changes{$role}{'bgs'}{$item} = 1;
5583: }
5584: }
5585: }
5586: foreach my $item (@links) {
5587: if ($domconfig->{$role}{$item} ne '') {
5588: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5589: $changes{$role}{'links'}{$item} = 1;
5590: }
5591: } else {
5592: if ($confhash->{$role}{$item}) {
5593: $changes{$role}{'links'}{$item} = 1;
5594: }
5595: }
5596: }
1.41 raeburn 5597: foreach my $item (@logintext) {
5598: if ($domconfig->{$role}{$item} ne '') {
5599: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5600: $changes{$role}{'logintext'}{$item} = 1;
5601: }
5602: } else {
5603: if ($confhash->{$role}{$item}) {
5604: $changes{$role}{'logintext'}{$item} = 1;
5605: }
5606: }
5607: }
1.6 raeburn 5608: } else {
5609: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5610: \@logintext,$confhash,\%changes);
1.6 raeburn 5611: }
5612: } else {
5613: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5614: \@logintext,$confhash,\%changes);
1.6 raeburn 5615: }
5616: }
5617: return ($errors,%changes);
5618: }
5619:
1.46 raeburn 5620: sub config_check {
5621: my ($dom,$confname,$servadm) = @_;
5622: my ($configuserok,$author_ok,$switchserver,%currroles);
5623: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
5624: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
5625: $confname,$servadm);
5626: if ($configuserok eq 'ok') {
5627: $switchserver = &check_switchserver($dom,$confname);
5628: if ($switchserver eq '') {
5629: $author_ok = &check_authorstatus($dom,$confname,%currroles);
5630: }
5631: }
5632: return ($configuserok,$author_ok,$switchserver);
5633: }
5634:
1.6 raeburn 5635: sub default_change_checker {
1.41 raeburn 5636: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 5637: foreach my $item (@{$links}) {
5638: if ($confhash->{$role}{$item}) {
5639: $changes->{$role}{'links'}{$item} = 1;
5640: }
5641: }
5642: foreach my $item (@{$bgs}) {
5643: if ($confhash->{$role}{$item}) {
5644: $changes->{$role}{'bgs'}{$item} = 1;
5645: }
5646: }
1.41 raeburn 5647: foreach my $item (@{$logintext}) {
5648: if ($confhash->{$role}{$item}) {
5649: $changes->{$role}{'logintext'}{$item} = 1;
5650: }
5651: }
1.6 raeburn 5652: foreach my $img (@{$images}) {
5653: if ($env{'form.'.$role.'_del_'.$img}) {
5654: $confhash->{$role}{$img} = '';
1.12 raeburn 5655: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 5656: }
1.70 raeburn 5657: if ($role eq 'login') {
5658: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5659: $changes->{$role}{'showlogo'}{$img} = 1;
5660: }
5661: }
1.6 raeburn 5662: }
5663: if ($confhash->{$role}{'font'}) {
5664: $changes->{$role}{'font'} = 1;
5665: }
1.48 raeburn 5666: }
1.6 raeburn 5667:
5668: sub display_colorchgs {
5669: my ($dom,$changes,$roles,$confhash) = @_;
5670: my (%choices,$resulttext);
5671: if (!grep(/^login$/,@{$roles})) {
5672: $resulttext = &mt('Changes made:').'<br />';
5673: }
5674: foreach my $role (@{$roles}) {
5675: if ($role eq 'login') {
5676: %choices = &login_choices();
5677: } else {
5678: %choices = &color_font_choices();
5679: }
5680: if (ref($changes->{$role}) eq 'HASH') {
5681: if ($role ne 'login') {
5682: $resulttext .= '<h4>'.&mt($role).'</h4>';
5683: }
5684: foreach my $key (sort(keys(%{$changes->{$role}}))) {
5685: if ($role ne 'login') {
5686: $resulttext .= '<ul>';
5687: }
5688: if (ref($changes->{$role}{$key}) eq 'HASH') {
5689: if ($role ne 'login') {
5690: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
5691: }
5692: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 5693: if (($role eq 'login') && ($key eq 'showlogo')) {
5694: if ($confhash->{$role}{$key}{$item}) {
5695: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
5696: } else {
5697: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
5698: }
5699: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 5700: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
5701: } else {
1.12 raeburn 5702: my $newitem = $confhash->{$role}{$item};
5703: if ($key eq 'images') {
5704: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
5705: }
5706: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 5707: }
5708: }
5709: if ($role ne 'login') {
5710: $resulttext .= '</ul></li>';
5711: }
5712: } else {
5713: if ($confhash->{$role}{$key} eq '') {
5714: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
5715: } else {
5716: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
5717: }
5718: }
5719: if ($role ne 'login') {
5720: $resulttext .= '</ul>';
5721: }
5722: }
5723: }
5724: }
1.3 raeburn 5725: return $resulttext;
1.1 raeburn 5726: }
5727:
1.9 raeburn 5728: sub thumb_dimensions {
5729: return ('200','50');
5730: }
5731:
1.16 raeburn 5732: sub check_dimensions {
5733: my ($inputfile) = @_;
5734: my ($fullwidth,$fullheight);
5735: if ($inputfile =~ m|^[/\w.\-]+$|) {
5736: if (open(PIPE,"identify $inputfile 2>&1 |")) {
5737: my $imageinfo = <PIPE>;
5738: if (!close(PIPE)) {
5739: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
5740: }
5741: chomp($imageinfo);
5742: my ($fullsize) =
1.21 raeburn 5743: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 5744: if ($fullsize) {
5745: ($fullwidth,$fullheight) = split(/x/,$fullsize);
5746: }
5747: }
5748: }
5749: return ($fullwidth,$fullheight);
5750: }
5751:
1.9 raeburn 5752: sub check_configuser {
5753: my ($uhome,$dom,$confname,$servadm) = @_;
5754: my ($configuserok,%currroles);
5755: if ($uhome eq 'no_host') {
5756: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
5757: my $configpass = &LONCAPA::Enrollment::create_password();
5758: $configuserok =
5759: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
5760: $configpass,'','','','','',undef,$servadm);
5761: } else {
5762: $configuserok = 'ok';
5763: %currroles =
5764: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
5765: }
5766: return ($configuserok,%currroles);
5767: }
5768:
5769: sub check_authorstatus {
5770: my ($dom,$confname,%currroles) = @_;
5771: my $author_ok;
1.40 raeburn 5772: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 5773: my $start = time;
5774: my $end = 0;
5775: $author_ok =
5776: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 5777: 'au',$end,$start,'','','domconfig');
1.9 raeburn 5778: } else {
5779: $author_ok = 'ok';
5780: }
5781: return $author_ok;
5782: }
5783:
5784: sub publishlogo {
1.46 raeburn 5785: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 5786: my ($output,$fname,$logourl);
5787: if ($action eq 'upload') {
5788: $fname=$env{'form.'.$formname.'.filename'};
5789: chop($env{'form.'.$formname});
5790: } else {
5791: ($fname) = ($formname =~ /([^\/]+)$/);
5792: }
1.46 raeburn 5793: if ($savefileas ne '') {
5794: $fname = $savefileas;
5795: }
1.9 raeburn 5796: $fname=&Apache::lonnet::clean_filename($fname);
5797: # See if there is anything left
5798: unless ($fname) { return ('error: no uploaded file'); }
5799: $fname="$subdir/$fname";
1.210 raeburn 5800: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 5801: my $filepath="$docroot/priv";
5802: my $relpath = "$dom/$confname";
1.9 raeburn 5803: my ($fnamepath,$file,$fetchthumb);
5804: $file=$fname;
5805: if ($fname=~m|/|) {
5806: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
5807: }
1.164 raeburn 5808: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 5809: my $count;
1.164 raeburn 5810: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 5811: $filepath.="/$parts[$count]";
5812: if ((-e $filepath)!=1) {
5813: mkdir($filepath,02770);
5814: }
5815: }
5816: # Check for bad extension and disallow upload
5817: if ($file=~/\.(\w+)$/ &&
5818: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
5819: $output =
1.207 bisitz 5820: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 5821: } elsif ($file=~/\.(\w+)$/ &&
5822: !defined(&Apache::loncommon::fileembstyle($1))) {
5823: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
5824: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 5825: $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 5826: } elsif (-d "$filepath/$file") {
1.195 bisitz 5827: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 5828: } else {
5829: my $source = $filepath.'/'.$file;
5830: my $logfile;
5831: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 5832: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 5833: }
5834: print $logfile
5835: "\n================= Publish ".localtime()." ================\n".
5836: $env{'user.name'}.':'.$env{'user.domain'}."\n";
5837: # Save the file
5838: if (!open(FH,'>'.$source)) {
5839: &Apache::lonnet::logthis('Failed to create '.$source);
5840: return (&mt('Failed to create file'));
5841: }
5842: if ($action eq 'upload') {
5843: if (!print FH ($env{'form.'.$formname})) {
5844: &Apache::lonnet::logthis('Failed to write to '.$source);
5845: return (&mt('Failed to write file'));
5846: }
5847: } else {
5848: my $original = &Apache::lonnet::filelocation('',$formname);
5849: if(!copy($original,$source)) {
5850: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
5851: return (&mt('Failed to write file'));
5852: }
5853: }
5854: close(FH);
5855: chmod(0660, $source); # Permissions to rw-rw---.
5856:
5857: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
5858: my $copyfile=$targetdir.'/'.$file;
5859:
5860: my @parts=split(/\//,$targetdir);
5861: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
5862: for (my $count=5;$count<=$#parts;$count++) {
5863: $path.="/$parts[$count]";
5864: if (!-e $path) {
5865: print $logfile "\nCreating directory ".$path;
5866: mkdir($path,02770);
5867: }
5868: }
5869: my $versionresult;
5870: if (-e $copyfile) {
5871: $versionresult = &logo_versioning($targetdir,$file,$logfile);
5872: } else {
5873: $versionresult = 'ok';
5874: }
5875: if ($versionresult eq 'ok') {
5876: if (copy($source,$copyfile)) {
5877: print $logfile "\nCopied original source to ".$copyfile."\n";
5878: $output = 'ok';
5879: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 5880: push(@{$modified_urls},[$copyfile,$source]);
5881: my $metaoutput =
5882: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
5883: unless ($registered_cleanup) {
5884: my $handlers = $r->get_handlers('PerlCleanupHandler');
5885: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5886: $registered_cleanup=1;
5887: }
1.9 raeburn 5888: } else {
5889: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
5890: $output = &mt('Failed to copy file to RES space').", $!";
5891: }
5892: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5893: my $inputfile = $filepath.'/'.$file;
5894: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 5895: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5896: if ($fullwidth ne '' && $fullheight ne '') {
5897: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5898: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5899: system("convert -sample $thumbsize $inputfile $outfile");
5900: chmod(0660, $filepath.'/tn-'.$file);
5901: if (-e $outfile) {
5902: my $copyfile=$targetdir.'/tn-'.$file;
5903: if (copy($outfile,$copyfile)) {
5904: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 5905: my $thumb_metaoutput =
5906: &write_metadata($dom,$confname,$formname,
5907: $targetdir,'tn-'.$file,$logfile);
5908: push(@{$modified_urls},[$copyfile,$outfile]);
5909: unless ($registered_cleanup) {
5910: my $handlers = $r->get_handlers('PerlCleanupHandler');
5911: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5912: $registered_cleanup=1;
5913: }
1.16 raeburn 5914: } else {
5915: print $logfile "\nUnable to write ".$copyfile.
5916: ':'.$!."\n";
5917: }
5918: }
1.9 raeburn 5919: }
5920: }
5921: }
5922: } else {
5923: $output = $versionresult;
5924: }
5925: }
5926: return ($output,$logourl);
5927: }
5928:
5929: sub logo_versioning {
5930: my ($targetdir,$file,$logfile) = @_;
5931: my $target = $targetdir.'/'.$file;
5932: my ($maxversion,$fn,$extn,$output);
5933: $maxversion = 0;
5934: if ($file =~ /^(.+)\.(\w+)$/) {
5935: $fn=$1;
5936: $extn=$2;
5937: }
5938: opendir(DIR,$targetdir);
5939: while (my $filename=readdir(DIR)) {
5940: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
5941: $maxversion=($1>$maxversion)?$1:$maxversion;
5942: }
5943: }
5944: $maxversion++;
5945: print $logfile "\nCreating old version ".$maxversion."\n";
5946: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
5947: if (copy($target,$copyfile)) {
5948: print $logfile "Copied old target to ".$copyfile."\n";
5949: $copyfile=$copyfile.'.meta';
5950: if (copy($target.'.meta',$copyfile)) {
5951: print $logfile "Copied old target metadata to ".$copyfile."\n";
5952: $output = 'ok';
5953: } else {
5954: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
5955: $output = &mt('Failed to copy old meta').", $!, ";
5956: }
5957: } else {
5958: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
5959: $output = &mt('Failed to copy old target').", $!, ";
5960: }
5961: return $output;
5962: }
5963:
5964: sub write_metadata {
5965: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
5966: my (%metadatafields,%metadatakeys,$output);
5967: $metadatafields{'title'}=$formname;
5968: $metadatafields{'creationdate'}=time;
5969: $metadatafields{'lastrevisiondate'}=time;
5970: $metadatafields{'copyright'}='public';
5971: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
5972: $env{'user.domain'};
5973: $metadatafields{'authorspace'}=$confname.':'.$dom;
5974: $metadatafields{'domain'}=$dom;
5975: {
5976: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
5977: my $mfh;
1.155 raeburn 5978: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 5979: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 5980: unless ($_=~/\./) {
5981: my $unikey=$_;
5982: $unikey=~/^([A-Za-z]+)/;
5983: my $tag=$1;
5984: $tag=~tr/A-Z/a-z/;
5985: print $mfh "\n\<$tag";
5986: foreach (split(/\,/,$metadatakeys{$unikey})) {
5987: my $value=$metadatafields{$unikey.'.'.$_};
5988: $value=~s/\"/\'\'/g;
5989: print $mfh ' '.$_.'="'.$value.'"';
5990: }
5991: print $mfh '>'.
5992: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
5993: .'</'.$tag.'>';
5994: }
5995: }
5996: $output = 'ok';
5997: print $logfile "\nWrote metadata";
5998: close($mfh);
5999: } else {
6000: print $logfile "\nFailed to open metadata file";
1.9 raeburn 6001: $output = &mt('Could not write metadata');
6002: }
6003: }
1.155 raeburn 6004: return $output;
6005: }
6006:
6007: sub notifysubscribed {
6008: foreach my $targetsource (@{$modified_urls}){
6009: next unless (ref($targetsource) eq 'ARRAY');
6010: my ($target,$source)=@{$targetsource};
6011: if ($source ne '') {
6012: if (open(my $logfh,'>>'.$source.'.log')) {
6013: print $logfh "\nCleanup phase: Notifications\n";
6014: my @subscribed=&subscribed_hosts($target);
6015: foreach my $subhost (@subscribed) {
6016: print $logfh "\nNotifying host ".$subhost.':';
6017: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
6018: print $logfh $reply;
6019: }
6020: my @subscribedmeta=&subscribed_hosts("$target.meta");
6021: foreach my $subhost (@subscribedmeta) {
6022: print $logfh "\nNotifying host for metadata only ".$subhost.':';
6023: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
6024: $subhost);
6025: print $logfh $reply;
6026: }
6027: print $logfh "\n============ Done ============\n";
1.160 raeburn 6028: close($logfh);
1.155 raeburn 6029: }
6030: }
6031: }
6032: return OK;
6033: }
6034:
6035: sub subscribed_hosts {
6036: my ($target) = @_;
6037: my @subscribed;
6038: if (open(my $fh,"<$target.subscription")) {
6039: while (my $subline=<$fh>) {
6040: if ($subline =~ /^($match_lonid):/) {
6041: my $host = $1;
6042: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
6043: unless (grep(/^\Q$host\E$/,@subscribed)) {
6044: push(@subscribed,$host);
6045: }
6046: }
6047: }
6048: }
6049: }
6050: return @subscribed;
1.9 raeburn 6051: }
6052:
6053: sub check_switchserver {
6054: my ($dom,$confname) = @_;
6055: my ($allowed,$switchserver);
6056: my $home = &Apache::lonnet::homeserver($confname,$dom);
6057: if ($home eq 'no_host') {
6058: $home = &Apache::lonnet::domain($dom,'primary');
6059: }
6060: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 6061: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
6062: if (!$allowed) {
1.180 raeburn 6063: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 6064: }
6065: return $switchserver;
6066: }
6067:
1.1 raeburn 6068: sub modify_quotas {
1.216 raeburn 6069: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 6070: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 6071: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
6072: $author_ok,$switchserver,$errors);
1.86 raeburn 6073: if ($action eq 'quotas') {
6074: $context = 'tools';
1.163 raeburn 6075: } else {
1.86 raeburn 6076: $context = $action;
6077: }
6078: if ($context eq 'requestcourses') {
1.216 raeburn 6079: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 6080: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 6081: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
6082: %titles = &courserequest_titles();
6083: $toolregexp = join('|',@usertools);
6084: %conditions = &courserequest_conditions();
1.216 raeburn 6085: $confname = $dom.'-domainconfig';
6086: my $servadm = $r->dir_config('lonAdmEMail');
6087: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.163 raeburn 6088: } elsif ($context eq 'requestauthor') {
6089: @usertools = ('author');
6090: %titles = &authorrequest_titles();
1.86 raeburn 6091: } else {
1.162 raeburn 6092: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 6093: %titles = &tool_titles();
1.86 raeburn 6094: }
1.212 raeburn 6095: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 6096: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6097: foreach my $key (keys(%env)) {
1.101 raeburn 6098: if ($context eq 'requestcourses') {
6099: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
6100: my $item = $1;
6101: my $type = $2;
6102: if ($type =~ /^limit_(.+)/) {
6103: $limithash{$item}{$1} = $env{$key};
6104: } else {
6105: $confhash{$item}{$type} = $env{$key};
6106: }
6107: }
1.163 raeburn 6108: } elsif ($context eq 'requestauthor') {
6109: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
6110: $confhash{$1} = $env{$key};
6111: }
1.101 raeburn 6112: } else {
1.86 raeburn 6113: if ($key =~ /^form\.quota_(.+)$/) {
6114: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 6115: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
6116: $confhash{'authorquota'}{$1} = $env{$key};
6117: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 6118: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
6119: }
1.72 raeburn 6120: }
6121: }
1.163 raeburn 6122: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.102 raeburn 6123: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
6124: @approvalnotify = sort(@approvalnotify);
6125: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.218 ! raeburn 6126: my @crstypes = ('official','unofficial','community','textbook');
! 6127: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
! 6128: foreach my $type (@hasuniquecode) {
! 6129: if (grep(/^\Q$type\E$/,@crstypes)) {
! 6130: $confhash{'uniquecode'}{$type} = 1;
! 6131: }
1.216 raeburn 6132: }
6133: my ($newbook,@allpos);
6134: if ($context eq 'requestcourses') {
6135: if ($env{'form.addbook'}) {
6136: if (($env{'form.addbook_cnum'} =~ /^$match_courseid$/) &&
6137: ($env{'form.addbook_cdom'} =~ /^$match_domain$/)) {
6138: if (&Apache::lonnet::homeserver($env{'form.addbook_cnum'},
6139: $env{'form.addbook_cdom'}) eq 'no_host') {
6140: $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
6141: '</span></li>';
6142: } else {
6143: $newbook = $env{'form.addbook_cdom'}.'_'.$env{'form.addbook_cnum'};
6144: my $position = $env{'form.addbook_pos'};
6145: $position =~ s/\D+//g;
6146: if ($position ne '') {
6147: $allpos[$position] = $newbook;
6148: }
6149: }
6150: } else {
6151: $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
6152: '</span></li>';
6153: }
6154: }
6155: }
1.102 raeburn 6156: if (ref($domconfig{$action}) eq 'HASH') {
6157: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
6158: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
6159: $changes{'notify'}{'approval'} = 1;
6160: }
6161: } else {
1.144 raeburn 6162: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6163: $changes{'notify'}{'approval'} = 1;
6164: }
6165: }
1.218 ! raeburn 6166: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
! 6167: if (ref($confhash{'uniquecode'}) eq 'HASH') {
! 6168: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
! 6169: unless ($confhash{'uniquecode'}{$crstype}) {
! 6170: $changes{'uniquecode'} = 1;
! 6171: }
! 6172: }
! 6173: unless ($changes{'uniquecode'}) {
! 6174: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
! 6175: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
! 6176: $changes{'uniquecode'} = 1;
! 6177: }
! 6178: }
! 6179: }
! 6180: } else {
! 6181: $changes{'uniquecode'} = 1;
! 6182: }
! 6183: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
! 6184: $changes{'uniquecode'} = 1;
1.216 raeburn 6185: }
6186: if ($context eq 'requestcourses') {
6187: if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
6188: my %deletions;
6189: my @todelete = &Apache::loncommon::get_env_multiple('form.book_del');
6190: if (@todelete) {
6191: map { $deletions{$_} = 1; } @todelete;
6192: }
6193: my %imgdeletions;
6194: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.book_image_del');
6195: if (@todeleteimages) {
6196: map { $imgdeletions{$_} = 1; } @todeleteimages;
6197: }
6198: my $maxnum = $env{'form.book_maxnum'};
6199: for (my $i=0; $i<=$maxnum; $i++) {
6200: my $key = $env{'form.book_id_'.$i};
6201: if (ref($domconfig{$action}{'textbooks'}{$key}) eq 'HASH') {
6202: if ($deletions{$key}) {
6203: if ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
6204: #FIXME need to obsolete item in RES space
6205: }
6206: next;
6207: } else {
6208: my $newpos = $env{'form.'.$key};
6209: $newpos =~ s/\D+//g;
6210: foreach my $item ('subject','title','author') {
6211: $confhash{'textbooks'}{$key}{$item} = $env{'form.book_'.$item.'_'.$i};
6212: if ($domconfig{$action}{'textbooks'}{$key}{$item} ne $confhash{'textbooks'}{$key}{$item}) {
6213: $changes{'textbooks'}{$key} = 1;
6214: }
6215: }
6216: $allpos[$newpos] = $key;
6217: }
6218: if ($imgdeletions{$key}) {
6219: $changes{'textbooks'}{$key} = 1;
6220: #FIXME need to obsolete item in RES space
6221: } elsif ($env{'form.book_image_'.$i.'.filename'}) {
6222: my ($cdom,$cnum) = split(/_/,$key);
6223: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,'book_image_'.$i,
6224: $cdom,$cnum,$configuserok,
6225: $switchserver,$author_ok);
6226: if ($imgurl) {
6227: $confhash{'textbooks'}{$key}{'image'} = $imgurl;
6228: $changes{'textbooks'}{$key} = 1;
6229: }
6230: if ($error) {
6231: &Apache::lonnet::logthis($error);
6232: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6233: }
6234: } elsif ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
6235: $confhash{'textbooks'}{$key}{'image'} =
6236: $domconfig{$action}{'textbooks'}{$key}{'image'};
6237: }
6238: }
6239: }
6240: }
6241: }
1.102 raeburn 6242: } else {
1.144 raeburn 6243: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6244: $changes{'notify'}{'approval'} = 1;
6245: }
1.218 ! raeburn 6246: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 6247: $changes{'uniquecode'} = 1;
6248: }
6249: }
6250: if ($context eq 'requestcourses') {
6251: if ($newbook) {
6252: $changes{'textbooks'}{$newbook} = 1;
6253: foreach my $item ('subject','title','author') {
6254: $env{'form.addbook_'.$item} =~ s/(`)/'/g;
6255: if ($env{'form.addbook_'.$item}) {
6256: $confhash{'textbooks'}{$newbook}{$item} = $env{'form.addbook_'.$item};
6257: }
6258: }
6259: if ($env{'form.addbook_image.filename'} ne '') {
6260: my ($cdom,$cnum) = split(/_/,$newbook);
6261: my ($imageurl,$error) =
6262: &process_textbook_image($r,$dom,$confname,'addbook_image',$cdom,$cnum,$configuserok,
6263: $switchserver,$author_ok);
6264: if ($imageurl) {
6265: $confhash{'textbooks'}{$newbook}{'image'} = $imageurl;
6266: }
6267: if ($error) {
6268: &Apache::lonnet::logthis($error);
6269: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6270: }
6271: }
6272: }
6273: if (@allpos > 0) {
6274: my $idx = 0;
6275: foreach my $item (@allpos) {
6276: if ($item ne '') {
6277: $confhash{'textbooks'}{$item}{'order'} = $idx;
6278: if (ref($domconfig{$action}) eq 'HASH') {
6279: if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
6280: if (ref($domconfig{$action}{'textbooks'}{$item}) eq 'HASH') {
6281: if ($domconfig{$action}{'textbooks'}{$item}{'order'} ne $idx) {
6282: $changes{'textbooks'}{$item} = 1;
6283: }
6284: }
6285: }
6286: }
6287: $idx ++;
6288: }
6289: }
6290: }
1.102 raeburn 6291: }
6292: } else {
1.86 raeburn 6293: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 6294: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 6295: }
1.72 raeburn 6296: foreach my $item (@usertools) {
6297: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 6298: my $unset;
1.101 raeburn 6299: if ($context eq 'requestcourses') {
1.104 raeburn 6300: $unset = '0';
6301: if ($type eq '_LC_adv') {
6302: $unset = '';
6303: }
1.101 raeburn 6304: if ($confhash{$item}{$type} eq 'autolimit') {
6305: $confhash{$item}{$type} .= '=';
6306: unless ($limithash{$item}{$type} =~ /\D/) {
6307: $confhash{$item}{$type} .= $limithash{$item}{$type};
6308: }
6309: }
1.163 raeburn 6310: } elsif ($context eq 'requestauthor') {
6311: $unset = '0';
6312: if ($type eq '_LC_adv') {
6313: $unset = '';
6314: }
1.72 raeburn 6315: } else {
1.101 raeburn 6316: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
6317: $confhash{$item}{$type} = 1;
6318: } else {
6319: $confhash{$item}{$type} = 0;
6320: }
1.72 raeburn 6321: }
1.86 raeburn 6322: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 6323: if ($action eq 'requestauthor') {
6324: if ($domconfig{$action}{$type} ne $confhash{$type}) {
6325: $changes{$type} = 1;
6326: }
6327: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 6328: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
6329: $changes{$item}{$type} = 1;
6330: }
6331: } else {
6332: if ($context eq 'requestcourses') {
1.104 raeburn 6333: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 6334: $changes{$item}{$type} = 1;
6335: }
6336: } else {
6337: if (!$confhash{$item}{$type}) {
6338: $changes{$item}{$type} = 1;
6339: }
6340: }
6341: }
6342: } else {
6343: if ($context eq 'requestcourses') {
1.104 raeburn 6344: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 6345: $changes{$item}{$type} = 1;
6346: }
1.163 raeburn 6347: } elsif ($context eq 'requestauthor') {
6348: if ($confhash{$type} ne $unset) {
6349: $changes{$type} = 1;
6350: }
1.72 raeburn 6351: } else {
6352: if (!$confhash{$item}{$type}) {
6353: $changes{$item}{$type} = 1;
6354: }
6355: }
6356: }
1.1 raeburn 6357: }
6358: }
1.163 raeburn 6359: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 6360: if (ref($domconfig{'quotas'}) eq 'HASH') {
6361: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
6362: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
6363: if (exists($confhash{'defaultquota'}{$key})) {
6364: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
6365: $changes{'defaultquota'}{$key} = 1;
6366: }
6367: } else {
6368: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 6369: }
6370: }
1.86 raeburn 6371: } else {
6372: foreach my $key (keys(%{$domconfig{'quotas'}})) {
6373: if (exists($confhash{'defaultquota'}{$key})) {
6374: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
6375: $changes{'defaultquota'}{$key} = 1;
6376: }
6377: } else {
6378: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 6379: }
1.1 raeburn 6380: }
6381: }
1.197 raeburn 6382: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
6383: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
6384: if (exists($confhash{'authorquota'}{$key})) {
6385: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
6386: $changes{'authorquota'}{$key} = 1;
6387: }
6388: } else {
6389: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
6390: }
6391: }
6392: }
1.1 raeburn 6393: }
1.86 raeburn 6394: if (ref($confhash{'defaultquota'}) eq 'HASH') {
6395: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
6396: if (ref($domconfig{'quotas'}) eq 'HASH') {
6397: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
6398: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
6399: $changes{'defaultquota'}{$key} = 1;
6400: }
6401: } else {
6402: if (!exists($domconfig{'quotas'}{$key})) {
6403: $changes{'defaultquota'}{$key} = 1;
6404: }
1.72 raeburn 6405: }
6406: } else {
1.86 raeburn 6407: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 6408: }
1.1 raeburn 6409: }
6410: }
1.197 raeburn 6411: if (ref($confhash{'authorquota'}) eq 'HASH') {
6412: foreach my $key (keys(%{$confhash{'authorquota'}})) {
6413: if (ref($domconfig{'quotas'}) eq 'HASH') {
6414: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
6415: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
6416: $changes{'authorquota'}{$key} = 1;
6417: }
6418: } else {
6419: $changes{'authorquota'}{$key} = 1;
6420: }
6421: } else {
6422: $changes{'authorquota'}{$key} = 1;
6423: }
6424: }
6425: }
1.1 raeburn 6426: }
1.72 raeburn 6427:
1.163 raeburn 6428: if ($context eq 'requestauthor') {
6429: $domdefaults{'requestauthor'} = \%confhash;
6430: } else {
6431: foreach my $key (keys(%confhash)) {
1.216 raeburn 6432: unless (($context eq 'requestcourses') && ($key eq 'textbooks')) {
6433: $domdefaults{$key} = $confhash{$key};
6434: }
1.163 raeburn 6435: }
1.72 raeburn 6436: }
1.163 raeburn 6437:
1.1 raeburn 6438: my %quotahash = (
1.86 raeburn 6439: $action => { %confhash }
1.1 raeburn 6440: );
6441: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
6442: $dom);
6443: if ($putresult eq 'ok') {
6444: if (keys(%changes) > 0) {
1.72 raeburn 6445: my $cachetime = 24*60*60;
6446: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 6447: if (ref($lastactref) eq 'HASH') {
6448: $lastactref->{'domdefaults'} = 1;
6449: }
1.1 raeburn 6450: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 6451: unless (($context eq 'requestcourses') ||
1.163 raeburn 6452: ($context eq 'requestauthor')) {
1.86 raeburn 6453: if (ref($changes{'defaultquota'}) eq 'HASH') {
6454: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
6455: foreach my $type (@{$types},'default') {
6456: if (defined($changes{'defaultquota'}{$type})) {
6457: my $typetitle = $usertypes->{$type};
6458: if ($type eq 'default') {
6459: $typetitle = $othertitle;
6460: }
1.213 raeburn 6461: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 6462: }
6463: }
1.86 raeburn 6464: $resulttext .= '</ul></li>';
1.72 raeburn 6465: }
1.197 raeburn 6466: if (ref($changes{'authorquota'}) eq 'HASH') {
6467: $resulttext .= '<li>'.&mt('Authoring space default quotas').'<ul>';
6468: foreach my $type (@{$types},'default') {
6469: if (defined($changes{'authorquota'}{$type})) {
6470: my $typetitle = $usertypes->{$type};
6471: if ($type eq 'default') {
6472: $typetitle = $othertitle;
6473: }
1.213 raeburn 6474: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 6475: }
6476: }
6477: $resulttext .= '</ul></li>';
6478: }
1.72 raeburn 6479: }
1.80 raeburn 6480: my %newenv;
1.72 raeburn 6481: foreach my $item (@usertools) {
1.163 raeburn 6482: my (%haschgs,%inconf);
6483: if ($context eq 'requestauthor') {
6484: %haschgs = %changes;
1.210 raeburn 6485: %inconf = %confhash;
1.163 raeburn 6486: } else {
6487: if (ref($changes{$item}) eq 'HASH') {
6488: %haschgs = %{$changes{$item}};
6489: }
6490: if (ref($confhash{$item}) eq 'HASH') {
6491: %inconf = %{$confhash{$item}};
6492: }
6493: }
6494: if (keys(%haschgs) > 0) {
1.80 raeburn 6495: my $newacc =
6496: &Apache::lonnet::usertools_access($env{'user.name'},
6497: $env{'user.domain'},
1.86 raeburn 6498: $item,'reload',$context);
1.210 raeburn 6499: if (($context eq 'requestcourses') ||
1.163 raeburn 6500: ($context eq 'requestauthor')) {
1.108 raeburn 6501: if ($env{'environment.canrequest.'.$item} ne $newacc) {
6502: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 6503: }
6504: } else {
6505: if ($env{'environment.availabletools.'.$item} ne $newacc) {
6506: $newenv{'environment.availabletools.'.$item} = $newacc;
6507: }
1.80 raeburn 6508: }
1.163 raeburn 6509: unless ($context eq 'requestauthor') {
6510: $resulttext .= '<li>'.$titles{$item}.'<ul>';
6511: }
1.72 raeburn 6512: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 6513: if ($haschgs{$type}) {
1.72 raeburn 6514: my $typetitle = $usertypes->{$type};
6515: if ($type eq 'default') {
6516: $typetitle = $othertitle;
6517: } elsif ($type eq '_LC_adv') {
6518: $typetitle = 'LON-CAPA Advanced Users';
6519: }
1.163 raeburn 6520: if ($inconf{$type}) {
1.101 raeburn 6521: if ($context eq 'requestcourses') {
6522: my $cond;
1.163 raeburn 6523: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 6524: if ($1 eq '') {
6525: $cond = &mt('(Automatic processing of any request).');
6526: } else {
6527: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
6528: }
6529: } else {
1.163 raeburn 6530: $cond = $conditions{$inconf{$type}};
1.101 raeburn 6531: }
6532: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 6533: } elsif ($context eq 'requestauthor') {
6534: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
6535: $titles{$inconf{$type}},$typetitle);
6536:
1.101 raeburn 6537: } else {
6538: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
6539: }
1.72 raeburn 6540: } else {
1.104 raeburn 6541: if ($type eq '_LC_adv') {
1.163 raeburn 6542: if ($inconf{$type} eq '0') {
1.104 raeburn 6543: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6544: } else {
6545: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
6546: }
6547: } else {
6548: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6549: }
1.72 raeburn 6550: }
6551: }
1.26 raeburn 6552: }
1.163 raeburn 6553: unless ($context eq 'requestauthor') {
6554: $resulttext .= '</ul></li>';
6555: }
1.26 raeburn 6556: }
1.1 raeburn 6557: }
1.163 raeburn 6558: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 6559: if (ref($changes{'notify'}) eq 'HASH') {
6560: if ($changes{'notify'}{'approval'}) {
6561: if (ref($confhash{'notify'}) eq 'HASH') {
6562: if ($confhash{'notify'}{'approval'}) {
6563: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
6564: } else {
1.163 raeburn 6565: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 6566: }
6567: }
6568: }
6569: }
6570: }
1.216 raeburn 6571: if ($action eq 'requestcourses') {
6572: my @offon = ('off','on');
6573: if ($changes{'uniquecode'}) {
1.218 ! raeburn 6574: if (ref($confhash{'uniquecode'}) eq 'HASH') {
! 6575: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
! 6576: $resulttext .= '<li>'.
! 6577: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
! 6578: '</li>';
! 6579: } else {
! 6580: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
! 6581: '</li>';
! 6582: }
1.216 raeburn 6583: }
6584: if (ref($changes{'textbooks'}) eq 'HASH') {
6585: $resulttext .= '<li>'.&mt('Available textbooks updated').'<ul>';
6586: foreach my $key (sort(keys(%{$changes{'textbooks'}}))) {
6587: my %coursehash = &Apache::lonnet::coursedescription($key);
6588: my $coursetitle = $coursehash{'description'};
6589: my $position = $confhash{'textbooks'}{$key}{'order'} + 1;
6590: $resulttext .= '<li>';
6591: foreach my $item ('subject','title','author') {
6592: my $name = $item.':';
6593: $name =~ s/^(\w)/\U$1/;
6594: $resulttext .= &mt($name).' '.$confhash{'textbooks'}{$key}{$item}.'<br />';
6595: }
6596: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
6597: if ($confhash{'textbooks'}{$key}{'image'}) {
6598: $resulttext .= ' '.&mt('Image: [_1]',
6599: '<img src="'.$confhash{'textbooks'}{$key}{'image'}.'"'.
6600: ' alt="Textbook cover" />').'<br />';
6601: }
6602: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
6603: }
6604: $resulttext .= '</ul></li>';
6605: }
6606: }
1.1 raeburn 6607: $resulttext .= '</ul>';
1.80 raeburn 6608: if (keys(%newenv)) {
6609: &Apache::lonnet::appenv(\%newenv);
6610: }
1.1 raeburn 6611: } else {
1.86 raeburn 6612: if ($context eq 'requestcourses') {
6613: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 6614: } elsif ($context eq 'requestauthor') {
6615: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 6616: } else {
1.90 weissno 6617: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 6618: }
1.1 raeburn 6619: }
6620: } else {
1.11 albertel 6621: $resulttext = '<span class="LC_error">'.
6622: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6623: }
1.216 raeburn 6624: if ($errors) {
6625: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
6626: '<ul>'.$errors.'</ul></p>';
6627: }
1.3 raeburn 6628: return $resulttext;
1.1 raeburn 6629: }
6630:
1.216 raeburn 6631: sub process_textbook_image {
6632: my ($r,$dom,$confname,$caller,$cdom,$cnum,$configuserok,$switchserver,$author_ok) = @_;
6633: my $filename = $env{'form.'.$caller.'.filename'};
6634: my ($error,$url);
6635: my ($width,$height) = (50,50);
6636: if ($configuserok eq 'ok') {
6637: if ($switchserver) {
6638: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
6639: $switchserver);
6640: } elsif ($author_ok eq 'ok') {
6641: my ($result,$imageurl) =
6642: &publishlogo($r,'upload',$caller,$dom,$confname,
6643: "textbooks/$dom/$cnum/cover",$width,$height);
6644: if ($result eq 'ok') {
6645: $url = $imageurl;
6646: } else {
6647: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
6648: }
6649: } else {
6650: $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);
6651: }
6652: } else {
6653: $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);
6654: }
6655: return ($url,$error);
6656: }
6657:
1.3 raeburn 6658: sub modify_autoenroll {
1.205 raeburn 6659: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 6660: my ($resulttext,%changes);
6661: my %currautoenroll;
6662: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6663: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
6664: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
6665: }
6666: }
6667: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
6668: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 6669: sender => 'Sender for notification messages',
6670: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 6671: my @offon = ('off','on');
1.17 raeburn 6672: my $sender_uname = $env{'form.sender_uname'};
6673: my $sender_domain = $env{'form.sender_domain'};
6674: if ($sender_domain eq '') {
6675: $sender_uname = '';
6676: } elsif ($sender_uname eq '') {
6677: $sender_domain = '';
6678: }
1.129 raeburn 6679: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 6680: my %autoenrollhash = (
1.129 raeburn 6681: autoenroll => { 'run' => $env{'form.autoenroll_run'},
6682: 'sender_uname' => $sender_uname,
6683: 'sender_domain' => $sender_domain,
6684: 'co-owners' => $coowners,
1.1 raeburn 6685: }
6686: );
1.4 raeburn 6687: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
6688: $dom);
1.1 raeburn 6689: if ($putresult eq 'ok') {
6690: if (exists($currautoenroll{'run'})) {
6691: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
6692: $changes{'run'} = 1;
6693: }
6694: } elsif ($autorun) {
6695: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 6696: $changes{'run'} = 1;
1.1 raeburn 6697: }
6698: }
1.17 raeburn 6699: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 6700: $changes{'sender'} = 1;
6701: }
1.17 raeburn 6702: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 6703: $changes{'sender'} = 1;
6704: }
1.129 raeburn 6705: if ($currautoenroll{'co-owners'} ne '') {
6706: if ($currautoenroll{'co-owners'} ne $coowners) {
6707: $changes{'coowners'} = 1;
6708: }
6709: } elsif ($coowners) {
6710: $changes{'coowners'} = 1;
6711: }
1.1 raeburn 6712: if (keys(%changes) > 0) {
6713: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 6714: if ($changes{'run'}) {
1.1 raeburn 6715: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
6716: }
6717: if ($changes{'sender'}) {
1.17 raeburn 6718: if ($sender_uname eq '' || $sender_domain eq '') {
6719: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
6720: } else {
6721: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
6722: }
1.1 raeburn 6723: }
1.129 raeburn 6724: if ($changes{'coowners'}) {
6725: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
6726: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 6727: if (ref($lastactref) eq 'HASH') {
6728: $lastactref->{'domainconfig'} = 1;
6729: }
1.129 raeburn 6730: }
1.1 raeburn 6731: $resulttext .= '</ul>';
6732: } else {
6733: $resulttext = &mt('No changes made to auto-enrollment settings');
6734: }
6735: } else {
1.11 albertel 6736: $resulttext = '<span class="LC_error">'.
6737: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6738: }
1.3 raeburn 6739: return $resulttext;
1.1 raeburn 6740: }
6741:
6742: sub modify_autoupdate {
1.3 raeburn 6743: my ($dom,%domconfig) = @_;
1.1 raeburn 6744: my ($resulttext,%currautoupdate,%fields,%changes);
6745: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
6746: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
6747: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
6748: }
6749: }
6750: my @offon = ('off','on');
6751: my %title = &Apache::lonlocal::texthash (
6752: run => 'Auto-update:',
6753: classlists => 'Updates to user information in classlists?'
6754: );
1.44 raeburn 6755: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6756: my %fieldtitles = &Apache::lonlocal::texthash (
6757: id => 'Student/Employee ID',
1.20 raeburn 6758: permanentemail => 'E-mail address',
1.1 raeburn 6759: lastname => 'Last Name',
6760: firstname => 'First Name',
6761: middlename => 'Middle Name',
1.132 raeburn 6762: generation => 'Generation',
1.1 raeburn 6763: );
1.142 raeburn 6764: $othertitle = &mt('All users');
1.1 raeburn 6765: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 6766: $othertitle = &mt('Other users');
1.1 raeburn 6767: }
6768: foreach my $key (keys(%env)) {
6769: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 6770: my ($usertype,$item) = ($1,$2);
6771: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
6772: if ($usertype eq 'default') {
6773: push(@{$fields{$1}},$2);
6774: } elsif (ref($types) eq 'ARRAY') {
6775: if (grep(/^\Q$usertype\E$/,@{$types})) {
6776: push(@{$fields{$1}},$2);
6777: }
6778: }
6779: }
1.1 raeburn 6780: }
6781: }
1.131 raeburn 6782: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
6783: @lockablenames = sort(@lockablenames);
6784: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
6785: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6786: if (@changed) {
6787: $changes{'lockablenames'} = 1;
6788: }
6789: } else {
6790: if (@lockablenames) {
6791: $changes{'lockablenames'} = 1;
6792: }
6793: }
1.1 raeburn 6794: my %updatehash = (
6795: autoupdate => { run => $env{'form.autoupdate_run'},
6796: classlists => $env{'form.classlists'},
6797: fields => {%fields},
1.131 raeburn 6798: lockablenames => \@lockablenames,
1.1 raeburn 6799: }
6800: );
6801: foreach my $key (keys(%currautoupdate)) {
6802: if (($key eq 'run') || ($key eq 'classlists')) {
6803: if (exists($updatehash{autoupdate}{$key})) {
6804: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
6805: $changes{$key} = 1;
6806: }
6807: }
6808: } elsif ($key eq 'fields') {
6809: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 6810: foreach my $item (@{$types},'default') {
1.1 raeburn 6811: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
6812: my $change = 0;
6813: foreach my $type (@{$currautoupdate{$key}{$item}}) {
6814: if (!exists($fields{$item})) {
6815: $change = 1;
1.132 raeburn 6816: last;
1.1 raeburn 6817: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 6818: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 6819: $change = 1;
1.132 raeburn 6820: last;
1.1 raeburn 6821: }
6822: }
6823: }
6824: if ($change) {
6825: push(@{$changes{$key}},$item);
6826: }
1.26 raeburn 6827: }
1.1 raeburn 6828: }
6829: }
1.131 raeburn 6830: } elsif ($key eq 'lockablenames') {
6831: if (ref($currautoupdate{$key}) eq 'ARRAY') {
6832: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6833: if (@changed) {
6834: $changes{'lockablenames'} = 1;
6835: }
6836: } else {
6837: if (@lockablenames) {
6838: $changes{'lockablenames'} = 1;
6839: }
6840: }
6841: }
6842: }
6843: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
6844: if (@lockablenames) {
6845: $changes{'lockablenames'} = 1;
1.1 raeburn 6846: }
6847: }
1.26 raeburn 6848: foreach my $item (@{$types},'default') {
6849: if (defined($fields{$item})) {
6850: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 6851: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
6852: my $change = 0;
6853: if (ref($fields{$item}) eq 'ARRAY') {
6854: foreach my $type (@{$fields{$item}}) {
6855: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
6856: $change = 1;
6857: last;
6858: }
6859: }
6860: }
6861: if ($change) {
6862: push(@{$changes{'fields'}},$item);
6863: }
6864: } else {
1.26 raeburn 6865: push(@{$changes{'fields'}},$item);
6866: }
6867: } else {
6868: push(@{$changes{'fields'}},$item);
1.1 raeburn 6869: }
6870: }
6871: }
6872: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
6873: $dom);
6874: if ($putresult eq 'ok') {
6875: if (keys(%changes) > 0) {
6876: $resulttext = &mt('Changes made:').'<ul>';
6877: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 6878: if ($key eq 'lockablenames') {
6879: $resulttext .= '<li>';
6880: if (@lockablenames) {
6881: $usertypes->{'default'} = $othertitle;
6882: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
6883: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
6884: } else {
6885: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
6886: }
6887: $resulttext .= '</li>';
6888: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 6889: foreach my $item (@{$changes{$key}}) {
6890: my @newvalues;
6891: foreach my $type (@{$fields{$item}}) {
6892: push(@newvalues,$fieldtitles{$type});
6893: }
1.3 raeburn 6894: my $newvaluestr;
6895: if (@newvalues > 0) {
6896: $newvaluestr = join(', ',@newvalues);
6897: } else {
6898: $newvaluestr = &mt('none');
1.6 raeburn 6899: }
1.1 raeburn 6900: if ($item eq 'default') {
1.26 raeburn 6901: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 6902: } else {
1.26 raeburn 6903: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 6904: }
6905: }
6906: } else {
6907: my $newvalue;
6908: if ($key eq 'run') {
6909: $newvalue = $offon[$env{'form.autoupdate_run'}];
6910: } else {
6911: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 6912: }
1.1 raeburn 6913: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
6914: }
6915: }
6916: $resulttext .= '</ul>';
6917: } else {
1.3 raeburn 6918: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 6919: }
6920: } else {
1.11 albertel 6921: $resulttext = '<span class="LC_error">'.
6922: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6923: }
1.3 raeburn 6924: return $resulttext;
1.1 raeburn 6925: }
6926:
1.125 raeburn 6927: sub modify_autocreate {
6928: my ($dom,%domconfig) = @_;
6929: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
6930: if (ref($domconfig{'autocreate'}) eq 'HASH') {
6931: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
6932: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
6933: }
6934: }
6935: my %title= ( xml => 'Auto-creation of courses in XML course description files',
6936: req => 'Auto-creation of validated requests for official courses',
6937: xmldc => 'Identity of course creator of courses from XML files',
6938: );
6939: my @types = ('xml','req');
6940: foreach my $item (@types) {
6941: $newvals{$item} = $env{'form.autocreate_'.$item};
6942: $newvals{$item} =~ s/\D//g;
6943: $newvals{$item} = 0 if ($newvals{$item} eq '');
6944: }
6945: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
6946: my %domcoords = &get_active_dcs($dom);
6947: unless (exists($domcoords{$newvals{'xmldc'}})) {
6948: $newvals{'xmldc'} = '';
6949: }
6950: %autocreatehash = (
6951: autocreate => { xml => $newvals{'xml'},
6952: req => $newvals{'req'},
6953: }
6954: );
6955: if ($newvals{'xmldc'} ne '') {
6956: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
6957: }
6958: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
6959: $dom);
6960: if ($putresult eq 'ok') {
6961: my @items = @types;
6962: if ($newvals{'xml'}) {
6963: push(@items,'xmldc');
6964: }
6965: foreach my $item (@items) {
6966: if (exists($currautocreate{$item})) {
6967: if ($currautocreate{$item} ne $newvals{$item}) {
6968: $changes{$item} = 1;
6969: }
6970: } elsif ($newvals{$item}) {
6971: $changes{$item} = 1;
6972: }
6973: }
6974: if (keys(%changes) > 0) {
6975: my @offon = ('off','on');
6976: $resulttext = &mt('Changes made:').'<ul>';
6977: foreach my $item (@types) {
6978: if ($changes{$item}) {
6979: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 6980: $resulttext .= '<li>'.
6981: &mt("$title{$item} set to [_1]$newtxt [_2]",
6982: '<b>','</b>').
6983: '</li>';
1.125 raeburn 6984: }
6985: }
6986: if ($changes{'xmldc'}) {
6987: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
6988: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 6989: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 6990: }
6991: $resulttext .= '</ul>';
6992: } else {
6993: $resulttext = &mt('No changes made to auto-creation settings');
6994: }
6995: } else {
6996: $resulttext = '<span class="LC_error">'.
6997: &mt('An error occurred: [_1]',$putresult).'</span>';
6998: }
6999: return $resulttext;
7000: }
7001:
1.23 raeburn 7002: sub modify_directorysrch {
7003: my ($dom,%domconfig) = @_;
7004: my ($resulttext,%changes);
7005: my %currdirsrch;
7006: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
7007: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
7008: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
7009: }
7010: }
7011: my %title = ( available => 'Directory search available',
1.24 raeburn 7012: localonly => 'Other domains can search',
1.23 raeburn 7013: searchby => 'Search types',
7014: searchtypes => 'Search latitude');
7015: my @offon = ('off','on');
1.24 raeburn 7016: my @otherdoms = ('Yes','No');
1.23 raeburn 7017:
1.25 raeburn 7018: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 7019: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
7020: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
7021:
1.44 raeburn 7022: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 7023: if (keys(%{$usertypes}) == 0) {
7024: @cansearch = ('default');
7025: } else {
7026: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
7027: foreach my $type (@{$currdirsrch{'cansearch'}}) {
7028: if (!grep(/^\Q$type\E$/,@cansearch)) {
7029: push(@{$changes{'cansearch'}},$type);
7030: }
1.23 raeburn 7031: }
1.26 raeburn 7032: foreach my $type (@cansearch) {
7033: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
7034: push(@{$changes{'cansearch'}},$type);
7035: }
1.23 raeburn 7036: }
1.26 raeburn 7037: } else {
7038: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 7039: }
7040: }
7041:
7042: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
7043: foreach my $by (@{$currdirsrch{'searchby'}}) {
7044: if (!grep(/^\Q$by\E$/,@searchby)) {
7045: push(@{$changes{'searchby'}},$by);
7046: }
7047: }
7048: foreach my $by (@searchby) {
7049: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
7050: push(@{$changes{'searchby'}},$by);
7051: }
7052: }
7053: } else {
7054: push(@{$changes{'searchby'}},@searchby);
7055: }
1.25 raeburn 7056:
7057: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
7058: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
7059: if (!grep(/^\Q$type\E$/,@searchtypes)) {
7060: push(@{$changes{'searchtypes'}},$type);
7061: }
7062: }
7063: foreach my $type (@searchtypes) {
7064: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
7065: push(@{$changes{'searchtypes'}},$type);
7066: }
7067: }
7068: } else {
7069: if (exists($currdirsrch{'searchtypes'})) {
7070: foreach my $type (@searchtypes) {
7071: if ($type ne $currdirsrch{'searchtypes'}) {
7072: push(@{$changes{'searchtypes'}},$type);
7073: }
7074: }
7075: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
7076: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
7077: }
7078: } else {
7079: push(@{$changes{'searchtypes'}},@searchtypes);
7080: }
7081: }
7082:
1.23 raeburn 7083: my %dirsrch_hash = (
7084: directorysrch => { available => $env{'form.dirsrch_available'},
7085: cansearch => \@cansearch,
1.24 raeburn 7086: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 7087: searchby => \@searchby,
1.25 raeburn 7088: searchtypes => \@searchtypes,
1.23 raeburn 7089: }
7090: );
7091: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
7092: $dom);
7093: if ($putresult eq 'ok') {
7094: if (exists($currdirsrch{'available'})) {
7095: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
7096: $changes{'available'} = 1;
7097: }
7098: } else {
7099: if ($env{'form.dirsrch_available'} eq '1') {
7100: $changes{'available'} = 1;
7101: }
7102: }
1.24 raeburn 7103: if (exists($currdirsrch{'localonly'})) {
7104: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
7105: $changes{'localonly'} = 1;
7106: }
7107: } else {
7108: if ($env{'form.dirsrch_localonly'} eq '1') {
7109: $changes{'localonly'} = 1;
7110: }
7111: }
1.23 raeburn 7112: if (keys(%changes) > 0) {
7113: $resulttext = &mt('Changes made:').'<ul>';
7114: if ($changes{'available'}) {
7115: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
7116: }
1.24 raeburn 7117: if ($changes{'localonly'}) {
7118: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
7119: }
7120:
1.23 raeburn 7121: if (ref($changes{'cansearch'}) eq 'ARRAY') {
7122: my $chgtext;
1.26 raeburn 7123: if (ref($usertypes) eq 'HASH') {
7124: if (keys(%{$usertypes}) > 0) {
7125: foreach my $type (@{$types}) {
7126: if (grep(/^\Q$type\E$/,@cansearch)) {
7127: $chgtext .= $usertypes->{$type}.'; ';
7128: }
7129: }
7130: if (grep(/^default$/,@cansearch)) {
7131: $chgtext .= $othertitle;
7132: } else {
7133: $chgtext =~ s/\; $//;
7134: }
1.210 raeburn 7135: $resulttext .=
1.178 raeburn 7136: '<li>'.
7137: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
7138: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
7139: '</li>';
1.23 raeburn 7140: }
7141: }
7142: }
7143: if (ref($changes{'searchby'}) eq 'ARRAY') {
7144: my ($searchtitles,$titleorder) = &sorted_searchtitles();
7145: my $chgtext;
7146: foreach my $type (@{$titleorder}) {
7147: if (grep(/^\Q$type\E$/,@searchby)) {
7148: if (defined($searchtitles->{$type})) {
7149: $chgtext .= $searchtitles->{$type}.'; ';
7150: }
7151: }
7152: }
7153: $chgtext =~ s/\; $//;
7154: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
7155: }
1.25 raeburn 7156: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
7157: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
7158: my $chgtext;
7159: foreach my $type (@{$srchtypeorder}) {
7160: if (grep(/^\Q$type\E$/,@searchtypes)) {
7161: if (defined($srchtypes_desc->{$type})) {
7162: $chgtext .= $srchtypes_desc->{$type}.'; ';
7163: }
7164: }
7165: }
7166: $chgtext =~ s/\; $//;
1.178 raeburn 7167: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 7168: }
7169: $resulttext .= '</ul>';
7170: } else {
7171: $resulttext = &mt('No changes made to institution directory search settings');
7172: }
7173: } else {
7174: $resulttext = '<span class="LC_error">'.
1.27 raeburn 7175: &mt('An error occurred: [_1]',$putresult).'</span>';
7176: }
7177: return $resulttext;
7178: }
7179:
1.28 raeburn 7180: sub modify_contacts {
1.205 raeburn 7181: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 7182: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
7183: if (ref($domconfig{'contacts'}) eq 'HASH') {
7184: foreach my $key (keys(%{$domconfig{'contacts'}})) {
7185: $currsetting{$key} = $domconfig{'contacts'}{$key};
7186: }
7187: }
1.134 raeburn 7188: my (%others,%to,%bcc);
1.28 raeburn 7189: my @contacts = ('supportemail','adminemail');
1.102 raeburn 7190: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.203 raeburn 7191: 'requestsmail','updatesmail','idconflictsmail');
7192: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 7193: foreach my $type (@mailings) {
7194: @{$newsetting{$type}} =
7195: &Apache::loncommon::get_env_multiple('form.'.$type);
7196: foreach my $item (@contacts) {
7197: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
7198: $contacts_hash{contacts}{$type}{$item} = 1;
7199: } else {
7200: $contacts_hash{contacts}{$type}{$item} = 0;
7201: }
7202: }
7203: $others{$type} = $env{'form.'.$type.'_others'};
7204: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 7205: if ($type eq 'helpdeskmail') {
7206: $bcc{$type} = $env{'form.'.$type.'_bcc'};
7207: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
7208: }
1.28 raeburn 7209: }
7210: foreach my $item (@contacts) {
7211: $to{$item} = $env{'form.'.$item};
7212: $contacts_hash{'contacts'}{$item} = $to{$item};
7213: }
1.203 raeburn 7214: foreach my $item (@toggles) {
7215: if ($env{'form.'.$item} =~ /^(0|1)$/) {
7216: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
7217: }
7218: }
1.28 raeburn 7219: if (keys(%currsetting) > 0) {
7220: foreach my $item (@contacts) {
7221: if ($to{$item} ne $currsetting{$item}) {
7222: $changes{$item} = 1;
7223: }
7224: }
7225: foreach my $type (@mailings) {
7226: foreach my $item (@contacts) {
7227: if (ref($currsetting{$type}) eq 'HASH') {
7228: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
7229: push(@{$changes{$type}},$item);
7230: }
7231: } else {
7232: push(@{$changes{$type}},@{$newsetting{$type}});
7233: }
7234: }
7235: if ($others{$type} ne $currsetting{$type}{'others'}) {
7236: push(@{$changes{$type}},'others');
7237: }
1.134 raeburn 7238: if ($type eq 'helpdeskmail') {
7239: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
7240: push(@{$changes{$type}},'bcc');
7241: }
7242: }
1.28 raeburn 7243: }
7244: } else {
7245: my %default;
7246: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
7247: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
7248: $default{'errormail'} = 'adminemail';
7249: $default{'packagesmail'} = 'adminemail';
7250: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 7251: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 7252: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 7253: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 7254: foreach my $item (@contacts) {
7255: if ($to{$item} ne $default{$item}) {
7256: $changes{$item} = 1;
1.203 raeburn 7257: }
1.28 raeburn 7258: }
7259: foreach my $type (@mailings) {
7260: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
7261:
7262: push(@{$changes{$type}},@{$newsetting{$type}});
7263: }
7264: if ($others{$type} ne '') {
7265: push(@{$changes{$type}},'others');
1.134 raeburn 7266: }
7267: if ($type eq 'helpdeskmail') {
7268: if ($bcc{$type} ne '') {
7269: push(@{$changes{$type}},'bcc');
7270: }
7271: }
1.28 raeburn 7272: }
7273: }
1.203 raeburn 7274: foreach my $item (@toggles) {
7275: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
7276: $changes{$item} = 1;
7277: } elsif ((!$env{'form.'.$item}) &&
7278: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
7279: $changes{$item} = 1;
7280: }
7281: }
1.28 raeburn 7282: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
7283: $dom);
7284: if ($putresult eq 'ok') {
7285: if (keys(%changes) > 0) {
1.205 raeburn 7286: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7287: if (ref($lastactref) eq 'HASH') {
7288: $lastactref->{'domainconfig'} = 1;
7289: }
1.28 raeburn 7290: my ($titles,$short_titles) = &contact_titles();
7291: $resulttext = &mt('Changes made:').'<ul>';
7292: foreach my $item (@contacts) {
7293: if ($changes{$item}) {
7294: $resulttext .= '<li>'.$titles->{$item}.
7295: &mt(' set to: ').
7296: '<span class="LC_cusr_emph">'.
7297: $to{$item}.'</span></li>';
7298: }
7299: }
7300: foreach my $type (@mailings) {
7301: if (ref($changes{$type}) eq 'ARRAY') {
7302: $resulttext .= '<li>'.$titles->{$type}.': ';
7303: my @text;
7304: foreach my $item (@{$newsetting{$type}}) {
7305: push(@text,$short_titles->{$item});
7306: }
7307: if ($others{$type} ne '') {
7308: push(@text,$others{$type});
7309: }
7310: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 7311: join(', ',@text).'</span>';
7312: if ($type eq 'helpdeskmail') {
7313: if ($bcc{$type} ne '') {
7314: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
7315: }
7316: }
7317: $resulttext .= '</li>';
1.28 raeburn 7318: }
7319: }
1.203 raeburn 7320: my @offon = ('off','on');
7321: if ($changes{'reporterrors'}) {
7322: $resulttext .= '<li>'.
7323: &mt('E-mail error reports to [_1] set to "'.
7324: $offon[$env{'form.reporterrors'}].'".',
7325: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
7326: &mt('LON-CAPA core group - MSU'),600,500)).
7327: '</li>';
7328: }
7329: if ($changes{'reportupdates'}) {
7330: $resulttext .= '<li>'.
7331: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
7332: $offon[$env{'form.reportupdates'}].'".',
7333: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
7334: &mt('LON-CAPA core group - MSU'),600,500)).
7335: '</li>';
7336: }
1.28 raeburn 7337: $resulttext .= '</ul>';
7338: } else {
1.34 raeburn 7339: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 7340: }
7341: } else {
7342: $resulttext = '<span class="LC_error">'.
7343: &mt('An error occurred: [_1].',$putresult).'</span>';
7344: }
7345: return $resulttext;
7346: }
7347:
7348: sub modify_usercreation {
1.27 raeburn 7349: my ($dom,%domconfig) = @_;
1.34 raeburn 7350: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 7351: my $warningmsg;
1.27 raeburn 7352: if (ref($domconfig{'usercreation'}) eq 'HASH') {
7353: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
7354: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
7355: }
7356: }
7357: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 7358: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 7359: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 7360: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 7361: foreach my $item(@contexts) {
1.45 raeburn 7362: if ($item eq 'selfcreate') {
1.50 raeburn 7363: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.212 raeburn 7364: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.43 raeburn 7365: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 7366: if (ref($cancreate{$item}) eq 'ARRAY') {
7367: if (grep(/^login$/,@{$cancreate{$item}})) {
7368: $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.');
7369: }
1.43 raeburn 7370: }
7371: }
1.50 raeburn 7372: } else {
7373: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 7374: }
1.34 raeburn 7375: }
1.93 raeburn 7376: my ($othertitle,$usertypes,$types) =
7377: &Apache::loncommon::sorted_inst_types($dom);
7378: if (ref($types) eq 'ARRAY') {
7379: if (@{$types} > 0) {
7380: @{$cancreate{'statustocreate'}} =
7381: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 raeburn 7382: } else {
7383: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 7384: }
7385: push(@contexts,'statustocreate');
7386: }
1.165 raeburn 7387: &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
1.34 raeburn 7388: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
7389: foreach my $item (@contexts) {
1.93 raeburn 7390: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
7391: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 7392: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 raeburn 7393: if (ref($cancreate{$item}) eq 'ARRAY') {
7394: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
7395: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7396: push(@{$changes{'cancreate'}},$item);
7397: }
1.50 raeburn 7398: }
7399: }
7400: }
7401: } else {
7402: if ($curr_usercreation{'cancreate'}{$item} eq '') {
7403: if (@{$cancreate{$item}} > 0) {
7404: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7405: push(@{$changes{'cancreate'}},$item);
7406: }
7407: }
7408: } else {
7409: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
7410: if (@{$cancreate{$item}} < 3) {
7411: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7412: push(@{$changes{'cancreate'}},$item);
7413: }
7414: }
7415: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
7416: if (@{$cancreate{$item}} > 0) {
7417: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7418: push(@{$changes{'cancreate'}},$item);
7419: }
7420: }
7421: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
7422: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7423: push(@{$changes{'cancreate'}},$item);
7424: }
7425: }
7426: }
7427: }
7428: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7429: foreach my $type (@{$cancreate{$item}}) {
7430: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
7431: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
7432: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7433: push(@{$changes{'cancreate'}},$item);
7434: }
7435: }
7436: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
7437: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
7438: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
7439: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7440: push(@{$changes{'cancreate'}},$item);
7441: }
7442: }
7443: }
7444: }
7445: }
7446: } else {
7447: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
7448: push(@{$changes{'cancreate'}},$item);
7449: }
7450: }
1.27 raeburn 7451: }
1.34 raeburn 7452: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
7453: foreach my $item (@contexts) {
1.43 raeburn 7454: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 7455: if ($cancreate{$item} ne 'any') {
7456: push(@{$changes{'cancreate'}},$item);
7457: }
7458: } else {
7459: if ($cancreate{$item} ne 'none') {
7460: push(@{$changes{'cancreate'}},$item);
7461: }
1.27 raeburn 7462: }
7463: }
7464: } else {
1.43 raeburn 7465: foreach my $item (@contexts) {
1.34 raeburn 7466: push(@{$changes{'cancreate'}},$item);
7467: }
1.27 raeburn 7468: }
1.34 raeburn 7469:
1.27 raeburn 7470: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
7471: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
7472: if (!grep(/^\Q$type\E$/,@username_rule)) {
7473: push(@{$changes{'username_rule'}},$type);
7474: }
7475: }
7476: foreach my $type (@username_rule) {
7477: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
7478: push(@{$changes{'username_rule'}},$type);
7479: }
7480: }
7481: } else {
7482: push(@{$changes{'username_rule'}},@username_rule);
7483: }
7484:
1.32 raeburn 7485: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
7486: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
7487: if (!grep(/^\Q$type\E$/,@id_rule)) {
7488: push(@{$changes{'id_rule'}},$type);
7489: }
7490: }
7491: foreach my $type (@id_rule) {
7492: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
7493: push(@{$changes{'id_rule'}},$type);
7494: }
7495: }
7496: } else {
7497: push(@{$changes{'id_rule'}},@id_rule);
7498: }
7499:
1.43 raeburn 7500: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
7501: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
7502: if (!grep(/^\Q$type\E$/,@email_rule)) {
7503: push(@{$changes{'email_rule'}},$type);
7504: }
7505: }
7506: foreach my $type (@email_rule) {
7507: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
7508: push(@{$changes{'email_rule'}},$type);
7509: }
7510: }
7511: } else {
7512: push(@{$changes{'email_rule'}},@email_rule);
7513: }
7514:
7515: my @authen_contexts = ('author','course','domain');
1.28 raeburn 7516: my @authtypes = ('int','krb4','krb5','loc');
7517: my %authhash;
1.43 raeburn 7518: foreach my $item (@authen_contexts) {
1.28 raeburn 7519: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
7520: foreach my $auth (@authtypes) {
7521: if (grep(/^\Q$auth\E$/,@authallowed)) {
7522: $authhash{$item}{$auth} = 1;
7523: } else {
7524: $authhash{$item}{$auth} = 0;
7525: }
7526: }
7527: }
7528: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 7529: foreach my $item (@authen_contexts) {
1.28 raeburn 7530: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
7531: foreach my $auth (@authtypes) {
7532: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
7533: push(@{$changes{'authtypes'}},$item);
7534: last;
7535: }
7536: }
7537: }
7538: }
7539: } else {
1.43 raeburn 7540: foreach my $item (@authen_contexts) {
1.28 raeburn 7541: push(@{$changes{'authtypes'}},$item);
7542: }
7543: }
7544:
1.27 raeburn 7545: my %usercreation_hash = (
1.28 raeburn 7546: usercreation => {
1.34 raeburn 7547: cancreate => \%cancreate,
1.27 raeburn 7548: username_rule => \@username_rule,
1.32 raeburn 7549: id_rule => \@id_rule,
1.43 raeburn 7550: email_rule => \@email_rule,
1.32 raeburn 7551: authtypes => \%authhash,
1.27 raeburn 7552: }
7553: );
7554:
7555: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
7556: $dom);
1.50 raeburn 7557:
7558: my %selfcreatetypes = (
7559: sso => 'users authenticated by institutional single sign on',
7560: login => 'users authenticated by institutional log-in',
7561: email => 'users who provide a valid e-mail address for use as the username',
7562: );
1.27 raeburn 7563: if ($putresult eq 'ok') {
7564: if (keys(%changes) > 0) {
7565: $resulttext = &mt('Changes made:').'<ul>';
7566: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 7567: my %lt = &usercreation_types();
7568: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 7569: my $chgtext;
1.165 raeburn 7570: unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
1.100 raeburn 7571: $chgtext = $lt{$type}.', ';
7572: }
1.45 raeburn 7573: if ($type eq 'selfcreate') {
1.50 raeburn 7574: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 7575: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 7576: } else {
1.100 raeburn 7577: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 7578: foreach my $case (@{$cancreate{$type}}) {
7579: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
7580: }
7581: $chgtext .= '</ul>';
1.100 raeburn 7582: if (ref($cancreate{$type}) eq 'ARRAY') {
7583: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
7584: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
7585: if (@{$cancreate{'statustocreate'}} == 0) {
7586: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
7587: }
7588: }
7589: }
7590: }
1.43 raeburn 7591: }
1.93 raeburn 7592: } elsif ($type eq 'statustocreate') {
1.96 raeburn 7593: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
7594: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
7595: if (@{$cancreate{'selfcreate'}} > 0) {
7596: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 7597:
7598: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 7599: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 7600: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
7601: }
1.96 raeburn 7602: } elsif (ref($usertypes) eq 'HASH') {
7603: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 7604: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
7605: } else {
7606: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
7607: }
7608: $chgtext .= '<ul>';
7609: foreach my $case (@{$cancreate{$type}}) {
7610: if ($case eq 'default') {
7611: $chgtext .= '<li>'.$othertitle.'</li>';
7612: } else {
7613: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 7614: }
7615: }
1.100 raeburn 7616: $chgtext .= '</ul>';
7617: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
7618: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
7619: }
7620: }
7621: } else {
7622: if (@{$cancreate{$type}} == 0) {
7623: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
7624: } else {
7625: $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 7626: }
7627: }
7628: }
1.165 raeburn 7629: } elsif ($type eq 'captcha') {
7630: if ($cancreate{$type} eq 'notused') {
7631: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
7632: } else {
7633: my %captchas = &captcha_phrases();
7634: if ($captchas{$cancreate{$type}}) {
7635: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
7636: } else {
1.210 raeburn 7637: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 7638: }
7639: }
7640: } elsif ($type eq 'recaptchakeys') {
7641: my ($privkey,$pubkey);
7642: if (ref($cancreate{$type}) eq 'HASH') {
7643: $pubkey = $cancreate{$type}{'public'};
7644: $privkey = $cancreate{$type}{'private'};
7645: }
7646: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
7647: if (!$pubkey) {
7648: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
7649: } else {
7650: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7651: }
7652: if (!$privkey) {
7653: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
7654: } else {
7655: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
7656: }
7657: $chgtext .= '</ul>';
1.43 raeburn 7658: } else {
7659: if ($cancreate{$type} eq 'none') {
7660: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
7661: } elsif ($cancreate{$type} eq 'any') {
7662: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
7663: } elsif ($cancreate{$type} eq 'official') {
7664: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
7665: } elsif ($cancreate{$type} eq 'unofficial') {
7666: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
7667: }
1.34 raeburn 7668: }
7669: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 7670: }
7671: }
7672: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 7673: my ($rules,$ruleorder) =
7674: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 7675: my $chgtext = '<ul>';
7676: foreach my $type (@username_rule) {
7677: if (ref($rules->{$type}) eq 'HASH') {
7678: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
7679: }
7680: }
7681: $chgtext .= '</ul>';
7682: if (@username_rule > 0) {
7683: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7684: } else {
1.28 raeburn 7685: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 7686: }
7687: }
1.32 raeburn 7688: if (ref($changes{'id_rule'}) eq 'ARRAY') {
7689: my ($idrules,$idruleorder) =
7690: &Apache::lonnet::inst_userrules($dom,'id');
7691: my $chgtext = '<ul>';
7692: foreach my $type (@id_rule) {
7693: if (ref($idrules->{$type}) eq 'HASH') {
7694: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
7695: }
7696: }
7697: $chgtext .= '</ul>';
7698: if (@id_rule > 0) {
7699: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7700: } else {
7701: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
7702: }
7703: }
1.43 raeburn 7704: if (ref($changes{'email_rule'}) eq 'ARRAY') {
7705: my ($emailrules,$emailruleorder) =
7706: &Apache::lonnet::inst_userrules($dom,'email');
7707: my $chgtext = '<ul>';
7708: foreach my $type (@email_rule) {
7709: if (ref($emailrules->{$type}) eq 'HASH') {
7710: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
7711: }
7712: }
7713: $chgtext .= '</ul>';
7714: if (@email_rule > 0) {
7715: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
7716: } else {
7717: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
7718: }
7719: }
7720:
1.28 raeburn 7721: my %authname = &authtype_names();
7722: my %context_title = &context_names();
7723: if (ref($changes{'authtypes'}) eq 'ARRAY') {
7724: my $chgtext = '<ul>';
7725: foreach my $type (@{$changes{'authtypes'}}) {
7726: my @allowed;
7727: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
7728: foreach my $auth (@authtypes) {
7729: if ($authhash{$type}{$auth}) {
7730: push(@allowed,$authname{$auth});
7731: }
7732: }
1.43 raeburn 7733: if (@allowed > 0) {
7734: $chgtext .= join(', ',@allowed).'</li>';
7735: } else {
7736: $chgtext .= &mt('none').'</li>';
7737: }
1.28 raeburn 7738: }
7739: $chgtext .= '</ul>';
7740: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
7741: $resulttext .= '</li>';
7742: }
1.27 raeburn 7743: $resulttext .= '</ul>';
7744: } else {
1.28 raeburn 7745: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 7746: }
7747: } else {
7748: $resulttext = '<span class="LC_error">'.
1.23 raeburn 7749: &mt('An error occurred: [_1]',$putresult).'</span>';
7750: }
1.43 raeburn 7751: if ($warningmsg ne '') {
7752: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
7753: }
1.23 raeburn 7754: return $resulttext;
7755: }
7756:
1.165 raeburn 7757: sub process_captcha {
7758: my ($container,$changes,$newsettings,$current) = @_;
7759: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
7760: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
7761: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
7762: $newsettings->{'captcha'} = 'original';
7763: }
7764: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 7765: if ($container eq 'cancreate') {
1.169 raeburn 7766: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7767: push(@{$changes->{'cancreate'}},'captcha');
7768: } elsif (!defined($changes->{'cancreate'})) {
7769: $changes->{'cancreate'} = ['captcha'];
7770: }
7771: } else {
7772: $changes->{'captcha'} = 1;
1.165 raeburn 7773: }
7774: }
7775: my ($newpub,$newpriv,$currpub,$currpriv);
7776: if ($newsettings->{'captcha'} eq 'recaptcha') {
7777: $newpub = $env{'form.'.$container.'_recaptchapub'};
7778: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.169 raeburn 7779: $newpub =~ s/\W//g;
7780: $newpriv =~ s/\W//g;
7781: $newsettings->{'recaptchakeys'} = {
7782: public => $newpub,
7783: private => $newpriv,
7784: };
1.165 raeburn 7785: }
7786: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
7787: $currpub = $current->{'recaptchakeys'}{'public'};
7788: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 7789: unless ($newsettings->{'captcha'} eq 'recaptcha') {
7790: $newsettings->{'recaptchakeys'} = {
7791: public => '',
7792: private => '',
7793: }
7794: }
1.165 raeburn 7795: }
7796: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 7797: if ($container eq 'cancreate') {
7798: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7799: push(@{$changes->{'cancreate'}},'recaptchakeys');
7800: } elsif (!defined($changes->{'cancreate'})) {
7801: $changes->{'cancreate'} = ['recaptchakeys'];
7802: }
7803: } else {
1.210 raeburn 7804: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 7805: }
7806: }
7807: return;
7808: }
7809:
1.33 raeburn 7810: sub modify_usermodification {
7811: my ($dom,%domconfig) = @_;
7812: my ($resulttext,%curr_usermodification,%changes);
7813: if (ref($domconfig{'usermodification'}) eq 'HASH') {
7814: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
7815: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
7816: }
7817: }
1.63 raeburn 7818: my @contexts = ('author','course','selfcreate');
1.33 raeburn 7819: my %context_title = (
7820: author => 'In author context',
7821: course => 'In course context',
1.63 raeburn 7822: selfcreate => 'When self creating account',
1.33 raeburn 7823: );
7824: my @fields = ('lastname','firstname','middlename','generation',
7825: 'permanentemail','id');
7826: my %roles = (
7827: author => ['ca','aa'],
7828: course => ['st','ep','ta','in','cr'],
7829: );
1.63 raeburn 7830: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7831: if (ref($types) eq 'ARRAY') {
7832: push(@{$types},'default');
7833: $usertypes->{'default'} = $othertitle;
7834: }
7835: $roles{'selfcreate'} = $types;
1.33 raeburn 7836: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7837: my %modifyhash;
7838: foreach my $context (@contexts) {
7839: foreach my $role (@{$roles{$context}}) {
7840: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
7841: foreach my $item (@fields) {
7842: if (grep(/^\Q$item\E$/,@modifiable)) {
7843: $modifyhash{$context}{$role}{$item} = 1;
7844: } else {
7845: $modifyhash{$context}{$role}{$item} = 0;
7846: }
7847: }
7848: }
7849: if (ref($curr_usermodification{$context}) eq 'HASH') {
7850: foreach my $role (@{$roles{$context}}) {
7851: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
7852: foreach my $field (@fields) {
7853: if ($modifyhash{$context}{$role}{$field} ne
7854: $curr_usermodification{$context}{$role}{$field}) {
7855: push(@{$changes{$context}},$role);
7856: last;
7857: }
7858: }
7859: }
7860: }
7861: } else {
7862: foreach my $context (@contexts) {
7863: foreach my $role (@{$roles{$context}}) {
7864: push(@{$changes{$context}},$role);
7865: }
7866: }
7867: }
7868: }
7869: my %usermodification_hash = (
7870: usermodification => \%modifyhash,
7871: );
7872: my $putresult = &Apache::lonnet::put_dom('configuration',
7873: \%usermodification_hash,$dom);
7874: if ($putresult eq 'ok') {
7875: if (keys(%changes) > 0) {
7876: $resulttext = &mt('Changes made: ').'<ul>';
7877: foreach my $context (@contexts) {
7878: if (ref($changes{$context}) eq 'ARRAY') {
7879: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
7880: if (ref($changes{$context}) eq 'ARRAY') {
7881: foreach my $role (@{$changes{$context}}) {
7882: my $rolename;
1.63 raeburn 7883: if ($context eq 'selfcreate') {
7884: $rolename = $role;
7885: if (ref($usertypes) eq 'HASH') {
7886: if ($usertypes->{$role} ne '') {
7887: $rolename = $usertypes->{$role};
7888: }
7889: }
1.33 raeburn 7890: } else {
1.63 raeburn 7891: if ($role eq 'cr') {
7892: $rolename = &mt('Custom');
7893: } else {
7894: $rolename = &Apache::lonnet::plaintext($role);
7895: }
1.33 raeburn 7896: }
7897: my @modifiable;
1.63 raeburn 7898: if ($context eq 'selfcreate') {
1.126 bisitz 7899: $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 7900: } else {
7901: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
7902: }
1.33 raeburn 7903: foreach my $field (@fields) {
7904: if ($modifyhash{$context}{$role}{$field}) {
7905: push(@modifiable,$fieldtitles{$field});
7906: }
7907: }
7908: if (@modifiable > 0) {
7909: $resulttext .= join(', ',@modifiable);
7910: } else {
7911: $resulttext .= &mt('none');
7912: }
7913: $resulttext .= '</li>';
7914: }
7915: $resulttext .= '</ul></li>';
7916: }
7917: }
7918: }
7919: $resulttext .= '</ul>';
7920: } else {
7921: $resulttext = &mt('No changes made to user modification settings');
7922: }
7923: } else {
7924: $resulttext = '<span class="LC_error">'.
7925: &mt('An error occurred: [_1]',$putresult).'</span>';
7926: }
7927: return $resulttext;
7928: }
7929:
1.43 raeburn 7930: sub modify_defaults {
1.212 raeburn 7931: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 7932: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 7933: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 7934: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 7935: my @authtypes = ('internal','krb4','krb5','localauth');
7936: foreach my $item (@items) {
7937: $newvalues{$item} = $env{'form.'.$item};
7938: if ($item eq 'auth_def') {
7939: if ($newvalues{$item} ne '') {
7940: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
7941: push(@errors,$item);
7942: }
7943: }
7944: } elsif ($item eq 'lang_def') {
7945: if ($newvalues{$item} ne '') {
7946: if ($newvalues{$item} =~ /^(\w+)/) {
7947: my $langcode = $1;
1.103 raeburn 7948: if ($langcode ne 'x_chef') {
7949: if (code2language($langcode) eq '') {
7950: push(@errors,$item);
7951: }
1.43 raeburn 7952: }
7953: } else {
7954: push(@errors,$item);
7955: }
7956: }
1.54 raeburn 7957: } elsif ($item eq 'timezone_def') {
7958: if ($newvalues{$item} ne '') {
1.62 raeburn 7959: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 7960: push(@errors,$item);
7961: }
7962: }
1.68 raeburn 7963: } elsif ($item eq 'datelocale_def') {
7964: if ($newvalues{$item} ne '') {
7965: my @datelocale_ids = DateTime::Locale->ids();
7966: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
7967: push(@errors,$item);
7968: }
7969: }
1.141 raeburn 7970: } elsif ($item eq 'portal_def') {
7971: if ($newvalues{$item} ne '') {
7972: 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])\/?$/) {
7973: push(@errors,$item);
7974: }
7975: }
1.43 raeburn 7976: }
7977: if (grep(/^\Q$item\E$/,@errors)) {
7978: $newvalues{$item} = $domdefaults{$item};
7979: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
7980: $changes{$item} = 1;
7981: }
1.72 raeburn 7982: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 7983: }
7984: my %defaults_hash = (
1.72 raeburn 7985: defaults => \%newvalues,
7986: );
1.43 raeburn 7987: my $title = &defaults_titles();
7988: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
7989: $dom);
7990: if ($putresult eq 'ok') {
7991: if (keys(%changes) > 0) {
7992: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 7993: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 7994: 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";
7995: foreach my $item (sort(keys(%changes))) {
7996: my $value = $env{'form.'.$item};
7997: if ($value eq '') {
7998: $value = &mt('none');
7999: } elsif ($item eq 'auth_def') {
8000: my %authnames = &authtype_names();
8001: my %shortauth = (
8002: internal => 'int',
8003: krb4 => 'krb4',
8004: krb5 => 'krb5',
8005: localauth => 'loc',
8006: );
8007: $value = $authnames{$shortauth{$value}};
8008: }
8009: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
8010: $mailmsgtext .= "$title->{$item} set to $value\n";
8011: }
8012: $resulttext .= '</ul>';
8013: $mailmsgtext .= "\n";
8014: my $cachetime = 24*60*60;
1.72 raeburn 8015: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 8016: if (ref($lastactref) eq 'HASH') {
8017: $lastactref->{'domdefaults'} = 1;
8018: }
1.68 raeburn 8019: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 8020: my $notify = 1;
8021: if (ref($domconfig{'contacts'}) eq 'HASH') {
8022: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
8023: $notify = 0;
8024: }
8025: }
8026: if ($notify) {
8027: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
8028: "LON-CAPA Domain Settings Change - $dom",
8029: $mailmsgtext);
8030: }
1.54 raeburn 8031: }
1.43 raeburn 8032: } else {
1.54 raeburn 8033: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 8034: }
8035: } else {
8036: $resulttext = '<span class="LC_error">'.
8037: &mt('An error occurred: [_1]',$putresult).'</span>';
8038: }
8039: if (@errors > 0) {
8040: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
8041: foreach my $item (@errors) {
8042: $resulttext .= ' "'.$title->{$item}.'",';
8043: }
8044: $resulttext =~ s/,$//;
8045: }
8046: return $resulttext;
8047: }
8048:
1.46 raeburn 8049: sub modify_scantron {
1.205 raeburn 8050: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 8051: my ($resulttext,%confhash,%changes,$errors);
8052: my $custom = 'custom.tab';
8053: my $default = 'default.tab';
8054: my $servadm = $r->dir_config('lonAdmEMail');
8055: my ($configuserok,$author_ok,$switchserver) =
8056: &config_check($dom,$confname,$servadm);
8057: if ($env{'form.scantronformat.filename'} ne '') {
8058: my $error;
8059: if ($configuserok eq 'ok') {
8060: if ($switchserver) {
1.130 raeburn 8061: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 8062: } else {
8063: if ($author_ok eq 'ok') {
8064: my ($result,$scantronurl) =
8065: &publishlogo($r,'upload','scantronformat',$dom,
8066: $confname,'scantron','','',$custom);
8067: if ($result eq 'ok') {
8068: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 8069: $changes{'scantronformat'} = 1;
1.46 raeburn 8070: } else {
8071: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
8072: }
8073: } else {
8074: $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);
8075: }
8076: }
8077: } else {
8078: $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);
8079: }
8080: if ($error) {
8081: &Apache::lonnet::logthis($error);
8082: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8083: }
8084: }
1.48 raeburn 8085: if (ref($domconfig{'scantron'}) eq 'HASH') {
8086: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
8087: if ($env{'form.scantronformat_del'}) {
8088: $confhash{'scantron'}{'scantronformat'} = '';
8089: $changes{'scantronformat'} = 1;
1.46 raeburn 8090: }
8091: }
8092: }
8093: if (keys(%confhash) > 0) {
8094: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
8095: $dom);
8096: if ($putresult eq 'ok') {
8097: if (keys(%changes) > 0) {
1.48 raeburn 8098: if (ref($confhash{'scantron'}) eq 'HASH') {
8099: $resulttext = &mt('Changes made:').'<ul>';
8100: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 8101: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 8102: } else {
1.130 raeburn 8103: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 8104: }
1.48 raeburn 8105: $resulttext .= '</ul>';
8106: } else {
1.130 raeburn 8107: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 8108: }
8109: $resulttext .= '</ul>';
8110: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 8111: if (ref($lastactref) eq 'HASH') {
8112: $lastactref->{'domainconfig'} = 1;
8113: }
1.46 raeburn 8114: } else {
1.130 raeburn 8115: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 8116: }
8117: } else {
8118: $resulttext = '<span class="LC_error">'.
8119: &mt('An error occurred: [_1]',$putresult).'</span>';
8120: }
8121: } else {
1.130 raeburn 8122: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 8123: }
8124: if ($errors) {
8125: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
8126: $errors.'</ul>';
8127: }
8128: return $resulttext;
8129: }
8130:
1.48 raeburn 8131: sub modify_coursecategories {
8132: my ($dom,%domconfig) = @_;
1.57 raeburn 8133: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
8134: $cathash);
1.48 raeburn 8135: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 8136: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 8137: $cathash = $domconfig{'coursecategories'}{'cats'};
8138: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
8139: $changes{'togglecats'} = 1;
8140: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
8141: }
8142: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
8143: $changes{'categorize'} = 1;
8144: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
8145: }
1.120 raeburn 8146: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
8147: $changes{'togglecatscomm'} = 1;
8148: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
8149: }
8150: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
8151: $changes{'categorizecomm'} = 1;
8152: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
8153: }
1.57 raeburn 8154: } else {
8155: $changes{'togglecats'} = 1;
8156: $changes{'categorize'} = 1;
1.124 raeburn 8157: $changes{'togglecatscomm'} = 1;
8158: $changes{'categorizecomm'} = 1;
1.87 raeburn 8159: $domconfig{'coursecategories'} = {
8160: togglecats => $env{'form.togglecats'},
8161: categorize => $env{'form.categorize'},
1.124 raeburn 8162: togglecatscomm => $env{'form.togglecatscomm'},
8163: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 8164: };
1.57 raeburn 8165: }
8166: if (ref($cathash) eq 'HASH') {
8167: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 8168: push (@deletecategory,'instcode::0');
8169: }
1.120 raeburn 8170: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
8171: push(@deletecategory,'communities::0');
8172: }
1.48 raeburn 8173: }
1.57 raeburn 8174: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
8175: if (ref($cathash) eq 'HASH') {
1.48 raeburn 8176: if (@deletecategory > 0) {
8177: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 8178: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 8179: foreach my $item (@deletecategory) {
1.57 raeburn 8180: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
8181: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 8182: $deletions{$item} = 1;
1.57 raeburn 8183: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 8184: }
8185: }
8186: }
1.57 raeburn 8187: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 8188: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 8189: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 8190: $reorderings{$item} = 1;
1.57 raeburn 8191: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 8192: }
8193: if ($env{'form.addcategory_name_'.$item} ne '') {
8194: my $newcat = $env{'form.addcategory_name_'.$item};
8195: my $newdepth = $depth+1;
8196: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 8197: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 8198: $adds{$newitem} = 1;
8199: }
8200: if ($env{'form.subcat_'.$item} ne '') {
8201: my $newcat = $env{'form.subcat_'.$item};
8202: my $newdepth = $depth+1;
8203: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 8204: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 8205: $adds{$newitem} = 1;
8206: }
8207: }
8208: }
8209: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 8210: if (ref($cathash) eq 'HASH') {
1.48 raeburn 8211: my $newitem = 'instcode::0';
1.57 raeburn 8212: if ($cathash->{$newitem} eq '') {
8213: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 8214: $adds{$newitem} = 1;
8215: }
8216: } else {
8217: my $newitem = 'instcode::0';
1.57 raeburn 8218: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 8219: $adds{$newitem} = 1;
8220: }
8221: }
1.120 raeburn 8222: if ($env{'form.communities'} eq '1') {
8223: if (ref($cathash) eq 'HASH') {
8224: my $newitem = 'communities::0';
8225: if ($cathash->{$newitem} eq '') {
8226: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
8227: $adds{$newitem} = 1;
8228: }
8229: } else {
8230: my $newitem = 'communities::0';
8231: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
8232: $adds{$newitem} = 1;
8233: }
8234: }
1.48 raeburn 8235: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 8236: if (($env{'form.addcategory_name'} ne 'instcode') &&
8237: ($env{'form.addcategory_name'} ne 'communities')) {
8238: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
8239: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
8240: $adds{$newitem} = 1;
8241: }
1.48 raeburn 8242: }
1.57 raeburn 8243: my $putresult;
1.48 raeburn 8244: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
8245: if (keys(%deletions) > 0) {
8246: foreach my $key (keys(%deletions)) {
8247: if ($predelallitems{$key} ne '') {
8248: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
8249: }
8250: }
8251: }
8252: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 8253: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 8254: if (ref($chkcats[0]) eq 'ARRAY') {
8255: my $depth = 0;
8256: my $chg = 0;
8257: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
8258: my $name = $chkcats[0][$i];
8259: my $item;
8260: if ($name eq '') {
8261: $chg ++;
8262: } else {
8263: $item = &escape($name).'::0';
8264: if ($chg) {
1.57 raeburn 8265: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 8266: }
8267: $depth ++;
1.57 raeburn 8268: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 8269: $depth --;
8270: }
8271: }
8272: }
1.57 raeburn 8273: }
8274: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
8275: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 8276: if ($putresult eq 'ok') {
1.57 raeburn 8277: my %title = (
1.120 raeburn 8278: togglecats => 'Show/Hide a course in catalog',
8279: categorize => 'Assign a category to a course',
8280: togglecatscomm => 'Show/Hide a community in catalog',
8281: categorizecomm => 'Assign a category to a community',
1.57 raeburn 8282: );
8283: my %level = (
1.120 raeburn 8284: dom => 'set in Domain ("Modify Course/Community")',
8285: crs => 'set in Course ("Course Configuration")',
8286: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 8287: );
1.48 raeburn 8288: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 8289: if ($changes{'togglecats'}) {
8290: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
8291: }
8292: if ($changes{'categorize'}) {
8293: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 8294: }
1.120 raeburn 8295: if ($changes{'togglecatscomm'}) {
8296: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
8297: }
8298: if ($changes{'categorizecomm'}) {
8299: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
8300: }
1.57 raeburn 8301: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
8302: my $cathash;
8303: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
8304: $cathash = $domconfig{'coursecategories'}{'cats'};
8305: } else {
8306: $cathash = {};
8307: }
8308: my (@cats,@trails,%allitems);
8309: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
8310: if (keys(%deletions) > 0) {
8311: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
8312: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
8313: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
8314: }
8315: $resulttext .= '</ul></li>';
8316: }
8317: if (keys(%reorderings) > 0) {
8318: my %sort_by_trail;
8319: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
8320: foreach my $key (keys(%reorderings)) {
8321: if ($allitems{$key} ne '') {
8322: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
8323: }
1.48 raeburn 8324: }
1.57 raeburn 8325: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
8326: $resulttext .= '<li>'.$trails[$trail].'</li>';
8327: }
8328: $resulttext .= '</ul></li>';
1.48 raeburn 8329: }
1.57 raeburn 8330: if (keys(%adds) > 0) {
8331: my %sort_by_trail;
8332: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
8333: foreach my $key (keys(%adds)) {
8334: if ($allitems{$key} ne '') {
8335: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
8336: }
8337: }
8338: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
8339: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 8340: }
1.57 raeburn 8341: $resulttext .= '</ul></li>';
1.48 raeburn 8342: }
8343: }
8344: $resulttext .= '</ul>';
8345: } else {
8346: $resulttext = '<span class="LC_error">'.
1.57 raeburn 8347: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 8348: }
8349: } else {
1.120 raeburn 8350: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 8351: }
8352: return $resulttext;
8353: }
8354:
1.69 raeburn 8355: sub modify_serverstatuses {
8356: my ($dom,%domconfig) = @_;
8357: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
8358: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
8359: %currserverstatus = %{$domconfig{'serverstatuses'}};
8360: }
8361: my @pages = &serverstatus_pages();
8362: foreach my $type (@pages) {
8363: $newserverstatus{$type}{'namedusers'} = '';
8364: $newserverstatus{$type}{'machines'} = '';
8365: if (defined($env{'form.'.$type.'_namedusers'})) {
8366: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
8367: my @okusers;
8368: foreach my $user (@users) {
8369: my ($uname,$udom) = split(/:/,$user);
8370: if (($udom =~ /^$match_domain$/) &&
8371: (&Apache::lonnet::domain($udom)) &&
8372: ($uname =~ /^$match_username$/)) {
8373: if (!grep(/^\Q$user\E/,@okusers)) {
8374: push(@okusers,$user);
8375: }
8376: }
8377: }
8378: if (@okusers > 0) {
8379: @okusers = sort(@okusers);
8380: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
8381: }
8382: }
8383: if (defined($env{'form.'.$type.'_machines'})) {
8384: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
8385: my @okmachines;
8386: foreach my $ip (@machines) {
8387: my @parts = split(/\./,$ip);
8388: next if (@parts < 4);
8389: my $badip = 0;
8390: for (my $i=0; $i<4; $i++) {
8391: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
8392: $badip = 1;
8393: last;
8394: }
8395: }
8396: if (!$badip) {
8397: push(@okmachines,$ip);
8398: }
8399: }
8400: @okmachines = sort(@okmachines);
8401: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
8402: }
8403: }
8404: my %serverstatushash = (
8405: serverstatuses => \%newserverstatus,
8406: );
8407: foreach my $type (@pages) {
1.83 raeburn 8408: foreach my $setting ('namedusers','machines') {
1.84 raeburn 8409: my (@current,@new);
1.83 raeburn 8410: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 8411: if ($currserverstatus{$type}{$setting} ne '') {
8412: @current = split(/,/,$currserverstatus{$type}{$setting});
8413: }
8414: }
8415: if ($newserverstatus{$type}{$setting} ne '') {
8416: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 8417: }
8418: if (@current > 0) {
8419: if (@new > 0) {
8420: foreach my $item (@current) {
8421: if (!grep(/^\Q$item\E$/,@new)) {
8422: $changes{$type}{$setting} = 1;
1.82 raeburn 8423: last;
8424: }
8425: }
1.84 raeburn 8426: foreach my $item (@new) {
8427: if (!grep(/^\Q$item\E$/,@current)) {
8428: $changes{$type}{$setting} = 1;
8429: last;
1.82 raeburn 8430: }
8431: }
8432: } else {
1.83 raeburn 8433: $changes{$type}{$setting} = 1;
1.69 raeburn 8434: }
1.83 raeburn 8435: } elsif (@new > 0) {
8436: $changes{$type}{$setting} = 1;
1.69 raeburn 8437: }
8438: }
8439: }
8440: if (keys(%changes) > 0) {
1.81 raeburn 8441: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 8442: my $putresult = &Apache::lonnet::put_dom('configuration',
8443: \%serverstatushash,$dom);
8444: if ($putresult eq 'ok') {
8445: $resulttext .= &mt('Changes made:').'<ul>';
8446: foreach my $type (@pages) {
1.84 raeburn 8447: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 8448: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 8449: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 8450: if ($newserverstatus{$type}{'namedusers'} eq '') {
8451: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
8452: } else {
8453: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
8454: }
1.84 raeburn 8455: }
8456: if ($changes{$type}{'machines'}) {
1.69 raeburn 8457: if ($newserverstatus{$type}{'machines'} eq '') {
8458: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
8459: } else {
8460: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
8461: }
8462:
8463: }
8464: $resulttext .= '</ul></li>';
8465: }
8466: }
8467: $resulttext .= '</ul>';
8468: } else {
8469: $resulttext = '<span class="LC_error">'.
8470: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
8471:
8472: }
8473: } else {
8474: $resulttext = &mt('No changes made to access to server status pages');
8475: }
8476: return $resulttext;
8477: }
8478:
1.118 jms 8479: sub modify_helpsettings {
1.122 jms 8480: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 8481: my ($resulttext,$errors,%changes,%helphash);
8482: my %defaultchecked = ('submitbugs' => 'on');
8483: my @offon = ('off','on');
1.118 jms 8484: my @toggles = ('submitbugs');
8485: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8486: foreach my $item (@toggles) {
1.166 raeburn 8487: if ($defaultchecked{$item} eq 'on') {
8488: if ($domconfig{'helpsettings'}{$item} eq '') {
8489: if ($env{'form.'.$item} eq '0') {
8490: $changes{$item} = 1;
8491: }
8492: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
8493: $changes{$item} = 1;
8494: }
8495: } elsif ($defaultchecked{$item} eq 'off') {
8496: if ($domconfig{'helpsettings'}{$item} eq '') {
8497: if ($env{'form.'.$item} eq '1') {
8498: $changes{$item} = 1;
8499: }
8500: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
8501: $changes{$item} = 1;
8502: }
8503: }
1.210 raeburn 8504: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
1.166 raeburn 8505: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
8506: }
8507: }
1.118 jms 8508: }
1.123 jms 8509: my $putresult;
8510: if (keys(%changes) > 0) {
1.166 raeburn 8511: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 8512: if ($putresult eq 'ok') {
1.166 raeburn 8513: $resulttext = &mt('Changes made:').'<ul>';
8514: foreach my $item (sort(keys(%changes))) {
8515: if ($item eq 'submitbugs') {
8516: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
8517: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
8518: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
8519: }
8520: }
8521: $resulttext .= '</ul>';
8522: } else {
8523: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 8524: $errors .= '<li><span class="LC_error">'.
8525: &mt('An error occurred storing the settings: [_1]',
8526: $putresult).'</span></li>';
1.166 raeburn 8527: }
1.118 jms 8528: }
8529: if ($errors) {
1.168 raeburn 8530: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 8531: $errors.'</ul>';
8532: }
8533: return $resulttext;
8534: }
8535:
1.121 raeburn 8536: sub modify_coursedefaults {
1.212 raeburn 8537: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 8538: my ($resulttext,$errors,%changes,%defaultshash);
8539: my %defaultchecked = ('canuse_pdfforms' => 'off');
8540: my @toggles = ('canuse_pdfforms');
1.198 raeburn 8541: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.216 raeburn 8542: 'uploadquota_community','uploadquota_textbook');
8543: my @types = ('official','unofficial','community','textbook');
1.198 raeburn 8544: my %staticdefaults = (
8545: anonsurvey_threshold => 10,
8546: uploadquota => 500,
8547: );
1.121 raeburn 8548:
8549: $defaultshash{'coursedefaults'} = {};
8550:
8551: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
8552: if ($domconfig{'coursedefaults'} eq '') {
8553: $domconfig{'coursedefaults'} = {};
8554: }
8555: }
8556:
8557: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
8558: foreach my $item (@toggles) {
8559: if ($defaultchecked{$item} eq 'on') {
8560: if (($domconfig{'coursedefaults'}{$item} eq '') &&
8561: ($env{'form.'.$item} eq '0')) {
8562: $changes{$item} = 1;
1.192 raeburn 8563: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 8564: $changes{$item} = 1;
8565: }
8566: } elsif ($defaultchecked{$item} eq 'off') {
8567: if (($domconfig{'coursedefaults'}{$item} eq '') &&
8568: ($env{'form.'.$item} eq '1')) {
8569: $changes{$item} = 1;
8570: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
8571: $changes{$item} = 1;
8572: }
8573: }
8574: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
8575: }
1.198 raeburn 8576: foreach my $item (@numbers) {
8577: my ($currdef,$newdef);
1.208 raeburn 8578: $newdef = $env{'form.'.$item};
1.198 raeburn 8579: if ($item eq 'anonsurvey_threshold') {
8580: $currdef = $domconfig{'coursedefaults'}{$item};
8581: $newdef =~ s/\D//g;
8582: if ($newdef eq '' || $newdef < 1) {
8583: $newdef = 1;
8584: }
8585: $defaultshash{'coursedefaults'}{$item} = $newdef;
8586: } else {
8587: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
8588: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8589: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
8590: }
8591: $newdef =~ s/[^\w.\-]//g;
8592: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
8593: }
8594: if ($currdef ne $newdef) {
8595: my $staticdef;
8596: if ($item eq 'anonsurvey_threshold') {
8597: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
8598: $changes{$item} = 1;
8599: }
8600: } else {
8601: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
8602: $changes{'uploadquota'} = 1;
8603: }
8604: }
1.139 raeburn 8605: }
8606: }
1.192 raeburn 8607: my $officialcreds = $env{'form.official_credits'};
1.216 raeburn 8608: $officialcreds =~ s/[^\d.]+//g;
1.192 raeburn 8609: my $unofficialcreds = $env{'form.unofficial_credits'};
1.216 raeburn 8610: $unofficialcreds =~ s/[^\d.]+//g;
8611: my $textbookcreds = $env{'form.textbook_credits'};
8612: $textbookcreds =~ s/[^\d.]+//g;
1.192 raeburn 8613: if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
8614: ($env{'form.coursecredits'} eq '1')) {
8615: $changes{'coursecredits'} = 1;
8616: } else {
8617: if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
1.216 raeburn 8618: ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds) ||
8619: ($domconfig{'coursedefaults'}{'coursecredits'}{'textbook'} ne $textbookcreds)) {
1.192 raeburn 8620: $changes{'coursecredits'} = 1;
8621: }
8622: }
8623: $defaultshash{'coursedefaults'}{'coursecredits'} = {
8624: official => $officialcreds,
8625: unofficial => $unofficialcreds,
1.216 raeburn 8626: textbook => $textbookcreds,
1.192 raeburn 8627: }
1.121 raeburn 8628: }
8629: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8630: $dom);
8631: if ($putresult eq 'ok') {
8632: if (keys(%changes) > 0) {
1.213 raeburn 8633: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.198 raeburn 8634: if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) || ($changes{'uploadquota'})) {
1.192 raeburn 8635: if ($changes{'canuse_pdfforms'}) {
8636: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
8637: }
8638: if ($changes{'coursecredits'}) {
8639: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
8640: $domdefaults{'officialcredits'} =
8641: $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
8642: $domdefaults{'unofficialcredits'} =
8643: $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
1.216 raeburn 8644: $domdefaults{'textbookcredits'} =
8645: $domdefaults{'coursedefaults'}{'coursecredits'}{'textbook'};
1.192 raeburn 8646: }
8647: }
1.198 raeburn 8648: if ($changes{'uploadquota'}) {
8649: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8650: foreach my $type (@types) {
8651: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
8652: }
8653: }
8654: }
1.121 raeburn 8655: my $cachetime = 24*60*60;
8656: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 8657: if (ref($lastactref) eq 'HASH') {
8658: $lastactref->{'domdefaults'} = 1;
8659: }
1.121 raeburn 8660: }
8661: $resulttext = &mt('Changes made:').'<ul>';
8662: foreach my $item (sort(keys(%changes))) {
8663: if ($item eq 'canuse_pdfforms') {
8664: if ($env{'form.'.$item} eq '1') {
8665: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
8666: } else {
8667: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
8668: }
1.139 raeburn 8669: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 8670: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 8671: } elsif ($item eq 'uploadquota') {
8672: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8673: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
8674: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
8675: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 8676: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
8677:
1.198 raeburn 8678: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
8679: '</ul>'.
8680: '</li>';
8681: } else {
8682: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
8683: }
1.192 raeburn 8684: } elsif ($item eq 'coursecredits') {
8685: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
8686: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 8687: ($domdefaults{'unofficialcredits'} eq '') &&
8688: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 8689: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
8690: } else {
8691: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
8692: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
8693: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 8694: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 8695: '</ul>'.
8696: '</li>';
8697: }
8698: } else {
8699: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
8700: }
1.140 raeburn 8701: }
1.121 raeburn 8702: }
8703: $resulttext .= '</ul>';
8704: } else {
8705: $resulttext = &mt('No changes made to course defaults');
8706: }
8707: } else {
8708: $resulttext = '<span class="LC_error">'.
8709: &mt('An error occurred: [_1]',$putresult).'</span>';
8710: }
8711: return $resulttext;
8712: }
8713:
1.137 raeburn 8714: sub modify_usersessions {
1.212 raeburn 8715: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 8716: my @hostingtypes = ('version','excludedomain','includedomain');
8717: my @offloadtypes = ('primary','default');
8718: my %types = (
8719: remote => \@hostingtypes,
8720: hosted => \@hostingtypes,
8721: spares => \@offloadtypes,
8722: );
8723: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 8724: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 8725: my (%by_ip,%by_location,@intdoms);
8726: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
8727: my @locations = sort(keys(%by_location));
1.137 raeburn 8728: my (%defaultshash,%changes);
8729: foreach my $prefix (@prefixes) {
8730: $defaultshash{'usersessions'}{$prefix} = {};
8731: }
1.212 raeburn 8732: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 8733: my $resulttext;
1.138 raeburn 8734: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 8735: foreach my $prefix (@prefixes) {
1.145 raeburn 8736: next if ($prefix eq 'spares');
8737: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 8738: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
8739: if ($type eq 'version') {
8740: my $value = $env{'form.'.$prefix.'_'.$type};
8741: my $okvalue;
8742: if ($value ne '') {
8743: if (grep(/^\Q$value\E$/,@lcversions)) {
8744: $okvalue = $value;
8745: }
8746: }
8747: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8748: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
8749: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
8750: if ($inuse == 0) {
8751: $changes{$prefix}{$type} = 1;
8752: } else {
8753: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
8754: $changes{$prefix}{$type} = 1;
8755: }
8756: if ($okvalue ne '') {
8757: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8758: }
8759: }
8760: } else {
8761: if (($inuse == 1) && ($okvalue ne '')) {
8762: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8763: $changes{$prefix}{$type} = 1;
8764: }
8765: }
8766: } else {
8767: if (($inuse == 1) && ($okvalue ne '')) {
8768: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8769: $changes{$prefix}{$type} = 1;
8770: }
8771: }
8772: } else {
8773: if (($inuse == 1) && ($okvalue ne '')) {
8774: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8775: $changes{$prefix}{$type} = 1;
8776: }
8777: }
8778: } else {
8779: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
8780: my @okvals;
8781: foreach my $val (@vals) {
1.138 raeburn 8782: if ($val =~ /:/) {
8783: my @items = split(/:/,$val);
8784: foreach my $item (@items) {
8785: if (ref($by_location{$item}) eq 'ARRAY') {
8786: push(@okvals,$item);
8787: }
8788: }
8789: } else {
8790: if (ref($by_location{$val}) eq 'ARRAY') {
8791: push(@okvals,$val);
8792: }
1.137 raeburn 8793: }
8794: }
8795: @okvals = sort(@okvals);
8796: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8797: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
8798: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8799: if ($inuse == 0) {
8800: $changes{$prefix}{$type} = 1;
8801: } else {
8802: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8803: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
8804: if (@changed > 0) {
8805: $changes{$prefix}{$type} = 1;
8806: }
8807: }
8808: } else {
8809: if ($inuse == 1) {
8810: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8811: $changes{$prefix}{$type} = 1;
8812: }
8813: }
8814: } else {
8815: if ($inuse == 1) {
8816: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8817: $changes{$prefix}{$type} = 1;
8818: }
8819: }
8820: } else {
8821: if ($inuse == 1) {
8822: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8823: $changes{$prefix}{$type} = 1;
8824: }
8825: }
8826: }
8827: }
8828: }
1.145 raeburn 8829:
8830: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 8831: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 8832: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
8833: my $savespares;
8834:
8835: foreach my $lonhost (sort(keys(%servers))) {
8836: my $serverhomeID =
8837: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 8838: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 8839: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
8840: my %spareschg;
8841: foreach my $type (@{$types{'spares'}}) {
8842: my @okspares;
8843: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
8844: foreach my $server (@checked) {
1.152 raeburn 8845: if (&Apache::lonnet::hostname($server) ne '') {
8846: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
8847: unless (grep(/^\Q$server\E$/,@okspares)) {
8848: push(@okspares,$server);
8849: }
1.145 raeburn 8850: }
8851: }
8852: }
8853: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
8854: my $newspare;
1.152 raeburn 8855: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
8856: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 8857: $newspare = $new;
8858: }
8859: }
1.152 raeburn 8860: my @spares;
8861: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
8862: @spares = sort(@okspares,$newspare);
8863: } else {
8864: @spares = sort(@okspares);
8865: }
8866: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 8867: if (ref($spareid{$lonhost}) eq 'HASH') {
8868: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 8869: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 8870: if (@diffs > 0) {
8871: $spareschg{$type} = 1;
8872: }
8873: }
8874: }
8875: }
8876: if (keys(%spareschg) > 0) {
8877: $changes{'spares'}{$lonhost} = \%spareschg;
8878: }
8879: }
8880:
8881: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8882: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
8883: if (ref($changes{'spares'}) eq 'HASH') {
8884: if (keys(%{$changes{'spares'}}) > 0) {
8885: $savespares = 1;
8886: }
8887: }
8888: } else {
8889: $savespares = 1;
8890: }
8891: }
8892:
1.147 raeburn 8893: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
8894: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 8895: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8896: $dom);
8897: if ($putresult eq 'ok') {
8898: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8899: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
8900: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
8901: }
8902: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
8903: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
8904: }
8905: }
8906: my $cachetime = 24*60*60;
8907: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 8908: if (ref($lastactref) eq 'HASH') {
8909: $lastactref->{'domdefaults'} = 1;
8910: }
1.147 raeburn 8911: if (keys(%changes) > 0) {
8912: my %lt = &usersession_titles();
8913: $resulttext = &mt('Changes made:').'<ul>';
8914: foreach my $prefix (@prefixes) {
8915: if (ref($changes{$prefix}) eq 'HASH') {
8916: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
8917: if ($prefix eq 'spares') {
8918: if (ref($changes{$prefix}) eq 'HASH') {
8919: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
8920: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 8921: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 8922: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
8923: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 8924: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
8925: foreach my $type (@{$types{$prefix}}) {
8926: if ($changes{$prefix}{$lonhost}{$type}) {
8927: my $offloadto = &mt('None');
8928: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
8929: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
8930: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
8931: }
1.145 raeburn 8932: }
1.147 raeburn 8933: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 8934: }
1.137 raeburn 8935: }
8936: }
1.147 raeburn 8937: $resulttext .= '</li>';
1.137 raeburn 8938: }
8939: }
1.147 raeburn 8940: } else {
8941: foreach my $type (@{$types{$prefix}}) {
8942: if (defined($changes{$prefix}{$type})) {
8943: my $newvalue;
8944: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8945: if (ref($defaultshash{'usersessions'}{$prefix})) {
8946: if ($type eq 'version') {
8947: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
8948: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8949: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
8950: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
8951: }
1.145 raeburn 8952: }
8953: }
8954: }
1.147 raeburn 8955: if ($newvalue eq '') {
8956: if ($type eq 'version') {
8957: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
8958: } else {
8959: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
8960: }
1.145 raeburn 8961: } else {
1.147 raeburn 8962: if ($type eq 'version') {
8963: $newvalue .= ' '.&mt('(or later)');
8964: }
8965: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 8966: }
1.137 raeburn 8967: }
8968: }
8969: }
1.147 raeburn 8970: $resulttext .= '</ul>';
1.137 raeburn 8971: }
8972: }
1.147 raeburn 8973: $resulttext .= '</ul>';
8974: } else {
8975: $resulttext = $nochgmsg;
1.137 raeburn 8976: }
8977: } else {
8978: $resulttext = '<span class="LC_error">'.
8979: &mt('An error occurred: [_1]',$putresult).'</span>';
8980: }
8981: } else {
1.147 raeburn 8982: $resulttext = $nochgmsg;
1.137 raeburn 8983: }
8984: return $resulttext;
8985: }
8986:
1.150 raeburn 8987: sub modify_loadbalancing {
8988: my ($dom,%domconfig) = @_;
8989: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8990: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8991: my ($othertitle,$usertypes,$types) =
8992: &Apache::loncommon::sorted_inst_types($dom);
8993: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8994: my @sparestypes = ('primary','default');
8995: my %typetitles = &sparestype_titles();
8996: my $resulttext;
1.171 raeburn 8997: my (%currbalancer,%currtargets,%currrules,%existing);
8998: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8999: %existing = %{$domconfig{'loadbalancing'}};
9000: }
9001: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
9002: \%currtargets,\%currrules);
9003: my ($saveloadbalancing,%defaultshash,%changes);
9004: my ($alltypes,$othertypes,$titles) =
9005: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
9006: my %ruletitles = &offloadtype_text();
9007: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
9008: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
9009: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
9010: if ($balancer eq '') {
9011: next;
9012: }
1.210 raeburn 9013: if (!exists($servers{$balancer})) {
1.171 raeburn 9014: if (exists($currbalancer{$balancer})) {
9015: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 9016: }
1.171 raeburn 9017: next;
9018: }
9019: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
9020: push(@{$changes{'delete'}},$balancer);
9021: next;
9022: }
9023: if (!exists($currbalancer{$balancer})) {
9024: push(@{$changes{'add'}},$balancer);
9025: }
9026: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
9027: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
9028: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
9029: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
9030: $saveloadbalancing = 1;
9031: }
9032: foreach my $sparetype (@sparestypes) {
9033: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
9034: my @offloadto;
9035: foreach my $target (@targets) {
9036: if (($servers{$target}) && ($target ne $balancer)) {
9037: if ($sparetype eq 'default') {
9038: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
9039: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 9040: }
9041: }
1.171 raeburn 9042: unless(grep(/^\Q$target\E$/,@offloadto)) {
9043: push(@offloadto,$target);
9044: }
1.150 raeburn 9045: }
1.171 raeburn 9046: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 9047: }
9048: }
1.171 raeburn 9049: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 9050: foreach my $sparetype (@sparestypes) {
1.171 raeburn 9051: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
9052: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 9053: if (@targetdiffs > 0) {
1.171 raeburn 9054: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 9055: }
1.171 raeburn 9056: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
9057: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
9058: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 9059: }
9060: }
9061: }
9062: } else {
1.171 raeburn 9063: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 9064: foreach my $sparetype (@sparestypes) {
1.171 raeburn 9065: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
9066: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
9067: $changes{'curr'}{$balancer}{'targets'} = 1;
9068: }
1.150 raeburn 9069: }
9070: }
1.210 raeburn 9071: }
1.150 raeburn 9072: }
9073: my $ishomedom;
1.171 raeburn 9074: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
9075: $ishomedom = 1;
1.150 raeburn 9076: }
9077: if (ref($alltypes) eq 'ARRAY') {
9078: foreach my $type (@{$alltypes}) {
9079: my $rule;
1.210 raeburn 9080: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 9081: (!$ishomedom)) {
1.171 raeburn 9082: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
9083: }
9084: if ($rule eq 'specific') {
9085: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 9086: }
1.171 raeburn 9087: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
9088: if (ref($currrules{$balancer}) eq 'HASH') {
9089: if ($rule ne $currrules{$balancer}{$type}) {
9090: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 9091: }
9092: } elsif ($rule ne '') {
1.171 raeburn 9093: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 9094: }
9095: }
9096: }
1.171 raeburn 9097: }
9098: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
9099: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
9100: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
9101: $defaultshash{'loadbalancing'} = {};
9102: }
9103: my $putresult = &Apache::lonnet::put_dom('configuration',
9104: \%defaultshash,$dom);
9105: if ($putresult eq 'ok') {
9106: if (keys(%changes) > 0) {
9107: if (ref($changes{'delete'}) eq 'ARRAY') {
9108: foreach my $balancer (sort(@{$changes{'delete'}})) {
9109: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.211 raeburn 9110: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
9111: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 9112: }
1.171 raeburn 9113: }
9114: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 9115: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 9116: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
9117: }
9118: }
9119: if (ref($changes{'curr'}) eq 'HASH') {
9120: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
9121: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
9122: if ($changes{'curr'}{$balancer}{'targets'}) {
9123: my %offloadstr;
9124: foreach my $sparetype (@sparestypes) {
9125: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
9126: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
9127: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
9128: }
9129: }
1.150 raeburn 9130: }
1.171 raeburn 9131: if (keys(%offloadstr) == 0) {
9132: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 9133: } else {
1.171 raeburn 9134: my $showoffload;
9135: foreach my $sparetype (@sparestypes) {
9136: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
9137: if (defined($offloadstr{$sparetype})) {
9138: $showoffload .= $offloadstr{$sparetype};
9139: } else {
9140: $showoffload .= &mt('None');
9141: }
9142: $showoffload .= (' 'x3);
9143: }
9144: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 9145: }
9146: }
9147: }
1.171 raeburn 9148: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
9149: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
9150: foreach my $type (@{$alltypes}) {
9151: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
9152: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
9153: my $balancetext;
9154: if ($rule eq '') {
9155: $balancetext = $ruletitles{'default'};
1.209 raeburn 9156: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
9157: ($rule eq 'balancer') || ($rule eq 'offloadedto')) {
1.171 raeburn 9158: $balancetext = $ruletitles{$rule};
9159: } else {
9160: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
9161: }
1.210 raeburn 9162: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 9163: }
9164: }
9165: }
9166: }
1.215 raeburn 9167: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
1.211 raeburn 9168: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 9169: }
1.171 raeburn 9170: }
9171: if ($resulttext ne '') {
9172: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 9173: } else {
9174: $resulttext = $nochgmsg;
9175: }
9176: } else {
1.171 raeburn 9177: $resulttext = $nochgmsg;
1.150 raeburn 9178: }
9179: } else {
1.171 raeburn 9180: $resulttext = '<span class="LC_error">'.
9181: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 9182: }
9183: } else {
1.171 raeburn 9184: $resulttext = $nochgmsg;
1.150 raeburn 9185: }
9186: return $resulttext;
9187: }
9188:
1.48 raeburn 9189: sub recurse_check {
9190: my ($chkcats,$categories,$depth,$name) = @_;
9191: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
9192: my $chg = 0;
9193: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
9194: my $category = $chkcats->[$depth]{$name}[$j];
9195: my $item;
9196: if ($category eq '') {
9197: $chg ++;
9198: } else {
9199: my $deeper = $depth + 1;
9200: $item = &escape($category).':'.&escape($name).':'.$depth;
9201: if ($chg) {
9202: $categories->{$item} -= $chg;
9203: }
9204: &recurse_check($chkcats,$categories,$deeper,$category);
9205: $deeper --;
9206: }
9207: }
9208: }
9209: return;
9210: }
9211:
9212: sub recurse_cat_deletes {
9213: my ($item,$coursecategories,$deletions) = @_;
9214: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9215: my $subdepth = $depth + 1;
9216: if (ref($coursecategories) eq 'HASH') {
9217: foreach my $subitem (keys(%{$coursecategories})) {
9218: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
9219: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
9220: delete($coursecategories->{$subitem});
9221: $deletions->{$subitem} = 1;
9222: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 9223: }
1.48 raeburn 9224: }
9225: }
9226: return;
9227: }
9228:
1.125 raeburn 9229: sub get_active_dcs {
9230: my ($dom) = @_;
1.191 raeburn 9231: my $now = time;
9232: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 9233: my %domcoords;
9234: my $numdcs = 0;
9235: foreach my $server (keys(%dompersonnel)) {
9236: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
9237: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.191 raeburn 9238: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 9239: }
9240: }
9241: return %domcoords;
9242: }
9243:
9244: sub active_dc_picker {
1.191 raeburn 9245: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.125 raeburn 9246: my %domcoords = &get_active_dcs($dom);
1.191 raeburn 9247: my @domcoord = keys(%domcoords);
9248: if (keys(%currhash)) {
9249: foreach my $dc (keys(%currhash)) {
9250: unless (exists($domcoords{$dc})) {
9251: push(@domcoord,$dc);
9252: }
9253: }
9254: }
9255: @domcoord = sort(@domcoord);
1.210 raeburn 9256: my $numdcs = scalar(@domcoord);
1.191 raeburn 9257: my $rows = 0;
9258: my $table;
1.125 raeburn 9259: if ($numdcs > 1) {
1.191 raeburn 9260: $table = '<table>';
9261: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 9262: my $rem = $i%($numinrow);
9263: if ($rem == 0) {
9264: if ($i > 0) {
1.191 raeburn 9265: $table .= '</tr>';
1.125 raeburn 9266: }
1.191 raeburn 9267: $table .= '<tr>';
9268: $rows ++;
1.125 raeburn 9269: }
1.191 raeburn 9270: my $check = '';
9271: if ($inputtype eq 'radio') {
9272: if (keys(%currhash) == 0) {
9273: if (!$i) {
9274: $check = ' checked="checked"';
9275: }
9276: } elsif (exists($currhash{$domcoord[$i]})) {
9277: $check = ' checked="checked"';
9278: }
9279: } else {
9280: if (exists($currhash{$domcoord[$i]})) {
9281: $check = ' checked="checked"';
1.125 raeburn 9282: }
9283: }
1.191 raeburn 9284: if ($i == @domcoord - 1) {
1.125 raeburn 9285: my $colsleft = $numinrow - $rem;
9286: if ($colsleft > 1) {
1.191 raeburn 9287: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 9288: } else {
1.191 raeburn 9289: $table .= '<td class="LC_left_item">';
1.125 raeburn 9290: }
9291: } else {
1.191 raeburn 9292: $table .= '<td class="LC_left_item">';
9293: }
9294: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
9295: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
9296: $table .= '<span class="LC_nobreak"><label>'.
9297: '<input type="'.$inputtype.'" name="'.$name.'"'.
9298: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
9299: if ($user ne $dcname.':'.$dcdom) {
9300: $table .= ' ('.$dcname.':'.$dcdom.')'.
9301: '</label></span></td>';
9302: }
9303: }
9304: $table .= '</tr></table>';
9305: } elsif ($numdcs == 1) {
9306: if ($inputtype eq 'radio') {
9307: $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />';
9308: } else {
9309: my $check;
9310: if (exists($currhash{$domcoord[0]})) {
9311: $check = ' checked="checked"';
1.125 raeburn 9312: }
1.191 raeburn 9313: $table .= '<input type="checkbox" name="'.$name.'" '.
9314: 'value="'.$domcoord[0].'"'.$check.' />';
9315: $rows ++;
1.125 raeburn 9316: }
9317: }
1.191 raeburn 9318: return ($numdcs,$table,$rows);
1.125 raeburn 9319: }
9320:
1.137 raeburn 9321: sub usersession_titles {
9322: return &Apache::lonlocal::texthash(
9323: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
9324: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 9325: spares => 'Servers offloaded to, when busy',
1.137 raeburn 9326: version => 'LON-CAPA version requirement',
1.138 raeburn 9327: excludedomain => 'Allow all, but exclude specific domains',
9328: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 9329: primary => 'Primary (checked first)',
1.154 raeburn 9330: default => 'Default',
1.137 raeburn 9331: );
9332: }
9333:
1.152 raeburn 9334: sub id_for_thisdom {
9335: my (%servers) = @_;
9336: my %altids;
9337: foreach my $server (keys(%servers)) {
9338: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
9339: if ($serverhome ne $server) {
9340: $altids{$serverhome} = $server;
9341: }
9342: }
9343: return %altids;
9344: }
9345:
1.150 raeburn 9346: sub count_servers {
9347: my ($currbalancer,%servers) = @_;
9348: my (@spares,$numspares);
9349: foreach my $lonhost (sort(keys(%servers))) {
9350: next if ($currbalancer eq $lonhost);
9351: push(@spares,$lonhost);
9352: }
9353: if ($currbalancer) {
9354: $numspares = scalar(@spares);
9355: } else {
9356: $numspares = scalar(@spares) - 1;
9357: }
9358: return ($numspares,@spares);
9359: }
9360:
9361: sub lonbalance_targets_js {
1.171 raeburn 9362: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 9363: my $select = &mt('Select');
9364: my ($alltargets,$allishome,$allinsttypes,@alltypes);
9365: if (ref($servers) eq 'HASH') {
9366: $alltargets = join("','",sort(keys(%{$servers})));
9367: my @homedoms;
9368: foreach my $server (sort(keys(%{$servers}))) {
9369: if (&Apache::lonnet::host_domain($server) eq $dom) {
9370: push(@homedoms,'1');
9371: } else {
9372: push(@homedoms,'0');
9373: }
9374: }
9375: $allishome = join("','",@homedoms);
9376: }
9377: if (ref($types) eq 'ARRAY') {
9378: if (@{$types} > 0) {
9379: @alltypes = @{$types};
9380: }
9381: }
9382: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
9383: $allinsttypes = join("','",@alltypes);
1.171 raeburn 9384: my (%currbalancer,%currtargets,%currrules,%existing);
9385: if (ref($settings) eq 'HASH') {
9386: %existing = %{$settings};
9387: }
9388: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
9389: \%currtargets,\%currrules);
1.210 raeburn 9390: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 9391: return <<"END";
9392:
9393: <script type="text/javascript">
9394: // <![CDATA[
9395:
1.171 raeburn 9396: currBalancers = new Array('$balancers');
9397:
9398: function toggleTargets(balnum) {
9399: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
9400: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
9401: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
9402: var prevbalancer = prevhostitem.value;
9403: var baltotal = document.getElementById('loadbalancing_total').value;
9404: prevhostitem.value = balancer;
9405: if (prevbalancer != '') {
9406: var prevIdx = currBalancers.indexOf(prevbalancer);
9407: if (prevIdx != -1) {
9408: currBalancers.splice(prevIdx,1);
9409: }
9410: }
1.150 raeburn 9411: if (balancer == '') {
1.171 raeburn 9412: hideSpares(balnum);
1.150 raeburn 9413: } else {
1.171 raeburn 9414: var currIdx = currBalancers.indexOf(balancer);
9415: if (currIdx == -1) {
9416: currBalancers.push(balancer);
9417: }
1.150 raeburn 9418: var homedoms = new Array('$allishome');
1.171 raeburn 9419: var ishomedom = homedoms[lonhostitem.selectedIndex];
9420: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 9421: }
1.171 raeburn 9422: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 9423: return;
9424: }
9425:
1.171 raeburn 9426: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 9427: var alltargets = new Array('$alltargets');
9428: var insttypes = new Array('$allinsttypes');
1.151 raeburn 9429: var offloadtypes = new Array('primary','default');
9430:
1.171 raeburn 9431: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
9432: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 9433:
1.151 raeburn 9434: for (var i=0; i<offloadtypes.length; i++) {
9435: var count = 0;
9436: for (var j=0; j<alltargets.length; j++) {
9437: if (alltargets[j] != balancer) {
1.171 raeburn 9438: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
9439: item.value = alltargets[j];
9440: item.style.textAlign='left';
9441: item.style.textFace='normal';
9442: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
9443: if (currBalancers.indexOf(alltargets[j]) == -1) {
9444: item.disabled = '';
9445: } else {
9446: item.disabled = 'disabled';
9447: item.checked = false;
9448: }
1.151 raeburn 9449: count ++;
9450: }
1.150 raeburn 9451: }
9452: }
1.151 raeburn 9453: for (var k=0; k<insttypes.length; k++) {
9454: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 9455: if (ishomedom == 1) {
1.171 raeburn 9456: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
9457: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 9458: } else {
1.171 raeburn 9459: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
9460: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 9461: }
9462: } else {
1.171 raeburn 9463: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
9464: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 9465: }
1.151 raeburn 9466: if ((insttypes[k] != '_LC_external') &&
9467: ((insttypes[k] != '_LC_internetdom') ||
9468: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 9469: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
9470: item.options.length = 0;
9471: item.options[0] = new Option("","",true,true);
1.210 raeburn 9472: var idx = 0;
1.151 raeburn 9473: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 9474: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
9475: idx ++;
9476: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 9477: }
9478: }
9479: }
9480: }
9481: return;
9482: }
9483:
1.171 raeburn 9484: function hideSpares(balnum) {
1.150 raeburn 9485: var alltargets = new Array('$alltargets');
9486: var insttypes = new Array('$allinsttypes');
9487: var offloadtypes = new Array('primary','default');
9488:
1.171 raeburn 9489: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
9490: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 9491:
9492: var total = alltargets.length - 1;
9493: for (var i=0; i<offloadtypes; i++) {
9494: for (var j=0; j<total; j++) {
1.171 raeburn 9495: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
9496: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
9497: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 9498: }
1.150 raeburn 9499: }
9500: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 9501: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
9502: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 9503: if (insttypes[k] != '_LC_external') {
1.171 raeburn 9504: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
9505: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 9506: }
9507: }
9508: return;
9509: }
9510:
1.171 raeburn 9511: function checkOffloads(item,balnum,type) {
1.150 raeburn 9512: var alltargets = new Array('$alltargets');
9513: var offloadtypes = new Array('primary','default');
9514: if (item.checked) {
9515: var total = alltargets.length - 1;
9516: var other;
9517: if (type == offloadtypes[0]) {
1.151 raeburn 9518: other = offloadtypes[1];
1.150 raeburn 9519: } else {
1.151 raeburn 9520: other = offloadtypes[0];
1.150 raeburn 9521: }
9522: for (var i=0; i<total; i++) {
1.171 raeburn 9523: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 9524: if (server == item.value) {
1.171 raeburn 9525: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
9526: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 9527: }
9528: }
9529: }
9530: }
9531: return;
9532: }
9533:
1.171 raeburn 9534: function singleServerToggle(balnum,type) {
9535: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 9536: if (offloadtoSelIdx == 0) {
1.171 raeburn 9537: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
9538: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 9539:
9540: } else {
1.171 raeburn 9541: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
9542: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 9543: }
9544: return;
9545: }
9546:
1.171 raeburn 9547: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 9548: if (type == '_LC_external') {
1.171 raeburn 9549: return;
1.150 raeburn 9550: }
1.171 raeburn 9551: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 9552: for (var i=0; i<typesRules.length; i++) {
9553: if (formname.elements[typesRules[i]].checked) {
9554: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 9555: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
9556: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 9557: } else {
1.171 raeburn 9558: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
9559: }
9560: }
9561: }
9562: return;
9563: }
9564:
9565: function balancerDeleteChange(balnum) {
9566: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
9567: var baltotal = document.getElementById('loadbalancing_total').value;
9568: var addtarget;
9569: var removetarget;
9570: var action = 'delete';
9571: if (document.getElementById('loadbalancing_delete_'+balnum)) {
9572: var lonhost = hostitem.value;
9573: var currIdx = currBalancers.indexOf(lonhost);
9574: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
9575: if (currIdx != -1) {
9576: currBalancers.splice(currIdx,1);
9577: }
9578: addtarget = lonhost;
9579: } else {
9580: if (currIdx == -1) {
9581: currBalancers.push(lonhost);
9582: }
9583: removetarget = lonhost;
9584: action = 'undelete';
9585: }
9586: balancerChange(balnum,baltotal,action,addtarget,removetarget);
9587: }
9588: return;
9589: }
9590:
9591: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
9592: if (baltotal > 1) {
9593: var offloadtypes = new Array('primary','default');
9594: var alltargets = new Array('$alltargets');
9595: var insttypes = new Array('$allinsttypes');
9596: for (var i=0; i<baltotal; i++) {
9597: if (i != balnum) {
9598: for (var j=0; j<offloadtypes.length; j++) {
9599: var total = alltargets.length - 1;
9600: for (var k=0; k<total; k++) {
9601: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
9602: var server = serveritem.value;
9603: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
9604: if (server == addtarget) {
9605: serveritem.disabled = '';
9606: }
9607: }
9608: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
9609: if (server == removetarget) {
9610: serveritem.disabled = 'disabled';
9611: serveritem.checked = false;
9612: }
9613: }
9614: }
9615: }
9616: for (var j=0; j<insttypes.length; j++) {
9617: if (insttypes[j] != '_LC_external') {
9618: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
9619: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
9620: var currSel = singleserver.selectedIndex;
9621: var currVal = singleserver.options[currSel].value;
9622: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
9623: var numoptions = singleserver.options.length;
9624: var needsnew = 1;
9625: for (var k=0; k<numoptions; k++) {
9626: if (singleserver.options[k] == addtarget) {
9627: needsnew = 0;
9628: break;
9629: }
9630: }
9631: if (needsnew == 1) {
9632: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
9633: }
9634: }
9635: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
9636: singleserver.options.length = 0;
9637: if ((currVal) && (currVal != removetarget)) {
9638: singleserver.options[0] = new Option("","",false,false);
9639: } else {
9640: singleserver.options[0] = new Option("","",true,true);
9641: }
9642: var idx = 0;
9643: for (var m=0; m<alltargets.length; m++) {
9644: if (currBalancers.indexOf(alltargets[m]) == -1) {
9645: idx ++;
9646: if (currVal == alltargets[m]) {
9647: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
9648: } else {
9649: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
9650: }
9651: }
9652: }
9653: }
9654: }
9655: }
9656: }
1.150 raeburn 9657: }
9658: }
9659: }
9660: return;
9661: }
9662:
1.152 raeburn 9663: // ]]>
9664: </script>
9665:
9666: END
9667: }
9668:
9669: sub new_spares_js {
9670: my @sparestypes = ('primary','default');
9671: my $types = join("','",@sparestypes);
9672: my $select = &mt('Select');
9673: return <<"END";
9674:
9675: <script type="text/javascript">
9676: // <![CDATA[
9677:
9678: function updateNewSpares(formname,lonhost) {
9679: var types = new Array('$types');
9680: var include = new Array();
9681: var exclude = new Array();
9682: for (var i=0; i<types.length; i++) {
9683: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
9684: for (var j=0; j<spareboxes.length; j++) {
9685: if (formname.elements[spareboxes[j]].checked) {
9686: exclude.push(formname.elements[spareboxes[j]].value);
9687: } else {
9688: include.push(formname.elements[spareboxes[j]].value);
9689: }
9690: }
9691: }
9692: for (var i=0; i<types.length; i++) {
9693: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
9694: var selIdx = newSpare.selectedIndex;
9695: var currnew = newSpare.options[selIdx].value;
9696: var okSpares = new Array();
9697: for (var j=0; j<newSpare.options.length; j++) {
9698: var possible = newSpare.options[j].value;
9699: if (possible != '') {
9700: if (exclude.indexOf(possible) == -1) {
9701: okSpares.push(possible);
9702: } else {
9703: if (currnew == possible) {
9704: selIdx = 0;
9705: }
9706: }
9707: }
9708: }
9709: for (var k=0; k<include.length; k++) {
9710: if (okSpares.indexOf(include[k]) == -1) {
9711: okSpares.push(include[k]);
9712: }
9713: }
9714: okSpares.sort();
9715: newSpare.options.length = 0;
9716: if (selIdx == 0) {
9717: newSpare.options[0] = new Option("$select","",true,true);
9718: } else {
9719: newSpare.options[0] = new Option("$select","",false,false);
9720: }
9721: for (var m=0; m<okSpares.length; m++) {
9722: var idx = m+1;
9723: var selThis = 0;
9724: if (selIdx != 0) {
9725: if (okSpares[m] == currnew) {
9726: selThis = 1;
9727: }
9728: }
9729: if (selThis == 1) {
9730: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
9731: } else {
9732: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
9733: }
9734: }
9735: }
9736: return;
9737: }
9738:
9739: function checkNewSpares(lonhost,type) {
9740: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
9741: var chosen = newSpare.options[newSpare.selectedIndex].value;
9742: if (chosen != '') {
9743: var othertype;
9744: var othernewSpare;
9745: if (type == 'primary') {
9746: othernewSpare = document.getElementById('newspare_default_'+lonhost);
9747: }
9748: if (type == 'default') {
9749: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
9750: }
9751: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
9752: othernewSpare.selectedIndex = 0;
9753: }
9754: }
9755: return;
9756: }
9757:
9758: // ]]>
9759: </script>
9760:
9761: END
9762:
9763: }
9764:
9765: sub common_domprefs_js {
9766: return <<"END";
9767:
9768: <script type="text/javascript">
9769: // <![CDATA[
9770:
1.150 raeburn 9771: function getIndicesByName(formname,item) {
1.152 raeburn 9772: var group = new Array();
1.150 raeburn 9773: for (var i=0;i<formname.elements.length;i++) {
9774: if (formname.elements[i].name == item) {
1.152 raeburn 9775: group.push(formname.elements[i].id);
1.150 raeburn 9776: }
9777: }
1.152 raeburn 9778: return group;
1.150 raeburn 9779: }
9780:
9781: // ]]>
9782: </script>
9783:
9784: END
1.152 raeburn 9785:
1.150 raeburn 9786: }
9787:
1.165 raeburn 9788: sub recaptcha_js {
9789: my %lt = &captcha_phrases();
9790: return <<"END";
9791:
9792: <script type="text/javascript">
9793: // <![CDATA[
9794:
9795: function updateCaptcha(caller,context) {
9796: var privitem;
9797: var pubitem;
9798: var privtext;
9799: var pubtext;
9800: if (document.getElementById(context+'_recaptchapub')) {
9801: pubitem = document.getElementById(context+'_recaptchapub');
9802: } else {
9803: return;
9804: }
9805: if (document.getElementById(context+'_recaptchapriv')) {
9806: privitem = document.getElementById(context+'_recaptchapriv');
9807: } else {
9808: return;
9809: }
9810: if (document.getElementById(context+'_recaptchapubtxt')) {
9811: pubtext = document.getElementById(context+'_recaptchapubtxt');
9812: } else {
9813: return;
9814: }
9815: if (document.getElementById(context+'_recaptchaprivtxt')) {
9816: privtext = document.getElementById(context+'_recaptchaprivtxt');
9817: } else {
9818: return;
9819: }
9820: if (caller.checked) {
9821: if (caller.value == 'recaptcha') {
9822: pubitem.type = 'text';
9823: privitem.type = 'text';
9824: pubitem.size = '40';
9825: privitem.size = '40';
9826: pubtext.innerHTML = "$lt{'pub'}";
9827: privtext.innerHTML = "$lt{'priv'}";
9828: } else {
9829: pubitem.type = 'hidden';
9830: privitem.type = 'hidden';
9831: pubtext.innerHTML = '';
9832: privtext.innerHTML = '';
9833: }
9834: }
9835: return;
9836: }
9837:
9838: // ]]>
9839: </script>
9840:
9841: END
9842:
9843: }
9844:
1.192 raeburn 9845: sub credits_js {
9846: return <<"END";
9847:
9848: <script type="text/javascript">
9849: // <![CDATA[
9850:
9851: function toggleCredits(domForm) {
9852: if (document.getElementById('credits')) {
9853: creditsitem = document.getElementById('credits');
9854: var creditsLength = domForm.coursecredits.length;
9855: if (creditsLength) {
9856: var currval;
9857: for (var i=0; i<creditsLength; i++) {
9858: if (domForm.coursecredits[i].checked) {
9859: currval = domForm.coursecredits[i].value;
9860: }
9861: }
9862: if (currval == 1) {
9863: creditsitem.style.display = 'block';
9864: } else {
9865: creditsitem.style.display = 'none';
9866: }
9867: }
9868: }
9869: return;
9870: }
9871:
9872: // ]]>
9873: </script>
9874:
9875: END
9876:
9877: }
9878:
1.165 raeburn 9879: sub captcha_phrases {
9880: return &Apache::lonlocal::texthash (
9881: priv => 'Private key',
9882: pub => 'Public key',
9883: original => 'original (CAPTCHA)',
9884: recaptcha => 'successor (ReCAPTCHA)',
9885: notused => 'unused',
9886: );
9887: }
9888:
1.205 raeburn 9889: sub devalidate_remote_domconfs {
1.212 raeburn 9890: my ($dom,$cachekeys) = @_;
9891: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 9892: my %servers = &Apache::lonnet::internet_dom_servers($dom);
9893: my %thismachine;
9894: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.212 raeburn 9895: my @posscached = ('domainconfig','domdefaults');
1.205 raeburn 9896: if (keys(%servers) > 1) {
9897: foreach my $server (keys(%servers)) {
9898: next if ($thismachine{$server});
1.212 raeburn 9899: my @cached;
9900: foreach my $name (@posscached) {
9901: if ($cachekeys->{$name}) {
9902: push(@cached,&escape($name).':'.&escape($dom));
9903: }
9904: }
9905: if (@cached) {
9906: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
9907: }
1.205 raeburn 9908: }
9909: }
9910: return;
9911: }
9912:
1.3 raeburn 9913: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>