1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
4: # $Id: domainprefs.pm,v 1.246 2014/05/30 01:39:48 raeburn 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 => 'Available templates',
373: col2 => ''},
374: {col1 => 'Validation (not official courses)',
375: col2 => 'Value'},],
376: print => \&print_quotas,
377: modify => \&modify_quotas,
378: },
379: 'requestauthor' =>
380: {text => 'Request Authoring Space',
381: help => 'Domain_Configuration_Request_Author',
382: header => [{col1 => 'User affiliation',
383: col2 => 'Availability/Processing of requests',},
384: {col1 => 'Setting',
385: col2 => 'Value'}],
386: print => \&print_quotas,
387: modify => \&modify_quotas,
388: },
389: 'coursecategories' =>
390: { text => 'Cataloging of courses/communities',
391: help => 'Domain_Configuration_Cataloging_Courses',
392: header => [{col1 => 'Catalog type/availability',
393: col2 => '',},
394: {col1 => 'Category settings for standard catalog',
395: col2 => '',},
396: {col1 => 'Categories',
397: col2 => '',
398: }],
399: print => \&print_coursecategories,
400: modify => \&modify_coursecategories,
401: },
402: 'serverstatuses' =>
403: {text => 'Access to server status pages',
404: help => 'Domain_Configuration_Server_Status',
405: header => [{col1 => 'Status Page',
406: col2 => 'Other named users',
407: col3 => 'Specific IPs',
408: }],
409: print => \&print_serverstatuses,
410: modify => \&modify_serverstatuses,
411: },
412: 'helpsettings' =>
413: {text => 'Help page settings',
414: help => 'Domain_Configuration_Help_Settings',
415: header => [{col1 => 'Help Settings (logged-in users)',
416: col2 => 'Value'}],
417: print => \&print_helpsettings,
418: modify => \&modify_helpsettings,
419: },
420: 'coursedefaults' =>
421: {text => 'Course/Community defaults',
422: help => 'Domain_Configuration_Course_Defaults',
423: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
424: col2 => 'Value',},
425: {col1 => 'Defaults which can be overridden for each course by a DC',
426: col2 => 'Value',},],
427: print => \&print_coursedefaults,
428: modify => \&modify_coursedefaults,
429: },
430: 'selfenrollment' =>
431: {text => 'Self-enrollment in Course/Community',
432: help => 'Domain_Configuration_Selfenrollment',
433: header => [{col1 => 'Configuration Rights',
434: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
435: {col1 => 'Defaults',
436: col2 => 'Value'},
437: {col1 => 'Self-enrollment validation (optional)',
438: col2 => 'Value'},],
439: print => \&print_selfenrollment,
440: modify => \&modify_selfenrollment,
441: },
442: 'privacy' =>
443: {text => 'User Privacy',
444: help => 'Domain_Configuration_User_Privacy',
445: header => [{col1 => 'Setting',
446: col2 => 'Value',}],
447: print => \&print_privacy,
448: modify => \&modify_privacy,
449: },
450: 'usersessions' =>
451: {text => 'User session hosting/offloading',
452: help => 'Domain_Configuration_User_Sessions',
453: header => [{col1 => 'Domain server',
454: col2 => 'Servers to offload sessions to when busy'},
455: {col1 => 'Hosting of users from other domains',
456: col2 => 'Rules'},
457: {col1 => "Hosting domain's own users elsewhere",
458: col2 => 'Rules'}],
459: print => \&print_usersessions,
460: modify => \&modify_usersessions,
461: },
462: 'loadbalancing' =>
463: {text => 'Dedicated Load Balancer(s)',
464: help => 'Domain_Configuration_Load_Balancing',
465: header => [{col1 => 'Balancers',
466: col2 => 'Default destinations',
467: col3 => 'User affiliation',
468: col4 => 'Overrides'},
469: ],
470: print => \&print_loadbalancing,
471: modify => \&modify_loadbalancing,
472: },
473: );
474: if (keys(%servers) > 1) {
475: $prefs{'login'} = { text => 'Log-in page options',
476: help => 'Domain_Configuration_Login_Page',
477: header => [{col1 => 'Log-in Service',
478: col2 => 'Server Setting',},
479: {col1 => 'Log-in Page Items',
480: col2 => ''},
481: {col1 => 'Log-in Help',
482: col2 => 'Value'}],
483: print => \&print_login,
484: modify => \&modify_login,
485: };
486: }
487:
488: my @roles = ('student','coordinator','author','admin');
489: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
490: &Apache::lonhtmlcommon::add_breadcrumb
491: ({href=>"javascript:changePage(document.$phase,'pickactions')",
492: text=>"Settings to display/modify"});
493: my $confname = $dom.'-domainconfig';
494:
495: if ($phase eq 'process') {
496: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
497: \%prefs,\%domconfig,$confname,\@roles);
498: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
499: $r->rflush();
500: &devalidate_remote_domconfs($dom,$result);
501: }
502: } elsif ($phase eq 'display') {
503: my $js = &recaptcha_js().
504: &toggle_display_js();
505: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
506: my ($othertitle,$usertypes,$types) =
507: &Apache::loncommon::sorted_inst_types($dom);
508: $js .= &lonbalance_targets_js($dom,$types,\%servers,
509: $domconfig{'loadbalancing'}).
510: &new_spares_js().
511: &common_domprefs_js().
512: &Apache::loncommon::javascript_array_indexof();
513: }
514: if (grep(/^requestcourses$/,@actions)) {
515: my $javascript_validations;
516: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
517: $js .= <<END;
518: <script type="text/javascript">
519: $javascript_validations
520: </script>
521: $coursebrowserjs
522: END
523: }
524: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
525: } else {
526: # check if domconfig user exists for the domain.
527: my $servadm = $r->dir_config('lonAdmEMail');
528: my ($configuserok,$author_ok,$switchserver) =
529: &config_check($dom,$confname,$servadm);
530: unless ($configuserok eq 'ok') {
531: &Apache::lonconfigsettings::print_header($r,$phase,$context);
532: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
533: $confname).
534: '<br />'
535: );
536: if ($switchserver) {
537: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
538: '<br />'.
539: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
540: '<br />'.
541: &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).
542: '<br />'.
543: &mt('To do that now, use the following link: [_1]',$switchserver)
544: );
545: } else {
546: $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.').
547: '<br />'.
548: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
549: );
550: }
551: $r->print(&Apache::loncommon::end_page());
552: return OK;
553: }
554: if (keys(%domconfig) == 0) {
555: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
556: my @ids=&Apache::lonnet::current_machine_ids();
557: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
558: my %designhash = &Apache::loncommon::get_domainconf($dom);
559: my @loginimages = ('img','logo','domlogo','login');
560: my $custom_img_count = 0;
561: foreach my $img (@loginimages) {
562: if ($designhash{$dom.'.login.'.$img} ne '') {
563: $custom_img_count ++;
564: }
565: }
566: foreach my $role (@roles) {
567: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
568: $custom_img_count ++;
569: }
570: }
571: if ($custom_img_count > 0) {
572: &Apache::lonconfigsettings::print_header($r,$phase,$context);
573: my $switch_server = &check_switchserver($dom,$confname);
574: $r->print(
575: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
576: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
577: &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 />'.
578: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
579: if ($switch_server) {
580: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
581: }
582: $r->print(&Apache::loncommon::end_page());
583: return OK;
584: }
585: }
586: }
587: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
588: }
589: return OK;
590: }
591:
592: sub process_changes {
593: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
594: my %domconfig;
595: if (ref($values) eq 'HASH') {
596: %domconfig = %{$values};
597: }
598: my $output;
599: if ($action eq 'login') {
600: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
601: } elsif ($action eq 'rolecolors') {
602: $output = &modify_rolecolors($r,$dom,$confname,$roles,
603: $lastactref,%domconfig);
604: } elsif ($action eq 'quotas') {
605: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
606: } elsif ($action eq 'autoenroll') {
607: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
608: } elsif ($action eq 'autoupdate') {
609: $output = &modify_autoupdate($dom,%domconfig);
610: } elsif ($action eq 'autocreate') {
611: $output = &modify_autocreate($dom,%domconfig);
612: } elsif ($action eq 'directorysrch') {
613: $output = &modify_directorysrch($dom,%domconfig);
614: } elsif ($action eq 'usercreation') {
615: $output = &modify_usercreation($dom,%domconfig);
616: } elsif ($action eq 'selfcreation') {
617: $output = &modify_selfcreation($dom,%domconfig);
618: } elsif ($action eq 'usermodification') {
619: $output = &modify_usermodification($dom,%domconfig);
620: } elsif ($action eq 'contacts') {
621: $output = &modify_contacts($dom,$lastactref,%domconfig);
622: } elsif ($action eq 'defaults') {
623: $output = &modify_defaults($dom,$lastactref,%domconfig);
624: } elsif ($action eq 'scantron') {
625: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
626: } elsif ($action eq 'coursecategories') {
627: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
628: } elsif ($action eq 'serverstatuses') {
629: $output = &modify_serverstatuses($dom,%domconfig);
630: } elsif ($action eq 'requestcourses') {
631: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
632: } elsif ($action eq 'requestauthor') {
633: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
634: } elsif ($action eq 'helpsettings') {
635: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
636: } elsif ($action eq 'coursedefaults') {
637: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
638: } elsif ($action eq 'selfenrollment') {
639: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
640: } elsif ($action eq 'usersessions') {
641: $output = &modify_usersessions($dom,$lastactref,%domconfig);
642: } elsif ($action eq 'loadbalancing') {
643: $output = &modify_loadbalancing($dom,%domconfig);
644: }
645: return $output;
646: }
647:
648: sub print_config_box {
649: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
650: my $rowtotal = 0;
651: my $output;
652: if ($action eq 'coursecategories') {
653: $output = &coursecategories_javascript($settings);
654: } elsif ($action eq 'defaults') {
655: $output = &defaults_javascript($settings);
656: }
657: $output .=
658: '<table class="LC_nested_outer">
659: <tr>
660: <th align="left" valign="middle"><span class="LC_nobreak">'.
661: &mt($item->{text}).' '.
662: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
663: '</tr>';
664: $rowtotal ++;
665: my $numheaders = 1;
666: if (ref($item->{'header'}) eq 'ARRAY') {
667: $numheaders = scalar(@{$item->{'header'}});
668: }
669: if ($numheaders > 1) {
670: my $colspan = '';
671: my $rightcolspan = '';
672: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
673: (($action eq 'login') && ($numheaders < 3))) {
674: $colspan = ' colspan="2"';
675: }
676: if ($action eq 'usersessions') {
677: $rightcolspan = ' colspan="3"';
678: }
679: $output .= '
680: <tr>
681: <td>
682: <table class="LC_nested">
683: <tr class="LC_info_row">
684: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
685: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
686: </tr>';
687: $rowtotal ++;
688: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
689: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
690: ($action eq 'selfenrollment') || ($action eq 'usersessions')) {
691: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
692: } elsif ($action eq 'coursecategories') {
693: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
694: } elsif ($action eq 'login') {
695: if ($numheaders == 3) {
696: $colspan = ' colspan="2"';
697: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
698: } else {
699: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
700: }
701: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
702: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
703: } elsif ($action eq 'rolecolors') {
704: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
705: }
706: $output .= '
707: </table>
708: </td>
709: </tr>
710: <tr>
711: <td>
712: <table class="LC_nested">
713: <tr class="LC_info_row">
714: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
715: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
716: </tr>';
717: $rowtotal ++;
718: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
719: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
720: ($action eq 'usersessions') || ($action eq 'coursecategories')) {
721: if ($action eq 'coursecategories') {
722: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
723: $colspan = ' colspan="2"';
724: } else {
725: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
726: }
727: $output .= '
728: </table>
729: </td>
730: </tr>
731: <tr>
732: <td>
733: <table class="LC_nested">
734: <tr class="LC_info_row">
735: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
736: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
737: </tr>'."\n";
738: if ($action eq 'coursecategories') {
739: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
740: } else {
741: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
742: }
743: $rowtotal ++;
744: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
745: ($action eq 'defaults')) {
746: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
747: } elsif ($action eq 'login') {
748: if ($numheaders == 3) {
749: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
750: </table>
751: </td>
752: </tr>
753: <tr>
754: <td>
755: <table class="LC_nested">
756: <tr class="LC_info_row">
757: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
758: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
759: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
760: $rowtotal ++;
761: } else {
762: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
763: }
764: } elsif ($action eq 'requestcourses') {
765: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal).
766: &print_studentcode($settings,\$rowtotal).'
767: </table>
768: </td>
769: </tr>
770: <tr>
771: <td>
772: <table class="LC_nested">
773: <tr class="LC_info_row">
774: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
775: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
776: &textbookcourses_javascript($settings).
777: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
778: </table>
779: </td>
780: </tr>
781: <tr>
782: <td>
783: <table class="LC_nested">
784: <tr class="LC_info_row">
785: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
786: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
787: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
788: </table>
789: </td>
790: </tr>
791: <tr>
792: <td>
793: <table class="LC_nested">
794: <tr class="LC_info_row">
795: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
796: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
797: </tr>'.
798: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
799: } elsif ($action eq 'requestauthor') {
800: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
801: } elsif ($action eq 'rolecolors') {
802: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
803: </table>
804: </td>
805: </tr>
806: <tr>
807: <td>
808: <table class="LC_nested">
809: <tr class="LC_info_row">
810: <td class="LC_left_item"'.$colspan.' valign="top">'.
811: &mt($item->{'header'}->[2]->{'col1'}).'</td>
812: <td class="LC_right_item" valign="top">'.
813: &mt($item->{'header'}->[2]->{'col2'}).'</td>
814: </tr>'.
815: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
816: </table>
817: </td>
818: </tr>
819: <tr>
820: <td>
821: <table class="LC_nested">
822: <tr class="LC_info_row">
823: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
824: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
825: </tr>'.
826: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
827: $rowtotal += 2;
828: }
829: } else {
830: $output .= '
831: <tr>
832: <td>
833: <table class="LC_nested">
834: <tr class="LC_info_row">';
835: if (($action eq 'login') || ($action eq 'directorysrch')) {
836: $output .= '
837: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
838: } elsif ($action eq 'serverstatuses') {
839: $output .= '
840: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
841: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
842:
843: } else {
844: $output .= '
845: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
846: }
847: if (defined($item->{'header'}->[0]->{'col3'})) {
848: $output .= '<td class="LC_left_item" valign="top">'.
849: &mt($item->{'header'}->[0]->{'col2'});
850: if ($action eq 'serverstatuses') {
851: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
852: }
853: } else {
854: $output .= '<td class="LC_right_item" valign="top">'.
855: &mt($item->{'header'}->[0]->{'col2'});
856: }
857: $output .= '</td>';
858: if ($item->{'header'}->[0]->{'col3'}) {
859: if (defined($item->{'header'}->[0]->{'col4'})) {
860: $output .= '<td class="LC_left_item" valign="top">'.
861: &mt($item->{'header'}->[0]->{'col3'});
862: } else {
863: $output .= '<td class="LC_right_item" valign="top">'.
864: &mt($item->{'header'}->[0]->{'col3'});
865: }
866: if ($action eq 'serverstatuses') {
867: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
868: }
869: $output .= '</td>';
870: }
871: if ($item->{'header'}->[0]->{'col4'}) {
872: $output .= '<td class="LC_right_item" valign="top">'.
873: &mt($item->{'header'}->[0]->{'col4'});
874: }
875: $output .= '</tr>';
876: $rowtotal ++;
877: if ($action eq 'quotas') {
878: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
879: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || ($action eq 'directorysrch') ||
880: ($action eq 'contacts') || ($action eq 'serverstatuses') || ($action eq 'loadbalancing')) {
881: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
882: } elsif ($action eq 'scantron') {
883: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
884: } elsif ($action eq 'helpsettings') {
885: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
886: }
887: }
888: $output .= '
889: </table>
890: </td>
891: </tr>
892: </table><br />';
893: return ($output,$rowtotal);
894: }
895:
896: sub print_login {
897: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
898: my ($css_class,$datatable);
899: my %choices = &login_choices();
900:
901: if ($caller eq 'service') {
902: my %servers = &Apache::lonnet::internet_dom_servers($dom);
903: my $choice = $choices{'disallowlogin'};
904: $css_class = ' class="LC_odd_row"';
905: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
906: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
907: '<th>'.$choices{'server'}.'</th>'.
908: '<th>'.$choices{'serverpath'}.'</th>'.
909: '<th>'.$choices{'custompath'}.'</th>'.
910: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
911: my %disallowed;
912: if (ref($settings) eq 'HASH') {
913: if (ref($settings->{'loginvia'}) eq 'HASH') {
914: %disallowed = %{$settings->{'loginvia'}};
915: }
916: }
917: foreach my $lonhost (sort(keys(%servers))) {
918: my $direct = 'selected="selected"';
919: if (ref($disallowed{$lonhost}) eq 'HASH') {
920: if ($disallowed{$lonhost}{'server'} ne '') {
921: $direct = '';
922: }
923: }
924: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
925: '<td><select name="'.$lonhost.'_server">'.
926: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
927: '</option>';
928: foreach my $hostid (sort(keys(%servers))) {
929: next if ($servers{$hostid} eq $servers{$lonhost});
930: my $selected = '';
931: if (ref($disallowed{$lonhost}) eq 'HASH') {
932: if ($hostid eq $disallowed{$lonhost}{'server'}) {
933: $selected = 'selected="selected"';
934: }
935: }
936: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
937: $servers{$hostid}.'</option>';
938: }
939: $datatable .= '</select></td>'.
940: '<td><select name="'.$lonhost.'_serverpath">';
941: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
942: my $pathname = $path;
943: if ($path eq 'custom') {
944: $pathname = &mt('Custom Path').' ->';
945: }
946: my $selected = '';
947: if (ref($disallowed{$lonhost}) eq 'HASH') {
948: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
949: $selected = 'selected="selected"';
950: }
951: } elsif ($path eq '') {
952: $selected = 'selected="selected"';
953: }
954: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
955: }
956: $datatable .= '</select></td>';
957: my ($custom,$exempt);
958: if (ref($disallowed{$lonhost}) eq 'HASH') {
959: $custom = $disallowed{$lonhost}{'custompath'};
960: $exempt = $disallowed{$lonhost}{'exempt'};
961: }
962: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
963: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
964: '</tr>';
965: }
966: $datatable .= '</table></td></tr>';
967: return $datatable;
968: } elsif ($caller eq 'page') {
969: my %defaultchecked = (
970: 'coursecatalog' => 'on',
971: 'helpdesk' => 'on',
972: 'adminmail' => 'off',
973: 'newuser' => 'off',
974: );
975: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
976: my (%checkedon,%checkedoff);
977: foreach my $item (@toggles) {
978: if ($defaultchecked{$item} eq 'on') {
979: $checkedon{$item} = ' checked="checked" ';
980: $checkedoff{$item} = ' ';
981: } elsif ($defaultchecked{$item} eq 'off') {
982: $checkedoff{$item} = ' checked="checked" ';
983: $checkedon{$item} = ' ';
984: }
985: }
986: my @images = ('img','logo','domlogo','login');
987: my @logintext = ('textcol','bgcol');
988: my @bgs = ('pgbg','mainbg','sidebg');
989: my @links = ('link','alink','vlink');
990: my %designhash = &Apache::loncommon::get_domainconf($dom);
991: my %defaultdesign = %Apache::loncommon::defaultdesign;
992: my (%is_custom,%designs);
993: my %defaults = (
994: font => $defaultdesign{'login.font'},
995: );
996: foreach my $item (@images) {
997: $defaults{$item} = $defaultdesign{'login.'.$item};
998: $defaults{'showlogo'}{$item} = 1;
999: }
1000: foreach my $item (@bgs) {
1001: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1002: }
1003: foreach my $item (@logintext) {
1004: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1005: }
1006: foreach my $item (@links) {
1007: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1008: }
1009: if (ref($settings) eq 'HASH') {
1010: foreach my $item (@toggles) {
1011: if ($settings->{$item} eq '1') {
1012: $checkedon{$item} = ' checked="checked" ';
1013: $checkedoff{$item} = ' ';
1014: } elsif ($settings->{$item} eq '0') {
1015: $checkedoff{$item} = ' checked="checked" ';
1016: $checkedon{$item} = ' ';
1017: }
1018: }
1019: foreach my $item (@images) {
1020: if (defined($settings->{$item})) {
1021: $designs{$item} = $settings->{$item};
1022: $is_custom{$item} = 1;
1023: }
1024: if (defined($settings->{'showlogo'}{$item})) {
1025: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1026: }
1027: }
1028: foreach my $item (@logintext) {
1029: if ($settings->{$item} ne '') {
1030: $designs{'logintext'}{$item} = $settings->{$item};
1031: $is_custom{$item} = 1;
1032: }
1033: }
1034: if ($settings->{'font'} ne '') {
1035: $designs{'font'} = $settings->{'font'};
1036: $is_custom{'font'} = 1;
1037: }
1038: foreach my $item (@bgs) {
1039: if ($settings->{$item} ne '') {
1040: $designs{'bgs'}{$item} = $settings->{$item};
1041: $is_custom{$item} = 1;
1042: }
1043: }
1044: foreach my $item (@links) {
1045: if ($settings->{$item} ne '') {
1046: $designs{'links'}{$item} = $settings->{$item};
1047: $is_custom{$item} = 1;
1048: }
1049: }
1050: } else {
1051: if ($designhash{$dom.'.login.font'} ne '') {
1052: $designs{'font'} = $designhash{$dom.'.login.font'};
1053: $is_custom{'font'} = 1;
1054: }
1055: foreach my $item (@images) {
1056: if ($designhash{$dom.'.login.'.$item} ne '') {
1057: $designs{$item} = $designhash{$dom.'.login.'.$item};
1058: $is_custom{$item} = 1;
1059: }
1060: }
1061: foreach my $item (@bgs) {
1062: if ($designhash{$dom.'.login.'.$item} ne '') {
1063: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1064: $is_custom{$item} = 1;
1065: }
1066: }
1067: foreach my $item (@links) {
1068: if ($designhash{$dom.'.login.'.$item} ne '') {
1069: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1070: $is_custom{$item} = 1;
1071: }
1072: }
1073: }
1074: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1075: logo => 'Institution Logo',
1076: domlogo => 'Domain Logo',
1077: login => 'Login box');
1078: my $itemcount = 1;
1079: foreach my $item (@toggles) {
1080: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1081: $datatable .=
1082: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1083: '</td><td>'.
1084: '<span class="LC_nobreak"><label><input type="radio" name="'.
1085: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1086: '</label> <label><input type="radio" name="'.$item.'"'.
1087: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1088: '</tr>';
1089: $itemcount ++;
1090: }
1091: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1092: $datatable .= '</tr></table></td></tr>';
1093: } elsif ($caller eq 'help') {
1094: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1095: my $switchserver = &check_switchserver($dom,$confname);
1096: my $itemcount = 1;
1097: $defaulturl = '/adm/loginproblems.html';
1098: $defaulttype = 'default';
1099: %lt = &Apache::lonlocal::texthash (
1100: del => 'Delete?',
1101: rep => 'Replace:',
1102: upl => 'Upload:',
1103: default => 'Default',
1104: custom => 'Custom',
1105: );
1106: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1107: my @currlangs;
1108: if (ref($settings) eq 'HASH') {
1109: if (ref($settings->{'helpurl'}) eq 'HASH') {
1110: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1111: next if ($settings->{'helpurl'}{$key} eq '');
1112: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1113: $type{$key} = 'custom';
1114: unless ($key eq 'nolang') {
1115: push(@currlangs,$key);
1116: }
1117: }
1118: } elsif ($settings->{'helpurl'} ne '') {
1119: $type{'nolang'} = 'custom';
1120: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1121: }
1122: }
1123: foreach my $lang ('nolang',sort(@currlangs)) {
1124: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1125: $datatable .= '<tr'.$css_class.'>';
1126: if ($url{$lang} eq '') {
1127: $url{$lang} = $defaulturl;
1128: }
1129: if ($type{$lang} eq '') {
1130: $type{$lang} = $defaulttype;
1131: }
1132: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1133: if ($lang eq 'nolang') {
1134: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1135: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1136: } else {
1137: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1138: $langchoices{$lang},
1139: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1140: }
1141: $datatable .= '</span></td>'."\n".
1142: '<td class="LC_left_item">';
1143: if ($type{$lang} eq 'custom') {
1144: $datatable .= '<span class="LC_nobreak"><label>'.
1145: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1146: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1147: } else {
1148: $datatable .= $lt{'upl'};
1149: }
1150: $datatable .='<br />';
1151: if ($switchserver) {
1152: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1153: } else {
1154: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1155: }
1156: $datatable .= '</td></tr>';
1157: $itemcount ++;
1158: }
1159: my @addlangs;
1160: foreach my $lang (sort(keys(%langchoices))) {
1161: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1162: push(@addlangs,$lang);
1163: }
1164: if (@addlangs > 0) {
1165: my %toadd;
1166: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1167: $toadd{''} = &mt('Select');
1168: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1169: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1170: &mt('Add log-in help page for a specific language:').' '.
1171: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1172: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1173: if ($switchserver) {
1174: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1175: } else {
1176: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1177: }
1178: $datatable .= '</td></tr>';
1179: $itemcount ++;
1180: }
1181: $datatable .= &captcha_choice('login',$settings,$itemcount);
1182: }
1183: return $datatable;
1184: }
1185:
1186: sub login_choices {
1187: my %choices =
1188: &Apache::lonlocal::texthash (
1189: coursecatalog => 'Display Course/Community Catalog link?',
1190: adminmail => "Display Administrator's E-mail Address?",
1191: helpdesk => 'Display "Contact Helpdesk" link',
1192: disallowlogin => "Login page requests redirected",
1193: hostid => "Server",
1194: server => "Redirect to:",
1195: serverpath => "Path",
1196: custompath => "Custom",
1197: exempt => "Exempt IP(s)",
1198: directlogin => "No redirect",
1199: newuser => "Link to create a user account",
1200: img => "Header",
1201: logo => "Main Logo",
1202: domlogo => "Domain Logo",
1203: login => "Log-in Header",
1204: textcol => "Text color",
1205: bgcol => "Box color",
1206: bgs => "Background colors",
1207: links => "Link colors",
1208: font => "Font color",
1209: pgbg => "Header",
1210: mainbg => "Page",
1211: sidebg => "Login box",
1212: link => "Link",
1213: alink => "Active link",
1214: vlink => "Visited link",
1215: );
1216: return %choices;
1217: }
1218:
1219: sub print_rolecolors {
1220: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1221: my %choices = &color_font_choices();
1222: my @bgs = ('pgbg','tabbg','sidebg');
1223: my @links = ('link','alink','vlink');
1224: my @images = ('img');
1225: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1226: my %designhash = &Apache::loncommon::get_domainconf($dom);
1227: my %defaultdesign = %Apache::loncommon::defaultdesign;
1228: my (%is_custom,%designs);
1229: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1230: if (ref($settings) eq 'HASH') {
1231: if (ref($settings->{$role}) eq 'HASH') {
1232: if ($settings->{$role}->{'img'} ne '') {
1233: $designs{'img'} = $settings->{$role}->{'img'};
1234: $is_custom{'img'} = 1;
1235: }
1236: if ($settings->{$role}->{'font'} ne '') {
1237: $designs{'font'} = $settings->{$role}->{'font'};
1238: $is_custom{'font'} = 1;
1239: }
1240: if ($settings->{$role}->{'fontmenu'} ne '') {
1241: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1242: $is_custom{'fontmenu'} = 1;
1243: }
1244: foreach my $item (@bgs) {
1245: if ($settings->{$role}->{$item} ne '') {
1246: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1247: $is_custom{$item} = 1;
1248: }
1249: }
1250: foreach my $item (@links) {
1251: if ($settings->{$role}->{$item} ne '') {
1252: $designs{'links'}{$item} = $settings->{$role}->{$item};
1253: $is_custom{$item} = 1;
1254: }
1255: }
1256: }
1257: } else {
1258: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1259: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1260: $is_custom{'img'} = 1;
1261: }
1262: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1263: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1264: $is_custom{'fontmenu'} = 1;
1265: }
1266: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1267: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1268: $is_custom{'font'} = 1;
1269: }
1270: foreach my $item (@bgs) {
1271: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1272: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1273: $is_custom{$item} = 1;
1274:
1275: }
1276: }
1277: foreach my $item (@links) {
1278: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1279: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1280: $is_custom{$item} = 1;
1281: }
1282: }
1283: }
1284: my $itemcount = 1;
1285: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1286: $datatable .= '</tr></table></td></tr>';
1287: return $datatable;
1288: }
1289:
1290: sub role_defaults {
1291: my ($role,$bgs,$links,$images,$logintext) = @_;
1292: my %defaults;
1293: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1294: return %defaults;
1295: }
1296: my %defaultdesign = %Apache::loncommon::defaultdesign;
1297: if ($role eq 'login') {
1298: %defaults = (
1299: font => $defaultdesign{$role.'.font'},
1300: );
1301: if (ref($logintext) eq 'ARRAY') {
1302: foreach my $item (@{$logintext}) {
1303: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1304: }
1305: }
1306: foreach my $item (@{$images}) {
1307: $defaults{'showlogo'}{$item} = 1;
1308: }
1309: } else {
1310: %defaults = (
1311: img => $defaultdesign{$role.'.img'},
1312: font => $defaultdesign{$role.'.font'},
1313: fontmenu => $defaultdesign{$role.'.fontmenu'},
1314: );
1315: }
1316: foreach my $item (@{$bgs}) {
1317: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1318: }
1319: foreach my $item (@{$links}) {
1320: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1321: }
1322: foreach my $item (@{$images}) {
1323: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1324: }
1325: return %defaults;
1326: }
1327:
1328: sub display_color_options {
1329: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1330: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1331: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1332: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1333: my $datatable = '<tr'.$css_class.'>'.
1334: '<td>'.$choices->{'font'}.'</td>';
1335: if (!$is_custom->{'font'}) {
1336: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1337: } else {
1338: $datatable .= '<td> </td>';
1339: }
1340: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1341:
1342: $datatable .= '<td><span class="LC_nobreak">'.
1343: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1344: ' value="'.$current_color.'" /> '.
1345: ' </td></tr>';
1346: unless ($role eq 'login') {
1347: $datatable .= '<tr'.$css_class.'>'.
1348: '<td>'.$choices->{'fontmenu'}.'</td>';
1349: if (!$is_custom->{'fontmenu'}) {
1350: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1351: } else {
1352: $datatable .= '<td> </td>';
1353: }
1354: $current_color = $designs->{'fontmenu'} ?
1355: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1356: $datatable .= '<td><span class="LC_nobreak">'.
1357: '<input class="colorchooser" type="text" size="10" name="'
1358: .$role.'_fontmenu"'.
1359: ' value="'.$current_color.'" /> '.
1360: ' </td></tr>';
1361: }
1362: my $switchserver = &check_switchserver($dom,$confname);
1363: foreach my $img (@{$images}) {
1364: $itemcount ++;
1365: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1366: $datatable .= '<tr'.$css_class.'>'.
1367: '<td>'.$choices->{$img};
1368: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1369: if ($role eq 'login') {
1370: if ($img eq 'login') {
1371: $login_hdr_pick =
1372: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1373: $logincolors =
1374: &login_text_colors($img,$role,$logintext,$phase,$choices,
1375: $designs,$defaults);
1376: } elsif ($img ne 'domlogo') {
1377: $datatable.= &logo_display_options($img,$defaults,$designs);
1378: }
1379: }
1380: $datatable .= '</td>';
1381: if ($designs->{$img} ne '') {
1382: $imgfile = $designs->{$img};
1383: $img_import = ($imgfile =~ m{^/adm/});
1384: } else {
1385: $imgfile = $defaults->{$img};
1386: }
1387: if ($imgfile) {
1388: my ($showfile,$fullsize);
1389: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1390: my $urldir = $1;
1391: my $filename = $2;
1392: my @info = &Apache::lonnet::stat_file($designs->{$img});
1393: if (@info) {
1394: my $thumbfile = 'tn-'.$filename;
1395: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1396: if (@thumb) {
1397: $showfile = $urldir.'/'.$thumbfile;
1398: } else {
1399: $showfile = $imgfile;
1400: }
1401: } else {
1402: $showfile = '';
1403: }
1404: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1405: $showfile = $imgfile;
1406: my $imgdir = $1;
1407: my $filename = $2;
1408: if (-e "$londocroot/$imgdir/tn-".$filename) {
1409: $showfile = "/$imgdir/tn-".$filename;
1410: } else {
1411: my $input = $londocroot.$imgfile;
1412: my $output = "$londocroot/$imgdir/tn-".$filename;
1413: if (!-e $output) {
1414: my ($width,$height) = &thumb_dimensions();
1415: my ($fullwidth,$fullheight) = &check_dimensions($input);
1416: if ($fullwidth ne '' && $fullheight ne '') {
1417: if ($fullwidth > $width && $fullheight > $height) {
1418: my $size = $width.'x'.$height;
1419: system("convert -sample $size $input $output");
1420: $showfile = "/$imgdir/tn-".$filename;
1421: }
1422: }
1423: }
1424: }
1425: }
1426: if ($showfile) {
1427: if ($showfile =~ m{^/(adm|res)/}) {
1428: if ($showfile =~ m{^/res/}) {
1429: my $local_showfile =
1430: &Apache::lonnet::filelocation('',$showfile);
1431: &Apache::lonnet::repcopy($local_showfile);
1432: }
1433: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1434: }
1435: if ($imgfile) {
1436: if ($imgfile =~ m{^/(adm|res)/}) {
1437: if ($imgfile =~ m{^/res/}) {
1438: my $local_imgfile =
1439: &Apache::lonnet::filelocation('',$imgfile);
1440: &Apache::lonnet::repcopy($local_imgfile);
1441: }
1442: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1443: } else {
1444: $fullsize = $imgfile;
1445: }
1446: }
1447: $datatable .= '<td>';
1448: if ($img eq 'login') {
1449: $datatable .= $login_hdr_pick;
1450: }
1451: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1452: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1453: } else {
1454: $datatable .= '<td> </td><td class="LC_left_item">'.
1455: &mt('Upload:').'<br />';
1456: }
1457: } else {
1458: $datatable .= '<td> </td><td class="LC_left_item">'.
1459: &mt('Upload:').'<br />';
1460: }
1461: if ($switchserver) {
1462: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1463: } else {
1464: if ($img ne 'login') { # suppress file selection for Log-in header
1465: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1466: }
1467: }
1468: $datatable .= '</td></tr>';
1469: }
1470: $itemcount ++;
1471: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1472: $datatable .= '<tr'.$css_class.'>'.
1473: '<td>'.$choices->{'bgs'}.'</td>';
1474: my $bgs_def;
1475: foreach my $item (@{$bgs}) {
1476: if (!$is_custom->{$item}) {
1477: $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>';
1478: }
1479: }
1480: if ($bgs_def) {
1481: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1482: } else {
1483: $datatable .= '<td> </td>';
1484: }
1485: $datatable .= '<td class="LC_right_item">'.
1486: '<table border="0"><tr>';
1487:
1488: foreach my $item (@{$bgs}) {
1489: $datatable .= '<td align="center">'.$choices->{$item};
1490: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1491: if ($designs->{'bgs'}{$item}) {
1492: $datatable .= ' ';
1493: }
1494: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1495: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1496: }
1497: $datatable .= '</tr></table></td></tr>';
1498: $itemcount ++;
1499: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1500: $datatable .= '<tr'.$css_class.'>'.
1501: '<td>'.$choices->{'links'}.'</td>';
1502: my $links_def;
1503: foreach my $item (@{$links}) {
1504: if (!$is_custom->{$item}) {
1505: $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1506: }
1507: }
1508: if ($links_def) {
1509: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1510: } else {
1511: $datatable .= '<td> </td>';
1512: }
1513: $datatable .= '<td class="LC_right_item">'.
1514: '<table border="0"><tr>';
1515: foreach my $item (@{$links}) {
1516: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1517: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1518: if ($designs->{'links'}{$item}) {
1519: $datatable.=' ';
1520: }
1521: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1522: '" /></td>';
1523: }
1524: $$rowtotal += $itemcount;
1525: return $datatable;
1526: }
1527:
1528: sub logo_display_options {
1529: my ($img,$defaults,$designs) = @_;
1530: my $checkedon;
1531: if (ref($defaults) eq 'HASH') {
1532: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1533: if ($defaults->{'showlogo'}{$img}) {
1534: $checkedon = 'checked="checked" ';
1535: }
1536: }
1537: }
1538: if (ref($designs) eq 'HASH') {
1539: if (ref($designs->{'showlogo'}) eq 'HASH') {
1540: if (defined($designs->{'showlogo'}{$img})) {
1541: if ($designs->{'showlogo'}{$img} == 0) {
1542: $checkedon = '';
1543: } elsif ($designs->{'showlogo'}{$img} == 1) {
1544: $checkedon = 'checked="checked" ';
1545: }
1546: }
1547: }
1548: }
1549: return '<br /><label> <input type="checkbox" name="'.
1550: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1551: &mt('show').'</label>'."\n";
1552: }
1553:
1554: sub login_header_options {
1555: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1556: my $output = '';
1557: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1558: $output .= &mt('Text default(s):').'<br />';
1559: if (!$is_custom->{'textcol'}) {
1560: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1561: ' ';
1562: }
1563: if (!$is_custom->{'bgcol'}) {
1564: $output .= $choices->{'bgcol'}.': '.
1565: '<span id="css_'.$role.'_font" style="background-color: '.
1566: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1567: }
1568: $output .= '<br />';
1569: }
1570: $output .='<br />';
1571: return $output;
1572: }
1573:
1574: sub login_text_colors {
1575: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1576: my $color_menu = '<table border="0"><tr>';
1577: foreach my $item (@{$logintext}) {
1578: $color_menu .= '<td align="center">'.$choices->{$item};
1579: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1580: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1581: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1582: }
1583: $color_menu .= '</tr></table><br />';
1584: return $color_menu;
1585: }
1586:
1587: sub image_changes {
1588: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1589: my $output;
1590: if ($img eq 'login') {
1591: # suppress image for Log-in header
1592: } elsif (!$is_custom) {
1593: if ($img ne 'domlogo') {
1594: $output .= &mt('Default image:').'<br />';
1595: } else {
1596: $output .= &mt('Default in use:').'<br />';
1597: }
1598: }
1599: if ($img eq 'login') { # suppress image for Log-in header
1600: $output .= '<td>'.$logincolors;
1601: } else {
1602: if ($img_import) {
1603: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1604: }
1605: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1606: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1607: if ($is_custom) {
1608: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1609: '<input type="checkbox" name="'.
1610: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1611: '</label> '.&mt('Replace:').'</span><br />';
1612: } else {
1613: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1614: }
1615: }
1616: return $output;
1617: }
1618:
1619: sub print_quotas {
1620: my ($dom,$settings,$rowtotal,$action) = @_;
1621: my $context;
1622: if ($action eq 'quotas') {
1623: $context = 'tools';
1624: } else {
1625: $context = $action;
1626: }
1627: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1628: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1629: my $typecount = 0;
1630: my ($css_class,%titles);
1631: if ($context eq 'requestcourses') {
1632: @usertools = ('official','unofficial','community','textbook');
1633: @options =('norequest','approval','validate','autolimit');
1634: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1635: %titles = &courserequest_titles();
1636: } elsif ($context eq 'requestauthor') {
1637: @usertools = ('author');
1638: @options = ('norequest','approval','automatic');
1639: %titles = &authorrequest_titles();
1640: } else {
1641: @usertools = ('aboutme','blog','webdav','portfolio');
1642: %titles = &tool_titles();
1643: }
1644: if (ref($types) eq 'ARRAY') {
1645: foreach my $type (@{$types}) {
1646: my ($currdefquota,$currauthorquota);
1647: unless (($context eq 'requestcourses') ||
1648: ($context eq 'requestauthor')) {
1649: if (ref($settings) eq 'HASH') {
1650: if (ref($settings->{defaultquota}) eq 'HASH') {
1651: $currdefquota = $settings->{defaultquota}->{$type};
1652: } else {
1653: $currdefquota = $settings->{$type};
1654: }
1655: if (ref($settings->{authorquota}) eq 'HASH') {
1656: $currauthorquota = $settings->{authorquota}->{$type};
1657: }
1658: }
1659: }
1660: if (defined($usertypes->{$type})) {
1661: $typecount ++;
1662: $css_class = $typecount%2?' class="LC_odd_row"':'';
1663: $datatable .= '<tr'.$css_class.'>'.
1664: '<td>'.$usertypes->{$type}.'</td>'.
1665: '<td class="LC_left_item">';
1666: if ($context eq 'requestcourses') {
1667: $datatable .= '<table><tr>';
1668: }
1669: my %cell;
1670: foreach my $item (@usertools) {
1671: if ($context eq 'requestcourses') {
1672: my ($curroption,$currlimit);
1673: if (ref($settings) eq 'HASH') {
1674: if (ref($settings->{$item}) eq 'HASH') {
1675: $curroption = $settings->{$item}->{$type};
1676: if ($curroption =~ /^autolimit=(\d*)$/) {
1677: $currlimit = $1;
1678: }
1679: }
1680: }
1681: if (!$curroption) {
1682: $curroption = 'norequest';
1683: }
1684: $datatable .= '<th>'.$titles{$item}.'</th>';
1685: foreach my $option (@options) {
1686: my $val = $option;
1687: if ($option eq 'norequest') {
1688: $val = 0;
1689: }
1690: if ($option eq 'validate') {
1691: my $canvalidate = 0;
1692: if (ref($validations{$item}) eq 'HASH') {
1693: if ($validations{$item}{$type}) {
1694: $canvalidate = 1;
1695: }
1696: }
1697: next if (!$canvalidate);
1698: }
1699: my $checked = '';
1700: if ($option eq $curroption) {
1701: $checked = ' checked="checked"';
1702: } elsif ($option eq 'autolimit') {
1703: if ($curroption =~ /^autolimit/) {
1704: $checked = ' checked="checked"';
1705: }
1706: }
1707: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1708: '<input type="radio" name="crsreq_'.$item.
1709: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1710: $titles{$option}.'</label>';
1711: if ($option eq 'autolimit') {
1712: $cell{$item} .= ' <input type="text" name="crsreq_'.
1713: $item.'_limit_'.$type.'" size="1" '.
1714: 'value="'.$currlimit.'" />';
1715: }
1716: $cell{$item} .= '</span> ';
1717: if ($option eq 'autolimit') {
1718: $cell{$item} .= $titles{'unlimited'};
1719: }
1720: }
1721: } elsif ($context eq 'requestauthor') {
1722: my $curroption;
1723: if (ref($settings) eq 'HASH') {
1724: $curroption = $settings->{$type};
1725: }
1726: if (!$curroption) {
1727: $curroption = 'norequest';
1728: }
1729: foreach my $option (@options) {
1730: my $val = $option;
1731: if ($option eq 'norequest') {
1732: $val = 0;
1733: }
1734: my $checked = '';
1735: if ($option eq $curroption) {
1736: $checked = ' checked="checked"';
1737: }
1738: $datatable .= '<span class="LC_nobreak"><label>'.
1739: '<input type="radio" name="authorreq_'.$type.
1740: '" value="'.$val.'"'.$checked.' />'.
1741: $titles{$option}.'</label></span> ';
1742: }
1743: } else {
1744: my $checked = 'checked="checked" ';
1745: if (ref($settings) eq 'HASH') {
1746: if (ref($settings->{$item}) eq 'HASH') {
1747: if ($settings->{$item}->{$type} == 0) {
1748: $checked = '';
1749: } elsif ($settings->{$item}->{$type} == 1) {
1750: $checked = 'checked="checked" ';
1751: }
1752: }
1753: }
1754: $datatable .= '<span class="LC_nobreak"><label>'.
1755: '<input type="checkbox" name="'.$context.'_'.$item.
1756: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1757: '</label></span> ';
1758: }
1759: }
1760: if ($context eq 'requestcourses') {
1761: $datatable .= '</tr><tr>';
1762: foreach my $item (@usertools) {
1763: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1764: }
1765: $datatable .= '</tr></table>';
1766: }
1767: $datatable .= '</td>';
1768: unless (($context eq 'requestcourses') ||
1769: ($context eq 'requestauthor')) {
1770: $datatable .=
1771: '<td class="LC_right_item">'.
1772: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1773: '<input type="text" name="quota_'.$type.
1774: '" value="'.$currdefquota.
1775: '" size="5" /></span>'.(' ' x 2).
1776: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1777: '<input type="text" name="authorquota_'.$type.
1778: '" value="'.$currauthorquota.
1779: '" size="5" /></span></td>';
1780: }
1781: $datatable .= '</tr>';
1782: }
1783: }
1784: }
1785: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1786: $defaultquota = '20';
1787: $authorquota = '500';
1788: if (ref($settings) eq 'HASH') {
1789: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1790: $defaultquota = $settings->{'defaultquota'}->{'default'};
1791: } elsif (defined($settings->{'default'})) {
1792: $defaultquota = $settings->{'default'};
1793: }
1794: if (ref($settings->{'authorquota'}) eq 'HASH') {
1795: $authorquota = $settings->{'authorquota'}->{'default'};
1796: }
1797: }
1798: }
1799: $typecount ++;
1800: $css_class = $typecount%2?' class="LC_odd_row"':'';
1801: $datatable .= '<tr'.$css_class.'>'.
1802: '<td>'.$othertitle.'</td>'.
1803: '<td class="LC_left_item">';
1804: if ($context eq 'requestcourses') {
1805: $datatable .= '<table><tr>';
1806: }
1807: my %defcell;
1808: foreach my $item (@usertools) {
1809: if ($context eq 'requestcourses') {
1810: my ($curroption,$currlimit);
1811: if (ref($settings) eq 'HASH') {
1812: if (ref($settings->{$item}) eq 'HASH') {
1813: $curroption = $settings->{$item}->{'default'};
1814: if ($curroption =~ /^autolimit=(\d*)$/) {
1815: $currlimit = $1;
1816: }
1817: }
1818: }
1819: if (!$curroption) {
1820: $curroption = 'norequest';
1821: }
1822: $datatable .= '<th>'.$titles{$item}.'</th>';
1823: foreach my $option (@options) {
1824: my $val = $option;
1825: if ($option eq 'norequest') {
1826: $val = 0;
1827: }
1828: if ($option eq 'validate') {
1829: my $canvalidate = 0;
1830: if (ref($validations{$item}) eq 'HASH') {
1831: if ($validations{$item}{'default'}) {
1832: $canvalidate = 1;
1833: }
1834: }
1835: next if (!$canvalidate);
1836: }
1837: my $checked = '';
1838: if ($option eq $curroption) {
1839: $checked = ' checked="checked"';
1840: } elsif ($option eq 'autolimit') {
1841: if ($curroption =~ /^autolimit/) {
1842: $checked = ' checked="checked"';
1843: }
1844: }
1845: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1846: '<input type="radio" name="crsreq_'.$item.
1847: '_default" value="'.$val.'"'.$checked.' />'.
1848: $titles{$option}.'</label>';
1849: if ($option eq 'autolimit') {
1850: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1851: $item.'_limit_default" size="1" '.
1852: 'value="'.$currlimit.'" />';
1853: }
1854: $defcell{$item} .= '</span> ';
1855: if ($option eq 'autolimit') {
1856: $defcell{$item} .= $titles{'unlimited'};
1857: }
1858: }
1859: } elsif ($context eq 'requestauthor') {
1860: my $curroption;
1861: if (ref($settings) eq 'HASH') {
1862: $curroption = $settings->{'default'};
1863: }
1864: if (!$curroption) {
1865: $curroption = 'norequest';
1866: }
1867: foreach my $option (@options) {
1868: my $val = $option;
1869: if ($option eq 'norequest') {
1870: $val = 0;
1871: }
1872: my $checked = '';
1873: if ($option eq $curroption) {
1874: $checked = ' checked="checked"';
1875: }
1876: $datatable .= '<span class="LC_nobreak"><label>'.
1877: '<input type="radio" name="authorreq_default"'.
1878: ' value="'.$val.'"'.$checked.' />'.
1879: $titles{$option}.'</label></span> ';
1880: }
1881: } else {
1882: my $checked = 'checked="checked" ';
1883: if (ref($settings) eq 'HASH') {
1884: if (ref($settings->{$item}) eq 'HASH') {
1885: if ($settings->{$item}->{'default'} == 0) {
1886: $checked = '';
1887: } elsif ($settings->{$item}->{'default'} == 1) {
1888: $checked = 'checked="checked" ';
1889: }
1890: }
1891: }
1892: $datatable .= '<span class="LC_nobreak"><label>'.
1893: '<input type="checkbox" name="'.$context.'_'.$item.
1894: '" value="default" '.$checked.'/>'.$titles{$item}.
1895: '</label></span> ';
1896: }
1897: }
1898: if ($context eq 'requestcourses') {
1899: $datatable .= '</tr><tr>';
1900: foreach my $item (@usertools) {
1901: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1902: }
1903: $datatable .= '</tr></table>';
1904: }
1905: $datatable .= '</td>';
1906: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1907: $datatable .= '<td class="LC_right_item">'.
1908: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1909: '<input type="text" name="defaultquota" value="'.
1910: $defaultquota.'" size="5" /></span>'.(' ' x2).
1911: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1912: '<input type="text" name="authorquota" value="'.
1913: $authorquota.'" size="5" /></span></td>';
1914: }
1915: $datatable .= '</tr>';
1916: $typecount ++;
1917: $css_class = $typecount%2?' class="LC_odd_row"':'';
1918: $datatable .= '<tr'.$css_class.'>'.
1919: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1920: if ($context eq 'requestcourses') {
1921: $datatable .= &mt('(overrides affiliation, if set)').
1922: '</td>'.
1923: '<td class="LC_left_item">'.
1924: '<table><tr>';
1925: } else {
1926: $datatable .= &mt('(overrides affiliation, if checked)').
1927: '</td>'.
1928: '<td class="LC_left_item" colspan="2">'.
1929: '<br />';
1930: }
1931: my %advcell;
1932: foreach my $item (@usertools) {
1933: if ($context eq 'requestcourses') {
1934: my ($curroption,$currlimit);
1935: if (ref($settings) eq 'HASH') {
1936: if (ref($settings->{$item}) eq 'HASH') {
1937: $curroption = $settings->{$item}->{'_LC_adv'};
1938: if ($curroption =~ /^autolimit=(\d*)$/) {
1939: $currlimit = $1;
1940: }
1941: }
1942: }
1943: $datatable .= '<th>'.$titles{$item}.'</th>';
1944: my $checked = '';
1945: if ($curroption eq '') {
1946: $checked = ' checked="checked"';
1947: }
1948: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1949: '<input type="radio" name="crsreq_'.$item.
1950: '__LC_adv" value=""'.$checked.' />'.
1951: &mt('No override set').'</label></span> ';
1952: foreach my $option (@options) {
1953: my $val = $option;
1954: if ($option eq 'norequest') {
1955: $val = 0;
1956: }
1957: if ($option eq 'validate') {
1958: my $canvalidate = 0;
1959: if (ref($validations{$item}) eq 'HASH') {
1960: if ($validations{$item}{'_LC_adv'}) {
1961: $canvalidate = 1;
1962: }
1963: }
1964: next if (!$canvalidate);
1965: }
1966: my $checked = '';
1967: if ($val eq $curroption) {
1968: $checked = ' checked="checked"';
1969: } elsif ($option eq 'autolimit') {
1970: if ($curroption =~ /^autolimit/) {
1971: $checked = ' checked="checked"';
1972: }
1973: }
1974: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1975: '<input type="radio" name="crsreq_'.$item.
1976: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1977: $titles{$option}.'</label>';
1978: if ($option eq 'autolimit') {
1979: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1980: $item.'_limit__LC_adv" size="1" '.
1981: 'value="'.$currlimit.'" />';
1982: }
1983: $advcell{$item} .= '</span> ';
1984: if ($option eq 'autolimit') {
1985: $advcell{$item} .= $titles{'unlimited'};
1986: }
1987: }
1988: } elsif ($context eq 'requestauthor') {
1989: my $curroption;
1990: if (ref($settings) eq 'HASH') {
1991: $curroption = $settings->{'_LC_adv'};
1992: }
1993: my $checked = '';
1994: if ($curroption eq '') {
1995: $checked = ' checked="checked"';
1996: }
1997: $datatable .= '<span class="LC_nobreak"><label>'.
1998: '<input type="radio" name="authorreq__LC_adv"'.
1999: ' value=""'.$checked.' />'.
2000: &mt('No override set').'</label></span> ';
2001: foreach my $option (@options) {
2002: my $val = $option;
2003: if ($option eq 'norequest') {
2004: $val = 0;
2005: }
2006: my $checked = '';
2007: if ($val eq $curroption) {
2008: $checked = ' checked="checked"';
2009: }
2010: $datatable .= '<span class="LC_nobreak"><label>'.
2011: '<input type="radio" name="authorreq__LC_adv"'.
2012: ' value="'.$val.'"'.$checked.' />'.
2013: $titles{$option}.'</label></span> ';
2014: }
2015: } else {
2016: my $checked = 'checked="checked" ';
2017: if (ref($settings) eq 'HASH') {
2018: if (ref($settings->{$item}) eq 'HASH') {
2019: if ($settings->{$item}->{'_LC_adv'} == 0) {
2020: $checked = '';
2021: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2022: $checked = 'checked="checked" ';
2023: }
2024: }
2025: }
2026: $datatable .= '<span class="LC_nobreak"><label>'.
2027: '<input type="checkbox" name="'.$context.'_'.$item.
2028: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2029: '</label></span> ';
2030: }
2031: }
2032: if ($context eq 'requestcourses') {
2033: $datatable .= '</tr><tr>';
2034: foreach my $item (@usertools) {
2035: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
2036: }
2037: $datatable .= '</tr></table>';
2038: }
2039: $datatable .= '</td></tr>';
2040: $$rowtotal += $typecount;
2041: return $datatable;
2042: }
2043:
2044: sub print_requestmail {
2045: my ($dom,$action,$settings,$rowtotal) = @_;
2046: my ($now,$datatable,%currapp);
2047: $now = time;
2048: if (ref($settings) eq 'HASH') {
2049: if (ref($settings->{'notify'}) eq 'HASH') {
2050: if ($settings->{'notify'}{'approval'} ne '') {
2051: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
2052: }
2053: }
2054: }
2055: my $numinrow = 2;
2056: my $css_class;
2057: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
2058: my $text;
2059: if ($action eq 'requestcourses') {
2060: $text = &mt('Receive notification of course requests requiring approval');
2061: } elsif ($action eq 'requestauthor') {
2062: $text = &mt('Receive notification of Authoring Space requests requiring approval');
2063: } else {
2064: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
2065: }
2066: $datatable = '<tr'.$css_class.'>'.
2067: ' <td>'.$text.'</td>'.
2068: ' <td class="LC_left_item">';
2069: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
2070: $action.'notifyapproval',%currapp);
2071: if ($numdc > 0) {
2072: $datatable .= $table;
2073: } else {
2074: $datatable .= &mt('There are no active Domain Coordinators');
2075: }
2076: $datatable .='</td></tr>';
2077: $$rowtotal += $rows;
2078: return $datatable;
2079: }
2080:
2081: sub print_studentcode {
2082: my ($settings,$rowtotal) = @_;
2083: my $rownum = 0;
2084: my ($output,%current);
2085: my @crstypes = ('official','unofficial','community','textbook');
2086: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2087: foreach my $type (@crstypes) {
2088: $current{$type} = $settings->{'uniquecode'}{$type};
2089: }
2090: }
2091: $output .= '<tr>'.
2092: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2093: '<td class="LC_left_item">';
2094: foreach my $type (@crstypes) {
2095: my $check = ' ';
2096: if ($current{$type}) {
2097: $check = ' checked="checked" ';
2098: }
2099: $output .= '<span class="LC_nobreak"><label>'.
2100: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2101: &mt($type).'</label></span>'.(' 'x2).' ';
2102: }
2103: $output .= '</td></tr>';
2104: $$rowtotal ++;
2105: return $output;
2106: }
2107:
2108: sub print_textbookcourses {
2109: my ($dom,$type,$settings,$rowtotal) = @_;
2110: my $rownum = 0;
2111: my $css_class;
2112: my $itemcount = 1;
2113: my $maxnum = 0;
2114: my $bookshash;
2115: if (ref($settings) eq 'HASH') {
2116: $bookshash = $settings->{$type};
2117: }
2118: my %ordered;
2119: if (ref($bookshash) eq 'HASH') {
2120: foreach my $item (keys(%{$bookshash})) {
2121: if (ref($bookshash->{$item}) eq 'HASH') {
2122: my $num = $bookshash->{$item}{'order'};
2123: $ordered{$num} = $item;
2124: }
2125: }
2126: }
2127: my $confname = $dom.'-domainconfig';
2128: my $switchserver = &check_switchserver($dom,$confname);
2129: my $maxnum = scalar(keys(%ordered));
2130: my $datatable;
2131: if (keys(%ordered)) {
2132: my @items = sort { $a <=> $b } keys(%ordered);
2133: for (my $i=0; $i<@items; $i++) {
2134: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2135: my $key = $ordered{$items[$i]};
2136: my %coursehash=&Apache::lonnet::coursedescription($key);
2137: my $coursetitle = $coursehash{'description'};
2138: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
2139: if (ref($bookshash->{$key}) eq 'HASH') {
2140: $subject = $bookshash->{$key}->{'subject'};
2141: $title = $bookshash->{$key}->{'title'};
2142: if ($type eq 'textbooks') {
2143: $publisher = $bookshash->{$key}->{'publisher'};
2144: $author = $bookshash->{$key}->{'author'};
2145: $image = $bookshash->{$key}->{'image'};
2146: if ($image ne '') {
2147: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2148: my $imagethumb = "$path/tn-".$imagefile;
2149: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2150: }
2151: }
2152: }
2153: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
2154: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
2155: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
2156: for (my $k=0; $k<=$maxnum; $k++) {
2157: my $vpos = $k+1;
2158: my $selstr;
2159: if ($k == $i) {
2160: $selstr = ' selected="selected" ';
2161: }
2162: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2163: }
2164: $datatable .= '</select>'.(' 'x2).
2165: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
2166: &mt('Delete?').'</label></span></td>'.
2167: '<td colspan="2">'.
2168: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
2169: (' 'x2).
2170: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2171: if ($type eq 'textbooks') {
2172: $datatable .= (' 'x2).
2173: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2174: (' 'x2).
2175: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2176: (' 'x2).
2177: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2178: if ($image) {
2179: $datatable .= '<span class="LC_nobreak">'.
2180: $imgsrc.
2181: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2182: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2183: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2184: }
2185: if ($switchserver) {
2186: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2187: } else {
2188: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2189: }
2190: }
2191: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
2192: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2193: $coursetitle.'</span></td></tr>'."\n";
2194: $itemcount ++;
2195: }
2196: }
2197: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2198: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
2199: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
2200: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2201: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
2202: for (my $k=0; $k<$maxnum+1; $k++) {
2203: my $vpos = $k+1;
2204: my $selstr;
2205: if ($k == $maxnum) {
2206: $selstr = ' selected="selected" ';
2207: }
2208: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2209: }
2210: $datatable .= '</select> '."\n".
2211: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
2212: '<td colspan="2">'.
2213: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
2214: (' 'x2).
2215: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2216: (' 'x2);
2217: if ($type eq 'textbooks') {
2218: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2219: (' 'x2).
2220: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
2221: (' 'x2).
2222: '<span class="LC_nobreak">'.&mt('Image:').' ';
2223: if ($switchserver) {
2224: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2225: } else {
2226: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2227: }
2228: }
2229: $datatable .= '</span>'."\n".
2230: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2231: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2232: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
2233: &Apache::loncommon::selectcourse_link
2234: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
2235: '</span></td>'."\n".
2236: '</tr>'."\n";
2237: $itemcount ++;
2238: return $datatable;
2239: }
2240:
2241: sub textbookcourses_javascript {
2242: my ($settings) = @_;
2243: return unless(ref($settings) eq 'HASH');
2244: my (%ordered,%total,%jstext);
2245: foreach my $type ('textbooks','templates') {
2246: $total{$type} = 0;
2247: if (ref($settings->{$type}) eq 'HASH') {
2248: foreach my $item (keys(%{$settings->{$type}})) {
2249: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2250: my $num = $settings->{$type}->{$item}{'order'};
2251: $ordered{$type}{$num} = $item;
2252: }
2253: }
2254: $total{$type} = scalar(keys(%{$settings->{$type}}));
2255: }
2256: my @jsarray = ();
2257: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2258: push(@jsarray,$ordered{$type}{$item});
2259: }
2260: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
2261: }
2262: return <<"ENDSCRIPT";
2263: <script type="text/javascript">
2264: // <![CDATA[
2265: function reorderBooks(form,item,caller) {
2266: var changedVal;
2267: $jstext{'textbooks'};
2268: $jstext{'templates'};
2269: var newpos;
2270: var maxh;
2271: if (caller == 'textbooks') {
2272: newpos = 'textbooks_addbook_pos';
2273: maxh = 1 + $total{'textbooks'};
2274: } else {
2275: newpos = 'templates_addbook_pos';
2276: maxh = 1 + $total{'templates'};
2277: }
2278: var current = new Array;
2279: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2280: if (item == newpos) {
2281: changedVal = newitemVal;
2282: } else {
2283: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2284: current[newitemVal] = newpos;
2285: }
2286: if (caller == 'textbooks') {
2287: for (var i=0; i<textbooks.length; i++) {
2288: var elementName = 'textbooks_'+textbooks[i];
2289: if (elementName != item) {
2290: if (form.elements[elementName]) {
2291: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2292: current[currVal] = elementName;
2293: }
2294: }
2295: }
2296: }
2297: if (caller == 'templates') {
2298: for (var i=0; i<templates.length; i++) {
2299: var elementName = 'templates_'+templates[i];
2300: if (elementName != item) {
2301: if (form.elements[elementName]) {
2302: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2303: current[currVal] = elementName;
2304: }
2305: }
2306: }
2307: }
2308: var oldVal;
2309: for (var j=0; j<maxh; j++) {
2310: if (current[j] == undefined) {
2311: oldVal = j;
2312: }
2313: }
2314: if (oldVal < changedVal) {
2315: for (var k=oldVal+1; k<=changedVal ; k++) {
2316: var elementName = current[k];
2317: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2318: }
2319: } else {
2320: for (var k=changedVal; k<oldVal; k++) {
2321: var elementName = current[k];
2322: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2323: }
2324: }
2325: return;
2326: }
2327:
2328: // ]]>
2329: </script>
2330:
2331: ENDSCRIPT
2332: }
2333:
2334: sub print_autoenroll {
2335: my ($dom,$settings,$rowtotal) = @_;
2336: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
2337: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
2338: if (ref($settings) eq 'HASH') {
2339: if (exists($settings->{'run'})) {
2340: if ($settings->{'run'} eq '0') {
2341: $runoff = ' checked="checked" ';
2342: $runon = ' ';
2343: } else {
2344: $runon = ' checked="checked" ';
2345: $runoff = ' ';
2346: }
2347: } else {
2348: if ($autorun) {
2349: $runon = ' checked="checked" ';
2350: $runoff = ' ';
2351: } else {
2352: $runoff = ' checked="checked" ';
2353: $runon = ' ';
2354: }
2355: }
2356: if (exists($settings->{'co-owners'})) {
2357: if ($settings->{'co-owners'} eq '0') {
2358: $coownersoff = ' checked="checked" ';
2359: $coownerson = ' ';
2360: } else {
2361: $coownerson = ' checked="checked" ';
2362: $coownersoff = ' ';
2363: }
2364: } else {
2365: $coownersoff = ' checked="checked" ';
2366: $coownerson = ' ';
2367: }
2368: if (exists($settings->{'sender_domain'})) {
2369: $defdom = $settings->{'sender_domain'};
2370: }
2371: } else {
2372: if ($autorun) {
2373: $runon = ' checked="checked" ';
2374: $runoff = ' ';
2375: } else {
2376: $runoff = ' checked="checked" ';
2377: $runon = ' ';
2378: }
2379: }
2380: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
2381: my $notif_sender;
2382: if (ref($settings) eq 'HASH') {
2383: $notif_sender = $settings->{'sender_uname'};
2384: }
2385: my $datatable='<tr class="LC_odd_row">'.
2386: '<td>'.&mt('Auto-enrollment active?').'</td>'.
2387: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2388: '<input type="radio" name="autoenroll_run"'.
2389: $runon.' value="1" />'.&mt('Yes').'</label> '.
2390: '<label><input type="radio" name="autoenroll_run"'.
2391: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
2392: '</tr><tr>'.
2393: '<td>'.&mt('Notification messages - sender').
2394: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
2395: &mt('username').': '.
2396: '<input type="text" name="sender_uname" value="'.
2397: $notif_sender.'" size="10" /> '.&mt('domain').
2398: ': '.$domform.'</span></td></tr>'.
2399: '<tr class="LC_odd_row">'.
2400: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2401: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2402: '<input type="radio" name="autoassign_coowners"'.
2403: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2404: '<label><input type="radio" name="autoassign_coowners"'.
2405: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2406: '</tr>';
2407: $$rowtotal += 3;
2408: return $datatable;
2409: }
2410:
2411: sub print_autoupdate {
2412: my ($position,$dom,$settings,$rowtotal) = @_;
2413: my $datatable;
2414: if ($position eq 'top') {
2415: my $updateon = ' ';
2416: my $updateoff = ' checked="checked" ';
2417: my $classlistson = ' ';
2418: my $classlistsoff = ' checked="checked" ';
2419: if (ref($settings) eq 'HASH') {
2420: if ($settings->{'run'} eq '1') {
2421: $updateon = $updateoff;
2422: $updateoff = ' ';
2423: }
2424: if ($settings->{'classlists'} eq '1') {
2425: $classlistson = $classlistsoff;
2426: $classlistsoff = ' ';
2427: }
2428: }
2429: my %title = (
2430: run => 'Auto-update active?',
2431: classlists => 'Update information in classlists?',
2432: );
2433: $datatable = '<tr class="LC_odd_row">'.
2434: '<td>'.&mt($title{'run'}).'</td>'.
2435: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2436: '<input type="radio" name="autoupdate_run"'.
2437: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2438: '<label><input type="radio" name="autoupdate_run"'.
2439: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
2440: '</tr><tr>'.
2441: '<td>'.&mt($title{'classlists'}).'</td>'.
2442: '<td class="LC_right_item"><span class="LC_nobreak">'.
2443: '<label><input type="radio" name="classlists"'.
2444: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2445: '<label><input type="radio" name="classlists"'.
2446: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
2447: '</tr>';
2448: $$rowtotal += 2;
2449: } elsif ($position eq 'middle') {
2450: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2451: my $numinrow = 3;
2452: my $locknamesettings;
2453: $datatable .= &insttypes_row($settings,$types,$usertypes,
2454: $dom,$numinrow,$othertitle,
2455: 'lockablenames');
2456: $$rowtotal ++;
2457: } else {
2458: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2459: my @fields = ('lastname','firstname','middlename','generation',
2460: 'permanentemail','id');
2461: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
2462: my $numrows = 0;
2463: if (ref($types) eq 'ARRAY') {
2464: if (@{$types} > 0) {
2465: $datatable =
2466: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2467: \@fields,$types,\$numrows);
2468: $$rowtotal += @{$types};
2469: }
2470: }
2471: $datatable .=
2472: &usertype_update_row($settings,{'default' => $othertitle},
2473: \%fieldtitles,\@fields,['default'],
2474: \$numrows);
2475: $$rowtotal ++;
2476: }
2477: return $datatable;
2478: }
2479:
2480: sub print_autocreate {
2481: my ($dom,$settings,$rowtotal) = @_;
2482: my (%createon,%createoff,%currhash);
2483: my @types = ('xml','req');
2484: if (ref($settings) eq 'HASH') {
2485: foreach my $item (@types) {
2486: $createoff{$item} = ' checked="checked" ';
2487: $createon{$item} = ' ';
2488: if (exists($settings->{$item})) {
2489: if ($settings->{$item}) {
2490: $createon{$item} = ' checked="checked" ';
2491: $createoff{$item} = ' ';
2492: }
2493: }
2494: }
2495: if ($settings->{'xmldc'} ne '') {
2496: $currhash{$settings->{'xmldc'}} = 1;
2497: }
2498: } else {
2499: foreach my $item (@types) {
2500: $createoff{$item} = ' checked="checked" ';
2501: $createon{$item} = ' ';
2502: }
2503: }
2504: $$rowtotal += 2;
2505: my $numinrow = 2;
2506: my $datatable='<tr class="LC_odd_row">'.
2507: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2508: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2509: '<input type="radio" name="autocreate_xml"'.
2510: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2511: '<label><input type="radio" name="autocreate_xml"'.
2512: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2513: '</td></tr><tr>'.
2514: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2515: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2516: '<input type="radio" name="autocreate_req"'.
2517: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2518: '<label><input type="radio" name="autocreate_req"'.
2519: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
2520: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2521: 'autocreate_xmldc',%currhash);
2522: if ($numdc > 1) {
2523: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2524: &mt('Course creation processed as: (choose Dom. Coord.)').
2525: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
2526: } else {
2527: $datatable .= $dctable.'</td></tr>';
2528: }
2529: $$rowtotal += $rows;
2530: return $datatable;
2531: }
2532:
2533: sub print_directorysrch {
2534: my ($dom,$settings,$rowtotal) = @_;
2535: my $srchon = ' ';
2536: my $srchoff = ' checked="checked" ';
2537: my ($exacton,$containson,$beginson);
2538: my $localon = ' ';
2539: my $localoff = ' checked="checked" ';
2540: if (ref($settings) eq 'HASH') {
2541: if ($settings->{'available'} eq '1') {
2542: $srchon = $srchoff;
2543: $srchoff = ' ';
2544: }
2545: if ($settings->{'localonly'} eq '1') {
2546: $localon = $localoff;
2547: $localoff = ' ';
2548: }
2549: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2550: foreach my $type (@{$settings->{'searchtypes'}}) {
2551: if ($type eq 'exact') {
2552: $exacton = ' checked="checked" ';
2553: } elsif ($type eq 'contains') {
2554: $containson = ' checked="checked" ';
2555: } elsif ($type eq 'begins') {
2556: $beginson = ' checked="checked" ';
2557: }
2558: }
2559: } else {
2560: if ($settings->{'searchtypes'} eq 'exact') {
2561: $exacton = ' checked="checked" ';
2562: } elsif ($settings->{'searchtypes'} eq 'contains') {
2563: $containson = ' checked="checked" ';
2564: } elsif ($settings->{'searchtypes'} eq 'specify') {
2565: $exacton = ' checked="checked" ';
2566: $containson = ' checked="checked" ';
2567: }
2568: }
2569: }
2570: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2571: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2572:
2573: my $numinrow = 4;
2574: my $cansrchrow = 0;
2575: my $datatable='<tr class="LC_odd_row">'.
2576: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
2577: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2578: '<input type="radio" name="dirsrch_available"'.
2579: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2580: '<label><input type="radio" name="dirsrch_available"'.
2581: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2582: '</tr><tr>'.
2583: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
2584: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2585: '<input type="radio" name="dirsrch_localonly"'.
2586: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2587: '<label><input type="radio" name="dirsrch_localonly"'.
2588: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
2589: '</tr>';
2590: $$rowtotal += 2;
2591: if (ref($usertypes) eq 'HASH') {
2592: if (keys(%{$usertypes}) > 0) {
2593: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2594: $numinrow,$othertitle,'cansearch');
2595: $cansrchrow = 1;
2596: }
2597: }
2598: if ($cansrchrow) {
2599: $$rowtotal ++;
2600: $datatable .= '<tr>';
2601: } else {
2602: $datatable .= '<tr class="LC_odd_row">';
2603: }
2604: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2605: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2606: foreach my $title (@{$titleorder}) {
2607: if (defined($searchtitles->{$title})) {
2608: my $check = ' ';
2609: if (ref($settings) eq 'HASH') {
2610: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2611: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2612: $check = ' checked="checked" ';
2613: }
2614: }
2615: }
2616: $datatable .= '<td class="LC_left_item">'.
2617: '<span class="LC_nobreak"><label>'.
2618: '<input type="checkbox" name="searchby" '.
2619: 'value="'.$title.'"'.$check.'/>'.
2620: $searchtitles->{$title}.'</label></span></td>';
2621: }
2622: }
2623: $datatable .= '</tr></table></td></tr>';
2624: $$rowtotal ++;
2625: if ($cansrchrow) {
2626: $datatable .= '<tr class="LC_odd_row">';
2627: } else {
2628: $datatable .= '<tr>';
2629: }
2630: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
2631: '<td class="LC_left_item" colspan="2">'.
2632: '<span class="LC_nobreak"><label>'.
2633: '<input type="checkbox" name="searchtypes" '.
2634: $exacton.' value="exact" />'.&mt('Exact match').
2635: '</label> '.
2636: '<label><input type="checkbox" name="searchtypes" '.
2637: $beginson.' value="begins" />'.&mt('Begins with').
2638: '</label> '.
2639: '<label><input type="checkbox" name="searchtypes" '.
2640: $containson.' value="contains" />'.&mt('Contains').
2641: '</label></span></td></tr>';
2642: $$rowtotal ++;
2643: return $datatable;
2644: }
2645:
2646: sub print_contacts {
2647: my ($dom,$settings,$rowtotal) = @_;
2648: my $datatable;
2649: my @contacts = ('adminemail','supportemail');
2650: my (%checked,%to,%otheremails,%bccemails);
2651: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
2652: 'requestsmail','updatesmail','idconflictsmail');
2653: foreach my $type (@mailings) {
2654: $otheremails{$type} = '';
2655: }
2656: $bccemails{'helpdeskmail'} = '';
2657: if (ref($settings) eq 'HASH') {
2658: foreach my $item (@contacts) {
2659: if (exists($settings->{$item})) {
2660: $to{$item} = $settings->{$item};
2661: }
2662: }
2663: foreach my $type (@mailings) {
2664: if (exists($settings->{$type})) {
2665: if (ref($settings->{$type}) eq 'HASH') {
2666: foreach my $item (@contacts) {
2667: if ($settings->{$type}{$item}) {
2668: $checked{$type}{$item} = ' checked="checked" ';
2669: }
2670: }
2671: $otheremails{$type} = $settings->{$type}{'others'};
2672: if ($type eq 'helpdeskmail') {
2673: $bccemails{$type} = $settings->{$type}{'bcc'};
2674: }
2675: }
2676: } elsif ($type eq 'lonstatusmail') {
2677: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2678: }
2679: }
2680: } else {
2681: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2682: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2683: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2684: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
2685: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2686: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2687: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
2688: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
2689: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
2690: }
2691: my ($titles,$short_titles) = &contact_titles();
2692: my $rownum = 0;
2693: my $css_class;
2694: foreach my $item (@contacts) {
2695: $css_class = $rownum%2?' class="LC_odd_row"':'';
2696: $datatable .= '<tr'.$css_class.'>'.
2697: '<td><span class="LC_nobreak">'.$titles->{$item}.
2698: '</span></td><td class="LC_right_item">'.
2699: '<input type="text" name="'.$item.'" value="'.
2700: $to{$item}.'" /></td></tr>';
2701: $rownum ++;
2702: }
2703: foreach my $type (@mailings) {
2704: $css_class = $rownum%2?' class="LC_odd_row"':'';
2705: $datatable .= '<tr'.$css_class.'>'.
2706: '<td><span class="LC_nobreak">'.
2707: $titles->{$type}.': </span></td>'.
2708: '<td class="LC_left_item">'.
2709: '<span class="LC_nobreak">';
2710: foreach my $item (@contacts) {
2711: $datatable .= '<label>'.
2712: '<input type="checkbox" name="'.$type.'"'.
2713: $checked{$type}{$item}.
2714: ' value="'.$item.'" />'.$short_titles->{$item}.
2715: '</label> ';
2716: }
2717: $datatable .= '</span><br />'.&mt('Others').': '.
2718: '<input type="text" name="'.$type.'_others" '.
2719: 'value="'.$otheremails{$type}.'" />';
2720: if ($type eq 'helpdeskmail') {
2721: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
2722: '<input type="text" name="'.$type.'_bcc" '.
2723: 'value="'.$bccemails{$type}.'" />';
2724: }
2725: $datatable .= '</td></tr>'."\n";
2726: $rownum ++;
2727: }
2728: my %choices;
2729: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2730: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2731: &mt('LON-CAPA core group - MSU'),600,500));
2732: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2733: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2734: &mt('LON-CAPA core group - MSU'),600,500));
2735: my @toggles = ('reporterrors','reportupdates');
2736: my %defaultchecked = ('reporterrors' => 'on',
2737: 'reportupdates' => 'on');
2738: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2739: \%choices,$rownum);
2740: $datatable .= $reports;
2741: $$rowtotal += $rownum;
2742: return $datatable;
2743: }
2744:
2745: sub print_helpsettings {
2746: my ($dom,$confname,$settings,$rowtotal) = @_;
2747: my ($datatable,$itemcount);
2748: $itemcount = 1;
2749: my (%choices,%defaultchecked,@toggles);
2750: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2751: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2752: &mt('LON-CAPA bug tracker'),600,500));
2753: %defaultchecked = ('submitbugs' => 'on');
2754: @toggles = ('submitbugs',);
2755:
2756: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2757: \%choices,$itemcount);
2758: return $datatable;
2759: }
2760:
2761: sub radiobutton_prefs {
2762: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
2763: $additional) = @_;
2764: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2765: (ref($choices) eq 'HASH'));
2766:
2767: my (%checkedon,%checkedoff,$datatable,$css_class);
2768:
2769: foreach my $item (@{$toggles}) {
2770: if ($defaultchecked->{$item} eq 'on') {
2771: $checkedon{$item} = ' checked="checked" ';
2772: $checkedoff{$item} = ' ';
2773: } elsif ($defaultchecked->{$item} eq 'off') {
2774: $checkedoff{$item} = ' checked="checked" ';
2775: $checkedon{$item} = ' ';
2776: }
2777: }
2778: if (ref($settings) eq 'HASH') {
2779: foreach my $item (@{$toggles}) {
2780: if ($settings->{$item} eq '1') {
2781: $checkedon{$item} = ' checked="checked" ';
2782: $checkedoff{$item} = ' ';
2783: } elsif ($settings->{$item} eq '0') {
2784: $checkedoff{$item} = ' checked="checked" ';
2785: $checkedon{$item} = ' ';
2786: }
2787: }
2788: }
2789: if ($onclick) {
2790: $onclick = ' onclick="'.$onclick.'"';
2791: }
2792: foreach my $item (@{$toggles}) {
2793: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2794: $datatable .=
2795: '<tr'.$css_class.'><td valign="top">'.
2796: '<span class="LC_nobreak">'.$choices->{$item}.
2797: '</span></td>'.
2798: '<td class="LC_right_item"><span class="LC_nobreak">'.
2799: '<label><input type="radio" name="'.
2800: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
2801: '</label> <label><input type="radio" name="'.$item.'" '.
2802: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2803: '</span>'.$additional.
2804: '</td>'.
2805: '</tr>';
2806: $itemcount ++;
2807: }
2808: return ($datatable,$itemcount);
2809: }
2810:
2811: sub print_coursedefaults {
2812: my ($position,$dom,$settings,$rowtotal) = @_;
2813: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
2814: my $itemcount = 1;
2815: my %choices = &Apache::lonlocal::texthash (
2816: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
2817: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
2818: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2819: coursecredits => 'Credits can be specified for courses',
2820: );
2821: my %staticdefaults = (
2822: anonsurvey_threshold => 10,
2823: uploadquota => 500,
2824: );
2825: if ($position eq 'top') {
2826: %defaultchecked = ('canuse_pdfforms' => 'off');
2827: @toggles = ('canuse_pdfforms');
2828: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2829: \%choices,$itemcount);
2830: } else {
2831: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2832: my ($currdefresponder,$def_official_credits,$def_unofficial_credits,$def_textbook_credits,
2833: %curruploadquota);
2834: my $currusecredits = 0;
2835: my @types = ('official','unofficial','community','textbook');
2836: if (ref($settings) eq 'HASH') {
2837: $currdefresponder = $settings->{'anonsurvey_threshold'};
2838: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2839: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2840: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2841: }
2842: }
2843: if (ref($settings->{'coursecredits'}) eq 'HASH') {
2844: $def_official_credits = $settings->{'coursecredits'}->{'official'};
2845: $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
2846: $def_textbook_credits = $settings->{'coursecredits'}->{'textbook'};
2847: if (($def_official_credits ne '') || ($def_unofficial_credits ne '') ||
2848: ($def_textbook_credits ne '')) {
2849: $currusecredits = 1;
2850: }
2851: }
2852: }
2853: if (!$currdefresponder) {
2854: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
2855: } elsif ($currdefresponder < 1) {
2856: $currdefresponder = 1;
2857: }
2858: foreach my $type (@types) {
2859: if ($curruploadquota{$type} eq '') {
2860: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
2861: }
2862: }
2863: $datatable .=
2864: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2865: $choices{'anonsurvey_threshold'}.
2866: '</span></td>'.
2867: '<td class="LC_right_item"><span class="LC_nobreak">'.
2868: '<input type="text" name="anonsurvey_threshold"'.
2869: ' value="'.$currdefresponder.'" size="5" /></span>'.
2870: '</td></tr>'."\n";
2871: $itemcount ++;
2872: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2873: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2874: $choices{'uploadquota'}.
2875: '</span></td>'.
2876: '<td align="right" class="LC_right_item">'.
2877: '<table><tr>';
2878: foreach my $type (@types) {
2879: $datatable .= '<td align="center">'.&mt($type).'<br />'.
2880: '<input type="text" name="uploadquota_'.$type.'"'.
2881: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
2882: }
2883: $datatable .= '</tr></table></td></tr>'."\n";
2884: $itemcount ++;
2885: my $onclick = "toggleDisplay(this.form,'credits');";
2886: my $display = 'none';
2887: if ($currusecredits) {
2888: $display = 'block';
2889: }
2890: my $additional = '<div id="credits" style="display: '.$display.'">'.
2891: '<span class="LC_nobreak">'.
2892: &mt('Default credits for official courses [_1]',
2893: '<input type="text" name="official_credits" value="'.
2894: $def_official_credits.'" size="3" />').
2895: '</span><br />'.
2896: '<span class="LC_nobreak">'.
2897: &mt('Default credits for unofficial courses [_1]',
2898: '<input type="text" name="unofficial_credits" value="'.
2899: $def_unofficial_credits.'" size="3" />').
2900: '</span><br />'.
2901: '<span class="LC_nobreak">'.
2902: &mt('Default credits for textbook courses [_1]',
2903: '<input type="text" name="textbook_credits" value="'.
2904: $def_textbook_credits.'" size="3" />').
2905: '</span></div>'."\n";
2906: %defaultchecked = ('coursecredits' => 'off');
2907: @toggles = ('coursecredits');
2908: my $current = {
2909: 'coursecredits' => $currusecredits,
2910: };
2911: (my $table,$itemcount) =
2912: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
2913: \%choices,$itemcount,$onclick,$additional);
2914: $datatable .= $table;
2915: $itemcount ++;
2916: }
2917: $$rowtotal += $itemcount;
2918: return $datatable;
2919: }
2920:
2921: sub print_selfenrollment {
2922: my ($position,$dom,$settings,$rowtotal) = @_;
2923: my ($css_class,$datatable);
2924: my $itemcount = 1;
2925: my @types = ('official','unofficial','community','textbook');
2926: if (($position eq 'top') || ($position eq 'middle')) {
2927: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
2928: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
2929: my @rows;
2930: my $key;
2931: if ($position eq 'top') {
2932: $key = 'admin';
2933: if (ref($rowsref) eq 'ARRAY') {
2934: @rows = @{$rowsref};
2935: }
2936: } elsif ($position eq 'middle') {
2937: $key = 'default';
2938: @rows = ('types','registered','approval','limit');
2939: }
2940: foreach my $row (@rows) {
2941: if (defined($titlesref->{$row})) {
2942: $itemcount ++;
2943: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2944: $datatable .= '<tr'.$css_class.'>'.
2945: '<td>'.$titlesref->{$row}.'</td>'.
2946: '<td class="LC_left_item">'.
2947: '<table><tr>';
2948: my (%current,%currentcap);
2949: if (ref($settings) eq 'HASH') {
2950: if (ref($settings->{$key}) eq 'HASH') {
2951: foreach my $type (@types) {
2952: if (ref($settings->{$key}->{$type}) eq 'HASH') {
2953: $current{$type} = $settings->{$key}->{$type}->{$row};
2954: }
2955: if (($row eq 'limit') && ($key eq 'default')) {
2956: if (ref($settings->{$key}->{$type}) eq 'HASH') {
2957: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
2958: }
2959: }
2960: }
2961: }
2962: }
2963: my %roles = (
2964: '0' => &Apache::lonnet::plaintext('dc'),
2965: );
2966:
2967: foreach my $type (@types) {
2968: unless (($row eq 'registered') && ($key eq 'default')) {
2969: $datatable .= '<th>'.&mt($type).'</th>';
2970: }
2971: }
2972: unless (($row eq 'registered') && ($key eq 'default')) {
2973: $datatable .= '</tr><tr>';
2974: }
2975: foreach my $type (@types) {
2976: if ($type eq 'community') {
2977: $roles{'1'} = &mt('Community personnel');
2978: } else {
2979: $roles{'1'} = &mt('Course personnel');
2980: }
2981: $datatable .= '<td style="vertical-align: top">';
2982: if ($position eq 'top') {
2983: my %checked;
2984: if ($current{$type} eq '0') {
2985: $checked{'0'} = ' checked="checked"';
2986: } else {
2987: $checked{'1'} = ' checked="checked"';
2988: }
2989: foreach my $role ('1','0') {
2990: $datatable .= '<span class="LC_nobreak"><label>'.
2991: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
2992: 'value="'.$role.'"'.$checked{$role}.' />'.
2993: $roles{$role}.'</label></span> ';
2994: }
2995: } else {
2996: if ($row eq 'types') {
2997: my %checked;
2998: if ($current{$type} =~ /^(all|dom)$/) {
2999: $checked{$1} = ' checked="checked"';
3000: } else {
3001: $checked{''} = ' checked="checked"';
3002: }
3003: foreach my $val ('','dom','all') {
3004: $datatable .= '<span class="LC_nobreak"><label>'.
3005: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3006: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3007: }
3008: } elsif ($row eq 'registered') {
3009: my %checked;
3010: if ($current{$type} eq '1') {
3011: $checked{'1'} = ' checked="checked"';
3012: } else {
3013: $checked{'0'} = ' checked="checked"';
3014: }
3015: foreach my $val ('0','1') {
3016: $datatable .= '<span class="LC_nobreak"><label>'.
3017: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3018: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3019: }
3020: } elsif ($row eq 'approval') {
3021: my %checked;
3022: if ($current{$type} =~ /^([12])$/) {
3023: $checked{$1} = ' checked="checked"';
3024: } else {
3025: $checked{'0'} = ' checked="checked"';
3026: }
3027: for my $val (0..2) {
3028: $datatable .= '<span class="LC_nobreak"><label>'.
3029: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3030: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3031: }
3032: } elsif ($row eq 'limit') {
3033: my %checked;
3034: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3035: $checked{$1} = ' checked="checked"';
3036: } else {
3037: $checked{'none'} = ' checked="checked"';
3038: }
3039: my $cap;
3040: if ($currentcap{$type} =~ /^\d+$/) {
3041: $cap = $currentcap{$type};
3042: }
3043: foreach my $val ('none','allstudents','selfenrolled') {
3044: $datatable .= '<span class="LC_nobreak"><label>'.
3045: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3046: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3047: }
3048: $datatable .= '<br />'.
3049: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3050: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3051: '</span>';
3052: }
3053: }
3054: $datatable .= '</td>';
3055: }
3056: $datatable .= '</tr>';
3057: }
3058: $datatable .= '</table></td></tr>';
3059: }
3060: } elsif ($position eq 'bottom') {
3061: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3062: }
3063: $$rowtotal += $itemcount;
3064: return $datatable;
3065: }
3066:
3067: sub print_validation_rows {
3068: my ($caller,$dom,$settings,$rowtotal) = @_;
3069: my ($itemsref,$namesref,$fieldsref);
3070: if ($caller eq 'selfenroll') {
3071: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3072: } elsif ($caller eq 'requestcourses') {
3073: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3074: }
3075: my %currvalidation;
3076: if (ref($settings) eq 'HASH') {
3077: if (ref($settings->{'validation'}) eq 'HASH') {
3078: %currvalidation = %{$settings->{'validation'}};
3079: }
3080: }
3081: my $datatable;
3082: my $itemcount = 0;
3083: foreach my $item (@{$itemsref}) {
3084: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3085: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3086: $namesref->{$item}.
3087: '</span></td>'.
3088: '<td class="LC_left_item">';
3089: if (($item eq 'url') || ($item eq 'button')) {
3090: $datatable .= '<span class="LC_nobreak">'.
3091: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3092: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3093: } elsif ($item eq 'fields') {
3094: my @currfields;
3095: if (ref($currvalidation{$item}) eq 'ARRAY') {
3096: @currfields = @{$currvalidation{$item}};
3097: }
3098: foreach my $field (@{$fieldsref}) {
3099: my $check = '';
3100: if (grep(/^\Q$field\E$/,@currfields)) {
3101: $check = ' checked="checked"';
3102: }
3103: $datatable .= '<span class="LC_nobreak"><label>'.
3104: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3105: ' value="'.$field.'"'.$check.' />'.$field.
3106: '</label></span> ';
3107: }
3108: } elsif ($item eq 'markup') {
3109: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
3110: $currvalidation{$item}.
3111: '</textarea>';
3112: }
3113: $datatable .= '</td></tr>'."\n";
3114: if (ref($rowtotal)) {
3115: $itemcount ++;
3116: }
3117: }
3118: if ($caller eq 'requestcourses') {
3119: my %currhash;
3120: if (ref($settings->{'validation'}) eq 'HASH') {
3121: if ($settings->{'validation'}{'dc'} ne '') {
3122: $currhash{$settings->{'validation'}{'dc'}} = 1;
3123: }
3124: }
3125: my $numinrow = 2;
3126: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3127: 'validationdc',%currhash);
3128: if ($numdc > 1) {
3129: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
3130: &mt('Course creation processed as: (choose Dom. Coord.)').
3131: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
3132: } else {
3133: $datatable .= $dctable.'</td></tr>';
3134: }
3135: $itemcount ++;
3136: }
3137: if (ref($rowtotal)) {
3138: $$rowtotal += $itemcount;
3139: }
3140: return $datatable;
3141: }
3142:
3143: sub print_usersessions {
3144: my ($position,$dom,$settings,$rowtotal) = @_;
3145: my ($css_class,$datatable,%checked,%choices);
3146: my (%by_ip,%by_location,@intdoms);
3147: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
3148:
3149: my @alldoms = &Apache::lonnet::all_domains();
3150: my %serverhomes = %Apache::lonnet::serverhomeIDs;
3151: my %servers = &Apache::lonnet::internet_dom_servers($dom);
3152: my %altids = &id_for_thisdom(%servers);
3153: my $itemcount = 1;
3154: if ($position eq 'top') {
3155: if (keys(%serverhomes) > 1) {
3156: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
3157: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
3158: } else {
3159: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
3160: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
3161: }
3162: } else {
3163: if (keys(%by_location) == 0) {
3164: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
3165: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
3166: } else {
3167: my %lt = &usersession_titles();
3168: my $numinrow = 5;
3169: my $prefix;
3170: my @types;
3171: if ($position eq 'bottom') {
3172: $prefix = 'remote';
3173: @types = ('version','excludedomain','includedomain');
3174: } else {
3175: $prefix = 'hosted';
3176: @types = ('excludedomain','includedomain');
3177: }
3178: my (%current,%checkedon,%checkedoff);
3179: my @lcversions = &Apache::lonnet::all_loncaparevs();
3180: my @locations = sort(keys(%by_location));
3181: foreach my $type (@types) {
3182: $checkedon{$type} = '';
3183: $checkedoff{$type} = ' checked="checked"';
3184: }
3185: if (ref($settings) eq 'HASH') {
3186: if (ref($settings->{$prefix}) eq 'HASH') {
3187: foreach my $key (keys(%{$settings->{$prefix}})) {
3188: $current{$key} = $settings->{$prefix}{$key};
3189: if ($key eq 'version') {
3190: if ($current{$key} ne '') {
3191: $checkedon{$key} = ' checked="checked"';
3192: $checkedoff{$key} = '';
3193: }
3194: } elsif (ref($current{$key}) eq 'ARRAY') {
3195: $checkedon{$key} = ' checked="checked"';
3196: $checkedoff{$key} = '';
3197: }
3198: }
3199: }
3200: }
3201: foreach my $type (@types) {
3202: next if ($type ne 'version' && !@locations);
3203: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3204: $datatable .= '<tr'.$css_class.'>
3205: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
3206: <span class="LC_nobreak">
3207: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
3208: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
3209: if ($type eq 'version') {
3210: my $selector = '<select name="'.$prefix.'_version">';
3211: foreach my $version (@lcversions) {
3212: my $selected = '';
3213: if ($current{'version'} eq $version) {
3214: $selected = ' selected="selected"';
3215: }
3216: $selector .= ' <option value="'.$version.'"'.
3217: $selected.'>'.$version.'</option>';
3218: }
3219: $selector .= '</select> ';
3220: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
3221: } else {
3222: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
3223: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
3224: ' />'.(' 'x2).
3225: '<input type="button" value="'.&mt('uncheck all').'" '.
3226: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
3227: "\n".
3228: '</div><div><table>';
3229: my $rem;
3230: for (my $i=0; $i<@locations; $i++) {
3231: my ($showloc,$value,$checkedtype);
3232: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
3233: my $ip = $by_location{$locations[$i]}->[0];
3234: if (ref($by_ip{$ip}) eq 'ARRAY') {
3235: $value = join(':',@{$by_ip{$ip}});
3236: $showloc = join(', ',@{$by_ip{$ip}});
3237: if (ref($current{$type}) eq 'ARRAY') {
3238: foreach my $loc (@{$by_ip{$ip}}) {
3239: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
3240: $checkedtype = ' checked="checked"';
3241: last;
3242: }
3243: }
3244: }
3245: }
3246: }
3247: $rem = $i%($numinrow);
3248: if ($rem == 0) {
3249: if ($i > 0) {
3250: $datatable .= '</tr>';
3251: }
3252: $datatable .= '<tr>';
3253: }
3254: $datatable .= '<td class="LC_left_item">'.
3255: '<span class="LC_nobreak"><label>'.
3256: '<input type="checkbox" name="'.$prefix.'_'.$type.
3257: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
3258: '</label></span></td>';
3259: }
3260: $rem = @locations%($numinrow);
3261: my $colsleft = $numinrow - $rem;
3262: if ($colsleft > 1 ) {
3263: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3264: ' </td>';
3265: } elsif ($colsleft == 1) {
3266: $datatable .= '<td class="LC_left_item"> </td>';
3267: }
3268: $datatable .= '</tr></table>';
3269: }
3270: $datatable .= '</td></tr>';
3271: $itemcount ++;
3272: }
3273: }
3274: }
3275: $$rowtotal += $itemcount;
3276: return $datatable;
3277: }
3278:
3279: sub build_location_hashes {
3280: my ($intdoms,$by_ip,$by_location) = @_;
3281: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
3282: (ref($by_location) eq 'HASH'));
3283: my %iphost = &Apache::lonnet::get_iphost();
3284: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
3285: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
3286: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
3287: foreach my $id (@{$iphost{$primary_ip}}) {
3288: my $intdom = &Apache::lonnet::internet_dom($id);
3289: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
3290: push(@{$intdoms},$intdom);
3291: }
3292: }
3293: }
3294: foreach my $ip (keys(%iphost)) {
3295: if (ref($iphost{$ip}) eq 'ARRAY') {
3296: foreach my $id (@{$iphost{$ip}}) {
3297: my $location = &Apache::lonnet::internet_dom($id);
3298: if ($location) {
3299: next if (grep(/^\Q$location\E$/,@{$intdoms}));
3300: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3301: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
3302: push(@{$by_ip->{$ip}},$location);
3303: }
3304: } else {
3305: $by_ip->{$ip} = [$location];
3306: }
3307: }
3308: }
3309: }
3310: }
3311: foreach my $ip (sort(keys(%{$by_ip}))) {
3312: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3313: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
3314: my $first = $by_ip->{$ip}->[0];
3315: if (ref($by_location->{$first}) eq 'ARRAY') {
3316: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
3317: push(@{$by_location->{$first}},$ip);
3318: }
3319: } else {
3320: $by_location->{$first} = [$ip];
3321: }
3322: }
3323: }
3324: return;
3325: }
3326:
3327: sub current_offloads_to {
3328: my ($dom,$settings,$servers) = @_;
3329: my (%spareid,%otherdomconfigs);
3330: if (ref($servers) eq 'HASH') {
3331: foreach my $lonhost (sort(keys(%{$servers}))) {
3332: my $gotspares;
3333: if (ref($settings) eq 'HASH') {
3334: if (ref($settings->{'spares'}) eq 'HASH') {
3335: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
3336: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
3337: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
3338: $gotspares = 1;
3339: }
3340: }
3341: }
3342: unless ($gotspares) {
3343: my $gotspares;
3344: my $serverhomeID =
3345: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
3346: my $serverhomedom =
3347: &Apache::lonnet::host_domain($serverhomeID);
3348: if ($serverhomedom ne $dom) {
3349: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
3350: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3351: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3352: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3353: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3354: $gotspares = 1;
3355: }
3356: }
3357: } else {
3358: $otherdomconfigs{$serverhomedom} =
3359: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
3360: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
3361: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3362: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3363: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
3364: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3365: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3366: $gotspares = 1;
3367: }
3368: }
3369: }
3370: }
3371: }
3372: }
3373: }
3374: unless ($gotspares) {
3375: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
3376: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3377: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3378: } else {
3379: my $server_hostname = &Apache::lonnet::hostname($lonhost);
3380: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
3381: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
3382: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3383: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3384: } else {
3385: my %what = (
3386: spareid => 1,
3387: );
3388: my ($result,$returnhash) =
3389: &Apache::lonnet::get_remote_globals($lonhost,\%what);
3390: if ($result eq 'ok') {
3391: if (ref($returnhash) eq 'HASH') {
3392: if (ref($returnhash->{'spareid'}) eq 'HASH') {
3393: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
3394: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
3395: }
3396: }
3397: }
3398: }
3399: }
3400: }
3401: }
3402: }
3403: return %spareid;
3404: }
3405:
3406: sub spares_row {
3407: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
3408: my $css_class;
3409: my $numinrow = 4;
3410: my $itemcount = 1;
3411: my $datatable;
3412: my %typetitles = &sparestype_titles();
3413: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
3414: foreach my $server (sort(keys(%{$servers}))) {
3415: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
3416: my ($othercontrol,$serverdom);
3417: if ($serverhome ne $server) {
3418: $serverdom = &Apache::lonnet::host_domain($serverhome);
3419: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3420: } else {
3421: $serverdom = &Apache::lonnet::host_domain($server);
3422: if ($serverdom ne $dom) {
3423: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3424: }
3425: }
3426: next unless (ref($spareid->{$server}) eq 'HASH');
3427: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3428: $datatable .= '<tr'.$css_class.'>
3429: <td rowspan="2">
3430: <span class="LC_nobreak">'.
3431: &mt('[_1] when busy, offloads to:'
3432: ,'<b>'.$server.'</b>').
3433: "\n";
3434: my (%current,%canselect);
3435: my @choices =
3436: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
3437: foreach my $type ('primary','default') {
3438: if (ref($spareid->{$server}) eq 'HASH') {
3439: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
3440: my @spares = @{$spareid->{$server}{$type}};
3441: if (@spares > 0) {
3442: if ($othercontrol) {
3443: $current{$type} = join(', ',@spares);
3444: } else {
3445: $current{$type} .= '<table>';
3446: my $numspares = scalar(@spares);
3447: for (my $i=0; $i<@spares; $i++) {
3448: my $rem = $i%($numinrow);
3449: if ($rem == 0) {
3450: if ($i > 0) {
3451: $current{$type} .= '</tr>';
3452: }
3453: $current{$type} .= '<tr>';
3454: }
3455: $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'".');" /> '.
3456: $spareid->{$server}{$type}[$i].
3457: '</label></td>'."\n";
3458: }
3459: my $rem = @spares%($numinrow);
3460: my $colsleft = $numinrow - $rem;
3461: if ($colsleft > 1 ) {
3462: $current{$type} .= '<td colspan="'.$colsleft.
3463: '" class="LC_left_item">'.
3464: ' </td>';
3465: } elsif ($colsleft == 1) {
3466: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
3467: }
3468: $current{$type} .= '</tr></table>';
3469: }
3470: }
3471: }
3472: if ($current{$type} eq '') {
3473: $current{$type} = &mt('None specified');
3474: }
3475: if ($othercontrol) {
3476: if ($type eq 'primary') {
3477: $canselect{$type} = $othercontrol;
3478: }
3479: } else {
3480: $canselect{$type} =
3481: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
3482: '<select name="newspare_'.$type.'_'.$server.'" '.
3483: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
3484: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
3485: if (@choices > 0) {
3486: foreach my $lonhost (@choices) {
3487: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
3488: }
3489: }
3490: $canselect{$type} .= '</select>'."\n";
3491: }
3492: } else {
3493: $current{$type} = &mt('Could not be determined');
3494: if ($type eq 'primary') {
3495: $canselect{$type} = $othercontrol;
3496: }
3497: }
3498: if ($type eq 'default') {
3499: $datatable .= '<tr'.$css_class.'>';
3500: }
3501: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
3502: '<td>'.$current{$type}.'</td>'."\n".
3503: '<td>'.$canselect{$type}.'</td></tr>'."\n";
3504: }
3505: $itemcount ++;
3506: }
3507: }
3508: $$rowtotal += $itemcount;
3509: return $datatable;
3510: }
3511:
3512: sub possible_newspares {
3513: my ($server,$currspares,$serverhomes,$altids) = @_;
3514: my $serverhostname = &Apache::lonnet::hostname($server);
3515: my %excluded;
3516: if ($serverhostname ne '') {
3517: %excluded = (
3518: $serverhostname => 1,
3519: );
3520: }
3521: if (ref($currspares) eq 'HASH') {
3522: foreach my $type (keys(%{$currspares})) {
3523: if (ref($currspares->{$type}) eq 'ARRAY') {
3524: if (@{$currspares->{$type}} > 0) {
3525: foreach my $curr (@{$currspares->{$type}}) {
3526: my $hostname = &Apache::lonnet::hostname($curr);
3527: $excluded{$hostname} = 1;
3528: }
3529: }
3530: }
3531: }
3532: }
3533: my @choices;
3534: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
3535: if (keys(%{$serverhomes}) > 1) {
3536: foreach my $name (sort(keys(%{$serverhomes}))) {
3537: unless ($excluded{$name}) {
3538: if (exists($altids->{$serverhomes->{$name}})) {
3539: push(@choices,$altids->{$serverhomes->{$name}});
3540: } else {
3541: push(@choices,$serverhomes->{$name});
3542: }
3543: }
3544: }
3545: }
3546: }
3547: return sort(@choices);
3548: }
3549:
3550: sub print_loadbalancing {
3551: my ($dom,$settings,$rowtotal) = @_;
3552: my $primary_id = &Apache::lonnet::domain($dom,'primary');
3553: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3554: my $numinrow = 1;
3555: my $datatable;
3556: my %servers = &Apache::lonnet::internet_dom_servers($dom);
3557: my (%currbalancer,%currtargets,%currrules,%existing);
3558: if (ref($settings) eq 'HASH') {
3559: %existing = %{$settings};
3560: }
3561: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
3562: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
3563: \%currtargets,\%currrules);
3564: } else {
3565: return;
3566: }
3567: my ($othertitle,$usertypes,$types) =
3568: &Apache::loncommon::sorted_inst_types($dom);
3569: my $rownum = 8;
3570: if (ref($types) eq 'ARRAY') {
3571: $rownum += scalar(@{$types});
3572: }
3573: my @css_class = ('LC_odd_row','LC_even_row');
3574: my $balnum = 0;
3575: my $islast;
3576: my (@toshow,$disabledtext);
3577: if (keys(%currbalancer) > 0) {
3578: @toshow = sort(keys(%currbalancer));
3579: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
3580: push(@toshow,'');
3581: }
3582: } else {
3583: @toshow = ('');
3584: $disabledtext = &mt('No existing load balancer');
3585: }
3586: foreach my $lonhost (@toshow) {
3587: if ($balnum == scalar(@toshow)-1) {
3588: $islast = 1;
3589: } else {
3590: $islast = 0;
3591: }
3592: my $cssidx = $balnum%2;
3593: my $targets_div_style = 'display: none';
3594: my $disabled_div_style = 'display: block';
3595: my $homedom_div_style = 'display: none';
3596: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3597: '<td rowspan="'.$rownum.'" valign="top">'.
3598: '<p>';
3599: if ($lonhost eq '') {
3600: $datatable .= '<span class="LC_nobreak">';
3601: if (keys(%currbalancer) > 0) {
3602: $datatable .= &mt('Add balancer:');
3603: } else {
3604: $datatable .= &mt('Enable balancer:');
3605: }
3606: $datatable .= ' '.
3607: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3608: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3609: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3610: '<option value="" selected="selected">'.&mt('None').
3611: '</option>'."\n";
3612: foreach my $server (sort(keys(%servers))) {
3613: next if ($currbalancer{$server});
3614: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3615: }
3616: $datatable .=
3617: '</select>'."\n".
3618: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3619: } else {
3620: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3621: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3622: &mt('Stop balancing').'</label>'.
3623: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3624: $targets_div_style = 'display: block';
3625: $disabled_div_style = 'display: none';
3626: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3627: $homedom_div_style = 'display: block';
3628: }
3629: }
3630: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3631: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3632: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3633: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3634: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3635: my @sparestypes = ('primary','default');
3636: my %typetitles = &sparestype_titles();
3637: foreach my $sparetype (@sparestypes) {
3638: my $targettable;
3639: for (my $i=0; $i<$numspares; $i++) {
3640: my $checked;
3641: if (ref($currtargets{$lonhost}) eq 'HASH') {
3642: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3643: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3644: $checked = ' checked="checked"';
3645: }
3646: }
3647: }
3648: my ($chkboxval,$disabled);
3649: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3650: $chkboxval = $spares[$i];
3651: }
3652: if (exists($currbalancer{$spares[$i]})) {
3653: $disabled = ' disabled="disabled"';
3654: }
3655: $targettable .=
3656: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3657: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3658: '</span></label></td>';
3659: my $rem = $i%($numinrow);
3660: if ($rem == 0) {
3661: if (($i > 0) && ($i < $numspares-1)) {
3662: $targettable .= '</tr>';
3663: }
3664: if ($i < $numspares-1) {
3665: $targettable .= '<tr>';
3666: }
3667: }
3668: }
3669: if ($targettable ne '') {
3670: my $rem = $numspares%($numinrow);
3671: my $colsleft = $numinrow - $rem;
3672: if ($colsleft > 1 ) {
3673: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3674: ' </td>';
3675: } elsif ($colsleft == 1) {
3676: $targettable .= '<td class="LC_left_item"> </td>';
3677: }
3678: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3679: '<table><tr>'.$targettable.'</tr></table><br />';
3680: }
3681: }
3682: $datatable .= '</div></td></tr>'.
3683: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3684: $othertitle,$usertypes,$types,\%servers,
3685: \%currbalancer,$lonhost,
3686: $targets_div_style,$homedom_div_style,
3687: $css_class[$cssidx],$balnum,$islast);
3688: $$rowtotal += $rownum;
3689: $balnum ++;
3690: }
3691: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3692: return $datatable;
3693: }
3694:
3695: sub get_loadbalancers_config {
3696: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3697: return unless ((ref($servers) eq 'HASH') &&
3698: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3699: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3700: if (keys(%{$existing}) > 0) {
3701: my $oldlonhost;
3702: foreach my $key (sort(keys(%{$existing}))) {
3703: if ($key eq 'lonhost') {
3704: $oldlonhost = $existing->{'lonhost'};
3705: $currbalancer->{$oldlonhost} = 1;
3706: } elsif ($key eq 'targets') {
3707: if ($oldlonhost) {
3708: $currtargets->{$oldlonhost} = $existing->{'targets'};
3709: }
3710: } elsif ($key eq 'rules') {
3711: if ($oldlonhost) {
3712: $currrules->{$oldlonhost} = $existing->{'rules'};
3713: }
3714: } elsif (ref($existing->{$key}) eq 'HASH') {
3715: $currbalancer->{$key} = 1;
3716: $currtargets->{$key} = $existing->{$key}{'targets'};
3717: $currrules->{$key} = $existing->{$key}{'rules'};
3718: }
3719: }
3720: } else {
3721: my ($balancerref,$targetsref) =
3722: &Apache::lonnet::get_lonbalancer_config($servers);
3723: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3724: foreach my $server (sort(keys(%{$balancerref}))) {
3725: $currbalancer->{$server} = 1;
3726: $currtargets->{$server} = $targetsref->{$server};
3727: }
3728: }
3729: }
3730: return;
3731: }
3732:
3733: sub loadbalancing_rules {
3734: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
3735: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3736: $css_class,$balnum,$islast) = @_;
3737: my $output;
3738: my $num = 0;
3739: my ($alltypes,$othertypes,$titles) =
3740: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3741: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3742: foreach my $type (@{$alltypes}) {
3743: $num ++;
3744: my $current;
3745: if (ref($currrules) eq 'HASH') {
3746: $current = $currrules->{$type};
3747: }
3748: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
3749: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
3750: $current = '';
3751: }
3752: }
3753: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
3754: $servers,$currbalancer,$lonhost,$dom,
3755: $targets_div_style,$homedom_div_style,
3756: $css_class,$balnum,$num,$islast);
3757: }
3758: }
3759: return $output;
3760: }
3761:
3762: sub loadbalancing_titles {
3763: my ($dom,$intdom,$usertypes,$types) = @_;
3764: my %othertypes = (
3765: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3766: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3767: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3768: '_LC_external' => &mt('Users not from [_1]',$intdom),
3769: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
3770: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
3771: );
3772: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
3773: if (ref($types) eq 'ARRAY') {
3774: unshift(@alltypes,@{$types},'default');
3775: }
3776: my %titles;
3777: foreach my $type (@alltypes) {
3778: if ($type =~ /^_LC_/) {
3779: $titles{$type} = $othertypes{$type};
3780: } elsif ($type eq 'default') {
3781: $titles{$type} = &mt('All users from [_1]',$dom);
3782: if (ref($types) eq 'ARRAY') {
3783: if (@{$types} > 0) {
3784: $titles{$type} = &mt('Other users from [_1]',$dom);
3785: }
3786: }
3787: } elsif (ref($usertypes) eq 'HASH') {
3788: $titles{$type} = $usertypes->{$type};
3789: }
3790: }
3791: return (\@alltypes,\%othertypes,\%titles);
3792: }
3793:
3794: sub loadbalance_rule_row {
3795: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3796: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
3797: my @rulenames;
3798: my %ruletitles = &offloadtype_text();
3799: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
3800: @rulenames = ('balancer','offloadedto');
3801: } else {
3802: @rulenames = ('default','homeserver');
3803: if ($type eq '_LC_external') {
3804: push(@rulenames,'externalbalancer');
3805: } else {
3806: push(@rulenames,'specific');
3807: }
3808: push(@rulenames,'none');
3809: }
3810: my $style = $targets_div_style;
3811: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
3812: $style = $homedom_div_style;
3813: }
3814: my $space;
3815: if ($islast && $num == 1) {
3816: $space = '<div display="inline-block"> </div>';
3817: }
3818: my $output =
3819: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3820: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3821: '<td valaign="top">'.$space.
3822: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
3823: for (my $i=0; $i<@rulenames; $i++) {
3824: my $rule = $rulenames[$i];
3825: my ($checked,$extra);
3826: if ($rulenames[$i] eq 'default') {
3827: $rule = '';
3828: }
3829: if ($rulenames[$i] eq 'specific') {
3830: if (ref($servers) eq 'HASH') {
3831: my $default;
3832: if (($current ne '') && (exists($servers->{$current}))) {
3833: $checked = ' checked="checked"';
3834: }
3835: unless ($checked) {
3836: $default = ' selected="selected"';
3837: }
3838: $extra =
3839: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3840: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3841: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3842: '<option value=""'.$default.'></option>'."\n";
3843: foreach my $server (sort(keys(%{$servers}))) {
3844: if (ref($currbalancer) eq 'HASH') {
3845: next if (exists($currbalancer->{$server}));
3846: }
3847: my $selected;
3848: if ($server eq $current) {
3849: $selected = ' selected="selected"';
3850: }
3851: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
3852: }
3853: $extra .= '</select>';
3854: }
3855: } elsif ($rule eq $current) {
3856: $checked = ' checked="checked"';
3857: }
3858: $output .= '<span class="LC_nobreak"><label>'.
3859: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3860: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3861: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
3862: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3863: '</label>'.$extra.'</span><br />'."\n";
3864: }
3865: $output .= '</div></td></tr>'."\n";
3866: return $output;
3867: }
3868:
3869: sub offloadtype_text {
3870: my %ruletitles = &Apache::lonlocal::texthash (
3871: 'default' => 'Offloads to default destinations',
3872: 'homeserver' => "Offloads to user's home server",
3873: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3874: 'specific' => 'Offloads to specific server',
3875: 'none' => 'No offload',
3876: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
3877: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
3878: );
3879: return %ruletitles;
3880: }
3881:
3882: sub sparestype_titles {
3883: my %typestitles = &Apache::lonlocal::texthash (
3884: 'primary' => 'primary',
3885: 'default' => 'default',
3886: );
3887: return %typestitles;
3888: }
3889:
3890: sub contact_titles {
3891: my %titles = &Apache::lonlocal::texthash (
3892: 'supportemail' => 'Support E-mail address',
3893: 'adminemail' => 'Default Server Admin E-mail address',
3894: 'errormail' => 'Error reports to be e-mailed to',
3895: 'packagesmail' => 'Package update alerts to be e-mailed to',
3896: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3897: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
3898: 'requestsmail' => 'E-mail from course requests requiring approval',
3899: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
3900: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
3901: );
3902: my %short_titles = &Apache::lonlocal::texthash (
3903: adminemail => 'Admin E-mail address',
3904: supportemail => 'Support E-mail',
3905: );
3906: return (\%titles,\%short_titles);
3907: }
3908:
3909: sub tool_titles {
3910: my %titles = &Apache::lonlocal::texthash (
3911: aboutme => 'Personal web page',
3912: blog => 'Blog',
3913: webdav => 'WebDAV',
3914: portfolio => 'Portfolio',
3915: official => 'Official courses (with institutional codes)',
3916: unofficial => 'Unofficial courses',
3917: community => 'Communities',
3918: textbook => 'Textbook courses',
3919: );
3920: return %titles;
3921: }
3922:
3923: sub courserequest_titles {
3924: my %titles = &Apache::lonlocal::texthash (
3925: official => 'Official',
3926: unofficial => 'Unofficial',
3927: community => 'Communities',
3928: textbook => 'Textbook',
3929: norequest => 'Not allowed',
3930: approval => 'Approval by Dom. Coord.',
3931: validate => 'With validation',
3932: autolimit => 'Numerical limit',
3933: unlimited => '(blank for unlimited)',
3934: );
3935: return %titles;
3936: }
3937:
3938: sub authorrequest_titles {
3939: my %titles = &Apache::lonlocal::texthash (
3940: norequest => 'Not allowed',
3941: approval => 'Approval by Dom. Coord.',
3942: automatic => 'Automatic approval',
3943: );
3944: return %titles;
3945: }
3946:
3947: sub courserequest_conditions {
3948: my %conditions = &Apache::lonlocal::texthash (
3949: approval => '(Processing of request subject to approval by Domain Coordinator).',
3950: validate => '(Processing of request subject to institutional validation).',
3951: );
3952: return %conditions;
3953: }
3954:
3955:
3956: sub print_usercreation {
3957: my ($position,$dom,$settings,$rowtotal) = @_;
3958: my $numinrow = 4;
3959: my $datatable;
3960: if ($position eq 'top') {
3961: $$rowtotal ++;
3962: my $rowcount = 0;
3963: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
3964: if (ref($rules) eq 'HASH') {
3965: if (keys(%{$rules}) > 0) {
3966: $datatable .= &user_formats_row('username',$settings,$rules,
3967: $ruleorder,$numinrow,$rowcount);
3968: $$rowtotal ++;
3969: $rowcount ++;
3970: }
3971: }
3972: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3973: if (ref($idrules) eq 'HASH') {
3974: if (keys(%{$idrules}) > 0) {
3975: $datatable .= &user_formats_row('id',$settings,$idrules,
3976: $idruleorder,$numinrow,$rowcount);
3977: $$rowtotal ++;
3978: $rowcount ++;
3979: }
3980: }
3981: if ($rowcount == 0) {
3982: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3983: $$rowtotal ++;
3984: $rowcount ++;
3985: }
3986: } elsif ($position eq 'middle') {
3987: my @creators = ('author','course','requestcrs');
3988: my ($rules,$ruleorder) =
3989: &Apache::lonnet::inst_userrules($dom,'username');
3990: my %lt = &usercreation_types();
3991: my %checked;
3992: if (ref($settings) eq 'HASH') {
3993: if (ref($settings->{'cancreate'}) eq 'HASH') {
3994: foreach my $item (@creators) {
3995: $checked{$item} = $settings->{'cancreate'}{$item};
3996: }
3997: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3998: foreach my $item (@creators) {
3999: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
4000: $checked{$item} = 'none';
4001: }
4002: }
4003: }
4004: }
4005: my $rownum = 0;
4006: foreach my $item (@creators) {
4007: $rownum ++;
4008: if ($checked{$item} eq '') {
4009: $checked{$item} = 'any';
4010: }
4011: my $css_class;
4012: if ($rownum%2) {
4013: $css_class = '';
4014: } else {
4015: $css_class = ' class="LC_odd_row" ';
4016: }
4017: $datatable .= '<tr'.$css_class.'>'.
4018: '<td><span class="LC_nobreak">'.$lt{$item}.
4019: '</span></td><td align="right">';
4020: my @options = ('any');
4021: if (ref($rules) eq 'HASH') {
4022: if (keys(%{$rules}) > 0) {
4023: push(@options,('official','unofficial'));
4024: }
4025: }
4026: push(@options,'none');
4027: foreach my $option (@options) {
4028: my $type = 'radio';
4029: my $check = ' ';
4030: if ($checked{$item} eq $option) {
4031: $check = ' checked="checked" ';
4032: }
4033: $datatable .= '<span class="LC_nobreak"><label>'.
4034: '<input type="'.$type.'" name="can_createuser_'.
4035: $item.'" value="'.$option.'"'.$check.'/> '.
4036: $lt{$option}.'</label> </span>';
4037: }
4038: $datatable .= '</td></tr>';
4039: }
4040: } else {
4041: my @contexts = ('author','course','domain');
4042: my @authtypes = ('int','krb4','krb5','loc');
4043: my %checked;
4044: if (ref($settings) eq 'HASH') {
4045: if (ref($settings->{'authtypes'}) eq 'HASH') {
4046: foreach my $item (@contexts) {
4047: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
4048: foreach my $auth (@authtypes) {
4049: if ($settings->{'authtypes'}{$item}{$auth}) {
4050: $checked{$item}{$auth} = ' checked="checked" ';
4051: }
4052: }
4053: }
4054: }
4055: }
4056: } else {
4057: foreach my $item (@contexts) {
4058: foreach my $auth (@authtypes) {
4059: $checked{$item}{$auth} = ' checked="checked" ';
4060: }
4061: }
4062: }
4063: my %title = &context_names();
4064: my %authname = &authtype_names();
4065: my $rownum = 0;
4066: my $css_class;
4067: foreach my $item (@contexts) {
4068: if ($rownum%2) {
4069: $css_class = '';
4070: } else {
4071: $css_class = ' class="LC_odd_row" ';
4072: }
4073: $datatable .= '<tr'.$css_class.'>'.
4074: '<td>'.$title{$item}.
4075: '</td><td class="LC_left_item">'.
4076: '<span class="LC_nobreak">';
4077: foreach my $auth (@authtypes) {
4078: $datatable .= '<label>'.
4079: '<input type="checkbox" name="'.$item.'_auth" '.
4080: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4081: $authname{$auth}.'</label> ';
4082: }
4083: $datatable .= '</span></td></tr>';
4084: $rownum ++;
4085: }
4086: $$rowtotal += $rownum;
4087: }
4088: return $datatable;
4089: }
4090:
4091: sub print_selfcreation {
4092: my ($position,$dom,$settings,$rowtotal) = @_;
4093: my (@selfcreate,$createsettings,$processing,$datatable);
4094: if (ref($settings) eq 'HASH') {
4095: if (ref($settings->{'cancreate'}) eq 'HASH') {
4096: $createsettings = $settings->{'cancreate'};
4097: if (ref($createsettings) eq 'HASH') {
4098: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
4099: @selfcreate = @{$createsettings->{'selfcreate'}};
4100: } elsif ($createsettings->{'selfcreate'} ne '') {
4101: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
4102: @selfcreate = ('email','login','sso');
4103: } elsif ($createsettings->{'selfcreate'} ne 'none') {
4104: @selfcreate = ($createsettings->{'selfcreate'});
4105: }
4106: }
4107: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
4108: $processing = $createsettings->{'selfcreateprocessing'};
4109: }
4110: }
4111: }
4112: }
4113: my %radiohash;
4114: my $numinrow = 4;
4115: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
4116: if ($position eq 'top') {
4117: my %choices = &Apache::lonlocal::texthash (
4118: cancreate_login => 'Institutional Login',
4119: cancreate_sso => 'Institutional Single Sign On',
4120: );
4121: my @toggles = sort(keys(%choices));
4122: my %defaultchecked = (
4123: 'cancreate_login' => 'off',
4124: 'cancreate_sso' => 'off',
4125: );
4126: my ($onclick,$itemcount);
4127: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4128: \%choices,$itemcount,$onclick);
4129: $$rowtotal += $itemcount;
4130:
4131: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4132:
4133: if (ref($usertypes) eq 'HASH') {
4134: if (keys(%{$usertypes}) > 0) {
4135: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
4136: $dom,$numinrow,$othertitle,
4137: 'statustocreate',$$rowtotal);
4138: $$rowtotal ++;
4139: }
4140: }
4141: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
4142: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4143: $fieldtitles{'inststatus'} = &mt('Institutional status');
4144: my $rem;
4145: my $numperrow = 2;
4146: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
4147: $datatable .= '<tr'.$css_class.'>'.
4148: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
4149: '<td class="LC_left_item">'."\n".
4150: '<table><tr><td>'."\n";
4151: for (my $i=0; $i<@fields; $i++) {
4152: $rem = $i%($numperrow);
4153: if ($rem == 0) {
4154: if ($i > 0) {
4155: $datatable .= '</tr>';
4156: }
4157: $datatable .= '<tr>';
4158: }
4159: my $currval;
4160: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
4161: $currval = $createsettings->{'shibenv'}{$fields[$i]};
4162: }
4163: $datatable .= '<td class="LC_left_item">'.
4164: '<span class="LC_nobreak">'.
4165: '<input type="text" name="shibenv_'.$fields[$i].'" '.
4166: 'value="'.$currval.'" size="10" /> '.
4167: $fieldtitles{$fields[$i]}.'</span></td>';
4168: }
4169: my $colsleft = $numperrow - $rem;
4170: if ($colsleft > 1 ) {
4171: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4172: ' </td>';
4173: } elsif ($colsleft == 1) {
4174: $datatable .= '<td class="LC_left_item"> </td>';
4175: }
4176: $datatable .= '</tr></table></td></tr>';
4177: $$rowtotal ++;
4178: } elsif ($position eq 'middle') {
4179: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
4180: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4181: $usertypes->{'default'} = $othertitle;
4182: if (ref($types) eq 'ARRAY') {
4183: push(@{$types},'default');
4184: $usertypes->{'default'} = $othertitle;
4185: foreach my $status (@{$types}) {
4186: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
4187: $numinrow,$$rowtotal,$usertypes);
4188: $$rowtotal ++;
4189: }
4190: }
4191: } else {
4192: my %choices = &Apache::lonlocal::texthash (
4193: cancreate_email => 'E-mail address as username',
4194: );
4195: my @toggles = sort(keys(%choices));
4196: my %defaultchecked = (
4197: 'cancreate_email' => 'off',
4198: );
4199: my $itemcount = 0;
4200: my $display = 'none';
4201: if (grep(/^\Qemail\E$/,@selfcreate)) {
4202: $display = 'block';
4203: }
4204: my $onclick = "toggleDisplay(this.form,'emailoptions');";
4205: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
4206: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
4207: my $usertypes = {};
4208: my $order = [];
4209: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
4210: $usertypes = $domdefaults{'inststatustypes'};
4211: $order = $domdefaults{'inststatusguest'};
4212: }
4213: if (ref($order) eq 'ARRAY') {
4214: push(@{$order},'default');
4215: if (@{$order} > 1) {
4216: $usertypes->{'default'} = &mt('Other users');
4217: $additional .= '<table><tr>';
4218: foreach my $status (@{$order}) {
4219: $additional .= '<th>'.$usertypes->{$status}.'</th>';
4220: }
4221: $additional .= '</tr><tr>';
4222: foreach my $status (@{$order}) {
4223: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
4224: }
4225: $additional .= '</tr></table>';
4226: } else {
4227: $usertypes->{'default'} = &mt('All users');
4228: $additional .= &email_as_username($rowtotal,$processing);
4229: }
4230: }
4231: $additional .= '</div>'."\n";
4232:
4233: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4234: \%choices,$$rowtotal,$onclick,$additional);
4235: $$rowtotal ++;
4236: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
4237: $$rowtotal ++;
4238: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4239: $numinrow = 1;
4240: if (ref($order) eq 'ARRAY') {
4241: foreach my $status (@{$order}) {
4242: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
4243: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
4244: $$rowtotal ++;
4245: }
4246: }
4247: my ($emailrules,$emailruleorder) =
4248: &Apache::lonnet::inst_userrules($dom,'email');
4249: if (ref($emailrules) eq 'HASH') {
4250: if (keys(%{$emailrules}) > 0) {
4251: $datatable .= &user_formats_row('email',$settings,$emailrules,
4252: $emailruleorder,$numinrow,$$rowtotal);
4253: $$rowtotal ++;
4254: }
4255: }
4256: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
4257: }
4258: return $datatable;
4259: }
4260:
4261: sub email_as_username {
4262: my ($rowtotal,$processing,$type) = @_;
4263: my %choices =
4264: &Apache::lonlocal::texthash (
4265: automatic => 'Automatic approval',
4266: approval => 'Queued for approval',
4267: );
4268: my $output;
4269: foreach my $option ('automatic','approval') {
4270: my $checked;
4271: if (ref($processing) eq 'HASH') {
4272: if ($type eq '') {
4273: if (!exists($processing->{'default'})) {
4274: if ($option eq 'automatic') {
4275: $checked = ' checked="checked"';
4276: }
4277: } else {
4278: if ($processing->{'default'} eq $option) {
4279: $checked = ' checked="checked"';
4280: }
4281: }
4282: } else {
4283: if (!exists($processing->{$type})) {
4284: if ($option eq 'automatic') {
4285: $checked = ' checked="checked"';
4286: }
4287: } else {
4288: if ($processing->{$type} eq $option) {
4289: $checked = ' checked="checked"';
4290: }
4291: }
4292: }
4293: } elsif ($option eq 'automatic') {
4294: $checked = ' checked="checked"';
4295: }
4296: my $name = 'cancreate_emailprocess';
4297: if (($type ne '') && ($type ne 'default')) {
4298: $name .= '_'.$type;
4299: }
4300: $output .= '<span class="LC_nobreak"><label>'.
4301: '<input type="radio" name="'.$name.'"'.
4302: $checked.' value="'.$option.'" />'.
4303: $choices{$option}.'</label></span>';
4304: if ($type eq '') {
4305: $output .= ' ';
4306: } else {
4307: $output .= '<br />';
4308: }
4309: }
4310: $$rowtotal ++;
4311: return $output;
4312: }
4313:
4314: sub captcha_choice {
4315: my ($context,$settings,$itemcount) = @_;
4316: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
4317: my %lt = &captcha_phrases();
4318: $keyentry = 'hidden';
4319: if ($context eq 'cancreate') {
4320: $rowname = &mt('CAPTCHA validation');
4321: } elsif ($context eq 'login') {
4322: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
4323: }
4324: if (ref($settings) eq 'HASH') {
4325: if ($settings->{'captcha'}) {
4326: $checked{$settings->{'captcha'}} = ' checked="checked"';
4327: } else {
4328: $checked{'original'} = ' checked="checked"';
4329: }
4330: if ($settings->{'captcha'} eq 'recaptcha') {
4331: $pubtext = $lt{'pub'};
4332: $privtext = $lt{'priv'};
4333: $keyentry = 'text';
4334: }
4335: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
4336: $currpub = $settings->{'recaptchakeys'}{'public'};
4337: $currpriv = $settings->{'recaptchakeys'}{'private'};
4338: }
4339: } else {
4340: $checked{'original'} = ' checked="checked"';
4341: }
4342: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4343: my $output = '<tr'.$css_class.'>'.
4344: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
4345: '<table><tr><td>'."\n";
4346: foreach my $option ('original','recaptcha','notused') {
4347: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
4348: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
4349: $lt{$option}.'</label></span>';
4350: unless ($option eq 'notused') {
4351: $output .= (' 'x2)."\n";
4352: }
4353: }
4354: #
4355: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
4356: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
4357: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
4358: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
4359: #
4360: $output .= '</td></tr>'."\n".
4361: '<tr><td>'."\n".
4362: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
4363: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
4364: $currpub.'" size="40" /></span><br />'."\n".
4365: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
4366: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
4367: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
4368: '</td></tr>';
4369: return $output;
4370: }
4371:
4372: sub user_formats_row {
4373: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
4374: my $output;
4375: my %text = (
4376: 'username' => 'new usernames',
4377: 'id' => 'IDs',
4378: 'email' => 'self-created accounts (e-mail)',
4379: );
4380: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4381: $output = '<tr '.$css_class.'>'.
4382: '<td><span class="LC_nobreak">';
4383: if ($type eq 'email') {
4384: $output .= &mt("Formats disallowed for $text{$type}: ");
4385: } else {
4386: $output .= &mt("Format rules to check for $text{$type}: ");
4387: }
4388: $output .= '</span></td>'.
4389: '<td class="LC_left_item" colspan="2"><table>';
4390: my $rem;
4391: if (ref($ruleorder) eq 'ARRAY') {
4392: for (my $i=0; $i<@{$ruleorder}; $i++) {
4393: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
4394: my $rem = $i%($numinrow);
4395: if ($rem == 0) {
4396: if ($i > 0) {
4397: $output .= '</tr>';
4398: }
4399: $output .= '<tr>';
4400: }
4401: my $check = ' ';
4402: if (ref($settings) eq 'HASH') {
4403: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
4404: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
4405: $check = ' checked="checked" ';
4406: }
4407: }
4408: }
4409: $output .= '<td class="LC_left_item">'.
4410: '<span class="LC_nobreak"><label>'.
4411: '<input type="checkbox" name="'.$type.'_rule" '.
4412: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
4413: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
4414: }
4415: }
4416: $rem = @{$ruleorder}%($numinrow);
4417: }
4418: my $colsleft = $numinrow - $rem;
4419: if ($colsleft > 1 ) {
4420: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4421: ' </td>';
4422: } elsif ($colsleft == 1) {
4423: $output .= '<td class="LC_left_item"> </td>';
4424: }
4425: $output .= '</tr></table></td></tr>';
4426: return $output;
4427: }
4428:
4429: sub usercreation_types {
4430: my %lt = &Apache::lonlocal::texthash (
4431: author => 'When adding a co-author',
4432: course => 'When adding a user to a course',
4433: requestcrs => 'When requesting a course',
4434: any => 'Any',
4435: official => 'Institutional only ',
4436: unofficial => 'Non-institutional only',
4437: none => 'None',
4438: );
4439: return %lt;
4440: }
4441:
4442: sub selfcreation_types {
4443: my %lt = &Apache::lonlocal::texthash (
4444: selfcreate => 'User creates own account',
4445: any => 'Any',
4446: official => 'Institutional only ',
4447: unofficial => 'Non-institutional only',
4448: email => 'E-mail address',
4449: login => 'Institutional Login',
4450: sso => 'SSO',
4451: );
4452: }
4453:
4454: sub authtype_names {
4455: my %lt = &Apache::lonlocal::texthash(
4456: int => 'Internal',
4457: krb4 => 'Kerberos 4',
4458: krb5 => 'Kerberos 5',
4459: loc => 'Local',
4460: );
4461: return %lt;
4462: }
4463:
4464: sub context_names {
4465: my %context_title = &Apache::lonlocal::texthash(
4466: author => 'Creating users when an Author',
4467: course => 'Creating users when in a course',
4468: domain => 'Creating users when a Domain Coordinator',
4469: );
4470: return %context_title;
4471: }
4472:
4473: sub print_usermodification {
4474: my ($position,$dom,$settings,$rowtotal) = @_;
4475: my $numinrow = 4;
4476: my ($context,$datatable,$rowcount);
4477: if ($position eq 'top') {
4478: $rowcount = 0;
4479: $context = 'author';
4480: foreach my $role ('ca','aa') {
4481: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4482: $numinrow,$rowcount);
4483: $$rowtotal ++;
4484: $rowcount ++;
4485: }
4486: } elsif ($position eq 'bottom') {
4487: $context = 'course';
4488: $rowcount = 0;
4489: foreach my $role ('st','ep','ta','in','cr') {
4490: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4491: $numinrow,$rowcount);
4492: $$rowtotal ++;
4493: $rowcount ++;
4494: }
4495: }
4496: return $datatable;
4497: }
4498:
4499: sub print_defaults {
4500: my ($position,$dom,$settings,$rowtotal) = @_;
4501: my $rownum = 0;
4502: my ($datatable,$css_class);
4503: if ($position eq 'top') {
4504: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
4505: 'datelocale_def','portal_def');
4506: my %defaults;
4507: if (ref($settings) eq 'HASH') {
4508: %defaults = %{$settings};
4509: } else {
4510: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
4511: foreach my $item (@items) {
4512: $defaults{$item} = $domdefaults{$item};
4513: }
4514: }
4515: my $titles = &defaults_titles($dom);
4516: foreach my $item (@items) {
4517: if ($rownum%2) {
4518: $css_class = '';
4519: } else {
4520: $css_class = ' class="LC_odd_row" ';
4521: }
4522: $datatable .= '<tr'.$css_class.'>'.
4523: '<td><span class="LC_nobreak">'.$titles->{$item}.
4524: '</span></td><td class="LC_right_item" colspan="3">';
4525: if ($item eq 'auth_def') {
4526: my @authtypes = ('internal','krb4','krb5','localauth');
4527: my %shortauth = (
4528: internal => 'int',
4529: krb4 => 'krb4',
4530: krb5 => 'krb5',
4531: localauth => 'loc'
4532: );
4533: my %authnames = &authtype_names();
4534: foreach my $auth (@authtypes) {
4535: my $checked = ' ';
4536: if ($defaults{$item} eq $auth) {
4537: $checked = ' checked="checked" ';
4538: }
4539: $datatable .= '<label><input type="radio" name="'.$item.
4540: '" value="'.$auth.'"'.$checked.'/>'.
4541: $authnames{$shortauth{$auth}}.'</label> ';
4542: }
4543: } elsif ($item eq 'timezone_def') {
4544: my $includeempty = 1;
4545: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
4546: } elsif ($item eq 'datelocale_def') {
4547: my $includeempty = 1;
4548: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
4549: } elsif ($item eq 'lang_def') {
4550: my %langchoices = &get_languages_hash();
4551: $langchoices{''} = 'No language preference';
4552: %langchoices = &Apache::lonlocal::texthash(%langchoices);
4553: $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,
4554: \%langchoices);
4555: } else {
4556: my $size;
4557: if ($item eq 'portal_def') {
4558: $size = ' size="25"';
4559: }
4560: $datatable .= '<input type="text" name="'.$item.'" value="'.
4561: $defaults{$item}.'"'.$size.' />';
4562: }
4563: $datatable .= '</td></tr>';
4564: $rownum ++;
4565: }
4566: } else {
4567: my (%defaults);
4568: if (ref($settings) eq 'HASH') {
4569: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
4570: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
4571: my $maxnum = @{$settings->{'inststatusorder'}};
4572: for (my $i=0; $i<$maxnum; $i++) {
4573: $css_class = $rownum%2?' class="LC_odd_row"':'';
4574: my $item = $settings->{'inststatusorder'}->[$i];
4575: my $title = $settings->{'inststatustypes'}->{$item};
4576: my $guestok;
4577: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
4578: $guestok = 1;
4579: }
4580: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
4581: $datatable .= '<tr'.$css_class.'>'.
4582: '<td><span class="LC_nobreak">'.
4583: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
4584: for (my $k=0; $k<=$maxnum; $k++) {
4585: my $vpos = $k+1;
4586: my $selstr;
4587: if ($k == $i) {
4588: $selstr = ' selected="selected" ';
4589: }
4590: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4591: }
4592: my ($checkedon,$checkedoff);
4593: $checkedoff = ' checked="checked"';
4594: if ($guestok) {
4595: $checkedon = $checkedoff;
4596: $checkedoff = '';
4597: }
4598: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
4599: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
4600: &mt('delete').'</span></td>'.
4601: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
4602: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
4603: '</span></td>'.
4604: '<td class="LC_right_item"><span class="LC_nobreak">'.
4605: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
4606: &mt('Yes').'</label>'.(' 'x2).
4607: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
4608: &mt('No').'</label></span></td></tr>';
4609: }
4610: $css_class = $rownum%2?' class="LC_odd_row"':'';
4611: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
4612: $datatable .= '<tr '.$css_class.'>'.
4613: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
4614: for (my $k=0; $k<=$maxnum; $k++) {
4615: my $vpos = $k+1;
4616: my $selstr;
4617: if ($k == $maxnum) {
4618: $selstr = ' selected="selected" ';
4619: }
4620: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4621: }
4622: $datatable .= '</select> '.&mt('Internal ID:').
4623: '<input type="text" size="10" name="addinststatus" value="" /></span>'.
4624: ' '.&mt('(new)').
4625: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
4626: &mt('Name displayed:').
4627: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
4628: '<td class="LC_right_item"><span class="LC_nobreak">'.
4629: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
4630: &mt('Yes').'</label>'.(' 'x2).
4631: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
4632: &mt('No').'</label></span></td></tr>';
4633: '</tr>'."\n";
4634: $rownum ++;
4635: }
4636: }
4637: }
4638: $$rowtotal += $rownum;
4639: return $datatable;
4640: }
4641:
4642: sub get_languages_hash {
4643: my %langchoices;
4644: foreach my $id (&Apache::loncommon::languageids()) {
4645: my $code = &Apache::loncommon::supportedlanguagecode($id);
4646: if ($code ne '') {
4647: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
4648: }
4649: }
4650: return %langchoices;
4651: }
4652:
4653: sub defaults_titles {
4654: my ($dom) = @_;
4655: my %titles = &Apache::lonlocal::texthash (
4656: 'auth_def' => 'Default authentication type',
4657: 'auth_arg_def' => 'Default authentication argument',
4658: 'lang_def' => 'Default language',
4659: 'timezone_def' => 'Default timezone',
4660: 'datelocale_def' => 'Default locale for dates',
4661: 'portal_def' => 'Portal/Default URL',
4662: );
4663: if ($dom) {
4664: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
4665: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
4666: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
4667: $protocol = 'http' if ($protocol ne 'https');
4668: if ($uint_dom) {
4669: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
4670: $uint_dom);
4671: }
4672: }
4673: return (\%titles);
4674: }
4675:
4676: sub print_scantronformat {
4677: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
4678: my $itemcount = 1;
4679: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
4680: %confhash);
4681: my $switchserver = &check_switchserver($dom,$confname);
4682: my %lt = &Apache::lonlocal::texthash (
4683: default => 'Default bubblesheet format file error',
4684: custom => 'Custom bubblesheet format file error',
4685: );
4686: my %scantronfiles = (
4687: default => 'default.tab',
4688: custom => 'custom.tab',
4689: );
4690: foreach my $key (keys(%scantronfiles)) {
4691: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
4692: .$scantronfiles{$key};
4693: }
4694: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
4695: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
4696: if (!$switchserver) {
4697: my $servadm = $r->dir_config('lonAdmEMail');
4698: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
4699: if ($configuserok eq 'ok') {
4700: if ($author_ok eq 'ok') {
4701: my %legacyfile = (
4702: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
4703: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
4704: );
4705: my %md5chk;
4706: foreach my $type (keys(%legacyfile)) {
4707: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
4708: chomp($md5chk{$type});
4709: }
4710: if ($md5chk{'default'} ne $md5chk{'custom'}) {
4711: foreach my $type (keys(%legacyfile)) {
4712: ($scantronurls{$type},my $error) =
4713: &legacy_scantronformat($r,$dom,$confname,
4714: $type,$legacyfile{$type},
4715: $scantronurls{$type},
4716: $scantronfiles{$type});
4717: if ($error ne '') {
4718: $error{$type} = $error;
4719: }
4720: }
4721: if (keys(%error) == 0) {
4722: $is_custom = 1;
4723: $confhash{'scantron'}{'scantronformat'} =
4724: $scantronurls{'custom'};
4725: my $putresult =
4726: &Apache::lonnet::put_dom('configuration',
4727: \%confhash,$dom);
4728: if ($putresult ne 'ok') {
4729: $error{'custom'} =
4730: '<span class="LC_error">'.
4731: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4732: }
4733: }
4734: } else {
4735: ($scantronurls{'default'},my $error) =
4736: &legacy_scantronformat($r,$dom,$confname,
4737: 'default',$legacyfile{'default'},
4738: $scantronurls{'default'},
4739: $scantronfiles{'default'});
4740: if ($error eq '') {
4741: $confhash{'scantron'}{'scantronformat'} = '';
4742: my $putresult =
4743: &Apache::lonnet::put_dom('configuration',
4744: \%confhash,$dom);
4745: if ($putresult ne 'ok') {
4746: $error{'default'} =
4747: '<span class="LC_error">'.
4748: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4749: }
4750: } else {
4751: $error{'default'} = $error;
4752: }
4753: }
4754: }
4755: }
4756: } else {
4757: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
4758: }
4759: }
4760: if (ref($settings) eq 'HASH') {
4761: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
4762: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
4763: if ((!@info) || ($info[0] eq 'no_such_dir')) {
4764: $scantronurl = '';
4765: } else {
4766: $scantronurl = $settings->{'scantronformat'};
4767: }
4768: $is_custom = 1;
4769: } else {
4770: $scantronurl = $scantronurls{'default'};
4771: }
4772: } else {
4773: if ($is_custom) {
4774: $scantronurl = $scantronurls{'custom'};
4775: } else {
4776: $scantronurl = $scantronurls{'default'};
4777: }
4778: }
4779: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4780: $datatable .= '<tr'.$css_class.'>';
4781: if (!$is_custom) {
4782: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
4783: '<span class="LC_nobreak">';
4784: if ($scantronurl) {
4785: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
4786: undef,undef,undef,undef,'background-color:#ffffff');
4787: } else {
4788: $datatable = &mt('File unavailable for display');
4789: }
4790: $datatable .= '</span></td>';
4791: if (keys(%error) == 0) {
4792: $datatable .= '<td valign="bottom">';
4793: if (!$switchserver) {
4794: $datatable .= &mt('Upload:').'<br />';
4795: }
4796: } else {
4797: my $errorstr;
4798: foreach my $key (sort(keys(%error))) {
4799: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4800: }
4801: $datatable .= '<td>'.$errorstr;
4802: }
4803: } else {
4804: if (keys(%error) > 0) {
4805: my $errorstr;
4806: foreach my $key (sort(keys(%error))) {
4807: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4808: }
4809: $datatable .= '<td>'.$errorstr.'</td><td> ';
4810: } elsif ($scantronurl) {
4811: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
4812: undef,undef,undef,undef,'background-color:#ffffff');
4813: $datatable .= '<td><span class="LC_nobreak">'.
4814: $link.
4815: '<label><input type="checkbox" name="scantronformat_del"'.
4816: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
4817: '<td><span class="LC_nobreak"> '.
4818: &mt('Replace:').'</span><br />';
4819: }
4820: }
4821: if (keys(%error) == 0) {
4822: if ($switchserver) {
4823: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4824: } else {
4825: $datatable .='<span class="LC_nobreak"> '.
4826: '<input type="file" name="scantronformat" /></span>';
4827: }
4828: }
4829: $datatable .= '</td></tr>';
4830: $$rowtotal ++;
4831: return $datatable;
4832: }
4833:
4834: sub legacy_scantronformat {
4835: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
4836: my ($url,$error);
4837: my @statinfo = &Apache::lonnet::stat_file($newurl);
4838: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
4839: (my $result,$url) =
4840: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
4841: '','',$newfile);
4842: if ($result ne 'ok') {
4843: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
4844: }
4845: }
4846: return ($url,$error);
4847: }
4848:
4849: sub print_coursecategories {
4850: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
4851: my $datatable;
4852: if ($position eq 'top') {
4853: my (%checked);
4854: my @catitems = ('unauth','auth');
4855: my @cattypes = ('std','domonly','codesrch','none');
4856: $checked{'unauth'} = 'std';
4857: $checked{'auth'} = 'std';
4858: if (ref($settings) eq 'HASH') {
4859: foreach my $type (@cattypes) {
4860: if ($type eq $settings->{'unauth'}) {
4861: $checked{'unauth'} = $type;
4862: }
4863: if ($type eq $settings->{'auth'}) {
4864: $checked{'auth'} = $type;
4865: }
4866: }
4867: }
4868: my %lt = &Apache::lonlocal::texthash (
4869: unauth => 'Catalog type for unauthenticated users',
4870: auth => 'Catalog type for authenticated users',
4871: none => 'No catalog',
4872: std => 'Standard catalog',
4873: domonly => 'Domain-only catalog',
4874: codesrch => "Code search form",
4875: );
4876: my $itemcount = 0;
4877: foreach my $item (@catitems) {
4878: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
4879: $datatable .= '<tr '.$css_class.'>'.
4880: '<td>'.$lt{$item}.'</td>'.
4881: '<td class="LC_right_item"><span class="LC_nobreak">';
4882: foreach my $type (@cattypes) {
4883: my $ischecked;
4884: if ($checked{$item} eq $type) {
4885: $ischecked=' checked="checked"';
4886: }
4887: $datatable .= '<label>'.
4888: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
4889: ' />'.$lt{$type}.'</label> ';
4890: }
4891: $datatable .= '</td></tr>';
4892: $itemcount ++;
4893: }
4894: $$rowtotal += $itemcount;
4895: } elsif ($position eq 'middle') {
4896: my $toggle_cats_crs = ' ';
4897: my $toggle_cats_dom = ' checked="checked" ';
4898: my $can_cat_crs = ' ';
4899: my $can_cat_dom = ' checked="checked" ';
4900: my $toggle_catscomm_comm = ' ';
4901: my $toggle_catscomm_dom = ' checked="checked" ';
4902: my $can_catcomm_comm = ' ';
4903: my $can_catcomm_dom = ' checked="checked" ';
4904:
4905: if (ref($settings) eq 'HASH') {
4906: if ($settings->{'togglecats'} eq 'crs') {
4907: $toggle_cats_crs = $toggle_cats_dom;
4908: $toggle_cats_dom = ' ';
4909: }
4910: if ($settings->{'categorize'} eq 'crs') {
4911: $can_cat_crs = $can_cat_dom;
4912: $can_cat_dom = ' ';
4913: }
4914: if ($settings->{'togglecatscomm'} eq 'comm') {
4915: $toggle_catscomm_comm = $toggle_catscomm_dom;
4916: $toggle_catscomm_dom = ' ';
4917: }
4918: if ($settings->{'categorizecomm'} eq 'comm') {
4919: $can_catcomm_comm = $can_catcomm_dom;
4920: $can_catcomm_dom = ' ';
4921: }
4922: }
4923: my %title = &Apache::lonlocal::texthash (
4924: togglecats => 'Show/Hide a course in catalog',
4925: togglecatscomm => 'Show/Hide a community in catalog',
4926: categorize => 'Assign a category to a course',
4927: categorizecomm => 'Assign a category to a community',
4928: );
4929: my %level = &Apache::lonlocal::texthash (
4930: dom => 'Set in Domain',
4931: crs => 'Set in Course',
4932: comm => 'Set in Community',
4933: );
4934: $datatable = '<tr class="LC_odd_row">'.
4935: '<td>'.$title{'togglecats'}.'</td>'.
4936: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4937: '<input type="radio" name="togglecats"'.
4938: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4939: '<label><input type="radio" name="togglecats"'.
4940: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
4941: '</tr><tr>'.
4942: '<td>'.$title{'categorize'}.'</td>'.
4943: '<td class="LC_right_item"><span class="LC_nobreak">'.
4944: '<label><input type="radio" name="categorize"'.
4945: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4946: '<label><input type="radio" name="categorize"'.
4947: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
4948: '</tr><tr class="LC_odd_row">'.
4949: '<td>'.$title{'togglecatscomm'}.'</td>'.
4950: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4951: '<input type="radio" name="togglecatscomm"'.
4952: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4953: '<label><input type="radio" name="togglecatscomm"'.
4954: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4955: '</tr><tr>'.
4956: '<td>'.$title{'categorizecomm'}.'</td>'.
4957: '<td class="LC_right_item"><span class="LC_nobreak">'.
4958: '<label><input type="radio" name="categorizecomm"'.
4959: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4960: '<label><input type="radio" name="categorizecomm"'.
4961: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
4962: '</tr>';
4963: $$rowtotal += 4;
4964: } else {
4965: my $css_class;
4966: my $itemcount = 1;
4967: my $cathash;
4968: if (ref($settings) eq 'HASH') {
4969: $cathash = $settings->{'cats'};
4970: }
4971: if (ref($cathash) eq 'HASH') {
4972: my (@cats,@trails,%allitems,%idx,@jsarray);
4973: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4974: \%allitems,\%idx,\@jsarray);
4975: my $maxdepth = scalar(@cats);
4976: my $colattrib = '';
4977: if ($maxdepth > 2) {
4978: $colattrib = ' colspan="2" ';
4979: }
4980: my @path;
4981: if (@cats > 0) {
4982: if (ref($cats[0]) eq 'ARRAY') {
4983: my $numtop = @{$cats[0]};
4984: my $maxnum = $numtop;
4985: my %default_names = (
4986: instcode => &mt('Official courses'),
4987: communities => &mt('Communities'),
4988: );
4989:
4990: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4991: ($cathash->{'instcode::0'} eq '') ||
4992: (!grep(/^communities$/,@{$cats[0]})) ||
4993: ($cathash->{'communities::0'} eq '')) {
4994: $maxnum ++;
4995: }
4996: my $lastidx;
4997: for (my $i=0; $i<$numtop; $i++) {
4998: my $parent = $cats[0][$i];
4999: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5000: my $item = &escape($parent).'::0';
5001: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
5002: $lastidx = $idx{$item};
5003: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5004: .'<select name="'.$item.'"'.$chgstr.'>';
5005: for (my $k=0; $k<=$maxnum; $k++) {
5006: my $vpos = $k+1;
5007: my $selstr;
5008: if ($k == $i) {
5009: $selstr = ' selected="selected" ';
5010: }
5011: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5012: }
5013: $datatable .= '</select></span></td><td>';
5014: if ($parent eq 'instcode' || $parent eq 'communities') {
5015: $datatable .= '<span class="LC_nobreak">'
5016: .$default_names{$parent}.'</span>';
5017: if ($parent eq 'instcode') {
5018: $datatable .= '<br /><span class="LC_nobreak">('
5019: .&mt('with institutional codes')
5020: .')</span></td><td'.$colattrib.'>';
5021: } else {
5022: $datatable .= '<table><tr><td>';
5023: }
5024: $datatable .= '<span class="LC_nobreak">'
5025: .'<label><input type="radio" name="'
5026: .$parent.'" value="1" checked="checked" />'
5027: .&mt('Display').'</label>';
5028: if ($parent eq 'instcode') {
5029: $datatable .= ' ';
5030: } else {
5031: $datatable .= '</span></td></tr><tr><td>'
5032: .'<span class="LC_nobreak">';
5033: }
5034: $datatable .= '<label><input type="radio" name="'
5035: .$parent.'" value="0" />'
5036: .&mt('Do not display').'</label></span>';
5037: if ($parent eq 'communities') {
5038: $datatable .= '</td></tr></table>';
5039: }
5040: $datatable .= '</td>';
5041: } else {
5042: $datatable .= $parent
5043: .' <span class="LC_nobreak"><label>'
5044: .'<input type="checkbox" name="deletecategory" '
5045: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
5046: }
5047: my $depth = 1;
5048: push(@path,$parent);
5049: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
5050: pop(@path);
5051: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
5052: $itemcount ++;
5053: }
5054: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5055: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
5056: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
5057: for (my $k=0; $k<=$maxnum; $k++) {
5058: my $vpos = $k+1;
5059: my $selstr;
5060: if ($k == $numtop) {
5061: $selstr = ' selected="selected" ';
5062: }
5063: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5064: }
5065: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
5066: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
5067: .'</tr>'."\n";
5068: $itemcount ++;
5069: foreach my $default ('instcode','communities') {
5070: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
5071: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5072: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
5073: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
5074: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
5075: for (my $k=0; $k<=$maxnum; $k++) {
5076: my $vpos = $k+1;
5077: my $selstr;
5078: if ($k == $maxnum) {
5079: $selstr = ' selected="selected" ';
5080: }
5081: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5082: }
5083: $datatable .= '</select></span></td>'.
5084: '<td><span class="LC_nobreak">'.
5085: $default_names{$default}.'</span>';
5086: if ($default eq 'instcode') {
5087: $datatable .= '<br /><span class="LC_nobreak">('
5088: .&mt('with institutional codes').')</span>';
5089: }
5090: $datatable .= '</td>'
5091: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
5092: .&mt('Display').'</label> '
5093: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
5094: .&mt('Do not display').'</label></span></td></tr>';
5095: }
5096: }
5097: }
5098: } else {
5099: $datatable .= &initialize_categories($itemcount);
5100: }
5101: } else {
5102: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
5103: .&initialize_categories($itemcount);
5104: }
5105: $$rowtotal += $itemcount;
5106: }
5107: return $datatable;
5108: }
5109:
5110: sub print_serverstatuses {
5111: my ($dom,$settings,$rowtotal) = @_;
5112: my $datatable;
5113: my @pages = &serverstatus_pages();
5114: my (%namedaccess,%machineaccess);
5115: foreach my $type (@pages) {
5116: $namedaccess{$type} = '';
5117: $machineaccess{$type}= '';
5118: }
5119: if (ref($settings) eq 'HASH') {
5120: foreach my $type (@pages) {
5121: if (exists($settings->{$type})) {
5122: if (ref($settings->{$type}) eq 'HASH') {
5123: foreach my $key (keys(%{$settings->{$type}})) {
5124: if ($key eq 'namedusers') {
5125: $namedaccess{$type} = $settings->{$type}->{$key};
5126: } elsif ($key eq 'machines') {
5127: $machineaccess{$type} = $settings->{$type}->{$key};
5128: }
5129: }
5130: }
5131: }
5132: }
5133: }
5134: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
5135: my $rownum = 0;
5136: my $css_class;
5137: foreach my $type (@pages) {
5138: $rownum ++;
5139: $css_class = $rownum%2?' class="LC_odd_row"':'';
5140: $datatable .= '<tr'.$css_class.'>'.
5141: '<td><span class="LC_nobreak">'.
5142: $titles->{$type}.'</span></td>'.
5143: '<td class="LC_left_item">'.
5144: '<input type="text" name="'.$type.'_namedusers" '.
5145: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
5146: '<td class="LC_right_item">'.
5147: '<span class="LC_nobreak">'.
5148: '<input type="text" name="'.$type.'_machines" '.
5149: 'value="'.$machineaccess{$type}.'" size="10" />'.
5150: '</td></tr>'."\n";
5151: }
5152: $$rowtotal += $rownum;
5153: return $datatable;
5154: }
5155:
5156: sub serverstatus_pages {
5157: return ('userstatus','lonstatus','loncron','server-status','codeversions',
5158: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
5159: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
5160: 'uniquecodes','diskusage');
5161: }
5162:
5163: sub defaults_javascript {
5164: my ($settings) = @_;
5165: my ($output,$jstext);
5166: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
5167: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
5168: if ($maxnum eq '') {
5169: $maxnum = 0;
5170: }
5171: $maxnum ++;
5172: $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
5173: return <<"ENDSCRIPT";
5174: <script type="text/javascript">
5175: // <![CDATA[
5176: function reorderTypes(form,caller) {
5177: var changedVal;
5178: $jstext
5179: var newpos = 'addinststatus_pos';
5180: var current = new Array;
5181: var maxh = $maxnum;
5182: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5183: var oldVal;
5184: if (caller == newpos) {
5185: changedVal = newitemVal;
5186: } else {
5187: var curritem = 'inststatus_pos_'+caller;
5188: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
5189: current[newitemVal] = newpos;
5190: }
5191: for (var i=0; i<inststatuses.length; i++) {
5192: if (inststatuses[i] != caller) {
5193: var elementName = 'inststatus_pos_'+inststatuses[i];
5194: if (form.elements[elementName]) {
5195: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5196: current[currVal] = elementName;
5197: }
5198: }
5199: }
5200: for (var j=0; j<maxh; j++) {
5201: if (current[j] == undefined) {
5202: oldVal = j;
5203: }
5204: }
5205: if (oldVal < changedVal) {
5206: for (var k=oldVal+1; k<=changedVal ; k++) {
5207: var elementName = current[k];
5208: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5209: }
5210: } else {
5211: for (var k=changedVal; k<oldVal; k++) {
5212: var elementName = current[k];
5213: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5214: }
5215: }
5216: return;
5217: }
5218:
5219: // ]]>
5220: </script>
5221:
5222: ENDSCRIPT
5223: }
5224: }
5225:
5226: sub coursecategories_javascript {
5227: my ($settings) = @_;
5228: my ($output,$jstext,$cathash);
5229: if (ref($settings) eq 'HASH') {
5230: $cathash = $settings->{'cats'};
5231: }
5232: if (ref($cathash) eq 'HASH') {
5233: my (@cats,@jsarray,%idx);
5234: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
5235: if (@jsarray > 0) {
5236: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
5237: for (my $i=0; $i<@jsarray; $i++) {
5238: if (ref($jsarray[$i]) eq 'ARRAY') {
5239: my $catstr = join('","',@{$jsarray[$i]});
5240: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
5241: }
5242: }
5243: }
5244: } else {
5245: $jstext = ' var categories = Array(1);'."\n".
5246: ' categories[0] = Array("instcode_pos");'."\n";
5247: }
5248: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
5249: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
5250: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category.');
5251: $output = <<"ENDSCRIPT";
5252: <script type="text/javascript">
5253: // <![CDATA[
5254: function reorderCats(form,parent,item,idx) {
5255: var changedVal;
5256: $jstext
5257: var newpos = 'addcategory_pos';
5258: if (parent == '') {
5259: var has_instcode = 0;
5260: var maxtop = categories[idx].length;
5261: for (var j=0; j<maxtop; j++) {
5262: if (categories[idx][j] == 'instcode::0') {
5263: has_instcode == 1;
5264: }
5265: }
5266: if (has_instcode == 0) {
5267: categories[idx][maxtop] = 'instcode_pos';
5268: }
5269: } else {
5270: newpos += '_'+parent;
5271: }
5272: var maxh = 1 + categories[idx].length;
5273: var current = new Array;
5274: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5275: if (item == newpos) {
5276: changedVal = newitemVal;
5277: } else {
5278: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5279: current[newitemVal] = newpos;
5280: }
5281: for (var i=0; i<categories[idx].length; i++) {
5282: var elementName = categories[idx][i];
5283: if (elementName != item) {
5284: if (form.elements[elementName]) {
5285: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5286: current[currVal] = elementName;
5287: }
5288: }
5289: }
5290: var oldVal;
5291: for (var j=0; j<maxh; j++) {
5292: if (current[j] == undefined) {
5293: oldVal = j;
5294: }
5295: }
5296: if (oldVal < changedVal) {
5297: for (var k=oldVal+1; k<=changedVal ; k++) {
5298: var elementName = current[k];
5299: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5300: }
5301: } else {
5302: for (var k=changedVal; k<oldVal; k++) {
5303: var elementName = current[k];
5304: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5305: }
5306: }
5307: return;
5308: }
5309:
5310: function categoryCheck(form) {
5311: if (form.elements['addcategory_name'].value == 'instcode') {
5312: alert('$instcode_reserved\\n$choose_again');
5313: return false;
5314: }
5315: if (form.elements['addcategory_name'].value == 'communities') {
5316: alert('$communities_reserved\\n$choose_again');
5317: return false;
5318: }
5319: return true;
5320: }
5321:
5322: // ]]>
5323: </script>
5324:
5325: ENDSCRIPT
5326: return $output;
5327: }
5328:
5329: sub initialize_categories {
5330: my ($itemcount) = @_;
5331: my ($datatable,$css_class,$chgstr);
5332: my %default_names = (
5333: instcode => 'Official courses (with institutional codes)',
5334: communities => 'Communities',
5335: );
5336: my $select0 = ' selected="selected"';
5337: my $select1 = '';
5338: foreach my $default ('instcode','communities') {
5339: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5340: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
5341: if ($default eq 'communities') {
5342: $select1 = $select0;
5343: $select0 = '';
5344: }
5345: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5346: .'<select name="'.$default.'_pos">'
5347: .'<option value="0"'.$select0.'>1</option>'
5348: .'<option value="1"'.$select1.'>2</option>'
5349: .'<option value="2">3</option></select> '
5350: .$default_names{$default}
5351: .'</span></td><td><span class="LC_nobreak">'
5352: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
5353: .&mt('Display').'</label> <label>'
5354: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
5355: .'</label></span></td></tr>';
5356: $itemcount ++;
5357: }
5358: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5359: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
5360: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5361: .'<select name="addcategory_pos"'.$chgstr.'>'
5362: .'<option value="0">1</option>'
5363: .'<option value="1">2</option>'
5364: .'<option value="2" selected="selected">3</option></select> '
5365: .&mt('Add category').'</td><td>'.&mt('Name:')
5366: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
5367: return $datatable;
5368: }
5369:
5370: sub build_category_rows {
5371: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
5372: my ($text,$name,$item,$chgstr);
5373: if (ref($cats) eq 'ARRAY') {
5374: my $maxdepth = scalar(@{$cats});
5375: if (ref($cats->[$depth]) eq 'HASH') {
5376: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
5377: my $numchildren = @{$cats->[$depth]{$parent}};
5378: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
5379: $text .= '<td><table class="LC_data_table">';
5380: my ($idxnum,$parent_name,$parent_item);
5381: my $higher = $depth - 1;
5382: if ($higher == 0) {
5383: $parent_name = &escape($parent).'::'.$higher;
5384: } else {
5385: if (ref($path) eq 'ARRAY') {
5386: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5387: }
5388: }
5389: $parent_item = 'addcategory_pos_'.$parent_name;
5390: for (my $j=0; $j<=$numchildren; $j++) {
5391: if ($j < $numchildren) {
5392: $name = $cats->[$depth]{$parent}[$j];
5393: $item = &escape($name).':'.&escape($parent).':'.$depth;
5394: $idxnum = $idx->{$item};
5395: } else {
5396: $name = $parent_name;
5397: $item = $parent_item;
5398: }
5399: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
5400: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
5401: for (my $i=0; $i<=$numchildren; $i++) {
5402: my $vpos = $i+1;
5403: my $selstr;
5404: if ($j == $i) {
5405: $selstr = ' selected="selected" ';
5406: }
5407: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
5408: }
5409: $text .= '</select> ';
5410: if ($j < $numchildren) {
5411: my $deeper = $depth+1;
5412: $text .= $name.' '
5413: .'<label><input type="checkbox" name="deletecategory" value="'
5414: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
5415: if(ref($path) eq 'ARRAY') {
5416: push(@{$path},$name);
5417: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
5418: pop(@{$path});
5419: }
5420: } else {
5421: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
5422: if ($j == $numchildren) {
5423: $text .= $name;
5424: } else {
5425: $text .= $item;
5426: }
5427: $text .= '" value="" />';
5428: }
5429: $text .= '</td></tr>';
5430: }
5431: $text .= '</table></td>';
5432: } else {
5433: my $higher = $depth-1;
5434: if ($higher == 0) {
5435: $name = &escape($parent).'::'.$higher;
5436: } else {
5437: if (ref($path) eq 'ARRAY') {
5438: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5439: }
5440: }
5441: my $colspan;
5442: if ($parent ne 'instcode') {
5443: $colspan = $maxdepth - $depth - 1;
5444: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
5445: }
5446: }
5447: }
5448: }
5449: return $text;
5450: }
5451:
5452: sub modifiable_userdata_row {
5453: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
5454: my ($role,$rolename,$statustype);
5455: $role = $item;
5456: if ($context eq 'cancreate') {
5457: if ($item =~ /^emailusername_(.+)$/) {
5458: $statustype = $1;
5459: $role = 'emailusername';
5460: if (ref($usertypes) eq 'HASH') {
5461: if ($usertypes->{$statustype}) {
5462: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
5463: } else {
5464: $rolename = &mt('Data provided by user');
5465: }
5466: }
5467: }
5468: } elsif ($context eq 'selfcreate') {
5469: if (ref($usertypes) eq 'HASH') {
5470: $rolename = $usertypes->{$role};
5471: } else {
5472: $rolename = $role;
5473: }
5474: } else {
5475: if ($role eq 'cr') {
5476: $rolename = &mt('Custom role');
5477: } else {
5478: $rolename = &Apache::lonnet::plaintext($role);
5479: }
5480: }
5481: my (@fields,%fieldtitles);
5482: if (ref($fieldsref) eq 'ARRAY') {
5483: @fields = @{$fieldsref};
5484: } else {
5485: @fields = ('lastname','firstname','middlename','generation',
5486: 'permanentemail','id');
5487: }
5488: if ((ref($titlesref) eq 'HASH')) {
5489: %fieldtitles = %{$titlesref};
5490: } else {
5491: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5492: }
5493: my $output;
5494: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5495: $output = '<tr '.$css_class.'>'.
5496: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
5497: '<td class="LC_left_item" colspan="2"><table>';
5498: my $rem;
5499: my %checks;
5500: if (ref($settings) eq 'HASH') {
5501: if (ref($settings->{$context}) eq 'HASH') {
5502: if (ref($settings->{$context}->{$role}) eq 'HASH') {
5503: my $hashref = $settings->{$context}->{$role};
5504: if ($role eq 'emailusername') {
5505: if ($statustype) {
5506: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
5507: $hashref = $settings->{$context}->{$role}->{$statustype};
5508: if (ref($hashref) eq 'HASH') {
5509: foreach my $field (@fields) {
5510: if ($hashref->{$field}) {
5511: $checks{$field} = $hashref->{$field};
5512: }
5513: }
5514: }
5515: }
5516: }
5517: } else {
5518: if (ref($hashref) eq 'HASH') {
5519: foreach my $field (@fields) {
5520: if ($hashref->{$field}) {
5521: $checks{$field} = ' checked="checked" ';
5522: }
5523: }
5524: }
5525: }
5526: }
5527: }
5528: }
5529:
5530: for (my $i=0; $i<@fields; $i++) {
5531: my $rem = $i%($numinrow);
5532: if ($rem == 0) {
5533: if ($i > 0) {
5534: $output .= '</tr>';
5535: }
5536: $output .= '<tr>';
5537: }
5538: my $check = ' ';
5539: unless ($role eq 'emailusername') {
5540: if (exists($checks{$fields[$i]})) {
5541: $check = $checks{$fields[$i]}
5542: } else {
5543: if ($role eq 'st') {
5544: if (ref($settings) ne 'HASH') {
5545: $check = ' checked="checked" ';
5546: }
5547: }
5548: }
5549: }
5550: $output .= '<td class="LC_left_item">'.
5551: '<span class="LC_nobreak">';
5552: if ($role eq 'emailusername') {
5553: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
5554: $checks{$fields[$i]} = 'omit';
5555: }
5556: foreach my $option ('required','optional','omit') {
5557: my $checked='';
5558: if ($checks{$fields[$i]} eq $option) {
5559: $checked='checked="checked" ';
5560: }
5561: $output .= '<label>'.
5562: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
5563: &mt($option).'</label>'.(' ' x2);
5564: }
5565: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
5566: } else {
5567: $output .= '<label>'.
5568: '<input type="checkbox" name="canmodify_'.$role.'" '.
5569: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
5570: '</label>';
5571: }
5572: $output .= '</span></td>';
5573: $rem = @fields%($numinrow);
5574: }
5575: my $colsleft = $numinrow - $rem;
5576: if ($colsleft > 1 ) {
5577: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5578: ' </td>';
5579: } elsif ($colsleft == 1) {
5580: $output .= '<td class="LC_left_item"> </td>';
5581: }
5582: $output .= '</tr></table></td></tr>';
5583: return $output;
5584: }
5585:
5586: sub insttypes_row {
5587: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
5588: my %lt = &Apache::lonlocal::texthash (
5589: cansearch => 'Users allowed to search',
5590: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
5591: lockablenames => 'User preference to lock name',
5592: );
5593: my $showdom;
5594: if ($context eq 'cansearch') {
5595: $showdom = ' ('.$dom.')';
5596: }
5597: my $class = 'LC_left_item';
5598: if ($context eq 'statustocreate') {
5599: $class = 'LC_right_item';
5600: }
5601: my $css_class = ' class="LC_odd_row"';
5602: if ($rownum ne '') {
5603: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
5604: }
5605: my $output = '<tr'.$css_class.'>'.
5606: '<td>'.$lt{$context}.$showdom.
5607: '</td><td class="'.$class.'" colspan="2"><table>';
5608: my $rem;
5609: if (ref($types) eq 'ARRAY') {
5610: for (my $i=0; $i<@{$types}; $i++) {
5611: if (defined($usertypes->{$types->[$i]})) {
5612: my $rem = $i%($numinrow);
5613: if ($rem == 0) {
5614: if ($i > 0) {
5615: $output .= '</tr>';
5616: }
5617: $output .= '<tr>';
5618: }
5619: my $check = ' ';
5620: if (ref($settings) eq 'HASH') {
5621: if (ref($settings->{$context}) eq 'ARRAY') {
5622: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
5623: $check = ' checked="checked" ';
5624: }
5625: } elsif ($context eq 'statustocreate') {
5626: $check = ' checked="checked" ';
5627: }
5628: }
5629: $output .= '<td class="LC_left_item">'.
5630: '<span class="LC_nobreak"><label>'.
5631: '<input type="checkbox" name="'.$context.'" '.
5632: 'value="'.$types->[$i].'"'.$check.'/>'.
5633: $usertypes->{$types->[$i]}.'</label></span></td>';
5634: }
5635: }
5636: $rem = @{$types}%($numinrow);
5637: }
5638: my $colsleft = $numinrow - $rem;
5639: if (($rem == 0) && (@{$types} > 0)) {
5640: $output .= '<tr>';
5641: }
5642: if ($colsleft > 1) {
5643: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5644: } else {
5645: $output .= '<td class="LC_left_item">';
5646: }
5647: my $defcheck = ' ';
5648: if (ref($settings) eq 'HASH') {
5649: if (ref($settings->{$context}) eq 'ARRAY') {
5650: if (grep(/^default$/,@{$settings->{$context}})) {
5651: $defcheck = ' checked="checked" ';
5652: }
5653: } elsif ($context eq 'statustocreate') {
5654: $defcheck = ' checked="checked" ';
5655: }
5656: }
5657: $output .= '<span class="LC_nobreak"><label>'.
5658: '<input type="checkbox" name="'.$context.'" '.
5659: 'value="default"'.$defcheck.'/>'.
5660: $othertitle.'</label></span></td>'.
5661: '</tr></table></td></tr>';
5662: return $output;
5663: }
5664:
5665: sub sorted_searchtitles {
5666: my %searchtitles = &Apache::lonlocal::texthash(
5667: 'uname' => 'username',
5668: 'lastname' => 'last name',
5669: 'lastfirst' => 'last name, first name',
5670: );
5671: my @titleorder = ('uname','lastname','lastfirst');
5672: return (\%searchtitles,\@titleorder);
5673: }
5674:
5675: sub sorted_searchtypes {
5676: my %srchtypes_desc = (
5677: exact => 'is exact match',
5678: contains => 'contains ..',
5679: begins => 'begins with ..',
5680: );
5681: my @srchtypeorder = ('exact','begins','contains');
5682: return (\%srchtypes_desc,\@srchtypeorder);
5683: }
5684:
5685: sub usertype_update_row {
5686: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
5687: my $datatable;
5688: my $numinrow = 4;
5689: foreach my $type (@{$types}) {
5690: if (defined($usertypes->{$type})) {
5691: $$rownums ++;
5692: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
5693: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
5694: '</td><td class="LC_left_item"><table>';
5695: for (my $i=0; $i<@{$fields}; $i++) {
5696: my $rem = $i%($numinrow);
5697: if ($rem == 0) {
5698: if ($i > 0) {
5699: $datatable .= '</tr>';
5700: }
5701: $datatable .= '<tr>';
5702: }
5703: my $check = ' ';
5704: if (ref($settings) eq 'HASH') {
5705: if (ref($settings->{'fields'}) eq 'HASH') {
5706: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
5707: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
5708: $check = ' checked="checked" ';
5709: }
5710: }
5711: }
5712: }
5713:
5714: if ($i == @{$fields}-1) {
5715: my $colsleft = $numinrow - $rem;
5716: if ($colsleft > 1) {
5717: $datatable .= '<td colspan="'.$colsleft.'">';
5718: } else {
5719: $datatable .= '<td>';
5720: }
5721: } else {
5722: $datatable .= '<td>';
5723: }
5724: $datatable .= '<span class="LC_nobreak"><label>'.
5725: '<input type="checkbox" name="updateable_'.$type.
5726: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
5727: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
5728: }
5729: $datatable .= '</tr></table></td></tr>';
5730: }
5731: }
5732: return $datatable;
5733: }
5734:
5735: sub modify_login {
5736: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
5737: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
5738: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
5739: %title = ( coursecatalog => 'Display course catalog',
5740: adminmail => 'Display administrator E-mail address',
5741: helpdesk => 'Display "Contact Helpdesk" link',
5742: newuser => 'Link for visitors to create a user account',
5743: loginheader => 'Log-in box header');
5744: @offon = ('off','on');
5745: if (ref($domconfig{login}) eq 'HASH') {
5746: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
5747: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
5748: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
5749: }
5750: }
5751: }
5752: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
5753: \%domconfig,\%loginhash);
5754: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
5755: foreach my $item (@toggles) {
5756: $loginhash{login}{$item} = $env{'form.'.$item};
5757: }
5758: $loginhash{login}{loginheader} = $env{'form.loginheader'};
5759: if (ref($colchanges{'login'}) eq 'HASH') {
5760: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
5761: \%loginhash);
5762: }
5763:
5764: my %servers = &Apache::lonnet::internet_dom_servers($dom);
5765: my @loginvia_attribs = ('serverpath','custompath','exempt');
5766: if (keys(%servers) > 1) {
5767: foreach my $lonhost (keys(%servers)) {
5768: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
5769: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
5770: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
5771: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
5772: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
5773: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5774: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5775: $changes{'loginvia'}{$lonhost} = 1;
5776: } else {
5777: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
5778: $changes{'loginvia'}{$lonhost} = 1;
5779: }
5780: } else {
5781: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5782: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5783: $changes{'loginvia'}{$lonhost} = 1;
5784: }
5785: }
5786: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
5787: foreach my $item (@loginvia_attribs) {
5788: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
5789: }
5790: } else {
5791: foreach my $item (@loginvia_attribs) {
5792: my $new = $env{'form.'.$lonhost.'_'.$item};
5793: if (($item eq 'serverpath') && ($new eq 'custom')) {
5794: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
5795: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5796: $new = '/';
5797: }
5798: }
5799: if (($item eq 'custompath') &&
5800: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5801: $new = '';
5802: }
5803: if ($new ne $curr_loginvia{$lonhost}{$item}) {
5804: $changes{'loginvia'}{$lonhost} = 1;
5805: }
5806: if ($item eq 'exempt') {
5807: $new =~ s/^\s+//;
5808: $new =~ s/\s+$//;
5809: my @poss_ips = split(/\s*[,:]\s*/,$new);
5810: my @okips;
5811: foreach my $ip (@poss_ips) {
5812: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
5813: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
5814: push(@okips,$ip);
5815: }
5816: }
5817: }
5818: if (@okips > 0) {
5819: $new = join(',',@okips);
5820: } else {
5821: $new = '';
5822: }
5823: }
5824: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5825: }
5826: }
5827: } else {
5828: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5829: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5830: $changes{'loginvia'}{$lonhost} = 1;
5831: foreach my $item (@loginvia_attribs) {
5832: my $new = $env{'form.'.$lonhost.'_'.$item};
5833: if (($item eq 'serverpath') && ($new eq 'custom')) {
5834: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5835: $new = '/';
5836: }
5837: }
5838: if (($item eq 'custompath') &&
5839: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5840: $new = '';
5841: }
5842: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5843: }
5844: }
5845: }
5846: }
5847: }
5848:
5849: my $servadm = $r->dir_config('lonAdmEMail');
5850: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
5851: if (ref($domconfig{'login'}) eq 'HASH') {
5852: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
5853: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
5854: if ($lang eq 'nolang') {
5855: push(@currlangs,$lang);
5856: } elsif (defined($langchoices{$lang})) {
5857: push(@currlangs,$lang);
5858: } else {
5859: next;
5860: }
5861: }
5862: }
5863: }
5864: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
5865: if (@currlangs > 0) {
5866: foreach my $lang (@currlangs) {
5867: if (grep(/^\Q$lang\E$/,@delurls)) {
5868: $changes{'helpurl'}{$lang} = 1;
5869: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
5870: $changes{'helpurl'}{$lang} = 1;
5871: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
5872: push(@newlangs,$lang);
5873: } else {
5874: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5875: }
5876: }
5877: }
5878: unless (grep(/^nolang$/,@currlangs)) {
5879: if ($env{'form.loginhelpurl_nolang.filename'}) {
5880: $changes{'helpurl'}{'nolang'} = 1;
5881: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
5882: push(@newlangs,'nolang');
5883: }
5884: }
5885: if ($env{'form.loginhelpurl_add_lang'}) {
5886: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
5887: ($env{'form.loginhelpurl_add_file.filename'})) {
5888: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
5889: $addedfile = $env{'form.loginhelpurl_add_lang'};
5890: }
5891: }
5892: if ((@newlangs > 0) || ($addedfile)) {
5893: my $error;
5894: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
5895: if ($configuserok eq 'ok') {
5896: if ($switchserver) {
5897: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
5898: } elsif ($author_ok eq 'ok') {
5899: my @allnew = @newlangs;
5900: if ($addedfile ne '') {
5901: push(@allnew,$addedfile);
5902: }
5903: foreach my $lang (@allnew) {
5904: my $formelem = 'loginhelpurl_'.$lang;
5905: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
5906: $formelem = 'loginhelpurl_add_file';
5907: }
5908: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
5909: "help/$lang",'','',$newfile{$lang});
5910: if ($result eq 'ok') {
5911: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
5912: $changes{'helpurl'}{$lang} = 1;
5913: } else {
5914: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
5915: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
5916: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
5917: (!grep(/^\Q$lang\E$/,@delurls))) {
5918:
5919: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5920: }
5921: }
5922: }
5923: } else {
5924: $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);
5925: }
5926: } else {
5927: $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);
5928: }
5929: if ($error) {
5930: &Apache::lonnet::logthis($error);
5931: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
5932: }
5933: }
5934: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
5935:
5936: my $defaulthelpfile = '/adm/loginproblems.html';
5937: my $defaulttext = &mt('Default in use');
5938:
5939: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
5940: $dom);
5941: if ($putresult eq 'ok') {
5942: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
5943: my %defaultchecked = (
5944: 'coursecatalog' => 'on',
5945: 'helpdesk' => 'on',
5946: 'adminmail' => 'off',
5947: 'newuser' => 'off',
5948: );
5949: if (ref($domconfig{'login'}) eq 'HASH') {
5950: foreach my $item (@toggles) {
5951: if ($defaultchecked{$item} eq 'on') {
5952: if (($domconfig{'login'}{$item} eq '0') &&
5953: ($env{'form.'.$item} eq '1')) {
5954: $changes{$item} = 1;
5955: } elsif (($domconfig{'login'}{$item} eq '' ||
5956: $domconfig{'login'}{$item} eq '1') &&
5957: ($env{'form.'.$item} eq '0')) {
5958: $changes{$item} = 1;
5959: }
5960: } elsif ($defaultchecked{$item} eq 'off') {
5961: if (($domconfig{'login'}{$item} eq '1') &&
5962: ($env{'form.'.$item} eq '0')) {
5963: $changes{$item} = 1;
5964: } elsif (($domconfig{'login'}{$item} eq '' ||
5965: $domconfig{'login'}{$item} eq '0') &&
5966: ($env{'form.'.$item} eq '1')) {
5967: $changes{$item} = 1;
5968: }
5969: }
5970: }
5971: }
5972: if (keys(%changes) > 0 || $colchgtext) {
5973: &Apache::loncommon::devalidate_domconfig_cache($dom);
5974: if (ref($lastactref) eq 'HASH') {
5975: $lastactref->{'domainconfig'} = 1;
5976: }
5977: $resulttext = &mt('Changes made:').'<ul>';
5978: foreach my $item (sort(keys(%changes))) {
5979: if ($item eq 'loginvia') {
5980: if (ref($changes{$item}) eq 'HASH') {
5981: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
5982: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
5983: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
5984: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
5985: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
5986: $protocol = 'http' if ($protocol ne 'https');
5987: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
5988:
5989: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
5990: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
5991: } else {
5992: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
5993: }
5994: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
5995: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
5996: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
5997: }
5998: $resulttext .= '</li>';
5999: } else {
6000: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
6001: }
6002: } else {
6003: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
6004: }
6005: }
6006: $resulttext .= '</ul></li>';
6007: }
6008: } elsif ($item eq 'helpurl') {
6009: if (ref($changes{$item}) eq 'HASH') {
6010: foreach my $lang (sort(keys(%{$changes{$item}}))) {
6011: if (grep(/^\Q$lang\E$/,@delurls)) {
6012: my ($chg,$link);
6013: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
6014: if ($lang eq 'nolang') {
6015: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
6016: } else {
6017: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
6018: }
6019: $resulttext .= '<li>'.$chg.'</li>';
6020: } else {
6021: my $chg;
6022: if ($lang eq 'nolang') {
6023: $chg = &mt('custom log-in help file for no preferred language');
6024: } else {
6025: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
6026: }
6027: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
6028: $loginhash{'login'}{'helpurl'}{$lang}.
6029: '?inhibitmenu=yes',$chg,600,500).
6030: '</li>';
6031: }
6032: }
6033: }
6034: } elsif ($item eq 'captcha') {
6035: if (ref($loginhash{'login'}) eq 'HASH') {
6036: my $chgtxt;
6037: if ($loginhash{'login'}{$item} eq 'notused') {
6038: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
6039: } else {
6040: my %captchas = &captcha_phrases();
6041: if ($captchas{$loginhash{'login'}{$item}}) {
6042: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
6043: } else {
6044: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
6045: }
6046: }
6047: $resulttext .= '<li>'.$chgtxt.'</li>';
6048: }
6049: } elsif ($item eq 'recaptchakeys') {
6050: if (ref($loginhash{'login'}) eq 'HASH') {
6051: my ($privkey,$pubkey);
6052: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
6053: $pubkey = $loginhash{'login'}{$item}{'public'};
6054: $privkey = $loginhash{'login'}{$item}{'private'};
6055: }
6056: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
6057: if (!$pubkey) {
6058: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
6059: } else {
6060: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6061: }
6062: if (!$privkey) {
6063: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
6064: } else {
6065: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
6066: }
6067: $chgtxt .= '</ul>';
6068: $resulttext .= '<li>'.$chgtxt.'</li>';
6069: }
6070: } else {
6071: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
6072: }
6073: }
6074: $resulttext .= $colchgtext.'</ul>';
6075: } else {
6076: $resulttext = &mt('No changes made to log-in page settings');
6077: }
6078: } else {
6079: $resulttext = '<span class="LC_error">'.
6080: &mt('An error occurred: [_1]',$putresult).'</span>';
6081: }
6082: if ($errors) {
6083: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
6084: $errors.'</ul>';
6085: }
6086: return $resulttext;
6087: }
6088:
6089: sub color_font_choices {
6090: my %choices =
6091: &Apache::lonlocal::texthash (
6092: img => "Header",
6093: bgs => "Background colors",
6094: links => "Link colors",
6095: images => "Images",
6096: font => "Font color",
6097: fontmenu => "Font menu",
6098: pgbg => "Page",
6099: tabbg => "Header",
6100: sidebg => "Border",
6101: link => "Link",
6102: alink => "Active link",
6103: vlink => "Visited link",
6104: );
6105: return %choices;
6106: }
6107:
6108: sub modify_rolecolors {
6109: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
6110: my ($resulttext,%rolehash);
6111: $rolehash{'rolecolors'} = {};
6112: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
6113: if ($domconfig{'rolecolors'} eq '') {
6114: $domconfig{'rolecolors'} = {};
6115: }
6116: }
6117: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
6118: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
6119: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
6120: $dom);
6121: if ($putresult eq 'ok') {
6122: if (keys(%changes) > 0) {
6123: &Apache::loncommon::devalidate_domconfig_cache($dom);
6124: if (ref($lastactref) eq 'HASH') {
6125: $lastactref->{'domainconfig'} = 1;
6126: }
6127: $resulttext = &display_colorchgs($dom,\%changes,$roles,
6128: $rolehash{'rolecolors'});
6129: } else {
6130: $resulttext = &mt('No changes made to default color schemes');
6131: }
6132: } else {
6133: $resulttext = '<span class="LC_error">'.
6134: &mt('An error occurred: [_1]',$putresult).'</span>';
6135: }
6136: if ($errors) {
6137: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6138: $errors.'</ul>';
6139: }
6140: return $resulttext;
6141: }
6142:
6143: sub modify_colors {
6144: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
6145: my (%changes,%choices);
6146: my @bgs;
6147: my @links = ('link','alink','vlink');
6148: my @logintext;
6149: my @images;
6150: my $servadm = $r->dir_config('lonAdmEMail');
6151: my $errors;
6152: my %defaults;
6153: foreach my $role (@{$roles}) {
6154: if ($role eq 'login') {
6155: %choices = &login_choices();
6156: @logintext = ('textcol','bgcol');
6157: } else {
6158: %choices = &color_font_choices();
6159: }
6160: if ($role eq 'login') {
6161: @images = ('img','logo','domlogo','login');
6162: @bgs = ('pgbg','mainbg','sidebg');
6163: } else {
6164: @images = ('img');
6165: @bgs = ('pgbg','tabbg','sidebg');
6166: }
6167: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
6168: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
6169: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
6170: }
6171: if ($role eq 'login') {
6172: foreach my $item (@logintext) {
6173: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6174: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6175: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6176: }
6177: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
6178: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6179: }
6180: }
6181: } else {
6182: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
6183: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
6184: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
6185: }
6186: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
6187: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
6188: }
6189: }
6190: foreach my $item (@bgs) {
6191: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6192: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6193: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6194: }
6195: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
6196: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6197: }
6198: }
6199: foreach my $item (@links) {
6200: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6201: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6202: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6203: }
6204: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
6205: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6206: }
6207: }
6208: my ($configuserok,$author_ok,$switchserver) =
6209: &config_check($dom,$confname,$servadm);
6210: my ($width,$height) = &thumb_dimensions();
6211: if (ref($domconfig->{$role}) ne 'HASH') {
6212: $domconfig->{$role} = {};
6213: }
6214: foreach my $img (@images) {
6215: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
6216: if (defined($env{'form.login_showlogo_'.$img})) {
6217: $confhash->{$role}{'showlogo'}{$img} = 1;
6218: } else {
6219: $confhash->{$role}{'showlogo'}{$img} = 0;
6220: }
6221: }
6222: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
6223: && !defined($domconfig->{$role}{$img})
6224: && !$env{'form.'.$role.'_del_'.$img}
6225: && $env{'form.'.$role.'_import_'.$img}) {
6226: # import the old configured image from the .tab setting
6227: # if they haven't provided a new one
6228: $domconfig->{$role}{$img} =
6229: $env{'form.'.$role.'_import_'.$img};
6230: }
6231: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
6232: my $error;
6233: if ($configuserok eq 'ok') {
6234: if ($switchserver) {
6235: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
6236: } else {
6237: if ($author_ok eq 'ok') {
6238: my ($result,$logourl) =
6239: &publishlogo($r,'upload',$role.'_'.$img,
6240: $dom,$confname,$img,$width,$height);
6241: if ($result eq 'ok') {
6242: $confhash->{$role}{$img} = $logourl;
6243: $changes{$role}{'images'}{$img} = 1;
6244: } else {
6245: $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);
6246: }
6247: } else {
6248: $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);
6249: }
6250: }
6251: } else {
6252: $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);
6253: }
6254: if ($error) {
6255: &Apache::lonnet::logthis($error);
6256: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6257: }
6258: } elsif ($domconfig->{$role}{$img} ne '') {
6259: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
6260: my $error;
6261: if ($configuserok eq 'ok') {
6262: # is confname an author?
6263: if ($switchserver eq '') {
6264: if ($author_ok eq 'ok') {
6265: my ($result,$logourl) =
6266: &publishlogo($r,'copy',$domconfig->{$role}{$img},
6267: $dom,$confname,$img,$width,$height);
6268: if ($result eq 'ok') {
6269: $confhash->{$role}{$img} = $logourl;
6270: $changes{$role}{'images'}{$img} = 1;
6271: }
6272: }
6273: }
6274: }
6275: }
6276: }
6277: }
6278: if (ref($domconfig) eq 'HASH') {
6279: if (ref($domconfig->{$role}) eq 'HASH') {
6280: foreach my $img (@images) {
6281: if ($domconfig->{$role}{$img} ne '') {
6282: if ($env{'form.'.$role.'_del_'.$img}) {
6283: $confhash->{$role}{$img} = '';
6284: $changes{$role}{'images'}{$img} = 1;
6285: } else {
6286: if ($confhash->{$role}{$img} eq '') {
6287: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
6288: }
6289: }
6290: } else {
6291: if ($env{'form.'.$role.'_del_'.$img}) {
6292: $confhash->{$role}{$img} = '';
6293: $changes{$role}{'images'}{$img} = 1;
6294: }
6295: }
6296: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
6297: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
6298: if ($confhash->{$role}{'showlogo'}{$img} ne
6299: $domconfig->{$role}{'showlogo'}{$img}) {
6300: $changes{$role}{'showlogo'}{$img} = 1;
6301: }
6302: } else {
6303: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6304: $changes{$role}{'showlogo'}{$img} = 1;
6305: }
6306: }
6307: }
6308: }
6309: if ($domconfig->{$role}{'font'} ne '') {
6310: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
6311: $changes{$role}{'font'} = 1;
6312: }
6313: } else {
6314: if ($confhash->{$role}{'font'}) {
6315: $changes{$role}{'font'} = 1;
6316: }
6317: }
6318: if ($role ne 'login') {
6319: if ($domconfig->{$role}{'fontmenu'} ne '') {
6320: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
6321: $changes{$role}{'fontmenu'} = 1;
6322: }
6323: } else {
6324: if ($confhash->{$role}{'fontmenu'}) {
6325: $changes{$role}{'fontmenu'} = 1;
6326: }
6327: }
6328: }
6329: foreach my $item (@bgs) {
6330: if ($domconfig->{$role}{$item} ne '') {
6331: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6332: $changes{$role}{'bgs'}{$item} = 1;
6333: }
6334: } else {
6335: if ($confhash->{$role}{$item}) {
6336: $changes{$role}{'bgs'}{$item} = 1;
6337: }
6338: }
6339: }
6340: foreach my $item (@links) {
6341: if ($domconfig->{$role}{$item} ne '') {
6342: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6343: $changes{$role}{'links'}{$item} = 1;
6344: }
6345: } else {
6346: if ($confhash->{$role}{$item}) {
6347: $changes{$role}{'links'}{$item} = 1;
6348: }
6349: }
6350: }
6351: foreach my $item (@logintext) {
6352: if ($domconfig->{$role}{$item} ne '') {
6353: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6354: $changes{$role}{'logintext'}{$item} = 1;
6355: }
6356: } else {
6357: if ($confhash->{$role}{$item}) {
6358: $changes{$role}{'logintext'}{$item} = 1;
6359: }
6360: }
6361: }
6362: } else {
6363: &default_change_checker($role,\@images,\@links,\@bgs,
6364: \@logintext,$confhash,\%changes);
6365: }
6366: } else {
6367: &default_change_checker($role,\@images,\@links,\@bgs,
6368: \@logintext,$confhash,\%changes);
6369: }
6370: }
6371: return ($errors,%changes);
6372: }
6373:
6374: sub config_check {
6375: my ($dom,$confname,$servadm) = @_;
6376: my ($configuserok,$author_ok,$switchserver,%currroles);
6377: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
6378: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
6379: $confname,$servadm);
6380: if ($configuserok eq 'ok') {
6381: $switchserver = &check_switchserver($dom,$confname);
6382: if ($switchserver eq '') {
6383: $author_ok = &check_authorstatus($dom,$confname,%currroles);
6384: }
6385: }
6386: return ($configuserok,$author_ok,$switchserver);
6387: }
6388:
6389: sub default_change_checker {
6390: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
6391: foreach my $item (@{$links}) {
6392: if ($confhash->{$role}{$item}) {
6393: $changes->{$role}{'links'}{$item} = 1;
6394: }
6395: }
6396: foreach my $item (@{$bgs}) {
6397: if ($confhash->{$role}{$item}) {
6398: $changes->{$role}{'bgs'}{$item} = 1;
6399: }
6400: }
6401: foreach my $item (@{$logintext}) {
6402: if ($confhash->{$role}{$item}) {
6403: $changes->{$role}{'logintext'}{$item} = 1;
6404: }
6405: }
6406: foreach my $img (@{$images}) {
6407: if ($env{'form.'.$role.'_del_'.$img}) {
6408: $confhash->{$role}{$img} = '';
6409: $changes->{$role}{'images'}{$img} = 1;
6410: }
6411: if ($role eq 'login') {
6412: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6413: $changes->{$role}{'showlogo'}{$img} = 1;
6414: }
6415: }
6416: }
6417: if ($confhash->{$role}{'font'}) {
6418: $changes->{$role}{'font'} = 1;
6419: }
6420: }
6421:
6422: sub display_colorchgs {
6423: my ($dom,$changes,$roles,$confhash) = @_;
6424: my (%choices,$resulttext);
6425: if (!grep(/^login$/,@{$roles})) {
6426: $resulttext = &mt('Changes made:').'<br />';
6427: }
6428: foreach my $role (@{$roles}) {
6429: if ($role eq 'login') {
6430: %choices = &login_choices();
6431: } else {
6432: %choices = &color_font_choices();
6433: }
6434: if (ref($changes->{$role}) eq 'HASH') {
6435: if ($role ne 'login') {
6436: $resulttext .= '<h4>'.&mt($role).'</h4>';
6437: }
6438: foreach my $key (sort(keys(%{$changes->{$role}}))) {
6439: if ($role ne 'login') {
6440: $resulttext .= '<ul>';
6441: }
6442: if (ref($changes->{$role}{$key}) eq 'HASH') {
6443: if ($role ne 'login') {
6444: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
6445: }
6446: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
6447: if (($role eq 'login') && ($key eq 'showlogo')) {
6448: if ($confhash->{$role}{$key}{$item}) {
6449: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
6450: } else {
6451: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
6452: }
6453: } elsif ($confhash->{$role}{$item} eq '') {
6454: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
6455: } else {
6456: my $newitem = $confhash->{$role}{$item};
6457: if ($key eq 'images') {
6458: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
6459: }
6460: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
6461: }
6462: }
6463: if ($role ne 'login') {
6464: $resulttext .= '</ul></li>';
6465: }
6466: } else {
6467: if ($confhash->{$role}{$key} eq '') {
6468: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
6469: } else {
6470: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
6471: }
6472: }
6473: if ($role ne 'login') {
6474: $resulttext .= '</ul>';
6475: }
6476: }
6477: }
6478: }
6479: return $resulttext;
6480: }
6481:
6482: sub thumb_dimensions {
6483: return ('200','50');
6484: }
6485:
6486: sub check_dimensions {
6487: my ($inputfile) = @_;
6488: my ($fullwidth,$fullheight);
6489: if ($inputfile =~ m|^[/\w.\-]+$|) {
6490: if (open(PIPE,"identify $inputfile 2>&1 |")) {
6491: my $imageinfo = <PIPE>;
6492: if (!close(PIPE)) {
6493: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
6494: }
6495: chomp($imageinfo);
6496: my ($fullsize) =
6497: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
6498: if ($fullsize) {
6499: ($fullwidth,$fullheight) = split(/x/,$fullsize);
6500: }
6501: }
6502: }
6503: return ($fullwidth,$fullheight);
6504: }
6505:
6506: sub check_configuser {
6507: my ($uhome,$dom,$confname,$servadm) = @_;
6508: my ($configuserok,%currroles);
6509: if ($uhome eq 'no_host') {
6510: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
6511: my $configpass = &LONCAPA::Enrollment::create_password();
6512: $configuserok =
6513: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
6514: $configpass,'','','','','',undef,$servadm);
6515: } else {
6516: $configuserok = 'ok';
6517: %currroles =
6518: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
6519: }
6520: return ($configuserok,%currroles);
6521: }
6522:
6523: sub check_authorstatus {
6524: my ($dom,$confname,%currroles) = @_;
6525: my $author_ok;
6526: if (!$currroles{':'.$dom.':au'}) {
6527: my $start = time;
6528: my $end = 0;
6529: $author_ok =
6530: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
6531: 'au',$end,$start,'','','domconfig');
6532: } else {
6533: $author_ok = 'ok';
6534: }
6535: return $author_ok;
6536: }
6537:
6538: sub publishlogo {
6539: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
6540: my ($output,$fname,$logourl);
6541: if ($action eq 'upload') {
6542: $fname=$env{'form.'.$formname.'.filename'};
6543: chop($env{'form.'.$formname});
6544: } else {
6545: ($fname) = ($formname =~ /([^\/]+)$/);
6546: }
6547: if ($savefileas ne '') {
6548: $fname = $savefileas;
6549: }
6550: $fname=&Apache::lonnet::clean_filename($fname);
6551: # See if there is anything left
6552: unless ($fname) { return ('error: no uploaded file'); }
6553: $fname="$subdir/$fname";
6554: my $docroot=$r->dir_config('lonDocRoot');
6555: my $filepath="$docroot/priv";
6556: my $relpath = "$dom/$confname";
6557: my ($fnamepath,$file,$fetchthumb);
6558: $file=$fname;
6559: if ($fname=~m|/|) {
6560: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
6561: }
6562: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
6563: my $count;
6564: for ($count=5;$count<=$#parts;$count++) {
6565: $filepath.="/$parts[$count]";
6566: if ((-e $filepath)!=1) {
6567: mkdir($filepath,02770);
6568: }
6569: }
6570: # Check for bad extension and disallow upload
6571: if ($file=~/\.(\w+)$/ &&
6572: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
6573: $output =
6574: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
6575: } elsif ($file=~/\.(\w+)$/ &&
6576: !defined(&Apache::loncommon::fileembstyle($1))) {
6577: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
6578: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
6579: $output = &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
6580: } elsif (-d "$filepath/$file") {
6581: $output = &mt('Filename is a directory name - rename the file and re-upload');
6582: } else {
6583: my $source = $filepath.'/'.$file;
6584: my $logfile;
6585: if (!open($logfile,">>$source".'.log')) {
6586: return (&mt('No write permission to Authoring Space'));
6587: }
6588: print $logfile
6589: "\n================= Publish ".localtime()." ================\n".
6590: $env{'user.name'}.':'.$env{'user.domain'}."\n";
6591: # Save the file
6592: if (!open(FH,'>'.$source)) {
6593: &Apache::lonnet::logthis('Failed to create '.$source);
6594: return (&mt('Failed to create file'));
6595: }
6596: if ($action eq 'upload') {
6597: if (!print FH ($env{'form.'.$formname})) {
6598: &Apache::lonnet::logthis('Failed to write to '.$source);
6599: return (&mt('Failed to write file'));
6600: }
6601: } else {
6602: my $original = &Apache::lonnet::filelocation('',$formname);
6603: if(!copy($original,$source)) {
6604: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
6605: return (&mt('Failed to write file'));
6606: }
6607: }
6608: close(FH);
6609: chmod(0660, $source); # Permissions to rw-rw---.
6610:
6611: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
6612: my $copyfile=$targetdir.'/'.$file;
6613:
6614: my @parts=split(/\//,$targetdir);
6615: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
6616: for (my $count=5;$count<=$#parts;$count++) {
6617: $path.="/$parts[$count]";
6618: if (!-e $path) {
6619: print $logfile "\nCreating directory ".$path;
6620: mkdir($path,02770);
6621: }
6622: }
6623: my $versionresult;
6624: if (-e $copyfile) {
6625: $versionresult = &logo_versioning($targetdir,$file,$logfile);
6626: } else {
6627: $versionresult = 'ok';
6628: }
6629: if ($versionresult eq 'ok') {
6630: if (copy($source,$copyfile)) {
6631: print $logfile "\nCopied original source to ".$copyfile."\n";
6632: $output = 'ok';
6633: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
6634: push(@{$modified_urls},[$copyfile,$source]);
6635: my $metaoutput =
6636: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
6637: unless ($registered_cleanup) {
6638: my $handlers = $r->get_handlers('PerlCleanupHandler');
6639: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6640: $registered_cleanup=1;
6641: }
6642: } else {
6643: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
6644: $output = &mt('Failed to copy file to RES space').", $!";
6645: }
6646: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
6647: my $inputfile = $filepath.'/'.$file;
6648: my $outfile = $filepath.'/'.'tn-'.$file;
6649: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
6650: if ($fullwidth ne '' && $fullheight ne '') {
6651: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
6652: my $thumbsize = $thumbwidth.'x'.$thumbheight;
6653: system("convert -sample $thumbsize $inputfile $outfile");
6654: chmod(0660, $filepath.'/tn-'.$file);
6655: if (-e $outfile) {
6656: my $copyfile=$targetdir.'/tn-'.$file;
6657: if (copy($outfile,$copyfile)) {
6658: print $logfile "\nCopied source to ".$copyfile."\n";
6659: my $thumb_metaoutput =
6660: &write_metadata($dom,$confname,$formname,
6661: $targetdir,'tn-'.$file,$logfile);
6662: push(@{$modified_urls},[$copyfile,$outfile]);
6663: unless ($registered_cleanup) {
6664: my $handlers = $r->get_handlers('PerlCleanupHandler');
6665: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6666: $registered_cleanup=1;
6667: }
6668: } else {
6669: print $logfile "\nUnable to write ".$copyfile.
6670: ':'.$!."\n";
6671: }
6672: }
6673: }
6674: }
6675: }
6676: } else {
6677: $output = $versionresult;
6678: }
6679: }
6680: return ($output,$logourl);
6681: }
6682:
6683: sub logo_versioning {
6684: my ($targetdir,$file,$logfile) = @_;
6685: my $target = $targetdir.'/'.$file;
6686: my ($maxversion,$fn,$extn,$output);
6687: $maxversion = 0;
6688: if ($file =~ /^(.+)\.(\w+)$/) {
6689: $fn=$1;
6690: $extn=$2;
6691: }
6692: opendir(DIR,$targetdir);
6693: while (my $filename=readdir(DIR)) {
6694: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
6695: $maxversion=($1>$maxversion)?$1:$maxversion;
6696: }
6697: }
6698: $maxversion++;
6699: print $logfile "\nCreating old version ".$maxversion."\n";
6700: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
6701: if (copy($target,$copyfile)) {
6702: print $logfile "Copied old target to ".$copyfile."\n";
6703: $copyfile=$copyfile.'.meta';
6704: if (copy($target.'.meta',$copyfile)) {
6705: print $logfile "Copied old target metadata to ".$copyfile."\n";
6706: $output = 'ok';
6707: } else {
6708: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
6709: $output = &mt('Failed to copy old meta').", $!, ";
6710: }
6711: } else {
6712: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
6713: $output = &mt('Failed to copy old target').", $!, ";
6714: }
6715: return $output;
6716: }
6717:
6718: sub write_metadata {
6719: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
6720: my (%metadatafields,%metadatakeys,$output);
6721: $metadatafields{'title'}=$formname;
6722: $metadatafields{'creationdate'}=time;
6723: $metadatafields{'lastrevisiondate'}=time;
6724: $metadatafields{'copyright'}='public';
6725: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
6726: $env{'user.domain'};
6727: $metadatafields{'authorspace'}=$confname.':'.$dom;
6728: $metadatafields{'domain'}=$dom;
6729: {
6730: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
6731: my $mfh;
6732: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
6733: foreach (sort(keys(%metadatafields))) {
6734: unless ($_=~/\./) {
6735: my $unikey=$_;
6736: $unikey=~/^([A-Za-z]+)/;
6737: my $tag=$1;
6738: $tag=~tr/A-Z/a-z/;
6739: print $mfh "\n\<$tag";
6740: foreach (split(/\,/,$metadatakeys{$unikey})) {
6741: my $value=$metadatafields{$unikey.'.'.$_};
6742: $value=~s/\"/\'\'/g;
6743: print $mfh ' '.$_.'="'.$value.'"';
6744: }
6745: print $mfh '>'.
6746: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
6747: .'</'.$tag.'>';
6748: }
6749: }
6750: $output = 'ok';
6751: print $logfile "\nWrote metadata";
6752: close($mfh);
6753: } else {
6754: print $logfile "\nFailed to open metadata file";
6755: $output = &mt('Could not write metadata');
6756: }
6757: }
6758: return $output;
6759: }
6760:
6761: sub notifysubscribed {
6762: foreach my $targetsource (@{$modified_urls}){
6763: next unless (ref($targetsource) eq 'ARRAY');
6764: my ($target,$source)=@{$targetsource};
6765: if ($source ne '') {
6766: if (open(my $logfh,'>>'.$source.'.log')) {
6767: print $logfh "\nCleanup phase: Notifications\n";
6768: my @subscribed=&subscribed_hosts($target);
6769: foreach my $subhost (@subscribed) {
6770: print $logfh "\nNotifying host ".$subhost.':';
6771: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
6772: print $logfh $reply;
6773: }
6774: my @subscribedmeta=&subscribed_hosts("$target.meta");
6775: foreach my $subhost (@subscribedmeta) {
6776: print $logfh "\nNotifying host for metadata only ".$subhost.':';
6777: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
6778: $subhost);
6779: print $logfh $reply;
6780: }
6781: print $logfh "\n============ Done ============\n";
6782: close($logfh);
6783: }
6784: }
6785: }
6786: return OK;
6787: }
6788:
6789: sub subscribed_hosts {
6790: my ($target) = @_;
6791: my @subscribed;
6792: if (open(my $fh,"<$target.subscription")) {
6793: while (my $subline=<$fh>) {
6794: if ($subline =~ /^($match_lonid):/) {
6795: my $host = $1;
6796: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
6797: unless (grep(/^\Q$host\E$/,@subscribed)) {
6798: push(@subscribed,$host);
6799: }
6800: }
6801: }
6802: }
6803: }
6804: return @subscribed;
6805: }
6806:
6807: sub check_switchserver {
6808: my ($dom,$confname) = @_;
6809: my ($allowed,$switchserver);
6810: my $home = &Apache::lonnet::homeserver($confname,$dom);
6811: if ($home eq 'no_host') {
6812: $home = &Apache::lonnet::domain($dom,'primary');
6813: }
6814: my @ids=&Apache::lonnet::current_machine_ids();
6815: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
6816: if (!$allowed) {
6817: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
6818: }
6819: return $switchserver;
6820: }
6821:
6822: sub modify_quotas {
6823: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
6824: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
6825: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
6826: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
6827: $validationfieldsref);
6828: if ($action eq 'quotas') {
6829: $context = 'tools';
6830: } else {
6831: $context = $action;
6832: }
6833: if ($context eq 'requestcourses') {
6834: @usertools = ('official','unofficial','community','textbook');
6835: @options =('norequest','approval','validate','autolimit');
6836: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
6837: %titles = &courserequest_titles();
6838: $toolregexp = join('|',@usertools);
6839: %conditions = &courserequest_conditions();
6840: $confname = $dom.'-domainconfig';
6841: my $servadm = $r->dir_config('lonAdmEMail');
6842: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6843: ($validationitemsref,$validationnamesref,$validationfieldsref) =
6844: &Apache::loncoursequeueadmin::requestcourses_validation_types();
6845: } elsif ($context eq 'requestauthor') {
6846: @usertools = ('author');
6847: %titles = &authorrequest_titles();
6848: } else {
6849: @usertools = ('aboutme','blog','webdav','portfolio');
6850: %titles = &tool_titles();
6851: }
6852: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
6853: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6854: foreach my $key (keys(%env)) {
6855: if ($context eq 'requestcourses') {
6856: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
6857: my $item = $1;
6858: my $type = $2;
6859: if ($type =~ /^limit_(.+)/) {
6860: $limithash{$item}{$1} = $env{$key};
6861: } else {
6862: $confhash{$item}{$type} = $env{$key};
6863: }
6864: }
6865: } elsif ($context eq 'requestauthor') {
6866: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
6867: $confhash{$1} = $env{$key};
6868: }
6869: } else {
6870: if ($key =~ /^form\.quota_(.+)$/) {
6871: $confhash{'defaultquota'}{$1} = $env{$key};
6872: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
6873: $confhash{'authorquota'}{$1} = $env{$key};
6874: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
6875: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
6876: }
6877: }
6878: }
6879: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
6880: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
6881: @approvalnotify = sort(@approvalnotify);
6882: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
6883: my @crstypes = ('official','unofficial','community','textbook');
6884: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
6885: foreach my $type (@hasuniquecode) {
6886: if (grep(/^\Q$type\E$/,@crstypes)) {
6887: $confhash{'uniquecode'}{$type} = 1;
6888: }
6889: }
6890: my (%newbook,%allpos);
6891: if ($context eq 'requestcourses') {
6892: foreach my $type ('textbooks','templates') {
6893: @{$allpos{$type}} = ();
6894: my $invalid;
6895: if ($type eq 'textbooks') {
6896: $invalid = &mt('Invalid LON-CAPA course for textbook');
6897: } else {
6898: $invalid = &mt('Invalid LON-CAPA course for template');
6899: }
6900: if ($env{'form.'.$type.'_addbook'}) {
6901: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
6902: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
6903: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
6904: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
6905: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
6906: } else {
6907: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
6908: my $position = $env{'form.'.$type.'_addbook_pos'};
6909: $position =~ s/\D+//g;
6910: if ($position ne '') {
6911: $allpos{$type}[$position] = $newbook{$type};
6912: }
6913: }
6914: } else {
6915: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
6916: }
6917: }
6918: }
6919: }
6920: if (ref($domconfig{$action}) eq 'HASH') {
6921: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
6922: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
6923: $changes{'notify'}{'approval'} = 1;
6924: }
6925: } else {
6926: if ($confhash{'notify'}{'approval'}) {
6927: $changes{'notify'}{'approval'} = 1;
6928: }
6929: }
6930: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
6931: if (ref($confhash{'uniquecode'}) eq 'HASH') {
6932: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
6933: unless ($confhash{'uniquecode'}{$crstype}) {
6934: $changes{'uniquecode'} = 1;
6935: }
6936: }
6937: unless ($changes{'uniquecode'}) {
6938: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
6939: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
6940: $changes{'uniquecode'} = 1;
6941: }
6942: }
6943: }
6944: } else {
6945: $changes{'uniquecode'} = 1;
6946: }
6947: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
6948: $changes{'uniquecode'} = 1;
6949: }
6950: if ($context eq 'requestcourses') {
6951: foreach my $type ('textbooks','templates') {
6952: if (ref($domconfig{$action}{$type}) eq 'HASH') {
6953: my %deletions;
6954: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
6955: if (@todelete) {
6956: map { $deletions{$_} = 1; } @todelete;
6957: }
6958: my %imgdeletions;
6959: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
6960: if (@todeleteimages) {
6961: map { $imgdeletions{$_} = 1; } @todeleteimages;
6962: }
6963: my $maxnum = $env{'form.'.$type.'_maxnum'};
6964: for (my $i=0; $i<=$maxnum; $i++) {
6965: my $itemid = $env{'form.'.$type.'_id_'.$i};
6966: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
6967: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
6968: if ($deletions{$key}) {
6969: if ($domconfig{$action}{$type}{$key}{'image'}) {
6970: #FIXME need to obsolete item in RES space
6971: }
6972: next;
6973: } else {
6974: my $newpos = $env{'form.'.$itemid};
6975: $newpos =~ s/\D+//g;
6976: foreach my $item ('subject','title','publisher','author') {
6977: next if ((($item eq 'author') || ($item eq 'publisher')) &&
6978: ($type eq 'templates'));
6979: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
6980: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
6981: $changes{$type}{$key} = 1;
6982: }
6983: }
6984: $allpos{$type}[$newpos] = $key;
6985: }
6986: if ($imgdeletions{$key}) {
6987: $changes{$type}{$key} = 1;
6988: #FIXME need to obsolete item in RES space
6989: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
6990: my ($cdom,$cnum) = split(/_/,$key);
6991: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
6992: $cdom,$cnum,$type,$configuserok,
6993: $switchserver,$author_ok);
6994: if ($imgurl) {
6995: $confhash{$type}{$key}{'image'} = $imgurl;
6996: $changes{$type}{$key} = 1;
6997: }
6998: if ($error) {
6999: &Apache::lonnet::logthis($error);
7000: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7001: }
7002: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
7003: $confhash{$type}{$key}{'image'} =
7004: $domconfig{$action}{$type}{$key}{'image'};
7005: }
7006: }
7007: }
7008: }
7009: }
7010: }
7011: } else {
7012: if ($confhash{'notify'}{'approval'}) {
7013: $changes{'notify'}{'approval'} = 1;
7014: }
7015: if (ref($confhash{'uniquecode'} eq 'HASH')) {
7016: $changes{'uniquecode'} = 1;
7017: }
7018: }
7019: if ($context eq 'requestcourses') {
7020: foreach my $type ('textbooks','templates') {
7021: if ($newbook{$type}) {
7022: $changes{$type}{$newbook{$type}} = 1;
7023: foreach my $item ('subject','title','publisher','author') {
7024: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7025: ($type eq 'template'));
7026: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
7027: if ($env{'form.'.$type.'_addbook_'.$item}) {
7028: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
7029: }
7030: }
7031: if ($type eq 'textbooks') {
7032: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
7033: my ($cdom,$cnum) = split(/_/,$newbook{$type});
7034: my ($imageurl,$error) =
7035: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
7036: $configuserok,$switchserver,$author_ok);
7037: if ($imageurl) {
7038: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
7039: }
7040: if ($error) {
7041: &Apache::lonnet::logthis($error);
7042: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7043: }
7044: }
7045: }
7046: }
7047: if (@{$allpos{$type}} > 0) {
7048: my $idx = 0;
7049: foreach my $item (@{$allpos{$type}}) {
7050: if ($item ne '') {
7051: $confhash{$type}{$item}{'order'} = $idx;
7052: if (ref($domconfig{$action}) eq 'HASH') {
7053: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7054: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
7055: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
7056: $changes{$type}{$item} = 1;
7057: }
7058: }
7059: }
7060: }
7061: $idx ++;
7062: }
7063: }
7064: }
7065: }
7066: if (ref($validationitemsref) eq 'ARRAY') {
7067: foreach my $item (@{$validationitemsref}) {
7068: if ($item eq 'fields') {
7069: my @changed;
7070: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
7071: if (@{$confhash{'validation'}{$item}} > 0) {
7072: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
7073: }
7074: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7075: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
7076: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
7077: $domconfig{'requestcourses'}{'validation'}{$item});
7078: } else {
7079: @changed = @{$confhash{'validation'}{$item}};
7080: }
7081: } else {
7082: @changed = @{$confhash{'validation'}{$item}};
7083: }
7084: if (@changed) {
7085: if ($confhash{'validation'}{$item}) {
7086: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
7087: } else {
7088: $changes{'validation'}{$item} = &mt('None');
7089: }
7090: }
7091: } else {
7092: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
7093: if ($item eq 'markup') {
7094: if ($env{'form.requestcourses_validation_'.$item}) {
7095: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
7096: }
7097: }
7098: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7099: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
7100: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7101: }
7102: } else {
7103: if ($confhash{'validation'}{$item} ne '') {
7104: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7105: }
7106: }
7107: }
7108: }
7109: }
7110: if ($env{'form.validationdc'}) {
7111: my $newval = $env{'form.validationdc'};
7112: my %domcoords = &get_active_dcs($dom);
7113: if (exists($domcoords{$newval})) {
7114: $confhash{'validation'}{'dc'} = $newval;
7115: }
7116: }
7117: if (ref($confhash{'validation'}) eq 'HASH') {
7118: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7119: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7120: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
7121: if ($confhash{'validation'}{'dc'} eq '') {
7122: $changes{'validation'}{'dc'} = &mt('None');
7123: } else {
7124: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7125: }
7126: }
7127: } elsif ($confhash{'validation'}{'dc'} ne '') {
7128: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7129: }
7130: } elsif ($confhash{'validation'}{'dc'} ne '') {
7131: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7132: }
7133: } elsif (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7134: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7135: $changes{'validation'}{'dc'} = &mt('None');
7136: }
7137: }
7138: }
7139: } else {
7140: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
7141: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
7142: }
7143: foreach my $item (@usertools) {
7144: foreach my $type (@{$types},'default','_LC_adv') {
7145: my $unset;
7146: if ($context eq 'requestcourses') {
7147: $unset = '0';
7148: if ($type eq '_LC_adv') {
7149: $unset = '';
7150: }
7151: if ($confhash{$item}{$type} eq 'autolimit') {
7152: $confhash{$item}{$type} .= '=';
7153: unless ($limithash{$item}{$type} =~ /\D/) {
7154: $confhash{$item}{$type} .= $limithash{$item}{$type};
7155: }
7156: }
7157: } elsif ($context eq 'requestauthor') {
7158: $unset = '0';
7159: if ($type eq '_LC_adv') {
7160: $unset = '';
7161: }
7162: } else {
7163: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
7164: $confhash{$item}{$type} = 1;
7165: } else {
7166: $confhash{$item}{$type} = 0;
7167: }
7168: }
7169: if (ref($domconfig{$action}) eq 'HASH') {
7170: if ($action eq 'requestauthor') {
7171: if ($domconfig{$action}{$type} ne $confhash{$type}) {
7172: $changes{$type} = 1;
7173: }
7174: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
7175: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
7176: $changes{$item}{$type} = 1;
7177: }
7178: } else {
7179: if ($context eq 'requestcourses') {
7180: if ($confhash{$item}{$type} ne $unset) {
7181: $changes{$item}{$type} = 1;
7182: }
7183: } else {
7184: if (!$confhash{$item}{$type}) {
7185: $changes{$item}{$type} = 1;
7186: }
7187: }
7188: }
7189: } else {
7190: if ($context eq 'requestcourses') {
7191: if ($confhash{$item}{$type} ne $unset) {
7192: $changes{$item}{$type} = 1;
7193: }
7194: } elsif ($context eq 'requestauthor') {
7195: if ($confhash{$type} ne $unset) {
7196: $changes{$type} = 1;
7197: }
7198: } else {
7199: if (!$confhash{$item}{$type}) {
7200: $changes{$item}{$type} = 1;
7201: }
7202: }
7203: }
7204: }
7205: }
7206: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
7207: if (ref($domconfig{'quotas'}) eq 'HASH') {
7208: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7209: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
7210: if (exists($confhash{'defaultquota'}{$key})) {
7211: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
7212: $changes{'defaultquota'}{$key} = 1;
7213: }
7214: } else {
7215: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
7216: }
7217: }
7218: } else {
7219: foreach my $key (keys(%{$domconfig{'quotas'}})) {
7220: if (exists($confhash{'defaultquota'}{$key})) {
7221: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
7222: $changes{'defaultquota'}{$key} = 1;
7223: }
7224: } else {
7225: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
7226: }
7227: }
7228: }
7229: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7230: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
7231: if (exists($confhash{'authorquota'}{$key})) {
7232: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
7233: $changes{'authorquota'}{$key} = 1;
7234: }
7235: } else {
7236: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
7237: }
7238: }
7239: }
7240: }
7241: if (ref($confhash{'defaultquota'}) eq 'HASH') {
7242: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
7243: if (ref($domconfig{'quotas'}) eq 'HASH') {
7244: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7245: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
7246: $changes{'defaultquota'}{$key} = 1;
7247: }
7248: } else {
7249: if (!exists($domconfig{'quotas'}{$key})) {
7250: $changes{'defaultquota'}{$key} = 1;
7251: }
7252: }
7253: } else {
7254: $changes{'defaultquota'}{$key} = 1;
7255: }
7256: }
7257: }
7258: if (ref($confhash{'authorquota'}) eq 'HASH') {
7259: foreach my $key (keys(%{$confhash{'authorquota'}})) {
7260: if (ref($domconfig{'quotas'}) eq 'HASH') {
7261: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7262: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
7263: $changes{'authorquota'}{$key} = 1;
7264: }
7265: } else {
7266: $changes{'authorquota'}{$key} = 1;
7267: }
7268: } else {
7269: $changes{'authorquota'}{$key} = 1;
7270: }
7271: }
7272: }
7273: }
7274:
7275: if ($context eq 'requestauthor') {
7276: $domdefaults{'requestauthor'} = \%confhash;
7277: } else {
7278: foreach my $key (keys(%confhash)) {
7279: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
7280: $domdefaults{$key} = $confhash{$key};
7281: }
7282: }
7283: }
7284:
7285: my %quotahash = (
7286: $action => { %confhash }
7287: );
7288: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
7289: $dom);
7290: if ($putresult eq 'ok') {
7291: if (keys(%changes) > 0) {
7292: my $cachetime = 24*60*60;
7293: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
7294: if (ref($lastactref) eq 'HASH') {
7295: $lastactref->{'domdefaults'} = 1;
7296: }
7297: $resulttext = &mt('Changes made:').'<ul>';
7298: unless (($context eq 'requestcourses') ||
7299: ($context eq 'requestauthor')) {
7300: if (ref($changes{'defaultquota'}) eq 'HASH') {
7301: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
7302: foreach my $type (@{$types},'default') {
7303: if (defined($changes{'defaultquota'}{$type})) {
7304: my $typetitle = $usertypes->{$type};
7305: if ($type eq 'default') {
7306: $typetitle = $othertitle;
7307: }
7308: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
7309: }
7310: }
7311: $resulttext .= '</ul></li>';
7312: }
7313: if (ref($changes{'authorquota'}) eq 'HASH') {
7314: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
7315: foreach my $type (@{$types},'default') {
7316: if (defined($changes{'authorquota'}{$type})) {
7317: my $typetitle = $usertypes->{$type};
7318: if ($type eq 'default') {
7319: $typetitle = $othertitle;
7320: }
7321: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
7322: }
7323: }
7324: $resulttext .= '</ul></li>';
7325: }
7326: }
7327: my %newenv;
7328: foreach my $item (@usertools) {
7329: my (%haschgs,%inconf);
7330: if ($context eq 'requestauthor') {
7331: %haschgs = %changes;
7332: %inconf = %confhash;
7333: } else {
7334: if (ref($changes{$item}) eq 'HASH') {
7335: %haschgs = %{$changes{$item}};
7336: }
7337: if (ref($confhash{$item}) eq 'HASH') {
7338: %inconf = %{$confhash{$item}};
7339: }
7340: }
7341: if (keys(%haschgs) > 0) {
7342: my $newacc =
7343: &Apache::lonnet::usertools_access($env{'user.name'},
7344: $env{'user.domain'},
7345: $item,'reload',$context);
7346: if (($context eq 'requestcourses') ||
7347: ($context eq 'requestauthor')) {
7348: if ($env{'environment.canrequest.'.$item} ne $newacc) {
7349: $newenv{'environment.canrequest.'.$item} = $newacc;
7350: }
7351: } else {
7352: if ($env{'environment.availabletools.'.$item} ne $newacc) {
7353: $newenv{'environment.availabletools.'.$item} = $newacc;
7354: }
7355: }
7356: unless ($context eq 'requestauthor') {
7357: $resulttext .= '<li>'.$titles{$item}.'<ul>';
7358: }
7359: foreach my $type (@{$types},'default','_LC_adv') {
7360: if ($haschgs{$type}) {
7361: my $typetitle = $usertypes->{$type};
7362: if ($type eq 'default') {
7363: $typetitle = $othertitle;
7364: } elsif ($type eq '_LC_adv') {
7365: $typetitle = 'LON-CAPA Advanced Users';
7366: }
7367: if ($inconf{$type}) {
7368: if ($context eq 'requestcourses') {
7369: my $cond;
7370: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
7371: if ($1 eq '') {
7372: $cond = &mt('(Automatic processing of any request).');
7373: } else {
7374: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
7375: }
7376: } else {
7377: $cond = $conditions{$inconf{$type}};
7378: }
7379: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
7380: } elsif ($context eq 'requestauthor') {
7381: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
7382: $titles{$inconf{$type}},$typetitle);
7383:
7384: } else {
7385: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
7386: }
7387: } else {
7388: if ($type eq '_LC_adv') {
7389: if ($inconf{$type} eq '0') {
7390: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7391: } else {
7392: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
7393: }
7394: } else {
7395: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7396: }
7397: }
7398: }
7399: }
7400: unless ($context eq 'requestauthor') {
7401: $resulttext .= '</ul></li>';
7402: }
7403: }
7404: }
7405: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
7406: if (ref($changes{'notify'}) eq 'HASH') {
7407: if ($changes{'notify'}{'approval'}) {
7408: if (ref($confhash{'notify'}) eq 'HASH') {
7409: if ($confhash{'notify'}{'approval'}) {
7410: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
7411: } else {
7412: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
7413: }
7414: }
7415: }
7416: }
7417: }
7418: if ($action eq 'requestcourses') {
7419: my @offon = ('off','on');
7420: if ($changes{'uniquecode'}) {
7421: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7422: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
7423: $resulttext .= '<li>'.
7424: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
7425: '</li>';
7426: } else {
7427: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
7428: '</li>';
7429: }
7430: }
7431: foreach my $type ('textbooks','templates') {
7432: if (ref($changes{$type}) eq 'HASH') {
7433: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
7434: foreach my $key (sort(keys(%{$changes{$type}}))) {
7435: my %coursehash = &Apache::lonnet::coursedescription($key);
7436: my $coursetitle = $coursehash{'description'};
7437: my $position = $confhash{$type}{$key}{'order'} + 1;
7438: $resulttext .= '<li>';
7439: foreach my $item ('subject','title','publisher','author') {
7440: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7441: ($type eq 'templates'));
7442: my $name = $item.':';
7443: $name =~ s/^(\w)/\U$1/;
7444: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
7445: }
7446: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
7447: if ($type eq 'textbooks') {
7448: if ($confhash{$type}{$key}{'image'}) {
7449: $resulttext .= ' '.&mt('Image: [_1]',
7450: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
7451: ' alt="Textbook cover" />').'<br />';
7452: }
7453: }
7454: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
7455: }
7456: $resulttext .= '</ul></li>';
7457: }
7458: }
7459: if (ref($changes{'validation'}) eq 'HASH') {
7460: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
7461: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
7462: foreach my $item (@{$validationitemsref}) {
7463: if (exists($changes{'validation'}{$item})) {
7464: if ($item eq 'markup') {
7465: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7466: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
7467: } else {
7468: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7469: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
7470: }
7471: }
7472: }
7473: if (exists($changes{'validation'}{'dc'})) {
7474: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
7475: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
7476: }
7477: }
7478: }
7479: }
7480: $resulttext .= '</ul>';
7481: if (keys(%newenv)) {
7482: &Apache::lonnet::appenv(\%newenv);
7483: }
7484: } else {
7485: if ($context eq 'requestcourses') {
7486: $resulttext = &mt('No changes made to rights to request creation of courses.');
7487: } elsif ($context eq 'requestauthor') {
7488: $resulttext = &mt('No changes made to rights to request author space.');
7489: } else {
7490: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
7491: }
7492: }
7493: } else {
7494: $resulttext = '<span class="LC_error">'.
7495: &mt('An error occurred: [_1]',$putresult).'</span>';
7496: }
7497: if ($errors) {
7498: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
7499: '<ul>'.$errors.'</ul></p>';
7500: }
7501: return $resulttext;
7502: }
7503:
7504: sub process_textbook_image {
7505: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
7506: my $filename = $env{'form.'.$caller.'.filename'};
7507: my ($error,$url);
7508: my ($width,$height) = (50,50);
7509: if ($configuserok eq 'ok') {
7510: if ($switchserver) {
7511: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
7512: $switchserver);
7513: } elsif ($author_ok eq 'ok') {
7514: my ($result,$imageurl) =
7515: &publishlogo($r,'upload',$caller,$dom,$confname,
7516: "$type/$dom/$cnum/cover",$width,$height);
7517: if ($result eq 'ok') {
7518: $url = $imageurl;
7519: } else {
7520: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
7521: }
7522: } else {
7523: $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);
7524: }
7525: } else {
7526: $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);
7527: }
7528: return ($url,$error);
7529: }
7530:
7531: sub modify_autoenroll {
7532: my ($dom,$lastactref,%domconfig) = @_;
7533: my ($resulttext,%changes);
7534: my %currautoenroll;
7535: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
7536: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
7537: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
7538: }
7539: }
7540: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
7541: my %title = ( run => 'Auto-enrollment active',
7542: sender => 'Sender for notification messages',
7543: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
7544: my @offon = ('off','on');
7545: my $sender_uname = $env{'form.sender_uname'};
7546: my $sender_domain = $env{'form.sender_domain'};
7547: if ($sender_domain eq '') {
7548: $sender_uname = '';
7549: } elsif ($sender_uname eq '') {
7550: $sender_domain = '';
7551: }
7552: my $coowners = $env{'form.autoassign_coowners'};
7553: my %autoenrollhash = (
7554: autoenroll => { 'run' => $env{'form.autoenroll_run'},
7555: 'sender_uname' => $sender_uname,
7556: 'sender_domain' => $sender_domain,
7557: 'co-owners' => $coowners,
7558: }
7559: );
7560: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
7561: $dom);
7562: if ($putresult eq 'ok') {
7563: if (exists($currautoenroll{'run'})) {
7564: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
7565: $changes{'run'} = 1;
7566: }
7567: } elsif ($autorun) {
7568: if ($env{'form.autoenroll_run'} ne '1') {
7569: $changes{'run'} = 1;
7570: }
7571: }
7572: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
7573: $changes{'sender'} = 1;
7574: }
7575: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
7576: $changes{'sender'} = 1;
7577: }
7578: if ($currautoenroll{'co-owners'} ne '') {
7579: if ($currautoenroll{'co-owners'} ne $coowners) {
7580: $changes{'coowners'} = 1;
7581: }
7582: } elsif ($coowners) {
7583: $changes{'coowners'} = 1;
7584: }
7585: if (keys(%changes) > 0) {
7586: $resulttext = &mt('Changes made:').'<ul>';
7587: if ($changes{'run'}) {
7588: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
7589: }
7590: if ($changes{'sender'}) {
7591: if ($sender_uname eq '' || $sender_domain eq '') {
7592: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
7593: } else {
7594: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
7595: }
7596: }
7597: if ($changes{'coowners'}) {
7598: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
7599: &Apache::loncommon::devalidate_domconfig_cache($dom);
7600: if (ref($lastactref) eq 'HASH') {
7601: $lastactref->{'domainconfig'} = 1;
7602: }
7603: }
7604: $resulttext .= '</ul>';
7605: } else {
7606: $resulttext = &mt('No changes made to auto-enrollment settings');
7607: }
7608: } else {
7609: $resulttext = '<span class="LC_error">'.
7610: &mt('An error occurred: [_1]',$putresult).'</span>';
7611: }
7612: return $resulttext;
7613: }
7614:
7615: sub modify_autoupdate {
7616: my ($dom,%domconfig) = @_;
7617: my ($resulttext,%currautoupdate,%fields,%changes);
7618: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
7619: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
7620: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
7621: }
7622: }
7623: my @offon = ('off','on');
7624: my %title = &Apache::lonlocal::texthash (
7625: run => 'Auto-update:',
7626: classlists => 'Updates to user information in classlists?'
7627: );
7628: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7629: my %fieldtitles = &Apache::lonlocal::texthash (
7630: id => 'Student/Employee ID',
7631: permanentemail => 'E-mail address',
7632: lastname => 'Last Name',
7633: firstname => 'First Name',
7634: middlename => 'Middle Name',
7635: generation => 'Generation',
7636: );
7637: $othertitle = &mt('All users');
7638: if (keys(%{$usertypes}) > 0) {
7639: $othertitle = &mt('Other users');
7640: }
7641: foreach my $key (keys(%env)) {
7642: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
7643: my ($usertype,$item) = ($1,$2);
7644: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
7645: if ($usertype eq 'default') {
7646: push(@{$fields{$1}},$2);
7647: } elsif (ref($types) eq 'ARRAY') {
7648: if (grep(/^\Q$usertype\E$/,@{$types})) {
7649: push(@{$fields{$1}},$2);
7650: }
7651: }
7652: }
7653: }
7654: }
7655: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
7656: @lockablenames = sort(@lockablenames);
7657: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
7658: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7659: if (@changed) {
7660: $changes{'lockablenames'} = 1;
7661: }
7662: } else {
7663: if (@lockablenames) {
7664: $changes{'lockablenames'} = 1;
7665: }
7666: }
7667: my %updatehash = (
7668: autoupdate => { run => $env{'form.autoupdate_run'},
7669: classlists => $env{'form.classlists'},
7670: fields => {%fields},
7671: lockablenames => \@lockablenames,
7672: }
7673: );
7674: foreach my $key (keys(%currautoupdate)) {
7675: if (($key eq 'run') || ($key eq 'classlists')) {
7676: if (exists($updatehash{autoupdate}{$key})) {
7677: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
7678: $changes{$key} = 1;
7679: }
7680: }
7681: } elsif ($key eq 'fields') {
7682: if (ref($currautoupdate{$key}) eq 'HASH') {
7683: foreach my $item (@{$types},'default') {
7684: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
7685: my $change = 0;
7686: foreach my $type (@{$currautoupdate{$key}{$item}}) {
7687: if (!exists($fields{$item})) {
7688: $change = 1;
7689: last;
7690: } elsif (ref($fields{$item}) eq 'ARRAY') {
7691: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
7692: $change = 1;
7693: last;
7694: }
7695: }
7696: }
7697: if ($change) {
7698: push(@{$changes{$key}},$item);
7699: }
7700: }
7701: }
7702: }
7703: } elsif ($key eq 'lockablenames') {
7704: if (ref($currautoupdate{$key}) eq 'ARRAY') {
7705: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7706: if (@changed) {
7707: $changes{'lockablenames'} = 1;
7708: }
7709: } else {
7710: if (@lockablenames) {
7711: $changes{'lockablenames'} = 1;
7712: }
7713: }
7714: }
7715: }
7716: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
7717: if (@lockablenames) {
7718: $changes{'lockablenames'} = 1;
7719: }
7720: }
7721: foreach my $item (@{$types},'default') {
7722: if (defined($fields{$item})) {
7723: if (ref($currautoupdate{'fields'}) eq 'HASH') {
7724: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
7725: my $change = 0;
7726: if (ref($fields{$item}) eq 'ARRAY') {
7727: foreach my $type (@{$fields{$item}}) {
7728: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
7729: $change = 1;
7730: last;
7731: }
7732: }
7733: }
7734: if ($change) {
7735: push(@{$changes{'fields'}},$item);
7736: }
7737: } else {
7738: push(@{$changes{'fields'}},$item);
7739: }
7740: } else {
7741: push(@{$changes{'fields'}},$item);
7742: }
7743: }
7744: }
7745: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
7746: $dom);
7747: if ($putresult eq 'ok') {
7748: if (keys(%changes) > 0) {
7749: $resulttext = &mt('Changes made:').'<ul>';
7750: foreach my $key (sort(keys(%changes))) {
7751: if ($key eq 'lockablenames') {
7752: $resulttext .= '<li>';
7753: if (@lockablenames) {
7754: $usertypes->{'default'} = $othertitle;
7755: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
7756: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
7757: } else {
7758: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
7759: }
7760: $resulttext .= '</li>';
7761: } elsif (ref($changes{$key}) eq 'ARRAY') {
7762: foreach my $item (@{$changes{$key}}) {
7763: my @newvalues;
7764: foreach my $type (@{$fields{$item}}) {
7765: push(@newvalues,$fieldtitles{$type});
7766: }
7767: my $newvaluestr;
7768: if (@newvalues > 0) {
7769: $newvaluestr = join(', ',@newvalues);
7770: } else {
7771: $newvaluestr = &mt('none');
7772: }
7773: if ($item eq 'default') {
7774: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
7775: } else {
7776: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
7777: }
7778: }
7779: } else {
7780: my $newvalue;
7781: if ($key eq 'run') {
7782: $newvalue = $offon[$env{'form.autoupdate_run'}];
7783: } else {
7784: $newvalue = $offon[$env{'form.'.$key}];
7785: }
7786: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
7787: }
7788: }
7789: $resulttext .= '</ul>';
7790: } else {
7791: $resulttext = &mt('No changes made to autoupdates');
7792: }
7793: } else {
7794: $resulttext = '<span class="LC_error">'.
7795: &mt('An error occurred: [_1]',$putresult).'</span>';
7796: }
7797: return $resulttext;
7798: }
7799:
7800: sub modify_autocreate {
7801: my ($dom,%domconfig) = @_;
7802: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
7803: if (ref($domconfig{'autocreate'}) eq 'HASH') {
7804: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
7805: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
7806: }
7807: }
7808: my %title= ( xml => 'Auto-creation of courses in XML course description files',
7809: req => 'Auto-creation of validated requests for official courses',
7810: xmldc => 'Identity of course creator of courses from XML files',
7811: );
7812: my @types = ('xml','req');
7813: foreach my $item (@types) {
7814: $newvals{$item} = $env{'form.autocreate_'.$item};
7815: $newvals{$item} =~ s/\D//g;
7816: $newvals{$item} = 0 if ($newvals{$item} eq '');
7817: }
7818: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
7819: my %domcoords = &get_active_dcs($dom);
7820: unless (exists($domcoords{$newvals{'xmldc'}})) {
7821: $newvals{'xmldc'} = '';
7822: }
7823: %autocreatehash = (
7824: autocreate => { xml => $newvals{'xml'},
7825: req => $newvals{'req'},
7826: }
7827: );
7828: if ($newvals{'xmldc'} ne '') {
7829: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
7830: }
7831: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
7832: $dom);
7833: if ($putresult eq 'ok') {
7834: my @items = @types;
7835: if ($newvals{'xml'}) {
7836: push(@items,'xmldc');
7837: }
7838: foreach my $item (@items) {
7839: if (exists($currautocreate{$item})) {
7840: if ($currautocreate{$item} ne $newvals{$item}) {
7841: $changes{$item} = 1;
7842: }
7843: } elsif ($newvals{$item}) {
7844: $changes{$item} = 1;
7845: }
7846: }
7847: if (keys(%changes) > 0) {
7848: my @offon = ('off','on');
7849: $resulttext = &mt('Changes made:').'<ul>';
7850: foreach my $item (@types) {
7851: if ($changes{$item}) {
7852: my $newtxt = $offon[$newvals{$item}];
7853: $resulttext .= '<li>'.
7854: &mt("$title{$item} set to [_1]$newtxt [_2]",
7855: '<b>','</b>').
7856: '</li>';
7857: }
7858: }
7859: if ($changes{'xmldc'}) {
7860: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
7861: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
7862: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
7863: }
7864: $resulttext .= '</ul>';
7865: } else {
7866: $resulttext = &mt('No changes made to auto-creation settings');
7867: }
7868: } else {
7869: $resulttext = '<span class="LC_error">'.
7870: &mt('An error occurred: [_1]',$putresult).'</span>';
7871: }
7872: return $resulttext;
7873: }
7874:
7875: sub modify_directorysrch {
7876: my ($dom,%domconfig) = @_;
7877: my ($resulttext,%changes);
7878: my %currdirsrch;
7879: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
7880: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
7881: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
7882: }
7883: }
7884: my %title = ( available => 'Directory search available',
7885: localonly => 'Other domains can search',
7886: searchby => 'Search types',
7887: searchtypes => 'Search latitude');
7888: my @offon = ('off','on');
7889: my @otherdoms = ('Yes','No');
7890:
7891: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
7892: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
7893: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
7894:
7895: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7896: if (keys(%{$usertypes}) == 0) {
7897: @cansearch = ('default');
7898: } else {
7899: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
7900: foreach my $type (@{$currdirsrch{'cansearch'}}) {
7901: if (!grep(/^\Q$type\E$/,@cansearch)) {
7902: push(@{$changes{'cansearch'}},$type);
7903: }
7904: }
7905: foreach my $type (@cansearch) {
7906: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
7907: push(@{$changes{'cansearch'}},$type);
7908: }
7909: }
7910: } else {
7911: push(@{$changes{'cansearch'}},@cansearch);
7912: }
7913: }
7914:
7915: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
7916: foreach my $by (@{$currdirsrch{'searchby'}}) {
7917: if (!grep(/^\Q$by\E$/,@searchby)) {
7918: push(@{$changes{'searchby'}},$by);
7919: }
7920: }
7921: foreach my $by (@searchby) {
7922: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
7923: push(@{$changes{'searchby'}},$by);
7924: }
7925: }
7926: } else {
7927: push(@{$changes{'searchby'}},@searchby);
7928: }
7929:
7930: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
7931: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
7932: if (!grep(/^\Q$type\E$/,@searchtypes)) {
7933: push(@{$changes{'searchtypes'}},$type);
7934: }
7935: }
7936: foreach my $type (@searchtypes) {
7937: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
7938: push(@{$changes{'searchtypes'}},$type);
7939: }
7940: }
7941: } else {
7942: if (exists($currdirsrch{'searchtypes'})) {
7943: foreach my $type (@searchtypes) {
7944: if ($type ne $currdirsrch{'searchtypes'}) {
7945: push(@{$changes{'searchtypes'}},$type);
7946: }
7947: }
7948: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
7949: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
7950: }
7951: } else {
7952: push(@{$changes{'searchtypes'}},@searchtypes);
7953: }
7954: }
7955:
7956: my %dirsrch_hash = (
7957: directorysrch => { available => $env{'form.dirsrch_available'},
7958: cansearch => \@cansearch,
7959: localonly => $env{'form.dirsrch_localonly'},
7960: searchby => \@searchby,
7961: searchtypes => \@searchtypes,
7962: }
7963: );
7964: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
7965: $dom);
7966: if ($putresult eq 'ok') {
7967: if (exists($currdirsrch{'available'})) {
7968: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
7969: $changes{'available'} = 1;
7970: }
7971: } else {
7972: if ($env{'form.dirsrch_available'} eq '1') {
7973: $changes{'available'} = 1;
7974: }
7975: }
7976: if (exists($currdirsrch{'localonly'})) {
7977: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
7978: $changes{'localonly'} = 1;
7979: }
7980: } else {
7981: if ($env{'form.dirsrch_localonly'} eq '1') {
7982: $changes{'localonly'} = 1;
7983: }
7984: }
7985: if (keys(%changes) > 0) {
7986: $resulttext = &mt('Changes made:').'<ul>';
7987: if ($changes{'available'}) {
7988: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
7989: }
7990: if ($changes{'localonly'}) {
7991: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
7992: }
7993:
7994: if (ref($changes{'cansearch'}) eq 'ARRAY') {
7995: my $chgtext;
7996: if (ref($usertypes) eq 'HASH') {
7997: if (keys(%{$usertypes}) > 0) {
7998: foreach my $type (@{$types}) {
7999: if (grep(/^\Q$type\E$/,@cansearch)) {
8000: $chgtext .= $usertypes->{$type}.'; ';
8001: }
8002: }
8003: if (grep(/^default$/,@cansearch)) {
8004: $chgtext .= $othertitle;
8005: } else {
8006: $chgtext =~ s/\; $//;
8007: }
8008: $resulttext .=
8009: '<li>'.
8010: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
8011: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
8012: '</li>';
8013: }
8014: }
8015: }
8016: if (ref($changes{'searchby'}) eq 'ARRAY') {
8017: my ($searchtitles,$titleorder) = &sorted_searchtitles();
8018: my $chgtext;
8019: foreach my $type (@{$titleorder}) {
8020: if (grep(/^\Q$type\E$/,@searchby)) {
8021: if (defined($searchtitles->{$type})) {
8022: $chgtext .= $searchtitles->{$type}.'; ';
8023: }
8024: }
8025: }
8026: $chgtext =~ s/\; $//;
8027: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
8028: }
8029: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
8030: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
8031: my $chgtext;
8032: foreach my $type (@{$srchtypeorder}) {
8033: if (grep(/^\Q$type\E$/,@searchtypes)) {
8034: if (defined($srchtypes_desc->{$type})) {
8035: $chgtext .= $srchtypes_desc->{$type}.'; ';
8036: }
8037: }
8038: }
8039: $chgtext =~ s/\; $//;
8040: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
8041: }
8042: $resulttext .= '</ul>';
8043: } else {
8044: $resulttext = &mt('No changes made to institution directory search settings');
8045: }
8046: } else {
8047: $resulttext = '<span class="LC_error">'.
8048: &mt('An error occurred: [_1]',$putresult).'</span>';
8049: }
8050: return $resulttext;
8051: }
8052:
8053: sub modify_contacts {
8054: my ($dom,$lastactref,%domconfig) = @_;
8055: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
8056: if (ref($domconfig{'contacts'}) eq 'HASH') {
8057: foreach my $key (keys(%{$domconfig{'contacts'}})) {
8058: $currsetting{$key} = $domconfig{'contacts'}{$key};
8059: }
8060: }
8061: my (%others,%to,%bcc);
8062: my @contacts = ('supportemail','adminemail');
8063: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
8064: 'requestsmail','updatesmail','idconflictsmail');
8065: my @toggles = ('reporterrors','reportupdates');
8066: foreach my $type (@mailings) {
8067: @{$newsetting{$type}} =
8068: &Apache::loncommon::get_env_multiple('form.'.$type);
8069: foreach my $item (@contacts) {
8070: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
8071: $contacts_hash{contacts}{$type}{$item} = 1;
8072: } else {
8073: $contacts_hash{contacts}{$type}{$item} = 0;
8074: }
8075: }
8076: $others{$type} = $env{'form.'.$type.'_others'};
8077: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
8078: if ($type eq 'helpdeskmail') {
8079: $bcc{$type} = $env{'form.'.$type.'_bcc'};
8080: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
8081: }
8082: }
8083: foreach my $item (@contacts) {
8084: $to{$item} = $env{'form.'.$item};
8085: $contacts_hash{'contacts'}{$item} = $to{$item};
8086: }
8087: foreach my $item (@toggles) {
8088: if ($env{'form.'.$item} =~ /^(0|1)$/) {
8089: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
8090: }
8091: }
8092: if (keys(%currsetting) > 0) {
8093: foreach my $item (@contacts) {
8094: if ($to{$item} ne $currsetting{$item}) {
8095: $changes{$item} = 1;
8096: }
8097: }
8098: foreach my $type (@mailings) {
8099: foreach my $item (@contacts) {
8100: if (ref($currsetting{$type}) eq 'HASH') {
8101: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
8102: push(@{$changes{$type}},$item);
8103: }
8104: } else {
8105: push(@{$changes{$type}},@{$newsetting{$type}});
8106: }
8107: }
8108: if ($others{$type} ne $currsetting{$type}{'others'}) {
8109: push(@{$changes{$type}},'others');
8110: }
8111: if ($type eq 'helpdeskmail') {
8112: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
8113: push(@{$changes{$type}},'bcc');
8114: }
8115: }
8116: }
8117: } else {
8118: my %default;
8119: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
8120: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
8121: $default{'errormail'} = 'adminemail';
8122: $default{'packagesmail'} = 'adminemail';
8123: $default{'helpdeskmail'} = 'supportemail';
8124: $default{'lonstatusmail'} = 'adminemail';
8125: $default{'requestsmail'} = 'adminemail';
8126: $default{'updatesmail'} = 'adminemail';
8127: foreach my $item (@contacts) {
8128: if ($to{$item} ne $default{$item}) {
8129: $changes{$item} = 1;
8130: }
8131: }
8132: foreach my $type (@mailings) {
8133: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
8134:
8135: push(@{$changes{$type}},@{$newsetting{$type}});
8136: }
8137: if ($others{$type} ne '') {
8138: push(@{$changes{$type}},'others');
8139: }
8140: if ($type eq 'helpdeskmail') {
8141: if ($bcc{$type} ne '') {
8142: push(@{$changes{$type}},'bcc');
8143: }
8144: }
8145: }
8146: }
8147: foreach my $item (@toggles) {
8148: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
8149: $changes{$item} = 1;
8150: } elsif ((!$env{'form.'.$item}) &&
8151: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
8152: $changes{$item} = 1;
8153: }
8154: }
8155: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
8156: $dom);
8157: if ($putresult eq 'ok') {
8158: if (keys(%changes) > 0) {
8159: &Apache::loncommon::devalidate_domconfig_cache($dom);
8160: if (ref($lastactref) eq 'HASH') {
8161: $lastactref->{'domainconfig'} = 1;
8162: }
8163: my ($titles,$short_titles) = &contact_titles();
8164: $resulttext = &mt('Changes made:').'<ul>';
8165: foreach my $item (@contacts) {
8166: if ($changes{$item}) {
8167: $resulttext .= '<li>'.$titles->{$item}.
8168: &mt(' set to: ').
8169: '<span class="LC_cusr_emph">'.
8170: $to{$item}.'</span></li>';
8171: }
8172: }
8173: foreach my $type (@mailings) {
8174: if (ref($changes{$type}) eq 'ARRAY') {
8175: $resulttext .= '<li>'.$titles->{$type}.': ';
8176: my @text;
8177: foreach my $item (@{$newsetting{$type}}) {
8178: push(@text,$short_titles->{$item});
8179: }
8180: if ($others{$type} ne '') {
8181: push(@text,$others{$type});
8182: }
8183: $resulttext .= '<span class="LC_cusr_emph">'.
8184: join(', ',@text).'</span>';
8185: if ($type eq 'helpdeskmail') {
8186: if ($bcc{$type} ne '') {
8187: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
8188: }
8189: }
8190: $resulttext .= '</li>';
8191: }
8192: }
8193: my @offon = ('off','on');
8194: if ($changes{'reporterrors'}) {
8195: $resulttext .= '<li>'.
8196: &mt('E-mail error reports to [_1] set to "'.
8197: $offon[$env{'form.reporterrors'}].'".',
8198: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8199: &mt('LON-CAPA core group - MSU'),600,500)).
8200: '</li>';
8201: }
8202: if ($changes{'reportupdates'}) {
8203: $resulttext .= '<li>'.
8204: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
8205: $offon[$env{'form.reportupdates'}].'".',
8206: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8207: &mt('LON-CAPA core group - MSU'),600,500)).
8208: '</li>';
8209: }
8210: $resulttext .= '</ul>';
8211: } else {
8212: $resulttext = &mt('No changes made to contact information');
8213: }
8214: } else {
8215: $resulttext = '<span class="LC_error">'.
8216: &mt('An error occurred: [_1].',$putresult).'</span>';
8217: }
8218: return $resulttext;
8219: }
8220:
8221: sub modify_usercreation {
8222: my ($dom,%domconfig) = @_;
8223: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
8224: my $warningmsg;
8225: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8226: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
8227: if ($key eq 'cancreate') {
8228: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8229: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8230: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8231: ($item eq 'captcha') || ($item eq 'recaptchakeys')) {
8232: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8233: } else {
8234: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8235: }
8236: }
8237: }
8238: } elsif ($key eq 'email_rule') {
8239: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8240: } else {
8241: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
8242: }
8243: }
8244: }
8245: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
8246: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
8247: my @contexts = ('author','course','requestcrs');
8248: foreach my $item(@contexts) {
8249: $cancreate{$item} = $env{'form.can_createuser_'.$item};
8250: }
8251: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8252: foreach my $item (@contexts) {
8253: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
8254: push(@{$changes{'cancreate'}},$item);
8255: }
8256: }
8257: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
8258: foreach my $item (@contexts) {
8259: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
8260: if ($cancreate{$item} ne 'any') {
8261: push(@{$changes{'cancreate'}},$item);
8262: }
8263: } else {
8264: if ($cancreate{$item} ne 'none') {
8265: push(@{$changes{'cancreate'}},$item);
8266: }
8267: }
8268: }
8269: } else {
8270: foreach my $item (@contexts) {
8271: push(@{$changes{'cancreate'}},$item);
8272: }
8273: }
8274:
8275: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
8276: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
8277: if (!grep(/^\Q$type\E$/,@username_rule)) {
8278: push(@{$changes{'username_rule'}},$type);
8279: }
8280: }
8281: foreach my $type (@username_rule) {
8282: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
8283: push(@{$changes{'username_rule'}},$type);
8284: }
8285: }
8286: } else {
8287: push(@{$changes{'username_rule'}},@username_rule);
8288: }
8289:
8290: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
8291: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
8292: if (!grep(/^\Q$type\E$/,@id_rule)) {
8293: push(@{$changes{'id_rule'}},$type);
8294: }
8295: }
8296: foreach my $type (@id_rule) {
8297: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
8298: push(@{$changes{'id_rule'}},$type);
8299: }
8300: }
8301: } else {
8302: push(@{$changes{'id_rule'}},@id_rule);
8303: }
8304:
8305: my @authen_contexts = ('author','course','domain');
8306: my @authtypes = ('int','krb4','krb5','loc');
8307: my %authhash;
8308: foreach my $item (@authen_contexts) {
8309: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
8310: foreach my $auth (@authtypes) {
8311: if (grep(/^\Q$auth\E$/,@authallowed)) {
8312: $authhash{$item}{$auth} = 1;
8313: } else {
8314: $authhash{$item}{$auth} = 0;
8315: }
8316: }
8317: }
8318: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
8319: foreach my $item (@authen_contexts) {
8320: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
8321: foreach my $auth (@authtypes) {
8322: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
8323: push(@{$changes{'authtypes'}},$item);
8324: last;
8325: }
8326: }
8327: }
8328: }
8329: } else {
8330: foreach my $item (@authen_contexts) {
8331: push(@{$changes{'authtypes'}},$item);
8332: }
8333: }
8334:
8335: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
8336: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
8337: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
8338: $save_usercreate{'id_rule'} = \@id_rule;
8339: $save_usercreate{'username_rule'} = \@username_rule,
8340: $save_usercreate{'authtypes'} = \%authhash;
8341:
8342: my %usercreation_hash = (
8343: usercreation => \%save_usercreate,
8344: );
8345:
8346: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
8347: $dom);
8348:
8349: if ($putresult eq 'ok') {
8350: if (keys(%changes) > 0) {
8351: $resulttext = &mt('Changes made:').'<ul>';
8352: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8353: my %lt = &usercreation_types();
8354: foreach my $type (@{$changes{'cancreate'}}) {
8355: my $chgtext = $lt{$type}.', ';
8356: if ($cancreate{$type} eq 'none') {
8357: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
8358: } elsif ($cancreate{$type} eq 'any') {
8359: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
8360: } elsif ($cancreate{$type} eq 'official') {
8361: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
8362: } elsif ($cancreate{$type} eq 'unofficial') {
8363: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
8364: }
8365: $resulttext .= '<li>'.$chgtext.'</li>';
8366: }
8367: }
8368: if (ref($changes{'username_rule'}) eq 'ARRAY') {
8369: my ($rules,$ruleorder) =
8370: &Apache::lonnet::inst_userrules($dom,'username');
8371: my $chgtext = '<ul>';
8372: foreach my $type (@username_rule) {
8373: if (ref($rules->{$type}) eq 'HASH') {
8374: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
8375: }
8376: }
8377: $chgtext .= '</ul>';
8378: if (@username_rule > 0) {
8379: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8380: } else {
8381: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
8382: }
8383: }
8384: if (ref($changes{'id_rule'}) eq 'ARRAY') {
8385: my ($idrules,$idruleorder) =
8386: &Apache::lonnet::inst_userrules($dom,'id');
8387: my $chgtext = '<ul>';
8388: foreach my $type (@id_rule) {
8389: if (ref($idrules->{$type}) eq 'HASH') {
8390: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
8391: }
8392: }
8393: $chgtext .= '</ul>';
8394: if (@id_rule > 0) {
8395: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8396: } else {
8397: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
8398: }
8399: }
8400: my %authname = &authtype_names();
8401: my %context_title = &context_names();
8402: if (ref($changes{'authtypes'}) eq 'ARRAY') {
8403: my $chgtext = '<ul>';
8404: foreach my $type (@{$changes{'authtypes'}}) {
8405: my @allowed;
8406: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
8407: foreach my $auth (@authtypes) {
8408: if ($authhash{$type}{$auth}) {
8409: push(@allowed,$authname{$auth});
8410: }
8411: }
8412: if (@allowed > 0) {
8413: $chgtext .= join(', ',@allowed).'</li>';
8414: } else {
8415: $chgtext .= &mt('none').'</li>';
8416: }
8417: }
8418: $chgtext .= '</ul>';
8419: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
8420: $resulttext .= '</li>';
8421: }
8422: $resulttext .= '</ul>';
8423: } else {
8424: $resulttext = &mt('No changes made to user creation settings');
8425: }
8426: } else {
8427: $resulttext = '<span class="LC_error">'.
8428: &mt('An error occurred: [_1]',$putresult).'</span>';
8429: }
8430: if ($warningmsg ne '') {
8431: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
8432: }
8433: return $resulttext;
8434: }
8435:
8436: sub modify_selfcreation {
8437: my ($dom,%domconfig) = @_;
8438: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
8439: my (%save_usercreate,%save_usermodify);
8440: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8441: if (ref($types) eq 'ARRAY') {
8442: $usertypes->{'default'} = $othertitle;
8443: push(@{$types},'default');
8444: }
8445: #
8446: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
8447: #
8448: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8449: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
8450: if ($key eq 'cancreate') {
8451: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8452: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8453: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8454: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
8455: ($item eq 'emailusername') || ($item eq 'notify') ||
8456: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
8457: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8458: } else {
8459: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8460: }
8461: }
8462: }
8463: } elsif ($key eq 'email_rule') {
8464: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
8465: } else {
8466: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8467: }
8468: }
8469: }
8470: #
8471: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
8472: #
8473: if (ref($domconfig{'usermodification'}) eq 'HASH') {
8474: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
8475: if ($key eq 'selfcreate') {
8476: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
8477: } else {
8478: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
8479: }
8480: }
8481: }
8482:
8483: my @contexts = ('selfcreate');
8484: @{$cancreate{'selfcreate'}} = ();
8485: %{$cancreate{'emailusername'}} = ();
8486: @{$cancreate{'statustocreate'}} = ();
8487: %{$cancreate{'selfcreateprocessing'}} = ();
8488: %{$cancreate{'shibenv'}} = ();
8489: my %selfcreatetypes = (
8490: sso => 'users authenticated by institutional single sign on',
8491: login => 'users authenticated by institutional log-in',
8492: email => 'users who provide a valid e-mail address for use as username',
8493: );
8494: #
8495: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
8496: # is permitted.
8497: #
8498:
8499: my @statuses;
8500: if (ref($domconfig{'inststatus'}) eq 'HASH') {
8501: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
8502: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
8503: }
8504: }
8505: push(@statuses,'default');
8506:
8507: foreach my $item ('login','sso','email') {
8508: if ($item eq 'email') {
8509: if ($env{'form.cancreate_email'}) {
8510: push(@{$cancreate{'selfcreate'}},'email');
8511: push(@contexts,'selfcreateprocessing');
8512: foreach my $type (@statuses) {
8513: if ($type eq 'default') {
8514: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
8515: } else {
8516: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
8517: }
8518: }
8519: }
8520: } else {
8521: if ($env{'form.cancreate_'.$item}) {
8522: push(@{$cancreate{'selfcreate'}},$item);
8523: }
8524: }
8525: }
8526: my (@email_rule,%userinfo,%savecaptcha);
8527: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
8528: #
8529: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
8530: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
8531: #
8532:
8533: if ($env{'form.cancreate_email'}) {
8534: push(@contexts,'emailusername');
8535: if (ref($types) eq 'ARRAY') {
8536: foreach my $type (@{$types}) {
8537: if (ref($infofields) eq 'ARRAY') {
8538: foreach my $field (@{$infofields}) {
8539: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
8540: $cancreate{'emailusername'}{$type}{$field} = $1;
8541: }
8542: }
8543: }
8544: }
8545: }
8546: #
8547: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
8548: # queued requests for self-creation of account using e-mail address as username
8549: #
8550:
8551: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
8552: @approvalnotify = sort(@approvalnotify);
8553: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
8554: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8555: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
8556: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
8557: push(@{$changes{'cancreate'}},'notify');
8558: }
8559: } else {
8560: if ($cancreate{'notify'}{'approval'}) {
8561: push(@{$changes{'cancreate'}},'notify');
8562: }
8563: }
8564: } elsif ($cancreate{'notify'}{'approval'}) {
8565: push(@{$changes{'cancreate'}},'notify');
8566: }
8567:
8568: #
8569: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
8570: #
8571: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
8572: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
8573: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
8574: if (@{$curr_usercreation{'email_rule'}} > 0) {
8575: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
8576: if (!grep(/^\Q$type\E$/,@email_rule)) {
8577: push(@{$changes{'email_rule'}},$type);
8578: }
8579: }
8580: }
8581: if (@email_rule > 0) {
8582: foreach my $type (@email_rule) {
8583: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
8584: push(@{$changes{'email_rule'}},$type);
8585: }
8586: }
8587: }
8588: } elsif (@email_rule > 0) {
8589: push(@{$changes{'email_rule'}},@email_rule);
8590: }
8591: }
8592: #
8593: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
8594: # institutional log-in.
8595: #
8596: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
8597: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8598: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
8599: ($domdefaults{'auth_def'} eq 'localauth'))) {
8600: $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.').' '.
8601: &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.');
8602: }
8603: }
8604: my @fields = ('lastname','firstname','middlename','generation',
8605: 'permanentemail','id');
8606: my @shibfields = (@fields,'inststatus');
8607: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8608: #
8609: # Where usernames may created for institutional log-in and/or institutional single sign on:
8610: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
8611: # may self-create accounts
8612: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
8613: # which the user may supply, if institutional data is unavailable.
8614: #
8615: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
8616: if (ref($types) eq 'ARRAY') {
8617: if (@{$types} > 1) {
8618: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
8619: push(@contexts,'statustocreate');
8620: } else {
8621: undef($cancreate{'statustocreate'});
8622: }
8623: foreach my $type (@{$types}) {
8624: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
8625: foreach my $field (@fields) {
8626: if (grep(/^\Q$field\E$/,@modifiable)) {
8627: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
8628: } else {
8629: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
8630: }
8631: }
8632: }
8633: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
8634: foreach my $type (@{$types}) {
8635: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
8636: foreach my $field (@fields) {
8637: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
8638: $curr_usermodify{'selfcreate'}{$type}{$field}) {
8639: push(@{$changes{'selfcreate'}},$type);
8640: last;
8641: }
8642: }
8643: }
8644: }
8645: } else {
8646: foreach my $type (@{$types}) {
8647: push(@{$changes{'selfcreate'}},$type);
8648: }
8649: }
8650: }
8651: foreach my $field (@shibfields) {
8652: if ($env{'form.shibenv_'.$field} ne '') {
8653: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
8654: }
8655: }
8656: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8657: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
8658: foreach my $field (@shibfields) {
8659: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
8660: push(@{$changes{'cancreate'}},'shibenv');
8661: }
8662: }
8663: } else {
8664: foreach my $field (@shibfields) {
8665: if ($env{'form.shibenv_'.$field}) {
8666: push(@{$changes{'cancreate'}},'shibenv');
8667: last;
8668: }
8669: }
8670: }
8671: }
8672: }
8673: foreach my $item (@contexts) {
8674: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
8675: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
8676: if (ref($cancreate{$item}) eq 'ARRAY') {
8677: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
8678: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8679: push(@{$changes{'cancreate'}},$item);
8680: }
8681: }
8682: }
8683: }
8684: if (ref($cancreate{$item}) eq 'ARRAY') {
8685: foreach my $type (@{$cancreate{$item}}) {
8686: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
8687: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8688: push(@{$changes{'cancreate'}},$item);
8689: }
8690: }
8691: }
8692: }
8693: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
8694: if (ref($cancreate{$item}) eq 'HASH') {
8695: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
8696: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
8697: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
8698: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
8699: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8700: push(@{$changes{'cancreate'}},$item);
8701: }
8702: }
8703: }
8704: } elsif ($item eq 'selfcreateprocessing') {
8705: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
8706: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8707: push(@{$changes{'cancreate'}},$item);
8708: }
8709: }
8710: } else {
8711: if (!$cancreate{$item}{$curr}) {
8712: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8713: push(@{$changes{'cancreate'}},$item);
8714: }
8715: }
8716: }
8717: }
8718: foreach my $field (keys(%{$cancreate{$item}})) {
8719: if (ref($cancreate{$item}{$field}) eq 'HASH') {
8720: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
8721: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
8722: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
8723: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8724: push(@{$changes{'cancreate'}},$item);
8725: }
8726: }
8727: } else {
8728: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8729: push(@{$changes{'cancreate'}},$item);
8730: }
8731: }
8732: }
8733: } elsif ($item eq 'selfcreateprocessing') {
8734: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
8735: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8736: push(@{$changes{'cancreate'}},$item);
8737: }
8738: }
8739: } else {
8740: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
8741: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8742: push(@{$changes{'cancreate'}},$item);
8743: }
8744: }
8745: }
8746: }
8747: }
8748: } elsif ($curr_usercreation{'cancreate'}{$item}) {
8749: if (ref($cancreate{$item}) eq 'ARRAY') {
8750: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
8751: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8752: push(@{$changes{'cancreate'}},$item);
8753: }
8754: }
8755: } elsif (ref($cancreate{$item}) eq 'HASH') {
8756: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
8757: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8758: push(@{$changes{'cancreate'}},$item);
8759: }
8760: }
8761: }
8762: } elsif ($item eq 'emailusername') {
8763: if (ref($cancreate{$item}) eq 'HASH') {
8764: foreach my $type (keys(%{$cancreate{$item}})) {
8765: if (ref($cancreate{$item}{$type}) eq 'HASH') {
8766: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
8767: if ($cancreate{$item}{$type}{$field}) {
8768: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8769: push(@{$changes{'cancreate'}},$item);
8770: }
8771: last;
8772: }
8773: }
8774: }
8775: }
8776: }
8777: }
8778: }
8779: #
8780: # Populate %save_usercreate hash with updates to self-creation configuration.
8781: #
8782: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
8783: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
8784: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
8785: if (ref($cancreate{'notify'}) eq 'HASH') {
8786: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
8787: }
8788: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
8789: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
8790: }
8791: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
8792: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
8793: }
8794: if (ref($cancreate{'shibenv'}) eq 'HASH') {
8795: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
8796: }
8797: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
8798: $save_usercreate{'emailrule'} = \@email_rule;
8799:
8800: my %userconfig_hash = (
8801: usercreation => \%save_usercreate,
8802: usermodification => \%save_usermodify,
8803: );
8804: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
8805: $dom);
8806: #
8807: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
8808: #
8809: if ($putresult eq 'ok') {
8810: if (keys(%changes) > 0) {
8811: $resulttext = &mt('Changes made:').'<ul>';
8812: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8813: my %lt = &selfcreation_types();
8814: foreach my $type (@{$changes{'cancreate'}}) {
8815: my $chgtext;
8816: if ($type eq 'selfcreate') {
8817: if (@{$cancreate{$type}} == 0) {
8818: $chgtext .= &mt('Self creation of a new user account is not permitted.');
8819: } else {
8820: $chgtext .= &mt('Self-creation of a new account is permitted for:').
8821: '<ul>';
8822: foreach my $case (@{$cancreate{$type}}) {
8823: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
8824: }
8825: $chgtext .= '</ul>';
8826: if (ref($cancreate{$type}) eq 'ARRAY') {
8827: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
8828: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
8829: if (@{$cancreate{'statustocreate'}} == 0) {
8830: $chgtext .= '<br />'.
8831: '<span class="LC_warning">'.
8832: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
8833: '</span>';
8834: }
8835: }
8836: }
8837: }
8838: }
8839: } elsif ($type eq 'shibenv') {
8840: if (keys(%{$cancreate{$type}}) == 0) {
8841: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
8842: } else {
8843: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
8844: '<ul>';
8845: foreach my $field (@shibfields) {
8846: next if ($cancreate{$type}{$field} eq '');
8847: if ($field eq 'inststatus') {
8848: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
8849: } else {
8850: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
8851: }
8852: }
8853: $chgtext .= '</ul>';
8854: }
8855: } elsif ($type eq 'statustocreate') {
8856: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
8857: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
8858: if (@{$cancreate{'selfcreate'}} > 0) {
8859: if (@{$cancreate{'statustocreate'}} == 0) {
8860: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
8861: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
8862: $chgtext .= '<br />'.
8863: '<span class="LC_warning">'.
8864: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
8865: '</span>';
8866: }
8867: } elsif (ref($usertypes) eq 'HASH') {
8868: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
8869: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
8870: } else {
8871: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
8872: }
8873: $chgtext .= '<ul>';
8874: foreach my $case (@{$cancreate{$type}}) {
8875: if ($case eq 'default') {
8876: $chgtext .= '<li>'.$othertitle.'</li>';
8877: } else {
8878: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
8879: }
8880: }
8881: $chgtext .= '</ul>';
8882: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
8883: $chgtext .= '<br /><span class="LC_warning">'.
8884: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
8885: '</span>';
8886: }
8887: }
8888: } else {
8889: if (@{$cancreate{$type}} == 0) {
8890: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
8891: } else {
8892: $chgtext .= &mt('Although institutional affiliations permitted to create accounts were changed, self creation of accounts is not currently permitted for any authentication types.');
8893: }
8894: }
8895: }
8896: } elsif ($type eq 'selfcreateprocessing') {
8897: my %choices = &Apache::lonlocal::texthash (
8898: automatic => 'Automatic approval',
8899: approval => 'Queued for approval',
8900: );
8901: if (@statuses > 1) {
8902: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
8903: '<ul>';
8904: foreach my $type (@statuses) {
8905: if ($type eq 'default') {
8906: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
8907: } else {
8908: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
8909: }
8910: }
8911: $chgtext .= '</ul>';
8912: } else {
8913: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
8914: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
8915: }
8916: } elsif ($type eq 'captcha') {
8917: if ($savecaptcha{$type} eq 'notused') {
8918: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
8919: } else {
8920: my %captchas = &captcha_phrases();
8921: if ($captchas{$savecaptcha{$type}}) {
8922: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
8923: } else {
8924: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
8925: }
8926: }
8927: } elsif ($type eq 'recaptchakeys') {
8928: my ($privkey,$pubkey);
8929: if (ref($savecaptcha{$type}) eq 'HASH') {
8930: $pubkey = $savecaptcha{$type}{'public'};
8931: $privkey = $savecaptcha{$type}{'private'};
8932: }
8933: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
8934: if (!$pubkey) {
8935: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
8936: } else {
8937: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
8938: }
8939: if (!$privkey) {
8940: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
8941: } else {
8942: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
8943: }
8944: $chgtext .= '</ul>';
8945: } elsif ($type eq 'emailusername') {
8946: if (ref($cancreate{'emailusername'}) eq 'HASH') {
8947: if (ref($types) eq 'ARRAY') {
8948: foreach my $type (@{$types}) {
8949: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
8950: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
8951: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
8952: '<ul>';
8953: foreach my $field (@{$infofields}) {
8954: if ($cancreate{'emailusername'}{$type}{$field}) {
8955: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
8956: }
8957: }
8958: $chgtext .= '</ul>';
8959: } else {
8960: $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 />';
8961: }
8962: } else {
8963: $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 />';
8964: }
8965: }
8966: }
8967: }
8968: } elsif ($type eq 'notify') {
8969: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
8970: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8971: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
8972: if ($cancreate{'notify'}{'approval'}) {
8973: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
8974: }
8975: }
8976: }
8977: }
8978: if ($chgtext) {
8979: $resulttext .= '<li>'.$chgtext.'</li>';
8980: }
8981: }
8982: }
8983: if (ref($changes{'email_rule'}) eq 'ARRAY') {
8984: my ($emailrules,$emailruleorder) =
8985: &Apache::lonnet::inst_userrules($dom,'email');
8986: my $chgtext = '<ul>';
8987: foreach my $type (@email_rule) {
8988: if (ref($emailrules->{$type}) eq 'HASH') {
8989: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
8990: }
8991: }
8992: $chgtext .= '</ul>';
8993: if (@email_rule > 0) {
8994: $resulttext .= '<li>'.
8995: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
8996: $chgtext.
8997: '</li>';
8998: } else {
8999: $resulttext .= '<li>'.
9000: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
9001: '</li>';
9002: }
9003: }
9004: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
9005: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
9006: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9007: foreach my $type (@{$changes{'selfcreate'}}) {
9008: my $typename = $type;
9009: if (ref($usertypes) eq 'HASH') {
9010: if ($usertypes->{$type} ne '') {
9011: $typename = $usertypes->{$type};
9012: }
9013: }
9014: my @modifiable;
9015: $resulttext .= '<li>'.
9016: &mt('Self-creation of account by users with status: [_1]',
9017: '<span class="LC_cusr_emph">'.$typename.'</span>').
9018: ' - '.&mt('modifiable fields (if institutional data blank): ');
9019: foreach my $field (@fields) {
9020: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
9021: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
9022: }
9023: }
9024: if (@modifiable > 0) {
9025: $resulttext .= join(', ',@modifiable);
9026: } else {
9027: $resulttext .= &mt('none');
9028: }
9029: $resulttext .= '</li>';
9030: }
9031: $resulttext .= '</ul></li>';
9032: }
9033: $resulttext .= '</ul>';
9034: } else {
9035: $resulttext = &mt('No changes made to self-creation settings');
9036: }
9037: } else {
9038: $resulttext = '<span class="LC_error">'.
9039: &mt('An error occurred: [_1]',$putresult).'</span>';
9040: }
9041: if ($warningmsg ne '') {
9042: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
9043: }
9044: return $resulttext;
9045: }
9046:
9047: sub process_captcha {
9048: my ($container,$changes,$newsettings,$current) = @_;
9049: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
9050: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
9051: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
9052: $newsettings->{'captcha'} = 'original';
9053: }
9054: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
9055: if ($container eq 'cancreate') {
9056: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9057: push(@{$changes->{'cancreate'}},'captcha');
9058: } elsif (!defined($changes->{'cancreate'})) {
9059: $changes->{'cancreate'} = ['captcha'];
9060: }
9061: } else {
9062: $changes->{'captcha'} = 1;
9063: }
9064: }
9065: my ($newpub,$newpriv,$currpub,$currpriv);
9066: if ($newsettings->{'captcha'} eq 'recaptcha') {
9067: $newpub = $env{'form.'.$container.'_recaptchapub'};
9068: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
9069: $newpub =~ s/\W//g;
9070: $newpriv =~ s/\W//g;
9071: $newsettings->{'recaptchakeys'} = {
9072: public => $newpub,
9073: private => $newpriv,
9074: };
9075: }
9076: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
9077: $currpub = $current->{'recaptchakeys'}{'public'};
9078: $currpriv = $current->{'recaptchakeys'}{'private'};
9079: unless ($newsettings->{'captcha'} eq 'recaptcha') {
9080: $newsettings->{'recaptchakeys'} = {
9081: public => '',
9082: private => '',
9083: }
9084: }
9085: }
9086: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
9087: if ($container eq 'cancreate') {
9088: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9089: push(@{$changes->{'cancreate'}},'recaptchakeys');
9090: } elsif (!defined($changes->{'cancreate'})) {
9091: $changes->{'cancreate'} = ['recaptchakeys'];
9092: }
9093: } else {
9094: $changes->{'recaptchakeys'} = 1;
9095: }
9096: }
9097: return;
9098: }
9099:
9100: sub modify_usermodification {
9101: my ($dom,%domconfig) = @_;
9102: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
9103: if (ref($domconfig{'usermodification'}) eq 'HASH') {
9104: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
9105: if ($key eq 'selfcreate') {
9106: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
9107: } else {
9108: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
9109: }
9110: }
9111: }
9112: my @contexts = ('author','course');
9113: my %context_title = (
9114: author => 'In author context',
9115: course => 'In course context',
9116: );
9117: my @fields = ('lastname','firstname','middlename','generation',
9118: 'permanentemail','id');
9119: my %roles = (
9120: author => ['ca','aa'],
9121: course => ['st','ep','ta','in','cr'],
9122: );
9123: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9124: foreach my $context (@contexts) {
9125: foreach my $role (@{$roles{$context}}) {
9126: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
9127: foreach my $item (@fields) {
9128: if (grep(/^\Q$item\E$/,@modifiable)) {
9129: $modifyhash{$context}{$role}{$item} = 1;
9130: } else {
9131: $modifyhash{$context}{$role}{$item} = 0;
9132: }
9133: }
9134: }
9135: if (ref($curr_usermodification{$context}) eq 'HASH') {
9136: foreach my $role (@{$roles{$context}}) {
9137: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
9138: foreach my $field (@fields) {
9139: if ($modifyhash{$context}{$role}{$field} ne
9140: $curr_usermodification{$context}{$role}{$field}) {
9141: push(@{$changes{$context}},$role);
9142: last;
9143: }
9144: }
9145: }
9146: }
9147: } else {
9148: foreach my $context (@contexts) {
9149: foreach my $role (@{$roles{$context}}) {
9150: push(@{$changes{$context}},$role);
9151: }
9152: }
9153: }
9154: }
9155: my %usermodification_hash = (
9156: usermodification => \%modifyhash,
9157: );
9158: my $putresult = &Apache::lonnet::put_dom('configuration',
9159: \%usermodification_hash,$dom);
9160: if ($putresult eq 'ok') {
9161: if (keys(%changes) > 0) {
9162: $resulttext = &mt('Changes made: ').'<ul>';
9163: foreach my $context (@contexts) {
9164: if (ref($changes{$context}) eq 'ARRAY') {
9165: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
9166: if (ref($changes{$context}) eq 'ARRAY') {
9167: foreach my $role (@{$changes{$context}}) {
9168: my $rolename;
9169: if ($role eq 'cr') {
9170: $rolename = &mt('Custom');
9171: } else {
9172: $rolename = &Apache::lonnet::plaintext($role);
9173: }
9174: my @modifiable;
9175: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
9176: foreach my $field (@fields) {
9177: if ($modifyhash{$context}{$role}{$field}) {
9178: push(@modifiable,$fieldtitles{$field});
9179: }
9180: }
9181: if (@modifiable > 0) {
9182: $resulttext .= join(', ',@modifiable);
9183: } else {
9184: $resulttext .= &mt('none');
9185: }
9186: $resulttext .= '</li>';
9187: }
9188: $resulttext .= '</ul></li>';
9189: }
9190: }
9191: }
9192: $resulttext .= '</ul>';
9193: } else {
9194: $resulttext = &mt('No changes made to user modification settings');
9195: }
9196: } else {
9197: $resulttext = '<span class="LC_error">'.
9198: &mt('An error occurred: [_1]',$putresult).'</span>';
9199: }
9200: return $resulttext;
9201: }
9202:
9203: sub modify_defaults {
9204: my ($dom,$lastactref,%domconfig) = @_;
9205: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
9206: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9207: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
9208: my @authtypes = ('internal','krb4','krb5','localauth');
9209: foreach my $item (@items) {
9210: $newvalues{$item} = $env{'form.'.$item};
9211: if ($item eq 'auth_def') {
9212: if ($newvalues{$item} ne '') {
9213: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
9214: push(@errors,$item);
9215: }
9216: }
9217: } elsif ($item eq 'lang_def') {
9218: if ($newvalues{$item} ne '') {
9219: if ($newvalues{$item} =~ /^(\w+)/) {
9220: my $langcode = $1;
9221: if ($langcode ne 'x_chef') {
9222: if (code2language($langcode) eq '') {
9223: push(@errors,$item);
9224: }
9225: }
9226: } else {
9227: push(@errors,$item);
9228: }
9229: }
9230: } elsif ($item eq 'timezone_def') {
9231: if ($newvalues{$item} ne '') {
9232: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
9233: push(@errors,$item);
9234: }
9235: }
9236: } elsif ($item eq 'datelocale_def') {
9237: if ($newvalues{$item} ne '') {
9238: my @datelocale_ids = DateTime::Locale->ids();
9239: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
9240: push(@errors,$item);
9241: }
9242: }
9243: } elsif ($item eq 'portal_def') {
9244: if ($newvalues{$item} ne '') {
9245: 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])\/?$/) {
9246: push(@errors,$item);
9247: }
9248: }
9249: }
9250: if (grep(/^\Q$item\E$/,@errors)) {
9251: $newvalues{$item} = $domdefaults{$item};
9252: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
9253: $changes{$item} = 1;
9254: }
9255: $domdefaults{$item} = $newvalues{$item};
9256: }
9257: my %defaults_hash = (
9258: defaults => \%newvalues,
9259: );
9260: my $title = &defaults_titles();
9261:
9262: my $currinststatus;
9263: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9264: $currinststatus = $domconfig{'inststatus'};
9265: } else {
9266: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9267: $currinststatus = {
9268: inststatustypes => $usertypes,
9269: inststatusorder => $types,
9270: inststatusguest => [],
9271: };
9272: }
9273: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
9274: my @allpos;
9275: my %guests;
9276: my %alltypes;
9277: my ($currtitles,$currguests,$currorder);
9278: if (ref($currinststatus) eq 'HASH') {
9279: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
9280: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
9281: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
9282: if ($currinststatus->{inststatustypes}->{$type} ne '') {
9283: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
9284: }
9285: }
9286: unless (grep(/^\Q$type\E$/,@todelete)) {
9287: my $position = $env{'form.inststatus_pos_'.$type};
9288: $position =~ s/\D+//g;
9289: $allpos[$position] = $type;
9290: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
9291: $alltypes{$type} =~ s/`//g;
9292: if ($env{'form.inststatus_guest_'.$type}) {
9293: $guests{$type} = 1;
9294: }
9295: }
9296: }
9297: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
9298: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
9299: }
9300: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
9301: $currtitles =~ s/,$//;
9302: }
9303: }
9304: if ($env{'form.addinststatus'}) {
9305: my $newtype = $env{'form.addinststatus'};
9306: $newtype =~ s/\W//g;
9307: unless (exists($alltypes{$newtype})) {
9308: if ($env{'form.addinststatus_guest'}) {
9309: $guests{$newtype} = 1;
9310: }
9311: $alltypes{$newtype} = $env{'form.addinststatus_title'};
9312: $alltypes{$newtype} =~ s/`//g;
9313: my $position = $env{'form.addinststatus_pos'};
9314: $position =~ s/\D+//g;
9315: if ($position ne '') {
9316: $allpos[$position] = $newtype;
9317: }
9318: }
9319: }
9320: my (@orderedstatus,@orderedguests);
9321: foreach my $type (@allpos) {
9322: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
9323: push(@orderedstatus,$type);
9324: if ($guests{$type}) {
9325: push(@orderedguests,$type);
9326: }
9327: }
9328: }
9329: foreach my $type (keys(%alltypes)) {
9330: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
9331: delete($alltypes{$type});
9332: }
9333: }
9334: $defaults_hash{'inststatus'} = {
9335: inststatustypes => \%alltypes,
9336: inststatusorder => \@orderedstatus,
9337: inststatusguest => \@orderedguests,
9338: };
9339: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
9340: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
9341: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
9342: }
9343: }
9344: if ($currorder ne join(',',@orderedstatus)) {
9345: $changes{'inststatus'}{'inststatusorder'} = 1;
9346: }
9347: if ($currguests ne join(',',@orderedguests)) {
9348: $changes{'inststatus'}{'inststatusguest'} = 1;
9349: }
9350: my $newtitles;
9351: foreach my $item (@orderedstatus) {
9352: $newtitles .= $alltypes{$item}.',';
9353: }
9354: $newtitles =~ s/,$//;
9355: if ($currtitles ne $newtitles) {
9356: $changes{'inststatus'}{'inststatustypes'} = 1;
9357: }
9358: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
9359: $dom);
9360: if ($putresult eq 'ok') {
9361: if (keys(%changes) > 0) {
9362: $resulttext = &mt('Changes made:').'<ul>';
9363: my $version = &Apache::lonnet::get_server_loncaparev($dom);
9364: 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";
9365: foreach my $item (sort(keys(%changes))) {
9366: if ($item eq 'inststatus') {
9367: if (ref($changes{'inststatus'}) eq 'HASH') {
9368: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
9369: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
9370: foreach my $type (@orderedstatus) {
9371: $resulttext .= $alltypes{$type}.', ';
9372: }
9373: $resulttext =~ s/, $//;
9374: $resulttext .= '</li>';
9375: }
9376: if ($changes{'inststatus'}{'inststatusguest'}) {
9377: $resulttext .= '<li>';
9378: if (@orderedguests) {
9379: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
9380: foreach my $type (@orderedguests) {
9381: $resulttext .= $alltypes{$type}.', ';
9382: }
9383: $resulttext =~ s/, $//;
9384: } else {
9385: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
9386: }
9387: $resulttext .= '</li>';
9388: }
9389: }
9390: } else {
9391: my $value = $env{'form.'.$item};
9392: if ($value eq '') {
9393: $value = &mt('none');
9394: } elsif ($item eq 'auth_def') {
9395: my %authnames = &authtype_names();
9396: my %shortauth = (
9397: internal => 'int',
9398: krb4 => 'krb4',
9399: krb5 => 'krb5',
9400: localauth => 'loc',
9401: );
9402: $value = $authnames{$shortauth{$value}};
9403: }
9404: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
9405: $mailmsgtext .= "$title->{$item} set to $value\n";
9406: }
9407: }
9408: $resulttext .= '</ul>';
9409: $mailmsgtext .= "\n";
9410: my $cachetime = 24*60*60;
9411: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
9412: if (ref($lastactref) eq 'HASH') {
9413: $lastactref->{'domdefaults'} = 1;
9414: }
9415: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
9416: my $notify = 1;
9417: if (ref($domconfig{'contacts'}) eq 'HASH') {
9418: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
9419: $notify = 0;
9420: }
9421: }
9422: if ($notify) {
9423: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
9424: "LON-CAPA Domain Settings Change - $dom",
9425: $mailmsgtext);
9426: }
9427: }
9428: } else {
9429: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
9430: }
9431: } else {
9432: $resulttext = '<span class="LC_error">'.
9433: &mt('An error occurred: [_1]',$putresult).'</span>';
9434: }
9435: if (@errors > 0) {
9436: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
9437: foreach my $item (@errors) {
9438: $resulttext .= ' "'.$title->{$item}.'",';
9439: }
9440: $resulttext =~ s/,$//;
9441: }
9442: return $resulttext;
9443: }
9444:
9445: sub modify_scantron {
9446: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
9447: my ($resulttext,%confhash,%changes,$errors);
9448: my $custom = 'custom.tab';
9449: my $default = 'default.tab';
9450: my $servadm = $r->dir_config('lonAdmEMail');
9451: my ($configuserok,$author_ok,$switchserver) =
9452: &config_check($dom,$confname,$servadm);
9453: if ($env{'form.scantronformat.filename'} ne '') {
9454: my $error;
9455: if ($configuserok eq 'ok') {
9456: if ($switchserver) {
9457: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
9458: } else {
9459: if ($author_ok eq 'ok') {
9460: my ($result,$scantronurl) =
9461: &publishlogo($r,'upload','scantronformat',$dom,
9462: $confname,'scantron','','',$custom);
9463: if ($result eq 'ok') {
9464: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
9465: $changes{'scantronformat'} = 1;
9466: } else {
9467: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
9468: }
9469: } else {
9470: $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);
9471: }
9472: }
9473: } else {
9474: $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);
9475: }
9476: if ($error) {
9477: &Apache::lonnet::logthis($error);
9478: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9479: }
9480: }
9481: if (ref($domconfig{'scantron'}) eq 'HASH') {
9482: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
9483: if ($env{'form.scantronformat_del'}) {
9484: $confhash{'scantron'}{'scantronformat'} = '';
9485: $changes{'scantronformat'} = 1;
9486: }
9487: }
9488: }
9489: if (keys(%confhash) > 0) {
9490: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
9491: $dom);
9492: if ($putresult eq 'ok') {
9493: if (keys(%changes) > 0) {
9494: if (ref($confhash{'scantron'}) eq 'HASH') {
9495: $resulttext = &mt('Changes made:').'<ul>';
9496: if ($confhash{'scantron'}{'scantronformat'} eq '') {
9497: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
9498: } else {
9499: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
9500: }
9501: $resulttext .= '</ul>';
9502: } else {
9503: $resulttext = &mt('Changes made to bubblesheet format file.');
9504: }
9505: $resulttext .= '</ul>';
9506: &Apache::loncommon::devalidate_domconfig_cache($dom);
9507: if (ref($lastactref) eq 'HASH') {
9508: $lastactref->{'domainconfig'} = 1;
9509: }
9510: } else {
9511: $resulttext = &mt('No changes made to bubblesheet format file');
9512: }
9513: } else {
9514: $resulttext = '<span class="LC_error">'.
9515: &mt('An error occurred: [_1]',$putresult).'</span>';
9516: }
9517: } else {
9518: $resulttext = &mt('No changes made to bubblesheet format file');
9519: }
9520: if ($errors) {
9521: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9522: $errors.'</ul>';
9523: }
9524: return $resulttext;
9525: }
9526:
9527: sub modify_coursecategories {
9528: my ($dom,$lastactref,%domconfig) = @_;
9529: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
9530: $cathash);
9531: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
9532: my @catitems = ('unauth','auth');
9533: my @cattypes = ('std','domonly','codesrch','none');
9534: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9535: $cathash = $domconfig{'coursecategories'}{'cats'};
9536: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
9537: $changes{'togglecats'} = 1;
9538: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
9539: }
9540: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
9541: $changes{'categorize'} = 1;
9542: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
9543: }
9544: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
9545: $changes{'togglecatscomm'} = 1;
9546: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
9547: }
9548: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
9549: $changes{'categorizecomm'} = 1;
9550: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
9551: }
9552: foreach my $item (@catitems) {
9553: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9554: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
9555: $changes{$item} = 1;
9556: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9557: }
9558: }
9559: }
9560: } else {
9561: $changes{'togglecats'} = 1;
9562: $changes{'categorize'} = 1;
9563: $changes{'togglecatscomm'} = 1;
9564: $changes{'categorizecomm'} = 1;
9565: $domconfig{'coursecategories'} = {
9566: togglecats => $env{'form.togglecats'},
9567: categorize => $env{'form.categorize'},
9568: togglecatscomm => $env{'form.togglecatscomm'},
9569: categorizecomm => $env{'form.categorizecomm'},
9570: };
9571: foreach my $item (@catitems) {
9572: if ($env{'form.coursecat_'.$item} ne 'std') {
9573: $changes{$item} = 1;
9574: }
9575: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9576: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9577: }
9578: }
9579: }
9580: if (ref($cathash) eq 'HASH') {
9581: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
9582: push (@deletecategory,'instcode::0');
9583: }
9584: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
9585: push(@deletecategory,'communities::0');
9586: }
9587: }
9588: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
9589: if (ref($cathash) eq 'HASH') {
9590: if (@deletecategory > 0) {
9591: #FIXME Need to remove category from all courses using a deleted category
9592: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
9593: foreach my $item (@deletecategory) {
9594: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
9595: delete($domconfig{'coursecategories'}{'cats'}{$item});
9596: $deletions{$item} = 1;
9597: &recurse_cat_deletes($item,$cathash,\%deletions);
9598: }
9599: }
9600: }
9601: foreach my $item (keys(%{$cathash})) {
9602: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9603: if ($cathash->{$item} ne $env{'form.'.$item}) {
9604: $reorderings{$item} = 1;
9605: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
9606: }
9607: if ($env{'form.addcategory_name_'.$item} ne '') {
9608: my $newcat = $env{'form.addcategory_name_'.$item};
9609: my $newdepth = $depth+1;
9610: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
9611: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
9612: $adds{$newitem} = 1;
9613: }
9614: if ($env{'form.subcat_'.$item} ne '') {
9615: my $newcat = $env{'form.subcat_'.$item};
9616: my $newdepth = $depth+1;
9617: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
9618: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
9619: $adds{$newitem} = 1;
9620: }
9621: }
9622: }
9623: if ($env{'form.instcode'} eq '1') {
9624: if (ref($cathash) eq 'HASH') {
9625: my $newitem = 'instcode::0';
9626: if ($cathash->{$newitem} eq '') {
9627: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
9628: $adds{$newitem} = 1;
9629: }
9630: } else {
9631: my $newitem = 'instcode::0';
9632: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
9633: $adds{$newitem} = 1;
9634: }
9635: }
9636: if ($env{'form.communities'} eq '1') {
9637: if (ref($cathash) eq 'HASH') {
9638: my $newitem = 'communities::0';
9639: if ($cathash->{$newitem} eq '') {
9640: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9641: $adds{$newitem} = 1;
9642: }
9643: } else {
9644: my $newitem = 'communities::0';
9645: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9646: $adds{$newitem} = 1;
9647: }
9648: }
9649: if ($env{'form.addcategory_name'} ne '') {
9650: if (($env{'form.addcategory_name'} ne 'instcode') &&
9651: ($env{'form.addcategory_name'} ne 'communities')) {
9652: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
9653: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
9654: $adds{$newitem} = 1;
9655: }
9656: }
9657: my $putresult;
9658: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9659: if (keys(%deletions) > 0) {
9660: foreach my $key (keys(%deletions)) {
9661: if ($predelallitems{$key} ne '') {
9662: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
9663: }
9664: }
9665: }
9666: my (@chkcats,@chktrails,%chkallitems);
9667: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
9668: if (ref($chkcats[0]) eq 'ARRAY') {
9669: my $depth = 0;
9670: my $chg = 0;
9671: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
9672: my $name = $chkcats[0][$i];
9673: my $item;
9674: if ($name eq '') {
9675: $chg ++;
9676: } else {
9677: $item = &escape($name).'::0';
9678: if ($chg) {
9679: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
9680: }
9681: $depth ++;
9682: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
9683: $depth --;
9684: }
9685: }
9686: }
9687: }
9688: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9689: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
9690: if ($putresult eq 'ok') {
9691: my %title = (
9692: togglecats => 'Show/Hide a course in catalog',
9693: categorize => 'Assign a category to a course',
9694: togglecatscomm => 'Show/Hide a community in catalog',
9695: categorizecomm => 'Assign a category to a community',
9696: );
9697: my %level = (
9698: dom => 'set in Domain ("Modify Course/Community")',
9699: crs => 'set in Course ("Course Configuration")',
9700: comm => 'set in Community ("Community Configuration")',
9701: none => 'No catalog',
9702: std => 'Standard catalog',
9703: domonly => 'Domain-only catalog',
9704: codesrch => 'Code search form',
9705: );
9706: $resulttext = &mt('Changes made:').'<ul>';
9707: if ($changes{'togglecats'}) {
9708: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
9709: }
9710: if ($changes{'categorize'}) {
9711: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
9712: }
9713: if ($changes{'togglecatscomm'}) {
9714: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
9715: }
9716: if ($changes{'categorizecomm'}) {
9717: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
9718: }
9719: if ($changes{'unauth'}) {
9720: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
9721: }
9722: if ($changes{'auth'}) {
9723: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
9724: }
9725: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9726: my $cathash;
9727: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9728: $cathash = $domconfig{'coursecategories'}{'cats'};
9729: } else {
9730: $cathash = {};
9731: }
9732: my (@cats,@trails,%allitems);
9733: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
9734: if (keys(%deletions) > 0) {
9735: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
9736: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
9737: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
9738: }
9739: $resulttext .= '</ul></li>';
9740: }
9741: if (keys(%reorderings) > 0) {
9742: my %sort_by_trail;
9743: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
9744: foreach my $key (keys(%reorderings)) {
9745: if ($allitems{$key} ne '') {
9746: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
9747: }
9748: }
9749: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
9750: $resulttext .= '<li>'.$trails[$trail].'</li>';
9751: }
9752: $resulttext .= '</ul></li>';
9753: }
9754: if (keys(%adds) > 0) {
9755: my %sort_by_trail;
9756: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
9757: foreach my $key (keys(%adds)) {
9758: if ($allitems{$key} ne '') {
9759: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
9760: }
9761: }
9762: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
9763: $resulttext .= '<li>'.$trails[$trail].'</li>';
9764: }
9765: $resulttext .= '</ul></li>';
9766: }
9767: }
9768: $resulttext .= '</ul>';
9769: if ($changes{'unauth'} || $changes{'auth'}) {
9770: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
9771: if ($changes{'auth'}) {
9772: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
9773: }
9774: if ($changes{'unauth'}) {
9775: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
9776: }
9777: my $cachetime = 24*60*60;
9778: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
9779: if (ref($lastactref) eq 'HASH') {
9780: $lastactref->{'domdefaults'} = 1;
9781: }
9782: }
9783: } else {
9784: $resulttext = '<span class="LC_error">'.
9785: &mt('An error occurred: [_1]',$putresult).'</span>';
9786: }
9787: } else {
9788: $resulttext = &mt('No changes made to course and community categories');
9789: }
9790: return $resulttext;
9791: }
9792:
9793: sub modify_serverstatuses {
9794: my ($dom,%domconfig) = @_;
9795: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
9796: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
9797: %currserverstatus = %{$domconfig{'serverstatuses'}};
9798: }
9799: my @pages = &serverstatus_pages();
9800: foreach my $type (@pages) {
9801: $newserverstatus{$type}{'namedusers'} = '';
9802: $newserverstatus{$type}{'machines'} = '';
9803: if (defined($env{'form.'.$type.'_namedusers'})) {
9804: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
9805: my @okusers;
9806: foreach my $user (@users) {
9807: my ($uname,$udom) = split(/:/,$user);
9808: if (($udom =~ /^$match_domain$/) &&
9809: (&Apache::lonnet::domain($udom)) &&
9810: ($uname =~ /^$match_username$/)) {
9811: if (!grep(/^\Q$user\E/,@okusers)) {
9812: push(@okusers,$user);
9813: }
9814: }
9815: }
9816: if (@okusers > 0) {
9817: @okusers = sort(@okusers);
9818: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
9819: }
9820: }
9821: if (defined($env{'form.'.$type.'_machines'})) {
9822: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
9823: my @okmachines;
9824: foreach my $ip (@machines) {
9825: my @parts = split(/\./,$ip);
9826: next if (@parts < 4);
9827: my $badip = 0;
9828: for (my $i=0; $i<4; $i++) {
9829: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
9830: $badip = 1;
9831: last;
9832: }
9833: }
9834: if (!$badip) {
9835: push(@okmachines,$ip);
9836: }
9837: }
9838: @okmachines = sort(@okmachines);
9839: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
9840: }
9841: }
9842: my %serverstatushash = (
9843: serverstatuses => \%newserverstatus,
9844: );
9845: foreach my $type (@pages) {
9846: foreach my $setting ('namedusers','machines') {
9847: my (@current,@new);
9848: if (ref($currserverstatus{$type}) eq 'HASH') {
9849: if ($currserverstatus{$type}{$setting} ne '') {
9850: @current = split(/,/,$currserverstatus{$type}{$setting});
9851: }
9852: }
9853: if ($newserverstatus{$type}{$setting} ne '') {
9854: @new = split(/,/,$newserverstatus{$type}{$setting});
9855: }
9856: if (@current > 0) {
9857: if (@new > 0) {
9858: foreach my $item (@current) {
9859: if (!grep(/^\Q$item\E$/,@new)) {
9860: $changes{$type}{$setting} = 1;
9861: last;
9862: }
9863: }
9864: foreach my $item (@new) {
9865: if (!grep(/^\Q$item\E$/,@current)) {
9866: $changes{$type}{$setting} = 1;
9867: last;
9868: }
9869: }
9870: } else {
9871: $changes{$type}{$setting} = 1;
9872: }
9873: } elsif (@new > 0) {
9874: $changes{$type}{$setting} = 1;
9875: }
9876: }
9877: }
9878: if (keys(%changes) > 0) {
9879: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
9880: my $putresult = &Apache::lonnet::put_dom('configuration',
9881: \%serverstatushash,$dom);
9882: if ($putresult eq 'ok') {
9883: $resulttext .= &mt('Changes made:').'<ul>';
9884: foreach my $type (@pages) {
9885: if (ref($changes{$type}) eq 'HASH') {
9886: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
9887: if ($changes{$type}{'namedusers'}) {
9888: if ($newserverstatus{$type}{'namedusers'} eq '') {
9889: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
9890: } else {
9891: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
9892: }
9893: }
9894: if ($changes{$type}{'machines'}) {
9895: if ($newserverstatus{$type}{'machines'} eq '') {
9896: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
9897: } else {
9898: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
9899: }
9900:
9901: }
9902: $resulttext .= '</ul></li>';
9903: }
9904: }
9905: $resulttext .= '</ul>';
9906: } else {
9907: $resulttext = '<span class="LC_error">'.
9908: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
9909:
9910: }
9911: } else {
9912: $resulttext = &mt('No changes made to access to server status pages');
9913: }
9914: return $resulttext;
9915: }
9916:
9917: sub modify_helpsettings {
9918: my ($r,$dom,$confname,%domconfig) = @_;
9919: my ($resulttext,$errors,%changes,%helphash);
9920: my %defaultchecked = ('submitbugs' => 'on');
9921: my @offon = ('off','on');
9922: my @toggles = ('submitbugs');
9923: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
9924: foreach my $item (@toggles) {
9925: if ($defaultchecked{$item} eq 'on') {
9926: if ($domconfig{'helpsettings'}{$item} eq '') {
9927: if ($env{'form.'.$item} eq '0') {
9928: $changes{$item} = 1;
9929: }
9930: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
9931: $changes{$item} = 1;
9932: }
9933: } elsif ($defaultchecked{$item} eq 'off') {
9934: if ($domconfig{'helpsettings'}{$item} eq '') {
9935: if ($env{'form.'.$item} eq '1') {
9936: $changes{$item} = 1;
9937: }
9938: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
9939: $changes{$item} = 1;
9940: }
9941: }
9942: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
9943: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
9944: }
9945: }
9946: }
9947: my $putresult;
9948: if (keys(%changes) > 0) {
9949: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
9950: if ($putresult eq 'ok') {
9951: $resulttext = &mt('Changes made:').'<ul>';
9952: foreach my $item (sort(keys(%changes))) {
9953: if ($item eq 'submitbugs') {
9954: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
9955: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
9956: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
9957: }
9958: }
9959: $resulttext .= '</ul>';
9960: } else {
9961: $resulttext = &mt('No changes made to help settings');
9962: $errors .= '<li><span class="LC_error">'.
9963: &mt('An error occurred storing the settings: [_1]',
9964: $putresult).'</span></li>';
9965: }
9966: }
9967: if ($errors) {
9968: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
9969: $errors.'</ul>';
9970: }
9971: return $resulttext;
9972: }
9973:
9974: sub modify_coursedefaults {
9975: my ($dom,$lastactref,%domconfig) = @_;
9976: my ($resulttext,$errors,%changes,%defaultshash);
9977: my %defaultchecked = ('canuse_pdfforms' => 'off');
9978: my @toggles = ('canuse_pdfforms');
9979: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
9980: 'uploadquota_community','uploadquota_textbook');
9981: my @types = ('official','unofficial','community','textbook');
9982: my %staticdefaults = (
9983: anonsurvey_threshold => 10,
9984: uploadquota => 500,
9985: );
9986:
9987: $defaultshash{'coursedefaults'} = {};
9988:
9989: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
9990: if ($domconfig{'coursedefaults'} eq '') {
9991: $domconfig{'coursedefaults'} = {};
9992: }
9993: }
9994:
9995: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
9996: foreach my $item (@toggles) {
9997: if ($defaultchecked{$item} eq 'on') {
9998: if (($domconfig{'coursedefaults'}{$item} eq '') &&
9999: ($env{'form.'.$item} eq '0')) {
10000: $changes{$item} = 1;
10001: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
10002: $changes{$item} = 1;
10003: }
10004: } elsif ($defaultchecked{$item} eq 'off') {
10005: if (($domconfig{'coursedefaults'}{$item} eq '') &&
10006: ($env{'form.'.$item} eq '1')) {
10007: $changes{$item} = 1;
10008: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
10009: $changes{$item} = 1;
10010: }
10011: }
10012: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
10013: }
10014: foreach my $item (@numbers) {
10015: my ($currdef,$newdef);
10016: $newdef = $env{'form.'.$item};
10017: if ($item eq 'anonsurvey_threshold') {
10018: $currdef = $domconfig{'coursedefaults'}{$item};
10019: $newdef =~ s/\D//g;
10020: if ($newdef eq '' || $newdef < 1) {
10021: $newdef = 1;
10022: }
10023: $defaultshash{'coursedefaults'}{$item} = $newdef;
10024: } else {
10025: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
10026: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10027: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
10028: }
10029: $newdef =~ s/[^\w.\-]//g;
10030: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
10031: }
10032: if ($currdef ne $newdef) {
10033: my $staticdef;
10034: if ($item eq 'anonsurvey_threshold') {
10035: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
10036: $changes{$item} = 1;
10037: }
10038: } else {
10039: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
10040: $changes{'uploadquota'} = 1;
10041: }
10042: }
10043: }
10044: }
10045:
10046: my $officialcreds = $env{'form.official_credits'};
10047: $officialcreds =~ s/[^\d.]+//g;
10048: my $unofficialcreds = $env{'form.unofficial_credits'};
10049: $unofficialcreds =~ s/[^\d.]+//g;
10050: my $textbookcreds = $env{'form.textbook_credits'};
10051: $textbookcreds =~ s/[^\d.]+//g;
10052: if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
10053: ($env{'form.coursecredits'} eq '1')) {
10054: $changes{'coursecredits'} = 1;
10055: } else {
10056: if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
10057: ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds) ||
10058: ($domconfig{'coursedefaults'}{'coursecredits'}{'textbook'} ne $textbookcreds)) {
10059: $changes{'coursecredits'} = 1;
10060: }
10061: }
10062: $defaultshash{'coursedefaults'}{'coursecredits'} = {
10063: official => $officialcreds,
10064: unofficial => $unofficialcreds,
10065: textbook => $textbookcreds,
10066: }
10067: }
10068: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10069: $dom);
10070: if ($putresult eq 'ok') {
10071: if (keys(%changes) > 0) {
10072: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10073: if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) ||
10074: ($changes{'uploadquota'})) {
10075: if ($changes{'canuse_pdfforms'}) {
10076: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
10077: }
10078: if ($changes{'coursecredits'}) {
10079: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10080: $domdefaults{'officialcredits'} =
10081: $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
10082: $domdefaults{'unofficialcredits'} =
10083: $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
10084: $domdefaults{'textbookcredits'} =
10085: $domdefaults{'coursedefaults'}{'coursecredits'}{'textbook'};
10086: }
10087: }
10088: if ($changes{'uploadquota'}) {
10089: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10090: foreach my $type (@types) {
10091: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
10092: }
10093: }
10094: }
10095: my $cachetime = 24*60*60;
10096: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10097: if (ref($lastactref) eq 'HASH') {
10098: $lastactref->{'domdefaults'} = 1;
10099: }
10100: }
10101: $resulttext = &mt('Changes made:').'<ul>';
10102: foreach my $item (sort(keys(%changes))) {
10103: if ($item eq 'canuse_pdfforms') {
10104: if ($env{'form.'.$item} eq '1') {
10105: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
10106: } else {
10107: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
10108: }
10109: } elsif ($item eq 'anonsurvey_threshold') {
10110: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
10111: } elsif ($item eq 'uploadquota') {
10112: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10113: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
10114: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
10115: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
10116: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
10117:
10118: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
10119: '</ul>'.
10120: '</li>';
10121: } else {
10122: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
10123: }
10124: } elsif ($item eq 'coursecredits') {
10125: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10126: if (($domdefaults{'officialcredits'} eq '') &&
10127: ($domdefaults{'unofficialcredits'} eq '') &&
10128: ($domdefaults{'textbookcredits'} eq '')) {
10129: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10130: } else {
10131: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
10132: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
10133: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
10134: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
10135: '</ul>'.
10136: '</li>';
10137: }
10138: } else {
10139: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10140: }
10141: }
10142: }
10143: $resulttext .= '</ul>';
10144: } else {
10145: $resulttext = &mt('No changes made to course defaults');
10146: }
10147: } else {
10148: $resulttext = '<span class="LC_error">'.
10149: &mt('An error occurred: [_1]',$putresult).'</span>';
10150: }
10151: return $resulttext;
10152: }
10153:
10154: sub modify_selfenrollment {
10155: my ($dom,$lastactref,%domconfig) = @_;
10156: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
10157: my @types = ('official','unofficial','community','textbook');
10158: my %titles = &tool_titles();
10159: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
10160: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
10161: $ordered{'default'} = ['types','registered','approval','limit'];
10162:
10163: my (%roles,%shown,%toplevel);
10164: $roles{'0'} = &Apache::lonnet::plaintext('dc');
10165:
10166: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
10167: if ($domconfig{'selfenrollment'} eq '') {
10168: $domconfig{'selfenrollment'} = {};
10169: }
10170: }
10171: %toplevel = (
10172: admin => 'Configuration Rights',
10173: default => 'Default settings',
10174: validation => 'Validation of self-enrollment requests',
10175: );
10176: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
10177:
10178: if (ref($ordered{'admin'}) eq 'ARRAY') {
10179: foreach my $item (@{$ordered{'admin'}}) {
10180: foreach my $type (@types) {
10181: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
10182: $selfenrollhash{'admin'}{$type}{$item} = 1;
10183: } else {
10184: $selfenrollhash{'admin'}{$type}{$item} = 0;
10185: }
10186: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
10187: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
10188: if ($selfenrollhash{'admin'}{$type}{$item} ne
10189: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
10190: push(@{$changes{'admin'}{$type}},$item);
10191: }
10192: } else {
10193: if (!$selfenrollhash{'admin'}{$type}{$item}) {
10194: push(@{$changes{'admin'}{$type}},$item);
10195: }
10196: }
10197: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
10198: push(@{$changes{'admin'}{$type}},$item);
10199: }
10200: }
10201: }
10202: }
10203:
10204: foreach my $item (@{$ordered{'default'}}) {
10205: foreach my $type (@types) {
10206: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
10207: if ($item eq 'types') {
10208: unless (($value eq 'all') || ($value eq 'dom')) {
10209: $value = '';
10210: }
10211: } elsif ($item eq 'registered') {
10212: unless ($value eq '1') {
10213: $value = 0;
10214: }
10215: } elsif ($item eq 'approval') {
10216: unless ($value =~ /^[012]$/) {
10217: $value = 0;
10218: }
10219: } else {
10220: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10221: $value = 'none';
10222: }
10223: }
10224: $selfenrollhash{'default'}{$type}{$item} = $value;
10225: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
10226: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10227: if ($selfenrollhash{'default'}{$type}{$item} ne
10228: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
10229: push(@{$changes{'default'}{$type}},$item);
10230: }
10231: } else {
10232: push(@{$changes{'default'}{$type}},$item);
10233: }
10234: } else {
10235: push(@{$changes{'default'}{$type}},$item);
10236: }
10237: if ($item eq 'limit') {
10238: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10239: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
10240: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
10241: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
10242: }
10243: } else {
10244: $selfenrollhash{'default'}{$type}{'cap'} = '';
10245: }
10246: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10247: if ($selfenrollhash{'default'}{$type}{'cap'} ne
10248: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
10249: push(@{$changes{'default'}{$type}},'cap');
10250: }
10251: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
10252: push(@{$changes{'default'}{$type}},'cap');
10253: }
10254: }
10255: }
10256: }
10257:
10258: foreach my $item (@{$itemsref}) {
10259: if ($item eq 'fields') {
10260: my @changed;
10261: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
10262: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
10263: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
10264: }
10265: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10266: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
10267: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
10268: $domconfig{'selfenrollment'}{'validation'}{$item});
10269: } else {
10270: @changed = @{$selfenrollhash{'validation'}{$item}};
10271: }
10272: } else {
10273: @changed = @{$selfenrollhash{'validation'}{$item}};
10274: }
10275: if (@changed) {
10276: if ($selfenrollhash{'validation'}{$item}) {
10277: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
10278: } else {
10279: $changes{'validation'}{$item} = &mt('None');
10280: }
10281: }
10282: } else {
10283: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
10284: if ($item eq 'markup') {
10285: if ($env{'form.selfenroll_validation_'.$item}) {
10286: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10287: }
10288: }
10289: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10290: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
10291: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
10292: }
10293: }
10294: }
10295: }
10296:
10297: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
10298: $dom);
10299: if ($putresult eq 'ok') {
10300: if (keys(%changes) > 0) {
10301: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10302: $resulttext = &mt('Changes made:').'<ul>';
10303: foreach my $key ('admin','default','validation') {
10304: if (ref($changes{$key}) eq 'HASH') {
10305: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
10306: if ($key eq 'validation') {
10307: foreach my $item (@{$itemsref}) {
10308: if (exists($changes{$key}{$item})) {
10309: if ($item eq 'markup') {
10310: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10311: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
10312: } else {
10313: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10314: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
10315: }
10316: }
10317: }
10318: } else {
10319: foreach my $type (@types) {
10320: if ($type eq 'community') {
10321: $roles{'1'} = &mt('Community personnel');
10322: } else {
10323: $roles{'1'} = &mt('Course personnel');
10324: }
10325: if (ref($changes{$key}{$type}) eq 'ARRAY') {
10326: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10327: if ($key eq 'admin') {
10328: my @mgrdc = ();
10329: if (ref($ordered{$key}) eq 'ARRAY') {
10330: foreach my $item (@{$ordered{'admin'}}) {
10331: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10332: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
10333: push(@mgrdc,$item);
10334: }
10335: }
10336: }
10337: if (@mgrdc) {
10338: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
10339: } else {
10340: delete($domdefaults{$type.'selfenrolladmdc'});
10341: }
10342: }
10343: } else {
10344: if (ref($ordered{$key}) eq 'ARRAY') {
10345: foreach my $item (@{$ordered{$key}}) {
10346: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10347: $domdefaults{$type.'selfenroll'.$item} =
10348: $selfenrollhash{$key}{$type}{$item};
10349: }
10350: }
10351: }
10352: }
10353: }
10354: $resulttext .= '<li>'.$titles{$type}.'<ul>';
10355: foreach my $item (@{$ordered{$key}}) {
10356: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10357: $resulttext .= '<li>';
10358: if ($key eq 'admin') {
10359: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
10360: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
10361: } else {
10362: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
10363: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
10364: }
10365: $resulttext .= '</li>';
10366: }
10367: }
10368: $resulttext .= '</ul></li>';
10369: }
10370: }
10371: $resulttext .= '</ul></li>';
10372: }
10373: }
10374: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
10375: my $cachetime = 24*60*60;
10376: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10377: if (ref($lastactref) eq 'HASH') {
10378: $lastactref->{'domdefaults'} = 1;
10379: }
10380: }
10381: }
10382: $resulttext .= '</ul>';
10383: } else {
10384: $resulttext = &mt('No changes made to self-enrollment settings');
10385: }
10386: } else {
10387: $resulttext = '<span class="LC_error">'.
10388: &mt('An error occurred: [_1]',$putresult).'</span>';
10389: }
10390: return $resulttext;
10391: }
10392:
10393: sub modify_usersessions {
10394: my ($dom,$lastactref,%domconfig) = @_;
10395: my @hostingtypes = ('version','excludedomain','includedomain');
10396: my @offloadtypes = ('primary','default');
10397: my %types = (
10398: remote => \@hostingtypes,
10399: hosted => \@hostingtypes,
10400: spares => \@offloadtypes,
10401: );
10402: my @prefixes = ('remote','hosted','spares');
10403: my @lcversions = &Apache::lonnet::all_loncaparevs();
10404: my (%by_ip,%by_location,@intdoms);
10405: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
10406: my @locations = sort(keys(%by_location));
10407: my (%defaultshash,%changes);
10408: foreach my $prefix (@prefixes) {
10409: $defaultshash{'usersessions'}{$prefix} = {};
10410: }
10411: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10412: my $resulttext;
10413: my %iphost = &Apache::lonnet::get_iphost();
10414: foreach my $prefix (@prefixes) {
10415: next if ($prefix eq 'spares');
10416: foreach my $type (@{$types{$prefix}}) {
10417: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
10418: if ($type eq 'version') {
10419: my $value = $env{'form.'.$prefix.'_'.$type};
10420: my $okvalue;
10421: if ($value ne '') {
10422: if (grep(/^\Q$value\E$/,@lcversions)) {
10423: $okvalue = $value;
10424: }
10425: }
10426: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10427: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10428: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
10429: if ($inuse == 0) {
10430: $changes{$prefix}{$type} = 1;
10431: } else {
10432: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
10433: $changes{$prefix}{$type} = 1;
10434: }
10435: if ($okvalue ne '') {
10436: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10437: }
10438: }
10439: } else {
10440: if (($inuse == 1) && ($okvalue ne '')) {
10441: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10442: $changes{$prefix}{$type} = 1;
10443: }
10444: }
10445: } else {
10446: if (($inuse == 1) && ($okvalue ne '')) {
10447: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10448: $changes{$prefix}{$type} = 1;
10449: }
10450: }
10451: } else {
10452: if (($inuse == 1) && ($okvalue ne '')) {
10453: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10454: $changes{$prefix}{$type} = 1;
10455: }
10456: }
10457: } else {
10458: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
10459: my @okvals;
10460: foreach my $val (@vals) {
10461: if ($val =~ /:/) {
10462: my @items = split(/:/,$val);
10463: foreach my $item (@items) {
10464: if (ref($by_location{$item}) eq 'ARRAY') {
10465: push(@okvals,$item);
10466: }
10467: }
10468: } else {
10469: if (ref($by_location{$val}) eq 'ARRAY') {
10470: push(@okvals,$val);
10471: }
10472: }
10473: }
10474: @okvals = sort(@okvals);
10475: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10476: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10477: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10478: if ($inuse == 0) {
10479: $changes{$prefix}{$type} = 1;
10480: } else {
10481: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10482: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
10483: if (@changed > 0) {
10484: $changes{$prefix}{$type} = 1;
10485: }
10486: }
10487: } else {
10488: if ($inuse == 1) {
10489: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10490: $changes{$prefix}{$type} = 1;
10491: }
10492: }
10493: } else {
10494: if ($inuse == 1) {
10495: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10496: $changes{$prefix}{$type} = 1;
10497: }
10498: }
10499: } else {
10500: if ($inuse == 1) {
10501: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10502: $changes{$prefix}{$type} = 1;
10503: }
10504: }
10505: }
10506: }
10507: }
10508:
10509: my @alldoms = &Apache::lonnet::all_domains();
10510: my %servers = &Apache::lonnet::internet_dom_servers($dom);
10511: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
10512: my $savespares;
10513:
10514: foreach my $lonhost (sort(keys(%servers))) {
10515: my $serverhomeID =
10516: &Apache::lonnet::get_server_homeID($servers{$lonhost});
10517: my $serverhostname = &Apache::lonnet::hostname($lonhost);
10518: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
10519: my %spareschg;
10520: foreach my $type (@{$types{'spares'}}) {
10521: my @okspares;
10522: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
10523: foreach my $server (@checked) {
10524: if (&Apache::lonnet::hostname($server) ne '') {
10525: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
10526: unless (grep(/^\Q$server\E$/,@okspares)) {
10527: push(@okspares,$server);
10528: }
10529: }
10530: }
10531: }
10532: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
10533: my $newspare;
10534: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
10535: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
10536: $newspare = $new;
10537: }
10538: }
10539: my @spares;
10540: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
10541: @spares = sort(@okspares,$newspare);
10542: } else {
10543: @spares = sort(@okspares);
10544: }
10545: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
10546: if (ref($spareid{$lonhost}) eq 'HASH') {
10547: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
10548: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
10549: if (@diffs > 0) {
10550: $spareschg{$type} = 1;
10551: }
10552: }
10553: }
10554: }
10555: if (keys(%spareschg) > 0) {
10556: $changes{'spares'}{$lonhost} = \%spareschg;
10557: }
10558: }
10559:
10560: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10561: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
10562: if (ref($changes{'spares'}) eq 'HASH') {
10563: if (keys(%{$changes{'spares'}}) > 0) {
10564: $savespares = 1;
10565: }
10566: }
10567: } else {
10568: $savespares = 1;
10569: }
10570: }
10571:
10572: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
10573: if ((keys(%changes) > 0) || ($savespares)) {
10574: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10575: $dom);
10576: if ($putresult eq 'ok') {
10577: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10578: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
10579: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
10580: }
10581: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
10582: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
10583: }
10584: }
10585: my $cachetime = 24*60*60;
10586: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10587: if (ref($lastactref) eq 'HASH') {
10588: $lastactref->{'domdefaults'} = 1;
10589: }
10590: if (keys(%changes) > 0) {
10591: my %lt = &usersession_titles();
10592: $resulttext = &mt('Changes made:').'<ul>';
10593: foreach my $prefix (@prefixes) {
10594: if (ref($changes{$prefix}) eq 'HASH') {
10595: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
10596: if ($prefix eq 'spares') {
10597: if (ref($changes{$prefix}) eq 'HASH') {
10598: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
10599: $resulttext .= '<li><b>'.$lonhost.'</b> ';
10600: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
10601: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
10602: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
10603: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
10604: foreach my $type (@{$types{$prefix}}) {
10605: if ($changes{$prefix}{$lonhost}{$type}) {
10606: my $offloadto = &mt('None');
10607: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
10608: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
10609: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
10610: }
10611: }
10612: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
10613: }
10614: }
10615: }
10616: $resulttext .= '</li>';
10617: }
10618: }
10619: } else {
10620: foreach my $type (@{$types{$prefix}}) {
10621: if (defined($changes{$prefix}{$type})) {
10622: my $newvalue;
10623: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10624: if (ref($defaultshash{'usersessions'}{$prefix})) {
10625: if ($type eq 'version') {
10626: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
10627: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10628: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
10629: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
10630: }
10631: }
10632: }
10633: }
10634: if ($newvalue eq '') {
10635: if ($type eq 'version') {
10636: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
10637: } else {
10638: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
10639: }
10640: } else {
10641: if ($type eq 'version') {
10642: $newvalue .= ' '.&mt('(or later)');
10643: }
10644: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
10645: }
10646: }
10647: }
10648: }
10649: $resulttext .= '</ul>';
10650: }
10651: }
10652: $resulttext .= '</ul>';
10653: } else {
10654: $resulttext = $nochgmsg;
10655: }
10656: } else {
10657: $resulttext = '<span class="LC_error">'.
10658: &mt('An error occurred: [_1]',$putresult).'</span>';
10659: }
10660: } else {
10661: $resulttext = $nochgmsg;
10662: }
10663: return $resulttext;
10664: }
10665:
10666: sub modify_loadbalancing {
10667: my ($dom,%domconfig) = @_;
10668: my $primary_id = &Apache::lonnet::domain($dom,'primary');
10669: my $intdom = &Apache::lonnet::internet_dom($primary_id);
10670: my ($othertitle,$usertypes,$types) =
10671: &Apache::loncommon::sorted_inst_types($dom);
10672: my %servers = &Apache::lonnet::internet_dom_servers($dom);
10673: my @sparestypes = ('primary','default');
10674: my %typetitles = &sparestype_titles();
10675: my $resulttext;
10676: my (%currbalancer,%currtargets,%currrules,%existing);
10677: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
10678: %existing = %{$domconfig{'loadbalancing'}};
10679: }
10680: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
10681: \%currtargets,\%currrules);
10682: my ($saveloadbalancing,%defaultshash,%changes);
10683: my ($alltypes,$othertypes,$titles) =
10684: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
10685: my %ruletitles = &offloadtype_text();
10686: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
10687: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
10688: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
10689: if ($balancer eq '') {
10690: next;
10691: }
10692: if (!exists($servers{$balancer})) {
10693: if (exists($currbalancer{$balancer})) {
10694: push(@{$changes{'delete'}},$balancer);
10695: }
10696: next;
10697: }
10698: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
10699: push(@{$changes{'delete'}},$balancer);
10700: next;
10701: }
10702: if (!exists($currbalancer{$balancer})) {
10703: push(@{$changes{'add'}},$balancer);
10704: }
10705: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
10706: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
10707: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
10708: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
10709: $saveloadbalancing = 1;
10710: }
10711: foreach my $sparetype (@sparestypes) {
10712: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
10713: my @offloadto;
10714: foreach my $target (@targets) {
10715: if (($servers{$target}) && ($target ne $balancer)) {
10716: if ($sparetype eq 'default') {
10717: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
10718: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
10719: }
10720: }
10721: unless(grep(/^\Q$target\E$/,@offloadto)) {
10722: push(@offloadto,$target);
10723: }
10724: }
10725: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
10726: }
10727: }
10728: if (ref($currtargets{$balancer}) eq 'HASH') {
10729: foreach my $sparetype (@sparestypes) {
10730: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
10731: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
10732: if (@targetdiffs > 0) {
10733: $changes{'curr'}{$balancer}{'targets'} = 1;
10734: }
10735: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10736: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10737: $changes{'curr'}{$balancer}{'targets'} = 1;
10738: }
10739: }
10740: }
10741: } else {
10742: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
10743: foreach my $sparetype (@sparestypes) {
10744: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10745: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10746: $changes{'curr'}{$balancer}{'targets'} = 1;
10747: }
10748: }
10749: }
10750: }
10751: }
10752: my $ishomedom;
10753: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
10754: $ishomedom = 1;
10755: }
10756: if (ref($alltypes) eq 'ARRAY') {
10757: foreach my $type (@{$alltypes}) {
10758: my $rule;
10759: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
10760: (!$ishomedom)) {
10761: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
10762: }
10763: if ($rule eq 'specific') {
10764: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
10765: }
10766: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
10767: if (ref($currrules{$balancer}) eq 'HASH') {
10768: if ($rule ne $currrules{$balancer}{$type}) {
10769: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
10770: }
10771: } elsif ($rule ne '') {
10772: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
10773: }
10774: }
10775: }
10776: }
10777: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
10778: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
10779: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
10780: $defaultshash{'loadbalancing'} = {};
10781: }
10782: my $putresult = &Apache::lonnet::put_dom('configuration',
10783: \%defaultshash,$dom);
10784: if ($putresult eq 'ok') {
10785: if (keys(%changes) > 0) {
10786: if (ref($changes{'delete'}) eq 'ARRAY') {
10787: foreach my $balancer (sort(@{$changes{'delete'}})) {
10788: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
10789: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
10790: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
10791: }
10792: }
10793: if (ref($changes{'add'}) eq 'ARRAY') {
10794: foreach my $balancer (sort(@{$changes{'add'}})) {
10795: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
10796: }
10797: }
10798: if (ref($changes{'curr'}) eq 'HASH') {
10799: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
10800: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
10801: if ($changes{'curr'}{$balancer}{'targets'}) {
10802: my %offloadstr;
10803: foreach my $sparetype (@sparestypes) {
10804: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10805: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10806: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
10807: }
10808: }
10809: }
10810: if (keys(%offloadstr) == 0) {
10811: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
10812: } else {
10813: my $showoffload;
10814: foreach my $sparetype (@sparestypes) {
10815: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
10816: if (defined($offloadstr{$sparetype})) {
10817: $showoffload .= $offloadstr{$sparetype};
10818: } else {
10819: $showoffload .= &mt('None');
10820: }
10821: $showoffload .= (' 'x3);
10822: }
10823: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
10824: }
10825: }
10826: }
10827: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
10828: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
10829: foreach my $type (@{$alltypes}) {
10830: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
10831: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
10832: my $balancetext;
10833: if ($rule eq '') {
10834: $balancetext = $ruletitles{'default'};
10835: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
10836: ($rule eq 'balancer') || ($rule eq 'offloadedto')) {
10837: $balancetext = $ruletitles{$rule};
10838: } else {
10839: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
10840: }
10841: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
10842: }
10843: }
10844: }
10845: }
10846: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
10847: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
10848: }
10849: }
10850: if ($resulttext ne '') {
10851: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
10852: } else {
10853: $resulttext = $nochgmsg;
10854: }
10855: } else {
10856: $resulttext = $nochgmsg;
10857: }
10858: } else {
10859: $resulttext = '<span class="LC_error">'.
10860: &mt('An error occurred: [_1]',$putresult).'</span>';
10861: }
10862: } else {
10863: $resulttext = $nochgmsg;
10864: }
10865: return $resulttext;
10866: }
10867:
10868: sub recurse_check {
10869: my ($chkcats,$categories,$depth,$name) = @_;
10870: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
10871: my $chg = 0;
10872: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
10873: my $category = $chkcats->[$depth]{$name}[$j];
10874: my $item;
10875: if ($category eq '') {
10876: $chg ++;
10877: } else {
10878: my $deeper = $depth + 1;
10879: $item = &escape($category).':'.&escape($name).':'.$depth;
10880: if ($chg) {
10881: $categories->{$item} -= $chg;
10882: }
10883: &recurse_check($chkcats,$categories,$deeper,$category);
10884: $deeper --;
10885: }
10886: }
10887: }
10888: return;
10889: }
10890:
10891: sub recurse_cat_deletes {
10892: my ($item,$coursecategories,$deletions) = @_;
10893: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
10894: my $subdepth = $depth + 1;
10895: if (ref($coursecategories) eq 'HASH') {
10896: foreach my $subitem (keys(%{$coursecategories})) {
10897: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
10898: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
10899: delete($coursecategories->{$subitem});
10900: $deletions->{$subitem} = 1;
10901: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
10902: }
10903: }
10904: }
10905: return;
10906: }
10907:
10908: sub get_active_dcs {
10909: my ($dom) = @_;
10910: my $now = time;
10911: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
10912: my %domcoords;
10913: my $numdcs = 0;
10914: foreach my $server (keys(%dompersonnel)) {
10915: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
10916: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
10917: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
10918: }
10919: }
10920: return %domcoords;
10921: }
10922:
10923: sub active_dc_picker {
10924: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
10925: my %domcoords = &get_active_dcs($dom);
10926: my @domcoord = keys(%domcoords);
10927: if (keys(%currhash)) {
10928: foreach my $dc (keys(%currhash)) {
10929: unless (exists($domcoords{$dc})) {
10930: push(@domcoord,$dc);
10931: }
10932: }
10933: }
10934: @domcoord = sort(@domcoord);
10935: my $numdcs = scalar(@domcoord);
10936: my $rows = 0;
10937: my $table;
10938: if ($numdcs > 1) {
10939: $table = '<table>';
10940: for (my $i=0; $i<@domcoord; $i++) {
10941: my $rem = $i%($numinrow);
10942: if ($rem == 0) {
10943: if ($i > 0) {
10944: $table .= '</tr>';
10945: }
10946: $table .= '<tr>';
10947: $rows ++;
10948: }
10949: my $check = '';
10950: if ($inputtype eq 'radio') {
10951: if (keys(%currhash) == 0) {
10952: if (!$i) {
10953: $check = ' checked="checked"';
10954: }
10955: } elsif (exists($currhash{$domcoord[$i]})) {
10956: $check = ' checked="checked"';
10957: }
10958: } else {
10959: if (exists($currhash{$domcoord[$i]})) {
10960: $check = ' checked="checked"';
10961: }
10962: }
10963: if ($i == @domcoord - 1) {
10964: my $colsleft = $numinrow - $rem;
10965: if ($colsleft > 1) {
10966: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
10967: } else {
10968: $table .= '<td class="LC_left_item">';
10969: }
10970: } else {
10971: $table .= '<td class="LC_left_item">';
10972: }
10973: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
10974: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
10975: $table .= '<span class="LC_nobreak"><label>'.
10976: '<input type="'.$inputtype.'" name="'.$name.'"'.
10977: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
10978: if ($user ne $dcname.':'.$dcdom) {
10979: $table .= ' ('.$dcname.':'.$dcdom.')';
10980: }
10981: $table .= '</label></span></td>';
10982: }
10983: $table .= '</tr></table>';
10984: } elsif ($numdcs == 1) {
10985: my ($dcname,$dcdom) = split(':',$domcoord[0]);
10986: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
10987: if ($inputtype eq 'radio') {
10988: $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
10989: if ($user ne $dcname.':'.$dcdom) {
10990: $table .= ' ('.$dcname.':'.$dcdom.')';
10991: }
10992: } else {
10993: my $check;
10994: if (exists($currhash{$domcoord[0]})) {
10995: $check = ' checked="checked"';
10996: }
10997: $table .= '<span class="LC_nobreak"><label>'.
10998: '<input type="checkbox" name="'.$name.'" '.
10999: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
11000: if ($user ne $dcname.':'.$dcdom) {
11001: $table .= ' ('.$dcname.':'.$dcdom.')';
11002: }
11003: $table .= '</label></span>';
11004: $rows ++;
11005: }
11006: }
11007: return ($numdcs,$table,$rows);
11008: }
11009:
11010: sub usersession_titles {
11011: return &Apache::lonlocal::texthash(
11012: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
11013: remote => 'Hosting of sessions for users in this domain on servers in other domains',
11014: spares => 'Servers offloaded to, when busy',
11015: version => 'LON-CAPA version requirement',
11016: excludedomain => 'Allow all, but exclude specific domains',
11017: includedomain => 'Deny all, but include specific domains',
11018: primary => 'Primary (checked first)',
11019: default => 'Default',
11020: );
11021: }
11022:
11023: sub id_for_thisdom {
11024: my (%servers) = @_;
11025: my %altids;
11026: foreach my $server (keys(%servers)) {
11027: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
11028: if ($serverhome ne $server) {
11029: $altids{$serverhome} = $server;
11030: }
11031: }
11032: return %altids;
11033: }
11034:
11035: sub count_servers {
11036: my ($currbalancer,%servers) = @_;
11037: my (@spares,$numspares);
11038: foreach my $lonhost (sort(keys(%servers))) {
11039: next if ($currbalancer eq $lonhost);
11040: push(@spares,$lonhost);
11041: }
11042: if ($currbalancer) {
11043: $numspares = scalar(@spares);
11044: } else {
11045: $numspares = scalar(@spares) - 1;
11046: }
11047: return ($numspares,@spares);
11048: }
11049:
11050: sub lonbalance_targets_js {
11051: my ($dom,$types,$servers,$settings) = @_;
11052: my $select = &mt('Select');
11053: my ($alltargets,$allishome,$allinsttypes,@alltypes);
11054: if (ref($servers) eq 'HASH') {
11055: $alltargets = join("','",sort(keys(%{$servers})));
11056: my @homedoms;
11057: foreach my $server (sort(keys(%{$servers}))) {
11058: if (&Apache::lonnet::host_domain($server) eq $dom) {
11059: push(@homedoms,'1');
11060: } else {
11061: push(@homedoms,'0');
11062: }
11063: }
11064: $allishome = join("','",@homedoms);
11065: }
11066: if (ref($types) eq 'ARRAY') {
11067: if (@{$types} > 0) {
11068: @alltypes = @{$types};
11069: }
11070: }
11071: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
11072: $allinsttypes = join("','",@alltypes);
11073: my (%currbalancer,%currtargets,%currrules,%existing);
11074: if (ref($settings) eq 'HASH') {
11075: %existing = %{$settings};
11076: }
11077: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
11078: \%currtargets,\%currrules);
11079: my $balancers = join("','",sort(keys(%currbalancer)));
11080: return <<"END";
11081:
11082: <script type="text/javascript">
11083: // <![CDATA[
11084:
11085: currBalancers = new Array('$balancers');
11086:
11087: function toggleTargets(balnum) {
11088: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11089: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
11090: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
11091: var prevbalancer = prevhostitem.value;
11092: var baltotal = document.getElementById('loadbalancing_total').value;
11093: prevhostitem.value = balancer;
11094: if (prevbalancer != '') {
11095: var prevIdx = currBalancers.indexOf(prevbalancer);
11096: if (prevIdx != -1) {
11097: currBalancers.splice(prevIdx,1);
11098: }
11099: }
11100: if (balancer == '') {
11101: hideSpares(balnum);
11102: } else {
11103: var currIdx = currBalancers.indexOf(balancer);
11104: if (currIdx == -1) {
11105: currBalancers.push(balancer);
11106: }
11107: var homedoms = new Array('$allishome');
11108: var ishomedom = homedoms[lonhostitem.selectedIndex];
11109: showSpares(balancer,ishomedom,balnum);
11110: }
11111: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
11112: return;
11113: }
11114:
11115: function showSpares(balancer,ishomedom,balnum) {
11116: var alltargets = new Array('$alltargets');
11117: var insttypes = new Array('$allinsttypes');
11118: var offloadtypes = new Array('primary','default');
11119:
11120: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
11121: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
11122:
11123: for (var i=0; i<offloadtypes.length; i++) {
11124: var count = 0;
11125: for (var j=0; j<alltargets.length; j++) {
11126: if (alltargets[j] != balancer) {
11127: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
11128: item.value = alltargets[j];
11129: item.style.textAlign='left';
11130: item.style.textFace='normal';
11131: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
11132: if (currBalancers.indexOf(alltargets[j]) == -1) {
11133: item.disabled = '';
11134: } else {
11135: item.disabled = 'disabled';
11136: item.checked = false;
11137: }
11138: count ++;
11139: }
11140: }
11141: }
11142: for (var k=0; k<insttypes.length; k++) {
11143: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
11144: if (ishomedom == 1) {
11145: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11146: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
11147: } else {
11148: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11149: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
11150: }
11151: } else {
11152: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11153: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
11154: }
11155: if ((insttypes[k] != '_LC_external') &&
11156: ((insttypes[k] != '_LC_internetdom') ||
11157: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
11158: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
11159: item.options.length = 0;
11160: item.options[0] = new Option("","",true,true);
11161: var idx = 0;
11162: for (var m=0; m<alltargets.length; m++) {
11163: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
11164: idx ++;
11165: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
11166: }
11167: }
11168: }
11169: }
11170: return;
11171: }
11172:
11173: function hideSpares(balnum) {
11174: var alltargets = new Array('$alltargets');
11175: var insttypes = new Array('$allinsttypes');
11176: var offloadtypes = new Array('primary','default');
11177:
11178: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
11179: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
11180:
11181: var total = alltargets.length - 1;
11182: for (var i=0; i<offloadtypes; i++) {
11183: for (var j=0; j<total; j++) {
11184: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
11185: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
11186: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
11187: }
11188: }
11189: for (var k=0; k<insttypes.length; k++) {
11190: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11191: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
11192: if (insttypes[k] != '_LC_external') {
11193: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
11194: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
11195: }
11196: }
11197: return;
11198: }
11199:
11200: function checkOffloads(item,balnum,type) {
11201: var alltargets = new Array('$alltargets');
11202: var offloadtypes = new Array('primary','default');
11203: if (item.checked) {
11204: var total = alltargets.length - 1;
11205: var other;
11206: if (type == offloadtypes[0]) {
11207: other = offloadtypes[1];
11208: } else {
11209: other = offloadtypes[0];
11210: }
11211: for (var i=0; i<total; i++) {
11212: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
11213: if (server == item.value) {
11214: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
11215: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
11216: }
11217: }
11218: }
11219: }
11220: return;
11221: }
11222:
11223: function singleServerToggle(balnum,type) {
11224: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
11225: if (offloadtoSelIdx == 0) {
11226: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
11227: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
11228:
11229: } else {
11230: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
11231: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
11232: }
11233: return;
11234: }
11235:
11236: function balanceruleChange(formname,balnum,type) {
11237: if (type == '_LC_external') {
11238: return;
11239: }
11240: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
11241: for (var i=0; i<typesRules.length; i++) {
11242: if (formname.elements[typesRules[i]].checked) {
11243: if (formname.elements[typesRules[i]].value != 'specific') {
11244: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
11245: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
11246: } else {
11247: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
11248: }
11249: }
11250: }
11251: return;
11252: }
11253:
11254: function balancerDeleteChange(balnum) {
11255: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11256: var baltotal = document.getElementById('loadbalancing_total').value;
11257: var addtarget;
11258: var removetarget;
11259: var action = 'delete';
11260: if (document.getElementById('loadbalancing_delete_'+balnum)) {
11261: var lonhost = hostitem.value;
11262: var currIdx = currBalancers.indexOf(lonhost);
11263: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
11264: if (currIdx != -1) {
11265: currBalancers.splice(currIdx,1);
11266: }
11267: addtarget = lonhost;
11268: } else {
11269: if (currIdx == -1) {
11270: currBalancers.push(lonhost);
11271: }
11272: removetarget = lonhost;
11273: action = 'undelete';
11274: }
11275: balancerChange(balnum,baltotal,action,addtarget,removetarget);
11276: }
11277: return;
11278: }
11279:
11280: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
11281: if (baltotal > 1) {
11282: var offloadtypes = new Array('primary','default');
11283: var alltargets = new Array('$alltargets');
11284: var insttypes = new Array('$allinsttypes');
11285: for (var i=0; i<baltotal; i++) {
11286: if (i != balnum) {
11287: for (var j=0; j<offloadtypes.length; j++) {
11288: var total = alltargets.length - 1;
11289: for (var k=0; k<total; k++) {
11290: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
11291: var server = serveritem.value;
11292: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11293: if (server == addtarget) {
11294: serveritem.disabled = '';
11295: }
11296: }
11297: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11298: if (server == removetarget) {
11299: serveritem.disabled = 'disabled';
11300: serveritem.checked = false;
11301: }
11302: }
11303: }
11304: }
11305: for (var j=0; j<insttypes.length; j++) {
11306: if (insttypes[j] != '_LC_external') {
11307: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
11308: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
11309: var currSel = singleserver.selectedIndex;
11310: var currVal = singleserver.options[currSel].value;
11311: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11312: var numoptions = singleserver.options.length;
11313: var needsnew = 1;
11314: for (var k=0; k<numoptions; k++) {
11315: if (singleserver.options[k] == addtarget) {
11316: needsnew = 0;
11317: break;
11318: }
11319: }
11320: if (needsnew == 1) {
11321: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
11322: }
11323: }
11324: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11325: singleserver.options.length = 0;
11326: if ((currVal) && (currVal != removetarget)) {
11327: singleserver.options[0] = new Option("","",false,false);
11328: } else {
11329: singleserver.options[0] = new Option("","",true,true);
11330: }
11331: var idx = 0;
11332: for (var m=0; m<alltargets.length; m++) {
11333: if (currBalancers.indexOf(alltargets[m]) == -1) {
11334: idx ++;
11335: if (currVal == alltargets[m]) {
11336: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
11337: } else {
11338: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
11339: }
11340: }
11341: }
11342: }
11343: }
11344: }
11345: }
11346: }
11347: }
11348: }
11349: return;
11350: }
11351:
11352: // ]]>
11353: </script>
11354:
11355: END
11356: }
11357:
11358: sub new_spares_js {
11359: my @sparestypes = ('primary','default');
11360: my $types = join("','",@sparestypes);
11361: my $select = &mt('Select');
11362: return <<"END";
11363:
11364: <script type="text/javascript">
11365: // <![CDATA[
11366:
11367: function updateNewSpares(formname,lonhost) {
11368: var types = new Array('$types');
11369: var include = new Array();
11370: var exclude = new Array();
11371: for (var i=0; i<types.length; i++) {
11372: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
11373: for (var j=0; j<spareboxes.length; j++) {
11374: if (formname.elements[spareboxes[j]].checked) {
11375: exclude.push(formname.elements[spareboxes[j]].value);
11376: } else {
11377: include.push(formname.elements[spareboxes[j]].value);
11378: }
11379: }
11380: }
11381: for (var i=0; i<types.length; i++) {
11382: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
11383: var selIdx = newSpare.selectedIndex;
11384: var currnew = newSpare.options[selIdx].value;
11385: var okSpares = new Array();
11386: for (var j=0; j<newSpare.options.length; j++) {
11387: var possible = newSpare.options[j].value;
11388: if (possible != '') {
11389: if (exclude.indexOf(possible) == -1) {
11390: okSpares.push(possible);
11391: } else {
11392: if (currnew == possible) {
11393: selIdx = 0;
11394: }
11395: }
11396: }
11397: }
11398: for (var k=0; k<include.length; k++) {
11399: if (okSpares.indexOf(include[k]) == -1) {
11400: okSpares.push(include[k]);
11401: }
11402: }
11403: okSpares.sort();
11404: newSpare.options.length = 0;
11405: if (selIdx == 0) {
11406: newSpare.options[0] = new Option("$select","",true,true);
11407: } else {
11408: newSpare.options[0] = new Option("$select","",false,false);
11409: }
11410: for (var m=0; m<okSpares.length; m++) {
11411: var idx = m+1;
11412: var selThis = 0;
11413: if (selIdx != 0) {
11414: if (okSpares[m] == currnew) {
11415: selThis = 1;
11416: }
11417: }
11418: if (selThis == 1) {
11419: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
11420: } else {
11421: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
11422: }
11423: }
11424: }
11425: return;
11426: }
11427:
11428: function checkNewSpares(lonhost,type) {
11429: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
11430: var chosen = newSpare.options[newSpare.selectedIndex].value;
11431: if (chosen != '') {
11432: var othertype;
11433: var othernewSpare;
11434: if (type == 'primary') {
11435: othernewSpare = document.getElementById('newspare_default_'+lonhost);
11436: }
11437: if (type == 'default') {
11438: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
11439: }
11440: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
11441: othernewSpare.selectedIndex = 0;
11442: }
11443: }
11444: return;
11445: }
11446:
11447: // ]]>
11448: </script>
11449:
11450: END
11451:
11452: }
11453:
11454: sub common_domprefs_js {
11455: return <<"END";
11456:
11457: <script type="text/javascript">
11458: // <![CDATA[
11459:
11460: function getIndicesByName(formname,item) {
11461: var group = new Array();
11462: for (var i=0;i<formname.elements.length;i++) {
11463: if (formname.elements[i].name == item) {
11464: group.push(formname.elements[i].id);
11465: }
11466: }
11467: return group;
11468: }
11469:
11470: // ]]>
11471: </script>
11472:
11473: END
11474:
11475: }
11476:
11477: sub recaptcha_js {
11478: my %lt = &captcha_phrases();
11479: return <<"END";
11480:
11481: <script type="text/javascript">
11482: // <![CDATA[
11483:
11484: function updateCaptcha(caller,context) {
11485: var privitem;
11486: var pubitem;
11487: var privtext;
11488: var pubtext;
11489: if (document.getElementById(context+'_recaptchapub')) {
11490: pubitem = document.getElementById(context+'_recaptchapub');
11491: } else {
11492: return;
11493: }
11494: if (document.getElementById(context+'_recaptchapriv')) {
11495: privitem = document.getElementById(context+'_recaptchapriv');
11496: } else {
11497: return;
11498: }
11499: if (document.getElementById(context+'_recaptchapubtxt')) {
11500: pubtext = document.getElementById(context+'_recaptchapubtxt');
11501: } else {
11502: return;
11503: }
11504: if (document.getElementById(context+'_recaptchaprivtxt')) {
11505: privtext = document.getElementById(context+'_recaptchaprivtxt');
11506: } else {
11507: return;
11508: }
11509: if (caller.checked) {
11510: if (caller.value == 'recaptcha') {
11511: pubitem.type = 'text';
11512: privitem.type = 'text';
11513: pubitem.size = '40';
11514: privitem.size = '40';
11515: pubtext.innerHTML = "$lt{'pub'}";
11516: privtext.innerHTML = "$lt{'priv'}";
11517: } else {
11518: pubitem.type = 'hidden';
11519: privitem.type = 'hidden';
11520: pubtext.innerHTML = '';
11521: privtext.innerHTML = '';
11522: }
11523: }
11524: return;
11525: }
11526:
11527: // ]]>
11528: </script>
11529:
11530: END
11531:
11532: }
11533:
11534: sub toggle_display_js {
11535: return <<"END";
11536:
11537: <script type="text/javascript">
11538: // <![CDATA[
11539:
11540: function toggleDisplay(domForm,caller) {
11541: if (document.getElementById(caller)) {
11542: var divitem = document.getElementById(caller);
11543: var optionsElement = domForm.coursecredits;
11544: if (caller == 'emailoptions') {
11545: optionsElement = domForm.cancreate_email;
11546: }
11547: if (optionsElement.length) {
11548: var currval;
11549: for (var i=0; i<optionsElement.length; i++) {
11550: if (optionsElement[i].checked) {
11551: currval = optionsElement[i].value;
11552: }
11553: }
11554: if (currval == 1) {
11555: divitem.style.display = 'block';
11556: } else {
11557: divitem.style.display = 'none';
11558: }
11559: }
11560: }
11561: return;
11562: }
11563:
11564: // ]]>
11565: </script>
11566:
11567: END
11568:
11569: }
11570:
11571: sub captcha_phrases {
11572: return &Apache::lonlocal::texthash (
11573: priv => 'Private key',
11574: pub => 'Public key',
11575: original => 'original (CAPTCHA)',
11576: recaptcha => 'successor (ReCAPTCHA)',
11577: notused => 'unused',
11578: );
11579: }
11580:
11581: sub devalidate_remote_domconfs {
11582: my ($dom,$cachekeys) = @_;
11583: return unless (ref($cachekeys) eq 'HASH');
11584: my %servers = &Apache::lonnet::internet_dom_servers($dom);
11585: my %thismachine;
11586: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
11587: my @posscached = ('domainconfig','domdefaults');
11588: if (keys(%servers) > 1) {
11589: foreach my $server (keys(%servers)) {
11590: next if ($thismachine{$server});
11591: my @cached;
11592: foreach my $name (@posscached) {
11593: if ($cachekeys->{$name}) {
11594: push(@cached,&escape($name).':'.&escape($dom));
11595: }
11596: }
11597: if (@cached) {
11598: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
11599: }
11600: }
11601: }
11602: return;
11603: }
11604:
11605: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>