Annotation of loncom/interface/domainprefs.pm, revision 1.343
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.343 ! raeburn 4: # $Id: domainprefs.pm,v 1.342 2018/11/24 16:48:01 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
1.286 raeburn 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
1.1 raeburn 24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
1.297 raeburn 30: ###############################################################
1.1 raeburn 31:
1.101 raeburn 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
1.183 bisitz 49: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 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
1.210 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.163 raeburn 91: requestcourses or requestauthor).
1.101 raeburn 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,
1.197 raeburn 98: used by course owners to request creation of a course, and to display/store
1.223 bisitz 99: default quota sizes for Authoring Spaces.
1.101 raeburn 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
1.325 raeburn 107: (official, unofficial, community, textbook, placement, and lti).
1.271 raeburn 108: In each case the radio buttons allow the selection of one of four values:
1.101 raeburn 109:
1.104 raeburn 110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 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:
1.104 raeburn 121: approval
1.101 raeburn 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:
1.143 raeburn 145: - course requests will be processed automatically up to a limit of
1.101 raeburn 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:
1.1 raeburn 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;
1.43 raeburn 166: use Apache::lonmsg();
1.91 raeburn 167: use Apache::lonconfigsettings;
1.232 raeburn 168: use Apache::lonuserutils();
1.235 raeburn 169: use Apache::loncoursequeueadmin();
1.69 raeburn 170: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 171: use LONCAPA::Enrollment;
1.81 raeburn 172: use LONCAPA::lonauthcgi();
1.275 raeburn 173: use LONCAPA::SSL;
1.9 raeburn 174: use File::Copy;
1.43 raeburn 175: use Locale::Language;
1.62 raeburn 176: use DateTime::TimeZone;
1.68 raeburn 177: use DateTime::Locale;
1.267 raeburn 178: use Time::HiRes qw( sleep );
1.1 raeburn 179:
1.155 raeburn 180: my $registered_cleanup;
181: my $modified_urls;
182:
1.1 raeburn 183: sub handler {
184: my $r=shift;
185: if ($r->header_only) {
186: &Apache::loncommon::content_type($r,'text/html');
187: $r->send_http_header;
188: return OK;
189: }
190:
1.91 raeburn 191: my $context = 'domain';
1.1 raeburn 192: my $dom = $env{'request.role.domain'};
1.5 albertel 193: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 194: if (&Apache::lonnet::allowed('mau',$dom)) {
195: &Apache::loncommon::content_type($r,'text/html');
196: $r->send_http_header;
197: } else {
198: $env{'user.error.msg'}=
199: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
200: return HTTP_NOT_ACCEPTABLE;
201: }
1.155 raeburn 202:
203: $registered_cleanup=0;
204: @{$modified_urls}=();
205:
1.1 raeburn 206: &Apache::lonhtmlcommon::clear_breadcrumbs();
207: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 208: ['phase','actions']);
1.30 raeburn 209: my $phase = 'pickactions';
1.3 raeburn 210: if ( exists($env{'form.phase'}) ) {
211: $phase = $env{'form.phase'};
212: }
1.150 raeburn 213: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 214: my %domconfig =
1.6 raeburn 215: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 216: 'quotas','autoenroll','autoupdate','autocreate',
217: 'directorysrch','usercreation','usermodification',
218: 'contacts','defaults','scantron','coursecategories',
219: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 220: 'coursedefaults','usersessions','loadbalancing',
1.267 raeburn 221: 'requestauthor','selfenrollment','inststatus',
1.320 raeburn 222: 'ltitools','ssl','trust','lti'],$dom);
223: my %encconfig =
224: &Apache::lonnet::get_dom('encconfig',['ltitools','lti'],$dom);
1.297 raeburn 225: if (ref($domconfig{'ltitools'}) eq 'HASH') {
226: if (ref($encconfig{'ltitools'}) eq 'HASH') {
227: foreach my $id (keys(%{$domconfig{'ltitools'}})) {
1.320 raeburn 228: if ((ref($domconfig{'ltitools'}{$id}) eq 'HASH') &&
229: (ref($encconfig{'ltitools'}{$id}) eq 'HASH')) {
1.297 raeburn 230: foreach my $item ('key','secret') {
231: $domconfig{'ltitools'}{$id}{$item} = $encconfig{'ltitools'}{$id}{$item};
232: }
233: }
234: }
235: }
236: }
1.320 raeburn 237: if (ref($domconfig{'lti'}) eq 'HASH') {
238: if (ref($encconfig{'lti'}) eq 'HASH') {
239: foreach my $id (keys(%{$domconfig{'lti'}})) {
240: if ((ref($domconfig{'lti'}{$id}) eq 'HASH') &&
241: (ref($encconfig{'lti'}{$id}) eq 'HASH')) {
242: foreach my $item ('key','secret') {
243: $domconfig{'lti'}{$id}{$item} = $encconfig{'lti'}{$id}{$item};
244: }
245: }
246: }
247: }
248: }
1.43 raeburn 249: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 250: 'autoupdate','autocreate','directorysrch','contacts',
1.224 raeburn 251: 'usercreation','selfcreation','usermodification','scantron',
1.163 raeburn 252: 'requestcourses','requestauthor','coursecategories',
1.267 raeburn 253: 'serverstatuses','helpsettings','coursedefaults',
1.320 raeburn 254: 'ltitools','selfenrollment','usersessions','ssl','trust','lti');
1.171 raeburn 255: my %existing;
256: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
257: %existing = %{$domconfig{'loadbalancing'}};
258: }
259: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 260: push(@prefs_order,'loadbalancing');
261: }
1.30 raeburn 262: my %prefs = (
263: 'rolecolors' =>
264: { text => 'Default color schemes',
1.67 raeburn 265: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 266: header => [{col1 => 'Student Settings',
267: col2 => '',},
268: {col1 => 'Coordinator Settings',
269: col2 => '',},
270: {col1 => 'Author Settings',
271: col2 => '',},
272: {col1 => 'Administrator Settings',
273: col2 => '',}],
1.230 raeburn 274: print => \&print_rolecolors,
275: modify => \&modify_rolecolors,
1.30 raeburn 276: },
1.110 raeburn 277: 'login' =>
1.30 raeburn 278: { text => 'Log-in page options',
1.67 raeburn 279: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 280: header => [{col1 => 'Log-in Page Items',
281: col2 => '',},
282: {col1 => 'Log-in Help',
1.256 raeburn 283: col2 => 'Value'},
284: {col1 => 'Custom HTML in document head',
1.168 raeburn 285: col2 => 'Value'}],
1.230 raeburn 286: print => \&print_login,
287: modify => \&modify_login,
1.30 raeburn 288: },
1.43 raeburn 289: 'defaults' =>
1.236 raeburn 290: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 291: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 292: header => [{col1 => 'Setting',
1.236 raeburn 293: col2 => 'Value'},
1.294 raeburn 294: {col1 => 'Internal Authentication',
295: col2 => 'Value'},
1.236 raeburn 296: {col1 => 'Institutional user types',
1.305 raeburn 297: col2 => 'Name displayed'}],
1.230 raeburn 298: print => \&print_defaults,
299: modify => \&modify_defaults,
1.43 raeburn 300: },
1.30 raeburn 301: 'quotas' =>
1.197 raeburn 302: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 303: help => 'Domain_Configuration_Quotas',
1.77 raeburn 304: header => [{col1 => 'User affiliation',
1.72 raeburn 305: col2 => 'Available tools',
1.213 raeburn 306: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230 raeburn 307: print => \&print_quotas,
308: modify => \&modify_quotas,
1.30 raeburn 309: },
310: 'autoenroll' =>
311: { text => 'Auto-enrollment settings',
1.67 raeburn 312: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 313: header => [{col1 => 'Configuration setting',
314: col2 => 'Value(s)'}],
1.230 raeburn 315: print => \&print_autoenroll,
316: modify => \&modify_autoenroll,
1.30 raeburn 317: },
318: 'autoupdate' =>
319: { text => 'Auto-update settings',
1.67 raeburn 320: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 321: header => [{col1 => 'Setting',
322: col2 => 'Value',},
1.131 raeburn 323: {col1 => 'Setting',
324: col2 => 'Affiliation'},
1.43 raeburn 325: {col1 => 'User population',
1.227 bisitz 326: col2 => 'Updatable user data'}],
1.230 raeburn 327: print => \&print_autoupdate,
328: modify => \&modify_autoupdate,
1.30 raeburn 329: },
1.125 raeburn 330: 'autocreate' =>
331: { text => 'Auto-course creation settings',
332: help => 'Domain_Configuration_Auto_Creation',
333: header => [{col1 => 'Configuration Setting',
334: col2 => 'Value',}],
1.230 raeburn 335: print => \&print_autocreate,
336: modify => \&modify_autocreate,
1.125 raeburn 337: },
1.30 raeburn 338: 'directorysrch' =>
1.277 raeburn 339: { text => 'Directory searches',
1.67 raeburn 340: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 341: header => [{col1 => 'Institutional Directory Setting',
342: col2 => 'Value',},
343: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 344: col2 => 'Value',}],
1.230 raeburn 345: print => \&print_directorysrch,
346: modify => \&modify_directorysrch,
1.30 raeburn 347: },
348: 'contacts' =>
1.286 raeburn 349: { text => 'E-mail addresses and helpform',
1.67 raeburn 350: help => 'Domain_Configuration_Contact_Info',
1.286 raeburn 351: header => [{col1 => 'Default e-mail addresses',
352: col2 => 'Value',},
353: {col1 => 'Recipient(s) for notifications',
354: col2 => 'Value',},
1.340 raeburn 355: {col1 => 'Nightly status check e-mail',
356: col2 => 'Settings',},
1.286 raeburn 357: {col1 => 'Ask helpdesk form settings',
358: col2 => 'Value',},],
1.230 raeburn 359: print => \&print_contacts,
360: modify => \&modify_contacts,
1.30 raeburn 361: },
362: 'usercreation' =>
363: { text => 'User creation',
1.67 raeburn 364: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 365: header => [{col1 => 'Format rule type',
366: col2 => 'Format rules in force'},
1.34 raeburn 367: {col1 => 'User account creation',
368: col2 => 'Usernames which may be created',},
1.30 raeburn 369: {col1 => 'Context',
1.43 raeburn 370: col2 => 'Assignable authentication types'}],
1.230 raeburn 371: print => \&print_usercreation,
372: modify => \&modify_usercreation,
1.30 raeburn 373: },
1.224 raeburn 374: 'selfcreation' =>
375: { text => 'Users self-creating accounts',
376: help => 'Domain_Configuration_Self_Creation',
377: header => [{col1 => 'Self-creation with institutional username',
378: col2 => 'Enabled?'},
379: {col1 => 'Institutional user type (login/SSO self-creation)',
380: col2 => 'Information user can enter'},
1.303 raeburn 381: {col1 => 'Self-creation with e-mail verification',
1.224 raeburn 382: col2 => 'Settings'}],
1.230 raeburn 383: print => \&print_selfcreation,
384: modify => \&modify_selfcreation,
1.224 raeburn 385: },
1.69 raeburn 386: 'usermodification' =>
1.33 raeburn 387: { text => 'User modification',
1.67 raeburn 388: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 389: header => [{col1 => 'Target user has role',
1.227 bisitz 390: col2 => 'User information updatable in author context'},
1.33 raeburn 391: {col1 => 'Target user has role',
1.227 bisitz 392: col2 => 'User information updatable in course context'}],
1.230 raeburn 393: print => \&print_usermodification,
394: modify => \&modify_usermodification,
1.33 raeburn 395: },
1.69 raeburn 396: 'scantron' =>
1.95 www 397: { text => 'Bubblesheet format file',
1.67 raeburn 398: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 399: header => [ {col1 => 'Item',
400: col2 => '',
401: }],
1.230 raeburn 402: print => \&print_scantron,
403: modify => \&modify_scantron,
1.46 raeburn 404: },
1.86 raeburn 405: 'requestcourses' =>
406: {text => 'Request creation of courses',
407: help => 'Domain_Configuration_Request_Courses',
408: header => [{col1 => 'User affiliation',
1.102 raeburn 409: col2 => 'Availability/Processing of requests',},
410: {col1 => 'Setting',
1.216 raeburn 411: col2 => 'Value'},
412: {col1 => 'Available textbooks',
1.235 raeburn 413: col2 => ''},
1.242 raeburn 414: {col1 => 'Available templates',
415: col2 => ''},
1.235 raeburn 416: {col1 => 'Validation (not official courses)',
417: col2 => 'Value'},],
1.230 raeburn 418: print => \&print_quotas,
419: modify => \&modify_quotas,
1.86 raeburn 420: },
1.163 raeburn 421: 'requestauthor' =>
1.223 bisitz 422: {text => 'Request Authoring Space',
1.163 raeburn 423: help => 'Domain_Configuration_Request_Author',
424: header => [{col1 => 'User affiliation',
425: col2 => 'Availability/Processing of requests',},
426: {col1 => 'Setting',
427: col2 => 'Value'}],
1.230 raeburn 428: print => \&print_quotas,
429: modify => \&modify_quotas,
1.163 raeburn 430: },
1.69 raeburn 431: 'coursecategories' =>
1.120 raeburn 432: { text => 'Cataloging of courses/communities',
1.67 raeburn 433: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 434: header => [{col1 => 'Catalog type/availability',
435: col2 => '',},
436: {col1 => 'Category settings for standard catalog',
1.57 raeburn 437: col2 => '',},
438: {col1 => 'Categories',
439: col2 => '',
440: }],
1.230 raeburn 441: print => \&print_coursecategories,
442: modify => \&modify_coursecategories,
1.69 raeburn 443: },
444: 'serverstatuses' =>
1.77 raeburn 445: {text => 'Access to server status pages',
1.69 raeburn 446: help => 'Domain_Configuration_Server_Status',
447: header => [{col1 => 'Status Page',
448: col2 => 'Other named users',
449: col3 => 'Specific IPs',
450: }],
1.230 raeburn 451: print => \&print_serverstatuses,
452: modify => \&modify_serverstatuses,
1.69 raeburn 453: },
1.118 jms 454: 'helpsettings' =>
1.282 raeburn 455: {text => 'Support settings',
1.118 jms 456: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 457: header => [{col1 => 'Help Page Settings (logged-in users)',
458: col2 => 'Value'},
459: {col1 => 'Helpdesk Roles',
460: col2 => 'Settings'},],
1.230 raeburn 461: print => \&print_helpsettings,
462: modify => \&modify_helpsettings,
1.118 jms 463: },
1.121 raeburn 464: 'coursedefaults' =>
465: {text => 'Course/Community defaults',
466: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 467: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
468: col2 => 'Value',},
469: {col1 => 'Defaults which can be overridden for each course by a DC',
470: col2 => 'Value',},],
1.230 raeburn 471: print => \&print_coursedefaults,
472: modify => \&modify_coursedefaults,
1.121 raeburn 473: },
1.231 raeburn 474: 'selfenrollment' =>
475: {text => 'Self-enrollment in Course/Community',
476: help => 'Domain_Configuration_Selfenrollment',
477: header => [{col1 => 'Configuration Rights',
478: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
479: {col1 => 'Defaults',
480: col2 => 'Value'},
481: {col1 => 'Self-enrollment validation (optional)',
482: col2 => 'Value'},],
483: print => \&print_selfenrollment,
484: modify => \&modify_selfenrollment,
485: },
1.120 raeburn 486: 'privacy' =>
487: {text => 'User Privacy',
488: help => 'Domain_Configuration_User_Privacy',
489: header => [{col1 => 'Setting',
490: col2 => 'Value',}],
1.230 raeburn 491: print => \&print_privacy,
492: modify => \&modify_privacy,
1.120 raeburn 493: },
1.141 raeburn 494: 'usersessions' =>
1.145 raeburn 495: {text => 'User session hosting/offloading',
1.137 raeburn 496: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 497: header => [{col1 => 'Domain server',
498: col2 => 'Servers to offload sessions to when busy'},
499: {col1 => 'Hosting of users from other domains',
1.137 raeburn 500: col2 => 'Rules'},
501: {col1 => "Hosting domain's own users elsewhere",
502: col2 => 'Rules'}],
1.230 raeburn 503: print => \&print_usersessions,
504: modify => \&modify_usersessions,
1.137 raeburn 505: },
1.279 raeburn 506: 'loadbalancing' =>
1.185 raeburn 507: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 508: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 509: header => [{col1 => 'Balancers',
1.150 raeburn 510: col2 => 'Default destinations',
1.183 bisitz 511: col3 => 'User affiliation',
1.150 raeburn 512: col4 => 'Overrides'},
513: ],
1.230 raeburn 514: print => \&print_loadbalancing,
515: modify => \&modify_loadbalancing,
1.150 raeburn 516: },
1.279 raeburn 517: 'ltitools' =>
1.267 raeburn 518: {text => 'External Tools (LTI)',
1.296 raeburn 519: help => 'Domain_Configuration_LTI_Tools',
1.267 raeburn 520: header => [{col1 => 'Setting',
521: col2 => 'Value',}],
522: print => \&print_ltitools,
523: modify => \&modify_ltitools,
524: },
1.279 raeburn 525: 'ssl' =>
1.275 raeburn 526: {text => 'LON-CAPA Network (SSL)',
527: help => 'Domain_Configuration_Network_SSL',
528: header => [{col1 => 'Server',
529: col2 => 'Certificate Status'},
530: {col1 => 'Connections to other servers',
531: col2 => 'Rules'},
1.293 raeburn 532: {col1 => 'Connections from other servers',
533: col2 => 'Rules'},
1.275 raeburn 534: {col1 => "Replicating domain's published content",
535: col2 => 'Rules'}],
536: print => \&print_ssl,
537: modify => \&modify_ssl,
538: },
1.279 raeburn 539: 'trust' =>
540: {text => 'Trust Settings',
541: help => 'Domain_Configuration_Trust',
542: header => [{col1 => "Access to this domain's content by others",
543: col2 => 'Rules'},
544: {col1 => "Access to other domain's content by this domain",
545: col2 => 'Rules'},
546: {col1 => "Enrollment in this domain's courses by others",
547: col2 => 'Rules',},
548: {col1 => "Co-author roles in this domain for others",
549: col2 => 'Rules',},
550: {col1 => "Co-author roles for this domain's users elsewhere",
551: col2 => 'Rules',},
552: {col1 => "Domain roles in this domain assignable to others",
553: col2 => 'Rules'},
554: {col1 => "Course catalog for this domain displayed elsewhere",
555: col2 => 'Rules'},
556: {col1 => "Requests for creation of courses in this domain by others",
557: col2 => 'Rules'},
558: {col1 => "Users in other domains can send messages to this domain",
559: col2 => 'Rules'},],
560: print => \&print_trust,
561: modify => \&modify_trust,
562: },
1.320 raeburn 563: 'lti' =>
564: {text => 'LTI Provider',
565: help => 'Domain_Configuration_LTI_Provider',
566: header => [{col1 => 'Setting',
567: col2 => 'Value',}],
568: print => \&print_lti,
569: modify => \&modify_lti,
570: },
1.3 raeburn 571: );
1.110 raeburn 572: if (keys(%servers) > 1) {
573: $prefs{'login'} = { text => 'Log-in page options',
574: help => 'Domain_Configuration_Login_Page',
575: header => [{col1 => 'Log-in Service',
576: col2 => 'Server Setting',},
577: {col1 => 'Log-in Page Items',
1.168 raeburn 578: col2 => ''},
579: {col1 => 'Log-in Help',
1.256 raeburn 580: col2 => 'Value'},
581: {col1 => 'Custom HTML in document head',
1.168 raeburn 582: col2 => 'Value'}],
1.230 raeburn 583: print => \&print_login,
584: modify => \&modify_login,
1.110 raeburn 585: };
586: }
1.174 foxr 587:
1.6 raeburn 588: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 589: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 590: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 591: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 592: text=>"Settings to display/modify"});
1.9 raeburn 593: my $confname = $dom.'-domainconfig';
1.174 foxr 594:
1.3 raeburn 595: if ($phase eq 'process') {
1.212 raeburn 596: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
597: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 598: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 599: $r->rflush();
1.212 raeburn 600: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 601: }
1.30 raeburn 602: } elsif ($phase eq 'display') {
1.192 raeburn 603: my $js = &recaptcha_js().
1.236 raeburn 604: &toggle_display_js();
1.171 raeburn 605: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 606: my ($othertitle,$usertypes,$types) =
607: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 608: $js .= &lonbalance_targets_js($dom,$types,\%servers,
609: $domconfig{'loadbalancing'}).
1.170 raeburn 610: &new_spares_js().
611: &common_domprefs_js().
612: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 613: }
1.216 raeburn 614: if (grep(/^requestcourses$/,@actions)) {
615: my $javascript_validations;
616: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
617: $js .= <<END;
618: <script type="text/javascript">
619: $javascript_validations
620: </script>
621: $coursebrowserjs
622: END
623: }
1.305 raeburn 624: if (grep(/^selfcreation$/,@actions)) {
625: $js .= &selfcreate_javascript();
626: }
1.286 raeburn 627: if (grep(/^contacts$/,@actions)) {
628: $js .= &contacts_javascript();
629: }
1.150 raeburn 630: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 631: } else {
1.180 raeburn 632: # check if domconfig user exists for the domain.
633: my $servadm = $r->dir_config('lonAdmEMail');
634: my ($configuserok,$author_ok,$switchserver) =
635: &config_check($dom,$confname,$servadm);
636: unless ($configuserok eq 'ok') {
1.181 raeburn 637: &Apache::lonconfigsettings::print_header($r,$phase,$context);
638: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 639: $confname).
1.181 raeburn 640: '<br />'
641: );
1.180 raeburn 642: if ($switchserver) {
1.181 raeburn 643: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
644: '<br />'.
645: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
646: '<br />'.
647: &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).
648: '<br />'.
649: &mt('To do that now, use the following link: [_1]',$switchserver)
650: );
651: } else {
652: $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.').
653: '<br />'.
654: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
655: );
1.180 raeburn 656: }
657: $r->print(&Apache::loncommon::end_page());
658: return OK;
659: }
1.21 raeburn 660: if (keys(%domconfig) == 0) {
661: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 662: my @ids=&Apache::lonnet::current_machine_ids();
663: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 664: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 665: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 666: my $custom_img_count = 0;
667: foreach my $img (@loginimages) {
668: if ($designhash{$dom.'.login.'.$img} ne '') {
669: $custom_img_count ++;
670: }
671: }
672: foreach my $role (@roles) {
673: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
674: $custom_img_count ++;
675: }
676: }
677: if ($custom_img_count > 0) {
1.94 raeburn 678: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 679: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 680: $r->print(
681: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
682: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
683: &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 />'.
684: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
685: if ($switch_server) {
1.30 raeburn 686: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 687: }
1.91 raeburn 688: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 689: return OK;
690: }
691: }
692: }
1.91 raeburn 693: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 694: }
695: return OK;
696: }
697:
698: sub process_changes {
1.205 raeburn 699: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 700: my %domconfig;
701: if (ref($values) eq 'HASH') {
702: %domconfig = %{$values};
703: }
1.3 raeburn 704: my $output;
705: if ($action eq 'login') {
1.205 raeburn 706: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 707: } elsif ($action eq 'rolecolors') {
1.9 raeburn 708: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 709: $lastactref,%domconfig);
1.3 raeburn 710: } elsif ($action eq 'quotas') {
1.216 raeburn 711: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 712: } elsif ($action eq 'autoenroll') {
1.205 raeburn 713: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 714: } elsif ($action eq 'autoupdate') {
715: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 716: } elsif ($action eq 'autocreate') {
717: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 718: } elsif ($action eq 'directorysrch') {
1.295 raeburn 719: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 720: } elsif ($action eq 'usercreation') {
1.28 raeburn 721: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 722: } elsif ($action eq 'selfcreation') {
1.305 raeburn 723: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 724: } elsif ($action eq 'usermodification') {
725: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 726: } elsif ($action eq 'contacts') {
1.205 raeburn 727: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 728: } elsif ($action eq 'defaults') {
1.212 raeburn 729: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 730: } elsif ($action eq 'scantron') {
1.205 raeburn 731: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 732: } elsif ($action eq 'coursecategories') {
1.239 raeburn 733: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 734: } elsif ($action eq 'serverstatuses') {
735: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 736: } elsif ($action eq 'requestcourses') {
1.216 raeburn 737: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 738: } elsif ($action eq 'requestauthor') {
1.216 raeburn 739: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 740: } elsif ($action eq 'helpsettings') {
1.285 raeburn 741: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 742: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 743: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 744: } elsif ($action eq 'selfenrollment') {
745: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 746: } elsif ($action eq 'usersessions') {
1.212 raeburn 747: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 748: } elsif ($action eq 'loadbalancing') {
749: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 750: } elsif ($action eq 'ltitools') {
751: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 752: } elsif ($action eq 'ssl') {
753: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 754: } elsif ($action eq 'trust') {
755: $output = &modify_trust($dom,$lastactref,%domconfig);
1.320 raeburn 756: } elsif ($action eq 'lti') {
757: $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 758: }
759: return $output;
760: }
761:
762: sub print_config_box {
1.9 raeburn 763: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 764: my $rowtotal = 0;
1.49 raeburn 765: my $output;
766: if ($action eq 'coursecategories') {
767: $output = &coursecategories_javascript($settings);
1.236 raeburn 768: } elsif ($action eq 'defaults') {
769: $output = &defaults_javascript($settings);
1.282 raeburn 770: } elsif ($action eq 'helpsettings') {
771: my (%privs,%levelscurrent);
772: my %full=();
773: my %levels=(
774: course => {},
775: domain => {},
776: system => {},
777: );
778: my $context = 'domain';
779: my $crstype = 'Course';
780: my $formname = 'display';
781: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
782: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
783: $output =
784: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
785: \@templateroles);
1.334 raeburn 786: } elsif ($action eq 'ltitools') {
787: $output .= <itools_javascript($settings);
788: } elsif ($action eq 'lti') {
789: $output .= <i_javascript($settings);
1.91 raeburn 790: }
1.236 raeburn 791: $output .=
1.30 raeburn 792: '<table class="LC_nested_outer">
1.3 raeburn 793: <tr>
1.306 raeburn 794: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 795: &mt($item->{text}).' '.
796: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
797: '</tr>';
1.30 raeburn 798: $rowtotal ++;
1.110 raeburn 799: my $numheaders = 1;
800: if (ref($item->{'header'}) eq 'ARRAY') {
801: $numheaders = scalar(@{$item->{'header'}});
802: }
803: if ($numheaders > 1) {
1.64 raeburn 804: my $colspan = '';
1.145 raeburn 805: my $rightcolspan = '';
1.238 raeburn 806: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 807: ($action eq 'directorysrch') ||
1.256 raeburn 808: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 809: $colspan = ' colspan="2"';
810: }
1.145 raeburn 811: if ($action eq 'usersessions') {
812: $rightcolspan = ' colspan="3"';
813: }
1.30 raeburn 814: $output .= '
1.3 raeburn 815: <tr>
816: <td>
817: <table class="LC_nested">
818: <tr class="LC_info_row">
1.59 bisitz 819: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 820: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 821: </tr>';
1.69 raeburn 822: $rowtotal ++;
1.230 raeburn 823: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 824: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 825: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 826: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
827: ($action eq 'contacts')) {
1.230 raeburn 828: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 829: } elsif ($action eq 'coursecategories') {
1.230 raeburn 830: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 831: } elsif ($action eq 'login') {
1.256 raeburn 832: if ($numheaders == 4) {
1.168 raeburn 833: $colspan = ' colspan="2"';
834: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
835: } else {
836: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
837: }
1.230 raeburn 838: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 839: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 840: } elsif ($action eq 'rolecolors') {
1.30 raeburn 841: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 842: }
1.30 raeburn 843: $output .= '
1.6 raeburn 844: </table>
845: </td>
846: </tr>
847: <tr>
848: <td>
849: <table class="LC_nested">
850: <tr class="LC_info_row">
1.230 raeburn 851: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 852: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 853: </tr>';
854: $rowtotal ++;
1.230 raeburn 855: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
856: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 857: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.294 raeburn 858: ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults')) {
1.238 raeburn 859: if ($action eq 'coursecategories') {
860: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
861: $colspan = ' colspan="2"';
1.279 raeburn 862: } elsif ($action eq 'trust') {
863: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.238 raeburn 864: } else {
865: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
866: }
1.279 raeburn 867: if ($action eq 'trust') {
868: $output .= '
869: </table>
870: </td>
871: </tr>';
872: my @trusthdrs = qw(2 3 4 5 6 7);
873: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
874: for (my $i=0; $i<@trusthdrs; $i++) {
875: $output .= '
876: <tr>
877: <td>
878: <table class="LC_nested">
879: <tr class="LC_info_row">
880: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
881: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
882: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
883: </table>
884: </td>
885: </tr>';
886: }
887: $output .= '
888: <tr>
889: <td>
890: <table class="LC_nested">
891: <tr class="LC_info_row">
892: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
893: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
894: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
895: } else {
896: $output .= '
1.63 raeburn 897: </table>
898: </td>
899: </tr>
900: <tr>
901: <td>
902: <table class="LC_nested">
903: <tr class="LC_info_row">
904: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 905: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 906: </tr>'."\n";
1.279 raeburn 907: if ($action eq 'coursecategories') {
908: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.340 raeburn 909: } elsif ($action eq 'contacts') {
910: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal).'
911: </tr>
912: </table>
913: </td>
914: </tr>
915: <tr>
916: <td>
917: <table class="LC_nested">
918: <tr class="LC_info_row">
919: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
920: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
921: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal).'
922: </table>
923: </td>
924: </tr>
925: <tr>';
1.279 raeburn 926: } else {
927: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
928: }
1.238 raeburn 929: }
1.63 raeburn 930: $rowtotal ++;
1.236 raeburn 931: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.282 raeburn 932: ($action eq 'defaults') || ($action eq 'directorysrch') ||
933: ($action eq 'helpsettings')) {
1.230 raeburn 934: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.293 raeburn 935: } elsif ($action eq 'ssl') {
936: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
937: </table>
938: </td>
939: </tr>
940: <tr>
941: <td>
942: <table class="LC_nested">
943: <tr class="LC_info_row">
944: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
945: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
946: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
947: </table>
948: </td>
949: </tr>
950: <tr>
951: <td>
952: <table class="LC_nested">
953: <tr class="LC_info_row">
954: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
955: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
956: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 957: } elsif ($action eq 'login') {
1.256 raeburn 958: if ($numheaders == 4) {
1.168 raeburn 959: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
960: </table>
961: </td>
962: </tr>
963: <tr>
964: <td>
965: <table class="LC_nested">
966: <tr class="LC_info_row">
967: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 968: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 969: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
970: $rowtotal ++;
971: } else {
972: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
973: }
1.256 raeburn 974: $output .= '
975: </table>
976: </td>
977: </tr>
978: <tr>
979: <td>
980: <table class="LC_nested">
981: <tr class="LC_info_row">';
982: if ($numheaders == 4) {
983: $output .= '
984: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
985: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
986: </tr>';
987: } else {
988: $output .= '
989: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
990: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
991: </tr>';
992: }
993: $rowtotal ++;
994: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 995: } elsif ($action eq 'requestcourses') {
1.247 raeburn 996: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
997: $rowtotal ++;
998: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 999: </table>
1000: </td>
1001: </tr>
1002: <tr>
1003: <td>
1004: <table class="LC_nested">
1005: <tr class="LC_info_row">
1006: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1007: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 1008: &textbookcourses_javascript($settings).
1009: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1010: </table>
1011: </td>
1012: </tr>
1013: <tr>
1014: <td>
1015: <table class="LC_nested">
1016: <tr class="LC_info_row">
1017: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1018: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1019: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 1020: </table>
1021: </td>
1022: </tr>
1023: <tr>
1024: <td>
1025: <table class="LC_nested">
1026: <tr class="LC_info_row">
1.306 raeburn 1027: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1028: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1029: </tr>'.
1030: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1031: } elsif ($action eq 'requestauthor') {
1032: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1033: $rowtotal ++;
1.122 jms 1034: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1035: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1036: </table>
1037: </td>
1038: </tr>
1039: <tr>
1040: <td>
1041: <table class="LC_nested">
1042: <tr class="LC_info_row">
1.306 raeburn 1043: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 1044: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1045: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1046: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1047: </tr>'.
1.30 raeburn 1048: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1049: </table>
1050: </td>
1051: </tr>
1052: <tr>
1053: <td>
1054: <table class="LC_nested">
1055: <tr class="LC_info_row">
1.59 bisitz 1056: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1057: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1058: </tr>'.
1.30 raeburn 1059: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1060: $rowtotal += 2;
1.6 raeburn 1061: }
1.3 raeburn 1062: } else {
1.30 raeburn 1063: $output .= '
1.3 raeburn 1064: <tr>
1065: <td>
1066: <table class="LC_nested">
1.30 raeburn 1067: <tr class="LC_info_row">';
1.277 raeburn 1068: if ($action eq 'login') {
1.30 raeburn 1069: $output .= '
1.59 bisitz 1070: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1071: } elsif ($action eq 'serverstatuses') {
1072: $output .= '
1.306 raeburn 1073: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1074: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1075:
1.6 raeburn 1076: } else {
1.30 raeburn 1077: $output .= '
1.306 raeburn 1078: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1079: }
1.72 raeburn 1080: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1081: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1082: &mt($item->{'header'}->[0]->{'col2'});
1083: if ($action eq 'serverstatuses') {
1084: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1085: }
1.69 raeburn 1086: } else {
1.306 raeburn 1087: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1088: &mt($item->{'header'}->[0]->{'col2'});
1089: }
1090: $output .= '</td>';
1091: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1092: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1093: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1094: &mt($item->{'header'}->[0]->{'col3'});
1095: } else {
1.306 raeburn 1096: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1097: &mt($item->{'header'}->[0]->{'col3'});
1098: }
1.69 raeburn 1099: if ($action eq 'serverstatuses') {
1100: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1101: }
1102: $output .= '</td>';
1.6 raeburn 1103: }
1.150 raeburn 1104: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1105: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1106: &mt($item->{'header'}->[0]->{'col4'});
1107: }
1.69 raeburn 1108: $output .= '</tr>';
1.48 raeburn 1109: $rowtotal ++;
1.168 raeburn 1110: if ($action eq 'quotas') {
1.86 raeburn 1111: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1112: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1113: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.320 raeburn 1114: ($action eq 'ltitools') || ($action eq 'lti')) {
1.230 raeburn 1115: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 1116: } elsif ($action eq 'scantron') {
1117: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.121 raeburn 1118: }
1.3 raeburn 1119: }
1.30 raeburn 1120: $output .= '
1.3 raeburn 1121: </table>
1122: </td>
1123: </tr>
1.30 raeburn 1124: </table><br />';
1125: return ($output,$rowtotal);
1.1 raeburn 1126: }
1127:
1.3 raeburn 1128: sub print_login {
1.168 raeburn 1129: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 1130: my ($css_class,$datatable);
1.6 raeburn 1131: my %choices = &login_choices();
1.110 raeburn 1132:
1.168 raeburn 1133: if ($caller eq 'service') {
1.149 raeburn 1134: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1135: my $choice = $choices{'disallowlogin'};
1136: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1137: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1138: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1139: '<th>'.$choices{'server'}.'</th>'.
1140: '<th>'.$choices{'serverpath'}.'</th>'.
1141: '<th>'.$choices{'custompath'}.'</th>'.
1142: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1143: my %disallowed;
1144: if (ref($settings) eq 'HASH') {
1145: if (ref($settings->{'loginvia'}) eq 'HASH') {
1146: %disallowed = %{$settings->{'loginvia'}};
1147: }
1148: }
1149: foreach my $lonhost (sort(keys(%servers))) {
1150: my $direct = 'selected="selected"';
1.128 raeburn 1151: if (ref($disallowed{$lonhost}) eq 'HASH') {
1152: if ($disallowed{$lonhost}{'server'} ne '') {
1153: $direct = '';
1154: }
1.110 raeburn 1155: }
1.115 raeburn 1156: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1157: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1158: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1159: '</option>';
1.184 raeburn 1160: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1161: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1162: my $selected = '';
1.128 raeburn 1163: if (ref($disallowed{$lonhost}) eq 'HASH') {
1164: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1165: $selected = 'selected="selected"';
1166: }
1.110 raeburn 1167: }
1168: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1169: $servers{$hostid}.'</option>';
1170: }
1.128 raeburn 1171: $datatable .= '</select></td>'.
1172: '<td><select name="'.$lonhost.'_serverpath">';
1173: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1174: my $pathname = $path;
1175: if ($path eq 'custom') {
1176: $pathname = &mt('Custom Path').' ->';
1177: }
1178: my $selected = '';
1179: if (ref($disallowed{$lonhost}) eq 'HASH') {
1180: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1181: $selected = 'selected="selected"';
1182: }
1183: } elsif ($path eq '') {
1184: $selected = 'selected="selected"';
1185: }
1186: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1187: }
1188: $datatable .= '</select></td>';
1189: my ($custom,$exempt);
1190: if (ref($disallowed{$lonhost}) eq 'HASH') {
1191: $custom = $disallowed{$lonhost}{'custompath'};
1192: $exempt = $disallowed{$lonhost}{'exempt'};
1193: }
1194: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1195: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1196: '</tr>';
1.110 raeburn 1197: }
1198: $datatable .= '</table></td></tr>';
1199: return $datatable;
1.168 raeburn 1200: } elsif ($caller eq 'page') {
1201: my %defaultchecked = (
1202: 'coursecatalog' => 'on',
1.188 raeburn 1203: 'helpdesk' => 'on',
1.168 raeburn 1204: 'adminmail' => 'off',
1205: 'newuser' => 'off',
1206: );
1.188 raeburn 1207: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1208: my (%checkedon,%checkedoff);
1.42 raeburn 1209: foreach my $item (@toggles) {
1.168 raeburn 1210: if ($defaultchecked{$item} eq 'on') {
1211: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1212: $checkedoff{$item} = ' ';
1.168 raeburn 1213: } elsif ($defaultchecked{$item} eq 'off') {
1214: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1215: $checkedon{$item} = ' ';
1216: }
1.1 raeburn 1217: }
1.168 raeburn 1218: my @images = ('img','logo','domlogo','login');
1219: my @logintext = ('textcol','bgcol');
1220: my @bgs = ('pgbg','mainbg','sidebg');
1221: my @links = ('link','alink','vlink');
1222: my %designhash = &Apache::loncommon::get_domainconf($dom);
1223: my %defaultdesign = %Apache::loncommon::defaultdesign;
1224: my (%is_custom,%designs);
1225: my %defaults = (
1226: font => $defaultdesign{'login.font'},
1227: );
1.6 raeburn 1228: foreach my $item (@images) {
1.168 raeburn 1229: $defaults{$item} = $defaultdesign{'login.'.$item};
1230: $defaults{'showlogo'}{$item} = 1;
1231: }
1232: foreach my $item (@bgs) {
1233: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1234: }
1.41 raeburn 1235: foreach my $item (@logintext) {
1.168 raeburn 1236: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1237: }
1.168 raeburn 1238: foreach my $item (@links) {
1239: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1240: }
1.168 raeburn 1241: if (ref($settings) eq 'HASH') {
1242: foreach my $item (@toggles) {
1243: if ($settings->{$item} eq '1') {
1244: $checkedon{$item} = ' checked="checked" ';
1245: $checkedoff{$item} = ' ';
1246: } elsif ($settings->{$item} eq '0') {
1247: $checkedoff{$item} = ' checked="checked" ';
1248: $checkedon{$item} = ' ';
1249: }
1250: }
1251: foreach my $item (@images) {
1252: if (defined($settings->{$item})) {
1253: $designs{$item} = $settings->{$item};
1254: $is_custom{$item} = 1;
1255: }
1256: if (defined($settings->{'showlogo'}{$item})) {
1257: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1258: }
1259: }
1260: foreach my $item (@logintext) {
1261: if ($settings->{$item} ne '') {
1262: $designs{'logintext'}{$item} = $settings->{$item};
1263: $is_custom{$item} = 1;
1264: }
1265: }
1266: if ($settings->{'font'} ne '') {
1267: $designs{'font'} = $settings->{'font'};
1268: $is_custom{'font'} = 1;
1269: }
1270: foreach my $item (@bgs) {
1271: if ($settings->{$item} ne '') {
1272: $designs{'bgs'}{$item} = $settings->{$item};
1273: $is_custom{$item} = 1;
1274: }
1275: }
1276: foreach my $item (@links) {
1277: if ($settings->{$item} ne '') {
1278: $designs{'links'}{$item} = $settings->{$item};
1279: $is_custom{$item} = 1;
1280: }
1281: }
1282: } else {
1283: if ($designhash{$dom.'.login.font'} ne '') {
1284: $designs{'font'} = $designhash{$dom.'.login.font'};
1285: $is_custom{'font'} = 1;
1286: }
1287: foreach my $item (@images) {
1288: if ($designhash{$dom.'.login.'.$item} ne '') {
1289: $designs{$item} = $designhash{$dom.'.login.'.$item};
1290: $is_custom{$item} = 1;
1291: }
1292: }
1293: foreach my $item (@bgs) {
1294: if ($designhash{$dom.'.login.'.$item} ne '') {
1295: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1296: $is_custom{$item} = 1;
1297: }
1.6 raeburn 1298: }
1.168 raeburn 1299: foreach my $item (@links) {
1300: if ($designhash{$dom.'.login.'.$item} ne '') {
1301: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1302: $is_custom{$item} = 1;
1303: }
1.6 raeburn 1304: }
1305: }
1.168 raeburn 1306: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1307: logo => 'Institution Logo',
1308: domlogo => 'Domain Logo',
1309: login => 'Login box');
1310: my $itemcount = 1;
1311: foreach my $item (@toggles) {
1312: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1313: $datatable .=
1314: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1315: '</td><td>'.
1316: '<span class="LC_nobreak"><label><input type="radio" name="'.
1317: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1318: '</label> <label><input type="radio" name="'.$item.'"'.
1319: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1320: '</tr>';
1321: $itemcount ++;
1.6 raeburn 1322: }
1.168 raeburn 1323: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1324: $datatable .= '</tr></table></td></tr>';
1325: } elsif ($caller eq 'help') {
1326: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1327: my $switchserver = &check_switchserver($dom,$confname);
1328: my $itemcount = 1;
1329: $defaulturl = '/adm/loginproblems.html';
1330: $defaulttype = 'default';
1331: %lt = &Apache::lonlocal::texthash (
1332: del => 'Delete?',
1333: rep => 'Replace:',
1334: upl => 'Upload:',
1335: default => 'Default',
1336: custom => 'Custom',
1337: );
1338: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1339: my @currlangs;
1340: if (ref($settings) eq 'HASH') {
1341: if (ref($settings->{'helpurl'}) eq 'HASH') {
1342: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1343: next if ($settings->{'helpurl'}{$key} eq '');
1344: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1345: $type{$key} = 'custom';
1346: unless ($key eq 'nolang') {
1347: push(@currlangs,$key);
1348: }
1349: }
1350: } elsif ($settings->{'helpurl'} ne '') {
1351: $type{'nolang'} = 'custom';
1352: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1353: }
1354: }
1.168 raeburn 1355: foreach my $lang ('nolang',sort(@currlangs)) {
1356: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1357: $datatable .= '<tr'.$css_class.'>';
1358: if ($url{$lang} eq '') {
1359: $url{$lang} = $defaulturl;
1360: }
1361: if ($type{$lang} eq '') {
1362: $type{$lang} = $defaulttype;
1363: }
1364: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1365: if ($lang eq 'nolang') {
1366: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1367: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1368: } else {
1369: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1370: $langchoices{$lang},
1371: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1372: }
1373: $datatable .= '</span></td>'."\n".
1374: '<td class="LC_left_item">';
1375: if ($type{$lang} eq 'custom') {
1376: $datatable .= '<span class="LC_nobreak"><label>'.
1377: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1378: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1379: } else {
1380: $datatable .= $lt{'upl'};
1381: }
1382: $datatable .='<br />';
1383: if ($switchserver) {
1384: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1385: } else {
1386: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1387: }
1.168 raeburn 1388: $datatable .= '</td></tr>';
1389: $itemcount ++;
1.6 raeburn 1390: }
1.168 raeburn 1391: my @addlangs;
1392: foreach my $lang (sort(keys(%langchoices))) {
1393: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1394: push(@addlangs,$lang);
1395: }
1396: if (@addlangs > 0) {
1397: my %toadd;
1398: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1399: $toadd{''} = &mt('Select');
1400: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1401: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1402: &mt('Add log-in help page for a specific language:').' '.
1403: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1404: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1405: if ($switchserver) {
1406: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1407: } else {
1408: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1409: }
1.168 raeburn 1410: $datatable .= '</td></tr>';
1.169 raeburn 1411: $itemcount ++;
1.6 raeburn 1412: }
1.169 raeburn 1413: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1414: } elsif ($caller eq 'headtag') {
1415: my %domservers = &Apache::lonnet::get_servers($dom);
1416: my $choice = $choices{'headtag'};
1417: $css_class = ' class="LC_odd_row"';
1418: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1419: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1420: '<th>'.$choices{'current'}.'</th>'.
1421: '<th>'.$choices{'action'}.'</th>'.
1422: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1423: my (%currurls,%currexempt);
1424: if (ref($settings) eq 'HASH') {
1425: if (ref($settings->{'headtag'}) eq 'HASH') {
1426: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1427: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1428: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1429: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1430: }
1431: }
1432: }
1433: }
1434: my %lt = &Apache::lonlocal::texthash(
1435: del => 'Delete?',
1436: rep => 'Replace:',
1437: upl => 'Upload:',
1438: curr => 'View contents',
1439: none => 'None',
1440: );
1441: my $switchserver = &check_switchserver($dom,$confname);
1442: foreach my $lonhost (sort(keys(%domservers))) {
1443: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1444: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1445: if ($currurls{$lonhost}) {
1446: $datatable .= '<td class="LC_right_item"><a href="'.
1447: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1448: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1449: '">'.$lt{'curr'}.'</a></td>'.
1450: '<td><span class="LC_nobreak"><label>'.
1451: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1452: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1453: } else {
1454: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1455: }
1456: $datatable .='<br />';
1457: if ($switchserver) {
1458: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1459: } else {
1460: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1461: }
1.330 raeburn 1462: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256 raeburn 1463: }
1464: $datatable .= '</table></td></tr>';
1.1 raeburn 1465: }
1.6 raeburn 1466: return $datatable;
1467: }
1468:
1469: sub login_choices {
1470: my %choices =
1471: &Apache::lonlocal::texthash (
1.116 bisitz 1472: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1473: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1474: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1475: disallowlogin => "Login page requests redirected",
1476: hostid => "Server",
1.128 raeburn 1477: server => "Redirect to:",
1478: serverpath => "Path",
1479: custompath => "Custom",
1480: exempt => "Exempt IP(s)",
1.110 raeburn 1481: directlogin => "No redirect",
1482: newuser => "Link to create a user account",
1483: img => "Header",
1484: logo => "Main Logo",
1485: domlogo => "Domain Logo",
1486: login => "Log-in Header",
1487: textcol => "Text color",
1488: bgcol => "Box color",
1489: bgs => "Background colors",
1490: links => "Link colors",
1491: font => "Font color",
1492: pgbg => "Header",
1493: mainbg => "Page",
1494: sidebg => "Login box",
1495: link => "Link",
1496: alink => "Active link",
1497: vlink => "Visited link",
1.256 raeburn 1498: headtag => "Custom markup",
1499: action => "Action",
1500: current => "Current",
1.6 raeburn 1501: );
1502: return %choices;
1503: }
1504:
1505: sub print_rolecolors {
1.30 raeburn 1506: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1507: my %choices = &color_font_choices();
1508: my @bgs = ('pgbg','tabbg','sidebg');
1509: my @links = ('link','alink','vlink');
1510: my @images = ('img');
1511: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1512: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1513: my %defaultdesign = %Apache::loncommon::defaultdesign;
1514: my (%is_custom,%designs);
1.200 raeburn 1515: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1516: if (ref($settings) eq 'HASH') {
1517: if (ref($settings->{$role}) eq 'HASH') {
1518: if ($settings->{$role}->{'img'} ne '') {
1519: $designs{'img'} = $settings->{$role}->{'img'};
1520: $is_custom{'img'} = 1;
1521: }
1522: if ($settings->{$role}->{'font'} ne '') {
1523: $designs{'font'} = $settings->{$role}->{'font'};
1524: $is_custom{'font'} = 1;
1525: }
1.97 tempelho 1526: if ($settings->{$role}->{'fontmenu'} ne '') {
1527: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1528: $is_custom{'fontmenu'} = 1;
1529: }
1.6 raeburn 1530: foreach my $item (@bgs) {
1531: if ($settings->{$role}->{$item} ne '') {
1532: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1533: $is_custom{$item} = 1;
1534: }
1535: }
1536: foreach my $item (@links) {
1537: if ($settings->{$role}->{$item} ne '') {
1538: $designs{'links'}{$item} = $settings->{$role}->{$item};
1539: $is_custom{$item} = 1;
1540: }
1541: }
1542: }
1543: } else {
1544: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1545: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1546: $is_custom{'img'} = 1;
1547: }
1.97 tempelho 1548: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1549: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1550: $is_custom{'fontmenu'} = 1;
1551: }
1.6 raeburn 1552: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1553: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1554: $is_custom{'font'} = 1;
1555: }
1556: foreach my $item (@bgs) {
1557: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1558: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1559: $is_custom{$item} = 1;
1560:
1561: }
1562: }
1563: foreach my $item (@links) {
1564: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1565: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1566: $is_custom{$item} = 1;
1567: }
1568: }
1569: }
1570: my $itemcount = 1;
1.30 raeburn 1571: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1572: $datatable .= '</tr></table></td></tr>';
1573: return $datatable;
1574: }
1575:
1.200 raeburn 1576: sub role_defaults {
1577: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1578: my %defaults;
1579: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1580: return %defaults;
1581: }
1582: my %defaultdesign = %Apache::loncommon::defaultdesign;
1583: if ($role eq 'login') {
1584: %defaults = (
1585: font => $defaultdesign{$role.'.font'},
1586: );
1587: if (ref($logintext) eq 'ARRAY') {
1588: foreach my $item (@{$logintext}) {
1589: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1590: }
1591: }
1592: foreach my $item (@{$images}) {
1593: $defaults{'showlogo'}{$item} = 1;
1594: }
1595: } else {
1596: %defaults = (
1597: img => $defaultdesign{$role.'.img'},
1598: font => $defaultdesign{$role.'.font'},
1599: fontmenu => $defaultdesign{$role.'.fontmenu'},
1600: );
1601: }
1602: foreach my $item (@{$bgs}) {
1603: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1604: }
1605: foreach my $item (@{$links}) {
1606: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1607: }
1608: foreach my $item (@{$images}) {
1609: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1610: }
1611: return %defaults;
1612: }
1613:
1.6 raeburn 1614: sub display_color_options {
1.9 raeburn 1615: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1616: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1617: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1618: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1619: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1620: '<td>'.$choices->{'font'}.'</td>';
1621: if (!$is_custom->{'font'}) {
1.329 raeburn 1622: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1623: } else {
1624: $datatable .= '<td> </td>';
1625: }
1.174 foxr 1626: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1627:
1.8 raeburn 1628: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1629: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1630: ' value="'.$current_color.'" /> '.
1.329 raeburn 1631: ' </span></td></tr>';
1.107 raeburn 1632: unless ($role eq 'login') {
1633: $datatable .= '<tr'.$css_class.'>'.
1634: '<td>'.$choices->{'fontmenu'}.'</td>';
1635: if (!$is_custom->{'fontmenu'}) {
1.329 raeburn 1636: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 1637: } else {
1638: $datatable .= '<td> </td>';
1639: }
1.202 raeburn 1640: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1641: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1642: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1643: '<input class="colorchooser" type="text" size="10" name="'
1644: .$role.'_fontmenu"'.
1645: ' value="'.$current_color.'" /> '.
1.329 raeburn 1646: ' </span></td></tr>';
1.97 tempelho 1647: }
1.9 raeburn 1648: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1649: foreach my $img (@{$images}) {
1.18 albertel 1650: $itemcount ++;
1.6 raeburn 1651: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1652: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1653: '<td>'.$choices->{$img};
1.41 raeburn 1654: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1655: if ($role eq 'login') {
1656: if ($img eq 'login') {
1657: $login_hdr_pick =
1.135 bisitz 1658: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1659: $logincolors =
1660: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1661: $designs,$defaults);
1.70 raeburn 1662: } elsif ($img ne 'domlogo') {
1663: $datatable.= &logo_display_options($img,$defaults,$designs);
1664: }
1665: }
1666: $datatable .= '</td>';
1.6 raeburn 1667: if ($designs->{$img} ne '') {
1668: $imgfile = $designs->{$img};
1.18 albertel 1669: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1670: } else {
1671: $imgfile = $defaults->{$img};
1672: }
1673: if ($imgfile) {
1.9 raeburn 1674: my ($showfile,$fullsize);
1675: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1676: my $urldir = $1;
1677: my $filename = $2;
1678: my @info = &Apache::lonnet::stat_file($designs->{$img});
1679: if (@info) {
1680: my $thumbfile = 'tn-'.$filename;
1681: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1682: if (@thumb) {
1683: $showfile = $urldir.'/'.$thumbfile;
1684: } else {
1685: $showfile = $imgfile;
1686: }
1687: } else {
1688: $showfile = '';
1689: }
1690: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1691: $showfile = $imgfile;
1.6 raeburn 1692: my $imgdir = $1;
1693: my $filename = $2;
1.159 raeburn 1694: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1695: $showfile = "/$imgdir/tn-".$filename;
1696: } else {
1.159 raeburn 1697: my $input = $londocroot.$imgfile;
1698: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1699: if (!-e $output) {
1.9 raeburn 1700: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1701: my ($fullwidth,$fullheight) = &check_dimensions($input);
1702: if ($fullwidth ne '' && $fullheight ne '') {
1703: if ($fullwidth > $width && $fullheight > $height) {
1704: my $size = $width.'x'.$height;
1.316 raeburn 1705: my @args = ('convert','-sample',$size,$input,$output);
1706: system({$args[0]} @args);
1.159 raeburn 1707: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1708: }
1709: }
1.6 raeburn 1710: }
1711: }
1.16 raeburn 1712: }
1.6 raeburn 1713: if ($showfile) {
1.40 raeburn 1714: if ($showfile =~ m{^/(adm|res)/}) {
1715: if ($showfile =~ m{^/res/}) {
1716: my $local_showfile =
1717: &Apache::lonnet::filelocation('',$showfile);
1718: &Apache::lonnet::repcopy($local_showfile);
1719: }
1720: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1721: }
1722: if ($imgfile) {
1723: if ($imgfile =~ m{^/(adm|res)/}) {
1724: if ($imgfile =~ m{^/res/}) {
1725: my $local_imgfile =
1726: &Apache::lonnet::filelocation('',$imgfile);
1727: &Apache::lonnet::repcopy($local_imgfile);
1728: }
1729: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1730: } else {
1731: $fullsize = $imgfile;
1732: }
1733: }
1.41 raeburn 1734: $datatable .= '<td>';
1735: if ($img eq 'login') {
1.135 bisitz 1736: $datatable .= $login_hdr_pick;
1737: }
1.41 raeburn 1738: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1739: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1740: } else {
1.201 raeburn 1741: $datatable .= '<td> </td><td class="LC_left_item">'.
1742: &mt('Upload:').'<br />';
1.6 raeburn 1743: }
1744: } else {
1.201 raeburn 1745: $datatable .= '<td> </td><td class="LC_left_item">'.
1746: &mt('Upload:').'<br />';
1.6 raeburn 1747: }
1.9 raeburn 1748: if ($switchserver) {
1749: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1750: } else {
1.135 bisitz 1751: if ($img ne 'login') { # suppress file selection for Log-in header
1752: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1753: }
1.9 raeburn 1754: }
1755: $datatable .= '</td></tr>';
1.6 raeburn 1756: }
1757: $itemcount ++;
1758: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1759: $datatable .= '<tr'.$css_class.'>'.
1760: '<td>'.$choices->{'bgs'}.'</td>';
1761: my $bgs_def;
1762: foreach my $item (@{$bgs}) {
1763: if (!$is_custom->{$item}) {
1.329 raeburn 1764: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span class="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 1765: }
1766: }
1767: if ($bgs_def) {
1.8 raeburn 1768: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1769: } else {
1770: $datatable .= '<td> </td>';
1771: }
1772: $datatable .= '<td class="LC_right_item">'.
1773: '<table border="0"><tr>';
1.174 foxr 1774:
1.6 raeburn 1775: foreach my $item (@{$bgs}) {
1.306 raeburn 1776: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 1777: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1778: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1779: $datatable .= ' ';
1.6 raeburn 1780: }
1.174 foxr 1781: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1782: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1783: }
1784: $datatable .= '</tr></table></td></tr>';
1785: $itemcount ++;
1786: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1787: $datatable .= '<tr'.$css_class.'>'.
1788: '<td>'.$choices->{'links'}.'</td>';
1789: my $links_def;
1790: foreach my $item (@{$links}) {
1791: if (!$is_custom->{$item}) {
1.329 raeburn 1792: $links_def .= '<td>'.$choices->{$item}.'<br /><span class="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 1793: }
1794: }
1795: if ($links_def) {
1.8 raeburn 1796: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1797: } else {
1798: $datatable .= '<td> </td>';
1799: }
1800: $datatable .= '<td class="LC_right_item">'.
1801: '<table border="0"><tr>';
1802: foreach my $item (@{$links}) {
1.234 raeburn 1803: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 1804: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 1805: if ($designs->{'links'}{$item}) {
1.174 foxr 1806: $datatable.=' ';
1.6 raeburn 1807: }
1.174 foxr 1808: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1809: '" /></td>';
1810: }
1.30 raeburn 1811: $$rowtotal += $itemcount;
1.3 raeburn 1812: return $datatable;
1813: }
1814:
1.70 raeburn 1815: sub logo_display_options {
1816: my ($img,$defaults,$designs) = @_;
1817: my $checkedon;
1818: if (ref($defaults) eq 'HASH') {
1819: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1820: if ($defaults->{'showlogo'}{$img}) {
1821: $checkedon = 'checked="checked" ';
1822: }
1823: }
1824: }
1825: if (ref($designs) eq 'HASH') {
1826: if (ref($designs->{'showlogo'}) eq 'HASH') {
1827: if (defined($designs->{'showlogo'}{$img})) {
1828: if ($designs->{'showlogo'}{$img} == 0) {
1829: $checkedon = '';
1830: } elsif ($designs->{'showlogo'}{$img} == 1) {
1831: $checkedon = 'checked="checked" ';
1832: }
1833: }
1834: }
1835: }
1836: return '<br /><label> <input type="checkbox" name="'.
1837: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1838: &mt('show').'</label>'."\n";
1839: }
1840:
1.41 raeburn 1841: sub login_header_options {
1.135 bisitz 1842: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1843: my $output = '';
1.41 raeburn 1844: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1845: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1846: if (!$is_custom->{'textcol'}) {
1847: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1848: ' ';
1849: }
1850: if (!$is_custom->{'bgcol'}) {
1851: $output .= $choices->{'bgcol'}.': '.
1852: '<span id="css_'.$role.'_font" style="background-color: '.
1853: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1854: }
1855: $output .= '<br />';
1856: }
1857: $output .='<br />';
1858: return $output;
1859: }
1860:
1861: sub login_text_colors {
1.201 raeburn 1862: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1863: my $color_menu = '<table border="0"><tr>';
1864: foreach my $item (@{$logintext}) {
1.306 raeburn 1865: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 1866: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1867: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1868: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1869: }
1870: $color_menu .= '</tr></table><br />';
1871: return $color_menu;
1872: }
1873:
1874: sub image_changes {
1875: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1876: my $output;
1.135 bisitz 1877: if ($img eq 'login') {
1.331 raeburn 1878: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 1879: } elsif (!$is_custom) {
1.70 raeburn 1880: if ($img ne 'domlogo') {
1.331 raeburn 1881: $output = &mt('Default image:').'<br />';
1.41 raeburn 1882: } else {
1.331 raeburn 1883: $output = &mt('Default in use:').'<br />';
1.41 raeburn 1884: }
1885: }
1.331 raeburn 1886: if ($img ne 'login') {
1.135 bisitz 1887: if ($img_import) {
1888: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1889: }
1890: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1891: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1892: if ($is_custom) {
1893: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1894: '<input type="checkbox" name="'.
1895: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1896: '</label> '.&mt('Replace:').'</span><br />';
1897: } else {
1.306 raeburn 1898: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1899: }
1.41 raeburn 1900: }
1901: return $output;
1902: }
1903:
1.3 raeburn 1904: sub print_quotas {
1.86 raeburn 1905: my ($dom,$settings,$rowtotal,$action) = @_;
1906: my $context;
1907: if ($action eq 'quotas') {
1908: $context = 'tools';
1909: } else {
1910: $context = $action;
1911: }
1.197 raeburn 1912: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1913: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1914: my $typecount = 0;
1.101 raeburn 1915: my ($css_class,%titles);
1.86 raeburn 1916: if ($context eq 'requestcourses') {
1.325 raeburn 1917: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 1918: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1919: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1920: %titles = &courserequest_titles();
1.163 raeburn 1921: } elsif ($context eq 'requestauthor') {
1922: @usertools = ('author');
1923: @options = ('norequest','approval','automatic');
1.210 raeburn 1924: %titles = &authorrequest_titles();
1.86 raeburn 1925: } else {
1.162 raeburn 1926: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1927: %titles = &tool_titles();
1.86 raeburn 1928: }
1.26 raeburn 1929: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1930: foreach my $type (@{$types}) {
1.197 raeburn 1931: my ($currdefquota,$currauthorquota);
1.163 raeburn 1932: unless (($context eq 'requestcourses') ||
1933: ($context eq 'requestauthor')) {
1.86 raeburn 1934: if (ref($settings) eq 'HASH') {
1935: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1936: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1937: } else {
1938: $currdefquota = $settings->{$type};
1939: }
1.197 raeburn 1940: if (ref($settings->{authorquota}) eq 'HASH') {
1941: $currauthorquota = $settings->{authorquota}->{$type};
1942: }
1.78 raeburn 1943: }
1.72 raeburn 1944: }
1.3 raeburn 1945: if (defined($usertypes->{$type})) {
1946: $typecount ++;
1947: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1948: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1949: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1950: '<td class="LC_left_item">';
1.101 raeburn 1951: if ($context eq 'requestcourses') {
1952: $datatable .= '<table><tr>';
1953: }
1954: my %cell;
1.72 raeburn 1955: foreach my $item (@usertools) {
1.101 raeburn 1956: if ($context eq 'requestcourses') {
1957: my ($curroption,$currlimit);
1958: if (ref($settings) eq 'HASH') {
1959: if (ref($settings->{$item}) eq 'HASH') {
1960: $curroption = $settings->{$item}->{$type};
1961: if ($curroption =~ /^autolimit=(\d*)$/) {
1962: $currlimit = $1;
1963: }
1964: }
1965: }
1966: if (!$curroption) {
1967: $curroption = 'norequest';
1968: }
1969: $datatable .= '<th>'.$titles{$item}.'</th>';
1970: foreach my $option (@options) {
1971: my $val = $option;
1972: if ($option eq 'norequest') {
1973: $val = 0;
1974: }
1975: if ($option eq 'validate') {
1976: my $canvalidate = 0;
1977: if (ref($validations{$item}) eq 'HASH') {
1978: if ($validations{$item}{$type}) {
1979: $canvalidate = 1;
1980: }
1981: }
1982: next if (!$canvalidate);
1983: }
1984: my $checked = '';
1985: if ($option eq $curroption) {
1986: $checked = ' checked="checked"';
1987: } elsif ($option eq 'autolimit') {
1988: if ($curroption =~ /^autolimit/) {
1989: $checked = ' checked="checked"';
1990: }
1991: }
1992: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1993: '<input type="radio" name="crsreq_'.$item.
1994: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1995: $titles{$option}.'</label>';
1.101 raeburn 1996: if ($option eq 'autolimit') {
1.127 raeburn 1997: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1998: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1999: 'value="'.$currlimit.'" />';
1.101 raeburn 2000: }
1.127 raeburn 2001: $cell{$item} .= '</span> ';
1.103 raeburn 2002: if ($option eq 'autolimit') {
1.127 raeburn 2003: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2004: }
1.101 raeburn 2005: }
1.163 raeburn 2006: } elsif ($context eq 'requestauthor') {
2007: my $curroption;
2008: if (ref($settings) eq 'HASH') {
2009: $curroption = $settings->{$type};
2010: }
2011: if (!$curroption) {
2012: $curroption = 'norequest';
2013: }
2014: foreach my $option (@options) {
2015: my $val = $option;
2016: if ($option eq 'norequest') {
2017: $val = 0;
2018: }
2019: my $checked = '';
2020: if ($option eq $curroption) {
2021: $checked = ' checked="checked"';
2022: }
2023: $datatable .= '<span class="LC_nobreak"><label>'.
2024: '<input type="radio" name="authorreq_'.$type.
2025: '" value="'.$val.'"'.$checked.' />'.
2026: $titles{$option}.'</label></span> ';
2027: }
1.101 raeburn 2028: } else {
2029: my $checked = 'checked="checked" ';
2030: if (ref($settings) eq 'HASH') {
2031: if (ref($settings->{$item}) eq 'HASH') {
2032: if ($settings->{$item}->{$type} == 0) {
2033: $checked = '';
2034: } elsif ($settings->{$item}->{$type} == 1) {
2035: $checked = 'checked="checked" ';
2036: }
1.78 raeburn 2037: }
1.72 raeburn 2038: }
1.101 raeburn 2039: $datatable .= '<span class="LC_nobreak"><label>'.
2040: '<input type="checkbox" name="'.$context.'_'.$item.
2041: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2042: '</label></span> ';
1.72 raeburn 2043: }
1.101 raeburn 2044: }
2045: if ($context eq 'requestcourses') {
2046: $datatable .= '</tr><tr>';
2047: foreach my $item (@usertools) {
1.106 raeburn 2048: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2049: }
2050: $datatable .= '</tr></table>';
1.72 raeburn 2051: }
1.86 raeburn 2052: $datatable .= '</td>';
1.163 raeburn 2053: unless (($context eq 'requestcourses') ||
2054: ($context eq 'requestauthor')) {
1.86 raeburn 2055: $datatable .=
1.197 raeburn 2056: '<td class="LC_right_item">'.
2057: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2058: '<input type="text" name="quota_'.$type.
1.72 raeburn 2059: '" value="'.$currdefquota.
1.197 raeburn 2060: '" size="5" /></span>'.(' ' x 2).
2061: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2062: '<input type="text" name="authorquota_'.$type.
2063: '" value="'.$currauthorquota.
2064: '" size="5" /></span></td>';
1.86 raeburn 2065: }
2066: $datatable .= '</tr>';
1.3 raeburn 2067: }
2068: }
2069: }
1.163 raeburn 2070: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2071: $defaultquota = '20';
1.197 raeburn 2072: $authorquota = '500';
1.86 raeburn 2073: if (ref($settings) eq 'HASH') {
2074: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2075: $defaultquota = $settings->{'defaultquota'}->{'default'};
2076: } elsif (defined($settings->{'default'})) {
2077: $defaultquota = $settings->{'default'};
2078: }
1.197 raeburn 2079: if (ref($settings->{'authorquota'}) eq 'HASH') {
2080: $authorquota = $settings->{'authorquota'}->{'default'};
2081: }
1.3 raeburn 2082: }
2083: }
2084: $typecount ++;
2085: $css_class = $typecount%2?' class="LC_odd_row"':'';
2086: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2087: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2088: '<td class="LC_left_item">';
1.101 raeburn 2089: if ($context eq 'requestcourses') {
2090: $datatable .= '<table><tr>';
2091: }
2092: my %defcell;
1.72 raeburn 2093: foreach my $item (@usertools) {
1.101 raeburn 2094: if ($context eq 'requestcourses') {
2095: my ($curroption,$currlimit);
2096: if (ref($settings) eq 'HASH') {
2097: if (ref($settings->{$item}) eq 'HASH') {
2098: $curroption = $settings->{$item}->{'default'};
2099: if ($curroption =~ /^autolimit=(\d*)$/) {
2100: $currlimit = $1;
2101: }
2102: }
2103: }
2104: if (!$curroption) {
2105: $curroption = 'norequest';
2106: }
2107: $datatable .= '<th>'.$titles{$item}.'</th>';
2108: foreach my $option (@options) {
2109: my $val = $option;
2110: if ($option eq 'norequest') {
2111: $val = 0;
2112: }
2113: if ($option eq 'validate') {
2114: my $canvalidate = 0;
2115: if (ref($validations{$item}) eq 'HASH') {
2116: if ($validations{$item}{'default'}) {
2117: $canvalidate = 1;
2118: }
2119: }
2120: next if (!$canvalidate);
2121: }
2122: my $checked = '';
2123: if ($option eq $curroption) {
2124: $checked = ' checked="checked"';
2125: } elsif ($option eq 'autolimit') {
2126: if ($curroption =~ /^autolimit/) {
2127: $checked = ' checked="checked"';
2128: }
2129: }
2130: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2131: '<input type="radio" name="crsreq_'.$item.
2132: '_default" value="'.$val.'"'.$checked.' />'.
2133: $titles{$option}.'</label>';
2134: if ($option eq 'autolimit') {
1.127 raeburn 2135: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2136: $item.'_limit_default" size="1" '.
2137: 'value="'.$currlimit.'" />';
2138: }
1.127 raeburn 2139: $defcell{$item} .= '</span> ';
1.104 raeburn 2140: if ($option eq 'autolimit') {
1.127 raeburn 2141: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2142: }
1.101 raeburn 2143: }
1.163 raeburn 2144: } elsif ($context eq 'requestauthor') {
2145: my $curroption;
2146: if (ref($settings) eq 'HASH') {
1.172 raeburn 2147: $curroption = $settings->{'default'};
1.163 raeburn 2148: }
2149: if (!$curroption) {
2150: $curroption = 'norequest';
2151: }
2152: foreach my $option (@options) {
2153: my $val = $option;
2154: if ($option eq 'norequest') {
2155: $val = 0;
2156: }
2157: my $checked = '';
2158: if ($option eq $curroption) {
2159: $checked = ' checked="checked"';
2160: }
2161: $datatable .= '<span class="LC_nobreak"><label>'.
2162: '<input type="radio" name="authorreq_default"'.
2163: ' value="'.$val.'"'.$checked.' />'.
2164: $titles{$option}.'</label></span> ';
2165: }
1.101 raeburn 2166: } else {
2167: my $checked = 'checked="checked" ';
2168: if (ref($settings) eq 'HASH') {
2169: if (ref($settings->{$item}) eq 'HASH') {
2170: if ($settings->{$item}->{'default'} == 0) {
2171: $checked = '';
2172: } elsif ($settings->{$item}->{'default'} == 1) {
2173: $checked = 'checked="checked" ';
2174: }
1.78 raeburn 2175: }
1.72 raeburn 2176: }
1.101 raeburn 2177: $datatable .= '<span class="LC_nobreak"><label>'.
2178: '<input type="checkbox" name="'.$context.'_'.$item.
2179: '" value="default" '.$checked.'/>'.$titles{$item}.
2180: '</label></span> ';
2181: }
2182: }
2183: if ($context eq 'requestcourses') {
2184: $datatable .= '</tr><tr>';
2185: foreach my $item (@usertools) {
1.106 raeburn 2186: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2187: }
1.101 raeburn 2188: $datatable .= '</tr></table>';
1.72 raeburn 2189: }
1.86 raeburn 2190: $datatable .= '</td>';
1.163 raeburn 2191: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2192: $datatable .= '<td class="LC_right_item">'.
2193: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2194: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2195: $defaultquota.'" size="5" /></span>'.(' ' x2).
2196: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2197: '<input type="text" name="authorquota" value="'.
2198: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2199: }
2200: $datatable .= '</tr>';
1.72 raeburn 2201: $typecount ++;
2202: $css_class = $typecount%2?' class="LC_odd_row"':'';
2203: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2204: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2205: if ($context eq 'requestcourses') {
1.109 raeburn 2206: $datatable .= &mt('(overrides affiliation, if set)').
2207: '</td>'.
2208: '<td class="LC_left_item">'.
2209: '<table><tr>';
1.101 raeburn 2210: } else {
1.109 raeburn 2211: $datatable .= &mt('(overrides affiliation, if checked)').
2212: '</td>'.
2213: '<td class="LC_left_item" colspan="2">'.
2214: '<br />';
1.101 raeburn 2215: }
2216: my %advcell;
1.72 raeburn 2217: foreach my $item (@usertools) {
1.101 raeburn 2218: if ($context eq 'requestcourses') {
2219: my ($curroption,$currlimit);
2220: if (ref($settings) eq 'HASH') {
2221: if (ref($settings->{$item}) eq 'HASH') {
2222: $curroption = $settings->{$item}->{'_LC_adv'};
2223: if ($curroption =~ /^autolimit=(\d*)$/) {
2224: $currlimit = $1;
2225: }
2226: }
2227: }
2228: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2229: my $checked = '';
2230: if ($curroption eq '') {
2231: $checked = ' checked="checked"';
2232: }
2233: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2234: '<input type="radio" name="crsreq_'.$item.
2235: '__LC_adv" value=""'.$checked.' />'.
2236: &mt('No override set').'</label></span> ';
1.101 raeburn 2237: foreach my $option (@options) {
2238: my $val = $option;
2239: if ($option eq 'norequest') {
2240: $val = 0;
2241: }
2242: if ($option eq 'validate') {
2243: my $canvalidate = 0;
2244: if (ref($validations{$item}) eq 'HASH') {
2245: if ($validations{$item}{'_LC_adv'}) {
2246: $canvalidate = 1;
2247: }
2248: }
2249: next if (!$canvalidate);
2250: }
2251: my $checked = '';
1.104 raeburn 2252: if ($val eq $curroption) {
1.101 raeburn 2253: $checked = ' checked="checked"';
2254: } elsif ($option eq 'autolimit') {
2255: if ($curroption =~ /^autolimit/) {
2256: $checked = ' checked="checked"';
2257: }
2258: }
2259: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2260: '<input type="radio" name="crsreq_'.$item.
2261: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2262: $titles{$option}.'</label>';
2263: if ($option eq 'autolimit') {
1.127 raeburn 2264: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2265: $item.'_limit__LC_adv" size="1" '.
2266: 'value="'.$currlimit.'" />';
2267: }
1.127 raeburn 2268: $advcell{$item} .= '</span> ';
1.104 raeburn 2269: if ($option eq 'autolimit') {
1.127 raeburn 2270: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2271: }
1.101 raeburn 2272: }
1.163 raeburn 2273: } elsif ($context eq 'requestauthor') {
2274: my $curroption;
2275: if (ref($settings) eq 'HASH') {
2276: $curroption = $settings->{'_LC_adv'};
2277: }
2278: my $checked = '';
2279: if ($curroption eq '') {
2280: $checked = ' checked="checked"';
2281: }
2282: $datatable .= '<span class="LC_nobreak"><label>'.
2283: '<input type="radio" name="authorreq__LC_adv"'.
2284: ' value=""'.$checked.' />'.
2285: &mt('No override set').'</label></span> ';
2286: foreach my $option (@options) {
2287: my $val = $option;
2288: if ($option eq 'norequest') {
2289: $val = 0;
2290: }
2291: my $checked = '';
2292: if ($val eq $curroption) {
2293: $checked = ' checked="checked"';
2294: }
2295: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2296: '<input type="radio" name="authorreq__LC_adv"'.
2297: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2298: $titles{$option}.'</label></span> ';
2299: }
1.101 raeburn 2300: } else {
2301: my $checked = 'checked="checked" ';
2302: if (ref($settings) eq 'HASH') {
2303: if (ref($settings->{$item}) eq 'HASH') {
2304: if ($settings->{$item}->{'_LC_adv'} == 0) {
2305: $checked = '';
2306: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2307: $checked = 'checked="checked" ';
2308: }
1.79 raeburn 2309: }
1.72 raeburn 2310: }
1.101 raeburn 2311: $datatable .= '<span class="LC_nobreak"><label>'.
2312: '<input type="checkbox" name="'.$context.'_'.$item.
2313: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2314: '</label></span> ';
2315: }
2316: }
2317: if ($context eq 'requestcourses') {
2318: $datatable .= '</tr><tr>';
2319: foreach my $item (@usertools) {
1.106 raeburn 2320: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2321: }
1.101 raeburn 2322: $datatable .= '</tr></table>';
1.72 raeburn 2323: }
1.98 raeburn 2324: $datatable .= '</td></tr>';
1.30 raeburn 2325: $$rowtotal += $typecount;
1.3 raeburn 2326: return $datatable;
2327: }
2328:
1.163 raeburn 2329: sub print_requestmail {
1.305 raeburn 2330: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2331: my ($now,$datatable,%currapp);
1.102 raeburn 2332: $now = time;
2333: if (ref($settings) eq 'HASH') {
2334: if (ref($settings->{'notify'}) eq 'HASH') {
2335: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2336: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2337: }
2338: }
2339: }
1.191 raeburn 2340: my $numinrow = 2;
1.224 raeburn 2341: my $css_class;
1.305 raeburn 2342: if ($$rowtotal%2) {
2343: $css_class = 'LC_odd_row';
2344: }
2345: if ($customcss) {
2346: $css_class .= " $customcss";
2347: }
2348: $css_class =~ s/^\s+//;
2349: if ($css_class) {
2350: $css_class = ' class="'.$css_class.'"';
2351: }
2352: if ($rowstyle) {
2353: $css_class .= ' style="'.$rowstyle.'"';
2354: }
1.163 raeburn 2355: my $text;
2356: if ($action eq 'requestcourses') {
2357: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2358: } elsif ($action eq 'requestauthor') {
2359: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2360: } else {
1.224 raeburn 2361: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2362: }
1.224 raeburn 2363: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2364: ' <td>'.$text.'</td>'.
1.102 raeburn 2365: ' <td class="LC_left_item">';
1.191 raeburn 2366: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2367: $action.'notifyapproval',%currapp);
1.191 raeburn 2368: if ($numdc > 0) {
2369: $datatable .= $table;
1.102 raeburn 2370: } else {
2371: $datatable .= &mt('There are no active Domain Coordinators');
2372: }
2373: $datatable .='</td></tr>';
2374: return $datatable;
2375: }
2376:
1.216 raeburn 2377: sub print_studentcode {
2378: my ($settings,$rowtotal) = @_;
2379: my $rownum = 0;
1.218 raeburn 2380: my ($output,%current);
1.325 raeburn 2381: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2382: if (ref($settings) eq 'HASH') {
2383: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2384: foreach my $type (@crstypes) {
2385: $current{$type} = $settings->{'uniquecode'}{$type};
2386: }
1.218 raeburn 2387: }
2388: }
2389: $output .= '<tr>'.
2390: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2391: '<td class="LC_left_item">';
2392: foreach my $type (@crstypes) {
2393: my $check = ' ';
2394: if ($current{$type}) {
2395: $check = ' checked="checked" ';
2396: }
2397: $output .= '<span class="LC_nobreak"><label>'.
2398: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2399: &mt($type).'</label></span>'.(' 'x2).' ';
2400: }
2401: $output .= '</td></tr>';
2402: $$rowtotal ++;
2403: return $output;
1.216 raeburn 2404: }
2405:
2406: sub print_textbookcourses {
1.242 raeburn 2407: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2408: my $rownum = 0;
2409: my $css_class;
2410: my $itemcount = 1;
2411: my $maxnum = 0;
2412: my $bookshash;
2413: if (ref($settings) eq 'HASH') {
1.242 raeburn 2414: $bookshash = $settings->{$type};
1.216 raeburn 2415: }
2416: my %ordered;
2417: if (ref($bookshash) eq 'HASH') {
2418: foreach my $item (keys(%{$bookshash})) {
2419: if (ref($bookshash->{$item}) eq 'HASH') {
2420: my $num = $bookshash->{$item}{'order'};
2421: $ordered{$num} = $item;
2422: }
2423: }
2424: }
2425: my $confname = $dom.'-domainconfig';
2426: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2427: my $maxnum = scalar(keys(%ordered));
2428: my $datatable;
1.216 raeburn 2429: if (keys(%ordered)) {
2430: my @items = sort { $a <=> $b } keys(%ordered);
2431: for (my $i=0; $i<@items; $i++) {
2432: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2433: my $key = $ordered{$items[$i]};
2434: my %coursehash=&Apache::lonnet::coursedescription($key);
2435: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2436: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2437: if (ref($bookshash->{$key}) eq 'HASH') {
2438: $subject = $bookshash->{$key}->{'subject'};
2439: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2440: if ($type eq 'textbooks') {
1.243 raeburn 2441: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2442: $author = $bookshash->{$key}->{'author'};
2443: $image = $bookshash->{$key}->{'image'};
2444: if ($image ne '') {
2445: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2446: my $imagethumb = "$path/tn-".$imagefile;
2447: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2448: }
1.216 raeburn 2449: }
2450: }
1.242 raeburn 2451: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2452: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2453: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2454: for (my $k=0; $k<=$maxnum; $k++) {
2455: my $vpos = $k+1;
2456: my $selstr;
2457: if ($k == $i) {
2458: $selstr = ' selected="selected" ';
2459: }
2460: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2461: }
2462: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2463: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2464: &mt('Delete?').'</label></span></td>'.
2465: '<td colspan="2">'.
1.242 raeburn 2466: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2467: (' 'x2).
1.242 raeburn 2468: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2469: if ($type eq 'textbooks') {
2470: $datatable .= (' 'x2).
1.243 raeburn 2471: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2472: (' 'x2).
1.242 raeburn 2473: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2474: (' 'x2).
2475: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2476: if ($image) {
1.267 raeburn 2477: $datatable .= $imgsrc.
1.242 raeburn 2478: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2479: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2480: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2481: }
2482: if ($switchserver) {
2483: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2484: } else {
2485: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2486: }
1.216 raeburn 2487: }
1.242 raeburn 2488: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2489: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2490: $coursetitle.'</span></td></tr>'."\n";
2491: $itemcount ++;
2492: }
2493: }
2494: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2495: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2496: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2497: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2498: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2499: for (my $k=0; $k<$maxnum+1; $k++) {
2500: my $vpos = $k+1;
2501: my $selstr;
2502: if ($k == $maxnum) {
2503: $selstr = ' selected="selected" ';
2504: }
2505: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2506: }
2507: $datatable .= '</select> '."\n".
1.334 raeburn 2508: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216 raeburn 2509: '<td colspan="2">'.
1.242 raeburn 2510: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2511: (' 'x2).
1.242 raeburn 2512: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2513: (' 'x2);
2514: if ($type eq 'textbooks') {
1.243 raeburn 2515: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2516: (' 'x2).
2517: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2518: (' 'x2).
2519: '<span class="LC_nobreak">'.&mt('Image:').' ';
2520: if ($switchserver) {
2521: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2522: } else {
2523: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2524: }
1.334 raeburn 2525: $datatable .= '</span>'."\n";
1.216 raeburn 2526: }
1.334 raeburn 2527: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2528: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2529: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2530: &Apache::loncommon::selectcourse_link
1.334 raeburn 2531: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216 raeburn 2532: '</span></td>'."\n".
2533: '</tr>'."\n";
2534: $itemcount ++;
2535: return $datatable;
2536: }
2537:
1.217 raeburn 2538: sub textbookcourses_javascript {
1.242 raeburn 2539: my ($settings) = @_;
2540: return unless(ref($settings) eq 'HASH');
2541: my (%ordered,%total,%jstext);
2542: foreach my $type ('textbooks','templates') {
2543: $total{$type} = 0;
2544: if (ref($settings->{$type}) eq 'HASH') {
2545: foreach my $item (keys(%{$settings->{$type}})) {
2546: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2547: my $num = $settings->{$type}->{$item}{'order'};
2548: $ordered{$type}{$num} = $item;
2549: }
2550: }
2551: $total{$type} = scalar(keys(%{$settings->{$type}}));
2552: }
2553: my @jsarray = ();
2554: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2555: push(@jsarray,$ordered{$type}{$item});
2556: }
2557: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2558: }
2559: return <<"ENDSCRIPT";
2560: <script type="text/javascript">
2561: // <![CDATA[
1.242 raeburn 2562: function reorderBooks(form,item,caller) {
1.217 raeburn 2563: var changedVal;
1.242 raeburn 2564: $jstext{'textbooks'};
2565: $jstext{'templates'};
2566: var newpos;
2567: var maxh;
2568: if (caller == 'textbooks') {
2569: newpos = 'textbooks_addbook_pos';
2570: maxh = 1 + $total{'textbooks'};
2571: } else {
2572: newpos = 'templates_addbook_pos';
2573: maxh = 1 + $total{'templates'};
2574: }
1.217 raeburn 2575: var current = new Array;
2576: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2577: if (item == newpos) {
2578: changedVal = newitemVal;
2579: } else {
2580: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2581: current[newitemVal] = newpos;
2582: }
1.242 raeburn 2583: if (caller == 'textbooks') {
2584: for (var i=0; i<textbooks.length; i++) {
2585: var elementName = 'textbooks_'+textbooks[i];
2586: if (elementName != item) {
2587: if (form.elements[elementName]) {
2588: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2589: current[currVal] = elementName;
2590: }
2591: }
2592: }
2593: }
2594: if (caller == 'templates') {
2595: for (var i=0; i<templates.length; i++) {
2596: var elementName = 'templates_'+templates[i];
2597: if (elementName != item) {
2598: if (form.elements[elementName]) {
2599: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2600: current[currVal] = elementName;
2601: }
1.217 raeburn 2602: }
2603: }
2604: }
2605: var oldVal;
2606: for (var j=0; j<maxh; j++) {
2607: if (current[j] == undefined) {
2608: oldVal = j;
2609: }
2610: }
2611: if (oldVal < changedVal) {
2612: for (var k=oldVal+1; k<=changedVal ; k++) {
2613: var elementName = current[k];
2614: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2615: }
2616: } else {
2617: for (var k=changedVal; k<oldVal; k++) {
2618: var elementName = current[k];
2619: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2620: }
2621: }
2622: return;
2623: }
2624:
2625: // ]]>
2626: </script>
2627:
2628: ENDSCRIPT
2629: }
2630:
1.267 raeburn 2631: sub ltitools_javascript {
2632: my ($settings) = @_;
1.319 raeburn 2633: my $togglejs = <itools_toggle_js();
2634: unless (ref($settings) eq 'HASH') {
2635: return $togglejs;
2636: }
1.267 raeburn 2637: my (%ordered,$total,%jstext);
2638: $total = 0;
2639: foreach my $item (keys(%{$settings})) {
2640: if (ref($settings->{$item}) eq 'HASH') {
2641: my $num = $settings->{$item}{'order'};
2642: $ordered{$num} = $item;
2643: }
2644: }
2645: $total = scalar(keys(%{$settings}));
2646: my @jsarray = ();
2647: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2648: push(@jsarray,$ordered{$item});
2649: }
2650: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2651: return <<"ENDSCRIPT";
2652: <script type="text/javascript">
2653: // <![CDATA[
1.319 raeburn 2654: function reorderLTITools(form,item) {
1.267 raeburn 2655: var changedVal;
2656: $jstext
2657: var newpos = 'ltitools_add_pos';
2658: var maxh = 1 + $total;
2659: var current = new Array;
2660: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2661: if (item == newpos) {
2662: changedVal = newitemVal;
2663: } else {
2664: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2665: current[newitemVal] = newpos;
2666: }
2667: for (var i=0; i<ltitools.length; i++) {
2668: var elementName = 'ltitools_'+ltitools[i];
2669: if (elementName != item) {
2670: if (form.elements[elementName]) {
2671: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2672: current[currVal] = elementName;
2673: }
2674: }
2675: }
2676: var oldVal;
2677: for (var j=0; j<maxh; j++) {
2678: if (current[j] == undefined) {
2679: oldVal = j;
2680: }
2681: }
2682: if (oldVal < changedVal) {
2683: for (var k=oldVal+1; k<=changedVal ; k++) {
2684: var elementName = current[k];
2685: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2686: }
2687: } else {
2688: for (var k=changedVal; k<oldVal; k++) {
2689: var elementName = current[k];
2690: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2691: }
2692: }
2693: return;
2694: }
2695:
2696: // ]]>
2697: </script>
2698:
1.319 raeburn 2699: $togglejs
2700:
2701: ENDSCRIPT
2702: }
2703:
2704: sub ltitools_toggle_js {
2705: return <<"ENDSCRIPT";
2706: <script type="text/javascript">
2707: // <![CDATA[
2708:
2709: function toggleLTITools(form,setting,item) {
2710: var radioname = '';
2711: var divid = '';
2712: if ((setting == 'passback') || (setting == 'roster')) {
2713: radioname = 'ltitools_'+setting+'_'+item;
2714: divid = 'ltitools_'+setting+'time_'+item;
2715: var num = form.elements[radioname].length;
2716: if (num) {
2717: var setvis = '';
2718: for (var i=0; i<num; i++) {
2719: if (form.elements[radioname][i].checked) {
2720: if (form.elements[radioname][i].value == '1') {
2721: if (document.getElementById(divid)) {
2722: document.getElementById(divid).style.display = 'inline-block';
2723: }
2724: setvis = 1;
2725: }
2726: break;
2727: }
2728: }
2729: }
2730: if (!setvis) {
2731: if (document.getElementById(divid)) {
2732: document.getElementById(divid).style.display = 'none';
2733: }
2734: }
2735: }
1.324 raeburn 2736: if (setting == 'user') {
2737: divid = 'ltitools_'+setting+'_div_'+item;
2738: var checkid = 'ltitools_'+setting+'_field_'+item;
2739: if (document.getElementById(divid)) {
2740: if (document.getElementById(checkid)) {
2741: if (document.getElementById(checkid).checked) {
2742: document.getElementById(divid).style.display = 'inline-block';
2743: } else {
2744: document.getElementById(divid).style.display = 'none';
2745: }
2746: }
2747: }
2748: }
1.319 raeburn 2749: return;
2750: }
2751: // ]]>
2752: </script>
2753:
1.267 raeburn 2754: ENDSCRIPT
2755: }
2756:
1.320 raeburn 2757: sub lti_javascript {
2758: my ($settings) = @_;
2759: my $togglejs = <i_toggle_js();
2760: unless (ref($settings) eq 'HASH') {
2761: return $togglejs;
2762: }
2763: my (%ordered,$total,%jstext);
2764: $total = 0;
2765: foreach my $item (keys(%{$settings})) {
2766: if (ref($settings->{$item}) eq 'HASH') {
2767: my $num = $settings->{$item}{'order'};
2768: $ordered{$num} = $item;
2769: }
2770: }
2771: $total = scalar(keys(%{$settings}));
2772: my @jsarray = ();
2773: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2774: push(@jsarray,$ordered{$item});
2775: }
2776: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
2777: return <<"ENDSCRIPT";
2778: <script type="text/javascript">
2779: // <![CDATA[
2780: function reorderLTI(form,item) {
2781: var changedVal;
2782: $jstext
2783: var newpos = 'lti_pos_add';
2784: var maxh = 1 + $total;
2785: var current = new Array;
2786: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2787: if (item == newpos) {
2788: changedVal = newitemVal;
2789: } else {
2790: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2791: current[newitemVal] = newpos;
2792: }
2793: for (var i=0; i<lti.length; i++) {
2794: var elementName = 'lti_pos_'+lti[i];
2795: if (elementName != item) {
2796: if (form.elements[elementName]) {
2797: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2798: current[currVal] = elementName;
2799: }
2800: }
2801: }
2802: var oldVal;
2803: for (var j=0; j<maxh; j++) {
2804: if (current[j] == undefined) {
2805: oldVal = j;
2806: }
2807: }
2808: if (oldVal < changedVal) {
2809: for (var k=oldVal+1; k<=changedVal ; k++) {
2810: var elementName = current[k];
2811: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2812: }
2813: } else {
2814: for (var k=changedVal; k<oldVal; k++) {
2815: var elementName = current[k];
2816: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2817: }
2818: }
2819: return;
2820: }
2821: // ]]>
2822: </script>
2823:
2824: $togglejs
2825:
2826: ENDSCRIPT
2827: }
2828:
2829: sub lti_toggle_js {
1.325 raeburn 2830: my %lcauthparmtext = &Apache::lonlocal::texthash (
2831: localauth => 'Local auth argument',
2832: krb => 'Kerberos domain',
2833: );
1.320 raeburn 2834: return <<"ENDSCRIPT";
2835: <script type="text/javascript">
2836: // <![CDATA[
2837:
2838: function toggleLTI(form,setting,item) {
1.337 raeburn 2839: if ((setting == 'user') || (setting == 'crs') || (setting == 'passback')) {
1.320 raeburn 2840: var radioname = '';
2841: var divid = '';
2842: if (setting == 'user') {
2843: radioname = 'lti_mapuser_'+item;
2844: divid = 'lti_userfield_'+item;
1.343 ! raeburn 2845: } else if (setting == 'crs') {
1.320 raeburn 2846: radioname = 'lti_mapcrs_'+item;
2847: divid = 'lti_crsfield_'+item;
1.337 raeburn 2848: } else {
2849: radioname = 'lti_passbackformat_'+item;
2850: divid = 'lti_passback_'+item;
1.320 raeburn 2851: }
2852: var num = form.elements[radioname].length;
2853: if (num) {
2854: var setvis = '';
2855: for (var i=0; i<num; i++) {
2856: if (form.elements[radioname][i].checked) {
1.337 raeburn 2857: if (setting == 'passback') {
2858: if (form.elements[radioname][i].value == '1') {
2859: if (document.getElementById(divid)) {
2860: document.getElementById(divid).style.display = 'inline-block';
2861: }
2862: setvis = 1;
2863: break;
2864: }
2865: } else {
2866: if (form.elements[radioname][i].value == 'other') {
2867: if (document.getElementById(divid)) {
2868: document.getElementById(divid).style.display = 'inline-block';
2869: }
2870: setvis = 1;
2871: break;
1.320 raeburn 2872: }
2873: }
2874: }
2875: }
2876: if (!setvis) {
2877: if (document.getElementById(divid)) {
2878: document.getElementById(divid).style.display = 'none';
2879: }
2880: }
2881: }
2882: } else if ((setting == 'sec') || (setting == 'secsrc')) {
2883: var numsec = form.elements['lti_crssec_'+item].length;
2884: if (numsec) {
2885: var setvis = '';
2886: for (var i=0; i<numsec; i++) {
2887: if (form.elements['lti_crssec_'+item][i].checked) {
2888: if (form.elements['lti_crssec_'+item][i].value == '1') {
2889: if (document.getElementById('lti_crssecfield_'+item)) {
2890: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
2891: setvis = 1;
2892: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
2893: if (numsrcsec) {
2894: var setsrcvis = '';
2895: for (var j=0; j<numsrcsec; j++) {
2896: if (form.elements['lti_crssecsrc_'+item][j].checked) {
2897: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
2898: if (document.getElementById('lti_secsrcfield_'+item)) {
2899: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
2900: setsrcvis = 1;
2901: }
2902: }
2903: }
2904: }
2905: if (!setsrcvis) {
2906: if (document.getElementById('lti_secsrcfield_'+item)) {
2907: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
2908: }
2909: }
2910: }
2911: }
2912: }
2913: }
2914: }
2915: if (!setvis) {
2916: if (document.getElementById('lti_crssecfield_'+item)) {
2917: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
2918: }
2919: if (document.getElementById('lti_secsrcfield_'+item)) {
2920: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
2921: }
2922: }
2923: }
1.325 raeburn 2924: } else if (setting == 'lcauth') {
2925: var numauth = form.elements['lti_lcauth_'+item].length;
2926: if (numauth) {
2927: for (var i=0; i<numauth; i++) {
2928: if (form.elements['lti_lcauth_'+item][i].checked) {
2929: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
2930: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
2931: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
2932: } else {
2933: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
2934: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
2935: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
2936: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
2937: } else {
2938: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
2939: }
2940: }
2941: }
2942: }
2943: }
2944: }
2945: }
1.326 raeburn 2946: } else if (setting == 'lcmenu') {
2947: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
2948: var divid = 'lti_menufield_'+item;
2949: var setvis = '';
2950: for (var i=0; i<menus.length; i++) {
2951: var radioname = menus[i];
2952: var num = form.elements[radioname].length;
2953: if (num) {
2954: for (var j=0; j<num; j++) {
2955: if (form.elements[radioname][j].checked) {
2956: if (form.elements[radioname][j].value == '1') {
2957: if (document.getElementById(divid)) {
2958: document.getElementById(divid).style.display = 'inline-block';
2959: }
2960: setvis = 1;
2961: break;
2962: }
2963: }
2964: }
2965: }
2966: if (setvis == 1) {
2967: break;
2968: }
2969: }
2970: if (!setvis) {
2971: if (document.getElementById(divid)) {
2972: document.getElementById(divid).style.display = 'none';
2973: }
2974: }
1.320 raeburn 2975: }
2976: return;
2977: }
2978: // ]]>
2979: </script>
2980:
2981: ENDSCRIPT
2982: }
2983:
1.3 raeburn 2984: sub print_autoenroll {
1.30 raeburn 2985: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2986: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274 raeburn 2987: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2988: if (ref($settings) eq 'HASH') {
2989: if (exists($settings->{'run'})) {
2990: if ($settings->{'run'} eq '0') {
2991: $runoff = ' checked="checked" ';
2992: $runon = ' ';
2993: } else {
2994: $runon = ' checked="checked" ';
2995: $runoff = ' ';
2996: }
2997: } else {
2998: if ($autorun) {
2999: $runon = ' checked="checked" ';
3000: $runoff = ' ';
3001: } else {
3002: $runoff = ' checked="checked" ';
3003: $runon = ' ';
3004: }
3005: }
1.129 raeburn 3006: if (exists($settings->{'co-owners'})) {
3007: if ($settings->{'co-owners'} eq '0') {
3008: $coownersoff = ' checked="checked" ';
3009: $coownerson = ' ';
3010: } else {
3011: $coownerson = ' checked="checked" ';
3012: $coownersoff = ' ';
3013: }
3014: } else {
3015: $coownersoff = ' checked="checked" ';
3016: $coownerson = ' ';
3017: }
1.3 raeburn 3018: if (exists($settings->{'sender_domain'})) {
3019: $defdom = $settings->{'sender_domain'};
3020: }
1.274 raeburn 3021: if (exists($settings->{'autofailsafe'})) {
3022: $failsafe = $settings->{'autofailsafe'};
3023: }
1.14 raeburn 3024: } else {
3025: if ($autorun) {
3026: $runon = ' checked="checked" ';
3027: $runoff = ' ';
3028: } else {
3029: $runoff = ' checked="checked" ';
3030: $runon = ' ';
3031: }
1.3 raeburn 3032: }
3033: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 3034: my $notif_sender;
3035: if (ref($settings) eq 'HASH') {
3036: $notif_sender = $settings->{'sender_uname'};
3037: }
1.3 raeburn 3038: my $datatable='<tr class="LC_odd_row">'.
3039: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 3040: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3041: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 3042: $runon.' value="1" />'.&mt('Yes').'</label> '.
3043: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 3044: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3045: '</tr><tr>'.
3046: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 3047: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 3048: &mt('username').': '.
3049: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 3050: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 3051: ': '.$domform.'</span></td></tr>'.
3052: '<tr class="LC_odd_row">'.
3053: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3054: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3055: '<input type="radio" name="autoassign_coowners"'.
3056: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3057: '<label><input type="radio" name="autoassign_coowners"'.
3058: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 3059: '</tr><tr>'.
3060: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
3061: '<td class="LC_right_item"><span class="LC_nobreak">'.
3062: '<input type="text" name="autoenroll_failsafe"'.
1.333 raeburn 3063: ' value="'.$failsafe.'" size="4" /></span></td></tr>';
1.274 raeburn 3064: $$rowtotal += 4;
1.3 raeburn 3065: return $datatable;
3066: }
3067:
3068: sub print_autoupdate {
1.30 raeburn 3069: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 3070: my $datatable;
3071: if ($position eq 'top') {
3072: my $updateon = ' ';
3073: my $updateoff = ' checked="checked" ';
3074: my $classlistson = ' ';
3075: my $classlistsoff = ' checked="checked" ';
3076: if (ref($settings) eq 'HASH') {
3077: if ($settings->{'run'} eq '1') {
3078: $updateon = $updateoff;
3079: $updateoff = ' ';
3080: }
3081: if ($settings->{'classlists'} eq '1') {
3082: $classlistson = $classlistsoff;
3083: $classlistsoff = ' ';
3084: }
3085: }
3086: my %title = (
3087: run => 'Auto-update active?',
3088: classlists => 'Update information in classlists?',
3089: );
3090: $datatable = '<tr class="LC_odd_row">'.
3091: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 3092: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3093: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 3094: $updateon.' value="1" />'.&mt('Yes').'</label> '.
3095: '<label><input type="radio" name="autoupdate_run"'.
3096: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3097: '</tr><tr>'.
3098: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 3099: '<td class="LC_right_item"><span class="LC_nobreak">'.
3100: '<label><input type="radio" name="classlists"'.
3101: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
3102: '<label><input type="radio" name="classlists"'.
3103: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3104: '</tr>';
1.30 raeburn 3105: $$rowtotal += 2;
1.131 raeburn 3106: } elsif ($position eq 'middle') {
3107: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3108: my $numinrow = 3;
3109: my $locknamesettings;
3110: $datatable .= &insttypes_row($settings,$types,$usertypes,
3111: $dom,$numinrow,$othertitle,
1.305 raeburn 3112: 'lockablenames',$rowtotal);
1.131 raeburn 3113: $$rowtotal ++;
1.3 raeburn 3114: } else {
1.44 raeburn 3115: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3116: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3117: 'permanentemail','id');
1.33 raeburn 3118: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3119: my $numrows = 0;
1.26 raeburn 3120: if (ref($types) eq 'ARRAY') {
3121: if (@{$types} > 0) {
3122: $datatable =
3123: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3124: \@fields,$types,\$numrows);
1.30 raeburn 3125: $$rowtotal += @{$types};
1.26 raeburn 3126: }
1.3 raeburn 3127: }
3128: $datatable .=
3129: &usertype_update_row($settings,{'default' => $othertitle},
3130: \%fieldtitles,\@fields,['default'],
3131: \$numrows);
1.30 raeburn 3132: $$rowtotal ++;
1.3 raeburn 3133: }
3134: return $datatable;
3135: }
3136:
1.125 raeburn 3137: sub print_autocreate {
3138: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 3139: my (%createon,%createoff,%currhash);
1.125 raeburn 3140: my @types = ('xml','req');
3141: if (ref($settings) eq 'HASH') {
3142: foreach my $item (@types) {
3143: $createoff{$item} = ' checked="checked" ';
3144: $createon{$item} = ' ';
3145: if (exists($settings->{$item})) {
3146: if ($settings->{$item}) {
3147: $createon{$item} = ' checked="checked" ';
3148: $createoff{$item} = ' ';
3149: }
3150: }
3151: }
1.210 raeburn 3152: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 3153: $currhash{$settings->{'xmldc'}} = 1;
3154: }
1.125 raeburn 3155: } else {
3156: foreach my $item (@types) {
3157: $createoff{$item} = ' checked="checked" ';
3158: $createon{$item} = ' ';
3159: }
3160: }
3161: $$rowtotal += 2;
1.191 raeburn 3162: my $numinrow = 2;
1.125 raeburn 3163: my $datatable='<tr class="LC_odd_row">'.
3164: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3165: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3166: '<input type="radio" name="autocreate_xml"'.
3167: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3168: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 3169: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3170: '</td></tr><tr>'.
3171: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3172: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3173: '<input type="radio" name="autocreate_req"'.
3174: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3175: '<label><input type="radio" name="autocreate_req"'.
3176: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 3177: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3178: 'autocreate_xmldc',%currhash);
1.247 raeburn 3179: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 3180: if ($numdc > 1) {
1.247 raeburn 3181: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
3182: '</td><td class="LC_left_item">';
1.125 raeburn 3183: } else {
1.247 raeburn 3184: $datatable .= &mt('Course creation processed as:').
3185: '</td><td class="LC_right_item">';
1.125 raeburn 3186: }
1.247 raeburn 3187: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 3188: $$rowtotal += $rows;
1.125 raeburn 3189: return $datatable;
3190: }
3191:
1.23 raeburn 3192: sub print_directorysrch {
1.277 raeburn 3193: my ($position,$dom,$settings,$rowtotal) = @_;
3194: my $datatable;
3195: if ($position eq 'top') {
3196: my $instsrchon = ' ';
3197: my $instsrchoff = ' checked="checked" ';
3198: my ($exacton,$containson,$beginson);
3199: my $instlocalon = ' ';
3200: my $instlocaloff = ' checked="checked" ';
3201: if (ref($settings) eq 'HASH') {
3202: if ($settings->{'available'} eq '1') {
3203: $instsrchon = $instsrchoff;
3204: $instsrchoff = ' ';
3205: }
3206: if ($settings->{'localonly'} eq '1') {
3207: $instlocalon = $instlocaloff;
3208: $instlocaloff = ' ';
3209: }
3210: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
3211: foreach my $type (@{$settings->{'searchtypes'}}) {
3212: if ($type eq 'exact') {
3213: $exacton = ' checked="checked" ';
3214: } elsif ($type eq 'contains') {
3215: $containson = ' checked="checked" ';
3216: } elsif ($type eq 'begins') {
3217: $beginson = ' checked="checked" ';
3218: }
3219: }
3220: } else {
3221: if ($settings->{'searchtypes'} eq 'exact') {
3222: $exacton = ' checked="checked" ';
3223: } elsif ($settings->{'searchtypes'} eq 'contains') {
3224: $containson = ' checked="checked" ';
3225: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 3226: $exacton = ' checked="checked" ';
3227: $containson = ' checked="checked" ';
3228: }
3229: }
1.277 raeburn 3230: }
3231: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3232: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3233:
3234: my $numinrow = 4;
3235: my $cansrchrow = 0;
3236: $datatable='<tr class="LC_odd_row">'.
3237: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
3238: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3239: '<input type="radio" name="dirsrch_available"'.
3240: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
3241: '<label><input type="radio" name="dirsrch_available"'.
3242: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3243: '</tr><tr>'.
3244: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
3245: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3246: '<input type="radio" name="dirsrch_instlocalonly"'.
3247: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3248: '<label><input type="radio" name="dirsrch_instlocalonly"'.
3249: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3250: '</tr>';
3251: $$rowtotal += 2;
3252: if (ref($usertypes) eq 'HASH') {
3253: if (keys(%{$usertypes}) > 0) {
3254: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 3255: $numinrow,$othertitle,'cansearch',
3256: $rowtotal);
1.277 raeburn 3257: $cansrchrow = 1;
1.25 raeburn 3258: }
1.23 raeburn 3259: }
1.277 raeburn 3260: if ($cansrchrow) {
3261: $$rowtotal ++;
3262: $datatable .= '<tr>';
3263: } else {
3264: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 3265: }
1.277 raeburn 3266: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
3267: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
3268: foreach my $title (@{$titleorder}) {
3269: if (defined($searchtitles->{$title})) {
3270: my $check = ' ';
3271: if (ref($settings) eq 'HASH') {
3272: if (ref($settings->{'searchby'}) eq 'ARRAY') {
3273: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
3274: $check = ' checked="checked" ';
3275: }
1.39 raeburn 3276: }
1.25 raeburn 3277: }
1.277 raeburn 3278: $datatable .= '<td class="LC_left_item">'.
3279: '<span class="LC_nobreak"><label>'.
3280: '<input type="checkbox" name="searchby" '.
3281: 'value="'.$title.'"'.$check.'/>'.
3282: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 3283: }
3284: }
1.277 raeburn 3285: $datatable .= '</tr></table></td></tr>';
3286: $$rowtotal ++;
3287: if ($cansrchrow) {
3288: $datatable .= '<tr class="LC_odd_row">';
3289: } else {
3290: $datatable .= '<tr>';
3291: }
3292: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
3293: '<td class="LC_left_item" colspan="2">'.
3294: '<span class="LC_nobreak"><label>'.
3295: '<input type="checkbox" name="searchtypes" '.
3296: $exacton.' value="exact" />'.&mt('Exact match').
3297: '</label> '.
3298: '<label><input type="checkbox" name="searchtypes" '.
3299: $beginson.' value="begins" />'.&mt('Begins with').
3300: '</label> '.
3301: '<label><input type="checkbox" name="searchtypes" '.
3302: $containson.' value="contains" />'.&mt('Contains').
3303: '</label></span></td></tr>';
3304: $$rowtotal ++;
1.26 raeburn 3305: } else {
1.277 raeburn 3306: my $domsrchon = ' checked="checked" ';
3307: my $domsrchoff = ' ';
3308: my $domlocalon = ' ';
3309: my $domlocaloff = ' checked="checked" ';
3310: if (ref($settings) eq 'HASH') {
3311: if ($settings->{'lclocalonly'} eq '1') {
3312: $domlocalon = $domlocaloff;
3313: $domlocaloff = ' ';
3314: }
3315: if ($settings->{'lcavailable'} eq '0') {
3316: $domsrchoff = $domsrchon;
3317: $domsrchon = ' ';
3318: }
3319: }
3320: $datatable='<tr class="LC_odd_row">'.
3321: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
3322: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3323: '<input type="radio" name="dirsrch_domavailable"'.
3324: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
3325: '<label><input type="radio" name="dirsrch_domavailable"'.
3326: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3327: '</tr><tr>'.
3328: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
3329: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3330: '<input type="radio" name="dirsrch_domlocalonly"'.
3331: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3332: '<label><input type="radio" name="dirsrch_domlocalonly"'.
3333: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3334: '</tr>';
3335: $$rowtotal += 2;
1.26 raeburn 3336: }
1.25 raeburn 3337: return $datatable;
3338: }
3339:
1.28 raeburn 3340: sub print_contacts {
1.286 raeburn 3341: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 3342: my $datatable;
3343: my @contacts = ('adminemail','supportemail');
1.286 raeburn 3344: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340 raeburn 3345: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286 raeburn 3346: if ($position eq 'top') {
3347: if (ref($settings) eq 'HASH') {
3348: foreach my $item (@contacts) {
3349: if (exists($settings->{$item})) {
3350: $to{$item} = $settings->{$item};
3351: }
3352: }
3353: }
3354: } elsif ($position eq 'middle') {
3355: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
3356: 'updatesmail','idconflictsmail');
1.288 raeburn 3357: foreach my $type (@mailings) {
3358: $otheremails{$type} = '';
3359: }
1.340 raeburn 3360: } elsif ($position eq 'lower') {
3361: if (ref($settings) eq 'HASH') {
3362: if (ref($settings->{'lonstatus'}) eq 'HASH') {
3363: %lonstatus = %{$settings->{'lonstatus'}};
3364: }
3365: }
1.286 raeburn 3366: } else {
3367: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 3368: foreach my $type (@mailings) {
3369: $otheremails{$type} = '';
3370: }
1.286 raeburn 3371: $bccemails{'helpdeskmail'} = '';
3372: $bccemails{'otherdomsmail'} = '';
3373: $includestr{'helpdeskmail'} = '';
3374: $includestr{'otherdomsmail'} = '';
3375: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3376: }
1.28 raeburn 3377: if (ref($settings) eq 'HASH') {
1.340 raeburn 3378: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 3379: foreach my $type (@mailings) {
3380: if (exists($settings->{$type})) {
3381: if (ref($settings->{$type}) eq 'HASH') {
3382: foreach my $item (@contacts) {
3383: if ($settings->{$type}{$item}) {
3384: $checked{$type}{$item} = ' checked="checked" ';
3385: }
3386: }
3387: $otheremails{$type} = $settings->{$type}{'others'};
3388: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3389: $bccemails{$type} = $settings->{$type}{'bcc'};
3390: if ($settings->{$type}{'include'} ne '') {
3391: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3392: $includestr{$type} = &unescape($includestr{$type});
3393: }
3394: }
3395: }
3396: } elsif ($type eq 'lonstatusmail') {
3397: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3398: }
1.28 raeburn 3399: }
3400: }
1.286 raeburn 3401: if ($position eq 'bottom') {
3402: foreach my $type (@mailings) {
3403: $bccemails{$type} = $settings->{$type}{'bcc'};
3404: if ($settings->{$type}{'include'} ne '') {
3405: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3406: $includestr{$type} = &unescape($includestr{$type});
3407: }
3408: }
3409: if (ref($settings->{'helpform'}) eq 'HASH') {
3410: if (ref($fields) eq 'ARRAY') {
3411: foreach my $field (@{$fields}) {
3412: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3413: }
1.286 raeburn 3414: }
3415: if (exists($settings->{'helpform'}{'maxsize'})) {
3416: $maxsize = $settings->{'helpform'}{'maxsize'};
3417: } else {
1.289 raeburn 3418: $maxsize = '1.0';
1.286 raeburn 3419: }
3420: } else {
3421: if (ref($fields) eq 'ARRAY') {
3422: foreach my $field (@{$fields}) {
3423: $currfield{$field} = 'yes';
1.134 raeburn 3424: }
1.28 raeburn 3425: }
1.286 raeburn 3426: $maxsize = '1.0';
1.28 raeburn 3427: }
3428: }
3429: } else {
1.286 raeburn 3430: if ($position eq 'top') {
3431: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3432: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3433: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3434: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 3435: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 3436: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3437: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3438: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
3439: } elsif ($position eq 'bottom') {
3440: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3441: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3442: if (ref($fields) eq 'ARRAY') {
3443: foreach my $field (@{$fields}) {
3444: $currfield{$field} = 'yes';
3445: }
3446: }
3447: $maxsize = '1.0';
3448: }
1.28 raeburn 3449: }
3450: my ($titles,$short_titles) = &contact_titles();
3451: my $rownum = 0;
3452: my $css_class;
1.286 raeburn 3453: if ($position eq 'top') {
3454: foreach my $item (@contacts) {
3455: $css_class = $rownum%2?' class="LC_odd_row"':'';
3456: $datatable .= '<tr'.$css_class.'>'.
3457: '<td><span class="LC_nobreak">'.$titles->{$item}.
3458: '</span></td><td class="LC_right_item">'.
3459: '<input type="text" name="'.$item.'" value="'.
3460: $to{$item}.'" /></td></tr>';
3461: $rownum ++;
3462: }
1.315 raeburn 3463: } elsif ($position eq 'bottom') {
3464: $css_class = $rownum%2?' class="LC_odd_row"':'';
3465: $datatable .= '<tr'.$css_class.'>'.
3466: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3467: &mt('(e-mail, subject, and description always shown)').
3468: '</td><td class="LC_left_item">';
3469: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3470: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3471: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3472: foreach my $field (@{$fields}) {
3473: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3474: if (($field eq 'screenshot') || ($field eq 'cc')) {
3475: $datatable .= ' '.&mt('(logged-in users)');
3476: }
3477: $datatable .='</td><td>';
3478: my $clickaction;
3479: if ($field eq 'screenshot') {
3480: $clickaction = ' onclick="screenshotSize(this);"';
3481: }
3482: if (ref($possoptions->{$field}) eq 'ARRAY') {
3483: foreach my $option (@{$possoptions->{$field}}) {
3484: my $checked;
3485: if ($currfield{$field} eq $option) {
3486: $checked = ' checked="checked"';
3487: }
3488: $datatable .= '<span class="LC_nobreak"><label>'.
3489: '<input type="radio" name="helpform_'.$field.'" '.
3490: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3491: '</label></span>'.(' 'x2);
3492: }
3493: }
3494: if ($field eq 'screenshot') {
3495: my $display;
3496: if ($currfield{$field} eq 'no') {
3497: $display = ' style="display:none"';
3498: }
1.334 raeburn 3499: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 3500: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3501: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3502: }
3503: $datatable .= '</td></tr>';
3504: }
3505: $datatable .= '</table>';
3506: }
3507: $datatable .= '</td></tr>'."\n";
3508: $rownum ++;
3509: }
1.340 raeburn 3510: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 3511: foreach my $type (@mailings) {
3512: $css_class = $rownum%2?' class="LC_odd_row"':'';
3513: $datatable .= '<tr'.$css_class.'>'.
3514: '<td><span class="LC_nobreak">'.
3515: $titles->{$type}.': </span></td>'.
3516: '<td class="LC_left_item">';
3517: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3518: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3519: }
3520: $datatable .= '<span class="LC_nobreak">';
3521: foreach my $item (@contacts) {
3522: $datatable .= '<label>'.
3523: '<input type="checkbox" name="'.$type.'"'.
3524: $checked{$type}{$item}.
3525: ' value="'.$item.'" />'.$short_titles->{$item}.
3526: '</label> ';
3527: }
3528: $datatable .= '</span><br />'.&mt('Others').': '.
3529: '<input type="text" name="'.$type.'_others" '.
3530: 'value="'.$otheremails{$type}.'" />';
3531: my %locchecked;
3532: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3533: foreach my $loc ('s','b') {
3534: if ($includeloc{$type} eq $loc) {
3535: $locchecked{$loc} = ' checked="checked"';
3536: last;
3537: }
3538: }
3539: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3540: '<input type="text" name="'.$type.'_bcc" '.
3541: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3542: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3543: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 3544: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 3545: '<span class="LC_nobreak">'.&mt('Location:').' '.
3546: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3547: (' 'x2).
3548: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3549: '</span></fieldset>';
3550: }
3551: $datatable .= '</td></tr>'."\n";
3552: $rownum ++;
3553: }
1.28 raeburn 3554: }
1.286 raeburn 3555: if ($position eq 'middle') {
3556: my %choices;
1.340 raeburn 3557: my $corelink = &core_link_msu();
3558: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286 raeburn 3559: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340 raeburn 3560: $corelink);
3561: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
3562: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286 raeburn 3563: my %defaultchecked = ('reporterrors' => 'on',
1.340 raeburn 3564: 'reportupdates' => 'on',
3565: 'reportstatus' => 'on');
1.286 raeburn 3566: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3567: \%choices,$rownum);
3568: $datatable .= $reports;
1.340 raeburn 3569: } elsif ($position eq 'lower') {
3570: $css_class = $rownum%2?' class="LC_odd_row"':'';
3571: my ($threshold,$sysmail,%excluded,%weights);
3572: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
3573: if ($lonstatus{'threshold'} =~ /^\d+$/) {
3574: $threshold = $lonstatus{'threshold'};
3575: } else {
3576: $threshold = $defaults->{'threshold'};
3577: }
3578: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
3579: $sysmail = $lonstatus{'sysmail'};
3580: } else {
3581: $sysmail = $defaults->{'sysmail'};
3582: }
3583: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 3584: foreach my $type ('E','W','N','U') {
1.340 raeburn 3585: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
3586: $weights{$type} = $lonstatus{'weights'}{$type};
3587: } else {
3588: $weights{$type} = $defaults->{$type};
3589: }
3590: }
3591: } else {
1.341 raeburn 3592: foreach my $type ('E','W','N','U') {
1.340 raeburn 3593: $weights{$type} = $defaults->{$type};
3594: }
3595: }
3596: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
3597: if (@{$lonstatus{'excluded'}} > 0) {
3598: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
3599: }
3600: }
3601: $datatable .= '<tr'.$css_class.'>'.
3602: '<td class="LC_left_item"><span class="LC_nobreak">'.
3603: $titles->{'errorthreshold'}.
3604: '</span></td><td class="LC_left_item">'.
3605: '<input type="text" name="errorthreshold" value="'.
3606: $threshold.'" size="5" /></td></tr>';
3607: $rownum ++;
3608: $css_class = $rownum%2?' class="LC_odd_row"':'';
3609: $datatable .= '<tr'.$css_class.'>'.
3610: '<td class="LC_left_item">'.
3611: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
3612: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 3613: foreach my $type ('E','W','N','U') {
1.340 raeburn 3614: $datatable .= '<td>'.$names->{$type}.'<br />'.
3615: '<input type="text" name="errorweights_'.$type.'" value="'.
3616: $weights{$type}.'" size="5" /></td>';
3617: }
3618: $datatable .= '</tr></table></tr>';
3619: $rownum ++;
3620: $css_class = $rownum%2?' class="LC_odd_row"':'';
3621: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
3622: $titles->{'errorexcluded'}.'</td>'.
3623: '<td class="LC_left_item"><table>';
3624: my $numinrow = 4;
3625: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
3626: for (my $i=0; $i<@ids; $i++) {
3627: my $rem = $i%($numinrow);
3628: if ($rem == 0) {
3629: if ($i > 0) {
3630: $datatable .= '</tr>';
3631: }
3632: $datatable .= '<tr>';
3633: }
3634: my $check;
3635: if ($excluded{$ids[$i]}) {
3636: $check = ' checked="checked" ';
3637: }
3638: $datatable .= '<td class="LC_left_item">'.
3639: '<span class="LC_nobreak"><label>'.
3640: '<input type="checkbox" name="errorexcluded" '.
3641: 'value="'.$ids[$i].'"'.$check.' />'.
3642: $ids[$i].'</label></span></td>';
3643: }
3644: my $colsleft = $numinrow - @ids%($numinrow);
3645: if ($colsleft > 1 ) {
3646: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3647: ' </td>';
3648: } elsif ($colsleft == 1) {
3649: $datatable .= '<td class="LC_left_item"> </td>';
3650: }
3651: $datatable .= '</tr></table></td></tr>';
3652: $rownum ++;
3653: $css_class = $rownum%2?' class="LC_odd_row"':'';
3654: $datatable .= '<tr'.$css_class.'>'.
3655: '<td class="LC_left_item"><span class="LC_nobreak">'.
3656: $titles->{'errorsysmail'}.
3657: '</span></td><td class="LC_left_item">'.
3658: '<input type="text" name="errorsysmail" value="'.
3659: $sysmail.'" size="5" /></td></tr>';
3660: $rownum ++;
1.286 raeburn 3661: } elsif ($position eq 'bottom') {
1.315 raeburn 3662: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3663: my (@posstypes,%usertypeshash);
3664: if (ref($types) eq 'ARRAY') {
3665: @posstypes = @{$types};
3666: }
3667: if (@posstypes) {
3668: if (ref($usertypes) eq 'HASH') {
3669: %usertypeshash = %{$usertypes};
3670: }
3671: my @overridden;
3672: my $numinrow = 4;
3673: if (ref($settings) eq 'HASH') {
3674: if (ref($settings->{'overrides'}) eq 'HASH') {
3675: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
3676: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
3677: push(@overridden,$key);
3678: foreach my $item (@contacts) {
3679: if ($settings->{'overrides'}{$key}{$item}) {
3680: $checked{'override_'.$key}{$item} = ' checked="checked" ';
3681: }
3682: }
3683: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
3684: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
3685: $includeloc{'override_'.$key} = '';
3686: $includestr{'override_'.$key} = '';
3687: if ($settings->{'overrides'}{$key}{'include'} ne '') {
3688: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
3689: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
3690: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
3691: }
1.286 raeburn 3692: }
3693: }
3694: }
1.315 raeburn 3695: }
3696: my $customclass = 'LC_helpdesk_override';
3697: my $optionsprefix = 'LC_options_helpdesk_';
3698:
3699: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
3700:
3701: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
3702: $numinrow,$othertitle,'overrides',
3703: \$rownum,$onclicktypes,$customclass);
3704: $rownum ++;
3705: $usertypeshash{'default'} = $othertitle;
3706: foreach my $status (@posstypes) {
3707: my $css_class;
3708: if ($rownum%2) {
3709: $css_class = 'LC_odd_row ';
3710: }
3711: $css_class .= $customclass;
3712: my $rowid = $optionsprefix.$status;
3713: my $hidden = 1;
3714: my $currstyle = 'display:none';
3715: if (grep(/^\Q$status\E$/,@overridden)) {
3716: $currstyle = 'display:table-row';
3717: $hidden = 0;
3718: }
3719: my $key = 'override_'.$status;
3720: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
3721: $includeloc{$key},$includestr{$key},$status,$rowid,
3722: $usertypeshash{$status},$css_class,$currstyle,
3723: \@contacts,$short_titles);
3724: unless ($hidden) {
3725: $rownum ++;
1.286 raeburn 3726: }
3727: }
1.134 raeburn 3728: }
1.28 raeburn 3729: }
1.30 raeburn 3730: $$rowtotal += $rownum;
1.28 raeburn 3731: return $datatable;
3732: }
3733:
1.340 raeburn 3734: sub core_link_msu {
3735: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3736: &mt('LON-CAPA core group - MSU'),600,500);
3737: }
3738:
1.315 raeburn 3739: sub overridden_helpdesk {
3740: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
3741: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
3742: my $class = 'LC_left_item';
3743: if ($css_class) {
3744: $css_class = ' class="'.$css_class.'"';
3745: }
3746: if ($rowid) {
3747: $rowid = ' id="'.$rowid.'"';
3748: }
3749: if ($rowstyle) {
3750: $rowstyle = ' style="'.$rowstyle.'"';
3751: }
3752: my ($output,$description);
3753: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
3754: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
3755: "<td>$description</td>\n".
3756: '<td class="'.$class.'" colspan="2">'.
3757: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
3758: '<span class="LC_nobreak">';
3759: if (ref($contacts) eq 'ARRAY') {
3760: foreach my $item (@{$contacts}) {
3761: my $check;
3762: if (ref($checked) eq 'HASH') {
3763: $check = $checked->{$item};
3764: }
3765: my $title;
3766: if (ref($short_titles) eq 'HASH') {
3767: $title = $short_titles->{$item};
3768: }
3769: $output .= '<label>'.
3770: '<input type="checkbox" name="override_'.$type.'"'.$check.
3771: ' value="'.$item.'" />'.$title.'</label> ';
3772: }
3773: }
3774: $output .= '</span><br />'.&mt('Others').': '.
3775: '<input type="text" name="override_'.$type.'_others" '.
3776: 'value="'.$otheremails.'" />';
3777: my %locchecked;
3778: foreach my $loc ('s','b') {
3779: if ($includeloc eq $loc) {
3780: $locchecked{$loc} = ' checked="checked"';
3781: last;
3782: }
3783: }
3784: $output .= '<br />'.&mt('Bcc:').(' 'x6).
3785: '<input type="text" name="override_'.$type.'_bcc" '.
3786: 'value="'.$bccemails.'" /></fieldset>'.
3787: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3788: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 3789: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 3790: '<span class="LC_nobreak">'.&mt('Location:').' '.
3791: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3792: (' 'x2).
3793: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3794: '</span></fieldset>'.
3795: '</td></tr>'."\n";
3796: return $output;
3797: }
3798:
1.286 raeburn 3799: sub contacts_javascript {
3800: return <<"ENDSCRIPT";
3801:
3802: <script type="text/javascript">
3803: // <![CDATA[
3804:
3805: function screenshotSize(field) {
3806: if (document.getElementById('help_screenshotsize')) {
3807: if (field.value == 'no') {
1.289 raeburn 3808: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 3809: } else {
3810: document.getElementById('help_screenshotsize').style.display="";
3811: }
3812: }
3813: return;
3814: }
3815:
1.315 raeburn 3816: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
3817: if (form.elements[checkbox].length != undefined) {
3818: var count = 0;
3819: if (docount) {
3820: for (var i=0; i<form.elements[checkbox].length; i++) {
3821: if (form.elements[checkbox][i].checked) {
3822: count ++;
3823: }
3824: }
3825: }
3826: for (var i=0; i<form.elements[checkbox].length; i++) {
3827: var type = form.elements[checkbox][i].value;
3828: if (document.getElementById(prefix+type)) {
3829: if (form.elements[checkbox][i].checked) {
3830: document.getElementById(prefix+type).style.display = 'table-row';
3831: if (count % 2 == 1) {
3832: document.getElementById(prefix+type).className = target+' LC_odd_row';
3833: } else {
3834: document.getElementById(prefix+type).className = target;
3835: }
3836: count ++;
3837: } else {
3838: document.getElementById(prefix+type).style.display = 'none';
3839: }
3840: }
3841: }
3842: }
3843: return;
3844: }
3845:
3846:
1.286 raeburn 3847: // ]]>
3848: </script>
3849:
3850: ENDSCRIPT
3851: }
3852:
1.118 jms 3853: sub print_helpsettings {
1.282 raeburn 3854: my ($position,$dom,$settings,$rowtotal) = @_;
3855: my $confname = $dom.'-domainconfig';
1.285 raeburn 3856: my $formname = 'display';
1.168 raeburn 3857: my ($datatable,$itemcount);
1.282 raeburn 3858: if ($position eq 'top') {
3859: $itemcount = 1;
3860: my (%choices,%defaultchecked,@toggles);
3861: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3862: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3863: &mt('LON-CAPA bug tracker'),600,500));
3864: %defaultchecked = ('submitbugs' => 'on');
3865: @toggles = ('submitbugs');
3866: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3867: \%choices,$itemcount);
3868: $$rowtotal ++;
3869: } else {
3870: my $css_class;
3871: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 3872: my (%customroles,%ordered,%current);
1.301 raeburn 3873: if (ref($settings) eq 'HASH') {
3874: if (ref($settings->{'adhoc'}) eq 'HASH') {
3875: %current = %{$settings->{'adhoc'}};
3876: }
1.285 raeburn 3877: }
3878: my $count = 0;
3879: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 3880: if ($key=~/^rolesdef\_(\w+)$/) {
3881: my $rolename = $1;
1.285 raeburn 3882: my (%privs,$order);
1.282 raeburn 3883: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3884: $customroles{$rolename} = \%privs;
1.285 raeburn 3885: if (ref($current{$rolename}) eq 'HASH') {
3886: $order = $current{$rolename}{'order'};
3887: }
3888: if ($order eq '') {
3889: $order = $count;
3890: }
3891: $ordered{$order} = $rolename;
3892: $count++;
3893: }
3894: }
3895: my $maxnum = scalar(keys(%ordered));
3896: my @roles_by_num = ();
3897: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3898: push(@roles_by_num,$item);
3899: }
3900: my $context = 'domprefs';
3901: my $crstype = 'Course';
3902: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 3903: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 3904: my ($numstatustypes,@jsarray);
3905: if (ref($types) eq 'ARRAY') {
3906: if (@{$types} > 0) {
3907: $numstatustypes = scalar(@{$types});
3908: push(@accesstypes,'status');
3909: @jsarray = ('bystatus');
1.282 raeburn 3910: }
3911: }
1.290 raeburn 3912: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 3913: if (keys(%domhelpdesk)) {
3914: push(@accesstypes,('inc','exc'));
3915: push(@jsarray,('notinc','notexc'));
3916: }
3917: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 3918: my $context = 'domprefs';
3919: my $crstype = 'Course';
1.285 raeburn 3920: my $prefix = 'helproles_';
3921: my $add_class = 'LC_hidden';
3922: foreach my $num (@roles_by_num) {
3923: my $role = $ordered{$num};
3924: my ($desc,$access,@statuses);
3925: if (ref($current{$role}) eq 'HASH') {
3926: $desc = $current{$role}{'desc'};
3927: $access = $current{$role}{'access'};
3928: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3929: @statuses = @{$current{$role}{'insttypes'}};
3930: }
3931: }
3932: if ($desc eq '') {
3933: $desc = $role;
3934: }
3935: my $identifier = 'custhelp'.$num;
1.282 raeburn 3936: my %full=();
3937: my %levels= (
3938: course => {},
3939: domain => {},
3940: system => {},
3941: );
3942: my %levelscurrent=(
3943: course => {},
3944: domain => {},
3945: system => {},
3946: );
3947: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3948: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3949: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 3950: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 3951: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 3952: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3953: for (my $k=0; $k<=$maxnum; $k++) {
3954: my $vpos = $k+1;
3955: my $selstr;
3956: if ($k == $num) {
3957: $selstr = ' selected="selected" ';
3958: }
3959: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3960: }
3961: $datatable .= '</select>'.(' 'x2).
3962: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3963: '</td>'.
3964: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3965: &mt('Name shown to users:').
3966: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3967: '</fieldset>'.
3968: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3969: $othertitle,$usertypes,$types,\%domhelpdesk).
3970: '<fieldset>'.
3971: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 3972: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 3973: \%levelscurrent,$identifier,
3974: 'LC_hidden',$prefix.$num.'_privs').
3975: '</fieldset></td>';
1.282 raeburn 3976: $itemcount ++;
3977: }
3978: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3979: my $newcust = 'custhelp'.$count;
3980: my (%privs,%levelscurrent);
3981: my %full=();
3982: my %levels= (
3983: course => {},
3984: domain => {},
3985: system => {},
3986: );
3987: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3988: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 3989: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 3990: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 3991: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3992: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3993: for (my $k=0; $k<$maxnum+1; $k++) {
3994: my $vpos = $k+1;
3995: my $selstr;
3996: if ($k == $maxnum) {
3997: $selstr = ' selected="selected" ';
3998: }
3999: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4000: }
4001: $datatable .= '</select> '."\n".
1.282 raeburn 4002: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
4003: '</label></span></td>'.
1.285 raeburn 4004: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4005: '<span class="LC_nobreak">'.
4006: &mt('Internal name:').
4007: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
4008: '</span>'.(' 'x4).
4009: '<span class="LC_nobreak">'.
4010: &mt('Name shown to users:').
4011: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
4012: '</span></fieldset>'.
4013: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
4014: $usertypes,$types,\%domhelpdesk).
4015: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 4016: &Apache::lonuserutils::custom_role_header($context,$crstype,
4017: \@templateroles,$newcust).
4018: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
4019: \%levelscurrent,$newcust).
1.334 raeburn 4020: '</fieldset>'.
4021: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
4022: '</td></tr>';
1.282 raeburn 4023: $count ++;
4024: $$rowtotal += $count;
4025: }
1.166 raeburn 4026: return $datatable;
1.121 raeburn 4027: }
4028:
1.285 raeburn 4029: sub adhocbutton {
4030: my ($prefix,$num,$field,$visibility) = @_;
4031: my %lt = &Apache::lonlocal::texthash(
4032: show => 'Show details',
4033: hide => 'Hide details',
4034: );
4035: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
4036: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
4037: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
4038: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
4039: }
4040:
4041: sub helpsettings_javascript {
4042: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
4043: return unless(ref($roles_by_num) eq 'ARRAY');
4044: my %html_js_lt = &Apache::lonlocal::texthash(
4045: show => 'Show details',
4046: hide => 'Hide details',
4047: );
4048: &html_escape(\%html_js_lt);
4049: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
4050: return <<"ENDSCRIPT";
4051: <script type="text/javascript">
4052: // <![CDATA[
4053:
4054: function reorderHelpRoles(form,item) {
4055: var changedVal;
4056: $jstext
4057: var newpos = 'helproles_${total}_pos';
4058: var maxh = 1 + $total;
4059: var current = new Array();
4060: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4061: if (item == newpos) {
4062: changedVal = newitemVal;
4063: } else {
4064: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4065: current[newitemVal] = newpos;
4066: }
4067: for (var i=0; i<helproles.length; i++) {
4068: var elementName = 'helproles_'+helproles[i]+'_pos';
4069: if (elementName != item) {
4070: if (form.elements[elementName]) {
4071: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4072: current[currVal] = elementName;
4073: }
4074: }
4075: }
4076: var oldVal;
4077: for (var j=0; j<maxh; j++) {
4078: if (current[j] == undefined) {
4079: oldVal = j;
4080: }
4081: }
4082: if (oldVal < changedVal) {
4083: for (var k=oldVal+1; k<=changedVal ; k++) {
4084: var elementName = current[k];
4085: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4086: }
4087: } else {
4088: for (var k=changedVal; k<oldVal; k++) {
4089: var elementName = current[k];
4090: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4091: }
4092: }
4093: return;
4094: }
4095:
4096: function helpdeskAccess(num) {
4097: var curraccess = null;
4098: if (document.$formname.elements['helproles_'+num+'_access'].length) {
4099: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
4100: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
4101: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
4102: }
4103: }
4104: }
4105: var shown = Array();
4106: var hidden = Array();
4107: if (curraccess == 'none') {
4108: hidden = Array('$hiddenstr');
4109: } else {
4110: if (curraccess == 'status') {
4111: shown = Array('bystatus');
4112: hidden = Array('notinc','notexc');
4113: } else {
4114: if (curraccess == 'exc') {
4115: shown = Array('notexc');
4116: hidden = Array('notinc','bystatus');
4117: }
4118: if (curraccess == 'inc') {
4119: shown = Array('notinc');
4120: hidden = Array('notexc','bystatus');
4121: }
1.293 raeburn 4122: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 4123: hidden = Array('notinc','notexc','bystatus');
4124: }
4125: }
4126: }
4127: if (hidden.length > 0) {
4128: for (var i=0; i<hidden.length; i++) {
4129: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
4130: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
4131: }
4132: }
4133: }
4134: if (shown.length > 0) {
4135: for (var i=0; i<shown.length; i++) {
4136: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
4137: if (shown[i] == 'privs') {
4138: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4139: } else {
4140: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4141: }
4142: }
4143: }
4144: }
4145: return;
4146: }
4147:
4148: function toggleHelpdeskItem(num,field) {
4149: if (document.getElementById('helproles_'+num+'_'+field)) {
4150: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 4151: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 4152: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4153: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4154: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4155: }
4156: } else {
4157: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4158: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4159: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4160: }
4161: }
4162: }
4163: return;
4164: }
4165:
4166: // ]]>
4167: </script>
4168:
4169: ENDSCRIPT
4170: }
4171:
4172: sub helpdeskroles_access {
4173: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4174: $usertypes,$types,$domhelpdesk) = @_;
4175: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
4176: my %lt = &Apache::lonlocal::texthash(
4177: 'rou' => 'Role usage',
4178: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 4179: 'all' => 'All with domain helpdesk or helpdesk assistant role',
4180: 'dh' => 'All with domain helpdesk role',
4181: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 4182: 'none' => 'None',
4183: 'status' => 'Determined based on institutional status',
4184: 'inc' => 'Include all, but exclude specific personnel',
4185: 'exc' => 'Exclude all, but include specific personnel',
4186: );
4187: my %usecheck = (
4188: all => ' checked="checked"',
4189: );
4190: my %displaydiv = (
4191: status => 'none',
4192: inc => 'none',
4193: exc => 'none',
4194: priv => 'block',
4195: );
4196: my $output;
4197: if (ref($current) eq 'HASH') {
4198: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
4199: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
4200: $usecheck{$current->{access}} = $usecheck{'all'};
4201: delete($usecheck{'all'});
4202: if ($current->{access} =~ /^(status|inc|exc)$/) {
4203: my $access = $1;
4204: $displaydiv{$access} = 'inline';
4205: } elsif ($current->{access} eq 'none') {
4206: $displaydiv{'priv'} = 'none';
4207: }
4208: }
4209: }
4210: }
4211: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
4212: '<p>'.$lt{'whi'}.'</p>';
4213: foreach my $access (@{$accesstypes}) {
4214: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
4215: ' onclick="helpdeskAccess('."'$num'".');" />'.
4216: $lt{$access}.'</label>';
4217: if ($access eq 'status') {
4218: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
4219: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
4220: $othertitle,$usertypes,$types).
4221: '</div>';
4222: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
4223: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
4224: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4225: '</div>';
4226: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
4227: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
4228: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4229: '</div>';
4230: }
4231: $output .= '</p>';
4232: }
4233: $output .= '</fieldset>';
4234: return $output;
4235: }
4236:
1.121 raeburn 4237: sub radiobutton_prefs {
1.192 raeburn 4238: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 4239: $additional,$align) = @_;
1.121 raeburn 4240: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
4241: (ref($choices) eq 'HASH'));
4242:
1.170 raeburn 4243: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 4244:
4245: foreach my $item (@{$toggles}) {
4246: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 4247: $checkedon{$item} = ' checked="checked" ';
4248: $checkedoff{$item} = ' ';
1.121 raeburn 4249: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 4250: $checkedoff{$item} = ' checked="checked" ';
4251: $checkedon{$item} = ' ';
4252: }
4253: }
4254: if (ref($settings) eq 'HASH') {
1.121 raeburn 4255: foreach my $item (@{$toggles}) {
1.118 jms 4256: if ($settings->{$item} eq '1') {
4257: $checkedon{$item} = ' checked="checked" ';
4258: $checkedoff{$item} = ' ';
4259: } elsif ($settings->{$item} eq '0') {
4260: $checkedoff{$item} = ' checked="checked" ';
4261: $checkedon{$item} = ' ';
4262: }
4263: }
1.121 raeburn 4264: }
1.192 raeburn 4265: if ($onclick) {
4266: $onclick = ' onclick="'.$onclick.'"';
4267: }
1.121 raeburn 4268: foreach my $item (@{$toggles}) {
1.118 jms 4269: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 4270: $datatable .=
1.306 raeburn 4271: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 4272: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 4273: '</span></td>';
4274: if ($align eq 'left') {
4275: $datatable .= '<td class="LC_left_item">';
4276: } else {
4277: $datatable .= '<td class="LC_right_item">';
4278: }
1.289 raeburn 4279: $datatable .=
1.257 raeburn 4280: '<span class="LC_nobreak">'.
1.118 jms 4281: '<label><input type="radio" name="'.
1.192 raeburn 4282: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 4283: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 4284: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
4285: '</span>'.$additional.
4286: '</td>'.
1.118 jms 4287: '</tr>';
4288: $itemcount ++;
1.121 raeburn 4289: }
4290: return ($datatable,$itemcount);
4291: }
4292:
1.267 raeburn 4293: sub print_ltitools {
4294: my ($dom,$settings,$rowtotal) = @_;
4295: my $rownum = 0;
4296: my $css_class;
4297: my $itemcount = 1;
4298: my $maxnum = 0;
4299: my %ordered;
4300: if (ref($settings) eq 'HASH') {
4301: foreach my $item (keys(%{$settings})) {
4302: if (ref($settings->{$item}) eq 'HASH') {
4303: my $num = $settings->{$item}{'order'};
4304: $ordered{$num} = $item;
4305: }
4306: }
4307: }
4308: my $confname = $dom.'-domainconfig';
4309: my $switchserver = &check_switchserver($dom,$confname);
4310: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 4311: my $datatable;
1.267 raeburn 4312: my %lt = <itools_names();
4313: my @courseroles = ('cc','in','ta','ep','st');
4314: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1.324 raeburn 4315: my @fields = ('fullname','firstname','lastname','email','roles','user');
1.267 raeburn 4316: if (keys(%ordered)) {
4317: my @items = sort { $a <=> $b } keys(%ordered);
4318: for (my $i=0; $i<@items; $i++) {
4319: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4320: my $item = $ordered{$items[$i]};
1.323 raeburn 4321: my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
1.267 raeburn 4322: if (ref($settings->{$item}) eq 'HASH') {
4323: $title = $settings->{$item}->{'title'};
4324: $url = $settings->{$item}->{'url'};
4325: $key = $settings->{$item}->{'key'};
4326: $secret = $settings->{$item}->{'secret'};
1.322 raeburn 4327: $lifetime = $settings->{$item}->{'lifetime'};
1.267 raeburn 4328: my $image = $settings->{$item}->{'image'};
4329: if ($image ne '') {
4330: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
4331: }
1.323 raeburn 4332: if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
4333: $sigsel{'HMAC-256'} = ' selected="selected"';
4334: } else {
4335: $sigsel{'HMAC-SHA1'} = ' selected="selected"';
4336: }
1.267 raeburn 4337: }
1.319 raeburn 4338: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1.267 raeburn 4339: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4340: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
4341: for (my $k=0; $k<=$maxnum; $k++) {
4342: my $vpos = $k+1;
4343: my $selstr;
4344: if ($k == $i) {
4345: $selstr = ' selected="selected" ';
4346: }
4347: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4348: }
4349: $datatable .= '</select>'.(' 'x2).
4350: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
4351: &mt('Delete?').'</label></span></td>'.
4352: '<td colspan="2">'.
4353: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4354: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
1.267 raeburn 4355: (' 'x2).
4356: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
4357: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4358: (' 'x2).
4359: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
4360: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4361: (' 'x2).
4362: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
4363: '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
4364: '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
1.267 raeburn 4365: '<br /><br />'.
1.323 raeburn 4366: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
1.267 raeburn 4367: ' value="'.$url.'" /></span>'.
4368: (' 'x2).
1.319 raeburn 4369: '<span class="LC_nobreak">'.$lt{'key'}.':'.
1.267 raeburn 4370: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
4371: (' 'x2).
1.322 raeburn 4372: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
4373: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
4374: (' 'x2).
1.267 raeburn 4375: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4376: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
4377: '<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>'.
4378: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
4379: '</fieldset>'.
4380: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4381: '<span class="LC_nobreak">'.&mt('Display target:');
4382: my %currdisp;
4383: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
4384: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
4385: $currdisp{'window'} = ' checked="checked"';
1.298 raeburn 4386: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
4387: $currdisp{'tab'} = ' checked="checked"';
1.267 raeburn 4388: } else {
4389: $currdisp{'iframe'} = ' checked="checked"';
4390: }
4391: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
4392: $currdisp{'width'} = $1;
4393: }
4394: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
4395: $currdisp{'height'} = $1;
4396: }
1.296 raeburn 4397: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
4398: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267 raeburn 4399: } else {
4400: $currdisp{'iframe'} = ' checked="checked"';
4401: }
1.298 raeburn 4402: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4403: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
4404: $lt{$disp}.'</label>'.(' 'x2);
4405: }
4406: $datatable .= (' 'x4);
4407: foreach my $dimen ('width','height') {
4408: $datatable .= '<label>'.$lt{$dimen}.' '.
4409: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
4410: (' 'x2);
4411: }
1.334 raeburn 4412: $datatable .= '</span><br />'.
1.296 raeburn 4413: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 4414: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
1.296 raeburn 4415: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4416: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
4417: '</textarea></div><div style=""></div><br />';
1.319 raeburn 4418: my %units = (
4419: 'passback' => 'days',
4420: 'roster' => 'seconds',
4421: );
1.267 raeburn 4422: foreach my $extra ('passback','roster') {
1.319 raeburn 4423: my $validsty = 'none';
4424: my $currvalid;
1.267 raeburn 4425: my $checkedon = '';
4426: my $checkedoff = ' checked="checked"';
4427: if ($settings->{$item}->{$extra}) {
4428: $checkedon = $checkedoff;
4429: $checkedoff = '';
1.319 raeburn 4430: $validsty = 'inline-block';
4431: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
4432: $currvalid = $settings->{$item}->{$extra.'valid'};
4433: }
4434: }
4435: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
4436: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4437: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
4438: &mt('No').'</label>'.(' 'x2).
4439: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
4440: &mt('Yes').'</label></span></div>'.
4441: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
4442: '<span class="LC_nobreak">'.
4443: &mt("at least [_1] $units{$extra} after launch",
4444: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
4445: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4446: }
1.319 raeburn 4447: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
1.267 raeburn 4448: if ($imgsrc) {
4449: $datatable .= $imgsrc.
4450: '<label><input type="checkbox" name="ltitools_image_del"'.
4451: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
4452: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
4453: } else {
4454: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4455: }
4456: if ($switchserver) {
4457: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4458: } else {
4459: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
4460: }
4461: $datatable .= '</span></fieldset>';
1.324 raeburn 4462: my (%checkedfields,%rolemaps,$userincdom);
1.267 raeburn 4463: if (ref($settings->{$item}) eq 'HASH') {
4464: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
4465: %checkedfields = %{$settings->{$item}->{'fields'}};
4466: }
1.324 raeburn 4467: $userincdom = $settings->{$item}->{'incdom'};
1.267 raeburn 4468: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
4469: %rolemaps = %{$settings->{$item}->{'roles'}};
4470: $checkedfields{'roles'} = 1;
4471: }
4472: }
4473: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4474: '<span class="LC_nobreak">';
1.324 raeburn 4475: my $userfieldstyle = 'display:none;';
4476: my $seluserdom = '';
4477: my $unseluserdom = ' selected="selected"';
1.267 raeburn 4478: foreach my $field (@fields) {
1.324 raeburn 4479: my ($checked,$onclick,$id,$spacer);
1.267 raeburn 4480: if ($checkedfields{$field}) {
4481: $checked = ' checked="checked"';
4482: }
1.324 raeburn 4483: if ($field eq 'user') {
4484: $id = ' id="ltitools_user_field_'.$i.'"';
4485: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
4486: if ($checked) {
4487: $userfieldstyle = 'display:inline-block';
4488: if ($userincdom) {
4489: $seluserdom = $unseluserdom;
4490: $unseluserdom = '';
4491: }
4492: }
4493: } else {
4494: $spacer = (' ' x2);
4495: }
1.267 raeburn 4496: $datatable .= '<label>'.
1.324 raeburn 4497: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
4498: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 4499: }
1.324 raeburn 4500: $datatable .= '</span>';
4501: $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
4502: '<span class="LC_nobreak"> : '.
4503: '<select name="ltitools_userincdom_'.$i.'">'.
4504: '<option value="">'.&mt('Select').'</option>'.
4505: '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
4506: '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
4507: '</select></span></div>';
4508: $datatable .= '</fieldset>'.
1.267 raeburn 4509: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4510: foreach my $role (@courseroles) {
4511: my ($selected,$selectnone);
4512: if (!$rolemaps{$role}) {
4513: $selectnone = ' selected="selected"';
4514: }
1.306 raeburn 4515: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4516: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4517: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
4518: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
4519: foreach my $ltirole (@ltiroles) {
4520: unless ($selectnone) {
4521: if ($rolemaps{$role} eq $ltirole) {
4522: $selected = ' selected="selected"';
4523: } else {
4524: $selected = '';
4525: }
4526: }
4527: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
4528: }
4529: $datatable .= '</select></td>';
4530: }
1.273 raeburn 4531: $datatable .= '</tr></table></fieldset>';
4532: my %courseconfig;
4533: if (ref($settings->{$item}) eq 'HASH') {
4534: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
4535: %courseconfig = %{$settings->{$item}->{'crsconf'}};
4536: }
4537: }
4538: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4539: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 4540: my $checked;
4541: if ($courseconfig{$item}) {
4542: $checked = ' checked="checked"';
4543: }
4544: $datatable .= '<label>'.
4545: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
4546: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
4547: }
4548: $datatable .= '</span></fieldset>'.
1.267 raeburn 4549: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4550: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
4551: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
4552: my %custom = %{$settings->{$item}->{'custom'}};
4553: if (keys(%custom) > 0) {
4554: foreach my $key (sort(keys(%custom))) {
4555: $datatable .= '<tr><td><span class="LC_nobreak">'.
4556: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
4557: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
4558: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
4559: ' value="'.$custom{$key}.'" /></td></tr>';
4560: }
4561: }
4562: }
4563: $datatable .= '<tr><td><span class="LC_nobreak">'.
4564: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
4565: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
4566: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
4567: $datatable .= '</table></fieldset></td></tr>'."\n";
4568: $itemcount ++;
4569: }
4570: }
4571: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.319 raeburn 4572: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1.267 raeburn 4573: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4574: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
4575: '<select name="ltitools_add_pos"'.$chgstr.'>';
4576: for (my $k=0; $k<$maxnum+1; $k++) {
4577: my $vpos = $k+1;
4578: my $selstr;
4579: if ($k == $maxnum) {
4580: $selstr = ' selected="selected" ';
4581: }
4582: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4583: }
4584: $datatable .= '</select> '."\n".
1.334 raeburn 4585: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.267 raeburn 4586: '<td colspan="2">'.
4587: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4588: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
1.267 raeburn 4589: (' 'x2).
4590: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
4591: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4592: (' 'x2).
4593: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
4594: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4595: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
4596: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
4597: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
1.267 raeburn 4598: '<br />'.
1.323 raeburn 4599: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
1.267 raeburn 4600: (' 'x2).
4601: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
4602: (' 'x2).
1.322 raeburn 4603: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
4604: (' 'x2).
1.267 raeburn 4605: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
4606: '<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".
4607: '</fieldset>'.
4608: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4609: '<span class="LC_nobreak">'.&mt('Display target:');
4610: my %defaultdisp;
4611: $defaultdisp{'iframe'} = ' checked="checked"';
1.298 raeburn 4612: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4613: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
4614: $lt{$disp}.'</label>'.(' 'x2);
4615: }
4616: $datatable .= (' 'x4);
4617: foreach my $dimen ('width','height') {
4618: $datatable .= '<label>'.$lt{$dimen}.' '.
4619: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
4620: (' 'x2);
4621: }
1.334 raeburn 4622: $datatable .= '</span><br />'.
1.296 raeburn 4623: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 4624: '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
1.296 raeburn 4625: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
1.334 raeburn 4626: '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
1.296 raeburn 4627: '</div><div style=""></div><br />';
1.319 raeburn 4628: my %units = (
4629: 'passback' => 'days',
4630: 'roster' => 'seconds',
4631: );
4632: my %defaulttimes = (
4633: 'passback' => '7',
1.322 raeburn 4634: 'roster' => '300',
1.319 raeburn 4635: );
1.267 raeburn 4636: foreach my $extra ('passback','roster') {
1.319 raeburn 4637: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
4638: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4639: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
4640: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
4641: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
4642: &mt('Yes').'</label></span></div>'.
4643: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
4644: '<span class="LC_nobreak">'.
4645: &mt("at least [_1] $units{$extra} after launch",
4646: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
4647: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4648: }
1.319 raeburn 4649: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
1.267 raeburn 4650: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4651: if ($switchserver) {
4652: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4653: } else {
4654: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
4655: }
4656: $datatable .= '</span></fieldset>'.
4657: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4658: '<span class="LC_nobreak">';
4659: foreach my $field (@fields) {
1.324 raeburn 4660: my ($id,$onclick,$spacer);
4661: if ($field eq 'user') {
4662: $id = ' id="ltitools_user_field_add"';
4663: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
4664: } else {
4665: $spacer = (' ' x2);
4666: }
1.267 raeburn 4667: $datatable .= '<label>'.
1.324 raeburn 4668: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
4669: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 4670: }
1.324 raeburn 4671: $datatable .= '</span>'.
4672: '<div style="display:none;" id="ltitools_user_div_add">'.
4673: '<span class="LC_nobreak"> : '.
4674: '<select name="ltitools_userincdom_add">'.
4675: '<option value="" selected="selected">'.&mt('Select').'</option>'.
4676: '<option value="0">'.&mt('username').'</option>'.
4677: '<option value="1">'.&mt('username:domain').'</option>'.
4678: '</select></span></div></fieldset>';
4679: $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
1.267 raeburn 4680: foreach my $role (@courseroles) {
4681: my ($checked,$checkednone);
1.306 raeburn 4682: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4683: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4684: '<select name="ltitools_add_roles_'.$role.'">'.
4685: '<option value="" selected="selected">'.&mt('Select').'</option>';
4686: foreach my $ltirole (@ltiroles) {
4687: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
4688: }
4689: $datatable .= '</select></td>';
4690: }
4691: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 4692: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4693: foreach my $item ('label','title','target','linktext','explanation','append') {
1.296 raeburn 4694: $datatable .= '<label>'.
4695: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
4696: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
1.273 raeburn 4697: }
4698: $datatable .= '</span></fieldset>'.
1.267 raeburn 4699: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4700: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
4701: '<tr><td><span class="LC_nobreak">'.
4702: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
4703: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
4704: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
1.334 raeburn 4705: '</table></fieldset>'."\n".
1.267 raeburn 4706: '</td>'."\n".
4707: '</tr>'."\n";
4708: $itemcount ++;
4709: return $datatable;
4710: }
4711:
4712: sub ltitools_names {
4713: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 4714: 'title' => 'Title',
4715: 'version' => 'Version',
4716: 'msgtype' => 'Message Type',
1.323 raeburn 4717: 'sigmethod' => 'Signature Method',
1.296 raeburn 4718: 'url' => 'URL',
4719: 'key' => 'Key',
1.322 raeburn 4720: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 4721: 'secret' => 'Secret',
4722: 'icon' => 'Icon',
1.324 raeburn 4723: 'user' => 'User',
1.296 raeburn 4724: 'fullname' => 'Full Name',
4725: 'firstname' => 'First Name',
4726: 'lastname' => 'Last Name',
4727: 'email' => 'E-mail',
4728: 'roles' => 'Role',
1.298 raeburn 4729: 'window' => 'Window',
4730: 'tab' => 'Tab',
1.296 raeburn 4731: 'iframe' => 'iFrame',
4732: 'height' => 'Height',
4733: 'width' => 'Width',
4734: 'linktext' => 'Default Link Text',
4735: 'explanation' => 'Default Explanation',
4736: 'passback' => 'Tool can return grades:',
4737: 'roster' => 'Tool can retrieve roster:',
4738: 'crstarget' => 'Display target',
4739: 'crslabel' => 'Course label',
4740: 'crstitle' => 'Course title',
4741: 'crslinktext' => 'Link Text',
4742: 'crsexplanation' => 'Explanation',
1.318 raeburn 4743: 'crsappend' => 'Provider URL',
1.267 raeburn 4744: );
4745: return %lt;
4746: }
4747:
1.320 raeburn 4748: sub print_lti {
4749: my ($dom,$settings,$rowtotal) = @_;
4750: my $itemcount = 1;
4751: my $maxnum = 0;
4752: my $css_class;
4753: my %ordered;
4754: if (ref($settings) eq 'HASH') {
4755: foreach my $item (keys(%{$settings})) {
4756: if (ref($settings->{$item}) eq 'HASH') {
4757: my $num = $settings->{$item}{'order'};
4758: $ordered{$num} = $item;
4759: }
4760: }
4761: }
4762: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 4763: my $datatable;
1.320 raeburn 4764: my %lt = <i_names();
4765: if (keys(%ordered)) {
4766: my @items = sort { $a <=> $b } keys(%ordered);
4767: for (my $i=0; $i<@items; $i++) {
4768: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4769: my $item = $ordered{$items[$i]};
4770: my ($key,$secret,$lifetime,$consumer,$current);
4771: if (ref($settings->{$item}) eq 'HASH') {
4772: $key = $settings->{$item}->{'key'};
4773: $secret = $settings->{$item}->{'secret'};
4774: $lifetime = $settings->{$item}->{'lifetime'};
4775: $consumer = $settings->{$item}->{'consumer'};
4776: $current = $settings->{$item};
4777: }
4778: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
4779: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4780: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
4781: for (my $k=0; $k<=$maxnum; $k++) {
4782: my $vpos = $k+1;
4783: my $selstr;
4784: if ($k == $i) {
4785: $selstr = ' selected="selected" ';
4786: }
4787: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4788: }
4789: $datatable .= '</select>'.(' 'x2).
4790: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
4791: &mt('Delete?').'</label></span></td>'.
4792: '<td colspan="2">'.
4793: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4794: '<span class="LC_nobreak">'.$lt{'consumer'}.
4795: ':<input type="text" size="20" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
4796: (' 'x2).
4797: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
4798: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4799: (' 'x2).
4800: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
4801: 'value="'.$lifetime.'" size="5" /></span>'.
4802: '<br /><br />'.
4803: '<span class="LC_nobreak">'.$lt{'key'}.
4804: ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
4805: (' 'x2).
4806: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4807: '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
4808: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.lti_secret_'.$i.'.type='."'text'".' } else { this.form.lti_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
4809: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
1.325 raeburn 4810: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
1.320 raeburn 4811: $itemcount ++;
4812: }
4813: }
4814: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4815: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
4816: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4817: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
4818: '<select name="lti_pos_add"'.$chgstr.'>';
4819: for (my $k=0; $k<$maxnum+1; $k++) {
4820: my $vpos = $k+1;
4821: my $selstr;
4822: if ($k == $maxnum) {
4823: $selstr = ' selected="selected" ';
4824: }
4825: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4826: }
4827: $datatable .= '</select> '."\n".
1.334 raeburn 4828: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.320 raeburn 4829: '<td colspan="2">'.
4830: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4831: '<span class="LC_nobreak">'.$lt{'consumer'}.
4832: ':<input type="text" size="20" name="lti_consumer_add" value="" /></span> '."\n".
4833: (' 'x2).
4834: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
4835: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4836: (' 'x2).
1.322 raeburn 4837: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="lti_lifetime_add" value="300" /></span> '."\n".
1.320 raeburn 4838: '<br /><br />'.
4839: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
4840: (' 'x2).
4841: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
4842: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.lti_secret_add.type='."'text'".' } else { this.form.lti_secret_add.type='."'password'".' }" />'.&mt('Visible input').'</label></span> '."\n".
1.325 raeburn 4843: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
1.320 raeburn 4844: '</td>'."\n".
4845: '</tr>'."\n";
4846: $$rowtotal ++;
4847: return $datatable;;
4848: }
4849:
4850: sub lti_names {
4851: my %lt = &Apache::lonlocal::texthash(
4852: 'version' => 'LTI Version',
4853: 'url' => 'URL',
4854: 'key' => 'Key',
1.322 raeburn 4855: 'lifetime' => 'Nonce lifetime (s)',
1.320 raeburn 4856: 'consumer' => 'LTI Consumer',
4857: 'secret' => 'Secret',
4858: 'email' => 'Email address',
4859: 'sourcedid' => 'User ID',
4860: 'other' => 'Other',
4861: 'passback' => 'Can return grades to Consumer:',
4862: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 4863: 'topmenu' => 'Display LON-CAPA page header',
4864: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 4865: );
4866: return %lt;
4867: }
4868:
4869: sub lti_options {
1.325 raeburn 4870: my ($num,$current,$itemcount,%lt) = @_;
1.320 raeburn 4871: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield);
4872: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
4873: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
4874: $checked{'makecrs'}{'N'} = ' checked="checked"';
4875: $checked{'mapcrstype'} = {};
4876: $checked{'makeuser'} = {};
4877: $checked{'selfenroll'} = {};
4878: $checked{'crssec'} = {};
4879: $checked{'crssecsrc'} = {};
1.325 raeburn 4880: $checked{'lcauth'} = {};
1.326 raeburn 4881: $checked{'menuitem'} = {};
1.325 raeburn 4882: if ($num eq 'add') {
4883: $checked{'lcauth'}{'lti'} = ' checked="checked"';
4884: }
1.320 raeburn 4885: my $userfieldsty = 'none';
4886: my $crsfieldsty = 'none';
4887: my $crssecfieldsty = 'none';
4888: my $secsrcfieldsty = 'none';
1.337 raeburn 4889: my $passbacksty = 'none';
1.325 raeburn 4890: my $lcauthparm;
4891: my $lcauthparmstyle = 'display:none';
4892: my $lcauthparmtext;
1.326 raeburn 4893: my $menusty;
1.325 raeburn 4894: my $numinrow = 4;
1.326 raeburn 4895: my %menutitles = <imenu_titles();
1.320 raeburn 4896:
4897: if (ref($current) eq 'HASH') {
4898: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
4899: $checked{'mapuser'}{'sourcedid'} = '';
4900: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
4901: $checked{'mapuser'}{'email'} = ' checked="checked"';
4902: } else {
4903: $checked{'mapuser'}{'other'} = ' checked="checked"';
4904: $userfield = $current->{'mapuser'};
4905: $userfieldsty = 'inline-block';
4906: }
4907: }
4908: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
4909: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
4910: if ($current->{'mapcrs'} eq 'context_id') {
4911: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
4912: } else {
4913: $checked{'mapcrs'}{'other'} = ' checked="checked"';
4914: $cidfield = $current->{'mapcrs'};
4915: $crsfieldsty = 'inline-block';
4916: }
4917: }
4918: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
4919: foreach my $type (@{$current->{'mapcrstype'}}) {
4920: $checked{'mapcrstype'}{$type} = ' checked="checked"';
4921: }
4922: }
4923: if ($current->{'makecrs'}) {
4924: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 4925: }
1.320 raeburn 4926: if (ref($current->{'makeuser'}) eq 'ARRAY') {
4927: foreach my $role (@{$current->{'makeuser'}}) {
4928: $checked{'makeuser'}{$role} = ' checked="checked"';
4929: }
4930: }
1.325 raeburn 4931: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
4932: $checked{'lcauth'}{$1} = ' checked="checked"';
4933: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
4934: $lcauthparm = $current->{'lcauthparm'};
4935: $lcauthparmstyle = 'display:table-row';
4936: if ($current->{'lcauth'} eq 'localauth') {
4937: $lcauthparmtext = &mt('Local auth argument');
4938: } else {
4939: $lcauthparmtext = &mt('Kerberos domain');
4940: }
4941: }
4942: }
1.320 raeburn 4943: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
4944: foreach my $role (@{$current->{'selfenroll'}}) {
4945: $checked{'selfenroll'}{$role} = ' checked="checked"';
4946: }
4947: }
4948: if (ref($current->{'maproles'}) eq 'HASH') {
4949: %rolemaps = %{$current->{'maproles'}};
4950: }
4951: if ($current->{'section'} ne '') {
4952: $checked{'crssec'}{'Y'} = ' checked="checked"';
4953: $crssecfieldsty = 'inline-block';
4954: if ($current->{'section'} eq 'course_section_sourcedid') {
4955: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
4956: } else {
4957: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
4958: $crssecsrc = $current->{'section'};
4959: $secsrcfieldsty = 'inline-block';
4960: }
4961: } else {
4962: $checked{'crssec'}{'N'} = ' checked="checked"';
4963: }
1.326 raeburn 4964: if ($current->{'topmenu'}) {
4965: $checked{'topmenu'}{'Y'} = ' checked="checked"';
4966: } else {
4967: $checked{'topmenu'}{'N'} = ' checked="checked"';
4968: }
4969: if ($current->{'inlinemenu'}) {
4970: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
4971: } else {
4972: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
4973: }
4974: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
4975: $menusty = 'inline-block';
4976: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
4977: foreach my $item (@{$current->{'lcmenu'}}) {
4978: if (exists($menutitles{$item})) {
4979: $checked{'menuitem'}{$item} = ' checked="checked"';
4980: }
4981: }
4982: }
4983: } else {
4984: $menusty = 'none';
4985: }
1.320 raeburn 4986: } else {
4987: $checked{'makecrs'}{'N'} = ' checked="checked"';
4988: $checked{'crssec'}{'N'} = ' checked="checked"';
1.326 raeburn 4989: $checked{'topmenu'}{'N'} = ' checked="checked"';
4990: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
4991: $checked{'menuitem'}{'grades'} = ' checked="checked"';
4992: $menusty = 'inline-block';
1.320 raeburn 4993: }
1.325 raeburn 4994: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 4995: my %coursetypetitles = &Apache::lonlocal::texthash (
4996: official => 'Official',
4997: unofficial => 'Unofficial',
4998: community => 'Community',
4999: textbook => 'Textbook',
5000: placement => 'Placement Test',
1.325 raeburn 5001: lti => 'LTI Provider',
1.320 raeburn 5002: );
1.325 raeburn 5003: my @authtypes = ('internal','krb4','krb5','localauth');
5004: my %shortauth = (
5005: internal => 'int',
5006: krb4 => 'krb4',
5007: krb5 => 'krb5',
5008: localauth => 'loc'
5009: );
5010: my %authnames = &authtype_names();
1.320 raeburn 5011: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
5012: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
5013: my @courseroles = ('cc','in','ta','ep','st');
5014: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
5015: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
5016: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
5017: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 5018: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 5019: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.320 raeburn 5020: my $output = '<fieldset><legend>'.&mt('Mapping users').'</legend>'.
5021: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
5022: foreach my $option ('sourcedid','email','other') {
5023: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
5024: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
5025: ($option eq 'other' ? '' : (' 'x2) );
5026: }
5027: $output .= '</span></div>'.
5028: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
5029: '<input type="text" name="lti_customuser_'.$num.'" '.
5030: 'value="'.$userfield.'" /></div></fieldset>'.
5031: '<fieldset><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
5032: foreach my $ltirole (@lticourseroles) {
5033: my ($selected,$selectnone);
5034: if ($rolemaps{$ltirole} eq '') {
5035: $selectnone = ' selected="selected"';
5036: }
5037: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
5038: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
5039: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5040: foreach my $role (@courseroles) {
5041: unless ($selectnone) {
5042: if ($rolemaps{$ltirole} eq $role) {
5043: $selected = ' selected="selected"';
5044: } else {
5045: $selected = '';
5046: }
5047: }
5048: $output .= '<option value="'.$role.'"'.$selected.'>'.
5049: &Apache::lonnet::plaintext($role,'Course').
5050: '</option>';
5051: }
5052: $output .= '</select></td>';
5053: }
5054: $output .= '</tr></table></fieldset>'.
5055: '<fieldset><legend>'.&mt('Roles which may create user accounts').'</legend>';
5056: foreach my $ltirole (@ltiroles) {
5057: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
5058: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
5059: }
5060: $output .= '</fieldset>'.
1.325 raeburn 5061: '<fieldset><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
5062: '<table>'.
5063: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
5064: '</table>'.
5065: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
5066: '<td class="LC_left_item">';
5067: foreach my $auth ('lti',@authtypes) {
5068: my $authtext;
5069: if ($auth eq 'lti') {
5070: $authtext = &mt('None');
5071: } else {
5072: $authtext = $authnames{$shortauth{$auth}};
5073: }
5074: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
5075: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
5076: $authtext.'</label></span> ';
5077: }
5078: $output .= '</td></tr>'.
5079: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
5080: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
5081: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
5082: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
5083: '</table></fieldset>'.
1.320 raeburn 5084: '<fieldset><legend>'.&mt('Mapping courses').'</legend>'.
5085: '<div class="LC_floatleft"><span class="LC_nobreak">'.
5086: &mt('Unique course identifier').': ';
5087: foreach my $option ('course_offering_sourcedid','context_id','other') {
5088: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
5089: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
5090: ($option eq 'other' ? '' : (' 'x2) );
5091: }
1.334 raeburn 5092: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 5093: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
5094: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
5095: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
5096: foreach my $type (@coursetypes) {
5097: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
5098: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
5099: (' 'x2);
5100: }
5101: $output .= '</span></fieldset>'.
5102: '<fieldset><legend>'.&mt('Creating courses').'</legend>'.
5103: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
5104: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
5105: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
5106: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
5107: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
5108: '</fieldset>'.
5109: '<fieldset><legend>'.&mt('Roles which may self-enroll').'</legend>';
5110: foreach my $lticrsrole (@lticourseroles) {
5111: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
5112: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
5113: }
5114: $output .= '</fieldset>'.
5115: '<fieldset><legend>'.&mt('Course options').'</legend>'.
5116: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
5117: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
5118: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
5119: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 5120: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 5121: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
5122: '<span class="LC_nobreak">'.&mt('From').':<label>'.
5123: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
5124: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
5125: &mt('Standard field').'</label>'.(' 'x2).
5126: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
5127: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 5128: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 5129: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 5130: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
5131: my ($pb1p1chk,$pb1p0chk,$onclickpb);
5132: foreach my $extra ('roster','passback') {
1.320 raeburn 5133: my $checkedon = '';
5134: my $checkedoff = ' checked="checked"';
1.337 raeburn 5135: if ($extra eq 'passback') {
5136: $pb1p1chk = ' checked="checked"';
5137: $pb1p0chk = '';
5138: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
5139: } else {
5140: $onclickpb = '';
5141: }
1.320 raeburn 5142: if (ref($current) eq 'HASH') {
5143: if (($current->{$extra})) {
5144: $checkedon = $checkedoff;
5145: $checkedoff = '';
1.337 raeburn 5146: if ($extra eq 'passback') {
5147: $passbacksty = 'inline-block';
5148: }
5149: if ($current->{'passbackformat'} eq '1.0') {
5150: $pb1p0chk = ' checked="checked"';
5151: $pb1p1chk = '';
5152: }
1.320 raeburn 5153: }
5154: }
5155: $output .= $lt{$extra}.' '.
1.337 raeburn 5156: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 5157: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 5158: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 5159: &mt('Yes').'</label><br />';
5160: }
1.337 raeburn 5161: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
5162: '<span class="LC_nobreak">'.&mt('Grade format').
5163: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
5164: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
5165: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
5166: &mt('Outcomes Extension (1.0)').'</label></span></div></fieldset>'.
1.326 raeburn 5167: '<fieldset><legend>'.&mt('Course defaults (Course Coordinator can override)').'</legend>'.
5168: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
5169: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
5170: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
5171: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
1.334 raeburn 5172: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
1.326 raeburn 5173: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
5174: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
5175: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
5176: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
5177: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
1.334 raeburn 5178: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
1.326 raeburn 5179: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
5180: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
5181: '<span class="LC_nobreak">'.&mt('Menu items').': ';
5182: foreach my $type ('fullname','coursetitle','role','logout','grades') {
5183: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
5184: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
5185: (' 'x2);
5186: }
1.334 raeburn 5187: $output .= '</span></div></fieldset>';
1.320 raeburn 5188: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
5189: #
5190: # $output .= '</fieldset>'.
5191: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
5192: return $output;
5193: }
5194:
1.326 raeburn 5195: sub ltimenu_titles {
5196: return &Apache::lonlocal::texthash(
5197: fullname => 'Full name',
5198: coursetitle => 'Course title',
5199: role => 'Role',
5200: logout => 'Logout',
5201: grades => 'Grades',
5202: );
5203: }
5204:
1.121 raeburn 5205: sub print_coursedefaults {
1.139 raeburn 5206: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 5207: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 5208: my $itemcount = 1;
1.192 raeburn 5209: my %choices = &Apache::lonlocal::texthash (
5210: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 5211: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 5212: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
5213: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 5214: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
5215: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.314 raeburn 5216: texengine => 'Default method to display mathematics',
1.257 raeburn 5217: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 5218: canclone => "People who may clone a course (besides course's owner and coordinators)",
5219: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 5220: );
1.198 raeburn 5221: my %staticdefaults = (
1.314 raeburn 5222: texengine => 'MathJax',
1.198 raeburn 5223: anonsurvey_threshold => 10,
5224: uploadquota => 500,
1.257 raeburn 5225: postsubmit => 60,
1.276 raeburn 5226: mysqltables => 172800,
1.198 raeburn 5227: );
1.139 raeburn 5228: if ($position eq 'top') {
1.257 raeburn 5229: %defaultchecked = (
5230: 'canuse_pdfforms' => 'off',
5231: 'uselcmath' => 'on',
5232: 'usejsme' => 'on',
1.289 raeburn 5233: 'canclone' => 'none',
1.257 raeburn 5234: );
5235: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.314 raeburn 5236: my $deftex = $staticdefaults{'texengine'};
5237: if (ref($settings) eq 'HASH') {
5238: if ($settings->{'texengine'}) {
5239: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
5240: $deftex = $settings->{'texengine'};
5241: }
5242: }
5243: }
5244: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5245: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
5246: '<span class="LC_nobreak">'.$choices{'texengine'}.
5247: '</span></td><td class="LC_right_item">'.
5248: '<select name="texengine">'."\n";
5249: my %texoptions = (
5250: MathJax => 'MathJax',
5251: mimetex => &mt('Convert to Images'),
5252: tth => &mt('TeX to HTML'),
5253: );
5254: foreach my $renderer ('MathJax','mimetex','tth') {
5255: my $selected = '';
5256: if ($renderer eq $deftex) {
5257: $selected = ' selected="selected"';
5258: }
5259: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
5260: }
5261: $mathdisp .= '</select></td></tr>'."\n";
5262: $itemcount ++;
1.139 raeburn 5263: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 5264: \%choices,$itemcount);
1.314 raeburn 5265: $datatable = $mathdisp.$datatable;
1.264 raeburn 5266: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5267: $datatable .=
1.306 raeburn 5268: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 5269: '<span class="LC_nobreak">'.$choices{'canclone'}.
5270: '</span></td><td class="LC_left_item">';
5271: my $currcanclone = 'none';
5272: my $onclick;
5273: my @cloneoptions = ('none','domain');
5274: my %clonetitles = (
5275: none => 'No additional course requesters',
5276: domain => "Any course requester in course's domain",
5277: instcode => 'Course requests for official courses ...',
5278: );
5279: my (%codedefaults,@code_order,@posscodes);
5280: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
5281: \@code_order) eq 'ok') {
5282: if (@code_order > 0) {
5283: push(@cloneoptions,'instcode');
5284: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
5285: }
5286: }
5287: if (ref($settings) eq 'HASH') {
5288: if ($settings->{'canclone'}) {
5289: if (ref($settings->{'canclone'}) eq 'HASH') {
5290: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
5291: if (@code_order > 0) {
5292: $currcanclone = 'instcode';
5293: @posscodes = @{$settings->{'canclone'}{'instcode'}};
5294: }
5295: }
5296: } elsif ($settings->{'canclone'} eq 'domain') {
5297: $currcanclone = $settings->{'canclone'};
5298: }
5299: }
1.289 raeburn 5300: }
1.264 raeburn 5301: foreach my $option (@cloneoptions) {
5302: my ($checked,$additional);
5303: if ($currcanclone eq $option) {
5304: $checked = ' checked="checked"';
5305: }
5306: if ($option eq 'instcode') {
5307: if (@code_order) {
5308: my $show = 'none';
5309: if ($checked) {
5310: $show = 'block';
5311: }
1.317 raeburn 5312: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 5313: &mt('Institutional codes for new and cloned course have identical:').
5314: '<br />';
5315: foreach my $item (@code_order) {
5316: my $codechk;
5317: if ($checked) {
5318: if (grep(/^\Q$item\E$/,@posscodes)) {
5319: $codechk = ' checked="checked"';
5320: }
5321: }
5322: $additional .= '<label>'.
5323: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
5324: $item.'</label>';
5325: }
5326: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
5327: }
5328: }
5329: $datatable .=
5330: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
5331: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
5332: '</label> '.$additional.'</span><br />';
5333: }
5334: $datatable .= '</td>'.
5335: '</tr>';
5336: $itemcount ++;
1.139 raeburn 5337: } else {
5338: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 5339: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 5340: my $currusecredits = 0;
1.257 raeburn 5341: my $postsubmitclient = 1;
1.271 raeburn 5342: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 5343: if (ref($settings) eq 'HASH') {
5344: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 5345: if (ref($settings->{'uploadquota'}) eq 'HASH') {
5346: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
5347: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
5348: }
5349: }
1.192 raeburn 5350: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 5351: foreach my $type (@types) {
5352: next if ($type eq 'community');
5353: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
5354: if ($defcredits{$type} ne '') {
5355: $currusecredits = 1;
5356: }
5357: }
5358: }
5359: if (ref($settings->{'postsubmit'}) eq 'HASH') {
5360: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
5361: $postsubmitclient = 0;
5362: foreach my $type (@types) {
5363: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5364: }
5365: } else {
5366: foreach my $type (@types) {
5367: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
5368: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 5369: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 5370: } else {
5371: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5372: }
5373: } else {
5374: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5375: }
5376: }
5377: }
5378: } else {
5379: foreach my $type (@types) {
5380: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 5381: }
5382: }
1.276 raeburn 5383: if (ref($settings->{'mysqltables'}) eq 'HASH') {
5384: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
5385: $currmysql{$type} = $settings->{'mysqltables'}{$type};
5386: }
5387: } else {
5388: foreach my $type (@types) {
5389: $currmysql{$type} = $staticdefaults{'mysqltables'};
5390: }
5391: }
1.258 raeburn 5392: } else {
5393: foreach my $type (@types) {
5394: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5395: }
1.139 raeburn 5396: }
5397: if (!$currdefresponder) {
1.198 raeburn 5398: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 5399: } elsif ($currdefresponder < 1) {
5400: $currdefresponder = 1;
5401: }
1.198 raeburn 5402: foreach my $type (@types) {
5403: if ($curruploadquota{$type} eq '') {
5404: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
5405: }
5406: }
1.139 raeburn 5407: $datatable .=
1.192 raeburn 5408: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5409: $choices{'anonsurvey_threshold'}.
1.139 raeburn 5410: '</span></td>'.
5411: '<td class="LC_right_item"><span class="LC_nobreak">'.
5412: '<input type="text" name="anonsurvey_threshold"'.
5413: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 5414: '</td></tr>'."\n";
5415: $itemcount ++;
5416: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5417: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5418: $choices{'uploadquota'}.
5419: '</span></td>'.
1.306 raeburn 5420: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 5421: '<table><tr>';
1.198 raeburn 5422: foreach my $type (@types) {
1.306 raeburn 5423: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 5424: '<input type="text" name="uploadquota_'.$type.'"'.
5425: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
5426: }
5427: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 5428: $itemcount ++;
1.236 raeburn 5429: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 5430: my $display = 'none';
1.192 raeburn 5431: if ($currusecredits) {
5432: $display = 'block';
5433: }
5434: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 5435: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
5436: foreach my $type (@types) {
5437: next if ($type eq 'community');
1.306 raeburn 5438: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 5439: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 5440: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 5441: }
5442: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 5443: %defaultchecked = ('coursecredits' => 'off');
5444: @toggles = ('coursecredits');
5445: my $current = {
5446: 'coursecredits' => $currusecredits,
5447: };
5448: (my $table,$itemcount) =
5449: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 5450: \%choices,$itemcount,$onclick,$additional,'left');
5451: $datatable .= $table;
5452: $onclick = "toggleDisplay(this.form,'studentsubmission');";
5453: my $display = 'none';
5454: if ($postsubmitclient) {
5455: $display = 'block';
5456: }
5457: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 5458: &mt('Number of seconds submit is disabled').'<br />'.
5459: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
5460: '<table><tr>';
1.257 raeburn 5461: foreach my $type (@types) {
1.306 raeburn 5462: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 5463: '<input type="text" name="'.$type.'_timeout" value="'.
5464: $deftimeout{$type}.'" size="5" /></td>';
5465: }
5466: $additional .= '</tr></table></div>'."\n";
5467: %defaultchecked = ('postsubmit' => 'on');
5468: @toggles = ('postsubmit');
1.280 raeburn 5469: $current = {
5470: 'postsubmit' => $postsubmitclient,
5471: };
1.257 raeburn 5472: ($table,$itemcount) =
5473: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
5474: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 5475: $datatable .= $table;
1.276 raeburn 5476: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5477: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5478: $choices{'mysqltables'}.
5479: '</span></td>'.
1.306 raeburn 5480: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 5481: '<table><tr>';
5482: foreach my $type (@types) {
1.306 raeburn 5483: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 5484: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 5485: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 5486: }
5487: $datatable .= '</tr></table></td></tr>'."\n";
5488: $itemcount ++;
5489:
1.139 raeburn 5490: }
1.192 raeburn 5491: $$rowtotal += $itemcount;
1.121 raeburn 5492: return $datatable;
1.118 jms 5493: }
5494:
1.231 raeburn 5495: sub print_selfenrollment {
5496: my ($position,$dom,$settings,$rowtotal) = @_;
5497: my ($css_class,$datatable);
5498: my $itemcount = 1;
1.271 raeburn 5499: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 5500: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 5501: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
5502: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 5503: my @rows;
5504: my $key;
5505: if ($position eq 'top') {
5506: $key = 'admin';
5507: if (ref($rowsref) eq 'ARRAY') {
5508: @rows = @{$rowsref};
5509: }
5510: } elsif ($position eq 'middle') {
5511: $key = 'default';
5512: @rows = ('types','registered','approval','limit');
5513: }
5514: foreach my $row (@rows) {
5515: if (defined($titlesref->{$row})) {
5516: $itemcount ++;
5517: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5518: $datatable .= '<tr'.$css_class.'>'.
5519: '<td>'.$titlesref->{$row}.'</td>'.
5520: '<td class="LC_left_item">'.
5521: '<table><tr>';
5522: my (%current,%currentcap);
5523: if (ref($settings) eq 'HASH') {
5524: if (ref($settings->{$key}) eq 'HASH') {
5525: foreach my $type (@types) {
5526: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5527: $current{$type} = $settings->{$key}->{$type}->{$row};
5528: }
5529: if (($row eq 'limit') && ($key eq 'default')) {
5530: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5531: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
5532: }
5533: }
5534: }
5535: }
5536: }
5537: my %roles = (
5538: '0' => &Apache::lonnet::plaintext('dc'),
5539: );
5540:
5541: foreach my $type (@types) {
5542: unless (($row eq 'registered') && ($key eq 'default')) {
5543: $datatable .= '<th>'.&mt($type).'</th>';
5544: }
5545: }
5546: unless (($row eq 'registered') && ($key eq 'default')) {
5547: $datatable .= '</tr><tr>';
5548: }
5549: foreach my $type (@types) {
5550: if ($type eq 'community') {
5551: $roles{'1'} = &mt('Community personnel');
5552: } else {
5553: $roles{'1'} = &mt('Course personnel');
5554: }
5555: $datatable .= '<td style="vertical-align: top">';
5556: if ($position eq 'top') {
5557: my %checked;
5558: if ($current{$type} eq '0') {
5559: $checked{'0'} = ' checked="checked"';
5560: } else {
5561: $checked{'1'} = ' checked="checked"';
5562: }
5563: foreach my $role ('1','0') {
5564: $datatable .= '<span class="LC_nobreak"><label>'.
5565: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
5566: 'value="'.$role.'"'.$checked{$role}.' />'.
5567: $roles{$role}.'</label></span> ';
5568: }
5569: } else {
5570: if ($row eq 'types') {
5571: my %checked;
5572: if ($current{$type} =~ /^(all|dom)$/) {
5573: $checked{$1} = ' checked="checked"';
5574: } else {
5575: $checked{''} = ' checked="checked"';
5576: }
5577: foreach my $val ('','dom','all') {
5578: $datatable .= '<span class="LC_nobreak"><label>'.
5579: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5580: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5581: }
5582: } elsif ($row eq 'registered') {
5583: my %checked;
5584: if ($current{$type} eq '1') {
5585: $checked{'1'} = ' checked="checked"';
5586: } else {
5587: $checked{'0'} = ' checked="checked"';
5588: }
5589: foreach my $val ('0','1') {
5590: $datatable .= '<span class="LC_nobreak"><label>'.
5591: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5592: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5593: }
5594: } elsif ($row eq 'approval') {
5595: my %checked;
5596: if ($current{$type} =~ /^([12])$/) {
5597: $checked{$1} = ' checked="checked"';
5598: } else {
5599: $checked{'0'} = ' checked="checked"';
5600: }
5601: for my $val (0..2) {
5602: $datatable .= '<span class="LC_nobreak"><label>'.
5603: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5604: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5605: }
5606: } elsif ($row eq 'limit') {
5607: my %checked;
5608: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
5609: $checked{$1} = ' checked="checked"';
5610: } else {
5611: $checked{'none'} = ' checked="checked"';
5612: }
5613: my $cap;
5614: if ($currentcap{$type} =~ /^\d+$/) {
5615: $cap = $currentcap{$type};
5616: }
5617: foreach my $val ('none','allstudents','selfenrolled') {
5618: $datatable .= '<span class="LC_nobreak"><label>'.
5619: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5620: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5621: }
5622: $datatable .= '<br />'.
5623: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
5624: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
5625: '</span>';
5626: }
5627: }
5628: $datatable .= '</td>';
5629: }
5630: $datatable .= '</tr>';
5631: }
5632: $datatable .= '</table></td></tr>';
5633: }
5634: } elsif ($position eq 'bottom') {
1.235 raeburn 5635: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
5636: }
5637: $$rowtotal += $itemcount;
5638: return $datatable;
5639: }
5640:
5641: sub print_validation_rows {
5642: my ($caller,$dom,$settings,$rowtotal) = @_;
5643: my ($itemsref,$namesref,$fieldsref);
5644: if ($caller eq 'selfenroll') {
5645: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
5646: } elsif ($caller eq 'requestcourses') {
5647: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
5648: }
5649: my %currvalidation;
5650: if (ref($settings) eq 'HASH') {
5651: if (ref($settings->{'validation'}) eq 'HASH') {
5652: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 5653: }
1.235 raeburn 5654: }
5655: my $datatable;
5656: my $itemcount = 0;
5657: foreach my $item (@{$itemsref}) {
5658: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5659: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5660: $namesref->{$item}.
5661: '</span></td>'.
5662: '<td class="LC_left_item">';
5663: if (($item eq 'url') || ($item eq 'button')) {
5664: $datatable .= '<span class="LC_nobreak">'.
5665: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
5666: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
5667: } elsif ($item eq 'fields') {
5668: my @currfields;
5669: if (ref($currvalidation{$item}) eq 'ARRAY') {
5670: @currfields = @{$currvalidation{$item}};
5671: }
5672: foreach my $field (@{$fieldsref}) {
5673: my $check = '';
5674: if (grep(/^\Q$field\E$/,@currfields)) {
5675: $check = ' checked="checked"';
5676: }
5677: $datatable .= '<span class="LC_nobreak"><label>'.
5678: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
5679: ' value="'.$field.'"'.$check.' />'.$field.
5680: '</label></span> ';
5681: }
5682: } elsif ($item eq 'markup') {
1.334 raeburn 5683: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 5684: $currvalidation{$item}.
1.231 raeburn 5685: '</textarea>';
1.235 raeburn 5686: }
5687: $datatable .= '</td></tr>'."\n";
5688: if (ref($rowtotal)) {
1.231 raeburn 5689: $itemcount ++;
5690: }
5691: }
1.235 raeburn 5692: if ($caller eq 'requestcourses') {
5693: my %currhash;
1.248 raeburn 5694: if (ref($settings) eq 'HASH') {
5695: if (ref($settings->{'validation'}) eq 'HASH') {
5696: if ($settings->{'validation'}{'dc'} ne '') {
5697: $currhash{$settings->{'validation'}{'dc'}} = 1;
5698: }
1.235 raeburn 5699: }
5700: }
5701: my $numinrow = 2;
5702: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
5703: 'validationdc',%currhash);
1.247 raeburn 5704: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 5705: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 5706: if ($numdc > 1) {
1.247 raeburn 5707: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 5708: } else {
1.247 raeburn 5709: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 5710: }
1.247 raeburn 5711: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 5712: $itemcount ++;
5713: }
5714: if (ref($rowtotal)) {
5715: $$rowtotal += $itemcount;
5716: }
1.231 raeburn 5717: return $datatable;
5718: }
5719:
1.137 raeburn 5720: sub print_usersessions {
5721: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 5722: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 5723: my (%by_ip,%by_location,@intdoms,@instdoms);
5724: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 5725:
5726: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 5727: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 5728: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 5729: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 5730: if ($position eq 'top') {
1.152 raeburn 5731: if (keys(%serverhomes) > 1) {
1.145 raeburn 5732: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.261 raeburn 5733: my $curroffloadnow;
5734: if (ref($settings) eq 'HASH') {
5735: if (ref($settings->{'offloadnow'}) eq 'HASH') {
5736: $curroffloadnow = $settings->{'offloadnow'};
5737: }
5738: }
5739: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 5740: } else {
1.140 raeburn 5741: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 5742: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
5743: '</td></tr>';
1.140 raeburn 5744: }
1.137 raeburn 5745: } else {
1.279 raeburn 5746: my %titles = &usersession_titles();
5747: my ($prefix,@types);
5748: if ($position eq 'bottom') {
5749: $prefix = 'remote';
5750: @types = ('version','excludedomain','includedomain');
1.145 raeburn 5751: } else {
1.279 raeburn 5752: $prefix = 'hosted';
5753: @types = ('excludedomain','includedomain');
5754: }
5755: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
5756: }
5757: $$rowtotal += $itemcount;
5758: return $datatable;
5759: }
5760:
5761: sub rules_by_location {
5762: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
5763: my ($datatable,$itemcount,$css_class);
5764: if (keys(%{$by_location}) == 0) {
5765: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5766: $datatable = '<tr'.$css_class.'><td colspan="2">'.
5767: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
5768: '</td></tr>';
5769: $itemcount = 1;
5770: } else {
5771: $itemcount = 0;
5772: my $numinrow = 5;
5773: my (%current,%checkedon,%checkedoff);
5774: my @locations = sort(keys(%{$by_location}));
5775: foreach my $type (@{$types}) {
5776: $checkedon{$type} = '';
5777: $checkedoff{$type} = ' checked="checked"';
5778: }
5779: if (ref($settings) eq 'HASH') {
5780: if (ref($settings->{$prefix}) eq 'HASH') {
5781: foreach my $key (keys(%{$settings->{$prefix}})) {
5782: $current{$key} = $settings->{$prefix}{$key};
5783: if ($key eq 'version') {
5784: if ($current{$key} ne '') {
1.145 raeburn 5785: $checkedon{$key} = ' checked="checked"';
5786: $checkedoff{$key} = '';
5787: }
1.279 raeburn 5788: } elsif (ref($current{$key}) eq 'ARRAY') {
5789: $checkedon{$key} = ' checked="checked"';
5790: $checkedoff{$key} = '';
1.137 raeburn 5791: }
5792: }
5793: }
1.279 raeburn 5794: }
5795: foreach my $type (@{$types}) {
5796: next if ($type ne 'version' && !@locations);
5797: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5798: $datatable .= '<tr'.$css_class.'>
5799: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
5800: <span class="LC_nobreak">
5801: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
5802: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
5803: if ($type eq 'version') {
5804: my @lcversions = &Apache::lonnet::all_loncaparevs();
5805: my $selector = '<select name="'.$prefix.'_version">';
5806: foreach my $version (@lcversions) {
5807: my $selected = '';
5808: if ($current{'version'} eq $version) {
5809: $selected = ' selected="selected"';
1.145 raeburn 5810: }
1.279 raeburn 5811: $selector .= ' <option value="'.$version.'"'.
5812: $selected.'>'.$version.'</option>';
5813: }
5814: $selector .= '</select> ';
5815: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
5816: } else {
5817: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
5818: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
5819: ' />'.(' 'x2).
5820: '<input type="button" value="'.&mt('uncheck all').'" '.
5821: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
5822: "\n".
5823: '</div><div><table>';
5824: my $rem;
5825: for (my $i=0; $i<@locations; $i++) {
5826: my ($showloc,$value,$checkedtype);
5827: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
5828: my $ip = $by_location->{$locations[$i]}->[0];
5829: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5830: $value = join(':',@{$by_ip->{$ip}});
5831: $showloc = join(', ',@{$by_ip->{$ip}});
5832: if (ref($current{$type}) eq 'ARRAY') {
5833: foreach my $loc (@{$by_ip->{$ip}}) {
5834: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
5835: $checkedtype = ' checked="checked"';
5836: last;
1.145 raeburn 5837: }
1.138 raeburn 5838: }
5839: }
5840: }
1.137 raeburn 5841: }
1.279 raeburn 5842: $rem = $i%($numinrow);
5843: if ($rem == 0) {
5844: if ($i > 0) {
5845: $datatable .= '</tr>';
5846: }
5847: $datatable .= '<tr>';
5848: }
5849: $datatable .= '<td class="LC_left_item">'.
5850: '<span class="LC_nobreak"><label>'.
5851: '<input type="checkbox" name="'.$prefix.'_'.$type.
5852: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
5853: '</label></span></td>';
5854: }
5855: $rem = @locations%($numinrow);
5856: my $colsleft = $numinrow - $rem;
5857: if ($colsleft > 1 ) {
5858: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5859: ' </td>';
5860: } elsif ($colsleft == 1) {
5861: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 5862: }
1.279 raeburn 5863: $datatable .= '</tr></table>';
1.137 raeburn 5864: }
1.279 raeburn 5865: $datatable .= '</td></tr>';
5866: $itemcount ++;
1.137 raeburn 5867: }
5868: }
1.279 raeburn 5869: return ($datatable,$itemcount);
1.137 raeburn 5870: }
5871:
1.275 raeburn 5872: sub print_ssl {
5873: my ($position,$dom,$settings,$rowtotal) = @_;
5874: my ($css_class,$datatable);
5875: my $itemcount = 1;
5876: if ($position eq 'top') {
1.281 raeburn 5877: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5878: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5879: my $same_institution;
5880: if ($intdom ne '') {
5881: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
5882: if (ref($internet_names) eq 'ARRAY') {
5883: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
5884: $same_institution = 1;
5885: }
5886: }
5887: }
1.275 raeburn 5888: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 5889: $datatable = '<tr'.$css_class.'><td colspan="2">';
5890: if ($same_institution) {
5891: my %domservers = &Apache::lonnet::get_servers($dom);
5892: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
5893: } else {
5894: $datatable .= &mt("You need to be logged into one of your own domain's servers to display information about the status of LON-CAPA SSL certificates.");
5895: }
5896: $datatable .= '</td></tr>';
1.275 raeburn 5897: $itemcount ++;
5898: } else {
5899: my %titles = &ssl_titles();
5900: my (%by_ip,%by_location,@intdoms,@instdoms);
5901: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
5902: my @alldoms = &Apache::lonnet::all_domains();
5903: my %serverhomes = %Apache::lonnet::serverhomeIDs;
5904: my @domservers = &Apache::lonnet::get_servers($dom);
5905: my %servers = &Apache::lonnet::internet_dom_servers($dom);
5906: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 5907: if (($position eq 'connto') || ($position eq 'connfrom')) {
5908: my $legacy;
5909: unless (ref($settings) eq 'HASH') {
5910: my $name;
5911: if ($position eq 'connto') {
5912: $name = 'loncAllowInsecure';
5913: } else {
5914: $name = 'londAllowInsecure';
5915: }
5916: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
5917: my @ids=&Apache::lonnet::current_machine_ids();
5918: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
5919: my %what = (
5920: $name => 1,
5921: );
5922: my ($result,$returnhash) =
5923: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
5924: if ($result eq 'ok') {
5925: if (ref($returnhash) eq 'HASH') {
5926: $legacy = $returnhash->{$name};
5927: }
5928: }
5929: } else {
5930: $legacy = $Apache::lonnet::perlvar{$name};
5931: }
5932: }
1.275 raeburn 5933: foreach my $type ('dom','intdom','other') {
5934: my %checked;
5935: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5936: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
5937: '<td class="LC_right_item">';
5938: my $skip;
5939: if ($type eq 'dom') {
5940: unless (keys(%servers) > 1) {
5941: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
5942: $skip = 1;
5943: }
5944: }
5945: if ($type eq 'intdom') {
5946: unless (@instdoms > 1) {
5947: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
5948: $skip = 1;
5949: }
5950: } elsif ($type eq 'other') {
5951: if (keys(%by_location) == 0) {
5952: $datatable .= &mt('Nothing to set here, as there are no other institutions');
5953: $skip = 1;
5954: }
5955: }
5956: unless ($skip) {
5957: $checked{'yes'} = ' checked="checked"';
5958: if (ref($settings) eq 'HASH') {
1.293 raeburn 5959: if (ref($settings->{$position}) eq 'HASH') {
5960: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 5961: $checked{$1} = $checked{'yes'};
5962: delete($checked{'yes'});
5963: }
5964: }
1.293 raeburn 5965: } else {
5966: if ($legacy == 0) {
5967: $checked{'req'} = $checked{'yes'};
5968: delete($checked{'yes'});
5969: }
1.275 raeburn 5970: }
5971: foreach my $option ('no','yes','req') {
5972: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 5973: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 5974: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
5975: '</label></span>'.(' 'x2);
5976: }
5977: }
5978: $datatable .= '</td></tr>';
5979: $itemcount ++;
5980: }
5981: } else {
5982: my $prefix = 'replication';
5983: my @types = ('certreq','nocertreq');
1.279 raeburn 5984: if (keys(%by_location) == 0) {
5985: $datatable .= '<tr'.$css_class.'><td>'.
5986: &mt('Nothing to set here, as there are no other institutions').
5987: '</td></tr>';
5988: $itemcount ++;
1.275 raeburn 5989: } else {
1.279 raeburn 5990: ($datatable,$itemcount) =
5991: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 5992: }
5993: }
5994: }
5995: $$rowtotal += $itemcount;
5996: return $datatable;
5997: }
5998:
5999: sub ssl_titles {
6000: return &Apache::lonlocal::texthash (
6001: dom => 'LON-CAPA servers/VMs from same domain',
6002: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
6003: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 6004: connto => 'Connections to other servers',
6005: connfrom => 'Connections from other servers',
1.275 raeburn 6006: replication => 'Replicating content to other institutions',
6007: certreq => 'Client certificate required, but specific domains exempt',
6008: nocertreq => 'No client certificate required, except for specific domains',
6009: no => 'SSL not used',
6010: yes => 'SSL Optional (used if available)',
6011: req => 'SSL Required',
6012: );
1.279 raeburn 6013: }
6014:
6015: sub print_trust {
6016: my ($prefix,$dom,$settings,$rowtotal) = @_;
6017: my ($css_class,$datatable,%checked,%choices);
6018: my (%by_ip,%by_location,@intdoms,@instdoms);
6019: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
6020: my $itemcount = 1;
6021: my %titles = &trust_titles();
6022: my @types = ('exc','inc');
6023: if ($prefix eq 'top') {
6024: $prefix = 'content';
6025: } elsif ($prefix eq 'bottom') {
6026: $prefix = 'msg';
6027: }
6028: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
6029: $$rowtotal += $itemcount;
6030: return $datatable;
6031: }
6032:
6033: sub trust_titles {
6034: return &Apache::lonlocal::texthash(
6035: content => "Access to this domain's content by others",
6036: shared => "Access to other domain's content by this domain",
6037: enroll => "Enrollment in this domain's courses by others",
6038: othcoau => "Co-author roles in this domain for others",
6039: coaurem => "Co-author roles for this domain's users elsewhere",
6040: domroles => "Domain roles in this domain assignable to others",
6041: catalog => "Course Catalog for this domain displayed elsewhere",
6042: reqcrs => "Requests for creation of courses in this domain by others",
6043: msg => "Users in other domains can send messages to this domain",
6044: exc => "Allow all, but exclude specific domains",
6045: inc => "Deny all, but include specific domains",
6046: );
1.275 raeburn 6047: }
6048:
1.138 raeburn 6049: sub build_location_hashes {
1.275 raeburn 6050: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 6051: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 6052: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 6053: my %iphost = &Apache::lonnet::get_iphost();
6054: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
6055: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
6056: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
6057: foreach my $id (@{$iphost{$primary_ip}}) {
6058: my $intdom = &Apache::lonnet::internet_dom($id);
6059: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
6060: push(@{$intdoms},$intdom);
6061: }
6062: }
6063: }
6064: foreach my $ip (keys(%iphost)) {
6065: if (ref($iphost{$ip}) eq 'ARRAY') {
6066: foreach my $id (@{$iphost{$ip}}) {
6067: my $location = &Apache::lonnet::internet_dom($id);
6068: if ($location) {
1.275 raeburn 6069: if (grep(/^\Q$location\E$/,@{$intdoms})) {
6070: my $dom = &Apache::lonnet::host_domain($id);
6071: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
6072: push(@{$instdoms},$dom);
6073: }
6074: next;
6075: }
1.138 raeburn 6076: if (ref($by_ip->{$ip}) eq 'ARRAY') {
6077: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
6078: push(@{$by_ip->{$ip}},$location);
6079: }
6080: } else {
6081: $by_ip->{$ip} = [$location];
6082: }
6083: }
6084: }
6085: }
6086: }
6087: foreach my $ip (sort(keys(%{$by_ip}))) {
6088: if (ref($by_ip->{$ip}) eq 'ARRAY') {
6089: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
6090: my $first = $by_ip->{$ip}->[0];
6091: if (ref($by_location->{$first}) eq 'ARRAY') {
6092: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
6093: push(@{$by_location->{$first}},$ip);
6094: }
6095: } else {
6096: $by_location->{$first} = [$ip];
6097: }
6098: }
6099: }
6100: return;
6101: }
6102:
1.145 raeburn 6103: sub current_offloads_to {
6104: my ($dom,$settings,$servers) = @_;
6105: my (%spareid,%otherdomconfigs);
1.152 raeburn 6106: if (ref($servers) eq 'HASH') {
1.145 raeburn 6107: foreach my $lonhost (sort(keys(%{$servers}))) {
6108: my $gotspares;
1.152 raeburn 6109: if (ref($settings) eq 'HASH') {
6110: if (ref($settings->{'spares'}) eq 'HASH') {
6111: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
6112: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
6113: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
6114: $gotspares = 1;
6115: }
1.145 raeburn 6116: }
6117: }
6118: unless ($gotspares) {
6119: my $gotspares;
6120: my $serverhomeID =
6121: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
6122: my $serverhomedom =
6123: &Apache::lonnet::host_domain($serverhomeID);
6124: if ($serverhomedom ne $dom) {
6125: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
6126: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
6127: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
6128: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
6129: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
6130: $gotspares = 1;
6131: }
6132: }
6133: } else {
6134: $otherdomconfigs{$serverhomedom} =
6135: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
6136: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
6137: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
6138: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
6139: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
6140: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
6141: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
6142: $gotspares = 1;
6143: }
6144: }
6145: }
6146: }
6147: }
6148: }
6149: }
6150: unless ($gotspares) {
6151: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
6152: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6153: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6154: } else {
6155: my $server_hostname = &Apache::lonnet::hostname($lonhost);
6156: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
6157: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
6158: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6159: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6160: } else {
1.150 raeburn 6161: my %what = (
6162: spareid => 1,
6163: );
6164: my ($result,$returnhash) =
6165: &Apache::lonnet::get_remote_globals($lonhost,\%what);
6166: if ($result eq 'ok') {
6167: if (ref($returnhash) eq 'HASH') {
6168: if (ref($returnhash->{'spareid'}) eq 'HASH') {
6169: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
6170: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
6171: }
6172: }
1.145 raeburn 6173: }
6174: }
6175: }
6176: }
6177: }
6178: }
6179: return %spareid;
6180: }
6181:
6182: sub spares_row {
1.261 raeburn 6183: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 6184: my $css_class;
6185: my $numinrow = 4;
6186: my $itemcount = 1;
6187: my $datatable;
1.152 raeburn 6188: my %typetitles = &sparestype_titles();
6189: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 6190: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 6191: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
6192: my ($othercontrol,$serverdom);
6193: if ($serverhome ne $server) {
6194: $serverdom = &Apache::lonnet::host_domain($serverhome);
6195: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6196: } else {
6197: $serverdom = &Apache::lonnet::host_domain($server);
6198: if ($serverdom ne $dom) {
6199: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6200: }
6201: }
6202: next unless (ref($spareid->{$server}) eq 'HASH');
1.261 raeburn 6203: my $checkednow;
6204: if (ref($curroffloadnow) eq 'HASH') {
6205: if ($curroffloadnow->{$server}) {
6206: $checkednow = ' checked="checked"';
6207: }
6208: }
1.145 raeburn 6209: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6210: $datatable .= '<tr'.$css_class.'>
6211: <td rowspan="2">
1.183 bisitz 6212: <span class="LC_nobreak">'.
6213: &mt('[_1] when busy, offloads to:'
1.261 raeburn 6214: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 6215: '<span class="LC_nobreak">'."\n".
1.261 raeburn 6216: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
6217: ' '.&mt('Switch active users on next access').'</label></span>'.
1.183 bisitz 6218: "\n";
1.145 raeburn 6219: my (%current,%canselect);
1.152 raeburn 6220: my @choices =
6221: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
6222: foreach my $type ('primary','default') {
6223: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 6224: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
6225: my @spares = @{$spareid->{$server}{$type}};
6226: if (@spares > 0) {
1.152 raeburn 6227: if ($othercontrol) {
6228: $current{$type} = join(', ',@spares);
6229: } else {
6230: $current{$type} .= '<table>';
6231: my $numspares = scalar(@spares);
6232: for (my $i=0; $i<@spares; $i++) {
6233: my $rem = $i%($numinrow);
6234: if ($rem == 0) {
6235: if ($i > 0) {
6236: $current{$type} .= '</tr>';
6237: }
6238: $current{$type} .= '<tr>';
1.145 raeburn 6239: }
1.152 raeburn 6240: $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'".');" /> '.
6241: $spareid->{$server}{$type}[$i].
6242: '</label></td>'."\n";
6243: }
6244: my $rem = @spares%($numinrow);
6245: my $colsleft = $numinrow - $rem;
6246: if ($colsleft > 1 ) {
6247: $current{$type} .= '<td colspan="'.$colsleft.
6248: '" class="LC_left_item">'.
6249: ' </td>';
6250: } elsif ($colsleft == 1) {
6251: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 6252: }
1.152 raeburn 6253: $current{$type} .= '</tr></table>';
1.150 raeburn 6254: }
1.145 raeburn 6255: }
6256: }
6257: if ($current{$type} eq '') {
6258: $current{$type} = &mt('None specified');
6259: }
1.152 raeburn 6260: if ($othercontrol) {
6261: if ($type eq 'primary') {
6262: $canselect{$type} = $othercontrol;
6263: }
6264: } else {
6265: $canselect{$type} =
6266: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
6267: '<select name="newspare_'.$type.'_'.$server.'" '.
6268: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
6269: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
6270: if (@choices > 0) {
6271: foreach my $lonhost (@choices) {
6272: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
6273: }
6274: }
6275: $canselect{$type} .= '</select>'."\n";
6276: }
6277: } else {
6278: $current{$type} = &mt('Could not be determined');
6279: if ($type eq 'primary') {
6280: $canselect{$type} = $othercontrol;
6281: }
1.145 raeburn 6282: }
1.152 raeburn 6283: if ($type eq 'default') {
6284: $datatable .= '<tr'.$css_class.'>';
6285: }
6286: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
6287: '<td>'.$current{$type}.'</td>'."\n".
6288: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 6289: }
6290: $itemcount ++;
6291: }
6292: }
6293: $$rowtotal += $itemcount;
6294: return $datatable;
6295: }
6296:
1.152 raeburn 6297: sub possible_newspares {
6298: my ($server,$currspares,$serverhomes,$altids) = @_;
6299: my $serverhostname = &Apache::lonnet::hostname($server);
6300: my %excluded;
6301: if ($serverhostname ne '') {
6302: %excluded = (
6303: $serverhostname => 1,
6304: );
6305: }
6306: if (ref($currspares) eq 'HASH') {
6307: foreach my $type (keys(%{$currspares})) {
6308: if (ref($currspares->{$type}) eq 'ARRAY') {
6309: if (@{$currspares->{$type}} > 0) {
6310: foreach my $curr (@{$currspares->{$type}}) {
6311: my $hostname = &Apache::lonnet::hostname($curr);
6312: $excluded{$hostname} = 1;
6313: }
6314: }
6315: }
6316: }
6317: }
6318: my @choices;
6319: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
6320: if (keys(%{$serverhomes}) > 1) {
6321: foreach my $name (sort(keys(%{$serverhomes}))) {
6322: unless ($excluded{$name}) {
6323: if (exists($altids->{$serverhomes->{$name}})) {
6324: push(@choices,$altids->{$serverhomes->{$name}});
6325: } else {
6326: push(@choices,$serverhomes->{$name});
1.145 raeburn 6327: }
6328: }
6329: }
6330: }
6331: }
1.152 raeburn 6332: return sort(@choices);
1.145 raeburn 6333: }
6334:
1.150 raeburn 6335: sub print_loadbalancing {
6336: my ($dom,$settings,$rowtotal) = @_;
6337: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6338: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6339: my $numinrow = 1;
6340: my $datatable;
6341: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 6342: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 6343: if (ref($settings) eq 'HASH') {
6344: %existing = %{$settings};
6345: }
6346: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
6347: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 6348: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 6349: } else {
6350: return;
6351: }
6352: my ($othertitle,$usertypes,$types) =
6353: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 6354: my $rownum = 8;
1.150 raeburn 6355: if (ref($types) eq 'ARRAY') {
6356: $rownum += scalar(@{$types});
6357: }
1.171 raeburn 6358: my @css_class = ('LC_odd_row','LC_even_row');
6359: my $balnum = 0;
6360: my $islast;
6361: my (@toshow,$disabledtext);
6362: if (keys(%currbalancer) > 0) {
6363: @toshow = sort(keys(%currbalancer));
6364: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
6365: push(@toshow,'');
6366: }
6367: } else {
6368: @toshow = ('');
6369: $disabledtext = &mt('No existing load balancer');
6370: }
6371: foreach my $lonhost (@toshow) {
6372: if ($balnum == scalar(@toshow)-1) {
6373: $islast = 1;
6374: } else {
6375: $islast = 0;
6376: }
6377: my $cssidx = $balnum%2;
6378: my $targets_div_style = 'display: none';
6379: my $disabled_div_style = 'display: block';
6380: my $homedom_div_style = 'display: none';
6381: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 6382: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 6383: '<p>';
6384: if ($lonhost eq '') {
1.210 raeburn 6385: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 6386: if (keys(%currbalancer) > 0) {
6387: $datatable .= &mt('Add balancer:');
6388: } else {
6389: $datatable .= &mt('Enable balancer:');
6390: }
6391: $datatable .= ' '.
6392: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
6393: ' id="loadbalancing_lonhost_'.$balnum.'"'.
6394: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
6395: '<option value="" selected="selected">'.&mt('None').
6396: '</option>'."\n";
6397: foreach my $server (sort(keys(%servers))) {
6398: next if ($currbalancer{$server});
6399: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
6400: }
1.210 raeburn 6401: $datatable .=
1.171 raeburn 6402: '</select>'."\n".
6403: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
6404: } else {
6405: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
6406: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
6407: &mt('Stop balancing').'</label>'.
6408: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
6409: $targets_div_style = 'display: block';
6410: $disabled_div_style = 'display: none';
6411: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
6412: $homedom_div_style = 'display: block';
6413: }
6414: }
1.306 raeburn 6415: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 6416: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
6417: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
6418: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
6419: my ($numspares,@spares) = &count_servers($lonhost,%servers);
6420: my @sparestypes = ('primary','default');
6421: my %typetitles = &sparestype_titles();
1.284 raeburn 6422: my %hostherechecked = (
6423: no => ' checked="checked"',
6424: );
1.342 raeburn 6425: my %balcookiechecked = (
6426: no => ' checked="checked"',
6427: );
1.171 raeburn 6428: foreach my $sparetype (@sparestypes) {
6429: my $targettable;
6430: for (my $i=0; $i<$numspares; $i++) {
6431: my $checked;
6432: if (ref($currtargets{$lonhost}) eq 'HASH') {
6433: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6434: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6435: $checked = ' checked="checked"';
6436: }
6437: }
6438: }
6439: my ($chkboxval,$disabled);
6440: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
6441: $chkboxval = $spares[$i];
6442: }
6443: if (exists($currbalancer{$spares[$i]})) {
6444: $disabled = ' disabled="disabled"';
6445: }
1.210 raeburn 6446: $targettable .=
1.253 raeburn 6447: '<td><span class="LC_nobreak"><label>'.
6448: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 6449: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
1.253 raeburn 6450: '</span></label></span></td>';
1.171 raeburn 6451: my $rem = $i%($numinrow);
6452: if ($rem == 0) {
6453: if (($i > 0) && ($i < $numspares-1)) {
6454: $targettable .= '</tr>';
6455: }
6456: if ($i < $numspares-1) {
6457: $targettable .= '<tr>';
1.150 raeburn 6458: }
6459: }
6460: }
1.171 raeburn 6461: if ($targettable ne '') {
6462: my $rem = $numspares%($numinrow);
6463: my $colsleft = $numinrow - $rem;
6464: if ($colsleft > 1 ) {
6465: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6466: ' </td>';
6467: } elsif ($colsleft == 1) {
6468: $targettable .= '<td class="LC_left_item"> </td>';
6469: }
6470: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
6471: '<table><tr>'.$targettable.'</tr></table><br />';
6472: }
1.284 raeburn 6473: $hostherechecked{$sparetype} = '';
6474: if (ref($currtargets{$lonhost}) eq 'HASH') {
6475: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6476: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6477: $hostherechecked{$sparetype} = ' checked="checked"';
6478: $hostherechecked{'no'} = '';
6479: }
6480: }
6481: }
6482: }
1.342 raeburn 6483: if ($currcookies{$lonhost}) {
6484: %balcookiechecked = (
6485: yes => ' checked="checked"',
6486: );
6487: }
1.284 raeburn 6488: $datatable .= &mt('Hosting on balancer itself').'<br />'.
6489: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
6490: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
6491: foreach my $sparetype (@sparestypes) {
6492: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
6493: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
6494: '</i></label><br />';
1.171 raeburn 6495: }
1.342 raeburn 6496: $datatable .= &mt('Use balancer cookie').'<br />'.
6497: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
6498: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
6499: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
6500: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
6501: '</div></td></tr>'.
1.171 raeburn 6502: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
6503: $othertitle,$usertypes,$types,\%servers,
6504: \%currbalancer,$lonhost,
6505: $targets_div_style,$homedom_div_style,
6506: $css_class[$cssidx],$balnum,$islast);
6507: $$rowtotal += $rownum;
6508: $balnum ++;
6509: }
6510: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
6511: return $datatable;
6512: }
6513:
6514: sub get_loadbalancers_config {
1.342 raeburn 6515: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 6516: return unless ((ref($servers) eq 'HASH') &&
6517: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 6518: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
6519: (ref($currcookies) eq 'HASH'));
1.171 raeburn 6520: if (keys(%{$existing}) > 0) {
6521: my $oldlonhost;
6522: foreach my $key (sort(keys(%{$existing}))) {
6523: if ($key eq 'lonhost') {
6524: $oldlonhost = $existing->{'lonhost'};
6525: $currbalancer->{$oldlonhost} = 1;
6526: } elsif ($key eq 'targets') {
6527: if ($oldlonhost) {
6528: $currtargets->{$oldlonhost} = $existing->{'targets'};
6529: }
6530: } elsif ($key eq 'rules') {
6531: if ($oldlonhost) {
6532: $currrules->{$oldlonhost} = $existing->{'rules'};
6533: }
6534: } elsif (ref($existing->{$key}) eq 'HASH') {
6535: $currbalancer->{$key} = 1;
6536: $currtargets->{$key} = $existing->{$key}{'targets'};
6537: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 6538: if ($existing->{$key}{'cookie'}) {
6539: $currcookies->{$key} = 1;
6540: }
1.150 raeburn 6541: }
6542: }
1.171 raeburn 6543: } else {
6544: my ($balancerref,$targetsref) =
6545: &Apache::lonnet::get_lonbalancer_config($servers);
6546: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
6547: foreach my $server (sort(keys(%{$balancerref}))) {
6548: $currbalancer->{$server} = 1;
6549: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 6550: }
6551: }
6552: }
1.171 raeburn 6553: return;
1.150 raeburn 6554: }
6555:
6556: sub loadbalancing_rules {
6557: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 6558: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
6559: $css_class,$balnum,$islast) = @_;
1.150 raeburn 6560: my $output;
1.171 raeburn 6561: my $num = 0;
1.210 raeburn 6562: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 6563: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
6564: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
6565: foreach my $type (@{$alltypes}) {
1.171 raeburn 6566: $num ++;
1.150 raeburn 6567: my $current;
6568: if (ref($currrules) eq 'HASH') {
6569: $current = $currrules->{$type};
6570: }
1.253 raeburn 6571: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 6572: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 6573: $current = '';
6574: }
6575: }
6576: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 6577: $servers,$currbalancer,$lonhost,$dom,
6578: $targets_div_style,$homedom_div_style,
6579: $css_class,$balnum,$num,$islast);
1.150 raeburn 6580: }
6581: }
6582: return $output;
6583: }
6584:
6585: sub loadbalancing_titles {
6586: my ($dom,$intdom,$usertypes,$types) = @_;
6587: my %othertypes = (
6588: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
6589: '_LC_author' => &mt('Users from [_1] with author role',$dom),
6590: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
6591: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 6592: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
6593: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 6594: );
1.209 raeburn 6595: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 6596: my @available;
1.150 raeburn 6597: if (ref($types) eq 'ARRAY') {
1.302 raeburn 6598: @available = @{$types};
1.150 raeburn 6599: }
1.302 raeburn 6600: unless (grep(/^default$/,@available)) {
6601: push(@available,'default');
6602: }
6603: unshift(@alltypes,@available);
1.150 raeburn 6604: my %titles;
6605: foreach my $type (@alltypes) {
6606: if ($type =~ /^_LC_/) {
6607: $titles{$type} = $othertypes{$type};
6608: } elsif ($type eq 'default') {
6609: $titles{$type} = &mt('All users from [_1]',$dom);
6610: if (ref($types) eq 'ARRAY') {
6611: if (@{$types} > 0) {
6612: $titles{$type} = &mt('Other users from [_1]',$dom);
6613: }
6614: }
6615: } elsif (ref($usertypes) eq 'HASH') {
6616: $titles{$type} = $usertypes->{$type};
6617: }
6618: }
6619: return (\@alltypes,\%othertypes,\%titles);
6620: }
6621:
6622: sub loadbalance_rule_row {
1.171 raeburn 6623: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
6624: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 6625: my @rulenames;
1.150 raeburn 6626: my %ruletitles = &offloadtype_text();
1.209 raeburn 6627: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 6628: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 6629: } else {
1.209 raeburn 6630: @rulenames = ('default','homeserver');
6631: if ($type eq '_LC_external') {
6632: push(@rulenames,'externalbalancer');
6633: } else {
6634: push(@rulenames,'specific');
6635: }
6636: push(@rulenames,'none');
1.150 raeburn 6637: }
6638: my $style = $targets_div_style;
1.253 raeburn 6639: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 6640: $style = $homedom_div_style;
6641: }
1.171 raeburn 6642: my $space;
6643: if ($islast && $num == 1) {
1.317 raeburn 6644: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 6645: }
1.210 raeburn 6646: my $output =
1.306 raeburn 6647: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 6648: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
6649: '<td valaign="top">'.$space.
6650: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 6651: for (my $i=0; $i<@rulenames; $i++) {
6652: my $rule = $rulenames[$i];
6653: my ($checked,$extra);
6654: if ($rulenames[$i] eq 'default') {
6655: $rule = '';
6656: }
6657: if ($rulenames[$i] eq 'specific') {
6658: if (ref($servers) eq 'HASH') {
6659: my $default;
6660: if (($current ne '') && (exists($servers->{$current}))) {
6661: $checked = ' checked="checked"';
6662: }
6663: unless ($checked) {
6664: $default = ' selected="selected"';
6665: }
1.210 raeburn 6666: $extra =
1.171 raeburn 6667: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
6668: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
6669: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
6670: '<option value=""'.$default.'></option>'."\n";
6671: foreach my $server (sort(keys(%{$servers}))) {
6672: if (ref($currbalancer) eq 'HASH') {
6673: next if (exists($currbalancer->{$server}));
6674: }
1.150 raeburn 6675: my $selected;
1.171 raeburn 6676: if ($server eq $current) {
1.150 raeburn 6677: $selected = ' selected="selected"';
6678: }
1.171 raeburn 6679: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 6680: }
6681: $extra .= '</select>';
6682: }
6683: } elsif ($rule eq $current) {
6684: $checked = ' checked="checked"';
6685: }
6686: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 6687: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
6688: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
6689: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 6690: ')"'.$checked.' /> ';
6691: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
6692: $output .= $ruletitles{'particular'};
6693: } else {
6694: $output .= $ruletitles{$rulenames[$i]};
6695: }
6696: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 6697: }
6698: $output .= '</div></td></tr>'."\n";
6699: return $output;
6700: }
6701:
6702: sub offloadtype_text {
6703: my %ruletitles = &Apache::lonlocal::texthash (
6704: 'default' => 'Offloads to default destinations',
6705: 'homeserver' => "Offloads to user's home server",
6706: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
6707: 'specific' => 'Offloads to specific server',
1.161 raeburn 6708: 'none' => 'No offload',
1.209 raeburn 6709: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
6710: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 6711: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 6712: );
6713: return %ruletitles;
6714: }
6715:
6716: sub sparestype_titles {
6717: my %typestitles = &Apache::lonlocal::texthash (
6718: 'primary' => 'primary',
6719: 'default' => 'default',
6720: );
6721: return %typestitles;
6722: }
6723:
1.28 raeburn 6724: sub contact_titles {
6725: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 6726: 'supportemail' => 'Support E-mail address',
6727: 'adminemail' => 'Default Server Admin E-mail address',
6728: 'errormail' => 'Error reports to be e-mailed to',
6729: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 6730: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
6731: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 6732: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
6733: 'requestsmail' => 'E-mail from course requests requiring approval',
6734: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 6735: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.340 raeburn 6736: 'errorthreshold' => 'Error/warning threshold for status e-mail',
6737: 'errorsysmail' => 'Error threshold for e-mail to core group',
6738: 'errorweights' => 'Weights used to compute error count',
6739: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 6740: );
6741: my %short_titles = &Apache::lonlocal::texthash (
6742: adminemail => 'Admin E-mail address',
6743: supportemail => 'Support E-mail',
6744: );
6745: return (\%titles,\%short_titles);
6746: }
6747:
1.286 raeburn 6748: sub helpform_fields {
6749: my %titles = &Apache::lonlocal::texthash (
6750: 'username' => 'Name',
6751: 'user' => 'Username/domain',
6752: 'phone' => 'Phone',
6753: 'cc' => 'Cc e-mail',
6754: 'course' => 'Course Details',
6755: 'section' => 'Sections',
1.289 raeburn 6756: 'screenshot' => 'File upload',
1.286 raeburn 6757: );
6758: my @fields = ('username','phone','user','course','section','cc','screenshot');
6759: my %possoptions = (
6760: username => ['yes','no','req'],
1.289 raeburn 6761: phone => ['yes','no','req'],
1.286 raeburn 6762: user => ['yes','no'],
1.289 raeburn 6763: cc => ['yes','no'],
1.286 raeburn 6764: course => ['yes','no'],
6765: section => ['yes','no'],
6766: screenshot => ['yes','no'],
6767: );
6768: my %fieldoptions = &Apache::lonlocal::texthash (
6769: 'yes' => 'Optional',
6770: 'req' => 'Required',
6771: 'no' => "Not shown",
6772: );
6773: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
6774: }
6775:
1.72 raeburn 6776: sub tool_titles {
6777: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 6778: aboutme => 'Personal web page',
1.86 raeburn 6779: blog => 'Blog',
1.162 raeburn 6780: webdav => 'WebDAV',
1.86 raeburn 6781: portfolio => 'Portfolio',
1.88 bisitz 6782: official => 'Official courses (with institutional codes)',
6783: unofficial => 'Unofficial courses',
1.98 raeburn 6784: community => 'Communities',
1.216 raeburn 6785: textbook => 'Textbook courses',
1.271 raeburn 6786: placement => 'Placement tests',
1.86 raeburn 6787: );
1.72 raeburn 6788: return %titles;
6789: }
6790:
1.101 raeburn 6791: sub courserequest_titles {
6792: my %titles = &Apache::lonlocal::texthash (
6793: official => 'Official',
6794: unofficial => 'Unofficial',
6795: community => 'Communities',
1.216 raeburn 6796: textbook => 'Textbook',
1.271 raeburn 6797: placement => 'Placement tests',
1.325 raeburn 6798: lti => 'LTI Provider',
1.101 raeburn 6799: norequest => 'Not allowed',
1.325 raeburn 6800: approval => 'Approval by DC',
1.101 raeburn 6801: validate => 'With validation',
6802: autolimit => 'Numerical limit',
1.103 raeburn 6803: unlimited => '(blank for unlimited)',
1.101 raeburn 6804: );
6805: return %titles;
6806: }
6807:
1.163 raeburn 6808: sub authorrequest_titles {
6809: my %titles = &Apache::lonlocal::texthash (
6810: norequest => 'Not allowed',
6811: approval => 'Approval by Dom. Coord.',
6812: automatic => 'Automatic approval',
6813: );
6814: return %titles;
1.210 raeburn 6815: }
1.163 raeburn 6816:
1.101 raeburn 6817: sub courserequest_conditions {
6818: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 6819: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 6820: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 6821: );
6822: return %conditions;
6823: }
6824:
6825:
1.27 raeburn 6826: sub print_usercreation {
1.30 raeburn 6827: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 6828: my $numinrow = 4;
1.28 raeburn 6829: my $datatable;
6830: if ($position eq 'top') {
1.30 raeburn 6831: $$rowtotal ++;
1.34 raeburn 6832: my $rowcount = 0;
1.32 raeburn 6833: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 6834: if (ref($rules) eq 'HASH') {
6835: if (keys(%{$rules}) > 0) {
1.32 raeburn 6836: $datatable .= &user_formats_row('username',$settings,$rules,
6837: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 6838: $$rowtotal ++;
1.32 raeburn 6839: $rowcount ++;
6840: }
6841: }
6842: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
6843: if (ref($idrules) eq 'HASH') {
6844: if (keys(%{$idrules}) > 0) {
6845: $datatable .= &user_formats_row('id',$settings,$idrules,
6846: $idruleorder,$numinrow,$rowcount);
6847: $$rowtotal ++;
6848: $rowcount ++;
1.28 raeburn 6849: }
6850: }
1.39 raeburn 6851: if ($rowcount == 0) {
6852: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
6853: $$rowtotal ++;
6854: $rowcount ++;
6855: }
1.34 raeburn 6856: } elsif ($position eq 'middle') {
1.224 raeburn 6857: my @creators = ('author','course','requestcrs');
1.37 raeburn 6858: my ($rules,$ruleorder) =
6859: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 6860: my %lt = &usercreation_types();
6861: my %checked;
6862: if (ref($settings) eq 'HASH') {
6863: if (ref($settings->{'cancreate'}) eq 'HASH') {
6864: foreach my $item (@creators) {
6865: $checked{$item} = $settings->{'cancreate'}{$item};
6866: }
6867: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
6868: foreach my $item (@creators) {
6869: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
6870: $checked{$item} = 'none';
6871: }
6872: }
6873: }
6874: }
6875: my $rownum = 0;
6876: foreach my $item (@creators) {
6877: $rownum ++;
1.224 raeburn 6878: if ($checked{$item} eq '') {
6879: $checked{$item} = 'any';
1.34 raeburn 6880: }
6881: my $css_class;
6882: if ($rownum%2) {
6883: $css_class = '';
6884: } else {
6885: $css_class = ' class="LC_odd_row" ';
6886: }
6887: $datatable .= '<tr'.$css_class.'>'.
6888: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 6889: '</span></td><td style="text-align: right">';
1.224 raeburn 6890: my @options = ('any');
6891: if (ref($rules) eq 'HASH') {
6892: if (keys(%{$rules}) > 0) {
6893: push(@options,('official','unofficial'));
1.37 raeburn 6894: }
6895: }
1.224 raeburn 6896: push(@options,'none');
1.37 raeburn 6897: foreach my $option (@options) {
1.50 raeburn 6898: my $type = 'radio';
1.34 raeburn 6899: my $check = ' ';
1.224 raeburn 6900: if ($checked{$item} eq $option) {
6901: $check = ' checked="checked" ';
1.34 raeburn 6902: }
6903: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 6904: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 6905: $item.'" value="'.$option.'"'.$check.'/> '.
6906: $lt{$option}.'</label> </span>';
6907: }
6908: $datatable .= '</td></tr>';
6909: }
1.28 raeburn 6910: } else {
6911: my @contexts = ('author','course','domain');
1.325 raeburn 6912: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 6913: my %checked;
6914: if (ref($settings) eq 'HASH') {
6915: if (ref($settings->{'authtypes'}) eq 'HASH') {
6916: foreach my $item (@contexts) {
6917: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
6918: foreach my $auth (@authtypes) {
6919: if ($settings->{'authtypes'}{$item}{$auth}) {
6920: $checked{$item}{$auth} = ' checked="checked" ';
6921: }
6922: }
6923: }
6924: }
1.27 raeburn 6925: }
1.35 raeburn 6926: } else {
6927: foreach my $item (@contexts) {
1.36 raeburn 6928: foreach my $auth (@authtypes) {
1.35 raeburn 6929: $checked{$item}{$auth} = ' checked="checked" ';
6930: }
6931: }
1.27 raeburn 6932: }
1.28 raeburn 6933: my %title = &context_names();
6934: my %authname = &authtype_names();
6935: my $rownum = 0;
6936: my $css_class;
6937: foreach my $item (@contexts) {
6938: if ($rownum%2) {
6939: $css_class = '';
6940: } else {
6941: $css_class = ' class="LC_odd_row" ';
6942: }
1.30 raeburn 6943: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 6944: '<td>'.$title{$item}.
6945: '</td><td class="LC_left_item">'.
6946: '<span class="LC_nobreak">';
6947: foreach my $auth (@authtypes) {
6948: $datatable .= '<label>'.
6949: '<input type="checkbox" name="'.$item.'_auth" '.
6950: $checked{$item}{$auth}.' value="'.$auth.'" />'.
6951: $authname{$auth}.'</label> ';
6952: }
6953: $datatable .= '</span></td></tr>';
6954: $rownum ++;
1.27 raeburn 6955: }
1.30 raeburn 6956: $$rowtotal += $rownum;
1.27 raeburn 6957: }
6958: return $datatable;
6959: }
6960:
1.224 raeburn 6961: sub print_selfcreation {
6962: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 6963: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
6964: $emaildomain,$datatable);
1.224 raeburn 6965: if (ref($settings) eq 'HASH') {
6966: if (ref($settings->{'cancreate'}) eq 'HASH') {
6967: $createsettings = $settings->{'cancreate'};
1.236 raeburn 6968: if (ref($createsettings) eq 'HASH') {
6969: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
6970: @selfcreate = @{$createsettings->{'selfcreate'}};
6971: } elsif ($createsettings->{'selfcreate'} ne '') {
6972: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
6973: @selfcreate = ('email','login','sso');
6974: } elsif ($createsettings->{'selfcreate'} ne 'none') {
6975: @selfcreate = ($createsettings->{'selfcreate'});
6976: }
6977: }
6978: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
6979: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 6980: }
1.305 raeburn 6981: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
6982: $emailoptions = $createsettings->{'emailoptions'};
6983: }
1.303 raeburn 6984: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
6985: $emailverified = $createsettings->{'emailverified'};
6986: }
6987: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
6988: $emaildomain = $createsettings->{'emaildomain'};
6989: }
1.224 raeburn 6990: }
6991: }
6992: }
6993: my %radiohash;
6994: my $numinrow = 4;
6995: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 6996: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 6997: if ($position eq 'top') {
6998: my %choices = &Apache::lonlocal::texthash (
6999: cancreate_login => 'Institutional Login',
7000: cancreate_sso => 'Institutional Single Sign On',
7001: );
7002: my @toggles = sort(keys(%choices));
7003: my %defaultchecked = (
7004: 'cancreate_login' => 'off',
7005: 'cancreate_sso' => 'off',
7006: );
1.228 raeburn 7007: my ($onclick,$itemcount);
1.224 raeburn 7008: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
7009: \%choices,$itemcount,$onclick);
1.228 raeburn 7010: $$rowtotal += $itemcount;
7011:
1.224 raeburn 7012: if (ref($usertypes) eq 'HASH') {
7013: if (keys(%{$usertypes}) > 0) {
7014: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
7015: $dom,$numinrow,$othertitle,
1.305 raeburn 7016: 'statustocreate',$rowtotal);
1.224 raeburn 7017: $$rowtotal ++;
7018: }
7019: }
1.240 raeburn 7020: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
7021: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7022: $fieldtitles{'inststatus'} = &mt('Institutional status');
7023: my $rem;
7024: my $numperrow = 2;
7025: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
7026: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 7027: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 7028: '<td class="LC_left_item">'."\n".
1.334 raeburn 7029: '<table>'."\n";
1.240 raeburn 7030: for (my $i=0; $i<@fields; $i++) {
7031: $rem = $i%($numperrow);
7032: if ($rem == 0) {
7033: if ($i > 0) {
7034: $datatable .= '</tr>';
7035: }
7036: $datatable .= '<tr>';
7037: }
7038: my $currval;
1.248 raeburn 7039: if (ref($createsettings) eq 'HASH') {
7040: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
7041: $currval = $createsettings->{'shibenv'}{$fields[$i]};
7042: }
1.240 raeburn 7043: }
7044: $datatable .= '<td class="LC_left_item">'.
7045: '<span class="LC_nobreak">'.
7046: '<input type="text" name="shibenv_'.$fields[$i].'" '.
7047: 'value="'.$currval.'" size="10" /> '.
7048: $fieldtitles{$fields[$i]}.'</span></td>';
7049: }
7050: my $colsleft = $numperrow - $rem;
7051: if ($colsleft > 1 ) {
7052: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7053: ' </td>';
7054: } elsif ($colsleft == 1) {
7055: $datatable .= '<td class="LC_left_item"> </td>';
7056: }
7057: $datatable .= '</tr></table></td></tr>';
7058: $$rowtotal ++;
1.224 raeburn 7059: } elsif ($position eq 'middle') {
7060: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 7061: my @posstypes;
1.224 raeburn 7062: if (ref($types) eq 'ARRAY') {
1.302 raeburn 7063: @posstypes = @{$types};
7064: }
7065: unless (grep(/^default$/,@posstypes)) {
7066: push(@posstypes,'default');
7067: }
7068: my %usertypeshash;
7069: if (ref($usertypes) eq 'HASH') {
7070: %usertypeshash = %{$usertypes};
7071: }
7072: $usertypeshash{'default'} = $othertitle;
7073: foreach my $status (@posstypes) {
7074: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
7075: $numinrow,$$rowtotal,\%usertypeshash);
7076: $$rowtotal ++;
1.224 raeburn 7077: }
7078: } else {
1.236 raeburn 7079: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 7080: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 7081: );
7082: my @toggles = sort(keys(%choices));
7083: my %defaultchecked = (
7084: 'cancreate_email' => 'off',
7085: );
1.305 raeburn 7086: my $customclass = 'LC_selfcreate_email';
7087: my $classprefix = 'LC_canmodify_emailusername_';
7088: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 7089: my $display = 'none';
1.305 raeburn 7090: my $rowstyle = 'display:none';
1.236 raeburn 7091: if (grep(/^\Qemail\E$/,@selfcreate)) {
7092: $display = 'block';
1.305 raeburn 7093: $rowstyle = 'display:table-row';
1.236 raeburn 7094: }
1.305 raeburn 7095: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
7096: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
7097: \%choices,$$rowtotal,$onclick);
7098: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
7099: $rowstyle);
7100: $$rowtotal ++;
7101: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
7102: $rowstyle);
7103: $$rowtotal ++;
7104: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 7105: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 7106: my ($emailrules,$emailruleorder) =
7107: &Apache::lonnet::inst_userrules($dom,'email');
7108: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7109: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7110: if (ref($types) eq 'ARRAY') {
7111: @posstypes = @{$types};
7112: }
7113: if (@posstypes) {
7114: unless (grep(/^default$/,@posstypes)) {
7115: push(@posstypes,'default');
1.302 raeburn 7116: }
7117: if (ref($usertypes) eq 'HASH') {
7118: %usertypeshash = %{$usertypes};
7119: }
1.305 raeburn 7120: my $currassign;
7121: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
7122: $currassign = {
7123: selfassign => $domdefaults{'inststatusguest'},
7124: };
7125: @ordered = @{$domdefaults{'inststatusguest'}};
7126: } else {
7127: $currassign = { selfassign => [] };
7128: }
7129: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
7130: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
7131: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
7132: $numinrow,$othertitle,'selfassign',
7133: $rowtotal,$onclicktypes,$customclass,
7134: $rowstyle);
7135: $$rowtotal ++;
1.302 raeburn 7136: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 7137: foreach my $status (@posstypes) {
7138: my $css_class;
7139: if ($$rowtotal%2) {
7140: $css_class = 'LC_odd_row ';
7141: }
7142: $css_class .= $customclass;
7143: my $rowid = $optionsprefix.$status;
7144: my $hidden = 1;
7145: my $currstyle = 'display:none';
7146: if (grep(/^\Q$status\E$/,@ordered)) {
7147: $currstyle = $rowstyle;
7148: $hidden = 0;
7149: }
7150: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7151: $emailrules,$emailruleorder,$settings,$status,$rowid,
7152: $usertypeshash{$status},$css_class,$currstyle,$intdom);
7153: unless ($hidden) {
7154: $$rowtotal ++;
7155: }
1.224 raeburn 7156: }
1.302 raeburn 7157: } else {
1.305 raeburn 7158: my $css_class;
7159: if ($$rowtotal%2) {
7160: $css_class = 'LC_odd_row ';
7161: }
7162: $css_class .= $customclass;
1.302 raeburn 7163: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 7164: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7165: $emailrules,$emailruleorder,$settings,'default','',
7166: $othertitle,$css_class,$rowstyle,$intdom);
7167: $$rowtotal ++;
1.224 raeburn 7168: }
7169: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 7170: $numinrow = 1;
1.305 raeburn 7171: if (@posstypes) {
7172: foreach my $status (@posstypes) {
7173: my $rowid = $classprefix.$status;
7174: my $datarowstyle = 'display:none';
7175: if (grep(/^\Q$status\E$/,@ordered)) {
7176: $datarowstyle = $rowstyle;
7177: }
7178: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
7179: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7180: $infotitles,$rowid,$customclass,$datarowstyle);
7181: unless ($datarowstyle eq 'display:none') {
7182: $$rowtotal ++;
7183: }
1.224 raeburn 7184: }
1.305 raeburn 7185: } else {
7186: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
7187: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7188: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 7189: }
7190: }
7191: return $datatable;
7192: }
7193:
1.305 raeburn 7194: sub selfcreate_javascript {
7195: return <<"ENDSCRIPT";
7196:
7197: <script type="text/javascript">
7198: // <![CDATA[
7199:
7200: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
7201: var x = document.getElementsByClassName(target);
7202: var insttypes = 0;
7203: var insttypeRegExp = new RegExp(prefix);
7204: if ((x.length != undefined) && (x.length > 0)) {
7205: if (form.elements[radio].length != undefined) {
7206: for (var i=0; i<form.elements[radio].length; i++) {
7207: if (form.elements[radio][i].checked) {
7208: if (form.elements[radio][i].value == 1) {
7209: for (var j=0; j<x.length; j++) {
7210: if (x[j].id == 'undefined') {
7211: x[j].style.display = 'table-row';
7212: } else if (insttypeRegExp.test(x[j].id)) {
7213: insttypes ++;
7214: } else {
7215: x[j].style.display = 'table-row';
7216: }
7217: }
7218: } else {
7219: for (var j=0; j<x.length; j++) {
7220: x[j].style.display = 'none';
7221: }
1.236 raeburn 7222: }
1.305 raeburn 7223: break;
7224: }
7225: }
7226: if (insttypes > 0) {
7227: toggleDataRow(form,checkbox,target,altprefix);
7228: toggleDataRow(form,checkbox,target,prefix,1);
7229: }
7230: }
7231: }
7232: return;
7233: }
7234:
7235: function toggleDataRow(form,checkbox,target,prefix,docount) {
7236: if (form.elements[checkbox].length != undefined) {
7237: var count = 0;
7238: if (docount) {
7239: for (var i=0; i<form.elements[checkbox].length; i++) {
7240: if (form.elements[checkbox][i].checked) {
7241: count ++;
1.236 raeburn 7242: }
1.305 raeburn 7243: }
7244: }
7245: for (var i=0; i<form.elements[checkbox].length; i++) {
7246: var type = form.elements[checkbox][i].value;
7247: if (document.getElementById(prefix+type)) {
7248: if (form.elements[checkbox][i].checked) {
7249: document.getElementById(prefix+type).style.display = 'table-row';
7250: if (count % 2 == 1) {
7251: document.getElementById(prefix+type).className = target+' LC_odd_row';
7252: } else {
7253: document.getElementById(prefix+type).className = target;
1.236 raeburn 7254: }
1.305 raeburn 7255: count ++;
1.236 raeburn 7256: } else {
1.305 raeburn 7257: document.getElementById(prefix+type).style.display = 'none';
7258: }
7259: }
7260: }
7261: }
7262: return;
7263: }
7264:
7265: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
7266: var caller = radio+'_'+status;
7267: if (form.elements[caller].length != undefined) {
7268: for (var i=0; i<form.elements[caller].length; i++) {
7269: if (form.elements[caller][i].checked) {
7270: if (document.getElementById(altprefix+'_inst_'+status)) {
7271: var curr = form.elements[caller][i].value;
7272: if (prefix) {
7273: document.getElementById(prefix+'_'+status).style.display = 'none';
7274: }
7275: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
7276: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
7277: if (curr == 'custom') {
7278: if (prefix) {
7279: document.getElementById(prefix+'_'+status).style.display = 'inline';
7280: }
7281: } else if (curr == 'inst') {
7282: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
7283: } else if (curr == 'noninst') {
7284: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 7285: }
1.305 raeburn 7286: break;
1.236 raeburn 7287: }
7288: }
7289: }
7290: }
7291: }
7292:
1.305 raeburn 7293: // ]]>
7294: </script>
7295:
7296: ENDSCRIPT
7297: }
7298:
7299: sub noninst_users {
7300: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
7301: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
7302: my $class = 'LC_left_item';
7303: if ($css_class) {
7304: $css_class = ' class="'.$css_class.'"';
7305: }
7306: if ($rowid) {
7307: $rowid = ' id="'.$rowid.'"';
7308: }
7309: if ($rowstyle) {
7310: $rowstyle = ' style="'.$rowstyle.'"';
7311: }
7312: my ($output,$description);
7313: if ($type eq 'default') {
7314: $description = &mt('Requests for: [_1]',$typetitle);
7315: } else {
7316: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
7317: }
7318: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
7319: "<td>$description</td>\n".
7320: '<td class="'.$class.'" colspan="2">'.
7321: '<table><tr>';
7322: my %headers = &Apache::lonlocal::texthash(
7323: approve => 'Processing',
7324: email => 'E-mail',
7325: username => 'Username',
7326: );
7327: foreach my $item ('approve','email','username') {
7328: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 7329: }
1.305 raeburn 7330: $output .= '</tr><tr>';
7331: foreach my $item ('approve','email','username') {
1.306 raeburn 7332: $output .= '<td style="vertical-align: top">';
1.305 raeburn 7333: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
7334: if ($item eq 'approve') {
7335: %choices = &Apache::lonlocal::texthash (
7336: automatic => 'Automatically approved',
7337: approval => 'Queued for approval',
7338: );
7339: @options = ('automatic','approval');
7340: $hashref = $processing;
7341: $defoption = 'automatic';
7342: $name = 'cancreate_emailprocess_'.$type;
7343: } elsif ($item eq 'email') {
7344: %choices = &Apache::lonlocal::texthash (
7345: any => 'Any e-mail',
7346: inst => 'Institutional only',
7347: noninst => 'Non-institutional only',
7348: custom => 'Custom restrictions',
7349: );
7350: @options = ('any','inst','noninst');
7351: my $showcustom;
7352: if (ref($emailrules) eq 'HASH') {
7353: if (keys(%{$emailrules}) > 0) {
7354: push(@options,'custom');
7355: $showcustom = 'cancreate_emailrule';
7356: if (ref($settings) eq 'HASH') {
7357: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
7358: foreach my $rule (@{$settings->{'email_rule'}}) {
7359: if (exists($emailrules->{$rule})) {
7360: $hascustom ++;
7361: }
7362: }
7363: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
7364: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
7365: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
7366: if (exists($emailrules->{$rule})) {
7367: $hascustom ++;
7368: }
7369: }
7370: }
7371: }
7372: }
7373: }
7374: }
7375: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
7376: "'cancreate_emaildomain','$type'".');"';
7377: $hashref = $emailoptions;
7378: $defoption = 'any';
7379: $name = 'cancreate_emailoptions_'.$type;
7380: } elsif ($item eq 'username') {
7381: %choices = &Apache::lonlocal::texthash (
7382: all => 'Same as e-mail',
7383: first => 'Omit @domain',
7384: free => 'Free to choose',
7385: );
7386: @options = ('all','first','free');
7387: $hashref = $emailverified;
7388: $defoption = 'all';
7389: $name = 'cancreate_usernameoptions_'.$type;
7390: }
7391: foreach my $option (@options) {
7392: my $checked;
7393: if (ref($hashref) eq 'HASH') {
7394: if ($type eq '') {
7395: if (!exists($hashref->{'default'})) {
7396: if ($option eq $defoption) {
7397: $checked = ' checked="checked"';
7398: }
7399: } else {
7400: if ($hashref->{'default'} eq $option) {
7401: $checked = ' checked="checked"';
7402: }
1.303 raeburn 7403: }
7404: } else {
1.305 raeburn 7405: if (!exists($hashref->{$type})) {
7406: if ($option eq $defoption) {
7407: $checked = ' checked="checked"';
7408: }
7409: } else {
7410: if ($hashref->{$type} eq $option) {
7411: $checked = ' checked="checked"';
7412: }
1.303 raeburn 7413: }
7414: }
1.305 raeburn 7415: } elsif (($item eq 'email') && ($hascustom)) {
7416: if ($option eq 'custom') {
7417: $checked = ' checked="checked"';
7418: }
7419: } elsif ($option eq $defoption) {
7420: $checked = ' checked="checked"';
7421: }
7422: $output .= '<span class="LC_nobreak"><label>'.
7423: '<input type="radio" name="'.$name.'"'.
7424: $checked.' value="'.$option.'"'.$onclick.' />'.
7425: $choices{$option}.'</label></span><br />';
7426: if ($item eq 'email') {
7427: if ($option eq 'custom') {
7428: my $id = 'cancreate_emailrule_'.$type;
7429: my $display = 'none';
7430: if ($checked) {
7431: $display = 'inline';
1.303 raeburn 7432: }
1.305 raeburn 7433: my $numinrow = 2;
7434: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
7435: '<legend>'.&mt('Disallow').'</legend><table>'.
7436: &user_formats_row('email',$settings,$emailrules,
7437: $emailruleorder,$numinrow,'',$type);
7438: '</table></fieldset>';
7439: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
7440: my %text = &Apache::lonlocal::texthash (
7441: inst => 'must end:',
7442: noninst => 'cannot end:',
7443: );
7444: my $value;
7445: if (ref($emaildomain) eq 'HASH') {
7446: if (ref($emaildomain->{$type}) eq 'HASH') {
7447: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 7448: }
7449: }
1.305 raeburn 7450: if ($value eq '') {
7451: $value = '@'.$intdom;
7452: }
7453: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
7454: my $display = 'none';
7455: if ($checked) {
7456: $display = 'inline';
7457: }
7458: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
7459: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
7460: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
7461: '</div>';
1.303 raeburn 7462: }
7463: }
7464: }
1.305 raeburn 7465: $output .= '</td>'."\n";
1.303 raeburn 7466: }
1.305 raeburn 7467: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 7468: return $output;
7469: }
7470:
1.165 raeburn 7471: sub captcha_choice {
1.305 raeburn 7472: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 7473: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
7474: $vertext,$currver);
1.165 raeburn 7475: my %lt = &captcha_phrases();
7476: $keyentry = 'hidden';
7477: if ($context eq 'cancreate') {
1.224 raeburn 7478: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 7479: } elsif ($context eq 'login') {
7480: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 7481: }
7482: if (ref($settings) eq 'HASH') {
7483: if ($settings->{'captcha'}) {
7484: $checked{$settings->{'captcha'}} = ' checked="checked"';
7485: } else {
7486: $checked{'original'} = ' checked="checked"';
7487: }
7488: if ($settings->{'captcha'} eq 'recaptcha') {
7489: $pubtext = $lt{'pub'};
7490: $privtext = $lt{'priv'};
7491: $keyentry = 'text';
1.269 raeburn 7492: $vertext = $lt{'ver'};
7493: $currver = $settings->{'recaptchaversion'};
7494: if ($currver ne '2') {
7495: $currver = 1;
7496: }
1.165 raeburn 7497: }
7498: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
7499: $currpub = $settings->{'recaptchakeys'}{'public'};
7500: $currpriv = $settings->{'recaptchakeys'}{'private'};
7501: }
7502: } else {
7503: $checked{'original'} = ' checked="checked"';
7504: }
1.305 raeburn 7505: my $css_class;
7506: if ($itemcount%2) {
7507: $css_class = 'LC_odd_row';
7508: }
7509: if ($customcss) {
7510: $css_class .= " $customcss";
7511: }
7512: $css_class =~ s/^\s+//;
7513: if ($css_class) {
7514: $css_class = ' class="'.$css_class.'"';
7515: }
7516: if ($rowstyle) {
7517: $css_class .= ' style="'.$rowstyle.'"';
7518: }
1.169 raeburn 7519: my $output = '<tr'.$css_class.'>'.
7520: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 7521: '<table><tr><td>'."\n";
7522: foreach my $option ('original','recaptcha','notused') {
7523: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
7524: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
7525: $lt{$option}.'</label></span>';
7526: unless ($option eq 'notused') {
7527: $output .= (' 'x2)."\n";
7528: }
7529: }
7530: #
7531: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
7532: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 7533: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 7534: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 7535: #
1.165 raeburn 7536: $output .= '</td></tr>'."\n".
1.305 raeburn 7537: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 7538: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
7539: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
7540: $currpub.'" size="40" /></span><br />'."\n".
7541: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
7542: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 7543: $currpriv.'" size="40" /></span><br />'.
7544: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
7545: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
7546: $currver.'" size="3" /></span><br />'.
7547: '</td></tr></table>'."\n".
1.165 raeburn 7548: '</td></tr>';
7549: return $output;
7550: }
7551:
1.32 raeburn 7552: sub user_formats_row {
1.305 raeburn 7553: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 7554: my $output;
7555: my %text = (
7556: 'username' => 'new usernames',
7557: 'id' => 'IDs',
7558: );
1.305 raeburn 7559: unless ($type eq 'email') {
7560: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
7561: $output = '<tr '.$css_class.'>'.
7562: '<td><span class="LC_nobreak">'.
7563: &mt("Format rules to check for $text{$type}: ").
7564: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 7565: }
1.27 raeburn 7566: my $rem;
7567: if (ref($ruleorder) eq 'ARRAY') {
7568: for (my $i=0; $i<@{$ruleorder}; $i++) {
7569: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
7570: my $rem = $i%($numinrow);
7571: if ($rem == 0) {
7572: if ($i > 0) {
7573: $output .= '</tr>';
7574: }
7575: $output .= '<tr>';
7576: }
7577: my $check = ' ';
1.39 raeburn 7578: if (ref($settings) eq 'HASH') {
7579: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
7580: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
7581: $check = ' checked="checked" ';
7582: }
1.305 raeburn 7583: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
7584: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
7585: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
7586: $check = ' checked="checked" ';
7587: }
7588: }
1.27 raeburn 7589: }
7590: }
1.305 raeburn 7591: my $name = $type.'_rule';
7592: if ($type eq 'email') {
7593: $name .= '_'.$status;
7594: }
1.27 raeburn 7595: $output .= '<td class="LC_left_item">'.
7596: '<span class="LC_nobreak"><label>'.
1.311 raeburn 7597: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 7598: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
7599: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
7600: }
7601: }
7602: $rem = @{$ruleorder}%($numinrow);
7603: }
1.305 raeburn 7604: my $colsleft;
7605: if ($rem) {
7606: $colsleft = $numinrow - $rem;
7607: }
1.27 raeburn 7608: if ($colsleft > 1 ) {
7609: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7610: ' </td>';
7611: } elsif ($colsleft == 1) {
7612: $output .= '<td class="LC_left_item"> </td>';
7613: }
1.305 raeburn 7614: $output .= '</tr></table>';
7615: unless ($type eq 'email') {
7616: $output .= '</td></tr>';
7617: }
1.27 raeburn 7618: return $output;
7619: }
7620:
1.34 raeburn 7621: sub usercreation_types {
7622: my %lt = &Apache::lonlocal::texthash (
7623: author => 'When adding a co-author',
7624: course => 'When adding a user to a course',
1.100 raeburn 7625: requestcrs => 'When requesting a course',
1.34 raeburn 7626: any => 'Any',
7627: official => 'Institutional only ',
7628: unofficial => 'Non-institutional only',
7629: none => 'None',
7630: );
7631: return %lt;
1.48 raeburn 7632: }
1.34 raeburn 7633:
1.224 raeburn 7634: sub selfcreation_types {
7635: my %lt = &Apache::lonlocal::texthash (
7636: selfcreate => 'User creates own account',
7637: any => 'Any',
7638: official => 'Institutional only ',
7639: unofficial => 'Non-institutional only',
7640: email => 'E-mail address',
7641: login => 'Institutional Login',
7642: sso => 'SSO',
7643: );
7644: }
7645:
1.28 raeburn 7646: sub authtype_names {
7647: my %lt = &Apache::lonlocal::texthash(
7648: int => 'Internal',
7649: krb4 => 'Kerberos 4',
7650: krb5 => 'Kerberos 5',
7651: loc => 'Local',
1.325 raeburn 7652: lti => 'LTI',
1.28 raeburn 7653: );
7654: return %lt;
7655: }
7656:
7657: sub context_names {
7658: my %context_title = &Apache::lonlocal::texthash(
7659: author => 'Creating users when an Author',
7660: course => 'Creating users when in a course',
7661: domain => 'Creating users when a Domain Coordinator',
7662: );
7663: return %context_title;
7664: }
7665:
1.33 raeburn 7666: sub print_usermodification {
7667: my ($position,$dom,$settings,$rowtotal) = @_;
7668: my $numinrow = 4;
7669: my ($context,$datatable,$rowcount);
7670: if ($position eq 'top') {
7671: $rowcount = 0;
7672: $context = 'author';
7673: foreach my $role ('ca','aa') {
7674: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7675: $numinrow,$rowcount);
7676: $$rowtotal ++;
7677: $rowcount ++;
7678: }
1.230 raeburn 7679: } elsif ($position eq 'bottom') {
1.33 raeburn 7680: $context = 'course';
7681: $rowcount = 0;
7682: foreach my $role ('st','ep','ta','in','cr') {
7683: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7684: $numinrow,$rowcount);
7685: $$rowtotal ++;
7686: $rowcount ++;
7687: }
7688: }
7689: return $datatable;
7690: }
7691:
1.43 raeburn 7692: sub print_defaults {
1.236 raeburn 7693: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 7694: my $rownum = 0;
1.294 raeburn 7695: my ($datatable,$css_class,$titles);
7696: unless ($position eq 'bottom') {
7697: $titles = &defaults_titles($dom);
7698: }
1.236 raeburn 7699: if ($position eq 'top') {
7700: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
7701: 'datelocale_def','portal_def');
7702: my %defaults;
7703: if (ref($settings) eq 'HASH') {
7704: %defaults = %{$settings};
1.43 raeburn 7705: } else {
1.236 raeburn 7706: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
7707: foreach my $item (@items) {
7708: $defaults{$item} = $domdefaults{$item};
7709: }
1.43 raeburn 7710: }
1.236 raeburn 7711: foreach my $item (@items) {
7712: if ($rownum%2) {
7713: $css_class = '';
7714: } else {
7715: $css_class = ' class="LC_odd_row" ';
7716: }
7717: $datatable .= '<tr'.$css_class.'>'.
7718: '<td><span class="LC_nobreak">'.$titles->{$item}.
7719: '</span></td><td class="LC_right_item" colspan="3">';
7720: if ($item eq 'auth_def') {
1.325 raeburn 7721: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 7722: my %shortauth = (
7723: internal => 'int',
7724: krb4 => 'krb4',
7725: krb5 => 'krb5',
1.325 raeburn 7726: localauth => 'loc',
7727: lti => 'lti',
1.236 raeburn 7728: );
7729: my %authnames = &authtype_names();
7730: foreach my $auth (@authtypes) {
7731: my $checked = ' ';
7732: if ($defaults{$item} eq $auth) {
7733: $checked = ' checked="checked" ';
7734: }
7735: $datatable .= '<label><input type="radio" name="'.$item.
7736: '" value="'.$auth.'"'.$checked.'/>'.
7737: $authnames{$shortauth{$auth}}.'</label> ';
7738: }
7739: } elsif ($item eq 'timezone_def') {
7740: my $includeempty = 1;
7741: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
7742: } elsif ($item eq 'datelocale_def') {
7743: my $includeempty = 1;
7744: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
7745: } elsif ($item eq 'lang_def') {
1.263 raeburn 7746: my $includeempty = 1;
7747: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 7748: } else {
7749: my $size;
7750: if ($item eq 'portal_def') {
7751: $size = ' size="25"';
7752: }
7753: $datatable .= '<input type="text" name="'.$item.'" value="'.
7754: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 7755: }
1.236 raeburn 7756: $datatable .= '</td></tr>';
7757: $rownum ++;
7758: }
1.294 raeburn 7759: } elsif ($position eq 'middle') {
7760: my @items = ('intauth_cost','intauth_check','intauth_switch');
7761: my %defaults;
7762: if (ref($settings) eq 'HASH') {
7763: %defaults = %{$settings};
7764: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
7765: $defaults{'intauth_cost'} = 10;
7766: }
7767: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
7768: $defaults{'intauth_check'} = 0;
7769: }
7770: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
7771: $defaults{'intauth_switch'} = 0;
7772: }
7773: } else {
7774: %defaults = (
7775: 'intauth_cost' => 10,
7776: 'intauth_check' => 0,
7777: 'intauth_switch' => 0,
7778: );
7779: }
7780: foreach my $item (@items) {
7781: if ($rownum%2) {
7782: $css_class = '';
7783: } else {
7784: $css_class = ' class="LC_odd_row" ';
7785: }
7786: $datatable .= '<tr'.$css_class.'>'.
7787: '<td><span class="LC_nobreak">'.$titles->{$item}.
7788: '</span></td><td class="LC_left_item" colspan="3">';
7789: if ($item eq 'intauth_switch') {
7790: my @options = (0,1,2);
7791: my %optiondesc = &Apache::lonlocal::texthash (
7792: 0 => 'No',
7793: 1 => 'Yes',
7794: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
7795: );
7796: $datatable .= '<table width="100%">';
7797: foreach my $option (@options) {
7798: my $checked = ' ';
7799: if ($defaults{$item} eq $option) {
7800: $checked = ' checked="checked"';
7801: }
7802: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7803: '<label><input type="radio" name="'.$item.
7804: '" value="'.$option.'"'.$checked.' />'.
7805: $optiondesc{$option}.'</label></span></td></tr>';
7806: }
7807: $datatable .= '</table>';
7808: } elsif ($item eq 'intauth_check') {
7809: my @options = (0,1,2);
7810: my %optiondesc = &Apache::lonlocal::texthash (
7811: 0 => 'No',
7812: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
7813: 2 => 'Yes, disallow login if stored cost is less than domain default',
7814: );
1.332 raeburn 7815: $datatable .= '<table width="100%">';
1.294 raeburn 7816: foreach my $option (@options) {
7817: my $checked = ' ';
7818: my $onclick;
7819: if ($defaults{$item} eq $option) {
7820: $checked = ' checked="checked"';
7821: }
7822: if ($option == 2) {
7823: $onclick = ' onclick="javascript:warnIntAuth(this);"';
7824: }
7825: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7826: '<label><input type="radio" name="'.$item.
7827: '" value="'.$option.'"'.$checked.$onclick.' />'.
7828: $optiondesc{$option}.'</label></span></td></tr>';
7829: }
7830: $datatable .= '</table>';
7831: } else {
7832: $datatable .= '<input type="text" name="'.$item.'" value="'.
7833: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
7834: }
7835: $datatable .= '</td></tr>';
7836: $rownum ++;
7837: }
1.236 raeburn 7838: } else {
1.294 raeburn 7839: my %defaults;
1.236 raeburn 7840: if (ref($settings) eq 'HASH') {
1.305 raeburn 7841: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.236 raeburn 7842: my $maxnum = @{$settings->{'inststatusorder'}};
7843: for (my $i=0; $i<$maxnum; $i++) {
7844: $css_class = $rownum%2?' class="LC_odd_row"':'';
7845: my $item = $settings->{'inststatusorder'}->[$i];
7846: my $title = $settings->{'inststatustypes'}->{$item};
7847: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
7848: $datatable .= '<tr'.$css_class.'>'.
7849: '<td><span class="LC_nobreak">'.
7850: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
7851: for (my $k=0; $k<=$maxnum; $k++) {
7852: my $vpos = $k+1;
7853: my $selstr;
7854: if ($k == $i) {
7855: $selstr = ' selected="selected" ';
7856: }
7857: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7858: }
7859: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
7860: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
7861: &mt('delete').'</span></td>'.
1.305 raeburn 7862: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed:').
1.236 raeburn 7863: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.305 raeburn 7864: '</span></td></tr>';
1.236 raeburn 7865: }
7866: $css_class = $rownum%2?' class="LC_odd_row"':'';
7867: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
7868: $datatable .= '<tr '.$css_class.'>'.
7869: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
7870: for (my $k=0; $k<=$maxnum; $k++) {
7871: my $vpos = $k+1;
7872: my $selstr;
7873: if ($k == $maxnum) {
7874: $selstr = ' selected="selected" ';
7875: }
7876: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7877: }
7878: $datatable .= '</select> '.&mt('Internal ID:').
1.263 raeburn 7879: '<input type="text" size="10" name="addinststatus" value="" />'.
1.236 raeburn 7880: ' '.&mt('(new)').
1.305 raeburn 7881: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.236 raeburn 7882: &mt('Name displayed:').
7883: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
7884: '</tr>'."\n";
7885: $rownum ++;
1.141 raeburn 7886: }
1.43 raeburn 7887: }
7888: }
7889: $$rowtotal += $rownum;
7890: return $datatable;
7891: }
7892:
1.168 raeburn 7893: sub get_languages_hash {
7894: my %langchoices;
7895: foreach my $id (&Apache::loncommon::languageids()) {
7896: my $code = &Apache::loncommon::supportedlanguagecode($id);
7897: if ($code ne '') {
7898: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
7899: }
7900: }
7901: return %langchoices;
7902: }
7903:
1.43 raeburn 7904: sub defaults_titles {
1.141 raeburn 7905: my ($dom) = @_;
1.43 raeburn 7906: my %titles = &Apache::lonlocal::texthash (
7907: 'auth_def' => 'Default authentication type',
7908: 'auth_arg_def' => 'Default authentication argument',
7909: 'lang_def' => 'Default language',
1.54 raeburn 7910: 'timezone_def' => 'Default timezone',
1.68 raeburn 7911: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 7912: 'portal_def' => 'Portal/Default URL',
1.294 raeburn 7913: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
7914: 'intauth_check' => 'Check bcrypt cost if authenticated',
7915: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 7916: );
1.141 raeburn 7917: if ($dom) {
7918: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
7919: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
7920: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
7921: $protocol = 'http' if ($protocol ne 'https');
7922: if ($uint_dom) {
7923: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
7924: $uint_dom);
7925: }
7926: }
1.43 raeburn 7927: return (\%titles);
7928: }
7929:
1.46 raeburn 7930: sub print_scantronformat {
7931: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
7932: my $itemcount = 1;
1.60 raeburn 7933: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
7934: %confhash);
1.46 raeburn 7935: my $switchserver = &check_switchserver($dom,$confname);
7936: my %lt = &Apache::lonlocal::texthash (
1.95 www 7937: default => 'Default bubblesheet format file error',
7938: custom => 'Custom bubblesheet format file error',
1.46 raeburn 7939: );
7940: my %scantronfiles = (
7941: default => 'default.tab',
7942: custom => 'custom.tab',
7943: );
7944: foreach my $key (keys(%scantronfiles)) {
7945: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
7946: .$scantronfiles{$key};
7947: }
7948: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
7949: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
7950: if (!$switchserver) {
7951: my $servadm = $r->dir_config('lonAdmEMail');
7952: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
7953: if ($configuserok eq 'ok') {
7954: if ($author_ok eq 'ok') {
7955: my %legacyfile = (
7956: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
7957: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
7958: );
7959: my %md5chk;
7960: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 7961: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
7962: chomp($md5chk{$type});
1.46 raeburn 7963: }
7964: if ($md5chk{'default'} ne $md5chk{'custom'}) {
7965: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 7966: ($scantronurls{$type},my $error) =
1.46 raeburn 7967: &legacy_scantronformat($r,$dom,$confname,
7968: $type,$legacyfile{$type},
7969: $scantronurls{$type},
7970: $scantronfiles{$type});
1.60 raeburn 7971: if ($error ne '') {
7972: $error{$type} = $error;
7973: }
7974: }
7975: if (keys(%error) == 0) {
7976: $is_custom = 1;
7977: $confhash{'scantron'}{'scantronformat'} =
7978: $scantronurls{'custom'};
7979: my $putresult =
7980: &Apache::lonnet::put_dom('configuration',
7981: \%confhash,$dom);
7982: if ($putresult ne 'ok') {
7983: $error{'custom'} =
7984: '<span class="LC_error">'.
7985: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7986: }
1.46 raeburn 7987: }
7988: } else {
1.60 raeburn 7989: ($scantronurls{'default'},my $error) =
1.46 raeburn 7990: &legacy_scantronformat($r,$dom,$confname,
7991: 'default',$legacyfile{'default'},
7992: $scantronurls{'default'},
7993: $scantronfiles{'default'});
1.60 raeburn 7994: if ($error eq '') {
7995: $confhash{'scantron'}{'scantronformat'} = '';
7996: my $putresult =
7997: &Apache::lonnet::put_dom('configuration',
7998: \%confhash,$dom);
7999: if ($putresult ne 'ok') {
8000: $error{'default'} =
8001: '<span class="LC_error">'.
8002: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
8003: }
8004: } else {
8005: $error{'default'} = $error;
8006: }
1.46 raeburn 8007: }
8008: }
8009: }
8010: } else {
1.95 www 8011: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 8012: }
8013: }
8014: if (ref($settings) eq 'HASH') {
8015: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
8016: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
8017: if ((!@info) || ($info[0] eq 'no_such_dir')) {
8018: $scantronurl = '';
8019: } else {
8020: $scantronurl = $settings->{'scantronformat'};
8021: }
8022: $is_custom = 1;
8023: } else {
8024: $scantronurl = $scantronurls{'default'};
8025: }
8026: } else {
1.60 raeburn 8027: if ($is_custom) {
8028: $scantronurl = $scantronurls{'custom'};
8029: } else {
8030: $scantronurl = $scantronurls{'default'};
8031: }
1.46 raeburn 8032: }
8033: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8034: $datatable .= '<tr'.$css_class.'>';
8035: if (!$is_custom) {
1.65 raeburn 8036: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
8037: '<span class="LC_nobreak">';
1.46 raeburn 8038: if ($scantronurl) {
1.199 raeburn 8039: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
8040: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 8041: } else {
8042: $datatable = &mt('File unavailable for display');
8043: }
1.65 raeburn 8044: $datatable .= '</span></td>';
1.60 raeburn 8045: if (keys(%error) == 0) {
1.306 raeburn 8046: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 8047: if (!$switchserver) {
8048: $datatable .= &mt('Upload:').'<br />';
8049: }
8050: } else {
8051: my $errorstr;
8052: foreach my $key (sort(keys(%error))) {
8053: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
8054: }
8055: $datatable .= '<td>'.$errorstr;
8056: }
1.46 raeburn 8057: } else {
8058: if (keys(%error) > 0) {
8059: my $errorstr;
8060: foreach my $key (sort(keys(%error))) {
8061: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
8062: }
1.60 raeburn 8063: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 8064: } elsif ($scantronurl) {
1.199 raeburn 8065: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
8066: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 8067: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 8068: $link.
8069: '<label><input type="checkbox" name="scantronformat_del"'.
8070: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 8071: '<td><span class="LC_nobreak"> '.
8072: &mt('Replace:').'</span><br />';
1.46 raeburn 8073: }
8074: }
8075: if (keys(%error) == 0) {
8076: if ($switchserver) {
8077: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
8078: } else {
1.65 raeburn 8079: $datatable .='<span class="LC_nobreak"> '.
8080: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 8081: }
8082: }
8083: $datatable .= '</td></tr>';
8084: $$rowtotal ++;
8085: return $datatable;
8086: }
8087:
8088: sub legacy_scantronformat {
8089: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
8090: my ($url,$error);
8091: my @statinfo = &Apache::lonnet::stat_file($newurl);
8092: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
8093: (my $result,$url) =
8094: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
8095: '','',$newfile);
8096: if ($result ne 'ok') {
1.130 raeburn 8097: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 8098: }
8099: }
8100: return ($url,$error);
8101: }
1.43 raeburn 8102:
1.49 raeburn 8103: sub print_coursecategories {
1.57 raeburn 8104: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
8105: my $datatable;
8106: if ($position eq 'top') {
1.238 raeburn 8107: my (%checked);
8108: my @catitems = ('unauth','auth');
8109: my @cattypes = ('std','domonly','codesrch','none');
8110: $checked{'unauth'} = 'std';
8111: $checked{'auth'} = 'std';
8112: if (ref($settings) eq 'HASH') {
8113: foreach my $type (@cattypes) {
8114: if ($type eq $settings->{'unauth'}) {
8115: $checked{'unauth'} = $type;
8116: }
8117: if ($type eq $settings->{'auth'}) {
8118: $checked{'auth'} = $type;
8119: }
8120: }
8121: }
8122: my %lt = &Apache::lonlocal::texthash (
8123: unauth => 'Catalog type for unauthenticated users',
8124: auth => 'Catalog type for authenticated users',
8125: none => 'No catalog',
8126: std => 'Standard catalog',
8127: domonly => 'Domain-only catalog',
8128: codesrch => "Code search form",
8129: );
8130: my $itemcount = 0;
8131: foreach my $item (@catitems) {
8132: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
8133: $datatable .= '<tr '.$css_class.'>'.
8134: '<td>'.$lt{$item}.'</td>'.
8135: '<td class="LC_right_item"><span class="LC_nobreak">';
8136: foreach my $type (@cattypes) {
8137: my $ischecked;
8138: if ($checked{$item} eq $type) {
8139: $ischecked=' checked="checked"';
8140: }
8141: $datatable .= '<label>'.
8142: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
8143: ' />'.$lt{$type}.'</label> ';
8144: }
1.327 raeburn 8145: $datatable .= '</span></td></tr>';
1.238 raeburn 8146: $itemcount ++;
8147: }
8148: $$rowtotal += $itemcount;
8149: } elsif ($position eq 'middle') {
1.57 raeburn 8150: my $toggle_cats_crs = ' ';
8151: my $toggle_cats_dom = ' checked="checked" ';
8152: my $can_cat_crs = ' ';
8153: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 8154: my $toggle_catscomm_comm = ' ';
8155: my $toggle_catscomm_dom = ' checked="checked" ';
8156: my $can_catcomm_comm = ' ';
8157: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 8158: my $toggle_catsplace_place = ' ';
8159: my $toggle_catsplace_dom = ' checked="checked" ';
8160: my $can_catplace_place = ' ';
8161: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 8162:
1.57 raeburn 8163: if (ref($settings) eq 'HASH') {
8164: if ($settings->{'togglecats'} eq 'crs') {
8165: $toggle_cats_crs = $toggle_cats_dom;
8166: $toggle_cats_dom = ' ';
8167: }
8168: if ($settings->{'categorize'} eq 'crs') {
8169: $can_cat_crs = $can_cat_dom;
8170: $can_cat_dom = ' ';
8171: }
1.120 raeburn 8172: if ($settings->{'togglecatscomm'} eq 'comm') {
8173: $toggle_catscomm_comm = $toggle_catscomm_dom;
8174: $toggle_catscomm_dom = ' ';
8175: }
8176: if ($settings->{'categorizecomm'} eq 'comm') {
8177: $can_catcomm_comm = $can_catcomm_dom;
8178: $can_catcomm_dom = ' ';
8179: }
1.272 raeburn 8180: if ($settings->{'togglecatsplace'} eq 'place') {
8181: $toggle_catsplace_place = $toggle_catsplace_dom;
8182: $toggle_catsplace_dom = ' ';
8183: }
8184: if ($settings->{'categorizeplace'} eq 'place') {
8185: $can_catplace_place = $can_catplace_dom;
8186: $can_catplace_dom = ' ';
8187: }
1.57 raeburn 8188: }
8189: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 8190: togglecats => 'Show/Hide a course in catalog',
8191: togglecatscomm => 'Show/Hide a community in catalog',
8192: togglecatsplace => 'Show/Hide a placement test in catalog',
8193: categorize => 'Assign a category to a course',
8194: categorizecomm => 'Assign a category to a community',
8195: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 8196: );
8197: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 8198: dom => 'Set in Domain',
8199: crs => 'Set in Course',
8200: comm => 'Set in Community',
8201: place => 'Set in Placement Test',
1.57 raeburn 8202: );
8203: $datatable = '<tr class="LC_odd_row">'.
8204: '<td>'.$title{'togglecats'}.'</td>'.
8205: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8206: '<input type="radio" name="togglecats"'.
8207: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8208: '<label><input type="radio" name="togglecats"'.
8209: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
8210: '</tr><tr>'.
8211: '<td>'.$title{'categorize'}.'</td>'.
8212: '<td class="LC_right_item"><span class="LC_nobreak">'.
8213: '<label><input type="radio" name="categorize"'.
8214: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8215: '<label><input type="radio" name="categorize"'.
8216: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 8217: '</tr><tr class="LC_odd_row">'.
8218: '<td>'.$title{'togglecatscomm'}.'</td>'.
8219: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8220: '<input type="radio" name="togglecatscomm"'.
8221: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8222: '<label><input type="radio" name="togglecatscomm"'.
8223: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
8224: '</tr><tr>'.
8225: '<td>'.$title{'categorizecomm'}.'</td>'.
8226: '<td class="LC_right_item"><span class="LC_nobreak">'.
8227: '<label><input type="radio" name="categorizecomm"'.
8228: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8229: '<label><input type="radio" name="categorizecomm"'.
8230: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 8231: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 8232: '<td>'.$title{'togglecatsplace'}.'</td>'.
8233: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8234: '<input type="radio" name="togglecatsplace"'.
8235: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8236: '<label><input type="radio" name="togglecatscomm"'.
8237: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
8238: '</tr><tr>'.
8239: '<td>'.$title{'categorizeplace'}.'</td>'.
8240: '<td class="LC_right_item"><span class="LC_nobreak">'.
8241: '<label><input type="radio" name="categorizeplace"'.
8242: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8243: '<label><input type="radio" name="categorizeplace"'.
8244: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 8245: '</tr>';
1.272 raeburn 8246: $$rowtotal += 6;
1.57 raeburn 8247: } else {
8248: my $css_class;
8249: my $itemcount = 1;
8250: my $cathash;
8251: if (ref($settings) eq 'HASH') {
8252: $cathash = $settings->{'cats'};
8253: }
8254: if (ref($cathash) eq 'HASH') {
8255: my (@cats,@trails,%allitems,%idx,@jsarray);
8256: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
8257: \%allitems,\%idx,\@jsarray);
8258: my $maxdepth = scalar(@cats);
8259: my $colattrib = '';
8260: if ($maxdepth > 2) {
8261: $colattrib = ' colspan="2" ';
8262: }
8263: my @path;
8264: if (@cats > 0) {
8265: if (ref($cats[0]) eq 'ARRAY') {
8266: my $numtop = @{$cats[0]};
8267: my $maxnum = $numtop;
1.120 raeburn 8268: my %default_names = (
8269: instcode => &mt('Official courses'),
8270: communities => &mt('Communities'),
1.272 raeburn 8271: placement => &mt('Placement Tests'),
1.120 raeburn 8272: );
8273:
8274: if ((!grep(/^instcode$/,@{$cats[0]})) ||
8275: ($cathash->{'instcode::0'} eq '') ||
8276: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 8277: ($cathash->{'communities::0'} eq '') ||
8278: (!grep(/^placement$/,@{$cats[0]})) ||
8279: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 8280: $maxnum ++;
8281: }
8282: my $lastidx;
8283: for (my $i=0; $i<$numtop; $i++) {
8284: my $parent = $cats[0][$i];
8285: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8286: my $item = &escape($parent).'::0';
8287: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
8288: $lastidx = $idx{$item};
8289: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
8290: .'<select name="'.$item.'"'.$chgstr.'>';
8291: for (my $k=0; $k<=$maxnum; $k++) {
8292: my $vpos = $k+1;
8293: my $selstr;
8294: if ($k == $i) {
8295: $selstr = ' selected="selected" ';
8296: }
8297: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8298: }
1.214 raeburn 8299: $datatable .= '</select></span></td><td>';
1.272 raeburn 8300: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 8301: $datatable .= '<span class="LC_nobreak">'
8302: .$default_names{$parent}.'</span>';
8303: if ($parent eq 'instcode') {
8304: $datatable .= '<br /><span class="LC_nobreak">('
8305: .&mt('with institutional codes')
8306: .')</span></td><td'.$colattrib.'>';
8307: } else {
8308: $datatable .= '<table><tr><td>';
8309: }
8310: $datatable .= '<span class="LC_nobreak">'
8311: .'<label><input type="radio" name="'
8312: .$parent.'" value="1" checked="checked" />'
8313: .&mt('Display').'</label>';
8314: if ($parent eq 'instcode') {
8315: $datatable .= ' ';
8316: } else {
8317: $datatable .= '</span></td></tr><tr><td>'
8318: .'<span class="LC_nobreak">';
8319: }
8320: $datatable .= '<label><input type="radio" name="'
8321: .$parent.'" value="0" />'
8322: .&mt('Do not display').'</label></span>';
1.272 raeburn 8323: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 8324: $datatable .= '</td></tr></table>';
8325: }
8326: $datatable .= '</td>';
1.57 raeburn 8327: } else {
8328: $datatable .= $parent
1.214 raeburn 8329: .' <span class="LC_nobreak"><label>'
8330: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 8331: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
8332: }
8333: my $depth = 1;
8334: push(@path,$parent);
8335: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
8336: pop(@path);
8337: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
8338: $itemcount ++;
8339: }
1.48 raeburn 8340: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 8341: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
8342: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 8343: for (my $k=0; $k<=$maxnum; $k++) {
8344: my $vpos = $k+1;
8345: my $selstr;
1.57 raeburn 8346: if ($k == $numtop) {
1.48 raeburn 8347: $selstr = ' selected="selected" ';
8348: }
8349: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8350: }
1.59 bisitz 8351: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 8352: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
8353: .'</tr>'."\n";
1.48 raeburn 8354: $itemcount ++;
1.272 raeburn 8355: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 8356: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
8357: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8358: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
8359: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
8360: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
8361: for (my $k=0; $k<=$maxnum; $k++) {
8362: my $vpos = $k+1;
8363: my $selstr;
8364: if ($k == $maxnum) {
8365: $selstr = ' selected="selected" ';
8366: }
8367: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 8368: }
1.120 raeburn 8369: $datatable .= '</select></span></td>'.
8370: '<td><span class="LC_nobreak">'.
8371: $default_names{$default}.'</span>';
8372: if ($default eq 'instcode') {
8373: $datatable .= '<br /><span class="LC_nobreak">('
8374: .&mt('with institutional codes').')</span>';
8375: }
8376: $datatable .= '</td>'
8377: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
8378: .&mt('Display').'</label> '
8379: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
8380: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 8381: }
8382: }
8383: }
1.57 raeburn 8384: } else {
8385: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 8386: }
8387: } else {
1.327 raeburn 8388: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 8389: .&initialize_categories($itemcount);
1.48 raeburn 8390: }
1.57 raeburn 8391: $$rowtotal += $itemcount;
1.48 raeburn 8392: }
8393: return $datatable;
8394: }
8395:
1.69 raeburn 8396: sub print_serverstatuses {
8397: my ($dom,$settings,$rowtotal) = @_;
8398: my $datatable;
8399: my @pages = &serverstatus_pages();
8400: my (%namedaccess,%machineaccess);
8401: foreach my $type (@pages) {
8402: $namedaccess{$type} = '';
8403: $machineaccess{$type}= '';
8404: }
8405: if (ref($settings) eq 'HASH') {
8406: foreach my $type (@pages) {
8407: if (exists($settings->{$type})) {
8408: if (ref($settings->{$type}) eq 'HASH') {
8409: foreach my $key (keys(%{$settings->{$type}})) {
8410: if ($key eq 'namedusers') {
8411: $namedaccess{$type} = $settings->{$type}->{$key};
8412: } elsif ($key eq 'machines') {
8413: $machineaccess{$type} = $settings->{$type}->{$key};
8414: }
8415: }
8416: }
8417: }
8418: }
8419: }
1.81 raeburn 8420: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 8421: my $rownum = 0;
8422: my $css_class;
8423: foreach my $type (@pages) {
8424: $rownum ++;
8425: $css_class = $rownum%2?' class="LC_odd_row"':'';
8426: $datatable .= '<tr'.$css_class.'>'.
8427: '<td><span class="LC_nobreak">'.
8428: $titles->{$type}.'</span></td>'.
8429: '<td class="LC_left_item">'.
8430: '<input type="text" name="'.$type.'_namedusers" '.
8431: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
8432: '<td class="LC_right_item">'.
8433: '<span class="LC_nobreak">'.
8434: '<input type="text" name="'.$type.'_machines" '.
8435: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 8436: '</span></td></tr>'."\n";
1.69 raeburn 8437: }
8438: $$rowtotal += $rownum;
8439: return $datatable;
8440: }
8441:
8442: sub serverstatus_pages {
8443: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 8444: 'checksums','clusterstatus','certstatus','metadata_keywords',
8445: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
8446: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 8447: }
8448:
1.236 raeburn 8449: sub defaults_javascript {
8450: my ($settings) = @_;
1.294 raeburn 8451: 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.');
8452: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
8453: &js_escape(\$intauthcheck);
8454: &js_escape(\$intauthcost);
8455: my $intauthjs = <<"ENDSCRIPT";
8456:
8457: function warnIntAuth(field) {
8458: if (field.name == 'intauth_check') {
8459: if (field.value == '2') {
8460: alert('$intauthcheck');
8461: }
8462: }
8463: if (field.name == 'intauth_cost') {
8464: field.value.replace(/\s/g,'');
8465: if (field.value != '') {
8466: var regexdigit=/^\\d+\$/;
8467: if (!regexdigit.test(field.value)) {
8468: alert('$intauthcost');
8469: }
8470: }
8471: }
8472: return;
8473: }
8474:
8475: ENDSCRIPT
8476:
8477: if (ref($settings) ne 'HASH') {
8478: return &Apache::lonhtmlcommon::scripttag($intauthjs);
8479: }
1.236 raeburn 8480: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
8481: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
8482: if ($maxnum eq '') {
8483: $maxnum = 0;
8484: }
8485: $maxnum ++;
1.249 raeburn 8486: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 8487: return <<"ENDSCRIPT";
8488: <script type="text/javascript">
8489: // <![CDATA[
8490: function reorderTypes(form,caller) {
8491: var changedVal;
8492: $jstext
8493: var newpos = 'addinststatus_pos';
8494: var current = new Array;
8495: var maxh = $maxnum;
8496: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8497: var oldVal;
8498: if (caller == newpos) {
8499: changedVal = newitemVal;
8500: } else {
8501: var curritem = 'inststatus_pos_'+caller;
8502: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
8503: current[newitemVal] = newpos;
8504: }
8505: for (var i=0; i<inststatuses.length; i++) {
8506: if (inststatuses[i] != caller) {
8507: var elementName = 'inststatus_pos_'+inststatuses[i];
8508: if (form.elements[elementName]) {
8509: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8510: current[currVal] = elementName;
8511: }
8512: }
8513: }
8514: for (var j=0; j<maxh; j++) {
8515: if (current[j] == undefined) {
8516: oldVal = j;
8517: }
8518: }
8519: if (oldVal < changedVal) {
8520: for (var k=oldVal+1; k<=changedVal ; k++) {
8521: var elementName = current[k];
8522: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8523: }
8524: } else {
8525: for (var k=changedVal; k<oldVal; k++) {
8526: var elementName = current[k];
8527: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8528: }
8529: }
8530: return;
8531: }
8532:
1.294 raeburn 8533: $intauthjs
8534:
1.236 raeburn 8535: // ]]>
8536: </script>
8537:
8538: ENDSCRIPT
1.294 raeburn 8539: } else {
8540: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 8541: }
8542: }
8543:
1.49 raeburn 8544: sub coursecategories_javascript {
8545: my ($settings) = @_;
1.57 raeburn 8546: my ($output,$jstext,$cathash);
1.49 raeburn 8547: if (ref($settings) eq 'HASH') {
1.57 raeburn 8548: $cathash = $settings->{'cats'};
8549: }
8550: if (ref($cathash) eq 'HASH') {
1.49 raeburn 8551: my (@cats,@jsarray,%idx);
1.57 raeburn 8552: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 8553: if (@jsarray > 0) {
8554: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
8555: for (my $i=0; $i<@jsarray; $i++) {
8556: if (ref($jsarray[$i]) eq 'ARRAY') {
8557: my $catstr = join('","',@{$jsarray[$i]});
8558: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
8559: }
8560: }
8561: }
8562: } else {
8563: $jstext = ' var categories = Array(1);'."\n".
8564: ' categories[0] = Array("instcode_pos");'."\n";
8565: }
1.237 bisitz 8566: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
8567: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 8568: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 8569: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
8570: &js_escape(\$instcode_reserved);
8571: &js_escape(\$communities_reserved);
1.272 raeburn 8572: &js_escape(\$placement_reserved);
1.265 damieng 8573: &js_escape(\$choose_again);
1.49 raeburn 8574: $output = <<"ENDSCRIPT";
8575: <script type="text/javascript">
1.109 raeburn 8576: // <![CDATA[
1.49 raeburn 8577: function reorderCats(form,parent,item,idx) {
8578: var changedVal;
8579: $jstext
8580: var newpos = 'addcategory_pos';
8581: if (parent == '') {
8582: var has_instcode = 0;
8583: var maxtop = categories[idx].length;
8584: for (var j=0; j<maxtop; j++) {
8585: if (categories[idx][j] == 'instcode::0') {
8586: has_instcode == 1;
8587: }
8588: }
8589: if (has_instcode == 0) {
8590: categories[idx][maxtop] = 'instcode_pos';
8591: }
8592: } else {
8593: newpos += '_'+parent;
8594: }
8595: var maxh = 1 + categories[idx].length;
8596: var current = new Array;
8597: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8598: if (item == newpos) {
8599: changedVal = newitemVal;
8600: } else {
8601: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
8602: current[newitemVal] = newpos;
8603: }
8604: for (var i=0; i<categories[idx].length; i++) {
8605: var elementName = categories[idx][i];
8606: if (elementName != item) {
8607: if (form.elements[elementName]) {
8608: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8609: current[currVal] = elementName;
8610: }
8611: }
8612: }
8613: var oldVal;
8614: for (var j=0; j<maxh; j++) {
8615: if (current[j] == undefined) {
8616: oldVal = j;
8617: }
8618: }
8619: if (oldVal < changedVal) {
8620: for (var k=oldVal+1; k<=changedVal ; k++) {
8621: var elementName = current[k];
8622: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8623: }
8624: } else {
8625: for (var k=changedVal; k<oldVal; k++) {
8626: var elementName = current[k];
8627: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8628: }
8629: }
8630: return;
8631: }
1.120 raeburn 8632:
8633: function categoryCheck(form) {
8634: if (form.elements['addcategory_name'].value == 'instcode') {
8635: alert('$instcode_reserved\\n$choose_again');
8636: return false;
8637: }
8638: if (form.elements['addcategory_name'].value == 'communities') {
8639: alert('$communities_reserved\\n$choose_again');
8640: return false;
8641: }
1.272 raeburn 8642: if (form.elements['addcategory_name'].value == 'placement') {
8643: alert('$placement_reserved\\n$choose_again');
8644: return false;
8645: }
1.120 raeburn 8646: return true;
8647: }
8648:
1.109 raeburn 8649: // ]]>
1.49 raeburn 8650: </script>
8651:
8652: ENDSCRIPT
8653: return $output;
8654: }
8655:
1.48 raeburn 8656: sub initialize_categories {
8657: my ($itemcount) = @_;
1.120 raeburn 8658: my ($datatable,$css_class,$chgstr);
8659: my %default_names = (
8660: instcode => 'Official courses (with institutional codes)',
8661: communities => 'Communities',
1.272 raeburn 8662: placement => 'Placement Tests',
1.120 raeburn 8663: );
1.328 raeburn 8664: my %selnum = (
8665: instcode => '0',
8666: communities => '1',
8667: placement => '2',
8668: );
8669: my %selected;
1.272 raeburn 8670: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 8671: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 8672: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 8673: map { $selected{$selnum{$_}} = '' } keys(%selnum);
8674: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 8675: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 8676: .'<select name="'.$default.'_pos"'.$chgstr.'>'
8677: .'<option value="0"'.$selected{'0'}.'>1</option>'
8678: .'<option value="1"'.$selected{'1'}.'>2</option>'
8679: .'<option value="2"'.$selected{'2'}.'>3</option>'
8680: .'<option value="3">4</option></select> '
1.120 raeburn 8681: .$default_names{$default}
8682: .'</span></td><td><span class="LC_nobreak">'
8683: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
8684: .&mt('Display').'</label> <label>'
8685: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 8686: .'</label></span></td></tr>';
1.120 raeburn 8687: $itemcount ++;
8688: }
1.48 raeburn 8689: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 8690: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 8691: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 8692: .'<select name="addcategory_pos"'.$chgstr.'>'
8693: .'<option value="0">1</option>'
8694: .'<option value="1">2</option>'
1.328 raeburn 8695: .'<option value="2">3</option>'
8696: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 8697: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
8698: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
8699: .'</td></tr>';
1.48 raeburn 8700: return $datatable;
8701: }
8702:
8703: sub build_category_rows {
1.49 raeburn 8704: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
8705: my ($text,$name,$item,$chgstr);
1.48 raeburn 8706: if (ref($cats) eq 'ARRAY') {
8707: my $maxdepth = scalar(@{$cats});
8708: if (ref($cats->[$depth]) eq 'HASH') {
8709: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
8710: my $numchildren = @{$cats->[$depth]{$parent}};
8711: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 8712: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 8713: my ($idxnum,$parent_name,$parent_item);
8714: my $higher = $depth - 1;
8715: if ($higher == 0) {
8716: $parent_name = &escape($parent).'::'.$higher;
8717: } else {
8718: if (ref($path) eq 'ARRAY') {
8719: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8720: }
8721: }
8722: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 8723: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 8724: if ($j < $numchildren) {
1.48 raeburn 8725: $name = $cats->[$depth]{$parent}[$j];
8726: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 8727: $idxnum = $idx->{$item};
8728: } else {
8729: $name = $parent_name;
8730: $item = $parent_item;
1.48 raeburn 8731: }
1.49 raeburn 8732: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
8733: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 8734: for (my $i=0; $i<=$numchildren; $i++) {
8735: my $vpos = $i+1;
8736: my $selstr;
8737: if ($j == $i) {
8738: $selstr = ' selected="selected" ';
8739: }
8740: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
8741: }
8742: $text .= '</select> ';
8743: if ($j < $numchildren) {
8744: my $deeper = $depth+1;
8745: $text .= $name.' '
8746: .'<label><input type="checkbox" name="deletecategory" value="'
8747: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
8748: if(ref($path) eq 'ARRAY') {
8749: push(@{$path},$name);
1.49 raeburn 8750: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 8751: pop(@{$path});
8752: }
8753: } else {
1.330 raeburn 8754: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 8755: if ($j == $numchildren) {
8756: $text .= $name;
8757: } else {
8758: $text .= $item;
8759: }
8760: $text .= '" value="" />';
8761: }
8762: $text .= '</td></tr>';
8763: }
8764: $text .= '</table></td>';
8765: } else {
8766: my $higher = $depth-1;
8767: if ($higher == 0) {
8768: $name = &escape($parent).'::'.$higher;
8769: } else {
8770: if (ref($path) eq 'ARRAY') {
8771: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8772: }
8773: }
8774: my $colspan;
8775: if ($parent ne 'instcode') {
8776: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 8777: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 8778: }
8779: }
8780: }
8781: }
8782: return $text;
8783: }
8784:
1.33 raeburn 8785: sub modifiable_userdata_row {
1.305 raeburn 8786: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
8787: $rowid,$customcss,$rowstyle) = @_;
1.228 raeburn 8788: my ($role,$rolename,$statustype);
8789: $role = $item;
1.224 raeburn 8790: if ($context eq 'cancreate') {
1.305 raeburn 8791: if ($item =~ /^(emailusername)_(.+)$/) {
8792: $role = $1;
8793: $statustype = $2;
1.228 raeburn 8794: if (ref($usertypes) eq 'HASH') {
8795: if ($usertypes->{$statustype}) {
8796: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
8797: } else {
8798: $rolename = &mt('Data provided by user');
8799: }
8800: }
1.224 raeburn 8801: }
8802: } elsif ($context eq 'selfcreate') {
1.63 raeburn 8803: if (ref($usertypes) eq 'HASH') {
8804: $rolename = $usertypes->{$role};
8805: } else {
8806: $rolename = $role;
8807: }
1.325 raeburn 8808: } elsif ($context eq 'lti') {
8809: $rolename = &mt('Institutional data used (if available)');
1.33 raeburn 8810: } else {
1.63 raeburn 8811: if ($role eq 'cr') {
8812: $rolename = &mt('Custom role');
8813: } else {
8814: $rolename = &Apache::lonnet::plaintext($role);
8815: }
1.33 raeburn 8816: }
1.224 raeburn 8817: my (@fields,%fieldtitles);
8818: if (ref($fieldsref) eq 'ARRAY') {
8819: @fields = @{$fieldsref};
8820: } else {
8821: @fields = ('lastname','firstname','middlename','generation',
8822: 'permanentemail','id');
8823: }
8824: if ((ref($titlesref) eq 'HASH')) {
8825: %fieldtitles = %{$titlesref};
8826: } else {
8827: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8828: }
1.33 raeburn 8829: my $output;
1.305 raeburn 8830: my $css_class;
8831: if ($rowcount%2) {
8832: $css_class = 'LC_odd_row';
8833: }
8834: if ($customcss) {
8835: $css_class .= " $customcss";
8836: }
8837: $css_class =~ s/^\s+//;
8838: if ($css_class) {
8839: $css_class = ' class="'.$css_class.'"';
8840: }
8841: if ($rowstyle) {
8842: $css_class .= ' style="'.$rowstyle.'"';
8843: }
8844: if ($rowid) {
8845: $rowid = ' id="'.$rowid.'"';
8846: }
8847: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 8848: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
8849: '<td class="LC_left_item" colspan="2"><table>';
8850: my $rem;
8851: my %checks;
1.325 raeburn 8852: my %current;
1.33 raeburn 8853: if (ref($settings) eq 'HASH') {
1.325 raeburn 8854: my $hashref;
8855: if ($context eq 'lti') {
8856: if (ref($settings) eq 'HASH') {
8857: $hashref = $settings->{'instdata'};
8858: }
8859: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 8860: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 8861: $hashref = $settings->{'lti_instdata'};
8862: }
8863: if ($role eq 'emailusername') {
8864: if ($statustype) {
8865: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
8866: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 8867: }
1.325 raeburn 8868: }
8869: }
8870: }
8871: if (ref($hashref) eq 'HASH') {
8872: foreach my $field (@fields) {
8873: if ($hashref->{$field}) {
8874: if ($role eq 'emailusername') {
8875: $checks{$field} = $hashref->{$field};
8876: } else {
8877: $checks{$field} = ' checked="checked" ';
1.33 raeburn 8878: }
8879: }
8880: }
8881: }
8882: }
1.305 raeburn 8883:
8884: my $total = scalar(@fields);
8885: for (my $i=0; $i<$total; $i++) {
8886: $rem = $i%($numinrow);
1.33 raeburn 8887: if ($rem == 0) {
8888: if ($i > 0) {
8889: $output .= '</tr>';
8890: }
8891: $output .= '<tr>';
8892: }
8893: my $check = ' ';
1.228 raeburn 8894: unless ($role eq 'emailusername') {
8895: if (exists($checks{$fields[$i]})) {
8896: $check = $checks{$fields[$i]}
1.325 raeburn 8897: } elsif ($context ne 'lti') {
1.228 raeburn 8898: if ($role eq 'st') {
8899: if (ref($settings) ne 'HASH') {
8900: $check = ' checked="checked" ';
8901: }
1.33 raeburn 8902: }
8903: }
8904: }
8905: $output .= '<td class="LC_left_item">'.
1.228 raeburn 8906: '<span class="LC_nobreak">';
1.325 raeburn 8907: my $prefix = 'canmodify';
1.228 raeburn 8908: if ($role eq 'emailusername') {
8909: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
8910: $checks{$fields[$i]} = 'omit';
8911: }
8912: foreach my $option ('required','optional','omit') {
8913: my $checked='';
8914: if ($checks{$fields[$i]} eq $option) {
8915: $checked='checked="checked" ';
8916: }
8917: $output .= '<label>'.
1.325 raeburn 8918: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 8919: &mt($option).'</label>'.(' ' x2);
8920: }
8921: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
8922: } else {
1.325 raeburn 8923: if ($context eq 'lti') {
8924: $prefix = 'lti';
8925: }
1.228 raeburn 8926: $output .= '<label>'.
1.325 raeburn 8927: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 8928: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
8929: '</label>';
8930: }
8931: $output .= '</span></td>';
1.33 raeburn 8932: }
1.305 raeburn 8933: $rem = $total%$numinrow;
8934: my $colsleft;
8935: if ($rem) {
8936: $colsleft = $numinrow - $rem;
8937: }
8938: if ($colsleft > 1) {
1.33 raeburn 8939: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8940: ' </td>';
8941: } elsif ($colsleft == 1) {
8942: $output .= '<td class="LC_left_item"> </td>';
8943: }
8944: $output .= '</tr></table></td></tr>';
8945: return $output;
8946: }
1.28 raeburn 8947:
1.93 raeburn 8948: sub insttypes_row {
1.305 raeburn 8949: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
8950: $customcss,$rowstyle) = @_;
1.93 raeburn 8951: my %lt = &Apache::lonlocal::texthash (
8952: cansearch => 'Users allowed to search',
8953: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 8954: lockablenames => 'User preference to lock name',
1.305 raeburn 8955: selfassign => 'Self-reportable affiliations',
1.315 raeburn 8956: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 8957: );
8958: my $showdom;
8959: if ($context eq 'cansearch') {
8960: $showdom = ' ('.$dom.')';
8961: }
1.165 raeburn 8962: my $class = 'LC_left_item';
8963: if ($context eq 'statustocreate') {
8964: $class = 'LC_right_item';
8965: }
1.305 raeburn 8966: my $css_class;
8967: if ($$rowtotal%2) {
8968: $css_class = 'LC_odd_row';
8969: }
8970: if ($customcss) {
8971: $css_class .= ' '.$customcss;
8972: }
8973: $css_class =~ s/^\s+//;
8974: if ($css_class) {
8975: $css_class = ' class="'.$css_class.'"';
8976: }
8977: if ($rowstyle) {
8978: $css_class .= ' style="'.$rowstyle.'"';
8979: }
8980: if ($onclick) {
8981: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 8982: }
8983: my $output = '<tr'.$css_class.'>'.
8984: '<td>'.$lt{$context}.$showdom.
8985: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 8986: my $rem;
8987: if (ref($types) eq 'ARRAY') {
8988: for (my $i=0; $i<@{$types}; $i++) {
8989: if (defined($usertypes->{$types->[$i]})) {
8990: my $rem = $i%($numinrow);
8991: if ($rem == 0) {
8992: if ($i > 0) {
8993: $output .= '</tr>';
8994: }
8995: $output .= '<tr>';
1.23 raeburn 8996: }
1.26 raeburn 8997: my $check = ' ';
1.99 raeburn 8998: if (ref($settings) eq 'HASH') {
8999: if (ref($settings->{$context}) eq 'ARRAY') {
9000: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
9001: $check = ' checked="checked" ';
9002: }
1.315 raeburn 9003: } elsif (ref($settings->{$context}) eq 'HASH') {
9004: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
9005: $check = ' checked="checked" ';
9006: }
1.99 raeburn 9007: } elsif ($context eq 'statustocreate') {
1.26 raeburn 9008: $check = ' checked="checked" ';
9009: }
1.23 raeburn 9010: }
1.26 raeburn 9011: $output .= '<td class="LC_left_item">'.
9012: '<span class="LC_nobreak"><label>'.
1.93 raeburn 9013: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 9014: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 9015: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 9016: }
9017: }
1.26 raeburn 9018: $rem = @{$types}%($numinrow);
1.23 raeburn 9019: }
9020: my $colsleft = $numinrow - $rem;
1.315 raeburn 9021: if ($context eq 'overrides') {
9022: if ($colsleft > 1) {
9023: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
9024: } else {
9025: $output .= '<td class="LC_left_item">';
9026: }
9027: $output .= ' ';
1.23 raeburn 9028: } else {
1.334 raeburn 9029: if ($rem == 0) {
1.315 raeburn 9030: $output .= '<tr>';
9031: }
9032: if ($colsleft > 1) {
9033: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
9034: } else {
9035: $output .= '<td class="LC_left_item">';
9036: }
9037: my $defcheck = ' ';
9038: if (ref($settings) eq 'HASH') {
9039: if (ref($settings->{$context}) eq 'ARRAY') {
9040: if (grep(/^default$/,@{$settings->{$context}})) {
9041: $defcheck = ' checked="checked" ';
9042: }
9043: } elsif ($context eq 'statustocreate') {
1.99 raeburn 9044: $defcheck = ' checked="checked" ';
9045: }
1.26 raeburn 9046: }
1.315 raeburn 9047: $output .= '<span class="LC_nobreak"><label>'.
9048: '<input type="checkbox" name="'.$context.'" '.
9049: 'value="default"'.$defcheck.$onclick.' />'.
9050: $othertitle.'</label></span>';
1.23 raeburn 9051: }
1.315 raeburn 9052: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 9053: return $output;
1.23 raeburn 9054: }
9055:
9056: sub sorted_searchtitles {
9057: my %searchtitles = &Apache::lonlocal::texthash(
9058: 'uname' => 'username',
9059: 'lastname' => 'last name',
9060: 'lastfirst' => 'last name, first name',
9061: );
9062: my @titleorder = ('uname','lastname','lastfirst');
9063: return (\%searchtitles,\@titleorder);
9064: }
9065:
1.25 raeburn 9066: sub sorted_searchtypes {
9067: my %srchtypes_desc = (
9068: exact => 'is exact match',
9069: contains => 'contains ..',
9070: begins => 'begins with ..',
9071: );
9072: my @srchtypeorder = ('exact','begins','contains');
9073: return (\%srchtypes_desc,\@srchtypeorder);
9074: }
9075:
1.3 raeburn 9076: sub usertype_update_row {
9077: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
9078: my $datatable;
9079: my $numinrow = 4;
9080: foreach my $type (@{$types}) {
9081: if (defined($usertypes->{$type})) {
9082: $$rownums ++;
9083: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
9084: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
9085: '</td><td class="LC_left_item"><table>';
9086: for (my $i=0; $i<@{$fields}; $i++) {
9087: my $rem = $i%($numinrow);
9088: if ($rem == 0) {
9089: if ($i > 0) {
9090: $datatable .= '</tr>';
9091: }
9092: $datatable .= '<tr>';
9093: }
9094: my $check = ' ';
1.39 raeburn 9095: if (ref($settings) eq 'HASH') {
9096: if (ref($settings->{'fields'}) eq 'HASH') {
9097: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
9098: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
9099: $check = ' checked="checked" ';
9100: }
1.3 raeburn 9101: }
9102: }
9103: }
9104:
9105: if ($i == @{$fields}-1) {
9106: my $colsleft = $numinrow - $rem;
9107: if ($colsleft > 1) {
9108: $datatable .= '<td colspan="'.$colsleft.'">';
9109: } else {
9110: $datatable .= '<td>';
9111: }
9112: } else {
9113: $datatable .= '<td>';
9114: }
1.8 raeburn 9115: $datatable .= '<span class="LC_nobreak"><label>'.
9116: '<input type="checkbox" name="updateable_'.$type.
9117: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
9118: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 9119: }
9120: $datatable .= '</tr></table></td></tr>';
9121: }
9122: }
9123: return $datatable;
1.1 raeburn 9124: }
9125:
9126: sub modify_login {
1.205 raeburn 9127: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 9128: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
9129: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
9130: %title = ( coursecatalog => 'Display course catalog',
9131: adminmail => 'Display administrator E-mail address',
1.188 raeburn 9132: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 9133: newuser => 'Link for visitors to create a user account',
9134: loginheader => 'Log-in box header');
9135: @offon = ('off','on');
1.112 raeburn 9136: if (ref($domconfig{login}) eq 'HASH') {
9137: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
9138: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
9139: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
9140: }
9141: }
9142: }
1.9 raeburn 9143: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
9144: \%domconfig,\%loginhash);
1.188 raeburn 9145: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 9146: foreach my $item (@toggles) {
9147: $loginhash{login}{$item} = $env{'form.'.$item};
9148: }
1.41 raeburn 9149: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 9150: if (ref($colchanges{'login'}) eq 'HASH') {
9151: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
9152: \%loginhash);
9153: }
1.110 raeburn 9154:
1.149 raeburn 9155: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 9156: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 9157: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 9158: if (keys(%servers) > 1) {
9159: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 9160: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
9161: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
9162: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
9163: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
9164: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
9165: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9166: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
9167: $changes{'loginvia'}{$lonhost} = 1;
9168: } else {
9169: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
9170: $changes{'loginvia'}{$lonhost} = 1;
9171: }
9172: } else {
9173: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9174: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
9175: $changes{'loginvia'}{$lonhost} = 1;
9176: }
9177: }
9178: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
9179: foreach my $item (@loginvia_attribs) {
9180: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
9181: }
9182: } else {
9183: foreach my $item (@loginvia_attribs) {
9184: my $new = $env{'form.'.$lonhost.'_'.$item};
9185: if (($item eq 'serverpath') && ($new eq 'custom')) {
9186: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
9187: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9188: $new = '/';
9189: }
9190: }
9191: if (($item eq 'custompath') &&
9192: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9193: $new = '';
9194: }
9195: if ($new ne $curr_loginvia{$lonhost}{$item}) {
9196: $changes{'loginvia'}{$lonhost} = 1;
9197: }
9198: if ($item eq 'exempt') {
1.256 raeburn 9199: $new = &check_exempt_addresses($new);
1.128 raeburn 9200: }
9201: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9202: }
9203: }
1.112 raeburn 9204: } else {
1.128 raeburn 9205: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9206: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 9207: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 9208: foreach my $item (@loginvia_attribs) {
9209: my $new = $env{'form.'.$lonhost.'_'.$item};
9210: if (($item eq 'serverpath') && ($new eq 'custom')) {
9211: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9212: $new = '/';
9213: }
9214: }
9215: if (($item eq 'custompath') &&
9216: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9217: $new = '';
9218: }
9219: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9220: }
1.110 raeburn 9221: }
9222: }
9223: }
9224: }
1.119 raeburn 9225:
1.168 raeburn 9226: my $servadm = $r->dir_config('lonAdmEMail');
9227: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
9228: if (ref($domconfig{'login'}) eq 'HASH') {
9229: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
9230: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
9231: if ($lang eq 'nolang') {
9232: push(@currlangs,$lang);
9233: } elsif (defined($langchoices{$lang})) {
9234: push(@currlangs,$lang);
9235: } else {
9236: next;
9237: }
9238: }
9239: }
9240: }
9241: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
9242: if (@currlangs > 0) {
9243: foreach my $lang (@currlangs) {
9244: if (grep(/^\Q$lang\E$/,@delurls)) {
9245: $changes{'helpurl'}{$lang} = 1;
9246: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
9247: $changes{'helpurl'}{$lang} = 1;
9248: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
9249: push(@newlangs,$lang);
9250: } else {
9251: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9252: }
9253: }
9254: }
9255: unless (grep(/^nolang$/,@currlangs)) {
9256: if ($env{'form.loginhelpurl_nolang.filename'}) {
9257: $changes{'helpurl'}{'nolang'} = 1;
9258: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
9259: push(@newlangs,'nolang');
9260: }
9261: }
9262: if ($env{'form.loginhelpurl_add_lang'}) {
9263: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
9264: ($env{'form.loginhelpurl_add_file.filename'})) {
9265: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
9266: $addedfile = $env{'form.loginhelpurl_add_lang'};
9267: }
9268: }
9269: if ((@newlangs > 0) || ($addedfile)) {
9270: my $error;
9271: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9272: if ($configuserok eq 'ok') {
9273: if ($switchserver) {
9274: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
9275: } elsif ($author_ok eq 'ok') {
9276: my @allnew = @newlangs;
9277: if ($addedfile ne '') {
9278: push(@allnew,$addedfile);
9279: }
9280: foreach my $lang (@allnew) {
9281: my $formelem = 'loginhelpurl_'.$lang;
9282: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
9283: $formelem = 'loginhelpurl_add_file';
9284: }
9285: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9286: "help/$lang",'','',$newfile{$lang});
9287: if ($result eq 'ok') {
9288: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
9289: $changes{'helpurl'}{$lang} = 1;
9290: } else {
9291: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
9292: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 9293: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 9294: (!grep(/^\Q$lang\E$/,@delurls))) {
9295: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9296: }
9297: }
9298: }
9299: } else {
9300: $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);
9301: }
9302: } else {
9303: $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);
9304: }
9305: if ($error) {
9306: &Apache::lonnet::logthis($error);
9307: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9308: }
9309: }
1.256 raeburn 9310:
9311: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
9312: if (ref($domconfig{'login'}) eq 'HASH') {
9313: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
9314: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
9315: if ($domservers{$lonhost}) {
9316: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9317: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 9318: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 9319: }
9320: }
9321: }
9322: }
9323: }
9324: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
9325: foreach my $lonhost (sort(keys(%domservers))) {
9326: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9327: $changes{'headtag'}{$lonhost} = 1;
9328: } else {
9329: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
9330: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
9331: }
9332: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
9333: push(@newhosts,$lonhost);
9334: } elsif ($currheadtagurls{$lonhost}) {
9335: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
9336: if ($currexempt{$lonhost}) {
1.289 raeburn 9337: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 9338: $changes{'headtag'}{$lonhost} = 1;
9339: }
9340: } elsif ($possexempt{$lonhost}) {
9341: $changes{'headtag'}{$lonhost} = 1;
9342: }
9343: if ($possexempt{$lonhost}) {
9344: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9345: }
9346: }
9347: }
9348: }
9349: if (@newhosts) {
9350: my $error;
9351: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9352: if ($configuserok eq 'ok') {
9353: if ($switchserver) {
9354: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
9355: } elsif ($author_ok eq 'ok') {
9356: foreach my $lonhost (@newhosts) {
9357: my $formelem = 'loginheadtag_'.$lonhost;
9358: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9359: "login/headtag/$lonhost",'','',
9360: $env{'form.loginheadtag_'.$lonhost.'.filename'});
9361: if ($result eq 'ok') {
9362: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
9363: $changes{'headtag'}{$lonhost} = 1;
9364: if ($possexempt{$lonhost}) {
9365: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9366: }
9367: } else {
9368: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
9369: $newheadtagurls{$lonhost},$result);
9370: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
9371: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
9372: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
9373: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
9374: }
9375: }
9376: }
9377: } else {
9378: $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);
9379: }
9380: } else {
9381: $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);
9382: }
9383: if ($error) {
9384: &Apache::lonnet::logthis($error);
9385: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9386: }
9387: }
1.169 raeburn 9388: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 9389:
9390: my $defaulthelpfile = '/adm/loginproblems.html';
9391: my $defaulttext = &mt('Default in use');
9392:
1.1 raeburn 9393: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
9394: $dom);
9395: if ($putresult eq 'ok') {
1.188 raeburn 9396: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 9397: my %defaultchecked = (
9398: 'coursecatalog' => 'on',
1.188 raeburn 9399: 'helpdesk' => 'on',
1.42 raeburn 9400: 'adminmail' => 'off',
1.43 raeburn 9401: 'newuser' => 'off',
1.42 raeburn 9402: );
1.55 raeburn 9403: if (ref($domconfig{'login'}) eq 'HASH') {
9404: foreach my $item (@toggles) {
9405: if ($defaultchecked{$item} eq 'on') {
9406: if (($domconfig{'login'}{$item} eq '0') &&
9407: ($env{'form.'.$item} eq '1')) {
9408: $changes{$item} = 1;
9409: } elsif (($domconfig{'login'}{$item} eq '' ||
9410: $domconfig{'login'}{$item} eq '1') &&
9411: ($env{'form.'.$item} eq '0')) {
9412: $changes{$item} = 1;
9413: }
9414: } elsif ($defaultchecked{$item} eq 'off') {
9415: if (($domconfig{'login'}{$item} eq '1') &&
9416: ($env{'form.'.$item} eq '0')) {
9417: $changes{$item} = 1;
9418: } elsif (($domconfig{'login'}{$item} eq '' ||
9419: $domconfig{'login'}{$item} eq '0') &&
9420: ($env{'form.'.$item} eq '1')) {
9421: $changes{$item} = 1;
9422: }
1.42 raeburn 9423: }
9424: }
1.41 raeburn 9425: }
1.6 raeburn 9426: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 9427: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9428: if (ref($lastactref) eq 'HASH') {
9429: $lastactref->{'domainconfig'} = 1;
9430: }
1.1 raeburn 9431: $resulttext = &mt('Changes made:').'<ul>';
9432: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 9433: if ($item eq 'loginvia') {
1.112 raeburn 9434: if (ref($changes{$item}) eq 'HASH') {
9435: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
9436: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 9437: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
9438: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
9439: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
9440: $protocol = 'http' if ($protocol ne 'https');
9441: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
9442:
9443: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
9444: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
9445: } else {
9446: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
9447: }
9448: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
9449: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
9450: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
9451: }
9452: $resulttext .= '</li>';
9453: } else {
9454: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
9455: }
1.112 raeburn 9456: } else {
1.128 raeburn 9457: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 9458: }
9459: }
1.128 raeburn 9460: $resulttext .= '</ul></li>';
1.112 raeburn 9461: }
1.168 raeburn 9462: } elsif ($item eq 'helpurl') {
9463: if (ref($changes{$item}) eq 'HASH') {
9464: foreach my $lang (sort(keys(%{$changes{$item}}))) {
9465: if (grep(/^\Q$lang\E$/,@delurls)) {
9466: my ($chg,$link);
9467: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
9468: if ($lang eq 'nolang') {
9469: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
9470: } else {
9471: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
9472: }
9473: $resulttext .= '<li>'.$chg.'</li>';
9474: } else {
9475: my $chg;
9476: if ($lang eq 'nolang') {
9477: $chg = &mt('custom log-in help file for no preferred language');
9478: } else {
9479: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
9480: }
9481: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
9482: $loginhash{'login'}{'helpurl'}{$lang}.
9483: '?inhibitmenu=yes',$chg,600,500).
9484: '</li>';
9485: }
9486: }
9487: }
1.256 raeburn 9488: } elsif ($item eq 'headtag') {
9489: if (ref($changes{$item}) eq 'HASH') {
9490: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
9491: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9492: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
9493: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9494: $resulttext .= '<li><a href="'.
9495: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
9496: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
9497: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
9498: if ($possexempt{$lonhost}) {
9499: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
9500: } else {
9501: $resulttext .= &mt('included for any client IP');
9502: }
9503: $resulttext .= '</li>';
9504: }
9505: }
9506: }
1.169 raeburn 9507: } elsif ($item eq 'captcha') {
9508: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 9509: my $chgtxt;
1.169 raeburn 9510: if ($loginhash{'login'}{$item} eq 'notused') {
9511: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
9512: } else {
9513: my %captchas = &captcha_phrases();
9514: if ($captchas{$loginhash{'login'}{$item}}) {
9515: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
9516: } else {
9517: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
9518: }
9519: }
9520: $resulttext .= '<li>'.$chgtxt.'</li>';
9521: }
9522: } elsif ($item eq 'recaptchakeys') {
9523: if (ref($loginhash{'login'}) eq 'HASH') {
9524: my ($privkey,$pubkey);
9525: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
9526: $pubkey = $loginhash{'login'}{$item}{'public'};
9527: $privkey = $loginhash{'login'}{$item}{'private'};
9528: }
9529: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
9530: if (!$pubkey) {
9531: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
9532: } else {
9533: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
9534: }
9535: if (!$privkey) {
9536: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
9537: } else {
1.251 raeburn 9538: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 9539: }
9540: $chgtxt .= '</ul>';
9541: $resulttext .= '<li>'.$chgtxt.'</li>';
9542: }
1.269 raeburn 9543: } elsif ($item eq 'recaptchaversion') {
9544: if (ref($loginhash{'login'}) eq 'HASH') {
9545: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 9546: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 9547: '</li>';
9548: }
9549: }
1.41 raeburn 9550: } else {
9551: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
9552: }
1.1 raeburn 9553: }
1.6 raeburn 9554: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 9555: } else {
9556: $resulttext = &mt('No changes made to log-in page settings');
9557: }
9558: } else {
1.11 albertel 9559: $resulttext = '<span class="LC_error">'.
9560: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9561: }
1.6 raeburn 9562: if ($errors) {
1.9 raeburn 9563: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 9564: $errors.'</ul>';
9565: }
9566: return $resulttext;
9567: }
9568:
1.256 raeburn 9569: sub check_exempt_addresses {
9570: my ($iplist) = @_;
9571: $iplist =~ s/^\s+//;
9572: $iplist =~ s/\s+$//;
9573: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
9574: my (@okips,$new);
9575: foreach my $ip (@poss_ips) {
9576: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
9577: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
9578: push(@okips,$ip);
9579: }
9580: }
9581: }
9582: if (@okips > 0) {
9583: $new = join(',',@okips);
9584: } else {
9585: $new = '';
9586: }
9587: return $new;
9588: }
9589:
1.6 raeburn 9590: sub color_font_choices {
9591: my %choices =
9592: &Apache::lonlocal::texthash (
9593: img => "Header",
9594: bgs => "Background colors",
9595: links => "Link colors",
1.55 raeburn 9596: images => "Images",
1.6 raeburn 9597: font => "Font color",
1.201 raeburn 9598: fontmenu => "Font menu",
1.76 raeburn 9599: pgbg => "Page",
1.6 raeburn 9600: tabbg => "Header",
9601: sidebg => "Border",
9602: link => "Link",
9603: alink => "Active link",
9604: vlink => "Visited link",
9605: );
9606: return %choices;
9607: }
9608:
9609: sub modify_rolecolors {
1.205 raeburn 9610: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 9611: my ($resulttext,%rolehash);
9612: $rolehash{'rolecolors'} = {};
1.55 raeburn 9613: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
9614: if ($domconfig{'rolecolors'} eq '') {
9615: $domconfig{'rolecolors'} = {};
9616: }
9617: }
1.9 raeburn 9618: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 9619: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
9620: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
9621: $dom);
9622: if ($putresult eq 'ok') {
9623: if (keys(%changes) > 0) {
1.41 raeburn 9624: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9625: if (ref($lastactref) eq 'HASH') {
9626: $lastactref->{'domainconfig'} = 1;
9627: }
1.6 raeburn 9628: $resulttext = &display_colorchgs($dom,\%changes,$roles,
9629: $rolehash{'rolecolors'});
9630: } else {
9631: $resulttext = &mt('No changes made to default color schemes');
9632: }
9633: } else {
1.11 albertel 9634: $resulttext = '<span class="LC_error">'.
9635: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 9636: }
9637: if ($errors) {
9638: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9639: $errors.'</ul>';
9640: }
9641: return $resulttext;
9642: }
9643:
9644: sub modify_colors {
1.9 raeburn 9645: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 9646: my (%changes,%choices);
1.51 raeburn 9647: my @bgs;
1.6 raeburn 9648: my @links = ('link','alink','vlink');
1.41 raeburn 9649: my @logintext;
1.6 raeburn 9650: my @images;
9651: my $servadm = $r->dir_config('lonAdmEMail');
9652: my $errors;
1.200 raeburn 9653: my %defaults;
1.6 raeburn 9654: foreach my $role (@{$roles}) {
9655: if ($role eq 'login') {
1.12 raeburn 9656: %choices = &login_choices();
1.41 raeburn 9657: @logintext = ('textcol','bgcol');
1.12 raeburn 9658: } else {
9659: %choices = &color_font_choices();
9660: }
9661: if ($role eq 'login') {
1.41 raeburn 9662: @images = ('img','logo','domlogo','login');
1.51 raeburn 9663: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 9664: } else {
9665: @images = ('img');
1.200 raeburn 9666: @bgs = ('pgbg','tabbg','sidebg');
9667: }
9668: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
9669: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
9670: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
9671: }
9672: if ($role eq 'login') {
9673: foreach my $item (@logintext) {
1.234 raeburn 9674: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9675: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9676: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9677: }
9678: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 9679: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9680: }
9681: }
9682: } else {
1.234 raeburn 9683: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
9684: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
9685: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
9686: }
9687: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 9688: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
9689: }
1.6 raeburn 9690: }
1.200 raeburn 9691: foreach my $item (@bgs) {
1.234 raeburn 9692: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9693: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9694: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9695: }
9696: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 9697: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9698: }
9699: }
9700: foreach my $item (@links) {
1.234 raeburn 9701: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9702: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9703: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9704: }
9705: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 9706: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9707: }
1.6 raeburn 9708: }
1.46 raeburn 9709: my ($configuserok,$author_ok,$switchserver) =
9710: &config_check($dom,$confname,$servadm);
1.9 raeburn 9711: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 9712: if (ref($domconfig->{$role}) ne 'HASH') {
9713: $domconfig->{$role} = {};
9714: }
1.8 raeburn 9715: foreach my $img (@images) {
1.70 raeburn 9716: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
9717: if (defined($env{'form.login_showlogo_'.$img})) {
9718: $confhash->{$role}{'showlogo'}{$img} = 1;
9719: } else {
9720: $confhash->{$role}{'showlogo'}{$img} = 0;
9721: }
9722: }
1.18 albertel 9723: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
9724: && !defined($domconfig->{$role}{$img})
9725: && !$env{'form.'.$role.'_del_'.$img}
9726: && $env{'form.'.$role.'_import_'.$img}) {
9727: # import the old configured image from the .tab setting
9728: # if they haven't provided a new one
9729: $domconfig->{$role}{$img} =
9730: $env{'form.'.$role.'_import_'.$img};
9731: }
1.6 raeburn 9732: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 9733: my $error;
1.6 raeburn 9734: if ($configuserok eq 'ok') {
1.9 raeburn 9735: if ($switchserver) {
1.12 raeburn 9736: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 9737: } else {
9738: if ($author_ok eq 'ok') {
9739: my ($result,$logourl) =
9740: &publishlogo($r,'upload',$role.'_'.$img,
9741: $dom,$confname,$img,$width,$height);
9742: if ($result eq 'ok') {
9743: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 9744: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 9745: } else {
1.12 raeburn 9746: $error = &mt("Upload of [_1] image for $role page(s) failed because an error occurred publishing the file in RES space. Error was: [_2].",$choices{img},$result);
1.9 raeburn 9747: }
9748: } else {
1.46 raeburn 9749: $error = &mt("Upload of [_1] image for $role page(s) failed because an author role could not be assigned to a Domain Configuration user ([_2]) in domain: [_3]. Error was: [_4].",$choices{$img},$confname,$dom,$author_ok);
1.6 raeburn 9750: }
9751: }
9752: } else {
1.46 raeburn 9753: $error = &mt("Upload of [_1] image for $role page(s) failed because a Domain Configuration user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$choices{$img},$confname,$dom,$configuserok);
1.9 raeburn 9754: }
9755: if ($error) {
1.8 raeburn 9756: &Apache::lonnet::logthis($error);
1.11 albertel 9757: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 9758: }
9759: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 9760: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
9761: my $error;
9762: if ($configuserok eq 'ok') {
9763: # is confname an author?
9764: if ($switchserver eq '') {
9765: if ($author_ok eq 'ok') {
9766: my ($result,$logourl) =
9767: &publishlogo($r,'copy',$domconfig->{$role}{$img},
9768: $dom,$confname,$img,$width,$height);
9769: if ($result eq 'ok') {
9770: $confhash->{$role}{$img} = $logourl;
1.18 albertel 9771: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 9772: }
9773: }
9774: }
9775: }
1.6 raeburn 9776: }
9777: }
9778: }
9779: if (ref($domconfig) eq 'HASH') {
9780: if (ref($domconfig->{$role}) eq 'HASH') {
9781: foreach my $img (@images) {
9782: if ($domconfig->{$role}{$img} ne '') {
9783: if ($env{'form.'.$role.'_del_'.$img}) {
9784: $confhash->{$role}{$img} = '';
1.12 raeburn 9785: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 9786: } else {
1.9 raeburn 9787: if ($confhash->{$role}{$img} eq '') {
9788: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
9789: }
1.6 raeburn 9790: }
9791: } else {
9792: if ($env{'form.'.$role.'_del_'.$img}) {
9793: $confhash->{$role}{$img} = '';
1.12 raeburn 9794: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 9795: }
9796: }
1.70 raeburn 9797: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
9798: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
9799: if ($confhash->{$role}{'showlogo'}{$img} ne
9800: $domconfig->{$role}{'showlogo'}{$img}) {
9801: $changes{$role}{'showlogo'}{$img} = 1;
9802: }
9803: } else {
9804: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
9805: $changes{$role}{'showlogo'}{$img} = 1;
9806: }
9807: }
9808: }
9809: }
1.6 raeburn 9810: if ($domconfig->{$role}{'font'} ne '') {
9811: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
9812: $changes{$role}{'font'} = 1;
9813: }
9814: } else {
9815: if ($confhash->{$role}{'font'}) {
9816: $changes{$role}{'font'} = 1;
9817: }
9818: }
1.107 raeburn 9819: if ($role ne 'login') {
9820: if ($domconfig->{$role}{'fontmenu'} ne '') {
9821: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
9822: $changes{$role}{'fontmenu'} = 1;
9823: }
9824: } else {
9825: if ($confhash->{$role}{'fontmenu'}) {
9826: $changes{$role}{'fontmenu'} = 1;
9827: }
1.97 tempelho 9828: }
9829: }
1.6 raeburn 9830: foreach my $item (@bgs) {
9831: if ($domconfig->{$role}{$item} ne '') {
9832: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9833: $changes{$role}{'bgs'}{$item} = 1;
9834: }
9835: } else {
9836: if ($confhash->{$role}{$item}) {
9837: $changes{$role}{'bgs'}{$item} = 1;
9838: }
9839: }
9840: }
9841: foreach my $item (@links) {
9842: if ($domconfig->{$role}{$item} ne '') {
9843: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9844: $changes{$role}{'links'}{$item} = 1;
9845: }
9846: } else {
9847: if ($confhash->{$role}{$item}) {
9848: $changes{$role}{'links'}{$item} = 1;
9849: }
9850: }
9851: }
1.41 raeburn 9852: foreach my $item (@logintext) {
9853: if ($domconfig->{$role}{$item} ne '') {
9854: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9855: $changes{$role}{'logintext'}{$item} = 1;
9856: }
9857: } else {
9858: if ($confhash->{$role}{$item}) {
9859: $changes{$role}{'logintext'}{$item} = 1;
9860: }
9861: }
9862: }
1.6 raeburn 9863: } else {
9864: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 9865: \@logintext,$confhash,\%changes);
1.6 raeburn 9866: }
9867: } else {
9868: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 9869: \@logintext,$confhash,\%changes);
1.6 raeburn 9870: }
9871: }
9872: return ($errors,%changes);
9873: }
9874:
1.46 raeburn 9875: sub config_check {
9876: my ($dom,$confname,$servadm) = @_;
9877: my ($configuserok,$author_ok,$switchserver,%currroles);
9878: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
9879: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
9880: $confname,$servadm);
9881: if ($configuserok eq 'ok') {
9882: $switchserver = &check_switchserver($dom,$confname);
9883: if ($switchserver eq '') {
9884: $author_ok = &check_authorstatus($dom,$confname,%currroles);
9885: }
9886: }
9887: return ($configuserok,$author_ok,$switchserver);
9888: }
9889:
1.6 raeburn 9890: sub default_change_checker {
1.41 raeburn 9891: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 9892: foreach my $item (@{$links}) {
9893: if ($confhash->{$role}{$item}) {
9894: $changes->{$role}{'links'}{$item} = 1;
9895: }
9896: }
9897: foreach my $item (@{$bgs}) {
9898: if ($confhash->{$role}{$item}) {
9899: $changes->{$role}{'bgs'}{$item} = 1;
9900: }
9901: }
1.41 raeburn 9902: foreach my $item (@{$logintext}) {
9903: if ($confhash->{$role}{$item}) {
9904: $changes->{$role}{'logintext'}{$item} = 1;
9905: }
9906: }
1.6 raeburn 9907: foreach my $img (@{$images}) {
9908: if ($env{'form.'.$role.'_del_'.$img}) {
9909: $confhash->{$role}{$img} = '';
1.12 raeburn 9910: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 9911: }
1.70 raeburn 9912: if ($role eq 'login') {
9913: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
9914: $changes->{$role}{'showlogo'}{$img} = 1;
9915: }
9916: }
1.6 raeburn 9917: }
9918: if ($confhash->{$role}{'font'}) {
9919: $changes->{$role}{'font'} = 1;
9920: }
1.48 raeburn 9921: }
1.6 raeburn 9922:
9923: sub display_colorchgs {
9924: my ($dom,$changes,$roles,$confhash) = @_;
9925: my (%choices,$resulttext);
9926: if (!grep(/^login$/,@{$roles})) {
9927: $resulttext = &mt('Changes made:').'<br />';
9928: }
9929: foreach my $role (@{$roles}) {
9930: if ($role eq 'login') {
9931: %choices = &login_choices();
9932: } else {
9933: %choices = &color_font_choices();
9934: }
9935: if (ref($changes->{$role}) eq 'HASH') {
9936: if ($role ne 'login') {
9937: $resulttext .= '<h4>'.&mt($role).'</h4>';
9938: }
9939: foreach my $key (sort(keys(%{$changes->{$role}}))) {
9940: if ($role ne 'login') {
9941: $resulttext .= '<ul>';
9942: }
9943: if (ref($changes->{$role}{$key}) eq 'HASH') {
9944: if ($role ne 'login') {
9945: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
9946: }
9947: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 9948: if (($role eq 'login') && ($key eq 'showlogo')) {
9949: if ($confhash->{$role}{$key}{$item}) {
9950: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
9951: } else {
9952: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
9953: }
9954: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 9955: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
9956: } else {
1.12 raeburn 9957: my $newitem = $confhash->{$role}{$item};
9958: if ($key eq 'images') {
1.306 raeburn 9959: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 9960: }
9961: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 9962: }
9963: }
9964: if ($role ne 'login') {
9965: $resulttext .= '</ul></li>';
9966: }
9967: } else {
9968: if ($confhash->{$role}{$key} eq '') {
9969: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
9970: } else {
9971: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
9972: }
9973: }
9974: if ($role ne 'login') {
9975: $resulttext .= '</ul>';
9976: }
9977: }
9978: }
9979: }
1.3 raeburn 9980: return $resulttext;
1.1 raeburn 9981: }
9982:
1.9 raeburn 9983: sub thumb_dimensions {
9984: return ('200','50');
9985: }
9986:
1.16 raeburn 9987: sub check_dimensions {
9988: my ($inputfile) = @_;
9989: my ($fullwidth,$fullheight);
9990: if ($inputfile =~ m|^[/\w.\-]+$|) {
9991: if (open(PIPE,"identify $inputfile 2>&1 |")) {
9992: my $imageinfo = <PIPE>;
9993: if (!close(PIPE)) {
9994: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
9995: }
9996: chomp($imageinfo);
9997: my ($fullsize) =
1.21 raeburn 9998: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 9999: if ($fullsize) {
10000: ($fullwidth,$fullheight) = split(/x/,$fullsize);
10001: }
10002: }
10003: }
10004: return ($fullwidth,$fullheight);
10005: }
10006:
1.9 raeburn 10007: sub check_configuser {
10008: my ($uhome,$dom,$confname,$servadm) = @_;
10009: my ($configuserok,%currroles);
10010: if ($uhome eq 'no_host') {
10011: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
10012: my $configpass = &LONCAPA::Enrollment::create_password();
10013: $configuserok =
10014: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
10015: $configpass,'','','','','',undef,$servadm);
10016: } else {
10017: $configuserok = 'ok';
10018: %currroles =
10019: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
10020: }
10021: return ($configuserok,%currroles);
10022: }
10023:
10024: sub check_authorstatus {
10025: my ($dom,$confname,%currroles) = @_;
10026: my $author_ok;
1.40 raeburn 10027: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 10028: my $start = time;
10029: my $end = 0;
10030: $author_ok =
10031: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 10032: 'au',$end,$start,'','','domconfig');
1.9 raeburn 10033: } else {
10034: $author_ok = 'ok';
10035: }
10036: return $author_ok;
10037: }
10038:
10039: sub publishlogo {
1.46 raeburn 10040: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 10041: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 10042: if ($action eq 'upload') {
10043: $fname=$env{'form.'.$formname.'.filename'};
10044: chop($env{'form.'.$formname});
10045: } else {
10046: ($fname) = ($formname =~ /([^\/]+)$/);
10047: }
1.46 raeburn 10048: if ($savefileas ne '') {
10049: $fname = $savefileas;
10050: }
1.9 raeburn 10051: $fname=&Apache::lonnet::clean_filename($fname);
10052: # See if there is anything left
10053: unless ($fname) { return ('error: no uploaded file'); }
10054: $fname="$subdir/$fname";
1.210 raeburn 10055: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 10056: my $filepath="$docroot/priv";
10057: my $relpath = "$dom/$confname";
1.9 raeburn 10058: my ($fnamepath,$file,$fetchthumb);
10059: $file=$fname;
10060: if ($fname=~m|/|) {
10061: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
10062: }
1.164 raeburn 10063: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 10064: my $count;
1.164 raeburn 10065: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 10066: $filepath.="/$parts[$count]";
10067: if ((-e $filepath)!=1) {
10068: mkdir($filepath,02770);
10069: }
10070: }
10071: # Check for bad extension and disallow upload
10072: if ($file=~/\.(\w+)$/ &&
10073: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
10074: $output =
1.207 bisitz 10075: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 10076: } elsif ($file=~/\.(\w+)$/ &&
10077: !defined(&Apache::loncommon::fileembstyle($1))) {
10078: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
10079: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 10080: $output = &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
1.9 raeburn 10081: } elsif (-d "$filepath/$file") {
1.195 bisitz 10082: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 10083: } else {
10084: my $source = $filepath.'/'.$file;
10085: my $logfile;
1.316 raeburn 10086: if (!open($logfile,">>",$source.'.log')) {
1.196 raeburn 10087: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 10088: }
10089: print $logfile
10090: "\n================= Publish ".localtime()." ================\n".
10091: $env{'user.name'}.':'.$env{'user.domain'}."\n";
10092: # Save the file
1.316 raeburn 10093: if (!open(FH,">",$source)) {
1.9 raeburn 10094: &Apache::lonnet::logthis('Failed to create '.$source);
10095: return (&mt('Failed to create file'));
10096: }
10097: if ($action eq 'upload') {
10098: if (!print FH ($env{'form.'.$formname})) {
10099: &Apache::lonnet::logthis('Failed to write to '.$source);
10100: return (&mt('Failed to write file'));
10101: }
10102: } else {
10103: my $original = &Apache::lonnet::filelocation('',$formname);
10104: if(!copy($original,$source)) {
10105: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
10106: return (&mt('Failed to write file'));
10107: }
10108: }
10109: close(FH);
10110: chmod(0660, $source); # Permissions to rw-rw---.
10111:
10112: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
10113: my $copyfile=$targetdir.'/'.$file;
10114:
10115: my @parts=split(/\//,$targetdir);
10116: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
10117: for (my $count=5;$count<=$#parts;$count++) {
10118: $path.="/$parts[$count]";
10119: if (!-e $path) {
10120: print $logfile "\nCreating directory ".$path;
10121: mkdir($path,02770);
10122: }
10123: }
10124: my $versionresult;
10125: if (-e $copyfile) {
10126: $versionresult = &logo_versioning($targetdir,$file,$logfile);
10127: } else {
10128: $versionresult = 'ok';
10129: }
10130: if ($versionresult eq 'ok') {
10131: if (copy($source,$copyfile)) {
10132: print $logfile "\nCopied original source to ".$copyfile."\n";
10133: $output = 'ok';
10134: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 10135: push(@{$modified_urls},[$copyfile,$source]);
10136: my $metaoutput =
10137: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
10138: unless ($registered_cleanup) {
10139: my $handlers = $r->get_handlers('PerlCleanupHandler');
10140: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
10141: $registered_cleanup=1;
10142: }
1.9 raeburn 10143: } else {
10144: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
10145: $output = &mt('Failed to copy file to RES space').", $!";
10146: }
10147: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
10148: my $inputfile = $filepath.'/'.$file;
10149: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 10150: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
10151: if ($fullwidth ne '' && $fullheight ne '') {
10152: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
10153: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316 raeburn 10154: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
10155: system({$args[0]} @args);
1.16 raeburn 10156: chmod(0660, $filepath.'/tn-'.$file);
10157: if (-e $outfile) {
10158: my $copyfile=$targetdir.'/tn-'.$file;
10159: if (copy($outfile,$copyfile)) {
10160: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 10161: my $thumb_metaoutput =
10162: &write_metadata($dom,$confname,$formname,
10163: $targetdir,'tn-'.$file,$logfile);
10164: push(@{$modified_urls},[$copyfile,$outfile]);
10165: unless ($registered_cleanup) {
10166: my $handlers = $r->get_handlers('PerlCleanupHandler');
10167: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
10168: $registered_cleanup=1;
10169: }
1.267 raeburn 10170: $madethumb = 1;
1.16 raeburn 10171: } else {
10172: print $logfile "\nUnable to write ".$copyfile.
10173: ':'.$!."\n";
10174: }
10175: }
1.9 raeburn 10176: }
10177: }
10178: }
10179: } else {
10180: $output = $versionresult;
10181: }
10182: }
1.267 raeburn 10183: return ($output,$logourl,$madethumb);
1.9 raeburn 10184: }
10185:
10186: sub logo_versioning {
10187: my ($targetdir,$file,$logfile) = @_;
10188: my $target = $targetdir.'/'.$file;
10189: my ($maxversion,$fn,$extn,$output);
10190: $maxversion = 0;
10191: if ($file =~ /^(.+)\.(\w+)$/) {
10192: $fn=$1;
10193: $extn=$2;
10194: }
10195: opendir(DIR,$targetdir);
10196: while (my $filename=readdir(DIR)) {
10197: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
10198: $maxversion=($1>$maxversion)?$1:$maxversion;
10199: }
10200: }
10201: $maxversion++;
10202: print $logfile "\nCreating old version ".$maxversion."\n";
10203: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
10204: if (copy($target,$copyfile)) {
10205: print $logfile "Copied old target to ".$copyfile."\n";
10206: $copyfile=$copyfile.'.meta';
10207: if (copy($target.'.meta',$copyfile)) {
10208: print $logfile "Copied old target metadata to ".$copyfile."\n";
10209: $output = 'ok';
10210: } else {
10211: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
10212: $output = &mt('Failed to copy old meta').", $!, ";
10213: }
10214: } else {
10215: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
10216: $output = &mt('Failed to copy old target').", $!, ";
10217: }
10218: return $output;
10219: }
10220:
10221: sub write_metadata {
10222: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
10223: my (%metadatafields,%metadatakeys,$output);
10224: $metadatafields{'title'}=$formname;
10225: $metadatafields{'creationdate'}=time;
10226: $metadatafields{'lastrevisiondate'}=time;
10227: $metadatafields{'copyright'}='public';
10228: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
10229: $env{'user.domain'};
10230: $metadatafields{'authorspace'}=$confname.':'.$dom;
10231: $metadatafields{'domain'}=$dom;
10232: {
10233: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
10234: my $mfh;
1.316 raeburn 10235: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 10236: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 10237: unless ($_=~/\./) {
10238: my $unikey=$_;
10239: $unikey=~/^([A-Za-z]+)/;
10240: my $tag=$1;
10241: $tag=~tr/A-Z/a-z/;
10242: print $mfh "\n\<$tag";
10243: foreach (split(/\,/,$metadatakeys{$unikey})) {
10244: my $value=$metadatafields{$unikey.'.'.$_};
10245: $value=~s/\"/\'\'/g;
10246: print $mfh ' '.$_.'="'.$value.'"';
10247: }
10248: print $mfh '>'.
10249: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
10250: .'</'.$tag.'>';
10251: }
10252: }
10253: $output = 'ok';
10254: print $logfile "\nWrote metadata";
10255: close($mfh);
10256: } else {
10257: print $logfile "\nFailed to open metadata file";
1.9 raeburn 10258: $output = &mt('Could not write metadata');
10259: }
10260: }
1.155 raeburn 10261: return $output;
10262: }
10263:
10264: sub notifysubscribed {
10265: foreach my $targetsource (@{$modified_urls}){
10266: next unless (ref($targetsource) eq 'ARRAY');
10267: my ($target,$source)=@{$targetsource};
10268: if ($source ne '') {
1.316 raeburn 10269: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 10270: print $logfh "\nCleanup phase: Notifications\n";
10271: my @subscribed=&subscribed_hosts($target);
10272: foreach my $subhost (@subscribed) {
10273: print $logfh "\nNotifying host ".$subhost.':';
10274: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
10275: print $logfh $reply;
10276: }
10277: my @subscribedmeta=&subscribed_hosts("$target.meta");
10278: foreach my $subhost (@subscribedmeta) {
10279: print $logfh "\nNotifying host for metadata only ".$subhost.':';
10280: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
10281: $subhost);
10282: print $logfh $reply;
10283: }
10284: print $logfh "\n============ Done ============\n";
1.160 raeburn 10285: close($logfh);
1.155 raeburn 10286: }
10287: }
10288: }
10289: return OK;
10290: }
10291:
10292: sub subscribed_hosts {
10293: my ($target) = @_;
10294: my @subscribed;
1.316 raeburn 10295: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 10296: while (my $subline=<$fh>) {
10297: if ($subline =~ /^($match_lonid):/) {
10298: my $host = $1;
10299: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
10300: unless (grep(/^\Q$host\E$/,@subscribed)) {
10301: push(@subscribed,$host);
10302: }
10303: }
10304: }
10305: }
10306: }
10307: return @subscribed;
1.9 raeburn 10308: }
10309:
10310: sub check_switchserver {
10311: my ($dom,$confname) = @_;
10312: my ($allowed,$switchserver);
10313: my $home = &Apache::lonnet::homeserver($confname,$dom);
10314: if ($home eq 'no_host') {
10315: $home = &Apache::lonnet::domain($dom,'primary');
10316: }
10317: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 10318: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
10319: if (!$allowed) {
1.180 raeburn 10320: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 10321: }
10322: return $switchserver;
10323: }
10324:
1.1 raeburn 10325: sub modify_quotas {
1.216 raeburn 10326: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 10327: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 10328: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 10329: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
10330: $validationfieldsref);
1.86 raeburn 10331: if ($action eq 'quotas') {
10332: $context = 'tools';
1.163 raeburn 10333: } else {
1.86 raeburn 10334: $context = $action;
10335: }
10336: if ($context eq 'requestcourses') {
1.325 raeburn 10337: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 10338: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 10339: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
10340: %titles = &courserequest_titles();
10341: $toolregexp = join('|',@usertools);
10342: %conditions = &courserequest_conditions();
1.216 raeburn 10343: $confname = $dom.'-domainconfig';
10344: my $servadm = $r->dir_config('lonAdmEMail');
10345: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 10346: ($validationitemsref,$validationnamesref,$validationfieldsref) =
10347: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 10348: } elsif ($context eq 'requestauthor') {
10349: @usertools = ('author');
10350: %titles = &authorrequest_titles();
1.86 raeburn 10351: } else {
1.162 raeburn 10352: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 10353: %titles = &tool_titles();
1.86 raeburn 10354: }
1.212 raeburn 10355: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 10356: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 10357: foreach my $key (keys(%env)) {
1.101 raeburn 10358: if ($context eq 'requestcourses') {
10359: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
10360: my $item = $1;
10361: my $type = $2;
10362: if ($type =~ /^limit_(.+)/) {
10363: $limithash{$item}{$1} = $env{$key};
10364: } else {
10365: $confhash{$item}{$type} = $env{$key};
10366: }
10367: }
1.163 raeburn 10368: } elsif ($context eq 'requestauthor') {
10369: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
10370: $confhash{$1} = $env{$key};
10371: }
1.101 raeburn 10372: } else {
1.86 raeburn 10373: if ($key =~ /^form\.quota_(.+)$/) {
10374: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 10375: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
10376: $confhash{'authorquota'}{$1} = $env{$key};
10377: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 10378: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
10379: }
1.72 raeburn 10380: }
10381: }
1.163 raeburn 10382: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 10383: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 10384: @approvalnotify = sort(@approvalnotify);
10385: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 10386: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 10387: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
10388: foreach my $type (@hasuniquecode) {
10389: if (grep(/^\Q$type\E$/,@crstypes)) {
10390: $confhash{'uniquecode'}{$type} = 1;
10391: }
1.216 raeburn 10392: }
1.242 raeburn 10393: my (%newbook,%allpos);
1.216 raeburn 10394: if ($context eq 'requestcourses') {
1.242 raeburn 10395: foreach my $type ('textbooks','templates') {
10396: @{$allpos{$type}} = ();
10397: my $invalid;
10398: if ($type eq 'textbooks') {
10399: $invalid = &mt('Invalid LON-CAPA course for textbook');
10400: } else {
10401: $invalid = &mt('Invalid LON-CAPA course for template');
10402: }
10403: if ($env{'form.'.$type.'_addbook'}) {
10404: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
10405: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
10406: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
10407: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
10408: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
10409: } else {
10410: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
10411: my $position = $env{'form.'.$type.'_addbook_pos'};
10412: $position =~ s/\D+//g;
10413: if ($position ne '') {
10414: $allpos{$type}[$position] = $newbook{$type};
10415: }
1.216 raeburn 10416: }
1.242 raeburn 10417: } else {
10418: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 10419: }
10420: }
1.242 raeburn 10421: }
1.216 raeburn 10422: }
1.102 raeburn 10423: if (ref($domconfig{$action}) eq 'HASH') {
10424: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
10425: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
10426: $changes{'notify'}{'approval'} = 1;
10427: }
10428: } else {
1.144 raeburn 10429: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10430: $changes{'notify'}{'approval'} = 1;
10431: }
10432: }
1.218 raeburn 10433: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
10434: if (ref($confhash{'uniquecode'}) eq 'HASH') {
10435: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
10436: unless ($confhash{'uniquecode'}{$crstype}) {
10437: $changes{'uniquecode'} = 1;
10438: }
10439: }
10440: unless ($changes{'uniquecode'}) {
10441: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
10442: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
10443: $changes{'uniquecode'} = 1;
10444: }
10445: }
10446: }
10447: } else {
10448: $changes{'uniquecode'} = 1;
10449: }
10450: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
10451: $changes{'uniquecode'} = 1;
1.216 raeburn 10452: }
10453: if ($context eq 'requestcourses') {
1.242 raeburn 10454: foreach my $type ('textbooks','templates') {
10455: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10456: my %deletions;
10457: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
10458: if (@todelete) {
10459: map { $deletions{$_} = 1; } @todelete;
10460: }
10461: my %imgdeletions;
10462: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
10463: if (@todeleteimages) {
10464: map { $imgdeletions{$_} = 1; } @todeleteimages;
10465: }
10466: my $maxnum = $env{'form.'.$type.'_maxnum'};
10467: for (my $i=0; $i<=$maxnum; $i++) {
10468: my $itemid = $env{'form.'.$type.'_id_'.$i};
10469: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
10470: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
10471: if ($deletions{$key}) {
10472: if ($domconfig{$action}{$type}{$key}{'image'}) {
10473: #FIXME need to obsolete item in RES space
10474: }
10475: next;
10476: } else {
10477: my $newpos = $env{'form.'.$itemid};
10478: $newpos =~ s/\D+//g;
1.243 raeburn 10479: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 10480: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 10481: ($type eq 'templates'));
1.242 raeburn 10482: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
10483: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
10484: $changes{$type}{$key} = 1;
10485: }
10486: }
10487: $allpos{$type}[$newpos] = $key;
10488: }
10489: if ($imgdeletions{$key}) {
10490: $changes{$type}{$key} = 1;
1.216 raeburn 10491: #FIXME need to obsolete item in RES space
1.242 raeburn 10492: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
10493: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 10494: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10495: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10496: } else {
10497: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
10498: $cdom,$cnum,$type,$configuserok,
10499: $switchserver,$author_ok);
10500: if ($imgurl) {
10501: $confhash{$type}{$key}{'image'} = $imgurl;
10502: $changes{$type}{$key} = 1;
10503: }
10504: if ($error) {
10505: &Apache::lonnet::logthis($error);
10506: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10507: }
10508: }
1.242 raeburn 10509: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
10510: $confhash{$type}{$key}{'image'} =
10511: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 10512: }
10513: }
10514: }
10515: }
10516: }
10517: }
1.102 raeburn 10518: } else {
1.144 raeburn 10519: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10520: $changes{'notify'}{'approval'} = 1;
10521: }
1.218 raeburn 10522: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 10523: $changes{'uniquecode'} = 1;
10524: }
10525: }
10526: if ($context eq 'requestcourses') {
1.242 raeburn 10527: foreach my $type ('textbooks','templates') {
10528: if ($newbook{$type}) {
10529: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 10530: foreach my $item ('subject','title','publisher','author') {
10531: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10532: ($type eq 'template'));
1.242 raeburn 10533: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
10534: if ($env{'form.'.$type.'_addbook_'.$item}) {
10535: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
10536: }
10537: }
10538: if ($type eq 'textbooks') {
10539: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
10540: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 10541: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10542: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10543: } else {
10544: my ($imageurl,$error) =
10545: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
10546: $configuserok,$switchserver,$author_ok);
10547: if ($imageurl) {
10548: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
10549: }
10550: if ($error) {
10551: &Apache::lonnet::logthis($error);
10552: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10553: }
1.242 raeburn 10554: }
10555: }
1.216 raeburn 10556: }
10557: }
1.242 raeburn 10558: if (@{$allpos{$type}} > 0) {
10559: my $idx = 0;
10560: foreach my $item (@{$allpos{$type}}) {
10561: if ($item ne '') {
10562: $confhash{$type}{$item}{'order'} = $idx;
10563: if (ref($domconfig{$action}) eq 'HASH') {
10564: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10565: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
10566: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
10567: $changes{$type}{$item} = 1;
10568: }
1.216 raeburn 10569: }
10570: }
10571: }
1.242 raeburn 10572: $idx ++;
1.216 raeburn 10573: }
10574: }
10575: }
10576: }
1.235 raeburn 10577: if (ref($validationitemsref) eq 'ARRAY') {
10578: foreach my $item (@{$validationitemsref}) {
10579: if ($item eq 'fields') {
10580: my @changed;
10581: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
10582: if (@{$confhash{'validation'}{$item}} > 0) {
10583: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
10584: }
1.266 raeburn 10585: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10586: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10587: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
10588: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
10589: $domconfig{'requestcourses'}{'validation'}{$item});
10590: } else {
10591: @changed = @{$confhash{'validation'}{$item}};
10592: }
1.235 raeburn 10593: } else {
10594: @changed = @{$confhash{'validation'}{$item}};
10595: }
10596: } else {
10597: @changed = @{$confhash{'validation'}{$item}};
10598: }
10599: if (@changed) {
10600: if ($confhash{'validation'}{$item}) {
10601: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
10602: } else {
10603: $changes{'validation'}{$item} = &mt('None');
10604: }
10605: }
10606: } else {
10607: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
10608: if ($item eq 'markup') {
10609: if ($env{'form.requestcourses_validation_'.$item}) {
10610: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10611: }
10612: }
1.266 raeburn 10613: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10614: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10615: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
10616: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10617: }
10618: } else {
10619: if ($confhash{'validation'}{$item} ne '') {
10620: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10621: }
1.235 raeburn 10622: }
10623: } else {
10624: if ($confhash{'validation'}{$item} ne '') {
10625: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10626: }
10627: }
10628: }
10629: }
10630: }
10631: if ($env{'form.validationdc'}) {
10632: my $newval = $env{'form.validationdc'};
1.285 raeburn 10633: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 10634: if (exists($domcoords{$newval})) {
10635: $confhash{'validation'}{'dc'} = $newval;
10636: }
10637: }
10638: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 10639: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10640: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10641: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10642: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
10643: if ($confhash{'validation'}{'dc'} eq '') {
10644: $changes{'validation'}{'dc'} = &mt('None');
10645: } else {
10646: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10647: }
1.235 raeburn 10648: }
1.266 raeburn 10649: } elsif ($confhash{'validation'}{'dc'} ne '') {
10650: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 10651: }
10652: } elsif ($confhash{'validation'}{'dc'} ne '') {
10653: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10654: }
10655: } elsif ($confhash{'validation'}{'dc'} ne '') {
10656: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 10657: }
1.266 raeburn 10658: } else {
10659: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10660: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10661: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10662: $changes{'validation'}{'dc'} = &mt('None');
10663: }
10664: }
1.235 raeburn 10665: }
10666: }
1.102 raeburn 10667: }
10668: } else {
1.86 raeburn 10669: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 10670: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 10671: }
1.72 raeburn 10672: foreach my $item (@usertools) {
10673: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 10674: my $unset;
1.101 raeburn 10675: if ($context eq 'requestcourses') {
1.104 raeburn 10676: $unset = '0';
10677: if ($type eq '_LC_adv') {
10678: $unset = '';
10679: }
1.101 raeburn 10680: if ($confhash{$item}{$type} eq 'autolimit') {
10681: $confhash{$item}{$type} .= '=';
10682: unless ($limithash{$item}{$type} =~ /\D/) {
10683: $confhash{$item}{$type} .= $limithash{$item}{$type};
10684: }
10685: }
1.163 raeburn 10686: } elsif ($context eq 'requestauthor') {
10687: $unset = '0';
10688: if ($type eq '_LC_adv') {
10689: $unset = '';
10690: }
1.72 raeburn 10691: } else {
1.101 raeburn 10692: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
10693: $confhash{$item}{$type} = 1;
10694: } else {
10695: $confhash{$item}{$type} = 0;
10696: }
1.72 raeburn 10697: }
1.86 raeburn 10698: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 10699: if ($action eq 'requestauthor') {
10700: if ($domconfig{$action}{$type} ne $confhash{$type}) {
10701: $changes{$type} = 1;
10702: }
10703: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 10704: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
10705: $changes{$item}{$type} = 1;
10706: }
10707: } else {
10708: if ($context eq 'requestcourses') {
1.104 raeburn 10709: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 10710: $changes{$item}{$type} = 1;
10711: }
10712: } else {
10713: if (!$confhash{$item}{$type}) {
10714: $changes{$item}{$type} = 1;
10715: }
10716: }
10717: }
10718: } else {
10719: if ($context eq 'requestcourses') {
1.104 raeburn 10720: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 10721: $changes{$item}{$type} = 1;
10722: }
1.163 raeburn 10723: } elsif ($context eq 'requestauthor') {
10724: if ($confhash{$type} ne $unset) {
10725: $changes{$type} = 1;
10726: }
1.72 raeburn 10727: } else {
10728: if (!$confhash{$item}{$type}) {
10729: $changes{$item}{$type} = 1;
10730: }
10731: }
10732: }
1.1 raeburn 10733: }
10734: }
1.163 raeburn 10735: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 10736: if (ref($domconfig{'quotas'}) eq 'HASH') {
10737: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
10738: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
10739: if (exists($confhash{'defaultquota'}{$key})) {
10740: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
10741: $changes{'defaultquota'}{$key} = 1;
10742: }
10743: } else {
10744: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 10745: }
10746: }
1.86 raeburn 10747: } else {
10748: foreach my $key (keys(%{$domconfig{'quotas'}})) {
10749: if (exists($confhash{'defaultquota'}{$key})) {
10750: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
10751: $changes{'defaultquota'}{$key} = 1;
10752: }
10753: } else {
10754: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 10755: }
1.1 raeburn 10756: }
10757: }
1.197 raeburn 10758: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
10759: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
10760: if (exists($confhash{'authorquota'}{$key})) {
10761: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
10762: $changes{'authorquota'}{$key} = 1;
10763: }
10764: } else {
10765: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
10766: }
10767: }
10768: }
1.1 raeburn 10769: }
1.86 raeburn 10770: if (ref($confhash{'defaultquota'}) eq 'HASH') {
10771: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
10772: if (ref($domconfig{'quotas'}) eq 'HASH') {
10773: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
10774: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
10775: $changes{'defaultquota'}{$key} = 1;
10776: }
10777: } else {
10778: if (!exists($domconfig{'quotas'}{$key})) {
10779: $changes{'defaultquota'}{$key} = 1;
10780: }
1.72 raeburn 10781: }
10782: } else {
1.86 raeburn 10783: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 10784: }
1.1 raeburn 10785: }
10786: }
1.197 raeburn 10787: if (ref($confhash{'authorquota'}) eq 'HASH') {
10788: foreach my $key (keys(%{$confhash{'authorquota'}})) {
10789: if (ref($domconfig{'quotas'}) eq 'HASH') {
10790: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
10791: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
10792: $changes{'authorquota'}{$key} = 1;
10793: }
10794: } else {
10795: $changes{'authorquota'}{$key} = 1;
10796: }
10797: } else {
10798: $changes{'authorquota'}{$key} = 1;
10799: }
10800: }
10801: }
1.1 raeburn 10802: }
1.72 raeburn 10803:
1.163 raeburn 10804: if ($context eq 'requestauthor') {
10805: $domdefaults{'requestauthor'} = \%confhash;
10806: } else {
10807: foreach my $key (keys(%confhash)) {
1.242 raeburn 10808: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 10809: $domdefaults{$key} = $confhash{$key};
10810: }
1.163 raeburn 10811: }
1.72 raeburn 10812: }
1.163 raeburn 10813:
1.1 raeburn 10814: my %quotahash = (
1.86 raeburn 10815: $action => { %confhash }
1.1 raeburn 10816: );
10817: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
10818: $dom);
10819: if ($putresult eq 'ok') {
10820: if (keys(%changes) > 0) {
1.72 raeburn 10821: my $cachetime = 24*60*60;
10822: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 10823: if (ref($lastactref) eq 'HASH') {
10824: $lastactref->{'domdefaults'} = 1;
10825: }
1.1 raeburn 10826: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 10827: unless (($context eq 'requestcourses') ||
1.163 raeburn 10828: ($context eq 'requestauthor')) {
1.86 raeburn 10829: if (ref($changes{'defaultquota'}) eq 'HASH') {
10830: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
10831: foreach my $type (@{$types},'default') {
10832: if (defined($changes{'defaultquota'}{$type})) {
10833: my $typetitle = $usertypes->{$type};
10834: if ($type eq 'default') {
10835: $typetitle = $othertitle;
10836: }
1.213 raeburn 10837: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 10838: }
10839: }
1.86 raeburn 10840: $resulttext .= '</ul></li>';
1.72 raeburn 10841: }
1.197 raeburn 10842: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 10843: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 10844: foreach my $type (@{$types},'default') {
10845: if (defined($changes{'authorquota'}{$type})) {
10846: my $typetitle = $usertypes->{$type};
10847: if ($type eq 'default') {
10848: $typetitle = $othertitle;
10849: }
1.213 raeburn 10850: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 10851: }
10852: }
10853: $resulttext .= '</ul></li>';
10854: }
1.72 raeburn 10855: }
1.80 raeburn 10856: my %newenv;
1.72 raeburn 10857: foreach my $item (@usertools) {
1.163 raeburn 10858: my (%haschgs,%inconf);
10859: if ($context eq 'requestauthor') {
10860: %haschgs = %changes;
1.210 raeburn 10861: %inconf = %confhash;
1.163 raeburn 10862: } else {
10863: if (ref($changes{$item}) eq 'HASH') {
10864: %haschgs = %{$changes{$item}};
10865: }
10866: if (ref($confhash{$item}) eq 'HASH') {
10867: %inconf = %{$confhash{$item}};
10868: }
10869: }
10870: if (keys(%haschgs) > 0) {
1.80 raeburn 10871: my $newacc =
10872: &Apache::lonnet::usertools_access($env{'user.name'},
10873: $env{'user.domain'},
1.86 raeburn 10874: $item,'reload',$context);
1.210 raeburn 10875: if (($context eq 'requestcourses') ||
1.163 raeburn 10876: ($context eq 'requestauthor')) {
1.108 raeburn 10877: if ($env{'environment.canrequest.'.$item} ne $newacc) {
10878: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 10879: }
10880: } else {
10881: if ($env{'environment.availabletools.'.$item} ne $newacc) {
10882: $newenv{'environment.availabletools.'.$item} = $newacc;
10883: }
1.80 raeburn 10884: }
1.163 raeburn 10885: unless ($context eq 'requestauthor') {
10886: $resulttext .= '<li>'.$titles{$item}.'<ul>';
10887: }
1.72 raeburn 10888: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 10889: if ($haschgs{$type}) {
1.72 raeburn 10890: my $typetitle = $usertypes->{$type};
10891: if ($type eq 'default') {
10892: $typetitle = $othertitle;
10893: } elsif ($type eq '_LC_adv') {
10894: $typetitle = 'LON-CAPA Advanced Users';
10895: }
1.163 raeburn 10896: if ($inconf{$type}) {
1.101 raeburn 10897: if ($context eq 'requestcourses') {
10898: my $cond;
1.163 raeburn 10899: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 10900: if ($1 eq '') {
10901: $cond = &mt('(Automatic processing of any request).');
10902: } else {
10903: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
10904: }
10905: } else {
1.163 raeburn 10906: $cond = $conditions{$inconf{$type}};
1.101 raeburn 10907: }
10908: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 10909: } elsif ($context eq 'requestauthor') {
10910: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
10911: $titles{$inconf{$type}},$typetitle);
10912:
1.101 raeburn 10913: } else {
10914: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
10915: }
1.72 raeburn 10916: } else {
1.104 raeburn 10917: if ($type eq '_LC_adv') {
1.163 raeburn 10918: if ($inconf{$type} eq '0') {
1.104 raeburn 10919: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
10920: } else {
10921: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
10922: }
10923: } else {
10924: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
10925: }
1.72 raeburn 10926: }
10927: }
1.26 raeburn 10928: }
1.163 raeburn 10929: unless ($context eq 'requestauthor') {
10930: $resulttext .= '</ul></li>';
10931: }
1.26 raeburn 10932: }
1.1 raeburn 10933: }
1.163 raeburn 10934: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 10935: if (ref($changes{'notify'}) eq 'HASH') {
10936: if ($changes{'notify'}{'approval'}) {
10937: if (ref($confhash{'notify'}) eq 'HASH') {
10938: if ($confhash{'notify'}{'approval'}) {
10939: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
10940: } else {
1.163 raeburn 10941: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 10942: }
10943: }
10944: }
10945: }
10946: }
1.216 raeburn 10947: if ($action eq 'requestcourses') {
10948: my @offon = ('off','on');
10949: if ($changes{'uniquecode'}) {
1.218 raeburn 10950: if (ref($confhash{'uniquecode'}) eq 'HASH') {
10951: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
10952: $resulttext .= '<li>'.
10953: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
10954: '</li>';
10955: } else {
10956: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
10957: '</li>';
10958: }
1.216 raeburn 10959: }
1.242 raeburn 10960: foreach my $type ('textbooks','templates') {
10961: if (ref($changes{$type}) eq 'HASH') {
10962: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
10963: foreach my $key (sort(keys(%{$changes{$type}}))) {
10964: my %coursehash = &Apache::lonnet::coursedescription($key);
10965: my $coursetitle = $coursehash{'description'};
10966: my $position = $confhash{$type}{$key}{'order'} + 1;
10967: $resulttext .= '<li>';
1.243 raeburn 10968: foreach my $item ('subject','title','publisher','author') {
10969: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10970: ($type eq 'templates'));
1.242 raeburn 10971: my $name = $item.':';
10972: $name =~ s/^(\w)/\U$1/;
10973: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
10974: }
10975: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
10976: if ($type eq 'textbooks') {
10977: if ($confhash{$type}{$key}{'image'}) {
10978: $resulttext .= ' '.&mt('Image: [_1]',
10979: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
10980: ' alt="Textbook cover" />').'<br />';
10981: }
10982: }
10983: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 10984: }
1.242 raeburn 10985: $resulttext .= '</ul></li>';
1.216 raeburn 10986: }
10987: }
1.235 raeburn 10988: if (ref($changes{'validation'}) eq 'HASH') {
10989: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
10990: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
10991: foreach my $item (@{$validationitemsref}) {
10992: if (exists($changes{'validation'}{$item})) {
10993: if ($item eq 'markup') {
10994: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
10995: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
10996: } else {
10997: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
10998: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
10999: }
11000: }
11001: }
11002: if (exists($changes{'validation'}{'dc'})) {
11003: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
11004: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
11005: }
11006: }
11007: }
1.216 raeburn 11008: }
1.1 raeburn 11009: $resulttext .= '</ul>';
1.80 raeburn 11010: if (keys(%newenv)) {
11011: &Apache::lonnet::appenv(\%newenv);
11012: }
1.1 raeburn 11013: } else {
1.86 raeburn 11014: if ($context eq 'requestcourses') {
11015: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 11016: } elsif ($context eq 'requestauthor') {
11017: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 11018: } else {
1.90 weissno 11019: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 11020: }
1.1 raeburn 11021: }
11022: } else {
1.11 albertel 11023: $resulttext = '<span class="LC_error">'.
11024: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11025: }
1.216 raeburn 11026: if ($errors) {
11027: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
11028: '<ul>'.$errors.'</ul></p>';
11029: }
1.3 raeburn 11030: return $resulttext;
1.1 raeburn 11031: }
11032:
1.216 raeburn 11033: sub process_textbook_image {
1.242 raeburn 11034: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 11035: my $filename = $env{'form.'.$caller.'.filename'};
11036: my ($error,$url);
11037: my ($width,$height) = (50,50);
11038: if ($configuserok eq 'ok') {
11039: if ($switchserver) {
11040: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
11041: $switchserver);
11042: } elsif ($author_ok eq 'ok') {
11043: my ($result,$imageurl) =
11044: &publishlogo($r,'upload',$caller,$dom,$confname,
1.312 raeburn 11045: "$type/$cdom/$cnum/cover",$width,$height);
1.216 raeburn 11046: if ($result eq 'ok') {
11047: $url = $imageurl;
11048: } else {
11049: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
11050: }
11051: } else {
11052: $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);
11053: }
11054: } else {
11055: $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);
11056: }
11057: return ($url,$error);
11058: }
11059:
1.267 raeburn 11060: sub modify_ltitools {
11061: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
11062: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 11063: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 11064: my $confname = $dom.'-domainconfig';
11065: my $servadm = $r->dir_config('lonAdmEMail');
11066: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11067: my (%posslti,%possfield);
11068: my @courseroles = ('cc','in','ta','ep','st');
11069: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
11070: map { $posslti{$_} = 1; } @ltiroles;
11071: my @allfields = ('fullname','firstname','lastname','email','user','roles');
11072: map { $possfield{$_} = 1; } @allfields;
11073: my %lt = <itools_names();
11074: if ($env{'form.ltitools_add'}) {
11075: my $title = $env{'form.ltitools_add_title'};
11076: $title =~ s/(`)/'/g;
11077: ($newid,my $error) = &get_ltitools_id($dom,$title);
11078: if ($newid) {
11079: my $position = $env{'form.ltitools_add_pos'};
11080: $position =~ s/\D+//g;
11081: if ($position ne '') {
11082: $allpos[$position] = $newid;
11083: }
11084: $changes{$newid} = 1;
1.322 raeburn 11085: foreach my $item ('title','url','key','secret','lifetime') {
1.267 raeburn 11086: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1.322 raeburn 11087: if ($item eq 'lifetime') {
11088: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
11089: }
1.267 raeburn 11090: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 11091: if (($item eq 'key') || ($item eq 'secret')) {
11092: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
11093: } else {
11094: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
11095: }
1.267 raeburn 11096: }
11097: }
11098: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
11099: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
11100: }
11101: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
11102: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
11103: }
1.323 raeburn 11104: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
11105: $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
11106: } else {
11107: $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
11108: }
1.296 raeburn 11109: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 11110: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
11111: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 11112: if (($item eq 'width') || ($item eq 'height')) {
11113: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
11114: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
11115: }
11116: } else {
11117: if ($env{'form.ltitools_add_'.$item} ne '') {
11118: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
11119: }
1.267 raeburn 11120: }
11121: }
11122: if ($env{'form.ltitools_add_target'} eq 'window') {
11123: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 11124: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
11125: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 11126: } else {
11127: $confhash{$newid}{'display'}{'target'} = 'iframe';
11128: }
11129: foreach my $item ('passback','roster') {
1.319 raeburn 11130: if ($env{'form.ltitools_'.$item.'_add'}) {
1.267 raeburn 11131: $confhash{$newid}{$item} = 1;
1.319 raeburn 11132: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
11133: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
11134: $lifetime =~ s/^\s+|\s+$//g;
11135: if ($lifetime =~ /^\d+\.?\d*$/) {
11136: $confhash{$newid}{$item.'valid'} = $lifetime;
11137: }
11138: }
1.267 raeburn 11139: }
11140: }
11141: if ($env{'form.ltitools_add_image.filename'} ne '') {
11142: my ($imageurl,$error) =
1.307 raeburn 11143: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267 raeburn 11144: $configuserok,$switchserver,$author_ok);
11145: if ($imageurl) {
11146: $confhash{$newid}{'image'} = $imageurl;
11147: }
11148: if ($error) {
11149: &Apache::lonnet::logthis($error);
11150: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11151: }
11152: }
11153: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
11154: foreach my $field (@fields) {
11155: if ($possfield{$field}) {
11156: if ($field eq 'roles') {
11157: foreach my $role (@courseroles) {
11158: my $choice = $env{'form.ltitools_add_roles_'.$role};
11159: if (($choice ne '') && ($posslti{$choice})) {
11160: $confhash{$newid}{'roles'}{$role} = $choice;
11161: if ($role eq 'cc') {
11162: $confhash{$newid}{'roles'}{'co'} = $choice;
11163: }
11164: }
11165: }
11166: } else {
11167: $confhash{$newid}{'fields'}{$field} = 1;
11168: }
11169: }
11170: }
1.324 raeburn 11171: if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
11172: if ($confhash{$newid}{'fields'}{'user'}) {
11173: if ($env{'form.ltitools_userincdom_add'}) {
11174: $confhash{$newid}{'incdom'} = 1;
11175: }
11176: }
11177: }
1.273 raeburn 11178: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
11179: foreach my $item (@courseconfig) {
11180: $confhash{$newid}{'crsconf'}{$item} = 1;
11181: }
1.267 raeburn 11182: if ($env{'form.ltitools_add_custom'}) {
11183: my $name = $env{'form.ltitools_add_custom_name'};
11184: my $value = $env{'form.ltitools_add_custom_value'};
11185: $value =~ s/(`)/'/g;
11186: $name =~ s/(`)/'/g;
11187: $confhash{$newid}{'custom'}{$name} = $value;
11188: }
11189: } else {
11190: my $error = &mt('Failed to acquire unique ID for new external tool');
11191: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11192: }
11193: }
11194: if (ref($domconfig{$action}) eq 'HASH') {
11195: my %deletions;
11196: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
11197: if (@todelete) {
11198: map { $deletions{$_} = 1; } @todelete;
11199: }
11200: my %customadds;
11201: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
11202: if (@newcustom) {
11203: map { $customadds{$_} = 1; } @newcustom;
11204: }
11205: my %imgdeletions;
11206: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
11207: if (@todeleteimages) {
11208: map { $imgdeletions{$_} = 1; } @todeleteimages;
11209: }
11210: my $maxnum = $env{'form.ltitools_maxnum'};
11211: for (my $i=0; $i<=$maxnum; $i++) {
11212: my $itemid = $env{'form.ltitools_id_'.$i};
1.308 raeburn 11213: $itemid =~ s/\D+//g;
1.267 raeburn 11214: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11215: if ($deletions{$itemid}) {
11216: if ($domconfig{$action}{$itemid}{'image'}) {
11217: #FIXME need to obsolete item in RES space
11218: }
11219: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
11220: next;
11221: } else {
11222: my $newpos = $env{'form.ltitools_'.$itemid};
11223: $newpos =~ s/\D+//g;
1.322 raeburn 11224: foreach my $item ('title','url','lifetime') {
1.267 raeburn 11225: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
11226: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
11227: $changes{$itemid} = 1;
11228: }
11229: }
1.297 raeburn 11230: foreach my $item ('key','secret') {
11231: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
11232: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
11233: $changes{$itemid} = 1;
11234: }
11235: }
1.267 raeburn 11236: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
11237: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
11238: }
11239: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
11240: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
11241: }
1.323 raeburn 11242: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
11243: $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
11244: } else {
11245: $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
11246: }
11247: if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
11248: if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
11249: $changes{$itemid} = 1;
11250: }
11251: } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
11252: $changes{$itemid} = 1;
11253: }
1.267 raeburn 11254: foreach my $size ('width','height') {
11255: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
11256: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
11257: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
11258: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
11259: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11260: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
11261: $changes{$itemid} = 1;
11262: }
11263: } else {
11264: $changes{$itemid} = 1;
11265: }
1.296 raeburn 11266: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11267: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
11268: $changes{$itemid} = 1;
11269: }
11270: }
11271: }
11272: foreach my $item ('linktext','explanation') {
11273: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
11274: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
11275: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
11276: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
11277: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11278: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
11279: $changes{$itemid} = 1;
11280: }
11281: } else {
11282: $changes{$itemid} = 1;
11283: }
11284: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11285: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
11286: $changes{$itemid} = 1;
11287: }
1.267 raeburn 11288: }
11289: }
11290: if ($env{'form.ltitools_target_'.$i} eq 'window') {
11291: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 11292: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
11293: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 11294: } else {
11295: $confhash{$itemid}{'display'}{'target'} = 'iframe';
11296: }
11297: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11298: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
11299: $changes{$itemid} = 1;
11300: }
11301: } else {
11302: $changes{$itemid} = 1;
11303: }
11304: foreach my $extra ('passback','roster') {
11305: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
11306: $confhash{$itemid}{$extra} = 1;
1.319 raeburn 11307: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
1.338 raeburn 11308: my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
1.319 raeburn 11309: $lifetime =~ s/^\s+|\s+$//g;
11310: if ($lifetime =~ /^\d+\.?\d*$/) {
11311: $confhash{$itemid}{$extra.'valid'} = $lifetime;
11312: }
11313: }
1.267 raeburn 11314: }
11315: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
11316: $changes{$itemid} = 1;
11317: }
1.319 raeburn 11318: if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
11319: $changes{$itemid} = 1;
11320: }
1.267 raeburn 11321: }
1.273 raeburn 11322: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318 raeburn 11323: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 11324: if (grep(/^\Q$item\E$/,@courseconfig)) {
11325: $confhash{$itemid}{'crsconf'}{$item} = 1;
11326: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
11327: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
11328: $changes{$itemid} = 1;
11329: }
11330: } else {
11331: $changes{$itemid} = 1;
11332: }
11333: }
11334: }
1.267 raeburn 11335: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
11336: foreach my $field (@fields) {
11337: if ($possfield{$field}) {
11338: if ($field eq 'roles') {
11339: foreach my $role (@courseroles) {
11340: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
11341: if (($choice ne '') && ($posslti{$choice})) {
11342: $confhash{$itemid}{'roles'}{$role} = $choice;
11343: if ($role eq 'cc') {
11344: $confhash{$itemid}{'roles'}{'co'} = $choice;
11345: }
11346: }
11347: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
11348: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
11349: $changes{$itemid} = 1;
11350: }
11351: } elsif ($confhash{$itemid}{'roles'}{$role}) {
11352: $changes{$itemid} = 1;
11353: }
11354: }
11355: } else {
11356: $confhash{$itemid}{'fields'}{$field} = 1;
11357: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
11358: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
11359: $changes{$itemid} = 1;
11360: }
11361: } else {
11362: $changes{$itemid} = 1;
11363: }
11364: }
11365: }
11366: }
1.324 raeburn 11367: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
11368: if ($confhash{$itemid}{'fields'}{'user'}) {
11369: if ($env{'form.ltitools_userincdom_'.$i}) {
11370: $confhash{$itemid}{'incdom'} = 1;
11371: }
11372: if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
11373: $changes{$itemid} = 1;
11374: }
11375: }
11376: }
1.267 raeburn 11377: $allpos[$newpos] = $itemid;
11378: }
11379: if ($imgdeletions{$itemid}) {
11380: $changes{$itemid} = 1;
11381: #FIXME need to obsolete item in RES space
11382: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
11383: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
11384: $itemid,$configuserok,$switchserver,
11385: $author_ok);
11386: if ($imgurl) {
11387: $confhash{$itemid}{'image'} = $imgurl;
11388: $changes{$itemid} = 1;
11389: }
11390: if ($error) {
11391: &Apache::lonnet::logthis($error);
11392: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11393: }
11394: } elsif ($domconfig{$action}{$itemid}{'image'}) {
11395: $confhash{$itemid}{'image'} =
11396: $domconfig{$action}{$itemid}{'image'};
11397: }
11398: if ($customadds{$i}) {
11399: my $name = $env{'form.ltitools_custom_name_'.$i};
11400: $name =~ s/(`)/'/g;
11401: $name =~ s/^\s+//;
11402: $name =~ s/\s+$//;
11403: my $value = $env{'form.ltitools_custom_value_'.$i};
11404: $value =~ s/(`)/'/g;
11405: $value =~ s/^\s+//;
11406: $value =~ s/\s+$//;
11407: if ($name ne '') {
11408: $confhash{$itemid}{'custom'}{$name} = $value;
11409: $changes{$itemid} = 1;
11410: }
11411: }
11412: my %customdels;
11413: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
11414: if (@customdeletions) {
11415: $changes{$itemid} = 1;
11416: }
11417: map { $customdels{$_} = 1; } @customdeletions;
11418: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
11419: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
11420: unless ($customdels{$key}) {
11421: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
11422: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
11423: }
11424: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
11425: $changes{$itemid} = 1;
11426: }
11427: }
11428: }
11429: }
11430: unless ($changes{$itemid}) {
11431: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
11432: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
11433: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
11434: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
11435: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
11436: $changes{$itemid} = 1;
11437: last;
11438: }
11439: }
11440: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
11441: $changes{$itemid} = 1;
11442: }
11443: }
11444: last if ($changes{$itemid});
11445: }
11446: }
11447: }
11448: }
11449: }
11450: if (@allpos > 0) {
11451: my $idx = 0;
11452: foreach my $itemid (@allpos) {
11453: if ($itemid ne '') {
11454: $confhash{$itemid}{'order'} = $idx;
11455: if (ref($domconfig{$action}) eq 'HASH') {
11456: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11457: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
11458: $changes{$itemid} = 1;
11459: }
11460: }
11461: }
11462: $idx ++;
11463: }
11464: }
11465: }
11466: my %ltitoolshash = (
11467: $action => { %confhash }
11468: );
11469: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
11470: $dom);
11471: if ($putresult eq 'ok') {
1.297 raeburn 11472: my %ltienchash = (
11473: $action => { %encconfig }
11474: );
11475: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
1.267 raeburn 11476: if (keys(%changes) > 0) {
11477: my $cachetime = 24*60*60;
1.297 raeburn 11478: my %ltiall = %confhash;
11479: foreach my $id (keys(%ltiall)) {
11480: if (ref($encconfig{$id}) eq 'HASH') {
11481: foreach my $item ('key','secret') {
11482: $ltiall{$id}{$item} = $encconfig{$id}{$item};
11483: }
11484: }
11485: }
11486: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 11487: if (ref($lastactref) eq 'HASH') {
11488: $lastactref->{'ltitools'} = 1;
11489: }
11490: $resulttext = &mt('Changes made:').'<ul>';
11491: my %bynum;
11492: foreach my $itemid (sort(keys(%changes))) {
11493: my $position = $confhash{$itemid}{'order'};
11494: $bynum{$position} = $itemid;
11495: }
11496: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
11497: my $itemid = $bynum{$pos};
11498: if (ref($confhash{$itemid}) ne 'HASH') {
11499: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
11500: } else {
11501: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
11502: if ($confhash{$itemid}{'image'}) {
11503: $resulttext .= ' '.
11504: '<img src="'.$confhash{$itemid}{'image'}.'"'.
11505: ' alt="'.&mt('Tool Provider icon').'" />';
11506: }
11507: $resulttext .= '</li><ul>';
11508: my $position = $pos + 1;
11509: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.323 raeburn 11510: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1.267 raeburn 11511: if ($confhash{$itemid}{$item} ne '') {
11512: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
11513: }
11514: }
1.297 raeburn 11515: if ($encconfig{$itemid}{'key'} ne '') {
11516: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
11517: }
11518: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 11519: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 11520: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 11521: $resulttext .= ('*'x$num).'</li>';
11522: }
1.273 raeburn 11523: $resulttext .= '<li>'.&mt('Configurable in course:');
1.318 raeburn 11524: my @possconfig = ('label','title','target','linktext','explanation','append');
1.273 raeburn 11525: my $numconfig = 0;
11526: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
11527: foreach my $item (@possconfig) {
11528: if ($confhash{$itemid}{'crsconf'}{$item}) {
11529: $numconfig ++;
1.296 raeburn 11530: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 11531: }
11532: }
11533: }
11534: if (!$numconfig) {
11535: $resulttext .= &mt('None');
11536: }
11537: $resulttext .= '</li>';
1.267 raeburn 11538: foreach my $item ('passback','roster') {
11539: $resulttext .= '<li>'.$lt{$item}.' ';
11540: if ($confhash{$itemid}{$item}) {
11541: $resulttext .= &mt('Yes');
1.319 raeburn 11542: if ($confhash{$itemid}{$item.'valid'}) {
11543: if ($item eq 'passback') {
11544: $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
11545: $confhash{$itemid}{$item.'valid'});
11546: } else {
11547: $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
11548: $confhash{$itemid}{$item.'valid'});
11549: }
11550: }
1.267 raeburn 11551: } else {
11552: $resulttext .= &mt('No');
11553: }
11554: $resulttext .= '</li>';
11555: }
11556: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
11557: my $displaylist;
11558: if ($confhash{$itemid}{'display'}{'target'}) {
11559: $displaylist = &mt('Display target').': '.
11560: $confhash{$itemid}{'display'}{'target'}.',';
11561: }
11562: foreach my $size ('width','height') {
11563: if ($confhash{$itemid}{'display'}{$size}) {
11564: $displaylist .= (' 'x2).$lt{$size}.': '.
11565: $confhash{$itemid}{'display'}{$size}.',';
11566: }
11567: }
11568: if ($displaylist) {
11569: $displaylist =~ s/,$//;
11570: $resulttext .= '<li>'.$displaylist.'</li>';
11571: }
1.296 raeburn 11572: foreach my $item ('linktext','explanation') {
11573: if ($confhash{$itemid}{'display'}{$item}) {
11574: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
11575: }
11576: }
11577: }
1.267 raeburn 11578: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
11579: my $fieldlist;
11580: foreach my $field (@allfields) {
11581: if ($confhash{$itemid}{'fields'}{$field}) {
11582: $fieldlist .= (' 'x2).$lt{$field}.',';
11583: }
11584: }
11585: if ($fieldlist) {
11586: $fieldlist =~ s/,$//;
1.324 raeburn 11587: if ($confhash{$itemid}{'fields'}{'user'}) {
11588: if ($confhash{$itemid}{'incdom'}) {
11589: $fieldlist .= ' ('.&mt('username:domain').')';
11590: } else {
11591: $fieldlist .= ' ('.&mt('username').')';
11592: }
11593: }
1.267 raeburn 11594: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
11595: }
11596: }
11597: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
11598: my $rolemaps;
11599: foreach my $role (@courseroles) {
11600: if ($confhash{$itemid}{'roles'}{$role}) {
11601: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
11602: $confhash{$itemid}{'roles'}{$role}.',';
11603: }
11604: }
11605: if ($rolemaps) {
11606: $rolemaps =~ s/,$//;
11607: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
11608: }
11609: }
11610: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
11611: my $customlist;
11612: if (keys(%{$confhash{$itemid}{'custom'}})) {
11613: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
11614: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
11615: }
11616: }
11617: if ($customlist) {
1.317 raeburn 11618: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267 raeburn 11619: }
11620: }
11621: $resulttext .= '</ul></li>';
11622: }
11623: }
11624: $resulttext .= '</ul>';
11625: } else {
11626: $resulttext = &mt('No changes made.');
11627: }
11628: } else {
11629: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
11630: }
11631: if ($errors) {
11632: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11633: $errors.'</ul>';
11634: }
11635: return $resulttext;
11636: }
11637:
11638: sub process_ltitools_image {
11639: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
11640: my $filename = $env{'form.'.$caller.'.filename'};
11641: my ($error,$url);
11642: my ($width,$height) = (21,21);
11643: if ($configuserok eq 'ok') {
11644: if ($switchserver) {
11645: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
11646: $switchserver);
11647: } elsif ($author_ok eq 'ok') {
11648: my ($result,$imageurl,$madethumb) =
11649: &publishlogo($r,'upload',$caller,$dom,$confname,
11650: "ltitools/$itemid/icon",$width,$height);
11651: if ($result eq 'ok') {
11652: if ($madethumb) {
11653: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
11654: my $imagethumb = "$path/tn-".$imagefile;
11655: $url = $imagethumb;
11656: } else {
11657: $url = $imageurl;
11658: }
11659: } else {
11660: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
11661: }
11662: } else {
11663: $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);
11664: }
11665: } else {
11666: $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);
11667: }
11668: return ($url,$error);
11669: }
11670:
11671: sub get_ltitools_id {
11672: my ($cdom,$title) = @_;
11673: # get lock on ltitools db
11674: my $lockhash = {
11675: lock => $env{'user.name'}.
11676: ':'.$env{'user.domain'},
11677: };
11678: my $tries = 0;
11679: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
11680: my ($id,$error);
11681:
11682: while (($gotlock ne 'ok') && ($tries<10)) {
11683: $tries ++;
11684: sleep (0.1);
11685: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
11686: }
11687: if ($gotlock eq 'ok') {
11688: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
11689: if ($currids{'lock'}) {
11690: delete($currids{'lock'});
11691: if (keys(%currids)) {
11692: my @curr = sort { $a <=> $b } keys(%currids);
11693: if ($curr[-1] =~ /^\d+$/) {
11694: $id = 1 + $curr[-1];
11695: }
11696: } else {
11697: $id = 1;
11698: }
11699: if ($id) {
11700: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
11701: $error = 'nostore';
11702: }
11703: } else {
11704: $error = 'nonumber';
11705: }
11706: }
11707: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
11708: } else {
11709: $error = 'nolock';
11710: }
11711: return ($id,$error);
11712: }
11713:
1.320 raeburn 11714: sub modify_lti {
11715: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
11716: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11717: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
11718: my (%posslti,%posslticrs,%posscrstype);
11719: my @courseroles = ('cc','in','ta','ep','st');
11720: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
11721: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
11722: my @coursetypes = ('official','unofficial','community','textbook','placement');
11723: my %coursetypetitles = &Apache::lonlocal::texthash (
11724: official => 'Official',
11725: unofficial => 'Unofficial',
11726: community => 'Community',
11727: textbook => 'Textbook',
11728: placement => 'Placement Test',
11729: );
1.325 raeburn 11730: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 11731: my %lt = <i_names();
11732: map { $posslti{$_} = 1; } @ltiroles;
11733: map { $posslticrs{$_} = 1; } @lticourseroles;
11734: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 11735:
1.326 raeburn 11736: my %menutitles = <imenu_titles();
11737:
1.320 raeburn 11738: my (@items,%deletions,%itemids);
11739: if ($env{'form.lti_add'}) {
11740: my $consumer = $env{'form.lti_consumer_add'};
11741: $consumer =~ s/(`)/'/g;
11742: ($newid,my $error) = &get_lti_id($dom,$consumer);
11743: if ($newid) {
11744: $itemids{'add'} = $newid;
11745: push(@items,'add');
11746: $changes{$newid} = 1;
11747: } else {
11748: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
11749: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11750: }
11751: }
11752: if (ref($domconfig{$action}) eq 'HASH') {
11753: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
11754: if (@todelete) {
11755: map { $deletions{$_} = 1; } @todelete;
11756: }
11757: my $maxnum = $env{'form.lti_maxnum'};
11758: for (my $i=0; $i<=$maxnum; $i++) {
11759: my $itemid = $env{'form.lti_id_'.$i};
11760: $itemid =~ s/\D+//g;
11761: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11762: if ($deletions{$itemid}) {
11763: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
11764: } else {
11765: push(@items,$i);
11766: $itemids{$i} = $itemid;
11767: }
11768: }
11769: }
11770: }
11771: foreach my $idx (@items) {
11772: my $itemid = $itemids{$idx};
11773: next unless ($itemid);
11774: my $position = $env{'form.lti_pos_'.$idx};
11775: $position =~ s/\D+//g;
11776: if ($position ne '') {
11777: $allpos[$position] = $itemid;
11778: }
11779: foreach my $item ('consumer','key','secret','lifetime') {
11780: my $formitem = 'form.lti_'.$item.'_'.$idx;
11781: $env{$formitem} =~ s/(`)/'/g;
11782: if ($item eq 'lifetime') {
11783: $env{$formitem} =~ s/[^\d.]//g;
11784: }
11785: if ($env{$formitem} ne '') {
11786: if (($item eq 'key') || ($item eq 'secret')) {
11787: $encconfig{$itemid}{$item} = $env{$formitem};
11788: } else {
11789: $confhash{$itemid}{$item} = $env{$formitem};
11790: unless (($idx eq 'add') || ($changes{$itemid})) {
11791: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
11792: $changes{$itemid} = 1;
11793: }
11794: }
11795: }
11796: }
11797: }
11798: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
11799: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
11800: }
11801: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
11802: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
11803: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
11804: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
11805: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
11806: my $mapuser = $env{'form.lti_customuser_'.$idx};
11807: $mapuser =~ s/(`)/'/g;
11808: $mapuser =~ s/^\s+|\s+$//g;
11809: $confhash{$itemid}{'mapuser'} = $mapuser;
11810: }
11811: foreach my $ltirole (@lticourseroles) {
11812: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
11813: if (grep(/^\Q$possrole\E$/,@courseroles)) {
11814: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
11815: }
11816: }
11817: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
11818: my @makeuser;
11819: foreach my $ltirole (sort(@possmakeuser)) {
11820: if ($posslti{$ltirole}) {
11821: push(@makeuser,$ltirole);
11822: }
11823: }
11824: $confhash{$itemid}{'makeuser'} = \@makeuser;
1.325 raeburn 11825: if (@makeuser) {
11826: my $lcauth = $env{'form.lti_lcauth_'.$idx};
11827: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
11828: $confhash{$itemid}{'lcauth'} = $lcauth;
11829: if ($lcauth ne 'internal') {
11830: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
11831: $lcauthparm =~ s/^(\s+|\s+)$//g;
11832: $lcauthparm =~ s/`//g;
11833: if ($lcauthparm ne '') {
11834: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
11835: }
11836: }
11837: } else {
11838: $confhash{$itemid}{'lcauth'} = 'lti';
11839: }
11840: }
11841: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
11842: if (@possinstdata) {
11843: foreach my $field (@possinstdata) {
11844: if (exists($fieldtitles{$field})) {
11845: push(@{$confhash{$itemid}{'instdata'}});
11846: }
11847: }
11848: }
1.320 raeburn 11849: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
11850: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
11851: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
11852: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
11853: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
11854: $mapcrs =~ s/(`)/'/g;
11855: $mapcrs =~ s/^\s+|\s+$//g;
11856: $confhash{$itemid}{'mapcrs'} = $mapcrs;
11857: }
11858: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
11859: my @crstypes;
11860: foreach my $type (sort(@posstypes)) {
11861: if ($posscrstype{$type}) {
11862: push(@crstypes,$type);
11863: }
11864: }
11865: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
11866: if ($env{'form.lti_makecrs_'.$idx}) {
11867: $confhash{$itemid}{'makecrs'} = 1;
11868: }
11869: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
11870: my @selfenroll;
11871: foreach my $type (sort(@possenroll)) {
11872: if ($posslticrs{$type}) {
11873: push(@selfenroll,$type);
11874: }
11875: }
11876: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
11877: if ($env{'form.lti_crssec_'.$idx}) {
11878: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
11879: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
11880: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
11881: my $section = $env{'form.lti_customsection_'.$idx};
11882: $section =~ s/(`)/'/g;
11883: $section =~ s/^\s+|\s+$//g;
11884: if ($section ne '') {
11885: $confhash{$itemid}{'section'} = $section;
11886: }
11887: }
11888: }
1.326 raeburn 11889: foreach my $field ('passback','roster','topmenu','inlinemenu') {
1.321 raeburn 11890: if ($env{'form.lti_'.$field.'_'.$idx}) {
1.320 raeburn 11891: $confhash{$itemid}{$field} = 1;
11892: }
11893: }
1.337 raeburn 11894: if ($env{'form.lti_passback_'.$idx}) {
11895: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
11896: $confhash{$itemid}{'passbackformat'} = '1.0';
11897: } else {
11898: $confhash{$itemid}{'passbackformat'} = '1.1';
11899: }
11900: }
1.326 raeburn 11901: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
11902: $confhash{$itemid}{lcmenu} = [];
11903: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
11904: foreach my $field (@possmenu) {
11905: if (exists($menutitles{$field})) {
11906: if ($field eq 'grades') {
11907: next unless ($env{'form.lti_inlinemenu_'.$idx});
11908: }
11909: push(@{$confhash{$itemid}{lcmenu}},$field);
11910: }
11911: }
11912: }
1.320 raeburn 11913: unless (($idx eq 'add') || ($changes{$itemid})) {
1.326 raeburn 11914: foreach my $field ('mapuser','mapcrs','makecrs','section','passback','roster','lcauth','lcauthparm','topmenu','inlinemenu') {
1.320 raeburn 11915: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
11916: $changes{$itemid} = 1;
11917: }
11918: }
1.337 raeburn 11919: unless ($changes{$itemid}) {
11920: if ($domconfig{$action}{$itemid}{'passback'} eq $confhash{$itemid}{'passback'}) {
11921: if ($domconfig{$action}{$itemid}{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
11922: $changes{$itemid} = 1;
11923: }
11924: }
11925: }
1.326 raeburn 11926: foreach my $field ('makeuser','mapcrstype','selfenroll','instdata','lcmenu') {
1.320 raeburn 11927: unless ($changes{$itemid}) {
11928: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
11929: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
11930: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
11931: $confhash{$itemid}{$field});
11932: if (@diffs) {
11933: $changes{$itemid} = 1;
11934: }
11935: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
11936: $changes{$itemid} = 1;
11937: }
11938: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
11939: if (@{$confhash{$itemid}{$field}} > 0) {
11940: $changes{$itemid} = 1;
11941: }
11942: }
11943: }
11944: }
11945: unless ($changes{$itemid}) {
11946: if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
11947: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
11948: foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
11949: if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne
11950: $confhash{$itemid}{'maproles'}{$ltirole}) {
11951: $changes{$itemid} = 1;
11952: last;
11953: }
11954: }
11955: unless ($changes{$itemid}) {
11956: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
11957: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
11958: $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
11959: $changes{$itemid} = 1;
11960: last;
11961: }
11962: }
11963: }
11964: } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
11965: $changes{$itemid} = 1;
11966: }
11967: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
11968: unless ($changes{$itemid}) {
11969: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
11970: $changes{$itemid} = 1;
11971: }
11972: }
11973: }
11974: }
11975: }
11976: }
11977: if (@allpos > 0) {
11978: my $idx = 0;
11979: foreach my $itemid (@allpos) {
11980: if ($itemid ne '') {
11981: $confhash{$itemid}{'order'} = $idx;
11982: if (ref($domconfig{$action}) eq 'HASH') {
11983: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11984: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
11985: $changes{$itemid} = 1;
11986: }
11987: }
11988: }
11989: $idx ++;
11990: }
11991: }
11992: }
11993: my %ltihash = (
11994: $action => { %confhash }
11995: );
11996: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,
11997: $dom);
11998: if ($putresult eq 'ok') {
11999: my %ltienchash = (
12000: $action => { %encconfig }
12001: );
12002: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
12003: if (keys(%changes) > 0) {
12004: my $cachetime = 24*60*60;
12005: my %ltiall = %confhash;
12006: foreach my $id (keys(%ltiall)) {
12007: if (ref($encconfig{$id}) eq 'HASH') {
12008: foreach my $item ('key','secret') {
12009: $ltiall{$id}{$item} = $encconfig{$id}{$item};
12010: }
12011: }
12012: }
12013: &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
12014: if (ref($lastactref) eq 'HASH') {
12015: $lastactref->{'lti'} = 1;
12016: }
12017: $resulttext = &mt('Changes made:').'<ul>';
12018: my %bynum;
12019: foreach my $itemid (sort(keys(%changes))) {
12020: my $position = $confhash{$itemid}{'order'};
12021: $bynum{$position} = $itemid;
12022: }
12023: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
12024: my $itemid = $bynum{$pos};
12025: if (ref($confhash{$itemid}) ne 'HASH') {
12026: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
12027: } else {
12028: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b></li><ul>';
12029: my $position = $pos + 1;
12030: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
12031: foreach my $item ('version','lifetime') {
12032: if ($confhash{$itemid}{$item} ne '') {
12033: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
12034: }
12035: }
12036: if ($encconfig{$itemid}{'key'} ne '') {
12037: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
12038: }
12039: if ($encconfig{$itemid}{'secret'} ne '') {
12040: $resulttext .= '<li>'.$lt{'secret'}.': ';
12041: my $num = length($encconfig{$itemid}{'secret'});
12042: $resulttext .= ('*'x$num).'</li>';
12043: }
12044: if ($confhash{$itemid}{'mapuser'}) {
12045: my $shownmapuser;
12046: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
12047: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
12048: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
12049: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
12050: } else {
12051: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
12052: }
12053: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
12054: }
12055: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
12056: my $rolemaps;
12057: foreach my $role (@ltiroles) {
12058: if ($confhash{$itemid}{'maproles'}{$role}) {
12059: $rolemaps .= (' 'x2).$role.'='.
12060: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
12061: 'Course').',';
12062: }
12063: }
12064: if ($rolemaps) {
12065: $rolemaps =~ s/,$//;
12066: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
12067: }
12068: }
12069: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
12070: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
12071: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
1.325 raeburn 12072: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
12073: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
12074: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
12075: } else {
12076: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
12077: $confhash{$itemid}{'lcauth'});
12078: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
12079: $resulttext .= '; '.&mt('a randomly generated password will be created');
12080: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
12081: if ($confhash{$itemid}{'lcauthparm'} ne '') {
12082: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
12083: }
12084: } else {
12085: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
12086: }
12087: }
12088: $resulttext .= '</li>';
1.320 raeburn 12089: } else {
12090: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
12091: }
12092: }
1.325 raeburn 12093: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
12094: if (@{$confhash{$itemid}{'instdata'}} > 0) {
12095: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
12096: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
12097: } else {
12098: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
12099: }
12100: }
1.320 raeburn 12101: if ($confhash{$itemid}{'mapcrs'}) {
12102: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
12103: }
12104: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
12105: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
12106: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
12107: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
12108: '</li>';
12109: } else {
12110: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
12111: }
12112: }
12113: if ($confhash{$itemid}{'makecrs'}) {
12114: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
12115: } else {
12116: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
12117: }
12118: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
12119: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
12120: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
12121: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
12122: '</li>';
12123: } else {
12124: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
12125: }
12126: }
12127: if ($confhash{$itemid}{'section'}) {
12128: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
12129: $resulttext .= '<li>'.&mt('User section from standard field:').
12130: ' (course_section_sourcedid)'.'</li>';
12131: } else {
12132: $resulttext .= '<li>'.&mt('User section from:').' '.
12133: $confhash{$itemid}{'section'}.'</li>';
12134: }
12135: } else {
12136: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
12137: }
1.326 raeburn 12138: foreach my $item ('passback','roster','topmenu','inlinemenu') {
12139: $resulttext .= '<li>'.$lt{$item}.': ';
1.320 raeburn 12140: if ($confhash{$itemid}{$item}) {
12141: $resulttext .= &mt('Yes');
1.337 raeburn 12142: if ($item eq 'passback') {
12143: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
12144: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
12145: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
12146: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
12147: }
12148: }
1.320 raeburn 12149: } else {
12150: $resulttext .= &mt('No');
12151: }
12152: $resulttext .= '</li>';
12153: }
1.326 raeburn 12154: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
12155: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
12156: $resulttext .= '<li>'.&mt('Menu items:').' '.
12157: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
12158: } else {
12159: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
12160: }
12161: }
1.320 raeburn 12162: $resulttext .= '</ul></li>';
12163: }
12164: }
12165: $resulttext .= '</ul>';
12166: } else {
12167: $resulttext = &mt('No changes made.');
12168: }
12169: } else {
12170: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
12171: }
12172: if ($errors) {
12173: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12174: $errors.'</ul>';
12175: }
12176: return $resulttext;
12177: }
12178:
12179: sub get_lti_id {
12180: my ($domain,$consumer) = @_;
12181: # get lock on lti db
12182: my $lockhash = {
12183: lock => $env{'user.name'}.
12184: ':'.$env{'user.domain'},
12185: };
12186: my $tries = 0;
12187: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
12188: my ($id,$error);
12189:
12190: while (($gotlock ne 'ok') && ($tries<10)) {
12191: $tries ++;
12192: sleep (0.1);
12193: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
12194: }
12195: if ($gotlock eq 'ok') {
12196: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
12197: if ($currids{'lock'}) {
12198: delete($currids{'lock'});
12199: if (keys(%currids)) {
12200: my @curr = sort { $a <=> $b } keys(%currids);
12201: if ($curr[-1] =~ /^\d+$/) {
12202: $id = 1 + $curr[-1];
12203: }
12204: } else {
12205: $id = 1;
12206: }
12207: if ($id) {
12208: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
12209: $error = 'nostore';
12210: }
12211: } else {
12212: $error = 'nonumber';
12213: }
12214: }
12215: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
12216: } else {
12217: $error = 'nolock';
12218: }
12219: return ($id,$error);
12220: }
12221:
1.3 raeburn 12222: sub modify_autoenroll {
1.205 raeburn 12223: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 12224: my ($resulttext,%changes);
12225: my %currautoenroll;
12226: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
12227: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
12228: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
12229: }
12230: }
12231: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
12232: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 12233: sender => 'Sender for notification messages',
1.274 raeburn 12234: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
12235: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 12236: my @offon = ('off','on');
1.17 raeburn 12237: my $sender_uname = $env{'form.sender_uname'};
12238: my $sender_domain = $env{'form.sender_domain'};
12239: if ($sender_domain eq '') {
12240: $sender_uname = '';
12241: } elsif ($sender_uname eq '') {
12242: $sender_domain = '';
12243: }
1.129 raeburn 12244: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 12245: my $failsafe = $env{'form.autoenroll_failsafe'};
12246: $failsafe =~ s{^\s+|\s+$}{}g;
12247: if ($failsafe =~ /\D/) {
12248: undef($failsafe);
12249: }
1.1 raeburn 12250: my %autoenrollhash = (
1.129 raeburn 12251: autoenroll => { 'run' => $env{'form.autoenroll_run'},
12252: 'sender_uname' => $sender_uname,
12253: 'sender_domain' => $sender_domain,
12254: 'co-owners' => $coowners,
1.274 raeburn 12255: 'autofailsafe' => $failsafe,
1.1 raeburn 12256: }
12257: );
1.4 raeburn 12258: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
12259: $dom);
1.1 raeburn 12260: if ($putresult eq 'ok') {
12261: if (exists($currautoenroll{'run'})) {
12262: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
12263: $changes{'run'} = 1;
12264: }
12265: } elsif ($autorun) {
12266: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 12267: $changes{'run'} = 1;
1.1 raeburn 12268: }
12269: }
1.17 raeburn 12270: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 12271: $changes{'sender'} = 1;
12272: }
1.17 raeburn 12273: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 12274: $changes{'sender'} = 1;
12275: }
1.129 raeburn 12276: if ($currautoenroll{'co-owners'} ne '') {
12277: if ($currautoenroll{'co-owners'} ne $coowners) {
12278: $changes{'coowners'} = 1;
12279: }
12280: } elsif ($coowners) {
12281: $changes{'coowners'} = 1;
1.274 raeburn 12282: }
12283: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
12284: $changes{'autofailsafe'} = 1;
12285: }
1.1 raeburn 12286: if (keys(%changes) > 0) {
12287: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 12288: if ($changes{'run'}) {
1.1 raeburn 12289: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
12290: }
12291: if ($changes{'sender'}) {
1.17 raeburn 12292: if ($sender_uname eq '' || $sender_domain eq '') {
12293: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
12294: } else {
12295: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
12296: }
1.1 raeburn 12297: }
1.129 raeburn 12298: if ($changes{'coowners'}) {
12299: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
12300: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12301: if (ref($lastactref) eq 'HASH') {
12302: $lastactref->{'domainconfig'} = 1;
12303: }
1.129 raeburn 12304: }
1.274 raeburn 12305: if ($changes{'autofailsafe'}) {
12306: if ($failsafe ne '') {
1.299 raeburn 12307: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274 raeburn 12308: } else {
1.299 raeburn 12309: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274 raeburn 12310: }
12311: &Apache::lonnet::get_domain_defaults($dom,1);
12312: if (ref($lastactref) eq 'HASH') {
12313: $lastactref->{'domdefaults'} = 1;
12314: }
12315: }
1.1 raeburn 12316: $resulttext .= '</ul>';
12317: } else {
12318: $resulttext = &mt('No changes made to auto-enrollment settings');
12319: }
12320: } else {
1.11 albertel 12321: $resulttext = '<span class="LC_error">'.
12322: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12323: }
1.3 raeburn 12324: return $resulttext;
1.1 raeburn 12325: }
12326:
12327: sub modify_autoupdate {
1.3 raeburn 12328: my ($dom,%domconfig) = @_;
1.1 raeburn 12329: my ($resulttext,%currautoupdate,%fields,%changes);
12330: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
12331: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
12332: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
12333: }
12334: }
12335: my @offon = ('off','on');
12336: my %title = &Apache::lonlocal::texthash (
12337: run => 'Auto-update:',
12338: classlists => 'Updates to user information in classlists?'
12339: );
1.44 raeburn 12340: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 12341: my %fieldtitles = &Apache::lonlocal::texthash (
12342: id => 'Student/Employee ID',
1.20 raeburn 12343: permanentemail => 'E-mail address',
1.1 raeburn 12344: lastname => 'Last Name',
12345: firstname => 'First Name',
12346: middlename => 'Middle Name',
1.132 raeburn 12347: generation => 'Generation',
1.1 raeburn 12348: );
1.142 raeburn 12349: $othertitle = &mt('All users');
1.1 raeburn 12350: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 12351: $othertitle = &mt('Other users');
1.1 raeburn 12352: }
12353: foreach my $key (keys(%env)) {
12354: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 12355: my ($usertype,$item) = ($1,$2);
12356: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
12357: if ($usertype eq 'default') {
12358: push(@{$fields{$1}},$2);
12359: } elsif (ref($types) eq 'ARRAY') {
12360: if (grep(/^\Q$usertype\E$/,@{$types})) {
12361: push(@{$fields{$1}},$2);
12362: }
12363: }
12364: }
1.1 raeburn 12365: }
12366: }
1.131 raeburn 12367: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
12368: @lockablenames = sort(@lockablenames);
12369: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
12370: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
12371: if (@changed) {
12372: $changes{'lockablenames'} = 1;
12373: }
12374: } else {
12375: if (@lockablenames) {
12376: $changes{'lockablenames'} = 1;
12377: }
12378: }
1.1 raeburn 12379: my %updatehash = (
12380: autoupdate => { run => $env{'form.autoupdate_run'},
12381: classlists => $env{'form.classlists'},
12382: fields => {%fields},
1.131 raeburn 12383: lockablenames => \@lockablenames,
1.1 raeburn 12384: }
12385: );
12386: foreach my $key (keys(%currautoupdate)) {
12387: if (($key eq 'run') || ($key eq 'classlists')) {
12388: if (exists($updatehash{autoupdate}{$key})) {
12389: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
12390: $changes{$key} = 1;
12391: }
12392: }
12393: } elsif ($key eq 'fields') {
12394: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 12395: foreach my $item (@{$types},'default') {
1.1 raeburn 12396: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
12397: my $change = 0;
12398: foreach my $type (@{$currautoupdate{$key}{$item}}) {
12399: if (!exists($fields{$item})) {
12400: $change = 1;
1.132 raeburn 12401: last;
1.1 raeburn 12402: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 12403: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 12404: $change = 1;
1.132 raeburn 12405: last;
1.1 raeburn 12406: }
12407: }
12408: }
12409: if ($change) {
12410: push(@{$changes{$key}},$item);
12411: }
1.26 raeburn 12412: }
1.1 raeburn 12413: }
12414: }
1.131 raeburn 12415: } elsif ($key eq 'lockablenames') {
12416: if (ref($currautoupdate{$key}) eq 'ARRAY') {
12417: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
12418: if (@changed) {
12419: $changes{'lockablenames'} = 1;
12420: }
12421: } else {
12422: if (@lockablenames) {
12423: $changes{'lockablenames'} = 1;
12424: }
12425: }
12426: }
12427: }
12428: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
12429: if (@lockablenames) {
12430: $changes{'lockablenames'} = 1;
1.1 raeburn 12431: }
12432: }
1.26 raeburn 12433: foreach my $item (@{$types},'default') {
12434: if (defined($fields{$item})) {
12435: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 12436: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
12437: my $change = 0;
12438: if (ref($fields{$item}) eq 'ARRAY') {
12439: foreach my $type (@{$fields{$item}}) {
12440: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
12441: $change = 1;
12442: last;
12443: }
12444: }
12445: }
12446: if ($change) {
12447: push(@{$changes{'fields'}},$item);
12448: }
12449: } else {
1.26 raeburn 12450: push(@{$changes{'fields'}},$item);
12451: }
12452: } else {
12453: push(@{$changes{'fields'}},$item);
1.1 raeburn 12454: }
12455: }
12456: }
12457: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
12458: $dom);
12459: if ($putresult eq 'ok') {
12460: if (keys(%changes) > 0) {
12461: $resulttext = &mt('Changes made:').'<ul>';
12462: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 12463: if ($key eq 'lockablenames') {
12464: $resulttext .= '<li>';
12465: if (@lockablenames) {
12466: $usertypes->{'default'} = $othertitle;
12467: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
12468: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
12469: } else {
12470: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
12471: }
12472: $resulttext .= '</li>';
12473: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 12474: foreach my $item (@{$changes{$key}}) {
12475: my @newvalues;
12476: foreach my $type (@{$fields{$item}}) {
12477: push(@newvalues,$fieldtitles{$type});
12478: }
1.3 raeburn 12479: my $newvaluestr;
12480: if (@newvalues > 0) {
12481: $newvaluestr = join(', ',@newvalues);
12482: } else {
12483: $newvaluestr = &mt('none');
1.6 raeburn 12484: }
1.1 raeburn 12485: if ($item eq 'default') {
1.26 raeburn 12486: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 12487: } else {
1.26 raeburn 12488: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 12489: }
12490: }
12491: } else {
12492: my $newvalue;
12493: if ($key eq 'run') {
12494: $newvalue = $offon[$env{'form.autoupdate_run'}];
12495: } else {
12496: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 12497: }
1.1 raeburn 12498: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
12499: }
12500: }
12501: $resulttext .= '</ul>';
12502: } else {
1.3 raeburn 12503: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 12504: }
12505: } else {
1.11 albertel 12506: $resulttext = '<span class="LC_error">'.
12507: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12508: }
1.3 raeburn 12509: return $resulttext;
1.1 raeburn 12510: }
12511:
1.125 raeburn 12512: sub modify_autocreate {
12513: my ($dom,%domconfig) = @_;
12514: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
12515: if (ref($domconfig{'autocreate'}) eq 'HASH') {
12516: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
12517: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
12518: }
12519: }
12520: my %title= ( xml => 'Auto-creation of courses in XML course description files',
12521: req => 'Auto-creation of validated requests for official courses',
12522: xmldc => 'Identity of course creator of courses from XML files',
12523: );
12524: my @types = ('xml','req');
12525: foreach my $item (@types) {
12526: $newvals{$item} = $env{'form.autocreate_'.$item};
12527: $newvals{$item} =~ s/\D//g;
12528: $newvals{$item} = 0 if ($newvals{$item} eq '');
12529: }
12530: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 12531: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 12532: unless (exists($domcoords{$newvals{'xmldc'}})) {
12533: $newvals{'xmldc'} = '';
12534: }
12535: %autocreatehash = (
12536: autocreate => { xml => $newvals{'xml'},
12537: req => $newvals{'req'},
12538: }
12539: );
12540: if ($newvals{'xmldc'} ne '') {
12541: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
12542: }
12543: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
12544: $dom);
12545: if ($putresult eq 'ok') {
12546: my @items = @types;
12547: if ($newvals{'xml'}) {
12548: push(@items,'xmldc');
12549: }
12550: foreach my $item (@items) {
12551: if (exists($currautocreate{$item})) {
12552: if ($currautocreate{$item} ne $newvals{$item}) {
12553: $changes{$item} = 1;
12554: }
12555: } elsif ($newvals{$item}) {
12556: $changes{$item} = 1;
12557: }
12558: }
12559: if (keys(%changes) > 0) {
12560: my @offon = ('off','on');
12561: $resulttext = &mt('Changes made:').'<ul>';
12562: foreach my $item (@types) {
12563: if ($changes{$item}) {
12564: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 12565: $resulttext .= '<li>'.
12566: &mt("$title{$item} set to [_1]$newtxt [_2]",
12567: '<b>','</b>').
12568: '</li>';
1.125 raeburn 12569: }
12570: }
12571: if ($changes{'xmldc'}) {
12572: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
12573: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 12574: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 12575: }
12576: $resulttext .= '</ul>';
12577: } else {
12578: $resulttext = &mt('No changes made to auto-creation settings');
12579: }
12580: } else {
12581: $resulttext = '<span class="LC_error">'.
12582: &mt('An error occurred: [_1]',$putresult).'</span>';
12583: }
12584: return $resulttext;
12585: }
12586:
1.23 raeburn 12587: sub modify_directorysrch {
1.295 raeburn 12588: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 12589: my ($resulttext,%changes);
12590: my %currdirsrch;
12591: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
12592: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
12593: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
12594: }
12595: }
1.277 raeburn 12596: my %title = ( available => 'Institutional directory search available',
12597: localonly => 'Other domains can search institution',
12598: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 12599: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 12600: searchby => 'Search types',
12601: searchtypes => 'Search latitude');
12602: my @offon = ('off','on');
1.24 raeburn 12603: my @otherdoms = ('Yes','No');
1.23 raeburn 12604:
1.25 raeburn 12605: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 12606: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
12607: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
12608:
1.44 raeburn 12609: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 12610: if (keys(%{$usertypes}) == 0) {
12611: @cansearch = ('default');
12612: } else {
12613: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
12614: foreach my $type (@{$currdirsrch{'cansearch'}}) {
12615: if (!grep(/^\Q$type\E$/,@cansearch)) {
12616: push(@{$changes{'cansearch'}},$type);
12617: }
1.23 raeburn 12618: }
1.26 raeburn 12619: foreach my $type (@cansearch) {
12620: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
12621: push(@{$changes{'cansearch'}},$type);
12622: }
1.23 raeburn 12623: }
1.26 raeburn 12624: } else {
12625: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 12626: }
12627: }
12628:
12629: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
12630: foreach my $by (@{$currdirsrch{'searchby'}}) {
12631: if (!grep(/^\Q$by\E$/,@searchby)) {
12632: push(@{$changes{'searchby'}},$by);
12633: }
12634: }
12635: foreach my $by (@searchby) {
12636: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
12637: push(@{$changes{'searchby'}},$by);
12638: }
12639: }
12640: } else {
12641: push(@{$changes{'searchby'}},@searchby);
12642: }
1.25 raeburn 12643:
12644: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
12645: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
12646: if (!grep(/^\Q$type\E$/,@searchtypes)) {
12647: push(@{$changes{'searchtypes'}},$type);
12648: }
12649: }
12650: foreach my $type (@searchtypes) {
12651: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
12652: push(@{$changes{'searchtypes'}},$type);
12653: }
12654: }
12655: } else {
12656: if (exists($currdirsrch{'searchtypes'})) {
12657: foreach my $type (@searchtypes) {
12658: if ($type ne $currdirsrch{'searchtypes'}) {
12659: push(@{$changes{'searchtypes'}},$type);
12660: }
12661: }
12662: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
12663: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
12664: }
12665: } else {
12666: push(@{$changes{'searchtypes'}},@searchtypes);
12667: }
12668: }
12669:
1.23 raeburn 12670: my %dirsrch_hash = (
12671: directorysrch => { available => $env{'form.dirsrch_available'},
12672: cansearch => \@cansearch,
1.277 raeburn 12673: localonly => $env{'form.dirsrch_instlocalonly'},
12674: lclocalonly => $env{'form.dirsrch_domlocalonly'},
12675: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 12676: searchby => \@searchby,
1.25 raeburn 12677: searchtypes => \@searchtypes,
1.23 raeburn 12678: }
12679: );
12680: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
12681: $dom);
12682: if ($putresult eq 'ok') {
12683: if (exists($currdirsrch{'available'})) {
12684: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
12685: $changes{'available'} = 1;
12686: }
12687: } else {
12688: if ($env{'form.dirsrch_available'} eq '1') {
12689: $changes{'available'} = 1;
12690: }
12691: }
1.277 raeburn 12692: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 12693: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
12694: $changes{'lcavailable'} = 1;
12695: }
1.277 raeburn 12696: } else {
12697: if ($env{'form.dirsrch_lcavailable'} eq '1') {
12698: $changes{'lcavailable'} = 1;
12699: }
12700: }
1.24 raeburn 12701: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 12702: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
12703: $changes{'localonly'} = 1;
12704: }
1.24 raeburn 12705: } else {
1.277 raeburn 12706: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 12707: $changes{'localonly'} = 1;
12708: }
12709: }
1.277 raeburn 12710: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 12711: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
12712: $changes{'lclocalonly'} = 1;
12713: }
1.277 raeburn 12714: } else {
12715: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
12716: $changes{'lclocalonly'} = 1;
12717: }
12718: }
1.23 raeburn 12719: if (keys(%changes) > 0) {
12720: $resulttext = &mt('Changes made:').'<ul>';
12721: if ($changes{'available'}) {
12722: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
12723: }
1.277 raeburn 12724: if ($changes{'lcavailable'}) {
12725: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
12726: }
1.24 raeburn 12727: if ($changes{'localonly'}) {
1.277 raeburn 12728: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 12729: }
1.277 raeburn 12730: if ($changes{'lclocalonly'}) {
12731: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 12732: }
1.23 raeburn 12733: if (ref($changes{'cansearch'}) eq 'ARRAY') {
12734: my $chgtext;
1.26 raeburn 12735: if (ref($usertypes) eq 'HASH') {
12736: if (keys(%{$usertypes}) > 0) {
12737: foreach my $type (@{$types}) {
12738: if (grep(/^\Q$type\E$/,@cansearch)) {
12739: $chgtext .= $usertypes->{$type}.'; ';
12740: }
12741: }
12742: if (grep(/^default$/,@cansearch)) {
12743: $chgtext .= $othertitle;
12744: } else {
12745: $chgtext =~ s/\; $//;
12746: }
1.210 raeburn 12747: $resulttext .=
1.178 raeburn 12748: '<li>'.
12749: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
12750: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
12751: '</li>';
1.23 raeburn 12752: }
12753: }
12754: }
12755: if (ref($changes{'searchby'}) eq 'ARRAY') {
12756: my ($searchtitles,$titleorder) = &sorted_searchtitles();
12757: my $chgtext;
12758: foreach my $type (@{$titleorder}) {
12759: if (grep(/^\Q$type\E$/,@searchby)) {
12760: if (defined($searchtitles->{$type})) {
12761: $chgtext .= $searchtitles->{$type}.'; ';
12762: }
12763: }
12764: }
12765: $chgtext =~ s/\; $//;
12766: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
12767: }
1.25 raeburn 12768: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
12769: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
12770: my $chgtext;
12771: foreach my $type (@{$srchtypeorder}) {
12772: if (grep(/^\Q$type\E$/,@searchtypes)) {
12773: if (defined($srchtypes_desc->{$type})) {
12774: $chgtext .= $srchtypes_desc->{$type}.'; ';
12775: }
12776: }
12777: }
12778: $chgtext =~ s/\; $//;
1.178 raeburn 12779: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 12780: }
12781: $resulttext .= '</ul>';
1.295 raeburn 12782: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
12783: if (ref($lastactref) eq 'HASH') {
12784: $lastactref->{'directorysrch'} = 1;
12785: }
1.23 raeburn 12786: } else {
1.277 raeburn 12787: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 12788: }
12789: } else {
12790: $resulttext = '<span class="LC_error">'.
1.27 raeburn 12791: &mt('An error occurred: [_1]',$putresult).'</span>';
12792: }
12793: return $resulttext;
12794: }
12795:
1.28 raeburn 12796: sub modify_contacts {
1.205 raeburn 12797: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 12798: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
12799: if (ref($domconfig{'contacts'}) eq 'HASH') {
12800: foreach my $key (keys(%{$domconfig{'contacts'}})) {
12801: $currsetting{$key} = $domconfig{'contacts'}{$key};
12802: }
12803: }
1.286 raeburn 12804: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 12805: my @contacts = ('supportemail','adminemail');
1.286 raeburn 12806: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
12807: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.340 raeburn 12808: my @toggles = ('reporterrors','reportupdates','reportstatus');
12809: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 12810: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 12811: foreach my $type (@mailings) {
12812: @{$newsetting{$type}} =
12813: &Apache::loncommon::get_env_multiple('form.'.$type);
12814: foreach my $item (@contacts) {
12815: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
12816: $contacts_hash{contacts}{$type}{$item} = 1;
12817: } else {
12818: $contacts_hash{contacts}{$type}{$item} = 0;
12819: }
1.289 raeburn 12820: }
1.28 raeburn 12821: $others{$type} = $env{'form.'.$type.'_others'};
12822: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 12823: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12824: $bcc{$type} = $env{'form.'.$type.'_bcc'};
12825: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 12826: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
12827: $includestr{$type} = $env{'form.'.$type.'_includestr'};
12828: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
12829: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
12830: }
1.134 raeburn 12831: }
1.28 raeburn 12832: }
12833: foreach my $item (@contacts) {
12834: $to{$item} = $env{'form.'.$item};
12835: $contacts_hash{'contacts'}{$item} = $to{$item};
12836: }
1.203 raeburn 12837: foreach my $item (@toggles) {
12838: if ($env{'form.'.$item} =~ /^(0|1)$/) {
12839: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
12840: }
12841: }
1.340 raeburn 12842: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
12843: foreach my $item (@lonstatus) {
12844: if ($item eq 'excluded') {
12845: my (%serverhomes,@excluded);
12846: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
12847: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
12848: if (@possexcluded) {
12849: foreach my $id (sort(@possexcluded)) {
12850: if ($serverhomes{$id}) {
12851: push(@excluded,$id);
12852: }
12853: }
12854: }
12855: if (@excluded) {
12856: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
12857: }
12858: } elsif ($item eq 'weights') {
12859: foreach my $type ('E','W','N') {
12860: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
12861: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
12862: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
12863: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
12864: $env{'form.error'.$item.'_'.$type};
12865: }
12866: }
12867: }
12868: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
12869: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
12870: if ($env{'form.error'.$item} =~ /^\d+$/) {
12871: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
12872: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
12873: }
12874: }
12875: }
12876: }
1.286 raeburn 12877: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
12878: foreach my $field (@{$fields}) {
12879: if (ref($possoptions->{$field}) eq 'ARRAY') {
12880: my $value = $env{'form.helpform_'.$field};
12881: $value =~ s/^\s+|\s+$//g;
12882: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 12883: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 12884: if ($field eq 'screenshot') {
12885: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
12886: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 12887: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 12888: }
12889: }
12890: }
12891: }
12892: }
12893: }
1.315 raeburn 12894: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12895: my (@statuses,%usertypeshash,@overrides);
12896: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
12897: @statuses = @{$types};
12898: if (ref($usertypes) eq 'HASH') {
12899: %usertypeshash = %{$usertypes};
12900: }
12901: }
12902: if (@statuses) {
12903: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
12904: foreach my $type (@possoverrides) {
12905: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
12906: push(@overrides,$type);
12907: }
12908: }
12909: if (@overrides) {
12910: foreach my $type (@overrides) {
12911: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
12912: foreach my $item (@contacts) {
12913: if (grep(/^\Q$item\E$/,@standard)) {
12914: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
12915: $newsetting{'override_'.$type}{$item} = 1;
12916: } else {
12917: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
12918: $newsetting{'override_'.$type}{$item} = 0;
12919: }
12920: }
12921: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
12922: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
12923: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
12924: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
12925: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
12926: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
12927: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
12928: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
12929: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
12930: }
12931: }
12932: }
12933: }
1.28 raeburn 12934: if (keys(%currsetting) > 0) {
12935: foreach my $item (@contacts) {
12936: if ($to{$item} ne $currsetting{$item}) {
12937: $changes{$item} = 1;
12938: }
12939: }
12940: foreach my $type (@mailings) {
12941: foreach my $item (@contacts) {
12942: if (ref($currsetting{$type}) eq 'HASH') {
12943: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
12944: push(@{$changes{$type}},$item);
12945: }
12946: } else {
12947: push(@{$changes{$type}},@{$newsetting{$type}});
12948: }
12949: }
12950: if ($others{$type} ne $currsetting{$type}{'others'}) {
12951: push(@{$changes{$type}},'others');
12952: }
1.289 raeburn 12953: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12954: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
12955: push(@{$changes{$type}},'bcc');
12956: }
1.286 raeburn 12957: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
12958: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
12959: push(@{$changes{$type}},'include');
12960: }
12961: }
12962: }
12963: if (ref($fields) eq 'ARRAY') {
12964: if (ref($currsetting{'helpform'}) eq 'HASH') {
12965: foreach my $field (@{$fields}) {
12966: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
12967: push(@{$changes{'helpform'}},$field);
12968: }
12969: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12970: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
12971: push(@{$changes{'helpform'}},'maxsize');
12972: }
12973: }
12974: }
12975: } else {
12976: foreach my $field (@{$fields}) {
12977: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12978: push(@{$changes{'helpform'}},$field);
12979: }
12980: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12981: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12982: push(@{$changes{'helpform'}},'maxsize');
12983: }
12984: }
12985: }
1.134 raeburn 12986: }
1.28 raeburn 12987: }
1.315 raeburn 12988: if (@statuses) {
12989: if (ref($currsetting{'overrides'}) eq 'HASH') {
12990: foreach my $key (keys(%{$currsetting{'overrides'}})) {
12991: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
12992: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
12993: foreach my $item (@contacts,'bcc','others','include') {
12994: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
12995: push(@{$changes{'overrides'}},$key);
12996: last;
12997: }
12998: }
12999: } else {
13000: push(@{$changes{'overrides'}},$key);
13001: }
13002: }
13003: }
13004: foreach my $key (@overrides) {
13005: unless (exists($currsetting{'overrides'}{$key})) {
13006: push(@{$changes{'overrides'}},$key);
13007: }
13008: }
13009: } else {
13010: foreach my $key (@overrides) {
13011: push(@{$changes{'overrides'}},$key);
13012: }
13013: }
13014: }
1.340 raeburn 13015: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
13016: foreach my $key ('excluded','weights','threshold','sysmail') {
13017: if ($key eq 'excluded') {
13018: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
13019: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
13020: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
13021: (@{$currsetting{'lonstatus'}{$key}})) {
13022: my @diffs =
13023: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
13024: $currsetting{'lonstatus'}{$key});
13025: if (@diffs) {
13026: push(@{$changes{'lonstatus'}},$key);
13027: }
13028: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
13029: push(@{$changes{'lonstatus'}},$key);
13030: }
13031: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
13032: (@{$currsetting{'lonstatus'}{$key}})) {
13033: push(@{$changes{'lonstatus'}},$key);
13034: }
13035: } elsif ($key eq 'weights') {
13036: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
13037: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
13038: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 13039: foreach my $type ('E','W','N','U') {
1.340 raeburn 13040: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
13041: $currsetting{'lonstatus'}{$key}{$type}) {
13042: push(@{$changes{'lonstatus'}},$key);
13043: last;
13044: }
13045: }
13046: } else {
1.341 raeburn 13047: foreach my $type ('E','W','N','U') {
1.340 raeburn 13048: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
13049: push(@{$changes{'lonstatus'}},$key);
13050: last;
13051: }
13052: }
13053: }
13054: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 13055: foreach my $type ('E','W','N','U') {
1.340 raeburn 13056: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
13057: push(@{$changes{'lonstatus'}},$key);
13058: last;
13059: }
13060: }
13061: }
13062: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
13063: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
13064: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
13065: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
13066: push(@{$changes{'lonstatus'}},$key);
13067: }
13068: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
13069: push(@{$changes{'lonstatus'}},$key);
13070: }
13071: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
13072: push(@{$changes{'lonstatus'}},$key);
13073: }
13074: }
13075: }
13076: } else {
13077: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
13078: foreach my $key ('excluded','weights','threshold','sysmail') {
13079: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
13080: push(@{$changes{'lonstatus'}},$key);
13081: }
13082: }
13083: }
13084: }
1.28 raeburn 13085: } else {
13086: my %default;
13087: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
13088: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
13089: $default{'errormail'} = 'adminemail';
13090: $default{'packagesmail'} = 'adminemail';
13091: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 13092: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 13093: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 13094: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 13095: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 13096: foreach my $item (@contacts) {
13097: if ($to{$item} ne $default{$item}) {
1.286 raeburn 13098: $changes{$item} = 1;
1.203 raeburn 13099: }
1.28 raeburn 13100: }
13101: foreach my $type (@mailings) {
13102: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
13103: push(@{$changes{$type}},@{$newsetting{$type}});
13104: }
13105: if ($others{$type} ne '') {
13106: push(@{$changes{$type}},'others');
1.134 raeburn 13107: }
1.286 raeburn 13108: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13109: if ($bcc{$type} ne '') {
13110: push(@{$changes{$type}},'bcc');
13111: }
1.286 raeburn 13112: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
13113: push(@{$changes{$type}},'include');
13114: }
1.134 raeburn 13115: }
1.28 raeburn 13116: }
1.286 raeburn 13117: if (ref($fields) eq 'ARRAY') {
13118: foreach my $field (@{$fields}) {
13119: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
13120: push(@{$changes{'helpform'}},$field);
13121: }
13122: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
13123: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
13124: push(@{$changes{'helpform'}},'maxsize');
13125: }
13126: }
13127: }
1.289 raeburn 13128: }
1.340 raeburn 13129: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
13130: foreach my $key ('excluded','weights','threshold','sysmail') {
13131: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
13132: push(@{$changes{'lonstatus'}},$key);
13133: }
13134: }
13135: }
1.28 raeburn 13136: }
1.203 raeburn 13137: foreach my $item (@toggles) {
13138: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
13139: $changes{$item} = 1;
13140: } elsif ((!$env{'form.'.$item}) &&
13141: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
13142: $changes{$item} = 1;
13143: }
13144: }
1.28 raeburn 13145: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
13146: $dom);
13147: if ($putresult eq 'ok') {
13148: if (keys(%changes) > 0) {
1.205 raeburn 13149: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 13150: if (ref($lastactref) eq 'HASH') {
13151: $lastactref->{'domainconfig'} = 1;
13152: }
1.28 raeburn 13153: my ($titles,$short_titles) = &contact_titles();
13154: $resulttext = &mt('Changes made:').'<ul>';
13155: foreach my $item (@contacts) {
13156: if ($changes{$item}) {
13157: $resulttext .= '<li>'.$titles->{$item}.
13158: &mt(' set to: ').
13159: '<span class="LC_cusr_emph">'.
13160: $to{$item}.'</span></li>';
13161: }
13162: }
13163: foreach my $type (@mailings) {
13164: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 13165: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 13166: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 13167: } else {
13168: $resulttext .= '<li>'.$titles->{$type}.': ';
13169: }
1.28 raeburn 13170: my @text;
13171: foreach my $item (@{$newsetting{$type}}) {
13172: push(@text,$short_titles->{$item});
13173: }
13174: if ($others{$type} ne '') {
13175: push(@text,$others{$type});
13176: }
1.286 raeburn 13177: if (@text) {
13178: $resulttext .= '<span class="LC_cusr_emph">'.
13179: join(', ',@text).'</span>';
13180: }
13181: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13182: if ($bcc{$type} ne '') {
1.286 raeburn 13183: my $bcctext;
13184: if (@text) {
1.289 raeburn 13185: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 13186: } else {
13187: $bcctext = '(Bcc)';
13188: }
13189: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
13190: } elsif (!@text) {
13191: $resulttext .= &mt('No one');
13192: }
1.289 raeburn 13193: if ($includestr{$type} ne '') {
1.286 raeburn 13194: if ($includeloc{$type} eq 'b') {
13195: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
13196: } elsif ($includeloc{$type} eq 's') {
13197: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
13198: }
1.134 raeburn 13199: }
1.286 raeburn 13200: } elsif (!@text) {
13201: $resulttext .= &mt('No recipients');
1.134 raeburn 13202: }
13203: $resulttext .= '</li>';
1.28 raeburn 13204: }
13205: }
1.315 raeburn 13206: if (ref($changes{'overrides'}) eq 'ARRAY') {
13207: my @deletions;
13208: foreach my $type (@{$changes{'overrides'}}) {
13209: if ($usertypeshash{$type}) {
13210: if (grep(/^\Q$type\E/,@overrides)) {
13211: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
13212: $usertypeshash{$type}).'<ul><li>';
13213: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
13214: my @text;
13215: foreach my $item (@contacts) {
13216: if ($newsetting{'override_'.$type}{$item}) {
13217: push(@text,$short_titles->{$item});
13218: }
13219: }
13220: if ($newsetting{'override_'.$type}{'others'} ne '') {
13221: push(@text,$newsetting{'override_'.$type}{'others'});
13222: }
13223:
13224: if (@text) {
13225: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
13226: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
13227: }
13228: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
13229: my $bcctext;
13230: if (@text) {
13231: $bcctext = ' '.&mt('with Bcc to');
13232: } else {
13233: $bcctext = '(Bcc)';
13234: }
13235: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
13236: } elsif (!@text) {
13237: $resulttext .= &mt('Helpdesk e-mail sent to no one');
13238: }
13239: $resulttext .= '</li>';
13240: if ($newsetting{'override_'.$type}{'include'} ne '') {
13241: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
13242: if ($loc eq 'b') {
13243: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
13244: } elsif ($loc eq 's') {
13245: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
13246: }
13247: }
13248: }
13249: $resulttext .= '</li></ul></li>';
13250: } else {
13251: push(@deletions,$usertypeshash{$type});
13252: }
13253: }
13254: }
13255: if (@deletions) {
13256: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
13257: join(', ',@deletions)).'</li>';
13258: }
13259: }
1.203 raeburn 13260: my @offon = ('off','on');
1.340 raeburn 13261: my $corelink = &core_link_msu();
1.203 raeburn 13262: if ($changes{'reporterrors'}) {
13263: $resulttext .= '<li>'.
13264: &mt('E-mail error reports to [_1] set to "'.
13265: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 13266: $corelink).
1.203 raeburn 13267: '</li>';
13268: }
13269: if ($changes{'reportupdates'}) {
13270: $resulttext .= '<li>'.
13271: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
13272: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 13273: $corelink).
1.203 raeburn 13274: '</li>';
13275: }
1.340 raeburn 13276: if ($changes{'reportstatus'}) {
13277: $resulttext .= '<li>'.
13278: &mt('E-mail status if errors above threshold to [_1] set to "'.
13279: $offon[$env{'form.reportstatus'}].'".',
13280: $corelink).
13281: '</li>';
13282: }
13283: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
13284: $resulttext .= '<li>'.
13285: &mt('Nightly status check e-mail settings').':<ul>';
13286: my (%defval,%use_def,%shown);
13287: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
13288: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
13289: $defval{'weights'} =
1.341 raeburn 13290: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 13291: $defval{'excluded'} = &mt('None');
13292: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
13293: foreach my $item ('threshold','sysmail','weights','excluded') {
13294: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
13295: if (($item eq 'threshold') || ($item eq 'sysmail')) {
13296: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
13297: } elsif ($item eq 'weights') {
13298: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 13299: foreach my $type ('E','W','N','U') {
1.340 raeburn 13300: $shown{$item} .= $lonstatus_names->{$type}.'=';
13301: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
13302: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
13303: } else {
13304: $shown{$item} .= $lonstatus_defs->{$type};
13305: }
13306: $shown{$item} .= ', ';
13307: }
13308: $shown{$item} =~ s/, $//;
13309: } else {
13310: $shown{$item} = $defval{$item};
13311: }
13312: } elsif ($item eq 'excluded') {
13313: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
13314: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
13315: } else {
13316: $shown{$item} = $defval{$item};
13317: }
13318: }
13319: } else {
13320: $shown{$item} = $defval{$item};
13321: }
13322: }
13323: } else {
13324: foreach my $item ('threshold','weights','excluded','sysmail') {
13325: $shown{$item} = $defval{$item};
13326: }
13327: }
13328: foreach my $item ('threshold','weights','excluded','sysmail') {
13329: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
13330: $shown{$item}).'</li>';
13331: }
13332: $resulttext .= '</ul></li>';
13333: }
1.286 raeburn 13334: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
13335: my (@optional,@required,@unused,$maxsizechg);
13336: foreach my $field (@{$changes{'helpform'}}) {
13337: if ($field eq 'maxsize') {
13338: $maxsizechg = 1;
13339: next;
13340: }
13341: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 13342: push(@optional,$field);
1.286 raeburn 13343: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
13344: push(@unused,$field);
13345: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 13346: push(@required,$field);
1.286 raeburn 13347: }
13348: }
13349: if (@optional) {
13350: $resulttext .= '<li>'.
13351: &mt('Help form fields changed to "Optional": [_1].',
13352: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
13353: '</li>';
13354: }
13355: if (@required) {
13356: $resulttext .= '<li>'.
13357: &mt('Help form fields changed to "Required": [_1].',
13358: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
13359: '</li>';
13360: }
13361: if (@unused) {
13362: $resulttext .= '<li>'.
13363: &mt('Help form fields changed to "Not shown": [_1].',
13364: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
13365: '</li>';
13366: }
13367: if ($maxsizechg) {
13368: $resulttext .= '<li>'.
13369: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
13370: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
13371: '</li>';
13372: }
13373: }
1.28 raeburn 13374: $resulttext .= '</ul>';
13375: } else {
1.288 raeburn 13376: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 13377: }
13378: } else {
13379: $resulttext = '<span class="LC_error">'.
13380: &mt('An error occurred: [_1].',$putresult).'</span>';
13381: }
13382: return $resulttext;
13383: }
13384:
13385: sub modify_usercreation {
1.27 raeburn 13386: my ($dom,%domconfig) = @_;
1.224 raeburn 13387: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 13388: my $warningmsg;
1.27 raeburn 13389: if (ref($domconfig{'usercreation'}) eq 'HASH') {
13390: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 13391: if ($key eq 'cancreate') {
13392: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
13393: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 13394: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
13395: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13396: } else {
1.224 raeburn 13397: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13398: }
13399: }
13400: }
13401: } elsif ($key eq 'email_rule') {
13402: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
13403: } else {
13404: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
13405: }
1.27 raeburn 13406: }
13407: }
13408: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 13409: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 13410: my @contexts = ('author','course','requestcrs');
1.34 raeburn 13411: foreach my $item(@contexts) {
1.224 raeburn 13412: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 13413: }
1.34 raeburn 13414: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13415: foreach my $item (@contexts) {
1.224 raeburn 13416: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
13417: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 13418: }
1.27 raeburn 13419: }
1.34 raeburn 13420: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
13421: foreach my $item (@contexts) {
1.43 raeburn 13422: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 13423: if ($cancreate{$item} ne 'any') {
13424: push(@{$changes{'cancreate'}},$item);
13425: }
13426: } else {
13427: if ($cancreate{$item} ne 'none') {
13428: push(@{$changes{'cancreate'}},$item);
13429: }
1.27 raeburn 13430: }
13431: }
13432: } else {
1.43 raeburn 13433: foreach my $item (@contexts) {
1.34 raeburn 13434: push(@{$changes{'cancreate'}},$item);
13435: }
1.27 raeburn 13436: }
1.34 raeburn 13437:
1.27 raeburn 13438: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
13439: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
13440: if (!grep(/^\Q$type\E$/,@username_rule)) {
13441: push(@{$changes{'username_rule'}},$type);
13442: }
13443: }
13444: foreach my $type (@username_rule) {
13445: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
13446: push(@{$changes{'username_rule'}},$type);
13447: }
13448: }
13449: } else {
13450: push(@{$changes{'username_rule'}},@username_rule);
13451: }
13452:
1.32 raeburn 13453: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
13454: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
13455: if (!grep(/^\Q$type\E$/,@id_rule)) {
13456: push(@{$changes{'id_rule'}},$type);
13457: }
13458: }
13459: foreach my $type (@id_rule) {
13460: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
13461: push(@{$changes{'id_rule'}},$type);
13462: }
13463: }
13464: } else {
13465: push(@{$changes{'id_rule'}},@id_rule);
13466: }
13467:
1.43 raeburn 13468: my @authen_contexts = ('author','course','domain');
1.325 raeburn 13469: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 13470: my %authhash;
1.43 raeburn 13471: foreach my $item (@authen_contexts) {
1.28 raeburn 13472: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
13473: foreach my $auth (@authtypes) {
13474: if (grep(/^\Q$auth\E$/,@authallowed)) {
13475: $authhash{$item}{$auth} = 1;
13476: } else {
13477: $authhash{$item}{$auth} = 0;
13478: }
13479: }
13480: }
13481: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 13482: foreach my $item (@authen_contexts) {
1.28 raeburn 13483: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
13484: foreach my $auth (@authtypes) {
13485: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
13486: push(@{$changes{'authtypes'}},$item);
13487: last;
13488: }
13489: }
13490: }
13491: }
13492: } else {
1.43 raeburn 13493: foreach my $item (@authen_contexts) {
1.28 raeburn 13494: push(@{$changes{'authtypes'}},$item);
13495: }
13496: }
13497:
1.224 raeburn 13498: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
13499: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
13500: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
13501: $save_usercreate{'id_rule'} = \@id_rule;
13502: $save_usercreate{'username_rule'} = \@username_rule,
13503: $save_usercreate{'authtypes'} = \%authhash;
13504:
1.27 raeburn 13505: my %usercreation_hash = (
1.224 raeburn 13506: usercreation => \%save_usercreate,
13507: );
1.27 raeburn 13508:
13509: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
13510: $dom);
1.50 raeburn 13511:
1.224 raeburn 13512: if ($putresult eq 'ok') {
13513: if (keys(%changes) > 0) {
13514: $resulttext = &mt('Changes made:').'<ul>';
13515: if (ref($changes{'cancreate'}) eq 'ARRAY') {
13516: my %lt = &usercreation_types();
13517: foreach my $type (@{$changes{'cancreate'}}) {
13518: my $chgtext = $lt{$type}.', ';
13519: if ($cancreate{$type} eq 'none') {
13520: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
13521: } elsif ($cancreate{$type} eq 'any') {
13522: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
13523: } elsif ($cancreate{$type} eq 'official') {
13524: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
13525: } elsif ($cancreate{$type} eq 'unofficial') {
13526: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
13527: }
13528: $resulttext .= '<li>'.$chgtext.'</li>';
13529: }
13530: }
13531: if (ref($changes{'username_rule'}) eq 'ARRAY') {
13532: my ($rules,$ruleorder) =
13533: &Apache::lonnet::inst_userrules($dom,'username');
13534: my $chgtext = '<ul>';
13535: foreach my $type (@username_rule) {
13536: if (ref($rules->{$type}) eq 'HASH') {
13537: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
13538: }
13539: }
13540: $chgtext .= '</ul>';
13541: if (@username_rule > 0) {
13542: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13543: } else {
13544: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
13545: }
13546: }
13547: if (ref($changes{'id_rule'}) eq 'ARRAY') {
13548: my ($idrules,$idruleorder) =
13549: &Apache::lonnet::inst_userrules($dom,'id');
13550: my $chgtext = '<ul>';
13551: foreach my $type (@id_rule) {
13552: if (ref($idrules->{$type}) eq 'HASH') {
13553: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
13554: }
13555: }
13556: $chgtext .= '</ul>';
13557: if (@id_rule > 0) {
13558: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13559: } else {
13560: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
13561: }
13562: }
13563: my %authname = &authtype_names();
13564: my %context_title = &context_names();
13565: if (ref($changes{'authtypes'}) eq 'ARRAY') {
13566: my $chgtext = '<ul>';
13567: foreach my $type (@{$changes{'authtypes'}}) {
13568: my @allowed;
13569: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
13570: foreach my $auth (@authtypes) {
13571: if ($authhash{$type}{$auth}) {
13572: push(@allowed,$authname{$auth});
13573: }
13574: }
13575: if (@allowed > 0) {
13576: $chgtext .= join(', ',@allowed).'</li>';
13577: } else {
13578: $chgtext .= &mt('none').'</li>';
13579: }
13580: }
13581: $chgtext .= '</ul>';
13582: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
13583: $resulttext .= '</li>';
13584: }
13585: $resulttext .= '</ul>';
13586: } else {
13587: $resulttext = &mt('No changes made to user creation settings');
13588: }
13589: } else {
13590: $resulttext = '<span class="LC_error">'.
13591: &mt('An error occurred: [_1]',$putresult).'</span>';
13592: }
13593: if ($warningmsg ne '') {
13594: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
13595: }
13596: return $resulttext;
13597: }
13598:
13599: sub modify_selfcreation {
1.305 raeburn 13600: my ($dom,$lastactref,%domconfig) = @_;
13601: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
13602: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
13603: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 13604: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
13605: if (ref($typesref) eq 'ARRAY') {
13606: @types = @{$typesref};
13607: }
13608: if (ref($usertypesref) eq 'HASH') {
13609: %usertypes = %{$usertypesref};
1.228 raeburn 13610: }
1.303 raeburn 13611: $usertypes{'default'} = $othertitle;
1.224 raeburn 13612: #
13613: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
13614: #
13615: if (ref($domconfig{'usercreation'}) eq 'HASH') {
13616: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
13617: if ($key eq 'cancreate') {
13618: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
13619: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
13620: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 13621: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
13622: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
13623: ($item eq 'emailusername') || ($item eq 'shibenv') ||
13624: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 13625: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 13626: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13627: } else {
13628: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13629: }
13630: }
13631: }
13632: } elsif ($key eq 'email_rule') {
13633: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
13634: } else {
13635: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
13636: }
13637: }
13638: }
13639: #
13640: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
13641: #
13642: if (ref($domconfig{'usermodification'}) eq 'HASH') {
13643: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
13644: if ($key eq 'selfcreate') {
13645: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
13646: } else {
13647: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
13648: }
13649: }
13650: }
1.305 raeburn 13651: #
13652: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
13653: #
13654: if (ref($domconfig{'inststatus'}) eq 'HASH') {
13655: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
13656: if ($key eq 'inststatusguest') {
13657: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
13658: } else {
13659: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
13660: }
13661: }
13662: }
1.224 raeburn 13663:
13664: my @contexts = ('selfcreate');
13665: @{$cancreate{'selfcreate'}} = ();
13666: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 13667: if (@types) {
13668: @{$cancreate{'statustocreate'}} = ();
13669: }
1.236 raeburn 13670: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 13671: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 13672: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 13673: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 13674: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 13675: my %selfcreatetypes = (
13676: sso => 'users authenticated by institutional single sign on',
13677: login => 'users authenticated by institutional log-in',
1.303 raeburn 13678: email => 'users verified by e-mail',
1.50 raeburn 13679: );
1.224 raeburn 13680: #
13681: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
13682: # is permitted.
13683: #
1.305 raeburn 13684: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 13685:
1.305 raeburn 13686: my (@statuses,%email_rule);
1.228 raeburn 13687: foreach my $item ('login','sso','email') {
1.224 raeburn 13688: if ($item eq 'email') {
1.236 raeburn 13689: if ($env{'form.cancreate_email'}) {
1.305 raeburn 13690: if (@types) {
13691: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
13692: foreach my $status (@poss_statuses) {
13693: if (grep(/^\Q$status\E$/,(@types,'default'))) {
13694: push(@statuses,$status);
13695: }
13696: }
13697: $save_inststatus{'inststatusguest'} = \@statuses;
13698: } else {
13699: push(@statuses,'default');
13700: }
13701: if (@statuses) {
13702: my %curr_rule;
13703: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
13704: foreach my $type (@statuses) {
13705: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 13706: }
1.305 raeburn 13707: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
13708: foreach my $type (@statuses) {
13709: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
13710: }
13711: }
13712: push(@{$cancreate{'selfcreate'}},'email');
13713: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
13714: my %curremaildom;
13715: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
13716: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
13717: }
13718: foreach my $type (@statuses) {
13719: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
13720: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
13721: }
13722: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
13723: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
13724: }
13725: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
13726: #
13727: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
13728: #
13729: my $chosen = $1;
13730: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
13731: my $emaildom;
13732: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
13733: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
13734: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
13735: if (ref($curremaildom{$type}) eq 'HASH') {
13736: if (exists($curremaildom{$type}{$chosen})) {
13737: if ($curremaildom{$type}{$chosen} ne $emaildom) {
13738: push(@{$changes{'cancreate'}},'emaildomain');
13739: }
13740: } elsif ($emaildom ne '') {
13741: push(@{$changes{'cancreate'}},'emaildomain');
13742: }
13743: } elsif ($emaildom ne '') {
13744: push(@{$changes{'cancreate'}},'emaildomain');
13745: }
13746: }
13747: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13748: } elsif ($chosen eq 'custom') {
13749: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
13750: $email_rule{$type} = [];
13751: if (ref($emailrules) eq 'HASH') {
13752: foreach my $rule (@possemail_rules) {
13753: if (exists($emailrules->{$rule})) {
13754: push(@{$email_rule{$type}},$rule);
13755: }
13756: }
13757: }
13758: if (@{$email_rule{$type}}) {
13759: $cancreate{'emailoptions'}{$type} = 'custom';
13760: if (ref($curr_rule{$type}) eq 'ARRAY') {
13761: if (@{$curr_rule{$type}} > 0) {
13762: foreach my $rule (@{$curr_rule{$type}}) {
13763: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
13764: push(@{$changes{'email_rule'}},$type);
13765: }
13766: }
13767: }
13768: foreach my $type (@{$email_rule{$type}}) {
13769: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
13770: push(@{$changes{'email_rule'}},$type);
13771: }
13772: }
13773: } else {
13774: push(@{$changes{'email_rule'}},$type);
13775: }
13776: }
13777: } else {
13778: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13779: }
13780: }
13781: }
13782: if (@types) {
13783: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13784: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
13785: if (@changed) {
13786: push(@{$changes{'inststatus'}},'inststatusguest');
13787: }
13788: } else {
13789: push(@{$changes{'inststatus'}},'inststatusguest');
13790: }
13791: }
13792: } else {
13793: delete($env{'form.cancreate_email'});
13794: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13795: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13796: push(@{$changes{'inststatus'}},'inststatusguest');
13797: }
13798: }
13799: }
13800: } else {
13801: $save_inststatus{'inststatusguest'} = [];
13802: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13803: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13804: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 13805: }
13806: }
1.224 raeburn 13807: }
13808: } else {
13809: if ($env{'form.cancreate_'.$item}) {
13810: push(@{$cancreate{'selfcreate'}},$item);
13811: }
13812: }
13813: }
1.305 raeburn 13814: my (%userinfo,%savecaptcha);
1.224 raeburn 13815: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
13816: #
1.228 raeburn 13817: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
13818: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 13819: #
1.236 raeburn 13820:
1.244 raeburn 13821: if ($env{'form.cancreate_email'}) {
1.228 raeburn 13822: push(@contexts,'emailusername');
1.305 raeburn 13823: if (@statuses) {
13824: foreach my $type (@statuses) {
1.228 raeburn 13825: if (ref($infofields) eq 'ARRAY') {
13826: foreach my $field (@{$infofields}) {
13827: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
13828: $cancreate{'emailusername'}{$type}{$field} = $1;
13829: }
13830: }
1.224 raeburn 13831: }
13832: }
13833: }
13834: #
13835: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 13836: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 13837: #
13838:
13839: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
13840: @approvalnotify = sort(@approvalnotify);
13841: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
13842: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13843: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
13844: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
13845: push(@{$changes{'cancreate'}},'notify');
13846: }
13847: } else {
13848: if ($cancreate{'notify'}{'approval'}) {
13849: push(@{$changes{'cancreate'}},'notify');
13850: }
13851: }
13852: } elsif ($cancreate{'notify'}{'approval'}) {
13853: push(@{$changes{'cancreate'}},'notify');
13854: }
13855:
13856: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
13857: }
13858: #
1.236 raeburn 13859: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 13860: # institutional log-in.
13861: #
13862: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
13863: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
13864: ($domdefaults{'auth_def'} eq 'localauth'))) {
13865: $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.').' '.
13866: &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.');
13867: }
13868: }
13869: my @fields = ('lastname','firstname','middlename','generation',
13870: 'permanentemail','id');
1.240 raeburn 13871: my @shibfields = (@fields,'inststatus');
1.224 raeburn 13872: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13873: #
13874: # Where usernames may created for institutional log-in and/or institutional single sign on:
13875: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
13876: # may self-create accounts
13877: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
13878: # which the user may supply, if institutional data is unavailable.
13879: #
13880: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 13881: if (@types) {
1.305 raeburn 13882: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
13883: push(@contexts,'statustocreate');
1.303 raeburn 13884: foreach my $type (@types) {
1.224 raeburn 13885: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
13886: foreach my $field (@fields) {
13887: if (grep(/^\Q$field\E$/,@modifiable)) {
13888: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
13889: } else {
13890: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
13891: }
13892: }
13893: }
13894: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 13895: foreach my $type (@types) {
1.224 raeburn 13896: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
13897: foreach my $field (@fields) {
13898: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
13899: $curr_usermodify{'selfcreate'}{$type}{$field}) {
13900: push(@{$changes{'selfcreate'}},$type);
13901: last;
13902: }
13903: }
13904: }
13905: }
13906: } else {
1.303 raeburn 13907: foreach my $type (@types) {
1.224 raeburn 13908: push(@{$changes{'selfcreate'}},$type);
13909: }
13910: }
13911: }
1.240 raeburn 13912: foreach my $field (@shibfields) {
13913: if ($env{'form.shibenv_'.$field} ne '') {
13914: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
13915: }
13916: }
13917: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13918: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
13919: foreach my $field (@shibfields) {
13920: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
13921: push(@{$changes{'cancreate'}},'shibenv');
13922: }
13923: }
13924: } else {
13925: foreach my $field (@shibfields) {
13926: if ($env{'form.shibenv_'.$field}) {
13927: push(@{$changes{'cancreate'}},'shibenv');
13928: last;
13929: }
13930: }
13931: }
13932: }
1.224 raeburn 13933: }
13934: foreach my $item (@contexts) {
13935: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
13936: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
13937: if (ref($cancreate{$item}) eq 'ARRAY') {
13938: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
13939: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13940: push(@{$changes{'cancreate'}},$item);
13941: }
13942: }
13943: }
13944: }
13945: if (ref($cancreate{$item}) eq 'ARRAY') {
13946: foreach my $type (@{$cancreate{$item}}) {
13947: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
13948: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13949: push(@{$changes{'cancreate'}},$item);
13950: }
13951: }
13952: }
13953: }
13954: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
13955: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 13956: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
13957: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13958: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
13959: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 13960: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13961: push(@{$changes{'cancreate'}},$item);
13962: }
13963: }
13964: }
1.305 raeburn 13965: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13966: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 13967: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13968: push(@{$changes{'cancreate'}},$item);
13969: }
1.224 raeburn 13970: }
13971: }
13972: }
1.305 raeburn 13973: foreach my $type (keys(%{$cancreate{$item}})) {
13974: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13975: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13976: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13977: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 13978: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13979: push(@{$changes{'cancreate'}},$item);
13980: }
13981: }
13982: } else {
13983: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13984: push(@{$changes{'cancreate'}},$item);
13985: }
13986: }
13987: }
1.305 raeburn 13988: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13989: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 13990: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13991: push(@{$changes{'cancreate'}},$item);
13992: }
1.224 raeburn 13993: }
13994: }
13995: }
13996: }
13997: } elsif ($curr_usercreation{'cancreate'}{$item}) {
13998: if (ref($cancreate{$item}) eq 'ARRAY') {
13999: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
14000: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14001: push(@{$changes{'cancreate'}},$item);
14002: }
14003: }
1.305 raeburn 14004: }
14005: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
14006: if (ref($cancreate{$item}) eq 'HASH') {
14007: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14008: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 14009: }
14010: }
14011: } elsif ($item eq 'emailusername') {
1.228 raeburn 14012: if (ref($cancreate{$item}) eq 'HASH') {
14013: foreach my $type (keys(%{$cancreate{$item}})) {
14014: if (ref($cancreate{$item}{$type}) eq 'HASH') {
14015: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
14016: if ($cancreate{$item}{$type}{$field}) {
14017: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14018: push(@{$changes{'cancreate'}},$item);
14019: }
14020: last;
14021: }
14022: }
14023: }
14024: }
1.224 raeburn 14025: }
14026: }
14027: }
14028: #
14029: # Populate %save_usercreate hash with updates to self-creation configuration.
14030: #
14031: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
14032: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 14033: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 14034: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
14035: if (ref($cancreate{'notify'}) eq 'HASH') {
14036: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
14037: }
1.236 raeburn 14038: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
14039: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
14040: }
1.303 raeburn 14041: if (ref($cancreate{'emailverified'}) eq 'HASH') {
14042: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
14043: }
1.305 raeburn 14044: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
14045: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
14046: }
1.303 raeburn 14047: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
14048: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
14049: }
1.224 raeburn 14050: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
14051: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
14052: }
1.240 raeburn 14053: if (ref($cancreate{'shibenv'}) eq 'HASH') {
14054: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
14055: }
1.224 raeburn 14056: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 14057: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 14058:
14059: my %userconfig_hash = (
14060: usercreation => \%save_usercreate,
14061: usermodification => \%save_usermodify,
1.305 raeburn 14062: inststatus => \%save_inststatus,
1.224 raeburn 14063: );
1.305 raeburn 14064:
1.224 raeburn 14065: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
14066: $dom);
14067: #
1.305 raeburn 14068: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 14069: #
1.27 raeburn 14070: if ($putresult eq 'ok') {
14071: if (keys(%changes) > 0) {
14072: $resulttext = &mt('Changes made:').'<ul>';
14073: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 14074: my %lt = &selfcreation_types();
1.34 raeburn 14075: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 14076: my $chgtext = '';
1.45 raeburn 14077: if ($type eq 'selfcreate') {
1.50 raeburn 14078: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 14079: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 14080: } else {
1.224 raeburn 14081: $chgtext .= &mt('Self-creation of a new account is permitted for:').
14082: '<ul>';
1.50 raeburn 14083: foreach my $case (@{$cancreate{$type}}) {
14084: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
14085: }
14086: $chgtext .= '</ul>';
1.100 raeburn 14087: if (ref($cancreate{$type}) eq 'ARRAY') {
14088: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
14089: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
14090: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 14091: $chgtext .= '<span class="LC_warning">'.
14092: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
14093: '</span><br />';
14094: }
14095: }
14096: }
14097: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 14098: if (!@statuses) {
14099: $chgtext .= '<span class="LC_warning">'.
14100: &mt("However, e-mail verification is currently set to 'unavailable' for all user types (including 'other'), so self-creation of accounts is not possible for non-institutional log-in.").
14101: '</span><br />';
1.303 raeburn 14102:
1.100 raeburn 14103: }
14104: }
14105: }
1.43 raeburn 14106: }
1.240 raeburn 14107: } elsif ($type eq 'shibenv') {
14108: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 14109: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 14110: } else {
14111: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
14112: '<ul>';
14113: foreach my $field (@shibfields) {
14114: next if ($cancreate{$type}{$field} eq '');
14115: if ($field eq 'inststatus') {
14116: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
14117: } else {
14118: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
14119: }
14120: }
14121: $chgtext .= '</ul>';
1.303 raeburn 14122: }
1.93 raeburn 14123: } elsif ($type eq 'statustocreate') {
1.96 raeburn 14124: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
14125: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
14126: if (@{$cancreate{'selfcreate'}} > 0) {
14127: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 14128: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 14129: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 14130: $chgtext .= '<br />'.
14131: '<span class="LC_warning">'.
14132: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
14133: '</span>';
14134: }
1.303 raeburn 14135: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 14136: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 14137: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
14138: } else {
14139: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
14140: }
14141: $chgtext .= '<ul>';
14142: foreach my $case (@{$cancreate{$type}}) {
14143: if ($case eq 'default') {
14144: $chgtext .= '<li>'.$othertitle.'</li>';
14145: } else {
1.303 raeburn 14146: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 14147: }
14148: }
1.100 raeburn 14149: $chgtext .= '</ul>';
14150: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 14151: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 14152: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
14153: '</span>';
1.100 raeburn 14154: }
14155: }
14156: } else {
14157: if (@{$cancreate{$type}} == 0) {
14158: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
14159: } else {
14160: $chgtext .= &mt('Although institutional affiliations permitted to create accounts were changed, self creation of accounts is not currently permitted for any authentication types.');
1.93 raeburn 14161: }
14162: }
1.303 raeburn 14163: $chgtext .= '<br />';
1.93 raeburn 14164: }
1.236 raeburn 14165: } elsif ($type eq 'selfcreateprocessing') {
14166: my %choices = &Apache::lonlocal::texthash (
14167: automatic => 'Automatic approval',
14168: approval => 'Queued for approval',
14169: );
1.305 raeburn 14170: if (@types) {
14171: if (@statuses) {
1.303 raeburn 14172: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 14173: '<ul>';
1.305 raeburn 14174: foreach my $status (@statuses) {
14175: if ($status eq 'default') {
14176: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 14177: } else {
1.305 raeburn 14178: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 14179: }
14180: }
14181: $chgtext .= '</ul>';
14182: }
14183: } else {
14184: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
14185: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
14186: }
14187: } elsif ($type eq 'emailverified') {
14188: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 14189: all => 'Same as e-mail',
14190: first => 'Omit @domain',
14191: free => 'Free to choose',
1.303 raeburn 14192: );
1.305 raeburn 14193: if (@types) {
14194: if (@statuses) {
1.303 raeburn 14195: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
14196: '<ul>';
1.305 raeburn 14197: foreach my $status (@statuses) {
1.303 raeburn 14198: if ($type eq 'default') {
1.305 raeburn 14199: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 14200: } else {
1.305 raeburn 14201: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 14202: }
14203: }
14204: $chgtext .= '</ul>';
14205: }
14206: } else {
1.305 raeburn 14207: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 14208: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 14209: }
1.305 raeburn 14210: } elsif ($type eq 'emailoptions') {
14211: my %options = &Apache::lonlocal::texthash (
14212: any => 'Any e-mail',
14213: inst => 'Institutional only',
14214: noninst => 'Non-institutional only',
14215: custom => 'Custom restrictions',
14216: );
14217: if (@types) {
14218: if (@statuses) {
14219: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
14220: '<ul>';
14221: foreach my $status (@statuses) {
14222: if ($type eq 'default') {
14223: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
14224: } else {
14225: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 14226: }
14227: }
1.305 raeburn 14228: $chgtext .= '</ul>';
14229: }
14230: } else {
14231: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
14232: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
14233: } else {
14234: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
14235: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 14236: }
1.305 raeburn 14237: }
14238: } elsif ($type eq 'emaildomain') {
14239: my $output;
14240: if (@statuses) {
14241: foreach my $type (@statuses) {
14242: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
14243: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
14244: if ($type eq 'default') {
14245: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
14246: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
14247: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
14248: } else {
14249: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
14250: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
14251: }
1.303 raeburn 14252: } else {
1.305 raeburn 14253: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
14254: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
14255: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
14256: } else {
14257: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
14258: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
14259: }
1.303 raeburn 14260: }
1.305 raeburn 14261: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
14262: if ($type eq 'default') {
14263: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
14264: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
14265: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
14266: } else {
14267: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
14268: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
14269: }
1.303 raeburn 14270: } else {
1.305 raeburn 14271: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
14272: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
14273: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
14274: } else {
14275: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
14276: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
14277: }
1.303 raeburn 14278: }
14279: }
14280: }
14281: }
1.305 raeburn 14282: }
14283: if ($output ne '') {
14284: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
14285: '<ul>'.$output.'</ul>';
1.236 raeburn 14286: }
1.165 raeburn 14287: } elsif ($type eq 'captcha') {
1.224 raeburn 14288: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 14289: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
14290: } else {
14291: my %captchas = &captcha_phrases();
1.224 raeburn 14292: if ($captchas{$savecaptcha{$type}}) {
14293: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 14294: } else {
1.210 raeburn 14295: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 14296: }
14297: }
14298: } elsif ($type eq 'recaptchakeys') {
14299: my ($privkey,$pubkey);
1.224 raeburn 14300: if (ref($savecaptcha{$type}) eq 'HASH') {
14301: $pubkey = $savecaptcha{$type}{'public'};
14302: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 14303: }
14304: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
14305: if (!$pubkey) {
14306: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
14307: } else {
14308: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
14309: }
14310: if (!$privkey) {
14311: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
14312: } else {
14313: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
14314: }
14315: $chgtext .= '</ul>';
1.269 raeburn 14316: } elsif ($type eq 'recaptchaversion') {
14317: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 14318: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 14319: }
1.224 raeburn 14320: } elsif ($type eq 'emailusername') {
14321: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 14322: if (@statuses) {
14323: foreach my $type (@statuses) {
1.228 raeburn 14324: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
14325: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 14326: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 14327: '<ul>';
14328: foreach my $field (@{$infofields}) {
14329: if ($cancreate{'emailusername'}{$type}{$field}) {
14330: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
14331: }
14332: }
1.245 raeburn 14333: $chgtext .= '</ul>';
14334: } else {
1.303 raeburn 14335: $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
1.228 raeburn 14336: }
14337: } else {
1.303 raeburn 14338: $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
1.224 raeburn 14339: }
14340: }
14341: }
14342: }
14343: } elsif ($type eq 'notify') {
1.303 raeburn 14344: my $numapprove = 0;
1.224 raeburn 14345: if (ref($changes{'cancreate'}) eq 'ARRAY') {
14346: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
14347: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 14348: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
14349: $numapprove ++;
1.224 raeburn 14350: }
14351: }
1.43 raeburn 14352: }
1.303 raeburn 14353: unless ($numapprove) {
14354: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
14355: }
1.34 raeburn 14356: }
1.224 raeburn 14357: if ($chgtext) {
14358: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 14359: }
14360: }
14361: }
1.305 raeburn 14362: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 14363: my ($emailrules,$emailruleorder) =
14364: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 14365: foreach my $type (@{$changes{'email_rule'}}) {
14366: if (ref($email_rule{$type}) eq 'ARRAY') {
14367: my $chgtext = '<ul>';
14368: foreach my $rule (@{$email_rule{$type}}) {
14369: if (ref($emailrules->{$rule}) eq 'HASH') {
14370: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
14371: }
14372: }
14373: $chgtext .= '</ul>';
1.310 raeburn 14374: my $typename;
1.305 raeburn 14375: if (@types) {
14376: if ($type eq 'default') {
14377: $typename = $othertitle;
14378: } else {
14379: $typename = $usertypes{$type};
14380: }
14381: $chgtext .= &mt('(Affiliation: [_1])',$typename);
14382: }
14383: if (@{$email_rule{$type}} > 0) {
14384: $resulttext .= '<li>'.
14385: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
14386: $usertypes{$type}).
14387: $chgtext.
14388: '</li>';
14389: } else {
14390: $resulttext .= '<li>'.
1.310 raeburn 14391: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
1.305 raeburn 14392: '</li>'.
1.310 raeburn 14393: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 14394: }
1.43 raeburn 14395: }
14396: }
1.305 raeburn 14397: }
14398: if (ref($changes{'inststatus'}) eq 'ARRAY') {
14399: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
14400: if (@{$save_inststatus{'inststatusguest'}} > 0) {
14401: my $chgtext = '<ul>';
14402: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
14403: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
14404: }
14405: $chgtext .= '</ul>';
14406: $resulttext .= '<li>'.
14407: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
14408: $chgtext.
14409: '</li>';
14410: } else {
14411: $resulttext .= '<li>'.
14412: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
14413: '</li>';
14414: }
1.43 raeburn 14415: }
14416: }
1.224 raeburn 14417: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
14418: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
14419: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14420: foreach my $type (@{$changes{'selfcreate'}}) {
14421: my $typename = $type;
1.303 raeburn 14422: if (keys(%usertypes) > 0) {
14423: if ($usertypes{$type} ne '') {
14424: $typename = $usertypes{$type};
1.224 raeburn 14425: }
14426: }
14427: my @modifiable;
14428: $resulttext .= '<li>'.
14429: &mt('Self-creation of account by users with status: [_1]',
14430: '<span class="LC_cusr_emph">'.$typename.'</span>').
14431: ' - '.&mt('modifiable fields (if institutional data blank): ');
14432: foreach my $field (@fields) {
14433: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
14434: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 14435: }
14436: }
1.224 raeburn 14437: if (@modifiable > 0) {
14438: $resulttext .= join(', ',@modifiable);
1.43 raeburn 14439: } else {
1.224 raeburn 14440: $resulttext .= &mt('none');
1.43 raeburn 14441: }
1.224 raeburn 14442: $resulttext .= '</li>';
1.28 raeburn 14443: }
1.224 raeburn 14444: $resulttext .= '</ul></li>';
1.28 raeburn 14445: }
1.27 raeburn 14446: $resulttext .= '</ul>';
1.305 raeburn 14447: my $cachetime = 24*60*60;
14448: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
14449: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14450: if (ref($lastactref) eq 'HASH') {
14451: $lastactref->{'domdefaults'} = 1;
14452: }
1.27 raeburn 14453: } else {
1.224 raeburn 14454: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 14455: }
14456: } else {
14457: $resulttext = '<span class="LC_error">'.
1.23 raeburn 14458: &mt('An error occurred: [_1]',$putresult).'</span>';
14459: }
1.43 raeburn 14460: if ($warningmsg ne '') {
14461: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
14462: }
1.23 raeburn 14463: return $resulttext;
14464: }
14465:
1.165 raeburn 14466: sub process_captcha {
14467: my ($container,$changes,$newsettings,$current) = @_;
14468: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
14469: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
14470: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
14471: $newsettings->{'captcha'} = 'original';
14472: }
14473: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 14474: if ($container eq 'cancreate') {
1.169 raeburn 14475: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14476: push(@{$changes->{'cancreate'}},'captcha');
14477: } elsif (!defined($changes->{'cancreate'})) {
14478: $changes->{'cancreate'} = ['captcha'];
14479: }
14480: } else {
14481: $changes->{'captcha'} = 1;
1.165 raeburn 14482: }
14483: }
1.269 raeburn 14484: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 14485: if ($newsettings->{'captcha'} eq 'recaptcha') {
14486: $newpub = $env{'form.'.$container.'_recaptchapub'};
14487: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 14488: $newpub =~ s/[^\w\-]//g;
14489: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 14490: $newsettings->{'recaptchakeys'} = {
14491: public => $newpub,
14492: private => $newpriv,
14493: };
1.269 raeburn 14494: $newversion = $env{'form.'.$container.'_recaptchaversion'};
14495: $newversion =~ s/\D//g;
14496: if ($newversion ne '2') {
14497: $newversion = 1;
14498: }
14499: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 14500: }
14501: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
14502: $currpub = $current->{'recaptchakeys'}{'public'};
14503: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 14504: unless ($newsettings->{'captcha'} eq 'recaptcha') {
14505: $newsettings->{'recaptchakeys'} = {
14506: public => '',
14507: private => '',
14508: }
14509: }
1.165 raeburn 14510: }
1.269 raeburn 14511: if ($current->{'captcha'} eq 'recaptcha') {
14512: $currversion = $current->{'recaptchaversion'};
14513: if ($currversion ne '2') {
14514: $currversion = 1;
14515: }
14516: }
14517: if ($currversion ne $newversion) {
14518: if ($container eq 'cancreate') {
14519: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14520: push(@{$changes->{'cancreate'}},'recaptchaversion');
14521: } elsif (!defined($changes->{'cancreate'})) {
14522: $changes->{'cancreate'} = ['recaptchaversion'];
14523: }
14524: } else {
14525: $changes->{'recaptchaversion'} = 1;
14526: }
14527: }
1.165 raeburn 14528: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 14529: if ($container eq 'cancreate') {
14530: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14531: push(@{$changes->{'cancreate'}},'recaptchakeys');
14532: } elsif (!defined($changes->{'cancreate'})) {
14533: $changes->{'cancreate'} = ['recaptchakeys'];
14534: }
14535: } else {
1.210 raeburn 14536: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 14537: }
14538: }
14539: return;
14540: }
14541:
1.33 raeburn 14542: sub modify_usermodification {
14543: my ($dom,%domconfig) = @_;
1.224 raeburn 14544: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 14545: if (ref($domconfig{'usermodification'}) eq 'HASH') {
14546: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 14547: if ($key eq 'selfcreate') {
14548: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
14549: } else {
14550: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
14551: }
1.33 raeburn 14552: }
14553: }
1.224 raeburn 14554: my @contexts = ('author','course');
1.33 raeburn 14555: my %context_title = (
14556: author => 'In author context',
14557: course => 'In course context',
14558: );
14559: my @fields = ('lastname','firstname','middlename','generation',
14560: 'permanentemail','id');
14561: my %roles = (
14562: author => ['ca','aa'],
14563: course => ['st','ep','ta','in','cr'],
14564: );
14565: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14566: foreach my $context (@contexts) {
14567: foreach my $role (@{$roles{$context}}) {
14568: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
14569: foreach my $item (@fields) {
14570: if (grep(/^\Q$item\E$/,@modifiable)) {
14571: $modifyhash{$context}{$role}{$item} = 1;
14572: } else {
14573: $modifyhash{$context}{$role}{$item} = 0;
14574: }
14575: }
14576: }
14577: if (ref($curr_usermodification{$context}) eq 'HASH') {
14578: foreach my $role (@{$roles{$context}}) {
14579: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
14580: foreach my $field (@fields) {
14581: if ($modifyhash{$context}{$role}{$field} ne
14582: $curr_usermodification{$context}{$role}{$field}) {
14583: push(@{$changes{$context}},$role);
14584: last;
14585: }
14586: }
14587: }
14588: }
14589: } else {
14590: foreach my $context (@contexts) {
14591: foreach my $role (@{$roles{$context}}) {
14592: push(@{$changes{$context}},$role);
14593: }
14594: }
14595: }
14596: }
14597: my %usermodification_hash = (
14598: usermodification => \%modifyhash,
14599: );
14600: my $putresult = &Apache::lonnet::put_dom('configuration',
14601: \%usermodification_hash,$dom);
14602: if ($putresult eq 'ok') {
14603: if (keys(%changes) > 0) {
14604: $resulttext = &mt('Changes made: ').'<ul>';
14605: foreach my $context (@contexts) {
14606: if (ref($changes{$context}) eq 'ARRAY') {
14607: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
14608: if (ref($changes{$context}) eq 'ARRAY') {
14609: foreach my $role (@{$changes{$context}}) {
14610: my $rolename;
1.224 raeburn 14611: if ($role eq 'cr') {
14612: $rolename = &mt('Custom');
1.33 raeburn 14613: } else {
1.224 raeburn 14614: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 14615: }
14616: my @modifiable;
1.224 raeburn 14617: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 14618: foreach my $field (@fields) {
14619: if ($modifyhash{$context}{$role}{$field}) {
14620: push(@modifiable,$fieldtitles{$field});
14621: }
14622: }
14623: if (@modifiable > 0) {
14624: $resulttext .= join(', ',@modifiable);
14625: } else {
14626: $resulttext .= &mt('none');
14627: }
14628: $resulttext .= '</li>';
14629: }
14630: $resulttext .= '</ul></li>';
14631: }
14632: }
14633: }
14634: $resulttext .= '</ul>';
14635: } else {
14636: $resulttext = &mt('No changes made to user modification settings');
14637: }
14638: } else {
14639: $resulttext = '<span class="LC_error">'.
14640: &mt('An error occurred: [_1]',$putresult).'</span>';
14641: }
14642: return $resulttext;
14643: }
14644:
1.43 raeburn 14645: sub modify_defaults {
1.212 raeburn 14646: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 14647: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 14648: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 14649: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
14650: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.325 raeburn 14651: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 14652: foreach my $item (@items) {
14653: $newvalues{$item} = $env{'form.'.$item};
14654: if ($item eq 'auth_def') {
14655: if ($newvalues{$item} ne '') {
14656: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
14657: push(@errors,$item);
14658: }
14659: }
14660: } elsif ($item eq 'lang_def') {
14661: if ($newvalues{$item} ne '') {
14662: if ($newvalues{$item} =~ /^(\w+)/) {
14663: my $langcode = $1;
1.103 raeburn 14664: if ($langcode ne 'x_chef') {
14665: if (code2language($langcode) eq '') {
14666: push(@errors,$item);
14667: }
1.43 raeburn 14668: }
14669: } else {
14670: push(@errors,$item);
14671: }
14672: }
1.54 raeburn 14673: } elsif ($item eq 'timezone_def') {
14674: if ($newvalues{$item} ne '') {
1.62 raeburn 14675: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 14676: push(@errors,$item);
14677: }
14678: }
1.68 raeburn 14679: } elsif ($item eq 'datelocale_def') {
14680: if ($newvalues{$item} ne '') {
14681: my @datelocale_ids = DateTime::Locale->ids();
14682: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
14683: push(@errors,$item);
14684: }
14685: }
1.141 raeburn 14686: } elsif ($item eq 'portal_def') {
14687: if ($newvalues{$item} ne '') {
14688: 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])\/?$/) {
14689: push(@errors,$item);
14690: }
14691: }
1.294 raeburn 14692: } elsif ($item eq 'intauth_cost') {
14693: if ($newvalues{$item} ne '') {
14694: if ($newvalues{$item} =~ /\D/) {
14695: push(@errors,$item);
14696: }
14697: }
14698: } elsif ($item eq 'intauth_check') {
14699: if ($newvalues{$item} ne '') {
14700: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
14701: push(@errors,$item);
14702: }
14703: }
14704: } elsif ($item eq 'intauth_switch') {
14705: if ($newvalues{$item} ne '') {
14706: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
14707: push(@errors,$item);
14708: }
14709: }
1.43 raeburn 14710: }
14711: if (grep(/^\Q$item\E$/,@errors)) {
14712: $newvalues{$item} = $domdefaults{$item};
14713: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
14714: $changes{$item} = 1;
14715: }
1.72 raeburn 14716: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 14717: }
14718: my %defaults_hash = (
1.72 raeburn 14719: defaults => \%newvalues,
14720: );
1.43 raeburn 14721: my $title = &defaults_titles();
1.236 raeburn 14722:
14723: my $currinststatus;
14724: if (ref($domconfig{'inststatus'}) eq 'HASH') {
14725: $currinststatus = $domconfig{'inststatus'};
14726: } else {
14727: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
14728: $currinststatus = {
14729: inststatustypes => $usertypes,
14730: inststatusorder => $types,
14731: inststatusguest => [],
14732: };
14733: }
14734: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
14735: my @allpos;
14736: my %alltypes;
1.305 raeburn 14737: my @inststatusguest;
14738: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
14739: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
14740: unless (grep(/^\Q$type\E$/,@todelete)) {
14741: push(@inststatusguest,$type);
14742: }
14743: }
14744: }
14745: my ($currtitles,$currorder);
1.236 raeburn 14746: if (ref($currinststatus) eq 'HASH') {
14747: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
14748: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
14749: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
14750: if ($currinststatus->{inststatustypes}->{$type} ne '') {
14751: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
14752: }
14753: }
14754: unless (grep(/^\Q$type\E$/,@todelete)) {
14755: my $position = $env{'form.inststatus_pos_'.$type};
14756: $position =~ s/\D+//g;
14757: $allpos[$position] = $type;
14758: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
14759: $alltypes{$type} =~ s/`//g;
14760: }
14761: }
14762: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
14763: $currtitles =~ s/,$//;
14764: }
14765: }
14766: if ($env{'form.addinststatus'}) {
14767: my $newtype = $env{'form.addinststatus'};
14768: $newtype =~ s/\W//g;
14769: unless (exists($alltypes{$newtype})) {
14770: $alltypes{$newtype} = $env{'form.addinststatus_title'};
14771: $alltypes{$newtype} =~ s/`//g;
14772: my $position = $env{'form.addinststatus_pos'};
14773: $position =~ s/\D+//g;
14774: if ($position ne '') {
14775: $allpos[$position] = $newtype;
14776: }
14777: }
14778: }
1.305 raeburn 14779: my @orderedstatus;
1.236 raeburn 14780: foreach my $type (@allpos) {
14781: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
14782: push(@orderedstatus,$type);
14783: }
14784: }
14785: foreach my $type (keys(%alltypes)) {
14786: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
14787: delete($alltypes{$type});
14788: }
14789: }
14790: $defaults_hash{'inststatus'} = {
14791: inststatustypes => \%alltypes,
14792: inststatusorder => \@orderedstatus,
1.305 raeburn 14793: inststatusguest => \@inststatusguest,
1.236 raeburn 14794: };
14795: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
14796: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
14797: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
14798: }
14799: }
14800: if ($currorder ne join(',',@orderedstatus)) {
14801: $changes{'inststatus'}{'inststatusorder'} = 1;
14802: }
14803: my $newtitles;
14804: foreach my $item (@orderedstatus) {
14805: $newtitles .= $alltypes{$item}.',';
14806: }
14807: $newtitles =~ s/,$//;
14808: if ($currtitles ne $newtitles) {
14809: $changes{'inststatus'}{'inststatustypes'} = 1;
14810: }
1.43 raeburn 14811: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
14812: $dom);
14813: if ($putresult eq 'ok') {
14814: if (keys(%changes) > 0) {
14815: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 14816: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 14817: 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";
14818: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 14819: if ($item eq 'inststatus') {
14820: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 14821: if (@orderedstatus) {
1.236 raeburn 14822: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
14823: foreach my $type (@orderedstatus) {
14824: $resulttext .= $alltypes{$type}.', ';
14825: }
14826: $resulttext =~ s/, $//;
14827: $resulttext .= '</li>';
1.305 raeburn 14828: } else {
14829: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 14830: }
14831: }
14832: } else {
14833: my $value = $env{'form.'.$item};
14834: if ($value eq '') {
14835: $value = &mt('none');
14836: } elsif ($item eq 'auth_def') {
14837: my %authnames = &authtype_names();
14838: my %shortauth = (
14839: internal => 'int',
14840: krb4 => 'krb4',
14841: krb5 => 'krb5',
14842: localauth => 'loc',
1.325 raeburn 14843: lti => 'lti',
1.236 raeburn 14844: );
14845: $value = $authnames{$shortauth{$value}};
1.294 raeburn 14846: } elsif ($item eq 'intauth_switch') {
14847: my %optiondesc = &Apache::lonlocal::texthash (
14848: 0 => 'No',
14849: 1 => 'Yes',
14850: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
14851: );
14852: if ($value =~ /^(0|1|2)$/) {
14853: $value = $optiondesc{$value};
14854: } else {
14855: $value = &mt('none -- defaults to No');
14856: }
14857: } elsif ($item eq 'intauth_check') {
14858: my %optiondesc = &Apache::lonlocal::texthash (
14859: 0 => 'No',
14860: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
14861: 2 => 'Yes, disallow login if stored cost is less than domain default',
14862: );
14863: if ($value =~ /^(0|1|2)$/) {
14864: $value = $optiondesc{$value};
14865: } else {
14866: $value = &mt('none -- defaults to No');
14867: }
1.236 raeburn 14868: }
14869: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
14870: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 14871: }
14872: }
14873: $resulttext .= '</ul>';
14874: $mailmsgtext .= "\n";
14875: my $cachetime = 24*60*60;
1.72 raeburn 14876: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 14877: if (ref($lastactref) eq 'HASH') {
14878: $lastactref->{'domdefaults'} = 1;
14879: }
1.68 raeburn 14880: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 14881: my $notify = 1;
14882: if (ref($domconfig{'contacts'}) eq 'HASH') {
14883: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
14884: $notify = 0;
14885: }
14886: }
14887: if ($notify) {
14888: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
14889: "LON-CAPA Domain Settings Change - $dom",
14890: $mailmsgtext);
14891: }
1.54 raeburn 14892: }
1.43 raeburn 14893: } else {
1.54 raeburn 14894: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 14895: }
14896: } else {
14897: $resulttext = '<span class="LC_error">'.
14898: &mt('An error occurred: [_1]',$putresult).'</span>';
14899: }
14900: if (@errors > 0) {
14901: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
14902: foreach my $item (@errors) {
14903: $resulttext .= ' "'.$title->{$item}.'",';
14904: }
14905: $resulttext =~ s/,$//;
14906: }
14907: return $resulttext;
14908: }
14909:
1.46 raeburn 14910: sub modify_scantron {
1.205 raeburn 14911: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 14912: my ($resulttext,%confhash,%changes,$errors);
14913: my $custom = 'custom.tab';
14914: my $default = 'default.tab';
14915: my $servadm = $r->dir_config('lonAdmEMail');
14916: my ($configuserok,$author_ok,$switchserver) =
14917: &config_check($dom,$confname,$servadm);
14918: if ($env{'form.scantronformat.filename'} ne '') {
14919: my $error;
14920: if ($configuserok eq 'ok') {
14921: if ($switchserver) {
1.130 raeburn 14922: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 14923: } else {
14924: if ($author_ok eq 'ok') {
14925: my ($result,$scantronurl) =
14926: &publishlogo($r,'upload','scantronformat',$dom,
14927: $confname,'scantron','','',$custom);
14928: if ($result eq 'ok') {
14929: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 14930: $changes{'scantronformat'} = 1;
1.46 raeburn 14931: } else {
14932: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
14933: }
14934: } else {
14935: $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);
14936: }
14937: }
14938: } else {
14939: $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);
14940: }
14941: if ($error) {
14942: &Apache::lonnet::logthis($error);
14943: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14944: }
14945: }
1.48 raeburn 14946: if (ref($domconfig{'scantron'}) eq 'HASH') {
14947: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
14948: if ($env{'form.scantronformat_del'}) {
14949: $confhash{'scantron'}{'scantronformat'} = '';
14950: $changes{'scantronformat'} = 1;
1.46 raeburn 14951: }
14952: }
14953: }
14954: if (keys(%confhash) > 0) {
14955: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
14956: $dom);
14957: if ($putresult eq 'ok') {
14958: if (keys(%changes) > 0) {
1.48 raeburn 14959: if (ref($confhash{'scantron'}) eq 'HASH') {
14960: $resulttext = &mt('Changes made:').'<ul>';
14961: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 14962: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 14963: } else {
1.130 raeburn 14964: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 14965: }
1.48 raeburn 14966: $resulttext .= '</ul>';
14967: } else {
1.130 raeburn 14968: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 14969: }
14970: $resulttext .= '</ul>';
14971: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 14972: if (ref($lastactref) eq 'HASH') {
14973: $lastactref->{'domainconfig'} = 1;
14974: }
1.46 raeburn 14975: } else {
1.130 raeburn 14976: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 14977: }
14978: } else {
14979: $resulttext = '<span class="LC_error">'.
14980: &mt('An error occurred: [_1]',$putresult).'</span>';
14981: }
14982: } else {
1.130 raeburn 14983: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 14984: }
14985: if ($errors) {
14986: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14987: $errors.'</ul>';
14988: }
14989: return $resulttext;
14990: }
14991:
1.48 raeburn 14992: sub modify_coursecategories {
1.239 raeburn 14993: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 14994: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
14995: $cathash);
1.48 raeburn 14996: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 14997: my @catitems = ('unauth','auth');
14998: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 14999: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 15000: $cathash = $domconfig{'coursecategories'}{'cats'};
15001: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
15002: $changes{'togglecats'} = 1;
15003: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
15004: }
15005: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
15006: $changes{'categorize'} = 1;
15007: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
15008: }
1.120 raeburn 15009: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
15010: $changes{'togglecatscomm'} = 1;
15011: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
15012: }
15013: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
15014: $changes{'categorizecomm'} = 1;
15015: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 15016:
15017: }
15018: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
15019: $changes{'togglecatsplace'} = 1;
15020: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
15021: }
15022: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
15023: $changes{'categorizeplace'} = 1;
15024: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 15025: }
1.238 raeburn 15026: foreach my $item (@catitems) {
15027: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
15028: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
15029: $changes{$item} = 1;
15030: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
15031: }
15032: }
15033: }
1.57 raeburn 15034: } else {
15035: $changes{'togglecats'} = 1;
15036: $changes{'categorize'} = 1;
1.124 raeburn 15037: $changes{'togglecatscomm'} = 1;
15038: $changes{'categorizecomm'} = 1;
1.272 raeburn 15039: $changes{'togglecatsplace'} = 1;
15040: $changes{'categorizeplace'} = 1;
1.87 raeburn 15041: $domconfig{'coursecategories'} = {
15042: togglecats => $env{'form.togglecats'},
15043: categorize => $env{'form.categorize'},
1.124 raeburn 15044: togglecatscomm => $env{'form.togglecatscomm'},
15045: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 15046: togglecatsplace => $env{'form.togglecatsplace'},
15047: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 15048: };
1.238 raeburn 15049: foreach my $item (@catitems) {
15050: if ($env{'form.coursecat_'.$item} ne 'std') {
15051: $changes{$item} = 1;
15052: }
15053: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
15054: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
15055: }
15056: }
1.57 raeburn 15057: }
15058: if (ref($cathash) eq 'HASH') {
15059: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 15060: push (@deletecategory,'instcode::0');
15061: }
1.120 raeburn 15062: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
15063: push(@deletecategory,'communities::0');
15064: }
1.272 raeburn 15065: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
15066: push(@deletecategory,'placement::0');
15067: }
1.48 raeburn 15068: }
1.57 raeburn 15069: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
15070: if (ref($cathash) eq 'HASH') {
1.48 raeburn 15071: if (@deletecategory > 0) {
15072: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 15073: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 15074: foreach my $item (@deletecategory) {
1.57 raeburn 15075: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
15076: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 15077: $deletions{$item} = 1;
1.57 raeburn 15078: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 15079: }
15080: }
15081: }
1.57 raeburn 15082: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 15083: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 15084: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 15085: $reorderings{$item} = 1;
1.57 raeburn 15086: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 15087: }
15088: if ($env{'form.addcategory_name_'.$item} ne '') {
15089: my $newcat = $env{'form.addcategory_name_'.$item};
15090: my $newdepth = $depth+1;
15091: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 15092: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 15093: $adds{$newitem} = 1;
15094: }
15095: if ($env{'form.subcat_'.$item} ne '') {
15096: my $newcat = $env{'form.subcat_'.$item};
15097: my $newdepth = $depth+1;
15098: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 15099: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 15100: $adds{$newitem} = 1;
15101: }
15102: }
15103: }
15104: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 15105: if (ref($cathash) eq 'HASH') {
1.48 raeburn 15106: my $newitem = 'instcode::0';
1.57 raeburn 15107: if ($cathash->{$newitem} eq '') {
15108: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 15109: $adds{$newitem} = 1;
15110: }
15111: } else {
15112: my $newitem = 'instcode::0';
1.57 raeburn 15113: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 15114: $adds{$newitem} = 1;
15115: }
15116: }
1.120 raeburn 15117: if ($env{'form.communities'} eq '1') {
15118: if (ref($cathash) eq 'HASH') {
15119: my $newitem = 'communities::0';
15120: if ($cathash->{$newitem} eq '') {
15121: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
15122: $adds{$newitem} = 1;
15123: }
15124: } else {
15125: my $newitem = 'communities::0';
15126: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
15127: $adds{$newitem} = 1;
15128: }
15129: }
1.272 raeburn 15130: if ($env{'form.placement'} eq '1') {
15131: if (ref($cathash) eq 'HASH') {
15132: my $newitem = 'placement::0';
15133: if ($cathash->{$newitem} eq '') {
15134: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
15135: $adds{$newitem} = 1;
15136: }
15137: } else {
15138: my $newitem = 'placement::0';
15139: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
15140: $adds{$newitem} = 1;
15141: }
15142: }
1.48 raeburn 15143: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 15144: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 15145: ($env{'form.addcategory_name'} ne 'communities') &&
15146: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 15147: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
15148: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
15149: $adds{$newitem} = 1;
15150: }
1.48 raeburn 15151: }
1.57 raeburn 15152: my $putresult;
1.48 raeburn 15153: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
15154: if (keys(%deletions) > 0) {
15155: foreach my $key (keys(%deletions)) {
15156: if ($predelallitems{$key} ne '') {
15157: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
15158: }
15159: }
15160: }
15161: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 15162: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 15163: if (ref($chkcats[0]) eq 'ARRAY') {
15164: my $depth = 0;
15165: my $chg = 0;
15166: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
15167: my $name = $chkcats[0][$i];
15168: my $item;
15169: if ($name eq '') {
15170: $chg ++;
15171: } else {
15172: $item = &escape($name).'::0';
15173: if ($chg) {
1.57 raeburn 15174: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 15175: }
15176: $depth ++;
1.57 raeburn 15177: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 15178: $depth --;
15179: }
15180: }
15181: }
1.57 raeburn 15182: }
15183: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
15184: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 15185: if ($putresult eq 'ok') {
1.57 raeburn 15186: my %title = (
1.120 raeburn 15187: togglecats => 'Show/Hide a course in catalog',
15188: categorize => 'Assign a category to a course',
15189: togglecatscomm => 'Show/Hide a community in catalog',
15190: categorizecomm => 'Assign a category to a community',
1.57 raeburn 15191: );
15192: my %level = (
1.120 raeburn 15193: dom => 'set in Domain ("Modify Course/Community")',
15194: crs => 'set in Course ("Course Configuration")',
15195: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 15196: none => 'No catalog',
15197: std => 'Standard catalog',
15198: domonly => 'Domain-only catalog',
15199: codesrch => 'Code search form',
1.57 raeburn 15200: );
1.48 raeburn 15201: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 15202: if ($changes{'togglecats'}) {
15203: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
15204: }
15205: if ($changes{'categorize'}) {
15206: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 15207: }
1.120 raeburn 15208: if ($changes{'togglecatscomm'}) {
15209: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
15210: }
15211: if ($changes{'categorizecomm'}) {
15212: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
15213: }
1.238 raeburn 15214: if ($changes{'unauth'}) {
15215: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
15216: }
15217: if ($changes{'auth'}) {
15218: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
15219: }
1.57 raeburn 15220: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
15221: my $cathash;
15222: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
15223: $cathash = $domconfig{'coursecategories'}{'cats'};
15224: } else {
15225: $cathash = {};
15226: }
15227: my (@cats,@trails,%allitems);
15228: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
15229: if (keys(%deletions) > 0) {
15230: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
15231: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
15232: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
15233: }
15234: $resulttext .= '</ul></li>';
15235: }
15236: if (keys(%reorderings) > 0) {
15237: my %sort_by_trail;
15238: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
15239: foreach my $key (keys(%reorderings)) {
15240: if ($allitems{$key} ne '') {
15241: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
15242: }
1.48 raeburn 15243: }
1.57 raeburn 15244: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
15245: $resulttext .= '<li>'.$trails[$trail].'</li>';
15246: }
15247: $resulttext .= '</ul></li>';
1.48 raeburn 15248: }
1.57 raeburn 15249: if (keys(%adds) > 0) {
15250: my %sort_by_trail;
15251: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
15252: foreach my $key (keys(%adds)) {
15253: if ($allitems{$key} ne '') {
15254: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
15255: }
15256: }
15257: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
15258: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 15259: }
1.57 raeburn 15260: $resulttext .= '</ul></li>';
1.48 raeburn 15261: }
15262: }
15263: $resulttext .= '</ul>';
1.239 raeburn 15264: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 15265: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
15266: if ($changes{'auth'}) {
15267: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
15268: }
15269: if ($changes{'unauth'}) {
15270: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
15271: }
15272: my $cachetime = 24*60*60;
15273: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 15274: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 15275: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 15276: }
15277: }
1.48 raeburn 15278: } else {
15279: $resulttext = '<span class="LC_error">'.
1.57 raeburn 15280: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 15281: }
15282: } else {
1.120 raeburn 15283: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 15284: }
15285: return $resulttext;
15286: }
15287:
1.69 raeburn 15288: sub modify_serverstatuses {
15289: my ($dom,%domconfig) = @_;
15290: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
15291: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
15292: %currserverstatus = %{$domconfig{'serverstatuses'}};
15293: }
15294: my @pages = &serverstatus_pages();
15295: foreach my $type (@pages) {
15296: $newserverstatus{$type}{'namedusers'} = '';
15297: $newserverstatus{$type}{'machines'} = '';
15298: if (defined($env{'form.'.$type.'_namedusers'})) {
15299: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
15300: my @okusers;
15301: foreach my $user (@users) {
15302: my ($uname,$udom) = split(/:/,$user);
15303: if (($udom =~ /^$match_domain$/) &&
15304: (&Apache::lonnet::domain($udom)) &&
15305: ($uname =~ /^$match_username$/)) {
15306: if (!grep(/^\Q$user\E/,@okusers)) {
15307: push(@okusers,$user);
15308: }
15309: }
15310: }
15311: if (@okusers > 0) {
15312: @okusers = sort(@okusers);
15313: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
15314: }
15315: }
15316: if (defined($env{'form.'.$type.'_machines'})) {
15317: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
15318: my @okmachines;
15319: foreach my $ip (@machines) {
15320: my @parts = split(/\./,$ip);
15321: next if (@parts < 4);
15322: my $badip = 0;
15323: for (my $i=0; $i<4; $i++) {
15324: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
15325: $badip = 1;
15326: last;
15327: }
15328: }
15329: if (!$badip) {
15330: push(@okmachines,$ip);
15331: }
15332: }
15333: @okmachines = sort(@okmachines);
15334: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
15335: }
15336: }
15337: my %serverstatushash = (
15338: serverstatuses => \%newserverstatus,
15339: );
15340: foreach my $type (@pages) {
1.83 raeburn 15341: foreach my $setting ('namedusers','machines') {
1.84 raeburn 15342: my (@current,@new);
1.83 raeburn 15343: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 15344: if ($currserverstatus{$type}{$setting} ne '') {
15345: @current = split(/,/,$currserverstatus{$type}{$setting});
15346: }
15347: }
15348: if ($newserverstatus{$type}{$setting} ne '') {
15349: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 15350: }
15351: if (@current > 0) {
15352: if (@new > 0) {
15353: foreach my $item (@current) {
15354: if (!grep(/^\Q$item\E$/,@new)) {
15355: $changes{$type}{$setting} = 1;
1.82 raeburn 15356: last;
15357: }
15358: }
1.84 raeburn 15359: foreach my $item (@new) {
15360: if (!grep(/^\Q$item\E$/,@current)) {
15361: $changes{$type}{$setting} = 1;
15362: last;
1.82 raeburn 15363: }
15364: }
15365: } else {
1.83 raeburn 15366: $changes{$type}{$setting} = 1;
1.69 raeburn 15367: }
1.83 raeburn 15368: } elsif (@new > 0) {
15369: $changes{$type}{$setting} = 1;
1.69 raeburn 15370: }
15371: }
15372: }
15373: if (keys(%changes) > 0) {
1.81 raeburn 15374: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 15375: my $putresult = &Apache::lonnet::put_dom('configuration',
15376: \%serverstatushash,$dom);
15377: if ($putresult eq 'ok') {
15378: $resulttext .= &mt('Changes made:').'<ul>';
15379: foreach my $type (@pages) {
1.84 raeburn 15380: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 15381: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 15382: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 15383: if ($newserverstatus{$type}{'namedusers'} eq '') {
15384: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
15385: } else {
15386: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
15387: }
1.84 raeburn 15388: }
15389: if ($changes{$type}{'machines'}) {
1.69 raeburn 15390: if ($newserverstatus{$type}{'machines'} eq '') {
15391: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
15392: } else {
15393: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
15394: }
15395:
15396: }
15397: $resulttext .= '</ul></li>';
15398: }
15399: }
15400: $resulttext .= '</ul>';
15401: } else {
15402: $resulttext = '<span class="LC_error">'.
15403: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
15404:
15405: }
15406: } else {
15407: $resulttext = &mt('No changes made to access to server status pages');
15408: }
15409: return $resulttext;
15410: }
15411:
1.118 jms 15412: sub modify_helpsettings {
1.285 raeburn 15413: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 15414: my ($resulttext,$errors,%changes,%helphash);
15415: my %defaultchecked = ('submitbugs' => 'on');
15416: my @offon = ('off','on');
1.118 jms 15417: my @toggles = ('submitbugs');
1.285 raeburn 15418: my %current = ('submitbugs' => '',
15419: 'adhoc' => {},
15420: );
1.118 jms 15421: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 15422: %current = %{$domconfig{'helpsettings'}};
15423: }
1.285 raeburn 15424: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 15425: foreach my $item (@toggles) {
15426: if ($defaultchecked{$item} eq 'on') {
15427: if ($current{$item} eq '') {
15428: if ($env{'form.'.$item} eq '0') {
15429: $changes{$item} = 1;
15430: }
15431: } elsif ($current{$item} ne $env{'form.'.$item}) {
15432: $changes{$item} = 1;
15433: }
15434: } elsif ($defaultchecked{$item} eq 'off') {
15435: if ($current{$item} eq '') {
15436: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 15437: $changes{$item} = 1;
15438: }
1.282 raeburn 15439: } elsif ($current{$item} ne $env{'form.'.$item}) {
15440: $changes{$item} = 1;
15441: }
15442: }
15443: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
15444: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
15445: }
15446: }
1.285 raeburn 15447: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 15448: my $confname = $dom.'-domainconfig';
15449: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 15450: my (@allpos,%newsettings,%changedprivs,$newrole);
15451: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 15452: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 15453: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 15454: my %lt = &Apache::lonlocal::texthash(
15455: s => 'system',
15456: d => 'domain',
15457: order => 'Display order',
15458: access => 'Role usage',
1.291 raeburn 15459: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 15460: dh => 'All with domain helpdesk role',
15461: da => 'All with domain helpdesk assistant role',
1.285 raeburn 15462: none => 'None',
15463: status => 'Determined based on institutional status',
15464: inc => 'Include all, but exclude specific personnel',
15465: exc => 'Exclude all, but include specific personnel',
15466: );
15467: for (my $num=0; $num<=$maxnum; $num++) {
15468: my ($prefix,$identifier,$rolename,%curr);
15469: if ($num == $maxnum) {
15470: next unless ($env{'form.newcusthelp'} == $maxnum);
15471: $identifier = 'custhelp'.$num;
15472: $prefix = 'helproles_'.$num;
15473: $rolename = $env{'form.custhelpname'.$num};
15474: $rolename=~s/[^A-Za-z0-9]//gs;
15475: next if ($rolename eq '');
15476: next if (exists($existing{'rolesdef_'.$rolename}));
15477: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15478: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15479: $newprivs{'c'},$confname,$dom);
15480: if ($result ne 'ok') {
15481: $errors .= '<li><span class="LC_error">'.
15482: &mt('An error occurred storing the new custom role: [_1]',
15483: $result).'</span></li>';
15484: next;
15485: } else {
15486: $changedprivs{$rolename} = \%newprivs;
15487: $newrole = $rolename;
15488: }
15489: } else {
15490: $prefix = 'helproles_'.$num;
15491: $rolename = $env{'form.'.$prefix};
15492: next if ($rolename eq '');
15493: next unless (exists($existing{'rolesdef_'.$rolename}));
15494: $identifier = 'custhelp'.$num;
15495: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15496: my %currprivs;
1.289 raeburn 15497: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 15498: split(/\_/,$existing{'rolesdef_'.$rolename});
15499: foreach my $level ('c','d','s') {
15500: if ($newprivs{$level} ne $currprivs{$level}) {
15501: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15502: $newprivs{'c'},$confname,$dom);
15503: if ($result ne 'ok') {
15504: $errors .= '<li><span class="LC_error">'.
15505: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
15506: $rolename,$result).'</span></li>';
15507: } else {
15508: $changedprivs{$rolename} = \%newprivs;
15509: }
15510: last;
15511: }
15512: }
15513: if (ref($current{'adhoc'}) eq 'HASH') {
15514: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15515: %curr = %{$current{'adhoc'}{$rolename}};
15516: }
15517: }
15518: }
15519: my $newpos = $env{'form.'.$prefix.'_pos'};
15520: $newpos =~ s/\D+//g;
15521: $allpos[$newpos] = $rolename;
15522: my $newdesc = $env{'form.'.$prefix.'_desc'};
15523: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
15524: if ($curr{'desc'}) {
15525: if ($curr{'desc'} ne $newdesc) {
15526: $changes{'customrole'}{$rolename}{'desc'} = 1;
15527: $newsettings{$rolename}{'desc'} = $newdesc;
15528: }
15529: } elsif ($newdesc ne '') {
15530: $changes{'customrole'}{$rolename}{'desc'} = 1;
15531: $newsettings{$rolename}{'desc'} = $newdesc;
15532: }
15533: my $access = $env{'form.'.$prefix.'_access'};
15534: if (grep(/^\Q$access\E$/,@accesstypes)) {
15535: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
15536: if ($access eq 'status') {
15537: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
15538: if (scalar(@statuses) == 0) {
1.289 raeburn 15539: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 15540: } else {
15541: my (@shownstatus,$numtypes);
15542: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15543: if (ref($types) eq 'ARRAY') {
15544: $numtypes = scalar(@{$types});
15545: foreach my $type (sort(@statuses)) {
15546: if ($type eq 'default') {
15547: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15548: } elsif (grep(/^\Q$type\E$/,@{$types})) {
15549: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15550: push(@shownstatus,$usertypes->{$type});
15551: }
15552: }
15553: }
15554: if (grep(/^default$/,@statuses)) {
15555: push(@shownstatus,$othertitle);
15556: }
15557: if (scalar(@shownstatus) == 1+$numtypes) {
15558: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
15559: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
15560: } else {
15561: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
15562: if (ref($curr{'status'}) eq 'ARRAY') {
15563: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15564: if (@diffs) {
15565: $changes{'customrole'}{$rolename}{$access} = 1;
15566: }
15567: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15568: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 15569: }
1.166 raeburn 15570: }
15571: }
1.285 raeburn 15572: } elsif (($access eq 'inc') || ($access eq 'exc')) {
15573: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
15574: my @newspecstaff;
15575: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15576: foreach my $person (sort(@personnel)) {
15577: if ($domhelpdesk{$person}) {
15578: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
15579: }
15580: }
15581: if (ref($curr{$access}) eq 'ARRAY') {
15582: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15583: if (@diffs) {
15584: $changes{'customrole'}{$rolename}{$access} = 1;
15585: }
15586: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15587: $changes{'customrole'}{$rolename}{$access} = 1;
15588: }
15589: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15590: my ($uname,$udom) = split(/:/,$person);
15591: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
15592: }
15593: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 15594: }
1.285 raeburn 15595: } else {
15596: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
15597: }
15598: unless ($curr{'access'} eq $access) {
15599: $changes{'customrole'}{$rolename}{'access'} = 1;
15600: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 15601: }
15602: }
1.285 raeburn 15603: if (@allpos > 0) {
15604: my $idx = 0;
15605: foreach my $rolename (@allpos) {
15606: if ($rolename ne '') {
15607: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
15608: if (ref($current{'adhoc'}) eq 'HASH') {
15609: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15610: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
15611: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 15612: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 15613: }
15614: }
1.282 raeburn 15615: }
1.285 raeburn 15616: $idx ++;
1.166 raeburn 15617: }
15618: }
1.118 jms 15619: }
1.123 jms 15620: my $putresult;
15621: if (keys(%changes) > 0) {
1.166 raeburn 15622: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 15623: if ($putresult eq 'ok') {
1.285 raeburn 15624: if (ref($helphash{'helpsettings'}) eq 'HASH') {
15625: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
15626: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
15627: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
15628: }
15629: }
15630: my $cachetime = 24*60*60;
15631: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15632: if (ref($lastactref) eq 'HASH') {
15633: $lastactref->{'domdefaults'} = 1;
15634: }
15635: } else {
15636: $errors .= '<li><span class="LC_error">'.
15637: &mt('An error occurred storing the settings: [_1]',
15638: $putresult).'</span></li>';
15639: }
15640: }
15641: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
15642: $resulttext = &mt('Changes made:').'<ul>';
15643: my (%shownprivs,@levelorder);
15644: @levelorder = ('c','d','s');
15645: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 15646: foreach my $item (sort(keys(%changes))) {
15647: if ($item eq 'submitbugs') {
15648: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
15649: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
15650: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 15651: } elsif ($item eq 'customrole') {
15652: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 15653: my @keyorder = ('order','desc','access','status','exc','inc');
15654: my %keytext = &Apache::lonlocal::texthash(
15655: order => 'Order',
15656: desc => 'Role description',
15657: access => 'Role usage',
1.300 droeschl 15658: status => 'Allowed institutional types',
1.285 raeburn 15659: exc => 'Allowed personnel',
15660: inc => 'Disallowed personnel',
15661: );
1.282 raeburn 15662: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 15663: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
15664: if ($role eq $newrole) {
15665: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
15666: $role).'<ul>';
15667: } else {
15668: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15669: $role).'<ul>';
15670: }
15671: foreach my $key (@keyorder) {
15672: if ($changes{'customrole'}{$role}{$key}) {
15673: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
15674: $keytext{$key},$newsettings{$role}{$key}).
15675: '</li>';
15676: }
15677: }
15678: if (ref($changedprivs{$role}) eq 'HASH') {
15679: $shownprivs{$role} = 1;
15680: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
15681: foreach my $level (@levelorder) {
15682: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
15683: next if ($item eq '');
15684: my ($priv) = split(/\&/,$item,2);
15685: if (&Apache::lonnet::plaintext($priv)) {
15686: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
15687: unless ($level eq 'c') {
15688: $resulttext .= ' ('.$lt{$level}.')';
15689: }
15690: $resulttext .= '</li>';
15691: }
15692: }
15693: }
15694: $resulttext .= '</ul>';
15695: }
15696: $resulttext .= '</ul></li>';
15697: }
15698: }
15699: }
15700: }
15701: }
15702: }
15703: if (keys(%changedprivs)) {
15704: foreach my $role (sort(keys(%changedprivs))) {
15705: unless ($shownprivs{$role}) {
15706: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15707: $role).'<ul>'.
15708: '<li>'.&mt('Privileges set to :').'<ul>';
15709: foreach my $level (@levelorder) {
15710: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
15711: next if ($item eq '');
15712: my ($priv) = split(/\&/,$item,2);
15713: if (&Apache::lonnet::plaintext($priv)) {
15714: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
15715: unless ($level eq 'c') {
15716: $resulttext .= ' ('.$lt{$level}.')';
15717: }
15718: $resulttext .= '</li>';
15719: }
1.282 raeburn 15720: }
15721: }
1.285 raeburn 15722: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 15723: }
15724: }
15725: }
1.285 raeburn 15726: $resulttext .= '</ul>';
15727: } else {
15728: $resulttext = &mt('No changes made to help settings');
1.118 jms 15729: }
15730: if ($errors) {
1.168 raeburn 15731: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 15732: $errors.'</ul>';
1.118 jms 15733: }
15734: return $resulttext;
15735: }
15736:
1.121 raeburn 15737: sub modify_coursedefaults {
1.212 raeburn 15738: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 15739: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 15740: my %defaultchecked = (
15741: 'canuse_pdfforms' => 'off',
15742: 'uselcmath' => 'on',
15743: 'usejsme' => 'on'
15744: );
15745: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 15746: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 15747: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
15748: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
15749: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 15750: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 15751: my %staticdefaults = (
15752: anonsurvey_threshold => 10,
15753: uploadquota => 500,
1.257 raeburn 15754: postsubmit => 60,
1.276 raeburn 15755: mysqltables => 172800,
1.198 raeburn 15756: );
1.314 raeburn 15757: my %texoptions = (
15758: MathJax => 'MathJax',
15759: mimetex => &mt('Convert to Images'),
15760: tth => &mt('TeX to HTML'),
15761: );
1.121 raeburn 15762: $defaultshash{'coursedefaults'} = {};
15763:
15764: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
15765: if ($domconfig{'coursedefaults'} eq '') {
15766: $domconfig{'coursedefaults'} = {};
15767: }
15768: }
15769:
15770: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
15771: foreach my $item (@toggles) {
15772: if ($defaultchecked{$item} eq 'on') {
15773: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15774: ($env{'form.'.$item} eq '0')) {
15775: $changes{$item} = 1;
1.192 raeburn 15776: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 15777: $changes{$item} = 1;
15778: }
15779: } elsif ($defaultchecked{$item} eq 'off') {
15780: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15781: ($env{'form.'.$item} eq '1')) {
15782: $changes{$item} = 1;
15783: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
15784: $changes{$item} = 1;
15785: }
15786: }
15787: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
15788: }
1.198 raeburn 15789: foreach my $item (@numbers) {
15790: my ($currdef,$newdef);
1.208 raeburn 15791: $newdef = $env{'form.'.$item};
1.198 raeburn 15792: if ($item eq 'anonsurvey_threshold') {
15793: $currdef = $domconfig{'coursedefaults'}{$item};
15794: $newdef =~ s/\D//g;
15795: if ($newdef eq '' || $newdef < 1) {
15796: $newdef = 1;
15797: }
15798: $defaultshash{'coursedefaults'}{$item} = $newdef;
15799: } else {
1.276 raeburn 15800: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
15801: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
15802: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 15803: }
15804: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 15805: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 15806: }
15807: if ($currdef ne $newdef) {
15808: my $staticdef;
15809: if ($item eq 'anonsurvey_threshold') {
15810: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
15811: $changes{$item} = 1;
15812: }
1.276 raeburn 15813: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 15814: my $setting = $1;
1.276 raeburn 15815: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
15816: $changes{$setting} = 1;
1.198 raeburn 15817: }
15818: }
1.139 raeburn 15819: }
15820: }
1.314 raeburn 15821: my $texengine;
15822: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
15823: $texengine = $env{'form.texengine'};
15824: if ($defaultshash{'coursedefaults'}{'texengine'} eq '') {
15825: unless ($texengine eq 'MathJax') {
15826: $changes{'texengine'} = 1;
15827: }
15828: } elsif ($defaultshash{'coursedefaults'}{'texengine'} ne $texengine) {
15829: $changes{'texengine'} = 1;
15830: }
15831: }
15832: if ($texengine ne '') {
15833: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
15834: }
1.264 raeburn 15835: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
15836: my @currclonecode;
15837: if (ref($currclone) eq 'HASH') {
15838: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
15839: @currclonecode = @{$currclone->{'instcode'}};
15840: }
15841: }
15842: my $newclone;
1.289 raeburn 15843: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 15844: $newclone = $env{'form.canclone'};
15845: }
15846: if ($newclone eq 'instcode') {
15847: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
15848: my (%codedefaults,@code_order,@clonecode);
15849: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
15850: \@code_order);
15851: foreach my $item (@code_order) {
15852: if (grep(/^\Q$item\E$/,@newcodes)) {
15853: push(@clonecode,$item);
15854: }
15855: }
15856: if (@clonecode) {
15857: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
15858: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
15859: if (@diffs) {
15860: $changes{'canclone'} = 1;
15861: }
15862: } else {
15863: $newclone eq '';
15864: }
15865: } elsif ($newclone ne '') {
1.289 raeburn 15866: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
15867: }
1.264 raeburn 15868: if ($newclone ne $currclone) {
15869: $changes{'canclone'} = 1;
15870: }
1.257 raeburn 15871: my %credits;
15872: foreach my $type (@types) {
15873: unless ($type eq 'community') {
15874: $credits{$type} = $env{'form.'.$type.'_credits'};
15875: $credits{$type} =~ s/[^\d.]+//g;
15876: }
15877: }
15878: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
15879: ($env{'form.coursecredits'} eq '1')) {
15880: $changes{'coursecredits'} = 1;
15881: foreach my $type (keys(%credits)) {
15882: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15883: }
15884: } else {
1.289 raeburn 15885: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 15886: foreach my $type (@types) {
15887: unless ($type eq 'community') {
1.289 raeburn 15888: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 15889: $changes{'coursecredits'} = 1;
15890: }
15891: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15892: }
15893: }
15894: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15895: foreach my $type (@types) {
15896: unless ($type eq 'community') {
15897: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
15898: $changes{'coursecredits'} = 1;
15899: last;
15900: }
15901: }
15902: }
15903: }
15904: }
15905: if ($env{'form.postsubmit'} eq '1') {
15906: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
15907: my %currtimeout;
15908: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15909: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
15910: $changes{'postsubmit'} = 1;
15911: }
15912: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15913: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
15914: }
15915: } else {
15916: $changes{'postsubmit'} = 1;
15917: }
15918: foreach my $type (@types) {
15919: my $timeout = $env{'form.'.$type.'_timeout'};
15920: $timeout =~ s/\D//g;
15921: if ($timeout == $staticdefaults{'postsubmit'}) {
15922: $timeout = '';
15923: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
15924: $timeout = '0';
15925: }
15926: unless ($timeout eq '') {
15927: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
15928: }
15929: if (exists($currtimeout{$type})) {
15930: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 15931: $changes{'postsubmit'} = 1;
1.257 raeburn 15932: }
15933: } elsif ($timeout ne '') {
15934: $changes{'postsubmit'} = 1;
15935: }
15936: }
15937: } else {
15938: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
15939: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15940: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
15941: $changes{'postsubmit'} = 1;
15942: }
15943: } else {
15944: $changes{'postsubmit'} = 1;
15945: }
1.192 raeburn 15946: }
1.121 raeburn 15947: }
15948: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
15949: $dom);
15950: if ($putresult eq 'ok') {
15951: if (keys(%changes) > 0) {
1.213 raeburn 15952: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 15953: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 15954: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.314 raeburn 15955: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
15956: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','texengine') {
1.257 raeburn 15957: if ($changes{$item}) {
15958: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
15959: }
1.289 raeburn 15960: }
1.192 raeburn 15961: if ($changes{'coursecredits'}) {
15962: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 15963: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
15964: $domdefaults{$type.'credits'} =
15965: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
15966: }
15967: }
15968: }
15969: if ($changes{'postsubmit'}) {
15970: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15971: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
15972: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15973: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
15974: $domdefaults{$type.'postsubtimeout'} =
15975: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15976: }
15977: }
1.192 raeburn 15978: }
15979: }
1.198 raeburn 15980: if ($changes{'uploadquota'}) {
15981: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15982: foreach my $type (@types) {
15983: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
15984: }
15985: }
15986: }
1.264 raeburn 15987: if ($changes{'canclone'}) {
15988: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15989: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15990: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
15991: if (@clonecodes) {
15992: $domdefaults{'canclone'} = join('+',@clonecodes);
15993: }
15994: }
15995: } else {
15996: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
15997: }
15998: }
1.121 raeburn 15999: my $cachetime = 24*60*60;
16000: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 16001: if (ref($lastactref) eq 'HASH') {
16002: $lastactref->{'domdefaults'} = 1;
16003: }
1.121 raeburn 16004: }
16005: $resulttext = &mt('Changes made:').'<ul>';
16006: foreach my $item (sort(keys(%changes))) {
16007: if ($item eq 'canuse_pdfforms') {
16008: if ($env{'form.'.$item} eq '1') {
16009: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
16010: } else {
16011: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
16012: }
1.257 raeburn 16013: } elsif ($item eq 'uselcmath') {
16014: if ($env{'form.'.$item} eq '1') {
16015: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
16016: } else {
16017: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
16018: }
16019: } elsif ($item eq 'usejsme') {
16020: if ($env{'form.'.$item} eq '1') {
16021: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
16022: } else {
1.289 raeburn 16023: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 16024: }
1.314 raeburn 16025: } elsif ($item eq 'texengine') {
16026: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
16027: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
16028: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
16029: }
1.139 raeburn 16030: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 16031: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 16032: } elsif ($item eq 'uploadquota') {
16033: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
16034: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
16035: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
16036: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 16037: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 16038: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 16039: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
16040: '</ul>'.
16041: '</li>';
16042: } else {
16043: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
16044: }
1.276 raeburn 16045: } elsif ($item eq 'mysqltables') {
16046: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
16047: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
16048: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
16049: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
16050: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
16051: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
16052: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
16053: '</ul>'.
16054: '</li>';
16055: } else {
16056: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
16057: }
1.257 raeburn 16058: } elsif ($item eq 'postsubmit') {
16059: if ($domdefaults{'postsubmit'} eq 'off') {
16060: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
16061: } else {
16062: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 16063: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 16064: $resulttext .= &mt('durations:').'<ul>';
16065: foreach my $type (@types) {
16066: $resulttext .= '<li>';
16067: my $timeout;
16068: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
16069: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
16070: }
16071: my $display;
16072: if ($timeout eq '0') {
16073: $display = &mt('unlimited');
16074: } elsif ($timeout eq '') {
16075: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
16076: } else {
16077: $display = &mt('[quant,_1,second]',$timeout);
16078: }
16079: if ($type eq 'community') {
16080: $resulttext .= &mt('Communities');
16081: } elsif ($type eq 'official') {
16082: $resulttext .= &mt('Official courses');
16083: } elsif ($type eq 'unofficial') {
16084: $resulttext .= &mt('Unofficial courses');
16085: } elsif ($type eq 'textbook') {
16086: $resulttext .= &mt('Textbook courses');
1.271 raeburn 16087: } elsif ($type eq 'placement') {
16088: $resulttext .= &mt('Placement tests');
1.257 raeburn 16089: }
16090: $resulttext .= ' -- '.$display.'</li>';
16091: }
16092: $resulttext .= '</ul>';
16093: }
1.289 raeburn 16094: $resulttext .= '</li>';
1.257 raeburn 16095: }
1.192 raeburn 16096: } elsif ($item eq 'coursecredits') {
16097: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
16098: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 16099: ($domdefaults{'unofficialcredits'} eq '') &&
16100: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 16101: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
16102: } else {
16103: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
16104: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
16105: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 16106: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 16107: '</ul>'.
16108: '</li>';
16109: }
16110: } else {
16111: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
16112: }
1.264 raeburn 16113: } elsif ($item eq 'canclone') {
16114: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
16115: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
16116: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
16117: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
16118: }
16119: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
16120: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
16121: } else {
1.289 raeburn 16122: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 16123: }
1.140 raeburn 16124: }
1.121 raeburn 16125: }
16126: $resulttext .= '</ul>';
16127: } else {
16128: $resulttext = &mt('No changes made to course defaults');
16129: }
16130: } else {
16131: $resulttext = '<span class="LC_error">'.
16132: &mt('An error occurred: [_1]',$putresult).'</span>';
16133: }
16134: return $resulttext;
16135: }
16136:
1.231 raeburn 16137: sub modify_selfenrollment {
16138: my ($dom,$lastactref,%domconfig) = @_;
16139: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 16140: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 16141: my %titles = &tool_titles();
1.232 raeburn 16142: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
16143: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 16144: $ordered{'default'} = ['types','registered','approval','limit'];
16145:
16146: my (%roles,%shown,%toplevel);
16147: $roles{'0'} = &Apache::lonnet::plaintext('dc');
16148:
16149: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
16150: if ($domconfig{'selfenrollment'} eq '') {
16151: $domconfig{'selfenrollment'} = {};
16152: }
16153: }
16154: %toplevel = (
16155: admin => 'Configuration Rights',
16156: default => 'Default settings',
16157: validation => 'Validation of self-enrollment requests',
16158: );
1.233 raeburn 16159: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 16160:
16161: if (ref($ordered{'admin'}) eq 'ARRAY') {
16162: foreach my $item (@{$ordered{'admin'}}) {
16163: foreach my $type (@types) {
16164: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
16165: $selfenrollhash{'admin'}{$type}{$item} = 1;
16166: } else {
16167: $selfenrollhash{'admin'}{$type}{$item} = 0;
16168: }
16169: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
16170: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
16171: if ($selfenrollhash{'admin'}{$type}{$item} ne
16172: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
16173: push(@{$changes{'admin'}{$type}},$item);
16174: }
16175: } else {
16176: if (!$selfenrollhash{'admin'}{$type}{$item}) {
16177: push(@{$changes{'admin'}{$type}},$item);
16178: }
16179: }
16180: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
16181: push(@{$changes{'admin'}{$type}},$item);
16182: }
16183: }
16184: }
16185: }
16186:
16187: foreach my $item (@{$ordered{'default'}}) {
16188: foreach my $type (@types) {
16189: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
16190: if ($item eq 'types') {
16191: unless (($value eq 'all') || ($value eq 'dom')) {
16192: $value = '';
16193: }
16194: } elsif ($item eq 'registered') {
16195: unless ($value eq '1') {
16196: $value = 0;
16197: }
16198: } elsif ($item eq 'approval') {
16199: unless ($value =~ /^[012]$/) {
16200: $value = 0;
16201: }
16202: } else {
16203: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
16204: $value = 'none';
16205: }
16206: }
16207: $selfenrollhash{'default'}{$type}{$item} = $value;
16208: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
16209: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
16210: if ($selfenrollhash{'default'}{$type}{$item} ne
16211: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
16212: push(@{$changes{'default'}{$type}},$item);
16213: }
16214: } else {
16215: push(@{$changes{'default'}{$type}},$item);
16216: }
16217: } else {
16218: push(@{$changes{'default'}{$type}},$item);
16219: }
16220: if ($item eq 'limit') {
16221: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
16222: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
16223: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
16224: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
16225: }
16226: } else {
16227: $selfenrollhash{'default'}{$type}{'cap'} = '';
16228: }
16229: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
16230: if ($selfenrollhash{'default'}{$type}{'cap'} ne
16231: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
16232: push(@{$changes{'default'}{$type}},'cap');
16233: }
16234: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
16235: push(@{$changes{'default'}{$type}},'cap');
16236: }
16237: }
16238: }
16239: }
16240:
16241: foreach my $item (@{$itemsref}) {
16242: if ($item eq 'fields') {
16243: my @changed;
16244: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
16245: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
16246: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
16247: }
16248: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
16249: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
16250: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
16251: $domconfig{'selfenrollment'}{'validation'}{$item});
16252: } else {
16253: @changed = @{$selfenrollhash{'validation'}{$item}};
16254: }
16255: } else {
16256: @changed = @{$selfenrollhash{'validation'}{$item}};
16257: }
16258: if (@changed) {
16259: if ($selfenrollhash{'validation'}{$item}) {
16260: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
16261: } else {
16262: $changes{'validation'}{$item} = &mt('None');
16263: }
16264: }
16265: } else {
16266: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
16267: if ($item eq 'markup') {
16268: if ($env{'form.selfenroll_validation_'.$item}) {
16269: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
16270: }
16271: }
16272: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
16273: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
16274: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
16275: }
16276: }
16277: }
16278: }
16279:
16280: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
16281: $dom);
16282: if ($putresult eq 'ok') {
16283: if (keys(%changes) > 0) {
16284: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16285: $resulttext = &mt('Changes made:').'<ul>';
16286: foreach my $key ('admin','default','validation') {
16287: if (ref($changes{$key}) eq 'HASH') {
16288: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
16289: if ($key eq 'validation') {
16290: foreach my $item (@{$itemsref}) {
16291: if (exists($changes{$key}{$item})) {
16292: if ($item eq 'markup') {
16293: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
16294: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
16295: } else {
16296: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
16297: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
16298: }
16299: }
16300: }
16301: } else {
16302: foreach my $type (@types) {
16303: if ($type eq 'community') {
16304: $roles{'1'} = &mt('Community personnel');
16305: } else {
16306: $roles{'1'} = &mt('Course personnel');
16307: }
16308: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 16309: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
16310: if ($key eq 'admin') {
16311: my @mgrdc = ();
16312: if (ref($ordered{$key}) eq 'ARRAY') {
16313: foreach my $item (@{$ordered{'admin'}}) {
16314: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
16315: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
16316: push(@mgrdc,$item);
16317: }
16318: }
16319: }
16320: if (@mgrdc) {
16321: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
16322: } else {
16323: delete($domdefaults{$type.'selfenrolladmdc'});
16324: }
16325: }
16326: } else {
16327: if (ref($ordered{$key}) eq 'ARRAY') {
16328: foreach my $item (@{$ordered{$key}}) {
16329: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
16330: $domdefaults{$type.'selfenroll'.$item} =
16331: $selfenrollhash{$key}{$type}{$item};
16332: }
16333: }
16334: }
16335: }
16336: }
1.231 raeburn 16337: $resulttext .= '<li>'.$titles{$type}.'<ul>';
16338: foreach my $item (@{$ordered{$key}}) {
16339: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
16340: $resulttext .= '<li>';
16341: if ($key eq 'admin') {
16342: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
16343: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
16344: } else {
16345: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
16346: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
16347: }
16348: $resulttext .= '</li>';
16349: }
16350: }
16351: $resulttext .= '</ul></li>';
16352: }
16353: }
16354: $resulttext .= '</ul></li>';
16355: }
16356: }
1.305 raeburn 16357: }
16358: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
16359: my $cachetime = 24*60*60;
16360: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16361: if (ref($lastactref) eq 'HASH') {
16362: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 16363: }
1.231 raeburn 16364: }
16365: $resulttext .= '</ul>';
16366: } else {
16367: $resulttext = &mt('No changes made to self-enrollment settings');
16368: }
16369: } else {
16370: $resulttext = '<span class="LC_error">'.
16371: &mt('An error occurred: [_1]',$putresult).'</span>';
16372: }
16373: return $resulttext;
16374: }
16375:
1.137 raeburn 16376: sub modify_usersessions {
1.212 raeburn 16377: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 16378: my @hostingtypes = ('version','excludedomain','includedomain');
16379: my @offloadtypes = ('primary','default');
16380: my %types = (
16381: remote => \@hostingtypes,
16382: hosted => \@hostingtypes,
16383: spares => \@offloadtypes,
16384: );
16385: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 16386: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 16387: my (%by_ip,%by_location,@intdoms,@instdoms);
16388: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 16389: my @locations = sort(keys(%by_location));
1.137 raeburn 16390: my (%defaultshash,%changes);
16391: foreach my $prefix (@prefixes) {
16392: $defaultshash{'usersessions'}{$prefix} = {};
16393: }
1.212 raeburn 16394: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 16395: my $resulttext;
1.138 raeburn 16396: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 16397: foreach my $prefix (@prefixes) {
1.145 raeburn 16398: next if ($prefix eq 'spares');
16399: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 16400: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16401: if ($type eq 'version') {
16402: my $value = $env{'form.'.$prefix.'_'.$type};
16403: my $okvalue;
16404: if ($value ne '') {
16405: if (grep(/^\Q$value\E$/,@lcversions)) {
16406: $okvalue = $value;
16407: }
16408: }
16409: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16410: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
16411: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
16412: if ($inuse == 0) {
16413: $changes{$prefix}{$type} = 1;
16414: } else {
16415: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
16416: $changes{$prefix}{$type} = 1;
16417: }
16418: if ($okvalue ne '') {
16419: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16420: }
16421: }
16422: } else {
16423: if (($inuse == 1) && ($okvalue ne '')) {
16424: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16425: $changes{$prefix}{$type} = 1;
16426: }
16427: }
16428: } else {
16429: if (($inuse == 1) && ($okvalue ne '')) {
16430: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16431: $changes{$prefix}{$type} = 1;
16432: }
16433: }
16434: } else {
16435: if (($inuse == 1) && ($okvalue ne '')) {
16436: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16437: $changes{$prefix}{$type} = 1;
16438: }
16439: }
16440: } else {
16441: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16442: my @okvals;
16443: foreach my $val (@vals) {
1.138 raeburn 16444: if ($val =~ /:/) {
16445: my @items = split(/:/,$val);
16446: foreach my $item (@items) {
16447: if (ref($by_location{$item}) eq 'ARRAY') {
16448: push(@okvals,$item);
16449: }
16450: }
16451: } else {
16452: if (ref($by_location{$val}) eq 'ARRAY') {
16453: push(@okvals,$val);
16454: }
1.137 raeburn 16455: }
16456: }
16457: @okvals = sort(@okvals);
16458: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16459: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
16460: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
16461: if ($inuse == 0) {
16462: $changes{$prefix}{$type} = 1;
16463: } else {
16464: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16465: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
16466: if (@changed > 0) {
16467: $changes{$prefix}{$type} = 1;
16468: }
16469: }
16470: } else {
16471: if ($inuse == 1) {
16472: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16473: $changes{$prefix}{$type} = 1;
16474: }
16475: }
16476: } else {
16477: if ($inuse == 1) {
16478: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16479: $changes{$prefix}{$type} = 1;
16480: }
16481: }
16482: } else {
16483: if ($inuse == 1) {
16484: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16485: $changes{$prefix}{$type} = 1;
16486: }
16487: }
16488: }
16489: }
16490: }
1.145 raeburn 16491:
16492: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 16493: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 16494: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
16495: my $savespares;
16496:
16497: foreach my $lonhost (sort(keys(%servers))) {
16498: my $serverhomeID =
16499: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 16500: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 16501: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
16502: my %spareschg;
16503: foreach my $type (@{$types{'spares'}}) {
16504: my @okspares;
16505: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
16506: foreach my $server (@checked) {
1.152 raeburn 16507: if (&Apache::lonnet::hostname($server) ne '') {
16508: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
16509: unless (grep(/^\Q$server\E$/,@okspares)) {
16510: push(@okspares,$server);
16511: }
1.145 raeburn 16512: }
16513: }
16514: }
16515: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
16516: my $newspare;
1.152 raeburn 16517: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
16518: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 16519: $newspare = $new;
16520: }
16521: }
1.152 raeburn 16522: my @spares;
16523: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
16524: @spares = sort(@okspares,$newspare);
16525: } else {
16526: @spares = sort(@okspares);
16527: }
16528: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 16529: if (ref($spareid{$lonhost}) eq 'HASH') {
16530: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 16531: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 16532: if (@diffs > 0) {
16533: $spareschg{$type} = 1;
16534: }
16535: }
16536: }
16537: }
16538: if (keys(%spareschg) > 0) {
16539: $changes{'spares'}{$lonhost} = \%spareschg;
16540: }
16541: }
1.261 raeburn 16542: $defaultshash{'usersessions'}{'offloadnow'} = {};
16543: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
16544: my @okoffload;
16545: if (@offloadnow) {
16546: foreach my $server (@offloadnow) {
16547: if (&Apache::lonnet::hostname($server) ne '') {
16548: unless (grep(/^\Q$server\E$/,@okoffload)) {
16549: push(@okoffload,$server);
16550: }
16551: }
16552: }
16553: if (@okoffload) {
16554: foreach my $lonhost (@okoffload) {
16555: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
16556: }
16557: }
16558: }
1.145 raeburn 16559: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16560: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
16561: if (ref($changes{'spares'}) eq 'HASH') {
16562: if (keys(%{$changes{'spares'}}) > 0) {
16563: $savespares = 1;
16564: }
16565: }
16566: } else {
16567: $savespares = 1;
16568: }
1.261 raeburn 16569: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
16570: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
16571: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
16572: $changes{'offloadnow'} = 1;
16573: last;
16574: }
16575: }
16576: unless ($changes{'offloadnow'}) {
1.289 raeburn 16577: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
1.261 raeburn 16578: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
16579: $changes{'offloadnow'} = 1;
16580: last;
16581: }
16582: }
16583: }
16584: } elsif (@okoffload) {
16585: $changes{'offloadnow'} = 1;
16586: }
16587: } elsif (@okoffload) {
16588: $changes{'offloadnow'} = 1;
1.145 raeburn 16589: }
1.147 raeburn 16590: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
16591: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 16592: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16593: $dom);
16594: if ($putresult eq 'ok') {
16595: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
16596: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
16597: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
16598: }
16599: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
16600: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
16601: }
1.261 raeburn 16602: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
16603: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
16604: }
1.137 raeburn 16605: }
16606: my $cachetime = 24*60*60;
16607: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 16608: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 16609: if (ref($lastactref) eq 'HASH') {
16610: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 16611: $lastactref->{'usersessions'} = 1;
1.212 raeburn 16612: }
1.147 raeburn 16613: if (keys(%changes) > 0) {
16614: my %lt = &usersession_titles();
16615: $resulttext = &mt('Changes made:').'<ul>';
16616: foreach my $prefix (@prefixes) {
16617: if (ref($changes{$prefix}) eq 'HASH') {
16618: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
16619: if ($prefix eq 'spares') {
16620: if (ref($changes{$prefix}) eq 'HASH') {
16621: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
16622: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 16623: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 16624: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
16625: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 16626: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
16627: foreach my $type (@{$types{$prefix}}) {
16628: if ($changes{$prefix}{$lonhost}{$type}) {
16629: my $offloadto = &mt('None');
16630: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
16631: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
16632: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
16633: }
1.145 raeburn 16634: }
1.147 raeburn 16635: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 16636: }
1.137 raeburn 16637: }
16638: }
1.147 raeburn 16639: $resulttext .= '</li>';
1.137 raeburn 16640: }
16641: }
1.147 raeburn 16642: } else {
16643: foreach my $type (@{$types{$prefix}}) {
16644: if (defined($changes{$prefix}{$type})) {
16645: my $newvalue;
16646: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
16647: if (ref($defaultshash{'usersessions'}{$prefix})) {
16648: if ($type eq 'version') {
16649: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
16650: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
16651: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
16652: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
16653: }
1.145 raeburn 16654: }
16655: }
16656: }
1.147 raeburn 16657: if ($newvalue eq '') {
16658: if ($type eq 'version') {
16659: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
16660: } else {
16661: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
16662: }
1.145 raeburn 16663: } else {
1.147 raeburn 16664: if ($type eq 'version') {
16665: $newvalue .= ' '.&mt('(or later)');
16666: }
16667: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 16668: }
1.137 raeburn 16669: }
16670: }
16671: }
1.147 raeburn 16672: $resulttext .= '</ul>';
1.137 raeburn 16673: }
16674: }
1.261 raeburn 16675: if ($changes{'offloadnow'}) {
16676: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
16677: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
16678: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
16679: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
16680: $resulttext .= '<li>'.$lonhost.'</li>';
16681: }
16682: $resulttext .= '</ul>';
16683: } else {
16684: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
16685: }
16686: } else {
16687: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
16688: }
16689: }
1.147 raeburn 16690: $resulttext .= '</ul>';
16691: } else {
16692: $resulttext = $nochgmsg;
1.137 raeburn 16693: }
16694: } else {
16695: $resulttext = '<span class="LC_error">'.
16696: &mt('An error occurred: [_1]',$putresult).'</span>';
16697: }
16698: } else {
1.147 raeburn 16699: $resulttext = $nochgmsg;
1.137 raeburn 16700: }
16701: return $resulttext;
16702: }
16703:
1.275 raeburn 16704: sub modify_ssl {
16705: my ($dom,$lastactref,%domconfig) = @_;
16706: my (%by_ip,%by_location,@intdoms,@instdoms);
16707: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
16708: my @locations = sort(keys(%by_location));
16709: my %servers = &Apache::lonnet::internet_dom_servers($dom);
16710: my (%defaultshash,%changes);
16711: my $action = 'ssl';
1.293 raeburn 16712: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 16713: foreach my $prefix (@prefixes) {
16714: $defaultshash{$action}{$prefix} = {};
16715: }
16716: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16717: my $resulttext;
16718: my %iphost = &Apache::lonnet::get_iphost();
16719: my @reptypes = ('certreq','nocertreq');
16720: my @connecttypes = ('dom','intdom','other');
16721: my %types = (
1.293 raeburn 16722: connto => \@connecttypes,
16723: connfrom => \@connecttypes,
16724: replication => \@reptypes,
1.275 raeburn 16725: );
16726: foreach my $prefix (sort(keys(%types))) {
16727: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 16728: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 16729: my $value = 'yes';
16730: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
16731: $value = $env{'form.'.$prefix.'_'.$type};
16732: }
1.335 raeburn 16733: if (ref($domconfig{$action}) eq 'HASH') {
16734: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
16735: if ($domconfig{$action}{$prefix}{$type} ne '') {
16736: if ($value ne $domconfig{$action}{$prefix}{$type}) {
16737: $changes{$prefix}{$type} = 1;
16738: }
16739: $defaultshash{$action}{$prefix}{$type} = $value;
16740: } else {
16741: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 16742: $changes{$prefix}{$type} = 1;
16743: }
16744: } else {
16745: $defaultshash{$action}{$prefix}{$type} = $value;
16746: $changes{$prefix}{$type} = 1;
16747: }
16748: } else {
16749: $defaultshash{$action}{$prefix}{$type} = $value;
16750: $changes{$prefix}{$type} = 1;
16751: }
16752: if (($type eq 'dom') && (keys(%servers) == 1)) {
16753: delete($changes{$prefix}{$type});
16754: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
16755: delete($changes{$prefix}{$type});
16756: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
16757: delete($changes{$prefix}{$type});
16758: }
16759: } elsif ($prefix eq 'replication') {
16760: if (@locations > 0) {
16761: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16762: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16763: my @okvals;
16764: foreach my $val (@vals) {
16765: if ($val =~ /:/) {
16766: my @items = split(/:/,$val);
16767: foreach my $item (@items) {
16768: if (ref($by_location{$item}) eq 'ARRAY') {
16769: push(@okvals,$item);
16770: }
16771: }
16772: } else {
16773: if (ref($by_location{$val}) eq 'ARRAY') {
16774: push(@okvals,$val);
16775: }
16776: }
16777: }
16778: @okvals = sort(@okvals);
16779: if (ref($domconfig{$action}) eq 'HASH') {
16780: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
16781: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
16782: if ($inuse == 0) {
16783: $changes{$prefix}{$type} = 1;
16784: } else {
16785: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16786: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
16787: if (@changed > 0) {
16788: $changes{$prefix}{$type} = 1;
16789: }
16790: }
16791: } else {
16792: if ($inuse == 1) {
16793: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16794: $changes{$prefix}{$type} = 1;
16795: }
16796: }
16797: } else {
16798: if ($inuse == 1) {
16799: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16800: $changes{$prefix}{$type} = 1;
16801: }
16802: }
16803: } else {
16804: if ($inuse == 1) {
16805: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16806: $changes{$prefix}{$type} = 1;
16807: }
16808: }
16809: }
16810: }
16811: }
16812: }
1.336 raeburn 16813: if (keys(%changes)) {
16814: foreach my $prefix (keys(%changes)) {
16815: if (ref($changes{$prefix}) eq 'HASH') {
16816: if (scalar(keys(%{$changes{$prefix}})) == 0) {
16817: delete($changes{$prefix});
16818: }
16819: } else {
16820: delete($changes{$prefix});
16821: }
16822: }
16823: }
1.275 raeburn 16824: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
16825: if (keys(%changes) > 0) {
16826: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16827: $dom);
16828: if ($putresult eq 'ok') {
16829: if (ref($defaultshash{$action}) eq 'HASH') {
16830: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
16831: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
16832: }
1.293 raeburn 16833: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 16834: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 16835: }
16836: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 16837: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 16838: }
16839: }
16840: my $cachetime = 24*60*60;
16841: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16842: if (ref($lastactref) eq 'HASH') {
16843: $lastactref->{'domdefaults'} = 1;
16844: }
16845: if (keys(%changes) > 0) {
16846: my %titles = &ssl_titles();
16847: $resulttext = &mt('Changes made:').'<ul>';
16848: foreach my $prefix (@prefixes) {
16849: if (ref($changes{$prefix}) eq 'HASH') {
16850: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
16851: foreach my $type (@{$types{$prefix}}) {
16852: if (defined($changes{$prefix}{$type})) {
16853: my $newvalue;
16854: if (ref($defaultshash{$action}) eq 'HASH') {
16855: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 16856: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 16857: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
16858: } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
16859: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
16860: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
16861: }
16862: }
16863: }
16864: if ($newvalue eq '') {
16865: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
16866: } else {
16867: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
16868: }
16869: }
16870: }
16871: }
16872: $resulttext .= '</ul>';
16873: }
16874: }
16875: } else {
16876: $resulttext = $nochgmsg;
16877: }
16878: } else {
16879: $resulttext = '<span class="LC_error">'.
16880: &mt('An error occurred: [_1]',$putresult).'</span>';
16881: }
16882: } else {
16883: $resulttext = $nochgmsg;
16884: }
16885: return $resulttext;
16886: }
16887:
1.279 raeburn 16888: sub modify_trust {
16889: my ($dom,$lastactref,%domconfig) = @_;
16890: my (%by_ip,%by_location,@intdoms,@instdoms);
16891: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
16892: my @locations = sort(keys(%by_location));
16893: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
16894: my @types = ('exc','inc');
16895: my (%defaultshash,%changes);
16896: foreach my $prefix (@prefixes) {
16897: $defaultshash{'trust'}{$prefix} = {};
16898: }
16899: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16900: my $resulttext;
16901: foreach my $prefix (@prefixes) {
16902: foreach my $type (@types) {
16903: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16904: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16905: my @okvals;
16906: foreach my $val (@vals) {
16907: if ($val =~ /:/) {
16908: my @items = split(/:/,$val);
16909: foreach my $item (@items) {
16910: if (ref($by_location{$item}) eq 'ARRAY') {
16911: push(@okvals,$item);
16912: }
16913: }
16914: } else {
16915: if (ref($by_location{$val}) eq 'ARRAY') {
16916: push(@okvals,$val);
16917: }
16918: }
16919: }
16920: @okvals = sort(@okvals);
16921: if (ref($domconfig{'trust'}) eq 'HASH') {
16922: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
16923: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
16924: if ($inuse == 0) {
16925: $changes{$prefix}{$type} = 1;
16926: } else {
16927: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16928: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
16929: if (@changed > 0) {
16930: $changes{$prefix}{$type} = 1;
16931: }
16932: }
16933: } else {
16934: if ($inuse == 1) {
16935: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16936: $changes{$prefix}{$type} = 1;
16937: }
16938: }
16939: } else {
16940: if ($inuse == 1) {
16941: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16942: $changes{$prefix}{$type} = 1;
16943: }
16944: }
16945: } else {
16946: if ($inuse == 1) {
16947: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16948: $changes{$prefix}{$type} = 1;
16949: }
16950: }
16951: }
16952: }
16953: my $nochgmsg = &mt('No changes made to trust settings.');
16954: if (keys(%changes) > 0) {
16955: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16956: $dom);
16957: if ($putresult eq 'ok') {
16958: if (ref($defaultshash{'trust'}) eq 'HASH') {
16959: foreach my $prefix (@prefixes) {
16960: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
16961: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
16962: }
16963: }
16964: }
16965: my $cachetime = 24*60*60;
16966: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16967: if (ref($lastactref) eq 'HASH') {
16968: $lastactref->{'domdefaults'} = 1;
16969: }
16970: if (keys(%changes) > 0) {
16971: my %lt = &trust_titles();
16972: $resulttext = &mt('Changes made:').'<ul>';
16973: foreach my $prefix (@prefixes) {
16974: if (ref($changes{$prefix}) eq 'HASH') {
16975: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
16976: foreach my $type (@types) {
16977: if (defined($changes{$prefix}{$type})) {
16978: my $newvalue;
16979: if (ref($defaultshash{'trust'}) eq 'HASH') {
16980: if (ref($defaultshash{'trust'}{$prefix})) {
16981: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
16982: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
16983: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
16984: }
16985: }
16986: }
16987: }
16988: if ($newvalue eq '') {
16989: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
16990: } else {
16991: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
16992: }
16993: }
16994: }
16995: $resulttext .= '</ul>';
16996: }
16997: }
16998: $resulttext .= '</ul>';
16999: } else {
17000: $resulttext = $nochgmsg;
17001: }
17002: } else {
17003: $resulttext = '<span class="LC_error">'.
17004: &mt('An error occurred: [_1]',$putresult).'</span>';
17005: }
17006: } else {
17007: $resulttext = $nochgmsg;
17008: }
17009: return $resulttext;
17010: }
17011:
1.150 raeburn 17012: sub modify_loadbalancing {
17013: my ($dom,%domconfig) = @_;
17014: my $primary_id = &Apache::lonnet::domain($dom,'primary');
17015: my $intdom = &Apache::lonnet::internet_dom($primary_id);
17016: my ($othertitle,$usertypes,$types) =
17017: &Apache::loncommon::sorted_inst_types($dom);
17018: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 17019: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 17020: my @sparestypes = ('primary','default');
17021: my %typetitles = &sparestype_titles();
17022: my $resulttext;
1.342 raeburn 17023: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 17024: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
17025: %existing = %{$domconfig{'loadbalancing'}};
17026: }
17027: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 17028: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 17029: my ($saveloadbalancing,%defaultshash,%changes);
17030: my ($alltypes,$othertypes,$titles) =
17031: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
17032: my %ruletitles = &offloadtype_text();
17033: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
17034: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
17035: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
17036: if ($balancer eq '') {
17037: next;
17038: }
1.210 raeburn 17039: if (!exists($servers{$balancer})) {
1.171 raeburn 17040: if (exists($currbalancer{$balancer})) {
17041: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 17042: }
1.171 raeburn 17043: next;
17044: }
17045: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
17046: push(@{$changes{'delete'}},$balancer);
17047: next;
17048: }
17049: if (!exists($currbalancer{$balancer})) {
17050: push(@{$changes{'add'}},$balancer);
17051: }
17052: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
17053: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
17054: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
17055: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
17056: $saveloadbalancing = 1;
17057: }
17058: foreach my $sparetype (@sparestypes) {
17059: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
17060: my @offloadto;
17061: foreach my $target (@targets) {
17062: if (($servers{$target}) && ($target ne $balancer)) {
17063: if ($sparetype eq 'default') {
17064: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
17065: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 17066: }
17067: }
1.171 raeburn 17068: unless(grep(/^\Q$target\E$/,@offloadto)) {
17069: push(@offloadto,$target);
17070: }
1.150 raeburn 17071: }
17072: }
1.284 raeburn 17073: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
17074: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
17075: push(@offloadto,$balancer);
17076: }
17077: }
17078: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 17079: }
1.342 raeburn 17080: if ($env{'form.loadbalancing_cookie_'.$i}) {
17081: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
17082: if (exists($currbalancer{$balancer})) {
17083: unless ($currcookies{$balancer}) {
17084: $changes{'curr'}{$balancer}{'cookie'} = 1;
17085: }
17086: }
17087: } elsif (exists($currbalancer{$balancer})) {
17088: if ($currcookies{$balancer}) {
17089: $changes{'curr'}{$balancer}{'cookie'} = 1;
17090: }
17091: }
1.171 raeburn 17092: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 17093: foreach my $sparetype (@sparestypes) {
1.171 raeburn 17094: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
17095: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 17096: if (@targetdiffs > 0) {
1.171 raeburn 17097: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 17098: }
1.171 raeburn 17099: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
17100: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
17101: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 17102: }
17103: }
17104: }
17105: } else {
1.171 raeburn 17106: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 17107: foreach my $sparetype (@sparestypes) {
1.171 raeburn 17108: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
17109: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
17110: $changes{'curr'}{$balancer}{'targets'} = 1;
17111: }
1.150 raeburn 17112: }
17113: }
1.210 raeburn 17114: }
1.150 raeburn 17115: }
17116: my $ishomedom;
1.171 raeburn 17117: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
17118: $ishomedom = 1;
1.150 raeburn 17119: }
17120: if (ref($alltypes) eq 'ARRAY') {
17121: foreach my $type (@{$alltypes}) {
17122: my $rule;
1.210 raeburn 17123: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 17124: (!$ishomedom)) {
1.171 raeburn 17125: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
17126: }
17127: if ($rule eq 'specific') {
1.255 raeburn 17128: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 17129: if (exists($servers{$specifiedhost})) {
1.255 raeburn 17130: $rule = $specifiedhost;
17131: }
1.150 raeburn 17132: }
1.171 raeburn 17133: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
17134: if (ref($currrules{$balancer}) eq 'HASH') {
17135: if ($rule ne $currrules{$balancer}{$type}) {
17136: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 17137: }
17138: } elsif ($rule ne '') {
1.171 raeburn 17139: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 17140: }
17141: }
17142: }
1.171 raeburn 17143: }
17144: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
17145: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
17146: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
17147: $defaultshash{'loadbalancing'} = {};
17148: }
17149: my $putresult = &Apache::lonnet::put_dom('configuration',
17150: \%defaultshash,$dom);
17151: if ($putresult eq 'ok') {
17152: if (keys(%changes) > 0) {
1.252 raeburn 17153: my %toupdate;
1.171 raeburn 17154: if (ref($changes{'delete'}) eq 'ARRAY') {
17155: foreach my $balancer (sort(@{$changes{'delete'}})) {
17156: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 17157: $toupdate{$balancer} = 1;
1.150 raeburn 17158: }
1.171 raeburn 17159: }
17160: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 17161: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 17162: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 17163: $toupdate{$balancer} = 1;
1.171 raeburn 17164: }
17165: }
17166: if (ref($changes{'curr'}) eq 'HASH') {
17167: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 17168: $toupdate{$balancer} = 1;
1.171 raeburn 17169: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
17170: if ($changes{'curr'}{$balancer}{'targets'}) {
17171: my %offloadstr;
17172: foreach my $sparetype (@sparestypes) {
17173: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
17174: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
17175: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
17176: }
17177: }
1.150 raeburn 17178: }
1.171 raeburn 17179: if (keys(%offloadstr) == 0) {
17180: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 17181: } else {
1.171 raeburn 17182: my $showoffload;
17183: foreach my $sparetype (@sparestypes) {
17184: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
17185: if (defined($offloadstr{$sparetype})) {
17186: $showoffload .= $offloadstr{$sparetype};
17187: } else {
17188: $showoffload .= &mt('None');
17189: }
17190: $showoffload .= (' 'x3);
17191: }
17192: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 17193: }
17194: }
17195: }
1.171 raeburn 17196: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
17197: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
17198: foreach my $type (@{$alltypes}) {
17199: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
17200: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
17201: my $balancetext;
17202: if ($rule eq '') {
17203: $balancetext = $ruletitles{'default'};
1.209 raeburn 17204: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 17205: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 17206: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 17207: foreach my $sparetype (@sparestypes) {
17208: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
17209: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
17210: }
17211: }
1.253 raeburn 17212: foreach my $item (@{$alltypes}) {
17213: next if ($item =~ /^_LC_ipchange/);
17214: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
17215: if ($hasrule eq 'homeserver') {
17216: map { $toupdate{$_} = 1; } (keys(%libraryservers));
17217: } else {
17218: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
17219: if ($servers{$hasrule}) {
17220: $toupdate{$hasrule} = 1;
17221: }
17222: }
17223: }
17224: }
1.254 raeburn 17225: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
17226: $balancetext = $ruletitles{$rule};
17227: } else {
17228: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
17229: $balancetext = $ruletitles{'particular'}.' '.$receiver;
17230: if ($receiver) {
17231: $toupdate{$receiver};
17232: }
17233: }
17234: } else {
17235: $balancetext = $ruletitles{$rule};
1.252 raeburn 17236: }
1.171 raeburn 17237: } else {
17238: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
17239: }
1.210 raeburn 17240: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 17241: }
17242: }
17243: }
17244: }
1.342 raeburn 17245: if ($changes{'curr'}{$balancer}{'cookie'}) {
17246: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
17247: $balancer).'</li>';
17248: }
1.252 raeburn 17249: if (keys(%toupdate)) {
17250: my %thismachine;
17251: my $updatedhere;
17252: my $cachetime = 60*60*24;
17253: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
17254: foreach my $lonhost (keys(%toupdate)) {
17255: if ($thismachine{$lonhost}) {
17256: unless ($updatedhere) {
17257: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
17258: $defaultshash{'loadbalancing'},
17259: $cachetime);
17260: $updatedhere = 1;
17261: }
17262: } else {
17263: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
17264: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
17265: }
17266: }
17267: }
1.150 raeburn 17268: }
1.171 raeburn 17269: }
17270: if ($resulttext ne '') {
17271: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 17272: } else {
17273: $resulttext = $nochgmsg;
17274: }
17275: } else {
1.171 raeburn 17276: $resulttext = $nochgmsg;
1.150 raeburn 17277: }
17278: } else {
1.171 raeburn 17279: $resulttext = '<span class="LC_error">'.
17280: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 17281: }
17282: } else {
1.171 raeburn 17283: $resulttext = $nochgmsg;
1.150 raeburn 17284: }
17285: return $resulttext;
17286: }
17287:
1.48 raeburn 17288: sub recurse_check {
17289: my ($chkcats,$categories,$depth,$name) = @_;
17290: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
17291: my $chg = 0;
17292: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
17293: my $category = $chkcats->[$depth]{$name}[$j];
17294: my $item;
17295: if ($category eq '') {
17296: $chg ++;
17297: } else {
17298: my $deeper = $depth + 1;
17299: $item = &escape($category).':'.&escape($name).':'.$depth;
17300: if ($chg) {
17301: $categories->{$item} -= $chg;
17302: }
17303: &recurse_check($chkcats,$categories,$deeper,$category);
17304: $deeper --;
17305: }
17306: }
17307: }
17308: return;
17309: }
17310:
17311: sub recurse_cat_deletes {
17312: my ($item,$coursecategories,$deletions) = @_;
17313: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
17314: my $subdepth = $depth + 1;
17315: if (ref($coursecategories) eq 'HASH') {
17316: foreach my $subitem (keys(%{$coursecategories})) {
17317: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
17318: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
17319: delete($coursecategories->{$subitem});
17320: $deletions->{$subitem} = 1;
17321: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 17322: }
1.48 raeburn 17323: }
17324: }
17325: return;
17326: }
17327:
1.125 raeburn 17328: sub active_dc_picker {
1.191 raeburn 17329: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 17330: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 17331: my @domcoord = keys(%domcoords);
17332: if (keys(%currhash)) {
17333: foreach my $dc (keys(%currhash)) {
17334: unless (exists($domcoords{$dc})) {
17335: push(@domcoord,$dc);
17336: }
17337: }
17338: }
17339: @domcoord = sort(@domcoord);
1.210 raeburn 17340: my $numdcs = scalar(@domcoord);
1.191 raeburn 17341: my $rows = 0;
17342: my $table;
1.125 raeburn 17343: if ($numdcs > 1) {
1.191 raeburn 17344: $table = '<table>';
17345: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 17346: my $rem = $i%($numinrow);
17347: if ($rem == 0) {
17348: if ($i > 0) {
1.191 raeburn 17349: $table .= '</tr>';
1.125 raeburn 17350: }
1.191 raeburn 17351: $table .= '<tr>';
17352: $rows ++;
1.125 raeburn 17353: }
1.191 raeburn 17354: my $check = '';
17355: if ($inputtype eq 'radio') {
17356: if (keys(%currhash) == 0) {
17357: if (!$i) {
17358: $check = ' checked="checked"';
17359: }
17360: } elsif (exists($currhash{$domcoord[$i]})) {
17361: $check = ' checked="checked"';
17362: }
17363: } else {
17364: if (exists($currhash{$domcoord[$i]})) {
17365: $check = ' checked="checked"';
1.125 raeburn 17366: }
17367: }
1.191 raeburn 17368: if ($i == @domcoord - 1) {
1.125 raeburn 17369: my $colsleft = $numinrow - $rem;
17370: if ($colsleft > 1) {
1.191 raeburn 17371: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 17372: } else {
1.191 raeburn 17373: $table .= '<td class="LC_left_item">';
1.125 raeburn 17374: }
17375: } else {
1.191 raeburn 17376: $table .= '<td class="LC_left_item">';
17377: }
17378: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
17379: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
17380: $table .= '<span class="LC_nobreak"><label>'.
17381: '<input type="'.$inputtype.'" name="'.$name.'"'.
17382: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
17383: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 17384: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 17385: }
1.219 raeburn 17386: $table .= '</label></span></td>';
1.191 raeburn 17387: }
17388: $table .= '</tr></table>';
17389: } elsif ($numdcs == 1) {
1.219 raeburn 17390: my ($dcname,$dcdom) = split(':',$domcoord[0]);
17391: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 17392: if ($inputtype eq 'radio') {
1.247 raeburn 17393: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 17394: if ($user ne $dcname.':'.$dcdom) {
17395: $table .= ' ('.$dcname.':'.$dcdom.')';
17396: }
1.191 raeburn 17397: } else {
17398: my $check;
17399: if (exists($currhash{$domcoord[0]})) {
17400: $check = ' checked="checked"';
1.125 raeburn 17401: }
1.247 raeburn 17402: $table = '<span class="LC_nobreak"><label>'.
17403: '<input type="checkbox" name="'.$name.'" '.
17404: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 17405: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 17406: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 17407: }
1.220 raeburn 17408: $table .= '</label></span>';
1.191 raeburn 17409: $rows ++;
1.125 raeburn 17410: }
17411: }
1.191 raeburn 17412: return ($numdcs,$table,$rows);
1.125 raeburn 17413: }
17414:
1.137 raeburn 17415: sub usersession_titles {
17416: return &Apache::lonlocal::texthash(
17417: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
17418: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 17419: spares => 'Servers offloaded to, when busy',
1.137 raeburn 17420: version => 'LON-CAPA version requirement',
1.138 raeburn 17421: excludedomain => 'Allow all, but exclude specific domains',
17422: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 17423: primary => 'Primary (checked first)',
1.154 raeburn 17424: default => 'Default',
1.137 raeburn 17425: );
17426: }
17427:
1.152 raeburn 17428: sub id_for_thisdom {
17429: my (%servers) = @_;
17430: my %altids;
17431: foreach my $server (keys(%servers)) {
17432: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
17433: if ($serverhome ne $server) {
17434: $altids{$serverhome} = $server;
17435: }
17436: }
17437: return %altids;
17438: }
17439:
1.150 raeburn 17440: sub count_servers {
17441: my ($currbalancer,%servers) = @_;
17442: my (@spares,$numspares);
17443: foreach my $lonhost (sort(keys(%servers))) {
17444: next if ($currbalancer eq $lonhost);
17445: push(@spares,$lonhost);
17446: }
17447: if ($currbalancer) {
17448: $numspares = scalar(@spares);
17449: } else {
17450: $numspares = scalar(@spares) - 1;
17451: }
17452: return ($numspares,@spares);
17453: }
17454:
17455: sub lonbalance_targets_js {
1.171 raeburn 17456: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 17457: my $select = &mt('Select');
17458: my ($alltargets,$allishome,$allinsttypes,@alltypes);
17459: if (ref($servers) eq 'HASH') {
17460: $alltargets = join("','",sort(keys(%{$servers})));
17461: my @homedoms;
17462: foreach my $server (sort(keys(%{$servers}))) {
17463: if (&Apache::lonnet::host_domain($server) eq $dom) {
17464: push(@homedoms,'1');
17465: } else {
17466: push(@homedoms,'0');
17467: }
17468: }
17469: $allishome = join("','",@homedoms);
17470: }
17471: if (ref($types) eq 'ARRAY') {
17472: if (@{$types} > 0) {
17473: @alltypes = @{$types};
17474: }
17475: }
17476: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
17477: $allinsttypes = join("','",@alltypes);
1.342 raeburn 17478: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 17479: if (ref($settings) eq 'HASH') {
17480: %existing = %{$settings};
17481: }
17482: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 17483: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 17484: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 17485: return <<"END";
17486:
17487: <script type="text/javascript">
17488: // <![CDATA[
17489:
1.171 raeburn 17490: currBalancers = new Array('$balancers');
17491:
17492: function toggleTargets(balnum) {
17493: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
17494: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
17495: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
17496: var prevbalancer = prevhostitem.value;
17497: var baltotal = document.getElementById('loadbalancing_total').value;
17498: prevhostitem.value = balancer;
17499: if (prevbalancer != '') {
17500: var prevIdx = currBalancers.indexOf(prevbalancer);
17501: if (prevIdx != -1) {
17502: currBalancers.splice(prevIdx,1);
17503: }
17504: }
1.150 raeburn 17505: if (balancer == '') {
1.171 raeburn 17506: hideSpares(balnum);
1.150 raeburn 17507: } else {
1.171 raeburn 17508: var currIdx = currBalancers.indexOf(balancer);
17509: if (currIdx == -1) {
17510: currBalancers.push(balancer);
17511: }
1.150 raeburn 17512: var homedoms = new Array('$allishome');
1.171 raeburn 17513: var ishomedom = homedoms[lonhostitem.selectedIndex];
17514: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 17515: }
1.171 raeburn 17516: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 17517: return;
17518: }
17519:
1.171 raeburn 17520: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 17521: var alltargets = new Array('$alltargets');
17522: var insttypes = new Array('$allinsttypes');
1.151 raeburn 17523: var offloadtypes = new Array('primary','default');
17524:
1.171 raeburn 17525: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
17526: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 17527:
1.151 raeburn 17528: for (var i=0; i<offloadtypes.length; i++) {
17529: var count = 0;
17530: for (var j=0; j<alltargets.length; j++) {
17531: if (alltargets[j] != balancer) {
1.171 raeburn 17532: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
17533: item.value = alltargets[j];
17534: item.style.textAlign='left';
17535: item.style.textFace='normal';
17536: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
17537: if (currBalancers.indexOf(alltargets[j]) == -1) {
17538: item.disabled = '';
17539: } else {
17540: item.disabled = 'disabled';
17541: item.checked = false;
17542: }
1.151 raeburn 17543: count ++;
17544: }
1.150 raeburn 17545: }
17546: }
1.151 raeburn 17547: for (var k=0; k<insttypes.length; k++) {
17548: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 17549: if (ishomedom == 1) {
1.171 raeburn 17550: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
17551: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 17552: } else {
1.171 raeburn 17553: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
17554: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 17555: }
17556: } else {
1.171 raeburn 17557: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
17558: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 17559: }
1.151 raeburn 17560: if ((insttypes[k] != '_LC_external') &&
17561: ((insttypes[k] != '_LC_internetdom') ||
17562: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 17563: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
17564: item.options.length = 0;
17565: item.options[0] = new Option("","",true,true);
1.210 raeburn 17566: var idx = 0;
1.151 raeburn 17567: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 17568: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
17569: idx ++;
17570: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 17571: }
17572: }
17573: }
17574: }
17575: return;
17576: }
17577:
1.171 raeburn 17578: function hideSpares(balnum) {
1.150 raeburn 17579: var alltargets = new Array('$alltargets');
17580: var insttypes = new Array('$allinsttypes');
17581: var offloadtypes = new Array('primary','default');
17582:
1.171 raeburn 17583: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
17584: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 17585:
17586: var total = alltargets.length - 1;
17587: for (var i=0; i<offloadtypes; i++) {
17588: for (var j=0; j<total; j++) {
1.171 raeburn 17589: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
17590: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
17591: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 17592: }
1.150 raeburn 17593: }
17594: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 17595: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
17596: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 17597: if (insttypes[k] != '_LC_external') {
1.171 raeburn 17598: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
17599: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 17600: }
17601: }
17602: return;
17603: }
17604:
1.171 raeburn 17605: function checkOffloads(item,balnum,type) {
1.150 raeburn 17606: var alltargets = new Array('$alltargets');
17607: var offloadtypes = new Array('primary','default');
17608: if (item.checked) {
17609: var total = alltargets.length - 1;
17610: var other;
17611: if (type == offloadtypes[0]) {
1.151 raeburn 17612: other = offloadtypes[1];
1.150 raeburn 17613: } else {
1.151 raeburn 17614: other = offloadtypes[0];
1.150 raeburn 17615: }
17616: for (var i=0; i<total; i++) {
1.171 raeburn 17617: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 17618: if (server == item.value) {
1.171 raeburn 17619: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
17620: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 17621: }
17622: }
17623: }
17624: }
17625: return;
17626: }
17627:
1.171 raeburn 17628: function singleServerToggle(balnum,type) {
17629: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 17630: if (offloadtoSelIdx == 0) {
1.171 raeburn 17631: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
17632: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 17633:
17634: } else {
1.171 raeburn 17635: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
17636: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 17637: }
17638: return;
17639: }
17640:
1.171 raeburn 17641: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 17642: if (type == '_LC_external') {
1.171 raeburn 17643: return;
1.150 raeburn 17644: }
1.171 raeburn 17645: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 17646: for (var i=0; i<typesRules.length; i++) {
17647: if (formname.elements[typesRules[i]].checked) {
17648: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 17649: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
17650: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 17651: } else {
1.171 raeburn 17652: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
17653: }
17654: }
17655: }
17656: return;
17657: }
17658:
17659: function balancerDeleteChange(balnum) {
17660: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
17661: var baltotal = document.getElementById('loadbalancing_total').value;
17662: var addtarget;
17663: var removetarget;
17664: var action = 'delete';
17665: if (document.getElementById('loadbalancing_delete_'+balnum)) {
17666: var lonhost = hostitem.value;
17667: var currIdx = currBalancers.indexOf(lonhost);
17668: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
17669: if (currIdx != -1) {
17670: currBalancers.splice(currIdx,1);
17671: }
17672: addtarget = lonhost;
17673: } else {
17674: if (currIdx == -1) {
17675: currBalancers.push(lonhost);
17676: }
17677: removetarget = lonhost;
17678: action = 'undelete';
17679: }
17680: balancerChange(balnum,baltotal,action,addtarget,removetarget);
17681: }
17682: return;
17683: }
17684:
17685: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
17686: if (baltotal > 1) {
17687: var offloadtypes = new Array('primary','default');
17688: var alltargets = new Array('$alltargets');
17689: var insttypes = new Array('$allinsttypes');
17690: for (var i=0; i<baltotal; i++) {
17691: if (i != balnum) {
17692: for (var j=0; j<offloadtypes.length; j++) {
17693: var total = alltargets.length - 1;
17694: for (var k=0; k<total; k++) {
17695: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
17696: var server = serveritem.value;
17697: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
17698: if (server == addtarget) {
17699: serveritem.disabled = '';
17700: }
17701: }
17702: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
17703: if (server == removetarget) {
17704: serveritem.disabled = 'disabled';
17705: serveritem.checked = false;
17706: }
17707: }
17708: }
17709: }
17710: for (var j=0; j<insttypes.length; j++) {
17711: if (insttypes[j] != '_LC_external') {
17712: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
17713: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
17714: var currSel = singleserver.selectedIndex;
17715: var currVal = singleserver.options[currSel].value;
17716: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
17717: var numoptions = singleserver.options.length;
17718: var needsnew = 1;
17719: for (var k=0; k<numoptions; k++) {
17720: if (singleserver.options[k] == addtarget) {
17721: needsnew = 0;
17722: break;
17723: }
17724: }
17725: if (needsnew == 1) {
17726: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
17727: }
17728: }
17729: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
17730: singleserver.options.length = 0;
17731: if ((currVal) && (currVal != removetarget)) {
17732: singleserver.options[0] = new Option("","",false,false);
17733: } else {
17734: singleserver.options[0] = new Option("","",true,true);
17735: }
17736: var idx = 0;
17737: for (var m=0; m<alltargets.length; m++) {
17738: if (currBalancers.indexOf(alltargets[m]) == -1) {
17739: idx ++;
17740: if (currVal == alltargets[m]) {
17741: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
17742: } else {
17743: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
17744: }
17745: }
17746: }
17747: }
17748: }
17749: }
17750: }
1.150 raeburn 17751: }
17752: }
17753: }
17754: return;
17755: }
17756:
1.152 raeburn 17757: // ]]>
17758: </script>
17759:
17760: END
17761: }
17762:
17763: sub new_spares_js {
17764: my @sparestypes = ('primary','default');
17765: my $types = join("','",@sparestypes);
17766: my $select = &mt('Select');
17767: return <<"END";
17768:
17769: <script type="text/javascript">
17770: // <![CDATA[
17771:
17772: function updateNewSpares(formname,lonhost) {
17773: var types = new Array('$types');
17774: var include = new Array();
17775: var exclude = new Array();
17776: for (var i=0; i<types.length; i++) {
17777: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
17778: for (var j=0; j<spareboxes.length; j++) {
17779: if (formname.elements[spareboxes[j]].checked) {
17780: exclude.push(formname.elements[spareboxes[j]].value);
17781: } else {
17782: include.push(formname.elements[spareboxes[j]].value);
17783: }
17784: }
17785: }
17786: for (var i=0; i<types.length; i++) {
17787: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
17788: var selIdx = newSpare.selectedIndex;
17789: var currnew = newSpare.options[selIdx].value;
17790: var okSpares = new Array();
17791: for (var j=0; j<newSpare.options.length; j++) {
17792: var possible = newSpare.options[j].value;
17793: if (possible != '') {
17794: if (exclude.indexOf(possible) == -1) {
17795: okSpares.push(possible);
17796: } else {
17797: if (currnew == possible) {
17798: selIdx = 0;
17799: }
17800: }
17801: }
17802: }
17803: for (var k=0; k<include.length; k++) {
17804: if (okSpares.indexOf(include[k]) == -1) {
17805: okSpares.push(include[k]);
17806: }
17807: }
17808: okSpares.sort();
17809: newSpare.options.length = 0;
17810: if (selIdx == 0) {
17811: newSpare.options[0] = new Option("$select","",true,true);
17812: } else {
17813: newSpare.options[0] = new Option("$select","",false,false);
17814: }
17815: for (var m=0; m<okSpares.length; m++) {
17816: var idx = m+1;
17817: var selThis = 0;
17818: if (selIdx != 0) {
17819: if (okSpares[m] == currnew) {
17820: selThis = 1;
17821: }
17822: }
17823: if (selThis == 1) {
17824: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
17825: } else {
17826: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
17827: }
17828: }
17829: }
17830: return;
17831: }
17832:
17833: function checkNewSpares(lonhost,type) {
17834: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
17835: var chosen = newSpare.options[newSpare.selectedIndex].value;
17836: if (chosen != '') {
17837: var othertype;
17838: var othernewSpare;
17839: if (type == 'primary') {
17840: othernewSpare = document.getElementById('newspare_default_'+lonhost);
17841: }
17842: if (type == 'default') {
17843: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
17844: }
17845: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
17846: othernewSpare.selectedIndex = 0;
17847: }
17848: }
17849: return;
17850: }
17851:
17852: // ]]>
17853: </script>
17854:
17855: END
17856:
17857: }
17858:
17859: sub common_domprefs_js {
17860: return <<"END";
17861:
17862: <script type="text/javascript">
17863: // <![CDATA[
17864:
1.150 raeburn 17865: function getIndicesByName(formname,item) {
1.152 raeburn 17866: var group = new Array();
1.150 raeburn 17867: for (var i=0;i<formname.elements.length;i++) {
17868: if (formname.elements[i].name == item) {
1.152 raeburn 17869: group.push(formname.elements[i].id);
1.150 raeburn 17870: }
17871: }
1.152 raeburn 17872: return group;
1.150 raeburn 17873: }
17874:
17875: // ]]>
17876: </script>
17877:
17878: END
1.152 raeburn 17879:
1.150 raeburn 17880: }
17881:
1.165 raeburn 17882: sub recaptcha_js {
17883: my %lt = &captcha_phrases();
17884: return <<"END";
17885:
17886: <script type="text/javascript">
17887: // <![CDATA[
17888:
17889: function updateCaptcha(caller,context) {
17890: var privitem;
17891: var pubitem;
17892: var privtext;
17893: var pubtext;
1.269 raeburn 17894: var versionitem;
17895: var versiontext;
1.165 raeburn 17896: if (document.getElementById(context+'_recaptchapub')) {
17897: pubitem = document.getElementById(context+'_recaptchapub');
17898: } else {
17899: return;
17900: }
17901: if (document.getElementById(context+'_recaptchapriv')) {
17902: privitem = document.getElementById(context+'_recaptchapriv');
17903: } else {
17904: return;
17905: }
17906: if (document.getElementById(context+'_recaptchapubtxt')) {
17907: pubtext = document.getElementById(context+'_recaptchapubtxt');
17908: } else {
17909: return;
17910: }
17911: if (document.getElementById(context+'_recaptchaprivtxt')) {
17912: privtext = document.getElementById(context+'_recaptchaprivtxt');
17913: } else {
17914: return;
17915: }
1.269 raeburn 17916: if (document.getElementById(context+'_recaptchaversion')) {
17917: versionitem = document.getElementById(context+'_recaptchaversion');
17918: } else {
17919: return;
17920: }
17921: if (document.getElementById(context+'_recaptchavertxt')) {
17922: versiontext = document.getElementById(context+'_recaptchavertxt');
17923: } else {
17924: return;
17925: }
1.165 raeburn 17926: if (caller.checked) {
17927: if (caller.value == 'recaptcha') {
17928: pubitem.type = 'text';
17929: privitem.type = 'text';
17930: pubitem.size = '40';
17931: privitem.size = '40';
17932: pubtext.innerHTML = "$lt{'pub'}";
17933: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 17934: versionitem.type = 'text';
17935: versionitem.size = '3';
1.289 raeburn 17936: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 17937: } else {
17938: pubitem.type = 'hidden';
17939: privitem.type = 'hidden';
1.269 raeburn 17940: versionitem.type = 'hidden';
1.165 raeburn 17941: pubtext.innerHTML = '';
17942: privtext.innerHTML = '';
1.269 raeburn 17943: versiontext.innerHTML = '';
1.165 raeburn 17944: }
17945: }
17946: return;
17947: }
17948:
17949: // ]]>
17950: </script>
17951:
17952: END
17953:
17954: }
17955:
1.236 raeburn 17956: sub toggle_display_js {
1.192 raeburn 17957: return <<"END";
17958:
17959: <script type="text/javascript">
17960: // <![CDATA[
17961:
1.236 raeburn 17962: function toggleDisplay(domForm,caller) {
17963: if (document.getElementById(caller)) {
17964: var divitem = document.getElementById(caller);
17965: var optionsElement = domForm.coursecredits;
1.264 raeburn 17966: var checkval = 1;
17967: var dispval = 'block';
1.303 raeburn 17968: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 17969: if (caller == 'emailoptions') {
17970: optionsElement = domForm.cancreate_email;
17971: }
1.257 raeburn 17972: if (caller == 'studentsubmission') {
17973: optionsElement = domForm.postsubmit;
17974: }
1.264 raeburn 17975: if (caller == 'cloneinstcode') {
17976: optionsElement = domForm.canclone;
17977: checkval = 'instcode';
17978: }
1.303 raeburn 17979: if (selfcreateRegExp.test(caller)) {
17980: optionsElement = domForm.elements[caller];
17981: checkval = 'other';
17982: dispval = 'inline'
17983: }
1.236 raeburn 17984: if (optionsElement.length) {
1.192 raeburn 17985: var currval;
1.236 raeburn 17986: for (var i=0; i<optionsElement.length; i++) {
17987: if (optionsElement[i].checked) {
17988: currval = optionsElement[i].value;
1.192 raeburn 17989: }
17990: }
1.264 raeburn 17991: if (currval == checkval) {
17992: divitem.style.display = dispval;
1.192 raeburn 17993: } else {
1.236 raeburn 17994: divitem.style.display = 'none';
1.192 raeburn 17995: }
17996: }
17997: }
17998: return;
17999: }
18000:
18001: // ]]>
18002: </script>
18003:
18004: END
18005:
18006: }
18007:
1.165 raeburn 18008: sub captcha_phrases {
18009: return &Apache::lonlocal::texthash (
18010: priv => 'Private key',
18011: pub => 'Public key',
18012: original => 'original (CAPTCHA)',
18013: recaptcha => 'successor (ReCAPTCHA)',
18014: notused => 'unused',
1.289 raeburn 18015: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 18016: );
18017: }
18018:
1.205 raeburn 18019: sub devalidate_remote_domconfs {
1.212 raeburn 18020: my ($dom,$cachekeys) = @_;
18021: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 18022: my %servers = &Apache::lonnet::internet_dom_servers($dom);
18023: my %thismachine;
18024: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.295 raeburn 18025: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions','directorysrch');
1.260 raeburn 18026: if (keys(%servers)) {
1.205 raeburn 18027: foreach my $server (keys(%servers)) {
18028: next if ($thismachine{$server});
1.212 raeburn 18029: my @cached;
18030: foreach my $name (@posscached) {
18031: if ($cachekeys->{$name}) {
18032: push(@cached,&escape($name).':'.&escape($dom));
18033: }
18034: }
18035: if (@cached) {
18036: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
18037: }
1.205 raeburn 18038: }
18039: }
18040: return;
18041: }
18042:
1.3 raeburn 18043: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>