Annotation of loncom/interface/domainprefs.pm, revision 1.225
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.225 ! raeburn 4: # $Id: domainprefs.pm,v 1.224 2014/02/12 20:37:42 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
1.223 bisitz 98: default quota sizes for Authoring Spaces.
1.101 raeburn 99:
100: Outputs: 1
101:
102: $datatable - HTML containing form elements which allow settings to be changed.
103:
104: In the case of course requests, radio buttons are displayed for each institutional
105: affiliate type (and also default, and _LC_adv) for each of the course types
1.216 raeburn 106: (official, unofficial, community, and textbook). In each case the radio buttons
107: allow the selection of one of four values:
1.101 raeburn 108:
1.104 raeburn 109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 110: which have the following effects:
111:
112: 0
113:
114: =over
115:
116: - course requests are not allowed for this course types/affiliation
117:
118: =back
119:
1.104 raeburn 120: approval
1.101 raeburn 121:
122: =over
123:
124: - course requests must be approved by a Doman Coordinator in the
125: course's domain
126:
127: =back
128:
129: validate
130:
131: =over
132:
133: - an institutional validation (e.g., check requestor is instructor
134: of record) needs to be passed before the course will be created. The required
135: validation is in localenroll.pm on the primary library server for the course
136: domain.
137:
138: =back
139:
140: autolimit
141:
142: =over
143:
1.143 raeburn 144: - course requests will be processed automatically up to a limit of
1.101 raeburn 145: N requests for the course type for the particular requestor.
146: If N is undefined, there is no limit to the number of course requests
147: which a course owner may submit and have processed automatically.
148:
149: =back
150:
151: =item modify_quotas()
152:
153: =back
154:
155: =cut
156:
1.1 raeburn 157: package Apache::domainprefs;
158:
159: use strict;
160: use Apache::Constants qw(:common :http);
161: use Apache::lonnet;
162: use Apache::loncommon();
163: use Apache::lonhtmlcommon();
164: use Apache::lonlocal;
1.43 raeburn 165: use Apache::lonmsg();
1.91 raeburn 166: use Apache::lonconfigsettings;
1.69 raeburn 167: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 168: use LONCAPA::Enrollment;
1.81 raeburn 169: use LONCAPA::lonauthcgi();
1.9 raeburn 170: use File::Copy;
1.43 raeburn 171: use Locale::Language;
1.62 raeburn 172: use DateTime::TimeZone;
1.68 raeburn 173: use DateTime::Locale;
1.1 raeburn 174:
1.155 raeburn 175: my $registered_cleanup;
176: my $modified_urls;
177:
1.1 raeburn 178: sub handler {
179: my $r=shift;
180: if ($r->header_only) {
181: &Apache::loncommon::content_type($r,'text/html');
182: $r->send_http_header;
183: return OK;
184: }
185:
1.91 raeburn 186: my $context = 'domain';
1.1 raeburn 187: my $dom = $env{'request.role.domain'};
1.5 albertel 188: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 189: if (&Apache::lonnet::allowed('mau',$dom)) {
190: &Apache::loncommon::content_type($r,'text/html');
191: $r->send_http_header;
192: } else {
193: $env{'user.error.msg'}=
194: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
195: return HTTP_NOT_ACCEPTABLE;
196: }
1.155 raeburn 197:
198: $registered_cleanup=0;
199: @{$modified_urls}=();
200:
1.1 raeburn 201: &Apache::lonhtmlcommon::clear_breadcrumbs();
202: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 203: ['phase','actions']);
1.30 raeburn 204: my $phase = 'pickactions';
1.3 raeburn 205: if ( exists($env{'form.phase'}) ) {
206: $phase = $env{'form.phase'};
207: }
1.150 raeburn 208: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 209: my %domconfig =
1.6 raeburn 210: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 211: 'quotas','autoenroll','autoupdate','autocreate',
212: 'directorysrch','usercreation','usermodification',
213: 'contacts','defaults','scantron','coursecategories',
214: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 215: 'coursedefaults','usersessions','loadbalancing',
216: 'requestauthor'],$dom);
1.43 raeburn 217: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 218: 'autoupdate','autocreate','directorysrch','contacts',
1.224 raeburn 219: 'usercreation','selfcreation','usermodification','scantron',
1.163 raeburn 220: 'requestcourses','requestauthor','coursecategories',
221: 'serverstatuses','helpsettings',
1.137 raeburn 222: 'coursedefaults','usersessions');
1.171 raeburn 223: my %existing;
224: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
225: %existing = %{$domconfig{'loadbalancing'}};
226: }
227: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 228: push(@prefs_order,'loadbalancing');
229: }
1.30 raeburn 230: my %prefs = (
231: 'rolecolors' =>
232: { text => 'Default color schemes',
1.67 raeburn 233: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 234: header => [{col1 => 'Student Settings',
235: col2 => '',},
236: {col1 => 'Coordinator Settings',
237: col2 => '',},
238: {col1 => 'Author Settings',
239: col2 => '',},
240: {col1 => 'Administrator Settings',
241: col2 => '',}],
242: },
1.110 raeburn 243: 'login' =>
1.30 raeburn 244: { text => 'Log-in page options',
1.67 raeburn 245: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 246: header => [{col1 => 'Log-in Page Items',
247: col2 => '',},
248: {col1 => 'Log-in Help',
249: col2 => 'Value'}],
1.30 raeburn 250: },
1.43 raeburn 251: 'defaults' =>
1.141 raeburn 252: { text => 'Default authentication/language/timezone/portal',
1.67 raeburn 253: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 254: header => [{col1 => 'Setting',
255: col2 => 'Value'}],
256: },
1.30 raeburn 257: 'quotas' =>
1.197 raeburn 258: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 259: help => 'Domain_Configuration_Quotas',
1.77 raeburn 260: header => [{col1 => 'User affiliation',
1.72 raeburn 261: col2 => 'Available tools',
1.213 raeburn 262: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.30 raeburn 263: },
264: 'autoenroll' =>
265: { text => 'Auto-enrollment settings',
1.67 raeburn 266: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 267: header => [{col1 => 'Configuration setting',
268: col2 => 'Value(s)'}],
269: },
270: 'autoupdate' =>
271: { text => 'Auto-update settings',
1.67 raeburn 272: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 273: header => [{col1 => 'Setting',
274: col2 => 'Value',},
1.131 raeburn 275: {col1 => 'Setting',
276: col2 => 'Affiliation'},
1.43 raeburn 277: {col1 => 'User population',
1.131 raeburn 278: col2 => 'Updateable user data'}],
1.30 raeburn 279: },
1.125 raeburn 280: 'autocreate' =>
281: { text => 'Auto-course creation settings',
282: help => 'Domain_Configuration_Auto_Creation',
283: header => [{col1 => 'Configuration Setting',
284: col2 => 'Value',}],
285: },
1.30 raeburn 286: 'directorysrch' =>
287: { text => 'Institutional directory searches',
1.67 raeburn 288: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 289: header => [{col1 => 'Setting',
290: col2 => 'Value',}],
291: },
292: 'contacts' =>
293: { text => 'Contact Information',
1.67 raeburn 294: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 295: header => [{col1 => 'Setting',
296: col2 => 'Value',}],
297: },
298: 'usercreation' =>
299: { text => 'User creation',
1.67 raeburn 300: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 301: header => [{col1 => 'Format rule type',
302: col2 => 'Format rules in force'},
1.34 raeburn 303: {col1 => 'User account creation',
304: col2 => 'Usernames which may be created',},
1.30 raeburn 305: {col1 => 'Context',
1.43 raeburn 306: col2 => 'Assignable authentication types'}],
1.30 raeburn 307: },
1.224 raeburn 308: 'selfcreation' =>
309: { text => 'Users self-creating accounts',
310: help => 'Domain_Configuration_Self_Creation',
311: header => [{col1 => 'Self-creation with institutional username',
312: col2 => 'Enabled?'},
313: {col1 => 'Institutional user type (login/SSO self-creation)',
314: col2 => 'Information user can enter'},
315: {col1 => 'Self-creation with e-mail as username',
316: col2 => 'Settings'}],
317: },
1.69 raeburn 318: 'usermodification' =>
1.33 raeburn 319: { text => 'User modification',
1.67 raeburn 320: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 321: header => [{col1 => 'Target user has role',
322: col2 => 'User information updateable in author context'},
323: {col1 => 'Target user has role',
1.224 raeburn 324: col2 => 'User information updateable in course context'}],
1.33 raeburn 325: },
1.69 raeburn 326: 'scantron' =>
1.95 www 327: { text => 'Bubblesheet format file',
1.67 raeburn 328: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 329: header => [ {col1 => 'Item',
330: col2 => '',
331: }],
332: },
1.86 raeburn 333: 'requestcourses' =>
334: {text => 'Request creation of courses',
335: help => 'Domain_Configuration_Request_Courses',
336: header => [{col1 => 'User affiliation',
1.102 raeburn 337: col2 => 'Availability/Processing of requests',},
338: {col1 => 'Setting',
1.216 raeburn 339: col2 => 'Value'},
340: {col1 => 'Available textbooks',
341: col2 => ''}],
1.86 raeburn 342: },
1.163 raeburn 343: 'requestauthor' =>
1.223 bisitz 344: {text => 'Request Authoring Space',
1.163 raeburn 345: help => 'Domain_Configuration_Request_Author',
346: header => [{col1 => 'User affiliation',
347: col2 => 'Availability/Processing of requests',},
348: {col1 => 'Setting',
349: col2 => 'Value'}],
350: },
1.69 raeburn 351: 'coursecategories' =>
1.120 raeburn 352: { text => 'Cataloging of courses/communities',
1.67 raeburn 353: help => 'Domain_Configuration_Cataloging_Courses',
1.69 raeburn 354: header => [{col1 => 'Category settings',
1.57 raeburn 355: col2 => '',},
356: {col1 => 'Categories',
357: col2 => '',
358: }],
1.69 raeburn 359: },
360: 'serverstatuses' =>
1.77 raeburn 361: {text => 'Access to server status pages',
1.69 raeburn 362: help => 'Domain_Configuration_Server_Status',
363: header => [{col1 => 'Status Page',
364: col2 => 'Other named users',
365: col3 => 'Specific IPs',
366: }],
367: },
1.118 jms 368: 'helpsettings' =>
369: {text => 'Help page settings',
370: help => 'Domain_Configuration_Help_Settings',
1.166 raeburn 371: header => [{col1 => 'Help Settings (logged-in users)',
372: col2 => 'Value'}],
1.118 jms 373: },
1.121 raeburn 374: 'coursedefaults' =>
375: {text => 'Course/Community defaults',
376: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 377: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
378: col2 => 'Value',},
379: {col1 => 'Defaults which can be overridden for each course by a DC',
380: col2 => 'Value',},],
1.121 raeburn 381: },
1.120 raeburn 382: 'privacy' =>
383: {text => 'User Privacy',
384: help => 'Domain_Configuration_User_Privacy',
385: header => [{col1 => 'Setting',
386: col2 => 'Value',}],
387: },
1.141 raeburn 388: 'usersessions' =>
1.145 raeburn 389: {text => 'User session hosting/offloading',
1.137 raeburn 390: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 391: header => [{col1 => 'Domain server',
392: col2 => 'Servers to offload sessions to when busy'},
393: {col1 => 'Hosting of users from other domains',
1.137 raeburn 394: col2 => 'Rules'},
395: {col1 => "Hosting domain's own users elsewhere",
396: col2 => 'Rules'}],
397: },
1.150 raeburn 398: 'loadbalancing' =>
1.185 raeburn 399: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 400: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 401: header => [{col1 => 'Balancers',
1.150 raeburn 402: col2 => 'Default destinations',
1.183 bisitz 403: col3 => 'User affiliation',
1.150 raeburn 404: col4 => 'Overrides'},
405: ],
406: },
1.3 raeburn 407: );
1.110 raeburn 408: if (keys(%servers) > 1) {
409: $prefs{'login'} = { text => 'Log-in page options',
410: help => 'Domain_Configuration_Login_Page',
411: header => [{col1 => 'Log-in Service',
412: col2 => 'Server Setting',},
413: {col1 => 'Log-in Page Items',
1.168 raeburn 414: col2 => ''},
415: {col1 => 'Log-in Help',
416: col2 => 'Value'}],
1.110 raeburn 417: };
418: }
1.174 foxr 419:
1.6 raeburn 420: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 421: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 422: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 423: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 424: text=>"Settings to display/modify"});
1.9 raeburn 425: my $confname = $dom.'-domainconfig';
1.174 foxr 426:
1.3 raeburn 427: if ($phase eq 'process') {
1.212 raeburn 428: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
429: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 430: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 431: $r->rflush();
1.212 raeburn 432: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 433: }
1.30 raeburn 434: } elsif ($phase eq 'display') {
1.192 raeburn 435: my $js = &recaptcha_js().
436: &credits_js();
1.171 raeburn 437: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 438: my ($othertitle,$usertypes,$types) =
439: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 440: $js .= &lonbalance_targets_js($dom,$types,\%servers,
441: $domconfig{'loadbalancing'}).
1.170 raeburn 442: &new_spares_js().
443: &common_domprefs_js().
444: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 445: }
1.216 raeburn 446: if (grep(/^requestcourses$/,@actions)) {
447: my $javascript_validations;
448: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
449: $js .= <<END;
450: <script type="text/javascript">
451: $javascript_validations
452: </script>
453: $coursebrowserjs
454: END
455: }
1.150 raeburn 456: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 457: } else {
1.180 raeburn 458: # check if domconfig user exists for the domain.
459: my $servadm = $r->dir_config('lonAdmEMail');
460: my ($configuserok,$author_ok,$switchserver) =
461: &config_check($dom,$confname,$servadm);
462: unless ($configuserok eq 'ok') {
1.181 raeburn 463: &Apache::lonconfigsettings::print_header($r,$phase,$context);
464: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 465: $confname).
1.181 raeburn 466: '<br />'
467: );
1.180 raeburn 468: if ($switchserver) {
1.181 raeburn 469: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
470: '<br />'.
471: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
472: '<br />'.
473: &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
474: '<br />'.
475: &mt('To do that now, use the following link: [_1]',$switchserver)
476: );
477: } else {
478: $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
479: '<br />'.
480: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
481: );
1.180 raeburn 482: }
483: $r->print(&Apache::loncommon::end_page());
484: return OK;
485: }
1.21 raeburn 486: if (keys(%domconfig) == 0) {
487: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 488: my @ids=&Apache::lonnet::current_machine_ids();
489: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 490: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 491: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 492: my $custom_img_count = 0;
493: foreach my $img (@loginimages) {
494: if ($designhash{$dom.'.login.'.$img} ne '') {
495: $custom_img_count ++;
496: }
497: }
498: foreach my $role (@roles) {
499: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
500: $custom_img_count ++;
501: }
502: }
503: if ($custom_img_count > 0) {
1.94 raeburn 504: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 505: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 506: $r->print(
507: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
508: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
509: &mt("Thereafter, (with a Domain Coordinator role selected in the domain) you will be able to update settings when logged in to any server in the LON-CAPA network.").'<br />'.
510: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
511: if ($switch_server) {
1.30 raeburn 512: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 513: }
1.91 raeburn 514: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 515: return OK;
516: }
517: }
518: }
1.91 raeburn 519: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 520: }
521: return OK;
522: }
523:
524: sub process_changes {
1.205 raeburn 525: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 526: my %domconfig;
527: if (ref($values) eq 'HASH') {
528: %domconfig = %{$values};
529: }
1.3 raeburn 530: my $output;
531: if ($action eq 'login') {
1.205 raeburn 532: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 533: } elsif ($action eq 'rolecolors') {
1.9 raeburn 534: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 535: $lastactref,%domconfig);
1.3 raeburn 536: } elsif ($action eq 'quotas') {
1.216 raeburn 537: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 538: } elsif ($action eq 'autoenroll') {
1.205 raeburn 539: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 540: } elsif ($action eq 'autoupdate') {
541: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 542: } elsif ($action eq 'autocreate') {
543: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 544: } elsif ($action eq 'directorysrch') {
545: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 546: } elsif ($action eq 'usercreation') {
1.28 raeburn 547: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 548: } elsif ($action eq 'selfcreation') {
549: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 550: } elsif ($action eq 'usermodification') {
551: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 552: } elsif ($action eq 'contacts') {
1.205 raeburn 553: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 554: } elsif ($action eq 'defaults') {
1.212 raeburn 555: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 556: } elsif ($action eq 'scantron') {
1.205 raeburn 557: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 558: } elsif ($action eq 'coursecategories') {
559: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 560: } elsif ($action eq 'serverstatuses') {
561: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 562: } elsif ($action eq 'requestcourses') {
1.216 raeburn 563: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 564: } elsif ($action eq 'requestauthor') {
1.216 raeburn 565: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 566: } elsif ($action eq 'helpsettings') {
1.122 jms 567: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121 raeburn 568: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 569: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.137 raeburn 570: } elsif ($action eq 'usersessions') {
1.212 raeburn 571: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 572: } elsif ($action eq 'loadbalancing') {
573: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 574: }
575: return $output;
576: }
577:
578: sub print_config_box {
1.9 raeburn 579: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 580: my $rowtotal = 0;
1.49 raeburn 581: my $output;
582: if ($action eq 'coursecategories') {
583: $output = &coursecategories_javascript($settings);
1.91 raeburn 584: }
1.49 raeburn 585: $output .=
1.30 raeburn 586: '<table class="LC_nested_outer">
1.3 raeburn 587: <tr>
1.66 raeburn 588: <th align="left" valign="middle"><span class="LC_nobreak">'.
589: &mt($item->{text}).' '.
590: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
591: '</tr>';
1.30 raeburn 592: $rowtotal ++;
1.110 raeburn 593: my $numheaders = 1;
594: if (ref($item->{'header'}) eq 'ARRAY') {
595: $numheaders = scalar(@{$item->{'header'}});
596: }
597: if ($numheaders > 1) {
1.64 raeburn 598: my $colspan = '';
1.145 raeburn 599: my $rightcolspan = '';
1.210 raeburn 600: if (($action eq 'rolecolors') || ($action eq 'coursecategories') ||
1.168 raeburn 601: (($action eq 'login') && ($numheaders < 3))) {
1.64 raeburn 602: $colspan = ' colspan="2"';
603: }
1.145 raeburn 604: if ($action eq 'usersessions') {
605: $rightcolspan = ' colspan="3"';
606: }
1.30 raeburn 607: $output .= '
1.3 raeburn 608: <tr>
609: <td>
610: <table class="LC_nested">
611: <tr class="LC_info_row">
1.59 bisitz 612: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 613: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 614: </tr>';
1.69 raeburn 615: $rowtotal ++;
1.6 raeburn 616: if ($action eq 'autoupdate') {
1.30 raeburn 617: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 618: } elsif ($action eq 'usercreation') {
1.33 raeburn 619: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
1.224 raeburn 620: } elsif ($action eq 'selfcreation') {
621: $output .= &print_selfcreation('top',$dom,$settings,\$rowtotal);
1.33 raeburn 622: } elsif ($action eq 'usermodification') {
623: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57 raeburn 624: } elsif ($action eq 'coursecategories') {
625: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 626: } elsif ($action eq 'login') {
1.168 raeburn 627: if ($numheaders == 3) {
628: $colspan = ' colspan="2"';
629: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
630: } else {
631: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
632: }
1.102 raeburn 633: } elsif ($action eq 'requestcourses') {
634: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.163 raeburn 635: } elsif ($action eq 'requestauthor') {
636: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.137 raeburn 637: } elsif ($action eq 'usersessions') {
638: $output .= &print_usersessions('top',$dom,$settings,\$rowtotal);
1.122 jms 639: } elsif ($action eq 'rolecolors') {
1.30 raeburn 640: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.139 raeburn 641: } elsif ($action eq 'coursedefaults') {
642: $output .= &print_coursedefaults('top',$dom,$settings,\$rowtotal);
1.6 raeburn 643: }
1.30 raeburn 644: $output .= '
1.6 raeburn 645: </table>
646: </td>
647: </tr>
648: <tr>
649: <td>
650: <table class="LC_nested">
651: <tr class="LC_info_row">
1.59 bisitz 652: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57 raeburn 653: $output .= '
1.59 bisitz 654: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 655: </tr>';
656: $rowtotal ++;
1.6 raeburn 657: if ($action eq 'autoupdate') {
1.131 raeburn 658: $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
659: </table>
660: </td>
661: </tr>
662: <tr>
663: <td>
664: <table class="LC_nested">
665: <tr class="LC_info_row">
666: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
667: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
668: &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
669: $rowtotal ++;
1.28 raeburn 670: } elsif ($action eq 'usercreation') {
1.34 raeburn 671: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
672: </table>
673: </td>
674: </tr>
675: <tr>
676: <td>
677: <table class="LC_nested">
678: <tr class="LC_info_row">
1.59 bisitz 679: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
680: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.34 raeburn 681: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
682: $rowtotal ++;
1.224 raeburn 683: } elsif ($action eq 'selfcreation') {
684: $output .= &print_selfcreation('middle',$dom,$settings,\$rowtotal).'
1.63 raeburn 685: </table>
686: </td>
687: </tr>
688: <tr>
689: <td>
690: <table class="LC_nested">
691: <tr class="LC_info_row">
692: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 693: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
694: </tr>'.
695: &print_selfcreation('bottom',$dom,$settings,\$rowtotal);
1.63 raeburn 696: $rowtotal ++;
1.224 raeburn 697: } elsif ($action eq 'usermodification') {
698: $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal);
1.57 raeburn 699: } elsif ($action eq 'coursecategories') {
700: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 701: } elsif ($action eq 'login') {
1.168 raeburn 702: if ($numheaders == 3) {
703: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
704: </table>
705: </td>
706: </tr>
707: <tr>
708: <td>
709: <table class="LC_nested">
710: <tr class="LC_info_row">
711: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 712: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 713: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
714: $rowtotal ++;
715: } else {
716: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
717: }
1.102 raeburn 718: } elsif ($action eq 'requestcourses') {
1.216 raeburn 719: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal).
720: &print_studentcode($settings,\$rowtotal).'
721: </table>
722: </td>
723: </tr>
724: <tr>
725: <td>
726: <table class="LC_nested">
727: <tr class="LC_info_row">
728: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
729: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
730: &print_textbookcourses($dom,$settings,\$rowtotal);
1.163 raeburn 731: } elsif ($action eq 'requestauthor') {
732: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.137 raeburn 733: } elsif ($action eq 'usersessions') {
1.145 raeburn 734: $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
735: </table>
736: </td>
737: </tr>
738: <tr>
739: <td>
740: <table class="LC_nested">
741: <tr class="LC_info_row">
742: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
743: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
744: &print_usersessions('bottom',$dom,$settings,\$rowtotal);
745: $rowtotal ++;
1.139 raeburn 746: } elsif ($action eq 'coursedefaults') {
747: $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.122 jms 748: } elsif ($action eq 'rolecolors') {
1.30 raeburn 749: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 750: </table>
751: </td>
752: </tr>
753: <tr>
754: <td>
755: <table class="LC_nested">
756: <tr class="LC_info_row">
1.69 raeburn 757: <td class="LC_left_item"'.$colspan.' valign="top">'.
758: &mt($item->{'header'}->[2]->{'col1'}).'</td>
759: <td class="LC_right_item" valign="top">'.
760: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 761: </tr>'.
1.30 raeburn 762: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 763: </table>
764: </td>
765: </tr>
766: <tr>
767: <td>
768: <table class="LC_nested">
769: <tr class="LC_info_row">
1.59 bisitz 770: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
771: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 772: </tr>'.
1.30 raeburn 773: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
774: $rowtotal += 2;
1.6 raeburn 775: }
1.3 raeburn 776: } else {
1.30 raeburn 777: $output .= '
1.3 raeburn 778: <tr>
779: <td>
780: <table class="LC_nested">
1.30 raeburn 781: <tr class="LC_info_row">';
1.24 raeburn 782: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 783: $output .= '
1.59 bisitz 784: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 785: } elsif ($action eq 'serverstatuses') {
786: $output .= '
787: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
788: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
789:
1.6 raeburn 790: } else {
1.30 raeburn 791: $output .= '
1.69 raeburn 792: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
793: }
1.72 raeburn 794: if (defined($item->{'header'}->[0]->{'col3'})) {
795: $output .= '<td class="LC_left_item" valign="top">'.
796: &mt($item->{'header'}->[0]->{'col2'});
797: if ($action eq 'serverstatuses') {
798: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
799: }
1.69 raeburn 800: } else {
801: $output .= '<td class="LC_right_item" valign="top">'.
802: &mt($item->{'header'}->[0]->{'col2'});
803: }
804: $output .= '</td>';
805: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 806: if (defined($item->{'header'}->[0]->{'col4'})) {
807: $output .= '<td class="LC_left_item" valign="top">'.
808: &mt($item->{'header'}->[0]->{'col3'});
809: } else {
810: $output .= '<td class="LC_right_item" valign="top">'.
811: &mt($item->{'header'}->[0]->{'col3'});
812: }
1.69 raeburn 813: if ($action eq 'serverstatuses') {
814: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
815: }
816: $output .= '</td>';
1.6 raeburn 817: }
1.150 raeburn 818: if ($item->{'header'}->[0]->{'col4'}) {
819: $output .= '<td class="LC_right_item" valign="top">'.
820: &mt($item->{'header'}->[0]->{'col4'});
821: }
1.69 raeburn 822: $output .= '</tr>';
1.48 raeburn 823: $rowtotal ++;
1.168 raeburn 824: if ($action eq 'quotas') {
1.86 raeburn 825: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3 raeburn 826: } elsif ($action eq 'autoenroll') {
1.30 raeburn 827: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125 raeburn 828: } elsif ($action eq 'autocreate') {
829: $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23 raeburn 830: } elsif ($action eq 'directorysrch') {
1.30 raeburn 831: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 832: } elsif ($action eq 'contacts') {
1.30 raeburn 833: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 raeburn 834: } elsif ($action eq 'defaults') {
1.212 raeburn 835: $output .= &print_defaults($dom,$settings,\$rowtotal);
1.46 raeburn 836: } elsif ($action eq 'scantron') {
837: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69 raeburn 838: } elsif ($action eq 'serverstatuses') {
839: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118 jms 840: } elsif ($action eq 'helpsettings') {
1.168 raeburn 841: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.150 raeburn 842: } elsif ($action eq 'loadbalancing') {
843: $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.121 raeburn 844: }
1.3 raeburn 845: }
1.30 raeburn 846: $output .= '
1.3 raeburn 847: </table>
848: </td>
849: </tr>
1.30 raeburn 850: </table><br />';
851: return ($output,$rowtotal);
1.1 raeburn 852: }
853:
1.3 raeburn 854: sub print_login {
1.168 raeburn 855: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 856: my ($css_class,$datatable);
1.6 raeburn 857: my %choices = &login_choices();
1.110 raeburn 858:
1.168 raeburn 859: if ($caller eq 'service') {
1.149 raeburn 860: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 861: my $choice = $choices{'disallowlogin'};
862: $css_class = ' class="LC_odd_row"';
1.128 raeburn 863: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 864: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 865: '<th>'.$choices{'server'}.'</th>'.
866: '<th>'.$choices{'serverpath'}.'</th>'.
867: '<th>'.$choices{'custompath'}.'</th>'.
868: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 869: my %disallowed;
870: if (ref($settings) eq 'HASH') {
871: if (ref($settings->{'loginvia'}) eq 'HASH') {
872: %disallowed = %{$settings->{'loginvia'}};
873: }
874: }
875: foreach my $lonhost (sort(keys(%servers))) {
876: my $direct = 'selected="selected"';
1.128 raeburn 877: if (ref($disallowed{$lonhost}) eq 'HASH') {
878: if ($disallowed{$lonhost}{'server'} ne '') {
879: $direct = '';
880: }
1.110 raeburn 881: }
1.115 raeburn 882: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 883: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 884: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
885: '</option>';
1.184 raeburn 886: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 887: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 888: my $selected = '';
1.128 raeburn 889: if (ref($disallowed{$lonhost}) eq 'HASH') {
890: if ($hostid eq $disallowed{$lonhost}{'server'}) {
891: $selected = 'selected="selected"';
892: }
1.110 raeburn 893: }
894: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
895: $servers{$hostid}.'</option>';
896: }
1.128 raeburn 897: $datatable .= '</select></td>'.
898: '<td><select name="'.$lonhost.'_serverpath">';
899: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
900: my $pathname = $path;
901: if ($path eq 'custom') {
902: $pathname = &mt('Custom Path').' ->';
903: }
904: my $selected = '';
905: if (ref($disallowed{$lonhost}) eq 'HASH') {
906: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
907: $selected = 'selected="selected"';
908: }
909: } elsif ($path eq '') {
910: $selected = 'selected="selected"';
911: }
912: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
913: }
914: $datatable .= '</select></td>';
915: my ($custom,$exempt);
916: if (ref($disallowed{$lonhost}) eq 'HASH') {
917: $custom = $disallowed{$lonhost}{'custompath'};
918: $exempt = $disallowed{$lonhost}{'exempt'};
919: }
920: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
921: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
922: '</tr>';
1.110 raeburn 923: }
924: $datatable .= '</table></td></tr>';
925: return $datatable;
1.168 raeburn 926: } elsif ($caller eq 'page') {
927: my %defaultchecked = (
928: 'coursecatalog' => 'on',
1.188 raeburn 929: 'helpdesk' => 'on',
1.168 raeburn 930: 'adminmail' => 'off',
931: 'newuser' => 'off',
932: );
1.188 raeburn 933: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 934: my (%checkedon,%checkedoff);
1.42 raeburn 935: foreach my $item (@toggles) {
1.168 raeburn 936: if ($defaultchecked{$item} eq 'on') {
937: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 938: $checkedoff{$item} = ' ';
1.168 raeburn 939: } elsif ($defaultchecked{$item} eq 'off') {
940: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 941: $checkedon{$item} = ' ';
942: }
1.1 raeburn 943: }
1.168 raeburn 944: my @images = ('img','logo','domlogo','login');
945: my @logintext = ('textcol','bgcol');
946: my @bgs = ('pgbg','mainbg','sidebg');
947: my @links = ('link','alink','vlink');
948: my %designhash = &Apache::loncommon::get_domainconf($dom);
949: my %defaultdesign = %Apache::loncommon::defaultdesign;
950: my (%is_custom,%designs);
951: my %defaults = (
952: font => $defaultdesign{'login.font'},
953: );
1.6 raeburn 954: foreach my $item (@images) {
1.168 raeburn 955: $defaults{$item} = $defaultdesign{'login.'.$item};
956: $defaults{'showlogo'}{$item} = 1;
957: }
958: foreach my $item (@bgs) {
959: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 960: }
1.41 raeburn 961: foreach my $item (@logintext) {
1.168 raeburn 962: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 963: }
1.168 raeburn 964: foreach my $item (@links) {
965: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 966: }
1.168 raeburn 967: if (ref($settings) eq 'HASH') {
968: foreach my $item (@toggles) {
969: if ($settings->{$item} eq '1') {
970: $checkedon{$item} = ' checked="checked" ';
971: $checkedoff{$item} = ' ';
972: } elsif ($settings->{$item} eq '0') {
973: $checkedoff{$item} = ' checked="checked" ';
974: $checkedon{$item} = ' ';
975: }
976: }
977: foreach my $item (@images) {
978: if (defined($settings->{$item})) {
979: $designs{$item} = $settings->{$item};
980: $is_custom{$item} = 1;
981: }
982: if (defined($settings->{'showlogo'}{$item})) {
983: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
984: }
985: }
986: foreach my $item (@logintext) {
987: if ($settings->{$item} ne '') {
988: $designs{'logintext'}{$item} = $settings->{$item};
989: $is_custom{$item} = 1;
990: }
991: }
992: if ($settings->{'font'} ne '') {
993: $designs{'font'} = $settings->{'font'};
994: $is_custom{'font'} = 1;
995: }
996: foreach my $item (@bgs) {
997: if ($settings->{$item} ne '') {
998: $designs{'bgs'}{$item} = $settings->{$item};
999: $is_custom{$item} = 1;
1000: }
1001: }
1002: foreach my $item (@links) {
1003: if ($settings->{$item} ne '') {
1004: $designs{'links'}{$item} = $settings->{$item};
1005: $is_custom{$item} = 1;
1006: }
1007: }
1008: } else {
1009: if ($designhash{$dom.'.login.font'} ne '') {
1010: $designs{'font'} = $designhash{$dom.'.login.font'};
1011: $is_custom{'font'} = 1;
1012: }
1013: foreach my $item (@images) {
1014: if ($designhash{$dom.'.login.'.$item} ne '') {
1015: $designs{$item} = $designhash{$dom.'.login.'.$item};
1016: $is_custom{$item} = 1;
1017: }
1018: }
1019: foreach my $item (@bgs) {
1020: if ($designhash{$dom.'.login.'.$item} ne '') {
1021: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1022: $is_custom{$item} = 1;
1023: }
1.6 raeburn 1024: }
1.168 raeburn 1025: foreach my $item (@links) {
1026: if ($designhash{$dom.'.login.'.$item} ne '') {
1027: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1028: $is_custom{$item} = 1;
1029: }
1.6 raeburn 1030: }
1031: }
1.168 raeburn 1032: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1033: logo => 'Institution Logo',
1034: domlogo => 'Domain Logo',
1035: login => 'Login box');
1036: my $itemcount = 1;
1037: foreach my $item (@toggles) {
1038: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1039: $datatable .=
1040: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1041: '</td><td>'.
1042: '<span class="LC_nobreak"><label><input type="radio" name="'.
1043: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1044: '</label> <label><input type="radio" name="'.$item.'"'.
1045: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1046: '</tr>';
1047: $itemcount ++;
1.6 raeburn 1048: }
1.168 raeburn 1049: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1050: $datatable .= '</tr></table></td></tr>';
1051: } elsif ($caller eq 'help') {
1052: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1053: my $switchserver = &check_switchserver($dom,$confname);
1054: my $itemcount = 1;
1055: $defaulturl = '/adm/loginproblems.html';
1056: $defaulttype = 'default';
1057: %lt = &Apache::lonlocal::texthash (
1058: del => 'Delete?',
1059: rep => 'Replace:',
1060: upl => 'Upload:',
1061: default => 'Default',
1062: custom => 'Custom',
1063: );
1064: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1065: my @currlangs;
1066: if (ref($settings) eq 'HASH') {
1067: if (ref($settings->{'helpurl'}) eq 'HASH') {
1068: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1069: next if ($settings->{'helpurl'}{$key} eq '');
1070: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1071: $type{$key} = 'custom';
1072: unless ($key eq 'nolang') {
1073: push(@currlangs,$key);
1074: }
1075: }
1076: } elsif ($settings->{'helpurl'} ne '') {
1077: $type{'nolang'} = 'custom';
1078: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1079: }
1080: }
1.168 raeburn 1081: foreach my $lang ('nolang',sort(@currlangs)) {
1082: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1083: $datatable .= '<tr'.$css_class.'>';
1084: if ($url{$lang} eq '') {
1085: $url{$lang} = $defaulturl;
1086: }
1087: if ($type{$lang} eq '') {
1088: $type{$lang} = $defaulttype;
1089: }
1090: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1091: if ($lang eq 'nolang') {
1092: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1093: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1094: } else {
1095: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1096: $langchoices{$lang},
1097: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1098: }
1099: $datatable .= '</span></td>'."\n".
1100: '<td class="LC_left_item">';
1101: if ($type{$lang} eq 'custom') {
1102: $datatable .= '<span class="LC_nobreak"><label>'.
1103: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1104: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1105: } else {
1106: $datatable .= $lt{'upl'};
1107: }
1108: $datatable .='<br />';
1109: if ($switchserver) {
1110: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1111: } else {
1112: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1113: }
1.168 raeburn 1114: $datatable .= '</td></tr>';
1115: $itemcount ++;
1.6 raeburn 1116: }
1.168 raeburn 1117: my @addlangs;
1118: foreach my $lang (sort(keys(%langchoices))) {
1119: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1120: push(@addlangs,$lang);
1121: }
1122: if (@addlangs > 0) {
1123: my %toadd;
1124: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1125: $toadd{''} = &mt('Select');
1126: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1127: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1128: &mt('Add log-in help page for a specific language:').' '.
1129: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1130: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1131: if ($switchserver) {
1132: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1133: } else {
1134: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1135: }
1.168 raeburn 1136: $datatable .= '</td></tr>';
1.169 raeburn 1137: $itemcount ++;
1.6 raeburn 1138: }
1.169 raeburn 1139: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1 raeburn 1140: }
1.6 raeburn 1141: return $datatable;
1142: }
1143:
1144: sub login_choices {
1145: my %choices =
1146: &Apache::lonlocal::texthash (
1.116 bisitz 1147: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1148: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1149: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1150: disallowlogin => "Login page requests redirected",
1151: hostid => "Server",
1.128 raeburn 1152: server => "Redirect to:",
1153: serverpath => "Path",
1154: custompath => "Custom",
1155: exempt => "Exempt IP(s)",
1.110 raeburn 1156: directlogin => "No redirect",
1157: newuser => "Link to create a user account",
1158: img => "Header",
1159: logo => "Main Logo",
1160: domlogo => "Domain Logo",
1161: login => "Log-in Header",
1162: textcol => "Text color",
1163: bgcol => "Box color",
1164: bgs => "Background colors",
1165: links => "Link colors",
1166: font => "Font color",
1167: pgbg => "Header",
1168: mainbg => "Page",
1169: sidebg => "Login box",
1170: link => "Link",
1171: alink => "Active link",
1172: vlink => "Visited link",
1.6 raeburn 1173: );
1174: return %choices;
1175: }
1176:
1177: sub print_rolecolors {
1.30 raeburn 1178: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1179: my %choices = &color_font_choices();
1180: my @bgs = ('pgbg','tabbg','sidebg');
1181: my @links = ('link','alink','vlink');
1182: my @images = ('img');
1183: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1184: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1185: my %defaultdesign = %Apache::loncommon::defaultdesign;
1186: my (%is_custom,%designs);
1.200 raeburn 1187: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1188: if (ref($settings) eq 'HASH') {
1189: if (ref($settings->{$role}) eq 'HASH') {
1190: if ($settings->{$role}->{'img'} ne '') {
1191: $designs{'img'} = $settings->{$role}->{'img'};
1192: $is_custom{'img'} = 1;
1193: }
1194: if ($settings->{$role}->{'font'} ne '') {
1195: $designs{'font'} = $settings->{$role}->{'font'};
1196: $is_custom{'font'} = 1;
1197: }
1.97 tempelho 1198: if ($settings->{$role}->{'fontmenu'} ne '') {
1199: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1200: $is_custom{'fontmenu'} = 1;
1201: }
1.6 raeburn 1202: foreach my $item (@bgs) {
1203: if ($settings->{$role}->{$item} ne '') {
1204: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1205: $is_custom{$item} = 1;
1206: }
1207: }
1208: foreach my $item (@links) {
1209: if ($settings->{$role}->{$item} ne '') {
1210: $designs{'links'}{$item} = $settings->{$role}->{$item};
1211: $is_custom{$item} = 1;
1212: }
1213: }
1214: }
1215: } else {
1216: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1217: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1218: $is_custom{'img'} = 1;
1219: }
1.97 tempelho 1220: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1221: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1222: $is_custom{'fontmenu'} = 1;
1223: }
1.6 raeburn 1224: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1225: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1226: $is_custom{'font'} = 1;
1227: }
1228: foreach my $item (@bgs) {
1229: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1230: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1231: $is_custom{$item} = 1;
1232:
1233: }
1234: }
1235: foreach my $item (@links) {
1236: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1237: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1238: $is_custom{$item} = 1;
1239: }
1240: }
1241: }
1242: my $itemcount = 1;
1.30 raeburn 1243: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1244: $datatable .= '</tr></table></td></tr>';
1245: return $datatable;
1246: }
1247:
1.200 raeburn 1248: sub role_defaults {
1249: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1250: my %defaults;
1251: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1252: return %defaults;
1253: }
1254: my %defaultdesign = %Apache::loncommon::defaultdesign;
1255: if ($role eq 'login') {
1256: %defaults = (
1257: font => $defaultdesign{$role.'.font'},
1258: );
1259: if (ref($logintext) eq 'ARRAY') {
1260: foreach my $item (@{$logintext}) {
1261: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1262: }
1263: }
1264: foreach my $item (@{$images}) {
1265: $defaults{'showlogo'}{$item} = 1;
1266: }
1267: } else {
1268: %defaults = (
1269: img => $defaultdesign{$role.'.img'},
1270: font => $defaultdesign{$role.'.font'},
1271: fontmenu => $defaultdesign{$role.'.fontmenu'},
1272: );
1273: }
1274: foreach my $item (@{$bgs}) {
1275: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1276: }
1277: foreach my $item (@{$links}) {
1278: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1279: }
1280: foreach my $item (@{$images}) {
1281: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1282: }
1283: return %defaults;
1284: }
1285:
1.6 raeburn 1286: sub display_color_options {
1.9 raeburn 1287: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1288: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1289: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1290: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1291: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1292: '<td>'.$choices->{'font'}.'</td>';
1293: if (!$is_custom->{'font'}) {
1.30 raeburn 1294: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1295: } else {
1296: $datatable .= '<td> </td>';
1297: }
1.174 foxr 1298: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1299:
1.8 raeburn 1300: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1301: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1302: ' value="'.$current_color.'" /> '.
1.174 foxr 1303: ' </td></tr>';
1.107 raeburn 1304: unless ($role eq 'login') {
1305: $datatable .= '<tr'.$css_class.'>'.
1306: '<td>'.$choices->{'fontmenu'}.'</td>';
1307: if (!$is_custom->{'fontmenu'}) {
1308: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1309: } else {
1310: $datatable .= '<td> </td>';
1311: }
1.202 raeburn 1312: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1313: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1314: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1315: '<input class="colorchooser" type="text" size="10" name="'
1316: .$role.'_fontmenu"'.
1317: ' value="'.$current_color.'" /> '.
1318: ' </td></tr>';
1.97 tempelho 1319: }
1.9 raeburn 1320: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1321: foreach my $img (@{$images}) {
1.18 albertel 1322: $itemcount ++;
1.6 raeburn 1323: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1324: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1325: '<td>'.$choices->{$img};
1.41 raeburn 1326: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1327: if ($role eq 'login') {
1328: if ($img eq 'login') {
1329: $login_hdr_pick =
1.135 bisitz 1330: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1331: $logincolors =
1332: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1333: $designs,$defaults);
1.70 raeburn 1334: } elsif ($img ne 'domlogo') {
1335: $datatable.= &logo_display_options($img,$defaults,$designs);
1336: }
1337: }
1338: $datatable .= '</td>';
1.6 raeburn 1339: if ($designs->{$img} ne '') {
1340: $imgfile = $designs->{$img};
1.18 albertel 1341: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1342: } else {
1343: $imgfile = $defaults->{$img};
1344: }
1345: if ($imgfile) {
1.9 raeburn 1346: my ($showfile,$fullsize);
1347: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1348: my $urldir = $1;
1349: my $filename = $2;
1350: my @info = &Apache::lonnet::stat_file($designs->{$img});
1351: if (@info) {
1352: my $thumbfile = 'tn-'.$filename;
1353: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1354: if (@thumb) {
1355: $showfile = $urldir.'/'.$thumbfile;
1356: } else {
1357: $showfile = $imgfile;
1358: }
1359: } else {
1360: $showfile = '';
1361: }
1362: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1363: $showfile = $imgfile;
1.6 raeburn 1364: my $imgdir = $1;
1365: my $filename = $2;
1.159 raeburn 1366: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1367: $showfile = "/$imgdir/tn-".$filename;
1368: } else {
1.159 raeburn 1369: my $input = $londocroot.$imgfile;
1370: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1371: if (!-e $output) {
1.9 raeburn 1372: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1373: my ($fullwidth,$fullheight) = &check_dimensions($input);
1374: if ($fullwidth ne '' && $fullheight ne '') {
1375: if ($fullwidth > $width && $fullheight > $height) {
1376: my $size = $width.'x'.$height;
1377: system("convert -sample $size $input $output");
1.159 raeburn 1378: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1379: }
1380: }
1.6 raeburn 1381: }
1382: }
1.16 raeburn 1383: }
1.6 raeburn 1384: if ($showfile) {
1.40 raeburn 1385: if ($showfile =~ m{^/(adm|res)/}) {
1386: if ($showfile =~ m{^/res/}) {
1387: my $local_showfile =
1388: &Apache::lonnet::filelocation('',$showfile);
1389: &Apache::lonnet::repcopy($local_showfile);
1390: }
1391: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1392: }
1393: if ($imgfile) {
1394: if ($imgfile =~ m{^/(adm|res)/}) {
1395: if ($imgfile =~ m{^/res/}) {
1396: my $local_imgfile =
1397: &Apache::lonnet::filelocation('',$imgfile);
1398: &Apache::lonnet::repcopy($local_imgfile);
1399: }
1400: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1401: } else {
1402: $fullsize = $imgfile;
1403: }
1404: }
1.41 raeburn 1405: $datatable .= '<td>';
1406: if ($img eq 'login') {
1.135 bisitz 1407: $datatable .= $login_hdr_pick;
1408: }
1.41 raeburn 1409: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1410: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1411: } else {
1.201 raeburn 1412: $datatable .= '<td> </td><td class="LC_left_item">'.
1413: &mt('Upload:').'<br />';
1.6 raeburn 1414: }
1415: } else {
1.201 raeburn 1416: $datatable .= '<td> </td><td class="LC_left_item">'.
1417: &mt('Upload:').'<br />';
1.6 raeburn 1418: }
1.9 raeburn 1419: if ($switchserver) {
1420: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1421: } else {
1.135 bisitz 1422: if ($img ne 'login') { # suppress file selection for Log-in header
1423: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1424: }
1.9 raeburn 1425: }
1426: $datatable .= '</td></tr>';
1.6 raeburn 1427: }
1428: $itemcount ++;
1429: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1430: $datatable .= '<tr'.$css_class.'>'.
1431: '<td>'.$choices->{'bgs'}.'</td>';
1432: my $bgs_def;
1433: foreach my $item (@{$bgs}) {
1434: if (!$is_custom->{$item}) {
1.70 raeburn 1435: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span id="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 1436: }
1437: }
1438: if ($bgs_def) {
1.8 raeburn 1439: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1440: } else {
1441: $datatable .= '<td> </td>';
1442: }
1443: $datatable .= '<td class="LC_right_item">'.
1444: '<table border="0"><tr>';
1.174 foxr 1445:
1.6 raeburn 1446: foreach my $item (@{$bgs}) {
1.201 raeburn 1447: $datatable .= '<td align="center">'.$choices->{$item};
1.174 foxr 1448: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1449: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1450: $datatable .= ' ';
1.6 raeburn 1451: }
1.174 foxr 1452: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1453: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1454: }
1455: $datatable .= '</tr></table></td></tr>';
1456: $itemcount ++;
1457: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1458: $datatable .= '<tr'.$css_class.'>'.
1459: '<td>'.$choices->{'links'}.'</td>';
1460: my $links_def;
1461: foreach my $item (@{$links}) {
1462: if (!$is_custom->{$item}) {
1.30 raeburn 1463: $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 1464: }
1465: }
1466: if ($links_def) {
1.8 raeburn 1467: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1468: } else {
1469: $datatable .= '<td> </td>';
1470: }
1471: $datatable .= '<td class="LC_right_item">'.
1472: '<table border="0"><tr>';
1473: foreach my $item (@{$links}) {
1.174 foxr 1474: my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
1.201 raeburn 1475: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1476: if ($designs->{'links'}{$item}) {
1.174 foxr 1477: $datatable.=' ';
1.6 raeburn 1478: }
1.174 foxr 1479: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1480: '" /></td>';
1481: }
1.30 raeburn 1482: $$rowtotal += $itemcount;
1.3 raeburn 1483: return $datatable;
1484: }
1485:
1.70 raeburn 1486: sub logo_display_options {
1487: my ($img,$defaults,$designs) = @_;
1488: my $checkedon;
1489: if (ref($defaults) eq 'HASH') {
1490: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1491: if ($defaults->{'showlogo'}{$img}) {
1492: $checkedon = 'checked="checked" ';
1493: }
1494: }
1495: }
1496: if (ref($designs) eq 'HASH') {
1497: if (ref($designs->{'showlogo'}) eq 'HASH') {
1498: if (defined($designs->{'showlogo'}{$img})) {
1499: if ($designs->{'showlogo'}{$img} == 0) {
1500: $checkedon = '';
1501: } elsif ($designs->{'showlogo'}{$img} == 1) {
1502: $checkedon = 'checked="checked" ';
1503: }
1504: }
1505: }
1506: }
1507: return '<br /><label> <input type="checkbox" name="'.
1508: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1509: &mt('show').'</label>'."\n";
1510: }
1511:
1.41 raeburn 1512: sub login_header_options {
1.135 bisitz 1513: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1514: my $output = '';
1.41 raeburn 1515: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1516: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1517: if (!$is_custom->{'textcol'}) {
1518: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1519: ' ';
1520: }
1521: if (!$is_custom->{'bgcol'}) {
1522: $output .= $choices->{'bgcol'}.': '.
1523: '<span id="css_'.$role.'_font" style="background-color: '.
1524: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1525: }
1526: $output .= '<br />';
1527: }
1528: $output .='<br />';
1529: return $output;
1530: }
1531:
1532: sub login_text_colors {
1.201 raeburn 1533: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1534: my $color_menu = '<table border="0"><tr>';
1535: foreach my $item (@{$logintext}) {
1.201 raeburn 1536: $color_menu .= '<td align="center">'.$choices->{$item};
1537: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1538: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1539: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1540: }
1541: $color_menu .= '</tr></table><br />';
1542: return $color_menu;
1543: }
1544:
1545: sub image_changes {
1546: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1547: my $output;
1.135 bisitz 1548: if ($img eq 'login') {
1549: # suppress image for Log-in header
1550: } elsif (!$is_custom) {
1.70 raeburn 1551: if ($img ne 'domlogo') {
1.41 raeburn 1552: $output .= &mt('Default image:').'<br />';
1553: } else {
1554: $output .= &mt('Default in use:').'<br />';
1555: }
1556: }
1.135 bisitz 1557: if ($img eq 'login') { # suppress image for Log-in header
1558: $output .= '<td>'.$logincolors;
1.41 raeburn 1559: } else {
1.135 bisitz 1560: if ($img_import) {
1561: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1562: }
1563: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1564: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1565: if ($is_custom) {
1566: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1567: '<input type="checkbox" name="'.
1568: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1569: '</label> '.&mt('Replace:').'</span><br />';
1570: } else {
1.201 raeburn 1571: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1572: }
1.41 raeburn 1573: }
1574: return $output;
1575: }
1576:
1.3 raeburn 1577: sub print_quotas {
1.86 raeburn 1578: my ($dom,$settings,$rowtotal,$action) = @_;
1579: my $context;
1580: if ($action eq 'quotas') {
1581: $context = 'tools';
1582: } else {
1583: $context = $action;
1584: }
1.197 raeburn 1585: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1586: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1587: my $typecount = 0;
1.101 raeburn 1588: my ($css_class,%titles);
1.86 raeburn 1589: if ($context eq 'requestcourses') {
1.216 raeburn 1590: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1591: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1592: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1593: %titles = &courserequest_titles();
1.163 raeburn 1594: } elsif ($context eq 'requestauthor') {
1595: @usertools = ('author');
1596: @options = ('norequest','approval','automatic');
1.210 raeburn 1597: %titles = &authorrequest_titles();
1.86 raeburn 1598: } else {
1.162 raeburn 1599: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1600: %titles = &tool_titles();
1.86 raeburn 1601: }
1.26 raeburn 1602: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1603: foreach my $type (@{$types}) {
1.197 raeburn 1604: my ($currdefquota,$currauthorquota);
1.163 raeburn 1605: unless (($context eq 'requestcourses') ||
1606: ($context eq 'requestauthor')) {
1.86 raeburn 1607: if (ref($settings) eq 'HASH') {
1608: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1609: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1610: } else {
1611: $currdefquota = $settings->{$type};
1612: }
1.197 raeburn 1613: if (ref($settings->{authorquota}) eq 'HASH') {
1614: $currauthorquota = $settings->{authorquota}->{$type};
1615: }
1.78 raeburn 1616: }
1.72 raeburn 1617: }
1.3 raeburn 1618: if (defined($usertypes->{$type})) {
1619: $typecount ++;
1620: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1621: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1622: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1623: '<td class="LC_left_item">';
1.101 raeburn 1624: if ($context eq 'requestcourses') {
1625: $datatable .= '<table><tr>';
1626: }
1627: my %cell;
1.72 raeburn 1628: foreach my $item (@usertools) {
1.101 raeburn 1629: if ($context eq 'requestcourses') {
1630: my ($curroption,$currlimit);
1631: if (ref($settings) eq 'HASH') {
1632: if (ref($settings->{$item}) eq 'HASH') {
1633: $curroption = $settings->{$item}->{$type};
1634: if ($curroption =~ /^autolimit=(\d*)$/) {
1635: $currlimit = $1;
1636: }
1637: }
1638: }
1639: if (!$curroption) {
1640: $curroption = 'norequest';
1641: }
1642: $datatable .= '<th>'.$titles{$item}.'</th>';
1643: foreach my $option (@options) {
1644: my $val = $option;
1645: if ($option eq 'norequest') {
1646: $val = 0;
1647: }
1648: if ($option eq 'validate') {
1649: my $canvalidate = 0;
1650: if (ref($validations{$item}) eq 'HASH') {
1651: if ($validations{$item}{$type}) {
1652: $canvalidate = 1;
1653: }
1654: }
1655: next if (!$canvalidate);
1656: }
1657: my $checked = '';
1658: if ($option eq $curroption) {
1659: $checked = ' checked="checked"';
1660: } elsif ($option eq 'autolimit') {
1661: if ($curroption =~ /^autolimit/) {
1662: $checked = ' checked="checked"';
1663: }
1664: }
1665: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1666: '<input type="radio" name="crsreq_'.$item.
1667: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1668: $titles{$option}.'</label>';
1.101 raeburn 1669: if ($option eq 'autolimit') {
1.127 raeburn 1670: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1671: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1672: 'value="'.$currlimit.'" />';
1.101 raeburn 1673: }
1.127 raeburn 1674: $cell{$item} .= '</span> ';
1.103 raeburn 1675: if ($option eq 'autolimit') {
1.127 raeburn 1676: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1677: }
1.101 raeburn 1678: }
1.163 raeburn 1679: } elsif ($context eq 'requestauthor') {
1680: my $curroption;
1681: if (ref($settings) eq 'HASH') {
1682: $curroption = $settings->{$type};
1683: }
1684: if (!$curroption) {
1685: $curroption = 'norequest';
1686: }
1687: foreach my $option (@options) {
1688: my $val = $option;
1689: if ($option eq 'norequest') {
1690: $val = 0;
1691: }
1692: my $checked = '';
1693: if ($option eq $curroption) {
1694: $checked = ' checked="checked"';
1695: }
1696: $datatable .= '<span class="LC_nobreak"><label>'.
1697: '<input type="radio" name="authorreq_'.$type.
1698: '" value="'.$val.'"'.$checked.' />'.
1699: $titles{$option}.'</label></span> ';
1700: }
1.101 raeburn 1701: } else {
1702: my $checked = 'checked="checked" ';
1703: if (ref($settings) eq 'HASH') {
1704: if (ref($settings->{$item}) eq 'HASH') {
1705: if ($settings->{$item}->{$type} == 0) {
1706: $checked = '';
1707: } elsif ($settings->{$item}->{$type} == 1) {
1708: $checked = 'checked="checked" ';
1709: }
1.78 raeburn 1710: }
1.72 raeburn 1711: }
1.101 raeburn 1712: $datatable .= '<span class="LC_nobreak"><label>'.
1713: '<input type="checkbox" name="'.$context.'_'.$item.
1714: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1715: '</label></span> ';
1.72 raeburn 1716: }
1.101 raeburn 1717: }
1718: if ($context eq 'requestcourses') {
1719: $datatable .= '</tr><tr>';
1720: foreach my $item (@usertools) {
1.106 raeburn 1721: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1722: }
1723: $datatable .= '</tr></table>';
1.72 raeburn 1724: }
1.86 raeburn 1725: $datatable .= '</td>';
1.163 raeburn 1726: unless (($context eq 'requestcourses') ||
1727: ($context eq 'requestauthor')) {
1.86 raeburn 1728: $datatable .=
1.197 raeburn 1729: '<td class="LC_right_item">'.
1730: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1731: '<input type="text" name="quota_'.$type.
1.72 raeburn 1732: '" value="'.$currdefquota.
1.197 raeburn 1733: '" size="5" /></span>'.(' ' x 2).
1734: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1735: '<input type="text" name="authorquota_'.$type.
1736: '" value="'.$currauthorquota.
1737: '" size="5" /></span></td>';
1.86 raeburn 1738: }
1739: $datatable .= '</tr>';
1.3 raeburn 1740: }
1741: }
1742: }
1.163 raeburn 1743: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1744: $defaultquota = '20';
1.197 raeburn 1745: $authorquota = '500';
1.86 raeburn 1746: if (ref($settings) eq 'HASH') {
1747: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1748: $defaultquota = $settings->{'defaultquota'}->{'default'};
1749: } elsif (defined($settings->{'default'})) {
1750: $defaultquota = $settings->{'default'};
1751: }
1.197 raeburn 1752: if (ref($settings->{'authorquota'}) eq 'HASH') {
1753: $authorquota = $settings->{'authorquota'}->{'default'};
1754: }
1.3 raeburn 1755: }
1756: }
1757: $typecount ++;
1758: $css_class = $typecount%2?' class="LC_odd_row"':'';
1759: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1760: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1761: '<td class="LC_left_item">';
1.101 raeburn 1762: if ($context eq 'requestcourses') {
1763: $datatable .= '<table><tr>';
1764: }
1765: my %defcell;
1.72 raeburn 1766: foreach my $item (@usertools) {
1.101 raeburn 1767: if ($context eq 'requestcourses') {
1768: my ($curroption,$currlimit);
1769: if (ref($settings) eq 'HASH') {
1770: if (ref($settings->{$item}) eq 'HASH') {
1771: $curroption = $settings->{$item}->{'default'};
1772: if ($curroption =~ /^autolimit=(\d*)$/) {
1773: $currlimit = $1;
1774: }
1775: }
1776: }
1777: if (!$curroption) {
1778: $curroption = 'norequest';
1779: }
1780: $datatable .= '<th>'.$titles{$item}.'</th>';
1781: foreach my $option (@options) {
1782: my $val = $option;
1783: if ($option eq 'norequest') {
1784: $val = 0;
1785: }
1786: if ($option eq 'validate') {
1787: my $canvalidate = 0;
1788: if (ref($validations{$item}) eq 'HASH') {
1789: if ($validations{$item}{'default'}) {
1790: $canvalidate = 1;
1791: }
1792: }
1793: next if (!$canvalidate);
1794: }
1795: my $checked = '';
1796: if ($option eq $curroption) {
1797: $checked = ' checked="checked"';
1798: } elsif ($option eq 'autolimit') {
1799: if ($curroption =~ /^autolimit/) {
1800: $checked = ' checked="checked"';
1801: }
1802: }
1803: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1804: '<input type="radio" name="crsreq_'.$item.
1805: '_default" value="'.$val.'"'.$checked.' />'.
1806: $titles{$option}.'</label>';
1807: if ($option eq 'autolimit') {
1.127 raeburn 1808: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1809: $item.'_limit_default" size="1" '.
1810: 'value="'.$currlimit.'" />';
1811: }
1.127 raeburn 1812: $defcell{$item} .= '</span> ';
1.104 raeburn 1813: if ($option eq 'autolimit') {
1.127 raeburn 1814: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1815: }
1.101 raeburn 1816: }
1.163 raeburn 1817: } elsif ($context eq 'requestauthor') {
1818: my $curroption;
1819: if (ref($settings) eq 'HASH') {
1.172 raeburn 1820: $curroption = $settings->{'default'};
1.163 raeburn 1821: }
1822: if (!$curroption) {
1823: $curroption = 'norequest';
1824: }
1825: foreach my $option (@options) {
1826: my $val = $option;
1827: if ($option eq 'norequest') {
1828: $val = 0;
1829: }
1830: my $checked = '';
1831: if ($option eq $curroption) {
1832: $checked = ' checked="checked"';
1833: }
1834: $datatable .= '<span class="LC_nobreak"><label>'.
1835: '<input type="radio" name="authorreq_default"'.
1836: ' value="'.$val.'"'.$checked.' />'.
1837: $titles{$option}.'</label></span> ';
1838: }
1.101 raeburn 1839: } else {
1840: my $checked = 'checked="checked" ';
1841: if (ref($settings) eq 'HASH') {
1842: if (ref($settings->{$item}) eq 'HASH') {
1843: if ($settings->{$item}->{'default'} == 0) {
1844: $checked = '';
1845: } elsif ($settings->{$item}->{'default'} == 1) {
1846: $checked = 'checked="checked" ';
1847: }
1.78 raeburn 1848: }
1.72 raeburn 1849: }
1.101 raeburn 1850: $datatable .= '<span class="LC_nobreak"><label>'.
1851: '<input type="checkbox" name="'.$context.'_'.$item.
1852: '" value="default" '.$checked.'/>'.$titles{$item}.
1853: '</label></span> ';
1854: }
1855: }
1856: if ($context eq 'requestcourses') {
1857: $datatable .= '</tr><tr>';
1858: foreach my $item (@usertools) {
1.106 raeburn 1859: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1860: }
1.101 raeburn 1861: $datatable .= '</tr></table>';
1.72 raeburn 1862: }
1.86 raeburn 1863: $datatable .= '</td>';
1.163 raeburn 1864: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 1865: $datatable .= '<td class="LC_right_item">'.
1866: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 1867: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 1868: $defaultquota.'" size="5" /></span>'.(' ' x2).
1869: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1870: '<input type="text" name="authorquota" value="'.
1871: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 1872: }
1873: $datatable .= '</tr>';
1.72 raeburn 1874: $typecount ++;
1875: $css_class = $typecount%2?' class="LC_odd_row"':'';
1876: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 1877: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 1878: if ($context eq 'requestcourses') {
1.109 raeburn 1879: $datatable .= &mt('(overrides affiliation, if set)').
1880: '</td>'.
1881: '<td class="LC_left_item">'.
1882: '<table><tr>';
1.101 raeburn 1883: } else {
1.109 raeburn 1884: $datatable .= &mt('(overrides affiliation, if checked)').
1885: '</td>'.
1886: '<td class="LC_left_item" colspan="2">'.
1887: '<br />';
1.101 raeburn 1888: }
1889: my %advcell;
1.72 raeburn 1890: foreach my $item (@usertools) {
1.101 raeburn 1891: if ($context eq 'requestcourses') {
1892: my ($curroption,$currlimit);
1893: if (ref($settings) eq 'HASH') {
1894: if (ref($settings->{$item}) eq 'HASH') {
1895: $curroption = $settings->{$item}->{'_LC_adv'};
1896: if ($curroption =~ /^autolimit=(\d*)$/) {
1897: $currlimit = $1;
1898: }
1899: }
1900: }
1901: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1902: my $checked = '';
1903: if ($curroption eq '') {
1904: $checked = ' checked="checked"';
1905: }
1906: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1907: '<input type="radio" name="crsreq_'.$item.
1908: '__LC_adv" value=""'.$checked.' />'.
1909: &mt('No override set').'</label></span> ';
1.101 raeburn 1910: foreach my $option (@options) {
1911: my $val = $option;
1912: if ($option eq 'norequest') {
1913: $val = 0;
1914: }
1915: if ($option eq 'validate') {
1916: my $canvalidate = 0;
1917: if (ref($validations{$item}) eq 'HASH') {
1918: if ($validations{$item}{'_LC_adv'}) {
1919: $canvalidate = 1;
1920: }
1921: }
1922: next if (!$canvalidate);
1923: }
1924: my $checked = '';
1.104 raeburn 1925: if ($val eq $curroption) {
1.101 raeburn 1926: $checked = ' checked="checked"';
1927: } elsif ($option eq 'autolimit') {
1928: if ($curroption =~ /^autolimit/) {
1929: $checked = ' checked="checked"';
1930: }
1931: }
1932: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1933: '<input type="radio" name="crsreq_'.$item.
1934: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1935: $titles{$option}.'</label>';
1936: if ($option eq 'autolimit') {
1.127 raeburn 1937: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1938: $item.'_limit__LC_adv" size="1" '.
1939: 'value="'.$currlimit.'" />';
1940: }
1.127 raeburn 1941: $advcell{$item} .= '</span> ';
1.104 raeburn 1942: if ($option eq 'autolimit') {
1.127 raeburn 1943: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1944: }
1.101 raeburn 1945: }
1.163 raeburn 1946: } elsif ($context eq 'requestauthor') {
1947: my $curroption;
1948: if (ref($settings) eq 'HASH') {
1949: $curroption = $settings->{'_LC_adv'};
1950: }
1951: my $checked = '';
1952: if ($curroption eq '') {
1953: $checked = ' checked="checked"';
1954: }
1955: $datatable .= '<span class="LC_nobreak"><label>'.
1956: '<input type="radio" name="authorreq__LC_adv"'.
1957: ' value=""'.$checked.' />'.
1958: &mt('No override set').'</label></span> ';
1959: foreach my $option (@options) {
1960: my $val = $option;
1961: if ($option eq 'norequest') {
1962: $val = 0;
1963: }
1964: my $checked = '';
1965: if ($val eq $curroption) {
1966: $checked = ' checked="checked"';
1967: }
1968: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 1969: '<input type="radio" name="authorreq__LC_adv"'.
1970: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 1971: $titles{$option}.'</label></span> ';
1972: }
1.101 raeburn 1973: } else {
1974: my $checked = 'checked="checked" ';
1975: if (ref($settings) eq 'HASH') {
1976: if (ref($settings->{$item}) eq 'HASH') {
1977: if ($settings->{$item}->{'_LC_adv'} == 0) {
1978: $checked = '';
1979: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1980: $checked = 'checked="checked" ';
1981: }
1.79 raeburn 1982: }
1.72 raeburn 1983: }
1.101 raeburn 1984: $datatable .= '<span class="LC_nobreak"><label>'.
1985: '<input type="checkbox" name="'.$context.'_'.$item.
1986: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1987: '</label></span> ';
1988: }
1989: }
1990: if ($context eq 'requestcourses') {
1991: $datatable .= '</tr><tr>';
1992: foreach my $item (@usertools) {
1.106 raeburn 1993: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1994: }
1.101 raeburn 1995: $datatable .= '</tr></table>';
1.72 raeburn 1996: }
1.98 raeburn 1997: $datatable .= '</td></tr>';
1.30 raeburn 1998: $$rowtotal += $typecount;
1.3 raeburn 1999: return $datatable;
2000: }
2001:
1.163 raeburn 2002: sub print_requestmail {
2003: my ($dom,$action,$settings,$rowtotal) = @_;
1.208 raeburn 2004: my ($now,$datatable,%currapp);
1.102 raeburn 2005: $now = time;
2006: if (ref($settings) eq 'HASH') {
2007: if (ref($settings->{'notify'}) eq 'HASH') {
2008: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2009: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2010: }
2011: }
2012: }
1.191 raeburn 2013: my $numinrow = 2;
1.224 raeburn 2014: my $css_class;
2015: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.163 raeburn 2016: my $text;
2017: if ($action eq 'requestcourses') {
2018: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2019: } elsif ($action eq 'requestauthor') {
2020: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2021: } else {
1.224 raeburn 2022: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2023: }
1.224 raeburn 2024: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2025: ' <td>'.$text.'</td>'.
1.102 raeburn 2026: ' <td class="LC_left_item">';
1.191 raeburn 2027: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2028: $action.'notifyapproval',%currapp);
1.191 raeburn 2029: if ($numdc > 0) {
2030: $datatable .= $table;
1.102 raeburn 2031: } else {
2032: $datatable .= &mt('There are no active Domain Coordinators');
2033: }
2034: $datatable .='</td></tr>';
2035: $$rowtotal += $rows;
2036: return $datatable;
2037: }
2038:
1.216 raeburn 2039: sub print_studentcode {
2040: my ($settings,$rowtotal) = @_;
2041: my $rownum = 0;
1.218 raeburn 2042: my ($output,%current);
2043: my @crstypes = ('official','unofficial','community','textbook');
2044: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2045: foreach my $type (@crstypes) {
2046: $current{$type} = $settings->{'uniquecode'}{$type};
2047: }
2048: }
2049: $output .= '<tr>'.
2050: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2051: '<td class="LC_left_item">';
2052: foreach my $type (@crstypes) {
2053: my $check = ' ';
2054: if ($current{$type}) {
2055: $check = ' checked="checked" ';
2056: }
2057: $output .= '<span class="LC_nobreak"><label>'.
2058: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2059: &mt($type).'</label></span>'.(' 'x2).' ';
2060: }
2061: $output .= '</td></tr>';
2062: $$rowtotal ++;
2063: return $output;
1.216 raeburn 2064: }
2065:
2066: sub print_textbookcourses {
2067: my ($dom,$settings,$rowtotal) = @_;
2068: my $rownum = 0;
2069: my $css_class;
2070: my $itemcount = 1;
2071: my $maxnum = 0;
2072: my $bookshash;
2073: if (ref($settings) eq 'HASH') {
2074: $bookshash = $settings->{'textbooks'};
2075: }
2076: my %ordered;
2077: if (ref($bookshash) eq 'HASH') {
2078: foreach my $item (keys(%{$bookshash})) {
2079: if (ref($bookshash->{$item}) eq 'HASH') {
2080: my $num = $bookshash->{$item}{'order'};
2081: $ordered{$num} = $item;
2082: }
2083: }
2084: }
2085: my $confname = $dom.'-domainconfig';
2086: my $switchserver = &check_switchserver($dom,$confname);
2087: my $maxnum = scalar(keys(%ordered));
1.217 raeburn 2088: my $datatable = &textbookcourses_javascript(\%ordered);
1.216 raeburn 2089: if (keys(%ordered)) {
2090: my @items = sort { $a <=> $b } keys(%ordered);
2091: for (my $i=0; $i<@items; $i++) {
2092: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2093: my $key = $ordered{$items[$i]};
2094: my %coursehash=&Apache::lonnet::coursedescription($key);
2095: my $coursetitle = $coursehash{'description'};
2096: my ($subject,$title,$author,$image,$imgsrc,$cdom,$cnum);
2097: if (ref($bookshash->{$key}) eq 'HASH') {
2098: $subject = $bookshash->{$key}->{'subject'};
2099: $title = $bookshash->{$key}->{'title'};
2100: $author = $bookshash->{$key}->{'author'};
2101: $image = $bookshash->{$key}->{'image'};
2102: if ($image ne '') {
2103: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2104: my $imagethumb = "$path/tn-".$imagefile;
2105: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2106: }
2107: }
1.217 raeburn 2108: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$key'".');"';
1.216 raeburn 2109: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
2110: .'<select name="'.$key.'"'.$chgstr.'>';
2111: for (my $k=0; $k<=$maxnum; $k++) {
2112: my $vpos = $k+1;
2113: my $selstr;
2114: if ($k == $i) {
2115: $selstr = ' selected="selected" ';
2116: }
2117: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2118: }
2119: $datatable .= '</select>'.(' 'x2).
2120: '<label><input type="checkbox" name="book_del" value="'.$key.'" />'.
2121: &mt('Delete?').'</label></span></td>'.
2122: '<td colspan="2">'.
2123: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="book_subject_'.$i.'" value="'.$subject.'" /></span> '.
2124: (' 'x2).
2125: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="book_title_'.$i.'" value="'.$title.'" /></span> '.
2126: (' 'x2).
2127: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="book_author_'.$i.'" value="'.$author.'" /></span> '.
2128: (' 'x2).
2129: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2130: if ($image) {
2131: $datatable .= '<span class="LC_nobreak">'.
2132: $imgsrc.
2133: '<label><input type="checkbox" name="book_image_del"'.
2134: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2135: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2136: }
2137: if ($switchserver) {
2138: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2139: } else {
2140: $datatable .= '<input type="file" name="book_image_'.$i.'" value="" />';
2141: }
2142: $datatable .= '<input type="hidden" name="book_id_'.$i.'" value="'.$key.'" /></span> '.
2143: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2144: $coursetitle.'</span></td></tr>'."\n";
2145: $itemcount ++;
2146: }
2147: }
2148: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.217 raeburn 2149: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'addbook_pos'".');"';
1.216 raeburn 2150: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
2151: '<input type="hidden" name="book_maxnum" value="'.$maxnum.'" />'."\n".
2152: '<select name="addbook_pos"'.$chgstr.'>';
2153: for (my $k=0; $k<$maxnum+1; $k++) {
2154: my $vpos = $k+1;
2155: my $selstr;
2156: if ($k == $maxnum) {
2157: $selstr = ' selected="selected" ';
2158: }
2159: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2160: }
2161: $datatable .= '</select> '."\n".
2162: '<input type="checkbox" name="addbook" value="1" />'.&mt('Add').'</td>'."\n".
2163: '<td colspan="2">'.
2164: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="addbook_subject" value="" /></span> '."\n".
2165: (' 'x2).
2166: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="addbook_title" value="" /></span> '."\n".
2167: (' 'x2).
2168: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="addbook_author" value="" /></span> '."\n".
2169: (' 'x2).
2170: '<span class="LC_nobreak">'.&mt('Image:').' ';
2171: if ($switchserver) {
2172: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2173: } else {
2174: $datatable .= '<input type="file" name="addbook_image" value="" />';
2175: }
2176: $datatable .= '</span>'."\n".
2177: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2178: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'addbook_cdom').
2179: '<input type="text" size="25" name="addbook_cnum" value="" />'.
2180: &Apache::loncommon::selectcourse_link
2181: ('display','addbook_cnum','addbook_cdom',undef,undef,undef,'Course');
2182: '</span></td>'."\n".
2183: '</tr>'."\n";
2184: $itemcount ++;
2185: return $datatable;
2186: }
2187:
1.217 raeburn 2188: sub textbookcourses_javascript {
2189: my ($textbooks) = @_;
2190: return unless(ref($textbooks) eq 'HASH');
2191: my $num = scalar(keys(%{$textbooks}));
2192: my @jsarray;
2193: foreach my $item (sort {$a <=> $b } (keys(%{$textbooks}))) {
2194: push(@jsarray,$textbooks->{$item});
2195: }
2196: my $jstext = ' var textbooks = Array('."'".join("','",@jsarray)."'".');'."\n";
2197: return <<"ENDSCRIPT";
2198: <script type="text/javascript">
2199: // <![CDATA[
2200: function reorderBooks(form,item) {
2201: var changedVal;
2202: $jstext
2203: var newpos = 'addbook_pos';
2204: var current = new Array;
2205: var maxh = 1 + $num;
2206: var current = new Array;
2207: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2208: if (item == newpos) {
2209: changedVal = newitemVal;
2210: } else {
2211: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2212: current[newitemVal] = newpos;
2213: }
2214: for (var i=0; i<textbooks.length; i++) {
2215: var elementName = textbooks[i];
2216: if (elementName != item) {
2217: if (form.elements[elementName]) {
2218: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2219: current[currVal] = elementName;
2220: }
2221: }
2222: }
2223: var oldVal;
2224: for (var j=0; j<maxh; j++) {
2225: if (current[j] == undefined) {
2226: oldVal = j;
2227: }
2228: }
2229: if (oldVal < changedVal) {
2230: for (var k=oldVal+1; k<=changedVal ; k++) {
2231: var elementName = current[k];
2232: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2233: }
2234: } else {
2235: for (var k=changedVal; k<oldVal; k++) {
2236: var elementName = current[k];
2237: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2238: }
2239: }
2240: return;
2241: }
2242:
2243: // ]]>
2244: </script>
2245:
2246: ENDSCRIPT
2247: }
2248:
1.3 raeburn 2249: sub print_autoenroll {
1.30 raeburn 2250: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2251: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 2252: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 2253: if (ref($settings) eq 'HASH') {
2254: if (exists($settings->{'run'})) {
2255: if ($settings->{'run'} eq '0') {
2256: $runoff = ' checked="checked" ';
2257: $runon = ' ';
2258: } else {
2259: $runon = ' checked="checked" ';
2260: $runoff = ' ';
2261: }
2262: } else {
2263: if ($autorun) {
2264: $runon = ' checked="checked" ';
2265: $runoff = ' ';
2266: } else {
2267: $runoff = ' checked="checked" ';
2268: $runon = ' ';
2269: }
2270: }
1.129 raeburn 2271: if (exists($settings->{'co-owners'})) {
2272: if ($settings->{'co-owners'} eq '0') {
2273: $coownersoff = ' checked="checked" ';
2274: $coownerson = ' ';
2275: } else {
2276: $coownerson = ' checked="checked" ';
2277: $coownersoff = ' ';
2278: }
2279: } else {
2280: $coownersoff = ' checked="checked" ';
2281: $coownerson = ' ';
2282: }
1.3 raeburn 2283: if (exists($settings->{'sender_domain'})) {
2284: $defdom = $settings->{'sender_domain'};
2285: }
1.14 raeburn 2286: } else {
2287: if ($autorun) {
2288: $runon = ' checked="checked" ';
2289: $runoff = ' ';
2290: } else {
2291: $runoff = ' checked="checked" ';
2292: $runon = ' ';
2293: }
1.3 raeburn 2294: }
2295: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2296: my $notif_sender;
2297: if (ref($settings) eq 'HASH') {
2298: $notif_sender = $settings->{'sender_uname'};
2299: }
1.3 raeburn 2300: my $datatable='<tr class="LC_odd_row">'.
2301: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2302: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2303: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2304: $runon.' value="1" />'.&mt('Yes').'</label> '.
2305: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2306: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2307: '</tr><tr>'.
2308: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2309: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2310: &mt('username').': '.
2311: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2312: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2313: ': '.$domform.'</span></td></tr>'.
2314: '<tr class="LC_odd_row">'.
2315: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2316: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2317: '<input type="radio" name="autoassign_coowners"'.
2318: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2319: '<label><input type="radio" name="autoassign_coowners"'.
2320: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2321: '</tr>';
2322: $$rowtotal += 3;
1.3 raeburn 2323: return $datatable;
2324: }
2325:
2326: sub print_autoupdate {
1.30 raeburn 2327: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2328: my $datatable;
2329: if ($position eq 'top') {
2330: my $updateon = ' ';
2331: my $updateoff = ' checked="checked" ';
2332: my $classlistson = ' ';
2333: my $classlistsoff = ' checked="checked" ';
2334: if (ref($settings) eq 'HASH') {
2335: if ($settings->{'run'} eq '1') {
2336: $updateon = $updateoff;
2337: $updateoff = ' ';
2338: }
2339: if ($settings->{'classlists'} eq '1') {
2340: $classlistson = $classlistsoff;
2341: $classlistsoff = ' ';
2342: }
2343: }
2344: my %title = (
2345: run => 'Auto-update active?',
2346: classlists => 'Update information in classlists?',
2347: );
2348: $datatable = '<tr class="LC_odd_row">'.
2349: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2350: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2351: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2352: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2353: '<label><input type="radio" name="autoupdate_run"'.
2354: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2355: '</tr><tr>'.
2356: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2357: '<td class="LC_right_item"><span class="LC_nobreak">'.
2358: '<label><input type="radio" name="classlists"'.
2359: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2360: '<label><input type="radio" name="classlists"'.
2361: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2362: '</tr>';
1.30 raeburn 2363: $$rowtotal += 2;
1.131 raeburn 2364: } elsif ($position eq 'middle') {
2365: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2366: my $numinrow = 3;
2367: my $locknamesettings;
2368: $datatable .= &insttypes_row($settings,$types,$usertypes,
2369: $dom,$numinrow,$othertitle,
2370: 'lockablenames');
2371: $$rowtotal ++;
1.3 raeburn 2372: } else {
1.44 raeburn 2373: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2374: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2375: 'permanentemail','id');
1.33 raeburn 2376: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2377: my $numrows = 0;
1.26 raeburn 2378: if (ref($types) eq 'ARRAY') {
2379: if (@{$types} > 0) {
2380: $datatable =
2381: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2382: \@fields,$types,\$numrows);
1.30 raeburn 2383: $$rowtotal += @{$types};
1.26 raeburn 2384: }
1.3 raeburn 2385: }
2386: $datatable .=
2387: &usertype_update_row($settings,{'default' => $othertitle},
2388: \%fieldtitles,\@fields,['default'],
2389: \$numrows);
1.30 raeburn 2390: $$rowtotal ++;
1.3 raeburn 2391: }
2392: return $datatable;
2393: }
2394:
1.125 raeburn 2395: sub print_autocreate {
2396: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 2397: my (%createon,%createoff,%currhash);
1.125 raeburn 2398: my @types = ('xml','req');
2399: if (ref($settings) eq 'HASH') {
2400: foreach my $item (@types) {
2401: $createoff{$item} = ' checked="checked" ';
2402: $createon{$item} = ' ';
2403: if (exists($settings->{$item})) {
2404: if ($settings->{$item}) {
2405: $createon{$item} = ' checked="checked" ';
2406: $createoff{$item} = ' ';
2407: }
2408: }
2409: }
1.210 raeburn 2410: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 2411: $currhash{$settings->{'xmldc'}} = 1;
2412: }
1.125 raeburn 2413: } else {
2414: foreach my $item (@types) {
2415: $createoff{$item} = ' checked="checked" ';
2416: $createon{$item} = ' ';
2417: }
2418: }
2419: $$rowtotal += 2;
1.191 raeburn 2420: my $numinrow = 2;
1.125 raeburn 2421: my $datatable='<tr class="LC_odd_row">'.
2422: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2423: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2424: '<input type="radio" name="autocreate_xml"'.
2425: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2426: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2427: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2428: '</td></tr><tr>'.
2429: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2430: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2431: '<input type="radio" name="autocreate_req"'.
2432: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2433: '<label><input type="radio" name="autocreate_req"'.
2434: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 2435: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2436: 'autocreate_xmldc',%currhash);
1.125 raeburn 2437: if ($numdc > 1) {
1.143 raeburn 2438: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2439: &mt('Course creation processed as: (choose Dom. Coord.)').
2440: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2441: } else {
1.143 raeburn 2442: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2443: }
1.191 raeburn 2444: $$rowtotal += $rows;
1.125 raeburn 2445: return $datatable;
2446: }
2447:
1.23 raeburn 2448: sub print_directorysrch {
1.30 raeburn 2449: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2450: my $srchon = ' ';
2451: my $srchoff = ' checked="checked" ';
1.25 raeburn 2452: my ($exacton,$containson,$beginson);
1.24 raeburn 2453: my $localon = ' ';
2454: my $localoff = ' checked="checked" ';
1.23 raeburn 2455: if (ref($settings) eq 'HASH') {
2456: if ($settings->{'available'} eq '1') {
2457: $srchon = $srchoff;
2458: $srchoff = ' ';
2459: }
1.24 raeburn 2460: if ($settings->{'localonly'} eq '1') {
2461: $localon = $localoff;
2462: $localoff = ' ';
2463: }
1.25 raeburn 2464: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2465: foreach my $type (@{$settings->{'searchtypes'}}) {
2466: if ($type eq 'exact') {
2467: $exacton = ' checked="checked" ';
2468: } elsif ($type eq 'contains') {
2469: $containson = ' checked="checked" ';
2470: } elsif ($type eq 'begins') {
2471: $beginson = ' checked="checked" ';
2472: }
2473: }
2474: } else {
2475: if ($settings->{'searchtypes'} eq 'exact') {
2476: $exacton = ' checked="checked" ';
2477: } elsif ($settings->{'searchtypes'} eq 'contains') {
2478: $containson = ' checked="checked" ';
2479: } elsif ($settings->{'searchtypes'} eq 'specify') {
2480: $exacton = ' checked="checked" ';
2481: $containson = ' checked="checked" ';
2482: }
1.23 raeburn 2483: }
2484: }
2485: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2486: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2487:
2488: my $numinrow = 4;
1.26 raeburn 2489: my $cansrchrow = 0;
1.23 raeburn 2490: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2491: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2492: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2493: '<input type="radio" name="dirsrch_available"'.
2494: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2495: '<label><input type="radio" name="dirsrch_available"'.
2496: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2497: '</tr><tr>'.
1.30 raeburn 2498: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2499: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2500: '<input type="radio" name="dirsrch_localonly"'.
2501: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2502: '<label><input type="radio" name="dirsrch_localonly"'.
2503: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2504: '</tr>';
1.30 raeburn 2505: $$rowtotal += 2;
1.26 raeburn 2506: if (ref($usertypes) eq 'HASH') {
2507: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2508: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2509: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2510: $cansrchrow = 1;
2511: }
2512: }
2513: if ($cansrchrow) {
1.30 raeburn 2514: $$rowtotal ++;
1.26 raeburn 2515: $datatable .= '<tr>';
2516: } else {
2517: $datatable .= '<tr class="LC_odd_row">';
2518: }
1.30 raeburn 2519: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2520: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2521: foreach my $title (@{$titleorder}) {
2522: if (defined($searchtitles->{$title})) {
2523: my $check = ' ';
1.93 raeburn 2524: if (ref($settings) eq 'HASH') {
1.39 raeburn 2525: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2526: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2527: $check = ' checked="checked" ';
2528: }
1.25 raeburn 2529: }
2530: }
2531: $datatable .= '<td class="LC_left_item">'.
2532: '<span class="LC_nobreak"><label>'.
2533: '<input type="checkbox" name="searchby" '.
2534: 'value="'.$title.'"'.$check.'/>'.
2535: $searchtitles->{$title}.'</label></span></td>';
2536: }
2537: }
1.26 raeburn 2538: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2539: $$rowtotal ++;
1.26 raeburn 2540: if ($cansrchrow) {
2541: $datatable .= '<tr class="LC_odd_row">';
2542: } else {
2543: $datatable .= '<tr>';
2544: }
1.30 raeburn 2545: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2546: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2547: '<span class="LC_nobreak"><label>'.
2548: '<input type="checkbox" name="searchtypes" '.
2549: $exacton.' value="exact" />'.&mt('Exact match').
2550: '</label> '.
2551: '<label><input type="checkbox" name="searchtypes" '.
2552: $beginson.' value="begins" />'.&mt('Begins with').
2553: '</label> '.
2554: '<label><input type="checkbox" name="searchtypes" '.
2555: $containson.' value="contains" />'.&mt('Contains').
2556: '</label></span></td></tr>';
1.30 raeburn 2557: $$rowtotal ++;
1.25 raeburn 2558: return $datatable;
2559: }
2560:
1.28 raeburn 2561: sub print_contacts {
1.30 raeburn 2562: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2563: my $datatable;
2564: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2565: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2566: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.203 raeburn 2567: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2568: foreach my $type (@mailings) {
2569: $otheremails{$type} = '';
2570: }
1.134 raeburn 2571: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2572: if (ref($settings) eq 'HASH') {
2573: foreach my $item (@contacts) {
2574: if (exists($settings->{$item})) {
2575: $to{$item} = $settings->{$item};
2576: }
2577: }
2578: foreach my $type (@mailings) {
2579: if (exists($settings->{$type})) {
2580: if (ref($settings->{$type}) eq 'HASH') {
2581: foreach my $item (@contacts) {
2582: if ($settings->{$type}{$item}) {
2583: $checked{$type}{$item} = ' checked="checked" ';
2584: }
2585: }
2586: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2587: if ($type eq 'helpdeskmail') {
2588: $bccemails{$type} = $settings->{$type}{'bcc'};
2589: }
1.28 raeburn 2590: }
1.89 raeburn 2591: } elsif ($type eq 'lonstatusmail') {
2592: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2593: }
2594: }
2595: } else {
2596: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2597: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2598: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2599: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2600: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2601: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2602: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.190 raeburn 2603: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
1.203 raeburn 2604: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2605: }
2606: my ($titles,$short_titles) = &contact_titles();
2607: my $rownum = 0;
2608: my $css_class;
2609: foreach my $item (@contacts) {
1.69 raeburn 2610: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2611: $datatable .= '<tr'.$css_class.'>'.
2612: '<td><span class="LC_nobreak">'.$titles->{$item}.
2613: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2614: '<input type="text" name="'.$item.'" value="'.
2615: $to{$item}.'" /></td></tr>';
1.203 raeburn 2616: $rownum ++;
1.28 raeburn 2617: }
2618: foreach my $type (@mailings) {
1.69 raeburn 2619: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2620: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2621: '<td><span class="LC_nobreak">'.
2622: $titles->{$type}.': </span></td>'.
1.28 raeburn 2623: '<td class="LC_left_item">'.
2624: '<span class="LC_nobreak">';
2625: foreach my $item (@contacts) {
2626: $datatable .= '<label>'.
2627: '<input type="checkbox" name="'.$type.'"'.
2628: $checked{$type}{$item}.
2629: ' value="'.$item.'" />'.$short_titles->{$item}.
2630: '</label> ';
2631: }
2632: $datatable .= '</span><br />'.&mt('Others').': '.
2633: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2634: 'value="'.$otheremails{$type}.'" />';
2635: if ($type eq 'helpdeskmail') {
1.136 raeburn 2636: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2637: '<input type="text" name="'.$type.'_bcc" '.
2638: 'value="'.$bccemails{$type}.'" />';
2639: }
2640: $datatable .= '</td></tr>'."\n";
1.203 raeburn 2641: $rownum ++;
1.28 raeburn 2642: }
1.203 raeburn 2643: my %choices;
2644: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2645: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2646: &mt('LON-CAPA core group - MSU'),600,500));
2647: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2648: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2649: &mt('LON-CAPA core group - MSU'),600,500));
2650: my @toggles = ('reporterrors','reportupdates');
2651: my %defaultchecked = ('reporterrors' => 'on',
2652: 'reportupdates' => 'on');
2653: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2654: \%choices,$rownum);
2655: $datatable .= $reports;
1.30 raeburn 2656: $$rowtotal += $rownum;
1.28 raeburn 2657: return $datatable;
2658: }
2659:
1.118 jms 2660: sub print_helpsettings {
1.168 raeburn 2661: my ($dom,$confname,$settings,$rowtotal) = @_;
2662: my ($datatable,$itemcount);
1.166 raeburn 2663: $itemcount = 1;
1.168 raeburn 2664: my (%choices,%defaultchecked,@toggles);
2665: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2666: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2667: &mt('LON-CAPA bug tracker'),600,500));
2668: %defaultchecked = ('submitbugs' => 'on');
2669: @toggles = ('submitbugs',);
1.166 raeburn 2670:
1.168 raeburn 2671: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2672: \%choices,$itemcount);
1.166 raeburn 2673: return $datatable;
1.121 raeburn 2674: }
2675:
2676: sub radiobutton_prefs {
1.192 raeburn 2677: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
2678: $additional) = @_;
1.121 raeburn 2679: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2680: (ref($choices) eq 'HASH'));
2681:
1.170 raeburn 2682: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 2683:
2684: foreach my $item (@{$toggles}) {
2685: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2686: $checkedon{$item} = ' checked="checked" ';
2687: $checkedoff{$item} = ' ';
1.121 raeburn 2688: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2689: $checkedoff{$item} = ' checked="checked" ';
2690: $checkedon{$item} = ' ';
2691: }
2692: }
2693: if (ref($settings) eq 'HASH') {
1.121 raeburn 2694: foreach my $item (@{$toggles}) {
1.118 jms 2695: if ($settings->{$item} eq '1') {
2696: $checkedon{$item} = ' checked="checked" ';
2697: $checkedoff{$item} = ' ';
2698: } elsif ($settings->{$item} eq '0') {
2699: $checkedoff{$item} = ' checked="checked" ';
2700: $checkedon{$item} = ' ';
2701: }
2702: }
1.121 raeburn 2703: }
1.192 raeburn 2704: if ($onclick) {
2705: $onclick = ' onclick="'.$onclick.'"';
2706: }
1.121 raeburn 2707: foreach my $item (@{$toggles}) {
1.118 jms 2708: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2709: $datatable .=
1.192 raeburn 2710: '<tr'.$css_class.'><td valign="top">'.
2711: '<span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2712: '</span></td>'.
2713: '<td class="LC_right_item"><span class="LC_nobreak">'.
2714: '<label><input type="radio" name="'.
1.192 raeburn 2715: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2716: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 2717: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2718: '</span>'.$additional.
2719: '</td>'.
1.118 jms 2720: '</tr>';
2721: $itemcount ++;
1.121 raeburn 2722: }
2723: return ($datatable,$itemcount);
2724: }
2725:
2726: sub print_coursedefaults {
1.139 raeburn 2727: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 2728: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2729: my $itemcount = 1;
1.192 raeburn 2730: my %choices = &Apache::lonlocal::texthash (
2731: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 2732: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 2733: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2734: coursecredits => 'Credits can be specified for courses',
2735: );
1.198 raeburn 2736: my %staticdefaults = (
2737: anonsurvey_threshold => 10,
2738: uploadquota => 500,
2739: );
1.139 raeburn 2740: if ($position eq 'top') {
2741: %defaultchecked = ('canuse_pdfforms' => 'off');
1.192 raeburn 2742: @toggles = ('canuse_pdfforms');
1.139 raeburn 2743: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2744: \%choices,$itemcount);
1.139 raeburn 2745: } else {
2746: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.216 raeburn 2747: my ($currdefresponder,$def_official_credits,$def_unofficial_credits,$def_textbook_credits,
2748: %curruploadquota);
1.192 raeburn 2749: my $currusecredits = 0;
1.216 raeburn 2750: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 2751: if (ref($settings) eq 'HASH') {
2752: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 2753: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2754: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2755: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2756: }
2757: }
1.192 raeburn 2758: if (ref($settings->{'coursecredits'}) eq 'HASH') {
2759: $def_official_credits = $settings->{'coursecredits'}->{'official'};
2760: $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
1.216 raeburn 2761: $def_textbook_credits = $settings->{'coursecredits'}->{'textbook'};
2762: if (($def_official_credits ne '') || ($def_unofficial_credits ne '') ||
2763: ($def_textbook_credits ne '')) {
1.192 raeburn 2764: $currusecredits = 1;
2765: }
2766: }
1.139 raeburn 2767: }
2768: if (!$currdefresponder) {
1.198 raeburn 2769: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 2770: } elsif ($currdefresponder < 1) {
2771: $currdefresponder = 1;
2772: }
1.198 raeburn 2773: foreach my $type (@types) {
2774: if ($curruploadquota{$type} eq '') {
2775: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
2776: }
2777: }
1.139 raeburn 2778: $datatable .=
1.192 raeburn 2779: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2780: $choices{'anonsurvey_threshold'}.
1.139 raeburn 2781: '</span></td>'.
2782: '<td class="LC_right_item"><span class="LC_nobreak">'.
2783: '<input type="text" name="anonsurvey_threshold"'.
2784: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.198 raeburn 2785: '</td></tr>'."\n".
2786: '<tr><td><span class="LC_nobreak">'.
2787: $choices{'uploadquota'}.
2788: '</span></td>'.
2789: '<td align="right" class="LC_right_item">'.
2790: '<table><tr>';
2791: foreach my $type (@types) {
2792: $datatable .= '<td align="center">'.&mt($type).'<br />'.
2793: '<input type="text" name="uploadquota_'.$type.'"'.
2794: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
2795: }
2796: $datatable .= '</tr></table></td></tr>'."\n";
2797: $itemcount += 2;
1.192 raeburn 2798: my $onclick = 'toggleCredits(this.form);';
1.210 raeburn 2799: my $display = 'none';
1.192 raeburn 2800: if ($currusecredits) {
2801: $display = 'block';
2802: }
2803: my $additional = '<div id="credits" style="display: '.$display.'">'.
2804: '<span class="LC_nobreak">'.
2805: &mt('Default credits for official courses [_1]',
2806: '<input type="text" name="official_credits" value="'.
2807: $def_official_credits.'" size="3" />').
2808: '</span><br />'.
2809: '<span class="LC_nobreak">'.
2810: &mt('Default credits for unofficial courses [_1]',
2811: '<input type="text" name="unofficial_credits" value="'.
2812: $def_unofficial_credits.'" size="3" />').
1.216 raeburn 2813: '</span><br />'.
2814: '<span class="LC_nobreak">'.
2815: &mt('Default credits for textbook courses [_1]',
2816: '<input type="text" name="textbook_credits" value="'.
2817: $def_textbook_credits.'" size="3" />').
1.192 raeburn 2818: '</span></div>'."\n";
2819: %defaultchecked = ('coursecredits' => 'off');
2820: @toggles = ('coursecredits');
2821: my $current = {
2822: 'coursecredits' => $currusecredits,
2823: };
2824: (my $table,$itemcount) =
2825: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
2826: \%choices,$itemcount,$onclick,$additional);
2827: $datatable .= $table;
1.139 raeburn 2828: }
1.192 raeburn 2829: $$rowtotal += $itemcount;
1.121 raeburn 2830: return $datatable;
1.118 jms 2831: }
2832:
1.137 raeburn 2833: sub print_usersessions {
2834: my ($position,$dom,$settings,$rowtotal) = @_;
2835: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2836: my (%by_ip,%by_location,@intdoms);
2837: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 2838:
2839: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 2840: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 2841: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 2842: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 2843: my $itemcount = 1;
2844: if ($position eq 'top') {
1.152 raeburn 2845: if (keys(%serverhomes) > 1) {
1.145 raeburn 2846: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 2847: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 2848: } else {
1.140 raeburn 2849: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2850: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 2851: }
1.137 raeburn 2852: } else {
1.145 raeburn 2853: if (keys(%by_location) == 0) {
2854: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2855: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 2856: } else {
2857: my %lt = &usersession_titles();
2858: my $numinrow = 5;
2859: my $prefix;
2860: my @types;
2861: if ($position eq 'bottom') {
2862: $prefix = 'remote';
2863: @types = ('version','excludedomain','includedomain');
2864: } else {
2865: $prefix = 'hosted';
2866: @types = ('excludedomain','includedomain');
2867: }
2868: my (%current,%checkedon,%checkedoff);
2869: my @lcversions = &Apache::lonnet::all_loncaparevs();
2870: my @locations = sort(keys(%by_location));
2871: foreach my $type (@types) {
2872: $checkedon{$type} = '';
2873: $checkedoff{$type} = ' checked="checked"';
2874: }
2875: if (ref($settings) eq 'HASH') {
2876: if (ref($settings->{$prefix}) eq 'HASH') {
2877: foreach my $key (keys(%{$settings->{$prefix}})) {
2878: $current{$key} = $settings->{$prefix}{$key};
2879: if ($key eq 'version') {
2880: if ($current{$key} ne '') {
2881: $checkedon{$key} = ' checked="checked"';
2882: $checkedoff{$key} = '';
2883: }
2884: } elsif (ref($current{$key}) eq 'ARRAY') {
2885: $checkedon{$key} = ' checked="checked"';
2886: $checkedoff{$key} = '';
2887: }
1.137 raeburn 2888: }
2889: }
2890: }
1.145 raeburn 2891: foreach my $type (@types) {
2892: next if ($type ne 'version' && !@locations);
2893: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2894: $datatable .= '<tr'.$css_class.'>
2895: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2896: <span class="LC_nobreak">
2897: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2898: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2899: if ($type eq 'version') {
2900: my $selector = '<select name="'.$prefix.'_version">';
2901: foreach my $version (@lcversions) {
2902: my $selected = '';
2903: if ($current{'version'} eq $version) {
2904: $selected = ' selected="selected"';
2905: }
2906: $selector .= ' <option value="'.$version.'"'.
2907: $selected.'>'.$version.'</option>';
2908: }
2909: $selector .= '</select> ';
2910: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2911: } else {
2912: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2913: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2914: ' />'.(' 'x2).
2915: '<input type="button" value="'.&mt('uncheck all').'" '.
2916: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2917: "\n".
2918: '</div><div><table>';
2919: my $rem;
2920: for (my $i=0; $i<@locations; $i++) {
2921: my ($showloc,$value,$checkedtype);
2922: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2923: my $ip = $by_location{$locations[$i]}->[0];
2924: if (ref($by_ip{$ip}) eq 'ARRAY') {
2925: $value = join(':',@{$by_ip{$ip}});
2926: $showloc = join(', ',@{$by_ip{$ip}});
2927: if (ref($current{$type}) eq 'ARRAY') {
2928: foreach my $loc (@{$by_ip{$ip}}) {
2929: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2930: $checkedtype = ' checked="checked"';
2931: last;
2932: }
2933: }
1.138 raeburn 2934: }
2935: }
2936: }
1.145 raeburn 2937: $rem = $i%($numinrow);
2938: if ($rem == 0) {
2939: if ($i > 0) {
2940: $datatable .= '</tr>';
2941: }
2942: $datatable .= '<tr>';
2943: }
2944: $datatable .= '<td class="LC_left_item">'.
2945: '<span class="LC_nobreak"><label>'.
2946: '<input type="checkbox" name="'.$prefix.'_'.$type.
2947: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2948: '</label></span></td>';
1.137 raeburn 2949: }
1.145 raeburn 2950: $rem = @locations%($numinrow);
2951: my $colsleft = $numinrow - $rem;
2952: if ($colsleft > 1 ) {
2953: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2954: ' </td>';
2955: } elsif ($colsleft == 1) {
2956: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 2957: }
1.145 raeburn 2958: $datatable .= '</tr></table>';
1.137 raeburn 2959: }
1.145 raeburn 2960: $datatable .= '</td></tr>';
2961: $itemcount ++;
1.137 raeburn 2962: }
2963: }
2964: }
2965: $$rowtotal += $itemcount;
2966: return $datatable;
2967: }
2968:
1.138 raeburn 2969: sub build_location_hashes {
2970: my ($intdoms,$by_ip,$by_location) = @_;
2971: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2972: (ref($by_location) eq 'HASH'));
2973: my %iphost = &Apache::lonnet::get_iphost();
2974: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2975: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2976: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2977: foreach my $id (@{$iphost{$primary_ip}}) {
2978: my $intdom = &Apache::lonnet::internet_dom($id);
2979: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2980: push(@{$intdoms},$intdom);
2981: }
2982: }
2983: }
2984: foreach my $ip (keys(%iphost)) {
2985: if (ref($iphost{$ip}) eq 'ARRAY') {
2986: foreach my $id (@{$iphost{$ip}}) {
2987: my $location = &Apache::lonnet::internet_dom($id);
2988: if ($location) {
2989: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2990: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2991: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2992: push(@{$by_ip->{$ip}},$location);
2993: }
2994: } else {
2995: $by_ip->{$ip} = [$location];
2996: }
2997: }
2998: }
2999: }
3000: }
3001: foreach my $ip (sort(keys(%{$by_ip}))) {
3002: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3003: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
3004: my $first = $by_ip->{$ip}->[0];
3005: if (ref($by_location->{$first}) eq 'ARRAY') {
3006: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
3007: push(@{$by_location->{$first}},$ip);
3008: }
3009: } else {
3010: $by_location->{$first} = [$ip];
3011: }
3012: }
3013: }
3014: return;
3015: }
3016:
1.145 raeburn 3017: sub current_offloads_to {
3018: my ($dom,$settings,$servers) = @_;
3019: my (%spareid,%otherdomconfigs);
1.152 raeburn 3020: if (ref($servers) eq 'HASH') {
1.145 raeburn 3021: foreach my $lonhost (sort(keys(%{$servers}))) {
3022: my $gotspares;
1.152 raeburn 3023: if (ref($settings) eq 'HASH') {
3024: if (ref($settings->{'spares'}) eq 'HASH') {
3025: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
3026: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
3027: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
3028: $gotspares = 1;
3029: }
1.145 raeburn 3030: }
3031: }
3032: unless ($gotspares) {
3033: my $gotspares;
3034: my $serverhomeID =
3035: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
3036: my $serverhomedom =
3037: &Apache::lonnet::host_domain($serverhomeID);
3038: if ($serverhomedom ne $dom) {
3039: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
3040: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3041: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3042: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3043: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3044: $gotspares = 1;
3045: }
3046: }
3047: } else {
3048: $otherdomconfigs{$serverhomedom} =
3049: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
3050: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
3051: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3052: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3053: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
3054: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3055: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3056: $gotspares = 1;
3057: }
3058: }
3059: }
3060: }
3061: }
3062: }
3063: }
3064: unless ($gotspares) {
3065: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
3066: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3067: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3068: } else {
3069: my $server_hostname = &Apache::lonnet::hostname($lonhost);
3070: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
3071: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
3072: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3073: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3074: } else {
1.150 raeburn 3075: my %what = (
3076: spareid => 1,
3077: );
3078: my ($result,$returnhash) =
3079: &Apache::lonnet::get_remote_globals($lonhost,\%what);
3080: if ($result eq 'ok') {
3081: if (ref($returnhash) eq 'HASH') {
3082: if (ref($returnhash->{'spareid'}) eq 'HASH') {
3083: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
3084: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
3085: }
3086: }
1.145 raeburn 3087: }
3088: }
3089: }
3090: }
3091: }
3092: }
3093: return %spareid;
3094: }
3095:
3096: sub spares_row {
1.152 raeburn 3097: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 3098: my $css_class;
3099: my $numinrow = 4;
3100: my $itemcount = 1;
3101: my $datatable;
1.152 raeburn 3102: my %typetitles = &sparestype_titles();
3103: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 3104: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 3105: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
3106: my ($othercontrol,$serverdom);
3107: if ($serverhome ne $server) {
3108: $serverdom = &Apache::lonnet::host_domain($serverhome);
3109: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3110: } else {
3111: $serverdom = &Apache::lonnet::host_domain($server);
3112: if ($serverdom ne $dom) {
3113: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3114: }
3115: }
3116: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 3117: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3118: $datatable .= '<tr'.$css_class.'>
3119: <td rowspan="2">
1.183 bisitz 3120: <span class="LC_nobreak">'.
3121: &mt('[_1] when busy, offloads to:'
3122: ,'<b>'.$server.'</b>').
3123: "\n";
1.145 raeburn 3124: my (%current,%canselect);
1.152 raeburn 3125: my @choices =
3126: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
3127: foreach my $type ('primary','default') {
3128: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 3129: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
3130: my @spares = @{$spareid->{$server}{$type}};
3131: if (@spares > 0) {
1.152 raeburn 3132: if ($othercontrol) {
3133: $current{$type} = join(', ',@spares);
3134: } else {
3135: $current{$type} .= '<table>';
3136: my $numspares = scalar(@spares);
3137: for (my $i=0; $i<@spares; $i++) {
3138: my $rem = $i%($numinrow);
3139: if ($rem == 0) {
3140: if ($i > 0) {
3141: $current{$type} .= '</tr>';
3142: }
3143: $current{$type} .= '<tr>';
1.145 raeburn 3144: }
1.152 raeburn 3145: $current{$type} .= '<td><label><input type="checkbox" name="spare_'.$type.'_'.$server.'" id="spare_'.$type.'_'.$server.'_'.$i.'" checked="checked" value="'.$spareid->{$server}{$type}[$i].'" onclick="updateNewSpares(this.form,'."'$server'".');" /> '.
3146: $spareid->{$server}{$type}[$i].
3147: '</label></td>'."\n";
3148: }
3149: my $rem = @spares%($numinrow);
3150: my $colsleft = $numinrow - $rem;
3151: if ($colsleft > 1 ) {
3152: $current{$type} .= '<td colspan="'.$colsleft.
3153: '" class="LC_left_item">'.
3154: ' </td>';
3155: } elsif ($colsleft == 1) {
3156: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 3157: }
1.152 raeburn 3158: $current{$type} .= '</tr></table>';
1.150 raeburn 3159: }
1.145 raeburn 3160: }
3161: }
3162: if ($current{$type} eq '') {
3163: $current{$type} = &mt('None specified');
3164: }
1.152 raeburn 3165: if ($othercontrol) {
3166: if ($type eq 'primary') {
3167: $canselect{$type} = $othercontrol;
3168: }
3169: } else {
3170: $canselect{$type} =
3171: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
3172: '<select name="newspare_'.$type.'_'.$server.'" '.
3173: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
3174: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
3175: if (@choices > 0) {
3176: foreach my $lonhost (@choices) {
3177: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
3178: }
3179: }
3180: $canselect{$type} .= '</select>'."\n";
3181: }
3182: } else {
3183: $current{$type} = &mt('Could not be determined');
3184: if ($type eq 'primary') {
3185: $canselect{$type} = $othercontrol;
3186: }
1.145 raeburn 3187: }
1.152 raeburn 3188: if ($type eq 'default') {
3189: $datatable .= '<tr'.$css_class.'>';
3190: }
3191: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
3192: '<td>'.$current{$type}.'</td>'."\n".
3193: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 3194: }
3195: $itemcount ++;
3196: }
3197: }
3198: $$rowtotal += $itemcount;
3199: return $datatable;
3200: }
3201:
1.152 raeburn 3202: sub possible_newspares {
3203: my ($server,$currspares,$serverhomes,$altids) = @_;
3204: my $serverhostname = &Apache::lonnet::hostname($server);
3205: my %excluded;
3206: if ($serverhostname ne '') {
3207: %excluded = (
3208: $serverhostname => 1,
3209: );
3210: }
3211: if (ref($currspares) eq 'HASH') {
3212: foreach my $type (keys(%{$currspares})) {
3213: if (ref($currspares->{$type}) eq 'ARRAY') {
3214: if (@{$currspares->{$type}} > 0) {
3215: foreach my $curr (@{$currspares->{$type}}) {
3216: my $hostname = &Apache::lonnet::hostname($curr);
3217: $excluded{$hostname} = 1;
3218: }
3219: }
3220: }
3221: }
3222: }
3223: my @choices;
3224: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
3225: if (keys(%{$serverhomes}) > 1) {
3226: foreach my $name (sort(keys(%{$serverhomes}))) {
3227: unless ($excluded{$name}) {
3228: if (exists($altids->{$serverhomes->{$name}})) {
3229: push(@choices,$altids->{$serverhomes->{$name}});
3230: } else {
3231: push(@choices,$serverhomes->{$name});
1.145 raeburn 3232: }
3233: }
3234: }
3235: }
3236: }
1.152 raeburn 3237: return sort(@choices);
1.145 raeburn 3238: }
3239:
1.150 raeburn 3240: sub print_loadbalancing {
3241: my ($dom,$settings,$rowtotal) = @_;
3242: my $primary_id = &Apache::lonnet::domain($dom,'primary');
3243: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3244: my $numinrow = 1;
3245: my $datatable;
3246: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 3247: my (%currbalancer,%currtargets,%currrules,%existing);
3248: if (ref($settings) eq 'HASH') {
3249: %existing = %{$settings};
3250: }
3251: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
3252: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
3253: \%currtargets,\%currrules);
1.150 raeburn 3254: } else {
3255: return;
3256: }
3257: my ($othertitle,$usertypes,$types) =
3258: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 3259: my $rownum = 8;
1.150 raeburn 3260: if (ref($types) eq 'ARRAY') {
3261: $rownum += scalar(@{$types});
3262: }
1.171 raeburn 3263: my @css_class = ('LC_odd_row','LC_even_row');
3264: my $balnum = 0;
3265: my $islast;
3266: my (@toshow,$disabledtext);
3267: if (keys(%currbalancer) > 0) {
3268: @toshow = sort(keys(%currbalancer));
3269: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
3270: push(@toshow,'');
3271: }
3272: } else {
3273: @toshow = ('');
3274: $disabledtext = &mt('No existing load balancer');
3275: }
3276: foreach my $lonhost (@toshow) {
3277: if ($balnum == scalar(@toshow)-1) {
3278: $islast = 1;
3279: } else {
3280: $islast = 0;
3281: }
3282: my $cssidx = $balnum%2;
3283: my $targets_div_style = 'display: none';
3284: my $disabled_div_style = 'display: block';
3285: my $homedom_div_style = 'display: none';
3286: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3287: '<td rowspan="'.$rownum.'" valign="top">'.
3288: '<p>';
3289: if ($lonhost eq '') {
1.210 raeburn 3290: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 3291: if (keys(%currbalancer) > 0) {
3292: $datatable .= &mt('Add balancer:');
3293: } else {
3294: $datatable .= &mt('Enable balancer:');
3295: }
3296: $datatable .= ' '.
3297: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3298: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3299: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3300: '<option value="" selected="selected">'.&mt('None').
3301: '</option>'."\n";
3302: foreach my $server (sort(keys(%servers))) {
3303: next if ($currbalancer{$server});
3304: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3305: }
1.210 raeburn 3306: $datatable .=
1.171 raeburn 3307: '</select>'."\n".
3308: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3309: } else {
3310: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3311: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3312: &mt('Stop balancing').'</label>'.
3313: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3314: $targets_div_style = 'display: block';
3315: $disabled_div_style = 'display: none';
3316: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3317: $homedom_div_style = 'display: block';
3318: }
3319: }
3320: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3321: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3322: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3323: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3324: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3325: my @sparestypes = ('primary','default');
3326: my %typetitles = &sparestype_titles();
3327: foreach my $sparetype (@sparestypes) {
3328: my $targettable;
3329: for (my $i=0; $i<$numspares; $i++) {
3330: my $checked;
3331: if (ref($currtargets{$lonhost}) eq 'HASH') {
3332: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3333: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3334: $checked = ' checked="checked"';
3335: }
3336: }
3337: }
3338: my ($chkboxval,$disabled);
3339: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3340: $chkboxval = $spares[$i];
3341: }
3342: if (exists($currbalancer{$spares[$i]})) {
3343: $disabled = ' disabled="disabled"';
3344: }
1.210 raeburn 3345: $targettable .=
1.171 raeburn 3346: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3347: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3348: '</span></label></td>';
3349: my $rem = $i%($numinrow);
3350: if ($rem == 0) {
3351: if (($i > 0) && ($i < $numspares-1)) {
3352: $targettable .= '</tr>';
3353: }
3354: if ($i < $numspares-1) {
3355: $targettable .= '<tr>';
1.150 raeburn 3356: }
3357: }
3358: }
1.171 raeburn 3359: if ($targettable ne '') {
3360: my $rem = $numspares%($numinrow);
3361: my $colsleft = $numinrow - $rem;
3362: if ($colsleft > 1 ) {
3363: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3364: ' </td>';
3365: } elsif ($colsleft == 1) {
3366: $targettable .= '<td class="LC_left_item"> </td>';
3367: }
3368: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3369: '<table><tr>'.$targettable.'</tr></table><br />';
3370: }
3371: }
3372: $datatable .= '</div></td></tr>'.
3373: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3374: $othertitle,$usertypes,$types,\%servers,
3375: \%currbalancer,$lonhost,
3376: $targets_div_style,$homedom_div_style,
3377: $css_class[$cssidx],$balnum,$islast);
3378: $$rowtotal += $rownum;
3379: $balnum ++;
3380: }
3381: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3382: return $datatable;
3383: }
3384:
3385: sub get_loadbalancers_config {
3386: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3387: return unless ((ref($servers) eq 'HASH') &&
3388: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3389: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3390: if (keys(%{$existing}) > 0) {
3391: my $oldlonhost;
3392: foreach my $key (sort(keys(%{$existing}))) {
3393: if ($key eq 'lonhost') {
3394: $oldlonhost = $existing->{'lonhost'};
3395: $currbalancer->{$oldlonhost} = 1;
3396: } elsif ($key eq 'targets') {
3397: if ($oldlonhost) {
3398: $currtargets->{$oldlonhost} = $existing->{'targets'};
3399: }
3400: } elsif ($key eq 'rules') {
3401: if ($oldlonhost) {
3402: $currrules->{$oldlonhost} = $existing->{'rules'};
3403: }
3404: } elsif (ref($existing->{$key}) eq 'HASH') {
3405: $currbalancer->{$key} = 1;
3406: $currtargets->{$key} = $existing->{$key}{'targets'};
3407: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3408: }
3409: }
1.171 raeburn 3410: } else {
3411: my ($balancerref,$targetsref) =
3412: &Apache::lonnet::get_lonbalancer_config($servers);
3413: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3414: foreach my $server (sort(keys(%{$balancerref}))) {
3415: $currbalancer->{$server} = 1;
3416: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3417: }
3418: }
3419: }
1.171 raeburn 3420: return;
1.150 raeburn 3421: }
3422:
3423: sub loadbalancing_rules {
3424: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 3425: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3426: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3427: my $output;
1.171 raeburn 3428: my $num = 0;
1.210 raeburn 3429: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3430: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3431: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3432: foreach my $type (@{$alltypes}) {
1.171 raeburn 3433: $num ++;
1.150 raeburn 3434: my $current;
3435: if (ref($currrules) eq 'HASH') {
3436: $current = $currrules->{$type};
3437: }
1.209 raeburn 3438: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.171 raeburn 3439: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3440: $current = '';
3441: }
3442: }
3443: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 3444: $servers,$currbalancer,$lonhost,$dom,
3445: $targets_div_style,$homedom_div_style,
3446: $css_class,$balnum,$num,$islast);
1.150 raeburn 3447: }
3448: }
3449: return $output;
3450: }
3451:
3452: sub loadbalancing_titles {
3453: my ($dom,$intdom,$usertypes,$types) = @_;
3454: my %othertypes = (
3455: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3456: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3457: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3458: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 3459: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
3460: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 3461: );
1.209 raeburn 3462: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 3463: if (ref($types) eq 'ARRAY') {
3464: unshift(@alltypes,@{$types},'default');
3465: }
3466: my %titles;
3467: foreach my $type (@alltypes) {
3468: if ($type =~ /^_LC_/) {
3469: $titles{$type} = $othertypes{$type};
3470: } elsif ($type eq 'default') {
3471: $titles{$type} = &mt('All users from [_1]',$dom);
3472: if (ref($types) eq 'ARRAY') {
3473: if (@{$types} > 0) {
3474: $titles{$type} = &mt('Other users from [_1]',$dom);
3475: }
3476: }
3477: } elsif (ref($usertypes) eq 'HASH') {
3478: $titles{$type} = $usertypes->{$type};
3479: }
3480: }
3481: return (\@alltypes,\%othertypes,\%titles);
3482: }
3483:
3484: sub loadbalance_rule_row {
1.171 raeburn 3485: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3486: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 3487: my @rulenames;
1.150 raeburn 3488: my %ruletitles = &offloadtype_text();
1.209 raeburn 3489: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
3490: @rulenames = ('balancer','offloadedto');
1.150 raeburn 3491: } else {
1.209 raeburn 3492: @rulenames = ('default','homeserver');
3493: if ($type eq '_LC_external') {
3494: push(@rulenames,'externalbalancer');
3495: } else {
3496: push(@rulenames,'specific');
3497: }
3498: push(@rulenames,'none');
1.150 raeburn 3499: }
3500: my $style = $targets_div_style;
1.209 raeburn 3501: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.150 raeburn 3502: $style = $homedom_div_style;
3503: }
1.171 raeburn 3504: my $space;
3505: if ($islast && $num == 1) {
3506: $space = '<div display="inline-block"> </div>';
3507: }
1.210 raeburn 3508: my $output =
1.171 raeburn 3509: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3510: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3511: '<td valaign="top">'.$space.
3512: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3513: for (my $i=0; $i<@rulenames; $i++) {
3514: my $rule = $rulenames[$i];
3515: my ($checked,$extra);
3516: if ($rulenames[$i] eq 'default') {
3517: $rule = '';
3518: }
3519: if ($rulenames[$i] eq 'specific') {
3520: if (ref($servers) eq 'HASH') {
3521: my $default;
3522: if (($current ne '') && (exists($servers->{$current}))) {
3523: $checked = ' checked="checked"';
3524: }
3525: unless ($checked) {
3526: $default = ' selected="selected"';
3527: }
1.210 raeburn 3528: $extra =
1.171 raeburn 3529: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3530: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3531: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3532: '<option value=""'.$default.'></option>'."\n";
3533: foreach my $server (sort(keys(%{$servers}))) {
3534: if (ref($currbalancer) eq 'HASH') {
3535: next if (exists($currbalancer->{$server}));
3536: }
1.150 raeburn 3537: my $selected;
1.171 raeburn 3538: if ($server eq $current) {
1.150 raeburn 3539: $selected = ' selected="selected"';
3540: }
1.171 raeburn 3541: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3542: }
3543: $extra .= '</select>';
3544: }
3545: } elsif ($rule eq $current) {
3546: $checked = ' checked="checked"';
3547: }
3548: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 3549: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3550: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3551: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3552: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3553: '</label>'.$extra.'</span><br />'."\n";
3554: }
3555: $output .= '</div></td></tr>'."\n";
3556: return $output;
3557: }
3558:
3559: sub offloadtype_text {
3560: my %ruletitles = &Apache::lonlocal::texthash (
3561: 'default' => 'Offloads to default destinations',
3562: 'homeserver' => "Offloads to user's home server",
3563: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3564: 'specific' => 'Offloads to specific server',
1.161 raeburn 3565: 'none' => 'No offload',
1.209 raeburn 3566: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
3567: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.150 raeburn 3568: );
3569: return %ruletitles;
3570: }
3571:
3572: sub sparestype_titles {
3573: my %typestitles = &Apache::lonlocal::texthash (
3574: 'primary' => 'primary',
3575: 'default' => 'default',
3576: );
3577: return %typestitles;
3578: }
3579:
1.28 raeburn 3580: sub contact_titles {
3581: my %titles = &Apache::lonlocal::texthash (
3582: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3583: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3584: 'errormail' => 'Error reports to be e-mailed to',
3585: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3586: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3587: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3588: 'requestsmail' => 'E-mail from course requests requiring approval',
1.190 raeburn 3589: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 3590: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 3591: );
3592: my %short_titles = &Apache::lonlocal::texthash (
3593: adminemail => 'Admin E-mail address',
3594: supportemail => 'Support E-mail',
3595: );
3596: return (\%titles,\%short_titles);
3597: }
3598:
1.72 raeburn 3599: sub tool_titles {
3600: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 3601: aboutme => 'Personal web page',
1.86 raeburn 3602: blog => 'Blog',
1.162 raeburn 3603: webdav => 'WebDAV',
1.86 raeburn 3604: portfolio => 'Portfolio',
1.88 bisitz 3605: official => 'Official courses (with institutional codes)',
3606: unofficial => 'Unofficial courses',
1.98 raeburn 3607: community => 'Communities',
1.216 raeburn 3608: textbook => 'Textbook courses',
1.86 raeburn 3609: );
1.72 raeburn 3610: return %titles;
3611: }
3612:
1.101 raeburn 3613: sub courserequest_titles {
3614: my %titles = &Apache::lonlocal::texthash (
3615: official => 'Official',
3616: unofficial => 'Unofficial',
3617: community => 'Communities',
1.216 raeburn 3618: textbook => 'Textbook',
1.101 raeburn 3619: norequest => 'Not allowed',
1.104 raeburn 3620: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3621: validate => 'With validation',
3622: autolimit => 'Numerical limit',
1.103 raeburn 3623: unlimited => '(blank for unlimited)',
1.101 raeburn 3624: );
3625: return %titles;
3626: }
3627:
1.163 raeburn 3628: sub authorrequest_titles {
3629: my %titles = &Apache::lonlocal::texthash (
3630: norequest => 'Not allowed',
3631: approval => 'Approval by Dom. Coord.',
3632: automatic => 'Automatic approval',
3633: );
3634: return %titles;
1.210 raeburn 3635: }
1.163 raeburn 3636:
1.101 raeburn 3637: sub courserequest_conditions {
3638: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3639: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 3640: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 3641: );
3642: return %conditions;
3643: }
3644:
3645:
1.27 raeburn 3646: sub print_usercreation {
1.30 raeburn 3647: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3648: my $numinrow = 4;
1.28 raeburn 3649: my $datatable;
3650: if ($position eq 'top') {
1.30 raeburn 3651: $$rowtotal ++;
1.34 raeburn 3652: my $rowcount = 0;
1.32 raeburn 3653: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3654: if (ref($rules) eq 'HASH') {
3655: if (keys(%{$rules}) > 0) {
1.32 raeburn 3656: $datatable .= &user_formats_row('username',$settings,$rules,
3657: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3658: $$rowtotal ++;
1.32 raeburn 3659: $rowcount ++;
3660: }
3661: }
3662: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3663: if (ref($idrules) eq 'HASH') {
3664: if (keys(%{$idrules}) > 0) {
3665: $datatable .= &user_formats_row('id',$settings,$idrules,
3666: $idruleorder,$numinrow,$rowcount);
3667: $$rowtotal ++;
3668: $rowcount ++;
1.28 raeburn 3669: }
3670: }
1.39 raeburn 3671: if ($rowcount == 0) {
3672: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3673: $$rowtotal ++;
3674: $rowcount ++;
3675: }
1.34 raeburn 3676: } elsif ($position eq 'middle') {
1.224 raeburn 3677: my @creators = ('author','course','requestcrs');
1.37 raeburn 3678: my ($rules,$ruleorder) =
3679: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3680: my %lt = &usercreation_types();
3681: my %checked;
3682: if (ref($settings) eq 'HASH') {
3683: if (ref($settings->{'cancreate'}) eq 'HASH') {
3684: foreach my $item (@creators) {
3685: $checked{$item} = $settings->{'cancreate'}{$item};
3686: }
3687: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3688: foreach my $item (@creators) {
3689: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3690: $checked{$item} = 'none';
3691: }
3692: }
3693: }
3694: }
3695: my $rownum = 0;
3696: foreach my $item (@creators) {
3697: $rownum ++;
1.224 raeburn 3698: if ($checked{$item} eq '') {
3699: $checked{$item} = 'any';
1.34 raeburn 3700: }
3701: my $css_class;
3702: if ($rownum%2) {
3703: $css_class = '';
3704: } else {
3705: $css_class = ' class="LC_odd_row" ';
3706: }
3707: $datatable .= '<tr'.$css_class.'>'.
3708: '<td><span class="LC_nobreak">'.$lt{$item}.
3709: '</span></td><td align="right">';
1.224 raeburn 3710: my @options = ('any');
3711: if (ref($rules) eq 'HASH') {
3712: if (keys(%{$rules}) > 0) {
3713: push(@options,('official','unofficial'));
1.37 raeburn 3714: }
3715: }
1.224 raeburn 3716: push(@options,'none');
1.37 raeburn 3717: foreach my $option (@options) {
1.50 raeburn 3718: my $type = 'radio';
1.34 raeburn 3719: my $check = ' ';
1.224 raeburn 3720: if ($checked{$item} eq $option) {
3721: $check = ' checked="checked" ';
1.34 raeburn 3722: }
3723: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3724: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3725: $item.'" value="'.$option.'"'.$check.'/> '.
3726: $lt{$option}.'</label> </span>';
3727: }
3728: $datatable .= '</td></tr>';
3729: }
1.28 raeburn 3730: } else {
3731: my @contexts = ('author','course','domain');
3732: my @authtypes = ('int','krb4','krb5','loc');
3733: my %checked;
3734: if (ref($settings) eq 'HASH') {
3735: if (ref($settings->{'authtypes'}) eq 'HASH') {
3736: foreach my $item (@contexts) {
3737: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3738: foreach my $auth (@authtypes) {
3739: if ($settings->{'authtypes'}{$item}{$auth}) {
3740: $checked{$item}{$auth} = ' checked="checked" ';
3741: }
3742: }
3743: }
3744: }
1.27 raeburn 3745: }
1.35 raeburn 3746: } else {
3747: foreach my $item (@contexts) {
1.36 raeburn 3748: foreach my $auth (@authtypes) {
1.35 raeburn 3749: $checked{$item}{$auth} = ' checked="checked" ';
3750: }
3751: }
1.27 raeburn 3752: }
1.28 raeburn 3753: my %title = &context_names();
3754: my %authname = &authtype_names();
3755: my $rownum = 0;
3756: my $css_class;
3757: foreach my $item (@contexts) {
3758: if ($rownum%2) {
3759: $css_class = '';
3760: } else {
3761: $css_class = ' class="LC_odd_row" ';
3762: }
1.30 raeburn 3763: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3764: '<td>'.$title{$item}.
3765: '</td><td class="LC_left_item">'.
3766: '<span class="LC_nobreak">';
3767: foreach my $auth (@authtypes) {
3768: $datatable .= '<label>'.
3769: '<input type="checkbox" name="'.$item.'_auth" '.
3770: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3771: $authname{$auth}.'</label> ';
3772: }
3773: $datatable .= '</span></td></tr>';
3774: $rownum ++;
1.27 raeburn 3775: }
1.30 raeburn 3776: $$rowtotal += $rownum;
1.27 raeburn 3777: }
3778: return $datatable;
3779: }
3780:
1.224 raeburn 3781: sub print_selfcreation {
3782: my ($position,$dom,$settings,$rowtotal) = @_;
3783: my (@selfcreate,$createsettings,$datatable);
3784: if (ref($settings) eq 'HASH') {
3785: if (ref($settings->{'cancreate'}) eq 'HASH') {
3786: $createsettings = $settings->{'cancreate'};
3787: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3788: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3789: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3790: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3791: @selfcreate = ('email','login','sso');
3792: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3793: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3794: }
3795: }
3796: }
3797: }
3798: my %radiohash;
3799: my $rownum = 0;
3800: my $numinrow = 4;
3801: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
3802: if ($position eq 'top') {
3803: my %choices = &Apache::lonlocal::texthash (
3804: cancreate_login => 'Institutional Login',
3805: cancreate_sso => 'Institutional Single Sign On',
3806: );
3807: my @toggles = sort(keys(%choices));
3808: my %defaultchecked = (
3809: 'cancreate_login' => 'off',
3810: 'cancreate_sso' => 'off',
3811: );
3812: my $itemcount = 1;
3813: my $onclick;
3814: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
3815: \%choices,$itemcount,$onclick);
3816: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3817:
3818: if (ref($usertypes) eq 'HASH') {
3819: if (keys(%{$usertypes}) > 0) {
3820: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
3821: $dom,$numinrow,$othertitle,
3822: 'statustocreate',$rownum);
3823: $rownum ++;
3824: $$rowtotal ++;
3825: }
3826: }
3827: } elsif ($position eq 'middle') {
3828: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
3829: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3830: $usertypes->{'default'} = $othertitle;
3831: if (ref($types) eq 'ARRAY') {
3832: push(@{$types},'default');
3833: $usertypes->{'default'} = $othertitle;
3834: foreach my $status (@{$types}) {
3835: $rownum ++;
3836: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
3837: $numinrow,$rownum,$usertypes);
3838: $$rowtotal ++;
3839: }
3840: }
3841: } else {
3842: my $css_class = $rownum%2?' class="LC_odd_row"':'';
3843: my %choices =
3844: &Apache::lonlocal::texthash(
3845: email => 'Approved automatically',
3846: emailapproval => 'Queued for approval by DC',
3847: off => 'Not enabled',
3848: );
3849: $datatable .= '<tr'.$css_class.'>'.
3850: '<td>'.&mt('E-mail address as username').
3851: '</td><td class="LC_left_item">'.
3852: '<span class="LC_nobreak">';
3853: foreach my $option ('email','emailapproval','off') {
3854: my $checked;
3855: if ($option eq 'email') {
3856: if ($radiohash{'cancreate_email'}) {
3857: $checked = 'checked="checked"';
3858: }
3859: } elsif ($option eq 'emailapproval') {
3860: if ($radiohash{'cancreate_emailapproval'}) {
3861: $checked = 'checked="checked"';
3862: }
3863: } else {
3864: if ((!$radiohash{'cancreate_email'}) && (!$radiohash{'cancreate_emailapproval'})) {
3865: $checked = 'checked="checked"';
3866: }
3867: }
3868: $datatable .= '<label>'.
3869: '<input type="radio" name="cancreate_email" '.
3870: $checked.' value="'.$option.'" />'.
3871: $choices{$option}.'</label> ';
3872: }
3873: $$rowtotal ++;
3874: $rownum ++;
3875: $datatable .= '</span></td></tr>'.
3876: &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
3877: $rownum ++;
3878: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
3879: $numinrow = 2;
3880: $datatable .= &modifiable_userdata_row('cancreate','emailusername',$settings,
3881: $numinrow,$rownum,undef,$infofields,$infotitles);
3882: $$rowtotal ++;
3883: $rownum ++;
3884: my ($emailrules,$emailruleorder) =
3885: &Apache::lonnet::inst_userrules($dom,'email');
3886: if (ref($emailrules) eq 'HASH') {
3887: if (keys(%{$emailrules}) > 0) {
3888: $datatable .= &user_formats_row('email',$settings,$emailrules,
3889: $emailruleorder,$numinrow,$rownum);
3890: $rownum ++;
3891: $$rowtotal ++;
3892: }
3893: }
3894: $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
3895: }
3896: return $datatable;
3897: }
3898:
1.165 raeburn 3899: sub captcha_choice {
1.169 raeburn 3900: my ($context,$settings,$itemcount) = @_;
1.165 raeburn 3901: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
3902: my %lt = &captcha_phrases();
3903: $keyentry = 'hidden';
3904: if ($context eq 'cancreate') {
1.224 raeburn 3905: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 3906: } elsif ($context eq 'login') {
3907: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 3908: }
3909: if (ref($settings) eq 'HASH') {
3910: if ($settings->{'captcha'}) {
3911: $checked{$settings->{'captcha'}} = ' checked="checked"';
3912: } else {
3913: $checked{'original'} = ' checked="checked"';
3914: }
3915: if ($settings->{'captcha'} eq 'recaptcha') {
3916: $pubtext = $lt{'pub'};
3917: $privtext = $lt{'priv'};
3918: $keyentry = 'text';
3919: }
3920: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
3921: $currpub = $settings->{'recaptchakeys'}{'public'};
3922: $currpriv = $settings->{'recaptchakeys'}{'private'};
3923: }
3924: } else {
3925: $checked{'original'} = ' checked="checked"';
3926: }
1.169 raeburn 3927: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3928: my $output = '<tr'.$css_class.'>'.
3929: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 3930: '<table><tr><td>'."\n";
3931: foreach my $option ('original','recaptcha','notused') {
3932: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
3933: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
3934: $lt{$option}.'</label></span>';
3935: unless ($option eq 'notused') {
3936: $output .= (' 'x2)."\n";
3937: }
3938: }
3939: #
3940: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
3941: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 3942: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 3943: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 3944: #
1.165 raeburn 3945: $output .= '</td></tr>'."\n".
3946: '<tr><td>'."\n".
3947: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
3948: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
3949: $currpub.'" size="40" /></span><br />'."\n".
3950: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
3951: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
3952: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
3953: '</td></tr>';
3954: return $output;
3955: }
3956:
1.32 raeburn 3957: sub user_formats_row {
3958: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3959: my $output;
3960: my %text = (
3961: 'username' => 'new usernames',
3962: 'id' => 'IDs',
1.45 raeburn 3963: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3964: );
3965: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3966: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3967: '<td><span class="LC_nobreak">';
3968: if ($type eq 'email') {
3969: $output .= &mt("Formats disallowed for $text{$type}: ");
3970: } else {
3971: $output .= &mt("Format rules to check for $text{$type}: ");
3972: }
3973: $output .= '</span></td>'.
3974: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3975: my $rem;
3976: if (ref($ruleorder) eq 'ARRAY') {
3977: for (my $i=0; $i<@{$ruleorder}; $i++) {
3978: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3979: my $rem = $i%($numinrow);
3980: if ($rem == 0) {
3981: if ($i > 0) {
3982: $output .= '</tr>';
3983: }
3984: $output .= '<tr>';
3985: }
3986: my $check = ' ';
1.39 raeburn 3987: if (ref($settings) eq 'HASH') {
3988: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3989: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3990: $check = ' checked="checked" ';
3991: }
1.27 raeburn 3992: }
3993: }
3994: $output .= '<td class="LC_left_item">'.
3995: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3996: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 3997: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3998: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3999: }
4000: }
4001: $rem = @{$ruleorder}%($numinrow);
4002: }
4003: my $colsleft = $numinrow - $rem;
4004: if ($colsleft > 1 ) {
4005: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4006: ' </td>';
4007: } elsif ($colsleft == 1) {
4008: $output .= '<td class="LC_left_item"> </td>';
4009: }
4010: $output .= '</tr></table></td></tr>';
4011: return $output;
4012: }
4013:
1.34 raeburn 4014: sub usercreation_types {
4015: my %lt = &Apache::lonlocal::texthash (
4016: author => 'When adding a co-author',
4017: course => 'When adding a user to a course',
1.100 raeburn 4018: requestcrs => 'When requesting a course',
1.34 raeburn 4019: any => 'Any',
4020: official => 'Institutional only ',
4021: unofficial => 'Non-institutional only',
4022: none => 'None',
4023: );
4024: return %lt;
1.48 raeburn 4025: }
1.34 raeburn 4026:
1.224 raeburn 4027: sub selfcreation_types {
4028: my %lt = &Apache::lonlocal::texthash (
4029: selfcreate => 'User creates own account',
4030: any => 'Any',
4031: official => 'Institutional only ',
4032: unofficial => 'Non-institutional only',
4033: email => 'E-mail address',
4034: login => 'Institutional Login',
4035: sso => 'SSO',
4036: );
4037: }
4038:
1.28 raeburn 4039: sub authtype_names {
4040: my %lt = &Apache::lonlocal::texthash(
4041: int => 'Internal',
4042: krb4 => 'Kerberos 4',
4043: krb5 => 'Kerberos 5',
4044: loc => 'Local',
4045: );
4046: return %lt;
4047: }
4048:
4049: sub context_names {
4050: my %context_title = &Apache::lonlocal::texthash(
4051: author => 'Creating users when an Author',
4052: course => 'Creating users when in a course',
4053: domain => 'Creating users when a Domain Coordinator',
4054: );
4055: return %context_title;
4056: }
4057:
1.33 raeburn 4058: sub print_usermodification {
4059: my ($position,$dom,$settings,$rowtotal) = @_;
4060: my $numinrow = 4;
4061: my ($context,$datatable,$rowcount);
4062: if ($position eq 'top') {
4063: $rowcount = 0;
4064: $context = 'author';
4065: foreach my $role ('ca','aa') {
4066: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4067: $numinrow,$rowcount);
4068: $$rowtotal ++;
4069: $rowcount ++;
4070: }
1.63 raeburn 4071: } elsif ($position eq 'middle') {
1.33 raeburn 4072: $context = 'course';
4073: $rowcount = 0;
4074: foreach my $role ('st','ep','ta','in','cr') {
4075: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4076: $numinrow,$rowcount);
4077: $$rowtotal ++;
4078: $rowcount ++;
4079: }
4080: }
4081: return $datatable;
4082: }
4083:
1.43 raeburn 4084: sub print_defaults {
1.212 raeburn 4085: my ($dom,$settings,$rowtotal) = @_;
1.68 raeburn 4086: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 4087: 'datelocale_def','portal_def');
1.212 raeburn 4088: my %defaults;
4089: if (ref($settings) eq 'HASH') {
1.213 raeburn 4090: %defaults = %{$settings};
1.212 raeburn 4091: } else {
4092: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
4093: foreach my $item (@items) {
4094: $defaults{$item} = $domdefaults{$item};
4095: }
4096: }
1.141 raeburn 4097: my $titles = &defaults_titles($dom);
1.43 raeburn 4098: my $rownum = 0;
4099: my ($datatable,$css_class);
4100: foreach my $item (@items) {
4101: if ($rownum%2) {
4102: $css_class = '';
4103: } else {
4104: $css_class = ' class="LC_odd_row" ';
4105: }
4106: $datatable .= '<tr'.$css_class.'>'.
4107: '<td><span class="LC_nobreak">'.$titles->{$item}.
4108: '</span></td><td class="LC_right_item">';
4109: if ($item eq 'auth_def') {
4110: my @authtypes = ('internal','krb4','krb5','localauth');
4111: my %shortauth = (
4112: internal => 'int',
4113: krb4 => 'krb4',
4114: krb5 => 'krb5',
4115: localauth => 'loc'
4116: );
4117: my %authnames = &authtype_names();
4118: foreach my $auth (@authtypes) {
4119: my $checked = ' ';
1.212 raeburn 4120: if ($defaults{$item} eq $auth) {
1.43 raeburn 4121: $checked = ' checked="checked" ';
4122: }
4123: $datatable .= '<label><input type="radio" name="'.$item.
4124: '" value="'.$auth.'"'.$checked.'/>'.
4125: $authnames{$shortauth{$auth}}.'</label> ';
4126: }
1.54 raeburn 4127: } elsif ($item eq 'timezone_def') {
4128: my $includeempty = 1;
1.212 raeburn 4129: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
1.68 raeburn 4130: } elsif ($item eq 'datelocale_def') {
4131: my $includeempty = 1;
1.212 raeburn 4132: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
1.167 raeburn 4133: } elsif ($item eq 'lang_def') {
1.168 raeburn 4134: my %langchoices = &get_languages_hash();
4135: $langchoices{''} = 'No language preference';
1.167 raeburn 4136: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.212 raeburn 4137: $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,
1.167 raeburn 4138: \%langchoices);
1.43 raeburn 4139: } else {
1.141 raeburn 4140: my $size;
4141: if ($item eq 'portal_def') {
4142: $size = ' size="25"';
4143: }
1.43 raeburn 4144: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.212 raeburn 4145: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 4146: }
4147: $datatable .= '</td></tr>';
4148: $rownum ++;
4149: }
4150: $$rowtotal += $rownum;
4151: return $datatable;
4152: }
4153:
1.168 raeburn 4154: sub get_languages_hash {
4155: my %langchoices;
4156: foreach my $id (&Apache::loncommon::languageids()) {
4157: my $code = &Apache::loncommon::supportedlanguagecode($id);
4158: if ($code ne '') {
4159: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
4160: }
4161: }
4162: return %langchoices;
4163: }
4164:
1.43 raeburn 4165: sub defaults_titles {
1.141 raeburn 4166: my ($dom) = @_;
1.43 raeburn 4167: my %titles = &Apache::lonlocal::texthash (
4168: 'auth_def' => 'Default authentication type',
4169: 'auth_arg_def' => 'Default authentication argument',
4170: 'lang_def' => 'Default language',
1.54 raeburn 4171: 'timezone_def' => 'Default timezone',
1.68 raeburn 4172: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 4173: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 4174: );
1.141 raeburn 4175: if ($dom) {
4176: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
4177: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
4178: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
4179: $protocol = 'http' if ($protocol ne 'https');
4180: if ($uint_dom) {
4181: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
4182: $uint_dom);
4183: }
4184: }
1.43 raeburn 4185: return (\%titles);
4186: }
4187:
1.46 raeburn 4188: sub print_scantronformat {
4189: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
4190: my $itemcount = 1;
1.60 raeburn 4191: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
4192: %confhash);
1.46 raeburn 4193: my $switchserver = &check_switchserver($dom,$confname);
4194: my %lt = &Apache::lonlocal::texthash (
1.95 www 4195: default => 'Default bubblesheet format file error',
4196: custom => 'Custom bubblesheet format file error',
1.46 raeburn 4197: );
4198: my %scantronfiles = (
4199: default => 'default.tab',
4200: custom => 'custom.tab',
4201: );
4202: foreach my $key (keys(%scantronfiles)) {
4203: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
4204: .$scantronfiles{$key};
4205: }
4206: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
4207: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
4208: if (!$switchserver) {
4209: my $servadm = $r->dir_config('lonAdmEMail');
4210: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
4211: if ($configuserok eq 'ok') {
4212: if ($author_ok eq 'ok') {
4213: my %legacyfile = (
4214: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
4215: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
4216: );
4217: my %md5chk;
4218: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4219: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
4220: chomp($md5chk{$type});
1.46 raeburn 4221: }
4222: if ($md5chk{'default'} ne $md5chk{'custom'}) {
4223: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4224: ($scantronurls{$type},my $error) =
1.46 raeburn 4225: &legacy_scantronformat($r,$dom,$confname,
4226: $type,$legacyfile{$type},
4227: $scantronurls{$type},
4228: $scantronfiles{$type});
1.60 raeburn 4229: if ($error ne '') {
4230: $error{$type} = $error;
4231: }
4232: }
4233: if (keys(%error) == 0) {
4234: $is_custom = 1;
4235: $confhash{'scantron'}{'scantronformat'} =
4236: $scantronurls{'custom'};
4237: my $putresult =
4238: &Apache::lonnet::put_dom('configuration',
4239: \%confhash,$dom);
4240: if ($putresult ne 'ok') {
4241: $error{'custom'} =
4242: '<span class="LC_error">'.
4243: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4244: }
1.46 raeburn 4245: }
4246: } else {
1.60 raeburn 4247: ($scantronurls{'default'},my $error) =
1.46 raeburn 4248: &legacy_scantronformat($r,$dom,$confname,
4249: 'default',$legacyfile{'default'},
4250: $scantronurls{'default'},
4251: $scantronfiles{'default'});
1.60 raeburn 4252: if ($error eq '') {
4253: $confhash{'scantron'}{'scantronformat'} = '';
4254: my $putresult =
4255: &Apache::lonnet::put_dom('configuration',
4256: \%confhash,$dom);
4257: if ($putresult ne 'ok') {
4258: $error{'default'} =
4259: '<span class="LC_error">'.
4260: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4261: }
4262: } else {
4263: $error{'default'} = $error;
4264: }
1.46 raeburn 4265: }
4266: }
4267: }
4268: } else {
1.95 www 4269: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 4270: }
4271: }
4272: if (ref($settings) eq 'HASH') {
4273: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
4274: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
4275: if ((!@info) || ($info[0] eq 'no_such_dir')) {
4276: $scantronurl = '';
4277: } else {
4278: $scantronurl = $settings->{'scantronformat'};
4279: }
4280: $is_custom = 1;
4281: } else {
4282: $scantronurl = $scantronurls{'default'};
4283: }
4284: } else {
1.60 raeburn 4285: if ($is_custom) {
4286: $scantronurl = $scantronurls{'custom'};
4287: } else {
4288: $scantronurl = $scantronurls{'default'};
4289: }
1.46 raeburn 4290: }
4291: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4292: $datatable .= '<tr'.$css_class.'>';
4293: if (!$is_custom) {
1.65 raeburn 4294: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
4295: '<span class="LC_nobreak">';
1.46 raeburn 4296: if ($scantronurl) {
1.199 raeburn 4297: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
4298: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 4299: } else {
4300: $datatable = &mt('File unavailable for display');
4301: }
1.65 raeburn 4302: $datatable .= '</span></td>';
1.60 raeburn 4303: if (keys(%error) == 0) {
4304: $datatable .= '<td valign="bottom">';
4305: if (!$switchserver) {
4306: $datatable .= &mt('Upload:').'<br />';
4307: }
4308: } else {
4309: my $errorstr;
4310: foreach my $key (sort(keys(%error))) {
4311: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4312: }
4313: $datatable .= '<td>'.$errorstr;
4314: }
1.46 raeburn 4315: } else {
4316: if (keys(%error) > 0) {
4317: my $errorstr;
4318: foreach my $key (sort(keys(%error))) {
4319: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4320: }
1.60 raeburn 4321: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 4322: } elsif ($scantronurl) {
1.199 raeburn 4323: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
4324: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 4325: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 4326: $link.
4327: '<label><input type="checkbox" name="scantronformat_del"'.
4328: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 4329: '<td><span class="LC_nobreak"> '.
4330: &mt('Replace:').'</span><br />';
1.46 raeburn 4331: }
4332: }
4333: if (keys(%error) == 0) {
4334: if ($switchserver) {
4335: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4336: } else {
1.65 raeburn 4337: $datatable .='<span class="LC_nobreak"> '.
4338: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 4339: }
4340: }
4341: $datatable .= '</td></tr>';
4342: $$rowtotal ++;
4343: return $datatable;
4344: }
4345:
4346: sub legacy_scantronformat {
4347: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
4348: my ($url,$error);
4349: my @statinfo = &Apache::lonnet::stat_file($newurl);
4350: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
4351: (my $result,$url) =
4352: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
4353: '','',$newfile);
4354: if ($result ne 'ok') {
1.130 raeburn 4355: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 4356: }
4357: }
4358: return ($url,$error);
4359: }
1.43 raeburn 4360:
1.49 raeburn 4361: sub print_coursecategories {
1.57 raeburn 4362: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
4363: my $datatable;
4364: if ($position eq 'top') {
4365: my $toggle_cats_crs = ' ';
4366: my $toggle_cats_dom = ' checked="checked" ';
4367: my $can_cat_crs = ' ';
4368: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 4369: my $toggle_catscomm_comm = ' ';
4370: my $toggle_catscomm_dom = ' checked="checked" ';
4371: my $can_catcomm_comm = ' ';
4372: my $can_catcomm_dom = ' checked="checked" ';
4373:
1.57 raeburn 4374: if (ref($settings) eq 'HASH') {
4375: if ($settings->{'togglecats'} eq 'crs') {
4376: $toggle_cats_crs = $toggle_cats_dom;
4377: $toggle_cats_dom = ' ';
4378: }
4379: if ($settings->{'categorize'} eq 'crs') {
4380: $can_cat_crs = $can_cat_dom;
4381: $can_cat_dom = ' ';
4382: }
1.120 raeburn 4383: if ($settings->{'togglecatscomm'} eq 'comm') {
4384: $toggle_catscomm_comm = $toggle_catscomm_dom;
4385: $toggle_catscomm_dom = ' ';
4386: }
4387: if ($settings->{'categorizecomm'} eq 'comm') {
4388: $can_catcomm_comm = $can_catcomm_dom;
4389: $can_catcomm_dom = ' ';
4390: }
1.57 raeburn 4391: }
4392: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 4393: togglecats => 'Show/Hide a course in catalog',
4394: togglecatscomm => 'Show/Hide a community in catalog',
4395: categorize => 'Assign a category to a course',
4396: categorizecomm => 'Assign a category to a community',
1.57 raeburn 4397: );
4398: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 4399: dom => 'Set in Domain',
4400: crs => 'Set in Course',
4401: comm => 'Set in Community',
1.57 raeburn 4402: );
4403: $datatable = '<tr class="LC_odd_row">'.
4404: '<td>'.$title{'togglecats'}.'</td>'.
4405: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4406: '<input type="radio" name="togglecats"'.
4407: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4408: '<label><input type="radio" name="togglecats"'.
4409: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
4410: '</tr><tr>'.
4411: '<td>'.$title{'categorize'}.'</td>'.
4412: '<td class="LC_right_item"><span class="LC_nobreak">'.
4413: '<label><input type="radio" name="categorize"'.
4414: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4415: '<label><input type="radio" name="categorize"'.
4416: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 4417: '</tr><tr class="LC_odd_row">'.
4418: '<td>'.$title{'togglecatscomm'}.'</td>'.
4419: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4420: '<input type="radio" name="togglecatscomm"'.
4421: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4422: '<label><input type="radio" name="togglecatscomm"'.
4423: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4424: '</tr><tr>'.
4425: '<td>'.$title{'categorizecomm'}.'</td>'.
4426: '<td class="LC_right_item"><span class="LC_nobreak">'.
4427: '<label><input type="radio" name="categorizecomm"'.
4428: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4429: '<label><input type="radio" name="categorizecomm"'.
4430: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 4431: '</tr>';
1.120 raeburn 4432: $$rowtotal += 4;
1.57 raeburn 4433: } else {
4434: my $css_class;
4435: my $itemcount = 1;
4436: my $cathash;
4437: if (ref($settings) eq 'HASH') {
4438: $cathash = $settings->{'cats'};
4439: }
4440: if (ref($cathash) eq 'HASH') {
4441: my (@cats,@trails,%allitems,%idx,@jsarray);
4442: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4443: \%allitems,\%idx,\@jsarray);
4444: my $maxdepth = scalar(@cats);
4445: my $colattrib = '';
4446: if ($maxdepth > 2) {
4447: $colattrib = ' colspan="2" ';
4448: }
4449: my @path;
4450: if (@cats > 0) {
4451: if (ref($cats[0]) eq 'ARRAY') {
4452: my $numtop = @{$cats[0]};
4453: my $maxnum = $numtop;
1.120 raeburn 4454: my %default_names = (
4455: instcode => &mt('Official courses'),
4456: communities => &mt('Communities'),
4457: );
4458:
4459: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4460: ($cathash->{'instcode::0'} eq '') ||
4461: (!grep(/^communities$/,@{$cats[0]})) ||
4462: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4463: $maxnum ++;
4464: }
4465: my $lastidx;
4466: for (my $i=0; $i<$numtop; $i++) {
4467: my $parent = $cats[0][$i];
4468: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4469: my $item = &escape($parent).'::0';
4470: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4471: $lastidx = $idx{$item};
4472: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4473: .'<select name="'.$item.'"'.$chgstr.'>';
4474: for (my $k=0; $k<=$maxnum; $k++) {
4475: my $vpos = $k+1;
4476: my $selstr;
4477: if ($k == $i) {
4478: $selstr = ' selected="selected" ';
4479: }
4480: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4481: }
1.214 raeburn 4482: $datatable .= '</select></span></td><td>';
1.120 raeburn 4483: if ($parent eq 'instcode' || $parent eq 'communities') {
4484: $datatable .= '<span class="LC_nobreak">'
4485: .$default_names{$parent}.'</span>';
4486: if ($parent eq 'instcode') {
4487: $datatable .= '<br /><span class="LC_nobreak">('
4488: .&mt('with institutional codes')
4489: .')</span></td><td'.$colattrib.'>';
4490: } else {
4491: $datatable .= '<table><tr><td>';
4492: }
4493: $datatable .= '<span class="LC_nobreak">'
4494: .'<label><input type="radio" name="'
4495: .$parent.'" value="1" checked="checked" />'
4496: .&mt('Display').'</label>';
4497: if ($parent eq 'instcode') {
4498: $datatable .= ' ';
4499: } else {
4500: $datatable .= '</span></td></tr><tr><td>'
4501: .'<span class="LC_nobreak">';
4502: }
4503: $datatable .= '<label><input type="radio" name="'
4504: .$parent.'" value="0" />'
4505: .&mt('Do not display').'</label></span>';
4506: if ($parent eq 'communities') {
4507: $datatable .= '</td></tr></table>';
4508: }
4509: $datatable .= '</td>';
1.57 raeburn 4510: } else {
4511: $datatable .= $parent
1.214 raeburn 4512: .' <span class="LC_nobreak"><label>'
4513: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 4514: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4515: }
4516: my $depth = 1;
4517: push(@path,$parent);
4518: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4519: pop(@path);
4520: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4521: $itemcount ++;
4522: }
1.48 raeburn 4523: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 4524: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4525: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 4526: for (my $k=0; $k<=$maxnum; $k++) {
4527: my $vpos = $k+1;
4528: my $selstr;
1.57 raeburn 4529: if ($k == $numtop) {
1.48 raeburn 4530: $selstr = ' selected="selected" ';
4531: }
4532: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4533: }
1.59 bisitz 4534: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 4535: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4536: .'</tr>'."\n";
1.48 raeburn 4537: $itemcount ++;
1.120 raeburn 4538: foreach my $default ('instcode','communities') {
4539: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4540: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4541: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4542: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4543: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4544: for (my $k=0; $k<=$maxnum; $k++) {
4545: my $vpos = $k+1;
4546: my $selstr;
4547: if ($k == $maxnum) {
4548: $selstr = ' selected="selected" ';
4549: }
4550: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 4551: }
1.120 raeburn 4552: $datatable .= '</select></span></td>'.
4553: '<td><span class="LC_nobreak">'.
4554: $default_names{$default}.'</span>';
4555: if ($default eq 'instcode') {
4556: $datatable .= '<br /><span class="LC_nobreak">('
4557: .&mt('with institutional codes').')</span>';
4558: }
4559: $datatable .= '</td>'
4560: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4561: .&mt('Display').'</label> '
4562: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
4563: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 4564: }
4565: }
4566: }
1.57 raeburn 4567: } else {
4568: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 4569: }
4570: } else {
1.57 raeburn 4571: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
4572: .&initialize_categories($itemcount);
1.48 raeburn 4573: }
1.57 raeburn 4574: $$rowtotal += $itemcount;
1.48 raeburn 4575: }
4576: return $datatable;
4577: }
4578:
1.69 raeburn 4579: sub print_serverstatuses {
4580: my ($dom,$settings,$rowtotal) = @_;
4581: my $datatable;
4582: my @pages = &serverstatus_pages();
4583: my (%namedaccess,%machineaccess);
4584: foreach my $type (@pages) {
4585: $namedaccess{$type} = '';
4586: $machineaccess{$type}= '';
4587: }
4588: if (ref($settings) eq 'HASH') {
4589: foreach my $type (@pages) {
4590: if (exists($settings->{$type})) {
4591: if (ref($settings->{$type}) eq 'HASH') {
4592: foreach my $key (keys(%{$settings->{$type}})) {
4593: if ($key eq 'namedusers') {
4594: $namedaccess{$type} = $settings->{$type}->{$key};
4595: } elsif ($key eq 'machines') {
4596: $machineaccess{$type} = $settings->{$type}->{$key};
4597: }
4598: }
4599: }
4600: }
4601: }
4602: }
1.81 raeburn 4603: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 4604: my $rownum = 0;
4605: my $css_class;
4606: foreach my $type (@pages) {
4607: $rownum ++;
4608: $css_class = $rownum%2?' class="LC_odd_row"':'';
4609: $datatable .= '<tr'.$css_class.'>'.
4610: '<td><span class="LC_nobreak">'.
4611: $titles->{$type}.'</span></td>'.
4612: '<td class="LC_left_item">'.
4613: '<input type="text" name="'.$type.'_namedusers" '.
4614: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
4615: '<td class="LC_right_item">'.
4616: '<span class="LC_nobreak">'.
4617: '<input type="text" name="'.$type.'_machines" '.
4618: 'value="'.$machineaccess{$type}.'" size="10" />'.
4619: '</td></tr>'."\n";
4620: }
4621: $$rowtotal += $rownum;
4622: return $datatable;
4623: }
4624:
4625: sub serverstatus_pages {
4626: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.189 raeburn 4627: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.221 raeburn 4628: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
4629: 'uniquecodes');
1.69 raeburn 4630: }
4631:
1.49 raeburn 4632: sub coursecategories_javascript {
4633: my ($settings) = @_;
1.57 raeburn 4634: my ($output,$jstext,$cathash);
1.49 raeburn 4635: if (ref($settings) eq 'HASH') {
1.57 raeburn 4636: $cathash = $settings->{'cats'};
4637: }
4638: if (ref($cathash) eq 'HASH') {
1.49 raeburn 4639: my (@cats,@jsarray,%idx);
1.57 raeburn 4640: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 4641: if (@jsarray > 0) {
4642: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
4643: for (my $i=0; $i<@jsarray; $i++) {
4644: if (ref($jsarray[$i]) eq 'ARRAY') {
4645: my $catstr = join('","',@{$jsarray[$i]});
4646: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
4647: }
4648: }
4649: }
4650: } else {
4651: $jstext = ' var categories = Array(1);'."\n".
4652: ' categories[0] = Array("instcode_pos");'."\n";
4653: }
1.120 raeburn 4654: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
4655: my $communities_reserved = &mt('The name: "communities" is a reserved category');
4656: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 4657: $output = <<"ENDSCRIPT";
4658: <script type="text/javascript">
1.109 raeburn 4659: // <![CDATA[
1.49 raeburn 4660: function reorderCats(form,parent,item,idx) {
4661: var changedVal;
4662: $jstext
4663: var newpos = 'addcategory_pos';
4664: var current = new Array;
4665: if (parent == '') {
4666: var has_instcode = 0;
4667: var maxtop = categories[idx].length;
4668: for (var j=0; j<maxtop; j++) {
4669: if (categories[idx][j] == 'instcode::0') {
4670: has_instcode == 1;
4671: }
4672: }
4673: if (has_instcode == 0) {
4674: categories[idx][maxtop] = 'instcode_pos';
4675: }
4676: } else {
4677: newpos += '_'+parent;
4678: }
4679: var maxh = 1 + categories[idx].length;
4680: var current = new Array;
4681: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4682: if (item == newpos) {
4683: changedVal = newitemVal;
4684: } else {
4685: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4686: current[newitemVal] = newpos;
4687: }
4688: for (var i=0; i<categories[idx].length; i++) {
4689: var elementName = categories[idx][i];
4690: if (elementName != item) {
4691: if (form.elements[elementName]) {
4692: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4693: current[currVal] = elementName;
4694: }
4695: }
4696: }
4697: var oldVal;
4698: for (var j=0; j<maxh; j++) {
4699: if (current[j] == undefined) {
4700: oldVal = j;
4701: }
4702: }
4703: if (oldVal < changedVal) {
4704: for (var k=oldVal+1; k<=changedVal ; k++) {
4705: var elementName = current[k];
4706: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4707: }
4708: } else {
4709: for (var k=changedVal; k<oldVal; k++) {
4710: var elementName = current[k];
4711: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4712: }
4713: }
4714: return;
4715: }
1.120 raeburn 4716:
4717: function categoryCheck(form) {
4718: if (form.elements['addcategory_name'].value == 'instcode') {
4719: alert('$instcode_reserved\\n$choose_again');
4720: return false;
4721: }
4722: if (form.elements['addcategory_name'].value == 'communities') {
4723: alert('$communities_reserved\\n$choose_again');
4724: return false;
4725: }
4726: return true;
4727: }
4728:
1.109 raeburn 4729: // ]]>
1.49 raeburn 4730: </script>
4731:
4732: ENDSCRIPT
4733: return $output;
4734: }
4735:
1.48 raeburn 4736: sub initialize_categories {
4737: my ($itemcount) = @_;
1.120 raeburn 4738: my ($datatable,$css_class,$chgstr);
4739: my %default_names = (
4740: instcode => 'Official courses (with institutional codes)',
4741: communities => 'Communities',
4742: );
4743: my $select0 = ' selected="selected"';
4744: my $select1 = '';
4745: foreach my $default ('instcode','communities') {
4746: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4747: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
4748: if ($default eq 'communities') {
4749: $select1 = $select0;
4750: $select0 = '';
4751: }
4752: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4753: .'<select name="'.$default.'_pos">'
4754: .'<option value="0"'.$select0.'>1</option>'
4755: .'<option value="1"'.$select1.'>2</option>'
4756: .'<option value="2">3</option></select> '
4757: .$default_names{$default}
4758: .'</span></td><td><span class="LC_nobreak">'
4759: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4760: .&mt('Display').'</label> <label>'
4761: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 4762: .'</label></span></td></tr>';
1.120 raeburn 4763: $itemcount ++;
4764: }
1.48 raeburn 4765: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 4766: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 4767: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 4768: .'<select name="addcategory_pos"'.$chgstr.'>'
4769: .'<option value="0">1</option>'
4770: .'<option value="1">2</option>'
4771: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 4772: .&mt('Add category').'</td><td>'.&mt('Name:')
4773: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4774: return $datatable;
4775: }
4776:
4777: sub build_category_rows {
1.49 raeburn 4778: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4779: my ($text,$name,$item,$chgstr);
1.48 raeburn 4780: if (ref($cats) eq 'ARRAY') {
4781: my $maxdepth = scalar(@{$cats});
4782: if (ref($cats->[$depth]) eq 'HASH') {
4783: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4784: my $numchildren = @{$cats->[$depth]{$parent}};
4785: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 4786: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 4787: my ($idxnum,$parent_name,$parent_item);
4788: my $higher = $depth - 1;
4789: if ($higher == 0) {
4790: $parent_name = &escape($parent).'::'.$higher;
4791: } else {
4792: if (ref($path) eq 'ARRAY') {
4793: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4794: }
4795: }
4796: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4797: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4798: if ($j < $numchildren) {
1.48 raeburn 4799: $name = $cats->[$depth]{$parent}[$j];
4800: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4801: $idxnum = $idx->{$item};
4802: } else {
4803: $name = $parent_name;
4804: $item = $parent_item;
1.48 raeburn 4805: }
1.49 raeburn 4806: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4807: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4808: for (my $i=0; $i<=$numchildren; $i++) {
4809: my $vpos = $i+1;
4810: my $selstr;
4811: if ($j == $i) {
4812: $selstr = ' selected="selected" ';
4813: }
4814: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4815: }
4816: $text .= '</select> ';
4817: if ($j < $numchildren) {
4818: my $deeper = $depth+1;
4819: $text .= $name.' '
4820: .'<label><input type="checkbox" name="deletecategory" value="'
4821: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4822: if(ref($path) eq 'ARRAY') {
4823: push(@{$path},$name);
1.49 raeburn 4824: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4825: pop(@{$path});
4826: }
4827: } else {
1.59 bisitz 4828: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4829: if ($j == $numchildren) {
4830: $text .= $name;
4831: } else {
4832: $text .= $item;
4833: }
4834: $text .= '" value="" />';
4835: }
4836: $text .= '</td></tr>';
4837: }
4838: $text .= '</table></td>';
4839: } else {
4840: my $higher = $depth-1;
4841: if ($higher == 0) {
4842: $name = &escape($parent).'::'.$higher;
4843: } else {
4844: if (ref($path) eq 'ARRAY') {
4845: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4846: }
4847: }
4848: my $colspan;
4849: if ($parent ne 'instcode') {
4850: $colspan = $maxdepth - $depth - 1;
4851: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4852: }
4853: }
4854: }
4855: }
4856: return $text;
4857: }
4858:
1.33 raeburn 4859: sub modifiable_userdata_row {
1.224 raeburn 4860: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
1.33 raeburn 4861: my $rolename;
1.224 raeburn 4862: if ($context eq 'cancreate') {
4863: if ($role eq 'emailusername') {
4864: $rolename = &mt('Data user provides');
4865: }
4866: } elsif ($context eq 'selfcreate') {
1.63 raeburn 4867: if (ref($usertypes) eq 'HASH') {
4868: $rolename = $usertypes->{$role};
4869: } else {
4870: $rolename = $role;
4871: }
1.33 raeburn 4872: } else {
1.63 raeburn 4873: if ($role eq 'cr') {
4874: $rolename = &mt('Custom role');
4875: } else {
4876: $rolename = &Apache::lonnet::plaintext($role);
4877: }
1.33 raeburn 4878: }
1.224 raeburn 4879: my (@fields,%fieldtitles);
4880: if (ref($fieldsref) eq 'ARRAY') {
4881: @fields = @{$fieldsref};
4882: } else {
4883: @fields = ('lastname','firstname','middlename','generation',
4884: 'permanentemail','id');
4885: }
4886: if ((ref($titlesref) eq 'HASH')) {
4887: %fieldtitles = %{$titlesref};
4888: } else {
4889: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4890: }
1.33 raeburn 4891: my $output;
4892: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4893: $output = '<tr '.$css_class.'>'.
4894: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4895: '<td class="LC_left_item" colspan="2"><table>';
4896: my $rem;
4897: my %checks;
4898: if (ref($settings) eq 'HASH') {
4899: if (ref($settings->{$context}) eq 'HASH') {
4900: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4901: foreach my $field (@fields) {
4902: if ($settings->{$context}->{$role}->{$field}) {
4903: $checks{$field} = ' checked="checked" ';
4904: }
4905: }
4906: }
4907: }
4908: }
4909: for (my $i=0; $i<@fields; $i++) {
4910: my $rem = $i%($numinrow);
4911: if ($rem == 0) {
4912: if ($i > 0) {
4913: $output .= '</tr>';
4914: }
4915: $output .= '<tr>';
4916: }
4917: my $check = ' ';
4918: if (exists($checks{$fields[$i]})) {
4919: $check = $checks{$fields[$i]}
4920: } else {
4921: if ($role eq 'st') {
4922: if (ref($settings) ne 'HASH') {
4923: $check = ' checked="checked" ';
4924: }
4925: }
4926: }
4927: $output .= '<td class="LC_left_item">'.
4928: '<span class="LC_nobreak"><label>'.
4929: '<input type="checkbox" name="canmodify_'.$role.'" '.
4930: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4931: '</label></span></td>';
4932: $rem = @fields%($numinrow);
4933: }
4934: my $colsleft = $numinrow - $rem;
4935: if ($colsleft > 1 ) {
4936: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4937: ' </td>';
4938: } elsif ($colsleft == 1) {
4939: $output .= '<td class="LC_left_item"> </td>';
4940: }
4941: $output .= '</tr></table></td></tr>';
4942: return $output;
4943: }
1.28 raeburn 4944:
1.93 raeburn 4945: sub insttypes_row {
1.224 raeburn 4946: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 4947: my %lt = &Apache::lonlocal::texthash (
4948: cansearch => 'Users allowed to search',
4949: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4950: lockablenames => 'User preference to lock name',
1.93 raeburn 4951: );
4952: my $showdom;
4953: if ($context eq 'cansearch') {
4954: $showdom = ' ('.$dom.')';
4955: }
1.165 raeburn 4956: my $class = 'LC_left_item';
4957: if ($context eq 'statustocreate') {
4958: $class = 'LC_right_item';
4959: }
1.224 raeburn 4960: my $css_class = ' class="LC_odd_row"';
4961: if ($rownum ne '') {
4962: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
4963: }
4964: my $output = '<tr'.$css_class.'>'.
4965: '<td>'.$lt{$context}.$showdom.
4966: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 4967: my $rem;
4968: if (ref($types) eq 'ARRAY') {
4969: for (my $i=0; $i<@{$types}; $i++) {
4970: if (defined($usertypes->{$types->[$i]})) {
4971: my $rem = $i%($numinrow);
4972: if ($rem == 0) {
4973: if ($i > 0) {
4974: $output .= '</tr>';
4975: }
4976: $output .= '<tr>';
1.23 raeburn 4977: }
1.26 raeburn 4978: my $check = ' ';
1.99 raeburn 4979: if (ref($settings) eq 'HASH') {
4980: if (ref($settings->{$context}) eq 'ARRAY') {
4981: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4982: $check = ' checked="checked" ';
4983: }
4984: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4985: $check = ' checked="checked" ';
4986: }
1.23 raeburn 4987: }
1.26 raeburn 4988: $output .= '<td class="LC_left_item">'.
4989: '<span class="LC_nobreak"><label>'.
1.93 raeburn 4990: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 4991: 'value="'.$types->[$i].'"'.$check.'/>'.
4992: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 4993: }
4994: }
1.26 raeburn 4995: $rem = @{$types}%($numinrow);
1.23 raeburn 4996: }
4997: my $colsleft = $numinrow - $rem;
1.131 raeburn 4998: if (($rem == 0) && (@{$types} > 0)) {
4999: $output .= '<tr>';
5000: }
1.23 raeburn 5001: if ($colsleft > 1) {
1.25 raeburn 5002: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 5003: } else {
1.25 raeburn 5004: $output .= '<td class="LC_left_item">';
1.23 raeburn 5005: }
5006: my $defcheck = ' ';
1.99 raeburn 5007: if (ref($settings) eq 'HASH') {
5008: if (ref($settings->{$context}) eq 'ARRAY') {
5009: if (grep(/^default$/,@{$settings->{$context}})) {
5010: $defcheck = ' checked="checked" ';
5011: }
5012: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5013: $defcheck = ' checked="checked" ';
5014: }
1.23 raeburn 5015: }
1.25 raeburn 5016: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 5017: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 5018: 'value="default"'.$defcheck.'/>'.
5019: $othertitle.'</label></span></td>'.
5020: '</tr></table></td></tr>';
5021: return $output;
1.23 raeburn 5022: }
5023:
5024: sub sorted_searchtitles {
5025: my %searchtitles = &Apache::lonlocal::texthash(
5026: 'uname' => 'username',
5027: 'lastname' => 'last name',
5028: 'lastfirst' => 'last name, first name',
5029: );
5030: my @titleorder = ('uname','lastname','lastfirst');
5031: return (\%searchtitles,\@titleorder);
5032: }
5033:
1.25 raeburn 5034: sub sorted_searchtypes {
5035: my %srchtypes_desc = (
5036: exact => 'is exact match',
5037: contains => 'contains ..',
5038: begins => 'begins with ..',
5039: );
5040: my @srchtypeorder = ('exact','begins','contains');
5041: return (\%srchtypes_desc,\@srchtypeorder);
5042: }
5043:
1.3 raeburn 5044: sub usertype_update_row {
5045: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
5046: my $datatable;
5047: my $numinrow = 4;
5048: foreach my $type (@{$types}) {
5049: if (defined($usertypes->{$type})) {
5050: $$rownums ++;
5051: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
5052: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
5053: '</td><td class="LC_left_item"><table>';
5054: for (my $i=0; $i<@{$fields}; $i++) {
5055: my $rem = $i%($numinrow);
5056: if ($rem == 0) {
5057: if ($i > 0) {
5058: $datatable .= '</tr>';
5059: }
5060: $datatable .= '<tr>';
5061: }
5062: my $check = ' ';
1.39 raeburn 5063: if (ref($settings) eq 'HASH') {
5064: if (ref($settings->{'fields'}) eq 'HASH') {
5065: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
5066: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
5067: $check = ' checked="checked" ';
5068: }
1.3 raeburn 5069: }
5070: }
5071: }
5072:
5073: if ($i == @{$fields}-1) {
5074: my $colsleft = $numinrow - $rem;
5075: if ($colsleft > 1) {
5076: $datatable .= '<td colspan="'.$colsleft.'">';
5077: } else {
5078: $datatable .= '<td>';
5079: }
5080: } else {
5081: $datatable .= '<td>';
5082: }
1.8 raeburn 5083: $datatable .= '<span class="LC_nobreak"><label>'.
5084: '<input type="checkbox" name="updateable_'.$type.
5085: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
5086: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 5087: }
5088: $datatable .= '</tr></table></td></tr>';
5089: }
5090: }
5091: return $datatable;
1.1 raeburn 5092: }
5093:
5094: sub modify_login {
1.205 raeburn 5095: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 5096: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
5097: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
5098: %title = ( coursecatalog => 'Display course catalog',
5099: adminmail => 'Display administrator E-mail address',
1.188 raeburn 5100: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 5101: newuser => 'Link for visitors to create a user account',
5102: loginheader => 'Log-in box header');
5103: @offon = ('off','on');
1.112 raeburn 5104: if (ref($domconfig{login}) eq 'HASH') {
5105: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
5106: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
5107: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
5108: }
5109: }
5110: }
1.9 raeburn 5111: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
5112: \%domconfig,\%loginhash);
1.188 raeburn 5113: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5114: foreach my $item (@toggles) {
5115: $loginhash{login}{$item} = $env{'form.'.$item};
5116: }
1.41 raeburn 5117: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 5118: if (ref($colchanges{'login'}) eq 'HASH') {
5119: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
5120: \%loginhash);
5121: }
1.110 raeburn 5122:
1.149 raeburn 5123: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 5124: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 5125: if (keys(%servers) > 1) {
5126: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 5127: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
5128: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
5129: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
5130: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
5131: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
5132: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5133: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5134: $changes{'loginvia'}{$lonhost} = 1;
5135: } else {
5136: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
5137: $changes{'loginvia'}{$lonhost} = 1;
5138: }
5139: } else {
5140: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5141: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5142: $changes{'loginvia'}{$lonhost} = 1;
5143: }
5144: }
5145: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
5146: foreach my $item (@loginvia_attribs) {
5147: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
5148: }
5149: } else {
5150: foreach my $item (@loginvia_attribs) {
5151: my $new = $env{'form.'.$lonhost.'_'.$item};
5152: if (($item eq 'serverpath') && ($new eq 'custom')) {
5153: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
5154: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5155: $new = '/';
5156: }
5157: }
5158: if (($item eq 'custompath') &&
5159: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5160: $new = '';
5161: }
5162: if ($new ne $curr_loginvia{$lonhost}{$item}) {
5163: $changes{'loginvia'}{$lonhost} = 1;
5164: }
5165: if ($item eq 'exempt') {
5166: $new =~ s/^\s+//;
5167: $new =~ s/\s+$//;
5168: my @poss_ips = split(/\s*[,:]\s*/,$new);
5169: my @okips;
5170: foreach my $ip (@poss_ips) {
5171: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
5172: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
5173: push(@okips,$ip);
5174: }
5175: }
5176: }
5177: if (@okips > 0) {
5178: $new = join(',',@okips);
5179: } else {
5180: $new = '';
5181: }
5182: }
5183: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5184: }
5185: }
1.112 raeburn 5186: } else {
1.128 raeburn 5187: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5188: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 5189: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 5190: foreach my $item (@loginvia_attribs) {
5191: my $new = $env{'form.'.$lonhost.'_'.$item};
5192: if (($item eq 'serverpath') && ($new eq 'custom')) {
5193: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5194: $new = '/';
5195: }
5196: }
5197: if (($item eq 'custompath') &&
5198: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5199: $new = '';
5200: }
5201: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5202: }
1.110 raeburn 5203: }
5204: }
5205: }
5206: }
1.119 raeburn 5207:
1.168 raeburn 5208: my $servadm = $r->dir_config('lonAdmEMail');
5209: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
5210: if (ref($domconfig{'login'}) eq 'HASH') {
5211: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
5212: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
5213: if ($lang eq 'nolang') {
5214: push(@currlangs,$lang);
5215: } elsif (defined($langchoices{$lang})) {
5216: push(@currlangs,$lang);
5217: } else {
5218: next;
5219: }
5220: }
5221: }
5222: }
5223: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
5224: if (@currlangs > 0) {
5225: foreach my $lang (@currlangs) {
5226: if (grep(/^\Q$lang\E$/,@delurls)) {
5227: $changes{'helpurl'}{$lang} = 1;
5228: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
5229: $changes{'helpurl'}{$lang} = 1;
5230: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
5231: push(@newlangs,$lang);
5232: } else {
5233: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5234: }
5235: }
5236: }
5237: unless (grep(/^nolang$/,@currlangs)) {
5238: if ($env{'form.loginhelpurl_nolang.filename'}) {
5239: $changes{'helpurl'}{'nolang'} = 1;
5240: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
5241: push(@newlangs,'nolang');
5242: }
5243: }
5244: if ($env{'form.loginhelpurl_add_lang'}) {
5245: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
5246: ($env{'form.loginhelpurl_add_file.filename'})) {
5247: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
5248: $addedfile = $env{'form.loginhelpurl_add_lang'};
5249: }
5250: }
5251: if ((@newlangs > 0) || ($addedfile)) {
5252: my $error;
5253: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
5254: if ($configuserok eq 'ok') {
5255: if ($switchserver) {
5256: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
5257: } elsif ($author_ok eq 'ok') {
5258: my @allnew = @newlangs;
5259: if ($addedfile ne '') {
5260: push(@allnew,$addedfile);
5261: }
5262: foreach my $lang (@allnew) {
5263: my $formelem = 'loginhelpurl_'.$lang;
5264: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
5265: $formelem = 'loginhelpurl_add_file';
5266: }
5267: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
5268: "help/$lang",'','',$newfile{$lang});
5269: if ($result eq 'ok') {
5270: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
5271: $changes{'helpurl'}{$lang} = 1;
5272: } else {
5273: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
5274: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 5275: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 5276: (!grep(/^\Q$lang\E$/,@delurls))) {
5277:
5278: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5279: }
5280: }
5281: }
5282: } else {
5283: $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);
5284: }
5285: } else {
5286: $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);
5287: }
5288: if ($error) {
5289: &Apache::lonnet::logthis($error);
5290: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
5291: }
5292: }
1.169 raeburn 5293: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 5294:
5295: my $defaulthelpfile = '/adm/loginproblems.html';
5296: my $defaulttext = &mt('Default in use');
5297:
1.1 raeburn 5298: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
5299: $dom);
5300: if ($putresult eq 'ok') {
1.188 raeburn 5301: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5302: my %defaultchecked = (
5303: 'coursecatalog' => 'on',
1.188 raeburn 5304: 'helpdesk' => 'on',
1.42 raeburn 5305: 'adminmail' => 'off',
1.43 raeburn 5306: 'newuser' => 'off',
1.42 raeburn 5307: );
1.55 raeburn 5308: if (ref($domconfig{'login'}) eq 'HASH') {
5309: foreach my $item (@toggles) {
5310: if ($defaultchecked{$item} eq 'on') {
5311: if (($domconfig{'login'}{$item} eq '0') &&
5312: ($env{'form.'.$item} eq '1')) {
5313: $changes{$item} = 1;
5314: } elsif (($domconfig{'login'}{$item} eq '' ||
5315: $domconfig{'login'}{$item} eq '1') &&
5316: ($env{'form.'.$item} eq '0')) {
5317: $changes{$item} = 1;
5318: }
5319: } elsif ($defaultchecked{$item} eq 'off') {
5320: if (($domconfig{'login'}{$item} eq '1') &&
5321: ($env{'form.'.$item} eq '0')) {
5322: $changes{$item} = 1;
5323: } elsif (($domconfig{'login'}{$item} eq '' ||
5324: $domconfig{'login'}{$item} eq '0') &&
5325: ($env{'form.'.$item} eq '1')) {
5326: $changes{$item} = 1;
5327: }
1.42 raeburn 5328: }
5329: }
1.41 raeburn 5330: }
1.6 raeburn 5331: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 5332: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 5333: if (ref($lastactref) eq 'HASH') {
5334: $lastactref->{'domainconfig'} = 1;
5335: }
1.1 raeburn 5336: $resulttext = &mt('Changes made:').'<ul>';
5337: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 5338: if ($item eq 'loginvia') {
1.112 raeburn 5339: if (ref($changes{$item}) eq 'HASH') {
5340: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
5341: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 5342: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
5343: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
5344: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
5345: $protocol = 'http' if ($protocol ne 'https');
5346: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
5347:
5348: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
5349: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
5350: } else {
5351: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
5352: }
5353: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
5354: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
5355: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
5356: }
5357: $resulttext .= '</li>';
5358: } else {
5359: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
5360: }
1.112 raeburn 5361: } else {
1.128 raeburn 5362: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 5363: }
5364: }
1.128 raeburn 5365: $resulttext .= '</ul></li>';
1.112 raeburn 5366: }
1.168 raeburn 5367: } elsif ($item eq 'helpurl') {
5368: if (ref($changes{$item}) eq 'HASH') {
5369: foreach my $lang (sort(keys(%{$changes{$item}}))) {
5370: if (grep(/^\Q$lang\E$/,@delurls)) {
5371: my ($chg,$link);
5372: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
5373: if ($lang eq 'nolang') {
5374: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
5375: } else {
5376: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
5377: }
5378: $resulttext .= '<li>'.$chg.'</li>';
5379: } else {
5380: my $chg;
5381: if ($lang eq 'nolang') {
5382: $chg = &mt('custom log-in help file for no preferred language');
5383: } else {
5384: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
5385: }
5386: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
5387: $loginhash{'login'}{'helpurl'}{$lang}.
5388: '?inhibitmenu=yes',$chg,600,500).
5389: '</li>';
5390: }
5391: }
5392: }
1.169 raeburn 5393: } elsif ($item eq 'captcha') {
5394: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 5395: my $chgtxt;
1.169 raeburn 5396: if ($loginhash{'login'}{$item} eq 'notused') {
5397: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
5398: } else {
5399: my %captchas = &captcha_phrases();
5400: if ($captchas{$loginhash{'login'}{$item}}) {
5401: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
5402: } else {
5403: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
5404: }
5405: }
5406: $resulttext .= '<li>'.$chgtxt.'</li>';
5407: }
5408: } elsif ($item eq 'recaptchakeys') {
5409: if (ref($loginhash{'login'}) eq 'HASH') {
5410: my ($privkey,$pubkey);
5411: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
5412: $pubkey = $loginhash{'login'}{$item}{'public'};
5413: $privkey = $loginhash{'login'}{$item}{'private'};
5414: }
5415: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
5416: if (!$pubkey) {
5417: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
5418: } else {
5419: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
5420: }
5421: if (!$privkey) {
5422: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
5423: } else {
5424: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
5425: }
5426: $chgtxt .= '</ul>';
5427: $resulttext .= '<li>'.$chgtxt.'</li>';
5428: }
1.41 raeburn 5429: } else {
5430: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
5431: }
1.1 raeburn 5432: }
1.6 raeburn 5433: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 5434: } else {
5435: $resulttext = &mt('No changes made to log-in page settings');
5436: }
5437: } else {
1.11 albertel 5438: $resulttext = '<span class="LC_error">'.
5439: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5440: }
1.6 raeburn 5441: if ($errors) {
1.9 raeburn 5442: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 5443: $errors.'</ul>';
5444: }
5445: return $resulttext;
5446: }
5447:
5448: sub color_font_choices {
5449: my %choices =
5450: &Apache::lonlocal::texthash (
5451: img => "Header",
5452: bgs => "Background colors",
5453: links => "Link colors",
1.55 raeburn 5454: images => "Images",
1.6 raeburn 5455: font => "Font color",
1.201 raeburn 5456: fontmenu => "Font menu",
1.76 raeburn 5457: pgbg => "Page",
1.6 raeburn 5458: tabbg => "Header",
5459: sidebg => "Border",
5460: link => "Link",
5461: alink => "Active link",
5462: vlink => "Visited link",
5463: );
5464: return %choices;
5465: }
5466:
5467: sub modify_rolecolors {
1.205 raeburn 5468: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 5469: my ($resulttext,%rolehash);
5470: $rolehash{'rolecolors'} = {};
1.55 raeburn 5471: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
5472: if ($domconfig{'rolecolors'} eq '') {
5473: $domconfig{'rolecolors'} = {};
5474: }
5475: }
1.9 raeburn 5476: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 5477: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
5478: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
5479: $dom);
5480: if ($putresult eq 'ok') {
5481: if (keys(%changes) > 0) {
1.41 raeburn 5482: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 5483: if (ref($lastactref) eq 'HASH') {
5484: $lastactref->{'domainconfig'} = 1;
5485: }
1.6 raeburn 5486: $resulttext = &display_colorchgs($dom,\%changes,$roles,
5487: $rolehash{'rolecolors'});
5488: } else {
5489: $resulttext = &mt('No changes made to default color schemes');
5490: }
5491: } else {
1.11 albertel 5492: $resulttext = '<span class="LC_error">'.
5493: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 5494: }
5495: if ($errors) {
5496: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5497: $errors.'</ul>';
5498: }
5499: return $resulttext;
5500: }
5501:
5502: sub modify_colors {
1.9 raeburn 5503: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 5504: my (%changes,%choices);
1.51 raeburn 5505: my @bgs;
1.6 raeburn 5506: my @links = ('link','alink','vlink');
1.41 raeburn 5507: my @logintext;
1.6 raeburn 5508: my @images;
5509: my $servadm = $r->dir_config('lonAdmEMail');
5510: my $errors;
1.200 raeburn 5511: my %defaults;
1.6 raeburn 5512: foreach my $role (@{$roles}) {
5513: if ($role eq 'login') {
1.12 raeburn 5514: %choices = &login_choices();
1.41 raeburn 5515: @logintext = ('textcol','bgcol');
1.12 raeburn 5516: } else {
5517: %choices = &color_font_choices();
5518: }
5519: if ($role eq 'login') {
1.41 raeburn 5520: @images = ('img','logo','domlogo','login');
1.51 raeburn 5521: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 5522: } else {
5523: @images = ('img');
1.200 raeburn 5524: @bgs = ('pgbg','tabbg','sidebg');
5525: }
5526: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
5527: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
5528: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
5529: }
5530: if ($role eq 'login') {
5531: foreach my $item (@logintext) {
5532: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'logintext'}{$item}) {
5533: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5534: }
5535: }
5536: } else {
5537: unless($env{'form.'.$role.'_fontmenu'} eq $defaults{'fontmenu'}) {
5538: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
5539: }
1.6 raeburn 5540: }
1.200 raeburn 5541: foreach my $item (@bgs) {
5542: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'bgs'}{$item} ) {
5543: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5544: }
5545: }
5546: foreach my $item (@links) {
5547: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'links'}{$item}) {
5548: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5549: }
1.6 raeburn 5550: }
1.46 raeburn 5551: my ($configuserok,$author_ok,$switchserver) =
5552: &config_check($dom,$confname,$servadm);
1.9 raeburn 5553: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 5554: if (ref($domconfig->{$role}) ne 'HASH') {
5555: $domconfig->{$role} = {};
5556: }
1.8 raeburn 5557: foreach my $img (@images) {
1.70 raeburn 5558: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
5559: if (defined($env{'form.login_showlogo_'.$img})) {
5560: $confhash->{$role}{'showlogo'}{$img} = 1;
5561: } else {
5562: $confhash->{$role}{'showlogo'}{$img} = 0;
5563: }
5564: }
1.18 albertel 5565: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
5566: && !defined($domconfig->{$role}{$img})
5567: && !$env{'form.'.$role.'_del_'.$img}
5568: && $env{'form.'.$role.'_import_'.$img}) {
5569: # import the old configured image from the .tab setting
5570: # if they haven't provided a new one
5571: $domconfig->{$role}{$img} =
5572: $env{'form.'.$role.'_import_'.$img};
5573: }
1.6 raeburn 5574: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 5575: my $error;
1.6 raeburn 5576: if ($configuserok eq 'ok') {
1.9 raeburn 5577: if ($switchserver) {
1.12 raeburn 5578: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 5579: } else {
5580: if ($author_ok eq 'ok') {
5581: my ($result,$logourl) =
5582: &publishlogo($r,'upload',$role.'_'.$img,
5583: $dom,$confname,$img,$width,$height);
5584: if ($result eq 'ok') {
5585: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 5586: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5587: } else {
1.12 raeburn 5588: $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 5589: }
5590: } else {
1.46 raeburn 5591: $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 5592: }
5593: }
5594: } else {
1.46 raeburn 5595: $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 5596: }
5597: if ($error) {
1.8 raeburn 5598: &Apache::lonnet::logthis($error);
1.11 albertel 5599: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 5600: }
5601: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 5602: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
5603: my $error;
5604: if ($configuserok eq 'ok') {
5605: # is confname an author?
5606: if ($switchserver eq '') {
5607: if ($author_ok eq 'ok') {
5608: my ($result,$logourl) =
5609: &publishlogo($r,'copy',$domconfig->{$role}{$img},
5610: $dom,$confname,$img,$width,$height);
5611: if ($result eq 'ok') {
5612: $confhash->{$role}{$img} = $logourl;
1.18 albertel 5613: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5614: }
5615: }
5616: }
5617: }
1.6 raeburn 5618: }
5619: }
5620: }
5621: if (ref($domconfig) eq 'HASH') {
5622: if (ref($domconfig->{$role}) eq 'HASH') {
5623: foreach my $img (@images) {
5624: if ($domconfig->{$role}{$img} ne '') {
5625: if ($env{'form.'.$role.'_del_'.$img}) {
5626: $confhash->{$role}{$img} = '';
1.12 raeburn 5627: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5628: } else {
1.9 raeburn 5629: if ($confhash->{$role}{$img} eq '') {
5630: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
5631: }
1.6 raeburn 5632: }
5633: } else {
5634: if ($env{'form.'.$role.'_del_'.$img}) {
5635: $confhash->{$role}{$img} = '';
1.12 raeburn 5636: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5637: }
5638: }
1.70 raeburn 5639: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
5640: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
5641: if ($confhash->{$role}{'showlogo'}{$img} ne
5642: $domconfig->{$role}{'showlogo'}{$img}) {
5643: $changes{$role}{'showlogo'}{$img} = 1;
5644: }
5645: } else {
5646: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5647: $changes{$role}{'showlogo'}{$img} = 1;
5648: }
5649: }
5650: }
5651: }
1.6 raeburn 5652: if ($domconfig->{$role}{'font'} ne '') {
5653: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
5654: $changes{$role}{'font'} = 1;
5655: }
5656: } else {
5657: if ($confhash->{$role}{'font'}) {
5658: $changes{$role}{'font'} = 1;
5659: }
5660: }
1.107 raeburn 5661: if ($role ne 'login') {
5662: if ($domconfig->{$role}{'fontmenu'} ne '') {
5663: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
5664: $changes{$role}{'fontmenu'} = 1;
5665: }
5666: } else {
5667: if ($confhash->{$role}{'fontmenu'}) {
5668: $changes{$role}{'fontmenu'} = 1;
5669: }
1.97 tempelho 5670: }
5671: }
1.6 raeburn 5672: foreach my $item (@bgs) {
5673: if ($domconfig->{$role}{$item} ne '') {
5674: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5675: $changes{$role}{'bgs'}{$item} = 1;
5676: }
5677: } else {
5678: if ($confhash->{$role}{$item}) {
5679: $changes{$role}{'bgs'}{$item} = 1;
5680: }
5681: }
5682: }
5683: foreach my $item (@links) {
5684: if ($domconfig->{$role}{$item} ne '') {
5685: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5686: $changes{$role}{'links'}{$item} = 1;
5687: }
5688: } else {
5689: if ($confhash->{$role}{$item}) {
5690: $changes{$role}{'links'}{$item} = 1;
5691: }
5692: }
5693: }
1.41 raeburn 5694: foreach my $item (@logintext) {
5695: if ($domconfig->{$role}{$item} ne '') {
5696: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5697: $changes{$role}{'logintext'}{$item} = 1;
5698: }
5699: } else {
5700: if ($confhash->{$role}{$item}) {
5701: $changes{$role}{'logintext'}{$item} = 1;
5702: }
5703: }
5704: }
1.6 raeburn 5705: } else {
5706: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5707: \@logintext,$confhash,\%changes);
1.6 raeburn 5708: }
5709: } else {
5710: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5711: \@logintext,$confhash,\%changes);
1.6 raeburn 5712: }
5713: }
5714: return ($errors,%changes);
5715: }
5716:
1.46 raeburn 5717: sub config_check {
5718: my ($dom,$confname,$servadm) = @_;
5719: my ($configuserok,$author_ok,$switchserver,%currroles);
5720: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
5721: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
5722: $confname,$servadm);
5723: if ($configuserok eq 'ok') {
5724: $switchserver = &check_switchserver($dom,$confname);
5725: if ($switchserver eq '') {
5726: $author_ok = &check_authorstatus($dom,$confname,%currroles);
5727: }
5728: }
5729: return ($configuserok,$author_ok,$switchserver);
5730: }
5731:
1.6 raeburn 5732: sub default_change_checker {
1.41 raeburn 5733: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 5734: foreach my $item (@{$links}) {
5735: if ($confhash->{$role}{$item}) {
5736: $changes->{$role}{'links'}{$item} = 1;
5737: }
5738: }
5739: foreach my $item (@{$bgs}) {
5740: if ($confhash->{$role}{$item}) {
5741: $changes->{$role}{'bgs'}{$item} = 1;
5742: }
5743: }
1.41 raeburn 5744: foreach my $item (@{$logintext}) {
5745: if ($confhash->{$role}{$item}) {
5746: $changes->{$role}{'logintext'}{$item} = 1;
5747: }
5748: }
1.6 raeburn 5749: foreach my $img (@{$images}) {
5750: if ($env{'form.'.$role.'_del_'.$img}) {
5751: $confhash->{$role}{$img} = '';
1.12 raeburn 5752: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 5753: }
1.70 raeburn 5754: if ($role eq 'login') {
5755: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5756: $changes->{$role}{'showlogo'}{$img} = 1;
5757: }
5758: }
1.6 raeburn 5759: }
5760: if ($confhash->{$role}{'font'}) {
5761: $changes->{$role}{'font'} = 1;
5762: }
1.48 raeburn 5763: }
1.6 raeburn 5764:
5765: sub display_colorchgs {
5766: my ($dom,$changes,$roles,$confhash) = @_;
5767: my (%choices,$resulttext);
5768: if (!grep(/^login$/,@{$roles})) {
5769: $resulttext = &mt('Changes made:').'<br />';
5770: }
5771: foreach my $role (@{$roles}) {
5772: if ($role eq 'login') {
5773: %choices = &login_choices();
5774: } else {
5775: %choices = &color_font_choices();
5776: }
5777: if (ref($changes->{$role}) eq 'HASH') {
5778: if ($role ne 'login') {
5779: $resulttext .= '<h4>'.&mt($role).'</h4>';
5780: }
5781: foreach my $key (sort(keys(%{$changes->{$role}}))) {
5782: if ($role ne 'login') {
5783: $resulttext .= '<ul>';
5784: }
5785: if (ref($changes->{$role}{$key}) eq 'HASH') {
5786: if ($role ne 'login') {
5787: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
5788: }
5789: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 5790: if (($role eq 'login') && ($key eq 'showlogo')) {
5791: if ($confhash->{$role}{$key}{$item}) {
5792: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
5793: } else {
5794: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
5795: }
5796: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 5797: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
5798: } else {
1.12 raeburn 5799: my $newitem = $confhash->{$role}{$item};
5800: if ($key eq 'images') {
5801: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
5802: }
5803: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 5804: }
5805: }
5806: if ($role ne 'login') {
5807: $resulttext .= '</ul></li>';
5808: }
5809: } else {
5810: if ($confhash->{$role}{$key} eq '') {
5811: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
5812: } else {
5813: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
5814: }
5815: }
5816: if ($role ne 'login') {
5817: $resulttext .= '</ul>';
5818: }
5819: }
5820: }
5821: }
1.3 raeburn 5822: return $resulttext;
1.1 raeburn 5823: }
5824:
1.9 raeburn 5825: sub thumb_dimensions {
5826: return ('200','50');
5827: }
5828:
1.16 raeburn 5829: sub check_dimensions {
5830: my ($inputfile) = @_;
5831: my ($fullwidth,$fullheight);
5832: if ($inputfile =~ m|^[/\w.\-]+$|) {
5833: if (open(PIPE,"identify $inputfile 2>&1 |")) {
5834: my $imageinfo = <PIPE>;
5835: if (!close(PIPE)) {
5836: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
5837: }
5838: chomp($imageinfo);
5839: my ($fullsize) =
1.21 raeburn 5840: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 5841: if ($fullsize) {
5842: ($fullwidth,$fullheight) = split(/x/,$fullsize);
5843: }
5844: }
5845: }
5846: return ($fullwidth,$fullheight);
5847: }
5848:
1.9 raeburn 5849: sub check_configuser {
5850: my ($uhome,$dom,$confname,$servadm) = @_;
5851: my ($configuserok,%currroles);
5852: if ($uhome eq 'no_host') {
5853: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
5854: my $configpass = &LONCAPA::Enrollment::create_password();
5855: $configuserok =
5856: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
5857: $configpass,'','','','','',undef,$servadm);
5858: } else {
5859: $configuserok = 'ok';
5860: %currroles =
5861: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
5862: }
5863: return ($configuserok,%currroles);
5864: }
5865:
5866: sub check_authorstatus {
5867: my ($dom,$confname,%currroles) = @_;
5868: my $author_ok;
1.40 raeburn 5869: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 5870: my $start = time;
5871: my $end = 0;
5872: $author_ok =
5873: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 5874: 'au',$end,$start,'','','domconfig');
1.9 raeburn 5875: } else {
5876: $author_ok = 'ok';
5877: }
5878: return $author_ok;
5879: }
5880:
5881: sub publishlogo {
1.46 raeburn 5882: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 5883: my ($output,$fname,$logourl);
5884: if ($action eq 'upload') {
5885: $fname=$env{'form.'.$formname.'.filename'};
5886: chop($env{'form.'.$formname});
5887: } else {
5888: ($fname) = ($formname =~ /([^\/]+)$/);
5889: }
1.46 raeburn 5890: if ($savefileas ne '') {
5891: $fname = $savefileas;
5892: }
1.9 raeburn 5893: $fname=&Apache::lonnet::clean_filename($fname);
5894: # See if there is anything left
5895: unless ($fname) { return ('error: no uploaded file'); }
5896: $fname="$subdir/$fname";
1.210 raeburn 5897: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 5898: my $filepath="$docroot/priv";
5899: my $relpath = "$dom/$confname";
1.9 raeburn 5900: my ($fnamepath,$file,$fetchthumb);
5901: $file=$fname;
5902: if ($fname=~m|/|) {
5903: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
5904: }
1.164 raeburn 5905: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 5906: my $count;
1.164 raeburn 5907: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 5908: $filepath.="/$parts[$count]";
5909: if ((-e $filepath)!=1) {
5910: mkdir($filepath,02770);
5911: }
5912: }
5913: # Check for bad extension and disallow upload
5914: if ($file=~/\.(\w+)$/ &&
5915: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
5916: $output =
1.207 bisitz 5917: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 5918: } elsif ($file=~/\.(\w+)$/ &&
5919: !defined(&Apache::loncommon::fileembstyle($1))) {
5920: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
5921: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 5922: $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 5923: } elsif (-d "$filepath/$file") {
1.195 bisitz 5924: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 5925: } else {
5926: my $source = $filepath.'/'.$file;
5927: my $logfile;
5928: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 5929: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 5930: }
5931: print $logfile
5932: "\n================= Publish ".localtime()." ================\n".
5933: $env{'user.name'}.':'.$env{'user.domain'}."\n";
5934: # Save the file
5935: if (!open(FH,'>'.$source)) {
5936: &Apache::lonnet::logthis('Failed to create '.$source);
5937: return (&mt('Failed to create file'));
5938: }
5939: if ($action eq 'upload') {
5940: if (!print FH ($env{'form.'.$formname})) {
5941: &Apache::lonnet::logthis('Failed to write to '.$source);
5942: return (&mt('Failed to write file'));
5943: }
5944: } else {
5945: my $original = &Apache::lonnet::filelocation('',$formname);
5946: if(!copy($original,$source)) {
5947: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
5948: return (&mt('Failed to write file'));
5949: }
5950: }
5951: close(FH);
5952: chmod(0660, $source); # Permissions to rw-rw---.
5953:
5954: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
5955: my $copyfile=$targetdir.'/'.$file;
5956:
5957: my @parts=split(/\//,$targetdir);
5958: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
5959: for (my $count=5;$count<=$#parts;$count++) {
5960: $path.="/$parts[$count]";
5961: if (!-e $path) {
5962: print $logfile "\nCreating directory ".$path;
5963: mkdir($path,02770);
5964: }
5965: }
5966: my $versionresult;
5967: if (-e $copyfile) {
5968: $versionresult = &logo_versioning($targetdir,$file,$logfile);
5969: } else {
5970: $versionresult = 'ok';
5971: }
5972: if ($versionresult eq 'ok') {
5973: if (copy($source,$copyfile)) {
5974: print $logfile "\nCopied original source to ".$copyfile."\n";
5975: $output = 'ok';
5976: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 5977: push(@{$modified_urls},[$copyfile,$source]);
5978: my $metaoutput =
5979: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
5980: unless ($registered_cleanup) {
5981: my $handlers = $r->get_handlers('PerlCleanupHandler');
5982: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5983: $registered_cleanup=1;
5984: }
1.9 raeburn 5985: } else {
5986: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
5987: $output = &mt('Failed to copy file to RES space').", $!";
5988: }
5989: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5990: my $inputfile = $filepath.'/'.$file;
5991: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 5992: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5993: if ($fullwidth ne '' && $fullheight ne '') {
5994: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5995: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5996: system("convert -sample $thumbsize $inputfile $outfile");
5997: chmod(0660, $filepath.'/tn-'.$file);
5998: if (-e $outfile) {
5999: my $copyfile=$targetdir.'/tn-'.$file;
6000: if (copy($outfile,$copyfile)) {
6001: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 6002: my $thumb_metaoutput =
6003: &write_metadata($dom,$confname,$formname,
6004: $targetdir,'tn-'.$file,$logfile);
6005: push(@{$modified_urls},[$copyfile,$outfile]);
6006: unless ($registered_cleanup) {
6007: my $handlers = $r->get_handlers('PerlCleanupHandler');
6008: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6009: $registered_cleanup=1;
6010: }
1.16 raeburn 6011: } else {
6012: print $logfile "\nUnable to write ".$copyfile.
6013: ':'.$!."\n";
6014: }
6015: }
1.9 raeburn 6016: }
6017: }
6018: }
6019: } else {
6020: $output = $versionresult;
6021: }
6022: }
6023: return ($output,$logourl);
6024: }
6025:
6026: sub logo_versioning {
6027: my ($targetdir,$file,$logfile) = @_;
6028: my $target = $targetdir.'/'.$file;
6029: my ($maxversion,$fn,$extn,$output);
6030: $maxversion = 0;
6031: if ($file =~ /^(.+)\.(\w+)$/) {
6032: $fn=$1;
6033: $extn=$2;
6034: }
6035: opendir(DIR,$targetdir);
6036: while (my $filename=readdir(DIR)) {
6037: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
6038: $maxversion=($1>$maxversion)?$1:$maxversion;
6039: }
6040: }
6041: $maxversion++;
6042: print $logfile "\nCreating old version ".$maxversion."\n";
6043: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
6044: if (copy($target,$copyfile)) {
6045: print $logfile "Copied old target to ".$copyfile."\n";
6046: $copyfile=$copyfile.'.meta';
6047: if (copy($target.'.meta',$copyfile)) {
6048: print $logfile "Copied old target metadata to ".$copyfile."\n";
6049: $output = 'ok';
6050: } else {
6051: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
6052: $output = &mt('Failed to copy old meta').", $!, ";
6053: }
6054: } else {
6055: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
6056: $output = &mt('Failed to copy old target').", $!, ";
6057: }
6058: return $output;
6059: }
6060:
6061: sub write_metadata {
6062: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
6063: my (%metadatafields,%metadatakeys,$output);
6064: $metadatafields{'title'}=$formname;
6065: $metadatafields{'creationdate'}=time;
6066: $metadatafields{'lastrevisiondate'}=time;
6067: $metadatafields{'copyright'}='public';
6068: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
6069: $env{'user.domain'};
6070: $metadatafields{'authorspace'}=$confname.':'.$dom;
6071: $metadatafields{'domain'}=$dom;
6072: {
6073: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
6074: my $mfh;
1.155 raeburn 6075: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 6076: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 6077: unless ($_=~/\./) {
6078: my $unikey=$_;
6079: $unikey=~/^([A-Za-z]+)/;
6080: my $tag=$1;
6081: $tag=~tr/A-Z/a-z/;
6082: print $mfh "\n\<$tag";
6083: foreach (split(/\,/,$metadatakeys{$unikey})) {
6084: my $value=$metadatafields{$unikey.'.'.$_};
6085: $value=~s/\"/\'\'/g;
6086: print $mfh ' '.$_.'="'.$value.'"';
6087: }
6088: print $mfh '>'.
6089: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
6090: .'</'.$tag.'>';
6091: }
6092: }
6093: $output = 'ok';
6094: print $logfile "\nWrote metadata";
6095: close($mfh);
6096: } else {
6097: print $logfile "\nFailed to open metadata file";
1.9 raeburn 6098: $output = &mt('Could not write metadata');
6099: }
6100: }
1.155 raeburn 6101: return $output;
6102: }
6103:
6104: sub notifysubscribed {
6105: foreach my $targetsource (@{$modified_urls}){
6106: next unless (ref($targetsource) eq 'ARRAY');
6107: my ($target,$source)=@{$targetsource};
6108: if ($source ne '') {
6109: if (open(my $logfh,'>>'.$source.'.log')) {
6110: print $logfh "\nCleanup phase: Notifications\n";
6111: my @subscribed=&subscribed_hosts($target);
6112: foreach my $subhost (@subscribed) {
6113: print $logfh "\nNotifying host ".$subhost.':';
6114: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
6115: print $logfh $reply;
6116: }
6117: my @subscribedmeta=&subscribed_hosts("$target.meta");
6118: foreach my $subhost (@subscribedmeta) {
6119: print $logfh "\nNotifying host for metadata only ".$subhost.':';
6120: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
6121: $subhost);
6122: print $logfh $reply;
6123: }
6124: print $logfh "\n============ Done ============\n";
1.160 raeburn 6125: close($logfh);
1.155 raeburn 6126: }
6127: }
6128: }
6129: return OK;
6130: }
6131:
6132: sub subscribed_hosts {
6133: my ($target) = @_;
6134: my @subscribed;
6135: if (open(my $fh,"<$target.subscription")) {
6136: while (my $subline=<$fh>) {
6137: if ($subline =~ /^($match_lonid):/) {
6138: my $host = $1;
6139: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
6140: unless (grep(/^\Q$host\E$/,@subscribed)) {
6141: push(@subscribed,$host);
6142: }
6143: }
6144: }
6145: }
6146: }
6147: return @subscribed;
1.9 raeburn 6148: }
6149:
6150: sub check_switchserver {
6151: my ($dom,$confname) = @_;
6152: my ($allowed,$switchserver);
6153: my $home = &Apache::lonnet::homeserver($confname,$dom);
6154: if ($home eq 'no_host') {
6155: $home = &Apache::lonnet::domain($dom,'primary');
6156: }
6157: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 6158: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
6159: if (!$allowed) {
1.180 raeburn 6160: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 6161: }
6162: return $switchserver;
6163: }
6164:
1.1 raeburn 6165: sub modify_quotas {
1.216 raeburn 6166: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 6167: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 6168: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
6169: $author_ok,$switchserver,$errors);
1.86 raeburn 6170: if ($action eq 'quotas') {
6171: $context = 'tools';
1.163 raeburn 6172: } else {
1.86 raeburn 6173: $context = $action;
6174: }
6175: if ($context eq 'requestcourses') {
1.216 raeburn 6176: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 6177: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 6178: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
6179: %titles = &courserequest_titles();
6180: $toolregexp = join('|',@usertools);
6181: %conditions = &courserequest_conditions();
1.216 raeburn 6182: $confname = $dom.'-domainconfig';
6183: my $servadm = $r->dir_config('lonAdmEMail');
6184: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.163 raeburn 6185: } elsif ($context eq 'requestauthor') {
6186: @usertools = ('author');
6187: %titles = &authorrequest_titles();
1.86 raeburn 6188: } else {
1.162 raeburn 6189: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 6190: %titles = &tool_titles();
1.86 raeburn 6191: }
1.212 raeburn 6192: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 6193: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6194: foreach my $key (keys(%env)) {
1.101 raeburn 6195: if ($context eq 'requestcourses') {
6196: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
6197: my $item = $1;
6198: my $type = $2;
6199: if ($type =~ /^limit_(.+)/) {
6200: $limithash{$item}{$1} = $env{$key};
6201: } else {
6202: $confhash{$item}{$type} = $env{$key};
6203: }
6204: }
1.163 raeburn 6205: } elsif ($context eq 'requestauthor') {
6206: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
6207: $confhash{$1} = $env{$key};
6208: }
1.101 raeburn 6209: } else {
1.86 raeburn 6210: if ($key =~ /^form\.quota_(.+)$/) {
6211: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 6212: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
6213: $confhash{'authorquota'}{$1} = $env{$key};
6214: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 6215: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
6216: }
1.72 raeburn 6217: }
6218: }
1.163 raeburn 6219: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 6220: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 6221: @approvalnotify = sort(@approvalnotify);
6222: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.218 raeburn 6223: my @crstypes = ('official','unofficial','community','textbook');
6224: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
6225: foreach my $type (@hasuniquecode) {
6226: if (grep(/^\Q$type\E$/,@crstypes)) {
6227: $confhash{'uniquecode'}{$type} = 1;
6228: }
1.216 raeburn 6229: }
6230: my ($newbook,@allpos);
6231: if ($context eq 'requestcourses') {
6232: if ($env{'form.addbook'}) {
6233: if (($env{'form.addbook_cnum'} =~ /^$match_courseid$/) &&
6234: ($env{'form.addbook_cdom'} =~ /^$match_domain$/)) {
6235: if (&Apache::lonnet::homeserver($env{'form.addbook_cnum'},
6236: $env{'form.addbook_cdom'}) eq 'no_host') {
6237: $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
6238: '</span></li>';
6239: } else {
6240: $newbook = $env{'form.addbook_cdom'}.'_'.$env{'form.addbook_cnum'};
6241: my $position = $env{'form.addbook_pos'};
6242: $position =~ s/\D+//g;
6243: if ($position ne '') {
6244: $allpos[$position] = $newbook;
6245: }
6246: }
6247: } else {
6248: $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
6249: '</span></li>';
6250: }
6251: }
6252: }
1.102 raeburn 6253: if (ref($domconfig{$action}) eq 'HASH') {
6254: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
6255: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
6256: $changes{'notify'}{'approval'} = 1;
6257: }
6258: } else {
1.144 raeburn 6259: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6260: $changes{'notify'}{'approval'} = 1;
6261: }
6262: }
1.218 raeburn 6263: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
6264: if (ref($confhash{'uniquecode'}) eq 'HASH') {
6265: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
6266: unless ($confhash{'uniquecode'}{$crstype}) {
6267: $changes{'uniquecode'} = 1;
6268: }
6269: }
6270: unless ($changes{'uniquecode'}) {
6271: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
6272: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
6273: $changes{'uniquecode'} = 1;
6274: }
6275: }
6276: }
6277: } else {
6278: $changes{'uniquecode'} = 1;
6279: }
6280: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
6281: $changes{'uniquecode'} = 1;
1.216 raeburn 6282: }
6283: if ($context eq 'requestcourses') {
6284: if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
6285: my %deletions;
6286: my @todelete = &Apache::loncommon::get_env_multiple('form.book_del');
6287: if (@todelete) {
6288: map { $deletions{$_} = 1; } @todelete;
6289: }
6290: my %imgdeletions;
6291: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.book_image_del');
6292: if (@todeleteimages) {
6293: map { $imgdeletions{$_} = 1; } @todeleteimages;
6294: }
6295: my $maxnum = $env{'form.book_maxnum'};
6296: for (my $i=0; $i<=$maxnum; $i++) {
6297: my $key = $env{'form.book_id_'.$i};
6298: if (ref($domconfig{$action}{'textbooks'}{$key}) eq 'HASH') {
6299: if ($deletions{$key}) {
6300: if ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
6301: #FIXME need to obsolete item in RES space
6302: }
6303: next;
6304: } else {
6305: my $newpos = $env{'form.'.$key};
6306: $newpos =~ s/\D+//g;
6307: foreach my $item ('subject','title','author') {
6308: $confhash{'textbooks'}{$key}{$item} = $env{'form.book_'.$item.'_'.$i};
6309: if ($domconfig{$action}{'textbooks'}{$key}{$item} ne $confhash{'textbooks'}{$key}{$item}) {
6310: $changes{'textbooks'}{$key} = 1;
6311: }
6312: }
6313: $allpos[$newpos] = $key;
6314: }
6315: if ($imgdeletions{$key}) {
6316: $changes{'textbooks'}{$key} = 1;
6317: #FIXME need to obsolete item in RES space
6318: } elsif ($env{'form.book_image_'.$i.'.filename'}) {
6319: my ($cdom,$cnum) = split(/_/,$key);
6320: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,'book_image_'.$i,
6321: $cdom,$cnum,$configuserok,
6322: $switchserver,$author_ok);
6323: if ($imgurl) {
6324: $confhash{'textbooks'}{$key}{'image'} = $imgurl;
6325: $changes{'textbooks'}{$key} = 1;
6326: }
6327: if ($error) {
6328: &Apache::lonnet::logthis($error);
6329: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6330: }
6331: } elsif ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
6332: $confhash{'textbooks'}{$key}{'image'} =
6333: $domconfig{$action}{'textbooks'}{$key}{'image'};
6334: }
6335: }
6336: }
6337: }
6338: }
1.102 raeburn 6339: } else {
1.144 raeburn 6340: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6341: $changes{'notify'}{'approval'} = 1;
6342: }
1.218 raeburn 6343: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 6344: $changes{'uniquecode'} = 1;
6345: }
6346: }
6347: if ($context eq 'requestcourses') {
6348: if ($newbook) {
6349: $changes{'textbooks'}{$newbook} = 1;
6350: foreach my $item ('subject','title','author') {
6351: $env{'form.addbook_'.$item} =~ s/(`)/'/g;
6352: if ($env{'form.addbook_'.$item}) {
6353: $confhash{'textbooks'}{$newbook}{$item} = $env{'form.addbook_'.$item};
6354: }
6355: }
6356: if ($env{'form.addbook_image.filename'} ne '') {
6357: my ($cdom,$cnum) = split(/_/,$newbook);
6358: my ($imageurl,$error) =
6359: &process_textbook_image($r,$dom,$confname,'addbook_image',$cdom,$cnum,$configuserok,
6360: $switchserver,$author_ok);
6361: if ($imageurl) {
6362: $confhash{'textbooks'}{$newbook}{'image'} = $imageurl;
6363: }
6364: if ($error) {
6365: &Apache::lonnet::logthis($error);
6366: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6367: }
6368: }
6369: }
6370: if (@allpos > 0) {
6371: my $idx = 0;
6372: foreach my $item (@allpos) {
6373: if ($item ne '') {
6374: $confhash{'textbooks'}{$item}{'order'} = $idx;
6375: if (ref($domconfig{$action}) eq 'HASH') {
6376: if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
6377: if (ref($domconfig{$action}{'textbooks'}{$item}) eq 'HASH') {
6378: if ($domconfig{$action}{'textbooks'}{$item}{'order'} ne $idx) {
6379: $changes{'textbooks'}{$item} = 1;
6380: }
6381: }
6382: }
6383: }
6384: $idx ++;
6385: }
6386: }
6387: }
1.102 raeburn 6388: }
6389: } else {
1.86 raeburn 6390: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 6391: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 6392: }
1.72 raeburn 6393: foreach my $item (@usertools) {
6394: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 6395: my $unset;
1.101 raeburn 6396: if ($context eq 'requestcourses') {
1.104 raeburn 6397: $unset = '0';
6398: if ($type eq '_LC_adv') {
6399: $unset = '';
6400: }
1.101 raeburn 6401: if ($confhash{$item}{$type} eq 'autolimit') {
6402: $confhash{$item}{$type} .= '=';
6403: unless ($limithash{$item}{$type} =~ /\D/) {
6404: $confhash{$item}{$type} .= $limithash{$item}{$type};
6405: }
6406: }
1.163 raeburn 6407: } elsif ($context eq 'requestauthor') {
6408: $unset = '0';
6409: if ($type eq '_LC_adv') {
6410: $unset = '';
6411: }
1.72 raeburn 6412: } else {
1.101 raeburn 6413: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
6414: $confhash{$item}{$type} = 1;
6415: } else {
6416: $confhash{$item}{$type} = 0;
6417: }
1.72 raeburn 6418: }
1.86 raeburn 6419: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 6420: if ($action eq 'requestauthor') {
6421: if ($domconfig{$action}{$type} ne $confhash{$type}) {
6422: $changes{$type} = 1;
6423: }
6424: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 6425: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
6426: $changes{$item}{$type} = 1;
6427: }
6428: } else {
6429: if ($context eq 'requestcourses') {
1.104 raeburn 6430: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 6431: $changes{$item}{$type} = 1;
6432: }
6433: } else {
6434: if (!$confhash{$item}{$type}) {
6435: $changes{$item}{$type} = 1;
6436: }
6437: }
6438: }
6439: } else {
6440: if ($context eq 'requestcourses') {
1.104 raeburn 6441: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 6442: $changes{$item}{$type} = 1;
6443: }
1.163 raeburn 6444: } elsif ($context eq 'requestauthor') {
6445: if ($confhash{$type} ne $unset) {
6446: $changes{$type} = 1;
6447: }
1.72 raeburn 6448: } else {
6449: if (!$confhash{$item}{$type}) {
6450: $changes{$item}{$type} = 1;
6451: }
6452: }
6453: }
1.1 raeburn 6454: }
6455: }
1.163 raeburn 6456: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 6457: if (ref($domconfig{'quotas'}) eq 'HASH') {
6458: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
6459: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
6460: if (exists($confhash{'defaultquota'}{$key})) {
6461: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
6462: $changes{'defaultquota'}{$key} = 1;
6463: }
6464: } else {
6465: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 6466: }
6467: }
1.86 raeburn 6468: } else {
6469: foreach my $key (keys(%{$domconfig{'quotas'}})) {
6470: if (exists($confhash{'defaultquota'}{$key})) {
6471: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
6472: $changes{'defaultquota'}{$key} = 1;
6473: }
6474: } else {
6475: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 6476: }
1.1 raeburn 6477: }
6478: }
1.197 raeburn 6479: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
6480: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
6481: if (exists($confhash{'authorquota'}{$key})) {
6482: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
6483: $changes{'authorquota'}{$key} = 1;
6484: }
6485: } else {
6486: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
6487: }
6488: }
6489: }
1.1 raeburn 6490: }
1.86 raeburn 6491: if (ref($confhash{'defaultquota'}) eq 'HASH') {
6492: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
6493: if (ref($domconfig{'quotas'}) eq 'HASH') {
6494: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
6495: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
6496: $changes{'defaultquota'}{$key} = 1;
6497: }
6498: } else {
6499: if (!exists($domconfig{'quotas'}{$key})) {
6500: $changes{'defaultquota'}{$key} = 1;
6501: }
1.72 raeburn 6502: }
6503: } else {
1.86 raeburn 6504: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 6505: }
1.1 raeburn 6506: }
6507: }
1.197 raeburn 6508: if (ref($confhash{'authorquota'}) eq 'HASH') {
6509: foreach my $key (keys(%{$confhash{'authorquota'}})) {
6510: if (ref($domconfig{'quotas'}) eq 'HASH') {
6511: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
6512: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
6513: $changes{'authorquota'}{$key} = 1;
6514: }
6515: } else {
6516: $changes{'authorquota'}{$key} = 1;
6517: }
6518: } else {
6519: $changes{'authorquota'}{$key} = 1;
6520: }
6521: }
6522: }
1.1 raeburn 6523: }
1.72 raeburn 6524:
1.163 raeburn 6525: if ($context eq 'requestauthor') {
6526: $domdefaults{'requestauthor'} = \%confhash;
6527: } else {
6528: foreach my $key (keys(%confhash)) {
1.216 raeburn 6529: unless (($context eq 'requestcourses') && ($key eq 'textbooks')) {
6530: $domdefaults{$key} = $confhash{$key};
6531: }
1.163 raeburn 6532: }
1.72 raeburn 6533: }
1.163 raeburn 6534:
1.1 raeburn 6535: my %quotahash = (
1.86 raeburn 6536: $action => { %confhash }
1.1 raeburn 6537: );
6538: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
6539: $dom);
6540: if ($putresult eq 'ok') {
6541: if (keys(%changes) > 0) {
1.72 raeburn 6542: my $cachetime = 24*60*60;
6543: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 6544: if (ref($lastactref) eq 'HASH') {
6545: $lastactref->{'domdefaults'} = 1;
6546: }
1.1 raeburn 6547: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 6548: unless (($context eq 'requestcourses') ||
1.163 raeburn 6549: ($context eq 'requestauthor')) {
1.86 raeburn 6550: if (ref($changes{'defaultquota'}) eq 'HASH') {
6551: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
6552: foreach my $type (@{$types},'default') {
6553: if (defined($changes{'defaultquota'}{$type})) {
6554: my $typetitle = $usertypes->{$type};
6555: if ($type eq 'default') {
6556: $typetitle = $othertitle;
6557: }
1.213 raeburn 6558: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 6559: }
6560: }
1.86 raeburn 6561: $resulttext .= '</ul></li>';
1.72 raeburn 6562: }
1.197 raeburn 6563: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 6564: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 6565: foreach my $type (@{$types},'default') {
6566: if (defined($changes{'authorquota'}{$type})) {
6567: my $typetitle = $usertypes->{$type};
6568: if ($type eq 'default') {
6569: $typetitle = $othertitle;
6570: }
1.213 raeburn 6571: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 6572: }
6573: }
6574: $resulttext .= '</ul></li>';
6575: }
1.72 raeburn 6576: }
1.80 raeburn 6577: my %newenv;
1.72 raeburn 6578: foreach my $item (@usertools) {
1.163 raeburn 6579: my (%haschgs,%inconf);
6580: if ($context eq 'requestauthor') {
6581: %haschgs = %changes;
1.210 raeburn 6582: %inconf = %confhash;
1.163 raeburn 6583: } else {
6584: if (ref($changes{$item}) eq 'HASH') {
6585: %haschgs = %{$changes{$item}};
6586: }
6587: if (ref($confhash{$item}) eq 'HASH') {
6588: %inconf = %{$confhash{$item}};
6589: }
6590: }
6591: if (keys(%haschgs) > 0) {
1.80 raeburn 6592: my $newacc =
6593: &Apache::lonnet::usertools_access($env{'user.name'},
6594: $env{'user.domain'},
1.86 raeburn 6595: $item,'reload',$context);
1.210 raeburn 6596: if (($context eq 'requestcourses') ||
1.163 raeburn 6597: ($context eq 'requestauthor')) {
1.108 raeburn 6598: if ($env{'environment.canrequest.'.$item} ne $newacc) {
6599: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 6600: }
6601: } else {
6602: if ($env{'environment.availabletools.'.$item} ne $newacc) {
6603: $newenv{'environment.availabletools.'.$item} = $newacc;
6604: }
1.80 raeburn 6605: }
1.163 raeburn 6606: unless ($context eq 'requestauthor') {
6607: $resulttext .= '<li>'.$titles{$item}.'<ul>';
6608: }
1.72 raeburn 6609: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 6610: if ($haschgs{$type}) {
1.72 raeburn 6611: my $typetitle = $usertypes->{$type};
6612: if ($type eq 'default') {
6613: $typetitle = $othertitle;
6614: } elsif ($type eq '_LC_adv') {
6615: $typetitle = 'LON-CAPA Advanced Users';
6616: }
1.163 raeburn 6617: if ($inconf{$type}) {
1.101 raeburn 6618: if ($context eq 'requestcourses') {
6619: my $cond;
1.163 raeburn 6620: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 6621: if ($1 eq '') {
6622: $cond = &mt('(Automatic processing of any request).');
6623: } else {
6624: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
6625: }
6626: } else {
1.163 raeburn 6627: $cond = $conditions{$inconf{$type}};
1.101 raeburn 6628: }
6629: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 6630: } elsif ($context eq 'requestauthor') {
6631: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
6632: $titles{$inconf{$type}},$typetitle);
6633:
1.101 raeburn 6634: } else {
6635: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
6636: }
1.72 raeburn 6637: } else {
1.104 raeburn 6638: if ($type eq '_LC_adv') {
1.163 raeburn 6639: if ($inconf{$type} eq '0') {
1.104 raeburn 6640: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6641: } else {
6642: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
6643: }
6644: } else {
6645: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6646: }
1.72 raeburn 6647: }
6648: }
1.26 raeburn 6649: }
1.163 raeburn 6650: unless ($context eq 'requestauthor') {
6651: $resulttext .= '</ul></li>';
6652: }
1.26 raeburn 6653: }
1.1 raeburn 6654: }
1.163 raeburn 6655: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 6656: if (ref($changes{'notify'}) eq 'HASH') {
6657: if ($changes{'notify'}{'approval'}) {
6658: if (ref($confhash{'notify'}) eq 'HASH') {
6659: if ($confhash{'notify'}{'approval'}) {
6660: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
6661: } else {
1.163 raeburn 6662: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 6663: }
6664: }
6665: }
6666: }
6667: }
1.216 raeburn 6668: if ($action eq 'requestcourses') {
6669: my @offon = ('off','on');
6670: if ($changes{'uniquecode'}) {
1.218 raeburn 6671: if (ref($confhash{'uniquecode'}) eq 'HASH') {
6672: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
6673: $resulttext .= '<li>'.
6674: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
6675: '</li>';
6676: } else {
6677: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
6678: '</li>';
6679: }
1.216 raeburn 6680: }
6681: if (ref($changes{'textbooks'}) eq 'HASH') {
6682: $resulttext .= '<li>'.&mt('Available textbooks updated').'<ul>';
6683: foreach my $key (sort(keys(%{$changes{'textbooks'}}))) {
6684: my %coursehash = &Apache::lonnet::coursedescription($key);
6685: my $coursetitle = $coursehash{'description'};
6686: my $position = $confhash{'textbooks'}{$key}{'order'} + 1;
6687: $resulttext .= '<li>';
6688: foreach my $item ('subject','title','author') {
6689: my $name = $item.':';
6690: $name =~ s/^(\w)/\U$1/;
6691: $resulttext .= &mt($name).' '.$confhash{'textbooks'}{$key}{$item}.'<br />';
6692: }
6693: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
6694: if ($confhash{'textbooks'}{$key}{'image'}) {
6695: $resulttext .= ' '.&mt('Image: [_1]',
6696: '<img src="'.$confhash{'textbooks'}{$key}{'image'}.'"'.
6697: ' alt="Textbook cover" />').'<br />';
6698: }
6699: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
6700: }
6701: $resulttext .= '</ul></li>';
6702: }
6703: }
1.1 raeburn 6704: $resulttext .= '</ul>';
1.80 raeburn 6705: if (keys(%newenv)) {
6706: &Apache::lonnet::appenv(\%newenv);
6707: }
1.1 raeburn 6708: } else {
1.86 raeburn 6709: if ($context eq 'requestcourses') {
6710: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 6711: } elsif ($context eq 'requestauthor') {
6712: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 6713: } else {
1.90 weissno 6714: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 6715: }
1.1 raeburn 6716: }
6717: } else {
1.11 albertel 6718: $resulttext = '<span class="LC_error">'.
6719: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6720: }
1.216 raeburn 6721: if ($errors) {
6722: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
6723: '<ul>'.$errors.'</ul></p>';
6724: }
1.3 raeburn 6725: return $resulttext;
1.1 raeburn 6726: }
6727:
1.216 raeburn 6728: sub process_textbook_image {
6729: my ($r,$dom,$confname,$caller,$cdom,$cnum,$configuserok,$switchserver,$author_ok) = @_;
6730: my $filename = $env{'form.'.$caller.'.filename'};
6731: my ($error,$url);
6732: my ($width,$height) = (50,50);
6733: if ($configuserok eq 'ok') {
6734: if ($switchserver) {
6735: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
6736: $switchserver);
6737: } elsif ($author_ok eq 'ok') {
6738: my ($result,$imageurl) =
6739: &publishlogo($r,'upload',$caller,$dom,$confname,
6740: "textbooks/$dom/$cnum/cover",$width,$height);
6741: if ($result eq 'ok') {
6742: $url = $imageurl;
6743: } else {
6744: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
6745: }
6746: } else {
6747: $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);
6748: }
6749: } else {
6750: $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);
6751: }
6752: return ($url,$error);
6753: }
6754:
1.3 raeburn 6755: sub modify_autoenroll {
1.205 raeburn 6756: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 6757: my ($resulttext,%changes);
6758: my %currautoenroll;
6759: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6760: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
6761: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
6762: }
6763: }
6764: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
6765: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 6766: sender => 'Sender for notification messages',
6767: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 6768: my @offon = ('off','on');
1.17 raeburn 6769: my $sender_uname = $env{'form.sender_uname'};
6770: my $sender_domain = $env{'form.sender_domain'};
6771: if ($sender_domain eq '') {
6772: $sender_uname = '';
6773: } elsif ($sender_uname eq '') {
6774: $sender_domain = '';
6775: }
1.129 raeburn 6776: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 6777: my %autoenrollhash = (
1.129 raeburn 6778: autoenroll => { 'run' => $env{'form.autoenroll_run'},
6779: 'sender_uname' => $sender_uname,
6780: 'sender_domain' => $sender_domain,
6781: 'co-owners' => $coowners,
1.1 raeburn 6782: }
6783: );
1.4 raeburn 6784: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
6785: $dom);
1.1 raeburn 6786: if ($putresult eq 'ok') {
6787: if (exists($currautoenroll{'run'})) {
6788: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
6789: $changes{'run'} = 1;
6790: }
6791: } elsif ($autorun) {
6792: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 6793: $changes{'run'} = 1;
1.1 raeburn 6794: }
6795: }
1.17 raeburn 6796: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 6797: $changes{'sender'} = 1;
6798: }
1.17 raeburn 6799: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 6800: $changes{'sender'} = 1;
6801: }
1.129 raeburn 6802: if ($currautoenroll{'co-owners'} ne '') {
6803: if ($currautoenroll{'co-owners'} ne $coowners) {
6804: $changes{'coowners'} = 1;
6805: }
6806: } elsif ($coowners) {
6807: $changes{'coowners'} = 1;
6808: }
1.1 raeburn 6809: if (keys(%changes) > 0) {
6810: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 6811: if ($changes{'run'}) {
1.1 raeburn 6812: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
6813: }
6814: if ($changes{'sender'}) {
1.17 raeburn 6815: if ($sender_uname eq '' || $sender_domain eq '') {
6816: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
6817: } else {
6818: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
6819: }
1.1 raeburn 6820: }
1.129 raeburn 6821: if ($changes{'coowners'}) {
6822: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
6823: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 6824: if (ref($lastactref) eq 'HASH') {
6825: $lastactref->{'domainconfig'} = 1;
6826: }
1.129 raeburn 6827: }
1.1 raeburn 6828: $resulttext .= '</ul>';
6829: } else {
6830: $resulttext = &mt('No changes made to auto-enrollment settings');
6831: }
6832: } else {
1.11 albertel 6833: $resulttext = '<span class="LC_error">'.
6834: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6835: }
1.3 raeburn 6836: return $resulttext;
1.1 raeburn 6837: }
6838:
6839: sub modify_autoupdate {
1.3 raeburn 6840: my ($dom,%domconfig) = @_;
1.1 raeburn 6841: my ($resulttext,%currautoupdate,%fields,%changes);
6842: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
6843: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
6844: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
6845: }
6846: }
6847: my @offon = ('off','on');
6848: my %title = &Apache::lonlocal::texthash (
6849: run => 'Auto-update:',
6850: classlists => 'Updates to user information in classlists?'
6851: );
1.44 raeburn 6852: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6853: my %fieldtitles = &Apache::lonlocal::texthash (
6854: id => 'Student/Employee ID',
1.20 raeburn 6855: permanentemail => 'E-mail address',
1.1 raeburn 6856: lastname => 'Last Name',
6857: firstname => 'First Name',
6858: middlename => 'Middle Name',
1.132 raeburn 6859: generation => 'Generation',
1.1 raeburn 6860: );
1.142 raeburn 6861: $othertitle = &mt('All users');
1.1 raeburn 6862: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 6863: $othertitle = &mt('Other users');
1.1 raeburn 6864: }
6865: foreach my $key (keys(%env)) {
6866: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 6867: my ($usertype,$item) = ($1,$2);
6868: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
6869: if ($usertype eq 'default') {
6870: push(@{$fields{$1}},$2);
6871: } elsif (ref($types) eq 'ARRAY') {
6872: if (grep(/^\Q$usertype\E$/,@{$types})) {
6873: push(@{$fields{$1}},$2);
6874: }
6875: }
6876: }
1.1 raeburn 6877: }
6878: }
1.131 raeburn 6879: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
6880: @lockablenames = sort(@lockablenames);
6881: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
6882: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6883: if (@changed) {
6884: $changes{'lockablenames'} = 1;
6885: }
6886: } else {
6887: if (@lockablenames) {
6888: $changes{'lockablenames'} = 1;
6889: }
6890: }
1.1 raeburn 6891: my %updatehash = (
6892: autoupdate => { run => $env{'form.autoupdate_run'},
6893: classlists => $env{'form.classlists'},
6894: fields => {%fields},
1.131 raeburn 6895: lockablenames => \@lockablenames,
1.1 raeburn 6896: }
6897: );
6898: foreach my $key (keys(%currautoupdate)) {
6899: if (($key eq 'run') || ($key eq 'classlists')) {
6900: if (exists($updatehash{autoupdate}{$key})) {
6901: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
6902: $changes{$key} = 1;
6903: }
6904: }
6905: } elsif ($key eq 'fields') {
6906: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 6907: foreach my $item (@{$types},'default') {
1.1 raeburn 6908: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
6909: my $change = 0;
6910: foreach my $type (@{$currautoupdate{$key}{$item}}) {
6911: if (!exists($fields{$item})) {
6912: $change = 1;
1.132 raeburn 6913: last;
1.1 raeburn 6914: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 6915: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 6916: $change = 1;
1.132 raeburn 6917: last;
1.1 raeburn 6918: }
6919: }
6920: }
6921: if ($change) {
6922: push(@{$changes{$key}},$item);
6923: }
1.26 raeburn 6924: }
1.1 raeburn 6925: }
6926: }
1.131 raeburn 6927: } elsif ($key eq 'lockablenames') {
6928: if (ref($currautoupdate{$key}) eq 'ARRAY') {
6929: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6930: if (@changed) {
6931: $changes{'lockablenames'} = 1;
6932: }
6933: } else {
6934: if (@lockablenames) {
6935: $changes{'lockablenames'} = 1;
6936: }
6937: }
6938: }
6939: }
6940: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
6941: if (@lockablenames) {
6942: $changes{'lockablenames'} = 1;
1.1 raeburn 6943: }
6944: }
1.26 raeburn 6945: foreach my $item (@{$types},'default') {
6946: if (defined($fields{$item})) {
6947: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 6948: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
6949: my $change = 0;
6950: if (ref($fields{$item}) eq 'ARRAY') {
6951: foreach my $type (@{$fields{$item}}) {
6952: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
6953: $change = 1;
6954: last;
6955: }
6956: }
6957: }
6958: if ($change) {
6959: push(@{$changes{'fields'}},$item);
6960: }
6961: } else {
1.26 raeburn 6962: push(@{$changes{'fields'}},$item);
6963: }
6964: } else {
6965: push(@{$changes{'fields'}},$item);
1.1 raeburn 6966: }
6967: }
6968: }
6969: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
6970: $dom);
6971: if ($putresult eq 'ok') {
6972: if (keys(%changes) > 0) {
6973: $resulttext = &mt('Changes made:').'<ul>';
6974: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 6975: if ($key eq 'lockablenames') {
6976: $resulttext .= '<li>';
6977: if (@lockablenames) {
6978: $usertypes->{'default'} = $othertitle;
6979: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
6980: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
6981: } else {
6982: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
6983: }
6984: $resulttext .= '</li>';
6985: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 6986: foreach my $item (@{$changes{$key}}) {
6987: my @newvalues;
6988: foreach my $type (@{$fields{$item}}) {
6989: push(@newvalues,$fieldtitles{$type});
6990: }
1.3 raeburn 6991: my $newvaluestr;
6992: if (@newvalues > 0) {
6993: $newvaluestr = join(', ',@newvalues);
6994: } else {
6995: $newvaluestr = &mt('none');
1.6 raeburn 6996: }
1.1 raeburn 6997: if ($item eq 'default') {
1.26 raeburn 6998: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 6999: } else {
1.26 raeburn 7000: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 7001: }
7002: }
7003: } else {
7004: my $newvalue;
7005: if ($key eq 'run') {
7006: $newvalue = $offon[$env{'form.autoupdate_run'}];
7007: } else {
7008: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 7009: }
1.1 raeburn 7010: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
7011: }
7012: }
7013: $resulttext .= '</ul>';
7014: } else {
1.3 raeburn 7015: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 7016: }
7017: } else {
1.11 albertel 7018: $resulttext = '<span class="LC_error">'.
7019: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7020: }
1.3 raeburn 7021: return $resulttext;
1.1 raeburn 7022: }
7023:
1.125 raeburn 7024: sub modify_autocreate {
7025: my ($dom,%domconfig) = @_;
7026: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
7027: if (ref($domconfig{'autocreate'}) eq 'HASH') {
7028: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
7029: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
7030: }
7031: }
7032: my %title= ( xml => 'Auto-creation of courses in XML course description files',
7033: req => 'Auto-creation of validated requests for official courses',
7034: xmldc => 'Identity of course creator of courses from XML files',
7035: );
7036: my @types = ('xml','req');
7037: foreach my $item (@types) {
7038: $newvals{$item} = $env{'form.autocreate_'.$item};
7039: $newvals{$item} =~ s/\D//g;
7040: $newvals{$item} = 0 if ($newvals{$item} eq '');
7041: }
7042: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
7043: my %domcoords = &get_active_dcs($dom);
7044: unless (exists($domcoords{$newvals{'xmldc'}})) {
7045: $newvals{'xmldc'} = '';
7046: }
7047: %autocreatehash = (
7048: autocreate => { xml => $newvals{'xml'},
7049: req => $newvals{'req'},
7050: }
7051: );
7052: if ($newvals{'xmldc'} ne '') {
7053: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
7054: }
7055: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
7056: $dom);
7057: if ($putresult eq 'ok') {
7058: my @items = @types;
7059: if ($newvals{'xml'}) {
7060: push(@items,'xmldc');
7061: }
7062: foreach my $item (@items) {
7063: if (exists($currautocreate{$item})) {
7064: if ($currautocreate{$item} ne $newvals{$item}) {
7065: $changes{$item} = 1;
7066: }
7067: } elsif ($newvals{$item}) {
7068: $changes{$item} = 1;
7069: }
7070: }
7071: if (keys(%changes) > 0) {
7072: my @offon = ('off','on');
7073: $resulttext = &mt('Changes made:').'<ul>';
7074: foreach my $item (@types) {
7075: if ($changes{$item}) {
7076: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 7077: $resulttext .= '<li>'.
7078: &mt("$title{$item} set to [_1]$newtxt [_2]",
7079: '<b>','</b>').
7080: '</li>';
1.125 raeburn 7081: }
7082: }
7083: if ($changes{'xmldc'}) {
7084: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
7085: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 7086: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 7087: }
7088: $resulttext .= '</ul>';
7089: } else {
7090: $resulttext = &mt('No changes made to auto-creation settings');
7091: }
7092: } else {
7093: $resulttext = '<span class="LC_error">'.
7094: &mt('An error occurred: [_1]',$putresult).'</span>';
7095: }
7096: return $resulttext;
7097: }
7098:
1.23 raeburn 7099: sub modify_directorysrch {
7100: my ($dom,%domconfig) = @_;
7101: my ($resulttext,%changes);
7102: my %currdirsrch;
7103: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
7104: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
7105: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
7106: }
7107: }
7108: my %title = ( available => 'Directory search available',
1.24 raeburn 7109: localonly => 'Other domains can search',
1.23 raeburn 7110: searchby => 'Search types',
7111: searchtypes => 'Search latitude');
7112: my @offon = ('off','on');
1.24 raeburn 7113: my @otherdoms = ('Yes','No');
1.23 raeburn 7114:
1.25 raeburn 7115: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 7116: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
7117: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
7118:
1.44 raeburn 7119: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 7120: if (keys(%{$usertypes}) == 0) {
7121: @cansearch = ('default');
7122: } else {
7123: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
7124: foreach my $type (@{$currdirsrch{'cansearch'}}) {
7125: if (!grep(/^\Q$type\E$/,@cansearch)) {
7126: push(@{$changes{'cansearch'}},$type);
7127: }
1.23 raeburn 7128: }
1.26 raeburn 7129: foreach my $type (@cansearch) {
7130: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
7131: push(@{$changes{'cansearch'}},$type);
7132: }
1.23 raeburn 7133: }
1.26 raeburn 7134: } else {
7135: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 7136: }
7137: }
7138:
7139: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
7140: foreach my $by (@{$currdirsrch{'searchby'}}) {
7141: if (!grep(/^\Q$by\E$/,@searchby)) {
7142: push(@{$changes{'searchby'}},$by);
7143: }
7144: }
7145: foreach my $by (@searchby) {
7146: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
7147: push(@{$changes{'searchby'}},$by);
7148: }
7149: }
7150: } else {
7151: push(@{$changes{'searchby'}},@searchby);
7152: }
1.25 raeburn 7153:
7154: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
7155: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
7156: if (!grep(/^\Q$type\E$/,@searchtypes)) {
7157: push(@{$changes{'searchtypes'}},$type);
7158: }
7159: }
7160: foreach my $type (@searchtypes) {
7161: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
7162: push(@{$changes{'searchtypes'}},$type);
7163: }
7164: }
7165: } else {
7166: if (exists($currdirsrch{'searchtypes'})) {
7167: foreach my $type (@searchtypes) {
7168: if ($type ne $currdirsrch{'searchtypes'}) {
7169: push(@{$changes{'searchtypes'}},$type);
7170: }
7171: }
7172: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
7173: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
7174: }
7175: } else {
7176: push(@{$changes{'searchtypes'}},@searchtypes);
7177: }
7178: }
7179:
1.23 raeburn 7180: my %dirsrch_hash = (
7181: directorysrch => { available => $env{'form.dirsrch_available'},
7182: cansearch => \@cansearch,
1.24 raeburn 7183: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 7184: searchby => \@searchby,
1.25 raeburn 7185: searchtypes => \@searchtypes,
1.23 raeburn 7186: }
7187: );
7188: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
7189: $dom);
7190: if ($putresult eq 'ok') {
7191: if (exists($currdirsrch{'available'})) {
7192: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
7193: $changes{'available'} = 1;
7194: }
7195: } else {
7196: if ($env{'form.dirsrch_available'} eq '1') {
7197: $changes{'available'} = 1;
7198: }
7199: }
1.24 raeburn 7200: if (exists($currdirsrch{'localonly'})) {
7201: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
7202: $changes{'localonly'} = 1;
7203: }
7204: } else {
7205: if ($env{'form.dirsrch_localonly'} eq '1') {
7206: $changes{'localonly'} = 1;
7207: }
7208: }
1.23 raeburn 7209: if (keys(%changes) > 0) {
7210: $resulttext = &mt('Changes made:').'<ul>';
7211: if ($changes{'available'}) {
7212: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
7213: }
1.24 raeburn 7214: if ($changes{'localonly'}) {
7215: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
7216: }
7217:
1.23 raeburn 7218: if (ref($changes{'cansearch'}) eq 'ARRAY') {
7219: my $chgtext;
1.26 raeburn 7220: if (ref($usertypes) eq 'HASH') {
7221: if (keys(%{$usertypes}) > 0) {
7222: foreach my $type (@{$types}) {
7223: if (grep(/^\Q$type\E$/,@cansearch)) {
7224: $chgtext .= $usertypes->{$type}.'; ';
7225: }
7226: }
7227: if (grep(/^default$/,@cansearch)) {
7228: $chgtext .= $othertitle;
7229: } else {
7230: $chgtext =~ s/\; $//;
7231: }
1.210 raeburn 7232: $resulttext .=
1.178 raeburn 7233: '<li>'.
7234: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
7235: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
7236: '</li>';
1.23 raeburn 7237: }
7238: }
7239: }
7240: if (ref($changes{'searchby'}) eq 'ARRAY') {
7241: my ($searchtitles,$titleorder) = &sorted_searchtitles();
7242: my $chgtext;
7243: foreach my $type (@{$titleorder}) {
7244: if (grep(/^\Q$type\E$/,@searchby)) {
7245: if (defined($searchtitles->{$type})) {
7246: $chgtext .= $searchtitles->{$type}.'; ';
7247: }
7248: }
7249: }
7250: $chgtext =~ s/\; $//;
7251: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
7252: }
1.25 raeburn 7253: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
7254: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
7255: my $chgtext;
7256: foreach my $type (@{$srchtypeorder}) {
7257: if (grep(/^\Q$type\E$/,@searchtypes)) {
7258: if (defined($srchtypes_desc->{$type})) {
7259: $chgtext .= $srchtypes_desc->{$type}.'; ';
7260: }
7261: }
7262: }
7263: $chgtext =~ s/\; $//;
1.178 raeburn 7264: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 7265: }
7266: $resulttext .= '</ul>';
7267: } else {
7268: $resulttext = &mt('No changes made to institution directory search settings');
7269: }
7270: } else {
7271: $resulttext = '<span class="LC_error">'.
1.27 raeburn 7272: &mt('An error occurred: [_1]',$putresult).'</span>';
7273: }
7274: return $resulttext;
7275: }
7276:
1.28 raeburn 7277: sub modify_contacts {
1.205 raeburn 7278: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 7279: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
7280: if (ref($domconfig{'contacts'}) eq 'HASH') {
7281: foreach my $key (keys(%{$domconfig{'contacts'}})) {
7282: $currsetting{$key} = $domconfig{'contacts'}{$key};
7283: }
7284: }
1.134 raeburn 7285: my (%others,%to,%bcc);
1.28 raeburn 7286: my @contacts = ('supportemail','adminemail');
1.102 raeburn 7287: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.203 raeburn 7288: 'requestsmail','updatesmail','idconflictsmail');
7289: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 7290: foreach my $type (@mailings) {
7291: @{$newsetting{$type}} =
7292: &Apache::loncommon::get_env_multiple('form.'.$type);
7293: foreach my $item (@contacts) {
7294: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
7295: $contacts_hash{contacts}{$type}{$item} = 1;
7296: } else {
7297: $contacts_hash{contacts}{$type}{$item} = 0;
7298: }
7299: }
7300: $others{$type} = $env{'form.'.$type.'_others'};
7301: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 7302: if ($type eq 'helpdeskmail') {
7303: $bcc{$type} = $env{'form.'.$type.'_bcc'};
7304: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
7305: }
1.28 raeburn 7306: }
7307: foreach my $item (@contacts) {
7308: $to{$item} = $env{'form.'.$item};
7309: $contacts_hash{'contacts'}{$item} = $to{$item};
7310: }
1.203 raeburn 7311: foreach my $item (@toggles) {
7312: if ($env{'form.'.$item} =~ /^(0|1)$/) {
7313: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
7314: }
7315: }
1.28 raeburn 7316: if (keys(%currsetting) > 0) {
7317: foreach my $item (@contacts) {
7318: if ($to{$item} ne $currsetting{$item}) {
7319: $changes{$item} = 1;
7320: }
7321: }
7322: foreach my $type (@mailings) {
7323: foreach my $item (@contacts) {
7324: if (ref($currsetting{$type}) eq 'HASH') {
7325: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
7326: push(@{$changes{$type}},$item);
7327: }
7328: } else {
7329: push(@{$changes{$type}},@{$newsetting{$type}});
7330: }
7331: }
7332: if ($others{$type} ne $currsetting{$type}{'others'}) {
7333: push(@{$changes{$type}},'others');
7334: }
1.134 raeburn 7335: if ($type eq 'helpdeskmail') {
7336: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
7337: push(@{$changes{$type}},'bcc');
7338: }
7339: }
1.28 raeburn 7340: }
7341: } else {
7342: my %default;
7343: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
7344: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
7345: $default{'errormail'} = 'adminemail';
7346: $default{'packagesmail'} = 'adminemail';
7347: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 7348: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 7349: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 7350: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 7351: foreach my $item (@contacts) {
7352: if ($to{$item} ne $default{$item}) {
7353: $changes{$item} = 1;
1.203 raeburn 7354: }
1.28 raeburn 7355: }
7356: foreach my $type (@mailings) {
7357: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
7358:
7359: push(@{$changes{$type}},@{$newsetting{$type}});
7360: }
7361: if ($others{$type} ne '') {
7362: push(@{$changes{$type}},'others');
1.134 raeburn 7363: }
7364: if ($type eq 'helpdeskmail') {
7365: if ($bcc{$type} ne '') {
7366: push(@{$changes{$type}},'bcc');
7367: }
7368: }
1.28 raeburn 7369: }
7370: }
1.203 raeburn 7371: foreach my $item (@toggles) {
7372: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
7373: $changes{$item} = 1;
7374: } elsif ((!$env{'form.'.$item}) &&
7375: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
7376: $changes{$item} = 1;
7377: }
7378: }
1.28 raeburn 7379: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
7380: $dom);
7381: if ($putresult eq 'ok') {
7382: if (keys(%changes) > 0) {
1.205 raeburn 7383: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7384: if (ref($lastactref) eq 'HASH') {
7385: $lastactref->{'domainconfig'} = 1;
7386: }
1.28 raeburn 7387: my ($titles,$short_titles) = &contact_titles();
7388: $resulttext = &mt('Changes made:').'<ul>';
7389: foreach my $item (@contacts) {
7390: if ($changes{$item}) {
7391: $resulttext .= '<li>'.$titles->{$item}.
7392: &mt(' set to: ').
7393: '<span class="LC_cusr_emph">'.
7394: $to{$item}.'</span></li>';
7395: }
7396: }
7397: foreach my $type (@mailings) {
7398: if (ref($changes{$type}) eq 'ARRAY') {
7399: $resulttext .= '<li>'.$titles->{$type}.': ';
7400: my @text;
7401: foreach my $item (@{$newsetting{$type}}) {
7402: push(@text,$short_titles->{$item});
7403: }
7404: if ($others{$type} ne '') {
7405: push(@text,$others{$type});
7406: }
7407: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 7408: join(', ',@text).'</span>';
7409: if ($type eq 'helpdeskmail') {
7410: if ($bcc{$type} ne '') {
7411: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
7412: }
7413: }
7414: $resulttext .= '</li>';
1.28 raeburn 7415: }
7416: }
1.203 raeburn 7417: my @offon = ('off','on');
7418: if ($changes{'reporterrors'}) {
7419: $resulttext .= '<li>'.
7420: &mt('E-mail error reports to [_1] set to "'.
7421: $offon[$env{'form.reporterrors'}].'".',
7422: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
7423: &mt('LON-CAPA core group - MSU'),600,500)).
7424: '</li>';
7425: }
7426: if ($changes{'reportupdates'}) {
7427: $resulttext .= '<li>'.
7428: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
7429: $offon[$env{'form.reportupdates'}].'".',
7430: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
7431: &mt('LON-CAPA core group - MSU'),600,500)).
7432: '</li>';
7433: }
1.28 raeburn 7434: $resulttext .= '</ul>';
7435: } else {
1.34 raeburn 7436: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 7437: }
7438: } else {
7439: $resulttext = '<span class="LC_error">'.
7440: &mt('An error occurred: [_1].',$putresult).'</span>';
7441: }
7442: return $resulttext;
7443: }
7444:
7445: sub modify_usercreation {
1.27 raeburn 7446: my ($dom,%domconfig) = @_;
1.224 raeburn 7447: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 7448: my $warningmsg;
1.27 raeburn 7449: if (ref($domconfig{'usercreation'}) eq 'HASH') {
7450: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 7451: if ($key eq 'cancreate') {
7452: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
7453: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
7454: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
7455: ($item eq 'captcha') || ($item eq 'recaptchakeys')) {
7456: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
7457: } else {
7458: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
7459: }
7460: }
7461: }
7462: } elsif ($key eq 'email_rule') {
7463: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
7464: } else {
7465: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
7466: }
1.27 raeburn 7467: }
7468: }
7469: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 7470: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 7471: my @contexts = ('author','course','requestcrs');
1.34 raeburn 7472: foreach my $item(@contexts) {
1.224 raeburn 7473: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 7474: }
1.34 raeburn 7475: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
7476: foreach my $item (@contexts) {
1.224 raeburn 7477: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
7478: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 7479: }
1.27 raeburn 7480: }
1.34 raeburn 7481: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
7482: foreach my $item (@contexts) {
1.43 raeburn 7483: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 7484: if ($cancreate{$item} ne 'any') {
7485: push(@{$changes{'cancreate'}},$item);
7486: }
7487: } else {
7488: if ($cancreate{$item} ne 'none') {
7489: push(@{$changes{'cancreate'}},$item);
7490: }
1.27 raeburn 7491: }
7492: }
7493: } else {
1.43 raeburn 7494: foreach my $item (@contexts) {
1.34 raeburn 7495: push(@{$changes{'cancreate'}},$item);
7496: }
1.27 raeburn 7497: }
1.34 raeburn 7498:
1.27 raeburn 7499: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
7500: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
7501: if (!grep(/^\Q$type\E$/,@username_rule)) {
7502: push(@{$changes{'username_rule'}},$type);
7503: }
7504: }
7505: foreach my $type (@username_rule) {
7506: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
7507: push(@{$changes{'username_rule'}},$type);
7508: }
7509: }
7510: } else {
7511: push(@{$changes{'username_rule'}},@username_rule);
7512: }
7513:
1.32 raeburn 7514: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
7515: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
7516: if (!grep(/^\Q$type\E$/,@id_rule)) {
7517: push(@{$changes{'id_rule'}},$type);
7518: }
7519: }
7520: foreach my $type (@id_rule) {
7521: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
7522: push(@{$changes{'id_rule'}},$type);
7523: }
7524: }
7525: } else {
7526: push(@{$changes{'id_rule'}},@id_rule);
7527: }
7528:
1.43 raeburn 7529: my @authen_contexts = ('author','course','domain');
1.28 raeburn 7530: my @authtypes = ('int','krb4','krb5','loc');
7531: my %authhash;
1.43 raeburn 7532: foreach my $item (@authen_contexts) {
1.28 raeburn 7533: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
7534: foreach my $auth (@authtypes) {
7535: if (grep(/^\Q$auth\E$/,@authallowed)) {
7536: $authhash{$item}{$auth} = 1;
7537: } else {
7538: $authhash{$item}{$auth} = 0;
7539: }
7540: }
7541: }
7542: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 7543: foreach my $item (@authen_contexts) {
1.28 raeburn 7544: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
7545: foreach my $auth (@authtypes) {
7546: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
7547: push(@{$changes{'authtypes'}},$item);
7548: last;
7549: }
7550: }
7551: }
7552: }
7553: } else {
1.43 raeburn 7554: foreach my $item (@authen_contexts) {
1.28 raeburn 7555: push(@{$changes{'authtypes'}},$item);
7556: }
7557: }
7558:
1.224 raeburn 7559: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
7560: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
7561: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
7562: $save_usercreate{'id_rule'} = \@id_rule;
7563: $save_usercreate{'username_rule'} = \@username_rule,
7564: $save_usercreate{'authtypes'} = \%authhash;
7565:
1.27 raeburn 7566: my %usercreation_hash = (
1.224 raeburn 7567: usercreation => \%save_usercreate,
7568: );
1.27 raeburn 7569:
7570: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
7571: $dom);
1.50 raeburn 7572:
1.224 raeburn 7573: if ($putresult eq 'ok') {
7574: if (keys(%changes) > 0) {
7575: $resulttext = &mt('Changes made:').'<ul>';
7576: if (ref($changes{'cancreate'}) eq 'ARRAY') {
7577: my %lt = &usercreation_types();
7578: foreach my $type (@{$changes{'cancreate'}}) {
7579: my $chgtext = $lt{$type}.', ';
7580: if ($cancreate{$type} eq 'none') {
7581: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
7582: } elsif ($cancreate{$type} eq 'any') {
7583: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
7584: } elsif ($cancreate{$type} eq 'official') {
7585: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
7586: } elsif ($cancreate{$type} eq 'unofficial') {
7587: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
7588: }
7589: $resulttext .= '<li>'.$chgtext.'</li>';
7590: }
7591: }
7592: if (ref($changes{'username_rule'}) eq 'ARRAY') {
7593: my ($rules,$ruleorder) =
7594: &Apache::lonnet::inst_userrules($dom,'username');
7595: my $chgtext = '<ul>';
7596: foreach my $type (@username_rule) {
7597: if (ref($rules->{$type}) eq 'HASH') {
7598: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
7599: }
7600: }
7601: $chgtext .= '</ul>';
7602: if (@username_rule > 0) {
7603: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7604: } else {
7605: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
7606: }
7607: }
7608: if (ref($changes{'id_rule'}) eq 'ARRAY') {
7609: my ($idrules,$idruleorder) =
7610: &Apache::lonnet::inst_userrules($dom,'id');
7611: my $chgtext = '<ul>';
7612: foreach my $type (@id_rule) {
7613: if (ref($idrules->{$type}) eq 'HASH') {
7614: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
7615: }
7616: }
7617: $chgtext .= '</ul>';
7618: if (@id_rule > 0) {
7619: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7620: } else {
7621: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
7622: }
7623: }
7624: my %authname = &authtype_names();
7625: my %context_title = &context_names();
7626: if (ref($changes{'authtypes'}) eq 'ARRAY') {
7627: my $chgtext = '<ul>';
7628: foreach my $type (@{$changes{'authtypes'}}) {
7629: my @allowed;
7630: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
7631: foreach my $auth (@authtypes) {
7632: if ($authhash{$type}{$auth}) {
7633: push(@allowed,$authname{$auth});
7634: }
7635: }
7636: if (@allowed > 0) {
7637: $chgtext .= join(', ',@allowed).'</li>';
7638: } else {
7639: $chgtext .= &mt('none').'</li>';
7640: }
7641: }
7642: $chgtext .= '</ul>';
7643: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
7644: $resulttext .= '</li>';
7645: }
7646: $resulttext .= '</ul>';
7647: } else {
7648: $resulttext = &mt('No changes made to user creation settings');
7649: }
7650: } else {
7651: $resulttext = '<span class="LC_error">'.
7652: &mt('An error occurred: [_1]',$putresult).'</span>';
7653: }
7654: if ($warningmsg ne '') {
7655: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
7656: }
7657: return $resulttext;
7658: }
7659:
7660: sub modify_selfcreation {
7661: my ($dom,%domconfig) = @_;
7662: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
7663: my (%save_usercreate,%save_usermodify);
7664: #
7665: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
7666: #
7667: if (ref($domconfig{'usercreation'}) eq 'HASH') {
7668: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
7669: if ($key eq 'cancreate') {
7670: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
7671: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
7672: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
7673: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
7674: ($item eq 'emailusername') || ($item eq 'notify')) {
7675: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
7676: } else {
7677: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
7678: }
7679: }
7680: }
7681: } elsif ($key eq 'email_rule') {
7682: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
7683: } else {
7684: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
7685: }
7686: }
7687: }
7688: #
7689: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
7690: #
7691: if (ref($domconfig{'usermodification'}) eq 'HASH') {
7692: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
7693: if ($key eq 'selfcreate') {
7694: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
7695: } else {
7696: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
7697: }
7698: }
7699: }
7700:
7701: my @contexts = ('selfcreate');
7702: @{$cancreate{'selfcreate'}} = ();
7703: %{$cancreate{'emailusername'}} = ();
7704: @{$cancreate{'statustocreate'}} = ();
1.50 raeburn 7705: my %selfcreatetypes = (
7706: sso => 'users authenticated by institutional single sign on',
7707: login => 'users authenticated by institutional log-in',
1.224 raeburn 7708: email => 'users who provide a valid e-mail address for use as username (automatic creation)',
7709: emailapproval => 'users who provide a valid e-mail address for use as username (queued for Domain Coordinator review)',
1.50 raeburn 7710: );
1.224 raeburn 7711: #
7712: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
7713: # is permitted.
7714: #
7715: foreach my $item ('login','sso','email') {
7716: if ($item eq 'email') {
7717: if ($env{'form.cancreate_email'} eq 'email') {
7718: push(@{$cancreate{'selfcreate'}},'email');
7719: } elsif ($env{'form.cancreate_email'} eq 'emailapproval') {
7720: push(@{$cancreate{'selfcreate'}},'emailapproval');
7721: }
7722: } else {
7723: if ($env{'form.cancreate_'.$item}) {
7724: push(@{$cancreate{'selfcreate'}},$item);
7725: }
7726: }
7727: }
7728: my (@email_rule,%userinfo,%savecaptcha);
7729: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
7730: #
7731: # Populate $cancreate{'emailusername'} hash ref with information types (if new user will provide data
7732: # value set to one), if self-creation with e-mail address permitted.
7733: #
7734: if (($env{'form.cancreate_email'} eq 'email') || ($env{'form.cancreate_email'} eq 'emailapproval')) {
7735: push(@contexts,'emailusername');
7736: map { $userinfo{$_} = 1; } &Apache::loncommon::get_env_multiple('form.canmodify_emailusername');
7737: if (ref($infofields) eq 'ARRAY') {
7738: foreach my $field (@{$infofields}) {
7739: if ($userinfo{$field}) {
7740: $cancreate{'emailusername'}{$field} = 1;
7741: }
7742: }
7743: }
7744:
7745: #
7746: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
7747: # queued requests for self-creation of account using e-mail address as username
7748: #
7749:
7750: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
7751: @approvalnotify = sort(@approvalnotify);
7752: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
7753: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
7754: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
7755: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
7756: push(@{$changes{'cancreate'}},'notify');
7757: }
7758: } else {
7759: if ($cancreate{'notify'}{'approval'}) {
7760: push(@{$changes{'cancreate'}},'notify');
7761: }
7762: }
7763: } elsif ($cancreate{'notify'}{'approval'}) {
7764: push(@{$changes{'cancreate'}},'notify');
7765: }
7766:
7767: #
7768: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
7769: #
7770: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
7771: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
7772: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
7773: if (@{$curr_usercreation{'email_rule'}} > 0) {
7774: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
7775: if (!grep(/^\Q$type\E$/,@email_rule)) {
7776: push(@{$changes{'email_rule'}},$type);
7777: }
7778: }
7779: }
7780: if (@email_rule > 0) {
7781: foreach my $type (@email_rule) {
7782: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
7783: push(@{$changes{'email_rule'}},$type);
7784: }
7785: }
7786: }
7787: } elsif (@email_rule > 0) {
7788: push(@{$changes{'email_rule'}},@email_rule);
7789: }
7790: }
7791: #
7792: # Check if domain default is set appropriately, if selef-creation of accounts is to be available for
7793: # institutional log-in.
7794: #
7795: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
7796: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
7797: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
7798: ($domdefaults{'auth_def'} eq 'localauth'))) {
7799: $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.').' '.
7800: &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.');
7801: }
7802: }
7803: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7804: my @fields = ('lastname','firstname','middlename','generation',
7805: 'permanentemail','id');
7806: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7807: #
7808: # Where usernames may created for institutional log-in and/or institutional single sign on:
7809: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
7810: # may self-create accounts
7811: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
7812: # which the user may supply, if institutional data is unavailable.
7813: #
7814: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
7815: if (ref($types) eq 'ARRAY') {
7816: if (@{$types} > 0) {
7817: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
7818: push(@contexts,'statustocreate');
7819: } else {
7820: undef($cancreate{'statustocreate'});
7821: }
7822: push(@{$types},'default');
7823: $usertypes->{'default'} = $othertitle;
7824: foreach my $type (@{$types}) {
7825: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
7826: foreach my $field (@fields) {
7827: if (grep(/^\Q$field\E$/,@modifiable)) {
7828: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
7829: } else {
7830: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
7831: }
7832: }
7833: }
7834: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
7835: foreach my $type (@{$types}) {
7836: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
7837: foreach my $field (@fields) {
7838: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
7839: $curr_usermodify{'selfcreate'}{$type}{$field}) {
7840: push(@{$changes{'selfcreate'}},$type);
7841: last;
7842: }
7843: }
7844: }
7845: }
7846: } else {
7847: foreach my $type (@{$types}) {
7848: push(@{$changes{'selfcreate'}},$type);
7849: }
7850: }
7851: }
7852: }
7853: foreach my $item (@contexts) {
7854: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
7855: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
7856: if (ref($cancreate{$item}) eq 'ARRAY') {
7857: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
7858: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7859: push(@{$changes{'cancreate'}},$item);
7860: }
7861: }
7862: }
7863: }
7864: if (ref($cancreate{$item}) eq 'ARRAY') {
7865: foreach my $type (@{$cancreate{$item}}) {
7866: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
7867: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7868: push(@{$changes{'cancreate'}},$item);
7869: }
7870: }
7871: }
7872: }
7873: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
7874: if (ref($cancreate{$item}) eq 'HASH') {
7875: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
7876: if (!$cancreate{$item}{$curr}) {
7877: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7878: push(@{$changes{'cancreate'}},$item);
7879: }
7880: }
7881: }
7882: foreach my $field (keys(%{$cancreate{$item}})) {
7883: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
7884: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7885: push(@{$changes{'cancreate'}},$item);
7886: }
7887: }
7888: }
7889: }
7890: } elsif ($curr_usercreation{'cancreate'}{$item}) {
7891: if (ref($cancreate{$item}) eq 'ARRAY') {
7892: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
7893: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7894: push(@{$changes{'cancreate'}},$item);
7895: }
7896: }
7897: } elsif (ref($cancreate{$item}) eq 'HASH') {
7898: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
7899: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
7900: push(@{$changes{'cancreate'}},$item);
7901: }
7902: }
7903: }
7904: } elsif ($item eq 'emailusername') {
7905: if (keys(%userinfo) > 0) {
7906: push(@{$changes{'cancreate'}},$item);
7907: }
7908: }
7909: }
7910: #
7911: # Populate %save_usercreate hash with updates to self-creation configuration.
7912: #
7913: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
7914: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
7915: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
7916: if (ref($cancreate{'notify'}) eq 'HASH') {
7917: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
7918: }
7919: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
7920: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
7921: }
7922: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
7923: $save_usercreate{'emailrule'} = \@email_rule;
7924:
7925: my %userconfig_hash = (
7926: usercreation => \%save_usercreate,
7927: usermodification => \%save_usermodify,
7928: );
7929: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
7930: $dom);
7931: #
7932: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
7933: #
1.27 raeburn 7934: if ($putresult eq 'ok') {
7935: if (keys(%changes) > 0) {
7936: $resulttext = &mt('Changes made:').'<ul>';
7937: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 7938: my %lt = &selfcreation_types();
1.34 raeburn 7939: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 7940: my $chgtext;
1.45 raeburn 7941: if ($type eq 'selfcreate') {
1.50 raeburn 7942: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 7943: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 7944: } else {
1.224 raeburn 7945: $chgtext .= &mt('Self-creation of a new account is permitted for:').
7946: '<ul>';
1.50 raeburn 7947: foreach my $case (@{$cancreate{$type}}) {
7948: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
7949: }
7950: $chgtext .= '</ul>';
1.100 raeburn 7951: if (ref($cancreate{$type}) eq 'ARRAY') {
7952: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
7953: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
7954: if (@{$cancreate{'statustocreate'}} == 0) {
1.224 raeburn 7955: $chgtext .= '<br />'.
7956: '<span class="LC_warning">'.
7957: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
7958: '</span>';
1.100 raeburn 7959: }
7960: }
7961: }
7962: }
1.43 raeburn 7963: }
1.93 raeburn 7964: } elsif ($type eq 'statustocreate') {
1.96 raeburn 7965: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
7966: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
7967: if (@{$cancreate{'selfcreate'}} > 0) {
7968: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 7969: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 7970: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 7971: $chgtext .= '<br />'.
7972: '<span class="LC_warning">'.
7973: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
7974: '</span>';
7975: }
1.96 raeburn 7976: } elsif (ref($usertypes) eq 'HASH') {
7977: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 7978: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
7979: } else {
7980: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
7981: }
7982: $chgtext .= '<ul>';
7983: foreach my $case (@{$cancreate{$type}}) {
7984: if ($case eq 'default') {
7985: $chgtext .= '<li>'.$othertitle.'</li>';
7986: } else {
7987: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 7988: }
7989: }
1.100 raeburn 7990: $chgtext .= '</ul>';
7991: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 7992: $chgtext .= '<br /><span class="LC_warning">'.
7993: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
7994: '</span>';
1.100 raeburn 7995: }
7996: }
7997: } else {
7998: if (@{$cancreate{$type}} == 0) {
7999: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
8000: } else {
8001: $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 8002: }
8003: }
8004: }
1.165 raeburn 8005: } elsif ($type eq 'captcha') {
1.224 raeburn 8006: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 8007: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
8008: } else {
8009: my %captchas = &captcha_phrases();
1.224 raeburn 8010: if ($captchas{$savecaptcha{$type}}) {
8011: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 8012: } else {
1.210 raeburn 8013: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 8014: }
8015: }
8016: } elsif ($type eq 'recaptchakeys') {
8017: my ($privkey,$pubkey);
1.224 raeburn 8018: if (ref($savecaptcha{$type}) eq 'HASH') {
8019: $pubkey = $savecaptcha{$type}{'public'};
8020: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 8021: }
8022: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
8023: if (!$pubkey) {
8024: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
8025: } else {
8026: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
8027: }
8028: if (!$privkey) {
8029: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
8030: } else {
8031: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
8032: }
8033: $chgtext .= '</ul>';
1.224 raeburn 8034: } elsif ($type eq 'emailusername') {
8035: if (ref($cancreate{'emailusername'}) eq 'HASH') {
8036: if (keys(%{$cancreate{'emailusername'}}) > 0) {
8037: $chgtext .= &mt('When self-creating account with e-mail as username, user will provide the following information:').
8038: '<ul>';
8039: foreach my $field (@{$infofields}) {
8040: if ($cancreate{'emailusername'}{$field}) {
8041: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
8042: }
8043: }
8044: $chgtext .= '</ul>';
8045: } else {
8046: $chgtext .= &mt('When self creating account with e-mail as username, user will not provide any information besides e-mail address');
8047: }
8048: }
8049: } elsif ($type eq 'notify') {
8050: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
8051: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8052: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
8053: if ($cancreate{'notify'}{'approval'}) {
8054: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
8055: }
8056: }
1.43 raeburn 8057: }
1.34 raeburn 8058: }
1.224 raeburn 8059: if ($chgtext) {
8060: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 8061: }
8062: }
8063: }
1.43 raeburn 8064: if (ref($changes{'email_rule'}) eq 'ARRAY') {
8065: my ($emailrules,$emailruleorder) =
8066: &Apache::lonnet::inst_userrules($dom,'email');
8067: my $chgtext = '<ul>';
8068: foreach my $type (@email_rule) {
8069: if (ref($emailrules->{$type}) eq 'HASH') {
8070: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
8071: }
8072: }
8073: $chgtext .= '</ul>';
8074: if (@email_rule > 0) {
1.224 raeburn 8075: $resulttext .= '<li>'.
8076: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
8077: $chgtext.
8078: '</li>';
1.43 raeburn 8079: } else {
1.224 raeburn 8080: $resulttext .= '<li>'.
8081: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
8082: '</li>';
1.43 raeburn 8083: }
8084: }
1.224 raeburn 8085: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
8086: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
8087: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8088: foreach my $type (@{$changes{'selfcreate'}}) {
8089: my $typename = $type;
8090: if (ref($usertypes) eq 'HASH') {
8091: if ($usertypes->{$type} ne '') {
8092: $typename = $usertypes->{$type};
8093: }
8094: }
8095: my @modifiable;
8096: $resulttext .= '<li>'.
8097: &mt('Self-creation of account by users with status: [_1]',
8098: '<span class="LC_cusr_emph">'.$typename.'</span>').
8099: ' - '.&mt('modifiable fields (if institutional data blank): ');
8100: foreach my $field (@fields) {
8101: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
8102: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 8103: }
8104: }
1.224 raeburn 8105: if (@modifiable > 0) {
8106: $resulttext .= join(', ',@modifiable);
1.43 raeburn 8107: } else {
1.224 raeburn 8108: $resulttext .= &mt('none');
1.43 raeburn 8109: }
1.224 raeburn 8110: $resulttext .= '</li>';
1.28 raeburn 8111: }
1.224 raeburn 8112: $resulttext .= '</ul></li>';
1.28 raeburn 8113: }
1.27 raeburn 8114: $resulttext .= '</ul>';
8115: } else {
1.224 raeburn 8116: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 8117: }
8118: } else {
8119: $resulttext = '<span class="LC_error">'.
1.23 raeburn 8120: &mt('An error occurred: [_1]',$putresult).'</span>';
8121: }
1.43 raeburn 8122: if ($warningmsg ne '') {
8123: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
8124: }
1.23 raeburn 8125: return $resulttext;
8126: }
8127:
1.165 raeburn 8128: sub process_captcha {
8129: my ($container,$changes,$newsettings,$current) = @_;
8130: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
8131: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
8132: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
8133: $newsettings->{'captcha'} = 'original';
8134: }
8135: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 8136: if ($container eq 'cancreate') {
1.169 raeburn 8137: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
8138: push(@{$changes->{'cancreate'}},'captcha');
8139: } elsif (!defined($changes->{'cancreate'})) {
8140: $changes->{'cancreate'} = ['captcha'];
8141: }
8142: } else {
8143: $changes->{'captcha'} = 1;
1.165 raeburn 8144: }
8145: }
8146: my ($newpub,$newpriv,$currpub,$currpriv);
8147: if ($newsettings->{'captcha'} eq 'recaptcha') {
8148: $newpub = $env{'form.'.$container.'_recaptchapub'};
8149: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.169 raeburn 8150: $newpub =~ s/\W//g;
8151: $newpriv =~ s/\W//g;
8152: $newsettings->{'recaptchakeys'} = {
8153: public => $newpub,
8154: private => $newpriv,
8155: };
1.165 raeburn 8156: }
8157: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
8158: $currpub = $current->{'recaptchakeys'}{'public'};
8159: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 8160: unless ($newsettings->{'captcha'} eq 'recaptcha') {
8161: $newsettings->{'recaptchakeys'} = {
8162: public => '',
8163: private => '',
8164: }
8165: }
1.165 raeburn 8166: }
8167: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 8168: if ($container eq 'cancreate') {
8169: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
8170: push(@{$changes->{'cancreate'}},'recaptchakeys');
8171: } elsif (!defined($changes->{'cancreate'})) {
8172: $changes->{'cancreate'} = ['recaptchakeys'];
8173: }
8174: } else {
1.210 raeburn 8175: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 8176: }
8177: }
8178: return;
8179: }
8180:
1.33 raeburn 8181: sub modify_usermodification {
8182: my ($dom,%domconfig) = @_;
1.224 raeburn 8183: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 8184: if (ref($domconfig{'usermodification'}) eq 'HASH') {
8185: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 8186: if ($key eq 'selfcreate') {
8187: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
8188: } else {
8189: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
8190: }
1.33 raeburn 8191: }
8192: }
1.224 raeburn 8193: my @contexts = ('author','course');
1.33 raeburn 8194: my %context_title = (
8195: author => 'In author context',
8196: course => 'In course context',
8197: );
8198: my @fields = ('lastname','firstname','middlename','generation',
8199: 'permanentemail','id');
8200: my %roles = (
8201: author => ['ca','aa'],
8202: course => ['st','ep','ta','in','cr'],
8203: );
8204: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8205: foreach my $context (@contexts) {
8206: foreach my $role (@{$roles{$context}}) {
8207: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
8208: foreach my $item (@fields) {
8209: if (grep(/^\Q$item\E$/,@modifiable)) {
8210: $modifyhash{$context}{$role}{$item} = 1;
8211: } else {
8212: $modifyhash{$context}{$role}{$item} = 0;
8213: }
8214: }
8215: }
8216: if (ref($curr_usermodification{$context}) eq 'HASH') {
8217: foreach my $role (@{$roles{$context}}) {
8218: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
8219: foreach my $field (@fields) {
8220: if ($modifyhash{$context}{$role}{$field} ne
8221: $curr_usermodification{$context}{$role}{$field}) {
8222: push(@{$changes{$context}},$role);
8223: last;
8224: }
8225: }
8226: }
8227: }
8228: } else {
8229: foreach my $context (@contexts) {
8230: foreach my $role (@{$roles{$context}}) {
8231: push(@{$changes{$context}},$role);
8232: }
8233: }
8234: }
8235: }
1.224 raeburn 8236: # FIXME need to ensure selfcreate stuff is preserved
1.33 raeburn 8237: my %usermodification_hash = (
8238: usermodification => \%modifyhash,
8239: );
8240: my $putresult = &Apache::lonnet::put_dom('configuration',
8241: \%usermodification_hash,$dom);
8242: if ($putresult eq 'ok') {
8243: if (keys(%changes) > 0) {
8244: $resulttext = &mt('Changes made: ').'<ul>';
8245: foreach my $context (@contexts) {
8246: if (ref($changes{$context}) eq 'ARRAY') {
8247: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
8248: if (ref($changes{$context}) eq 'ARRAY') {
8249: foreach my $role (@{$changes{$context}}) {
8250: my $rolename;
1.224 raeburn 8251: if ($role eq 'cr') {
8252: $rolename = &mt('Custom');
1.33 raeburn 8253: } else {
1.224 raeburn 8254: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 8255: }
8256: my @modifiable;
1.224 raeburn 8257: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 8258: foreach my $field (@fields) {
8259: if ($modifyhash{$context}{$role}{$field}) {
8260: push(@modifiable,$fieldtitles{$field});
8261: }
8262: }
8263: if (@modifiable > 0) {
8264: $resulttext .= join(', ',@modifiable);
8265: } else {
8266: $resulttext .= &mt('none');
8267: }
8268: $resulttext .= '</li>';
8269: }
8270: $resulttext .= '</ul></li>';
8271: }
8272: }
8273: }
8274: $resulttext .= '</ul>';
8275: } else {
8276: $resulttext = &mt('No changes made to user modification settings');
8277: }
8278: } else {
8279: $resulttext = '<span class="LC_error">'.
8280: &mt('An error occurred: [_1]',$putresult).'</span>';
8281: }
8282: return $resulttext;
8283: }
8284:
1.43 raeburn 8285: sub modify_defaults {
1.212 raeburn 8286: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 8287: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 8288: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 8289: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 8290: my @authtypes = ('internal','krb4','krb5','localauth');
8291: foreach my $item (@items) {
8292: $newvalues{$item} = $env{'form.'.$item};
8293: if ($item eq 'auth_def') {
8294: if ($newvalues{$item} ne '') {
8295: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
8296: push(@errors,$item);
8297: }
8298: }
8299: } elsif ($item eq 'lang_def') {
8300: if ($newvalues{$item} ne '') {
8301: if ($newvalues{$item} =~ /^(\w+)/) {
8302: my $langcode = $1;
1.103 raeburn 8303: if ($langcode ne 'x_chef') {
8304: if (code2language($langcode) eq '') {
8305: push(@errors,$item);
8306: }
1.43 raeburn 8307: }
8308: } else {
8309: push(@errors,$item);
8310: }
8311: }
1.54 raeburn 8312: } elsif ($item eq 'timezone_def') {
8313: if ($newvalues{$item} ne '') {
1.62 raeburn 8314: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 8315: push(@errors,$item);
8316: }
8317: }
1.68 raeburn 8318: } elsif ($item eq 'datelocale_def') {
8319: if ($newvalues{$item} ne '') {
8320: my @datelocale_ids = DateTime::Locale->ids();
8321: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
8322: push(@errors,$item);
8323: }
8324: }
1.141 raeburn 8325: } elsif ($item eq 'portal_def') {
8326: if ($newvalues{$item} ne '') {
8327: 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])\/?$/) {
8328: push(@errors,$item);
8329: }
8330: }
1.43 raeburn 8331: }
8332: if (grep(/^\Q$item\E$/,@errors)) {
8333: $newvalues{$item} = $domdefaults{$item};
8334: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
8335: $changes{$item} = 1;
8336: }
1.72 raeburn 8337: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 8338: }
8339: my %defaults_hash = (
1.72 raeburn 8340: defaults => \%newvalues,
8341: );
1.43 raeburn 8342: my $title = &defaults_titles();
8343: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
8344: $dom);
8345: if ($putresult eq 'ok') {
8346: if (keys(%changes) > 0) {
8347: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 8348: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 8349: 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";
8350: foreach my $item (sort(keys(%changes))) {
8351: my $value = $env{'form.'.$item};
8352: if ($value eq '') {
8353: $value = &mt('none');
8354: } elsif ($item eq 'auth_def') {
8355: my %authnames = &authtype_names();
8356: my %shortauth = (
8357: internal => 'int',
8358: krb4 => 'krb4',
8359: krb5 => 'krb5',
8360: localauth => 'loc',
8361: );
8362: $value = $authnames{$shortauth{$value}};
8363: }
8364: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
8365: $mailmsgtext .= "$title->{$item} set to $value\n";
8366: }
8367: $resulttext .= '</ul>';
8368: $mailmsgtext .= "\n";
8369: my $cachetime = 24*60*60;
1.72 raeburn 8370: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 8371: if (ref($lastactref) eq 'HASH') {
8372: $lastactref->{'domdefaults'} = 1;
8373: }
1.68 raeburn 8374: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 8375: my $notify = 1;
8376: if (ref($domconfig{'contacts'}) eq 'HASH') {
8377: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
8378: $notify = 0;
8379: }
8380: }
8381: if ($notify) {
8382: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
8383: "LON-CAPA Domain Settings Change - $dom",
8384: $mailmsgtext);
8385: }
1.54 raeburn 8386: }
1.43 raeburn 8387: } else {
1.54 raeburn 8388: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 8389: }
8390: } else {
8391: $resulttext = '<span class="LC_error">'.
8392: &mt('An error occurred: [_1]',$putresult).'</span>';
8393: }
8394: if (@errors > 0) {
8395: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
8396: foreach my $item (@errors) {
8397: $resulttext .= ' "'.$title->{$item}.'",';
8398: }
8399: $resulttext =~ s/,$//;
8400: }
8401: return $resulttext;
8402: }
8403:
1.46 raeburn 8404: sub modify_scantron {
1.205 raeburn 8405: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 8406: my ($resulttext,%confhash,%changes,$errors);
8407: my $custom = 'custom.tab';
8408: my $default = 'default.tab';
8409: my $servadm = $r->dir_config('lonAdmEMail');
8410: my ($configuserok,$author_ok,$switchserver) =
8411: &config_check($dom,$confname,$servadm);
8412: if ($env{'form.scantronformat.filename'} ne '') {
8413: my $error;
8414: if ($configuserok eq 'ok') {
8415: if ($switchserver) {
1.130 raeburn 8416: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 8417: } else {
8418: if ($author_ok eq 'ok') {
8419: my ($result,$scantronurl) =
8420: &publishlogo($r,'upload','scantronformat',$dom,
8421: $confname,'scantron','','',$custom);
8422: if ($result eq 'ok') {
8423: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 8424: $changes{'scantronformat'} = 1;
1.46 raeburn 8425: } else {
8426: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
8427: }
8428: } else {
8429: $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);
8430: }
8431: }
8432: } else {
8433: $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);
8434: }
8435: if ($error) {
8436: &Apache::lonnet::logthis($error);
8437: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8438: }
8439: }
1.48 raeburn 8440: if (ref($domconfig{'scantron'}) eq 'HASH') {
8441: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
8442: if ($env{'form.scantronformat_del'}) {
8443: $confhash{'scantron'}{'scantronformat'} = '';
8444: $changes{'scantronformat'} = 1;
1.46 raeburn 8445: }
8446: }
8447: }
8448: if (keys(%confhash) > 0) {
8449: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
8450: $dom);
8451: if ($putresult eq 'ok') {
8452: if (keys(%changes) > 0) {
1.48 raeburn 8453: if (ref($confhash{'scantron'}) eq 'HASH') {
8454: $resulttext = &mt('Changes made:').'<ul>';
8455: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 8456: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 8457: } else {
1.130 raeburn 8458: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 8459: }
1.48 raeburn 8460: $resulttext .= '</ul>';
8461: } else {
1.130 raeburn 8462: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 8463: }
8464: $resulttext .= '</ul>';
8465: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 8466: if (ref($lastactref) eq 'HASH') {
8467: $lastactref->{'domainconfig'} = 1;
8468: }
1.46 raeburn 8469: } else {
1.130 raeburn 8470: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 8471: }
8472: } else {
8473: $resulttext = '<span class="LC_error">'.
8474: &mt('An error occurred: [_1]',$putresult).'</span>';
8475: }
8476: } else {
1.130 raeburn 8477: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 8478: }
8479: if ($errors) {
8480: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
8481: $errors.'</ul>';
8482: }
8483: return $resulttext;
8484: }
8485:
1.48 raeburn 8486: sub modify_coursecategories {
8487: my ($dom,%domconfig) = @_;
1.57 raeburn 8488: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
8489: $cathash);
1.48 raeburn 8490: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 8491: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 8492: $cathash = $domconfig{'coursecategories'}{'cats'};
8493: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
8494: $changes{'togglecats'} = 1;
8495: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
8496: }
8497: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
8498: $changes{'categorize'} = 1;
8499: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
8500: }
1.120 raeburn 8501: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
8502: $changes{'togglecatscomm'} = 1;
8503: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
8504: }
8505: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
8506: $changes{'categorizecomm'} = 1;
8507: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
8508: }
1.57 raeburn 8509: } else {
8510: $changes{'togglecats'} = 1;
8511: $changes{'categorize'} = 1;
1.124 raeburn 8512: $changes{'togglecatscomm'} = 1;
8513: $changes{'categorizecomm'} = 1;
1.87 raeburn 8514: $domconfig{'coursecategories'} = {
8515: togglecats => $env{'form.togglecats'},
8516: categorize => $env{'form.categorize'},
1.124 raeburn 8517: togglecatscomm => $env{'form.togglecatscomm'},
8518: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 8519: };
1.57 raeburn 8520: }
8521: if (ref($cathash) eq 'HASH') {
8522: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 8523: push (@deletecategory,'instcode::0');
8524: }
1.120 raeburn 8525: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
8526: push(@deletecategory,'communities::0');
8527: }
1.48 raeburn 8528: }
1.57 raeburn 8529: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
8530: if (ref($cathash) eq 'HASH') {
1.48 raeburn 8531: if (@deletecategory > 0) {
8532: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 8533: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 8534: foreach my $item (@deletecategory) {
1.57 raeburn 8535: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
8536: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 8537: $deletions{$item} = 1;
1.57 raeburn 8538: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 8539: }
8540: }
8541: }
1.57 raeburn 8542: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 8543: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 8544: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 8545: $reorderings{$item} = 1;
1.57 raeburn 8546: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 8547: }
8548: if ($env{'form.addcategory_name_'.$item} ne '') {
8549: my $newcat = $env{'form.addcategory_name_'.$item};
8550: my $newdepth = $depth+1;
8551: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 8552: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 8553: $adds{$newitem} = 1;
8554: }
8555: if ($env{'form.subcat_'.$item} ne '') {
8556: my $newcat = $env{'form.subcat_'.$item};
8557: my $newdepth = $depth+1;
8558: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 8559: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 8560: $adds{$newitem} = 1;
8561: }
8562: }
8563: }
8564: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 8565: if (ref($cathash) eq 'HASH') {
1.48 raeburn 8566: my $newitem = 'instcode::0';
1.57 raeburn 8567: if ($cathash->{$newitem} eq '') {
8568: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 8569: $adds{$newitem} = 1;
8570: }
8571: } else {
8572: my $newitem = 'instcode::0';
1.57 raeburn 8573: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 8574: $adds{$newitem} = 1;
8575: }
8576: }
1.120 raeburn 8577: if ($env{'form.communities'} eq '1') {
8578: if (ref($cathash) eq 'HASH') {
8579: my $newitem = 'communities::0';
8580: if ($cathash->{$newitem} eq '') {
8581: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
8582: $adds{$newitem} = 1;
8583: }
8584: } else {
8585: my $newitem = 'communities::0';
8586: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
8587: $adds{$newitem} = 1;
8588: }
8589: }
1.48 raeburn 8590: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 8591: if (($env{'form.addcategory_name'} ne 'instcode') &&
8592: ($env{'form.addcategory_name'} ne 'communities')) {
8593: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
8594: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
8595: $adds{$newitem} = 1;
8596: }
1.48 raeburn 8597: }
1.57 raeburn 8598: my $putresult;
1.48 raeburn 8599: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
8600: if (keys(%deletions) > 0) {
8601: foreach my $key (keys(%deletions)) {
8602: if ($predelallitems{$key} ne '') {
8603: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
8604: }
8605: }
8606: }
8607: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 8608: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 8609: if (ref($chkcats[0]) eq 'ARRAY') {
8610: my $depth = 0;
8611: my $chg = 0;
8612: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
8613: my $name = $chkcats[0][$i];
8614: my $item;
8615: if ($name eq '') {
8616: $chg ++;
8617: } else {
8618: $item = &escape($name).'::0';
8619: if ($chg) {
1.57 raeburn 8620: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 8621: }
8622: $depth ++;
1.57 raeburn 8623: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 8624: $depth --;
8625: }
8626: }
8627: }
1.57 raeburn 8628: }
8629: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
8630: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 8631: if ($putresult eq 'ok') {
1.57 raeburn 8632: my %title = (
1.120 raeburn 8633: togglecats => 'Show/Hide a course in catalog',
8634: categorize => 'Assign a category to a course',
8635: togglecatscomm => 'Show/Hide a community in catalog',
8636: categorizecomm => 'Assign a category to a community',
1.57 raeburn 8637: );
8638: my %level = (
1.120 raeburn 8639: dom => 'set in Domain ("Modify Course/Community")',
8640: crs => 'set in Course ("Course Configuration")',
8641: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 8642: );
1.48 raeburn 8643: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 8644: if ($changes{'togglecats'}) {
8645: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
8646: }
8647: if ($changes{'categorize'}) {
8648: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 8649: }
1.120 raeburn 8650: if ($changes{'togglecatscomm'}) {
8651: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
8652: }
8653: if ($changes{'categorizecomm'}) {
8654: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
8655: }
1.57 raeburn 8656: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
8657: my $cathash;
8658: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
8659: $cathash = $domconfig{'coursecategories'}{'cats'};
8660: } else {
8661: $cathash = {};
8662: }
8663: my (@cats,@trails,%allitems);
8664: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
8665: if (keys(%deletions) > 0) {
8666: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
8667: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
8668: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
8669: }
8670: $resulttext .= '</ul></li>';
8671: }
8672: if (keys(%reorderings) > 0) {
8673: my %sort_by_trail;
8674: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
8675: foreach my $key (keys(%reorderings)) {
8676: if ($allitems{$key} ne '') {
8677: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
8678: }
1.48 raeburn 8679: }
1.57 raeburn 8680: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
8681: $resulttext .= '<li>'.$trails[$trail].'</li>';
8682: }
8683: $resulttext .= '</ul></li>';
1.48 raeburn 8684: }
1.57 raeburn 8685: if (keys(%adds) > 0) {
8686: my %sort_by_trail;
8687: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
8688: foreach my $key (keys(%adds)) {
8689: if ($allitems{$key} ne '') {
8690: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
8691: }
8692: }
8693: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
8694: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 8695: }
1.57 raeburn 8696: $resulttext .= '</ul></li>';
1.48 raeburn 8697: }
8698: }
8699: $resulttext .= '</ul>';
8700: } else {
8701: $resulttext = '<span class="LC_error">'.
1.57 raeburn 8702: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 8703: }
8704: } else {
1.120 raeburn 8705: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 8706: }
8707: return $resulttext;
8708: }
8709:
1.69 raeburn 8710: sub modify_serverstatuses {
8711: my ($dom,%domconfig) = @_;
8712: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
8713: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
8714: %currserverstatus = %{$domconfig{'serverstatuses'}};
8715: }
8716: my @pages = &serverstatus_pages();
8717: foreach my $type (@pages) {
8718: $newserverstatus{$type}{'namedusers'} = '';
8719: $newserverstatus{$type}{'machines'} = '';
8720: if (defined($env{'form.'.$type.'_namedusers'})) {
8721: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
8722: my @okusers;
8723: foreach my $user (@users) {
8724: my ($uname,$udom) = split(/:/,$user);
8725: if (($udom =~ /^$match_domain$/) &&
8726: (&Apache::lonnet::domain($udom)) &&
8727: ($uname =~ /^$match_username$/)) {
8728: if (!grep(/^\Q$user\E/,@okusers)) {
8729: push(@okusers,$user);
8730: }
8731: }
8732: }
8733: if (@okusers > 0) {
8734: @okusers = sort(@okusers);
8735: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
8736: }
8737: }
8738: if (defined($env{'form.'.$type.'_machines'})) {
8739: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
8740: my @okmachines;
8741: foreach my $ip (@machines) {
8742: my @parts = split(/\./,$ip);
8743: next if (@parts < 4);
8744: my $badip = 0;
8745: for (my $i=0; $i<4; $i++) {
8746: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
8747: $badip = 1;
8748: last;
8749: }
8750: }
8751: if (!$badip) {
8752: push(@okmachines,$ip);
8753: }
8754: }
8755: @okmachines = sort(@okmachines);
8756: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
8757: }
8758: }
8759: my %serverstatushash = (
8760: serverstatuses => \%newserverstatus,
8761: );
8762: foreach my $type (@pages) {
1.83 raeburn 8763: foreach my $setting ('namedusers','machines') {
1.84 raeburn 8764: my (@current,@new);
1.83 raeburn 8765: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 8766: if ($currserverstatus{$type}{$setting} ne '') {
8767: @current = split(/,/,$currserverstatus{$type}{$setting});
8768: }
8769: }
8770: if ($newserverstatus{$type}{$setting} ne '') {
8771: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 8772: }
8773: if (@current > 0) {
8774: if (@new > 0) {
8775: foreach my $item (@current) {
8776: if (!grep(/^\Q$item\E$/,@new)) {
8777: $changes{$type}{$setting} = 1;
1.82 raeburn 8778: last;
8779: }
8780: }
1.84 raeburn 8781: foreach my $item (@new) {
8782: if (!grep(/^\Q$item\E$/,@current)) {
8783: $changes{$type}{$setting} = 1;
8784: last;
1.82 raeburn 8785: }
8786: }
8787: } else {
1.83 raeburn 8788: $changes{$type}{$setting} = 1;
1.69 raeburn 8789: }
1.83 raeburn 8790: } elsif (@new > 0) {
8791: $changes{$type}{$setting} = 1;
1.69 raeburn 8792: }
8793: }
8794: }
8795: if (keys(%changes) > 0) {
1.81 raeburn 8796: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 8797: my $putresult = &Apache::lonnet::put_dom('configuration',
8798: \%serverstatushash,$dom);
8799: if ($putresult eq 'ok') {
8800: $resulttext .= &mt('Changes made:').'<ul>';
8801: foreach my $type (@pages) {
1.84 raeburn 8802: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 8803: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 8804: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 8805: if ($newserverstatus{$type}{'namedusers'} eq '') {
8806: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
8807: } else {
8808: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
8809: }
1.84 raeburn 8810: }
8811: if ($changes{$type}{'machines'}) {
1.69 raeburn 8812: if ($newserverstatus{$type}{'machines'} eq '') {
8813: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
8814: } else {
8815: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
8816: }
8817:
8818: }
8819: $resulttext .= '</ul></li>';
8820: }
8821: }
8822: $resulttext .= '</ul>';
8823: } else {
8824: $resulttext = '<span class="LC_error">'.
8825: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
8826:
8827: }
8828: } else {
8829: $resulttext = &mt('No changes made to access to server status pages');
8830: }
8831: return $resulttext;
8832: }
8833:
1.118 jms 8834: sub modify_helpsettings {
1.122 jms 8835: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 8836: my ($resulttext,$errors,%changes,%helphash);
8837: my %defaultchecked = ('submitbugs' => 'on');
8838: my @offon = ('off','on');
1.118 jms 8839: my @toggles = ('submitbugs');
8840: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8841: foreach my $item (@toggles) {
1.166 raeburn 8842: if ($defaultchecked{$item} eq 'on') {
8843: if ($domconfig{'helpsettings'}{$item} eq '') {
8844: if ($env{'form.'.$item} eq '0') {
8845: $changes{$item} = 1;
8846: }
8847: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
8848: $changes{$item} = 1;
8849: }
8850: } elsif ($defaultchecked{$item} eq 'off') {
8851: if ($domconfig{'helpsettings'}{$item} eq '') {
8852: if ($env{'form.'.$item} eq '1') {
8853: $changes{$item} = 1;
8854: }
8855: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
8856: $changes{$item} = 1;
8857: }
8858: }
1.210 raeburn 8859: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
1.166 raeburn 8860: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
8861: }
8862: }
1.118 jms 8863: }
1.123 jms 8864: my $putresult;
8865: if (keys(%changes) > 0) {
1.166 raeburn 8866: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 8867: if ($putresult eq 'ok') {
1.166 raeburn 8868: $resulttext = &mt('Changes made:').'<ul>';
8869: foreach my $item (sort(keys(%changes))) {
8870: if ($item eq 'submitbugs') {
8871: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
8872: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
8873: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
8874: }
8875: }
8876: $resulttext .= '</ul>';
8877: } else {
8878: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 8879: $errors .= '<li><span class="LC_error">'.
8880: &mt('An error occurred storing the settings: [_1]',
8881: $putresult).'</span></li>';
1.166 raeburn 8882: }
1.118 jms 8883: }
8884: if ($errors) {
1.168 raeburn 8885: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 8886: $errors.'</ul>';
8887: }
8888: return $resulttext;
8889: }
8890:
1.121 raeburn 8891: sub modify_coursedefaults {
1.212 raeburn 8892: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 8893: my ($resulttext,$errors,%changes,%defaultshash);
8894: my %defaultchecked = ('canuse_pdfforms' => 'off');
8895: my @toggles = ('canuse_pdfforms');
1.198 raeburn 8896: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.216 raeburn 8897: 'uploadquota_community','uploadquota_textbook');
8898: my @types = ('official','unofficial','community','textbook');
1.198 raeburn 8899: my %staticdefaults = (
8900: anonsurvey_threshold => 10,
8901: uploadquota => 500,
8902: );
1.121 raeburn 8903:
8904: $defaultshash{'coursedefaults'} = {};
8905:
8906: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
8907: if ($domconfig{'coursedefaults'} eq '') {
8908: $domconfig{'coursedefaults'} = {};
8909: }
8910: }
8911:
8912: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
8913: foreach my $item (@toggles) {
8914: if ($defaultchecked{$item} eq 'on') {
8915: if (($domconfig{'coursedefaults'}{$item} eq '') &&
8916: ($env{'form.'.$item} eq '0')) {
8917: $changes{$item} = 1;
1.192 raeburn 8918: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 8919: $changes{$item} = 1;
8920: }
8921: } elsif ($defaultchecked{$item} eq 'off') {
8922: if (($domconfig{'coursedefaults'}{$item} eq '') &&
8923: ($env{'form.'.$item} eq '1')) {
8924: $changes{$item} = 1;
8925: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
8926: $changes{$item} = 1;
8927: }
8928: }
8929: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
8930: }
1.198 raeburn 8931: foreach my $item (@numbers) {
8932: my ($currdef,$newdef);
1.208 raeburn 8933: $newdef = $env{'form.'.$item};
1.198 raeburn 8934: if ($item eq 'anonsurvey_threshold') {
8935: $currdef = $domconfig{'coursedefaults'}{$item};
8936: $newdef =~ s/\D//g;
8937: if ($newdef eq '' || $newdef < 1) {
8938: $newdef = 1;
8939: }
8940: $defaultshash{'coursedefaults'}{$item} = $newdef;
8941: } else {
8942: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
8943: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8944: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
8945: }
8946: $newdef =~ s/[^\w.\-]//g;
8947: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
8948: }
8949: if ($currdef ne $newdef) {
8950: my $staticdef;
8951: if ($item eq 'anonsurvey_threshold') {
8952: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
8953: $changes{$item} = 1;
8954: }
8955: } else {
8956: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
8957: $changes{'uploadquota'} = 1;
8958: }
8959: }
1.139 raeburn 8960: }
8961: }
1.192 raeburn 8962: my $officialcreds = $env{'form.official_credits'};
1.216 raeburn 8963: $officialcreds =~ s/[^\d.]+//g;
1.192 raeburn 8964: my $unofficialcreds = $env{'form.unofficial_credits'};
1.216 raeburn 8965: $unofficialcreds =~ s/[^\d.]+//g;
8966: my $textbookcreds = $env{'form.textbook_credits'};
8967: $textbookcreds =~ s/[^\d.]+//g;
1.192 raeburn 8968: if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
8969: ($env{'form.coursecredits'} eq '1')) {
8970: $changes{'coursecredits'} = 1;
8971: } else {
8972: if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
1.216 raeburn 8973: ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds) ||
8974: ($domconfig{'coursedefaults'}{'coursecredits'}{'textbook'} ne $textbookcreds)) {
1.192 raeburn 8975: $changes{'coursecredits'} = 1;
8976: }
8977: }
8978: $defaultshash{'coursedefaults'}{'coursecredits'} = {
8979: official => $officialcreds,
8980: unofficial => $unofficialcreds,
1.216 raeburn 8981: textbook => $textbookcreds,
1.192 raeburn 8982: }
1.121 raeburn 8983: }
8984: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8985: $dom);
8986: if ($putresult eq 'ok') {
8987: if (keys(%changes) > 0) {
1.213 raeburn 8988: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.198 raeburn 8989: if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) || ($changes{'uploadquota'})) {
1.192 raeburn 8990: if ($changes{'canuse_pdfforms'}) {
8991: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
8992: }
8993: if ($changes{'coursecredits'}) {
8994: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
8995: $domdefaults{'officialcredits'} =
8996: $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
8997: $domdefaults{'unofficialcredits'} =
8998: $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
1.216 raeburn 8999: $domdefaults{'textbookcredits'} =
9000: $domdefaults{'coursedefaults'}{'coursecredits'}{'textbook'};
1.192 raeburn 9001: }
9002: }
1.198 raeburn 9003: if ($changes{'uploadquota'}) {
9004: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
9005: foreach my $type (@types) {
9006: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
9007: }
9008: }
9009: }
1.121 raeburn 9010: my $cachetime = 24*60*60;
9011: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 9012: if (ref($lastactref) eq 'HASH') {
9013: $lastactref->{'domdefaults'} = 1;
9014: }
1.121 raeburn 9015: }
9016: $resulttext = &mt('Changes made:').'<ul>';
9017: foreach my $item (sort(keys(%changes))) {
9018: if ($item eq 'canuse_pdfforms') {
9019: if ($env{'form.'.$item} eq '1') {
9020: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
9021: } else {
9022: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
9023: }
1.139 raeburn 9024: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 9025: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 9026: } elsif ($item eq 'uploadquota') {
9027: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
9028: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
9029: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
9030: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 9031: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
9032:
1.198 raeburn 9033: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
9034: '</ul>'.
9035: '</li>';
9036: } else {
9037: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
9038: }
1.192 raeburn 9039: } elsif ($item eq 'coursecredits') {
9040: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
9041: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 9042: ($domdefaults{'unofficialcredits'} eq '') &&
9043: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 9044: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
9045: } else {
9046: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
9047: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
9048: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 9049: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 9050: '</ul>'.
9051: '</li>';
9052: }
9053: } else {
9054: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
9055: }
1.140 raeburn 9056: }
1.121 raeburn 9057: }
9058: $resulttext .= '</ul>';
9059: } else {
9060: $resulttext = &mt('No changes made to course defaults');
9061: }
9062: } else {
9063: $resulttext = '<span class="LC_error">'.
9064: &mt('An error occurred: [_1]',$putresult).'</span>';
9065: }
9066: return $resulttext;
9067: }
9068:
1.137 raeburn 9069: sub modify_usersessions {
1.212 raeburn 9070: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 9071: my @hostingtypes = ('version','excludedomain','includedomain');
9072: my @offloadtypes = ('primary','default');
9073: my %types = (
9074: remote => \@hostingtypes,
9075: hosted => \@hostingtypes,
9076: spares => \@offloadtypes,
9077: );
9078: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 9079: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 9080: my (%by_ip,%by_location,@intdoms);
9081: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
9082: my @locations = sort(keys(%by_location));
1.137 raeburn 9083: my (%defaultshash,%changes);
9084: foreach my $prefix (@prefixes) {
9085: $defaultshash{'usersessions'}{$prefix} = {};
9086: }
1.212 raeburn 9087: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 9088: my $resulttext;
1.138 raeburn 9089: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 9090: foreach my $prefix (@prefixes) {
1.145 raeburn 9091: next if ($prefix eq 'spares');
9092: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 9093: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
9094: if ($type eq 'version') {
9095: my $value = $env{'form.'.$prefix.'_'.$type};
9096: my $okvalue;
9097: if ($value ne '') {
9098: if (grep(/^\Q$value\E$/,@lcversions)) {
9099: $okvalue = $value;
9100: }
9101: }
9102: if (ref($domconfig{'usersessions'}) eq 'HASH') {
9103: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
9104: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
9105: if ($inuse == 0) {
9106: $changes{$prefix}{$type} = 1;
9107: } else {
9108: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
9109: $changes{$prefix}{$type} = 1;
9110: }
9111: if ($okvalue ne '') {
9112: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
9113: }
9114: }
9115: } else {
9116: if (($inuse == 1) && ($okvalue ne '')) {
9117: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
9118: $changes{$prefix}{$type} = 1;
9119: }
9120: }
9121: } else {
9122: if (($inuse == 1) && ($okvalue ne '')) {
9123: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
9124: $changes{$prefix}{$type} = 1;
9125: }
9126: }
9127: } else {
9128: if (($inuse == 1) && ($okvalue ne '')) {
9129: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
9130: $changes{$prefix}{$type} = 1;
9131: }
9132: }
9133: } else {
9134: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
9135: my @okvals;
9136: foreach my $val (@vals) {
1.138 raeburn 9137: if ($val =~ /:/) {
9138: my @items = split(/:/,$val);
9139: foreach my $item (@items) {
9140: if (ref($by_location{$item}) eq 'ARRAY') {
9141: push(@okvals,$item);
9142: }
9143: }
9144: } else {
9145: if (ref($by_location{$val}) eq 'ARRAY') {
9146: push(@okvals,$val);
9147: }
1.137 raeburn 9148: }
9149: }
9150: @okvals = sort(@okvals);
9151: if (ref($domconfig{'usersessions'}) eq 'HASH') {
9152: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
9153: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
9154: if ($inuse == 0) {
9155: $changes{$prefix}{$type} = 1;
9156: } else {
9157: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
9158: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
9159: if (@changed > 0) {
9160: $changes{$prefix}{$type} = 1;
9161: }
9162: }
9163: } else {
9164: if ($inuse == 1) {
9165: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
9166: $changes{$prefix}{$type} = 1;
9167: }
9168: }
9169: } else {
9170: if ($inuse == 1) {
9171: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
9172: $changes{$prefix}{$type} = 1;
9173: }
9174: }
9175: } else {
9176: if ($inuse == 1) {
9177: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
9178: $changes{$prefix}{$type} = 1;
9179: }
9180: }
9181: }
9182: }
9183: }
1.145 raeburn 9184:
9185: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 9186: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 9187: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
9188: my $savespares;
9189:
9190: foreach my $lonhost (sort(keys(%servers))) {
9191: my $serverhomeID =
9192: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 9193: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 9194: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
9195: my %spareschg;
9196: foreach my $type (@{$types{'spares'}}) {
9197: my @okspares;
9198: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
9199: foreach my $server (@checked) {
1.152 raeburn 9200: if (&Apache::lonnet::hostname($server) ne '') {
9201: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
9202: unless (grep(/^\Q$server\E$/,@okspares)) {
9203: push(@okspares,$server);
9204: }
1.145 raeburn 9205: }
9206: }
9207: }
9208: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
9209: my $newspare;
1.152 raeburn 9210: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
9211: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 9212: $newspare = $new;
9213: }
9214: }
1.152 raeburn 9215: my @spares;
9216: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
9217: @spares = sort(@okspares,$newspare);
9218: } else {
9219: @spares = sort(@okspares);
9220: }
9221: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 9222: if (ref($spareid{$lonhost}) eq 'HASH') {
9223: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 9224: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 9225: if (@diffs > 0) {
9226: $spareschg{$type} = 1;
9227: }
9228: }
9229: }
9230: }
9231: if (keys(%spareschg) > 0) {
9232: $changes{'spares'}{$lonhost} = \%spareschg;
9233: }
9234: }
9235:
9236: if (ref($domconfig{'usersessions'}) eq 'HASH') {
9237: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
9238: if (ref($changes{'spares'}) eq 'HASH') {
9239: if (keys(%{$changes{'spares'}}) > 0) {
9240: $savespares = 1;
9241: }
9242: }
9243: } else {
9244: $savespares = 1;
9245: }
9246: }
9247:
1.147 raeburn 9248: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
9249: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 9250: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
9251: $dom);
9252: if ($putresult eq 'ok') {
9253: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
9254: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
9255: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
9256: }
9257: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
9258: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
9259: }
9260: }
9261: my $cachetime = 24*60*60;
9262: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 9263: if (ref($lastactref) eq 'HASH') {
9264: $lastactref->{'domdefaults'} = 1;
9265: }
1.147 raeburn 9266: if (keys(%changes) > 0) {
9267: my %lt = &usersession_titles();
9268: $resulttext = &mt('Changes made:').'<ul>';
9269: foreach my $prefix (@prefixes) {
9270: if (ref($changes{$prefix}) eq 'HASH') {
9271: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
9272: if ($prefix eq 'spares') {
9273: if (ref($changes{$prefix}) eq 'HASH') {
9274: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
9275: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 9276: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 9277: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
9278: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 9279: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
9280: foreach my $type (@{$types{$prefix}}) {
9281: if ($changes{$prefix}{$lonhost}{$type}) {
9282: my $offloadto = &mt('None');
9283: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
9284: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
9285: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
9286: }
1.145 raeburn 9287: }
1.147 raeburn 9288: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 9289: }
1.137 raeburn 9290: }
9291: }
1.147 raeburn 9292: $resulttext .= '</li>';
1.137 raeburn 9293: }
9294: }
1.147 raeburn 9295: } else {
9296: foreach my $type (@{$types{$prefix}}) {
9297: if (defined($changes{$prefix}{$type})) {
9298: my $newvalue;
9299: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
9300: if (ref($defaultshash{'usersessions'}{$prefix})) {
9301: if ($type eq 'version') {
9302: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
9303: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
9304: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
9305: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
9306: }
1.145 raeburn 9307: }
9308: }
9309: }
1.147 raeburn 9310: if ($newvalue eq '') {
9311: if ($type eq 'version') {
9312: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
9313: } else {
9314: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
9315: }
1.145 raeburn 9316: } else {
1.147 raeburn 9317: if ($type eq 'version') {
9318: $newvalue .= ' '.&mt('(or later)');
9319: }
9320: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 9321: }
1.137 raeburn 9322: }
9323: }
9324: }
1.147 raeburn 9325: $resulttext .= '</ul>';
1.137 raeburn 9326: }
9327: }
1.147 raeburn 9328: $resulttext .= '</ul>';
9329: } else {
9330: $resulttext = $nochgmsg;
1.137 raeburn 9331: }
9332: } else {
9333: $resulttext = '<span class="LC_error">'.
9334: &mt('An error occurred: [_1]',$putresult).'</span>';
9335: }
9336: } else {
1.147 raeburn 9337: $resulttext = $nochgmsg;
1.137 raeburn 9338: }
9339: return $resulttext;
9340: }
9341:
1.150 raeburn 9342: sub modify_loadbalancing {
9343: my ($dom,%domconfig) = @_;
9344: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9345: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9346: my ($othertitle,$usertypes,$types) =
9347: &Apache::loncommon::sorted_inst_types($dom);
9348: my %servers = &Apache::lonnet::internet_dom_servers($dom);
9349: my @sparestypes = ('primary','default');
9350: my %typetitles = &sparestype_titles();
9351: my $resulttext;
1.171 raeburn 9352: my (%currbalancer,%currtargets,%currrules,%existing);
9353: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
9354: %existing = %{$domconfig{'loadbalancing'}};
9355: }
9356: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
9357: \%currtargets,\%currrules);
9358: my ($saveloadbalancing,%defaultshash,%changes);
9359: my ($alltypes,$othertypes,$titles) =
9360: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
9361: my %ruletitles = &offloadtype_text();
9362: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
9363: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
9364: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
9365: if ($balancer eq '') {
9366: next;
9367: }
1.210 raeburn 9368: if (!exists($servers{$balancer})) {
1.171 raeburn 9369: if (exists($currbalancer{$balancer})) {
9370: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 9371: }
1.171 raeburn 9372: next;
9373: }
9374: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
9375: push(@{$changes{'delete'}},$balancer);
9376: next;
9377: }
9378: if (!exists($currbalancer{$balancer})) {
9379: push(@{$changes{'add'}},$balancer);
9380: }
9381: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
9382: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
9383: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
9384: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
9385: $saveloadbalancing = 1;
9386: }
9387: foreach my $sparetype (@sparestypes) {
9388: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
9389: my @offloadto;
9390: foreach my $target (@targets) {
9391: if (($servers{$target}) && ($target ne $balancer)) {
9392: if ($sparetype eq 'default') {
9393: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
9394: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 9395: }
9396: }
1.171 raeburn 9397: unless(grep(/^\Q$target\E$/,@offloadto)) {
9398: push(@offloadto,$target);
9399: }
1.150 raeburn 9400: }
1.171 raeburn 9401: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 9402: }
9403: }
1.171 raeburn 9404: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 9405: foreach my $sparetype (@sparestypes) {
1.171 raeburn 9406: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
9407: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 9408: if (@targetdiffs > 0) {
1.171 raeburn 9409: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 9410: }
1.171 raeburn 9411: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
9412: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
9413: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 9414: }
9415: }
9416: }
9417: } else {
1.171 raeburn 9418: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 9419: foreach my $sparetype (@sparestypes) {
1.171 raeburn 9420: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
9421: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
9422: $changes{'curr'}{$balancer}{'targets'} = 1;
9423: }
1.150 raeburn 9424: }
9425: }
1.210 raeburn 9426: }
1.150 raeburn 9427: }
9428: my $ishomedom;
1.171 raeburn 9429: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
9430: $ishomedom = 1;
1.150 raeburn 9431: }
9432: if (ref($alltypes) eq 'ARRAY') {
9433: foreach my $type (@{$alltypes}) {
9434: my $rule;
1.210 raeburn 9435: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 9436: (!$ishomedom)) {
1.171 raeburn 9437: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
9438: }
9439: if ($rule eq 'specific') {
9440: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 9441: }
1.171 raeburn 9442: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
9443: if (ref($currrules{$balancer}) eq 'HASH') {
9444: if ($rule ne $currrules{$balancer}{$type}) {
9445: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 9446: }
9447: } elsif ($rule ne '') {
1.171 raeburn 9448: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 9449: }
9450: }
9451: }
1.171 raeburn 9452: }
9453: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
9454: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
9455: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
9456: $defaultshash{'loadbalancing'} = {};
9457: }
9458: my $putresult = &Apache::lonnet::put_dom('configuration',
9459: \%defaultshash,$dom);
9460: if ($putresult eq 'ok') {
9461: if (keys(%changes) > 0) {
9462: if (ref($changes{'delete'}) eq 'ARRAY') {
9463: foreach my $balancer (sort(@{$changes{'delete'}})) {
9464: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.211 raeburn 9465: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
9466: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 9467: }
1.171 raeburn 9468: }
9469: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 9470: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 9471: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
9472: }
9473: }
9474: if (ref($changes{'curr'}) eq 'HASH') {
9475: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
9476: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
9477: if ($changes{'curr'}{$balancer}{'targets'}) {
9478: my %offloadstr;
9479: foreach my $sparetype (@sparestypes) {
9480: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
9481: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
9482: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
9483: }
9484: }
1.150 raeburn 9485: }
1.171 raeburn 9486: if (keys(%offloadstr) == 0) {
9487: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 9488: } else {
1.171 raeburn 9489: my $showoffload;
9490: foreach my $sparetype (@sparestypes) {
9491: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
9492: if (defined($offloadstr{$sparetype})) {
9493: $showoffload .= $offloadstr{$sparetype};
9494: } else {
9495: $showoffload .= &mt('None');
9496: }
9497: $showoffload .= (' 'x3);
9498: }
9499: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 9500: }
9501: }
9502: }
1.171 raeburn 9503: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
9504: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
9505: foreach my $type (@{$alltypes}) {
9506: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
9507: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
9508: my $balancetext;
9509: if ($rule eq '') {
9510: $balancetext = $ruletitles{'default'};
1.209 raeburn 9511: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
9512: ($rule eq 'balancer') || ($rule eq 'offloadedto')) {
1.171 raeburn 9513: $balancetext = $ruletitles{$rule};
9514: } else {
9515: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
9516: }
1.210 raeburn 9517: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 9518: }
9519: }
9520: }
9521: }
1.215 raeburn 9522: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
1.211 raeburn 9523: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 9524: }
1.171 raeburn 9525: }
9526: if ($resulttext ne '') {
9527: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 9528: } else {
9529: $resulttext = $nochgmsg;
9530: }
9531: } else {
1.171 raeburn 9532: $resulttext = $nochgmsg;
1.150 raeburn 9533: }
9534: } else {
1.171 raeburn 9535: $resulttext = '<span class="LC_error">'.
9536: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 9537: }
9538: } else {
1.171 raeburn 9539: $resulttext = $nochgmsg;
1.150 raeburn 9540: }
9541: return $resulttext;
9542: }
9543:
1.48 raeburn 9544: sub recurse_check {
9545: my ($chkcats,$categories,$depth,$name) = @_;
9546: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
9547: my $chg = 0;
9548: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
9549: my $category = $chkcats->[$depth]{$name}[$j];
9550: my $item;
9551: if ($category eq '') {
9552: $chg ++;
9553: } else {
9554: my $deeper = $depth + 1;
9555: $item = &escape($category).':'.&escape($name).':'.$depth;
9556: if ($chg) {
9557: $categories->{$item} -= $chg;
9558: }
9559: &recurse_check($chkcats,$categories,$deeper,$category);
9560: $deeper --;
9561: }
9562: }
9563: }
9564: return;
9565: }
9566:
9567: sub recurse_cat_deletes {
9568: my ($item,$coursecategories,$deletions) = @_;
9569: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9570: my $subdepth = $depth + 1;
9571: if (ref($coursecategories) eq 'HASH') {
9572: foreach my $subitem (keys(%{$coursecategories})) {
9573: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
9574: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
9575: delete($coursecategories->{$subitem});
9576: $deletions->{$subitem} = 1;
9577: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 9578: }
1.48 raeburn 9579: }
9580: }
9581: return;
9582: }
9583:
1.125 raeburn 9584: sub get_active_dcs {
9585: my ($dom) = @_;
1.191 raeburn 9586: my $now = time;
9587: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 9588: my %domcoords;
9589: my $numdcs = 0;
9590: foreach my $server (keys(%dompersonnel)) {
9591: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
9592: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.191 raeburn 9593: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 9594: }
9595: }
9596: return %domcoords;
9597: }
9598:
9599: sub active_dc_picker {
1.191 raeburn 9600: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.125 raeburn 9601: my %domcoords = &get_active_dcs($dom);
1.191 raeburn 9602: my @domcoord = keys(%domcoords);
9603: if (keys(%currhash)) {
9604: foreach my $dc (keys(%currhash)) {
9605: unless (exists($domcoords{$dc})) {
9606: push(@domcoord,$dc);
9607: }
9608: }
9609: }
9610: @domcoord = sort(@domcoord);
1.210 raeburn 9611: my $numdcs = scalar(@domcoord);
1.191 raeburn 9612: my $rows = 0;
9613: my $table;
1.125 raeburn 9614: if ($numdcs > 1) {
1.191 raeburn 9615: $table = '<table>';
9616: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 9617: my $rem = $i%($numinrow);
9618: if ($rem == 0) {
9619: if ($i > 0) {
1.191 raeburn 9620: $table .= '</tr>';
1.125 raeburn 9621: }
1.191 raeburn 9622: $table .= '<tr>';
9623: $rows ++;
1.125 raeburn 9624: }
1.191 raeburn 9625: my $check = '';
9626: if ($inputtype eq 'radio') {
9627: if (keys(%currhash) == 0) {
9628: if (!$i) {
9629: $check = ' checked="checked"';
9630: }
9631: } elsif (exists($currhash{$domcoord[$i]})) {
9632: $check = ' checked="checked"';
9633: }
9634: } else {
9635: if (exists($currhash{$domcoord[$i]})) {
9636: $check = ' checked="checked"';
1.125 raeburn 9637: }
9638: }
1.191 raeburn 9639: if ($i == @domcoord - 1) {
1.125 raeburn 9640: my $colsleft = $numinrow - $rem;
9641: if ($colsleft > 1) {
1.191 raeburn 9642: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 9643: } else {
1.191 raeburn 9644: $table .= '<td class="LC_left_item">';
1.125 raeburn 9645: }
9646: } else {
1.191 raeburn 9647: $table .= '<td class="LC_left_item">';
9648: }
9649: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
9650: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
9651: $table .= '<span class="LC_nobreak"><label>'.
9652: '<input type="'.$inputtype.'" name="'.$name.'"'.
9653: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
9654: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 9655: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 9656: }
1.219 raeburn 9657: $table .= '</label></span></td>';
1.191 raeburn 9658: }
9659: $table .= '</tr></table>';
9660: } elsif ($numdcs == 1) {
1.219 raeburn 9661: my ($dcname,$dcdom) = split(':',$domcoord[0]);
9662: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 9663: if ($inputtype eq 'radio') {
1.219 raeburn 9664: $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
9665: if ($user ne $dcname.':'.$dcdom) {
9666: $table .= ' ('.$dcname.':'.$dcdom.')';
9667: }
1.191 raeburn 9668: } else {
9669: my $check;
9670: if (exists($currhash{$domcoord[0]})) {
9671: $check = ' checked="checked"';
1.125 raeburn 9672: }
1.219 raeburn 9673: $table .= '<span class="LC_nobreak"><label>'.
9674: '<input type="checkbox" name="'.$name.'" '.
9675: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
9676: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 9677: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 9678: }
1.220 raeburn 9679: $table .= '</label></span>';
1.191 raeburn 9680: $rows ++;
1.125 raeburn 9681: }
9682: }
1.191 raeburn 9683: return ($numdcs,$table,$rows);
1.125 raeburn 9684: }
9685:
1.137 raeburn 9686: sub usersession_titles {
9687: return &Apache::lonlocal::texthash(
9688: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
9689: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 9690: spares => 'Servers offloaded to, when busy',
1.137 raeburn 9691: version => 'LON-CAPA version requirement',
1.138 raeburn 9692: excludedomain => 'Allow all, but exclude specific domains',
9693: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 9694: primary => 'Primary (checked first)',
1.154 raeburn 9695: default => 'Default',
1.137 raeburn 9696: );
9697: }
9698:
1.152 raeburn 9699: sub id_for_thisdom {
9700: my (%servers) = @_;
9701: my %altids;
9702: foreach my $server (keys(%servers)) {
9703: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
9704: if ($serverhome ne $server) {
9705: $altids{$serverhome} = $server;
9706: }
9707: }
9708: return %altids;
9709: }
9710:
1.150 raeburn 9711: sub count_servers {
9712: my ($currbalancer,%servers) = @_;
9713: my (@spares,$numspares);
9714: foreach my $lonhost (sort(keys(%servers))) {
9715: next if ($currbalancer eq $lonhost);
9716: push(@spares,$lonhost);
9717: }
9718: if ($currbalancer) {
9719: $numspares = scalar(@spares);
9720: } else {
9721: $numspares = scalar(@spares) - 1;
9722: }
9723: return ($numspares,@spares);
9724: }
9725:
9726: sub lonbalance_targets_js {
1.171 raeburn 9727: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 9728: my $select = &mt('Select');
9729: my ($alltargets,$allishome,$allinsttypes,@alltypes);
9730: if (ref($servers) eq 'HASH') {
9731: $alltargets = join("','",sort(keys(%{$servers})));
9732: my @homedoms;
9733: foreach my $server (sort(keys(%{$servers}))) {
9734: if (&Apache::lonnet::host_domain($server) eq $dom) {
9735: push(@homedoms,'1');
9736: } else {
9737: push(@homedoms,'0');
9738: }
9739: }
9740: $allishome = join("','",@homedoms);
9741: }
9742: if (ref($types) eq 'ARRAY') {
9743: if (@{$types} > 0) {
9744: @alltypes = @{$types};
9745: }
9746: }
9747: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
9748: $allinsttypes = join("','",@alltypes);
1.171 raeburn 9749: my (%currbalancer,%currtargets,%currrules,%existing);
9750: if (ref($settings) eq 'HASH') {
9751: %existing = %{$settings};
9752: }
9753: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
9754: \%currtargets,\%currrules);
1.210 raeburn 9755: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 9756: return <<"END";
9757:
9758: <script type="text/javascript">
9759: // <![CDATA[
9760:
1.171 raeburn 9761: currBalancers = new Array('$balancers');
9762:
9763: function toggleTargets(balnum) {
9764: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
9765: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
9766: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
9767: var prevbalancer = prevhostitem.value;
9768: var baltotal = document.getElementById('loadbalancing_total').value;
9769: prevhostitem.value = balancer;
9770: if (prevbalancer != '') {
9771: var prevIdx = currBalancers.indexOf(prevbalancer);
9772: if (prevIdx != -1) {
9773: currBalancers.splice(prevIdx,1);
9774: }
9775: }
1.150 raeburn 9776: if (balancer == '') {
1.171 raeburn 9777: hideSpares(balnum);
1.150 raeburn 9778: } else {
1.171 raeburn 9779: var currIdx = currBalancers.indexOf(balancer);
9780: if (currIdx == -1) {
9781: currBalancers.push(balancer);
9782: }
1.150 raeburn 9783: var homedoms = new Array('$allishome');
1.171 raeburn 9784: var ishomedom = homedoms[lonhostitem.selectedIndex];
9785: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 9786: }
1.171 raeburn 9787: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 9788: return;
9789: }
9790:
1.171 raeburn 9791: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 9792: var alltargets = new Array('$alltargets');
9793: var insttypes = new Array('$allinsttypes');
1.151 raeburn 9794: var offloadtypes = new Array('primary','default');
9795:
1.171 raeburn 9796: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
9797: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 9798:
1.151 raeburn 9799: for (var i=0; i<offloadtypes.length; i++) {
9800: var count = 0;
9801: for (var j=0; j<alltargets.length; j++) {
9802: if (alltargets[j] != balancer) {
1.171 raeburn 9803: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
9804: item.value = alltargets[j];
9805: item.style.textAlign='left';
9806: item.style.textFace='normal';
9807: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
9808: if (currBalancers.indexOf(alltargets[j]) == -1) {
9809: item.disabled = '';
9810: } else {
9811: item.disabled = 'disabled';
9812: item.checked = false;
9813: }
1.151 raeburn 9814: count ++;
9815: }
1.150 raeburn 9816: }
9817: }
1.151 raeburn 9818: for (var k=0; k<insttypes.length; k++) {
9819: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 9820: if (ishomedom == 1) {
1.171 raeburn 9821: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
9822: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 9823: } else {
1.171 raeburn 9824: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
9825: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 9826: }
9827: } else {
1.171 raeburn 9828: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
9829: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 9830: }
1.151 raeburn 9831: if ((insttypes[k] != '_LC_external') &&
9832: ((insttypes[k] != '_LC_internetdom') ||
9833: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 9834: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
9835: item.options.length = 0;
9836: item.options[0] = new Option("","",true,true);
1.210 raeburn 9837: var idx = 0;
1.151 raeburn 9838: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 9839: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
9840: idx ++;
9841: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 9842: }
9843: }
9844: }
9845: }
9846: return;
9847: }
9848:
1.171 raeburn 9849: function hideSpares(balnum) {
1.150 raeburn 9850: var alltargets = new Array('$alltargets');
9851: var insttypes = new Array('$allinsttypes');
9852: var offloadtypes = new Array('primary','default');
9853:
1.171 raeburn 9854: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
9855: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 9856:
9857: var total = alltargets.length - 1;
9858: for (var i=0; i<offloadtypes; i++) {
9859: for (var j=0; j<total; j++) {
1.171 raeburn 9860: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
9861: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
9862: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 9863: }
1.150 raeburn 9864: }
9865: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 9866: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
9867: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 9868: if (insttypes[k] != '_LC_external') {
1.171 raeburn 9869: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
9870: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 9871: }
9872: }
9873: return;
9874: }
9875:
1.171 raeburn 9876: function checkOffloads(item,balnum,type) {
1.150 raeburn 9877: var alltargets = new Array('$alltargets');
9878: var offloadtypes = new Array('primary','default');
9879: if (item.checked) {
9880: var total = alltargets.length - 1;
9881: var other;
9882: if (type == offloadtypes[0]) {
1.151 raeburn 9883: other = offloadtypes[1];
1.150 raeburn 9884: } else {
1.151 raeburn 9885: other = offloadtypes[0];
1.150 raeburn 9886: }
9887: for (var i=0; i<total; i++) {
1.171 raeburn 9888: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 9889: if (server == item.value) {
1.171 raeburn 9890: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
9891: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 9892: }
9893: }
9894: }
9895: }
9896: return;
9897: }
9898:
1.171 raeburn 9899: function singleServerToggle(balnum,type) {
9900: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 9901: if (offloadtoSelIdx == 0) {
1.171 raeburn 9902: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
9903: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 9904:
9905: } else {
1.171 raeburn 9906: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
9907: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 9908: }
9909: return;
9910: }
9911:
1.171 raeburn 9912: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 9913: if (type == '_LC_external') {
1.171 raeburn 9914: return;
1.150 raeburn 9915: }
1.171 raeburn 9916: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 9917: for (var i=0; i<typesRules.length; i++) {
9918: if (formname.elements[typesRules[i]].checked) {
9919: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 9920: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
9921: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 9922: } else {
1.171 raeburn 9923: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
9924: }
9925: }
9926: }
9927: return;
9928: }
9929:
9930: function balancerDeleteChange(balnum) {
9931: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
9932: var baltotal = document.getElementById('loadbalancing_total').value;
9933: var addtarget;
9934: var removetarget;
9935: var action = 'delete';
9936: if (document.getElementById('loadbalancing_delete_'+balnum)) {
9937: var lonhost = hostitem.value;
9938: var currIdx = currBalancers.indexOf(lonhost);
9939: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
9940: if (currIdx != -1) {
9941: currBalancers.splice(currIdx,1);
9942: }
9943: addtarget = lonhost;
9944: } else {
9945: if (currIdx == -1) {
9946: currBalancers.push(lonhost);
9947: }
9948: removetarget = lonhost;
9949: action = 'undelete';
9950: }
9951: balancerChange(balnum,baltotal,action,addtarget,removetarget);
9952: }
9953: return;
9954: }
9955:
9956: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
9957: if (baltotal > 1) {
9958: var offloadtypes = new Array('primary','default');
9959: var alltargets = new Array('$alltargets');
9960: var insttypes = new Array('$allinsttypes');
9961: for (var i=0; i<baltotal; i++) {
9962: if (i != balnum) {
9963: for (var j=0; j<offloadtypes.length; j++) {
9964: var total = alltargets.length - 1;
9965: for (var k=0; k<total; k++) {
9966: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
9967: var server = serveritem.value;
9968: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
9969: if (server == addtarget) {
9970: serveritem.disabled = '';
9971: }
9972: }
9973: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
9974: if (server == removetarget) {
9975: serveritem.disabled = 'disabled';
9976: serveritem.checked = false;
9977: }
9978: }
9979: }
9980: }
9981: for (var j=0; j<insttypes.length; j++) {
9982: if (insttypes[j] != '_LC_external') {
9983: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
9984: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
9985: var currSel = singleserver.selectedIndex;
9986: var currVal = singleserver.options[currSel].value;
9987: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
9988: var numoptions = singleserver.options.length;
9989: var needsnew = 1;
9990: for (var k=0; k<numoptions; k++) {
9991: if (singleserver.options[k] == addtarget) {
9992: needsnew = 0;
9993: break;
9994: }
9995: }
9996: if (needsnew == 1) {
9997: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
9998: }
9999: }
10000: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
10001: singleserver.options.length = 0;
10002: if ((currVal) && (currVal != removetarget)) {
10003: singleserver.options[0] = new Option("","",false,false);
10004: } else {
10005: singleserver.options[0] = new Option("","",true,true);
10006: }
10007: var idx = 0;
10008: for (var m=0; m<alltargets.length; m++) {
10009: if (currBalancers.indexOf(alltargets[m]) == -1) {
10010: idx ++;
10011: if (currVal == alltargets[m]) {
10012: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
10013: } else {
10014: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
10015: }
10016: }
10017: }
10018: }
10019: }
10020: }
10021: }
1.150 raeburn 10022: }
10023: }
10024: }
10025: return;
10026: }
10027:
1.152 raeburn 10028: // ]]>
10029: </script>
10030:
10031: END
10032: }
10033:
10034: sub new_spares_js {
10035: my @sparestypes = ('primary','default');
10036: my $types = join("','",@sparestypes);
10037: my $select = &mt('Select');
10038: return <<"END";
10039:
10040: <script type="text/javascript">
10041: // <![CDATA[
10042:
10043: function updateNewSpares(formname,lonhost) {
10044: var types = new Array('$types');
10045: var include = new Array();
10046: var exclude = new Array();
10047: for (var i=0; i<types.length; i++) {
10048: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
10049: for (var j=0; j<spareboxes.length; j++) {
10050: if (formname.elements[spareboxes[j]].checked) {
10051: exclude.push(formname.elements[spareboxes[j]].value);
10052: } else {
10053: include.push(formname.elements[spareboxes[j]].value);
10054: }
10055: }
10056: }
10057: for (var i=0; i<types.length; i++) {
10058: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
10059: var selIdx = newSpare.selectedIndex;
10060: var currnew = newSpare.options[selIdx].value;
10061: var okSpares = new Array();
10062: for (var j=0; j<newSpare.options.length; j++) {
10063: var possible = newSpare.options[j].value;
10064: if (possible != '') {
10065: if (exclude.indexOf(possible) == -1) {
10066: okSpares.push(possible);
10067: } else {
10068: if (currnew == possible) {
10069: selIdx = 0;
10070: }
10071: }
10072: }
10073: }
10074: for (var k=0; k<include.length; k++) {
10075: if (okSpares.indexOf(include[k]) == -1) {
10076: okSpares.push(include[k]);
10077: }
10078: }
10079: okSpares.sort();
10080: newSpare.options.length = 0;
10081: if (selIdx == 0) {
10082: newSpare.options[0] = new Option("$select","",true,true);
10083: } else {
10084: newSpare.options[0] = new Option("$select","",false,false);
10085: }
10086: for (var m=0; m<okSpares.length; m++) {
10087: var idx = m+1;
10088: var selThis = 0;
10089: if (selIdx != 0) {
10090: if (okSpares[m] == currnew) {
10091: selThis = 1;
10092: }
10093: }
10094: if (selThis == 1) {
10095: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
10096: } else {
10097: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
10098: }
10099: }
10100: }
10101: return;
10102: }
10103:
10104: function checkNewSpares(lonhost,type) {
10105: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
10106: var chosen = newSpare.options[newSpare.selectedIndex].value;
10107: if (chosen != '') {
10108: var othertype;
10109: var othernewSpare;
10110: if (type == 'primary') {
10111: othernewSpare = document.getElementById('newspare_default_'+lonhost);
10112: }
10113: if (type == 'default') {
10114: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
10115: }
10116: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
10117: othernewSpare.selectedIndex = 0;
10118: }
10119: }
10120: return;
10121: }
10122:
10123: // ]]>
10124: </script>
10125:
10126: END
10127:
10128: }
10129:
10130: sub common_domprefs_js {
10131: return <<"END";
10132:
10133: <script type="text/javascript">
10134: // <![CDATA[
10135:
1.150 raeburn 10136: function getIndicesByName(formname,item) {
1.152 raeburn 10137: var group = new Array();
1.150 raeburn 10138: for (var i=0;i<formname.elements.length;i++) {
10139: if (formname.elements[i].name == item) {
1.152 raeburn 10140: group.push(formname.elements[i].id);
1.150 raeburn 10141: }
10142: }
1.152 raeburn 10143: return group;
1.150 raeburn 10144: }
10145:
10146: // ]]>
10147: </script>
10148:
10149: END
1.152 raeburn 10150:
1.150 raeburn 10151: }
10152:
1.165 raeburn 10153: sub recaptcha_js {
10154: my %lt = &captcha_phrases();
10155: return <<"END";
10156:
10157: <script type="text/javascript">
10158: // <![CDATA[
10159:
10160: function updateCaptcha(caller,context) {
10161: var privitem;
10162: var pubitem;
10163: var privtext;
10164: var pubtext;
10165: if (document.getElementById(context+'_recaptchapub')) {
10166: pubitem = document.getElementById(context+'_recaptchapub');
10167: } else {
10168: return;
10169: }
10170: if (document.getElementById(context+'_recaptchapriv')) {
10171: privitem = document.getElementById(context+'_recaptchapriv');
10172: } else {
10173: return;
10174: }
10175: if (document.getElementById(context+'_recaptchapubtxt')) {
10176: pubtext = document.getElementById(context+'_recaptchapubtxt');
10177: } else {
10178: return;
10179: }
10180: if (document.getElementById(context+'_recaptchaprivtxt')) {
10181: privtext = document.getElementById(context+'_recaptchaprivtxt');
10182: } else {
10183: return;
10184: }
10185: if (caller.checked) {
10186: if (caller.value == 'recaptcha') {
10187: pubitem.type = 'text';
10188: privitem.type = 'text';
10189: pubitem.size = '40';
10190: privitem.size = '40';
10191: pubtext.innerHTML = "$lt{'pub'}";
10192: privtext.innerHTML = "$lt{'priv'}";
10193: } else {
10194: pubitem.type = 'hidden';
10195: privitem.type = 'hidden';
10196: pubtext.innerHTML = '';
10197: privtext.innerHTML = '';
10198: }
10199: }
10200: return;
10201: }
10202:
10203: // ]]>
10204: </script>
10205:
10206: END
10207:
10208: }
10209:
1.192 raeburn 10210: sub credits_js {
10211: return <<"END";
10212:
10213: <script type="text/javascript">
10214: // <![CDATA[
10215:
10216: function toggleCredits(domForm) {
10217: if (document.getElementById('credits')) {
10218: creditsitem = document.getElementById('credits');
10219: var creditsLength = domForm.coursecredits.length;
10220: if (creditsLength) {
10221: var currval;
10222: for (var i=0; i<creditsLength; i++) {
10223: if (domForm.coursecredits[i].checked) {
10224: currval = domForm.coursecredits[i].value;
10225: }
10226: }
10227: if (currval == 1) {
10228: creditsitem.style.display = 'block';
10229: } else {
10230: creditsitem.style.display = 'none';
10231: }
10232: }
10233: }
10234: return;
10235: }
10236:
10237: // ]]>
10238: </script>
10239:
10240: END
10241:
10242: }
10243:
1.165 raeburn 10244: sub captcha_phrases {
10245: return &Apache::lonlocal::texthash (
10246: priv => 'Private key',
10247: pub => 'Public key',
10248: original => 'original (CAPTCHA)',
10249: recaptcha => 'successor (ReCAPTCHA)',
10250: notused => 'unused',
10251: );
10252: }
10253:
1.205 raeburn 10254: sub devalidate_remote_domconfs {
1.212 raeburn 10255: my ($dom,$cachekeys) = @_;
10256: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 10257: my %servers = &Apache::lonnet::internet_dom_servers($dom);
10258: my %thismachine;
10259: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.212 raeburn 10260: my @posscached = ('domainconfig','domdefaults');
1.205 raeburn 10261: if (keys(%servers) > 1) {
10262: foreach my $server (keys(%servers)) {
10263: next if ($thismachine{$server});
1.212 raeburn 10264: my @cached;
10265: foreach my $name (@posscached) {
10266: if ($cachekeys->{$name}) {
10267: push(@cached,&escape($name).':'.&escape($dom));
10268: }
10269: }
10270: if (@cached) {
10271: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
10272: }
1.205 raeburn 10273: }
10274: }
10275: return;
10276: }
10277:
1.3 raeburn 10278: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>