1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
4: # $Id: domainprefs.pm,v 1.237 2014/04/25 17:56:43 bisitz Exp $
5: #
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:
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
48: for use by individuals affiliated with the institution. Accordingly, each domain
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
89: number of rows displayed on the page, and $action is the context (quotas,
90: requestcourses or requestauthor).
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,
97: used by course owners to request creation of a course, and to display/store
98: default quota sizes for Authoring Spaces.
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
106: (official, unofficial, community, and textbook). In each case the radio buttons
107: allow the selection of one of four values:
108:
109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
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:
120: approval
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:
144: - course requests will be processed automatically up to a limit of
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:
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;
165: use Apache::lonmsg();
166: use Apache::lonconfigsettings;
167: use Apache::lonuserutils();
168: use Apache::loncoursequeueadmin();
169: use LONCAPA qw(:DEFAULT :match);
170: use LONCAPA::Enrollment;
171: use LONCAPA::lonauthcgi();
172: use File::Copy;
173: use Locale::Language;
174: use DateTime::TimeZone;
175: use DateTime::Locale;
176:
177: my $registered_cleanup;
178: my $modified_urls;
179:
180: sub handler {
181: my $r=shift;
182: if ($r->header_only) {
183: &Apache::loncommon::content_type($r,'text/html');
184: $r->send_http_header;
185: return OK;
186: }
187:
188: my $context = 'domain';
189: my $dom = $env{'request.role.domain'};
190: my $domdesc = &Apache::lonnet::domain($dom,'description');
191: if (&Apache::lonnet::allowed('mau',$dom)) {
192: &Apache::loncommon::content_type($r,'text/html');
193: $r->send_http_header;
194: } else {
195: $env{'user.error.msg'}=
196: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
197: return HTTP_NOT_ACCEPTABLE;
198: }
199:
200: $registered_cleanup=0;
201: @{$modified_urls}=();
202:
203: &Apache::lonhtmlcommon::clear_breadcrumbs();
204: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
205: ['phase','actions']);
206: my $phase = 'pickactions';
207: if ( exists($env{'form.phase'}) ) {
208: $phase = $env{'form.phase'};
209: }
210: my %servers = &Apache::lonnet::internet_dom_servers($dom);
211: my %domconfig =
212: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
213: 'quotas','autoenroll','autoupdate','autocreate',
214: 'directorysrch','usercreation','usermodification',
215: 'contacts','defaults','scantron','coursecategories',
216: 'serverstatuses','requestcourses','helpsettings',
217: 'coursedefaults','usersessions','loadbalancing',
218: 'requestauthor','selfenrollment','inststatus'],$dom);
219: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
220: 'autoupdate','autocreate','directorysrch','contacts',
221: 'usercreation','selfcreation','usermodification','scantron',
222: 'requestcourses','requestauthor','coursecategories',
223: 'serverstatuses','helpsettings',
224: 'coursedefaults','selfenrollment','usersessions');
225: my %existing;
226: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
227: %existing = %{$domconfig{'loadbalancing'}};
228: }
229: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
230: push(@prefs_order,'loadbalancing');
231: }
232: my %prefs = (
233: 'rolecolors' =>
234: { text => 'Default color schemes',
235: help => 'Domain_Configuration_Color_Schemes',
236: header => [{col1 => 'Student Settings',
237: col2 => '',},
238: {col1 => 'Coordinator Settings',
239: col2 => '',},
240: {col1 => 'Author Settings',
241: col2 => '',},
242: {col1 => 'Administrator Settings',
243: col2 => '',}],
244: print => \&print_rolecolors,
245: modify => \&modify_rolecolors,
246: },
247: 'login' =>
248: { text => 'Log-in page options',
249: help => 'Domain_Configuration_Login_Page',
250: header => [{col1 => 'Log-in Page Items',
251: col2 => '',},
252: {col1 => 'Log-in Help',
253: col2 => 'Value'}],
254: print => \&print_login,
255: modify => \&modify_login,
256: },
257: 'defaults' =>
258: { text => 'Default authentication/language/timezone/portal/types',
259: help => 'Domain_Configuration_LangTZAuth',
260: header => [{col1 => 'Setting',
261: col2 => 'Value'},
262: {col1 => 'Institutional user types',
263: col2 => 'Assignable to e-mail usernames'}],
264: print => \&print_defaults,
265: modify => \&modify_defaults,
266: },
267: 'quotas' =>
268: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
269: help => 'Domain_Configuration_Quotas',
270: header => [{col1 => 'User affiliation',
271: col2 => 'Available tools',
272: col3 => 'Quotas, MB; (Authoring requires role)',}],
273: print => \&print_quotas,
274: modify => \&modify_quotas,
275: },
276: 'autoenroll' =>
277: { text => 'Auto-enrollment settings',
278: help => 'Domain_Configuration_Auto_Enrollment',
279: header => [{col1 => 'Configuration setting',
280: col2 => 'Value(s)'}],
281: print => \&print_autoenroll,
282: modify => \&modify_autoenroll,
283: },
284: 'autoupdate' =>
285: { text => 'Auto-update settings',
286: help => 'Domain_Configuration_Auto_Updates',
287: header => [{col1 => 'Setting',
288: col2 => 'Value',},
289: {col1 => 'Setting',
290: col2 => 'Affiliation'},
291: {col1 => 'User population',
292: col2 => 'Updatable user data'}],
293: print => \&print_autoupdate,
294: modify => \&modify_autoupdate,
295: },
296: 'autocreate' =>
297: { text => 'Auto-course creation settings',
298: help => 'Domain_Configuration_Auto_Creation',
299: header => [{col1 => 'Configuration Setting',
300: col2 => 'Value',}],
301: print => \&print_autocreate,
302: modify => \&modify_autocreate,
303: },
304: 'directorysrch' =>
305: { text => 'Institutional directory searches',
306: help => 'Domain_Configuration_InstDirectory_Search',
307: header => [{col1 => 'Setting',
308: col2 => 'Value',}],
309: print => \&print_directorysrch,
310: modify => \&modify_directorysrch,
311: },
312: 'contacts' =>
313: { text => 'Contact Information',
314: help => 'Domain_Configuration_Contact_Info',
315: header => [{col1 => 'Setting',
316: col2 => 'Value',}],
317: print => \&print_contacts,
318: modify => \&modify_contacts,
319: },
320: 'usercreation' =>
321: { text => 'User creation',
322: help => 'Domain_Configuration_User_Creation',
323: header => [{col1 => 'Format rule type',
324: col2 => 'Format rules in force'},
325: {col1 => 'User account creation',
326: col2 => 'Usernames which may be created',},
327: {col1 => 'Context',
328: col2 => 'Assignable authentication types'}],
329: print => \&print_usercreation,
330: modify => \&modify_usercreation,
331: },
332: 'selfcreation' =>
333: { text => 'Users self-creating accounts',
334: help => 'Domain_Configuration_Self_Creation',
335: header => [{col1 => 'Self-creation with institutional username',
336: col2 => 'Enabled?'},
337: {col1 => 'Institutional user type (login/SSO self-creation)',
338: col2 => 'Information user can enter'},
339: {col1 => 'Self-creation with e-mail as username',
340: col2 => 'Settings'}],
341: print => \&print_selfcreation,
342: modify => \&modify_selfcreation,
343: },
344: 'usermodification' =>
345: { text => 'User modification',
346: help => 'Domain_Configuration_User_Modification',
347: header => [{col1 => 'Target user has role',
348: col2 => 'User information updatable in author context'},
349: {col1 => 'Target user has role',
350: col2 => 'User information updatable in course context'}],
351: print => \&print_usermodification,
352: modify => \&modify_usermodification,
353: },
354: 'scantron' =>
355: { text => 'Bubblesheet format file',
356: help => 'Domain_Configuration_Scantron_Format',
357: header => [ {col1 => 'Item',
358: col2 => '',
359: }],
360: print => \&print_scantron,
361: modify => \&modify_scantron,
362: },
363: 'requestcourses' =>
364: {text => 'Request creation of courses',
365: help => 'Domain_Configuration_Request_Courses',
366: header => [{col1 => 'User affiliation',
367: col2 => 'Availability/Processing of requests',},
368: {col1 => 'Setting',
369: col2 => 'Value'},
370: {col1 => 'Available textbooks',
371: col2 => ''},
372: {col1 => 'Validation (not official courses)',
373: col2 => 'Value'},],
374: print => \&print_quotas,
375: modify => \&modify_quotas,
376: },
377: 'requestauthor' =>
378: {text => 'Request Authoring Space',
379: help => 'Domain_Configuration_Request_Author',
380: header => [{col1 => 'User affiliation',
381: col2 => 'Availability/Processing of requests',},
382: {col1 => 'Setting',
383: col2 => 'Value'}],
384: print => \&print_quotas,
385: modify => \&modify_quotas,
386: },
387: 'coursecategories' =>
388: { text => 'Cataloging of courses/communities',
389: help => 'Domain_Configuration_Cataloging_Courses',
390: header => [{col1 => 'Category settings',
391: col2 => '',},
392: {col1 => 'Categories',
393: col2 => '',
394: }],
395: print => \&print_coursecategories,
396: modify => \&modify_coursecategories,
397: },
398: 'serverstatuses' =>
399: {text => 'Access to server status pages',
400: help => 'Domain_Configuration_Server_Status',
401: header => [{col1 => 'Status Page',
402: col2 => 'Other named users',
403: col3 => 'Specific IPs',
404: }],
405: print => \&print_serverstatuses,
406: modify => \&modify_serverstatuses,
407: },
408: 'helpsettings' =>
409: {text => 'Help page settings',
410: help => 'Domain_Configuration_Help_Settings',
411: header => [{col1 => 'Help Settings (logged-in users)',
412: col2 => 'Value'}],
413: print => \&print_helpsettings,
414: modify => \&modify_helpsettings,
415: },
416: 'coursedefaults' =>
417: {text => 'Course/Community defaults',
418: help => 'Domain_Configuration_Course_Defaults',
419: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
420: col2 => 'Value',},
421: {col1 => 'Defaults which can be overridden for each course by a DC',
422: col2 => 'Value',},],
423: print => \&print_coursedefaults,
424: modify => \&modify_coursedefaults,
425: },
426: 'selfenrollment' =>
427: {text => 'Self-enrollment in Course/Community',
428: help => 'Domain_Configuration_Selfenrollment',
429: header => [{col1 => 'Configuration Rights',
430: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
431: {col1 => 'Defaults',
432: col2 => 'Value'},
433: {col1 => 'Self-enrollment validation (optional)',
434: col2 => 'Value'},],
435: print => \&print_selfenrollment,
436: modify => \&modify_selfenrollment,
437: },
438: 'privacy' =>
439: {text => 'User Privacy',
440: help => 'Domain_Configuration_User_Privacy',
441: header => [{col1 => 'Setting',
442: col2 => 'Value',}],
443: print => \&print_privacy,
444: modify => \&modify_privacy,
445: },
446: 'usersessions' =>
447: {text => 'User session hosting/offloading',
448: help => 'Domain_Configuration_User_Sessions',
449: header => [{col1 => 'Domain server',
450: col2 => 'Servers to offload sessions to when busy'},
451: {col1 => 'Hosting of users from other domains',
452: col2 => 'Rules'},
453: {col1 => "Hosting domain's own users elsewhere",
454: col2 => 'Rules'}],
455: print => \&print_usersessions,
456: modify => \&modify_usersessions,
457: },
458: 'loadbalancing' =>
459: {text => 'Dedicated Load Balancer(s)',
460: help => 'Domain_Configuration_Load_Balancing',
461: header => [{col1 => 'Balancers',
462: col2 => 'Default destinations',
463: col3 => 'User affiliation',
464: col4 => 'Overrides'},
465: ],
466: print => \&print_loadbalancing,
467: modify => \&modify_loadbalancing,
468: },
469: );
470: if (keys(%servers) > 1) {
471: $prefs{'login'} = { text => 'Log-in page options',
472: help => 'Domain_Configuration_Login_Page',
473: header => [{col1 => 'Log-in Service',
474: col2 => 'Server Setting',},
475: {col1 => 'Log-in Page Items',
476: col2 => ''},
477: {col1 => 'Log-in Help',
478: col2 => 'Value'}],
479: print => \&print_login,
480: modify => \&modify_login,
481: };
482: }
483:
484: my @roles = ('student','coordinator','author','admin');
485: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
486: &Apache::lonhtmlcommon::add_breadcrumb
487: ({href=>"javascript:changePage(document.$phase,'pickactions')",
488: text=>"Settings to display/modify"});
489: my $confname = $dom.'-domainconfig';
490:
491: if ($phase eq 'process') {
492: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
493: \%prefs,\%domconfig,$confname,\@roles);
494: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
495: $r->rflush();
496: &devalidate_remote_domconfs($dom,$result);
497: }
498: } elsif ($phase eq 'display') {
499: my $js = &recaptcha_js().
500: &toggle_display_js();
501: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
502: my ($othertitle,$usertypes,$types) =
503: &Apache::loncommon::sorted_inst_types($dom);
504: $js .= &lonbalance_targets_js($dom,$types,\%servers,
505: $domconfig{'loadbalancing'}).
506: &new_spares_js().
507: &common_domprefs_js().
508: &Apache::loncommon::javascript_array_indexof();
509: }
510: if (grep(/^requestcourses$/,@actions)) {
511: my $javascript_validations;
512: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
513: $js .= <<END;
514: <script type="text/javascript">
515: $javascript_validations
516: </script>
517: $coursebrowserjs
518: END
519: }
520: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
521: } else {
522: # check if domconfig user exists for the domain.
523: my $servadm = $r->dir_config('lonAdmEMail');
524: my ($configuserok,$author_ok,$switchserver) =
525: &config_check($dom,$confname,$servadm);
526: unless ($configuserok eq 'ok') {
527: &Apache::lonconfigsettings::print_header($r,$phase,$context);
528: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
529: $confname).
530: '<br />'
531: );
532: if ($switchserver) {
533: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
534: '<br />'.
535: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
536: '<br />'.
537: &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).
538: '<br />'.
539: &mt('To do that now, use the following link: [_1]',$switchserver)
540: );
541: } else {
542: $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.').
543: '<br />'.
544: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
545: );
546: }
547: $r->print(&Apache::loncommon::end_page());
548: return OK;
549: }
550: if (keys(%domconfig) == 0) {
551: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
552: my @ids=&Apache::lonnet::current_machine_ids();
553: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
554: my %designhash = &Apache::loncommon::get_domainconf($dom);
555: my @loginimages = ('img','logo','domlogo','login');
556: my $custom_img_count = 0;
557: foreach my $img (@loginimages) {
558: if ($designhash{$dom.'.login.'.$img} ne '') {
559: $custom_img_count ++;
560: }
561: }
562: foreach my $role (@roles) {
563: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
564: $custom_img_count ++;
565: }
566: }
567: if ($custom_img_count > 0) {
568: &Apache::lonconfigsettings::print_header($r,$phase,$context);
569: my $switch_server = &check_switchserver($dom,$confname);
570: $r->print(
571: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
572: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
573: &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 />'.
574: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
575: if ($switch_server) {
576: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
577: }
578: $r->print(&Apache::loncommon::end_page());
579: return OK;
580: }
581: }
582: }
583: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
584: }
585: return OK;
586: }
587:
588: sub process_changes {
589: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
590: my %domconfig;
591: if (ref($values) eq 'HASH') {
592: %domconfig = %{$values};
593: }
594: my $output;
595: if ($action eq 'login') {
596: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
597: } elsif ($action eq 'rolecolors') {
598: $output = &modify_rolecolors($r,$dom,$confname,$roles,
599: $lastactref,%domconfig);
600: } elsif ($action eq 'quotas') {
601: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
602: } elsif ($action eq 'autoenroll') {
603: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
604: } elsif ($action eq 'autoupdate') {
605: $output = &modify_autoupdate($dom,%domconfig);
606: } elsif ($action eq 'autocreate') {
607: $output = &modify_autocreate($dom,%domconfig);
608: } elsif ($action eq 'directorysrch') {
609: $output = &modify_directorysrch($dom,%domconfig);
610: } elsif ($action eq 'usercreation') {
611: $output = &modify_usercreation($dom,%domconfig);
612: } elsif ($action eq 'selfcreation') {
613: $output = &modify_selfcreation($dom,%domconfig);
614: } elsif ($action eq 'usermodification') {
615: $output = &modify_usermodification($dom,%domconfig);
616: } elsif ($action eq 'contacts') {
617: $output = &modify_contacts($dom,$lastactref,%domconfig);
618: } elsif ($action eq 'defaults') {
619: $output = &modify_defaults($dom,$lastactref,%domconfig);
620: } elsif ($action eq 'scantron') {
621: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
622: } elsif ($action eq 'coursecategories') {
623: $output = &modify_coursecategories($dom,%domconfig);
624: } elsif ($action eq 'serverstatuses') {
625: $output = &modify_serverstatuses($dom,%domconfig);
626: } elsif ($action eq 'requestcourses') {
627: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
628: } elsif ($action eq 'requestauthor') {
629: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
630: } elsif ($action eq 'helpsettings') {
631: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
632: } elsif ($action eq 'coursedefaults') {
633: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
634: } elsif ($action eq 'selfenrollment') {
635: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
636: } elsif ($action eq 'usersessions') {
637: $output = &modify_usersessions($dom,$lastactref,%domconfig);
638: } elsif ($action eq 'loadbalancing') {
639: $output = &modify_loadbalancing($dom,%domconfig);
640: }
641: return $output;
642: }
643:
644: sub print_config_box {
645: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
646: my $rowtotal = 0;
647: my $output;
648: if ($action eq 'coursecategories') {
649: $output = &coursecategories_javascript($settings);
650: } elsif ($action eq 'defaults') {
651: $output = &defaults_javascript($settings);
652: }
653: $output .=
654: '<table class="LC_nested_outer">
655: <tr>
656: <th align="left" valign="middle"><span class="LC_nobreak">'.
657: &mt($item->{text}).' '.
658: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
659: '</tr>';
660: $rowtotal ++;
661: my $numheaders = 1;
662: if (ref($item->{'header'}) eq 'ARRAY') {
663: $numheaders = scalar(@{$item->{'header'}});
664: }
665: if ($numheaders > 1) {
666: my $colspan = '';
667: my $rightcolspan = '';
668: if (($action eq 'rolecolors') || ($action eq 'coursecategories') || ($action eq 'defaults') ||
669: (($action eq 'login') && ($numheaders < 3))) {
670: $colspan = ' colspan="2"';
671: }
672: if ($action eq 'usersessions') {
673: $rightcolspan = ' colspan="3"';
674: }
675: $output .= '
676: <tr>
677: <td>
678: <table class="LC_nested">
679: <tr class="LC_info_row">
680: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
681: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
682: </tr>';
683: $rowtotal ++;
684: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
685: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
686: ($action eq 'selfenrollment') || ($action eq 'usersessions')) {
687: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
688: } elsif ($action eq 'coursecategories') {
689: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
690: } elsif ($action eq 'login') {
691: if ($numheaders == 3) {
692: $colspan = ' colspan="2"';
693: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
694: } else {
695: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
696: }
697: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
698: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
699: } elsif ($action eq 'rolecolors') {
700: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
701: }
702: $output .= '
703: </table>
704: </td>
705: </tr>
706: <tr>
707: <td>
708: <table class="LC_nested">
709: <tr class="LC_info_row">
710: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
711: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
712: </tr>';
713: $rowtotal ++;
714: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
715: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
716: ($action eq 'usersessions')) {
717: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal).'
718: </table>
719: </td>
720: </tr>
721: <tr>
722: <td>
723: <table class="LC_nested">
724: <tr class="LC_info_row">
725: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
726: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
727: </tr>'."\n".
728: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
729: $rowtotal ++;
730: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
731: ($action eq 'defaults')) {
732: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
733: } elsif ($action eq 'coursecategories') {
734: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
735: } elsif ($action eq 'login') {
736: if ($numheaders == 3) {
737: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
738: </table>
739: </td>
740: </tr>
741: <tr>
742: <td>
743: <table class="LC_nested">
744: <tr class="LC_info_row">
745: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
746: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
747: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
748: $rowtotal ++;
749: } else {
750: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
751: }
752: } elsif ($action eq 'requestcourses') {
753: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal).
754: &print_studentcode($settings,\$rowtotal).'
755: </table>
756: </td>
757: </tr>
758: <tr>
759: <td>
760: <table class="LC_nested">
761: <tr class="LC_info_row">
762: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
763: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
764: &print_textbookcourses($dom,$settings,\$rowtotal).'
765: </table>
766: </td>
767: </tr>
768: <tr>
769: <td>
770: <table class="LC_nested">
771: <tr class="LC_info_row">
772: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
773: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
774: </tr>'.
775: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
776: } elsif ($action eq 'requestauthor') {
777: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
778: } elsif ($action eq 'rolecolors') {
779: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
780: </table>
781: </td>
782: </tr>
783: <tr>
784: <td>
785: <table class="LC_nested">
786: <tr class="LC_info_row">
787: <td class="LC_left_item"'.$colspan.' valign="top">'.
788: &mt($item->{'header'}->[2]->{'col1'}).'</td>
789: <td class="LC_right_item" valign="top">'.
790: &mt($item->{'header'}->[2]->{'col2'}).'</td>
791: </tr>'.
792: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
793: </table>
794: </td>
795: </tr>
796: <tr>
797: <td>
798: <table class="LC_nested">
799: <tr class="LC_info_row">
800: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
801: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
802: </tr>'.
803: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
804: $rowtotal += 2;
805: }
806: } else {
807: $output .= '
808: <tr>
809: <td>
810: <table class="LC_nested">
811: <tr class="LC_info_row">';
812: if (($action eq 'login') || ($action eq 'directorysrch')) {
813: $output .= '
814: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
815: } elsif ($action eq 'serverstatuses') {
816: $output .= '
817: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
818: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
819:
820: } else {
821: $output .= '
822: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
823: }
824: if (defined($item->{'header'}->[0]->{'col3'})) {
825: $output .= '<td class="LC_left_item" valign="top">'.
826: &mt($item->{'header'}->[0]->{'col2'});
827: if ($action eq 'serverstatuses') {
828: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
829: }
830: } else {
831: $output .= '<td class="LC_right_item" valign="top">'.
832: &mt($item->{'header'}->[0]->{'col2'});
833: }
834: $output .= '</td>';
835: if ($item->{'header'}->[0]->{'col3'}) {
836: if (defined($item->{'header'}->[0]->{'col4'})) {
837: $output .= '<td class="LC_left_item" valign="top">'.
838: &mt($item->{'header'}->[0]->{'col3'});
839: } else {
840: $output .= '<td class="LC_right_item" valign="top">'.
841: &mt($item->{'header'}->[0]->{'col3'});
842: }
843: if ($action eq 'serverstatuses') {
844: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
845: }
846: $output .= '</td>';
847: }
848: if ($item->{'header'}->[0]->{'col4'}) {
849: $output .= '<td class="LC_right_item" valign="top">'.
850: &mt($item->{'header'}->[0]->{'col4'});
851: }
852: $output .= '</tr>';
853: $rowtotal ++;
854: if ($action eq 'quotas') {
855: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
856: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || ($action eq 'directorysrch') ||
857: ($action eq 'contacts') || ($action eq 'serverstatuses') || ($action eq 'loadbalancing')) {
858: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
859: } elsif ($action eq 'scantron') {
860: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
861: } elsif ($action eq 'helpsettings') {
862: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
863: }
864: }
865: $output .= '
866: </table>
867: </td>
868: </tr>
869: </table><br />';
870: return ($output,$rowtotal);
871: }
872:
873: sub print_login {
874: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
875: my ($css_class,$datatable);
876: my %choices = &login_choices();
877:
878: if ($caller eq 'service') {
879: my %servers = &Apache::lonnet::internet_dom_servers($dom);
880: my $choice = $choices{'disallowlogin'};
881: $css_class = ' class="LC_odd_row"';
882: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
883: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
884: '<th>'.$choices{'server'}.'</th>'.
885: '<th>'.$choices{'serverpath'}.'</th>'.
886: '<th>'.$choices{'custompath'}.'</th>'.
887: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
888: my %disallowed;
889: if (ref($settings) eq 'HASH') {
890: if (ref($settings->{'loginvia'}) eq 'HASH') {
891: %disallowed = %{$settings->{'loginvia'}};
892: }
893: }
894: foreach my $lonhost (sort(keys(%servers))) {
895: my $direct = 'selected="selected"';
896: if (ref($disallowed{$lonhost}) eq 'HASH') {
897: if ($disallowed{$lonhost}{'server'} ne '') {
898: $direct = '';
899: }
900: }
901: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
902: '<td><select name="'.$lonhost.'_server">'.
903: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
904: '</option>';
905: foreach my $hostid (sort(keys(%servers))) {
906: next if ($servers{$hostid} eq $servers{$lonhost});
907: my $selected = '';
908: if (ref($disallowed{$lonhost}) eq 'HASH') {
909: if ($hostid eq $disallowed{$lonhost}{'server'}) {
910: $selected = 'selected="selected"';
911: }
912: }
913: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
914: $servers{$hostid}.'</option>';
915: }
916: $datatable .= '</select></td>'.
917: '<td><select name="'.$lonhost.'_serverpath">';
918: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
919: my $pathname = $path;
920: if ($path eq 'custom') {
921: $pathname = &mt('Custom Path').' ->';
922: }
923: my $selected = '';
924: if (ref($disallowed{$lonhost}) eq 'HASH') {
925: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
926: $selected = 'selected="selected"';
927: }
928: } elsif ($path eq '') {
929: $selected = 'selected="selected"';
930: }
931: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
932: }
933: $datatable .= '</select></td>';
934: my ($custom,$exempt);
935: if (ref($disallowed{$lonhost}) eq 'HASH') {
936: $custom = $disallowed{$lonhost}{'custompath'};
937: $exempt = $disallowed{$lonhost}{'exempt'};
938: }
939: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
940: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
941: '</tr>';
942: }
943: $datatable .= '</table></td></tr>';
944: return $datatable;
945: } elsif ($caller eq 'page') {
946: my %defaultchecked = (
947: 'coursecatalog' => 'on',
948: 'helpdesk' => 'on',
949: 'adminmail' => 'off',
950: 'newuser' => 'off',
951: );
952: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
953: my (%checkedon,%checkedoff);
954: foreach my $item (@toggles) {
955: if ($defaultchecked{$item} eq 'on') {
956: $checkedon{$item} = ' checked="checked" ';
957: $checkedoff{$item} = ' ';
958: } elsif ($defaultchecked{$item} eq 'off') {
959: $checkedoff{$item} = ' checked="checked" ';
960: $checkedon{$item} = ' ';
961: }
962: }
963: my @images = ('img','logo','domlogo','login');
964: my @logintext = ('textcol','bgcol');
965: my @bgs = ('pgbg','mainbg','sidebg');
966: my @links = ('link','alink','vlink');
967: my %designhash = &Apache::loncommon::get_domainconf($dom);
968: my %defaultdesign = %Apache::loncommon::defaultdesign;
969: my (%is_custom,%designs);
970: my %defaults = (
971: font => $defaultdesign{'login.font'},
972: );
973: foreach my $item (@images) {
974: $defaults{$item} = $defaultdesign{'login.'.$item};
975: $defaults{'showlogo'}{$item} = 1;
976: }
977: foreach my $item (@bgs) {
978: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
979: }
980: foreach my $item (@logintext) {
981: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
982: }
983: foreach my $item (@links) {
984: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
985: }
986: if (ref($settings) eq 'HASH') {
987: foreach my $item (@toggles) {
988: if ($settings->{$item} eq '1') {
989: $checkedon{$item} = ' checked="checked" ';
990: $checkedoff{$item} = ' ';
991: } elsif ($settings->{$item} eq '0') {
992: $checkedoff{$item} = ' checked="checked" ';
993: $checkedon{$item} = ' ';
994: }
995: }
996: foreach my $item (@images) {
997: if (defined($settings->{$item})) {
998: $designs{$item} = $settings->{$item};
999: $is_custom{$item} = 1;
1000: }
1001: if (defined($settings->{'showlogo'}{$item})) {
1002: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1003: }
1004: }
1005: foreach my $item (@logintext) {
1006: if ($settings->{$item} ne '') {
1007: $designs{'logintext'}{$item} = $settings->{$item};
1008: $is_custom{$item} = 1;
1009: }
1010: }
1011: if ($settings->{'font'} ne '') {
1012: $designs{'font'} = $settings->{'font'};
1013: $is_custom{'font'} = 1;
1014: }
1015: foreach my $item (@bgs) {
1016: if ($settings->{$item} ne '') {
1017: $designs{'bgs'}{$item} = $settings->{$item};
1018: $is_custom{$item} = 1;
1019: }
1020: }
1021: foreach my $item (@links) {
1022: if ($settings->{$item} ne '') {
1023: $designs{'links'}{$item} = $settings->{$item};
1024: $is_custom{$item} = 1;
1025: }
1026: }
1027: } else {
1028: if ($designhash{$dom.'.login.font'} ne '') {
1029: $designs{'font'} = $designhash{$dom.'.login.font'};
1030: $is_custom{'font'} = 1;
1031: }
1032: foreach my $item (@images) {
1033: if ($designhash{$dom.'.login.'.$item} ne '') {
1034: $designs{$item} = $designhash{$dom.'.login.'.$item};
1035: $is_custom{$item} = 1;
1036: }
1037: }
1038: foreach my $item (@bgs) {
1039: if ($designhash{$dom.'.login.'.$item} ne '') {
1040: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1041: $is_custom{$item} = 1;
1042: }
1043: }
1044: foreach my $item (@links) {
1045: if ($designhash{$dom.'.login.'.$item} ne '') {
1046: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1047: $is_custom{$item} = 1;
1048: }
1049: }
1050: }
1051: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1052: logo => 'Institution Logo',
1053: domlogo => 'Domain Logo',
1054: login => 'Login box');
1055: my $itemcount = 1;
1056: foreach my $item (@toggles) {
1057: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1058: $datatable .=
1059: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1060: '</td><td>'.
1061: '<span class="LC_nobreak"><label><input type="radio" name="'.
1062: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1063: '</label> <label><input type="radio" name="'.$item.'"'.
1064: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1065: '</tr>';
1066: $itemcount ++;
1067: }
1068: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1069: $datatable .= '</tr></table></td></tr>';
1070: } elsif ($caller eq 'help') {
1071: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1072: my $switchserver = &check_switchserver($dom,$confname);
1073: my $itemcount = 1;
1074: $defaulturl = '/adm/loginproblems.html';
1075: $defaulttype = 'default';
1076: %lt = &Apache::lonlocal::texthash (
1077: del => 'Delete?',
1078: rep => 'Replace:',
1079: upl => 'Upload:',
1080: default => 'Default',
1081: custom => 'Custom',
1082: );
1083: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1084: my @currlangs;
1085: if (ref($settings) eq 'HASH') {
1086: if (ref($settings->{'helpurl'}) eq 'HASH') {
1087: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1088: next if ($settings->{'helpurl'}{$key} eq '');
1089: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1090: $type{$key} = 'custom';
1091: unless ($key eq 'nolang') {
1092: push(@currlangs,$key);
1093: }
1094: }
1095: } elsif ($settings->{'helpurl'} ne '') {
1096: $type{'nolang'} = 'custom';
1097: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1098: }
1099: }
1100: foreach my $lang ('nolang',sort(@currlangs)) {
1101: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1102: $datatable .= '<tr'.$css_class.'>';
1103: if ($url{$lang} eq '') {
1104: $url{$lang} = $defaulturl;
1105: }
1106: if ($type{$lang} eq '') {
1107: $type{$lang} = $defaulttype;
1108: }
1109: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1110: if ($lang eq 'nolang') {
1111: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1112: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1113: } else {
1114: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1115: $langchoices{$lang},
1116: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1117: }
1118: $datatable .= '</span></td>'."\n".
1119: '<td class="LC_left_item">';
1120: if ($type{$lang} eq 'custom') {
1121: $datatable .= '<span class="LC_nobreak"><label>'.
1122: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1123: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1124: } else {
1125: $datatable .= $lt{'upl'};
1126: }
1127: $datatable .='<br />';
1128: if ($switchserver) {
1129: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1130: } else {
1131: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1132: }
1133: $datatable .= '</td></tr>';
1134: $itemcount ++;
1135: }
1136: my @addlangs;
1137: foreach my $lang (sort(keys(%langchoices))) {
1138: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1139: push(@addlangs,$lang);
1140: }
1141: if (@addlangs > 0) {
1142: my %toadd;
1143: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1144: $toadd{''} = &mt('Select');
1145: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1146: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1147: &mt('Add log-in help page for a specific language:').' '.
1148: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1149: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1150: if ($switchserver) {
1151: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1152: } else {
1153: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1154: }
1155: $datatable .= '</td></tr>';
1156: $itemcount ++;
1157: }
1158: $datatable .= &captcha_choice('login',$settings,$itemcount);
1159: }
1160: return $datatable;
1161: }
1162:
1163: sub login_choices {
1164: my %choices =
1165: &Apache::lonlocal::texthash (
1166: coursecatalog => 'Display Course/Community Catalog link?',
1167: adminmail => "Display Administrator's E-mail Address?",
1168: helpdesk => 'Display "Contact Helpdesk" link',
1169: disallowlogin => "Login page requests redirected",
1170: hostid => "Server",
1171: server => "Redirect to:",
1172: serverpath => "Path",
1173: custompath => "Custom",
1174: exempt => "Exempt IP(s)",
1175: directlogin => "No redirect",
1176: newuser => "Link to create a user account",
1177: img => "Header",
1178: logo => "Main Logo",
1179: domlogo => "Domain Logo",
1180: login => "Log-in Header",
1181: textcol => "Text color",
1182: bgcol => "Box color",
1183: bgs => "Background colors",
1184: links => "Link colors",
1185: font => "Font color",
1186: pgbg => "Header",
1187: mainbg => "Page",
1188: sidebg => "Login box",
1189: link => "Link",
1190: alink => "Active link",
1191: vlink => "Visited link",
1192: );
1193: return %choices;
1194: }
1195:
1196: sub print_rolecolors {
1197: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1198: my %choices = &color_font_choices();
1199: my @bgs = ('pgbg','tabbg','sidebg');
1200: my @links = ('link','alink','vlink');
1201: my @images = ('img');
1202: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1203: my %designhash = &Apache::loncommon::get_domainconf($dom);
1204: my %defaultdesign = %Apache::loncommon::defaultdesign;
1205: my (%is_custom,%designs);
1206: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1207: if (ref($settings) eq 'HASH') {
1208: if (ref($settings->{$role}) eq 'HASH') {
1209: if ($settings->{$role}->{'img'} ne '') {
1210: $designs{'img'} = $settings->{$role}->{'img'};
1211: $is_custom{'img'} = 1;
1212: }
1213: if ($settings->{$role}->{'font'} ne '') {
1214: $designs{'font'} = $settings->{$role}->{'font'};
1215: $is_custom{'font'} = 1;
1216: }
1217: if ($settings->{$role}->{'fontmenu'} ne '') {
1218: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1219: $is_custom{'fontmenu'} = 1;
1220: }
1221: foreach my $item (@bgs) {
1222: if ($settings->{$role}->{$item} ne '') {
1223: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1224: $is_custom{$item} = 1;
1225: }
1226: }
1227: foreach my $item (@links) {
1228: if ($settings->{$role}->{$item} ne '') {
1229: $designs{'links'}{$item} = $settings->{$role}->{$item};
1230: $is_custom{$item} = 1;
1231: }
1232: }
1233: }
1234: } else {
1235: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1236: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1237: $is_custom{'img'} = 1;
1238: }
1239: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1240: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1241: $is_custom{'fontmenu'} = 1;
1242: }
1243: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1244: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1245: $is_custom{'font'} = 1;
1246: }
1247: foreach my $item (@bgs) {
1248: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1249: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1250: $is_custom{$item} = 1;
1251:
1252: }
1253: }
1254: foreach my $item (@links) {
1255: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1256: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1257: $is_custom{$item} = 1;
1258: }
1259: }
1260: }
1261: my $itemcount = 1;
1262: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1263: $datatable .= '</tr></table></td></tr>';
1264: return $datatable;
1265: }
1266:
1267: sub role_defaults {
1268: my ($role,$bgs,$links,$images,$logintext) = @_;
1269: my %defaults;
1270: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1271: return %defaults;
1272: }
1273: my %defaultdesign = %Apache::loncommon::defaultdesign;
1274: if ($role eq 'login') {
1275: %defaults = (
1276: font => $defaultdesign{$role.'.font'},
1277: );
1278: if (ref($logintext) eq 'ARRAY') {
1279: foreach my $item (@{$logintext}) {
1280: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1281: }
1282: }
1283: foreach my $item (@{$images}) {
1284: $defaults{'showlogo'}{$item} = 1;
1285: }
1286: } else {
1287: %defaults = (
1288: img => $defaultdesign{$role.'.img'},
1289: font => $defaultdesign{$role.'.font'},
1290: fontmenu => $defaultdesign{$role.'.fontmenu'},
1291: );
1292: }
1293: foreach my $item (@{$bgs}) {
1294: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1295: }
1296: foreach my $item (@{$links}) {
1297: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1298: }
1299: foreach my $item (@{$images}) {
1300: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1301: }
1302: return %defaults;
1303: }
1304:
1305: sub display_color_options {
1306: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1307: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1308: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1309: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1310: my $datatable = '<tr'.$css_class.'>'.
1311: '<td>'.$choices->{'font'}.'</td>';
1312: if (!$is_custom->{'font'}) {
1313: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1314: } else {
1315: $datatable .= '<td> </td>';
1316: }
1317: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1318:
1319: $datatable .= '<td><span class="LC_nobreak">'.
1320: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1321: ' value="'.$current_color.'" /> '.
1322: ' </td></tr>';
1323: unless ($role eq 'login') {
1324: $datatable .= '<tr'.$css_class.'>'.
1325: '<td>'.$choices->{'fontmenu'}.'</td>';
1326: if (!$is_custom->{'fontmenu'}) {
1327: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1328: } else {
1329: $datatable .= '<td> </td>';
1330: }
1331: $current_color = $designs->{'fontmenu'} ?
1332: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1333: $datatable .= '<td><span class="LC_nobreak">'.
1334: '<input class="colorchooser" type="text" size="10" name="'
1335: .$role.'_fontmenu"'.
1336: ' value="'.$current_color.'" /> '.
1337: ' </td></tr>';
1338: }
1339: my $switchserver = &check_switchserver($dom,$confname);
1340: foreach my $img (@{$images}) {
1341: $itemcount ++;
1342: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1343: $datatable .= '<tr'.$css_class.'>'.
1344: '<td>'.$choices->{$img};
1345: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1346: if ($role eq 'login') {
1347: if ($img eq 'login') {
1348: $login_hdr_pick =
1349: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1350: $logincolors =
1351: &login_text_colors($img,$role,$logintext,$phase,$choices,
1352: $designs,$defaults);
1353: } elsif ($img ne 'domlogo') {
1354: $datatable.= &logo_display_options($img,$defaults,$designs);
1355: }
1356: }
1357: $datatable .= '</td>';
1358: if ($designs->{$img} ne '') {
1359: $imgfile = $designs->{$img};
1360: $img_import = ($imgfile =~ m{^/adm/});
1361: } else {
1362: $imgfile = $defaults->{$img};
1363: }
1364: if ($imgfile) {
1365: my ($showfile,$fullsize);
1366: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1367: my $urldir = $1;
1368: my $filename = $2;
1369: my @info = &Apache::lonnet::stat_file($designs->{$img});
1370: if (@info) {
1371: my $thumbfile = 'tn-'.$filename;
1372: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1373: if (@thumb) {
1374: $showfile = $urldir.'/'.$thumbfile;
1375: } else {
1376: $showfile = $imgfile;
1377: }
1378: } else {
1379: $showfile = '';
1380: }
1381: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1382: $showfile = $imgfile;
1383: my $imgdir = $1;
1384: my $filename = $2;
1385: if (-e "$londocroot/$imgdir/tn-".$filename) {
1386: $showfile = "/$imgdir/tn-".$filename;
1387: } else {
1388: my $input = $londocroot.$imgfile;
1389: my $output = "$londocroot/$imgdir/tn-".$filename;
1390: if (!-e $output) {
1391: my ($width,$height) = &thumb_dimensions();
1392: my ($fullwidth,$fullheight) = &check_dimensions($input);
1393: if ($fullwidth ne '' && $fullheight ne '') {
1394: if ($fullwidth > $width && $fullheight > $height) {
1395: my $size = $width.'x'.$height;
1396: system("convert -sample $size $input $output");
1397: $showfile = "/$imgdir/tn-".$filename;
1398: }
1399: }
1400: }
1401: }
1402: }
1403: if ($showfile) {
1404: if ($showfile =~ m{^/(adm|res)/}) {
1405: if ($showfile =~ m{^/res/}) {
1406: my $local_showfile =
1407: &Apache::lonnet::filelocation('',$showfile);
1408: &Apache::lonnet::repcopy($local_showfile);
1409: }
1410: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1411: }
1412: if ($imgfile) {
1413: if ($imgfile =~ m{^/(adm|res)/}) {
1414: if ($imgfile =~ m{^/res/}) {
1415: my $local_imgfile =
1416: &Apache::lonnet::filelocation('',$imgfile);
1417: &Apache::lonnet::repcopy($local_imgfile);
1418: }
1419: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1420: } else {
1421: $fullsize = $imgfile;
1422: }
1423: }
1424: $datatable .= '<td>';
1425: if ($img eq 'login') {
1426: $datatable .= $login_hdr_pick;
1427: }
1428: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1429: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1430: } else {
1431: $datatable .= '<td> </td><td class="LC_left_item">'.
1432: &mt('Upload:').'<br />';
1433: }
1434: } else {
1435: $datatable .= '<td> </td><td class="LC_left_item">'.
1436: &mt('Upload:').'<br />';
1437: }
1438: if ($switchserver) {
1439: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1440: } else {
1441: if ($img ne 'login') { # suppress file selection for Log-in header
1442: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1443: }
1444: }
1445: $datatable .= '</td></tr>';
1446: }
1447: $itemcount ++;
1448: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1449: $datatable .= '<tr'.$css_class.'>'.
1450: '<td>'.$choices->{'bgs'}.'</td>';
1451: my $bgs_def;
1452: foreach my $item (@{$bgs}) {
1453: if (!$is_custom->{$item}) {
1454: $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>';
1455: }
1456: }
1457: if ($bgs_def) {
1458: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1459: } else {
1460: $datatable .= '<td> </td>';
1461: }
1462: $datatable .= '<td class="LC_right_item">'.
1463: '<table border="0"><tr>';
1464:
1465: foreach my $item (@{$bgs}) {
1466: $datatable .= '<td align="center">'.$choices->{$item};
1467: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1468: if ($designs->{'bgs'}{$item}) {
1469: $datatable .= ' ';
1470: }
1471: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1472: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1473: }
1474: $datatable .= '</tr></table></td></tr>';
1475: $itemcount ++;
1476: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1477: $datatable .= '<tr'.$css_class.'>'.
1478: '<td>'.$choices->{'links'}.'</td>';
1479: my $links_def;
1480: foreach my $item (@{$links}) {
1481: if (!$is_custom->{$item}) {
1482: $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1483: }
1484: }
1485: if ($links_def) {
1486: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1487: } else {
1488: $datatable .= '<td> </td>';
1489: }
1490: $datatable .= '<td class="LC_right_item">'.
1491: '<table border="0"><tr>';
1492: foreach my $item (@{$links}) {
1493: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1494: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1495: if ($designs->{'links'}{$item}) {
1496: $datatable.=' ';
1497: }
1498: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1499: '" /></td>';
1500: }
1501: $$rowtotal += $itemcount;
1502: return $datatable;
1503: }
1504:
1505: sub logo_display_options {
1506: my ($img,$defaults,$designs) = @_;
1507: my $checkedon;
1508: if (ref($defaults) eq 'HASH') {
1509: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1510: if ($defaults->{'showlogo'}{$img}) {
1511: $checkedon = 'checked="checked" ';
1512: }
1513: }
1514: }
1515: if (ref($designs) eq 'HASH') {
1516: if (ref($designs->{'showlogo'}) eq 'HASH') {
1517: if (defined($designs->{'showlogo'}{$img})) {
1518: if ($designs->{'showlogo'}{$img} == 0) {
1519: $checkedon = '';
1520: } elsif ($designs->{'showlogo'}{$img} == 1) {
1521: $checkedon = 'checked="checked" ';
1522: }
1523: }
1524: }
1525: }
1526: return '<br /><label> <input type="checkbox" name="'.
1527: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1528: &mt('show').'</label>'."\n";
1529: }
1530:
1531: sub login_header_options {
1532: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1533: my $output = '';
1534: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1535: $output .= &mt('Text default(s):').'<br />';
1536: if (!$is_custom->{'textcol'}) {
1537: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1538: ' ';
1539: }
1540: if (!$is_custom->{'bgcol'}) {
1541: $output .= $choices->{'bgcol'}.': '.
1542: '<span id="css_'.$role.'_font" style="background-color: '.
1543: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1544: }
1545: $output .= '<br />';
1546: }
1547: $output .='<br />';
1548: return $output;
1549: }
1550:
1551: sub login_text_colors {
1552: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1553: my $color_menu = '<table border="0"><tr>';
1554: foreach my $item (@{$logintext}) {
1555: $color_menu .= '<td align="center">'.$choices->{$item};
1556: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1557: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1558: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1559: }
1560: $color_menu .= '</tr></table><br />';
1561: return $color_menu;
1562: }
1563:
1564: sub image_changes {
1565: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1566: my $output;
1567: if ($img eq 'login') {
1568: # suppress image for Log-in header
1569: } elsif (!$is_custom) {
1570: if ($img ne 'domlogo') {
1571: $output .= &mt('Default image:').'<br />';
1572: } else {
1573: $output .= &mt('Default in use:').'<br />';
1574: }
1575: }
1576: if ($img eq 'login') { # suppress image for Log-in header
1577: $output .= '<td>'.$logincolors;
1578: } else {
1579: if ($img_import) {
1580: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1581: }
1582: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1583: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1584: if ($is_custom) {
1585: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1586: '<input type="checkbox" name="'.
1587: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1588: '</label> '.&mt('Replace:').'</span><br />';
1589: } else {
1590: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1591: }
1592: }
1593: return $output;
1594: }
1595:
1596: sub print_quotas {
1597: my ($dom,$settings,$rowtotal,$action) = @_;
1598: my $context;
1599: if ($action eq 'quotas') {
1600: $context = 'tools';
1601: } else {
1602: $context = $action;
1603: }
1604: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1605: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1606: my $typecount = 0;
1607: my ($css_class,%titles);
1608: if ($context eq 'requestcourses') {
1609: @usertools = ('official','unofficial','community','textbook');
1610: @options =('norequest','approval','validate','autolimit');
1611: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1612: %titles = &courserequest_titles();
1613: } elsif ($context eq 'requestauthor') {
1614: @usertools = ('author');
1615: @options = ('norequest','approval','automatic');
1616: %titles = &authorrequest_titles();
1617: } else {
1618: @usertools = ('aboutme','blog','webdav','portfolio');
1619: %titles = &tool_titles();
1620: }
1621: if (ref($types) eq 'ARRAY') {
1622: foreach my $type (@{$types}) {
1623: my ($currdefquota,$currauthorquota);
1624: unless (($context eq 'requestcourses') ||
1625: ($context eq 'requestauthor')) {
1626: if (ref($settings) eq 'HASH') {
1627: if (ref($settings->{defaultquota}) eq 'HASH') {
1628: $currdefquota = $settings->{defaultquota}->{$type};
1629: } else {
1630: $currdefquota = $settings->{$type};
1631: }
1632: if (ref($settings->{authorquota}) eq 'HASH') {
1633: $currauthorquota = $settings->{authorquota}->{$type};
1634: }
1635: }
1636: }
1637: if (defined($usertypes->{$type})) {
1638: $typecount ++;
1639: $css_class = $typecount%2?' class="LC_odd_row"':'';
1640: $datatable .= '<tr'.$css_class.'>'.
1641: '<td>'.$usertypes->{$type}.'</td>'.
1642: '<td class="LC_left_item">';
1643: if ($context eq 'requestcourses') {
1644: $datatable .= '<table><tr>';
1645: }
1646: my %cell;
1647: foreach my $item (@usertools) {
1648: if ($context eq 'requestcourses') {
1649: my ($curroption,$currlimit);
1650: if (ref($settings) eq 'HASH') {
1651: if (ref($settings->{$item}) eq 'HASH') {
1652: $curroption = $settings->{$item}->{$type};
1653: if ($curroption =~ /^autolimit=(\d*)$/) {
1654: $currlimit = $1;
1655: }
1656: }
1657: }
1658: if (!$curroption) {
1659: $curroption = 'norequest';
1660: }
1661: $datatable .= '<th>'.$titles{$item}.'</th>';
1662: foreach my $option (@options) {
1663: my $val = $option;
1664: if ($option eq 'norequest') {
1665: $val = 0;
1666: }
1667: if ($option eq 'validate') {
1668: my $canvalidate = 0;
1669: if (ref($validations{$item}) eq 'HASH') {
1670: if ($validations{$item}{$type}) {
1671: $canvalidate = 1;
1672: }
1673: }
1674: next if (!$canvalidate);
1675: }
1676: my $checked = '';
1677: if ($option eq $curroption) {
1678: $checked = ' checked="checked"';
1679: } elsif ($option eq 'autolimit') {
1680: if ($curroption =~ /^autolimit/) {
1681: $checked = ' checked="checked"';
1682: }
1683: }
1684: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1685: '<input type="radio" name="crsreq_'.$item.
1686: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1687: $titles{$option}.'</label>';
1688: if ($option eq 'autolimit') {
1689: $cell{$item} .= ' <input type="text" name="crsreq_'.
1690: $item.'_limit_'.$type.'" size="1" '.
1691: 'value="'.$currlimit.'" />';
1692: }
1693: $cell{$item} .= '</span> ';
1694: if ($option eq 'autolimit') {
1695: $cell{$item} .= $titles{'unlimited'};
1696: }
1697: }
1698: } elsif ($context eq 'requestauthor') {
1699: my $curroption;
1700: if (ref($settings) eq 'HASH') {
1701: $curroption = $settings->{$type};
1702: }
1703: if (!$curroption) {
1704: $curroption = 'norequest';
1705: }
1706: foreach my $option (@options) {
1707: my $val = $option;
1708: if ($option eq 'norequest') {
1709: $val = 0;
1710: }
1711: my $checked = '';
1712: if ($option eq $curroption) {
1713: $checked = ' checked="checked"';
1714: }
1715: $datatable .= '<span class="LC_nobreak"><label>'.
1716: '<input type="radio" name="authorreq_'.$type.
1717: '" value="'.$val.'"'.$checked.' />'.
1718: $titles{$option}.'</label></span> ';
1719: }
1720: } else {
1721: my $checked = 'checked="checked" ';
1722: if (ref($settings) eq 'HASH') {
1723: if (ref($settings->{$item}) eq 'HASH') {
1724: if ($settings->{$item}->{$type} == 0) {
1725: $checked = '';
1726: } elsif ($settings->{$item}->{$type} == 1) {
1727: $checked = 'checked="checked" ';
1728: }
1729: }
1730: }
1731: $datatable .= '<span class="LC_nobreak"><label>'.
1732: '<input type="checkbox" name="'.$context.'_'.$item.
1733: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1734: '</label></span> ';
1735: }
1736: }
1737: if ($context eq 'requestcourses') {
1738: $datatable .= '</tr><tr>';
1739: foreach my $item (@usertools) {
1740: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1741: }
1742: $datatable .= '</tr></table>';
1743: }
1744: $datatable .= '</td>';
1745: unless (($context eq 'requestcourses') ||
1746: ($context eq 'requestauthor')) {
1747: $datatable .=
1748: '<td class="LC_right_item">'.
1749: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1750: '<input type="text" name="quota_'.$type.
1751: '" value="'.$currdefquota.
1752: '" size="5" /></span>'.(' ' x 2).
1753: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1754: '<input type="text" name="authorquota_'.$type.
1755: '" value="'.$currauthorquota.
1756: '" size="5" /></span></td>';
1757: }
1758: $datatable .= '</tr>';
1759: }
1760: }
1761: }
1762: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1763: $defaultquota = '20';
1764: $authorquota = '500';
1765: if (ref($settings) eq 'HASH') {
1766: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1767: $defaultquota = $settings->{'defaultquota'}->{'default'};
1768: } elsif (defined($settings->{'default'})) {
1769: $defaultquota = $settings->{'default'};
1770: }
1771: if (ref($settings->{'authorquota'}) eq 'HASH') {
1772: $authorquota = $settings->{'authorquota'}->{'default'};
1773: }
1774: }
1775: }
1776: $typecount ++;
1777: $css_class = $typecount%2?' class="LC_odd_row"':'';
1778: $datatable .= '<tr'.$css_class.'>'.
1779: '<td>'.$othertitle.'</td>'.
1780: '<td class="LC_left_item">';
1781: if ($context eq 'requestcourses') {
1782: $datatable .= '<table><tr>';
1783: }
1784: my %defcell;
1785: foreach my $item (@usertools) {
1786: if ($context eq 'requestcourses') {
1787: my ($curroption,$currlimit);
1788: if (ref($settings) eq 'HASH') {
1789: if (ref($settings->{$item}) eq 'HASH') {
1790: $curroption = $settings->{$item}->{'default'};
1791: if ($curroption =~ /^autolimit=(\d*)$/) {
1792: $currlimit = $1;
1793: }
1794: }
1795: }
1796: if (!$curroption) {
1797: $curroption = 'norequest';
1798: }
1799: $datatable .= '<th>'.$titles{$item}.'</th>';
1800: foreach my $option (@options) {
1801: my $val = $option;
1802: if ($option eq 'norequest') {
1803: $val = 0;
1804: }
1805: if ($option eq 'validate') {
1806: my $canvalidate = 0;
1807: if (ref($validations{$item}) eq 'HASH') {
1808: if ($validations{$item}{'default'}) {
1809: $canvalidate = 1;
1810: }
1811: }
1812: next if (!$canvalidate);
1813: }
1814: my $checked = '';
1815: if ($option eq $curroption) {
1816: $checked = ' checked="checked"';
1817: } elsif ($option eq 'autolimit') {
1818: if ($curroption =~ /^autolimit/) {
1819: $checked = ' checked="checked"';
1820: }
1821: }
1822: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1823: '<input type="radio" name="crsreq_'.$item.
1824: '_default" value="'.$val.'"'.$checked.' />'.
1825: $titles{$option}.'</label>';
1826: if ($option eq 'autolimit') {
1827: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1828: $item.'_limit_default" size="1" '.
1829: 'value="'.$currlimit.'" />';
1830: }
1831: $defcell{$item} .= '</span> ';
1832: if ($option eq 'autolimit') {
1833: $defcell{$item} .= $titles{'unlimited'};
1834: }
1835: }
1836: } elsif ($context eq 'requestauthor') {
1837: my $curroption;
1838: if (ref($settings) eq 'HASH') {
1839: $curroption = $settings->{'default'};
1840: }
1841: if (!$curroption) {
1842: $curroption = 'norequest';
1843: }
1844: foreach my $option (@options) {
1845: my $val = $option;
1846: if ($option eq 'norequest') {
1847: $val = 0;
1848: }
1849: my $checked = '';
1850: if ($option eq $curroption) {
1851: $checked = ' checked="checked"';
1852: }
1853: $datatable .= '<span class="LC_nobreak"><label>'.
1854: '<input type="radio" name="authorreq_default"'.
1855: ' value="'.$val.'"'.$checked.' />'.
1856: $titles{$option}.'</label></span> ';
1857: }
1858: } else {
1859: my $checked = 'checked="checked" ';
1860: if (ref($settings) eq 'HASH') {
1861: if (ref($settings->{$item}) eq 'HASH') {
1862: if ($settings->{$item}->{'default'} == 0) {
1863: $checked = '';
1864: } elsif ($settings->{$item}->{'default'} == 1) {
1865: $checked = 'checked="checked" ';
1866: }
1867: }
1868: }
1869: $datatable .= '<span class="LC_nobreak"><label>'.
1870: '<input type="checkbox" name="'.$context.'_'.$item.
1871: '" value="default" '.$checked.'/>'.$titles{$item}.
1872: '</label></span> ';
1873: }
1874: }
1875: if ($context eq 'requestcourses') {
1876: $datatable .= '</tr><tr>';
1877: foreach my $item (@usertools) {
1878: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1879: }
1880: $datatable .= '</tr></table>';
1881: }
1882: $datatable .= '</td>';
1883: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1884: $datatable .= '<td class="LC_right_item">'.
1885: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1886: '<input type="text" name="defaultquota" value="'.
1887: $defaultquota.'" size="5" /></span>'.(' ' x2).
1888: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1889: '<input type="text" name="authorquota" value="'.
1890: $authorquota.'" size="5" /></span></td>';
1891: }
1892: $datatable .= '</tr>';
1893: $typecount ++;
1894: $css_class = $typecount%2?' class="LC_odd_row"':'';
1895: $datatable .= '<tr'.$css_class.'>'.
1896: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1897: if ($context eq 'requestcourses') {
1898: $datatable .= &mt('(overrides affiliation, if set)').
1899: '</td>'.
1900: '<td class="LC_left_item">'.
1901: '<table><tr>';
1902: } else {
1903: $datatable .= &mt('(overrides affiliation, if checked)').
1904: '</td>'.
1905: '<td class="LC_left_item" colspan="2">'.
1906: '<br />';
1907: }
1908: my %advcell;
1909: foreach my $item (@usertools) {
1910: if ($context eq 'requestcourses') {
1911: my ($curroption,$currlimit);
1912: if (ref($settings) eq 'HASH') {
1913: if (ref($settings->{$item}) eq 'HASH') {
1914: $curroption = $settings->{$item}->{'_LC_adv'};
1915: if ($curroption =~ /^autolimit=(\d*)$/) {
1916: $currlimit = $1;
1917: }
1918: }
1919: }
1920: $datatable .= '<th>'.$titles{$item}.'</th>';
1921: my $checked = '';
1922: if ($curroption eq '') {
1923: $checked = ' checked="checked"';
1924: }
1925: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1926: '<input type="radio" name="crsreq_'.$item.
1927: '__LC_adv" value=""'.$checked.' />'.
1928: &mt('No override set').'</label></span> ';
1929: foreach my $option (@options) {
1930: my $val = $option;
1931: if ($option eq 'norequest') {
1932: $val = 0;
1933: }
1934: if ($option eq 'validate') {
1935: my $canvalidate = 0;
1936: if (ref($validations{$item}) eq 'HASH') {
1937: if ($validations{$item}{'_LC_adv'}) {
1938: $canvalidate = 1;
1939: }
1940: }
1941: next if (!$canvalidate);
1942: }
1943: my $checked = '';
1944: if ($val eq $curroption) {
1945: $checked = ' checked="checked"';
1946: } elsif ($option eq 'autolimit') {
1947: if ($curroption =~ /^autolimit/) {
1948: $checked = ' checked="checked"';
1949: }
1950: }
1951: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1952: '<input type="radio" name="crsreq_'.$item.
1953: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1954: $titles{$option}.'</label>';
1955: if ($option eq 'autolimit') {
1956: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1957: $item.'_limit__LC_adv" size="1" '.
1958: 'value="'.$currlimit.'" />';
1959: }
1960: $advcell{$item} .= '</span> ';
1961: if ($option eq 'autolimit') {
1962: $advcell{$item} .= $titles{'unlimited'};
1963: }
1964: }
1965: } elsif ($context eq 'requestauthor') {
1966: my $curroption;
1967: if (ref($settings) eq 'HASH') {
1968: $curroption = $settings->{'_LC_adv'};
1969: }
1970: my $checked = '';
1971: if ($curroption eq '') {
1972: $checked = ' checked="checked"';
1973: }
1974: $datatable .= '<span class="LC_nobreak"><label>'.
1975: '<input type="radio" name="authorreq__LC_adv"'.
1976: ' value=""'.$checked.' />'.
1977: &mt('No override set').'</label></span> ';
1978: foreach my $option (@options) {
1979: my $val = $option;
1980: if ($option eq 'norequest') {
1981: $val = 0;
1982: }
1983: my $checked = '';
1984: if ($val eq $curroption) {
1985: $checked = ' checked="checked"';
1986: }
1987: $datatable .= '<span class="LC_nobreak"><label>'.
1988: '<input type="radio" name="authorreq__LC_adv"'.
1989: ' value="'.$val.'"'.$checked.' />'.
1990: $titles{$option}.'</label></span> ';
1991: }
1992: } else {
1993: my $checked = 'checked="checked" ';
1994: if (ref($settings) eq 'HASH') {
1995: if (ref($settings->{$item}) eq 'HASH') {
1996: if ($settings->{$item}->{'_LC_adv'} == 0) {
1997: $checked = '';
1998: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1999: $checked = 'checked="checked" ';
2000: }
2001: }
2002: }
2003: $datatable .= '<span class="LC_nobreak"><label>'.
2004: '<input type="checkbox" name="'.$context.'_'.$item.
2005: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2006: '</label></span> ';
2007: }
2008: }
2009: if ($context eq 'requestcourses') {
2010: $datatable .= '</tr><tr>';
2011: foreach my $item (@usertools) {
2012: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
2013: }
2014: $datatable .= '</tr></table>';
2015: }
2016: $datatable .= '</td></tr>';
2017: $$rowtotal += $typecount;
2018: return $datatable;
2019: }
2020:
2021: sub print_requestmail {
2022: my ($dom,$action,$settings,$rowtotal) = @_;
2023: my ($now,$datatable,%currapp);
2024: $now = time;
2025: if (ref($settings) eq 'HASH') {
2026: if (ref($settings->{'notify'}) eq 'HASH') {
2027: if ($settings->{'notify'}{'approval'} ne '') {
2028: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
2029: }
2030: }
2031: }
2032: my $numinrow = 2;
2033: my $css_class;
2034: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
2035: my $text;
2036: if ($action eq 'requestcourses') {
2037: $text = &mt('Receive notification of course requests requiring approval');
2038: } elsif ($action eq 'requestauthor') {
2039: $text = &mt('Receive notification of Authoring Space requests requiring approval');
2040: } else {
2041: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
2042: }
2043: $datatable = '<tr'.$css_class.'>'.
2044: ' <td>'.$text.'</td>'.
2045: ' <td class="LC_left_item">';
2046: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
2047: $action.'notifyapproval',%currapp);
2048: if ($numdc > 0) {
2049: $datatable .= $table;
2050: } else {
2051: $datatable .= &mt('There are no active Domain Coordinators');
2052: }
2053: $datatable .='</td></tr>';
2054: $$rowtotal += $rows;
2055: return $datatable;
2056: }
2057:
2058: sub print_studentcode {
2059: my ($settings,$rowtotal) = @_;
2060: my $rownum = 0;
2061: my ($output,%current);
2062: my @crstypes = ('official','unofficial','community','textbook');
2063: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2064: foreach my $type (@crstypes) {
2065: $current{$type} = $settings->{'uniquecode'}{$type};
2066: }
2067: }
2068: $output .= '<tr>'.
2069: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2070: '<td class="LC_left_item">';
2071: foreach my $type (@crstypes) {
2072: my $check = ' ';
2073: if ($current{$type}) {
2074: $check = ' checked="checked" ';
2075: }
2076: $output .= '<span class="LC_nobreak"><label>'.
2077: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2078: &mt($type).'</label></span>'.(' 'x2).' ';
2079: }
2080: $output .= '</td></tr>';
2081: $$rowtotal ++;
2082: return $output;
2083: }
2084:
2085: sub print_textbookcourses {
2086: my ($dom,$settings,$rowtotal) = @_;
2087: my $rownum = 0;
2088: my $css_class;
2089: my $itemcount = 1;
2090: my $maxnum = 0;
2091: my $bookshash;
2092: if (ref($settings) eq 'HASH') {
2093: $bookshash = $settings->{'textbooks'};
2094: }
2095: my %ordered;
2096: if (ref($bookshash) eq 'HASH') {
2097: foreach my $item (keys(%{$bookshash})) {
2098: if (ref($bookshash->{$item}) eq 'HASH') {
2099: my $num = $bookshash->{$item}{'order'};
2100: $ordered{$num} = $item;
2101: }
2102: }
2103: }
2104: my $confname = $dom.'-domainconfig';
2105: my $switchserver = &check_switchserver($dom,$confname);
2106: $maxnum = scalar(keys(%ordered));
2107: my $datatable = &textbookcourses_javascript(\%ordered);
2108: if (keys(%ordered)) {
2109: my @items = sort { $a <=> $b } keys(%ordered);
2110: for (my $i=0; $i<@items; $i++) {
2111: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2112: my $key = $ordered{$items[$i]};
2113: my %coursehash=&Apache::lonnet::coursedescription($key);
2114: my $coursetitle = $coursehash{'description'};
2115: my ($subject,$title,$author,$image,$imgsrc,$cdom,$cnum);
2116: if (ref($bookshash->{$key}) eq 'HASH') {
2117: $subject = $bookshash->{$key}->{'subject'};
2118: $title = $bookshash->{$key}->{'title'};
2119: $author = $bookshash->{$key}->{'author'};
2120: $image = $bookshash->{$key}->{'image'};
2121: if ($image ne '') {
2122: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2123: my $imagethumb = "$path/tn-".$imagefile;
2124: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2125: }
2126: }
2127: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$key'".');"';
2128: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
2129: .'<select name="'.$key.'"'.$chgstr.'>';
2130: for (my $k=0; $k<=$maxnum; $k++) {
2131: my $vpos = $k+1;
2132: my $selstr;
2133: if ($k == $i) {
2134: $selstr = ' selected="selected" ';
2135: }
2136: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2137: }
2138: $datatable .= '</select>'.(' 'x2).
2139: '<label><input type="checkbox" name="book_del" value="'.$key.'" />'.
2140: &mt('Delete?').'</label></span></td>'.
2141: '<td colspan="2">'.
2142: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="book_subject_'.$i.'" value="'.$subject.'" /></span> '.
2143: (' 'x2).
2144: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="book_title_'.$i.'" value="'.$title.'" /></span> '.
2145: (' 'x2).
2146: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="book_author_'.$i.'" value="'.$author.'" /></span> '.
2147: (' 'x2).
2148: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2149: if ($image) {
2150: $datatable .= '<span class="LC_nobreak">'.
2151: $imgsrc.
2152: '<label><input type="checkbox" name="book_image_del"'.
2153: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2154: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2155: }
2156: if ($switchserver) {
2157: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2158: } else {
2159: $datatable .= '<input type="file" name="book_image_'.$i.'" value="" />';
2160: }
2161: $datatable .= '<input type="hidden" name="book_id_'.$i.'" value="'.$key.'" /></span> '.
2162: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2163: $coursetitle.'</span></td></tr>'."\n";
2164: $itemcount ++;
2165: }
2166: }
2167: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2168: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'addbook_pos'".');"';
2169: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
2170: '<input type="hidden" name="book_maxnum" value="'.$maxnum.'" />'."\n".
2171: '<select name="addbook_pos"'.$chgstr.'>';
2172: for (my $k=0; $k<$maxnum+1; $k++) {
2173: my $vpos = $k+1;
2174: my $selstr;
2175: if ($k == $maxnum) {
2176: $selstr = ' selected="selected" ';
2177: }
2178: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2179: }
2180: $datatable .= '</select> '."\n".
2181: '<input type="checkbox" name="addbook" value="1" />'.&mt('Add').'</td>'."\n".
2182: '<td colspan="2">'.
2183: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="addbook_subject" value="" /></span> '."\n".
2184: (' 'x2).
2185: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="addbook_title" value="" /></span> '."\n".
2186: (' 'x2).
2187: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="addbook_author" value="" /></span> '."\n".
2188: (' 'x2).
2189: '<span class="LC_nobreak">'.&mt('Image:').' ';
2190: if ($switchserver) {
2191: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2192: } else {
2193: $datatable .= '<input type="file" name="addbook_image" value="" />';
2194: }
2195: $datatable .= '</span>'."\n".
2196: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2197: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'addbook_cdom').
2198: '<input type="text" size="25" name="addbook_cnum" value="" />'.
2199: &Apache::loncommon::selectcourse_link
2200: ('display','addbook_cnum','addbook_cdom',undef,undef,undef,'Course');
2201: '</span></td>'."\n".
2202: '</tr>'."\n";
2203: $itemcount ++;
2204: return $datatable;
2205: }
2206:
2207: sub textbookcourses_javascript {
2208: my ($textbooks) = @_;
2209: return unless(ref($textbooks) eq 'HASH');
2210: my $num = scalar(keys(%{$textbooks}));
2211: my @jsarray;
2212: foreach my $item (sort {$a <=> $b } (keys(%{$textbooks}))) {
2213: push(@jsarray,$textbooks->{$item});
2214: }
2215: my $jstext = ' var textbooks = Array('."'".join("','",@jsarray)."'".');'."\n";
2216: return <<"ENDSCRIPT";
2217: <script type="text/javascript">
2218: // <![CDATA[
2219: function reorderBooks(form,item) {
2220: var changedVal;
2221: $jstext
2222: var newpos = 'addbook_pos';
2223: var current = new Array;
2224: var maxh = 1 + $num;
2225: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2226: if (item == newpos) {
2227: changedVal = newitemVal;
2228: } else {
2229: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2230: current[newitemVal] = newpos;
2231: }
2232: for (var i=0; i<textbooks.length; i++) {
2233: var elementName = textbooks[i];
2234: if (elementName != item) {
2235: if (form.elements[elementName]) {
2236: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2237: current[currVal] = elementName;
2238: }
2239: }
2240: }
2241: var oldVal;
2242: for (var j=0; j<maxh; j++) {
2243: if (current[j] == undefined) {
2244: oldVal = j;
2245: }
2246: }
2247: if (oldVal < changedVal) {
2248: for (var k=oldVal+1; k<=changedVal ; k++) {
2249: var elementName = current[k];
2250: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2251: }
2252: } else {
2253: for (var k=changedVal; k<oldVal; k++) {
2254: var elementName = current[k];
2255: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2256: }
2257: }
2258: return;
2259: }
2260:
2261: // ]]>
2262: </script>
2263:
2264: ENDSCRIPT
2265: }
2266:
2267: sub print_autoenroll {
2268: my ($dom,$settings,$rowtotal) = @_;
2269: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
2270: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
2271: if (ref($settings) eq 'HASH') {
2272: if (exists($settings->{'run'})) {
2273: if ($settings->{'run'} eq '0') {
2274: $runoff = ' checked="checked" ';
2275: $runon = ' ';
2276: } else {
2277: $runon = ' checked="checked" ';
2278: $runoff = ' ';
2279: }
2280: } else {
2281: if ($autorun) {
2282: $runon = ' checked="checked" ';
2283: $runoff = ' ';
2284: } else {
2285: $runoff = ' checked="checked" ';
2286: $runon = ' ';
2287: }
2288: }
2289: if (exists($settings->{'co-owners'})) {
2290: if ($settings->{'co-owners'} eq '0') {
2291: $coownersoff = ' checked="checked" ';
2292: $coownerson = ' ';
2293: } else {
2294: $coownerson = ' checked="checked" ';
2295: $coownersoff = ' ';
2296: }
2297: } else {
2298: $coownersoff = ' checked="checked" ';
2299: $coownerson = ' ';
2300: }
2301: if (exists($settings->{'sender_domain'})) {
2302: $defdom = $settings->{'sender_domain'};
2303: }
2304: } else {
2305: if ($autorun) {
2306: $runon = ' checked="checked" ';
2307: $runoff = ' ';
2308: } else {
2309: $runoff = ' checked="checked" ';
2310: $runon = ' ';
2311: }
2312: }
2313: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
2314: my $notif_sender;
2315: if (ref($settings) eq 'HASH') {
2316: $notif_sender = $settings->{'sender_uname'};
2317: }
2318: my $datatable='<tr class="LC_odd_row">'.
2319: '<td>'.&mt('Auto-enrollment active?').'</td>'.
2320: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2321: '<input type="radio" name="autoenroll_run"'.
2322: $runon.' value="1" />'.&mt('Yes').'</label> '.
2323: '<label><input type="radio" name="autoenroll_run"'.
2324: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
2325: '</tr><tr>'.
2326: '<td>'.&mt('Notification messages - sender').
2327: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
2328: &mt('username').': '.
2329: '<input type="text" name="sender_uname" value="'.
2330: $notif_sender.'" size="10" /> '.&mt('domain').
2331: ': '.$domform.'</span></td></tr>'.
2332: '<tr class="LC_odd_row">'.
2333: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2334: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2335: '<input type="radio" name="autoassign_coowners"'.
2336: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2337: '<label><input type="radio" name="autoassign_coowners"'.
2338: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2339: '</tr>';
2340: $$rowtotal += 3;
2341: return $datatable;
2342: }
2343:
2344: sub print_autoupdate {
2345: my ($position,$dom,$settings,$rowtotal) = @_;
2346: my $datatable;
2347: if ($position eq 'top') {
2348: my $updateon = ' ';
2349: my $updateoff = ' checked="checked" ';
2350: my $classlistson = ' ';
2351: my $classlistsoff = ' checked="checked" ';
2352: if (ref($settings) eq 'HASH') {
2353: if ($settings->{'run'} eq '1') {
2354: $updateon = $updateoff;
2355: $updateoff = ' ';
2356: }
2357: if ($settings->{'classlists'} eq '1') {
2358: $classlistson = $classlistsoff;
2359: $classlistsoff = ' ';
2360: }
2361: }
2362: my %title = (
2363: run => 'Auto-update active?',
2364: classlists => 'Update information in classlists?',
2365: );
2366: $datatable = '<tr class="LC_odd_row">'.
2367: '<td>'.&mt($title{'run'}).'</td>'.
2368: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2369: '<input type="radio" name="autoupdate_run"'.
2370: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2371: '<label><input type="radio" name="autoupdate_run"'.
2372: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
2373: '</tr><tr>'.
2374: '<td>'.&mt($title{'classlists'}).'</td>'.
2375: '<td class="LC_right_item"><span class="LC_nobreak">'.
2376: '<label><input type="radio" name="classlists"'.
2377: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2378: '<label><input type="radio" name="classlists"'.
2379: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
2380: '</tr>';
2381: $$rowtotal += 2;
2382: } elsif ($position eq 'middle') {
2383: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2384: my $numinrow = 3;
2385: my $locknamesettings;
2386: $datatable .= &insttypes_row($settings,$types,$usertypes,
2387: $dom,$numinrow,$othertitle,
2388: 'lockablenames');
2389: $$rowtotal ++;
2390: } else {
2391: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2392: my @fields = ('lastname','firstname','middlename','generation',
2393: 'permanentemail','id');
2394: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
2395: my $numrows = 0;
2396: if (ref($types) eq 'ARRAY') {
2397: if (@{$types} > 0) {
2398: $datatable =
2399: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2400: \@fields,$types,\$numrows);
2401: $$rowtotal += @{$types};
2402: }
2403: }
2404: $datatable .=
2405: &usertype_update_row($settings,{'default' => $othertitle},
2406: \%fieldtitles,\@fields,['default'],
2407: \$numrows);
2408: $$rowtotal ++;
2409: }
2410: return $datatable;
2411: }
2412:
2413: sub print_autocreate {
2414: my ($dom,$settings,$rowtotal) = @_;
2415: my (%createon,%createoff,%currhash);
2416: my @types = ('xml','req');
2417: if (ref($settings) eq 'HASH') {
2418: foreach my $item (@types) {
2419: $createoff{$item} = ' checked="checked" ';
2420: $createon{$item} = ' ';
2421: if (exists($settings->{$item})) {
2422: if ($settings->{$item}) {
2423: $createon{$item} = ' checked="checked" ';
2424: $createoff{$item} = ' ';
2425: }
2426: }
2427: }
2428: if ($settings->{'xmldc'} ne '') {
2429: $currhash{$settings->{'xmldc'}} = 1;
2430: }
2431: } else {
2432: foreach my $item (@types) {
2433: $createoff{$item} = ' checked="checked" ';
2434: $createon{$item} = ' ';
2435: }
2436: }
2437: $$rowtotal += 2;
2438: my $numinrow = 2;
2439: my $datatable='<tr class="LC_odd_row">'.
2440: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2441: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2442: '<input type="radio" name="autocreate_xml"'.
2443: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2444: '<label><input type="radio" name="autocreate_xml"'.
2445: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2446: '</td></tr><tr>'.
2447: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2448: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2449: '<input type="radio" name="autocreate_req"'.
2450: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2451: '<label><input type="radio" name="autocreate_req"'.
2452: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
2453: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2454: 'autocreate_xmldc',%currhash);
2455: if ($numdc > 1) {
2456: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2457: &mt('Course creation processed as: (choose Dom. Coord.)').
2458: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
2459: } else {
2460: $datatable .= $dctable.'</td></tr>';
2461: }
2462: $$rowtotal += $rows;
2463: return $datatable;
2464: }
2465:
2466: sub print_directorysrch {
2467: my ($dom,$settings,$rowtotal) = @_;
2468: my $srchon = ' ';
2469: my $srchoff = ' checked="checked" ';
2470: my ($exacton,$containson,$beginson);
2471: my $localon = ' ';
2472: my $localoff = ' checked="checked" ';
2473: if (ref($settings) eq 'HASH') {
2474: if ($settings->{'available'} eq '1') {
2475: $srchon = $srchoff;
2476: $srchoff = ' ';
2477: }
2478: if ($settings->{'localonly'} eq '1') {
2479: $localon = $localoff;
2480: $localoff = ' ';
2481: }
2482: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2483: foreach my $type (@{$settings->{'searchtypes'}}) {
2484: if ($type eq 'exact') {
2485: $exacton = ' checked="checked" ';
2486: } elsif ($type eq 'contains') {
2487: $containson = ' checked="checked" ';
2488: } elsif ($type eq 'begins') {
2489: $beginson = ' checked="checked" ';
2490: }
2491: }
2492: } else {
2493: if ($settings->{'searchtypes'} eq 'exact') {
2494: $exacton = ' checked="checked" ';
2495: } elsif ($settings->{'searchtypes'} eq 'contains') {
2496: $containson = ' checked="checked" ';
2497: } elsif ($settings->{'searchtypes'} eq 'specify') {
2498: $exacton = ' checked="checked" ';
2499: $containson = ' checked="checked" ';
2500: }
2501: }
2502: }
2503: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2504: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2505:
2506: my $numinrow = 4;
2507: my $cansrchrow = 0;
2508: my $datatable='<tr class="LC_odd_row">'.
2509: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
2510: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2511: '<input type="radio" name="dirsrch_available"'.
2512: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2513: '<label><input type="radio" name="dirsrch_available"'.
2514: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2515: '</tr><tr>'.
2516: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
2517: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2518: '<input type="radio" name="dirsrch_localonly"'.
2519: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2520: '<label><input type="radio" name="dirsrch_localonly"'.
2521: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
2522: '</tr>';
2523: $$rowtotal += 2;
2524: if (ref($usertypes) eq 'HASH') {
2525: if (keys(%{$usertypes}) > 0) {
2526: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2527: $numinrow,$othertitle,'cansearch');
2528: $cansrchrow = 1;
2529: }
2530: }
2531: if ($cansrchrow) {
2532: $$rowtotal ++;
2533: $datatable .= '<tr>';
2534: } else {
2535: $datatable .= '<tr class="LC_odd_row">';
2536: }
2537: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2538: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2539: foreach my $title (@{$titleorder}) {
2540: if (defined($searchtitles->{$title})) {
2541: my $check = ' ';
2542: if (ref($settings) eq 'HASH') {
2543: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2544: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2545: $check = ' checked="checked" ';
2546: }
2547: }
2548: }
2549: $datatable .= '<td class="LC_left_item">'.
2550: '<span class="LC_nobreak"><label>'.
2551: '<input type="checkbox" name="searchby" '.
2552: 'value="'.$title.'"'.$check.'/>'.
2553: $searchtitles->{$title}.'</label></span></td>';
2554: }
2555: }
2556: $datatable .= '</tr></table></td></tr>';
2557: $$rowtotal ++;
2558: if ($cansrchrow) {
2559: $datatable .= '<tr class="LC_odd_row">';
2560: } else {
2561: $datatable .= '<tr>';
2562: }
2563: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
2564: '<td class="LC_left_item" colspan="2">'.
2565: '<span class="LC_nobreak"><label>'.
2566: '<input type="checkbox" name="searchtypes" '.
2567: $exacton.' value="exact" />'.&mt('Exact match').
2568: '</label> '.
2569: '<label><input type="checkbox" name="searchtypes" '.
2570: $beginson.' value="begins" />'.&mt('Begins with').
2571: '</label> '.
2572: '<label><input type="checkbox" name="searchtypes" '.
2573: $containson.' value="contains" />'.&mt('Contains').
2574: '</label></span></td></tr>';
2575: $$rowtotal ++;
2576: return $datatable;
2577: }
2578:
2579: sub print_contacts {
2580: my ($dom,$settings,$rowtotal) = @_;
2581: my $datatable;
2582: my @contacts = ('adminemail','supportemail');
2583: my (%checked,%to,%otheremails,%bccemails);
2584: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
2585: 'requestsmail','updatesmail','idconflictsmail');
2586: foreach my $type (@mailings) {
2587: $otheremails{$type} = '';
2588: }
2589: $bccemails{'helpdeskmail'} = '';
2590: if (ref($settings) eq 'HASH') {
2591: foreach my $item (@contacts) {
2592: if (exists($settings->{$item})) {
2593: $to{$item} = $settings->{$item};
2594: }
2595: }
2596: foreach my $type (@mailings) {
2597: if (exists($settings->{$type})) {
2598: if (ref($settings->{$type}) eq 'HASH') {
2599: foreach my $item (@contacts) {
2600: if ($settings->{$type}{$item}) {
2601: $checked{$type}{$item} = ' checked="checked" ';
2602: }
2603: }
2604: $otheremails{$type} = $settings->{$type}{'others'};
2605: if ($type eq 'helpdeskmail') {
2606: $bccemails{$type} = $settings->{$type}{'bcc'};
2607: }
2608: }
2609: } elsif ($type eq 'lonstatusmail') {
2610: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2611: }
2612: }
2613: } else {
2614: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2615: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2616: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2617: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
2618: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2619: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2620: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
2621: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
2622: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
2623: }
2624: my ($titles,$short_titles) = &contact_titles();
2625: my $rownum = 0;
2626: my $css_class;
2627: foreach my $item (@contacts) {
2628: $css_class = $rownum%2?' class="LC_odd_row"':'';
2629: $datatable .= '<tr'.$css_class.'>'.
2630: '<td><span class="LC_nobreak">'.$titles->{$item}.
2631: '</span></td><td class="LC_right_item">'.
2632: '<input type="text" name="'.$item.'" value="'.
2633: $to{$item}.'" /></td></tr>';
2634: $rownum ++;
2635: }
2636: foreach my $type (@mailings) {
2637: $css_class = $rownum%2?' class="LC_odd_row"':'';
2638: $datatable .= '<tr'.$css_class.'>'.
2639: '<td><span class="LC_nobreak">'.
2640: $titles->{$type}.': </span></td>'.
2641: '<td class="LC_left_item">'.
2642: '<span class="LC_nobreak">';
2643: foreach my $item (@contacts) {
2644: $datatable .= '<label>'.
2645: '<input type="checkbox" name="'.$type.'"'.
2646: $checked{$type}{$item}.
2647: ' value="'.$item.'" />'.$short_titles->{$item}.
2648: '</label> ';
2649: }
2650: $datatable .= '</span><br />'.&mt('Others').': '.
2651: '<input type="text" name="'.$type.'_others" '.
2652: 'value="'.$otheremails{$type}.'" />';
2653: if ($type eq 'helpdeskmail') {
2654: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
2655: '<input type="text" name="'.$type.'_bcc" '.
2656: 'value="'.$bccemails{$type}.'" />';
2657: }
2658: $datatable .= '</td></tr>'."\n";
2659: $rownum ++;
2660: }
2661: my %choices;
2662: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2663: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2664: &mt('LON-CAPA core group - MSU'),600,500));
2665: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2666: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2667: &mt('LON-CAPA core group - MSU'),600,500));
2668: my @toggles = ('reporterrors','reportupdates');
2669: my %defaultchecked = ('reporterrors' => 'on',
2670: 'reportupdates' => 'on');
2671: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2672: \%choices,$rownum);
2673: $datatable .= $reports;
2674: $$rowtotal += $rownum;
2675: return $datatable;
2676: }
2677:
2678: sub print_helpsettings {
2679: my ($dom,$confname,$settings,$rowtotal) = @_;
2680: my ($datatable,$itemcount);
2681: $itemcount = 1;
2682: my (%choices,%defaultchecked,@toggles);
2683: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2684: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2685: &mt('LON-CAPA bug tracker'),600,500));
2686: %defaultchecked = ('submitbugs' => 'on');
2687: @toggles = ('submitbugs',);
2688:
2689: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2690: \%choices,$itemcount);
2691: return $datatable;
2692: }
2693:
2694: sub radiobutton_prefs {
2695: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
2696: $additional) = @_;
2697: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2698: (ref($choices) eq 'HASH'));
2699:
2700: my (%checkedon,%checkedoff,$datatable,$css_class);
2701:
2702: foreach my $item (@{$toggles}) {
2703: if ($defaultchecked->{$item} eq 'on') {
2704: $checkedon{$item} = ' checked="checked" ';
2705: $checkedoff{$item} = ' ';
2706: } elsif ($defaultchecked->{$item} eq 'off') {
2707: $checkedoff{$item} = ' checked="checked" ';
2708: $checkedon{$item} = ' ';
2709: }
2710: }
2711: if (ref($settings) eq 'HASH') {
2712: foreach my $item (@{$toggles}) {
2713: if ($settings->{$item} eq '1') {
2714: $checkedon{$item} = ' checked="checked" ';
2715: $checkedoff{$item} = ' ';
2716: } elsif ($settings->{$item} eq '0') {
2717: $checkedoff{$item} = ' checked="checked" ';
2718: $checkedon{$item} = ' ';
2719: }
2720: }
2721: }
2722: if ($onclick) {
2723: $onclick = ' onclick="'.$onclick.'"';
2724: }
2725: foreach my $item (@{$toggles}) {
2726: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2727: $datatable .=
2728: '<tr'.$css_class.'><td valign="top">'.
2729: '<span class="LC_nobreak">'.$choices->{$item}.
2730: '</span></td>'.
2731: '<td class="LC_right_item"><span class="LC_nobreak">'.
2732: '<label><input type="radio" name="'.
2733: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
2734: '</label> <label><input type="radio" name="'.$item.'" '.
2735: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2736: '</span>'.$additional.
2737: '</td>'.
2738: '</tr>';
2739: $itemcount ++;
2740: }
2741: return ($datatable,$itemcount);
2742: }
2743:
2744: sub print_coursedefaults {
2745: my ($position,$dom,$settings,$rowtotal) = @_;
2746: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
2747: my $itemcount = 1;
2748: my %choices = &Apache::lonlocal::texthash (
2749: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
2750: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
2751: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2752: coursecredits => 'Credits can be specified for courses',
2753: );
2754: my %staticdefaults = (
2755: anonsurvey_threshold => 10,
2756: uploadquota => 500,
2757: );
2758: if ($position eq 'top') {
2759: %defaultchecked = ('canuse_pdfforms' => 'off');
2760: @toggles = ('canuse_pdfforms');
2761: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2762: \%choices,$itemcount);
2763: } else {
2764: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2765: my ($currdefresponder,$def_official_credits,$def_unofficial_credits,$def_textbook_credits,
2766: %curruploadquota);
2767: my $currusecredits = 0;
2768: my @types = ('official','unofficial','community','textbook');
2769: if (ref($settings) eq 'HASH') {
2770: $currdefresponder = $settings->{'anonsurvey_threshold'};
2771: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2772: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2773: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2774: }
2775: }
2776: if (ref($settings->{'coursecredits'}) eq 'HASH') {
2777: $def_official_credits = $settings->{'coursecredits'}->{'official'};
2778: $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
2779: $def_textbook_credits = $settings->{'coursecredits'}->{'textbook'};
2780: if (($def_official_credits ne '') || ($def_unofficial_credits ne '') ||
2781: ($def_textbook_credits ne '')) {
2782: $currusecredits = 1;
2783: }
2784: }
2785: }
2786: if (!$currdefresponder) {
2787: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
2788: } elsif ($currdefresponder < 1) {
2789: $currdefresponder = 1;
2790: }
2791: foreach my $type (@types) {
2792: if ($curruploadquota{$type} eq '') {
2793: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
2794: }
2795: }
2796: $datatable .=
2797: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2798: $choices{'anonsurvey_threshold'}.
2799: '</span></td>'.
2800: '<td class="LC_right_item"><span class="LC_nobreak">'.
2801: '<input type="text" name="anonsurvey_threshold"'.
2802: ' value="'.$currdefresponder.'" size="5" /></span>'.
2803: '</td></tr>'."\n";
2804: $itemcount ++;
2805: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2806: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2807: $choices{'uploadquota'}.
2808: '</span></td>'.
2809: '<td align="right" class="LC_right_item">'.
2810: '<table><tr>';
2811: foreach my $type (@types) {
2812: $datatable .= '<td align="center">'.&mt($type).'<br />'.
2813: '<input type="text" name="uploadquota_'.$type.'"'.
2814: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
2815: }
2816: $datatable .= '</tr></table></td></tr>'."\n";
2817: $itemcount ++;
2818: my $onclick = "toggleDisplay(this.form,'credits');";
2819: my $display = 'none';
2820: if ($currusecredits) {
2821: $display = 'block';
2822: }
2823: my $additional = '<div id="credits" style="display: '.$display.'">'.
2824: '<span class="LC_nobreak">'.
2825: &mt('Default credits for official courses [_1]',
2826: '<input type="text" name="official_credits" value="'.
2827: $def_official_credits.'" size="3" />').
2828: '</span><br />'.
2829: '<span class="LC_nobreak">'.
2830: &mt('Default credits for unofficial courses [_1]',
2831: '<input type="text" name="unofficial_credits" value="'.
2832: $def_unofficial_credits.'" size="3" />').
2833: '</span><br />'.
2834: '<span class="LC_nobreak">'.
2835: &mt('Default credits for textbook courses [_1]',
2836: '<input type="text" name="textbook_credits" value="'.
2837: $def_textbook_credits.'" size="3" />').
2838: '</span></div>'."\n";
2839: %defaultchecked = ('coursecredits' => 'off');
2840: @toggles = ('coursecredits');
2841: my $current = {
2842: 'coursecredits' => $currusecredits,
2843: };
2844: (my $table,$itemcount) =
2845: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
2846: \%choices,$itemcount,$onclick,$additional);
2847: $datatable .= $table;
2848: $itemcount ++;
2849: }
2850: $$rowtotal += $itemcount;
2851: return $datatable;
2852: }
2853:
2854: sub print_selfenrollment {
2855: my ($position,$dom,$settings,$rowtotal) = @_;
2856: my ($css_class,$datatable);
2857: my $itemcount = 1;
2858: my @types = ('official','unofficial','community','textbook');
2859: if (($position eq 'top') || ($position eq 'middle')) {
2860: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
2861: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
2862: my @rows;
2863: my $key;
2864: if ($position eq 'top') {
2865: $key = 'admin';
2866: if (ref($rowsref) eq 'ARRAY') {
2867: @rows = @{$rowsref};
2868: }
2869: } elsif ($position eq 'middle') {
2870: $key = 'default';
2871: @rows = ('types','registered','approval','limit');
2872: }
2873: foreach my $row (@rows) {
2874: if (defined($titlesref->{$row})) {
2875: $itemcount ++;
2876: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2877: $datatable .= '<tr'.$css_class.'>'.
2878: '<td>'.$titlesref->{$row}.'</td>'.
2879: '<td class="LC_left_item">'.
2880: '<table><tr>';
2881: my (%current,%currentcap);
2882: if (ref($settings) eq 'HASH') {
2883: if (ref($settings->{$key}) eq 'HASH') {
2884: foreach my $type (@types) {
2885: if (ref($settings->{$key}->{$type}) eq 'HASH') {
2886: $current{$type} = $settings->{$key}->{$type}->{$row};
2887: }
2888: if (($row eq 'limit') && ($key eq 'default')) {
2889: if (ref($settings->{$key}->{$type}) eq 'HASH') {
2890: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
2891: }
2892: }
2893: }
2894: }
2895: }
2896: my %roles = (
2897: '0' => &Apache::lonnet::plaintext('dc'),
2898: );
2899:
2900: foreach my $type (@types) {
2901: unless (($row eq 'registered') && ($key eq 'default')) {
2902: $datatable .= '<th>'.&mt($type).'</th>';
2903: }
2904: }
2905: unless (($row eq 'registered') && ($key eq 'default')) {
2906: $datatable .= '</tr><tr>';
2907: }
2908: foreach my $type (@types) {
2909: if ($type eq 'community') {
2910: $roles{'1'} = &mt('Community personnel');
2911: } else {
2912: $roles{'1'} = &mt('Course personnel');
2913: }
2914: $datatable .= '<td style="vertical-align: top">';
2915: if ($position eq 'top') {
2916: my %checked;
2917: if ($current{$type} eq '0') {
2918: $checked{'0'} = ' checked="checked"';
2919: } else {
2920: $checked{'1'} = ' checked="checked"';
2921: }
2922: foreach my $role ('1','0') {
2923: $datatable .= '<span class="LC_nobreak"><label>'.
2924: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
2925: 'value="'.$role.'"'.$checked{$role}.' />'.
2926: $roles{$role}.'</label></span> ';
2927: }
2928: } else {
2929: if ($row eq 'types') {
2930: my %checked;
2931: if ($current{$type} =~ /^(all|dom)$/) {
2932: $checked{$1} = ' checked="checked"';
2933: } else {
2934: $checked{''} = ' checked="checked"';
2935: }
2936: foreach my $val ('','dom','all') {
2937: $datatable .= '<span class="LC_nobreak"><label>'.
2938: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
2939: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
2940: }
2941: } elsif ($row eq 'registered') {
2942: my %checked;
2943: if ($current{$type} eq '1') {
2944: $checked{'1'} = ' checked="checked"';
2945: } else {
2946: $checked{'0'} = ' checked="checked"';
2947: }
2948: foreach my $val ('0','1') {
2949: $datatable .= '<span class="LC_nobreak"><label>'.
2950: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
2951: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
2952: }
2953: } elsif ($row eq 'approval') {
2954: my %checked;
2955: if ($current{$type} =~ /^([12])$/) {
2956: $checked{$1} = ' checked="checked"';
2957: } else {
2958: $checked{'0'} = ' checked="checked"';
2959: }
2960: for my $val (0..2) {
2961: $datatable .= '<span class="LC_nobreak"><label>'.
2962: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
2963: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
2964: }
2965: } elsif ($row eq 'limit') {
2966: my %checked;
2967: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
2968: $checked{$1} = ' checked="checked"';
2969: } else {
2970: $checked{'none'} = ' checked="checked"';
2971: }
2972: my $cap;
2973: if ($currentcap{$type} =~ /^\d+$/) {
2974: $cap = $currentcap{$type};
2975: }
2976: foreach my $val ('none','allstudents','selfenrolled') {
2977: $datatable .= '<span class="LC_nobreak"><label>'.
2978: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
2979: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
2980: }
2981: $datatable .= '<br />'.
2982: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
2983: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
2984: '</span>';
2985: }
2986: }
2987: $datatable .= '</td>';
2988: }
2989: $datatable .= '</tr>';
2990: }
2991: $datatable .= '</table></td></tr>';
2992: }
2993: } elsif ($position eq 'bottom') {
2994: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
2995: }
2996: $$rowtotal += $itemcount;
2997: return $datatable;
2998: }
2999:
3000: sub print_validation_rows {
3001: my ($caller,$dom,$settings,$rowtotal) = @_;
3002: my ($itemsref,$namesref,$fieldsref);
3003: if ($caller eq 'selfenroll') {
3004: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3005: } elsif ($caller eq 'requestcourses') {
3006: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3007: }
3008: my %currvalidation;
3009: if (ref($settings) eq 'HASH') {
3010: if (ref($settings->{'validation'}) eq 'HASH') {
3011: %currvalidation = %{$settings->{'validation'}};
3012: }
3013: }
3014: my $datatable;
3015: my $itemcount = 0;
3016: foreach my $item (@{$itemsref}) {
3017: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3018: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3019: $namesref->{$item}.
3020: '</span></td>'.
3021: '<td class="LC_left_item">';
3022: if (($item eq 'url') || ($item eq 'button')) {
3023: $datatable .= '<span class="LC_nobreak">'.
3024: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3025: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3026: } elsif ($item eq 'fields') {
3027: my @currfields;
3028: if (ref($currvalidation{$item}) eq 'ARRAY') {
3029: @currfields = @{$currvalidation{$item}};
3030: }
3031: foreach my $field (@{$fieldsref}) {
3032: my $check = '';
3033: if (grep(/^\Q$field\E$/,@currfields)) {
3034: $check = ' checked="checked"';
3035: }
3036: $datatable .= '<span class="LC_nobreak"><label>'.
3037: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3038: ' value="'.$field.'"'.$check.' />'.$field.
3039: '</label></span> ';
3040: }
3041: } elsif ($item eq 'markup') {
3042: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
3043: $currvalidation{$item}.
3044: '</textarea>';
3045: }
3046: $datatable .= '</td></tr>'."\n";
3047: if (ref($rowtotal)) {
3048: $itemcount ++;
3049: }
3050: }
3051: if ($caller eq 'requestcourses') {
3052: my %currhash;
3053: if (ref($settings->{'validation'}) eq 'HASH') {
3054: if ($settings->{'validation'}{'dc'} ne '') {
3055: $currhash{$settings->{'validation'}{'dc'}} = 1;
3056: }
3057: }
3058: my $numinrow = 2;
3059: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3060: 'validationdc',%currhash);
3061: if ($numdc > 1) {
3062: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
3063: &mt('Course creation processed as: (choose Dom. Coord.)').
3064: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
3065: } else {
3066: $datatable .= $dctable.'</td></tr>';
3067: }
3068: $itemcount ++;
3069: }
3070: if (ref($rowtotal)) {
3071: $$rowtotal += $itemcount;
3072: }
3073: return $datatable;
3074: }
3075:
3076: sub print_usersessions {
3077: my ($position,$dom,$settings,$rowtotal) = @_;
3078: my ($css_class,$datatable,%checked,%choices);
3079: my (%by_ip,%by_location,@intdoms);
3080: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
3081:
3082: my @alldoms = &Apache::lonnet::all_domains();
3083: my %serverhomes = %Apache::lonnet::serverhomeIDs;
3084: my %servers = &Apache::lonnet::internet_dom_servers($dom);
3085: my %altids = &id_for_thisdom(%servers);
3086: my $itemcount = 1;
3087: if ($position eq 'top') {
3088: if (keys(%serverhomes) > 1) {
3089: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
3090: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
3091: } else {
3092: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
3093: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
3094: }
3095: } else {
3096: if (keys(%by_location) == 0) {
3097: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
3098: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
3099: } else {
3100: my %lt = &usersession_titles();
3101: my $numinrow = 5;
3102: my $prefix;
3103: my @types;
3104: if ($position eq 'bottom') {
3105: $prefix = 'remote';
3106: @types = ('version','excludedomain','includedomain');
3107: } else {
3108: $prefix = 'hosted';
3109: @types = ('excludedomain','includedomain');
3110: }
3111: my (%current,%checkedon,%checkedoff);
3112: my @lcversions = &Apache::lonnet::all_loncaparevs();
3113: my @locations = sort(keys(%by_location));
3114: foreach my $type (@types) {
3115: $checkedon{$type} = '';
3116: $checkedoff{$type} = ' checked="checked"';
3117: }
3118: if (ref($settings) eq 'HASH') {
3119: if (ref($settings->{$prefix}) eq 'HASH') {
3120: foreach my $key (keys(%{$settings->{$prefix}})) {
3121: $current{$key} = $settings->{$prefix}{$key};
3122: if ($key eq 'version') {
3123: if ($current{$key} ne '') {
3124: $checkedon{$key} = ' checked="checked"';
3125: $checkedoff{$key} = '';
3126: }
3127: } elsif (ref($current{$key}) eq 'ARRAY') {
3128: $checkedon{$key} = ' checked="checked"';
3129: $checkedoff{$key} = '';
3130: }
3131: }
3132: }
3133: }
3134: foreach my $type (@types) {
3135: next if ($type ne 'version' && !@locations);
3136: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3137: $datatable .= '<tr'.$css_class.'>
3138: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
3139: <span class="LC_nobreak">
3140: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
3141: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
3142: if ($type eq 'version') {
3143: my $selector = '<select name="'.$prefix.'_version">';
3144: foreach my $version (@lcversions) {
3145: my $selected = '';
3146: if ($current{'version'} eq $version) {
3147: $selected = ' selected="selected"';
3148: }
3149: $selector .= ' <option value="'.$version.'"'.
3150: $selected.'>'.$version.'</option>';
3151: }
3152: $selector .= '</select> ';
3153: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
3154: } else {
3155: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
3156: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
3157: ' />'.(' 'x2).
3158: '<input type="button" value="'.&mt('uncheck all').'" '.
3159: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
3160: "\n".
3161: '</div><div><table>';
3162: my $rem;
3163: for (my $i=0; $i<@locations; $i++) {
3164: my ($showloc,$value,$checkedtype);
3165: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
3166: my $ip = $by_location{$locations[$i]}->[0];
3167: if (ref($by_ip{$ip}) eq 'ARRAY') {
3168: $value = join(':',@{$by_ip{$ip}});
3169: $showloc = join(', ',@{$by_ip{$ip}});
3170: if (ref($current{$type}) eq 'ARRAY') {
3171: foreach my $loc (@{$by_ip{$ip}}) {
3172: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
3173: $checkedtype = ' checked="checked"';
3174: last;
3175: }
3176: }
3177: }
3178: }
3179: }
3180: $rem = $i%($numinrow);
3181: if ($rem == 0) {
3182: if ($i > 0) {
3183: $datatable .= '</tr>';
3184: }
3185: $datatable .= '<tr>';
3186: }
3187: $datatable .= '<td class="LC_left_item">'.
3188: '<span class="LC_nobreak"><label>'.
3189: '<input type="checkbox" name="'.$prefix.'_'.$type.
3190: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
3191: '</label></span></td>';
3192: }
3193: $rem = @locations%($numinrow);
3194: my $colsleft = $numinrow - $rem;
3195: if ($colsleft > 1 ) {
3196: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3197: ' </td>';
3198: } elsif ($colsleft == 1) {
3199: $datatable .= '<td class="LC_left_item"> </td>';
3200: }
3201: $datatable .= '</tr></table>';
3202: }
3203: $datatable .= '</td></tr>';
3204: $itemcount ++;
3205: }
3206: }
3207: }
3208: $$rowtotal += $itemcount;
3209: return $datatable;
3210: }
3211:
3212: sub build_location_hashes {
3213: my ($intdoms,$by_ip,$by_location) = @_;
3214: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
3215: (ref($by_location) eq 'HASH'));
3216: my %iphost = &Apache::lonnet::get_iphost();
3217: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
3218: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
3219: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
3220: foreach my $id (@{$iphost{$primary_ip}}) {
3221: my $intdom = &Apache::lonnet::internet_dom($id);
3222: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
3223: push(@{$intdoms},$intdom);
3224: }
3225: }
3226: }
3227: foreach my $ip (keys(%iphost)) {
3228: if (ref($iphost{$ip}) eq 'ARRAY') {
3229: foreach my $id (@{$iphost{$ip}}) {
3230: my $location = &Apache::lonnet::internet_dom($id);
3231: if ($location) {
3232: next if (grep(/^\Q$location\E$/,@{$intdoms}));
3233: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3234: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
3235: push(@{$by_ip->{$ip}},$location);
3236: }
3237: } else {
3238: $by_ip->{$ip} = [$location];
3239: }
3240: }
3241: }
3242: }
3243: }
3244: foreach my $ip (sort(keys(%{$by_ip}))) {
3245: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3246: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
3247: my $first = $by_ip->{$ip}->[0];
3248: if (ref($by_location->{$first}) eq 'ARRAY') {
3249: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
3250: push(@{$by_location->{$first}},$ip);
3251: }
3252: } else {
3253: $by_location->{$first} = [$ip];
3254: }
3255: }
3256: }
3257: return;
3258: }
3259:
3260: sub current_offloads_to {
3261: my ($dom,$settings,$servers) = @_;
3262: my (%spareid,%otherdomconfigs);
3263: if (ref($servers) eq 'HASH') {
3264: foreach my $lonhost (sort(keys(%{$servers}))) {
3265: my $gotspares;
3266: if (ref($settings) eq 'HASH') {
3267: if (ref($settings->{'spares'}) eq 'HASH') {
3268: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
3269: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
3270: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
3271: $gotspares = 1;
3272: }
3273: }
3274: }
3275: unless ($gotspares) {
3276: my $gotspares;
3277: my $serverhomeID =
3278: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
3279: my $serverhomedom =
3280: &Apache::lonnet::host_domain($serverhomeID);
3281: if ($serverhomedom ne $dom) {
3282: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
3283: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3284: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3285: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3286: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3287: $gotspares = 1;
3288: }
3289: }
3290: } else {
3291: $otherdomconfigs{$serverhomedom} =
3292: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
3293: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
3294: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3295: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3296: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
3297: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3298: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3299: $gotspares = 1;
3300: }
3301: }
3302: }
3303: }
3304: }
3305: }
3306: }
3307: unless ($gotspares) {
3308: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
3309: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3310: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3311: } else {
3312: my $server_hostname = &Apache::lonnet::hostname($lonhost);
3313: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
3314: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
3315: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3316: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3317: } else {
3318: my %what = (
3319: spareid => 1,
3320: );
3321: my ($result,$returnhash) =
3322: &Apache::lonnet::get_remote_globals($lonhost,\%what);
3323: if ($result eq 'ok') {
3324: if (ref($returnhash) eq 'HASH') {
3325: if (ref($returnhash->{'spareid'}) eq 'HASH') {
3326: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
3327: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
3328: }
3329: }
3330: }
3331: }
3332: }
3333: }
3334: }
3335: }
3336: return %spareid;
3337: }
3338:
3339: sub spares_row {
3340: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
3341: my $css_class;
3342: my $numinrow = 4;
3343: my $itemcount = 1;
3344: my $datatable;
3345: my %typetitles = &sparestype_titles();
3346: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
3347: foreach my $server (sort(keys(%{$servers}))) {
3348: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
3349: my ($othercontrol,$serverdom);
3350: if ($serverhome ne $server) {
3351: $serverdom = &Apache::lonnet::host_domain($serverhome);
3352: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3353: } else {
3354: $serverdom = &Apache::lonnet::host_domain($server);
3355: if ($serverdom ne $dom) {
3356: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3357: }
3358: }
3359: next unless (ref($spareid->{$server}) eq 'HASH');
3360: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3361: $datatable .= '<tr'.$css_class.'>
3362: <td rowspan="2">
3363: <span class="LC_nobreak">'.
3364: &mt('[_1] when busy, offloads to:'
3365: ,'<b>'.$server.'</b>').
3366: "\n";
3367: my (%current,%canselect);
3368: my @choices =
3369: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
3370: foreach my $type ('primary','default') {
3371: if (ref($spareid->{$server}) eq 'HASH') {
3372: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
3373: my @spares = @{$spareid->{$server}{$type}};
3374: if (@spares > 0) {
3375: if ($othercontrol) {
3376: $current{$type} = join(', ',@spares);
3377: } else {
3378: $current{$type} .= '<table>';
3379: my $numspares = scalar(@spares);
3380: for (my $i=0; $i<@spares; $i++) {
3381: my $rem = $i%($numinrow);
3382: if ($rem == 0) {
3383: if ($i > 0) {
3384: $current{$type} .= '</tr>';
3385: }
3386: $current{$type} .= '<tr>';
3387: }
3388: $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'".');" /> '.
3389: $spareid->{$server}{$type}[$i].
3390: '</label></td>'."\n";
3391: }
3392: my $rem = @spares%($numinrow);
3393: my $colsleft = $numinrow - $rem;
3394: if ($colsleft > 1 ) {
3395: $current{$type} .= '<td colspan="'.$colsleft.
3396: '" class="LC_left_item">'.
3397: ' </td>';
3398: } elsif ($colsleft == 1) {
3399: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
3400: }
3401: $current{$type} .= '</tr></table>';
3402: }
3403: }
3404: }
3405: if ($current{$type} eq '') {
3406: $current{$type} = &mt('None specified');
3407: }
3408: if ($othercontrol) {
3409: if ($type eq 'primary') {
3410: $canselect{$type} = $othercontrol;
3411: }
3412: } else {
3413: $canselect{$type} =
3414: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
3415: '<select name="newspare_'.$type.'_'.$server.'" '.
3416: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
3417: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
3418: if (@choices > 0) {
3419: foreach my $lonhost (@choices) {
3420: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
3421: }
3422: }
3423: $canselect{$type} .= '</select>'."\n";
3424: }
3425: } else {
3426: $current{$type} = &mt('Could not be determined');
3427: if ($type eq 'primary') {
3428: $canselect{$type} = $othercontrol;
3429: }
3430: }
3431: if ($type eq 'default') {
3432: $datatable .= '<tr'.$css_class.'>';
3433: }
3434: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
3435: '<td>'.$current{$type}.'</td>'."\n".
3436: '<td>'.$canselect{$type}.'</td></tr>'."\n";
3437: }
3438: $itemcount ++;
3439: }
3440: }
3441: $$rowtotal += $itemcount;
3442: return $datatable;
3443: }
3444:
3445: sub possible_newspares {
3446: my ($server,$currspares,$serverhomes,$altids) = @_;
3447: my $serverhostname = &Apache::lonnet::hostname($server);
3448: my %excluded;
3449: if ($serverhostname ne '') {
3450: %excluded = (
3451: $serverhostname => 1,
3452: );
3453: }
3454: if (ref($currspares) eq 'HASH') {
3455: foreach my $type (keys(%{$currspares})) {
3456: if (ref($currspares->{$type}) eq 'ARRAY') {
3457: if (@{$currspares->{$type}} > 0) {
3458: foreach my $curr (@{$currspares->{$type}}) {
3459: my $hostname = &Apache::lonnet::hostname($curr);
3460: $excluded{$hostname} = 1;
3461: }
3462: }
3463: }
3464: }
3465: }
3466: my @choices;
3467: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
3468: if (keys(%{$serverhomes}) > 1) {
3469: foreach my $name (sort(keys(%{$serverhomes}))) {
3470: unless ($excluded{$name}) {
3471: if (exists($altids->{$serverhomes->{$name}})) {
3472: push(@choices,$altids->{$serverhomes->{$name}});
3473: } else {
3474: push(@choices,$serverhomes->{$name});
3475: }
3476: }
3477: }
3478: }
3479: }
3480: return sort(@choices);
3481: }
3482:
3483: sub print_loadbalancing {
3484: my ($dom,$settings,$rowtotal) = @_;
3485: my $primary_id = &Apache::lonnet::domain($dom,'primary');
3486: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3487: my $numinrow = 1;
3488: my $datatable;
3489: my %servers = &Apache::lonnet::internet_dom_servers($dom);
3490: my (%currbalancer,%currtargets,%currrules,%existing);
3491: if (ref($settings) eq 'HASH') {
3492: %existing = %{$settings};
3493: }
3494: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
3495: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
3496: \%currtargets,\%currrules);
3497: } else {
3498: return;
3499: }
3500: my ($othertitle,$usertypes,$types) =
3501: &Apache::loncommon::sorted_inst_types($dom);
3502: my $rownum = 8;
3503: if (ref($types) eq 'ARRAY') {
3504: $rownum += scalar(@{$types});
3505: }
3506: my @css_class = ('LC_odd_row','LC_even_row');
3507: my $balnum = 0;
3508: my $islast;
3509: my (@toshow,$disabledtext);
3510: if (keys(%currbalancer) > 0) {
3511: @toshow = sort(keys(%currbalancer));
3512: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
3513: push(@toshow,'');
3514: }
3515: } else {
3516: @toshow = ('');
3517: $disabledtext = &mt('No existing load balancer');
3518: }
3519: foreach my $lonhost (@toshow) {
3520: if ($balnum == scalar(@toshow)-1) {
3521: $islast = 1;
3522: } else {
3523: $islast = 0;
3524: }
3525: my $cssidx = $balnum%2;
3526: my $targets_div_style = 'display: none';
3527: my $disabled_div_style = 'display: block';
3528: my $homedom_div_style = 'display: none';
3529: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3530: '<td rowspan="'.$rownum.'" valign="top">'.
3531: '<p>';
3532: if ($lonhost eq '') {
3533: $datatable .= '<span class="LC_nobreak">';
3534: if (keys(%currbalancer) > 0) {
3535: $datatable .= &mt('Add balancer:');
3536: } else {
3537: $datatable .= &mt('Enable balancer:');
3538: }
3539: $datatable .= ' '.
3540: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3541: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3542: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3543: '<option value="" selected="selected">'.&mt('None').
3544: '</option>'."\n";
3545: foreach my $server (sort(keys(%servers))) {
3546: next if ($currbalancer{$server});
3547: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3548: }
3549: $datatable .=
3550: '</select>'."\n".
3551: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3552: } else {
3553: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3554: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3555: &mt('Stop balancing').'</label>'.
3556: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3557: $targets_div_style = 'display: block';
3558: $disabled_div_style = 'display: none';
3559: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3560: $homedom_div_style = 'display: block';
3561: }
3562: }
3563: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3564: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3565: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3566: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3567: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3568: my @sparestypes = ('primary','default');
3569: my %typetitles = &sparestype_titles();
3570: foreach my $sparetype (@sparestypes) {
3571: my $targettable;
3572: for (my $i=0; $i<$numspares; $i++) {
3573: my $checked;
3574: if (ref($currtargets{$lonhost}) eq 'HASH') {
3575: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3576: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3577: $checked = ' checked="checked"';
3578: }
3579: }
3580: }
3581: my ($chkboxval,$disabled);
3582: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3583: $chkboxval = $spares[$i];
3584: }
3585: if (exists($currbalancer{$spares[$i]})) {
3586: $disabled = ' disabled="disabled"';
3587: }
3588: $targettable .=
3589: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3590: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3591: '</span></label></td>';
3592: my $rem = $i%($numinrow);
3593: if ($rem == 0) {
3594: if (($i > 0) && ($i < $numspares-1)) {
3595: $targettable .= '</tr>';
3596: }
3597: if ($i < $numspares-1) {
3598: $targettable .= '<tr>';
3599: }
3600: }
3601: }
3602: if ($targettable ne '') {
3603: my $rem = $numspares%($numinrow);
3604: my $colsleft = $numinrow - $rem;
3605: if ($colsleft > 1 ) {
3606: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3607: ' </td>';
3608: } elsif ($colsleft == 1) {
3609: $targettable .= '<td class="LC_left_item"> </td>';
3610: }
3611: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3612: '<table><tr>'.$targettable.'</tr></table><br />';
3613: }
3614: }
3615: $datatable .= '</div></td></tr>'.
3616: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3617: $othertitle,$usertypes,$types,\%servers,
3618: \%currbalancer,$lonhost,
3619: $targets_div_style,$homedom_div_style,
3620: $css_class[$cssidx],$balnum,$islast);
3621: $$rowtotal += $rownum;
3622: $balnum ++;
3623: }
3624: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3625: return $datatable;
3626: }
3627:
3628: sub get_loadbalancers_config {
3629: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3630: return unless ((ref($servers) eq 'HASH') &&
3631: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3632: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3633: if (keys(%{$existing}) > 0) {
3634: my $oldlonhost;
3635: foreach my $key (sort(keys(%{$existing}))) {
3636: if ($key eq 'lonhost') {
3637: $oldlonhost = $existing->{'lonhost'};
3638: $currbalancer->{$oldlonhost} = 1;
3639: } elsif ($key eq 'targets') {
3640: if ($oldlonhost) {
3641: $currtargets->{$oldlonhost} = $existing->{'targets'};
3642: }
3643: } elsif ($key eq 'rules') {
3644: if ($oldlonhost) {
3645: $currrules->{$oldlonhost} = $existing->{'rules'};
3646: }
3647: } elsif (ref($existing->{$key}) eq 'HASH') {
3648: $currbalancer->{$key} = 1;
3649: $currtargets->{$key} = $existing->{$key}{'targets'};
3650: $currrules->{$key} = $existing->{$key}{'rules'};
3651: }
3652: }
3653: } else {
3654: my ($balancerref,$targetsref) =
3655: &Apache::lonnet::get_lonbalancer_config($servers);
3656: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3657: foreach my $server (sort(keys(%{$balancerref}))) {
3658: $currbalancer->{$server} = 1;
3659: $currtargets->{$server} = $targetsref->{$server};
3660: }
3661: }
3662: }
3663: return;
3664: }
3665:
3666: sub loadbalancing_rules {
3667: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
3668: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3669: $css_class,$balnum,$islast) = @_;
3670: my $output;
3671: my $num = 0;
3672: my ($alltypes,$othertypes,$titles) =
3673: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3674: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3675: foreach my $type (@{$alltypes}) {
3676: $num ++;
3677: my $current;
3678: if (ref($currrules) eq 'HASH') {
3679: $current = $currrules->{$type};
3680: }
3681: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
3682: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
3683: $current = '';
3684: }
3685: }
3686: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
3687: $servers,$currbalancer,$lonhost,$dom,
3688: $targets_div_style,$homedom_div_style,
3689: $css_class,$balnum,$num,$islast);
3690: }
3691: }
3692: return $output;
3693: }
3694:
3695: sub loadbalancing_titles {
3696: my ($dom,$intdom,$usertypes,$types) = @_;
3697: my %othertypes = (
3698: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3699: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3700: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3701: '_LC_external' => &mt('Users not from [_1]',$intdom),
3702: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
3703: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
3704: );
3705: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
3706: if (ref($types) eq 'ARRAY') {
3707: unshift(@alltypes,@{$types},'default');
3708: }
3709: my %titles;
3710: foreach my $type (@alltypes) {
3711: if ($type =~ /^_LC_/) {
3712: $titles{$type} = $othertypes{$type};
3713: } elsif ($type eq 'default') {
3714: $titles{$type} = &mt('All users from [_1]',$dom);
3715: if (ref($types) eq 'ARRAY') {
3716: if (@{$types} > 0) {
3717: $titles{$type} = &mt('Other users from [_1]',$dom);
3718: }
3719: }
3720: } elsif (ref($usertypes) eq 'HASH') {
3721: $titles{$type} = $usertypes->{$type};
3722: }
3723: }
3724: return (\@alltypes,\%othertypes,\%titles);
3725: }
3726:
3727: sub loadbalance_rule_row {
3728: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3729: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
3730: my @rulenames;
3731: my %ruletitles = &offloadtype_text();
3732: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
3733: @rulenames = ('balancer','offloadedto');
3734: } else {
3735: @rulenames = ('default','homeserver');
3736: if ($type eq '_LC_external') {
3737: push(@rulenames,'externalbalancer');
3738: } else {
3739: push(@rulenames,'specific');
3740: }
3741: push(@rulenames,'none');
3742: }
3743: my $style = $targets_div_style;
3744: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
3745: $style = $homedom_div_style;
3746: }
3747: my $space;
3748: if ($islast && $num == 1) {
3749: $space = '<div display="inline-block"> </div>';
3750: }
3751: my $output =
3752: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3753: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3754: '<td valaign="top">'.$space.
3755: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
3756: for (my $i=0; $i<@rulenames; $i++) {
3757: my $rule = $rulenames[$i];
3758: my ($checked,$extra);
3759: if ($rulenames[$i] eq 'default') {
3760: $rule = '';
3761: }
3762: if ($rulenames[$i] eq 'specific') {
3763: if (ref($servers) eq 'HASH') {
3764: my $default;
3765: if (($current ne '') && (exists($servers->{$current}))) {
3766: $checked = ' checked="checked"';
3767: }
3768: unless ($checked) {
3769: $default = ' selected="selected"';
3770: }
3771: $extra =
3772: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3773: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3774: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3775: '<option value=""'.$default.'></option>'."\n";
3776: foreach my $server (sort(keys(%{$servers}))) {
3777: if (ref($currbalancer) eq 'HASH') {
3778: next if (exists($currbalancer->{$server}));
3779: }
3780: my $selected;
3781: if ($server eq $current) {
3782: $selected = ' selected="selected"';
3783: }
3784: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
3785: }
3786: $extra .= '</select>';
3787: }
3788: } elsif ($rule eq $current) {
3789: $checked = ' checked="checked"';
3790: }
3791: $output .= '<span class="LC_nobreak"><label>'.
3792: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3793: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3794: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
3795: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3796: '</label>'.$extra.'</span><br />'."\n";
3797: }
3798: $output .= '</div></td></tr>'."\n";
3799: return $output;
3800: }
3801:
3802: sub offloadtype_text {
3803: my %ruletitles = &Apache::lonlocal::texthash (
3804: 'default' => 'Offloads to default destinations',
3805: 'homeserver' => "Offloads to user's home server",
3806: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3807: 'specific' => 'Offloads to specific server',
3808: 'none' => 'No offload',
3809: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
3810: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
3811: );
3812: return %ruletitles;
3813: }
3814:
3815: sub sparestype_titles {
3816: my %typestitles = &Apache::lonlocal::texthash (
3817: 'primary' => 'primary',
3818: 'default' => 'default',
3819: );
3820: return %typestitles;
3821: }
3822:
3823: sub contact_titles {
3824: my %titles = &Apache::lonlocal::texthash (
3825: 'supportemail' => 'Support E-mail address',
3826: 'adminemail' => 'Default Server Admin E-mail address',
3827: 'errormail' => 'Error reports to be e-mailed to',
3828: 'packagesmail' => 'Package update alerts to be e-mailed to',
3829: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3830: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
3831: 'requestsmail' => 'E-mail from course requests requiring approval',
3832: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
3833: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
3834: );
3835: my %short_titles = &Apache::lonlocal::texthash (
3836: adminemail => 'Admin E-mail address',
3837: supportemail => 'Support E-mail',
3838: );
3839: return (\%titles,\%short_titles);
3840: }
3841:
3842: sub tool_titles {
3843: my %titles = &Apache::lonlocal::texthash (
3844: aboutme => 'Personal web page',
3845: blog => 'Blog',
3846: webdav => 'WebDAV',
3847: portfolio => 'Portfolio',
3848: official => 'Official courses (with institutional codes)',
3849: unofficial => 'Unofficial courses',
3850: community => 'Communities',
3851: textbook => 'Textbook courses',
3852: );
3853: return %titles;
3854: }
3855:
3856: sub courserequest_titles {
3857: my %titles = &Apache::lonlocal::texthash (
3858: official => 'Official',
3859: unofficial => 'Unofficial',
3860: community => 'Communities',
3861: textbook => 'Textbook',
3862: norequest => 'Not allowed',
3863: approval => 'Approval by Dom. Coord.',
3864: validate => 'With validation',
3865: autolimit => 'Numerical limit',
3866: unlimited => '(blank for unlimited)',
3867: );
3868: return %titles;
3869: }
3870:
3871: sub authorrequest_titles {
3872: my %titles = &Apache::lonlocal::texthash (
3873: norequest => 'Not allowed',
3874: approval => 'Approval by Dom. Coord.',
3875: automatic => 'Automatic approval',
3876: );
3877: return %titles;
3878: }
3879:
3880: sub courserequest_conditions {
3881: my %conditions = &Apache::lonlocal::texthash (
3882: approval => '(Processing of request subject to approval by Domain Coordinator).',
3883: validate => '(Processing of request subject to institutional validation).',
3884: );
3885: return %conditions;
3886: }
3887:
3888:
3889: sub print_usercreation {
3890: my ($position,$dom,$settings,$rowtotal) = @_;
3891: my $numinrow = 4;
3892: my $datatable;
3893: if ($position eq 'top') {
3894: $$rowtotal ++;
3895: my $rowcount = 0;
3896: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
3897: if (ref($rules) eq 'HASH') {
3898: if (keys(%{$rules}) > 0) {
3899: $datatable .= &user_formats_row('username',$settings,$rules,
3900: $ruleorder,$numinrow,$rowcount);
3901: $$rowtotal ++;
3902: $rowcount ++;
3903: }
3904: }
3905: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3906: if (ref($idrules) eq 'HASH') {
3907: if (keys(%{$idrules}) > 0) {
3908: $datatable .= &user_formats_row('id',$settings,$idrules,
3909: $idruleorder,$numinrow,$rowcount);
3910: $$rowtotal ++;
3911: $rowcount ++;
3912: }
3913: }
3914: if ($rowcount == 0) {
3915: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3916: $$rowtotal ++;
3917: $rowcount ++;
3918: }
3919: } elsif ($position eq 'middle') {
3920: my @creators = ('author','course','requestcrs');
3921: my ($rules,$ruleorder) =
3922: &Apache::lonnet::inst_userrules($dom,'username');
3923: my %lt = &usercreation_types();
3924: my %checked;
3925: if (ref($settings) eq 'HASH') {
3926: if (ref($settings->{'cancreate'}) eq 'HASH') {
3927: foreach my $item (@creators) {
3928: $checked{$item} = $settings->{'cancreate'}{$item};
3929: }
3930: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3931: foreach my $item (@creators) {
3932: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3933: $checked{$item} = 'none';
3934: }
3935: }
3936: }
3937: }
3938: my $rownum = 0;
3939: foreach my $item (@creators) {
3940: $rownum ++;
3941: if ($checked{$item} eq '') {
3942: $checked{$item} = 'any';
3943: }
3944: my $css_class;
3945: if ($rownum%2) {
3946: $css_class = '';
3947: } else {
3948: $css_class = ' class="LC_odd_row" ';
3949: }
3950: $datatable .= '<tr'.$css_class.'>'.
3951: '<td><span class="LC_nobreak">'.$lt{$item}.
3952: '</span></td><td align="right">';
3953: my @options = ('any');
3954: if (ref($rules) eq 'HASH') {
3955: if (keys(%{$rules}) > 0) {
3956: push(@options,('official','unofficial'));
3957: }
3958: }
3959: push(@options,'none');
3960: foreach my $option (@options) {
3961: my $type = 'radio';
3962: my $check = ' ';
3963: if ($checked{$item} eq $option) {
3964: $check = ' checked="checked" ';
3965: }
3966: $datatable .= '<span class="LC_nobreak"><label>'.
3967: '<input type="'.$type.'" name="can_createuser_'.
3968: $item.'" value="'.$option.'"'.$check.'/> '.
3969: $lt{$option}.'</label> </span>';
3970: }
3971: $datatable .= '</td></tr>';
3972: }
3973: } else {
3974: my @contexts = ('author','course','domain');
3975: my @authtypes = ('int','krb4','krb5','loc');
3976: my %checked;
3977: if (ref($settings) eq 'HASH') {
3978: if (ref($settings->{'authtypes'}) eq 'HASH') {
3979: foreach my $item (@contexts) {
3980: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3981: foreach my $auth (@authtypes) {
3982: if ($settings->{'authtypes'}{$item}{$auth}) {
3983: $checked{$item}{$auth} = ' checked="checked" ';
3984: }
3985: }
3986: }
3987: }
3988: }
3989: } else {
3990: foreach my $item (@contexts) {
3991: foreach my $auth (@authtypes) {
3992: $checked{$item}{$auth} = ' checked="checked" ';
3993: }
3994: }
3995: }
3996: my %title = &context_names();
3997: my %authname = &authtype_names();
3998: my $rownum = 0;
3999: my $css_class;
4000: foreach my $item (@contexts) {
4001: if ($rownum%2) {
4002: $css_class = '';
4003: } else {
4004: $css_class = ' class="LC_odd_row" ';
4005: }
4006: $datatable .= '<tr'.$css_class.'>'.
4007: '<td>'.$title{$item}.
4008: '</td><td class="LC_left_item">'.
4009: '<span class="LC_nobreak">';
4010: foreach my $auth (@authtypes) {
4011: $datatable .= '<label>'.
4012: '<input type="checkbox" name="'.$item.'_auth" '.
4013: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4014: $authname{$auth}.'</label> ';
4015: }
4016: $datatable .= '</span></td></tr>';
4017: $rownum ++;
4018: }
4019: $$rowtotal += $rownum;
4020: }
4021: return $datatable;
4022: }
4023:
4024: sub print_selfcreation {
4025: my ($position,$dom,$settings,$rowtotal) = @_;
4026: my (@selfcreate,$createsettings,$processing,$datatable);
4027: if (ref($settings) eq 'HASH') {
4028: if (ref($settings->{'cancreate'}) eq 'HASH') {
4029: $createsettings = $settings->{'cancreate'};
4030: if (ref($createsettings) eq 'HASH') {
4031: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
4032: @selfcreate = @{$createsettings->{'selfcreate'}};
4033: } elsif ($createsettings->{'selfcreate'} ne '') {
4034: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
4035: @selfcreate = ('email','login','sso');
4036: } elsif ($createsettings->{'selfcreate'} ne 'none') {
4037: @selfcreate = ($createsettings->{'selfcreate'});
4038: }
4039: }
4040: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
4041: $processing = $createsettings->{'selfcreateprocessing'};
4042: }
4043: }
4044: }
4045: }
4046: my %radiohash;
4047: my $numinrow = 4;
4048: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
4049: if ($position eq 'top') {
4050: my %choices = &Apache::lonlocal::texthash (
4051: cancreate_login => 'Institutional Login',
4052: cancreate_sso => 'Institutional Single Sign On',
4053: );
4054: my @toggles = sort(keys(%choices));
4055: my %defaultchecked = (
4056: 'cancreate_login' => 'off',
4057: 'cancreate_sso' => 'off',
4058: );
4059: my ($onclick,$itemcount);
4060: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4061: \%choices,$itemcount,$onclick);
4062: $$rowtotal += $itemcount;
4063:
4064: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4065:
4066: if (ref($usertypes) eq 'HASH') {
4067: if (keys(%{$usertypes}) > 0) {
4068: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
4069: $dom,$numinrow,$othertitle,
4070: 'statustocreate',$$rowtotal);
4071: $$rowtotal ++;
4072: }
4073: }
4074: } elsif ($position eq 'middle') {
4075: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
4076: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4077: $usertypes->{'default'} = $othertitle;
4078: if (ref($types) eq 'ARRAY') {
4079: push(@{$types},'default');
4080: $usertypes->{'default'} = $othertitle;
4081: foreach my $status (@{$types}) {
4082: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
4083: $numinrow,$$rowtotal,$usertypes);
4084: $$rowtotal ++;
4085: }
4086: }
4087: } else {
4088: my %choices = &Apache::lonlocal::texthash (
4089: cancreate_email => 'E-mail address as username',
4090: );
4091: my @toggles = sort(keys(%choices));
4092: my %defaultchecked = (
4093: 'cancreate_email' => 'off',
4094: );
4095: my $itemcount = 0;
4096: my $display = 'none';
4097: if (grep(/^\Qemail\E$/,@selfcreate)) {
4098: $display = 'block';
4099: }
4100: my $onclick = "toggleDisplay(this.form,'emailoptions');";
4101: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
4102: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
4103: my $usertypes = {};
4104: my $order = [];
4105: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
4106: $usertypes = $domdefaults{'inststatustypes'};
4107: $order = $domdefaults{'inststatusguest'};
4108: }
4109: if (ref($order) eq 'ARRAY') {
4110: push(@{$order},'default');
4111: if (@{$order} > 1) {
4112: $usertypes->{'default'} = &mt('Other users');
4113: $additional .= '<table><tr>';
4114: foreach my $status (@{$order}) {
4115: $additional .= '<th>'.$usertypes->{$status}.'</th>';
4116: }
4117: $additional .= '</tr><tr>';
4118: foreach my $status (@{$order}) {
4119: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
4120: }
4121: $additional .= '</tr></table>';
4122: } else {
4123: $usertypes->{'default'} = &mt('All users');
4124: $additional .= &email_as_username($rowtotal,$processing);
4125: }
4126: }
4127: $additional .= '</div>'."\n";
4128:
4129: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4130: \%choices,$itemcount,$onclick,$additional);
4131: $$rowtotal += $itemcount;
4132: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
4133: $$rowtotal ++;
4134: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4135: $numinrow = 1;
4136: if (ref($order) eq 'ARRAY') {
4137: foreach my $status (@{$order}) {
4138: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
4139: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
4140: $$rowtotal ++;
4141: }
4142: }
4143: my ($emailrules,$emailruleorder) =
4144: &Apache::lonnet::inst_userrules($dom,'email');
4145: if (ref($emailrules) eq 'HASH') {
4146: if (keys(%{$emailrules}) > 0) {
4147: $datatable .= &user_formats_row('email',$settings,$emailrules,
4148: $emailruleorder,$numinrow,$$rowtotal);
4149: $$rowtotal ++;
4150: }
4151: }
4152: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
4153: }
4154: return $datatable;
4155: }
4156:
4157: sub email_as_username {
4158: my ($rowtotal,$processing,$type) = @_;
4159: my %choices =
4160: &Apache::lonlocal::texthash (
4161: automatic => 'Automatic approval',
4162: approval => 'Queued for approval',
4163: );
4164: my $output;
4165: foreach my $option ('automatic','approval') {
4166: my $checked;
4167: if (ref($processing) eq 'HASH') {
4168: if ($type eq '') {
4169: if (!exists($processing->{'default'})) {
4170: if ($option eq 'automatic') {
4171: $checked = ' checked="checked"';
4172: }
4173: } else {
4174: if ($processing->{'default'} eq $option) {
4175: $checked = ' checked="checked"';
4176: }
4177: }
4178: } else {
4179: if (!exists($processing->{$type})) {
4180: if ($option eq 'automatic') {
4181: $checked = ' checked="checked"';
4182: }
4183: } else {
4184: if ($processing->{$type} eq $option) {
4185: $checked = ' checked="checked"';
4186: }
4187: }
4188: }
4189: } elsif ($option eq 'automatic') {
4190: $checked = ' checked="checked"';
4191: }
4192: my $name = 'cancreate_emailprocess';
4193: if (($type ne '') && ($type ne 'default')) {
4194: $name .= '_'.$type;
4195: }
4196: $output .= '<span class="LC_nobreak"><label>'.
4197: '<input type="radio" name="'.$name.'"'.
4198: $checked.' value="'.$option.'" />'.
4199: $choices{$option}.'</label></span>';
4200: if ($type eq '') {
4201: $output .= ' ';
4202: } else {
4203: $output .= '<br />';
4204: }
4205: }
4206: $$rowtotal ++;
4207: return $output;
4208: }
4209:
4210: sub captcha_choice {
4211: my ($context,$settings,$itemcount) = @_;
4212: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
4213: my %lt = &captcha_phrases();
4214: $keyentry = 'hidden';
4215: if ($context eq 'cancreate') {
4216: $rowname = &mt('CAPTCHA validation');
4217: } elsif ($context eq 'login') {
4218: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
4219: }
4220: if (ref($settings) eq 'HASH') {
4221: if ($settings->{'captcha'}) {
4222: $checked{$settings->{'captcha'}} = ' checked="checked"';
4223: } else {
4224: $checked{'original'} = ' checked="checked"';
4225: }
4226: if ($settings->{'captcha'} eq 'recaptcha') {
4227: $pubtext = $lt{'pub'};
4228: $privtext = $lt{'priv'};
4229: $keyentry = 'text';
4230: }
4231: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
4232: $currpub = $settings->{'recaptchakeys'}{'public'};
4233: $currpriv = $settings->{'recaptchakeys'}{'private'};
4234: }
4235: } else {
4236: $checked{'original'} = ' checked="checked"';
4237: }
4238: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4239: my $output = '<tr'.$css_class.'>'.
4240: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
4241: '<table><tr><td>'."\n";
4242: foreach my $option ('original','recaptcha','notused') {
4243: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
4244: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
4245: $lt{$option}.'</label></span>';
4246: unless ($option eq 'notused') {
4247: $output .= (' 'x2)."\n";
4248: }
4249: }
4250: #
4251: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
4252: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
4253: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
4254: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
4255: #
4256: $output .= '</td></tr>'."\n".
4257: '<tr><td>'."\n".
4258: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
4259: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
4260: $currpub.'" size="40" /></span><br />'."\n".
4261: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
4262: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
4263: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
4264: '</td></tr>';
4265: return $output;
4266: }
4267:
4268: sub user_formats_row {
4269: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
4270: my $output;
4271: my %text = (
4272: 'username' => 'new usernames',
4273: 'id' => 'IDs',
4274: 'email' => 'self-created accounts (e-mail)',
4275: );
4276: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4277: $output = '<tr '.$css_class.'>'.
4278: '<td><span class="LC_nobreak">';
4279: if ($type eq 'email') {
4280: $output .= &mt("Formats disallowed for $text{$type}: ");
4281: } else {
4282: $output .= &mt("Format rules to check for $text{$type}: ");
4283: }
4284: $output .= '</span></td>'.
4285: '<td class="LC_left_item" colspan="2"><table>';
4286: my $rem;
4287: if (ref($ruleorder) eq 'ARRAY') {
4288: for (my $i=0; $i<@{$ruleorder}; $i++) {
4289: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
4290: my $rem = $i%($numinrow);
4291: if ($rem == 0) {
4292: if ($i > 0) {
4293: $output .= '</tr>';
4294: }
4295: $output .= '<tr>';
4296: }
4297: my $check = ' ';
4298: if (ref($settings) eq 'HASH') {
4299: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
4300: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
4301: $check = ' checked="checked" ';
4302: }
4303: }
4304: }
4305: $output .= '<td class="LC_left_item">'.
4306: '<span class="LC_nobreak"><label>'.
4307: '<input type="checkbox" name="'.$type.'_rule" '.
4308: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
4309: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
4310: }
4311: }
4312: $rem = @{$ruleorder}%($numinrow);
4313: }
4314: my $colsleft = $numinrow - $rem;
4315: if ($colsleft > 1 ) {
4316: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4317: ' </td>';
4318: } elsif ($colsleft == 1) {
4319: $output .= '<td class="LC_left_item"> </td>';
4320: }
4321: $output .= '</tr></table></td></tr>';
4322: return $output;
4323: }
4324:
4325: sub usercreation_types {
4326: my %lt = &Apache::lonlocal::texthash (
4327: author => 'When adding a co-author',
4328: course => 'When adding a user to a course',
4329: requestcrs => 'When requesting a course',
4330: any => 'Any',
4331: official => 'Institutional only ',
4332: unofficial => 'Non-institutional only',
4333: none => 'None',
4334: );
4335: return %lt;
4336: }
4337:
4338: sub selfcreation_types {
4339: my %lt = &Apache::lonlocal::texthash (
4340: selfcreate => 'User creates own account',
4341: any => 'Any',
4342: official => 'Institutional only ',
4343: unofficial => 'Non-institutional only',
4344: email => 'E-mail address',
4345: login => 'Institutional Login',
4346: sso => 'SSO',
4347: );
4348: }
4349:
4350: sub authtype_names {
4351: my %lt = &Apache::lonlocal::texthash(
4352: int => 'Internal',
4353: krb4 => 'Kerberos 4',
4354: krb5 => 'Kerberos 5',
4355: loc => 'Local',
4356: );
4357: return %lt;
4358: }
4359:
4360: sub context_names {
4361: my %context_title = &Apache::lonlocal::texthash(
4362: author => 'Creating users when an Author',
4363: course => 'Creating users when in a course',
4364: domain => 'Creating users when a Domain Coordinator',
4365: );
4366: return %context_title;
4367: }
4368:
4369: sub print_usermodification {
4370: my ($position,$dom,$settings,$rowtotal) = @_;
4371: my $numinrow = 4;
4372: my ($context,$datatable,$rowcount);
4373: if ($position eq 'top') {
4374: $rowcount = 0;
4375: $context = 'author';
4376: foreach my $role ('ca','aa') {
4377: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4378: $numinrow,$rowcount);
4379: $$rowtotal ++;
4380: $rowcount ++;
4381: }
4382: } elsif ($position eq 'bottom') {
4383: $context = 'course';
4384: $rowcount = 0;
4385: foreach my $role ('st','ep','ta','in','cr') {
4386: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4387: $numinrow,$rowcount);
4388: $$rowtotal ++;
4389: $rowcount ++;
4390: }
4391: }
4392: return $datatable;
4393: }
4394:
4395: sub print_defaults {
4396: my ($position,$dom,$settings,$rowtotal) = @_;
4397: my $rownum = 0;
4398: my ($datatable,$css_class);
4399: if ($position eq 'top') {
4400: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
4401: 'datelocale_def','portal_def');
4402: my %defaults;
4403: if (ref($settings) eq 'HASH') {
4404: %defaults = %{$settings};
4405: } else {
4406: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
4407: foreach my $item (@items) {
4408: $defaults{$item} = $domdefaults{$item};
4409: }
4410: }
4411: my $titles = &defaults_titles($dom);
4412: foreach my $item (@items) {
4413: if ($rownum%2) {
4414: $css_class = '';
4415: } else {
4416: $css_class = ' class="LC_odd_row" ';
4417: }
4418: $datatable .= '<tr'.$css_class.'>'.
4419: '<td><span class="LC_nobreak">'.$titles->{$item}.
4420: '</span></td><td class="LC_right_item" colspan="3">';
4421: if ($item eq 'auth_def') {
4422: my @authtypes = ('internal','krb4','krb5','localauth');
4423: my %shortauth = (
4424: internal => 'int',
4425: krb4 => 'krb4',
4426: krb5 => 'krb5',
4427: localauth => 'loc'
4428: );
4429: my %authnames = &authtype_names();
4430: foreach my $auth (@authtypes) {
4431: my $checked = ' ';
4432: if ($defaults{$item} eq $auth) {
4433: $checked = ' checked="checked" ';
4434: }
4435: $datatable .= '<label><input type="radio" name="'.$item.
4436: '" value="'.$auth.'"'.$checked.'/>'.
4437: $authnames{$shortauth{$auth}}.'</label> ';
4438: }
4439: } elsif ($item eq 'timezone_def') {
4440: my $includeempty = 1;
4441: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
4442: } elsif ($item eq 'datelocale_def') {
4443: my $includeempty = 1;
4444: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
4445: } elsif ($item eq 'lang_def') {
4446: my %langchoices = &get_languages_hash();
4447: $langchoices{''} = 'No language preference';
4448: %langchoices = &Apache::lonlocal::texthash(%langchoices);
4449: $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,
4450: \%langchoices);
4451: } else {
4452: my $size;
4453: if ($item eq 'portal_def') {
4454: $size = ' size="25"';
4455: }
4456: $datatable .= '<input type="text" name="'.$item.'" value="'.
4457: $defaults{$item}.'"'.$size.' />';
4458: }
4459: $datatable .= '</td></tr>';
4460: $rownum ++;
4461: }
4462: } else {
4463: my (%defaults);
4464: if (ref($settings) eq 'HASH') {
4465: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
4466: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
4467: my $maxnum = @{$settings->{'inststatusorder'}};
4468: for (my $i=0; $i<$maxnum; $i++) {
4469: $css_class = $rownum%2?' class="LC_odd_row"':'';
4470: my $item = $settings->{'inststatusorder'}->[$i];
4471: my $title = $settings->{'inststatustypes'}->{$item};
4472: my $guestok;
4473: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
4474: $guestok = 1;
4475: }
4476: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
4477: $datatable .= '<tr'.$css_class.'>'.
4478: '<td><span class="LC_nobreak">'.
4479: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
4480: for (my $k=0; $k<=$maxnum; $k++) {
4481: my $vpos = $k+1;
4482: my $selstr;
4483: if ($k == $i) {
4484: $selstr = ' selected="selected" ';
4485: }
4486: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4487: }
4488: my ($checkedon,$checkedoff);
4489: $checkedoff = ' checked="checked"';
4490: if ($guestok) {
4491: $checkedon = $checkedoff;
4492: $checkedoff = '';
4493: }
4494: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
4495: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
4496: &mt('delete').'</span></td>'.
4497: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
4498: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
4499: '</span></td>'.
4500: '<td class="LC_right_item"><span class="LC_nobreak">'.
4501: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
4502: &mt('Yes').'</label>'.(' 'x2).
4503: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
4504: &mt('No').'</label></span></td></tr>';
4505: }
4506: $css_class = $rownum%2?' class="LC_odd_row"':'';
4507: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
4508: $datatable .= '<tr '.$css_class.'>'.
4509: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
4510: for (my $k=0; $k<=$maxnum; $k++) {
4511: my $vpos = $k+1;
4512: my $selstr;
4513: if ($k == $maxnum) {
4514: $selstr = ' selected="selected" ';
4515: }
4516: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4517: }
4518: $datatable .= '</select> '.&mt('Internal ID:').
4519: '<input type="text" size="10" name="addinststatus" value="" /></span>'.
4520: ' '.&mt('(new)').
4521: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
4522: &mt('Name displayed:').
4523: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
4524: '<td class="LC_right_item"><span class="LC_nobreak">'.
4525: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
4526: &mt('Yes').'</label>'.(' 'x2).
4527: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
4528: &mt('No').'</label></span></td></tr>';
4529: '</tr>'."\n";
4530: $rownum ++;
4531: }
4532: }
4533: }
4534: $$rowtotal += $rownum;
4535: return $datatable;
4536: }
4537:
4538: sub get_languages_hash {
4539: my %langchoices;
4540: foreach my $id (&Apache::loncommon::languageids()) {
4541: my $code = &Apache::loncommon::supportedlanguagecode($id);
4542: if ($code ne '') {
4543: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
4544: }
4545: }
4546: return %langchoices;
4547: }
4548:
4549: sub defaults_titles {
4550: my ($dom) = @_;
4551: my %titles = &Apache::lonlocal::texthash (
4552: 'auth_def' => 'Default authentication type',
4553: 'auth_arg_def' => 'Default authentication argument',
4554: 'lang_def' => 'Default language',
4555: 'timezone_def' => 'Default timezone',
4556: 'datelocale_def' => 'Default locale for dates',
4557: 'portal_def' => 'Portal/Default URL',
4558: );
4559: if ($dom) {
4560: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
4561: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
4562: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
4563: $protocol = 'http' if ($protocol ne 'https');
4564: if ($uint_dom) {
4565: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
4566: $uint_dom);
4567: }
4568: }
4569: return (\%titles);
4570: }
4571:
4572: sub print_scantronformat {
4573: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
4574: my $itemcount = 1;
4575: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
4576: %confhash);
4577: my $switchserver = &check_switchserver($dom,$confname);
4578: my %lt = &Apache::lonlocal::texthash (
4579: default => 'Default bubblesheet format file error',
4580: custom => 'Custom bubblesheet format file error',
4581: );
4582: my %scantronfiles = (
4583: default => 'default.tab',
4584: custom => 'custom.tab',
4585: );
4586: foreach my $key (keys(%scantronfiles)) {
4587: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
4588: .$scantronfiles{$key};
4589: }
4590: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
4591: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
4592: if (!$switchserver) {
4593: my $servadm = $r->dir_config('lonAdmEMail');
4594: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
4595: if ($configuserok eq 'ok') {
4596: if ($author_ok eq 'ok') {
4597: my %legacyfile = (
4598: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
4599: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
4600: );
4601: my %md5chk;
4602: foreach my $type (keys(%legacyfile)) {
4603: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
4604: chomp($md5chk{$type});
4605: }
4606: if ($md5chk{'default'} ne $md5chk{'custom'}) {
4607: foreach my $type (keys(%legacyfile)) {
4608: ($scantronurls{$type},my $error) =
4609: &legacy_scantronformat($r,$dom,$confname,
4610: $type,$legacyfile{$type},
4611: $scantronurls{$type},
4612: $scantronfiles{$type});
4613: if ($error ne '') {
4614: $error{$type} = $error;
4615: }
4616: }
4617: if (keys(%error) == 0) {
4618: $is_custom = 1;
4619: $confhash{'scantron'}{'scantronformat'} =
4620: $scantronurls{'custom'};
4621: my $putresult =
4622: &Apache::lonnet::put_dom('configuration',
4623: \%confhash,$dom);
4624: if ($putresult ne 'ok') {
4625: $error{'custom'} =
4626: '<span class="LC_error">'.
4627: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4628: }
4629: }
4630: } else {
4631: ($scantronurls{'default'},my $error) =
4632: &legacy_scantronformat($r,$dom,$confname,
4633: 'default',$legacyfile{'default'},
4634: $scantronurls{'default'},
4635: $scantronfiles{'default'});
4636: if ($error eq '') {
4637: $confhash{'scantron'}{'scantronformat'} = '';
4638: my $putresult =
4639: &Apache::lonnet::put_dom('configuration',
4640: \%confhash,$dom);
4641: if ($putresult ne 'ok') {
4642: $error{'default'} =
4643: '<span class="LC_error">'.
4644: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4645: }
4646: } else {
4647: $error{'default'} = $error;
4648: }
4649: }
4650: }
4651: }
4652: } else {
4653: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
4654: }
4655: }
4656: if (ref($settings) eq 'HASH') {
4657: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
4658: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
4659: if ((!@info) || ($info[0] eq 'no_such_dir')) {
4660: $scantronurl = '';
4661: } else {
4662: $scantronurl = $settings->{'scantronformat'};
4663: }
4664: $is_custom = 1;
4665: } else {
4666: $scantronurl = $scantronurls{'default'};
4667: }
4668: } else {
4669: if ($is_custom) {
4670: $scantronurl = $scantronurls{'custom'};
4671: } else {
4672: $scantronurl = $scantronurls{'default'};
4673: }
4674: }
4675: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4676: $datatable .= '<tr'.$css_class.'>';
4677: if (!$is_custom) {
4678: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
4679: '<span class="LC_nobreak">';
4680: if ($scantronurl) {
4681: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
4682: undef,undef,undef,undef,'background-color:#ffffff');
4683: } else {
4684: $datatable = &mt('File unavailable for display');
4685: }
4686: $datatable .= '</span></td>';
4687: if (keys(%error) == 0) {
4688: $datatable .= '<td valign="bottom">';
4689: if (!$switchserver) {
4690: $datatable .= &mt('Upload:').'<br />';
4691: }
4692: } else {
4693: my $errorstr;
4694: foreach my $key (sort(keys(%error))) {
4695: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4696: }
4697: $datatable .= '<td>'.$errorstr;
4698: }
4699: } else {
4700: if (keys(%error) > 0) {
4701: my $errorstr;
4702: foreach my $key (sort(keys(%error))) {
4703: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4704: }
4705: $datatable .= '<td>'.$errorstr.'</td><td> ';
4706: } elsif ($scantronurl) {
4707: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
4708: undef,undef,undef,undef,'background-color:#ffffff');
4709: $datatable .= '<td><span class="LC_nobreak">'.
4710: $link.
4711: '<label><input type="checkbox" name="scantronformat_del"'.
4712: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
4713: '<td><span class="LC_nobreak"> '.
4714: &mt('Replace:').'</span><br />';
4715: }
4716: }
4717: if (keys(%error) == 0) {
4718: if ($switchserver) {
4719: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4720: } else {
4721: $datatable .='<span class="LC_nobreak"> '.
4722: '<input type="file" name="scantronformat" /></span>';
4723: }
4724: }
4725: $datatable .= '</td></tr>';
4726: $$rowtotal ++;
4727: return $datatable;
4728: }
4729:
4730: sub legacy_scantronformat {
4731: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
4732: my ($url,$error);
4733: my @statinfo = &Apache::lonnet::stat_file($newurl);
4734: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
4735: (my $result,$url) =
4736: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
4737: '','',$newfile);
4738: if ($result ne 'ok') {
4739: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
4740: }
4741: }
4742: return ($url,$error);
4743: }
4744:
4745: sub print_coursecategories {
4746: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
4747: my $datatable;
4748: if ($position eq 'top') {
4749: my $toggle_cats_crs = ' ';
4750: my $toggle_cats_dom = ' checked="checked" ';
4751: my $can_cat_crs = ' ';
4752: my $can_cat_dom = ' checked="checked" ';
4753: my $toggle_catscomm_comm = ' ';
4754: my $toggle_catscomm_dom = ' checked="checked" ';
4755: my $can_catcomm_comm = ' ';
4756: my $can_catcomm_dom = ' checked="checked" ';
4757:
4758: if (ref($settings) eq 'HASH') {
4759: if ($settings->{'togglecats'} eq 'crs') {
4760: $toggle_cats_crs = $toggle_cats_dom;
4761: $toggle_cats_dom = ' ';
4762: }
4763: if ($settings->{'categorize'} eq 'crs') {
4764: $can_cat_crs = $can_cat_dom;
4765: $can_cat_dom = ' ';
4766: }
4767: if ($settings->{'togglecatscomm'} eq 'comm') {
4768: $toggle_catscomm_comm = $toggle_catscomm_dom;
4769: $toggle_catscomm_dom = ' ';
4770: }
4771: if ($settings->{'categorizecomm'} eq 'comm') {
4772: $can_catcomm_comm = $can_catcomm_dom;
4773: $can_catcomm_dom = ' ';
4774: }
4775: }
4776: my %title = &Apache::lonlocal::texthash (
4777: togglecats => 'Show/Hide a course in catalog',
4778: togglecatscomm => 'Show/Hide a community in catalog',
4779: categorize => 'Assign a category to a course',
4780: categorizecomm => 'Assign a category to a community',
4781: );
4782: my %level = &Apache::lonlocal::texthash (
4783: dom => 'Set in Domain',
4784: crs => 'Set in Course',
4785: comm => 'Set in Community',
4786: );
4787: $datatable = '<tr class="LC_odd_row">'.
4788: '<td>'.$title{'togglecats'}.'</td>'.
4789: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4790: '<input type="radio" name="togglecats"'.
4791: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4792: '<label><input type="radio" name="togglecats"'.
4793: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
4794: '</tr><tr>'.
4795: '<td>'.$title{'categorize'}.'</td>'.
4796: '<td class="LC_right_item"><span class="LC_nobreak">'.
4797: '<label><input type="radio" name="categorize"'.
4798: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4799: '<label><input type="radio" name="categorize"'.
4800: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
4801: '</tr><tr class="LC_odd_row">'.
4802: '<td>'.$title{'togglecatscomm'}.'</td>'.
4803: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4804: '<input type="radio" name="togglecatscomm"'.
4805: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4806: '<label><input type="radio" name="togglecatscomm"'.
4807: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4808: '</tr><tr>'.
4809: '<td>'.$title{'categorizecomm'}.'</td>'.
4810: '<td class="LC_right_item"><span class="LC_nobreak">'.
4811: '<label><input type="radio" name="categorizecomm"'.
4812: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4813: '<label><input type="radio" name="categorizecomm"'.
4814: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
4815: '</tr>';
4816: $$rowtotal += 4;
4817: } else {
4818: my $css_class;
4819: my $itemcount = 1;
4820: my $cathash;
4821: if (ref($settings) eq 'HASH') {
4822: $cathash = $settings->{'cats'};
4823: }
4824: if (ref($cathash) eq 'HASH') {
4825: my (@cats,@trails,%allitems,%idx,@jsarray);
4826: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4827: \%allitems,\%idx,\@jsarray);
4828: my $maxdepth = scalar(@cats);
4829: my $colattrib = '';
4830: if ($maxdepth > 2) {
4831: $colattrib = ' colspan="2" ';
4832: }
4833: my @path;
4834: if (@cats > 0) {
4835: if (ref($cats[0]) eq 'ARRAY') {
4836: my $numtop = @{$cats[0]};
4837: my $maxnum = $numtop;
4838: my %default_names = (
4839: instcode => &mt('Official courses'),
4840: communities => &mt('Communities'),
4841: );
4842:
4843: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4844: ($cathash->{'instcode::0'} eq '') ||
4845: (!grep(/^communities$/,@{$cats[0]})) ||
4846: ($cathash->{'communities::0'} eq '')) {
4847: $maxnum ++;
4848: }
4849: my $lastidx;
4850: for (my $i=0; $i<$numtop; $i++) {
4851: my $parent = $cats[0][$i];
4852: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4853: my $item = &escape($parent).'::0';
4854: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4855: $lastidx = $idx{$item};
4856: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4857: .'<select name="'.$item.'"'.$chgstr.'>';
4858: for (my $k=0; $k<=$maxnum; $k++) {
4859: my $vpos = $k+1;
4860: my $selstr;
4861: if ($k == $i) {
4862: $selstr = ' selected="selected" ';
4863: }
4864: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4865: }
4866: $datatable .= '</select></span></td><td>';
4867: if ($parent eq 'instcode' || $parent eq 'communities') {
4868: $datatable .= '<span class="LC_nobreak">'
4869: .$default_names{$parent}.'</span>';
4870: if ($parent eq 'instcode') {
4871: $datatable .= '<br /><span class="LC_nobreak">('
4872: .&mt('with institutional codes')
4873: .')</span></td><td'.$colattrib.'>';
4874: } else {
4875: $datatable .= '<table><tr><td>';
4876: }
4877: $datatable .= '<span class="LC_nobreak">'
4878: .'<label><input type="radio" name="'
4879: .$parent.'" value="1" checked="checked" />'
4880: .&mt('Display').'</label>';
4881: if ($parent eq 'instcode') {
4882: $datatable .= ' ';
4883: } else {
4884: $datatable .= '</span></td></tr><tr><td>'
4885: .'<span class="LC_nobreak">';
4886: }
4887: $datatable .= '<label><input type="radio" name="'
4888: .$parent.'" value="0" />'
4889: .&mt('Do not display').'</label></span>';
4890: if ($parent eq 'communities') {
4891: $datatable .= '</td></tr></table>';
4892: }
4893: $datatable .= '</td>';
4894: } else {
4895: $datatable .= $parent
4896: .' <span class="LC_nobreak"><label>'
4897: .'<input type="checkbox" name="deletecategory" '
4898: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4899: }
4900: my $depth = 1;
4901: push(@path,$parent);
4902: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4903: pop(@path);
4904: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4905: $itemcount ++;
4906: }
4907: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4908: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4909: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
4910: for (my $k=0; $k<=$maxnum; $k++) {
4911: my $vpos = $k+1;
4912: my $selstr;
4913: if ($k == $numtop) {
4914: $selstr = ' selected="selected" ';
4915: }
4916: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4917: }
4918: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
4919: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4920: .'</tr>'."\n";
4921: $itemcount ++;
4922: foreach my $default ('instcode','communities') {
4923: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4924: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4925: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4926: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4927: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4928: for (my $k=0; $k<=$maxnum; $k++) {
4929: my $vpos = $k+1;
4930: my $selstr;
4931: if ($k == $maxnum) {
4932: $selstr = ' selected="selected" ';
4933: }
4934: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4935: }
4936: $datatable .= '</select></span></td>'.
4937: '<td><span class="LC_nobreak">'.
4938: $default_names{$default}.'</span>';
4939: if ($default eq 'instcode') {
4940: $datatable .= '<br /><span class="LC_nobreak">('
4941: .&mt('with institutional codes').')</span>';
4942: }
4943: $datatable .= '</td>'
4944: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4945: .&mt('Display').'</label> '
4946: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
4947: .&mt('Do not display').'</label></span></td></tr>';
4948: }
4949: }
4950: }
4951: } else {
4952: $datatable .= &initialize_categories($itemcount);
4953: }
4954: } else {
4955: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
4956: .&initialize_categories($itemcount);
4957: }
4958: $$rowtotal += $itemcount;
4959: }
4960: return $datatable;
4961: }
4962:
4963: sub print_serverstatuses {
4964: my ($dom,$settings,$rowtotal) = @_;
4965: my $datatable;
4966: my @pages = &serverstatus_pages();
4967: my (%namedaccess,%machineaccess);
4968: foreach my $type (@pages) {
4969: $namedaccess{$type} = '';
4970: $machineaccess{$type}= '';
4971: }
4972: if (ref($settings) eq 'HASH') {
4973: foreach my $type (@pages) {
4974: if (exists($settings->{$type})) {
4975: if (ref($settings->{$type}) eq 'HASH') {
4976: foreach my $key (keys(%{$settings->{$type}})) {
4977: if ($key eq 'namedusers') {
4978: $namedaccess{$type} = $settings->{$type}->{$key};
4979: } elsif ($key eq 'machines') {
4980: $machineaccess{$type} = $settings->{$type}->{$key};
4981: }
4982: }
4983: }
4984: }
4985: }
4986: }
4987: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
4988: my $rownum = 0;
4989: my $css_class;
4990: foreach my $type (@pages) {
4991: $rownum ++;
4992: $css_class = $rownum%2?' class="LC_odd_row"':'';
4993: $datatable .= '<tr'.$css_class.'>'.
4994: '<td><span class="LC_nobreak">'.
4995: $titles->{$type}.'</span></td>'.
4996: '<td class="LC_left_item">'.
4997: '<input type="text" name="'.$type.'_namedusers" '.
4998: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
4999: '<td class="LC_right_item">'.
5000: '<span class="LC_nobreak">'.
5001: '<input type="text" name="'.$type.'_machines" '.
5002: 'value="'.$machineaccess{$type}.'" size="10" />'.
5003: '</td></tr>'."\n";
5004: }
5005: $$rowtotal += $rownum;
5006: return $datatable;
5007: }
5008:
5009: sub serverstatus_pages {
5010: return ('userstatus','lonstatus','loncron','server-status','codeversions',
5011: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
5012: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
5013: 'uniquecodes','diskusage');
5014: }
5015:
5016: sub defaults_javascript {
5017: my ($settings) = @_;
5018: my ($output,$jstext);
5019: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
5020: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
5021: if ($maxnum eq '') {
5022: $maxnum = 0;
5023: }
5024: $maxnum ++;
5025: $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
5026: return <<"ENDSCRIPT";
5027: <script type="text/javascript">
5028: // <![CDATA[
5029: function reorderTypes(form,caller) {
5030: var changedVal;
5031: $jstext
5032: var newpos = 'addinststatus_pos';
5033: var current = new Array;
5034: var maxh = $maxnum;
5035: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5036: var oldVal;
5037: if (caller == newpos) {
5038: changedVal = newitemVal;
5039: } else {
5040: var curritem = 'inststatus_pos_'+caller;
5041: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
5042: current[newitemVal] = newpos;
5043: }
5044: for (var i=0; i<inststatuses.length; i++) {
5045: if (inststatuses[i] != caller) {
5046: var elementName = 'inststatus_pos_'+inststatuses[i];
5047: if (form.elements[elementName]) {
5048: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5049: current[currVal] = elementName;
5050: }
5051: }
5052: }
5053: for (var j=0; j<maxh; j++) {
5054: if (current[j] == undefined) {
5055: oldVal = j;
5056: }
5057: }
5058: if (oldVal < changedVal) {
5059: for (var k=oldVal+1; k<=changedVal ; k++) {
5060: var elementName = current[k];
5061: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5062: }
5063: } else {
5064: for (var k=changedVal; k<oldVal; k++) {
5065: var elementName = current[k];
5066: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5067: }
5068: }
5069: return;
5070: }
5071:
5072: // ]]>
5073: </script>
5074:
5075: ENDSCRIPT
5076: }
5077: }
5078:
5079: sub coursecategories_javascript {
5080: my ($settings) = @_;
5081: my ($output,$jstext,$cathash);
5082: if (ref($settings) eq 'HASH') {
5083: $cathash = $settings->{'cats'};
5084: }
5085: if (ref($cathash) eq 'HASH') {
5086: my (@cats,@jsarray,%idx);
5087: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
5088: if (@jsarray > 0) {
5089: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
5090: for (my $i=0; $i<@jsarray; $i++) {
5091: if (ref($jsarray[$i]) eq 'ARRAY') {
5092: my $catstr = join('","',@{$jsarray[$i]});
5093: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
5094: }
5095: }
5096: }
5097: } else {
5098: $jstext = ' var categories = Array(1);'."\n".
5099: ' categories[0] = Array("instcode_pos");'."\n";
5100: }
5101: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
5102: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
5103: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category.');
5104: $output = <<"ENDSCRIPT";
5105: <script type="text/javascript">
5106: // <![CDATA[
5107: function reorderCats(form,parent,item,idx) {
5108: var changedVal;
5109: $jstext
5110: var newpos = 'addcategory_pos';
5111: if (parent == '') {
5112: var has_instcode = 0;
5113: var maxtop = categories[idx].length;
5114: for (var j=0; j<maxtop; j++) {
5115: if (categories[idx][j] == 'instcode::0') {
5116: has_instcode == 1;
5117: }
5118: }
5119: if (has_instcode == 0) {
5120: categories[idx][maxtop] = 'instcode_pos';
5121: }
5122: } else {
5123: newpos += '_'+parent;
5124: }
5125: var maxh = 1 + categories[idx].length;
5126: var current = new Array;
5127: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5128: if (item == newpos) {
5129: changedVal = newitemVal;
5130: } else {
5131: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5132: current[newitemVal] = newpos;
5133: }
5134: for (var i=0; i<categories[idx].length; i++) {
5135: var elementName = categories[idx][i];
5136: if (elementName != item) {
5137: if (form.elements[elementName]) {
5138: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5139: current[currVal] = elementName;
5140: }
5141: }
5142: }
5143: var oldVal;
5144: for (var j=0; j<maxh; j++) {
5145: if (current[j] == undefined) {
5146: oldVal = j;
5147: }
5148: }
5149: if (oldVal < changedVal) {
5150: for (var k=oldVal+1; k<=changedVal ; k++) {
5151: var elementName = current[k];
5152: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5153: }
5154: } else {
5155: for (var k=changedVal; k<oldVal; k++) {
5156: var elementName = current[k];
5157: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5158: }
5159: }
5160: return;
5161: }
5162:
5163: function categoryCheck(form) {
5164: if (form.elements['addcategory_name'].value == 'instcode') {
5165: alert('$instcode_reserved\\n$choose_again');
5166: return false;
5167: }
5168: if (form.elements['addcategory_name'].value == 'communities') {
5169: alert('$communities_reserved\\n$choose_again');
5170: return false;
5171: }
5172: return true;
5173: }
5174:
5175: // ]]>
5176: </script>
5177:
5178: ENDSCRIPT
5179: return $output;
5180: }
5181:
5182: sub initialize_categories {
5183: my ($itemcount) = @_;
5184: my ($datatable,$css_class,$chgstr);
5185: my %default_names = (
5186: instcode => 'Official courses (with institutional codes)',
5187: communities => 'Communities',
5188: );
5189: my $select0 = ' selected="selected"';
5190: my $select1 = '';
5191: foreach my $default ('instcode','communities') {
5192: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5193: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
5194: if ($default eq 'communities') {
5195: $select1 = $select0;
5196: $select0 = '';
5197: }
5198: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5199: .'<select name="'.$default.'_pos">'
5200: .'<option value="0"'.$select0.'>1</option>'
5201: .'<option value="1"'.$select1.'>2</option>'
5202: .'<option value="2">3</option></select> '
5203: .$default_names{$default}
5204: .'</span></td><td><span class="LC_nobreak">'
5205: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
5206: .&mt('Display').'</label> <label>'
5207: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
5208: .'</label></span></td></tr>';
5209: $itemcount ++;
5210: }
5211: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5212: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
5213: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5214: .'<select name="addcategory_pos"'.$chgstr.'>'
5215: .'<option value="0">1</option>'
5216: .'<option value="1">2</option>'
5217: .'<option value="2" selected="selected">3</option></select> '
5218: .&mt('Add category').'</td><td>'.&mt('Name:')
5219: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
5220: return $datatable;
5221: }
5222:
5223: sub build_category_rows {
5224: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
5225: my ($text,$name,$item,$chgstr);
5226: if (ref($cats) eq 'ARRAY') {
5227: my $maxdepth = scalar(@{$cats});
5228: if (ref($cats->[$depth]) eq 'HASH') {
5229: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
5230: my $numchildren = @{$cats->[$depth]{$parent}};
5231: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
5232: $text .= '<td><table class="LC_data_table">';
5233: my ($idxnum,$parent_name,$parent_item);
5234: my $higher = $depth - 1;
5235: if ($higher == 0) {
5236: $parent_name = &escape($parent).'::'.$higher;
5237: } else {
5238: if (ref($path) eq 'ARRAY') {
5239: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5240: }
5241: }
5242: $parent_item = 'addcategory_pos_'.$parent_name;
5243: for (my $j=0; $j<=$numchildren; $j++) {
5244: if ($j < $numchildren) {
5245: $name = $cats->[$depth]{$parent}[$j];
5246: $item = &escape($name).':'.&escape($parent).':'.$depth;
5247: $idxnum = $idx->{$item};
5248: } else {
5249: $name = $parent_name;
5250: $item = $parent_item;
5251: }
5252: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
5253: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
5254: for (my $i=0; $i<=$numchildren; $i++) {
5255: my $vpos = $i+1;
5256: my $selstr;
5257: if ($j == $i) {
5258: $selstr = ' selected="selected" ';
5259: }
5260: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
5261: }
5262: $text .= '</select> ';
5263: if ($j < $numchildren) {
5264: my $deeper = $depth+1;
5265: $text .= $name.' '
5266: .'<label><input type="checkbox" name="deletecategory" value="'
5267: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
5268: if(ref($path) eq 'ARRAY') {
5269: push(@{$path},$name);
5270: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
5271: pop(@{$path});
5272: }
5273: } else {
5274: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
5275: if ($j == $numchildren) {
5276: $text .= $name;
5277: } else {
5278: $text .= $item;
5279: }
5280: $text .= '" value="" />';
5281: }
5282: $text .= '</td></tr>';
5283: }
5284: $text .= '</table></td>';
5285: } else {
5286: my $higher = $depth-1;
5287: if ($higher == 0) {
5288: $name = &escape($parent).'::'.$higher;
5289: } else {
5290: if (ref($path) eq 'ARRAY') {
5291: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5292: }
5293: }
5294: my $colspan;
5295: if ($parent ne 'instcode') {
5296: $colspan = $maxdepth - $depth - 1;
5297: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
5298: }
5299: }
5300: }
5301: }
5302: return $text;
5303: }
5304:
5305: sub modifiable_userdata_row {
5306: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
5307: my ($role,$rolename,$statustype);
5308: $role = $item;
5309: if ($context eq 'cancreate') {
5310: if ($item =~ /^emailusername_(.+)$/) {
5311: $statustype = $1;
5312: $role = 'emailusername';
5313: if (ref($usertypes) eq 'HASH') {
5314: if ($usertypes->{$statustype}) {
5315: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
5316: } else {
5317: $rolename = &mt('Data provided by user');
5318: }
5319: }
5320: }
5321: } elsif ($context eq 'selfcreate') {
5322: if (ref($usertypes) eq 'HASH') {
5323: $rolename = $usertypes->{$role};
5324: } else {
5325: $rolename = $role;
5326: }
5327: } else {
5328: if ($role eq 'cr') {
5329: $rolename = &mt('Custom role');
5330: } else {
5331: $rolename = &Apache::lonnet::plaintext($role);
5332: }
5333: }
5334: my (@fields,%fieldtitles);
5335: if (ref($fieldsref) eq 'ARRAY') {
5336: @fields = @{$fieldsref};
5337: } else {
5338: @fields = ('lastname','firstname','middlename','generation',
5339: 'permanentemail','id');
5340: }
5341: if ((ref($titlesref) eq 'HASH')) {
5342: %fieldtitles = %{$titlesref};
5343: } else {
5344: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5345: }
5346: my $output;
5347: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5348: $output = '<tr '.$css_class.'>'.
5349: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
5350: '<td class="LC_left_item" colspan="2"><table>';
5351: my $rem;
5352: my %checks;
5353: if (ref($settings) eq 'HASH') {
5354: if (ref($settings->{$context}) eq 'HASH') {
5355: if (ref($settings->{$context}->{$role}) eq 'HASH') {
5356: my $hashref = $settings->{$context}->{$role};
5357: if ($role eq 'emailusername') {
5358: if ($statustype) {
5359: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
5360: $hashref = $settings->{$context}->{$role}->{$statustype};
5361: if (ref($hashref) eq 'HASH') {
5362: foreach my $field (@fields) {
5363: if ($hashref->{$field}) {
5364: $checks{$field} = $hashref->{$field};
5365: }
5366: }
5367: }
5368: }
5369: }
5370: } else {
5371: if (ref($hashref) eq 'HASH') {
5372: foreach my $field (@fields) {
5373: if ($hashref->{$field}) {
5374: $checks{$field} = ' checked="checked" ';
5375: }
5376: }
5377: }
5378: }
5379: }
5380: }
5381: }
5382:
5383: for (my $i=0; $i<@fields; $i++) {
5384: my $rem = $i%($numinrow);
5385: if ($rem == 0) {
5386: if ($i > 0) {
5387: $output .= '</tr>';
5388: }
5389: $output .= '<tr>';
5390: }
5391: my $check = ' ';
5392: unless ($role eq 'emailusername') {
5393: if (exists($checks{$fields[$i]})) {
5394: $check = $checks{$fields[$i]}
5395: } else {
5396: if ($role eq 'st') {
5397: if (ref($settings) ne 'HASH') {
5398: $check = ' checked="checked" ';
5399: }
5400: }
5401: }
5402: }
5403: $output .= '<td class="LC_left_item">'.
5404: '<span class="LC_nobreak">';
5405: if ($role eq 'emailusername') {
5406: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
5407: $checks{$fields[$i]} = 'omit';
5408: }
5409: foreach my $option ('required','optional','omit') {
5410: my $checked='';
5411: if ($checks{$fields[$i]} eq $option) {
5412: $checked='checked="checked" ';
5413: }
5414: $output .= '<label>'.
5415: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
5416: &mt($option).'</label>'.(' ' x2);
5417: }
5418: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
5419: } else {
5420: $output .= '<label>'.
5421: '<input type="checkbox" name="canmodify_'.$role.'" '.
5422: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
5423: '</label>';
5424: }
5425: $output .= '</span></td>';
5426: $rem = @fields%($numinrow);
5427: }
5428: my $colsleft = $numinrow - $rem;
5429: if ($colsleft > 1 ) {
5430: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5431: ' </td>';
5432: } elsif ($colsleft == 1) {
5433: $output .= '<td class="LC_left_item"> </td>';
5434: }
5435: $output .= '</tr></table></td></tr>';
5436: return $output;
5437: }
5438:
5439: sub insttypes_row {
5440: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
5441: my %lt = &Apache::lonlocal::texthash (
5442: cansearch => 'Users allowed to search',
5443: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
5444: lockablenames => 'User preference to lock name',
5445: );
5446: my $showdom;
5447: if ($context eq 'cansearch') {
5448: $showdom = ' ('.$dom.')';
5449: }
5450: my $class = 'LC_left_item';
5451: if ($context eq 'statustocreate') {
5452: $class = 'LC_right_item';
5453: }
5454: my $css_class = ' class="LC_odd_row"';
5455: if ($rownum ne '') {
5456: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
5457: }
5458: my $output = '<tr'.$css_class.'>'.
5459: '<td>'.$lt{$context}.$showdom.
5460: '</td><td class="'.$class.'" colspan="2"><table>';
5461: my $rem;
5462: if (ref($types) eq 'ARRAY') {
5463: for (my $i=0; $i<@{$types}; $i++) {
5464: if (defined($usertypes->{$types->[$i]})) {
5465: my $rem = $i%($numinrow);
5466: if ($rem == 0) {
5467: if ($i > 0) {
5468: $output .= '</tr>';
5469: }
5470: $output .= '<tr>';
5471: }
5472: my $check = ' ';
5473: if (ref($settings) eq 'HASH') {
5474: if (ref($settings->{$context}) eq 'ARRAY') {
5475: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
5476: $check = ' checked="checked" ';
5477: }
5478: } elsif ($context eq 'statustocreate') {
5479: $check = ' checked="checked" ';
5480: }
5481: }
5482: $output .= '<td class="LC_left_item">'.
5483: '<span class="LC_nobreak"><label>'.
5484: '<input type="checkbox" name="'.$context.'" '.
5485: 'value="'.$types->[$i].'"'.$check.'/>'.
5486: $usertypes->{$types->[$i]}.'</label></span></td>';
5487: }
5488: }
5489: $rem = @{$types}%($numinrow);
5490: }
5491: my $colsleft = $numinrow - $rem;
5492: if (($rem == 0) && (@{$types} > 0)) {
5493: $output .= '<tr>';
5494: }
5495: if ($colsleft > 1) {
5496: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5497: } else {
5498: $output .= '<td class="LC_left_item">';
5499: }
5500: my $defcheck = ' ';
5501: if (ref($settings) eq 'HASH') {
5502: if (ref($settings->{$context}) eq 'ARRAY') {
5503: if (grep(/^default$/,@{$settings->{$context}})) {
5504: $defcheck = ' checked="checked" ';
5505: }
5506: } elsif ($context eq 'statustocreate') {
5507: $defcheck = ' checked="checked" ';
5508: }
5509: }
5510: $output .= '<span class="LC_nobreak"><label>'.
5511: '<input type="checkbox" name="'.$context.'" '.
5512: 'value="default"'.$defcheck.'/>'.
5513: $othertitle.'</label></span></td>'.
5514: '</tr></table></td></tr>';
5515: return $output;
5516: }
5517:
5518: sub sorted_searchtitles {
5519: my %searchtitles = &Apache::lonlocal::texthash(
5520: 'uname' => 'username',
5521: 'lastname' => 'last name',
5522: 'lastfirst' => 'last name, first name',
5523: );
5524: my @titleorder = ('uname','lastname','lastfirst');
5525: return (\%searchtitles,\@titleorder);
5526: }
5527:
5528: sub sorted_searchtypes {
5529: my %srchtypes_desc = (
5530: exact => 'is exact match',
5531: contains => 'contains ..',
5532: begins => 'begins with ..',
5533: );
5534: my @srchtypeorder = ('exact','begins','contains');
5535: return (\%srchtypes_desc,\@srchtypeorder);
5536: }
5537:
5538: sub usertype_update_row {
5539: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
5540: my $datatable;
5541: my $numinrow = 4;
5542: foreach my $type (@{$types}) {
5543: if (defined($usertypes->{$type})) {
5544: $$rownums ++;
5545: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
5546: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
5547: '</td><td class="LC_left_item"><table>';
5548: for (my $i=0; $i<@{$fields}; $i++) {
5549: my $rem = $i%($numinrow);
5550: if ($rem == 0) {
5551: if ($i > 0) {
5552: $datatable .= '</tr>';
5553: }
5554: $datatable .= '<tr>';
5555: }
5556: my $check = ' ';
5557: if (ref($settings) eq 'HASH') {
5558: if (ref($settings->{'fields'}) eq 'HASH') {
5559: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
5560: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
5561: $check = ' checked="checked" ';
5562: }
5563: }
5564: }
5565: }
5566:
5567: if ($i == @{$fields}-1) {
5568: my $colsleft = $numinrow - $rem;
5569: if ($colsleft > 1) {
5570: $datatable .= '<td colspan="'.$colsleft.'">';
5571: } else {
5572: $datatable .= '<td>';
5573: }
5574: } else {
5575: $datatable .= '<td>';
5576: }
5577: $datatable .= '<span class="LC_nobreak"><label>'.
5578: '<input type="checkbox" name="updateable_'.$type.
5579: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
5580: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
5581: }
5582: $datatable .= '</tr></table></td></tr>';
5583: }
5584: }
5585: return $datatable;
5586: }
5587:
5588: sub modify_login {
5589: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
5590: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
5591: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
5592: %title = ( coursecatalog => 'Display course catalog',
5593: adminmail => 'Display administrator E-mail address',
5594: helpdesk => 'Display "Contact Helpdesk" link',
5595: newuser => 'Link for visitors to create a user account',
5596: loginheader => 'Log-in box header');
5597: @offon = ('off','on');
5598: if (ref($domconfig{login}) eq 'HASH') {
5599: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
5600: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
5601: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
5602: }
5603: }
5604: }
5605: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
5606: \%domconfig,\%loginhash);
5607: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
5608: foreach my $item (@toggles) {
5609: $loginhash{login}{$item} = $env{'form.'.$item};
5610: }
5611: $loginhash{login}{loginheader} = $env{'form.loginheader'};
5612: if (ref($colchanges{'login'}) eq 'HASH') {
5613: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
5614: \%loginhash);
5615: }
5616:
5617: my %servers = &Apache::lonnet::internet_dom_servers($dom);
5618: my @loginvia_attribs = ('serverpath','custompath','exempt');
5619: if (keys(%servers) > 1) {
5620: foreach my $lonhost (keys(%servers)) {
5621: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
5622: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
5623: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
5624: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
5625: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
5626: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5627: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5628: $changes{'loginvia'}{$lonhost} = 1;
5629: } else {
5630: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
5631: $changes{'loginvia'}{$lonhost} = 1;
5632: }
5633: } else {
5634: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5635: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5636: $changes{'loginvia'}{$lonhost} = 1;
5637: }
5638: }
5639: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
5640: foreach my $item (@loginvia_attribs) {
5641: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
5642: }
5643: } else {
5644: foreach my $item (@loginvia_attribs) {
5645: my $new = $env{'form.'.$lonhost.'_'.$item};
5646: if (($item eq 'serverpath') && ($new eq 'custom')) {
5647: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
5648: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5649: $new = '/';
5650: }
5651: }
5652: if (($item eq 'custompath') &&
5653: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5654: $new = '';
5655: }
5656: if ($new ne $curr_loginvia{$lonhost}{$item}) {
5657: $changes{'loginvia'}{$lonhost} = 1;
5658: }
5659: if ($item eq 'exempt') {
5660: $new =~ s/^\s+//;
5661: $new =~ s/\s+$//;
5662: my @poss_ips = split(/\s*[,:]\s*/,$new);
5663: my @okips;
5664: foreach my $ip (@poss_ips) {
5665: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
5666: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
5667: push(@okips,$ip);
5668: }
5669: }
5670: }
5671: if (@okips > 0) {
5672: $new = join(',',@okips);
5673: } else {
5674: $new = '';
5675: }
5676: }
5677: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5678: }
5679: }
5680: } else {
5681: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5682: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5683: $changes{'loginvia'}{$lonhost} = 1;
5684: foreach my $item (@loginvia_attribs) {
5685: my $new = $env{'form.'.$lonhost.'_'.$item};
5686: if (($item eq 'serverpath') && ($new eq 'custom')) {
5687: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5688: $new = '/';
5689: }
5690: }
5691: if (($item eq 'custompath') &&
5692: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5693: $new = '';
5694: }
5695: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5696: }
5697: }
5698: }
5699: }
5700: }
5701:
5702: my $servadm = $r->dir_config('lonAdmEMail');
5703: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
5704: if (ref($domconfig{'login'}) eq 'HASH') {
5705: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
5706: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
5707: if ($lang eq 'nolang') {
5708: push(@currlangs,$lang);
5709: } elsif (defined($langchoices{$lang})) {
5710: push(@currlangs,$lang);
5711: } else {
5712: next;
5713: }
5714: }
5715: }
5716: }
5717: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
5718: if (@currlangs > 0) {
5719: foreach my $lang (@currlangs) {
5720: if (grep(/^\Q$lang\E$/,@delurls)) {
5721: $changes{'helpurl'}{$lang} = 1;
5722: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
5723: $changes{'helpurl'}{$lang} = 1;
5724: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
5725: push(@newlangs,$lang);
5726: } else {
5727: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5728: }
5729: }
5730: }
5731: unless (grep(/^nolang$/,@currlangs)) {
5732: if ($env{'form.loginhelpurl_nolang.filename'}) {
5733: $changes{'helpurl'}{'nolang'} = 1;
5734: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
5735: push(@newlangs,'nolang');
5736: }
5737: }
5738: if ($env{'form.loginhelpurl_add_lang'}) {
5739: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
5740: ($env{'form.loginhelpurl_add_file.filename'})) {
5741: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
5742: $addedfile = $env{'form.loginhelpurl_add_lang'};
5743: }
5744: }
5745: if ((@newlangs > 0) || ($addedfile)) {
5746: my $error;
5747: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
5748: if ($configuserok eq 'ok') {
5749: if ($switchserver) {
5750: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
5751: } elsif ($author_ok eq 'ok') {
5752: my @allnew = @newlangs;
5753: if ($addedfile ne '') {
5754: push(@allnew,$addedfile);
5755: }
5756: foreach my $lang (@allnew) {
5757: my $formelem = 'loginhelpurl_'.$lang;
5758: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
5759: $formelem = 'loginhelpurl_add_file';
5760: }
5761: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
5762: "help/$lang",'','',$newfile{$lang});
5763: if ($result eq 'ok') {
5764: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
5765: $changes{'helpurl'}{$lang} = 1;
5766: } else {
5767: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
5768: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
5769: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
5770: (!grep(/^\Q$lang\E$/,@delurls))) {
5771:
5772: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5773: }
5774: }
5775: }
5776: } else {
5777: $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);
5778: }
5779: } else {
5780: $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);
5781: }
5782: if ($error) {
5783: &Apache::lonnet::logthis($error);
5784: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
5785: }
5786: }
5787: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
5788:
5789: my $defaulthelpfile = '/adm/loginproblems.html';
5790: my $defaulttext = &mt('Default in use');
5791:
5792: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
5793: $dom);
5794: if ($putresult eq 'ok') {
5795: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
5796: my %defaultchecked = (
5797: 'coursecatalog' => 'on',
5798: 'helpdesk' => 'on',
5799: 'adminmail' => 'off',
5800: 'newuser' => 'off',
5801: );
5802: if (ref($domconfig{'login'}) eq 'HASH') {
5803: foreach my $item (@toggles) {
5804: if ($defaultchecked{$item} eq 'on') {
5805: if (($domconfig{'login'}{$item} eq '0') &&
5806: ($env{'form.'.$item} eq '1')) {
5807: $changes{$item} = 1;
5808: } elsif (($domconfig{'login'}{$item} eq '' ||
5809: $domconfig{'login'}{$item} eq '1') &&
5810: ($env{'form.'.$item} eq '0')) {
5811: $changes{$item} = 1;
5812: }
5813: } elsif ($defaultchecked{$item} eq 'off') {
5814: if (($domconfig{'login'}{$item} eq '1') &&
5815: ($env{'form.'.$item} eq '0')) {
5816: $changes{$item} = 1;
5817: } elsif (($domconfig{'login'}{$item} eq '' ||
5818: $domconfig{'login'}{$item} eq '0') &&
5819: ($env{'form.'.$item} eq '1')) {
5820: $changes{$item} = 1;
5821: }
5822: }
5823: }
5824: }
5825: if (keys(%changes) > 0 || $colchgtext) {
5826: &Apache::loncommon::devalidate_domconfig_cache($dom);
5827: if (ref($lastactref) eq 'HASH') {
5828: $lastactref->{'domainconfig'} = 1;
5829: }
5830: $resulttext = &mt('Changes made:').'<ul>';
5831: foreach my $item (sort(keys(%changes))) {
5832: if ($item eq 'loginvia') {
5833: if (ref($changes{$item}) eq 'HASH') {
5834: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
5835: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
5836: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
5837: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
5838: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
5839: $protocol = 'http' if ($protocol ne 'https');
5840: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
5841:
5842: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
5843: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
5844: } else {
5845: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
5846: }
5847: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
5848: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
5849: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
5850: }
5851: $resulttext .= '</li>';
5852: } else {
5853: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
5854: }
5855: } else {
5856: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
5857: }
5858: }
5859: $resulttext .= '</ul></li>';
5860: }
5861: } elsif ($item eq 'helpurl') {
5862: if (ref($changes{$item}) eq 'HASH') {
5863: foreach my $lang (sort(keys(%{$changes{$item}}))) {
5864: if (grep(/^\Q$lang\E$/,@delurls)) {
5865: my ($chg,$link);
5866: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
5867: if ($lang eq 'nolang') {
5868: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
5869: } else {
5870: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
5871: }
5872: $resulttext .= '<li>'.$chg.'</li>';
5873: } else {
5874: my $chg;
5875: if ($lang eq 'nolang') {
5876: $chg = &mt('custom log-in help file for no preferred language');
5877: } else {
5878: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
5879: }
5880: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
5881: $loginhash{'login'}{'helpurl'}{$lang}.
5882: '?inhibitmenu=yes',$chg,600,500).
5883: '</li>';
5884: }
5885: }
5886: }
5887: } elsif ($item eq 'captcha') {
5888: if (ref($loginhash{'login'}) eq 'HASH') {
5889: my $chgtxt;
5890: if ($loginhash{'login'}{$item} eq 'notused') {
5891: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
5892: } else {
5893: my %captchas = &captcha_phrases();
5894: if ($captchas{$loginhash{'login'}{$item}}) {
5895: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
5896: } else {
5897: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
5898: }
5899: }
5900: $resulttext .= '<li>'.$chgtxt.'</li>';
5901: }
5902: } elsif ($item eq 'recaptchakeys') {
5903: if (ref($loginhash{'login'}) eq 'HASH') {
5904: my ($privkey,$pubkey);
5905: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
5906: $pubkey = $loginhash{'login'}{$item}{'public'};
5907: $privkey = $loginhash{'login'}{$item}{'private'};
5908: }
5909: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
5910: if (!$pubkey) {
5911: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
5912: } else {
5913: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
5914: }
5915: if (!$privkey) {
5916: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
5917: } else {
5918: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
5919: }
5920: $chgtxt .= '</ul>';
5921: $resulttext .= '<li>'.$chgtxt.'</li>';
5922: }
5923: } else {
5924: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
5925: }
5926: }
5927: $resulttext .= $colchgtext.'</ul>';
5928: } else {
5929: $resulttext = &mt('No changes made to log-in page settings');
5930: }
5931: } else {
5932: $resulttext = '<span class="LC_error">'.
5933: &mt('An error occurred: [_1]',$putresult).'</span>';
5934: }
5935: if ($errors) {
5936: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
5937: $errors.'</ul>';
5938: }
5939: return $resulttext;
5940: }
5941:
5942: sub color_font_choices {
5943: my %choices =
5944: &Apache::lonlocal::texthash (
5945: img => "Header",
5946: bgs => "Background colors",
5947: links => "Link colors",
5948: images => "Images",
5949: font => "Font color",
5950: fontmenu => "Font menu",
5951: pgbg => "Page",
5952: tabbg => "Header",
5953: sidebg => "Border",
5954: link => "Link",
5955: alink => "Active link",
5956: vlink => "Visited link",
5957: );
5958: return %choices;
5959: }
5960:
5961: sub modify_rolecolors {
5962: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
5963: my ($resulttext,%rolehash);
5964: $rolehash{'rolecolors'} = {};
5965: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
5966: if ($domconfig{'rolecolors'} eq '') {
5967: $domconfig{'rolecolors'} = {};
5968: }
5969: }
5970: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
5971: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
5972: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
5973: $dom);
5974: if ($putresult eq 'ok') {
5975: if (keys(%changes) > 0) {
5976: &Apache::loncommon::devalidate_domconfig_cache($dom);
5977: if (ref($lastactref) eq 'HASH') {
5978: $lastactref->{'domainconfig'} = 1;
5979: }
5980: $resulttext = &display_colorchgs($dom,\%changes,$roles,
5981: $rolehash{'rolecolors'});
5982: } else {
5983: $resulttext = &mt('No changes made to default color schemes');
5984: }
5985: } else {
5986: $resulttext = '<span class="LC_error">'.
5987: &mt('An error occurred: [_1]',$putresult).'</span>';
5988: }
5989: if ($errors) {
5990: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5991: $errors.'</ul>';
5992: }
5993: return $resulttext;
5994: }
5995:
5996: sub modify_colors {
5997: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
5998: my (%changes,%choices);
5999: my @bgs;
6000: my @links = ('link','alink','vlink');
6001: my @logintext;
6002: my @images;
6003: my $servadm = $r->dir_config('lonAdmEMail');
6004: my $errors;
6005: my %defaults;
6006: foreach my $role (@{$roles}) {
6007: if ($role eq 'login') {
6008: %choices = &login_choices();
6009: @logintext = ('textcol','bgcol');
6010: } else {
6011: %choices = &color_font_choices();
6012: }
6013: if ($role eq 'login') {
6014: @images = ('img','logo','domlogo','login');
6015: @bgs = ('pgbg','mainbg','sidebg');
6016: } else {
6017: @images = ('img');
6018: @bgs = ('pgbg','tabbg','sidebg');
6019: }
6020: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
6021: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
6022: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
6023: }
6024: if ($role eq 'login') {
6025: foreach my $item (@logintext) {
6026: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6027: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6028: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6029: }
6030: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
6031: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6032: }
6033: }
6034: } else {
6035: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
6036: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
6037: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
6038: }
6039: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
6040: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
6041: }
6042: }
6043: foreach my $item (@bgs) {
6044: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6045: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6046: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6047: }
6048: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
6049: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6050: }
6051: }
6052: foreach my $item (@links) {
6053: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6054: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6055: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6056: }
6057: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
6058: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6059: }
6060: }
6061: my ($configuserok,$author_ok,$switchserver) =
6062: &config_check($dom,$confname,$servadm);
6063: my ($width,$height) = &thumb_dimensions();
6064: if (ref($domconfig->{$role}) ne 'HASH') {
6065: $domconfig->{$role} = {};
6066: }
6067: foreach my $img (@images) {
6068: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
6069: if (defined($env{'form.login_showlogo_'.$img})) {
6070: $confhash->{$role}{'showlogo'}{$img} = 1;
6071: } else {
6072: $confhash->{$role}{'showlogo'}{$img} = 0;
6073: }
6074: }
6075: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
6076: && !defined($domconfig->{$role}{$img})
6077: && !$env{'form.'.$role.'_del_'.$img}
6078: && $env{'form.'.$role.'_import_'.$img}) {
6079: # import the old configured image from the .tab setting
6080: # if they haven't provided a new one
6081: $domconfig->{$role}{$img} =
6082: $env{'form.'.$role.'_import_'.$img};
6083: }
6084: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
6085: my $error;
6086: if ($configuserok eq 'ok') {
6087: if ($switchserver) {
6088: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
6089: } else {
6090: if ($author_ok eq 'ok') {
6091: my ($result,$logourl) =
6092: &publishlogo($r,'upload',$role.'_'.$img,
6093: $dom,$confname,$img,$width,$height);
6094: if ($result eq 'ok') {
6095: $confhash->{$role}{$img} = $logourl;
6096: $changes{$role}{'images'}{$img} = 1;
6097: } else {
6098: $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);
6099: }
6100: } else {
6101: $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);
6102: }
6103: }
6104: } else {
6105: $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);
6106: }
6107: if ($error) {
6108: &Apache::lonnet::logthis($error);
6109: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6110: }
6111: } elsif ($domconfig->{$role}{$img} ne '') {
6112: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
6113: my $error;
6114: if ($configuserok eq 'ok') {
6115: # is confname an author?
6116: if ($switchserver eq '') {
6117: if ($author_ok eq 'ok') {
6118: my ($result,$logourl) =
6119: &publishlogo($r,'copy',$domconfig->{$role}{$img},
6120: $dom,$confname,$img,$width,$height);
6121: if ($result eq 'ok') {
6122: $confhash->{$role}{$img} = $logourl;
6123: $changes{$role}{'images'}{$img} = 1;
6124: }
6125: }
6126: }
6127: }
6128: }
6129: }
6130: }
6131: if (ref($domconfig) eq 'HASH') {
6132: if (ref($domconfig->{$role}) eq 'HASH') {
6133: foreach my $img (@images) {
6134: if ($domconfig->{$role}{$img} ne '') {
6135: if ($env{'form.'.$role.'_del_'.$img}) {
6136: $confhash->{$role}{$img} = '';
6137: $changes{$role}{'images'}{$img} = 1;
6138: } else {
6139: if ($confhash->{$role}{$img} eq '') {
6140: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
6141: }
6142: }
6143: } else {
6144: if ($env{'form.'.$role.'_del_'.$img}) {
6145: $confhash->{$role}{$img} = '';
6146: $changes{$role}{'images'}{$img} = 1;
6147: }
6148: }
6149: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
6150: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
6151: if ($confhash->{$role}{'showlogo'}{$img} ne
6152: $domconfig->{$role}{'showlogo'}{$img}) {
6153: $changes{$role}{'showlogo'}{$img} = 1;
6154: }
6155: } else {
6156: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6157: $changes{$role}{'showlogo'}{$img} = 1;
6158: }
6159: }
6160: }
6161: }
6162: if ($domconfig->{$role}{'font'} ne '') {
6163: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
6164: $changes{$role}{'font'} = 1;
6165: }
6166: } else {
6167: if ($confhash->{$role}{'font'}) {
6168: $changes{$role}{'font'} = 1;
6169: }
6170: }
6171: if ($role ne 'login') {
6172: if ($domconfig->{$role}{'fontmenu'} ne '') {
6173: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
6174: $changes{$role}{'fontmenu'} = 1;
6175: }
6176: } else {
6177: if ($confhash->{$role}{'fontmenu'}) {
6178: $changes{$role}{'fontmenu'} = 1;
6179: }
6180: }
6181: }
6182: foreach my $item (@bgs) {
6183: if ($domconfig->{$role}{$item} ne '') {
6184: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6185: $changes{$role}{'bgs'}{$item} = 1;
6186: }
6187: } else {
6188: if ($confhash->{$role}{$item}) {
6189: $changes{$role}{'bgs'}{$item} = 1;
6190: }
6191: }
6192: }
6193: foreach my $item (@links) {
6194: if ($domconfig->{$role}{$item} ne '') {
6195: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6196: $changes{$role}{'links'}{$item} = 1;
6197: }
6198: } else {
6199: if ($confhash->{$role}{$item}) {
6200: $changes{$role}{'links'}{$item} = 1;
6201: }
6202: }
6203: }
6204: foreach my $item (@logintext) {
6205: if ($domconfig->{$role}{$item} ne '') {
6206: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6207: $changes{$role}{'logintext'}{$item} = 1;
6208: }
6209: } else {
6210: if ($confhash->{$role}{$item}) {
6211: $changes{$role}{'logintext'}{$item} = 1;
6212: }
6213: }
6214: }
6215: } else {
6216: &default_change_checker($role,\@images,\@links,\@bgs,
6217: \@logintext,$confhash,\%changes);
6218: }
6219: } else {
6220: &default_change_checker($role,\@images,\@links,\@bgs,
6221: \@logintext,$confhash,\%changes);
6222: }
6223: }
6224: return ($errors,%changes);
6225: }
6226:
6227: sub config_check {
6228: my ($dom,$confname,$servadm) = @_;
6229: my ($configuserok,$author_ok,$switchserver,%currroles);
6230: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
6231: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
6232: $confname,$servadm);
6233: if ($configuserok eq 'ok') {
6234: $switchserver = &check_switchserver($dom,$confname);
6235: if ($switchserver eq '') {
6236: $author_ok = &check_authorstatus($dom,$confname,%currroles);
6237: }
6238: }
6239: return ($configuserok,$author_ok,$switchserver);
6240: }
6241:
6242: sub default_change_checker {
6243: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
6244: foreach my $item (@{$links}) {
6245: if ($confhash->{$role}{$item}) {
6246: $changes->{$role}{'links'}{$item} = 1;
6247: }
6248: }
6249: foreach my $item (@{$bgs}) {
6250: if ($confhash->{$role}{$item}) {
6251: $changes->{$role}{'bgs'}{$item} = 1;
6252: }
6253: }
6254: foreach my $item (@{$logintext}) {
6255: if ($confhash->{$role}{$item}) {
6256: $changes->{$role}{'logintext'}{$item} = 1;
6257: }
6258: }
6259: foreach my $img (@{$images}) {
6260: if ($env{'form.'.$role.'_del_'.$img}) {
6261: $confhash->{$role}{$img} = '';
6262: $changes->{$role}{'images'}{$img} = 1;
6263: }
6264: if ($role eq 'login') {
6265: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6266: $changes->{$role}{'showlogo'}{$img} = 1;
6267: }
6268: }
6269: }
6270: if ($confhash->{$role}{'font'}) {
6271: $changes->{$role}{'font'} = 1;
6272: }
6273: }
6274:
6275: sub display_colorchgs {
6276: my ($dom,$changes,$roles,$confhash) = @_;
6277: my (%choices,$resulttext);
6278: if (!grep(/^login$/,@{$roles})) {
6279: $resulttext = &mt('Changes made:').'<br />';
6280: }
6281: foreach my $role (@{$roles}) {
6282: if ($role eq 'login') {
6283: %choices = &login_choices();
6284: } else {
6285: %choices = &color_font_choices();
6286: }
6287: if (ref($changes->{$role}) eq 'HASH') {
6288: if ($role ne 'login') {
6289: $resulttext .= '<h4>'.&mt($role).'</h4>';
6290: }
6291: foreach my $key (sort(keys(%{$changes->{$role}}))) {
6292: if ($role ne 'login') {
6293: $resulttext .= '<ul>';
6294: }
6295: if (ref($changes->{$role}{$key}) eq 'HASH') {
6296: if ($role ne 'login') {
6297: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
6298: }
6299: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
6300: if (($role eq 'login') && ($key eq 'showlogo')) {
6301: if ($confhash->{$role}{$key}{$item}) {
6302: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
6303: } else {
6304: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
6305: }
6306: } elsif ($confhash->{$role}{$item} eq '') {
6307: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
6308: } else {
6309: my $newitem = $confhash->{$role}{$item};
6310: if ($key eq 'images') {
6311: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
6312: }
6313: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
6314: }
6315: }
6316: if ($role ne 'login') {
6317: $resulttext .= '</ul></li>';
6318: }
6319: } else {
6320: if ($confhash->{$role}{$key} eq '') {
6321: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
6322: } else {
6323: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
6324: }
6325: }
6326: if ($role ne 'login') {
6327: $resulttext .= '</ul>';
6328: }
6329: }
6330: }
6331: }
6332: return $resulttext;
6333: }
6334:
6335: sub thumb_dimensions {
6336: return ('200','50');
6337: }
6338:
6339: sub check_dimensions {
6340: my ($inputfile) = @_;
6341: my ($fullwidth,$fullheight);
6342: if ($inputfile =~ m|^[/\w.\-]+$|) {
6343: if (open(PIPE,"identify $inputfile 2>&1 |")) {
6344: my $imageinfo = <PIPE>;
6345: if (!close(PIPE)) {
6346: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
6347: }
6348: chomp($imageinfo);
6349: my ($fullsize) =
6350: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
6351: if ($fullsize) {
6352: ($fullwidth,$fullheight) = split(/x/,$fullsize);
6353: }
6354: }
6355: }
6356: return ($fullwidth,$fullheight);
6357: }
6358:
6359: sub check_configuser {
6360: my ($uhome,$dom,$confname,$servadm) = @_;
6361: my ($configuserok,%currroles);
6362: if ($uhome eq 'no_host') {
6363: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
6364: my $configpass = &LONCAPA::Enrollment::create_password();
6365: $configuserok =
6366: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
6367: $configpass,'','','','','',undef,$servadm);
6368: } else {
6369: $configuserok = 'ok';
6370: %currroles =
6371: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
6372: }
6373: return ($configuserok,%currroles);
6374: }
6375:
6376: sub check_authorstatus {
6377: my ($dom,$confname,%currroles) = @_;
6378: my $author_ok;
6379: if (!$currroles{':'.$dom.':au'}) {
6380: my $start = time;
6381: my $end = 0;
6382: $author_ok =
6383: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
6384: 'au',$end,$start,'','','domconfig');
6385: } else {
6386: $author_ok = 'ok';
6387: }
6388: return $author_ok;
6389: }
6390:
6391: sub publishlogo {
6392: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
6393: my ($output,$fname,$logourl);
6394: if ($action eq 'upload') {
6395: $fname=$env{'form.'.$formname.'.filename'};
6396: chop($env{'form.'.$formname});
6397: } else {
6398: ($fname) = ($formname =~ /([^\/]+)$/);
6399: }
6400: if ($savefileas ne '') {
6401: $fname = $savefileas;
6402: }
6403: $fname=&Apache::lonnet::clean_filename($fname);
6404: # See if there is anything left
6405: unless ($fname) { return ('error: no uploaded file'); }
6406: $fname="$subdir/$fname";
6407: my $docroot=$r->dir_config('lonDocRoot');
6408: my $filepath="$docroot/priv";
6409: my $relpath = "$dom/$confname";
6410: my ($fnamepath,$file,$fetchthumb);
6411: $file=$fname;
6412: if ($fname=~m|/|) {
6413: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
6414: }
6415: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
6416: my $count;
6417: for ($count=5;$count<=$#parts;$count++) {
6418: $filepath.="/$parts[$count]";
6419: if ((-e $filepath)!=1) {
6420: mkdir($filepath,02770);
6421: }
6422: }
6423: # Check for bad extension and disallow upload
6424: if ($file=~/\.(\w+)$/ &&
6425: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
6426: $output =
6427: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
6428: } elsif ($file=~/\.(\w+)$/ &&
6429: !defined(&Apache::loncommon::fileembstyle($1))) {
6430: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
6431: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
6432: $output = &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
6433: } elsif (-d "$filepath/$file") {
6434: $output = &mt('Filename is a directory name - rename the file and re-upload');
6435: } else {
6436: my $source = $filepath.'/'.$file;
6437: my $logfile;
6438: if (!open($logfile,">>$source".'.log')) {
6439: return (&mt('No write permission to Authoring Space'));
6440: }
6441: print $logfile
6442: "\n================= Publish ".localtime()." ================\n".
6443: $env{'user.name'}.':'.$env{'user.domain'}."\n";
6444: # Save the file
6445: if (!open(FH,'>'.$source)) {
6446: &Apache::lonnet::logthis('Failed to create '.$source);
6447: return (&mt('Failed to create file'));
6448: }
6449: if ($action eq 'upload') {
6450: if (!print FH ($env{'form.'.$formname})) {
6451: &Apache::lonnet::logthis('Failed to write to '.$source);
6452: return (&mt('Failed to write file'));
6453: }
6454: } else {
6455: my $original = &Apache::lonnet::filelocation('',$formname);
6456: if(!copy($original,$source)) {
6457: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
6458: return (&mt('Failed to write file'));
6459: }
6460: }
6461: close(FH);
6462: chmod(0660, $source); # Permissions to rw-rw---.
6463:
6464: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
6465: my $copyfile=$targetdir.'/'.$file;
6466:
6467: my @parts=split(/\//,$targetdir);
6468: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
6469: for (my $count=5;$count<=$#parts;$count++) {
6470: $path.="/$parts[$count]";
6471: if (!-e $path) {
6472: print $logfile "\nCreating directory ".$path;
6473: mkdir($path,02770);
6474: }
6475: }
6476: my $versionresult;
6477: if (-e $copyfile) {
6478: $versionresult = &logo_versioning($targetdir,$file,$logfile);
6479: } else {
6480: $versionresult = 'ok';
6481: }
6482: if ($versionresult eq 'ok') {
6483: if (copy($source,$copyfile)) {
6484: print $logfile "\nCopied original source to ".$copyfile."\n";
6485: $output = 'ok';
6486: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
6487: push(@{$modified_urls},[$copyfile,$source]);
6488: my $metaoutput =
6489: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
6490: unless ($registered_cleanup) {
6491: my $handlers = $r->get_handlers('PerlCleanupHandler');
6492: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6493: $registered_cleanup=1;
6494: }
6495: } else {
6496: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
6497: $output = &mt('Failed to copy file to RES space').", $!";
6498: }
6499: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
6500: my $inputfile = $filepath.'/'.$file;
6501: my $outfile = $filepath.'/'.'tn-'.$file;
6502: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
6503: if ($fullwidth ne '' && $fullheight ne '') {
6504: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
6505: my $thumbsize = $thumbwidth.'x'.$thumbheight;
6506: system("convert -sample $thumbsize $inputfile $outfile");
6507: chmod(0660, $filepath.'/tn-'.$file);
6508: if (-e $outfile) {
6509: my $copyfile=$targetdir.'/tn-'.$file;
6510: if (copy($outfile,$copyfile)) {
6511: print $logfile "\nCopied source to ".$copyfile."\n";
6512: my $thumb_metaoutput =
6513: &write_metadata($dom,$confname,$formname,
6514: $targetdir,'tn-'.$file,$logfile);
6515: push(@{$modified_urls},[$copyfile,$outfile]);
6516: unless ($registered_cleanup) {
6517: my $handlers = $r->get_handlers('PerlCleanupHandler');
6518: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6519: $registered_cleanup=1;
6520: }
6521: } else {
6522: print $logfile "\nUnable to write ".$copyfile.
6523: ':'.$!."\n";
6524: }
6525: }
6526: }
6527: }
6528: }
6529: } else {
6530: $output = $versionresult;
6531: }
6532: }
6533: return ($output,$logourl);
6534: }
6535:
6536: sub logo_versioning {
6537: my ($targetdir,$file,$logfile) = @_;
6538: my $target = $targetdir.'/'.$file;
6539: my ($maxversion,$fn,$extn,$output);
6540: $maxversion = 0;
6541: if ($file =~ /^(.+)\.(\w+)$/) {
6542: $fn=$1;
6543: $extn=$2;
6544: }
6545: opendir(DIR,$targetdir);
6546: while (my $filename=readdir(DIR)) {
6547: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
6548: $maxversion=($1>$maxversion)?$1:$maxversion;
6549: }
6550: }
6551: $maxversion++;
6552: print $logfile "\nCreating old version ".$maxversion."\n";
6553: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
6554: if (copy($target,$copyfile)) {
6555: print $logfile "Copied old target to ".$copyfile."\n";
6556: $copyfile=$copyfile.'.meta';
6557: if (copy($target.'.meta',$copyfile)) {
6558: print $logfile "Copied old target metadata to ".$copyfile."\n";
6559: $output = 'ok';
6560: } else {
6561: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
6562: $output = &mt('Failed to copy old meta').", $!, ";
6563: }
6564: } else {
6565: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
6566: $output = &mt('Failed to copy old target').", $!, ";
6567: }
6568: return $output;
6569: }
6570:
6571: sub write_metadata {
6572: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
6573: my (%metadatafields,%metadatakeys,$output);
6574: $metadatafields{'title'}=$formname;
6575: $metadatafields{'creationdate'}=time;
6576: $metadatafields{'lastrevisiondate'}=time;
6577: $metadatafields{'copyright'}='public';
6578: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
6579: $env{'user.domain'};
6580: $metadatafields{'authorspace'}=$confname.':'.$dom;
6581: $metadatafields{'domain'}=$dom;
6582: {
6583: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
6584: my $mfh;
6585: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
6586: foreach (sort(keys(%metadatafields))) {
6587: unless ($_=~/\./) {
6588: my $unikey=$_;
6589: $unikey=~/^([A-Za-z]+)/;
6590: my $tag=$1;
6591: $tag=~tr/A-Z/a-z/;
6592: print $mfh "\n\<$tag";
6593: foreach (split(/\,/,$metadatakeys{$unikey})) {
6594: my $value=$metadatafields{$unikey.'.'.$_};
6595: $value=~s/\"/\'\'/g;
6596: print $mfh ' '.$_.'="'.$value.'"';
6597: }
6598: print $mfh '>'.
6599: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
6600: .'</'.$tag.'>';
6601: }
6602: }
6603: $output = 'ok';
6604: print $logfile "\nWrote metadata";
6605: close($mfh);
6606: } else {
6607: print $logfile "\nFailed to open metadata file";
6608: $output = &mt('Could not write metadata');
6609: }
6610: }
6611: return $output;
6612: }
6613:
6614: sub notifysubscribed {
6615: foreach my $targetsource (@{$modified_urls}){
6616: next unless (ref($targetsource) eq 'ARRAY');
6617: my ($target,$source)=@{$targetsource};
6618: if ($source ne '') {
6619: if (open(my $logfh,'>>'.$source.'.log')) {
6620: print $logfh "\nCleanup phase: Notifications\n";
6621: my @subscribed=&subscribed_hosts($target);
6622: foreach my $subhost (@subscribed) {
6623: print $logfh "\nNotifying host ".$subhost.':';
6624: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
6625: print $logfh $reply;
6626: }
6627: my @subscribedmeta=&subscribed_hosts("$target.meta");
6628: foreach my $subhost (@subscribedmeta) {
6629: print $logfh "\nNotifying host for metadata only ".$subhost.':';
6630: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
6631: $subhost);
6632: print $logfh $reply;
6633: }
6634: print $logfh "\n============ Done ============\n";
6635: close($logfh);
6636: }
6637: }
6638: }
6639: return OK;
6640: }
6641:
6642: sub subscribed_hosts {
6643: my ($target) = @_;
6644: my @subscribed;
6645: if (open(my $fh,"<$target.subscription")) {
6646: while (my $subline=<$fh>) {
6647: if ($subline =~ /^($match_lonid):/) {
6648: my $host = $1;
6649: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
6650: unless (grep(/^\Q$host\E$/,@subscribed)) {
6651: push(@subscribed,$host);
6652: }
6653: }
6654: }
6655: }
6656: }
6657: return @subscribed;
6658: }
6659:
6660: sub check_switchserver {
6661: my ($dom,$confname) = @_;
6662: my ($allowed,$switchserver);
6663: my $home = &Apache::lonnet::homeserver($confname,$dom);
6664: if ($home eq 'no_host') {
6665: $home = &Apache::lonnet::domain($dom,'primary');
6666: }
6667: my @ids=&Apache::lonnet::current_machine_ids();
6668: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
6669: if (!$allowed) {
6670: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
6671: }
6672: return $switchserver;
6673: }
6674:
6675: sub modify_quotas {
6676: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
6677: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
6678: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
6679: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
6680: $validationfieldsref);
6681: if ($action eq 'quotas') {
6682: $context = 'tools';
6683: } else {
6684: $context = $action;
6685: }
6686: if ($context eq 'requestcourses') {
6687: @usertools = ('official','unofficial','community','textbook');
6688: @options =('norequest','approval','validate','autolimit');
6689: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
6690: %titles = &courserequest_titles();
6691: $toolregexp = join('|',@usertools);
6692: %conditions = &courserequest_conditions();
6693: $confname = $dom.'-domainconfig';
6694: my $servadm = $r->dir_config('lonAdmEMail');
6695: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6696: ($validationitemsref,$validationnamesref,$validationfieldsref) =
6697: &Apache::loncoursequeueadmin::requestcourses_validation_types();
6698: } elsif ($context eq 'requestauthor') {
6699: @usertools = ('author');
6700: %titles = &authorrequest_titles();
6701: } else {
6702: @usertools = ('aboutme','blog','webdav','portfolio');
6703: %titles = &tool_titles();
6704: }
6705: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
6706: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6707: foreach my $key (keys(%env)) {
6708: if ($context eq 'requestcourses') {
6709: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
6710: my $item = $1;
6711: my $type = $2;
6712: if ($type =~ /^limit_(.+)/) {
6713: $limithash{$item}{$1} = $env{$key};
6714: } else {
6715: $confhash{$item}{$type} = $env{$key};
6716: }
6717: }
6718: } elsif ($context eq 'requestauthor') {
6719: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
6720: $confhash{$1} = $env{$key};
6721: }
6722: } else {
6723: if ($key =~ /^form\.quota_(.+)$/) {
6724: $confhash{'defaultquota'}{$1} = $env{$key};
6725: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
6726: $confhash{'authorquota'}{$1} = $env{$key};
6727: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
6728: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
6729: }
6730: }
6731: }
6732: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
6733: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
6734: @approvalnotify = sort(@approvalnotify);
6735: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
6736: my @crstypes = ('official','unofficial','community','textbook');
6737: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
6738: foreach my $type (@hasuniquecode) {
6739: if (grep(/^\Q$type\E$/,@crstypes)) {
6740: $confhash{'uniquecode'}{$type} = 1;
6741: }
6742: }
6743: my ($newbook,@allpos);
6744: if ($context eq 'requestcourses') {
6745: if ($env{'form.addbook'}) {
6746: if (($env{'form.addbook_cnum'} =~ /^$match_courseid$/) &&
6747: ($env{'form.addbook_cdom'} =~ /^$match_domain$/)) {
6748: if (&Apache::lonnet::homeserver($env{'form.addbook_cnum'},
6749: $env{'form.addbook_cdom'}) eq 'no_host') {
6750: $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
6751: '</span></li>';
6752: } else {
6753: $newbook = $env{'form.addbook_cdom'}.'_'.$env{'form.addbook_cnum'};
6754: my $position = $env{'form.addbook_pos'};
6755: $position =~ s/\D+//g;
6756: if ($position ne '') {
6757: $allpos[$position] = $newbook;
6758: }
6759: }
6760: } else {
6761: $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
6762: '</span></li>';
6763: }
6764: }
6765:
6766: }
6767: if (ref($domconfig{$action}) eq 'HASH') {
6768: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
6769: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
6770: $changes{'notify'}{'approval'} = 1;
6771: }
6772: } else {
6773: if ($confhash{'notify'}{'approval'}) {
6774: $changes{'notify'}{'approval'} = 1;
6775: }
6776: }
6777: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
6778: if (ref($confhash{'uniquecode'}) eq 'HASH') {
6779: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
6780: unless ($confhash{'uniquecode'}{$crstype}) {
6781: $changes{'uniquecode'} = 1;
6782: }
6783: }
6784: unless ($changes{'uniquecode'}) {
6785: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
6786: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
6787: $changes{'uniquecode'} = 1;
6788: }
6789: }
6790: }
6791: } else {
6792: $changes{'uniquecode'} = 1;
6793: }
6794: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
6795: $changes{'uniquecode'} = 1;
6796: }
6797: if ($context eq 'requestcourses') {
6798: if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
6799: my %deletions;
6800: my @todelete = &Apache::loncommon::get_env_multiple('form.book_del');
6801: if (@todelete) {
6802: map { $deletions{$_} = 1; } @todelete;
6803: }
6804: my %imgdeletions;
6805: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.book_image_del');
6806: if (@todeleteimages) {
6807: map { $imgdeletions{$_} = 1; } @todeleteimages;
6808: }
6809: my $maxnum = $env{'form.book_maxnum'};
6810: for (my $i=0; $i<=$maxnum; $i++) {
6811: my $key = $env{'form.book_id_'.$i};
6812: if (ref($domconfig{$action}{'textbooks'}{$key}) eq 'HASH') {
6813: if ($deletions{$key}) {
6814: if ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
6815: #FIXME need to obsolete item in RES space
6816: }
6817: next;
6818: } else {
6819: my $newpos = $env{'form.'.$key};
6820: $newpos =~ s/\D+//g;
6821: foreach my $item ('subject','title','author') {
6822: $confhash{'textbooks'}{$key}{$item} = $env{'form.book_'.$item.'_'.$i};
6823: if ($domconfig{$action}{'textbooks'}{$key}{$item} ne $confhash{'textbooks'}{$key}{$item}) {
6824: $changes{'textbooks'}{$key} = 1;
6825: }
6826: }
6827: $allpos[$newpos] = $key;
6828: }
6829: if ($imgdeletions{$key}) {
6830: $changes{'textbooks'}{$key} = 1;
6831: #FIXME need to obsolete item in RES space
6832: } elsif ($env{'form.book_image_'.$i.'.filename'}) {
6833: my ($cdom,$cnum) = split(/_/,$key);
6834: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,'book_image_'.$i,
6835: $cdom,$cnum,$configuserok,
6836: $switchserver,$author_ok);
6837: if ($imgurl) {
6838: $confhash{'textbooks'}{$key}{'image'} = $imgurl;
6839: $changes{'textbooks'}{$key} = 1;
6840: }
6841: if ($error) {
6842: &Apache::lonnet::logthis($error);
6843: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6844: }
6845: } elsif ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
6846: $confhash{'textbooks'}{$key}{'image'} =
6847: $domconfig{$action}{'textbooks'}{$key}{'image'};
6848: }
6849: }
6850: }
6851: }
6852: }
6853: } else {
6854: if ($confhash{'notify'}{'approval'}) {
6855: $changes{'notify'}{'approval'} = 1;
6856: }
6857: if (ref($confhash{'uniquecode'} eq 'HASH')) {
6858: $changes{'uniquecode'} = 1;
6859: }
6860: }
6861: if ($context eq 'requestcourses') {
6862: if ($newbook) {
6863: $changes{'textbooks'}{$newbook} = 1;
6864: foreach my $item ('subject','title','author') {
6865: $env{'form.addbook_'.$item} =~ s/(`)/'/g;
6866: if ($env{'form.addbook_'.$item}) {
6867: $confhash{'textbooks'}{$newbook}{$item} = $env{'form.addbook_'.$item};
6868: }
6869: }
6870: if ($env{'form.addbook_image.filename'} ne '') {
6871: my ($cdom,$cnum) = split(/_/,$newbook);
6872: my ($imageurl,$error) =
6873: &process_textbook_image($r,$dom,$confname,'addbook_image',$cdom,$cnum,$configuserok,
6874: $switchserver,$author_ok);
6875: if ($imageurl) {
6876: $confhash{'textbooks'}{$newbook}{'image'} = $imageurl;
6877: }
6878: if ($error) {
6879: &Apache::lonnet::logthis($error);
6880: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6881: }
6882: }
6883: }
6884: if (@allpos > 0) {
6885: my $idx = 0;
6886: foreach my $item (@allpos) {
6887: if ($item ne '') {
6888: $confhash{'textbooks'}{$item}{'order'} = $idx;
6889: if (ref($domconfig{$action}) eq 'HASH') {
6890: if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
6891: if (ref($domconfig{$action}{'textbooks'}{$item}) eq 'HASH') {
6892: if ($domconfig{$action}{'textbooks'}{$item}{'order'} ne $idx) {
6893: $changes{'textbooks'}{$item} = 1;
6894: }
6895: }
6896: }
6897: }
6898: $idx ++;
6899: }
6900: }
6901: }
6902: if (ref($validationitemsref) eq 'ARRAY') {
6903: foreach my $item (@{$validationitemsref}) {
6904: if ($item eq 'fields') {
6905: my @changed;
6906: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
6907: if (@{$confhash{'validation'}{$item}} > 0) {
6908: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
6909: }
6910: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
6911: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
6912: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
6913: $domconfig{'requestcourses'}{'validation'}{$item});
6914: } else {
6915: @changed = @{$confhash{'validation'}{$item}};
6916: }
6917: } else {
6918: @changed = @{$confhash{'validation'}{$item}};
6919: }
6920: if (@changed) {
6921: if ($confhash{'validation'}{$item}) {
6922: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
6923: } else {
6924: $changes{'validation'}{$item} = &mt('None');
6925: }
6926: }
6927: } else {
6928: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
6929: if ($item eq 'markup') {
6930: if ($env{'form.requestcourses_validation_'.$item}) {
6931: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
6932: }
6933: }
6934: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
6935: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
6936: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
6937: }
6938: } else {
6939: if ($confhash{'validation'}{$item} ne '') {
6940: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
6941: }
6942: }
6943: }
6944: }
6945: }
6946: if ($env{'form.validationdc'}) {
6947: my $newval = $env{'form.validationdc'};
6948: my %domcoords = &get_active_dcs($dom);
6949: if (exists($domcoords{$newval})) {
6950: $confhash{'validation'}{'dc'} = $newval;
6951: }
6952: }
6953: if (ref($confhash{'validation'}) eq 'HASH') {
6954: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
6955: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
6956: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
6957: if ($confhash{'validation'}{'dc'} eq '') {
6958: $changes{'validation'}{'dc'} = &mt('None');
6959: } else {
6960: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
6961: }
6962: }
6963: } elsif ($confhash{'validation'}{'dc'} ne '') {
6964: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
6965: }
6966: } elsif ($confhash{'validation'}{'dc'} ne '') {
6967: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
6968: }
6969: } elsif (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
6970: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
6971: $changes{'validation'}{'dc'} = &mt('None');
6972: }
6973: }
6974: }
6975: } else {
6976: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
6977: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
6978: }
6979: foreach my $item (@usertools) {
6980: foreach my $type (@{$types},'default','_LC_adv') {
6981: my $unset;
6982: if ($context eq 'requestcourses') {
6983: $unset = '0';
6984: if ($type eq '_LC_adv') {
6985: $unset = '';
6986: }
6987: if ($confhash{$item}{$type} eq 'autolimit') {
6988: $confhash{$item}{$type} .= '=';
6989: unless ($limithash{$item}{$type} =~ /\D/) {
6990: $confhash{$item}{$type} .= $limithash{$item}{$type};
6991: }
6992: }
6993: } elsif ($context eq 'requestauthor') {
6994: $unset = '0';
6995: if ($type eq '_LC_adv') {
6996: $unset = '';
6997: }
6998: } else {
6999: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
7000: $confhash{$item}{$type} = 1;
7001: } else {
7002: $confhash{$item}{$type} = 0;
7003: }
7004: }
7005: if (ref($domconfig{$action}) eq 'HASH') {
7006: if ($action eq 'requestauthor') {
7007: if ($domconfig{$action}{$type} ne $confhash{$type}) {
7008: $changes{$type} = 1;
7009: }
7010: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
7011: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
7012: $changes{$item}{$type} = 1;
7013: }
7014: } else {
7015: if ($context eq 'requestcourses') {
7016: if ($confhash{$item}{$type} ne $unset) {
7017: $changes{$item}{$type} = 1;
7018: }
7019: } else {
7020: if (!$confhash{$item}{$type}) {
7021: $changes{$item}{$type} = 1;
7022: }
7023: }
7024: }
7025: } else {
7026: if ($context eq 'requestcourses') {
7027: if ($confhash{$item}{$type} ne $unset) {
7028: $changes{$item}{$type} = 1;
7029: }
7030: } elsif ($context eq 'requestauthor') {
7031: if ($confhash{$type} ne $unset) {
7032: $changes{$type} = 1;
7033: }
7034: } else {
7035: if (!$confhash{$item}{$type}) {
7036: $changes{$item}{$type} = 1;
7037: }
7038: }
7039: }
7040: }
7041: }
7042: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
7043: if (ref($domconfig{'quotas'}) eq 'HASH') {
7044: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7045: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
7046: if (exists($confhash{'defaultquota'}{$key})) {
7047: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
7048: $changes{'defaultquota'}{$key} = 1;
7049: }
7050: } else {
7051: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
7052: }
7053: }
7054: } else {
7055: foreach my $key (keys(%{$domconfig{'quotas'}})) {
7056: if (exists($confhash{'defaultquota'}{$key})) {
7057: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
7058: $changes{'defaultquota'}{$key} = 1;
7059: }
7060: } else {
7061: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
7062: }
7063: }
7064: }
7065: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7066: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
7067: if (exists($confhash{'authorquota'}{$key})) {
7068: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
7069: $changes{'authorquota'}{$key} = 1;
7070: }
7071: } else {
7072: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
7073: }
7074: }
7075: }
7076: }
7077: if (ref($confhash{'defaultquota'}) eq 'HASH') {
7078: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
7079: if (ref($domconfig{'quotas'}) eq 'HASH') {
7080: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7081: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
7082: $changes{'defaultquota'}{$key} = 1;
7083: }
7084: } else {
7085: if (!exists($domconfig{'quotas'}{$key})) {
7086: $changes{'defaultquota'}{$key} = 1;
7087: }
7088: }
7089: } else {
7090: $changes{'defaultquota'}{$key} = 1;
7091: }
7092: }
7093: }
7094: if (ref($confhash{'authorquota'}) eq 'HASH') {
7095: foreach my $key (keys(%{$confhash{'authorquota'}})) {
7096: if (ref($domconfig{'quotas'}) eq 'HASH') {
7097: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7098: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
7099: $changes{'authorquota'}{$key} = 1;
7100: }
7101: } else {
7102: $changes{'authorquota'}{$key} = 1;
7103: }
7104: } else {
7105: $changes{'authorquota'}{$key} = 1;
7106: }
7107: }
7108: }
7109: }
7110:
7111: if ($context eq 'requestauthor') {
7112: $domdefaults{'requestauthor'} = \%confhash;
7113: } else {
7114: foreach my $key (keys(%confhash)) {
7115: unless (($context eq 'requestcourses') && ($key eq 'textbooks')) {
7116: $domdefaults{$key} = $confhash{$key};
7117: }
7118: }
7119: }
7120:
7121: my %quotahash = (
7122: $action => { %confhash }
7123: );
7124: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
7125: $dom);
7126: if ($putresult eq 'ok') {
7127: if (keys(%changes) > 0) {
7128: my $cachetime = 24*60*60;
7129: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
7130: if (ref($lastactref) eq 'HASH') {
7131: $lastactref->{'domdefaults'} = 1;
7132: }
7133: $resulttext = &mt('Changes made:').'<ul>';
7134: unless (($context eq 'requestcourses') ||
7135: ($context eq 'requestauthor')) {
7136: if (ref($changes{'defaultquota'}) eq 'HASH') {
7137: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
7138: foreach my $type (@{$types},'default') {
7139: if (defined($changes{'defaultquota'}{$type})) {
7140: my $typetitle = $usertypes->{$type};
7141: if ($type eq 'default') {
7142: $typetitle = $othertitle;
7143: }
7144: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
7145: }
7146: }
7147: $resulttext .= '</ul></li>';
7148: }
7149: if (ref($changes{'authorquota'}) eq 'HASH') {
7150: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
7151: foreach my $type (@{$types},'default') {
7152: if (defined($changes{'authorquota'}{$type})) {
7153: my $typetitle = $usertypes->{$type};
7154: if ($type eq 'default') {
7155: $typetitle = $othertitle;
7156: }
7157: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
7158: }
7159: }
7160: $resulttext .= '</ul></li>';
7161: }
7162: }
7163: my %newenv;
7164: foreach my $item (@usertools) {
7165: my (%haschgs,%inconf);
7166: if ($context eq 'requestauthor') {
7167: %haschgs = %changes;
7168: %inconf = %confhash;
7169: } else {
7170: if (ref($changes{$item}) eq 'HASH') {
7171: %haschgs = %{$changes{$item}};
7172: }
7173: if (ref($confhash{$item}) eq 'HASH') {
7174: %inconf = %{$confhash{$item}};
7175: }
7176: }
7177: if (keys(%haschgs) > 0) {
7178: my $newacc =
7179: &Apache::lonnet::usertools_access($env{'user.name'},
7180: $env{'user.domain'},
7181: $item,'reload',$context);
7182: if (($context eq 'requestcourses') ||
7183: ($context eq 'requestauthor')) {
7184: if ($env{'environment.canrequest.'.$item} ne $newacc) {
7185: $newenv{'environment.canrequest.'.$item} = $newacc;
7186: }
7187: } else {
7188: if ($env{'environment.availabletools.'.$item} ne $newacc) {
7189: $newenv{'environment.availabletools.'.$item} = $newacc;
7190: }
7191: }
7192: unless ($context eq 'requestauthor') {
7193: $resulttext .= '<li>'.$titles{$item}.'<ul>';
7194: }
7195: foreach my $type (@{$types},'default','_LC_adv') {
7196: if ($haschgs{$type}) {
7197: my $typetitle = $usertypes->{$type};
7198: if ($type eq 'default') {
7199: $typetitle = $othertitle;
7200: } elsif ($type eq '_LC_adv') {
7201: $typetitle = 'LON-CAPA Advanced Users';
7202: }
7203: if ($inconf{$type}) {
7204: if ($context eq 'requestcourses') {
7205: my $cond;
7206: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
7207: if ($1 eq '') {
7208: $cond = &mt('(Automatic processing of any request).');
7209: } else {
7210: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
7211: }
7212: } else {
7213: $cond = $conditions{$inconf{$type}};
7214: }
7215: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
7216: } elsif ($context eq 'requestauthor') {
7217: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
7218: $titles{$inconf{$type}},$typetitle);
7219:
7220: } else {
7221: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
7222: }
7223: } else {
7224: if ($type eq '_LC_adv') {
7225: if ($inconf{$type} eq '0') {
7226: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7227: } else {
7228: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
7229: }
7230: } else {
7231: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7232: }
7233: }
7234: }
7235: }
7236: unless ($context eq 'requestauthor') {
7237: $resulttext .= '</ul></li>';
7238: }
7239: }
7240: }
7241: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
7242: if (ref($changes{'notify'}) eq 'HASH') {
7243: if ($changes{'notify'}{'approval'}) {
7244: if (ref($confhash{'notify'}) eq 'HASH') {
7245: if ($confhash{'notify'}{'approval'}) {
7246: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
7247: } else {
7248: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
7249: }
7250: }
7251: }
7252: }
7253: }
7254: if ($action eq 'requestcourses') {
7255: my @offon = ('off','on');
7256: if ($changes{'uniquecode'}) {
7257: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7258: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
7259: $resulttext .= '<li>'.
7260: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
7261: '</li>';
7262: } else {
7263: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
7264: '</li>';
7265: }
7266: }
7267: if (ref($changes{'textbooks'}) eq 'HASH') {
7268: $resulttext .= '<li>'.&mt('Available textbooks updated').'<ul>';
7269: foreach my $key (sort(keys(%{$changes{'textbooks'}}))) {
7270: my %coursehash = &Apache::lonnet::coursedescription($key);
7271: my $coursetitle = $coursehash{'description'};
7272: my $position = $confhash{'textbooks'}{$key}{'order'} + 1;
7273: $resulttext .= '<li>';
7274: foreach my $item ('subject','title','author') {
7275: my $name = $item.':';
7276: $name =~ s/^(\w)/\U$1/;
7277: $resulttext .= &mt($name).' '.$confhash{'textbooks'}{$key}{$item}.'<br />';
7278: }
7279: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
7280: if ($confhash{'textbooks'}{$key}{'image'}) {
7281: $resulttext .= ' '.&mt('Image: [_1]',
7282: '<img src="'.$confhash{'textbooks'}{$key}{'image'}.'"'.
7283: ' alt="Textbook cover" />').'<br />';
7284: }
7285: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
7286: }
7287: $resulttext .= '</ul></li>';
7288: }
7289: if (ref($changes{'validation'}) eq 'HASH') {
7290: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
7291: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
7292: foreach my $item (@{$validationitemsref}) {
7293: if (exists($changes{'validation'}{$item})) {
7294: if ($item eq 'markup') {
7295: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7296: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
7297: } else {
7298: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7299: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
7300: }
7301: }
7302: }
7303: if (exists($changes{'validation'}{'dc'})) {
7304: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
7305: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
7306: }
7307: }
7308: }
7309: }
7310: $resulttext .= '</ul>';
7311: if (keys(%newenv)) {
7312: &Apache::lonnet::appenv(\%newenv);
7313: }
7314: } else {
7315: if ($context eq 'requestcourses') {
7316: $resulttext = &mt('No changes made to rights to request creation of courses.');
7317: } elsif ($context eq 'requestauthor') {
7318: $resulttext = &mt('No changes made to rights to request author space.');
7319: } else {
7320: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
7321: }
7322: }
7323: } else {
7324: $resulttext = '<span class="LC_error">'.
7325: &mt('An error occurred: [_1]',$putresult).'</span>';
7326: }
7327: if ($errors) {
7328: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
7329: '<ul>'.$errors.'</ul></p>';
7330: }
7331: return $resulttext;
7332: }
7333:
7334: sub process_textbook_image {
7335: my ($r,$dom,$confname,$caller,$cdom,$cnum,$configuserok,$switchserver,$author_ok) = @_;
7336: my $filename = $env{'form.'.$caller.'.filename'};
7337: my ($error,$url);
7338: my ($width,$height) = (50,50);
7339: if ($configuserok eq 'ok') {
7340: if ($switchserver) {
7341: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
7342: $switchserver);
7343: } elsif ($author_ok eq 'ok') {
7344: my ($result,$imageurl) =
7345: &publishlogo($r,'upload',$caller,$dom,$confname,
7346: "textbooks/$dom/$cnum/cover",$width,$height);
7347: if ($result eq 'ok') {
7348: $url = $imageurl;
7349: } else {
7350: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
7351: }
7352: } else {
7353: $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);
7354: }
7355: } else {
7356: $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);
7357: }
7358: return ($url,$error);
7359: }
7360:
7361: sub modify_autoenroll {
7362: my ($dom,$lastactref,%domconfig) = @_;
7363: my ($resulttext,%changes);
7364: my %currautoenroll;
7365: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
7366: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
7367: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
7368: }
7369: }
7370: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
7371: my %title = ( run => 'Auto-enrollment active',
7372: sender => 'Sender for notification messages',
7373: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
7374: my @offon = ('off','on');
7375: my $sender_uname = $env{'form.sender_uname'};
7376: my $sender_domain = $env{'form.sender_domain'};
7377: if ($sender_domain eq '') {
7378: $sender_uname = '';
7379: } elsif ($sender_uname eq '') {
7380: $sender_domain = '';
7381: }
7382: my $coowners = $env{'form.autoassign_coowners'};
7383: my %autoenrollhash = (
7384: autoenroll => { 'run' => $env{'form.autoenroll_run'},
7385: 'sender_uname' => $sender_uname,
7386: 'sender_domain' => $sender_domain,
7387: 'co-owners' => $coowners,
7388: }
7389: );
7390: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
7391: $dom);
7392: if ($putresult eq 'ok') {
7393: if (exists($currautoenroll{'run'})) {
7394: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
7395: $changes{'run'} = 1;
7396: }
7397: } elsif ($autorun) {
7398: if ($env{'form.autoenroll_run'} ne '1') {
7399: $changes{'run'} = 1;
7400: }
7401: }
7402: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
7403: $changes{'sender'} = 1;
7404: }
7405: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
7406: $changes{'sender'} = 1;
7407: }
7408: if ($currautoenroll{'co-owners'} ne '') {
7409: if ($currautoenroll{'co-owners'} ne $coowners) {
7410: $changes{'coowners'} = 1;
7411: }
7412: } elsif ($coowners) {
7413: $changes{'coowners'} = 1;
7414: }
7415: if (keys(%changes) > 0) {
7416: $resulttext = &mt('Changes made:').'<ul>';
7417: if ($changes{'run'}) {
7418: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
7419: }
7420: if ($changes{'sender'}) {
7421: if ($sender_uname eq '' || $sender_domain eq '') {
7422: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
7423: } else {
7424: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
7425: }
7426: }
7427: if ($changes{'coowners'}) {
7428: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
7429: &Apache::loncommon::devalidate_domconfig_cache($dom);
7430: if (ref($lastactref) eq 'HASH') {
7431: $lastactref->{'domainconfig'} = 1;
7432: }
7433: }
7434: $resulttext .= '</ul>';
7435: } else {
7436: $resulttext = &mt('No changes made to auto-enrollment settings');
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_autoupdate {
7446: my ($dom,%domconfig) = @_;
7447: my ($resulttext,%currautoupdate,%fields,%changes);
7448: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
7449: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
7450: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
7451: }
7452: }
7453: my @offon = ('off','on');
7454: my %title = &Apache::lonlocal::texthash (
7455: run => 'Auto-update:',
7456: classlists => 'Updates to user information in classlists?'
7457: );
7458: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7459: my %fieldtitles = &Apache::lonlocal::texthash (
7460: id => 'Student/Employee ID',
7461: permanentemail => 'E-mail address',
7462: lastname => 'Last Name',
7463: firstname => 'First Name',
7464: middlename => 'Middle Name',
7465: generation => 'Generation',
7466: );
7467: $othertitle = &mt('All users');
7468: if (keys(%{$usertypes}) > 0) {
7469: $othertitle = &mt('Other users');
7470: }
7471: foreach my $key (keys(%env)) {
7472: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
7473: my ($usertype,$item) = ($1,$2);
7474: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
7475: if ($usertype eq 'default') {
7476: push(@{$fields{$1}},$2);
7477: } elsif (ref($types) eq 'ARRAY') {
7478: if (grep(/^\Q$usertype\E$/,@{$types})) {
7479: push(@{$fields{$1}},$2);
7480: }
7481: }
7482: }
7483: }
7484: }
7485: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
7486: @lockablenames = sort(@lockablenames);
7487: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
7488: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7489: if (@changed) {
7490: $changes{'lockablenames'} = 1;
7491: }
7492: } else {
7493: if (@lockablenames) {
7494: $changes{'lockablenames'} = 1;
7495: }
7496: }
7497: my %updatehash = (
7498: autoupdate => { run => $env{'form.autoupdate_run'},
7499: classlists => $env{'form.classlists'},
7500: fields => {%fields},
7501: lockablenames => \@lockablenames,
7502: }
7503: );
7504: foreach my $key (keys(%currautoupdate)) {
7505: if (($key eq 'run') || ($key eq 'classlists')) {
7506: if (exists($updatehash{autoupdate}{$key})) {
7507: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
7508: $changes{$key} = 1;
7509: }
7510: }
7511: } elsif ($key eq 'fields') {
7512: if (ref($currautoupdate{$key}) eq 'HASH') {
7513: foreach my $item (@{$types},'default') {
7514: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
7515: my $change = 0;
7516: foreach my $type (@{$currautoupdate{$key}{$item}}) {
7517: if (!exists($fields{$item})) {
7518: $change = 1;
7519: last;
7520: } elsif (ref($fields{$item}) eq 'ARRAY') {
7521: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
7522: $change = 1;
7523: last;
7524: }
7525: }
7526: }
7527: if ($change) {
7528: push(@{$changes{$key}},$item);
7529: }
7530: }
7531: }
7532: }
7533: } elsif ($key eq 'lockablenames') {
7534: if (ref($currautoupdate{$key}) eq 'ARRAY') {
7535: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7536: if (@changed) {
7537: $changes{'lockablenames'} = 1;
7538: }
7539: } else {
7540: if (@lockablenames) {
7541: $changes{'lockablenames'} = 1;
7542: }
7543: }
7544: }
7545: }
7546: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
7547: if (@lockablenames) {
7548: $changes{'lockablenames'} = 1;
7549: }
7550: }
7551: foreach my $item (@{$types},'default') {
7552: if (defined($fields{$item})) {
7553: if (ref($currautoupdate{'fields'}) eq 'HASH') {
7554: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
7555: my $change = 0;
7556: if (ref($fields{$item}) eq 'ARRAY') {
7557: foreach my $type (@{$fields{$item}}) {
7558: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
7559: $change = 1;
7560: last;
7561: }
7562: }
7563: }
7564: if ($change) {
7565: push(@{$changes{'fields'}},$item);
7566: }
7567: } else {
7568: push(@{$changes{'fields'}},$item);
7569: }
7570: } else {
7571: push(@{$changes{'fields'}},$item);
7572: }
7573: }
7574: }
7575: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
7576: $dom);
7577: if ($putresult eq 'ok') {
7578: if (keys(%changes) > 0) {
7579: $resulttext = &mt('Changes made:').'<ul>';
7580: foreach my $key (sort(keys(%changes))) {
7581: if ($key eq 'lockablenames') {
7582: $resulttext .= '<li>';
7583: if (@lockablenames) {
7584: $usertypes->{'default'} = $othertitle;
7585: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
7586: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
7587: } else {
7588: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
7589: }
7590: $resulttext .= '</li>';
7591: } elsif (ref($changes{$key}) eq 'ARRAY') {
7592: foreach my $item (@{$changes{$key}}) {
7593: my @newvalues;
7594: foreach my $type (@{$fields{$item}}) {
7595: push(@newvalues,$fieldtitles{$type});
7596: }
7597: my $newvaluestr;
7598: if (@newvalues > 0) {
7599: $newvaluestr = join(', ',@newvalues);
7600: } else {
7601: $newvaluestr = &mt('none');
7602: }
7603: if ($item eq 'default') {
7604: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
7605: } else {
7606: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
7607: }
7608: }
7609: } else {
7610: my $newvalue;
7611: if ($key eq 'run') {
7612: $newvalue = $offon[$env{'form.autoupdate_run'}];
7613: } else {
7614: $newvalue = $offon[$env{'form.'.$key}];
7615: }
7616: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
7617: }
7618: }
7619: $resulttext .= '</ul>';
7620: } else {
7621: $resulttext = &mt('No changes made to autoupdates');
7622: }
7623: } else {
7624: $resulttext = '<span class="LC_error">'.
7625: &mt('An error occurred: [_1]',$putresult).'</span>';
7626: }
7627: return $resulttext;
7628: }
7629:
7630: sub modify_autocreate {
7631: my ($dom,%domconfig) = @_;
7632: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
7633: if (ref($domconfig{'autocreate'}) eq 'HASH') {
7634: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
7635: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
7636: }
7637: }
7638: my %title= ( xml => 'Auto-creation of courses in XML course description files',
7639: req => 'Auto-creation of validated requests for official courses',
7640: xmldc => 'Identity of course creator of courses from XML files',
7641: );
7642: my @types = ('xml','req');
7643: foreach my $item (@types) {
7644: $newvals{$item} = $env{'form.autocreate_'.$item};
7645: $newvals{$item} =~ s/\D//g;
7646: $newvals{$item} = 0 if ($newvals{$item} eq '');
7647: }
7648: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
7649: my %domcoords = &get_active_dcs($dom);
7650: unless (exists($domcoords{$newvals{'xmldc'}})) {
7651: $newvals{'xmldc'} = '';
7652: }
7653: %autocreatehash = (
7654: autocreate => { xml => $newvals{'xml'},
7655: req => $newvals{'req'},
7656: }
7657: );
7658: if ($newvals{'xmldc'} ne '') {
7659: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
7660: }
7661: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
7662: $dom);
7663: if ($putresult eq 'ok') {
7664: my @items = @types;
7665: if ($newvals{'xml'}) {
7666: push(@items,'xmldc');
7667: }
7668: foreach my $item (@items) {
7669: if (exists($currautocreate{$item})) {
7670: if ($currautocreate{$item} ne $newvals{$item}) {
7671: $changes{$item} = 1;
7672: }
7673: } elsif ($newvals{$item}) {
7674: $changes{$item} = 1;
7675: }
7676: }
7677: if (keys(%changes) > 0) {
7678: my @offon = ('off','on');
7679: $resulttext = &mt('Changes made:').'<ul>';
7680: foreach my $item (@types) {
7681: if ($changes{$item}) {
7682: my $newtxt = $offon[$newvals{$item}];
7683: $resulttext .= '<li>'.
7684: &mt("$title{$item} set to [_1]$newtxt [_2]",
7685: '<b>','</b>').
7686: '</li>';
7687: }
7688: }
7689: if ($changes{'xmldc'}) {
7690: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
7691: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
7692: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
7693: }
7694: $resulttext .= '</ul>';
7695: } else {
7696: $resulttext = &mt('No changes made to auto-creation settings');
7697: }
7698: } else {
7699: $resulttext = '<span class="LC_error">'.
7700: &mt('An error occurred: [_1]',$putresult).'</span>';
7701: }
7702: return $resulttext;
7703: }
7704:
7705: sub modify_directorysrch {
7706: my ($dom,%domconfig) = @_;
7707: my ($resulttext,%changes);
7708: my %currdirsrch;
7709: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
7710: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
7711: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
7712: }
7713: }
7714: my %title = ( available => 'Directory search available',
7715: localonly => 'Other domains can search',
7716: searchby => 'Search types',
7717: searchtypes => 'Search latitude');
7718: my @offon = ('off','on');
7719: my @otherdoms = ('Yes','No');
7720:
7721: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
7722: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
7723: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
7724:
7725: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7726: if (keys(%{$usertypes}) == 0) {
7727: @cansearch = ('default');
7728: } else {
7729: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
7730: foreach my $type (@{$currdirsrch{'cansearch'}}) {
7731: if (!grep(/^\Q$type\E$/,@cansearch)) {
7732: push(@{$changes{'cansearch'}},$type);
7733: }
7734: }
7735: foreach my $type (@cansearch) {
7736: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
7737: push(@{$changes{'cansearch'}},$type);
7738: }
7739: }
7740: } else {
7741: push(@{$changes{'cansearch'}},@cansearch);
7742: }
7743: }
7744:
7745: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
7746: foreach my $by (@{$currdirsrch{'searchby'}}) {
7747: if (!grep(/^\Q$by\E$/,@searchby)) {
7748: push(@{$changes{'searchby'}},$by);
7749: }
7750: }
7751: foreach my $by (@searchby) {
7752: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
7753: push(@{$changes{'searchby'}},$by);
7754: }
7755: }
7756: } else {
7757: push(@{$changes{'searchby'}},@searchby);
7758: }
7759:
7760: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
7761: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
7762: if (!grep(/^\Q$type\E$/,@searchtypes)) {
7763: push(@{$changes{'searchtypes'}},$type);
7764: }
7765: }
7766: foreach my $type (@searchtypes) {
7767: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
7768: push(@{$changes{'searchtypes'}},$type);
7769: }
7770: }
7771: } else {
7772: if (exists($currdirsrch{'searchtypes'})) {
7773: foreach my $type (@searchtypes) {
7774: if ($type ne $currdirsrch{'searchtypes'}) {
7775: push(@{$changes{'searchtypes'}},$type);
7776: }
7777: }
7778: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
7779: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
7780: }
7781: } else {
7782: push(@{$changes{'searchtypes'}},@searchtypes);
7783: }
7784: }
7785:
7786: my %dirsrch_hash = (
7787: directorysrch => { available => $env{'form.dirsrch_available'},
7788: cansearch => \@cansearch,
7789: localonly => $env{'form.dirsrch_localonly'},
7790: searchby => \@searchby,
7791: searchtypes => \@searchtypes,
7792: }
7793: );
7794: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
7795: $dom);
7796: if ($putresult eq 'ok') {
7797: if (exists($currdirsrch{'available'})) {
7798: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
7799: $changes{'available'} = 1;
7800: }
7801: } else {
7802: if ($env{'form.dirsrch_available'} eq '1') {
7803: $changes{'available'} = 1;
7804: }
7805: }
7806: if (exists($currdirsrch{'localonly'})) {
7807: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
7808: $changes{'localonly'} = 1;
7809: }
7810: } else {
7811: if ($env{'form.dirsrch_localonly'} eq '1') {
7812: $changes{'localonly'} = 1;
7813: }
7814: }
7815: if (keys(%changes) > 0) {
7816: $resulttext = &mt('Changes made:').'<ul>';
7817: if ($changes{'available'}) {
7818: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
7819: }
7820: if ($changes{'localonly'}) {
7821: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
7822: }
7823:
7824: if (ref($changes{'cansearch'}) eq 'ARRAY') {
7825: my $chgtext;
7826: if (ref($usertypes) eq 'HASH') {
7827: if (keys(%{$usertypes}) > 0) {
7828: foreach my $type (@{$types}) {
7829: if (grep(/^\Q$type\E$/,@cansearch)) {
7830: $chgtext .= $usertypes->{$type}.'; ';
7831: }
7832: }
7833: if (grep(/^default$/,@cansearch)) {
7834: $chgtext .= $othertitle;
7835: } else {
7836: $chgtext =~ s/\; $//;
7837: }
7838: $resulttext .=
7839: '<li>'.
7840: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
7841: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
7842: '</li>';
7843: }
7844: }
7845: }
7846: if (ref($changes{'searchby'}) eq 'ARRAY') {
7847: my ($searchtitles,$titleorder) = &sorted_searchtitles();
7848: my $chgtext;
7849: foreach my $type (@{$titleorder}) {
7850: if (grep(/^\Q$type\E$/,@searchby)) {
7851: if (defined($searchtitles->{$type})) {
7852: $chgtext .= $searchtitles->{$type}.'; ';
7853: }
7854: }
7855: }
7856: $chgtext =~ s/\; $//;
7857: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
7858: }
7859: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
7860: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
7861: my $chgtext;
7862: foreach my $type (@{$srchtypeorder}) {
7863: if (grep(/^\Q$type\E$/,@searchtypes)) {
7864: if (defined($srchtypes_desc->{$type})) {
7865: $chgtext .= $srchtypes_desc->{$type}.'; ';
7866: }
7867: }
7868: }
7869: $chgtext =~ s/\; $//;
7870: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
7871: }
7872: $resulttext .= '</ul>';
7873: } else {
7874: $resulttext = &mt('No changes made to institution directory search settings');
7875: }
7876: } else {
7877: $resulttext = '<span class="LC_error">'.
7878: &mt('An error occurred: [_1]',$putresult).'</span>';
7879: }
7880: return $resulttext;
7881: }
7882:
7883: sub modify_contacts {
7884: my ($dom,$lastactref,%domconfig) = @_;
7885: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
7886: if (ref($domconfig{'contacts'}) eq 'HASH') {
7887: foreach my $key (keys(%{$domconfig{'contacts'}})) {
7888: $currsetting{$key} = $domconfig{'contacts'}{$key};
7889: }
7890: }
7891: my (%others,%to,%bcc);
7892: my @contacts = ('supportemail','adminemail');
7893: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
7894: 'requestsmail','updatesmail','idconflictsmail');
7895: my @toggles = ('reporterrors','reportupdates');
7896: foreach my $type (@mailings) {
7897: @{$newsetting{$type}} =
7898: &Apache::loncommon::get_env_multiple('form.'.$type);
7899: foreach my $item (@contacts) {
7900: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
7901: $contacts_hash{contacts}{$type}{$item} = 1;
7902: } else {
7903: $contacts_hash{contacts}{$type}{$item} = 0;
7904: }
7905: }
7906: $others{$type} = $env{'form.'.$type.'_others'};
7907: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
7908: if ($type eq 'helpdeskmail') {
7909: $bcc{$type} = $env{'form.'.$type.'_bcc'};
7910: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
7911: }
7912: }
7913: foreach my $item (@contacts) {
7914: $to{$item} = $env{'form.'.$item};
7915: $contacts_hash{'contacts'}{$item} = $to{$item};
7916: }
7917: foreach my $item (@toggles) {
7918: if ($env{'form.'.$item} =~ /^(0|1)$/) {
7919: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
7920: }
7921: }
7922: if (keys(%currsetting) > 0) {
7923: foreach my $item (@contacts) {
7924: if ($to{$item} ne $currsetting{$item}) {
7925: $changes{$item} = 1;
7926: }
7927: }
7928: foreach my $type (@mailings) {
7929: foreach my $item (@contacts) {
7930: if (ref($currsetting{$type}) eq 'HASH') {
7931: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
7932: push(@{$changes{$type}},$item);
7933: }
7934: } else {
7935: push(@{$changes{$type}},@{$newsetting{$type}});
7936: }
7937: }
7938: if ($others{$type} ne $currsetting{$type}{'others'}) {
7939: push(@{$changes{$type}},'others');
7940: }
7941: if ($type eq 'helpdeskmail') {
7942: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
7943: push(@{$changes{$type}},'bcc');
7944: }
7945: }
7946: }
7947: } else {
7948: my %default;
7949: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
7950: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
7951: $default{'errormail'} = 'adminemail';
7952: $default{'packagesmail'} = 'adminemail';
7953: $default{'helpdeskmail'} = 'supportemail';
7954: $default{'lonstatusmail'} = 'adminemail';
7955: $default{'requestsmail'} = 'adminemail';
7956: $default{'updatesmail'} = 'adminemail';
7957: foreach my $item (@contacts) {
7958: if ($to{$item} ne $default{$item}) {
7959: $changes{$item} = 1;
7960: }
7961: }
7962: foreach my $type (@mailings) {
7963: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
7964:
7965: push(@{$changes{$type}},@{$newsetting{$type}});
7966: }
7967: if ($others{$type} ne '') {
7968: push(@{$changes{$type}},'others');
7969: }
7970: if ($type eq 'helpdeskmail') {
7971: if ($bcc{$type} ne '') {
7972: push(@{$changes{$type}},'bcc');
7973: }
7974: }
7975: }
7976: }
7977: foreach my $item (@toggles) {
7978: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
7979: $changes{$item} = 1;
7980: } elsif ((!$env{'form.'.$item}) &&
7981: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
7982: $changes{$item} = 1;
7983: }
7984: }
7985: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
7986: $dom);
7987: if ($putresult eq 'ok') {
7988: if (keys(%changes) > 0) {
7989: &Apache::loncommon::devalidate_domconfig_cache($dom);
7990: if (ref($lastactref) eq 'HASH') {
7991: $lastactref->{'domainconfig'} = 1;
7992: }
7993: my ($titles,$short_titles) = &contact_titles();
7994: $resulttext = &mt('Changes made:').'<ul>';
7995: foreach my $item (@contacts) {
7996: if ($changes{$item}) {
7997: $resulttext .= '<li>'.$titles->{$item}.
7998: &mt(' set to: ').
7999: '<span class="LC_cusr_emph">'.
8000: $to{$item}.'</span></li>';
8001: }
8002: }
8003: foreach my $type (@mailings) {
8004: if (ref($changes{$type}) eq 'ARRAY') {
8005: $resulttext .= '<li>'.$titles->{$type}.': ';
8006: my @text;
8007: foreach my $item (@{$newsetting{$type}}) {
8008: push(@text,$short_titles->{$item});
8009: }
8010: if ($others{$type} ne '') {
8011: push(@text,$others{$type});
8012: }
8013: $resulttext .= '<span class="LC_cusr_emph">'.
8014: join(', ',@text).'</span>';
8015: if ($type eq 'helpdeskmail') {
8016: if ($bcc{$type} ne '') {
8017: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
8018: }
8019: }
8020: $resulttext .= '</li>';
8021: }
8022: }
8023: my @offon = ('off','on');
8024: if ($changes{'reporterrors'}) {
8025: $resulttext .= '<li>'.
8026: &mt('E-mail error reports to [_1] set to "'.
8027: $offon[$env{'form.reporterrors'}].'".',
8028: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8029: &mt('LON-CAPA core group - MSU'),600,500)).
8030: '</li>';
8031: }
8032: if ($changes{'reportupdates'}) {
8033: $resulttext .= '<li>'.
8034: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
8035: $offon[$env{'form.reportupdates'}].'".',
8036: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8037: &mt('LON-CAPA core group - MSU'),600,500)).
8038: '</li>';
8039: }
8040: $resulttext .= '</ul>';
8041: } else {
8042: $resulttext = &mt('No changes made to contact information');
8043: }
8044: } else {
8045: $resulttext = '<span class="LC_error">'.
8046: &mt('An error occurred: [_1].',$putresult).'</span>';
8047: }
8048: return $resulttext;
8049: }
8050:
8051: sub modify_usercreation {
8052: my ($dom,%domconfig) = @_;
8053: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
8054: my $warningmsg;
8055: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8056: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
8057: if ($key eq 'cancreate') {
8058: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8059: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8060: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8061: ($item eq 'captcha') || ($item eq 'recaptchakeys')) {
8062: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8063: } else {
8064: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8065: }
8066: }
8067: }
8068: } elsif ($key eq 'email_rule') {
8069: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8070: } else {
8071: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
8072: }
8073: }
8074: }
8075: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
8076: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
8077: my @contexts = ('author','course','requestcrs');
8078: foreach my $item(@contexts) {
8079: $cancreate{$item} = $env{'form.can_createuser_'.$item};
8080: }
8081: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8082: foreach my $item (@contexts) {
8083: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
8084: push(@{$changes{'cancreate'}},$item);
8085: }
8086: }
8087: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
8088: foreach my $item (@contexts) {
8089: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
8090: if ($cancreate{$item} ne 'any') {
8091: push(@{$changes{'cancreate'}},$item);
8092: }
8093: } else {
8094: if ($cancreate{$item} ne 'none') {
8095: push(@{$changes{'cancreate'}},$item);
8096: }
8097: }
8098: }
8099: } else {
8100: foreach my $item (@contexts) {
8101: push(@{$changes{'cancreate'}},$item);
8102: }
8103: }
8104:
8105: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
8106: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
8107: if (!grep(/^\Q$type\E$/,@username_rule)) {
8108: push(@{$changes{'username_rule'}},$type);
8109: }
8110: }
8111: foreach my $type (@username_rule) {
8112: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
8113: push(@{$changes{'username_rule'}},$type);
8114: }
8115: }
8116: } else {
8117: push(@{$changes{'username_rule'}},@username_rule);
8118: }
8119:
8120: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
8121: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
8122: if (!grep(/^\Q$type\E$/,@id_rule)) {
8123: push(@{$changes{'id_rule'}},$type);
8124: }
8125: }
8126: foreach my $type (@id_rule) {
8127: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
8128: push(@{$changes{'id_rule'}},$type);
8129: }
8130: }
8131: } else {
8132: push(@{$changes{'id_rule'}},@id_rule);
8133: }
8134:
8135: my @authen_contexts = ('author','course','domain');
8136: my @authtypes = ('int','krb4','krb5','loc');
8137: my %authhash;
8138: foreach my $item (@authen_contexts) {
8139: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
8140: foreach my $auth (@authtypes) {
8141: if (grep(/^\Q$auth\E$/,@authallowed)) {
8142: $authhash{$item}{$auth} = 1;
8143: } else {
8144: $authhash{$item}{$auth} = 0;
8145: }
8146: }
8147: }
8148: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
8149: foreach my $item (@authen_contexts) {
8150: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
8151: foreach my $auth (@authtypes) {
8152: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
8153: push(@{$changes{'authtypes'}},$item);
8154: last;
8155: }
8156: }
8157: }
8158: }
8159: } else {
8160: foreach my $item (@authen_contexts) {
8161: push(@{$changes{'authtypes'}},$item);
8162: }
8163: }
8164:
8165: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
8166: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
8167: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
8168: $save_usercreate{'id_rule'} = \@id_rule;
8169: $save_usercreate{'username_rule'} = \@username_rule,
8170: $save_usercreate{'authtypes'} = \%authhash;
8171:
8172: my %usercreation_hash = (
8173: usercreation => \%save_usercreate,
8174: );
8175:
8176: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
8177: $dom);
8178:
8179: if ($putresult eq 'ok') {
8180: if (keys(%changes) > 0) {
8181: $resulttext = &mt('Changes made:').'<ul>';
8182: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8183: my %lt = &usercreation_types();
8184: foreach my $type (@{$changes{'cancreate'}}) {
8185: my $chgtext = $lt{$type}.', ';
8186: if ($cancreate{$type} eq 'none') {
8187: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
8188: } elsif ($cancreate{$type} eq 'any') {
8189: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
8190: } elsif ($cancreate{$type} eq 'official') {
8191: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
8192: } elsif ($cancreate{$type} eq 'unofficial') {
8193: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
8194: }
8195: $resulttext .= '<li>'.$chgtext.'</li>';
8196: }
8197: }
8198: if (ref($changes{'username_rule'}) eq 'ARRAY') {
8199: my ($rules,$ruleorder) =
8200: &Apache::lonnet::inst_userrules($dom,'username');
8201: my $chgtext = '<ul>';
8202: foreach my $type (@username_rule) {
8203: if (ref($rules->{$type}) eq 'HASH') {
8204: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
8205: }
8206: }
8207: $chgtext .= '</ul>';
8208: if (@username_rule > 0) {
8209: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8210: } else {
8211: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
8212: }
8213: }
8214: if (ref($changes{'id_rule'}) eq 'ARRAY') {
8215: my ($idrules,$idruleorder) =
8216: &Apache::lonnet::inst_userrules($dom,'id');
8217: my $chgtext = '<ul>';
8218: foreach my $type (@id_rule) {
8219: if (ref($idrules->{$type}) eq 'HASH') {
8220: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
8221: }
8222: }
8223: $chgtext .= '</ul>';
8224: if (@id_rule > 0) {
8225: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8226: } else {
8227: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
8228: }
8229: }
8230: my %authname = &authtype_names();
8231: my %context_title = &context_names();
8232: if (ref($changes{'authtypes'}) eq 'ARRAY') {
8233: my $chgtext = '<ul>';
8234: foreach my $type (@{$changes{'authtypes'}}) {
8235: my @allowed;
8236: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
8237: foreach my $auth (@authtypes) {
8238: if ($authhash{$type}{$auth}) {
8239: push(@allowed,$authname{$auth});
8240: }
8241: }
8242: if (@allowed > 0) {
8243: $chgtext .= join(', ',@allowed).'</li>';
8244: } else {
8245: $chgtext .= &mt('none').'</li>';
8246: }
8247: }
8248: $chgtext .= '</ul>';
8249: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
8250: $resulttext .= '</li>';
8251: }
8252: $resulttext .= '</ul>';
8253: } else {
8254: $resulttext = &mt('No changes made to user creation settings');
8255: }
8256: } else {
8257: $resulttext = '<span class="LC_error">'.
8258: &mt('An error occurred: [_1]',$putresult).'</span>';
8259: }
8260: if ($warningmsg ne '') {
8261: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
8262: }
8263: return $resulttext;
8264: }
8265:
8266: sub modify_selfcreation {
8267: my ($dom,%domconfig) = @_;
8268: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
8269: my (%save_usercreate,%save_usermodify);
8270: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8271: if (ref($types) eq 'ARRAY') {
8272: $usertypes->{'default'} = $othertitle;
8273: push(@{$types},'default');
8274: }
8275: #
8276: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
8277: #
8278: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8279: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
8280: if ($key eq 'cancreate') {
8281: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8282: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8283: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8284: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
8285: ($item eq 'emailusername') || ($item eq 'notify') ||
8286: ($item eq 'selfcreateprocessing')) {
8287: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8288: } else {
8289: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8290: }
8291: }
8292: }
8293: } elsif ($key eq 'email_rule') {
8294: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
8295: } else {
8296: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8297: }
8298: }
8299: }
8300: #
8301: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
8302: #
8303: if (ref($domconfig{'usermodification'}) eq 'HASH') {
8304: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
8305: if ($key eq 'selfcreate') {
8306: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
8307: } else {
8308: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
8309: }
8310: }
8311: }
8312:
8313: my @contexts = ('selfcreate');
8314: @{$cancreate{'selfcreate'}} = ();
8315: %{$cancreate{'emailusername'}} = ();
8316: @{$cancreate{'statustocreate'}} = ();
8317: %{$cancreate{'selfcreateprocessing'}} = ();
8318: my %selfcreatetypes = (
8319: sso => 'users authenticated by institutional single sign on',
8320: login => 'users authenticated by institutional log-in',
8321: email => 'users who provide a valid e-mail address for use as username',
8322: );
8323: #
8324: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
8325: # is permitted.
8326: #
8327:
8328: my @statuses;
8329: if (ref($domconfig{'inststatus'}) eq 'HASH') {
8330: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
8331: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
8332: }
8333: }
8334: push(@statuses,'default');
8335:
8336: foreach my $item ('login','sso','email') {
8337: if ($item eq 'email') {
8338: if ($env{'form.cancreate_email'}) {
8339: push(@{$cancreate{'selfcreate'}},'email');
8340: push(@contexts,'selfcreateprocessing');
8341: foreach my $type (@statuses) {
8342: if ($type eq 'default') {
8343: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
8344: } else {
8345: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
8346: }
8347: }
8348: }
8349: } else {
8350: if ($env{'form.cancreate_'.$item}) {
8351: push(@{$cancreate{'selfcreate'}},$item);
8352: }
8353: }
8354: }
8355: my (@email_rule,%userinfo,%savecaptcha);
8356: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
8357: #
8358: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
8359: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
8360: #
8361:
8362: if ($env{'form.cancreate_email'} eq 'email') {
8363: push(@contexts,'emailusername');
8364: if (ref($types) eq 'ARRAY') {
8365: foreach my $type (@{$types}) {
8366: if (ref($infofields) eq 'ARRAY') {
8367: foreach my $field (@{$infofields}) {
8368: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
8369: $cancreate{'emailusername'}{$type}{$field} = $1;
8370: }
8371: }
8372: }
8373: }
8374: }
8375: #
8376: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
8377: # queued requests for self-creation of account using e-mail address as username
8378: #
8379:
8380: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
8381: @approvalnotify = sort(@approvalnotify);
8382: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
8383: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8384: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
8385: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
8386: push(@{$changes{'cancreate'}},'notify');
8387: }
8388: } else {
8389: if ($cancreate{'notify'}{'approval'}) {
8390: push(@{$changes{'cancreate'}},'notify');
8391: }
8392: }
8393: } elsif ($cancreate{'notify'}{'approval'}) {
8394: push(@{$changes{'cancreate'}},'notify');
8395: }
8396:
8397: #
8398: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
8399: #
8400: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
8401: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
8402: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
8403: if (@{$curr_usercreation{'email_rule'}} > 0) {
8404: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
8405: if (!grep(/^\Q$type\E$/,@email_rule)) {
8406: push(@{$changes{'email_rule'}},$type);
8407: }
8408: }
8409: }
8410: if (@email_rule > 0) {
8411: foreach my $type (@email_rule) {
8412: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
8413: push(@{$changes{'email_rule'}},$type);
8414: }
8415: }
8416: }
8417: } elsif (@email_rule > 0) {
8418: push(@{$changes{'email_rule'}},@email_rule);
8419: }
8420: }
8421: #
8422: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
8423: # institutional log-in.
8424: #
8425: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
8426: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8427: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
8428: ($domdefaults{'auth_def'} eq 'localauth'))) {
8429: $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.').' '.
8430: &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.');
8431: }
8432: }
8433: my @fields = ('lastname','firstname','middlename','generation',
8434: 'permanentemail','id');
8435: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8436: #
8437: # Where usernames may created for institutional log-in and/or institutional single sign on:
8438: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
8439: # may self-create accounts
8440: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
8441: # which the user may supply, if institutional data is unavailable.
8442: #
8443: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
8444: if (ref($types) eq 'ARRAY') {
8445: if (@{$types} > 1) {
8446: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
8447: push(@contexts,'statustocreate');
8448: } else {
8449: undef($cancreate{'statustocreate'});
8450: }
8451: foreach my $type (@{$types}) {
8452: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
8453: foreach my $field (@fields) {
8454: if (grep(/^\Q$field\E$/,@modifiable)) {
8455: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
8456: } else {
8457: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
8458: }
8459: }
8460: }
8461: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
8462: foreach my $type (@{$types}) {
8463: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
8464: foreach my $field (@fields) {
8465: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
8466: $curr_usermodify{'selfcreate'}{$type}{$field}) {
8467: push(@{$changes{'selfcreate'}},$type);
8468: last;
8469: }
8470: }
8471: }
8472: }
8473: } else {
8474: foreach my $type (@{$types}) {
8475: push(@{$changes{'selfcreate'}},$type);
8476: }
8477: }
8478: }
8479: }
8480: foreach my $item (@contexts) {
8481: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
8482: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
8483: if (ref($cancreate{$item}) eq 'ARRAY') {
8484: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
8485: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8486: push(@{$changes{'cancreate'}},$item);
8487: }
8488: }
8489: }
8490: }
8491: if (ref($cancreate{$item}) eq 'ARRAY') {
8492: foreach my $type (@{$cancreate{$item}}) {
8493: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
8494: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8495: push(@{$changes{'cancreate'}},$item);
8496: }
8497: }
8498: }
8499: }
8500: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
8501: if (ref($cancreate{$item}) eq 'HASH') {
8502: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
8503: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
8504: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
8505: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
8506: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8507: push(@{$changes{'cancreate'}},$item);
8508: }
8509: }
8510: }
8511: } elsif ($item eq 'selfcreateprocessing') {
8512: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
8513: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8514: push(@{$changes{'cancreate'}},$item);
8515: }
8516: }
8517: } else {
8518: if (!$cancreate{$item}{$curr}) {
8519: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8520: push(@{$changes{'cancreate'}},$item);
8521: }
8522: }
8523: }
8524: }
8525: foreach my $field (keys(%{$cancreate{$item}})) {
8526: if (ref($cancreate{$item}{$field}) eq 'HASH') {
8527: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
8528: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
8529: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
8530: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8531: push(@{$changes{'cancreate'}},$item);
8532: }
8533: }
8534: } else {
8535: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8536: push(@{$changes{'cancreate'}},$item);
8537: }
8538: }
8539: }
8540: } elsif ($item eq 'selfcreateprocessing') {
8541: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
8542: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8543: push(@{$changes{'cancreate'}},$item);
8544: }
8545: }
8546: } else {
8547: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
8548: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8549: push(@{$changes{'cancreate'}},$item);
8550: }
8551: }
8552: }
8553: }
8554: }
8555: } elsif ($curr_usercreation{'cancreate'}{$item}) {
8556: if (ref($cancreate{$item}) eq 'ARRAY') {
8557: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
8558: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8559: push(@{$changes{'cancreate'}},$item);
8560: }
8561: }
8562: } elsif (ref($cancreate{$item}) eq 'HASH') {
8563: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
8564: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8565: push(@{$changes{'cancreate'}},$item);
8566: }
8567: }
8568: }
8569: } elsif ($item eq 'emailusername') {
8570: if (ref($cancreate{$item}) eq 'HASH') {
8571: foreach my $type (keys(%{$cancreate{$item}})) {
8572: if (ref($cancreate{$item}{$type}) eq 'HASH') {
8573: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
8574: if ($cancreate{$item}{$type}{$field}) {
8575: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8576: push(@{$changes{'cancreate'}},$item);
8577: }
8578: last;
8579: }
8580: }
8581: }
8582: }
8583: }
8584: }
8585: }
8586: #
8587: # Populate %save_usercreate hash with updates to self-creation configuration.
8588: #
8589: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
8590: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
8591: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
8592: if (ref($cancreate{'notify'}) eq 'HASH') {
8593: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
8594: }
8595: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
8596: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
8597: }
8598: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
8599: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
8600: }
8601: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
8602: $save_usercreate{'emailrule'} = \@email_rule;
8603:
8604: my %userconfig_hash = (
8605: usercreation => \%save_usercreate,
8606: usermodification => \%save_usermodify,
8607: );
8608: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
8609: $dom);
8610: #
8611: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
8612: #
8613: if ($putresult eq 'ok') {
8614: if (keys(%changes) > 0) {
8615: $resulttext = &mt('Changes made:').'<ul>';
8616: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8617: my %lt = &selfcreation_types();
8618: foreach my $type (@{$changes{'cancreate'}}) {
8619: my $chgtext;
8620: if ($type eq 'selfcreate') {
8621: if (@{$cancreate{$type}} == 0) {
8622: $chgtext .= &mt('Self creation of a new user account is not permitted.');
8623: } else {
8624: $chgtext .= &mt('Self-creation of a new account is permitted for:').
8625: '<ul>';
8626: foreach my $case (@{$cancreate{$type}}) {
8627: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
8628: }
8629: $chgtext .= '</ul>';
8630: if (ref($cancreate{$type}) eq 'ARRAY') {
8631: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
8632: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
8633: if (@{$cancreate{'statustocreate'}} == 0) {
8634: $chgtext .= '<br />'.
8635: '<span class="LC_warning">'.
8636: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
8637: '</span>';
8638: }
8639: }
8640: }
8641: }
8642: }
8643: } elsif ($type eq 'statustocreate') {
8644: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
8645: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
8646: if (@{$cancreate{'selfcreate'}} > 0) {
8647: if (@{$cancreate{'statustocreate'}} == 0) {
8648: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
8649: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
8650: $chgtext .= '<br />'.
8651: '<span class="LC_warning">'.
8652: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
8653: '</span>';
8654: }
8655: } elsif (ref($usertypes) eq 'HASH') {
8656: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
8657: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
8658: } else {
8659: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
8660: }
8661: $chgtext .= '<ul>';
8662: foreach my $case (@{$cancreate{$type}}) {
8663: if ($case eq 'default') {
8664: $chgtext .= '<li>'.$othertitle.'</li>';
8665: } else {
8666: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
8667: }
8668: }
8669: $chgtext .= '</ul>';
8670: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
8671: $chgtext .= '<br /><span class="LC_warning">'.
8672: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
8673: '</span>';
8674: }
8675: }
8676: } else {
8677: if (@{$cancreate{$type}} == 0) {
8678: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
8679: } else {
8680: $chgtext .= &mt('Although institutional affiliations permitted to create accounts were changed, self creation of accounts is not currently permitted for any authentication types.');
8681: }
8682: }
8683: }
8684: } elsif ($type eq 'selfcreateprocessing') {
8685: my %choices = &Apache::lonlocal::texthash (
8686: automatic => 'Automatic approval',
8687: approval => 'Queued for approval',
8688: );
8689: if (@statuses > 1) {
8690: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
8691: '<ul>';
8692: foreach my $type (@statuses) {
8693: if ($type eq 'default') {
8694: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
8695: } else {
8696: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
8697: }
8698: }
8699: $chgtext .= '</ul>';
8700: } else {
8701: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
8702: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
8703: }
8704: } elsif ($type eq 'captcha') {
8705: if ($savecaptcha{$type} eq 'notused') {
8706: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
8707: } else {
8708: my %captchas = &captcha_phrases();
8709: if ($captchas{$savecaptcha{$type}}) {
8710: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
8711: } else {
8712: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
8713: }
8714: }
8715: } elsif ($type eq 'recaptchakeys') {
8716: my ($privkey,$pubkey);
8717: if (ref($savecaptcha{$type}) eq 'HASH') {
8718: $pubkey = $savecaptcha{$type}{'public'};
8719: $privkey = $savecaptcha{$type}{'private'};
8720: }
8721: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
8722: if (!$pubkey) {
8723: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
8724: } else {
8725: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
8726: }
8727: if (!$privkey) {
8728: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
8729: } else {
8730: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
8731: }
8732: $chgtext .= '</ul>';
8733: } elsif ($type eq 'emailusername') {
8734: if (ref($cancreate{'emailusername'}) eq 'HASH') {
8735: if (ref($types) eq 'ARRAY') {
8736: foreach my $type (@{$types}) {
8737: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
8738: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
8739: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',$usertypes->{$type}).
8740: '<ul>';
8741: foreach my $field (@{$infofields}) {
8742: if ($cancreate{'emailusername'}{$type}{$field}) {
8743: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
8744: }
8745: }
8746: }
8747: $chgtext .= '</ul>';
8748: } else {
8749: $chgtext .= &mt('When self creating account with e-mail as username, no information besides e-mail address will be provided by [_1].',$usertypes->{$type}).'<br />';
8750: }
8751: }
8752: }
8753: }
8754: } elsif ($type eq 'notify') {
8755: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
8756: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8757: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
8758: if ($cancreate{'notify'}{'approval'}) {
8759: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
8760: }
8761: }
8762: }
8763: }
8764: if ($chgtext) {
8765: $resulttext .= '<li>'.$chgtext.'</li>';
8766: }
8767: }
8768: }
8769: if (ref($changes{'email_rule'}) eq 'ARRAY') {
8770: my ($emailrules,$emailruleorder) =
8771: &Apache::lonnet::inst_userrules($dom,'email');
8772: my $chgtext = '<ul>';
8773: foreach my $type (@email_rule) {
8774: if (ref($emailrules->{$type}) eq 'HASH') {
8775: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
8776: }
8777: }
8778: $chgtext .= '</ul>';
8779: if (@email_rule > 0) {
8780: $resulttext .= '<li>'.
8781: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
8782: $chgtext.
8783: '</li>';
8784: } else {
8785: $resulttext .= '<li>'.
8786: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
8787: '</li>';
8788: }
8789: }
8790: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
8791: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
8792: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8793: foreach my $type (@{$changes{'selfcreate'}}) {
8794: my $typename = $type;
8795: if (ref($usertypes) eq 'HASH') {
8796: if ($usertypes->{$type} ne '') {
8797: $typename = $usertypes->{$type};
8798: }
8799: }
8800: my @modifiable;
8801: $resulttext .= '<li>'.
8802: &mt('Self-creation of account by users with status: [_1]',
8803: '<span class="LC_cusr_emph">'.$typename.'</span>').
8804: ' - '.&mt('modifiable fields (if institutional data blank): ');
8805: foreach my $field (@fields) {
8806: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
8807: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
8808: }
8809: }
8810: if (@modifiable > 0) {
8811: $resulttext .= join(', ',@modifiable);
8812: } else {
8813: $resulttext .= &mt('none');
8814: }
8815: $resulttext .= '</li>';
8816: }
8817: $resulttext .= '</ul></li>';
8818: }
8819: $resulttext .= '</ul>';
8820: } else {
8821: $resulttext = &mt('No changes made to self-creation settings');
8822: }
8823: } else {
8824: $resulttext = '<span class="LC_error">'.
8825: &mt('An error occurred: [_1]',$putresult).'</span>';
8826: }
8827: if ($warningmsg ne '') {
8828: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
8829: }
8830: return $resulttext;
8831: }
8832:
8833: sub process_captcha {
8834: my ($container,$changes,$newsettings,$current) = @_;
8835: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
8836: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
8837: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
8838: $newsettings->{'captcha'} = 'original';
8839: }
8840: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
8841: if ($container eq 'cancreate') {
8842: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
8843: push(@{$changes->{'cancreate'}},'captcha');
8844: } elsif (!defined($changes->{'cancreate'})) {
8845: $changes->{'cancreate'} = ['captcha'];
8846: }
8847: } else {
8848: $changes->{'captcha'} = 1;
8849: }
8850: }
8851: my ($newpub,$newpriv,$currpub,$currpriv);
8852: if ($newsettings->{'captcha'} eq 'recaptcha') {
8853: $newpub = $env{'form.'.$container.'_recaptchapub'};
8854: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
8855: $newpub =~ s/\W//g;
8856: $newpriv =~ s/\W//g;
8857: $newsettings->{'recaptchakeys'} = {
8858: public => $newpub,
8859: private => $newpriv,
8860: };
8861: }
8862: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
8863: $currpub = $current->{'recaptchakeys'}{'public'};
8864: $currpriv = $current->{'recaptchakeys'}{'private'};
8865: unless ($newsettings->{'captcha'} eq 'recaptcha') {
8866: $newsettings->{'recaptchakeys'} = {
8867: public => '',
8868: private => '',
8869: }
8870: }
8871: }
8872: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
8873: if ($container eq 'cancreate') {
8874: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
8875: push(@{$changes->{'cancreate'}},'recaptchakeys');
8876: } elsif (!defined($changes->{'cancreate'})) {
8877: $changes->{'cancreate'} = ['recaptchakeys'];
8878: }
8879: } else {
8880: $changes->{'recaptchakeys'} = 1;
8881: }
8882: }
8883: return;
8884: }
8885:
8886: sub modify_usermodification {
8887: my ($dom,%domconfig) = @_;
8888: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
8889: if (ref($domconfig{'usermodification'}) eq 'HASH') {
8890: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
8891: if ($key eq 'selfcreate') {
8892: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
8893: } else {
8894: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
8895: }
8896: }
8897: }
8898: my @contexts = ('author','course');
8899: my %context_title = (
8900: author => 'In author context',
8901: course => 'In course context',
8902: );
8903: my @fields = ('lastname','firstname','middlename','generation',
8904: 'permanentemail','id');
8905: my %roles = (
8906: author => ['ca','aa'],
8907: course => ['st','ep','ta','in','cr'],
8908: );
8909: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8910: foreach my $context (@contexts) {
8911: foreach my $role (@{$roles{$context}}) {
8912: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
8913: foreach my $item (@fields) {
8914: if (grep(/^\Q$item\E$/,@modifiable)) {
8915: $modifyhash{$context}{$role}{$item} = 1;
8916: } else {
8917: $modifyhash{$context}{$role}{$item} = 0;
8918: }
8919: }
8920: }
8921: if (ref($curr_usermodification{$context}) eq 'HASH') {
8922: foreach my $role (@{$roles{$context}}) {
8923: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
8924: foreach my $field (@fields) {
8925: if ($modifyhash{$context}{$role}{$field} ne
8926: $curr_usermodification{$context}{$role}{$field}) {
8927: push(@{$changes{$context}},$role);
8928: last;
8929: }
8930: }
8931: }
8932: }
8933: } else {
8934: foreach my $context (@contexts) {
8935: foreach my $role (@{$roles{$context}}) {
8936: push(@{$changes{$context}},$role);
8937: }
8938: }
8939: }
8940: }
8941: my %usermodification_hash = (
8942: usermodification => \%modifyhash,
8943: );
8944: my $putresult = &Apache::lonnet::put_dom('configuration',
8945: \%usermodification_hash,$dom);
8946: if ($putresult eq 'ok') {
8947: if (keys(%changes) > 0) {
8948: $resulttext = &mt('Changes made: ').'<ul>';
8949: foreach my $context (@contexts) {
8950: if (ref($changes{$context}) eq 'ARRAY') {
8951: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
8952: if (ref($changes{$context}) eq 'ARRAY') {
8953: foreach my $role (@{$changes{$context}}) {
8954: my $rolename;
8955: if ($role eq 'cr') {
8956: $rolename = &mt('Custom');
8957: } else {
8958: $rolename = &Apache::lonnet::plaintext($role);
8959: }
8960: my @modifiable;
8961: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
8962: foreach my $field (@fields) {
8963: if ($modifyhash{$context}{$role}{$field}) {
8964: push(@modifiable,$fieldtitles{$field});
8965: }
8966: }
8967: if (@modifiable > 0) {
8968: $resulttext .= join(', ',@modifiable);
8969: } else {
8970: $resulttext .= &mt('none');
8971: }
8972: $resulttext .= '</li>';
8973: }
8974: $resulttext .= '</ul></li>';
8975: }
8976: }
8977: }
8978: $resulttext .= '</ul>';
8979: } else {
8980: $resulttext = &mt('No changes made to user modification settings');
8981: }
8982: } else {
8983: $resulttext = '<span class="LC_error">'.
8984: &mt('An error occurred: [_1]',$putresult).'</span>';
8985: }
8986: return $resulttext;
8987: }
8988:
8989: sub modify_defaults {
8990: my ($dom,$lastactref,%domconfig) = @_;
8991: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
8992: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8993: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
8994: my @authtypes = ('internal','krb4','krb5','localauth');
8995: foreach my $item (@items) {
8996: $newvalues{$item} = $env{'form.'.$item};
8997: if ($item eq 'auth_def') {
8998: if ($newvalues{$item} ne '') {
8999: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
9000: push(@errors,$item);
9001: }
9002: }
9003: } elsif ($item eq 'lang_def') {
9004: if ($newvalues{$item} ne '') {
9005: if ($newvalues{$item} =~ /^(\w+)/) {
9006: my $langcode = $1;
9007: if ($langcode ne 'x_chef') {
9008: if (code2language($langcode) eq '') {
9009: push(@errors,$item);
9010: }
9011: }
9012: } else {
9013: push(@errors,$item);
9014: }
9015: }
9016: } elsif ($item eq 'timezone_def') {
9017: if ($newvalues{$item} ne '') {
9018: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
9019: push(@errors,$item);
9020: }
9021: }
9022: } elsif ($item eq 'datelocale_def') {
9023: if ($newvalues{$item} ne '') {
9024: my @datelocale_ids = DateTime::Locale->ids();
9025: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
9026: push(@errors,$item);
9027: }
9028: }
9029: } elsif ($item eq 'portal_def') {
9030: if ($newvalues{$item} ne '') {
9031: 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])\/?$/) {
9032: push(@errors,$item);
9033: }
9034: }
9035: }
9036: if (grep(/^\Q$item\E$/,@errors)) {
9037: $newvalues{$item} = $domdefaults{$item};
9038: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
9039: $changes{$item} = 1;
9040: }
9041: $domdefaults{$item} = $newvalues{$item};
9042: }
9043: my %defaults_hash = (
9044: defaults => \%newvalues,
9045: );
9046: my $title = &defaults_titles();
9047:
9048: my $currinststatus;
9049: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9050: $currinststatus = $domconfig{'inststatus'};
9051: } else {
9052: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9053: $currinststatus = {
9054: inststatustypes => $usertypes,
9055: inststatusorder => $types,
9056: inststatusguest => [],
9057: };
9058: }
9059: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
9060: my @allpos;
9061: my %guests;
9062: my %alltypes;
9063: my ($currtitles,$currguests,$currorder);
9064: if (ref($currinststatus) eq 'HASH') {
9065: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
9066: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
9067: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
9068: if ($currinststatus->{inststatustypes}->{$type} ne '') {
9069: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
9070: }
9071: }
9072: unless (grep(/^\Q$type\E$/,@todelete)) {
9073: my $position = $env{'form.inststatus_pos_'.$type};
9074: $position =~ s/\D+//g;
9075: $allpos[$position] = $type;
9076: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
9077: $alltypes{$type} =~ s/`//g;
9078: if ($env{'form.inststatus_guest_'.$type}) {
9079: $guests{$type} = 1;
9080: }
9081: }
9082: }
9083: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
9084: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
9085: }
9086: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
9087: $currtitles =~ s/,$//;
9088: }
9089: }
9090: if ($env{'form.addinststatus'}) {
9091: my $newtype = $env{'form.addinststatus'};
9092: $newtype =~ s/\W//g;
9093: unless (exists($alltypes{$newtype})) {
9094: if ($env{'form.addinststatus_guest'}) {
9095: $guests{$newtype} = 1;
9096: }
9097: $alltypes{$newtype} = $env{'form.addinststatus_title'};
9098: $alltypes{$newtype} =~ s/`//g;
9099: my $position = $env{'form.addinststatus_pos'};
9100: $position =~ s/\D+//g;
9101: if ($position ne '') {
9102: $allpos[$position] = $newtype;
9103: }
9104: }
9105: }
9106: my (@orderedstatus,@orderedguests);
9107: foreach my $type (@allpos) {
9108: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
9109: push(@orderedstatus,$type);
9110: if ($guests{$type}) {
9111: push(@orderedguests,$type);
9112: }
9113: }
9114: }
9115: foreach my $type (keys(%alltypes)) {
9116: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
9117: delete($alltypes{$type});
9118: }
9119: }
9120: $defaults_hash{'inststatus'} = {
9121: inststatustypes => \%alltypes,
9122: inststatusorder => \@orderedstatus,
9123: inststatusguest => \@orderedguests,
9124: };
9125: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
9126: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
9127: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
9128: }
9129: }
9130: if ($currorder ne join(',',@orderedstatus)) {
9131: $changes{'inststatus'}{'inststatusorder'} = 1;
9132: }
9133: if ($currguests ne join(',',@orderedguests)) {
9134: $changes{'inststatus'}{'inststatusguest'} = 1;
9135: }
9136: my $newtitles;
9137: foreach my $item (@orderedstatus) {
9138: $newtitles .= $alltypes{$item}.',';
9139: }
9140: $newtitles =~ s/,$//;
9141: if ($currtitles ne $newtitles) {
9142: $changes{'inststatus'}{'inststatustypes'} = 1;
9143: }
9144: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
9145: $dom);
9146: if ($putresult eq 'ok') {
9147: if (keys(%changes) > 0) {
9148: $resulttext = &mt('Changes made:').'<ul>';
9149: my $version = &Apache::lonnet::get_server_loncaparev($dom);
9150: 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";
9151: foreach my $item (sort(keys(%changes))) {
9152: if ($item eq 'inststatus') {
9153: if (ref($changes{'inststatus'}) eq 'HASH') {
9154: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
9155: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
9156: foreach my $type (@orderedstatus) {
9157: $resulttext .= $alltypes{$type}.', ';
9158: }
9159: $resulttext =~ s/, $//;
9160: $resulttext .= '</li>';
9161: }
9162: if ($changes{'inststatus'}{'inststatusguest'}) {
9163: $resulttext .= '<li>';
9164: if (@orderedguests) {
9165: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
9166: foreach my $type (@orderedguests) {
9167: $resulttext .= $alltypes{$type}.', ';
9168: }
9169: $resulttext =~ s/, $//;
9170: } else {
9171: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
9172: }
9173: $resulttext .= '</li>';
9174: }
9175: }
9176: } else {
9177: my $value = $env{'form.'.$item};
9178: if ($value eq '') {
9179: $value = &mt('none');
9180: } elsif ($item eq 'auth_def') {
9181: my %authnames = &authtype_names();
9182: my %shortauth = (
9183: internal => 'int',
9184: krb4 => 'krb4',
9185: krb5 => 'krb5',
9186: localauth => 'loc',
9187: );
9188: $value = $authnames{$shortauth{$value}};
9189: }
9190: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
9191: $mailmsgtext .= "$title->{$item} set to $value\n";
9192: }
9193: }
9194: $resulttext .= '</ul>';
9195: $mailmsgtext .= "\n";
9196: my $cachetime = 24*60*60;
9197: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
9198: if (ref($lastactref) eq 'HASH') {
9199: $lastactref->{'domdefaults'} = 1;
9200: }
9201: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
9202: my $notify = 1;
9203: if (ref($domconfig{'contacts'}) eq 'HASH') {
9204: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
9205: $notify = 0;
9206: }
9207: }
9208: if ($notify) {
9209: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
9210: "LON-CAPA Domain Settings Change - $dom",
9211: $mailmsgtext);
9212: }
9213: }
9214: } else {
9215: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
9216: }
9217: } else {
9218: $resulttext = '<span class="LC_error">'.
9219: &mt('An error occurred: [_1]',$putresult).'</span>';
9220: }
9221: if (@errors > 0) {
9222: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
9223: foreach my $item (@errors) {
9224: $resulttext .= ' "'.$title->{$item}.'",';
9225: }
9226: $resulttext =~ s/,$//;
9227: }
9228: return $resulttext;
9229: }
9230:
9231: sub modify_scantron {
9232: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
9233: my ($resulttext,%confhash,%changes,$errors);
9234: my $custom = 'custom.tab';
9235: my $default = 'default.tab';
9236: my $servadm = $r->dir_config('lonAdmEMail');
9237: my ($configuserok,$author_ok,$switchserver) =
9238: &config_check($dom,$confname,$servadm);
9239: if ($env{'form.scantronformat.filename'} ne '') {
9240: my $error;
9241: if ($configuserok eq 'ok') {
9242: if ($switchserver) {
9243: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
9244: } else {
9245: if ($author_ok eq 'ok') {
9246: my ($result,$scantronurl) =
9247: &publishlogo($r,'upload','scantronformat',$dom,
9248: $confname,'scantron','','',$custom);
9249: if ($result eq 'ok') {
9250: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
9251: $changes{'scantronformat'} = 1;
9252: } else {
9253: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
9254: }
9255: } else {
9256: $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);
9257: }
9258: }
9259: } else {
9260: $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);
9261: }
9262: if ($error) {
9263: &Apache::lonnet::logthis($error);
9264: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9265: }
9266: }
9267: if (ref($domconfig{'scantron'}) eq 'HASH') {
9268: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
9269: if ($env{'form.scantronformat_del'}) {
9270: $confhash{'scantron'}{'scantronformat'} = '';
9271: $changes{'scantronformat'} = 1;
9272: }
9273: }
9274: }
9275: if (keys(%confhash) > 0) {
9276: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
9277: $dom);
9278: if ($putresult eq 'ok') {
9279: if (keys(%changes) > 0) {
9280: if (ref($confhash{'scantron'}) eq 'HASH') {
9281: $resulttext = &mt('Changes made:').'<ul>';
9282: if ($confhash{'scantron'}{'scantronformat'} eq '') {
9283: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
9284: } else {
9285: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
9286: }
9287: $resulttext .= '</ul>';
9288: } else {
9289: $resulttext = &mt('Changes made to bubblesheet format file.');
9290: }
9291: $resulttext .= '</ul>';
9292: &Apache::loncommon::devalidate_domconfig_cache($dom);
9293: if (ref($lastactref) eq 'HASH') {
9294: $lastactref->{'domainconfig'} = 1;
9295: }
9296: } else {
9297: $resulttext = &mt('No changes made to bubblesheet format file');
9298: }
9299: } else {
9300: $resulttext = '<span class="LC_error">'.
9301: &mt('An error occurred: [_1]',$putresult).'</span>';
9302: }
9303: } else {
9304: $resulttext = &mt('No changes made to bubblesheet format file');
9305: }
9306: if ($errors) {
9307: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9308: $errors.'</ul>';
9309: }
9310: return $resulttext;
9311: }
9312:
9313: sub modify_coursecategories {
9314: my ($dom,%domconfig) = @_;
9315: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
9316: $cathash);
9317: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
9318: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9319: $cathash = $domconfig{'coursecategories'}{'cats'};
9320: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
9321: $changes{'togglecats'} = 1;
9322: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
9323: }
9324: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
9325: $changes{'categorize'} = 1;
9326: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
9327: }
9328: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
9329: $changes{'togglecatscomm'} = 1;
9330: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
9331: }
9332: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
9333: $changes{'categorizecomm'} = 1;
9334: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
9335: }
9336: } else {
9337: $changes{'togglecats'} = 1;
9338: $changes{'categorize'} = 1;
9339: $changes{'togglecatscomm'} = 1;
9340: $changes{'categorizecomm'} = 1;
9341: $domconfig{'coursecategories'} = {
9342: togglecats => $env{'form.togglecats'},
9343: categorize => $env{'form.categorize'},
9344: togglecatscomm => $env{'form.togglecatscomm'},
9345: categorizecomm => $env{'form.categorizecomm'},
9346: };
9347: }
9348: if (ref($cathash) eq 'HASH') {
9349: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
9350: push (@deletecategory,'instcode::0');
9351: }
9352: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
9353: push(@deletecategory,'communities::0');
9354: }
9355: }
9356: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
9357: if (ref($cathash) eq 'HASH') {
9358: if (@deletecategory > 0) {
9359: #FIXME Need to remove category from all courses using a deleted category
9360: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
9361: foreach my $item (@deletecategory) {
9362: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
9363: delete($domconfig{'coursecategories'}{'cats'}{$item});
9364: $deletions{$item} = 1;
9365: &recurse_cat_deletes($item,$cathash,\%deletions);
9366: }
9367: }
9368: }
9369: foreach my $item (keys(%{$cathash})) {
9370: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9371: if ($cathash->{$item} ne $env{'form.'.$item}) {
9372: $reorderings{$item} = 1;
9373: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
9374: }
9375: if ($env{'form.addcategory_name_'.$item} ne '') {
9376: my $newcat = $env{'form.addcategory_name_'.$item};
9377: my $newdepth = $depth+1;
9378: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
9379: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
9380: $adds{$newitem} = 1;
9381: }
9382: if ($env{'form.subcat_'.$item} ne '') {
9383: my $newcat = $env{'form.subcat_'.$item};
9384: my $newdepth = $depth+1;
9385: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
9386: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
9387: $adds{$newitem} = 1;
9388: }
9389: }
9390: }
9391: if ($env{'form.instcode'} eq '1') {
9392: if (ref($cathash) eq 'HASH') {
9393: my $newitem = 'instcode::0';
9394: if ($cathash->{$newitem} eq '') {
9395: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
9396: $adds{$newitem} = 1;
9397: }
9398: } else {
9399: my $newitem = 'instcode::0';
9400: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
9401: $adds{$newitem} = 1;
9402: }
9403: }
9404: if ($env{'form.communities'} eq '1') {
9405: if (ref($cathash) eq 'HASH') {
9406: my $newitem = 'communities::0';
9407: if ($cathash->{$newitem} eq '') {
9408: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9409: $adds{$newitem} = 1;
9410: }
9411: } else {
9412: my $newitem = 'communities::0';
9413: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9414: $adds{$newitem} = 1;
9415: }
9416: }
9417: if ($env{'form.addcategory_name'} ne '') {
9418: if (($env{'form.addcategory_name'} ne 'instcode') &&
9419: ($env{'form.addcategory_name'} ne 'communities')) {
9420: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
9421: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
9422: $adds{$newitem} = 1;
9423: }
9424: }
9425: my $putresult;
9426: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9427: if (keys(%deletions) > 0) {
9428: foreach my $key (keys(%deletions)) {
9429: if ($predelallitems{$key} ne '') {
9430: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
9431: }
9432: }
9433: }
9434: my (@chkcats,@chktrails,%chkallitems);
9435: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
9436: if (ref($chkcats[0]) eq 'ARRAY') {
9437: my $depth = 0;
9438: my $chg = 0;
9439: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
9440: my $name = $chkcats[0][$i];
9441: my $item;
9442: if ($name eq '') {
9443: $chg ++;
9444: } else {
9445: $item = &escape($name).'::0';
9446: if ($chg) {
9447: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
9448: }
9449: $depth ++;
9450: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
9451: $depth --;
9452: }
9453: }
9454: }
9455: }
9456: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9457: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
9458: if ($putresult eq 'ok') {
9459: my %title = (
9460: togglecats => 'Show/Hide a course in catalog',
9461: categorize => 'Assign a category to a course',
9462: togglecatscomm => 'Show/Hide a community in catalog',
9463: categorizecomm => 'Assign a category to a community',
9464: );
9465: my %level = (
9466: dom => 'set in Domain ("Modify Course/Community")',
9467: crs => 'set in Course ("Course Configuration")',
9468: comm => 'set in Community ("Community Configuration")',
9469: );
9470: $resulttext = &mt('Changes made:').'<ul>';
9471: if ($changes{'togglecats'}) {
9472: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
9473: }
9474: if ($changes{'categorize'}) {
9475: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
9476: }
9477: if ($changes{'togglecatscomm'}) {
9478: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
9479: }
9480: if ($changes{'categorizecomm'}) {
9481: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
9482: }
9483: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9484: my $cathash;
9485: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9486: $cathash = $domconfig{'coursecategories'}{'cats'};
9487: } else {
9488: $cathash = {};
9489: }
9490: my (@cats,@trails,%allitems);
9491: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
9492: if (keys(%deletions) > 0) {
9493: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
9494: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
9495: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
9496: }
9497: $resulttext .= '</ul></li>';
9498: }
9499: if (keys(%reorderings) > 0) {
9500: my %sort_by_trail;
9501: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
9502: foreach my $key (keys(%reorderings)) {
9503: if ($allitems{$key} ne '') {
9504: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
9505: }
9506: }
9507: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
9508: $resulttext .= '<li>'.$trails[$trail].'</li>';
9509: }
9510: $resulttext .= '</ul></li>';
9511: }
9512: if (keys(%adds) > 0) {
9513: my %sort_by_trail;
9514: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
9515: foreach my $key (keys(%adds)) {
9516: if ($allitems{$key} ne '') {
9517: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
9518: }
9519: }
9520: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
9521: $resulttext .= '<li>'.$trails[$trail].'</li>';
9522: }
9523: $resulttext .= '</ul></li>';
9524: }
9525: }
9526: $resulttext .= '</ul>';
9527: } else {
9528: $resulttext = '<span class="LC_error">'.
9529: &mt('An error occurred: [_1]',$putresult).'</span>';
9530: }
9531: } else {
9532: $resulttext = &mt('No changes made to course and community categories');
9533: }
9534: return $resulttext;
9535: }
9536:
9537: sub modify_serverstatuses {
9538: my ($dom,%domconfig) = @_;
9539: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
9540: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
9541: %currserverstatus = %{$domconfig{'serverstatuses'}};
9542: }
9543: my @pages = &serverstatus_pages();
9544: foreach my $type (@pages) {
9545: $newserverstatus{$type}{'namedusers'} = '';
9546: $newserverstatus{$type}{'machines'} = '';
9547: if (defined($env{'form.'.$type.'_namedusers'})) {
9548: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
9549: my @okusers;
9550: foreach my $user (@users) {
9551: my ($uname,$udom) = split(/:/,$user);
9552: if (($udom =~ /^$match_domain$/) &&
9553: (&Apache::lonnet::domain($udom)) &&
9554: ($uname =~ /^$match_username$/)) {
9555: if (!grep(/^\Q$user\E/,@okusers)) {
9556: push(@okusers,$user);
9557: }
9558: }
9559: }
9560: if (@okusers > 0) {
9561: @okusers = sort(@okusers);
9562: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
9563: }
9564: }
9565: if (defined($env{'form.'.$type.'_machines'})) {
9566: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
9567: my @okmachines;
9568: foreach my $ip (@machines) {
9569: my @parts = split(/\./,$ip);
9570: next if (@parts < 4);
9571: my $badip = 0;
9572: for (my $i=0; $i<4; $i++) {
9573: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
9574: $badip = 1;
9575: last;
9576: }
9577: }
9578: if (!$badip) {
9579: push(@okmachines,$ip);
9580: }
9581: }
9582: @okmachines = sort(@okmachines);
9583: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
9584: }
9585: }
9586: my %serverstatushash = (
9587: serverstatuses => \%newserverstatus,
9588: );
9589: foreach my $type (@pages) {
9590: foreach my $setting ('namedusers','machines') {
9591: my (@current,@new);
9592: if (ref($currserverstatus{$type}) eq 'HASH') {
9593: if ($currserverstatus{$type}{$setting} ne '') {
9594: @current = split(/,/,$currserverstatus{$type}{$setting});
9595: }
9596: }
9597: if ($newserverstatus{$type}{$setting} ne '') {
9598: @new = split(/,/,$newserverstatus{$type}{$setting});
9599: }
9600: if (@current > 0) {
9601: if (@new > 0) {
9602: foreach my $item (@current) {
9603: if (!grep(/^\Q$item\E$/,@new)) {
9604: $changes{$type}{$setting} = 1;
9605: last;
9606: }
9607: }
9608: foreach my $item (@new) {
9609: if (!grep(/^\Q$item\E$/,@current)) {
9610: $changes{$type}{$setting} = 1;
9611: last;
9612: }
9613: }
9614: } else {
9615: $changes{$type}{$setting} = 1;
9616: }
9617: } elsif (@new > 0) {
9618: $changes{$type}{$setting} = 1;
9619: }
9620: }
9621: }
9622: if (keys(%changes) > 0) {
9623: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
9624: my $putresult = &Apache::lonnet::put_dom('configuration',
9625: \%serverstatushash,$dom);
9626: if ($putresult eq 'ok') {
9627: $resulttext .= &mt('Changes made:').'<ul>';
9628: foreach my $type (@pages) {
9629: if (ref($changes{$type}) eq 'HASH') {
9630: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
9631: if ($changes{$type}{'namedusers'}) {
9632: if ($newserverstatus{$type}{'namedusers'} eq '') {
9633: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
9634: } else {
9635: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
9636: }
9637: }
9638: if ($changes{$type}{'machines'}) {
9639: if ($newserverstatus{$type}{'machines'} eq '') {
9640: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
9641: } else {
9642: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
9643: }
9644:
9645: }
9646: $resulttext .= '</ul></li>';
9647: }
9648: }
9649: $resulttext .= '</ul>';
9650: } else {
9651: $resulttext = '<span class="LC_error">'.
9652: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
9653:
9654: }
9655: } else {
9656: $resulttext = &mt('No changes made to access to server status pages');
9657: }
9658: return $resulttext;
9659: }
9660:
9661: sub modify_helpsettings {
9662: my ($r,$dom,$confname,%domconfig) = @_;
9663: my ($resulttext,$errors,%changes,%helphash);
9664: my %defaultchecked = ('submitbugs' => 'on');
9665: my @offon = ('off','on');
9666: my @toggles = ('submitbugs');
9667: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
9668: foreach my $item (@toggles) {
9669: if ($defaultchecked{$item} eq 'on') {
9670: if ($domconfig{'helpsettings'}{$item} eq '') {
9671: if ($env{'form.'.$item} eq '0') {
9672: $changes{$item} = 1;
9673: }
9674: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
9675: $changes{$item} = 1;
9676: }
9677: } elsif ($defaultchecked{$item} eq 'off') {
9678: if ($domconfig{'helpsettings'}{$item} eq '') {
9679: if ($env{'form.'.$item} eq '1') {
9680: $changes{$item} = 1;
9681: }
9682: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
9683: $changes{$item} = 1;
9684: }
9685: }
9686: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
9687: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
9688: }
9689: }
9690: }
9691: my $putresult;
9692: if (keys(%changes) > 0) {
9693: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
9694: if ($putresult eq 'ok') {
9695: $resulttext = &mt('Changes made:').'<ul>';
9696: foreach my $item (sort(keys(%changes))) {
9697: if ($item eq 'submitbugs') {
9698: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
9699: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
9700: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
9701: }
9702: }
9703: $resulttext .= '</ul>';
9704: } else {
9705: $resulttext = &mt('No changes made to help settings');
9706: $errors .= '<li><span class="LC_error">'.
9707: &mt('An error occurred storing the settings: [_1]',
9708: $putresult).'</span></li>';
9709: }
9710: }
9711: if ($errors) {
9712: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
9713: $errors.'</ul>';
9714: }
9715: return $resulttext;
9716: }
9717:
9718: sub modify_coursedefaults {
9719: my ($dom,$lastactref,%domconfig) = @_;
9720: my ($resulttext,$errors,%changes,%defaultshash);
9721: my %defaultchecked = ('canuse_pdfforms' => 'off');
9722: my @toggles = ('canuse_pdfforms');
9723: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
9724: 'uploadquota_community','uploadquota_textbook');
9725: my @types = ('official','unofficial','community','textbook');
9726: my %staticdefaults = (
9727: anonsurvey_threshold => 10,
9728: uploadquota => 500,
9729: );
9730:
9731: $defaultshash{'coursedefaults'} = {};
9732:
9733: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
9734: if ($domconfig{'coursedefaults'} eq '') {
9735: $domconfig{'coursedefaults'} = {};
9736: }
9737: }
9738:
9739: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
9740: foreach my $item (@toggles) {
9741: if ($defaultchecked{$item} eq 'on') {
9742: if (($domconfig{'coursedefaults'}{$item} eq '') &&
9743: ($env{'form.'.$item} eq '0')) {
9744: $changes{$item} = 1;
9745: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
9746: $changes{$item} = 1;
9747: }
9748: } elsif ($defaultchecked{$item} eq 'off') {
9749: if (($domconfig{'coursedefaults'}{$item} eq '') &&
9750: ($env{'form.'.$item} eq '1')) {
9751: $changes{$item} = 1;
9752: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
9753: $changes{$item} = 1;
9754: }
9755: }
9756: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
9757: }
9758: foreach my $item (@numbers) {
9759: my ($currdef,$newdef);
9760: $newdef = $env{'form.'.$item};
9761: if ($item eq 'anonsurvey_threshold') {
9762: $currdef = $domconfig{'coursedefaults'}{$item};
9763: $newdef =~ s/\D//g;
9764: if ($newdef eq '' || $newdef < 1) {
9765: $newdef = 1;
9766: }
9767: $defaultshash{'coursedefaults'}{$item} = $newdef;
9768: } else {
9769: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
9770: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
9771: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
9772: }
9773: $newdef =~ s/[^\w.\-]//g;
9774: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
9775: }
9776: if ($currdef ne $newdef) {
9777: my $staticdef;
9778: if ($item eq 'anonsurvey_threshold') {
9779: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
9780: $changes{$item} = 1;
9781: }
9782: } else {
9783: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
9784: $changes{'uploadquota'} = 1;
9785: }
9786: }
9787: }
9788: }
9789:
9790: my $officialcreds = $env{'form.official_credits'};
9791: $officialcreds =~ s/[^\d.]+//g;
9792: my $unofficialcreds = $env{'form.unofficial_credits'};
9793: $unofficialcreds =~ s/[^\d.]+//g;
9794: my $textbookcreds = $env{'form.textbook_credits'};
9795: $textbookcreds =~ s/[^\d.]+//g;
9796: if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
9797: ($env{'form.coursecredits'} eq '1')) {
9798: $changes{'coursecredits'} = 1;
9799: } else {
9800: if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
9801: ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds) ||
9802: ($domconfig{'coursedefaults'}{'coursecredits'}{'textbook'} ne $textbookcreds)) {
9803: $changes{'coursecredits'} = 1;
9804: }
9805: }
9806: $defaultshash{'coursedefaults'}{'coursecredits'} = {
9807: official => $officialcreds,
9808: unofficial => $unofficialcreds,
9809: textbook => $textbookcreds,
9810: }
9811: }
9812: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
9813: $dom);
9814: if ($putresult eq 'ok') {
9815: if (keys(%changes) > 0) {
9816: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9817: if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) ||
9818: ($changes{'uploadquota'})) {
9819: if ($changes{'canuse_pdfforms'}) {
9820: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
9821: }
9822: if ($changes{'coursecredits'}) {
9823: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
9824: $domdefaults{'officialcredits'} =
9825: $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
9826: $domdefaults{'unofficialcredits'} =
9827: $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
9828: $domdefaults{'textbookcredits'} =
9829: $domdefaults{'coursedefaults'}{'coursecredits'}{'textbook'};
9830: }
9831: }
9832: if ($changes{'uploadquota'}) {
9833: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
9834: foreach my $type (@types) {
9835: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
9836: }
9837: }
9838: }
9839: my $cachetime = 24*60*60;
9840: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
9841: if (ref($lastactref) eq 'HASH') {
9842: $lastactref->{'domdefaults'} = 1;
9843: }
9844: }
9845: $resulttext = &mt('Changes made:').'<ul>';
9846: foreach my $item (sort(keys(%changes))) {
9847: if ($item eq 'canuse_pdfforms') {
9848: if ($env{'form.'.$item} eq '1') {
9849: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
9850: } else {
9851: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
9852: }
9853: } elsif ($item eq 'anonsurvey_threshold') {
9854: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
9855: } elsif ($item eq 'uploadquota') {
9856: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
9857: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
9858: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
9859: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
9860: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
9861:
9862: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
9863: '</ul>'.
9864: '</li>';
9865: } else {
9866: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
9867: }
9868: } elsif ($item eq 'coursecredits') {
9869: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
9870: if (($domdefaults{'officialcredits'} eq '') &&
9871: ($domdefaults{'unofficialcredits'} eq '') &&
9872: ($domdefaults{'textbookcredits'} eq '')) {
9873: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
9874: } else {
9875: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
9876: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
9877: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
9878: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
9879: '</ul>'.
9880: '</li>';
9881: }
9882: } else {
9883: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
9884: }
9885: }
9886: }
9887: $resulttext .= '</ul>';
9888: } else {
9889: $resulttext = &mt('No changes made to course defaults');
9890: }
9891: } else {
9892: $resulttext = '<span class="LC_error">'.
9893: &mt('An error occurred: [_1]',$putresult).'</span>';
9894: }
9895: return $resulttext;
9896: }
9897:
9898: sub modify_selfenrollment {
9899: my ($dom,$lastactref,%domconfig) = @_;
9900: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
9901: my @types = ('official','unofficial','community','textbook');
9902: my %titles = &tool_titles();
9903: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
9904: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
9905: $ordered{'default'} = ['types','registered','approval','limit'];
9906:
9907: my (%roles,%shown,%toplevel);
9908: $roles{'0'} = &Apache::lonnet::plaintext('dc');
9909:
9910: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
9911: if ($domconfig{'selfenrollment'} eq '') {
9912: $domconfig{'selfenrollment'} = {};
9913: }
9914: }
9915: %toplevel = (
9916: admin => 'Configuration Rights',
9917: default => 'Default settings',
9918: validation => 'Validation of self-enrollment requests',
9919: );
9920: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
9921:
9922: if (ref($ordered{'admin'}) eq 'ARRAY') {
9923: foreach my $item (@{$ordered{'admin'}}) {
9924: foreach my $type (@types) {
9925: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
9926: $selfenrollhash{'admin'}{$type}{$item} = 1;
9927: } else {
9928: $selfenrollhash{'admin'}{$type}{$item} = 0;
9929: }
9930: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
9931: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
9932: if ($selfenrollhash{'admin'}{$type}{$item} ne
9933: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
9934: push(@{$changes{'admin'}{$type}},$item);
9935: }
9936: } else {
9937: if (!$selfenrollhash{'admin'}{$type}{$item}) {
9938: push(@{$changes{'admin'}{$type}},$item);
9939: }
9940: }
9941: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
9942: push(@{$changes{'admin'}{$type}},$item);
9943: }
9944: }
9945: }
9946: }
9947:
9948: foreach my $item (@{$ordered{'default'}}) {
9949: foreach my $type (@types) {
9950: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
9951: if ($item eq 'types') {
9952: unless (($value eq 'all') || ($value eq 'dom')) {
9953: $value = '';
9954: }
9955: } elsif ($item eq 'registered') {
9956: unless ($value eq '1') {
9957: $value = 0;
9958: }
9959: } elsif ($item eq 'approval') {
9960: unless ($value =~ /^[012]$/) {
9961: $value = 0;
9962: }
9963: } else {
9964: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
9965: $value = 'none';
9966: }
9967: }
9968: $selfenrollhash{'default'}{$type}{$item} = $value;
9969: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
9970: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
9971: if ($selfenrollhash{'default'}{$type}{$item} ne
9972: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
9973: push(@{$changes{'default'}{$type}},$item);
9974: }
9975: } else {
9976: push(@{$changes{'default'}{$type}},$item);
9977: }
9978: } else {
9979: push(@{$changes{'default'}{$type}},$item);
9980: }
9981: if ($item eq 'limit') {
9982: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
9983: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
9984: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
9985: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
9986: }
9987: } else {
9988: $selfenrollhash{'default'}{$type}{'cap'} = '';
9989: }
9990: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
9991: if ($selfenrollhash{'default'}{$type}{'cap'} ne
9992: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
9993: push(@{$changes{'default'}{$type}},'cap');
9994: }
9995: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
9996: push(@{$changes{'default'}{$type}},'cap');
9997: }
9998: }
9999: }
10000: }
10001:
10002: foreach my $item (@{$itemsref}) {
10003: if ($item eq 'fields') {
10004: my @changed;
10005: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
10006: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
10007: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
10008: }
10009: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10010: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
10011: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
10012: $domconfig{'selfenrollment'}{'validation'}{$item});
10013: } else {
10014: @changed = @{$selfenrollhash{'validation'}{$item}};
10015: }
10016: } else {
10017: @changed = @{$selfenrollhash{'validation'}{$item}};
10018: }
10019: if (@changed) {
10020: if ($selfenrollhash{'validation'}{$item}) {
10021: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
10022: } else {
10023: $changes{'validation'}{$item} = &mt('None');
10024: }
10025: }
10026: } else {
10027: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
10028: if ($item eq 'markup') {
10029: if ($env{'form.selfenroll_validation_'.$item}) {
10030: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10031: }
10032: }
10033: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10034: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
10035: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
10036: }
10037: }
10038: }
10039: }
10040:
10041: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
10042: $dom);
10043: if ($putresult eq 'ok') {
10044: if (keys(%changes) > 0) {
10045: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10046: $resulttext = &mt('Changes made:').'<ul>';
10047: foreach my $key ('admin','default','validation') {
10048: if (ref($changes{$key}) eq 'HASH') {
10049: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
10050: if ($key eq 'validation') {
10051: foreach my $item (@{$itemsref}) {
10052: if (exists($changes{$key}{$item})) {
10053: if ($item eq 'markup') {
10054: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10055: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
10056: } else {
10057: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10058: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
10059: }
10060: }
10061: }
10062: } else {
10063: foreach my $type (@types) {
10064: if ($type eq 'community') {
10065: $roles{'1'} = &mt('Community personnel');
10066: } else {
10067: $roles{'1'} = &mt('Course personnel');
10068: }
10069: if (ref($changes{$key}{$type}) eq 'ARRAY') {
10070: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10071: if ($key eq 'admin') {
10072: my @mgrdc = ();
10073: if (ref($ordered{$key}) eq 'ARRAY') {
10074: foreach my $item (@{$ordered{'admin'}}) {
10075: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10076: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
10077: push(@mgrdc,$item);
10078: }
10079: }
10080: }
10081: if (@mgrdc) {
10082: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
10083: } else {
10084: delete($domdefaults{$type.'selfenrolladmdc'});
10085: }
10086: }
10087: } else {
10088: if (ref($ordered{$key}) eq 'ARRAY') {
10089: foreach my $item (@{$ordered{$key}}) {
10090: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10091: $domdefaults{$type.'selfenroll'.$item} =
10092: $selfenrollhash{$key}{$type}{$item};
10093: }
10094: }
10095: }
10096: }
10097: }
10098: $resulttext .= '<li>'.$titles{$type}.'<ul>';
10099: foreach my $item (@{$ordered{$key}}) {
10100: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10101: $resulttext .= '<li>';
10102: if ($key eq 'admin') {
10103: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
10104: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
10105: } else {
10106: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
10107: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
10108: }
10109: $resulttext .= '</li>';
10110: }
10111: }
10112: $resulttext .= '</ul></li>';
10113: }
10114: }
10115: $resulttext .= '</ul></li>';
10116: }
10117: }
10118: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
10119: my $cachetime = 24*60*60;
10120: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10121: if (ref($lastactref) eq 'HASH') {
10122: $lastactref->{'domdefaults'} = 1;
10123: }
10124: }
10125: }
10126: $resulttext .= '</ul>';
10127: } else {
10128: $resulttext = &mt('No changes made to self-enrollment settings');
10129: }
10130: } else {
10131: $resulttext = '<span class="LC_error">'.
10132: &mt('An error occurred: [_1]',$putresult).'</span>';
10133: }
10134: return $resulttext;
10135: }
10136:
10137: sub modify_usersessions {
10138: my ($dom,$lastactref,%domconfig) = @_;
10139: my @hostingtypes = ('version','excludedomain','includedomain');
10140: my @offloadtypes = ('primary','default');
10141: my %types = (
10142: remote => \@hostingtypes,
10143: hosted => \@hostingtypes,
10144: spares => \@offloadtypes,
10145: );
10146: my @prefixes = ('remote','hosted','spares');
10147: my @lcversions = &Apache::lonnet::all_loncaparevs();
10148: my (%by_ip,%by_location,@intdoms);
10149: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
10150: my @locations = sort(keys(%by_location));
10151: my (%defaultshash,%changes);
10152: foreach my $prefix (@prefixes) {
10153: $defaultshash{'usersessions'}{$prefix} = {};
10154: }
10155: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10156: my $resulttext;
10157: my %iphost = &Apache::lonnet::get_iphost();
10158: foreach my $prefix (@prefixes) {
10159: next if ($prefix eq 'spares');
10160: foreach my $type (@{$types{$prefix}}) {
10161: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
10162: if ($type eq 'version') {
10163: my $value = $env{'form.'.$prefix.'_'.$type};
10164: my $okvalue;
10165: if ($value ne '') {
10166: if (grep(/^\Q$value\E$/,@lcversions)) {
10167: $okvalue = $value;
10168: }
10169: }
10170: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10171: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10172: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
10173: if ($inuse == 0) {
10174: $changes{$prefix}{$type} = 1;
10175: } else {
10176: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
10177: $changes{$prefix}{$type} = 1;
10178: }
10179: if ($okvalue ne '') {
10180: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10181: }
10182: }
10183: } else {
10184: if (($inuse == 1) && ($okvalue ne '')) {
10185: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10186: $changes{$prefix}{$type} = 1;
10187: }
10188: }
10189: } else {
10190: if (($inuse == 1) && ($okvalue ne '')) {
10191: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10192: $changes{$prefix}{$type} = 1;
10193: }
10194: }
10195: } else {
10196: if (($inuse == 1) && ($okvalue ne '')) {
10197: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10198: $changes{$prefix}{$type} = 1;
10199: }
10200: }
10201: } else {
10202: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
10203: my @okvals;
10204: foreach my $val (@vals) {
10205: if ($val =~ /:/) {
10206: my @items = split(/:/,$val);
10207: foreach my $item (@items) {
10208: if (ref($by_location{$item}) eq 'ARRAY') {
10209: push(@okvals,$item);
10210: }
10211: }
10212: } else {
10213: if (ref($by_location{$val}) eq 'ARRAY') {
10214: push(@okvals,$val);
10215: }
10216: }
10217: }
10218: @okvals = sort(@okvals);
10219: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10220: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10221: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10222: if ($inuse == 0) {
10223: $changes{$prefix}{$type} = 1;
10224: } else {
10225: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10226: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
10227: if (@changed > 0) {
10228: $changes{$prefix}{$type} = 1;
10229: }
10230: }
10231: } else {
10232: if ($inuse == 1) {
10233: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10234: $changes{$prefix}{$type} = 1;
10235: }
10236: }
10237: } else {
10238: if ($inuse == 1) {
10239: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10240: $changes{$prefix}{$type} = 1;
10241: }
10242: }
10243: } else {
10244: if ($inuse == 1) {
10245: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10246: $changes{$prefix}{$type} = 1;
10247: }
10248: }
10249: }
10250: }
10251: }
10252:
10253: my @alldoms = &Apache::lonnet::all_domains();
10254: my %servers = &Apache::lonnet::internet_dom_servers($dom);
10255: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
10256: my $savespares;
10257:
10258: foreach my $lonhost (sort(keys(%servers))) {
10259: my $serverhomeID =
10260: &Apache::lonnet::get_server_homeID($servers{$lonhost});
10261: my $serverhostname = &Apache::lonnet::hostname($lonhost);
10262: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
10263: my %spareschg;
10264: foreach my $type (@{$types{'spares'}}) {
10265: my @okspares;
10266: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
10267: foreach my $server (@checked) {
10268: if (&Apache::lonnet::hostname($server) ne '') {
10269: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
10270: unless (grep(/^\Q$server\E$/,@okspares)) {
10271: push(@okspares,$server);
10272: }
10273: }
10274: }
10275: }
10276: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
10277: my $newspare;
10278: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
10279: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
10280: $newspare = $new;
10281: }
10282: }
10283: my @spares;
10284: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
10285: @spares = sort(@okspares,$newspare);
10286: } else {
10287: @spares = sort(@okspares);
10288: }
10289: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
10290: if (ref($spareid{$lonhost}) eq 'HASH') {
10291: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
10292: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
10293: if (@diffs > 0) {
10294: $spareschg{$type} = 1;
10295: }
10296: }
10297: }
10298: }
10299: if (keys(%spareschg) > 0) {
10300: $changes{'spares'}{$lonhost} = \%spareschg;
10301: }
10302: }
10303:
10304: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10305: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
10306: if (ref($changes{'spares'}) eq 'HASH') {
10307: if (keys(%{$changes{'spares'}}) > 0) {
10308: $savespares = 1;
10309: }
10310: }
10311: } else {
10312: $savespares = 1;
10313: }
10314: }
10315:
10316: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
10317: if ((keys(%changes) > 0) || ($savespares)) {
10318: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10319: $dom);
10320: if ($putresult eq 'ok') {
10321: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10322: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
10323: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
10324: }
10325: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
10326: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
10327: }
10328: }
10329: my $cachetime = 24*60*60;
10330: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10331: if (ref($lastactref) eq 'HASH') {
10332: $lastactref->{'domdefaults'} = 1;
10333: }
10334: if (keys(%changes) > 0) {
10335: my %lt = &usersession_titles();
10336: $resulttext = &mt('Changes made:').'<ul>';
10337: foreach my $prefix (@prefixes) {
10338: if (ref($changes{$prefix}) eq 'HASH') {
10339: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
10340: if ($prefix eq 'spares') {
10341: if (ref($changes{$prefix}) eq 'HASH') {
10342: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
10343: $resulttext .= '<li><b>'.$lonhost.'</b> ';
10344: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
10345: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
10346: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
10347: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
10348: foreach my $type (@{$types{$prefix}}) {
10349: if ($changes{$prefix}{$lonhost}{$type}) {
10350: my $offloadto = &mt('None');
10351: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
10352: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
10353: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
10354: }
10355: }
10356: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
10357: }
10358: }
10359: }
10360: $resulttext .= '</li>';
10361: }
10362: }
10363: } else {
10364: foreach my $type (@{$types{$prefix}}) {
10365: if (defined($changes{$prefix}{$type})) {
10366: my $newvalue;
10367: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10368: if (ref($defaultshash{'usersessions'}{$prefix})) {
10369: if ($type eq 'version') {
10370: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
10371: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10372: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
10373: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
10374: }
10375: }
10376: }
10377: }
10378: if ($newvalue eq '') {
10379: if ($type eq 'version') {
10380: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
10381: } else {
10382: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
10383: }
10384: } else {
10385: if ($type eq 'version') {
10386: $newvalue .= ' '.&mt('(or later)');
10387: }
10388: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
10389: }
10390: }
10391: }
10392: }
10393: $resulttext .= '</ul>';
10394: }
10395: }
10396: $resulttext .= '</ul>';
10397: } else {
10398: $resulttext = $nochgmsg;
10399: }
10400: } else {
10401: $resulttext = '<span class="LC_error">'.
10402: &mt('An error occurred: [_1]',$putresult).'</span>';
10403: }
10404: } else {
10405: $resulttext = $nochgmsg;
10406: }
10407: return $resulttext;
10408: }
10409:
10410: sub modify_loadbalancing {
10411: my ($dom,%domconfig) = @_;
10412: my $primary_id = &Apache::lonnet::domain($dom,'primary');
10413: my $intdom = &Apache::lonnet::internet_dom($primary_id);
10414: my ($othertitle,$usertypes,$types) =
10415: &Apache::loncommon::sorted_inst_types($dom);
10416: my %servers = &Apache::lonnet::internet_dom_servers($dom);
10417: my @sparestypes = ('primary','default');
10418: my %typetitles = &sparestype_titles();
10419: my $resulttext;
10420: my (%currbalancer,%currtargets,%currrules,%existing);
10421: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
10422: %existing = %{$domconfig{'loadbalancing'}};
10423: }
10424: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
10425: \%currtargets,\%currrules);
10426: my ($saveloadbalancing,%defaultshash,%changes);
10427: my ($alltypes,$othertypes,$titles) =
10428: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
10429: my %ruletitles = &offloadtype_text();
10430: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
10431: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
10432: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
10433: if ($balancer eq '') {
10434: next;
10435: }
10436: if (!exists($servers{$balancer})) {
10437: if (exists($currbalancer{$balancer})) {
10438: push(@{$changes{'delete'}},$balancer);
10439: }
10440: next;
10441: }
10442: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
10443: push(@{$changes{'delete'}},$balancer);
10444: next;
10445: }
10446: if (!exists($currbalancer{$balancer})) {
10447: push(@{$changes{'add'}},$balancer);
10448: }
10449: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
10450: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
10451: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
10452: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
10453: $saveloadbalancing = 1;
10454: }
10455: foreach my $sparetype (@sparestypes) {
10456: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
10457: my @offloadto;
10458: foreach my $target (@targets) {
10459: if (($servers{$target}) && ($target ne $balancer)) {
10460: if ($sparetype eq 'default') {
10461: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
10462: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
10463: }
10464: }
10465: unless(grep(/^\Q$target\E$/,@offloadto)) {
10466: push(@offloadto,$target);
10467: }
10468: }
10469: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
10470: }
10471: }
10472: if (ref($currtargets{$balancer}) eq 'HASH') {
10473: foreach my $sparetype (@sparestypes) {
10474: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
10475: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
10476: if (@targetdiffs > 0) {
10477: $changes{'curr'}{$balancer}{'targets'} = 1;
10478: }
10479: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10480: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10481: $changes{'curr'}{$balancer}{'targets'} = 1;
10482: }
10483: }
10484: }
10485: } else {
10486: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
10487: foreach my $sparetype (@sparestypes) {
10488: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10489: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10490: $changes{'curr'}{$balancer}{'targets'} = 1;
10491: }
10492: }
10493: }
10494: }
10495: }
10496: my $ishomedom;
10497: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
10498: $ishomedom = 1;
10499: }
10500: if (ref($alltypes) eq 'ARRAY') {
10501: foreach my $type (@{$alltypes}) {
10502: my $rule;
10503: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
10504: (!$ishomedom)) {
10505: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
10506: }
10507: if ($rule eq 'specific') {
10508: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
10509: }
10510: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
10511: if (ref($currrules{$balancer}) eq 'HASH') {
10512: if ($rule ne $currrules{$balancer}{$type}) {
10513: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
10514: }
10515: } elsif ($rule ne '') {
10516: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
10517: }
10518: }
10519: }
10520: }
10521: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
10522: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
10523: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
10524: $defaultshash{'loadbalancing'} = {};
10525: }
10526: my $putresult = &Apache::lonnet::put_dom('configuration',
10527: \%defaultshash,$dom);
10528: if ($putresult eq 'ok') {
10529: if (keys(%changes) > 0) {
10530: if (ref($changes{'delete'}) eq 'ARRAY') {
10531: foreach my $balancer (sort(@{$changes{'delete'}})) {
10532: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
10533: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
10534: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
10535: }
10536: }
10537: if (ref($changes{'add'}) eq 'ARRAY') {
10538: foreach my $balancer (sort(@{$changes{'add'}})) {
10539: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
10540: }
10541: }
10542: if (ref($changes{'curr'}) eq 'HASH') {
10543: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
10544: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
10545: if ($changes{'curr'}{$balancer}{'targets'}) {
10546: my %offloadstr;
10547: foreach my $sparetype (@sparestypes) {
10548: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10549: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10550: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
10551: }
10552: }
10553: }
10554: if (keys(%offloadstr) == 0) {
10555: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
10556: } else {
10557: my $showoffload;
10558: foreach my $sparetype (@sparestypes) {
10559: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
10560: if (defined($offloadstr{$sparetype})) {
10561: $showoffload .= $offloadstr{$sparetype};
10562: } else {
10563: $showoffload .= &mt('None');
10564: }
10565: $showoffload .= (' 'x3);
10566: }
10567: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
10568: }
10569: }
10570: }
10571: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
10572: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
10573: foreach my $type (@{$alltypes}) {
10574: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
10575: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
10576: my $balancetext;
10577: if ($rule eq '') {
10578: $balancetext = $ruletitles{'default'};
10579: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
10580: ($rule eq 'balancer') || ($rule eq 'offloadedto')) {
10581: $balancetext = $ruletitles{$rule};
10582: } else {
10583: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
10584: }
10585: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
10586: }
10587: }
10588: }
10589: }
10590: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
10591: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
10592: }
10593: }
10594: if ($resulttext ne '') {
10595: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
10596: } else {
10597: $resulttext = $nochgmsg;
10598: }
10599: } else {
10600: $resulttext = $nochgmsg;
10601: }
10602: } else {
10603: $resulttext = '<span class="LC_error">'.
10604: &mt('An error occurred: [_1]',$putresult).'</span>';
10605: }
10606: } else {
10607: $resulttext = $nochgmsg;
10608: }
10609: return $resulttext;
10610: }
10611:
10612: sub recurse_check {
10613: my ($chkcats,$categories,$depth,$name) = @_;
10614: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
10615: my $chg = 0;
10616: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
10617: my $category = $chkcats->[$depth]{$name}[$j];
10618: my $item;
10619: if ($category eq '') {
10620: $chg ++;
10621: } else {
10622: my $deeper = $depth + 1;
10623: $item = &escape($category).':'.&escape($name).':'.$depth;
10624: if ($chg) {
10625: $categories->{$item} -= $chg;
10626: }
10627: &recurse_check($chkcats,$categories,$deeper,$category);
10628: $deeper --;
10629: }
10630: }
10631: }
10632: return;
10633: }
10634:
10635: sub recurse_cat_deletes {
10636: my ($item,$coursecategories,$deletions) = @_;
10637: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
10638: my $subdepth = $depth + 1;
10639: if (ref($coursecategories) eq 'HASH') {
10640: foreach my $subitem (keys(%{$coursecategories})) {
10641: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
10642: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
10643: delete($coursecategories->{$subitem});
10644: $deletions->{$subitem} = 1;
10645: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
10646: }
10647: }
10648: }
10649: return;
10650: }
10651:
10652: sub get_active_dcs {
10653: my ($dom) = @_;
10654: my $now = time;
10655: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
10656: my %domcoords;
10657: my $numdcs = 0;
10658: foreach my $server (keys(%dompersonnel)) {
10659: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
10660: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
10661: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
10662: }
10663: }
10664: return %domcoords;
10665: }
10666:
10667: sub active_dc_picker {
10668: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
10669: my %domcoords = &get_active_dcs($dom);
10670: my @domcoord = keys(%domcoords);
10671: if (keys(%currhash)) {
10672: foreach my $dc (keys(%currhash)) {
10673: unless (exists($domcoords{$dc})) {
10674: push(@domcoord,$dc);
10675: }
10676: }
10677: }
10678: @domcoord = sort(@domcoord);
10679: my $numdcs = scalar(@domcoord);
10680: my $rows = 0;
10681: my $table;
10682: if ($numdcs > 1) {
10683: $table = '<table>';
10684: for (my $i=0; $i<@domcoord; $i++) {
10685: my $rem = $i%($numinrow);
10686: if ($rem == 0) {
10687: if ($i > 0) {
10688: $table .= '</tr>';
10689: }
10690: $table .= '<tr>';
10691: $rows ++;
10692: }
10693: my $check = '';
10694: if ($inputtype eq 'radio') {
10695: if (keys(%currhash) == 0) {
10696: if (!$i) {
10697: $check = ' checked="checked"';
10698: }
10699: } elsif (exists($currhash{$domcoord[$i]})) {
10700: $check = ' checked="checked"';
10701: }
10702: } else {
10703: if (exists($currhash{$domcoord[$i]})) {
10704: $check = ' checked="checked"';
10705: }
10706: }
10707: if ($i == @domcoord - 1) {
10708: my $colsleft = $numinrow - $rem;
10709: if ($colsleft > 1) {
10710: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
10711: } else {
10712: $table .= '<td class="LC_left_item">';
10713: }
10714: } else {
10715: $table .= '<td class="LC_left_item">';
10716: }
10717: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
10718: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
10719: $table .= '<span class="LC_nobreak"><label>'.
10720: '<input type="'.$inputtype.'" name="'.$name.'"'.
10721: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
10722: if ($user ne $dcname.':'.$dcdom) {
10723: $table .= ' ('.$dcname.':'.$dcdom.')';
10724: }
10725: $table .= '</label></span></td>';
10726: }
10727: $table .= '</tr></table>';
10728: } elsif ($numdcs == 1) {
10729: my ($dcname,$dcdom) = split(':',$domcoord[0]);
10730: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
10731: if ($inputtype eq 'radio') {
10732: $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
10733: if ($user ne $dcname.':'.$dcdom) {
10734: $table .= ' ('.$dcname.':'.$dcdom.')';
10735: }
10736: } else {
10737: my $check;
10738: if (exists($currhash{$domcoord[0]})) {
10739: $check = ' checked="checked"';
10740: }
10741: $table .= '<span class="LC_nobreak"><label>'.
10742: '<input type="checkbox" name="'.$name.'" '.
10743: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
10744: if ($user ne $dcname.':'.$dcdom) {
10745: $table .= ' ('.$dcname.':'.$dcdom.')';
10746: }
10747: $table .= '</label></span>';
10748: $rows ++;
10749: }
10750: }
10751: return ($numdcs,$table,$rows);
10752: }
10753:
10754: sub usersession_titles {
10755: return &Apache::lonlocal::texthash(
10756: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
10757: remote => 'Hosting of sessions for users in this domain on servers in other domains',
10758: spares => 'Servers offloaded to, when busy',
10759: version => 'LON-CAPA version requirement',
10760: excludedomain => 'Allow all, but exclude specific domains',
10761: includedomain => 'Deny all, but include specific domains',
10762: primary => 'Primary (checked first)',
10763: default => 'Default',
10764: );
10765: }
10766:
10767: sub id_for_thisdom {
10768: my (%servers) = @_;
10769: my %altids;
10770: foreach my $server (keys(%servers)) {
10771: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
10772: if ($serverhome ne $server) {
10773: $altids{$serverhome} = $server;
10774: }
10775: }
10776: return %altids;
10777: }
10778:
10779: sub count_servers {
10780: my ($currbalancer,%servers) = @_;
10781: my (@spares,$numspares);
10782: foreach my $lonhost (sort(keys(%servers))) {
10783: next if ($currbalancer eq $lonhost);
10784: push(@spares,$lonhost);
10785: }
10786: if ($currbalancer) {
10787: $numspares = scalar(@spares);
10788: } else {
10789: $numspares = scalar(@spares) - 1;
10790: }
10791: return ($numspares,@spares);
10792: }
10793:
10794: sub lonbalance_targets_js {
10795: my ($dom,$types,$servers,$settings) = @_;
10796: my $select = &mt('Select');
10797: my ($alltargets,$allishome,$allinsttypes,@alltypes);
10798: if (ref($servers) eq 'HASH') {
10799: $alltargets = join("','",sort(keys(%{$servers})));
10800: my @homedoms;
10801: foreach my $server (sort(keys(%{$servers}))) {
10802: if (&Apache::lonnet::host_domain($server) eq $dom) {
10803: push(@homedoms,'1');
10804: } else {
10805: push(@homedoms,'0');
10806: }
10807: }
10808: $allishome = join("','",@homedoms);
10809: }
10810: if (ref($types) eq 'ARRAY') {
10811: if (@{$types} > 0) {
10812: @alltypes = @{$types};
10813: }
10814: }
10815: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
10816: $allinsttypes = join("','",@alltypes);
10817: my (%currbalancer,%currtargets,%currrules,%existing);
10818: if (ref($settings) eq 'HASH') {
10819: %existing = %{$settings};
10820: }
10821: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
10822: \%currtargets,\%currrules);
10823: my $balancers = join("','",sort(keys(%currbalancer)));
10824: return <<"END";
10825:
10826: <script type="text/javascript">
10827: // <![CDATA[
10828:
10829: currBalancers = new Array('$balancers');
10830:
10831: function toggleTargets(balnum) {
10832: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
10833: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
10834: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
10835: var prevbalancer = prevhostitem.value;
10836: var baltotal = document.getElementById('loadbalancing_total').value;
10837: prevhostitem.value = balancer;
10838: if (prevbalancer != '') {
10839: var prevIdx = currBalancers.indexOf(prevbalancer);
10840: if (prevIdx != -1) {
10841: currBalancers.splice(prevIdx,1);
10842: }
10843: }
10844: if (balancer == '') {
10845: hideSpares(balnum);
10846: } else {
10847: var currIdx = currBalancers.indexOf(balancer);
10848: if (currIdx == -1) {
10849: currBalancers.push(balancer);
10850: }
10851: var homedoms = new Array('$allishome');
10852: var ishomedom = homedoms[lonhostitem.selectedIndex];
10853: showSpares(balancer,ishomedom,balnum);
10854: }
10855: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
10856: return;
10857: }
10858:
10859: function showSpares(balancer,ishomedom,balnum) {
10860: var alltargets = new Array('$alltargets');
10861: var insttypes = new Array('$allinsttypes');
10862: var offloadtypes = new Array('primary','default');
10863:
10864: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
10865: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
10866:
10867: for (var i=0; i<offloadtypes.length; i++) {
10868: var count = 0;
10869: for (var j=0; j<alltargets.length; j++) {
10870: if (alltargets[j] != balancer) {
10871: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
10872: item.value = alltargets[j];
10873: item.style.textAlign='left';
10874: item.style.textFace='normal';
10875: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
10876: if (currBalancers.indexOf(alltargets[j]) == -1) {
10877: item.disabled = '';
10878: } else {
10879: item.disabled = 'disabled';
10880: item.checked = false;
10881: }
10882: count ++;
10883: }
10884: }
10885: }
10886: for (var k=0; k<insttypes.length; k++) {
10887: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
10888: if (ishomedom == 1) {
10889: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
10890: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
10891: } else {
10892: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
10893: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
10894: }
10895: } else {
10896: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
10897: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
10898: }
10899: if ((insttypes[k] != '_LC_external') &&
10900: ((insttypes[k] != '_LC_internetdom') ||
10901: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
10902: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
10903: item.options.length = 0;
10904: item.options[0] = new Option("","",true,true);
10905: var idx = 0;
10906: for (var m=0; m<alltargets.length; m++) {
10907: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
10908: idx ++;
10909: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
10910: }
10911: }
10912: }
10913: }
10914: return;
10915: }
10916:
10917: function hideSpares(balnum) {
10918: var alltargets = new Array('$alltargets');
10919: var insttypes = new Array('$allinsttypes');
10920: var offloadtypes = new Array('primary','default');
10921:
10922: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
10923: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
10924:
10925: var total = alltargets.length - 1;
10926: for (var i=0; i<offloadtypes; i++) {
10927: for (var j=0; j<total; j++) {
10928: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
10929: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
10930: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
10931: }
10932: }
10933: for (var k=0; k<insttypes.length; k++) {
10934: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
10935: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
10936: if (insttypes[k] != '_LC_external') {
10937: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
10938: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
10939: }
10940: }
10941: return;
10942: }
10943:
10944: function checkOffloads(item,balnum,type) {
10945: var alltargets = new Array('$alltargets');
10946: var offloadtypes = new Array('primary','default');
10947: if (item.checked) {
10948: var total = alltargets.length - 1;
10949: var other;
10950: if (type == offloadtypes[0]) {
10951: other = offloadtypes[1];
10952: } else {
10953: other = offloadtypes[0];
10954: }
10955: for (var i=0; i<total; i++) {
10956: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
10957: if (server == item.value) {
10958: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
10959: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
10960: }
10961: }
10962: }
10963: }
10964: return;
10965: }
10966:
10967: function singleServerToggle(balnum,type) {
10968: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
10969: if (offloadtoSelIdx == 0) {
10970: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
10971: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
10972:
10973: } else {
10974: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
10975: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
10976: }
10977: return;
10978: }
10979:
10980: function balanceruleChange(formname,balnum,type) {
10981: if (type == '_LC_external') {
10982: return;
10983: }
10984: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
10985: for (var i=0; i<typesRules.length; i++) {
10986: if (formname.elements[typesRules[i]].checked) {
10987: if (formname.elements[typesRules[i]].value != 'specific') {
10988: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
10989: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
10990: } else {
10991: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
10992: }
10993: }
10994: }
10995: return;
10996: }
10997:
10998: function balancerDeleteChange(balnum) {
10999: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11000: var baltotal = document.getElementById('loadbalancing_total').value;
11001: var addtarget;
11002: var removetarget;
11003: var action = 'delete';
11004: if (document.getElementById('loadbalancing_delete_'+balnum)) {
11005: var lonhost = hostitem.value;
11006: var currIdx = currBalancers.indexOf(lonhost);
11007: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
11008: if (currIdx != -1) {
11009: currBalancers.splice(currIdx,1);
11010: }
11011: addtarget = lonhost;
11012: } else {
11013: if (currIdx == -1) {
11014: currBalancers.push(lonhost);
11015: }
11016: removetarget = lonhost;
11017: action = 'undelete';
11018: }
11019: balancerChange(balnum,baltotal,action,addtarget,removetarget);
11020: }
11021: return;
11022: }
11023:
11024: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
11025: if (baltotal > 1) {
11026: var offloadtypes = new Array('primary','default');
11027: var alltargets = new Array('$alltargets');
11028: var insttypes = new Array('$allinsttypes');
11029: for (var i=0; i<baltotal; i++) {
11030: if (i != balnum) {
11031: for (var j=0; j<offloadtypes.length; j++) {
11032: var total = alltargets.length - 1;
11033: for (var k=0; k<total; k++) {
11034: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
11035: var server = serveritem.value;
11036: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11037: if (server == addtarget) {
11038: serveritem.disabled = '';
11039: }
11040: }
11041: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11042: if (server == removetarget) {
11043: serveritem.disabled = 'disabled';
11044: serveritem.checked = false;
11045: }
11046: }
11047: }
11048: }
11049: for (var j=0; j<insttypes.length; j++) {
11050: if (insttypes[j] != '_LC_external') {
11051: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
11052: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
11053: var currSel = singleserver.selectedIndex;
11054: var currVal = singleserver.options[currSel].value;
11055: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11056: var numoptions = singleserver.options.length;
11057: var needsnew = 1;
11058: for (var k=0; k<numoptions; k++) {
11059: if (singleserver.options[k] == addtarget) {
11060: needsnew = 0;
11061: break;
11062: }
11063: }
11064: if (needsnew == 1) {
11065: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
11066: }
11067: }
11068: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11069: singleserver.options.length = 0;
11070: if ((currVal) && (currVal != removetarget)) {
11071: singleserver.options[0] = new Option("","",false,false);
11072: } else {
11073: singleserver.options[0] = new Option("","",true,true);
11074: }
11075: var idx = 0;
11076: for (var m=0; m<alltargets.length; m++) {
11077: if (currBalancers.indexOf(alltargets[m]) == -1) {
11078: idx ++;
11079: if (currVal == alltargets[m]) {
11080: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
11081: } else {
11082: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
11083: }
11084: }
11085: }
11086: }
11087: }
11088: }
11089: }
11090: }
11091: }
11092: }
11093: return;
11094: }
11095:
11096: // ]]>
11097: </script>
11098:
11099: END
11100: }
11101:
11102: sub new_spares_js {
11103: my @sparestypes = ('primary','default');
11104: my $types = join("','",@sparestypes);
11105: my $select = &mt('Select');
11106: return <<"END";
11107:
11108: <script type="text/javascript">
11109: // <![CDATA[
11110:
11111: function updateNewSpares(formname,lonhost) {
11112: var types = new Array('$types');
11113: var include = new Array();
11114: var exclude = new Array();
11115: for (var i=0; i<types.length; i++) {
11116: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
11117: for (var j=0; j<spareboxes.length; j++) {
11118: if (formname.elements[spareboxes[j]].checked) {
11119: exclude.push(formname.elements[spareboxes[j]].value);
11120: } else {
11121: include.push(formname.elements[spareboxes[j]].value);
11122: }
11123: }
11124: }
11125: for (var i=0; i<types.length; i++) {
11126: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
11127: var selIdx = newSpare.selectedIndex;
11128: var currnew = newSpare.options[selIdx].value;
11129: var okSpares = new Array();
11130: for (var j=0; j<newSpare.options.length; j++) {
11131: var possible = newSpare.options[j].value;
11132: if (possible != '') {
11133: if (exclude.indexOf(possible) == -1) {
11134: okSpares.push(possible);
11135: } else {
11136: if (currnew == possible) {
11137: selIdx = 0;
11138: }
11139: }
11140: }
11141: }
11142: for (var k=0; k<include.length; k++) {
11143: if (okSpares.indexOf(include[k]) == -1) {
11144: okSpares.push(include[k]);
11145: }
11146: }
11147: okSpares.sort();
11148: newSpare.options.length = 0;
11149: if (selIdx == 0) {
11150: newSpare.options[0] = new Option("$select","",true,true);
11151: } else {
11152: newSpare.options[0] = new Option("$select","",false,false);
11153: }
11154: for (var m=0; m<okSpares.length; m++) {
11155: var idx = m+1;
11156: var selThis = 0;
11157: if (selIdx != 0) {
11158: if (okSpares[m] == currnew) {
11159: selThis = 1;
11160: }
11161: }
11162: if (selThis == 1) {
11163: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
11164: } else {
11165: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
11166: }
11167: }
11168: }
11169: return;
11170: }
11171:
11172: function checkNewSpares(lonhost,type) {
11173: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
11174: var chosen = newSpare.options[newSpare.selectedIndex].value;
11175: if (chosen != '') {
11176: var othertype;
11177: var othernewSpare;
11178: if (type == 'primary') {
11179: othernewSpare = document.getElementById('newspare_default_'+lonhost);
11180: }
11181: if (type == 'default') {
11182: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
11183: }
11184: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
11185: othernewSpare.selectedIndex = 0;
11186: }
11187: }
11188: return;
11189: }
11190:
11191: // ]]>
11192: </script>
11193:
11194: END
11195:
11196: }
11197:
11198: sub common_domprefs_js {
11199: return <<"END";
11200:
11201: <script type="text/javascript">
11202: // <![CDATA[
11203:
11204: function getIndicesByName(formname,item) {
11205: var group = new Array();
11206: for (var i=0;i<formname.elements.length;i++) {
11207: if (formname.elements[i].name == item) {
11208: group.push(formname.elements[i].id);
11209: }
11210: }
11211: return group;
11212: }
11213:
11214: // ]]>
11215: </script>
11216:
11217: END
11218:
11219: }
11220:
11221: sub recaptcha_js {
11222: my %lt = &captcha_phrases();
11223: return <<"END";
11224:
11225: <script type="text/javascript">
11226: // <![CDATA[
11227:
11228: function updateCaptcha(caller,context) {
11229: var privitem;
11230: var pubitem;
11231: var privtext;
11232: var pubtext;
11233: if (document.getElementById(context+'_recaptchapub')) {
11234: pubitem = document.getElementById(context+'_recaptchapub');
11235: } else {
11236: return;
11237: }
11238: if (document.getElementById(context+'_recaptchapriv')) {
11239: privitem = document.getElementById(context+'_recaptchapriv');
11240: } else {
11241: return;
11242: }
11243: if (document.getElementById(context+'_recaptchapubtxt')) {
11244: pubtext = document.getElementById(context+'_recaptchapubtxt');
11245: } else {
11246: return;
11247: }
11248: if (document.getElementById(context+'_recaptchaprivtxt')) {
11249: privtext = document.getElementById(context+'_recaptchaprivtxt');
11250: } else {
11251: return;
11252: }
11253: if (caller.checked) {
11254: if (caller.value == 'recaptcha') {
11255: pubitem.type = 'text';
11256: privitem.type = 'text';
11257: pubitem.size = '40';
11258: privitem.size = '40';
11259: pubtext.innerHTML = "$lt{'pub'}";
11260: privtext.innerHTML = "$lt{'priv'}";
11261: } else {
11262: pubitem.type = 'hidden';
11263: privitem.type = 'hidden';
11264: pubtext.innerHTML = '';
11265: privtext.innerHTML = '';
11266: }
11267: }
11268: return;
11269: }
11270:
11271: // ]]>
11272: </script>
11273:
11274: END
11275:
11276: }
11277:
11278: sub toggle_display_js {
11279: return <<"END";
11280:
11281: <script type="text/javascript">
11282: // <![CDATA[
11283:
11284: function toggleDisplay(domForm,caller) {
11285: if (document.getElementById(caller)) {
11286: var divitem = document.getElementById(caller);
11287: var optionsElement = domForm.coursecredits;
11288: if (caller == 'emailoptions') {
11289: optionsElement = domForm.cancreate_email;
11290: }
11291: if (optionsElement.length) {
11292: var currval;
11293: for (var i=0; i<optionsElement.length; i++) {
11294: if (optionsElement[i].checked) {
11295: currval = optionsElement[i].value;
11296: }
11297: }
11298: if (currval == 1) {
11299: divitem.style.display = 'block';
11300: } else {
11301: divitem.style.display = 'none';
11302: }
11303: }
11304: }
11305: return;
11306: }
11307:
11308: // ]]>
11309: </script>
11310:
11311: END
11312:
11313: }
11314:
11315: sub captcha_phrases {
11316: return &Apache::lonlocal::texthash (
11317: priv => 'Private key',
11318: pub => 'Public key',
11319: original => 'original (CAPTCHA)',
11320: recaptcha => 'successor (ReCAPTCHA)',
11321: notused => 'unused',
11322: );
11323: }
11324:
11325: sub devalidate_remote_domconfs {
11326: my ($dom,$cachekeys) = @_;
11327: return unless (ref($cachekeys) eq 'HASH');
11328: my %servers = &Apache::lonnet::internet_dom_servers($dom);
11329: my %thismachine;
11330: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
11331: my @posscached = ('domainconfig','domdefaults');
11332: if (keys(%servers) > 1) {
11333: foreach my $server (keys(%servers)) {
11334: next if ($thismachine{$server});
11335: my @cached;
11336: foreach my $name (@posscached) {
11337: if ($cachekeys->{$name}) {
11338: push(@cached,&escape($name).':'.&escape($dom));
11339: }
11340: }
11341: if (@cached) {
11342: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
11343: }
11344: }
11345: }
11346: return;
11347: }
11348:
11349: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>