Annotation of loncom/interface/domainprefs.pm, revision 1.323
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.323 ! raeburn 4: # $Id: domainprefs.pm,v 1.322 2017/12/07 01:36:11 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.271 raeburn 107: (official, unofficial, community, textbook, and placement).
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',},
355: {col1 => 'Ask helpdesk form settings',
356: col2 => 'Value',},],
1.230 raeburn 357: print => \&print_contacts,
358: modify => \&modify_contacts,
1.30 raeburn 359: },
360: 'usercreation' =>
361: { text => 'User creation',
1.67 raeburn 362: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 363: header => [{col1 => 'Format rule type',
364: col2 => 'Format rules in force'},
1.34 raeburn 365: {col1 => 'User account creation',
366: col2 => 'Usernames which may be created',},
1.30 raeburn 367: {col1 => 'Context',
1.43 raeburn 368: col2 => 'Assignable authentication types'}],
1.230 raeburn 369: print => \&print_usercreation,
370: modify => \&modify_usercreation,
1.30 raeburn 371: },
1.224 raeburn 372: 'selfcreation' =>
373: { text => 'Users self-creating accounts',
374: help => 'Domain_Configuration_Self_Creation',
375: header => [{col1 => 'Self-creation with institutional username',
376: col2 => 'Enabled?'},
377: {col1 => 'Institutional user type (login/SSO self-creation)',
378: col2 => 'Information user can enter'},
1.303 raeburn 379: {col1 => 'Self-creation with e-mail verification',
1.224 raeburn 380: col2 => 'Settings'}],
1.230 raeburn 381: print => \&print_selfcreation,
382: modify => \&modify_selfcreation,
1.224 raeburn 383: },
1.69 raeburn 384: 'usermodification' =>
1.33 raeburn 385: { text => 'User modification',
1.67 raeburn 386: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 387: header => [{col1 => 'Target user has role',
1.227 bisitz 388: col2 => 'User information updatable in author context'},
1.33 raeburn 389: {col1 => 'Target user has role',
1.227 bisitz 390: col2 => 'User information updatable in course context'}],
1.230 raeburn 391: print => \&print_usermodification,
392: modify => \&modify_usermodification,
1.33 raeburn 393: },
1.69 raeburn 394: 'scantron' =>
1.95 www 395: { text => 'Bubblesheet format file',
1.67 raeburn 396: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 397: header => [ {col1 => 'Item',
398: col2 => '',
399: }],
1.230 raeburn 400: print => \&print_scantron,
401: modify => \&modify_scantron,
1.46 raeburn 402: },
1.86 raeburn 403: 'requestcourses' =>
404: {text => 'Request creation of courses',
405: help => 'Domain_Configuration_Request_Courses',
406: header => [{col1 => 'User affiliation',
1.102 raeburn 407: col2 => 'Availability/Processing of requests',},
408: {col1 => 'Setting',
1.216 raeburn 409: col2 => 'Value'},
410: {col1 => 'Available textbooks',
1.235 raeburn 411: col2 => ''},
1.242 raeburn 412: {col1 => 'Available templates',
413: col2 => ''},
1.235 raeburn 414: {col1 => 'Validation (not official courses)',
415: col2 => 'Value'},],
1.230 raeburn 416: print => \&print_quotas,
417: modify => \&modify_quotas,
1.86 raeburn 418: },
1.163 raeburn 419: 'requestauthor' =>
1.223 bisitz 420: {text => 'Request Authoring Space',
1.163 raeburn 421: help => 'Domain_Configuration_Request_Author',
422: header => [{col1 => 'User affiliation',
423: col2 => 'Availability/Processing of requests',},
424: {col1 => 'Setting',
425: col2 => 'Value'}],
1.230 raeburn 426: print => \&print_quotas,
427: modify => \&modify_quotas,
1.163 raeburn 428: },
1.69 raeburn 429: 'coursecategories' =>
1.120 raeburn 430: { text => 'Cataloging of courses/communities',
1.67 raeburn 431: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 432: header => [{col1 => 'Catalog type/availability',
433: col2 => '',},
434: {col1 => 'Category settings for standard catalog',
1.57 raeburn 435: col2 => '',},
436: {col1 => 'Categories',
437: col2 => '',
438: }],
1.230 raeburn 439: print => \&print_coursecategories,
440: modify => \&modify_coursecategories,
1.69 raeburn 441: },
442: 'serverstatuses' =>
1.77 raeburn 443: {text => 'Access to server status pages',
1.69 raeburn 444: help => 'Domain_Configuration_Server_Status',
445: header => [{col1 => 'Status Page',
446: col2 => 'Other named users',
447: col3 => 'Specific IPs',
448: }],
1.230 raeburn 449: print => \&print_serverstatuses,
450: modify => \&modify_serverstatuses,
1.69 raeburn 451: },
1.118 jms 452: 'helpsettings' =>
1.282 raeburn 453: {text => 'Support settings',
1.118 jms 454: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 455: header => [{col1 => 'Help Page Settings (logged-in users)',
456: col2 => 'Value'},
457: {col1 => 'Helpdesk Roles',
458: col2 => 'Settings'},],
1.230 raeburn 459: print => \&print_helpsettings,
460: modify => \&modify_helpsettings,
1.118 jms 461: },
1.121 raeburn 462: 'coursedefaults' =>
463: {text => 'Course/Community defaults',
464: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 465: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
466: col2 => 'Value',},
467: {col1 => 'Defaults which can be overridden for each course by a DC',
468: col2 => 'Value',},],
1.230 raeburn 469: print => \&print_coursedefaults,
470: modify => \&modify_coursedefaults,
1.121 raeburn 471: },
1.231 raeburn 472: 'selfenrollment' =>
473: {text => 'Self-enrollment in Course/Community',
474: help => 'Domain_Configuration_Selfenrollment',
475: header => [{col1 => 'Configuration Rights',
476: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
477: {col1 => 'Defaults',
478: col2 => 'Value'},
479: {col1 => 'Self-enrollment validation (optional)',
480: col2 => 'Value'},],
481: print => \&print_selfenrollment,
482: modify => \&modify_selfenrollment,
483: },
1.120 raeburn 484: 'privacy' =>
485: {text => 'User Privacy',
486: help => 'Domain_Configuration_User_Privacy',
487: header => [{col1 => 'Setting',
488: col2 => 'Value',}],
1.230 raeburn 489: print => \&print_privacy,
490: modify => \&modify_privacy,
1.120 raeburn 491: },
1.141 raeburn 492: 'usersessions' =>
1.145 raeburn 493: {text => 'User session hosting/offloading',
1.137 raeburn 494: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 495: header => [{col1 => 'Domain server',
496: col2 => 'Servers to offload sessions to when busy'},
497: {col1 => 'Hosting of users from other domains',
1.137 raeburn 498: col2 => 'Rules'},
499: {col1 => "Hosting domain's own users elsewhere",
500: col2 => 'Rules'}],
1.230 raeburn 501: print => \&print_usersessions,
502: modify => \&modify_usersessions,
1.137 raeburn 503: },
1.279 raeburn 504: 'loadbalancing' =>
1.185 raeburn 505: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 506: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 507: header => [{col1 => 'Balancers',
1.150 raeburn 508: col2 => 'Default destinations',
1.183 bisitz 509: col3 => 'User affiliation',
1.150 raeburn 510: col4 => 'Overrides'},
511: ],
1.230 raeburn 512: print => \&print_loadbalancing,
513: modify => \&modify_loadbalancing,
1.150 raeburn 514: },
1.279 raeburn 515: 'ltitools' =>
1.267 raeburn 516: {text => 'External Tools (LTI)',
1.296 raeburn 517: help => 'Domain_Configuration_LTI_Tools',
1.267 raeburn 518: header => [{col1 => 'Setting',
519: col2 => 'Value',}],
520: print => \&print_ltitools,
521: modify => \&modify_ltitools,
522: },
1.279 raeburn 523: 'ssl' =>
1.275 raeburn 524: {text => 'LON-CAPA Network (SSL)',
525: help => 'Domain_Configuration_Network_SSL',
526: header => [{col1 => 'Server',
527: col2 => 'Certificate Status'},
528: {col1 => 'Connections to other servers',
529: col2 => 'Rules'},
1.293 raeburn 530: {col1 => 'Connections from other servers',
531: col2 => 'Rules'},
1.275 raeburn 532: {col1 => "Replicating domain's published content",
533: col2 => 'Rules'}],
534: print => \&print_ssl,
535: modify => \&modify_ssl,
536: },
1.279 raeburn 537: 'trust' =>
538: {text => 'Trust Settings',
539: help => 'Domain_Configuration_Trust',
540: header => [{col1 => "Access to this domain's content by others",
541: col2 => 'Rules'},
542: {col1 => "Access to other domain's content by this domain",
543: col2 => 'Rules'},
544: {col1 => "Enrollment in this domain's courses by others",
545: col2 => 'Rules',},
546: {col1 => "Co-author roles in this domain for others",
547: col2 => 'Rules',},
548: {col1 => "Co-author roles for this domain's users elsewhere",
549: col2 => 'Rules',},
550: {col1 => "Domain roles in this domain assignable to others",
551: col2 => 'Rules'},
552: {col1 => "Course catalog for this domain displayed elsewhere",
553: col2 => 'Rules'},
554: {col1 => "Requests for creation of courses in this domain by others",
555: col2 => 'Rules'},
556: {col1 => "Users in other domains can send messages to this domain",
557: col2 => 'Rules'},],
558: print => \&print_trust,
559: modify => \&modify_trust,
560: },
1.320 raeburn 561: 'lti' =>
562: {text => 'LTI Provider',
563: help => 'Domain_Configuration_LTI_Provider',
564: header => [{col1 => 'Setting',
565: col2 => 'Value',}],
566: print => \&print_lti,
567: modify => \&modify_lti,
568: },
1.3 raeburn 569: );
1.110 raeburn 570: if (keys(%servers) > 1) {
571: $prefs{'login'} = { text => 'Log-in page options',
572: help => 'Domain_Configuration_Login_Page',
573: header => [{col1 => 'Log-in Service',
574: col2 => 'Server Setting',},
575: {col1 => 'Log-in Page Items',
1.168 raeburn 576: col2 => ''},
577: {col1 => 'Log-in Help',
1.256 raeburn 578: col2 => 'Value'},
579: {col1 => 'Custom HTML in document head',
1.168 raeburn 580: col2 => 'Value'}],
1.230 raeburn 581: print => \&print_login,
582: modify => \&modify_login,
1.110 raeburn 583: };
584: }
1.174 foxr 585:
1.6 raeburn 586: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 587: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 588: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 589: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 590: text=>"Settings to display/modify"});
1.9 raeburn 591: my $confname = $dom.'-domainconfig';
1.174 foxr 592:
1.3 raeburn 593: if ($phase eq 'process') {
1.212 raeburn 594: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
595: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 596: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 597: $r->rflush();
1.212 raeburn 598: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 599: }
1.30 raeburn 600: } elsif ($phase eq 'display') {
1.192 raeburn 601: my $js = &recaptcha_js().
1.236 raeburn 602: &toggle_display_js();
1.171 raeburn 603: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 604: my ($othertitle,$usertypes,$types) =
605: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 606: $js .= &lonbalance_targets_js($dom,$types,\%servers,
607: $domconfig{'loadbalancing'}).
1.170 raeburn 608: &new_spares_js().
609: &common_domprefs_js().
610: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 611: }
1.216 raeburn 612: if (grep(/^requestcourses$/,@actions)) {
613: my $javascript_validations;
614: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
615: $js .= <<END;
616: <script type="text/javascript">
617: $javascript_validations
618: </script>
619: $coursebrowserjs
620: END
621: }
1.305 raeburn 622: if (grep(/^selfcreation$/,@actions)) {
623: $js .= &selfcreate_javascript();
624: }
1.286 raeburn 625: if (grep(/^contacts$/,@actions)) {
626: $js .= &contacts_javascript();
627: }
1.150 raeburn 628: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 629: } else {
1.180 raeburn 630: # check if domconfig user exists for the domain.
631: my $servadm = $r->dir_config('lonAdmEMail');
632: my ($configuserok,$author_ok,$switchserver) =
633: &config_check($dom,$confname,$servadm);
634: unless ($configuserok eq 'ok') {
1.181 raeburn 635: &Apache::lonconfigsettings::print_header($r,$phase,$context);
636: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 637: $confname).
1.181 raeburn 638: '<br />'
639: );
1.180 raeburn 640: if ($switchserver) {
1.181 raeburn 641: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
642: '<br />'.
643: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
644: '<br />'.
645: &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).
646: '<br />'.
647: &mt('To do that now, use the following link: [_1]',$switchserver)
648: );
649: } else {
650: $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.').
651: '<br />'.
652: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
653: );
1.180 raeburn 654: }
655: $r->print(&Apache::loncommon::end_page());
656: return OK;
657: }
1.21 raeburn 658: if (keys(%domconfig) == 0) {
659: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 660: my @ids=&Apache::lonnet::current_machine_ids();
661: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 662: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 663: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 664: my $custom_img_count = 0;
665: foreach my $img (@loginimages) {
666: if ($designhash{$dom.'.login.'.$img} ne '') {
667: $custom_img_count ++;
668: }
669: }
670: foreach my $role (@roles) {
671: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
672: $custom_img_count ++;
673: }
674: }
675: if ($custom_img_count > 0) {
1.94 raeburn 676: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 677: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 678: $r->print(
679: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
680: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
681: &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 />'.
682: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
683: if ($switch_server) {
1.30 raeburn 684: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 685: }
1.91 raeburn 686: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 687: return OK;
688: }
689: }
690: }
1.91 raeburn 691: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 692: }
693: return OK;
694: }
695:
696: sub process_changes {
1.205 raeburn 697: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 698: my %domconfig;
699: if (ref($values) eq 'HASH') {
700: %domconfig = %{$values};
701: }
1.3 raeburn 702: my $output;
703: if ($action eq 'login') {
1.205 raeburn 704: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 705: } elsif ($action eq 'rolecolors') {
1.9 raeburn 706: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 707: $lastactref,%domconfig);
1.3 raeburn 708: } elsif ($action eq 'quotas') {
1.216 raeburn 709: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 710: } elsif ($action eq 'autoenroll') {
1.205 raeburn 711: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 712: } elsif ($action eq 'autoupdate') {
713: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 714: } elsif ($action eq 'autocreate') {
715: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 716: } elsif ($action eq 'directorysrch') {
1.295 raeburn 717: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 718: } elsif ($action eq 'usercreation') {
1.28 raeburn 719: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 720: } elsif ($action eq 'selfcreation') {
1.305 raeburn 721: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 722: } elsif ($action eq 'usermodification') {
723: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 724: } elsif ($action eq 'contacts') {
1.205 raeburn 725: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 726: } elsif ($action eq 'defaults') {
1.212 raeburn 727: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 728: } elsif ($action eq 'scantron') {
1.205 raeburn 729: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 730: } elsif ($action eq 'coursecategories') {
1.239 raeburn 731: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 732: } elsif ($action eq 'serverstatuses') {
733: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 734: } elsif ($action eq 'requestcourses') {
1.216 raeburn 735: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 736: } elsif ($action eq 'requestauthor') {
1.216 raeburn 737: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 738: } elsif ($action eq 'helpsettings') {
1.285 raeburn 739: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 740: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 741: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 742: } elsif ($action eq 'selfenrollment') {
743: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 744: } elsif ($action eq 'usersessions') {
1.212 raeburn 745: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 746: } elsif ($action eq 'loadbalancing') {
747: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 748: } elsif ($action eq 'ltitools') {
749: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 750: } elsif ($action eq 'ssl') {
751: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 752: } elsif ($action eq 'trust') {
753: $output = &modify_trust($dom,$lastactref,%domconfig);
1.320 raeburn 754: } elsif ($action eq 'lti') {
755: $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 756: }
757: return $output;
758: }
759:
760: sub print_config_box {
1.9 raeburn 761: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 762: my $rowtotal = 0;
1.49 raeburn 763: my $output;
764: if ($action eq 'coursecategories') {
765: $output = &coursecategories_javascript($settings);
1.236 raeburn 766: } elsif ($action eq 'defaults') {
767: $output = &defaults_javascript($settings);
1.282 raeburn 768: } elsif ($action eq 'helpsettings') {
769: my (%privs,%levelscurrent);
770: my %full=();
771: my %levels=(
772: course => {},
773: domain => {},
774: system => {},
775: );
776: my $context = 'domain';
777: my $crstype = 'Course';
778: my $formname = 'display';
779: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
780: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
781: $output =
782: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
783: \@templateroles);
1.91 raeburn 784: }
1.236 raeburn 785: $output .=
1.30 raeburn 786: '<table class="LC_nested_outer">
1.3 raeburn 787: <tr>
1.306 raeburn 788: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 789: &mt($item->{text}).' '.
790: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
791: '</tr>';
1.30 raeburn 792: $rowtotal ++;
1.110 raeburn 793: my $numheaders = 1;
794: if (ref($item->{'header'}) eq 'ARRAY') {
795: $numheaders = scalar(@{$item->{'header'}});
796: }
797: if ($numheaders > 1) {
1.64 raeburn 798: my $colspan = '';
1.145 raeburn 799: my $rightcolspan = '';
1.238 raeburn 800: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 801: ($action eq 'directorysrch') ||
1.256 raeburn 802: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 803: $colspan = ' colspan="2"';
804: }
1.145 raeburn 805: if ($action eq 'usersessions') {
806: $rightcolspan = ' colspan="3"';
807: }
1.30 raeburn 808: $output .= '
1.3 raeburn 809: <tr>
810: <td>
811: <table class="LC_nested">
812: <tr class="LC_info_row">
1.59 bisitz 813: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 814: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 815: </tr>';
1.69 raeburn 816: $rowtotal ++;
1.230 raeburn 817: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 818: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 819: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 820: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
821: ($action eq 'contacts')) {
1.230 raeburn 822: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 823: } elsif ($action eq 'coursecategories') {
1.230 raeburn 824: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 825: } elsif ($action eq 'login') {
1.256 raeburn 826: if ($numheaders == 4) {
1.168 raeburn 827: $colspan = ' colspan="2"';
828: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
829: } else {
830: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
831: }
1.230 raeburn 832: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 833: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 834: } elsif ($action eq 'rolecolors') {
1.30 raeburn 835: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 836: }
1.30 raeburn 837: $output .= '
1.6 raeburn 838: </table>
839: </td>
840: </tr>
841: <tr>
842: <td>
843: <table class="LC_nested">
844: <tr class="LC_info_row">
1.230 raeburn 845: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 846: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 847: </tr>';
848: $rowtotal ++;
1.230 raeburn 849: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
850: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 851: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.294 raeburn 852: ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults')) {
1.238 raeburn 853: if ($action eq 'coursecategories') {
854: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
855: $colspan = ' colspan="2"';
1.279 raeburn 856: } elsif ($action eq 'trust') {
857: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.238 raeburn 858: } else {
859: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
860: }
1.279 raeburn 861: if ($action eq 'trust') {
862: $output .= '
863: </table>
864: </td>
865: </tr>';
866: my @trusthdrs = qw(2 3 4 5 6 7);
867: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
868: for (my $i=0; $i<@trusthdrs; $i++) {
869: $output .= '
870: <tr>
871: <td>
872: <table class="LC_nested">
873: <tr class="LC_info_row">
874: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
875: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
876: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
877: </table>
878: </td>
879: </tr>';
880: }
881: $output .= '
882: <tr>
883: <td>
884: <table class="LC_nested">
885: <tr class="LC_info_row">
886: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
887: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
888: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
889: } else {
890: $output .= '
1.63 raeburn 891: </table>
892: </td>
893: </tr>
894: <tr>
895: <td>
896: <table class="LC_nested">
897: <tr class="LC_info_row">
898: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 899: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 900: </tr>'."\n";
1.279 raeburn 901: if ($action eq 'coursecategories') {
902: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
903: } else {
904: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
905: }
1.238 raeburn 906: }
1.63 raeburn 907: $rowtotal ++;
1.236 raeburn 908: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.282 raeburn 909: ($action eq 'defaults') || ($action eq 'directorysrch') ||
910: ($action eq 'helpsettings')) {
1.230 raeburn 911: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.293 raeburn 912: } elsif ($action eq 'ssl') {
913: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
914: </table>
915: </td>
916: </tr>
917: <tr>
918: <td>
919: <table class="LC_nested">
920: <tr class="LC_info_row">
921: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
922: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
923: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
924: </table>
925: </td>
926: </tr>
927: <tr>
928: <td>
929: <table class="LC_nested">
930: <tr class="LC_info_row">
931: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
932: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
933: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 934: } elsif ($action eq 'login') {
1.256 raeburn 935: if ($numheaders == 4) {
1.168 raeburn 936: $output .= &print_login('page',$dom,$confname,$phase,$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>
1.216 raeburn 945: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 946: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
947: $rowtotal ++;
948: } else {
949: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
950: }
1.256 raeburn 951: $output .= '
952: </table>
953: </td>
954: </tr>
955: <tr>
956: <td>
957: <table class="LC_nested">
958: <tr class="LC_info_row">';
959: if ($numheaders == 4) {
960: $output .= '
961: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
962: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
963: </tr>';
964: } else {
965: $output .= '
966: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
967: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
968: </tr>';
969: }
970: $rowtotal ++;
971: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 972: } elsif ($action eq 'requestcourses') {
1.247 raeburn 973: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
974: $rowtotal ++;
975: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 976: </table>
977: </td>
978: </tr>
979: <tr>
980: <td>
981: <table class="LC_nested">
982: <tr class="LC_info_row">
983: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
984: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 985: &textbookcourses_javascript($settings).
986: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
987: </table>
988: </td>
989: </tr>
990: <tr>
991: <td>
992: <table class="LC_nested">
993: <tr class="LC_info_row">
994: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
995: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
996: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 997: </table>
998: </td>
999: </tr>
1000: <tr>
1001: <td>
1002: <table class="LC_nested">
1003: <tr class="LC_info_row">
1.306 raeburn 1004: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1005: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1006: </tr>'.
1007: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1008: } elsif ($action eq 'requestauthor') {
1009: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1010: $rowtotal ++;
1.122 jms 1011: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1012: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1013: </table>
1014: </td>
1015: </tr>
1016: <tr>
1017: <td>
1018: <table class="LC_nested">
1019: <tr class="LC_info_row">
1.306 raeburn 1020: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 1021: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1022: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1023: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1024: </tr>'.
1.30 raeburn 1025: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1026: </table>
1027: </td>
1028: </tr>
1029: <tr>
1030: <td>
1031: <table class="LC_nested">
1032: <tr class="LC_info_row">
1.59 bisitz 1033: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1034: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1035: </tr>'.
1.30 raeburn 1036: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1037: $rowtotal += 2;
1.6 raeburn 1038: }
1.3 raeburn 1039: } else {
1.30 raeburn 1040: $output .= '
1.3 raeburn 1041: <tr>
1042: <td>
1043: <table class="LC_nested">
1.30 raeburn 1044: <tr class="LC_info_row">';
1.277 raeburn 1045: if ($action eq 'login') {
1.30 raeburn 1046: $output .= '
1.59 bisitz 1047: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1048: } elsif ($action eq 'serverstatuses') {
1049: $output .= '
1.306 raeburn 1050: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1051: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1052:
1.6 raeburn 1053: } else {
1.30 raeburn 1054: $output .= '
1.306 raeburn 1055: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1056: }
1.72 raeburn 1057: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1058: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1059: &mt($item->{'header'}->[0]->{'col2'});
1060: if ($action eq 'serverstatuses') {
1061: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1062: }
1.69 raeburn 1063: } else {
1.306 raeburn 1064: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1065: &mt($item->{'header'}->[0]->{'col2'});
1066: }
1067: $output .= '</td>';
1068: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1069: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1070: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1071: &mt($item->{'header'}->[0]->{'col3'});
1072: } else {
1.306 raeburn 1073: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1074: &mt($item->{'header'}->[0]->{'col3'});
1075: }
1.69 raeburn 1076: if ($action eq 'serverstatuses') {
1077: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1078: }
1079: $output .= '</td>';
1.6 raeburn 1080: }
1.150 raeburn 1081: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1082: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1083: &mt($item->{'header'}->[0]->{'col4'});
1084: }
1.69 raeburn 1085: $output .= '</tr>';
1.48 raeburn 1086: $rowtotal ++;
1.168 raeburn 1087: if ($action eq 'quotas') {
1.86 raeburn 1088: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1089: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1090: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.320 raeburn 1091: ($action eq 'ltitools') || ($action eq 'lti')) {
1.230 raeburn 1092: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 1093: } elsif ($action eq 'scantron') {
1094: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.121 raeburn 1095: }
1.3 raeburn 1096: }
1.30 raeburn 1097: $output .= '
1.3 raeburn 1098: </table>
1099: </td>
1100: </tr>
1.30 raeburn 1101: </table><br />';
1102: return ($output,$rowtotal);
1.1 raeburn 1103: }
1104:
1.3 raeburn 1105: sub print_login {
1.168 raeburn 1106: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 1107: my ($css_class,$datatable);
1.6 raeburn 1108: my %choices = &login_choices();
1.110 raeburn 1109:
1.168 raeburn 1110: if ($caller eq 'service') {
1.149 raeburn 1111: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1112: my $choice = $choices{'disallowlogin'};
1113: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1114: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1115: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1116: '<th>'.$choices{'server'}.'</th>'.
1117: '<th>'.$choices{'serverpath'}.'</th>'.
1118: '<th>'.$choices{'custompath'}.'</th>'.
1119: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1120: my %disallowed;
1121: if (ref($settings) eq 'HASH') {
1122: if (ref($settings->{'loginvia'}) eq 'HASH') {
1123: %disallowed = %{$settings->{'loginvia'}};
1124: }
1125: }
1126: foreach my $lonhost (sort(keys(%servers))) {
1127: my $direct = 'selected="selected"';
1.128 raeburn 1128: if (ref($disallowed{$lonhost}) eq 'HASH') {
1129: if ($disallowed{$lonhost}{'server'} ne '') {
1130: $direct = '';
1131: }
1.110 raeburn 1132: }
1.115 raeburn 1133: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1134: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1135: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1136: '</option>';
1.184 raeburn 1137: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1138: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1139: my $selected = '';
1.128 raeburn 1140: if (ref($disallowed{$lonhost}) eq 'HASH') {
1141: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1142: $selected = 'selected="selected"';
1143: }
1.110 raeburn 1144: }
1145: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1146: $servers{$hostid}.'</option>';
1147: }
1.128 raeburn 1148: $datatable .= '</select></td>'.
1149: '<td><select name="'.$lonhost.'_serverpath">';
1150: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1151: my $pathname = $path;
1152: if ($path eq 'custom') {
1153: $pathname = &mt('Custom Path').' ->';
1154: }
1155: my $selected = '';
1156: if (ref($disallowed{$lonhost}) eq 'HASH') {
1157: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1158: $selected = 'selected="selected"';
1159: }
1160: } elsif ($path eq '') {
1161: $selected = 'selected="selected"';
1162: }
1163: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1164: }
1165: $datatable .= '</select></td>';
1166: my ($custom,$exempt);
1167: if (ref($disallowed{$lonhost}) eq 'HASH') {
1168: $custom = $disallowed{$lonhost}{'custompath'};
1169: $exempt = $disallowed{$lonhost}{'exempt'};
1170: }
1171: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1172: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1173: '</tr>';
1.110 raeburn 1174: }
1175: $datatable .= '</table></td></tr>';
1176: return $datatable;
1.168 raeburn 1177: } elsif ($caller eq 'page') {
1178: my %defaultchecked = (
1179: 'coursecatalog' => 'on',
1.188 raeburn 1180: 'helpdesk' => 'on',
1.168 raeburn 1181: 'adminmail' => 'off',
1182: 'newuser' => 'off',
1183: );
1.188 raeburn 1184: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1185: my (%checkedon,%checkedoff);
1.42 raeburn 1186: foreach my $item (@toggles) {
1.168 raeburn 1187: if ($defaultchecked{$item} eq 'on') {
1188: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1189: $checkedoff{$item} = ' ';
1.168 raeburn 1190: } elsif ($defaultchecked{$item} eq 'off') {
1191: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1192: $checkedon{$item} = ' ';
1193: }
1.1 raeburn 1194: }
1.168 raeburn 1195: my @images = ('img','logo','domlogo','login');
1196: my @logintext = ('textcol','bgcol');
1197: my @bgs = ('pgbg','mainbg','sidebg');
1198: my @links = ('link','alink','vlink');
1199: my %designhash = &Apache::loncommon::get_domainconf($dom);
1200: my %defaultdesign = %Apache::loncommon::defaultdesign;
1201: my (%is_custom,%designs);
1202: my %defaults = (
1203: font => $defaultdesign{'login.font'},
1204: );
1.6 raeburn 1205: foreach my $item (@images) {
1.168 raeburn 1206: $defaults{$item} = $defaultdesign{'login.'.$item};
1207: $defaults{'showlogo'}{$item} = 1;
1208: }
1209: foreach my $item (@bgs) {
1210: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1211: }
1.41 raeburn 1212: foreach my $item (@logintext) {
1.168 raeburn 1213: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1214: }
1.168 raeburn 1215: foreach my $item (@links) {
1216: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1217: }
1.168 raeburn 1218: if (ref($settings) eq 'HASH') {
1219: foreach my $item (@toggles) {
1220: if ($settings->{$item} eq '1') {
1221: $checkedon{$item} = ' checked="checked" ';
1222: $checkedoff{$item} = ' ';
1223: } elsif ($settings->{$item} eq '0') {
1224: $checkedoff{$item} = ' checked="checked" ';
1225: $checkedon{$item} = ' ';
1226: }
1227: }
1228: foreach my $item (@images) {
1229: if (defined($settings->{$item})) {
1230: $designs{$item} = $settings->{$item};
1231: $is_custom{$item} = 1;
1232: }
1233: if (defined($settings->{'showlogo'}{$item})) {
1234: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1235: }
1236: }
1237: foreach my $item (@logintext) {
1238: if ($settings->{$item} ne '') {
1239: $designs{'logintext'}{$item} = $settings->{$item};
1240: $is_custom{$item} = 1;
1241: }
1242: }
1243: if ($settings->{'font'} ne '') {
1244: $designs{'font'} = $settings->{'font'};
1245: $is_custom{'font'} = 1;
1246: }
1247: foreach my $item (@bgs) {
1248: if ($settings->{$item} ne '') {
1249: $designs{'bgs'}{$item} = $settings->{$item};
1250: $is_custom{$item} = 1;
1251: }
1252: }
1253: foreach my $item (@links) {
1254: if ($settings->{$item} ne '') {
1255: $designs{'links'}{$item} = $settings->{$item};
1256: $is_custom{$item} = 1;
1257: }
1258: }
1259: } else {
1260: if ($designhash{$dom.'.login.font'} ne '') {
1261: $designs{'font'} = $designhash{$dom.'.login.font'};
1262: $is_custom{'font'} = 1;
1263: }
1264: foreach my $item (@images) {
1265: if ($designhash{$dom.'.login.'.$item} ne '') {
1266: $designs{$item} = $designhash{$dom.'.login.'.$item};
1267: $is_custom{$item} = 1;
1268: }
1269: }
1270: foreach my $item (@bgs) {
1271: if ($designhash{$dom.'.login.'.$item} ne '') {
1272: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1273: $is_custom{$item} = 1;
1274: }
1.6 raeburn 1275: }
1.168 raeburn 1276: foreach my $item (@links) {
1277: if ($designhash{$dom.'.login.'.$item} ne '') {
1278: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1279: $is_custom{$item} = 1;
1280: }
1.6 raeburn 1281: }
1282: }
1.168 raeburn 1283: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1284: logo => 'Institution Logo',
1285: domlogo => 'Domain Logo',
1286: login => 'Login box');
1287: my $itemcount = 1;
1288: foreach my $item (@toggles) {
1289: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1290: $datatable .=
1291: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1292: '</td><td>'.
1293: '<span class="LC_nobreak"><label><input type="radio" name="'.
1294: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1295: '</label> <label><input type="radio" name="'.$item.'"'.
1296: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1297: '</tr>';
1298: $itemcount ++;
1.6 raeburn 1299: }
1.168 raeburn 1300: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1301: $datatable .= '</tr></table></td></tr>';
1302: } elsif ($caller eq 'help') {
1303: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1304: my $switchserver = &check_switchserver($dom,$confname);
1305: my $itemcount = 1;
1306: $defaulturl = '/adm/loginproblems.html';
1307: $defaulttype = 'default';
1308: %lt = &Apache::lonlocal::texthash (
1309: del => 'Delete?',
1310: rep => 'Replace:',
1311: upl => 'Upload:',
1312: default => 'Default',
1313: custom => 'Custom',
1314: );
1315: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1316: my @currlangs;
1317: if (ref($settings) eq 'HASH') {
1318: if (ref($settings->{'helpurl'}) eq 'HASH') {
1319: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1320: next if ($settings->{'helpurl'}{$key} eq '');
1321: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1322: $type{$key} = 'custom';
1323: unless ($key eq 'nolang') {
1324: push(@currlangs,$key);
1325: }
1326: }
1327: } elsif ($settings->{'helpurl'} ne '') {
1328: $type{'nolang'} = 'custom';
1329: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1330: }
1331: }
1.168 raeburn 1332: foreach my $lang ('nolang',sort(@currlangs)) {
1333: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1334: $datatable .= '<tr'.$css_class.'>';
1335: if ($url{$lang} eq '') {
1336: $url{$lang} = $defaulturl;
1337: }
1338: if ($type{$lang} eq '') {
1339: $type{$lang} = $defaulttype;
1340: }
1341: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1342: if ($lang eq 'nolang') {
1343: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1344: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1345: } else {
1346: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1347: $langchoices{$lang},
1348: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1349: }
1350: $datatable .= '</span></td>'."\n".
1351: '<td class="LC_left_item">';
1352: if ($type{$lang} eq 'custom') {
1353: $datatable .= '<span class="LC_nobreak"><label>'.
1354: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1355: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1356: } else {
1357: $datatable .= $lt{'upl'};
1358: }
1359: $datatable .='<br />';
1360: if ($switchserver) {
1361: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1362: } else {
1363: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1364: }
1.168 raeburn 1365: $datatable .= '</td></tr>';
1366: $itemcount ++;
1.6 raeburn 1367: }
1.168 raeburn 1368: my @addlangs;
1369: foreach my $lang (sort(keys(%langchoices))) {
1370: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1371: push(@addlangs,$lang);
1372: }
1373: if (@addlangs > 0) {
1374: my %toadd;
1375: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1376: $toadd{''} = &mt('Select');
1377: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1378: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1379: &mt('Add log-in help page for a specific language:').' '.
1380: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1381: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1382: if ($switchserver) {
1383: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1384: } else {
1385: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1386: }
1.168 raeburn 1387: $datatable .= '</td></tr>';
1.169 raeburn 1388: $itemcount ++;
1.6 raeburn 1389: }
1.169 raeburn 1390: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1391: } elsif ($caller eq 'headtag') {
1392: my %domservers = &Apache::lonnet::get_servers($dom);
1393: my $choice = $choices{'headtag'};
1394: $css_class = ' class="LC_odd_row"';
1395: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1396: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1397: '<th>'.$choices{'current'}.'</th>'.
1398: '<th>'.$choices{'action'}.'</th>'.
1399: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1400: my (%currurls,%currexempt);
1401: if (ref($settings) eq 'HASH') {
1402: if (ref($settings->{'headtag'}) eq 'HASH') {
1403: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1404: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1405: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1406: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1407: }
1408: }
1409: }
1410: }
1411: my %lt = &Apache::lonlocal::texthash(
1412: del => 'Delete?',
1413: rep => 'Replace:',
1414: upl => 'Upload:',
1415: curr => 'View contents',
1416: none => 'None',
1417: );
1418: my $switchserver = &check_switchserver($dom,$confname);
1419: foreach my $lonhost (sort(keys(%domservers))) {
1420: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1421: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1422: if ($currurls{$lonhost}) {
1423: $datatable .= '<td class="LC_right_item"><a href="'.
1424: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1425: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1426: '">'.$lt{'curr'}.'</a></td>'.
1427: '<td><span class="LC_nobreak"><label>'.
1428: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1429: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1430: } else {
1431: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1432: }
1433: $datatable .='<br />';
1434: if ($switchserver) {
1435: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1436: } else {
1437: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1438: }
1439: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1440: }
1441: $datatable .= '</table></td></tr>';
1.1 raeburn 1442: }
1.6 raeburn 1443: return $datatable;
1444: }
1445:
1446: sub login_choices {
1447: my %choices =
1448: &Apache::lonlocal::texthash (
1.116 bisitz 1449: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1450: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1451: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1452: disallowlogin => "Login page requests redirected",
1453: hostid => "Server",
1.128 raeburn 1454: server => "Redirect to:",
1455: serverpath => "Path",
1456: custompath => "Custom",
1457: exempt => "Exempt IP(s)",
1.110 raeburn 1458: directlogin => "No redirect",
1459: newuser => "Link to create a user account",
1460: img => "Header",
1461: logo => "Main Logo",
1462: domlogo => "Domain Logo",
1463: login => "Log-in Header",
1464: textcol => "Text color",
1465: bgcol => "Box color",
1466: bgs => "Background colors",
1467: links => "Link colors",
1468: font => "Font color",
1469: pgbg => "Header",
1470: mainbg => "Page",
1471: sidebg => "Login box",
1472: link => "Link",
1473: alink => "Active link",
1474: vlink => "Visited link",
1.256 raeburn 1475: headtag => "Custom markup",
1476: action => "Action",
1477: current => "Current",
1.6 raeburn 1478: );
1479: return %choices;
1480: }
1481:
1482: sub print_rolecolors {
1.30 raeburn 1483: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1484: my %choices = &color_font_choices();
1485: my @bgs = ('pgbg','tabbg','sidebg');
1486: my @links = ('link','alink','vlink');
1487: my @images = ('img');
1488: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1489: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1490: my %defaultdesign = %Apache::loncommon::defaultdesign;
1491: my (%is_custom,%designs);
1.200 raeburn 1492: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1493: if (ref($settings) eq 'HASH') {
1494: if (ref($settings->{$role}) eq 'HASH') {
1495: if ($settings->{$role}->{'img'} ne '') {
1496: $designs{'img'} = $settings->{$role}->{'img'};
1497: $is_custom{'img'} = 1;
1498: }
1499: if ($settings->{$role}->{'font'} ne '') {
1500: $designs{'font'} = $settings->{$role}->{'font'};
1501: $is_custom{'font'} = 1;
1502: }
1.97 tempelho 1503: if ($settings->{$role}->{'fontmenu'} ne '') {
1504: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1505: $is_custom{'fontmenu'} = 1;
1506: }
1.6 raeburn 1507: foreach my $item (@bgs) {
1508: if ($settings->{$role}->{$item} ne '') {
1509: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1510: $is_custom{$item} = 1;
1511: }
1512: }
1513: foreach my $item (@links) {
1514: if ($settings->{$role}->{$item} ne '') {
1515: $designs{'links'}{$item} = $settings->{$role}->{$item};
1516: $is_custom{$item} = 1;
1517: }
1518: }
1519: }
1520: } else {
1521: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1522: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1523: $is_custom{'img'} = 1;
1524: }
1.97 tempelho 1525: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1526: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1527: $is_custom{'fontmenu'} = 1;
1528: }
1.6 raeburn 1529: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1530: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1531: $is_custom{'font'} = 1;
1532: }
1533: foreach my $item (@bgs) {
1534: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1535: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1536: $is_custom{$item} = 1;
1537:
1538: }
1539: }
1540: foreach my $item (@links) {
1541: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1542: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1543: $is_custom{$item} = 1;
1544: }
1545: }
1546: }
1547: my $itemcount = 1;
1.30 raeburn 1548: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1549: $datatable .= '</tr></table></td></tr>';
1550: return $datatable;
1551: }
1552:
1.200 raeburn 1553: sub role_defaults {
1554: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1555: my %defaults;
1556: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1557: return %defaults;
1558: }
1559: my %defaultdesign = %Apache::loncommon::defaultdesign;
1560: if ($role eq 'login') {
1561: %defaults = (
1562: font => $defaultdesign{$role.'.font'},
1563: );
1564: if (ref($logintext) eq 'ARRAY') {
1565: foreach my $item (@{$logintext}) {
1566: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1567: }
1568: }
1569: foreach my $item (@{$images}) {
1570: $defaults{'showlogo'}{$item} = 1;
1571: }
1572: } else {
1573: %defaults = (
1574: img => $defaultdesign{$role.'.img'},
1575: font => $defaultdesign{$role.'.font'},
1576: fontmenu => $defaultdesign{$role.'.fontmenu'},
1577: );
1578: }
1579: foreach my $item (@{$bgs}) {
1580: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1581: }
1582: foreach my $item (@{$links}) {
1583: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1584: }
1585: foreach my $item (@{$images}) {
1586: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1587: }
1588: return %defaults;
1589: }
1590:
1.6 raeburn 1591: sub display_color_options {
1.9 raeburn 1592: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1593: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1594: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1595: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1596: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1597: '<td>'.$choices->{'font'}.'</td>';
1598: if (!$is_custom->{'font'}) {
1.30 raeburn 1599: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1600: } else {
1601: $datatable .= '<td> </td>';
1602: }
1.174 foxr 1603: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1604:
1.8 raeburn 1605: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1606: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1607: ' value="'.$current_color.'" /> '.
1.174 foxr 1608: ' </td></tr>';
1.107 raeburn 1609: unless ($role eq 'login') {
1610: $datatable .= '<tr'.$css_class.'>'.
1611: '<td>'.$choices->{'fontmenu'}.'</td>';
1612: if (!$is_custom->{'fontmenu'}) {
1613: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1614: } else {
1615: $datatable .= '<td> </td>';
1616: }
1.202 raeburn 1617: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1618: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1619: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1620: '<input class="colorchooser" type="text" size="10" name="'
1621: .$role.'_fontmenu"'.
1622: ' value="'.$current_color.'" /> '.
1623: ' </td></tr>';
1.97 tempelho 1624: }
1.9 raeburn 1625: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1626: foreach my $img (@{$images}) {
1.18 albertel 1627: $itemcount ++;
1.6 raeburn 1628: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1629: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1630: '<td>'.$choices->{$img};
1.41 raeburn 1631: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1632: if ($role eq 'login') {
1633: if ($img eq 'login') {
1634: $login_hdr_pick =
1.135 bisitz 1635: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1636: $logincolors =
1637: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1638: $designs,$defaults);
1.70 raeburn 1639: } elsif ($img ne 'domlogo') {
1640: $datatable.= &logo_display_options($img,$defaults,$designs);
1641: }
1642: }
1643: $datatable .= '</td>';
1.6 raeburn 1644: if ($designs->{$img} ne '') {
1645: $imgfile = $designs->{$img};
1.18 albertel 1646: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1647: } else {
1648: $imgfile = $defaults->{$img};
1649: }
1650: if ($imgfile) {
1.9 raeburn 1651: my ($showfile,$fullsize);
1652: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1653: my $urldir = $1;
1654: my $filename = $2;
1655: my @info = &Apache::lonnet::stat_file($designs->{$img});
1656: if (@info) {
1657: my $thumbfile = 'tn-'.$filename;
1658: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1659: if (@thumb) {
1660: $showfile = $urldir.'/'.$thumbfile;
1661: } else {
1662: $showfile = $imgfile;
1663: }
1664: } else {
1665: $showfile = '';
1666: }
1667: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1668: $showfile = $imgfile;
1.6 raeburn 1669: my $imgdir = $1;
1670: my $filename = $2;
1.159 raeburn 1671: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1672: $showfile = "/$imgdir/tn-".$filename;
1673: } else {
1.159 raeburn 1674: my $input = $londocroot.$imgfile;
1675: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1676: if (!-e $output) {
1.9 raeburn 1677: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1678: my ($fullwidth,$fullheight) = &check_dimensions($input);
1679: if ($fullwidth ne '' && $fullheight ne '') {
1680: if ($fullwidth > $width && $fullheight > $height) {
1681: my $size = $width.'x'.$height;
1.316 raeburn 1682: my @args = ('convert','-sample',$size,$input,$output);
1683: system({$args[0]} @args);
1.159 raeburn 1684: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1685: }
1686: }
1.6 raeburn 1687: }
1688: }
1.16 raeburn 1689: }
1.6 raeburn 1690: if ($showfile) {
1.40 raeburn 1691: if ($showfile =~ m{^/(adm|res)/}) {
1692: if ($showfile =~ m{^/res/}) {
1693: my $local_showfile =
1694: &Apache::lonnet::filelocation('',$showfile);
1695: &Apache::lonnet::repcopy($local_showfile);
1696: }
1697: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1698: }
1699: if ($imgfile) {
1700: if ($imgfile =~ m{^/(adm|res)/}) {
1701: if ($imgfile =~ m{^/res/}) {
1702: my $local_imgfile =
1703: &Apache::lonnet::filelocation('',$imgfile);
1704: &Apache::lonnet::repcopy($local_imgfile);
1705: }
1706: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1707: } else {
1708: $fullsize = $imgfile;
1709: }
1710: }
1.41 raeburn 1711: $datatable .= '<td>';
1712: if ($img eq 'login') {
1.135 bisitz 1713: $datatable .= $login_hdr_pick;
1714: }
1.41 raeburn 1715: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1716: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1717: } else {
1.201 raeburn 1718: $datatable .= '<td> </td><td class="LC_left_item">'.
1719: &mt('Upload:').'<br />';
1.6 raeburn 1720: }
1721: } else {
1.201 raeburn 1722: $datatable .= '<td> </td><td class="LC_left_item">'.
1723: &mt('Upload:').'<br />';
1.6 raeburn 1724: }
1.9 raeburn 1725: if ($switchserver) {
1726: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1727: } else {
1.135 bisitz 1728: if ($img ne 'login') { # suppress file selection for Log-in header
1729: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1730: }
1.9 raeburn 1731: }
1732: $datatable .= '</td></tr>';
1.6 raeburn 1733: }
1734: $itemcount ++;
1735: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1736: $datatable .= '<tr'.$css_class.'>'.
1737: '<td>'.$choices->{'bgs'}.'</td>';
1738: my $bgs_def;
1739: foreach my $item (@{$bgs}) {
1740: if (!$is_custom->{$item}) {
1.70 raeburn 1741: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span id="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 1742: }
1743: }
1744: if ($bgs_def) {
1.8 raeburn 1745: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1746: } else {
1747: $datatable .= '<td> </td>';
1748: }
1749: $datatable .= '<td class="LC_right_item">'.
1750: '<table border="0"><tr>';
1.174 foxr 1751:
1.6 raeburn 1752: foreach my $item (@{$bgs}) {
1.306 raeburn 1753: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 1754: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1755: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1756: $datatable .= ' ';
1.6 raeburn 1757: }
1.174 foxr 1758: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1759: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1760: }
1761: $datatable .= '</tr></table></td></tr>';
1762: $itemcount ++;
1763: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1764: $datatable .= '<tr'.$css_class.'>'.
1765: '<td>'.$choices->{'links'}.'</td>';
1766: my $links_def;
1767: foreach my $item (@{$links}) {
1768: if (!$is_custom->{$item}) {
1.30 raeburn 1769: $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 1770: }
1771: }
1772: if ($links_def) {
1.8 raeburn 1773: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1774: } else {
1775: $datatable .= '<td> </td>';
1776: }
1777: $datatable .= '<td class="LC_right_item">'.
1778: '<table border="0"><tr>';
1779: foreach my $item (@{$links}) {
1.234 raeburn 1780: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 1781: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 1782: if ($designs->{'links'}{$item}) {
1.174 foxr 1783: $datatable.=' ';
1.6 raeburn 1784: }
1.174 foxr 1785: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1786: '" /></td>';
1787: }
1.30 raeburn 1788: $$rowtotal += $itemcount;
1.3 raeburn 1789: return $datatable;
1790: }
1791:
1.70 raeburn 1792: sub logo_display_options {
1793: my ($img,$defaults,$designs) = @_;
1794: my $checkedon;
1795: if (ref($defaults) eq 'HASH') {
1796: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1797: if ($defaults->{'showlogo'}{$img}) {
1798: $checkedon = 'checked="checked" ';
1799: }
1800: }
1801: }
1802: if (ref($designs) eq 'HASH') {
1803: if (ref($designs->{'showlogo'}) eq 'HASH') {
1804: if (defined($designs->{'showlogo'}{$img})) {
1805: if ($designs->{'showlogo'}{$img} == 0) {
1806: $checkedon = '';
1807: } elsif ($designs->{'showlogo'}{$img} == 1) {
1808: $checkedon = 'checked="checked" ';
1809: }
1810: }
1811: }
1812: }
1813: return '<br /><label> <input type="checkbox" name="'.
1814: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1815: &mt('show').'</label>'."\n";
1816: }
1817:
1.41 raeburn 1818: sub login_header_options {
1.135 bisitz 1819: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1820: my $output = '';
1.41 raeburn 1821: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1822: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1823: if (!$is_custom->{'textcol'}) {
1824: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1825: ' ';
1826: }
1827: if (!$is_custom->{'bgcol'}) {
1828: $output .= $choices->{'bgcol'}.': '.
1829: '<span id="css_'.$role.'_font" style="background-color: '.
1830: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1831: }
1832: $output .= '<br />';
1833: }
1834: $output .='<br />';
1835: return $output;
1836: }
1837:
1838: sub login_text_colors {
1.201 raeburn 1839: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1840: my $color_menu = '<table border="0"><tr>';
1841: foreach my $item (@{$logintext}) {
1.306 raeburn 1842: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 1843: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1844: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1845: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1846: }
1847: $color_menu .= '</tr></table><br />';
1848: return $color_menu;
1849: }
1850:
1851: sub image_changes {
1852: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1853: my $output;
1.135 bisitz 1854: if ($img eq 'login') {
1855: # suppress image for Log-in header
1856: } elsif (!$is_custom) {
1.70 raeburn 1857: if ($img ne 'domlogo') {
1.41 raeburn 1858: $output .= &mt('Default image:').'<br />';
1859: } else {
1860: $output .= &mt('Default in use:').'<br />';
1861: }
1862: }
1.135 bisitz 1863: if ($img eq 'login') { # suppress image for Log-in header
1864: $output .= '<td>'.$logincolors;
1.41 raeburn 1865: } else {
1.135 bisitz 1866: if ($img_import) {
1867: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1868: }
1869: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1870: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1871: if ($is_custom) {
1872: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1873: '<input type="checkbox" name="'.
1874: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1875: '</label> '.&mt('Replace:').'</span><br />';
1876: } else {
1.306 raeburn 1877: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1878: }
1.41 raeburn 1879: }
1880: return $output;
1881: }
1882:
1.3 raeburn 1883: sub print_quotas {
1.86 raeburn 1884: my ($dom,$settings,$rowtotal,$action) = @_;
1885: my $context;
1886: if ($action eq 'quotas') {
1887: $context = 'tools';
1888: } else {
1889: $context = $action;
1890: }
1.197 raeburn 1891: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1892: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1893: my $typecount = 0;
1.101 raeburn 1894: my ($css_class,%titles);
1.86 raeburn 1895: if ($context eq 'requestcourses') {
1.271 raeburn 1896: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 1897: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1898: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1899: %titles = &courserequest_titles();
1.163 raeburn 1900: } elsif ($context eq 'requestauthor') {
1901: @usertools = ('author');
1902: @options = ('norequest','approval','automatic');
1.210 raeburn 1903: %titles = &authorrequest_titles();
1.86 raeburn 1904: } else {
1.162 raeburn 1905: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1906: %titles = &tool_titles();
1.86 raeburn 1907: }
1.26 raeburn 1908: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1909: foreach my $type (@{$types}) {
1.197 raeburn 1910: my ($currdefquota,$currauthorquota);
1.163 raeburn 1911: unless (($context eq 'requestcourses') ||
1912: ($context eq 'requestauthor')) {
1.86 raeburn 1913: if (ref($settings) eq 'HASH') {
1914: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1915: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1916: } else {
1917: $currdefquota = $settings->{$type};
1918: }
1.197 raeburn 1919: if (ref($settings->{authorquota}) eq 'HASH') {
1920: $currauthorquota = $settings->{authorquota}->{$type};
1921: }
1.78 raeburn 1922: }
1.72 raeburn 1923: }
1.3 raeburn 1924: if (defined($usertypes->{$type})) {
1925: $typecount ++;
1926: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1927: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1928: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1929: '<td class="LC_left_item">';
1.101 raeburn 1930: if ($context eq 'requestcourses') {
1931: $datatable .= '<table><tr>';
1932: }
1933: my %cell;
1.72 raeburn 1934: foreach my $item (@usertools) {
1.101 raeburn 1935: if ($context eq 'requestcourses') {
1936: my ($curroption,$currlimit);
1937: if (ref($settings) eq 'HASH') {
1938: if (ref($settings->{$item}) eq 'HASH') {
1939: $curroption = $settings->{$item}->{$type};
1940: if ($curroption =~ /^autolimit=(\d*)$/) {
1941: $currlimit = $1;
1942: }
1943: }
1944: }
1945: if (!$curroption) {
1946: $curroption = 'norequest';
1947: }
1948: $datatable .= '<th>'.$titles{$item}.'</th>';
1949: foreach my $option (@options) {
1950: my $val = $option;
1951: if ($option eq 'norequest') {
1952: $val = 0;
1953: }
1954: if ($option eq 'validate') {
1955: my $canvalidate = 0;
1956: if (ref($validations{$item}) eq 'HASH') {
1957: if ($validations{$item}{$type}) {
1958: $canvalidate = 1;
1959: }
1960: }
1961: next if (!$canvalidate);
1962: }
1963: my $checked = '';
1964: if ($option eq $curroption) {
1965: $checked = ' checked="checked"';
1966: } elsif ($option eq 'autolimit') {
1967: if ($curroption =~ /^autolimit/) {
1968: $checked = ' checked="checked"';
1969: }
1970: }
1971: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1972: '<input type="radio" name="crsreq_'.$item.
1973: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1974: $titles{$option}.'</label>';
1.101 raeburn 1975: if ($option eq 'autolimit') {
1.127 raeburn 1976: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1977: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1978: 'value="'.$currlimit.'" />';
1.101 raeburn 1979: }
1.127 raeburn 1980: $cell{$item} .= '</span> ';
1.103 raeburn 1981: if ($option eq 'autolimit') {
1.127 raeburn 1982: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1983: }
1.101 raeburn 1984: }
1.163 raeburn 1985: } elsif ($context eq 'requestauthor') {
1986: my $curroption;
1987: if (ref($settings) eq 'HASH') {
1988: $curroption = $settings->{$type};
1989: }
1990: if (!$curroption) {
1991: $curroption = 'norequest';
1992: }
1993: foreach my $option (@options) {
1994: my $val = $option;
1995: if ($option eq 'norequest') {
1996: $val = 0;
1997: }
1998: my $checked = '';
1999: if ($option eq $curroption) {
2000: $checked = ' checked="checked"';
2001: }
2002: $datatable .= '<span class="LC_nobreak"><label>'.
2003: '<input type="radio" name="authorreq_'.$type.
2004: '" value="'.$val.'"'.$checked.' />'.
2005: $titles{$option}.'</label></span> ';
2006: }
1.101 raeburn 2007: } else {
2008: my $checked = 'checked="checked" ';
2009: if (ref($settings) eq 'HASH') {
2010: if (ref($settings->{$item}) eq 'HASH') {
2011: if ($settings->{$item}->{$type} == 0) {
2012: $checked = '';
2013: } elsif ($settings->{$item}->{$type} == 1) {
2014: $checked = 'checked="checked" ';
2015: }
1.78 raeburn 2016: }
1.72 raeburn 2017: }
1.101 raeburn 2018: $datatable .= '<span class="LC_nobreak"><label>'.
2019: '<input type="checkbox" name="'.$context.'_'.$item.
2020: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2021: '</label></span> ';
1.72 raeburn 2022: }
1.101 raeburn 2023: }
2024: if ($context eq 'requestcourses') {
2025: $datatable .= '</tr><tr>';
2026: foreach my $item (@usertools) {
1.106 raeburn 2027: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2028: }
2029: $datatable .= '</tr></table>';
1.72 raeburn 2030: }
1.86 raeburn 2031: $datatable .= '</td>';
1.163 raeburn 2032: unless (($context eq 'requestcourses') ||
2033: ($context eq 'requestauthor')) {
1.86 raeburn 2034: $datatable .=
1.197 raeburn 2035: '<td class="LC_right_item">'.
2036: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2037: '<input type="text" name="quota_'.$type.
1.72 raeburn 2038: '" value="'.$currdefquota.
1.197 raeburn 2039: '" size="5" /></span>'.(' ' x 2).
2040: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2041: '<input type="text" name="authorquota_'.$type.
2042: '" value="'.$currauthorquota.
2043: '" size="5" /></span></td>';
1.86 raeburn 2044: }
2045: $datatable .= '</tr>';
1.3 raeburn 2046: }
2047: }
2048: }
1.163 raeburn 2049: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2050: $defaultquota = '20';
1.197 raeburn 2051: $authorquota = '500';
1.86 raeburn 2052: if (ref($settings) eq 'HASH') {
2053: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2054: $defaultquota = $settings->{'defaultquota'}->{'default'};
2055: } elsif (defined($settings->{'default'})) {
2056: $defaultquota = $settings->{'default'};
2057: }
1.197 raeburn 2058: if (ref($settings->{'authorquota'}) eq 'HASH') {
2059: $authorquota = $settings->{'authorquota'}->{'default'};
2060: }
1.3 raeburn 2061: }
2062: }
2063: $typecount ++;
2064: $css_class = $typecount%2?' class="LC_odd_row"':'';
2065: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2066: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2067: '<td class="LC_left_item">';
1.101 raeburn 2068: if ($context eq 'requestcourses') {
2069: $datatable .= '<table><tr>';
2070: }
2071: my %defcell;
1.72 raeburn 2072: foreach my $item (@usertools) {
1.101 raeburn 2073: if ($context eq 'requestcourses') {
2074: my ($curroption,$currlimit);
2075: if (ref($settings) eq 'HASH') {
2076: if (ref($settings->{$item}) eq 'HASH') {
2077: $curroption = $settings->{$item}->{'default'};
2078: if ($curroption =~ /^autolimit=(\d*)$/) {
2079: $currlimit = $1;
2080: }
2081: }
2082: }
2083: if (!$curroption) {
2084: $curroption = 'norequest';
2085: }
2086: $datatable .= '<th>'.$titles{$item}.'</th>';
2087: foreach my $option (@options) {
2088: my $val = $option;
2089: if ($option eq 'norequest') {
2090: $val = 0;
2091: }
2092: if ($option eq 'validate') {
2093: my $canvalidate = 0;
2094: if (ref($validations{$item}) eq 'HASH') {
2095: if ($validations{$item}{'default'}) {
2096: $canvalidate = 1;
2097: }
2098: }
2099: next if (!$canvalidate);
2100: }
2101: my $checked = '';
2102: if ($option eq $curroption) {
2103: $checked = ' checked="checked"';
2104: } elsif ($option eq 'autolimit') {
2105: if ($curroption =~ /^autolimit/) {
2106: $checked = ' checked="checked"';
2107: }
2108: }
2109: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2110: '<input type="radio" name="crsreq_'.$item.
2111: '_default" value="'.$val.'"'.$checked.' />'.
2112: $titles{$option}.'</label>';
2113: if ($option eq 'autolimit') {
1.127 raeburn 2114: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2115: $item.'_limit_default" size="1" '.
2116: 'value="'.$currlimit.'" />';
2117: }
1.127 raeburn 2118: $defcell{$item} .= '</span> ';
1.104 raeburn 2119: if ($option eq 'autolimit') {
1.127 raeburn 2120: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2121: }
1.101 raeburn 2122: }
1.163 raeburn 2123: } elsif ($context eq 'requestauthor') {
2124: my $curroption;
2125: if (ref($settings) eq 'HASH') {
1.172 raeburn 2126: $curroption = $settings->{'default'};
1.163 raeburn 2127: }
2128: if (!$curroption) {
2129: $curroption = 'norequest';
2130: }
2131: foreach my $option (@options) {
2132: my $val = $option;
2133: if ($option eq 'norequest') {
2134: $val = 0;
2135: }
2136: my $checked = '';
2137: if ($option eq $curroption) {
2138: $checked = ' checked="checked"';
2139: }
2140: $datatable .= '<span class="LC_nobreak"><label>'.
2141: '<input type="radio" name="authorreq_default"'.
2142: ' value="'.$val.'"'.$checked.' />'.
2143: $titles{$option}.'</label></span> ';
2144: }
1.101 raeburn 2145: } else {
2146: my $checked = 'checked="checked" ';
2147: if (ref($settings) eq 'HASH') {
2148: if (ref($settings->{$item}) eq 'HASH') {
2149: if ($settings->{$item}->{'default'} == 0) {
2150: $checked = '';
2151: } elsif ($settings->{$item}->{'default'} == 1) {
2152: $checked = 'checked="checked" ';
2153: }
1.78 raeburn 2154: }
1.72 raeburn 2155: }
1.101 raeburn 2156: $datatable .= '<span class="LC_nobreak"><label>'.
2157: '<input type="checkbox" name="'.$context.'_'.$item.
2158: '" value="default" '.$checked.'/>'.$titles{$item}.
2159: '</label></span> ';
2160: }
2161: }
2162: if ($context eq 'requestcourses') {
2163: $datatable .= '</tr><tr>';
2164: foreach my $item (@usertools) {
1.106 raeburn 2165: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2166: }
1.101 raeburn 2167: $datatable .= '</tr></table>';
1.72 raeburn 2168: }
1.86 raeburn 2169: $datatable .= '</td>';
1.163 raeburn 2170: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2171: $datatable .= '<td class="LC_right_item">'.
2172: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2173: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2174: $defaultquota.'" size="5" /></span>'.(' ' x2).
2175: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2176: '<input type="text" name="authorquota" value="'.
2177: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2178: }
2179: $datatable .= '</tr>';
1.72 raeburn 2180: $typecount ++;
2181: $css_class = $typecount%2?' class="LC_odd_row"':'';
2182: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2183: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2184: if ($context eq 'requestcourses') {
1.109 raeburn 2185: $datatable .= &mt('(overrides affiliation, if set)').
2186: '</td>'.
2187: '<td class="LC_left_item">'.
2188: '<table><tr>';
1.101 raeburn 2189: } else {
1.109 raeburn 2190: $datatable .= &mt('(overrides affiliation, if checked)').
2191: '</td>'.
2192: '<td class="LC_left_item" colspan="2">'.
2193: '<br />';
1.101 raeburn 2194: }
2195: my %advcell;
1.72 raeburn 2196: foreach my $item (@usertools) {
1.101 raeburn 2197: if ($context eq 'requestcourses') {
2198: my ($curroption,$currlimit);
2199: if (ref($settings) eq 'HASH') {
2200: if (ref($settings->{$item}) eq 'HASH') {
2201: $curroption = $settings->{$item}->{'_LC_adv'};
2202: if ($curroption =~ /^autolimit=(\d*)$/) {
2203: $currlimit = $1;
2204: }
2205: }
2206: }
2207: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2208: my $checked = '';
2209: if ($curroption eq '') {
2210: $checked = ' checked="checked"';
2211: }
2212: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2213: '<input type="radio" name="crsreq_'.$item.
2214: '__LC_adv" value=""'.$checked.' />'.
2215: &mt('No override set').'</label></span> ';
1.101 raeburn 2216: foreach my $option (@options) {
2217: my $val = $option;
2218: if ($option eq 'norequest') {
2219: $val = 0;
2220: }
2221: if ($option eq 'validate') {
2222: my $canvalidate = 0;
2223: if (ref($validations{$item}) eq 'HASH') {
2224: if ($validations{$item}{'_LC_adv'}) {
2225: $canvalidate = 1;
2226: }
2227: }
2228: next if (!$canvalidate);
2229: }
2230: my $checked = '';
1.104 raeburn 2231: if ($val eq $curroption) {
1.101 raeburn 2232: $checked = ' checked="checked"';
2233: } elsif ($option eq 'autolimit') {
2234: if ($curroption =~ /^autolimit/) {
2235: $checked = ' checked="checked"';
2236: }
2237: }
2238: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2239: '<input type="radio" name="crsreq_'.$item.
2240: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2241: $titles{$option}.'</label>';
2242: if ($option eq 'autolimit') {
1.127 raeburn 2243: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2244: $item.'_limit__LC_adv" size="1" '.
2245: 'value="'.$currlimit.'" />';
2246: }
1.127 raeburn 2247: $advcell{$item} .= '</span> ';
1.104 raeburn 2248: if ($option eq 'autolimit') {
1.127 raeburn 2249: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2250: }
1.101 raeburn 2251: }
1.163 raeburn 2252: } elsif ($context eq 'requestauthor') {
2253: my $curroption;
2254: if (ref($settings) eq 'HASH') {
2255: $curroption = $settings->{'_LC_adv'};
2256: }
2257: my $checked = '';
2258: if ($curroption eq '') {
2259: $checked = ' checked="checked"';
2260: }
2261: $datatable .= '<span class="LC_nobreak"><label>'.
2262: '<input type="radio" name="authorreq__LC_adv"'.
2263: ' value=""'.$checked.' />'.
2264: &mt('No override set').'</label></span> ';
2265: foreach my $option (@options) {
2266: my $val = $option;
2267: if ($option eq 'norequest') {
2268: $val = 0;
2269: }
2270: my $checked = '';
2271: if ($val eq $curroption) {
2272: $checked = ' checked="checked"';
2273: }
2274: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2275: '<input type="radio" name="authorreq__LC_adv"'.
2276: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2277: $titles{$option}.'</label></span> ';
2278: }
1.101 raeburn 2279: } else {
2280: my $checked = 'checked="checked" ';
2281: if (ref($settings) eq 'HASH') {
2282: if (ref($settings->{$item}) eq 'HASH') {
2283: if ($settings->{$item}->{'_LC_adv'} == 0) {
2284: $checked = '';
2285: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2286: $checked = 'checked="checked" ';
2287: }
1.79 raeburn 2288: }
1.72 raeburn 2289: }
1.101 raeburn 2290: $datatable .= '<span class="LC_nobreak"><label>'.
2291: '<input type="checkbox" name="'.$context.'_'.$item.
2292: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2293: '</label></span> ';
2294: }
2295: }
2296: if ($context eq 'requestcourses') {
2297: $datatable .= '</tr><tr>';
2298: foreach my $item (@usertools) {
1.106 raeburn 2299: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2300: }
1.101 raeburn 2301: $datatable .= '</tr></table>';
1.72 raeburn 2302: }
1.98 raeburn 2303: $datatable .= '</td></tr>';
1.30 raeburn 2304: $$rowtotal += $typecount;
1.3 raeburn 2305: return $datatable;
2306: }
2307:
1.163 raeburn 2308: sub print_requestmail {
1.305 raeburn 2309: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2310: my ($now,$datatable,%currapp);
1.102 raeburn 2311: $now = time;
2312: if (ref($settings) eq 'HASH') {
2313: if (ref($settings->{'notify'}) eq 'HASH') {
2314: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2315: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2316: }
2317: }
2318: }
1.191 raeburn 2319: my $numinrow = 2;
1.224 raeburn 2320: my $css_class;
1.305 raeburn 2321: if ($$rowtotal%2) {
2322: $css_class = 'LC_odd_row';
2323: }
2324: if ($customcss) {
2325: $css_class .= " $customcss";
2326: }
2327: $css_class =~ s/^\s+//;
2328: if ($css_class) {
2329: $css_class = ' class="'.$css_class.'"';
2330: }
2331: if ($rowstyle) {
2332: $css_class .= ' style="'.$rowstyle.'"';
2333: }
1.163 raeburn 2334: my $text;
2335: if ($action eq 'requestcourses') {
2336: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2337: } elsif ($action eq 'requestauthor') {
2338: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2339: } else {
1.224 raeburn 2340: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2341: }
1.224 raeburn 2342: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2343: ' <td>'.$text.'</td>'.
1.102 raeburn 2344: ' <td class="LC_left_item">';
1.191 raeburn 2345: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2346: $action.'notifyapproval',%currapp);
1.191 raeburn 2347: if ($numdc > 0) {
2348: $datatable .= $table;
1.102 raeburn 2349: } else {
2350: $datatable .= &mt('There are no active Domain Coordinators');
2351: }
2352: $datatable .='</td></tr>';
2353: return $datatable;
2354: }
2355:
1.216 raeburn 2356: sub print_studentcode {
2357: my ($settings,$rowtotal) = @_;
2358: my $rownum = 0;
1.218 raeburn 2359: my ($output,%current);
1.271 raeburn 2360: my @crstypes = ('official','unofficial','community','textbook','placement');
1.248 raeburn 2361: if (ref($settings) eq 'HASH') {
2362: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2363: foreach my $type (@crstypes) {
2364: $current{$type} = $settings->{'uniquecode'}{$type};
2365: }
1.218 raeburn 2366: }
2367: }
2368: $output .= '<tr>'.
2369: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2370: '<td class="LC_left_item">';
2371: foreach my $type (@crstypes) {
2372: my $check = ' ';
2373: if ($current{$type}) {
2374: $check = ' checked="checked" ';
2375: }
2376: $output .= '<span class="LC_nobreak"><label>'.
2377: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2378: &mt($type).'</label></span>'.(' 'x2).' ';
2379: }
2380: $output .= '</td></tr>';
2381: $$rowtotal ++;
2382: return $output;
1.216 raeburn 2383: }
2384:
2385: sub print_textbookcourses {
1.242 raeburn 2386: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2387: my $rownum = 0;
2388: my $css_class;
2389: my $itemcount = 1;
2390: my $maxnum = 0;
2391: my $bookshash;
2392: if (ref($settings) eq 'HASH') {
1.242 raeburn 2393: $bookshash = $settings->{$type};
1.216 raeburn 2394: }
2395: my %ordered;
2396: if (ref($bookshash) eq 'HASH') {
2397: foreach my $item (keys(%{$bookshash})) {
2398: if (ref($bookshash->{$item}) eq 'HASH') {
2399: my $num = $bookshash->{$item}{'order'};
2400: $ordered{$num} = $item;
2401: }
2402: }
2403: }
2404: my $confname = $dom.'-domainconfig';
2405: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2406: my $maxnum = scalar(keys(%ordered));
2407: my $datatable;
1.216 raeburn 2408: if (keys(%ordered)) {
2409: my @items = sort { $a <=> $b } keys(%ordered);
2410: for (my $i=0; $i<@items; $i++) {
2411: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2412: my $key = $ordered{$items[$i]};
2413: my %coursehash=&Apache::lonnet::coursedescription($key);
2414: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2415: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2416: if (ref($bookshash->{$key}) eq 'HASH') {
2417: $subject = $bookshash->{$key}->{'subject'};
2418: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2419: if ($type eq 'textbooks') {
1.243 raeburn 2420: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2421: $author = $bookshash->{$key}->{'author'};
2422: $image = $bookshash->{$key}->{'image'};
2423: if ($image ne '') {
2424: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2425: my $imagethumb = "$path/tn-".$imagefile;
2426: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2427: }
1.216 raeburn 2428: }
2429: }
1.242 raeburn 2430: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2431: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2432: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2433: for (my $k=0; $k<=$maxnum; $k++) {
2434: my $vpos = $k+1;
2435: my $selstr;
2436: if ($k == $i) {
2437: $selstr = ' selected="selected" ';
2438: }
2439: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2440: }
2441: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2442: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2443: &mt('Delete?').'</label></span></td>'.
2444: '<td colspan="2">'.
1.242 raeburn 2445: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2446: (' 'x2).
1.242 raeburn 2447: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2448: if ($type eq 'textbooks') {
2449: $datatable .= (' 'x2).
1.243 raeburn 2450: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2451: (' 'x2).
1.242 raeburn 2452: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2453: (' 'x2).
2454: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2455: if ($image) {
1.267 raeburn 2456: $datatable .= $imgsrc.
1.242 raeburn 2457: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2458: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2459: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2460: }
2461: if ($switchserver) {
2462: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2463: } else {
2464: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2465: }
1.216 raeburn 2466: }
1.242 raeburn 2467: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2468: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2469: $coursetitle.'</span></td></tr>'."\n";
2470: $itemcount ++;
2471: }
2472: }
2473: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2474: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2475: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2476: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2477: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2478: for (my $k=0; $k<$maxnum+1; $k++) {
2479: my $vpos = $k+1;
2480: my $selstr;
2481: if ($k == $maxnum) {
2482: $selstr = ' selected="selected" ';
2483: }
2484: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2485: }
2486: $datatable .= '</select> '."\n".
1.242 raeburn 2487: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.216 raeburn 2488: '<td colspan="2">'.
1.242 raeburn 2489: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2490: (' 'x2).
1.242 raeburn 2491: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2492: (' 'x2);
2493: if ($type eq 'textbooks') {
1.243 raeburn 2494: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2495: (' 'x2).
2496: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2497: (' 'x2).
2498: '<span class="LC_nobreak">'.&mt('Image:').' ';
2499: if ($switchserver) {
2500: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2501: } else {
2502: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2503: }
1.216 raeburn 2504: }
2505: $datatable .= '</span>'."\n".
2506: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2507: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2508: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2509: &Apache::loncommon::selectcourse_link
1.242 raeburn 2510: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.216 raeburn 2511: '</span></td>'."\n".
2512: '</tr>'."\n";
2513: $itemcount ++;
2514: return $datatable;
2515: }
2516:
1.217 raeburn 2517: sub textbookcourses_javascript {
1.242 raeburn 2518: my ($settings) = @_;
2519: return unless(ref($settings) eq 'HASH');
2520: my (%ordered,%total,%jstext);
2521: foreach my $type ('textbooks','templates') {
2522: $total{$type} = 0;
2523: if (ref($settings->{$type}) eq 'HASH') {
2524: foreach my $item (keys(%{$settings->{$type}})) {
2525: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2526: my $num = $settings->{$type}->{$item}{'order'};
2527: $ordered{$type}{$num} = $item;
2528: }
2529: }
2530: $total{$type} = scalar(keys(%{$settings->{$type}}));
2531: }
2532: my @jsarray = ();
2533: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2534: push(@jsarray,$ordered{$type}{$item});
2535: }
2536: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2537: }
2538: return <<"ENDSCRIPT";
2539: <script type="text/javascript">
2540: // <![CDATA[
1.242 raeburn 2541: function reorderBooks(form,item,caller) {
1.217 raeburn 2542: var changedVal;
1.242 raeburn 2543: $jstext{'textbooks'};
2544: $jstext{'templates'};
2545: var newpos;
2546: var maxh;
2547: if (caller == 'textbooks') {
2548: newpos = 'textbooks_addbook_pos';
2549: maxh = 1 + $total{'textbooks'};
2550: } else {
2551: newpos = 'templates_addbook_pos';
2552: maxh = 1 + $total{'templates'};
2553: }
1.217 raeburn 2554: var current = new Array;
2555: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2556: if (item == newpos) {
2557: changedVal = newitemVal;
2558: } else {
2559: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2560: current[newitemVal] = newpos;
2561: }
1.242 raeburn 2562: if (caller == 'textbooks') {
2563: for (var i=0; i<textbooks.length; i++) {
2564: var elementName = 'textbooks_'+textbooks[i];
2565: if (elementName != item) {
2566: if (form.elements[elementName]) {
2567: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2568: current[currVal] = elementName;
2569: }
2570: }
2571: }
2572: }
2573: if (caller == 'templates') {
2574: for (var i=0; i<templates.length; i++) {
2575: var elementName = 'templates_'+templates[i];
2576: if (elementName != item) {
2577: if (form.elements[elementName]) {
2578: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2579: current[currVal] = elementName;
2580: }
1.217 raeburn 2581: }
2582: }
2583: }
2584: var oldVal;
2585: for (var j=0; j<maxh; j++) {
2586: if (current[j] == undefined) {
2587: oldVal = j;
2588: }
2589: }
2590: if (oldVal < changedVal) {
2591: for (var k=oldVal+1; k<=changedVal ; k++) {
2592: var elementName = current[k];
2593: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2594: }
2595: } else {
2596: for (var k=changedVal; k<oldVal; k++) {
2597: var elementName = current[k];
2598: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2599: }
2600: }
2601: return;
2602: }
2603:
2604: // ]]>
2605: </script>
2606:
2607: ENDSCRIPT
2608: }
2609:
1.267 raeburn 2610: sub ltitools_javascript {
2611: my ($settings) = @_;
1.319 raeburn 2612: my $togglejs = <itools_toggle_js();
2613: unless (ref($settings) eq 'HASH') {
2614: return $togglejs;
2615: }
1.267 raeburn 2616: my (%ordered,$total,%jstext);
2617: $total = 0;
2618: foreach my $item (keys(%{$settings})) {
2619: if (ref($settings->{$item}) eq 'HASH') {
2620: my $num = $settings->{$item}{'order'};
2621: $ordered{$num} = $item;
2622: }
2623: }
2624: $total = scalar(keys(%{$settings}));
2625: my @jsarray = ();
2626: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2627: push(@jsarray,$ordered{$item});
2628: }
2629: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2630: return <<"ENDSCRIPT";
2631: <script type="text/javascript">
2632: // <![CDATA[
1.319 raeburn 2633: function reorderLTITools(form,item) {
1.267 raeburn 2634: var changedVal;
2635: $jstext
2636: var newpos = 'ltitools_add_pos';
2637: var maxh = 1 + $total;
2638: var current = new Array;
2639: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2640: if (item == newpos) {
2641: changedVal = newitemVal;
2642: } else {
2643: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2644: current[newitemVal] = newpos;
2645: }
2646: for (var i=0; i<ltitools.length; i++) {
2647: var elementName = 'ltitools_'+ltitools[i];
2648: if (elementName != item) {
2649: if (form.elements[elementName]) {
2650: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2651: current[currVal] = elementName;
2652: }
2653: }
2654: }
2655: var oldVal;
2656: for (var j=0; j<maxh; j++) {
2657: if (current[j] == undefined) {
2658: oldVal = j;
2659: }
2660: }
2661: if (oldVal < changedVal) {
2662: for (var k=oldVal+1; k<=changedVal ; k++) {
2663: var elementName = current[k];
2664: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2665: }
2666: } else {
2667: for (var k=changedVal; k<oldVal; k++) {
2668: var elementName = current[k];
2669: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2670: }
2671: }
2672: return;
2673: }
2674:
2675: // ]]>
2676: </script>
2677:
1.319 raeburn 2678: $togglejs
2679:
2680: ENDSCRIPT
2681: }
2682:
2683: sub ltitools_toggle_js {
2684: return <<"ENDSCRIPT";
2685: <script type="text/javascript">
2686: // <![CDATA[
2687:
2688: function toggleLTITools(form,setting,item) {
2689: var radioname = '';
2690: var divid = '';
2691: if ((setting == 'passback') || (setting == 'roster')) {
2692: radioname = 'ltitools_'+setting+'_'+item;
2693: divid = 'ltitools_'+setting+'time_'+item;
2694: var num = form.elements[radioname].length;
2695: if (num) {
2696: var setvis = '';
2697: for (var i=0; i<num; i++) {
2698: if (form.elements[radioname][i].checked) {
2699: if (form.elements[radioname][i].value == '1') {
2700: if (document.getElementById(divid)) {
2701: document.getElementById(divid).style.display = 'inline-block';
2702: }
2703: setvis = 1;
2704: }
2705: break;
2706: }
2707: }
2708: }
2709: if (!setvis) {
2710: if (document.getElementById(divid)) {
2711: document.getElementById(divid).style.display = 'none';
2712: }
2713: }
2714: }
2715: return;
2716: }
2717: // ]]>
2718: </script>
2719:
1.267 raeburn 2720: ENDSCRIPT
2721: }
2722:
1.320 raeburn 2723: sub lti_javascript {
2724: my ($settings) = @_;
2725: my $togglejs = <i_toggle_js();
2726: unless (ref($settings) eq 'HASH') {
2727: return $togglejs;
2728: }
2729: my (%ordered,$total,%jstext);
2730: $total = 0;
2731: foreach my $item (keys(%{$settings})) {
2732: if (ref($settings->{$item}) eq 'HASH') {
2733: my $num = $settings->{$item}{'order'};
2734: $ordered{$num} = $item;
2735: }
2736: }
2737: $total = scalar(keys(%{$settings}));
2738: my @jsarray = ();
2739: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2740: push(@jsarray,$ordered{$item});
2741: }
2742: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
2743: return <<"ENDSCRIPT";
2744: <script type="text/javascript">
2745: // <![CDATA[
2746: function reorderLTI(form,item) {
2747: var changedVal;
2748: $jstext
2749: var newpos = 'lti_pos_add';
2750: var maxh = 1 + $total;
2751: var current = new Array;
2752: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2753: if (item == newpos) {
2754: changedVal = newitemVal;
2755: } else {
2756: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2757: current[newitemVal] = newpos;
2758: }
2759: for (var i=0; i<lti.length; i++) {
2760: var elementName = 'lti_pos_'+lti[i];
2761: if (elementName != item) {
2762: if (form.elements[elementName]) {
2763: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2764: current[currVal] = elementName;
2765: }
2766: }
2767: }
2768: var oldVal;
2769: for (var j=0; j<maxh; j++) {
2770: if (current[j] == undefined) {
2771: oldVal = j;
2772: }
2773: }
2774: if (oldVal < changedVal) {
2775: for (var k=oldVal+1; k<=changedVal ; k++) {
2776: var elementName = current[k];
2777: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2778: }
2779: } else {
2780: for (var k=changedVal; k<oldVal; k++) {
2781: var elementName = current[k];
2782: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2783: }
2784: }
2785: return;
2786: }
2787: // ]]>
2788: </script>
2789:
2790: $togglejs
2791:
2792: ENDSCRIPT
2793: }
2794:
2795: sub lti_toggle_js {
2796: return <<"ENDSCRIPT";
2797: <script type="text/javascript">
2798: // <![CDATA[
2799:
2800: function toggleLTI(form,setting,item) {
2801: if ((setting == 'user') || (setting == 'crs')) {
2802: var radioname = '';
2803: var divid = '';
2804: if (setting == 'user') {
2805: radioname = 'lti_mapuser_'+item;
2806: divid = 'lti_userfield_'+item;
2807: } else {
2808: radioname = 'lti_mapcrs_'+item;
2809: divid = 'lti_crsfield_'+item;
2810: }
2811: var num = form.elements[radioname].length;
2812: if (num) {
2813: var setvis = '';
2814: for (var i=0; i<num; i++) {
2815: if (form.elements[radioname][i].checked) {
2816: if (form.elements[radioname][i].value == 'other') {
2817: if (document.getElementById(divid)) {
2818: document.getElementById(divid).style.display = 'inline-block';
2819: }
2820: setvis = 1;
2821: break;
2822: }
2823: }
2824: }
2825: if (!setvis) {
2826: if (document.getElementById(divid)) {
2827: document.getElementById(divid).style.display = 'none';
2828: }
2829: }
2830: }
2831: } else if ((setting == 'sec') || (setting == 'secsrc')) {
2832: var numsec = form.elements['lti_crssec_'+item].length;
2833: if (numsec) {
2834: var setvis = '';
2835: for (var i=0; i<numsec; i++) {
2836: if (form.elements['lti_crssec_'+item][i].checked) {
2837: if (form.elements['lti_crssec_'+item][i].value == '1') {
2838: if (document.getElementById('lti_crssecfield_'+item)) {
2839: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
2840: setvis = 1;
2841: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
2842: if (numsrcsec) {
2843: var setsrcvis = '';
2844: for (var j=0; j<numsrcsec; j++) {
2845: if (form.elements['lti_crssecsrc_'+item][j].checked) {
2846: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
2847: if (document.getElementById('lti_secsrcfield_'+item)) {
2848: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
2849: setsrcvis = 1;
2850: }
2851: }
2852: }
2853: }
2854: if (!setsrcvis) {
2855: if (document.getElementById('lti_secsrcfield_'+item)) {
2856: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
2857: }
2858: }
2859: }
2860: }
2861: }
2862: }
2863: }
2864: if (!setvis) {
2865: if (document.getElementById('lti_crssecfield_'+item)) {
2866: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
2867: }
2868: if (document.getElementById('lti_secsrcfield_'+item)) {
2869: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
2870: }
2871: }
2872: }
2873: }
2874: return;
2875: }
2876: // ]]>
2877: </script>
2878:
2879: ENDSCRIPT
2880: }
2881:
1.3 raeburn 2882: sub print_autoenroll {
1.30 raeburn 2883: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2884: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274 raeburn 2885: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2886: if (ref($settings) eq 'HASH') {
2887: if (exists($settings->{'run'})) {
2888: if ($settings->{'run'} eq '0') {
2889: $runoff = ' checked="checked" ';
2890: $runon = ' ';
2891: } else {
2892: $runon = ' checked="checked" ';
2893: $runoff = ' ';
2894: }
2895: } else {
2896: if ($autorun) {
2897: $runon = ' checked="checked" ';
2898: $runoff = ' ';
2899: } else {
2900: $runoff = ' checked="checked" ';
2901: $runon = ' ';
2902: }
2903: }
1.129 raeburn 2904: if (exists($settings->{'co-owners'})) {
2905: if ($settings->{'co-owners'} eq '0') {
2906: $coownersoff = ' checked="checked" ';
2907: $coownerson = ' ';
2908: } else {
2909: $coownerson = ' checked="checked" ';
2910: $coownersoff = ' ';
2911: }
2912: } else {
2913: $coownersoff = ' checked="checked" ';
2914: $coownerson = ' ';
2915: }
1.3 raeburn 2916: if (exists($settings->{'sender_domain'})) {
2917: $defdom = $settings->{'sender_domain'};
2918: }
1.274 raeburn 2919: if (exists($settings->{'autofailsafe'})) {
2920: $failsafe = $settings->{'autofailsafe'};
2921: }
1.14 raeburn 2922: } else {
2923: if ($autorun) {
2924: $runon = ' checked="checked" ';
2925: $runoff = ' ';
2926: } else {
2927: $runoff = ' checked="checked" ';
2928: $runon = ' ';
2929: }
1.3 raeburn 2930: }
2931: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2932: my $notif_sender;
2933: if (ref($settings) eq 'HASH') {
2934: $notif_sender = $settings->{'sender_uname'};
2935: }
1.3 raeburn 2936: my $datatable='<tr class="LC_odd_row">'.
2937: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2938: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2939: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2940: $runon.' value="1" />'.&mt('Yes').'</label> '.
2941: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2942: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2943: '</tr><tr>'.
2944: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2945: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2946: &mt('username').': '.
2947: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2948: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2949: ': '.$domform.'</span></td></tr>'.
2950: '<tr class="LC_odd_row">'.
2951: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2952: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2953: '<input type="radio" name="autoassign_coowners"'.
2954: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2955: '<label><input type="radio" name="autoassign_coowners"'.
2956: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 2957: '</tr><tr>'.
2958: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2959: '<td class="LC_right_item"><span class="LC_nobreak">'.
2960: '<input type="text" name="autoenroll_failsafe"'.
2961: ' value="'.$failsafe.'" size="4" /></td></tr>';
2962: $$rowtotal += 4;
1.3 raeburn 2963: return $datatable;
2964: }
2965:
2966: sub print_autoupdate {
1.30 raeburn 2967: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2968: my $datatable;
2969: if ($position eq 'top') {
2970: my $updateon = ' ';
2971: my $updateoff = ' checked="checked" ';
2972: my $classlistson = ' ';
2973: my $classlistsoff = ' checked="checked" ';
2974: if (ref($settings) eq 'HASH') {
2975: if ($settings->{'run'} eq '1') {
2976: $updateon = $updateoff;
2977: $updateoff = ' ';
2978: }
2979: if ($settings->{'classlists'} eq '1') {
2980: $classlistson = $classlistsoff;
2981: $classlistsoff = ' ';
2982: }
2983: }
2984: my %title = (
2985: run => 'Auto-update active?',
2986: classlists => 'Update information in classlists?',
2987: );
2988: $datatable = '<tr class="LC_odd_row">'.
2989: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2990: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2991: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2992: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2993: '<label><input type="radio" name="autoupdate_run"'.
2994: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2995: '</tr><tr>'.
2996: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2997: '<td class="LC_right_item"><span class="LC_nobreak">'.
2998: '<label><input type="radio" name="classlists"'.
2999: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
3000: '<label><input type="radio" name="classlists"'.
3001: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3002: '</tr>';
1.30 raeburn 3003: $$rowtotal += 2;
1.131 raeburn 3004: } elsif ($position eq 'middle') {
3005: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3006: my $numinrow = 3;
3007: my $locknamesettings;
3008: $datatable .= &insttypes_row($settings,$types,$usertypes,
3009: $dom,$numinrow,$othertitle,
1.305 raeburn 3010: 'lockablenames',$rowtotal);
1.131 raeburn 3011: $$rowtotal ++;
1.3 raeburn 3012: } else {
1.44 raeburn 3013: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3014: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3015: 'permanentemail','id');
1.33 raeburn 3016: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3017: my $numrows = 0;
1.26 raeburn 3018: if (ref($types) eq 'ARRAY') {
3019: if (@{$types} > 0) {
3020: $datatable =
3021: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3022: \@fields,$types,\$numrows);
1.30 raeburn 3023: $$rowtotal += @{$types};
1.26 raeburn 3024: }
1.3 raeburn 3025: }
3026: $datatable .=
3027: &usertype_update_row($settings,{'default' => $othertitle},
3028: \%fieldtitles,\@fields,['default'],
3029: \$numrows);
1.30 raeburn 3030: $$rowtotal ++;
1.3 raeburn 3031: }
3032: return $datatable;
3033: }
3034:
1.125 raeburn 3035: sub print_autocreate {
3036: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 3037: my (%createon,%createoff,%currhash);
1.125 raeburn 3038: my @types = ('xml','req');
3039: if (ref($settings) eq 'HASH') {
3040: foreach my $item (@types) {
3041: $createoff{$item} = ' checked="checked" ';
3042: $createon{$item} = ' ';
3043: if (exists($settings->{$item})) {
3044: if ($settings->{$item}) {
3045: $createon{$item} = ' checked="checked" ';
3046: $createoff{$item} = ' ';
3047: }
3048: }
3049: }
1.210 raeburn 3050: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 3051: $currhash{$settings->{'xmldc'}} = 1;
3052: }
1.125 raeburn 3053: } else {
3054: foreach my $item (@types) {
3055: $createoff{$item} = ' checked="checked" ';
3056: $createon{$item} = ' ';
3057: }
3058: }
3059: $$rowtotal += 2;
1.191 raeburn 3060: my $numinrow = 2;
1.125 raeburn 3061: my $datatable='<tr class="LC_odd_row">'.
3062: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3063: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3064: '<input type="radio" name="autocreate_xml"'.
3065: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3066: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 3067: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3068: '</td></tr><tr>'.
3069: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3070: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3071: '<input type="radio" name="autocreate_req"'.
3072: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3073: '<label><input type="radio" name="autocreate_req"'.
3074: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 3075: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3076: 'autocreate_xmldc',%currhash);
1.247 raeburn 3077: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 3078: if ($numdc > 1) {
1.247 raeburn 3079: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
3080: '</td><td class="LC_left_item">';
1.125 raeburn 3081: } else {
1.247 raeburn 3082: $datatable .= &mt('Course creation processed as:').
3083: '</td><td class="LC_right_item">';
1.125 raeburn 3084: }
1.247 raeburn 3085: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 3086: $$rowtotal += $rows;
1.125 raeburn 3087: return $datatable;
3088: }
3089:
1.23 raeburn 3090: sub print_directorysrch {
1.277 raeburn 3091: my ($position,$dom,$settings,$rowtotal) = @_;
3092: my $datatable;
3093: if ($position eq 'top') {
3094: my $instsrchon = ' ';
3095: my $instsrchoff = ' checked="checked" ';
3096: my ($exacton,$containson,$beginson);
3097: my $instlocalon = ' ';
3098: my $instlocaloff = ' checked="checked" ';
3099: if (ref($settings) eq 'HASH') {
3100: if ($settings->{'available'} eq '1') {
3101: $instsrchon = $instsrchoff;
3102: $instsrchoff = ' ';
3103: }
3104: if ($settings->{'localonly'} eq '1') {
3105: $instlocalon = $instlocaloff;
3106: $instlocaloff = ' ';
3107: }
3108: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
3109: foreach my $type (@{$settings->{'searchtypes'}}) {
3110: if ($type eq 'exact') {
3111: $exacton = ' checked="checked" ';
3112: } elsif ($type eq 'contains') {
3113: $containson = ' checked="checked" ';
3114: } elsif ($type eq 'begins') {
3115: $beginson = ' checked="checked" ';
3116: }
3117: }
3118: } else {
3119: if ($settings->{'searchtypes'} eq 'exact') {
3120: $exacton = ' checked="checked" ';
3121: } elsif ($settings->{'searchtypes'} eq 'contains') {
3122: $containson = ' checked="checked" ';
3123: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 3124: $exacton = ' checked="checked" ';
3125: $containson = ' checked="checked" ';
3126: }
3127: }
1.277 raeburn 3128: }
3129: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3130: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3131:
3132: my $numinrow = 4;
3133: my $cansrchrow = 0;
3134: $datatable='<tr class="LC_odd_row">'.
3135: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
3136: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3137: '<input type="radio" name="dirsrch_available"'.
3138: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
3139: '<label><input type="radio" name="dirsrch_available"'.
3140: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3141: '</tr><tr>'.
3142: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
3143: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3144: '<input type="radio" name="dirsrch_instlocalonly"'.
3145: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3146: '<label><input type="radio" name="dirsrch_instlocalonly"'.
3147: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3148: '</tr>';
3149: $$rowtotal += 2;
3150: if (ref($usertypes) eq 'HASH') {
3151: if (keys(%{$usertypes}) > 0) {
3152: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 3153: $numinrow,$othertitle,'cansearch',
3154: $rowtotal);
1.277 raeburn 3155: $cansrchrow = 1;
1.25 raeburn 3156: }
1.23 raeburn 3157: }
1.277 raeburn 3158: if ($cansrchrow) {
3159: $$rowtotal ++;
3160: $datatable .= '<tr>';
3161: } else {
3162: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 3163: }
1.277 raeburn 3164: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
3165: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
3166: foreach my $title (@{$titleorder}) {
3167: if (defined($searchtitles->{$title})) {
3168: my $check = ' ';
3169: if (ref($settings) eq 'HASH') {
3170: if (ref($settings->{'searchby'}) eq 'ARRAY') {
3171: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
3172: $check = ' checked="checked" ';
3173: }
1.39 raeburn 3174: }
1.25 raeburn 3175: }
1.277 raeburn 3176: $datatable .= '<td class="LC_left_item">'.
3177: '<span class="LC_nobreak"><label>'.
3178: '<input type="checkbox" name="searchby" '.
3179: 'value="'.$title.'"'.$check.'/>'.
3180: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 3181: }
3182: }
1.277 raeburn 3183: $datatable .= '</tr></table></td></tr>';
3184: $$rowtotal ++;
3185: if ($cansrchrow) {
3186: $datatable .= '<tr class="LC_odd_row">';
3187: } else {
3188: $datatable .= '<tr>';
3189: }
3190: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
3191: '<td class="LC_left_item" colspan="2">'.
3192: '<span class="LC_nobreak"><label>'.
3193: '<input type="checkbox" name="searchtypes" '.
3194: $exacton.' value="exact" />'.&mt('Exact match').
3195: '</label> '.
3196: '<label><input type="checkbox" name="searchtypes" '.
3197: $beginson.' value="begins" />'.&mt('Begins with').
3198: '</label> '.
3199: '<label><input type="checkbox" name="searchtypes" '.
3200: $containson.' value="contains" />'.&mt('Contains').
3201: '</label></span></td></tr>';
3202: $$rowtotal ++;
1.26 raeburn 3203: } else {
1.277 raeburn 3204: my $domsrchon = ' checked="checked" ';
3205: my $domsrchoff = ' ';
3206: my $domlocalon = ' ';
3207: my $domlocaloff = ' checked="checked" ';
3208: if (ref($settings) eq 'HASH') {
3209: if ($settings->{'lclocalonly'} eq '1') {
3210: $domlocalon = $domlocaloff;
3211: $domlocaloff = ' ';
3212: }
3213: if ($settings->{'lcavailable'} eq '0') {
3214: $domsrchoff = $domsrchon;
3215: $domsrchon = ' ';
3216: }
3217: }
3218: $datatable='<tr class="LC_odd_row">'.
3219: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
3220: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3221: '<input type="radio" name="dirsrch_domavailable"'.
3222: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
3223: '<label><input type="radio" name="dirsrch_domavailable"'.
3224: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3225: '</tr><tr>'.
3226: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
3227: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3228: '<input type="radio" name="dirsrch_domlocalonly"'.
3229: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3230: '<label><input type="radio" name="dirsrch_domlocalonly"'.
3231: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3232: '</tr>';
3233: $$rowtotal += 2;
1.26 raeburn 3234: }
1.25 raeburn 3235: return $datatable;
3236: }
3237:
1.28 raeburn 3238: sub print_contacts {
1.286 raeburn 3239: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 3240: my $datatable;
3241: my @contacts = ('adminemail','supportemail');
1.286 raeburn 3242: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
3243: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings);
3244: if ($position eq 'top') {
3245: if (ref($settings) eq 'HASH') {
3246: foreach my $item (@contacts) {
3247: if (exists($settings->{$item})) {
3248: $to{$item} = $settings->{$item};
3249: }
3250: }
3251: }
3252: } elsif ($position eq 'middle') {
3253: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
3254: 'updatesmail','idconflictsmail');
1.288 raeburn 3255: foreach my $type (@mailings) {
3256: $otheremails{$type} = '';
3257: }
1.286 raeburn 3258: } else {
3259: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 3260: foreach my $type (@mailings) {
3261: $otheremails{$type} = '';
3262: }
1.286 raeburn 3263: $bccemails{'helpdeskmail'} = '';
3264: $bccemails{'otherdomsmail'} = '';
3265: $includestr{'helpdeskmail'} = '';
3266: $includestr{'otherdomsmail'} = '';
3267: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3268: }
1.28 raeburn 3269: if (ref($settings) eq 'HASH') {
1.286 raeburn 3270: unless ($position eq 'top') {
3271: foreach my $type (@mailings) {
3272: if (exists($settings->{$type})) {
3273: if (ref($settings->{$type}) eq 'HASH') {
3274: foreach my $item (@contacts) {
3275: if ($settings->{$type}{$item}) {
3276: $checked{$type}{$item} = ' checked="checked" ';
3277: }
3278: }
3279: $otheremails{$type} = $settings->{$type}{'others'};
3280: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3281: $bccemails{$type} = $settings->{$type}{'bcc'};
3282: if ($settings->{$type}{'include'} ne '') {
3283: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3284: $includestr{$type} = &unescape($includestr{$type});
3285: }
3286: }
3287: }
3288: } elsif ($type eq 'lonstatusmail') {
3289: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3290: }
1.28 raeburn 3291: }
3292: }
1.286 raeburn 3293: if ($position eq 'bottom') {
3294: foreach my $type (@mailings) {
3295: $bccemails{$type} = $settings->{$type}{'bcc'};
3296: if ($settings->{$type}{'include'} ne '') {
3297: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3298: $includestr{$type} = &unescape($includestr{$type});
3299: }
3300: }
3301: if (ref($settings->{'helpform'}) eq 'HASH') {
3302: if (ref($fields) eq 'ARRAY') {
3303: foreach my $field (@{$fields}) {
3304: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3305: }
1.286 raeburn 3306: }
3307: if (exists($settings->{'helpform'}{'maxsize'})) {
3308: $maxsize = $settings->{'helpform'}{'maxsize'};
3309: } else {
1.289 raeburn 3310: $maxsize = '1.0';
1.286 raeburn 3311: }
3312: } else {
3313: if (ref($fields) eq 'ARRAY') {
3314: foreach my $field (@{$fields}) {
3315: $currfield{$field} = 'yes';
1.134 raeburn 3316: }
1.28 raeburn 3317: }
1.286 raeburn 3318: $maxsize = '1.0';
1.28 raeburn 3319: }
3320: }
3321: } else {
1.286 raeburn 3322: if ($position eq 'top') {
3323: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3324: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3325: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3326: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 3327: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 3328: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3329: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3330: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
3331: } elsif ($position eq 'bottom') {
3332: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3333: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3334: if (ref($fields) eq 'ARRAY') {
3335: foreach my $field (@{$fields}) {
3336: $currfield{$field} = 'yes';
3337: }
3338: }
3339: $maxsize = '1.0';
3340: }
1.28 raeburn 3341: }
3342: my ($titles,$short_titles) = &contact_titles();
3343: my $rownum = 0;
3344: my $css_class;
1.286 raeburn 3345: if ($position eq 'top') {
3346: foreach my $item (@contacts) {
3347: $css_class = $rownum%2?' class="LC_odd_row"':'';
3348: $datatable .= '<tr'.$css_class.'>'.
3349: '<td><span class="LC_nobreak">'.$titles->{$item}.
3350: '</span></td><td class="LC_right_item">'.
3351: '<input type="text" name="'.$item.'" value="'.
3352: $to{$item}.'" /></td></tr>';
3353: $rownum ++;
3354: }
1.315 raeburn 3355: } elsif ($position eq 'bottom') {
3356: $css_class = $rownum%2?' class="LC_odd_row"':'';
3357: $datatable .= '<tr'.$css_class.'>'.
3358: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3359: &mt('(e-mail, subject, and description always shown)').
3360: '</td><td class="LC_left_item">';
3361: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3362: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3363: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3364: foreach my $field (@{$fields}) {
3365: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3366: if (($field eq 'screenshot') || ($field eq 'cc')) {
3367: $datatable .= ' '.&mt('(logged-in users)');
3368: }
3369: $datatable .='</td><td>';
3370: my $clickaction;
3371: if ($field eq 'screenshot') {
3372: $clickaction = ' onclick="screenshotSize(this);"';
3373: }
3374: if (ref($possoptions->{$field}) eq 'ARRAY') {
3375: foreach my $option (@{$possoptions->{$field}}) {
3376: my $checked;
3377: if ($currfield{$field} eq $option) {
3378: $checked = ' checked="checked"';
3379: }
3380: $datatable .= '<span class="LC_nobreak"><label>'.
3381: '<input type="radio" name="helpform_'.$field.'" '.
3382: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3383: '</label></span>'.(' 'x2);
3384: }
3385: }
3386: if ($field eq 'screenshot') {
3387: my $display;
3388: if ($currfield{$field} eq 'no') {
3389: $display = ' style="display:none"';
3390: }
3391: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.' />'.
3392: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3393: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3394: }
3395: $datatable .= '</td></tr>';
3396: }
3397: $datatable .= '</table>';
3398: }
3399: $datatable .= '</td></tr>'."\n";
3400: $rownum ++;
3401: }
3402: unless ($position eq 'top') {
1.286 raeburn 3403: foreach my $type (@mailings) {
3404: $css_class = $rownum%2?' class="LC_odd_row"':'';
3405: $datatable .= '<tr'.$css_class.'>'.
3406: '<td><span class="LC_nobreak">'.
3407: $titles->{$type}.': </span></td>'.
3408: '<td class="LC_left_item">';
3409: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3410: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3411: }
3412: $datatable .= '<span class="LC_nobreak">';
3413: foreach my $item (@contacts) {
3414: $datatable .= '<label>'.
3415: '<input type="checkbox" name="'.$type.'"'.
3416: $checked{$type}{$item}.
3417: ' value="'.$item.'" />'.$short_titles->{$item}.
3418: '</label> ';
3419: }
3420: $datatable .= '</span><br />'.&mt('Others').': '.
3421: '<input type="text" name="'.$type.'_others" '.
3422: 'value="'.$otheremails{$type}.'" />';
3423: my %locchecked;
3424: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3425: foreach my $loc ('s','b') {
3426: if ($includeloc{$type} eq $loc) {
3427: $locchecked{$loc} = ' checked="checked"';
3428: last;
3429: }
3430: }
3431: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3432: '<input type="text" name="'.$type.'_bcc" '.
3433: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3434: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3435: &mt('Text automatically added to e-mail:').' '.
3436: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br >'.
3437: '<span class="LC_nobreak">'.&mt('Location:').' '.
3438: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3439: (' 'x2).
3440: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3441: '</span></fieldset>';
3442: }
3443: $datatable .= '</td></tr>'."\n";
3444: $rownum ++;
3445: }
1.28 raeburn 3446: }
1.286 raeburn 3447: if ($position eq 'middle') {
3448: my %choices;
3449: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
1.289 raeburn 3450: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3451: &mt('LON-CAPA core group - MSU'),600,500));
1.286 raeburn 3452: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
3453: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3454: &mt('LON-CAPA core group - MSU'),600,500));
3455: my @toggles = ('reporterrors','reportupdates');
3456: my %defaultchecked = ('reporterrors' => 'on',
3457: 'reportupdates' => 'on');
3458: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3459: \%choices,$rownum);
3460: $datatable .= $reports;
3461: } elsif ($position eq 'bottom') {
1.315 raeburn 3462: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3463: my (@posstypes,%usertypeshash);
3464: if (ref($types) eq 'ARRAY') {
3465: @posstypes = @{$types};
3466: }
3467: if (@posstypes) {
3468: if (ref($usertypes) eq 'HASH') {
3469: %usertypeshash = %{$usertypes};
3470: }
3471: my @overridden;
3472: my $numinrow = 4;
3473: if (ref($settings) eq 'HASH') {
3474: if (ref($settings->{'overrides'}) eq 'HASH') {
3475: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
3476: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
3477: push(@overridden,$key);
3478: foreach my $item (@contacts) {
3479: if ($settings->{'overrides'}{$key}{$item}) {
3480: $checked{'override_'.$key}{$item} = ' checked="checked" ';
3481: }
3482: }
3483: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
3484: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
3485: $includeloc{'override_'.$key} = '';
3486: $includestr{'override_'.$key} = '';
3487: if ($settings->{'overrides'}{$key}{'include'} ne '') {
3488: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
3489: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
3490: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
3491: }
1.286 raeburn 3492: }
3493: }
3494: }
1.315 raeburn 3495: }
3496: my $customclass = 'LC_helpdesk_override';
3497: my $optionsprefix = 'LC_options_helpdesk_';
3498:
3499: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
3500:
3501: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
3502: $numinrow,$othertitle,'overrides',
3503: \$rownum,$onclicktypes,$customclass);
3504: $rownum ++;
3505: $usertypeshash{'default'} = $othertitle;
3506: foreach my $status (@posstypes) {
3507: my $css_class;
3508: if ($rownum%2) {
3509: $css_class = 'LC_odd_row ';
3510: }
3511: $css_class .= $customclass;
3512: my $rowid = $optionsprefix.$status;
3513: my $hidden = 1;
3514: my $currstyle = 'display:none';
3515: if (grep(/^\Q$status\E$/,@overridden)) {
3516: $currstyle = 'display:table-row';
3517: $hidden = 0;
3518: }
3519: my $key = 'override_'.$status;
3520: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
3521: $includeloc{$key},$includestr{$key},$status,$rowid,
3522: $usertypeshash{$status},$css_class,$currstyle,
3523: \@contacts,$short_titles);
3524: unless ($hidden) {
3525: $rownum ++;
1.286 raeburn 3526: }
3527: }
1.134 raeburn 3528: }
1.28 raeburn 3529: }
1.30 raeburn 3530: $$rowtotal += $rownum;
1.28 raeburn 3531: return $datatable;
3532: }
3533:
1.315 raeburn 3534: sub overridden_helpdesk {
3535: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
3536: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
3537: my $class = 'LC_left_item';
3538: if ($css_class) {
3539: $css_class = ' class="'.$css_class.'"';
3540: }
3541: if ($rowid) {
3542: $rowid = ' id="'.$rowid.'"';
3543: }
3544: if ($rowstyle) {
3545: $rowstyle = ' style="'.$rowstyle.'"';
3546: }
3547: my ($output,$description);
3548: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
3549: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
3550: "<td>$description</td>\n".
3551: '<td class="'.$class.'" colspan="2">'.
3552: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
3553: '<span class="LC_nobreak">';
3554: if (ref($contacts) eq 'ARRAY') {
3555: foreach my $item (@{$contacts}) {
3556: my $check;
3557: if (ref($checked) eq 'HASH') {
3558: $check = $checked->{$item};
3559: }
3560: my $title;
3561: if (ref($short_titles) eq 'HASH') {
3562: $title = $short_titles->{$item};
3563: }
3564: $output .= '<label>'.
3565: '<input type="checkbox" name="override_'.$type.'"'.$check.
3566: ' value="'.$item.'" />'.$title.'</label> ';
3567: }
3568: }
3569: $output .= '</span><br />'.&mt('Others').': '.
3570: '<input type="text" name="override_'.$type.'_others" '.
3571: 'value="'.$otheremails.'" />';
3572: my %locchecked;
3573: foreach my $loc ('s','b') {
3574: if ($includeloc eq $loc) {
3575: $locchecked{$loc} = ' checked="checked"';
3576: last;
3577: }
3578: }
3579: $output .= '<br />'.&mt('Bcc:').(' 'x6).
3580: '<input type="text" name="override_'.$type.'_bcc" '.
3581: 'value="'.$bccemails.'" /></fieldset>'.
3582: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3583: &mt('Text automatically added to e-mail:').' '.
3584: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br >'.
3585: '<span class="LC_nobreak">'.&mt('Location:').' '.
3586: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3587: (' 'x2).
3588: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3589: '</span></fieldset>'.
3590: '</td></tr>'."\n";
3591: return $output;
3592: }
3593:
1.286 raeburn 3594: sub contacts_javascript {
3595: return <<"ENDSCRIPT";
3596:
3597: <script type="text/javascript">
3598: // <![CDATA[
3599:
3600: function screenshotSize(field) {
3601: if (document.getElementById('help_screenshotsize')) {
3602: if (field.value == 'no') {
1.289 raeburn 3603: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 3604: } else {
3605: document.getElementById('help_screenshotsize').style.display="";
3606: }
3607: }
3608: return;
3609: }
3610:
1.315 raeburn 3611: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
3612: if (form.elements[checkbox].length != undefined) {
3613: var count = 0;
3614: if (docount) {
3615: for (var i=0; i<form.elements[checkbox].length; i++) {
3616: if (form.elements[checkbox][i].checked) {
3617: count ++;
3618: }
3619: }
3620: }
3621: for (var i=0; i<form.elements[checkbox].length; i++) {
3622: var type = form.elements[checkbox][i].value;
3623: if (document.getElementById(prefix+type)) {
3624: if (form.elements[checkbox][i].checked) {
3625: document.getElementById(prefix+type).style.display = 'table-row';
3626: if (count % 2 == 1) {
3627: document.getElementById(prefix+type).className = target+' LC_odd_row';
3628: } else {
3629: document.getElementById(prefix+type).className = target;
3630: }
3631: count ++;
3632: } else {
3633: document.getElementById(prefix+type).style.display = 'none';
3634: }
3635: }
3636: }
3637: }
3638: return;
3639: }
3640:
3641:
1.286 raeburn 3642: // ]]>
3643: </script>
3644:
3645: ENDSCRIPT
3646: }
3647:
1.118 jms 3648: sub print_helpsettings {
1.282 raeburn 3649: my ($position,$dom,$settings,$rowtotal) = @_;
3650: my $confname = $dom.'-domainconfig';
1.285 raeburn 3651: my $formname = 'display';
1.168 raeburn 3652: my ($datatable,$itemcount);
1.282 raeburn 3653: if ($position eq 'top') {
3654: $itemcount = 1;
3655: my (%choices,%defaultchecked,@toggles);
3656: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3657: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3658: &mt('LON-CAPA bug tracker'),600,500));
3659: %defaultchecked = ('submitbugs' => 'on');
3660: @toggles = ('submitbugs');
3661: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3662: \%choices,$itemcount);
3663: $$rowtotal ++;
3664: } else {
3665: my $css_class;
3666: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 3667: my (%customroles,%ordered,%current);
1.301 raeburn 3668: if (ref($settings) eq 'HASH') {
3669: if (ref($settings->{'adhoc'}) eq 'HASH') {
3670: %current = %{$settings->{'adhoc'}};
3671: }
1.285 raeburn 3672: }
3673: my $count = 0;
3674: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 3675: if ($key=~/^rolesdef\_(\w+)$/) {
3676: my $rolename = $1;
1.285 raeburn 3677: my (%privs,$order);
1.282 raeburn 3678: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3679: $customroles{$rolename} = \%privs;
1.285 raeburn 3680: if (ref($current{$rolename}) eq 'HASH') {
3681: $order = $current{$rolename}{'order'};
3682: }
3683: if ($order eq '') {
3684: $order = $count;
3685: }
3686: $ordered{$order} = $rolename;
3687: $count++;
3688: }
3689: }
3690: my $maxnum = scalar(keys(%ordered));
3691: my @roles_by_num = ();
3692: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3693: push(@roles_by_num,$item);
3694: }
3695: my $context = 'domprefs';
3696: my $crstype = 'Course';
3697: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 3698: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 3699: my ($numstatustypes,@jsarray);
3700: if (ref($types) eq 'ARRAY') {
3701: if (@{$types} > 0) {
3702: $numstatustypes = scalar(@{$types});
3703: push(@accesstypes,'status');
3704: @jsarray = ('bystatus');
1.282 raeburn 3705: }
3706: }
1.290 raeburn 3707: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 3708: if (keys(%domhelpdesk)) {
3709: push(@accesstypes,('inc','exc'));
3710: push(@jsarray,('notinc','notexc'));
3711: }
3712: my $hiddenstr = join("','",@jsarray);
3713: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.282 raeburn 3714: my $context = 'domprefs';
3715: my $crstype = 'Course';
1.285 raeburn 3716: my $prefix = 'helproles_';
3717: my $add_class = 'LC_hidden';
3718: foreach my $num (@roles_by_num) {
3719: my $role = $ordered{$num};
3720: my ($desc,$access,@statuses);
3721: if (ref($current{$role}) eq 'HASH') {
3722: $desc = $current{$role}{'desc'};
3723: $access = $current{$role}{'access'};
3724: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3725: @statuses = @{$current{$role}{'insttypes'}};
3726: }
3727: }
3728: if ($desc eq '') {
3729: $desc = $role;
3730: }
3731: my $identifier = 'custhelp'.$num;
1.282 raeburn 3732: my %full=();
3733: my %levels= (
3734: course => {},
3735: domain => {},
3736: system => {},
3737: );
3738: my %levelscurrent=(
3739: course => {},
3740: domain => {},
3741: system => {},
3742: );
3743: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3744: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3745: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 3746: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 3747: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 3748: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3749: for (my $k=0; $k<=$maxnum; $k++) {
3750: my $vpos = $k+1;
3751: my $selstr;
3752: if ($k == $num) {
3753: $selstr = ' selected="selected" ';
3754: }
3755: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3756: }
3757: $datatable .= '</select>'.(' 'x2).
3758: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3759: '</td>'.
3760: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3761: &mt('Name shown to users:').
3762: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3763: '</fieldset>'.
3764: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3765: $othertitle,$usertypes,$types,\%domhelpdesk).
3766: '<fieldset>'.
3767: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 3768: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 3769: \%levelscurrent,$identifier,
3770: 'LC_hidden',$prefix.$num.'_privs').
3771: '</fieldset></td>';
1.282 raeburn 3772: $itemcount ++;
3773: }
3774: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3775: my $newcust = 'custhelp'.$count;
3776: my (%privs,%levelscurrent);
3777: my %full=();
3778: my %levels= (
3779: course => {},
3780: domain => {},
3781: system => {},
3782: );
3783: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3784: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 3785: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 3786: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 3787: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3788: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3789: for (my $k=0; $k<$maxnum+1; $k++) {
3790: my $vpos = $k+1;
3791: my $selstr;
3792: if ($k == $maxnum) {
3793: $selstr = ' selected="selected" ';
3794: }
3795: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3796: }
3797: $datatable .= '</select> '."\n".
1.282 raeburn 3798: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3799: '</label></span></td>'.
1.285 raeburn 3800: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3801: '<span class="LC_nobreak">'.
3802: &mt('Internal name:').
3803: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3804: '</span>'.(' 'x4).
3805: '<span class="LC_nobreak">'.
3806: &mt('Name shown to users:').
3807: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3808: '</span></fieldset>'.
3809: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3810: $usertypes,$types,\%domhelpdesk).
3811: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 3812: &Apache::lonuserutils::custom_role_header($context,$crstype,
3813: \@templateroles,$newcust).
3814: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3815: \%levelscurrent,$newcust).
1.285 raeburn 3816: '</fieldset></td></tr>';
1.282 raeburn 3817: $count ++;
3818: $$rowtotal += $count;
3819: }
1.166 raeburn 3820: return $datatable;
1.121 raeburn 3821: }
3822:
1.285 raeburn 3823: sub adhocbutton {
3824: my ($prefix,$num,$field,$visibility) = @_;
3825: my %lt = &Apache::lonlocal::texthash(
3826: show => 'Show details',
3827: hide => 'Hide details',
3828: );
3829: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3830: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3831: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3832: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3833: }
3834:
3835: sub helpsettings_javascript {
3836: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3837: return unless(ref($roles_by_num) eq 'ARRAY');
3838: my %html_js_lt = &Apache::lonlocal::texthash(
3839: show => 'Show details',
3840: hide => 'Hide details',
3841: );
3842: &html_escape(\%html_js_lt);
3843: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3844: return <<"ENDSCRIPT";
3845: <script type="text/javascript">
3846: // <![CDATA[
3847:
3848: function reorderHelpRoles(form,item) {
3849: var changedVal;
3850: $jstext
3851: var newpos = 'helproles_${total}_pos';
3852: var maxh = 1 + $total;
3853: var current = new Array();
3854: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3855: if (item == newpos) {
3856: changedVal = newitemVal;
3857: } else {
3858: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3859: current[newitemVal] = newpos;
3860: }
3861: for (var i=0; i<helproles.length; i++) {
3862: var elementName = 'helproles_'+helproles[i]+'_pos';
3863: if (elementName != item) {
3864: if (form.elements[elementName]) {
3865: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3866: current[currVal] = elementName;
3867: }
3868: }
3869: }
3870: var oldVal;
3871: for (var j=0; j<maxh; j++) {
3872: if (current[j] == undefined) {
3873: oldVal = j;
3874: }
3875: }
3876: if (oldVal < changedVal) {
3877: for (var k=oldVal+1; k<=changedVal ; k++) {
3878: var elementName = current[k];
3879: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3880: }
3881: } else {
3882: for (var k=changedVal; k<oldVal; k++) {
3883: var elementName = current[k];
3884: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3885: }
3886: }
3887: return;
3888: }
3889:
3890: function helpdeskAccess(num) {
3891: var curraccess = null;
3892: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3893: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3894: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3895: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3896: }
3897: }
3898: }
3899: var shown = Array();
3900: var hidden = Array();
3901: if (curraccess == 'none') {
3902: hidden = Array('$hiddenstr');
3903: } else {
3904: if (curraccess == 'status') {
3905: shown = Array('bystatus');
3906: hidden = Array('notinc','notexc');
3907: } else {
3908: if (curraccess == 'exc') {
3909: shown = Array('notexc');
3910: hidden = Array('notinc','bystatus');
3911: }
3912: if (curraccess == 'inc') {
3913: shown = Array('notinc');
3914: hidden = Array('notexc','bystatus');
3915: }
1.293 raeburn 3916: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 3917: hidden = Array('notinc','notexc','bystatus');
3918: }
3919: }
3920: }
3921: if (hidden.length > 0) {
3922: for (var i=0; i<hidden.length; i++) {
3923: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3924: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3925: }
3926: }
3927: }
3928: if (shown.length > 0) {
3929: for (var i=0; i<shown.length; i++) {
3930: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
3931: if (shown[i] == 'privs') {
3932: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
3933: } else {
3934: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
3935: }
3936: }
3937: }
3938: }
3939: return;
3940: }
3941:
3942: function toggleHelpdeskItem(num,field) {
3943: if (document.getElementById('helproles_'+num+'_'+field)) {
3944: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 3945: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 3946: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
3947: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3948: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
3949: }
3950: } else {
3951: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
3952: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3953: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
3954: }
3955: }
3956: }
3957: return;
3958: }
3959:
3960: // ]]>
3961: </script>
3962:
3963: ENDSCRIPT
3964: }
3965:
3966: sub helpdeskroles_access {
3967: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
3968: $usertypes,$types,$domhelpdesk) = @_;
3969: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
3970: my %lt = &Apache::lonlocal::texthash(
3971: 'rou' => 'Role usage',
3972: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 3973: 'all' => 'All with domain helpdesk or helpdesk assistant role',
3974: 'dh' => 'All with domain helpdesk role',
3975: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 3976: 'none' => 'None',
3977: 'status' => 'Determined based on institutional status',
3978: 'inc' => 'Include all, but exclude specific personnel',
3979: 'exc' => 'Exclude all, but include specific personnel',
3980: );
3981: my %usecheck = (
3982: all => ' checked="checked"',
3983: );
3984: my %displaydiv = (
3985: status => 'none',
3986: inc => 'none',
3987: exc => 'none',
3988: priv => 'block',
3989: );
3990: my $output;
3991: if (ref($current) eq 'HASH') {
3992: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
3993: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
3994: $usecheck{$current->{access}} = $usecheck{'all'};
3995: delete($usecheck{'all'});
3996: if ($current->{access} =~ /^(status|inc|exc)$/) {
3997: my $access = $1;
3998: $displaydiv{$access} = 'inline';
3999: } elsif ($current->{access} eq 'none') {
4000: $displaydiv{'priv'} = 'none';
4001: }
4002: }
4003: }
4004: }
4005: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
4006: '<p>'.$lt{'whi'}.'</p>';
4007: foreach my $access (@{$accesstypes}) {
4008: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
4009: ' onclick="helpdeskAccess('."'$num'".');" />'.
4010: $lt{$access}.'</label>';
4011: if ($access eq 'status') {
4012: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
4013: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
4014: $othertitle,$usertypes,$types).
4015: '</div>';
4016: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
4017: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
4018: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4019: '</div>';
4020: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
4021: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
4022: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4023: '</div>';
4024: }
4025: $output .= '</p>';
4026: }
4027: $output .= '</fieldset>';
4028: return $output;
4029: }
4030:
1.121 raeburn 4031: sub radiobutton_prefs {
1.192 raeburn 4032: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 4033: $additional,$align) = @_;
1.121 raeburn 4034: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
4035: (ref($choices) eq 'HASH'));
4036:
1.170 raeburn 4037: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 4038:
4039: foreach my $item (@{$toggles}) {
4040: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 4041: $checkedon{$item} = ' checked="checked" ';
4042: $checkedoff{$item} = ' ';
1.121 raeburn 4043: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 4044: $checkedoff{$item} = ' checked="checked" ';
4045: $checkedon{$item} = ' ';
4046: }
4047: }
4048: if (ref($settings) eq 'HASH') {
1.121 raeburn 4049: foreach my $item (@{$toggles}) {
1.118 jms 4050: if ($settings->{$item} eq '1') {
4051: $checkedon{$item} = ' checked="checked" ';
4052: $checkedoff{$item} = ' ';
4053: } elsif ($settings->{$item} eq '0') {
4054: $checkedoff{$item} = ' checked="checked" ';
4055: $checkedon{$item} = ' ';
4056: }
4057: }
1.121 raeburn 4058: }
1.192 raeburn 4059: if ($onclick) {
4060: $onclick = ' onclick="'.$onclick.'"';
4061: }
1.121 raeburn 4062: foreach my $item (@{$toggles}) {
1.118 jms 4063: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 4064: $datatable .=
1.306 raeburn 4065: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 4066: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 4067: '</span></td>';
4068: if ($align eq 'left') {
4069: $datatable .= '<td class="LC_left_item">';
4070: } else {
4071: $datatable .= '<td class="LC_right_item">';
4072: }
1.289 raeburn 4073: $datatable .=
1.257 raeburn 4074: '<span class="LC_nobreak">'.
1.118 jms 4075: '<label><input type="radio" name="'.
1.192 raeburn 4076: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 4077: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 4078: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
4079: '</span>'.$additional.
4080: '</td>'.
1.118 jms 4081: '</tr>';
4082: $itemcount ++;
1.121 raeburn 4083: }
4084: return ($datatable,$itemcount);
4085: }
4086:
1.267 raeburn 4087: sub print_ltitools {
4088: my ($dom,$settings,$rowtotal) = @_;
4089: my $rownum = 0;
4090: my $css_class;
4091: my $itemcount = 1;
4092: my $maxnum = 0;
4093: my %ordered;
4094: if (ref($settings) eq 'HASH') {
4095: foreach my $item (keys(%{$settings})) {
4096: if (ref($settings->{$item}) eq 'HASH') {
4097: my $num = $settings->{$item}{'order'};
4098: $ordered{$num} = $item;
4099: }
4100: }
4101: }
4102: my $confname = $dom.'-domainconfig';
4103: my $switchserver = &check_switchserver($dom,$confname);
4104: my $maxnum = scalar(keys(%ordered));
4105: my $datatable = <itools_javascript($settings);
4106: my %lt = <itools_names();
4107: my @courseroles = ('cc','in','ta','ep','st');
4108: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
4109: my @fields = ('fullname','firstname','lastname','email','user','roles');
4110: if (keys(%ordered)) {
4111: my @items = sort { $a <=> $b } keys(%ordered);
4112: for (my $i=0; $i<@items; $i++) {
4113: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4114: my $item = $ordered{$items[$i]};
1.323 ! raeburn 4115: my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
1.267 raeburn 4116: if (ref($settings->{$item}) eq 'HASH') {
4117: $title = $settings->{$item}->{'title'};
4118: $url = $settings->{$item}->{'url'};
4119: $key = $settings->{$item}->{'key'};
4120: $secret = $settings->{$item}->{'secret'};
1.322 raeburn 4121: $lifetime = $settings->{$item}->{'lifetime'};
1.267 raeburn 4122: my $image = $settings->{$item}->{'image'};
4123: if ($image ne '') {
4124: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
4125: }
1.323 ! raeburn 4126: if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
! 4127: $sigsel{'HMAC-256'} = ' selected="selected"';
! 4128: } else {
! 4129: $sigsel{'HMAC-SHA1'} = ' selected="selected"';
! 4130: }
1.267 raeburn 4131: }
1.319 raeburn 4132: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1.267 raeburn 4133: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4134: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
4135: for (my $k=0; $k<=$maxnum; $k++) {
4136: my $vpos = $k+1;
4137: my $selstr;
4138: if ($k == $i) {
4139: $selstr = ' selected="selected" ';
4140: }
4141: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4142: }
4143: $datatable .= '</select>'.(' 'x2).
4144: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
4145: &mt('Delete?').'</label></span></td>'.
4146: '<td colspan="2">'.
4147: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 ! raeburn 4148: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
1.267 raeburn 4149: (' 'x2).
4150: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
4151: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4152: (' 'x2).
4153: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
4154: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 ! raeburn 4155: (' 'x2).
! 4156: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
! 4157: '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
! 4158: '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
1.267 raeburn 4159: '<br /><br />'.
1.323 ! raeburn 4160: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
1.267 raeburn 4161: ' value="'.$url.'" /></span>'.
4162: (' 'x2).
1.319 raeburn 4163: '<span class="LC_nobreak">'.$lt{'key'}.':'.
1.267 raeburn 4164: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
4165: (' 'x2).
1.322 raeburn 4166: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
4167: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
4168: (' 'x2).
1.267 raeburn 4169: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4170: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
4171: '<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>'.
4172: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
4173: '</fieldset>'.
4174: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4175: '<span class="LC_nobreak">'.&mt('Display target:');
4176: my %currdisp;
4177: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
4178: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
4179: $currdisp{'window'} = ' checked="checked"';
1.298 raeburn 4180: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
4181: $currdisp{'tab'} = ' checked="checked"';
1.267 raeburn 4182: } else {
4183: $currdisp{'iframe'} = ' checked="checked"';
4184: }
4185: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
4186: $currdisp{'width'} = $1;
4187: }
4188: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
4189: $currdisp{'height'} = $1;
4190: }
1.296 raeburn 4191: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
4192: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267 raeburn 4193: } else {
4194: $currdisp{'iframe'} = ' checked="checked"';
4195: }
1.298 raeburn 4196: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4197: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
4198: $lt{$disp}.'</label>'.(' 'x2);
4199: }
4200: $datatable .= (' 'x4);
4201: foreach my $dimen ('width','height') {
4202: $datatable .= '<label>'.$lt{$dimen}.' '.
4203: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
4204: (' 'x2);
4205: }
1.296 raeburn 4206: $datatable .= '<br />'.
4207: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
4208: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></label></div>'.
4209: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4210: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
4211: '</textarea></div><div style=""></div><br />';
1.319 raeburn 4212: my %units = (
4213: 'passback' => 'days',
4214: 'roster' => 'seconds',
4215: );
1.267 raeburn 4216: foreach my $extra ('passback','roster') {
1.319 raeburn 4217: my $validsty = 'none';
4218: my $currvalid;
1.267 raeburn 4219: my $checkedon = '';
4220: my $checkedoff = ' checked="checked"';
4221: if ($settings->{$item}->{$extra}) {
4222: $checkedon = $checkedoff;
4223: $checkedoff = '';
1.319 raeburn 4224: $validsty = 'inline-block';
4225: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
4226: $currvalid = $settings->{$item}->{$extra.'valid'};
4227: }
4228: }
4229: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
4230: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4231: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
4232: &mt('No').'</label>'.(' 'x2).
4233: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
4234: &mt('Yes').'</label></span></div>'.
4235: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
4236: '<span class="LC_nobreak">'.
4237: &mt("at least [_1] $units{$extra} after launch",
4238: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
4239: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4240: }
1.319 raeburn 4241: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
1.267 raeburn 4242: if ($imgsrc) {
4243: $datatable .= $imgsrc.
4244: '<label><input type="checkbox" name="ltitools_image_del"'.
4245: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
4246: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
4247: } else {
4248: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4249: }
4250: if ($switchserver) {
4251: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4252: } else {
4253: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
4254: }
4255: $datatable .= '</span></fieldset>';
4256: my (%checkedfields,%rolemaps);
4257: if (ref($settings->{$item}) eq 'HASH') {
4258: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
4259: %checkedfields = %{$settings->{$item}->{'fields'}};
4260: }
4261: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
4262: %rolemaps = %{$settings->{$item}->{'roles'}};
4263: $checkedfields{'roles'} = 1;
4264: }
4265: }
4266: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4267: '<span class="LC_nobreak">';
4268: foreach my $field (@fields) {
4269: my $checked;
4270: if ($checkedfields{$field}) {
4271: $checked = ' checked="checked"';
4272: }
4273: $datatable .= '<label>'.
4274: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$checked.' />'.
4275: $lt{$field}.'</label>'.(' ' x2);
4276: }
4277: $datatable .= '</span></fieldset>'.
4278: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4279: foreach my $role (@courseroles) {
4280: my ($selected,$selectnone);
4281: if (!$rolemaps{$role}) {
4282: $selectnone = ' selected="selected"';
4283: }
1.306 raeburn 4284: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4285: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4286: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
4287: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
4288: foreach my $ltirole (@ltiroles) {
4289: unless ($selectnone) {
4290: if ($rolemaps{$role} eq $ltirole) {
4291: $selected = ' selected="selected"';
4292: } else {
4293: $selected = '';
4294: }
4295: }
4296: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
4297: }
4298: $datatable .= '</select></td>';
4299: }
1.273 raeburn 4300: $datatable .= '</tr></table></fieldset>';
4301: my %courseconfig;
4302: if (ref($settings->{$item}) eq 'HASH') {
4303: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
4304: %courseconfig = %{$settings->{$item}->{'crsconf'}};
4305: }
4306: }
4307: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4308: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 4309: my $checked;
4310: if ($courseconfig{$item}) {
4311: $checked = ' checked="checked"';
4312: }
4313: $datatable .= '<label>'.
4314: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
4315: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
4316: }
4317: $datatable .= '</span></fieldset>'.
1.267 raeburn 4318: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4319: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
4320: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
4321: my %custom = %{$settings->{$item}->{'custom'}};
4322: if (keys(%custom) > 0) {
4323: foreach my $key (sort(keys(%custom))) {
4324: $datatable .= '<tr><td><span class="LC_nobreak">'.
4325: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
4326: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
4327: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
4328: ' value="'.$custom{$key}.'" /></td></tr>';
4329: }
4330: }
4331: }
4332: $datatable .= '<tr><td><span class="LC_nobreak">'.
4333: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
4334: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
4335: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
4336: $datatable .= '</table></fieldset></td></tr>'."\n";
4337: $itemcount ++;
4338: }
4339: }
4340: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.319 raeburn 4341: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1.267 raeburn 4342: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4343: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
4344: '<select name="ltitools_add_pos"'.$chgstr.'>';
4345: for (my $k=0; $k<$maxnum+1; $k++) {
4346: my $vpos = $k+1;
4347: my $selstr;
4348: if ($k == $maxnum) {
4349: $selstr = ' selected="selected" ';
4350: }
4351: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4352: }
4353: $datatable .= '</select> '."\n".
4354: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".
4355: '<td colspan="2">'.
4356: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 ! raeburn 4357: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
1.267 raeburn 4358: (' 'x2).
4359: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
4360: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4361: (' 'x2).
4362: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
4363: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 ! raeburn 4364: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
! 4365: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
! 4366: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
1.267 raeburn 4367: '<br />'.
1.323 ! raeburn 4368: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
1.267 raeburn 4369: (' 'x2).
4370: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
4371: (' 'x2).
1.322 raeburn 4372: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
4373: (' 'x2).
1.267 raeburn 4374: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
4375: '<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".
4376: '</fieldset>'.
4377: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4378: '<span class="LC_nobreak">'.&mt('Display target:');
4379: my %defaultdisp;
4380: $defaultdisp{'iframe'} = ' checked="checked"';
1.298 raeburn 4381: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4382: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
4383: $lt{$disp}.'</label>'.(' 'x2);
4384: }
4385: $datatable .= (' 'x4);
4386: foreach my $dimen ('width','height') {
4387: $datatable .= '<label>'.$lt{$dimen}.' '.
4388: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
4389: (' 'x2);
4390: }
1.296 raeburn 4391: $datatable .= '<br />'.
4392: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
4393: '<input type="text" name="ltitools_add_linktext" size="5" /></label></div>'.
4394: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4395: '<textarea name=ltitools_add_explanation" rows="5" cols="40"></textarea>'.
4396: '</div><div style=""></div><br />';
1.319 raeburn 4397: my %units = (
4398: 'passback' => 'days',
4399: 'roster' => 'seconds',
4400: );
4401: my %defaulttimes = (
4402: 'passback' => '7',
1.322 raeburn 4403: 'roster' => '300',
1.319 raeburn 4404: );
1.267 raeburn 4405: foreach my $extra ('passback','roster') {
1.319 raeburn 4406: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
4407: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4408: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
4409: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
4410: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
4411: &mt('Yes').'</label></span></div>'.
4412: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
4413: '<span class="LC_nobreak">'.
4414: &mt("at least [_1] $units{$extra} after launch",
4415: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
4416: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4417: }
1.319 raeburn 4418: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
1.267 raeburn 4419: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4420: if ($switchserver) {
4421: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4422: } else {
4423: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
4424: }
4425: $datatable .= '</span></fieldset>'.
4426: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4427: '<span class="LC_nobreak">';
4428: foreach my $field (@fields) {
4429: $datatable .= '<label>'.
4430: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'" />'.
4431: $lt{$field}.'</label>'.(' ' x2);
4432: }
4433: $datatable .= '</span></fieldset>'.
4434: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4435: foreach my $role (@courseroles) {
4436: my ($checked,$checkednone);
1.306 raeburn 4437: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4438: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4439: '<select name="ltitools_add_roles_'.$role.'">'.
4440: '<option value="" selected="selected">'.&mt('Select').'</option>';
4441: foreach my $ltirole (@ltiroles) {
4442: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
4443: }
4444: $datatable .= '</select></td>';
4445: }
4446: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 4447: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4448: foreach my $item ('label','title','target','linktext','explanation','append') {
1.296 raeburn 4449: $datatable .= '<label>'.
4450: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
4451: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
1.273 raeburn 4452: }
4453: $datatable .= '</span></fieldset>'.
1.267 raeburn 4454: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4455: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
4456: '<tr><td><span class="LC_nobreak">'.
4457: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
4458: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
4459: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
4460: '</table></fieldset></td></tr>'."\n".
4461: '</td>'."\n".
4462: '</tr>'."\n";
4463: $itemcount ++;
4464: return $datatable;
4465: }
4466:
4467: sub ltitools_names {
4468: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 4469: 'title' => 'Title',
4470: 'version' => 'Version',
4471: 'msgtype' => 'Message Type',
1.323 ! raeburn 4472: 'sigmethod' => 'Signature Method',
1.296 raeburn 4473: 'url' => 'URL',
4474: 'key' => 'Key',
1.322 raeburn 4475: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 4476: 'secret' => 'Secret',
4477: 'icon' => 'Icon',
4478: 'user' => 'Username:domain',
4479: 'fullname' => 'Full Name',
4480: 'firstname' => 'First Name',
4481: 'lastname' => 'Last Name',
4482: 'email' => 'E-mail',
4483: 'roles' => 'Role',
1.298 raeburn 4484: 'window' => 'Window',
4485: 'tab' => 'Tab',
1.296 raeburn 4486: 'iframe' => 'iFrame',
4487: 'height' => 'Height',
4488: 'width' => 'Width',
4489: 'linktext' => 'Default Link Text',
4490: 'explanation' => 'Default Explanation',
4491: 'passback' => 'Tool can return grades:',
4492: 'roster' => 'Tool can retrieve roster:',
4493: 'crstarget' => 'Display target',
4494: 'crslabel' => 'Course label',
4495: 'crstitle' => 'Course title',
4496: 'crslinktext' => 'Link Text',
4497: 'crsexplanation' => 'Explanation',
1.318 raeburn 4498: 'crsappend' => 'Provider URL',
1.267 raeburn 4499: );
4500: return %lt;
4501: }
4502:
1.320 raeburn 4503: sub print_lti {
4504: my ($dom,$settings,$rowtotal) = @_;
4505: my $itemcount = 1;
4506: my $maxnum = 0;
4507: my $css_class;
4508: my %ordered;
4509: if (ref($settings) eq 'HASH') {
4510: foreach my $item (keys(%{$settings})) {
4511: if (ref($settings->{$item}) eq 'HASH') {
4512: my $num = $settings->{$item}{'order'};
4513: $ordered{$num} = $item;
4514: }
4515: }
4516: }
4517: my $maxnum = scalar(keys(%ordered));
4518: my $datatable = <i_javascript($settings);
4519: my %lt = <i_names();
4520: if (keys(%ordered)) {
4521: my @items = sort { $a <=> $b } keys(%ordered);
4522: for (my $i=0; $i<@items; $i++) {
4523: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4524: my $item = $ordered{$items[$i]};
4525: my ($key,$secret,$lifetime,$consumer,$current);
4526: if (ref($settings->{$item}) eq 'HASH') {
4527: $key = $settings->{$item}->{'key'};
4528: $secret = $settings->{$item}->{'secret'};
4529: $lifetime = $settings->{$item}->{'lifetime'};
4530: $consumer = $settings->{$item}->{'consumer'};
4531: $current = $settings->{$item};
4532: }
4533: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
4534: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4535: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
4536: for (my $k=0; $k<=$maxnum; $k++) {
4537: my $vpos = $k+1;
4538: my $selstr;
4539: if ($k == $i) {
4540: $selstr = ' selected="selected" ';
4541: }
4542: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4543: }
4544: $datatable .= '</select>'.(' 'x2).
4545: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
4546: &mt('Delete?').'</label></span></td>'.
4547: '<td colspan="2">'.
4548: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4549: '<span class="LC_nobreak">'.$lt{'consumer'}.
4550: ':<input type="text" size="20" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
4551: (' 'x2).
4552: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
4553: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4554: (' 'x2).
4555: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
4556: 'value="'.$lifetime.'" size="5" /></span>'.
4557: '<br /><br />'.
4558: '<span class="LC_nobreak">'.$lt{'key'}.
4559: ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
4560: (' 'x2).
4561: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4562: '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
4563: '<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>'.
4564: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
4565: '</fieldset>'.<i_options($i,$current,%lt).'</td></tr>';
4566: $itemcount ++;
4567: }
4568: }
4569: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4570: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
4571: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4572: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
4573: '<select name="lti_pos_add"'.$chgstr.'>';
4574: for (my $k=0; $k<$maxnum+1; $k++) {
4575: my $vpos = $k+1;
4576: my $selstr;
4577: if ($k == $maxnum) {
4578: $selstr = ' selected="selected" ';
4579: }
4580: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4581: }
4582: $datatable .= '</select> '."\n".
4583: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</td>'."\n".
4584: '<td colspan="2">'.
4585: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4586: '<span class="LC_nobreak">'.$lt{'consumer'}.
4587: ':<input type="text" size="20" name="lti_consumer_add" value="" /></span> '."\n".
4588: (' 'x2).
4589: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
4590: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4591: (' 'x2).
1.322 raeburn 4592: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="lti_lifetime_add" value="300" /></span> '."\n".
1.320 raeburn 4593: '<br /><br />'.
4594: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
4595: (' 'x2).
4596: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
4597: '<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".
4598: '</fieldset>'.<i_options('add',undef,%lt).
4599: '</td>'."\n".
4600: '</tr>'."\n";
4601: $$rowtotal ++;
4602: return $datatable;;
4603: }
4604:
4605: sub lti_names {
4606: my %lt = &Apache::lonlocal::texthash(
4607: 'version' => 'LTI Version',
4608: 'url' => 'URL',
4609: 'key' => 'Key',
1.322 raeburn 4610: 'lifetime' => 'Nonce lifetime (s)',
1.320 raeburn 4611: 'consumer' => 'LTI Consumer',
4612: 'secret' => 'Secret',
4613: 'email' => 'Email address',
4614: 'sourcedid' => 'User ID',
4615: 'other' => 'Other',
4616: 'passback' => 'Can return grades to Consumer:',
4617: 'roster' => 'Can retrieve roster from Consumer:',
4618: );
4619: return %lt;
4620: }
4621:
4622: sub lti_options {
4623: my ($num,$current,%lt) = @_;
4624: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield);
4625: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
4626: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
4627: $checked{'makecrs'}{'N'} = ' checked="checked"';
4628: $checked{'mapcrstype'} = {};
4629: $checked{'makeuser'} = {};
4630: $checked{'selfenroll'} = {};
4631: $checked{'crssec'} = {};
4632: $checked{'crssecsrc'} = {};
4633:
4634: my $userfieldsty = 'none';
4635: my $crsfieldsty = 'none';
4636: my $crssecfieldsty = 'none';
4637: my $secsrcfieldsty = 'none';
4638:
4639: if (ref($current) eq 'HASH') {
4640: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
4641: $checked{'mapuser'}{'sourcedid'} = '';
4642: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
4643: $checked{'mapuser'}{'email'} = ' checked="checked"';
4644: } else {
4645: $checked{'mapuser'}{'other'} = ' checked="checked"';
4646: $userfield = $current->{'mapuser'};
4647: $userfieldsty = 'inline-block';
4648: }
4649: }
4650: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
4651: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
4652: if ($current->{'mapcrs'} eq 'context_id') {
4653: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
4654: } else {
4655: $checked{'mapcrs'}{'other'} = ' checked="checked"';
4656: $cidfield = $current->{'mapcrs'};
4657: $crsfieldsty = 'inline-block';
4658: }
4659: }
4660: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
4661: foreach my $type (@{$current->{'mapcrstype'}}) {
4662: $checked{'mapcrstype'}{$type} = ' checked="checked"';
4663: }
4664: }
4665: if ($current->{'makecrs'}) {
4666: $checked{'makecrs'}{'Y'} = ' checked="checked"';
4667: }
4668: if (ref($current->{'makeuser'}) eq 'ARRAY') {
4669: foreach my $role (@{$current->{'makeuser'}}) {
4670: $checked{'makeuser'}{$role} = ' checked="checked"';
4671: }
4672: }
4673: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
4674: foreach my $role (@{$current->{'selfenroll'}}) {
4675: $checked{'selfenroll'}{$role} = ' checked="checked"';
4676: }
4677: }
4678: if (ref($current->{'maproles'}) eq 'HASH') {
4679: %rolemaps = %{$current->{'maproles'}};
4680: }
4681: if ($current->{'section'} ne '') {
4682: $checked{'crssec'}{'Y'} = ' checked="checked"';
4683: $crssecfieldsty = 'inline-block';
4684: if ($current->{'section'} eq 'course_section_sourcedid') {
4685: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
4686: } else {
4687: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
4688: $crssecsrc = $current->{'section'};
4689: $secsrcfieldsty = 'inline-block';
4690: }
4691: } else {
4692: $checked{'crssec'}{'N'} = ' checked="checked"';
4693: }
4694: } else {
4695: $checked{'makecrs'}{'N'} = ' checked="checked"';
4696: $checked{'crssec'}{'N'} = ' checked="checked"';
4697: }
4698: my @coursetypes = ('official','unofficial','community','textbook','placement');
4699: my %coursetypetitles = &Apache::lonlocal::texthash (
4700: official => 'Official',
4701: unofficial => 'Unofficial',
4702: community => 'Community',
4703: textbook => 'Textbook',
4704: placement => 'Placement Test',
4705: );
4706: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
4707: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
4708: my @courseroles = ('cc','in','ta','ep','st');
4709: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
4710: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
4711: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
4712: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
4713: my $output = '<fieldset><legend>'.&mt('Mapping users').'</legend>'.
4714: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
4715: foreach my $option ('sourcedid','email','other') {
4716: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
4717: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
4718: ($option eq 'other' ? '' : (' 'x2) );
4719: }
4720: $output .= '</span></div>'.
4721: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
4722: '<input type="text" name="lti_customuser_'.$num.'" '.
4723: 'value="'.$userfield.'" /></div></fieldset>'.
4724: '<fieldset><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
4725: foreach my $ltirole (@lticourseroles) {
4726: my ($selected,$selectnone);
4727: if ($rolemaps{$ltirole} eq '') {
4728: $selectnone = ' selected="selected"';
4729: }
4730: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
4731: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
4732: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
4733: foreach my $role (@courseroles) {
4734: unless ($selectnone) {
4735: if ($rolemaps{$ltirole} eq $role) {
4736: $selected = ' selected="selected"';
4737: } else {
4738: $selected = '';
4739: }
4740: }
4741: $output .= '<option value="'.$role.'"'.$selected.'>'.
4742: &Apache::lonnet::plaintext($role,'Course').
4743: '</option>';
4744: }
4745: $output .= '</select></td>';
4746: }
4747: $output .= '</tr></table></fieldset>'.
4748: '<fieldset><legend>'.&mt('Roles which may create user accounts').'</legend>';
4749: foreach my $ltirole (@ltiroles) {
4750: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
4751: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
4752: }
4753: $output .= '</fieldset>'.
4754: '<fieldset><legend>'.&mt('Mapping courses').'</legend>'.
4755: '<div class="LC_floatleft"><span class="LC_nobreak">'.
4756: &mt('Unique course identifier').': ';
4757: foreach my $option ('course_offering_sourcedid','context_id','other') {
4758: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
4759: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
4760: ($option eq 'other' ? '' : (' 'x2) );
4761: }
4762: $output .= '</div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'".>'.
4763: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
4764: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
4765: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
4766: foreach my $type (@coursetypes) {
4767: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
4768: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
4769: (' 'x2);
4770: }
4771: $output .= '</span></fieldset>'.
4772: '<fieldset><legend>'.&mt('Creating courses').'</legend>'.
4773: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
4774: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
4775: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
4776: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
4777: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
4778: '</fieldset>'.
4779: '<fieldset><legend>'.&mt('Roles which may self-enroll').'</legend>';
4780: foreach my $lticrsrole (@lticourseroles) {
4781: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
4782: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
4783: }
4784: $output .= '</fieldset>'.
4785: '<fieldset><legend>'.&mt('Course options').'</legend>'.
4786: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
4787: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
4788: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
4789: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
4790: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label><span></div>'.
4791: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
4792: '<span class="LC_nobreak">'.&mt('From').':<label>'.
4793: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
4794: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
4795: &mt('Standard field').'</label>'.(' 'x2).
4796: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
4797: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
4798: '</label></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
4799: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
4800: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
4801: foreach my $extra ('passback','roster') {
4802: my $checkedon = '';
4803: my $checkedoff = ' checked="checked"';
4804: if (ref($current) eq 'HASH') {
4805: if (($current->{$extra})) {
4806: $checkedon = $checkedoff;
4807: $checkedoff = '';
4808: }
4809: }
4810: $output .= $lt{$extra}.' '.
4811: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.' />'.
4812: &mt('No').'</label>'.(' 'x2).
4813: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.' />'.
4814: &mt('Yes').'</label><br />';
4815: }
4816: $output .= '</span></fieldset>';
4817: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
4818: #
4819: # $output .= '</fieldset>'.
4820: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
4821: return $output;
4822: }
4823:
1.121 raeburn 4824: sub print_coursedefaults {
1.139 raeburn 4825: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 4826: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 4827: my $itemcount = 1;
1.192 raeburn 4828: my %choices = &Apache::lonlocal::texthash (
4829: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 4830: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 4831: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
4832: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 4833: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
4834: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.314 raeburn 4835: texengine => 'Default method to display mathematics',
1.257 raeburn 4836: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 4837: canclone => "People who may clone a course (besides course's owner and coordinators)",
4838: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 4839: );
1.198 raeburn 4840: my %staticdefaults = (
1.314 raeburn 4841: texengine => 'MathJax',
1.198 raeburn 4842: anonsurvey_threshold => 10,
4843: uploadquota => 500,
1.257 raeburn 4844: postsubmit => 60,
1.276 raeburn 4845: mysqltables => 172800,
1.198 raeburn 4846: );
1.139 raeburn 4847: if ($position eq 'top') {
1.257 raeburn 4848: %defaultchecked = (
4849: 'canuse_pdfforms' => 'off',
4850: 'uselcmath' => 'on',
4851: 'usejsme' => 'on',
1.289 raeburn 4852: 'canclone' => 'none',
1.257 raeburn 4853: );
4854: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.314 raeburn 4855: my $deftex = $staticdefaults{'texengine'};
4856: if (ref($settings) eq 'HASH') {
4857: if ($settings->{'texengine'}) {
4858: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
4859: $deftex = $settings->{'texengine'};
4860: }
4861: }
4862: }
4863: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4864: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
4865: '<span class="LC_nobreak">'.$choices{'texengine'}.
4866: '</span></td><td class="LC_right_item">'.
4867: '<select name="texengine">'."\n";
4868: my %texoptions = (
4869: MathJax => 'MathJax',
4870: mimetex => &mt('Convert to Images'),
4871: tth => &mt('TeX to HTML'),
4872: );
4873: foreach my $renderer ('MathJax','mimetex','tth') {
4874: my $selected = '';
4875: if ($renderer eq $deftex) {
4876: $selected = ' selected="selected"';
4877: }
4878: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
4879: }
4880: $mathdisp .= '</select></td></tr>'."\n";
4881: $itemcount ++;
1.139 raeburn 4882: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 4883: \%choices,$itemcount);
1.314 raeburn 4884: $datatable = $mathdisp.$datatable;
1.264 raeburn 4885: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4886: $datatable .=
1.306 raeburn 4887: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 4888: '<span class="LC_nobreak">'.$choices{'canclone'}.
4889: '</span></td><td class="LC_left_item">';
4890: my $currcanclone = 'none';
4891: my $onclick;
4892: my @cloneoptions = ('none','domain');
4893: my %clonetitles = (
4894: none => 'No additional course requesters',
4895: domain => "Any course requester in course's domain",
4896: instcode => 'Course requests for official courses ...',
4897: );
4898: my (%codedefaults,@code_order,@posscodes);
4899: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
4900: \@code_order) eq 'ok') {
4901: if (@code_order > 0) {
4902: push(@cloneoptions,'instcode');
4903: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
4904: }
4905: }
4906: if (ref($settings) eq 'HASH') {
4907: if ($settings->{'canclone'}) {
4908: if (ref($settings->{'canclone'}) eq 'HASH') {
4909: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
4910: if (@code_order > 0) {
4911: $currcanclone = 'instcode';
4912: @posscodes = @{$settings->{'canclone'}{'instcode'}};
4913: }
4914: }
4915: } elsif ($settings->{'canclone'} eq 'domain') {
4916: $currcanclone = $settings->{'canclone'};
4917: }
4918: }
1.289 raeburn 4919: }
1.264 raeburn 4920: foreach my $option (@cloneoptions) {
4921: my ($checked,$additional);
4922: if ($currcanclone eq $option) {
4923: $checked = ' checked="checked"';
4924: }
4925: if ($option eq 'instcode') {
4926: if (@code_order) {
4927: my $show = 'none';
4928: if ($checked) {
4929: $show = 'block';
4930: }
1.317 raeburn 4931: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 4932: &mt('Institutional codes for new and cloned course have identical:').
4933: '<br />';
4934: foreach my $item (@code_order) {
4935: my $codechk;
4936: if ($checked) {
4937: if (grep(/^\Q$item\E$/,@posscodes)) {
4938: $codechk = ' checked="checked"';
4939: }
4940: }
4941: $additional .= '<label>'.
4942: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
4943: $item.'</label>';
4944: }
4945: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
4946: }
4947: }
4948: $datatable .=
4949: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
4950: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
4951: '</label> '.$additional.'</span><br />';
4952: }
4953: $datatable .= '</td>'.
4954: '</tr>';
4955: $itemcount ++;
1.139 raeburn 4956: } else {
4957: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 4958: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 4959: my $currusecredits = 0;
1.257 raeburn 4960: my $postsubmitclient = 1;
1.271 raeburn 4961: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 4962: if (ref($settings) eq 'HASH') {
4963: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 4964: if (ref($settings->{'uploadquota'}) eq 'HASH') {
4965: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
4966: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
4967: }
4968: }
1.192 raeburn 4969: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 4970: foreach my $type (@types) {
4971: next if ($type eq 'community');
4972: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
4973: if ($defcredits{$type} ne '') {
4974: $currusecredits = 1;
4975: }
4976: }
4977: }
4978: if (ref($settings->{'postsubmit'}) eq 'HASH') {
4979: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
4980: $postsubmitclient = 0;
4981: foreach my $type (@types) {
4982: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4983: }
4984: } else {
4985: foreach my $type (@types) {
4986: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
4987: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 4988: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 4989: } else {
4990: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4991: }
4992: } else {
4993: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4994: }
4995: }
4996: }
4997: } else {
4998: foreach my $type (@types) {
4999: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 5000: }
5001: }
1.276 raeburn 5002: if (ref($settings->{'mysqltables'}) eq 'HASH') {
5003: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
5004: $currmysql{$type} = $settings->{'mysqltables'}{$type};
5005: }
5006: } else {
5007: foreach my $type (@types) {
5008: $currmysql{$type} = $staticdefaults{'mysqltables'};
5009: }
5010: }
1.258 raeburn 5011: } else {
5012: foreach my $type (@types) {
5013: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5014: }
1.139 raeburn 5015: }
5016: if (!$currdefresponder) {
1.198 raeburn 5017: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 5018: } elsif ($currdefresponder < 1) {
5019: $currdefresponder = 1;
5020: }
1.198 raeburn 5021: foreach my $type (@types) {
5022: if ($curruploadquota{$type} eq '') {
5023: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
5024: }
5025: }
1.139 raeburn 5026: $datatable .=
1.192 raeburn 5027: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5028: $choices{'anonsurvey_threshold'}.
1.139 raeburn 5029: '</span></td>'.
5030: '<td class="LC_right_item"><span class="LC_nobreak">'.
5031: '<input type="text" name="anonsurvey_threshold"'.
5032: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 5033: '</td></tr>'."\n";
5034: $itemcount ++;
5035: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5036: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5037: $choices{'uploadquota'}.
5038: '</span></td>'.
1.306 raeburn 5039: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 5040: '<table><tr>';
1.198 raeburn 5041: foreach my $type (@types) {
1.306 raeburn 5042: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 5043: '<input type="text" name="uploadquota_'.$type.'"'.
5044: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
5045: }
5046: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 5047: $itemcount ++;
1.236 raeburn 5048: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 5049: my $display = 'none';
1.192 raeburn 5050: if ($currusecredits) {
5051: $display = 'block';
5052: }
5053: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 5054: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
5055: foreach my $type (@types) {
5056: next if ($type eq 'community');
1.306 raeburn 5057: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 5058: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 5059: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 5060: }
5061: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 5062: %defaultchecked = ('coursecredits' => 'off');
5063: @toggles = ('coursecredits');
5064: my $current = {
5065: 'coursecredits' => $currusecredits,
5066: };
5067: (my $table,$itemcount) =
5068: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 5069: \%choices,$itemcount,$onclick,$additional,'left');
5070: $datatable .= $table;
5071: $onclick = "toggleDisplay(this.form,'studentsubmission');";
5072: my $display = 'none';
5073: if ($postsubmitclient) {
5074: $display = 'block';
5075: }
5076: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 5077: &mt('Number of seconds submit is disabled').'<br />'.
5078: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
5079: '<table><tr>';
1.257 raeburn 5080: foreach my $type (@types) {
1.306 raeburn 5081: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 5082: '<input type="text" name="'.$type.'_timeout" value="'.
5083: $deftimeout{$type}.'" size="5" /></td>';
5084: }
5085: $additional .= '</tr></table></div>'."\n";
5086: %defaultchecked = ('postsubmit' => 'on');
5087: @toggles = ('postsubmit');
1.280 raeburn 5088: $current = {
5089: 'postsubmit' => $postsubmitclient,
5090: };
1.257 raeburn 5091: ($table,$itemcount) =
5092: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
5093: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 5094: $datatable .= $table;
1.276 raeburn 5095: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5096: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5097: $choices{'mysqltables'}.
5098: '</span></td>'.
1.306 raeburn 5099: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 5100: '<table><tr>';
5101: foreach my $type (@types) {
1.306 raeburn 5102: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 5103: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 5104: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 5105: }
5106: $datatable .= '</tr></table></td></tr>'."\n";
5107: $itemcount ++;
5108:
1.139 raeburn 5109: }
1.192 raeburn 5110: $$rowtotal += $itemcount;
1.121 raeburn 5111: return $datatable;
1.118 jms 5112: }
5113:
1.231 raeburn 5114: sub print_selfenrollment {
5115: my ($position,$dom,$settings,$rowtotal) = @_;
5116: my ($css_class,$datatable);
5117: my $itemcount = 1;
1.271 raeburn 5118: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 5119: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 5120: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
5121: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 5122: my @rows;
5123: my $key;
5124: if ($position eq 'top') {
5125: $key = 'admin';
5126: if (ref($rowsref) eq 'ARRAY') {
5127: @rows = @{$rowsref};
5128: }
5129: } elsif ($position eq 'middle') {
5130: $key = 'default';
5131: @rows = ('types','registered','approval','limit');
5132: }
5133: foreach my $row (@rows) {
5134: if (defined($titlesref->{$row})) {
5135: $itemcount ++;
5136: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5137: $datatable .= '<tr'.$css_class.'>'.
5138: '<td>'.$titlesref->{$row}.'</td>'.
5139: '<td class="LC_left_item">'.
5140: '<table><tr>';
5141: my (%current,%currentcap);
5142: if (ref($settings) eq 'HASH') {
5143: if (ref($settings->{$key}) eq 'HASH') {
5144: foreach my $type (@types) {
5145: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5146: $current{$type} = $settings->{$key}->{$type}->{$row};
5147: }
5148: if (($row eq 'limit') && ($key eq 'default')) {
5149: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5150: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
5151: }
5152: }
5153: }
5154: }
5155: }
5156: my %roles = (
5157: '0' => &Apache::lonnet::plaintext('dc'),
5158: );
5159:
5160: foreach my $type (@types) {
5161: unless (($row eq 'registered') && ($key eq 'default')) {
5162: $datatable .= '<th>'.&mt($type).'</th>';
5163: }
5164: }
5165: unless (($row eq 'registered') && ($key eq 'default')) {
5166: $datatable .= '</tr><tr>';
5167: }
5168: foreach my $type (@types) {
5169: if ($type eq 'community') {
5170: $roles{'1'} = &mt('Community personnel');
5171: } else {
5172: $roles{'1'} = &mt('Course personnel');
5173: }
5174: $datatable .= '<td style="vertical-align: top">';
5175: if ($position eq 'top') {
5176: my %checked;
5177: if ($current{$type} eq '0') {
5178: $checked{'0'} = ' checked="checked"';
5179: } else {
5180: $checked{'1'} = ' checked="checked"';
5181: }
5182: foreach my $role ('1','0') {
5183: $datatable .= '<span class="LC_nobreak"><label>'.
5184: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
5185: 'value="'.$role.'"'.$checked{$role}.' />'.
5186: $roles{$role}.'</label></span> ';
5187: }
5188: } else {
5189: if ($row eq 'types') {
5190: my %checked;
5191: if ($current{$type} =~ /^(all|dom)$/) {
5192: $checked{$1} = ' checked="checked"';
5193: } else {
5194: $checked{''} = ' checked="checked"';
5195: }
5196: foreach my $val ('','dom','all') {
5197: $datatable .= '<span class="LC_nobreak"><label>'.
5198: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5199: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5200: }
5201: } elsif ($row eq 'registered') {
5202: my %checked;
5203: if ($current{$type} eq '1') {
5204: $checked{'1'} = ' checked="checked"';
5205: } else {
5206: $checked{'0'} = ' checked="checked"';
5207: }
5208: foreach my $val ('0','1') {
5209: $datatable .= '<span class="LC_nobreak"><label>'.
5210: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5211: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5212: }
5213: } elsif ($row eq 'approval') {
5214: my %checked;
5215: if ($current{$type} =~ /^([12])$/) {
5216: $checked{$1} = ' checked="checked"';
5217: } else {
5218: $checked{'0'} = ' checked="checked"';
5219: }
5220: for my $val (0..2) {
5221: $datatable .= '<span class="LC_nobreak"><label>'.
5222: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5223: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5224: }
5225: } elsif ($row eq 'limit') {
5226: my %checked;
5227: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
5228: $checked{$1} = ' checked="checked"';
5229: } else {
5230: $checked{'none'} = ' checked="checked"';
5231: }
5232: my $cap;
5233: if ($currentcap{$type} =~ /^\d+$/) {
5234: $cap = $currentcap{$type};
5235: }
5236: foreach my $val ('none','allstudents','selfenrolled') {
5237: $datatable .= '<span class="LC_nobreak"><label>'.
5238: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5239: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5240: }
5241: $datatable .= '<br />'.
5242: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
5243: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
5244: '</span>';
5245: }
5246: }
5247: $datatable .= '</td>';
5248: }
5249: $datatable .= '</tr>';
5250: }
5251: $datatable .= '</table></td></tr>';
5252: }
5253: } elsif ($position eq 'bottom') {
1.235 raeburn 5254: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
5255: }
5256: $$rowtotal += $itemcount;
5257: return $datatable;
5258: }
5259:
5260: sub print_validation_rows {
5261: my ($caller,$dom,$settings,$rowtotal) = @_;
5262: my ($itemsref,$namesref,$fieldsref);
5263: if ($caller eq 'selfenroll') {
5264: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
5265: } elsif ($caller eq 'requestcourses') {
5266: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
5267: }
5268: my %currvalidation;
5269: if (ref($settings) eq 'HASH') {
5270: if (ref($settings->{'validation'}) eq 'HASH') {
5271: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 5272: }
1.235 raeburn 5273: }
5274: my $datatable;
5275: my $itemcount = 0;
5276: foreach my $item (@{$itemsref}) {
5277: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5278: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5279: $namesref->{$item}.
5280: '</span></td>'.
5281: '<td class="LC_left_item">';
5282: if (($item eq 'url') || ($item eq 'button')) {
5283: $datatable .= '<span class="LC_nobreak">'.
5284: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
5285: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
5286: } elsif ($item eq 'fields') {
5287: my @currfields;
5288: if (ref($currvalidation{$item}) eq 'ARRAY') {
5289: @currfields = @{$currvalidation{$item}};
5290: }
5291: foreach my $field (@{$fieldsref}) {
5292: my $check = '';
5293: if (grep(/^\Q$field\E$/,@currfields)) {
5294: $check = ' checked="checked"';
5295: }
5296: $datatable .= '<span class="LC_nobreak"><label>'.
5297: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
5298: ' value="'.$field.'"'.$check.' />'.$field.
5299: '</label></span> ';
5300: }
5301: } elsif ($item eq 'markup') {
5302: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
5303: $currvalidation{$item}.
1.231 raeburn 5304: '</textarea>';
1.235 raeburn 5305: }
5306: $datatable .= '</td></tr>'."\n";
5307: if (ref($rowtotal)) {
1.231 raeburn 5308: $itemcount ++;
5309: }
5310: }
1.235 raeburn 5311: if ($caller eq 'requestcourses') {
5312: my %currhash;
1.248 raeburn 5313: if (ref($settings) eq 'HASH') {
5314: if (ref($settings->{'validation'}) eq 'HASH') {
5315: if ($settings->{'validation'}{'dc'} ne '') {
5316: $currhash{$settings->{'validation'}{'dc'}} = 1;
5317: }
1.235 raeburn 5318: }
5319: }
5320: my $numinrow = 2;
5321: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
5322: 'validationdc',%currhash);
1.247 raeburn 5323: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5324: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.235 raeburn 5325: if ($numdc > 1) {
1.247 raeburn 5326: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 5327: } else {
1.247 raeburn 5328: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 5329: }
1.247 raeburn 5330: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 5331: $itemcount ++;
5332: }
5333: if (ref($rowtotal)) {
5334: $$rowtotal += $itemcount;
5335: }
1.231 raeburn 5336: return $datatable;
5337: }
5338:
1.137 raeburn 5339: sub print_usersessions {
5340: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 5341: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 5342: my (%by_ip,%by_location,@intdoms,@instdoms);
5343: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 5344:
5345: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 5346: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 5347: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 5348: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 5349: if ($position eq 'top') {
1.152 raeburn 5350: if (keys(%serverhomes) > 1) {
1.145 raeburn 5351: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.261 raeburn 5352: my $curroffloadnow;
5353: if (ref($settings) eq 'HASH') {
5354: if (ref($settings->{'offloadnow'}) eq 'HASH') {
5355: $curroffloadnow = $settings->{'offloadnow'};
5356: }
5357: }
5358: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 5359: } else {
1.140 raeburn 5360: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 5361: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
5362: '</td></tr>';
1.140 raeburn 5363: }
1.137 raeburn 5364: } else {
1.279 raeburn 5365: my %titles = &usersession_titles();
5366: my ($prefix,@types);
5367: if ($position eq 'bottom') {
5368: $prefix = 'remote';
5369: @types = ('version','excludedomain','includedomain');
1.145 raeburn 5370: } else {
1.279 raeburn 5371: $prefix = 'hosted';
5372: @types = ('excludedomain','includedomain');
5373: }
5374: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
5375: }
5376: $$rowtotal += $itemcount;
5377: return $datatable;
5378: }
5379:
5380: sub rules_by_location {
5381: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
5382: my ($datatable,$itemcount,$css_class);
5383: if (keys(%{$by_location}) == 0) {
5384: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5385: $datatable = '<tr'.$css_class.'><td colspan="2">'.
5386: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
5387: '</td></tr>';
5388: $itemcount = 1;
5389: } else {
5390: $itemcount = 0;
5391: my $numinrow = 5;
5392: my (%current,%checkedon,%checkedoff);
5393: my @locations = sort(keys(%{$by_location}));
5394: foreach my $type (@{$types}) {
5395: $checkedon{$type} = '';
5396: $checkedoff{$type} = ' checked="checked"';
5397: }
5398: if (ref($settings) eq 'HASH') {
5399: if (ref($settings->{$prefix}) eq 'HASH') {
5400: foreach my $key (keys(%{$settings->{$prefix}})) {
5401: $current{$key} = $settings->{$prefix}{$key};
5402: if ($key eq 'version') {
5403: if ($current{$key} ne '') {
1.145 raeburn 5404: $checkedon{$key} = ' checked="checked"';
5405: $checkedoff{$key} = '';
5406: }
1.279 raeburn 5407: } elsif (ref($current{$key}) eq 'ARRAY') {
5408: $checkedon{$key} = ' checked="checked"';
5409: $checkedoff{$key} = '';
1.137 raeburn 5410: }
5411: }
5412: }
1.279 raeburn 5413: }
5414: foreach my $type (@{$types}) {
5415: next if ($type ne 'version' && !@locations);
5416: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5417: $datatable .= '<tr'.$css_class.'>
5418: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
5419: <span class="LC_nobreak">
5420: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
5421: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
5422: if ($type eq 'version') {
5423: my @lcversions = &Apache::lonnet::all_loncaparevs();
5424: my $selector = '<select name="'.$prefix.'_version">';
5425: foreach my $version (@lcversions) {
5426: my $selected = '';
5427: if ($current{'version'} eq $version) {
5428: $selected = ' selected="selected"';
1.145 raeburn 5429: }
1.279 raeburn 5430: $selector .= ' <option value="'.$version.'"'.
5431: $selected.'>'.$version.'</option>';
5432: }
5433: $selector .= '</select> ';
5434: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
5435: } else {
5436: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
5437: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
5438: ' />'.(' 'x2).
5439: '<input type="button" value="'.&mt('uncheck all').'" '.
5440: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
5441: "\n".
5442: '</div><div><table>';
5443: my $rem;
5444: for (my $i=0; $i<@locations; $i++) {
5445: my ($showloc,$value,$checkedtype);
5446: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
5447: my $ip = $by_location->{$locations[$i]}->[0];
5448: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5449: $value = join(':',@{$by_ip->{$ip}});
5450: $showloc = join(', ',@{$by_ip->{$ip}});
5451: if (ref($current{$type}) eq 'ARRAY') {
5452: foreach my $loc (@{$by_ip->{$ip}}) {
5453: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
5454: $checkedtype = ' checked="checked"';
5455: last;
1.145 raeburn 5456: }
1.138 raeburn 5457: }
5458: }
5459: }
1.137 raeburn 5460: }
1.279 raeburn 5461: $rem = $i%($numinrow);
5462: if ($rem == 0) {
5463: if ($i > 0) {
5464: $datatable .= '</tr>';
5465: }
5466: $datatable .= '<tr>';
5467: }
5468: $datatable .= '<td class="LC_left_item">'.
5469: '<span class="LC_nobreak"><label>'.
5470: '<input type="checkbox" name="'.$prefix.'_'.$type.
5471: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
5472: '</label></span></td>';
5473: }
5474: $rem = @locations%($numinrow);
5475: my $colsleft = $numinrow - $rem;
5476: if ($colsleft > 1 ) {
5477: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5478: ' </td>';
5479: } elsif ($colsleft == 1) {
5480: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 5481: }
1.279 raeburn 5482: $datatable .= '</tr></table>';
1.137 raeburn 5483: }
1.279 raeburn 5484: $datatable .= '</td></tr>';
5485: $itemcount ++;
1.137 raeburn 5486: }
5487: }
1.279 raeburn 5488: return ($datatable,$itemcount);
1.137 raeburn 5489: }
5490:
1.275 raeburn 5491: sub print_ssl {
5492: my ($position,$dom,$settings,$rowtotal) = @_;
5493: my ($css_class,$datatable);
5494: my $itemcount = 1;
5495: if ($position eq 'top') {
1.281 raeburn 5496: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5497: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5498: my $same_institution;
5499: if ($intdom ne '') {
5500: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
5501: if (ref($internet_names) eq 'ARRAY') {
5502: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
5503: $same_institution = 1;
5504: }
5505: }
5506: }
1.275 raeburn 5507: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 5508: $datatable = '<tr'.$css_class.'><td colspan="2">';
5509: if ($same_institution) {
5510: my %domservers = &Apache::lonnet::get_servers($dom);
5511: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
5512: } else {
5513: $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.");
5514: }
5515: $datatable .= '</td></tr>';
1.275 raeburn 5516: $itemcount ++;
5517: } else {
5518: my %titles = &ssl_titles();
5519: my (%by_ip,%by_location,@intdoms,@instdoms);
5520: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
5521: my @alldoms = &Apache::lonnet::all_domains();
5522: my %serverhomes = %Apache::lonnet::serverhomeIDs;
5523: my @domservers = &Apache::lonnet::get_servers($dom);
5524: my %servers = &Apache::lonnet::internet_dom_servers($dom);
5525: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 5526: if (($position eq 'connto') || ($position eq 'connfrom')) {
5527: my $legacy;
5528: unless (ref($settings) eq 'HASH') {
5529: my $name;
5530: if ($position eq 'connto') {
5531: $name = 'loncAllowInsecure';
5532: } else {
5533: $name = 'londAllowInsecure';
5534: }
5535: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
5536: my @ids=&Apache::lonnet::current_machine_ids();
5537: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
5538: my %what = (
5539: $name => 1,
5540: );
5541: my ($result,$returnhash) =
5542: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
5543: if ($result eq 'ok') {
5544: if (ref($returnhash) eq 'HASH') {
5545: $legacy = $returnhash->{$name};
5546: }
5547: }
5548: } else {
5549: $legacy = $Apache::lonnet::perlvar{$name};
5550: }
5551: }
1.275 raeburn 5552: foreach my $type ('dom','intdom','other') {
5553: my %checked;
5554: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5555: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
5556: '<td class="LC_right_item">';
5557: my $skip;
5558: if ($type eq 'dom') {
5559: unless (keys(%servers) > 1) {
5560: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
5561: $skip = 1;
5562: }
5563: }
5564: if ($type eq 'intdom') {
5565: unless (@instdoms > 1) {
5566: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
5567: $skip = 1;
5568: }
5569: } elsif ($type eq 'other') {
5570: if (keys(%by_location) == 0) {
5571: $datatable .= &mt('Nothing to set here, as there are no other institutions');
5572: $skip = 1;
5573: }
5574: }
5575: unless ($skip) {
5576: $checked{'yes'} = ' checked="checked"';
5577: if (ref($settings) eq 'HASH') {
1.293 raeburn 5578: if (ref($settings->{$position}) eq 'HASH') {
5579: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 5580: $checked{$1} = $checked{'yes'};
5581: delete($checked{'yes'});
5582: }
5583: }
1.293 raeburn 5584: } else {
5585: if ($legacy == 0) {
5586: $checked{'req'} = $checked{'yes'};
5587: delete($checked{'yes'});
5588: }
1.275 raeburn 5589: }
5590: foreach my $option ('no','yes','req') {
5591: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 5592: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 5593: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
5594: '</label></span>'.(' 'x2);
5595: }
5596: }
5597: $datatable .= '</td></tr>';
5598: $itemcount ++;
5599: }
5600: } else {
5601: my $prefix = 'replication';
5602: my @types = ('certreq','nocertreq');
1.279 raeburn 5603: if (keys(%by_location) == 0) {
5604: $datatable .= '<tr'.$css_class.'><td>'.
5605: &mt('Nothing to set here, as there are no other institutions').
5606: '</td></tr>';
5607: $itemcount ++;
1.275 raeburn 5608: } else {
1.279 raeburn 5609: ($datatable,$itemcount) =
5610: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 5611: }
5612: }
5613: }
5614: $$rowtotal += $itemcount;
5615: return $datatable;
5616: }
5617:
5618: sub ssl_titles {
5619: return &Apache::lonlocal::texthash (
5620: dom => 'LON-CAPA servers/VMs from same domain',
5621: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
5622: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 5623: connto => 'Connections to other servers',
5624: connfrom => 'Connections from other servers',
1.275 raeburn 5625: replication => 'Replicating content to other institutions',
5626: certreq => 'Client certificate required, but specific domains exempt',
5627: nocertreq => 'No client certificate required, except for specific domains',
5628: no => 'SSL not used',
5629: yes => 'SSL Optional (used if available)',
5630: req => 'SSL Required',
5631: );
1.279 raeburn 5632: }
5633:
5634: sub print_trust {
5635: my ($prefix,$dom,$settings,$rowtotal) = @_;
5636: my ($css_class,$datatable,%checked,%choices);
5637: my (%by_ip,%by_location,@intdoms,@instdoms);
5638: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
5639: my $itemcount = 1;
5640: my %titles = &trust_titles();
5641: my @types = ('exc','inc');
5642: if ($prefix eq 'top') {
5643: $prefix = 'content';
5644: } elsif ($prefix eq 'bottom') {
5645: $prefix = 'msg';
5646: }
5647: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
5648: $$rowtotal += $itemcount;
5649: return $datatable;
5650: }
5651:
5652: sub trust_titles {
5653: return &Apache::lonlocal::texthash(
5654: content => "Access to this domain's content by others",
5655: shared => "Access to other domain's content by this domain",
5656: enroll => "Enrollment in this domain's courses by others",
5657: othcoau => "Co-author roles in this domain for others",
5658: coaurem => "Co-author roles for this domain's users elsewhere",
5659: domroles => "Domain roles in this domain assignable to others",
5660: catalog => "Course Catalog for this domain displayed elsewhere",
5661: reqcrs => "Requests for creation of courses in this domain by others",
5662: msg => "Users in other domains can send messages to this domain",
5663: exc => "Allow all, but exclude specific domains",
5664: inc => "Deny all, but include specific domains",
5665: );
1.275 raeburn 5666: }
5667:
1.138 raeburn 5668: sub build_location_hashes {
1.275 raeburn 5669: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 5670: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 5671: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 5672: my %iphost = &Apache::lonnet::get_iphost();
5673: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
5674: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
5675: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
5676: foreach my $id (@{$iphost{$primary_ip}}) {
5677: my $intdom = &Apache::lonnet::internet_dom($id);
5678: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
5679: push(@{$intdoms},$intdom);
5680: }
5681: }
5682: }
5683: foreach my $ip (keys(%iphost)) {
5684: if (ref($iphost{$ip}) eq 'ARRAY') {
5685: foreach my $id (@{$iphost{$ip}}) {
5686: my $location = &Apache::lonnet::internet_dom($id);
5687: if ($location) {
1.275 raeburn 5688: if (grep(/^\Q$location\E$/,@{$intdoms})) {
5689: my $dom = &Apache::lonnet::host_domain($id);
5690: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
5691: push(@{$instdoms},$dom);
5692: }
5693: next;
5694: }
1.138 raeburn 5695: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5696: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
5697: push(@{$by_ip->{$ip}},$location);
5698: }
5699: } else {
5700: $by_ip->{$ip} = [$location];
5701: }
5702: }
5703: }
5704: }
5705: }
5706: foreach my $ip (sort(keys(%{$by_ip}))) {
5707: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5708: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
5709: my $first = $by_ip->{$ip}->[0];
5710: if (ref($by_location->{$first}) eq 'ARRAY') {
5711: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
5712: push(@{$by_location->{$first}},$ip);
5713: }
5714: } else {
5715: $by_location->{$first} = [$ip];
5716: }
5717: }
5718: }
5719: return;
5720: }
5721:
1.145 raeburn 5722: sub current_offloads_to {
5723: my ($dom,$settings,$servers) = @_;
5724: my (%spareid,%otherdomconfigs);
1.152 raeburn 5725: if (ref($servers) eq 'HASH') {
1.145 raeburn 5726: foreach my $lonhost (sort(keys(%{$servers}))) {
5727: my $gotspares;
1.152 raeburn 5728: if (ref($settings) eq 'HASH') {
5729: if (ref($settings->{'spares'}) eq 'HASH') {
5730: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
5731: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
5732: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
5733: $gotspares = 1;
5734: }
1.145 raeburn 5735: }
5736: }
5737: unless ($gotspares) {
5738: my $gotspares;
5739: my $serverhomeID =
5740: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
5741: my $serverhomedom =
5742: &Apache::lonnet::host_domain($serverhomeID);
5743: if ($serverhomedom ne $dom) {
5744: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
5745: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5746: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5747: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5748: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5749: $gotspares = 1;
5750: }
5751: }
5752: } else {
5753: $otherdomconfigs{$serverhomedom} =
5754: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
5755: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
5756: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5757: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5758: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
5759: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5760: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5761: $gotspares = 1;
5762: }
5763: }
5764: }
5765: }
5766: }
5767: }
5768: }
5769: unless ($gotspares) {
5770: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
5771: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
5772: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
5773: } else {
5774: my $server_hostname = &Apache::lonnet::hostname($lonhost);
5775: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
5776: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
5777: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
5778: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
5779: } else {
1.150 raeburn 5780: my %what = (
5781: spareid => 1,
5782: );
5783: my ($result,$returnhash) =
5784: &Apache::lonnet::get_remote_globals($lonhost,\%what);
5785: if ($result eq 'ok') {
5786: if (ref($returnhash) eq 'HASH') {
5787: if (ref($returnhash->{'spareid'}) eq 'HASH') {
5788: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
5789: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
5790: }
5791: }
1.145 raeburn 5792: }
5793: }
5794: }
5795: }
5796: }
5797: }
5798: return %spareid;
5799: }
5800:
5801: sub spares_row {
1.261 raeburn 5802: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 5803: my $css_class;
5804: my $numinrow = 4;
5805: my $itemcount = 1;
5806: my $datatable;
1.152 raeburn 5807: my %typetitles = &sparestype_titles();
5808: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 5809: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 5810: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
5811: my ($othercontrol,$serverdom);
5812: if ($serverhome ne $server) {
5813: $serverdom = &Apache::lonnet::host_domain($serverhome);
5814: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5815: } else {
5816: $serverdom = &Apache::lonnet::host_domain($server);
5817: if ($serverdom ne $dom) {
5818: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5819: }
5820: }
5821: next unless (ref($spareid->{$server}) eq 'HASH');
1.261 raeburn 5822: my $checkednow;
5823: if (ref($curroffloadnow) eq 'HASH') {
5824: if ($curroffloadnow->{$server}) {
5825: $checkednow = ' checked="checked"';
5826: }
5827: }
1.145 raeburn 5828: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5829: $datatable .= '<tr'.$css_class.'>
5830: <td rowspan="2">
1.183 bisitz 5831: <span class="LC_nobreak">'.
5832: &mt('[_1] when busy, offloads to:'
1.261 raeburn 5833: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 5834: '<span class="LC_nobreak">'."\n".
1.261 raeburn 5835: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
5836: ' '.&mt('Switch active users on next access').'</label></span>'.
1.183 bisitz 5837: "\n";
1.145 raeburn 5838: my (%current,%canselect);
1.152 raeburn 5839: my @choices =
5840: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
5841: foreach my $type ('primary','default') {
5842: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 5843: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
5844: my @spares = @{$spareid->{$server}{$type}};
5845: if (@spares > 0) {
1.152 raeburn 5846: if ($othercontrol) {
5847: $current{$type} = join(', ',@spares);
5848: } else {
5849: $current{$type} .= '<table>';
5850: my $numspares = scalar(@spares);
5851: for (my $i=0; $i<@spares; $i++) {
5852: my $rem = $i%($numinrow);
5853: if ($rem == 0) {
5854: if ($i > 0) {
5855: $current{$type} .= '</tr>';
5856: }
5857: $current{$type} .= '<tr>';
1.145 raeburn 5858: }
1.152 raeburn 5859: $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'".');" /> '.
5860: $spareid->{$server}{$type}[$i].
5861: '</label></td>'."\n";
5862: }
5863: my $rem = @spares%($numinrow);
5864: my $colsleft = $numinrow - $rem;
5865: if ($colsleft > 1 ) {
5866: $current{$type} .= '<td colspan="'.$colsleft.
5867: '" class="LC_left_item">'.
5868: ' </td>';
5869: } elsif ($colsleft == 1) {
5870: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 5871: }
1.152 raeburn 5872: $current{$type} .= '</tr></table>';
1.150 raeburn 5873: }
1.145 raeburn 5874: }
5875: }
5876: if ($current{$type} eq '') {
5877: $current{$type} = &mt('None specified');
5878: }
1.152 raeburn 5879: if ($othercontrol) {
5880: if ($type eq 'primary') {
5881: $canselect{$type} = $othercontrol;
5882: }
5883: } else {
5884: $canselect{$type} =
5885: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
5886: '<select name="newspare_'.$type.'_'.$server.'" '.
5887: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
5888: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
5889: if (@choices > 0) {
5890: foreach my $lonhost (@choices) {
5891: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
5892: }
5893: }
5894: $canselect{$type} .= '</select>'."\n";
5895: }
5896: } else {
5897: $current{$type} = &mt('Could not be determined');
5898: if ($type eq 'primary') {
5899: $canselect{$type} = $othercontrol;
5900: }
1.145 raeburn 5901: }
1.152 raeburn 5902: if ($type eq 'default') {
5903: $datatable .= '<tr'.$css_class.'>';
5904: }
5905: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
5906: '<td>'.$current{$type}.'</td>'."\n".
5907: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 5908: }
5909: $itemcount ++;
5910: }
5911: }
5912: $$rowtotal += $itemcount;
5913: return $datatable;
5914: }
5915:
1.152 raeburn 5916: sub possible_newspares {
5917: my ($server,$currspares,$serverhomes,$altids) = @_;
5918: my $serverhostname = &Apache::lonnet::hostname($server);
5919: my %excluded;
5920: if ($serverhostname ne '') {
5921: %excluded = (
5922: $serverhostname => 1,
5923: );
5924: }
5925: if (ref($currspares) eq 'HASH') {
5926: foreach my $type (keys(%{$currspares})) {
5927: if (ref($currspares->{$type}) eq 'ARRAY') {
5928: if (@{$currspares->{$type}} > 0) {
5929: foreach my $curr (@{$currspares->{$type}}) {
5930: my $hostname = &Apache::lonnet::hostname($curr);
5931: $excluded{$hostname} = 1;
5932: }
5933: }
5934: }
5935: }
5936: }
5937: my @choices;
5938: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
5939: if (keys(%{$serverhomes}) > 1) {
5940: foreach my $name (sort(keys(%{$serverhomes}))) {
5941: unless ($excluded{$name}) {
5942: if (exists($altids->{$serverhomes->{$name}})) {
5943: push(@choices,$altids->{$serverhomes->{$name}});
5944: } else {
5945: push(@choices,$serverhomes->{$name});
1.145 raeburn 5946: }
5947: }
5948: }
5949: }
5950: }
1.152 raeburn 5951: return sort(@choices);
1.145 raeburn 5952: }
5953:
1.150 raeburn 5954: sub print_loadbalancing {
5955: my ($dom,$settings,$rowtotal) = @_;
5956: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5957: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5958: my $numinrow = 1;
5959: my $datatable;
5960: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 5961: my (%currbalancer,%currtargets,%currrules,%existing);
5962: if (ref($settings) eq 'HASH') {
5963: %existing = %{$settings};
5964: }
5965: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
5966: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
5967: \%currtargets,\%currrules);
1.150 raeburn 5968: } else {
5969: return;
5970: }
5971: my ($othertitle,$usertypes,$types) =
5972: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 5973: my $rownum = 8;
1.150 raeburn 5974: if (ref($types) eq 'ARRAY') {
5975: $rownum += scalar(@{$types});
5976: }
1.171 raeburn 5977: my @css_class = ('LC_odd_row','LC_even_row');
5978: my $balnum = 0;
5979: my $islast;
5980: my (@toshow,$disabledtext);
5981: if (keys(%currbalancer) > 0) {
5982: @toshow = sort(keys(%currbalancer));
5983: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
5984: push(@toshow,'');
5985: }
5986: } else {
5987: @toshow = ('');
5988: $disabledtext = &mt('No existing load balancer');
5989: }
5990: foreach my $lonhost (@toshow) {
5991: if ($balnum == scalar(@toshow)-1) {
5992: $islast = 1;
5993: } else {
5994: $islast = 0;
5995: }
5996: my $cssidx = $balnum%2;
5997: my $targets_div_style = 'display: none';
5998: my $disabled_div_style = 'display: block';
5999: my $homedom_div_style = 'display: none';
6000: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 6001: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 6002: '<p>';
6003: if ($lonhost eq '') {
1.210 raeburn 6004: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 6005: if (keys(%currbalancer) > 0) {
6006: $datatable .= &mt('Add balancer:');
6007: } else {
6008: $datatable .= &mt('Enable balancer:');
6009: }
6010: $datatable .= ' '.
6011: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
6012: ' id="loadbalancing_lonhost_'.$balnum.'"'.
6013: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
6014: '<option value="" selected="selected">'.&mt('None').
6015: '</option>'."\n";
6016: foreach my $server (sort(keys(%servers))) {
6017: next if ($currbalancer{$server});
6018: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
6019: }
1.210 raeburn 6020: $datatable .=
1.171 raeburn 6021: '</select>'."\n".
6022: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
6023: } else {
6024: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
6025: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
6026: &mt('Stop balancing').'</label>'.
6027: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
6028: $targets_div_style = 'display: block';
6029: $disabled_div_style = 'display: none';
6030: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
6031: $homedom_div_style = 'display: block';
6032: }
6033: }
1.306 raeburn 6034: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 6035: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
6036: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
6037: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
6038: my ($numspares,@spares) = &count_servers($lonhost,%servers);
6039: my @sparestypes = ('primary','default');
6040: my %typetitles = &sparestype_titles();
1.284 raeburn 6041: my %hostherechecked = (
6042: no => ' checked="checked"',
6043: );
1.171 raeburn 6044: foreach my $sparetype (@sparestypes) {
6045: my $targettable;
6046: for (my $i=0; $i<$numspares; $i++) {
6047: my $checked;
6048: if (ref($currtargets{$lonhost}) eq 'HASH') {
6049: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6050: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6051: $checked = ' checked="checked"';
6052: }
6053: }
6054: }
6055: my ($chkboxval,$disabled);
6056: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
6057: $chkboxval = $spares[$i];
6058: }
6059: if (exists($currbalancer{$spares[$i]})) {
6060: $disabled = ' disabled="disabled"';
6061: }
1.210 raeburn 6062: $targettable .=
1.253 raeburn 6063: '<td><span class="LC_nobreak"><label>'.
6064: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 6065: $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 6066: '</span></label></span></td>';
1.171 raeburn 6067: my $rem = $i%($numinrow);
6068: if ($rem == 0) {
6069: if (($i > 0) && ($i < $numspares-1)) {
6070: $targettable .= '</tr>';
6071: }
6072: if ($i < $numspares-1) {
6073: $targettable .= '<tr>';
1.150 raeburn 6074: }
6075: }
6076: }
1.171 raeburn 6077: if ($targettable ne '') {
6078: my $rem = $numspares%($numinrow);
6079: my $colsleft = $numinrow - $rem;
6080: if ($colsleft > 1 ) {
6081: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6082: ' </td>';
6083: } elsif ($colsleft == 1) {
6084: $targettable .= '<td class="LC_left_item"> </td>';
6085: }
6086: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
6087: '<table><tr>'.$targettable.'</tr></table><br />';
6088: }
1.284 raeburn 6089: $hostherechecked{$sparetype} = '';
6090: if (ref($currtargets{$lonhost}) eq 'HASH') {
6091: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6092: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6093: $hostherechecked{$sparetype} = ' checked="checked"';
6094: $hostherechecked{'no'} = '';
6095: }
6096: }
6097: }
6098: }
6099: $datatable .= &mt('Hosting on balancer itself').'<br />'.
6100: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
6101: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
6102: foreach my $sparetype (@sparestypes) {
6103: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
6104: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
6105: '</i></label><br />';
1.171 raeburn 6106: }
6107: $datatable .= '</div></td></tr>'.
6108: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
6109: $othertitle,$usertypes,$types,\%servers,
6110: \%currbalancer,$lonhost,
6111: $targets_div_style,$homedom_div_style,
6112: $css_class[$cssidx],$balnum,$islast);
6113: $$rowtotal += $rownum;
6114: $balnum ++;
6115: }
6116: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
6117: return $datatable;
6118: }
6119:
6120: sub get_loadbalancers_config {
6121: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
6122: return unless ((ref($servers) eq 'HASH') &&
6123: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
6124: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
6125: if (keys(%{$existing}) > 0) {
6126: my $oldlonhost;
6127: foreach my $key (sort(keys(%{$existing}))) {
6128: if ($key eq 'lonhost') {
6129: $oldlonhost = $existing->{'lonhost'};
6130: $currbalancer->{$oldlonhost} = 1;
6131: } elsif ($key eq 'targets') {
6132: if ($oldlonhost) {
6133: $currtargets->{$oldlonhost} = $existing->{'targets'};
6134: }
6135: } elsif ($key eq 'rules') {
6136: if ($oldlonhost) {
6137: $currrules->{$oldlonhost} = $existing->{'rules'};
6138: }
6139: } elsif (ref($existing->{$key}) eq 'HASH') {
6140: $currbalancer->{$key} = 1;
6141: $currtargets->{$key} = $existing->{$key}{'targets'};
6142: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 6143: }
6144: }
1.171 raeburn 6145: } else {
6146: my ($balancerref,$targetsref) =
6147: &Apache::lonnet::get_lonbalancer_config($servers);
6148: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
6149: foreach my $server (sort(keys(%{$balancerref}))) {
6150: $currbalancer->{$server} = 1;
6151: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 6152: }
6153: }
6154: }
1.171 raeburn 6155: return;
1.150 raeburn 6156: }
6157:
6158: sub loadbalancing_rules {
6159: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 6160: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
6161: $css_class,$balnum,$islast) = @_;
1.150 raeburn 6162: my $output;
1.171 raeburn 6163: my $num = 0;
1.210 raeburn 6164: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 6165: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
6166: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
6167: foreach my $type (@{$alltypes}) {
1.171 raeburn 6168: $num ++;
1.150 raeburn 6169: my $current;
6170: if (ref($currrules) eq 'HASH') {
6171: $current = $currrules->{$type};
6172: }
1.253 raeburn 6173: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 6174: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 6175: $current = '';
6176: }
6177: }
6178: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 6179: $servers,$currbalancer,$lonhost,$dom,
6180: $targets_div_style,$homedom_div_style,
6181: $css_class,$balnum,$num,$islast);
1.150 raeburn 6182: }
6183: }
6184: return $output;
6185: }
6186:
6187: sub loadbalancing_titles {
6188: my ($dom,$intdom,$usertypes,$types) = @_;
6189: my %othertypes = (
6190: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
6191: '_LC_author' => &mt('Users from [_1] with author role',$dom),
6192: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
6193: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 6194: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
6195: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 6196: );
1.209 raeburn 6197: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 6198: my @available;
1.150 raeburn 6199: if (ref($types) eq 'ARRAY') {
1.302 raeburn 6200: @available = @{$types};
1.150 raeburn 6201: }
1.302 raeburn 6202: unless (grep(/^default$/,@available)) {
6203: push(@available,'default');
6204: }
6205: unshift(@alltypes,@available);
1.150 raeburn 6206: my %titles;
6207: foreach my $type (@alltypes) {
6208: if ($type =~ /^_LC_/) {
6209: $titles{$type} = $othertypes{$type};
6210: } elsif ($type eq 'default') {
6211: $titles{$type} = &mt('All users from [_1]',$dom);
6212: if (ref($types) eq 'ARRAY') {
6213: if (@{$types} > 0) {
6214: $titles{$type} = &mt('Other users from [_1]',$dom);
6215: }
6216: }
6217: } elsif (ref($usertypes) eq 'HASH') {
6218: $titles{$type} = $usertypes->{$type};
6219: }
6220: }
6221: return (\@alltypes,\%othertypes,\%titles);
6222: }
6223:
6224: sub loadbalance_rule_row {
1.171 raeburn 6225: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
6226: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 6227: my @rulenames;
1.150 raeburn 6228: my %ruletitles = &offloadtype_text();
1.209 raeburn 6229: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 6230: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 6231: } else {
1.209 raeburn 6232: @rulenames = ('default','homeserver');
6233: if ($type eq '_LC_external') {
6234: push(@rulenames,'externalbalancer');
6235: } else {
6236: push(@rulenames,'specific');
6237: }
6238: push(@rulenames,'none');
1.150 raeburn 6239: }
6240: my $style = $targets_div_style;
1.253 raeburn 6241: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 6242: $style = $homedom_div_style;
6243: }
1.171 raeburn 6244: my $space;
6245: if ($islast && $num == 1) {
1.317 raeburn 6246: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 6247: }
1.210 raeburn 6248: my $output =
1.306 raeburn 6249: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 6250: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
6251: '<td valaign="top">'.$space.
6252: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 6253: for (my $i=0; $i<@rulenames; $i++) {
6254: my $rule = $rulenames[$i];
6255: my ($checked,$extra);
6256: if ($rulenames[$i] eq 'default') {
6257: $rule = '';
6258: }
6259: if ($rulenames[$i] eq 'specific') {
6260: if (ref($servers) eq 'HASH') {
6261: my $default;
6262: if (($current ne '') && (exists($servers->{$current}))) {
6263: $checked = ' checked="checked"';
6264: }
6265: unless ($checked) {
6266: $default = ' selected="selected"';
6267: }
1.210 raeburn 6268: $extra =
1.171 raeburn 6269: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
6270: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
6271: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
6272: '<option value=""'.$default.'></option>'."\n";
6273: foreach my $server (sort(keys(%{$servers}))) {
6274: if (ref($currbalancer) eq 'HASH') {
6275: next if (exists($currbalancer->{$server}));
6276: }
1.150 raeburn 6277: my $selected;
1.171 raeburn 6278: if ($server eq $current) {
1.150 raeburn 6279: $selected = ' selected="selected"';
6280: }
1.171 raeburn 6281: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 6282: }
6283: $extra .= '</select>';
6284: }
6285: } elsif ($rule eq $current) {
6286: $checked = ' checked="checked"';
6287: }
6288: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 6289: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
6290: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
6291: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 6292: ')"'.$checked.' /> ';
6293: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
6294: $output .= $ruletitles{'particular'};
6295: } else {
6296: $output .= $ruletitles{$rulenames[$i]};
6297: }
6298: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 6299: }
6300: $output .= '</div></td></tr>'."\n";
6301: return $output;
6302: }
6303:
6304: sub offloadtype_text {
6305: my %ruletitles = &Apache::lonlocal::texthash (
6306: 'default' => 'Offloads to default destinations',
6307: 'homeserver' => "Offloads to user's home server",
6308: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
6309: 'specific' => 'Offloads to specific server',
1.161 raeburn 6310: 'none' => 'No offload',
1.209 raeburn 6311: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
6312: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 6313: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 6314: );
6315: return %ruletitles;
6316: }
6317:
6318: sub sparestype_titles {
6319: my %typestitles = &Apache::lonlocal::texthash (
6320: 'primary' => 'primary',
6321: 'default' => 'default',
6322: );
6323: return %typestitles;
6324: }
6325:
1.28 raeburn 6326: sub contact_titles {
6327: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 6328: 'supportemail' => 'Support E-mail address',
6329: 'adminemail' => 'Default Server Admin E-mail address',
6330: 'errormail' => 'Error reports to be e-mailed to',
6331: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 6332: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
6333: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 6334: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
6335: 'requestsmail' => 'E-mail from course requests requiring approval',
6336: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 6337: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 6338: );
6339: my %short_titles = &Apache::lonlocal::texthash (
6340: adminemail => 'Admin E-mail address',
6341: supportemail => 'Support E-mail',
6342: );
6343: return (\%titles,\%short_titles);
6344: }
6345:
1.286 raeburn 6346: sub helpform_fields {
6347: my %titles = &Apache::lonlocal::texthash (
6348: 'username' => 'Name',
6349: 'user' => 'Username/domain',
6350: 'phone' => 'Phone',
6351: 'cc' => 'Cc e-mail',
6352: 'course' => 'Course Details',
6353: 'section' => 'Sections',
1.289 raeburn 6354: 'screenshot' => 'File upload',
1.286 raeburn 6355: );
6356: my @fields = ('username','phone','user','course','section','cc','screenshot');
6357: my %possoptions = (
6358: username => ['yes','no','req'],
1.289 raeburn 6359: phone => ['yes','no','req'],
1.286 raeburn 6360: user => ['yes','no'],
1.289 raeburn 6361: cc => ['yes','no'],
1.286 raeburn 6362: course => ['yes','no'],
6363: section => ['yes','no'],
6364: screenshot => ['yes','no'],
6365: );
6366: my %fieldoptions = &Apache::lonlocal::texthash (
6367: 'yes' => 'Optional',
6368: 'req' => 'Required',
6369: 'no' => "Not shown",
6370: );
6371: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
6372: }
6373:
1.72 raeburn 6374: sub tool_titles {
6375: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 6376: aboutme => 'Personal web page',
1.86 raeburn 6377: blog => 'Blog',
1.162 raeburn 6378: webdav => 'WebDAV',
1.86 raeburn 6379: portfolio => 'Portfolio',
1.88 bisitz 6380: official => 'Official courses (with institutional codes)',
6381: unofficial => 'Unofficial courses',
1.98 raeburn 6382: community => 'Communities',
1.216 raeburn 6383: textbook => 'Textbook courses',
1.271 raeburn 6384: placement => 'Placement tests',
1.86 raeburn 6385: );
1.72 raeburn 6386: return %titles;
6387: }
6388:
1.101 raeburn 6389: sub courserequest_titles {
6390: my %titles = &Apache::lonlocal::texthash (
6391: official => 'Official',
6392: unofficial => 'Unofficial',
6393: community => 'Communities',
1.216 raeburn 6394: textbook => 'Textbook',
1.271 raeburn 6395: placement => 'Placement tests',
1.101 raeburn 6396: norequest => 'Not allowed',
1.104 raeburn 6397: approval => 'Approval by Dom. Coord.',
1.101 raeburn 6398: validate => 'With validation',
6399: autolimit => 'Numerical limit',
1.103 raeburn 6400: unlimited => '(blank for unlimited)',
1.101 raeburn 6401: );
6402: return %titles;
6403: }
6404:
1.163 raeburn 6405: sub authorrequest_titles {
6406: my %titles = &Apache::lonlocal::texthash (
6407: norequest => 'Not allowed',
6408: approval => 'Approval by Dom. Coord.',
6409: automatic => 'Automatic approval',
6410: );
6411: return %titles;
1.210 raeburn 6412: }
1.163 raeburn 6413:
1.101 raeburn 6414: sub courserequest_conditions {
6415: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 6416: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 6417: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 6418: );
6419: return %conditions;
6420: }
6421:
6422:
1.27 raeburn 6423: sub print_usercreation {
1.30 raeburn 6424: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 6425: my $numinrow = 4;
1.28 raeburn 6426: my $datatable;
6427: if ($position eq 'top') {
1.30 raeburn 6428: $$rowtotal ++;
1.34 raeburn 6429: my $rowcount = 0;
1.32 raeburn 6430: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 6431: if (ref($rules) eq 'HASH') {
6432: if (keys(%{$rules}) > 0) {
1.32 raeburn 6433: $datatable .= &user_formats_row('username',$settings,$rules,
6434: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 6435: $$rowtotal ++;
1.32 raeburn 6436: $rowcount ++;
6437: }
6438: }
6439: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
6440: if (ref($idrules) eq 'HASH') {
6441: if (keys(%{$idrules}) > 0) {
6442: $datatable .= &user_formats_row('id',$settings,$idrules,
6443: $idruleorder,$numinrow,$rowcount);
6444: $$rowtotal ++;
6445: $rowcount ++;
1.28 raeburn 6446: }
6447: }
1.39 raeburn 6448: if ($rowcount == 0) {
6449: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
6450: $$rowtotal ++;
6451: $rowcount ++;
6452: }
1.34 raeburn 6453: } elsif ($position eq 'middle') {
1.224 raeburn 6454: my @creators = ('author','course','requestcrs');
1.37 raeburn 6455: my ($rules,$ruleorder) =
6456: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 6457: my %lt = &usercreation_types();
6458: my %checked;
6459: if (ref($settings) eq 'HASH') {
6460: if (ref($settings->{'cancreate'}) eq 'HASH') {
6461: foreach my $item (@creators) {
6462: $checked{$item} = $settings->{'cancreate'}{$item};
6463: }
6464: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
6465: foreach my $item (@creators) {
6466: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
6467: $checked{$item} = 'none';
6468: }
6469: }
6470: }
6471: }
6472: my $rownum = 0;
6473: foreach my $item (@creators) {
6474: $rownum ++;
1.224 raeburn 6475: if ($checked{$item} eq '') {
6476: $checked{$item} = 'any';
1.34 raeburn 6477: }
6478: my $css_class;
6479: if ($rownum%2) {
6480: $css_class = '';
6481: } else {
6482: $css_class = ' class="LC_odd_row" ';
6483: }
6484: $datatable .= '<tr'.$css_class.'>'.
6485: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 6486: '</span></td><td style="text-align: right">';
1.224 raeburn 6487: my @options = ('any');
6488: if (ref($rules) eq 'HASH') {
6489: if (keys(%{$rules}) > 0) {
6490: push(@options,('official','unofficial'));
1.37 raeburn 6491: }
6492: }
1.224 raeburn 6493: push(@options,'none');
1.37 raeburn 6494: foreach my $option (@options) {
1.50 raeburn 6495: my $type = 'radio';
1.34 raeburn 6496: my $check = ' ';
1.224 raeburn 6497: if ($checked{$item} eq $option) {
6498: $check = ' checked="checked" ';
1.34 raeburn 6499: }
6500: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 6501: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 6502: $item.'" value="'.$option.'"'.$check.'/> '.
6503: $lt{$option}.'</label> </span>';
6504: }
6505: $datatable .= '</td></tr>';
6506: }
1.28 raeburn 6507: } else {
6508: my @contexts = ('author','course','domain');
6509: my @authtypes = ('int','krb4','krb5','loc');
6510: my %checked;
6511: if (ref($settings) eq 'HASH') {
6512: if (ref($settings->{'authtypes'}) eq 'HASH') {
6513: foreach my $item (@contexts) {
6514: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
6515: foreach my $auth (@authtypes) {
6516: if ($settings->{'authtypes'}{$item}{$auth}) {
6517: $checked{$item}{$auth} = ' checked="checked" ';
6518: }
6519: }
6520: }
6521: }
1.27 raeburn 6522: }
1.35 raeburn 6523: } else {
6524: foreach my $item (@contexts) {
1.36 raeburn 6525: foreach my $auth (@authtypes) {
1.35 raeburn 6526: $checked{$item}{$auth} = ' checked="checked" ';
6527: }
6528: }
1.27 raeburn 6529: }
1.28 raeburn 6530: my %title = &context_names();
6531: my %authname = &authtype_names();
6532: my $rownum = 0;
6533: my $css_class;
6534: foreach my $item (@contexts) {
6535: if ($rownum%2) {
6536: $css_class = '';
6537: } else {
6538: $css_class = ' class="LC_odd_row" ';
6539: }
1.30 raeburn 6540: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 6541: '<td>'.$title{$item}.
6542: '</td><td class="LC_left_item">'.
6543: '<span class="LC_nobreak">';
6544: foreach my $auth (@authtypes) {
6545: $datatable .= '<label>'.
6546: '<input type="checkbox" name="'.$item.'_auth" '.
6547: $checked{$item}{$auth}.' value="'.$auth.'" />'.
6548: $authname{$auth}.'</label> ';
6549: }
6550: $datatable .= '</span></td></tr>';
6551: $rownum ++;
1.27 raeburn 6552: }
1.30 raeburn 6553: $$rowtotal += $rownum;
1.27 raeburn 6554: }
6555: return $datatable;
6556: }
6557:
1.224 raeburn 6558: sub print_selfcreation {
6559: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 6560: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
6561: $emaildomain,$datatable);
1.224 raeburn 6562: if (ref($settings) eq 'HASH') {
6563: if (ref($settings->{'cancreate'}) eq 'HASH') {
6564: $createsettings = $settings->{'cancreate'};
1.236 raeburn 6565: if (ref($createsettings) eq 'HASH') {
6566: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
6567: @selfcreate = @{$createsettings->{'selfcreate'}};
6568: } elsif ($createsettings->{'selfcreate'} ne '') {
6569: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
6570: @selfcreate = ('email','login','sso');
6571: } elsif ($createsettings->{'selfcreate'} ne 'none') {
6572: @selfcreate = ($createsettings->{'selfcreate'});
6573: }
6574: }
6575: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
6576: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 6577: }
1.305 raeburn 6578: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
6579: $emailoptions = $createsettings->{'emailoptions'};
6580: }
1.303 raeburn 6581: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
6582: $emailverified = $createsettings->{'emailverified'};
6583: }
6584: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
6585: $emaildomain = $createsettings->{'emaildomain'};
6586: }
1.224 raeburn 6587: }
6588: }
6589: }
6590: my %radiohash;
6591: my $numinrow = 4;
6592: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 6593: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 6594: if ($position eq 'top') {
6595: my %choices = &Apache::lonlocal::texthash (
6596: cancreate_login => 'Institutional Login',
6597: cancreate_sso => 'Institutional Single Sign On',
6598: );
6599: my @toggles = sort(keys(%choices));
6600: my %defaultchecked = (
6601: 'cancreate_login' => 'off',
6602: 'cancreate_sso' => 'off',
6603: );
1.228 raeburn 6604: my ($onclick,$itemcount);
1.224 raeburn 6605: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6606: \%choices,$itemcount,$onclick);
1.228 raeburn 6607: $$rowtotal += $itemcount;
6608:
1.224 raeburn 6609: if (ref($usertypes) eq 'HASH') {
6610: if (keys(%{$usertypes}) > 0) {
6611: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
6612: $dom,$numinrow,$othertitle,
1.305 raeburn 6613: 'statustocreate',$rowtotal);
1.224 raeburn 6614: $$rowtotal ++;
6615: }
6616: }
1.240 raeburn 6617: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
6618: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6619: $fieldtitles{'inststatus'} = &mt('Institutional status');
6620: my $rem;
6621: my $numperrow = 2;
6622: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
6623: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 6624: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 6625: '<td class="LC_left_item">'."\n".
6626: '<table><tr><td>'."\n";
6627: for (my $i=0; $i<@fields; $i++) {
6628: $rem = $i%($numperrow);
6629: if ($rem == 0) {
6630: if ($i > 0) {
6631: $datatable .= '</tr>';
6632: }
6633: $datatable .= '<tr>';
6634: }
6635: my $currval;
1.248 raeburn 6636: if (ref($createsettings) eq 'HASH') {
6637: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
6638: $currval = $createsettings->{'shibenv'}{$fields[$i]};
6639: }
1.240 raeburn 6640: }
6641: $datatable .= '<td class="LC_left_item">'.
6642: '<span class="LC_nobreak">'.
6643: '<input type="text" name="shibenv_'.$fields[$i].'" '.
6644: 'value="'.$currval.'" size="10" /> '.
6645: $fieldtitles{$fields[$i]}.'</span></td>';
6646: }
6647: my $colsleft = $numperrow - $rem;
6648: if ($colsleft > 1 ) {
6649: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6650: ' </td>';
6651: } elsif ($colsleft == 1) {
6652: $datatable .= '<td class="LC_left_item"> </td>';
6653: }
6654: $datatable .= '</tr></table></td></tr>';
6655: $$rowtotal ++;
1.224 raeburn 6656: } elsif ($position eq 'middle') {
6657: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 6658: my @posstypes;
1.224 raeburn 6659: if (ref($types) eq 'ARRAY') {
1.302 raeburn 6660: @posstypes = @{$types};
6661: }
6662: unless (grep(/^default$/,@posstypes)) {
6663: push(@posstypes,'default');
6664: }
6665: my %usertypeshash;
6666: if (ref($usertypes) eq 'HASH') {
6667: %usertypeshash = %{$usertypes};
6668: }
6669: $usertypeshash{'default'} = $othertitle;
6670: foreach my $status (@posstypes) {
6671: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
6672: $numinrow,$$rowtotal,\%usertypeshash);
6673: $$rowtotal ++;
1.224 raeburn 6674: }
6675: } else {
1.236 raeburn 6676: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 6677: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 6678: );
6679: my @toggles = sort(keys(%choices));
6680: my %defaultchecked = (
6681: 'cancreate_email' => 'off',
6682: );
1.305 raeburn 6683: my $customclass = 'LC_selfcreate_email';
6684: my $classprefix = 'LC_canmodify_emailusername_';
6685: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 6686: my $display = 'none';
1.305 raeburn 6687: my $rowstyle = 'display:none';
1.236 raeburn 6688: if (grep(/^\Qemail\E$/,@selfcreate)) {
6689: $display = 'block';
1.305 raeburn 6690: $rowstyle = 'display:table-row';
1.236 raeburn 6691: }
1.305 raeburn 6692: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
6693: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6694: \%choices,$$rowtotal,$onclick);
6695: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
6696: $rowstyle);
6697: $$rowtotal ++;
6698: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
6699: $rowstyle);
6700: $$rowtotal ++;
6701: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 6702: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 6703: my ($emailrules,$emailruleorder) =
6704: &Apache::lonnet::inst_userrules($dom,'email');
6705: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6706: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6707: if (ref($types) eq 'ARRAY') {
6708: @posstypes = @{$types};
6709: }
6710: if (@posstypes) {
6711: unless (grep(/^default$/,@posstypes)) {
6712: push(@posstypes,'default');
1.302 raeburn 6713: }
6714: if (ref($usertypes) eq 'HASH') {
6715: %usertypeshash = %{$usertypes};
6716: }
1.305 raeburn 6717: my $currassign;
6718: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
6719: $currassign = {
6720: selfassign => $domdefaults{'inststatusguest'},
6721: };
6722: @ordered = @{$domdefaults{'inststatusguest'}};
6723: } else {
6724: $currassign = { selfassign => [] };
6725: }
6726: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
6727: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
6728: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
6729: $numinrow,$othertitle,'selfassign',
6730: $rowtotal,$onclicktypes,$customclass,
6731: $rowstyle);
6732: $$rowtotal ++;
1.302 raeburn 6733: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 6734: foreach my $status (@posstypes) {
6735: my $css_class;
6736: if ($$rowtotal%2) {
6737: $css_class = 'LC_odd_row ';
6738: }
6739: $css_class .= $customclass;
6740: my $rowid = $optionsprefix.$status;
6741: my $hidden = 1;
6742: my $currstyle = 'display:none';
6743: if (grep(/^\Q$status\E$/,@ordered)) {
6744: $currstyle = $rowstyle;
6745: $hidden = 0;
6746: }
6747: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
6748: $emailrules,$emailruleorder,$settings,$status,$rowid,
6749: $usertypeshash{$status},$css_class,$currstyle,$intdom);
6750: unless ($hidden) {
6751: $$rowtotal ++;
6752: }
1.224 raeburn 6753: }
1.302 raeburn 6754: } else {
1.305 raeburn 6755: my $css_class;
6756: if ($$rowtotal%2) {
6757: $css_class = 'LC_odd_row ';
6758: }
6759: $css_class .= $customclass;
1.302 raeburn 6760: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 6761: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
6762: $emailrules,$emailruleorder,$settings,'default','',
6763: $othertitle,$css_class,$rowstyle,$intdom);
6764: $$rowtotal ++;
1.224 raeburn 6765: }
6766: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 6767: $numinrow = 1;
1.305 raeburn 6768: if (@posstypes) {
6769: foreach my $status (@posstypes) {
6770: my $rowid = $classprefix.$status;
6771: my $datarowstyle = 'display:none';
6772: if (grep(/^\Q$status\E$/,@ordered)) {
6773: $datarowstyle = $rowstyle;
6774: }
6775: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
6776: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
6777: $infotitles,$rowid,$customclass,$datarowstyle);
6778: unless ($datarowstyle eq 'display:none') {
6779: $$rowtotal ++;
6780: }
1.224 raeburn 6781: }
1.305 raeburn 6782: } else {
6783: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
6784: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
6785: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 6786: }
6787: }
6788: return $datatable;
6789: }
6790:
1.305 raeburn 6791: sub selfcreate_javascript {
6792: return <<"ENDSCRIPT";
6793:
6794: <script type="text/javascript">
6795: // <![CDATA[
6796:
6797: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
6798: var x = document.getElementsByClassName(target);
6799: var insttypes = 0;
6800: var insttypeRegExp = new RegExp(prefix);
6801: if ((x.length != undefined) && (x.length > 0)) {
6802: if (form.elements[radio].length != undefined) {
6803: for (var i=0; i<form.elements[radio].length; i++) {
6804: if (form.elements[radio][i].checked) {
6805: if (form.elements[radio][i].value == 1) {
6806: for (var j=0; j<x.length; j++) {
6807: if (x[j].id == 'undefined') {
6808: x[j].style.display = 'table-row';
6809: } else if (insttypeRegExp.test(x[j].id)) {
6810: insttypes ++;
6811: } else {
6812: x[j].style.display = 'table-row';
6813: }
6814: }
6815: } else {
6816: for (var j=0; j<x.length; j++) {
6817: x[j].style.display = 'none';
6818: }
1.236 raeburn 6819: }
1.305 raeburn 6820: break;
6821: }
6822: }
6823: if (insttypes > 0) {
6824: toggleDataRow(form,checkbox,target,altprefix);
6825: toggleDataRow(form,checkbox,target,prefix,1);
6826: }
6827: }
6828: }
6829: return;
6830: }
6831:
6832: function toggleDataRow(form,checkbox,target,prefix,docount) {
6833: if (form.elements[checkbox].length != undefined) {
6834: var count = 0;
6835: if (docount) {
6836: for (var i=0; i<form.elements[checkbox].length; i++) {
6837: if (form.elements[checkbox][i].checked) {
6838: count ++;
1.236 raeburn 6839: }
1.305 raeburn 6840: }
6841: }
6842: for (var i=0; i<form.elements[checkbox].length; i++) {
6843: var type = form.elements[checkbox][i].value;
6844: if (document.getElementById(prefix+type)) {
6845: if (form.elements[checkbox][i].checked) {
6846: document.getElementById(prefix+type).style.display = 'table-row';
6847: if (count % 2 == 1) {
6848: document.getElementById(prefix+type).className = target+' LC_odd_row';
6849: } else {
6850: document.getElementById(prefix+type).className = target;
1.236 raeburn 6851: }
1.305 raeburn 6852: count ++;
1.236 raeburn 6853: } else {
1.305 raeburn 6854: document.getElementById(prefix+type).style.display = 'none';
6855: }
6856: }
6857: }
6858: }
6859: return;
6860: }
6861:
6862: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
6863: var caller = radio+'_'+status;
6864: if (form.elements[caller].length != undefined) {
6865: for (var i=0; i<form.elements[caller].length; i++) {
6866: if (form.elements[caller][i].checked) {
6867: if (document.getElementById(altprefix+'_inst_'+status)) {
6868: var curr = form.elements[caller][i].value;
6869: if (prefix) {
6870: document.getElementById(prefix+'_'+status).style.display = 'none';
6871: }
6872: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
6873: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
6874: if (curr == 'custom') {
6875: if (prefix) {
6876: document.getElementById(prefix+'_'+status).style.display = 'inline';
6877: }
6878: } else if (curr == 'inst') {
6879: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
6880: } else if (curr == 'noninst') {
6881: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 6882: }
1.305 raeburn 6883: break;
1.236 raeburn 6884: }
6885: }
6886: }
6887: }
6888: }
6889:
1.305 raeburn 6890: // ]]>
6891: </script>
6892:
6893: ENDSCRIPT
6894: }
6895:
6896: sub noninst_users {
6897: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
6898: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
6899: my $class = 'LC_left_item';
6900: if ($css_class) {
6901: $css_class = ' class="'.$css_class.'"';
6902: }
6903: if ($rowid) {
6904: $rowid = ' id="'.$rowid.'"';
6905: }
6906: if ($rowstyle) {
6907: $rowstyle = ' style="'.$rowstyle.'"';
6908: }
6909: my ($output,$description);
6910: if ($type eq 'default') {
6911: $description = &mt('Requests for: [_1]',$typetitle);
6912: } else {
6913: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
6914: }
6915: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
6916: "<td>$description</td>\n".
6917: '<td class="'.$class.'" colspan="2">'.
6918: '<table><tr>';
6919: my %headers = &Apache::lonlocal::texthash(
6920: approve => 'Processing',
6921: email => 'E-mail',
6922: username => 'Username',
6923: );
6924: foreach my $item ('approve','email','username') {
6925: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 6926: }
1.305 raeburn 6927: $output .= '</tr><tr>';
6928: foreach my $item ('approve','email','username') {
1.306 raeburn 6929: $output .= '<td style="vertical-align: top">';
1.305 raeburn 6930: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
6931: if ($item eq 'approve') {
6932: %choices = &Apache::lonlocal::texthash (
6933: automatic => 'Automatically approved',
6934: approval => 'Queued for approval',
6935: );
6936: @options = ('automatic','approval');
6937: $hashref = $processing;
6938: $defoption = 'automatic';
6939: $name = 'cancreate_emailprocess_'.$type;
6940: } elsif ($item eq 'email') {
6941: %choices = &Apache::lonlocal::texthash (
6942: any => 'Any e-mail',
6943: inst => 'Institutional only',
6944: noninst => 'Non-institutional only',
6945: custom => 'Custom restrictions',
6946: );
6947: @options = ('any','inst','noninst');
6948: my $showcustom;
6949: if (ref($emailrules) eq 'HASH') {
6950: if (keys(%{$emailrules}) > 0) {
6951: push(@options,'custom');
6952: $showcustom = 'cancreate_emailrule';
6953: if (ref($settings) eq 'HASH') {
6954: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
6955: foreach my $rule (@{$settings->{'email_rule'}}) {
6956: if (exists($emailrules->{$rule})) {
6957: $hascustom ++;
6958: }
6959: }
6960: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
6961: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
6962: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
6963: if (exists($emailrules->{$rule})) {
6964: $hascustom ++;
6965: }
6966: }
6967: }
6968: }
6969: }
6970: }
6971: }
6972: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
6973: "'cancreate_emaildomain','$type'".');"';
6974: $hashref = $emailoptions;
6975: $defoption = 'any';
6976: $name = 'cancreate_emailoptions_'.$type;
6977: } elsif ($item eq 'username') {
6978: %choices = &Apache::lonlocal::texthash (
6979: all => 'Same as e-mail',
6980: first => 'Omit @domain',
6981: free => 'Free to choose',
6982: );
6983: @options = ('all','first','free');
6984: $hashref = $emailverified;
6985: $defoption = 'all';
6986: $name = 'cancreate_usernameoptions_'.$type;
6987: }
6988: foreach my $option (@options) {
6989: my $checked;
6990: if (ref($hashref) eq 'HASH') {
6991: if ($type eq '') {
6992: if (!exists($hashref->{'default'})) {
6993: if ($option eq $defoption) {
6994: $checked = ' checked="checked"';
6995: }
6996: } else {
6997: if ($hashref->{'default'} eq $option) {
6998: $checked = ' checked="checked"';
6999: }
1.303 raeburn 7000: }
7001: } else {
1.305 raeburn 7002: if (!exists($hashref->{$type})) {
7003: if ($option eq $defoption) {
7004: $checked = ' checked="checked"';
7005: }
7006: } else {
7007: if ($hashref->{$type} eq $option) {
7008: $checked = ' checked="checked"';
7009: }
1.303 raeburn 7010: }
7011: }
1.305 raeburn 7012: } elsif (($item eq 'email') && ($hascustom)) {
7013: if ($option eq 'custom') {
7014: $checked = ' checked="checked"';
7015: }
7016: } elsif ($option eq $defoption) {
7017: $checked = ' checked="checked"';
7018: }
7019: $output .= '<span class="LC_nobreak"><label>'.
7020: '<input type="radio" name="'.$name.'"'.
7021: $checked.' value="'.$option.'"'.$onclick.' />'.
7022: $choices{$option}.'</label></span><br />';
7023: if ($item eq 'email') {
7024: if ($option eq 'custom') {
7025: my $id = 'cancreate_emailrule_'.$type;
7026: my $display = 'none';
7027: if ($checked) {
7028: $display = 'inline';
1.303 raeburn 7029: }
1.305 raeburn 7030: my $numinrow = 2;
7031: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
7032: '<legend>'.&mt('Disallow').'</legend><table>'.
7033: &user_formats_row('email',$settings,$emailrules,
7034: $emailruleorder,$numinrow,'',$type);
7035: '</table></fieldset>';
7036: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
7037: my %text = &Apache::lonlocal::texthash (
7038: inst => 'must end:',
7039: noninst => 'cannot end:',
7040: );
7041: my $value;
7042: if (ref($emaildomain) eq 'HASH') {
7043: if (ref($emaildomain->{$type}) eq 'HASH') {
7044: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 7045: }
7046: }
1.305 raeburn 7047: if ($value eq '') {
7048: $value = '@'.$intdom;
7049: }
7050: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
7051: my $display = 'none';
7052: if ($checked) {
7053: $display = 'inline';
7054: }
7055: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
7056: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
7057: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
7058: '</div>';
1.303 raeburn 7059: }
7060: }
7061: }
1.305 raeburn 7062: $output .= '</td>'."\n";
1.303 raeburn 7063: }
1.305 raeburn 7064: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 7065: return $output;
7066: }
7067:
1.165 raeburn 7068: sub captcha_choice {
1.305 raeburn 7069: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 7070: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
7071: $vertext,$currver);
1.165 raeburn 7072: my %lt = &captcha_phrases();
7073: $keyentry = 'hidden';
7074: if ($context eq 'cancreate') {
1.224 raeburn 7075: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 7076: } elsif ($context eq 'login') {
7077: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 7078: }
7079: if (ref($settings) eq 'HASH') {
7080: if ($settings->{'captcha'}) {
7081: $checked{$settings->{'captcha'}} = ' checked="checked"';
7082: } else {
7083: $checked{'original'} = ' checked="checked"';
7084: }
7085: if ($settings->{'captcha'} eq 'recaptcha') {
7086: $pubtext = $lt{'pub'};
7087: $privtext = $lt{'priv'};
7088: $keyentry = 'text';
1.269 raeburn 7089: $vertext = $lt{'ver'};
7090: $currver = $settings->{'recaptchaversion'};
7091: if ($currver ne '2') {
7092: $currver = 1;
7093: }
1.165 raeburn 7094: }
7095: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
7096: $currpub = $settings->{'recaptchakeys'}{'public'};
7097: $currpriv = $settings->{'recaptchakeys'}{'private'};
7098: }
7099: } else {
7100: $checked{'original'} = ' checked="checked"';
7101: }
1.305 raeburn 7102: my $css_class;
7103: if ($itemcount%2) {
7104: $css_class = 'LC_odd_row';
7105: }
7106: if ($customcss) {
7107: $css_class .= " $customcss";
7108: }
7109: $css_class =~ s/^\s+//;
7110: if ($css_class) {
7111: $css_class = ' class="'.$css_class.'"';
7112: }
7113: if ($rowstyle) {
7114: $css_class .= ' style="'.$rowstyle.'"';
7115: }
1.169 raeburn 7116: my $output = '<tr'.$css_class.'>'.
7117: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 7118: '<table><tr><td>'."\n";
7119: foreach my $option ('original','recaptcha','notused') {
7120: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
7121: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
7122: $lt{$option}.'</label></span>';
7123: unless ($option eq 'notused') {
7124: $output .= (' 'x2)."\n";
7125: }
7126: }
7127: #
7128: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
7129: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 7130: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 7131: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 7132: #
1.165 raeburn 7133: $output .= '</td></tr>'."\n".
1.305 raeburn 7134: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 7135: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
7136: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
7137: $currpub.'" size="40" /></span><br />'."\n".
7138: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
7139: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 7140: $currpriv.'" size="40" /></span><br />'.
7141: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
7142: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
7143: $currver.'" size="3" /></span><br />'.
7144: '</td></tr></table>'."\n".
1.165 raeburn 7145: '</td></tr>';
7146: return $output;
7147: }
7148:
1.32 raeburn 7149: sub user_formats_row {
1.305 raeburn 7150: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 7151: my $output;
7152: my %text = (
7153: 'username' => 'new usernames',
7154: 'id' => 'IDs',
7155: );
1.305 raeburn 7156: unless ($type eq 'email') {
7157: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
7158: $output = '<tr '.$css_class.'>'.
7159: '<td><span class="LC_nobreak">'.
7160: &mt("Format rules to check for $text{$type}: ").
7161: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 7162: }
1.27 raeburn 7163: my $rem;
7164: if (ref($ruleorder) eq 'ARRAY') {
7165: for (my $i=0; $i<@{$ruleorder}; $i++) {
7166: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
7167: my $rem = $i%($numinrow);
7168: if ($rem == 0) {
7169: if ($i > 0) {
7170: $output .= '</tr>';
7171: }
7172: $output .= '<tr>';
7173: }
7174: my $check = ' ';
1.39 raeburn 7175: if (ref($settings) eq 'HASH') {
7176: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
7177: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
7178: $check = ' checked="checked" ';
7179: }
1.305 raeburn 7180: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
7181: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
7182: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
7183: $check = ' checked="checked" ';
7184: }
7185: }
1.27 raeburn 7186: }
7187: }
1.305 raeburn 7188: my $name = $type.'_rule';
7189: if ($type eq 'email') {
7190: $name .= '_'.$status;
7191: }
1.27 raeburn 7192: $output .= '<td class="LC_left_item">'.
7193: '<span class="LC_nobreak"><label>'.
1.311 raeburn 7194: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 7195: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
7196: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
7197: }
7198: }
7199: $rem = @{$ruleorder}%($numinrow);
7200: }
1.305 raeburn 7201: my $colsleft;
7202: if ($rem) {
7203: $colsleft = $numinrow - $rem;
7204: }
1.27 raeburn 7205: if ($colsleft > 1 ) {
7206: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7207: ' </td>';
7208: } elsif ($colsleft == 1) {
7209: $output .= '<td class="LC_left_item"> </td>';
7210: }
1.305 raeburn 7211: $output .= '</tr></table>';
7212: unless ($type eq 'email') {
7213: $output .= '</td></tr>';
7214: }
1.27 raeburn 7215: return $output;
7216: }
7217:
1.34 raeburn 7218: sub usercreation_types {
7219: my %lt = &Apache::lonlocal::texthash (
7220: author => 'When adding a co-author',
7221: course => 'When adding a user to a course',
1.100 raeburn 7222: requestcrs => 'When requesting a course',
1.34 raeburn 7223: any => 'Any',
7224: official => 'Institutional only ',
7225: unofficial => 'Non-institutional only',
7226: none => 'None',
7227: );
7228: return %lt;
1.48 raeburn 7229: }
1.34 raeburn 7230:
1.224 raeburn 7231: sub selfcreation_types {
7232: my %lt = &Apache::lonlocal::texthash (
7233: selfcreate => 'User creates own account',
7234: any => 'Any',
7235: official => 'Institutional only ',
7236: unofficial => 'Non-institutional only',
7237: email => 'E-mail address',
7238: login => 'Institutional Login',
7239: sso => 'SSO',
7240: );
7241: }
7242:
1.28 raeburn 7243: sub authtype_names {
7244: my %lt = &Apache::lonlocal::texthash(
7245: int => 'Internal',
7246: krb4 => 'Kerberos 4',
7247: krb5 => 'Kerberos 5',
7248: loc => 'Local',
7249: );
7250: return %lt;
7251: }
7252:
7253: sub context_names {
7254: my %context_title = &Apache::lonlocal::texthash(
7255: author => 'Creating users when an Author',
7256: course => 'Creating users when in a course',
7257: domain => 'Creating users when a Domain Coordinator',
7258: );
7259: return %context_title;
7260: }
7261:
1.33 raeburn 7262: sub print_usermodification {
7263: my ($position,$dom,$settings,$rowtotal) = @_;
7264: my $numinrow = 4;
7265: my ($context,$datatable,$rowcount);
7266: if ($position eq 'top') {
7267: $rowcount = 0;
7268: $context = 'author';
7269: foreach my $role ('ca','aa') {
7270: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7271: $numinrow,$rowcount);
7272: $$rowtotal ++;
7273: $rowcount ++;
7274: }
1.230 raeburn 7275: } elsif ($position eq 'bottom') {
1.33 raeburn 7276: $context = 'course';
7277: $rowcount = 0;
7278: foreach my $role ('st','ep','ta','in','cr') {
7279: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7280: $numinrow,$rowcount);
7281: $$rowtotal ++;
7282: $rowcount ++;
7283: }
7284: }
7285: return $datatable;
7286: }
7287:
1.43 raeburn 7288: sub print_defaults {
1.236 raeburn 7289: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 7290: my $rownum = 0;
1.294 raeburn 7291: my ($datatable,$css_class,$titles);
7292: unless ($position eq 'bottom') {
7293: $titles = &defaults_titles($dom);
7294: }
1.236 raeburn 7295: if ($position eq 'top') {
7296: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
7297: 'datelocale_def','portal_def');
7298: my %defaults;
7299: if (ref($settings) eq 'HASH') {
7300: %defaults = %{$settings};
1.43 raeburn 7301: } else {
1.236 raeburn 7302: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
7303: foreach my $item (@items) {
7304: $defaults{$item} = $domdefaults{$item};
7305: }
1.43 raeburn 7306: }
1.236 raeburn 7307: foreach my $item (@items) {
7308: if ($rownum%2) {
7309: $css_class = '';
7310: } else {
7311: $css_class = ' class="LC_odd_row" ';
7312: }
7313: $datatable .= '<tr'.$css_class.'>'.
7314: '<td><span class="LC_nobreak">'.$titles->{$item}.
7315: '</span></td><td class="LC_right_item" colspan="3">';
7316: if ($item eq 'auth_def') {
7317: my @authtypes = ('internal','krb4','krb5','localauth');
7318: my %shortauth = (
7319: internal => 'int',
7320: krb4 => 'krb4',
7321: krb5 => 'krb5',
7322: localauth => 'loc'
7323: );
7324: my %authnames = &authtype_names();
7325: foreach my $auth (@authtypes) {
7326: my $checked = ' ';
7327: if ($defaults{$item} eq $auth) {
7328: $checked = ' checked="checked" ';
7329: }
7330: $datatable .= '<label><input type="radio" name="'.$item.
7331: '" value="'.$auth.'"'.$checked.'/>'.
7332: $authnames{$shortauth{$auth}}.'</label> ';
7333: }
7334: } elsif ($item eq 'timezone_def') {
7335: my $includeempty = 1;
7336: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
7337: } elsif ($item eq 'datelocale_def') {
7338: my $includeempty = 1;
7339: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
7340: } elsif ($item eq 'lang_def') {
1.263 raeburn 7341: my $includeempty = 1;
7342: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 7343: } else {
7344: my $size;
7345: if ($item eq 'portal_def') {
7346: $size = ' size="25"';
7347: }
7348: $datatable .= '<input type="text" name="'.$item.'" value="'.
7349: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 7350: }
1.236 raeburn 7351: $datatable .= '</td></tr>';
7352: $rownum ++;
7353: }
1.294 raeburn 7354: } elsif ($position eq 'middle') {
7355: my @items = ('intauth_cost','intauth_check','intauth_switch');
7356: my %defaults;
7357: if (ref($settings) eq 'HASH') {
7358: %defaults = %{$settings};
7359: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
7360: $defaults{'intauth_cost'} = 10;
7361: }
7362: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
7363: $defaults{'intauth_check'} = 0;
7364: }
7365: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
7366: $defaults{'intauth_switch'} = 0;
7367: }
7368: } else {
7369: %defaults = (
7370: 'intauth_cost' => 10,
7371: 'intauth_check' => 0,
7372: 'intauth_switch' => 0,
7373: );
7374: }
7375: foreach my $item (@items) {
7376: if ($rownum%2) {
7377: $css_class = '';
7378: } else {
7379: $css_class = ' class="LC_odd_row" ';
7380: }
7381: $datatable .= '<tr'.$css_class.'>'.
7382: '<td><span class="LC_nobreak">'.$titles->{$item}.
7383: '</span></td><td class="LC_left_item" colspan="3">';
7384: if ($item eq 'intauth_switch') {
7385: my @options = (0,1,2);
7386: my %optiondesc = &Apache::lonlocal::texthash (
7387: 0 => 'No',
7388: 1 => 'Yes',
7389: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
7390: );
7391: $datatable .= '<table width="100%">';
7392: foreach my $option (@options) {
7393: my $checked = ' ';
7394: if ($defaults{$item} eq $option) {
7395: $checked = ' checked="checked"';
7396: }
7397: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7398: '<label><input type="radio" name="'.$item.
7399: '" value="'.$option.'"'.$checked.' />'.
7400: $optiondesc{$option}.'</label></span></td></tr>';
7401: }
7402: $datatable .= '</table>';
7403: } elsif ($item eq 'intauth_check') {
7404: my @options = (0,1,2);
7405: my %optiondesc = &Apache::lonlocal::texthash (
7406: 0 => 'No',
7407: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
7408: 2 => 'Yes, disallow login if stored cost is less than domain default',
7409: );
7410: $datatable .= '<table wisth="100%">';
7411: foreach my $option (@options) {
7412: my $checked = ' ';
7413: my $onclick;
7414: if ($defaults{$item} eq $option) {
7415: $checked = ' checked="checked"';
7416: }
7417: if ($option == 2) {
7418: $onclick = ' onclick="javascript:warnIntAuth(this);"';
7419: }
7420: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7421: '<label><input type="radio" name="'.$item.
7422: '" value="'.$option.'"'.$checked.$onclick.' />'.
7423: $optiondesc{$option}.'</label></span></td></tr>';
7424: }
7425: $datatable .= '</table>';
7426: } else {
7427: $datatable .= '<input type="text" name="'.$item.'" value="'.
7428: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
7429: }
7430: $datatable .= '</td></tr>';
7431: $rownum ++;
7432: }
1.236 raeburn 7433: } else {
1.294 raeburn 7434: my %defaults;
1.236 raeburn 7435: if (ref($settings) eq 'HASH') {
1.305 raeburn 7436: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.236 raeburn 7437: my $maxnum = @{$settings->{'inststatusorder'}};
7438: for (my $i=0; $i<$maxnum; $i++) {
7439: $css_class = $rownum%2?' class="LC_odd_row"':'';
7440: my $item = $settings->{'inststatusorder'}->[$i];
7441: my $title = $settings->{'inststatustypes'}->{$item};
7442: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
7443: $datatable .= '<tr'.$css_class.'>'.
7444: '<td><span class="LC_nobreak">'.
7445: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
7446: for (my $k=0; $k<=$maxnum; $k++) {
7447: my $vpos = $k+1;
7448: my $selstr;
7449: if ($k == $i) {
7450: $selstr = ' selected="selected" ';
7451: }
7452: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7453: }
7454: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
7455: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
7456: &mt('delete').'</span></td>'.
1.305 raeburn 7457: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed:').
1.236 raeburn 7458: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.305 raeburn 7459: '</span></td></tr>';
1.236 raeburn 7460: }
7461: $css_class = $rownum%2?' class="LC_odd_row"':'';
7462: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
7463: $datatable .= '<tr '.$css_class.'>'.
7464: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
7465: for (my $k=0; $k<=$maxnum; $k++) {
7466: my $vpos = $k+1;
7467: my $selstr;
7468: if ($k == $maxnum) {
7469: $selstr = ' selected="selected" ';
7470: }
7471: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7472: }
7473: $datatable .= '</select> '.&mt('Internal ID:').
1.263 raeburn 7474: '<input type="text" size="10" name="addinststatus" value="" />'.
1.236 raeburn 7475: ' '.&mt('(new)').
1.305 raeburn 7476: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.236 raeburn 7477: &mt('Name displayed:').
7478: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
7479: '</tr>'."\n";
7480: $rownum ++;
1.141 raeburn 7481: }
1.43 raeburn 7482: }
7483: }
7484: $$rowtotal += $rownum;
7485: return $datatable;
7486: }
7487:
1.168 raeburn 7488: sub get_languages_hash {
7489: my %langchoices;
7490: foreach my $id (&Apache::loncommon::languageids()) {
7491: my $code = &Apache::loncommon::supportedlanguagecode($id);
7492: if ($code ne '') {
7493: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
7494: }
7495: }
7496: return %langchoices;
7497: }
7498:
1.43 raeburn 7499: sub defaults_titles {
1.141 raeburn 7500: my ($dom) = @_;
1.43 raeburn 7501: my %titles = &Apache::lonlocal::texthash (
7502: 'auth_def' => 'Default authentication type',
7503: 'auth_arg_def' => 'Default authentication argument',
7504: 'lang_def' => 'Default language',
1.54 raeburn 7505: 'timezone_def' => 'Default timezone',
1.68 raeburn 7506: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 7507: 'portal_def' => 'Portal/Default URL',
1.294 raeburn 7508: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
7509: 'intauth_check' => 'Check bcrypt cost if authenticated',
7510: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 7511: );
1.141 raeburn 7512: if ($dom) {
7513: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
7514: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
7515: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
7516: $protocol = 'http' if ($protocol ne 'https');
7517: if ($uint_dom) {
7518: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
7519: $uint_dom);
7520: }
7521: }
1.43 raeburn 7522: return (\%titles);
7523: }
7524:
1.46 raeburn 7525: sub print_scantronformat {
7526: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
7527: my $itemcount = 1;
1.60 raeburn 7528: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
7529: %confhash);
1.46 raeburn 7530: my $switchserver = &check_switchserver($dom,$confname);
7531: my %lt = &Apache::lonlocal::texthash (
1.95 www 7532: default => 'Default bubblesheet format file error',
7533: custom => 'Custom bubblesheet format file error',
1.46 raeburn 7534: );
7535: my %scantronfiles = (
7536: default => 'default.tab',
7537: custom => 'custom.tab',
7538: );
7539: foreach my $key (keys(%scantronfiles)) {
7540: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
7541: .$scantronfiles{$key};
7542: }
7543: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
7544: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
7545: if (!$switchserver) {
7546: my $servadm = $r->dir_config('lonAdmEMail');
7547: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
7548: if ($configuserok eq 'ok') {
7549: if ($author_ok eq 'ok') {
7550: my %legacyfile = (
7551: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
7552: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
7553: );
7554: my %md5chk;
7555: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 7556: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
7557: chomp($md5chk{$type});
1.46 raeburn 7558: }
7559: if ($md5chk{'default'} ne $md5chk{'custom'}) {
7560: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 7561: ($scantronurls{$type},my $error) =
1.46 raeburn 7562: &legacy_scantronformat($r,$dom,$confname,
7563: $type,$legacyfile{$type},
7564: $scantronurls{$type},
7565: $scantronfiles{$type});
1.60 raeburn 7566: if ($error ne '') {
7567: $error{$type} = $error;
7568: }
7569: }
7570: if (keys(%error) == 0) {
7571: $is_custom = 1;
7572: $confhash{'scantron'}{'scantronformat'} =
7573: $scantronurls{'custom'};
7574: my $putresult =
7575: &Apache::lonnet::put_dom('configuration',
7576: \%confhash,$dom);
7577: if ($putresult ne 'ok') {
7578: $error{'custom'} =
7579: '<span class="LC_error">'.
7580: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7581: }
1.46 raeburn 7582: }
7583: } else {
1.60 raeburn 7584: ($scantronurls{'default'},my $error) =
1.46 raeburn 7585: &legacy_scantronformat($r,$dom,$confname,
7586: 'default',$legacyfile{'default'},
7587: $scantronurls{'default'},
7588: $scantronfiles{'default'});
1.60 raeburn 7589: if ($error eq '') {
7590: $confhash{'scantron'}{'scantronformat'} = '';
7591: my $putresult =
7592: &Apache::lonnet::put_dom('configuration',
7593: \%confhash,$dom);
7594: if ($putresult ne 'ok') {
7595: $error{'default'} =
7596: '<span class="LC_error">'.
7597: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7598: }
7599: } else {
7600: $error{'default'} = $error;
7601: }
1.46 raeburn 7602: }
7603: }
7604: }
7605: } else {
1.95 www 7606: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 7607: }
7608: }
7609: if (ref($settings) eq 'HASH') {
7610: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
7611: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
7612: if ((!@info) || ($info[0] eq 'no_such_dir')) {
7613: $scantronurl = '';
7614: } else {
7615: $scantronurl = $settings->{'scantronformat'};
7616: }
7617: $is_custom = 1;
7618: } else {
7619: $scantronurl = $scantronurls{'default'};
7620: }
7621: } else {
1.60 raeburn 7622: if ($is_custom) {
7623: $scantronurl = $scantronurls{'custom'};
7624: } else {
7625: $scantronurl = $scantronurls{'default'};
7626: }
1.46 raeburn 7627: }
7628: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7629: $datatable .= '<tr'.$css_class.'>';
7630: if (!$is_custom) {
1.65 raeburn 7631: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
7632: '<span class="LC_nobreak">';
1.46 raeburn 7633: if ($scantronurl) {
1.199 raeburn 7634: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
7635: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 7636: } else {
7637: $datatable = &mt('File unavailable for display');
7638: }
1.65 raeburn 7639: $datatable .= '</span></td>';
1.60 raeburn 7640: if (keys(%error) == 0) {
1.306 raeburn 7641: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 7642: if (!$switchserver) {
7643: $datatable .= &mt('Upload:').'<br />';
7644: }
7645: } else {
7646: my $errorstr;
7647: foreach my $key (sort(keys(%error))) {
7648: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7649: }
7650: $datatable .= '<td>'.$errorstr;
7651: }
1.46 raeburn 7652: } else {
7653: if (keys(%error) > 0) {
7654: my $errorstr;
7655: foreach my $key (sort(keys(%error))) {
7656: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7657: }
1.60 raeburn 7658: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 7659: } elsif ($scantronurl) {
1.199 raeburn 7660: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
7661: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 7662: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 7663: $link.
7664: '<label><input type="checkbox" name="scantronformat_del"'.
7665: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 7666: '<td><span class="LC_nobreak"> '.
7667: &mt('Replace:').'</span><br />';
1.46 raeburn 7668: }
7669: }
7670: if (keys(%error) == 0) {
7671: if ($switchserver) {
7672: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
7673: } else {
1.65 raeburn 7674: $datatable .='<span class="LC_nobreak"> '.
7675: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 7676: }
7677: }
7678: $datatable .= '</td></tr>';
7679: $$rowtotal ++;
7680: return $datatable;
7681: }
7682:
7683: sub legacy_scantronformat {
7684: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
7685: my ($url,$error);
7686: my @statinfo = &Apache::lonnet::stat_file($newurl);
7687: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
7688: (my $result,$url) =
7689: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
7690: '','',$newfile);
7691: if ($result ne 'ok') {
1.130 raeburn 7692: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 7693: }
7694: }
7695: return ($url,$error);
7696: }
1.43 raeburn 7697:
1.49 raeburn 7698: sub print_coursecategories {
1.57 raeburn 7699: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
7700: my $datatable;
7701: if ($position eq 'top') {
1.238 raeburn 7702: my (%checked);
7703: my @catitems = ('unauth','auth');
7704: my @cattypes = ('std','domonly','codesrch','none');
7705: $checked{'unauth'} = 'std';
7706: $checked{'auth'} = 'std';
7707: if (ref($settings) eq 'HASH') {
7708: foreach my $type (@cattypes) {
7709: if ($type eq $settings->{'unauth'}) {
7710: $checked{'unauth'} = $type;
7711: }
7712: if ($type eq $settings->{'auth'}) {
7713: $checked{'auth'} = $type;
7714: }
7715: }
7716: }
7717: my %lt = &Apache::lonlocal::texthash (
7718: unauth => 'Catalog type for unauthenticated users',
7719: auth => 'Catalog type for authenticated users',
7720: none => 'No catalog',
7721: std => 'Standard catalog',
7722: domonly => 'Domain-only catalog',
7723: codesrch => "Code search form",
7724: );
7725: my $itemcount = 0;
7726: foreach my $item (@catitems) {
7727: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
7728: $datatable .= '<tr '.$css_class.'>'.
7729: '<td>'.$lt{$item}.'</td>'.
7730: '<td class="LC_right_item"><span class="LC_nobreak">';
7731: foreach my $type (@cattypes) {
7732: my $ischecked;
7733: if ($checked{$item} eq $type) {
7734: $ischecked=' checked="checked"';
7735: }
7736: $datatable .= '<label>'.
7737: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
7738: ' />'.$lt{$type}.'</label> ';
7739: }
7740: $datatable .= '</td></tr>';
7741: $itemcount ++;
7742: }
7743: $$rowtotal += $itemcount;
7744: } elsif ($position eq 'middle') {
1.57 raeburn 7745: my $toggle_cats_crs = ' ';
7746: my $toggle_cats_dom = ' checked="checked" ';
7747: my $can_cat_crs = ' ';
7748: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 7749: my $toggle_catscomm_comm = ' ';
7750: my $toggle_catscomm_dom = ' checked="checked" ';
7751: my $can_catcomm_comm = ' ';
7752: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 7753: my $toggle_catsplace_place = ' ';
7754: my $toggle_catsplace_dom = ' checked="checked" ';
7755: my $can_catplace_place = ' ';
7756: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 7757:
1.57 raeburn 7758: if (ref($settings) eq 'HASH') {
7759: if ($settings->{'togglecats'} eq 'crs') {
7760: $toggle_cats_crs = $toggle_cats_dom;
7761: $toggle_cats_dom = ' ';
7762: }
7763: if ($settings->{'categorize'} eq 'crs') {
7764: $can_cat_crs = $can_cat_dom;
7765: $can_cat_dom = ' ';
7766: }
1.120 raeburn 7767: if ($settings->{'togglecatscomm'} eq 'comm') {
7768: $toggle_catscomm_comm = $toggle_catscomm_dom;
7769: $toggle_catscomm_dom = ' ';
7770: }
7771: if ($settings->{'categorizecomm'} eq 'comm') {
7772: $can_catcomm_comm = $can_catcomm_dom;
7773: $can_catcomm_dom = ' ';
7774: }
1.272 raeburn 7775: if ($settings->{'togglecatsplace'} eq 'place') {
7776: $toggle_catsplace_place = $toggle_catsplace_dom;
7777: $toggle_catsplace_dom = ' ';
7778: }
7779: if ($settings->{'categorizeplace'} eq 'place') {
7780: $can_catplace_place = $can_catplace_dom;
7781: $can_catplace_dom = ' ';
7782: }
1.57 raeburn 7783: }
7784: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 7785: togglecats => 'Show/Hide a course in catalog',
7786: togglecatscomm => 'Show/Hide a community in catalog',
7787: togglecatsplace => 'Show/Hide a placement test in catalog',
7788: categorize => 'Assign a category to a course',
7789: categorizecomm => 'Assign a category to a community',
7790: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 7791: );
7792: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 7793: dom => 'Set in Domain',
7794: crs => 'Set in Course',
7795: comm => 'Set in Community',
7796: place => 'Set in Placement Test',
1.57 raeburn 7797: );
7798: $datatable = '<tr class="LC_odd_row">'.
7799: '<td>'.$title{'togglecats'}.'</td>'.
7800: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7801: '<input type="radio" name="togglecats"'.
7802: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7803: '<label><input type="radio" name="togglecats"'.
7804: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
7805: '</tr><tr>'.
7806: '<td>'.$title{'categorize'}.'</td>'.
7807: '<td class="LC_right_item"><span class="LC_nobreak">'.
7808: '<label><input type="radio" name="categorize"'.
7809: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7810: '<label><input type="radio" name="categorize"'.
7811: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 7812: '</tr><tr class="LC_odd_row">'.
7813: '<td>'.$title{'togglecatscomm'}.'</td>'.
7814: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7815: '<input type="radio" name="togglecatscomm"'.
7816: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7817: '<label><input type="radio" name="togglecatscomm"'.
7818: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
7819: '</tr><tr>'.
7820: '<td>'.$title{'categorizecomm'}.'</td>'.
7821: '<td class="LC_right_item"><span class="LC_nobreak">'.
7822: '<label><input type="radio" name="categorizecomm"'.
7823: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7824: '<label><input type="radio" name="categorizecomm"'.
7825: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.272 raeburn 7826: '</tr><tr>'.
7827: '<td>'.$title{'togglecatsplace'}.'</td>'.
7828: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7829: '<input type="radio" name="togglecatsplace"'.
7830: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7831: '<label><input type="radio" name="togglecatscomm"'.
7832: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
7833: '</tr><tr>'.
7834: '<td>'.$title{'categorizeplace'}.'</td>'.
7835: '<td class="LC_right_item"><span class="LC_nobreak">'.
7836: '<label><input type="radio" name="categorizeplace"'.
7837: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7838: '<label><input type="radio" name="categorizeplace"'.
7839: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 7840: '</tr>';
1.272 raeburn 7841: $$rowtotal += 6;
1.57 raeburn 7842: } else {
7843: my $css_class;
7844: my $itemcount = 1;
7845: my $cathash;
7846: if (ref($settings) eq 'HASH') {
7847: $cathash = $settings->{'cats'};
7848: }
7849: if (ref($cathash) eq 'HASH') {
7850: my (@cats,@trails,%allitems,%idx,@jsarray);
7851: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
7852: \%allitems,\%idx,\@jsarray);
7853: my $maxdepth = scalar(@cats);
7854: my $colattrib = '';
7855: if ($maxdepth > 2) {
7856: $colattrib = ' colspan="2" ';
7857: }
7858: my @path;
7859: if (@cats > 0) {
7860: if (ref($cats[0]) eq 'ARRAY') {
7861: my $numtop = @{$cats[0]};
7862: my $maxnum = $numtop;
1.120 raeburn 7863: my %default_names = (
7864: instcode => &mt('Official courses'),
7865: communities => &mt('Communities'),
1.272 raeburn 7866: placement => &mt('Placement Tests'),
1.120 raeburn 7867: );
7868:
7869: if ((!grep(/^instcode$/,@{$cats[0]})) ||
7870: ($cathash->{'instcode::0'} eq '') ||
7871: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 7872: ($cathash->{'communities::0'} eq '') ||
7873: (!grep(/^placement$/,@{$cats[0]})) ||
7874: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 7875: $maxnum ++;
7876: }
7877: my $lastidx;
7878: for (my $i=0; $i<$numtop; $i++) {
7879: my $parent = $cats[0][$i];
7880: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7881: my $item = &escape($parent).'::0';
7882: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
7883: $lastidx = $idx{$item};
7884: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
7885: .'<select name="'.$item.'"'.$chgstr.'>';
7886: for (my $k=0; $k<=$maxnum; $k++) {
7887: my $vpos = $k+1;
7888: my $selstr;
7889: if ($k == $i) {
7890: $selstr = ' selected="selected" ';
7891: }
7892: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7893: }
1.214 raeburn 7894: $datatable .= '</select></span></td><td>';
1.272 raeburn 7895: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 7896: $datatable .= '<span class="LC_nobreak">'
7897: .$default_names{$parent}.'</span>';
7898: if ($parent eq 'instcode') {
7899: $datatable .= '<br /><span class="LC_nobreak">('
7900: .&mt('with institutional codes')
7901: .')</span></td><td'.$colattrib.'>';
7902: } else {
7903: $datatable .= '<table><tr><td>';
7904: }
7905: $datatable .= '<span class="LC_nobreak">'
7906: .'<label><input type="radio" name="'
7907: .$parent.'" value="1" checked="checked" />'
7908: .&mt('Display').'</label>';
7909: if ($parent eq 'instcode') {
7910: $datatable .= ' ';
7911: } else {
7912: $datatable .= '</span></td></tr><tr><td>'
7913: .'<span class="LC_nobreak">';
7914: }
7915: $datatable .= '<label><input type="radio" name="'
7916: .$parent.'" value="0" />'
7917: .&mt('Do not display').'</label></span>';
1.272 raeburn 7918: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 7919: $datatable .= '</td></tr></table>';
7920: }
7921: $datatable .= '</td>';
1.57 raeburn 7922: } else {
7923: $datatable .= $parent
1.214 raeburn 7924: .' <span class="LC_nobreak"><label>'
7925: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 7926: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
7927: }
7928: my $depth = 1;
7929: push(@path,$parent);
7930: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
7931: pop(@path);
7932: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
7933: $itemcount ++;
7934: }
1.48 raeburn 7935: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 7936: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
7937: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 7938: for (my $k=0; $k<=$maxnum; $k++) {
7939: my $vpos = $k+1;
7940: my $selstr;
1.57 raeburn 7941: if ($k == $numtop) {
1.48 raeburn 7942: $selstr = ' selected="selected" ';
7943: }
7944: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7945: }
1.59 bisitz 7946: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 7947: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
7948: .'</tr>'."\n";
1.48 raeburn 7949: $itemcount ++;
1.272 raeburn 7950: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 7951: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
7952: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7953: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
7954: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
7955: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
7956: for (my $k=0; $k<=$maxnum; $k++) {
7957: my $vpos = $k+1;
7958: my $selstr;
7959: if ($k == $maxnum) {
7960: $selstr = ' selected="selected" ';
7961: }
7962: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 7963: }
1.120 raeburn 7964: $datatable .= '</select></span></td>'.
7965: '<td><span class="LC_nobreak">'.
7966: $default_names{$default}.'</span>';
7967: if ($default eq 'instcode') {
7968: $datatable .= '<br /><span class="LC_nobreak">('
7969: .&mt('with institutional codes').')</span>';
7970: }
7971: $datatable .= '</td>'
7972: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
7973: .&mt('Display').'</label> '
7974: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
7975: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 7976: }
7977: }
7978: }
1.57 raeburn 7979: } else {
7980: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 7981: }
7982: } else {
1.238 raeburn 7983: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 7984: .&initialize_categories($itemcount);
1.48 raeburn 7985: }
1.57 raeburn 7986: $$rowtotal += $itemcount;
1.48 raeburn 7987: }
7988: return $datatable;
7989: }
7990:
1.69 raeburn 7991: sub print_serverstatuses {
7992: my ($dom,$settings,$rowtotal) = @_;
7993: my $datatable;
7994: my @pages = &serverstatus_pages();
7995: my (%namedaccess,%machineaccess);
7996: foreach my $type (@pages) {
7997: $namedaccess{$type} = '';
7998: $machineaccess{$type}= '';
7999: }
8000: if (ref($settings) eq 'HASH') {
8001: foreach my $type (@pages) {
8002: if (exists($settings->{$type})) {
8003: if (ref($settings->{$type}) eq 'HASH') {
8004: foreach my $key (keys(%{$settings->{$type}})) {
8005: if ($key eq 'namedusers') {
8006: $namedaccess{$type} = $settings->{$type}->{$key};
8007: } elsif ($key eq 'machines') {
8008: $machineaccess{$type} = $settings->{$type}->{$key};
8009: }
8010: }
8011: }
8012: }
8013: }
8014: }
1.81 raeburn 8015: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 8016: my $rownum = 0;
8017: my $css_class;
8018: foreach my $type (@pages) {
8019: $rownum ++;
8020: $css_class = $rownum%2?' class="LC_odd_row"':'';
8021: $datatable .= '<tr'.$css_class.'>'.
8022: '<td><span class="LC_nobreak">'.
8023: $titles->{$type}.'</span></td>'.
8024: '<td class="LC_left_item">'.
8025: '<input type="text" name="'.$type.'_namedusers" '.
8026: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
8027: '<td class="LC_right_item">'.
8028: '<span class="LC_nobreak">'.
8029: '<input type="text" name="'.$type.'_machines" '.
8030: 'value="'.$machineaccess{$type}.'" size="10" />'.
8031: '</td></tr>'."\n";
8032: }
8033: $$rowtotal += $rownum;
8034: return $datatable;
8035: }
8036:
8037: sub serverstatus_pages {
8038: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 8039: 'checksums','clusterstatus','certstatus','metadata_keywords',
8040: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
8041: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 8042: }
8043:
1.236 raeburn 8044: sub defaults_javascript {
8045: my ($settings) = @_;
1.294 raeburn 8046: 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.');
8047: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
8048: &js_escape(\$intauthcheck);
8049: &js_escape(\$intauthcost);
8050: my $intauthjs = <<"ENDSCRIPT";
8051:
8052: function warnIntAuth(field) {
8053: if (field.name == 'intauth_check') {
8054: if (field.value == '2') {
8055: alert('$intauthcheck');
8056: }
8057: }
8058: if (field.name == 'intauth_cost') {
8059: field.value.replace(/\s/g,'');
8060: if (field.value != '') {
8061: var regexdigit=/^\\d+\$/;
8062: if (!regexdigit.test(field.value)) {
8063: alert('$intauthcost');
8064: }
8065: }
8066: }
8067: return;
8068: }
8069:
8070: ENDSCRIPT
8071:
8072: if (ref($settings) ne 'HASH') {
8073: return &Apache::lonhtmlcommon::scripttag($intauthjs);
8074: }
1.236 raeburn 8075: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
8076: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
8077: if ($maxnum eq '') {
8078: $maxnum = 0;
8079: }
8080: $maxnum ++;
1.249 raeburn 8081: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 8082: return <<"ENDSCRIPT";
8083: <script type="text/javascript">
8084: // <![CDATA[
8085: function reorderTypes(form,caller) {
8086: var changedVal;
8087: $jstext
8088: var newpos = 'addinststatus_pos';
8089: var current = new Array;
8090: var maxh = $maxnum;
8091: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8092: var oldVal;
8093: if (caller == newpos) {
8094: changedVal = newitemVal;
8095: } else {
8096: var curritem = 'inststatus_pos_'+caller;
8097: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
8098: current[newitemVal] = newpos;
8099: }
8100: for (var i=0; i<inststatuses.length; i++) {
8101: if (inststatuses[i] != caller) {
8102: var elementName = 'inststatus_pos_'+inststatuses[i];
8103: if (form.elements[elementName]) {
8104: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8105: current[currVal] = elementName;
8106: }
8107: }
8108: }
8109: for (var j=0; j<maxh; j++) {
8110: if (current[j] == undefined) {
8111: oldVal = j;
8112: }
8113: }
8114: if (oldVal < changedVal) {
8115: for (var k=oldVal+1; k<=changedVal ; k++) {
8116: var elementName = current[k];
8117: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8118: }
8119: } else {
8120: for (var k=changedVal; k<oldVal; k++) {
8121: var elementName = current[k];
8122: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8123: }
8124: }
8125: return;
8126: }
8127:
1.294 raeburn 8128: $intauthjs
8129:
1.236 raeburn 8130: // ]]>
8131: </script>
8132:
8133: ENDSCRIPT
1.294 raeburn 8134: } else {
8135: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 8136: }
8137: }
8138:
1.49 raeburn 8139: sub coursecategories_javascript {
8140: my ($settings) = @_;
1.57 raeburn 8141: my ($output,$jstext,$cathash);
1.49 raeburn 8142: if (ref($settings) eq 'HASH') {
1.57 raeburn 8143: $cathash = $settings->{'cats'};
8144: }
8145: if (ref($cathash) eq 'HASH') {
1.49 raeburn 8146: my (@cats,@jsarray,%idx);
1.57 raeburn 8147: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 8148: if (@jsarray > 0) {
8149: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
8150: for (my $i=0; $i<@jsarray; $i++) {
8151: if (ref($jsarray[$i]) eq 'ARRAY') {
8152: my $catstr = join('","',@{$jsarray[$i]});
8153: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
8154: }
8155: }
8156: }
8157: } else {
8158: $jstext = ' var categories = Array(1);'."\n".
8159: ' categories[0] = Array("instcode_pos");'."\n";
8160: }
1.237 bisitz 8161: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
8162: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 8163: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 8164: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
8165: &js_escape(\$instcode_reserved);
8166: &js_escape(\$communities_reserved);
1.272 raeburn 8167: &js_escape(\$placement_reserved);
1.265 damieng 8168: &js_escape(\$choose_again);
1.49 raeburn 8169: $output = <<"ENDSCRIPT";
8170: <script type="text/javascript">
1.109 raeburn 8171: // <![CDATA[
1.49 raeburn 8172: function reorderCats(form,parent,item,idx) {
8173: var changedVal;
8174: $jstext
8175: var newpos = 'addcategory_pos';
8176: if (parent == '') {
8177: var has_instcode = 0;
8178: var maxtop = categories[idx].length;
8179: for (var j=0; j<maxtop; j++) {
8180: if (categories[idx][j] == 'instcode::0') {
8181: has_instcode == 1;
8182: }
8183: }
8184: if (has_instcode == 0) {
8185: categories[idx][maxtop] = 'instcode_pos';
8186: }
8187: } else {
8188: newpos += '_'+parent;
8189: }
8190: var maxh = 1 + categories[idx].length;
8191: var current = new Array;
8192: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8193: if (item == newpos) {
8194: changedVal = newitemVal;
8195: } else {
8196: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
8197: current[newitemVal] = newpos;
8198: }
8199: for (var i=0; i<categories[idx].length; i++) {
8200: var elementName = categories[idx][i];
8201: if (elementName != item) {
8202: if (form.elements[elementName]) {
8203: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8204: current[currVal] = elementName;
8205: }
8206: }
8207: }
8208: var oldVal;
8209: for (var j=0; j<maxh; j++) {
8210: if (current[j] == undefined) {
8211: oldVal = j;
8212: }
8213: }
8214: if (oldVal < changedVal) {
8215: for (var k=oldVal+1; k<=changedVal ; k++) {
8216: var elementName = current[k];
8217: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8218: }
8219: } else {
8220: for (var k=changedVal; k<oldVal; k++) {
8221: var elementName = current[k];
8222: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8223: }
8224: }
8225: return;
8226: }
1.120 raeburn 8227:
8228: function categoryCheck(form) {
8229: if (form.elements['addcategory_name'].value == 'instcode') {
8230: alert('$instcode_reserved\\n$choose_again');
8231: return false;
8232: }
8233: if (form.elements['addcategory_name'].value == 'communities') {
8234: alert('$communities_reserved\\n$choose_again');
8235: return false;
8236: }
1.272 raeburn 8237: if (form.elements['addcategory_name'].value == 'placement') {
8238: alert('$placement_reserved\\n$choose_again');
8239: return false;
8240: }
1.120 raeburn 8241: return true;
8242: }
8243:
1.109 raeburn 8244: // ]]>
1.49 raeburn 8245: </script>
8246:
8247: ENDSCRIPT
8248: return $output;
8249: }
8250:
1.48 raeburn 8251: sub initialize_categories {
8252: my ($itemcount) = @_;
1.120 raeburn 8253: my ($datatable,$css_class,$chgstr);
8254: my %default_names = (
8255: instcode => 'Official courses (with institutional codes)',
8256: communities => 'Communities',
1.272 raeburn 8257: placement => 'Placement Tests',
1.120 raeburn 8258: );
8259: my $select0 = ' selected="selected"';
8260: my $select1 = '';
1.272 raeburn 8261: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 8262: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8263: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
1.272 raeburn 8264: if (($default eq 'communities') || ($default eq 'placement')) {
1.120 raeburn 8265: $select1 = $select0;
8266: $select0 = '';
8267: }
8268: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
8269: .'<select name="'.$default.'_pos">'
8270: .'<option value="0"'.$select0.'>1</option>'
8271: .'<option value="1"'.$select1.'>2</option>'
8272: .'<option value="2">3</option></select> '
8273: .$default_names{$default}
8274: .'</span></td><td><span class="LC_nobreak">'
8275: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
8276: .&mt('Display').'</label> <label>'
8277: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 8278: .'</label></span></td></tr>';
1.120 raeburn 8279: $itemcount ++;
8280: }
1.48 raeburn 8281: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 8282: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 8283: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 8284: .'<select name="addcategory_pos"'.$chgstr.'>'
8285: .'<option value="0">1</option>'
8286: .'<option value="1">2</option>'
8287: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 8288: .&mt('Add category').'</td><td>'.&mt('Name:')
8289: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
8290: return $datatable;
8291: }
8292:
8293: sub build_category_rows {
1.49 raeburn 8294: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
8295: my ($text,$name,$item,$chgstr);
1.48 raeburn 8296: if (ref($cats) eq 'ARRAY') {
8297: my $maxdepth = scalar(@{$cats});
8298: if (ref($cats->[$depth]) eq 'HASH') {
8299: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
8300: my $numchildren = @{$cats->[$depth]{$parent}};
8301: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 8302: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 8303: my ($idxnum,$parent_name,$parent_item);
8304: my $higher = $depth - 1;
8305: if ($higher == 0) {
8306: $parent_name = &escape($parent).'::'.$higher;
8307: } else {
8308: if (ref($path) eq 'ARRAY') {
8309: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8310: }
8311: }
8312: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 8313: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 8314: if ($j < $numchildren) {
1.48 raeburn 8315: $name = $cats->[$depth]{$parent}[$j];
8316: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 8317: $idxnum = $idx->{$item};
8318: } else {
8319: $name = $parent_name;
8320: $item = $parent_item;
1.48 raeburn 8321: }
1.49 raeburn 8322: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
8323: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 8324: for (my $i=0; $i<=$numchildren; $i++) {
8325: my $vpos = $i+1;
8326: my $selstr;
8327: if ($j == $i) {
8328: $selstr = ' selected="selected" ';
8329: }
8330: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
8331: }
8332: $text .= '</select> ';
8333: if ($j < $numchildren) {
8334: my $deeper = $depth+1;
8335: $text .= $name.' '
8336: .'<label><input type="checkbox" name="deletecategory" value="'
8337: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
8338: if(ref($path) eq 'ARRAY') {
8339: push(@{$path},$name);
1.49 raeburn 8340: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 8341: pop(@{$path});
8342: }
8343: } else {
1.59 bisitz 8344: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 8345: if ($j == $numchildren) {
8346: $text .= $name;
8347: } else {
8348: $text .= $item;
8349: }
8350: $text .= '" value="" />';
8351: }
8352: $text .= '</td></tr>';
8353: }
8354: $text .= '</table></td>';
8355: } else {
8356: my $higher = $depth-1;
8357: if ($higher == 0) {
8358: $name = &escape($parent).'::'.$higher;
8359: } else {
8360: if (ref($path) eq 'ARRAY') {
8361: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8362: }
8363: }
8364: my $colspan;
8365: if ($parent ne 'instcode') {
8366: $colspan = $maxdepth - $depth - 1;
8367: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
8368: }
8369: }
8370: }
8371: }
8372: return $text;
8373: }
8374:
1.33 raeburn 8375: sub modifiable_userdata_row {
1.305 raeburn 8376: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
8377: $rowid,$customcss,$rowstyle) = @_;
1.228 raeburn 8378: my ($role,$rolename,$statustype);
8379: $role = $item;
1.224 raeburn 8380: if ($context eq 'cancreate') {
1.305 raeburn 8381: if ($item =~ /^(emailusername)_(.+)$/) {
8382: $role = $1;
8383: $statustype = $2;
1.228 raeburn 8384: if (ref($usertypes) eq 'HASH') {
8385: if ($usertypes->{$statustype}) {
8386: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
8387: } else {
8388: $rolename = &mt('Data provided by user');
8389: }
8390: }
1.224 raeburn 8391: }
8392: } elsif ($context eq 'selfcreate') {
1.63 raeburn 8393: if (ref($usertypes) eq 'HASH') {
8394: $rolename = $usertypes->{$role};
8395: } else {
8396: $rolename = $role;
8397: }
1.33 raeburn 8398: } else {
1.63 raeburn 8399: if ($role eq 'cr') {
8400: $rolename = &mt('Custom role');
8401: } else {
8402: $rolename = &Apache::lonnet::plaintext($role);
8403: }
1.33 raeburn 8404: }
1.224 raeburn 8405: my (@fields,%fieldtitles);
8406: if (ref($fieldsref) eq 'ARRAY') {
8407: @fields = @{$fieldsref};
8408: } else {
8409: @fields = ('lastname','firstname','middlename','generation',
8410: 'permanentemail','id');
8411: }
8412: if ((ref($titlesref) eq 'HASH')) {
8413: %fieldtitles = %{$titlesref};
8414: } else {
8415: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8416: }
1.33 raeburn 8417: my $output;
1.305 raeburn 8418: my $css_class;
8419: if ($rowcount%2) {
8420: $css_class = 'LC_odd_row';
8421: }
8422: if ($customcss) {
8423: $css_class .= " $customcss";
8424: }
8425: $css_class =~ s/^\s+//;
8426: if ($css_class) {
8427: $css_class = ' class="'.$css_class.'"';
8428: }
8429: if ($rowstyle) {
8430: $css_class .= ' style="'.$rowstyle.'"';
8431: }
8432: if ($rowid) {
8433: $rowid = ' id="'.$rowid.'"';
8434: }
8435: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 8436: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
8437: '<td class="LC_left_item" colspan="2"><table>';
8438: my $rem;
8439: my %checks;
8440: if (ref($settings) eq 'HASH') {
8441: if (ref($settings->{$context}) eq 'HASH') {
8442: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228 raeburn 8443: my $hashref = $settings->{$context}->{$role};
8444: if ($role eq 'emailusername') {
8445: if ($statustype) {
8446: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
8447: $hashref = $settings->{$context}->{$role}->{$statustype};
8448: if (ref($hashref) eq 'HASH') {
8449: foreach my $field (@fields) {
8450: if ($hashref->{$field}) {
8451: $checks{$field} = $hashref->{$field};
8452: }
8453: }
8454: }
8455: }
8456: }
8457: } else {
8458: if (ref($hashref) eq 'HASH') {
8459: foreach my $field (@fields) {
8460: if ($hashref->{$field}) {
8461: $checks{$field} = ' checked="checked" ';
8462: }
8463: }
1.33 raeburn 8464: }
8465: }
8466: }
8467: }
8468: }
1.305 raeburn 8469:
8470: my $total = scalar(@fields);
8471: for (my $i=0; $i<$total; $i++) {
8472: $rem = $i%($numinrow);
1.33 raeburn 8473: if ($rem == 0) {
8474: if ($i > 0) {
8475: $output .= '</tr>';
8476: }
8477: $output .= '<tr>';
8478: }
8479: my $check = ' ';
1.228 raeburn 8480: unless ($role eq 'emailusername') {
8481: if (exists($checks{$fields[$i]})) {
8482: $check = $checks{$fields[$i]}
8483: } else {
8484: if ($role eq 'st') {
8485: if (ref($settings) ne 'HASH') {
8486: $check = ' checked="checked" ';
8487: }
1.33 raeburn 8488: }
8489: }
8490: }
8491: $output .= '<td class="LC_left_item">'.
1.228 raeburn 8492: '<span class="LC_nobreak">';
8493: if ($role eq 'emailusername') {
8494: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
8495: $checks{$fields[$i]} = 'omit';
8496: }
8497: foreach my $option ('required','optional','omit') {
8498: my $checked='';
8499: if ($checks{$fields[$i]} eq $option) {
8500: $checked='checked="checked" ';
8501: }
8502: $output .= '<label>'.
8503: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
8504: &mt($option).'</label>'.(' ' x2);
8505: }
8506: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
8507: } else {
8508: $output .= '<label>'.
8509: '<input type="checkbox" name="canmodify_'.$role.'" '.
8510: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
8511: '</label>';
8512: }
8513: $output .= '</span></td>';
1.33 raeburn 8514: }
1.305 raeburn 8515: $rem = $total%$numinrow;
8516: my $colsleft;
8517: if ($rem) {
8518: $colsleft = $numinrow - $rem;
8519: }
8520: if ($colsleft > 1) {
1.33 raeburn 8521: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8522: ' </td>';
8523: } elsif ($colsleft == 1) {
8524: $output .= '<td class="LC_left_item"> </td>';
8525: }
8526: $output .= '</tr></table></td></tr>';
8527: return $output;
8528: }
1.28 raeburn 8529:
1.93 raeburn 8530: sub insttypes_row {
1.305 raeburn 8531: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
8532: $customcss,$rowstyle) = @_;
1.93 raeburn 8533: my %lt = &Apache::lonlocal::texthash (
8534: cansearch => 'Users allowed to search',
8535: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 8536: lockablenames => 'User preference to lock name',
1.305 raeburn 8537: selfassign => 'Self-reportable affiliations',
1.315 raeburn 8538: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 8539: );
8540: my $showdom;
8541: if ($context eq 'cansearch') {
8542: $showdom = ' ('.$dom.')';
8543: }
1.165 raeburn 8544: my $class = 'LC_left_item';
8545: if ($context eq 'statustocreate') {
8546: $class = 'LC_right_item';
8547: }
1.305 raeburn 8548: my $css_class;
8549: if ($$rowtotal%2) {
8550: $css_class = 'LC_odd_row';
8551: }
8552: if ($customcss) {
8553: $css_class .= ' '.$customcss;
8554: }
8555: $css_class =~ s/^\s+//;
8556: if ($css_class) {
8557: $css_class = ' class="'.$css_class.'"';
8558: }
8559: if ($rowstyle) {
8560: $css_class .= ' style="'.$rowstyle.'"';
8561: }
8562: if ($onclick) {
8563: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 8564: }
8565: my $output = '<tr'.$css_class.'>'.
8566: '<td>'.$lt{$context}.$showdom.
8567: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 8568: my $rem;
8569: if (ref($types) eq 'ARRAY') {
8570: for (my $i=0; $i<@{$types}; $i++) {
8571: if (defined($usertypes->{$types->[$i]})) {
8572: my $rem = $i%($numinrow);
8573: if ($rem == 0) {
8574: if ($i > 0) {
8575: $output .= '</tr>';
8576: }
8577: $output .= '<tr>';
1.23 raeburn 8578: }
1.26 raeburn 8579: my $check = ' ';
1.99 raeburn 8580: if (ref($settings) eq 'HASH') {
8581: if (ref($settings->{$context}) eq 'ARRAY') {
8582: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
8583: $check = ' checked="checked" ';
8584: }
1.315 raeburn 8585: } elsif (ref($settings->{$context}) eq 'HASH') {
8586: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
8587: $check = ' checked="checked" ';
8588: }
1.99 raeburn 8589: } elsif ($context eq 'statustocreate') {
1.26 raeburn 8590: $check = ' checked="checked" ';
8591: }
1.23 raeburn 8592: }
1.26 raeburn 8593: $output .= '<td class="LC_left_item">'.
8594: '<span class="LC_nobreak"><label>'.
1.93 raeburn 8595: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 8596: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 8597: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 8598: }
8599: }
1.26 raeburn 8600: $rem = @{$types}%($numinrow);
1.23 raeburn 8601: }
8602: my $colsleft = $numinrow - $rem;
1.315 raeburn 8603: if ($context eq 'overrides') {
8604: if ($colsleft > 1) {
8605: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8606: } else {
8607: $output .= '<td class="LC_left_item">';
8608: }
8609: $output .= ' ';
1.23 raeburn 8610: } else {
1.315 raeburn 8611: if (($rem == 0) && (@{$types} > 0)) {
8612: $output .= '<tr>';
8613: }
8614: if ($colsleft > 1) {
8615: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8616: } else {
8617: $output .= '<td class="LC_left_item">';
8618: }
8619: my $defcheck = ' ';
8620: if (ref($settings) eq 'HASH') {
8621: if (ref($settings->{$context}) eq 'ARRAY') {
8622: if (grep(/^default$/,@{$settings->{$context}})) {
8623: $defcheck = ' checked="checked" ';
8624: }
8625: } elsif ($context eq 'statustocreate') {
1.99 raeburn 8626: $defcheck = ' checked="checked" ';
8627: }
1.26 raeburn 8628: }
1.315 raeburn 8629: $output .= '<span class="LC_nobreak"><label>'.
8630: '<input type="checkbox" name="'.$context.'" '.
8631: 'value="default"'.$defcheck.$onclick.' />'.
8632: $othertitle.'</label></span>';
1.23 raeburn 8633: }
1.315 raeburn 8634: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 8635: return $output;
1.23 raeburn 8636: }
8637:
8638: sub sorted_searchtitles {
8639: my %searchtitles = &Apache::lonlocal::texthash(
8640: 'uname' => 'username',
8641: 'lastname' => 'last name',
8642: 'lastfirst' => 'last name, first name',
8643: );
8644: my @titleorder = ('uname','lastname','lastfirst');
8645: return (\%searchtitles,\@titleorder);
8646: }
8647:
1.25 raeburn 8648: sub sorted_searchtypes {
8649: my %srchtypes_desc = (
8650: exact => 'is exact match',
8651: contains => 'contains ..',
8652: begins => 'begins with ..',
8653: );
8654: my @srchtypeorder = ('exact','begins','contains');
8655: return (\%srchtypes_desc,\@srchtypeorder);
8656: }
8657:
1.3 raeburn 8658: sub usertype_update_row {
8659: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
8660: my $datatable;
8661: my $numinrow = 4;
8662: foreach my $type (@{$types}) {
8663: if (defined($usertypes->{$type})) {
8664: $$rownums ++;
8665: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
8666: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
8667: '</td><td class="LC_left_item"><table>';
8668: for (my $i=0; $i<@{$fields}; $i++) {
8669: my $rem = $i%($numinrow);
8670: if ($rem == 0) {
8671: if ($i > 0) {
8672: $datatable .= '</tr>';
8673: }
8674: $datatable .= '<tr>';
8675: }
8676: my $check = ' ';
1.39 raeburn 8677: if (ref($settings) eq 'HASH') {
8678: if (ref($settings->{'fields'}) eq 'HASH') {
8679: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
8680: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
8681: $check = ' checked="checked" ';
8682: }
1.3 raeburn 8683: }
8684: }
8685: }
8686:
8687: if ($i == @{$fields}-1) {
8688: my $colsleft = $numinrow - $rem;
8689: if ($colsleft > 1) {
8690: $datatable .= '<td colspan="'.$colsleft.'">';
8691: } else {
8692: $datatable .= '<td>';
8693: }
8694: } else {
8695: $datatable .= '<td>';
8696: }
1.8 raeburn 8697: $datatable .= '<span class="LC_nobreak"><label>'.
8698: '<input type="checkbox" name="updateable_'.$type.
8699: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
8700: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 8701: }
8702: $datatable .= '</tr></table></td></tr>';
8703: }
8704: }
8705: return $datatable;
1.1 raeburn 8706: }
8707:
8708: sub modify_login {
1.205 raeburn 8709: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 8710: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
8711: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
8712: %title = ( coursecatalog => 'Display course catalog',
8713: adminmail => 'Display administrator E-mail address',
1.188 raeburn 8714: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 8715: newuser => 'Link for visitors to create a user account',
8716: loginheader => 'Log-in box header');
8717: @offon = ('off','on');
1.112 raeburn 8718: if (ref($domconfig{login}) eq 'HASH') {
8719: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
8720: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
8721: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
8722: }
8723: }
8724: }
1.9 raeburn 8725: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
8726: \%domconfig,\%loginhash);
1.188 raeburn 8727: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 8728: foreach my $item (@toggles) {
8729: $loginhash{login}{$item} = $env{'form.'.$item};
8730: }
1.41 raeburn 8731: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 8732: if (ref($colchanges{'login'}) eq 'HASH') {
8733: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
8734: \%loginhash);
8735: }
1.110 raeburn 8736:
1.149 raeburn 8737: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 8738: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 8739: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 8740: if (keys(%servers) > 1) {
8741: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 8742: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
8743: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
8744: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
8745: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
8746: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
8747: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8748: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
8749: $changes{'loginvia'}{$lonhost} = 1;
8750: } else {
8751: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
8752: $changes{'loginvia'}{$lonhost} = 1;
8753: }
8754: } else {
8755: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8756: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
8757: $changes{'loginvia'}{$lonhost} = 1;
8758: }
8759: }
8760: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
8761: foreach my $item (@loginvia_attribs) {
8762: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
8763: }
8764: } else {
8765: foreach my $item (@loginvia_attribs) {
8766: my $new = $env{'form.'.$lonhost.'_'.$item};
8767: if (($item eq 'serverpath') && ($new eq 'custom')) {
8768: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
8769: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
8770: $new = '/';
8771: }
8772: }
8773: if (($item eq 'custompath') &&
8774: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
8775: $new = '';
8776: }
8777: if ($new ne $curr_loginvia{$lonhost}{$item}) {
8778: $changes{'loginvia'}{$lonhost} = 1;
8779: }
8780: if ($item eq 'exempt') {
1.256 raeburn 8781: $new = &check_exempt_addresses($new);
1.128 raeburn 8782: }
8783: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
8784: }
8785: }
1.112 raeburn 8786: } else {
1.128 raeburn 8787: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8788: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 8789: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 8790: foreach my $item (@loginvia_attribs) {
8791: my $new = $env{'form.'.$lonhost.'_'.$item};
8792: if (($item eq 'serverpath') && ($new eq 'custom')) {
8793: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
8794: $new = '/';
8795: }
8796: }
8797: if (($item eq 'custompath') &&
8798: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
8799: $new = '';
8800: }
8801: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
8802: }
1.110 raeburn 8803: }
8804: }
8805: }
8806: }
1.119 raeburn 8807:
1.168 raeburn 8808: my $servadm = $r->dir_config('lonAdmEMail');
8809: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
8810: if (ref($domconfig{'login'}) eq 'HASH') {
8811: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
8812: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
8813: if ($lang eq 'nolang') {
8814: push(@currlangs,$lang);
8815: } elsif (defined($langchoices{$lang})) {
8816: push(@currlangs,$lang);
8817: } else {
8818: next;
8819: }
8820: }
8821: }
8822: }
8823: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
8824: if (@currlangs > 0) {
8825: foreach my $lang (@currlangs) {
8826: if (grep(/^\Q$lang\E$/,@delurls)) {
8827: $changes{'helpurl'}{$lang} = 1;
8828: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
8829: $changes{'helpurl'}{$lang} = 1;
8830: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
8831: push(@newlangs,$lang);
8832: } else {
8833: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
8834: }
8835: }
8836: }
8837: unless (grep(/^nolang$/,@currlangs)) {
8838: if ($env{'form.loginhelpurl_nolang.filename'}) {
8839: $changes{'helpurl'}{'nolang'} = 1;
8840: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
8841: push(@newlangs,'nolang');
8842: }
8843: }
8844: if ($env{'form.loginhelpurl_add_lang'}) {
8845: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
8846: ($env{'form.loginhelpurl_add_file.filename'})) {
8847: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
8848: $addedfile = $env{'form.loginhelpurl_add_lang'};
8849: }
8850: }
8851: if ((@newlangs > 0) || ($addedfile)) {
8852: my $error;
8853: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8854: if ($configuserok eq 'ok') {
8855: if ($switchserver) {
8856: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
8857: } elsif ($author_ok eq 'ok') {
8858: my @allnew = @newlangs;
8859: if ($addedfile ne '') {
8860: push(@allnew,$addedfile);
8861: }
8862: foreach my $lang (@allnew) {
8863: my $formelem = 'loginhelpurl_'.$lang;
8864: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
8865: $formelem = 'loginhelpurl_add_file';
8866: }
8867: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
8868: "help/$lang",'','',$newfile{$lang});
8869: if ($result eq 'ok') {
8870: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
8871: $changes{'helpurl'}{$lang} = 1;
8872: } else {
8873: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
8874: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 8875: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 8876: (!grep(/^\Q$lang\E$/,@delurls))) {
8877: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
8878: }
8879: }
8880: }
8881: } else {
8882: $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);
8883: }
8884: } else {
8885: $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);
8886: }
8887: if ($error) {
8888: &Apache::lonnet::logthis($error);
8889: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8890: }
8891: }
1.256 raeburn 8892:
8893: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
8894: if (ref($domconfig{'login'}) eq 'HASH') {
8895: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
8896: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
8897: if ($domservers{$lonhost}) {
8898: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
8899: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 8900: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 8901: }
8902: }
8903: }
8904: }
8905: }
8906: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
8907: foreach my $lonhost (sort(keys(%domservers))) {
8908: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
8909: $changes{'headtag'}{$lonhost} = 1;
8910: } else {
8911: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
8912: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
8913: }
8914: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
8915: push(@newhosts,$lonhost);
8916: } elsif ($currheadtagurls{$lonhost}) {
8917: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
8918: if ($currexempt{$lonhost}) {
1.289 raeburn 8919: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 8920: $changes{'headtag'}{$lonhost} = 1;
8921: }
8922: } elsif ($possexempt{$lonhost}) {
8923: $changes{'headtag'}{$lonhost} = 1;
8924: }
8925: if ($possexempt{$lonhost}) {
8926: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
8927: }
8928: }
8929: }
8930: }
8931: if (@newhosts) {
8932: my $error;
8933: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8934: if ($configuserok eq 'ok') {
8935: if ($switchserver) {
8936: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
8937: } elsif ($author_ok eq 'ok') {
8938: foreach my $lonhost (@newhosts) {
8939: my $formelem = 'loginheadtag_'.$lonhost;
8940: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
8941: "login/headtag/$lonhost",'','',
8942: $env{'form.loginheadtag_'.$lonhost.'.filename'});
8943: if ($result eq 'ok') {
8944: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
8945: $changes{'headtag'}{$lonhost} = 1;
8946: if ($possexempt{$lonhost}) {
8947: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
8948: }
8949: } else {
8950: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
8951: $newheadtagurls{$lonhost},$result);
8952: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
8953: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
8954: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
8955: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
8956: }
8957: }
8958: }
8959: } else {
8960: $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);
8961: }
8962: } else {
8963: $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);
8964: }
8965: if ($error) {
8966: &Apache::lonnet::logthis($error);
8967: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8968: }
8969: }
1.169 raeburn 8970: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 8971:
8972: my $defaulthelpfile = '/adm/loginproblems.html';
8973: my $defaulttext = &mt('Default in use');
8974:
1.1 raeburn 8975: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
8976: $dom);
8977: if ($putresult eq 'ok') {
1.188 raeburn 8978: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 8979: my %defaultchecked = (
8980: 'coursecatalog' => 'on',
1.188 raeburn 8981: 'helpdesk' => 'on',
1.42 raeburn 8982: 'adminmail' => 'off',
1.43 raeburn 8983: 'newuser' => 'off',
1.42 raeburn 8984: );
1.55 raeburn 8985: if (ref($domconfig{'login'}) eq 'HASH') {
8986: foreach my $item (@toggles) {
8987: if ($defaultchecked{$item} eq 'on') {
8988: if (($domconfig{'login'}{$item} eq '0') &&
8989: ($env{'form.'.$item} eq '1')) {
8990: $changes{$item} = 1;
8991: } elsif (($domconfig{'login'}{$item} eq '' ||
8992: $domconfig{'login'}{$item} eq '1') &&
8993: ($env{'form.'.$item} eq '0')) {
8994: $changes{$item} = 1;
8995: }
8996: } elsif ($defaultchecked{$item} eq 'off') {
8997: if (($domconfig{'login'}{$item} eq '1') &&
8998: ($env{'form.'.$item} eq '0')) {
8999: $changes{$item} = 1;
9000: } elsif (($domconfig{'login'}{$item} eq '' ||
9001: $domconfig{'login'}{$item} eq '0') &&
9002: ($env{'form.'.$item} eq '1')) {
9003: $changes{$item} = 1;
9004: }
1.42 raeburn 9005: }
9006: }
1.41 raeburn 9007: }
1.6 raeburn 9008: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 9009: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9010: if (ref($lastactref) eq 'HASH') {
9011: $lastactref->{'domainconfig'} = 1;
9012: }
1.1 raeburn 9013: $resulttext = &mt('Changes made:').'<ul>';
9014: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 9015: if ($item eq 'loginvia') {
1.112 raeburn 9016: if (ref($changes{$item}) eq 'HASH') {
9017: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
9018: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 9019: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
9020: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
9021: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
9022: $protocol = 'http' if ($protocol ne 'https');
9023: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
9024:
9025: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
9026: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
9027: } else {
9028: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
9029: }
9030: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
9031: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
9032: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
9033: }
9034: $resulttext .= '</li>';
9035: } else {
9036: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
9037: }
1.112 raeburn 9038: } else {
1.128 raeburn 9039: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 9040: }
9041: }
1.128 raeburn 9042: $resulttext .= '</ul></li>';
1.112 raeburn 9043: }
1.168 raeburn 9044: } elsif ($item eq 'helpurl') {
9045: if (ref($changes{$item}) eq 'HASH') {
9046: foreach my $lang (sort(keys(%{$changes{$item}}))) {
9047: if (grep(/^\Q$lang\E$/,@delurls)) {
9048: my ($chg,$link);
9049: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
9050: if ($lang eq 'nolang') {
9051: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
9052: } else {
9053: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
9054: }
9055: $resulttext .= '<li>'.$chg.'</li>';
9056: } else {
9057: my $chg;
9058: if ($lang eq 'nolang') {
9059: $chg = &mt('custom log-in help file for no preferred language');
9060: } else {
9061: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
9062: }
9063: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
9064: $loginhash{'login'}{'helpurl'}{$lang}.
9065: '?inhibitmenu=yes',$chg,600,500).
9066: '</li>';
9067: }
9068: }
9069: }
1.256 raeburn 9070: } elsif ($item eq 'headtag') {
9071: if (ref($changes{$item}) eq 'HASH') {
9072: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
9073: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9074: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
9075: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9076: $resulttext .= '<li><a href="'.
9077: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
9078: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
9079: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
9080: if ($possexempt{$lonhost}) {
9081: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
9082: } else {
9083: $resulttext .= &mt('included for any client IP');
9084: }
9085: $resulttext .= '</li>';
9086: }
9087: }
9088: }
1.169 raeburn 9089: } elsif ($item eq 'captcha') {
9090: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 9091: my $chgtxt;
1.169 raeburn 9092: if ($loginhash{'login'}{$item} eq 'notused') {
9093: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
9094: } else {
9095: my %captchas = &captcha_phrases();
9096: if ($captchas{$loginhash{'login'}{$item}}) {
9097: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
9098: } else {
9099: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
9100: }
9101: }
9102: $resulttext .= '<li>'.$chgtxt.'</li>';
9103: }
9104: } elsif ($item eq 'recaptchakeys') {
9105: if (ref($loginhash{'login'}) eq 'HASH') {
9106: my ($privkey,$pubkey);
9107: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
9108: $pubkey = $loginhash{'login'}{$item}{'public'};
9109: $privkey = $loginhash{'login'}{$item}{'private'};
9110: }
9111: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
9112: if (!$pubkey) {
9113: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
9114: } else {
9115: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
9116: }
9117: if (!$privkey) {
9118: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
9119: } else {
1.251 raeburn 9120: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 9121: }
9122: $chgtxt .= '</ul>';
9123: $resulttext .= '<li>'.$chgtxt.'</li>';
9124: }
1.269 raeburn 9125: } elsif ($item eq 'recaptchaversion') {
9126: if (ref($loginhash{'login'}) eq 'HASH') {
9127: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 9128: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 9129: '</li>';
9130: }
9131: }
1.41 raeburn 9132: } else {
9133: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
9134: }
1.1 raeburn 9135: }
1.6 raeburn 9136: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 9137: } else {
9138: $resulttext = &mt('No changes made to log-in page settings');
9139: }
9140: } else {
1.11 albertel 9141: $resulttext = '<span class="LC_error">'.
9142: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9143: }
1.6 raeburn 9144: if ($errors) {
1.9 raeburn 9145: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 9146: $errors.'</ul>';
9147: }
9148: return $resulttext;
9149: }
9150:
1.256 raeburn 9151: sub check_exempt_addresses {
9152: my ($iplist) = @_;
9153: $iplist =~ s/^\s+//;
9154: $iplist =~ s/\s+$//;
9155: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
9156: my (@okips,$new);
9157: foreach my $ip (@poss_ips) {
9158: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
9159: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
9160: push(@okips,$ip);
9161: }
9162: }
9163: }
9164: if (@okips > 0) {
9165: $new = join(',',@okips);
9166: } else {
9167: $new = '';
9168: }
9169: return $new;
9170: }
9171:
1.6 raeburn 9172: sub color_font_choices {
9173: my %choices =
9174: &Apache::lonlocal::texthash (
9175: img => "Header",
9176: bgs => "Background colors",
9177: links => "Link colors",
1.55 raeburn 9178: images => "Images",
1.6 raeburn 9179: font => "Font color",
1.201 raeburn 9180: fontmenu => "Font menu",
1.76 raeburn 9181: pgbg => "Page",
1.6 raeburn 9182: tabbg => "Header",
9183: sidebg => "Border",
9184: link => "Link",
9185: alink => "Active link",
9186: vlink => "Visited link",
9187: );
9188: return %choices;
9189: }
9190:
9191: sub modify_rolecolors {
1.205 raeburn 9192: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 9193: my ($resulttext,%rolehash);
9194: $rolehash{'rolecolors'} = {};
1.55 raeburn 9195: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
9196: if ($domconfig{'rolecolors'} eq '') {
9197: $domconfig{'rolecolors'} = {};
9198: }
9199: }
1.9 raeburn 9200: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 9201: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
9202: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
9203: $dom);
9204: if ($putresult eq 'ok') {
9205: if (keys(%changes) > 0) {
1.41 raeburn 9206: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9207: if (ref($lastactref) eq 'HASH') {
9208: $lastactref->{'domainconfig'} = 1;
9209: }
1.6 raeburn 9210: $resulttext = &display_colorchgs($dom,\%changes,$roles,
9211: $rolehash{'rolecolors'});
9212: } else {
9213: $resulttext = &mt('No changes made to default color schemes');
9214: }
9215: } else {
1.11 albertel 9216: $resulttext = '<span class="LC_error">'.
9217: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 9218: }
9219: if ($errors) {
9220: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9221: $errors.'</ul>';
9222: }
9223: return $resulttext;
9224: }
9225:
9226: sub modify_colors {
1.9 raeburn 9227: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 9228: my (%changes,%choices);
1.51 raeburn 9229: my @bgs;
1.6 raeburn 9230: my @links = ('link','alink','vlink');
1.41 raeburn 9231: my @logintext;
1.6 raeburn 9232: my @images;
9233: my $servadm = $r->dir_config('lonAdmEMail');
9234: my $errors;
1.200 raeburn 9235: my %defaults;
1.6 raeburn 9236: foreach my $role (@{$roles}) {
9237: if ($role eq 'login') {
1.12 raeburn 9238: %choices = &login_choices();
1.41 raeburn 9239: @logintext = ('textcol','bgcol');
1.12 raeburn 9240: } else {
9241: %choices = &color_font_choices();
9242: }
9243: if ($role eq 'login') {
1.41 raeburn 9244: @images = ('img','logo','domlogo','login');
1.51 raeburn 9245: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 9246: } else {
9247: @images = ('img');
1.200 raeburn 9248: @bgs = ('pgbg','tabbg','sidebg');
9249: }
9250: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
9251: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
9252: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
9253: }
9254: if ($role eq 'login') {
9255: foreach my $item (@logintext) {
1.234 raeburn 9256: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9257: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9258: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9259: }
9260: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 9261: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9262: }
9263: }
9264: } else {
1.234 raeburn 9265: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
9266: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
9267: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
9268: }
9269: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 9270: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
9271: }
1.6 raeburn 9272: }
1.200 raeburn 9273: foreach my $item (@bgs) {
1.234 raeburn 9274: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9275: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9276: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9277: }
9278: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 9279: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9280: }
9281: }
9282: foreach my $item (@links) {
1.234 raeburn 9283: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9284: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9285: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9286: }
9287: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 9288: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9289: }
1.6 raeburn 9290: }
1.46 raeburn 9291: my ($configuserok,$author_ok,$switchserver) =
9292: &config_check($dom,$confname,$servadm);
1.9 raeburn 9293: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 9294: if (ref($domconfig->{$role}) ne 'HASH') {
9295: $domconfig->{$role} = {};
9296: }
1.8 raeburn 9297: foreach my $img (@images) {
1.70 raeburn 9298: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
9299: if (defined($env{'form.login_showlogo_'.$img})) {
9300: $confhash->{$role}{'showlogo'}{$img} = 1;
9301: } else {
9302: $confhash->{$role}{'showlogo'}{$img} = 0;
9303: }
9304: }
1.18 albertel 9305: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
9306: && !defined($domconfig->{$role}{$img})
9307: && !$env{'form.'.$role.'_del_'.$img}
9308: && $env{'form.'.$role.'_import_'.$img}) {
9309: # import the old configured image from the .tab setting
9310: # if they haven't provided a new one
9311: $domconfig->{$role}{$img} =
9312: $env{'form.'.$role.'_import_'.$img};
9313: }
1.6 raeburn 9314: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 9315: my $error;
1.6 raeburn 9316: if ($configuserok eq 'ok') {
1.9 raeburn 9317: if ($switchserver) {
1.12 raeburn 9318: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 9319: } else {
9320: if ($author_ok eq 'ok') {
9321: my ($result,$logourl) =
9322: &publishlogo($r,'upload',$role.'_'.$img,
9323: $dom,$confname,$img,$width,$height);
9324: if ($result eq 'ok') {
9325: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 9326: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 9327: } else {
1.12 raeburn 9328: $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 9329: }
9330: } else {
1.46 raeburn 9331: $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 9332: }
9333: }
9334: } else {
1.46 raeburn 9335: $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 9336: }
9337: if ($error) {
1.8 raeburn 9338: &Apache::lonnet::logthis($error);
1.11 albertel 9339: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 9340: }
9341: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 9342: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
9343: my $error;
9344: if ($configuserok eq 'ok') {
9345: # is confname an author?
9346: if ($switchserver eq '') {
9347: if ($author_ok eq 'ok') {
9348: my ($result,$logourl) =
9349: &publishlogo($r,'copy',$domconfig->{$role}{$img},
9350: $dom,$confname,$img,$width,$height);
9351: if ($result eq 'ok') {
9352: $confhash->{$role}{$img} = $logourl;
1.18 albertel 9353: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 9354: }
9355: }
9356: }
9357: }
1.6 raeburn 9358: }
9359: }
9360: }
9361: if (ref($domconfig) eq 'HASH') {
9362: if (ref($domconfig->{$role}) eq 'HASH') {
9363: foreach my $img (@images) {
9364: if ($domconfig->{$role}{$img} ne '') {
9365: if ($env{'form.'.$role.'_del_'.$img}) {
9366: $confhash->{$role}{$img} = '';
1.12 raeburn 9367: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 9368: } else {
1.9 raeburn 9369: if ($confhash->{$role}{$img} eq '') {
9370: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
9371: }
1.6 raeburn 9372: }
9373: } else {
9374: if ($env{'form.'.$role.'_del_'.$img}) {
9375: $confhash->{$role}{$img} = '';
1.12 raeburn 9376: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 9377: }
9378: }
1.70 raeburn 9379: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
9380: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
9381: if ($confhash->{$role}{'showlogo'}{$img} ne
9382: $domconfig->{$role}{'showlogo'}{$img}) {
9383: $changes{$role}{'showlogo'}{$img} = 1;
9384: }
9385: } else {
9386: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
9387: $changes{$role}{'showlogo'}{$img} = 1;
9388: }
9389: }
9390: }
9391: }
1.6 raeburn 9392: if ($domconfig->{$role}{'font'} ne '') {
9393: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
9394: $changes{$role}{'font'} = 1;
9395: }
9396: } else {
9397: if ($confhash->{$role}{'font'}) {
9398: $changes{$role}{'font'} = 1;
9399: }
9400: }
1.107 raeburn 9401: if ($role ne 'login') {
9402: if ($domconfig->{$role}{'fontmenu'} ne '') {
9403: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
9404: $changes{$role}{'fontmenu'} = 1;
9405: }
9406: } else {
9407: if ($confhash->{$role}{'fontmenu'}) {
9408: $changes{$role}{'fontmenu'} = 1;
9409: }
1.97 tempelho 9410: }
9411: }
1.6 raeburn 9412: foreach my $item (@bgs) {
9413: if ($domconfig->{$role}{$item} ne '') {
9414: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9415: $changes{$role}{'bgs'}{$item} = 1;
9416: }
9417: } else {
9418: if ($confhash->{$role}{$item}) {
9419: $changes{$role}{'bgs'}{$item} = 1;
9420: }
9421: }
9422: }
9423: foreach my $item (@links) {
9424: if ($domconfig->{$role}{$item} ne '') {
9425: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9426: $changes{$role}{'links'}{$item} = 1;
9427: }
9428: } else {
9429: if ($confhash->{$role}{$item}) {
9430: $changes{$role}{'links'}{$item} = 1;
9431: }
9432: }
9433: }
1.41 raeburn 9434: foreach my $item (@logintext) {
9435: if ($domconfig->{$role}{$item} ne '') {
9436: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9437: $changes{$role}{'logintext'}{$item} = 1;
9438: }
9439: } else {
9440: if ($confhash->{$role}{$item}) {
9441: $changes{$role}{'logintext'}{$item} = 1;
9442: }
9443: }
9444: }
1.6 raeburn 9445: } else {
9446: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 9447: \@logintext,$confhash,\%changes);
1.6 raeburn 9448: }
9449: } else {
9450: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 9451: \@logintext,$confhash,\%changes);
1.6 raeburn 9452: }
9453: }
9454: return ($errors,%changes);
9455: }
9456:
1.46 raeburn 9457: sub config_check {
9458: my ($dom,$confname,$servadm) = @_;
9459: my ($configuserok,$author_ok,$switchserver,%currroles);
9460: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
9461: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
9462: $confname,$servadm);
9463: if ($configuserok eq 'ok') {
9464: $switchserver = &check_switchserver($dom,$confname);
9465: if ($switchserver eq '') {
9466: $author_ok = &check_authorstatus($dom,$confname,%currroles);
9467: }
9468: }
9469: return ($configuserok,$author_ok,$switchserver);
9470: }
9471:
1.6 raeburn 9472: sub default_change_checker {
1.41 raeburn 9473: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 9474: foreach my $item (@{$links}) {
9475: if ($confhash->{$role}{$item}) {
9476: $changes->{$role}{'links'}{$item} = 1;
9477: }
9478: }
9479: foreach my $item (@{$bgs}) {
9480: if ($confhash->{$role}{$item}) {
9481: $changes->{$role}{'bgs'}{$item} = 1;
9482: }
9483: }
1.41 raeburn 9484: foreach my $item (@{$logintext}) {
9485: if ($confhash->{$role}{$item}) {
9486: $changes->{$role}{'logintext'}{$item} = 1;
9487: }
9488: }
1.6 raeburn 9489: foreach my $img (@{$images}) {
9490: if ($env{'form.'.$role.'_del_'.$img}) {
9491: $confhash->{$role}{$img} = '';
1.12 raeburn 9492: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 9493: }
1.70 raeburn 9494: if ($role eq 'login') {
9495: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
9496: $changes->{$role}{'showlogo'}{$img} = 1;
9497: }
9498: }
1.6 raeburn 9499: }
9500: if ($confhash->{$role}{'font'}) {
9501: $changes->{$role}{'font'} = 1;
9502: }
1.48 raeburn 9503: }
1.6 raeburn 9504:
9505: sub display_colorchgs {
9506: my ($dom,$changes,$roles,$confhash) = @_;
9507: my (%choices,$resulttext);
9508: if (!grep(/^login$/,@{$roles})) {
9509: $resulttext = &mt('Changes made:').'<br />';
9510: }
9511: foreach my $role (@{$roles}) {
9512: if ($role eq 'login') {
9513: %choices = &login_choices();
9514: } else {
9515: %choices = &color_font_choices();
9516: }
9517: if (ref($changes->{$role}) eq 'HASH') {
9518: if ($role ne 'login') {
9519: $resulttext .= '<h4>'.&mt($role).'</h4>';
9520: }
9521: foreach my $key (sort(keys(%{$changes->{$role}}))) {
9522: if ($role ne 'login') {
9523: $resulttext .= '<ul>';
9524: }
9525: if (ref($changes->{$role}{$key}) eq 'HASH') {
9526: if ($role ne 'login') {
9527: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
9528: }
9529: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 9530: if (($role eq 'login') && ($key eq 'showlogo')) {
9531: if ($confhash->{$role}{$key}{$item}) {
9532: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
9533: } else {
9534: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
9535: }
9536: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 9537: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
9538: } else {
1.12 raeburn 9539: my $newitem = $confhash->{$role}{$item};
9540: if ($key eq 'images') {
1.306 raeburn 9541: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 9542: }
9543: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 9544: }
9545: }
9546: if ($role ne 'login') {
9547: $resulttext .= '</ul></li>';
9548: }
9549: } else {
9550: if ($confhash->{$role}{$key} eq '') {
9551: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
9552: } else {
9553: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
9554: }
9555: }
9556: if ($role ne 'login') {
9557: $resulttext .= '</ul>';
9558: }
9559: }
9560: }
9561: }
1.3 raeburn 9562: return $resulttext;
1.1 raeburn 9563: }
9564:
1.9 raeburn 9565: sub thumb_dimensions {
9566: return ('200','50');
9567: }
9568:
1.16 raeburn 9569: sub check_dimensions {
9570: my ($inputfile) = @_;
9571: my ($fullwidth,$fullheight);
9572: if ($inputfile =~ m|^[/\w.\-]+$|) {
9573: if (open(PIPE,"identify $inputfile 2>&1 |")) {
9574: my $imageinfo = <PIPE>;
9575: if (!close(PIPE)) {
9576: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
9577: }
9578: chomp($imageinfo);
9579: my ($fullsize) =
1.21 raeburn 9580: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 9581: if ($fullsize) {
9582: ($fullwidth,$fullheight) = split(/x/,$fullsize);
9583: }
9584: }
9585: }
9586: return ($fullwidth,$fullheight);
9587: }
9588:
1.9 raeburn 9589: sub check_configuser {
9590: my ($uhome,$dom,$confname,$servadm) = @_;
9591: my ($configuserok,%currroles);
9592: if ($uhome eq 'no_host') {
9593: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
9594: my $configpass = &LONCAPA::Enrollment::create_password();
9595: $configuserok =
9596: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
9597: $configpass,'','','','','',undef,$servadm);
9598: } else {
9599: $configuserok = 'ok';
9600: %currroles =
9601: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
9602: }
9603: return ($configuserok,%currroles);
9604: }
9605:
9606: sub check_authorstatus {
9607: my ($dom,$confname,%currroles) = @_;
9608: my $author_ok;
1.40 raeburn 9609: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 9610: my $start = time;
9611: my $end = 0;
9612: $author_ok =
9613: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 9614: 'au',$end,$start,'','','domconfig');
1.9 raeburn 9615: } else {
9616: $author_ok = 'ok';
9617: }
9618: return $author_ok;
9619: }
9620:
9621: sub publishlogo {
1.46 raeburn 9622: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 9623: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 9624: if ($action eq 'upload') {
9625: $fname=$env{'form.'.$formname.'.filename'};
9626: chop($env{'form.'.$formname});
9627: } else {
9628: ($fname) = ($formname =~ /([^\/]+)$/);
9629: }
1.46 raeburn 9630: if ($savefileas ne '') {
9631: $fname = $savefileas;
9632: }
1.9 raeburn 9633: $fname=&Apache::lonnet::clean_filename($fname);
9634: # See if there is anything left
9635: unless ($fname) { return ('error: no uploaded file'); }
9636: $fname="$subdir/$fname";
1.210 raeburn 9637: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 9638: my $filepath="$docroot/priv";
9639: my $relpath = "$dom/$confname";
1.9 raeburn 9640: my ($fnamepath,$file,$fetchthumb);
9641: $file=$fname;
9642: if ($fname=~m|/|) {
9643: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
9644: }
1.164 raeburn 9645: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 9646: my $count;
1.164 raeburn 9647: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 9648: $filepath.="/$parts[$count]";
9649: if ((-e $filepath)!=1) {
9650: mkdir($filepath,02770);
9651: }
9652: }
9653: # Check for bad extension and disallow upload
9654: if ($file=~/\.(\w+)$/ &&
9655: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
9656: $output =
1.207 bisitz 9657: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 9658: } elsif ($file=~/\.(\w+)$/ &&
9659: !defined(&Apache::loncommon::fileembstyle($1))) {
9660: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
9661: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 9662: $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 9663: } elsif (-d "$filepath/$file") {
1.195 bisitz 9664: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 9665: } else {
9666: my $source = $filepath.'/'.$file;
9667: my $logfile;
1.316 raeburn 9668: if (!open($logfile,">>",$source.'.log')) {
1.196 raeburn 9669: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 9670: }
9671: print $logfile
9672: "\n================= Publish ".localtime()." ================\n".
9673: $env{'user.name'}.':'.$env{'user.domain'}."\n";
9674: # Save the file
1.316 raeburn 9675: if (!open(FH,">",$source)) {
1.9 raeburn 9676: &Apache::lonnet::logthis('Failed to create '.$source);
9677: return (&mt('Failed to create file'));
9678: }
9679: if ($action eq 'upload') {
9680: if (!print FH ($env{'form.'.$formname})) {
9681: &Apache::lonnet::logthis('Failed to write to '.$source);
9682: return (&mt('Failed to write file'));
9683: }
9684: } else {
9685: my $original = &Apache::lonnet::filelocation('',$formname);
9686: if(!copy($original,$source)) {
9687: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
9688: return (&mt('Failed to write file'));
9689: }
9690: }
9691: close(FH);
9692: chmod(0660, $source); # Permissions to rw-rw---.
9693:
9694: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
9695: my $copyfile=$targetdir.'/'.$file;
9696:
9697: my @parts=split(/\//,$targetdir);
9698: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
9699: for (my $count=5;$count<=$#parts;$count++) {
9700: $path.="/$parts[$count]";
9701: if (!-e $path) {
9702: print $logfile "\nCreating directory ".$path;
9703: mkdir($path,02770);
9704: }
9705: }
9706: my $versionresult;
9707: if (-e $copyfile) {
9708: $versionresult = &logo_versioning($targetdir,$file,$logfile);
9709: } else {
9710: $versionresult = 'ok';
9711: }
9712: if ($versionresult eq 'ok') {
9713: if (copy($source,$copyfile)) {
9714: print $logfile "\nCopied original source to ".$copyfile."\n";
9715: $output = 'ok';
9716: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 9717: push(@{$modified_urls},[$copyfile,$source]);
9718: my $metaoutput =
9719: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
9720: unless ($registered_cleanup) {
9721: my $handlers = $r->get_handlers('PerlCleanupHandler');
9722: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
9723: $registered_cleanup=1;
9724: }
1.9 raeburn 9725: } else {
9726: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
9727: $output = &mt('Failed to copy file to RES space').", $!";
9728: }
9729: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
9730: my $inputfile = $filepath.'/'.$file;
9731: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 9732: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
9733: if ($fullwidth ne '' && $fullheight ne '') {
9734: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
9735: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316 raeburn 9736: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
9737: system({$args[0]} @args);
1.16 raeburn 9738: chmod(0660, $filepath.'/tn-'.$file);
9739: if (-e $outfile) {
9740: my $copyfile=$targetdir.'/tn-'.$file;
9741: if (copy($outfile,$copyfile)) {
9742: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 9743: my $thumb_metaoutput =
9744: &write_metadata($dom,$confname,$formname,
9745: $targetdir,'tn-'.$file,$logfile);
9746: push(@{$modified_urls},[$copyfile,$outfile]);
9747: unless ($registered_cleanup) {
9748: my $handlers = $r->get_handlers('PerlCleanupHandler');
9749: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
9750: $registered_cleanup=1;
9751: }
1.267 raeburn 9752: $madethumb = 1;
1.16 raeburn 9753: } else {
9754: print $logfile "\nUnable to write ".$copyfile.
9755: ':'.$!."\n";
9756: }
9757: }
1.9 raeburn 9758: }
9759: }
9760: }
9761: } else {
9762: $output = $versionresult;
9763: }
9764: }
1.267 raeburn 9765: return ($output,$logourl,$madethumb);
1.9 raeburn 9766: }
9767:
9768: sub logo_versioning {
9769: my ($targetdir,$file,$logfile) = @_;
9770: my $target = $targetdir.'/'.$file;
9771: my ($maxversion,$fn,$extn,$output);
9772: $maxversion = 0;
9773: if ($file =~ /^(.+)\.(\w+)$/) {
9774: $fn=$1;
9775: $extn=$2;
9776: }
9777: opendir(DIR,$targetdir);
9778: while (my $filename=readdir(DIR)) {
9779: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
9780: $maxversion=($1>$maxversion)?$1:$maxversion;
9781: }
9782: }
9783: $maxversion++;
9784: print $logfile "\nCreating old version ".$maxversion."\n";
9785: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
9786: if (copy($target,$copyfile)) {
9787: print $logfile "Copied old target to ".$copyfile."\n";
9788: $copyfile=$copyfile.'.meta';
9789: if (copy($target.'.meta',$copyfile)) {
9790: print $logfile "Copied old target metadata to ".$copyfile."\n";
9791: $output = 'ok';
9792: } else {
9793: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
9794: $output = &mt('Failed to copy old meta').", $!, ";
9795: }
9796: } else {
9797: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
9798: $output = &mt('Failed to copy old target').", $!, ";
9799: }
9800: return $output;
9801: }
9802:
9803: sub write_metadata {
9804: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
9805: my (%metadatafields,%metadatakeys,$output);
9806: $metadatafields{'title'}=$formname;
9807: $metadatafields{'creationdate'}=time;
9808: $metadatafields{'lastrevisiondate'}=time;
9809: $metadatafields{'copyright'}='public';
9810: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
9811: $env{'user.domain'};
9812: $metadatafields{'authorspace'}=$confname.':'.$dom;
9813: $metadatafields{'domain'}=$dom;
9814: {
9815: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
9816: my $mfh;
1.316 raeburn 9817: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 9818: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 9819: unless ($_=~/\./) {
9820: my $unikey=$_;
9821: $unikey=~/^([A-Za-z]+)/;
9822: my $tag=$1;
9823: $tag=~tr/A-Z/a-z/;
9824: print $mfh "\n\<$tag";
9825: foreach (split(/\,/,$metadatakeys{$unikey})) {
9826: my $value=$metadatafields{$unikey.'.'.$_};
9827: $value=~s/\"/\'\'/g;
9828: print $mfh ' '.$_.'="'.$value.'"';
9829: }
9830: print $mfh '>'.
9831: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
9832: .'</'.$tag.'>';
9833: }
9834: }
9835: $output = 'ok';
9836: print $logfile "\nWrote metadata";
9837: close($mfh);
9838: } else {
9839: print $logfile "\nFailed to open metadata file";
1.9 raeburn 9840: $output = &mt('Could not write metadata');
9841: }
9842: }
1.155 raeburn 9843: return $output;
9844: }
9845:
9846: sub notifysubscribed {
9847: foreach my $targetsource (@{$modified_urls}){
9848: next unless (ref($targetsource) eq 'ARRAY');
9849: my ($target,$source)=@{$targetsource};
9850: if ($source ne '') {
1.316 raeburn 9851: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 9852: print $logfh "\nCleanup phase: Notifications\n";
9853: my @subscribed=&subscribed_hosts($target);
9854: foreach my $subhost (@subscribed) {
9855: print $logfh "\nNotifying host ".$subhost.':';
9856: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
9857: print $logfh $reply;
9858: }
9859: my @subscribedmeta=&subscribed_hosts("$target.meta");
9860: foreach my $subhost (@subscribedmeta) {
9861: print $logfh "\nNotifying host for metadata only ".$subhost.':';
9862: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
9863: $subhost);
9864: print $logfh $reply;
9865: }
9866: print $logfh "\n============ Done ============\n";
1.160 raeburn 9867: close($logfh);
1.155 raeburn 9868: }
9869: }
9870: }
9871: return OK;
9872: }
9873:
9874: sub subscribed_hosts {
9875: my ($target) = @_;
9876: my @subscribed;
1.316 raeburn 9877: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 9878: while (my $subline=<$fh>) {
9879: if ($subline =~ /^($match_lonid):/) {
9880: my $host = $1;
9881: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
9882: unless (grep(/^\Q$host\E$/,@subscribed)) {
9883: push(@subscribed,$host);
9884: }
9885: }
9886: }
9887: }
9888: }
9889: return @subscribed;
1.9 raeburn 9890: }
9891:
9892: sub check_switchserver {
9893: my ($dom,$confname) = @_;
9894: my ($allowed,$switchserver);
9895: my $home = &Apache::lonnet::homeserver($confname,$dom);
9896: if ($home eq 'no_host') {
9897: $home = &Apache::lonnet::domain($dom,'primary');
9898: }
9899: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 9900: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
9901: if (!$allowed) {
1.180 raeburn 9902: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 9903: }
9904: return $switchserver;
9905: }
9906:
1.1 raeburn 9907: sub modify_quotas {
1.216 raeburn 9908: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 9909: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 9910: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 9911: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
9912: $validationfieldsref);
1.86 raeburn 9913: if ($action eq 'quotas') {
9914: $context = 'tools';
1.163 raeburn 9915: } else {
1.86 raeburn 9916: $context = $action;
9917: }
9918: if ($context eq 'requestcourses') {
1.271 raeburn 9919: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 9920: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 9921: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
9922: %titles = &courserequest_titles();
9923: $toolregexp = join('|',@usertools);
9924: %conditions = &courserequest_conditions();
1.216 raeburn 9925: $confname = $dom.'-domainconfig';
9926: my $servadm = $r->dir_config('lonAdmEMail');
9927: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 9928: ($validationitemsref,$validationnamesref,$validationfieldsref) =
9929: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 9930: } elsif ($context eq 'requestauthor') {
9931: @usertools = ('author');
9932: %titles = &authorrequest_titles();
1.86 raeburn 9933: } else {
1.162 raeburn 9934: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 9935: %titles = &tool_titles();
1.86 raeburn 9936: }
1.212 raeburn 9937: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 9938: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 9939: foreach my $key (keys(%env)) {
1.101 raeburn 9940: if ($context eq 'requestcourses') {
9941: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
9942: my $item = $1;
9943: my $type = $2;
9944: if ($type =~ /^limit_(.+)/) {
9945: $limithash{$item}{$1} = $env{$key};
9946: } else {
9947: $confhash{$item}{$type} = $env{$key};
9948: }
9949: }
1.163 raeburn 9950: } elsif ($context eq 'requestauthor') {
9951: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
9952: $confhash{$1} = $env{$key};
9953: }
1.101 raeburn 9954: } else {
1.86 raeburn 9955: if ($key =~ /^form\.quota_(.+)$/) {
9956: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 9957: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
9958: $confhash{'authorquota'}{$1} = $env{$key};
9959: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 9960: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
9961: }
1.72 raeburn 9962: }
9963: }
1.163 raeburn 9964: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 9965: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 9966: @approvalnotify = sort(@approvalnotify);
9967: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.271 raeburn 9968: my @crstypes = ('official','unofficial','community','textbook','placement');
1.218 raeburn 9969: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
9970: foreach my $type (@hasuniquecode) {
9971: if (grep(/^\Q$type\E$/,@crstypes)) {
9972: $confhash{'uniquecode'}{$type} = 1;
9973: }
1.216 raeburn 9974: }
1.242 raeburn 9975: my (%newbook,%allpos);
1.216 raeburn 9976: if ($context eq 'requestcourses') {
1.242 raeburn 9977: foreach my $type ('textbooks','templates') {
9978: @{$allpos{$type}} = ();
9979: my $invalid;
9980: if ($type eq 'textbooks') {
9981: $invalid = &mt('Invalid LON-CAPA course for textbook');
9982: } else {
9983: $invalid = &mt('Invalid LON-CAPA course for template');
9984: }
9985: if ($env{'form.'.$type.'_addbook'}) {
9986: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
9987: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
9988: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
9989: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
9990: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
9991: } else {
9992: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
9993: my $position = $env{'form.'.$type.'_addbook_pos'};
9994: $position =~ s/\D+//g;
9995: if ($position ne '') {
9996: $allpos{$type}[$position] = $newbook{$type};
9997: }
1.216 raeburn 9998: }
1.242 raeburn 9999: } else {
10000: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 10001: }
10002: }
1.242 raeburn 10003: }
1.216 raeburn 10004: }
1.102 raeburn 10005: if (ref($domconfig{$action}) eq 'HASH') {
10006: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
10007: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
10008: $changes{'notify'}{'approval'} = 1;
10009: }
10010: } else {
1.144 raeburn 10011: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10012: $changes{'notify'}{'approval'} = 1;
10013: }
10014: }
1.218 raeburn 10015: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
10016: if (ref($confhash{'uniquecode'}) eq 'HASH') {
10017: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
10018: unless ($confhash{'uniquecode'}{$crstype}) {
10019: $changes{'uniquecode'} = 1;
10020: }
10021: }
10022: unless ($changes{'uniquecode'}) {
10023: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
10024: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
10025: $changes{'uniquecode'} = 1;
10026: }
10027: }
10028: }
10029: } else {
10030: $changes{'uniquecode'} = 1;
10031: }
10032: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
10033: $changes{'uniquecode'} = 1;
1.216 raeburn 10034: }
10035: if ($context eq 'requestcourses') {
1.242 raeburn 10036: foreach my $type ('textbooks','templates') {
10037: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10038: my %deletions;
10039: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
10040: if (@todelete) {
10041: map { $deletions{$_} = 1; } @todelete;
10042: }
10043: my %imgdeletions;
10044: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
10045: if (@todeleteimages) {
10046: map { $imgdeletions{$_} = 1; } @todeleteimages;
10047: }
10048: my $maxnum = $env{'form.'.$type.'_maxnum'};
10049: for (my $i=0; $i<=$maxnum; $i++) {
10050: my $itemid = $env{'form.'.$type.'_id_'.$i};
10051: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
10052: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
10053: if ($deletions{$key}) {
10054: if ($domconfig{$action}{$type}{$key}{'image'}) {
10055: #FIXME need to obsolete item in RES space
10056: }
10057: next;
10058: } else {
10059: my $newpos = $env{'form.'.$itemid};
10060: $newpos =~ s/\D+//g;
1.243 raeburn 10061: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 10062: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 10063: ($type eq 'templates'));
1.242 raeburn 10064: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
10065: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
10066: $changes{$type}{$key} = 1;
10067: }
10068: }
10069: $allpos{$type}[$newpos] = $key;
10070: }
10071: if ($imgdeletions{$key}) {
10072: $changes{$type}{$key} = 1;
1.216 raeburn 10073: #FIXME need to obsolete item in RES space
1.242 raeburn 10074: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
10075: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 10076: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10077: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10078: } else {
10079: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
10080: $cdom,$cnum,$type,$configuserok,
10081: $switchserver,$author_ok);
10082: if ($imgurl) {
10083: $confhash{$type}{$key}{'image'} = $imgurl;
10084: $changes{$type}{$key} = 1;
10085: }
10086: if ($error) {
10087: &Apache::lonnet::logthis($error);
10088: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10089: }
10090: }
1.242 raeburn 10091: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
10092: $confhash{$type}{$key}{'image'} =
10093: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 10094: }
10095: }
10096: }
10097: }
10098: }
10099: }
1.102 raeburn 10100: } else {
1.144 raeburn 10101: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10102: $changes{'notify'}{'approval'} = 1;
10103: }
1.218 raeburn 10104: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 10105: $changes{'uniquecode'} = 1;
10106: }
10107: }
10108: if ($context eq 'requestcourses') {
1.242 raeburn 10109: foreach my $type ('textbooks','templates') {
10110: if ($newbook{$type}) {
10111: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 10112: foreach my $item ('subject','title','publisher','author') {
10113: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10114: ($type eq 'template'));
1.242 raeburn 10115: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
10116: if ($env{'form.'.$type.'_addbook_'.$item}) {
10117: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
10118: }
10119: }
10120: if ($type eq 'textbooks') {
10121: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
10122: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 10123: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10124: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10125: } else {
10126: my ($imageurl,$error) =
10127: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
10128: $configuserok,$switchserver,$author_ok);
10129: if ($imageurl) {
10130: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
10131: }
10132: if ($error) {
10133: &Apache::lonnet::logthis($error);
10134: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10135: }
1.242 raeburn 10136: }
10137: }
1.216 raeburn 10138: }
10139: }
1.242 raeburn 10140: if (@{$allpos{$type}} > 0) {
10141: my $idx = 0;
10142: foreach my $item (@{$allpos{$type}}) {
10143: if ($item ne '') {
10144: $confhash{$type}{$item}{'order'} = $idx;
10145: if (ref($domconfig{$action}) eq 'HASH') {
10146: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10147: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
10148: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
10149: $changes{$type}{$item} = 1;
10150: }
1.216 raeburn 10151: }
10152: }
10153: }
1.242 raeburn 10154: $idx ++;
1.216 raeburn 10155: }
10156: }
10157: }
10158: }
1.235 raeburn 10159: if (ref($validationitemsref) eq 'ARRAY') {
10160: foreach my $item (@{$validationitemsref}) {
10161: if ($item eq 'fields') {
10162: my @changed;
10163: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
10164: if (@{$confhash{'validation'}{$item}} > 0) {
10165: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
10166: }
1.266 raeburn 10167: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10168: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10169: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
10170: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
10171: $domconfig{'requestcourses'}{'validation'}{$item});
10172: } else {
10173: @changed = @{$confhash{'validation'}{$item}};
10174: }
1.235 raeburn 10175: } else {
10176: @changed = @{$confhash{'validation'}{$item}};
10177: }
10178: } else {
10179: @changed = @{$confhash{'validation'}{$item}};
10180: }
10181: if (@changed) {
10182: if ($confhash{'validation'}{$item}) {
10183: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
10184: } else {
10185: $changes{'validation'}{$item} = &mt('None');
10186: }
10187: }
10188: } else {
10189: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
10190: if ($item eq 'markup') {
10191: if ($env{'form.requestcourses_validation_'.$item}) {
10192: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10193: }
10194: }
1.266 raeburn 10195: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10196: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10197: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
10198: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10199: }
10200: } else {
10201: if ($confhash{'validation'}{$item} ne '') {
10202: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10203: }
1.235 raeburn 10204: }
10205: } else {
10206: if ($confhash{'validation'}{$item} ne '') {
10207: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10208: }
10209: }
10210: }
10211: }
10212: }
10213: if ($env{'form.validationdc'}) {
10214: my $newval = $env{'form.validationdc'};
1.285 raeburn 10215: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 10216: if (exists($domcoords{$newval})) {
10217: $confhash{'validation'}{'dc'} = $newval;
10218: }
10219: }
10220: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 10221: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10222: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10223: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10224: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
10225: if ($confhash{'validation'}{'dc'} eq '') {
10226: $changes{'validation'}{'dc'} = &mt('None');
10227: } else {
10228: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10229: }
1.235 raeburn 10230: }
1.266 raeburn 10231: } elsif ($confhash{'validation'}{'dc'} ne '') {
10232: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 10233: }
10234: } elsif ($confhash{'validation'}{'dc'} ne '') {
10235: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10236: }
10237: } elsif ($confhash{'validation'}{'dc'} ne '') {
10238: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 10239: }
1.266 raeburn 10240: } else {
10241: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10242: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10243: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10244: $changes{'validation'}{'dc'} = &mt('None');
10245: }
10246: }
1.235 raeburn 10247: }
10248: }
1.102 raeburn 10249: }
10250: } else {
1.86 raeburn 10251: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 10252: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 10253: }
1.72 raeburn 10254: foreach my $item (@usertools) {
10255: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 10256: my $unset;
1.101 raeburn 10257: if ($context eq 'requestcourses') {
1.104 raeburn 10258: $unset = '0';
10259: if ($type eq '_LC_adv') {
10260: $unset = '';
10261: }
1.101 raeburn 10262: if ($confhash{$item}{$type} eq 'autolimit') {
10263: $confhash{$item}{$type} .= '=';
10264: unless ($limithash{$item}{$type} =~ /\D/) {
10265: $confhash{$item}{$type} .= $limithash{$item}{$type};
10266: }
10267: }
1.163 raeburn 10268: } elsif ($context eq 'requestauthor') {
10269: $unset = '0';
10270: if ($type eq '_LC_adv') {
10271: $unset = '';
10272: }
1.72 raeburn 10273: } else {
1.101 raeburn 10274: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
10275: $confhash{$item}{$type} = 1;
10276: } else {
10277: $confhash{$item}{$type} = 0;
10278: }
1.72 raeburn 10279: }
1.86 raeburn 10280: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 10281: if ($action eq 'requestauthor') {
10282: if ($domconfig{$action}{$type} ne $confhash{$type}) {
10283: $changes{$type} = 1;
10284: }
10285: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 10286: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
10287: $changes{$item}{$type} = 1;
10288: }
10289: } else {
10290: if ($context eq 'requestcourses') {
1.104 raeburn 10291: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 10292: $changes{$item}{$type} = 1;
10293: }
10294: } else {
10295: if (!$confhash{$item}{$type}) {
10296: $changes{$item}{$type} = 1;
10297: }
10298: }
10299: }
10300: } else {
10301: if ($context eq 'requestcourses') {
1.104 raeburn 10302: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 10303: $changes{$item}{$type} = 1;
10304: }
1.163 raeburn 10305: } elsif ($context eq 'requestauthor') {
10306: if ($confhash{$type} ne $unset) {
10307: $changes{$type} = 1;
10308: }
1.72 raeburn 10309: } else {
10310: if (!$confhash{$item}{$type}) {
10311: $changes{$item}{$type} = 1;
10312: }
10313: }
10314: }
1.1 raeburn 10315: }
10316: }
1.163 raeburn 10317: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 10318: if (ref($domconfig{'quotas'}) eq 'HASH') {
10319: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
10320: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
10321: if (exists($confhash{'defaultquota'}{$key})) {
10322: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
10323: $changes{'defaultquota'}{$key} = 1;
10324: }
10325: } else {
10326: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 10327: }
10328: }
1.86 raeburn 10329: } else {
10330: foreach my $key (keys(%{$domconfig{'quotas'}})) {
10331: if (exists($confhash{'defaultquota'}{$key})) {
10332: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
10333: $changes{'defaultquota'}{$key} = 1;
10334: }
10335: } else {
10336: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 10337: }
1.1 raeburn 10338: }
10339: }
1.197 raeburn 10340: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
10341: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
10342: if (exists($confhash{'authorquota'}{$key})) {
10343: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
10344: $changes{'authorquota'}{$key} = 1;
10345: }
10346: } else {
10347: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
10348: }
10349: }
10350: }
1.1 raeburn 10351: }
1.86 raeburn 10352: if (ref($confhash{'defaultquota'}) eq 'HASH') {
10353: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
10354: if (ref($domconfig{'quotas'}) eq 'HASH') {
10355: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
10356: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
10357: $changes{'defaultquota'}{$key} = 1;
10358: }
10359: } else {
10360: if (!exists($domconfig{'quotas'}{$key})) {
10361: $changes{'defaultquota'}{$key} = 1;
10362: }
1.72 raeburn 10363: }
10364: } else {
1.86 raeburn 10365: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 10366: }
1.1 raeburn 10367: }
10368: }
1.197 raeburn 10369: if (ref($confhash{'authorquota'}) eq 'HASH') {
10370: foreach my $key (keys(%{$confhash{'authorquota'}})) {
10371: if (ref($domconfig{'quotas'}) eq 'HASH') {
10372: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
10373: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
10374: $changes{'authorquota'}{$key} = 1;
10375: }
10376: } else {
10377: $changes{'authorquota'}{$key} = 1;
10378: }
10379: } else {
10380: $changes{'authorquota'}{$key} = 1;
10381: }
10382: }
10383: }
1.1 raeburn 10384: }
1.72 raeburn 10385:
1.163 raeburn 10386: if ($context eq 'requestauthor') {
10387: $domdefaults{'requestauthor'} = \%confhash;
10388: } else {
10389: foreach my $key (keys(%confhash)) {
1.242 raeburn 10390: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 10391: $domdefaults{$key} = $confhash{$key};
10392: }
1.163 raeburn 10393: }
1.72 raeburn 10394: }
1.163 raeburn 10395:
1.1 raeburn 10396: my %quotahash = (
1.86 raeburn 10397: $action => { %confhash }
1.1 raeburn 10398: );
10399: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
10400: $dom);
10401: if ($putresult eq 'ok') {
10402: if (keys(%changes) > 0) {
1.72 raeburn 10403: my $cachetime = 24*60*60;
10404: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 10405: if (ref($lastactref) eq 'HASH') {
10406: $lastactref->{'domdefaults'} = 1;
10407: }
1.1 raeburn 10408: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 10409: unless (($context eq 'requestcourses') ||
1.163 raeburn 10410: ($context eq 'requestauthor')) {
1.86 raeburn 10411: if (ref($changes{'defaultquota'}) eq 'HASH') {
10412: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
10413: foreach my $type (@{$types},'default') {
10414: if (defined($changes{'defaultquota'}{$type})) {
10415: my $typetitle = $usertypes->{$type};
10416: if ($type eq 'default') {
10417: $typetitle = $othertitle;
10418: }
1.213 raeburn 10419: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 10420: }
10421: }
1.86 raeburn 10422: $resulttext .= '</ul></li>';
1.72 raeburn 10423: }
1.197 raeburn 10424: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 10425: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 10426: foreach my $type (@{$types},'default') {
10427: if (defined($changes{'authorquota'}{$type})) {
10428: my $typetitle = $usertypes->{$type};
10429: if ($type eq 'default') {
10430: $typetitle = $othertitle;
10431: }
1.213 raeburn 10432: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 10433: }
10434: }
10435: $resulttext .= '</ul></li>';
10436: }
1.72 raeburn 10437: }
1.80 raeburn 10438: my %newenv;
1.72 raeburn 10439: foreach my $item (@usertools) {
1.163 raeburn 10440: my (%haschgs,%inconf);
10441: if ($context eq 'requestauthor') {
10442: %haschgs = %changes;
1.210 raeburn 10443: %inconf = %confhash;
1.163 raeburn 10444: } else {
10445: if (ref($changes{$item}) eq 'HASH') {
10446: %haschgs = %{$changes{$item}};
10447: }
10448: if (ref($confhash{$item}) eq 'HASH') {
10449: %inconf = %{$confhash{$item}};
10450: }
10451: }
10452: if (keys(%haschgs) > 0) {
1.80 raeburn 10453: my $newacc =
10454: &Apache::lonnet::usertools_access($env{'user.name'},
10455: $env{'user.domain'},
1.86 raeburn 10456: $item,'reload',$context);
1.210 raeburn 10457: if (($context eq 'requestcourses') ||
1.163 raeburn 10458: ($context eq 'requestauthor')) {
1.108 raeburn 10459: if ($env{'environment.canrequest.'.$item} ne $newacc) {
10460: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 10461: }
10462: } else {
10463: if ($env{'environment.availabletools.'.$item} ne $newacc) {
10464: $newenv{'environment.availabletools.'.$item} = $newacc;
10465: }
1.80 raeburn 10466: }
1.163 raeburn 10467: unless ($context eq 'requestauthor') {
10468: $resulttext .= '<li>'.$titles{$item}.'<ul>';
10469: }
1.72 raeburn 10470: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 10471: if ($haschgs{$type}) {
1.72 raeburn 10472: my $typetitle = $usertypes->{$type};
10473: if ($type eq 'default') {
10474: $typetitle = $othertitle;
10475: } elsif ($type eq '_LC_adv') {
10476: $typetitle = 'LON-CAPA Advanced Users';
10477: }
1.163 raeburn 10478: if ($inconf{$type}) {
1.101 raeburn 10479: if ($context eq 'requestcourses') {
10480: my $cond;
1.163 raeburn 10481: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 10482: if ($1 eq '') {
10483: $cond = &mt('(Automatic processing of any request).');
10484: } else {
10485: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
10486: }
10487: } else {
1.163 raeburn 10488: $cond = $conditions{$inconf{$type}};
1.101 raeburn 10489: }
10490: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 10491: } elsif ($context eq 'requestauthor') {
10492: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
10493: $titles{$inconf{$type}},$typetitle);
10494:
1.101 raeburn 10495: } else {
10496: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
10497: }
1.72 raeburn 10498: } else {
1.104 raeburn 10499: if ($type eq '_LC_adv') {
1.163 raeburn 10500: if ($inconf{$type} eq '0') {
1.104 raeburn 10501: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
10502: } else {
10503: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
10504: }
10505: } else {
10506: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
10507: }
1.72 raeburn 10508: }
10509: }
1.26 raeburn 10510: }
1.163 raeburn 10511: unless ($context eq 'requestauthor') {
10512: $resulttext .= '</ul></li>';
10513: }
1.26 raeburn 10514: }
1.1 raeburn 10515: }
1.163 raeburn 10516: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 10517: if (ref($changes{'notify'}) eq 'HASH') {
10518: if ($changes{'notify'}{'approval'}) {
10519: if (ref($confhash{'notify'}) eq 'HASH') {
10520: if ($confhash{'notify'}{'approval'}) {
10521: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
10522: } else {
1.163 raeburn 10523: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 10524: }
10525: }
10526: }
10527: }
10528: }
1.216 raeburn 10529: if ($action eq 'requestcourses') {
10530: my @offon = ('off','on');
10531: if ($changes{'uniquecode'}) {
1.218 raeburn 10532: if (ref($confhash{'uniquecode'}) eq 'HASH') {
10533: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
10534: $resulttext .= '<li>'.
10535: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
10536: '</li>';
10537: } else {
10538: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
10539: '</li>';
10540: }
1.216 raeburn 10541: }
1.242 raeburn 10542: foreach my $type ('textbooks','templates') {
10543: if (ref($changes{$type}) eq 'HASH') {
10544: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
10545: foreach my $key (sort(keys(%{$changes{$type}}))) {
10546: my %coursehash = &Apache::lonnet::coursedescription($key);
10547: my $coursetitle = $coursehash{'description'};
10548: my $position = $confhash{$type}{$key}{'order'} + 1;
10549: $resulttext .= '<li>';
1.243 raeburn 10550: foreach my $item ('subject','title','publisher','author') {
10551: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10552: ($type eq 'templates'));
1.242 raeburn 10553: my $name = $item.':';
10554: $name =~ s/^(\w)/\U$1/;
10555: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
10556: }
10557: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
10558: if ($type eq 'textbooks') {
10559: if ($confhash{$type}{$key}{'image'}) {
10560: $resulttext .= ' '.&mt('Image: [_1]',
10561: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
10562: ' alt="Textbook cover" />').'<br />';
10563: }
10564: }
10565: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 10566: }
1.242 raeburn 10567: $resulttext .= '</ul></li>';
1.216 raeburn 10568: }
10569: }
1.235 raeburn 10570: if (ref($changes{'validation'}) eq 'HASH') {
10571: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
10572: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
10573: foreach my $item (@{$validationitemsref}) {
10574: if (exists($changes{'validation'}{$item})) {
10575: if ($item eq 'markup') {
10576: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
10577: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
10578: } else {
10579: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
10580: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
10581: }
10582: }
10583: }
10584: if (exists($changes{'validation'}{'dc'})) {
10585: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
10586: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
10587: }
10588: }
10589: }
1.216 raeburn 10590: }
1.1 raeburn 10591: $resulttext .= '</ul>';
1.80 raeburn 10592: if (keys(%newenv)) {
10593: &Apache::lonnet::appenv(\%newenv);
10594: }
1.1 raeburn 10595: } else {
1.86 raeburn 10596: if ($context eq 'requestcourses') {
10597: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 10598: } elsif ($context eq 'requestauthor') {
10599: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 10600: } else {
1.90 weissno 10601: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 10602: }
1.1 raeburn 10603: }
10604: } else {
1.11 albertel 10605: $resulttext = '<span class="LC_error">'.
10606: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10607: }
1.216 raeburn 10608: if ($errors) {
10609: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
10610: '<ul>'.$errors.'</ul></p>';
10611: }
1.3 raeburn 10612: return $resulttext;
1.1 raeburn 10613: }
10614:
1.216 raeburn 10615: sub process_textbook_image {
1.242 raeburn 10616: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 10617: my $filename = $env{'form.'.$caller.'.filename'};
10618: my ($error,$url);
10619: my ($width,$height) = (50,50);
10620: if ($configuserok eq 'ok') {
10621: if ($switchserver) {
10622: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
10623: $switchserver);
10624: } elsif ($author_ok eq 'ok') {
10625: my ($result,$imageurl) =
10626: &publishlogo($r,'upload',$caller,$dom,$confname,
1.312 raeburn 10627: "$type/$cdom/$cnum/cover",$width,$height);
1.216 raeburn 10628: if ($result eq 'ok') {
10629: $url = $imageurl;
10630: } else {
10631: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
10632: }
10633: } else {
10634: $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);
10635: }
10636: } else {
10637: $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);
10638: }
10639: return ($url,$error);
10640: }
10641:
1.267 raeburn 10642: sub modify_ltitools {
10643: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
10644: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 10645: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 10646: my $confname = $dom.'-domainconfig';
10647: my $servadm = $r->dir_config('lonAdmEMail');
10648: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10649: my (%posslti,%possfield);
10650: my @courseroles = ('cc','in','ta','ep','st');
10651: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
10652: map { $posslti{$_} = 1; } @ltiroles;
10653: my @allfields = ('fullname','firstname','lastname','email','user','roles');
10654: map { $possfield{$_} = 1; } @allfields;
10655: my %lt = <itools_names();
10656: if ($env{'form.ltitools_add'}) {
10657: my $title = $env{'form.ltitools_add_title'};
10658: $title =~ s/(`)/'/g;
10659: ($newid,my $error) = &get_ltitools_id($dom,$title);
10660: if ($newid) {
10661: my $position = $env{'form.ltitools_add_pos'};
10662: $position =~ s/\D+//g;
10663: if ($position ne '') {
10664: $allpos[$position] = $newid;
10665: }
10666: $changes{$newid} = 1;
1.322 raeburn 10667: foreach my $item ('title','url','key','secret','lifetime') {
1.267 raeburn 10668: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1.322 raeburn 10669: if ($item eq 'lifetime') {
10670: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
10671: }
1.267 raeburn 10672: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 10673: if (($item eq 'key') || ($item eq 'secret')) {
10674: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
10675: } else {
10676: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
10677: }
1.267 raeburn 10678: }
10679: }
10680: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
10681: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
10682: }
10683: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
10684: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
10685: }
1.323 ! raeburn 10686: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
! 10687: $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
! 10688: } else {
! 10689: $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
! 10690: }
1.296 raeburn 10691: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 10692: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
10693: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 10694: if (($item eq 'width') || ($item eq 'height')) {
10695: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
10696: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
10697: }
10698: } else {
10699: if ($env{'form.ltitools_add_'.$item} ne '') {
10700: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
10701: }
1.267 raeburn 10702: }
10703: }
10704: if ($env{'form.ltitools_add_target'} eq 'window') {
10705: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 10706: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
10707: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 10708: } else {
10709: $confhash{$newid}{'display'}{'target'} = 'iframe';
10710: }
10711: foreach my $item ('passback','roster') {
1.319 raeburn 10712: if ($env{'form.ltitools_'.$item.'_add'}) {
1.267 raeburn 10713: $confhash{$newid}{$item} = 1;
1.319 raeburn 10714: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
10715: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
10716: $lifetime =~ s/^\s+|\s+$//g;
10717: if ($lifetime =~ /^\d+\.?\d*$/) {
10718: $confhash{$newid}{$item.'valid'} = $lifetime;
10719: }
10720: }
1.267 raeburn 10721: }
10722: }
10723: if ($env{'form.ltitools_add_image.filename'} ne '') {
10724: my ($imageurl,$error) =
1.307 raeburn 10725: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267 raeburn 10726: $configuserok,$switchserver,$author_ok);
10727: if ($imageurl) {
10728: $confhash{$newid}{'image'} = $imageurl;
10729: }
10730: if ($error) {
10731: &Apache::lonnet::logthis($error);
10732: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10733: }
10734: }
10735: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
10736: foreach my $field (@fields) {
10737: if ($possfield{$field}) {
10738: if ($field eq 'roles') {
10739: foreach my $role (@courseroles) {
10740: my $choice = $env{'form.ltitools_add_roles_'.$role};
10741: if (($choice ne '') && ($posslti{$choice})) {
10742: $confhash{$newid}{'roles'}{$role} = $choice;
10743: if ($role eq 'cc') {
10744: $confhash{$newid}{'roles'}{'co'} = $choice;
10745: }
10746: }
10747: }
10748: } else {
10749: $confhash{$newid}{'fields'}{$field} = 1;
10750: }
10751: }
10752: }
1.273 raeburn 10753: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
10754: foreach my $item (@courseconfig) {
10755: $confhash{$newid}{'crsconf'}{$item} = 1;
10756: }
1.267 raeburn 10757: if ($env{'form.ltitools_add_custom'}) {
10758: my $name = $env{'form.ltitools_add_custom_name'};
10759: my $value = $env{'form.ltitools_add_custom_value'};
10760: $value =~ s/(`)/'/g;
10761: $name =~ s/(`)/'/g;
10762: $confhash{$newid}{'custom'}{$name} = $value;
10763: }
10764: } else {
10765: my $error = &mt('Failed to acquire unique ID for new external tool');
10766: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10767: }
10768: }
10769: if (ref($domconfig{$action}) eq 'HASH') {
10770: my %deletions;
10771: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
10772: if (@todelete) {
10773: map { $deletions{$_} = 1; } @todelete;
10774: }
10775: my %customadds;
10776: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
10777: if (@newcustom) {
10778: map { $customadds{$_} = 1; } @newcustom;
10779: }
10780: my %imgdeletions;
10781: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
10782: if (@todeleteimages) {
10783: map { $imgdeletions{$_} = 1; } @todeleteimages;
10784: }
10785: my $maxnum = $env{'form.ltitools_maxnum'};
10786: for (my $i=0; $i<=$maxnum; $i++) {
10787: my $itemid = $env{'form.ltitools_id_'.$i};
1.308 raeburn 10788: $itemid =~ s/\D+//g;
1.267 raeburn 10789: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
10790: if ($deletions{$itemid}) {
10791: if ($domconfig{$action}{$itemid}{'image'}) {
10792: #FIXME need to obsolete item in RES space
10793: }
10794: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
10795: next;
10796: } else {
10797: my $newpos = $env{'form.ltitools_'.$itemid};
10798: $newpos =~ s/\D+//g;
1.322 raeburn 10799: foreach my $item ('title','url','lifetime') {
1.267 raeburn 10800: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
10801: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
10802: $changes{$itemid} = 1;
10803: }
10804: }
1.297 raeburn 10805: foreach my $item ('key','secret') {
10806: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
10807: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
10808: $changes{$itemid} = 1;
10809: }
10810: }
1.267 raeburn 10811: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
10812: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
10813: }
10814: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
10815: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
10816: }
1.323 ! raeburn 10817: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
! 10818: $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
! 10819: } else {
! 10820: $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
! 10821: }
! 10822: if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
! 10823: if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
! 10824: $changes{$itemid} = 1;
! 10825: }
! 10826: } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
! 10827: $changes{$itemid} = 1;
! 10828: }
1.267 raeburn 10829: foreach my $size ('width','height') {
10830: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
10831: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
10832: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
10833: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
10834: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10835: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
10836: $changes{$itemid} = 1;
10837: }
10838: } else {
10839: $changes{$itemid} = 1;
10840: }
1.296 raeburn 10841: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10842: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
10843: $changes{$itemid} = 1;
10844: }
10845: }
10846: }
10847: foreach my $item ('linktext','explanation') {
10848: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
10849: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
10850: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
10851: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
10852: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10853: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
10854: $changes{$itemid} = 1;
10855: }
10856: } else {
10857: $changes{$itemid} = 1;
10858: }
10859: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10860: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
10861: $changes{$itemid} = 1;
10862: }
1.267 raeburn 10863: }
10864: }
10865: if ($env{'form.ltitools_target_'.$i} eq 'window') {
10866: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 10867: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
10868: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 10869: } else {
10870: $confhash{$itemid}{'display'}{'target'} = 'iframe';
10871: }
10872: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10873: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
10874: $changes{$itemid} = 1;
10875: }
10876: } else {
10877: $changes{$itemid} = 1;
10878: }
10879: foreach my $extra ('passback','roster') {
10880: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
10881: $confhash{$itemid}{$extra} = 1;
1.319 raeburn 10882: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
10883: my $lifetime = $env{'form.ltitools_'.$extra.'valid_add'};
10884: $lifetime =~ s/^\s+|\s+$//g;
10885: if ($lifetime =~ /^\d+\.?\d*$/) {
10886: $confhash{$itemid}{$extra.'valid'} = $lifetime;
10887: }
10888: }
1.267 raeburn 10889: }
10890: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
10891: $changes{$itemid} = 1;
10892: }
1.319 raeburn 10893: if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
10894: $changes{$itemid} = 1;
10895: }
1.267 raeburn 10896: }
1.273 raeburn 10897: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318 raeburn 10898: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 10899: if (grep(/^\Q$item\E$/,@courseconfig)) {
10900: $confhash{$itemid}{'crsconf'}{$item} = 1;
10901: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
10902: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
10903: $changes{$itemid} = 1;
10904: }
10905: } else {
10906: $changes{$itemid} = 1;
10907: }
10908: }
10909: }
1.267 raeburn 10910: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
10911: foreach my $field (@fields) {
10912: if ($possfield{$field}) {
10913: if ($field eq 'roles') {
10914: foreach my $role (@courseroles) {
10915: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
10916: if (($choice ne '') && ($posslti{$choice})) {
10917: $confhash{$itemid}{'roles'}{$role} = $choice;
10918: if ($role eq 'cc') {
10919: $confhash{$itemid}{'roles'}{'co'} = $choice;
10920: }
10921: }
10922: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
10923: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
10924: $changes{$itemid} = 1;
10925: }
10926: } elsif ($confhash{$itemid}{'roles'}{$role}) {
10927: $changes{$itemid} = 1;
10928: }
10929: }
10930: } else {
10931: $confhash{$itemid}{'fields'}{$field} = 1;
10932: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
10933: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
10934: $changes{$itemid} = 1;
10935: }
10936: } else {
10937: $changes{$itemid} = 1;
10938: }
10939: }
10940: }
10941: }
10942: $allpos[$newpos] = $itemid;
10943: }
10944: if ($imgdeletions{$itemid}) {
10945: $changes{$itemid} = 1;
10946: #FIXME need to obsolete item in RES space
10947: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
10948: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
10949: $itemid,$configuserok,$switchserver,
10950: $author_ok);
10951: if ($imgurl) {
10952: $confhash{$itemid}{'image'} = $imgurl;
10953: $changes{$itemid} = 1;
10954: }
10955: if ($error) {
10956: &Apache::lonnet::logthis($error);
10957: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10958: }
10959: } elsif ($domconfig{$action}{$itemid}{'image'}) {
10960: $confhash{$itemid}{'image'} =
10961: $domconfig{$action}{$itemid}{'image'};
10962: }
10963: if ($customadds{$i}) {
10964: my $name = $env{'form.ltitools_custom_name_'.$i};
10965: $name =~ s/(`)/'/g;
10966: $name =~ s/^\s+//;
10967: $name =~ s/\s+$//;
10968: my $value = $env{'form.ltitools_custom_value_'.$i};
10969: $value =~ s/(`)/'/g;
10970: $value =~ s/^\s+//;
10971: $value =~ s/\s+$//;
10972: if ($name ne '') {
10973: $confhash{$itemid}{'custom'}{$name} = $value;
10974: $changes{$itemid} = 1;
10975: }
10976: }
10977: my %customdels;
10978: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
10979: if (@customdeletions) {
10980: $changes{$itemid} = 1;
10981: }
10982: map { $customdels{$_} = 1; } @customdeletions;
10983: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
10984: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
10985: unless ($customdels{$key}) {
10986: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
10987: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
10988: }
10989: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
10990: $changes{$itemid} = 1;
10991: }
10992: }
10993: }
10994: }
10995: unless ($changes{$itemid}) {
10996: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
10997: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
10998: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
10999: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
11000: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
11001: $changes{$itemid} = 1;
11002: last;
11003: }
11004: }
11005: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
11006: $changes{$itemid} = 1;
11007: }
11008: }
11009: last if ($changes{$itemid});
11010: }
11011: }
11012: }
11013: }
11014: }
11015: if (@allpos > 0) {
11016: my $idx = 0;
11017: foreach my $itemid (@allpos) {
11018: if ($itemid ne '') {
11019: $confhash{$itemid}{'order'} = $idx;
11020: if (ref($domconfig{$action}) eq 'HASH') {
11021: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11022: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
11023: $changes{$itemid} = 1;
11024: }
11025: }
11026: }
11027: $idx ++;
11028: }
11029: }
11030: }
11031: my %ltitoolshash = (
11032: $action => { %confhash }
11033: );
11034: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
11035: $dom);
11036: if ($putresult eq 'ok') {
1.297 raeburn 11037: my %ltienchash = (
11038: $action => { %encconfig }
11039: );
11040: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
1.267 raeburn 11041: if (keys(%changes) > 0) {
11042: my $cachetime = 24*60*60;
1.297 raeburn 11043: my %ltiall = %confhash;
11044: foreach my $id (keys(%ltiall)) {
11045: if (ref($encconfig{$id}) eq 'HASH') {
11046: foreach my $item ('key','secret') {
11047: $ltiall{$id}{$item} = $encconfig{$id}{$item};
11048: }
11049: }
11050: }
11051: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 11052: if (ref($lastactref) eq 'HASH') {
11053: $lastactref->{'ltitools'} = 1;
11054: }
11055: $resulttext = &mt('Changes made:').'<ul>';
11056: my %bynum;
11057: foreach my $itemid (sort(keys(%changes))) {
11058: my $position = $confhash{$itemid}{'order'};
11059: $bynum{$position} = $itemid;
11060: }
11061: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
11062: my $itemid = $bynum{$pos};
11063: if (ref($confhash{$itemid}) ne 'HASH') {
11064: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
11065: } else {
11066: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
11067: if ($confhash{$itemid}{'image'}) {
11068: $resulttext .= ' '.
11069: '<img src="'.$confhash{$itemid}{'image'}.'"'.
11070: ' alt="'.&mt('Tool Provider icon').'" />';
11071: }
11072: $resulttext .= '</li><ul>';
11073: my $position = $pos + 1;
11074: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.323 ! raeburn 11075: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1.267 raeburn 11076: if ($confhash{$itemid}{$item} ne '') {
11077: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
11078: }
11079: }
1.297 raeburn 11080: if ($encconfig{$itemid}{'key'} ne '') {
11081: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
11082: }
11083: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 11084: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 11085: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 11086: $resulttext .= ('*'x$num).'</li>';
11087: }
1.273 raeburn 11088: $resulttext .= '<li>'.&mt('Configurable in course:');
1.318 raeburn 11089: my @possconfig = ('label','title','target','linktext','explanation','append');
1.273 raeburn 11090: my $numconfig = 0;
11091: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
11092: foreach my $item (@possconfig) {
11093: if ($confhash{$itemid}{'crsconf'}{$item}) {
11094: $numconfig ++;
1.296 raeburn 11095: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 11096: }
11097: }
11098: }
11099: if (!$numconfig) {
11100: $resulttext .= &mt('None');
11101: }
11102: $resulttext .= '</li>';
1.267 raeburn 11103: foreach my $item ('passback','roster') {
11104: $resulttext .= '<li>'.$lt{$item}.' ';
11105: if ($confhash{$itemid}{$item}) {
11106: $resulttext .= &mt('Yes');
1.319 raeburn 11107: if ($confhash{$itemid}{$item.'valid'}) {
11108: if ($item eq 'passback') {
11109: $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
11110: $confhash{$itemid}{$item.'valid'});
11111: } else {
11112: $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
11113: $confhash{$itemid}{$item.'valid'});
11114: }
11115: }
1.267 raeburn 11116: } else {
11117: $resulttext .= &mt('No');
11118: }
11119: $resulttext .= '</li>';
11120: }
11121: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
11122: my $displaylist;
11123: if ($confhash{$itemid}{'display'}{'target'}) {
11124: $displaylist = &mt('Display target').': '.
11125: $confhash{$itemid}{'display'}{'target'}.',';
11126: }
11127: foreach my $size ('width','height') {
11128: if ($confhash{$itemid}{'display'}{$size}) {
11129: $displaylist .= (' 'x2).$lt{$size}.': '.
11130: $confhash{$itemid}{'display'}{$size}.',';
11131: }
11132: }
11133: if ($displaylist) {
11134: $displaylist =~ s/,$//;
11135: $resulttext .= '<li>'.$displaylist.'</li>';
11136: }
1.296 raeburn 11137: foreach my $item ('linktext','explanation') {
11138: if ($confhash{$itemid}{'display'}{$item}) {
11139: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
11140: }
11141: }
11142: }
1.267 raeburn 11143: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
11144: my $fieldlist;
11145: foreach my $field (@allfields) {
11146: if ($confhash{$itemid}{'fields'}{$field}) {
11147: $fieldlist .= (' 'x2).$lt{$field}.',';
11148: }
11149: }
11150: if ($fieldlist) {
11151: $fieldlist =~ s/,$//;
11152: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
11153: }
11154: }
11155: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
11156: my $rolemaps;
11157: foreach my $role (@courseroles) {
11158: if ($confhash{$itemid}{'roles'}{$role}) {
11159: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
11160: $confhash{$itemid}{'roles'}{$role}.',';
11161: }
11162: }
11163: if ($rolemaps) {
11164: $rolemaps =~ s/,$//;
11165: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
11166: }
11167: }
11168: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
11169: my $customlist;
11170: if (keys(%{$confhash{$itemid}{'custom'}})) {
11171: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
11172: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
11173: }
11174: }
11175: if ($customlist) {
1.317 raeburn 11176: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267 raeburn 11177: }
11178: }
11179: $resulttext .= '</ul></li>';
11180: }
11181: }
11182: $resulttext .= '</ul>';
11183: } else {
11184: $resulttext = &mt('No changes made.');
11185: }
11186: } else {
11187: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
11188: }
11189: if ($errors) {
11190: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11191: $errors.'</ul>';
11192: }
11193: return $resulttext;
11194: }
11195:
11196: sub process_ltitools_image {
11197: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
11198: my $filename = $env{'form.'.$caller.'.filename'};
11199: my ($error,$url);
11200: my ($width,$height) = (21,21);
11201: if ($configuserok eq 'ok') {
11202: if ($switchserver) {
11203: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
11204: $switchserver);
11205: } elsif ($author_ok eq 'ok') {
11206: my ($result,$imageurl,$madethumb) =
11207: &publishlogo($r,'upload',$caller,$dom,$confname,
11208: "ltitools/$itemid/icon",$width,$height);
11209: if ($result eq 'ok') {
11210: if ($madethumb) {
11211: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
11212: my $imagethumb = "$path/tn-".$imagefile;
11213: $url = $imagethumb;
11214: } else {
11215: $url = $imageurl;
11216: }
11217: } else {
11218: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
11219: }
11220: } else {
11221: $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);
11222: }
11223: } else {
11224: $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);
11225: }
11226: return ($url,$error);
11227: }
11228:
11229: sub get_ltitools_id {
11230: my ($cdom,$title) = @_;
11231: # get lock on ltitools db
11232: my $lockhash = {
11233: lock => $env{'user.name'}.
11234: ':'.$env{'user.domain'},
11235: };
11236: my $tries = 0;
11237: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
11238: my ($id,$error);
11239:
11240: while (($gotlock ne 'ok') && ($tries<10)) {
11241: $tries ++;
11242: sleep (0.1);
11243: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
11244: }
11245: if ($gotlock eq 'ok') {
11246: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
11247: if ($currids{'lock'}) {
11248: delete($currids{'lock'});
11249: if (keys(%currids)) {
11250: my @curr = sort { $a <=> $b } keys(%currids);
11251: if ($curr[-1] =~ /^\d+$/) {
11252: $id = 1 + $curr[-1];
11253: }
11254: } else {
11255: $id = 1;
11256: }
11257: if ($id) {
11258: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
11259: $error = 'nostore';
11260: }
11261: } else {
11262: $error = 'nonumber';
11263: }
11264: }
11265: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
11266: } else {
11267: $error = 'nolock';
11268: }
11269: return ($id,$error);
11270: }
11271:
1.320 raeburn 11272: sub modify_lti {
11273: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
11274: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11275: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
11276: my (%posslti,%posslticrs,%posscrstype);
11277: my @courseroles = ('cc','in','ta','ep','st');
11278: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
11279: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
11280: my @coursetypes = ('official','unofficial','community','textbook','placement');
11281: my %coursetypetitles = &Apache::lonlocal::texthash (
11282: official => 'Official',
11283: unofficial => 'Unofficial',
11284: community => 'Community',
11285: textbook => 'Textbook',
11286: placement => 'Placement Test',
11287: );
11288: my %lt = <i_names();
11289: map { $posslti{$_} = 1; } @ltiroles;
11290: map { $posslticrs{$_} = 1; } @lticourseroles;
11291: map { $posscrstype{$_} = 1; } @coursetypes;
11292:
11293: my (@items,%deletions,%itemids);
11294: if ($env{'form.lti_add'}) {
11295: my $consumer = $env{'form.lti_consumer_add'};
11296: $consumer =~ s/(`)/'/g;
11297: ($newid,my $error) = &get_lti_id($dom,$consumer);
11298: if ($newid) {
11299: $itemids{'add'} = $newid;
11300: push(@items,'add');
11301: $changes{$newid} = 1;
11302: } else {
11303: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
11304: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11305: }
11306: }
11307: if (ref($domconfig{$action}) eq 'HASH') {
11308: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
11309: if (@todelete) {
11310: map { $deletions{$_} = 1; } @todelete;
11311: }
11312: my $maxnum = $env{'form.lti_maxnum'};
11313: for (my $i=0; $i<=$maxnum; $i++) {
11314: my $itemid = $env{'form.lti_id_'.$i};
11315: $itemid =~ s/\D+//g;
11316: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11317: if ($deletions{$itemid}) {
11318: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
11319: } else {
11320: push(@items,$i);
11321: $itemids{$i} = $itemid;
11322: }
11323: }
11324: }
11325: }
11326: foreach my $idx (@items) {
11327: my $itemid = $itemids{$idx};
11328: next unless ($itemid);
11329: my $position = $env{'form.lti_pos_'.$idx};
11330: $position =~ s/\D+//g;
11331: if ($position ne '') {
11332: $allpos[$position] = $itemid;
11333: }
11334: foreach my $item ('consumer','key','secret','lifetime') {
11335: my $formitem = 'form.lti_'.$item.'_'.$idx;
11336: $env{$formitem} =~ s/(`)/'/g;
11337: if ($item eq 'lifetime') {
11338: $env{$formitem} =~ s/[^\d.]//g;
11339: }
11340: if ($env{$formitem} ne '') {
11341: if (($item eq 'key') || ($item eq 'secret')) {
11342: $encconfig{$itemid}{$item} = $env{$formitem};
11343: } else {
11344: $confhash{$itemid}{$item} = $env{$formitem};
11345: unless (($idx eq 'add') || ($changes{$itemid})) {
11346: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
11347: $changes{$itemid} = 1;
11348: }
11349: }
11350: }
11351: }
11352: }
11353: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
11354: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
11355: }
11356: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
11357: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
11358: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
11359: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
11360: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
11361: my $mapuser = $env{'form.lti_customuser_'.$idx};
11362: $mapuser =~ s/(`)/'/g;
11363: $mapuser =~ s/^\s+|\s+$//g;
11364: $confhash{$itemid}{'mapuser'} = $mapuser;
11365: }
11366: foreach my $ltirole (@lticourseroles) {
11367: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
11368: if (grep(/^\Q$possrole\E$/,@courseroles)) {
11369: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
11370: }
11371: }
11372: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
11373: my @makeuser;
11374: foreach my $ltirole (sort(@possmakeuser)) {
11375: if ($posslti{$ltirole}) {
11376: push(@makeuser,$ltirole);
11377: }
11378: }
11379: $confhash{$itemid}{'makeuser'} = \@makeuser;
11380: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
11381: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
11382: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
11383: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
11384: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
11385: $mapcrs =~ s/(`)/'/g;
11386: $mapcrs =~ s/^\s+|\s+$//g;
11387: $confhash{$itemid}{'mapcrs'} = $mapcrs;
11388: }
11389: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
11390: my @crstypes;
11391: foreach my $type (sort(@posstypes)) {
11392: if ($posscrstype{$type}) {
11393: push(@crstypes,$type);
11394: }
11395: }
11396: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
11397: if ($env{'form.lti_makecrs_'.$idx}) {
11398: $confhash{$itemid}{'makecrs'} = 1;
11399: }
11400: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
11401: my @selfenroll;
11402: foreach my $type (sort(@possenroll)) {
11403: if ($posslticrs{$type}) {
11404: push(@selfenroll,$type);
11405: }
11406: }
11407: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
11408: if ($env{'form.lti_crssec_'.$idx}) {
11409: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
11410: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
11411: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
11412: my $section = $env{'form.lti_customsection_'.$idx};
11413: $section =~ s/(`)/'/g;
11414: $section =~ s/^\s+|\s+$//g;
11415: if ($section ne '') {
11416: $confhash{$itemid}{'section'} = $section;
11417: }
11418: }
11419: }
11420: foreach my $field ('passback','roster') {
1.321 raeburn 11421: if ($env{'form.lti_'.$field.'_'.$idx}) {
1.320 raeburn 11422: $confhash{$itemid}{$field} = 1;
11423: }
11424: }
11425: unless (($idx eq 'add') || ($changes{$itemid})) {
11426: foreach my $field ('mapuser','mapcrs','section','passback','roster') {
11427: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
11428: $changes{$itemid} = 1;
11429: }
11430: }
11431: foreach my $field ('makeuser','mapcrstype','selfenroll') {
11432: unless ($changes{$itemid}) {
11433: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
11434: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
11435: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
11436: $confhash{$itemid}{$field});
11437: if (@diffs) {
11438: $changes{$itemid} = 1;
11439: }
11440: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
11441: $changes{$itemid} = 1;
11442: }
11443: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
11444: if (@{$confhash{$itemid}{$field}} > 0) {
11445: $changes{$itemid} = 1;
11446: }
11447: }
11448: }
11449: }
11450: unless ($changes{$itemid}) {
11451: if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
11452: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
11453: foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
11454: if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne
11455: $confhash{$itemid}{'maproles'}{$ltirole}) {
11456: $changes{$itemid} = 1;
11457: last;
11458: }
11459: }
11460: unless ($changes{$itemid}) {
11461: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
11462: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
11463: $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
11464: $changes{$itemid} = 1;
11465: last;
11466: }
11467: }
11468: }
11469: } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
11470: $changes{$itemid} = 1;
11471: }
11472: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
11473: unless ($changes{$itemid}) {
11474: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
11475: $changes{$itemid} = 1;
11476: }
11477: }
11478: }
11479: }
11480: }
11481: }
11482: if (@allpos > 0) {
11483: my $idx = 0;
11484: foreach my $itemid (@allpos) {
11485: if ($itemid ne '') {
11486: $confhash{$itemid}{'order'} = $idx;
11487: if (ref($domconfig{$action}) eq 'HASH') {
11488: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11489: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
11490: $changes{$itemid} = 1;
11491: }
11492: }
11493: }
11494: $idx ++;
11495: }
11496: }
11497: }
11498: my %ltihash = (
11499: $action => { %confhash }
11500: );
11501: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,
11502: $dom);
11503: if ($putresult eq 'ok') {
11504: my %ltienchash = (
11505: $action => { %encconfig }
11506: );
11507: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
11508: if (keys(%changes) > 0) {
11509: my $cachetime = 24*60*60;
11510: my %ltiall = %confhash;
11511: foreach my $id (keys(%ltiall)) {
11512: if (ref($encconfig{$id}) eq 'HASH') {
11513: foreach my $item ('key','secret') {
11514: $ltiall{$id}{$item} = $encconfig{$id}{$item};
11515: }
11516: }
11517: }
11518: &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
11519: if (ref($lastactref) eq 'HASH') {
11520: $lastactref->{'lti'} = 1;
11521: }
11522: $resulttext = &mt('Changes made:').'<ul>';
11523: my %bynum;
11524: foreach my $itemid (sort(keys(%changes))) {
11525: my $position = $confhash{$itemid}{'order'};
11526: $bynum{$position} = $itemid;
11527: }
11528: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
11529: my $itemid = $bynum{$pos};
11530: if (ref($confhash{$itemid}) ne 'HASH') {
11531: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
11532: } else {
11533: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b></li><ul>';
11534: my $position = $pos + 1;
11535: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
11536: foreach my $item ('version','lifetime') {
11537: if ($confhash{$itemid}{$item} ne '') {
11538: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
11539: }
11540: }
11541: if ($encconfig{$itemid}{'key'} ne '') {
11542: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
11543: }
11544: if ($encconfig{$itemid}{'secret'} ne '') {
11545: $resulttext .= '<li>'.$lt{'secret'}.': ';
11546: my $num = length($encconfig{$itemid}{'secret'});
11547: $resulttext .= ('*'x$num).'</li>';
11548: }
11549: if ($confhash{$itemid}{'mapuser'}) {
11550: my $shownmapuser;
11551: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
11552: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
11553: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
11554: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
11555: } else {
11556: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
11557: }
11558: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
11559: }
11560: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
11561: my $rolemaps;
11562: foreach my $role (@ltiroles) {
11563: if ($confhash{$itemid}{'maproles'}{$role}) {
11564: $rolemaps .= (' 'x2).$role.'='.
11565: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
11566: 'Course').',';
11567: }
11568: }
11569: if ($rolemaps) {
11570: $rolemaps =~ s/,$//;
11571: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
11572: }
11573: }
11574: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
11575: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
11576: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
11577: join(', ',@{$confhash{$itemid}{'makeuser'}})).'</li>';
11578: } else {
11579: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
11580: }
11581: }
11582: if ($confhash{$itemid}{'mapcrs'}) {
11583: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
11584: }
11585: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
11586: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
11587: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
11588: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
11589: '</li>';
11590: } else {
11591: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
11592: }
11593: }
11594: if ($confhash{$itemid}{'makecrs'}) {
11595: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
11596: } else {
11597: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
11598: }
11599: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
11600: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
11601: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
11602: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
11603: '</li>';
11604: } else {
11605: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
11606: }
11607: }
11608: if ($confhash{$itemid}{'section'}) {
11609: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
11610: $resulttext .= '<li>'.&mt('User section from standard field:').
11611: ' (course_section_sourcedid)'.'</li>';
11612: } else {
11613: $resulttext .= '<li>'.&mt('User section from:').' '.
11614: $confhash{$itemid}{'section'}.'</li>';
11615: }
11616: } else {
11617: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
11618: }
11619: foreach my $item ('passback','roster') {
11620: $resulttext .= '<li>'.$lt{$item}.' ';
11621: if ($confhash{$itemid}{$item}) {
11622: $resulttext .= &mt('Yes');
11623: } else {
11624: $resulttext .= &mt('No');
11625: }
11626: $resulttext .= '</li>';
11627: }
11628: $resulttext .= '</ul></li>';
11629: }
11630: }
11631: $resulttext .= '</ul>';
11632: } else {
11633: $resulttext = &mt('No changes made.');
11634: }
11635: } else {
11636: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
11637: }
11638: if ($errors) {
11639: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11640: $errors.'</ul>';
11641: }
11642: return $resulttext;
11643: }
11644:
11645: sub get_lti_id {
11646: my ($domain,$consumer) = @_;
11647: # get lock on lti db
11648: my $lockhash = {
11649: lock => $env{'user.name'}.
11650: ':'.$env{'user.domain'},
11651: };
11652: my $tries = 0;
11653: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
11654: my ($id,$error);
11655:
11656: while (($gotlock ne 'ok') && ($tries<10)) {
11657: $tries ++;
11658: sleep (0.1);
11659: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
11660: }
11661: if ($gotlock eq 'ok') {
11662: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
11663: if ($currids{'lock'}) {
11664: delete($currids{'lock'});
11665: if (keys(%currids)) {
11666: my @curr = sort { $a <=> $b } keys(%currids);
11667: if ($curr[-1] =~ /^\d+$/) {
11668: $id = 1 + $curr[-1];
11669: }
11670: } else {
11671: $id = 1;
11672: }
11673: if ($id) {
11674: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
11675: $error = 'nostore';
11676: }
11677: } else {
11678: $error = 'nonumber';
11679: }
11680: }
11681: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
11682: } else {
11683: $error = 'nolock';
11684: }
11685: return ($id,$error);
11686: }
11687:
1.3 raeburn 11688: sub modify_autoenroll {
1.205 raeburn 11689: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 11690: my ($resulttext,%changes);
11691: my %currautoenroll;
11692: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
11693: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
11694: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
11695: }
11696: }
11697: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
11698: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 11699: sender => 'Sender for notification messages',
1.274 raeburn 11700: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
11701: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 11702: my @offon = ('off','on');
1.17 raeburn 11703: my $sender_uname = $env{'form.sender_uname'};
11704: my $sender_domain = $env{'form.sender_domain'};
11705: if ($sender_domain eq '') {
11706: $sender_uname = '';
11707: } elsif ($sender_uname eq '') {
11708: $sender_domain = '';
11709: }
1.129 raeburn 11710: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 11711: my $failsafe = $env{'form.autoenroll_failsafe'};
11712: $failsafe =~ s{^\s+|\s+$}{}g;
11713: if ($failsafe =~ /\D/) {
11714: undef($failsafe);
11715: }
1.1 raeburn 11716: my %autoenrollhash = (
1.129 raeburn 11717: autoenroll => { 'run' => $env{'form.autoenroll_run'},
11718: 'sender_uname' => $sender_uname,
11719: 'sender_domain' => $sender_domain,
11720: 'co-owners' => $coowners,
1.274 raeburn 11721: 'autofailsafe' => $failsafe,
1.1 raeburn 11722: }
11723: );
1.4 raeburn 11724: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
11725: $dom);
1.1 raeburn 11726: if ($putresult eq 'ok') {
11727: if (exists($currautoenroll{'run'})) {
11728: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
11729: $changes{'run'} = 1;
11730: }
11731: } elsif ($autorun) {
11732: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 11733: $changes{'run'} = 1;
1.1 raeburn 11734: }
11735: }
1.17 raeburn 11736: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 11737: $changes{'sender'} = 1;
11738: }
1.17 raeburn 11739: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 11740: $changes{'sender'} = 1;
11741: }
1.129 raeburn 11742: if ($currautoenroll{'co-owners'} ne '') {
11743: if ($currautoenroll{'co-owners'} ne $coowners) {
11744: $changes{'coowners'} = 1;
11745: }
11746: } elsif ($coowners) {
11747: $changes{'coowners'} = 1;
1.274 raeburn 11748: }
11749: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
11750: $changes{'autofailsafe'} = 1;
11751: }
1.1 raeburn 11752: if (keys(%changes) > 0) {
11753: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 11754: if ($changes{'run'}) {
1.1 raeburn 11755: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
11756: }
11757: if ($changes{'sender'}) {
1.17 raeburn 11758: if ($sender_uname eq '' || $sender_domain eq '') {
11759: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
11760: } else {
11761: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
11762: }
1.1 raeburn 11763: }
1.129 raeburn 11764: if ($changes{'coowners'}) {
11765: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
11766: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 11767: if (ref($lastactref) eq 'HASH') {
11768: $lastactref->{'domainconfig'} = 1;
11769: }
1.129 raeburn 11770: }
1.274 raeburn 11771: if ($changes{'autofailsafe'}) {
11772: if ($failsafe ne '') {
1.299 raeburn 11773: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274 raeburn 11774: } else {
1.299 raeburn 11775: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274 raeburn 11776: }
11777: &Apache::lonnet::get_domain_defaults($dom,1);
11778: if (ref($lastactref) eq 'HASH') {
11779: $lastactref->{'domdefaults'} = 1;
11780: }
11781: }
1.1 raeburn 11782: $resulttext .= '</ul>';
11783: } else {
11784: $resulttext = &mt('No changes made to auto-enrollment settings');
11785: }
11786: } else {
1.11 albertel 11787: $resulttext = '<span class="LC_error">'.
11788: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11789: }
1.3 raeburn 11790: return $resulttext;
1.1 raeburn 11791: }
11792:
11793: sub modify_autoupdate {
1.3 raeburn 11794: my ($dom,%domconfig) = @_;
1.1 raeburn 11795: my ($resulttext,%currautoupdate,%fields,%changes);
11796: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
11797: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
11798: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
11799: }
11800: }
11801: my @offon = ('off','on');
11802: my %title = &Apache::lonlocal::texthash (
11803: run => 'Auto-update:',
11804: classlists => 'Updates to user information in classlists?'
11805: );
1.44 raeburn 11806: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 11807: my %fieldtitles = &Apache::lonlocal::texthash (
11808: id => 'Student/Employee ID',
1.20 raeburn 11809: permanentemail => 'E-mail address',
1.1 raeburn 11810: lastname => 'Last Name',
11811: firstname => 'First Name',
11812: middlename => 'Middle Name',
1.132 raeburn 11813: generation => 'Generation',
1.1 raeburn 11814: );
1.142 raeburn 11815: $othertitle = &mt('All users');
1.1 raeburn 11816: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 11817: $othertitle = &mt('Other users');
1.1 raeburn 11818: }
11819: foreach my $key (keys(%env)) {
11820: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 11821: my ($usertype,$item) = ($1,$2);
11822: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
11823: if ($usertype eq 'default') {
11824: push(@{$fields{$1}},$2);
11825: } elsif (ref($types) eq 'ARRAY') {
11826: if (grep(/^\Q$usertype\E$/,@{$types})) {
11827: push(@{$fields{$1}},$2);
11828: }
11829: }
11830: }
1.1 raeburn 11831: }
11832: }
1.131 raeburn 11833: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
11834: @lockablenames = sort(@lockablenames);
11835: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
11836: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
11837: if (@changed) {
11838: $changes{'lockablenames'} = 1;
11839: }
11840: } else {
11841: if (@lockablenames) {
11842: $changes{'lockablenames'} = 1;
11843: }
11844: }
1.1 raeburn 11845: my %updatehash = (
11846: autoupdate => { run => $env{'form.autoupdate_run'},
11847: classlists => $env{'form.classlists'},
11848: fields => {%fields},
1.131 raeburn 11849: lockablenames => \@lockablenames,
1.1 raeburn 11850: }
11851: );
11852: foreach my $key (keys(%currautoupdate)) {
11853: if (($key eq 'run') || ($key eq 'classlists')) {
11854: if (exists($updatehash{autoupdate}{$key})) {
11855: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
11856: $changes{$key} = 1;
11857: }
11858: }
11859: } elsif ($key eq 'fields') {
11860: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 11861: foreach my $item (@{$types},'default') {
1.1 raeburn 11862: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
11863: my $change = 0;
11864: foreach my $type (@{$currautoupdate{$key}{$item}}) {
11865: if (!exists($fields{$item})) {
11866: $change = 1;
1.132 raeburn 11867: last;
1.1 raeburn 11868: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 11869: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 11870: $change = 1;
1.132 raeburn 11871: last;
1.1 raeburn 11872: }
11873: }
11874: }
11875: if ($change) {
11876: push(@{$changes{$key}},$item);
11877: }
1.26 raeburn 11878: }
1.1 raeburn 11879: }
11880: }
1.131 raeburn 11881: } elsif ($key eq 'lockablenames') {
11882: if (ref($currautoupdate{$key}) eq 'ARRAY') {
11883: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
11884: if (@changed) {
11885: $changes{'lockablenames'} = 1;
11886: }
11887: } else {
11888: if (@lockablenames) {
11889: $changes{'lockablenames'} = 1;
11890: }
11891: }
11892: }
11893: }
11894: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
11895: if (@lockablenames) {
11896: $changes{'lockablenames'} = 1;
1.1 raeburn 11897: }
11898: }
1.26 raeburn 11899: foreach my $item (@{$types},'default') {
11900: if (defined($fields{$item})) {
11901: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 11902: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
11903: my $change = 0;
11904: if (ref($fields{$item}) eq 'ARRAY') {
11905: foreach my $type (@{$fields{$item}}) {
11906: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
11907: $change = 1;
11908: last;
11909: }
11910: }
11911: }
11912: if ($change) {
11913: push(@{$changes{'fields'}},$item);
11914: }
11915: } else {
1.26 raeburn 11916: push(@{$changes{'fields'}},$item);
11917: }
11918: } else {
11919: push(@{$changes{'fields'}},$item);
1.1 raeburn 11920: }
11921: }
11922: }
11923: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
11924: $dom);
11925: if ($putresult eq 'ok') {
11926: if (keys(%changes) > 0) {
11927: $resulttext = &mt('Changes made:').'<ul>';
11928: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 11929: if ($key eq 'lockablenames') {
11930: $resulttext .= '<li>';
11931: if (@lockablenames) {
11932: $usertypes->{'default'} = $othertitle;
11933: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
11934: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
11935: } else {
11936: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
11937: }
11938: $resulttext .= '</li>';
11939: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 11940: foreach my $item (@{$changes{$key}}) {
11941: my @newvalues;
11942: foreach my $type (@{$fields{$item}}) {
11943: push(@newvalues,$fieldtitles{$type});
11944: }
1.3 raeburn 11945: my $newvaluestr;
11946: if (@newvalues > 0) {
11947: $newvaluestr = join(', ',@newvalues);
11948: } else {
11949: $newvaluestr = &mt('none');
1.6 raeburn 11950: }
1.1 raeburn 11951: if ($item eq 'default') {
1.26 raeburn 11952: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 11953: } else {
1.26 raeburn 11954: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 11955: }
11956: }
11957: } else {
11958: my $newvalue;
11959: if ($key eq 'run') {
11960: $newvalue = $offon[$env{'form.autoupdate_run'}];
11961: } else {
11962: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 11963: }
1.1 raeburn 11964: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
11965: }
11966: }
11967: $resulttext .= '</ul>';
11968: } else {
1.3 raeburn 11969: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 11970: }
11971: } else {
1.11 albertel 11972: $resulttext = '<span class="LC_error">'.
11973: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11974: }
1.3 raeburn 11975: return $resulttext;
1.1 raeburn 11976: }
11977:
1.125 raeburn 11978: sub modify_autocreate {
11979: my ($dom,%domconfig) = @_;
11980: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
11981: if (ref($domconfig{'autocreate'}) eq 'HASH') {
11982: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
11983: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
11984: }
11985: }
11986: my %title= ( xml => 'Auto-creation of courses in XML course description files',
11987: req => 'Auto-creation of validated requests for official courses',
11988: xmldc => 'Identity of course creator of courses from XML files',
11989: );
11990: my @types = ('xml','req');
11991: foreach my $item (@types) {
11992: $newvals{$item} = $env{'form.autocreate_'.$item};
11993: $newvals{$item} =~ s/\D//g;
11994: $newvals{$item} = 0 if ($newvals{$item} eq '');
11995: }
11996: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 11997: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 11998: unless (exists($domcoords{$newvals{'xmldc'}})) {
11999: $newvals{'xmldc'} = '';
12000: }
12001: %autocreatehash = (
12002: autocreate => { xml => $newvals{'xml'},
12003: req => $newvals{'req'},
12004: }
12005: );
12006: if ($newvals{'xmldc'} ne '') {
12007: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
12008: }
12009: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
12010: $dom);
12011: if ($putresult eq 'ok') {
12012: my @items = @types;
12013: if ($newvals{'xml'}) {
12014: push(@items,'xmldc');
12015: }
12016: foreach my $item (@items) {
12017: if (exists($currautocreate{$item})) {
12018: if ($currautocreate{$item} ne $newvals{$item}) {
12019: $changes{$item} = 1;
12020: }
12021: } elsif ($newvals{$item}) {
12022: $changes{$item} = 1;
12023: }
12024: }
12025: if (keys(%changes) > 0) {
12026: my @offon = ('off','on');
12027: $resulttext = &mt('Changes made:').'<ul>';
12028: foreach my $item (@types) {
12029: if ($changes{$item}) {
12030: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 12031: $resulttext .= '<li>'.
12032: &mt("$title{$item} set to [_1]$newtxt [_2]",
12033: '<b>','</b>').
12034: '</li>';
1.125 raeburn 12035: }
12036: }
12037: if ($changes{'xmldc'}) {
12038: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
12039: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 12040: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 12041: }
12042: $resulttext .= '</ul>';
12043: } else {
12044: $resulttext = &mt('No changes made to auto-creation settings');
12045: }
12046: } else {
12047: $resulttext = '<span class="LC_error">'.
12048: &mt('An error occurred: [_1]',$putresult).'</span>';
12049: }
12050: return $resulttext;
12051: }
12052:
1.23 raeburn 12053: sub modify_directorysrch {
1.295 raeburn 12054: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 12055: my ($resulttext,%changes);
12056: my %currdirsrch;
12057: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
12058: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
12059: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
12060: }
12061: }
1.277 raeburn 12062: my %title = ( available => 'Institutional directory search available',
12063: localonly => 'Other domains can search institution',
12064: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 12065: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 12066: searchby => 'Search types',
12067: searchtypes => 'Search latitude');
12068: my @offon = ('off','on');
1.24 raeburn 12069: my @otherdoms = ('Yes','No');
1.23 raeburn 12070:
1.25 raeburn 12071: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 12072: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
12073: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
12074:
1.44 raeburn 12075: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 12076: if (keys(%{$usertypes}) == 0) {
12077: @cansearch = ('default');
12078: } else {
12079: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
12080: foreach my $type (@{$currdirsrch{'cansearch'}}) {
12081: if (!grep(/^\Q$type\E$/,@cansearch)) {
12082: push(@{$changes{'cansearch'}},$type);
12083: }
1.23 raeburn 12084: }
1.26 raeburn 12085: foreach my $type (@cansearch) {
12086: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
12087: push(@{$changes{'cansearch'}},$type);
12088: }
1.23 raeburn 12089: }
1.26 raeburn 12090: } else {
12091: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 12092: }
12093: }
12094:
12095: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
12096: foreach my $by (@{$currdirsrch{'searchby'}}) {
12097: if (!grep(/^\Q$by\E$/,@searchby)) {
12098: push(@{$changes{'searchby'}},$by);
12099: }
12100: }
12101: foreach my $by (@searchby) {
12102: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
12103: push(@{$changes{'searchby'}},$by);
12104: }
12105: }
12106: } else {
12107: push(@{$changes{'searchby'}},@searchby);
12108: }
1.25 raeburn 12109:
12110: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
12111: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
12112: if (!grep(/^\Q$type\E$/,@searchtypes)) {
12113: push(@{$changes{'searchtypes'}},$type);
12114: }
12115: }
12116: foreach my $type (@searchtypes) {
12117: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
12118: push(@{$changes{'searchtypes'}},$type);
12119: }
12120: }
12121: } else {
12122: if (exists($currdirsrch{'searchtypes'})) {
12123: foreach my $type (@searchtypes) {
12124: if ($type ne $currdirsrch{'searchtypes'}) {
12125: push(@{$changes{'searchtypes'}},$type);
12126: }
12127: }
12128: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
12129: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
12130: }
12131: } else {
12132: push(@{$changes{'searchtypes'}},@searchtypes);
12133: }
12134: }
12135:
1.23 raeburn 12136: my %dirsrch_hash = (
12137: directorysrch => { available => $env{'form.dirsrch_available'},
12138: cansearch => \@cansearch,
1.277 raeburn 12139: localonly => $env{'form.dirsrch_instlocalonly'},
12140: lclocalonly => $env{'form.dirsrch_domlocalonly'},
12141: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 12142: searchby => \@searchby,
1.25 raeburn 12143: searchtypes => \@searchtypes,
1.23 raeburn 12144: }
12145: );
12146: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
12147: $dom);
12148: if ($putresult eq 'ok') {
12149: if (exists($currdirsrch{'available'})) {
12150: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
12151: $changes{'available'} = 1;
12152: }
12153: } else {
12154: if ($env{'form.dirsrch_available'} eq '1') {
12155: $changes{'available'} = 1;
12156: }
12157: }
1.277 raeburn 12158: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 12159: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
12160: $changes{'lcavailable'} = 1;
12161: }
1.277 raeburn 12162: } else {
12163: if ($env{'form.dirsrch_lcavailable'} eq '1') {
12164: $changes{'lcavailable'} = 1;
12165: }
12166: }
1.24 raeburn 12167: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 12168: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
12169: $changes{'localonly'} = 1;
12170: }
1.24 raeburn 12171: } else {
1.277 raeburn 12172: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 12173: $changes{'localonly'} = 1;
12174: }
12175: }
1.277 raeburn 12176: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 12177: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
12178: $changes{'lclocalonly'} = 1;
12179: }
1.277 raeburn 12180: } else {
12181: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
12182: $changes{'lclocalonly'} = 1;
12183: }
12184: }
1.23 raeburn 12185: if (keys(%changes) > 0) {
12186: $resulttext = &mt('Changes made:').'<ul>';
12187: if ($changes{'available'}) {
12188: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
12189: }
1.277 raeburn 12190: if ($changes{'lcavailable'}) {
12191: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
12192: }
1.24 raeburn 12193: if ($changes{'localonly'}) {
1.277 raeburn 12194: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 12195: }
1.277 raeburn 12196: if ($changes{'lclocalonly'}) {
12197: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 12198: }
1.23 raeburn 12199: if (ref($changes{'cansearch'}) eq 'ARRAY') {
12200: my $chgtext;
1.26 raeburn 12201: if (ref($usertypes) eq 'HASH') {
12202: if (keys(%{$usertypes}) > 0) {
12203: foreach my $type (@{$types}) {
12204: if (grep(/^\Q$type\E$/,@cansearch)) {
12205: $chgtext .= $usertypes->{$type}.'; ';
12206: }
12207: }
12208: if (grep(/^default$/,@cansearch)) {
12209: $chgtext .= $othertitle;
12210: } else {
12211: $chgtext =~ s/\; $//;
12212: }
1.210 raeburn 12213: $resulttext .=
1.178 raeburn 12214: '<li>'.
12215: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
12216: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
12217: '</li>';
1.23 raeburn 12218: }
12219: }
12220: }
12221: if (ref($changes{'searchby'}) eq 'ARRAY') {
12222: my ($searchtitles,$titleorder) = &sorted_searchtitles();
12223: my $chgtext;
12224: foreach my $type (@{$titleorder}) {
12225: if (grep(/^\Q$type\E$/,@searchby)) {
12226: if (defined($searchtitles->{$type})) {
12227: $chgtext .= $searchtitles->{$type}.'; ';
12228: }
12229: }
12230: }
12231: $chgtext =~ s/\; $//;
12232: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
12233: }
1.25 raeburn 12234: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
12235: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
12236: my $chgtext;
12237: foreach my $type (@{$srchtypeorder}) {
12238: if (grep(/^\Q$type\E$/,@searchtypes)) {
12239: if (defined($srchtypes_desc->{$type})) {
12240: $chgtext .= $srchtypes_desc->{$type}.'; ';
12241: }
12242: }
12243: }
12244: $chgtext =~ s/\; $//;
1.178 raeburn 12245: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 12246: }
12247: $resulttext .= '</ul>';
1.295 raeburn 12248: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
12249: if (ref($lastactref) eq 'HASH') {
12250: $lastactref->{'directorysrch'} = 1;
12251: }
1.23 raeburn 12252: } else {
1.277 raeburn 12253: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 12254: }
12255: } else {
12256: $resulttext = '<span class="LC_error">'.
1.27 raeburn 12257: &mt('An error occurred: [_1]',$putresult).'</span>';
12258: }
12259: return $resulttext;
12260: }
12261:
1.28 raeburn 12262: sub modify_contacts {
1.205 raeburn 12263: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 12264: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
12265: if (ref($domconfig{'contacts'}) eq 'HASH') {
12266: foreach my $key (keys(%{$domconfig{'contacts'}})) {
12267: $currsetting{$key} = $domconfig{'contacts'}{$key};
12268: }
12269: }
1.286 raeburn 12270: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 12271: my @contacts = ('supportemail','adminemail');
1.286 raeburn 12272: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
12273: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.203 raeburn 12274: my @toggles = ('reporterrors','reportupdates');
1.286 raeburn 12275: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 12276: foreach my $type (@mailings) {
12277: @{$newsetting{$type}} =
12278: &Apache::loncommon::get_env_multiple('form.'.$type);
12279: foreach my $item (@contacts) {
12280: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
12281: $contacts_hash{contacts}{$type}{$item} = 1;
12282: } else {
12283: $contacts_hash{contacts}{$type}{$item} = 0;
12284: }
1.289 raeburn 12285: }
1.28 raeburn 12286: $others{$type} = $env{'form.'.$type.'_others'};
12287: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 12288: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12289: $bcc{$type} = $env{'form.'.$type.'_bcc'};
12290: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 12291: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
12292: $includestr{$type} = $env{'form.'.$type.'_includestr'};
12293: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
12294: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
12295: }
1.134 raeburn 12296: }
1.28 raeburn 12297: }
12298: foreach my $item (@contacts) {
12299: $to{$item} = $env{'form.'.$item};
12300: $contacts_hash{'contacts'}{$item} = $to{$item};
12301: }
1.203 raeburn 12302: foreach my $item (@toggles) {
12303: if ($env{'form.'.$item} =~ /^(0|1)$/) {
12304: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
12305: }
12306: }
1.286 raeburn 12307: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
12308: foreach my $field (@{$fields}) {
12309: if (ref($possoptions->{$field}) eq 'ARRAY') {
12310: my $value = $env{'form.helpform_'.$field};
12311: $value =~ s/^\s+|\s+$//g;
12312: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 12313: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 12314: if ($field eq 'screenshot') {
12315: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
12316: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 12317: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 12318: }
12319: }
12320: }
12321: }
12322: }
12323: }
1.315 raeburn 12324: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12325: my (@statuses,%usertypeshash,@overrides);
12326: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
12327: @statuses = @{$types};
12328: if (ref($usertypes) eq 'HASH') {
12329: %usertypeshash = %{$usertypes};
12330: }
12331: }
12332: if (@statuses) {
12333: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
12334: foreach my $type (@possoverrides) {
12335: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
12336: push(@overrides,$type);
12337: }
12338: }
12339: if (@overrides) {
12340: foreach my $type (@overrides) {
12341: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
12342: foreach my $item (@contacts) {
12343: if (grep(/^\Q$item\E$/,@standard)) {
12344: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
12345: $newsetting{'override_'.$type}{$item} = 1;
12346: } else {
12347: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
12348: $newsetting{'override_'.$type}{$item} = 0;
12349: }
12350: }
12351: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
12352: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
12353: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
12354: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
12355: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
12356: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
12357: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
12358: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
12359: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
12360: }
12361: }
12362: }
12363: }
1.28 raeburn 12364: if (keys(%currsetting) > 0) {
12365: foreach my $item (@contacts) {
12366: if ($to{$item} ne $currsetting{$item}) {
12367: $changes{$item} = 1;
12368: }
12369: }
12370: foreach my $type (@mailings) {
12371: foreach my $item (@contacts) {
12372: if (ref($currsetting{$type}) eq 'HASH') {
12373: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
12374: push(@{$changes{$type}},$item);
12375: }
12376: } else {
12377: push(@{$changes{$type}},@{$newsetting{$type}});
12378: }
12379: }
12380: if ($others{$type} ne $currsetting{$type}{'others'}) {
12381: push(@{$changes{$type}},'others');
12382: }
1.289 raeburn 12383: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12384: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
12385: push(@{$changes{$type}},'bcc');
12386: }
1.286 raeburn 12387: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
12388: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
12389: push(@{$changes{$type}},'include');
12390: }
12391: }
12392: }
12393: if (ref($fields) eq 'ARRAY') {
12394: if (ref($currsetting{'helpform'}) eq 'HASH') {
12395: foreach my $field (@{$fields}) {
12396: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
12397: push(@{$changes{'helpform'}},$field);
12398: }
12399: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12400: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
12401: push(@{$changes{'helpform'}},'maxsize');
12402: }
12403: }
12404: }
12405: } else {
12406: foreach my $field (@{$fields}) {
12407: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12408: push(@{$changes{'helpform'}},$field);
12409: }
12410: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12411: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12412: push(@{$changes{'helpform'}},'maxsize');
12413: }
12414: }
12415: }
1.134 raeburn 12416: }
1.28 raeburn 12417: }
1.315 raeburn 12418: if (@statuses) {
12419: if (ref($currsetting{'overrides'}) eq 'HASH') {
12420: foreach my $key (keys(%{$currsetting{'overrides'}})) {
12421: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
12422: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
12423: foreach my $item (@contacts,'bcc','others','include') {
12424: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
12425: push(@{$changes{'overrides'}},$key);
12426: last;
12427: }
12428: }
12429: } else {
12430: push(@{$changes{'overrides'}},$key);
12431: }
12432: }
12433: }
12434: foreach my $key (@overrides) {
12435: unless (exists($currsetting{'overrides'}{$key})) {
12436: push(@{$changes{'overrides'}},$key);
12437: }
12438: }
12439: } else {
12440: foreach my $key (@overrides) {
12441: push(@{$changes{'overrides'}},$key);
12442: }
12443: }
12444: }
1.28 raeburn 12445: } else {
12446: my %default;
12447: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
12448: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
12449: $default{'errormail'} = 'adminemail';
12450: $default{'packagesmail'} = 'adminemail';
12451: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 12452: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 12453: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 12454: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 12455: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 12456: foreach my $item (@contacts) {
12457: if ($to{$item} ne $default{$item}) {
1.286 raeburn 12458: $changes{$item} = 1;
1.203 raeburn 12459: }
1.28 raeburn 12460: }
12461: foreach my $type (@mailings) {
12462: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
12463: push(@{$changes{$type}},@{$newsetting{$type}});
12464: }
12465: if ($others{$type} ne '') {
12466: push(@{$changes{$type}},'others');
1.134 raeburn 12467: }
1.286 raeburn 12468: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12469: if ($bcc{$type} ne '') {
12470: push(@{$changes{$type}},'bcc');
12471: }
1.286 raeburn 12472: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
12473: push(@{$changes{$type}},'include');
12474: }
1.134 raeburn 12475: }
1.28 raeburn 12476: }
1.286 raeburn 12477: if (ref($fields) eq 'ARRAY') {
12478: foreach my $field (@{$fields}) {
12479: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12480: push(@{$changes{'helpform'}},$field);
12481: }
12482: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12483: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12484: push(@{$changes{'helpform'}},'maxsize');
12485: }
12486: }
12487: }
1.289 raeburn 12488: }
1.28 raeburn 12489: }
1.203 raeburn 12490: foreach my $item (@toggles) {
12491: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
12492: $changes{$item} = 1;
12493: } elsif ((!$env{'form.'.$item}) &&
12494: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
12495: $changes{$item} = 1;
12496: }
12497: }
1.28 raeburn 12498: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
12499: $dom);
12500: if ($putresult eq 'ok') {
12501: if (keys(%changes) > 0) {
1.205 raeburn 12502: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12503: if (ref($lastactref) eq 'HASH') {
12504: $lastactref->{'domainconfig'} = 1;
12505: }
1.28 raeburn 12506: my ($titles,$short_titles) = &contact_titles();
12507: $resulttext = &mt('Changes made:').'<ul>';
12508: foreach my $item (@contacts) {
12509: if ($changes{$item}) {
12510: $resulttext .= '<li>'.$titles->{$item}.
12511: &mt(' set to: ').
12512: '<span class="LC_cusr_emph">'.
12513: $to{$item}.'</span></li>';
12514: }
12515: }
12516: foreach my $type (@mailings) {
12517: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 12518: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 12519: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 12520: } else {
12521: $resulttext .= '<li>'.$titles->{$type}.': ';
12522: }
1.28 raeburn 12523: my @text;
12524: foreach my $item (@{$newsetting{$type}}) {
12525: push(@text,$short_titles->{$item});
12526: }
12527: if ($others{$type} ne '') {
12528: push(@text,$others{$type});
12529: }
1.286 raeburn 12530: if (@text) {
12531: $resulttext .= '<span class="LC_cusr_emph">'.
12532: join(', ',@text).'</span>';
12533: }
12534: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12535: if ($bcc{$type} ne '') {
1.286 raeburn 12536: my $bcctext;
12537: if (@text) {
1.289 raeburn 12538: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 12539: } else {
12540: $bcctext = '(Bcc)';
12541: }
12542: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
12543: } elsif (!@text) {
12544: $resulttext .= &mt('No one');
12545: }
1.289 raeburn 12546: if ($includestr{$type} ne '') {
1.286 raeburn 12547: if ($includeloc{$type} eq 'b') {
12548: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
12549: } elsif ($includeloc{$type} eq 's') {
12550: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
12551: }
1.134 raeburn 12552: }
1.286 raeburn 12553: } elsif (!@text) {
12554: $resulttext .= &mt('No recipients');
1.134 raeburn 12555: }
12556: $resulttext .= '</li>';
1.28 raeburn 12557: }
12558: }
1.315 raeburn 12559: if (ref($changes{'overrides'}) eq 'ARRAY') {
12560: my @deletions;
12561: foreach my $type (@{$changes{'overrides'}}) {
12562: if ($usertypeshash{$type}) {
12563: if (grep(/^\Q$type\E/,@overrides)) {
12564: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
12565: $usertypeshash{$type}).'<ul><li>';
12566: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
12567: my @text;
12568: foreach my $item (@contacts) {
12569: if ($newsetting{'override_'.$type}{$item}) {
12570: push(@text,$short_titles->{$item});
12571: }
12572: }
12573: if ($newsetting{'override_'.$type}{'others'} ne '') {
12574: push(@text,$newsetting{'override_'.$type}{'others'});
12575: }
12576:
12577: if (@text) {
12578: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
12579: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
12580: }
12581: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
12582: my $bcctext;
12583: if (@text) {
12584: $bcctext = ' '.&mt('with Bcc to');
12585: } else {
12586: $bcctext = '(Bcc)';
12587: }
12588: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
12589: } elsif (!@text) {
12590: $resulttext .= &mt('Helpdesk e-mail sent to no one');
12591: }
12592: $resulttext .= '</li>';
12593: if ($newsetting{'override_'.$type}{'include'} ne '') {
12594: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
12595: if ($loc eq 'b') {
12596: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
12597: } elsif ($loc eq 's') {
12598: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
12599: }
12600: }
12601: }
12602: $resulttext .= '</li></ul></li>';
12603: } else {
12604: push(@deletions,$usertypeshash{$type});
12605: }
12606: }
12607: }
12608: if (@deletions) {
12609: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
12610: join(', ',@deletions)).'</li>';
12611: }
12612: }
1.203 raeburn 12613: my @offon = ('off','on');
12614: if ($changes{'reporterrors'}) {
12615: $resulttext .= '<li>'.
12616: &mt('E-mail error reports to [_1] set to "'.
12617: $offon[$env{'form.reporterrors'}].'".',
12618: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
12619: &mt('LON-CAPA core group - MSU'),600,500)).
12620: '</li>';
12621: }
12622: if ($changes{'reportupdates'}) {
12623: $resulttext .= '<li>'.
12624: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
12625: $offon[$env{'form.reportupdates'}].'".',
12626: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
12627: &mt('LON-CAPA core group - MSU'),600,500)).
12628: '</li>';
12629: }
1.286 raeburn 12630: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
12631: my (@optional,@required,@unused,$maxsizechg);
12632: foreach my $field (@{$changes{'helpform'}}) {
12633: if ($field eq 'maxsize') {
12634: $maxsizechg = 1;
12635: next;
12636: }
12637: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 12638: push(@optional,$field);
1.286 raeburn 12639: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
12640: push(@unused,$field);
12641: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 12642: push(@required,$field);
1.286 raeburn 12643: }
12644: }
12645: if (@optional) {
12646: $resulttext .= '<li>'.
12647: &mt('Help form fields changed to "Optional": [_1].',
12648: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
12649: '</li>';
12650: }
12651: if (@required) {
12652: $resulttext .= '<li>'.
12653: &mt('Help form fields changed to "Required": [_1].',
12654: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
12655: '</li>';
12656: }
12657: if (@unused) {
12658: $resulttext .= '<li>'.
12659: &mt('Help form fields changed to "Not shown": [_1].',
12660: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
12661: '</li>';
12662: }
12663: if ($maxsizechg) {
12664: $resulttext .= '<li>'.
12665: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
12666: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
12667: '</li>';
12668: }
12669: }
1.28 raeburn 12670: $resulttext .= '</ul>';
12671: } else {
1.288 raeburn 12672: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 12673: }
12674: } else {
12675: $resulttext = '<span class="LC_error">'.
12676: &mt('An error occurred: [_1].',$putresult).'</span>';
12677: }
12678: return $resulttext;
12679: }
12680:
12681: sub modify_usercreation {
1.27 raeburn 12682: my ($dom,%domconfig) = @_;
1.224 raeburn 12683: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 12684: my $warningmsg;
1.27 raeburn 12685: if (ref($domconfig{'usercreation'}) eq 'HASH') {
12686: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 12687: if ($key eq 'cancreate') {
12688: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
12689: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 12690: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
12691: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
12692: } else {
1.224 raeburn 12693: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
12694: }
12695: }
12696: }
12697: } elsif ($key eq 'email_rule') {
12698: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
12699: } else {
12700: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
12701: }
1.27 raeburn 12702: }
12703: }
12704: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 12705: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 12706: my @contexts = ('author','course','requestcrs');
1.34 raeburn 12707: foreach my $item(@contexts) {
1.224 raeburn 12708: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 12709: }
1.34 raeburn 12710: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
12711: foreach my $item (@contexts) {
1.224 raeburn 12712: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
12713: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 12714: }
1.27 raeburn 12715: }
1.34 raeburn 12716: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
12717: foreach my $item (@contexts) {
1.43 raeburn 12718: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 12719: if ($cancreate{$item} ne 'any') {
12720: push(@{$changes{'cancreate'}},$item);
12721: }
12722: } else {
12723: if ($cancreate{$item} ne 'none') {
12724: push(@{$changes{'cancreate'}},$item);
12725: }
1.27 raeburn 12726: }
12727: }
12728: } else {
1.43 raeburn 12729: foreach my $item (@contexts) {
1.34 raeburn 12730: push(@{$changes{'cancreate'}},$item);
12731: }
1.27 raeburn 12732: }
1.34 raeburn 12733:
1.27 raeburn 12734: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
12735: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
12736: if (!grep(/^\Q$type\E$/,@username_rule)) {
12737: push(@{$changes{'username_rule'}},$type);
12738: }
12739: }
12740: foreach my $type (@username_rule) {
12741: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
12742: push(@{$changes{'username_rule'}},$type);
12743: }
12744: }
12745: } else {
12746: push(@{$changes{'username_rule'}},@username_rule);
12747: }
12748:
1.32 raeburn 12749: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
12750: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
12751: if (!grep(/^\Q$type\E$/,@id_rule)) {
12752: push(@{$changes{'id_rule'}},$type);
12753: }
12754: }
12755: foreach my $type (@id_rule) {
12756: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
12757: push(@{$changes{'id_rule'}},$type);
12758: }
12759: }
12760: } else {
12761: push(@{$changes{'id_rule'}},@id_rule);
12762: }
12763:
1.43 raeburn 12764: my @authen_contexts = ('author','course','domain');
1.28 raeburn 12765: my @authtypes = ('int','krb4','krb5','loc');
12766: my %authhash;
1.43 raeburn 12767: foreach my $item (@authen_contexts) {
1.28 raeburn 12768: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
12769: foreach my $auth (@authtypes) {
12770: if (grep(/^\Q$auth\E$/,@authallowed)) {
12771: $authhash{$item}{$auth} = 1;
12772: } else {
12773: $authhash{$item}{$auth} = 0;
12774: }
12775: }
12776: }
12777: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 12778: foreach my $item (@authen_contexts) {
1.28 raeburn 12779: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
12780: foreach my $auth (@authtypes) {
12781: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
12782: push(@{$changes{'authtypes'}},$item);
12783: last;
12784: }
12785: }
12786: }
12787: }
12788: } else {
1.43 raeburn 12789: foreach my $item (@authen_contexts) {
1.28 raeburn 12790: push(@{$changes{'authtypes'}},$item);
12791: }
12792: }
12793:
1.224 raeburn 12794: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
12795: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
12796: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
12797: $save_usercreate{'id_rule'} = \@id_rule;
12798: $save_usercreate{'username_rule'} = \@username_rule,
12799: $save_usercreate{'authtypes'} = \%authhash;
12800:
1.27 raeburn 12801: my %usercreation_hash = (
1.224 raeburn 12802: usercreation => \%save_usercreate,
12803: );
1.27 raeburn 12804:
12805: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
12806: $dom);
1.50 raeburn 12807:
1.224 raeburn 12808: if ($putresult eq 'ok') {
12809: if (keys(%changes) > 0) {
12810: $resulttext = &mt('Changes made:').'<ul>';
12811: if (ref($changes{'cancreate'}) eq 'ARRAY') {
12812: my %lt = &usercreation_types();
12813: foreach my $type (@{$changes{'cancreate'}}) {
12814: my $chgtext = $lt{$type}.', ';
12815: if ($cancreate{$type} eq 'none') {
12816: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
12817: } elsif ($cancreate{$type} eq 'any') {
12818: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
12819: } elsif ($cancreate{$type} eq 'official') {
12820: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
12821: } elsif ($cancreate{$type} eq 'unofficial') {
12822: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
12823: }
12824: $resulttext .= '<li>'.$chgtext.'</li>';
12825: }
12826: }
12827: if (ref($changes{'username_rule'}) eq 'ARRAY') {
12828: my ($rules,$ruleorder) =
12829: &Apache::lonnet::inst_userrules($dom,'username');
12830: my $chgtext = '<ul>';
12831: foreach my $type (@username_rule) {
12832: if (ref($rules->{$type}) eq 'HASH') {
12833: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
12834: }
12835: }
12836: $chgtext .= '</ul>';
12837: if (@username_rule > 0) {
12838: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
12839: } else {
12840: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
12841: }
12842: }
12843: if (ref($changes{'id_rule'}) eq 'ARRAY') {
12844: my ($idrules,$idruleorder) =
12845: &Apache::lonnet::inst_userrules($dom,'id');
12846: my $chgtext = '<ul>';
12847: foreach my $type (@id_rule) {
12848: if (ref($idrules->{$type}) eq 'HASH') {
12849: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
12850: }
12851: }
12852: $chgtext .= '</ul>';
12853: if (@id_rule > 0) {
12854: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
12855: } else {
12856: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
12857: }
12858: }
12859: my %authname = &authtype_names();
12860: my %context_title = &context_names();
12861: if (ref($changes{'authtypes'}) eq 'ARRAY') {
12862: my $chgtext = '<ul>';
12863: foreach my $type (@{$changes{'authtypes'}}) {
12864: my @allowed;
12865: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
12866: foreach my $auth (@authtypes) {
12867: if ($authhash{$type}{$auth}) {
12868: push(@allowed,$authname{$auth});
12869: }
12870: }
12871: if (@allowed > 0) {
12872: $chgtext .= join(', ',@allowed).'</li>';
12873: } else {
12874: $chgtext .= &mt('none').'</li>';
12875: }
12876: }
12877: $chgtext .= '</ul>';
12878: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
12879: $resulttext .= '</li>';
12880: }
12881: $resulttext .= '</ul>';
12882: } else {
12883: $resulttext = &mt('No changes made to user creation settings');
12884: }
12885: } else {
12886: $resulttext = '<span class="LC_error">'.
12887: &mt('An error occurred: [_1]',$putresult).'</span>';
12888: }
12889: if ($warningmsg ne '') {
12890: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
12891: }
12892: return $resulttext;
12893: }
12894:
12895: sub modify_selfcreation {
1.305 raeburn 12896: my ($dom,$lastactref,%domconfig) = @_;
12897: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
12898: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
12899: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 12900: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
12901: if (ref($typesref) eq 'ARRAY') {
12902: @types = @{$typesref};
12903: }
12904: if (ref($usertypesref) eq 'HASH') {
12905: %usertypes = %{$usertypesref};
1.228 raeburn 12906: }
1.303 raeburn 12907: $usertypes{'default'} = $othertitle;
1.224 raeburn 12908: #
12909: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
12910: #
12911: if (ref($domconfig{'usercreation'}) eq 'HASH') {
12912: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
12913: if ($key eq 'cancreate') {
12914: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
12915: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
12916: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 12917: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
12918: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
12919: ($item eq 'emailusername') || ($item eq 'shibenv') ||
12920: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 12921: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 12922: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
12923: } else {
12924: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
12925: }
12926: }
12927: }
12928: } elsif ($key eq 'email_rule') {
12929: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
12930: } else {
12931: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
12932: }
12933: }
12934: }
12935: #
12936: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
12937: #
12938: if (ref($domconfig{'usermodification'}) eq 'HASH') {
12939: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
12940: if ($key eq 'selfcreate') {
12941: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
12942: } else {
12943: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
12944: }
12945: }
12946: }
1.305 raeburn 12947: #
12948: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
12949: #
12950: if (ref($domconfig{'inststatus'}) eq 'HASH') {
12951: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
12952: if ($key eq 'inststatusguest') {
12953: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
12954: } else {
12955: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
12956: }
12957: }
12958: }
1.224 raeburn 12959:
12960: my @contexts = ('selfcreate');
12961: @{$cancreate{'selfcreate'}} = ();
12962: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 12963: if (@types) {
12964: @{$cancreate{'statustocreate'}} = ();
12965: }
1.236 raeburn 12966: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 12967: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 12968: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 12969: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 12970: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 12971: my %selfcreatetypes = (
12972: sso => 'users authenticated by institutional single sign on',
12973: login => 'users authenticated by institutional log-in',
1.303 raeburn 12974: email => 'users verified by e-mail',
1.50 raeburn 12975: );
1.224 raeburn 12976: #
12977: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
12978: # is permitted.
12979: #
1.305 raeburn 12980: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 12981:
1.305 raeburn 12982: my (@statuses,%email_rule);
1.228 raeburn 12983: foreach my $item ('login','sso','email') {
1.224 raeburn 12984: if ($item eq 'email') {
1.236 raeburn 12985: if ($env{'form.cancreate_email'}) {
1.305 raeburn 12986: if (@types) {
12987: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
12988: foreach my $status (@poss_statuses) {
12989: if (grep(/^\Q$status\E$/,(@types,'default'))) {
12990: push(@statuses,$status);
12991: }
12992: }
12993: $save_inststatus{'inststatusguest'} = \@statuses;
12994: } else {
12995: push(@statuses,'default');
12996: }
12997: if (@statuses) {
12998: my %curr_rule;
12999: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
13000: foreach my $type (@statuses) {
13001: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 13002: }
1.305 raeburn 13003: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
13004: foreach my $type (@statuses) {
13005: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
13006: }
13007: }
13008: push(@{$cancreate{'selfcreate'}},'email');
13009: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
13010: my %curremaildom;
13011: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
13012: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
13013: }
13014: foreach my $type (@statuses) {
13015: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
13016: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
13017: }
13018: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
13019: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
13020: }
13021: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
13022: #
13023: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
13024: #
13025: my $chosen = $1;
13026: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
13027: my $emaildom;
13028: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
13029: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
13030: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
13031: if (ref($curremaildom{$type}) eq 'HASH') {
13032: if (exists($curremaildom{$type}{$chosen})) {
13033: if ($curremaildom{$type}{$chosen} ne $emaildom) {
13034: push(@{$changes{'cancreate'}},'emaildomain');
13035: }
13036: } elsif ($emaildom ne '') {
13037: push(@{$changes{'cancreate'}},'emaildomain');
13038: }
13039: } elsif ($emaildom ne '') {
13040: push(@{$changes{'cancreate'}},'emaildomain');
13041: }
13042: }
13043: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13044: } elsif ($chosen eq 'custom') {
13045: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
13046: $email_rule{$type} = [];
13047: if (ref($emailrules) eq 'HASH') {
13048: foreach my $rule (@possemail_rules) {
13049: if (exists($emailrules->{$rule})) {
13050: push(@{$email_rule{$type}},$rule);
13051: }
13052: }
13053: }
13054: if (@{$email_rule{$type}}) {
13055: $cancreate{'emailoptions'}{$type} = 'custom';
13056: if (ref($curr_rule{$type}) eq 'ARRAY') {
13057: if (@{$curr_rule{$type}} > 0) {
13058: foreach my $rule (@{$curr_rule{$type}}) {
13059: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
13060: push(@{$changes{'email_rule'}},$type);
13061: }
13062: }
13063: }
13064: foreach my $type (@{$email_rule{$type}}) {
13065: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
13066: push(@{$changes{'email_rule'}},$type);
13067: }
13068: }
13069: } else {
13070: push(@{$changes{'email_rule'}},$type);
13071: }
13072: }
13073: } else {
13074: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13075: }
13076: }
13077: }
13078: if (@types) {
13079: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13080: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
13081: if (@changed) {
13082: push(@{$changes{'inststatus'}},'inststatusguest');
13083: }
13084: } else {
13085: push(@{$changes{'inststatus'}},'inststatusguest');
13086: }
13087: }
13088: } else {
13089: delete($env{'form.cancreate_email'});
13090: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13091: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13092: push(@{$changes{'inststatus'}},'inststatusguest');
13093: }
13094: }
13095: }
13096: } else {
13097: $save_inststatus{'inststatusguest'} = [];
13098: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13099: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13100: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 13101: }
13102: }
1.224 raeburn 13103: }
13104: } else {
13105: if ($env{'form.cancreate_'.$item}) {
13106: push(@{$cancreate{'selfcreate'}},$item);
13107: }
13108: }
13109: }
1.305 raeburn 13110: my (%userinfo,%savecaptcha);
1.224 raeburn 13111: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
13112: #
1.228 raeburn 13113: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
13114: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 13115: #
1.236 raeburn 13116:
1.244 raeburn 13117: if ($env{'form.cancreate_email'}) {
1.228 raeburn 13118: push(@contexts,'emailusername');
1.305 raeburn 13119: if (@statuses) {
13120: foreach my $type (@statuses) {
1.228 raeburn 13121: if (ref($infofields) eq 'ARRAY') {
13122: foreach my $field (@{$infofields}) {
13123: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
13124: $cancreate{'emailusername'}{$type}{$field} = $1;
13125: }
13126: }
1.224 raeburn 13127: }
13128: }
13129: }
13130: #
13131: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 13132: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 13133: #
13134:
13135: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
13136: @approvalnotify = sort(@approvalnotify);
13137: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
13138: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13139: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
13140: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
13141: push(@{$changes{'cancreate'}},'notify');
13142: }
13143: } else {
13144: if ($cancreate{'notify'}{'approval'}) {
13145: push(@{$changes{'cancreate'}},'notify');
13146: }
13147: }
13148: } elsif ($cancreate{'notify'}{'approval'}) {
13149: push(@{$changes{'cancreate'}},'notify');
13150: }
13151:
13152: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
13153: }
13154: #
1.236 raeburn 13155: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 13156: # institutional log-in.
13157: #
13158: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
13159: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
13160: ($domdefaults{'auth_def'} eq 'localauth'))) {
13161: $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.').' '.
13162: &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.');
13163: }
13164: }
13165: my @fields = ('lastname','firstname','middlename','generation',
13166: 'permanentemail','id');
1.240 raeburn 13167: my @shibfields = (@fields,'inststatus');
1.224 raeburn 13168: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13169: #
13170: # Where usernames may created for institutional log-in and/or institutional single sign on:
13171: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
13172: # may self-create accounts
13173: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
13174: # which the user may supply, if institutional data is unavailable.
13175: #
13176: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 13177: if (@types) {
1.305 raeburn 13178: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
13179: push(@contexts,'statustocreate');
1.303 raeburn 13180: foreach my $type (@types) {
1.224 raeburn 13181: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
13182: foreach my $field (@fields) {
13183: if (grep(/^\Q$field\E$/,@modifiable)) {
13184: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
13185: } else {
13186: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
13187: }
13188: }
13189: }
13190: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 13191: foreach my $type (@types) {
1.224 raeburn 13192: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
13193: foreach my $field (@fields) {
13194: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
13195: $curr_usermodify{'selfcreate'}{$type}{$field}) {
13196: push(@{$changes{'selfcreate'}},$type);
13197: last;
13198: }
13199: }
13200: }
13201: }
13202: } else {
1.303 raeburn 13203: foreach my $type (@types) {
1.224 raeburn 13204: push(@{$changes{'selfcreate'}},$type);
13205: }
13206: }
13207: }
1.240 raeburn 13208: foreach my $field (@shibfields) {
13209: if ($env{'form.shibenv_'.$field} ne '') {
13210: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
13211: }
13212: }
13213: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13214: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
13215: foreach my $field (@shibfields) {
13216: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
13217: push(@{$changes{'cancreate'}},'shibenv');
13218: }
13219: }
13220: } else {
13221: foreach my $field (@shibfields) {
13222: if ($env{'form.shibenv_'.$field}) {
13223: push(@{$changes{'cancreate'}},'shibenv');
13224: last;
13225: }
13226: }
13227: }
13228: }
1.224 raeburn 13229: }
13230: foreach my $item (@contexts) {
13231: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
13232: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
13233: if (ref($cancreate{$item}) eq 'ARRAY') {
13234: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
13235: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13236: push(@{$changes{'cancreate'}},$item);
13237: }
13238: }
13239: }
13240: }
13241: if (ref($cancreate{$item}) eq 'ARRAY') {
13242: foreach my $type (@{$cancreate{$item}}) {
13243: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
13244: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13245: push(@{$changes{'cancreate'}},$item);
13246: }
13247: }
13248: }
13249: }
13250: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
13251: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 13252: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
13253: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13254: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
13255: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 13256: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13257: push(@{$changes{'cancreate'}},$item);
13258: }
13259: }
13260: }
1.305 raeburn 13261: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13262: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 13263: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13264: push(@{$changes{'cancreate'}},$item);
13265: }
1.224 raeburn 13266: }
13267: }
13268: }
1.305 raeburn 13269: foreach my $type (keys(%{$cancreate{$item}})) {
13270: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13271: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13272: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13273: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 13274: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13275: push(@{$changes{'cancreate'}},$item);
13276: }
13277: }
13278: } else {
13279: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13280: push(@{$changes{'cancreate'}},$item);
13281: }
13282: }
13283: }
1.305 raeburn 13284: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13285: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 13286: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13287: push(@{$changes{'cancreate'}},$item);
13288: }
1.224 raeburn 13289: }
13290: }
13291: }
13292: }
13293: } elsif ($curr_usercreation{'cancreate'}{$item}) {
13294: if (ref($cancreate{$item}) eq 'ARRAY') {
13295: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
13296: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13297: push(@{$changes{'cancreate'}},$item);
13298: }
13299: }
1.305 raeburn 13300: }
13301: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13302: if (ref($cancreate{$item}) eq 'HASH') {
13303: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13304: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 13305: }
13306: }
13307: } elsif ($item eq 'emailusername') {
1.228 raeburn 13308: if (ref($cancreate{$item}) eq 'HASH') {
13309: foreach my $type (keys(%{$cancreate{$item}})) {
13310: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13311: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13312: if ($cancreate{$item}{$type}{$field}) {
13313: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13314: push(@{$changes{'cancreate'}},$item);
13315: }
13316: last;
13317: }
13318: }
13319: }
13320: }
1.224 raeburn 13321: }
13322: }
13323: }
13324: #
13325: # Populate %save_usercreate hash with updates to self-creation configuration.
13326: #
13327: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
13328: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 13329: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 13330: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
13331: if (ref($cancreate{'notify'}) eq 'HASH') {
13332: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
13333: }
1.236 raeburn 13334: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
13335: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
13336: }
1.303 raeburn 13337: if (ref($cancreate{'emailverified'}) eq 'HASH') {
13338: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
13339: }
1.305 raeburn 13340: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
13341: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
13342: }
1.303 raeburn 13343: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
13344: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
13345: }
1.224 raeburn 13346: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13347: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
13348: }
1.240 raeburn 13349: if (ref($cancreate{'shibenv'}) eq 'HASH') {
13350: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
13351: }
1.224 raeburn 13352: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 13353: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 13354:
13355: my %userconfig_hash = (
13356: usercreation => \%save_usercreate,
13357: usermodification => \%save_usermodify,
1.305 raeburn 13358: inststatus => \%save_inststatus,
1.224 raeburn 13359: );
1.305 raeburn 13360:
1.224 raeburn 13361: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
13362: $dom);
13363: #
1.305 raeburn 13364: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 13365: #
1.27 raeburn 13366: if ($putresult eq 'ok') {
13367: if (keys(%changes) > 0) {
13368: $resulttext = &mt('Changes made:').'<ul>';
13369: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 13370: my %lt = &selfcreation_types();
1.34 raeburn 13371: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 13372: my $chgtext = '';
1.45 raeburn 13373: if ($type eq 'selfcreate') {
1.50 raeburn 13374: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 13375: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 13376: } else {
1.224 raeburn 13377: $chgtext .= &mt('Self-creation of a new account is permitted for:').
13378: '<ul>';
1.50 raeburn 13379: foreach my $case (@{$cancreate{$type}}) {
13380: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
13381: }
13382: $chgtext .= '</ul>';
1.100 raeburn 13383: if (ref($cancreate{$type}) eq 'ARRAY') {
13384: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
13385: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13386: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 13387: $chgtext .= '<span class="LC_warning">'.
13388: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
13389: '</span><br />';
13390: }
13391: }
13392: }
13393: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 13394: if (!@statuses) {
13395: $chgtext .= '<span class="LC_warning">'.
13396: &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.").
13397: '</span><br />';
1.303 raeburn 13398:
1.100 raeburn 13399: }
13400: }
13401: }
1.43 raeburn 13402: }
1.240 raeburn 13403: } elsif ($type eq 'shibenv') {
13404: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 13405: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 13406: } else {
13407: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
13408: '<ul>';
13409: foreach my $field (@shibfields) {
13410: next if ($cancreate{$type}{$field} eq '');
13411: if ($field eq 'inststatus') {
13412: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
13413: } else {
13414: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
13415: }
13416: }
13417: $chgtext .= '</ul>';
1.303 raeburn 13418: }
1.93 raeburn 13419: } elsif ($type eq 'statustocreate') {
1.96 raeburn 13420: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
13421: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
13422: if (@{$cancreate{'selfcreate'}} > 0) {
13423: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 13424: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 13425: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 13426: $chgtext .= '<br />'.
13427: '<span class="LC_warning">'.
13428: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
13429: '</span>';
13430: }
1.303 raeburn 13431: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 13432: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 13433: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
13434: } else {
13435: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
13436: }
13437: $chgtext .= '<ul>';
13438: foreach my $case (@{$cancreate{$type}}) {
13439: if ($case eq 'default') {
13440: $chgtext .= '<li>'.$othertitle.'</li>';
13441: } else {
1.303 raeburn 13442: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 13443: }
13444: }
1.100 raeburn 13445: $chgtext .= '</ul>';
13446: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 13447: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 13448: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
13449: '</span>';
1.100 raeburn 13450: }
13451: }
13452: } else {
13453: if (@{$cancreate{$type}} == 0) {
13454: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
13455: } else {
13456: $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 13457: }
13458: }
1.303 raeburn 13459: $chgtext .= '<br />';
1.93 raeburn 13460: }
1.236 raeburn 13461: } elsif ($type eq 'selfcreateprocessing') {
13462: my %choices = &Apache::lonlocal::texthash (
13463: automatic => 'Automatic approval',
13464: approval => 'Queued for approval',
13465: );
1.305 raeburn 13466: if (@types) {
13467: if (@statuses) {
1.303 raeburn 13468: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 13469: '<ul>';
1.305 raeburn 13470: foreach my $status (@statuses) {
13471: if ($status eq 'default') {
13472: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 13473: } else {
1.305 raeburn 13474: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 13475: }
13476: }
13477: $chgtext .= '</ul>';
13478: }
13479: } else {
13480: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
13481: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
13482: }
13483: } elsif ($type eq 'emailverified') {
13484: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 13485: all => 'Same as e-mail',
13486: first => 'Omit @domain',
13487: free => 'Free to choose',
1.303 raeburn 13488: );
1.305 raeburn 13489: if (@types) {
13490: if (@statuses) {
1.303 raeburn 13491: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
13492: '<ul>';
1.305 raeburn 13493: foreach my $status (@statuses) {
1.303 raeburn 13494: if ($type eq 'default') {
1.305 raeburn 13495: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 13496: } else {
1.305 raeburn 13497: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 13498: }
13499: }
13500: $chgtext .= '</ul>';
13501: }
13502: } else {
1.305 raeburn 13503: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 13504: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 13505: }
1.305 raeburn 13506: } elsif ($type eq 'emailoptions') {
13507: my %options = &Apache::lonlocal::texthash (
13508: any => 'Any e-mail',
13509: inst => 'Institutional only',
13510: noninst => 'Non-institutional only',
13511: custom => 'Custom restrictions',
13512: );
13513: if (@types) {
13514: if (@statuses) {
13515: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
13516: '<ul>';
13517: foreach my $status (@statuses) {
13518: if ($type eq 'default') {
13519: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
13520: } else {
13521: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 13522: }
13523: }
1.305 raeburn 13524: $chgtext .= '</ul>';
13525: }
13526: } else {
13527: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
13528: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
13529: } else {
13530: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
13531: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 13532: }
1.305 raeburn 13533: }
13534: } elsif ($type eq 'emaildomain') {
13535: my $output;
13536: if (@statuses) {
13537: foreach my $type (@statuses) {
13538: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
13539: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
13540: if ($type eq 'default') {
13541: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13542: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
13543: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
13544: } else {
13545: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
13546: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
13547: }
1.303 raeburn 13548: } else {
1.305 raeburn 13549: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13550: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
13551: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
13552: } else {
13553: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
13554: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
13555: }
1.303 raeburn 13556: }
1.305 raeburn 13557: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
13558: if ($type eq 'default') {
13559: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13560: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
13561: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
13562: } else {
13563: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
13564: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
13565: }
1.303 raeburn 13566: } else {
1.305 raeburn 13567: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13568: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
13569: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
13570: } else {
13571: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
13572: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
13573: }
1.303 raeburn 13574: }
13575: }
13576: }
13577: }
1.305 raeburn 13578: }
13579: if ($output ne '') {
13580: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
13581: '<ul>'.$output.'</ul>';
1.236 raeburn 13582: }
1.165 raeburn 13583: } elsif ($type eq 'captcha') {
1.224 raeburn 13584: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 13585: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
13586: } else {
13587: my %captchas = &captcha_phrases();
1.224 raeburn 13588: if ($captchas{$savecaptcha{$type}}) {
13589: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 13590: } else {
1.210 raeburn 13591: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 13592: }
13593: }
13594: } elsif ($type eq 'recaptchakeys') {
13595: my ($privkey,$pubkey);
1.224 raeburn 13596: if (ref($savecaptcha{$type}) eq 'HASH') {
13597: $pubkey = $savecaptcha{$type}{'public'};
13598: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 13599: }
13600: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
13601: if (!$pubkey) {
13602: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
13603: } else {
13604: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
13605: }
13606: if (!$privkey) {
13607: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
13608: } else {
13609: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
13610: }
13611: $chgtext .= '</ul>';
1.269 raeburn 13612: } elsif ($type eq 'recaptchaversion') {
13613: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 13614: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 13615: }
1.224 raeburn 13616: } elsif ($type eq 'emailusername') {
13617: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 13618: if (@statuses) {
13619: foreach my $type (@statuses) {
1.228 raeburn 13620: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
13621: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 13622: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 13623: '<ul>';
13624: foreach my $field (@{$infofields}) {
13625: if ($cancreate{'emailusername'}{$type}{$field}) {
13626: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
13627: }
13628: }
1.245 raeburn 13629: $chgtext .= '</ul>';
13630: } else {
1.303 raeburn 13631: $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 13632: }
13633: } else {
1.303 raeburn 13634: $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 13635: }
13636: }
13637: }
13638: }
13639: } elsif ($type eq 'notify') {
1.303 raeburn 13640: my $numapprove = 0;
1.224 raeburn 13641: if (ref($changes{'cancreate'}) eq 'ARRAY') {
13642: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
13643: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 13644: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
13645: $numapprove ++;
1.224 raeburn 13646: }
13647: }
1.43 raeburn 13648: }
1.303 raeburn 13649: unless ($numapprove) {
13650: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
13651: }
1.34 raeburn 13652: }
1.224 raeburn 13653: if ($chgtext) {
13654: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 13655: }
13656: }
13657: }
1.305 raeburn 13658: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 13659: my ($emailrules,$emailruleorder) =
13660: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 13661: foreach my $type (@{$changes{'email_rule'}}) {
13662: if (ref($email_rule{$type}) eq 'ARRAY') {
13663: my $chgtext = '<ul>';
13664: foreach my $rule (@{$email_rule{$type}}) {
13665: if (ref($emailrules->{$rule}) eq 'HASH') {
13666: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
13667: }
13668: }
13669: $chgtext .= '</ul>';
1.310 raeburn 13670: my $typename;
1.305 raeburn 13671: if (@types) {
13672: if ($type eq 'default') {
13673: $typename = $othertitle;
13674: } else {
13675: $typename = $usertypes{$type};
13676: }
13677: $chgtext .= &mt('(Affiliation: [_1])',$typename);
13678: }
13679: if (@{$email_rule{$type}} > 0) {
13680: $resulttext .= '<li>'.
13681: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
13682: $usertypes{$type}).
13683: $chgtext.
13684: '</li>';
13685: } else {
13686: $resulttext .= '<li>'.
1.310 raeburn 13687: &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 13688: '</li>'.
1.310 raeburn 13689: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 13690: }
1.43 raeburn 13691: }
13692: }
1.305 raeburn 13693: }
13694: if (ref($changes{'inststatus'}) eq 'ARRAY') {
13695: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
13696: if (@{$save_inststatus{'inststatusguest'}} > 0) {
13697: my $chgtext = '<ul>';
13698: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
13699: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
13700: }
13701: $chgtext .= '</ul>';
13702: $resulttext .= '<li>'.
13703: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
13704: $chgtext.
13705: '</li>';
13706: } else {
13707: $resulttext .= '<li>'.
13708: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
13709: '</li>';
13710: }
1.43 raeburn 13711: }
13712: }
1.224 raeburn 13713: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
13714: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
13715: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13716: foreach my $type (@{$changes{'selfcreate'}}) {
13717: my $typename = $type;
1.303 raeburn 13718: if (keys(%usertypes) > 0) {
13719: if ($usertypes{$type} ne '') {
13720: $typename = $usertypes{$type};
1.224 raeburn 13721: }
13722: }
13723: my @modifiable;
13724: $resulttext .= '<li>'.
13725: &mt('Self-creation of account by users with status: [_1]',
13726: '<span class="LC_cusr_emph">'.$typename.'</span>').
13727: ' - '.&mt('modifiable fields (if institutional data blank): ');
13728: foreach my $field (@fields) {
13729: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
13730: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 13731: }
13732: }
1.224 raeburn 13733: if (@modifiable > 0) {
13734: $resulttext .= join(', ',@modifiable);
1.43 raeburn 13735: } else {
1.224 raeburn 13736: $resulttext .= &mt('none');
1.43 raeburn 13737: }
1.224 raeburn 13738: $resulttext .= '</li>';
1.28 raeburn 13739: }
1.224 raeburn 13740: $resulttext .= '</ul></li>';
1.28 raeburn 13741: }
1.27 raeburn 13742: $resulttext .= '</ul>';
1.305 raeburn 13743: my $cachetime = 24*60*60;
13744: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
13745: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13746: if (ref($lastactref) eq 'HASH') {
13747: $lastactref->{'domdefaults'} = 1;
13748: }
1.27 raeburn 13749: } else {
1.224 raeburn 13750: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 13751: }
13752: } else {
13753: $resulttext = '<span class="LC_error">'.
1.23 raeburn 13754: &mt('An error occurred: [_1]',$putresult).'</span>';
13755: }
1.43 raeburn 13756: if ($warningmsg ne '') {
13757: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
13758: }
1.23 raeburn 13759: return $resulttext;
13760: }
13761:
1.165 raeburn 13762: sub process_captcha {
13763: my ($container,$changes,$newsettings,$current) = @_;
13764: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
13765: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
13766: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
13767: $newsettings->{'captcha'} = 'original';
13768: }
13769: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 13770: if ($container eq 'cancreate') {
1.169 raeburn 13771: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
13772: push(@{$changes->{'cancreate'}},'captcha');
13773: } elsif (!defined($changes->{'cancreate'})) {
13774: $changes->{'cancreate'} = ['captcha'];
13775: }
13776: } else {
13777: $changes->{'captcha'} = 1;
1.165 raeburn 13778: }
13779: }
1.269 raeburn 13780: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 13781: if ($newsettings->{'captcha'} eq 'recaptcha') {
13782: $newpub = $env{'form.'.$container.'_recaptchapub'};
13783: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 13784: $newpub =~ s/[^\w\-]//g;
13785: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 13786: $newsettings->{'recaptchakeys'} = {
13787: public => $newpub,
13788: private => $newpriv,
13789: };
1.269 raeburn 13790: $newversion = $env{'form.'.$container.'_recaptchaversion'};
13791: $newversion =~ s/\D//g;
13792: if ($newversion ne '2') {
13793: $newversion = 1;
13794: }
13795: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 13796: }
13797: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
13798: $currpub = $current->{'recaptchakeys'}{'public'};
13799: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 13800: unless ($newsettings->{'captcha'} eq 'recaptcha') {
13801: $newsettings->{'recaptchakeys'} = {
13802: public => '',
13803: private => '',
13804: }
13805: }
1.165 raeburn 13806: }
1.269 raeburn 13807: if ($current->{'captcha'} eq 'recaptcha') {
13808: $currversion = $current->{'recaptchaversion'};
13809: if ($currversion ne '2') {
13810: $currversion = 1;
13811: }
13812: }
13813: if ($currversion ne $newversion) {
13814: if ($container eq 'cancreate') {
13815: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
13816: push(@{$changes->{'cancreate'}},'recaptchaversion');
13817: } elsif (!defined($changes->{'cancreate'})) {
13818: $changes->{'cancreate'} = ['recaptchaversion'];
13819: }
13820: } else {
13821: $changes->{'recaptchaversion'} = 1;
13822: }
13823: }
1.165 raeburn 13824: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 13825: if ($container eq 'cancreate') {
13826: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
13827: push(@{$changes->{'cancreate'}},'recaptchakeys');
13828: } elsif (!defined($changes->{'cancreate'})) {
13829: $changes->{'cancreate'} = ['recaptchakeys'];
13830: }
13831: } else {
1.210 raeburn 13832: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 13833: }
13834: }
13835: return;
13836: }
13837:
1.33 raeburn 13838: sub modify_usermodification {
13839: my ($dom,%domconfig) = @_;
1.224 raeburn 13840: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 13841: if (ref($domconfig{'usermodification'}) eq 'HASH') {
13842: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 13843: if ($key eq 'selfcreate') {
13844: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
13845: } else {
13846: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
13847: }
1.33 raeburn 13848: }
13849: }
1.224 raeburn 13850: my @contexts = ('author','course');
1.33 raeburn 13851: my %context_title = (
13852: author => 'In author context',
13853: course => 'In course context',
13854: );
13855: my @fields = ('lastname','firstname','middlename','generation',
13856: 'permanentemail','id');
13857: my %roles = (
13858: author => ['ca','aa'],
13859: course => ['st','ep','ta','in','cr'],
13860: );
13861: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13862: foreach my $context (@contexts) {
13863: foreach my $role (@{$roles{$context}}) {
13864: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
13865: foreach my $item (@fields) {
13866: if (grep(/^\Q$item\E$/,@modifiable)) {
13867: $modifyhash{$context}{$role}{$item} = 1;
13868: } else {
13869: $modifyhash{$context}{$role}{$item} = 0;
13870: }
13871: }
13872: }
13873: if (ref($curr_usermodification{$context}) eq 'HASH') {
13874: foreach my $role (@{$roles{$context}}) {
13875: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
13876: foreach my $field (@fields) {
13877: if ($modifyhash{$context}{$role}{$field} ne
13878: $curr_usermodification{$context}{$role}{$field}) {
13879: push(@{$changes{$context}},$role);
13880: last;
13881: }
13882: }
13883: }
13884: }
13885: } else {
13886: foreach my $context (@contexts) {
13887: foreach my $role (@{$roles{$context}}) {
13888: push(@{$changes{$context}},$role);
13889: }
13890: }
13891: }
13892: }
13893: my %usermodification_hash = (
13894: usermodification => \%modifyhash,
13895: );
13896: my $putresult = &Apache::lonnet::put_dom('configuration',
13897: \%usermodification_hash,$dom);
13898: if ($putresult eq 'ok') {
13899: if (keys(%changes) > 0) {
13900: $resulttext = &mt('Changes made: ').'<ul>';
13901: foreach my $context (@contexts) {
13902: if (ref($changes{$context}) eq 'ARRAY') {
13903: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
13904: if (ref($changes{$context}) eq 'ARRAY') {
13905: foreach my $role (@{$changes{$context}}) {
13906: my $rolename;
1.224 raeburn 13907: if ($role eq 'cr') {
13908: $rolename = &mt('Custom');
1.33 raeburn 13909: } else {
1.224 raeburn 13910: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 13911: }
13912: my @modifiable;
1.224 raeburn 13913: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 13914: foreach my $field (@fields) {
13915: if ($modifyhash{$context}{$role}{$field}) {
13916: push(@modifiable,$fieldtitles{$field});
13917: }
13918: }
13919: if (@modifiable > 0) {
13920: $resulttext .= join(', ',@modifiable);
13921: } else {
13922: $resulttext .= &mt('none');
13923: }
13924: $resulttext .= '</li>';
13925: }
13926: $resulttext .= '</ul></li>';
13927: }
13928: }
13929: }
13930: $resulttext .= '</ul>';
13931: } else {
13932: $resulttext = &mt('No changes made to user modification settings');
13933: }
13934: } else {
13935: $resulttext = '<span class="LC_error">'.
13936: &mt('An error occurred: [_1]',$putresult).'</span>';
13937: }
13938: return $resulttext;
13939: }
13940:
1.43 raeburn 13941: sub modify_defaults {
1.212 raeburn 13942: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 13943: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 13944: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 13945: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
13946: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.43 raeburn 13947: my @authtypes = ('internal','krb4','krb5','localauth');
13948: foreach my $item (@items) {
13949: $newvalues{$item} = $env{'form.'.$item};
13950: if ($item eq 'auth_def') {
13951: if ($newvalues{$item} ne '') {
13952: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
13953: push(@errors,$item);
13954: }
13955: }
13956: } elsif ($item eq 'lang_def') {
13957: if ($newvalues{$item} ne '') {
13958: if ($newvalues{$item} =~ /^(\w+)/) {
13959: my $langcode = $1;
1.103 raeburn 13960: if ($langcode ne 'x_chef') {
13961: if (code2language($langcode) eq '') {
13962: push(@errors,$item);
13963: }
1.43 raeburn 13964: }
13965: } else {
13966: push(@errors,$item);
13967: }
13968: }
1.54 raeburn 13969: } elsif ($item eq 'timezone_def') {
13970: if ($newvalues{$item} ne '') {
1.62 raeburn 13971: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 13972: push(@errors,$item);
13973: }
13974: }
1.68 raeburn 13975: } elsif ($item eq 'datelocale_def') {
13976: if ($newvalues{$item} ne '') {
13977: my @datelocale_ids = DateTime::Locale->ids();
13978: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
13979: push(@errors,$item);
13980: }
13981: }
1.141 raeburn 13982: } elsif ($item eq 'portal_def') {
13983: if ($newvalues{$item} ne '') {
13984: 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])\/?$/) {
13985: push(@errors,$item);
13986: }
13987: }
1.294 raeburn 13988: } elsif ($item eq 'intauth_cost') {
13989: if ($newvalues{$item} ne '') {
13990: if ($newvalues{$item} =~ /\D/) {
13991: push(@errors,$item);
13992: }
13993: }
13994: } elsif ($item eq 'intauth_check') {
13995: if ($newvalues{$item} ne '') {
13996: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
13997: push(@errors,$item);
13998: }
13999: }
14000: } elsif ($item eq 'intauth_switch') {
14001: if ($newvalues{$item} ne '') {
14002: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
14003: push(@errors,$item);
14004: }
14005: }
1.43 raeburn 14006: }
14007: if (grep(/^\Q$item\E$/,@errors)) {
14008: $newvalues{$item} = $domdefaults{$item};
14009: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
14010: $changes{$item} = 1;
14011: }
1.72 raeburn 14012: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 14013: }
14014: my %defaults_hash = (
1.72 raeburn 14015: defaults => \%newvalues,
14016: );
1.43 raeburn 14017: my $title = &defaults_titles();
1.236 raeburn 14018:
14019: my $currinststatus;
14020: if (ref($domconfig{'inststatus'}) eq 'HASH') {
14021: $currinststatus = $domconfig{'inststatus'};
14022: } else {
14023: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
14024: $currinststatus = {
14025: inststatustypes => $usertypes,
14026: inststatusorder => $types,
14027: inststatusguest => [],
14028: };
14029: }
14030: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
14031: my @allpos;
14032: my %alltypes;
1.305 raeburn 14033: my @inststatusguest;
14034: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
14035: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
14036: unless (grep(/^\Q$type\E$/,@todelete)) {
14037: push(@inststatusguest,$type);
14038: }
14039: }
14040: }
14041: my ($currtitles,$currorder);
1.236 raeburn 14042: if (ref($currinststatus) eq 'HASH') {
14043: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
14044: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
14045: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
14046: if ($currinststatus->{inststatustypes}->{$type} ne '') {
14047: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
14048: }
14049: }
14050: unless (grep(/^\Q$type\E$/,@todelete)) {
14051: my $position = $env{'form.inststatus_pos_'.$type};
14052: $position =~ s/\D+//g;
14053: $allpos[$position] = $type;
14054: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
14055: $alltypes{$type} =~ s/`//g;
14056: }
14057: }
14058: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
14059: $currtitles =~ s/,$//;
14060: }
14061: }
14062: if ($env{'form.addinststatus'}) {
14063: my $newtype = $env{'form.addinststatus'};
14064: $newtype =~ s/\W//g;
14065: unless (exists($alltypes{$newtype})) {
14066: $alltypes{$newtype} = $env{'form.addinststatus_title'};
14067: $alltypes{$newtype} =~ s/`//g;
14068: my $position = $env{'form.addinststatus_pos'};
14069: $position =~ s/\D+//g;
14070: if ($position ne '') {
14071: $allpos[$position] = $newtype;
14072: }
14073: }
14074: }
1.305 raeburn 14075: my @orderedstatus;
1.236 raeburn 14076: foreach my $type (@allpos) {
14077: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
14078: push(@orderedstatus,$type);
14079: }
14080: }
14081: foreach my $type (keys(%alltypes)) {
14082: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
14083: delete($alltypes{$type});
14084: }
14085: }
14086: $defaults_hash{'inststatus'} = {
14087: inststatustypes => \%alltypes,
14088: inststatusorder => \@orderedstatus,
1.305 raeburn 14089: inststatusguest => \@inststatusguest,
1.236 raeburn 14090: };
14091: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
14092: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
14093: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
14094: }
14095: }
14096: if ($currorder ne join(',',@orderedstatus)) {
14097: $changes{'inststatus'}{'inststatusorder'} = 1;
14098: }
14099: my $newtitles;
14100: foreach my $item (@orderedstatus) {
14101: $newtitles .= $alltypes{$item}.',';
14102: }
14103: $newtitles =~ s/,$//;
14104: if ($currtitles ne $newtitles) {
14105: $changes{'inststatus'}{'inststatustypes'} = 1;
14106: }
1.43 raeburn 14107: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
14108: $dom);
14109: if ($putresult eq 'ok') {
14110: if (keys(%changes) > 0) {
14111: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 14112: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 14113: 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";
14114: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 14115: if ($item eq 'inststatus') {
14116: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 14117: if (@orderedstatus) {
1.236 raeburn 14118: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
14119: foreach my $type (@orderedstatus) {
14120: $resulttext .= $alltypes{$type}.', ';
14121: }
14122: $resulttext =~ s/, $//;
14123: $resulttext .= '</li>';
1.305 raeburn 14124: } else {
14125: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 14126: }
14127: }
14128: } else {
14129: my $value = $env{'form.'.$item};
14130: if ($value eq '') {
14131: $value = &mt('none');
14132: } elsif ($item eq 'auth_def') {
14133: my %authnames = &authtype_names();
14134: my %shortauth = (
14135: internal => 'int',
14136: krb4 => 'krb4',
14137: krb5 => 'krb5',
14138: localauth => 'loc',
14139: );
14140: $value = $authnames{$shortauth{$value}};
1.294 raeburn 14141: } elsif ($item eq 'intauth_switch') {
14142: my %optiondesc = &Apache::lonlocal::texthash (
14143: 0 => 'No',
14144: 1 => 'Yes',
14145: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
14146: );
14147: if ($value =~ /^(0|1|2)$/) {
14148: $value = $optiondesc{$value};
14149: } else {
14150: $value = &mt('none -- defaults to No');
14151: }
14152: } elsif ($item eq 'intauth_check') {
14153: my %optiondesc = &Apache::lonlocal::texthash (
14154: 0 => 'No',
14155: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
14156: 2 => 'Yes, disallow login if stored cost is less than domain default',
14157: );
14158: if ($value =~ /^(0|1|2)$/) {
14159: $value = $optiondesc{$value};
14160: } else {
14161: $value = &mt('none -- defaults to No');
14162: }
1.236 raeburn 14163: }
14164: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
14165: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 14166: }
14167: }
14168: $resulttext .= '</ul>';
14169: $mailmsgtext .= "\n";
14170: my $cachetime = 24*60*60;
1.72 raeburn 14171: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 14172: if (ref($lastactref) eq 'HASH') {
14173: $lastactref->{'domdefaults'} = 1;
14174: }
1.68 raeburn 14175: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 14176: my $notify = 1;
14177: if (ref($domconfig{'contacts'}) eq 'HASH') {
14178: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
14179: $notify = 0;
14180: }
14181: }
14182: if ($notify) {
14183: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
14184: "LON-CAPA Domain Settings Change - $dom",
14185: $mailmsgtext);
14186: }
1.54 raeburn 14187: }
1.43 raeburn 14188: } else {
1.54 raeburn 14189: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 14190: }
14191: } else {
14192: $resulttext = '<span class="LC_error">'.
14193: &mt('An error occurred: [_1]',$putresult).'</span>';
14194: }
14195: if (@errors > 0) {
14196: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
14197: foreach my $item (@errors) {
14198: $resulttext .= ' "'.$title->{$item}.'",';
14199: }
14200: $resulttext =~ s/,$//;
14201: }
14202: return $resulttext;
14203: }
14204:
1.46 raeburn 14205: sub modify_scantron {
1.205 raeburn 14206: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 14207: my ($resulttext,%confhash,%changes,$errors);
14208: my $custom = 'custom.tab';
14209: my $default = 'default.tab';
14210: my $servadm = $r->dir_config('lonAdmEMail');
14211: my ($configuserok,$author_ok,$switchserver) =
14212: &config_check($dom,$confname,$servadm);
14213: if ($env{'form.scantronformat.filename'} ne '') {
14214: my $error;
14215: if ($configuserok eq 'ok') {
14216: if ($switchserver) {
1.130 raeburn 14217: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 14218: } else {
14219: if ($author_ok eq 'ok') {
14220: my ($result,$scantronurl) =
14221: &publishlogo($r,'upload','scantronformat',$dom,
14222: $confname,'scantron','','',$custom);
14223: if ($result eq 'ok') {
14224: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 14225: $changes{'scantronformat'} = 1;
1.46 raeburn 14226: } else {
14227: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
14228: }
14229: } else {
14230: $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);
14231: }
14232: }
14233: } else {
14234: $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);
14235: }
14236: if ($error) {
14237: &Apache::lonnet::logthis($error);
14238: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14239: }
14240: }
1.48 raeburn 14241: if (ref($domconfig{'scantron'}) eq 'HASH') {
14242: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
14243: if ($env{'form.scantronformat_del'}) {
14244: $confhash{'scantron'}{'scantronformat'} = '';
14245: $changes{'scantronformat'} = 1;
1.46 raeburn 14246: }
14247: }
14248: }
14249: if (keys(%confhash) > 0) {
14250: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
14251: $dom);
14252: if ($putresult eq 'ok') {
14253: if (keys(%changes) > 0) {
1.48 raeburn 14254: if (ref($confhash{'scantron'}) eq 'HASH') {
14255: $resulttext = &mt('Changes made:').'<ul>';
14256: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 14257: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 14258: } else {
1.130 raeburn 14259: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 14260: }
1.48 raeburn 14261: $resulttext .= '</ul>';
14262: } else {
1.130 raeburn 14263: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 14264: }
14265: $resulttext .= '</ul>';
14266: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 14267: if (ref($lastactref) eq 'HASH') {
14268: $lastactref->{'domainconfig'} = 1;
14269: }
1.46 raeburn 14270: } else {
1.130 raeburn 14271: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 14272: }
14273: } else {
14274: $resulttext = '<span class="LC_error">'.
14275: &mt('An error occurred: [_1]',$putresult).'</span>';
14276: }
14277: } else {
1.130 raeburn 14278: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 14279: }
14280: if ($errors) {
14281: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14282: $errors.'</ul>';
14283: }
14284: return $resulttext;
14285: }
14286:
1.48 raeburn 14287: sub modify_coursecategories {
1.239 raeburn 14288: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 14289: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
14290: $cathash);
1.48 raeburn 14291: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 14292: my @catitems = ('unauth','auth');
14293: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 14294: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 14295: $cathash = $domconfig{'coursecategories'}{'cats'};
14296: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
14297: $changes{'togglecats'} = 1;
14298: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
14299: }
14300: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
14301: $changes{'categorize'} = 1;
14302: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
14303: }
1.120 raeburn 14304: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
14305: $changes{'togglecatscomm'} = 1;
14306: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
14307: }
14308: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
14309: $changes{'categorizecomm'} = 1;
14310: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 14311:
14312: }
14313: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
14314: $changes{'togglecatsplace'} = 1;
14315: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
14316: }
14317: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
14318: $changes{'categorizeplace'} = 1;
14319: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 14320: }
1.238 raeburn 14321: foreach my $item (@catitems) {
14322: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
14323: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
14324: $changes{$item} = 1;
14325: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
14326: }
14327: }
14328: }
1.57 raeburn 14329: } else {
14330: $changes{'togglecats'} = 1;
14331: $changes{'categorize'} = 1;
1.124 raeburn 14332: $changes{'togglecatscomm'} = 1;
14333: $changes{'categorizecomm'} = 1;
1.272 raeburn 14334: $changes{'togglecatsplace'} = 1;
14335: $changes{'categorizeplace'} = 1;
1.87 raeburn 14336: $domconfig{'coursecategories'} = {
14337: togglecats => $env{'form.togglecats'},
14338: categorize => $env{'form.categorize'},
1.124 raeburn 14339: togglecatscomm => $env{'form.togglecatscomm'},
14340: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 14341: togglecatsplace => $env{'form.togglecatsplace'},
14342: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 14343: };
1.238 raeburn 14344: foreach my $item (@catitems) {
14345: if ($env{'form.coursecat_'.$item} ne 'std') {
14346: $changes{$item} = 1;
14347: }
14348: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
14349: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
14350: }
14351: }
1.57 raeburn 14352: }
14353: if (ref($cathash) eq 'HASH') {
14354: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 14355: push (@deletecategory,'instcode::0');
14356: }
1.120 raeburn 14357: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
14358: push(@deletecategory,'communities::0');
14359: }
1.272 raeburn 14360: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
14361: push(@deletecategory,'placement::0');
14362: }
1.48 raeburn 14363: }
1.57 raeburn 14364: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
14365: if (ref($cathash) eq 'HASH') {
1.48 raeburn 14366: if (@deletecategory > 0) {
14367: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 14368: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 14369: foreach my $item (@deletecategory) {
1.57 raeburn 14370: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
14371: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 14372: $deletions{$item} = 1;
1.57 raeburn 14373: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 14374: }
14375: }
14376: }
1.57 raeburn 14377: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 14378: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 14379: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 14380: $reorderings{$item} = 1;
1.57 raeburn 14381: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 14382: }
14383: if ($env{'form.addcategory_name_'.$item} ne '') {
14384: my $newcat = $env{'form.addcategory_name_'.$item};
14385: my $newdepth = $depth+1;
14386: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 14387: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 14388: $adds{$newitem} = 1;
14389: }
14390: if ($env{'form.subcat_'.$item} ne '') {
14391: my $newcat = $env{'form.subcat_'.$item};
14392: my $newdepth = $depth+1;
14393: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 14394: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 14395: $adds{$newitem} = 1;
14396: }
14397: }
14398: }
14399: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 14400: if (ref($cathash) eq 'HASH') {
1.48 raeburn 14401: my $newitem = 'instcode::0';
1.57 raeburn 14402: if ($cathash->{$newitem} eq '') {
14403: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 14404: $adds{$newitem} = 1;
14405: }
14406: } else {
14407: my $newitem = 'instcode::0';
1.57 raeburn 14408: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 14409: $adds{$newitem} = 1;
14410: }
14411: }
1.120 raeburn 14412: if ($env{'form.communities'} eq '1') {
14413: if (ref($cathash) eq 'HASH') {
14414: my $newitem = 'communities::0';
14415: if ($cathash->{$newitem} eq '') {
14416: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
14417: $adds{$newitem} = 1;
14418: }
14419: } else {
14420: my $newitem = 'communities::0';
14421: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
14422: $adds{$newitem} = 1;
14423: }
14424: }
1.272 raeburn 14425: if ($env{'form.placement'} eq '1') {
14426: if (ref($cathash) eq 'HASH') {
14427: my $newitem = 'placement::0';
14428: if ($cathash->{$newitem} eq '') {
14429: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
14430: $adds{$newitem} = 1;
14431: }
14432: } else {
14433: my $newitem = 'placement::0';
14434: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
14435: $adds{$newitem} = 1;
14436: }
14437: }
1.48 raeburn 14438: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 14439: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 14440: ($env{'form.addcategory_name'} ne 'communities') &&
14441: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 14442: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
14443: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
14444: $adds{$newitem} = 1;
14445: }
1.48 raeburn 14446: }
1.57 raeburn 14447: my $putresult;
1.48 raeburn 14448: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14449: if (keys(%deletions) > 0) {
14450: foreach my $key (keys(%deletions)) {
14451: if ($predelallitems{$key} ne '') {
14452: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
14453: }
14454: }
14455: }
14456: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 14457: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 14458: if (ref($chkcats[0]) eq 'ARRAY') {
14459: my $depth = 0;
14460: my $chg = 0;
14461: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
14462: my $name = $chkcats[0][$i];
14463: my $item;
14464: if ($name eq '') {
14465: $chg ++;
14466: } else {
14467: $item = &escape($name).'::0';
14468: if ($chg) {
1.57 raeburn 14469: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 14470: }
14471: $depth ++;
1.57 raeburn 14472: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 14473: $depth --;
14474: }
14475: }
14476: }
1.57 raeburn 14477: }
14478: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14479: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 14480: if ($putresult eq 'ok') {
1.57 raeburn 14481: my %title = (
1.120 raeburn 14482: togglecats => 'Show/Hide a course in catalog',
14483: categorize => 'Assign a category to a course',
14484: togglecatscomm => 'Show/Hide a community in catalog',
14485: categorizecomm => 'Assign a category to a community',
1.57 raeburn 14486: );
14487: my %level = (
1.120 raeburn 14488: dom => 'set in Domain ("Modify Course/Community")',
14489: crs => 'set in Course ("Course Configuration")',
14490: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 14491: none => 'No catalog',
14492: std => 'Standard catalog',
14493: domonly => 'Domain-only catalog',
14494: codesrch => 'Code search form',
1.57 raeburn 14495: );
1.48 raeburn 14496: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 14497: if ($changes{'togglecats'}) {
14498: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
14499: }
14500: if ($changes{'categorize'}) {
14501: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 14502: }
1.120 raeburn 14503: if ($changes{'togglecatscomm'}) {
14504: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
14505: }
14506: if ($changes{'categorizecomm'}) {
14507: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
14508: }
1.238 raeburn 14509: if ($changes{'unauth'}) {
14510: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
14511: }
14512: if ($changes{'auth'}) {
14513: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
14514: }
1.57 raeburn 14515: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14516: my $cathash;
14517: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
14518: $cathash = $domconfig{'coursecategories'}{'cats'};
14519: } else {
14520: $cathash = {};
14521: }
14522: my (@cats,@trails,%allitems);
14523: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
14524: if (keys(%deletions) > 0) {
14525: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
14526: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
14527: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
14528: }
14529: $resulttext .= '</ul></li>';
14530: }
14531: if (keys(%reorderings) > 0) {
14532: my %sort_by_trail;
14533: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
14534: foreach my $key (keys(%reorderings)) {
14535: if ($allitems{$key} ne '') {
14536: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
14537: }
1.48 raeburn 14538: }
1.57 raeburn 14539: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
14540: $resulttext .= '<li>'.$trails[$trail].'</li>';
14541: }
14542: $resulttext .= '</ul></li>';
1.48 raeburn 14543: }
1.57 raeburn 14544: if (keys(%adds) > 0) {
14545: my %sort_by_trail;
14546: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
14547: foreach my $key (keys(%adds)) {
14548: if ($allitems{$key} ne '') {
14549: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
14550: }
14551: }
14552: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
14553: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 14554: }
1.57 raeburn 14555: $resulttext .= '</ul></li>';
1.48 raeburn 14556: }
14557: }
14558: $resulttext .= '</ul>';
1.239 raeburn 14559: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 14560: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
14561: if ($changes{'auth'}) {
14562: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
14563: }
14564: if ($changes{'unauth'}) {
14565: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
14566: }
14567: my $cachetime = 24*60*60;
14568: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 14569: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 14570: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 14571: }
14572: }
1.48 raeburn 14573: } else {
14574: $resulttext = '<span class="LC_error">'.
1.57 raeburn 14575: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 14576: }
14577: } else {
1.120 raeburn 14578: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 14579: }
14580: return $resulttext;
14581: }
14582:
1.69 raeburn 14583: sub modify_serverstatuses {
14584: my ($dom,%domconfig) = @_;
14585: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
14586: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
14587: %currserverstatus = %{$domconfig{'serverstatuses'}};
14588: }
14589: my @pages = &serverstatus_pages();
14590: foreach my $type (@pages) {
14591: $newserverstatus{$type}{'namedusers'} = '';
14592: $newserverstatus{$type}{'machines'} = '';
14593: if (defined($env{'form.'.$type.'_namedusers'})) {
14594: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
14595: my @okusers;
14596: foreach my $user (@users) {
14597: my ($uname,$udom) = split(/:/,$user);
14598: if (($udom =~ /^$match_domain$/) &&
14599: (&Apache::lonnet::domain($udom)) &&
14600: ($uname =~ /^$match_username$/)) {
14601: if (!grep(/^\Q$user\E/,@okusers)) {
14602: push(@okusers,$user);
14603: }
14604: }
14605: }
14606: if (@okusers > 0) {
14607: @okusers = sort(@okusers);
14608: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
14609: }
14610: }
14611: if (defined($env{'form.'.$type.'_machines'})) {
14612: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
14613: my @okmachines;
14614: foreach my $ip (@machines) {
14615: my @parts = split(/\./,$ip);
14616: next if (@parts < 4);
14617: my $badip = 0;
14618: for (my $i=0; $i<4; $i++) {
14619: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
14620: $badip = 1;
14621: last;
14622: }
14623: }
14624: if (!$badip) {
14625: push(@okmachines,$ip);
14626: }
14627: }
14628: @okmachines = sort(@okmachines);
14629: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
14630: }
14631: }
14632: my %serverstatushash = (
14633: serverstatuses => \%newserverstatus,
14634: );
14635: foreach my $type (@pages) {
1.83 raeburn 14636: foreach my $setting ('namedusers','machines') {
1.84 raeburn 14637: my (@current,@new);
1.83 raeburn 14638: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 14639: if ($currserverstatus{$type}{$setting} ne '') {
14640: @current = split(/,/,$currserverstatus{$type}{$setting});
14641: }
14642: }
14643: if ($newserverstatus{$type}{$setting} ne '') {
14644: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 14645: }
14646: if (@current > 0) {
14647: if (@new > 0) {
14648: foreach my $item (@current) {
14649: if (!grep(/^\Q$item\E$/,@new)) {
14650: $changes{$type}{$setting} = 1;
1.82 raeburn 14651: last;
14652: }
14653: }
1.84 raeburn 14654: foreach my $item (@new) {
14655: if (!grep(/^\Q$item\E$/,@current)) {
14656: $changes{$type}{$setting} = 1;
14657: last;
1.82 raeburn 14658: }
14659: }
14660: } else {
1.83 raeburn 14661: $changes{$type}{$setting} = 1;
1.69 raeburn 14662: }
1.83 raeburn 14663: } elsif (@new > 0) {
14664: $changes{$type}{$setting} = 1;
1.69 raeburn 14665: }
14666: }
14667: }
14668: if (keys(%changes) > 0) {
1.81 raeburn 14669: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 14670: my $putresult = &Apache::lonnet::put_dom('configuration',
14671: \%serverstatushash,$dom);
14672: if ($putresult eq 'ok') {
14673: $resulttext .= &mt('Changes made:').'<ul>';
14674: foreach my $type (@pages) {
1.84 raeburn 14675: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 14676: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 14677: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 14678: if ($newserverstatus{$type}{'namedusers'} eq '') {
14679: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
14680: } else {
14681: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
14682: }
1.84 raeburn 14683: }
14684: if ($changes{$type}{'machines'}) {
1.69 raeburn 14685: if ($newserverstatus{$type}{'machines'} eq '') {
14686: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
14687: } else {
14688: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
14689: }
14690:
14691: }
14692: $resulttext .= '</ul></li>';
14693: }
14694: }
14695: $resulttext .= '</ul>';
14696: } else {
14697: $resulttext = '<span class="LC_error">'.
14698: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
14699:
14700: }
14701: } else {
14702: $resulttext = &mt('No changes made to access to server status pages');
14703: }
14704: return $resulttext;
14705: }
14706:
1.118 jms 14707: sub modify_helpsettings {
1.285 raeburn 14708: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 14709: my ($resulttext,$errors,%changes,%helphash);
14710: my %defaultchecked = ('submitbugs' => 'on');
14711: my @offon = ('off','on');
1.118 jms 14712: my @toggles = ('submitbugs');
1.285 raeburn 14713: my %current = ('submitbugs' => '',
14714: 'adhoc' => {},
14715: );
1.118 jms 14716: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 14717: %current = %{$domconfig{'helpsettings'}};
14718: }
1.285 raeburn 14719: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 14720: foreach my $item (@toggles) {
14721: if ($defaultchecked{$item} eq 'on') {
14722: if ($current{$item} eq '') {
14723: if ($env{'form.'.$item} eq '0') {
14724: $changes{$item} = 1;
14725: }
14726: } elsif ($current{$item} ne $env{'form.'.$item}) {
14727: $changes{$item} = 1;
14728: }
14729: } elsif ($defaultchecked{$item} eq 'off') {
14730: if ($current{$item} eq '') {
14731: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 14732: $changes{$item} = 1;
14733: }
1.282 raeburn 14734: } elsif ($current{$item} ne $env{'form.'.$item}) {
14735: $changes{$item} = 1;
14736: }
14737: }
14738: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
14739: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
14740: }
14741: }
1.285 raeburn 14742: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 14743: my $confname = $dom.'-domainconfig';
14744: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 14745: my (@allpos,%newsettings,%changedprivs,$newrole);
14746: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 14747: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 14748: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 14749: my %lt = &Apache::lonlocal::texthash(
14750: s => 'system',
14751: d => 'domain',
14752: order => 'Display order',
14753: access => 'Role usage',
1.291 raeburn 14754: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 14755: dh => 'All with domain helpdesk role',
14756: da => 'All with domain helpdesk assistant role',
1.285 raeburn 14757: none => 'None',
14758: status => 'Determined based on institutional status',
14759: inc => 'Include all, but exclude specific personnel',
14760: exc => 'Exclude all, but include specific personnel',
14761: );
14762: for (my $num=0; $num<=$maxnum; $num++) {
14763: my ($prefix,$identifier,$rolename,%curr);
14764: if ($num == $maxnum) {
14765: next unless ($env{'form.newcusthelp'} == $maxnum);
14766: $identifier = 'custhelp'.$num;
14767: $prefix = 'helproles_'.$num;
14768: $rolename = $env{'form.custhelpname'.$num};
14769: $rolename=~s/[^A-Za-z0-9]//gs;
14770: next if ($rolename eq '');
14771: next if (exists($existing{'rolesdef_'.$rolename}));
14772: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
14773: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
14774: $newprivs{'c'},$confname,$dom);
14775: if ($result ne 'ok') {
14776: $errors .= '<li><span class="LC_error">'.
14777: &mt('An error occurred storing the new custom role: [_1]',
14778: $result).'</span></li>';
14779: next;
14780: } else {
14781: $changedprivs{$rolename} = \%newprivs;
14782: $newrole = $rolename;
14783: }
14784: } else {
14785: $prefix = 'helproles_'.$num;
14786: $rolename = $env{'form.'.$prefix};
14787: next if ($rolename eq '');
14788: next unless (exists($existing{'rolesdef_'.$rolename}));
14789: $identifier = 'custhelp'.$num;
14790: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
14791: my %currprivs;
1.289 raeburn 14792: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 14793: split(/\_/,$existing{'rolesdef_'.$rolename});
14794: foreach my $level ('c','d','s') {
14795: if ($newprivs{$level} ne $currprivs{$level}) {
14796: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
14797: $newprivs{'c'},$confname,$dom);
14798: if ($result ne 'ok') {
14799: $errors .= '<li><span class="LC_error">'.
14800: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
14801: $rolename,$result).'</span></li>';
14802: } else {
14803: $changedprivs{$rolename} = \%newprivs;
14804: }
14805: last;
14806: }
14807: }
14808: if (ref($current{'adhoc'}) eq 'HASH') {
14809: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
14810: %curr = %{$current{'adhoc'}{$rolename}};
14811: }
14812: }
14813: }
14814: my $newpos = $env{'form.'.$prefix.'_pos'};
14815: $newpos =~ s/\D+//g;
14816: $allpos[$newpos] = $rolename;
14817: my $newdesc = $env{'form.'.$prefix.'_desc'};
14818: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
14819: if ($curr{'desc'}) {
14820: if ($curr{'desc'} ne $newdesc) {
14821: $changes{'customrole'}{$rolename}{'desc'} = 1;
14822: $newsettings{$rolename}{'desc'} = $newdesc;
14823: }
14824: } elsif ($newdesc ne '') {
14825: $changes{'customrole'}{$rolename}{'desc'} = 1;
14826: $newsettings{$rolename}{'desc'} = $newdesc;
14827: }
14828: my $access = $env{'form.'.$prefix.'_access'};
14829: if (grep(/^\Q$access\E$/,@accesstypes)) {
14830: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
14831: if ($access eq 'status') {
14832: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
14833: if (scalar(@statuses) == 0) {
1.289 raeburn 14834: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 14835: } else {
14836: my (@shownstatus,$numtypes);
14837: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
14838: if (ref($types) eq 'ARRAY') {
14839: $numtypes = scalar(@{$types});
14840: foreach my $type (sort(@statuses)) {
14841: if ($type eq 'default') {
14842: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
14843: } elsif (grep(/^\Q$type\E$/,@{$types})) {
14844: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
14845: push(@shownstatus,$usertypes->{$type});
14846: }
14847: }
14848: }
14849: if (grep(/^default$/,@statuses)) {
14850: push(@shownstatus,$othertitle);
14851: }
14852: if (scalar(@shownstatus) == 1+$numtypes) {
14853: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
14854: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
14855: } else {
14856: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
14857: if (ref($curr{'status'}) eq 'ARRAY') {
14858: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
14859: if (@diffs) {
14860: $changes{'customrole'}{$rolename}{$access} = 1;
14861: }
14862: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
14863: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 14864: }
1.166 raeburn 14865: }
14866: }
1.285 raeburn 14867: } elsif (($access eq 'inc') || ($access eq 'exc')) {
14868: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
14869: my @newspecstaff;
14870: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
14871: foreach my $person (sort(@personnel)) {
14872: if ($domhelpdesk{$person}) {
14873: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
14874: }
14875: }
14876: if (ref($curr{$access}) eq 'ARRAY') {
14877: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
14878: if (@diffs) {
14879: $changes{'customrole'}{$rolename}{$access} = 1;
14880: }
14881: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
14882: $changes{'customrole'}{$rolename}{$access} = 1;
14883: }
14884: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
14885: my ($uname,$udom) = split(/:/,$person);
14886: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
14887: }
14888: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 14889: }
1.285 raeburn 14890: } else {
14891: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
14892: }
14893: unless ($curr{'access'} eq $access) {
14894: $changes{'customrole'}{$rolename}{'access'} = 1;
14895: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 14896: }
14897: }
1.285 raeburn 14898: if (@allpos > 0) {
14899: my $idx = 0;
14900: foreach my $rolename (@allpos) {
14901: if ($rolename ne '') {
14902: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
14903: if (ref($current{'adhoc'}) eq 'HASH') {
14904: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
14905: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
14906: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 14907: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 14908: }
14909: }
1.282 raeburn 14910: }
1.285 raeburn 14911: $idx ++;
1.166 raeburn 14912: }
14913: }
1.118 jms 14914: }
1.123 jms 14915: my $putresult;
14916: if (keys(%changes) > 0) {
1.166 raeburn 14917: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 14918: if ($putresult eq 'ok') {
1.285 raeburn 14919: if (ref($helphash{'helpsettings'}) eq 'HASH') {
14920: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
14921: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
14922: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
14923: }
14924: }
14925: my $cachetime = 24*60*60;
14926: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14927: if (ref($lastactref) eq 'HASH') {
14928: $lastactref->{'domdefaults'} = 1;
14929: }
14930: } else {
14931: $errors .= '<li><span class="LC_error">'.
14932: &mt('An error occurred storing the settings: [_1]',
14933: $putresult).'</span></li>';
14934: }
14935: }
14936: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
14937: $resulttext = &mt('Changes made:').'<ul>';
14938: my (%shownprivs,@levelorder);
14939: @levelorder = ('c','d','s');
14940: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 14941: foreach my $item (sort(keys(%changes))) {
14942: if ($item eq 'submitbugs') {
14943: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
14944: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
14945: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 14946: } elsif ($item eq 'customrole') {
14947: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 14948: my @keyorder = ('order','desc','access','status','exc','inc');
14949: my %keytext = &Apache::lonlocal::texthash(
14950: order => 'Order',
14951: desc => 'Role description',
14952: access => 'Role usage',
1.300 droeschl 14953: status => 'Allowed institutional types',
1.285 raeburn 14954: exc => 'Allowed personnel',
14955: inc => 'Disallowed personnel',
14956: );
1.282 raeburn 14957: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 14958: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
14959: if ($role eq $newrole) {
14960: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
14961: $role).'<ul>';
14962: } else {
14963: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
14964: $role).'<ul>';
14965: }
14966: foreach my $key (@keyorder) {
14967: if ($changes{'customrole'}{$role}{$key}) {
14968: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
14969: $keytext{$key},$newsettings{$role}{$key}).
14970: '</li>';
14971: }
14972: }
14973: if (ref($changedprivs{$role}) eq 'HASH') {
14974: $shownprivs{$role} = 1;
14975: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
14976: foreach my $level (@levelorder) {
14977: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
14978: next if ($item eq '');
14979: my ($priv) = split(/\&/,$item,2);
14980: if (&Apache::lonnet::plaintext($priv)) {
14981: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
14982: unless ($level eq 'c') {
14983: $resulttext .= ' ('.$lt{$level}.')';
14984: }
14985: $resulttext .= '</li>';
14986: }
14987: }
14988: }
14989: $resulttext .= '</ul>';
14990: }
14991: $resulttext .= '</ul></li>';
14992: }
14993: }
14994: }
14995: }
14996: }
14997: }
14998: if (keys(%changedprivs)) {
14999: foreach my $role (sort(keys(%changedprivs))) {
15000: unless ($shownprivs{$role}) {
15001: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15002: $role).'<ul>'.
15003: '<li>'.&mt('Privileges set to :').'<ul>';
15004: foreach my $level (@levelorder) {
15005: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
15006: next if ($item eq '');
15007: my ($priv) = split(/\&/,$item,2);
15008: if (&Apache::lonnet::plaintext($priv)) {
15009: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
15010: unless ($level eq 'c') {
15011: $resulttext .= ' ('.$lt{$level}.')';
15012: }
15013: $resulttext .= '</li>';
15014: }
1.282 raeburn 15015: }
15016: }
1.285 raeburn 15017: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 15018: }
15019: }
15020: }
1.285 raeburn 15021: $resulttext .= '</ul>';
15022: } else {
15023: $resulttext = &mt('No changes made to help settings');
1.118 jms 15024: }
15025: if ($errors) {
1.168 raeburn 15026: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 15027: $errors.'</ul>';
1.118 jms 15028: }
15029: return $resulttext;
15030: }
15031:
1.121 raeburn 15032: sub modify_coursedefaults {
1.212 raeburn 15033: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 15034: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 15035: my %defaultchecked = (
15036: 'canuse_pdfforms' => 'off',
15037: 'uselcmath' => 'on',
15038: 'usejsme' => 'on'
15039: );
15040: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 15041: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 15042: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
15043: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
15044: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 15045: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 15046: my %staticdefaults = (
15047: anonsurvey_threshold => 10,
15048: uploadquota => 500,
1.257 raeburn 15049: postsubmit => 60,
1.276 raeburn 15050: mysqltables => 172800,
1.198 raeburn 15051: );
1.314 raeburn 15052: my %texoptions = (
15053: MathJax => 'MathJax',
15054: mimetex => &mt('Convert to Images'),
15055: tth => &mt('TeX to HTML'),
15056: );
1.121 raeburn 15057: $defaultshash{'coursedefaults'} = {};
15058:
15059: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
15060: if ($domconfig{'coursedefaults'} eq '') {
15061: $domconfig{'coursedefaults'} = {};
15062: }
15063: }
15064:
15065: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
15066: foreach my $item (@toggles) {
15067: if ($defaultchecked{$item} eq 'on') {
15068: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15069: ($env{'form.'.$item} eq '0')) {
15070: $changes{$item} = 1;
1.192 raeburn 15071: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 15072: $changes{$item} = 1;
15073: }
15074: } elsif ($defaultchecked{$item} eq 'off') {
15075: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15076: ($env{'form.'.$item} eq '1')) {
15077: $changes{$item} = 1;
15078: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
15079: $changes{$item} = 1;
15080: }
15081: }
15082: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
15083: }
1.198 raeburn 15084: foreach my $item (@numbers) {
15085: my ($currdef,$newdef);
1.208 raeburn 15086: $newdef = $env{'form.'.$item};
1.198 raeburn 15087: if ($item eq 'anonsurvey_threshold') {
15088: $currdef = $domconfig{'coursedefaults'}{$item};
15089: $newdef =~ s/\D//g;
15090: if ($newdef eq '' || $newdef < 1) {
15091: $newdef = 1;
15092: }
15093: $defaultshash{'coursedefaults'}{$item} = $newdef;
15094: } else {
1.276 raeburn 15095: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
15096: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
15097: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 15098: }
15099: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 15100: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 15101: }
15102: if ($currdef ne $newdef) {
15103: my $staticdef;
15104: if ($item eq 'anonsurvey_threshold') {
15105: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
15106: $changes{$item} = 1;
15107: }
1.276 raeburn 15108: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 15109: my $setting = $1;
1.276 raeburn 15110: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
15111: $changes{$setting} = 1;
1.198 raeburn 15112: }
15113: }
1.139 raeburn 15114: }
15115: }
1.314 raeburn 15116: my $texengine;
15117: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
15118: $texengine = $env{'form.texengine'};
15119: if ($defaultshash{'coursedefaults'}{'texengine'} eq '') {
15120: unless ($texengine eq 'MathJax') {
15121: $changes{'texengine'} = 1;
15122: }
15123: } elsif ($defaultshash{'coursedefaults'}{'texengine'} ne $texengine) {
15124: $changes{'texengine'} = 1;
15125: }
15126: }
15127: if ($texengine ne '') {
15128: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
15129: }
1.264 raeburn 15130: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
15131: my @currclonecode;
15132: if (ref($currclone) eq 'HASH') {
15133: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
15134: @currclonecode = @{$currclone->{'instcode'}};
15135: }
15136: }
15137: my $newclone;
1.289 raeburn 15138: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 15139: $newclone = $env{'form.canclone'};
15140: }
15141: if ($newclone eq 'instcode') {
15142: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
15143: my (%codedefaults,@code_order,@clonecode);
15144: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
15145: \@code_order);
15146: foreach my $item (@code_order) {
15147: if (grep(/^\Q$item\E$/,@newcodes)) {
15148: push(@clonecode,$item);
15149: }
15150: }
15151: if (@clonecode) {
15152: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
15153: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
15154: if (@diffs) {
15155: $changes{'canclone'} = 1;
15156: }
15157: } else {
15158: $newclone eq '';
15159: }
15160: } elsif ($newclone ne '') {
1.289 raeburn 15161: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
15162: }
1.264 raeburn 15163: if ($newclone ne $currclone) {
15164: $changes{'canclone'} = 1;
15165: }
1.257 raeburn 15166: my %credits;
15167: foreach my $type (@types) {
15168: unless ($type eq 'community') {
15169: $credits{$type} = $env{'form.'.$type.'_credits'};
15170: $credits{$type} =~ s/[^\d.]+//g;
15171: }
15172: }
15173: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
15174: ($env{'form.coursecredits'} eq '1')) {
15175: $changes{'coursecredits'} = 1;
15176: foreach my $type (keys(%credits)) {
15177: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15178: }
15179: } else {
1.289 raeburn 15180: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 15181: foreach my $type (@types) {
15182: unless ($type eq 'community') {
1.289 raeburn 15183: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 15184: $changes{'coursecredits'} = 1;
15185: }
15186: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15187: }
15188: }
15189: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15190: foreach my $type (@types) {
15191: unless ($type eq 'community') {
15192: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
15193: $changes{'coursecredits'} = 1;
15194: last;
15195: }
15196: }
15197: }
15198: }
15199: }
15200: if ($env{'form.postsubmit'} eq '1') {
15201: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
15202: my %currtimeout;
15203: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15204: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
15205: $changes{'postsubmit'} = 1;
15206: }
15207: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15208: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
15209: }
15210: } else {
15211: $changes{'postsubmit'} = 1;
15212: }
15213: foreach my $type (@types) {
15214: my $timeout = $env{'form.'.$type.'_timeout'};
15215: $timeout =~ s/\D//g;
15216: if ($timeout == $staticdefaults{'postsubmit'}) {
15217: $timeout = '';
15218: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
15219: $timeout = '0';
15220: }
15221: unless ($timeout eq '') {
15222: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
15223: }
15224: if (exists($currtimeout{$type})) {
15225: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 15226: $changes{'postsubmit'} = 1;
1.257 raeburn 15227: }
15228: } elsif ($timeout ne '') {
15229: $changes{'postsubmit'} = 1;
15230: }
15231: }
15232: } else {
15233: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
15234: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15235: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
15236: $changes{'postsubmit'} = 1;
15237: }
15238: } else {
15239: $changes{'postsubmit'} = 1;
15240: }
1.192 raeburn 15241: }
1.121 raeburn 15242: }
15243: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
15244: $dom);
15245: if ($putresult eq 'ok') {
15246: if (keys(%changes) > 0) {
1.213 raeburn 15247: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 15248: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 15249: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.314 raeburn 15250: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
15251: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','texengine') {
1.257 raeburn 15252: if ($changes{$item}) {
15253: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
15254: }
1.289 raeburn 15255: }
1.192 raeburn 15256: if ($changes{'coursecredits'}) {
15257: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 15258: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
15259: $domdefaults{$type.'credits'} =
15260: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
15261: }
15262: }
15263: }
15264: if ($changes{'postsubmit'}) {
15265: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15266: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
15267: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15268: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
15269: $domdefaults{$type.'postsubtimeout'} =
15270: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15271: }
15272: }
1.192 raeburn 15273: }
15274: }
1.198 raeburn 15275: if ($changes{'uploadquota'}) {
15276: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15277: foreach my $type (@types) {
15278: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
15279: }
15280: }
15281: }
1.264 raeburn 15282: if ($changes{'canclone'}) {
15283: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15284: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15285: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
15286: if (@clonecodes) {
15287: $domdefaults{'canclone'} = join('+',@clonecodes);
15288: }
15289: }
15290: } else {
15291: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
15292: }
15293: }
1.121 raeburn 15294: my $cachetime = 24*60*60;
15295: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 15296: if (ref($lastactref) eq 'HASH') {
15297: $lastactref->{'domdefaults'} = 1;
15298: }
1.121 raeburn 15299: }
15300: $resulttext = &mt('Changes made:').'<ul>';
15301: foreach my $item (sort(keys(%changes))) {
15302: if ($item eq 'canuse_pdfforms') {
15303: if ($env{'form.'.$item} eq '1') {
15304: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
15305: } else {
15306: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
15307: }
1.257 raeburn 15308: } elsif ($item eq 'uselcmath') {
15309: if ($env{'form.'.$item} eq '1') {
15310: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
15311: } else {
15312: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
15313: }
15314: } elsif ($item eq 'usejsme') {
15315: if ($env{'form.'.$item} eq '1') {
15316: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
15317: } else {
1.289 raeburn 15318: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 15319: }
1.314 raeburn 15320: } elsif ($item eq 'texengine') {
15321: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
15322: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
15323: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
15324: }
1.139 raeburn 15325: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 15326: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 15327: } elsif ($item eq 'uploadquota') {
15328: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15329: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
15330: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
15331: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 15332: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 15333: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 15334: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
15335: '</ul>'.
15336: '</li>';
15337: } else {
15338: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
15339: }
1.276 raeburn 15340: } elsif ($item eq 'mysqltables') {
15341: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
15342: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
15343: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
15344: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
15345: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
15346: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
15347: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
15348: '</ul>'.
15349: '</li>';
15350: } else {
15351: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
15352: }
1.257 raeburn 15353: } elsif ($item eq 'postsubmit') {
15354: if ($domdefaults{'postsubmit'} eq 'off') {
15355: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
15356: } else {
15357: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 15358: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 15359: $resulttext .= &mt('durations:').'<ul>';
15360: foreach my $type (@types) {
15361: $resulttext .= '<li>';
15362: my $timeout;
15363: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15364: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15365: }
15366: my $display;
15367: if ($timeout eq '0') {
15368: $display = &mt('unlimited');
15369: } elsif ($timeout eq '') {
15370: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
15371: } else {
15372: $display = &mt('[quant,_1,second]',$timeout);
15373: }
15374: if ($type eq 'community') {
15375: $resulttext .= &mt('Communities');
15376: } elsif ($type eq 'official') {
15377: $resulttext .= &mt('Official courses');
15378: } elsif ($type eq 'unofficial') {
15379: $resulttext .= &mt('Unofficial courses');
15380: } elsif ($type eq 'textbook') {
15381: $resulttext .= &mt('Textbook courses');
1.271 raeburn 15382: } elsif ($type eq 'placement') {
15383: $resulttext .= &mt('Placement tests');
1.257 raeburn 15384: }
15385: $resulttext .= ' -- '.$display.'</li>';
15386: }
15387: $resulttext .= '</ul>';
15388: }
1.289 raeburn 15389: $resulttext .= '</li>';
1.257 raeburn 15390: }
1.192 raeburn 15391: } elsif ($item eq 'coursecredits') {
15392: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15393: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 15394: ($domdefaults{'unofficialcredits'} eq '') &&
15395: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 15396: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
15397: } else {
15398: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
15399: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
15400: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 15401: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 15402: '</ul>'.
15403: '</li>';
15404: }
15405: } else {
15406: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
15407: }
1.264 raeburn 15408: } elsif ($item eq 'canclone') {
15409: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15410: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15411: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
15412: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
15413: }
15414: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
15415: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
15416: } else {
1.289 raeburn 15417: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 15418: }
1.140 raeburn 15419: }
1.121 raeburn 15420: }
15421: $resulttext .= '</ul>';
15422: } else {
15423: $resulttext = &mt('No changes made to course defaults');
15424: }
15425: } else {
15426: $resulttext = '<span class="LC_error">'.
15427: &mt('An error occurred: [_1]',$putresult).'</span>';
15428: }
15429: return $resulttext;
15430: }
15431:
1.231 raeburn 15432: sub modify_selfenrollment {
15433: my ($dom,$lastactref,%domconfig) = @_;
15434: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 15435: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 15436: my %titles = &tool_titles();
1.232 raeburn 15437: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
15438: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 15439: $ordered{'default'} = ['types','registered','approval','limit'];
15440:
15441: my (%roles,%shown,%toplevel);
15442: $roles{'0'} = &Apache::lonnet::plaintext('dc');
15443:
15444: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
15445: if ($domconfig{'selfenrollment'} eq '') {
15446: $domconfig{'selfenrollment'} = {};
15447: }
15448: }
15449: %toplevel = (
15450: admin => 'Configuration Rights',
15451: default => 'Default settings',
15452: validation => 'Validation of self-enrollment requests',
15453: );
1.233 raeburn 15454: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 15455:
15456: if (ref($ordered{'admin'}) eq 'ARRAY') {
15457: foreach my $item (@{$ordered{'admin'}}) {
15458: foreach my $type (@types) {
15459: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
15460: $selfenrollhash{'admin'}{$type}{$item} = 1;
15461: } else {
15462: $selfenrollhash{'admin'}{$type}{$item} = 0;
15463: }
15464: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
15465: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
15466: if ($selfenrollhash{'admin'}{$type}{$item} ne
15467: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
15468: push(@{$changes{'admin'}{$type}},$item);
15469: }
15470: } else {
15471: if (!$selfenrollhash{'admin'}{$type}{$item}) {
15472: push(@{$changes{'admin'}{$type}},$item);
15473: }
15474: }
15475: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
15476: push(@{$changes{'admin'}{$type}},$item);
15477: }
15478: }
15479: }
15480: }
15481:
15482: foreach my $item (@{$ordered{'default'}}) {
15483: foreach my $type (@types) {
15484: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
15485: if ($item eq 'types') {
15486: unless (($value eq 'all') || ($value eq 'dom')) {
15487: $value = '';
15488: }
15489: } elsif ($item eq 'registered') {
15490: unless ($value eq '1') {
15491: $value = 0;
15492: }
15493: } elsif ($item eq 'approval') {
15494: unless ($value =~ /^[012]$/) {
15495: $value = 0;
15496: }
15497: } else {
15498: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
15499: $value = 'none';
15500: }
15501: }
15502: $selfenrollhash{'default'}{$type}{$item} = $value;
15503: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
15504: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
15505: if ($selfenrollhash{'default'}{$type}{$item} ne
15506: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
15507: push(@{$changes{'default'}{$type}},$item);
15508: }
15509: } else {
15510: push(@{$changes{'default'}{$type}},$item);
15511: }
15512: } else {
15513: push(@{$changes{'default'}{$type}},$item);
15514: }
15515: if ($item eq 'limit') {
15516: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
15517: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
15518: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
15519: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
15520: }
15521: } else {
15522: $selfenrollhash{'default'}{$type}{'cap'} = '';
15523: }
15524: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
15525: if ($selfenrollhash{'default'}{$type}{'cap'} ne
15526: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
15527: push(@{$changes{'default'}{$type}},'cap');
15528: }
15529: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
15530: push(@{$changes{'default'}{$type}},'cap');
15531: }
15532: }
15533: }
15534: }
15535:
15536: foreach my $item (@{$itemsref}) {
15537: if ($item eq 'fields') {
15538: my @changed;
15539: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
15540: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
15541: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
15542: }
15543: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
15544: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
15545: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
15546: $domconfig{'selfenrollment'}{'validation'}{$item});
15547: } else {
15548: @changed = @{$selfenrollhash{'validation'}{$item}};
15549: }
15550: } else {
15551: @changed = @{$selfenrollhash{'validation'}{$item}};
15552: }
15553: if (@changed) {
15554: if ($selfenrollhash{'validation'}{$item}) {
15555: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
15556: } else {
15557: $changes{'validation'}{$item} = &mt('None');
15558: }
15559: }
15560: } else {
15561: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
15562: if ($item eq 'markup') {
15563: if ($env{'form.selfenroll_validation_'.$item}) {
15564: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
15565: }
15566: }
15567: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
15568: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
15569: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
15570: }
15571: }
15572: }
15573: }
15574:
15575: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
15576: $dom);
15577: if ($putresult eq 'ok') {
15578: if (keys(%changes) > 0) {
15579: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15580: $resulttext = &mt('Changes made:').'<ul>';
15581: foreach my $key ('admin','default','validation') {
15582: if (ref($changes{$key}) eq 'HASH') {
15583: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
15584: if ($key eq 'validation') {
15585: foreach my $item (@{$itemsref}) {
15586: if (exists($changes{$key}{$item})) {
15587: if ($item eq 'markup') {
15588: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
15589: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
15590: } else {
15591: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
15592: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
15593: }
15594: }
15595: }
15596: } else {
15597: foreach my $type (@types) {
15598: if ($type eq 'community') {
15599: $roles{'1'} = &mt('Community personnel');
15600: } else {
15601: $roles{'1'} = &mt('Course personnel');
15602: }
15603: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 15604: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
15605: if ($key eq 'admin') {
15606: my @mgrdc = ();
15607: if (ref($ordered{$key}) eq 'ARRAY') {
15608: foreach my $item (@{$ordered{'admin'}}) {
15609: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
15610: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
15611: push(@mgrdc,$item);
15612: }
15613: }
15614: }
15615: if (@mgrdc) {
15616: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
15617: } else {
15618: delete($domdefaults{$type.'selfenrolladmdc'});
15619: }
15620: }
15621: } else {
15622: if (ref($ordered{$key}) eq 'ARRAY') {
15623: foreach my $item (@{$ordered{$key}}) {
15624: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
15625: $domdefaults{$type.'selfenroll'.$item} =
15626: $selfenrollhash{$key}{$type}{$item};
15627: }
15628: }
15629: }
15630: }
15631: }
1.231 raeburn 15632: $resulttext .= '<li>'.$titles{$type}.'<ul>';
15633: foreach my $item (@{$ordered{$key}}) {
15634: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
15635: $resulttext .= '<li>';
15636: if ($key eq 'admin') {
15637: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
15638: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
15639: } else {
15640: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
15641: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
15642: }
15643: $resulttext .= '</li>';
15644: }
15645: }
15646: $resulttext .= '</ul></li>';
15647: }
15648: }
15649: $resulttext .= '</ul></li>';
15650: }
15651: }
1.305 raeburn 15652: }
15653: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
15654: my $cachetime = 24*60*60;
15655: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15656: if (ref($lastactref) eq 'HASH') {
15657: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 15658: }
1.231 raeburn 15659: }
15660: $resulttext .= '</ul>';
15661: } else {
15662: $resulttext = &mt('No changes made to self-enrollment settings');
15663: }
15664: } else {
15665: $resulttext = '<span class="LC_error">'.
15666: &mt('An error occurred: [_1]',$putresult).'</span>';
15667: }
15668: return $resulttext;
15669: }
15670:
1.137 raeburn 15671: sub modify_usersessions {
1.212 raeburn 15672: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 15673: my @hostingtypes = ('version','excludedomain','includedomain');
15674: my @offloadtypes = ('primary','default');
15675: my %types = (
15676: remote => \@hostingtypes,
15677: hosted => \@hostingtypes,
15678: spares => \@offloadtypes,
15679: );
15680: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 15681: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 15682: my (%by_ip,%by_location,@intdoms,@instdoms);
15683: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 15684: my @locations = sort(keys(%by_location));
1.137 raeburn 15685: my (%defaultshash,%changes);
15686: foreach my $prefix (@prefixes) {
15687: $defaultshash{'usersessions'}{$prefix} = {};
15688: }
1.212 raeburn 15689: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 15690: my $resulttext;
1.138 raeburn 15691: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 15692: foreach my $prefix (@prefixes) {
1.145 raeburn 15693: next if ($prefix eq 'spares');
15694: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 15695: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
15696: if ($type eq 'version') {
15697: my $value = $env{'form.'.$prefix.'_'.$type};
15698: my $okvalue;
15699: if ($value ne '') {
15700: if (grep(/^\Q$value\E$/,@lcversions)) {
15701: $okvalue = $value;
15702: }
15703: }
15704: if (ref($domconfig{'usersessions'}) eq 'HASH') {
15705: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
15706: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
15707: if ($inuse == 0) {
15708: $changes{$prefix}{$type} = 1;
15709: } else {
15710: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
15711: $changes{$prefix}{$type} = 1;
15712: }
15713: if ($okvalue ne '') {
15714: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
15715: }
15716: }
15717: } else {
15718: if (($inuse == 1) && ($okvalue ne '')) {
15719: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
15720: $changes{$prefix}{$type} = 1;
15721: }
15722: }
15723: } else {
15724: if (($inuse == 1) && ($okvalue ne '')) {
15725: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
15726: $changes{$prefix}{$type} = 1;
15727: }
15728: }
15729: } else {
15730: if (($inuse == 1) && ($okvalue ne '')) {
15731: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
15732: $changes{$prefix}{$type} = 1;
15733: }
15734: }
15735: } else {
15736: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
15737: my @okvals;
15738: foreach my $val (@vals) {
1.138 raeburn 15739: if ($val =~ /:/) {
15740: my @items = split(/:/,$val);
15741: foreach my $item (@items) {
15742: if (ref($by_location{$item}) eq 'ARRAY') {
15743: push(@okvals,$item);
15744: }
15745: }
15746: } else {
15747: if (ref($by_location{$val}) eq 'ARRAY') {
15748: push(@okvals,$val);
15749: }
1.137 raeburn 15750: }
15751: }
15752: @okvals = sort(@okvals);
15753: if (ref($domconfig{'usersessions'}) eq 'HASH') {
15754: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
15755: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
15756: if ($inuse == 0) {
15757: $changes{$prefix}{$type} = 1;
15758: } else {
15759: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
15760: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
15761: if (@changed > 0) {
15762: $changes{$prefix}{$type} = 1;
15763: }
15764: }
15765: } else {
15766: if ($inuse == 1) {
15767: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
15768: $changes{$prefix}{$type} = 1;
15769: }
15770: }
15771: } else {
15772: if ($inuse == 1) {
15773: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
15774: $changes{$prefix}{$type} = 1;
15775: }
15776: }
15777: } else {
15778: if ($inuse == 1) {
15779: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
15780: $changes{$prefix}{$type} = 1;
15781: }
15782: }
15783: }
15784: }
15785: }
1.145 raeburn 15786:
15787: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 15788: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 15789: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
15790: my $savespares;
15791:
15792: foreach my $lonhost (sort(keys(%servers))) {
15793: my $serverhomeID =
15794: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 15795: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 15796: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
15797: my %spareschg;
15798: foreach my $type (@{$types{'spares'}}) {
15799: my @okspares;
15800: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
15801: foreach my $server (@checked) {
1.152 raeburn 15802: if (&Apache::lonnet::hostname($server) ne '') {
15803: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
15804: unless (grep(/^\Q$server\E$/,@okspares)) {
15805: push(@okspares,$server);
15806: }
1.145 raeburn 15807: }
15808: }
15809: }
15810: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
15811: my $newspare;
1.152 raeburn 15812: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
15813: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 15814: $newspare = $new;
15815: }
15816: }
1.152 raeburn 15817: my @spares;
15818: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
15819: @spares = sort(@okspares,$newspare);
15820: } else {
15821: @spares = sort(@okspares);
15822: }
15823: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 15824: if (ref($spareid{$lonhost}) eq 'HASH') {
15825: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 15826: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 15827: if (@diffs > 0) {
15828: $spareschg{$type} = 1;
15829: }
15830: }
15831: }
15832: }
15833: if (keys(%spareschg) > 0) {
15834: $changes{'spares'}{$lonhost} = \%spareschg;
15835: }
15836: }
1.261 raeburn 15837: $defaultshash{'usersessions'}{'offloadnow'} = {};
15838: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
15839: my @okoffload;
15840: if (@offloadnow) {
15841: foreach my $server (@offloadnow) {
15842: if (&Apache::lonnet::hostname($server) ne '') {
15843: unless (grep(/^\Q$server\E$/,@okoffload)) {
15844: push(@okoffload,$server);
15845: }
15846: }
15847: }
15848: if (@okoffload) {
15849: foreach my $lonhost (@okoffload) {
15850: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
15851: }
15852: }
15853: }
1.145 raeburn 15854: if (ref($domconfig{'usersessions'}) eq 'HASH') {
15855: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
15856: if (ref($changes{'spares'}) eq 'HASH') {
15857: if (keys(%{$changes{'spares'}}) > 0) {
15858: $savespares = 1;
15859: }
15860: }
15861: } else {
15862: $savespares = 1;
15863: }
1.261 raeburn 15864: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
15865: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
15866: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
15867: $changes{'offloadnow'} = 1;
15868: last;
15869: }
15870: }
15871: unless ($changes{'offloadnow'}) {
1.289 raeburn 15872: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
1.261 raeburn 15873: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
15874: $changes{'offloadnow'} = 1;
15875: last;
15876: }
15877: }
15878: }
15879: } elsif (@okoffload) {
15880: $changes{'offloadnow'} = 1;
15881: }
15882: } elsif (@okoffload) {
15883: $changes{'offloadnow'} = 1;
1.145 raeburn 15884: }
1.147 raeburn 15885: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
15886: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 15887: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
15888: $dom);
15889: if ($putresult eq 'ok') {
15890: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
15891: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
15892: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
15893: }
15894: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
15895: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
15896: }
1.261 raeburn 15897: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
15898: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
15899: }
1.137 raeburn 15900: }
15901: my $cachetime = 24*60*60;
15902: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 15903: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 15904: if (ref($lastactref) eq 'HASH') {
15905: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 15906: $lastactref->{'usersessions'} = 1;
1.212 raeburn 15907: }
1.147 raeburn 15908: if (keys(%changes) > 0) {
15909: my %lt = &usersession_titles();
15910: $resulttext = &mt('Changes made:').'<ul>';
15911: foreach my $prefix (@prefixes) {
15912: if (ref($changes{$prefix}) eq 'HASH') {
15913: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
15914: if ($prefix eq 'spares') {
15915: if (ref($changes{$prefix}) eq 'HASH') {
15916: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
15917: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 15918: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 15919: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
15920: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 15921: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
15922: foreach my $type (@{$types{$prefix}}) {
15923: if ($changes{$prefix}{$lonhost}{$type}) {
15924: my $offloadto = &mt('None');
15925: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
15926: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
15927: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
15928: }
1.145 raeburn 15929: }
1.147 raeburn 15930: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 15931: }
1.137 raeburn 15932: }
15933: }
1.147 raeburn 15934: $resulttext .= '</li>';
1.137 raeburn 15935: }
15936: }
1.147 raeburn 15937: } else {
15938: foreach my $type (@{$types{$prefix}}) {
15939: if (defined($changes{$prefix}{$type})) {
15940: my $newvalue;
15941: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
15942: if (ref($defaultshash{'usersessions'}{$prefix})) {
15943: if ($type eq 'version') {
15944: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
15945: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
15946: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
15947: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
15948: }
1.145 raeburn 15949: }
15950: }
15951: }
1.147 raeburn 15952: if ($newvalue eq '') {
15953: if ($type eq 'version') {
15954: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
15955: } else {
15956: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
15957: }
1.145 raeburn 15958: } else {
1.147 raeburn 15959: if ($type eq 'version') {
15960: $newvalue .= ' '.&mt('(or later)');
15961: }
15962: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 15963: }
1.137 raeburn 15964: }
15965: }
15966: }
1.147 raeburn 15967: $resulttext .= '</ul>';
1.137 raeburn 15968: }
15969: }
1.261 raeburn 15970: if ($changes{'offloadnow'}) {
15971: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
15972: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
15973: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
15974: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
15975: $resulttext .= '<li>'.$lonhost.'</li>';
15976: }
15977: $resulttext .= '</ul>';
15978: } else {
15979: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
15980: }
15981: } else {
15982: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
15983: }
15984: }
1.147 raeburn 15985: $resulttext .= '</ul>';
15986: } else {
15987: $resulttext = $nochgmsg;
1.137 raeburn 15988: }
15989: } else {
15990: $resulttext = '<span class="LC_error">'.
15991: &mt('An error occurred: [_1]',$putresult).'</span>';
15992: }
15993: } else {
1.147 raeburn 15994: $resulttext = $nochgmsg;
1.137 raeburn 15995: }
15996: return $resulttext;
15997: }
15998:
1.275 raeburn 15999: sub modify_ssl {
16000: my ($dom,$lastactref,%domconfig) = @_;
16001: my (%by_ip,%by_location,@intdoms,@instdoms);
16002: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
16003: my @locations = sort(keys(%by_location));
16004: my %servers = &Apache::lonnet::internet_dom_servers($dom);
16005: my (%defaultshash,%changes);
16006: my $action = 'ssl';
1.293 raeburn 16007: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 16008: foreach my $prefix (@prefixes) {
16009: $defaultshash{$action}{$prefix} = {};
16010: }
16011: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16012: my $resulttext;
16013: my %iphost = &Apache::lonnet::get_iphost();
16014: my @reptypes = ('certreq','nocertreq');
16015: my @connecttypes = ('dom','intdom','other');
16016: my %types = (
1.293 raeburn 16017: connto => \@connecttypes,
16018: connfrom => \@connecttypes,
16019: replication => \@reptypes,
1.275 raeburn 16020: );
16021: foreach my $prefix (sort(keys(%types))) {
16022: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 16023: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 16024: my $value = 'yes';
16025: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
16026: $value = $env{'form.'.$prefix.'_'.$type};
16027: }
16028: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
16029: if ($domconfig{$action}{$prefix}{$type} ne '') {
16030: if ($value ne $domconfig{$action}{$prefix}{$type}) {
16031: $changes{$prefix}{$type} = 1;
16032: }
16033: $defaultshash{$action}{$prefix}{$type} = $value;
16034: } else {
16035: $defaultshash{$action}{$prefix}{$type} = $value;
16036: $changes{$prefix}{$type} = 1;
16037: }
16038: } else {
16039: $defaultshash{$action}{$prefix}{$type} = $value;
16040: $changes{$prefix}{$type} = 1;
16041: }
16042: if (($type eq 'dom') && (keys(%servers) == 1)) {
16043: delete($changes{$prefix}{$type});
16044: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
16045: delete($changes{$prefix}{$type});
16046: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
16047: delete($changes{$prefix}{$type});
16048: }
16049: } elsif ($prefix eq 'replication') {
16050: if (@locations > 0) {
16051: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16052: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16053: my @okvals;
16054: foreach my $val (@vals) {
16055: if ($val =~ /:/) {
16056: my @items = split(/:/,$val);
16057: foreach my $item (@items) {
16058: if (ref($by_location{$item}) eq 'ARRAY') {
16059: push(@okvals,$item);
16060: }
16061: }
16062: } else {
16063: if (ref($by_location{$val}) eq 'ARRAY') {
16064: push(@okvals,$val);
16065: }
16066: }
16067: }
16068: @okvals = sort(@okvals);
16069: if (ref($domconfig{$action}) eq 'HASH') {
16070: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
16071: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
16072: if ($inuse == 0) {
16073: $changes{$prefix}{$type} = 1;
16074: } else {
16075: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16076: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
16077: if (@changed > 0) {
16078: $changes{$prefix}{$type} = 1;
16079: }
16080: }
16081: } else {
16082: if ($inuse == 1) {
16083: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16084: $changes{$prefix}{$type} = 1;
16085: }
16086: }
16087: } else {
16088: if ($inuse == 1) {
16089: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16090: $changes{$prefix}{$type} = 1;
16091: }
16092: }
16093: } else {
16094: if ($inuse == 1) {
16095: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16096: $changes{$prefix}{$type} = 1;
16097: }
16098: }
16099: }
16100: }
16101: }
16102: }
16103: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
16104: if (keys(%changes) > 0) {
16105: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16106: $dom);
16107: if ($putresult eq 'ok') {
16108: if (ref($defaultshash{$action}) eq 'HASH') {
16109: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
16110: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
16111: }
1.293 raeburn 16112: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
16113: $domdefaults{'connto'} = $domconfig{$action}{'connto'};
16114: }
16115: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
16116: $domdefaults{'connfrom'} = $domconfig{$action}{'connfrom'};
1.275 raeburn 16117: }
16118: }
16119: my $cachetime = 24*60*60;
16120: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16121: if (ref($lastactref) eq 'HASH') {
16122: $lastactref->{'domdefaults'} = 1;
16123: }
16124: if (keys(%changes) > 0) {
16125: my %titles = &ssl_titles();
16126: $resulttext = &mt('Changes made:').'<ul>';
16127: foreach my $prefix (@prefixes) {
16128: if (ref($changes{$prefix}) eq 'HASH') {
16129: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
16130: foreach my $type (@{$types{$prefix}}) {
16131: if (defined($changes{$prefix}{$type})) {
16132: my $newvalue;
16133: if (ref($defaultshash{$action}) eq 'HASH') {
16134: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 16135: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 16136: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
16137: } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
16138: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
16139: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
16140: }
16141: }
16142: }
16143: if ($newvalue eq '') {
16144: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
16145: } else {
16146: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
16147: }
16148: }
16149: }
16150: }
16151: $resulttext .= '</ul>';
16152: }
16153: }
16154: } else {
16155: $resulttext = $nochgmsg;
16156: }
16157: } else {
16158: $resulttext = '<span class="LC_error">'.
16159: &mt('An error occurred: [_1]',$putresult).'</span>';
16160: }
16161: } else {
16162: $resulttext = $nochgmsg;
16163: }
16164: return $resulttext;
16165: }
16166:
1.279 raeburn 16167: sub modify_trust {
16168: my ($dom,$lastactref,%domconfig) = @_;
16169: my (%by_ip,%by_location,@intdoms,@instdoms);
16170: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
16171: my @locations = sort(keys(%by_location));
16172: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
16173: my @types = ('exc','inc');
16174: my (%defaultshash,%changes);
16175: foreach my $prefix (@prefixes) {
16176: $defaultshash{'trust'}{$prefix} = {};
16177: }
16178: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16179: my $resulttext;
16180: foreach my $prefix (@prefixes) {
16181: foreach my $type (@types) {
16182: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16183: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16184: my @okvals;
16185: foreach my $val (@vals) {
16186: if ($val =~ /:/) {
16187: my @items = split(/:/,$val);
16188: foreach my $item (@items) {
16189: if (ref($by_location{$item}) eq 'ARRAY') {
16190: push(@okvals,$item);
16191: }
16192: }
16193: } else {
16194: if (ref($by_location{$val}) eq 'ARRAY') {
16195: push(@okvals,$val);
16196: }
16197: }
16198: }
16199: @okvals = sort(@okvals);
16200: if (ref($domconfig{'trust'}) eq 'HASH') {
16201: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
16202: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
16203: if ($inuse == 0) {
16204: $changes{$prefix}{$type} = 1;
16205: } else {
16206: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16207: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
16208: if (@changed > 0) {
16209: $changes{$prefix}{$type} = 1;
16210: }
16211: }
16212: } else {
16213: if ($inuse == 1) {
16214: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16215: $changes{$prefix}{$type} = 1;
16216: }
16217: }
16218: } else {
16219: if ($inuse == 1) {
16220: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16221: $changes{$prefix}{$type} = 1;
16222: }
16223: }
16224: } else {
16225: if ($inuse == 1) {
16226: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16227: $changes{$prefix}{$type} = 1;
16228: }
16229: }
16230: }
16231: }
16232: my $nochgmsg = &mt('No changes made to trust settings.');
16233: if (keys(%changes) > 0) {
16234: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16235: $dom);
16236: if ($putresult eq 'ok') {
16237: if (ref($defaultshash{'trust'}) eq 'HASH') {
16238: foreach my $prefix (@prefixes) {
16239: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
16240: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
16241: }
16242: }
16243: }
16244: my $cachetime = 24*60*60;
16245: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16246: if (ref($lastactref) eq 'HASH') {
16247: $lastactref->{'domdefaults'} = 1;
16248: }
16249: if (keys(%changes) > 0) {
16250: my %lt = &trust_titles();
16251: $resulttext = &mt('Changes made:').'<ul>';
16252: foreach my $prefix (@prefixes) {
16253: if (ref($changes{$prefix}) eq 'HASH') {
16254: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
16255: foreach my $type (@types) {
16256: if (defined($changes{$prefix}{$type})) {
16257: my $newvalue;
16258: if (ref($defaultshash{'trust'}) eq 'HASH') {
16259: if (ref($defaultshash{'trust'}{$prefix})) {
16260: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
16261: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
16262: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
16263: }
16264: }
16265: }
16266: }
16267: if ($newvalue eq '') {
16268: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
16269: } else {
16270: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
16271: }
16272: }
16273: }
16274: $resulttext .= '</ul>';
16275: }
16276: }
16277: $resulttext .= '</ul>';
16278: } else {
16279: $resulttext = $nochgmsg;
16280: }
16281: } else {
16282: $resulttext = '<span class="LC_error">'.
16283: &mt('An error occurred: [_1]',$putresult).'</span>';
16284: }
16285: } else {
16286: $resulttext = $nochgmsg;
16287: }
16288: return $resulttext;
16289: }
16290:
1.150 raeburn 16291: sub modify_loadbalancing {
16292: my ($dom,%domconfig) = @_;
16293: my $primary_id = &Apache::lonnet::domain($dom,'primary');
16294: my $intdom = &Apache::lonnet::internet_dom($primary_id);
16295: my ($othertitle,$usertypes,$types) =
16296: &Apache::loncommon::sorted_inst_types($dom);
16297: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 16298: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 16299: my @sparestypes = ('primary','default');
16300: my %typetitles = &sparestype_titles();
16301: my $resulttext;
1.171 raeburn 16302: my (%currbalancer,%currtargets,%currrules,%existing);
16303: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
16304: %existing = %{$domconfig{'loadbalancing'}};
16305: }
16306: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
16307: \%currtargets,\%currrules);
16308: my ($saveloadbalancing,%defaultshash,%changes);
16309: my ($alltypes,$othertypes,$titles) =
16310: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
16311: my %ruletitles = &offloadtype_text();
16312: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
16313: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
16314: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
16315: if ($balancer eq '') {
16316: next;
16317: }
1.210 raeburn 16318: if (!exists($servers{$balancer})) {
1.171 raeburn 16319: if (exists($currbalancer{$balancer})) {
16320: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 16321: }
1.171 raeburn 16322: next;
16323: }
16324: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
16325: push(@{$changes{'delete'}},$balancer);
16326: next;
16327: }
16328: if (!exists($currbalancer{$balancer})) {
16329: push(@{$changes{'add'}},$balancer);
16330: }
16331: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
16332: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
16333: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
16334: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
16335: $saveloadbalancing = 1;
16336: }
16337: foreach my $sparetype (@sparestypes) {
16338: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
16339: my @offloadto;
16340: foreach my $target (@targets) {
16341: if (($servers{$target}) && ($target ne $balancer)) {
16342: if ($sparetype eq 'default') {
16343: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
16344: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 16345: }
16346: }
1.171 raeburn 16347: unless(grep(/^\Q$target\E$/,@offloadto)) {
16348: push(@offloadto,$target);
16349: }
1.150 raeburn 16350: }
16351: }
1.284 raeburn 16352: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
16353: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
16354: push(@offloadto,$balancer);
16355: }
16356: }
16357: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 16358: }
1.171 raeburn 16359: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 16360: foreach my $sparetype (@sparestypes) {
1.171 raeburn 16361: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
16362: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 16363: if (@targetdiffs > 0) {
1.171 raeburn 16364: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 16365: }
1.171 raeburn 16366: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16367: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16368: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 16369: }
16370: }
16371: }
16372: } else {
1.171 raeburn 16373: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 16374: foreach my $sparetype (@sparestypes) {
1.171 raeburn 16375: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16376: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16377: $changes{'curr'}{$balancer}{'targets'} = 1;
16378: }
1.150 raeburn 16379: }
16380: }
1.210 raeburn 16381: }
1.150 raeburn 16382: }
16383: my $ishomedom;
1.171 raeburn 16384: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
16385: $ishomedom = 1;
1.150 raeburn 16386: }
16387: if (ref($alltypes) eq 'ARRAY') {
16388: foreach my $type (@{$alltypes}) {
16389: my $rule;
1.210 raeburn 16390: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 16391: (!$ishomedom)) {
1.171 raeburn 16392: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
16393: }
16394: if ($rule eq 'specific') {
1.255 raeburn 16395: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 16396: if (exists($servers{$specifiedhost})) {
1.255 raeburn 16397: $rule = $specifiedhost;
16398: }
1.150 raeburn 16399: }
1.171 raeburn 16400: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
16401: if (ref($currrules{$balancer}) eq 'HASH') {
16402: if ($rule ne $currrules{$balancer}{$type}) {
16403: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 16404: }
16405: } elsif ($rule ne '') {
1.171 raeburn 16406: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 16407: }
16408: }
16409: }
1.171 raeburn 16410: }
16411: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
16412: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
16413: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
16414: $defaultshash{'loadbalancing'} = {};
16415: }
16416: my $putresult = &Apache::lonnet::put_dom('configuration',
16417: \%defaultshash,$dom);
16418: if ($putresult eq 'ok') {
16419: if (keys(%changes) > 0) {
1.252 raeburn 16420: my %toupdate;
1.171 raeburn 16421: if (ref($changes{'delete'}) eq 'ARRAY') {
16422: foreach my $balancer (sort(@{$changes{'delete'}})) {
16423: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 16424: $toupdate{$balancer} = 1;
1.150 raeburn 16425: }
1.171 raeburn 16426: }
16427: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 16428: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 16429: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 16430: $toupdate{$balancer} = 1;
1.171 raeburn 16431: }
16432: }
16433: if (ref($changes{'curr'}) eq 'HASH') {
16434: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 16435: $toupdate{$balancer} = 1;
1.171 raeburn 16436: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
16437: if ($changes{'curr'}{$balancer}{'targets'}) {
16438: my %offloadstr;
16439: foreach my $sparetype (@sparestypes) {
16440: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16441: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16442: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
16443: }
16444: }
1.150 raeburn 16445: }
1.171 raeburn 16446: if (keys(%offloadstr) == 0) {
16447: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 16448: } else {
1.171 raeburn 16449: my $showoffload;
16450: foreach my $sparetype (@sparestypes) {
16451: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
16452: if (defined($offloadstr{$sparetype})) {
16453: $showoffload .= $offloadstr{$sparetype};
16454: } else {
16455: $showoffload .= &mt('None');
16456: }
16457: $showoffload .= (' 'x3);
16458: }
16459: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 16460: }
16461: }
16462: }
1.171 raeburn 16463: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
16464: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
16465: foreach my $type (@{$alltypes}) {
16466: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
16467: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
16468: my $balancetext;
16469: if ($rule eq '') {
16470: $balancetext = $ruletitles{'default'};
1.209 raeburn 16471: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 16472: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 16473: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 16474: foreach my $sparetype (@sparestypes) {
16475: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16476: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
16477: }
16478: }
1.253 raeburn 16479: foreach my $item (@{$alltypes}) {
16480: next if ($item =~ /^_LC_ipchange/);
16481: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
16482: if ($hasrule eq 'homeserver') {
16483: map { $toupdate{$_} = 1; } (keys(%libraryservers));
16484: } else {
16485: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
16486: if ($servers{$hasrule}) {
16487: $toupdate{$hasrule} = 1;
16488: }
16489: }
16490: }
16491: }
1.254 raeburn 16492: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
16493: $balancetext = $ruletitles{$rule};
16494: } else {
16495: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
16496: $balancetext = $ruletitles{'particular'}.' '.$receiver;
16497: if ($receiver) {
16498: $toupdate{$receiver};
16499: }
16500: }
16501: } else {
16502: $balancetext = $ruletitles{$rule};
1.252 raeburn 16503: }
1.171 raeburn 16504: } else {
16505: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
16506: }
1.210 raeburn 16507: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 16508: }
16509: }
16510: }
16511: }
1.252 raeburn 16512: if (keys(%toupdate)) {
16513: my %thismachine;
16514: my $updatedhere;
16515: my $cachetime = 60*60*24;
16516: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
16517: foreach my $lonhost (keys(%toupdate)) {
16518: if ($thismachine{$lonhost}) {
16519: unless ($updatedhere) {
16520: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
16521: $defaultshash{'loadbalancing'},
16522: $cachetime);
16523: $updatedhere = 1;
16524: }
16525: } else {
16526: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
16527: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
16528: }
16529: }
16530: }
1.150 raeburn 16531: }
1.171 raeburn 16532: }
16533: if ($resulttext ne '') {
16534: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 16535: } else {
16536: $resulttext = $nochgmsg;
16537: }
16538: } else {
1.171 raeburn 16539: $resulttext = $nochgmsg;
1.150 raeburn 16540: }
16541: } else {
1.171 raeburn 16542: $resulttext = '<span class="LC_error">'.
16543: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 16544: }
16545: } else {
1.171 raeburn 16546: $resulttext = $nochgmsg;
1.150 raeburn 16547: }
16548: return $resulttext;
16549: }
16550:
1.48 raeburn 16551: sub recurse_check {
16552: my ($chkcats,$categories,$depth,$name) = @_;
16553: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
16554: my $chg = 0;
16555: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
16556: my $category = $chkcats->[$depth]{$name}[$j];
16557: my $item;
16558: if ($category eq '') {
16559: $chg ++;
16560: } else {
16561: my $deeper = $depth + 1;
16562: $item = &escape($category).':'.&escape($name).':'.$depth;
16563: if ($chg) {
16564: $categories->{$item} -= $chg;
16565: }
16566: &recurse_check($chkcats,$categories,$deeper,$category);
16567: $deeper --;
16568: }
16569: }
16570: }
16571: return;
16572: }
16573:
16574: sub recurse_cat_deletes {
16575: my ($item,$coursecategories,$deletions) = @_;
16576: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
16577: my $subdepth = $depth + 1;
16578: if (ref($coursecategories) eq 'HASH') {
16579: foreach my $subitem (keys(%{$coursecategories})) {
16580: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
16581: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
16582: delete($coursecategories->{$subitem});
16583: $deletions->{$subitem} = 1;
16584: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 16585: }
1.48 raeburn 16586: }
16587: }
16588: return;
16589: }
16590:
1.125 raeburn 16591: sub active_dc_picker {
1.191 raeburn 16592: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 16593: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 16594: my @domcoord = keys(%domcoords);
16595: if (keys(%currhash)) {
16596: foreach my $dc (keys(%currhash)) {
16597: unless (exists($domcoords{$dc})) {
16598: push(@domcoord,$dc);
16599: }
16600: }
16601: }
16602: @domcoord = sort(@domcoord);
1.210 raeburn 16603: my $numdcs = scalar(@domcoord);
1.191 raeburn 16604: my $rows = 0;
16605: my $table;
1.125 raeburn 16606: if ($numdcs > 1) {
1.191 raeburn 16607: $table = '<table>';
16608: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 16609: my $rem = $i%($numinrow);
16610: if ($rem == 0) {
16611: if ($i > 0) {
1.191 raeburn 16612: $table .= '</tr>';
1.125 raeburn 16613: }
1.191 raeburn 16614: $table .= '<tr>';
16615: $rows ++;
1.125 raeburn 16616: }
1.191 raeburn 16617: my $check = '';
16618: if ($inputtype eq 'radio') {
16619: if (keys(%currhash) == 0) {
16620: if (!$i) {
16621: $check = ' checked="checked"';
16622: }
16623: } elsif (exists($currhash{$domcoord[$i]})) {
16624: $check = ' checked="checked"';
16625: }
16626: } else {
16627: if (exists($currhash{$domcoord[$i]})) {
16628: $check = ' checked="checked"';
1.125 raeburn 16629: }
16630: }
1.191 raeburn 16631: if ($i == @domcoord - 1) {
1.125 raeburn 16632: my $colsleft = $numinrow - $rem;
16633: if ($colsleft > 1) {
1.191 raeburn 16634: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 16635: } else {
1.191 raeburn 16636: $table .= '<td class="LC_left_item">';
1.125 raeburn 16637: }
16638: } else {
1.191 raeburn 16639: $table .= '<td class="LC_left_item">';
16640: }
16641: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
16642: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
16643: $table .= '<span class="LC_nobreak"><label>'.
16644: '<input type="'.$inputtype.'" name="'.$name.'"'.
16645: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
16646: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 16647: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 16648: }
1.219 raeburn 16649: $table .= '</label></span></td>';
1.191 raeburn 16650: }
16651: $table .= '</tr></table>';
16652: } elsif ($numdcs == 1) {
1.219 raeburn 16653: my ($dcname,$dcdom) = split(':',$domcoord[0]);
16654: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 16655: if ($inputtype eq 'radio') {
1.247 raeburn 16656: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 16657: if ($user ne $dcname.':'.$dcdom) {
16658: $table .= ' ('.$dcname.':'.$dcdom.')';
16659: }
1.191 raeburn 16660: } else {
16661: my $check;
16662: if (exists($currhash{$domcoord[0]})) {
16663: $check = ' checked="checked"';
1.125 raeburn 16664: }
1.247 raeburn 16665: $table = '<span class="LC_nobreak"><label>'.
16666: '<input type="checkbox" name="'.$name.'" '.
16667: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 16668: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 16669: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 16670: }
1.220 raeburn 16671: $table .= '</label></span>';
1.191 raeburn 16672: $rows ++;
1.125 raeburn 16673: }
16674: }
1.191 raeburn 16675: return ($numdcs,$table,$rows);
1.125 raeburn 16676: }
16677:
1.137 raeburn 16678: sub usersession_titles {
16679: return &Apache::lonlocal::texthash(
16680: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
16681: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 16682: spares => 'Servers offloaded to, when busy',
1.137 raeburn 16683: version => 'LON-CAPA version requirement',
1.138 raeburn 16684: excludedomain => 'Allow all, but exclude specific domains',
16685: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 16686: primary => 'Primary (checked first)',
1.154 raeburn 16687: default => 'Default',
1.137 raeburn 16688: );
16689: }
16690:
1.152 raeburn 16691: sub id_for_thisdom {
16692: my (%servers) = @_;
16693: my %altids;
16694: foreach my $server (keys(%servers)) {
16695: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
16696: if ($serverhome ne $server) {
16697: $altids{$serverhome} = $server;
16698: }
16699: }
16700: return %altids;
16701: }
16702:
1.150 raeburn 16703: sub count_servers {
16704: my ($currbalancer,%servers) = @_;
16705: my (@spares,$numspares);
16706: foreach my $lonhost (sort(keys(%servers))) {
16707: next if ($currbalancer eq $lonhost);
16708: push(@spares,$lonhost);
16709: }
16710: if ($currbalancer) {
16711: $numspares = scalar(@spares);
16712: } else {
16713: $numspares = scalar(@spares) - 1;
16714: }
16715: return ($numspares,@spares);
16716: }
16717:
16718: sub lonbalance_targets_js {
1.171 raeburn 16719: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 16720: my $select = &mt('Select');
16721: my ($alltargets,$allishome,$allinsttypes,@alltypes);
16722: if (ref($servers) eq 'HASH') {
16723: $alltargets = join("','",sort(keys(%{$servers})));
16724: my @homedoms;
16725: foreach my $server (sort(keys(%{$servers}))) {
16726: if (&Apache::lonnet::host_domain($server) eq $dom) {
16727: push(@homedoms,'1');
16728: } else {
16729: push(@homedoms,'0');
16730: }
16731: }
16732: $allishome = join("','",@homedoms);
16733: }
16734: if (ref($types) eq 'ARRAY') {
16735: if (@{$types} > 0) {
16736: @alltypes = @{$types};
16737: }
16738: }
16739: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
16740: $allinsttypes = join("','",@alltypes);
1.171 raeburn 16741: my (%currbalancer,%currtargets,%currrules,%existing);
16742: if (ref($settings) eq 'HASH') {
16743: %existing = %{$settings};
16744: }
16745: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
16746: \%currtargets,\%currrules);
1.210 raeburn 16747: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 16748: return <<"END";
16749:
16750: <script type="text/javascript">
16751: // <![CDATA[
16752:
1.171 raeburn 16753: currBalancers = new Array('$balancers');
16754:
16755: function toggleTargets(balnum) {
16756: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
16757: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
16758: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
16759: var prevbalancer = prevhostitem.value;
16760: var baltotal = document.getElementById('loadbalancing_total').value;
16761: prevhostitem.value = balancer;
16762: if (prevbalancer != '') {
16763: var prevIdx = currBalancers.indexOf(prevbalancer);
16764: if (prevIdx != -1) {
16765: currBalancers.splice(prevIdx,1);
16766: }
16767: }
1.150 raeburn 16768: if (balancer == '') {
1.171 raeburn 16769: hideSpares(balnum);
1.150 raeburn 16770: } else {
1.171 raeburn 16771: var currIdx = currBalancers.indexOf(balancer);
16772: if (currIdx == -1) {
16773: currBalancers.push(balancer);
16774: }
1.150 raeburn 16775: var homedoms = new Array('$allishome');
1.171 raeburn 16776: var ishomedom = homedoms[lonhostitem.selectedIndex];
16777: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 16778: }
1.171 raeburn 16779: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 16780: return;
16781: }
16782:
1.171 raeburn 16783: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 16784: var alltargets = new Array('$alltargets');
16785: var insttypes = new Array('$allinsttypes');
1.151 raeburn 16786: var offloadtypes = new Array('primary','default');
16787:
1.171 raeburn 16788: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
16789: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 16790:
1.151 raeburn 16791: for (var i=0; i<offloadtypes.length; i++) {
16792: var count = 0;
16793: for (var j=0; j<alltargets.length; j++) {
16794: if (alltargets[j] != balancer) {
1.171 raeburn 16795: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
16796: item.value = alltargets[j];
16797: item.style.textAlign='left';
16798: item.style.textFace='normal';
16799: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
16800: if (currBalancers.indexOf(alltargets[j]) == -1) {
16801: item.disabled = '';
16802: } else {
16803: item.disabled = 'disabled';
16804: item.checked = false;
16805: }
1.151 raeburn 16806: count ++;
16807: }
1.150 raeburn 16808: }
16809: }
1.151 raeburn 16810: for (var k=0; k<insttypes.length; k++) {
16811: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 16812: if (ishomedom == 1) {
1.171 raeburn 16813: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
16814: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 16815: } else {
1.171 raeburn 16816: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
16817: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 16818: }
16819: } else {
1.171 raeburn 16820: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
16821: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 16822: }
1.151 raeburn 16823: if ((insttypes[k] != '_LC_external') &&
16824: ((insttypes[k] != '_LC_internetdom') ||
16825: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 16826: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
16827: item.options.length = 0;
16828: item.options[0] = new Option("","",true,true);
1.210 raeburn 16829: var idx = 0;
1.151 raeburn 16830: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 16831: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
16832: idx ++;
16833: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 16834: }
16835: }
16836: }
16837: }
16838: return;
16839: }
16840:
1.171 raeburn 16841: function hideSpares(balnum) {
1.150 raeburn 16842: var alltargets = new Array('$alltargets');
16843: var insttypes = new Array('$allinsttypes');
16844: var offloadtypes = new Array('primary','default');
16845:
1.171 raeburn 16846: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
16847: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 16848:
16849: var total = alltargets.length - 1;
16850: for (var i=0; i<offloadtypes; i++) {
16851: for (var j=0; j<total; j++) {
1.171 raeburn 16852: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
16853: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
16854: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 16855: }
1.150 raeburn 16856: }
16857: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 16858: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
16859: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 16860: if (insttypes[k] != '_LC_external') {
1.171 raeburn 16861: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
16862: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 16863: }
16864: }
16865: return;
16866: }
16867:
1.171 raeburn 16868: function checkOffloads(item,balnum,type) {
1.150 raeburn 16869: var alltargets = new Array('$alltargets');
16870: var offloadtypes = new Array('primary','default');
16871: if (item.checked) {
16872: var total = alltargets.length - 1;
16873: var other;
16874: if (type == offloadtypes[0]) {
1.151 raeburn 16875: other = offloadtypes[1];
1.150 raeburn 16876: } else {
1.151 raeburn 16877: other = offloadtypes[0];
1.150 raeburn 16878: }
16879: for (var i=0; i<total; i++) {
1.171 raeburn 16880: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 16881: if (server == item.value) {
1.171 raeburn 16882: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
16883: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 16884: }
16885: }
16886: }
16887: }
16888: return;
16889: }
16890:
1.171 raeburn 16891: function singleServerToggle(balnum,type) {
16892: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 16893: if (offloadtoSelIdx == 0) {
1.171 raeburn 16894: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
16895: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 16896:
16897: } else {
1.171 raeburn 16898: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
16899: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 16900: }
16901: return;
16902: }
16903:
1.171 raeburn 16904: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 16905: if (type == '_LC_external') {
1.171 raeburn 16906: return;
1.150 raeburn 16907: }
1.171 raeburn 16908: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 16909: for (var i=0; i<typesRules.length; i++) {
16910: if (formname.elements[typesRules[i]].checked) {
16911: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 16912: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
16913: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 16914: } else {
1.171 raeburn 16915: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
16916: }
16917: }
16918: }
16919: return;
16920: }
16921:
16922: function balancerDeleteChange(balnum) {
16923: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
16924: var baltotal = document.getElementById('loadbalancing_total').value;
16925: var addtarget;
16926: var removetarget;
16927: var action = 'delete';
16928: if (document.getElementById('loadbalancing_delete_'+balnum)) {
16929: var lonhost = hostitem.value;
16930: var currIdx = currBalancers.indexOf(lonhost);
16931: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
16932: if (currIdx != -1) {
16933: currBalancers.splice(currIdx,1);
16934: }
16935: addtarget = lonhost;
16936: } else {
16937: if (currIdx == -1) {
16938: currBalancers.push(lonhost);
16939: }
16940: removetarget = lonhost;
16941: action = 'undelete';
16942: }
16943: balancerChange(balnum,baltotal,action,addtarget,removetarget);
16944: }
16945: return;
16946: }
16947:
16948: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
16949: if (baltotal > 1) {
16950: var offloadtypes = new Array('primary','default');
16951: var alltargets = new Array('$alltargets');
16952: var insttypes = new Array('$allinsttypes');
16953: for (var i=0; i<baltotal; i++) {
16954: if (i != balnum) {
16955: for (var j=0; j<offloadtypes.length; j++) {
16956: var total = alltargets.length - 1;
16957: for (var k=0; k<total; k++) {
16958: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
16959: var server = serveritem.value;
16960: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
16961: if (server == addtarget) {
16962: serveritem.disabled = '';
16963: }
16964: }
16965: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
16966: if (server == removetarget) {
16967: serveritem.disabled = 'disabled';
16968: serveritem.checked = false;
16969: }
16970: }
16971: }
16972: }
16973: for (var j=0; j<insttypes.length; j++) {
16974: if (insttypes[j] != '_LC_external') {
16975: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
16976: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
16977: var currSel = singleserver.selectedIndex;
16978: var currVal = singleserver.options[currSel].value;
16979: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
16980: var numoptions = singleserver.options.length;
16981: var needsnew = 1;
16982: for (var k=0; k<numoptions; k++) {
16983: if (singleserver.options[k] == addtarget) {
16984: needsnew = 0;
16985: break;
16986: }
16987: }
16988: if (needsnew == 1) {
16989: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
16990: }
16991: }
16992: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
16993: singleserver.options.length = 0;
16994: if ((currVal) && (currVal != removetarget)) {
16995: singleserver.options[0] = new Option("","",false,false);
16996: } else {
16997: singleserver.options[0] = new Option("","",true,true);
16998: }
16999: var idx = 0;
17000: for (var m=0; m<alltargets.length; m++) {
17001: if (currBalancers.indexOf(alltargets[m]) == -1) {
17002: idx ++;
17003: if (currVal == alltargets[m]) {
17004: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
17005: } else {
17006: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
17007: }
17008: }
17009: }
17010: }
17011: }
17012: }
17013: }
1.150 raeburn 17014: }
17015: }
17016: }
17017: return;
17018: }
17019:
1.152 raeburn 17020: // ]]>
17021: </script>
17022:
17023: END
17024: }
17025:
17026: sub new_spares_js {
17027: my @sparestypes = ('primary','default');
17028: my $types = join("','",@sparestypes);
17029: my $select = &mt('Select');
17030: return <<"END";
17031:
17032: <script type="text/javascript">
17033: // <![CDATA[
17034:
17035: function updateNewSpares(formname,lonhost) {
17036: var types = new Array('$types');
17037: var include = new Array();
17038: var exclude = new Array();
17039: for (var i=0; i<types.length; i++) {
17040: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
17041: for (var j=0; j<spareboxes.length; j++) {
17042: if (formname.elements[spareboxes[j]].checked) {
17043: exclude.push(formname.elements[spareboxes[j]].value);
17044: } else {
17045: include.push(formname.elements[spareboxes[j]].value);
17046: }
17047: }
17048: }
17049: for (var i=0; i<types.length; i++) {
17050: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
17051: var selIdx = newSpare.selectedIndex;
17052: var currnew = newSpare.options[selIdx].value;
17053: var okSpares = new Array();
17054: for (var j=0; j<newSpare.options.length; j++) {
17055: var possible = newSpare.options[j].value;
17056: if (possible != '') {
17057: if (exclude.indexOf(possible) == -1) {
17058: okSpares.push(possible);
17059: } else {
17060: if (currnew == possible) {
17061: selIdx = 0;
17062: }
17063: }
17064: }
17065: }
17066: for (var k=0; k<include.length; k++) {
17067: if (okSpares.indexOf(include[k]) == -1) {
17068: okSpares.push(include[k]);
17069: }
17070: }
17071: okSpares.sort();
17072: newSpare.options.length = 0;
17073: if (selIdx == 0) {
17074: newSpare.options[0] = new Option("$select","",true,true);
17075: } else {
17076: newSpare.options[0] = new Option("$select","",false,false);
17077: }
17078: for (var m=0; m<okSpares.length; m++) {
17079: var idx = m+1;
17080: var selThis = 0;
17081: if (selIdx != 0) {
17082: if (okSpares[m] == currnew) {
17083: selThis = 1;
17084: }
17085: }
17086: if (selThis == 1) {
17087: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
17088: } else {
17089: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
17090: }
17091: }
17092: }
17093: return;
17094: }
17095:
17096: function checkNewSpares(lonhost,type) {
17097: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
17098: var chosen = newSpare.options[newSpare.selectedIndex].value;
17099: if (chosen != '') {
17100: var othertype;
17101: var othernewSpare;
17102: if (type == 'primary') {
17103: othernewSpare = document.getElementById('newspare_default_'+lonhost);
17104: }
17105: if (type == 'default') {
17106: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
17107: }
17108: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
17109: othernewSpare.selectedIndex = 0;
17110: }
17111: }
17112: return;
17113: }
17114:
17115: // ]]>
17116: </script>
17117:
17118: END
17119:
17120: }
17121:
17122: sub common_domprefs_js {
17123: return <<"END";
17124:
17125: <script type="text/javascript">
17126: // <![CDATA[
17127:
1.150 raeburn 17128: function getIndicesByName(formname,item) {
1.152 raeburn 17129: var group = new Array();
1.150 raeburn 17130: for (var i=0;i<formname.elements.length;i++) {
17131: if (formname.elements[i].name == item) {
1.152 raeburn 17132: group.push(formname.elements[i].id);
1.150 raeburn 17133: }
17134: }
1.152 raeburn 17135: return group;
1.150 raeburn 17136: }
17137:
17138: // ]]>
17139: </script>
17140:
17141: END
1.152 raeburn 17142:
1.150 raeburn 17143: }
17144:
1.165 raeburn 17145: sub recaptcha_js {
17146: my %lt = &captcha_phrases();
17147: return <<"END";
17148:
17149: <script type="text/javascript">
17150: // <![CDATA[
17151:
17152: function updateCaptcha(caller,context) {
17153: var privitem;
17154: var pubitem;
17155: var privtext;
17156: var pubtext;
1.269 raeburn 17157: var versionitem;
17158: var versiontext;
1.165 raeburn 17159: if (document.getElementById(context+'_recaptchapub')) {
17160: pubitem = document.getElementById(context+'_recaptchapub');
17161: } else {
17162: return;
17163: }
17164: if (document.getElementById(context+'_recaptchapriv')) {
17165: privitem = document.getElementById(context+'_recaptchapriv');
17166: } else {
17167: return;
17168: }
17169: if (document.getElementById(context+'_recaptchapubtxt')) {
17170: pubtext = document.getElementById(context+'_recaptchapubtxt');
17171: } else {
17172: return;
17173: }
17174: if (document.getElementById(context+'_recaptchaprivtxt')) {
17175: privtext = document.getElementById(context+'_recaptchaprivtxt');
17176: } else {
17177: return;
17178: }
1.269 raeburn 17179: if (document.getElementById(context+'_recaptchaversion')) {
17180: versionitem = document.getElementById(context+'_recaptchaversion');
17181: } else {
17182: return;
17183: }
17184: if (document.getElementById(context+'_recaptchavertxt')) {
17185: versiontext = document.getElementById(context+'_recaptchavertxt');
17186: } else {
17187: return;
17188: }
1.165 raeburn 17189: if (caller.checked) {
17190: if (caller.value == 'recaptcha') {
17191: pubitem.type = 'text';
17192: privitem.type = 'text';
17193: pubitem.size = '40';
17194: privitem.size = '40';
17195: pubtext.innerHTML = "$lt{'pub'}";
17196: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 17197: versionitem.type = 'text';
17198: versionitem.size = '3';
1.289 raeburn 17199: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 17200: } else {
17201: pubitem.type = 'hidden';
17202: privitem.type = 'hidden';
1.269 raeburn 17203: versionitem.type = 'hidden';
1.165 raeburn 17204: pubtext.innerHTML = '';
17205: privtext.innerHTML = '';
1.269 raeburn 17206: versiontext.innerHTML = '';
1.165 raeburn 17207: }
17208: }
17209: return;
17210: }
17211:
17212: // ]]>
17213: </script>
17214:
17215: END
17216:
17217: }
17218:
1.236 raeburn 17219: sub toggle_display_js {
1.192 raeburn 17220: return <<"END";
17221:
17222: <script type="text/javascript">
17223: // <![CDATA[
17224:
1.236 raeburn 17225: function toggleDisplay(domForm,caller) {
17226: if (document.getElementById(caller)) {
17227: var divitem = document.getElementById(caller);
17228: var optionsElement = domForm.coursecredits;
1.264 raeburn 17229: var checkval = 1;
17230: var dispval = 'block';
1.303 raeburn 17231: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 17232: if (caller == 'emailoptions') {
17233: optionsElement = domForm.cancreate_email;
17234: }
1.257 raeburn 17235: if (caller == 'studentsubmission') {
17236: optionsElement = domForm.postsubmit;
17237: }
1.264 raeburn 17238: if (caller == 'cloneinstcode') {
17239: optionsElement = domForm.canclone;
17240: checkval = 'instcode';
17241: }
1.303 raeburn 17242: if (selfcreateRegExp.test(caller)) {
17243: optionsElement = domForm.elements[caller];
17244: checkval = 'other';
17245: dispval = 'inline'
17246: }
1.236 raeburn 17247: if (optionsElement.length) {
1.192 raeburn 17248: var currval;
1.236 raeburn 17249: for (var i=0; i<optionsElement.length; i++) {
17250: if (optionsElement[i].checked) {
17251: currval = optionsElement[i].value;
1.192 raeburn 17252: }
17253: }
1.264 raeburn 17254: if (currval == checkval) {
17255: divitem.style.display = dispval;
1.192 raeburn 17256: } else {
1.236 raeburn 17257: divitem.style.display = 'none';
1.192 raeburn 17258: }
17259: }
17260: }
17261: return;
17262: }
17263:
17264: // ]]>
17265: </script>
17266:
17267: END
17268:
17269: }
17270:
1.165 raeburn 17271: sub captcha_phrases {
17272: return &Apache::lonlocal::texthash (
17273: priv => 'Private key',
17274: pub => 'Public key',
17275: original => 'original (CAPTCHA)',
17276: recaptcha => 'successor (ReCAPTCHA)',
17277: notused => 'unused',
1.289 raeburn 17278: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 17279: );
17280: }
17281:
1.205 raeburn 17282: sub devalidate_remote_domconfs {
1.212 raeburn 17283: my ($dom,$cachekeys) = @_;
17284: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 17285: my %servers = &Apache::lonnet::internet_dom_servers($dom);
17286: my %thismachine;
17287: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.295 raeburn 17288: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions','directorysrch');
1.260 raeburn 17289: if (keys(%servers)) {
1.205 raeburn 17290: foreach my $server (keys(%servers)) {
17291: next if ($thismachine{$server});
1.212 raeburn 17292: my @cached;
17293: foreach my $name (@posscached) {
17294: if ($cachekeys->{$name}) {
17295: push(@cached,&escape($name).':'.&escape($dom));
17296: }
17297: }
17298: if (@cached) {
17299: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
17300: }
1.205 raeburn 17301: }
17302: }
17303: return;
17304: }
17305:
1.3 raeburn 17306: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>