1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
4: # $Id: domainprefs.pm,v 1.160.6.84.2.6 2017/10/17 14:08: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: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
30: ###############################################################
31:
32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
49: for use by individuals affiliated with the institution. Accordingly, each domain
50: may define a default set of logos and a color scheme which can be used to "brand"
51: the LON-CAPA instance. In addition, an institution will typically have a language
52: and timezone which are used for the majority of courses.
53:
54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
55: host of other domain-wide settings which determine the types of functionality
56: available to users and courses in the domain.
57:
58: There is also a mechanism to configure cataloging of courses in the domain, and
59: controls on the operation of automated processes which govern such things as
60: roster updates, user directory updates and processing of course requests.
61:
62: The domain coordination manual which is built dynamically on install/update of
63: LON-CAPA from the relevant help items provides more information about domain
64: configuration.
65:
66: Most of the domain settings are stored in the configuration.db GDBM file which is
67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
68: where $dom is the domain. The configuration.db stores settings in a number of
69: frozen hashes of hashes. In a few cases, domain information must be uploaded to
70: the domain as files (e.g., image files for logos etc., or plain text files for
71: bubblesheet formats). In this case the domainprefs.pm must be running in a user
72: session hosted on the primary library server in the domain, as these files are
73: stored in author space belonging to a special $dom-domainconfig user.
74:
75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
76: the current settings, and provides an interface to make modifications.
77:
78: =head1 SUBROUTINES
79:
80: =over
81:
82: =item print_quotas()
83:
84: Inputs: 4
85:
86: $dom,$settings,$rowtotal,$action.
87:
88: $dom is the domain, $settings is a reference to a hash of current settings for
89: the current context, $rowtotal is a reference to the scalar used to record the
90: number of rows displayed on the page, and $action is the context (quotas,
91: requestcourses or requestauthor).
92:
93: The print_quotas routine was orginally created to display/store information
94: about default quota sizes for portfolio spaces for the different types of
95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
96: but is now also used to manage availability of user tools:
97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
98: used by course owners to request creation of a course, and to display/store
99: default quota sizes for Authoring Spaces.
100:
101: Outputs: 1
102:
103: $datatable - HTML containing form elements which allow settings to be changed.
104:
105: In the case of course requests, radio buttons are displayed for each institutional
106: affiliate type (and also default, and _LC_adv) for each of the course types
107: (official, unofficial, community, and textbook). In each case the radio buttons
108: allow the selection of one of four values:
109:
110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
111: which have the following effects:
112:
113: 0
114:
115: =over
116:
117: - course requests are not allowed for this course types/affiliation
118:
119: =back
120:
121: approval
122:
123: =over
124:
125: - course requests must be approved by a Doman Coordinator in the
126: course's domain
127:
128: =back
129:
130: validate
131:
132: =over
133:
134: - an institutional validation (e.g., check requestor is instructor
135: of record) needs to be passed before the course will be created. The required
136: validation is in localenroll.pm on the primary library server for the course
137: domain.
138:
139: =back
140:
141: autolimit
142:
143: =over
144:
145: - course requests will be processed automatically up to a limit of
146: N requests for the course type for the particular requestor.
147: If N is undefined, there is no limit to the number of course requests
148: which a course owner may submit and have processed automatically.
149:
150: =back
151:
152: =item modify_quotas()
153:
154: =back
155:
156: =cut
157:
158: package Apache::domainprefs;
159:
160: use strict;
161: use Apache::Constants qw(:common :http);
162: use Apache::lonnet;
163: use Apache::loncommon();
164: use Apache::lonhtmlcommon();
165: use Apache::lonlocal;
166: use Apache::lonmsg();
167: use Apache::lonconfigsettings;
168: use Apache::lonuserutils();
169: use Apache::loncoursequeueadmin();
170: use LONCAPA qw(:DEFAULT :match);
171: use LONCAPA::Enrollment;
172: use LONCAPA::lonauthcgi();
173: use File::Copy;
174: use Locale::Language;
175: use DateTime::TimeZone;
176: use DateTime::Locale;
177:
178: my $registered_cleanup;
179: my $modified_urls;
180:
181: sub handler {
182: my $r=shift;
183: if ($r->header_only) {
184: &Apache::loncommon::content_type($r,'text/html');
185: $r->send_http_header;
186: return OK;
187: }
188:
189: my $context = 'domain';
190: my $dom = $env{'request.role.domain'};
191: my $domdesc = &Apache::lonnet::domain($dom,'description');
192: if (&Apache::lonnet::allowed('mau',$dom)) {
193: &Apache::loncommon::content_type($r,'text/html');
194: $r->send_http_header;
195: } else {
196: $env{'user.error.msg'}=
197: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
198: return HTTP_NOT_ACCEPTABLE;
199: }
200:
201: $registered_cleanup=0;
202: @{$modified_urls}=();
203:
204: &Apache::lonhtmlcommon::clear_breadcrumbs();
205: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
206: ['phase','actions']);
207: my $phase = 'pickactions';
208: if ( exists($env{'form.phase'}) ) {
209: $phase = $env{'form.phase'};
210: }
211: my %servers = &Apache::lonnet::internet_dom_servers($dom);
212: my %domconfig =
213: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
214: 'quotas','autoenroll','autoupdate','autocreate',
215: 'directorysrch','usercreation','usermodification',
216: 'contacts','defaults','scantron','coursecategories',
217: 'serverstatuses','requestcourses','helpsettings',
218: 'coursedefaults','usersessions','loadbalancing',
219: 'requestauthor','selfenrollment','inststatus',
220: 'ltitools'],$dom);
221: if (ref($domconfig{'ltitools'}) eq 'HASH') {
222: my %encconfig =
223: &Apache::lonnet::get_dom('encconfig',['ltitools'],$dom);
224: if (ref($encconfig{'ltitools'}) eq 'HASH') {
225: foreach my $id (keys(%{$domconfig{'ltitools'}})) {
226: if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
227: foreach my $item ('key','secret') {
228: $domconfig{'ltitools'}{$id}{$item} = $encconfig{'ltitools'}{$id}{$item};
229: }
230: }
231: }
232: }
233: }
234: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
235: 'autoupdate','autocreate','directorysrch','contacts',
236: 'usercreation','selfcreation','usermodification','scantron',
237: 'requestcourses','requestauthor','coursecategories',
238: 'serverstatuses','helpsettings','coursedefaults',
239: 'ltitools','selfenrollment','usersessions');
240: my %existing;
241: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
242: %existing = %{$domconfig{'loadbalancing'}};
243: }
244: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
245: push(@prefs_order,'loadbalancing');
246: }
247: my %prefs = (
248: 'rolecolors' =>
249: { text => 'Default color schemes',
250: help => 'Domain_Configuration_Color_Schemes',
251: header => [{col1 => 'Student Settings',
252: col2 => '',},
253: {col1 => 'Coordinator Settings',
254: col2 => '',},
255: {col1 => 'Author Settings',
256: col2 => '',},
257: {col1 => 'Administrator Settings',
258: col2 => '',}],
259: print => \&print_rolecolors,
260: modify => \&modify_rolecolors,
261: },
262: 'login' =>
263: { text => 'Log-in page options',
264: help => 'Domain_Configuration_Login_Page',
265: header => [{col1 => 'Log-in Page Items',
266: col2 => '',},
267: {col1 => 'Log-in Help',
268: col2 => 'Value'},
269: {col1 => 'Custom HTML in document head',
270: col2 => 'Value'}],
271: print => \&print_login,
272: modify => \&modify_login,
273: },
274: 'defaults' =>
275: { text => 'Default authentication/language/timezone/portal/types',
276: help => 'Domain_Configuration_LangTZAuth',
277: header => [{col1 => 'Setting',
278: col2 => 'Value'},
279: {col1 => 'Internal Authentication',
280: col2 => 'Value'},
281: {col1 => 'Institutional user types',
282: col2 => 'Assignable to e-mail usernames'}],
283: print => \&print_defaults,
284: modify => \&modify_defaults,
285: },
286: 'quotas' =>
287: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
288: help => 'Domain_Configuration_Quotas',
289: header => [{col1 => 'User affiliation',
290: col2 => 'Available tools',
291: col3 => 'Quotas, MB; (Authoring requires role)',}],
292: print => \&print_quotas,
293: modify => \&modify_quotas,
294: },
295: 'autoenroll' =>
296: { text => 'Auto-enrollment settings',
297: help => 'Domain_Configuration_Auto_Enrollment',
298: header => [{col1 => 'Configuration setting',
299: col2 => 'Value(s)'}],
300: print => \&print_autoenroll,
301: modify => \&modify_autoenroll,
302: },
303: 'autoupdate' =>
304: { text => 'Auto-update settings',
305: help => 'Domain_Configuration_Auto_Updates',
306: header => [{col1 => 'Setting',
307: col2 => 'Value',},
308: {col1 => 'Setting',
309: col2 => 'Affiliation'},
310: {col1 => 'User population',
311: col2 => 'Updatable user data'}],
312: print => \&print_autoupdate,
313: modify => \&modify_autoupdate,
314: },
315: 'autocreate' =>
316: { text => 'Auto-course creation settings',
317: help => 'Domain_Configuration_Auto_Creation',
318: header => [{col1 => 'Configuration Setting',
319: col2 => 'Value',}],
320: print => \&print_autocreate,
321: modify => \&modify_autocreate,
322: },
323: 'directorysrch' =>
324: { text => 'Directory searches',
325: help => 'Domain_Configuration_InstDirectory_Search',
326: header => [{col1 => 'Institutional Directory Setting',
327: col2 => 'Value',},
328: {col1 => 'LON-CAPA Directory Setting',
329: col2 => 'Value',}],
330: print => \&print_directorysrch,
331: modify => \&modify_directorysrch,
332: },
333: 'contacts' =>
334: { text => 'E-mail addresses and helpform',
335: help => 'Domain_Configuration_Contact_Info',
336: header => [{col1 => 'Default e-mail addresses',
337: col2 => 'Value',},
338: {col1 => 'Recipient(s) for notifications',
339: col2 => 'Value',},
340: {col1 => 'Ask helpdesk form settings',
341: col2 => 'Value',},],
342: print => \&print_contacts,
343: modify => \&modify_contacts,
344: },
345: 'usercreation' =>
346: { text => 'User creation',
347: help => 'Domain_Configuration_User_Creation',
348: header => [{col1 => 'Format rule type',
349: col2 => 'Format rules in force'},
350: {col1 => 'User account creation',
351: col2 => 'Usernames which may be created',},
352: {col1 => 'Context',
353: col2 => 'Assignable authentication types'}],
354: print => \&print_usercreation,
355: modify => \&modify_usercreation,
356: },
357: 'selfcreation' =>
358: { text => 'Users self-creating accounts',
359: help => 'Domain_Configuration_Self_Creation',
360: header => [{col1 => 'Self-creation with institutional username',
361: col2 => 'Enabled?'},
362: {col1 => 'Institutional user type (login/SSO self-creation)',
363: col2 => 'Information user can enter'},
364: {col1 => 'Self-creation with e-mail as username',
365: col2 => 'Settings'}],
366: print => \&print_selfcreation,
367: modify => \&modify_selfcreation,
368: },
369: 'usermodification' =>
370: { text => 'User modification',
371: help => 'Domain_Configuration_User_Modification',
372: header => [{col1 => 'Target user has role',
373: col2 => 'User information updatable in author context'},
374: {col1 => 'Target user has role',
375: col2 => 'User information updatable in course context'}],
376: print => \&print_usermodification,
377: modify => \&modify_usermodification,
378: },
379: 'scantron' =>
380: { text => 'Bubblesheet format file',
381: help => 'Domain_Configuration_Scantron_Format',
382: header => [ {col1 => 'Item',
383: col2 => '',
384: }],
385: print => \&print_scantron,
386: modify => \&modify_scantron,
387: },
388: 'requestcourses' =>
389: {text => 'Request creation of courses',
390: help => 'Domain_Configuration_Request_Courses',
391: header => [{col1 => 'User affiliation',
392: col2 => 'Availability/Processing of requests',},
393: {col1 => 'Setting',
394: col2 => 'Value'},
395: {col1 => 'Available textbooks',
396: col2 => ''},
397: {col1 => 'Available templates',
398: col2 => ''},
399: {col1 => 'Validation (not official courses)',
400: col2 => 'Value'},],
401: print => \&print_quotas,
402: modify => \&modify_quotas,
403: },
404: 'requestauthor' =>
405: {text => 'Request Authoring Space',
406: help => 'Domain_Configuration_Request_Author',
407: header => [{col1 => 'User affiliation',
408: col2 => 'Availability/Processing of requests',},
409: {col1 => 'Setting',
410: col2 => 'Value'}],
411: print => \&print_quotas,
412: modify => \&modify_quotas,
413: },
414: 'coursecategories' =>
415: { text => 'Cataloging of courses/communities',
416: help => 'Domain_Configuration_Cataloging_Courses',
417: header => [{col1 => 'Catalog type/availability',
418: col2 => '',},
419: {col1 => 'Category settings for standard catalog',
420: col2 => '',},
421: {col1 => 'Categories',
422: col2 => '',
423: }],
424: print => \&print_coursecategories,
425: modify => \&modify_coursecategories,
426: },
427: 'serverstatuses' =>
428: {text => 'Access to server status pages',
429: help => 'Domain_Configuration_Server_Status',
430: header => [{col1 => 'Status Page',
431: col2 => 'Other named users',
432: col3 => 'Specific IPs',
433: }],
434: print => \&print_serverstatuses,
435: modify => \&modify_serverstatuses,
436: },
437: 'helpsettings' =>
438: {text => 'Support settings',
439: help => 'Domain_Configuration_Help_Settings',
440: header => [{col1 => 'Help Page Settings (logged-in users)',
441: col2 => 'Value'},
442: {col1 => 'Helpdesk Roles',
443: col2 => 'Settings'},],
444: print => \&print_helpsettings,
445: modify => \&modify_helpsettings,
446: },
447: 'coursedefaults' =>
448: {text => 'Course/Community defaults',
449: help => 'Domain_Configuration_Course_Defaults',
450: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
451: col2 => 'Value',},
452: {col1 => 'Defaults which can be overridden for each course by a DC',
453: col2 => 'Value',},],
454: print => \&print_coursedefaults,
455: modify => \&modify_coursedefaults,
456: },
457: 'selfenrollment' =>
458: {text => 'Self-enrollment in Course/Community',
459: help => 'Domain_Configuration_Selfenrollment',
460: header => [{col1 => 'Configuration Rights',
461: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
462: {col1 => 'Defaults',
463: col2 => 'Value'},
464: {col1 => 'Self-enrollment validation (optional)',
465: col2 => 'Value'},],
466: print => \&print_selfenrollment,
467: modify => \&modify_selfenrollment,
468: },
469: 'usersessions' =>
470: {text => 'User session hosting/offloading',
471: help => 'Domain_Configuration_User_Sessions',
472: header => [{col1 => 'Domain server',
473: col2 => 'Servers to offload sessions to when busy'},
474: {col1 => 'Hosting of users from other domains',
475: col2 => 'Rules'},
476: {col1 => "Hosting domain's own users elsewhere",
477: col2 => 'Rules'}],
478: print => \&print_usersessions,
479: modify => \&modify_usersessions,
480: },
481: 'loadbalancing' =>
482: {text => 'Dedicated Load Balancer(s)',
483: help => 'Domain_Configuration_Load_Balancing',
484: header => [{col1 => 'Balancers',
485: col2 => 'Default destinations',
486: col3 => 'User affiliation',
487: col4 => 'Overrides'},
488: ],
489: print => \&print_loadbalancing,
490: modify => \&modify_loadbalancing,
491: },
492: 'ltitools' =>
493: {text => 'External Tools (LTI)',
494: help => 'Domain_Configuration_LTI_Tools',
495: header => [{col1 => 'Setting',
496: col2 => 'Value',}],
497: print => \&print_ltitools,
498: modify => \&modify_ltitools,
499: },
500: );
501: if (keys(%servers) > 1) {
502: $prefs{'login'} = { text => 'Log-in page options',
503: help => 'Domain_Configuration_Login_Page',
504: header => [{col1 => 'Log-in Service',
505: col2 => 'Server Setting',},
506: {col1 => 'Log-in Page Items',
507: col2 => ''},
508: {col1 => 'Log-in Help',
509: col2 => 'Value'},
510: {col1 => 'Custom HTML in document head',
511: col2 => 'Value'}],
512: print => \&print_login,
513: modify => \&modify_login,
514: };
515: }
516:
517: my @roles = ('student','coordinator','author','admin');
518: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
519: &Apache::lonhtmlcommon::add_breadcrumb
520: ({href=>"javascript:changePage(document.$phase,'pickactions')",
521: text=>"Settings to display/modify"});
522: my $confname = $dom.'-domainconfig';
523:
524: if ($phase eq 'process') {
525: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
526: \%prefs,\%domconfig,$confname,\@roles);
527: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
528: $r->rflush();
529: &devalidate_remote_domconfs($dom,$result);
530: }
531: } elsif ($phase eq 'display') {
532: my $js = &recaptcha_js().
533: &toggle_display_js();
534: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
535: my ($othertitle,$usertypes,$types) =
536: &Apache::loncommon::sorted_inst_types($dom);
537: $js .= &lonbalance_targets_js($dom,$types,\%servers,
538: $domconfig{'loadbalancing'}).
539: &new_spares_js().
540: &common_domprefs_js().
541: &Apache::loncommon::javascript_array_indexof();
542: }
543: if (grep(/^requestcourses$/,@actions)) {
544: my $javascript_validations;
545: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
546: $js .= <<END;
547: <script type="text/javascript">
548: $javascript_validations
549: </script>
550: $coursebrowserjs
551: END
552: }
553: if (grep(/^contacts$/,@actions)) {
554: $js .= &contacts_javascript();
555: }
556: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
557: } else {
558: # check if domconfig user exists for the domain.
559: my $servadm = $r->dir_config('lonAdmEMail');
560: my ($configuserok,$author_ok,$switchserver) =
561: &config_check($dom,$confname,$servadm);
562: unless ($configuserok eq 'ok') {
563: &Apache::lonconfigsettings::print_header($r,$phase,$context);
564: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
565: $confname).
566: '<br />'
567: );
568: if ($switchserver) {
569: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
570: '<br />'.
571: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
572: '<br />'.
573: &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).
574: '<br />'.
575: &mt('To do that now, use the following link: [_1]',$switchserver)
576: );
577: } else {
578: $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.').
579: '<br />'.
580: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
581: );
582: }
583: $r->print(&Apache::loncommon::end_page());
584: return OK;
585: }
586: if (keys(%domconfig) == 0) {
587: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
588: my @ids=&Apache::lonnet::current_machine_ids();
589: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
590: my %designhash = &Apache::loncommon::get_domainconf($dom);
591: my @loginimages = ('img','logo','domlogo','login');
592: my $custom_img_count = 0;
593: foreach my $img (@loginimages) {
594: if ($designhash{$dom.'.login.'.$img} ne '') {
595: $custom_img_count ++;
596: }
597: }
598: foreach my $role (@roles) {
599: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
600: $custom_img_count ++;
601: }
602: }
603: if ($custom_img_count > 0) {
604: &Apache::lonconfigsettings::print_header($r,$phase,$context);
605: my $switch_server = &check_switchserver($dom,$confname);
606: $r->print(
607: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
608: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
609: &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 />'.
610: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
611: if ($switch_server) {
612: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
613: }
614: $r->print(&Apache::loncommon::end_page());
615: return OK;
616: }
617: }
618: }
619: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
620: }
621: return OK;
622: }
623:
624: sub process_changes {
625: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
626: my %domconfig;
627: if (ref($values) eq 'HASH') {
628: %domconfig = %{$values};
629: }
630: my $output;
631: if ($action eq 'login') {
632: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
633: } elsif ($action eq 'rolecolors') {
634: $output = &modify_rolecolors($r,$dom,$confname,$roles,
635: $lastactref,%domconfig);
636: } elsif ($action eq 'quotas') {
637: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
638: } elsif ($action eq 'autoenroll') {
639: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
640: } elsif ($action eq 'autoupdate') {
641: $output = &modify_autoupdate($dom,%domconfig);
642: } elsif ($action eq 'autocreate') {
643: $output = &modify_autocreate($dom,%domconfig);
644: } elsif ($action eq 'directorysrch') {
645: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
646: } elsif ($action eq 'usercreation') {
647: $output = &modify_usercreation($dom,%domconfig);
648: } elsif ($action eq 'selfcreation') {
649: $output = &modify_selfcreation($dom,%domconfig);
650: } elsif ($action eq 'usermodification') {
651: $output = &modify_usermodification($dom,%domconfig);
652: } elsif ($action eq 'contacts') {
653: $output = &modify_contacts($dom,$lastactref,%domconfig);
654: } elsif ($action eq 'defaults') {
655: $output = &modify_defaults($dom,$lastactref,%domconfig);
656: } elsif ($action eq 'scantron') {
657: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
658: } elsif ($action eq 'coursecategories') {
659: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
660: } elsif ($action eq 'serverstatuses') {
661: $output = &modify_serverstatuses($dom,%domconfig);
662: } elsif ($action eq 'requestcourses') {
663: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
664: } elsif ($action eq 'requestauthor') {
665: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
666: } elsif ($action eq 'helpsettings') {
667: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
668: } elsif ($action eq 'coursedefaults') {
669: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
670: } elsif ($action eq 'selfenrollment') {
671: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
672: } elsif ($action eq 'usersessions') {
673: $output = &modify_usersessions($dom,$lastactref,%domconfig);
674: } elsif ($action eq 'loadbalancing') {
675: $output = &modify_loadbalancing($dom,%domconfig);
676: } elsif ($action eq 'ltitools') {
677: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
678: }
679: return $output;
680: }
681:
682: sub print_config_box {
683: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
684: my $rowtotal = 0;
685: my $output;
686: if ($action eq 'coursecategories') {
687: $output = &coursecategories_javascript($settings);
688: } elsif ($action eq 'defaults') {
689: $output = &defaults_javascript($settings);
690: } elsif ($action eq 'helpsettings') {
691: my (%privs,%levelscurrent);
692: my %full=();
693: my %levels=(
694: course => {},
695: domain => {},
696: system => {},
697: );
698: my $context = 'domain';
699: my $crstype = 'Course';
700: my $formname = 'display';
701: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
702: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
703: $output =
704: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
705: \@templateroles);
706: }
707: $output .=
708: '<table class="LC_nested_outer">
709: <tr>
710: <th align="left" valign="middle"><span class="LC_nobreak">'.
711: &mt($item->{text}).' '.
712: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
713: '</tr>';
714: $rowtotal ++;
715: my $numheaders = 1;
716: if (ref($item->{'header'}) eq 'ARRAY') {
717: $numheaders = scalar(@{$item->{'header'}});
718: }
719: if ($numheaders > 1) {
720: my $colspan = '';
721: my $rightcolspan = '';
722: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
723: ($action eq 'directorysrch') ||
724: (($action eq 'login') && ($numheaders < 4))) {
725: $colspan = ' colspan="2"';
726: }
727: if ($action eq 'usersessions') {
728: $rightcolspan = ' colspan="3"';
729: }
730: $output .= '
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'}->[0]->{'col1'}).'</td>
736: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
737: </tr>';
738: $rowtotal ++;
739: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
740: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
741: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') ||
742: ($action eq 'helpsettings') || ($action eq 'contacts')) {
743: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
744: } elsif ($action eq 'coursecategories') {
745: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
746: } elsif ($action eq 'login') {
747: if ($numheaders == 4) {
748: $colspan = ' colspan="2"';
749: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
750: } else {
751: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
752: }
753: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
754: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
755: } elsif ($action eq 'rolecolors') {
756: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
757: }
758: $output .= '
759: </table>
760: </td>
761: </tr>
762: <tr>
763: <td>
764: <table class="LC_nested">
765: <tr class="LC_info_row">
766: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
767: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
768: </tr>';
769: $rowtotal ++;
770: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
771: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
772: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
773: ($action eq 'contacts') || ($action eq 'defaults')) {
774: if ($action eq 'coursecategories') {
775: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
776: $colspan = ' colspan="2"';
777: } else {
778: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
779: }
780: $output .= '
781: </table>
782: </td>
783: </tr>
784: <tr>
785: <td>
786: <table class="LC_nested">
787: <tr class="LC_info_row">
788: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
789: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
790: </tr>'."\n";
791: if ($action eq 'coursecategories') {
792: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
793: } else {
794: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
795: }
796: $rowtotal ++;
797: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
798: ($action eq 'defaults') || ($action eq 'directorysrch') ||
799: ($action eq 'helpsettings')) {
800: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
801: } elsif ($action eq 'login') {
802: if ($numheaders == 4) {
803: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
804: </table>
805: </td>
806: </tr>
807: <tr>
808: <td>
809: <table class="LC_nested">
810: <tr class="LC_info_row">
811: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
812: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
813: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
814: $rowtotal ++;
815: } else {
816: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
817: }
818: $output .= '
819: </table>
820: </td>
821: </tr>
822: <tr>
823: <td>
824: <table class="LC_nested">
825: <tr class="LC_info_row">';
826: if ($numheaders == 4) {
827: $output .= '
828: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
829: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
830: </tr>';
831: } else {
832: $output .= '
833: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
834: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
835: </tr>';
836: }
837: $rowtotal ++;
838: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
839: } elsif ($action eq 'requestcourses') {
840: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
841: $rowtotal ++;
842: $output .= &print_studentcode($settings,\$rowtotal).'
843: </table>
844: </td>
845: </tr>
846: <tr>
847: <td>
848: <table class="LC_nested">
849: <tr class="LC_info_row">
850: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
851: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
852: &textbookcourses_javascript($settings).
853: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
854: </table>
855: </td>
856: </tr>
857: <tr>
858: <td>
859: <table class="LC_nested">
860: <tr class="LC_info_row">
861: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
862: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
863: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
864: </table>
865: </td>
866: </tr>
867: <tr>
868: <td>
869: <table class="LC_nested">
870: <tr class="LC_info_row">
871: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
872: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
873: </tr>'.
874: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
875: } elsif ($action eq 'requestauthor') {
876: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
877: $rowtotal ++;
878: } elsif ($action eq 'rolecolors') {
879: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
880: </table>
881: </td>
882: </tr>
883: <tr>
884: <td>
885: <table class="LC_nested">
886: <tr class="LC_info_row">
887: <td class="LC_left_item"'.$colspan.' valign="top">'.
888: &mt($item->{'header'}->[2]->{'col1'}).'</td>
889: <td class="LC_right_item" valign="top">'.
890: &mt($item->{'header'}->[2]->{'col2'}).'</td>
891: </tr>'.
892: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
893: </table>
894: </td>
895: </tr>
896: <tr>
897: <td>
898: <table class="LC_nested">
899: <tr class="LC_info_row">
900: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
901: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
902: </tr>'.
903: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
904: $rowtotal += 2;
905: }
906: } else {
907: $output .= '
908: <tr>
909: <td>
910: <table class="LC_nested">
911: <tr class="LC_info_row">';
912: if ($action eq 'login') {
913: $output .= '
914: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
915: } elsif ($action eq 'serverstatuses') {
916: $output .= '
917: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
918: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
919:
920: } else {
921: $output .= '
922: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
923: }
924: if (defined($item->{'header'}->[0]->{'col3'})) {
925: $output .= '<td class="LC_left_item" valign="top">'.
926: &mt($item->{'header'}->[0]->{'col2'});
927: if ($action eq 'serverstatuses') {
928: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
929: }
930: } else {
931: $output .= '<td class="LC_right_item" valign="top">'.
932: &mt($item->{'header'}->[0]->{'col2'});
933: }
934: $output .= '</td>';
935: if ($item->{'header'}->[0]->{'col3'}) {
936: if (defined($item->{'header'}->[0]->{'col4'})) {
937: $output .= '<td class="LC_left_item" valign="top">'.
938: &mt($item->{'header'}->[0]->{'col3'});
939: } else {
940: $output .= '<td class="LC_right_item" valign="top">'.
941: &mt($item->{'header'}->[0]->{'col3'});
942: }
943: if ($action eq 'serverstatuses') {
944: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
945: }
946: $output .= '</td>';
947: }
948: if ($item->{'header'}->[0]->{'col4'}) {
949: $output .= '<td class="LC_right_item" valign="top">'.
950: &mt($item->{'header'}->[0]->{'col4'});
951: }
952: $output .= '</tr>';
953: $rowtotal ++;
954: if ($action eq 'quotas') {
955: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
956: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
957: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
958: ($action eq 'ltitools')) {
959: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
960: } elsif ($action eq 'scantron') {
961: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
962: }
963: }
964: $output .= '
965: </table>
966: </td>
967: </tr>
968: </table><br />';
969: return ($output,$rowtotal);
970: }
971:
972: sub print_login {
973: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
974: my ($css_class,$datatable);
975: my %choices = &login_choices();
976:
977: if ($caller eq 'service') {
978: my %servers = &Apache::lonnet::internet_dom_servers($dom);
979: my $choice = $choices{'disallowlogin'};
980: $css_class = ' class="LC_odd_row"';
981: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
982: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
983: '<th>'.$choices{'server'}.'</th>'.
984: '<th>'.$choices{'serverpath'}.'</th>'.
985: '<th>'.$choices{'custompath'}.'</th>'.
986: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
987: my %disallowed;
988: if (ref($settings) eq 'HASH') {
989: if (ref($settings->{'loginvia'}) eq 'HASH') {
990: %disallowed = %{$settings->{'loginvia'}};
991: }
992: }
993: foreach my $lonhost (sort(keys(%servers))) {
994: my $direct = 'selected="selected"';
995: if (ref($disallowed{$lonhost}) eq 'HASH') {
996: if ($disallowed{$lonhost}{'server'} ne '') {
997: $direct = '';
998: }
999: }
1000: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1001: '<td><select name="'.$lonhost.'_server">'.
1002: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1003: '</option>';
1004: foreach my $hostid (sort(keys(%servers))) {
1005: next if ($servers{$hostid} eq $servers{$lonhost});
1006: my $selected = '';
1007: if (ref($disallowed{$lonhost}) eq 'HASH') {
1008: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1009: $selected = 'selected="selected"';
1010: }
1011: }
1012: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1013: $servers{$hostid}.'</option>';
1014: }
1015: $datatable .= '</select></td>'.
1016: '<td><select name="'.$lonhost.'_serverpath">';
1017: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1018: my $pathname = $path;
1019: if ($path eq 'custom') {
1020: $pathname = &mt('Custom Path').' ->';
1021: }
1022: my $selected = '';
1023: if (ref($disallowed{$lonhost}) eq 'HASH') {
1024: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1025: $selected = 'selected="selected"';
1026: }
1027: } elsif ($path eq '') {
1028: $selected = 'selected="selected"';
1029: }
1030: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1031: }
1032: $datatable .= '</select></td>';
1033: my ($custom,$exempt);
1034: if (ref($disallowed{$lonhost}) eq 'HASH') {
1035: $custom = $disallowed{$lonhost}{'custompath'};
1036: $exempt = $disallowed{$lonhost}{'exempt'};
1037: }
1038: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1039: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1040: '</tr>';
1041: }
1042: $datatable .= '</table></td></tr>';
1043: return $datatable;
1044: } elsif ($caller eq 'page') {
1045: my %defaultchecked = (
1046: 'coursecatalog' => 'on',
1047: 'helpdesk' => 'on',
1048: 'adminmail' => 'off',
1049: 'newuser' => 'off',
1050: );
1051: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1052: my (%checkedon,%checkedoff);
1053: foreach my $item (@toggles) {
1054: if ($defaultchecked{$item} eq 'on') {
1055: $checkedon{$item} = ' checked="checked" ';
1056: $checkedoff{$item} = ' ';
1057: } elsif ($defaultchecked{$item} eq 'off') {
1058: $checkedoff{$item} = ' checked="checked" ';
1059: $checkedon{$item} = ' ';
1060: }
1061: }
1062: my @images = ('img','logo','domlogo','login');
1063: my @logintext = ('textcol','bgcol');
1064: my @bgs = ('pgbg','mainbg','sidebg');
1065: my @links = ('link','alink','vlink');
1066: my %designhash = &Apache::loncommon::get_domainconf($dom);
1067: my %defaultdesign = %Apache::loncommon::defaultdesign;
1068: my (%is_custom,%designs);
1069: my %defaults = (
1070: font => $defaultdesign{'login.font'},
1071: );
1072: foreach my $item (@images) {
1073: $defaults{$item} = $defaultdesign{'login.'.$item};
1074: $defaults{'showlogo'}{$item} = 1;
1075: }
1076: foreach my $item (@bgs) {
1077: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1078: }
1079: foreach my $item (@logintext) {
1080: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1081: }
1082: foreach my $item (@links) {
1083: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1084: }
1085: if (ref($settings) eq 'HASH') {
1086: foreach my $item (@toggles) {
1087: if ($settings->{$item} eq '1') {
1088: $checkedon{$item} = ' checked="checked" ';
1089: $checkedoff{$item} = ' ';
1090: } elsif ($settings->{$item} eq '0') {
1091: $checkedoff{$item} = ' checked="checked" ';
1092: $checkedon{$item} = ' ';
1093: }
1094: }
1095: foreach my $item (@images) {
1096: if (defined($settings->{$item})) {
1097: $designs{$item} = $settings->{$item};
1098: $is_custom{$item} = 1;
1099: }
1100: if (defined($settings->{'showlogo'}{$item})) {
1101: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1102: }
1103: }
1104: foreach my $item (@logintext) {
1105: if ($settings->{$item} ne '') {
1106: $designs{'logintext'}{$item} = $settings->{$item};
1107: $is_custom{$item} = 1;
1108: }
1109: }
1110: if ($settings->{'font'} ne '') {
1111: $designs{'font'} = $settings->{'font'};
1112: $is_custom{'font'} = 1;
1113: }
1114: foreach my $item (@bgs) {
1115: if ($settings->{$item} ne '') {
1116: $designs{'bgs'}{$item} = $settings->{$item};
1117: $is_custom{$item} = 1;
1118: }
1119: }
1120: foreach my $item (@links) {
1121: if ($settings->{$item} ne '') {
1122: $designs{'links'}{$item} = $settings->{$item};
1123: $is_custom{$item} = 1;
1124: }
1125: }
1126: } else {
1127: if ($designhash{$dom.'.login.font'} ne '') {
1128: $designs{'font'} = $designhash{$dom.'.login.font'};
1129: $is_custom{'font'} = 1;
1130: }
1131: foreach my $item (@images) {
1132: if ($designhash{$dom.'.login.'.$item} ne '') {
1133: $designs{$item} = $designhash{$dom.'.login.'.$item};
1134: $is_custom{$item} = 1;
1135: }
1136: }
1137: foreach my $item (@bgs) {
1138: if ($designhash{$dom.'.login.'.$item} ne '') {
1139: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1140: $is_custom{$item} = 1;
1141: }
1142: }
1143: foreach my $item (@links) {
1144: if ($designhash{$dom.'.login.'.$item} ne '') {
1145: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1146: $is_custom{$item} = 1;
1147: }
1148: }
1149: }
1150: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1151: logo => 'Institution Logo',
1152: domlogo => 'Domain Logo',
1153: login => 'Login box');
1154: my $itemcount = 1;
1155: foreach my $item (@toggles) {
1156: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1157: $datatable .=
1158: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1159: '</td><td>'.
1160: '<span class="LC_nobreak"><label><input type="radio" name="'.
1161: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1162: '</label> <label><input type="radio" name="'.$item.'"'.
1163: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1164: '</tr>';
1165: $itemcount ++;
1166: }
1167: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1168: $datatable .= '</tr></table></td></tr>';
1169: } elsif ($caller eq 'help') {
1170: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1171: my $switchserver = &check_switchserver($dom,$confname);
1172: my $itemcount = 1;
1173: $defaulturl = '/adm/loginproblems.html';
1174: $defaulttype = 'default';
1175: %lt = &Apache::lonlocal::texthash (
1176: del => 'Delete?',
1177: rep => 'Replace:',
1178: upl => 'Upload:',
1179: default => 'Default',
1180: custom => 'Custom',
1181: );
1182: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1183: my @currlangs;
1184: if (ref($settings) eq 'HASH') {
1185: if (ref($settings->{'helpurl'}) eq 'HASH') {
1186: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1187: next if ($settings->{'helpurl'}{$key} eq '');
1188: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1189: $type{$key} = 'custom';
1190: unless ($key eq 'nolang') {
1191: push(@currlangs,$key);
1192: }
1193: }
1194: } elsif ($settings->{'helpurl'} ne '') {
1195: $type{'nolang'} = 'custom';
1196: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1197: }
1198: }
1199: foreach my $lang ('nolang',sort(@currlangs)) {
1200: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1201: $datatable .= '<tr'.$css_class.'>';
1202: if ($url{$lang} eq '') {
1203: $url{$lang} = $defaulturl;
1204: }
1205: if ($type{$lang} eq '') {
1206: $type{$lang} = $defaulttype;
1207: }
1208: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1209: if ($lang eq 'nolang') {
1210: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1211: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1212: } else {
1213: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1214: $langchoices{$lang},
1215: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1216: }
1217: $datatable .= '</span></td>'."\n".
1218: '<td class="LC_left_item">';
1219: if ($type{$lang} eq 'custom') {
1220: $datatable .= '<span class="LC_nobreak"><label>'.
1221: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1222: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1223: } else {
1224: $datatable .= $lt{'upl'};
1225: }
1226: $datatable .='<br />';
1227: if ($switchserver) {
1228: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1229: } else {
1230: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1231: }
1232: $datatable .= '</td></tr>';
1233: $itemcount ++;
1234: }
1235: my @addlangs;
1236: foreach my $lang (sort(keys(%langchoices))) {
1237: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1238: push(@addlangs,$lang);
1239: }
1240: if (@addlangs > 0) {
1241: my %toadd;
1242: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1243: $toadd{''} = &mt('Select');
1244: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1245: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1246: &mt('Add log-in help page for a specific language:').' '.
1247: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1248: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1249: if ($switchserver) {
1250: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1251: } else {
1252: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1253: }
1254: $datatable .= '</td></tr>';
1255: $itemcount ++;
1256: }
1257: $datatable .= &captcha_choice('login',$settings,$itemcount);
1258: } elsif ($caller eq 'headtag') {
1259: my %domservers = &Apache::lonnet::get_servers($dom);
1260: my $choice = $choices{'headtag'};
1261: $css_class = ' class="LC_odd_row"';
1262: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1263: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1264: '<th>'.$choices{'current'}.'</th>'.
1265: '<th>'.$choices{'action'}.'</th>'.
1266: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1267: my (%currurls,%currexempt);
1268: if (ref($settings) eq 'HASH') {
1269: if (ref($settings->{'headtag'}) eq 'HASH') {
1270: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1271: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1272: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1273: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1274: }
1275: }
1276: }
1277: }
1278: my %lt = &Apache::lonlocal::texthash(
1279: del => 'Delete?',
1280: rep => 'Replace:',
1281: upl => 'Upload:',
1282: curr => 'View contents',
1283: none => 'None',
1284: );
1285: my $switchserver = &check_switchserver($dom,$confname);
1286: foreach my $lonhost (sort(keys(%domservers))) {
1287: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1288: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1289: if ($currurls{$lonhost}) {
1290: $datatable .= '<td class="LC_right_item"><a href="'.
1291: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1292: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1293: '">'.$lt{'curr'}.'</a></td>'.
1294: '<td><span class="LC_nobreak"><label>'.
1295: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1296: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1297: } else {
1298: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1299: }
1300: $datatable .='<br />';
1301: if ($switchserver) {
1302: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1303: } else {
1304: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1305: }
1306: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1307: }
1308: $datatable .= '</table></td></tr>';
1309: }
1310: return $datatable;
1311: }
1312:
1313: sub login_choices {
1314: my %choices =
1315: &Apache::lonlocal::texthash (
1316: coursecatalog => 'Display Course/Community Catalog link?',
1317: adminmail => "Display Administrator's E-mail Address?",
1318: helpdesk => 'Display "Contact Helpdesk" link',
1319: disallowlogin => "Login page requests redirected",
1320: hostid => "Server",
1321: server => "Redirect to:",
1322: serverpath => "Path",
1323: custompath => "Custom",
1324: exempt => "Exempt IP(s)",
1325: directlogin => "No redirect",
1326: newuser => "Link to create a user account",
1327: img => "Header",
1328: logo => "Main Logo",
1329: domlogo => "Domain Logo",
1330: login => "Log-in Header",
1331: textcol => "Text color",
1332: bgcol => "Box color",
1333: bgs => "Background colors",
1334: links => "Link colors",
1335: font => "Font color",
1336: pgbg => "Header",
1337: mainbg => "Page",
1338: sidebg => "Login box",
1339: link => "Link",
1340: alink => "Active link",
1341: vlink => "Visited link",
1342: headtag => "Custom markup",
1343: action => "Action",
1344: current => "Current",
1345: );
1346: return %choices;
1347: }
1348:
1349: sub print_rolecolors {
1350: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1351: my %choices = &color_font_choices();
1352: my @bgs = ('pgbg','tabbg','sidebg');
1353: my @links = ('link','alink','vlink');
1354: my @images = ('img');
1355: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1356: my %designhash = &Apache::loncommon::get_domainconf($dom);
1357: my %defaultdesign = %Apache::loncommon::defaultdesign;
1358: my (%is_custom,%designs);
1359: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1360: if (ref($settings) eq 'HASH') {
1361: if (ref($settings->{$role}) eq 'HASH') {
1362: if ($settings->{$role}->{'img'} ne '') {
1363: $designs{'img'} = $settings->{$role}->{'img'};
1364: $is_custom{'img'} = 1;
1365: }
1366: if ($settings->{$role}->{'font'} ne '') {
1367: $designs{'font'} = $settings->{$role}->{'font'};
1368: $is_custom{'font'} = 1;
1369: }
1370: if ($settings->{$role}->{'fontmenu'} ne '') {
1371: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1372: $is_custom{'fontmenu'} = 1;
1373: }
1374: foreach my $item (@bgs) {
1375: if ($settings->{$role}->{$item} ne '') {
1376: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1377: $is_custom{$item} = 1;
1378: }
1379: }
1380: foreach my $item (@links) {
1381: if ($settings->{$role}->{$item} ne '') {
1382: $designs{'links'}{$item} = $settings->{$role}->{$item};
1383: $is_custom{$item} = 1;
1384: }
1385: }
1386: }
1387: } else {
1388: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1389: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1390: $is_custom{'img'} = 1;
1391: }
1392: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1393: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1394: $is_custom{'fontmenu'} = 1;
1395: }
1396: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1397: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1398: $is_custom{'font'} = 1;
1399: }
1400: foreach my $item (@bgs) {
1401: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1402: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1403: $is_custom{$item} = 1;
1404:
1405: }
1406: }
1407: foreach my $item (@links) {
1408: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1409: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1410: $is_custom{$item} = 1;
1411: }
1412: }
1413: }
1414: my $itemcount = 1;
1415: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1416: $datatable .= '</tr></table></td></tr>';
1417: return $datatable;
1418: }
1419:
1420: sub role_defaults {
1421: my ($role,$bgs,$links,$images,$logintext) = @_;
1422: my %defaults;
1423: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1424: return %defaults;
1425: }
1426: my %defaultdesign = %Apache::loncommon::defaultdesign;
1427: if ($role eq 'login') {
1428: %defaults = (
1429: font => $defaultdesign{$role.'.font'},
1430: );
1431: if (ref($logintext) eq 'ARRAY') {
1432: foreach my $item (@{$logintext}) {
1433: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1434: }
1435: }
1436: foreach my $item (@{$images}) {
1437: $defaults{'showlogo'}{$item} = 1;
1438: }
1439: } else {
1440: %defaults = (
1441: img => $defaultdesign{$role.'.img'},
1442: font => $defaultdesign{$role.'.font'},
1443: fontmenu => $defaultdesign{$role.'.fontmenu'},
1444: );
1445: }
1446: foreach my $item (@{$bgs}) {
1447: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1448: }
1449: foreach my $item (@{$links}) {
1450: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1451: }
1452: foreach my $item (@{$images}) {
1453: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1454: }
1455: return %defaults;
1456: }
1457:
1458: sub display_color_options {
1459: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1460: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1461: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1462: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1463: my $datatable = '<tr'.$css_class.'>'.
1464: '<td>'.$choices->{'font'}.'</td>';
1465: if (!$is_custom->{'font'}) {
1466: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1467: } else {
1468: $datatable .= '<td> </td>';
1469: }
1470: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1471:
1472: $datatable .= '<td><span class="LC_nobreak">'.
1473: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1474: ' value="'.$current_color.'" /> '.
1475: ' </td></tr>';
1476: unless ($role eq 'login') {
1477: $datatable .= '<tr'.$css_class.'>'.
1478: '<td>'.$choices->{'fontmenu'}.'</td>';
1479: if (!$is_custom->{'fontmenu'}) {
1480: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1481: } else {
1482: $datatable .= '<td> </td>';
1483: }
1484: $current_color = $designs->{'fontmenu'} ?
1485: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1486: $datatable .= '<td><span class="LC_nobreak">'.
1487: '<input class="colorchooser" type="text" size="10" name="'
1488: .$role.'_fontmenu"'.
1489: ' value="'.$current_color.'" /> '.
1490: ' </td></tr>';
1491: }
1492: my $switchserver = &check_switchserver($dom,$confname);
1493: foreach my $img (@{$images}) {
1494: $itemcount ++;
1495: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1496: $datatable .= '<tr'.$css_class.'>'.
1497: '<td>'.$choices->{$img};
1498: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1499: if ($role eq 'login') {
1500: if ($img eq 'login') {
1501: $login_hdr_pick =
1502: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1503: $logincolors =
1504: &login_text_colors($img,$role,$logintext,$phase,$choices,
1505: $designs,$defaults);
1506: } elsif ($img ne 'domlogo') {
1507: $datatable.= &logo_display_options($img,$defaults,$designs);
1508: }
1509: }
1510: $datatable .= '</td>';
1511: if ($designs->{$img} ne '') {
1512: $imgfile = $designs->{$img};
1513: $img_import = ($imgfile =~ m{^/adm/});
1514: } else {
1515: $imgfile = $defaults->{$img};
1516: }
1517: if ($imgfile) {
1518: my ($showfile,$fullsize);
1519: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1520: my $urldir = $1;
1521: my $filename = $2;
1522: my @info = &Apache::lonnet::stat_file($designs->{$img});
1523: if (@info) {
1524: my $thumbfile = 'tn-'.$filename;
1525: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1526: if (@thumb) {
1527: $showfile = $urldir.'/'.$thumbfile;
1528: } else {
1529: $showfile = $imgfile;
1530: }
1531: } else {
1532: $showfile = '';
1533: }
1534: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1535: $showfile = $imgfile;
1536: my $imgdir = $1;
1537: my $filename = $2;
1538: if (-e "$londocroot/$imgdir/tn-".$filename) {
1539: $showfile = "/$imgdir/tn-".$filename;
1540: } else {
1541: my $input = $londocroot.$imgfile;
1542: my $output = "$londocroot/$imgdir/tn-".$filename;
1543: if (!-e $output) {
1544: my ($width,$height) = &thumb_dimensions();
1545: my ($fullwidth,$fullheight) = &check_dimensions($input);
1546: if ($fullwidth ne '' && $fullheight ne '') {
1547: if ($fullwidth > $width && $fullheight > $height) {
1548: my $size = $width.'x'.$height;
1549: system("convert -sample $size $input $output");
1550: $showfile = "/$imgdir/tn-".$filename;
1551: }
1552: }
1553: }
1554: }
1555: }
1556: if ($showfile) {
1557: if ($showfile =~ m{^/(adm|res)/}) {
1558: if ($showfile =~ m{^/res/}) {
1559: my $local_showfile =
1560: &Apache::lonnet::filelocation('',$showfile);
1561: &Apache::lonnet::repcopy($local_showfile);
1562: }
1563: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1564: }
1565: if ($imgfile) {
1566: if ($imgfile =~ m{^/(adm|res)/}) {
1567: if ($imgfile =~ m{^/res/}) {
1568: my $local_imgfile =
1569: &Apache::lonnet::filelocation('',$imgfile);
1570: &Apache::lonnet::repcopy($local_imgfile);
1571: }
1572: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1573: } else {
1574: $fullsize = $imgfile;
1575: }
1576: }
1577: $datatable .= '<td>';
1578: if ($img eq 'login') {
1579: $datatable .= $login_hdr_pick;
1580: }
1581: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1582: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1583: } else {
1584: $datatable .= '<td> </td><td class="LC_left_item">'.
1585: &mt('Upload:').'<br />';
1586: }
1587: } else {
1588: $datatable .= '<td> </td><td class="LC_left_item">'.
1589: &mt('Upload:').'<br />';
1590: }
1591: if ($switchserver) {
1592: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1593: } else {
1594: if ($img ne 'login') { # suppress file selection for Log-in header
1595: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1596: }
1597: }
1598: $datatable .= '</td></tr>';
1599: }
1600: $itemcount ++;
1601: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1602: $datatable .= '<tr'.$css_class.'>'.
1603: '<td>'.$choices->{'bgs'}.'</td>';
1604: my $bgs_def;
1605: foreach my $item (@{$bgs}) {
1606: if (!$is_custom->{$item}) {
1607: $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>';
1608: }
1609: }
1610: if ($bgs_def) {
1611: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1612: } else {
1613: $datatable .= '<td> </td>';
1614: }
1615: $datatable .= '<td class="LC_right_item">'.
1616: '<table border="0"><tr>';
1617:
1618: foreach my $item (@{$bgs}) {
1619: $datatable .= '<td align="center">'.$choices->{$item};
1620: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1621: if ($designs->{'bgs'}{$item}) {
1622: $datatable .= ' ';
1623: }
1624: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1625: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1626: }
1627: $datatable .= '</tr></table></td></tr>';
1628: $itemcount ++;
1629: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1630: $datatable .= '<tr'.$css_class.'>'.
1631: '<td>'.$choices->{'links'}.'</td>';
1632: my $links_def;
1633: foreach my $item (@{$links}) {
1634: if (!$is_custom->{$item}) {
1635: $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1636: }
1637: }
1638: if ($links_def) {
1639: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1640: } else {
1641: $datatable .= '<td> </td>';
1642: }
1643: $datatable .= '<td class="LC_right_item">'.
1644: '<table border="0"><tr>';
1645: foreach my $item (@{$links}) {
1646: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1647: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1648: if ($designs->{'links'}{$item}) {
1649: $datatable.=' ';
1650: }
1651: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1652: '" /></td>';
1653: }
1654: $$rowtotal += $itemcount;
1655: return $datatable;
1656: }
1657:
1658: sub logo_display_options {
1659: my ($img,$defaults,$designs) = @_;
1660: my $checkedon;
1661: if (ref($defaults) eq 'HASH') {
1662: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1663: if ($defaults->{'showlogo'}{$img}) {
1664: $checkedon = 'checked="checked" ';
1665: }
1666: }
1667: }
1668: if (ref($designs) eq 'HASH') {
1669: if (ref($designs->{'showlogo'}) eq 'HASH') {
1670: if (defined($designs->{'showlogo'}{$img})) {
1671: if ($designs->{'showlogo'}{$img} == 0) {
1672: $checkedon = '';
1673: } elsif ($designs->{'showlogo'}{$img} == 1) {
1674: $checkedon = 'checked="checked" ';
1675: }
1676: }
1677: }
1678: }
1679: return '<br /><label> <input type="checkbox" name="'.
1680: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1681: &mt('show').'</label>'."\n";
1682: }
1683:
1684: sub login_header_options {
1685: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1686: my $output = '';
1687: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1688: $output .= &mt('Text default(s):').'<br />';
1689: if (!$is_custom->{'textcol'}) {
1690: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1691: ' ';
1692: }
1693: if (!$is_custom->{'bgcol'}) {
1694: $output .= $choices->{'bgcol'}.': '.
1695: '<span id="css_'.$role.'_font" style="background-color: '.
1696: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1697: }
1698: $output .= '<br />';
1699: }
1700: $output .='<br />';
1701: return $output;
1702: }
1703:
1704: sub login_text_colors {
1705: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1706: my $color_menu = '<table border="0"><tr>';
1707: foreach my $item (@{$logintext}) {
1708: $color_menu .= '<td align="center">'.$choices->{$item};
1709: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1710: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1711: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1712: }
1713: $color_menu .= '</tr></table><br />';
1714: return $color_menu;
1715: }
1716:
1717: sub image_changes {
1718: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1719: my $output;
1720: if ($img eq 'login') {
1721: # suppress image for Log-in header
1722: } elsif (!$is_custom) {
1723: if ($img ne 'domlogo') {
1724: $output .= &mt('Default image:').'<br />';
1725: } else {
1726: $output .= &mt('Default in use:').'<br />';
1727: }
1728: }
1729: if ($img eq 'login') { # suppress image for Log-in header
1730: $output .= '<td>'.$logincolors;
1731: } else {
1732: if ($img_import) {
1733: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1734: }
1735: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1736: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1737: if ($is_custom) {
1738: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1739: '<input type="checkbox" name="'.
1740: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1741: '</label> '.&mt('Replace:').'</span><br />';
1742: } else {
1743: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1744: }
1745: }
1746: return $output;
1747: }
1748:
1749: sub print_quotas {
1750: my ($dom,$settings,$rowtotal,$action) = @_;
1751: my $context;
1752: if ($action eq 'quotas') {
1753: $context = 'tools';
1754: } else {
1755: $context = $action;
1756: }
1757: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1758: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1759: my $typecount = 0;
1760: my ($css_class,%titles);
1761: if ($context eq 'requestcourses') {
1762: @usertools = ('official','unofficial','community','textbook');
1763: @options =('norequest','approval','validate','autolimit');
1764: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1765: %titles = &courserequest_titles();
1766: } elsif ($context eq 'requestauthor') {
1767: @usertools = ('author');
1768: @options = ('norequest','approval','automatic');
1769: %titles = &authorrequest_titles();
1770: } else {
1771: @usertools = ('aboutme','blog','webdav','portfolio');
1772: %titles = &tool_titles();
1773: }
1774: if (ref($types) eq 'ARRAY') {
1775: foreach my $type (@{$types}) {
1776: my ($currdefquota,$currauthorquota);
1777: unless (($context eq 'requestcourses') ||
1778: ($context eq 'requestauthor')) {
1779: if (ref($settings) eq 'HASH') {
1780: if (ref($settings->{defaultquota}) eq 'HASH') {
1781: $currdefquota = $settings->{defaultquota}->{$type};
1782: } else {
1783: $currdefquota = $settings->{$type};
1784: }
1785: if (ref($settings->{authorquota}) eq 'HASH') {
1786: $currauthorquota = $settings->{authorquota}->{$type};
1787: }
1788: }
1789: }
1790: if (defined($usertypes->{$type})) {
1791: $typecount ++;
1792: $css_class = $typecount%2?' class="LC_odd_row"':'';
1793: $datatable .= '<tr'.$css_class.'>'.
1794: '<td>'.$usertypes->{$type}.'</td>'.
1795: '<td class="LC_left_item">';
1796: if ($context eq 'requestcourses') {
1797: $datatable .= '<table><tr>';
1798: }
1799: my %cell;
1800: foreach my $item (@usertools) {
1801: if ($context eq 'requestcourses') {
1802: my ($curroption,$currlimit);
1803: if (ref($settings) eq 'HASH') {
1804: if (ref($settings->{$item}) eq 'HASH') {
1805: $curroption = $settings->{$item}->{$type};
1806: if ($curroption =~ /^autolimit=(\d*)$/) {
1807: $currlimit = $1;
1808: }
1809: }
1810: }
1811: if (!$curroption) {
1812: $curroption = 'norequest';
1813: }
1814: $datatable .= '<th>'.$titles{$item}.'</th>';
1815: foreach my $option (@options) {
1816: my $val = $option;
1817: if ($option eq 'norequest') {
1818: $val = 0;
1819: }
1820: if ($option eq 'validate') {
1821: my $canvalidate = 0;
1822: if (ref($validations{$item}) eq 'HASH') {
1823: if ($validations{$item}{$type}) {
1824: $canvalidate = 1;
1825: }
1826: }
1827: next if (!$canvalidate);
1828: }
1829: my $checked = '';
1830: if ($option eq $curroption) {
1831: $checked = ' checked="checked"';
1832: } elsif ($option eq 'autolimit') {
1833: if ($curroption =~ /^autolimit/) {
1834: $checked = ' checked="checked"';
1835: }
1836: }
1837: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1838: '<input type="radio" name="crsreq_'.$item.
1839: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1840: $titles{$option}.'</label>';
1841: if ($option eq 'autolimit') {
1842: $cell{$item} .= ' <input type="text" name="crsreq_'.
1843: $item.'_limit_'.$type.'" size="1" '.
1844: 'value="'.$currlimit.'" />';
1845: }
1846: $cell{$item} .= '</span> ';
1847: if ($option eq 'autolimit') {
1848: $cell{$item} .= $titles{'unlimited'};
1849: }
1850: }
1851: } elsif ($context eq 'requestauthor') {
1852: my $curroption;
1853: if (ref($settings) eq 'HASH') {
1854: $curroption = $settings->{$type};
1855: }
1856: if (!$curroption) {
1857: $curroption = 'norequest';
1858: }
1859: foreach my $option (@options) {
1860: my $val = $option;
1861: if ($option eq 'norequest') {
1862: $val = 0;
1863: }
1864: my $checked = '';
1865: if ($option eq $curroption) {
1866: $checked = ' checked="checked"';
1867: }
1868: $datatable .= '<span class="LC_nobreak"><label>'.
1869: '<input type="radio" name="authorreq_'.$type.
1870: '" value="'.$val.'"'.$checked.' />'.
1871: $titles{$option}.'</label></span> ';
1872: }
1873: } else {
1874: my $checked = 'checked="checked" ';
1875: if (ref($settings) eq 'HASH') {
1876: if (ref($settings->{$item}) eq 'HASH') {
1877: if ($settings->{$item}->{$type} == 0) {
1878: $checked = '';
1879: } elsif ($settings->{$item}->{$type} == 1) {
1880: $checked = 'checked="checked" ';
1881: }
1882: }
1883: }
1884: $datatable .= '<span class="LC_nobreak"><label>'.
1885: '<input type="checkbox" name="'.$context.'_'.$item.
1886: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1887: '</label></span> ';
1888: }
1889: }
1890: if ($context eq 'requestcourses') {
1891: $datatable .= '</tr><tr>';
1892: foreach my $item (@usertools) {
1893: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1894: }
1895: $datatable .= '</tr></table>';
1896: }
1897: $datatable .= '</td>';
1898: unless (($context eq 'requestcourses') ||
1899: ($context eq 'requestauthor')) {
1900: $datatable .=
1901: '<td class="LC_right_item">'.
1902: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1903: '<input type="text" name="quota_'.$type.
1904: '" value="'.$currdefquota.
1905: '" size="5" /></span>'.(' ' x 2).
1906: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1907: '<input type="text" name="authorquota_'.$type.
1908: '" value="'.$currauthorquota.
1909: '" size="5" /></span></td>';
1910: }
1911: $datatable .= '</tr>';
1912: }
1913: }
1914: }
1915: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1916: $defaultquota = '20';
1917: $authorquota = '500';
1918: if (ref($settings) eq 'HASH') {
1919: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1920: $defaultquota = $settings->{'defaultquota'}->{'default'};
1921: } elsif (defined($settings->{'default'})) {
1922: $defaultquota = $settings->{'default'};
1923: }
1924: if (ref($settings->{'authorquota'}) eq 'HASH') {
1925: $authorquota = $settings->{'authorquota'}->{'default'};
1926: }
1927: }
1928: }
1929: $typecount ++;
1930: $css_class = $typecount%2?' class="LC_odd_row"':'';
1931: $datatable .= '<tr'.$css_class.'>'.
1932: '<td>'.$othertitle.'</td>'.
1933: '<td class="LC_left_item">';
1934: if ($context eq 'requestcourses') {
1935: $datatable .= '<table><tr>';
1936: }
1937: my %defcell;
1938: foreach my $item (@usertools) {
1939: if ($context eq 'requestcourses') {
1940: my ($curroption,$currlimit);
1941: if (ref($settings) eq 'HASH') {
1942: if (ref($settings->{$item}) eq 'HASH') {
1943: $curroption = $settings->{$item}->{'default'};
1944: if ($curroption =~ /^autolimit=(\d*)$/) {
1945: $currlimit = $1;
1946: }
1947: }
1948: }
1949: if (!$curroption) {
1950: $curroption = 'norequest';
1951: }
1952: $datatable .= '<th>'.$titles{$item}.'</th>';
1953: foreach my $option (@options) {
1954: my $val = $option;
1955: if ($option eq 'norequest') {
1956: $val = 0;
1957: }
1958: if ($option eq 'validate') {
1959: my $canvalidate = 0;
1960: if (ref($validations{$item}) eq 'HASH') {
1961: if ($validations{$item}{'default'}) {
1962: $canvalidate = 1;
1963: }
1964: }
1965: next if (!$canvalidate);
1966: }
1967: my $checked = '';
1968: if ($option eq $curroption) {
1969: $checked = ' checked="checked"';
1970: } elsif ($option eq 'autolimit') {
1971: if ($curroption =~ /^autolimit/) {
1972: $checked = ' checked="checked"';
1973: }
1974: }
1975: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1976: '<input type="radio" name="crsreq_'.$item.
1977: '_default" value="'.$val.'"'.$checked.' />'.
1978: $titles{$option}.'</label>';
1979: if ($option eq 'autolimit') {
1980: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1981: $item.'_limit_default" size="1" '.
1982: 'value="'.$currlimit.'" />';
1983: }
1984: $defcell{$item} .= '</span> ';
1985: if ($option eq 'autolimit') {
1986: $defcell{$item} .= $titles{'unlimited'};
1987: }
1988: }
1989: } elsif ($context eq 'requestauthor') {
1990: my $curroption;
1991: if (ref($settings) eq 'HASH') {
1992: $curroption = $settings->{'default'};
1993: }
1994: if (!$curroption) {
1995: $curroption = 'norequest';
1996: }
1997: foreach my $option (@options) {
1998: my $val = $option;
1999: if ($option eq 'norequest') {
2000: $val = 0;
2001: }
2002: my $checked = '';
2003: if ($option eq $curroption) {
2004: $checked = ' checked="checked"';
2005: }
2006: $datatable .= '<span class="LC_nobreak"><label>'.
2007: '<input type="radio" name="authorreq_default"'.
2008: ' value="'.$val.'"'.$checked.' />'.
2009: $titles{$option}.'</label></span> ';
2010: }
2011: } else {
2012: my $checked = 'checked="checked" ';
2013: if (ref($settings) eq 'HASH') {
2014: if (ref($settings->{$item}) eq 'HASH') {
2015: if ($settings->{$item}->{'default'} == 0) {
2016: $checked = '';
2017: } elsif ($settings->{$item}->{'default'} == 1) {
2018: $checked = 'checked="checked" ';
2019: }
2020: }
2021: }
2022: $datatable .= '<span class="LC_nobreak"><label>'.
2023: '<input type="checkbox" name="'.$context.'_'.$item.
2024: '" value="default" '.$checked.'/>'.$titles{$item}.
2025: '</label></span> ';
2026: }
2027: }
2028: if ($context eq 'requestcourses') {
2029: $datatable .= '</tr><tr>';
2030: foreach my $item (@usertools) {
2031: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
2032: }
2033: $datatable .= '</tr></table>';
2034: }
2035: $datatable .= '</td>';
2036: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
2037: $datatable .= '<td class="LC_right_item">'.
2038: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
2039: '<input type="text" name="defaultquota" value="'.
2040: $defaultquota.'" size="5" /></span>'.(' ' x2).
2041: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2042: '<input type="text" name="authorquota" value="'.
2043: $authorquota.'" size="5" /></span></td>';
2044: }
2045: $datatable .= '</tr>';
2046: $typecount ++;
2047: $css_class = $typecount%2?' class="LC_odd_row"':'';
2048: $datatable .= '<tr'.$css_class.'>'.
2049: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
2050: if ($context eq 'requestcourses') {
2051: $datatable .= &mt('(overrides affiliation, if set)').
2052: '</td>'.
2053: '<td class="LC_left_item">'.
2054: '<table><tr>';
2055: } else {
2056: $datatable .= &mt('(overrides affiliation, if checked)').
2057: '</td>'.
2058: '<td class="LC_left_item" colspan="2">'.
2059: '<br />';
2060: }
2061: my %advcell;
2062: foreach my $item (@usertools) {
2063: if ($context eq 'requestcourses') {
2064: my ($curroption,$currlimit);
2065: if (ref($settings) eq 'HASH') {
2066: if (ref($settings->{$item}) eq 'HASH') {
2067: $curroption = $settings->{$item}->{'_LC_adv'};
2068: if ($curroption =~ /^autolimit=(\d*)$/) {
2069: $currlimit = $1;
2070: }
2071: }
2072: }
2073: $datatable .= '<th>'.$titles{$item}.'</th>';
2074: my $checked = '';
2075: if ($curroption eq '') {
2076: $checked = ' checked="checked"';
2077: }
2078: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2079: '<input type="radio" name="crsreq_'.$item.
2080: '__LC_adv" value=""'.$checked.' />'.
2081: &mt('No override set').'</label></span> ';
2082: foreach my $option (@options) {
2083: my $val = $option;
2084: if ($option eq 'norequest') {
2085: $val = 0;
2086: }
2087: if ($option eq 'validate') {
2088: my $canvalidate = 0;
2089: if (ref($validations{$item}) eq 'HASH') {
2090: if ($validations{$item}{'_LC_adv'}) {
2091: $canvalidate = 1;
2092: }
2093: }
2094: next if (!$canvalidate);
2095: }
2096: my $checked = '';
2097: if ($val eq $curroption) {
2098: $checked = ' checked="checked"';
2099: } elsif ($option eq 'autolimit') {
2100: if ($curroption =~ /^autolimit/) {
2101: $checked = ' checked="checked"';
2102: }
2103: }
2104: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2105: '<input type="radio" name="crsreq_'.$item.
2106: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2107: $titles{$option}.'</label>';
2108: if ($option eq 'autolimit') {
2109: $advcell{$item} .= ' <input type="text" name="crsreq_'.
2110: $item.'_limit__LC_adv" size="1" '.
2111: 'value="'.$currlimit.'" />';
2112: }
2113: $advcell{$item} .= '</span> ';
2114: if ($option eq 'autolimit') {
2115: $advcell{$item} .= $titles{'unlimited'};
2116: }
2117: }
2118: } elsif ($context eq 'requestauthor') {
2119: my $curroption;
2120: if (ref($settings) eq 'HASH') {
2121: $curroption = $settings->{'_LC_adv'};
2122: }
2123: my $checked = '';
2124: if ($curroption eq '') {
2125: $checked = ' checked="checked"';
2126: }
2127: $datatable .= '<span class="LC_nobreak"><label>'.
2128: '<input type="radio" name="authorreq__LC_adv"'.
2129: ' value=""'.$checked.' />'.
2130: &mt('No override set').'</label></span> ';
2131: foreach my $option (@options) {
2132: my $val = $option;
2133: if ($option eq 'norequest') {
2134: $val = 0;
2135: }
2136: my $checked = '';
2137: if ($val eq $curroption) {
2138: $checked = ' checked="checked"';
2139: }
2140: $datatable .= '<span class="LC_nobreak"><label>'.
2141: '<input type="radio" name="authorreq__LC_adv"'.
2142: ' value="'.$val.'"'.$checked.' />'.
2143: $titles{$option}.'</label></span> ';
2144: }
2145: } else {
2146: my $checked = 'checked="checked" ';
2147: if (ref($settings) eq 'HASH') {
2148: if (ref($settings->{$item}) eq 'HASH') {
2149: if ($settings->{$item}->{'_LC_adv'} == 0) {
2150: $checked = '';
2151: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2152: $checked = 'checked="checked" ';
2153: }
2154: }
2155: }
2156: $datatable .= '<span class="LC_nobreak"><label>'.
2157: '<input type="checkbox" name="'.$context.'_'.$item.
2158: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2159: '</label></span> ';
2160: }
2161: }
2162: if ($context eq 'requestcourses') {
2163: $datatable .= '</tr><tr>';
2164: foreach my $item (@usertools) {
2165: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
2166: }
2167: $datatable .= '</tr></table>';
2168: }
2169: $datatable .= '</td></tr>';
2170: $$rowtotal += $typecount;
2171: return $datatable;
2172: }
2173:
2174: sub print_requestmail {
2175: my ($dom,$action,$settings,$rowtotal) = @_;
2176: my ($now,$datatable,%currapp);
2177: $now = time;
2178: if (ref($settings) eq 'HASH') {
2179: if (ref($settings->{'notify'}) eq 'HASH') {
2180: if ($settings->{'notify'}{'approval'} ne '') {
2181: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
2182: }
2183: }
2184: }
2185: my $numinrow = 2;
2186: my $css_class;
2187: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
2188: my $text;
2189: if ($action eq 'requestcourses') {
2190: $text = &mt('Receive notification of course requests requiring approval');
2191: } elsif ($action eq 'requestauthor') {
2192: $text = &mt('Receive notification of Authoring Space requests requiring approval');
2193: } else {
2194: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
2195: }
2196: $datatable = '<tr'.$css_class.'>'.
2197: ' <td>'.$text.'</td>'.
2198: ' <td class="LC_left_item">';
2199: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
2200: $action.'notifyapproval',%currapp);
2201: if ($numdc > 0) {
2202: $datatable .= $table;
2203: } else {
2204: $datatable .= &mt('There are no active Domain Coordinators');
2205: }
2206: $datatable .='</td></tr>';
2207: return $datatable;
2208: }
2209:
2210: sub print_studentcode {
2211: my ($settings,$rowtotal) = @_;
2212: my $rownum = 0;
2213: my ($output,%current);
2214: my @crstypes = ('official','unofficial','community','textbook');
2215: if (ref($settings) eq 'HASH') {
2216: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2217: foreach my $type (@crstypes) {
2218: $current{$type} = $settings->{'uniquecode'}{$type};
2219: }
2220: }
2221: }
2222: $output .= '<tr>'.
2223: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2224: '<td class="LC_left_item">';
2225: foreach my $type (@crstypes) {
2226: my $check = ' ';
2227: if ($current{$type}) {
2228: $check = ' checked="checked" ';
2229: }
2230: $output .= '<span class="LC_nobreak"><label>'.
2231: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2232: &mt($type).'</label></span>'.(' 'x2).' ';
2233: }
2234: $output .= '</td></tr>';
2235: $$rowtotal ++;
2236: return $output;
2237: }
2238:
2239: sub print_textbookcourses {
2240: my ($dom,$type,$settings,$rowtotal) = @_;
2241: my $rownum = 0;
2242: my $css_class;
2243: my $itemcount = 1;
2244: my $maxnum = 0;
2245: my $bookshash;
2246: if (ref($settings) eq 'HASH') {
2247: $bookshash = $settings->{$type};
2248: }
2249: my %ordered;
2250: if (ref($bookshash) eq 'HASH') {
2251: foreach my $item (keys(%{$bookshash})) {
2252: if (ref($bookshash->{$item}) eq 'HASH') {
2253: my $num = $bookshash->{$item}{'order'};
2254: $ordered{$num} = $item;
2255: }
2256: }
2257: }
2258: my $confname = $dom.'-domainconfig';
2259: my $switchserver = &check_switchserver($dom,$confname);
2260: my $maxnum = scalar(keys(%ordered));
2261: my $datatable;
2262: if (keys(%ordered)) {
2263: my @items = sort { $a <=> $b } keys(%ordered);
2264: for (my $i=0; $i<@items; $i++) {
2265: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2266: my $key = $ordered{$items[$i]};
2267: my %coursehash=&Apache::lonnet::coursedescription($key);
2268: my $coursetitle = $coursehash{'description'};
2269: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
2270: if (ref($bookshash->{$key}) eq 'HASH') {
2271: $subject = $bookshash->{$key}->{'subject'};
2272: $title = $bookshash->{$key}->{'title'};
2273: if ($type eq 'textbooks') {
2274: $publisher = $bookshash->{$key}->{'publisher'};
2275: $author = $bookshash->{$key}->{'author'};
2276: $image = $bookshash->{$key}->{'image'};
2277: if ($image ne '') {
2278: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2279: my $imagethumb = "$path/tn-".$imagefile;
2280: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2281: }
2282: }
2283: }
2284: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
2285: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
2286: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
2287: for (my $k=0; $k<=$maxnum; $k++) {
2288: my $vpos = $k+1;
2289: my $selstr;
2290: if ($k == $i) {
2291: $selstr = ' selected="selected" ';
2292: }
2293: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2294: }
2295: $datatable .= '</select>'.(' 'x2).
2296: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
2297: &mt('Delete?').'</label></span></td>'.
2298: '<td colspan="2">'.
2299: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
2300: (' 'x2).
2301: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2302: if ($type eq 'textbooks') {
2303: $datatable .= (' 'x2).
2304: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2305: (' 'x2).
2306: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2307: (' 'x2).
2308: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2309: if ($image) {
2310: $datatable .= '<span class="LC_nobreak">'.
2311: $imgsrc.
2312: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2313: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2314: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2315: }
2316: if ($switchserver) {
2317: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2318: } else {
2319: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2320: }
2321: }
2322: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
2323: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2324: $coursetitle.'</span></td></tr>'."\n";
2325: $itemcount ++;
2326: }
2327: }
2328: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2329: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
2330: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
2331: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2332: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
2333: for (my $k=0; $k<$maxnum+1; $k++) {
2334: my $vpos = $k+1;
2335: my $selstr;
2336: if ($k == $maxnum) {
2337: $selstr = ' selected="selected" ';
2338: }
2339: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2340: }
2341: $datatable .= '</select> '."\n".
2342: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
2343: '<td colspan="2">'.
2344: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
2345: (' 'x2).
2346: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2347: (' 'x2);
2348: if ($type eq 'textbooks') {
2349: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2350: (' 'x2).
2351: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
2352: (' 'x2).
2353: '<span class="LC_nobreak">'.&mt('Image:').' ';
2354: if ($switchserver) {
2355: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2356: } else {
2357: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2358: }
2359: }
2360: $datatable .= '</span>'."\n".
2361: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2362: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2363: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
2364: &Apache::loncommon::selectcourse_link
2365: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
2366: '</span></td>'."\n".
2367: '</tr>'."\n";
2368: $itemcount ++;
2369: return $datatable;
2370: }
2371:
2372: sub textbookcourses_javascript {
2373: my ($settings) = @_;
2374: return unless(ref($settings) eq 'HASH');
2375: my (%ordered,%total,%jstext);
2376: foreach my $type ('textbooks','templates') {
2377: $total{$type} = 0;
2378: if (ref($settings->{$type}) eq 'HASH') {
2379: foreach my $item (keys(%{$settings->{$type}})) {
2380: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2381: my $num = $settings->{$type}->{$item}{'order'};
2382: $ordered{$type}{$num} = $item;
2383: }
2384: }
2385: $total{$type} = scalar(keys(%{$settings->{$type}}));
2386: }
2387: my @jsarray = ();
2388: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2389: push(@jsarray,$ordered{$type}{$item});
2390: }
2391: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
2392: }
2393: return <<"ENDSCRIPT";
2394: <script type="text/javascript">
2395: // <![CDATA[
2396: function reorderBooks(form,item,caller) {
2397: var changedVal;
2398: $jstext{'textbooks'};
2399: $jstext{'templates'};
2400: var newpos;
2401: var maxh;
2402: if (caller == 'textbooks') {
2403: newpos = 'textbooks_addbook_pos';
2404: maxh = 1 + $total{'textbooks'};
2405: } else {
2406: newpos = 'templates_addbook_pos';
2407: maxh = 1 + $total{'templates'};
2408: }
2409: var current = new Array;
2410: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2411: if (item == newpos) {
2412: changedVal = newitemVal;
2413: } else {
2414: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2415: current[newitemVal] = newpos;
2416: }
2417: if (caller == 'textbooks') {
2418: for (var i=0; i<textbooks.length; i++) {
2419: var elementName = 'textbooks_'+textbooks[i];
2420: if (elementName != item) {
2421: if (form.elements[elementName]) {
2422: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2423: current[currVal] = elementName;
2424: }
2425: }
2426: }
2427: }
2428: if (caller == 'templates') {
2429: for (var i=0; i<templates.length; i++) {
2430: var elementName = 'templates_'+templates[i];
2431: if (elementName != item) {
2432: if (form.elements[elementName]) {
2433: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2434: current[currVal] = elementName;
2435: }
2436: }
2437: }
2438: }
2439: var oldVal;
2440: for (var j=0; j<maxh; j++) {
2441: if (current[j] == undefined) {
2442: oldVal = j;
2443: }
2444: }
2445: if (oldVal < changedVal) {
2446: for (var k=oldVal+1; k<=changedVal ; k++) {
2447: var elementName = current[k];
2448: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2449: }
2450: } else {
2451: for (var k=changedVal; k<oldVal; k++) {
2452: var elementName = current[k];
2453: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2454: }
2455: }
2456: return;
2457: }
2458:
2459: // ]]>
2460: </script>
2461:
2462: ENDSCRIPT
2463: }
2464:
2465: sub ltitools_javascript {
2466: my ($settings) = @_;
2467: return unless(ref($settings) eq 'HASH');
2468: my (%ordered,$total,%jstext);
2469: $total = 0;
2470: foreach my $item (keys(%{$settings})) {
2471: if (ref($settings->{$item}) eq 'HASH') {
2472: my $num = $settings->{$item}{'order'};
2473: $ordered{$num} = $item;
2474: }
2475: }
2476: $total = scalar(keys(%{$settings}));
2477: my @jsarray = ();
2478: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2479: push(@jsarray,$ordered{$item});
2480: }
2481: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2482: return <<"ENDSCRIPT";
2483: <script type="text/javascript">
2484: // <![CDATA[
2485: function reorderLTI(form,item) {
2486: var changedVal;
2487: $jstext
2488: var newpos = 'ltitools_add_pos';
2489: var maxh = 1 + $total;
2490: var current = new Array;
2491: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2492: if (item == newpos) {
2493: changedVal = newitemVal;
2494: } else {
2495: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2496: current[newitemVal] = newpos;
2497: }
2498: for (var i=0; i<ltitools.length; i++) {
2499: var elementName = 'ltitools_'+ltitools[i];
2500: if (elementName != item) {
2501: if (form.elements[elementName]) {
2502: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2503: current[currVal] = elementName;
2504: }
2505: }
2506: }
2507: var oldVal;
2508: for (var j=0; j<maxh; j++) {
2509: if (current[j] == undefined) {
2510: oldVal = j;
2511: }
2512: }
2513: if (oldVal < changedVal) {
2514: for (var k=oldVal+1; k<=changedVal ; k++) {
2515: var elementName = current[k];
2516: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2517: }
2518: } else {
2519: for (var k=changedVal; k<oldVal; k++) {
2520: var elementName = current[k];
2521: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2522: }
2523: }
2524: return;
2525: }
2526:
2527: // ]]>
2528: </script>
2529:
2530: ENDSCRIPT
2531: }
2532:
2533: sub print_autoenroll {
2534: my ($dom,$settings,$rowtotal) = @_;
2535: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
2536: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
2537: if (ref($settings) eq 'HASH') {
2538: if (exists($settings->{'run'})) {
2539: if ($settings->{'run'} eq '0') {
2540: $runoff = ' checked="checked" ';
2541: $runon = ' ';
2542: } else {
2543: $runon = ' checked="checked" ';
2544: $runoff = ' ';
2545: }
2546: } else {
2547: if ($autorun) {
2548: $runon = ' checked="checked" ';
2549: $runoff = ' ';
2550: } else {
2551: $runoff = ' checked="checked" ';
2552: $runon = ' ';
2553: }
2554: }
2555: if (exists($settings->{'co-owners'})) {
2556: if ($settings->{'co-owners'} eq '0') {
2557: $coownersoff = ' checked="checked" ';
2558: $coownerson = ' ';
2559: } else {
2560: $coownerson = ' checked="checked" ';
2561: $coownersoff = ' ';
2562: }
2563: } else {
2564: $coownersoff = ' checked="checked" ';
2565: $coownerson = ' ';
2566: }
2567: if (exists($settings->{'sender_domain'})) {
2568: $defdom = $settings->{'sender_domain'};
2569: }
2570: if (exists($settings->{'autofailsafe'})) {
2571: $failsafe = $settings->{'autofailsafe'};
2572: }
2573: } else {
2574: if ($autorun) {
2575: $runon = ' checked="checked" ';
2576: $runoff = ' ';
2577: } else {
2578: $runoff = ' checked="checked" ';
2579: $runon = ' ';
2580: }
2581: }
2582: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
2583: my $notif_sender;
2584: if (ref($settings) eq 'HASH') {
2585: $notif_sender = $settings->{'sender_uname'};
2586: }
2587: my $datatable='<tr class="LC_odd_row">'.
2588: '<td>'.&mt('Auto-enrollment active?').'</td>'.
2589: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2590: '<input type="radio" name="autoenroll_run"'.
2591: $runon.' value="1" />'.&mt('Yes').'</label> '.
2592: '<label><input type="radio" name="autoenroll_run"'.
2593: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
2594: '</tr><tr>'.
2595: '<td>'.&mt('Notification messages - sender').
2596: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
2597: &mt('username').': '.
2598: '<input type="text" name="sender_uname" value="'.
2599: $notif_sender.'" size="10" /> '.&mt('domain').
2600: ': '.$domform.'</span></td></tr>'.
2601: '<tr class="LC_odd_row">'.
2602: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2603: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2604: '<input type="radio" name="autoassign_coowners"'.
2605: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2606: '<label><input type="radio" name="autoassign_coowners"'.
2607: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2608: '</tr><tr>'.
2609: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2610: '<td class="LC_right_item"><span class="LC_nobreak">'.
2611: '<input type="text" name="autoenroll_failsafe"'.
2612: ' value="'.$failsafe.'" size="4" /></td></tr>';
2613: $$rowtotal += 4;
2614: return $datatable;
2615: }
2616:
2617: sub print_autoupdate {
2618: my ($position,$dom,$settings,$rowtotal) = @_;
2619: my $datatable;
2620: if ($position eq 'top') {
2621: my $updateon = ' ';
2622: my $updateoff = ' checked="checked" ';
2623: my $classlistson = ' ';
2624: my $classlistsoff = ' checked="checked" ';
2625: if (ref($settings) eq 'HASH') {
2626: if ($settings->{'run'} eq '1') {
2627: $updateon = $updateoff;
2628: $updateoff = ' ';
2629: }
2630: if ($settings->{'classlists'} eq '1') {
2631: $classlistson = $classlistsoff;
2632: $classlistsoff = ' ';
2633: }
2634: }
2635: my %title = (
2636: run => 'Auto-update active?',
2637: classlists => 'Update information in classlists?',
2638: );
2639: $datatable = '<tr class="LC_odd_row">'.
2640: '<td>'.&mt($title{'run'}).'</td>'.
2641: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2642: '<input type="radio" name="autoupdate_run"'.
2643: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2644: '<label><input type="radio" name="autoupdate_run"'.
2645: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
2646: '</tr><tr>'.
2647: '<td>'.&mt($title{'classlists'}).'</td>'.
2648: '<td class="LC_right_item"><span class="LC_nobreak">'.
2649: '<label><input type="radio" name="classlists"'.
2650: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2651: '<label><input type="radio" name="classlists"'.
2652: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
2653: '</tr>';
2654: $$rowtotal += 2;
2655: } elsif ($position eq 'middle') {
2656: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2657: my $numinrow = 3;
2658: my $locknamesettings;
2659: $datatable .= &insttypes_row($settings,$types,$usertypes,
2660: $dom,$numinrow,$othertitle,
2661: 'lockablenames',$rowtotal);
2662: $$rowtotal ++;
2663: } else {
2664: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2665: my @fields = ('lastname','firstname','middlename','generation',
2666: 'permanentemail','id');
2667: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
2668: my $numrows = 0;
2669: if (ref($types) eq 'ARRAY') {
2670: if (@{$types} > 0) {
2671: $datatable =
2672: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2673: \@fields,$types,\$numrows);
2674: $$rowtotal += @{$types};
2675: }
2676: }
2677: $datatable .=
2678: &usertype_update_row($settings,{'default' => $othertitle},
2679: \%fieldtitles,\@fields,['default'],
2680: \$numrows);
2681: $$rowtotal ++;
2682: }
2683: return $datatable;
2684: }
2685:
2686: sub print_autocreate {
2687: my ($dom,$settings,$rowtotal) = @_;
2688: my (%createon,%createoff,%currhash);
2689: my @types = ('xml','req');
2690: if (ref($settings) eq 'HASH') {
2691: foreach my $item (@types) {
2692: $createoff{$item} = ' checked="checked" ';
2693: $createon{$item} = ' ';
2694: if (exists($settings->{$item})) {
2695: if ($settings->{$item}) {
2696: $createon{$item} = ' checked="checked" ';
2697: $createoff{$item} = ' ';
2698: }
2699: }
2700: }
2701: if ($settings->{'xmldc'} ne '') {
2702: $currhash{$settings->{'xmldc'}} = 1;
2703: }
2704: } else {
2705: foreach my $item (@types) {
2706: $createoff{$item} = ' checked="checked" ';
2707: $createon{$item} = ' ';
2708: }
2709: }
2710: $$rowtotal += 2;
2711: my $numinrow = 2;
2712: my $datatable='<tr class="LC_odd_row">'.
2713: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2714: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2715: '<input type="radio" name="autocreate_xml"'.
2716: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2717: '<label><input type="radio" name="autocreate_xml"'.
2718: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2719: '</td></tr><tr>'.
2720: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2721: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2722: '<input type="radio" name="autocreate_req"'.
2723: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2724: '<label><input type="radio" name="autocreate_req"'.
2725: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
2726: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2727: 'autocreate_xmldc',%currhash);
2728: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
2729: if ($numdc > 1) {
2730: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2731: '</td><td class="LC_left_item">';
2732: } else {
2733: $datatable .= &mt('Course creation processed as:').
2734: '</td><td class="LC_right_item">';
2735: }
2736: $datatable .= $dctable.'</td></tr>';
2737: $$rowtotal += $rows;
2738: return $datatable;
2739: }
2740:
2741: sub print_directorysrch {
2742: my ($position,$dom,$settings,$rowtotal) = @_;
2743: my $datatable;
2744: if ($position eq 'top') {
2745: my $instsrchon = ' ';
2746: my $instsrchoff = ' checked="checked" ';
2747: my ($exacton,$containson,$beginson);
2748: my $instlocalon = ' ';
2749: my $instlocaloff = ' checked="checked" ';
2750: if (ref($settings) eq 'HASH') {
2751: if ($settings->{'available'} eq '1') {
2752: $instsrchon = $instsrchoff;
2753: $instsrchoff = ' ';
2754: }
2755: if ($settings->{'localonly'} eq '1') {
2756: $instlocalon = $instlocaloff;
2757: $instlocaloff = ' ';
2758: }
2759: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2760: foreach my $type (@{$settings->{'searchtypes'}}) {
2761: if ($type eq 'exact') {
2762: $exacton = ' checked="checked" ';
2763: } elsif ($type eq 'contains') {
2764: $containson = ' checked="checked" ';
2765: } elsif ($type eq 'begins') {
2766: $beginson = ' checked="checked" ';
2767: }
2768: }
2769: } else {
2770: if ($settings->{'searchtypes'} eq 'exact') {
2771: $exacton = ' checked="checked" ';
2772: } elsif ($settings->{'searchtypes'} eq 'contains') {
2773: $containson = ' checked="checked" ';
2774: } elsif ($settings->{'searchtypes'} eq 'specify') {
2775: $exacton = ' checked="checked" ';
2776: $containson = ' checked="checked" ';
2777: }
2778: }
2779: }
2780: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2781: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2782:
2783: my $numinrow = 4;
2784: my $cansrchrow = 0;
2785: $datatable='<tr class="LC_odd_row">'.
2786: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
2787: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2788: '<input type="radio" name="dirsrch_available"'.
2789: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
2790: '<label><input type="radio" name="dirsrch_available"'.
2791: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2792: '</tr><tr>'.
2793: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
2794: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2795: '<input type="radio" name="dirsrch_instlocalonly"'.
2796: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2797: '<label><input type="radio" name="dirsrch_instlocalonly"'.
2798: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2799: '</tr>';
2800: $$rowtotal += 2;
2801: if (ref($usertypes) eq 'HASH') {
2802: if (keys(%{$usertypes}) > 0) {
2803: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2804: $numinrow,$othertitle,'cansearch',
2805: $rowtotal);
2806: $cansrchrow = 1;
2807: }
2808: }
2809: if ($cansrchrow) {
2810: $$rowtotal ++;
2811: $datatable .= '<tr>';
2812: } else {
2813: $datatable .= '<tr class="LC_odd_row">';
2814: }
2815: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2816: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2817: foreach my $title (@{$titleorder}) {
2818: if (defined($searchtitles->{$title})) {
2819: my $check = ' ';
2820: if (ref($settings) eq 'HASH') {
2821: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2822: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2823: $check = ' checked="checked" ';
2824: }
2825: }
2826: }
2827: $datatable .= '<td class="LC_left_item">'.
2828: '<span class="LC_nobreak"><label>'.
2829: '<input type="checkbox" name="searchby" '.
2830: 'value="'.$title.'"'.$check.'/>'.
2831: $searchtitles->{$title}.'</label></span></td>';
2832: }
2833: }
2834: $datatable .= '</tr></table></td></tr>';
2835: $$rowtotal ++;
2836: if ($cansrchrow) {
2837: $datatable .= '<tr class="LC_odd_row">';
2838: } else {
2839: $datatable .= '<tr>';
2840: }
2841: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
2842: '<td class="LC_left_item" colspan="2">'.
2843: '<span class="LC_nobreak"><label>'.
2844: '<input type="checkbox" name="searchtypes" '.
2845: $exacton.' value="exact" />'.&mt('Exact match').
2846: '</label> '.
2847: '<label><input type="checkbox" name="searchtypes" '.
2848: $beginson.' value="begins" />'.&mt('Begins with').
2849: '</label> '.
2850: '<label><input type="checkbox" name="searchtypes" '.
2851: $containson.' value="contains" />'.&mt('Contains').
2852: '</label></span></td></tr>';
2853: $$rowtotal ++;
2854: } else {
2855: my $domsrchon = ' checked="checked" ';
2856: my $domsrchoff = ' ';
2857: my $domlocalon = ' ';
2858: my $domlocaloff = ' checked="checked" ';
2859: if (ref($settings) eq 'HASH') {
2860: if ($settings->{'lclocalonly'} eq '1') {
2861: $domlocalon = $domlocaloff;
2862: $domlocaloff = ' ';
2863: }
2864: if ($settings->{'lcavailable'} eq '0') {
2865: $domsrchoff = $domsrchon;
2866: $domsrchon = ' ';
2867: }
2868: }
2869: $datatable='<tr class="LC_odd_row">'.
2870: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
2871: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2872: '<input type="radio" name="dirsrch_domavailable"'.
2873: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
2874: '<label><input type="radio" name="dirsrch_domavailable"'.
2875: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2876: '</tr><tr>'.
2877: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
2878: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2879: '<input type="radio" name="dirsrch_domlocalonly"'.
2880: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2881: '<label><input type="radio" name="dirsrch_domlocalonly"'.
2882: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2883: '</tr>';
2884: $$rowtotal += 2;
2885: }
2886: return $datatable;
2887: }
2888:
2889: sub print_contacts {
2890: my ($position,$dom,$settings,$rowtotal) = @_;
2891: my $datatable;
2892: my @contacts = ('adminemail','supportemail');
2893: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
2894: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings);
2895: if ($position eq 'top') {
2896: if (ref($settings) eq 'HASH') {
2897: foreach my $item (@contacts) {
2898: if (exists($settings->{$item})) {
2899: $to{$item} = $settings->{$item};
2900: }
2901: }
2902: }
2903: } elsif ($position eq 'middle') {
2904: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
2905: 'updatesmail','idconflictsmail');
2906: foreach my $type (@mailings) {
2907: $otheremails{$type} = '';
2908: }
2909: } else {
2910: @mailings = ('helpdeskmail','otherdomsmail');
2911: foreach my $type (@mailings) {
2912: $otheremails{$type} = '';
2913: }
2914: $bccemails{'helpdeskmail'} = '';
2915: $bccemails{'otherdomsmail'} = '';
2916: $includestr{'helpdeskmail'} = '';
2917: $includestr{'otherdomsmail'} = '';
2918: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
2919: }
2920: if (ref($settings) eq 'HASH') {
2921: unless ($position eq 'top') {
2922: foreach my $type (@mailings) {
2923: if (exists($settings->{$type})) {
2924: if (ref($settings->{$type}) eq 'HASH') {
2925: foreach my $item (@contacts) {
2926: if ($settings->{$type}{$item}) {
2927: $checked{$type}{$item} = ' checked="checked" ';
2928: }
2929: }
2930: $otheremails{$type} = $settings->{$type}{'others'};
2931: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
2932: $bccemails{$type} = $settings->{$type}{'bcc'};
2933: if ($settings->{$type}{'include'} ne '') {
2934: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
2935: $includestr{$type} = &unescape($includestr{$type});
2936: }
2937: }
2938: }
2939: } elsif ($type eq 'lonstatusmail') {
2940: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2941: }
2942: }
2943: }
2944: if ($position eq 'bottom') {
2945: foreach my $type (@mailings) {
2946: $bccemails{$type} = $settings->{$type}{'bcc'};
2947: if ($settings->{$type}{'include'} ne '') {
2948: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
2949: $includestr{$type} = &unescape($includestr{$type});
2950: }
2951: }
2952: if (ref($settings->{'helpform'}) eq 'HASH') {
2953: if (ref($fields) eq 'ARRAY') {
2954: foreach my $field (@{$fields}) {
2955: $currfield{$field} = $settings->{'helpform'}{$field};
2956: }
2957: }
2958: if (exists($settings->{'helpform'}{'maxsize'})) {
2959: $maxsize = $settings->{'helpform'}{'maxsize'};
2960: } else {
2961: $maxsize = '1.0';
2962: }
2963: } else {
2964: if (ref($fields) eq 'ARRAY') {
2965: foreach my $field (@{$fields}) {
2966: $currfield{$field} = 'yes';
2967: }
2968: }
2969: $maxsize = '1.0';
2970: }
2971: }
2972: } else {
2973: if ($position eq 'top') {
2974: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2975: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2976: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2977: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
2978: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2979: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
2980: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
2981: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
2982: } elsif ($position eq 'bottom') {
2983: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2984: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
2985: if (ref($fields) eq 'ARRAY') {
2986: foreach my $field (@{$fields}) {
2987: $currfield{$field} = 'yes';
2988: }
2989: }
2990: $maxsize = '1.0';
2991: }
2992: }
2993: my ($titles,$short_titles) = &contact_titles();
2994: my $rownum = 0;
2995: my $css_class;
2996: if ($position eq 'top') {
2997: foreach my $item (@contacts) {
2998: $css_class = $rownum%2?' class="LC_odd_row"':'';
2999: $datatable .= '<tr'.$css_class.'>'.
3000: '<td><span class="LC_nobreak">'.$titles->{$item}.
3001: '</span></td><td class="LC_right_item">'.
3002: '<input type="text" name="'.$item.'" value="'.
3003: $to{$item}.'" /></td></tr>';
3004: $rownum ++;
3005: }
3006: } elsif ($position eq 'bottom') {
3007: $css_class = $rownum%2?' class="LC_odd_row"':'';
3008: $datatable .= '<tr'.$css_class.'>'.
3009: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3010: &mt('(e-mail, subject, and description always shown)').
3011: '</td><td class="LC_left_item">';
3012: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3013: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3014: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3015: foreach my $field (@{$fields}) {
3016: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3017: if (($field eq 'screenshot') || ($field eq 'cc')) {
3018: $datatable .= ' '.&mt('(logged-in users)');
3019: }
3020: $datatable .='</td><td>';
3021: my $clickaction;
3022: if ($field eq 'screenshot') {
3023: $clickaction = ' onclick="screenshotSize(this);"';
3024: }
3025: if (ref($possoptions->{$field}) eq 'ARRAY') {
3026: foreach my $option (@{$possoptions->{$field}}) {
3027: my $checked;
3028: if ($currfield{$field} eq $option) {
3029: $checked = ' checked="checked"';
3030: }
3031: $datatable .= '<span class="LC_nobreak"><label>'.
3032: '<input type="radio" name="helpform_'.$field.'" '.
3033: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3034: '</label></span>'.(' 'x2);
3035: }
3036: }
3037: if ($field eq 'screenshot') {
3038: my $display;
3039: if ($currfield{$field} eq 'no') {
3040: $display = ' style="display:none"';
3041: }
3042: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.' />'.
3043: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3044: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3045: }
3046: $datatable .= '</td></tr>';
3047: }
3048: $datatable .= '</table>';
3049: }
3050: $datatable .= '</td></tr>'."\n";
3051: $rownum ++;
3052: }
3053: unless ($position eq 'top') {
3054: foreach my $type (@mailings) {
3055: $css_class = $rownum%2?' class="LC_odd_row"':'';
3056: $datatable .= '<tr'.$css_class.'>'.
3057: '<td><span class="LC_nobreak">'.
3058: $titles->{$type}.': </span></td>'.
3059: '<td class="LC_left_item">';
3060: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3061: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3062: }
3063: $datatable .= '<span class="LC_nobreak">';
3064: foreach my $item (@contacts) {
3065: $datatable .= '<label>'.
3066: '<input type="checkbox" name="'.$type.'"'.
3067: $checked{$type}{$item}.
3068: ' value="'.$item.'" />'.$short_titles->{$item}.
3069: '</label> ';
3070: }
3071: $datatable .= '</span><br />'.&mt('Others').': '.
3072: '<input type="text" name="'.$type.'_others" '.
3073: 'value="'.$otheremails{$type}.'" />';
3074: my %locchecked;
3075: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3076: foreach my $loc ('s','b') {
3077: if ($includeloc{$type} eq $loc) {
3078: $locchecked{$loc} = ' checked="checked"';
3079: last;
3080: }
3081: }
3082: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3083: '<input type="text" name="'.$type.'_bcc" '.
3084: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3085: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3086: &mt('Text automatically added to e-mail:').' '.
3087: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br >'.
3088: '<span class="LC_nobreak">'.&mt('Location:').' '.
3089: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3090: (' 'x2).
3091: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3092: '</span></fieldset>';
3093: }
3094: $datatable .= '</td></tr>'."\n";
3095: $rownum ++;
3096: }
3097: }
3098: if ($position eq 'middle') {
3099: my %choices;
3100: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
3101: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3102: &mt('LON-CAPA core group - MSU'),600,500));
3103: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
3104: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3105: &mt('LON-CAPA core group - MSU'),600,500));
3106: my @toggles = ('reporterrors','reportupdates');
3107: my %defaultchecked = ('reporterrors' => 'on',
3108: 'reportupdates' => 'on');
3109: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3110: \%choices,$rownum);
3111: $datatable .= $reports;
3112: } elsif ($position eq 'bottom') {
3113: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3114: my (@posstypes,%usertypeshash);
3115: if (ref($types) eq 'ARRAY') {
3116: @posstypes = @{$types};
3117: }
3118: if (@posstypes) {
3119: if (ref($usertypes) eq 'HASH') {
3120: %usertypeshash = %{$usertypes};
3121: }
3122: my @overridden;
3123: my $numinrow = 4;
3124: if (ref($settings) eq 'HASH') {
3125: if (ref($settings->{'overrides'}) eq 'HASH') {
3126: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
3127: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
3128: push(@overridden,$key);
3129: foreach my $item (@contacts) {
3130: if ($settings->{'overrides'}{$key}{$item}) {
3131: $checked{'override_'.$key}{$item} = ' checked="checked" ';
3132: }
3133: }
3134: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
3135: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
3136: $includeloc{'override_'.$key} = '';
3137: $includestr{'override_'.$key} = '';
3138: if ($settings->{'overrides'}{$key}{'include'} ne '') {
3139: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
3140: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
3141: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
3142: }
3143: }
3144: }
3145: }
3146: }
3147: my $customclass = 'LC_helpdesk_override';
3148: my $optionsprefix = 'LC_options_helpdesk_';
3149:
3150: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
3151:
3152: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
3153: $numinrow,$othertitle,'overrides',
3154: \$rownum,$onclicktypes,$customclass);
3155: $rownum ++;
3156: $usertypeshash{'default'} = $othertitle;
3157: foreach my $status (@posstypes) {
3158: my $css_class;
3159: if ($rownum%2) {
3160: $css_class = 'LC_odd_row ';
3161: }
3162: $css_class .= $customclass;
3163: my $rowid = $optionsprefix.$status;
3164: my $hidden = 1;
3165: my $currstyle = 'display:none';
3166: if (grep(/^\Q$status\E$/,@overridden)) {
3167: $currstyle = 'display:table-row';
3168: $hidden = 0;
3169: }
3170: my $key = 'override_'.$status;
3171: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
3172: $includeloc{$key},$includestr{$key},$status,$rowid,
3173: $usertypeshash{$status},$css_class,$currstyle,
3174: \@contacts,$short_titles);
3175: unless ($hidden) {
3176: $rownum ++;
3177: }
3178: }
3179: }
3180: }
3181: $$rowtotal += $rownum;
3182: return $datatable;
3183: }
3184:
3185: sub overridden_helpdesk {
3186: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
3187: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
3188: my $class = 'LC_left_item';
3189: if ($css_class) {
3190: $css_class = ' class="'.$css_class.'"';
3191: }
3192: if ($rowid) {
3193: $rowid = ' id="'.$rowid.'"';
3194: }
3195: if ($rowstyle) {
3196: $rowstyle = ' style="'.$rowstyle.'"';
3197: }
3198: my ($output,$description);
3199: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
3200: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
3201: "<td>$description</td>\n".
3202: '<td class="'.$class.'" colspan="2">'.
3203: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
3204: '<span class="LC_nobreak">';
3205: if (ref($contacts) eq 'ARRAY') {
3206: foreach my $item (@{$contacts}) {
3207: my $check;
3208: if (ref($checked) eq 'HASH') {
3209: $check = $checked->{$item};
3210: }
3211: my $title;
3212: if (ref($short_titles) eq 'HASH') {
3213: $title = $short_titles->{$item};
3214: }
3215: $output .= '<label>'.
3216: '<input type="checkbox" name="override_'.$type.'"'.$check.
3217: ' value="'.$item.'" />'.$title.'</label> ';
3218: }
3219: }
3220: $output .= '</span><br />'.&mt('Others').': '.
3221: '<input type="text" name="override_'.$type.'_others" '.
3222: 'value="'.$otheremails.'" />';
3223: my %locchecked;
3224: foreach my $loc ('s','b') {
3225: if ($includeloc eq $loc) {
3226: $locchecked{$loc} = ' checked="checked"';
3227: last;
3228: }
3229: }
3230: $output .= '<br />'.&mt('Bcc:').(' 'x6).
3231: '<input type="text" name="override_'.$type.'_bcc" '.
3232: 'value="'.$bccemails.'" /></fieldset>'.
3233: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3234: &mt('Text automatically added to e-mail:').' '.
3235: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br >'.
3236: '<span class="LC_nobreak">'.&mt('Location:').' '.
3237: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3238: (' 'x2).
3239: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3240: '</span></fieldset>'.
3241: '</td></tr>'."\n";
3242: return $output;
3243: }
3244:
3245: sub contacts_javascript {
3246: return <<"ENDSCRIPT";
3247:
3248: <script type="text/javascript">
3249: // <![CDATA[
3250:
3251: function screenshotSize(field) {
3252: if (document.getElementById('help_screenshotsize')) {
3253: if (field.value == 'no') {
3254: document.getElementById('help_screenshotsize').style.display="none";
3255: } else {
3256: document.getElementById('help_screenshotsize').style.display="";
3257: }
3258: }
3259: return;
3260: }
3261:
3262: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
3263: if (form.elements[checkbox].length != undefined) {
3264: var count = 0;
3265: if (docount) {
3266: for (var i=0; i<form.elements[checkbox].length; i++) {
3267: if (form.elements[checkbox][i].checked) {
3268: count ++;
3269: }
3270: }
3271: }
3272: for (var i=0; i<form.elements[checkbox].length; i++) {
3273: var type = form.elements[checkbox][i].value;
3274: if (document.getElementById(prefix+type)) {
3275: if (form.elements[checkbox][i].checked) {
3276: document.getElementById(prefix+type).style.display = 'table-row';
3277: if (count % 2 == 1) {
3278: document.getElementById(prefix+type).className = target+' LC_odd_row';
3279: } else {
3280: document.getElementById(prefix+type).className = target;
3281: }
3282: count ++;
3283: } else {
3284: document.getElementById(prefix+type).style.display = 'none';
3285: }
3286: }
3287: }
3288: }
3289: return;
3290: }
3291:
3292:
3293: // ]]>
3294: </script>
3295:
3296: ENDSCRIPT
3297: }
3298:
3299: sub print_helpsettings {
3300: my ($position,$dom,$settings,$rowtotal) = @_;
3301: my $confname = $dom.'-domainconfig';
3302: my $formname = 'display';
3303: my ($datatable,$itemcount);
3304: if ($position eq 'top') {
3305: $itemcount = 1;
3306: my (%choices,%defaultchecked,@toggles);
3307: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3308: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3309: &mt('LON-CAPA bug tracker'),600,500));
3310: %defaultchecked = ('submitbugs' => 'on');
3311: @toggles = ('submitbugs');
3312: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3313: \%choices,$itemcount);
3314: $$rowtotal ++;
3315: } else {
3316: my $css_class;
3317: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
3318: my (%customroles,%ordered,%current);
3319: if (ref($settings) eq 'HASH') {
3320: if (ref($settings->{'adhoc'}) eq 'HASH') {
3321: %current = %{$settings->{'adhoc'}};
3322: }
3323: }
3324: my $count = 0;
3325: foreach my $key (sort(keys(%existing))) {
3326: if ($key=~/^rolesdef\_(\w+)$/) {
3327: my $rolename = $1;
3328: my (%privs,$order);
3329: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3330: $customroles{$rolename} = \%privs;
3331: if (ref($current{$rolename}) eq 'HASH') {
3332: $order = $current{$rolename}{'order'};
3333: }
3334: if ($order eq '') {
3335: $order = $count;
3336: }
3337: $ordered{$order} = $rolename;
3338: $count++;
3339: }
3340: }
3341: my $maxnum = scalar(keys(%ordered));
3342: my @roles_by_num = ();
3343: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3344: push(@roles_by_num,$item);
3345: }
3346: my $context = 'domprefs';
3347: my $crstype = 'Course';
3348: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3349: my @accesstypes = ('all','dh','da','none');
3350: my ($numstatustypes,@jsarray);
3351: if (ref($types) eq 'ARRAY') {
3352: if (@{$types} > 0) {
3353: $numstatustypes = scalar(@{$types});
3354: push(@accesstypes,'status');
3355: @jsarray = ('bystatus');
3356: }
3357: }
3358: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
3359: if (keys(%domhelpdesk)) {
3360: push(@accesstypes,('inc','exc'));
3361: push(@jsarray,('notinc','notexc'));
3362: }
3363: my $hiddenstr = join("','",@jsarray);
3364: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
3365: my $context = 'domprefs';
3366: my $crstype = 'Course';
3367: my $prefix = 'helproles_';
3368: my $add_class = 'LC_hidden';
3369: foreach my $num (@roles_by_num) {
3370: my $role = $ordered{$num};
3371: my ($desc,$access,@statuses);
3372: if (ref($current{$role}) eq 'HASH') {
3373: $desc = $current{$role}{'desc'};
3374: $access = $current{$role}{'access'};
3375: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3376: @statuses = @{$current{$role}{'insttypes'}};
3377: }
3378: }
3379: if ($desc eq '') {
3380: $desc = $role;
3381: }
3382: my $identifier = 'custhelp'.$num;
3383: my %full=();
3384: my %levels= (
3385: course => {},
3386: domain => {},
3387: system => {},
3388: );
3389: my %levelscurrent=(
3390: course => {},
3391: domain => {},
3392: system => {},
3393: );
3394: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3395: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3396: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3397: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
3398: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
3399: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3400: for (my $k=0; $k<=$maxnum; $k++) {
3401: my $vpos = $k+1;
3402: my $selstr;
3403: if ($k == $num) {
3404: $selstr = ' selected="selected" ';
3405: }
3406: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3407: }
3408: $datatable .= '</select>'.(' 'x2).
3409: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3410: '</td>'.
3411: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3412: &mt('Name shown to users:').
3413: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3414: '</fieldset>'.
3415: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3416: $othertitle,$usertypes,$types,\%domhelpdesk).
3417: '<fieldset>'.
3418: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
3419: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
3420: \%levelscurrent,$identifier,
3421: 'LC_hidden',$prefix.$num.'_privs').
3422: '</fieldset></td>';
3423: $itemcount ++;
3424: }
3425: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3426: my $newcust = 'custhelp'.$count;
3427: my (%privs,%levelscurrent);
3428: my %full=();
3429: my %levels= (
3430: course => {},
3431: domain => {},
3432: system => {},
3433: );
3434: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3435: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3436: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
3437: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
3438: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3439: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3440: for (my $k=0; $k<$maxnum+1; $k++) {
3441: my $vpos = $k+1;
3442: my $selstr;
3443: if ($k == $maxnum) {
3444: $selstr = ' selected="selected" ';
3445: }
3446: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3447: }
3448: $datatable .= '</select> '."\n".
3449: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3450: '</label></span></td>'.
3451: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3452: '<span class="LC_nobreak">'.
3453: &mt('Internal name:').
3454: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3455: '</span>'.(' 'x4).
3456: '<span class="LC_nobreak">'.
3457: &mt('Name shown to users:').
3458: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3459: '</span></fieldset>'.
3460: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3461: $usertypes,$types,\%domhelpdesk).
3462: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
3463: &Apache::lonuserutils::custom_role_header($context,$crstype,
3464: \@templateroles,$newcust).
3465: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3466: \%levelscurrent,$newcust).
3467: '</fieldset></td></tr>';
3468: $count ++;
3469: $$rowtotal += $count;
3470: }
3471: return $datatable;
3472: }
3473:
3474: sub adhocbutton {
3475: my ($prefix,$num,$field,$visibility) = @_;
3476: my %lt = &Apache::lonlocal::texthash(
3477: show => 'Show details',
3478: hide => 'Hide details',
3479: );
3480: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3481: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3482: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3483: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3484: }
3485:
3486: sub helpsettings_javascript {
3487: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3488: return unless(ref($roles_by_num) eq 'ARRAY');
3489: my %html_js_lt = &Apache::lonlocal::texthash(
3490: show => 'Show details',
3491: hide => 'Hide details',
3492: );
3493: &html_escape(\%html_js_lt);
3494: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3495: return <<"ENDSCRIPT";
3496: <script type="text/javascript">
3497: // <![CDATA[
3498:
3499: function reorderHelpRoles(form,item) {
3500: var changedVal;
3501: $jstext
3502: var newpos = 'helproles_${total}_pos';
3503: var maxh = 1 + $total;
3504: var current = new Array();
3505: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3506: if (item == newpos) {
3507: changedVal = newitemVal;
3508: } else {
3509: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3510: current[newitemVal] = newpos;
3511: }
3512: for (var i=0; i<helproles.length; i++) {
3513: var elementName = 'helproles_'+helproles[i]+'_pos';
3514: if (elementName != item) {
3515: if (form.elements[elementName]) {
3516: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3517: current[currVal] = elementName;
3518: }
3519: }
3520: }
3521: var oldVal;
3522: for (var j=0; j<maxh; j++) {
3523: if (current[j] == undefined) {
3524: oldVal = j;
3525: }
3526: }
3527: if (oldVal < changedVal) {
3528: for (var k=oldVal+1; k<=changedVal ; k++) {
3529: var elementName = current[k];
3530: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3531: }
3532: } else {
3533: for (var k=changedVal; k<oldVal; k++) {
3534: var elementName = current[k];
3535: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3536: }
3537: }
3538: return;
3539: }
3540:
3541: function helpdeskAccess(num) {
3542: var curraccess = null;
3543: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3544: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3545: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3546: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3547: }
3548: }
3549: }
3550: var shown = Array();
3551: var hidden = Array();
3552: if (curraccess == 'none') {
3553: hidden = Array('$hiddenstr');
3554: } else {
3555: if (curraccess == 'status') {
3556: shown = Array('bystatus');
3557: hidden = Array('notinc','notexc');
3558: } else {
3559: if (curraccess == 'exc') {
3560: shown = Array('notexc');
3561: hidden = Array('notinc','bystatus');
3562: }
3563: if (curraccess == 'inc') {
3564: shown = Array('notinc');
3565: hidden = Array('notexc','bystatus');
3566: }
3567: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
3568: hidden = Array('notinc','notexc','bystatus');
3569: }
3570: }
3571: }
3572: if (hidden.length > 0) {
3573: for (var i=0; i<hidden.length; i++) {
3574: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3575: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3576: }
3577: }
3578: }
3579: if (shown.length > 0) {
3580: for (var i=0; i<shown.length; i++) {
3581: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
3582: if (shown[i] == 'privs') {
3583: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
3584: } else {
3585: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
3586: }
3587: }
3588: }
3589: }
3590: return;
3591: }
3592:
3593: function toggleHelpdeskItem(num,field) {
3594: if (document.getElementById('helproles_'+num+'_'+field)) {
3595: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
3596: document.getElementById('helproles_'+num+'_'+field).className =
3597: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
3598: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3599: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
3600: }
3601: } else {
3602: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
3603: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3604: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
3605: }
3606: }
3607: }
3608: return;
3609: }
3610:
3611: // ]]>
3612: </script>
3613:
3614: ENDSCRIPT
3615: }
3616:
3617: sub helpdeskroles_access {
3618: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
3619: $usertypes,$types,$domhelpdesk) = @_;
3620: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
3621: my %lt = &Apache::lonlocal::texthash(
3622: 'rou' => 'Role usage',
3623: 'whi' => 'Which helpdesk personnel may use this role?',
3624: 'all' => 'All with domain helpdesk or helpdesk assistant role',
3625: 'dh' => 'All with domain helpdesk role',
3626: 'da' => 'All with domain helpdesk assistant role',
3627: 'none' => 'None',
3628: 'status' => 'Determined based on institutional status',
3629: 'inc' => 'Include all, but exclude specific personnel',
3630: 'exc' => 'Exclude all, but include specific personnel',
3631: );
3632: my %usecheck = (
3633: all => ' checked="checked"',
3634: );
3635: my %displaydiv = (
3636: status => 'none',
3637: inc => 'none',
3638: exc => 'none',
3639: priv => 'block',
3640: );
3641: my $output;
3642: if (ref($current) eq 'HASH') {
3643: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
3644: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
3645: $usecheck{$current->{access}} = $usecheck{'all'};
3646: delete($usecheck{'all'});
3647: if ($current->{access} =~ /^(status|inc|exc)$/) {
3648: my $access = $1;
3649: $displaydiv{$access} = 'inline';
3650: } elsif ($current->{access} eq 'none') {
3651: $displaydiv{'priv'} = 'none';
3652: }
3653: }
3654: }
3655: }
3656: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
3657: '<p>'.$lt{'whi'}.'</p>';
3658: foreach my $access (@{$accesstypes}) {
3659: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
3660: ' onclick="helpdeskAccess('."'$num'".');" />'.
3661: $lt{$access}.'</label>';
3662: if ($access eq 'status') {
3663: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
3664: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
3665: $othertitle,$usertypes,$types).
3666: '</div>';
3667: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
3668: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
3669: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3670: '</div>';
3671: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
3672: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
3673: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3674: '</div>';
3675: }
3676: $output .= '</p>';
3677: }
3678: $output .= '</fieldset>';
3679: return $output;
3680: }
3681:
3682: sub radiobutton_prefs {
3683: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
3684: $additional,$align) = @_;
3685: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
3686: (ref($choices) eq 'HASH'));
3687:
3688: my (%checkedon,%checkedoff,$datatable,$css_class);
3689:
3690: foreach my $item (@{$toggles}) {
3691: if ($defaultchecked->{$item} eq 'on') {
3692: $checkedon{$item} = ' checked="checked" ';
3693: $checkedoff{$item} = ' ';
3694: } elsif ($defaultchecked->{$item} eq 'off') {
3695: $checkedoff{$item} = ' checked="checked" ';
3696: $checkedon{$item} = ' ';
3697: }
3698: }
3699: if (ref($settings) eq 'HASH') {
3700: foreach my $item (@{$toggles}) {
3701: if ($settings->{$item} eq '1') {
3702: $checkedon{$item} = ' checked="checked" ';
3703: $checkedoff{$item} = ' ';
3704: } elsif ($settings->{$item} eq '0') {
3705: $checkedoff{$item} = ' checked="checked" ';
3706: $checkedon{$item} = ' ';
3707: }
3708: }
3709: }
3710: if ($onclick) {
3711: $onclick = ' onclick="'.$onclick.'"';
3712: }
3713: foreach my $item (@{$toggles}) {
3714: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3715: $datatable .=
3716: '<tr'.$css_class.'><td valign="top">'.
3717: '<span class="LC_nobreak">'.$choices->{$item}.
3718: '</span></td>';
3719: if ($align eq 'left') {
3720: $datatable .= '<td class="LC_left_item">';
3721: } else {
3722: $datatable .= '<td class="LC_right_item">';
3723: }
3724: $datatable .=
3725: '<span class="LC_nobreak">'.
3726: '<label><input type="radio" name="'.
3727: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
3728: '</label> <label><input type="radio" name="'.$item.'" '.
3729: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3730: '</span>'.$additional.
3731: '</td>'.
3732: '</tr>';
3733: $itemcount ++;
3734: }
3735: return ($datatable,$itemcount);
3736: }
3737:
3738: sub print_ltitools {
3739: my ($dom,$settings,$rowtotal) = @_;
3740: my $rownum = 0;
3741: my $css_class;
3742: my $itemcount = 1;
3743: my $maxnum = 0;
3744: my %ordered;
3745: if (ref($settings) eq 'HASH') {
3746: foreach my $item (keys(%{$settings})) {
3747: if (ref($settings->{$item}) eq 'HASH') {
3748: my $num = $settings->{$item}{'order'};
3749: $ordered{$num} = $item;
3750: }
3751: }
3752: }
3753: my $confname = $dom.'-domainconfig';
3754: my $switchserver = &check_switchserver($dom,$confname);
3755: my $maxnum = scalar(keys(%ordered));
3756: my $datatable = <itools_javascript($settings);
3757: my %lt = <itools_names();
3758: my @courseroles = ('cc','in','ta','ep','st');
3759: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
3760: my @fields = ('fullname','firstname','lastname','email','user','roles');
3761: if (keys(%ordered)) {
3762: my @items = sort { $a <=> $b } keys(%ordered);
3763: for (my $i=0; $i<@items; $i++) {
3764: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3765: my $item = $ordered{$items[$i]};
3766: my ($title,$key,$secret,$url,$imgsrc,$version);
3767: if (ref($settings->{$item}) eq 'HASH') {
3768: $title = $settings->{$item}->{'title'};
3769: $url = $settings->{$item}->{'url'};
3770: $key = $settings->{$item}->{'key'};
3771: $secret = $settings->{$item}->{'secret'};
3772: my $image = $settings->{$item}->{'image'};
3773: if ($image ne '') {
3774: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
3775: }
3776: }
3777: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_".$item."'".');"';
3778: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3779: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
3780: for (my $k=0; $k<=$maxnum; $k++) {
3781: my $vpos = $k+1;
3782: my $selstr;
3783: if ($k == $i) {
3784: $selstr = ' selected="selected" ';
3785: }
3786: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3787: }
3788: $datatable .= '</select>'.(' 'x2).
3789: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
3790: &mt('Delete?').'</label></span></td>'.
3791: '<td colspan="2">'.
3792: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3793: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
3794: (' 'x2).
3795: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
3796: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
3797: (' 'x2).
3798: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
3799: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3800: '<br /><br />'.
3801: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_url_'.$i.'"'.
3802: ' value="'.$url.'" /></span>'.
3803: (' 'x2).
3804: '<span class="LC_nobreak">'.$lt{'key'}.
3805: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
3806: (' 'x2).
3807: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
3808: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
3809: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltitools_secret_'.$i.'.type='."'text'".' } else { this.form.ltitools_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
3810: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
3811: '</fieldset>'.
3812: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3813: '<span class="LC_nobreak">'.&mt('Display target:');
3814: my %currdisp;
3815: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
3816: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
3817: $currdisp{'window'} = ' checked="checked"';
3818: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
3819: $currdisp{'tab'} = ' checked="checked"';
3820: } else {
3821: $currdisp{'iframe'} = ' checked="checked"';
3822: }
3823: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
3824: $currdisp{'width'} = $1;
3825: }
3826: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
3827: $currdisp{'height'} = $1;
3828: }
3829: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
3830: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
3831: } else {
3832: $currdisp{'iframe'} = ' checked="checked"';
3833: }
3834: foreach my $disp ('iframe','tab','window') {
3835: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
3836: $lt{$disp}.'</label>'.(' 'x2);
3837: }
3838: $datatable .= (' 'x4);
3839: foreach my $dimen ('width','height') {
3840: $datatable .= '<label>'.$lt{$dimen}.' '.
3841: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
3842: (' 'x2);
3843: }
3844: $datatable .= '<br />'.
3845: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
3846: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></label></div>'.
3847: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
3848: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
3849: '</textarea></div><div style=""></div><br />';
3850: $datatable .= '<br />';
3851: foreach my $extra ('passback','roster') {
3852: my $checkedon = '';
3853: my $checkedoff = ' checked="checked"';
3854: if ($settings->{$item}->{$extra}) {
3855: $checkedon = $checkedoff;
3856: $checkedoff = '';
3857: }
3858: $datatable .= $lt{$extra}.' '.
3859: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.' />'.
3860: &mt('Yes').'</label>'.(' 'x2).
3861: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.' />'.
3862: &mt('No').'</label>'.(' 'x4);
3863: }
3864: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': ';
3865: if ($imgsrc) {
3866: $datatable .= $imgsrc.
3867: '<label><input type="checkbox" name="ltitools_image_del"'.
3868: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
3869: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
3870: } else {
3871: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3872: }
3873: if ($switchserver) {
3874: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3875: } else {
3876: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
3877: }
3878: $datatable .= '</span></fieldset>';
3879: my (%checkedfields,%rolemaps);
3880: if (ref($settings->{$item}) eq 'HASH') {
3881: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
3882: %checkedfields = %{$settings->{$item}->{'fields'}};
3883: }
3884: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
3885: %rolemaps = %{$settings->{$item}->{'roles'}};
3886: $checkedfields{'roles'} = 1;
3887: }
3888: }
3889: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3890: '<span class="LC_nobreak">';
3891: foreach my $field (@fields) {
3892: my $checked;
3893: if ($checkedfields{$field}) {
3894: $checked = ' checked="checked"';
3895: }
3896: $datatable .= '<label>'.
3897: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$checked.' />'.
3898: $lt{$field}.'</label>'.(' ' x2);
3899: }
3900: $datatable .= '</span></fieldset>'.
3901: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3902: foreach my $role (@courseroles) {
3903: my ($selected,$selectnone);
3904: if (!$rolemaps{$role}) {
3905: $selectnone = ' selected="selected"';
3906: }
3907: $datatable .= '<td align="center">'.
3908: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3909: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
3910: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
3911: foreach my $ltirole (@ltiroles) {
3912: unless ($selectnone) {
3913: if ($rolemaps{$role} eq $ltirole) {
3914: $selected = ' selected="selected"';
3915: } else {
3916: $selected = '';
3917: }
3918: }
3919: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
3920: }
3921: $datatable .= '</select></td>';
3922: }
3923: $datatable .= '</tr></table></fieldset>';
3924: my %courseconfig;
3925: if (ref($settings->{$item}) eq 'HASH') {
3926: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
3927: %courseconfig = %{$settings->{$item}->{'crsconf'}};
3928: }
3929: }
3930: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
3931: foreach my $item ('label','title','target','linktext','explanation') {
3932: my $checked;
3933: if ($courseconfig{$item}) {
3934: $checked = ' checked="checked"';
3935: }
3936: $datatable .= '<label>'.
3937: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
3938: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
3939: }
3940: $datatable .= '</span></fieldset>'.
3941: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3942: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
3943: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
3944: my %custom = %{$settings->{$item}->{'custom'}};
3945: if (keys(%custom) > 0) {
3946: foreach my $key (sort(keys(%custom))) {
3947: $datatable .= '<tr><td><span class="LC_nobreak">'.
3948: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
3949: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
3950: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
3951: ' value="'.$custom{$key}.'" /></td></tr>';
3952: }
3953: }
3954: }
3955: $datatable .= '<tr><td><span class="LC_nobreak">'.
3956: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
3957: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
3958: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
3959: $datatable .= '</table></fieldset></td></tr>'."\n";
3960: $itemcount ++;
3961: }
3962: }
3963: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3964: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_add_pos'".');"';
3965: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
3966: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
3967: '<select name="ltitools_add_pos"'.$chgstr.'>';
3968: for (my $k=0; $k<$maxnum+1; $k++) {
3969: my $vpos = $k+1;
3970: my $selstr;
3971: if ($k == $maxnum) {
3972: $selstr = ' selected="selected" ';
3973: }
3974: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3975: }
3976: $datatable .= '</select> '."\n".
3977: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".
3978: '<td colspan="2">'.
3979: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3980: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_add_title" value="" /></span> '."\n".
3981: (' 'x2).
3982: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
3983: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
3984: (' 'x2).
3985: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
3986: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3987: '<br />'.
3988: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_add_url" value="" /></span> '."\n".
3989: (' 'x2).
3990: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
3991: (' 'x2).
3992: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
3993: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltitools_add_secret.type='."'text'".' } else { this.form.ltitools_add_secret.type='."'password'".' }" />'.&mt('Visible input').'</label></span> '."\n".
3994: '</fieldset>'.
3995: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3996: '<span class="LC_nobreak">'.&mt('Display target:');
3997: my %defaultdisp;
3998: $defaultdisp{'iframe'} = ' checked="checked"';
3999: foreach my $disp ('iframe','tab','window') {
4000: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
4001: $lt{$disp}.'</label>'.(' 'x2);
4002: }
4003: $datatable .= (' 'x4);
4004: foreach my $dimen ('width','height') {
4005: $datatable .= '<label>'.$lt{$dimen}.' '.
4006: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
4007: (' 'x2);
4008: }
4009: $datatable .= '<br />'.
4010: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
4011: '<input type="text" name="ltitools_add_linktext" size="5" /></label></div>'.
4012: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4013: '<textarea name=ltitools_add_explanation" rows="5" cols="40"></textarea>'.
4014: '</div><div style=""></div><br />';
4015: foreach my $extra ('passback','roster') {
4016: $datatable .= $lt{$extra}.' '.
4017: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="1" />'.
4018: &mt('Yes').'</label>'.(' 'x2).
4019: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="0" checked="checked" />'.
4020: &mt('No').'</label>'.(' 'x4);
4021: }
4022: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': '.
4023: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4024: if ($switchserver) {
4025: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4026: } else {
4027: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
4028: }
4029: $datatable .= '</span></fieldset>'.
4030: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4031: '<span class="LC_nobreak">';
4032: foreach my $field (@fields) {
4033: $datatable .= '<label>'.
4034: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'" />'.
4035: $lt{$field}.'</label>'.(' ' x2);
4036: }
4037: $datatable .= '</span></fieldset>'.
4038: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4039: foreach my $role (@courseroles) {
4040: my ($checked,$checkednone);
4041: $datatable .= '<td align="center">'.
4042: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4043: '<select name="ltitools_add_roles_'.$role.'">'.
4044: '<option value="" selected="selected">'.&mt('Select').'</option>';
4045: foreach my $ltirole (@ltiroles) {
4046: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
4047: }
4048: $datatable .= '</select></td>';
4049: }
4050: $datatable .= '</tr></table></fieldset>'.
4051: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
4052: foreach my $item ('label','title','target','linktext','explanation') {
4053: $datatable .= '<label>'.
4054: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
4055: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
4056: }
4057: $datatable .= '</span></fieldset>'.
4058: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4059: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
4060: '<tr><td><span class="LC_nobreak">'.
4061: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
4062: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
4063: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
4064: '</table></fieldset></td></tr>'."\n".
4065: '</td>'."\n".
4066: '</tr>'."\n";
4067: $itemcount ++;
4068: return $datatable;
4069: }
4070:
4071: sub ltitools_names {
4072: my %lt = &Apache::lonlocal::texthash(
4073: 'title' => 'Title',
4074: 'version' => 'Version',
4075: 'msgtype' => 'Message Type',
4076: 'url' => 'URL',
4077: 'key' => 'Key',
4078: 'secret' => 'Secret',
4079: 'icon' => 'Icon',
4080: 'user' => 'Username:domain',
4081: 'fullname' => 'Full Name',
4082: 'firstname' => 'First Name',
4083: 'lastname' => 'Last Name',
4084: 'email' => 'E-mail',
4085: 'roles' => 'Role',
4086: 'window' => 'Window',
4087: 'tab' => 'Tab',
4088: 'iframe' => 'iFrame',
4089: 'height' => 'Height',
4090: 'width' => 'Width',
4091: 'linktext' => 'Default Link Text',
4092: 'explanation' => 'Default Explanation',
4093: 'passback' => 'Tool can return grades:',
4094: 'roster' => 'Tool can retrieve roster:',
4095: 'crstarget' => 'Display target',
4096: 'crslabel' => 'Course label',
4097: 'crstitle' => 'Course title',
4098: 'crslinktext' => 'Link Text',
4099: 'crsexplanation' => 'Explanation',
4100: );
4101:
4102: return %lt;
4103: }
4104:
4105: sub print_coursedefaults {
4106: my ($position,$dom,$settings,$rowtotal) = @_;
4107: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
4108: my $itemcount = 1;
4109: my %choices = &Apache::lonlocal::texthash (
4110: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
4111: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
4112: coursecredits => 'Credits can be specified for courses',
4113: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
4114: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
4115: postsubmit => 'Disable submit button/keypress following student submission',
4116: canclone => "People who may clone a course (besides course's owner and coordinators)",
4117: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
4118: );
4119: my %staticdefaults = (
4120: anonsurvey_threshold => 10,
4121: uploadquota => 500,
4122: postsubmit => 60,
4123: mysqltables => 172800,
4124: );
4125: if ($position eq 'top') {
4126: %defaultchecked = (
4127: 'uselcmath' => 'on',
4128: 'usejsme' => 'on',
4129: 'canclone' => 'none',
4130: );
4131: @toggles = ('uselcmath','usejsme');
4132: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4133: \%choices,$itemcount);
4134: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4135: $datatable .=
4136: '<tr'.$css_class.'><td valign="top">'.
4137: '<span class="LC_nobreak">'.$choices{'canclone'}.
4138: '</span></td><td class="LC_left_item">';
4139: my $currcanclone = 'none';
4140: my $onclick;
4141: my @cloneoptions = ('none','domain');
4142: my %clonetitles = (
4143: none => 'No additional course requesters',
4144: domain => "Any course requester in course's domain",
4145: instcode => 'Course requests for official courses ...',
4146: );
4147: my (%codedefaults,@code_order,@posscodes);
4148: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
4149: \@code_order) eq 'ok') {
4150: if (@code_order > 0) {
4151: push(@cloneoptions,'instcode');
4152: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
4153: }
4154: }
4155: if (ref($settings) eq 'HASH') {
4156: if ($settings->{'canclone'}) {
4157: if (ref($settings->{'canclone'}) eq 'HASH') {
4158: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
4159: if (@code_order > 0) {
4160: $currcanclone = 'instcode';
4161: @posscodes = @{$settings->{'canclone'}{'instcode'}};
4162: }
4163: }
4164: } elsif ($settings->{'canclone'} eq 'domain') {
4165: $currcanclone = $settings->{'canclone'};
4166: }
4167: }
4168: }
4169: foreach my $option (@cloneoptions) {
4170: my ($checked,$additional);
4171: if ($currcanclone eq $option) {
4172: $checked = ' checked="checked"';
4173: }
4174: if ($option eq 'instcode') {
4175: if (@code_order) {
4176: my $show = 'none';
4177: if ($checked) {
4178: $show = 'block';
4179: }
4180: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
4181: &mt('Institutional codes for new and cloned course have identical:').
4182: '<br />';
4183: foreach my $item (@code_order) {
4184: my $codechk;
4185: if ($checked) {
4186: if (grep(/^\Q$item\E$/,@posscodes)) {
4187: $codechk = ' checked="checked"';
4188: }
4189: }
4190: $additional .= '<label>'.
4191: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
4192: $item.'</label>';
4193: }
4194: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
4195: }
4196: }
4197: $datatable .=
4198: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
4199: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
4200: '</label> '.$additional.'</span><br />';
4201: }
4202: $datatable .= '</td>'.
4203: '</tr>';
4204: $itemcount ++;
4205: } else {
4206: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4207: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
4208: my $currusecredits = 0;
4209: my $postsubmitclient = 1;
4210: my @types = ('official','unofficial','community','textbook');
4211: if (ref($settings) eq 'HASH') {
4212: $currdefresponder = $settings->{'anonsurvey_threshold'};
4213: if (ref($settings->{'uploadquota'}) eq 'HASH') {
4214: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
4215: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
4216: }
4217: }
4218: if (ref($settings->{'coursecredits'}) eq 'HASH') {
4219: foreach my $type (@types) {
4220: next if ($type eq 'community');
4221: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
4222: if ($defcredits{$type} ne '') {
4223: $currusecredits = 1;
4224: }
4225: }
4226: }
4227: if (ref($settings->{'postsubmit'}) eq 'HASH') {
4228: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
4229: $postsubmitclient = 0;
4230: foreach my $type (@types) {
4231: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4232: }
4233: } else {
4234: foreach my $type (@types) {
4235: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
4236: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
4237: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
4238: } else {
4239: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4240: }
4241: } else {
4242: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4243: }
4244: }
4245: }
4246: } else {
4247: foreach my $type (@types) {
4248: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4249: }
4250: }
4251: if (ref($settings->{'mysqltables'}) eq 'HASH') {
4252: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
4253: $currmysql{$type} = $settings->{'mysqltables'}{$type};
4254: }
4255: } else {
4256: foreach my $type (@types) {
4257: $currmysql{$type} = $staticdefaults{'mysqltables'};
4258: }
4259: }
4260: } else {
4261: foreach my $type (@types) {
4262: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4263: }
4264: }
4265: if (!$currdefresponder) {
4266: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
4267: } elsif ($currdefresponder < 1) {
4268: $currdefresponder = 1;
4269: }
4270: foreach my $type (@types) {
4271: if ($curruploadquota{$type} eq '') {
4272: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
4273: }
4274: }
4275: $datatable .=
4276: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4277: $choices{'anonsurvey_threshold'}.
4278: '</span></td>'.
4279: '<td class="LC_right_item"><span class="LC_nobreak">'.
4280: '<input type="text" name="anonsurvey_threshold"'.
4281: ' value="'.$currdefresponder.'" size="5" /></span>'.
4282: '</td></tr>'."\n";
4283: $itemcount ++;
4284: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4285: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4286: $choices{'uploadquota'}.
4287: '</span></td>'.
4288: '<td align="right" class="LC_right_item">'.
4289: '<table><tr>';
4290: foreach my $type (@types) {
4291: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4292: '<input type="text" name="uploadquota_'.$type.'"'.
4293: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
4294: }
4295: $datatable .= '</tr></table></td></tr>'."\n";
4296: $itemcount ++;
4297: my $onclick = "toggleDisplay(this.form,'credits');";
4298: my $display = 'none';
4299: if ($currusecredits) {
4300: $display = 'block';
4301: }
4302: my $additional = '<div id="credits" style="display: '.$display.'">'.
4303: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
4304: foreach my $type (@types) {
4305: next if ($type eq 'community');
4306: $additional .= '<td align="center">'.&mt($type).'<br />'.
4307: '<input type="text" name="'.$type.'_credits"'.
4308: ' value="'.$defcredits{$type}.'" size="3" /></td>';
4309: }
4310: $additional .= '</tr></table></div>'."\n";
4311: %defaultchecked = ('coursecredits' => 'off');
4312: @toggles = ('coursecredits');
4313: my $current = {
4314: 'coursecredits' => $currusecredits,
4315: };
4316: (my $table,$itemcount) =
4317: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
4318: \%choices,$itemcount,$onclick,$additional,'left');
4319: $datatable .= $table;
4320: $onclick = "toggleDisplay(this.form,'studentsubmission');";
4321: my $display = 'none';
4322: if ($postsubmitclient) {
4323: $display = 'block';
4324: }
4325: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
4326: &mt('Number of seconds submit is disabled').'<br />'.
4327: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
4328: '<table><tr>';
4329: foreach my $type (@types) {
4330: $additional .= '<td align="center">'.&mt($type).'<br />'.
4331: '<input type="text" name="'.$type.'_timeout" value="'.
4332: $deftimeout{$type}.'" size="5" /></td>';
4333: }
4334: $additional .= '</tr></table></div>'."\n";
4335: %defaultchecked = ('postsubmit' => 'on');
4336: @toggles = ('postsubmit');
4337: $current = {
4338: 'postsubmit' => $postsubmitclient,
4339: };
4340: ($table,$itemcount) =
4341: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
4342: \%choices,$itemcount,$onclick,$additional,'left');
4343: $datatable .= $table;
4344: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4345: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4346: $choices{'mysqltables'}.
4347: '</span></td>'.
4348: '<td align="right" class="LC_right_item">'.
4349: '<table><tr>';
4350: foreach my $type (@types) {
4351: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4352: '<input type="text" name="mysqltables_'.$type.'"'.
4353: ' value="'.$currmysql{$type}.'" size="8" /></td>';
4354: }
4355: $datatable .= '</tr></table></td></tr>'."\n";
4356: $itemcount ++;
4357:
4358: }
4359: $$rowtotal += $itemcount;
4360: return $datatable;
4361: }
4362:
4363: sub print_selfenrollment {
4364: my ($position,$dom,$settings,$rowtotal) = @_;
4365: my ($css_class,$datatable);
4366: my $itemcount = 1;
4367: my @types = ('official','unofficial','community','textbook');
4368: if (($position eq 'top') || ($position eq 'middle')) {
4369: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
4370: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
4371: my @rows;
4372: my $key;
4373: if ($position eq 'top') {
4374: $key = 'admin';
4375: if (ref($rowsref) eq 'ARRAY') {
4376: @rows = @{$rowsref};
4377: }
4378: } elsif ($position eq 'middle') {
4379: $key = 'default';
4380: @rows = ('types','registered','approval','limit');
4381: }
4382: foreach my $row (@rows) {
4383: if (defined($titlesref->{$row})) {
4384: $itemcount ++;
4385: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4386: $datatable .= '<tr'.$css_class.'>'.
4387: '<td>'.$titlesref->{$row}.'</td>'.
4388: '<td class="LC_left_item">'.
4389: '<table><tr>';
4390: my (%current,%currentcap);
4391: if (ref($settings) eq 'HASH') {
4392: if (ref($settings->{$key}) eq 'HASH') {
4393: foreach my $type (@types) {
4394: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4395: $current{$type} = $settings->{$key}->{$type}->{$row};
4396: }
4397: if (($row eq 'limit') && ($key eq 'default')) {
4398: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4399: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
4400: }
4401: }
4402: }
4403: }
4404: }
4405: my %roles = (
4406: '0' => &Apache::lonnet::plaintext('dc'),
4407: );
4408:
4409: foreach my $type (@types) {
4410: unless (($row eq 'registered') && ($key eq 'default')) {
4411: $datatable .= '<th>'.&mt($type).'</th>';
4412: }
4413: }
4414: unless (($row eq 'registered') && ($key eq 'default')) {
4415: $datatable .= '</tr><tr>';
4416: }
4417: foreach my $type (@types) {
4418: if ($type eq 'community') {
4419: $roles{'1'} = &mt('Community personnel');
4420: } else {
4421: $roles{'1'} = &mt('Course personnel');
4422: }
4423: $datatable .= '<td style="vertical-align: top">';
4424: if ($position eq 'top') {
4425: my %checked;
4426: if ($current{$type} eq '0') {
4427: $checked{'0'} = ' checked="checked"';
4428: } else {
4429: $checked{'1'} = ' checked="checked"';
4430: }
4431: foreach my $role ('1','0') {
4432: $datatable .= '<span class="LC_nobreak"><label>'.
4433: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
4434: 'value="'.$role.'"'.$checked{$role}.' />'.
4435: $roles{$role}.'</label></span> ';
4436: }
4437: } else {
4438: if ($row eq 'types') {
4439: my %checked;
4440: if ($current{$type} =~ /^(all|dom)$/) {
4441: $checked{$1} = ' checked="checked"';
4442: } else {
4443: $checked{''} = ' checked="checked"';
4444: }
4445: foreach my $val ('','dom','all') {
4446: $datatable .= '<span class="LC_nobreak"><label>'.
4447: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4448: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4449: }
4450: } elsif ($row eq 'registered') {
4451: my %checked;
4452: if ($current{$type} eq '1') {
4453: $checked{'1'} = ' checked="checked"';
4454: } else {
4455: $checked{'0'} = ' checked="checked"';
4456: }
4457: foreach my $val ('0','1') {
4458: $datatable .= '<span class="LC_nobreak"><label>'.
4459: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4460: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4461: }
4462: } elsif ($row eq 'approval') {
4463: my %checked;
4464: if ($current{$type} =~ /^([12])$/) {
4465: $checked{$1} = ' checked="checked"';
4466: } else {
4467: $checked{'0'} = ' checked="checked"';
4468: }
4469: for my $val (0..2) {
4470: $datatable .= '<span class="LC_nobreak"><label>'.
4471: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4472: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4473: }
4474: } elsif ($row eq 'limit') {
4475: my %checked;
4476: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
4477: $checked{$1} = ' checked="checked"';
4478: } else {
4479: $checked{'none'} = ' checked="checked"';
4480: }
4481: my $cap;
4482: if ($currentcap{$type} =~ /^\d+$/) {
4483: $cap = $currentcap{$type};
4484: }
4485: foreach my $val ('none','allstudents','selfenrolled') {
4486: $datatable .= '<span class="LC_nobreak"><label>'.
4487: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4488: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4489: }
4490: $datatable .= '<br />'.
4491: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
4492: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
4493: '</span>';
4494: }
4495: }
4496: $datatable .= '</td>';
4497: }
4498: $datatable .= '</tr>';
4499: }
4500: $datatable .= '</table></td></tr>';
4501: }
4502: } elsif ($position eq 'bottom') {
4503: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
4504: }
4505: $$rowtotal += $itemcount;
4506: return $datatable;
4507: }
4508:
4509: sub print_validation_rows {
4510: my ($caller,$dom,$settings,$rowtotal) = @_;
4511: my ($itemsref,$namesref,$fieldsref);
4512: if ($caller eq 'selfenroll') {
4513: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
4514: } elsif ($caller eq 'requestcourses') {
4515: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
4516: }
4517: my %currvalidation;
4518: if (ref($settings) eq 'HASH') {
4519: if (ref($settings->{'validation'}) eq 'HASH') {
4520: %currvalidation = %{$settings->{'validation'}};
4521: }
4522: }
4523: my $datatable;
4524: my $itemcount = 0;
4525: foreach my $item (@{$itemsref}) {
4526: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4527: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4528: $namesref->{$item}.
4529: '</span></td>'.
4530: '<td class="LC_left_item">';
4531: if (($item eq 'url') || ($item eq 'button')) {
4532: $datatable .= '<span class="LC_nobreak">'.
4533: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
4534: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
4535: } elsif ($item eq 'fields') {
4536: my @currfields;
4537: if (ref($currvalidation{$item}) eq 'ARRAY') {
4538: @currfields = @{$currvalidation{$item}};
4539: }
4540: foreach my $field (@{$fieldsref}) {
4541: my $check = '';
4542: if (grep(/^\Q$field\E$/,@currfields)) {
4543: $check = ' checked="checked"';
4544: }
4545: $datatable .= '<span class="LC_nobreak"><label>'.
4546: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
4547: ' value="'.$field.'"'.$check.' />'.$field.
4548: '</label></span> ';
4549: }
4550: } elsif ($item eq 'markup') {
4551: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
4552: $currvalidation{$item}.
4553: '</textarea>';
4554: }
4555: $datatable .= '</td></tr>'."\n";
4556: if (ref($rowtotal)) {
4557: $itemcount ++;
4558: }
4559: }
4560: if ($caller eq 'requestcourses') {
4561: my %currhash;
4562: if (ref($settings) eq 'HASH') {
4563: if (ref($settings->{'validation'}) eq 'HASH') {
4564: if ($settings->{'validation'}{'dc'} ne '') {
4565: $currhash{$settings->{'validation'}{'dc'}} = 1;
4566: }
4567: }
4568: }
4569: my $numinrow = 2;
4570: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4571: 'validationdc',%currhash);
4572: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4573: $datatable .= '</td></tr><tr'.$css_class.'><td>';
4574: if ($numdc > 1) {
4575: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
4576: } else {
4577: $datatable .= &mt('Course creation processed as: ');
4578: }
4579: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
4580: $itemcount ++;
4581: }
4582: if (ref($rowtotal)) {
4583: $$rowtotal += $itemcount;
4584: }
4585: return $datatable;
4586: }
4587:
4588: sub print_usersessions {
4589: my ($position,$dom,$settings,$rowtotal) = @_;
4590: my ($css_class,$datatable,%checked,%choices);
4591: my (%by_ip,%by_location,@intdoms);
4592: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
4593:
4594: my @alldoms = &Apache::lonnet::all_domains();
4595: my %serverhomes = %Apache::lonnet::serverhomeIDs;
4596: my %servers = &Apache::lonnet::internet_dom_servers($dom);
4597: my %altids = &id_for_thisdom(%servers);
4598: my $itemcount = 1;
4599: if ($position eq 'top') {
4600: if (keys(%serverhomes) > 1) {
4601: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
4602: my $curroffloadnow;
4603: if (ref($settings) eq 'HASH') {
4604: if (ref($settings->{'offloadnow'}) eq 'HASH') {
4605: $curroffloadnow = $settings->{'offloadnow'};
4606: }
4607: }
4608: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
4609: } else {
4610: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
4611: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
4612: }
4613: } else {
4614: if (keys(%by_location) == 0) {
4615: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
4616: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
4617: } else {
4618: my %lt = &usersession_titles();
4619: my $numinrow = 5;
4620: my $prefix;
4621: my @types;
4622: if ($position eq 'bottom') {
4623: $prefix = 'remote';
4624: @types = ('version','excludedomain','includedomain');
4625: } else {
4626: $prefix = 'hosted';
4627: @types = ('excludedomain','includedomain');
4628: }
4629: my (%current,%checkedon,%checkedoff);
4630: my @lcversions = &Apache::lonnet::all_loncaparevs();
4631: my @locations = sort(keys(%by_location));
4632: foreach my $type (@types) {
4633: $checkedon{$type} = '';
4634: $checkedoff{$type} = ' checked="checked"';
4635: }
4636: if (ref($settings) eq 'HASH') {
4637: if (ref($settings->{$prefix}) eq 'HASH') {
4638: foreach my $key (keys(%{$settings->{$prefix}})) {
4639: $current{$key} = $settings->{$prefix}{$key};
4640: if ($key eq 'version') {
4641: if ($current{$key} ne '') {
4642: $checkedon{$key} = ' checked="checked"';
4643: $checkedoff{$key} = '';
4644: }
4645: } elsif (ref($current{$key}) eq 'ARRAY') {
4646: $checkedon{$key} = ' checked="checked"';
4647: $checkedoff{$key} = '';
4648: }
4649: }
4650: }
4651: }
4652: foreach my $type (@types) {
4653: next if ($type ne 'version' && !@locations);
4654: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4655: $datatable .= '<tr'.$css_class.'>
4656: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
4657: <span class="LC_nobreak">
4658: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
4659: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
4660: if ($type eq 'version') {
4661: my $selector = '<select name="'.$prefix.'_version">';
4662: foreach my $version (@lcversions) {
4663: my $selected = '';
4664: if ($current{'version'} eq $version) {
4665: $selected = ' selected="selected"';
4666: }
4667: $selector .= ' <option value="'.$version.'"'.
4668: $selected.'>'.$version.'</option>';
4669: }
4670: $selector .= '</select> ';
4671: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
4672: } else {
4673: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
4674: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
4675: ' />'.(' 'x2).
4676: '<input type="button" value="'.&mt('uncheck all').'" '.
4677: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
4678: "\n".
4679: '</div><div><table>';
4680: my $rem;
4681: for (my $i=0; $i<@locations; $i++) {
4682: my ($showloc,$value,$checkedtype);
4683: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
4684: my $ip = $by_location{$locations[$i]}->[0];
4685: if (ref($by_ip{$ip}) eq 'ARRAY') {
4686: $value = join(':',@{$by_ip{$ip}});
4687: $showloc = join(', ',@{$by_ip{$ip}});
4688: if (ref($current{$type}) eq 'ARRAY') {
4689: foreach my $loc (@{$by_ip{$ip}}) {
4690: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
4691: $checkedtype = ' checked="checked"';
4692: last;
4693: }
4694: }
4695: }
4696: }
4697: }
4698: $rem = $i%($numinrow);
4699: if ($rem == 0) {
4700: if ($i > 0) {
4701: $datatable .= '</tr>';
4702: }
4703: $datatable .= '<tr>';
4704: }
4705: $datatable .= '<td class="LC_left_item">'.
4706: '<span class="LC_nobreak"><label>'.
4707: '<input type="checkbox" name="'.$prefix.'_'.$type.
4708: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
4709: '</label></span></td>';
4710: }
4711: $rem = @locations%($numinrow);
4712: my $colsleft = $numinrow - $rem;
4713: if ($colsleft > 1 ) {
4714: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4715: ' </td>';
4716: } elsif ($colsleft == 1) {
4717: $datatable .= '<td class="LC_left_item"> </td>';
4718: }
4719: $datatable .= '</tr></table>';
4720: }
4721: $datatable .= '</td></tr>';
4722: $itemcount ++;
4723: }
4724: }
4725: }
4726: $$rowtotal += $itemcount;
4727: return $datatable;
4728: }
4729:
4730: sub build_location_hashes {
4731: my ($intdoms,$by_ip,$by_location) = @_;
4732: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
4733: (ref($by_location) eq 'HASH'));
4734: my %iphost = &Apache::lonnet::get_iphost();
4735: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
4736: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
4737: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
4738: foreach my $id (@{$iphost{$primary_ip}}) {
4739: my $intdom = &Apache::lonnet::internet_dom($id);
4740: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
4741: push(@{$intdoms},$intdom);
4742: }
4743: }
4744: }
4745: foreach my $ip (keys(%iphost)) {
4746: if (ref($iphost{$ip}) eq 'ARRAY') {
4747: foreach my $id (@{$iphost{$ip}}) {
4748: my $location = &Apache::lonnet::internet_dom($id);
4749: if ($location) {
4750: next if (grep(/^\Q$location\E$/,@{$intdoms}));
4751: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4752: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
4753: push(@{$by_ip->{$ip}},$location);
4754: }
4755: } else {
4756: $by_ip->{$ip} = [$location];
4757: }
4758: }
4759: }
4760: }
4761: }
4762: foreach my $ip (sort(keys(%{$by_ip}))) {
4763: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4764: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
4765: my $first = $by_ip->{$ip}->[0];
4766: if (ref($by_location->{$first}) eq 'ARRAY') {
4767: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
4768: push(@{$by_location->{$first}},$ip);
4769: }
4770: } else {
4771: $by_location->{$first} = [$ip];
4772: }
4773: }
4774: }
4775: return;
4776: }
4777:
4778: sub current_offloads_to {
4779: my ($dom,$settings,$servers) = @_;
4780: my (%spareid,%otherdomconfigs);
4781: if (ref($servers) eq 'HASH') {
4782: foreach my $lonhost (sort(keys(%{$servers}))) {
4783: my $gotspares;
4784: if (ref($settings) eq 'HASH') {
4785: if (ref($settings->{'spares'}) eq 'HASH') {
4786: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
4787: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
4788: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
4789: $gotspares = 1;
4790: }
4791: }
4792: }
4793: unless ($gotspares) {
4794: my $gotspares;
4795: my $serverhomeID =
4796: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
4797: my $serverhomedom =
4798: &Apache::lonnet::host_domain($serverhomeID);
4799: if ($serverhomedom ne $dom) {
4800: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
4801: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4802: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4803: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4804: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4805: $gotspares = 1;
4806: }
4807: }
4808: } else {
4809: $otherdomconfigs{$serverhomedom} =
4810: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
4811: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
4812: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4813: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4814: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
4815: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4816: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4817: $gotspares = 1;
4818: }
4819: }
4820: }
4821: }
4822: }
4823: }
4824: }
4825: unless ($gotspares) {
4826: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
4827: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4828: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4829: } else {
4830: my $server_hostname = &Apache::lonnet::hostname($lonhost);
4831: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
4832: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
4833: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4834: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4835: } else {
4836: my %what = (
4837: spareid => 1,
4838: );
4839: my ($result,$returnhash) =
4840: &Apache::lonnet::get_remote_globals($lonhost,\%what);
4841: if ($result eq 'ok') {
4842: if (ref($returnhash) eq 'HASH') {
4843: if (ref($returnhash->{'spareid'}) eq 'HASH') {
4844: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
4845: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
4846: }
4847: }
4848: }
4849: }
4850: }
4851: }
4852: }
4853: }
4854: return %spareid;
4855: }
4856:
4857: sub spares_row {
4858: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
4859: my $css_class;
4860: my $numinrow = 4;
4861: my $itemcount = 1;
4862: my $datatable;
4863: my %typetitles = &sparestype_titles();
4864: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
4865: foreach my $server (sort(keys(%{$servers}))) {
4866: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
4867: my ($othercontrol,$serverdom);
4868: if ($serverhome ne $server) {
4869: $serverdom = &Apache::lonnet::host_domain($serverhome);
4870: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4871: } else {
4872: $serverdom = &Apache::lonnet::host_domain($server);
4873: if ($serverdom ne $dom) {
4874: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4875: }
4876: }
4877: next unless (ref($spareid->{$server}) eq 'HASH');
4878: my $checkednow;
4879: if (ref($curroffloadnow) eq 'HASH') {
4880: if ($curroffloadnow->{$server}) {
4881: $checkednow = ' checked="checked"';
4882: }
4883: }
4884: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4885: $datatable .= '<tr'.$css_class.'>
4886: <td rowspan="2">
4887: <span class="LC_nobreak">'.
4888: &mt('[_1] when busy, offloads to:'
4889: ,'<b>'.$server.'</b>').'</span><br />'.
4890: '<span class="LC_nobreak">'."\n".
4891: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
4892: ' '.&mt('Switch active users on next access').'</label></span>'.
4893: "\n";
4894: my (%current,%canselect);
4895: my @choices =
4896: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
4897: foreach my $type ('primary','default') {
4898: if (ref($spareid->{$server}) eq 'HASH') {
4899: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
4900: my @spares = @{$spareid->{$server}{$type}};
4901: if (@spares > 0) {
4902: if ($othercontrol) {
4903: $current{$type} = join(', ',@spares);
4904: } else {
4905: $current{$type} .= '<table>';
4906: my $numspares = scalar(@spares);
4907: for (my $i=0; $i<@spares; $i++) {
4908: my $rem = $i%($numinrow);
4909: if ($rem == 0) {
4910: if ($i > 0) {
4911: $current{$type} .= '</tr>';
4912: }
4913: $current{$type} .= '<tr>';
4914: }
4915: $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'".');" /> '.
4916: $spareid->{$server}{$type}[$i].
4917: '</label></td>'."\n";
4918: }
4919: my $rem = @spares%($numinrow);
4920: my $colsleft = $numinrow - $rem;
4921: if ($colsleft > 1 ) {
4922: $current{$type} .= '<td colspan="'.$colsleft.
4923: '" class="LC_left_item">'.
4924: ' </td>';
4925: } elsif ($colsleft == 1) {
4926: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
4927: }
4928: $current{$type} .= '</tr></table>';
4929: }
4930: }
4931: }
4932: if ($current{$type} eq '') {
4933: $current{$type} = &mt('None specified');
4934: }
4935: if ($othercontrol) {
4936: if ($type eq 'primary') {
4937: $canselect{$type} = $othercontrol;
4938: }
4939: } else {
4940: $canselect{$type} =
4941: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
4942: '<select name="newspare_'.$type.'_'.$server.'" '.
4943: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
4944: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
4945: if (@choices > 0) {
4946: foreach my $lonhost (@choices) {
4947: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
4948: }
4949: }
4950: $canselect{$type} .= '</select>'."\n";
4951: }
4952: } else {
4953: $current{$type} = &mt('Could not be determined');
4954: if ($type eq 'primary') {
4955: $canselect{$type} = $othercontrol;
4956: }
4957: }
4958: if ($type eq 'default') {
4959: $datatable .= '<tr'.$css_class.'>';
4960: }
4961: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
4962: '<td>'.$current{$type}.'</td>'."\n".
4963: '<td>'.$canselect{$type}.'</td></tr>'."\n";
4964: }
4965: $itemcount ++;
4966: }
4967: }
4968: $$rowtotal += $itemcount;
4969: return $datatable;
4970: }
4971:
4972: sub possible_newspares {
4973: my ($server,$currspares,$serverhomes,$altids) = @_;
4974: my $serverhostname = &Apache::lonnet::hostname($server);
4975: my %excluded;
4976: if ($serverhostname ne '') {
4977: %excluded = (
4978: $serverhostname => 1,
4979: );
4980: }
4981: if (ref($currspares) eq 'HASH') {
4982: foreach my $type (keys(%{$currspares})) {
4983: if (ref($currspares->{$type}) eq 'ARRAY') {
4984: if (@{$currspares->{$type}} > 0) {
4985: foreach my $curr (@{$currspares->{$type}}) {
4986: my $hostname = &Apache::lonnet::hostname($curr);
4987: $excluded{$hostname} = 1;
4988: }
4989: }
4990: }
4991: }
4992: }
4993: my @choices;
4994: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
4995: if (keys(%{$serverhomes}) > 1) {
4996: foreach my $name (sort(keys(%{$serverhomes}))) {
4997: unless ($excluded{$name}) {
4998: if (exists($altids->{$serverhomes->{$name}})) {
4999: push(@choices,$altids->{$serverhomes->{$name}});
5000: } else {
5001: push(@choices,$serverhomes->{$name});
5002: }
5003: }
5004: }
5005: }
5006: }
5007: return sort(@choices);
5008: }
5009:
5010: sub print_loadbalancing {
5011: my ($dom,$settings,$rowtotal) = @_;
5012: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5013: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5014: my $numinrow = 1;
5015: my $datatable;
5016: my %servers = &Apache::lonnet::internet_dom_servers($dom);
5017: my (%currbalancer,%currtargets,%currrules,%existing);
5018: if (ref($settings) eq 'HASH') {
5019: %existing = %{$settings};
5020: }
5021: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
5022: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
5023: \%currtargets,\%currrules);
5024: } else {
5025: return;
5026: }
5027: my ($othertitle,$usertypes,$types) =
5028: &Apache::loncommon::sorted_inst_types($dom);
5029: my $rownum = 8;
5030: if (ref($types) eq 'ARRAY') {
5031: $rownum += scalar(@{$types});
5032: }
5033: my @css_class = ('LC_odd_row','LC_even_row');
5034: my $balnum = 0;
5035: my $islast;
5036: my (@toshow,$disabledtext);
5037: if (keys(%currbalancer) > 0) {
5038: @toshow = sort(keys(%currbalancer));
5039: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
5040: push(@toshow,'');
5041: }
5042: } else {
5043: @toshow = ('');
5044: $disabledtext = &mt('No existing load balancer');
5045: }
5046: foreach my $lonhost (@toshow) {
5047: if ($balnum == scalar(@toshow)-1) {
5048: $islast = 1;
5049: } else {
5050: $islast = 0;
5051: }
5052: my $cssidx = $balnum%2;
5053: my $targets_div_style = 'display: none';
5054: my $disabled_div_style = 'display: block';
5055: my $homedom_div_style = 'display: none';
5056: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
5057: '<td rowspan="'.$rownum.'" valign="top">'.
5058: '<p>';
5059: if ($lonhost eq '') {
5060: $datatable .= '<span class="LC_nobreak">';
5061: if (keys(%currbalancer) > 0) {
5062: $datatable .= &mt('Add balancer:');
5063: } else {
5064: $datatable .= &mt('Enable balancer:');
5065: }
5066: $datatable .= ' '.
5067: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
5068: ' id="loadbalancing_lonhost_'.$balnum.'"'.
5069: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
5070: '<option value="" selected="selected">'.&mt('None').
5071: '</option>'."\n";
5072: foreach my $server (sort(keys(%servers))) {
5073: next if ($currbalancer{$server});
5074: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
5075: }
5076: $datatable .=
5077: '</select>'."\n".
5078: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
5079: } else {
5080: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
5081: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
5082: &mt('Stop balancing').'</label>'.
5083: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
5084: $targets_div_style = 'display: block';
5085: $disabled_div_style = 'display: none';
5086: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
5087: $homedom_div_style = 'display: block';
5088: }
5089: }
5090: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
5091: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
5092: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
5093: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
5094: my ($numspares,@spares) = &count_servers($lonhost,%servers);
5095: my @sparestypes = ('primary','default');
5096: my %typetitles = &sparestype_titles();
5097: my %hostherechecked = (
5098: no => ' checked="checked"',
5099: );
5100: foreach my $sparetype (@sparestypes) {
5101: my $targettable;
5102: for (my $i=0; $i<$numspares; $i++) {
5103: my $checked;
5104: if (ref($currtargets{$lonhost}) eq 'HASH') {
5105: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5106: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5107: $checked = ' checked="checked"';
5108: }
5109: }
5110: }
5111: my ($chkboxval,$disabled);
5112: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
5113: $chkboxval = $spares[$i];
5114: }
5115: if (exists($currbalancer{$spares[$i]})) {
5116: $disabled = ' disabled="disabled"';
5117: }
5118: $targettable .=
5119: '<td><span class="LC_nobreak"><label>'.
5120: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
5121: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
5122: '</span></label></span></td>';
5123: my $rem = $i%($numinrow);
5124: if ($rem == 0) {
5125: if (($i > 0) && ($i < $numspares-1)) {
5126: $targettable .= '</tr>';
5127: }
5128: if ($i < $numspares-1) {
5129: $targettable .= '<tr>';
5130: }
5131: }
5132: }
5133: if ($targettable ne '') {
5134: my $rem = $numspares%($numinrow);
5135: my $colsleft = $numinrow - $rem;
5136: if ($colsleft > 1 ) {
5137: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5138: ' </td>';
5139: } elsif ($colsleft == 1) {
5140: $targettable .= '<td class="LC_left_item"> </td>';
5141: }
5142: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
5143: '<table><tr>'.$targettable.'</tr></table><br />';
5144: }
5145: $hostherechecked{$sparetype} = '';
5146: if (ref($currtargets{$lonhost}) eq 'HASH') {
5147: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5148: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5149: $hostherechecked{$sparetype} = ' checked="checked"';
5150: $hostherechecked{'no'} = '';
5151: }
5152: }
5153: }
5154: }
5155: $datatable .= &mt('Hosting on balancer itself').'<br />'.
5156: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
5157: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
5158: foreach my $sparetype (@sparestypes) {
5159: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
5160: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
5161: '</i></label><br />';
5162: }
5163: $datatable .= '</div></td></tr>'.
5164: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
5165: $othertitle,$usertypes,$types,\%servers,
5166: \%currbalancer,$lonhost,
5167: $targets_div_style,$homedom_div_style,
5168: $css_class[$cssidx],$balnum,$islast);
5169: $$rowtotal += $rownum;
5170: $balnum ++;
5171: }
5172: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
5173: return $datatable;
5174: }
5175:
5176: sub get_loadbalancers_config {
5177: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
5178: return unless ((ref($servers) eq 'HASH') &&
5179: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
5180: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
5181: if (keys(%{$existing}) > 0) {
5182: my $oldlonhost;
5183: foreach my $key (sort(keys(%{$existing}))) {
5184: if ($key eq 'lonhost') {
5185: $oldlonhost = $existing->{'lonhost'};
5186: $currbalancer->{$oldlonhost} = 1;
5187: } elsif ($key eq 'targets') {
5188: if ($oldlonhost) {
5189: $currtargets->{$oldlonhost} = $existing->{'targets'};
5190: }
5191: } elsif ($key eq 'rules') {
5192: if ($oldlonhost) {
5193: $currrules->{$oldlonhost} = $existing->{'rules'};
5194: }
5195: } elsif (ref($existing->{$key}) eq 'HASH') {
5196: $currbalancer->{$key} = 1;
5197: $currtargets->{$key} = $existing->{$key}{'targets'};
5198: $currrules->{$key} = $existing->{$key}{'rules'};
5199: }
5200: }
5201: } else {
5202: my ($balancerref,$targetsref) =
5203: &Apache::lonnet::get_lonbalancer_config($servers);
5204: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
5205: foreach my $server (sort(keys(%{$balancerref}))) {
5206: $currbalancer->{$server} = 1;
5207: $currtargets->{$server} = $targetsref->{$server};
5208: }
5209: }
5210: }
5211: return;
5212: }
5213:
5214: sub loadbalancing_rules {
5215: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
5216: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
5217: $css_class,$balnum,$islast) = @_;
5218: my $output;
5219: my $num = 0;
5220: my ($alltypes,$othertypes,$titles) =
5221: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
5222: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
5223: foreach my $type (@{$alltypes}) {
5224: $num ++;
5225: my $current;
5226: if (ref($currrules) eq 'HASH') {
5227: $current = $currrules->{$type};
5228: }
5229: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
5230: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
5231: $current = '';
5232: }
5233: }
5234: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
5235: $servers,$currbalancer,$lonhost,$dom,
5236: $targets_div_style,$homedom_div_style,
5237: $css_class,$balnum,$num,$islast);
5238: }
5239: }
5240: return $output;
5241: }
5242:
5243: sub loadbalancing_titles {
5244: my ($dom,$intdom,$usertypes,$types) = @_;
5245: my %othertypes = (
5246: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
5247: '_LC_author' => &mt('Users from [_1] with author role',$dom),
5248: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
5249: '_LC_external' => &mt('Users not from [_1]',$intdom),
5250: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
5251: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
5252: );
5253: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
5254: my @available;
5255: if (ref($types) eq 'ARRAY') {
5256: @available = @{$types};
5257: }
5258: unless (grep(/^default$/,@available)) {
5259: push(@available,'default');
5260: }
5261: unshift(@alltypes,@available);
5262: my %titles;
5263: foreach my $type (@alltypes) {
5264: if ($type =~ /^_LC_/) {
5265: $titles{$type} = $othertypes{$type};
5266: } elsif ($type eq 'default') {
5267: $titles{$type} = &mt('All users from [_1]',$dom);
5268: if (ref($types) eq 'ARRAY') {
5269: if (@{$types} > 0) {
5270: $titles{$type} = &mt('Other users from [_1]',$dom);
5271: }
5272: }
5273: } elsif (ref($usertypes) eq 'HASH') {
5274: $titles{$type} = $usertypes->{$type};
5275: }
5276: }
5277: return (\@alltypes,\%othertypes,\%titles);
5278: }
5279:
5280: sub loadbalance_rule_row {
5281: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
5282: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
5283: my @rulenames;
5284: my %ruletitles = &offloadtype_text();
5285: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
5286: @rulenames = ('balancer','offloadedto','specific');
5287: } else {
5288: @rulenames = ('default','homeserver');
5289: if ($type eq '_LC_external') {
5290: push(@rulenames,'externalbalancer');
5291: } else {
5292: push(@rulenames,'specific');
5293: }
5294: push(@rulenames,'none');
5295: }
5296: my $style = $targets_div_style;
5297: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
5298: $style = $homedom_div_style;
5299: }
5300: my $space;
5301: if ($islast && $num == 1) {
5302: $space = '<div display="inline-block"> </div>';
5303: }
5304: my $output =
5305: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
5306: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
5307: '<td valaign="top">'.$space.
5308: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
5309: for (my $i=0; $i<@rulenames; $i++) {
5310: my $rule = $rulenames[$i];
5311: my ($checked,$extra);
5312: if ($rulenames[$i] eq 'default') {
5313: $rule = '';
5314: }
5315: if ($rulenames[$i] eq 'specific') {
5316: if (ref($servers) eq 'HASH') {
5317: my $default;
5318: if (($current ne '') && (exists($servers->{$current}))) {
5319: $checked = ' checked="checked"';
5320: }
5321: unless ($checked) {
5322: $default = ' selected="selected"';
5323: }
5324: $extra =
5325: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
5326: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
5327: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
5328: '<option value=""'.$default.'></option>'."\n";
5329: foreach my $server (sort(keys(%{$servers}))) {
5330: if (ref($currbalancer) eq 'HASH') {
5331: next if (exists($currbalancer->{$server}));
5332: }
5333: my $selected;
5334: if ($server eq $current) {
5335: $selected = ' selected="selected"';
5336: }
5337: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
5338: }
5339: $extra .= '</select>';
5340: }
5341: } elsif ($rule eq $current) {
5342: $checked = ' checked="checked"';
5343: }
5344: $output .= '<span class="LC_nobreak"><label>'.
5345: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
5346: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
5347: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
5348: ')"'.$checked.' /> ';
5349: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
5350: $output .= $ruletitles{'particular'};
5351: } else {
5352: $output .= $ruletitles{$rulenames[$i]};
5353: }
5354: $output .= '</label>'.$extra.'</span><br />'."\n";
5355: }
5356: $output .= '</div></td></tr>'."\n";
5357: return $output;
5358: }
5359:
5360: sub offloadtype_text {
5361: my %ruletitles = &Apache::lonlocal::texthash (
5362: 'default' => 'Offloads to default destinations',
5363: 'homeserver' => "Offloads to user's home server",
5364: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
5365: 'specific' => 'Offloads to specific server',
5366: 'none' => 'No offload',
5367: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
5368: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
5369: 'particular' => 'Session hosted (after re-auth) on server:',
5370: );
5371: return %ruletitles;
5372: }
5373:
5374: sub sparestype_titles {
5375: my %typestitles = &Apache::lonlocal::texthash (
5376: 'primary' => 'primary',
5377: 'default' => 'default',
5378: );
5379: return %typestitles;
5380: }
5381:
5382: sub contact_titles {
5383: my %titles = &Apache::lonlocal::texthash (
5384: 'supportemail' => 'Support E-mail address',
5385: 'adminemail' => 'Default Server Admin E-mail address',
5386: 'errormail' => 'Error reports to be e-mailed to',
5387: 'packagesmail' => 'Package update alerts to be e-mailed to',
5388: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
5389: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
5390: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
5391: 'requestsmail' => 'E-mail from course requests requiring approval',
5392: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
5393: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
5394: );
5395: my %short_titles = &Apache::lonlocal::texthash (
5396: adminemail => 'Admin E-mail address',
5397: supportemail => 'Support E-mail',
5398: );
5399: return (\%titles,\%short_titles);
5400: }
5401:
5402: sub helpform_fields {
5403: my %titles = &Apache::lonlocal::texthash (
5404: 'username' => 'Name',
5405: 'user' => 'Username/domain',
5406: 'phone' => 'Phone',
5407: 'cc' => 'Cc e-mail',
5408: 'course' => 'Course Details',
5409: 'section' => 'Sections',
5410: 'screenshot' => 'File upload',
5411: );
5412: my @fields = ('username','phone','user','course','section','cc','screenshot');
5413: my %possoptions = (
5414: username => ['yes','no','req'],
5415: phone => ['yes','no','req'],
5416: user => ['yes','no'],
5417: cc => ['yes','no'],
5418: course => ['yes','no'],
5419: section => ['yes','no'],
5420: screenshot => ['yes','no'],
5421: );
5422: my %fieldoptions = &Apache::lonlocal::texthash (
5423: 'yes' => 'Optional',
5424: 'req' => 'Required',
5425: 'no' => "Not shown",
5426: );
5427: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
5428: }
5429:
5430: sub tool_titles {
5431: my %titles = &Apache::lonlocal::texthash (
5432: aboutme => 'Personal web page',
5433: blog => 'Blog',
5434: webdav => 'WebDAV',
5435: portfolio => 'Portfolio',
5436: official => 'Official courses (with institutional codes)',
5437: unofficial => 'Unofficial courses',
5438: community => 'Communities',
5439: textbook => 'Textbook courses',
5440: );
5441: return %titles;
5442: }
5443:
5444: sub courserequest_titles {
5445: my %titles = &Apache::lonlocal::texthash (
5446: official => 'Official',
5447: unofficial => 'Unofficial',
5448: community => 'Communities',
5449: textbook => 'Textbook',
5450: norequest => 'Not allowed',
5451: approval => 'Approval by Dom. Coord.',
5452: validate => 'With validation',
5453: autolimit => 'Numerical limit',
5454: unlimited => '(blank for unlimited)',
5455: );
5456: return %titles;
5457: }
5458:
5459: sub authorrequest_titles {
5460: my %titles = &Apache::lonlocal::texthash (
5461: norequest => 'Not allowed',
5462: approval => 'Approval by Dom. Coord.',
5463: automatic => 'Automatic approval',
5464: );
5465: return %titles;
5466: }
5467:
5468: sub courserequest_conditions {
5469: my %conditions = &Apache::lonlocal::texthash (
5470: approval => '(Processing of request subject to approval by Domain Coordinator).',
5471: validate => '(Processing of request subject to institutional validation).',
5472: );
5473: return %conditions;
5474: }
5475:
5476:
5477: sub print_usercreation {
5478: my ($position,$dom,$settings,$rowtotal) = @_;
5479: my $numinrow = 4;
5480: my $datatable;
5481: if ($position eq 'top') {
5482: $$rowtotal ++;
5483: my $rowcount = 0;
5484: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
5485: if (ref($rules) eq 'HASH') {
5486: if (keys(%{$rules}) > 0) {
5487: $datatable .= &user_formats_row('username',$settings,$rules,
5488: $ruleorder,$numinrow,$rowcount);
5489: $$rowtotal ++;
5490: $rowcount ++;
5491: }
5492: }
5493: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
5494: if (ref($idrules) eq 'HASH') {
5495: if (keys(%{$idrules}) > 0) {
5496: $datatable .= &user_formats_row('id',$settings,$idrules,
5497: $idruleorder,$numinrow,$rowcount);
5498: $$rowtotal ++;
5499: $rowcount ++;
5500: }
5501: }
5502: if ($rowcount == 0) {
5503: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
5504: $$rowtotal ++;
5505: $rowcount ++;
5506: }
5507: } elsif ($position eq 'middle') {
5508: my @creators = ('author','course','requestcrs');
5509: my ($rules,$ruleorder) =
5510: &Apache::lonnet::inst_userrules($dom,'username');
5511: my %lt = &usercreation_types();
5512: my %checked;
5513: if (ref($settings) eq 'HASH') {
5514: if (ref($settings->{'cancreate'}) eq 'HASH') {
5515: foreach my $item (@creators) {
5516: $checked{$item} = $settings->{'cancreate'}{$item};
5517: }
5518: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
5519: foreach my $item (@creators) {
5520: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
5521: $checked{$item} = 'none';
5522: }
5523: }
5524: }
5525: }
5526: my $rownum = 0;
5527: foreach my $item (@creators) {
5528: $rownum ++;
5529: if ($checked{$item} eq '') {
5530: $checked{$item} = 'any';
5531: }
5532: my $css_class;
5533: if ($rownum%2) {
5534: $css_class = '';
5535: } else {
5536: $css_class = ' class="LC_odd_row" ';
5537: }
5538: $datatable .= '<tr'.$css_class.'>'.
5539: '<td><span class="LC_nobreak">'.$lt{$item}.
5540: '</span></td><td align="right">';
5541: my @options = ('any');
5542: if (ref($rules) eq 'HASH') {
5543: if (keys(%{$rules}) > 0) {
5544: push(@options,('official','unofficial'));
5545: }
5546: }
5547: push(@options,'none');
5548: foreach my $option (@options) {
5549: my $type = 'radio';
5550: my $check = ' ';
5551: if ($checked{$item} eq $option) {
5552: $check = ' checked="checked" ';
5553: }
5554: $datatable .= '<span class="LC_nobreak"><label>'.
5555: '<input type="'.$type.'" name="can_createuser_'.
5556: $item.'" value="'.$option.'"'.$check.'/> '.
5557: $lt{$option}.'</label> </span>';
5558: }
5559: $datatable .= '</td></tr>';
5560: }
5561: } else {
5562: my @contexts = ('author','course','domain');
5563: my @authtypes = ('int','krb4','krb5','loc');
5564: my %checked;
5565: if (ref($settings) eq 'HASH') {
5566: if (ref($settings->{'authtypes'}) eq 'HASH') {
5567: foreach my $item (@contexts) {
5568: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
5569: foreach my $auth (@authtypes) {
5570: if ($settings->{'authtypes'}{$item}{$auth}) {
5571: $checked{$item}{$auth} = ' checked="checked" ';
5572: }
5573: }
5574: }
5575: }
5576: }
5577: } else {
5578: foreach my $item (@contexts) {
5579: foreach my $auth (@authtypes) {
5580: $checked{$item}{$auth} = ' checked="checked" ';
5581: }
5582: }
5583: }
5584: my %title = &context_names();
5585: my %authname = &authtype_names();
5586: my $rownum = 0;
5587: my $css_class;
5588: foreach my $item (@contexts) {
5589: if ($rownum%2) {
5590: $css_class = '';
5591: } else {
5592: $css_class = ' class="LC_odd_row" ';
5593: }
5594: $datatable .= '<tr'.$css_class.'>'.
5595: '<td>'.$title{$item}.
5596: '</td><td class="LC_left_item">'.
5597: '<span class="LC_nobreak">';
5598: foreach my $auth (@authtypes) {
5599: $datatable .= '<label>'.
5600: '<input type="checkbox" name="'.$item.'_auth" '.
5601: $checked{$item}{$auth}.' value="'.$auth.'" />'.
5602: $authname{$auth}.'</label> ';
5603: }
5604: $datatable .= '</span></td></tr>';
5605: $rownum ++;
5606: }
5607: $$rowtotal += $rownum;
5608: }
5609: return $datatable;
5610: }
5611:
5612: sub print_selfcreation {
5613: my ($position,$dom,$settings,$rowtotal) = @_;
5614: my (@selfcreate,$createsettings,$processing,$datatable);
5615: if (ref($settings) eq 'HASH') {
5616: if (ref($settings->{'cancreate'}) eq 'HASH') {
5617: $createsettings = $settings->{'cancreate'};
5618: if (ref($createsettings) eq 'HASH') {
5619: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
5620: @selfcreate = @{$createsettings->{'selfcreate'}};
5621: } elsif ($createsettings->{'selfcreate'} ne '') {
5622: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
5623: @selfcreate = ('email','login','sso');
5624: } elsif ($createsettings->{'selfcreate'} ne 'none') {
5625: @selfcreate = ($createsettings->{'selfcreate'});
5626: }
5627: }
5628: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
5629: $processing = $createsettings->{'selfcreateprocessing'};
5630: }
5631: }
5632: }
5633: }
5634: my %radiohash;
5635: my $numinrow = 4;
5636: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
5637: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5638: if ($position eq 'top') {
5639: my %choices = &Apache::lonlocal::texthash (
5640: cancreate_login => 'Institutional Login',
5641: cancreate_sso => 'Institutional Single Sign On',
5642: );
5643: my @toggles = sort(keys(%choices));
5644: my %defaultchecked = (
5645: 'cancreate_login' => 'off',
5646: 'cancreate_sso' => 'off',
5647: );
5648: my ($onclick,$itemcount);
5649: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5650: \%choices,$itemcount,$onclick);
5651: $$rowtotal += $itemcount;
5652:
5653: if (ref($usertypes) eq 'HASH') {
5654: if (keys(%{$usertypes}) > 0) {
5655: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
5656: $dom,$numinrow,$othertitle,
5657: 'statustocreate',$rowtotal);
5658: $$rowtotal ++;
5659: }
5660: }
5661: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
5662: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5663: $fieldtitles{'inststatus'} = &mt('Institutional status');
5664: my $rem;
5665: my $numperrow = 2;
5666: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
5667: $datatable .= '<tr'.$css_class.'>'.
5668: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
5669: '<td class="LC_left_item">'."\n".
5670: '<table><tr><td>'."\n";
5671: for (my $i=0; $i<@fields; $i++) {
5672: $rem = $i%($numperrow);
5673: if ($rem == 0) {
5674: if ($i > 0) {
5675: $datatable .= '</tr>';
5676: }
5677: $datatable .= '<tr>';
5678: }
5679: my $currval;
5680: if (ref($createsettings) eq 'HASH') {
5681: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
5682: $currval = $createsettings->{'shibenv'}{$fields[$i]};
5683: }
5684: }
5685: $datatable .= '<td class="LC_left_item">'.
5686: '<span class="LC_nobreak">'.
5687: '<input type="text" name="shibenv_'.$fields[$i].'" '.
5688: 'value="'.$currval.'" size="10" /> '.
5689: $fieldtitles{$fields[$i]}.'</span></td>';
5690: }
5691: my $colsleft = $numperrow - $rem;
5692: if ($colsleft > 1 ) {
5693: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5694: ' </td>';
5695: } elsif ($colsleft == 1) {
5696: $datatable .= '<td class="LC_left_item"> </td>';
5697: }
5698: $datatable .= '</tr></table></td></tr>';
5699: $$rowtotal ++;
5700: } elsif ($position eq 'middle') {
5701: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
5702: my @posstypes;
5703: if (ref($types) eq 'ARRAY') {
5704: @posstypes = @{$types};
5705: }
5706: unless (grep(/^default$/,@posstypes)) {
5707: push(@posstypes,'default');
5708: }
5709: my %usertypeshash;
5710: if (ref($usertypes) eq 'HASH') {
5711: %usertypeshash = %{$usertypes};
5712: }
5713: $usertypeshash{'default'} = $othertitle;
5714: foreach my $status (@posstypes) {
5715: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
5716: $numinrow,$$rowtotal,\%usertypeshash);
5717: $$rowtotal ++;
5718: }
5719: } else {
5720: my %choices = &Apache::lonlocal::texthash (
5721: cancreate_email => 'E-mail address as username',
5722: );
5723: my @toggles = sort(keys(%choices));
5724: my %defaultchecked = (
5725: 'cancreate_email' => 'off',
5726: );
5727: my $itemcount = 0;
5728: my $display = 'none';
5729: if (grep(/^\Qemail\E$/,@selfcreate)) {
5730: $display = 'block';
5731: }
5732: my $onclick = "toggleDisplay(this.form,'emailoptions');";
5733: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
5734: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
5735: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
5736: $order = $domdefaults{'inststatusguest'};
5737: }
5738: my (@ordered,%usertypeshash);
5739: if (ref($order) eq 'ARRAY') {
5740: @ordered = @{$order};
5741: }
5742: if (@ordered) {
5743: unless (grep(/^default$/,@ordered)) {
5744: push(@ordered,'default');
5745: }
5746: if (ref($usertypes) eq 'HASH') {
5747: %usertypeshash = %{$usertypes};
5748: }
5749: $usertypeshash{'default'} = $othertitle;
5750: $additional .= '<table><tr>';
5751: foreach my $status (@ordered) {
5752: $additional .= '<th>'.$usertypeshash{$status}.'</th>';
5753: }
5754: $additional .= '</tr><tr>';
5755: foreach my $status (@ordered) {
5756: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
5757: }
5758: $additional .= '</tr></table>';
5759: } else {
5760: $usertypeshash{'default'} = $othertitle;
5761: $additional .= &email_as_username($rowtotal,$processing);
5762: }
5763: $additional .= '</div>'."\n";
5764:
5765: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5766: \%choices,$$rowtotal,$onclick,$additional);
5767: $$rowtotal ++;
5768: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
5769: $$rowtotal ++;
5770: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
5771: $numinrow = 1;
5772: foreach my $status (@ordered) {
5773: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
5774: $numinrow,$$rowtotal,\%usertypeshash,$infofields,$infotitles);
5775: $$rowtotal ++;
5776: }
5777: my ($emailrules,$emailruleorder) =
5778: &Apache::lonnet::inst_userrules($dom,'email');
5779: if (ref($emailrules) eq 'HASH') {
5780: if (keys(%{$emailrules}) > 0) {
5781: $datatable .= &user_formats_row('email',$settings,$emailrules,
5782: $emailruleorder,$numinrow,$$rowtotal);
5783: $$rowtotal ++;
5784: }
5785: }
5786: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
5787: }
5788: return $datatable;
5789: }
5790:
5791: sub email_as_username {
5792: my ($rowtotal,$processing,$type) = @_;
5793: my %choices =
5794: &Apache::lonlocal::texthash (
5795: automatic => 'Automatic approval',
5796: approval => 'Queued for approval',
5797: );
5798: my $output;
5799: foreach my $option ('automatic','approval') {
5800: my $checked;
5801: if (ref($processing) eq 'HASH') {
5802: if ($type eq '') {
5803: if (!exists($processing->{'default'})) {
5804: if ($option eq 'automatic') {
5805: $checked = ' checked="checked"';
5806: }
5807: } else {
5808: if ($processing->{'default'} eq $option) {
5809: $checked = ' checked="checked"';
5810: }
5811: }
5812: } else {
5813: if (!exists($processing->{$type})) {
5814: if ($option eq 'automatic') {
5815: $checked = ' checked="checked"';
5816: }
5817: } else {
5818: if ($processing->{$type} eq $option) {
5819: $checked = ' checked="checked"';
5820: }
5821: }
5822: }
5823: } elsif ($option eq 'automatic') {
5824: $checked = ' checked="checked"';
5825: }
5826: my $name = 'cancreate_emailprocess';
5827: if (($type ne '') && ($type ne 'default')) {
5828: $name .= '_'.$type;
5829: }
5830: $output .= '<span class="LC_nobreak"><label>'.
5831: '<input type="radio" name="'.$name.'"'.
5832: $checked.' value="'.$option.'" />'.
5833: $choices{$option}.'</label></span>';
5834: if ($type eq '') {
5835: $output .= ' ';
5836: } else {
5837: $output .= '<br />';
5838: }
5839: }
5840: $$rowtotal ++;
5841: return $output;
5842: }
5843:
5844: sub captcha_choice {
5845: my ($context,$settings,$itemcount) = @_;
5846: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
5847: $vertext,$currver);
5848: my %lt = &captcha_phrases();
5849: $keyentry = 'hidden';
5850: if ($context eq 'cancreate') {
5851: $rowname = &mt('CAPTCHA validation');
5852: } elsif ($context eq 'login') {
5853: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
5854: }
5855: if (ref($settings) eq 'HASH') {
5856: if ($settings->{'captcha'}) {
5857: $checked{$settings->{'captcha'}} = ' checked="checked"';
5858: } else {
5859: $checked{'original'} = ' checked="checked"';
5860: }
5861: if ($settings->{'captcha'} eq 'recaptcha') {
5862: $pubtext = $lt{'pub'};
5863: $privtext = $lt{'priv'};
5864: $keyentry = 'text';
5865: $vertext = $lt{'ver'};
5866: $currver = $settings->{'recaptchaversion'};
5867: if ($currver ne '2') {
5868: $currver = 1;
5869: }
5870: }
5871: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
5872: $currpub = $settings->{'recaptchakeys'}{'public'};
5873: $currpriv = $settings->{'recaptchakeys'}{'private'};
5874: }
5875: } else {
5876: $checked{'original'} = ' checked="checked"';
5877: }
5878: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
5879: my $output = '<tr'.$css_class.'>'.
5880: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
5881: '<table><tr><td>'."\n";
5882: foreach my $option ('original','recaptcha','notused') {
5883: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
5884: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
5885: $lt{$option}.'</label></span>';
5886: unless ($option eq 'notused') {
5887: $output .= (' 'x2)."\n";
5888: }
5889: }
5890: #
5891: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
5892: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
5893: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
5894: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
5895: #
5896: $output .= '</td></tr>'."\n".
5897: '<tr><td>'."\n".
5898: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
5899: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
5900: $currpub.'" size="40" /></span><br />'."\n".
5901: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
5902: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
5903: $currpriv.'" size="40" /></span><br />'.
5904: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
5905: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
5906: $currver.'" size="3" /></span><br />'.
5907: '</td></tr></table>'."\n".
5908: '</td></tr>';
5909: return $output;
5910: }
5911:
5912: sub user_formats_row {
5913: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
5914: my $output;
5915: my %text = (
5916: 'username' => 'new usernames',
5917: 'id' => 'IDs',
5918: 'email' => 'self-created accounts (e-mail)',
5919: );
5920: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5921: $output = '<tr '.$css_class.'>'.
5922: '<td><span class="LC_nobreak">';
5923: if ($type eq 'email') {
5924: $output .= &mt("Formats disallowed for $text{$type}: ");
5925: } else {
5926: $output .= &mt("Format rules to check for $text{$type}: ");
5927: }
5928: $output .= '</span></td>'.
5929: '<td class="LC_left_item" colspan="2"><table>';
5930: my $rem;
5931: if (ref($ruleorder) eq 'ARRAY') {
5932: for (my $i=0; $i<@{$ruleorder}; $i++) {
5933: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
5934: my $rem = $i%($numinrow);
5935: if ($rem == 0) {
5936: if ($i > 0) {
5937: $output .= '</tr>';
5938: }
5939: $output .= '<tr>';
5940: }
5941: my $check = ' ';
5942: if (ref($settings) eq 'HASH') {
5943: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
5944: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
5945: $check = ' checked="checked" ';
5946: }
5947: }
5948: }
5949: $output .= '<td class="LC_left_item">'.
5950: '<span class="LC_nobreak"><label>'.
5951: '<input type="checkbox" name="'.$type.'_rule" '.
5952: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
5953: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
5954: }
5955: }
5956: $rem = @{$ruleorder}%($numinrow);
5957: }
5958: my $colsleft = $numinrow - $rem;
5959: if ($colsleft > 1 ) {
5960: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5961: ' </td>';
5962: } elsif ($colsleft == 1) {
5963: $output .= '<td class="LC_left_item"> </td>';
5964: }
5965: $output .= '</tr></table></td></tr>';
5966: return $output;
5967: }
5968:
5969: sub usercreation_types {
5970: my %lt = &Apache::lonlocal::texthash (
5971: author => 'When adding a co-author',
5972: course => 'When adding a user to a course',
5973: requestcrs => 'When requesting a course',
5974: any => 'Any',
5975: official => 'Institutional only ',
5976: unofficial => 'Non-institutional only',
5977: none => 'None',
5978: );
5979: return %lt;
5980: }
5981:
5982: sub selfcreation_types {
5983: my %lt = &Apache::lonlocal::texthash (
5984: selfcreate => 'User creates own account',
5985: any => 'Any',
5986: official => 'Institutional only ',
5987: unofficial => 'Non-institutional only',
5988: email => 'E-mail address',
5989: login => 'Institutional Login',
5990: sso => 'SSO',
5991: );
5992: }
5993:
5994: sub authtype_names {
5995: my %lt = &Apache::lonlocal::texthash(
5996: int => 'Internal',
5997: krb4 => 'Kerberos 4',
5998: krb5 => 'Kerberos 5',
5999: loc => 'Local',
6000: );
6001: return %lt;
6002: }
6003:
6004: sub context_names {
6005: my %context_title = &Apache::lonlocal::texthash(
6006: author => 'Creating users when an Author',
6007: course => 'Creating users when in a course',
6008: domain => 'Creating users when a Domain Coordinator',
6009: );
6010: return %context_title;
6011: }
6012:
6013: sub print_usermodification {
6014: my ($position,$dom,$settings,$rowtotal) = @_;
6015: my $numinrow = 4;
6016: my ($context,$datatable,$rowcount);
6017: if ($position eq 'top') {
6018: $rowcount = 0;
6019: $context = 'author';
6020: foreach my $role ('ca','aa') {
6021: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6022: $numinrow,$rowcount);
6023: $$rowtotal ++;
6024: $rowcount ++;
6025: }
6026: } elsif ($position eq 'bottom') {
6027: $context = 'course';
6028: $rowcount = 0;
6029: foreach my $role ('st','ep','ta','in','cr') {
6030: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6031: $numinrow,$rowcount);
6032: $$rowtotal ++;
6033: $rowcount ++;
6034: }
6035: }
6036: return $datatable;
6037: }
6038:
6039: sub print_defaults {
6040: my ($position,$dom,$settings,$rowtotal) = @_;
6041: my $rownum = 0;
6042: my ($datatable,$css_class,$titles);
6043: unless ($position eq 'bottom') {
6044: $titles = &defaults_titles($dom);
6045: }
6046: if ($position eq 'top') {
6047: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
6048: 'datelocale_def','portal_def');
6049: my %defaults;
6050: if (ref($settings) eq 'HASH') {
6051: %defaults = %{$settings};
6052: } else {
6053: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
6054: foreach my $item (@items) {
6055: $defaults{$item} = $domdefaults{$item};
6056: }
6057: }
6058: foreach my $item (@items) {
6059: if ($rownum%2) {
6060: $css_class = '';
6061: } else {
6062: $css_class = ' class="LC_odd_row" ';
6063: }
6064: $datatable .= '<tr'.$css_class.'>'.
6065: '<td><span class="LC_nobreak">'.$titles->{$item}.
6066: '</span></td><td class="LC_right_item" colspan="3">';
6067: if ($item eq 'auth_def') {
6068: my @authtypes = ('internal','krb4','krb5','localauth');
6069: my %shortauth = (
6070: internal => 'int',
6071: krb4 => 'krb4',
6072: krb5 => 'krb5',
6073: localauth => 'loc'
6074: );
6075: my %authnames = &authtype_names();
6076: foreach my $auth (@authtypes) {
6077: my $checked = ' ';
6078: if ($defaults{$item} eq $auth) {
6079: $checked = ' checked="checked" ';
6080: }
6081: $datatable .= '<label><input type="radio" name="'.$item.
6082: '" value="'.$auth.'"'.$checked.'/>'.
6083: $authnames{$shortauth{$auth}}.'</label> ';
6084: }
6085: } elsif ($item eq 'timezone_def') {
6086: my $includeempty = 1;
6087: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
6088: } elsif ($item eq 'datelocale_def') {
6089: my $includeempty = 1;
6090: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
6091: } elsif ($item eq 'lang_def') {
6092: my $includeempty = 1;
6093: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
6094: } else {
6095: my $size;
6096: if ($item eq 'portal_def') {
6097: $size = ' size="25"';
6098: }
6099: $datatable .= '<input type="text" name="'.$item.'" value="'.
6100: $defaults{$item}.'"'.$size.' />';
6101: }
6102: $datatable .= '</td></tr>';
6103: $rownum ++;
6104: }
6105: } elsif ($position eq 'middle') {
6106: my @items = ('intauth_cost','intauth_check','intauth_switch');
6107: my %defaults;
6108: if (ref($settings) eq 'HASH') {
6109: %defaults = %{$settings};
6110: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
6111: $defaults{'intauth_cost'} = 10;
6112: }
6113: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
6114: $defaults{'intauth_check'} = 0;
6115: }
6116: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
6117: $defaults{'intauth_switch'} = 0;
6118: }
6119: } else {
6120: %defaults = (
6121: 'intauth_cost' => 10,
6122: 'intauth_check' => 0,
6123: 'intauth_switch' => 0,
6124: );
6125: }
6126: foreach my $item (@items) {
6127: if ($rownum%2) {
6128: $css_class = '';
6129: } else {
6130: $css_class = ' class="LC_odd_row" ';
6131: }
6132: $datatable .= '<tr'.$css_class.'>'.
6133: '<td><span class="LC_nobreak">'.$titles->{$item}.
6134: '</span></td><td class="LC_left_item" colspan="3">';
6135: if ($item eq 'intauth_switch') {
6136: my @options = (0,1,2);
6137: my %optiondesc = &Apache::lonlocal::texthash (
6138: 0 => 'No',
6139: 1 => 'Yes',
6140: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
6141: );
6142: $datatable .= '<table width="100%">';
6143: foreach my $option (@options) {
6144: my $checked = ' ';
6145: if ($defaults{$item} eq $option) {
6146: $checked = ' checked="checked"';
6147: }
6148: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6149: '<label><input type="radio" name="'.$item.
6150: '" value="'.$option.'"'.$checked.' />'.
6151: $optiondesc{$option}.'</label></span></td></tr>';
6152: }
6153: $datatable .= '</table>';
6154: } elsif ($item eq 'intauth_check') {
6155: my @options = (0,1,2);
6156: my %optiondesc = &Apache::lonlocal::texthash (
6157: 0 => 'No',
6158: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
6159: 2 => 'Yes, disallow login if stored cost is less than domain default',
6160: );
6161: $datatable .= '<table wisth="100%">';
6162: foreach my $option (@options) {
6163: my $checked = ' ';
6164: my $onclick;
6165: if ($defaults{$item} eq $option) {
6166: $checked = ' checked="checked"';
6167: }
6168: if ($option == 2) {
6169: $onclick = ' onclick="javascript:warnIntAuth(this);"';
6170: }
6171: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6172: '<label><input type="radio" name="'.$item.
6173: '" value="'.$option.'"'.$checked.$onclick.' />'.
6174: $optiondesc{$option}.'</label></span></td></tr>';
6175: }
6176: $datatable .= '</table>';
6177: } else {
6178: $datatable .= '<input type="text" name="'.$item.'" value="'.
6179: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
6180: }
6181: $datatable .= '</td></tr>';
6182: $rownum ++;
6183: }
6184: } else {
6185: my %defaults;
6186: if (ref($settings) eq 'HASH') {
6187: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
6188: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
6189: my $maxnum = @{$settings->{'inststatusorder'}};
6190: for (my $i=0; $i<$maxnum; $i++) {
6191: $css_class = $rownum%2?' class="LC_odd_row"':'';
6192: my $item = $settings->{'inststatusorder'}->[$i];
6193: my $title = $settings->{'inststatustypes'}->{$item};
6194: my $guestok;
6195: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
6196: $guestok = 1;
6197: }
6198: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
6199: $datatable .= '<tr'.$css_class.'>'.
6200: '<td><span class="LC_nobreak">'.
6201: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
6202: for (my $k=0; $k<=$maxnum; $k++) {
6203: my $vpos = $k+1;
6204: my $selstr;
6205: if ($k == $i) {
6206: $selstr = ' selected="selected" ';
6207: }
6208: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6209: }
6210: my ($checkedon,$checkedoff);
6211: $checkedoff = ' checked="checked"';
6212: if ($guestok) {
6213: $checkedon = $checkedoff;
6214: $checkedoff = '';
6215: }
6216: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
6217: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
6218: &mt('delete').'</span></td>'.
6219: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
6220: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
6221: '</span></td>'.
6222: '<td class="LC_right_item"><span class="LC_nobreak">'.
6223: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
6224: &mt('Yes').'</label>'.(' 'x2).
6225: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
6226: &mt('No').'</label></span></td></tr>';
6227: }
6228: $css_class = $rownum%2?' class="LC_odd_row"':'';
6229: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
6230: $datatable .= '<tr '.$css_class.'>'.
6231: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
6232: for (my $k=0; $k<=$maxnum; $k++) {
6233: my $vpos = $k+1;
6234: my $selstr;
6235: if ($k == $maxnum) {
6236: $selstr = ' selected="selected" ';
6237: }
6238: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6239: }
6240: $datatable .= '</select> '.&mt('Internal ID:').
6241: '<input type="text" size="10" name="addinststatus" value="" />'.
6242: ' '.&mt('(new)').
6243: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
6244: &mt('Name displayed:').
6245: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
6246: '<td class="LC_right_item"><span class="LC_nobreak">'.
6247: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
6248: &mt('Yes').'</label>'.(' 'x2).
6249: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
6250: &mt('No').'</label></span></td></tr>';
6251: '</tr>'."\n";
6252: $rownum ++;
6253: }
6254: }
6255: }
6256: $$rowtotal += $rownum;
6257: return $datatable;
6258: }
6259:
6260: sub get_languages_hash {
6261: my %langchoices;
6262: foreach my $id (&Apache::loncommon::languageids()) {
6263: my $code = &Apache::loncommon::supportedlanguagecode($id);
6264: if ($code ne '') {
6265: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
6266: }
6267: }
6268: return %langchoices;
6269: }
6270:
6271: sub defaults_titles {
6272: my ($dom) = @_;
6273: my %titles = &Apache::lonlocal::texthash (
6274: 'auth_def' => 'Default authentication type',
6275: 'auth_arg_def' => 'Default authentication argument',
6276: 'lang_def' => 'Default language',
6277: 'timezone_def' => 'Default timezone',
6278: 'datelocale_def' => 'Default locale for dates',
6279: 'portal_def' => 'Portal/Default URL',
6280: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
6281: 'intauth_check' => 'Check bcrypt cost if authenticated',
6282: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
6283: );
6284: if ($dom) {
6285: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
6286: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
6287: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
6288: $protocol = 'http' if ($protocol ne 'https');
6289: if ($uint_dom) {
6290: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
6291: $uint_dom);
6292: }
6293: }
6294: return (\%titles);
6295: }
6296:
6297: sub print_scantronformat {
6298: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
6299: my $itemcount = 1;
6300: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
6301: %confhash);
6302: my $switchserver = &check_switchserver($dom,$confname);
6303: my %lt = &Apache::lonlocal::texthash (
6304: default => 'Default bubblesheet format file error',
6305: custom => 'Custom bubblesheet format file error',
6306: );
6307: my %scantronfiles = (
6308: default => 'default.tab',
6309: custom => 'custom.tab',
6310: );
6311: foreach my $key (keys(%scantronfiles)) {
6312: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
6313: .$scantronfiles{$key};
6314: }
6315: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
6316: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
6317: if (!$switchserver) {
6318: my $servadm = $r->dir_config('lonAdmEMail');
6319: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
6320: if ($configuserok eq 'ok') {
6321: if ($author_ok eq 'ok') {
6322: my %legacyfile = (
6323: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
6324: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
6325: );
6326: my %md5chk;
6327: foreach my $type (keys(%legacyfile)) {
6328: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
6329: chomp($md5chk{$type});
6330: }
6331: if ($md5chk{'default'} ne $md5chk{'custom'}) {
6332: foreach my $type (keys(%legacyfile)) {
6333: ($scantronurls{$type},my $error) =
6334: &legacy_scantronformat($r,$dom,$confname,
6335: $type,$legacyfile{$type},
6336: $scantronurls{$type},
6337: $scantronfiles{$type});
6338: if ($error ne '') {
6339: $error{$type} = $error;
6340: }
6341: }
6342: if (keys(%error) == 0) {
6343: $is_custom = 1;
6344: $confhash{'scantron'}{'scantronformat'} =
6345: $scantronurls{'custom'};
6346: my $putresult =
6347: &Apache::lonnet::put_dom('configuration',
6348: \%confhash,$dom);
6349: if ($putresult ne 'ok') {
6350: $error{'custom'} =
6351: '<span class="LC_error">'.
6352: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6353: }
6354: }
6355: } else {
6356: ($scantronurls{'default'},my $error) =
6357: &legacy_scantronformat($r,$dom,$confname,
6358: 'default',$legacyfile{'default'},
6359: $scantronurls{'default'},
6360: $scantronfiles{'default'});
6361: if ($error eq '') {
6362: $confhash{'scantron'}{'scantronformat'} = '';
6363: my $putresult =
6364: &Apache::lonnet::put_dom('configuration',
6365: \%confhash,$dom);
6366: if ($putresult ne 'ok') {
6367: $error{'default'} =
6368: '<span class="LC_error">'.
6369: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6370: }
6371: } else {
6372: $error{'default'} = $error;
6373: }
6374: }
6375: }
6376: }
6377: } else {
6378: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
6379: }
6380: }
6381: if (ref($settings) eq 'HASH') {
6382: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
6383: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
6384: if ((!@info) || ($info[0] eq 'no_such_dir')) {
6385: $scantronurl = '';
6386: } else {
6387: $scantronurl = $settings->{'scantronformat'};
6388: }
6389: $is_custom = 1;
6390: } else {
6391: $scantronurl = $scantronurls{'default'};
6392: }
6393: } else {
6394: if ($is_custom) {
6395: $scantronurl = $scantronurls{'custom'};
6396: } else {
6397: $scantronurl = $scantronurls{'default'};
6398: }
6399: }
6400: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6401: $datatable .= '<tr'.$css_class.'>';
6402: if (!$is_custom) {
6403: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
6404: '<span class="LC_nobreak">';
6405: if ($scantronurl) {
6406: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
6407: undef,undef,undef,undef,'background-color:#ffffff');
6408: } else {
6409: $datatable = &mt('File unavailable for display');
6410: }
6411: $datatable .= '</span></td>';
6412: if (keys(%error) == 0) {
6413: $datatable .= '<td valign="bottom">';
6414: if (!$switchserver) {
6415: $datatable .= &mt('Upload:').'<br />';
6416: }
6417: } else {
6418: my $errorstr;
6419: foreach my $key (sort(keys(%error))) {
6420: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6421: }
6422: $datatable .= '<td>'.$errorstr;
6423: }
6424: } else {
6425: if (keys(%error) > 0) {
6426: my $errorstr;
6427: foreach my $key (sort(keys(%error))) {
6428: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6429: }
6430: $datatable .= '<td>'.$errorstr.'</td><td> ';
6431: } elsif ($scantronurl) {
6432: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
6433: undef,undef,undef,undef,'background-color:#ffffff');
6434: $datatable .= '<td><span class="LC_nobreak">'.
6435: $link.
6436: '<label><input type="checkbox" name="scantronformat_del"'.
6437: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
6438: '<td><span class="LC_nobreak"> '.
6439: &mt('Replace:').'</span><br />';
6440: }
6441: }
6442: if (keys(%error) == 0) {
6443: if ($switchserver) {
6444: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6445: } else {
6446: $datatable .='<span class="LC_nobreak"> '.
6447: '<input type="file" name="scantronformat" /></span>';
6448: }
6449: }
6450: $datatable .= '</td></tr>';
6451: $$rowtotal ++;
6452: return $datatable;
6453: }
6454:
6455: sub legacy_scantronformat {
6456: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
6457: my ($url,$error);
6458: my @statinfo = &Apache::lonnet::stat_file($newurl);
6459: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
6460: (my $result,$url) =
6461: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
6462: '','',$newfile);
6463: if ($result ne 'ok') {
6464: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
6465: }
6466: }
6467: return ($url,$error);
6468: }
6469:
6470: sub print_coursecategories {
6471: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
6472: my $datatable;
6473: if ($position eq 'top') {
6474: my (%checked);
6475: my @catitems = ('unauth','auth');
6476: my @cattypes = ('std','domonly','codesrch','none');
6477: $checked{'unauth'} = 'std';
6478: $checked{'auth'} = 'std';
6479: if (ref($settings) eq 'HASH') {
6480: foreach my $type (@cattypes) {
6481: if ($type eq $settings->{'unauth'}) {
6482: $checked{'unauth'} = $type;
6483: }
6484: if ($type eq $settings->{'auth'}) {
6485: $checked{'auth'} = $type;
6486: }
6487: }
6488: }
6489: my %lt = &Apache::lonlocal::texthash (
6490: unauth => 'Catalog type for unauthenticated users',
6491: auth => 'Catalog type for authenticated users',
6492: none => 'No catalog',
6493: std => 'Standard catalog',
6494: domonly => 'Domain-only catalog',
6495: codesrch => "Code search form",
6496: );
6497: my $itemcount = 0;
6498: foreach my $item (@catitems) {
6499: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
6500: $datatable .= '<tr '.$css_class.'>'.
6501: '<td>'.$lt{$item}.'</td>'.
6502: '<td class="LC_right_item"><span class="LC_nobreak">';
6503: foreach my $type (@cattypes) {
6504: my $ischecked;
6505: if ($checked{$item} eq $type) {
6506: $ischecked=' checked="checked"';
6507: }
6508: $datatable .= '<label>'.
6509: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
6510: ' />'.$lt{$type}.'</label> ';
6511: }
6512: $datatable .= '</td></tr>';
6513: $itemcount ++;
6514: }
6515: $$rowtotal += $itemcount;
6516: } elsif ($position eq 'middle') {
6517: my $toggle_cats_crs = ' ';
6518: my $toggle_cats_dom = ' checked="checked" ';
6519: my $can_cat_crs = ' ';
6520: my $can_cat_dom = ' checked="checked" ';
6521: my $toggle_catscomm_comm = ' ';
6522: my $toggle_catscomm_dom = ' checked="checked" ';
6523: my $can_catcomm_comm = ' ';
6524: my $can_catcomm_dom = ' checked="checked" ';
6525:
6526: if (ref($settings) eq 'HASH') {
6527: if ($settings->{'togglecats'} eq 'crs') {
6528: $toggle_cats_crs = $toggle_cats_dom;
6529: $toggle_cats_dom = ' ';
6530: }
6531: if ($settings->{'categorize'} eq 'crs') {
6532: $can_cat_crs = $can_cat_dom;
6533: $can_cat_dom = ' ';
6534: }
6535: if ($settings->{'togglecatscomm'} eq 'comm') {
6536: $toggle_catscomm_comm = $toggle_catscomm_dom;
6537: $toggle_catscomm_dom = ' ';
6538: }
6539: if ($settings->{'categorizecomm'} eq 'comm') {
6540: $can_catcomm_comm = $can_catcomm_dom;
6541: $can_catcomm_dom = ' ';
6542: }
6543: }
6544: my %title = &Apache::lonlocal::texthash (
6545: togglecats => 'Show/Hide a course in catalog',
6546: togglecatscomm => 'Show/Hide a community in catalog',
6547: categorize => 'Assign a category to a course',
6548: categorizecomm => 'Assign a category to a community',
6549: );
6550: my %level = &Apache::lonlocal::texthash (
6551: dom => 'Set in Domain',
6552: crs => 'Set in Course',
6553: comm => 'Set in Community',
6554: );
6555: $datatable = '<tr class="LC_odd_row">'.
6556: '<td>'.$title{'togglecats'}.'</td>'.
6557: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6558: '<input type="radio" name="togglecats"'.
6559: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6560: '<label><input type="radio" name="togglecats"'.
6561: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
6562: '</tr><tr>'.
6563: '<td>'.$title{'categorize'}.'</td>'.
6564: '<td class="LC_right_item"><span class="LC_nobreak">'.
6565: '<label><input type="radio" name="categorize"'.
6566: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6567: '<label><input type="radio" name="categorize"'.
6568: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
6569: '</tr><tr class="LC_odd_row">'.
6570: '<td>'.$title{'togglecatscomm'}.'</td>'.
6571: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6572: '<input type="radio" name="togglecatscomm"'.
6573: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6574: '<label><input type="radio" name="togglecatscomm"'.
6575: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
6576: '</tr><tr>'.
6577: '<td>'.$title{'categorizecomm'}.'</td>'.
6578: '<td class="LC_right_item"><span class="LC_nobreak">'.
6579: '<label><input type="radio" name="categorizecomm"'.
6580: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6581: '<label><input type="radio" name="categorizecomm"'.
6582: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
6583: '</tr>';
6584: $$rowtotal += 4;
6585: } else {
6586: my $css_class;
6587: my $itemcount = 1;
6588: my $cathash;
6589: if (ref($settings) eq 'HASH') {
6590: $cathash = $settings->{'cats'};
6591: }
6592: if (ref($cathash) eq 'HASH') {
6593: my (@cats,@trails,%allitems,%idx,@jsarray);
6594: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
6595: \%allitems,\%idx,\@jsarray);
6596: my $maxdepth = scalar(@cats);
6597: my $colattrib = '';
6598: if ($maxdepth > 2) {
6599: $colattrib = ' colspan="2" ';
6600: }
6601: my @path;
6602: if (@cats > 0) {
6603: if (ref($cats[0]) eq 'ARRAY') {
6604: my $numtop = @{$cats[0]};
6605: my $maxnum = $numtop;
6606: my %default_names = (
6607: instcode => &mt('Official courses'),
6608: communities => &mt('Communities'),
6609: );
6610:
6611: if ((!grep(/^instcode$/,@{$cats[0]})) ||
6612: ($cathash->{'instcode::0'} eq '') ||
6613: (!grep(/^communities$/,@{$cats[0]})) ||
6614: ($cathash->{'communities::0'} eq '')) {
6615: $maxnum ++;
6616: }
6617: my $lastidx;
6618: for (my $i=0; $i<$numtop; $i++) {
6619: my $parent = $cats[0][$i];
6620: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6621: my $item = &escape($parent).'::0';
6622: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
6623: $lastidx = $idx{$item};
6624: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6625: .'<select name="'.$item.'"'.$chgstr.'>';
6626: for (my $k=0; $k<=$maxnum; $k++) {
6627: my $vpos = $k+1;
6628: my $selstr;
6629: if ($k == $i) {
6630: $selstr = ' selected="selected" ';
6631: }
6632: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6633: }
6634: $datatable .= '</select></span></td><td>';
6635: if ($parent eq 'instcode' || $parent eq 'communities') {
6636: $datatable .= '<span class="LC_nobreak">'
6637: .$default_names{$parent}.'</span>';
6638: if ($parent eq 'instcode') {
6639: $datatable .= '<br /><span class="LC_nobreak">('
6640: .&mt('with institutional codes')
6641: .')</span></td><td'.$colattrib.'>';
6642: } else {
6643: $datatable .= '<table><tr><td>';
6644: }
6645: $datatable .= '<span class="LC_nobreak">'
6646: .'<label><input type="radio" name="'
6647: .$parent.'" value="1" checked="checked" />'
6648: .&mt('Display').'</label>';
6649: if ($parent eq 'instcode') {
6650: $datatable .= ' ';
6651: } else {
6652: $datatable .= '</span></td></tr><tr><td>'
6653: .'<span class="LC_nobreak">';
6654: }
6655: $datatable .= '<label><input type="radio" name="'
6656: .$parent.'" value="0" />'
6657: .&mt('Do not display').'</label></span>';
6658: if ($parent eq 'communities') {
6659: $datatable .= '</td></tr></table>';
6660: }
6661: $datatable .= '</td>';
6662: } else {
6663: $datatable .= $parent
6664: .' <span class="LC_nobreak"><label>'
6665: .'<input type="checkbox" name="deletecategory" '
6666: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
6667: }
6668: my $depth = 1;
6669: push(@path,$parent);
6670: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
6671: pop(@path);
6672: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
6673: $itemcount ++;
6674: }
6675: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6676: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
6677: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
6678: for (my $k=0; $k<=$maxnum; $k++) {
6679: my $vpos = $k+1;
6680: my $selstr;
6681: if ($k == $numtop) {
6682: $selstr = ' selected="selected" ';
6683: }
6684: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6685: }
6686: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
6687: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
6688: .'</tr>'."\n";
6689: $itemcount ++;
6690: foreach my $default ('instcode','communities') {
6691: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
6692: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6693: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
6694: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
6695: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
6696: for (my $k=0; $k<=$maxnum; $k++) {
6697: my $vpos = $k+1;
6698: my $selstr;
6699: if ($k == $maxnum) {
6700: $selstr = ' selected="selected" ';
6701: }
6702: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6703: }
6704: $datatable .= '</select></span></td>'.
6705: '<td><span class="LC_nobreak">'.
6706: $default_names{$default}.'</span>';
6707: if ($default eq 'instcode') {
6708: $datatable .= '<br /><span class="LC_nobreak">('
6709: .&mt('with institutional codes').')</span>';
6710: }
6711: $datatable .= '</td>'
6712: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
6713: .&mt('Display').'</label> '
6714: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
6715: .&mt('Do not display').'</label></span></td></tr>';
6716: }
6717: }
6718: }
6719: } else {
6720: $datatable .= &initialize_categories($itemcount);
6721: }
6722: } else {
6723: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
6724: .&initialize_categories($itemcount);
6725: }
6726: $$rowtotal += $itemcount;
6727: }
6728: return $datatable;
6729: }
6730:
6731: sub print_serverstatuses {
6732: my ($dom,$settings,$rowtotal) = @_;
6733: my $datatable;
6734: my @pages = &serverstatus_pages();
6735: my (%namedaccess,%machineaccess);
6736: foreach my $type (@pages) {
6737: $namedaccess{$type} = '';
6738: $machineaccess{$type}= '';
6739: }
6740: if (ref($settings) eq 'HASH') {
6741: foreach my $type (@pages) {
6742: if (exists($settings->{$type})) {
6743: if (ref($settings->{$type}) eq 'HASH') {
6744: foreach my $key (keys(%{$settings->{$type}})) {
6745: if ($key eq 'namedusers') {
6746: $namedaccess{$type} = $settings->{$type}->{$key};
6747: } elsif ($key eq 'machines') {
6748: $machineaccess{$type} = $settings->{$type}->{$key};
6749: }
6750: }
6751: }
6752: }
6753: }
6754: }
6755: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
6756: my $rownum = 0;
6757: my $css_class;
6758: foreach my $type (@pages) {
6759: $rownum ++;
6760: $css_class = $rownum%2?' class="LC_odd_row"':'';
6761: $datatable .= '<tr'.$css_class.'>'.
6762: '<td><span class="LC_nobreak">'.
6763: $titles->{$type}.'</span></td>'.
6764: '<td class="LC_left_item">'.
6765: '<input type="text" name="'.$type.'_namedusers" '.
6766: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
6767: '<td class="LC_right_item">'.
6768: '<span class="LC_nobreak">'.
6769: '<input type="text" name="'.$type.'_machines" '.
6770: 'value="'.$machineaccess{$type}.'" size="10" />'.
6771: '</td></tr>'."\n";
6772: }
6773: $$rowtotal += $rownum;
6774: return $datatable;
6775: }
6776:
6777: sub serverstatus_pages {
6778: return ('userstatus','lonstatus','loncron','server-status','codeversions',
6779: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
6780: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
6781: 'uniquecodes','diskusage','coursecatalog');
6782: }
6783:
6784: sub defaults_javascript {
6785: my ($settings) = @_;
6786: my $intauthcheck = &mt('Warning: disallowing login for an authenticated user if the stored cost is less than the default will require a password reset by/for the user.');
6787: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
6788: &js_escape(\$intauthcheck);
6789: &js_escape(\$intauthcost);
6790: my $intauthjs = <<"ENDSCRIPT";
6791:
6792: function warnIntAuth(field) {
6793: if (field.name == 'intauth_check') {
6794: if (field.value == '2') {
6795: alert('$intauthcheck');
6796: }
6797: }
6798: if (field.name == 'intauth_cost') {
6799: field.value.replace(/\s/g,'');
6800: if (field.value != '') {
6801: var regexdigit=/^\\d+\$/;
6802: if (!regexdigit.test(field.value)) {
6803: alert('$intauthcost');
6804: }
6805: }
6806: }
6807: return;
6808: }
6809:
6810: ENDSCRIPT
6811:
6812: if (ref($settings) ne 'HASH') {
6813: return &Apache::lonhtmlcommon::scripttag($intauthjs);
6814: }
6815: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
6816: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
6817: if ($maxnum eq '') {
6818: $maxnum = 0;
6819: }
6820: $maxnum ++;
6821: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
6822: return <<"ENDSCRIPT";
6823: <script type="text/javascript">
6824: // <![CDATA[
6825: function reorderTypes(form,caller) {
6826: var changedVal;
6827: $jstext
6828: var newpos = 'addinststatus_pos';
6829: var current = new Array;
6830: var maxh = $maxnum;
6831: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6832: var oldVal;
6833: if (caller == newpos) {
6834: changedVal = newitemVal;
6835: } else {
6836: var curritem = 'inststatus_pos_'+caller;
6837: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
6838: current[newitemVal] = newpos;
6839: }
6840: for (var i=0; i<inststatuses.length; i++) {
6841: if (inststatuses[i] != caller) {
6842: var elementName = 'inststatus_pos_'+inststatuses[i];
6843: if (form.elements[elementName]) {
6844: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6845: current[currVal] = elementName;
6846: }
6847: }
6848: }
6849: for (var j=0; j<maxh; j++) {
6850: if (current[j] == undefined) {
6851: oldVal = j;
6852: }
6853: }
6854: if (oldVal < changedVal) {
6855: for (var k=oldVal+1; k<=changedVal ; k++) {
6856: var elementName = current[k];
6857: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6858: }
6859: } else {
6860: for (var k=changedVal; k<oldVal; k++) {
6861: var elementName = current[k];
6862: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6863: }
6864: }
6865: return;
6866: }
6867:
6868: $intauthjs
6869:
6870: // ]]>
6871: </script>
6872:
6873: ENDSCRIPT
6874: } else {
6875: return &Apache::lonhtmlcommon::scripttag($intauthjs);
6876: }
6877: }
6878:
6879: sub coursecategories_javascript {
6880: my ($settings) = @_;
6881: my ($output,$jstext,$cathash);
6882: if (ref($settings) eq 'HASH') {
6883: $cathash = $settings->{'cats'};
6884: }
6885: if (ref($cathash) eq 'HASH') {
6886: my (@cats,@jsarray,%idx);
6887: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
6888: if (@jsarray > 0) {
6889: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
6890: for (my $i=0; $i<@jsarray; $i++) {
6891: if (ref($jsarray[$i]) eq 'ARRAY') {
6892: my $catstr = join('","',@{$jsarray[$i]});
6893: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
6894: }
6895: }
6896: }
6897: } else {
6898: $jstext = ' var categories = Array(1);'."\n".
6899: ' categories[0] = Array("instcode_pos");'."\n";
6900: }
6901: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
6902: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
6903: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
6904: &js_escape(\$instcode_reserved);
6905: &js_escape(\$communities_reserved);
6906: &js_escape(\$choose_again);
6907: $output = <<"ENDSCRIPT";
6908: <script type="text/javascript">
6909: // <![CDATA[
6910: function reorderCats(form,parent,item,idx) {
6911: var changedVal;
6912: $jstext
6913: var newpos = 'addcategory_pos';
6914: if (parent == '') {
6915: var has_instcode = 0;
6916: var maxtop = categories[idx].length;
6917: for (var j=0; j<maxtop; j++) {
6918: if (categories[idx][j] == 'instcode::0') {
6919: has_instcode == 1;
6920: }
6921: }
6922: if (has_instcode == 0) {
6923: categories[idx][maxtop] = 'instcode_pos';
6924: }
6925: } else {
6926: newpos += '_'+parent;
6927: }
6928: var maxh = 1 + categories[idx].length;
6929: var current = new Array;
6930: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6931: if (item == newpos) {
6932: changedVal = newitemVal;
6933: } else {
6934: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
6935: current[newitemVal] = newpos;
6936: }
6937: for (var i=0; i<categories[idx].length; i++) {
6938: var elementName = categories[idx][i];
6939: if (elementName != item) {
6940: if (form.elements[elementName]) {
6941: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6942: current[currVal] = elementName;
6943: }
6944: }
6945: }
6946: var oldVal;
6947: for (var j=0; j<maxh; j++) {
6948: if (current[j] == undefined) {
6949: oldVal = j;
6950: }
6951: }
6952: if (oldVal < changedVal) {
6953: for (var k=oldVal+1; k<=changedVal ; k++) {
6954: var elementName = current[k];
6955: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6956: }
6957: } else {
6958: for (var k=changedVal; k<oldVal; k++) {
6959: var elementName = current[k];
6960: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6961: }
6962: }
6963: return;
6964: }
6965:
6966: function categoryCheck(form) {
6967: if (form.elements['addcategory_name'].value == 'instcode') {
6968: alert('$instcode_reserved\\n$choose_again');
6969: return false;
6970: }
6971: if (form.elements['addcategory_name'].value == 'communities') {
6972: alert('$communities_reserved\\n$choose_again');
6973: return false;
6974: }
6975: return true;
6976: }
6977:
6978: // ]]>
6979: </script>
6980:
6981: ENDSCRIPT
6982: return $output;
6983: }
6984:
6985: sub initialize_categories {
6986: my ($itemcount) = @_;
6987: my ($datatable,$css_class,$chgstr);
6988: my %default_names = (
6989: instcode => 'Official courses (with institutional codes)',
6990: communities => 'Communities',
6991: );
6992: my $select0 = ' selected="selected"';
6993: my $select1 = '';
6994: foreach my $default ('instcode','communities') {
6995: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6996: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
6997: if ($default eq 'communities') {
6998: $select1 = $select0;
6999: $select0 = '';
7000: }
7001: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
7002: .'<select name="'.$default.'_pos">'
7003: .'<option value="0"'.$select0.'>1</option>'
7004: .'<option value="1"'.$select1.'>2</option>'
7005: .'<option value="2">3</option></select> '
7006: .$default_names{$default}
7007: .'</span></td><td><span class="LC_nobreak">'
7008: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
7009: .&mt('Display').'</label> <label>'
7010: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
7011: .'</label></span></td></tr>';
7012: $itemcount ++;
7013: }
7014: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7015: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
7016: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
7017: .'<select name="addcategory_pos"'.$chgstr.'>'
7018: .'<option value="0">1</option>'
7019: .'<option value="1">2</option>'
7020: .'<option value="2" selected="selected">3</option></select> '
7021: .&mt('Add category').'</td><td>'.&mt('Name:')
7022: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
7023: return $datatable;
7024: }
7025:
7026: sub build_category_rows {
7027: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
7028: my ($text,$name,$item,$chgstr);
7029: if (ref($cats) eq 'ARRAY') {
7030: my $maxdepth = scalar(@{$cats});
7031: if (ref($cats->[$depth]) eq 'HASH') {
7032: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
7033: my $numchildren = @{$cats->[$depth]{$parent}};
7034: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
7035: $text .= '<td><table class="LC_data_table">';
7036: my ($idxnum,$parent_name,$parent_item);
7037: my $higher = $depth - 1;
7038: if ($higher == 0) {
7039: $parent_name = &escape($parent).'::'.$higher;
7040: } else {
7041: if (ref($path) eq 'ARRAY') {
7042: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7043: }
7044: }
7045: $parent_item = 'addcategory_pos_'.$parent_name;
7046: for (my $j=0; $j<=$numchildren; $j++) {
7047: if ($j < $numchildren) {
7048: $name = $cats->[$depth]{$parent}[$j];
7049: $item = &escape($name).':'.&escape($parent).':'.$depth;
7050: $idxnum = $idx->{$item};
7051: } else {
7052: $name = $parent_name;
7053: $item = $parent_item;
7054: }
7055: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
7056: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
7057: for (my $i=0; $i<=$numchildren; $i++) {
7058: my $vpos = $i+1;
7059: my $selstr;
7060: if ($j == $i) {
7061: $selstr = ' selected="selected" ';
7062: }
7063: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
7064: }
7065: $text .= '</select> ';
7066: if ($j < $numchildren) {
7067: my $deeper = $depth+1;
7068: $text .= $name.' '
7069: .'<label><input type="checkbox" name="deletecategory" value="'
7070: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
7071: if(ref($path) eq 'ARRAY') {
7072: push(@{$path},$name);
7073: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
7074: pop(@{$path});
7075: }
7076: } else {
7077: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
7078: if ($j == $numchildren) {
7079: $text .= $name;
7080: } else {
7081: $text .= $item;
7082: }
7083: $text .= '" value="" />';
7084: }
7085: $text .= '</td></tr>';
7086: }
7087: $text .= '</table></td>';
7088: } else {
7089: my $higher = $depth-1;
7090: if ($higher == 0) {
7091: $name = &escape($parent).'::'.$higher;
7092: } else {
7093: if (ref($path) eq 'ARRAY') {
7094: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7095: }
7096: }
7097: my $colspan;
7098: if ($parent ne 'instcode') {
7099: $colspan = $maxdepth - $depth - 1;
7100: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
7101: }
7102: }
7103: }
7104: }
7105: return $text;
7106: }
7107:
7108: sub modifiable_userdata_row {
7109: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
7110: my ($role,$rolename,$statustype);
7111: $role = $item;
7112: if ($context eq 'cancreate') {
7113: if ($item =~ /^emailusername_(.+)$/) {
7114: $statustype = $1;
7115: $role = 'emailusername';
7116: if (ref($usertypes) eq 'HASH') {
7117: if ($usertypes->{$statustype}) {
7118: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
7119: } else {
7120: $rolename = &mt('Data provided by user');
7121: }
7122: }
7123: }
7124: } elsif ($context eq 'selfcreate') {
7125: if (ref($usertypes) eq 'HASH') {
7126: $rolename = $usertypes->{$role};
7127: } else {
7128: $rolename = $role;
7129: }
7130: } else {
7131: if ($role eq 'cr') {
7132: $rolename = &mt('Custom role');
7133: } else {
7134: $rolename = &Apache::lonnet::plaintext($role);
7135: }
7136: }
7137: my (@fields,%fieldtitles);
7138: if (ref($fieldsref) eq 'ARRAY') {
7139: @fields = @{$fieldsref};
7140: } else {
7141: @fields = ('lastname','firstname','middlename','generation',
7142: 'permanentemail','id');
7143: }
7144: if ((ref($titlesref) eq 'HASH')) {
7145: %fieldtitles = %{$titlesref};
7146: } else {
7147: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7148: }
7149: my $output;
7150: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
7151: $output = '<tr '.$css_class.'>'.
7152: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
7153: '<td class="LC_left_item" colspan="2"><table>';
7154: my $rem;
7155: my %checks;
7156: if (ref($settings) eq 'HASH') {
7157: if (ref($settings->{$context}) eq 'HASH') {
7158: if (ref($settings->{$context}->{$role}) eq 'HASH') {
7159: my $hashref = $settings->{$context}->{$role};
7160: if ($role eq 'emailusername') {
7161: if ($statustype) {
7162: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
7163: $hashref = $settings->{$context}->{$role}->{$statustype};
7164: if (ref($hashref) eq 'HASH') {
7165: foreach my $field (@fields) {
7166: if ($hashref->{$field}) {
7167: $checks{$field} = $hashref->{$field};
7168: }
7169: }
7170: }
7171: }
7172: }
7173: } else {
7174: if (ref($hashref) eq 'HASH') {
7175: foreach my $field (@fields) {
7176: if ($hashref->{$field}) {
7177: $checks{$field} = ' checked="checked" ';
7178: }
7179: }
7180: }
7181: }
7182: }
7183: }
7184: }
7185:
7186: for (my $i=0; $i<@fields; $i++) {
7187: my $rem = $i%($numinrow);
7188: if ($rem == 0) {
7189: if ($i > 0) {
7190: $output .= '</tr>';
7191: }
7192: $output .= '<tr>';
7193: }
7194: my $check = ' ';
7195: unless ($role eq 'emailusername') {
7196: if (exists($checks{$fields[$i]})) {
7197: $check = $checks{$fields[$i]}
7198: } else {
7199: if ($role eq 'st') {
7200: if (ref($settings) ne 'HASH') {
7201: $check = ' checked="checked" ';
7202: }
7203: }
7204: }
7205: }
7206: $output .= '<td class="LC_left_item">'.
7207: '<span class="LC_nobreak">';
7208: if ($role eq 'emailusername') {
7209: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
7210: $checks{$fields[$i]} = 'omit';
7211: }
7212: foreach my $option ('required','optional','omit') {
7213: my $checked='';
7214: if ($checks{$fields[$i]} eq $option) {
7215: $checked='checked="checked" ';
7216: }
7217: $output .= '<label>'.
7218: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
7219: &mt($option).'</label>'.(' ' x2);
7220: }
7221: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
7222: } else {
7223: $output .= '<label>'.
7224: '<input type="checkbox" name="canmodify_'.$role.'" '.
7225: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
7226: '</label>';
7227: }
7228: $output .= '</span></td>';
7229: $rem = @fields%($numinrow);
7230: }
7231: my $colsleft = $numinrow - $rem;
7232: if ($colsleft > 1 ) {
7233: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7234: ' </td>';
7235: } elsif ($colsleft == 1) {
7236: $output .= '<td class="LC_left_item"> </td>';
7237: }
7238: $output .= '</tr></table></td></tr>';
7239: return $output;
7240: }
7241:
7242: sub insttypes_row {
7243: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
7244: $customcss,$rowstyle) = @_;
7245: my %lt = &Apache::lonlocal::texthash (
7246: cansearch => 'Users allowed to search',
7247: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
7248: lockablenames => 'User preference to lock name',
7249: overrides => "Override domain's helpdesk settings based on requester's affiliation",
7250: );
7251: my $showdom;
7252: if ($context eq 'cansearch') {
7253: $showdom = ' ('.$dom.')';
7254: }
7255: my $class = 'LC_left_item';
7256: if ($context eq 'statustocreate') {
7257: $class = 'LC_right_item';
7258: }
7259: my $css_class;
7260: if ($$rowtotal%2) {
7261: $css_class = 'LC_odd_row';
7262: }
7263: if ($customcss) {
7264: $css_class .= ' '.$customcss;
7265: }
7266: $css_class =~ s/^\s+//;
7267: if ($css_class) {
7268: $css_class = ' class="'.$css_class.'"';
7269: }
7270: if ($rowstyle) {
7271: $css_class .= ' style="'.$rowstyle.'"';
7272: }
7273: if ($onclick) {
7274: $onclick = 'onclick="'.$onclick.'" ';
7275: }
7276: my $output = '<tr'.$css_class.'>'.
7277: '<td>'.$lt{$context}.$showdom.
7278: '</td><td class="'.$class.'" colspan="2"><table>';
7279: my $rem;
7280: if (ref($types) eq 'ARRAY') {
7281: for (my $i=0; $i<@{$types}; $i++) {
7282: if (defined($usertypes->{$types->[$i]})) {
7283: my $rem = $i%($numinrow);
7284: if ($rem == 0) {
7285: if ($i > 0) {
7286: $output .= '</tr>';
7287: }
7288: $output .= '<tr>';
7289: }
7290: my $check = ' ';
7291: if (ref($settings) eq 'HASH') {
7292: if (ref($settings->{$context}) eq 'ARRAY') {
7293: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
7294: $check = ' checked="checked" ';
7295: }
7296: } elsif (ref($settings->{$context}) eq 'HASH') {
7297: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
7298: $check = ' checked="checked" ';
7299: }
7300: } elsif ($context eq 'statustocreate') {
7301: $check = ' checked="checked" ';
7302: }
7303: }
7304: $output .= '<td class="LC_left_item">'.
7305: '<span class="LC_nobreak"><label>'.
7306: '<input type="checkbox" name="'.$context.'" '.
7307: 'value="'.$types->[$i].'"'.$check.'/>'.
7308: $usertypes->{$types->[$i]}.'</label></span></td>';
7309: }
7310: }
7311: $rem = @{$types}%($numinrow);
7312: }
7313: my $colsleft = $numinrow - $rem;
7314: if ($context eq 'overrides') {
7315: if ($colsleft > 1) {
7316: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
7317: } else {
7318: $output .= '<td class="LC_left_item">';
7319: }
7320: $output .= ' ';
7321: } else {
7322: if (($rem == 0) && (@{$types} > 0)) {
7323: $output .= '<tr>';
7324: }
7325: if ($colsleft > 1) {
7326: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
7327: } else {
7328: $output .= '<td class="LC_left_item">';
7329: }
7330: my $defcheck = ' ';
7331: if (ref($settings) eq 'HASH') {
7332: if (ref($settings->{$context}) eq 'ARRAY') {
7333: if (grep(/^default$/,@{$settings->{$context}})) {
7334: $defcheck = ' checked="checked" ';
7335: }
7336: } elsif ($context eq 'statustocreate') {
7337: $defcheck = ' checked="checked" ';
7338: }
7339: }
7340: $output .= '<span class="LC_nobreak"><label>'.
7341: '<input type="checkbox" name="'.$context.'" '.
7342: 'value="default"'.$defcheck.'/>'.
7343: $othertitle.'</label></span>';
7344: }
7345: $output .= '</td></tr></table></td></tr>';
7346: return $output;
7347: }
7348:
7349: sub sorted_searchtitles {
7350: my %searchtitles = &Apache::lonlocal::texthash(
7351: 'uname' => 'username',
7352: 'lastname' => 'last name',
7353: 'lastfirst' => 'last name, first name',
7354: );
7355: my @titleorder = ('uname','lastname','lastfirst');
7356: return (\%searchtitles,\@titleorder);
7357: }
7358:
7359: sub sorted_searchtypes {
7360: my %srchtypes_desc = (
7361: exact => 'is exact match',
7362: contains => 'contains ..',
7363: begins => 'begins with ..',
7364: );
7365: my @srchtypeorder = ('exact','begins','contains');
7366: return (\%srchtypes_desc,\@srchtypeorder);
7367: }
7368:
7369: sub usertype_update_row {
7370: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
7371: my $datatable;
7372: my $numinrow = 4;
7373: foreach my $type (@{$types}) {
7374: if (defined($usertypes->{$type})) {
7375: $$rownums ++;
7376: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
7377: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
7378: '</td><td class="LC_left_item"><table>';
7379: for (my $i=0; $i<@{$fields}; $i++) {
7380: my $rem = $i%($numinrow);
7381: if ($rem == 0) {
7382: if ($i > 0) {
7383: $datatable .= '</tr>';
7384: }
7385: $datatable .= '<tr>';
7386: }
7387: my $check = ' ';
7388: if (ref($settings) eq 'HASH') {
7389: if (ref($settings->{'fields'}) eq 'HASH') {
7390: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
7391: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
7392: $check = ' checked="checked" ';
7393: }
7394: }
7395: }
7396: }
7397:
7398: if ($i == @{$fields}-1) {
7399: my $colsleft = $numinrow - $rem;
7400: if ($colsleft > 1) {
7401: $datatable .= '<td colspan="'.$colsleft.'">';
7402: } else {
7403: $datatable .= '<td>';
7404: }
7405: } else {
7406: $datatable .= '<td>';
7407: }
7408: $datatable .= '<span class="LC_nobreak"><label>'.
7409: '<input type="checkbox" name="updateable_'.$type.
7410: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
7411: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
7412: }
7413: $datatable .= '</tr></table></td></tr>';
7414: }
7415: }
7416: return $datatable;
7417: }
7418:
7419: sub modify_login {
7420: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
7421: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
7422: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
7423: %title = ( coursecatalog => 'Display course catalog',
7424: adminmail => 'Display administrator E-mail address',
7425: helpdesk => 'Display "Contact Helpdesk" link',
7426: newuser => 'Link for visitors to create a user account',
7427: loginheader => 'Log-in box header');
7428: @offon = ('off','on');
7429: if (ref($domconfig{login}) eq 'HASH') {
7430: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
7431: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
7432: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
7433: }
7434: }
7435: }
7436: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
7437: \%domconfig,\%loginhash);
7438: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
7439: foreach my $item (@toggles) {
7440: $loginhash{login}{$item} = $env{'form.'.$item};
7441: }
7442: $loginhash{login}{loginheader} = $env{'form.loginheader'};
7443: if (ref($colchanges{'login'}) eq 'HASH') {
7444: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
7445: \%loginhash);
7446: }
7447:
7448: my %servers = &Apache::lonnet::internet_dom_servers($dom);
7449: my %domservers = &Apache::lonnet::get_servers($dom);
7450: my @loginvia_attribs = ('serverpath','custompath','exempt');
7451: if (keys(%servers) > 1) {
7452: foreach my $lonhost (keys(%servers)) {
7453: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
7454: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
7455: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
7456: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
7457: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
7458: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7459: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7460: $changes{'loginvia'}{$lonhost} = 1;
7461: } else {
7462: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
7463: $changes{'loginvia'}{$lonhost} = 1;
7464: }
7465: } else {
7466: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7467: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7468: $changes{'loginvia'}{$lonhost} = 1;
7469: }
7470: }
7471: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
7472: foreach my $item (@loginvia_attribs) {
7473: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
7474: }
7475: } else {
7476: foreach my $item (@loginvia_attribs) {
7477: my $new = $env{'form.'.$lonhost.'_'.$item};
7478: if (($item eq 'serverpath') && ($new eq 'custom')) {
7479: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
7480: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7481: $new = '/';
7482: }
7483: }
7484: if (($item eq 'custompath') &&
7485: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7486: $new = '';
7487: }
7488: if ($new ne $curr_loginvia{$lonhost}{$item}) {
7489: $changes{'loginvia'}{$lonhost} = 1;
7490: }
7491: if ($item eq 'exempt') {
7492: $new = &check_exempt_addresses($new);
7493: }
7494: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7495: }
7496: }
7497: } else {
7498: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7499: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7500: $changes{'loginvia'}{$lonhost} = 1;
7501: foreach my $item (@loginvia_attribs) {
7502: my $new = $env{'form.'.$lonhost.'_'.$item};
7503: if (($item eq 'serverpath') && ($new eq 'custom')) {
7504: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7505: $new = '/';
7506: }
7507: }
7508: if (($item eq 'custompath') &&
7509: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7510: $new = '';
7511: }
7512: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7513: }
7514: }
7515: }
7516: }
7517: }
7518:
7519: my $servadm = $r->dir_config('lonAdmEMail');
7520: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
7521: if (ref($domconfig{'login'}) eq 'HASH') {
7522: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
7523: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
7524: if ($lang eq 'nolang') {
7525: push(@currlangs,$lang);
7526: } elsif (defined($langchoices{$lang})) {
7527: push(@currlangs,$lang);
7528: } else {
7529: next;
7530: }
7531: }
7532: }
7533: }
7534: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
7535: if (@currlangs > 0) {
7536: foreach my $lang (@currlangs) {
7537: if (grep(/^\Q$lang\E$/,@delurls)) {
7538: $changes{'helpurl'}{$lang} = 1;
7539: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
7540: $changes{'helpurl'}{$lang} = 1;
7541: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
7542: push(@newlangs,$lang);
7543: } else {
7544: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
7545: }
7546: }
7547: }
7548: unless (grep(/^nolang$/,@currlangs)) {
7549: if ($env{'form.loginhelpurl_nolang.filename'}) {
7550: $changes{'helpurl'}{'nolang'} = 1;
7551: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
7552: push(@newlangs,'nolang');
7553: }
7554: }
7555: if ($env{'form.loginhelpurl_add_lang'}) {
7556: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
7557: ($env{'form.loginhelpurl_add_file.filename'})) {
7558: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
7559: $addedfile = $env{'form.loginhelpurl_add_lang'};
7560: }
7561: }
7562: if ((@newlangs > 0) || ($addedfile)) {
7563: my $error;
7564: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7565: if ($configuserok eq 'ok') {
7566: if ($switchserver) {
7567: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
7568: } elsif ($author_ok eq 'ok') {
7569: my @allnew = @newlangs;
7570: if ($addedfile ne '') {
7571: push(@allnew,$addedfile);
7572: }
7573: foreach my $lang (@allnew) {
7574: my $formelem = 'loginhelpurl_'.$lang;
7575: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
7576: $formelem = 'loginhelpurl_add_file';
7577: }
7578: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7579: "help/$lang",'','',$newfile{$lang});
7580: if ($result eq 'ok') {
7581: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
7582: $changes{'helpurl'}{$lang} = 1;
7583: } else {
7584: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
7585: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
7586: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
7587: (!grep(/^\Q$lang\E$/,@delurls))) {
7588: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
7589: }
7590: }
7591: }
7592: } else {
7593: $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);
7594: }
7595: } else {
7596: $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);
7597: }
7598: if ($error) {
7599: &Apache::lonnet::logthis($error);
7600: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7601: }
7602: }
7603:
7604: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
7605: if (ref($domconfig{'login'}) eq 'HASH') {
7606: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
7607: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
7608: if ($domservers{$lonhost}) {
7609: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7610: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
7611: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
7612: }
7613: }
7614: }
7615: }
7616: }
7617: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
7618: foreach my $lonhost (sort(keys(%domservers))) {
7619: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7620: $changes{'headtag'}{$lonhost} = 1;
7621: } else {
7622: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
7623: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
7624: }
7625: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
7626: push(@newhosts,$lonhost);
7627: } elsif ($currheadtagurls{$lonhost}) {
7628: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
7629: if ($currexempt{$lonhost}) {
7630: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
7631: $changes{'headtag'}{$lonhost} = 1;
7632: }
7633: } elsif ($possexempt{$lonhost}) {
7634: $changes{'headtag'}{$lonhost} = 1;
7635: }
7636: if ($possexempt{$lonhost}) {
7637: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7638: }
7639: }
7640: }
7641: }
7642: if (@newhosts) {
7643: my $error;
7644: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7645: if ($configuserok eq 'ok') {
7646: if ($switchserver) {
7647: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
7648: } elsif ($author_ok eq 'ok') {
7649: foreach my $lonhost (@newhosts) {
7650: my $formelem = 'loginheadtag_'.$lonhost;
7651: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7652: "login/headtag/$lonhost",'','',
7653: $env{'form.loginheadtag_'.$lonhost.'.filename'});
7654: if ($result eq 'ok') {
7655: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
7656: $changes{'headtag'}{$lonhost} = 1;
7657: if ($possexempt{$lonhost}) {
7658: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7659: }
7660: } else {
7661: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
7662: $newheadtagurls{$lonhost},$result);
7663: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
7664: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
7665: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
7666: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
7667: }
7668: }
7669: }
7670: } else {
7671: $error = &mt("Upload of custom markup 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);
7672: }
7673: } else {
7674: $error = &mt("Upload of custom markup file(s) failed because a Domain Configuration user ([_1]) could not be created in domain: [_2]. Error was: [_3].",$confname,$dom,$configuserok);
7675: }
7676: if ($error) {
7677: &Apache::lonnet::logthis($error);
7678: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7679: }
7680: }
7681: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
7682:
7683: my $defaulthelpfile = '/adm/loginproblems.html';
7684: my $defaulttext = &mt('Default in use');
7685:
7686: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
7687: $dom);
7688: if ($putresult eq 'ok') {
7689: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
7690: my %defaultchecked = (
7691: 'coursecatalog' => 'on',
7692: 'helpdesk' => 'on',
7693: 'adminmail' => 'off',
7694: 'newuser' => 'off',
7695: );
7696: if (ref($domconfig{'login'}) eq 'HASH') {
7697: foreach my $item (@toggles) {
7698: if ($defaultchecked{$item} eq 'on') {
7699: if (($domconfig{'login'}{$item} eq '0') &&
7700: ($env{'form.'.$item} eq '1')) {
7701: $changes{$item} = 1;
7702: } elsif (($domconfig{'login'}{$item} eq '' ||
7703: $domconfig{'login'}{$item} eq '1') &&
7704: ($env{'form.'.$item} eq '0')) {
7705: $changes{$item} = 1;
7706: }
7707: } elsif ($defaultchecked{$item} eq 'off') {
7708: if (($domconfig{'login'}{$item} eq '1') &&
7709: ($env{'form.'.$item} eq '0')) {
7710: $changes{$item} = 1;
7711: } elsif (($domconfig{'login'}{$item} eq '' ||
7712: $domconfig{'login'}{$item} eq '0') &&
7713: ($env{'form.'.$item} eq '1')) {
7714: $changes{$item} = 1;
7715: }
7716: }
7717: }
7718: }
7719: if (keys(%changes) > 0 || $colchgtext) {
7720: &Apache::loncommon::devalidate_domconfig_cache($dom);
7721: if (ref($lastactref) eq 'HASH') {
7722: $lastactref->{'domainconfig'} = 1;
7723: }
7724: $resulttext = &mt('Changes made:').'<ul>';
7725: foreach my $item (sort(keys(%changes))) {
7726: if ($item eq 'loginvia') {
7727: if (ref($changes{$item}) eq 'HASH') {
7728: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
7729: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
7730: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
7731: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
7732: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
7733: $protocol = 'http' if ($protocol ne 'https');
7734: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
7735:
7736: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
7737: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
7738: } else {
7739: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
7740: }
7741: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
7742: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
7743: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
7744: }
7745: $resulttext .= '</li>';
7746: } else {
7747: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
7748: }
7749: } else {
7750: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
7751: }
7752: }
7753: $resulttext .= '</ul></li>';
7754: }
7755: } elsif ($item eq 'helpurl') {
7756: if (ref($changes{$item}) eq 'HASH') {
7757: foreach my $lang (sort(keys(%{$changes{$item}}))) {
7758: if (grep(/^\Q$lang\E$/,@delurls)) {
7759: my ($chg,$link);
7760: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
7761: if ($lang eq 'nolang') {
7762: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
7763: } else {
7764: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
7765: }
7766: $resulttext .= '<li>'.$chg.'</li>';
7767: } else {
7768: my $chg;
7769: if ($lang eq 'nolang') {
7770: $chg = &mt('custom log-in help file for no preferred language');
7771: } else {
7772: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
7773: }
7774: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
7775: $loginhash{'login'}{'helpurl'}{$lang}.
7776: '?inhibitmenu=yes',$chg,600,500).
7777: '</li>';
7778: }
7779: }
7780: }
7781: } elsif ($item eq 'headtag') {
7782: if (ref($changes{$item}) eq 'HASH') {
7783: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
7784: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7785: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
7786: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7787: $resulttext .= '<li><a href="'.
7788: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
7789: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
7790: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
7791: if ($possexempt{$lonhost}) {
7792: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
7793: } else {
7794: $resulttext .= &mt('included for any client IP');
7795: }
7796: $resulttext .= '</li>';
7797: }
7798: }
7799: }
7800: } elsif ($item eq 'captcha') {
7801: if (ref($loginhash{'login'}) eq 'HASH') {
7802: my $chgtxt;
7803: if ($loginhash{'login'}{$item} eq 'notused') {
7804: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
7805: } else {
7806: my %captchas = &captcha_phrases();
7807: if ($captchas{$loginhash{'login'}{$item}}) {
7808: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
7809: } else {
7810: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
7811: }
7812: }
7813: $resulttext .= '<li>'.$chgtxt.'</li>';
7814: }
7815: } elsif ($item eq 'recaptchakeys') {
7816: if (ref($loginhash{'login'}) eq 'HASH') {
7817: my ($privkey,$pubkey);
7818: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
7819: $pubkey = $loginhash{'login'}{$item}{'public'};
7820: $privkey = $loginhash{'login'}{$item}{'private'};
7821: }
7822: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
7823: if (!$pubkey) {
7824: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
7825: } else {
7826: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7827: }
7828: if (!$privkey) {
7829: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
7830: } else {
7831: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
7832: }
7833: $chgtxt .= '</ul>';
7834: $resulttext .= '<li>'.$chgtxt.'</li>';
7835: }
7836: } elsif ($item eq 'recaptchaversion') {
7837: if (ref($loginhash{'login'}) eq 'HASH') {
7838: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
7839: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
7840: '</li>';
7841: }
7842: }
7843: } else {
7844: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
7845: }
7846: }
7847: $resulttext .= $colchgtext.'</ul>';
7848: } else {
7849: $resulttext = &mt('No changes made to log-in page settings');
7850: }
7851: } else {
7852: $resulttext = '<span class="LC_error">'.
7853: &mt('An error occurred: [_1]',$putresult).'</span>';
7854: }
7855: if ($errors) {
7856: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
7857: $errors.'</ul>';
7858: }
7859: return $resulttext;
7860: }
7861:
7862: sub check_exempt_addresses {
7863: my ($iplist) = @_;
7864: $iplist =~ s/^\s+//;
7865: $iplist =~ s/\s+$//;
7866: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
7867: my (@okips,$new);
7868: foreach my $ip (@poss_ips) {
7869: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
7870: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
7871: push(@okips,$ip);
7872: }
7873: }
7874: }
7875: if (@okips > 0) {
7876: $new = join(',',@okips);
7877: } else {
7878: $new = '';
7879: }
7880: return $new;
7881: }
7882:
7883: sub color_font_choices {
7884: my %choices =
7885: &Apache::lonlocal::texthash (
7886: img => "Header",
7887: bgs => "Background colors",
7888: links => "Link colors",
7889: images => "Images",
7890: font => "Font color",
7891: fontmenu => "Font menu",
7892: pgbg => "Page",
7893: tabbg => "Header",
7894: sidebg => "Border",
7895: link => "Link",
7896: alink => "Active link",
7897: vlink => "Visited link",
7898: );
7899: return %choices;
7900: }
7901:
7902: sub modify_rolecolors {
7903: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
7904: my ($resulttext,%rolehash);
7905: $rolehash{'rolecolors'} = {};
7906: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
7907: if ($domconfig{'rolecolors'} eq '') {
7908: $domconfig{'rolecolors'} = {};
7909: }
7910: }
7911: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
7912: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
7913: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
7914: $dom);
7915: if ($putresult eq 'ok') {
7916: if (keys(%changes) > 0) {
7917: &Apache::loncommon::devalidate_domconfig_cache($dom);
7918: if (ref($lastactref) eq 'HASH') {
7919: $lastactref->{'domainconfig'} = 1;
7920: }
7921: $resulttext = &display_colorchgs($dom,\%changes,$roles,
7922: $rolehash{'rolecolors'});
7923: } else {
7924: $resulttext = &mt('No changes made to default color schemes');
7925: }
7926: } else {
7927: $resulttext = '<span class="LC_error">'.
7928: &mt('An error occurred: [_1]',$putresult).'</span>';
7929: }
7930: if ($errors) {
7931: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7932: $errors.'</ul>';
7933: }
7934: return $resulttext;
7935: }
7936:
7937: sub modify_colors {
7938: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
7939: my (%changes,%choices);
7940: my @bgs;
7941: my @links = ('link','alink','vlink');
7942: my @logintext;
7943: my @images;
7944: my $servadm = $r->dir_config('lonAdmEMail');
7945: my $errors;
7946: my %defaults;
7947: foreach my $role (@{$roles}) {
7948: if ($role eq 'login') {
7949: %choices = &login_choices();
7950: @logintext = ('textcol','bgcol');
7951: } else {
7952: %choices = &color_font_choices();
7953: }
7954: if ($role eq 'login') {
7955: @images = ('img','logo','domlogo','login');
7956: @bgs = ('pgbg','mainbg','sidebg');
7957: } else {
7958: @images = ('img');
7959: @bgs = ('pgbg','tabbg','sidebg');
7960: }
7961: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
7962: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
7963: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
7964: }
7965: if ($role eq 'login') {
7966: foreach my $item (@logintext) {
7967: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7968: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7969: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7970: }
7971: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
7972: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7973: }
7974: }
7975: } else {
7976: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
7977: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
7978: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
7979: }
7980: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
7981: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
7982: }
7983: }
7984: foreach my $item (@bgs) {
7985: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7986: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7987: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7988: }
7989: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
7990: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7991: }
7992: }
7993: foreach my $item (@links) {
7994: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7995: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7996: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7997: }
7998: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
7999: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8000: }
8001: }
8002: my ($configuserok,$author_ok,$switchserver) =
8003: &config_check($dom,$confname,$servadm);
8004: my ($width,$height) = &thumb_dimensions();
8005: if (ref($domconfig->{$role}) ne 'HASH') {
8006: $domconfig->{$role} = {};
8007: }
8008: foreach my $img (@images) {
8009: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
8010: if (defined($env{'form.login_showlogo_'.$img})) {
8011: $confhash->{$role}{'showlogo'}{$img} = 1;
8012: } else {
8013: $confhash->{$role}{'showlogo'}{$img} = 0;
8014: }
8015: }
8016: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
8017: && !defined($domconfig->{$role}{$img})
8018: && !$env{'form.'.$role.'_del_'.$img}
8019: && $env{'form.'.$role.'_import_'.$img}) {
8020: # import the old configured image from the .tab setting
8021: # if they haven't provided a new one
8022: $domconfig->{$role}{$img} =
8023: $env{'form.'.$role.'_import_'.$img};
8024: }
8025: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
8026: my $error;
8027: if ($configuserok eq 'ok') {
8028: if ($switchserver) {
8029: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
8030: } else {
8031: if ($author_ok eq 'ok') {
8032: my ($result,$logourl) =
8033: &publishlogo($r,'upload',$role.'_'.$img,
8034: $dom,$confname,$img,$width,$height);
8035: if ($result eq 'ok') {
8036: $confhash->{$role}{$img} = $logourl;
8037: $changes{$role}{'images'}{$img} = 1;
8038: } else {
8039: $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);
8040: }
8041: } else {
8042: $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);
8043: }
8044: }
8045: } else {
8046: $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);
8047: }
8048: if ($error) {
8049: &Apache::lonnet::logthis($error);
8050: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8051: }
8052: } elsif ($domconfig->{$role}{$img} ne '') {
8053: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
8054: my $error;
8055: if ($configuserok eq 'ok') {
8056: # is confname an author?
8057: if ($switchserver eq '') {
8058: if ($author_ok eq 'ok') {
8059: my ($result,$logourl) =
8060: &publishlogo($r,'copy',$domconfig->{$role}{$img},
8061: $dom,$confname,$img,$width,$height);
8062: if ($result eq 'ok') {
8063: $confhash->{$role}{$img} = $logourl;
8064: $changes{$role}{'images'}{$img} = 1;
8065: }
8066: }
8067: }
8068: }
8069: }
8070: }
8071: }
8072: if (ref($domconfig) eq 'HASH') {
8073: if (ref($domconfig->{$role}) eq 'HASH') {
8074: foreach my $img (@images) {
8075: if ($domconfig->{$role}{$img} ne '') {
8076: if ($env{'form.'.$role.'_del_'.$img}) {
8077: $confhash->{$role}{$img} = '';
8078: $changes{$role}{'images'}{$img} = 1;
8079: } else {
8080: if ($confhash->{$role}{$img} eq '') {
8081: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
8082: }
8083: }
8084: } else {
8085: if ($env{'form.'.$role.'_del_'.$img}) {
8086: $confhash->{$role}{$img} = '';
8087: $changes{$role}{'images'}{$img} = 1;
8088: }
8089: }
8090: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
8091: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
8092: if ($confhash->{$role}{'showlogo'}{$img} ne
8093: $domconfig->{$role}{'showlogo'}{$img}) {
8094: $changes{$role}{'showlogo'}{$img} = 1;
8095: }
8096: } else {
8097: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8098: $changes{$role}{'showlogo'}{$img} = 1;
8099: }
8100: }
8101: }
8102: }
8103: if ($domconfig->{$role}{'font'} ne '') {
8104: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
8105: $changes{$role}{'font'} = 1;
8106: }
8107: } else {
8108: if ($confhash->{$role}{'font'}) {
8109: $changes{$role}{'font'} = 1;
8110: }
8111: }
8112: if ($role ne 'login') {
8113: if ($domconfig->{$role}{'fontmenu'} ne '') {
8114: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
8115: $changes{$role}{'fontmenu'} = 1;
8116: }
8117: } else {
8118: if ($confhash->{$role}{'fontmenu'}) {
8119: $changes{$role}{'fontmenu'} = 1;
8120: }
8121: }
8122: }
8123: foreach my $item (@bgs) {
8124: if ($domconfig->{$role}{$item} ne '') {
8125: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8126: $changes{$role}{'bgs'}{$item} = 1;
8127: }
8128: } else {
8129: if ($confhash->{$role}{$item}) {
8130: $changes{$role}{'bgs'}{$item} = 1;
8131: }
8132: }
8133: }
8134: foreach my $item (@links) {
8135: if ($domconfig->{$role}{$item} ne '') {
8136: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8137: $changes{$role}{'links'}{$item} = 1;
8138: }
8139: } else {
8140: if ($confhash->{$role}{$item}) {
8141: $changes{$role}{'links'}{$item} = 1;
8142: }
8143: }
8144: }
8145: foreach my $item (@logintext) {
8146: if ($domconfig->{$role}{$item} ne '') {
8147: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8148: $changes{$role}{'logintext'}{$item} = 1;
8149: }
8150: } else {
8151: if ($confhash->{$role}{$item}) {
8152: $changes{$role}{'logintext'}{$item} = 1;
8153: }
8154: }
8155: }
8156: } else {
8157: &default_change_checker($role,\@images,\@links,\@bgs,
8158: \@logintext,$confhash,\%changes);
8159: }
8160: } else {
8161: &default_change_checker($role,\@images,\@links,\@bgs,
8162: \@logintext,$confhash,\%changes);
8163: }
8164: }
8165: return ($errors,%changes);
8166: }
8167:
8168: sub config_check {
8169: my ($dom,$confname,$servadm) = @_;
8170: my ($configuserok,$author_ok,$switchserver,%currroles);
8171: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
8172: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
8173: $confname,$servadm);
8174: if ($configuserok eq 'ok') {
8175: $switchserver = &check_switchserver($dom,$confname);
8176: if ($switchserver eq '') {
8177: $author_ok = &check_authorstatus($dom,$confname,%currroles);
8178: }
8179: }
8180: return ($configuserok,$author_ok,$switchserver);
8181: }
8182:
8183: sub default_change_checker {
8184: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
8185: foreach my $item (@{$links}) {
8186: if ($confhash->{$role}{$item}) {
8187: $changes->{$role}{'links'}{$item} = 1;
8188: }
8189: }
8190: foreach my $item (@{$bgs}) {
8191: if ($confhash->{$role}{$item}) {
8192: $changes->{$role}{'bgs'}{$item} = 1;
8193: }
8194: }
8195: foreach my $item (@{$logintext}) {
8196: if ($confhash->{$role}{$item}) {
8197: $changes->{$role}{'logintext'}{$item} = 1;
8198: }
8199: }
8200: foreach my $img (@{$images}) {
8201: if ($env{'form.'.$role.'_del_'.$img}) {
8202: $confhash->{$role}{$img} = '';
8203: $changes->{$role}{'images'}{$img} = 1;
8204: }
8205: if ($role eq 'login') {
8206: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8207: $changes->{$role}{'showlogo'}{$img} = 1;
8208: }
8209: }
8210: }
8211: if ($confhash->{$role}{'font'}) {
8212: $changes->{$role}{'font'} = 1;
8213: }
8214: }
8215:
8216: sub display_colorchgs {
8217: my ($dom,$changes,$roles,$confhash) = @_;
8218: my (%choices,$resulttext);
8219: if (!grep(/^login$/,@{$roles})) {
8220: $resulttext = &mt('Changes made:').'<br />';
8221: }
8222: foreach my $role (@{$roles}) {
8223: if ($role eq 'login') {
8224: %choices = &login_choices();
8225: } else {
8226: %choices = &color_font_choices();
8227: }
8228: if (ref($changes->{$role}) eq 'HASH') {
8229: if ($role ne 'login') {
8230: $resulttext .= '<h4>'.&mt($role).'</h4>';
8231: }
8232: foreach my $key (sort(keys(%{$changes->{$role}}))) {
8233: if ($role ne 'login') {
8234: $resulttext .= '<ul>';
8235: }
8236: if (ref($changes->{$role}{$key}) eq 'HASH') {
8237: if ($role ne 'login') {
8238: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
8239: }
8240: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
8241: if (($role eq 'login') && ($key eq 'showlogo')) {
8242: if ($confhash->{$role}{$key}{$item}) {
8243: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
8244: } else {
8245: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
8246: }
8247: } elsif ($confhash->{$role}{$item} eq '') {
8248: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
8249: } else {
8250: my $newitem = $confhash->{$role}{$item};
8251: if ($key eq 'images') {
8252: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
8253: }
8254: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
8255: }
8256: }
8257: if ($role ne 'login') {
8258: $resulttext .= '</ul></li>';
8259: }
8260: } else {
8261: if ($confhash->{$role}{$key} eq '') {
8262: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
8263: } else {
8264: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
8265: }
8266: }
8267: if ($role ne 'login') {
8268: $resulttext .= '</ul>';
8269: }
8270: }
8271: }
8272: }
8273: return $resulttext;
8274: }
8275:
8276: sub thumb_dimensions {
8277: return ('200','50');
8278: }
8279:
8280: sub check_dimensions {
8281: my ($inputfile) = @_;
8282: my ($fullwidth,$fullheight);
8283: if ($inputfile =~ m|^[/\w.\-]+$|) {
8284: if (open(PIPE,"identify $inputfile 2>&1 |")) {
8285: my $imageinfo = <PIPE>;
8286: if (!close(PIPE)) {
8287: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
8288: }
8289: chomp($imageinfo);
8290: my ($fullsize) =
8291: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
8292: if ($fullsize) {
8293: ($fullwidth,$fullheight) = split(/x/,$fullsize);
8294: }
8295: }
8296: }
8297: return ($fullwidth,$fullheight);
8298: }
8299:
8300: sub check_configuser {
8301: my ($uhome,$dom,$confname,$servadm) = @_;
8302: my ($configuserok,%currroles);
8303: if ($uhome eq 'no_host') {
8304: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
8305: my $configpass = &LONCAPA::Enrollment::create_password();
8306: $configuserok =
8307: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
8308: $configpass,'','','','','',undef,$servadm);
8309: } else {
8310: $configuserok = 'ok';
8311: %currroles =
8312: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
8313: }
8314: return ($configuserok,%currroles);
8315: }
8316:
8317: sub check_authorstatus {
8318: my ($dom,$confname,%currroles) = @_;
8319: my $author_ok;
8320: if (!$currroles{':'.$dom.':au'}) {
8321: my $start = time;
8322: my $end = 0;
8323: $author_ok =
8324: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
8325: 'au',$end,$start,'','','domconfig');
8326: } else {
8327: $author_ok = 'ok';
8328: }
8329: return $author_ok;
8330: }
8331:
8332: sub publishlogo {
8333: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
8334: my ($output,$fname,$logourl);
8335: if ($action eq 'upload') {
8336: $fname=$env{'form.'.$formname.'.filename'};
8337: chop($env{'form.'.$formname});
8338: } else {
8339: ($fname) = ($formname =~ /([^\/]+)$/);
8340: }
8341: if ($savefileas ne '') {
8342: $fname = $savefileas;
8343: }
8344: $fname=&Apache::lonnet::clean_filename($fname);
8345: # See if there is anything left
8346: unless ($fname) { return ('error: no uploaded file'); }
8347: $fname="$subdir/$fname";
8348: my $docroot=$r->dir_config('lonDocRoot');
8349: my $filepath="$docroot/priv";
8350: my $relpath = "$dom/$confname";
8351: my ($fnamepath,$file,$fetchthumb);
8352: $file=$fname;
8353: if ($fname=~m|/|) {
8354: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
8355: }
8356: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
8357: my $count;
8358: for ($count=5;$count<=$#parts;$count++) {
8359: $filepath.="/$parts[$count]";
8360: if ((-e $filepath)!=1) {
8361: mkdir($filepath,02770);
8362: }
8363: }
8364: # Check for bad extension and disallow upload
8365: if ($file=~/\.(\w+)$/ &&
8366: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8367: $output =
8368: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
8369: } elsif ($file=~/\.(\w+)$/ &&
8370: !defined(&Apache::loncommon::fileembstyle($1))) {
8371: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8372: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
8373: $output = &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
8374: } elsif (-d "$filepath/$file") {
8375: $output = &mt('Filename is a directory name - rename the file and re-upload');
8376: } else {
8377: my $source = $filepath.'/'.$file;
8378: my $logfile;
8379: if (!open($logfile,">>$source".'.log')) {
8380: return (&mt('No write permission to Authoring Space'));
8381: }
8382: print $logfile
8383: "\n================= Publish ".localtime()." ================\n".
8384: $env{'user.name'}.':'.$env{'user.domain'}."\n";
8385: # Save the file
8386: if (!open(FH,'>'.$source)) {
8387: &Apache::lonnet::logthis('Failed to create '.$source);
8388: return (&mt('Failed to create file'));
8389: }
8390: if ($action eq 'upload') {
8391: if (!print FH ($env{'form.'.$formname})) {
8392: &Apache::lonnet::logthis('Failed to write to '.$source);
8393: return (&mt('Failed to write file'));
8394: }
8395: } else {
8396: my $original = &Apache::lonnet::filelocation('',$formname);
8397: if(!copy($original,$source)) {
8398: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
8399: return (&mt('Failed to write file'));
8400: }
8401: }
8402: close(FH);
8403: chmod(0660, $source); # Permissions to rw-rw---.
8404:
8405: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
8406: my $copyfile=$targetdir.'/'.$file;
8407:
8408: my @parts=split(/\//,$targetdir);
8409: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
8410: for (my $count=5;$count<=$#parts;$count++) {
8411: $path.="/$parts[$count]";
8412: if (!-e $path) {
8413: print $logfile "\nCreating directory ".$path;
8414: mkdir($path,02770);
8415: }
8416: }
8417: my $versionresult;
8418: if (-e $copyfile) {
8419: $versionresult = &logo_versioning($targetdir,$file,$logfile);
8420: } else {
8421: $versionresult = 'ok';
8422: }
8423: if ($versionresult eq 'ok') {
8424: if (copy($source,$copyfile)) {
8425: print $logfile "\nCopied original source to ".$copyfile."\n";
8426: $output = 'ok';
8427: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
8428: push(@{$modified_urls},[$copyfile,$source]);
8429: my $metaoutput =
8430: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
8431: unless ($registered_cleanup) {
8432: my $handlers = $r->get_handlers('PerlCleanupHandler');
8433: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8434: $registered_cleanup=1;
8435: }
8436: } else {
8437: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
8438: $output = &mt('Failed to copy file to RES space').", $!";
8439: }
8440: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
8441: my $inputfile = $filepath.'/'.$file;
8442: my $outfile = $filepath.'/'.'tn-'.$file;
8443: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
8444: if ($fullwidth ne '' && $fullheight ne '') {
8445: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
8446: my $thumbsize = $thumbwidth.'x'.$thumbheight;
8447: system("convert -sample $thumbsize $inputfile $outfile");
8448: chmod(0660, $filepath.'/tn-'.$file);
8449: if (-e $outfile) {
8450: my $copyfile=$targetdir.'/tn-'.$file;
8451: if (copy($outfile,$copyfile)) {
8452: print $logfile "\nCopied source to ".$copyfile."\n";
8453: my $thumb_metaoutput =
8454: &write_metadata($dom,$confname,$formname,
8455: $targetdir,'tn-'.$file,$logfile);
8456: push(@{$modified_urls},[$copyfile,$outfile]);
8457: unless ($registered_cleanup) {
8458: my $handlers = $r->get_handlers('PerlCleanupHandler');
8459: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8460: $registered_cleanup=1;
8461: }
8462: } else {
8463: print $logfile "\nUnable to write ".$copyfile.
8464: ':'.$!."\n";
8465: }
8466: }
8467: }
8468: }
8469: }
8470: } else {
8471: $output = $versionresult;
8472: }
8473: }
8474: return ($output,$logourl);
8475: }
8476:
8477: sub logo_versioning {
8478: my ($targetdir,$file,$logfile) = @_;
8479: my $target = $targetdir.'/'.$file;
8480: my ($maxversion,$fn,$extn,$output);
8481: $maxversion = 0;
8482: if ($file =~ /^(.+)\.(\w+)$/) {
8483: $fn=$1;
8484: $extn=$2;
8485: }
8486: opendir(DIR,$targetdir);
8487: while (my $filename=readdir(DIR)) {
8488: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
8489: $maxversion=($1>$maxversion)?$1:$maxversion;
8490: }
8491: }
8492: $maxversion++;
8493: print $logfile "\nCreating old version ".$maxversion."\n";
8494: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
8495: if (copy($target,$copyfile)) {
8496: print $logfile "Copied old target to ".$copyfile."\n";
8497: $copyfile=$copyfile.'.meta';
8498: if (copy($target.'.meta',$copyfile)) {
8499: print $logfile "Copied old target metadata to ".$copyfile."\n";
8500: $output = 'ok';
8501: } else {
8502: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
8503: $output = &mt('Failed to copy old meta').", $!, ";
8504: }
8505: } else {
8506: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
8507: $output = &mt('Failed to copy old target').", $!, ";
8508: }
8509: return $output;
8510: }
8511:
8512: sub write_metadata {
8513: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
8514: my (%metadatafields,%metadatakeys,$output);
8515: $metadatafields{'title'}=$formname;
8516: $metadatafields{'creationdate'}=time;
8517: $metadatafields{'lastrevisiondate'}=time;
8518: $metadatafields{'copyright'}='public';
8519: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
8520: $env{'user.domain'};
8521: $metadatafields{'authorspace'}=$confname.':'.$dom;
8522: $metadatafields{'domain'}=$dom;
8523: {
8524: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
8525: my $mfh;
8526: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
8527: foreach (sort(keys(%metadatafields))) {
8528: unless ($_=~/\./) {
8529: my $unikey=$_;
8530: $unikey=~/^([A-Za-z]+)/;
8531: my $tag=$1;
8532: $tag=~tr/A-Z/a-z/;
8533: print $mfh "\n\<$tag";
8534: foreach (split(/\,/,$metadatakeys{$unikey})) {
8535: my $value=$metadatafields{$unikey.'.'.$_};
8536: $value=~s/\"/\'\'/g;
8537: print $mfh ' '.$_.'="'.$value.'"';
8538: }
8539: print $mfh '>'.
8540: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
8541: .'</'.$tag.'>';
8542: }
8543: }
8544: $output = 'ok';
8545: print $logfile "\nWrote metadata";
8546: close($mfh);
8547: } else {
8548: print $logfile "\nFailed to open metadata file";
8549: $output = &mt('Could not write metadata');
8550: }
8551: }
8552: return $output;
8553: }
8554:
8555: sub notifysubscribed {
8556: foreach my $targetsource (@{$modified_urls}){
8557: next unless (ref($targetsource) eq 'ARRAY');
8558: my ($target,$source)=@{$targetsource};
8559: if ($source ne '') {
8560: if (open(my $logfh,'>>'.$source.'.log')) {
8561: print $logfh "\nCleanup phase: Notifications\n";
8562: my @subscribed=&subscribed_hosts($target);
8563: foreach my $subhost (@subscribed) {
8564: print $logfh "\nNotifying host ".$subhost.':';
8565: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
8566: print $logfh $reply;
8567: }
8568: my @subscribedmeta=&subscribed_hosts("$target.meta");
8569: foreach my $subhost (@subscribedmeta) {
8570: print $logfh "\nNotifying host for metadata only ".$subhost.':';
8571: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
8572: $subhost);
8573: print $logfh $reply;
8574: }
8575: print $logfh "\n============ Done ============\n";
8576: close($logfh);
8577: }
8578: }
8579: }
8580: return OK;
8581: }
8582:
8583: sub subscribed_hosts {
8584: my ($target) = @_;
8585: my @subscribed;
8586: if (open(my $fh,"<$target.subscription")) {
8587: while (my $subline=<$fh>) {
8588: if ($subline =~ /^($match_lonid):/) {
8589: my $host = $1;
8590: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
8591: unless (grep(/^\Q$host\E$/,@subscribed)) {
8592: push(@subscribed,$host);
8593: }
8594: }
8595: }
8596: }
8597: }
8598: return @subscribed;
8599: }
8600:
8601: sub check_switchserver {
8602: my ($dom,$confname) = @_;
8603: my ($allowed,$switchserver);
8604: my $home = &Apache::lonnet::homeserver($confname,$dom);
8605: if ($home eq 'no_host') {
8606: $home = &Apache::lonnet::domain($dom,'primary');
8607: }
8608: my @ids=&Apache::lonnet::current_machine_ids();
8609: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
8610: if (!$allowed) {
8611: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
8612: }
8613: return $switchserver;
8614: }
8615:
8616: sub modify_quotas {
8617: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
8618: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
8619: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
8620: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
8621: $validationfieldsref);
8622: if ($action eq 'quotas') {
8623: $context = 'tools';
8624: } else {
8625: $context = $action;
8626: }
8627: if ($context eq 'requestcourses') {
8628: @usertools = ('official','unofficial','community','textbook');
8629: @options =('norequest','approval','validate','autolimit');
8630: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
8631: %titles = &courserequest_titles();
8632: $toolregexp = join('|',@usertools);
8633: %conditions = &courserequest_conditions();
8634: $confname = $dom.'-domainconfig';
8635: my $servadm = $r->dir_config('lonAdmEMail');
8636: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8637: ($validationitemsref,$validationnamesref,$validationfieldsref) =
8638: &Apache::loncoursequeueadmin::requestcourses_validation_types();
8639: } elsif ($context eq 'requestauthor') {
8640: @usertools = ('author');
8641: %titles = &authorrequest_titles();
8642: } else {
8643: @usertools = ('aboutme','blog','webdav','portfolio');
8644: %titles = &tool_titles();
8645: }
8646: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8647: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8648: foreach my $key (keys(%env)) {
8649: if ($context eq 'requestcourses') {
8650: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
8651: my $item = $1;
8652: my $type = $2;
8653: if ($type =~ /^limit_(.+)/) {
8654: $limithash{$item}{$1} = $env{$key};
8655: } else {
8656: $confhash{$item}{$type} = $env{$key};
8657: }
8658: }
8659: } elsif ($context eq 'requestauthor') {
8660: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
8661: $confhash{$1} = $env{$key};
8662: }
8663: } else {
8664: if ($key =~ /^form\.quota_(.+)$/) {
8665: $confhash{'defaultquota'}{$1} = $env{$key};
8666: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
8667: $confhash{'authorquota'}{$1} = $env{$key};
8668: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
8669: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
8670: }
8671: }
8672: }
8673: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
8674: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
8675: @approvalnotify = sort(@approvalnotify);
8676: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
8677: my @crstypes = ('official','unofficial','community','textbook');
8678: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
8679: foreach my $type (@hasuniquecode) {
8680: if (grep(/^\Q$type\E$/,@crstypes)) {
8681: $confhash{'uniquecode'}{$type} = 1;
8682: }
8683: }
8684: my (%newbook,%allpos);
8685: if ($context eq 'requestcourses') {
8686: foreach my $type ('textbooks','templates') {
8687: @{$allpos{$type}} = ();
8688: my $invalid;
8689: if ($type eq 'textbooks') {
8690: $invalid = &mt('Invalid LON-CAPA course for textbook');
8691: } else {
8692: $invalid = &mt('Invalid LON-CAPA course for template');
8693: }
8694: if ($env{'form.'.$type.'_addbook'}) {
8695: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
8696: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
8697: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
8698: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
8699: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
8700: } else {
8701: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
8702: my $position = $env{'form.'.$type.'_addbook_pos'};
8703: $position =~ s/\D+//g;
8704: if ($position ne '') {
8705: $allpos{$type}[$position] = $newbook{$type};
8706: }
8707: }
8708: } else {
8709: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
8710: }
8711: }
8712: }
8713: }
8714: if (ref($domconfig{$action}) eq 'HASH') {
8715: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
8716: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
8717: $changes{'notify'}{'approval'} = 1;
8718: }
8719: } else {
8720: if ($confhash{'notify'}{'approval'}) {
8721: $changes{'notify'}{'approval'} = 1;
8722: }
8723: }
8724: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
8725: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8726: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
8727: unless ($confhash{'uniquecode'}{$crstype}) {
8728: $changes{'uniquecode'} = 1;
8729: }
8730: }
8731: unless ($changes{'uniquecode'}) {
8732: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
8733: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
8734: $changes{'uniquecode'} = 1;
8735: }
8736: }
8737: }
8738: } else {
8739: $changes{'uniquecode'} = 1;
8740: }
8741: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
8742: $changes{'uniquecode'} = 1;
8743: }
8744: if ($context eq 'requestcourses') {
8745: foreach my $type ('textbooks','templates') {
8746: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8747: my %deletions;
8748: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
8749: if (@todelete) {
8750: map { $deletions{$_} = 1; } @todelete;
8751: }
8752: my %imgdeletions;
8753: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
8754: if (@todeleteimages) {
8755: map { $imgdeletions{$_} = 1; } @todeleteimages;
8756: }
8757: my $maxnum = $env{'form.'.$type.'_maxnum'};
8758: for (my $i=0; $i<=$maxnum; $i++) {
8759: my $itemid = $env{'form.'.$type.'_id_'.$i};
8760: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
8761: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
8762: if ($deletions{$key}) {
8763: if ($domconfig{$action}{$type}{$key}{'image'}) {
8764: #FIXME need to obsolete item in RES space
8765: }
8766: next;
8767: } else {
8768: my $newpos = $env{'form.'.$itemid};
8769: $newpos =~ s/\D+//g;
8770: foreach my $item ('subject','title','publisher','author') {
8771: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8772: ($type eq 'templates'));
8773: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
8774: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
8775: $changes{$type}{$key} = 1;
8776: }
8777: }
8778: $allpos{$type}[$newpos] = $key;
8779: }
8780: if ($imgdeletions{$key}) {
8781: $changes{$type}{$key} = 1;
8782: #FIXME need to obsolete item in RES space
8783: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
8784: my ($cdom,$cnum) = split(/_/,$key);
8785: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
8786: $cdom,$cnum,$type,$configuserok,
8787: $switchserver,$author_ok);
8788: if ($imgurl) {
8789: $confhash{$type}{$key}{'image'} = $imgurl;
8790: $changes{$type}{$key} = 1;
8791: }
8792: if ($error) {
8793: &Apache::lonnet::logthis($error);
8794: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8795: }
8796: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
8797: $confhash{$type}{$key}{'image'} =
8798: $domconfig{$action}{$type}{$key}{'image'};
8799: }
8800: }
8801: }
8802: }
8803: }
8804: }
8805: } else {
8806: if ($confhash{'notify'}{'approval'}) {
8807: $changes{'notify'}{'approval'} = 1;
8808: }
8809: if (ref($confhash{'uniquecode'} eq 'HASH')) {
8810: $changes{'uniquecode'} = 1;
8811: }
8812: }
8813: if ($context eq 'requestcourses') {
8814: foreach my $type ('textbooks','templates') {
8815: if ($newbook{$type}) {
8816: $changes{$type}{$newbook{$type}} = 1;
8817: foreach my $item ('subject','title','publisher','author') {
8818: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8819: ($type eq 'template'));
8820: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
8821: if ($env{'form.'.$type.'_addbook_'.$item}) {
8822: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
8823: }
8824: }
8825: if ($type eq 'textbooks') {
8826: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
8827: my ($cdom,$cnum) = split(/_/,$newbook{$type});
8828: my ($imageurl,$error) =
8829: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
8830: $configuserok,$switchserver,$author_ok);
8831: if ($imageurl) {
8832: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
8833: }
8834: if ($error) {
8835: &Apache::lonnet::logthis($error);
8836: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8837: }
8838: }
8839: }
8840: }
8841: if (@{$allpos{$type}} > 0) {
8842: my $idx = 0;
8843: foreach my $item (@{$allpos{$type}}) {
8844: if ($item ne '') {
8845: $confhash{$type}{$item}{'order'} = $idx;
8846: if (ref($domconfig{$action}) eq 'HASH') {
8847: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8848: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
8849: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
8850: $changes{$type}{$item} = 1;
8851: }
8852: }
8853: }
8854: }
8855: $idx ++;
8856: }
8857: }
8858: }
8859: }
8860: if (ref($validationitemsref) eq 'ARRAY') {
8861: foreach my $item (@{$validationitemsref}) {
8862: if ($item eq 'fields') {
8863: my @changed;
8864: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
8865: if (@{$confhash{'validation'}{$item}} > 0) {
8866: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
8867: }
8868: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8869: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8870: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
8871: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
8872: $domconfig{'requestcourses'}{'validation'}{$item});
8873: } else {
8874: @changed = @{$confhash{'validation'}{$item}};
8875: }
8876: } else {
8877: @changed = @{$confhash{'validation'}{$item}};
8878: }
8879: } else {
8880: @changed = @{$confhash{'validation'}{$item}};
8881: }
8882: if (@changed) {
8883: if ($confhash{'validation'}{$item}) {
8884: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
8885: } else {
8886: $changes{'validation'}{$item} = &mt('None');
8887: }
8888: }
8889: } else {
8890: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
8891: if ($item eq 'markup') {
8892: if ($env{'form.requestcourses_validation_'.$item}) {
8893: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
8894: }
8895: }
8896: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8897: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8898: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
8899: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8900: }
8901: } else {
8902: if ($confhash{'validation'}{$item} ne '') {
8903: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8904: }
8905: }
8906: } else {
8907: if ($confhash{'validation'}{$item} ne '') {
8908: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8909: }
8910: }
8911: }
8912: }
8913: }
8914: if ($env{'form.validationdc'}) {
8915: my $newval = $env{'form.validationdc'};
8916: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
8917: if (exists($domcoords{$newval})) {
8918: $confhash{'validation'}{'dc'} = $newval;
8919: }
8920: }
8921: if (ref($confhash{'validation'}) eq 'HASH') {
8922: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8923: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8924: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8925: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
8926: if ($confhash{'validation'}{'dc'} eq '') {
8927: $changes{'validation'}{'dc'} = &mt('None');
8928: } else {
8929: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8930: }
8931: }
8932: } elsif ($confhash{'validation'}{'dc'} ne '') {
8933: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8934: }
8935: } elsif ($confhash{'validation'}{'dc'} ne '') {
8936: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8937: }
8938: } elsif ($confhash{'validation'}{'dc'} ne '') {
8939: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8940: }
8941: } else {
8942: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8943: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8944: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8945: $changes{'validation'}{'dc'} = &mt('None');
8946: }
8947: }
8948: }
8949: }
8950: }
8951: } else {
8952: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
8953: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
8954: }
8955: foreach my $item (@usertools) {
8956: foreach my $type (@{$types},'default','_LC_adv') {
8957: my $unset;
8958: if ($context eq 'requestcourses') {
8959: $unset = '0';
8960: if ($type eq '_LC_adv') {
8961: $unset = '';
8962: }
8963: if ($confhash{$item}{$type} eq 'autolimit') {
8964: $confhash{$item}{$type} .= '=';
8965: unless ($limithash{$item}{$type} =~ /\D/) {
8966: $confhash{$item}{$type} .= $limithash{$item}{$type};
8967: }
8968: }
8969: } elsif ($context eq 'requestauthor') {
8970: $unset = '0';
8971: if ($type eq '_LC_adv') {
8972: $unset = '';
8973: }
8974: } else {
8975: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
8976: $confhash{$item}{$type} = 1;
8977: } else {
8978: $confhash{$item}{$type} = 0;
8979: }
8980: }
8981: if (ref($domconfig{$action}) eq 'HASH') {
8982: if ($action eq 'requestauthor') {
8983: if ($domconfig{$action}{$type} ne $confhash{$type}) {
8984: $changes{$type} = 1;
8985: }
8986: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
8987: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
8988: $changes{$item}{$type} = 1;
8989: }
8990: } else {
8991: if ($context eq 'requestcourses') {
8992: if ($confhash{$item}{$type} ne $unset) {
8993: $changes{$item}{$type} = 1;
8994: }
8995: } else {
8996: if (!$confhash{$item}{$type}) {
8997: $changes{$item}{$type} = 1;
8998: }
8999: }
9000: }
9001: } else {
9002: if ($context eq 'requestcourses') {
9003: if ($confhash{$item}{$type} ne $unset) {
9004: $changes{$item}{$type} = 1;
9005: }
9006: } elsif ($context eq 'requestauthor') {
9007: if ($confhash{$type} ne $unset) {
9008: $changes{$type} = 1;
9009: }
9010: } else {
9011: if (!$confhash{$item}{$type}) {
9012: $changes{$item}{$type} = 1;
9013: }
9014: }
9015: }
9016: }
9017: }
9018: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
9019: if (ref($domconfig{'quotas'}) eq 'HASH') {
9020: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9021: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
9022: if (exists($confhash{'defaultquota'}{$key})) {
9023: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
9024: $changes{'defaultquota'}{$key} = 1;
9025: }
9026: } else {
9027: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
9028: }
9029: }
9030: } else {
9031: foreach my $key (keys(%{$domconfig{'quotas'}})) {
9032: if (exists($confhash{'defaultquota'}{$key})) {
9033: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
9034: $changes{'defaultquota'}{$key} = 1;
9035: }
9036: } else {
9037: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
9038: }
9039: }
9040: }
9041: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9042: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
9043: if (exists($confhash{'authorquota'}{$key})) {
9044: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
9045: $changes{'authorquota'}{$key} = 1;
9046: }
9047: } else {
9048: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
9049: }
9050: }
9051: }
9052: }
9053: if (ref($confhash{'defaultquota'}) eq 'HASH') {
9054: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
9055: if (ref($domconfig{'quotas'}) eq 'HASH') {
9056: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9057: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
9058: $changes{'defaultquota'}{$key} = 1;
9059: }
9060: } else {
9061: if (!exists($domconfig{'quotas'}{$key})) {
9062: $changes{'defaultquota'}{$key} = 1;
9063: }
9064: }
9065: } else {
9066: $changes{'defaultquota'}{$key} = 1;
9067: }
9068: }
9069: }
9070: if (ref($confhash{'authorquota'}) eq 'HASH') {
9071: foreach my $key (keys(%{$confhash{'authorquota'}})) {
9072: if (ref($domconfig{'quotas'}) eq 'HASH') {
9073: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9074: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
9075: $changes{'authorquota'}{$key} = 1;
9076: }
9077: } else {
9078: $changes{'authorquota'}{$key} = 1;
9079: }
9080: } else {
9081: $changes{'authorquota'}{$key} = 1;
9082: }
9083: }
9084: }
9085: }
9086:
9087: if ($context eq 'requestauthor') {
9088: $domdefaults{'requestauthor'} = \%confhash;
9089: } else {
9090: foreach my $key (keys(%confhash)) {
9091: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
9092: $domdefaults{$key} = $confhash{$key};
9093: }
9094: }
9095: }
9096:
9097: my %quotahash = (
9098: $action => { %confhash }
9099: );
9100: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
9101: $dom);
9102: if ($putresult eq 'ok') {
9103: if (keys(%changes) > 0) {
9104: my $cachetime = 24*60*60;
9105: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
9106: if (ref($lastactref) eq 'HASH') {
9107: $lastactref->{'domdefaults'} = 1;
9108: }
9109: $resulttext = &mt('Changes made:').'<ul>';
9110: unless (($context eq 'requestcourses') ||
9111: ($context eq 'requestauthor')) {
9112: if (ref($changes{'defaultquota'}) eq 'HASH') {
9113: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
9114: foreach my $type (@{$types},'default') {
9115: if (defined($changes{'defaultquota'}{$type})) {
9116: my $typetitle = $usertypes->{$type};
9117: if ($type eq 'default') {
9118: $typetitle = $othertitle;
9119: }
9120: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
9121: }
9122: }
9123: $resulttext .= '</ul></li>';
9124: }
9125: if (ref($changes{'authorquota'}) eq 'HASH') {
9126: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
9127: foreach my $type (@{$types},'default') {
9128: if (defined($changes{'authorquota'}{$type})) {
9129: my $typetitle = $usertypes->{$type};
9130: if ($type eq 'default') {
9131: $typetitle = $othertitle;
9132: }
9133: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
9134: }
9135: }
9136: $resulttext .= '</ul></li>';
9137: }
9138: }
9139: my %newenv;
9140: foreach my $item (@usertools) {
9141: my (%haschgs,%inconf);
9142: if ($context eq 'requestauthor') {
9143: %haschgs = %changes;
9144: %inconf = %confhash;
9145: } else {
9146: if (ref($changes{$item}) eq 'HASH') {
9147: %haschgs = %{$changes{$item}};
9148: }
9149: if (ref($confhash{$item}) eq 'HASH') {
9150: %inconf = %{$confhash{$item}};
9151: }
9152: }
9153: if (keys(%haschgs) > 0) {
9154: my $newacc =
9155: &Apache::lonnet::usertools_access($env{'user.name'},
9156: $env{'user.domain'},
9157: $item,'reload',$context);
9158: if (($context eq 'requestcourses') ||
9159: ($context eq 'requestauthor')) {
9160: if ($env{'environment.canrequest.'.$item} ne $newacc) {
9161: $newenv{'environment.canrequest.'.$item} = $newacc;
9162: }
9163: } else {
9164: if ($env{'environment.availabletools.'.$item} ne $newacc) {
9165: $newenv{'environment.availabletools.'.$item} = $newacc;
9166: }
9167: }
9168: unless ($context eq 'requestauthor') {
9169: $resulttext .= '<li>'.$titles{$item}.'<ul>';
9170: }
9171: foreach my $type (@{$types},'default','_LC_adv') {
9172: if ($haschgs{$type}) {
9173: my $typetitle = $usertypes->{$type};
9174: if ($type eq 'default') {
9175: $typetitle = $othertitle;
9176: } elsif ($type eq '_LC_adv') {
9177: $typetitle = 'LON-CAPA Advanced Users';
9178: }
9179: if ($inconf{$type}) {
9180: if ($context eq 'requestcourses') {
9181: my $cond;
9182: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
9183: if ($1 eq '') {
9184: $cond = &mt('(Automatic processing of any request).');
9185: } else {
9186: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
9187: }
9188: } else {
9189: $cond = $conditions{$inconf{$type}};
9190: }
9191: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
9192: } elsif ($context eq 'requestauthor') {
9193: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
9194: $titles{$inconf{$type}},$typetitle);
9195:
9196: } else {
9197: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
9198: }
9199: } else {
9200: if ($type eq '_LC_adv') {
9201: if ($inconf{$type} eq '0') {
9202: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9203: } else {
9204: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
9205: }
9206: } else {
9207: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9208: }
9209: }
9210: }
9211: }
9212: unless ($context eq 'requestauthor') {
9213: $resulttext .= '</ul></li>';
9214: }
9215: }
9216: }
9217: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
9218: if (ref($changes{'notify'}) eq 'HASH') {
9219: if ($changes{'notify'}{'approval'}) {
9220: if (ref($confhash{'notify'}) eq 'HASH') {
9221: if ($confhash{'notify'}{'approval'}) {
9222: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
9223: } else {
9224: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
9225: }
9226: }
9227: }
9228: }
9229: }
9230: if ($action eq 'requestcourses') {
9231: my @offon = ('off','on');
9232: if ($changes{'uniquecode'}) {
9233: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9234: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
9235: $resulttext .= '<li>'.
9236: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
9237: '</li>';
9238: } else {
9239: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
9240: '</li>';
9241: }
9242: }
9243: foreach my $type ('textbooks','templates') {
9244: if (ref($changes{$type}) eq 'HASH') {
9245: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
9246: foreach my $key (sort(keys(%{$changes{$type}}))) {
9247: my %coursehash = &Apache::lonnet::coursedescription($key);
9248: my $coursetitle = $coursehash{'description'};
9249: my $position = $confhash{$type}{$key}{'order'} + 1;
9250: $resulttext .= '<li>';
9251: foreach my $item ('subject','title','publisher','author') {
9252: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9253: ($type eq 'templates'));
9254: my $name = $item.':';
9255: $name =~ s/^(\w)/\U$1/;
9256: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
9257: }
9258: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
9259: if ($type eq 'textbooks') {
9260: if ($confhash{$type}{$key}{'image'}) {
9261: $resulttext .= ' '.&mt('Image: [_1]',
9262: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
9263: ' alt="Textbook cover" />').'<br />';
9264: }
9265: }
9266: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
9267: }
9268: $resulttext .= '</ul></li>';
9269: }
9270: }
9271: if (ref($changes{'validation'}) eq 'HASH') {
9272: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
9273: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
9274: foreach my $item (@{$validationitemsref}) {
9275: if (exists($changes{'validation'}{$item})) {
9276: if ($item eq 'markup') {
9277: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9278: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
9279: } else {
9280: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9281: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
9282: }
9283: }
9284: }
9285: if (exists($changes{'validation'}{'dc'})) {
9286: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
9287: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
9288: }
9289: }
9290: }
9291: }
9292: $resulttext .= '</ul>';
9293: if (keys(%newenv)) {
9294: &Apache::lonnet::appenv(\%newenv);
9295: }
9296: } else {
9297: if ($context eq 'requestcourses') {
9298: $resulttext = &mt('No changes made to rights to request creation of courses.');
9299: } elsif ($context eq 'requestauthor') {
9300: $resulttext = &mt('No changes made to rights to request author space.');
9301: } else {
9302: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
9303: }
9304: }
9305: } else {
9306: $resulttext = '<span class="LC_error">'.
9307: &mt('An error occurred: [_1]',$putresult).'</span>';
9308: }
9309: if ($errors) {
9310: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
9311: '<ul>'.$errors.'</ul></p>';
9312: }
9313: return $resulttext;
9314: }
9315:
9316: sub process_textbook_image {
9317: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
9318: my $filename = $env{'form.'.$caller.'.filename'};
9319: my ($error,$url);
9320: my ($width,$height) = (50,50);
9321: if ($configuserok eq 'ok') {
9322: if ($switchserver) {
9323: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
9324: $switchserver);
9325: } elsif ($author_ok eq 'ok') {
9326: my ($result,$imageurl) =
9327: &publishlogo($r,'upload',$caller,$dom,$confname,
9328: "$type/$dom/$cnum/cover",$width,$height);
9329: if ($result eq 'ok') {
9330: $url = $imageurl;
9331: } else {
9332: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9333: }
9334: } else {
9335: $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);
9336: }
9337: } else {
9338: $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);
9339: }
9340: return ($url,$error);
9341: }
9342:
9343: sub modify_ltitools {
9344: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
9345: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9346: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
9347: my $confname = $dom.'-domainconfig';
9348: my $servadm = $r->dir_config('lonAdmEMail');
9349: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9350: my (%posslti,%possfield);
9351: my @courseroles = ('cc','in','ta','ep','st');
9352: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
9353: map { $posslti{$_} = 1; } @ltiroles;
9354: my @allfields = ('fullname','firstname','lastname','email','user','roles');
9355: map { $possfield{$_} = 1; } @allfields;
9356: my %lt = <itools_names();
9357: if ($env{'form.ltitools_add'}) {
9358: my $title = $env{'form.ltitools_add_title'};
9359: $title =~ s/(`)/'/g;
9360: ($newid,my $error) = &get_ltitools_id($dom,$title);
9361: if ($newid) {
9362: my $position = $env{'form.ltitools_add_pos'};
9363: $position =~ s/\D+//g;
9364: if ($position ne '') {
9365: $allpos[$position] = $newid;
9366: }
9367: $changes{$newid} = 1;
9368: foreach my $item ('title','url','key','secret') {
9369: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
9370: if ($env{'form.ltitools_add_'.$item}) {
9371: if (($item eq 'key') || ($item eq 'secret')) {
9372: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
9373: } else {
9374: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
9375: }
9376: }
9377: }
9378: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
9379: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
9380: }
9381: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
9382: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
9383: }
9384: foreach my $item ('width','height','linktext','explanation') {
9385: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
9386: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
9387: if (($item eq 'width') || ($item eq 'height')) {
9388: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
9389: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
9390: }
9391: } else {
9392: if ($env{'form.ltitools_add_'.$item} ne '') {
9393: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
9394: }
9395: }
9396: }
9397: if ($env{'form.ltitools_add_target'} eq 'window') {
9398: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
9399: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
9400: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
9401: } else {
9402: $confhash{$newid}{'display'}{'target'} = 'iframe';
9403: }
9404: foreach my $item ('passback','roster') {
9405: if ($env{'form.ltitools_add_'.$item}) {
9406: $confhash{$newid}{$item} = 1;
9407: }
9408: }
9409: if ($env{'form.ltitools_add_image.filename'} ne '') {
9410: my ($imageurl,$error) =
9411: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
9412: $configuserok,$switchserver,$author_ok);
9413: if ($imageurl) {
9414: $confhash{$newid}{'image'} = $imageurl;
9415: }
9416: if ($error) {
9417: &Apache::lonnet::logthis($error);
9418: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9419: }
9420: }
9421: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
9422: foreach my $field (@fields) {
9423: if ($possfield{$field}) {
9424: if ($field eq 'roles') {
9425: foreach my $role (@courseroles) {
9426: my $choice = $env{'form.ltitools_add_roles_'.$role};
9427: if (($choice ne '') && ($posslti{$choice})) {
9428: $confhash{$newid}{'roles'}{$role} = $choice;
9429: if ($role eq 'cc') {
9430: $confhash{$newid}{'roles'}{'co'} = $choice;
9431: }
9432: }
9433: }
9434: } else {
9435: $confhash{$newid}{'fields'}{$field} = 1;
9436: }
9437: }
9438: }
9439: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
9440: foreach my $item (@courseconfig) {
9441: $confhash{$newid}{'crsconf'}{$item} = 1;
9442: }
9443: if ($env{'form.ltitools_add_custom'}) {
9444: my $name = $env{'form.ltitools_add_custom_name'};
9445: my $value = $env{'form.ltitools_add_custom_value'};
9446: $value =~ s/(`)/'/g;
9447: $name =~ s/(`)/'/g;
9448: $confhash{$newid}{'custom'}{$name} = $value;
9449: }
9450: } else {
9451: my $error = &mt('Failed to acquire unique ID for new external tool');
9452: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9453: }
9454: }
9455: if (ref($domconfig{$action}) eq 'HASH') {
9456: my %deletions;
9457: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
9458: if (@todelete) {
9459: map { $deletions{$_} = 1; } @todelete;
9460: }
9461: my %customadds;
9462: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
9463: if (@newcustom) {
9464: map { $customadds{$_} = 1; } @newcustom;
9465: }
9466: my %imgdeletions;
9467: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
9468: if (@todeleteimages) {
9469: map { $imgdeletions{$_} = 1; } @todeleteimages;
9470: }
9471: my $maxnum = $env{'form.ltitools_maxnum'};
9472: for (my $i=0; $i<=$maxnum; $i++) {
9473: my $itemid = $env{'form.ltitools_id_'.$i};
9474: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
9475: if ($deletions{$itemid}) {
9476: if ($domconfig{$action}{$itemid}{'image'}) {
9477: #FIXME need to obsolete item in RES space
9478: }
9479: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
9480: next;
9481: } else {
9482: my $newpos = $env{'form.ltitools_'.$itemid};
9483: $newpos =~ s/\D+//g;
9484: foreach my $item ('title','url') {
9485: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
9486: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
9487: $changes{$itemid} = 1;
9488: }
9489: }
9490: foreach my $item ('key','secret') {
9491: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
9492: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
9493: $changes{$itemid} = 1;
9494: }
9495: }
9496: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
9497: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
9498: }
9499: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
9500: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
9501: }
9502: foreach my $size ('width','height') {
9503: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
9504: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
9505: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
9506: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
9507: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9508: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
9509: $changes{$itemid} = 1;
9510: }
9511: } else {
9512: $changes{$itemid} = 1;
9513: }
9514: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9515: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
9516: $changes{$itemid} = 1;
9517: }
9518: }
9519: }
9520: foreach my $item ('linktext','explanation') {
9521: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
9522: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
9523: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
9524: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
9525: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9526: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
9527: $changes{$itemid} = 1;
9528: }
9529: } else {
9530: $changes{$itemid} = 1;
9531: }
9532: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9533: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
9534: $changes{$itemid} = 1;
9535: }
9536: }
9537: }
9538: if ($env{'form.ltitools_target_'.$i} eq 'window') {
9539: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
9540: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
9541: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
9542: } else {
9543: $confhash{$itemid}{'display'}{'target'} = 'iframe';
9544: }
9545: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9546: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
9547: $changes{$itemid} = 1;
9548: }
9549: } else {
9550: $changes{$itemid} = 1;
9551: }
9552: foreach my $extra ('passback','roster') {
9553: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
9554: $confhash{$itemid}{$extra} = 1;
9555: }
9556: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
9557: $changes{$itemid} = 1;
9558: }
9559: }
9560: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
9561: foreach my $item ('label','title','target','linktext','explanation') {
9562: if (grep(/^\Q$item\E$/,@courseconfig)) {
9563: $confhash{$itemid}{'crsconf'}{$item} = 1;
9564: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
9565: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
9566: $changes{$itemid} = 1;
9567: }
9568: } else {
9569: $changes{$itemid} = 1;
9570: }
9571: }
9572: }
9573: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
9574: foreach my $field (@fields) {
9575: if ($possfield{$field}) {
9576: if ($field eq 'roles') {
9577: foreach my $role (@courseroles) {
9578: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
9579: if (($choice ne '') && ($posslti{$choice})) {
9580: $confhash{$itemid}{'roles'}{$role} = $choice;
9581: if ($role eq 'cc') {
9582: $confhash{$itemid}{'roles'}{'co'} = $choice;
9583: }
9584: }
9585: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
9586: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
9587: $changes{$itemid} = 1;
9588: }
9589: } elsif ($confhash{$itemid}{'roles'}{$role}) {
9590: $changes{$itemid} = 1;
9591: }
9592: }
9593: } else {
9594: $confhash{$itemid}{'fields'}{$field} = 1;
9595: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
9596: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
9597: $changes{$itemid} = 1;
9598: }
9599: } else {
9600: $changes{$itemid} = 1;
9601: }
9602: }
9603: }
9604: }
9605: $allpos[$newpos] = $itemid;
9606: }
9607: if ($imgdeletions{$itemid}) {
9608: $changes{$itemid} = 1;
9609: #FIXME need to obsolete item in RES space
9610: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
9611: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
9612: $itemid,$configuserok,$switchserver,
9613: $author_ok);
9614: if ($imgurl) {
9615: $confhash{$itemid}{'image'} = $imgurl;
9616: $changes{$itemid} = 1;
9617: }
9618: if ($error) {
9619: &Apache::lonnet::logthis($error);
9620: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9621: }
9622: } elsif ($domconfig{$action}{$itemid}{'image'}) {
9623: $confhash{$itemid}{'image'} =
9624: $domconfig{$action}{$itemid}{'image'};
9625: }
9626: if ($customadds{$i}) {
9627: my $name = $env{'form.ltitools_custom_name_'.$i};
9628: $name =~ s/(`)/'/g;
9629: $name =~ s/^\s+//;
9630: $name =~ s/\s+$//;
9631: my $value = $env{'form.ltitools_custom_value_'.$i};
9632: $value =~ s/(`)/'/g;
9633: $value =~ s/^\s+//;
9634: $value =~ s/\s+$//;
9635: if ($name ne '') {
9636: $confhash{$itemid}{'custom'}{$name} = $value;
9637: $changes{$itemid} = 1;
9638: }
9639: }
9640: my %customdels;
9641: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
9642: if (@customdeletions) {
9643: $changes{$itemid} = 1;
9644: }
9645: map { $customdels{$_} = 1; } @customdeletions;
9646: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
9647: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
9648: unless ($customdels{$key}) {
9649: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
9650: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
9651: }
9652: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
9653: $changes{$itemid} = 1;
9654: }
9655: }
9656: }
9657: }
9658: unless ($changes{$itemid}) {
9659: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
9660: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
9661: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
9662: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
9663: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
9664: $changes{$itemid} = 1;
9665: last;
9666: }
9667: }
9668: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
9669: $changes{$itemid} = 1;
9670: }
9671: }
9672: last if ($changes{$itemid});
9673: }
9674: }
9675: }
9676: }
9677: }
9678: if (@allpos > 0) {
9679: my $idx = 0;
9680: foreach my $itemid (@allpos) {
9681: if ($itemid ne '') {
9682: $confhash{$itemid}{'order'} = $idx;
9683: if (ref($domconfig{$action}) eq 'HASH') {
9684: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
9685: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
9686: $changes{$itemid} = 1;
9687: }
9688: }
9689: }
9690: $idx ++;
9691: }
9692: }
9693: }
9694: my %ltitoolshash = (
9695: $action => { %confhash }
9696: );
9697: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
9698: $dom);
9699: if ($putresult eq 'ok') {
9700: my %ltienchash = (
9701: $action => { %encconfig }
9702: );
9703: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
9704: if (keys(%changes) > 0) {
9705: my $cachetime = 24*60*60;
9706: my %ltiall = %confhash;
9707: foreach my $id (keys(%ltiall)) {
9708: if (ref($encconfig{$id}) eq 'HASH') {
9709: foreach my $item ('key','secret') {
9710: $ltiall{$id}{$item} = $encconfig{$id}{$item};
9711: }
9712: }
9713: }
9714: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
9715: if (ref($lastactref) eq 'HASH') {
9716: $lastactref->{'ltitools'} = 1;
9717: }
9718: $resulttext = &mt('Changes made:').'<ul>';
9719: my %bynum;
9720: foreach my $itemid (sort(keys(%changes))) {
9721: my $position = $confhash{$itemid}{'order'};
9722: $bynum{$position} = $itemid;
9723: }
9724: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
9725: my $itemid = $bynum{$pos};
9726: if (ref($confhash{$itemid}) ne 'HASH') {
9727: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
9728: } else {
9729: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
9730: if ($confhash{$itemid}{'image'}) {
9731: $resulttext .= ' '.
9732: '<img src="'.$confhash{$itemid}{'image'}.'"'.
9733: ' alt="'.&mt('Tool Provider icon').'" />';
9734: }
9735: $resulttext .= '</li><ul>';
9736: my $position = $pos + 1;
9737: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
9738: foreach my $item ('version','msgtype','url') {
9739: if ($confhash{$itemid}{$item} ne '') {
9740: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
9741: }
9742: }
9743: if ($encconfig{$itemid}{'key'} ne '') {
9744: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
9745: }
9746: if ($encconfig{$itemid}{'secret'} ne '') {
9747: $resulttext .= '<li>'.$lt{'secret'}.': ';
9748: my $num = length($encconfig{$itemid}{'secret'});
9749: $resulttext .= ('*'x$num).'</li>';
9750: }
9751: $resulttext .= '<li>'.&mt('Configurable in course:');
9752: my @possconfig = ('label','title','target','linktext','explanation');
9753: my $numconfig = 0;
9754: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
9755: foreach my $item (@possconfig) {
9756: if ($confhash{$itemid}{'crsconf'}{$item}) {
9757: $numconfig ++;
9758: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
9759: }
9760: }
9761: }
9762: if (!$numconfig) {
9763: $resulttext .= &mt('None');
9764: }
9765: $resulttext .= '</li>';
9766: foreach my $item ('passback','roster') {
9767: $resulttext .= '<li>'.$lt{$item}.' ';
9768: if ($confhash{$itemid}{$item}) {
9769: $resulttext .= &mt('Yes');
9770: } else {
9771: $resulttext .= &mt('No');
9772: }
9773: $resulttext .= '</li>';
9774: }
9775: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
9776: my $displaylist;
9777: if ($confhash{$itemid}{'display'}{'target'}) {
9778: $displaylist = &mt('Display target').': '.
9779: $confhash{$itemid}{'display'}{'target'}.',';
9780: }
9781: foreach my $size ('width','height') {
9782: if ($confhash{$itemid}{'display'}{$size}) {
9783: $displaylist .= (' 'x2).$lt{$size}.': '.
9784: $confhash{$itemid}{'display'}{$size}.',';
9785: }
9786: }
9787: if ($displaylist) {
9788: $displaylist =~ s/,$//;
9789: $resulttext .= '<li>'.$displaylist.'</li>';
9790: }
9791: foreach my $item ('linktext','explanation') {
9792: if ($confhash{$itemid}{'display'}{$item}) {
9793: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
9794: }
9795: }
9796: }
9797: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
9798: my $fieldlist;
9799: foreach my $field (@allfields) {
9800: if ($confhash{$itemid}{'fields'}{$field}) {
9801: $fieldlist .= (' 'x2).$lt{$field}.',';
9802: }
9803: }
9804: if ($fieldlist) {
9805: $fieldlist =~ s/,$//;
9806: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
9807: }
9808: }
9809: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
9810: my $rolemaps;
9811: foreach my $role (@courseroles) {
9812: if ($confhash{$itemid}{'roles'}{$role}) {
9813: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
9814: $confhash{$itemid}{'roles'}{$role}.',';
9815: }
9816: }
9817: if ($rolemaps) {
9818: $rolemaps =~ s/,$//;
9819: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
9820: }
9821: }
9822: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
9823: my $customlist;
9824: if (keys(%{$confhash{$itemid}{'custom'}})) {
9825: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
9826: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
9827: }
9828: }
9829: if ($customlist) {
9830: $resulttext .= '<li>'.&mt('Custom items').':'.$customlist.'</li>';
9831: }
9832: }
9833: $resulttext .= '</ul></li>';
9834: }
9835: }
9836: $resulttext .= '</ul>';
9837: } else {
9838: $resulttext = &mt('No changes made.');
9839: }
9840: } else {
9841: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
9842: }
9843: if ($errors) {
9844: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9845: $errors.'</ul>';
9846: }
9847: return $resulttext;
9848: }
9849:
9850: sub process_ltitools_image {
9851: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
9852: my $filename = $env{'form.'.$caller.'.filename'};
9853: my ($error,$url);
9854: my ($width,$height) = (21,21);
9855: if ($configuserok eq 'ok') {
9856: if ($switchserver) {
9857: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
9858: $switchserver);
9859: } elsif ($author_ok eq 'ok') {
9860: my ($result,$imageurl,$madethumb) =
9861: &publishlogo($r,'upload',$caller,$dom,$confname,
9862: "ltitools/$itemid/icon",$width,$height);
9863: if ($result eq 'ok') {
9864: if ($madethumb) {
9865: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
9866: my $imagethumb = "$path/tn-".$imagefile;
9867: $url = $imagethumb;
9868: } else {
9869: $url = $imageurl;
9870: }
9871: } else {
9872: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9873: }
9874: } else {
9875: $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);
9876: }
9877: } else {
9878: $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);
9879: }
9880: return ($url,$error);
9881: }
9882:
9883: sub get_ltitools_id {
9884: my ($cdom,$title) = @_;
9885: # get lock on ltitools db
9886: my $lockhash = {
9887: lock => $env{'user.name'}.
9888: ':'.$env{'user.domain'},
9889: };
9890: my $tries = 0;
9891: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
9892: my ($id,$error);
9893:
9894: while (($gotlock ne 'ok') && ($tries<10)) {
9895: $tries ++;
9896: sleep (0.1);
9897: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
9898: }
9899: if ($gotlock eq 'ok') {
9900: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
9901: if ($currids{'lock'}) {
9902: delete($currids{'lock'});
9903: if (keys(%currids)) {
9904: my @curr = sort { $a <=> $b } keys(%currids);
9905: if ($curr[-1] =~ /^\d+$/) {
9906: $id = 1 + $curr[-1];
9907: }
9908: } else {
9909: $id = 1;
9910: }
9911: if ($id) {
9912: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
9913: $error = 'nostore';
9914: }
9915: } else {
9916: $error = 'nonumber';
9917: }
9918: }
9919: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
9920: } else {
9921: $error = 'nolock';
9922: }
9923: return ($id,$error);
9924: }
9925:
9926: sub modify_autoenroll {
9927: my ($dom,$lastactref,%domconfig) = @_;
9928: my ($resulttext,%changes);
9929: my %currautoenroll;
9930: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
9931: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
9932: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
9933: }
9934: }
9935: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
9936: my %title = ( run => 'Auto-enrollment active',
9937: sender => 'Sender for notification messages',
9938: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
9939: failsafe => 'Failsafe for no drops if institutional data missing for a section');
9940: my @offon = ('off','on');
9941: my $sender_uname = $env{'form.sender_uname'};
9942: my $sender_domain = $env{'form.sender_domain'};
9943: if ($sender_domain eq '') {
9944: $sender_uname = '';
9945: } elsif ($sender_uname eq '') {
9946: $sender_domain = '';
9947: }
9948: my $coowners = $env{'form.autoassign_coowners'};
9949: my $failsafe = $env{'form.autoenroll_failsafe'};
9950: $failsafe =~ s{^\s+|\s+$}{}g;
9951: if ($failsafe =~ /\D/) {
9952: undef($failsafe);
9953: }
9954: my %autoenrollhash = (
9955: autoenroll => { 'run' => $env{'form.autoenroll_run'},
9956: 'sender_uname' => $sender_uname,
9957: 'sender_domain' => $sender_domain,
9958: 'co-owners' => $coowners,
9959: 'autofailsafe' => $failsafe,
9960: }
9961: );
9962: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
9963: $dom);
9964: if ($putresult eq 'ok') {
9965: if (exists($currautoenroll{'run'})) {
9966: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
9967: $changes{'run'} = 1;
9968: }
9969: } elsif ($autorun) {
9970: if ($env{'form.autoenroll_run'} ne '1') {
9971: $changes{'run'} = 1;
9972: }
9973: }
9974: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
9975: $changes{'sender'} = 1;
9976: }
9977: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
9978: $changes{'sender'} = 1;
9979: }
9980: if ($currautoenroll{'co-owners'} ne '') {
9981: if ($currautoenroll{'co-owners'} ne $coowners) {
9982: $changes{'coowners'} = 1;
9983: }
9984: } elsif ($coowners) {
9985: $changes{'coowners'} = 1;
9986: }
9987: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
9988: $changes{'autofailsafe'} = 1;
9989: }
9990: if (keys(%changes) > 0) {
9991: $resulttext = &mt('Changes made:').'<ul>';
9992: if ($changes{'run'}) {
9993: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
9994: }
9995: if ($changes{'sender'}) {
9996: if ($sender_uname eq '' || $sender_domain eq '') {
9997: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
9998: } else {
9999: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
10000: }
10001: }
10002: if ($changes{'coowners'}) {
10003: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
10004: &Apache::loncommon::devalidate_domconfig_cache($dom);
10005: if (ref($lastactref) eq 'HASH') {
10006: $lastactref->{'domainconfig'} = 1;
10007: }
10008: }
10009: if ($changes{'autofailsafe'}) {
10010: if ($failsafe ne '') {
10011: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
10012: } else {
10013: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
10014: }
10015: &Apache::lonnet::get_domain_defaults($dom,1);
10016: if (ref($lastactref) eq 'HASH') {
10017: $lastactref->{'domdefaults'} = 1;
10018: }
10019: }
10020: $resulttext .= '</ul>';
10021: } else {
10022: $resulttext = &mt('No changes made to auto-enrollment settings');
10023: }
10024: } else {
10025: $resulttext = '<span class="LC_error">'.
10026: &mt('An error occurred: [_1]',$putresult).'</span>';
10027: }
10028: return $resulttext;
10029: }
10030:
10031: sub modify_autoupdate {
10032: my ($dom,%domconfig) = @_;
10033: my ($resulttext,%currautoupdate,%fields,%changes);
10034: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
10035: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
10036: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
10037: }
10038: }
10039: my @offon = ('off','on');
10040: my %title = &Apache::lonlocal::texthash (
10041: run => 'Auto-update:',
10042: classlists => 'Updates to user information in classlists?'
10043: );
10044: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10045: my %fieldtitles = &Apache::lonlocal::texthash (
10046: id => 'Student/Employee ID',
10047: permanentemail => 'E-mail address',
10048: lastname => 'Last Name',
10049: firstname => 'First Name',
10050: middlename => 'Middle Name',
10051: generation => 'Generation',
10052: );
10053: $othertitle = &mt('All users');
10054: if (keys(%{$usertypes}) > 0) {
10055: $othertitle = &mt('Other users');
10056: }
10057: foreach my $key (keys(%env)) {
10058: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
10059: my ($usertype,$item) = ($1,$2);
10060: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
10061: if ($usertype eq 'default') {
10062: push(@{$fields{$1}},$2);
10063: } elsif (ref($types) eq 'ARRAY') {
10064: if (grep(/^\Q$usertype\E$/,@{$types})) {
10065: push(@{$fields{$1}},$2);
10066: }
10067: }
10068: }
10069: }
10070: }
10071: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
10072: @lockablenames = sort(@lockablenames);
10073: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
10074: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
10075: if (@changed) {
10076: $changes{'lockablenames'} = 1;
10077: }
10078: } else {
10079: if (@lockablenames) {
10080: $changes{'lockablenames'} = 1;
10081: }
10082: }
10083: my %updatehash = (
10084: autoupdate => { run => $env{'form.autoupdate_run'},
10085: classlists => $env{'form.classlists'},
10086: fields => {%fields},
10087: lockablenames => \@lockablenames,
10088: }
10089: );
10090: foreach my $key (keys(%currautoupdate)) {
10091: if (($key eq 'run') || ($key eq 'classlists')) {
10092: if (exists($updatehash{autoupdate}{$key})) {
10093: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
10094: $changes{$key} = 1;
10095: }
10096: }
10097: } elsif ($key eq 'fields') {
10098: if (ref($currautoupdate{$key}) eq 'HASH') {
10099: foreach my $item (@{$types},'default') {
10100: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
10101: my $change = 0;
10102: foreach my $type (@{$currautoupdate{$key}{$item}}) {
10103: if (!exists($fields{$item})) {
10104: $change = 1;
10105: last;
10106: } elsif (ref($fields{$item}) eq 'ARRAY') {
10107: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
10108: $change = 1;
10109: last;
10110: }
10111: }
10112: }
10113: if ($change) {
10114: push(@{$changes{$key}},$item);
10115: }
10116: }
10117: }
10118: }
10119: } elsif ($key eq 'lockablenames') {
10120: if (ref($currautoupdate{$key}) eq 'ARRAY') {
10121: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
10122: if (@changed) {
10123: $changes{'lockablenames'} = 1;
10124: }
10125: } else {
10126: if (@lockablenames) {
10127: $changes{'lockablenames'} = 1;
10128: }
10129: }
10130: }
10131: }
10132: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
10133: if (@lockablenames) {
10134: $changes{'lockablenames'} = 1;
10135: }
10136: }
10137: foreach my $item (@{$types},'default') {
10138: if (defined($fields{$item})) {
10139: if (ref($currautoupdate{'fields'}) eq 'HASH') {
10140: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
10141: my $change = 0;
10142: if (ref($fields{$item}) eq 'ARRAY') {
10143: foreach my $type (@{$fields{$item}}) {
10144: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
10145: $change = 1;
10146: last;
10147: }
10148: }
10149: }
10150: if ($change) {
10151: push(@{$changes{'fields'}},$item);
10152: }
10153: } else {
10154: push(@{$changes{'fields'}},$item);
10155: }
10156: } else {
10157: push(@{$changes{'fields'}},$item);
10158: }
10159: }
10160: }
10161: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
10162: $dom);
10163: if ($putresult eq 'ok') {
10164: if (keys(%changes) > 0) {
10165: $resulttext = &mt('Changes made:').'<ul>';
10166: foreach my $key (sort(keys(%changes))) {
10167: if ($key eq 'lockablenames') {
10168: $resulttext .= '<li>';
10169: if (@lockablenames) {
10170: $usertypes->{'default'} = $othertitle;
10171: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
10172: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
10173: } else {
10174: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
10175: }
10176: $resulttext .= '</li>';
10177: } elsif (ref($changes{$key}) eq 'ARRAY') {
10178: foreach my $item (@{$changes{$key}}) {
10179: my @newvalues;
10180: foreach my $type (@{$fields{$item}}) {
10181: push(@newvalues,$fieldtitles{$type});
10182: }
10183: my $newvaluestr;
10184: if (@newvalues > 0) {
10185: $newvaluestr = join(', ',@newvalues);
10186: } else {
10187: $newvaluestr = &mt('none');
10188: }
10189: if ($item eq 'default') {
10190: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
10191: } else {
10192: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
10193: }
10194: }
10195: } else {
10196: my $newvalue;
10197: if ($key eq 'run') {
10198: $newvalue = $offon[$env{'form.autoupdate_run'}];
10199: } else {
10200: $newvalue = $offon[$env{'form.'.$key}];
10201: }
10202: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
10203: }
10204: }
10205: $resulttext .= '</ul>';
10206: } else {
10207: $resulttext = &mt('No changes made to autoupdates');
10208: }
10209: } else {
10210: $resulttext = '<span class="LC_error">'.
10211: &mt('An error occurred: [_1]',$putresult).'</span>';
10212: }
10213: return $resulttext;
10214: }
10215:
10216: sub modify_autocreate {
10217: my ($dom,%domconfig) = @_;
10218: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
10219: if (ref($domconfig{'autocreate'}) eq 'HASH') {
10220: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
10221: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
10222: }
10223: }
10224: my %title= ( xml => 'Auto-creation of courses in XML course description files',
10225: req => 'Auto-creation of validated requests for official courses',
10226: xmldc => 'Identity of course creator of courses from XML files',
10227: );
10228: my @types = ('xml','req');
10229: foreach my $item (@types) {
10230: $newvals{$item} = $env{'form.autocreate_'.$item};
10231: $newvals{$item} =~ s/\D//g;
10232: $newvals{$item} = 0 if ($newvals{$item} eq '');
10233: }
10234: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
10235: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
10236: unless (exists($domcoords{$newvals{'xmldc'}})) {
10237: $newvals{'xmldc'} = '';
10238: }
10239: %autocreatehash = (
10240: autocreate => { xml => $newvals{'xml'},
10241: req => $newvals{'req'},
10242: }
10243: );
10244: if ($newvals{'xmldc'} ne '') {
10245: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
10246: }
10247: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
10248: $dom);
10249: if ($putresult eq 'ok') {
10250: my @items = @types;
10251: if ($newvals{'xml'}) {
10252: push(@items,'xmldc');
10253: }
10254: foreach my $item (@items) {
10255: if (exists($currautocreate{$item})) {
10256: if ($currautocreate{$item} ne $newvals{$item}) {
10257: $changes{$item} = 1;
10258: }
10259: } elsif ($newvals{$item}) {
10260: $changes{$item} = 1;
10261: }
10262: }
10263: if (keys(%changes) > 0) {
10264: my @offon = ('off','on');
10265: $resulttext = &mt('Changes made:').'<ul>';
10266: foreach my $item (@types) {
10267: if ($changes{$item}) {
10268: my $newtxt = $offon[$newvals{$item}];
10269: $resulttext .= '<li>'.
10270: &mt("$title{$item} set to [_1]$newtxt [_2]",
10271: '<b>','</b>').
10272: '</li>';
10273: }
10274: }
10275: if ($changes{'xmldc'}) {
10276: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
10277: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
10278: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
10279: }
10280: $resulttext .= '</ul>';
10281: } else {
10282: $resulttext = &mt('No changes made to auto-creation settings');
10283: }
10284: } else {
10285: $resulttext = '<span class="LC_error">'.
10286: &mt('An error occurred: [_1]',$putresult).'</span>';
10287: }
10288: return $resulttext;
10289: }
10290:
10291: sub modify_directorysrch {
10292: my ($dom,$lastactref,%domconfig) = @_;
10293: my ($resulttext,%changes);
10294: my %currdirsrch;
10295: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
10296: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
10297: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
10298: }
10299: }
10300: my %title = ( available => 'Institutional directory search available',
10301: localonly => 'Other domains can search institution',
10302: lcavailable => 'LON-CAPA directory search available',
10303: lclocalonly => 'Other domains can search LON-CAPA domain',
10304: searchby => 'Search types',
10305: searchtypes => 'Search latitude');
10306: my @offon = ('off','on');
10307: my @otherdoms = ('Yes','No');
10308:
10309: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
10310: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
10311: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
10312:
10313: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10314: if (keys(%{$usertypes}) == 0) {
10315: @cansearch = ('default');
10316: } else {
10317: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
10318: foreach my $type (@{$currdirsrch{'cansearch'}}) {
10319: if (!grep(/^\Q$type\E$/,@cansearch)) {
10320: push(@{$changes{'cansearch'}},$type);
10321: }
10322: }
10323: foreach my $type (@cansearch) {
10324: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
10325: push(@{$changes{'cansearch'}},$type);
10326: }
10327: }
10328: } else {
10329: push(@{$changes{'cansearch'}},@cansearch);
10330: }
10331: }
10332:
10333: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
10334: foreach my $by (@{$currdirsrch{'searchby'}}) {
10335: if (!grep(/^\Q$by\E$/,@searchby)) {
10336: push(@{$changes{'searchby'}},$by);
10337: }
10338: }
10339: foreach my $by (@searchby) {
10340: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
10341: push(@{$changes{'searchby'}},$by);
10342: }
10343: }
10344: } else {
10345: push(@{$changes{'searchby'}},@searchby);
10346: }
10347:
10348: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
10349: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
10350: if (!grep(/^\Q$type\E$/,@searchtypes)) {
10351: push(@{$changes{'searchtypes'}},$type);
10352: }
10353: }
10354: foreach my $type (@searchtypes) {
10355: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
10356: push(@{$changes{'searchtypes'}},$type);
10357: }
10358: }
10359: } else {
10360: if (exists($currdirsrch{'searchtypes'})) {
10361: foreach my $type (@searchtypes) {
10362: if ($type ne $currdirsrch{'searchtypes'}) {
10363: push(@{$changes{'searchtypes'}},$type);
10364: }
10365: }
10366: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
10367: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
10368: }
10369: } else {
10370: push(@{$changes{'searchtypes'}},@searchtypes);
10371: }
10372: }
10373:
10374: my %dirsrch_hash = (
10375: directorysrch => { available => $env{'form.dirsrch_available'},
10376: cansearch => \@cansearch,
10377: localonly => $env{'form.dirsrch_instlocalonly'},
10378: lclocalonly => $env{'form.dirsrch_domlocalonly'},
10379: lcavailable => $env{'form.dirsrch_domavailable'},
10380: searchby => \@searchby,
10381: searchtypes => \@searchtypes,
10382: }
10383: );
10384: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
10385: $dom);
10386: if ($putresult eq 'ok') {
10387: if (exists($currdirsrch{'available'})) {
10388: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
10389: $changes{'available'} = 1;
10390: }
10391: } else {
10392: if ($env{'form.dirsrch_available'} eq '1') {
10393: $changes{'available'} = 1;
10394: }
10395: }
10396: if (exists($currdirsrch{'lcavailable'})) {
10397: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
10398: $changes{'lcavailable'} = 1;
10399: }
10400: } else {
10401: if ($env{'form.dirsrch_lcavailable'} eq '1') {
10402: $changes{'lcavailable'} = 1;
10403: }
10404: }
10405: if (exists($currdirsrch{'localonly'})) {
10406: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
10407: $changes{'localonly'} = 1;
10408: }
10409: } else {
10410: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
10411: $changes{'localonly'} = 1;
10412: }
10413: }
10414: if (exists($currdirsrch{'lclocalonly'})) {
10415: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
10416: $changes{'lclocalonly'} = 1;
10417: }
10418: } else {
10419: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
10420: $changes{'lclocalonly'} = 1;
10421: }
10422: }
10423: if (keys(%changes) > 0) {
10424: $resulttext = &mt('Changes made:').'<ul>';
10425: if ($changes{'available'}) {
10426: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
10427: }
10428: if ($changes{'lcavailable'}) {
10429: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
10430: }
10431: if ($changes{'localonly'}) {
10432: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
10433: }
10434: if ($changes{'lclocalonly'}) {
10435: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
10436: }
10437: if (ref($changes{'cansearch'}) eq 'ARRAY') {
10438: my $chgtext;
10439: if (ref($usertypes) eq 'HASH') {
10440: if (keys(%{$usertypes}) > 0) {
10441: foreach my $type (@{$types}) {
10442: if (grep(/^\Q$type\E$/,@cansearch)) {
10443: $chgtext .= $usertypes->{$type}.'; ';
10444: }
10445: }
10446: if (grep(/^default$/,@cansearch)) {
10447: $chgtext .= $othertitle;
10448: } else {
10449: $chgtext =~ s/\; $//;
10450: }
10451: $resulttext .=
10452: '<li>'.
10453: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
10454: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
10455: '</li>';
10456: }
10457: }
10458: }
10459: if (ref($changes{'searchby'}) eq 'ARRAY') {
10460: my ($searchtitles,$titleorder) = &sorted_searchtitles();
10461: my $chgtext;
10462: foreach my $type (@{$titleorder}) {
10463: if (grep(/^\Q$type\E$/,@searchby)) {
10464: if (defined($searchtitles->{$type})) {
10465: $chgtext .= $searchtitles->{$type}.'; ';
10466: }
10467: }
10468: }
10469: $chgtext =~ s/\; $//;
10470: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
10471: }
10472: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
10473: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
10474: my $chgtext;
10475: foreach my $type (@{$srchtypeorder}) {
10476: if (grep(/^\Q$type\E$/,@searchtypes)) {
10477: if (defined($srchtypes_desc->{$type})) {
10478: $chgtext .= $srchtypes_desc->{$type}.'; ';
10479: }
10480: }
10481: }
10482: $chgtext =~ s/\; $//;
10483: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
10484: }
10485: $resulttext .= '</ul>';
10486: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
10487: if (ref($lastactref) eq 'HASH') {
10488: $lastactref->{'directorysrch'} = 1;
10489: }
10490: } else {
10491: $resulttext = &mt('No changes made to directory search settings');
10492: }
10493: } else {
10494: $resulttext = '<span class="LC_error">'.
10495: &mt('An error occurred: [_1]',$putresult).'</span>';
10496: }
10497: return $resulttext;
10498: }
10499:
10500: sub modify_contacts {
10501: my ($dom,$lastactref,%domconfig) = @_;
10502: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
10503: if (ref($domconfig{'contacts'}) eq 'HASH') {
10504: foreach my $key (keys(%{$domconfig{'contacts'}})) {
10505: $currsetting{$key} = $domconfig{'contacts'}{$key};
10506: }
10507: }
10508: my (%others,%to,%bcc,%includestr,%includeloc);
10509: my @contacts = ('supportemail','adminemail');
10510: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
10511: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
10512: my @toggles = ('reporterrors','reportupdates');
10513: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
10514: foreach my $type (@mailings) {
10515: @{$newsetting{$type}} =
10516: &Apache::loncommon::get_env_multiple('form.'.$type);
10517: foreach my $item (@contacts) {
10518: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
10519: $contacts_hash{contacts}{$type}{$item} = 1;
10520: } else {
10521: $contacts_hash{contacts}{$type}{$item} = 0;
10522: }
10523: }
10524: $others{$type} = $env{'form.'.$type.'_others'};
10525: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
10526: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
10527: $bcc{$type} = $env{'form.'.$type.'_bcc'};
10528: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
10529: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
10530: $includestr{$type} = $env{'form.'.$type.'_includestr'};
10531: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
10532: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
10533: }
10534: }
10535: }
10536: foreach my $item (@contacts) {
10537: $to{$item} = $env{'form.'.$item};
10538: $contacts_hash{'contacts'}{$item} = $to{$item};
10539: }
10540: foreach my $item (@toggles) {
10541: if ($env{'form.'.$item} =~ /^(0|1)$/) {
10542: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
10543: }
10544: }
10545: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
10546: foreach my $field (@{$fields}) {
10547: if (ref($possoptions->{$field}) eq 'ARRAY') {
10548: my $value = $env{'form.helpform_'.$field};
10549: $value =~ s/^\s+|\s+$//g;
10550: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
10551: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
10552: if ($field eq 'screenshot') {
10553: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
10554: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
10555: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
10556: }
10557: }
10558: }
10559: }
10560: }
10561: }
10562: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10563: my (@statuses,%usertypeshash,@overrides);
10564: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
10565: @statuses = @{$types};
10566: if (ref($usertypes) eq 'HASH') {
10567: %usertypeshash = %{$usertypes};
10568: }
10569: }
10570: if (@statuses) {
10571: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
10572: foreach my $type (@possoverrides) {
10573: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
10574: push(@overrides,$type);
10575: }
10576: }
10577: if (@overrides) {
10578: foreach my $type (@overrides) {
10579: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
10580: foreach my $item (@contacts) {
10581: if (grep(/^\Q$item\E$/,@standard)) {
10582: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
10583: $newsetting{'override_'.$type}{$item} = 1;
10584: } else {
10585: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
10586: $newsetting{'override_'.$type}{$item} = 0;
10587: }
10588: }
10589: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
10590: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
10591: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
10592: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
10593: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
10594: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
10595: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
10596: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
10597: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
10598: }
10599: }
10600: }
10601: }
10602: if (keys(%currsetting) > 0) {
10603: foreach my $item (@contacts) {
10604: if ($to{$item} ne $currsetting{$item}) {
10605: $changes{$item} = 1;
10606: }
10607: }
10608: foreach my $type (@mailings) {
10609: foreach my $item (@contacts) {
10610: if (ref($currsetting{$type}) eq 'HASH') {
10611: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
10612: push(@{$changes{$type}},$item);
10613: }
10614: } else {
10615: push(@{$changes{$type}},@{$newsetting{$type}});
10616: }
10617: }
10618: if ($others{$type} ne $currsetting{$type}{'others'}) {
10619: push(@{$changes{$type}},'others');
10620: }
10621: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
10622: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
10623: push(@{$changes{$type}},'bcc');
10624: }
10625: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
10626: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
10627: push(@{$changes{$type}},'include');
10628: }
10629: }
10630: }
10631: if (ref($fields) eq 'ARRAY') {
10632: if (ref($currsetting{'helpform'}) eq 'HASH') {
10633: foreach my $field (@{$fields}) {
10634: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
10635: push(@{$changes{'helpform'}},$field);
10636: }
10637: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10638: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
10639: push(@{$changes{'helpform'}},'maxsize');
10640: }
10641: }
10642: }
10643: } else {
10644: foreach my $field (@{$fields}) {
10645: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10646: push(@{$changes{'helpform'}},$field);
10647: }
10648: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10649: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10650: push(@{$changes{'helpform'}},'maxsize');
10651: }
10652: }
10653: }
10654: }
10655: }
10656: if (@statuses) {
10657: if (ref($currsetting{'overrides'}) eq 'HASH') {
10658: foreach my $key (keys(%{$currsetting{'overrides'}})) {
10659: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
10660: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
10661: foreach my $item (@contacts,'bcc','others','include') {
10662: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
10663: push(@{$changes{'overrides'}},$key);
10664: last;
10665: }
10666: }
10667: } else {
10668: push(@{$changes{'overrides'}},$key);
10669: }
10670: }
10671: }
10672: foreach my $key (@overrides) {
10673: unless (exists($currsetting{'overrides'}{$key})) {
10674: push(@{$changes{'overrides'}},$key);
10675: }
10676: }
10677: } else {
10678: foreach my $key (@overrides) {
10679: push(@{$changes{'overrides'}},$key);
10680: }
10681: }
10682: }
10683: } else {
10684: my %default;
10685: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
10686: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
10687: $default{'errormail'} = 'adminemail';
10688: $default{'packagesmail'} = 'adminemail';
10689: $default{'helpdeskmail'} = 'supportemail';
10690: $default{'otherdomsmail'} = 'supportemail';
10691: $default{'lonstatusmail'} = 'adminemail';
10692: $default{'requestsmail'} = 'adminemail';
10693: $default{'updatesmail'} = 'adminemail';
10694: foreach my $item (@contacts) {
10695: if ($to{$item} ne $default{$item}) {
10696: $changes{$item} = 1;
10697: }
10698: }
10699: foreach my $type (@mailings) {
10700: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
10701: push(@{$changes{$type}},@{$newsetting{$type}});
10702: }
10703: if ($others{$type} ne '') {
10704: push(@{$changes{$type}},'others');
10705: }
10706: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
10707: if ($bcc{$type} ne '') {
10708: push(@{$changes{$type}},'bcc');
10709: }
10710: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
10711: push(@{$changes{$type}},'include');
10712: }
10713: }
10714: }
10715: if (ref($fields) eq 'ARRAY') {
10716: foreach my $field (@{$fields}) {
10717: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10718: push(@{$changes{'helpform'}},$field);
10719: }
10720: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10721: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10722: push(@{$changes{'helpform'}},'maxsize');
10723: }
10724: }
10725: }
10726: }
10727: }
10728: foreach my $item (@toggles) {
10729: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
10730: $changes{$item} = 1;
10731: } elsif ((!$env{'form.'.$item}) &&
10732: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
10733: $changes{$item} = 1;
10734: }
10735: }
10736: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
10737: $dom);
10738: if ($putresult eq 'ok') {
10739: if (keys(%changes) > 0) {
10740: &Apache::loncommon::devalidate_domconfig_cache($dom);
10741: if (ref($lastactref) eq 'HASH') {
10742: $lastactref->{'domainconfig'} = 1;
10743: }
10744: my ($titles,$short_titles) = &contact_titles();
10745: $resulttext = &mt('Changes made:').'<ul>';
10746: foreach my $item (@contacts) {
10747: if ($changes{$item}) {
10748: $resulttext .= '<li>'.$titles->{$item}.
10749: &mt(' set to: ').
10750: '<span class="LC_cusr_emph">'.
10751: $to{$item}.'</span></li>';
10752: }
10753: }
10754: foreach my $type (@mailings) {
10755: if (ref($changes{$type}) eq 'ARRAY') {
10756: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
10757: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
10758: } else {
10759: $resulttext .= '<li>'.$titles->{$type}.': ';
10760: }
10761: my @text;
10762: foreach my $item (@{$newsetting{$type}}) {
10763: push(@text,$short_titles->{$item});
10764: }
10765: if ($others{$type} ne '') {
10766: push(@text,$others{$type});
10767: }
10768: if (@text) {
10769: $resulttext .= '<span class="LC_cusr_emph">'.
10770: join(', ',@text).'</span>';
10771: }
10772: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
10773: if ($bcc{$type} ne '') {
10774: my $bcctext;
10775: if (@text) {
10776: $bcctext = ' '.&mt('with Bcc to');
10777: } else {
10778: $bcctext = '(Bcc)';
10779: }
10780: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
10781: } elsif (!@text) {
10782: $resulttext .= &mt('No one');
10783: }
10784: if ($includestr{$type} ne '') {
10785: if ($includeloc{$type} eq 'b') {
10786: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
10787: } elsif ($includeloc{$type} eq 's') {
10788: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
10789: }
10790: }
10791: } elsif (!@text) {
10792: $resulttext .= &mt('No recipients');
10793: }
10794: $resulttext .= '</li>';
10795: }
10796: }
10797: if (ref($changes{'overrides'}) eq 'ARRAY') {
10798: my @deletions;
10799: foreach my $type (@{$changes{'overrides'}}) {
10800: if ($usertypeshash{$type}) {
10801: if (grep(/^\Q$type\E/,@overrides)) {
10802: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
10803: $usertypeshash{$type}).'<ul><li>';
10804: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
10805: my @text;
10806: foreach my $item (@contacts) {
10807: if ($newsetting{'override_'.$type}{$item}) {
10808: push(@text,$short_titles->{$item});
10809: }
10810: }
10811: if ($newsetting{'override_'.$type}{'others'} ne '') {
10812: push(@text,$newsetting{'override_'.$type}{'others'});
10813: }
10814:
10815: if (@text) {
10816: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
10817: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
10818: }
10819: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
10820: my $bcctext;
10821: if (@text) {
10822: $bcctext = ' '.&mt('with Bcc to');
10823: } else {
10824: $bcctext = '(Bcc)';
10825: }
10826: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
10827: } elsif (!@text) {
10828: $resulttext .= &mt('Helpdesk e-mail sent to no one');
10829: }
10830: $resulttext .= '</li>';
10831: if ($newsetting{'override_'.$type}{'include'} ne '') {
10832: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
10833: if ($loc eq 'b') {
10834: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
10835: } elsif ($loc eq 's') {
10836: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
10837: }
10838: }
10839: }
10840: $resulttext .= '</li></ul></li>';
10841: } else {
10842: push(@deletions,$usertypeshash{$type});
10843: }
10844: }
10845: }
10846: if (@deletions) {
10847: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
10848: join(', ',@deletions)).'</li>';
10849: }
10850: }
10851: my @offon = ('off','on');
10852: if ($changes{'reporterrors'}) {
10853: $resulttext .= '<li>'.
10854: &mt('E-mail error reports to [_1] set to "'.
10855: $offon[$env{'form.reporterrors'}].'".',
10856: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10857: &mt('LON-CAPA core group - MSU'),600,500)).
10858: '</li>';
10859: }
10860: if ($changes{'reportupdates'}) {
10861: $resulttext .= '<li>'.
10862: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
10863: $offon[$env{'form.reportupdates'}].'".',
10864: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10865: &mt('LON-CAPA core group - MSU'),600,500)).
10866: '</li>';
10867: }
10868: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
10869: my (@optional,@required,@unused,$maxsizechg);
10870: foreach my $field (@{$changes{'helpform'}}) {
10871: if ($field eq 'maxsize') {
10872: $maxsizechg = 1;
10873: next;
10874: }
10875: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
10876: push(@optional,$field);
10877: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
10878: push(@unused,$field);
10879: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
10880: push(@required,$field);
10881: }
10882: }
10883: if (@optional) {
10884: $resulttext .= '<li>'.
10885: &mt('Help form fields changed to "Optional": [_1].',
10886: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
10887: '</li>';
10888: }
10889: if (@required) {
10890: $resulttext .= '<li>'.
10891: &mt('Help form fields changed to "Required": [_1].',
10892: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
10893: '</li>';
10894: }
10895: if (@unused) {
10896: $resulttext .= '<li>'.
10897: &mt('Help form fields changed to "Not shown": [_1].',
10898: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
10899: '</li>';
10900: }
10901: if ($maxsizechg) {
10902: $resulttext .= '<li>'.
10903: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
10904: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
10905: '</li>';
10906: }
10907: }
10908: $resulttext .= '</ul>';
10909: } else {
10910: $resulttext = &mt('No changes made to contacts and form settings');
10911: }
10912: } else {
10913: $resulttext = '<span class="LC_error">'.
10914: &mt('An error occurred: [_1].',$putresult).'</span>';
10915: }
10916: return $resulttext;
10917: }
10918:
10919: sub modify_usercreation {
10920: my ($dom,%domconfig) = @_;
10921: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
10922: my $warningmsg;
10923: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10924: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
10925: if ($key eq 'cancreate') {
10926: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
10927: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
10928: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
10929: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
10930: ($item eq 'recaptchaversion')) {
10931: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10932: } else {
10933: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10934: }
10935: }
10936: }
10937: } elsif ($key eq 'email_rule') {
10938: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
10939: } else {
10940: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
10941: }
10942: }
10943: }
10944: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
10945: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
10946: my @contexts = ('author','course','requestcrs');
10947: foreach my $item(@contexts) {
10948: $cancreate{$item} = $env{'form.can_createuser_'.$item};
10949: }
10950: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10951: foreach my $item (@contexts) {
10952: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
10953: push(@{$changes{'cancreate'}},$item);
10954: }
10955: }
10956: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
10957: foreach my $item (@contexts) {
10958: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
10959: if ($cancreate{$item} ne 'any') {
10960: push(@{$changes{'cancreate'}},$item);
10961: }
10962: } else {
10963: if ($cancreate{$item} ne 'none') {
10964: push(@{$changes{'cancreate'}},$item);
10965: }
10966: }
10967: }
10968: } else {
10969: foreach my $item (@contexts) {
10970: push(@{$changes{'cancreate'}},$item);
10971: }
10972: }
10973:
10974: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
10975: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
10976: if (!grep(/^\Q$type\E$/,@username_rule)) {
10977: push(@{$changes{'username_rule'}},$type);
10978: }
10979: }
10980: foreach my $type (@username_rule) {
10981: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
10982: push(@{$changes{'username_rule'}},$type);
10983: }
10984: }
10985: } else {
10986: push(@{$changes{'username_rule'}},@username_rule);
10987: }
10988:
10989: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
10990: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
10991: if (!grep(/^\Q$type\E$/,@id_rule)) {
10992: push(@{$changes{'id_rule'}},$type);
10993: }
10994: }
10995: foreach my $type (@id_rule) {
10996: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
10997: push(@{$changes{'id_rule'}},$type);
10998: }
10999: }
11000: } else {
11001: push(@{$changes{'id_rule'}},@id_rule);
11002: }
11003:
11004: my @authen_contexts = ('author','course','domain');
11005: my @authtypes = ('int','krb4','krb5','loc');
11006: my %authhash;
11007: foreach my $item (@authen_contexts) {
11008: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
11009: foreach my $auth (@authtypes) {
11010: if (grep(/^\Q$auth\E$/,@authallowed)) {
11011: $authhash{$item}{$auth} = 1;
11012: } else {
11013: $authhash{$item}{$auth} = 0;
11014: }
11015: }
11016: }
11017: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
11018: foreach my $item (@authen_contexts) {
11019: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
11020: foreach my $auth (@authtypes) {
11021: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
11022: push(@{$changes{'authtypes'}},$item);
11023: last;
11024: }
11025: }
11026: }
11027: }
11028: } else {
11029: foreach my $item (@authen_contexts) {
11030: push(@{$changes{'authtypes'}},$item);
11031: }
11032: }
11033:
11034: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
11035: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
11036: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
11037: $save_usercreate{'id_rule'} = \@id_rule;
11038: $save_usercreate{'username_rule'} = \@username_rule,
11039: $save_usercreate{'authtypes'} = \%authhash;
11040:
11041: my %usercreation_hash = (
11042: usercreation => \%save_usercreate,
11043: );
11044:
11045: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
11046: $dom);
11047:
11048: if ($putresult eq 'ok') {
11049: if (keys(%changes) > 0) {
11050: $resulttext = &mt('Changes made:').'<ul>';
11051: if (ref($changes{'cancreate'}) eq 'ARRAY') {
11052: my %lt = &usercreation_types();
11053: foreach my $type (@{$changes{'cancreate'}}) {
11054: my $chgtext = $lt{$type}.', ';
11055: if ($cancreate{$type} eq 'none') {
11056: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
11057: } elsif ($cancreate{$type} eq 'any') {
11058: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
11059: } elsif ($cancreate{$type} eq 'official') {
11060: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
11061: } elsif ($cancreate{$type} eq 'unofficial') {
11062: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
11063: }
11064: $resulttext .= '<li>'.$chgtext.'</li>';
11065: }
11066: }
11067: if (ref($changes{'username_rule'}) eq 'ARRAY') {
11068: my ($rules,$ruleorder) =
11069: &Apache::lonnet::inst_userrules($dom,'username');
11070: my $chgtext = '<ul>';
11071: foreach my $type (@username_rule) {
11072: if (ref($rules->{$type}) eq 'HASH') {
11073: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
11074: }
11075: }
11076: $chgtext .= '</ul>';
11077: if (@username_rule > 0) {
11078: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11079: } else {
11080: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
11081: }
11082: }
11083: if (ref($changes{'id_rule'}) eq 'ARRAY') {
11084: my ($idrules,$idruleorder) =
11085: &Apache::lonnet::inst_userrules($dom,'id');
11086: my $chgtext = '<ul>';
11087: foreach my $type (@id_rule) {
11088: if (ref($idrules->{$type}) eq 'HASH') {
11089: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
11090: }
11091: }
11092: $chgtext .= '</ul>';
11093: if (@id_rule > 0) {
11094: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11095: } else {
11096: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
11097: }
11098: }
11099: my %authname = &authtype_names();
11100: my %context_title = &context_names();
11101: if (ref($changes{'authtypes'}) eq 'ARRAY') {
11102: my $chgtext = '<ul>';
11103: foreach my $type (@{$changes{'authtypes'}}) {
11104: my @allowed;
11105: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
11106: foreach my $auth (@authtypes) {
11107: if ($authhash{$type}{$auth}) {
11108: push(@allowed,$authname{$auth});
11109: }
11110: }
11111: if (@allowed > 0) {
11112: $chgtext .= join(', ',@allowed).'</li>';
11113: } else {
11114: $chgtext .= &mt('none').'</li>';
11115: }
11116: }
11117: $chgtext .= '</ul>';
11118: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
11119: $resulttext .= '</li>';
11120: }
11121: $resulttext .= '</ul>';
11122: } else {
11123: $resulttext = &mt('No changes made to user creation settings');
11124: }
11125: } else {
11126: $resulttext = '<span class="LC_error">'.
11127: &mt('An error occurred: [_1]',$putresult).'</span>';
11128: }
11129: if ($warningmsg ne '') {
11130: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
11131: }
11132: return $resulttext;
11133: }
11134:
11135: sub modify_selfcreation {
11136: my ($dom,%domconfig) = @_;
11137: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
11138: my (%save_usercreate,%save_usermodify);
11139: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
11140: if (ref($types) eq 'ARRAY') {
11141: $usertypes->{'default'} = $othertitle;
11142: push(@{$types},'default');
11143: }
11144: #
11145: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
11146: #
11147: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11148: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
11149: if ($key eq 'cancreate') {
11150: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
11151: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
11152: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
11153: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
11154: ($item eq 'recaptchaversion') ||
11155: ($item eq 'emailusername') || ($item eq 'notify') ||
11156: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
11157: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11158: } else {
11159: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11160: }
11161: }
11162: }
11163: } elsif ($key eq 'email_rule') {
11164: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
11165: } else {
11166: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
11167: }
11168: }
11169: }
11170: #
11171: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
11172: #
11173: if (ref($domconfig{'usermodification'}) eq 'HASH') {
11174: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
11175: if ($key eq 'selfcreate') {
11176: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
11177: } else {
11178: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
11179: }
11180: }
11181: }
11182:
11183: my @contexts = ('selfcreate');
11184: @{$cancreate{'selfcreate'}} = ();
11185: %{$cancreate{'emailusername'}} = ();
11186: @{$cancreate{'statustocreate'}} = ();
11187: %{$cancreate{'selfcreateprocessing'}} = ();
11188: %{$cancreate{'shibenv'}} = ();
11189: my %selfcreatetypes = (
11190: sso => 'users authenticated by institutional single sign on',
11191: login => 'users authenticated by institutional log-in',
11192: email => 'users who provide a valid e-mail address for use as username',
11193: );
11194: #
11195: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
11196: # is permitted.
11197: #
11198:
11199: my @statuses;
11200: if (ref($domconfig{'inststatus'}) eq 'HASH') {
11201: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
11202: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
11203: }
11204: }
11205: push(@statuses,'default');
11206:
11207: foreach my $item ('login','sso','email') {
11208: if ($item eq 'email') {
11209: if ($env{'form.cancreate_email'}) {
11210: push(@{$cancreate{'selfcreate'}},'email');
11211: push(@contexts,'selfcreateprocessing');
11212: foreach my $type (@statuses) {
11213: if ($type eq 'default') {
11214: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
11215: } else {
11216: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
11217: }
11218: }
11219: }
11220: } else {
11221: if ($env{'form.cancreate_'.$item}) {
11222: push(@{$cancreate{'selfcreate'}},$item);
11223: }
11224: }
11225: }
11226: my (@email_rule,%userinfo,%savecaptcha);
11227: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
11228: #
11229: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
11230: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
11231: #
11232:
11233: if ($env{'form.cancreate_email'}) {
11234: push(@contexts,'emailusername');
11235: if (ref($types) eq 'ARRAY') {
11236: foreach my $type (@{$types}) {
11237: if (ref($infofields) eq 'ARRAY') {
11238: foreach my $field (@{$infofields}) {
11239: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
11240: $cancreate{'emailusername'}{$type}{$field} = $1;
11241: }
11242: }
11243: }
11244: }
11245: }
11246: #
11247: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
11248: # queued requests for self-creation of account using e-mail address as username
11249: #
11250:
11251: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
11252: @approvalnotify = sort(@approvalnotify);
11253: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
11254: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11255: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
11256: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
11257: push(@{$changes{'cancreate'}},'notify');
11258: }
11259: } else {
11260: if ($cancreate{'notify'}{'approval'}) {
11261: push(@{$changes{'cancreate'}},'notify');
11262: }
11263: }
11264: } elsif ($cancreate{'notify'}{'approval'}) {
11265: push(@{$changes{'cancreate'}},'notify');
11266: }
11267:
11268: #
11269: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
11270: #
11271: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
11272: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
11273: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
11274: if (@{$curr_usercreation{'email_rule'}} > 0) {
11275: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
11276: if (!grep(/^\Q$type\E$/,@email_rule)) {
11277: push(@{$changes{'email_rule'}},$type);
11278: }
11279: }
11280: }
11281: if (@email_rule > 0) {
11282: foreach my $type (@email_rule) {
11283: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
11284: push(@{$changes{'email_rule'}},$type);
11285: }
11286: }
11287: }
11288: } elsif (@email_rule > 0) {
11289: push(@{$changes{'email_rule'}},@email_rule);
11290: }
11291: }
11292: #
11293: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
11294: # institutional log-in.
11295: #
11296: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
11297: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11298: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
11299: ($domdefaults{'auth_def'} eq 'localauth'))) {
11300: $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.').' '.
11301: &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.');
11302: }
11303: }
11304: my @fields = ('lastname','firstname','middlename','generation',
11305: 'permanentemail','id');
11306: my @shibfields = (@fields,'inststatus');
11307: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11308: #
11309: # Where usernames may created for institutional log-in and/or institutional single sign on:
11310: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
11311: # may self-create accounts
11312: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
11313: # which the user may supply, if institutional data is unavailable.
11314: #
11315: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
11316: if (ref($types) eq 'ARRAY') {
11317: if (@{$types} > 1) {
11318: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
11319: push(@contexts,'statustocreate');
11320: } else {
11321: undef($cancreate{'statustocreate'});
11322: }
11323: foreach my $type (@{$types}) {
11324: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
11325: foreach my $field (@fields) {
11326: if (grep(/^\Q$field\E$/,@modifiable)) {
11327: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
11328: } else {
11329: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
11330: }
11331: }
11332: }
11333: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
11334: foreach my $type (@{$types}) {
11335: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
11336: foreach my $field (@fields) {
11337: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
11338: $curr_usermodify{'selfcreate'}{$type}{$field}) {
11339: push(@{$changes{'selfcreate'}},$type);
11340: last;
11341: }
11342: }
11343: }
11344: }
11345: } else {
11346: foreach my $type (@{$types}) {
11347: push(@{$changes{'selfcreate'}},$type);
11348: }
11349: }
11350: }
11351: foreach my $field (@shibfields) {
11352: if ($env{'form.shibenv_'.$field} ne '') {
11353: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
11354: }
11355: }
11356: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11357: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
11358: foreach my $field (@shibfields) {
11359: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
11360: push(@{$changes{'cancreate'}},'shibenv');
11361: }
11362: }
11363: } else {
11364: foreach my $field (@shibfields) {
11365: if ($env{'form.shibenv_'.$field}) {
11366: push(@{$changes{'cancreate'}},'shibenv');
11367: last;
11368: }
11369: }
11370: }
11371: }
11372: }
11373: foreach my $item (@contexts) {
11374: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
11375: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
11376: if (ref($cancreate{$item}) eq 'ARRAY') {
11377: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
11378: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11379: push(@{$changes{'cancreate'}},$item);
11380: }
11381: }
11382: }
11383: }
11384: if (ref($cancreate{$item}) eq 'ARRAY') {
11385: foreach my $type (@{$cancreate{$item}}) {
11386: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
11387: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11388: push(@{$changes{'cancreate'}},$item);
11389: }
11390: }
11391: }
11392: }
11393: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
11394: if (ref($cancreate{$item}) eq 'HASH') {
11395: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
11396: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
11397: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
11398: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
11399: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11400: push(@{$changes{'cancreate'}},$item);
11401: }
11402: }
11403: }
11404: } elsif ($item eq 'selfcreateprocessing') {
11405: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
11406: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11407: push(@{$changes{'cancreate'}},$item);
11408: }
11409: }
11410: } else {
11411: if (!$cancreate{$item}{$curr}) {
11412: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11413: push(@{$changes{'cancreate'}},$item);
11414: }
11415: }
11416: }
11417: }
11418: foreach my $field (keys(%{$cancreate{$item}})) {
11419: if (ref($cancreate{$item}{$field}) eq 'HASH') {
11420: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
11421: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
11422: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
11423: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11424: push(@{$changes{'cancreate'}},$item);
11425: }
11426: }
11427: } else {
11428: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11429: push(@{$changes{'cancreate'}},$item);
11430: }
11431: }
11432: }
11433: } elsif ($item eq 'selfcreateprocessing') {
11434: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
11435: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11436: push(@{$changes{'cancreate'}},$item);
11437: }
11438: }
11439: } else {
11440: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
11441: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11442: push(@{$changes{'cancreate'}},$item);
11443: }
11444: }
11445: }
11446: }
11447: }
11448: } elsif ($curr_usercreation{'cancreate'}{$item}) {
11449: if (ref($cancreate{$item}) eq 'ARRAY') {
11450: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
11451: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11452: push(@{$changes{'cancreate'}},$item);
11453: }
11454: }
11455: } elsif (ref($cancreate{$item}) eq 'HASH') {
11456: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
11457: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11458: push(@{$changes{'cancreate'}},$item);
11459: }
11460: }
11461: }
11462: } elsif ($item eq 'emailusername') {
11463: if (ref($cancreate{$item}) eq 'HASH') {
11464: foreach my $type (keys(%{$cancreate{$item}})) {
11465: if (ref($cancreate{$item}{$type}) eq 'HASH') {
11466: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
11467: if ($cancreate{$item}{$type}{$field}) {
11468: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11469: push(@{$changes{'cancreate'}},$item);
11470: }
11471: last;
11472: }
11473: }
11474: }
11475: }
11476: }
11477: }
11478: }
11479: #
11480: # Populate %save_usercreate hash with updates to self-creation configuration.
11481: #
11482: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
11483: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
11484: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
11485: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
11486: if (ref($cancreate{'notify'}) eq 'HASH') {
11487: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
11488: }
11489: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
11490: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
11491: }
11492: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11493: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
11494: }
11495: if (ref($cancreate{'shibenv'}) eq 'HASH') {
11496: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
11497: }
11498: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
11499: $save_usercreate{'email_rule'} = \@email_rule;
11500:
11501: my %userconfig_hash = (
11502: usercreation => \%save_usercreate,
11503: usermodification => \%save_usermodify,
11504: );
11505: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
11506: $dom);
11507: #
11508: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
11509: #
11510: if ($putresult eq 'ok') {
11511: if (keys(%changes) > 0) {
11512: $resulttext = &mt('Changes made:').'<ul>';
11513: if (ref($changes{'cancreate'}) eq 'ARRAY') {
11514: my %lt = &selfcreation_types();
11515: foreach my $type (@{$changes{'cancreate'}}) {
11516: my $chgtext;
11517: if ($type eq 'selfcreate') {
11518: if (@{$cancreate{$type}} == 0) {
11519: $chgtext .= &mt('Self creation of a new user account is not permitted.');
11520: } else {
11521: $chgtext .= &mt('Self-creation of a new account is permitted for:').
11522: '<ul>';
11523: foreach my $case (@{$cancreate{$type}}) {
11524: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
11525: }
11526: $chgtext .= '</ul>';
11527: if (ref($cancreate{$type}) eq 'ARRAY') {
11528: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
11529: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11530: if (@{$cancreate{'statustocreate'}} == 0) {
11531: $chgtext .= '<br />'.
11532: '<span class="LC_warning">'.
11533: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
11534: '</span>';
11535: }
11536: }
11537: }
11538: }
11539: }
11540: } elsif ($type eq 'shibenv') {
11541: if (keys(%{$cancreate{$type}}) == 0) {
11542: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
11543: } else {
11544: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
11545: '<ul>';
11546: foreach my $field (@shibfields) {
11547: next if ($cancreate{$type}{$field} eq '');
11548: if ($field eq 'inststatus') {
11549: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
11550: } else {
11551: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
11552: }
11553: }
11554: $chgtext .= '</ul>';
11555: }
11556: } elsif ($type eq 'statustocreate') {
11557: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
11558: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
11559: if (@{$cancreate{'selfcreate'}} > 0) {
11560: if (@{$cancreate{'statustocreate'}} == 0) {
11561: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
11562: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
11563: $chgtext .= '<br />'.
11564: '<span class="LC_warning">'.
11565: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
11566: '</span>';
11567: }
11568: } elsif (ref($usertypes) eq 'HASH') {
11569: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
11570: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
11571: } else {
11572: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
11573: }
11574: $chgtext .= '<ul>';
11575: foreach my $case (@{$cancreate{$type}}) {
11576: if ($case eq 'default') {
11577: $chgtext .= '<li>'.$othertitle.'</li>';
11578: } else {
11579: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
11580: }
11581: }
11582: $chgtext .= '</ul>';
11583: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
11584: $chgtext .= '<br /><span class="LC_warning">'.
11585: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
11586: '</span>';
11587: }
11588: }
11589: } else {
11590: if (@{$cancreate{$type}} == 0) {
11591: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
11592: } else {
11593: $chgtext .= &mt('Although institutional affiliations permitted to create accounts were changed, self creation of accounts is not currently permitted for any authentication types.');
11594: }
11595: }
11596: }
11597: } elsif ($type eq 'selfcreateprocessing') {
11598: my %choices = &Apache::lonlocal::texthash (
11599: automatic => 'Automatic approval',
11600: approval => 'Queued for approval',
11601: );
11602: if (@statuses > 1) {
11603: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
11604: '<ul>';
11605: foreach my $type (@statuses) {
11606: if ($type eq 'default') {
11607: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
11608: } else {
11609: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
11610: }
11611: }
11612: $chgtext .= '</ul>';
11613: } else {
11614: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
11615: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
11616: }
11617: } elsif ($type eq 'captcha') {
11618: if ($savecaptcha{$type} eq 'notused') {
11619: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
11620: } else {
11621: my %captchas = &captcha_phrases();
11622: if ($captchas{$savecaptcha{$type}}) {
11623: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
11624: } else {
11625: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
11626: }
11627: }
11628: } elsif ($type eq 'recaptchakeys') {
11629: my ($privkey,$pubkey);
11630: if (ref($savecaptcha{$type}) eq 'HASH') {
11631: $pubkey = $savecaptcha{$type}{'public'};
11632: $privkey = $savecaptcha{$type}{'private'};
11633: }
11634: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
11635: if (!$pubkey) {
11636: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
11637: } else {
11638: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
11639: }
11640: if (!$privkey) {
11641: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
11642: } else {
11643: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
11644: }
11645: $chgtext .= '</ul>';
11646: } elsif ($type eq 'recaptchaversion') {
11647: if ($savecaptcha{'captcha'} eq 'recaptcha') {
11648: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
11649: }
11650: } elsif ($type eq 'emailusername') {
11651: if (ref($cancreate{'emailusername'}) eq 'HASH') {
11652: if (ref($types) eq 'ARRAY') {
11653: foreach my $type (@{$types}) {
11654: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
11655: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
11656: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
11657: '<ul>';
11658: foreach my $field (@{$infofields}) {
11659: if ($cancreate{'emailusername'}{$type}{$field}) {
11660: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
11661: }
11662: }
11663: $chgtext .= '</ul>';
11664: } else {
11665: $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 />';
11666: }
11667: } else {
11668: $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 />';
11669: }
11670: }
11671: }
11672: }
11673: } elsif ($type eq 'notify') {
11674: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
11675: if (ref($changes{'cancreate'}) eq 'ARRAY') {
11676: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
11677: if ($cancreate{'notify'}{'approval'}) {
11678: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
11679: }
11680: }
11681: }
11682: }
11683: if ($chgtext) {
11684: $resulttext .= '<li>'.$chgtext.'</li>';
11685: }
11686: }
11687: }
11688: if (ref($changes{'email_rule'}) eq 'ARRAY') {
11689: my ($emailrules,$emailruleorder) =
11690: &Apache::lonnet::inst_userrules($dom,'email');
11691: my $chgtext = '<ul>';
11692: foreach my $type (@email_rule) {
11693: if (ref($emailrules->{$type}) eq 'HASH') {
11694: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
11695: }
11696: }
11697: $chgtext .= '</ul>';
11698: if (@email_rule > 0) {
11699: $resulttext .= '<li>'.
11700: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
11701: $chgtext.
11702: '</li>';
11703: } else {
11704: $resulttext .= '<li>'.
11705: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
11706: '</li>';
11707: }
11708: }
11709: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
11710: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
11711: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11712: foreach my $type (@{$changes{'selfcreate'}}) {
11713: my $typename = $type;
11714: if (ref($usertypes) eq 'HASH') {
11715: if ($usertypes->{$type} ne '') {
11716: $typename = $usertypes->{$type};
11717: }
11718: }
11719: my @modifiable;
11720: $resulttext .= '<li>'.
11721: &mt('Self-creation of account by users with status: [_1]',
11722: '<span class="LC_cusr_emph">'.$typename.'</span>').
11723: ' - '.&mt('modifiable fields (if institutional data blank): ');
11724: foreach my $field (@fields) {
11725: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
11726: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
11727: }
11728: }
11729: if (@modifiable > 0) {
11730: $resulttext .= join(', ',@modifiable);
11731: } else {
11732: $resulttext .= &mt('none');
11733: }
11734: $resulttext .= '</li>';
11735: }
11736: $resulttext .= '</ul></li>';
11737: }
11738: $resulttext .= '</ul>';
11739: } else {
11740: $resulttext = &mt('No changes made to self-creation settings');
11741: }
11742: } else {
11743: $resulttext = '<span class="LC_error">'.
11744: &mt('An error occurred: [_1]',$putresult).'</span>';
11745: }
11746: if ($warningmsg ne '') {
11747: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
11748: }
11749: return $resulttext;
11750: }
11751:
11752: sub process_captcha {
11753: my ($container,$changes,$newsettings,$current) = @_;
11754: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
11755: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
11756: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
11757: $newsettings->{'captcha'} = 'original';
11758: }
11759: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
11760: if ($container eq 'cancreate') {
11761: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11762: push(@{$changes->{'cancreate'}},'captcha');
11763: } elsif (!defined($changes->{'cancreate'})) {
11764: $changes->{'cancreate'} = ['captcha'];
11765: }
11766: } else {
11767: $changes->{'captcha'} = 1;
11768: }
11769: }
11770: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
11771: if ($newsettings->{'captcha'} eq 'recaptcha') {
11772: $newpub = $env{'form.'.$container.'_recaptchapub'};
11773: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
11774: $newpub =~ s/[^\w\-]//g;
11775: $newpriv =~ s/[^\w\-]//g;
11776: $newsettings->{'recaptchakeys'} = {
11777: public => $newpub,
11778: private => $newpriv,
11779: };
11780: $newversion = $env{'form.'.$container.'_recaptchaversion'};
11781: $newversion =~ s/\D//g;
11782: if ($newversion ne '2') {
11783: $newversion = 1;
11784: }
11785: $newsettings->{'recaptchaversion'} = $newversion;
11786: }
11787: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
11788: $currpub = $current->{'recaptchakeys'}{'public'};
11789: $currpriv = $current->{'recaptchakeys'}{'private'};
11790: unless ($newsettings->{'captcha'} eq 'recaptcha') {
11791: $newsettings->{'recaptchakeys'} = {
11792: public => '',
11793: private => '',
11794: }
11795: }
11796: }
11797: if ($current->{'captcha'} eq 'recaptcha') {
11798: $currversion = $current->{'recaptchaversion'};
11799: if ($currversion ne '2') {
11800: $currversion = 1;
11801: }
11802: }
11803: if ($currversion ne $newversion) {
11804: if ($container eq 'cancreate') {
11805: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11806: push(@{$changes->{'cancreate'}},'recaptchaversion');
11807: } elsif (!defined($changes->{'cancreate'})) {
11808: $changes->{'cancreate'} = ['recaptchaversion'];
11809: }
11810: } else {
11811: $changes->{'recaptchaversion'} = 1;
11812: }
11813: }
11814: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
11815: if ($container eq 'cancreate') {
11816: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11817: push(@{$changes->{'cancreate'}},'recaptchakeys');
11818: } elsif (!defined($changes->{'cancreate'})) {
11819: $changes->{'cancreate'} = ['recaptchakeys'];
11820: }
11821: } else {
11822: $changes->{'recaptchakeys'} = 1;
11823: }
11824: }
11825: return;
11826: }
11827:
11828: sub modify_usermodification {
11829: my ($dom,%domconfig) = @_;
11830: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
11831: if (ref($domconfig{'usermodification'}) eq 'HASH') {
11832: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
11833: if ($key eq 'selfcreate') {
11834: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
11835: } else {
11836: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
11837: }
11838: }
11839: }
11840: my @contexts = ('author','course');
11841: my %context_title = (
11842: author => 'In author context',
11843: course => 'In course context',
11844: );
11845: my @fields = ('lastname','firstname','middlename','generation',
11846: 'permanentemail','id');
11847: my %roles = (
11848: author => ['ca','aa'],
11849: course => ['st','ep','ta','in','cr'],
11850: );
11851: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11852: foreach my $context (@contexts) {
11853: foreach my $role (@{$roles{$context}}) {
11854: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
11855: foreach my $item (@fields) {
11856: if (grep(/^\Q$item\E$/,@modifiable)) {
11857: $modifyhash{$context}{$role}{$item} = 1;
11858: } else {
11859: $modifyhash{$context}{$role}{$item} = 0;
11860: }
11861: }
11862: }
11863: if (ref($curr_usermodification{$context}) eq 'HASH') {
11864: foreach my $role (@{$roles{$context}}) {
11865: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
11866: foreach my $field (@fields) {
11867: if ($modifyhash{$context}{$role}{$field} ne
11868: $curr_usermodification{$context}{$role}{$field}) {
11869: push(@{$changes{$context}},$role);
11870: last;
11871: }
11872: }
11873: }
11874: }
11875: } else {
11876: foreach my $context (@contexts) {
11877: foreach my $role (@{$roles{$context}}) {
11878: push(@{$changes{$context}},$role);
11879: }
11880: }
11881: }
11882: }
11883: my %usermodification_hash = (
11884: usermodification => \%modifyhash,
11885: );
11886: my $putresult = &Apache::lonnet::put_dom('configuration',
11887: \%usermodification_hash,$dom);
11888: if ($putresult eq 'ok') {
11889: if (keys(%changes) > 0) {
11890: $resulttext = &mt('Changes made: ').'<ul>';
11891: foreach my $context (@contexts) {
11892: if (ref($changes{$context}) eq 'ARRAY') {
11893: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
11894: if (ref($changes{$context}) eq 'ARRAY') {
11895: foreach my $role (@{$changes{$context}}) {
11896: my $rolename;
11897: if ($role eq 'cr') {
11898: $rolename = &mt('Custom');
11899: } else {
11900: $rolename = &Apache::lonnet::plaintext($role);
11901: }
11902: my @modifiable;
11903: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
11904: foreach my $field (@fields) {
11905: if ($modifyhash{$context}{$role}{$field}) {
11906: push(@modifiable,$fieldtitles{$field});
11907: }
11908: }
11909: if (@modifiable > 0) {
11910: $resulttext .= join(', ',@modifiable);
11911: } else {
11912: $resulttext .= &mt('none');
11913: }
11914: $resulttext .= '</li>';
11915: }
11916: $resulttext .= '</ul></li>';
11917: }
11918: }
11919: }
11920: $resulttext .= '</ul>';
11921: } else {
11922: $resulttext = &mt('No changes made to user modification settings');
11923: }
11924: } else {
11925: $resulttext = '<span class="LC_error">'.
11926: &mt('An error occurred: [_1]',$putresult).'</span>';
11927: }
11928: return $resulttext;
11929: }
11930:
11931: sub modify_defaults {
11932: my ($dom,$lastactref,%domconfig) = @_;
11933: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
11934: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11935: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
11936: 'portal_def','intauth_cost','intauth_check','intauth_switch');
11937: my @authtypes = ('internal','krb4','krb5','localauth');
11938: foreach my $item (@items) {
11939: $newvalues{$item} = $env{'form.'.$item};
11940: if ($item eq 'auth_def') {
11941: if ($newvalues{$item} ne '') {
11942: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
11943: push(@errors,$item);
11944: }
11945: }
11946: } elsif ($item eq 'lang_def') {
11947: if ($newvalues{$item} ne '') {
11948: if ($newvalues{$item} =~ /^(\w+)/) {
11949: my $langcode = $1;
11950: if ($langcode ne 'x_chef') {
11951: if (code2language($langcode) eq '') {
11952: push(@errors,$item);
11953: }
11954: }
11955: } else {
11956: push(@errors,$item);
11957: }
11958: }
11959: } elsif ($item eq 'timezone_def') {
11960: if ($newvalues{$item} ne '') {
11961: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
11962: push(@errors,$item);
11963: }
11964: }
11965: } elsif ($item eq 'datelocale_def') {
11966: if ($newvalues{$item} ne '') {
11967: my @datelocale_ids = DateTime::Locale->ids();
11968: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
11969: push(@errors,$item);
11970: }
11971: }
11972: } elsif ($item eq 'portal_def') {
11973: if ($newvalues{$item} ne '') {
11974: 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])\/?$/) {
11975: push(@errors,$item);
11976: }
11977: }
11978: } elsif ($item eq 'intauth_cost') {
11979: if ($newvalues{$item} ne '') {
11980: if ($newvalues{$item} =~ /\D/) {
11981: push(@errors,$item);
11982: }
11983: }
11984: } elsif ($item eq 'intauth_check') {
11985: if ($newvalues{$item} ne '') {
11986: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
11987: push(@errors,$item);
11988: }
11989: }
11990: } elsif ($item eq 'intauth_switch') {
11991: if ($newvalues{$item} ne '') {
11992: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
11993: push(@errors,$item);
11994: }
11995: }
11996: }
11997: if (grep(/^\Q$item\E$/,@errors)) {
11998: $newvalues{$item} = $domdefaults{$item};
11999: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
12000: $changes{$item} = 1;
12001: }
12002: $domdefaults{$item} = $newvalues{$item};
12003: }
12004: my %defaults_hash = (
12005: defaults => \%newvalues,
12006: );
12007: my $title = &defaults_titles();
12008:
12009: my $currinststatus;
12010: if (ref($domconfig{'inststatus'}) eq 'HASH') {
12011: $currinststatus = $domconfig{'inststatus'};
12012: } else {
12013: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12014: $currinststatus = {
12015: inststatustypes => $usertypes,
12016: inststatusorder => $types,
12017: inststatusguest => [],
12018: };
12019: }
12020: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
12021: my @allpos;
12022: my %guests;
12023: my %alltypes;
12024: my ($currtitles,$currguests,$currorder);
12025: if (ref($currinststatus) eq 'HASH') {
12026: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
12027: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
12028: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
12029: if ($currinststatus->{inststatustypes}->{$type} ne '') {
12030: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
12031: }
12032: }
12033: unless (grep(/^\Q$type\E$/,@todelete)) {
12034: my $position = $env{'form.inststatus_pos_'.$type};
12035: $position =~ s/\D+//g;
12036: $allpos[$position] = $type;
12037: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
12038: $alltypes{$type} =~ s/`//g;
12039: if ($env{'form.inststatus_guest_'.$type}) {
12040: $guests{$type} = 1;
12041: }
12042: }
12043: }
12044: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
12045: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
12046: }
12047: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
12048: $currtitles =~ s/,$//;
12049: }
12050: }
12051: if ($env{'form.addinststatus'}) {
12052: my $newtype = $env{'form.addinststatus'};
12053: $newtype =~ s/\W//g;
12054: unless (exists($alltypes{$newtype})) {
12055: if ($env{'form.addinststatus_guest'}) {
12056: $guests{$newtype} = 1;
12057: }
12058: $alltypes{$newtype} = $env{'form.addinststatus_title'};
12059: $alltypes{$newtype} =~ s/`//g;
12060: my $position = $env{'form.addinststatus_pos'};
12061: $position =~ s/\D+//g;
12062: if ($position ne '') {
12063: $allpos[$position] = $newtype;
12064: }
12065: }
12066: }
12067: my (@orderedstatus,@orderedguests);
12068: foreach my $type (@allpos) {
12069: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
12070: push(@orderedstatus,$type);
12071: if ($guests{$type}) {
12072: push(@orderedguests,$type);
12073: }
12074: }
12075: }
12076: foreach my $type (keys(%alltypes)) {
12077: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
12078: delete($alltypes{$type});
12079: }
12080: }
12081: $defaults_hash{'inststatus'} = {
12082: inststatustypes => \%alltypes,
12083: inststatusorder => \@orderedstatus,
12084: inststatusguest => \@orderedguests,
12085: };
12086: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
12087: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
12088: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
12089: }
12090: }
12091: if ($currorder ne join(',',@orderedstatus)) {
12092: $changes{'inststatus'}{'inststatusorder'} = 1;
12093: }
12094: if ($currguests ne join(',',@orderedguests)) {
12095: $changes{'inststatus'}{'inststatusguest'} = 1;
12096: }
12097: my $newtitles;
12098: foreach my $item (@orderedstatus) {
12099: $newtitles .= $alltypes{$item}.',';
12100: }
12101: $newtitles =~ s/,$//;
12102: if ($currtitles ne $newtitles) {
12103: $changes{'inststatus'}{'inststatustypes'} = 1;
12104: }
12105: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
12106: $dom);
12107: if ($putresult eq 'ok') {
12108: if (keys(%changes) > 0) {
12109: $resulttext = &mt('Changes made:').'<ul>';
12110: my $version = &Apache::lonnet::get_server_loncaparev($dom);
12111: 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";
12112: foreach my $item (sort(keys(%changes))) {
12113: if ($item eq 'inststatus') {
12114: if (ref($changes{'inststatus'}) eq 'HASH') {
12115: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
12116: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
12117: foreach my $type (@orderedstatus) {
12118: $resulttext .= $alltypes{$type}.', ';
12119: }
12120: $resulttext =~ s/, $//;
12121: $resulttext .= '</li>';
12122: }
12123: if ($changes{'inststatus'}{'inststatusguest'}) {
12124: $resulttext .= '<li>';
12125: if (@orderedguests) {
12126: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
12127: foreach my $type (@orderedguests) {
12128: $resulttext .= $alltypes{$type}.', ';
12129: }
12130: $resulttext =~ s/, $//;
12131: } else {
12132: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
12133: }
12134: $resulttext .= '</li>';
12135: }
12136: }
12137: } else {
12138: my $value = $env{'form.'.$item};
12139: if ($value eq '') {
12140: $value = &mt('none');
12141: } elsif ($item eq 'auth_def') {
12142: my %authnames = &authtype_names();
12143: my %shortauth = (
12144: internal => 'int',
12145: krb4 => 'krb4',
12146: krb5 => 'krb5',
12147: localauth => 'loc',
12148: );
12149: $value = $authnames{$shortauth{$value}};
12150: } elsif ($item eq 'intauth_switch') {
12151: my %optiondesc = &Apache::lonlocal::texthash (
12152: 0 => 'No',
12153: 1 => 'Yes',
12154: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
12155: );
12156: if ($value =~ /^(0|1|2)$/) {
12157: $value = $optiondesc{$value};
12158: } else {
12159: $value = &mt('none -- defaults to No');
12160: }
12161: } elsif ($item eq 'intauth_check') {
12162: my %optiondesc = &Apache::lonlocal::texthash (
12163: 0 => 'No',
12164: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
12165: 2 => 'Yes, disallow login if stored cost is less than domain default',
12166: );
12167: if ($value =~ /^(0|1|2)$/) {
12168: $value = $optiondesc{$value};
12169: } else {
12170: $value = &mt('none -- defaults to No');
12171: }
12172: }
12173: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
12174: $mailmsgtext .= "$title->{$item} set to $value\n";
12175: }
12176: }
12177: $resulttext .= '</ul>';
12178: $mailmsgtext .= "\n";
12179: my $cachetime = 24*60*60;
12180: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12181: if (ref($lastactref) eq 'HASH') {
12182: $lastactref->{'domdefaults'} = 1;
12183: }
12184: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
12185: my $notify = 1;
12186: if (ref($domconfig{'contacts'}) eq 'HASH') {
12187: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
12188: $notify = 0;
12189: }
12190: }
12191: if ($notify) {
12192: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
12193: "LON-CAPA Domain Settings Change - $dom",
12194: $mailmsgtext);
12195: }
12196: }
12197: } else {
12198: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
12199: }
12200: } else {
12201: $resulttext = '<span class="LC_error">'.
12202: &mt('An error occurred: [_1]',$putresult).'</span>';
12203: }
12204: if (@errors > 0) {
12205: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
12206: foreach my $item (@errors) {
12207: $resulttext .= ' "'.$title->{$item}.'",';
12208: }
12209: $resulttext =~ s/,$//;
12210: }
12211: return $resulttext;
12212: }
12213:
12214: sub modify_scantron {
12215: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
12216: my ($resulttext,%confhash,%changes,$errors);
12217: my $custom = 'custom.tab';
12218: my $default = 'default.tab';
12219: my $servadm = $r->dir_config('lonAdmEMail');
12220: my ($configuserok,$author_ok,$switchserver) =
12221: &config_check($dom,$confname,$servadm);
12222: if ($env{'form.scantronformat.filename'} ne '') {
12223: my $error;
12224: if ($configuserok eq 'ok') {
12225: if ($switchserver) {
12226: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
12227: } else {
12228: if ($author_ok eq 'ok') {
12229: my ($result,$scantronurl) =
12230: &publishlogo($r,'upload','scantronformat',$dom,
12231: $confname,'scantron','','',$custom);
12232: if ($result eq 'ok') {
12233: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
12234: $changes{'scantronformat'} = 1;
12235: } else {
12236: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
12237: }
12238: } else {
12239: $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);
12240: }
12241: }
12242: } else {
12243: $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);
12244: }
12245: if ($error) {
12246: &Apache::lonnet::logthis($error);
12247: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12248: }
12249: }
12250: if (ref($domconfig{'scantron'}) eq 'HASH') {
12251: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
12252: if ($env{'form.scantronformat_del'}) {
12253: $confhash{'scantron'}{'scantronformat'} = '';
12254: $changes{'scantronformat'} = 1;
12255: }
12256: }
12257: }
12258: if (keys(%confhash) > 0) {
12259: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
12260: $dom);
12261: if ($putresult eq 'ok') {
12262: if (keys(%changes) > 0) {
12263: if (ref($confhash{'scantron'}) eq 'HASH') {
12264: $resulttext = &mt('Changes made:').'<ul>';
12265: if ($confhash{'scantron'}{'scantronformat'} eq '') {
12266: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
12267: } else {
12268: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
12269: }
12270: $resulttext .= '</ul>';
12271: } else {
12272: $resulttext = &mt('Changes made to bubblesheet format file.');
12273: }
12274: $resulttext .= '</ul>';
12275: &Apache::loncommon::devalidate_domconfig_cache($dom);
12276: if (ref($lastactref) eq 'HASH') {
12277: $lastactref->{'domainconfig'} = 1;
12278: }
12279: } else {
12280: $resulttext = &mt('No changes made to bubblesheet format file');
12281: }
12282: } else {
12283: $resulttext = '<span class="LC_error">'.
12284: &mt('An error occurred: [_1]',$putresult).'</span>';
12285: }
12286: } else {
12287: $resulttext = &mt('No changes made to bubblesheet format file');
12288: }
12289: if ($errors) {
12290: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12291: $errors.'</ul>';
12292: }
12293: return $resulttext;
12294: }
12295:
12296: sub modify_coursecategories {
12297: my ($dom,$lastactref,%domconfig) = @_;
12298: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
12299: $cathash);
12300: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
12301: my @catitems = ('unauth','auth');
12302: my @cattypes = ('std','domonly','codesrch','none');
12303: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
12304: $cathash = $domconfig{'coursecategories'}{'cats'};
12305: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
12306: $changes{'togglecats'} = 1;
12307: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
12308: }
12309: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
12310: $changes{'categorize'} = 1;
12311: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
12312: }
12313: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
12314: $changes{'togglecatscomm'} = 1;
12315: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
12316: }
12317: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
12318: $changes{'categorizecomm'} = 1;
12319: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
12320: }
12321: foreach my $item (@catitems) {
12322: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12323: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
12324: $changes{$item} = 1;
12325: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12326: }
12327: }
12328: }
12329: } else {
12330: $changes{'togglecats'} = 1;
12331: $changes{'categorize'} = 1;
12332: $changes{'togglecatscomm'} = 1;
12333: $changes{'categorizecomm'} = 1;
12334: $domconfig{'coursecategories'} = {
12335: togglecats => $env{'form.togglecats'},
12336: categorize => $env{'form.categorize'},
12337: togglecatscomm => $env{'form.togglecatscomm'},
12338: categorizecomm => $env{'form.categorizecomm'},
12339: };
12340: foreach my $item (@catitems) {
12341: if ($env{'form.coursecat_'.$item} ne 'std') {
12342: $changes{$item} = 1;
12343: }
12344: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12345: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12346: }
12347: }
12348: }
12349: if (ref($cathash) eq 'HASH') {
12350: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
12351: push (@deletecategory,'instcode::0');
12352: }
12353: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
12354: push(@deletecategory,'communities::0');
12355: }
12356: }
12357: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
12358: if (ref($cathash) eq 'HASH') {
12359: if (@deletecategory > 0) {
12360: #FIXME Need to remove category from all courses using a deleted category
12361: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
12362: foreach my $item (@deletecategory) {
12363: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
12364: delete($domconfig{'coursecategories'}{'cats'}{$item});
12365: $deletions{$item} = 1;
12366: &recurse_cat_deletes($item,$cathash,\%deletions);
12367: }
12368: }
12369: }
12370: foreach my $item (keys(%{$cathash})) {
12371: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
12372: if ($cathash->{$item} ne $env{'form.'.$item}) {
12373: $reorderings{$item} = 1;
12374: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
12375: }
12376: if ($env{'form.addcategory_name_'.$item} ne '') {
12377: my $newcat = $env{'form.addcategory_name_'.$item};
12378: my $newdepth = $depth+1;
12379: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
12380: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
12381: $adds{$newitem} = 1;
12382: }
12383: if ($env{'form.subcat_'.$item} ne '') {
12384: my $newcat = $env{'form.subcat_'.$item};
12385: my $newdepth = $depth+1;
12386: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
12387: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
12388: $adds{$newitem} = 1;
12389: }
12390: }
12391: }
12392: if ($env{'form.instcode'} eq '1') {
12393: if (ref($cathash) eq 'HASH') {
12394: my $newitem = 'instcode::0';
12395: if ($cathash->{$newitem} eq '') {
12396: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
12397: $adds{$newitem} = 1;
12398: }
12399: } else {
12400: my $newitem = 'instcode::0';
12401: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
12402: $adds{$newitem} = 1;
12403: }
12404: }
12405: if ($env{'form.communities'} eq '1') {
12406: if (ref($cathash) eq 'HASH') {
12407: my $newitem = 'communities::0';
12408: if ($cathash->{$newitem} eq '') {
12409: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
12410: $adds{$newitem} = 1;
12411: }
12412: } else {
12413: my $newitem = 'communities::0';
12414: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
12415: $adds{$newitem} = 1;
12416: }
12417: }
12418: if ($env{'form.addcategory_name'} ne '') {
12419: if (($env{'form.addcategory_name'} ne 'instcode') &&
12420: ($env{'form.addcategory_name'} ne 'communities')) {
12421: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
12422: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
12423: $adds{$newitem} = 1;
12424: }
12425: }
12426: my $putresult;
12427: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12428: if (keys(%deletions) > 0) {
12429: foreach my $key (keys(%deletions)) {
12430: if ($predelallitems{$key} ne '') {
12431: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
12432: }
12433: }
12434: }
12435: my (@chkcats,@chktrails,%chkallitems);
12436: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
12437: if (ref($chkcats[0]) eq 'ARRAY') {
12438: my $depth = 0;
12439: my $chg = 0;
12440: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
12441: my $name = $chkcats[0][$i];
12442: my $item;
12443: if ($name eq '') {
12444: $chg ++;
12445: } else {
12446: $item = &escape($name).'::0';
12447: if ($chg) {
12448: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
12449: }
12450: $depth ++;
12451: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
12452: $depth --;
12453: }
12454: }
12455: }
12456: }
12457: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12458: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
12459: if ($putresult eq 'ok') {
12460: my %title = (
12461: togglecats => 'Show/Hide a course in catalog',
12462: categorize => 'Assign a category to a course',
12463: togglecatscomm => 'Show/Hide a community in catalog',
12464: categorizecomm => 'Assign a category to a community',
12465: );
12466: my %level = (
12467: dom => 'set in Domain ("Modify Course/Community")',
12468: crs => 'set in Course ("Course Configuration")',
12469: comm => 'set in Community ("Community Configuration")',
12470: none => 'No catalog',
12471: std => 'Standard catalog',
12472: domonly => 'Domain-only catalog',
12473: codesrch => 'Code search form',
12474: );
12475: $resulttext = &mt('Changes made:').'<ul>';
12476: if ($changes{'togglecats'}) {
12477: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
12478: }
12479: if ($changes{'categorize'}) {
12480: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
12481: }
12482: if ($changes{'togglecatscomm'}) {
12483: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
12484: }
12485: if ($changes{'categorizecomm'}) {
12486: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
12487: }
12488: if ($changes{'unauth'}) {
12489: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
12490: }
12491: if ($changes{'auth'}) {
12492: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
12493: }
12494: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12495: my $cathash;
12496: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
12497: $cathash = $domconfig{'coursecategories'}{'cats'};
12498: } else {
12499: $cathash = {};
12500: }
12501: my (@cats,@trails,%allitems);
12502: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
12503: if (keys(%deletions) > 0) {
12504: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
12505: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
12506: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
12507: }
12508: $resulttext .= '</ul></li>';
12509: }
12510: if (keys(%reorderings) > 0) {
12511: my %sort_by_trail;
12512: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
12513: foreach my $key (keys(%reorderings)) {
12514: if ($allitems{$key} ne '') {
12515: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
12516: }
12517: }
12518: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
12519: $resulttext .= '<li>'.$trails[$trail].'</li>';
12520: }
12521: $resulttext .= '</ul></li>';
12522: }
12523: if (keys(%adds) > 0) {
12524: my %sort_by_trail;
12525: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
12526: foreach my $key (keys(%adds)) {
12527: if ($allitems{$key} ne '') {
12528: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
12529: }
12530: }
12531: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
12532: $resulttext .= '<li>'.$trails[$trail].'</li>';
12533: }
12534: $resulttext .= '</ul></li>';
12535: }
12536: }
12537: $resulttext .= '</ul>';
12538: if ($changes{'unauth'} || $changes{'auth'}) {
12539: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
12540: if ($changes{'auth'}) {
12541: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
12542: }
12543: if ($changes{'unauth'}) {
12544: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
12545: }
12546: my $cachetime = 24*60*60;
12547: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12548: if (ref($lastactref) eq 'HASH') {
12549: $lastactref->{'domdefaults'} = 1;
12550: }
12551: }
12552: } else {
12553: $resulttext = '<span class="LC_error">'.
12554: &mt('An error occurred: [_1]',$putresult).'</span>';
12555: }
12556: } else {
12557: $resulttext = &mt('No changes made to course and community categories');
12558: }
12559: return $resulttext;
12560: }
12561:
12562: sub modify_serverstatuses {
12563: my ($dom,%domconfig) = @_;
12564: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
12565: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
12566: %currserverstatus = %{$domconfig{'serverstatuses'}};
12567: }
12568: my @pages = &serverstatus_pages();
12569: foreach my $type (@pages) {
12570: $newserverstatus{$type}{'namedusers'} = '';
12571: $newserverstatus{$type}{'machines'} = '';
12572: if (defined($env{'form.'.$type.'_namedusers'})) {
12573: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
12574: my @okusers;
12575: foreach my $user (@users) {
12576: my ($uname,$udom) = split(/:/,$user);
12577: if (($udom =~ /^$match_domain$/) &&
12578: (&Apache::lonnet::domain($udom)) &&
12579: ($uname =~ /^$match_username$/)) {
12580: if (!grep(/^\Q$user\E/,@okusers)) {
12581: push(@okusers,$user);
12582: }
12583: }
12584: }
12585: if (@okusers > 0) {
12586: @okusers = sort(@okusers);
12587: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
12588: }
12589: }
12590: if (defined($env{'form.'.$type.'_machines'})) {
12591: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
12592: my @okmachines;
12593: foreach my $ip (@machines) {
12594: my @parts = split(/\./,$ip);
12595: next if (@parts < 4);
12596: my $badip = 0;
12597: for (my $i=0; $i<4; $i++) {
12598: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
12599: $badip = 1;
12600: last;
12601: }
12602: }
12603: if (!$badip) {
12604: push(@okmachines,$ip);
12605: }
12606: }
12607: @okmachines = sort(@okmachines);
12608: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
12609: }
12610: }
12611: my %serverstatushash = (
12612: serverstatuses => \%newserverstatus,
12613: );
12614: foreach my $type (@pages) {
12615: foreach my $setting ('namedusers','machines') {
12616: my (@current,@new);
12617: if (ref($currserverstatus{$type}) eq 'HASH') {
12618: if ($currserverstatus{$type}{$setting} ne '') {
12619: @current = split(/,/,$currserverstatus{$type}{$setting});
12620: }
12621: }
12622: if ($newserverstatus{$type}{$setting} ne '') {
12623: @new = split(/,/,$newserverstatus{$type}{$setting});
12624: }
12625: if (@current > 0) {
12626: if (@new > 0) {
12627: foreach my $item (@current) {
12628: if (!grep(/^\Q$item\E$/,@new)) {
12629: $changes{$type}{$setting} = 1;
12630: last;
12631: }
12632: }
12633: foreach my $item (@new) {
12634: if (!grep(/^\Q$item\E$/,@current)) {
12635: $changes{$type}{$setting} = 1;
12636: last;
12637: }
12638: }
12639: } else {
12640: $changes{$type}{$setting} = 1;
12641: }
12642: } elsif (@new > 0) {
12643: $changes{$type}{$setting} = 1;
12644: }
12645: }
12646: }
12647: if (keys(%changes) > 0) {
12648: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
12649: my $putresult = &Apache::lonnet::put_dom('configuration',
12650: \%serverstatushash,$dom);
12651: if ($putresult eq 'ok') {
12652: $resulttext .= &mt('Changes made:').'<ul>';
12653: foreach my $type (@pages) {
12654: if (ref($changes{$type}) eq 'HASH') {
12655: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
12656: if ($changes{$type}{'namedusers'}) {
12657: if ($newserverstatus{$type}{'namedusers'} eq '') {
12658: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
12659: } else {
12660: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
12661: }
12662: }
12663: if ($changes{$type}{'machines'}) {
12664: if ($newserverstatus{$type}{'machines'} eq '') {
12665: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
12666: } else {
12667: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
12668: }
12669:
12670: }
12671: $resulttext .= '</ul></li>';
12672: }
12673: }
12674: $resulttext .= '</ul>';
12675: } else {
12676: $resulttext = '<span class="LC_error">'.
12677: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
12678:
12679: }
12680: } else {
12681: $resulttext = &mt('No changes made to access to server status pages');
12682: }
12683: return $resulttext;
12684: }
12685:
12686: sub modify_helpsettings {
12687: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
12688: my ($resulttext,$errors,%changes,%helphash);
12689: my %defaultchecked = ('submitbugs' => 'on');
12690: my @offon = ('off','on');
12691: my @toggles = ('submitbugs');
12692: my %current = ('submitbugs' => '',
12693: 'adhoc' => {},
12694: );
12695: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
12696: %current = %{$domconfig{'helpsettings'}};
12697: }
12698: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12699: foreach my $item (@toggles) {
12700: if ($defaultchecked{$item} eq 'on') {
12701: if ($current{$item} eq '') {
12702: if ($env{'form.'.$item} eq '0') {
12703: $changes{$item} = 1;
12704: }
12705: } elsif ($current{$item} ne $env{'form.'.$item}) {
12706: $changes{$item} = 1;
12707: }
12708: } elsif ($defaultchecked{$item} eq 'off') {
12709: if ($current{$item} eq '') {
12710: if ($env{'form.'.$item} eq '1') {
12711: $changes{$item} = 1;
12712: }
12713: } elsif ($current{$item} ne $env{'form.'.$item}) {
12714: $changes{$item} = 1;
12715: }
12716: }
12717: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
12718: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
12719: }
12720: }
12721: my $maxnum = $env{'form.helproles_maxnum'};
12722: my $confname = $dom.'-domainconfig';
12723: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
12724: my (@allpos,%newsettings,%changedprivs,$newrole);
12725: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12726: my @accesstypes = ('all','dh','da','none','status','inc','exc');
12727: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
12728: my %lt = &Apache::lonlocal::texthash(
12729: s => 'system',
12730: d => 'domain',
12731: order => 'Display order',
12732: access => 'Role usage',
12733: all => 'All with domain helpdesk or helpdesk assistant role',
12734: dh => 'All with domain helpdesk role',
12735: da => 'All with domain helpdesk assistant role',
12736: none => 'None',
12737: status => 'Determined based on institutional status',
12738: inc => 'Include all, but exclude specific personnel',
12739: exc => 'Exclude all, but include specific personnel',
12740: );
12741: for (my $num=0; $num<=$maxnum; $num++) {
12742: my ($prefix,$identifier,$rolename,%curr);
12743: if ($num == $maxnum) {
12744: next unless ($env{'form.newcusthelp'} == $maxnum);
12745: $identifier = 'custhelp'.$num;
12746: $prefix = 'helproles_'.$num;
12747: $rolename = $env{'form.custhelpname'.$num};
12748: $rolename=~s/[^A-Za-z0-9]//gs;
12749: next if ($rolename eq '');
12750: next if (exists($existing{'rolesdef_'.$rolename}));
12751: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
12752: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
12753: $newprivs{'c'},$confname,$dom);
12754: if ($result ne 'ok') {
12755: $errors .= '<li><span class="LC_error">'.
12756: &mt('An error occurred storing the new custom role: [_1]',
12757: $result).'</span></li>';
12758: next;
12759: } else {
12760: $changedprivs{$rolename} = \%newprivs;
12761: $newrole = $rolename;
12762: }
12763: } else {
12764: $prefix = 'helproles_'.$num;
12765: $rolename = $env{'form.'.$prefix};
12766: next if ($rolename eq '');
12767: next unless (exists($existing{'rolesdef_'.$rolename}));
12768: $identifier = 'custhelp'.$num;
12769: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
12770: my %currprivs;
12771: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
12772: split(/\_/,$existing{'rolesdef_'.$rolename});
12773: foreach my $level ('c','d','s') {
12774: if ($newprivs{$level} ne $currprivs{$level}) {
12775: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
12776: $newprivs{'c'},$confname,$dom);
12777: if ($result ne 'ok') {
12778: $errors .= '<li><span class="LC_error">'.
12779: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
12780: $rolename,$result).'</span></li>';
12781: } else {
12782: $changedprivs{$rolename} = \%newprivs;
12783: }
12784: last;
12785: }
12786: }
12787: if (ref($current{'adhoc'}) eq 'HASH') {
12788: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
12789: %curr = %{$current{'adhoc'}{$rolename}};
12790: }
12791: }
12792: }
12793: my $newpos = $env{'form.'.$prefix.'_pos'};
12794: $newpos =~ s/\D+//g;
12795: $allpos[$newpos] = $rolename;
12796: my $newdesc = $env{'form.'.$prefix.'_desc'};
12797: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
12798: if ($curr{'desc'}) {
12799: if ($curr{'desc'} ne $newdesc) {
12800: $changes{'customrole'}{$rolename}{'desc'} = 1;
12801: $newsettings{$rolename}{'desc'} = $newdesc;
12802: }
12803: } elsif ($newdesc ne '') {
12804: $changes{'customrole'}{$rolename}{'desc'} = 1;
12805: $newsettings{$rolename}{'desc'} = $newdesc;
12806: }
12807: my $access = $env{'form.'.$prefix.'_access'};
12808: if (grep(/^\Q$access\E$/,@accesstypes)) {
12809: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
12810: if ($access eq 'status') {
12811: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
12812: if (scalar(@statuses) == 0) {
12813: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
12814: } else {
12815: my (@shownstatus,$numtypes);
12816: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
12817: if (ref($types) eq 'ARRAY') {
12818: $numtypes = scalar(@{$types});
12819: foreach my $type (sort(@statuses)) {
12820: if ($type eq 'default') {
12821: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
12822: } elsif (grep(/^\Q$type\E$/,@{$types})) {
12823: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
12824: push(@shownstatus,$usertypes->{$type});
12825: }
12826: }
12827: }
12828: if (grep(/^default$/,@statuses)) {
12829: push(@shownstatus,$othertitle);
12830: }
12831: if (scalar(@shownstatus) == 1+$numtypes) {
12832: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
12833: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
12834: } else {
12835: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
12836: if (ref($curr{'status'}) eq 'ARRAY') {
12837: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
12838: if (@diffs) {
12839: $changes{'customrole'}{$rolename}{$access} = 1;
12840: }
12841: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12842: $changes{'customrole'}{$rolename}{$access} = 1;
12843: }
12844: }
12845: }
12846: } elsif (($access eq 'inc') || ($access eq 'exc')) {
12847: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
12848: my @newspecstaff;
12849: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
12850: foreach my $person (sort(@personnel)) {
12851: if ($domhelpdesk{$person}) {
12852: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
12853: }
12854: }
12855: if (ref($curr{$access}) eq 'ARRAY') {
12856: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
12857: if (@diffs) {
12858: $changes{'customrole'}{$rolename}{$access} = 1;
12859: }
12860: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12861: $changes{'customrole'}{$rolename}{$access} = 1;
12862: }
12863: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12864: my ($uname,$udom) = split(/:/,$person);
12865: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
12866: }
12867: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
12868: }
12869: } else {
12870: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
12871: }
12872: unless ($curr{'access'} eq $access) {
12873: $changes{'customrole'}{$rolename}{'access'} = 1;
12874: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
12875: }
12876: }
12877: if (@allpos > 0) {
12878: my $idx = 0;
12879: foreach my $rolename (@allpos) {
12880: if ($rolename ne '') {
12881: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
12882: if (ref($current{'adhoc'}) eq 'HASH') {
12883: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
12884: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
12885: $changes{'customrole'}{$rolename}{'order'} = 1;
12886: $newsettings{$rolename}{'order'} = $idx+1;
12887: }
12888: }
12889: }
12890: $idx ++;
12891: }
12892: }
12893: }
12894: my $putresult;
12895: if (keys(%changes) > 0) {
12896: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
12897: if ($putresult eq 'ok') {
12898: if (ref($helphash{'helpsettings'}) eq 'HASH') {
12899: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
12900: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
12901: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
12902: }
12903: }
12904: my $cachetime = 24*60*60;
12905: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12906: if (ref($lastactref) eq 'HASH') {
12907: $lastactref->{'domdefaults'} = 1;
12908: }
12909: } else {
12910: $errors .= '<li><span class="LC_error">'.
12911: &mt('An error occurred storing the settings: [_1]',
12912: $putresult).'</span></li>';
12913: }
12914: }
12915: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
12916: $resulttext = &mt('Changes made:').'<ul>';
12917: my (%shownprivs,@levelorder);
12918: @levelorder = ('c','d','s');
12919: if ((keys(%changes)) && ($putresult eq 'ok')) {
12920: foreach my $item (sort(keys(%changes))) {
12921: if ($item eq 'submitbugs') {
12922: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
12923: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
12924: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
12925: } elsif ($item eq 'customrole') {
12926: if (ref($changes{'customrole'}) eq 'HASH') {
12927: my @keyorder = ('order','desc','access','status','exc','inc');
12928: my %keytext = &Apache::lonlocal::texthash(
12929: order => 'Order',
12930: desc => 'Role description',
12931: access => 'Role usage',
12932: status => 'Allowed institutional types',
12933: exc => 'Allowed personnel',
12934: inc => 'Disallowed personnel',
12935: );
12936: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
12937: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
12938: if ($role eq $newrole) {
12939: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
12940: $role).'<ul>';
12941: } else {
12942: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
12943: $role).'<ul>';
12944: }
12945: foreach my $key (@keyorder) {
12946: if ($changes{'customrole'}{$role}{$key}) {
12947: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
12948: $keytext{$key},$newsettings{$role}{$key}).
12949: '</li>';
12950: }
12951: }
12952: if (ref($changedprivs{$role}) eq 'HASH') {
12953: $shownprivs{$role} = 1;
12954: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
12955: foreach my $level (@levelorder) {
12956: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
12957: next if ($item eq '');
12958: my ($priv) = split(/\&/,$item,2);
12959: if (&Apache::lonnet::plaintext($priv)) {
12960: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
12961: unless ($level eq 'c') {
12962: $resulttext .= ' ('.$lt{$level}.')';
12963: }
12964: $resulttext .= '</li>';
12965: }
12966: }
12967: }
12968: $resulttext .= '</ul>';
12969: }
12970: $resulttext .= '</ul></li>';
12971: }
12972: }
12973: }
12974: }
12975: }
12976: }
12977: if (keys(%changedprivs)) {
12978: foreach my $role (sort(keys(%changedprivs))) {
12979: unless ($shownprivs{$role}) {
12980: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
12981: $role).'<ul>'.
12982: '<li>'.&mt('Privileges set to :').'<ul>';
12983: foreach my $level (@levelorder) {
12984: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
12985: next if ($item eq '');
12986: my ($priv) = split(/\&/,$item,2);
12987: if (&Apache::lonnet::plaintext($priv)) {
12988: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
12989: unless ($level eq 'c') {
12990: $resulttext .= ' ('.$lt{$level}.')';
12991: }
12992: $resulttext .= '</li>';
12993: }
12994: }
12995: }
12996: $resulttext .= '</ul></li></ul></li>';
12997: }
12998: }
12999: }
13000: $resulttext .= '</ul>';
13001: } else {
13002: $resulttext = &mt('No changes made to help settings');
13003: }
13004: if ($errors) {
13005: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
13006: $errors.'</ul>';
13007: }
13008: return $resulttext;
13009: }
13010:
13011: sub modify_coursedefaults {
13012: my ($dom,$lastactref,%domconfig) = @_;
13013: my ($resulttext,$errors,%changes,%defaultshash);
13014: my %defaultchecked = (
13015: 'uselcmath' => 'on',
13016: 'usejsme' => 'on'
13017: );
13018: my @toggles = ('uselcmath','usejsme');
13019: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
13020: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
13021: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
13022: my @types = ('official','unofficial','community','textbook');
13023: my %staticdefaults = (
13024: anonsurvey_threshold => 10,
13025: uploadquota => 500,
13026: postsubmit => 60,
13027: mysqltables => 172800,
13028: );
13029:
13030: $defaultshash{'coursedefaults'} = {};
13031:
13032: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
13033: if ($domconfig{'coursedefaults'} eq '') {
13034: $domconfig{'coursedefaults'} = {};
13035: }
13036: }
13037:
13038: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
13039: foreach my $item (@toggles) {
13040: if ($defaultchecked{$item} eq 'on') {
13041: if (($domconfig{'coursedefaults'}{$item} eq '') &&
13042: ($env{'form.'.$item} eq '0')) {
13043: $changes{$item} = 1;
13044: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
13045: $changes{$item} = 1;
13046: }
13047: } elsif ($defaultchecked{$item} eq 'off') {
13048: if (($domconfig{'coursedefaults'}{$item} eq '') &&
13049: ($env{'form.'.$item} eq '1')) {
13050: $changes{$item} = 1;
13051: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
13052: $changes{$item} = 1;
13053: }
13054: }
13055: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
13056: }
13057: foreach my $item (@numbers) {
13058: my ($currdef,$newdef);
13059: $newdef = $env{'form.'.$item};
13060: if ($item eq 'anonsurvey_threshold') {
13061: $currdef = $domconfig{'coursedefaults'}{$item};
13062: $newdef =~ s/\D//g;
13063: if ($newdef eq '' || $newdef < 1) {
13064: $newdef = 1;
13065: }
13066: $defaultshash{'coursedefaults'}{$item} = $newdef;
13067: } else {
13068: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
13069: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
13070: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
13071: }
13072: $newdef =~ s/[^\w.\-]//g;
13073: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
13074: }
13075: if ($currdef ne $newdef) {
13076: my $staticdef;
13077: if ($item eq 'anonsurvey_threshold') {
13078: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
13079: $changes{$item} = 1;
13080: }
13081: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
13082: my $setting = $1;
13083: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
13084: $changes{$setting} = 1;
13085: }
13086: }
13087: }
13088: }
13089: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
13090: my @currclonecode;
13091: if (ref($currclone) eq 'HASH') {
13092: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
13093: @currclonecode = @{$currclone->{'instcode'}};
13094: }
13095: }
13096: my $newclone;
13097: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
13098: $newclone = $env{'form.canclone'};
13099: }
13100: if ($newclone eq 'instcode') {
13101: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
13102: my (%codedefaults,@code_order,@clonecode);
13103: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
13104: \@code_order);
13105: foreach my $item (@code_order) {
13106: if (grep(/^\Q$item\E$/,@newcodes)) {
13107: push(@clonecode,$item);
13108: }
13109: }
13110: if (@clonecode) {
13111: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
13112: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
13113: if (@diffs) {
13114: $changes{'canclone'} = 1;
13115: }
13116: } else {
13117: $newclone eq '';
13118: }
13119: } elsif ($newclone ne '') {
13120: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
13121: }
13122: if ($newclone ne $currclone) {
13123: $changes{'canclone'} = 1;
13124: }
13125: my %credits;
13126: foreach my $type (@types) {
13127: unless ($type eq 'community') {
13128: $credits{$type} = $env{'form.'.$type.'_credits'};
13129: $credits{$type} =~ s/[^\d.]+//g;
13130: }
13131: }
13132: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
13133: ($env{'form.coursecredits'} eq '1')) {
13134: $changes{'coursecredits'} = 1;
13135: foreach my $type (keys(%credits)) {
13136: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
13137: }
13138: } else {
13139: if ($env{'form.coursecredits'} eq '1') {
13140: foreach my $type (@types) {
13141: unless ($type eq 'community') {
13142: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
13143: $changes{'coursecredits'} = 1;
13144: }
13145: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
13146: }
13147: }
13148: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13149: foreach my $type (@types) {
13150: unless ($type eq 'community') {
13151: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
13152: $changes{'coursecredits'} = 1;
13153: last;
13154: }
13155: }
13156: }
13157: }
13158: }
13159: if ($env{'form.postsubmit'} eq '1') {
13160: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
13161: my %currtimeout;
13162: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13163: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
13164: $changes{'postsubmit'} = 1;
13165: }
13166: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13167: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
13168: }
13169: } else {
13170: $changes{'postsubmit'} = 1;
13171: }
13172: foreach my $type (@types) {
13173: my $timeout = $env{'form.'.$type.'_timeout'};
13174: $timeout =~ s/\D//g;
13175: if ($timeout == $staticdefaults{'postsubmit'}) {
13176: $timeout = '';
13177: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
13178: $timeout = '0';
13179: }
13180: unless ($timeout eq '') {
13181: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
13182: }
13183: if (exists($currtimeout{$type})) {
13184: if ($timeout ne $currtimeout{$type}) {
13185: $changes{'postsubmit'} = 1;
13186: }
13187: } elsif ($timeout ne '') {
13188: $changes{'postsubmit'} = 1;
13189: }
13190: }
13191: } else {
13192: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
13193: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13194: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
13195: $changes{'postsubmit'} = 1;
13196: }
13197: } else {
13198: $changes{'postsubmit'} = 1;
13199: }
13200: }
13201: }
13202: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13203: $dom);
13204: if ($putresult eq 'ok') {
13205: if (keys(%changes) > 0) {
13206: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13207: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
13208: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
13209: ($changes{'canclone'}) || ($changes{'mysqltables'})) {
13210: foreach my $item ('uselcmath','usejsme') {
13211: if ($changes{$item}) {
13212: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
13213: }
13214: }
13215: if ($changes{'coursecredits'}) {
13216: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13217: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
13218: $domdefaults{$type.'credits'} =
13219: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
13220: }
13221: }
13222: }
13223: if ($changes{'postsubmit'}) {
13224: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13225: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
13226: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13227: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
13228: $domdefaults{$type.'postsubtimeout'} =
13229: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
13230: }
13231: }
13232: }
13233: }
13234: if ($changes{'uploadquota'}) {
13235: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
13236: foreach my $type (@types) {
13237: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
13238: }
13239: }
13240: }
13241: if ($changes{'canclone'}) {
13242: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
13243: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
13244: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
13245: if (@clonecodes) {
13246: $domdefaults{'canclone'} = join('+',@clonecodes);
13247: }
13248: }
13249: } else {
13250: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
13251: }
13252: }
13253: my $cachetime = 24*60*60;
13254: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13255: if (ref($lastactref) eq 'HASH') {
13256: $lastactref->{'domdefaults'} = 1;
13257: }
13258: }
13259: $resulttext = &mt('Changes made:').'<ul>';
13260: foreach my $item (sort(keys(%changes))) {
13261: if ($item eq 'uselcmath') {
13262: if ($env{'form.'.$item} eq '1') {
13263: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
13264: } else {
13265: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
13266: }
13267: } elsif ($item eq 'usejsme') {
13268: if ($env{'form.'.$item} eq '1') {
13269: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
13270: } else {
13271: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
13272: }
13273: } elsif ($item eq 'anonsurvey_threshold') {
13274: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
13275: } elsif ($item eq 'uploadquota') {
13276: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
13277: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
13278: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
13279: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
13280: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
13281:
13282: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
13283: '</ul>'.
13284: '</li>';
13285: } else {
13286: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
13287: }
13288: } elsif ($item eq 'mysqltables') {
13289: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
13290: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
13291: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
13292: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
13293: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
13294: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
13295: '</ul>'.
13296: '</li>';
13297: } else {
13298: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
13299: }
13300: } elsif ($item eq 'postsubmit') {
13301: if ($domdefaults{'postsubmit'} eq 'off') {
13302: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
13303: } else {
13304: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
13305: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13306: $resulttext .= &mt('durations:').'<ul>';
13307: foreach my $type (@types) {
13308: $resulttext .= '<li>';
13309: my $timeout;
13310: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13311: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
13312: }
13313: my $display;
13314: if ($timeout eq '0') {
13315: $display = &mt('unlimited');
13316: } elsif ($timeout eq '') {
13317: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
13318: } else {
13319: $display = &mt('[quant,_1,second]',$timeout);
13320: }
13321: if ($type eq 'community') {
13322: $resulttext .= &mt('Communities');
13323: } elsif ($type eq 'official') {
13324: $resulttext .= &mt('Official courses');
13325: } elsif ($type eq 'unofficial') {
13326: $resulttext .= &mt('Unofficial courses');
13327: } elsif ($type eq 'textbook') {
13328: $resulttext .= &mt('Textbook courses');
13329: }
13330: $resulttext .= ' -- '.$display.'</li>';
13331: }
13332: $resulttext .= '</ul>';
13333: }
13334: $resulttext .= '</li>';
13335: }
13336: } elsif ($item eq 'coursecredits') {
13337: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13338: if (($domdefaults{'officialcredits'} eq '') &&
13339: ($domdefaults{'unofficialcredits'} eq '') &&
13340: ($domdefaults{'textbookcredits'} eq '')) {
13341: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13342: } else {
13343: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
13344: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
13345: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
13346: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
13347: '</ul>'.
13348: '</li>';
13349: }
13350: } else {
13351: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13352: }
13353: } elsif ($item eq 'canclone') {
13354: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
13355: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
13356: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
13357: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
13358: }
13359: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
13360: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
13361: } else {
13362: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
13363: }
13364: }
13365: }
13366: $resulttext .= '</ul>';
13367: } else {
13368: $resulttext = &mt('No changes made to course defaults');
13369: }
13370: } else {
13371: $resulttext = '<span class="LC_error">'.
13372: &mt('An error occurred: [_1]',$putresult).'</span>';
13373: }
13374: return $resulttext;
13375: }
13376:
13377: sub modify_selfenrollment {
13378: my ($dom,$lastactref,%domconfig) = @_;
13379: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
13380: my @types = ('official','unofficial','community','textbook');
13381: my %titles = &tool_titles();
13382: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
13383: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
13384: $ordered{'default'} = ['types','registered','approval','limit'];
13385:
13386: my (%roles,%shown,%toplevel);
13387: $roles{'0'} = &Apache::lonnet::plaintext('dc');
13388:
13389: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
13390: if ($domconfig{'selfenrollment'} eq '') {
13391: $domconfig{'selfenrollment'} = {};
13392: }
13393: }
13394: %toplevel = (
13395: admin => 'Configuration Rights',
13396: default => 'Default settings',
13397: validation => 'Validation of self-enrollment requests',
13398: );
13399: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
13400:
13401: if (ref($ordered{'admin'}) eq 'ARRAY') {
13402: foreach my $item (@{$ordered{'admin'}}) {
13403: foreach my $type (@types) {
13404: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
13405: $selfenrollhash{'admin'}{$type}{$item} = 1;
13406: } else {
13407: $selfenrollhash{'admin'}{$type}{$item} = 0;
13408: }
13409: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
13410: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
13411: if ($selfenrollhash{'admin'}{$type}{$item} ne
13412: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
13413: push(@{$changes{'admin'}{$type}},$item);
13414: }
13415: } else {
13416: if (!$selfenrollhash{'admin'}{$type}{$item}) {
13417: push(@{$changes{'admin'}{$type}},$item);
13418: }
13419: }
13420: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
13421: push(@{$changes{'admin'}{$type}},$item);
13422: }
13423: }
13424: }
13425: }
13426:
13427: foreach my $item (@{$ordered{'default'}}) {
13428: foreach my $type (@types) {
13429: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
13430: if ($item eq 'types') {
13431: unless (($value eq 'all') || ($value eq 'dom')) {
13432: $value = '';
13433: }
13434: } elsif ($item eq 'registered') {
13435: unless ($value eq '1') {
13436: $value = 0;
13437: }
13438: } elsif ($item eq 'approval') {
13439: unless ($value =~ /^[012]$/) {
13440: $value = 0;
13441: }
13442: } else {
13443: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
13444: $value = 'none';
13445: }
13446: }
13447: $selfenrollhash{'default'}{$type}{$item} = $value;
13448: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
13449: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
13450: if ($selfenrollhash{'default'}{$type}{$item} ne
13451: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
13452: push(@{$changes{'default'}{$type}},$item);
13453: }
13454: } else {
13455: push(@{$changes{'default'}{$type}},$item);
13456: }
13457: } else {
13458: push(@{$changes{'default'}{$type}},$item);
13459: }
13460: if ($item eq 'limit') {
13461: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
13462: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
13463: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
13464: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
13465: }
13466: } else {
13467: $selfenrollhash{'default'}{$type}{'cap'} = '';
13468: }
13469: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
13470: if ($selfenrollhash{'default'}{$type}{'cap'} ne
13471: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
13472: push(@{$changes{'default'}{$type}},'cap');
13473: }
13474: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
13475: push(@{$changes{'default'}{$type}},'cap');
13476: }
13477: }
13478: }
13479: }
13480:
13481: foreach my $item (@{$itemsref}) {
13482: if ($item eq 'fields') {
13483: my @changed;
13484: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
13485: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
13486: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
13487: }
13488: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
13489: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
13490: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
13491: $domconfig{'selfenrollment'}{'validation'}{$item});
13492: } else {
13493: @changed = @{$selfenrollhash{'validation'}{$item}};
13494: }
13495: } else {
13496: @changed = @{$selfenrollhash{'validation'}{$item}};
13497: }
13498: if (@changed) {
13499: if ($selfenrollhash{'validation'}{$item}) {
13500: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
13501: } else {
13502: $changes{'validation'}{$item} = &mt('None');
13503: }
13504: }
13505: } else {
13506: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
13507: if ($item eq 'markup') {
13508: if ($env{'form.selfenroll_validation_'.$item}) {
13509: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
13510: }
13511: }
13512: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
13513: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
13514: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
13515: }
13516: }
13517: }
13518: }
13519:
13520: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
13521: $dom);
13522: if ($putresult eq 'ok') {
13523: if (keys(%changes) > 0) {
13524: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13525: $resulttext = &mt('Changes made:').'<ul>';
13526: foreach my $key ('admin','default','validation') {
13527: if (ref($changes{$key}) eq 'HASH') {
13528: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
13529: if ($key eq 'validation') {
13530: foreach my $item (@{$itemsref}) {
13531: if (exists($changes{$key}{$item})) {
13532: if ($item eq 'markup') {
13533: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
13534: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
13535: } else {
13536: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
13537: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
13538: }
13539: }
13540: }
13541: } else {
13542: foreach my $type (@types) {
13543: if ($type eq 'community') {
13544: $roles{'1'} = &mt('Community personnel');
13545: } else {
13546: $roles{'1'} = &mt('Course personnel');
13547: }
13548: if (ref($changes{$key}{$type}) eq 'ARRAY') {
13549: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
13550: if ($key eq 'admin') {
13551: my @mgrdc = ();
13552: if (ref($ordered{$key}) eq 'ARRAY') {
13553: foreach my $item (@{$ordered{'admin'}}) {
13554: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
13555: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
13556: push(@mgrdc,$item);
13557: }
13558: }
13559: }
13560: if (@mgrdc) {
13561: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
13562: } else {
13563: delete($domdefaults{$type.'selfenrolladmdc'});
13564: }
13565: }
13566: } else {
13567: if (ref($ordered{$key}) eq 'ARRAY') {
13568: foreach my $item (@{$ordered{$key}}) {
13569: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
13570: $domdefaults{$type.'selfenroll'.$item} =
13571: $selfenrollhash{$key}{$type}{$item};
13572: }
13573: }
13574: }
13575: }
13576: }
13577: $resulttext .= '<li>'.$titles{$type}.'<ul>';
13578: foreach my $item (@{$ordered{$key}}) {
13579: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
13580: $resulttext .= '<li>';
13581: if ($key eq 'admin') {
13582: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
13583: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
13584: } else {
13585: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
13586: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
13587: }
13588: $resulttext .= '</li>';
13589: }
13590: }
13591: $resulttext .= '</ul></li>';
13592: }
13593: }
13594: $resulttext .= '</ul></li>';
13595: }
13596: }
13597: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
13598: my $cachetime = 24*60*60;
13599: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13600: if (ref($lastactref) eq 'HASH') {
13601: $lastactref->{'domdefaults'} = 1;
13602: }
13603: }
13604: }
13605: $resulttext .= '</ul>';
13606: } else {
13607: $resulttext = &mt('No changes made to self-enrollment settings');
13608: }
13609: } else {
13610: $resulttext = '<span class="LC_error">'.
13611: &mt('An error occurred: [_1]',$putresult).'</span>';
13612: }
13613: return $resulttext;
13614: }
13615:
13616: sub modify_usersessions {
13617: my ($dom,$lastactref,%domconfig) = @_;
13618: my @hostingtypes = ('version','excludedomain','includedomain');
13619: my @offloadtypes = ('primary','default');
13620: my %types = (
13621: remote => \@hostingtypes,
13622: hosted => \@hostingtypes,
13623: spares => \@offloadtypes,
13624: );
13625: my @prefixes = ('remote','hosted','spares');
13626: my @lcversions = &Apache::lonnet::all_loncaparevs();
13627: my (%by_ip,%by_location,@intdoms);
13628: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
13629: my @locations = sort(keys(%by_location));
13630: my (%defaultshash,%changes);
13631: foreach my $prefix (@prefixes) {
13632: $defaultshash{'usersessions'}{$prefix} = {};
13633: }
13634: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13635: my $resulttext;
13636: my %iphost = &Apache::lonnet::get_iphost();
13637: foreach my $prefix (@prefixes) {
13638: next if ($prefix eq 'spares');
13639: foreach my $type (@{$types{$prefix}}) {
13640: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
13641: if ($type eq 'version') {
13642: my $value = $env{'form.'.$prefix.'_'.$type};
13643: my $okvalue;
13644: if ($value ne '') {
13645: if (grep(/^\Q$value\E$/,@lcversions)) {
13646: $okvalue = $value;
13647: }
13648: }
13649: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13650: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
13651: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
13652: if ($inuse == 0) {
13653: $changes{$prefix}{$type} = 1;
13654: } else {
13655: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
13656: $changes{$prefix}{$type} = 1;
13657: }
13658: if ($okvalue ne '') {
13659: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13660: }
13661: }
13662: } else {
13663: if (($inuse == 1) && ($okvalue ne '')) {
13664: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13665: $changes{$prefix}{$type} = 1;
13666: }
13667: }
13668: } else {
13669: if (($inuse == 1) && ($okvalue ne '')) {
13670: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13671: $changes{$prefix}{$type} = 1;
13672: }
13673: }
13674: } else {
13675: if (($inuse == 1) && ($okvalue ne '')) {
13676: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13677: $changes{$prefix}{$type} = 1;
13678: }
13679: }
13680: } else {
13681: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
13682: my @okvals;
13683: foreach my $val (@vals) {
13684: if ($val =~ /:/) {
13685: my @items = split(/:/,$val);
13686: foreach my $item (@items) {
13687: if (ref($by_location{$item}) eq 'ARRAY') {
13688: push(@okvals,$item);
13689: }
13690: }
13691: } else {
13692: if (ref($by_location{$val}) eq 'ARRAY') {
13693: push(@okvals,$val);
13694: }
13695: }
13696: }
13697: @okvals = sort(@okvals);
13698: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13699: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
13700: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
13701: if ($inuse == 0) {
13702: $changes{$prefix}{$type} = 1;
13703: } else {
13704: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13705: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
13706: if (@changed > 0) {
13707: $changes{$prefix}{$type} = 1;
13708: }
13709: }
13710: } else {
13711: if ($inuse == 1) {
13712: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13713: $changes{$prefix}{$type} = 1;
13714: }
13715: }
13716: } else {
13717: if ($inuse == 1) {
13718: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13719: $changes{$prefix}{$type} = 1;
13720: }
13721: }
13722: } else {
13723: if ($inuse == 1) {
13724: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13725: $changes{$prefix}{$type} = 1;
13726: }
13727: }
13728: }
13729: }
13730: }
13731:
13732: my @alldoms = &Apache::lonnet::all_domains();
13733: my %servers = &Apache::lonnet::internet_dom_servers($dom);
13734: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
13735: my $savespares;
13736:
13737: foreach my $lonhost (sort(keys(%servers))) {
13738: my $serverhomeID =
13739: &Apache::lonnet::get_server_homeID($servers{$lonhost});
13740: my $serverhostname = &Apache::lonnet::hostname($lonhost);
13741: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
13742: my %spareschg;
13743: foreach my $type (@{$types{'spares'}}) {
13744: my @okspares;
13745: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
13746: foreach my $server (@checked) {
13747: if (&Apache::lonnet::hostname($server) ne '') {
13748: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
13749: unless (grep(/^\Q$server\E$/,@okspares)) {
13750: push(@okspares,$server);
13751: }
13752: }
13753: }
13754: }
13755: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
13756: my $newspare;
13757: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
13758: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
13759: $newspare = $new;
13760: }
13761: }
13762: my @spares;
13763: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
13764: @spares = sort(@okspares,$newspare);
13765: } else {
13766: @spares = sort(@okspares);
13767: }
13768: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
13769: if (ref($spareid{$lonhost}) eq 'HASH') {
13770: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
13771: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
13772: if (@diffs > 0) {
13773: $spareschg{$type} = 1;
13774: }
13775: }
13776: }
13777: }
13778: if (keys(%spareschg) > 0) {
13779: $changes{'spares'}{$lonhost} = \%spareschg;
13780: }
13781: }
13782: $defaultshash{'usersessions'}{'offloadnow'} = {};
13783: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
13784: my @okoffload;
13785: if (@offloadnow) {
13786: foreach my $server (@offloadnow) {
13787: if (&Apache::lonnet::hostname($server) ne '') {
13788: unless (grep(/^\Q$server\E$/,@okoffload)) {
13789: push(@okoffload,$server);
13790: }
13791: }
13792: }
13793: if (@okoffload) {
13794: foreach my $lonhost (@okoffload) {
13795: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
13796: }
13797: }
13798: }
13799: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13800: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
13801: if (ref($changes{'spares'}) eq 'HASH') {
13802: if (keys(%{$changes{'spares'}}) > 0) {
13803: $savespares = 1;
13804: }
13805: }
13806: } else {
13807: $savespares = 1;
13808: }
13809: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
13810: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
13811: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
13812: $changes{'offloadnow'} = 1;
13813: last;
13814: }
13815: }
13816: unless ($changes{'offloadnow'}) {
13817: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
13818: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
13819: $changes{'offloadnow'} = 1;
13820: last;
13821: }
13822: }
13823: }
13824: } elsif (@okoffload) {
13825: $changes{'offloadnow'} = 1;
13826: }
13827: } elsif (@okoffload) {
13828: $changes{'offloadnow'} = 1;
13829: }
13830: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
13831: if ((keys(%changes) > 0) || ($savespares)) {
13832: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13833: $dom);
13834: if ($putresult eq 'ok') {
13835: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
13836: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
13837: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
13838: }
13839: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
13840: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
13841: }
13842: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
13843: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
13844: }
13845: }
13846: my $cachetime = 24*60*60;
13847: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13848: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
13849: if (ref($lastactref) eq 'HASH') {
13850: $lastactref->{'domdefaults'} = 1;
13851: $lastactref->{'usersessions'} = 1;
13852: }
13853: if (keys(%changes) > 0) {
13854: my %lt = &usersession_titles();
13855: $resulttext = &mt('Changes made:').'<ul>';
13856: foreach my $prefix (@prefixes) {
13857: if (ref($changes{$prefix}) eq 'HASH') {
13858: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
13859: if ($prefix eq 'spares') {
13860: if (ref($changes{$prefix}) eq 'HASH') {
13861: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
13862: $resulttext .= '<li><b>'.$lonhost.'</b> ';
13863: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
13864: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
13865: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
13866: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
13867: foreach my $type (@{$types{$prefix}}) {
13868: if ($changes{$prefix}{$lonhost}{$type}) {
13869: my $offloadto = &mt('None');
13870: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
13871: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
13872: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
13873: }
13874: }
13875: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
13876: }
13877: }
13878: }
13879: $resulttext .= '</li>';
13880: }
13881: }
13882: } else {
13883: foreach my $type (@{$types{$prefix}}) {
13884: if (defined($changes{$prefix}{$type})) {
13885: my $newvalue;
13886: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
13887: if (ref($defaultshash{'usersessions'}{$prefix})) {
13888: if ($type eq 'version') {
13889: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
13890: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
13891: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
13892: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
13893: }
13894: }
13895: }
13896: }
13897: if ($newvalue eq '') {
13898: if ($type eq 'version') {
13899: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
13900: } else {
13901: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
13902: }
13903: } else {
13904: if ($type eq 'version') {
13905: $newvalue .= ' '.&mt('(or later)');
13906: }
13907: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
13908: }
13909: }
13910: }
13911: }
13912: $resulttext .= '</ul>';
13913: }
13914: }
13915: if ($changes{'offloadnow'}) {
13916: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
13917: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
13918: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
13919: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
13920: $resulttext .= '<li>'.$lonhost.'</li>';
13921: }
13922: $resulttext .= '</ul>';
13923: } else {
13924: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
13925: }
13926: } else {
13927: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
13928: }
13929: }
13930: $resulttext .= '</ul>';
13931: } else {
13932: $resulttext = $nochgmsg;
13933: }
13934: } else {
13935: $resulttext = '<span class="LC_error">'.
13936: &mt('An error occurred: [_1]',$putresult).'</span>';
13937: }
13938: } else {
13939: $resulttext = $nochgmsg;
13940: }
13941: return $resulttext;
13942: }
13943:
13944: sub modify_loadbalancing {
13945: my ($dom,%domconfig) = @_;
13946: my $primary_id = &Apache::lonnet::domain($dom,'primary');
13947: my $intdom = &Apache::lonnet::internet_dom($primary_id);
13948: my ($othertitle,$usertypes,$types) =
13949: &Apache::loncommon::sorted_inst_types($dom);
13950: my %servers = &Apache::lonnet::internet_dom_servers($dom);
13951: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
13952: my @sparestypes = ('primary','default');
13953: my %typetitles = &sparestype_titles();
13954: my $resulttext;
13955: my (%currbalancer,%currtargets,%currrules,%existing);
13956: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
13957: %existing = %{$domconfig{'loadbalancing'}};
13958: }
13959: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
13960: \%currtargets,\%currrules);
13961: my ($saveloadbalancing,%defaultshash,%changes);
13962: my ($alltypes,$othertypes,$titles) =
13963: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
13964: my %ruletitles = &offloadtype_text();
13965: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
13966: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
13967: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
13968: if ($balancer eq '') {
13969: next;
13970: }
13971: if (!exists($servers{$balancer})) {
13972: if (exists($currbalancer{$balancer})) {
13973: push(@{$changes{'delete'}},$balancer);
13974: }
13975: next;
13976: }
13977: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
13978: push(@{$changes{'delete'}},$balancer);
13979: next;
13980: }
13981: if (!exists($currbalancer{$balancer})) {
13982: push(@{$changes{'add'}},$balancer);
13983: }
13984: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
13985: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
13986: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
13987: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
13988: $saveloadbalancing = 1;
13989: }
13990: foreach my $sparetype (@sparestypes) {
13991: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
13992: my @offloadto;
13993: foreach my $target (@targets) {
13994: if (($servers{$target}) && ($target ne $balancer)) {
13995: if ($sparetype eq 'default') {
13996: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
13997: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
13998: }
13999: }
14000: unless(grep(/^\Q$target\E$/,@offloadto)) {
14001: push(@offloadto,$target);
14002: }
14003: }
14004: }
14005: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
14006: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
14007: push(@offloadto,$balancer);
14008: }
14009: }
14010: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
14011: }
14012: if (ref($currtargets{$balancer}) eq 'HASH') {
14013: foreach my $sparetype (@sparestypes) {
14014: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
14015: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
14016: if (@targetdiffs > 0) {
14017: $changes{'curr'}{$balancer}{'targets'} = 1;
14018: }
14019: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14020: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14021: $changes{'curr'}{$balancer}{'targets'} = 1;
14022: }
14023: }
14024: }
14025: } else {
14026: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
14027: foreach my $sparetype (@sparestypes) {
14028: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14029: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14030: $changes{'curr'}{$balancer}{'targets'} = 1;
14031: }
14032: }
14033: }
14034: }
14035: }
14036: my $ishomedom;
14037: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
14038: $ishomedom = 1;
14039: }
14040: if (ref($alltypes) eq 'ARRAY') {
14041: foreach my $type (@{$alltypes}) {
14042: my $rule;
14043: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
14044: (!$ishomedom)) {
14045: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
14046: }
14047: if ($rule eq 'specific') {
14048: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
14049: if (exists($servers{$specifiedhost})) {
14050: $rule = $specifiedhost;
14051: }
14052: }
14053: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
14054: if (ref($currrules{$balancer}) eq 'HASH') {
14055: if ($rule ne $currrules{$balancer}{$type}) {
14056: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
14057: }
14058: } elsif ($rule ne '') {
14059: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
14060: }
14061: }
14062: }
14063: }
14064: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
14065: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
14066: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
14067: $defaultshash{'loadbalancing'} = {};
14068: }
14069: my $putresult = &Apache::lonnet::put_dom('configuration',
14070: \%defaultshash,$dom);
14071: if ($putresult eq 'ok') {
14072: if (keys(%changes) > 0) {
14073: my %toupdate;
14074: if (ref($changes{'delete'}) eq 'ARRAY') {
14075: foreach my $balancer (sort(@{$changes{'delete'}})) {
14076: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
14077: $toupdate{$balancer} = 1;
14078: }
14079: }
14080: if (ref($changes{'add'}) eq 'ARRAY') {
14081: foreach my $balancer (sort(@{$changes{'add'}})) {
14082: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
14083: $toupdate{$balancer} = 1;
14084: }
14085: }
14086: if (ref($changes{'curr'}) eq 'HASH') {
14087: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
14088: $toupdate{$balancer} = 1;
14089: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
14090: if ($changes{'curr'}{$balancer}{'targets'}) {
14091: my %offloadstr;
14092: foreach my $sparetype (@sparestypes) {
14093: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14094: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14095: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
14096: }
14097: }
14098: }
14099: if (keys(%offloadstr) == 0) {
14100: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
14101: } else {
14102: my $showoffload;
14103: foreach my $sparetype (@sparestypes) {
14104: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
14105: if (defined($offloadstr{$sparetype})) {
14106: $showoffload .= $offloadstr{$sparetype};
14107: } else {
14108: $showoffload .= &mt('None');
14109: }
14110: $showoffload .= (' 'x3);
14111: }
14112: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
14113: }
14114: }
14115: }
14116: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
14117: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
14118: foreach my $type (@{$alltypes}) {
14119: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
14120: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
14121: my $balancetext;
14122: if ($rule eq '') {
14123: $balancetext = $ruletitles{'default'};
14124: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
14125: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
14126: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
14127: foreach my $sparetype (@sparestypes) {
14128: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14129: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
14130: }
14131: }
14132: foreach my $item (@{$alltypes}) {
14133: next if ($item =~ /^_LC_ipchange/);
14134: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
14135: if ($hasrule eq 'homeserver') {
14136: map { $toupdate{$_} = 1; } (keys(%libraryservers));
14137: } else {
14138: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
14139: if ($servers{$hasrule}) {
14140: $toupdate{$hasrule} = 1;
14141: }
14142: }
14143: }
14144: }
14145: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
14146: $balancetext = $ruletitles{$rule};
14147: } else {
14148: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
14149: $balancetext = $ruletitles{'particular'}.' '.$receiver;
14150: if ($receiver) {
14151: $toupdate{$receiver};
14152: }
14153: }
14154: } else {
14155: $balancetext = $ruletitles{$rule};
14156: }
14157: } else {
14158: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
14159: }
14160: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
14161: }
14162: }
14163: }
14164: }
14165: if (keys(%toupdate)) {
14166: my %thismachine;
14167: my $updatedhere;
14168: my $cachetime = 60*60*24;
14169: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
14170: foreach my $lonhost (keys(%toupdate)) {
14171: if ($thismachine{$lonhost}) {
14172: unless ($updatedhere) {
14173: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
14174: $defaultshash{'loadbalancing'},
14175: $cachetime);
14176: $updatedhere = 1;
14177: }
14178: } else {
14179: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
14180: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
14181: }
14182: }
14183: }
14184: }
14185: }
14186: if ($resulttext ne '') {
14187: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
14188: } else {
14189: $resulttext = $nochgmsg;
14190: }
14191: } else {
14192: $resulttext = $nochgmsg;
14193: }
14194: } else {
14195: $resulttext = '<span class="LC_error">'.
14196: &mt('An error occurred: [_1]',$putresult).'</span>';
14197: }
14198: } else {
14199: $resulttext = $nochgmsg;
14200: }
14201: return $resulttext;
14202: }
14203:
14204: sub recurse_check {
14205: my ($chkcats,$categories,$depth,$name) = @_;
14206: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
14207: my $chg = 0;
14208: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
14209: my $category = $chkcats->[$depth]{$name}[$j];
14210: my $item;
14211: if ($category eq '') {
14212: $chg ++;
14213: } else {
14214: my $deeper = $depth + 1;
14215: $item = &escape($category).':'.&escape($name).':'.$depth;
14216: if ($chg) {
14217: $categories->{$item} -= $chg;
14218: }
14219: &recurse_check($chkcats,$categories,$deeper,$category);
14220: $deeper --;
14221: }
14222: }
14223: }
14224: return;
14225: }
14226:
14227: sub recurse_cat_deletes {
14228: my ($item,$coursecategories,$deletions) = @_;
14229: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14230: my $subdepth = $depth + 1;
14231: if (ref($coursecategories) eq 'HASH') {
14232: foreach my $subitem (keys(%{$coursecategories})) {
14233: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
14234: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
14235: delete($coursecategories->{$subitem});
14236: $deletions->{$subitem} = 1;
14237: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
14238: }
14239: }
14240: }
14241: return;
14242: }
14243:
14244: sub active_dc_picker {
14245: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
14246: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
14247: my @domcoord = keys(%domcoords);
14248: if (keys(%currhash)) {
14249: foreach my $dc (keys(%currhash)) {
14250: unless (exists($domcoords{$dc})) {
14251: push(@domcoord,$dc);
14252: }
14253: }
14254: }
14255: @domcoord = sort(@domcoord);
14256: my $numdcs = scalar(@domcoord);
14257: my $rows = 0;
14258: my $table;
14259: if ($numdcs > 1) {
14260: $table = '<table>';
14261: for (my $i=0; $i<@domcoord; $i++) {
14262: my $rem = $i%($numinrow);
14263: if ($rem == 0) {
14264: if ($i > 0) {
14265: $table .= '</tr>';
14266: }
14267: $table .= '<tr>';
14268: $rows ++;
14269: }
14270: my $check = '';
14271: if ($inputtype eq 'radio') {
14272: if (keys(%currhash) == 0) {
14273: if (!$i) {
14274: $check = ' checked="checked"';
14275: }
14276: } elsif (exists($currhash{$domcoord[$i]})) {
14277: $check = ' checked="checked"';
14278: }
14279: } else {
14280: if (exists($currhash{$domcoord[$i]})) {
14281: $check = ' checked="checked"';
14282: }
14283: }
14284: if ($i == @domcoord - 1) {
14285: my $colsleft = $numinrow - $rem;
14286: if ($colsleft > 1) {
14287: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
14288: } else {
14289: $table .= '<td class="LC_left_item">';
14290: }
14291: } else {
14292: $table .= '<td class="LC_left_item">';
14293: }
14294: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
14295: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
14296: $table .= '<span class="LC_nobreak"><label>'.
14297: '<input type="'.$inputtype.'" name="'.$name.'"'.
14298: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
14299: if ($user ne $dcname.':'.$dcdom) {
14300: $table .= ' ('.$dcname.':'.$dcdom.')';
14301: }
14302: $table .= '</label></span></td>';
14303: }
14304: $table .= '</tr></table>';
14305: } elsif ($numdcs == 1) {
14306: my ($dcname,$dcdom) = split(':',$domcoord[0]);
14307: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
14308: if ($inputtype eq 'radio') {
14309: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
14310: if ($user ne $dcname.':'.$dcdom) {
14311: $table .= ' ('.$dcname.':'.$dcdom.')';
14312: }
14313: } else {
14314: my $check;
14315: if (exists($currhash{$domcoord[0]})) {
14316: $check = ' checked="checked"';
14317: }
14318: $table = '<span class="LC_nobreak"><label>'.
14319: '<input type="checkbox" name="'.$name.'" '.
14320: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
14321: if ($user ne $dcname.':'.$dcdom) {
14322: $table .= ' ('.$dcname.':'.$dcdom.')';
14323: }
14324: $table .= '</label></span>';
14325: $rows ++;
14326: }
14327: }
14328: return ($numdcs,$table,$rows);
14329: }
14330:
14331: sub usersession_titles {
14332: return &Apache::lonlocal::texthash(
14333: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
14334: remote => 'Hosting of sessions for users in this domain on servers in other domains',
14335: spares => 'Servers offloaded to, when busy',
14336: version => 'LON-CAPA version requirement',
14337: excludedomain => 'Allow all, but exclude specific domains',
14338: includedomain => 'Deny all, but include specific domains',
14339: primary => 'Primary (checked first)',
14340: default => 'Default',
14341: );
14342: }
14343:
14344: sub id_for_thisdom {
14345: my (%servers) = @_;
14346: my %altids;
14347: foreach my $server (keys(%servers)) {
14348: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
14349: if ($serverhome ne $server) {
14350: $altids{$serverhome} = $server;
14351: }
14352: }
14353: return %altids;
14354: }
14355:
14356: sub count_servers {
14357: my ($currbalancer,%servers) = @_;
14358: my (@spares,$numspares);
14359: foreach my $lonhost (sort(keys(%servers))) {
14360: next if ($currbalancer eq $lonhost);
14361: push(@spares,$lonhost);
14362: }
14363: if ($currbalancer) {
14364: $numspares = scalar(@spares);
14365: } else {
14366: $numspares = scalar(@spares) - 1;
14367: }
14368: return ($numspares,@spares);
14369: }
14370:
14371: sub lonbalance_targets_js {
14372: my ($dom,$types,$servers,$settings) = @_;
14373: my $select = &mt('Select');
14374: my ($alltargets,$allishome,$allinsttypes,@alltypes);
14375: if (ref($servers) eq 'HASH') {
14376: $alltargets = join("','",sort(keys(%{$servers})));
14377: my @homedoms;
14378: foreach my $server (sort(keys(%{$servers}))) {
14379: if (&Apache::lonnet::host_domain($server) eq $dom) {
14380: push(@homedoms,'1');
14381: } else {
14382: push(@homedoms,'0');
14383: }
14384: }
14385: $allishome = join("','",@homedoms);
14386: }
14387: if (ref($types) eq 'ARRAY') {
14388: if (@{$types} > 0) {
14389: @alltypes = @{$types};
14390: }
14391: }
14392: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
14393: $allinsttypes = join("','",@alltypes);
14394: my (%currbalancer,%currtargets,%currrules,%existing);
14395: if (ref($settings) eq 'HASH') {
14396: %existing = %{$settings};
14397: }
14398: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
14399: \%currtargets,\%currrules);
14400: my $balancers = join("','",sort(keys(%currbalancer)));
14401: return <<"END";
14402:
14403: <script type="text/javascript">
14404: // <![CDATA[
14405:
14406: currBalancers = new Array('$balancers');
14407:
14408: function toggleTargets(balnum) {
14409: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
14410: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
14411: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
14412: var prevbalancer = prevhostitem.value;
14413: var baltotal = document.getElementById('loadbalancing_total').value;
14414: prevhostitem.value = balancer;
14415: if (prevbalancer != '') {
14416: var prevIdx = currBalancers.indexOf(prevbalancer);
14417: if (prevIdx != -1) {
14418: currBalancers.splice(prevIdx,1);
14419: }
14420: }
14421: if (balancer == '') {
14422: hideSpares(balnum);
14423: } else {
14424: var currIdx = currBalancers.indexOf(balancer);
14425: if (currIdx == -1) {
14426: currBalancers.push(balancer);
14427: }
14428: var homedoms = new Array('$allishome');
14429: var ishomedom = homedoms[lonhostitem.selectedIndex];
14430: showSpares(balancer,ishomedom,balnum);
14431: }
14432: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
14433: return;
14434: }
14435:
14436: function showSpares(balancer,ishomedom,balnum) {
14437: var alltargets = new Array('$alltargets');
14438: var insttypes = new Array('$allinsttypes');
14439: var offloadtypes = new Array('primary','default');
14440:
14441: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
14442: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
14443:
14444: for (var i=0; i<offloadtypes.length; i++) {
14445: var count = 0;
14446: for (var j=0; j<alltargets.length; j++) {
14447: if (alltargets[j] != balancer) {
14448: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
14449: item.value = alltargets[j];
14450: item.style.textAlign='left';
14451: item.style.textFace='normal';
14452: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
14453: if (currBalancers.indexOf(alltargets[j]) == -1) {
14454: item.disabled = '';
14455: } else {
14456: item.disabled = 'disabled';
14457: item.checked = false;
14458: }
14459: count ++;
14460: }
14461: }
14462: }
14463: for (var k=0; k<insttypes.length; k++) {
14464: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
14465: if (ishomedom == 1) {
14466: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
14467: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
14468: } else {
14469: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
14470: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
14471: }
14472: } else {
14473: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
14474: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
14475: }
14476: if ((insttypes[k] != '_LC_external') &&
14477: ((insttypes[k] != '_LC_internetdom') ||
14478: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
14479: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
14480: item.options.length = 0;
14481: item.options[0] = new Option("","",true,true);
14482: var idx = 0;
14483: for (var m=0; m<alltargets.length; m++) {
14484: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
14485: idx ++;
14486: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
14487: }
14488: }
14489: }
14490: }
14491: return;
14492: }
14493:
14494: function hideSpares(balnum) {
14495: var alltargets = new Array('$alltargets');
14496: var insttypes = new Array('$allinsttypes');
14497: var offloadtypes = new Array('primary','default');
14498:
14499: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
14500: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
14501:
14502: var total = alltargets.length - 1;
14503: for (var i=0; i<offloadtypes; i++) {
14504: for (var j=0; j<total; j++) {
14505: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
14506: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
14507: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
14508: }
14509: }
14510: for (var k=0; k<insttypes.length; k++) {
14511: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
14512: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
14513: if (insttypes[k] != '_LC_external') {
14514: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
14515: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
14516: }
14517: }
14518: return;
14519: }
14520:
14521: function checkOffloads(item,balnum,type) {
14522: var alltargets = new Array('$alltargets');
14523: var offloadtypes = new Array('primary','default');
14524: if (item.checked) {
14525: var total = alltargets.length - 1;
14526: var other;
14527: if (type == offloadtypes[0]) {
14528: other = offloadtypes[1];
14529: } else {
14530: other = offloadtypes[0];
14531: }
14532: for (var i=0; i<total; i++) {
14533: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
14534: if (server == item.value) {
14535: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
14536: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
14537: }
14538: }
14539: }
14540: }
14541: return;
14542: }
14543:
14544: function singleServerToggle(balnum,type) {
14545: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
14546: if (offloadtoSelIdx == 0) {
14547: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
14548: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
14549:
14550: } else {
14551: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
14552: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
14553: }
14554: return;
14555: }
14556:
14557: function balanceruleChange(formname,balnum,type) {
14558: if (type == '_LC_external') {
14559: return;
14560: }
14561: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
14562: for (var i=0; i<typesRules.length; i++) {
14563: if (formname.elements[typesRules[i]].checked) {
14564: if (formname.elements[typesRules[i]].value != 'specific') {
14565: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
14566: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
14567: } else {
14568: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
14569: }
14570: }
14571: }
14572: return;
14573: }
14574:
14575: function balancerDeleteChange(balnum) {
14576: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
14577: var baltotal = document.getElementById('loadbalancing_total').value;
14578: var addtarget;
14579: var removetarget;
14580: var action = 'delete';
14581: if (document.getElementById('loadbalancing_delete_'+balnum)) {
14582: var lonhost = hostitem.value;
14583: var currIdx = currBalancers.indexOf(lonhost);
14584: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
14585: if (currIdx != -1) {
14586: currBalancers.splice(currIdx,1);
14587: }
14588: addtarget = lonhost;
14589: } else {
14590: if (currIdx == -1) {
14591: currBalancers.push(lonhost);
14592: }
14593: removetarget = lonhost;
14594: action = 'undelete';
14595: }
14596: balancerChange(balnum,baltotal,action,addtarget,removetarget);
14597: }
14598: return;
14599: }
14600:
14601: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
14602: if (baltotal > 1) {
14603: var offloadtypes = new Array('primary','default');
14604: var alltargets = new Array('$alltargets');
14605: var insttypes = new Array('$allinsttypes');
14606: for (var i=0; i<baltotal; i++) {
14607: if (i != balnum) {
14608: for (var j=0; j<offloadtypes.length; j++) {
14609: var total = alltargets.length - 1;
14610: for (var k=0; k<total; k++) {
14611: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
14612: var server = serveritem.value;
14613: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
14614: if (server == addtarget) {
14615: serveritem.disabled = '';
14616: }
14617: }
14618: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
14619: if (server == removetarget) {
14620: serveritem.disabled = 'disabled';
14621: serveritem.checked = false;
14622: }
14623: }
14624: }
14625: }
14626: for (var j=0; j<insttypes.length; j++) {
14627: if (insttypes[j] != '_LC_external') {
14628: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
14629: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
14630: var currSel = singleserver.selectedIndex;
14631: var currVal = singleserver.options[currSel].value;
14632: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
14633: var numoptions = singleserver.options.length;
14634: var needsnew = 1;
14635: for (var k=0; k<numoptions; k++) {
14636: if (singleserver.options[k] == addtarget) {
14637: needsnew = 0;
14638: break;
14639: }
14640: }
14641: if (needsnew == 1) {
14642: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
14643: }
14644: }
14645: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
14646: singleserver.options.length = 0;
14647: if ((currVal) && (currVal != removetarget)) {
14648: singleserver.options[0] = new Option("","",false,false);
14649: } else {
14650: singleserver.options[0] = new Option("","",true,true);
14651: }
14652: var idx = 0;
14653: for (var m=0; m<alltargets.length; m++) {
14654: if (currBalancers.indexOf(alltargets[m]) == -1) {
14655: idx ++;
14656: if (currVal == alltargets[m]) {
14657: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
14658: } else {
14659: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
14660: }
14661: }
14662: }
14663: }
14664: }
14665: }
14666: }
14667: }
14668: }
14669: }
14670: return;
14671: }
14672:
14673: // ]]>
14674: </script>
14675:
14676: END
14677: }
14678:
14679: sub new_spares_js {
14680: my @sparestypes = ('primary','default');
14681: my $types = join("','",@sparestypes);
14682: my $select = &mt('Select');
14683: return <<"END";
14684:
14685: <script type="text/javascript">
14686: // <![CDATA[
14687:
14688: function updateNewSpares(formname,lonhost) {
14689: var types = new Array('$types');
14690: var include = new Array();
14691: var exclude = new Array();
14692: for (var i=0; i<types.length; i++) {
14693: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
14694: for (var j=0; j<spareboxes.length; j++) {
14695: if (formname.elements[spareboxes[j]].checked) {
14696: exclude.push(formname.elements[spareboxes[j]].value);
14697: } else {
14698: include.push(formname.elements[spareboxes[j]].value);
14699: }
14700: }
14701: }
14702: for (var i=0; i<types.length; i++) {
14703: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
14704: var selIdx = newSpare.selectedIndex;
14705: var currnew = newSpare.options[selIdx].value;
14706: var okSpares = new Array();
14707: for (var j=0; j<newSpare.options.length; j++) {
14708: var possible = newSpare.options[j].value;
14709: if (possible != '') {
14710: if (exclude.indexOf(possible) == -1) {
14711: okSpares.push(possible);
14712: } else {
14713: if (currnew == possible) {
14714: selIdx = 0;
14715: }
14716: }
14717: }
14718: }
14719: for (var k=0; k<include.length; k++) {
14720: if (okSpares.indexOf(include[k]) == -1) {
14721: okSpares.push(include[k]);
14722: }
14723: }
14724: okSpares.sort();
14725: newSpare.options.length = 0;
14726: if (selIdx == 0) {
14727: newSpare.options[0] = new Option("$select","",true,true);
14728: } else {
14729: newSpare.options[0] = new Option("$select","",false,false);
14730: }
14731: for (var m=0; m<okSpares.length; m++) {
14732: var idx = m+1;
14733: var selThis = 0;
14734: if (selIdx != 0) {
14735: if (okSpares[m] == currnew) {
14736: selThis = 1;
14737: }
14738: }
14739: if (selThis == 1) {
14740: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
14741: } else {
14742: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
14743: }
14744: }
14745: }
14746: return;
14747: }
14748:
14749: function checkNewSpares(lonhost,type) {
14750: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
14751: var chosen = newSpare.options[newSpare.selectedIndex].value;
14752: if (chosen != '') {
14753: var othertype;
14754: var othernewSpare;
14755: if (type == 'primary') {
14756: othernewSpare = document.getElementById('newspare_default_'+lonhost);
14757: }
14758: if (type == 'default') {
14759: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
14760: }
14761: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
14762: othernewSpare.selectedIndex = 0;
14763: }
14764: }
14765: return;
14766: }
14767:
14768: // ]]>
14769: </script>
14770:
14771: END
14772:
14773: }
14774:
14775: sub common_domprefs_js {
14776: return <<"END";
14777:
14778: <script type="text/javascript">
14779: // <![CDATA[
14780:
14781: function getIndicesByName(formname,item) {
14782: var group = new Array();
14783: for (var i=0;i<formname.elements.length;i++) {
14784: if (formname.elements[i].name == item) {
14785: group.push(formname.elements[i].id);
14786: }
14787: }
14788: return group;
14789: }
14790:
14791: // ]]>
14792: </script>
14793:
14794: END
14795:
14796: }
14797:
14798: sub recaptcha_js {
14799: my %lt = &captcha_phrases();
14800: return <<"END";
14801:
14802: <script type="text/javascript">
14803: // <![CDATA[
14804:
14805: function updateCaptcha(caller,context) {
14806: var privitem;
14807: var pubitem;
14808: var privtext;
14809: var pubtext;
14810: var versionitem;
14811: var versiontext;
14812: if (document.getElementById(context+'_recaptchapub')) {
14813: pubitem = document.getElementById(context+'_recaptchapub');
14814: } else {
14815: return;
14816: }
14817: if (document.getElementById(context+'_recaptchapriv')) {
14818: privitem = document.getElementById(context+'_recaptchapriv');
14819: } else {
14820: return;
14821: }
14822: if (document.getElementById(context+'_recaptchapubtxt')) {
14823: pubtext = document.getElementById(context+'_recaptchapubtxt');
14824: } else {
14825: return;
14826: }
14827: if (document.getElementById(context+'_recaptchaprivtxt')) {
14828: privtext = document.getElementById(context+'_recaptchaprivtxt');
14829: } else {
14830: return;
14831: }
14832: if (document.getElementById(context+'_recaptchaversion')) {
14833: versionitem = document.getElementById(context+'_recaptchaversion');
14834: } else {
14835: return;
14836: }
14837: if (document.getElementById(context+'_recaptchavertxt')) {
14838: versiontext = document.getElementById(context+'_recaptchavertxt');
14839: } else {
14840: return;
14841: }
14842: if (caller.checked) {
14843: if (caller.value == 'recaptcha') {
14844: pubitem.type = 'text';
14845: privitem.type = 'text';
14846: pubitem.size = '40';
14847: privitem.size = '40';
14848: pubtext.innerHTML = "$lt{'pub'}";
14849: privtext.innerHTML = "$lt{'priv'}";
14850: versionitem.type = 'text';
14851: versionitem.size = '3';
14852: versiontext.innerHTML = "$lt{'ver'}";
14853: } else {
14854: pubitem.type = 'hidden';
14855: privitem.type = 'hidden';
14856: versionitem.type = 'hidden';
14857: pubtext.innerHTML = '';
14858: privtext.innerHTML = '';
14859: versiontext.innerHTML = '';
14860: }
14861: }
14862: return;
14863: }
14864:
14865: // ]]>
14866: </script>
14867:
14868: END
14869:
14870: }
14871:
14872: sub toggle_display_js {
14873: return <<"END";
14874:
14875: <script type="text/javascript">
14876: // <![CDATA[
14877:
14878: function toggleDisplay(domForm,caller) {
14879: if (document.getElementById(caller)) {
14880: var divitem = document.getElementById(caller);
14881: var optionsElement = domForm.coursecredits;
14882: var checkval = 1;
14883: var dispval = 'block';
14884: if (caller == 'emailoptions') {
14885: optionsElement = domForm.cancreate_email;
14886: }
14887: if (caller == 'studentsubmission') {
14888: optionsElement = domForm.postsubmit;
14889: }
14890: if (caller == 'cloneinstcode') {
14891: optionsElement = domForm.canclone;
14892: checkval = 'instcode';
14893: }
14894: if (optionsElement.length) {
14895: var currval;
14896: for (var i=0; i<optionsElement.length; i++) {
14897: if (optionsElement[i].checked) {
14898: currval = optionsElement[i].value;
14899: }
14900: }
14901: if (currval == checkval) {
14902: divitem.style.display = dispval;
14903: } else {
14904: divitem.style.display = 'none';
14905: }
14906: }
14907: }
14908: return;
14909: }
14910:
14911: // ]]>
14912: </script>
14913:
14914: END
14915:
14916: }
14917:
14918: sub captcha_phrases {
14919: return &Apache::lonlocal::texthash (
14920: priv => 'Private key',
14921: pub => 'Public key',
14922: original => 'original (CAPTCHA)',
14923: recaptcha => 'successor (ReCAPTCHA)',
14924: notused => 'unused',
14925: ver => 'ReCAPTCHA version (1 or 2)',
14926: );
14927: }
14928:
14929: sub devalidate_remote_domconfs {
14930: my ($dom,$cachekeys) = @_;
14931: return unless (ref($cachekeys) eq 'HASH');
14932: my %servers = &Apache::lonnet::internet_dom_servers($dom);
14933: my %thismachine;
14934: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
14935: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions','directorysrch');
14936: if (keys(%servers)) {
14937: foreach my $server (keys(%servers)) {
14938: next if ($thismachine{$server});
14939: my @cached;
14940: foreach my $name (@posscached) {
14941: if ($cachekeys->{$name}) {
14942: push(@cached,&escape($name).':'.&escape($dom));
14943: }
14944: }
14945: if (@cached) {
14946: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
14947: }
14948: }
14949: }
14950: return;
14951: }
14952:
14953: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>