Annotation of loncom/interface/domainprefs.pm, revision 1.322
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.322 ! raeburn 4: # $Id: domainprefs.pm,v 1.321 2017/12/06 23:41:19 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.322 ! raeburn 4115: my ($title,$key,$secret,$url,$lifetime,$imgsrc);
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: }
4126: }
1.319 raeburn 4127: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1.267 raeburn 4128: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4129: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
4130: for (my $k=0; $k<=$maxnum; $k++) {
4131: my $vpos = $k+1;
4132: my $selstr;
4133: if ($k == $i) {
4134: $selstr = ' selected="selected" ';
4135: }
4136: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4137: }
4138: $datatable .= '</select>'.(' 'x2).
4139: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
4140: &mt('Delete?').'</label></span></td>'.
4141: '<td colspan="2">'.
4142: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4143: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
4144: (' 'x2).
4145: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
4146: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4147: (' 'x2).
4148: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
4149: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
4150: '<br /><br />'.
4151: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_url_'.$i.'"'.
4152: ' value="'.$url.'" /></span>'.
4153: (' 'x2).
1.319 raeburn 4154: '<span class="LC_nobreak">'.$lt{'key'}.':'.
1.267 raeburn 4155: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
4156: (' 'x2).
1.322 ! raeburn 4157: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
! 4158: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
! 4159: (' 'x2).
1.267 raeburn 4160: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4161: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
4162: '<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>'.
4163: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
4164: '</fieldset>'.
4165: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4166: '<span class="LC_nobreak">'.&mt('Display target:');
4167: my %currdisp;
4168: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
4169: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
4170: $currdisp{'window'} = ' checked="checked"';
1.298 raeburn 4171: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
4172: $currdisp{'tab'} = ' checked="checked"';
1.267 raeburn 4173: } else {
4174: $currdisp{'iframe'} = ' checked="checked"';
4175: }
4176: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
4177: $currdisp{'width'} = $1;
4178: }
4179: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
4180: $currdisp{'height'} = $1;
4181: }
1.296 raeburn 4182: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
4183: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267 raeburn 4184: } else {
4185: $currdisp{'iframe'} = ' checked="checked"';
4186: }
1.298 raeburn 4187: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4188: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
4189: $lt{$disp}.'</label>'.(' 'x2);
4190: }
4191: $datatable .= (' 'x4);
4192: foreach my $dimen ('width','height') {
4193: $datatable .= '<label>'.$lt{$dimen}.' '.
4194: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
4195: (' 'x2);
4196: }
1.296 raeburn 4197: $datatable .= '<br />'.
4198: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
4199: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></label></div>'.
4200: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4201: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
4202: '</textarea></div><div style=""></div><br />';
1.319 raeburn 4203: my %units = (
4204: 'passback' => 'days',
4205: 'roster' => 'seconds',
4206: );
1.267 raeburn 4207: foreach my $extra ('passback','roster') {
1.319 raeburn 4208: my $validsty = 'none';
4209: my $currvalid;
1.267 raeburn 4210: my $checkedon = '';
4211: my $checkedoff = ' checked="checked"';
4212: if ($settings->{$item}->{$extra}) {
4213: $checkedon = $checkedoff;
4214: $checkedoff = '';
1.319 raeburn 4215: $validsty = 'inline-block';
4216: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
4217: $currvalid = $settings->{$item}->{$extra.'valid'};
4218: }
4219: }
4220: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
4221: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4222: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
4223: &mt('No').'</label>'.(' 'x2).
4224: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
4225: &mt('Yes').'</label></span></div>'.
4226: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
4227: '<span class="LC_nobreak">'.
4228: &mt("at least [_1] $units{$extra} after launch",
4229: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
4230: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4231: }
1.319 raeburn 4232: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
1.267 raeburn 4233: if ($imgsrc) {
4234: $datatable .= $imgsrc.
4235: '<label><input type="checkbox" name="ltitools_image_del"'.
4236: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
4237: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
4238: } else {
4239: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4240: }
4241: if ($switchserver) {
4242: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4243: } else {
4244: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
4245: }
4246: $datatable .= '</span></fieldset>';
4247: my (%checkedfields,%rolemaps);
4248: if (ref($settings->{$item}) eq 'HASH') {
4249: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
4250: %checkedfields = %{$settings->{$item}->{'fields'}};
4251: }
4252: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
4253: %rolemaps = %{$settings->{$item}->{'roles'}};
4254: $checkedfields{'roles'} = 1;
4255: }
4256: }
4257: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4258: '<span class="LC_nobreak">';
4259: foreach my $field (@fields) {
4260: my $checked;
4261: if ($checkedfields{$field}) {
4262: $checked = ' checked="checked"';
4263: }
4264: $datatable .= '<label>'.
4265: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$checked.' />'.
4266: $lt{$field}.'</label>'.(' ' x2);
4267: }
4268: $datatable .= '</span></fieldset>'.
4269: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4270: foreach my $role (@courseroles) {
4271: my ($selected,$selectnone);
4272: if (!$rolemaps{$role}) {
4273: $selectnone = ' selected="selected"';
4274: }
1.306 raeburn 4275: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4276: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4277: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
4278: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
4279: foreach my $ltirole (@ltiroles) {
4280: unless ($selectnone) {
4281: if ($rolemaps{$role} eq $ltirole) {
4282: $selected = ' selected="selected"';
4283: } else {
4284: $selected = '';
4285: }
4286: }
4287: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
4288: }
4289: $datatable .= '</select></td>';
4290: }
1.273 raeburn 4291: $datatable .= '</tr></table></fieldset>';
4292: my %courseconfig;
4293: if (ref($settings->{$item}) eq 'HASH') {
4294: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
4295: %courseconfig = %{$settings->{$item}->{'crsconf'}};
4296: }
4297: }
4298: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4299: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 4300: my $checked;
4301: if ($courseconfig{$item}) {
4302: $checked = ' checked="checked"';
4303: }
4304: $datatable .= '<label>'.
4305: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
4306: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
4307: }
4308: $datatable .= '</span></fieldset>'.
1.267 raeburn 4309: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4310: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
4311: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
4312: my %custom = %{$settings->{$item}->{'custom'}};
4313: if (keys(%custom) > 0) {
4314: foreach my $key (sort(keys(%custom))) {
4315: $datatable .= '<tr><td><span class="LC_nobreak">'.
4316: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
4317: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
4318: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
4319: ' value="'.$custom{$key}.'" /></td></tr>';
4320: }
4321: }
4322: }
4323: $datatable .= '<tr><td><span class="LC_nobreak">'.
4324: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
4325: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
4326: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
4327: $datatable .= '</table></fieldset></td></tr>'."\n";
4328: $itemcount ++;
4329: }
4330: }
4331: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.319 raeburn 4332: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1.267 raeburn 4333: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4334: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
4335: '<select name="ltitools_add_pos"'.$chgstr.'>';
4336: for (my $k=0; $k<$maxnum+1; $k++) {
4337: my $vpos = $k+1;
4338: my $selstr;
4339: if ($k == $maxnum) {
4340: $selstr = ' selected="selected" ';
4341: }
4342: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4343: }
4344: $datatable .= '</select> '."\n".
4345: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".
4346: '<td colspan="2">'.
4347: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4348: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_add_title" value="" /></span> '."\n".
4349: (' 'x2).
4350: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
4351: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4352: (' 'x2).
4353: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
4354: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
4355: '<br />'.
4356: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_add_url" value="" /></span> '."\n".
4357: (' 'x2).
4358: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
4359: (' 'x2).
1.322 ! raeburn 4360: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
! 4361: (' 'x2).
1.267 raeburn 4362: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
4363: '<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".
4364: '</fieldset>'.
4365: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4366: '<span class="LC_nobreak">'.&mt('Display target:');
4367: my %defaultdisp;
4368: $defaultdisp{'iframe'} = ' checked="checked"';
1.298 raeburn 4369: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4370: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
4371: $lt{$disp}.'</label>'.(' 'x2);
4372: }
4373: $datatable .= (' 'x4);
4374: foreach my $dimen ('width','height') {
4375: $datatable .= '<label>'.$lt{$dimen}.' '.
4376: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
4377: (' 'x2);
4378: }
1.296 raeburn 4379: $datatable .= '<br />'.
4380: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
4381: '<input type="text" name="ltitools_add_linktext" size="5" /></label></div>'.
4382: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4383: '<textarea name=ltitools_add_explanation" rows="5" cols="40"></textarea>'.
4384: '</div><div style=""></div><br />';
1.319 raeburn 4385: my %units = (
4386: 'passback' => 'days',
4387: 'roster' => 'seconds',
4388: );
4389: my %defaulttimes = (
4390: 'passback' => '7',
1.322 ! raeburn 4391: 'roster' => '300',
1.319 raeburn 4392: );
1.267 raeburn 4393: foreach my $extra ('passback','roster') {
1.319 raeburn 4394: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
4395: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4396: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
4397: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
4398: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
4399: &mt('Yes').'</label></span></div>'.
4400: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
4401: '<span class="LC_nobreak">'.
4402: &mt("at least [_1] $units{$extra} after launch",
4403: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
4404: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4405: }
1.319 raeburn 4406: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
1.267 raeburn 4407: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4408: if ($switchserver) {
4409: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4410: } else {
4411: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
4412: }
4413: $datatable .= '</span></fieldset>'.
4414: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4415: '<span class="LC_nobreak">';
4416: foreach my $field (@fields) {
4417: $datatable .= '<label>'.
4418: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'" />'.
4419: $lt{$field}.'</label>'.(' ' x2);
4420: }
4421: $datatable .= '</span></fieldset>'.
4422: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4423: foreach my $role (@courseroles) {
4424: my ($checked,$checkednone);
1.306 raeburn 4425: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4426: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4427: '<select name="ltitools_add_roles_'.$role.'">'.
4428: '<option value="" selected="selected">'.&mt('Select').'</option>';
4429: foreach my $ltirole (@ltiroles) {
4430: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
4431: }
4432: $datatable .= '</select></td>';
4433: }
4434: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 4435: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4436: foreach my $item ('label','title','target','linktext','explanation','append') {
1.296 raeburn 4437: $datatable .= '<label>'.
4438: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
4439: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
1.273 raeburn 4440: }
4441: $datatable .= '</span></fieldset>'.
1.267 raeburn 4442: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4443: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
4444: '<tr><td><span class="LC_nobreak">'.
4445: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
4446: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
4447: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
4448: '</table></fieldset></td></tr>'."\n".
4449: '</td>'."\n".
4450: '</tr>'."\n";
4451: $itemcount ++;
4452: return $datatable;
4453: }
4454:
4455: sub ltitools_names {
4456: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 4457: 'title' => 'Title',
4458: 'version' => 'Version',
4459: 'msgtype' => 'Message Type',
4460: 'url' => 'URL',
4461: 'key' => 'Key',
1.322 ! raeburn 4462: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 4463: 'secret' => 'Secret',
4464: 'icon' => 'Icon',
4465: 'user' => 'Username:domain',
4466: 'fullname' => 'Full Name',
4467: 'firstname' => 'First Name',
4468: 'lastname' => 'Last Name',
4469: 'email' => 'E-mail',
4470: 'roles' => 'Role',
1.298 raeburn 4471: 'window' => 'Window',
4472: 'tab' => 'Tab',
1.296 raeburn 4473: 'iframe' => 'iFrame',
4474: 'height' => 'Height',
4475: 'width' => 'Width',
4476: 'linktext' => 'Default Link Text',
4477: 'explanation' => 'Default Explanation',
4478: 'passback' => 'Tool can return grades:',
4479: 'roster' => 'Tool can retrieve roster:',
4480: 'crstarget' => 'Display target',
4481: 'crslabel' => 'Course label',
4482: 'crstitle' => 'Course title',
4483: 'crslinktext' => 'Link Text',
4484: 'crsexplanation' => 'Explanation',
1.318 raeburn 4485: 'crsappend' => 'Provider URL',
1.267 raeburn 4486: );
4487: return %lt;
4488: }
4489:
1.320 raeburn 4490: sub print_lti {
4491: my ($dom,$settings,$rowtotal) = @_;
4492: my $itemcount = 1;
4493: my $maxnum = 0;
4494: my $css_class;
4495: my %ordered;
4496: if (ref($settings) eq 'HASH') {
4497: foreach my $item (keys(%{$settings})) {
4498: if (ref($settings->{$item}) eq 'HASH') {
4499: my $num = $settings->{$item}{'order'};
4500: $ordered{$num} = $item;
4501: }
4502: }
4503: }
4504: my $maxnum = scalar(keys(%ordered));
4505: my $datatable = <i_javascript($settings);
4506: my %lt = <i_names();
4507: if (keys(%ordered)) {
4508: my @items = sort { $a <=> $b } keys(%ordered);
4509: for (my $i=0; $i<@items; $i++) {
4510: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4511: my $item = $ordered{$items[$i]};
4512: my ($key,$secret,$lifetime,$consumer,$current);
4513: if (ref($settings->{$item}) eq 'HASH') {
4514: $key = $settings->{$item}->{'key'};
4515: $secret = $settings->{$item}->{'secret'};
4516: $lifetime = $settings->{$item}->{'lifetime'};
4517: $consumer = $settings->{$item}->{'consumer'};
4518: $current = $settings->{$item};
4519: }
4520: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
4521: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4522: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
4523: for (my $k=0; $k<=$maxnum; $k++) {
4524: my $vpos = $k+1;
4525: my $selstr;
4526: if ($k == $i) {
4527: $selstr = ' selected="selected" ';
4528: }
4529: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4530: }
4531: $datatable .= '</select>'.(' 'x2).
4532: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
4533: &mt('Delete?').'</label></span></td>'.
4534: '<td colspan="2">'.
4535: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4536: '<span class="LC_nobreak">'.$lt{'consumer'}.
4537: ':<input type="text" size="20" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
4538: (' 'x2).
4539: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
4540: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4541: (' 'x2).
4542: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
4543: 'value="'.$lifetime.'" size="5" /></span>'.
4544: '<br /><br />'.
4545: '<span class="LC_nobreak">'.$lt{'key'}.
4546: ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
4547: (' 'x2).
4548: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4549: '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
4550: '<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>'.
4551: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
4552: '</fieldset>'.<i_options($i,$current,%lt).'</td></tr>';
4553: $itemcount ++;
4554: }
4555: }
4556: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4557: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
4558: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4559: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
4560: '<select name="lti_pos_add"'.$chgstr.'>';
4561: for (my $k=0; $k<$maxnum+1; $k++) {
4562: my $vpos = $k+1;
4563: my $selstr;
4564: if ($k == $maxnum) {
4565: $selstr = ' selected="selected" ';
4566: }
4567: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4568: }
4569: $datatable .= '</select> '."\n".
4570: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</td>'."\n".
4571: '<td colspan="2">'.
4572: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4573: '<span class="LC_nobreak">'.$lt{'consumer'}.
4574: ':<input type="text" size="20" name="lti_consumer_add" value="" /></span> '."\n".
4575: (' 'x2).
4576: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
4577: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4578: (' 'x2).
1.322 ! raeburn 4579: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="lti_lifetime_add" value="300" /></span> '."\n".
1.320 raeburn 4580: '<br /><br />'.
4581: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
4582: (' 'x2).
4583: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
4584: '<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".
4585: '</fieldset>'.<i_options('add',undef,%lt).
4586: '</td>'."\n".
4587: '</tr>'."\n";
4588: $$rowtotal ++;
4589: return $datatable;;
4590: }
4591:
4592: sub lti_names {
4593: my %lt = &Apache::lonlocal::texthash(
4594: 'version' => 'LTI Version',
4595: 'url' => 'URL',
4596: 'key' => 'Key',
1.322 ! raeburn 4597: 'lifetime' => 'Nonce lifetime (s)',
1.320 raeburn 4598: 'consumer' => 'LTI Consumer',
4599: 'secret' => 'Secret',
4600: 'email' => 'Email address',
4601: 'sourcedid' => 'User ID',
4602: 'other' => 'Other',
4603: 'passback' => 'Can return grades to Consumer:',
4604: 'roster' => 'Can retrieve roster from Consumer:',
4605: );
4606: return %lt;
4607: }
4608:
4609: sub lti_options {
4610: my ($num,$current,%lt) = @_;
4611: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield);
4612: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
4613: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
4614: $checked{'makecrs'}{'N'} = ' checked="checked"';
4615: $checked{'mapcrstype'} = {};
4616: $checked{'makeuser'} = {};
4617: $checked{'selfenroll'} = {};
4618: $checked{'crssec'} = {};
4619: $checked{'crssecsrc'} = {};
4620:
4621: my $userfieldsty = 'none';
4622: my $crsfieldsty = 'none';
4623: my $crssecfieldsty = 'none';
4624: my $secsrcfieldsty = 'none';
4625:
4626: if (ref($current) eq 'HASH') {
4627: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
4628: $checked{'mapuser'}{'sourcedid'} = '';
4629: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
4630: $checked{'mapuser'}{'email'} = ' checked="checked"';
4631: } else {
4632: $checked{'mapuser'}{'other'} = ' checked="checked"';
4633: $userfield = $current->{'mapuser'};
4634: $userfieldsty = 'inline-block';
4635: }
4636: }
4637: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
4638: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
4639: if ($current->{'mapcrs'} eq 'context_id') {
4640: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
4641: } else {
4642: $checked{'mapcrs'}{'other'} = ' checked="checked"';
4643: $cidfield = $current->{'mapcrs'};
4644: $crsfieldsty = 'inline-block';
4645: }
4646: }
4647: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
4648: foreach my $type (@{$current->{'mapcrstype'}}) {
4649: $checked{'mapcrstype'}{$type} = ' checked="checked"';
4650: }
4651: }
4652: if ($current->{'makecrs'}) {
4653: $checked{'makecrs'}{'Y'} = ' checked="checked"';
4654: }
4655: if (ref($current->{'makeuser'}) eq 'ARRAY') {
4656: foreach my $role (@{$current->{'makeuser'}}) {
4657: $checked{'makeuser'}{$role} = ' checked="checked"';
4658: }
4659: }
4660: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
4661: foreach my $role (@{$current->{'selfenroll'}}) {
4662: $checked{'selfenroll'}{$role} = ' checked="checked"';
4663: }
4664: }
4665: if (ref($current->{'maproles'}) eq 'HASH') {
4666: %rolemaps = %{$current->{'maproles'}};
4667: }
4668: if ($current->{'section'} ne '') {
4669: $checked{'crssec'}{'Y'} = ' checked="checked"';
4670: $crssecfieldsty = 'inline-block';
4671: if ($current->{'section'} eq 'course_section_sourcedid') {
4672: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
4673: } else {
4674: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
4675: $crssecsrc = $current->{'section'};
4676: $secsrcfieldsty = 'inline-block';
4677: }
4678: } else {
4679: $checked{'crssec'}{'N'} = ' checked="checked"';
4680: }
4681: } else {
4682: $checked{'makecrs'}{'N'} = ' checked="checked"';
4683: $checked{'crssec'}{'N'} = ' checked="checked"';
4684: }
4685: my @coursetypes = ('official','unofficial','community','textbook','placement');
4686: my %coursetypetitles = &Apache::lonlocal::texthash (
4687: official => 'Official',
4688: unofficial => 'Unofficial',
4689: community => 'Community',
4690: textbook => 'Textbook',
4691: placement => 'Placement Test',
4692: );
4693: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
4694: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
4695: my @courseroles = ('cc','in','ta','ep','st');
4696: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
4697: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
4698: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
4699: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
4700: my $output = '<fieldset><legend>'.&mt('Mapping users').'</legend>'.
4701: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
4702: foreach my $option ('sourcedid','email','other') {
4703: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
4704: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
4705: ($option eq 'other' ? '' : (' 'x2) );
4706: }
4707: $output .= '</span></div>'.
4708: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
4709: '<input type="text" name="lti_customuser_'.$num.'" '.
4710: 'value="'.$userfield.'" /></div></fieldset>'.
4711: '<fieldset><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
4712: foreach my $ltirole (@lticourseroles) {
4713: my ($selected,$selectnone);
4714: if ($rolemaps{$ltirole} eq '') {
4715: $selectnone = ' selected="selected"';
4716: }
4717: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
4718: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
4719: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
4720: foreach my $role (@courseroles) {
4721: unless ($selectnone) {
4722: if ($rolemaps{$ltirole} eq $role) {
4723: $selected = ' selected="selected"';
4724: } else {
4725: $selected = '';
4726: }
4727: }
4728: $output .= '<option value="'.$role.'"'.$selected.'>'.
4729: &Apache::lonnet::plaintext($role,'Course').
4730: '</option>';
4731: }
4732: $output .= '</select></td>';
4733: }
4734: $output .= '</tr></table></fieldset>'.
4735: '<fieldset><legend>'.&mt('Roles which may create user accounts').'</legend>';
4736: foreach my $ltirole (@ltiroles) {
4737: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
4738: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
4739: }
4740: $output .= '</fieldset>'.
4741: '<fieldset><legend>'.&mt('Mapping courses').'</legend>'.
4742: '<div class="LC_floatleft"><span class="LC_nobreak">'.
4743: &mt('Unique course identifier').': ';
4744: foreach my $option ('course_offering_sourcedid','context_id','other') {
4745: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
4746: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
4747: ($option eq 'other' ? '' : (' 'x2) );
4748: }
4749: $output .= '</div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'".>'.
4750: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
4751: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
4752: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
4753: foreach my $type (@coursetypes) {
4754: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
4755: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
4756: (' 'x2);
4757: }
4758: $output .= '</span></fieldset>'.
4759: '<fieldset><legend>'.&mt('Creating courses').'</legend>'.
4760: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
4761: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
4762: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
4763: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
4764: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
4765: '</fieldset>'.
4766: '<fieldset><legend>'.&mt('Roles which may self-enroll').'</legend>';
4767: foreach my $lticrsrole (@lticourseroles) {
4768: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
4769: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
4770: }
4771: $output .= '</fieldset>'.
4772: '<fieldset><legend>'.&mt('Course options').'</legend>'.
4773: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
4774: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
4775: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
4776: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
4777: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label><span></div>'.
4778: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
4779: '<span class="LC_nobreak">'.&mt('From').':<label>'.
4780: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
4781: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
4782: &mt('Standard field').'</label>'.(' 'x2).
4783: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
4784: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
4785: '</label></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
4786: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
4787: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
4788: foreach my $extra ('passback','roster') {
4789: my $checkedon = '';
4790: my $checkedoff = ' checked="checked"';
4791: if (ref($current) eq 'HASH') {
4792: if (($current->{$extra})) {
4793: $checkedon = $checkedoff;
4794: $checkedoff = '';
4795: }
4796: }
4797: $output .= $lt{$extra}.' '.
4798: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.' />'.
4799: &mt('No').'</label>'.(' 'x2).
4800: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.' />'.
4801: &mt('Yes').'</label><br />';
4802: }
4803: $output .= '</span></fieldset>';
4804: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
4805: #
4806: # $output .= '</fieldset>'.
4807: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
4808: return $output;
4809: }
4810:
1.121 raeburn 4811: sub print_coursedefaults {
1.139 raeburn 4812: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 4813: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 4814: my $itemcount = 1;
1.192 raeburn 4815: my %choices = &Apache::lonlocal::texthash (
4816: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 4817: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 4818: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
4819: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 4820: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
4821: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.314 raeburn 4822: texengine => 'Default method to display mathematics',
1.257 raeburn 4823: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 4824: canclone => "People who may clone a course (besides course's owner and coordinators)",
4825: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 4826: );
1.198 raeburn 4827: my %staticdefaults = (
1.314 raeburn 4828: texengine => 'MathJax',
1.198 raeburn 4829: anonsurvey_threshold => 10,
4830: uploadquota => 500,
1.257 raeburn 4831: postsubmit => 60,
1.276 raeburn 4832: mysqltables => 172800,
1.198 raeburn 4833: );
1.139 raeburn 4834: if ($position eq 'top') {
1.257 raeburn 4835: %defaultchecked = (
4836: 'canuse_pdfforms' => 'off',
4837: 'uselcmath' => 'on',
4838: 'usejsme' => 'on',
1.289 raeburn 4839: 'canclone' => 'none',
1.257 raeburn 4840: );
4841: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.314 raeburn 4842: my $deftex = $staticdefaults{'texengine'};
4843: if (ref($settings) eq 'HASH') {
4844: if ($settings->{'texengine'}) {
4845: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
4846: $deftex = $settings->{'texengine'};
4847: }
4848: }
4849: }
4850: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4851: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
4852: '<span class="LC_nobreak">'.$choices{'texengine'}.
4853: '</span></td><td class="LC_right_item">'.
4854: '<select name="texengine">'."\n";
4855: my %texoptions = (
4856: MathJax => 'MathJax',
4857: mimetex => &mt('Convert to Images'),
4858: tth => &mt('TeX to HTML'),
4859: );
4860: foreach my $renderer ('MathJax','mimetex','tth') {
4861: my $selected = '';
4862: if ($renderer eq $deftex) {
4863: $selected = ' selected="selected"';
4864: }
4865: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
4866: }
4867: $mathdisp .= '</select></td></tr>'."\n";
4868: $itemcount ++;
1.139 raeburn 4869: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 4870: \%choices,$itemcount);
1.314 raeburn 4871: $datatable = $mathdisp.$datatable;
1.264 raeburn 4872: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4873: $datatable .=
1.306 raeburn 4874: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 4875: '<span class="LC_nobreak">'.$choices{'canclone'}.
4876: '</span></td><td class="LC_left_item">';
4877: my $currcanclone = 'none';
4878: my $onclick;
4879: my @cloneoptions = ('none','domain');
4880: my %clonetitles = (
4881: none => 'No additional course requesters',
4882: domain => "Any course requester in course's domain",
4883: instcode => 'Course requests for official courses ...',
4884: );
4885: my (%codedefaults,@code_order,@posscodes);
4886: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
4887: \@code_order) eq 'ok') {
4888: if (@code_order > 0) {
4889: push(@cloneoptions,'instcode');
4890: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
4891: }
4892: }
4893: if (ref($settings) eq 'HASH') {
4894: if ($settings->{'canclone'}) {
4895: if (ref($settings->{'canclone'}) eq 'HASH') {
4896: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
4897: if (@code_order > 0) {
4898: $currcanclone = 'instcode';
4899: @posscodes = @{$settings->{'canclone'}{'instcode'}};
4900: }
4901: }
4902: } elsif ($settings->{'canclone'} eq 'domain') {
4903: $currcanclone = $settings->{'canclone'};
4904: }
4905: }
1.289 raeburn 4906: }
1.264 raeburn 4907: foreach my $option (@cloneoptions) {
4908: my ($checked,$additional);
4909: if ($currcanclone eq $option) {
4910: $checked = ' checked="checked"';
4911: }
4912: if ($option eq 'instcode') {
4913: if (@code_order) {
4914: my $show = 'none';
4915: if ($checked) {
4916: $show = 'block';
4917: }
1.317 raeburn 4918: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 4919: &mt('Institutional codes for new and cloned course have identical:').
4920: '<br />';
4921: foreach my $item (@code_order) {
4922: my $codechk;
4923: if ($checked) {
4924: if (grep(/^\Q$item\E$/,@posscodes)) {
4925: $codechk = ' checked="checked"';
4926: }
4927: }
4928: $additional .= '<label>'.
4929: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
4930: $item.'</label>';
4931: }
4932: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
4933: }
4934: }
4935: $datatable .=
4936: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
4937: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
4938: '</label> '.$additional.'</span><br />';
4939: }
4940: $datatable .= '</td>'.
4941: '</tr>';
4942: $itemcount ++;
1.139 raeburn 4943: } else {
4944: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 4945: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 4946: my $currusecredits = 0;
1.257 raeburn 4947: my $postsubmitclient = 1;
1.271 raeburn 4948: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 4949: if (ref($settings) eq 'HASH') {
4950: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 4951: if (ref($settings->{'uploadquota'}) eq 'HASH') {
4952: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
4953: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
4954: }
4955: }
1.192 raeburn 4956: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 4957: foreach my $type (@types) {
4958: next if ($type eq 'community');
4959: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
4960: if ($defcredits{$type} ne '') {
4961: $currusecredits = 1;
4962: }
4963: }
4964: }
4965: if (ref($settings->{'postsubmit'}) eq 'HASH') {
4966: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
4967: $postsubmitclient = 0;
4968: foreach my $type (@types) {
4969: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4970: }
4971: } else {
4972: foreach my $type (@types) {
4973: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
4974: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 4975: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 4976: } else {
4977: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4978: }
4979: } else {
4980: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4981: }
4982: }
4983: }
4984: } else {
4985: foreach my $type (@types) {
4986: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 4987: }
4988: }
1.276 raeburn 4989: if (ref($settings->{'mysqltables'}) eq 'HASH') {
4990: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
4991: $currmysql{$type} = $settings->{'mysqltables'}{$type};
4992: }
4993: } else {
4994: foreach my $type (@types) {
4995: $currmysql{$type} = $staticdefaults{'mysqltables'};
4996: }
4997: }
1.258 raeburn 4998: } else {
4999: foreach my $type (@types) {
5000: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5001: }
1.139 raeburn 5002: }
5003: if (!$currdefresponder) {
1.198 raeburn 5004: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 5005: } elsif ($currdefresponder < 1) {
5006: $currdefresponder = 1;
5007: }
1.198 raeburn 5008: foreach my $type (@types) {
5009: if ($curruploadquota{$type} eq '') {
5010: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
5011: }
5012: }
1.139 raeburn 5013: $datatable .=
1.192 raeburn 5014: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5015: $choices{'anonsurvey_threshold'}.
1.139 raeburn 5016: '</span></td>'.
5017: '<td class="LC_right_item"><span class="LC_nobreak">'.
5018: '<input type="text" name="anonsurvey_threshold"'.
5019: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 5020: '</td></tr>'."\n";
5021: $itemcount ++;
5022: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5023: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5024: $choices{'uploadquota'}.
5025: '</span></td>'.
1.306 raeburn 5026: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 5027: '<table><tr>';
1.198 raeburn 5028: foreach my $type (@types) {
1.306 raeburn 5029: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 5030: '<input type="text" name="uploadquota_'.$type.'"'.
5031: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
5032: }
5033: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 5034: $itemcount ++;
1.236 raeburn 5035: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 5036: my $display = 'none';
1.192 raeburn 5037: if ($currusecredits) {
5038: $display = 'block';
5039: }
5040: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 5041: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
5042: foreach my $type (@types) {
5043: next if ($type eq 'community');
1.306 raeburn 5044: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 5045: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 5046: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 5047: }
5048: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 5049: %defaultchecked = ('coursecredits' => 'off');
5050: @toggles = ('coursecredits');
5051: my $current = {
5052: 'coursecredits' => $currusecredits,
5053: };
5054: (my $table,$itemcount) =
5055: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 5056: \%choices,$itemcount,$onclick,$additional,'left');
5057: $datatable .= $table;
5058: $onclick = "toggleDisplay(this.form,'studentsubmission');";
5059: my $display = 'none';
5060: if ($postsubmitclient) {
5061: $display = 'block';
5062: }
5063: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 5064: &mt('Number of seconds submit is disabled').'<br />'.
5065: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
5066: '<table><tr>';
1.257 raeburn 5067: foreach my $type (@types) {
1.306 raeburn 5068: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 5069: '<input type="text" name="'.$type.'_timeout" value="'.
5070: $deftimeout{$type}.'" size="5" /></td>';
5071: }
5072: $additional .= '</tr></table></div>'."\n";
5073: %defaultchecked = ('postsubmit' => 'on');
5074: @toggles = ('postsubmit');
1.280 raeburn 5075: $current = {
5076: 'postsubmit' => $postsubmitclient,
5077: };
1.257 raeburn 5078: ($table,$itemcount) =
5079: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
5080: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 5081: $datatable .= $table;
1.276 raeburn 5082: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5083: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5084: $choices{'mysqltables'}.
5085: '</span></td>'.
1.306 raeburn 5086: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 5087: '<table><tr>';
5088: foreach my $type (@types) {
1.306 raeburn 5089: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 5090: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 5091: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 5092: }
5093: $datatable .= '</tr></table></td></tr>'."\n";
5094: $itemcount ++;
5095:
1.139 raeburn 5096: }
1.192 raeburn 5097: $$rowtotal += $itemcount;
1.121 raeburn 5098: return $datatable;
1.118 jms 5099: }
5100:
1.231 raeburn 5101: sub print_selfenrollment {
5102: my ($position,$dom,$settings,$rowtotal) = @_;
5103: my ($css_class,$datatable);
5104: my $itemcount = 1;
1.271 raeburn 5105: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 5106: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 5107: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
5108: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 5109: my @rows;
5110: my $key;
5111: if ($position eq 'top') {
5112: $key = 'admin';
5113: if (ref($rowsref) eq 'ARRAY') {
5114: @rows = @{$rowsref};
5115: }
5116: } elsif ($position eq 'middle') {
5117: $key = 'default';
5118: @rows = ('types','registered','approval','limit');
5119: }
5120: foreach my $row (@rows) {
5121: if (defined($titlesref->{$row})) {
5122: $itemcount ++;
5123: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5124: $datatable .= '<tr'.$css_class.'>'.
5125: '<td>'.$titlesref->{$row}.'</td>'.
5126: '<td class="LC_left_item">'.
5127: '<table><tr>';
5128: my (%current,%currentcap);
5129: if (ref($settings) eq 'HASH') {
5130: if (ref($settings->{$key}) eq 'HASH') {
5131: foreach my $type (@types) {
5132: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5133: $current{$type} = $settings->{$key}->{$type}->{$row};
5134: }
5135: if (($row eq 'limit') && ($key eq 'default')) {
5136: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5137: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
5138: }
5139: }
5140: }
5141: }
5142: }
5143: my %roles = (
5144: '0' => &Apache::lonnet::plaintext('dc'),
5145: );
5146:
5147: foreach my $type (@types) {
5148: unless (($row eq 'registered') && ($key eq 'default')) {
5149: $datatable .= '<th>'.&mt($type).'</th>';
5150: }
5151: }
5152: unless (($row eq 'registered') && ($key eq 'default')) {
5153: $datatable .= '</tr><tr>';
5154: }
5155: foreach my $type (@types) {
5156: if ($type eq 'community') {
5157: $roles{'1'} = &mt('Community personnel');
5158: } else {
5159: $roles{'1'} = &mt('Course personnel');
5160: }
5161: $datatable .= '<td style="vertical-align: top">';
5162: if ($position eq 'top') {
5163: my %checked;
5164: if ($current{$type} eq '0') {
5165: $checked{'0'} = ' checked="checked"';
5166: } else {
5167: $checked{'1'} = ' checked="checked"';
5168: }
5169: foreach my $role ('1','0') {
5170: $datatable .= '<span class="LC_nobreak"><label>'.
5171: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
5172: 'value="'.$role.'"'.$checked{$role}.' />'.
5173: $roles{$role}.'</label></span> ';
5174: }
5175: } else {
5176: if ($row eq 'types') {
5177: my %checked;
5178: if ($current{$type} =~ /^(all|dom)$/) {
5179: $checked{$1} = ' checked="checked"';
5180: } else {
5181: $checked{''} = ' checked="checked"';
5182: }
5183: foreach my $val ('','dom','all') {
5184: $datatable .= '<span class="LC_nobreak"><label>'.
5185: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5186: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5187: }
5188: } elsif ($row eq 'registered') {
5189: my %checked;
5190: if ($current{$type} eq '1') {
5191: $checked{'1'} = ' checked="checked"';
5192: } else {
5193: $checked{'0'} = ' checked="checked"';
5194: }
5195: foreach my $val ('0','1') {
5196: $datatable .= '<span class="LC_nobreak"><label>'.
5197: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5198: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5199: }
5200: } elsif ($row eq 'approval') {
5201: my %checked;
5202: if ($current{$type} =~ /^([12])$/) {
5203: $checked{$1} = ' checked="checked"';
5204: } else {
5205: $checked{'0'} = ' checked="checked"';
5206: }
5207: for my $val (0..2) {
5208: $datatable .= '<span class="LC_nobreak"><label>'.
5209: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5210: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5211: }
5212: } elsif ($row eq 'limit') {
5213: my %checked;
5214: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
5215: $checked{$1} = ' checked="checked"';
5216: } else {
5217: $checked{'none'} = ' checked="checked"';
5218: }
5219: my $cap;
5220: if ($currentcap{$type} =~ /^\d+$/) {
5221: $cap = $currentcap{$type};
5222: }
5223: foreach my $val ('none','allstudents','selfenrolled') {
5224: $datatable .= '<span class="LC_nobreak"><label>'.
5225: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5226: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5227: }
5228: $datatable .= '<br />'.
5229: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
5230: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
5231: '</span>';
5232: }
5233: }
5234: $datatable .= '</td>';
5235: }
5236: $datatable .= '</tr>';
5237: }
5238: $datatable .= '</table></td></tr>';
5239: }
5240: } elsif ($position eq 'bottom') {
1.235 raeburn 5241: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
5242: }
5243: $$rowtotal += $itemcount;
5244: return $datatable;
5245: }
5246:
5247: sub print_validation_rows {
5248: my ($caller,$dom,$settings,$rowtotal) = @_;
5249: my ($itemsref,$namesref,$fieldsref);
5250: if ($caller eq 'selfenroll') {
5251: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
5252: } elsif ($caller eq 'requestcourses') {
5253: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
5254: }
5255: my %currvalidation;
5256: if (ref($settings) eq 'HASH') {
5257: if (ref($settings->{'validation'}) eq 'HASH') {
5258: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 5259: }
1.235 raeburn 5260: }
5261: my $datatable;
5262: my $itemcount = 0;
5263: foreach my $item (@{$itemsref}) {
5264: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5265: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5266: $namesref->{$item}.
5267: '</span></td>'.
5268: '<td class="LC_left_item">';
5269: if (($item eq 'url') || ($item eq 'button')) {
5270: $datatable .= '<span class="LC_nobreak">'.
5271: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
5272: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
5273: } elsif ($item eq 'fields') {
5274: my @currfields;
5275: if (ref($currvalidation{$item}) eq 'ARRAY') {
5276: @currfields = @{$currvalidation{$item}};
5277: }
5278: foreach my $field (@{$fieldsref}) {
5279: my $check = '';
5280: if (grep(/^\Q$field\E$/,@currfields)) {
5281: $check = ' checked="checked"';
5282: }
5283: $datatable .= '<span class="LC_nobreak"><label>'.
5284: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
5285: ' value="'.$field.'"'.$check.' />'.$field.
5286: '</label></span> ';
5287: }
5288: } elsif ($item eq 'markup') {
5289: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
5290: $currvalidation{$item}.
1.231 raeburn 5291: '</textarea>';
1.235 raeburn 5292: }
5293: $datatable .= '</td></tr>'."\n";
5294: if (ref($rowtotal)) {
1.231 raeburn 5295: $itemcount ++;
5296: }
5297: }
1.235 raeburn 5298: if ($caller eq 'requestcourses') {
5299: my %currhash;
1.248 raeburn 5300: if (ref($settings) eq 'HASH') {
5301: if (ref($settings->{'validation'}) eq 'HASH') {
5302: if ($settings->{'validation'}{'dc'} ne '') {
5303: $currhash{$settings->{'validation'}{'dc'}} = 1;
5304: }
1.235 raeburn 5305: }
5306: }
5307: my $numinrow = 2;
5308: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
5309: 'validationdc',%currhash);
1.247 raeburn 5310: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5311: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.235 raeburn 5312: if ($numdc > 1) {
1.247 raeburn 5313: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 5314: } else {
1.247 raeburn 5315: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 5316: }
1.247 raeburn 5317: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 5318: $itemcount ++;
5319: }
5320: if (ref($rowtotal)) {
5321: $$rowtotal += $itemcount;
5322: }
1.231 raeburn 5323: return $datatable;
5324: }
5325:
1.137 raeburn 5326: sub print_usersessions {
5327: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 5328: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 5329: my (%by_ip,%by_location,@intdoms,@instdoms);
5330: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 5331:
5332: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 5333: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 5334: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 5335: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 5336: if ($position eq 'top') {
1.152 raeburn 5337: if (keys(%serverhomes) > 1) {
1.145 raeburn 5338: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.261 raeburn 5339: my $curroffloadnow;
5340: if (ref($settings) eq 'HASH') {
5341: if (ref($settings->{'offloadnow'}) eq 'HASH') {
5342: $curroffloadnow = $settings->{'offloadnow'};
5343: }
5344: }
5345: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 5346: } else {
1.140 raeburn 5347: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 5348: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
5349: '</td></tr>';
1.140 raeburn 5350: }
1.137 raeburn 5351: } else {
1.279 raeburn 5352: my %titles = &usersession_titles();
5353: my ($prefix,@types);
5354: if ($position eq 'bottom') {
5355: $prefix = 'remote';
5356: @types = ('version','excludedomain','includedomain');
1.145 raeburn 5357: } else {
1.279 raeburn 5358: $prefix = 'hosted';
5359: @types = ('excludedomain','includedomain');
5360: }
5361: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
5362: }
5363: $$rowtotal += $itemcount;
5364: return $datatable;
5365: }
5366:
5367: sub rules_by_location {
5368: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
5369: my ($datatable,$itemcount,$css_class);
5370: if (keys(%{$by_location}) == 0) {
5371: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5372: $datatable = '<tr'.$css_class.'><td colspan="2">'.
5373: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
5374: '</td></tr>';
5375: $itemcount = 1;
5376: } else {
5377: $itemcount = 0;
5378: my $numinrow = 5;
5379: my (%current,%checkedon,%checkedoff);
5380: my @locations = sort(keys(%{$by_location}));
5381: foreach my $type (@{$types}) {
5382: $checkedon{$type} = '';
5383: $checkedoff{$type} = ' checked="checked"';
5384: }
5385: if (ref($settings) eq 'HASH') {
5386: if (ref($settings->{$prefix}) eq 'HASH') {
5387: foreach my $key (keys(%{$settings->{$prefix}})) {
5388: $current{$key} = $settings->{$prefix}{$key};
5389: if ($key eq 'version') {
5390: if ($current{$key} ne '') {
1.145 raeburn 5391: $checkedon{$key} = ' checked="checked"';
5392: $checkedoff{$key} = '';
5393: }
1.279 raeburn 5394: } elsif (ref($current{$key}) eq 'ARRAY') {
5395: $checkedon{$key} = ' checked="checked"';
5396: $checkedoff{$key} = '';
1.137 raeburn 5397: }
5398: }
5399: }
1.279 raeburn 5400: }
5401: foreach my $type (@{$types}) {
5402: next if ($type ne 'version' && !@locations);
5403: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5404: $datatable .= '<tr'.$css_class.'>
5405: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
5406: <span class="LC_nobreak">
5407: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
5408: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
5409: if ($type eq 'version') {
5410: my @lcversions = &Apache::lonnet::all_loncaparevs();
5411: my $selector = '<select name="'.$prefix.'_version">';
5412: foreach my $version (@lcversions) {
5413: my $selected = '';
5414: if ($current{'version'} eq $version) {
5415: $selected = ' selected="selected"';
1.145 raeburn 5416: }
1.279 raeburn 5417: $selector .= ' <option value="'.$version.'"'.
5418: $selected.'>'.$version.'</option>';
5419: }
5420: $selector .= '</select> ';
5421: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
5422: } else {
5423: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
5424: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
5425: ' />'.(' 'x2).
5426: '<input type="button" value="'.&mt('uncheck all').'" '.
5427: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
5428: "\n".
5429: '</div><div><table>';
5430: my $rem;
5431: for (my $i=0; $i<@locations; $i++) {
5432: my ($showloc,$value,$checkedtype);
5433: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
5434: my $ip = $by_location->{$locations[$i]}->[0];
5435: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5436: $value = join(':',@{$by_ip->{$ip}});
5437: $showloc = join(', ',@{$by_ip->{$ip}});
5438: if (ref($current{$type}) eq 'ARRAY') {
5439: foreach my $loc (@{$by_ip->{$ip}}) {
5440: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
5441: $checkedtype = ' checked="checked"';
5442: last;
1.145 raeburn 5443: }
1.138 raeburn 5444: }
5445: }
5446: }
1.137 raeburn 5447: }
1.279 raeburn 5448: $rem = $i%($numinrow);
5449: if ($rem == 0) {
5450: if ($i > 0) {
5451: $datatable .= '</tr>';
5452: }
5453: $datatable .= '<tr>';
5454: }
5455: $datatable .= '<td class="LC_left_item">'.
5456: '<span class="LC_nobreak"><label>'.
5457: '<input type="checkbox" name="'.$prefix.'_'.$type.
5458: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
5459: '</label></span></td>';
5460: }
5461: $rem = @locations%($numinrow);
5462: my $colsleft = $numinrow - $rem;
5463: if ($colsleft > 1 ) {
5464: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5465: ' </td>';
5466: } elsif ($colsleft == 1) {
5467: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 5468: }
1.279 raeburn 5469: $datatable .= '</tr></table>';
1.137 raeburn 5470: }
1.279 raeburn 5471: $datatable .= '</td></tr>';
5472: $itemcount ++;
1.137 raeburn 5473: }
5474: }
1.279 raeburn 5475: return ($datatable,$itemcount);
1.137 raeburn 5476: }
5477:
1.275 raeburn 5478: sub print_ssl {
5479: my ($position,$dom,$settings,$rowtotal) = @_;
5480: my ($css_class,$datatable);
5481: my $itemcount = 1;
5482: if ($position eq 'top') {
1.281 raeburn 5483: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5484: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5485: my $same_institution;
5486: if ($intdom ne '') {
5487: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
5488: if (ref($internet_names) eq 'ARRAY') {
5489: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
5490: $same_institution = 1;
5491: }
5492: }
5493: }
1.275 raeburn 5494: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 5495: $datatable = '<tr'.$css_class.'><td colspan="2">';
5496: if ($same_institution) {
5497: my %domservers = &Apache::lonnet::get_servers($dom);
5498: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
5499: } else {
5500: $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.");
5501: }
5502: $datatable .= '</td></tr>';
1.275 raeburn 5503: $itemcount ++;
5504: } else {
5505: my %titles = &ssl_titles();
5506: my (%by_ip,%by_location,@intdoms,@instdoms);
5507: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
5508: my @alldoms = &Apache::lonnet::all_domains();
5509: my %serverhomes = %Apache::lonnet::serverhomeIDs;
5510: my @domservers = &Apache::lonnet::get_servers($dom);
5511: my %servers = &Apache::lonnet::internet_dom_servers($dom);
5512: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 5513: if (($position eq 'connto') || ($position eq 'connfrom')) {
5514: my $legacy;
5515: unless (ref($settings) eq 'HASH') {
5516: my $name;
5517: if ($position eq 'connto') {
5518: $name = 'loncAllowInsecure';
5519: } else {
5520: $name = 'londAllowInsecure';
5521: }
5522: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
5523: my @ids=&Apache::lonnet::current_machine_ids();
5524: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
5525: my %what = (
5526: $name => 1,
5527: );
5528: my ($result,$returnhash) =
5529: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
5530: if ($result eq 'ok') {
5531: if (ref($returnhash) eq 'HASH') {
5532: $legacy = $returnhash->{$name};
5533: }
5534: }
5535: } else {
5536: $legacy = $Apache::lonnet::perlvar{$name};
5537: }
5538: }
1.275 raeburn 5539: foreach my $type ('dom','intdom','other') {
5540: my %checked;
5541: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5542: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
5543: '<td class="LC_right_item">';
5544: my $skip;
5545: if ($type eq 'dom') {
5546: unless (keys(%servers) > 1) {
5547: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
5548: $skip = 1;
5549: }
5550: }
5551: if ($type eq 'intdom') {
5552: unless (@instdoms > 1) {
5553: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
5554: $skip = 1;
5555: }
5556: } elsif ($type eq 'other') {
5557: if (keys(%by_location) == 0) {
5558: $datatable .= &mt('Nothing to set here, as there are no other institutions');
5559: $skip = 1;
5560: }
5561: }
5562: unless ($skip) {
5563: $checked{'yes'} = ' checked="checked"';
5564: if (ref($settings) eq 'HASH') {
1.293 raeburn 5565: if (ref($settings->{$position}) eq 'HASH') {
5566: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 5567: $checked{$1} = $checked{'yes'};
5568: delete($checked{'yes'});
5569: }
5570: }
1.293 raeburn 5571: } else {
5572: if ($legacy == 0) {
5573: $checked{'req'} = $checked{'yes'};
5574: delete($checked{'yes'});
5575: }
1.275 raeburn 5576: }
5577: foreach my $option ('no','yes','req') {
5578: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 5579: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 5580: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
5581: '</label></span>'.(' 'x2);
5582: }
5583: }
5584: $datatable .= '</td></tr>';
5585: $itemcount ++;
5586: }
5587: } else {
5588: my $prefix = 'replication';
5589: my @types = ('certreq','nocertreq');
1.279 raeburn 5590: if (keys(%by_location) == 0) {
5591: $datatable .= '<tr'.$css_class.'><td>'.
5592: &mt('Nothing to set here, as there are no other institutions').
5593: '</td></tr>';
5594: $itemcount ++;
1.275 raeburn 5595: } else {
1.279 raeburn 5596: ($datatable,$itemcount) =
5597: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 5598: }
5599: }
5600: }
5601: $$rowtotal += $itemcount;
5602: return $datatable;
5603: }
5604:
5605: sub ssl_titles {
5606: return &Apache::lonlocal::texthash (
5607: dom => 'LON-CAPA servers/VMs from same domain',
5608: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
5609: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 5610: connto => 'Connections to other servers',
5611: connfrom => 'Connections from other servers',
1.275 raeburn 5612: replication => 'Replicating content to other institutions',
5613: certreq => 'Client certificate required, but specific domains exempt',
5614: nocertreq => 'No client certificate required, except for specific domains',
5615: no => 'SSL not used',
5616: yes => 'SSL Optional (used if available)',
5617: req => 'SSL Required',
5618: );
1.279 raeburn 5619: }
5620:
5621: sub print_trust {
5622: my ($prefix,$dom,$settings,$rowtotal) = @_;
5623: my ($css_class,$datatable,%checked,%choices);
5624: my (%by_ip,%by_location,@intdoms,@instdoms);
5625: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
5626: my $itemcount = 1;
5627: my %titles = &trust_titles();
5628: my @types = ('exc','inc');
5629: if ($prefix eq 'top') {
5630: $prefix = 'content';
5631: } elsif ($prefix eq 'bottom') {
5632: $prefix = 'msg';
5633: }
5634: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
5635: $$rowtotal += $itemcount;
5636: return $datatable;
5637: }
5638:
5639: sub trust_titles {
5640: return &Apache::lonlocal::texthash(
5641: content => "Access to this domain's content by others",
5642: shared => "Access to other domain's content by this domain",
5643: enroll => "Enrollment in this domain's courses by others",
5644: othcoau => "Co-author roles in this domain for others",
5645: coaurem => "Co-author roles for this domain's users elsewhere",
5646: domroles => "Domain roles in this domain assignable to others",
5647: catalog => "Course Catalog for this domain displayed elsewhere",
5648: reqcrs => "Requests for creation of courses in this domain by others",
5649: msg => "Users in other domains can send messages to this domain",
5650: exc => "Allow all, but exclude specific domains",
5651: inc => "Deny all, but include specific domains",
5652: );
1.275 raeburn 5653: }
5654:
1.138 raeburn 5655: sub build_location_hashes {
1.275 raeburn 5656: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 5657: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 5658: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 5659: my %iphost = &Apache::lonnet::get_iphost();
5660: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
5661: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
5662: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
5663: foreach my $id (@{$iphost{$primary_ip}}) {
5664: my $intdom = &Apache::lonnet::internet_dom($id);
5665: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
5666: push(@{$intdoms},$intdom);
5667: }
5668: }
5669: }
5670: foreach my $ip (keys(%iphost)) {
5671: if (ref($iphost{$ip}) eq 'ARRAY') {
5672: foreach my $id (@{$iphost{$ip}}) {
5673: my $location = &Apache::lonnet::internet_dom($id);
5674: if ($location) {
1.275 raeburn 5675: if (grep(/^\Q$location\E$/,@{$intdoms})) {
5676: my $dom = &Apache::lonnet::host_domain($id);
5677: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
5678: push(@{$instdoms},$dom);
5679: }
5680: next;
5681: }
1.138 raeburn 5682: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5683: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
5684: push(@{$by_ip->{$ip}},$location);
5685: }
5686: } else {
5687: $by_ip->{$ip} = [$location];
5688: }
5689: }
5690: }
5691: }
5692: }
5693: foreach my $ip (sort(keys(%{$by_ip}))) {
5694: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5695: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
5696: my $first = $by_ip->{$ip}->[0];
5697: if (ref($by_location->{$first}) eq 'ARRAY') {
5698: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
5699: push(@{$by_location->{$first}},$ip);
5700: }
5701: } else {
5702: $by_location->{$first} = [$ip];
5703: }
5704: }
5705: }
5706: return;
5707: }
5708:
1.145 raeburn 5709: sub current_offloads_to {
5710: my ($dom,$settings,$servers) = @_;
5711: my (%spareid,%otherdomconfigs);
1.152 raeburn 5712: if (ref($servers) eq 'HASH') {
1.145 raeburn 5713: foreach my $lonhost (sort(keys(%{$servers}))) {
5714: my $gotspares;
1.152 raeburn 5715: if (ref($settings) eq 'HASH') {
5716: if (ref($settings->{'spares'}) eq 'HASH') {
5717: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
5718: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
5719: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
5720: $gotspares = 1;
5721: }
1.145 raeburn 5722: }
5723: }
5724: unless ($gotspares) {
5725: my $gotspares;
5726: my $serverhomeID =
5727: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
5728: my $serverhomedom =
5729: &Apache::lonnet::host_domain($serverhomeID);
5730: if ($serverhomedom ne $dom) {
5731: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
5732: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5733: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5734: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5735: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5736: $gotspares = 1;
5737: }
5738: }
5739: } else {
5740: $otherdomconfigs{$serverhomedom} =
5741: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
5742: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
5743: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5744: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5745: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
5746: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5747: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5748: $gotspares = 1;
5749: }
5750: }
5751: }
5752: }
5753: }
5754: }
5755: }
5756: unless ($gotspares) {
5757: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
5758: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
5759: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
5760: } else {
5761: my $server_hostname = &Apache::lonnet::hostname($lonhost);
5762: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
5763: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
5764: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
5765: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
5766: } else {
1.150 raeburn 5767: my %what = (
5768: spareid => 1,
5769: );
5770: my ($result,$returnhash) =
5771: &Apache::lonnet::get_remote_globals($lonhost,\%what);
5772: if ($result eq 'ok') {
5773: if (ref($returnhash) eq 'HASH') {
5774: if (ref($returnhash->{'spareid'}) eq 'HASH') {
5775: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
5776: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
5777: }
5778: }
1.145 raeburn 5779: }
5780: }
5781: }
5782: }
5783: }
5784: }
5785: return %spareid;
5786: }
5787:
5788: sub spares_row {
1.261 raeburn 5789: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 5790: my $css_class;
5791: my $numinrow = 4;
5792: my $itemcount = 1;
5793: my $datatable;
1.152 raeburn 5794: my %typetitles = &sparestype_titles();
5795: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 5796: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 5797: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
5798: my ($othercontrol,$serverdom);
5799: if ($serverhome ne $server) {
5800: $serverdom = &Apache::lonnet::host_domain($serverhome);
5801: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5802: } else {
5803: $serverdom = &Apache::lonnet::host_domain($server);
5804: if ($serverdom ne $dom) {
5805: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5806: }
5807: }
5808: next unless (ref($spareid->{$server}) eq 'HASH');
1.261 raeburn 5809: my $checkednow;
5810: if (ref($curroffloadnow) eq 'HASH') {
5811: if ($curroffloadnow->{$server}) {
5812: $checkednow = ' checked="checked"';
5813: }
5814: }
1.145 raeburn 5815: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5816: $datatable .= '<tr'.$css_class.'>
5817: <td rowspan="2">
1.183 bisitz 5818: <span class="LC_nobreak">'.
5819: &mt('[_1] when busy, offloads to:'
1.261 raeburn 5820: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 5821: '<span class="LC_nobreak">'."\n".
1.261 raeburn 5822: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
5823: ' '.&mt('Switch active users on next access').'</label></span>'.
1.183 bisitz 5824: "\n";
1.145 raeburn 5825: my (%current,%canselect);
1.152 raeburn 5826: my @choices =
5827: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
5828: foreach my $type ('primary','default') {
5829: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 5830: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
5831: my @spares = @{$spareid->{$server}{$type}};
5832: if (@spares > 0) {
1.152 raeburn 5833: if ($othercontrol) {
5834: $current{$type} = join(', ',@spares);
5835: } else {
5836: $current{$type} .= '<table>';
5837: my $numspares = scalar(@spares);
5838: for (my $i=0; $i<@spares; $i++) {
5839: my $rem = $i%($numinrow);
5840: if ($rem == 0) {
5841: if ($i > 0) {
5842: $current{$type} .= '</tr>';
5843: }
5844: $current{$type} .= '<tr>';
1.145 raeburn 5845: }
1.152 raeburn 5846: $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'".');" /> '.
5847: $spareid->{$server}{$type}[$i].
5848: '</label></td>'."\n";
5849: }
5850: my $rem = @spares%($numinrow);
5851: my $colsleft = $numinrow - $rem;
5852: if ($colsleft > 1 ) {
5853: $current{$type} .= '<td colspan="'.$colsleft.
5854: '" class="LC_left_item">'.
5855: ' </td>';
5856: } elsif ($colsleft == 1) {
5857: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 5858: }
1.152 raeburn 5859: $current{$type} .= '</tr></table>';
1.150 raeburn 5860: }
1.145 raeburn 5861: }
5862: }
5863: if ($current{$type} eq '') {
5864: $current{$type} = &mt('None specified');
5865: }
1.152 raeburn 5866: if ($othercontrol) {
5867: if ($type eq 'primary') {
5868: $canselect{$type} = $othercontrol;
5869: }
5870: } else {
5871: $canselect{$type} =
5872: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
5873: '<select name="newspare_'.$type.'_'.$server.'" '.
5874: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
5875: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
5876: if (@choices > 0) {
5877: foreach my $lonhost (@choices) {
5878: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
5879: }
5880: }
5881: $canselect{$type} .= '</select>'."\n";
5882: }
5883: } else {
5884: $current{$type} = &mt('Could not be determined');
5885: if ($type eq 'primary') {
5886: $canselect{$type} = $othercontrol;
5887: }
1.145 raeburn 5888: }
1.152 raeburn 5889: if ($type eq 'default') {
5890: $datatable .= '<tr'.$css_class.'>';
5891: }
5892: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
5893: '<td>'.$current{$type}.'</td>'."\n".
5894: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 5895: }
5896: $itemcount ++;
5897: }
5898: }
5899: $$rowtotal += $itemcount;
5900: return $datatable;
5901: }
5902:
1.152 raeburn 5903: sub possible_newspares {
5904: my ($server,$currspares,$serverhomes,$altids) = @_;
5905: my $serverhostname = &Apache::lonnet::hostname($server);
5906: my %excluded;
5907: if ($serverhostname ne '') {
5908: %excluded = (
5909: $serverhostname => 1,
5910: );
5911: }
5912: if (ref($currspares) eq 'HASH') {
5913: foreach my $type (keys(%{$currspares})) {
5914: if (ref($currspares->{$type}) eq 'ARRAY') {
5915: if (@{$currspares->{$type}} > 0) {
5916: foreach my $curr (@{$currspares->{$type}}) {
5917: my $hostname = &Apache::lonnet::hostname($curr);
5918: $excluded{$hostname} = 1;
5919: }
5920: }
5921: }
5922: }
5923: }
5924: my @choices;
5925: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
5926: if (keys(%{$serverhomes}) > 1) {
5927: foreach my $name (sort(keys(%{$serverhomes}))) {
5928: unless ($excluded{$name}) {
5929: if (exists($altids->{$serverhomes->{$name}})) {
5930: push(@choices,$altids->{$serverhomes->{$name}});
5931: } else {
5932: push(@choices,$serverhomes->{$name});
1.145 raeburn 5933: }
5934: }
5935: }
5936: }
5937: }
1.152 raeburn 5938: return sort(@choices);
1.145 raeburn 5939: }
5940:
1.150 raeburn 5941: sub print_loadbalancing {
5942: my ($dom,$settings,$rowtotal) = @_;
5943: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5944: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5945: my $numinrow = 1;
5946: my $datatable;
5947: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 5948: my (%currbalancer,%currtargets,%currrules,%existing);
5949: if (ref($settings) eq 'HASH') {
5950: %existing = %{$settings};
5951: }
5952: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
5953: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
5954: \%currtargets,\%currrules);
1.150 raeburn 5955: } else {
5956: return;
5957: }
5958: my ($othertitle,$usertypes,$types) =
5959: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 5960: my $rownum = 8;
1.150 raeburn 5961: if (ref($types) eq 'ARRAY') {
5962: $rownum += scalar(@{$types});
5963: }
1.171 raeburn 5964: my @css_class = ('LC_odd_row','LC_even_row');
5965: my $balnum = 0;
5966: my $islast;
5967: my (@toshow,$disabledtext);
5968: if (keys(%currbalancer) > 0) {
5969: @toshow = sort(keys(%currbalancer));
5970: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
5971: push(@toshow,'');
5972: }
5973: } else {
5974: @toshow = ('');
5975: $disabledtext = &mt('No existing load balancer');
5976: }
5977: foreach my $lonhost (@toshow) {
5978: if ($balnum == scalar(@toshow)-1) {
5979: $islast = 1;
5980: } else {
5981: $islast = 0;
5982: }
5983: my $cssidx = $balnum%2;
5984: my $targets_div_style = 'display: none';
5985: my $disabled_div_style = 'display: block';
5986: my $homedom_div_style = 'display: none';
5987: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 5988: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 5989: '<p>';
5990: if ($lonhost eq '') {
1.210 raeburn 5991: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 5992: if (keys(%currbalancer) > 0) {
5993: $datatable .= &mt('Add balancer:');
5994: } else {
5995: $datatable .= &mt('Enable balancer:');
5996: }
5997: $datatable .= ' '.
5998: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
5999: ' id="loadbalancing_lonhost_'.$balnum.'"'.
6000: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
6001: '<option value="" selected="selected">'.&mt('None').
6002: '</option>'."\n";
6003: foreach my $server (sort(keys(%servers))) {
6004: next if ($currbalancer{$server});
6005: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
6006: }
1.210 raeburn 6007: $datatable .=
1.171 raeburn 6008: '</select>'."\n".
6009: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
6010: } else {
6011: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
6012: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
6013: &mt('Stop balancing').'</label>'.
6014: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
6015: $targets_div_style = 'display: block';
6016: $disabled_div_style = 'display: none';
6017: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
6018: $homedom_div_style = 'display: block';
6019: }
6020: }
1.306 raeburn 6021: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 6022: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
6023: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
6024: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
6025: my ($numspares,@spares) = &count_servers($lonhost,%servers);
6026: my @sparestypes = ('primary','default');
6027: my %typetitles = &sparestype_titles();
1.284 raeburn 6028: my %hostherechecked = (
6029: no => ' checked="checked"',
6030: );
1.171 raeburn 6031: foreach my $sparetype (@sparestypes) {
6032: my $targettable;
6033: for (my $i=0; $i<$numspares; $i++) {
6034: my $checked;
6035: if (ref($currtargets{$lonhost}) eq 'HASH') {
6036: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6037: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6038: $checked = ' checked="checked"';
6039: }
6040: }
6041: }
6042: my ($chkboxval,$disabled);
6043: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
6044: $chkboxval = $spares[$i];
6045: }
6046: if (exists($currbalancer{$spares[$i]})) {
6047: $disabled = ' disabled="disabled"';
6048: }
1.210 raeburn 6049: $targettable .=
1.253 raeburn 6050: '<td><span class="LC_nobreak"><label>'.
6051: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 6052: $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 6053: '</span></label></span></td>';
1.171 raeburn 6054: my $rem = $i%($numinrow);
6055: if ($rem == 0) {
6056: if (($i > 0) && ($i < $numspares-1)) {
6057: $targettable .= '</tr>';
6058: }
6059: if ($i < $numspares-1) {
6060: $targettable .= '<tr>';
1.150 raeburn 6061: }
6062: }
6063: }
1.171 raeburn 6064: if ($targettable ne '') {
6065: my $rem = $numspares%($numinrow);
6066: my $colsleft = $numinrow - $rem;
6067: if ($colsleft > 1 ) {
6068: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6069: ' </td>';
6070: } elsif ($colsleft == 1) {
6071: $targettable .= '<td class="LC_left_item"> </td>';
6072: }
6073: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
6074: '<table><tr>'.$targettable.'</tr></table><br />';
6075: }
1.284 raeburn 6076: $hostherechecked{$sparetype} = '';
6077: if (ref($currtargets{$lonhost}) eq 'HASH') {
6078: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6079: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6080: $hostherechecked{$sparetype} = ' checked="checked"';
6081: $hostherechecked{'no'} = '';
6082: }
6083: }
6084: }
6085: }
6086: $datatable .= &mt('Hosting on balancer itself').'<br />'.
6087: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
6088: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
6089: foreach my $sparetype (@sparestypes) {
6090: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
6091: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
6092: '</i></label><br />';
1.171 raeburn 6093: }
6094: $datatable .= '</div></td></tr>'.
6095: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
6096: $othertitle,$usertypes,$types,\%servers,
6097: \%currbalancer,$lonhost,
6098: $targets_div_style,$homedom_div_style,
6099: $css_class[$cssidx],$balnum,$islast);
6100: $$rowtotal += $rownum;
6101: $balnum ++;
6102: }
6103: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
6104: return $datatable;
6105: }
6106:
6107: sub get_loadbalancers_config {
6108: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
6109: return unless ((ref($servers) eq 'HASH') &&
6110: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
6111: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
6112: if (keys(%{$existing}) > 0) {
6113: my $oldlonhost;
6114: foreach my $key (sort(keys(%{$existing}))) {
6115: if ($key eq 'lonhost') {
6116: $oldlonhost = $existing->{'lonhost'};
6117: $currbalancer->{$oldlonhost} = 1;
6118: } elsif ($key eq 'targets') {
6119: if ($oldlonhost) {
6120: $currtargets->{$oldlonhost} = $existing->{'targets'};
6121: }
6122: } elsif ($key eq 'rules') {
6123: if ($oldlonhost) {
6124: $currrules->{$oldlonhost} = $existing->{'rules'};
6125: }
6126: } elsif (ref($existing->{$key}) eq 'HASH') {
6127: $currbalancer->{$key} = 1;
6128: $currtargets->{$key} = $existing->{$key}{'targets'};
6129: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 6130: }
6131: }
1.171 raeburn 6132: } else {
6133: my ($balancerref,$targetsref) =
6134: &Apache::lonnet::get_lonbalancer_config($servers);
6135: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
6136: foreach my $server (sort(keys(%{$balancerref}))) {
6137: $currbalancer->{$server} = 1;
6138: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 6139: }
6140: }
6141: }
1.171 raeburn 6142: return;
1.150 raeburn 6143: }
6144:
6145: sub loadbalancing_rules {
6146: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 6147: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
6148: $css_class,$balnum,$islast) = @_;
1.150 raeburn 6149: my $output;
1.171 raeburn 6150: my $num = 0;
1.210 raeburn 6151: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 6152: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
6153: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
6154: foreach my $type (@{$alltypes}) {
1.171 raeburn 6155: $num ++;
1.150 raeburn 6156: my $current;
6157: if (ref($currrules) eq 'HASH') {
6158: $current = $currrules->{$type};
6159: }
1.253 raeburn 6160: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 6161: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 6162: $current = '';
6163: }
6164: }
6165: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 6166: $servers,$currbalancer,$lonhost,$dom,
6167: $targets_div_style,$homedom_div_style,
6168: $css_class,$balnum,$num,$islast);
1.150 raeburn 6169: }
6170: }
6171: return $output;
6172: }
6173:
6174: sub loadbalancing_titles {
6175: my ($dom,$intdom,$usertypes,$types) = @_;
6176: my %othertypes = (
6177: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
6178: '_LC_author' => &mt('Users from [_1] with author role',$dom),
6179: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
6180: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 6181: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
6182: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 6183: );
1.209 raeburn 6184: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 6185: my @available;
1.150 raeburn 6186: if (ref($types) eq 'ARRAY') {
1.302 raeburn 6187: @available = @{$types};
1.150 raeburn 6188: }
1.302 raeburn 6189: unless (grep(/^default$/,@available)) {
6190: push(@available,'default');
6191: }
6192: unshift(@alltypes,@available);
1.150 raeburn 6193: my %titles;
6194: foreach my $type (@alltypes) {
6195: if ($type =~ /^_LC_/) {
6196: $titles{$type} = $othertypes{$type};
6197: } elsif ($type eq 'default') {
6198: $titles{$type} = &mt('All users from [_1]',$dom);
6199: if (ref($types) eq 'ARRAY') {
6200: if (@{$types} > 0) {
6201: $titles{$type} = &mt('Other users from [_1]',$dom);
6202: }
6203: }
6204: } elsif (ref($usertypes) eq 'HASH') {
6205: $titles{$type} = $usertypes->{$type};
6206: }
6207: }
6208: return (\@alltypes,\%othertypes,\%titles);
6209: }
6210:
6211: sub loadbalance_rule_row {
1.171 raeburn 6212: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
6213: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 6214: my @rulenames;
1.150 raeburn 6215: my %ruletitles = &offloadtype_text();
1.209 raeburn 6216: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 6217: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 6218: } else {
1.209 raeburn 6219: @rulenames = ('default','homeserver');
6220: if ($type eq '_LC_external') {
6221: push(@rulenames,'externalbalancer');
6222: } else {
6223: push(@rulenames,'specific');
6224: }
6225: push(@rulenames,'none');
1.150 raeburn 6226: }
6227: my $style = $targets_div_style;
1.253 raeburn 6228: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 6229: $style = $homedom_div_style;
6230: }
1.171 raeburn 6231: my $space;
6232: if ($islast && $num == 1) {
1.317 raeburn 6233: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 6234: }
1.210 raeburn 6235: my $output =
1.306 raeburn 6236: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 6237: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
6238: '<td valaign="top">'.$space.
6239: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 6240: for (my $i=0; $i<@rulenames; $i++) {
6241: my $rule = $rulenames[$i];
6242: my ($checked,$extra);
6243: if ($rulenames[$i] eq 'default') {
6244: $rule = '';
6245: }
6246: if ($rulenames[$i] eq 'specific') {
6247: if (ref($servers) eq 'HASH') {
6248: my $default;
6249: if (($current ne '') && (exists($servers->{$current}))) {
6250: $checked = ' checked="checked"';
6251: }
6252: unless ($checked) {
6253: $default = ' selected="selected"';
6254: }
1.210 raeburn 6255: $extra =
1.171 raeburn 6256: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
6257: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
6258: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
6259: '<option value=""'.$default.'></option>'."\n";
6260: foreach my $server (sort(keys(%{$servers}))) {
6261: if (ref($currbalancer) eq 'HASH') {
6262: next if (exists($currbalancer->{$server}));
6263: }
1.150 raeburn 6264: my $selected;
1.171 raeburn 6265: if ($server eq $current) {
1.150 raeburn 6266: $selected = ' selected="selected"';
6267: }
1.171 raeburn 6268: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 6269: }
6270: $extra .= '</select>';
6271: }
6272: } elsif ($rule eq $current) {
6273: $checked = ' checked="checked"';
6274: }
6275: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 6276: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
6277: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
6278: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 6279: ')"'.$checked.' /> ';
6280: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
6281: $output .= $ruletitles{'particular'};
6282: } else {
6283: $output .= $ruletitles{$rulenames[$i]};
6284: }
6285: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 6286: }
6287: $output .= '</div></td></tr>'."\n";
6288: return $output;
6289: }
6290:
6291: sub offloadtype_text {
6292: my %ruletitles = &Apache::lonlocal::texthash (
6293: 'default' => 'Offloads to default destinations',
6294: 'homeserver' => "Offloads to user's home server",
6295: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
6296: 'specific' => 'Offloads to specific server',
1.161 raeburn 6297: 'none' => 'No offload',
1.209 raeburn 6298: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
6299: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 6300: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 6301: );
6302: return %ruletitles;
6303: }
6304:
6305: sub sparestype_titles {
6306: my %typestitles = &Apache::lonlocal::texthash (
6307: 'primary' => 'primary',
6308: 'default' => 'default',
6309: );
6310: return %typestitles;
6311: }
6312:
1.28 raeburn 6313: sub contact_titles {
6314: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 6315: 'supportemail' => 'Support E-mail address',
6316: 'adminemail' => 'Default Server Admin E-mail address',
6317: 'errormail' => 'Error reports to be e-mailed to',
6318: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 6319: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
6320: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 6321: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
6322: 'requestsmail' => 'E-mail from course requests requiring approval',
6323: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 6324: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 6325: );
6326: my %short_titles = &Apache::lonlocal::texthash (
6327: adminemail => 'Admin E-mail address',
6328: supportemail => 'Support E-mail',
6329: );
6330: return (\%titles,\%short_titles);
6331: }
6332:
1.286 raeburn 6333: sub helpform_fields {
6334: my %titles = &Apache::lonlocal::texthash (
6335: 'username' => 'Name',
6336: 'user' => 'Username/domain',
6337: 'phone' => 'Phone',
6338: 'cc' => 'Cc e-mail',
6339: 'course' => 'Course Details',
6340: 'section' => 'Sections',
1.289 raeburn 6341: 'screenshot' => 'File upload',
1.286 raeburn 6342: );
6343: my @fields = ('username','phone','user','course','section','cc','screenshot');
6344: my %possoptions = (
6345: username => ['yes','no','req'],
1.289 raeburn 6346: phone => ['yes','no','req'],
1.286 raeburn 6347: user => ['yes','no'],
1.289 raeburn 6348: cc => ['yes','no'],
1.286 raeburn 6349: course => ['yes','no'],
6350: section => ['yes','no'],
6351: screenshot => ['yes','no'],
6352: );
6353: my %fieldoptions = &Apache::lonlocal::texthash (
6354: 'yes' => 'Optional',
6355: 'req' => 'Required',
6356: 'no' => "Not shown",
6357: );
6358: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
6359: }
6360:
1.72 raeburn 6361: sub tool_titles {
6362: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 6363: aboutme => 'Personal web page',
1.86 raeburn 6364: blog => 'Blog',
1.162 raeburn 6365: webdav => 'WebDAV',
1.86 raeburn 6366: portfolio => 'Portfolio',
1.88 bisitz 6367: official => 'Official courses (with institutional codes)',
6368: unofficial => 'Unofficial courses',
1.98 raeburn 6369: community => 'Communities',
1.216 raeburn 6370: textbook => 'Textbook courses',
1.271 raeburn 6371: placement => 'Placement tests',
1.86 raeburn 6372: );
1.72 raeburn 6373: return %titles;
6374: }
6375:
1.101 raeburn 6376: sub courserequest_titles {
6377: my %titles = &Apache::lonlocal::texthash (
6378: official => 'Official',
6379: unofficial => 'Unofficial',
6380: community => 'Communities',
1.216 raeburn 6381: textbook => 'Textbook',
1.271 raeburn 6382: placement => 'Placement tests',
1.101 raeburn 6383: norequest => 'Not allowed',
1.104 raeburn 6384: approval => 'Approval by Dom. Coord.',
1.101 raeburn 6385: validate => 'With validation',
6386: autolimit => 'Numerical limit',
1.103 raeburn 6387: unlimited => '(blank for unlimited)',
1.101 raeburn 6388: );
6389: return %titles;
6390: }
6391:
1.163 raeburn 6392: sub authorrequest_titles {
6393: my %titles = &Apache::lonlocal::texthash (
6394: norequest => 'Not allowed',
6395: approval => 'Approval by Dom. Coord.',
6396: automatic => 'Automatic approval',
6397: );
6398: return %titles;
1.210 raeburn 6399: }
1.163 raeburn 6400:
1.101 raeburn 6401: sub courserequest_conditions {
6402: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 6403: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 6404: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 6405: );
6406: return %conditions;
6407: }
6408:
6409:
1.27 raeburn 6410: sub print_usercreation {
1.30 raeburn 6411: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 6412: my $numinrow = 4;
1.28 raeburn 6413: my $datatable;
6414: if ($position eq 'top') {
1.30 raeburn 6415: $$rowtotal ++;
1.34 raeburn 6416: my $rowcount = 0;
1.32 raeburn 6417: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 6418: if (ref($rules) eq 'HASH') {
6419: if (keys(%{$rules}) > 0) {
1.32 raeburn 6420: $datatable .= &user_formats_row('username',$settings,$rules,
6421: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 6422: $$rowtotal ++;
1.32 raeburn 6423: $rowcount ++;
6424: }
6425: }
6426: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
6427: if (ref($idrules) eq 'HASH') {
6428: if (keys(%{$idrules}) > 0) {
6429: $datatable .= &user_formats_row('id',$settings,$idrules,
6430: $idruleorder,$numinrow,$rowcount);
6431: $$rowtotal ++;
6432: $rowcount ++;
1.28 raeburn 6433: }
6434: }
1.39 raeburn 6435: if ($rowcount == 0) {
6436: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
6437: $$rowtotal ++;
6438: $rowcount ++;
6439: }
1.34 raeburn 6440: } elsif ($position eq 'middle') {
1.224 raeburn 6441: my @creators = ('author','course','requestcrs');
1.37 raeburn 6442: my ($rules,$ruleorder) =
6443: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 6444: my %lt = &usercreation_types();
6445: my %checked;
6446: if (ref($settings) eq 'HASH') {
6447: if (ref($settings->{'cancreate'}) eq 'HASH') {
6448: foreach my $item (@creators) {
6449: $checked{$item} = $settings->{'cancreate'}{$item};
6450: }
6451: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
6452: foreach my $item (@creators) {
6453: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
6454: $checked{$item} = 'none';
6455: }
6456: }
6457: }
6458: }
6459: my $rownum = 0;
6460: foreach my $item (@creators) {
6461: $rownum ++;
1.224 raeburn 6462: if ($checked{$item} eq '') {
6463: $checked{$item} = 'any';
1.34 raeburn 6464: }
6465: my $css_class;
6466: if ($rownum%2) {
6467: $css_class = '';
6468: } else {
6469: $css_class = ' class="LC_odd_row" ';
6470: }
6471: $datatable .= '<tr'.$css_class.'>'.
6472: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 6473: '</span></td><td style="text-align: right">';
1.224 raeburn 6474: my @options = ('any');
6475: if (ref($rules) eq 'HASH') {
6476: if (keys(%{$rules}) > 0) {
6477: push(@options,('official','unofficial'));
1.37 raeburn 6478: }
6479: }
1.224 raeburn 6480: push(@options,'none');
1.37 raeburn 6481: foreach my $option (@options) {
1.50 raeburn 6482: my $type = 'radio';
1.34 raeburn 6483: my $check = ' ';
1.224 raeburn 6484: if ($checked{$item} eq $option) {
6485: $check = ' checked="checked" ';
1.34 raeburn 6486: }
6487: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 6488: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 6489: $item.'" value="'.$option.'"'.$check.'/> '.
6490: $lt{$option}.'</label> </span>';
6491: }
6492: $datatable .= '</td></tr>';
6493: }
1.28 raeburn 6494: } else {
6495: my @contexts = ('author','course','domain');
6496: my @authtypes = ('int','krb4','krb5','loc');
6497: my %checked;
6498: if (ref($settings) eq 'HASH') {
6499: if (ref($settings->{'authtypes'}) eq 'HASH') {
6500: foreach my $item (@contexts) {
6501: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
6502: foreach my $auth (@authtypes) {
6503: if ($settings->{'authtypes'}{$item}{$auth}) {
6504: $checked{$item}{$auth} = ' checked="checked" ';
6505: }
6506: }
6507: }
6508: }
1.27 raeburn 6509: }
1.35 raeburn 6510: } else {
6511: foreach my $item (@contexts) {
1.36 raeburn 6512: foreach my $auth (@authtypes) {
1.35 raeburn 6513: $checked{$item}{$auth} = ' checked="checked" ';
6514: }
6515: }
1.27 raeburn 6516: }
1.28 raeburn 6517: my %title = &context_names();
6518: my %authname = &authtype_names();
6519: my $rownum = 0;
6520: my $css_class;
6521: foreach my $item (@contexts) {
6522: if ($rownum%2) {
6523: $css_class = '';
6524: } else {
6525: $css_class = ' class="LC_odd_row" ';
6526: }
1.30 raeburn 6527: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 6528: '<td>'.$title{$item}.
6529: '</td><td class="LC_left_item">'.
6530: '<span class="LC_nobreak">';
6531: foreach my $auth (@authtypes) {
6532: $datatable .= '<label>'.
6533: '<input type="checkbox" name="'.$item.'_auth" '.
6534: $checked{$item}{$auth}.' value="'.$auth.'" />'.
6535: $authname{$auth}.'</label> ';
6536: }
6537: $datatable .= '</span></td></tr>';
6538: $rownum ++;
1.27 raeburn 6539: }
1.30 raeburn 6540: $$rowtotal += $rownum;
1.27 raeburn 6541: }
6542: return $datatable;
6543: }
6544:
1.224 raeburn 6545: sub print_selfcreation {
6546: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 6547: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
6548: $emaildomain,$datatable);
1.224 raeburn 6549: if (ref($settings) eq 'HASH') {
6550: if (ref($settings->{'cancreate'}) eq 'HASH') {
6551: $createsettings = $settings->{'cancreate'};
1.236 raeburn 6552: if (ref($createsettings) eq 'HASH') {
6553: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
6554: @selfcreate = @{$createsettings->{'selfcreate'}};
6555: } elsif ($createsettings->{'selfcreate'} ne '') {
6556: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
6557: @selfcreate = ('email','login','sso');
6558: } elsif ($createsettings->{'selfcreate'} ne 'none') {
6559: @selfcreate = ($createsettings->{'selfcreate'});
6560: }
6561: }
6562: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
6563: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 6564: }
1.305 raeburn 6565: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
6566: $emailoptions = $createsettings->{'emailoptions'};
6567: }
1.303 raeburn 6568: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
6569: $emailverified = $createsettings->{'emailverified'};
6570: }
6571: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
6572: $emaildomain = $createsettings->{'emaildomain'};
6573: }
1.224 raeburn 6574: }
6575: }
6576: }
6577: my %radiohash;
6578: my $numinrow = 4;
6579: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 6580: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 6581: if ($position eq 'top') {
6582: my %choices = &Apache::lonlocal::texthash (
6583: cancreate_login => 'Institutional Login',
6584: cancreate_sso => 'Institutional Single Sign On',
6585: );
6586: my @toggles = sort(keys(%choices));
6587: my %defaultchecked = (
6588: 'cancreate_login' => 'off',
6589: 'cancreate_sso' => 'off',
6590: );
1.228 raeburn 6591: my ($onclick,$itemcount);
1.224 raeburn 6592: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6593: \%choices,$itemcount,$onclick);
1.228 raeburn 6594: $$rowtotal += $itemcount;
6595:
1.224 raeburn 6596: if (ref($usertypes) eq 'HASH') {
6597: if (keys(%{$usertypes}) > 0) {
6598: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
6599: $dom,$numinrow,$othertitle,
1.305 raeburn 6600: 'statustocreate',$rowtotal);
1.224 raeburn 6601: $$rowtotal ++;
6602: }
6603: }
1.240 raeburn 6604: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
6605: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6606: $fieldtitles{'inststatus'} = &mt('Institutional status');
6607: my $rem;
6608: my $numperrow = 2;
6609: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
6610: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 6611: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 6612: '<td class="LC_left_item">'."\n".
6613: '<table><tr><td>'."\n";
6614: for (my $i=0; $i<@fields; $i++) {
6615: $rem = $i%($numperrow);
6616: if ($rem == 0) {
6617: if ($i > 0) {
6618: $datatable .= '</tr>';
6619: }
6620: $datatable .= '<tr>';
6621: }
6622: my $currval;
1.248 raeburn 6623: if (ref($createsettings) eq 'HASH') {
6624: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
6625: $currval = $createsettings->{'shibenv'}{$fields[$i]};
6626: }
1.240 raeburn 6627: }
6628: $datatable .= '<td class="LC_left_item">'.
6629: '<span class="LC_nobreak">'.
6630: '<input type="text" name="shibenv_'.$fields[$i].'" '.
6631: 'value="'.$currval.'" size="10" /> '.
6632: $fieldtitles{$fields[$i]}.'</span></td>';
6633: }
6634: my $colsleft = $numperrow - $rem;
6635: if ($colsleft > 1 ) {
6636: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6637: ' </td>';
6638: } elsif ($colsleft == 1) {
6639: $datatable .= '<td class="LC_left_item"> </td>';
6640: }
6641: $datatable .= '</tr></table></td></tr>';
6642: $$rowtotal ++;
1.224 raeburn 6643: } elsif ($position eq 'middle') {
6644: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 6645: my @posstypes;
1.224 raeburn 6646: if (ref($types) eq 'ARRAY') {
1.302 raeburn 6647: @posstypes = @{$types};
6648: }
6649: unless (grep(/^default$/,@posstypes)) {
6650: push(@posstypes,'default');
6651: }
6652: my %usertypeshash;
6653: if (ref($usertypes) eq 'HASH') {
6654: %usertypeshash = %{$usertypes};
6655: }
6656: $usertypeshash{'default'} = $othertitle;
6657: foreach my $status (@posstypes) {
6658: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
6659: $numinrow,$$rowtotal,\%usertypeshash);
6660: $$rowtotal ++;
1.224 raeburn 6661: }
6662: } else {
1.236 raeburn 6663: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 6664: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 6665: );
6666: my @toggles = sort(keys(%choices));
6667: my %defaultchecked = (
6668: 'cancreate_email' => 'off',
6669: );
1.305 raeburn 6670: my $customclass = 'LC_selfcreate_email';
6671: my $classprefix = 'LC_canmodify_emailusername_';
6672: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 6673: my $display = 'none';
1.305 raeburn 6674: my $rowstyle = 'display:none';
1.236 raeburn 6675: if (grep(/^\Qemail\E$/,@selfcreate)) {
6676: $display = 'block';
1.305 raeburn 6677: $rowstyle = 'display:table-row';
1.236 raeburn 6678: }
1.305 raeburn 6679: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
6680: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6681: \%choices,$$rowtotal,$onclick);
6682: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
6683: $rowstyle);
6684: $$rowtotal ++;
6685: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
6686: $rowstyle);
6687: $$rowtotal ++;
6688: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 6689: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 6690: my ($emailrules,$emailruleorder) =
6691: &Apache::lonnet::inst_userrules($dom,'email');
6692: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6693: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6694: if (ref($types) eq 'ARRAY') {
6695: @posstypes = @{$types};
6696: }
6697: if (@posstypes) {
6698: unless (grep(/^default$/,@posstypes)) {
6699: push(@posstypes,'default');
1.302 raeburn 6700: }
6701: if (ref($usertypes) eq 'HASH') {
6702: %usertypeshash = %{$usertypes};
6703: }
1.305 raeburn 6704: my $currassign;
6705: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
6706: $currassign = {
6707: selfassign => $domdefaults{'inststatusguest'},
6708: };
6709: @ordered = @{$domdefaults{'inststatusguest'}};
6710: } else {
6711: $currassign = { selfassign => [] };
6712: }
6713: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
6714: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
6715: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
6716: $numinrow,$othertitle,'selfassign',
6717: $rowtotal,$onclicktypes,$customclass,
6718: $rowstyle);
6719: $$rowtotal ++;
1.302 raeburn 6720: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 6721: foreach my $status (@posstypes) {
6722: my $css_class;
6723: if ($$rowtotal%2) {
6724: $css_class = 'LC_odd_row ';
6725: }
6726: $css_class .= $customclass;
6727: my $rowid = $optionsprefix.$status;
6728: my $hidden = 1;
6729: my $currstyle = 'display:none';
6730: if (grep(/^\Q$status\E$/,@ordered)) {
6731: $currstyle = $rowstyle;
6732: $hidden = 0;
6733: }
6734: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
6735: $emailrules,$emailruleorder,$settings,$status,$rowid,
6736: $usertypeshash{$status},$css_class,$currstyle,$intdom);
6737: unless ($hidden) {
6738: $$rowtotal ++;
6739: }
1.224 raeburn 6740: }
1.302 raeburn 6741: } else {
1.305 raeburn 6742: my $css_class;
6743: if ($$rowtotal%2) {
6744: $css_class = 'LC_odd_row ';
6745: }
6746: $css_class .= $customclass;
1.302 raeburn 6747: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 6748: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
6749: $emailrules,$emailruleorder,$settings,'default','',
6750: $othertitle,$css_class,$rowstyle,$intdom);
6751: $$rowtotal ++;
1.224 raeburn 6752: }
6753: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 6754: $numinrow = 1;
1.305 raeburn 6755: if (@posstypes) {
6756: foreach my $status (@posstypes) {
6757: my $rowid = $classprefix.$status;
6758: my $datarowstyle = 'display:none';
6759: if (grep(/^\Q$status\E$/,@ordered)) {
6760: $datarowstyle = $rowstyle;
6761: }
6762: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
6763: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
6764: $infotitles,$rowid,$customclass,$datarowstyle);
6765: unless ($datarowstyle eq 'display:none') {
6766: $$rowtotal ++;
6767: }
1.224 raeburn 6768: }
1.305 raeburn 6769: } else {
6770: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
6771: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
6772: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 6773: }
6774: }
6775: return $datatable;
6776: }
6777:
1.305 raeburn 6778: sub selfcreate_javascript {
6779: return <<"ENDSCRIPT";
6780:
6781: <script type="text/javascript">
6782: // <![CDATA[
6783:
6784: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
6785: var x = document.getElementsByClassName(target);
6786: var insttypes = 0;
6787: var insttypeRegExp = new RegExp(prefix);
6788: if ((x.length != undefined) && (x.length > 0)) {
6789: if (form.elements[radio].length != undefined) {
6790: for (var i=0; i<form.elements[radio].length; i++) {
6791: if (form.elements[radio][i].checked) {
6792: if (form.elements[radio][i].value == 1) {
6793: for (var j=0; j<x.length; j++) {
6794: if (x[j].id == 'undefined') {
6795: x[j].style.display = 'table-row';
6796: } else if (insttypeRegExp.test(x[j].id)) {
6797: insttypes ++;
6798: } else {
6799: x[j].style.display = 'table-row';
6800: }
6801: }
6802: } else {
6803: for (var j=0; j<x.length; j++) {
6804: x[j].style.display = 'none';
6805: }
1.236 raeburn 6806: }
1.305 raeburn 6807: break;
6808: }
6809: }
6810: if (insttypes > 0) {
6811: toggleDataRow(form,checkbox,target,altprefix);
6812: toggleDataRow(form,checkbox,target,prefix,1);
6813: }
6814: }
6815: }
6816: return;
6817: }
6818:
6819: function toggleDataRow(form,checkbox,target,prefix,docount) {
6820: if (form.elements[checkbox].length != undefined) {
6821: var count = 0;
6822: if (docount) {
6823: for (var i=0; i<form.elements[checkbox].length; i++) {
6824: if (form.elements[checkbox][i].checked) {
6825: count ++;
1.236 raeburn 6826: }
1.305 raeburn 6827: }
6828: }
6829: for (var i=0; i<form.elements[checkbox].length; i++) {
6830: var type = form.elements[checkbox][i].value;
6831: if (document.getElementById(prefix+type)) {
6832: if (form.elements[checkbox][i].checked) {
6833: document.getElementById(prefix+type).style.display = 'table-row';
6834: if (count % 2 == 1) {
6835: document.getElementById(prefix+type).className = target+' LC_odd_row';
6836: } else {
6837: document.getElementById(prefix+type).className = target;
1.236 raeburn 6838: }
1.305 raeburn 6839: count ++;
1.236 raeburn 6840: } else {
1.305 raeburn 6841: document.getElementById(prefix+type).style.display = 'none';
6842: }
6843: }
6844: }
6845: }
6846: return;
6847: }
6848:
6849: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
6850: var caller = radio+'_'+status;
6851: if (form.elements[caller].length != undefined) {
6852: for (var i=0; i<form.elements[caller].length; i++) {
6853: if (form.elements[caller][i].checked) {
6854: if (document.getElementById(altprefix+'_inst_'+status)) {
6855: var curr = form.elements[caller][i].value;
6856: if (prefix) {
6857: document.getElementById(prefix+'_'+status).style.display = 'none';
6858: }
6859: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
6860: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
6861: if (curr == 'custom') {
6862: if (prefix) {
6863: document.getElementById(prefix+'_'+status).style.display = 'inline';
6864: }
6865: } else if (curr == 'inst') {
6866: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
6867: } else if (curr == 'noninst') {
6868: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 6869: }
1.305 raeburn 6870: break;
1.236 raeburn 6871: }
6872: }
6873: }
6874: }
6875: }
6876:
1.305 raeburn 6877: // ]]>
6878: </script>
6879:
6880: ENDSCRIPT
6881: }
6882:
6883: sub noninst_users {
6884: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
6885: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
6886: my $class = 'LC_left_item';
6887: if ($css_class) {
6888: $css_class = ' class="'.$css_class.'"';
6889: }
6890: if ($rowid) {
6891: $rowid = ' id="'.$rowid.'"';
6892: }
6893: if ($rowstyle) {
6894: $rowstyle = ' style="'.$rowstyle.'"';
6895: }
6896: my ($output,$description);
6897: if ($type eq 'default') {
6898: $description = &mt('Requests for: [_1]',$typetitle);
6899: } else {
6900: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
6901: }
6902: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
6903: "<td>$description</td>\n".
6904: '<td class="'.$class.'" colspan="2">'.
6905: '<table><tr>';
6906: my %headers = &Apache::lonlocal::texthash(
6907: approve => 'Processing',
6908: email => 'E-mail',
6909: username => 'Username',
6910: );
6911: foreach my $item ('approve','email','username') {
6912: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 6913: }
1.305 raeburn 6914: $output .= '</tr><tr>';
6915: foreach my $item ('approve','email','username') {
1.306 raeburn 6916: $output .= '<td style="vertical-align: top">';
1.305 raeburn 6917: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
6918: if ($item eq 'approve') {
6919: %choices = &Apache::lonlocal::texthash (
6920: automatic => 'Automatically approved',
6921: approval => 'Queued for approval',
6922: );
6923: @options = ('automatic','approval');
6924: $hashref = $processing;
6925: $defoption = 'automatic';
6926: $name = 'cancreate_emailprocess_'.$type;
6927: } elsif ($item eq 'email') {
6928: %choices = &Apache::lonlocal::texthash (
6929: any => 'Any e-mail',
6930: inst => 'Institutional only',
6931: noninst => 'Non-institutional only',
6932: custom => 'Custom restrictions',
6933: );
6934: @options = ('any','inst','noninst');
6935: my $showcustom;
6936: if (ref($emailrules) eq 'HASH') {
6937: if (keys(%{$emailrules}) > 0) {
6938: push(@options,'custom');
6939: $showcustom = 'cancreate_emailrule';
6940: if (ref($settings) eq 'HASH') {
6941: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
6942: foreach my $rule (@{$settings->{'email_rule'}}) {
6943: if (exists($emailrules->{$rule})) {
6944: $hascustom ++;
6945: }
6946: }
6947: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
6948: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
6949: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
6950: if (exists($emailrules->{$rule})) {
6951: $hascustom ++;
6952: }
6953: }
6954: }
6955: }
6956: }
6957: }
6958: }
6959: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
6960: "'cancreate_emaildomain','$type'".');"';
6961: $hashref = $emailoptions;
6962: $defoption = 'any';
6963: $name = 'cancreate_emailoptions_'.$type;
6964: } elsif ($item eq 'username') {
6965: %choices = &Apache::lonlocal::texthash (
6966: all => 'Same as e-mail',
6967: first => 'Omit @domain',
6968: free => 'Free to choose',
6969: );
6970: @options = ('all','first','free');
6971: $hashref = $emailverified;
6972: $defoption = 'all';
6973: $name = 'cancreate_usernameoptions_'.$type;
6974: }
6975: foreach my $option (@options) {
6976: my $checked;
6977: if (ref($hashref) eq 'HASH') {
6978: if ($type eq '') {
6979: if (!exists($hashref->{'default'})) {
6980: if ($option eq $defoption) {
6981: $checked = ' checked="checked"';
6982: }
6983: } else {
6984: if ($hashref->{'default'} eq $option) {
6985: $checked = ' checked="checked"';
6986: }
1.303 raeburn 6987: }
6988: } else {
1.305 raeburn 6989: if (!exists($hashref->{$type})) {
6990: if ($option eq $defoption) {
6991: $checked = ' checked="checked"';
6992: }
6993: } else {
6994: if ($hashref->{$type} eq $option) {
6995: $checked = ' checked="checked"';
6996: }
1.303 raeburn 6997: }
6998: }
1.305 raeburn 6999: } elsif (($item eq 'email') && ($hascustom)) {
7000: if ($option eq 'custom') {
7001: $checked = ' checked="checked"';
7002: }
7003: } elsif ($option eq $defoption) {
7004: $checked = ' checked="checked"';
7005: }
7006: $output .= '<span class="LC_nobreak"><label>'.
7007: '<input type="radio" name="'.$name.'"'.
7008: $checked.' value="'.$option.'"'.$onclick.' />'.
7009: $choices{$option}.'</label></span><br />';
7010: if ($item eq 'email') {
7011: if ($option eq 'custom') {
7012: my $id = 'cancreate_emailrule_'.$type;
7013: my $display = 'none';
7014: if ($checked) {
7015: $display = 'inline';
1.303 raeburn 7016: }
1.305 raeburn 7017: my $numinrow = 2;
7018: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
7019: '<legend>'.&mt('Disallow').'</legend><table>'.
7020: &user_formats_row('email',$settings,$emailrules,
7021: $emailruleorder,$numinrow,'',$type);
7022: '</table></fieldset>';
7023: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
7024: my %text = &Apache::lonlocal::texthash (
7025: inst => 'must end:',
7026: noninst => 'cannot end:',
7027: );
7028: my $value;
7029: if (ref($emaildomain) eq 'HASH') {
7030: if (ref($emaildomain->{$type}) eq 'HASH') {
7031: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 7032: }
7033: }
1.305 raeburn 7034: if ($value eq '') {
7035: $value = '@'.$intdom;
7036: }
7037: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
7038: my $display = 'none';
7039: if ($checked) {
7040: $display = 'inline';
7041: }
7042: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
7043: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
7044: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
7045: '</div>';
1.303 raeburn 7046: }
7047: }
7048: }
1.305 raeburn 7049: $output .= '</td>'."\n";
1.303 raeburn 7050: }
1.305 raeburn 7051: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 7052: return $output;
7053: }
7054:
1.165 raeburn 7055: sub captcha_choice {
1.305 raeburn 7056: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 7057: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
7058: $vertext,$currver);
1.165 raeburn 7059: my %lt = &captcha_phrases();
7060: $keyentry = 'hidden';
7061: if ($context eq 'cancreate') {
1.224 raeburn 7062: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 7063: } elsif ($context eq 'login') {
7064: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 7065: }
7066: if (ref($settings) eq 'HASH') {
7067: if ($settings->{'captcha'}) {
7068: $checked{$settings->{'captcha'}} = ' checked="checked"';
7069: } else {
7070: $checked{'original'} = ' checked="checked"';
7071: }
7072: if ($settings->{'captcha'} eq 'recaptcha') {
7073: $pubtext = $lt{'pub'};
7074: $privtext = $lt{'priv'};
7075: $keyentry = 'text';
1.269 raeburn 7076: $vertext = $lt{'ver'};
7077: $currver = $settings->{'recaptchaversion'};
7078: if ($currver ne '2') {
7079: $currver = 1;
7080: }
1.165 raeburn 7081: }
7082: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
7083: $currpub = $settings->{'recaptchakeys'}{'public'};
7084: $currpriv = $settings->{'recaptchakeys'}{'private'};
7085: }
7086: } else {
7087: $checked{'original'} = ' checked="checked"';
7088: }
1.305 raeburn 7089: my $css_class;
7090: if ($itemcount%2) {
7091: $css_class = 'LC_odd_row';
7092: }
7093: if ($customcss) {
7094: $css_class .= " $customcss";
7095: }
7096: $css_class =~ s/^\s+//;
7097: if ($css_class) {
7098: $css_class = ' class="'.$css_class.'"';
7099: }
7100: if ($rowstyle) {
7101: $css_class .= ' style="'.$rowstyle.'"';
7102: }
1.169 raeburn 7103: my $output = '<tr'.$css_class.'>'.
7104: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 7105: '<table><tr><td>'."\n";
7106: foreach my $option ('original','recaptcha','notused') {
7107: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
7108: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
7109: $lt{$option}.'</label></span>';
7110: unless ($option eq 'notused') {
7111: $output .= (' 'x2)."\n";
7112: }
7113: }
7114: #
7115: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
7116: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 7117: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 7118: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 7119: #
1.165 raeburn 7120: $output .= '</td></tr>'."\n".
1.305 raeburn 7121: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 7122: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
7123: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
7124: $currpub.'" size="40" /></span><br />'."\n".
7125: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
7126: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 7127: $currpriv.'" size="40" /></span><br />'.
7128: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
7129: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
7130: $currver.'" size="3" /></span><br />'.
7131: '</td></tr></table>'."\n".
1.165 raeburn 7132: '</td></tr>';
7133: return $output;
7134: }
7135:
1.32 raeburn 7136: sub user_formats_row {
1.305 raeburn 7137: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 7138: my $output;
7139: my %text = (
7140: 'username' => 'new usernames',
7141: 'id' => 'IDs',
7142: );
1.305 raeburn 7143: unless ($type eq 'email') {
7144: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
7145: $output = '<tr '.$css_class.'>'.
7146: '<td><span class="LC_nobreak">'.
7147: &mt("Format rules to check for $text{$type}: ").
7148: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 7149: }
1.27 raeburn 7150: my $rem;
7151: if (ref($ruleorder) eq 'ARRAY') {
7152: for (my $i=0; $i<@{$ruleorder}; $i++) {
7153: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
7154: my $rem = $i%($numinrow);
7155: if ($rem == 0) {
7156: if ($i > 0) {
7157: $output .= '</tr>';
7158: }
7159: $output .= '<tr>';
7160: }
7161: my $check = ' ';
1.39 raeburn 7162: if (ref($settings) eq 'HASH') {
7163: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
7164: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
7165: $check = ' checked="checked" ';
7166: }
1.305 raeburn 7167: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
7168: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
7169: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
7170: $check = ' checked="checked" ';
7171: }
7172: }
1.27 raeburn 7173: }
7174: }
1.305 raeburn 7175: my $name = $type.'_rule';
7176: if ($type eq 'email') {
7177: $name .= '_'.$status;
7178: }
1.27 raeburn 7179: $output .= '<td class="LC_left_item">'.
7180: '<span class="LC_nobreak"><label>'.
1.311 raeburn 7181: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 7182: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
7183: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
7184: }
7185: }
7186: $rem = @{$ruleorder}%($numinrow);
7187: }
1.305 raeburn 7188: my $colsleft;
7189: if ($rem) {
7190: $colsleft = $numinrow - $rem;
7191: }
1.27 raeburn 7192: if ($colsleft > 1 ) {
7193: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7194: ' </td>';
7195: } elsif ($colsleft == 1) {
7196: $output .= '<td class="LC_left_item"> </td>';
7197: }
1.305 raeburn 7198: $output .= '</tr></table>';
7199: unless ($type eq 'email') {
7200: $output .= '</td></tr>';
7201: }
1.27 raeburn 7202: return $output;
7203: }
7204:
1.34 raeburn 7205: sub usercreation_types {
7206: my %lt = &Apache::lonlocal::texthash (
7207: author => 'When adding a co-author',
7208: course => 'When adding a user to a course',
1.100 raeburn 7209: requestcrs => 'When requesting a course',
1.34 raeburn 7210: any => 'Any',
7211: official => 'Institutional only ',
7212: unofficial => 'Non-institutional only',
7213: none => 'None',
7214: );
7215: return %lt;
1.48 raeburn 7216: }
1.34 raeburn 7217:
1.224 raeburn 7218: sub selfcreation_types {
7219: my %lt = &Apache::lonlocal::texthash (
7220: selfcreate => 'User creates own account',
7221: any => 'Any',
7222: official => 'Institutional only ',
7223: unofficial => 'Non-institutional only',
7224: email => 'E-mail address',
7225: login => 'Institutional Login',
7226: sso => 'SSO',
7227: );
7228: }
7229:
1.28 raeburn 7230: sub authtype_names {
7231: my %lt = &Apache::lonlocal::texthash(
7232: int => 'Internal',
7233: krb4 => 'Kerberos 4',
7234: krb5 => 'Kerberos 5',
7235: loc => 'Local',
7236: );
7237: return %lt;
7238: }
7239:
7240: sub context_names {
7241: my %context_title = &Apache::lonlocal::texthash(
7242: author => 'Creating users when an Author',
7243: course => 'Creating users when in a course',
7244: domain => 'Creating users when a Domain Coordinator',
7245: );
7246: return %context_title;
7247: }
7248:
1.33 raeburn 7249: sub print_usermodification {
7250: my ($position,$dom,$settings,$rowtotal) = @_;
7251: my $numinrow = 4;
7252: my ($context,$datatable,$rowcount);
7253: if ($position eq 'top') {
7254: $rowcount = 0;
7255: $context = 'author';
7256: foreach my $role ('ca','aa') {
7257: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7258: $numinrow,$rowcount);
7259: $$rowtotal ++;
7260: $rowcount ++;
7261: }
1.230 raeburn 7262: } elsif ($position eq 'bottom') {
1.33 raeburn 7263: $context = 'course';
7264: $rowcount = 0;
7265: foreach my $role ('st','ep','ta','in','cr') {
7266: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7267: $numinrow,$rowcount);
7268: $$rowtotal ++;
7269: $rowcount ++;
7270: }
7271: }
7272: return $datatable;
7273: }
7274:
1.43 raeburn 7275: sub print_defaults {
1.236 raeburn 7276: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 7277: my $rownum = 0;
1.294 raeburn 7278: my ($datatable,$css_class,$titles);
7279: unless ($position eq 'bottom') {
7280: $titles = &defaults_titles($dom);
7281: }
1.236 raeburn 7282: if ($position eq 'top') {
7283: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
7284: 'datelocale_def','portal_def');
7285: my %defaults;
7286: if (ref($settings) eq 'HASH') {
7287: %defaults = %{$settings};
1.43 raeburn 7288: } else {
1.236 raeburn 7289: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
7290: foreach my $item (@items) {
7291: $defaults{$item} = $domdefaults{$item};
7292: }
1.43 raeburn 7293: }
1.236 raeburn 7294: foreach my $item (@items) {
7295: if ($rownum%2) {
7296: $css_class = '';
7297: } else {
7298: $css_class = ' class="LC_odd_row" ';
7299: }
7300: $datatable .= '<tr'.$css_class.'>'.
7301: '<td><span class="LC_nobreak">'.$titles->{$item}.
7302: '</span></td><td class="LC_right_item" colspan="3">';
7303: if ($item eq 'auth_def') {
7304: my @authtypes = ('internal','krb4','krb5','localauth');
7305: my %shortauth = (
7306: internal => 'int',
7307: krb4 => 'krb4',
7308: krb5 => 'krb5',
7309: localauth => 'loc'
7310: );
7311: my %authnames = &authtype_names();
7312: foreach my $auth (@authtypes) {
7313: my $checked = ' ';
7314: if ($defaults{$item} eq $auth) {
7315: $checked = ' checked="checked" ';
7316: }
7317: $datatable .= '<label><input type="radio" name="'.$item.
7318: '" value="'.$auth.'"'.$checked.'/>'.
7319: $authnames{$shortauth{$auth}}.'</label> ';
7320: }
7321: } elsif ($item eq 'timezone_def') {
7322: my $includeempty = 1;
7323: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
7324: } elsif ($item eq 'datelocale_def') {
7325: my $includeempty = 1;
7326: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
7327: } elsif ($item eq 'lang_def') {
1.263 raeburn 7328: my $includeempty = 1;
7329: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 7330: } else {
7331: my $size;
7332: if ($item eq 'portal_def') {
7333: $size = ' size="25"';
7334: }
7335: $datatable .= '<input type="text" name="'.$item.'" value="'.
7336: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 7337: }
1.236 raeburn 7338: $datatable .= '</td></tr>';
7339: $rownum ++;
7340: }
1.294 raeburn 7341: } elsif ($position eq 'middle') {
7342: my @items = ('intauth_cost','intauth_check','intauth_switch');
7343: my %defaults;
7344: if (ref($settings) eq 'HASH') {
7345: %defaults = %{$settings};
7346: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
7347: $defaults{'intauth_cost'} = 10;
7348: }
7349: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
7350: $defaults{'intauth_check'} = 0;
7351: }
7352: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
7353: $defaults{'intauth_switch'} = 0;
7354: }
7355: } else {
7356: %defaults = (
7357: 'intauth_cost' => 10,
7358: 'intauth_check' => 0,
7359: 'intauth_switch' => 0,
7360: );
7361: }
7362: foreach my $item (@items) {
7363: if ($rownum%2) {
7364: $css_class = '';
7365: } else {
7366: $css_class = ' class="LC_odd_row" ';
7367: }
7368: $datatable .= '<tr'.$css_class.'>'.
7369: '<td><span class="LC_nobreak">'.$titles->{$item}.
7370: '</span></td><td class="LC_left_item" colspan="3">';
7371: if ($item eq 'intauth_switch') {
7372: my @options = (0,1,2);
7373: my %optiondesc = &Apache::lonlocal::texthash (
7374: 0 => 'No',
7375: 1 => 'Yes',
7376: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
7377: );
7378: $datatable .= '<table width="100%">';
7379: foreach my $option (@options) {
7380: my $checked = ' ';
7381: if ($defaults{$item} eq $option) {
7382: $checked = ' checked="checked"';
7383: }
7384: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7385: '<label><input type="radio" name="'.$item.
7386: '" value="'.$option.'"'.$checked.' />'.
7387: $optiondesc{$option}.'</label></span></td></tr>';
7388: }
7389: $datatable .= '</table>';
7390: } elsif ($item eq 'intauth_check') {
7391: my @options = (0,1,2);
7392: my %optiondesc = &Apache::lonlocal::texthash (
7393: 0 => 'No',
7394: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
7395: 2 => 'Yes, disallow login if stored cost is less than domain default',
7396: );
7397: $datatable .= '<table wisth="100%">';
7398: foreach my $option (@options) {
7399: my $checked = ' ';
7400: my $onclick;
7401: if ($defaults{$item} eq $option) {
7402: $checked = ' checked="checked"';
7403: }
7404: if ($option == 2) {
7405: $onclick = ' onclick="javascript:warnIntAuth(this);"';
7406: }
7407: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7408: '<label><input type="radio" name="'.$item.
7409: '" value="'.$option.'"'.$checked.$onclick.' />'.
7410: $optiondesc{$option}.'</label></span></td></tr>';
7411: }
7412: $datatable .= '</table>';
7413: } else {
7414: $datatable .= '<input type="text" name="'.$item.'" value="'.
7415: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
7416: }
7417: $datatable .= '</td></tr>';
7418: $rownum ++;
7419: }
1.236 raeburn 7420: } else {
1.294 raeburn 7421: my %defaults;
1.236 raeburn 7422: if (ref($settings) eq 'HASH') {
1.305 raeburn 7423: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.236 raeburn 7424: my $maxnum = @{$settings->{'inststatusorder'}};
7425: for (my $i=0; $i<$maxnum; $i++) {
7426: $css_class = $rownum%2?' class="LC_odd_row"':'';
7427: my $item = $settings->{'inststatusorder'}->[$i];
7428: my $title = $settings->{'inststatustypes'}->{$item};
7429: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
7430: $datatable .= '<tr'.$css_class.'>'.
7431: '<td><span class="LC_nobreak">'.
7432: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
7433: for (my $k=0; $k<=$maxnum; $k++) {
7434: my $vpos = $k+1;
7435: my $selstr;
7436: if ($k == $i) {
7437: $selstr = ' selected="selected" ';
7438: }
7439: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7440: }
7441: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
7442: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
7443: &mt('delete').'</span></td>'.
1.305 raeburn 7444: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed:').
1.236 raeburn 7445: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.305 raeburn 7446: '</span></td></tr>';
1.236 raeburn 7447: }
7448: $css_class = $rownum%2?' class="LC_odd_row"':'';
7449: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
7450: $datatable .= '<tr '.$css_class.'>'.
7451: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
7452: for (my $k=0; $k<=$maxnum; $k++) {
7453: my $vpos = $k+1;
7454: my $selstr;
7455: if ($k == $maxnum) {
7456: $selstr = ' selected="selected" ';
7457: }
7458: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7459: }
7460: $datatable .= '</select> '.&mt('Internal ID:').
1.263 raeburn 7461: '<input type="text" size="10" name="addinststatus" value="" />'.
1.236 raeburn 7462: ' '.&mt('(new)').
1.305 raeburn 7463: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.236 raeburn 7464: &mt('Name displayed:').
7465: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
7466: '</tr>'."\n";
7467: $rownum ++;
1.141 raeburn 7468: }
1.43 raeburn 7469: }
7470: }
7471: $$rowtotal += $rownum;
7472: return $datatable;
7473: }
7474:
1.168 raeburn 7475: sub get_languages_hash {
7476: my %langchoices;
7477: foreach my $id (&Apache::loncommon::languageids()) {
7478: my $code = &Apache::loncommon::supportedlanguagecode($id);
7479: if ($code ne '') {
7480: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
7481: }
7482: }
7483: return %langchoices;
7484: }
7485:
1.43 raeburn 7486: sub defaults_titles {
1.141 raeburn 7487: my ($dom) = @_;
1.43 raeburn 7488: my %titles = &Apache::lonlocal::texthash (
7489: 'auth_def' => 'Default authentication type',
7490: 'auth_arg_def' => 'Default authentication argument',
7491: 'lang_def' => 'Default language',
1.54 raeburn 7492: 'timezone_def' => 'Default timezone',
1.68 raeburn 7493: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 7494: 'portal_def' => 'Portal/Default URL',
1.294 raeburn 7495: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
7496: 'intauth_check' => 'Check bcrypt cost if authenticated',
7497: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 7498: );
1.141 raeburn 7499: if ($dom) {
7500: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
7501: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
7502: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
7503: $protocol = 'http' if ($protocol ne 'https');
7504: if ($uint_dom) {
7505: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
7506: $uint_dom);
7507: }
7508: }
1.43 raeburn 7509: return (\%titles);
7510: }
7511:
1.46 raeburn 7512: sub print_scantronformat {
7513: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
7514: my $itemcount = 1;
1.60 raeburn 7515: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
7516: %confhash);
1.46 raeburn 7517: my $switchserver = &check_switchserver($dom,$confname);
7518: my %lt = &Apache::lonlocal::texthash (
1.95 www 7519: default => 'Default bubblesheet format file error',
7520: custom => 'Custom bubblesheet format file error',
1.46 raeburn 7521: );
7522: my %scantronfiles = (
7523: default => 'default.tab',
7524: custom => 'custom.tab',
7525: );
7526: foreach my $key (keys(%scantronfiles)) {
7527: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
7528: .$scantronfiles{$key};
7529: }
7530: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
7531: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
7532: if (!$switchserver) {
7533: my $servadm = $r->dir_config('lonAdmEMail');
7534: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
7535: if ($configuserok eq 'ok') {
7536: if ($author_ok eq 'ok') {
7537: my %legacyfile = (
7538: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
7539: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
7540: );
7541: my %md5chk;
7542: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 7543: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
7544: chomp($md5chk{$type});
1.46 raeburn 7545: }
7546: if ($md5chk{'default'} ne $md5chk{'custom'}) {
7547: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 7548: ($scantronurls{$type},my $error) =
1.46 raeburn 7549: &legacy_scantronformat($r,$dom,$confname,
7550: $type,$legacyfile{$type},
7551: $scantronurls{$type},
7552: $scantronfiles{$type});
1.60 raeburn 7553: if ($error ne '') {
7554: $error{$type} = $error;
7555: }
7556: }
7557: if (keys(%error) == 0) {
7558: $is_custom = 1;
7559: $confhash{'scantron'}{'scantronformat'} =
7560: $scantronurls{'custom'};
7561: my $putresult =
7562: &Apache::lonnet::put_dom('configuration',
7563: \%confhash,$dom);
7564: if ($putresult ne 'ok') {
7565: $error{'custom'} =
7566: '<span class="LC_error">'.
7567: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7568: }
1.46 raeburn 7569: }
7570: } else {
1.60 raeburn 7571: ($scantronurls{'default'},my $error) =
1.46 raeburn 7572: &legacy_scantronformat($r,$dom,$confname,
7573: 'default',$legacyfile{'default'},
7574: $scantronurls{'default'},
7575: $scantronfiles{'default'});
1.60 raeburn 7576: if ($error eq '') {
7577: $confhash{'scantron'}{'scantronformat'} = '';
7578: my $putresult =
7579: &Apache::lonnet::put_dom('configuration',
7580: \%confhash,$dom);
7581: if ($putresult ne 'ok') {
7582: $error{'default'} =
7583: '<span class="LC_error">'.
7584: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7585: }
7586: } else {
7587: $error{'default'} = $error;
7588: }
1.46 raeburn 7589: }
7590: }
7591: }
7592: } else {
1.95 www 7593: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 7594: }
7595: }
7596: if (ref($settings) eq 'HASH') {
7597: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
7598: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
7599: if ((!@info) || ($info[0] eq 'no_such_dir')) {
7600: $scantronurl = '';
7601: } else {
7602: $scantronurl = $settings->{'scantronformat'};
7603: }
7604: $is_custom = 1;
7605: } else {
7606: $scantronurl = $scantronurls{'default'};
7607: }
7608: } else {
1.60 raeburn 7609: if ($is_custom) {
7610: $scantronurl = $scantronurls{'custom'};
7611: } else {
7612: $scantronurl = $scantronurls{'default'};
7613: }
1.46 raeburn 7614: }
7615: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7616: $datatable .= '<tr'.$css_class.'>';
7617: if (!$is_custom) {
1.65 raeburn 7618: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
7619: '<span class="LC_nobreak">';
1.46 raeburn 7620: if ($scantronurl) {
1.199 raeburn 7621: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
7622: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 7623: } else {
7624: $datatable = &mt('File unavailable for display');
7625: }
1.65 raeburn 7626: $datatable .= '</span></td>';
1.60 raeburn 7627: if (keys(%error) == 0) {
1.306 raeburn 7628: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 7629: if (!$switchserver) {
7630: $datatable .= &mt('Upload:').'<br />';
7631: }
7632: } else {
7633: my $errorstr;
7634: foreach my $key (sort(keys(%error))) {
7635: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7636: }
7637: $datatable .= '<td>'.$errorstr;
7638: }
1.46 raeburn 7639: } else {
7640: if (keys(%error) > 0) {
7641: my $errorstr;
7642: foreach my $key (sort(keys(%error))) {
7643: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7644: }
1.60 raeburn 7645: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 7646: } elsif ($scantronurl) {
1.199 raeburn 7647: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
7648: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 7649: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 7650: $link.
7651: '<label><input type="checkbox" name="scantronformat_del"'.
7652: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 7653: '<td><span class="LC_nobreak"> '.
7654: &mt('Replace:').'</span><br />';
1.46 raeburn 7655: }
7656: }
7657: if (keys(%error) == 0) {
7658: if ($switchserver) {
7659: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
7660: } else {
1.65 raeburn 7661: $datatable .='<span class="LC_nobreak"> '.
7662: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 7663: }
7664: }
7665: $datatable .= '</td></tr>';
7666: $$rowtotal ++;
7667: return $datatable;
7668: }
7669:
7670: sub legacy_scantronformat {
7671: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
7672: my ($url,$error);
7673: my @statinfo = &Apache::lonnet::stat_file($newurl);
7674: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
7675: (my $result,$url) =
7676: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
7677: '','',$newfile);
7678: if ($result ne 'ok') {
1.130 raeburn 7679: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 7680: }
7681: }
7682: return ($url,$error);
7683: }
1.43 raeburn 7684:
1.49 raeburn 7685: sub print_coursecategories {
1.57 raeburn 7686: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
7687: my $datatable;
7688: if ($position eq 'top') {
1.238 raeburn 7689: my (%checked);
7690: my @catitems = ('unauth','auth');
7691: my @cattypes = ('std','domonly','codesrch','none');
7692: $checked{'unauth'} = 'std';
7693: $checked{'auth'} = 'std';
7694: if (ref($settings) eq 'HASH') {
7695: foreach my $type (@cattypes) {
7696: if ($type eq $settings->{'unauth'}) {
7697: $checked{'unauth'} = $type;
7698: }
7699: if ($type eq $settings->{'auth'}) {
7700: $checked{'auth'} = $type;
7701: }
7702: }
7703: }
7704: my %lt = &Apache::lonlocal::texthash (
7705: unauth => 'Catalog type for unauthenticated users',
7706: auth => 'Catalog type for authenticated users',
7707: none => 'No catalog',
7708: std => 'Standard catalog',
7709: domonly => 'Domain-only catalog',
7710: codesrch => "Code search form",
7711: );
7712: my $itemcount = 0;
7713: foreach my $item (@catitems) {
7714: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
7715: $datatable .= '<tr '.$css_class.'>'.
7716: '<td>'.$lt{$item}.'</td>'.
7717: '<td class="LC_right_item"><span class="LC_nobreak">';
7718: foreach my $type (@cattypes) {
7719: my $ischecked;
7720: if ($checked{$item} eq $type) {
7721: $ischecked=' checked="checked"';
7722: }
7723: $datatable .= '<label>'.
7724: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
7725: ' />'.$lt{$type}.'</label> ';
7726: }
7727: $datatable .= '</td></tr>';
7728: $itemcount ++;
7729: }
7730: $$rowtotal += $itemcount;
7731: } elsif ($position eq 'middle') {
1.57 raeburn 7732: my $toggle_cats_crs = ' ';
7733: my $toggle_cats_dom = ' checked="checked" ';
7734: my $can_cat_crs = ' ';
7735: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 7736: my $toggle_catscomm_comm = ' ';
7737: my $toggle_catscomm_dom = ' checked="checked" ';
7738: my $can_catcomm_comm = ' ';
7739: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 7740: my $toggle_catsplace_place = ' ';
7741: my $toggle_catsplace_dom = ' checked="checked" ';
7742: my $can_catplace_place = ' ';
7743: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 7744:
1.57 raeburn 7745: if (ref($settings) eq 'HASH') {
7746: if ($settings->{'togglecats'} eq 'crs') {
7747: $toggle_cats_crs = $toggle_cats_dom;
7748: $toggle_cats_dom = ' ';
7749: }
7750: if ($settings->{'categorize'} eq 'crs') {
7751: $can_cat_crs = $can_cat_dom;
7752: $can_cat_dom = ' ';
7753: }
1.120 raeburn 7754: if ($settings->{'togglecatscomm'} eq 'comm') {
7755: $toggle_catscomm_comm = $toggle_catscomm_dom;
7756: $toggle_catscomm_dom = ' ';
7757: }
7758: if ($settings->{'categorizecomm'} eq 'comm') {
7759: $can_catcomm_comm = $can_catcomm_dom;
7760: $can_catcomm_dom = ' ';
7761: }
1.272 raeburn 7762: if ($settings->{'togglecatsplace'} eq 'place') {
7763: $toggle_catsplace_place = $toggle_catsplace_dom;
7764: $toggle_catsplace_dom = ' ';
7765: }
7766: if ($settings->{'categorizeplace'} eq 'place') {
7767: $can_catplace_place = $can_catplace_dom;
7768: $can_catplace_dom = ' ';
7769: }
1.57 raeburn 7770: }
7771: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 7772: togglecats => 'Show/Hide a course in catalog',
7773: togglecatscomm => 'Show/Hide a community in catalog',
7774: togglecatsplace => 'Show/Hide a placement test in catalog',
7775: categorize => 'Assign a category to a course',
7776: categorizecomm => 'Assign a category to a community',
7777: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 7778: );
7779: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 7780: dom => 'Set in Domain',
7781: crs => 'Set in Course',
7782: comm => 'Set in Community',
7783: place => 'Set in Placement Test',
1.57 raeburn 7784: );
7785: $datatable = '<tr class="LC_odd_row">'.
7786: '<td>'.$title{'togglecats'}.'</td>'.
7787: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7788: '<input type="radio" name="togglecats"'.
7789: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7790: '<label><input type="radio" name="togglecats"'.
7791: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
7792: '</tr><tr>'.
7793: '<td>'.$title{'categorize'}.'</td>'.
7794: '<td class="LC_right_item"><span class="LC_nobreak">'.
7795: '<label><input type="radio" name="categorize"'.
7796: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7797: '<label><input type="radio" name="categorize"'.
7798: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 7799: '</tr><tr class="LC_odd_row">'.
7800: '<td>'.$title{'togglecatscomm'}.'</td>'.
7801: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7802: '<input type="radio" name="togglecatscomm"'.
7803: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7804: '<label><input type="radio" name="togglecatscomm"'.
7805: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
7806: '</tr><tr>'.
7807: '<td>'.$title{'categorizecomm'}.'</td>'.
7808: '<td class="LC_right_item"><span class="LC_nobreak">'.
7809: '<label><input type="radio" name="categorizecomm"'.
7810: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7811: '<label><input type="radio" name="categorizecomm"'.
7812: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.272 raeburn 7813: '</tr><tr>'.
7814: '<td>'.$title{'togglecatsplace'}.'</td>'.
7815: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7816: '<input type="radio" name="togglecatsplace"'.
7817: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7818: '<label><input type="radio" name="togglecatscomm"'.
7819: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
7820: '</tr><tr>'.
7821: '<td>'.$title{'categorizeplace'}.'</td>'.
7822: '<td class="LC_right_item"><span class="LC_nobreak">'.
7823: '<label><input type="radio" name="categorizeplace"'.
7824: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7825: '<label><input type="radio" name="categorizeplace"'.
7826: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 7827: '</tr>';
1.272 raeburn 7828: $$rowtotal += 6;
1.57 raeburn 7829: } else {
7830: my $css_class;
7831: my $itemcount = 1;
7832: my $cathash;
7833: if (ref($settings) eq 'HASH') {
7834: $cathash = $settings->{'cats'};
7835: }
7836: if (ref($cathash) eq 'HASH') {
7837: my (@cats,@trails,%allitems,%idx,@jsarray);
7838: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
7839: \%allitems,\%idx,\@jsarray);
7840: my $maxdepth = scalar(@cats);
7841: my $colattrib = '';
7842: if ($maxdepth > 2) {
7843: $colattrib = ' colspan="2" ';
7844: }
7845: my @path;
7846: if (@cats > 0) {
7847: if (ref($cats[0]) eq 'ARRAY') {
7848: my $numtop = @{$cats[0]};
7849: my $maxnum = $numtop;
1.120 raeburn 7850: my %default_names = (
7851: instcode => &mt('Official courses'),
7852: communities => &mt('Communities'),
1.272 raeburn 7853: placement => &mt('Placement Tests'),
1.120 raeburn 7854: );
7855:
7856: if ((!grep(/^instcode$/,@{$cats[0]})) ||
7857: ($cathash->{'instcode::0'} eq '') ||
7858: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 7859: ($cathash->{'communities::0'} eq '') ||
7860: (!grep(/^placement$/,@{$cats[0]})) ||
7861: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 7862: $maxnum ++;
7863: }
7864: my $lastidx;
7865: for (my $i=0; $i<$numtop; $i++) {
7866: my $parent = $cats[0][$i];
7867: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7868: my $item = &escape($parent).'::0';
7869: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
7870: $lastidx = $idx{$item};
7871: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
7872: .'<select name="'.$item.'"'.$chgstr.'>';
7873: for (my $k=0; $k<=$maxnum; $k++) {
7874: my $vpos = $k+1;
7875: my $selstr;
7876: if ($k == $i) {
7877: $selstr = ' selected="selected" ';
7878: }
7879: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7880: }
1.214 raeburn 7881: $datatable .= '</select></span></td><td>';
1.272 raeburn 7882: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 7883: $datatable .= '<span class="LC_nobreak">'
7884: .$default_names{$parent}.'</span>';
7885: if ($parent eq 'instcode') {
7886: $datatable .= '<br /><span class="LC_nobreak">('
7887: .&mt('with institutional codes')
7888: .')</span></td><td'.$colattrib.'>';
7889: } else {
7890: $datatable .= '<table><tr><td>';
7891: }
7892: $datatable .= '<span class="LC_nobreak">'
7893: .'<label><input type="radio" name="'
7894: .$parent.'" value="1" checked="checked" />'
7895: .&mt('Display').'</label>';
7896: if ($parent eq 'instcode') {
7897: $datatable .= ' ';
7898: } else {
7899: $datatable .= '</span></td></tr><tr><td>'
7900: .'<span class="LC_nobreak">';
7901: }
7902: $datatable .= '<label><input type="radio" name="'
7903: .$parent.'" value="0" />'
7904: .&mt('Do not display').'</label></span>';
1.272 raeburn 7905: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 7906: $datatable .= '</td></tr></table>';
7907: }
7908: $datatable .= '</td>';
1.57 raeburn 7909: } else {
7910: $datatable .= $parent
1.214 raeburn 7911: .' <span class="LC_nobreak"><label>'
7912: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 7913: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
7914: }
7915: my $depth = 1;
7916: push(@path,$parent);
7917: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
7918: pop(@path);
7919: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
7920: $itemcount ++;
7921: }
1.48 raeburn 7922: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 7923: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
7924: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 7925: for (my $k=0; $k<=$maxnum; $k++) {
7926: my $vpos = $k+1;
7927: my $selstr;
1.57 raeburn 7928: if ($k == $numtop) {
1.48 raeburn 7929: $selstr = ' selected="selected" ';
7930: }
7931: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7932: }
1.59 bisitz 7933: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 7934: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
7935: .'</tr>'."\n";
1.48 raeburn 7936: $itemcount ++;
1.272 raeburn 7937: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 7938: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
7939: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7940: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
7941: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
7942: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
7943: for (my $k=0; $k<=$maxnum; $k++) {
7944: my $vpos = $k+1;
7945: my $selstr;
7946: if ($k == $maxnum) {
7947: $selstr = ' selected="selected" ';
7948: }
7949: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 7950: }
1.120 raeburn 7951: $datatable .= '</select></span></td>'.
7952: '<td><span class="LC_nobreak">'.
7953: $default_names{$default}.'</span>';
7954: if ($default eq 'instcode') {
7955: $datatable .= '<br /><span class="LC_nobreak">('
7956: .&mt('with institutional codes').')</span>';
7957: }
7958: $datatable .= '</td>'
7959: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
7960: .&mt('Display').'</label> '
7961: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
7962: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 7963: }
7964: }
7965: }
1.57 raeburn 7966: } else {
7967: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 7968: }
7969: } else {
1.238 raeburn 7970: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 7971: .&initialize_categories($itemcount);
1.48 raeburn 7972: }
1.57 raeburn 7973: $$rowtotal += $itemcount;
1.48 raeburn 7974: }
7975: return $datatable;
7976: }
7977:
1.69 raeburn 7978: sub print_serverstatuses {
7979: my ($dom,$settings,$rowtotal) = @_;
7980: my $datatable;
7981: my @pages = &serverstatus_pages();
7982: my (%namedaccess,%machineaccess);
7983: foreach my $type (@pages) {
7984: $namedaccess{$type} = '';
7985: $machineaccess{$type}= '';
7986: }
7987: if (ref($settings) eq 'HASH') {
7988: foreach my $type (@pages) {
7989: if (exists($settings->{$type})) {
7990: if (ref($settings->{$type}) eq 'HASH') {
7991: foreach my $key (keys(%{$settings->{$type}})) {
7992: if ($key eq 'namedusers') {
7993: $namedaccess{$type} = $settings->{$type}->{$key};
7994: } elsif ($key eq 'machines') {
7995: $machineaccess{$type} = $settings->{$type}->{$key};
7996: }
7997: }
7998: }
7999: }
8000: }
8001: }
1.81 raeburn 8002: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 8003: my $rownum = 0;
8004: my $css_class;
8005: foreach my $type (@pages) {
8006: $rownum ++;
8007: $css_class = $rownum%2?' class="LC_odd_row"':'';
8008: $datatable .= '<tr'.$css_class.'>'.
8009: '<td><span class="LC_nobreak">'.
8010: $titles->{$type}.'</span></td>'.
8011: '<td class="LC_left_item">'.
8012: '<input type="text" name="'.$type.'_namedusers" '.
8013: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
8014: '<td class="LC_right_item">'.
8015: '<span class="LC_nobreak">'.
8016: '<input type="text" name="'.$type.'_machines" '.
8017: 'value="'.$machineaccess{$type}.'" size="10" />'.
8018: '</td></tr>'."\n";
8019: }
8020: $$rowtotal += $rownum;
8021: return $datatable;
8022: }
8023:
8024: sub serverstatus_pages {
8025: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 8026: 'checksums','clusterstatus','certstatus','metadata_keywords',
8027: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
8028: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 8029: }
8030:
1.236 raeburn 8031: sub defaults_javascript {
8032: my ($settings) = @_;
1.294 raeburn 8033: 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.');
8034: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
8035: &js_escape(\$intauthcheck);
8036: &js_escape(\$intauthcost);
8037: my $intauthjs = <<"ENDSCRIPT";
8038:
8039: function warnIntAuth(field) {
8040: if (field.name == 'intauth_check') {
8041: if (field.value == '2') {
8042: alert('$intauthcheck');
8043: }
8044: }
8045: if (field.name == 'intauth_cost') {
8046: field.value.replace(/\s/g,'');
8047: if (field.value != '') {
8048: var regexdigit=/^\\d+\$/;
8049: if (!regexdigit.test(field.value)) {
8050: alert('$intauthcost');
8051: }
8052: }
8053: }
8054: return;
8055: }
8056:
8057: ENDSCRIPT
8058:
8059: if (ref($settings) ne 'HASH') {
8060: return &Apache::lonhtmlcommon::scripttag($intauthjs);
8061: }
1.236 raeburn 8062: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
8063: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
8064: if ($maxnum eq '') {
8065: $maxnum = 0;
8066: }
8067: $maxnum ++;
1.249 raeburn 8068: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 8069: return <<"ENDSCRIPT";
8070: <script type="text/javascript">
8071: // <![CDATA[
8072: function reorderTypes(form,caller) {
8073: var changedVal;
8074: $jstext
8075: var newpos = 'addinststatus_pos';
8076: var current = new Array;
8077: var maxh = $maxnum;
8078: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8079: var oldVal;
8080: if (caller == newpos) {
8081: changedVal = newitemVal;
8082: } else {
8083: var curritem = 'inststatus_pos_'+caller;
8084: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
8085: current[newitemVal] = newpos;
8086: }
8087: for (var i=0; i<inststatuses.length; i++) {
8088: if (inststatuses[i] != caller) {
8089: var elementName = 'inststatus_pos_'+inststatuses[i];
8090: if (form.elements[elementName]) {
8091: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8092: current[currVal] = elementName;
8093: }
8094: }
8095: }
8096: for (var j=0; j<maxh; j++) {
8097: if (current[j] == undefined) {
8098: oldVal = j;
8099: }
8100: }
8101: if (oldVal < changedVal) {
8102: for (var k=oldVal+1; k<=changedVal ; k++) {
8103: var elementName = current[k];
8104: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8105: }
8106: } else {
8107: for (var k=changedVal; k<oldVal; k++) {
8108: var elementName = current[k];
8109: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8110: }
8111: }
8112: return;
8113: }
8114:
1.294 raeburn 8115: $intauthjs
8116:
1.236 raeburn 8117: // ]]>
8118: </script>
8119:
8120: ENDSCRIPT
1.294 raeburn 8121: } else {
8122: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 8123: }
8124: }
8125:
1.49 raeburn 8126: sub coursecategories_javascript {
8127: my ($settings) = @_;
1.57 raeburn 8128: my ($output,$jstext,$cathash);
1.49 raeburn 8129: if (ref($settings) eq 'HASH') {
1.57 raeburn 8130: $cathash = $settings->{'cats'};
8131: }
8132: if (ref($cathash) eq 'HASH') {
1.49 raeburn 8133: my (@cats,@jsarray,%idx);
1.57 raeburn 8134: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 8135: if (@jsarray > 0) {
8136: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
8137: for (my $i=0; $i<@jsarray; $i++) {
8138: if (ref($jsarray[$i]) eq 'ARRAY') {
8139: my $catstr = join('","',@{$jsarray[$i]});
8140: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
8141: }
8142: }
8143: }
8144: } else {
8145: $jstext = ' var categories = Array(1);'."\n".
8146: ' categories[0] = Array("instcode_pos");'."\n";
8147: }
1.237 bisitz 8148: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
8149: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 8150: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 8151: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
8152: &js_escape(\$instcode_reserved);
8153: &js_escape(\$communities_reserved);
1.272 raeburn 8154: &js_escape(\$placement_reserved);
1.265 damieng 8155: &js_escape(\$choose_again);
1.49 raeburn 8156: $output = <<"ENDSCRIPT";
8157: <script type="text/javascript">
1.109 raeburn 8158: // <![CDATA[
1.49 raeburn 8159: function reorderCats(form,parent,item,idx) {
8160: var changedVal;
8161: $jstext
8162: var newpos = 'addcategory_pos';
8163: if (parent == '') {
8164: var has_instcode = 0;
8165: var maxtop = categories[idx].length;
8166: for (var j=0; j<maxtop; j++) {
8167: if (categories[idx][j] == 'instcode::0') {
8168: has_instcode == 1;
8169: }
8170: }
8171: if (has_instcode == 0) {
8172: categories[idx][maxtop] = 'instcode_pos';
8173: }
8174: } else {
8175: newpos += '_'+parent;
8176: }
8177: var maxh = 1 + categories[idx].length;
8178: var current = new Array;
8179: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8180: if (item == newpos) {
8181: changedVal = newitemVal;
8182: } else {
8183: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
8184: current[newitemVal] = newpos;
8185: }
8186: for (var i=0; i<categories[idx].length; i++) {
8187: var elementName = categories[idx][i];
8188: if (elementName != item) {
8189: if (form.elements[elementName]) {
8190: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8191: current[currVal] = elementName;
8192: }
8193: }
8194: }
8195: var oldVal;
8196: for (var j=0; j<maxh; j++) {
8197: if (current[j] == undefined) {
8198: oldVal = j;
8199: }
8200: }
8201: if (oldVal < changedVal) {
8202: for (var k=oldVal+1; k<=changedVal ; k++) {
8203: var elementName = current[k];
8204: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8205: }
8206: } else {
8207: for (var k=changedVal; k<oldVal; k++) {
8208: var elementName = current[k];
8209: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8210: }
8211: }
8212: return;
8213: }
1.120 raeburn 8214:
8215: function categoryCheck(form) {
8216: if (form.elements['addcategory_name'].value == 'instcode') {
8217: alert('$instcode_reserved\\n$choose_again');
8218: return false;
8219: }
8220: if (form.elements['addcategory_name'].value == 'communities') {
8221: alert('$communities_reserved\\n$choose_again');
8222: return false;
8223: }
1.272 raeburn 8224: if (form.elements['addcategory_name'].value == 'placement') {
8225: alert('$placement_reserved\\n$choose_again');
8226: return false;
8227: }
1.120 raeburn 8228: return true;
8229: }
8230:
1.109 raeburn 8231: // ]]>
1.49 raeburn 8232: </script>
8233:
8234: ENDSCRIPT
8235: return $output;
8236: }
8237:
1.48 raeburn 8238: sub initialize_categories {
8239: my ($itemcount) = @_;
1.120 raeburn 8240: my ($datatable,$css_class,$chgstr);
8241: my %default_names = (
8242: instcode => 'Official courses (with institutional codes)',
8243: communities => 'Communities',
1.272 raeburn 8244: placement => 'Placement Tests',
1.120 raeburn 8245: );
8246: my $select0 = ' selected="selected"';
8247: my $select1 = '';
1.272 raeburn 8248: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 8249: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8250: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
1.272 raeburn 8251: if (($default eq 'communities') || ($default eq 'placement')) {
1.120 raeburn 8252: $select1 = $select0;
8253: $select0 = '';
8254: }
8255: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
8256: .'<select name="'.$default.'_pos">'
8257: .'<option value="0"'.$select0.'>1</option>'
8258: .'<option value="1"'.$select1.'>2</option>'
8259: .'<option value="2">3</option></select> '
8260: .$default_names{$default}
8261: .'</span></td><td><span class="LC_nobreak">'
8262: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
8263: .&mt('Display').'</label> <label>'
8264: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 8265: .'</label></span></td></tr>';
1.120 raeburn 8266: $itemcount ++;
8267: }
1.48 raeburn 8268: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 8269: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 8270: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 8271: .'<select name="addcategory_pos"'.$chgstr.'>'
8272: .'<option value="0">1</option>'
8273: .'<option value="1">2</option>'
8274: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 8275: .&mt('Add category').'</td><td>'.&mt('Name:')
8276: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
8277: return $datatable;
8278: }
8279:
8280: sub build_category_rows {
1.49 raeburn 8281: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
8282: my ($text,$name,$item,$chgstr);
1.48 raeburn 8283: if (ref($cats) eq 'ARRAY') {
8284: my $maxdepth = scalar(@{$cats});
8285: if (ref($cats->[$depth]) eq 'HASH') {
8286: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
8287: my $numchildren = @{$cats->[$depth]{$parent}};
8288: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 8289: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 8290: my ($idxnum,$parent_name,$parent_item);
8291: my $higher = $depth - 1;
8292: if ($higher == 0) {
8293: $parent_name = &escape($parent).'::'.$higher;
8294: } else {
8295: if (ref($path) eq 'ARRAY') {
8296: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8297: }
8298: }
8299: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 8300: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 8301: if ($j < $numchildren) {
1.48 raeburn 8302: $name = $cats->[$depth]{$parent}[$j];
8303: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 8304: $idxnum = $idx->{$item};
8305: } else {
8306: $name = $parent_name;
8307: $item = $parent_item;
1.48 raeburn 8308: }
1.49 raeburn 8309: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
8310: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 8311: for (my $i=0; $i<=$numchildren; $i++) {
8312: my $vpos = $i+1;
8313: my $selstr;
8314: if ($j == $i) {
8315: $selstr = ' selected="selected" ';
8316: }
8317: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
8318: }
8319: $text .= '</select> ';
8320: if ($j < $numchildren) {
8321: my $deeper = $depth+1;
8322: $text .= $name.' '
8323: .'<label><input type="checkbox" name="deletecategory" value="'
8324: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
8325: if(ref($path) eq 'ARRAY') {
8326: push(@{$path},$name);
1.49 raeburn 8327: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 8328: pop(@{$path});
8329: }
8330: } else {
1.59 bisitz 8331: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 8332: if ($j == $numchildren) {
8333: $text .= $name;
8334: } else {
8335: $text .= $item;
8336: }
8337: $text .= '" value="" />';
8338: }
8339: $text .= '</td></tr>';
8340: }
8341: $text .= '</table></td>';
8342: } else {
8343: my $higher = $depth-1;
8344: if ($higher == 0) {
8345: $name = &escape($parent).'::'.$higher;
8346: } else {
8347: if (ref($path) eq 'ARRAY') {
8348: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8349: }
8350: }
8351: my $colspan;
8352: if ($parent ne 'instcode') {
8353: $colspan = $maxdepth - $depth - 1;
8354: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
8355: }
8356: }
8357: }
8358: }
8359: return $text;
8360: }
8361:
1.33 raeburn 8362: sub modifiable_userdata_row {
1.305 raeburn 8363: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
8364: $rowid,$customcss,$rowstyle) = @_;
1.228 raeburn 8365: my ($role,$rolename,$statustype);
8366: $role = $item;
1.224 raeburn 8367: if ($context eq 'cancreate') {
1.305 raeburn 8368: if ($item =~ /^(emailusername)_(.+)$/) {
8369: $role = $1;
8370: $statustype = $2;
1.228 raeburn 8371: if (ref($usertypes) eq 'HASH') {
8372: if ($usertypes->{$statustype}) {
8373: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
8374: } else {
8375: $rolename = &mt('Data provided by user');
8376: }
8377: }
1.224 raeburn 8378: }
8379: } elsif ($context eq 'selfcreate') {
1.63 raeburn 8380: if (ref($usertypes) eq 'HASH') {
8381: $rolename = $usertypes->{$role};
8382: } else {
8383: $rolename = $role;
8384: }
1.33 raeburn 8385: } else {
1.63 raeburn 8386: if ($role eq 'cr') {
8387: $rolename = &mt('Custom role');
8388: } else {
8389: $rolename = &Apache::lonnet::plaintext($role);
8390: }
1.33 raeburn 8391: }
1.224 raeburn 8392: my (@fields,%fieldtitles);
8393: if (ref($fieldsref) eq 'ARRAY') {
8394: @fields = @{$fieldsref};
8395: } else {
8396: @fields = ('lastname','firstname','middlename','generation',
8397: 'permanentemail','id');
8398: }
8399: if ((ref($titlesref) eq 'HASH')) {
8400: %fieldtitles = %{$titlesref};
8401: } else {
8402: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8403: }
1.33 raeburn 8404: my $output;
1.305 raeburn 8405: my $css_class;
8406: if ($rowcount%2) {
8407: $css_class = 'LC_odd_row';
8408: }
8409: if ($customcss) {
8410: $css_class .= " $customcss";
8411: }
8412: $css_class =~ s/^\s+//;
8413: if ($css_class) {
8414: $css_class = ' class="'.$css_class.'"';
8415: }
8416: if ($rowstyle) {
8417: $css_class .= ' style="'.$rowstyle.'"';
8418: }
8419: if ($rowid) {
8420: $rowid = ' id="'.$rowid.'"';
8421: }
8422: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 8423: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
8424: '<td class="LC_left_item" colspan="2"><table>';
8425: my $rem;
8426: my %checks;
8427: if (ref($settings) eq 'HASH') {
8428: if (ref($settings->{$context}) eq 'HASH') {
8429: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228 raeburn 8430: my $hashref = $settings->{$context}->{$role};
8431: if ($role eq 'emailusername') {
8432: if ($statustype) {
8433: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
8434: $hashref = $settings->{$context}->{$role}->{$statustype};
8435: if (ref($hashref) eq 'HASH') {
8436: foreach my $field (@fields) {
8437: if ($hashref->{$field}) {
8438: $checks{$field} = $hashref->{$field};
8439: }
8440: }
8441: }
8442: }
8443: }
8444: } else {
8445: if (ref($hashref) eq 'HASH') {
8446: foreach my $field (@fields) {
8447: if ($hashref->{$field}) {
8448: $checks{$field} = ' checked="checked" ';
8449: }
8450: }
1.33 raeburn 8451: }
8452: }
8453: }
8454: }
8455: }
1.305 raeburn 8456:
8457: my $total = scalar(@fields);
8458: for (my $i=0; $i<$total; $i++) {
8459: $rem = $i%($numinrow);
1.33 raeburn 8460: if ($rem == 0) {
8461: if ($i > 0) {
8462: $output .= '</tr>';
8463: }
8464: $output .= '<tr>';
8465: }
8466: my $check = ' ';
1.228 raeburn 8467: unless ($role eq 'emailusername') {
8468: if (exists($checks{$fields[$i]})) {
8469: $check = $checks{$fields[$i]}
8470: } else {
8471: if ($role eq 'st') {
8472: if (ref($settings) ne 'HASH') {
8473: $check = ' checked="checked" ';
8474: }
1.33 raeburn 8475: }
8476: }
8477: }
8478: $output .= '<td class="LC_left_item">'.
1.228 raeburn 8479: '<span class="LC_nobreak">';
8480: if ($role eq 'emailusername') {
8481: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
8482: $checks{$fields[$i]} = 'omit';
8483: }
8484: foreach my $option ('required','optional','omit') {
8485: my $checked='';
8486: if ($checks{$fields[$i]} eq $option) {
8487: $checked='checked="checked" ';
8488: }
8489: $output .= '<label>'.
8490: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
8491: &mt($option).'</label>'.(' ' x2);
8492: }
8493: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
8494: } else {
8495: $output .= '<label>'.
8496: '<input type="checkbox" name="canmodify_'.$role.'" '.
8497: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
8498: '</label>';
8499: }
8500: $output .= '</span></td>';
1.33 raeburn 8501: }
1.305 raeburn 8502: $rem = $total%$numinrow;
8503: my $colsleft;
8504: if ($rem) {
8505: $colsleft = $numinrow - $rem;
8506: }
8507: if ($colsleft > 1) {
1.33 raeburn 8508: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8509: ' </td>';
8510: } elsif ($colsleft == 1) {
8511: $output .= '<td class="LC_left_item"> </td>';
8512: }
8513: $output .= '</tr></table></td></tr>';
8514: return $output;
8515: }
1.28 raeburn 8516:
1.93 raeburn 8517: sub insttypes_row {
1.305 raeburn 8518: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
8519: $customcss,$rowstyle) = @_;
1.93 raeburn 8520: my %lt = &Apache::lonlocal::texthash (
8521: cansearch => 'Users allowed to search',
8522: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 8523: lockablenames => 'User preference to lock name',
1.305 raeburn 8524: selfassign => 'Self-reportable affiliations',
1.315 raeburn 8525: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 8526: );
8527: my $showdom;
8528: if ($context eq 'cansearch') {
8529: $showdom = ' ('.$dom.')';
8530: }
1.165 raeburn 8531: my $class = 'LC_left_item';
8532: if ($context eq 'statustocreate') {
8533: $class = 'LC_right_item';
8534: }
1.305 raeburn 8535: my $css_class;
8536: if ($$rowtotal%2) {
8537: $css_class = 'LC_odd_row';
8538: }
8539: if ($customcss) {
8540: $css_class .= ' '.$customcss;
8541: }
8542: $css_class =~ s/^\s+//;
8543: if ($css_class) {
8544: $css_class = ' class="'.$css_class.'"';
8545: }
8546: if ($rowstyle) {
8547: $css_class .= ' style="'.$rowstyle.'"';
8548: }
8549: if ($onclick) {
8550: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 8551: }
8552: my $output = '<tr'.$css_class.'>'.
8553: '<td>'.$lt{$context}.$showdom.
8554: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 8555: my $rem;
8556: if (ref($types) eq 'ARRAY') {
8557: for (my $i=0; $i<@{$types}; $i++) {
8558: if (defined($usertypes->{$types->[$i]})) {
8559: my $rem = $i%($numinrow);
8560: if ($rem == 0) {
8561: if ($i > 0) {
8562: $output .= '</tr>';
8563: }
8564: $output .= '<tr>';
1.23 raeburn 8565: }
1.26 raeburn 8566: my $check = ' ';
1.99 raeburn 8567: if (ref($settings) eq 'HASH') {
8568: if (ref($settings->{$context}) eq 'ARRAY') {
8569: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
8570: $check = ' checked="checked" ';
8571: }
1.315 raeburn 8572: } elsif (ref($settings->{$context}) eq 'HASH') {
8573: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
8574: $check = ' checked="checked" ';
8575: }
1.99 raeburn 8576: } elsif ($context eq 'statustocreate') {
1.26 raeburn 8577: $check = ' checked="checked" ';
8578: }
1.23 raeburn 8579: }
1.26 raeburn 8580: $output .= '<td class="LC_left_item">'.
8581: '<span class="LC_nobreak"><label>'.
1.93 raeburn 8582: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 8583: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 8584: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 8585: }
8586: }
1.26 raeburn 8587: $rem = @{$types}%($numinrow);
1.23 raeburn 8588: }
8589: my $colsleft = $numinrow - $rem;
1.315 raeburn 8590: if ($context eq 'overrides') {
8591: if ($colsleft > 1) {
8592: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8593: } else {
8594: $output .= '<td class="LC_left_item">';
8595: }
8596: $output .= ' ';
1.23 raeburn 8597: } else {
1.315 raeburn 8598: if (($rem == 0) && (@{$types} > 0)) {
8599: $output .= '<tr>';
8600: }
8601: if ($colsleft > 1) {
8602: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8603: } else {
8604: $output .= '<td class="LC_left_item">';
8605: }
8606: my $defcheck = ' ';
8607: if (ref($settings) eq 'HASH') {
8608: if (ref($settings->{$context}) eq 'ARRAY') {
8609: if (grep(/^default$/,@{$settings->{$context}})) {
8610: $defcheck = ' checked="checked" ';
8611: }
8612: } elsif ($context eq 'statustocreate') {
1.99 raeburn 8613: $defcheck = ' checked="checked" ';
8614: }
1.26 raeburn 8615: }
1.315 raeburn 8616: $output .= '<span class="LC_nobreak"><label>'.
8617: '<input type="checkbox" name="'.$context.'" '.
8618: 'value="default"'.$defcheck.$onclick.' />'.
8619: $othertitle.'</label></span>';
1.23 raeburn 8620: }
1.315 raeburn 8621: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 8622: return $output;
1.23 raeburn 8623: }
8624:
8625: sub sorted_searchtitles {
8626: my %searchtitles = &Apache::lonlocal::texthash(
8627: 'uname' => 'username',
8628: 'lastname' => 'last name',
8629: 'lastfirst' => 'last name, first name',
8630: );
8631: my @titleorder = ('uname','lastname','lastfirst');
8632: return (\%searchtitles,\@titleorder);
8633: }
8634:
1.25 raeburn 8635: sub sorted_searchtypes {
8636: my %srchtypes_desc = (
8637: exact => 'is exact match',
8638: contains => 'contains ..',
8639: begins => 'begins with ..',
8640: );
8641: my @srchtypeorder = ('exact','begins','contains');
8642: return (\%srchtypes_desc,\@srchtypeorder);
8643: }
8644:
1.3 raeburn 8645: sub usertype_update_row {
8646: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
8647: my $datatable;
8648: my $numinrow = 4;
8649: foreach my $type (@{$types}) {
8650: if (defined($usertypes->{$type})) {
8651: $$rownums ++;
8652: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
8653: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
8654: '</td><td class="LC_left_item"><table>';
8655: for (my $i=0; $i<@{$fields}; $i++) {
8656: my $rem = $i%($numinrow);
8657: if ($rem == 0) {
8658: if ($i > 0) {
8659: $datatable .= '</tr>';
8660: }
8661: $datatable .= '<tr>';
8662: }
8663: my $check = ' ';
1.39 raeburn 8664: if (ref($settings) eq 'HASH') {
8665: if (ref($settings->{'fields'}) eq 'HASH') {
8666: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
8667: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
8668: $check = ' checked="checked" ';
8669: }
1.3 raeburn 8670: }
8671: }
8672: }
8673:
8674: if ($i == @{$fields}-1) {
8675: my $colsleft = $numinrow - $rem;
8676: if ($colsleft > 1) {
8677: $datatable .= '<td colspan="'.$colsleft.'">';
8678: } else {
8679: $datatable .= '<td>';
8680: }
8681: } else {
8682: $datatable .= '<td>';
8683: }
1.8 raeburn 8684: $datatable .= '<span class="LC_nobreak"><label>'.
8685: '<input type="checkbox" name="updateable_'.$type.
8686: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
8687: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 8688: }
8689: $datatable .= '</tr></table></td></tr>';
8690: }
8691: }
8692: return $datatable;
1.1 raeburn 8693: }
8694:
8695: sub modify_login {
1.205 raeburn 8696: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 8697: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
8698: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
8699: %title = ( coursecatalog => 'Display course catalog',
8700: adminmail => 'Display administrator E-mail address',
1.188 raeburn 8701: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 8702: newuser => 'Link for visitors to create a user account',
8703: loginheader => 'Log-in box header');
8704: @offon = ('off','on');
1.112 raeburn 8705: if (ref($domconfig{login}) eq 'HASH') {
8706: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
8707: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
8708: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
8709: }
8710: }
8711: }
1.9 raeburn 8712: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
8713: \%domconfig,\%loginhash);
1.188 raeburn 8714: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 8715: foreach my $item (@toggles) {
8716: $loginhash{login}{$item} = $env{'form.'.$item};
8717: }
1.41 raeburn 8718: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 8719: if (ref($colchanges{'login'}) eq 'HASH') {
8720: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
8721: \%loginhash);
8722: }
1.110 raeburn 8723:
1.149 raeburn 8724: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 8725: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 8726: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 8727: if (keys(%servers) > 1) {
8728: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 8729: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
8730: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
8731: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
8732: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
8733: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
8734: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8735: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
8736: $changes{'loginvia'}{$lonhost} = 1;
8737: } else {
8738: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
8739: $changes{'loginvia'}{$lonhost} = 1;
8740: }
8741: } else {
8742: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8743: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
8744: $changes{'loginvia'}{$lonhost} = 1;
8745: }
8746: }
8747: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
8748: foreach my $item (@loginvia_attribs) {
8749: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
8750: }
8751: } else {
8752: foreach my $item (@loginvia_attribs) {
8753: my $new = $env{'form.'.$lonhost.'_'.$item};
8754: if (($item eq 'serverpath') && ($new eq 'custom')) {
8755: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
8756: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
8757: $new = '/';
8758: }
8759: }
8760: if (($item eq 'custompath') &&
8761: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
8762: $new = '';
8763: }
8764: if ($new ne $curr_loginvia{$lonhost}{$item}) {
8765: $changes{'loginvia'}{$lonhost} = 1;
8766: }
8767: if ($item eq 'exempt') {
1.256 raeburn 8768: $new = &check_exempt_addresses($new);
1.128 raeburn 8769: }
8770: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
8771: }
8772: }
1.112 raeburn 8773: } else {
1.128 raeburn 8774: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8775: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 8776: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 8777: foreach my $item (@loginvia_attribs) {
8778: my $new = $env{'form.'.$lonhost.'_'.$item};
8779: if (($item eq 'serverpath') && ($new eq 'custom')) {
8780: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
8781: $new = '/';
8782: }
8783: }
8784: if (($item eq 'custompath') &&
8785: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
8786: $new = '';
8787: }
8788: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
8789: }
1.110 raeburn 8790: }
8791: }
8792: }
8793: }
1.119 raeburn 8794:
1.168 raeburn 8795: my $servadm = $r->dir_config('lonAdmEMail');
8796: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
8797: if (ref($domconfig{'login'}) eq 'HASH') {
8798: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
8799: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
8800: if ($lang eq 'nolang') {
8801: push(@currlangs,$lang);
8802: } elsif (defined($langchoices{$lang})) {
8803: push(@currlangs,$lang);
8804: } else {
8805: next;
8806: }
8807: }
8808: }
8809: }
8810: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
8811: if (@currlangs > 0) {
8812: foreach my $lang (@currlangs) {
8813: if (grep(/^\Q$lang\E$/,@delurls)) {
8814: $changes{'helpurl'}{$lang} = 1;
8815: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
8816: $changes{'helpurl'}{$lang} = 1;
8817: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
8818: push(@newlangs,$lang);
8819: } else {
8820: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
8821: }
8822: }
8823: }
8824: unless (grep(/^nolang$/,@currlangs)) {
8825: if ($env{'form.loginhelpurl_nolang.filename'}) {
8826: $changes{'helpurl'}{'nolang'} = 1;
8827: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
8828: push(@newlangs,'nolang');
8829: }
8830: }
8831: if ($env{'form.loginhelpurl_add_lang'}) {
8832: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
8833: ($env{'form.loginhelpurl_add_file.filename'})) {
8834: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
8835: $addedfile = $env{'form.loginhelpurl_add_lang'};
8836: }
8837: }
8838: if ((@newlangs > 0) || ($addedfile)) {
8839: my $error;
8840: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8841: if ($configuserok eq 'ok') {
8842: if ($switchserver) {
8843: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
8844: } elsif ($author_ok eq 'ok') {
8845: my @allnew = @newlangs;
8846: if ($addedfile ne '') {
8847: push(@allnew,$addedfile);
8848: }
8849: foreach my $lang (@allnew) {
8850: my $formelem = 'loginhelpurl_'.$lang;
8851: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
8852: $formelem = 'loginhelpurl_add_file';
8853: }
8854: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
8855: "help/$lang",'','',$newfile{$lang});
8856: if ($result eq 'ok') {
8857: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
8858: $changes{'helpurl'}{$lang} = 1;
8859: } else {
8860: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
8861: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 8862: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 8863: (!grep(/^\Q$lang\E$/,@delurls))) {
8864: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
8865: }
8866: }
8867: }
8868: } else {
8869: $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);
8870: }
8871: } else {
8872: $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);
8873: }
8874: if ($error) {
8875: &Apache::lonnet::logthis($error);
8876: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8877: }
8878: }
1.256 raeburn 8879:
8880: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
8881: if (ref($domconfig{'login'}) eq 'HASH') {
8882: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
8883: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
8884: if ($domservers{$lonhost}) {
8885: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
8886: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 8887: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 8888: }
8889: }
8890: }
8891: }
8892: }
8893: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
8894: foreach my $lonhost (sort(keys(%domservers))) {
8895: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
8896: $changes{'headtag'}{$lonhost} = 1;
8897: } else {
8898: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
8899: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
8900: }
8901: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
8902: push(@newhosts,$lonhost);
8903: } elsif ($currheadtagurls{$lonhost}) {
8904: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
8905: if ($currexempt{$lonhost}) {
1.289 raeburn 8906: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 8907: $changes{'headtag'}{$lonhost} = 1;
8908: }
8909: } elsif ($possexempt{$lonhost}) {
8910: $changes{'headtag'}{$lonhost} = 1;
8911: }
8912: if ($possexempt{$lonhost}) {
8913: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
8914: }
8915: }
8916: }
8917: }
8918: if (@newhosts) {
8919: my $error;
8920: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8921: if ($configuserok eq 'ok') {
8922: if ($switchserver) {
8923: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
8924: } elsif ($author_ok eq 'ok') {
8925: foreach my $lonhost (@newhosts) {
8926: my $formelem = 'loginheadtag_'.$lonhost;
8927: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
8928: "login/headtag/$lonhost",'','',
8929: $env{'form.loginheadtag_'.$lonhost.'.filename'});
8930: if ($result eq 'ok') {
8931: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
8932: $changes{'headtag'}{$lonhost} = 1;
8933: if ($possexempt{$lonhost}) {
8934: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
8935: }
8936: } else {
8937: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
8938: $newheadtagurls{$lonhost},$result);
8939: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
8940: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
8941: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
8942: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
8943: }
8944: }
8945: }
8946: } else {
8947: $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);
8948: }
8949: } else {
8950: $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);
8951: }
8952: if ($error) {
8953: &Apache::lonnet::logthis($error);
8954: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8955: }
8956: }
1.169 raeburn 8957: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 8958:
8959: my $defaulthelpfile = '/adm/loginproblems.html';
8960: my $defaulttext = &mt('Default in use');
8961:
1.1 raeburn 8962: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
8963: $dom);
8964: if ($putresult eq 'ok') {
1.188 raeburn 8965: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 8966: my %defaultchecked = (
8967: 'coursecatalog' => 'on',
1.188 raeburn 8968: 'helpdesk' => 'on',
1.42 raeburn 8969: 'adminmail' => 'off',
1.43 raeburn 8970: 'newuser' => 'off',
1.42 raeburn 8971: );
1.55 raeburn 8972: if (ref($domconfig{'login'}) eq 'HASH') {
8973: foreach my $item (@toggles) {
8974: if ($defaultchecked{$item} eq 'on') {
8975: if (($domconfig{'login'}{$item} eq '0') &&
8976: ($env{'form.'.$item} eq '1')) {
8977: $changes{$item} = 1;
8978: } elsif (($domconfig{'login'}{$item} eq '' ||
8979: $domconfig{'login'}{$item} eq '1') &&
8980: ($env{'form.'.$item} eq '0')) {
8981: $changes{$item} = 1;
8982: }
8983: } elsif ($defaultchecked{$item} eq 'off') {
8984: if (($domconfig{'login'}{$item} eq '1') &&
8985: ($env{'form.'.$item} eq '0')) {
8986: $changes{$item} = 1;
8987: } elsif (($domconfig{'login'}{$item} eq '' ||
8988: $domconfig{'login'}{$item} eq '0') &&
8989: ($env{'form.'.$item} eq '1')) {
8990: $changes{$item} = 1;
8991: }
1.42 raeburn 8992: }
8993: }
1.41 raeburn 8994: }
1.6 raeburn 8995: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 8996: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 8997: if (ref($lastactref) eq 'HASH') {
8998: $lastactref->{'domainconfig'} = 1;
8999: }
1.1 raeburn 9000: $resulttext = &mt('Changes made:').'<ul>';
9001: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 9002: if ($item eq 'loginvia') {
1.112 raeburn 9003: if (ref($changes{$item}) eq 'HASH') {
9004: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
9005: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 9006: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
9007: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
9008: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
9009: $protocol = 'http' if ($protocol ne 'https');
9010: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
9011:
9012: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
9013: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
9014: } else {
9015: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
9016: }
9017: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
9018: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
9019: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
9020: }
9021: $resulttext .= '</li>';
9022: } else {
9023: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
9024: }
1.112 raeburn 9025: } else {
1.128 raeburn 9026: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 9027: }
9028: }
1.128 raeburn 9029: $resulttext .= '</ul></li>';
1.112 raeburn 9030: }
1.168 raeburn 9031: } elsif ($item eq 'helpurl') {
9032: if (ref($changes{$item}) eq 'HASH') {
9033: foreach my $lang (sort(keys(%{$changes{$item}}))) {
9034: if (grep(/^\Q$lang\E$/,@delurls)) {
9035: my ($chg,$link);
9036: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
9037: if ($lang eq 'nolang') {
9038: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
9039: } else {
9040: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
9041: }
9042: $resulttext .= '<li>'.$chg.'</li>';
9043: } else {
9044: my $chg;
9045: if ($lang eq 'nolang') {
9046: $chg = &mt('custom log-in help file for no preferred language');
9047: } else {
9048: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
9049: }
9050: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
9051: $loginhash{'login'}{'helpurl'}{$lang}.
9052: '?inhibitmenu=yes',$chg,600,500).
9053: '</li>';
9054: }
9055: }
9056: }
1.256 raeburn 9057: } elsif ($item eq 'headtag') {
9058: if (ref($changes{$item}) eq 'HASH') {
9059: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
9060: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9061: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
9062: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9063: $resulttext .= '<li><a href="'.
9064: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
9065: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
9066: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
9067: if ($possexempt{$lonhost}) {
9068: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
9069: } else {
9070: $resulttext .= &mt('included for any client IP');
9071: }
9072: $resulttext .= '</li>';
9073: }
9074: }
9075: }
1.169 raeburn 9076: } elsif ($item eq 'captcha') {
9077: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 9078: my $chgtxt;
1.169 raeburn 9079: if ($loginhash{'login'}{$item} eq 'notused') {
9080: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
9081: } else {
9082: my %captchas = &captcha_phrases();
9083: if ($captchas{$loginhash{'login'}{$item}}) {
9084: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
9085: } else {
9086: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
9087: }
9088: }
9089: $resulttext .= '<li>'.$chgtxt.'</li>';
9090: }
9091: } elsif ($item eq 'recaptchakeys') {
9092: if (ref($loginhash{'login'}) eq 'HASH') {
9093: my ($privkey,$pubkey);
9094: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
9095: $pubkey = $loginhash{'login'}{$item}{'public'};
9096: $privkey = $loginhash{'login'}{$item}{'private'};
9097: }
9098: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
9099: if (!$pubkey) {
9100: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
9101: } else {
9102: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
9103: }
9104: if (!$privkey) {
9105: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
9106: } else {
1.251 raeburn 9107: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 9108: }
9109: $chgtxt .= '</ul>';
9110: $resulttext .= '<li>'.$chgtxt.'</li>';
9111: }
1.269 raeburn 9112: } elsif ($item eq 'recaptchaversion') {
9113: if (ref($loginhash{'login'}) eq 'HASH') {
9114: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 9115: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 9116: '</li>';
9117: }
9118: }
1.41 raeburn 9119: } else {
9120: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
9121: }
1.1 raeburn 9122: }
1.6 raeburn 9123: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 9124: } else {
9125: $resulttext = &mt('No changes made to log-in page settings');
9126: }
9127: } else {
1.11 albertel 9128: $resulttext = '<span class="LC_error">'.
9129: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9130: }
1.6 raeburn 9131: if ($errors) {
1.9 raeburn 9132: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 9133: $errors.'</ul>';
9134: }
9135: return $resulttext;
9136: }
9137:
1.256 raeburn 9138: sub check_exempt_addresses {
9139: my ($iplist) = @_;
9140: $iplist =~ s/^\s+//;
9141: $iplist =~ s/\s+$//;
9142: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
9143: my (@okips,$new);
9144: foreach my $ip (@poss_ips) {
9145: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
9146: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
9147: push(@okips,$ip);
9148: }
9149: }
9150: }
9151: if (@okips > 0) {
9152: $new = join(',',@okips);
9153: } else {
9154: $new = '';
9155: }
9156: return $new;
9157: }
9158:
1.6 raeburn 9159: sub color_font_choices {
9160: my %choices =
9161: &Apache::lonlocal::texthash (
9162: img => "Header",
9163: bgs => "Background colors",
9164: links => "Link colors",
1.55 raeburn 9165: images => "Images",
1.6 raeburn 9166: font => "Font color",
1.201 raeburn 9167: fontmenu => "Font menu",
1.76 raeburn 9168: pgbg => "Page",
1.6 raeburn 9169: tabbg => "Header",
9170: sidebg => "Border",
9171: link => "Link",
9172: alink => "Active link",
9173: vlink => "Visited link",
9174: );
9175: return %choices;
9176: }
9177:
9178: sub modify_rolecolors {
1.205 raeburn 9179: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 9180: my ($resulttext,%rolehash);
9181: $rolehash{'rolecolors'} = {};
1.55 raeburn 9182: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
9183: if ($domconfig{'rolecolors'} eq '') {
9184: $domconfig{'rolecolors'} = {};
9185: }
9186: }
1.9 raeburn 9187: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 9188: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
9189: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
9190: $dom);
9191: if ($putresult eq 'ok') {
9192: if (keys(%changes) > 0) {
1.41 raeburn 9193: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9194: if (ref($lastactref) eq 'HASH') {
9195: $lastactref->{'domainconfig'} = 1;
9196: }
1.6 raeburn 9197: $resulttext = &display_colorchgs($dom,\%changes,$roles,
9198: $rolehash{'rolecolors'});
9199: } else {
9200: $resulttext = &mt('No changes made to default color schemes');
9201: }
9202: } else {
1.11 albertel 9203: $resulttext = '<span class="LC_error">'.
9204: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 9205: }
9206: if ($errors) {
9207: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9208: $errors.'</ul>';
9209: }
9210: return $resulttext;
9211: }
9212:
9213: sub modify_colors {
1.9 raeburn 9214: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 9215: my (%changes,%choices);
1.51 raeburn 9216: my @bgs;
1.6 raeburn 9217: my @links = ('link','alink','vlink');
1.41 raeburn 9218: my @logintext;
1.6 raeburn 9219: my @images;
9220: my $servadm = $r->dir_config('lonAdmEMail');
9221: my $errors;
1.200 raeburn 9222: my %defaults;
1.6 raeburn 9223: foreach my $role (@{$roles}) {
9224: if ($role eq 'login') {
1.12 raeburn 9225: %choices = &login_choices();
1.41 raeburn 9226: @logintext = ('textcol','bgcol');
1.12 raeburn 9227: } else {
9228: %choices = &color_font_choices();
9229: }
9230: if ($role eq 'login') {
1.41 raeburn 9231: @images = ('img','logo','domlogo','login');
1.51 raeburn 9232: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 9233: } else {
9234: @images = ('img');
1.200 raeburn 9235: @bgs = ('pgbg','tabbg','sidebg');
9236: }
9237: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
9238: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
9239: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
9240: }
9241: if ($role eq 'login') {
9242: foreach my $item (@logintext) {
1.234 raeburn 9243: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9244: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9245: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9246: }
9247: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 9248: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9249: }
9250: }
9251: } else {
1.234 raeburn 9252: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
9253: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
9254: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
9255: }
9256: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 9257: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
9258: }
1.6 raeburn 9259: }
1.200 raeburn 9260: foreach my $item (@bgs) {
1.234 raeburn 9261: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9262: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9263: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9264: }
9265: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 9266: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9267: }
9268: }
9269: foreach my $item (@links) {
1.234 raeburn 9270: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9271: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9272: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9273: }
9274: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 9275: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9276: }
1.6 raeburn 9277: }
1.46 raeburn 9278: my ($configuserok,$author_ok,$switchserver) =
9279: &config_check($dom,$confname,$servadm);
1.9 raeburn 9280: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 9281: if (ref($domconfig->{$role}) ne 'HASH') {
9282: $domconfig->{$role} = {};
9283: }
1.8 raeburn 9284: foreach my $img (@images) {
1.70 raeburn 9285: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
9286: if (defined($env{'form.login_showlogo_'.$img})) {
9287: $confhash->{$role}{'showlogo'}{$img} = 1;
9288: } else {
9289: $confhash->{$role}{'showlogo'}{$img} = 0;
9290: }
9291: }
1.18 albertel 9292: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
9293: && !defined($domconfig->{$role}{$img})
9294: && !$env{'form.'.$role.'_del_'.$img}
9295: && $env{'form.'.$role.'_import_'.$img}) {
9296: # import the old configured image from the .tab setting
9297: # if they haven't provided a new one
9298: $domconfig->{$role}{$img} =
9299: $env{'form.'.$role.'_import_'.$img};
9300: }
1.6 raeburn 9301: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 9302: my $error;
1.6 raeburn 9303: if ($configuserok eq 'ok') {
1.9 raeburn 9304: if ($switchserver) {
1.12 raeburn 9305: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 9306: } else {
9307: if ($author_ok eq 'ok') {
9308: my ($result,$logourl) =
9309: &publishlogo($r,'upload',$role.'_'.$img,
9310: $dom,$confname,$img,$width,$height);
9311: if ($result eq 'ok') {
9312: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 9313: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 9314: } else {
1.12 raeburn 9315: $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 9316: }
9317: } else {
1.46 raeburn 9318: $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 9319: }
9320: }
9321: } else {
1.46 raeburn 9322: $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 9323: }
9324: if ($error) {
1.8 raeburn 9325: &Apache::lonnet::logthis($error);
1.11 albertel 9326: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 9327: }
9328: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 9329: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
9330: my $error;
9331: if ($configuserok eq 'ok') {
9332: # is confname an author?
9333: if ($switchserver eq '') {
9334: if ($author_ok eq 'ok') {
9335: my ($result,$logourl) =
9336: &publishlogo($r,'copy',$domconfig->{$role}{$img},
9337: $dom,$confname,$img,$width,$height);
9338: if ($result eq 'ok') {
9339: $confhash->{$role}{$img} = $logourl;
1.18 albertel 9340: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 9341: }
9342: }
9343: }
9344: }
1.6 raeburn 9345: }
9346: }
9347: }
9348: if (ref($domconfig) eq 'HASH') {
9349: if (ref($domconfig->{$role}) eq 'HASH') {
9350: foreach my $img (@images) {
9351: if ($domconfig->{$role}{$img} ne '') {
9352: if ($env{'form.'.$role.'_del_'.$img}) {
9353: $confhash->{$role}{$img} = '';
1.12 raeburn 9354: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 9355: } else {
1.9 raeburn 9356: if ($confhash->{$role}{$img} eq '') {
9357: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
9358: }
1.6 raeburn 9359: }
9360: } else {
9361: if ($env{'form.'.$role.'_del_'.$img}) {
9362: $confhash->{$role}{$img} = '';
1.12 raeburn 9363: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 9364: }
9365: }
1.70 raeburn 9366: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
9367: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
9368: if ($confhash->{$role}{'showlogo'}{$img} ne
9369: $domconfig->{$role}{'showlogo'}{$img}) {
9370: $changes{$role}{'showlogo'}{$img} = 1;
9371: }
9372: } else {
9373: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
9374: $changes{$role}{'showlogo'}{$img} = 1;
9375: }
9376: }
9377: }
9378: }
1.6 raeburn 9379: if ($domconfig->{$role}{'font'} ne '') {
9380: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
9381: $changes{$role}{'font'} = 1;
9382: }
9383: } else {
9384: if ($confhash->{$role}{'font'}) {
9385: $changes{$role}{'font'} = 1;
9386: }
9387: }
1.107 raeburn 9388: if ($role ne 'login') {
9389: if ($domconfig->{$role}{'fontmenu'} ne '') {
9390: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
9391: $changes{$role}{'fontmenu'} = 1;
9392: }
9393: } else {
9394: if ($confhash->{$role}{'fontmenu'}) {
9395: $changes{$role}{'fontmenu'} = 1;
9396: }
1.97 tempelho 9397: }
9398: }
1.6 raeburn 9399: foreach my $item (@bgs) {
9400: if ($domconfig->{$role}{$item} ne '') {
9401: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9402: $changes{$role}{'bgs'}{$item} = 1;
9403: }
9404: } else {
9405: if ($confhash->{$role}{$item}) {
9406: $changes{$role}{'bgs'}{$item} = 1;
9407: }
9408: }
9409: }
9410: foreach my $item (@links) {
9411: if ($domconfig->{$role}{$item} ne '') {
9412: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9413: $changes{$role}{'links'}{$item} = 1;
9414: }
9415: } else {
9416: if ($confhash->{$role}{$item}) {
9417: $changes{$role}{'links'}{$item} = 1;
9418: }
9419: }
9420: }
1.41 raeburn 9421: foreach my $item (@logintext) {
9422: if ($domconfig->{$role}{$item} ne '') {
9423: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9424: $changes{$role}{'logintext'}{$item} = 1;
9425: }
9426: } else {
9427: if ($confhash->{$role}{$item}) {
9428: $changes{$role}{'logintext'}{$item} = 1;
9429: }
9430: }
9431: }
1.6 raeburn 9432: } else {
9433: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 9434: \@logintext,$confhash,\%changes);
1.6 raeburn 9435: }
9436: } else {
9437: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 9438: \@logintext,$confhash,\%changes);
1.6 raeburn 9439: }
9440: }
9441: return ($errors,%changes);
9442: }
9443:
1.46 raeburn 9444: sub config_check {
9445: my ($dom,$confname,$servadm) = @_;
9446: my ($configuserok,$author_ok,$switchserver,%currroles);
9447: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
9448: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
9449: $confname,$servadm);
9450: if ($configuserok eq 'ok') {
9451: $switchserver = &check_switchserver($dom,$confname);
9452: if ($switchserver eq '') {
9453: $author_ok = &check_authorstatus($dom,$confname,%currroles);
9454: }
9455: }
9456: return ($configuserok,$author_ok,$switchserver);
9457: }
9458:
1.6 raeburn 9459: sub default_change_checker {
1.41 raeburn 9460: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 9461: foreach my $item (@{$links}) {
9462: if ($confhash->{$role}{$item}) {
9463: $changes->{$role}{'links'}{$item} = 1;
9464: }
9465: }
9466: foreach my $item (@{$bgs}) {
9467: if ($confhash->{$role}{$item}) {
9468: $changes->{$role}{'bgs'}{$item} = 1;
9469: }
9470: }
1.41 raeburn 9471: foreach my $item (@{$logintext}) {
9472: if ($confhash->{$role}{$item}) {
9473: $changes->{$role}{'logintext'}{$item} = 1;
9474: }
9475: }
1.6 raeburn 9476: foreach my $img (@{$images}) {
9477: if ($env{'form.'.$role.'_del_'.$img}) {
9478: $confhash->{$role}{$img} = '';
1.12 raeburn 9479: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 9480: }
1.70 raeburn 9481: if ($role eq 'login') {
9482: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
9483: $changes->{$role}{'showlogo'}{$img} = 1;
9484: }
9485: }
1.6 raeburn 9486: }
9487: if ($confhash->{$role}{'font'}) {
9488: $changes->{$role}{'font'} = 1;
9489: }
1.48 raeburn 9490: }
1.6 raeburn 9491:
9492: sub display_colorchgs {
9493: my ($dom,$changes,$roles,$confhash) = @_;
9494: my (%choices,$resulttext);
9495: if (!grep(/^login$/,@{$roles})) {
9496: $resulttext = &mt('Changes made:').'<br />';
9497: }
9498: foreach my $role (@{$roles}) {
9499: if ($role eq 'login') {
9500: %choices = &login_choices();
9501: } else {
9502: %choices = &color_font_choices();
9503: }
9504: if (ref($changes->{$role}) eq 'HASH') {
9505: if ($role ne 'login') {
9506: $resulttext .= '<h4>'.&mt($role).'</h4>';
9507: }
9508: foreach my $key (sort(keys(%{$changes->{$role}}))) {
9509: if ($role ne 'login') {
9510: $resulttext .= '<ul>';
9511: }
9512: if (ref($changes->{$role}{$key}) eq 'HASH') {
9513: if ($role ne 'login') {
9514: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
9515: }
9516: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 9517: if (($role eq 'login') && ($key eq 'showlogo')) {
9518: if ($confhash->{$role}{$key}{$item}) {
9519: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
9520: } else {
9521: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
9522: }
9523: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 9524: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
9525: } else {
1.12 raeburn 9526: my $newitem = $confhash->{$role}{$item};
9527: if ($key eq 'images') {
1.306 raeburn 9528: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 9529: }
9530: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 9531: }
9532: }
9533: if ($role ne 'login') {
9534: $resulttext .= '</ul></li>';
9535: }
9536: } else {
9537: if ($confhash->{$role}{$key} eq '') {
9538: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
9539: } else {
9540: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
9541: }
9542: }
9543: if ($role ne 'login') {
9544: $resulttext .= '</ul>';
9545: }
9546: }
9547: }
9548: }
1.3 raeburn 9549: return $resulttext;
1.1 raeburn 9550: }
9551:
1.9 raeburn 9552: sub thumb_dimensions {
9553: return ('200','50');
9554: }
9555:
1.16 raeburn 9556: sub check_dimensions {
9557: my ($inputfile) = @_;
9558: my ($fullwidth,$fullheight);
9559: if ($inputfile =~ m|^[/\w.\-]+$|) {
9560: if (open(PIPE,"identify $inputfile 2>&1 |")) {
9561: my $imageinfo = <PIPE>;
9562: if (!close(PIPE)) {
9563: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
9564: }
9565: chomp($imageinfo);
9566: my ($fullsize) =
1.21 raeburn 9567: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 9568: if ($fullsize) {
9569: ($fullwidth,$fullheight) = split(/x/,$fullsize);
9570: }
9571: }
9572: }
9573: return ($fullwidth,$fullheight);
9574: }
9575:
1.9 raeburn 9576: sub check_configuser {
9577: my ($uhome,$dom,$confname,$servadm) = @_;
9578: my ($configuserok,%currroles);
9579: if ($uhome eq 'no_host') {
9580: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
9581: my $configpass = &LONCAPA::Enrollment::create_password();
9582: $configuserok =
9583: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
9584: $configpass,'','','','','',undef,$servadm);
9585: } else {
9586: $configuserok = 'ok';
9587: %currroles =
9588: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
9589: }
9590: return ($configuserok,%currroles);
9591: }
9592:
9593: sub check_authorstatus {
9594: my ($dom,$confname,%currroles) = @_;
9595: my $author_ok;
1.40 raeburn 9596: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 9597: my $start = time;
9598: my $end = 0;
9599: $author_ok =
9600: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 9601: 'au',$end,$start,'','','domconfig');
1.9 raeburn 9602: } else {
9603: $author_ok = 'ok';
9604: }
9605: return $author_ok;
9606: }
9607:
9608: sub publishlogo {
1.46 raeburn 9609: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 9610: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 9611: if ($action eq 'upload') {
9612: $fname=$env{'form.'.$formname.'.filename'};
9613: chop($env{'form.'.$formname});
9614: } else {
9615: ($fname) = ($formname =~ /([^\/]+)$/);
9616: }
1.46 raeburn 9617: if ($savefileas ne '') {
9618: $fname = $savefileas;
9619: }
1.9 raeburn 9620: $fname=&Apache::lonnet::clean_filename($fname);
9621: # See if there is anything left
9622: unless ($fname) { return ('error: no uploaded file'); }
9623: $fname="$subdir/$fname";
1.210 raeburn 9624: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 9625: my $filepath="$docroot/priv";
9626: my $relpath = "$dom/$confname";
1.9 raeburn 9627: my ($fnamepath,$file,$fetchthumb);
9628: $file=$fname;
9629: if ($fname=~m|/|) {
9630: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
9631: }
1.164 raeburn 9632: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 9633: my $count;
1.164 raeburn 9634: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 9635: $filepath.="/$parts[$count]";
9636: if ((-e $filepath)!=1) {
9637: mkdir($filepath,02770);
9638: }
9639: }
9640: # Check for bad extension and disallow upload
9641: if ($file=~/\.(\w+)$/ &&
9642: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
9643: $output =
1.207 bisitz 9644: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 9645: } elsif ($file=~/\.(\w+)$/ &&
9646: !defined(&Apache::loncommon::fileembstyle($1))) {
9647: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
9648: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 9649: $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 9650: } elsif (-d "$filepath/$file") {
1.195 bisitz 9651: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 9652: } else {
9653: my $source = $filepath.'/'.$file;
9654: my $logfile;
1.316 raeburn 9655: if (!open($logfile,">>",$source.'.log')) {
1.196 raeburn 9656: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 9657: }
9658: print $logfile
9659: "\n================= Publish ".localtime()." ================\n".
9660: $env{'user.name'}.':'.$env{'user.domain'}."\n";
9661: # Save the file
1.316 raeburn 9662: if (!open(FH,">",$source)) {
1.9 raeburn 9663: &Apache::lonnet::logthis('Failed to create '.$source);
9664: return (&mt('Failed to create file'));
9665: }
9666: if ($action eq 'upload') {
9667: if (!print FH ($env{'form.'.$formname})) {
9668: &Apache::lonnet::logthis('Failed to write to '.$source);
9669: return (&mt('Failed to write file'));
9670: }
9671: } else {
9672: my $original = &Apache::lonnet::filelocation('',$formname);
9673: if(!copy($original,$source)) {
9674: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
9675: return (&mt('Failed to write file'));
9676: }
9677: }
9678: close(FH);
9679: chmod(0660, $source); # Permissions to rw-rw---.
9680:
9681: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
9682: my $copyfile=$targetdir.'/'.$file;
9683:
9684: my @parts=split(/\//,$targetdir);
9685: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
9686: for (my $count=5;$count<=$#parts;$count++) {
9687: $path.="/$parts[$count]";
9688: if (!-e $path) {
9689: print $logfile "\nCreating directory ".$path;
9690: mkdir($path,02770);
9691: }
9692: }
9693: my $versionresult;
9694: if (-e $copyfile) {
9695: $versionresult = &logo_versioning($targetdir,$file,$logfile);
9696: } else {
9697: $versionresult = 'ok';
9698: }
9699: if ($versionresult eq 'ok') {
9700: if (copy($source,$copyfile)) {
9701: print $logfile "\nCopied original source to ".$copyfile."\n";
9702: $output = 'ok';
9703: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 9704: push(@{$modified_urls},[$copyfile,$source]);
9705: my $metaoutput =
9706: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
9707: unless ($registered_cleanup) {
9708: my $handlers = $r->get_handlers('PerlCleanupHandler');
9709: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
9710: $registered_cleanup=1;
9711: }
1.9 raeburn 9712: } else {
9713: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
9714: $output = &mt('Failed to copy file to RES space').", $!";
9715: }
9716: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
9717: my $inputfile = $filepath.'/'.$file;
9718: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 9719: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
9720: if ($fullwidth ne '' && $fullheight ne '') {
9721: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
9722: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316 raeburn 9723: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
9724: system({$args[0]} @args);
1.16 raeburn 9725: chmod(0660, $filepath.'/tn-'.$file);
9726: if (-e $outfile) {
9727: my $copyfile=$targetdir.'/tn-'.$file;
9728: if (copy($outfile,$copyfile)) {
9729: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 9730: my $thumb_metaoutput =
9731: &write_metadata($dom,$confname,$formname,
9732: $targetdir,'tn-'.$file,$logfile);
9733: push(@{$modified_urls},[$copyfile,$outfile]);
9734: unless ($registered_cleanup) {
9735: my $handlers = $r->get_handlers('PerlCleanupHandler');
9736: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
9737: $registered_cleanup=1;
9738: }
1.267 raeburn 9739: $madethumb = 1;
1.16 raeburn 9740: } else {
9741: print $logfile "\nUnable to write ".$copyfile.
9742: ':'.$!."\n";
9743: }
9744: }
1.9 raeburn 9745: }
9746: }
9747: }
9748: } else {
9749: $output = $versionresult;
9750: }
9751: }
1.267 raeburn 9752: return ($output,$logourl,$madethumb);
1.9 raeburn 9753: }
9754:
9755: sub logo_versioning {
9756: my ($targetdir,$file,$logfile) = @_;
9757: my $target = $targetdir.'/'.$file;
9758: my ($maxversion,$fn,$extn,$output);
9759: $maxversion = 0;
9760: if ($file =~ /^(.+)\.(\w+)$/) {
9761: $fn=$1;
9762: $extn=$2;
9763: }
9764: opendir(DIR,$targetdir);
9765: while (my $filename=readdir(DIR)) {
9766: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
9767: $maxversion=($1>$maxversion)?$1:$maxversion;
9768: }
9769: }
9770: $maxversion++;
9771: print $logfile "\nCreating old version ".$maxversion."\n";
9772: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
9773: if (copy($target,$copyfile)) {
9774: print $logfile "Copied old target to ".$copyfile."\n";
9775: $copyfile=$copyfile.'.meta';
9776: if (copy($target.'.meta',$copyfile)) {
9777: print $logfile "Copied old target metadata to ".$copyfile."\n";
9778: $output = 'ok';
9779: } else {
9780: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
9781: $output = &mt('Failed to copy old meta').", $!, ";
9782: }
9783: } else {
9784: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
9785: $output = &mt('Failed to copy old target').", $!, ";
9786: }
9787: return $output;
9788: }
9789:
9790: sub write_metadata {
9791: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
9792: my (%metadatafields,%metadatakeys,$output);
9793: $metadatafields{'title'}=$formname;
9794: $metadatafields{'creationdate'}=time;
9795: $metadatafields{'lastrevisiondate'}=time;
9796: $metadatafields{'copyright'}='public';
9797: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
9798: $env{'user.domain'};
9799: $metadatafields{'authorspace'}=$confname.':'.$dom;
9800: $metadatafields{'domain'}=$dom;
9801: {
9802: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
9803: my $mfh;
1.316 raeburn 9804: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 9805: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 9806: unless ($_=~/\./) {
9807: my $unikey=$_;
9808: $unikey=~/^([A-Za-z]+)/;
9809: my $tag=$1;
9810: $tag=~tr/A-Z/a-z/;
9811: print $mfh "\n\<$tag";
9812: foreach (split(/\,/,$metadatakeys{$unikey})) {
9813: my $value=$metadatafields{$unikey.'.'.$_};
9814: $value=~s/\"/\'\'/g;
9815: print $mfh ' '.$_.'="'.$value.'"';
9816: }
9817: print $mfh '>'.
9818: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
9819: .'</'.$tag.'>';
9820: }
9821: }
9822: $output = 'ok';
9823: print $logfile "\nWrote metadata";
9824: close($mfh);
9825: } else {
9826: print $logfile "\nFailed to open metadata file";
1.9 raeburn 9827: $output = &mt('Could not write metadata');
9828: }
9829: }
1.155 raeburn 9830: return $output;
9831: }
9832:
9833: sub notifysubscribed {
9834: foreach my $targetsource (@{$modified_urls}){
9835: next unless (ref($targetsource) eq 'ARRAY');
9836: my ($target,$source)=@{$targetsource};
9837: if ($source ne '') {
1.316 raeburn 9838: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 9839: print $logfh "\nCleanup phase: Notifications\n";
9840: my @subscribed=&subscribed_hosts($target);
9841: foreach my $subhost (@subscribed) {
9842: print $logfh "\nNotifying host ".$subhost.':';
9843: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
9844: print $logfh $reply;
9845: }
9846: my @subscribedmeta=&subscribed_hosts("$target.meta");
9847: foreach my $subhost (@subscribedmeta) {
9848: print $logfh "\nNotifying host for metadata only ".$subhost.':';
9849: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
9850: $subhost);
9851: print $logfh $reply;
9852: }
9853: print $logfh "\n============ Done ============\n";
1.160 raeburn 9854: close($logfh);
1.155 raeburn 9855: }
9856: }
9857: }
9858: return OK;
9859: }
9860:
9861: sub subscribed_hosts {
9862: my ($target) = @_;
9863: my @subscribed;
1.316 raeburn 9864: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 9865: while (my $subline=<$fh>) {
9866: if ($subline =~ /^($match_lonid):/) {
9867: my $host = $1;
9868: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
9869: unless (grep(/^\Q$host\E$/,@subscribed)) {
9870: push(@subscribed,$host);
9871: }
9872: }
9873: }
9874: }
9875: }
9876: return @subscribed;
1.9 raeburn 9877: }
9878:
9879: sub check_switchserver {
9880: my ($dom,$confname) = @_;
9881: my ($allowed,$switchserver);
9882: my $home = &Apache::lonnet::homeserver($confname,$dom);
9883: if ($home eq 'no_host') {
9884: $home = &Apache::lonnet::domain($dom,'primary');
9885: }
9886: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 9887: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
9888: if (!$allowed) {
1.180 raeburn 9889: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 9890: }
9891: return $switchserver;
9892: }
9893:
1.1 raeburn 9894: sub modify_quotas {
1.216 raeburn 9895: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 9896: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 9897: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 9898: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
9899: $validationfieldsref);
1.86 raeburn 9900: if ($action eq 'quotas') {
9901: $context = 'tools';
1.163 raeburn 9902: } else {
1.86 raeburn 9903: $context = $action;
9904: }
9905: if ($context eq 'requestcourses') {
1.271 raeburn 9906: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 9907: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 9908: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
9909: %titles = &courserequest_titles();
9910: $toolregexp = join('|',@usertools);
9911: %conditions = &courserequest_conditions();
1.216 raeburn 9912: $confname = $dom.'-domainconfig';
9913: my $servadm = $r->dir_config('lonAdmEMail');
9914: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 9915: ($validationitemsref,$validationnamesref,$validationfieldsref) =
9916: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 9917: } elsif ($context eq 'requestauthor') {
9918: @usertools = ('author');
9919: %titles = &authorrequest_titles();
1.86 raeburn 9920: } else {
1.162 raeburn 9921: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 9922: %titles = &tool_titles();
1.86 raeburn 9923: }
1.212 raeburn 9924: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 9925: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 9926: foreach my $key (keys(%env)) {
1.101 raeburn 9927: if ($context eq 'requestcourses') {
9928: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
9929: my $item = $1;
9930: my $type = $2;
9931: if ($type =~ /^limit_(.+)/) {
9932: $limithash{$item}{$1} = $env{$key};
9933: } else {
9934: $confhash{$item}{$type} = $env{$key};
9935: }
9936: }
1.163 raeburn 9937: } elsif ($context eq 'requestauthor') {
9938: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
9939: $confhash{$1} = $env{$key};
9940: }
1.101 raeburn 9941: } else {
1.86 raeburn 9942: if ($key =~ /^form\.quota_(.+)$/) {
9943: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 9944: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
9945: $confhash{'authorquota'}{$1} = $env{$key};
9946: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 9947: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
9948: }
1.72 raeburn 9949: }
9950: }
1.163 raeburn 9951: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 9952: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 9953: @approvalnotify = sort(@approvalnotify);
9954: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.271 raeburn 9955: my @crstypes = ('official','unofficial','community','textbook','placement');
1.218 raeburn 9956: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
9957: foreach my $type (@hasuniquecode) {
9958: if (grep(/^\Q$type\E$/,@crstypes)) {
9959: $confhash{'uniquecode'}{$type} = 1;
9960: }
1.216 raeburn 9961: }
1.242 raeburn 9962: my (%newbook,%allpos);
1.216 raeburn 9963: if ($context eq 'requestcourses') {
1.242 raeburn 9964: foreach my $type ('textbooks','templates') {
9965: @{$allpos{$type}} = ();
9966: my $invalid;
9967: if ($type eq 'textbooks') {
9968: $invalid = &mt('Invalid LON-CAPA course for textbook');
9969: } else {
9970: $invalid = &mt('Invalid LON-CAPA course for template');
9971: }
9972: if ($env{'form.'.$type.'_addbook'}) {
9973: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
9974: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
9975: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
9976: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
9977: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
9978: } else {
9979: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
9980: my $position = $env{'form.'.$type.'_addbook_pos'};
9981: $position =~ s/\D+//g;
9982: if ($position ne '') {
9983: $allpos{$type}[$position] = $newbook{$type};
9984: }
1.216 raeburn 9985: }
1.242 raeburn 9986: } else {
9987: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 9988: }
9989: }
1.242 raeburn 9990: }
1.216 raeburn 9991: }
1.102 raeburn 9992: if (ref($domconfig{$action}) eq 'HASH') {
9993: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
9994: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
9995: $changes{'notify'}{'approval'} = 1;
9996: }
9997: } else {
1.144 raeburn 9998: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 9999: $changes{'notify'}{'approval'} = 1;
10000: }
10001: }
1.218 raeburn 10002: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
10003: if (ref($confhash{'uniquecode'}) eq 'HASH') {
10004: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
10005: unless ($confhash{'uniquecode'}{$crstype}) {
10006: $changes{'uniquecode'} = 1;
10007: }
10008: }
10009: unless ($changes{'uniquecode'}) {
10010: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
10011: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
10012: $changes{'uniquecode'} = 1;
10013: }
10014: }
10015: }
10016: } else {
10017: $changes{'uniquecode'} = 1;
10018: }
10019: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
10020: $changes{'uniquecode'} = 1;
1.216 raeburn 10021: }
10022: if ($context eq 'requestcourses') {
1.242 raeburn 10023: foreach my $type ('textbooks','templates') {
10024: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10025: my %deletions;
10026: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
10027: if (@todelete) {
10028: map { $deletions{$_} = 1; } @todelete;
10029: }
10030: my %imgdeletions;
10031: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
10032: if (@todeleteimages) {
10033: map { $imgdeletions{$_} = 1; } @todeleteimages;
10034: }
10035: my $maxnum = $env{'form.'.$type.'_maxnum'};
10036: for (my $i=0; $i<=$maxnum; $i++) {
10037: my $itemid = $env{'form.'.$type.'_id_'.$i};
10038: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
10039: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
10040: if ($deletions{$key}) {
10041: if ($domconfig{$action}{$type}{$key}{'image'}) {
10042: #FIXME need to obsolete item in RES space
10043: }
10044: next;
10045: } else {
10046: my $newpos = $env{'form.'.$itemid};
10047: $newpos =~ s/\D+//g;
1.243 raeburn 10048: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 10049: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 10050: ($type eq 'templates'));
1.242 raeburn 10051: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
10052: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
10053: $changes{$type}{$key} = 1;
10054: }
10055: }
10056: $allpos{$type}[$newpos] = $key;
10057: }
10058: if ($imgdeletions{$key}) {
10059: $changes{$type}{$key} = 1;
1.216 raeburn 10060: #FIXME need to obsolete item in RES space
1.242 raeburn 10061: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
10062: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 10063: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10064: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10065: } else {
10066: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
10067: $cdom,$cnum,$type,$configuserok,
10068: $switchserver,$author_ok);
10069: if ($imgurl) {
10070: $confhash{$type}{$key}{'image'} = $imgurl;
10071: $changes{$type}{$key} = 1;
10072: }
10073: if ($error) {
10074: &Apache::lonnet::logthis($error);
10075: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10076: }
10077: }
1.242 raeburn 10078: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
10079: $confhash{$type}{$key}{'image'} =
10080: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 10081: }
10082: }
10083: }
10084: }
10085: }
10086: }
1.102 raeburn 10087: } else {
1.144 raeburn 10088: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10089: $changes{'notify'}{'approval'} = 1;
10090: }
1.218 raeburn 10091: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 10092: $changes{'uniquecode'} = 1;
10093: }
10094: }
10095: if ($context eq 'requestcourses') {
1.242 raeburn 10096: foreach my $type ('textbooks','templates') {
10097: if ($newbook{$type}) {
10098: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 10099: foreach my $item ('subject','title','publisher','author') {
10100: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10101: ($type eq 'template'));
1.242 raeburn 10102: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
10103: if ($env{'form.'.$type.'_addbook_'.$item}) {
10104: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
10105: }
10106: }
10107: if ($type eq 'textbooks') {
10108: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
10109: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 10110: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10111: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10112: } else {
10113: my ($imageurl,$error) =
10114: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
10115: $configuserok,$switchserver,$author_ok);
10116: if ($imageurl) {
10117: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
10118: }
10119: if ($error) {
10120: &Apache::lonnet::logthis($error);
10121: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10122: }
1.242 raeburn 10123: }
10124: }
1.216 raeburn 10125: }
10126: }
1.242 raeburn 10127: if (@{$allpos{$type}} > 0) {
10128: my $idx = 0;
10129: foreach my $item (@{$allpos{$type}}) {
10130: if ($item ne '') {
10131: $confhash{$type}{$item}{'order'} = $idx;
10132: if (ref($domconfig{$action}) eq 'HASH') {
10133: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10134: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
10135: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
10136: $changes{$type}{$item} = 1;
10137: }
1.216 raeburn 10138: }
10139: }
10140: }
1.242 raeburn 10141: $idx ++;
1.216 raeburn 10142: }
10143: }
10144: }
10145: }
1.235 raeburn 10146: if (ref($validationitemsref) eq 'ARRAY') {
10147: foreach my $item (@{$validationitemsref}) {
10148: if ($item eq 'fields') {
10149: my @changed;
10150: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
10151: if (@{$confhash{'validation'}{$item}} > 0) {
10152: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
10153: }
1.266 raeburn 10154: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10155: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10156: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
10157: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
10158: $domconfig{'requestcourses'}{'validation'}{$item});
10159: } else {
10160: @changed = @{$confhash{'validation'}{$item}};
10161: }
1.235 raeburn 10162: } else {
10163: @changed = @{$confhash{'validation'}{$item}};
10164: }
10165: } else {
10166: @changed = @{$confhash{'validation'}{$item}};
10167: }
10168: if (@changed) {
10169: if ($confhash{'validation'}{$item}) {
10170: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
10171: } else {
10172: $changes{'validation'}{$item} = &mt('None');
10173: }
10174: }
10175: } else {
10176: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
10177: if ($item eq 'markup') {
10178: if ($env{'form.requestcourses_validation_'.$item}) {
10179: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10180: }
10181: }
1.266 raeburn 10182: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10183: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10184: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
10185: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10186: }
10187: } else {
10188: if ($confhash{'validation'}{$item} ne '') {
10189: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10190: }
1.235 raeburn 10191: }
10192: } else {
10193: if ($confhash{'validation'}{$item} ne '') {
10194: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10195: }
10196: }
10197: }
10198: }
10199: }
10200: if ($env{'form.validationdc'}) {
10201: my $newval = $env{'form.validationdc'};
1.285 raeburn 10202: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 10203: if (exists($domcoords{$newval})) {
10204: $confhash{'validation'}{'dc'} = $newval;
10205: }
10206: }
10207: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 10208: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10209: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10210: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10211: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
10212: if ($confhash{'validation'}{'dc'} eq '') {
10213: $changes{'validation'}{'dc'} = &mt('None');
10214: } else {
10215: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10216: }
1.235 raeburn 10217: }
1.266 raeburn 10218: } elsif ($confhash{'validation'}{'dc'} ne '') {
10219: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 10220: }
10221: } elsif ($confhash{'validation'}{'dc'} ne '') {
10222: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10223: }
10224: } elsif ($confhash{'validation'}{'dc'} ne '') {
10225: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 10226: }
1.266 raeburn 10227: } else {
10228: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10229: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10230: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10231: $changes{'validation'}{'dc'} = &mt('None');
10232: }
10233: }
1.235 raeburn 10234: }
10235: }
1.102 raeburn 10236: }
10237: } else {
1.86 raeburn 10238: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 10239: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 10240: }
1.72 raeburn 10241: foreach my $item (@usertools) {
10242: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 10243: my $unset;
1.101 raeburn 10244: if ($context eq 'requestcourses') {
1.104 raeburn 10245: $unset = '0';
10246: if ($type eq '_LC_adv') {
10247: $unset = '';
10248: }
1.101 raeburn 10249: if ($confhash{$item}{$type} eq 'autolimit') {
10250: $confhash{$item}{$type} .= '=';
10251: unless ($limithash{$item}{$type} =~ /\D/) {
10252: $confhash{$item}{$type} .= $limithash{$item}{$type};
10253: }
10254: }
1.163 raeburn 10255: } elsif ($context eq 'requestauthor') {
10256: $unset = '0';
10257: if ($type eq '_LC_adv') {
10258: $unset = '';
10259: }
1.72 raeburn 10260: } else {
1.101 raeburn 10261: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
10262: $confhash{$item}{$type} = 1;
10263: } else {
10264: $confhash{$item}{$type} = 0;
10265: }
1.72 raeburn 10266: }
1.86 raeburn 10267: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 10268: if ($action eq 'requestauthor') {
10269: if ($domconfig{$action}{$type} ne $confhash{$type}) {
10270: $changes{$type} = 1;
10271: }
10272: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 10273: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
10274: $changes{$item}{$type} = 1;
10275: }
10276: } else {
10277: if ($context eq 'requestcourses') {
1.104 raeburn 10278: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 10279: $changes{$item}{$type} = 1;
10280: }
10281: } else {
10282: if (!$confhash{$item}{$type}) {
10283: $changes{$item}{$type} = 1;
10284: }
10285: }
10286: }
10287: } else {
10288: if ($context eq 'requestcourses') {
1.104 raeburn 10289: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 10290: $changes{$item}{$type} = 1;
10291: }
1.163 raeburn 10292: } elsif ($context eq 'requestauthor') {
10293: if ($confhash{$type} ne $unset) {
10294: $changes{$type} = 1;
10295: }
1.72 raeburn 10296: } else {
10297: if (!$confhash{$item}{$type}) {
10298: $changes{$item}{$type} = 1;
10299: }
10300: }
10301: }
1.1 raeburn 10302: }
10303: }
1.163 raeburn 10304: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 10305: if (ref($domconfig{'quotas'}) eq 'HASH') {
10306: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
10307: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
10308: if (exists($confhash{'defaultquota'}{$key})) {
10309: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
10310: $changes{'defaultquota'}{$key} = 1;
10311: }
10312: } else {
10313: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 10314: }
10315: }
1.86 raeburn 10316: } else {
10317: foreach my $key (keys(%{$domconfig{'quotas'}})) {
10318: if (exists($confhash{'defaultquota'}{$key})) {
10319: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
10320: $changes{'defaultquota'}{$key} = 1;
10321: }
10322: } else {
10323: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 10324: }
1.1 raeburn 10325: }
10326: }
1.197 raeburn 10327: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
10328: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
10329: if (exists($confhash{'authorquota'}{$key})) {
10330: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
10331: $changes{'authorquota'}{$key} = 1;
10332: }
10333: } else {
10334: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
10335: }
10336: }
10337: }
1.1 raeburn 10338: }
1.86 raeburn 10339: if (ref($confhash{'defaultquota'}) eq 'HASH') {
10340: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
10341: if (ref($domconfig{'quotas'}) eq 'HASH') {
10342: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
10343: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
10344: $changes{'defaultquota'}{$key} = 1;
10345: }
10346: } else {
10347: if (!exists($domconfig{'quotas'}{$key})) {
10348: $changes{'defaultquota'}{$key} = 1;
10349: }
1.72 raeburn 10350: }
10351: } else {
1.86 raeburn 10352: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 10353: }
1.1 raeburn 10354: }
10355: }
1.197 raeburn 10356: if (ref($confhash{'authorquota'}) eq 'HASH') {
10357: foreach my $key (keys(%{$confhash{'authorquota'}})) {
10358: if (ref($domconfig{'quotas'}) eq 'HASH') {
10359: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
10360: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
10361: $changes{'authorquota'}{$key} = 1;
10362: }
10363: } else {
10364: $changes{'authorquota'}{$key} = 1;
10365: }
10366: } else {
10367: $changes{'authorquota'}{$key} = 1;
10368: }
10369: }
10370: }
1.1 raeburn 10371: }
1.72 raeburn 10372:
1.163 raeburn 10373: if ($context eq 'requestauthor') {
10374: $domdefaults{'requestauthor'} = \%confhash;
10375: } else {
10376: foreach my $key (keys(%confhash)) {
1.242 raeburn 10377: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 10378: $domdefaults{$key} = $confhash{$key};
10379: }
1.163 raeburn 10380: }
1.72 raeburn 10381: }
1.163 raeburn 10382:
1.1 raeburn 10383: my %quotahash = (
1.86 raeburn 10384: $action => { %confhash }
1.1 raeburn 10385: );
10386: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
10387: $dom);
10388: if ($putresult eq 'ok') {
10389: if (keys(%changes) > 0) {
1.72 raeburn 10390: my $cachetime = 24*60*60;
10391: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 10392: if (ref($lastactref) eq 'HASH') {
10393: $lastactref->{'domdefaults'} = 1;
10394: }
1.1 raeburn 10395: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 10396: unless (($context eq 'requestcourses') ||
1.163 raeburn 10397: ($context eq 'requestauthor')) {
1.86 raeburn 10398: if (ref($changes{'defaultquota'}) eq 'HASH') {
10399: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
10400: foreach my $type (@{$types},'default') {
10401: if (defined($changes{'defaultquota'}{$type})) {
10402: my $typetitle = $usertypes->{$type};
10403: if ($type eq 'default') {
10404: $typetitle = $othertitle;
10405: }
1.213 raeburn 10406: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 10407: }
10408: }
1.86 raeburn 10409: $resulttext .= '</ul></li>';
1.72 raeburn 10410: }
1.197 raeburn 10411: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 10412: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 10413: foreach my $type (@{$types},'default') {
10414: if (defined($changes{'authorquota'}{$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{'authorquota'}{$type}).'</li>';
1.197 raeburn 10420: }
10421: }
10422: $resulttext .= '</ul></li>';
10423: }
1.72 raeburn 10424: }
1.80 raeburn 10425: my %newenv;
1.72 raeburn 10426: foreach my $item (@usertools) {
1.163 raeburn 10427: my (%haschgs,%inconf);
10428: if ($context eq 'requestauthor') {
10429: %haschgs = %changes;
1.210 raeburn 10430: %inconf = %confhash;
1.163 raeburn 10431: } else {
10432: if (ref($changes{$item}) eq 'HASH') {
10433: %haschgs = %{$changes{$item}};
10434: }
10435: if (ref($confhash{$item}) eq 'HASH') {
10436: %inconf = %{$confhash{$item}};
10437: }
10438: }
10439: if (keys(%haschgs) > 0) {
1.80 raeburn 10440: my $newacc =
10441: &Apache::lonnet::usertools_access($env{'user.name'},
10442: $env{'user.domain'},
1.86 raeburn 10443: $item,'reload',$context);
1.210 raeburn 10444: if (($context eq 'requestcourses') ||
1.163 raeburn 10445: ($context eq 'requestauthor')) {
1.108 raeburn 10446: if ($env{'environment.canrequest.'.$item} ne $newacc) {
10447: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 10448: }
10449: } else {
10450: if ($env{'environment.availabletools.'.$item} ne $newacc) {
10451: $newenv{'environment.availabletools.'.$item} = $newacc;
10452: }
1.80 raeburn 10453: }
1.163 raeburn 10454: unless ($context eq 'requestauthor') {
10455: $resulttext .= '<li>'.$titles{$item}.'<ul>';
10456: }
1.72 raeburn 10457: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 10458: if ($haschgs{$type}) {
1.72 raeburn 10459: my $typetitle = $usertypes->{$type};
10460: if ($type eq 'default') {
10461: $typetitle = $othertitle;
10462: } elsif ($type eq '_LC_adv') {
10463: $typetitle = 'LON-CAPA Advanced Users';
10464: }
1.163 raeburn 10465: if ($inconf{$type}) {
1.101 raeburn 10466: if ($context eq 'requestcourses') {
10467: my $cond;
1.163 raeburn 10468: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 10469: if ($1 eq '') {
10470: $cond = &mt('(Automatic processing of any request).');
10471: } else {
10472: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
10473: }
10474: } else {
1.163 raeburn 10475: $cond = $conditions{$inconf{$type}};
1.101 raeburn 10476: }
10477: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 10478: } elsif ($context eq 'requestauthor') {
10479: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
10480: $titles{$inconf{$type}},$typetitle);
10481:
1.101 raeburn 10482: } else {
10483: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
10484: }
1.72 raeburn 10485: } else {
1.104 raeburn 10486: if ($type eq '_LC_adv') {
1.163 raeburn 10487: if ($inconf{$type} eq '0') {
1.104 raeburn 10488: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
10489: } else {
10490: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
10491: }
10492: } else {
10493: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
10494: }
1.72 raeburn 10495: }
10496: }
1.26 raeburn 10497: }
1.163 raeburn 10498: unless ($context eq 'requestauthor') {
10499: $resulttext .= '</ul></li>';
10500: }
1.26 raeburn 10501: }
1.1 raeburn 10502: }
1.163 raeburn 10503: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 10504: if (ref($changes{'notify'}) eq 'HASH') {
10505: if ($changes{'notify'}{'approval'}) {
10506: if (ref($confhash{'notify'}) eq 'HASH') {
10507: if ($confhash{'notify'}{'approval'}) {
10508: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
10509: } else {
1.163 raeburn 10510: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 10511: }
10512: }
10513: }
10514: }
10515: }
1.216 raeburn 10516: if ($action eq 'requestcourses') {
10517: my @offon = ('off','on');
10518: if ($changes{'uniquecode'}) {
1.218 raeburn 10519: if (ref($confhash{'uniquecode'}) eq 'HASH') {
10520: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
10521: $resulttext .= '<li>'.
10522: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
10523: '</li>';
10524: } else {
10525: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
10526: '</li>';
10527: }
1.216 raeburn 10528: }
1.242 raeburn 10529: foreach my $type ('textbooks','templates') {
10530: if (ref($changes{$type}) eq 'HASH') {
10531: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
10532: foreach my $key (sort(keys(%{$changes{$type}}))) {
10533: my %coursehash = &Apache::lonnet::coursedescription($key);
10534: my $coursetitle = $coursehash{'description'};
10535: my $position = $confhash{$type}{$key}{'order'} + 1;
10536: $resulttext .= '<li>';
1.243 raeburn 10537: foreach my $item ('subject','title','publisher','author') {
10538: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10539: ($type eq 'templates'));
1.242 raeburn 10540: my $name = $item.':';
10541: $name =~ s/^(\w)/\U$1/;
10542: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
10543: }
10544: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
10545: if ($type eq 'textbooks') {
10546: if ($confhash{$type}{$key}{'image'}) {
10547: $resulttext .= ' '.&mt('Image: [_1]',
10548: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
10549: ' alt="Textbook cover" />').'<br />';
10550: }
10551: }
10552: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 10553: }
1.242 raeburn 10554: $resulttext .= '</ul></li>';
1.216 raeburn 10555: }
10556: }
1.235 raeburn 10557: if (ref($changes{'validation'}) eq 'HASH') {
10558: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
10559: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
10560: foreach my $item (@{$validationitemsref}) {
10561: if (exists($changes{'validation'}{$item})) {
10562: if ($item eq 'markup') {
10563: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
10564: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
10565: } else {
10566: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
10567: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
10568: }
10569: }
10570: }
10571: if (exists($changes{'validation'}{'dc'})) {
10572: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
10573: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
10574: }
10575: }
10576: }
1.216 raeburn 10577: }
1.1 raeburn 10578: $resulttext .= '</ul>';
1.80 raeburn 10579: if (keys(%newenv)) {
10580: &Apache::lonnet::appenv(\%newenv);
10581: }
1.1 raeburn 10582: } else {
1.86 raeburn 10583: if ($context eq 'requestcourses') {
10584: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 10585: } elsif ($context eq 'requestauthor') {
10586: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 10587: } else {
1.90 weissno 10588: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 10589: }
1.1 raeburn 10590: }
10591: } else {
1.11 albertel 10592: $resulttext = '<span class="LC_error">'.
10593: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10594: }
1.216 raeburn 10595: if ($errors) {
10596: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
10597: '<ul>'.$errors.'</ul></p>';
10598: }
1.3 raeburn 10599: return $resulttext;
1.1 raeburn 10600: }
10601:
1.216 raeburn 10602: sub process_textbook_image {
1.242 raeburn 10603: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 10604: my $filename = $env{'form.'.$caller.'.filename'};
10605: my ($error,$url);
10606: my ($width,$height) = (50,50);
10607: if ($configuserok eq 'ok') {
10608: if ($switchserver) {
10609: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
10610: $switchserver);
10611: } elsif ($author_ok eq 'ok') {
10612: my ($result,$imageurl) =
10613: &publishlogo($r,'upload',$caller,$dom,$confname,
1.312 raeburn 10614: "$type/$cdom/$cnum/cover",$width,$height);
1.216 raeburn 10615: if ($result eq 'ok') {
10616: $url = $imageurl;
10617: } else {
10618: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
10619: }
10620: } else {
10621: $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);
10622: }
10623: } else {
10624: $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);
10625: }
10626: return ($url,$error);
10627: }
10628:
1.267 raeburn 10629: sub modify_ltitools {
10630: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
10631: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 10632: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 10633: my $confname = $dom.'-domainconfig';
10634: my $servadm = $r->dir_config('lonAdmEMail');
10635: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10636: my (%posslti,%possfield);
10637: my @courseroles = ('cc','in','ta','ep','st');
10638: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
10639: map { $posslti{$_} = 1; } @ltiroles;
10640: my @allfields = ('fullname','firstname','lastname','email','user','roles');
10641: map { $possfield{$_} = 1; } @allfields;
10642: my %lt = <itools_names();
10643: if ($env{'form.ltitools_add'}) {
10644: my $title = $env{'form.ltitools_add_title'};
10645: $title =~ s/(`)/'/g;
10646: ($newid,my $error) = &get_ltitools_id($dom,$title);
10647: if ($newid) {
10648: my $position = $env{'form.ltitools_add_pos'};
10649: $position =~ s/\D+//g;
10650: if ($position ne '') {
10651: $allpos[$position] = $newid;
10652: }
10653: $changes{$newid} = 1;
1.322 ! raeburn 10654: foreach my $item ('title','url','key','secret','lifetime') {
1.267 raeburn 10655: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1.322 ! raeburn 10656: if ($item eq 'lifetime') {
! 10657: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
! 10658: }
1.267 raeburn 10659: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 10660: if (($item eq 'key') || ($item eq 'secret')) {
10661: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
10662: } else {
10663: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
10664: }
1.267 raeburn 10665: }
10666: }
10667: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
10668: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
10669: }
10670: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
10671: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
10672: }
1.296 raeburn 10673: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 10674: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
10675: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 10676: if (($item eq 'width') || ($item eq 'height')) {
10677: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
10678: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
10679: }
10680: } else {
10681: if ($env{'form.ltitools_add_'.$item} ne '') {
10682: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
10683: }
1.267 raeburn 10684: }
10685: }
10686: if ($env{'form.ltitools_add_target'} eq 'window') {
10687: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 10688: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
10689: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 10690: } else {
10691: $confhash{$newid}{'display'}{'target'} = 'iframe';
10692: }
10693: foreach my $item ('passback','roster') {
1.319 raeburn 10694: if ($env{'form.ltitools_'.$item.'_add'}) {
1.267 raeburn 10695: $confhash{$newid}{$item} = 1;
1.319 raeburn 10696: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
10697: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
10698: $lifetime =~ s/^\s+|\s+$//g;
10699: if ($lifetime =~ /^\d+\.?\d*$/) {
10700: $confhash{$newid}{$item.'valid'} = $lifetime;
10701: }
10702: }
1.267 raeburn 10703: }
10704: }
10705: if ($env{'form.ltitools_add_image.filename'} ne '') {
10706: my ($imageurl,$error) =
1.307 raeburn 10707: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267 raeburn 10708: $configuserok,$switchserver,$author_ok);
10709: if ($imageurl) {
10710: $confhash{$newid}{'image'} = $imageurl;
10711: }
10712: if ($error) {
10713: &Apache::lonnet::logthis($error);
10714: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10715: }
10716: }
10717: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
10718: foreach my $field (@fields) {
10719: if ($possfield{$field}) {
10720: if ($field eq 'roles') {
10721: foreach my $role (@courseroles) {
10722: my $choice = $env{'form.ltitools_add_roles_'.$role};
10723: if (($choice ne '') && ($posslti{$choice})) {
10724: $confhash{$newid}{'roles'}{$role} = $choice;
10725: if ($role eq 'cc') {
10726: $confhash{$newid}{'roles'}{'co'} = $choice;
10727: }
10728: }
10729: }
10730: } else {
10731: $confhash{$newid}{'fields'}{$field} = 1;
10732: }
10733: }
10734: }
1.273 raeburn 10735: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
10736: foreach my $item (@courseconfig) {
10737: $confhash{$newid}{'crsconf'}{$item} = 1;
10738: }
1.267 raeburn 10739: if ($env{'form.ltitools_add_custom'}) {
10740: my $name = $env{'form.ltitools_add_custom_name'};
10741: my $value = $env{'form.ltitools_add_custom_value'};
10742: $value =~ s/(`)/'/g;
10743: $name =~ s/(`)/'/g;
10744: $confhash{$newid}{'custom'}{$name} = $value;
10745: }
10746: } else {
10747: my $error = &mt('Failed to acquire unique ID for new external tool');
10748: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10749: }
10750: }
10751: if (ref($domconfig{$action}) eq 'HASH') {
10752: my %deletions;
10753: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
10754: if (@todelete) {
10755: map { $deletions{$_} = 1; } @todelete;
10756: }
10757: my %customadds;
10758: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
10759: if (@newcustom) {
10760: map { $customadds{$_} = 1; } @newcustom;
10761: }
10762: my %imgdeletions;
10763: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
10764: if (@todeleteimages) {
10765: map { $imgdeletions{$_} = 1; } @todeleteimages;
10766: }
10767: my $maxnum = $env{'form.ltitools_maxnum'};
10768: for (my $i=0; $i<=$maxnum; $i++) {
10769: my $itemid = $env{'form.ltitools_id_'.$i};
1.308 raeburn 10770: $itemid =~ s/\D+//g;
1.267 raeburn 10771: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
10772: if ($deletions{$itemid}) {
10773: if ($domconfig{$action}{$itemid}{'image'}) {
10774: #FIXME need to obsolete item in RES space
10775: }
10776: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
10777: next;
10778: } else {
10779: my $newpos = $env{'form.ltitools_'.$itemid};
10780: $newpos =~ s/\D+//g;
1.322 ! raeburn 10781: foreach my $item ('title','url','lifetime') {
1.267 raeburn 10782: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
10783: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
10784: $changes{$itemid} = 1;
10785: }
10786: }
1.297 raeburn 10787: foreach my $item ('key','secret') {
10788: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
10789: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
10790: $changes{$itemid} = 1;
10791: }
10792: }
1.267 raeburn 10793: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
10794: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
10795: }
10796: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
10797: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
10798: }
10799: foreach my $size ('width','height') {
10800: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
10801: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
10802: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
10803: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
10804: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10805: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
10806: $changes{$itemid} = 1;
10807: }
10808: } else {
10809: $changes{$itemid} = 1;
10810: }
1.296 raeburn 10811: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10812: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
10813: $changes{$itemid} = 1;
10814: }
10815: }
10816: }
10817: foreach my $item ('linktext','explanation') {
10818: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
10819: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
10820: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
10821: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
10822: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10823: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
10824: $changes{$itemid} = 1;
10825: }
10826: } else {
10827: $changes{$itemid} = 1;
10828: }
10829: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10830: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
10831: $changes{$itemid} = 1;
10832: }
1.267 raeburn 10833: }
10834: }
10835: if ($env{'form.ltitools_target_'.$i} eq 'window') {
10836: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 10837: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
10838: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 10839: } else {
10840: $confhash{$itemid}{'display'}{'target'} = 'iframe';
10841: }
10842: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10843: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
10844: $changes{$itemid} = 1;
10845: }
10846: } else {
10847: $changes{$itemid} = 1;
10848: }
10849: foreach my $extra ('passback','roster') {
10850: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
10851: $confhash{$itemid}{$extra} = 1;
1.319 raeburn 10852: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
10853: my $lifetime = $env{'form.ltitools_'.$extra.'valid_add'};
10854: $lifetime =~ s/^\s+|\s+$//g;
10855: if ($lifetime =~ /^\d+\.?\d*$/) {
10856: $confhash{$itemid}{$extra.'valid'} = $lifetime;
10857: }
10858: }
1.267 raeburn 10859: }
10860: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
10861: $changes{$itemid} = 1;
10862: }
1.319 raeburn 10863: if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
10864: $changes{$itemid} = 1;
10865: }
1.267 raeburn 10866: }
1.273 raeburn 10867: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318 raeburn 10868: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 10869: if (grep(/^\Q$item\E$/,@courseconfig)) {
10870: $confhash{$itemid}{'crsconf'}{$item} = 1;
10871: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
10872: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
10873: $changes{$itemid} = 1;
10874: }
10875: } else {
10876: $changes{$itemid} = 1;
10877: }
10878: }
10879: }
1.267 raeburn 10880: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
10881: foreach my $field (@fields) {
10882: if ($possfield{$field}) {
10883: if ($field eq 'roles') {
10884: foreach my $role (@courseroles) {
10885: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
10886: if (($choice ne '') && ($posslti{$choice})) {
10887: $confhash{$itemid}{'roles'}{$role} = $choice;
10888: if ($role eq 'cc') {
10889: $confhash{$itemid}{'roles'}{'co'} = $choice;
10890: }
10891: }
10892: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
10893: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
10894: $changes{$itemid} = 1;
10895: }
10896: } elsif ($confhash{$itemid}{'roles'}{$role}) {
10897: $changes{$itemid} = 1;
10898: }
10899: }
10900: } else {
10901: $confhash{$itemid}{'fields'}{$field} = 1;
10902: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
10903: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
10904: $changes{$itemid} = 1;
10905: }
10906: } else {
10907: $changes{$itemid} = 1;
10908: }
10909: }
10910: }
10911: }
10912: $allpos[$newpos] = $itemid;
10913: }
10914: if ($imgdeletions{$itemid}) {
10915: $changes{$itemid} = 1;
10916: #FIXME need to obsolete item in RES space
10917: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
10918: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
10919: $itemid,$configuserok,$switchserver,
10920: $author_ok);
10921: if ($imgurl) {
10922: $confhash{$itemid}{'image'} = $imgurl;
10923: $changes{$itemid} = 1;
10924: }
10925: if ($error) {
10926: &Apache::lonnet::logthis($error);
10927: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10928: }
10929: } elsif ($domconfig{$action}{$itemid}{'image'}) {
10930: $confhash{$itemid}{'image'} =
10931: $domconfig{$action}{$itemid}{'image'};
10932: }
10933: if ($customadds{$i}) {
10934: my $name = $env{'form.ltitools_custom_name_'.$i};
10935: $name =~ s/(`)/'/g;
10936: $name =~ s/^\s+//;
10937: $name =~ s/\s+$//;
10938: my $value = $env{'form.ltitools_custom_value_'.$i};
10939: $value =~ s/(`)/'/g;
10940: $value =~ s/^\s+//;
10941: $value =~ s/\s+$//;
10942: if ($name ne '') {
10943: $confhash{$itemid}{'custom'}{$name} = $value;
10944: $changes{$itemid} = 1;
10945: }
10946: }
10947: my %customdels;
10948: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
10949: if (@customdeletions) {
10950: $changes{$itemid} = 1;
10951: }
10952: map { $customdels{$_} = 1; } @customdeletions;
10953: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
10954: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
10955: unless ($customdels{$key}) {
10956: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
10957: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
10958: }
10959: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
10960: $changes{$itemid} = 1;
10961: }
10962: }
10963: }
10964: }
10965: unless ($changes{$itemid}) {
10966: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
10967: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
10968: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
10969: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
10970: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
10971: $changes{$itemid} = 1;
10972: last;
10973: }
10974: }
10975: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
10976: $changes{$itemid} = 1;
10977: }
10978: }
10979: last if ($changes{$itemid});
10980: }
10981: }
10982: }
10983: }
10984: }
10985: if (@allpos > 0) {
10986: my $idx = 0;
10987: foreach my $itemid (@allpos) {
10988: if ($itemid ne '') {
10989: $confhash{$itemid}{'order'} = $idx;
10990: if (ref($domconfig{$action}) eq 'HASH') {
10991: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
10992: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
10993: $changes{$itemid} = 1;
10994: }
10995: }
10996: }
10997: $idx ++;
10998: }
10999: }
11000: }
11001: my %ltitoolshash = (
11002: $action => { %confhash }
11003: );
11004: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
11005: $dom);
11006: if ($putresult eq 'ok') {
1.297 raeburn 11007: my %ltienchash = (
11008: $action => { %encconfig }
11009: );
11010: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
1.267 raeburn 11011: if (keys(%changes) > 0) {
11012: my $cachetime = 24*60*60;
1.297 raeburn 11013: my %ltiall = %confhash;
11014: foreach my $id (keys(%ltiall)) {
11015: if (ref($encconfig{$id}) eq 'HASH') {
11016: foreach my $item ('key','secret') {
11017: $ltiall{$id}{$item} = $encconfig{$id}{$item};
11018: }
11019: }
11020: }
11021: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 11022: if (ref($lastactref) eq 'HASH') {
11023: $lastactref->{'ltitools'} = 1;
11024: }
11025: $resulttext = &mt('Changes made:').'<ul>';
11026: my %bynum;
11027: foreach my $itemid (sort(keys(%changes))) {
11028: my $position = $confhash{$itemid}{'order'};
11029: $bynum{$position} = $itemid;
11030: }
11031: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
11032: my $itemid = $bynum{$pos};
11033: if (ref($confhash{$itemid}) ne 'HASH') {
11034: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
11035: } else {
11036: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
11037: if ($confhash{$itemid}{'image'}) {
11038: $resulttext .= ' '.
11039: '<img src="'.$confhash{$itemid}{'image'}.'"'.
11040: ' alt="'.&mt('Tool Provider icon').'" />';
11041: }
11042: $resulttext .= '</li><ul>';
11043: my $position = $pos + 1;
11044: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.322 ! raeburn 11045: foreach my $item ('version','msgtype','url','lifetime') {
1.267 raeburn 11046: if ($confhash{$itemid}{$item} ne '') {
11047: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
11048: }
11049: }
1.297 raeburn 11050: if ($encconfig{$itemid}{'key'} ne '') {
11051: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
11052: }
11053: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 11054: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 11055: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 11056: $resulttext .= ('*'x$num).'</li>';
11057: }
1.273 raeburn 11058: $resulttext .= '<li>'.&mt('Configurable in course:');
1.318 raeburn 11059: my @possconfig = ('label','title','target','linktext','explanation','append');
1.273 raeburn 11060: my $numconfig = 0;
11061: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
11062: foreach my $item (@possconfig) {
11063: if ($confhash{$itemid}{'crsconf'}{$item}) {
11064: $numconfig ++;
1.296 raeburn 11065: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 11066: }
11067: }
11068: }
11069: if (!$numconfig) {
11070: $resulttext .= &mt('None');
11071: }
11072: $resulttext .= '</li>';
1.267 raeburn 11073: foreach my $item ('passback','roster') {
11074: $resulttext .= '<li>'.$lt{$item}.' ';
11075: if ($confhash{$itemid}{$item}) {
11076: $resulttext .= &mt('Yes');
1.319 raeburn 11077: if ($confhash{$itemid}{$item.'valid'}) {
11078: if ($item eq 'passback') {
11079: $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
11080: $confhash{$itemid}{$item.'valid'});
11081: } else {
11082: $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
11083: $confhash{$itemid}{$item.'valid'});
11084: }
11085: }
1.267 raeburn 11086: } else {
11087: $resulttext .= &mt('No');
11088: }
11089: $resulttext .= '</li>';
11090: }
11091: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
11092: my $displaylist;
11093: if ($confhash{$itemid}{'display'}{'target'}) {
11094: $displaylist = &mt('Display target').': '.
11095: $confhash{$itemid}{'display'}{'target'}.',';
11096: }
11097: foreach my $size ('width','height') {
11098: if ($confhash{$itemid}{'display'}{$size}) {
11099: $displaylist .= (' 'x2).$lt{$size}.': '.
11100: $confhash{$itemid}{'display'}{$size}.',';
11101: }
11102: }
11103: if ($displaylist) {
11104: $displaylist =~ s/,$//;
11105: $resulttext .= '<li>'.$displaylist.'</li>';
11106: }
1.296 raeburn 11107: foreach my $item ('linktext','explanation') {
11108: if ($confhash{$itemid}{'display'}{$item}) {
11109: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
11110: }
11111: }
11112: }
1.267 raeburn 11113: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
11114: my $fieldlist;
11115: foreach my $field (@allfields) {
11116: if ($confhash{$itemid}{'fields'}{$field}) {
11117: $fieldlist .= (' 'x2).$lt{$field}.',';
11118: }
11119: }
11120: if ($fieldlist) {
11121: $fieldlist =~ s/,$//;
11122: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
11123: }
11124: }
11125: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
11126: my $rolemaps;
11127: foreach my $role (@courseroles) {
11128: if ($confhash{$itemid}{'roles'}{$role}) {
11129: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
11130: $confhash{$itemid}{'roles'}{$role}.',';
11131: }
11132: }
11133: if ($rolemaps) {
11134: $rolemaps =~ s/,$//;
11135: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
11136: }
11137: }
11138: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
11139: my $customlist;
11140: if (keys(%{$confhash{$itemid}{'custom'}})) {
11141: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
11142: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
11143: }
11144: }
11145: if ($customlist) {
1.317 raeburn 11146: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267 raeburn 11147: }
11148: }
11149: $resulttext .= '</ul></li>';
11150: }
11151: }
11152: $resulttext .= '</ul>';
11153: } else {
11154: $resulttext = &mt('No changes made.');
11155: }
11156: } else {
11157: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
11158: }
11159: if ($errors) {
11160: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11161: $errors.'</ul>';
11162: }
11163: return $resulttext;
11164: }
11165:
11166: sub process_ltitools_image {
11167: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
11168: my $filename = $env{'form.'.$caller.'.filename'};
11169: my ($error,$url);
11170: my ($width,$height) = (21,21);
11171: if ($configuserok eq 'ok') {
11172: if ($switchserver) {
11173: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
11174: $switchserver);
11175: } elsif ($author_ok eq 'ok') {
11176: my ($result,$imageurl,$madethumb) =
11177: &publishlogo($r,'upload',$caller,$dom,$confname,
11178: "ltitools/$itemid/icon",$width,$height);
11179: if ($result eq 'ok') {
11180: if ($madethumb) {
11181: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
11182: my $imagethumb = "$path/tn-".$imagefile;
11183: $url = $imagethumb;
11184: } else {
11185: $url = $imageurl;
11186: }
11187: } else {
11188: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
11189: }
11190: } else {
11191: $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);
11192: }
11193: } else {
11194: $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);
11195: }
11196: return ($url,$error);
11197: }
11198:
11199: sub get_ltitools_id {
11200: my ($cdom,$title) = @_;
11201: # get lock on ltitools db
11202: my $lockhash = {
11203: lock => $env{'user.name'}.
11204: ':'.$env{'user.domain'},
11205: };
11206: my $tries = 0;
11207: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
11208: my ($id,$error);
11209:
11210: while (($gotlock ne 'ok') && ($tries<10)) {
11211: $tries ++;
11212: sleep (0.1);
11213: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
11214: }
11215: if ($gotlock eq 'ok') {
11216: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
11217: if ($currids{'lock'}) {
11218: delete($currids{'lock'});
11219: if (keys(%currids)) {
11220: my @curr = sort { $a <=> $b } keys(%currids);
11221: if ($curr[-1] =~ /^\d+$/) {
11222: $id = 1 + $curr[-1];
11223: }
11224: } else {
11225: $id = 1;
11226: }
11227: if ($id) {
11228: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
11229: $error = 'nostore';
11230: }
11231: } else {
11232: $error = 'nonumber';
11233: }
11234: }
11235: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
11236: } else {
11237: $error = 'nolock';
11238: }
11239: return ($id,$error);
11240: }
11241:
1.320 raeburn 11242: sub modify_lti {
11243: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
11244: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11245: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
11246: my (%posslti,%posslticrs,%posscrstype);
11247: my @courseroles = ('cc','in','ta','ep','st');
11248: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
11249: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
11250: my @coursetypes = ('official','unofficial','community','textbook','placement');
11251: my %coursetypetitles = &Apache::lonlocal::texthash (
11252: official => 'Official',
11253: unofficial => 'Unofficial',
11254: community => 'Community',
11255: textbook => 'Textbook',
11256: placement => 'Placement Test',
11257: );
11258: my %lt = <i_names();
11259: map { $posslti{$_} = 1; } @ltiroles;
11260: map { $posslticrs{$_} = 1; } @lticourseroles;
11261: map { $posscrstype{$_} = 1; } @coursetypes;
11262:
11263: my (@items,%deletions,%itemids);
11264: if ($env{'form.lti_add'}) {
11265: my $consumer = $env{'form.lti_consumer_add'};
11266: $consumer =~ s/(`)/'/g;
11267: ($newid,my $error) = &get_lti_id($dom,$consumer);
11268: if ($newid) {
11269: $itemids{'add'} = $newid;
11270: push(@items,'add');
11271: $changes{$newid} = 1;
11272: } else {
11273: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
11274: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11275: }
11276: }
11277: if (ref($domconfig{$action}) eq 'HASH') {
11278: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
11279: if (@todelete) {
11280: map { $deletions{$_} = 1; } @todelete;
11281: }
11282: my $maxnum = $env{'form.lti_maxnum'};
11283: for (my $i=0; $i<=$maxnum; $i++) {
11284: my $itemid = $env{'form.lti_id_'.$i};
11285: $itemid =~ s/\D+//g;
11286: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11287: if ($deletions{$itemid}) {
11288: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
11289: } else {
11290: push(@items,$i);
11291: $itemids{$i} = $itemid;
11292: }
11293: }
11294: }
11295: }
11296: foreach my $idx (@items) {
11297: my $itemid = $itemids{$idx};
11298: next unless ($itemid);
11299: my $position = $env{'form.lti_pos_'.$idx};
11300: $position =~ s/\D+//g;
11301: if ($position ne '') {
11302: $allpos[$position] = $itemid;
11303: }
11304: foreach my $item ('consumer','key','secret','lifetime') {
11305: my $formitem = 'form.lti_'.$item.'_'.$idx;
11306: $env{$formitem} =~ s/(`)/'/g;
11307: if ($item eq 'lifetime') {
11308: $env{$formitem} =~ s/[^\d.]//g;
11309: }
11310: if ($env{$formitem} ne '') {
11311: if (($item eq 'key') || ($item eq 'secret')) {
11312: $encconfig{$itemid}{$item} = $env{$formitem};
11313: } else {
11314: $confhash{$itemid}{$item} = $env{$formitem};
11315: unless (($idx eq 'add') || ($changes{$itemid})) {
11316: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
11317: $changes{$itemid} = 1;
11318: }
11319: }
11320: }
11321: }
11322: }
11323: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
11324: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
11325: }
11326: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
11327: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
11328: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
11329: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
11330: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
11331: my $mapuser = $env{'form.lti_customuser_'.$idx};
11332: $mapuser =~ s/(`)/'/g;
11333: $mapuser =~ s/^\s+|\s+$//g;
11334: $confhash{$itemid}{'mapuser'} = $mapuser;
11335: }
11336: foreach my $ltirole (@lticourseroles) {
11337: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
11338: if (grep(/^\Q$possrole\E$/,@courseroles)) {
11339: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
11340: }
11341: }
11342: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
11343: my @makeuser;
11344: foreach my $ltirole (sort(@possmakeuser)) {
11345: if ($posslti{$ltirole}) {
11346: push(@makeuser,$ltirole);
11347: }
11348: }
11349: $confhash{$itemid}{'makeuser'} = \@makeuser;
11350: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
11351: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
11352: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
11353: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
11354: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
11355: $mapcrs =~ s/(`)/'/g;
11356: $mapcrs =~ s/^\s+|\s+$//g;
11357: $confhash{$itemid}{'mapcrs'} = $mapcrs;
11358: }
11359: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
11360: my @crstypes;
11361: foreach my $type (sort(@posstypes)) {
11362: if ($posscrstype{$type}) {
11363: push(@crstypes,$type);
11364: }
11365: }
11366: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
11367: if ($env{'form.lti_makecrs_'.$idx}) {
11368: $confhash{$itemid}{'makecrs'} = 1;
11369: }
11370: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
11371: my @selfenroll;
11372: foreach my $type (sort(@possenroll)) {
11373: if ($posslticrs{$type}) {
11374: push(@selfenroll,$type);
11375: }
11376: }
11377: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
11378: if ($env{'form.lti_crssec_'.$idx}) {
11379: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
11380: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
11381: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
11382: my $section = $env{'form.lti_customsection_'.$idx};
11383: $section =~ s/(`)/'/g;
11384: $section =~ s/^\s+|\s+$//g;
11385: if ($section ne '') {
11386: $confhash{$itemid}{'section'} = $section;
11387: }
11388: }
11389: }
11390: foreach my $field ('passback','roster') {
1.321 raeburn 11391: if ($env{'form.lti_'.$field.'_'.$idx}) {
1.320 raeburn 11392: $confhash{$itemid}{$field} = 1;
11393: }
11394: }
11395: unless (($idx eq 'add') || ($changes{$itemid})) {
11396: foreach my $field ('mapuser','mapcrs','section','passback','roster') {
11397: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
11398: $changes{$itemid} = 1;
11399: }
11400: }
11401: foreach my $field ('makeuser','mapcrstype','selfenroll') {
11402: unless ($changes{$itemid}) {
11403: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
11404: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
11405: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
11406: $confhash{$itemid}{$field});
11407: if (@diffs) {
11408: $changes{$itemid} = 1;
11409: }
11410: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
11411: $changes{$itemid} = 1;
11412: }
11413: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
11414: if (@{$confhash{$itemid}{$field}} > 0) {
11415: $changes{$itemid} = 1;
11416: }
11417: }
11418: }
11419: }
11420: unless ($changes{$itemid}) {
11421: if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
11422: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
11423: foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
11424: if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne
11425: $confhash{$itemid}{'maproles'}{$ltirole}) {
11426: $changes{$itemid} = 1;
11427: last;
11428: }
11429: }
11430: unless ($changes{$itemid}) {
11431: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
11432: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
11433: $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
11434: $changes{$itemid} = 1;
11435: last;
11436: }
11437: }
11438: }
11439: } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
11440: $changes{$itemid} = 1;
11441: }
11442: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
11443: unless ($changes{$itemid}) {
11444: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
11445: $changes{$itemid} = 1;
11446: }
11447: }
11448: }
11449: }
11450: }
11451: }
11452: if (@allpos > 0) {
11453: my $idx = 0;
11454: foreach my $itemid (@allpos) {
11455: if ($itemid ne '') {
11456: $confhash{$itemid}{'order'} = $idx;
11457: if (ref($domconfig{$action}) eq 'HASH') {
11458: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11459: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
11460: $changes{$itemid} = 1;
11461: }
11462: }
11463: }
11464: $idx ++;
11465: }
11466: }
11467: }
11468: my %ltihash = (
11469: $action => { %confhash }
11470: );
11471: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,
11472: $dom);
11473: if ($putresult eq 'ok') {
11474: my %ltienchash = (
11475: $action => { %encconfig }
11476: );
11477: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
11478: if (keys(%changes) > 0) {
11479: my $cachetime = 24*60*60;
11480: my %ltiall = %confhash;
11481: foreach my $id (keys(%ltiall)) {
11482: if (ref($encconfig{$id}) eq 'HASH') {
11483: foreach my $item ('key','secret') {
11484: $ltiall{$id}{$item} = $encconfig{$id}{$item};
11485: }
11486: }
11487: }
11488: &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
11489: if (ref($lastactref) eq 'HASH') {
11490: $lastactref->{'lti'} = 1;
11491: }
11492: $resulttext = &mt('Changes made:').'<ul>';
11493: my %bynum;
11494: foreach my $itemid (sort(keys(%changes))) {
11495: my $position = $confhash{$itemid}{'order'};
11496: $bynum{$position} = $itemid;
11497: }
11498: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
11499: my $itemid = $bynum{$pos};
11500: if (ref($confhash{$itemid}) ne 'HASH') {
11501: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
11502: } else {
11503: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b></li><ul>';
11504: my $position = $pos + 1;
11505: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
11506: foreach my $item ('version','lifetime') {
11507: if ($confhash{$itemid}{$item} ne '') {
11508: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
11509: }
11510: }
11511: if ($encconfig{$itemid}{'key'} ne '') {
11512: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
11513: }
11514: if ($encconfig{$itemid}{'secret'} ne '') {
11515: $resulttext .= '<li>'.$lt{'secret'}.': ';
11516: my $num = length($encconfig{$itemid}{'secret'});
11517: $resulttext .= ('*'x$num).'</li>';
11518: }
11519: if ($confhash{$itemid}{'mapuser'}) {
11520: my $shownmapuser;
11521: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
11522: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
11523: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
11524: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
11525: } else {
11526: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
11527: }
11528: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
11529: }
11530: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
11531: my $rolemaps;
11532: foreach my $role (@ltiroles) {
11533: if ($confhash{$itemid}{'maproles'}{$role}) {
11534: $rolemaps .= (' 'x2).$role.'='.
11535: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
11536: 'Course').',';
11537: }
11538: }
11539: if ($rolemaps) {
11540: $rolemaps =~ s/,$//;
11541: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
11542: }
11543: }
11544: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
11545: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
11546: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
11547: join(', ',@{$confhash{$itemid}{'makeuser'}})).'</li>';
11548: } else {
11549: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
11550: }
11551: }
11552: if ($confhash{$itemid}{'mapcrs'}) {
11553: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
11554: }
11555: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
11556: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
11557: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
11558: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
11559: '</li>';
11560: } else {
11561: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
11562: }
11563: }
11564: if ($confhash{$itemid}{'makecrs'}) {
11565: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
11566: } else {
11567: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
11568: }
11569: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
11570: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
11571: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
11572: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
11573: '</li>';
11574: } else {
11575: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
11576: }
11577: }
11578: if ($confhash{$itemid}{'section'}) {
11579: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
11580: $resulttext .= '<li>'.&mt('User section from standard field:').
11581: ' (course_section_sourcedid)'.'</li>';
11582: } else {
11583: $resulttext .= '<li>'.&mt('User section from:').' '.
11584: $confhash{$itemid}{'section'}.'</li>';
11585: }
11586: } else {
11587: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
11588: }
11589: foreach my $item ('passback','roster') {
11590: $resulttext .= '<li>'.$lt{$item}.' ';
11591: if ($confhash{$itemid}{$item}) {
11592: $resulttext .= &mt('Yes');
11593: } else {
11594: $resulttext .= &mt('No');
11595: }
11596: $resulttext .= '</li>';
11597: }
11598: $resulttext .= '</ul></li>';
11599: }
11600: }
11601: $resulttext .= '</ul>';
11602: } else {
11603: $resulttext = &mt('No changes made.');
11604: }
11605: } else {
11606: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
11607: }
11608: if ($errors) {
11609: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11610: $errors.'</ul>';
11611: }
11612: return $resulttext;
11613: }
11614:
11615: sub get_lti_id {
11616: my ($domain,$consumer) = @_;
11617: # get lock on lti db
11618: my $lockhash = {
11619: lock => $env{'user.name'}.
11620: ':'.$env{'user.domain'},
11621: };
11622: my $tries = 0;
11623: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
11624: my ($id,$error);
11625:
11626: while (($gotlock ne 'ok') && ($tries<10)) {
11627: $tries ++;
11628: sleep (0.1);
11629: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
11630: }
11631: if ($gotlock eq 'ok') {
11632: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
11633: if ($currids{'lock'}) {
11634: delete($currids{'lock'});
11635: if (keys(%currids)) {
11636: my @curr = sort { $a <=> $b } keys(%currids);
11637: if ($curr[-1] =~ /^\d+$/) {
11638: $id = 1 + $curr[-1];
11639: }
11640: } else {
11641: $id = 1;
11642: }
11643: if ($id) {
11644: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
11645: $error = 'nostore';
11646: }
11647: } else {
11648: $error = 'nonumber';
11649: }
11650: }
11651: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
11652: } else {
11653: $error = 'nolock';
11654: }
11655: return ($id,$error);
11656: }
11657:
1.3 raeburn 11658: sub modify_autoenroll {
1.205 raeburn 11659: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 11660: my ($resulttext,%changes);
11661: my %currautoenroll;
11662: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
11663: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
11664: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
11665: }
11666: }
11667: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
11668: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 11669: sender => 'Sender for notification messages',
1.274 raeburn 11670: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
11671: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 11672: my @offon = ('off','on');
1.17 raeburn 11673: my $sender_uname = $env{'form.sender_uname'};
11674: my $sender_domain = $env{'form.sender_domain'};
11675: if ($sender_domain eq '') {
11676: $sender_uname = '';
11677: } elsif ($sender_uname eq '') {
11678: $sender_domain = '';
11679: }
1.129 raeburn 11680: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 11681: my $failsafe = $env{'form.autoenroll_failsafe'};
11682: $failsafe =~ s{^\s+|\s+$}{}g;
11683: if ($failsafe =~ /\D/) {
11684: undef($failsafe);
11685: }
1.1 raeburn 11686: my %autoenrollhash = (
1.129 raeburn 11687: autoenroll => { 'run' => $env{'form.autoenroll_run'},
11688: 'sender_uname' => $sender_uname,
11689: 'sender_domain' => $sender_domain,
11690: 'co-owners' => $coowners,
1.274 raeburn 11691: 'autofailsafe' => $failsafe,
1.1 raeburn 11692: }
11693: );
1.4 raeburn 11694: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
11695: $dom);
1.1 raeburn 11696: if ($putresult eq 'ok') {
11697: if (exists($currautoenroll{'run'})) {
11698: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
11699: $changes{'run'} = 1;
11700: }
11701: } elsif ($autorun) {
11702: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 11703: $changes{'run'} = 1;
1.1 raeburn 11704: }
11705: }
1.17 raeburn 11706: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 11707: $changes{'sender'} = 1;
11708: }
1.17 raeburn 11709: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 11710: $changes{'sender'} = 1;
11711: }
1.129 raeburn 11712: if ($currautoenroll{'co-owners'} ne '') {
11713: if ($currautoenroll{'co-owners'} ne $coowners) {
11714: $changes{'coowners'} = 1;
11715: }
11716: } elsif ($coowners) {
11717: $changes{'coowners'} = 1;
1.274 raeburn 11718: }
11719: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
11720: $changes{'autofailsafe'} = 1;
11721: }
1.1 raeburn 11722: if (keys(%changes) > 0) {
11723: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 11724: if ($changes{'run'}) {
1.1 raeburn 11725: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
11726: }
11727: if ($changes{'sender'}) {
1.17 raeburn 11728: if ($sender_uname eq '' || $sender_domain eq '') {
11729: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
11730: } else {
11731: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
11732: }
1.1 raeburn 11733: }
1.129 raeburn 11734: if ($changes{'coowners'}) {
11735: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
11736: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 11737: if (ref($lastactref) eq 'HASH') {
11738: $lastactref->{'domainconfig'} = 1;
11739: }
1.129 raeburn 11740: }
1.274 raeburn 11741: if ($changes{'autofailsafe'}) {
11742: if ($failsafe ne '') {
1.299 raeburn 11743: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274 raeburn 11744: } else {
1.299 raeburn 11745: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274 raeburn 11746: }
11747: &Apache::lonnet::get_domain_defaults($dom,1);
11748: if (ref($lastactref) eq 'HASH') {
11749: $lastactref->{'domdefaults'} = 1;
11750: }
11751: }
1.1 raeburn 11752: $resulttext .= '</ul>';
11753: } else {
11754: $resulttext = &mt('No changes made to auto-enrollment settings');
11755: }
11756: } else {
1.11 albertel 11757: $resulttext = '<span class="LC_error">'.
11758: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11759: }
1.3 raeburn 11760: return $resulttext;
1.1 raeburn 11761: }
11762:
11763: sub modify_autoupdate {
1.3 raeburn 11764: my ($dom,%domconfig) = @_;
1.1 raeburn 11765: my ($resulttext,%currautoupdate,%fields,%changes);
11766: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
11767: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
11768: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
11769: }
11770: }
11771: my @offon = ('off','on');
11772: my %title = &Apache::lonlocal::texthash (
11773: run => 'Auto-update:',
11774: classlists => 'Updates to user information in classlists?'
11775: );
1.44 raeburn 11776: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 11777: my %fieldtitles = &Apache::lonlocal::texthash (
11778: id => 'Student/Employee ID',
1.20 raeburn 11779: permanentemail => 'E-mail address',
1.1 raeburn 11780: lastname => 'Last Name',
11781: firstname => 'First Name',
11782: middlename => 'Middle Name',
1.132 raeburn 11783: generation => 'Generation',
1.1 raeburn 11784: );
1.142 raeburn 11785: $othertitle = &mt('All users');
1.1 raeburn 11786: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 11787: $othertitle = &mt('Other users');
1.1 raeburn 11788: }
11789: foreach my $key (keys(%env)) {
11790: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 11791: my ($usertype,$item) = ($1,$2);
11792: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
11793: if ($usertype eq 'default') {
11794: push(@{$fields{$1}},$2);
11795: } elsif (ref($types) eq 'ARRAY') {
11796: if (grep(/^\Q$usertype\E$/,@{$types})) {
11797: push(@{$fields{$1}},$2);
11798: }
11799: }
11800: }
1.1 raeburn 11801: }
11802: }
1.131 raeburn 11803: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
11804: @lockablenames = sort(@lockablenames);
11805: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
11806: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
11807: if (@changed) {
11808: $changes{'lockablenames'} = 1;
11809: }
11810: } else {
11811: if (@lockablenames) {
11812: $changes{'lockablenames'} = 1;
11813: }
11814: }
1.1 raeburn 11815: my %updatehash = (
11816: autoupdate => { run => $env{'form.autoupdate_run'},
11817: classlists => $env{'form.classlists'},
11818: fields => {%fields},
1.131 raeburn 11819: lockablenames => \@lockablenames,
1.1 raeburn 11820: }
11821: );
11822: foreach my $key (keys(%currautoupdate)) {
11823: if (($key eq 'run') || ($key eq 'classlists')) {
11824: if (exists($updatehash{autoupdate}{$key})) {
11825: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
11826: $changes{$key} = 1;
11827: }
11828: }
11829: } elsif ($key eq 'fields') {
11830: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 11831: foreach my $item (@{$types},'default') {
1.1 raeburn 11832: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
11833: my $change = 0;
11834: foreach my $type (@{$currautoupdate{$key}{$item}}) {
11835: if (!exists($fields{$item})) {
11836: $change = 1;
1.132 raeburn 11837: last;
1.1 raeburn 11838: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 11839: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 11840: $change = 1;
1.132 raeburn 11841: last;
1.1 raeburn 11842: }
11843: }
11844: }
11845: if ($change) {
11846: push(@{$changes{$key}},$item);
11847: }
1.26 raeburn 11848: }
1.1 raeburn 11849: }
11850: }
1.131 raeburn 11851: } elsif ($key eq 'lockablenames') {
11852: if (ref($currautoupdate{$key}) eq 'ARRAY') {
11853: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
11854: if (@changed) {
11855: $changes{'lockablenames'} = 1;
11856: }
11857: } else {
11858: if (@lockablenames) {
11859: $changes{'lockablenames'} = 1;
11860: }
11861: }
11862: }
11863: }
11864: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
11865: if (@lockablenames) {
11866: $changes{'lockablenames'} = 1;
1.1 raeburn 11867: }
11868: }
1.26 raeburn 11869: foreach my $item (@{$types},'default') {
11870: if (defined($fields{$item})) {
11871: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 11872: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
11873: my $change = 0;
11874: if (ref($fields{$item}) eq 'ARRAY') {
11875: foreach my $type (@{$fields{$item}}) {
11876: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
11877: $change = 1;
11878: last;
11879: }
11880: }
11881: }
11882: if ($change) {
11883: push(@{$changes{'fields'}},$item);
11884: }
11885: } else {
1.26 raeburn 11886: push(@{$changes{'fields'}},$item);
11887: }
11888: } else {
11889: push(@{$changes{'fields'}},$item);
1.1 raeburn 11890: }
11891: }
11892: }
11893: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
11894: $dom);
11895: if ($putresult eq 'ok') {
11896: if (keys(%changes) > 0) {
11897: $resulttext = &mt('Changes made:').'<ul>';
11898: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 11899: if ($key eq 'lockablenames') {
11900: $resulttext .= '<li>';
11901: if (@lockablenames) {
11902: $usertypes->{'default'} = $othertitle;
11903: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
11904: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
11905: } else {
11906: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
11907: }
11908: $resulttext .= '</li>';
11909: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 11910: foreach my $item (@{$changes{$key}}) {
11911: my @newvalues;
11912: foreach my $type (@{$fields{$item}}) {
11913: push(@newvalues,$fieldtitles{$type});
11914: }
1.3 raeburn 11915: my $newvaluestr;
11916: if (@newvalues > 0) {
11917: $newvaluestr = join(', ',@newvalues);
11918: } else {
11919: $newvaluestr = &mt('none');
1.6 raeburn 11920: }
1.1 raeburn 11921: if ($item eq 'default') {
1.26 raeburn 11922: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 11923: } else {
1.26 raeburn 11924: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 11925: }
11926: }
11927: } else {
11928: my $newvalue;
11929: if ($key eq 'run') {
11930: $newvalue = $offon[$env{'form.autoupdate_run'}];
11931: } else {
11932: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 11933: }
1.1 raeburn 11934: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
11935: }
11936: }
11937: $resulttext .= '</ul>';
11938: } else {
1.3 raeburn 11939: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 11940: }
11941: } else {
1.11 albertel 11942: $resulttext = '<span class="LC_error">'.
11943: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11944: }
1.3 raeburn 11945: return $resulttext;
1.1 raeburn 11946: }
11947:
1.125 raeburn 11948: sub modify_autocreate {
11949: my ($dom,%domconfig) = @_;
11950: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
11951: if (ref($domconfig{'autocreate'}) eq 'HASH') {
11952: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
11953: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
11954: }
11955: }
11956: my %title= ( xml => 'Auto-creation of courses in XML course description files',
11957: req => 'Auto-creation of validated requests for official courses',
11958: xmldc => 'Identity of course creator of courses from XML files',
11959: );
11960: my @types = ('xml','req');
11961: foreach my $item (@types) {
11962: $newvals{$item} = $env{'form.autocreate_'.$item};
11963: $newvals{$item} =~ s/\D//g;
11964: $newvals{$item} = 0 if ($newvals{$item} eq '');
11965: }
11966: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 11967: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 11968: unless (exists($domcoords{$newvals{'xmldc'}})) {
11969: $newvals{'xmldc'} = '';
11970: }
11971: %autocreatehash = (
11972: autocreate => { xml => $newvals{'xml'},
11973: req => $newvals{'req'},
11974: }
11975: );
11976: if ($newvals{'xmldc'} ne '') {
11977: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
11978: }
11979: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
11980: $dom);
11981: if ($putresult eq 'ok') {
11982: my @items = @types;
11983: if ($newvals{'xml'}) {
11984: push(@items,'xmldc');
11985: }
11986: foreach my $item (@items) {
11987: if (exists($currautocreate{$item})) {
11988: if ($currautocreate{$item} ne $newvals{$item}) {
11989: $changes{$item} = 1;
11990: }
11991: } elsif ($newvals{$item}) {
11992: $changes{$item} = 1;
11993: }
11994: }
11995: if (keys(%changes) > 0) {
11996: my @offon = ('off','on');
11997: $resulttext = &mt('Changes made:').'<ul>';
11998: foreach my $item (@types) {
11999: if ($changes{$item}) {
12000: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 12001: $resulttext .= '<li>'.
12002: &mt("$title{$item} set to [_1]$newtxt [_2]",
12003: '<b>','</b>').
12004: '</li>';
1.125 raeburn 12005: }
12006: }
12007: if ($changes{'xmldc'}) {
12008: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
12009: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 12010: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 12011: }
12012: $resulttext .= '</ul>';
12013: } else {
12014: $resulttext = &mt('No changes made to auto-creation settings');
12015: }
12016: } else {
12017: $resulttext = '<span class="LC_error">'.
12018: &mt('An error occurred: [_1]',$putresult).'</span>';
12019: }
12020: return $resulttext;
12021: }
12022:
1.23 raeburn 12023: sub modify_directorysrch {
1.295 raeburn 12024: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 12025: my ($resulttext,%changes);
12026: my %currdirsrch;
12027: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
12028: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
12029: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
12030: }
12031: }
1.277 raeburn 12032: my %title = ( available => 'Institutional directory search available',
12033: localonly => 'Other domains can search institution',
12034: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 12035: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 12036: searchby => 'Search types',
12037: searchtypes => 'Search latitude');
12038: my @offon = ('off','on');
1.24 raeburn 12039: my @otherdoms = ('Yes','No');
1.23 raeburn 12040:
1.25 raeburn 12041: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 12042: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
12043: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
12044:
1.44 raeburn 12045: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 12046: if (keys(%{$usertypes}) == 0) {
12047: @cansearch = ('default');
12048: } else {
12049: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
12050: foreach my $type (@{$currdirsrch{'cansearch'}}) {
12051: if (!grep(/^\Q$type\E$/,@cansearch)) {
12052: push(@{$changes{'cansearch'}},$type);
12053: }
1.23 raeburn 12054: }
1.26 raeburn 12055: foreach my $type (@cansearch) {
12056: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
12057: push(@{$changes{'cansearch'}},$type);
12058: }
1.23 raeburn 12059: }
1.26 raeburn 12060: } else {
12061: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 12062: }
12063: }
12064:
12065: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
12066: foreach my $by (@{$currdirsrch{'searchby'}}) {
12067: if (!grep(/^\Q$by\E$/,@searchby)) {
12068: push(@{$changes{'searchby'}},$by);
12069: }
12070: }
12071: foreach my $by (@searchby) {
12072: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
12073: push(@{$changes{'searchby'}},$by);
12074: }
12075: }
12076: } else {
12077: push(@{$changes{'searchby'}},@searchby);
12078: }
1.25 raeburn 12079:
12080: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
12081: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
12082: if (!grep(/^\Q$type\E$/,@searchtypes)) {
12083: push(@{$changes{'searchtypes'}},$type);
12084: }
12085: }
12086: foreach my $type (@searchtypes) {
12087: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
12088: push(@{$changes{'searchtypes'}},$type);
12089: }
12090: }
12091: } else {
12092: if (exists($currdirsrch{'searchtypes'})) {
12093: foreach my $type (@searchtypes) {
12094: if ($type ne $currdirsrch{'searchtypes'}) {
12095: push(@{$changes{'searchtypes'}},$type);
12096: }
12097: }
12098: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
12099: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
12100: }
12101: } else {
12102: push(@{$changes{'searchtypes'}},@searchtypes);
12103: }
12104: }
12105:
1.23 raeburn 12106: my %dirsrch_hash = (
12107: directorysrch => { available => $env{'form.dirsrch_available'},
12108: cansearch => \@cansearch,
1.277 raeburn 12109: localonly => $env{'form.dirsrch_instlocalonly'},
12110: lclocalonly => $env{'form.dirsrch_domlocalonly'},
12111: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 12112: searchby => \@searchby,
1.25 raeburn 12113: searchtypes => \@searchtypes,
1.23 raeburn 12114: }
12115: );
12116: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
12117: $dom);
12118: if ($putresult eq 'ok') {
12119: if (exists($currdirsrch{'available'})) {
12120: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
12121: $changes{'available'} = 1;
12122: }
12123: } else {
12124: if ($env{'form.dirsrch_available'} eq '1') {
12125: $changes{'available'} = 1;
12126: }
12127: }
1.277 raeburn 12128: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 12129: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
12130: $changes{'lcavailable'} = 1;
12131: }
1.277 raeburn 12132: } else {
12133: if ($env{'form.dirsrch_lcavailable'} eq '1') {
12134: $changes{'lcavailable'} = 1;
12135: }
12136: }
1.24 raeburn 12137: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 12138: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
12139: $changes{'localonly'} = 1;
12140: }
1.24 raeburn 12141: } else {
1.277 raeburn 12142: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 12143: $changes{'localonly'} = 1;
12144: }
12145: }
1.277 raeburn 12146: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 12147: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
12148: $changes{'lclocalonly'} = 1;
12149: }
1.277 raeburn 12150: } else {
12151: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
12152: $changes{'lclocalonly'} = 1;
12153: }
12154: }
1.23 raeburn 12155: if (keys(%changes) > 0) {
12156: $resulttext = &mt('Changes made:').'<ul>';
12157: if ($changes{'available'}) {
12158: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
12159: }
1.277 raeburn 12160: if ($changes{'lcavailable'}) {
12161: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
12162: }
1.24 raeburn 12163: if ($changes{'localonly'}) {
1.277 raeburn 12164: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 12165: }
1.277 raeburn 12166: if ($changes{'lclocalonly'}) {
12167: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 12168: }
1.23 raeburn 12169: if (ref($changes{'cansearch'}) eq 'ARRAY') {
12170: my $chgtext;
1.26 raeburn 12171: if (ref($usertypes) eq 'HASH') {
12172: if (keys(%{$usertypes}) > 0) {
12173: foreach my $type (@{$types}) {
12174: if (grep(/^\Q$type\E$/,@cansearch)) {
12175: $chgtext .= $usertypes->{$type}.'; ';
12176: }
12177: }
12178: if (grep(/^default$/,@cansearch)) {
12179: $chgtext .= $othertitle;
12180: } else {
12181: $chgtext =~ s/\; $//;
12182: }
1.210 raeburn 12183: $resulttext .=
1.178 raeburn 12184: '<li>'.
12185: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
12186: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
12187: '</li>';
1.23 raeburn 12188: }
12189: }
12190: }
12191: if (ref($changes{'searchby'}) eq 'ARRAY') {
12192: my ($searchtitles,$titleorder) = &sorted_searchtitles();
12193: my $chgtext;
12194: foreach my $type (@{$titleorder}) {
12195: if (grep(/^\Q$type\E$/,@searchby)) {
12196: if (defined($searchtitles->{$type})) {
12197: $chgtext .= $searchtitles->{$type}.'; ';
12198: }
12199: }
12200: }
12201: $chgtext =~ s/\; $//;
12202: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
12203: }
1.25 raeburn 12204: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
12205: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
12206: my $chgtext;
12207: foreach my $type (@{$srchtypeorder}) {
12208: if (grep(/^\Q$type\E$/,@searchtypes)) {
12209: if (defined($srchtypes_desc->{$type})) {
12210: $chgtext .= $srchtypes_desc->{$type}.'; ';
12211: }
12212: }
12213: }
12214: $chgtext =~ s/\; $//;
1.178 raeburn 12215: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 12216: }
12217: $resulttext .= '</ul>';
1.295 raeburn 12218: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
12219: if (ref($lastactref) eq 'HASH') {
12220: $lastactref->{'directorysrch'} = 1;
12221: }
1.23 raeburn 12222: } else {
1.277 raeburn 12223: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 12224: }
12225: } else {
12226: $resulttext = '<span class="LC_error">'.
1.27 raeburn 12227: &mt('An error occurred: [_1]',$putresult).'</span>';
12228: }
12229: return $resulttext;
12230: }
12231:
1.28 raeburn 12232: sub modify_contacts {
1.205 raeburn 12233: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 12234: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
12235: if (ref($domconfig{'contacts'}) eq 'HASH') {
12236: foreach my $key (keys(%{$domconfig{'contacts'}})) {
12237: $currsetting{$key} = $domconfig{'contacts'}{$key};
12238: }
12239: }
1.286 raeburn 12240: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 12241: my @contacts = ('supportemail','adminemail');
1.286 raeburn 12242: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
12243: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.203 raeburn 12244: my @toggles = ('reporterrors','reportupdates');
1.286 raeburn 12245: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 12246: foreach my $type (@mailings) {
12247: @{$newsetting{$type}} =
12248: &Apache::loncommon::get_env_multiple('form.'.$type);
12249: foreach my $item (@contacts) {
12250: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
12251: $contacts_hash{contacts}{$type}{$item} = 1;
12252: } else {
12253: $contacts_hash{contacts}{$type}{$item} = 0;
12254: }
1.289 raeburn 12255: }
1.28 raeburn 12256: $others{$type} = $env{'form.'.$type.'_others'};
12257: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 12258: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12259: $bcc{$type} = $env{'form.'.$type.'_bcc'};
12260: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 12261: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
12262: $includestr{$type} = $env{'form.'.$type.'_includestr'};
12263: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
12264: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
12265: }
1.134 raeburn 12266: }
1.28 raeburn 12267: }
12268: foreach my $item (@contacts) {
12269: $to{$item} = $env{'form.'.$item};
12270: $contacts_hash{'contacts'}{$item} = $to{$item};
12271: }
1.203 raeburn 12272: foreach my $item (@toggles) {
12273: if ($env{'form.'.$item} =~ /^(0|1)$/) {
12274: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
12275: }
12276: }
1.286 raeburn 12277: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
12278: foreach my $field (@{$fields}) {
12279: if (ref($possoptions->{$field}) eq 'ARRAY') {
12280: my $value = $env{'form.helpform_'.$field};
12281: $value =~ s/^\s+|\s+$//g;
12282: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 12283: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 12284: if ($field eq 'screenshot') {
12285: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
12286: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 12287: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 12288: }
12289: }
12290: }
12291: }
12292: }
12293: }
1.315 raeburn 12294: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12295: my (@statuses,%usertypeshash,@overrides);
12296: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
12297: @statuses = @{$types};
12298: if (ref($usertypes) eq 'HASH') {
12299: %usertypeshash = %{$usertypes};
12300: }
12301: }
12302: if (@statuses) {
12303: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
12304: foreach my $type (@possoverrides) {
12305: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
12306: push(@overrides,$type);
12307: }
12308: }
12309: if (@overrides) {
12310: foreach my $type (@overrides) {
12311: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
12312: foreach my $item (@contacts) {
12313: if (grep(/^\Q$item\E$/,@standard)) {
12314: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
12315: $newsetting{'override_'.$type}{$item} = 1;
12316: } else {
12317: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
12318: $newsetting{'override_'.$type}{$item} = 0;
12319: }
12320: }
12321: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
12322: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
12323: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
12324: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
12325: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
12326: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
12327: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
12328: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
12329: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
12330: }
12331: }
12332: }
12333: }
1.28 raeburn 12334: if (keys(%currsetting) > 0) {
12335: foreach my $item (@contacts) {
12336: if ($to{$item} ne $currsetting{$item}) {
12337: $changes{$item} = 1;
12338: }
12339: }
12340: foreach my $type (@mailings) {
12341: foreach my $item (@contacts) {
12342: if (ref($currsetting{$type}) eq 'HASH') {
12343: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
12344: push(@{$changes{$type}},$item);
12345: }
12346: } else {
12347: push(@{$changes{$type}},@{$newsetting{$type}});
12348: }
12349: }
12350: if ($others{$type} ne $currsetting{$type}{'others'}) {
12351: push(@{$changes{$type}},'others');
12352: }
1.289 raeburn 12353: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12354: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
12355: push(@{$changes{$type}},'bcc');
12356: }
1.286 raeburn 12357: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
12358: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
12359: push(@{$changes{$type}},'include');
12360: }
12361: }
12362: }
12363: if (ref($fields) eq 'ARRAY') {
12364: if (ref($currsetting{'helpform'}) eq 'HASH') {
12365: foreach my $field (@{$fields}) {
12366: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
12367: push(@{$changes{'helpform'}},$field);
12368: }
12369: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12370: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
12371: push(@{$changes{'helpform'}},'maxsize');
12372: }
12373: }
12374: }
12375: } else {
12376: foreach my $field (@{$fields}) {
12377: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12378: push(@{$changes{'helpform'}},$field);
12379: }
12380: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12381: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12382: push(@{$changes{'helpform'}},'maxsize');
12383: }
12384: }
12385: }
1.134 raeburn 12386: }
1.28 raeburn 12387: }
1.315 raeburn 12388: if (@statuses) {
12389: if (ref($currsetting{'overrides'}) eq 'HASH') {
12390: foreach my $key (keys(%{$currsetting{'overrides'}})) {
12391: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
12392: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
12393: foreach my $item (@contacts,'bcc','others','include') {
12394: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
12395: push(@{$changes{'overrides'}},$key);
12396: last;
12397: }
12398: }
12399: } else {
12400: push(@{$changes{'overrides'}},$key);
12401: }
12402: }
12403: }
12404: foreach my $key (@overrides) {
12405: unless (exists($currsetting{'overrides'}{$key})) {
12406: push(@{$changes{'overrides'}},$key);
12407: }
12408: }
12409: } else {
12410: foreach my $key (@overrides) {
12411: push(@{$changes{'overrides'}},$key);
12412: }
12413: }
12414: }
1.28 raeburn 12415: } else {
12416: my %default;
12417: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
12418: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
12419: $default{'errormail'} = 'adminemail';
12420: $default{'packagesmail'} = 'adminemail';
12421: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 12422: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 12423: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 12424: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 12425: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 12426: foreach my $item (@contacts) {
12427: if ($to{$item} ne $default{$item}) {
1.286 raeburn 12428: $changes{$item} = 1;
1.203 raeburn 12429: }
1.28 raeburn 12430: }
12431: foreach my $type (@mailings) {
12432: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
12433: push(@{$changes{$type}},@{$newsetting{$type}});
12434: }
12435: if ($others{$type} ne '') {
12436: push(@{$changes{$type}},'others');
1.134 raeburn 12437: }
1.286 raeburn 12438: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12439: if ($bcc{$type} ne '') {
12440: push(@{$changes{$type}},'bcc');
12441: }
1.286 raeburn 12442: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
12443: push(@{$changes{$type}},'include');
12444: }
1.134 raeburn 12445: }
1.28 raeburn 12446: }
1.286 raeburn 12447: if (ref($fields) eq 'ARRAY') {
12448: foreach my $field (@{$fields}) {
12449: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12450: push(@{$changes{'helpform'}},$field);
12451: }
12452: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12453: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12454: push(@{$changes{'helpform'}},'maxsize');
12455: }
12456: }
12457: }
1.289 raeburn 12458: }
1.28 raeburn 12459: }
1.203 raeburn 12460: foreach my $item (@toggles) {
12461: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
12462: $changes{$item} = 1;
12463: } elsif ((!$env{'form.'.$item}) &&
12464: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
12465: $changes{$item} = 1;
12466: }
12467: }
1.28 raeburn 12468: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
12469: $dom);
12470: if ($putresult eq 'ok') {
12471: if (keys(%changes) > 0) {
1.205 raeburn 12472: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12473: if (ref($lastactref) eq 'HASH') {
12474: $lastactref->{'domainconfig'} = 1;
12475: }
1.28 raeburn 12476: my ($titles,$short_titles) = &contact_titles();
12477: $resulttext = &mt('Changes made:').'<ul>';
12478: foreach my $item (@contacts) {
12479: if ($changes{$item}) {
12480: $resulttext .= '<li>'.$titles->{$item}.
12481: &mt(' set to: ').
12482: '<span class="LC_cusr_emph">'.
12483: $to{$item}.'</span></li>';
12484: }
12485: }
12486: foreach my $type (@mailings) {
12487: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 12488: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 12489: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 12490: } else {
12491: $resulttext .= '<li>'.$titles->{$type}.': ';
12492: }
1.28 raeburn 12493: my @text;
12494: foreach my $item (@{$newsetting{$type}}) {
12495: push(@text,$short_titles->{$item});
12496: }
12497: if ($others{$type} ne '') {
12498: push(@text,$others{$type});
12499: }
1.286 raeburn 12500: if (@text) {
12501: $resulttext .= '<span class="LC_cusr_emph">'.
12502: join(', ',@text).'</span>';
12503: }
12504: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12505: if ($bcc{$type} ne '') {
1.286 raeburn 12506: my $bcctext;
12507: if (@text) {
1.289 raeburn 12508: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 12509: } else {
12510: $bcctext = '(Bcc)';
12511: }
12512: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
12513: } elsif (!@text) {
12514: $resulttext .= &mt('No one');
12515: }
1.289 raeburn 12516: if ($includestr{$type} ne '') {
1.286 raeburn 12517: if ($includeloc{$type} eq 'b') {
12518: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
12519: } elsif ($includeloc{$type} eq 's') {
12520: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
12521: }
1.134 raeburn 12522: }
1.286 raeburn 12523: } elsif (!@text) {
12524: $resulttext .= &mt('No recipients');
1.134 raeburn 12525: }
12526: $resulttext .= '</li>';
1.28 raeburn 12527: }
12528: }
1.315 raeburn 12529: if (ref($changes{'overrides'}) eq 'ARRAY') {
12530: my @deletions;
12531: foreach my $type (@{$changes{'overrides'}}) {
12532: if ($usertypeshash{$type}) {
12533: if (grep(/^\Q$type\E/,@overrides)) {
12534: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
12535: $usertypeshash{$type}).'<ul><li>';
12536: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
12537: my @text;
12538: foreach my $item (@contacts) {
12539: if ($newsetting{'override_'.$type}{$item}) {
12540: push(@text,$short_titles->{$item});
12541: }
12542: }
12543: if ($newsetting{'override_'.$type}{'others'} ne '') {
12544: push(@text,$newsetting{'override_'.$type}{'others'});
12545: }
12546:
12547: if (@text) {
12548: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
12549: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
12550: }
12551: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
12552: my $bcctext;
12553: if (@text) {
12554: $bcctext = ' '.&mt('with Bcc to');
12555: } else {
12556: $bcctext = '(Bcc)';
12557: }
12558: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
12559: } elsif (!@text) {
12560: $resulttext .= &mt('Helpdesk e-mail sent to no one');
12561: }
12562: $resulttext .= '</li>';
12563: if ($newsetting{'override_'.$type}{'include'} ne '') {
12564: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
12565: if ($loc eq 'b') {
12566: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
12567: } elsif ($loc eq 's') {
12568: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
12569: }
12570: }
12571: }
12572: $resulttext .= '</li></ul></li>';
12573: } else {
12574: push(@deletions,$usertypeshash{$type});
12575: }
12576: }
12577: }
12578: if (@deletions) {
12579: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
12580: join(', ',@deletions)).'</li>';
12581: }
12582: }
1.203 raeburn 12583: my @offon = ('off','on');
12584: if ($changes{'reporterrors'}) {
12585: $resulttext .= '<li>'.
12586: &mt('E-mail error reports to [_1] set to "'.
12587: $offon[$env{'form.reporterrors'}].'".',
12588: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
12589: &mt('LON-CAPA core group - MSU'),600,500)).
12590: '</li>';
12591: }
12592: if ($changes{'reportupdates'}) {
12593: $resulttext .= '<li>'.
12594: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
12595: $offon[$env{'form.reportupdates'}].'".',
12596: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
12597: &mt('LON-CAPA core group - MSU'),600,500)).
12598: '</li>';
12599: }
1.286 raeburn 12600: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
12601: my (@optional,@required,@unused,$maxsizechg);
12602: foreach my $field (@{$changes{'helpform'}}) {
12603: if ($field eq 'maxsize') {
12604: $maxsizechg = 1;
12605: next;
12606: }
12607: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 12608: push(@optional,$field);
1.286 raeburn 12609: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
12610: push(@unused,$field);
12611: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 12612: push(@required,$field);
1.286 raeburn 12613: }
12614: }
12615: if (@optional) {
12616: $resulttext .= '<li>'.
12617: &mt('Help form fields changed to "Optional": [_1].',
12618: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
12619: '</li>';
12620: }
12621: if (@required) {
12622: $resulttext .= '<li>'.
12623: &mt('Help form fields changed to "Required": [_1].',
12624: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
12625: '</li>';
12626: }
12627: if (@unused) {
12628: $resulttext .= '<li>'.
12629: &mt('Help form fields changed to "Not shown": [_1].',
12630: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
12631: '</li>';
12632: }
12633: if ($maxsizechg) {
12634: $resulttext .= '<li>'.
12635: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
12636: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
12637: '</li>';
12638: }
12639: }
1.28 raeburn 12640: $resulttext .= '</ul>';
12641: } else {
1.288 raeburn 12642: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 12643: }
12644: } else {
12645: $resulttext = '<span class="LC_error">'.
12646: &mt('An error occurred: [_1].',$putresult).'</span>';
12647: }
12648: return $resulttext;
12649: }
12650:
12651: sub modify_usercreation {
1.27 raeburn 12652: my ($dom,%domconfig) = @_;
1.224 raeburn 12653: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 12654: my $warningmsg;
1.27 raeburn 12655: if (ref($domconfig{'usercreation'}) eq 'HASH') {
12656: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 12657: if ($key eq 'cancreate') {
12658: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
12659: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 12660: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
12661: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
12662: } else {
1.224 raeburn 12663: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
12664: }
12665: }
12666: }
12667: } elsif ($key eq 'email_rule') {
12668: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
12669: } else {
12670: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
12671: }
1.27 raeburn 12672: }
12673: }
12674: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 12675: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 12676: my @contexts = ('author','course','requestcrs');
1.34 raeburn 12677: foreach my $item(@contexts) {
1.224 raeburn 12678: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 12679: }
1.34 raeburn 12680: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
12681: foreach my $item (@contexts) {
1.224 raeburn 12682: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
12683: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 12684: }
1.27 raeburn 12685: }
1.34 raeburn 12686: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
12687: foreach my $item (@contexts) {
1.43 raeburn 12688: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 12689: if ($cancreate{$item} ne 'any') {
12690: push(@{$changes{'cancreate'}},$item);
12691: }
12692: } else {
12693: if ($cancreate{$item} ne 'none') {
12694: push(@{$changes{'cancreate'}},$item);
12695: }
1.27 raeburn 12696: }
12697: }
12698: } else {
1.43 raeburn 12699: foreach my $item (@contexts) {
1.34 raeburn 12700: push(@{$changes{'cancreate'}},$item);
12701: }
1.27 raeburn 12702: }
1.34 raeburn 12703:
1.27 raeburn 12704: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
12705: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
12706: if (!grep(/^\Q$type\E$/,@username_rule)) {
12707: push(@{$changes{'username_rule'}},$type);
12708: }
12709: }
12710: foreach my $type (@username_rule) {
12711: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
12712: push(@{$changes{'username_rule'}},$type);
12713: }
12714: }
12715: } else {
12716: push(@{$changes{'username_rule'}},@username_rule);
12717: }
12718:
1.32 raeburn 12719: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
12720: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
12721: if (!grep(/^\Q$type\E$/,@id_rule)) {
12722: push(@{$changes{'id_rule'}},$type);
12723: }
12724: }
12725: foreach my $type (@id_rule) {
12726: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
12727: push(@{$changes{'id_rule'}},$type);
12728: }
12729: }
12730: } else {
12731: push(@{$changes{'id_rule'}},@id_rule);
12732: }
12733:
1.43 raeburn 12734: my @authen_contexts = ('author','course','domain');
1.28 raeburn 12735: my @authtypes = ('int','krb4','krb5','loc');
12736: my %authhash;
1.43 raeburn 12737: foreach my $item (@authen_contexts) {
1.28 raeburn 12738: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
12739: foreach my $auth (@authtypes) {
12740: if (grep(/^\Q$auth\E$/,@authallowed)) {
12741: $authhash{$item}{$auth} = 1;
12742: } else {
12743: $authhash{$item}{$auth} = 0;
12744: }
12745: }
12746: }
12747: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 12748: foreach my $item (@authen_contexts) {
1.28 raeburn 12749: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
12750: foreach my $auth (@authtypes) {
12751: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
12752: push(@{$changes{'authtypes'}},$item);
12753: last;
12754: }
12755: }
12756: }
12757: }
12758: } else {
1.43 raeburn 12759: foreach my $item (@authen_contexts) {
1.28 raeburn 12760: push(@{$changes{'authtypes'}},$item);
12761: }
12762: }
12763:
1.224 raeburn 12764: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
12765: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
12766: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
12767: $save_usercreate{'id_rule'} = \@id_rule;
12768: $save_usercreate{'username_rule'} = \@username_rule,
12769: $save_usercreate{'authtypes'} = \%authhash;
12770:
1.27 raeburn 12771: my %usercreation_hash = (
1.224 raeburn 12772: usercreation => \%save_usercreate,
12773: );
1.27 raeburn 12774:
12775: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
12776: $dom);
1.50 raeburn 12777:
1.224 raeburn 12778: if ($putresult eq 'ok') {
12779: if (keys(%changes) > 0) {
12780: $resulttext = &mt('Changes made:').'<ul>';
12781: if (ref($changes{'cancreate'}) eq 'ARRAY') {
12782: my %lt = &usercreation_types();
12783: foreach my $type (@{$changes{'cancreate'}}) {
12784: my $chgtext = $lt{$type}.', ';
12785: if ($cancreate{$type} eq 'none') {
12786: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
12787: } elsif ($cancreate{$type} eq 'any') {
12788: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
12789: } elsif ($cancreate{$type} eq 'official') {
12790: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
12791: } elsif ($cancreate{$type} eq 'unofficial') {
12792: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
12793: }
12794: $resulttext .= '<li>'.$chgtext.'</li>';
12795: }
12796: }
12797: if (ref($changes{'username_rule'}) eq 'ARRAY') {
12798: my ($rules,$ruleorder) =
12799: &Apache::lonnet::inst_userrules($dom,'username');
12800: my $chgtext = '<ul>';
12801: foreach my $type (@username_rule) {
12802: if (ref($rules->{$type}) eq 'HASH') {
12803: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
12804: }
12805: }
12806: $chgtext .= '</ul>';
12807: if (@username_rule > 0) {
12808: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
12809: } else {
12810: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
12811: }
12812: }
12813: if (ref($changes{'id_rule'}) eq 'ARRAY') {
12814: my ($idrules,$idruleorder) =
12815: &Apache::lonnet::inst_userrules($dom,'id');
12816: my $chgtext = '<ul>';
12817: foreach my $type (@id_rule) {
12818: if (ref($idrules->{$type}) eq 'HASH') {
12819: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
12820: }
12821: }
12822: $chgtext .= '</ul>';
12823: if (@id_rule > 0) {
12824: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
12825: } else {
12826: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
12827: }
12828: }
12829: my %authname = &authtype_names();
12830: my %context_title = &context_names();
12831: if (ref($changes{'authtypes'}) eq 'ARRAY') {
12832: my $chgtext = '<ul>';
12833: foreach my $type (@{$changes{'authtypes'}}) {
12834: my @allowed;
12835: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
12836: foreach my $auth (@authtypes) {
12837: if ($authhash{$type}{$auth}) {
12838: push(@allowed,$authname{$auth});
12839: }
12840: }
12841: if (@allowed > 0) {
12842: $chgtext .= join(', ',@allowed).'</li>';
12843: } else {
12844: $chgtext .= &mt('none').'</li>';
12845: }
12846: }
12847: $chgtext .= '</ul>';
12848: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
12849: $resulttext .= '</li>';
12850: }
12851: $resulttext .= '</ul>';
12852: } else {
12853: $resulttext = &mt('No changes made to user creation settings');
12854: }
12855: } else {
12856: $resulttext = '<span class="LC_error">'.
12857: &mt('An error occurred: [_1]',$putresult).'</span>';
12858: }
12859: if ($warningmsg ne '') {
12860: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
12861: }
12862: return $resulttext;
12863: }
12864:
12865: sub modify_selfcreation {
1.305 raeburn 12866: my ($dom,$lastactref,%domconfig) = @_;
12867: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
12868: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
12869: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 12870: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
12871: if (ref($typesref) eq 'ARRAY') {
12872: @types = @{$typesref};
12873: }
12874: if (ref($usertypesref) eq 'HASH') {
12875: %usertypes = %{$usertypesref};
1.228 raeburn 12876: }
1.303 raeburn 12877: $usertypes{'default'} = $othertitle;
1.224 raeburn 12878: #
12879: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
12880: #
12881: if (ref($domconfig{'usercreation'}) eq 'HASH') {
12882: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
12883: if ($key eq 'cancreate') {
12884: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
12885: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
12886: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 12887: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
12888: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
12889: ($item eq 'emailusername') || ($item eq 'shibenv') ||
12890: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 12891: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 12892: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
12893: } else {
12894: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
12895: }
12896: }
12897: }
12898: } elsif ($key eq 'email_rule') {
12899: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
12900: } else {
12901: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
12902: }
12903: }
12904: }
12905: #
12906: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
12907: #
12908: if (ref($domconfig{'usermodification'}) eq 'HASH') {
12909: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
12910: if ($key eq 'selfcreate') {
12911: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
12912: } else {
12913: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
12914: }
12915: }
12916: }
1.305 raeburn 12917: #
12918: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
12919: #
12920: if (ref($domconfig{'inststatus'}) eq 'HASH') {
12921: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
12922: if ($key eq 'inststatusguest') {
12923: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
12924: } else {
12925: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
12926: }
12927: }
12928: }
1.224 raeburn 12929:
12930: my @contexts = ('selfcreate');
12931: @{$cancreate{'selfcreate'}} = ();
12932: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 12933: if (@types) {
12934: @{$cancreate{'statustocreate'}} = ();
12935: }
1.236 raeburn 12936: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 12937: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 12938: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 12939: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 12940: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 12941: my %selfcreatetypes = (
12942: sso => 'users authenticated by institutional single sign on',
12943: login => 'users authenticated by institutional log-in',
1.303 raeburn 12944: email => 'users verified by e-mail',
1.50 raeburn 12945: );
1.224 raeburn 12946: #
12947: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
12948: # is permitted.
12949: #
1.305 raeburn 12950: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 12951:
1.305 raeburn 12952: my (@statuses,%email_rule);
1.228 raeburn 12953: foreach my $item ('login','sso','email') {
1.224 raeburn 12954: if ($item eq 'email') {
1.236 raeburn 12955: if ($env{'form.cancreate_email'}) {
1.305 raeburn 12956: if (@types) {
12957: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
12958: foreach my $status (@poss_statuses) {
12959: if (grep(/^\Q$status\E$/,(@types,'default'))) {
12960: push(@statuses,$status);
12961: }
12962: }
12963: $save_inststatus{'inststatusguest'} = \@statuses;
12964: } else {
12965: push(@statuses,'default');
12966: }
12967: if (@statuses) {
12968: my %curr_rule;
12969: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
12970: foreach my $type (@statuses) {
12971: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 12972: }
1.305 raeburn 12973: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
12974: foreach my $type (@statuses) {
12975: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
12976: }
12977: }
12978: push(@{$cancreate{'selfcreate'}},'email');
12979: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
12980: my %curremaildom;
12981: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
12982: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
12983: }
12984: foreach my $type (@statuses) {
12985: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
12986: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
12987: }
12988: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
12989: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
12990: }
12991: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
12992: #
12993: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
12994: #
12995: my $chosen = $1;
12996: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
12997: my $emaildom;
12998: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
12999: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
13000: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
13001: if (ref($curremaildom{$type}) eq 'HASH') {
13002: if (exists($curremaildom{$type}{$chosen})) {
13003: if ($curremaildom{$type}{$chosen} ne $emaildom) {
13004: push(@{$changes{'cancreate'}},'emaildomain');
13005: }
13006: } elsif ($emaildom ne '') {
13007: push(@{$changes{'cancreate'}},'emaildomain');
13008: }
13009: } elsif ($emaildom ne '') {
13010: push(@{$changes{'cancreate'}},'emaildomain');
13011: }
13012: }
13013: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13014: } elsif ($chosen eq 'custom') {
13015: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
13016: $email_rule{$type} = [];
13017: if (ref($emailrules) eq 'HASH') {
13018: foreach my $rule (@possemail_rules) {
13019: if (exists($emailrules->{$rule})) {
13020: push(@{$email_rule{$type}},$rule);
13021: }
13022: }
13023: }
13024: if (@{$email_rule{$type}}) {
13025: $cancreate{'emailoptions'}{$type} = 'custom';
13026: if (ref($curr_rule{$type}) eq 'ARRAY') {
13027: if (@{$curr_rule{$type}} > 0) {
13028: foreach my $rule (@{$curr_rule{$type}}) {
13029: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
13030: push(@{$changes{'email_rule'}},$type);
13031: }
13032: }
13033: }
13034: foreach my $type (@{$email_rule{$type}}) {
13035: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
13036: push(@{$changes{'email_rule'}},$type);
13037: }
13038: }
13039: } else {
13040: push(@{$changes{'email_rule'}},$type);
13041: }
13042: }
13043: } else {
13044: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13045: }
13046: }
13047: }
13048: if (@types) {
13049: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13050: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
13051: if (@changed) {
13052: push(@{$changes{'inststatus'}},'inststatusguest');
13053: }
13054: } else {
13055: push(@{$changes{'inststatus'}},'inststatusguest');
13056: }
13057: }
13058: } else {
13059: delete($env{'form.cancreate_email'});
13060: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13061: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13062: push(@{$changes{'inststatus'}},'inststatusguest');
13063: }
13064: }
13065: }
13066: } else {
13067: $save_inststatus{'inststatusguest'} = [];
13068: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13069: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13070: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 13071: }
13072: }
1.224 raeburn 13073: }
13074: } else {
13075: if ($env{'form.cancreate_'.$item}) {
13076: push(@{$cancreate{'selfcreate'}},$item);
13077: }
13078: }
13079: }
1.305 raeburn 13080: my (%userinfo,%savecaptcha);
1.224 raeburn 13081: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
13082: #
1.228 raeburn 13083: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
13084: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 13085: #
1.236 raeburn 13086:
1.244 raeburn 13087: if ($env{'form.cancreate_email'}) {
1.228 raeburn 13088: push(@contexts,'emailusername');
1.305 raeburn 13089: if (@statuses) {
13090: foreach my $type (@statuses) {
1.228 raeburn 13091: if (ref($infofields) eq 'ARRAY') {
13092: foreach my $field (@{$infofields}) {
13093: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
13094: $cancreate{'emailusername'}{$type}{$field} = $1;
13095: }
13096: }
1.224 raeburn 13097: }
13098: }
13099: }
13100: #
13101: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 13102: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 13103: #
13104:
13105: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
13106: @approvalnotify = sort(@approvalnotify);
13107: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
13108: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13109: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
13110: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
13111: push(@{$changes{'cancreate'}},'notify');
13112: }
13113: } else {
13114: if ($cancreate{'notify'}{'approval'}) {
13115: push(@{$changes{'cancreate'}},'notify');
13116: }
13117: }
13118: } elsif ($cancreate{'notify'}{'approval'}) {
13119: push(@{$changes{'cancreate'}},'notify');
13120: }
13121:
13122: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
13123: }
13124: #
1.236 raeburn 13125: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 13126: # institutional log-in.
13127: #
13128: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
13129: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
13130: ($domdefaults{'auth_def'} eq 'localauth'))) {
13131: $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.').' '.
13132: &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.');
13133: }
13134: }
13135: my @fields = ('lastname','firstname','middlename','generation',
13136: 'permanentemail','id');
1.240 raeburn 13137: my @shibfields = (@fields,'inststatus');
1.224 raeburn 13138: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13139: #
13140: # Where usernames may created for institutional log-in and/or institutional single sign on:
13141: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
13142: # may self-create accounts
13143: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
13144: # which the user may supply, if institutional data is unavailable.
13145: #
13146: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 13147: if (@types) {
1.305 raeburn 13148: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
13149: push(@contexts,'statustocreate');
1.303 raeburn 13150: foreach my $type (@types) {
1.224 raeburn 13151: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
13152: foreach my $field (@fields) {
13153: if (grep(/^\Q$field\E$/,@modifiable)) {
13154: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
13155: } else {
13156: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
13157: }
13158: }
13159: }
13160: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 13161: foreach my $type (@types) {
1.224 raeburn 13162: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
13163: foreach my $field (@fields) {
13164: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
13165: $curr_usermodify{'selfcreate'}{$type}{$field}) {
13166: push(@{$changes{'selfcreate'}},$type);
13167: last;
13168: }
13169: }
13170: }
13171: }
13172: } else {
1.303 raeburn 13173: foreach my $type (@types) {
1.224 raeburn 13174: push(@{$changes{'selfcreate'}},$type);
13175: }
13176: }
13177: }
1.240 raeburn 13178: foreach my $field (@shibfields) {
13179: if ($env{'form.shibenv_'.$field} ne '') {
13180: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
13181: }
13182: }
13183: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13184: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
13185: foreach my $field (@shibfields) {
13186: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
13187: push(@{$changes{'cancreate'}},'shibenv');
13188: }
13189: }
13190: } else {
13191: foreach my $field (@shibfields) {
13192: if ($env{'form.shibenv_'.$field}) {
13193: push(@{$changes{'cancreate'}},'shibenv');
13194: last;
13195: }
13196: }
13197: }
13198: }
1.224 raeburn 13199: }
13200: foreach my $item (@contexts) {
13201: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
13202: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
13203: if (ref($cancreate{$item}) eq 'ARRAY') {
13204: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
13205: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13206: push(@{$changes{'cancreate'}},$item);
13207: }
13208: }
13209: }
13210: }
13211: if (ref($cancreate{$item}) eq 'ARRAY') {
13212: foreach my $type (@{$cancreate{$item}}) {
13213: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
13214: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13215: push(@{$changes{'cancreate'}},$item);
13216: }
13217: }
13218: }
13219: }
13220: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
13221: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 13222: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
13223: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13224: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
13225: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 13226: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13227: push(@{$changes{'cancreate'}},$item);
13228: }
13229: }
13230: }
1.305 raeburn 13231: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13232: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 13233: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13234: push(@{$changes{'cancreate'}},$item);
13235: }
1.224 raeburn 13236: }
13237: }
13238: }
1.305 raeburn 13239: foreach my $type (keys(%{$cancreate{$item}})) {
13240: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13241: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13242: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13243: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 13244: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13245: push(@{$changes{'cancreate'}},$item);
13246: }
13247: }
13248: } else {
13249: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13250: push(@{$changes{'cancreate'}},$item);
13251: }
13252: }
13253: }
1.305 raeburn 13254: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13255: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 13256: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13257: push(@{$changes{'cancreate'}},$item);
13258: }
1.224 raeburn 13259: }
13260: }
13261: }
13262: }
13263: } elsif ($curr_usercreation{'cancreate'}{$item}) {
13264: if (ref($cancreate{$item}) eq 'ARRAY') {
13265: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
13266: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13267: push(@{$changes{'cancreate'}},$item);
13268: }
13269: }
1.305 raeburn 13270: }
13271: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13272: if (ref($cancreate{$item}) eq 'HASH') {
13273: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13274: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 13275: }
13276: }
13277: } elsif ($item eq 'emailusername') {
1.228 raeburn 13278: if (ref($cancreate{$item}) eq 'HASH') {
13279: foreach my $type (keys(%{$cancreate{$item}})) {
13280: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13281: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13282: if ($cancreate{$item}{$type}{$field}) {
13283: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13284: push(@{$changes{'cancreate'}},$item);
13285: }
13286: last;
13287: }
13288: }
13289: }
13290: }
1.224 raeburn 13291: }
13292: }
13293: }
13294: #
13295: # Populate %save_usercreate hash with updates to self-creation configuration.
13296: #
13297: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
13298: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 13299: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 13300: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
13301: if (ref($cancreate{'notify'}) eq 'HASH') {
13302: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
13303: }
1.236 raeburn 13304: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
13305: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
13306: }
1.303 raeburn 13307: if (ref($cancreate{'emailverified'}) eq 'HASH') {
13308: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
13309: }
1.305 raeburn 13310: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
13311: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
13312: }
1.303 raeburn 13313: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
13314: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
13315: }
1.224 raeburn 13316: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13317: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
13318: }
1.240 raeburn 13319: if (ref($cancreate{'shibenv'}) eq 'HASH') {
13320: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
13321: }
1.224 raeburn 13322: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 13323: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 13324:
13325: my %userconfig_hash = (
13326: usercreation => \%save_usercreate,
13327: usermodification => \%save_usermodify,
1.305 raeburn 13328: inststatus => \%save_inststatus,
1.224 raeburn 13329: );
1.305 raeburn 13330:
1.224 raeburn 13331: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
13332: $dom);
13333: #
1.305 raeburn 13334: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 13335: #
1.27 raeburn 13336: if ($putresult eq 'ok') {
13337: if (keys(%changes) > 0) {
13338: $resulttext = &mt('Changes made:').'<ul>';
13339: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 13340: my %lt = &selfcreation_types();
1.34 raeburn 13341: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 13342: my $chgtext = '';
1.45 raeburn 13343: if ($type eq 'selfcreate') {
1.50 raeburn 13344: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 13345: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 13346: } else {
1.224 raeburn 13347: $chgtext .= &mt('Self-creation of a new account is permitted for:').
13348: '<ul>';
1.50 raeburn 13349: foreach my $case (@{$cancreate{$type}}) {
13350: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
13351: }
13352: $chgtext .= '</ul>';
1.100 raeburn 13353: if (ref($cancreate{$type}) eq 'ARRAY') {
13354: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
13355: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13356: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 13357: $chgtext .= '<span class="LC_warning">'.
13358: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
13359: '</span><br />';
13360: }
13361: }
13362: }
13363: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 13364: if (!@statuses) {
13365: $chgtext .= '<span class="LC_warning">'.
13366: &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.").
13367: '</span><br />';
1.303 raeburn 13368:
1.100 raeburn 13369: }
13370: }
13371: }
1.43 raeburn 13372: }
1.240 raeburn 13373: } elsif ($type eq 'shibenv') {
13374: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 13375: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 13376: } else {
13377: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
13378: '<ul>';
13379: foreach my $field (@shibfields) {
13380: next if ($cancreate{$type}{$field} eq '');
13381: if ($field eq 'inststatus') {
13382: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
13383: } else {
13384: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
13385: }
13386: }
13387: $chgtext .= '</ul>';
1.303 raeburn 13388: }
1.93 raeburn 13389: } elsif ($type eq 'statustocreate') {
1.96 raeburn 13390: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
13391: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
13392: if (@{$cancreate{'selfcreate'}} > 0) {
13393: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 13394: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 13395: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 13396: $chgtext .= '<br />'.
13397: '<span class="LC_warning">'.
13398: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
13399: '</span>';
13400: }
1.303 raeburn 13401: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 13402: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 13403: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
13404: } else {
13405: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
13406: }
13407: $chgtext .= '<ul>';
13408: foreach my $case (@{$cancreate{$type}}) {
13409: if ($case eq 'default') {
13410: $chgtext .= '<li>'.$othertitle.'</li>';
13411: } else {
1.303 raeburn 13412: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 13413: }
13414: }
1.100 raeburn 13415: $chgtext .= '</ul>';
13416: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 13417: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 13418: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
13419: '</span>';
1.100 raeburn 13420: }
13421: }
13422: } else {
13423: if (@{$cancreate{$type}} == 0) {
13424: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
13425: } else {
13426: $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 13427: }
13428: }
1.303 raeburn 13429: $chgtext .= '<br />';
1.93 raeburn 13430: }
1.236 raeburn 13431: } elsif ($type eq 'selfcreateprocessing') {
13432: my %choices = &Apache::lonlocal::texthash (
13433: automatic => 'Automatic approval',
13434: approval => 'Queued for approval',
13435: );
1.305 raeburn 13436: if (@types) {
13437: if (@statuses) {
1.303 raeburn 13438: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 13439: '<ul>';
1.305 raeburn 13440: foreach my $status (@statuses) {
13441: if ($status eq 'default') {
13442: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 13443: } else {
1.305 raeburn 13444: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 13445: }
13446: }
13447: $chgtext .= '</ul>';
13448: }
13449: } else {
13450: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
13451: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
13452: }
13453: } elsif ($type eq 'emailverified') {
13454: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 13455: all => 'Same as e-mail',
13456: first => 'Omit @domain',
13457: free => 'Free to choose',
1.303 raeburn 13458: );
1.305 raeburn 13459: if (@types) {
13460: if (@statuses) {
1.303 raeburn 13461: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
13462: '<ul>';
1.305 raeburn 13463: foreach my $status (@statuses) {
1.303 raeburn 13464: if ($type eq 'default') {
1.305 raeburn 13465: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 13466: } else {
1.305 raeburn 13467: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 13468: }
13469: }
13470: $chgtext .= '</ul>';
13471: }
13472: } else {
1.305 raeburn 13473: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 13474: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 13475: }
1.305 raeburn 13476: } elsif ($type eq 'emailoptions') {
13477: my %options = &Apache::lonlocal::texthash (
13478: any => 'Any e-mail',
13479: inst => 'Institutional only',
13480: noninst => 'Non-institutional only',
13481: custom => 'Custom restrictions',
13482: );
13483: if (@types) {
13484: if (@statuses) {
13485: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
13486: '<ul>';
13487: foreach my $status (@statuses) {
13488: if ($type eq 'default') {
13489: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
13490: } else {
13491: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 13492: }
13493: }
1.305 raeburn 13494: $chgtext .= '</ul>';
13495: }
13496: } else {
13497: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
13498: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
13499: } else {
13500: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
13501: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 13502: }
1.305 raeburn 13503: }
13504: } elsif ($type eq 'emaildomain') {
13505: my $output;
13506: if (@statuses) {
13507: foreach my $type (@statuses) {
13508: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
13509: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
13510: if ($type eq 'default') {
13511: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13512: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
13513: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
13514: } else {
13515: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
13516: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
13517: }
1.303 raeburn 13518: } else {
1.305 raeburn 13519: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13520: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
13521: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
13522: } else {
13523: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
13524: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
13525: }
1.303 raeburn 13526: }
1.305 raeburn 13527: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
13528: if ($type eq 'default') {
13529: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13530: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
13531: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
13532: } else {
13533: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
13534: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
13535: }
1.303 raeburn 13536: } else {
1.305 raeburn 13537: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13538: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
13539: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
13540: } else {
13541: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
13542: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
13543: }
1.303 raeburn 13544: }
13545: }
13546: }
13547: }
1.305 raeburn 13548: }
13549: if ($output ne '') {
13550: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
13551: '<ul>'.$output.'</ul>';
1.236 raeburn 13552: }
1.165 raeburn 13553: } elsif ($type eq 'captcha') {
1.224 raeburn 13554: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 13555: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
13556: } else {
13557: my %captchas = &captcha_phrases();
1.224 raeburn 13558: if ($captchas{$savecaptcha{$type}}) {
13559: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 13560: } else {
1.210 raeburn 13561: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 13562: }
13563: }
13564: } elsif ($type eq 'recaptchakeys') {
13565: my ($privkey,$pubkey);
1.224 raeburn 13566: if (ref($savecaptcha{$type}) eq 'HASH') {
13567: $pubkey = $savecaptcha{$type}{'public'};
13568: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 13569: }
13570: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
13571: if (!$pubkey) {
13572: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
13573: } else {
13574: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
13575: }
13576: if (!$privkey) {
13577: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
13578: } else {
13579: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
13580: }
13581: $chgtext .= '</ul>';
1.269 raeburn 13582: } elsif ($type eq 'recaptchaversion') {
13583: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 13584: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 13585: }
1.224 raeburn 13586: } elsif ($type eq 'emailusername') {
13587: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 13588: if (@statuses) {
13589: foreach my $type (@statuses) {
1.228 raeburn 13590: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
13591: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 13592: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 13593: '<ul>';
13594: foreach my $field (@{$infofields}) {
13595: if ($cancreate{'emailusername'}{$type}{$field}) {
13596: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
13597: }
13598: }
1.245 raeburn 13599: $chgtext .= '</ul>';
13600: } else {
1.303 raeburn 13601: $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 13602: }
13603: } else {
1.303 raeburn 13604: $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 13605: }
13606: }
13607: }
13608: }
13609: } elsif ($type eq 'notify') {
1.303 raeburn 13610: my $numapprove = 0;
1.224 raeburn 13611: if (ref($changes{'cancreate'}) eq 'ARRAY') {
13612: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
13613: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 13614: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
13615: $numapprove ++;
1.224 raeburn 13616: }
13617: }
1.43 raeburn 13618: }
1.303 raeburn 13619: unless ($numapprove) {
13620: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
13621: }
1.34 raeburn 13622: }
1.224 raeburn 13623: if ($chgtext) {
13624: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 13625: }
13626: }
13627: }
1.305 raeburn 13628: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 13629: my ($emailrules,$emailruleorder) =
13630: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 13631: foreach my $type (@{$changes{'email_rule'}}) {
13632: if (ref($email_rule{$type}) eq 'ARRAY') {
13633: my $chgtext = '<ul>';
13634: foreach my $rule (@{$email_rule{$type}}) {
13635: if (ref($emailrules->{$rule}) eq 'HASH') {
13636: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
13637: }
13638: }
13639: $chgtext .= '</ul>';
1.310 raeburn 13640: my $typename;
1.305 raeburn 13641: if (@types) {
13642: if ($type eq 'default') {
13643: $typename = $othertitle;
13644: } else {
13645: $typename = $usertypes{$type};
13646: }
13647: $chgtext .= &mt('(Affiliation: [_1])',$typename);
13648: }
13649: if (@{$email_rule{$type}} > 0) {
13650: $resulttext .= '<li>'.
13651: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
13652: $usertypes{$type}).
13653: $chgtext.
13654: '</li>';
13655: } else {
13656: $resulttext .= '<li>'.
1.310 raeburn 13657: &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 13658: '</li>'.
1.310 raeburn 13659: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 13660: }
1.43 raeburn 13661: }
13662: }
1.305 raeburn 13663: }
13664: if (ref($changes{'inststatus'}) eq 'ARRAY') {
13665: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
13666: if (@{$save_inststatus{'inststatusguest'}} > 0) {
13667: my $chgtext = '<ul>';
13668: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
13669: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
13670: }
13671: $chgtext .= '</ul>';
13672: $resulttext .= '<li>'.
13673: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
13674: $chgtext.
13675: '</li>';
13676: } else {
13677: $resulttext .= '<li>'.
13678: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
13679: '</li>';
13680: }
1.43 raeburn 13681: }
13682: }
1.224 raeburn 13683: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
13684: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
13685: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13686: foreach my $type (@{$changes{'selfcreate'}}) {
13687: my $typename = $type;
1.303 raeburn 13688: if (keys(%usertypes) > 0) {
13689: if ($usertypes{$type} ne '') {
13690: $typename = $usertypes{$type};
1.224 raeburn 13691: }
13692: }
13693: my @modifiable;
13694: $resulttext .= '<li>'.
13695: &mt('Self-creation of account by users with status: [_1]',
13696: '<span class="LC_cusr_emph">'.$typename.'</span>').
13697: ' - '.&mt('modifiable fields (if institutional data blank): ');
13698: foreach my $field (@fields) {
13699: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
13700: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 13701: }
13702: }
1.224 raeburn 13703: if (@modifiable > 0) {
13704: $resulttext .= join(', ',@modifiable);
1.43 raeburn 13705: } else {
1.224 raeburn 13706: $resulttext .= &mt('none');
1.43 raeburn 13707: }
1.224 raeburn 13708: $resulttext .= '</li>';
1.28 raeburn 13709: }
1.224 raeburn 13710: $resulttext .= '</ul></li>';
1.28 raeburn 13711: }
1.27 raeburn 13712: $resulttext .= '</ul>';
1.305 raeburn 13713: my $cachetime = 24*60*60;
13714: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
13715: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13716: if (ref($lastactref) eq 'HASH') {
13717: $lastactref->{'domdefaults'} = 1;
13718: }
1.27 raeburn 13719: } else {
1.224 raeburn 13720: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 13721: }
13722: } else {
13723: $resulttext = '<span class="LC_error">'.
1.23 raeburn 13724: &mt('An error occurred: [_1]',$putresult).'</span>';
13725: }
1.43 raeburn 13726: if ($warningmsg ne '') {
13727: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
13728: }
1.23 raeburn 13729: return $resulttext;
13730: }
13731:
1.165 raeburn 13732: sub process_captcha {
13733: my ($container,$changes,$newsettings,$current) = @_;
13734: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
13735: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
13736: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
13737: $newsettings->{'captcha'} = 'original';
13738: }
13739: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 13740: if ($container eq 'cancreate') {
1.169 raeburn 13741: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
13742: push(@{$changes->{'cancreate'}},'captcha');
13743: } elsif (!defined($changes->{'cancreate'})) {
13744: $changes->{'cancreate'} = ['captcha'];
13745: }
13746: } else {
13747: $changes->{'captcha'} = 1;
1.165 raeburn 13748: }
13749: }
1.269 raeburn 13750: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 13751: if ($newsettings->{'captcha'} eq 'recaptcha') {
13752: $newpub = $env{'form.'.$container.'_recaptchapub'};
13753: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 13754: $newpub =~ s/[^\w\-]//g;
13755: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 13756: $newsettings->{'recaptchakeys'} = {
13757: public => $newpub,
13758: private => $newpriv,
13759: };
1.269 raeburn 13760: $newversion = $env{'form.'.$container.'_recaptchaversion'};
13761: $newversion =~ s/\D//g;
13762: if ($newversion ne '2') {
13763: $newversion = 1;
13764: }
13765: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 13766: }
13767: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
13768: $currpub = $current->{'recaptchakeys'}{'public'};
13769: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 13770: unless ($newsettings->{'captcha'} eq 'recaptcha') {
13771: $newsettings->{'recaptchakeys'} = {
13772: public => '',
13773: private => '',
13774: }
13775: }
1.165 raeburn 13776: }
1.269 raeburn 13777: if ($current->{'captcha'} eq 'recaptcha') {
13778: $currversion = $current->{'recaptchaversion'};
13779: if ($currversion ne '2') {
13780: $currversion = 1;
13781: }
13782: }
13783: if ($currversion ne $newversion) {
13784: if ($container eq 'cancreate') {
13785: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
13786: push(@{$changes->{'cancreate'}},'recaptchaversion');
13787: } elsif (!defined($changes->{'cancreate'})) {
13788: $changes->{'cancreate'} = ['recaptchaversion'];
13789: }
13790: } else {
13791: $changes->{'recaptchaversion'} = 1;
13792: }
13793: }
1.165 raeburn 13794: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 13795: if ($container eq 'cancreate') {
13796: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
13797: push(@{$changes->{'cancreate'}},'recaptchakeys');
13798: } elsif (!defined($changes->{'cancreate'})) {
13799: $changes->{'cancreate'} = ['recaptchakeys'];
13800: }
13801: } else {
1.210 raeburn 13802: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 13803: }
13804: }
13805: return;
13806: }
13807:
1.33 raeburn 13808: sub modify_usermodification {
13809: my ($dom,%domconfig) = @_;
1.224 raeburn 13810: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 13811: if (ref($domconfig{'usermodification'}) eq 'HASH') {
13812: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 13813: if ($key eq 'selfcreate') {
13814: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
13815: } else {
13816: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
13817: }
1.33 raeburn 13818: }
13819: }
1.224 raeburn 13820: my @contexts = ('author','course');
1.33 raeburn 13821: my %context_title = (
13822: author => 'In author context',
13823: course => 'In course context',
13824: );
13825: my @fields = ('lastname','firstname','middlename','generation',
13826: 'permanentemail','id');
13827: my %roles = (
13828: author => ['ca','aa'],
13829: course => ['st','ep','ta','in','cr'],
13830: );
13831: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13832: foreach my $context (@contexts) {
13833: foreach my $role (@{$roles{$context}}) {
13834: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
13835: foreach my $item (@fields) {
13836: if (grep(/^\Q$item\E$/,@modifiable)) {
13837: $modifyhash{$context}{$role}{$item} = 1;
13838: } else {
13839: $modifyhash{$context}{$role}{$item} = 0;
13840: }
13841: }
13842: }
13843: if (ref($curr_usermodification{$context}) eq 'HASH') {
13844: foreach my $role (@{$roles{$context}}) {
13845: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
13846: foreach my $field (@fields) {
13847: if ($modifyhash{$context}{$role}{$field} ne
13848: $curr_usermodification{$context}{$role}{$field}) {
13849: push(@{$changes{$context}},$role);
13850: last;
13851: }
13852: }
13853: }
13854: }
13855: } else {
13856: foreach my $context (@contexts) {
13857: foreach my $role (@{$roles{$context}}) {
13858: push(@{$changes{$context}},$role);
13859: }
13860: }
13861: }
13862: }
13863: my %usermodification_hash = (
13864: usermodification => \%modifyhash,
13865: );
13866: my $putresult = &Apache::lonnet::put_dom('configuration',
13867: \%usermodification_hash,$dom);
13868: if ($putresult eq 'ok') {
13869: if (keys(%changes) > 0) {
13870: $resulttext = &mt('Changes made: ').'<ul>';
13871: foreach my $context (@contexts) {
13872: if (ref($changes{$context}) eq 'ARRAY') {
13873: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
13874: if (ref($changes{$context}) eq 'ARRAY') {
13875: foreach my $role (@{$changes{$context}}) {
13876: my $rolename;
1.224 raeburn 13877: if ($role eq 'cr') {
13878: $rolename = &mt('Custom');
1.33 raeburn 13879: } else {
1.224 raeburn 13880: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 13881: }
13882: my @modifiable;
1.224 raeburn 13883: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 13884: foreach my $field (@fields) {
13885: if ($modifyhash{$context}{$role}{$field}) {
13886: push(@modifiable,$fieldtitles{$field});
13887: }
13888: }
13889: if (@modifiable > 0) {
13890: $resulttext .= join(', ',@modifiable);
13891: } else {
13892: $resulttext .= &mt('none');
13893: }
13894: $resulttext .= '</li>';
13895: }
13896: $resulttext .= '</ul></li>';
13897: }
13898: }
13899: }
13900: $resulttext .= '</ul>';
13901: } else {
13902: $resulttext = &mt('No changes made to user modification settings');
13903: }
13904: } else {
13905: $resulttext = '<span class="LC_error">'.
13906: &mt('An error occurred: [_1]',$putresult).'</span>';
13907: }
13908: return $resulttext;
13909: }
13910:
1.43 raeburn 13911: sub modify_defaults {
1.212 raeburn 13912: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 13913: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 13914: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 13915: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
13916: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.43 raeburn 13917: my @authtypes = ('internal','krb4','krb5','localauth');
13918: foreach my $item (@items) {
13919: $newvalues{$item} = $env{'form.'.$item};
13920: if ($item eq 'auth_def') {
13921: if ($newvalues{$item} ne '') {
13922: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
13923: push(@errors,$item);
13924: }
13925: }
13926: } elsif ($item eq 'lang_def') {
13927: if ($newvalues{$item} ne '') {
13928: if ($newvalues{$item} =~ /^(\w+)/) {
13929: my $langcode = $1;
1.103 raeburn 13930: if ($langcode ne 'x_chef') {
13931: if (code2language($langcode) eq '') {
13932: push(@errors,$item);
13933: }
1.43 raeburn 13934: }
13935: } else {
13936: push(@errors,$item);
13937: }
13938: }
1.54 raeburn 13939: } elsif ($item eq 'timezone_def') {
13940: if ($newvalues{$item} ne '') {
1.62 raeburn 13941: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 13942: push(@errors,$item);
13943: }
13944: }
1.68 raeburn 13945: } elsif ($item eq 'datelocale_def') {
13946: if ($newvalues{$item} ne '') {
13947: my @datelocale_ids = DateTime::Locale->ids();
13948: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
13949: push(@errors,$item);
13950: }
13951: }
1.141 raeburn 13952: } elsif ($item eq 'portal_def') {
13953: if ($newvalues{$item} ne '') {
13954: 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])\/?$/) {
13955: push(@errors,$item);
13956: }
13957: }
1.294 raeburn 13958: } elsif ($item eq 'intauth_cost') {
13959: if ($newvalues{$item} ne '') {
13960: if ($newvalues{$item} =~ /\D/) {
13961: push(@errors,$item);
13962: }
13963: }
13964: } elsif ($item eq 'intauth_check') {
13965: if ($newvalues{$item} ne '') {
13966: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
13967: push(@errors,$item);
13968: }
13969: }
13970: } elsif ($item eq 'intauth_switch') {
13971: if ($newvalues{$item} ne '') {
13972: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
13973: push(@errors,$item);
13974: }
13975: }
1.43 raeburn 13976: }
13977: if (grep(/^\Q$item\E$/,@errors)) {
13978: $newvalues{$item} = $domdefaults{$item};
13979: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
13980: $changes{$item} = 1;
13981: }
1.72 raeburn 13982: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 13983: }
13984: my %defaults_hash = (
1.72 raeburn 13985: defaults => \%newvalues,
13986: );
1.43 raeburn 13987: my $title = &defaults_titles();
1.236 raeburn 13988:
13989: my $currinststatus;
13990: if (ref($domconfig{'inststatus'}) eq 'HASH') {
13991: $currinststatus = $domconfig{'inststatus'};
13992: } else {
13993: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13994: $currinststatus = {
13995: inststatustypes => $usertypes,
13996: inststatusorder => $types,
13997: inststatusguest => [],
13998: };
13999: }
14000: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
14001: my @allpos;
14002: my %alltypes;
1.305 raeburn 14003: my @inststatusguest;
14004: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
14005: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
14006: unless (grep(/^\Q$type\E$/,@todelete)) {
14007: push(@inststatusguest,$type);
14008: }
14009: }
14010: }
14011: my ($currtitles,$currorder);
1.236 raeburn 14012: if (ref($currinststatus) eq 'HASH') {
14013: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
14014: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
14015: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
14016: if ($currinststatus->{inststatustypes}->{$type} ne '') {
14017: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
14018: }
14019: }
14020: unless (grep(/^\Q$type\E$/,@todelete)) {
14021: my $position = $env{'form.inststatus_pos_'.$type};
14022: $position =~ s/\D+//g;
14023: $allpos[$position] = $type;
14024: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
14025: $alltypes{$type} =~ s/`//g;
14026: }
14027: }
14028: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
14029: $currtitles =~ s/,$//;
14030: }
14031: }
14032: if ($env{'form.addinststatus'}) {
14033: my $newtype = $env{'form.addinststatus'};
14034: $newtype =~ s/\W//g;
14035: unless (exists($alltypes{$newtype})) {
14036: $alltypes{$newtype} = $env{'form.addinststatus_title'};
14037: $alltypes{$newtype} =~ s/`//g;
14038: my $position = $env{'form.addinststatus_pos'};
14039: $position =~ s/\D+//g;
14040: if ($position ne '') {
14041: $allpos[$position] = $newtype;
14042: }
14043: }
14044: }
1.305 raeburn 14045: my @orderedstatus;
1.236 raeburn 14046: foreach my $type (@allpos) {
14047: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
14048: push(@orderedstatus,$type);
14049: }
14050: }
14051: foreach my $type (keys(%alltypes)) {
14052: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
14053: delete($alltypes{$type});
14054: }
14055: }
14056: $defaults_hash{'inststatus'} = {
14057: inststatustypes => \%alltypes,
14058: inststatusorder => \@orderedstatus,
1.305 raeburn 14059: inststatusguest => \@inststatusguest,
1.236 raeburn 14060: };
14061: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
14062: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
14063: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
14064: }
14065: }
14066: if ($currorder ne join(',',@orderedstatus)) {
14067: $changes{'inststatus'}{'inststatusorder'} = 1;
14068: }
14069: my $newtitles;
14070: foreach my $item (@orderedstatus) {
14071: $newtitles .= $alltypes{$item}.',';
14072: }
14073: $newtitles =~ s/,$//;
14074: if ($currtitles ne $newtitles) {
14075: $changes{'inststatus'}{'inststatustypes'} = 1;
14076: }
1.43 raeburn 14077: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
14078: $dom);
14079: if ($putresult eq 'ok') {
14080: if (keys(%changes) > 0) {
14081: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 14082: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 14083: 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";
14084: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 14085: if ($item eq 'inststatus') {
14086: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 14087: if (@orderedstatus) {
1.236 raeburn 14088: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
14089: foreach my $type (@orderedstatus) {
14090: $resulttext .= $alltypes{$type}.', ';
14091: }
14092: $resulttext =~ s/, $//;
14093: $resulttext .= '</li>';
1.305 raeburn 14094: } else {
14095: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 14096: }
14097: }
14098: } else {
14099: my $value = $env{'form.'.$item};
14100: if ($value eq '') {
14101: $value = &mt('none');
14102: } elsif ($item eq 'auth_def') {
14103: my %authnames = &authtype_names();
14104: my %shortauth = (
14105: internal => 'int',
14106: krb4 => 'krb4',
14107: krb5 => 'krb5',
14108: localauth => 'loc',
14109: );
14110: $value = $authnames{$shortauth{$value}};
1.294 raeburn 14111: } elsif ($item eq 'intauth_switch') {
14112: my %optiondesc = &Apache::lonlocal::texthash (
14113: 0 => 'No',
14114: 1 => 'Yes',
14115: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
14116: );
14117: if ($value =~ /^(0|1|2)$/) {
14118: $value = $optiondesc{$value};
14119: } else {
14120: $value = &mt('none -- defaults to No');
14121: }
14122: } elsif ($item eq 'intauth_check') {
14123: my %optiondesc = &Apache::lonlocal::texthash (
14124: 0 => 'No',
14125: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
14126: 2 => 'Yes, disallow login if stored cost is less than domain default',
14127: );
14128: if ($value =~ /^(0|1|2)$/) {
14129: $value = $optiondesc{$value};
14130: } else {
14131: $value = &mt('none -- defaults to No');
14132: }
1.236 raeburn 14133: }
14134: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
14135: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 14136: }
14137: }
14138: $resulttext .= '</ul>';
14139: $mailmsgtext .= "\n";
14140: my $cachetime = 24*60*60;
1.72 raeburn 14141: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 14142: if (ref($lastactref) eq 'HASH') {
14143: $lastactref->{'domdefaults'} = 1;
14144: }
1.68 raeburn 14145: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 14146: my $notify = 1;
14147: if (ref($domconfig{'contacts'}) eq 'HASH') {
14148: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
14149: $notify = 0;
14150: }
14151: }
14152: if ($notify) {
14153: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
14154: "LON-CAPA Domain Settings Change - $dom",
14155: $mailmsgtext);
14156: }
1.54 raeburn 14157: }
1.43 raeburn 14158: } else {
1.54 raeburn 14159: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 14160: }
14161: } else {
14162: $resulttext = '<span class="LC_error">'.
14163: &mt('An error occurred: [_1]',$putresult).'</span>';
14164: }
14165: if (@errors > 0) {
14166: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
14167: foreach my $item (@errors) {
14168: $resulttext .= ' "'.$title->{$item}.'",';
14169: }
14170: $resulttext =~ s/,$//;
14171: }
14172: return $resulttext;
14173: }
14174:
1.46 raeburn 14175: sub modify_scantron {
1.205 raeburn 14176: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 14177: my ($resulttext,%confhash,%changes,$errors);
14178: my $custom = 'custom.tab';
14179: my $default = 'default.tab';
14180: my $servadm = $r->dir_config('lonAdmEMail');
14181: my ($configuserok,$author_ok,$switchserver) =
14182: &config_check($dom,$confname,$servadm);
14183: if ($env{'form.scantronformat.filename'} ne '') {
14184: my $error;
14185: if ($configuserok eq 'ok') {
14186: if ($switchserver) {
1.130 raeburn 14187: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 14188: } else {
14189: if ($author_ok eq 'ok') {
14190: my ($result,$scantronurl) =
14191: &publishlogo($r,'upload','scantronformat',$dom,
14192: $confname,'scantron','','',$custom);
14193: if ($result eq 'ok') {
14194: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 14195: $changes{'scantronformat'} = 1;
1.46 raeburn 14196: } else {
14197: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
14198: }
14199: } else {
14200: $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);
14201: }
14202: }
14203: } else {
14204: $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);
14205: }
14206: if ($error) {
14207: &Apache::lonnet::logthis($error);
14208: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14209: }
14210: }
1.48 raeburn 14211: if (ref($domconfig{'scantron'}) eq 'HASH') {
14212: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
14213: if ($env{'form.scantronformat_del'}) {
14214: $confhash{'scantron'}{'scantronformat'} = '';
14215: $changes{'scantronformat'} = 1;
1.46 raeburn 14216: }
14217: }
14218: }
14219: if (keys(%confhash) > 0) {
14220: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
14221: $dom);
14222: if ($putresult eq 'ok') {
14223: if (keys(%changes) > 0) {
1.48 raeburn 14224: if (ref($confhash{'scantron'}) eq 'HASH') {
14225: $resulttext = &mt('Changes made:').'<ul>';
14226: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 14227: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 14228: } else {
1.130 raeburn 14229: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 14230: }
1.48 raeburn 14231: $resulttext .= '</ul>';
14232: } else {
1.130 raeburn 14233: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 14234: }
14235: $resulttext .= '</ul>';
14236: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 14237: if (ref($lastactref) eq 'HASH') {
14238: $lastactref->{'domainconfig'} = 1;
14239: }
1.46 raeburn 14240: } else {
1.130 raeburn 14241: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 14242: }
14243: } else {
14244: $resulttext = '<span class="LC_error">'.
14245: &mt('An error occurred: [_1]',$putresult).'</span>';
14246: }
14247: } else {
1.130 raeburn 14248: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 14249: }
14250: if ($errors) {
14251: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14252: $errors.'</ul>';
14253: }
14254: return $resulttext;
14255: }
14256:
1.48 raeburn 14257: sub modify_coursecategories {
1.239 raeburn 14258: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 14259: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
14260: $cathash);
1.48 raeburn 14261: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 14262: my @catitems = ('unauth','auth');
14263: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 14264: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 14265: $cathash = $domconfig{'coursecategories'}{'cats'};
14266: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
14267: $changes{'togglecats'} = 1;
14268: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
14269: }
14270: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
14271: $changes{'categorize'} = 1;
14272: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
14273: }
1.120 raeburn 14274: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
14275: $changes{'togglecatscomm'} = 1;
14276: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
14277: }
14278: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
14279: $changes{'categorizecomm'} = 1;
14280: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 14281:
14282: }
14283: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
14284: $changes{'togglecatsplace'} = 1;
14285: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
14286: }
14287: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
14288: $changes{'categorizeplace'} = 1;
14289: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 14290: }
1.238 raeburn 14291: foreach my $item (@catitems) {
14292: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
14293: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
14294: $changes{$item} = 1;
14295: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
14296: }
14297: }
14298: }
1.57 raeburn 14299: } else {
14300: $changes{'togglecats'} = 1;
14301: $changes{'categorize'} = 1;
1.124 raeburn 14302: $changes{'togglecatscomm'} = 1;
14303: $changes{'categorizecomm'} = 1;
1.272 raeburn 14304: $changes{'togglecatsplace'} = 1;
14305: $changes{'categorizeplace'} = 1;
1.87 raeburn 14306: $domconfig{'coursecategories'} = {
14307: togglecats => $env{'form.togglecats'},
14308: categorize => $env{'form.categorize'},
1.124 raeburn 14309: togglecatscomm => $env{'form.togglecatscomm'},
14310: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 14311: togglecatsplace => $env{'form.togglecatsplace'},
14312: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 14313: };
1.238 raeburn 14314: foreach my $item (@catitems) {
14315: if ($env{'form.coursecat_'.$item} ne 'std') {
14316: $changes{$item} = 1;
14317: }
14318: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
14319: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
14320: }
14321: }
1.57 raeburn 14322: }
14323: if (ref($cathash) eq 'HASH') {
14324: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 14325: push (@deletecategory,'instcode::0');
14326: }
1.120 raeburn 14327: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
14328: push(@deletecategory,'communities::0');
14329: }
1.272 raeburn 14330: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
14331: push(@deletecategory,'placement::0');
14332: }
1.48 raeburn 14333: }
1.57 raeburn 14334: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
14335: if (ref($cathash) eq 'HASH') {
1.48 raeburn 14336: if (@deletecategory > 0) {
14337: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 14338: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 14339: foreach my $item (@deletecategory) {
1.57 raeburn 14340: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
14341: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 14342: $deletions{$item} = 1;
1.57 raeburn 14343: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 14344: }
14345: }
14346: }
1.57 raeburn 14347: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 14348: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 14349: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 14350: $reorderings{$item} = 1;
1.57 raeburn 14351: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 14352: }
14353: if ($env{'form.addcategory_name_'.$item} ne '') {
14354: my $newcat = $env{'form.addcategory_name_'.$item};
14355: my $newdepth = $depth+1;
14356: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 14357: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 14358: $adds{$newitem} = 1;
14359: }
14360: if ($env{'form.subcat_'.$item} ne '') {
14361: my $newcat = $env{'form.subcat_'.$item};
14362: my $newdepth = $depth+1;
14363: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 14364: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 14365: $adds{$newitem} = 1;
14366: }
14367: }
14368: }
14369: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 14370: if (ref($cathash) eq 'HASH') {
1.48 raeburn 14371: my $newitem = 'instcode::0';
1.57 raeburn 14372: if ($cathash->{$newitem} eq '') {
14373: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 14374: $adds{$newitem} = 1;
14375: }
14376: } else {
14377: my $newitem = 'instcode::0';
1.57 raeburn 14378: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 14379: $adds{$newitem} = 1;
14380: }
14381: }
1.120 raeburn 14382: if ($env{'form.communities'} eq '1') {
14383: if (ref($cathash) eq 'HASH') {
14384: my $newitem = 'communities::0';
14385: if ($cathash->{$newitem} eq '') {
14386: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
14387: $adds{$newitem} = 1;
14388: }
14389: } else {
14390: my $newitem = 'communities::0';
14391: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
14392: $adds{$newitem} = 1;
14393: }
14394: }
1.272 raeburn 14395: if ($env{'form.placement'} eq '1') {
14396: if (ref($cathash) eq 'HASH') {
14397: my $newitem = 'placement::0';
14398: if ($cathash->{$newitem} eq '') {
14399: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
14400: $adds{$newitem} = 1;
14401: }
14402: } else {
14403: my $newitem = 'placement::0';
14404: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
14405: $adds{$newitem} = 1;
14406: }
14407: }
1.48 raeburn 14408: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 14409: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 14410: ($env{'form.addcategory_name'} ne 'communities') &&
14411: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 14412: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
14413: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
14414: $adds{$newitem} = 1;
14415: }
1.48 raeburn 14416: }
1.57 raeburn 14417: my $putresult;
1.48 raeburn 14418: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14419: if (keys(%deletions) > 0) {
14420: foreach my $key (keys(%deletions)) {
14421: if ($predelallitems{$key} ne '') {
14422: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
14423: }
14424: }
14425: }
14426: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 14427: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 14428: if (ref($chkcats[0]) eq 'ARRAY') {
14429: my $depth = 0;
14430: my $chg = 0;
14431: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
14432: my $name = $chkcats[0][$i];
14433: my $item;
14434: if ($name eq '') {
14435: $chg ++;
14436: } else {
14437: $item = &escape($name).'::0';
14438: if ($chg) {
1.57 raeburn 14439: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 14440: }
14441: $depth ++;
1.57 raeburn 14442: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 14443: $depth --;
14444: }
14445: }
14446: }
1.57 raeburn 14447: }
14448: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14449: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 14450: if ($putresult eq 'ok') {
1.57 raeburn 14451: my %title = (
1.120 raeburn 14452: togglecats => 'Show/Hide a course in catalog',
14453: categorize => 'Assign a category to a course',
14454: togglecatscomm => 'Show/Hide a community in catalog',
14455: categorizecomm => 'Assign a category to a community',
1.57 raeburn 14456: );
14457: my %level = (
1.120 raeburn 14458: dom => 'set in Domain ("Modify Course/Community")',
14459: crs => 'set in Course ("Course Configuration")',
14460: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 14461: none => 'No catalog',
14462: std => 'Standard catalog',
14463: domonly => 'Domain-only catalog',
14464: codesrch => 'Code search form',
1.57 raeburn 14465: );
1.48 raeburn 14466: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 14467: if ($changes{'togglecats'}) {
14468: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
14469: }
14470: if ($changes{'categorize'}) {
14471: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 14472: }
1.120 raeburn 14473: if ($changes{'togglecatscomm'}) {
14474: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
14475: }
14476: if ($changes{'categorizecomm'}) {
14477: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
14478: }
1.238 raeburn 14479: if ($changes{'unauth'}) {
14480: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
14481: }
14482: if ($changes{'auth'}) {
14483: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
14484: }
1.57 raeburn 14485: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14486: my $cathash;
14487: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
14488: $cathash = $domconfig{'coursecategories'}{'cats'};
14489: } else {
14490: $cathash = {};
14491: }
14492: my (@cats,@trails,%allitems);
14493: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
14494: if (keys(%deletions) > 0) {
14495: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
14496: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
14497: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
14498: }
14499: $resulttext .= '</ul></li>';
14500: }
14501: if (keys(%reorderings) > 0) {
14502: my %sort_by_trail;
14503: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
14504: foreach my $key (keys(%reorderings)) {
14505: if ($allitems{$key} ne '') {
14506: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
14507: }
1.48 raeburn 14508: }
1.57 raeburn 14509: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
14510: $resulttext .= '<li>'.$trails[$trail].'</li>';
14511: }
14512: $resulttext .= '</ul></li>';
1.48 raeburn 14513: }
1.57 raeburn 14514: if (keys(%adds) > 0) {
14515: my %sort_by_trail;
14516: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
14517: foreach my $key (keys(%adds)) {
14518: if ($allitems{$key} ne '') {
14519: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
14520: }
14521: }
14522: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
14523: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 14524: }
1.57 raeburn 14525: $resulttext .= '</ul></li>';
1.48 raeburn 14526: }
14527: }
14528: $resulttext .= '</ul>';
1.239 raeburn 14529: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 14530: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
14531: if ($changes{'auth'}) {
14532: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
14533: }
14534: if ($changes{'unauth'}) {
14535: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
14536: }
14537: my $cachetime = 24*60*60;
14538: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 14539: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 14540: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 14541: }
14542: }
1.48 raeburn 14543: } else {
14544: $resulttext = '<span class="LC_error">'.
1.57 raeburn 14545: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 14546: }
14547: } else {
1.120 raeburn 14548: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 14549: }
14550: return $resulttext;
14551: }
14552:
1.69 raeburn 14553: sub modify_serverstatuses {
14554: my ($dom,%domconfig) = @_;
14555: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
14556: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
14557: %currserverstatus = %{$domconfig{'serverstatuses'}};
14558: }
14559: my @pages = &serverstatus_pages();
14560: foreach my $type (@pages) {
14561: $newserverstatus{$type}{'namedusers'} = '';
14562: $newserverstatus{$type}{'machines'} = '';
14563: if (defined($env{'form.'.$type.'_namedusers'})) {
14564: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
14565: my @okusers;
14566: foreach my $user (@users) {
14567: my ($uname,$udom) = split(/:/,$user);
14568: if (($udom =~ /^$match_domain$/) &&
14569: (&Apache::lonnet::domain($udom)) &&
14570: ($uname =~ /^$match_username$/)) {
14571: if (!grep(/^\Q$user\E/,@okusers)) {
14572: push(@okusers,$user);
14573: }
14574: }
14575: }
14576: if (@okusers > 0) {
14577: @okusers = sort(@okusers);
14578: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
14579: }
14580: }
14581: if (defined($env{'form.'.$type.'_machines'})) {
14582: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
14583: my @okmachines;
14584: foreach my $ip (@machines) {
14585: my @parts = split(/\./,$ip);
14586: next if (@parts < 4);
14587: my $badip = 0;
14588: for (my $i=0; $i<4; $i++) {
14589: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
14590: $badip = 1;
14591: last;
14592: }
14593: }
14594: if (!$badip) {
14595: push(@okmachines,$ip);
14596: }
14597: }
14598: @okmachines = sort(@okmachines);
14599: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
14600: }
14601: }
14602: my %serverstatushash = (
14603: serverstatuses => \%newserverstatus,
14604: );
14605: foreach my $type (@pages) {
1.83 raeburn 14606: foreach my $setting ('namedusers','machines') {
1.84 raeburn 14607: my (@current,@new);
1.83 raeburn 14608: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 14609: if ($currserverstatus{$type}{$setting} ne '') {
14610: @current = split(/,/,$currserverstatus{$type}{$setting});
14611: }
14612: }
14613: if ($newserverstatus{$type}{$setting} ne '') {
14614: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 14615: }
14616: if (@current > 0) {
14617: if (@new > 0) {
14618: foreach my $item (@current) {
14619: if (!grep(/^\Q$item\E$/,@new)) {
14620: $changes{$type}{$setting} = 1;
1.82 raeburn 14621: last;
14622: }
14623: }
1.84 raeburn 14624: foreach my $item (@new) {
14625: if (!grep(/^\Q$item\E$/,@current)) {
14626: $changes{$type}{$setting} = 1;
14627: last;
1.82 raeburn 14628: }
14629: }
14630: } else {
1.83 raeburn 14631: $changes{$type}{$setting} = 1;
1.69 raeburn 14632: }
1.83 raeburn 14633: } elsif (@new > 0) {
14634: $changes{$type}{$setting} = 1;
1.69 raeburn 14635: }
14636: }
14637: }
14638: if (keys(%changes) > 0) {
1.81 raeburn 14639: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 14640: my $putresult = &Apache::lonnet::put_dom('configuration',
14641: \%serverstatushash,$dom);
14642: if ($putresult eq 'ok') {
14643: $resulttext .= &mt('Changes made:').'<ul>';
14644: foreach my $type (@pages) {
1.84 raeburn 14645: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 14646: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 14647: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 14648: if ($newserverstatus{$type}{'namedusers'} eq '') {
14649: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
14650: } else {
14651: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
14652: }
1.84 raeburn 14653: }
14654: if ($changes{$type}{'machines'}) {
1.69 raeburn 14655: if ($newserverstatus{$type}{'machines'} eq '') {
14656: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
14657: } else {
14658: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
14659: }
14660:
14661: }
14662: $resulttext .= '</ul></li>';
14663: }
14664: }
14665: $resulttext .= '</ul>';
14666: } else {
14667: $resulttext = '<span class="LC_error">'.
14668: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
14669:
14670: }
14671: } else {
14672: $resulttext = &mt('No changes made to access to server status pages');
14673: }
14674: return $resulttext;
14675: }
14676:
1.118 jms 14677: sub modify_helpsettings {
1.285 raeburn 14678: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 14679: my ($resulttext,$errors,%changes,%helphash);
14680: my %defaultchecked = ('submitbugs' => 'on');
14681: my @offon = ('off','on');
1.118 jms 14682: my @toggles = ('submitbugs');
1.285 raeburn 14683: my %current = ('submitbugs' => '',
14684: 'adhoc' => {},
14685: );
1.118 jms 14686: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 14687: %current = %{$domconfig{'helpsettings'}};
14688: }
1.285 raeburn 14689: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 14690: foreach my $item (@toggles) {
14691: if ($defaultchecked{$item} eq 'on') {
14692: if ($current{$item} eq '') {
14693: if ($env{'form.'.$item} eq '0') {
14694: $changes{$item} = 1;
14695: }
14696: } elsif ($current{$item} ne $env{'form.'.$item}) {
14697: $changes{$item} = 1;
14698: }
14699: } elsif ($defaultchecked{$item} eq 'off') {
14700: if ($current{$item} eq '') {
14701: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 14702: $changes{$item} = 1;
14703: }
1.282 raeburn 14704: } elsif ($current{$item} ne $env{'form.'.$item}) {
14705: $changes{$item} = 1;
14706: }
14707: }
14708: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
14709: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
14710: }
14711: }
1.285 raeburn 14712: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 14713: my $confname = $dom.'-domainconfig';
14714: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 14715: my (@allpos,%newsettings,%changedprivs,$newrole);
14716: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 14717: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 14718: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 14719: my %lt = &Apache::lonlocal::texthash(
14720: s => 'system',
14721: d => 'domain',
14722: order => 'Display order',
14723: access => 'Role usage',
1.291 raeburn 14724: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 14725: dh => 'All with domain helpdesk role',
14726: da => 'All with domain helpdesk assistant role',
1.285 raeburn 14727: none => 'None',
14728: status => 'Determined based on institutional status',
14729: inc => 'Include all, but exclude specific personnel',
14730: exc => 'Exclude all, but include specific personnel',
14731: );
14732: for (my $num=0; $num<=$maxnum; $num++) {
14733: my ($prefix,$identifier,$rolename,%curr);
14734: if ($num == $maxnum) {
14735: next unless ($env{'form.newcusthelp'} == $maxnum);
14736: $identifier = 'custhelp'.$num;
14737: $prefix = 'helproles_'.$num;
14738: $rolename = $env{'form.custhelpname'.$num};
14739: $rolename=~s/[^A-Za-z0-9]//gs;
14740: next if ($rolename eq '');
14741: next if (exists($existing{'rolesdef_'.$rolename}));
14742: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
14743: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
14744: $newprivs{'c'},$confname,$dom);
14745: if ($result ne 'ok') {
14746: $errors .= '<li><span class="LC_error">'.
14747: &mt('An error occurred storing the new custom role: [_1]',
14748: $result).'</span></li>';
14749: next;
14750: } else {
14751: $changedprivs{$rolename} = \%newprivs;
14752: $newrole = $rolename;
14753: }
14754: } else {
14755: $prefix = 'helproles_'.$num;
14756: $rolename = $env{'form.'.$prefix};
14757: next if ($rolename eq '');
14758: next unless (exists($existing{'rolesdef_'.$rolename}));
14759: $identifier = 'custhelp'.$num;
14760: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
14761: my %currprivs;
1.289 raeburn 14762: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 14763: split(/\_/,$existing{'rolesdef_'.$rolename});
14764: foreach my $level ('c','d','s') {
14765: if ($newprivs{$level} ne $currprivs{$level}) {
14766: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
14767: $newprivs{'c'},$confname,$dom);
14768: if ($result ne 'ok') {
14769: $errors .= '<li><span class="LC_error">'.
14770: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
14771: $rolename,$result).'</span></li>';
14772: } else {
14773: $changedprivs{$rolename} = \%newprivs;
14774: }
14775: last;
14776: }
14777: }
14778: if (ref($current{'adhoc'}) eq 'HASH') {
14779: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
14780: %curr = %{$current{'adhoc'}{$rolename}};
14781: }
14782: }
14783: }
14784: my $newpos = $env{'form.'.$prefix.'_pos'};
14785: $newpos =~ s/\D+//g;
14786: $allpos[$newpos] = $rolename;
14787: my $newdesc = $env{'form.'.$prefix.'_desc'};
14788: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
14789: if ($curr{'desc'}) {
14790: if ($curr{'desc'} ne $newdesc) {
14791: $changes{'customrole'}{$rolename}{'desc'} = 1;
14792: $newsettings{$rolename}{'desc'} = $newdesc;
14793: }
14794: } elsif ($newdesc ne '') {
14795: $changes{'customrole'}{$rolename}{'desc'} = 1;
14796: $newsettings{$rolename}{'desc'} = $newdesc;
14797: }
14798: my $access = $env{'form.'.$prefix.'_access'};
14799: if (grep(/^\Q$access\E$/,@accesstypes)) {
14800: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
14801: if ($access eq 'status') {
14802: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
14803: if (scalar(@statuses) == 0) {
1.289 raeburn 14804: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 14805: } else {
14806: my (@shownstatus,$numtypes);
14807: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
14808: if (ref($types) eq 'ARRAY') {
14809: $numtypes = scalar(@{$types});
14810: foreach my $type (sort(@statuses)) {
14811: if ($type eq 'default') {
14812: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
14813: } elsif (grep(/^\Q$type\E$/,@{$types})) {
14814: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
14815: push(@shownstatus,$usertypes->{$type});
14816: }
14817: }
14818: }
14819: if (grep(/^default$/,@statuses)) {
14820: push(@shownstatus,$othertitle);
14821: }
14822: if (scalar(@shownstatus) == 1+$numtypes) {
14823: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
14824: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
14825: } else {
14826: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
14827: if (ref($curr{'status'}) eq 'ARRAY') {
14828: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
14829: if (@diffs) {
14830: $changes{'customrole'}{$rolename}{$access} = 1;
14831: }
14832: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
14833: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 14834: }
1.166 raeburn 14835: }
14836: }
1.285 raeburn 14837: } elsif (($access eq 'inc') || ($access eq 'exc')) {
14838: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
14839: my @newspecstaff;
14840: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
14841: foreach my $person (sort(@personnel)) {
14842: if ($domhelpdesk{$person}) {
14843: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
14844: }
14845: }
14846: if (ref($curr{$access}) eq 'ARRAY') {
14847: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
14848: if (@diffs) {
14849: $changes{'customrole'}{$rolename}{$access} = 1;
14850: }
14851: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
14852: $changes{'customrole'}{$rolename}{$access} = 1;
14853: }
14854: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
14855: my ($uname,$udom) = split(/:/,$person);
14856: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
14857: }
14858: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 14859: }
1.285 raeburn 14860: } else {
14861: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
14862: }
14863: unless ($curr{'access'} eq $access) {
14864: $changes{'customrole'}{$rolename}{'access'} = 1;
14865: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 14866: }
14867: }
1.285 raeburn 14868: if (@allpos > 0) {
14869: my $idx = 0;
14870: foreach my $rolename (@allpos) {
14871: if ($rolename ne '') {
14872: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
14873: if (ref($current{'adhoc'}) eq 'HASH') {
14874: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
14875: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
14876: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 14877: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 14878: }
14879: }
1.282 raeburn 14880: }
1.285 raeburn 14881: $idx ++;
1.166 raeburn 14882: }
14883: }
1.118 jms 14884: }
1.123 jms 14885: my $putresult;
14886: if (keys(%changes) > 0) {
1.166 raeburn 14887: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 14888: if ($putresult eq 'ok') {
1.285 raeburn 14889: if (ref($helphash{'helpsettings'}) eq 'HASH') {
14890: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
14891: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
14892: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
14893: }
14894: }
14895: my $cachetime = 24*60*60;
14896: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14897: if (ref($lastactref) eq 'HASH') {
14898: $lastactref->{'domdefaults'} = 1;
14899: }
14900: } else {
14901: $errors .= '<li><span class="LC_error">'.
14902: &mt('An error occurred storing the settings: [_1]',
14903: $putresult).'</span></li>';
14904: }
14905: }
14906: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
14907: $resulttext = &mt('Changes made:').'<ul>';
14908: my (%shownprivs,@levelorder);
14909: @levelorder = ('c','d','s');
14910: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 14911: foreach my $item (sort(keys(%changes))) {
14912: if ($item eq 'submitbugs') {
14913: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
14914: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
14915: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 14916: } elsif ($item eq 'customrole') {
14917: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 14918: my @keyorder = ('order','desc','access','status','exc','inc');
14919: my %keytext = &Apache::lonlocal::texthash(
14920: order => 'Order',
14921: desc => 'Role description',
14922: access => 'Role usage',
1.300 droeschl 14923: status => 'Allowed institutional types',
1.285 raeburn 14924: exc => 'Allowed personnel',
14925: inc => 'Disallowed personnel',
14926: );
1.282 raeburn 14927: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 14928: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
14929: if ($role eq $newrole) {
14930: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
14931: $role).'<ul>';
14932: } else {
14933: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
14934: $role).'<ul>';
14935: }
14936: foreach my $key (@keyorder) {
14937: if ($changes{'customrole'}{$role}{$key}) {
14938: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
14939: $keytext{$key},$newsettings{$role}{$key}).
14940: '</li>';
14941: }
14942: }
14943: if (ref($changedprivs{$role}) eq 'HASH') {
14944: $shownprivs{$role} = 1;
14945: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
14946: foreach my $level (@levelorder) {
14947: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
14948: next if ($item eq '');
14949: my ($priv) = split(/\&/,$item,2);
14950: if (&Apache::lonnet::plaintext($priv)) {
14951: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
14952: unless ($level eq 'c') {
14953: $resulttext .= ' ('.$lt{$level}.')';
14954: }
14955: $resulttext .= '</li>';
14956: }
14957: }
14958: }
14959: $resulttext .= '</ul>';
14960: }
14961: $resulttext .= '</ul></li>';
14962: }
14963: }
14964: }
14965: }
14966: }
14967: }
14968: if (keys(%changedprivs)) {
14969: foreach my $role (sort(keys(%changedprivs))) {
14970: unless ($shownprivs{$role}) {
14971: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
14972: $role).'<ul>'.
14973: '<li>'.&mt('Privileges set to :').'<ul>';
14974: foreach my $level (@levelorder) {
14975: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
14976: next if ($item eq '');
14977: my ($priv) = split(/\&/,$item,2);
14978: if (&Apache::lonnet::plaintext($priv)) {
14979: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
14980: unless ($level eq 'c') {
14981: $resulttext .= ' ('.$lt{$level}.')';
14982: }
14983: $resulttext .= '</li>';
14984: }
1.282 raeburn 14985: }
14986: }
1.285 raeburn 14987: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 14988: }
14989: }
14990: }
1.285 raeburn 14991: $resulttext .= '</ul>';
14992: } else {
14993: $resulttext = &mt('No changes made to help settings');
1.118 jms 14994: }
14995: if ($errors) {
1.168 raeburn 14996: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 14997: $errors.'</ul>';
1.118 jms 14998: }
14999: return $resulttext;
15000: }
15001:
1.121 raeburn 15002: sub modify_coursedefaults {
1.212 raeburn 15003: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 15004: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 15005: my %defaultchecked = (
15006: 'canuse_pdfforms' => 'off',
15007: 'uselcmath' => 'on',
15008: 'usejsme' => 'on'
15009: );
15010: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 15011: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 15012: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
15013: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
15014: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 15015: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 15016: my %staticdefaults = (
15017: anonsurvey_threshold => 10,
15018: uploadquota => 500,
1.257 raeburn 15019: postsubmit => 60,
1.276 raeburn 15020: mysqltables => 172800,
1.198 raeburn 15021: );
1.314 raeburn 15022: my %texoptions = (
15023: MathJax => 'MathJax',
15024: mimetex => &mt('Convert to Images'),
15025: tth => &mt('TeX to HTML'),
15026: );
1.121 raeburn 15027: $defaultshash{'coursedefaults'} = {};
15028:
15029: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
15030: if ($domconfig{'coursedefaults'} eq '') {
15031: $domconfig{'coursedefaults'} = {};
15032: }
15033: }
15034:
15035: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
15036: foreach my $item (@toggles) {
15037: if ($defaultchecked{$item} eq 'on') {
15038: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15039: ($env{'form.'.$item} eq '0')) {
15040: $changes{$item} = 1;
1.192 raeburn 15041: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 15042: $changes{$item} = 1;
15043: }
15044: } elsif ($defaultchecked{$item} eq 'off') {
15045: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15046: ($env{'form.'.$item} eq '1')) {
15047: $changes{$item} = 1;
15048: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
15049: $changes{$item} = 1;
15050: }
15051: }
15052: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
15053: }
1.198 raeburn 15054: foreach my $item (@numbers) {
15055: my ($currdef,$newdef);
1.208 raeburn 15056: $newdef = $env{'form.'.$item};
1.198 raeburn 15057: if ($item eq 'anonsurvey_threshold') {
15058: $currdef = $domconfig{'coursedefaults'}{$item};
15059: $newdef =~ s/\D//g;
15060: if ($newdef eq '' || $newdef < 1) {
15061: $newdef = 1;
15062: }
15063: $defaultshash{'coursedefaults'}{$item} = $newdef;
15064: } else {
1.276 raeburn 15065: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
15066: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
15067: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 15068: }
15069: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 15070: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 15071: }
15072: if ($currdef ne $newdef) {
15073: my $staticdef;
15074: if ($item eq 'anonsurvey_threshold') {
15075: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
15076: $changes{$item} = 1;
15077: }
1.276 raeburn 15078: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 15079: my $setting = $1;
1.276 raeburn 15080: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
15081: $changes{$setting} = 1;
1.198 raeburn 15082: }
15083: }
1.139 raeburn 15084: }
15085: }
1.314 raeburn 15086: my $texengine;
15087: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
15088: $texengine = $env{'form.texengine'};
15089: if ($defaultshash{'coursedefaults'}{'texengine'} eq '') {
15090: unless ($texengine eq 'MathJax') {
15091: $changes{'texengine'} = 1;
15092: }
15093: } elsif ($defaultshash{'coursedefaults'}{'texengine'} ne $texengine) {
15094: $changes{'texengine'} = 1;
15095: }
15096: }
15097: if ($texengine ne '') {
15098: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
15099: }
1.264 raeburn 15100: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
15101: my @currclonecode;
15102: if (ref($currclone) eq 'HASH') {
15103: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
15104: @currclonecode = @{$currclone->{'instcode'}};
15105: }
15106: }
15107: my $newclone;
1.289 raeburn 15108: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 15109: $newclone = $env{'form.canclone'};
15110: }
15111: if ($newclone eq 'instcode') {
15112: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
15113: my (%codedefaults,@code_order,@clonecode);
15114: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
15115: \@code_order);
15116: foreach my $item (@code_order) {
15117: if (grep(/^\Q$item\E$/,@newcodes)) {
15118: push(@clonecode,$item);
15119: }
15120: }
15121: if (@clonecode) {
15122: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
15123: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
15124: if (@diffs) {
15125: $changes{'canclone'} = 1;
15126: }
15127: } else {
15128: $newclone eq '';
15129: }
15130: } elsif ($newclone ne '') {
1.289 raeburn 15131: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
15132: }
1.264 raeburn 15133: if ($newclone ne $currclone) {
15134: $changes{'canclone'} = 1;
15135: }
1.257 raeburn 15136: my %credits;
15137: foreach my $type (@types) {
15138: unless ($type eq 'community') {
15139: $credits{$type} = $env{'form.'.$type.'_credits'};
15140: $credits{$type} =~ s/[^\d.]+//g;
15141: }
15142: }
15143: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
15144: ($env{'form.coursecredits'} eq '1')) {
15145: $changes{'coursecredits'} = 1;
15146: foreach my $type (keys(%credits)) {
15147: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15148: }
15149: } else {
1.289 raeburn 15150: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 15151: foreach my $type (@types) {
15152: unless ($type eq 'community') {
1.289 raeburn 15153: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 15154: $changes{'coursecredits'} = 1;
15155: }
15156: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15157: }
15158: }
15159: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15160: foreach my $type (@types) {
15161: unless ($type eq 'community') {
15162: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
15163: $changes{'coursecredits'} = 1;
15164: last;
15165: }
15166: }
15167: }
15168: }
15169: }
15170: if ($env{'form.postsubmit'} eq '1') {
15171: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
15172: my %currtimeout;
15173: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15174: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
15175: $changes{'postsubmit'} = 1;
15176: }
15177: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15178: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
15179: }
15180: } else {
15181: $changes{'postsubmit'} = 1;
15182: }
15183: foreach my $type (@types) {
15184: my $timeout = $env{'form.'.$type.'_timeout'};
15185: $timeout =~ s/\D//g;
15186: if ($timeout == $staticdefaults{'postsubmit'}) {
15187: $timeout = '';
15188: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
15189: $timeout = '0';
15190: }
15191: unless ($timeout eq '') {
15192: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
15193: }
15194: if (exists($currtimeout{$type})) {
15195: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 15196: $changes{'postsubmit'} = 1;
1.257 raeburn 15197: }
15198: } elsif ($timeout ne '') {
15199: $changes{'postsubmit'} = 1;
15200: }
15201: }
15202: } else {
15203: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
15204: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15205: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
15206: $changes{'postsubmit'} = 1;
15207: }
15208: } else {
15209: $changes{'postsubmit'} = 1;
15210: }
1.192 raeburn 15211: }
1.121 raeburn 15212: }
15213: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
15214: $dom);
15215: if ($putresult eq 'ok') {
15216: if (keys(%changes) > 0) {
1.213 raeburn 15217: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 15218: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 15219: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.314 raeburn 15220: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
15221: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','texengine') {
1.257 raeburn 15222: if ($changes{$item}) {
15223: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
15224: }
1.289 raeburn 15225: }
1.192 raeburn 15226: if ($changes{'coursecredits'}) {
15227: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 15228: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
15229: $domdefaults{$type.'credits'} =
15230: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
15231: }
15232: }
15233: }
15234: if ($changes{'postsubmit'}) {
15235: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15236: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
15237: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15238: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
15239: $domdefaults{$type.'postsubtimeout'} =
15240: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15241: }
15242: }
1.192 raeburn 15243: }
15244: }
1.198 raeburn 15245: if ($changes{'uploadquota'}) {
15246: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15247: foreach my $type (@types) {
15248: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
15249: }
15250: }
15251: }
1.264 raeburn 15252: if ($changes{'canclone'}) {
15253: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15254: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15255: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
15256: if (@clonecodes) {
15257: $domdefaults{'canclone'} = join('+',@clonecodes);
15258: }
15259: }
15260: } else {
15261: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
15262: }
15263: }
1.121 raeburn 15264: my $cachetime = 24*60*60;
15265: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 15266: if (ref($lastactref) eq 'HASH') {
15267: $lastactref->{'domdefaults'} = 1;
15268: }
1.121 raeburn 15269: }
15270: $resulttext = &mt('Changes made:').'<ul>';
15271: foreach my $item (sort(keys(%changes))) {
15272: if ($item eq 'canuse_pdfforms') {
15273: if ($env{'form.'.$item} eq '1') {
15274: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
15275: } else {
15276: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
15277: }
1.257 raeburn 15278: } elsif ($item eq 'uselcmath') {
15279: if ($env{'form.'.$item} eq '1') {
15280: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
15281: } else {
15282: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
15283: }
15284: } elsif ($item eq 'usejsme') {
15285: if ($env{'form.'.$item} eq '1') {
15286: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
15287: } else {
1.289 raeburn 15288: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 15289: }
1.314 raeburn 15290: } elsif ($item eq 'texengine') {
15291: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
15292: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
15293: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
15294: }
1.139 raeburn 15295: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 15296: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 15297: } elsif ($item eq 'uploadquota') {
15298: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15299: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
15300: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
15301: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 15302: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 15303: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 15304: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
15305: '</ul>'.
15306: '</li>';
15307: } else {
15308: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
15309: }
1.276 raeburn 15310: } elsif ($item eq 'mysqltables') {
15311: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
15312: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
15313: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
15314: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
15315: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
15316: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
15317: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
15318: '</ul>'.
15319: '</li>';
15320: } else {
15321: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
15322: }
1.257 raeburn 15323: } elsif ($item eq 'postsubmit') {
15324: if ($domdefaults{'postsubmit'} eq 'off') {
15325: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
15326: } else {
15327: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 15328: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 15329: $resulttext .= &mt('durations:').'<ul>';
15330: foreach my $type (@types) {
15331: $resulttext .= '<li>';
15332: my $timeout;
15333: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15334: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15335: }
15336: my $display;
15337: if ($timeout eq '0') {
15338: $display = &mt('unlimited');
15339: } elsif ($timeout eq '') {
15340: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
15341: } else {
15342: $display = &mt('[quant,_1,second]',$timeout);
15343: }
15344: if ($type eq 'community') {
15345: $resulttext .= &mt('Communities');
15346: } elsif ($type eq 'official') {
15347: $resulttext .= &mt('Official courses');
15348: } elsif ($type eq 'unofficial') {
15349: $resulttext .= &mt('Unofficial courses');
15350: } elsif ($type eq 'textbook') {
15351: $resulttext .= &mt('Textbook courses');
1.271 raeburn 15352: } elsif ($type eq 'placement') {
15353: $resulttext .= &mt('Placement tests');
1.257 raeburn 15354: }
15355: $resulttext .= ' -- '.$display.'</li>';
15356: }
15357: $resulttext .= '</ul>';
15358: }
1.289 raeburn 15359: $resulttext .= '</li>';
1.257 raeburn 15360: }
1.192 raeburn 15361: } elsif ($item eq 'coursecredits') {
15362: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15363: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 15364: ($domdefaults{'unofficialcredits'} eq '') &&
15365: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 15366: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
15367: } else {
15368: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
15369: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
15370: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 15371: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 15372: '</ul>'.
15373: '</li>';
15374: }
15375: } else {
15376: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
15377: }
1.264 raeburn 15378: } elsif ($item eq 'canclone') {
15379: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15380: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15381: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
15382: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
15383: }
15384: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
15385: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
15386: } else {
1.289 raeburn 15387: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 15388: }
1.140 raeburn 15389: }
1.121 raeburn 15390: }
15391: $resulttext .= '</ul>';
15392: } else {
15393: $resulttext = &mt('No changes made to course defaults');
15394: }
15395: } else {
15396: $resulttext = '<span class="LC_error">'.
15397: &mt('An error occurred: [_1]',$putresult).'</span>';
15398: }
15399: return $resulttext;
15400: }
15401:
1.231 raeburn 15402: sub modify_selfenrollment {
15403: my ($dom,$lastactref,%domconfig) = @_;
15404: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 15405: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 15406: my %titles = &tool_titles();
1.232 raeburn 15407: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
15408: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 15409: $ordered{'default'} = ['types','registered','approval','limit'];
15410:
15411: my (%roles,%shown,%toplevel);
15412: $roles{'0'} = &Apache::lonnet::plaintext('dc');
15413:
15414: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
15415: if ($domconfig{'selfenrollment'} eq '') {
15416: $domconfig{'selfenrollment'} = {};
15417: }
15418: }
15419: %toplevel = (
15420: admin => 'Configuration Rights',
15421: default => 'Default settings',
15422: validation => 'Validation of self-enrollment requests',
15423: );
1.233 raeburn 15424: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 15425:
15426: if (ref($ordered{'admin'}) eq 'ARRAY') {
15427: foreach my $item (@{$ordered{'admin'}}) {
15428: foreach my $type (@types) {
15429: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
15430: $selfenrollhash{'admin'}{$type}{$item} = 1;
15431: } else {
15432: $selfenrollhash{'admin'}{$type}{$item} = 0;
15433: }
15434: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
15435: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
15436: if ($selfenrollhash{'admin'}{$type}{$item} ne
15437: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
15438: push(@{$changes{'admin'}{$type}},$item);
15439: }
15440: } else {
15441: if (!$selfenrollhash{'admin'}{$type}{$item}) {
15442: push(@{$changes{'admin'}{$type}},$item);
15443: }
15444: }
15445: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
15446: push(@{$changes{'admin'}{$type}},$item);
15447: }
15448: }
15449: }
15450: }
15451:
15452: foreach my $item (@{$ordered{'default'}}) {
15453: foreach my $type (@types) {
15454: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
15455: if ($item eq 'types') {
15456: unless (($value eq 'all') || ($value eq 'dom')) {
15457: $value = '';
15458: }
15459: } elsif ($item eq 'registered') {
15460: unless ($value eq '1') {
15461: $value = 0;
15462: }
15463: } elsif ($item eq 'approval') {
15464: unless ($value =~ /^[012]$/) {
15465: $value = 0;
15466: }
15467: } else {
15468: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
15469: $value = 'none';
15470: }
15471: }
15472: $selfenrollhash{'default'}{$type}{$item} = $value;
15473: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
15474: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
15475: if ($selfenrollhash{'default'}{$type}{$item} ne
15476: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
15477: push(@{$changes{'default'}{$type}},$item);
15478: }
15479: } else {
15480: push(@{$changes{'default'}{$type}},$item);
15481: }
15482: } else {
15483: push(@{$changes{'default'}{$type}},$item);
15484: }
15485: if ($item eq 'limit') {
15486: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
15487: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
15488: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
15489: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
15490: }
15491: } else {
15492: $selfenrollhash{'default'}{$type}{'cap'} = '';
15493: }
15494: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
15495: if ($selfenrollhash{'default'}{$type}{'cap'} ne
15496: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
15497: push(@{$changes{'default'}{$type}},'cap');
15498: }
15499: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
15500: push(@{$changes{'default'}{$type}},'cap');
15501: }
15502: }
15503: }
15504: }
15505:
15506: foreach my $item (@{$itemsref}) {
15507: if ($item eq 'fields') {
15508: my @changed;
15509: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
15510: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
15511: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
15512: }
15513: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
15514: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
15515: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
15516: $domconfig{'selfenrollment'}{'validation'}{$item});
15517: } else {
15518: @changed = @{$selfenrollhash{'validation'}{$item}};
15519: }
15520: } else {
15521: @changed = @{$selfenrollhash{'validation'}{$item}};
15522: }
15523: if (@changed) {
15524: if ($selfenrollhash{'validation'}{$item}) {
15525: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
15526: } else {
15527: $changes{'validation'}{$item} = &mt('None');
15528: }
15529: }
15530: } else {
15531: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
15532: if ($item eq 'markup') {
15533: if ($env{'form.selfenroll_validation_'.$item}) {
15534: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
15535: }
15536: }
15537: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
15538: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
15539: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
15540: }
15541: }
15542: }
15543: }
15544:
15545: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
15546: $dom);
15547: if ($putresult eq 'ok') {
15548: if (keys(%changes) > 0) {
15549: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15550: $resulttext = &mt('Changes made:').'<ul>';
15551: foreach my $key ('admin','default','validation') {
15552: if (ref($changes{$key}) eq 'HASH') {
15553: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
15554: if ($key eq 'validation') {
15555: foreach my $item (@{$itemsref}) {
15556: if (exists($changes{$key}{$item})) {
15557: if ($item eq 'markup') {
15558: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
15559: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
15560: } else {
15561: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
15562: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
15563: }
15564: }
15565: }
15566: } else {
15567: foreach my $type (@types) {
15568: if ($type eq 'community') {
15569: $roles{'1'} = &mt('Community personnel');
15570: } else {
15571: $roles{'1'} = &mt('Course personnel');
15572: }
15573: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 15574: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
15575: if ($key eq 'admin') {
15576: my @mgrdc = ();
15577: if (ref($ordered{$key}) eq 'ARRAY') {
15578: foreach my $item (@{$ordered{'admin'}}) {
15579: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
15580: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
15581: push(@mgrdc,$item);
15582: }
15583: }
15584: }
15585: if (@mgrdc) {
15586: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
15587: } else {
15588: delete($domdefaults{$type.'selfenrolladmdc'});
15589: }
15590: }
15591: } else {
15592: if (ref($ordered{$key}) eq 'ARRAY') {
15593: foreach my $item (@{$ordered{$key}}) {
15594: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
15595: $domdefaults{$type.'selfenroll'.$item} =
15596: $selfenrollhash{$key}{$type}{$item};
15597: }
15598: }
15599: }
15600: }
15601: }
1.231 raeburn 15602: $resulttext .= '<li>'.$titles{$type}.'<ul>';
15603: foreach my $item (@{$ordered{$key}}) {
15604: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
15605: $resulttext .= '<li>';
15606: if ($key eq 'admin') {
15607: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
15608: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
15609: } else {
15610: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
15611: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
15612: }
15613: $resulttext .= '</li>';
15614: }
15615: }
15616: $resulttext .= '</ul></li>';
15617: }
15618: }
15619: $resulttext .= '</ul></li>';
15620: }
15621: }
1.305 raeburn 15622: }
15623: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
15624: my $cachetime = 24*60*60;
15625: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15626: if (ref($lastactref) eq 'HASH') {
15627: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 15628: }
1.231 raeburn 15629: }
15630: $resulttext .= '</ul>';
15631: } else {
15632: $resulttext = &mt('No changes made to self-enrollment settings');
15633: }
15634: } else {
15635: $resulttext = '<span class="LC_error">'.
15636: &mt('An error occurred: [_1]',$putresult).'</span>';
15637: }
15638: return $resulttext;
15639: }
15640:
1.137 raeburn 15641: sub modify_usersessions {
1.212 raeburn 15642: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 15643: my @hostingtypes = ('version','excludedomain','includedomain');
15644: my @offloadtypes = ('primary','default');
15645: my %types = (
15646: remote => \@hostingtypes,
15647: hosted => \@hostingtypes,
15648: spares => \@offloadtypes,
15649: );
15650: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 15651: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 15652: my (%by_ip,%by_location,@intdoms,@instdoms);
15653: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 15654: my @locations = sort(keys(%by_location));
1.137 raeburn 15655: my (%defaultshash,%changes);
15656: foreach my $prefix (@prefixes) {
15657: $defaultshash{'usersessions'}{$prefix} = {};
15658: }
1.212 raeburn 15659: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 15660: my $resulttext;
1.138 raeburn 15661: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 15662: foreach my $prefix (@prefixes) {
1.145 raeburn 15663: next if ($prefix eq 'spares');
15664: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 15665: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
15666: if ($type eq 'version') {
15667: my $value = $env{'form.'.$prefix.'_'.$type};
15668: my $okvalue;
15669: if ($value ne '') {
15670: if (grep(/^\Q$value\E$/,@lcversions)) {
15671: $okvalue = $value;
15672: }
15673: }
15674: if (ref($domconfig{'usersessions'}) eq 'HASH') {
15675: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
15676: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
15677: if ($inuse == 0) {
15678: $changes{$prefix}{$type} = 1;
15679: } else {
15680: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
15681: $changes{$prefix}{$type} = 1;
15682: }
15683: if ($okvalue ne '') {
15684: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
15685: }
15686: }
15687: } else {
15688: if (($inuse == 1) && ($okvalue ne '')) {
15689: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
15690: $changes{$prefix}{$type} = 1;
15691: }
15692: }
15693: } else {
15694: if (($inuse == 1) && ($okvalue ne '')) {
15695: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
15696: $changes{$prefix}{$type} = 1;
15697: }
15698: }
15699: } else {
15700: if (($inuse == 1) && ($okvalue ne '')) {
15701: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
15702: $changes{$prefix}{$type} = 1;
15703: }
15704: }
15705: } else {
15706: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
15707: my @okvals;
15708: foreach my $val (@vals) {
1.138 raeburn 15709: if ($val =~ /:/) {
15710: my @items = split(/:/,$val);
15711: foreach my $item (@items) {
15712: if (ref($by_location{$item}) eq 'ARRAY') {
15713: push(@okvals,$item);
15714: }
15715: }
15716: } else {
15717: if (ref($by_location{$val}) eq 'ARRAY') {
15718: push(@okvals,$val);
15719: }
1.137 raeburn 15720: }
15721: }
15722: @okvals = sort(@okvals);
15723: if (ref($domconfig{'usersessions'}) eq 'HASH') {
15724: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
15725: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
15726: if ($inuse == 0) {
15727: $changes{$prefix}{$type} = 1;
15728: } else {
15729: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
15730: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
15731: if (@changed > 0) {
15732: $changes{$prefix}{$type} = 1;
15733: }
15734: }
15735: } else {
15736: if ($inuse == 1) {
15737: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
15738: $changes{$prefix}{$type} = 1;
15739: }
15740: }
15741: } else {
15742: if ($inuse == 1) {
15743: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
15744: $changes{$prefix}{$type} = 1;
15745: }
15746: }
15747: } else {
15748: if ($inuse == 1) {
15749: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
15750: $changes{$prefix}{$type} = 1;
15751: }
15752: }
15753: }
15754: }
15755: }
1.145 raeburn 15756:
15757: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 15758: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 15759: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
15760: my $savespares;
15761:
15762: foreach my $lonhost (sort(keys(%servers))) {
15763: my $serverhomeID =
15764: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 15765: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 15766: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
15767: my %spareschg;
15768: foreach my $type (@{$types{'spares'}}) {
15769: my @okspares;
15770: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
15771: foreach my $server (@checked) {
1.152 raeburn 15772: if (&Apache::lonnet::hostname($server) ne '') {
15773: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
15774: unless (grep(/^\Q$server\E$/,@okspares)) {
15775: push(@okspares,$server);
15776: }
1.145 raeburn 15777: }
15778: }
15779: }
15780: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
15781: my $newspare;
1.152 raeburn 15782: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
15783: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 15784: $newspare = $new;
15785: }
15786: }
1.152 raeburn 15787: my @spares;
15788: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
15789: @spares = sort(@okspares,$newspare);
15790: } else {
15791: @spares = sort(@okspares);
15792: }
15793: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 15794: if (ref($spareid{$lonhost}) eq 'HASH') {
15795: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 15796: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 15797: if (@diffs > 0) {
15798: $spareschg{$type} = 1;
15799: }
15800: }
15801: }
15802: }
15803: if (keys(%spareschg) > 0) {
15804: $changes{'spares'}{$lonhost} = \%spareschg;
15805: }
15806: }
1.261 raeburn 15807: $defaultshash{'usersessions'}{'offloadnow'} = {};
15808: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
15809: my @okoffload;
15810: if (@offloadnow) {
15811: foreach my $server (@offloadnow) {
15812: if (&Apache::lonnet::hostname($server) ne '') {
15813: unless (grep(/^\Q$server\E$/,@okoffload)) {
15814: push(@okoffload,$server);
15815: }
15816: }
15817: }
15818: if (@okoffload) {
15819: foreach my $lonhost (@okoffload) {
15820: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
15821: }
15822: }
15823: }
1.145 raeburn 15824: if (ref($domconfig{'usersessions'}) eq 'HASH') {
15825: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
15826: if (ref($changes{'spares'}) eq 'HASH') {
15827: if (keys(%{$changes{'spares'}}) > 0) {
15828: $savespares = 1;
15829: }
15830: }
15831: } else {
15832: $savespares = 1;
15833: }
1.261 raeburn 15834: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
15835: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
15836: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
15837: $changes{'offloadnow'} = 1;
15838: last;
15839: }
15840: }
15841: unless ($changes{'offloadnow'}) {
1.289 raeburn 15842: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
1.261 raeburn 15843: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
15844: $changes{'offloadnow'} = 1;
15845: last;
15846: }
15847: }
15848: }
15849: } elsif (@okoffload) {
15850: $changes{'offloadnow'} = 1;
15851: }
15852: } elsif (@okoffload) {
15853: $changes{'offloadnow'} = 1;
1.145 raeburn 15854: }
1.147 raeburn 15855: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
15856: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 15857: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
15858: $dom);
15859: if ($putresult eq 'ok') {
15860: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
15861: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
15862: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
15863: }
15864: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
15865: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
15866: }
1.261 raeburn 15867: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
15868: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
15869: }
1.137 raeburn 15870: }
15871: my $cachetime = 24*60*60;
15872: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 15873: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 15874: if (ref($lastactref) eq 'HASH') {
15875: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 15876: $lastactref->{'usersessions'} = 1;
1.212 raeburn 15877: }
1.147 raeburn 15878: if (keys(%changes) > 0) {
15879: my %lt = &usersession_titles();
15880: $resulttext = &mt('Changes made:').'<ul>';
15881: foreach my $prefix (@prefixes) {
15882: if (ref($changes{$prefix}) eq 'HASH') {
15883: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
15884: if ($prefix eq 'spares') {
15885: if (ref($changes{$prefix}) eq 'HASH') {
15886: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
15887: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 15888: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 15889: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
15890: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 15891: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
15892: foreach my $type (@{$types{$prefix}}) {
15893: if ($changes{$prefix}{$lonhost}{$type}) {
15894: my $offloadto = &mt('None');
15895: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
15896: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
15897: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
15898: }
1.145 raeburn 15899: }
1.147 raeburn 15900: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 15901: }
1.137 raeburn 15902: }
15903: }
1.147 raeburn 15904: $resulttext .= '</li>';
1.137 raeburn 15905: }
15906: }
1.147 raeburn 15907: } else {
15908: foreach my $type (@{$types{$prefix}}) {
15909: if (defined($changes{$prefix}{$type})) {
15910: my $newvalue;
15911: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
15912: if (ref($defaultshash{'usersessions'}{$prefix})) {
15913: if ($type eq 'version') {
15914: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
15915: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
15916: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
15917: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
15918: }
1.145 raeburn 15919: }
15920: }
15921: }
1.147 raeburn 15922: if ($newvalue eq '') {
15923: if ($type eq 'version') {
15924: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
15925: } else {
15926: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
15927: }
1.145 raeburn 15928: } else {
1.147 raeburn 15929: if ($type eq 'version') {
15930: $newvalue .= ' '.&mt('(or later)');
15931: }
15932: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 15933: }
1.137 raeburn 15934: }
15935: }
15936: }
1.147 raeburn 15937: $resulttext .= '</ul>';
1.137 raeburn 15938: }
15939: }
1.261 raeburn 15940: if ($changes{'offloadnow'}) {
15941: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
15942: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
15943: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
15944: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
15945: $resulttext .= '<li>'.$lonhost.'</li>';
15946: }
15947: $resulttext .= '</ul>';
15948: } else {
15949: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
15950: }
15951: } else {
15952: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
15953: }
15954: }
1.147 raeburn 15955: $resulttext .= '</ul>';
15956: } else {
15957: $resulttext = $nochgmsg;
1.137 raeburn 15958: }
15959: } else {
15960: $resulttext = '<span class="LC_error">'.
15961: &mt('An error occurred: [_1]',$putresult).'</span>';
15962: }
15963: } else {
1.147 raeburn 15964: $resulttext = $nochgmsg;
1.137 raeburn 15965: }
15966: return $resulttext;
15967: }
15968:
1.275 raeburn 15969: sub modify_ssl {
15970: my ($dom,$lastactref,%domconfig) = @_;
15971: my (%by_ip,%by_location,@intdoms,@instdoms);
15972: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
15973: my @locations = sort(keys(%by_location));
15974: my %servers = &Apache::lonnet::internet_dom_servers($dom);
15975: my (%defaultshash,%changes);
15976: my $action = 'ssl';
1.293 raeburn 15977: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 15978: foreach my $prefix (@prefixes) {
15979: $defaultshash{$action}{$prefix} = {};
15980: }
15981: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15982: my $resulttext;
15983: my %iphost = &Apache::lonnet::get_iphost();
15984: my @reptypes = ('certreq','nocertreq');
15985: my @connecttypes = ('dom','intdom','other');
15986: my %types = (
1.293 raeburn 15987: connto => \@connecttypes,
15988: connfrom => \@connecttypes,
15989: replication => \@reptypes,
1.275 raeburn 15990: );
15991: foreach my $prefix (sort(keys(%types))) {
15992: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 15993: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 15994: my $value = 'yes';
15995: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
15996: $value = $env{'form.'.$prefix.'_'.$type};
15997: }
15998: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
15999: if ($domconfig{$action}{$prefix}{$type} ne '') {
16000: if ($value ne $domconfig{$action}{$prefix}{$type}) {
16001: $changes{$prefix}{$type} = 1;
16002: }
16003: $defaultshash{$action}{$prefix}{$type} = $value;
16004: } else {
16005: $defaultshash{$action}{$prefix}{$type} = $value;
16006: $changes{$prefix}{$type} = 1;
16007: }
16008: } else {
16009: $defaultshash{$action}{$prefix}{$type} = $value;
16010: $changes{$prefix}{$type} = 1;
16011: }
16012: if (($type eq 'dom') && (keys(%servers) == 1)) {
16013: delete($changes{$prefix}{$type});
16014: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
16015: delete($changes{$prefix}{$type});
16016: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
16017: delete($changes{$prefix}{$type});
16018: }
16019: } elsif ($prefix eq 'replication') {
16020: if (@locations > 0) {
16021: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16022: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16023: my @okvals;
16024: foreach my $val (@vals) {
16025: if ($val =~ /:/) {
16026: my @items = split(/:/,$val);
16027: foreach my $item (@items) {
16028: if (ref($by_location{$item}) eq 'ARRAY') {
16029: push(@okvals,$item);
16030: }
16031: }
16032: } else {
16033: if (ref($by_location{$val}) eq 'ARRAY') {
16034: push(@okvals,$val);
16035: }
16036: }
16037: }
16038: @okvals = sort(@okvals);
16039: if (ref($domconfig{$action}) eq 'HASH') {
16040: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
16041: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
16042: if ($inuse == 0) {
16043: $changes{$prefix}{$type} = 1;
16044: } else {
16045: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16046: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
16047: if (@changed > 0) {
16048: $changes{$prefix}{$type} = 1;
16049: }
16050: }
16051: } else {
16052: if ($inuse == 1) {
16053: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16054: $changes{$prefix}{$type} = 1;
16055: }
16056: }
16057: } else {
16058: if ($inuse == 1) {
16059: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16060: $changes{$prefix}{$type} = 1;
16061: }
16062: }
16063: } else {
16064: if ($inuse == 1) {
16065: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16066: $changes{$prefix}{$type} = 1;
16067: }
16068: }
16069: }
16070: }
16071: }
16072: }
16073: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
16074: if (keys(%changes) > 0) {
16075: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16076: $dom);
16077: if ($putresult eq 'ok') {
16078: if (ref($defaultshash{$action}) eq 'HASH') {
16079: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
16080: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
16081: }
1.293 raeburn 16082: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
16083: $domdefaults{'connto'} = $domconfig{$action}{'connto'};
16084: }
16085: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
16086: $domdefaults{'connfrom'} = $domconfig{$action}{'connfrom'};
1.275 raeburn 16087: }
16088: }
16089: my $cachetime = 24*60*60;
16090: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16091: if (ref($lastactref) eq 'HASH') {
16092: $lastactref->{'domdefaults'} = 1;
16093: }
16094: if (keys(%changes) > 0) {
16095: my %titles = &ssl_titles();
16096: $resulttext = &mt('Changes made:').'<ul>';
16097: foreach my $prefix (@prefixes) {
16098: if (ref($changes{$prefix}) eq 'HASH') {
16099: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
16100: foreach my $type (@{$types{$prefix}}) {
16101: if (defined($changes{$prefix}{$type})) {
16102: my $newvalue;
16103: if (ref($defaultshash{$action}) eq 'HASH') {
16104: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 16105: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 16106: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
16107: } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
16108: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
16109: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
16110: }
16111: }
16112: }
16113: if ($newvalue eq '') {
16114: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
16115: } else {
16116: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
16117: }
16118: }
16119: }
16120: }
16121: $resulttext .= '</ul>';
16122: }
16123: }
16124: } else {
16125: $resulttext = $nochgmsg;
16126: }
16127: } else {
16128: $resulttext = '<span class="LC_error">'.
16129: &mt('An error occurred: [_1]',$putresult).'</span>';
16130: }
16131: } else {
16132: $resulttext = $nochgmsg;
16133: }
16134: return $resulttext;
16135: }
16136:
1.279 raeburn 16137: sub modify_trust {
16138: my ($dom,$lastactref,%domconfig) = @_;
16139: my (%by_ip,%by_location,@intdoms,@instdoms);
16140: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
16141: my @locations = sort(keys(%by_location));
16142: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
16143: my @types = ('exc','inc');
16144: my (%defaultshash,%changes);
16145: foreach my $prefix (@prefixes) {
16146: $defaultshash{'trust'}{$prefix} = {};
16147: }
16148: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16149: my $resulttext;
16150: foreach my $prefix (@prefixes) {
16151: foreach my $type (@types) {
16152: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16153: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16154: my @okvals;
16155: foreach my $val (@vals) {
16156: if ($val =~ /:/) {
16157: my @items = split(/:/,$val);
16158: foreach my $item (@items) {
16159: if (ref($by_location{$item}) eq 'ARRAY') {
16160: push(@okvals,$item);
16161: }
16162: }
16163: } else {
16164: if (ref($by_location{$val}) eq 'ARRAY') {
16165: push(@okvals,$val);
16166: }
16167: }
16168: }
16169: @okvals = sort(@okvals);
16170: if (ref($domconfig{'trust'}) eq 'HASH') {
16171: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
16172: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
16173: if ($inuse == 0) {
16174: $changes{$prefix}{$type} = 1;
16175: } else {
16176: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16177: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
16178: if (@changed > 0) {
16179: $changes{$prefix}{$type} = 1;
16180: }
16181: }
16182: } else {
16183: if ($inuse == 1) {
16184: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16185: $changes{$prefix}{$type} = 1;
16186: }
16187: }
16188: } else {
16189: if ($inuse == 1) {
16190: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16191: $changes{$prefix}{$type} = 1;
16192: }
16193: }
16194: } else {
16195: if ($inuse == 1) {
16196: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16197: $changes{$prefix}{$type} = 1;
16198: }
16199: }
16200: }
16201: }
16202: my $nochgmsg = &mt('No changes made to trust settings.');
16203: if (keys(%changes) > 0) {
16204: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16205: $dom);
16206: if ($putresult eq 'ok') {
16207: if (ref($defaultshash{'trust'}) eq 'HASH') {
16208: foreach my $prefix (@prefixes) {
16209: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
16210: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
16211: }
16212: }
16213: }
16214: my $cachetime = 24*60*60;
16215: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16216: if (ref($lastactref) eq 'HASH') {
16217: $lastactref->{'domdefaults'} = 1;
16218: }
16219: if (keys(%changes) > 0) {
16220: my %lt = &trust_titles();
16221: $resulttext = &mt('Changes made:').'<ul>';
16222: foreach my $prefix (@prefixes) {
16223: if (ref($changes{$prefix}) eq 'HASH') {
16224: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
16225: foreach my $type (@types) {
16226: if (defined($changes{$prefix}{$type})) {
16227: my $newvalue;
16228: if (ref($defaultshash{'trust'}) eq 'HASH') {
16229: if (ref($defaultshash{'trust'}{$prefix})) {
16230: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
16231: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
16232: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
16233: }
16234: }
16235: }
16236: }
16237: if ($newvalue eq '') {
16238: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
16239: } else {
16240: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
16241: }
16242: }
16243: }
16244: $resulttext .= '</ul>';
16245: }
16246: }
16247: $resulttext .= '</ul>';
16248: } else {
16249: $resulttext = $nochgmsg;
16250: }
16251: } else {
16252: $resulttext = '<span class="LC_error">'.
16253: &mt('An error occurred: [_1]',$putresult).'</span>';
16254: }
16255: } else {
16256: $resulttext = $nochgmsg;
16257: }
16258: return $resulttext;
16259: }
16260:
1.150 raeburn 16261: sub modify_loadbalancing {
16262: my ($dom,%domconfig) = @_;
16263: my $primary_id = &Apache::lonnet::domain($dom,'primary');
16264: my $intdom = &Apache::lonnet::internet_dom($primary_id);
16265: my ($othertitle,$usertypes,$types) =
16266: &Apache::loncommon::sorted_inst_types($dom);
16267: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 16268: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 16269: my @sparestypes = ('primary','default');
16270: my %typetitles = &sparestype_titles();
16271: my $resulttext;
1.171 raeburn 16272: my (%currbalancer,%currtargets,%currrules,%existing);
16273: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
16274: %existing = %{$domconfig{'loadbalancing'}};
16275: }
16276: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
16277: \%currtargets,\%currrules);
16278: my ($saveloadbalancing,%defaultshash,%changes);
16279: my ($alltypes,$othertypes,$titles) =
16280: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
16281: my %ruletitles = &offloadtype_text();
16282: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
16283: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
16284: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
16285: if ($balancer eq '') {
16286: next;
16287: }
1.210 raeburn 16288: if (!exists($servers{$balancer})) {
1.171 raeburn 16289: if (exists($currbalancer{$balancer})) {
16290: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 16291: }
1.171 raeburn 16292: next;
16293: }
16294: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
16295: push(@{$changes{'delete'}},$balancer);
16296: next;
16297: }
16298: if (!exists($currbalancer{$balancer})) {
16299: push(@{$changes{'add'}},$balancer);
16300: }
16301: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
16302: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
16303: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
16304: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
16305: $saveloadbalancing = 1;
16306: }
16307: foreach my $sparetype (@sparestypes) {
16308: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
16309: my @offloadto;
16310: foreach my $target (@targets) {
16311: if (($servers{$target}) && ($target ne $balancer)) {
16312: if ($sparetype eq 'default') {
16313: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
16314: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 16315: }
16316: }
1.171 raeburn 16317: unless(grep(/^\Q$target\E$/,@offloadto)) {
16318: push(@offloadto,$target);
16319: }
1.150 raeburn 16320: }
16321: }
1.284 raeburn 16322: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
16323: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
16324: push(@offloadto,$balancer);
16325: }
16326: }
16327: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 16328: }
1.171 raeburn 16329: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 16330: foreach my $sparetype (@sparestypes) {
1.171 raeburn 16331: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
16332: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 16333: if (@targetdiffs > 0) {
1.171 raeburn 16334: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 16335: }
1.171 raeburn 16336: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16337: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16338: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 16339: }
16340: }
16341: }
16342: } else {
1.171 raeburn 16343: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 16344: foreach my $sparetype (@sparestypes) {
1.171 raeburn 16345: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16346: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16347: $changes{'curr'}{$balancer}{'targets'} = 1;
16348: }
1.150 raeburn 16349: }
16350: }
1.210 raeburn 16351: }
1.150 raeburn 16352: }
16353: my $ishomedom;
1.171 raeburn 16354: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
16355: $ishomedom = 1;
1.150 raeburn 16356: }
16357: if (ref($alltypes) eq 'ARRAY') {
16358: foreach my $type (@{$alltypes}) {
16359: my $rule;
1.210 raeburn 16360: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 16361: (!$ishomedom)) {
1.171 raeburn 16362: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
16363: }
16364: if ($rule eq 'specific') {
1.255 raeburn 16365: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 16366: if (exists($servers{$specifiedhost})) {
1.255 raeburn 16367: $rule = $specifiedhost;
16368: }
1.150 raeburn 16369: }
1.171 raeburn 16370: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
16371: if (ref($currrules{$balancer}) eq 'HASH') {
16372: if ($rule ne $currrules{$balancer}{$type}) {
16373: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 16374: }
16375: } elsif ($rule ne '') {
1.171 raeburn 16376: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 16377: }
16378: }
16379: }
1.171 raeburn 16380: }
16381: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
16382: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
16383: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
16384: $defaultshash{'loadbalancing'} = {};
16385: }
16386: my $putresult = &Apache::lonnet::put_dom('configuration',
16387: \%defaultshash,$dom);
16388: if ($putresult eq 'ok') {
16389: if (keys(%changes) > 0) {
1.252 raeburn 16390: my %toupdate;
1.171 raeburn 16391: if (ref($changes{'delete'}) eq 'ARRAY') {
16392: foreach my $balancer (sort(@{$changes{'delete'}})) {
16393: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 16394: $toupdate{$balancer} = 1;
1.150 raeburn 16395: }
1.171 raeburn 16396: }
16397: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 16398: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 16399: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 16400: $toupdate{$balancer} = 1;
1.171 raeburn 16401: }
16402: }
16403: if (ref($changes{'curr'}) eq 'HASH') {
16404: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 16405: $toupdate{$balancer} = 1;
1.171 raeburn 16406: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
16407: if ($changes{'curr'}{$balancer}{'targets'}) {
16408: my %offloadstr;
16409: foreach my $sparetype (@sparestypes) {
16410: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16411: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16412: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
16413: }
16414: }
1.150 raeburn 16415: }
1.171 raeburn 16416: if (keys(%offloadstr) == 0) {
16417: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 16418: } else {
1.171 raeburn 16419: my $showoffload;
16420: foreach my $sparetype (@sparestypes) {
16421: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
16422: if (defined($offloadstr{$sparetype})) {
16423: $showoffload .= $offloadstr{$sparetype};
16424: } else {
16425: $showoffload .= &mt('None');
16426: }
16427: $showoffload .= (' 'x3);
16428: }
16429: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 16430: }
16431: }
16432: }
1.171 raeburn 16433: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
16434: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
16435: foreach my $type (@{$alltypes}) {
16436: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
16437: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
16438: my $balancetext;
16439: if ($rule eq '') {
16440: $balancetext = $ruletitles{'default'};
1.209 raeburn 16441: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 16442: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 16443: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 16444: foreach my $sparetype (@sparestypes) {
16445: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16446: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
16447: }
16448: }
1.253 raeburn 16449: foreach my $item (@{$alltypes}) {
16450: next if ($item =~ /^_LC_ipchange/);
16451: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
16452: if ($hasrule eq 'homeserver') {
16453: map { $toupdate{$_} = 1; } (keys(%libraryservers));
16454: } else {
16455: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
16456: if ($servers{$hasrule}) {
16457: $toupdate{$hasrule} = 1;
16458: }
16459: }
16460: }
16461: }
1.254 raeburn 16462: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
16463: $balancetext = $ruletitles{$rule};
16464: } else {
16465: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
16466: $balancetext = $ruletitles{'particular'}.' '.$receiver;
16467: if ($receiver) {
16468: $toupdate{$receiver};
16469: }
16470: }
16471: } else {
16472: $balancetext = $ruletitles{$rule};
1.252 raeburn 16473: }
1.171 raeburn 16474: } else {
16475: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
16476: }
1.210 raeburn 16477: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 16478: }
16479: }
16480: }
16481: }
1.252 raeburn 16482: if (keys(%toupdate)) {
16483: my %thismachine;
16484: my $updatedhere;
16485: my $cachetime = 60*60*24;
16486: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
16487: foreach my $lonhost (keys(%toupdate)) {
16488: if ($thismachine{$lonhost}) {
16489: unless ($updatedhere) {
16490: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
16491: $defaultshash{'loadbalancing'},
16492: $cachetime);
16493: $updatedhere = 1;
16494: }
16495: } else {
16496: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
16497: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
16498: }
16499: }
16500: }
1.150 raeburn 16501: }
1.171 raeburn 16502: }
16503: if ($resulttext ne '') {
16504: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 16505: } else {
16506: $resulttext = $nochgmsg;
16507: }
16508: } else {
1.171 raeburn 16509: $resulttext = $nochgmsg;
1.150 raeburn 16510: }
16511: } else {
1.171 raeburn 16512: $resulttext = '<span class="LC_error">'.
16513: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 16514: }
16515: } else {
1.171 raeburn 16516: $resulttext = $nochgmsg;
1.150 raeburn 16517: }
16518: return $resulttext;
16519: }
16520:
1.48 raeburn 16521: sub recurse_check {
16522: my ($chkcats,$categories,$depth,$name) = @_;
16523: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
16524: my $chg = 0;
16525: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
16526: my $category = $chkcats->[$depth]{$name}[$j];
16527: my $item;
16528: if ($category eq '') {
16529: $chg ++;
16530: } else {
16531: my $deeper = $depth + 1;
16532: $item = &escape($category).':'.&escape($name).':'.$depth;
16533: if ($chg) {
16534: $categories->{$item} -= $chg;
16535: }
16536: &recurse_check($chkcats,$categories,$deeper,$category);
16537: $deeper --;
16538: }
16539: }
16540: }
16541: return;
16542: }
16543:
16544: sub recurse_cat_deletes {
16545: my ($item,$coursecategories,$deletions) = @_;
16546: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
16547: my $subdepth = $depth + 1;
16548: if (ref($coursecategories) eq 'HASH') {
16549: foreach my $subitem (keys(%{$coursecategories})) {
16550: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
16551: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
16552: delete($coursecategories->{$subitem});
16553: $deletions->{$subitem} = 1;
16554: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 16555: }
1.48 raeburn 16556: }
16557: }
16558: return;
16559: }
16560:
1.125 raeburn 16561: sub active_dc_picker {
1.191 raeburn 16562: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 16563: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 16564: my @domcoord = keys(%domcoords);
16565: if (keys(%currhash)) {
16566: foreach my $dc (keys(%currhash)) {
16567: unless (exists($domcoords{$dc})) {
16568: push(@domcoord,$dc);
16569: }
16570: }
16571: }
16572: @domcoord = sort(@domcoord);
1.210 raeburn 16573: my $numdcs = scalar(@domcoord);
1.191 raeburn 16574: my $rows = 0;
16575: my $table;
1.125 raeburn 16576: if ($numdcs > 1) {
1.191 raeburn 16577: $table = '<table>';
16578: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 16579: my $rem = $i%($numinrow);
16580: if ($rem == 0) {
16581: if ($i > 0) {
1.191 raeburn 16582: $table .= '</tr>';
1.125 raeburn 16583: }
1.191 raeburn 16584: $table .= '<tr>';
16585: $rows ++;
1.125 raeburn 16586: }
1.191 raeburn 16587: my $check = '';
16588: if ($inputtype eq 'radio') {
16589: if (keys(%currhash) == 0) {
16590: if (!$i) {
16591: $check = ' checked="checked"';
16592: }
16593: } elsif (exists($currhash{$domcoord[$i]})) {
16594: $check = ' checked="checked"';
16595: }
16596: } else {
16597: if (exists($currhash{$domcoord[$i]})) {
16598: $check = ' checked="checked"';
1.125 raeburn 16599: }
16600: }
1.191 raeburn 16601: if ($i == @domcoord - 1) {
1.125 raeburn 16602: my $colsleft = $numinrow - $rem;
16603: if ($colsleft > 1) {
1.191 raeburn 16604: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 16605: } else {
1.191 raeburn 16606: $table .= '<td class="LC_left_item">';
1.125 raeburn 16607: }
16608: } else {
1.191 raeburn 16609: $table .= '<td class="LC_left_item">';
16610: }
16611: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
16612: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
16613: $table .= '<span class="LC_nobreak"><label>'.
16614: '<input type="'.$inputtype.'" name="'.$name.'"'.
16615: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
16616: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 16617: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 16618: }
1.219 raeburn 16619: $table .= '</label></span></td>';
1.191 raeburn 16620: }
16621: $table .= '</tr></table>';
16622: } elsif ($numdcs == 1) {
1.219 raeburn 16623: my ($dcname,$dcdom) = split(':',$domcoord[0]);
16624: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 16625: if ($inputtype eq 'radio') {
1.247 raeburn 16626: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 16627: if ($user ne $dcname.':'.$dcdom) {
16628: $table .= ' ('.$dcname.':'.$dcdom.')';
16629: }
1.191 raeburn 16630: } else {
16631: my $check;
16632: if (exists($currhash{$domcoord[0]})) {
16633: $check = ' checked="checked"';
1.125 raeburn 16634: }
1.247 raeburn 16635: $table = '<span class="LC_nobreak"><label>'.
16636: '<input type="checkbox" name="'.$name.'" '.
16637: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 16638: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 16639: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 16640: }
1.220 raeburn 16641: $table .= '</label></span>';
1.191 raeburn 16642: $rows ++;
1.125 raeburn 16643: }
16644: }
1.191 raeburn 16645: return ($numdcs,$table,$rows);
1.125 raeburn 16646: }
16647:
1.137 raeburn 16648: sub usersession_titles {
16649: return &Apache::lonlocal::texthash(
16650: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
16651: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 16652: spares => 'Servers offloaded to, when busy',
1.137 raeburn 16653: version => 'LON-CAPA version requirement',
1.138 raeburn 16654: excludedomain => 'Allow all, but exclude specific domains',
16655: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 16656: primary => 'Primary (checked first)',
1.154 raeburn 16657: default => 'Default',
1.137 raeburn 16658: );
16659: }
16660:
1.152 raeburn 16661: sub id_for_thisdom {
16662: my (%servers) = @_;
16663: my %altids;
16664: foreach my $server (keys(%servers)) {
16665: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
16666: if ($serverhome ne $server) {
16667: $altids{$serverhome} = $server;
16668: }
16669: }
16670: return %altids;
16671: }
16672:
1.150 raeburn 16673: sub count_servers {
16674: my ($currbalancer,%servers) = @_;
16675: my (@spares,$numspares);
16676: foreach my $lonhost (sort(keys(%servers))) {
16677: next if ($currbalancer eq $lonhost);
16678: push(@spares,$lonhost);
16679: }
16680: if ($currbalancer) {
16681: $numspares = scalar(@spares);
16682: } else {
16683: $numspares = scalar(@spares) - 1;
16684: }
16685: return ($numspares,@spares);
16686: }
16687:
16688: sub lonbalance_targets_js {
1.171 raeburn 16689: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 16690: my $select = &mt('Select');
16691: my ($alltargets,$allishome,$allinsttypes,@alltypes);
16692: if (ref($servers) eq 'HASH') {
16693: $alltargets = join("','",sort(keys(%{$servers})));
16694: my @homedoms;
16695: foreach my $server (sort(keys(%{$servers}))) {
16696: if (&Apache::lonnet::host_domain($server) eq $dom) {
16697: push(@homedoms,'1');
16698: } else {
16699: push(@homedoms,'0');
16700: }
16701: }
16702: $allishome = join("','",@homedoms);
16703: }
16704: if (ref($types) eq 'ARRAY') {
16705: if (@{$types} > 0) {
16706: @alltypes = @{$types};
16707: }
16708: }
16709: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
16710: $allinsttypes = join("','",@alltypes);
1.171 raeburn 16711: my (%currbalancer,%currtargets,%currrules,%existing);
16712: if (ref($settings) eq 'HASH') {
16713: %existing = %{$settings};
16714: }
16715: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
16716: \%currtargets,\%currrules);
1.210 raeburn 16717: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 16718: return <<"END";
16719:
16720: <script type="text/javascript">
16721: // <![CDATA[
16722:
1.171 raeburn 16723: currBalancers = new Array('$balancers');
16724:
16725: function toggleTargets(balnum) {
16726: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
16727: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
16728: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
16729: var prevbalancer = prevhostitem.value;
16730: var baltotal = document.getElementById('loadbalancing_total').value;
16731: prevhostitem.value = balancer;
16732: if (prevbalancer != '') {
16733: var prevIdx = currBalancers.indexOf(prevbalancer);
16734: if (prevIdx != -1) {
16735: currBalancers.splice(prevIdx,1);
16736: }
16737: }
1.150 raeburn 16738: if (balancer == '') {
1.171 raeburn 16739: hideSpares(balnum);
1.150 raeburn 16740: } else {
1.171 raeburn 16741: var currIdx = currBalancers.indexOf(balancer);
16742: if (currIdx == -1) {
16743: currBalancers.push(balancer);
16744: }
1.150 raeburn 16745: var homedoms = new Array('$allishome');
1.171 raeburn 16746: var ishomedom = homedoms[lonhostitem.selectedIndex];
16747: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 16748: }
1.171 raeburn 16749: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 16750: return;
16751: }
16752:
1.171 raeburn 16753: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 16754: var alltargets = new Array('$alltargets');
16755: var insttypes = new Array('$allinsttypes');
1.151 raeburn 16756: var offloadtypes = new Array('primary','default');
16757:
1.171 raeburn 16758: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
16759: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 16760:
1.151 raeburn 16761: for (var i=0; i<offloadtypes.length; i++) {
16762: var count = 0;
16763: for (var j=0; j<alltargets.length; j++) {
16764: if (alltargets[j] != balancer) {
1.171 raeburn 16765: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
16766: item.value = alltargets[j];
16767: item.style.textAlign='left';
16768: item.style.textFace='normal';
16769: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
16770: if (currBalancers.indexOf(alltargets[j]) == -1) {
16771: item.disabled = '';
16772: } else {
16773: item.disabled = 'disabled';
16774: item.checked = false;
16775: }
1.151 raeburn 16776: count ++;
16777: }
1.150 raeburn 16778: }
16779: }
1.151 raeburn 16780: for (var k=0; k<insttypes.length; k++) {
16781: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 16782: if (ishomedom == 1) {
1.171 raeburn 16783: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
16784: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 16785: } else {
1.171 raeburn 16786: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
16787: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 16788: }
16789: } else {
1.171 raeburn 16790: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
16791: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 16792: }
1.151 raeburn 16793: if ((insttypes[k] != '_LC_external') &&
16794: ((insttypes[k] != '_LC_internetdom') ||
16795: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 16796: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
16797: item.options.length = 0;
16798: item.options[0] = new Option("","",true,true);
1.210 raeburn 16799: var idx = 0;
1.151 raeburn 16800: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 16801: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
16802: idx ++;
16803: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 16804: }
16805: }
16806: }
16807: }
16808: return;
16809: }
16810:
1.171 raeburn 16811: function hideSpares(balnum) {
1.150 raeburn 16812: var alltargets = new Array('$alltargets');
16813: var insttypes = new Array('$allinsttypes');
16814: var offloadtypes = new Array('primary','default');
16815:
1.171 raeburn 16816: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
16817: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 16818:
16819: var total = alltargets.length - 1;
16820: for (var i=0; i<offloadtypes; i++) {
16821: for (var j=0; j<total; j++) {
1.171 raeburn 16822: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
16823: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
16824: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 16825: }
1.150 raeburn 16826: }
16827: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 16828: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
16829: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 16830: if (insttypes[k] != '_LC_external') {
1.171 raeburn 16831: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
16832: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 16833: }
16834: }
16835: return;
16836: }
16837:
1.171 raeburn 16838: function checkOffloads(item,balnum,type) {
1.150 raeburn 16839: var alltargets = new Array('$alltargets');
16840: var offloadtypes = new Array('primary','default');
16841: if (item.checked) {
16842: var total = alltargets.length - 1;
16843: var other;
16844: if (type == offloadtypes[0]) {
1.151 raeburn 16845: other = offloadtypes[1];
1.150 raeburn 16846: } else {
1.151 raeburn 16847: other = offloadtypes[0];
1.150 raeburn 16848: }
16849: for (var i=0; i<total; i++) {
1.171 raeburn 16850: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 16851: if (server == item.value) {
1.171 raeburn 16852: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
16853: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 16854: }
16855: }
16856: }
16857: }
16858: return;
16859: }
16860:
1.171 raeburn 16861: function singleServerToggle(balnum,type) {
16862: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 16863: if (offloadtoSelIdx == 0) {
1.171 raeburn 16864: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
16865: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 16866:
16867: } else {
1.171 raeburn 16868: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
16869: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 16870: }
16871: return;
16872: }
16873:
1.171 raeburn 16874: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 16875: if (type == '_LC_external') {
1.171 raeburn 16876: return;
1.150 raeburn 16877: }
1.171 raeburn 16878: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 16879: for (var i=0; i<typesRules.length; i++) {
16880: if (formname.elements[typesRules[i]].checked) {
16881: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 16882: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
16883: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 16884: } else {
1.171 raeburn 16885: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
16886: }
16887: }
16888: }
16889: return;
16890: }
16891:
16892: function balancerDeleteChange(balnum) {
16893: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
16894: var baltotal = document.getElementById('loadbalancing_total').value;
16895: var addtarget;
16896: var removetarget;
16897: var action = 'delete';
16898: if (document.getElementById('loadbalancing_delete_'+balnum)) {
16899: var lonhost = hostitem.value;
16900: var currIdx = currBalancers.indexOf(lonhost);
16901: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
16902: if (currIdx != -1) {
16903: currBalancers.splice(currIdx,1);
16904: }
16905: addtarget = lonhost;
16906: } else {
16907: if (currIdx == -1) {
16908: currBalancers.push(lonhost);
16909: }
16910: removetarget = lonhost;
16911: action = 'undelete';
16912: }
16913: balancerChange(balnum,baltotal,action,addtarget,removetarget);
16914: }
16915: return;
16916: }
16917:
16918: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
16919: if (baltotal > 1) {
16920: var offloadtypes = new Array('primary','default');
16921: var alltargets = new Array('$alltargets');
16922: var insttypes = new Array('$allinsttypes');
16923: for (var i=0; i<baltotal; i++) {
16924: if (i != balnum) {
16925: for (var j=0; j<offloadtypes.length; j++) {
16926: var total = alltargets.length - 1;
16927: for (var k=0; k<total; k++) {
16928: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
16929: var server = serveritem.value;
16930: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
16931: if (server == addtarget) {
16932: serveritem.disabled = '';
16933: }
16934: }
16935: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
16936: if (server == removetarget) {
16937: serveritem.disabled = 'disabled';
16938: serveritem.checked = false;
16939: }
16940: }
16941: }
16942: }
16943: for (var j=0; j<insttypes.length; j++) {
16944: if (insttypes[j] != '_LC_external') {
16945: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
16946: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
16947: var currSel = singleserver.selectedIndex;
16948: var currVal = singleserver.options[currSel].value;
16949: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
16950: var numoptions = singleserver.options.length;
16951: var needsnew = 1;
16952: for (var k=0; k<numoptions; k++) {
16953: if (singleserver.options[k] == addtarget) {
16954: needsnew = 0;
16955: break;
16956: }
16957: }
16958: if (needsnew == 1) {
16959: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
16960: }
16961: }
16962: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
16963: singleserver.options.length = 0;
16964: if ((currVal) && (currVal != removetarget)) {
16965: singleserver.options[0] = new Option("","",false,false);
16966: } else {
16967: singleserver.options[0] = new Option("","",true,true);
16968: }
16969: var idx = 0;
16970: for (var m=0; m<alltargets.length; m++) {
16971: if (currBalancers.indexOf(alltargets[m]) == -1) {
16972: idx ++;
16973: if (currVal == alltargets[m]) {
16974: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
16975: } else {
16976: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
16977: }
16978: }
16979: }
16980: }
16981: }
16982: }
16983: }
1.150 raeburn 16984: }
16985: }
16986: }
16987: return;
16988: }
16989:
1.152 raeburn 16990: // ]]>
16991: </script>
16992:
16993: END
16994: }
16995:
16996: sub new_spares_js {
16997: my @sparestypes = ('primary','default');
16998: my $types = join("','",@sparestypes);
16999: my $select = &mt('Select');
17000: return <<"END";
17001:
17002: <script type="text/javascript">
17003: // <![CDATA[
17004:
17005: function updateNewSpares(formname,lonhost) {
17006: var types = new Array('$types');
17007: var include = new Array();
17008: var exclude = new Array();
17009: for (var i=0; i<types.length; i++) {
17010: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
17011: for (var j=0; j<spareboxes.length; j++) {
17012: if (formname.elements[spareboxes[j]].checked) {
17013: exclude.push(formname.elements[spareboxes[j]].value);
17014: } else {
17015: include.push(formname.elements[spareboxes[j]].value);
17016: }
17017: }
17018: }
17019: for (var i=0; i<types.length; i++) {
17020: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
17021: var selIdx = newSpare.selectedIndex;
17022: var currnew = newSpare.options[selIdx].value;
17023: var okSpares = new Array();
17024: for (var j=0; j<newSpare.options.length; j++) {
17025: var possible = newSpare.options[j].value;
17026: if (possible != '') {
17027: if (exclude.indexOf(possible) == -1) {
17028: okSpares.push(possible);
17029: } else {
17030: if (currnew == possible) {
17031: selIdx = 0;
17032: }
17033: }
17034: }
17035: }
17036: for (var k=0; k<include.length; k++) {
17037: if (okSpares.indexOf(include[k]) == -1) {
17038: okSpares.push(include[k]);
17039: }
17040: }
17041: okSpares.sort();
17042: newSpare.options.length = 0;
17043: if (selIdx == 0) {
17044: newSpare.options[0] = new Option("$select","",true,true);
17045: } else {
17046: newSpare.options[0] = new Option("$select","",false,false);
17047: }
17048: for (var m=0; m<okSpares.length; m++) {
17049: var idx = m+1;
17050: var selThis = 0;
17051: if (selIdx != 0) {
17052: if (okSpares[m] == currnew) {
17053: selThis = 1;
17054: }
17055: }
17056: if (selThis == 1) {
17057: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
17058: } else {
17059: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
17060: }
17061: }
17062: }
17063: return;
17064: }
17065:
17066: function checkNewSpares(lonhost,type) {
17067: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
17068: var chosen = newSpare.options[newSpare.selectedIndex].value;
17069: if (chosen != '') {
17070: var othertype;
17071: var othernewSpare;
17072: if (type == 'primary') {
17073: othernewSpare = document.getElementById('newspare_default_'+lonhost);
17074: }
17075: if (type == 'default') {
17076: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
17077: }
17078: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
17079: othernewSpare.selectedIndex = 0;
17080: }
17081: }
17082: return;
17083: }
17084:
17085: // ]]>
17086: </script>
17087:
17088: END
17089:
17090: }
17091:
17092: sub common_domprefs_js {
17093: return <<"END";
17094:
17095: <script type="text/javascript">
17096: // <![CDATA[
17097:
1.150 raeburn 17098: function getIndicesByName(formname,item) {
1.152 raeburn 17099: var group = new Array();
1.150 raeburn 17100: for (var i=0;i<formname.elements.length;i++) {
17101: if (formname.elements[i].name == item) {
1.152 raeburn 17102: group.push(formname.elements[i].id);
1.150 raeburn 17103: }
17104: }
1.152 raeburn 17105: return group;
1.150 raeburn 17106: }
17107:
17108: // ]]>
17109: </script>
17110:
17111: END
1.152 raeburn 17112:
1.150 raeburn 17113: }
17114:
1.165 raeburn 17115: sub recaptcha_js {
17116: my %lt = &captcha_phrases();
17117: return <<"END";
17118:
17119: <script type="text/javascript">
17120: // <![CDATA[
17121:
17122: function updateCaptcha(caller,context) {
17123: var privitem;
17124: var pubitem;
17125: var privtext;
17126: var pubtext;
1.269 raeburn 17127: var versionitem;
17128: var versiontext;
1.165 raeburn 17129: if (document.getElementById(context+'_recaptchapub')) {
17130: pubitem = document.getElementById(context+'_recaptchapub');
17131: } else {
17132: return;
17133: }
17134: if (document.getElementById(context+'_recaptchapriv')) {
17135: privitem = document.getElementById(context+'_recaptchapriv');
17136: } else {
17137: return;
17138: }
17139: if (document.getElementById(context+'_recaptchapubtxt')) {
17140: pubtext = document.getElementById(context+'_recaptchapubtxt');
17141: } else {
17142: return;
17143: }
17144: if (document.getElementById(context+'_recaptchaprivtxt')) {
17145: privtext = document.getElementById(context+'_recaptchaprivtxt');
17146: } else {
17147: return;
17148: }
1.269 raeburn 17149: if (document.getElementById(context+'_recaptchaversion')) {
17150: versionitem = document.getElementById(context+'_recaptchaversion');
17151: } else {
17152: return;
17153: }
17154: if (document.getElementById(context+'_recaptchavertxt')) {
17155: versiontext = document.getElementById(context+'_recaptchavertxt');
17156: } else {
17157: return;
17158: }
1.165 raeburn 17159: if (caller.checked) {
17160: if (caller.value == 'recaptcha') {
17161: pubitem.type = 'text';
17162: privitem.type = 'text';
17163: pubitem.size = '40';
17164: privitem.size = '40';
17165: pubtext.innerHTML = "$lt{'pub'}";
17166: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 17167: versionitem.type = 'text';
17168: versionitem.size = '3';
1.289 raeburn 17169: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 17170: } else {
17171: pubitem.type = 'hidden';
17172: privitem.type = 'hidden';
1.269 raeburn 17173: versionitem.type = 'hidden';
1.165 raeburn 17174: pubtext.innerHTML = '';
17175: privtext.innerHTML = '';
1.269 raeburn 17176: versiontext.innerHTML = '';
1.165 raeburn 17177: }
17178: }
17179: return;
17180: }
17181:
17182: // ]]>
17183: </script>
17184:
17185: END
17186:
17187: }
17188:
1.236 raeburn 17189: sub toggle_display_js {
1.192 raeburn 17190: return <<"END";
17191:
17192: <script type="text/javascript">
17193: // <![CDATA[
17194:
1.236 raeburn 17195: function toggleDisplay(domForm,caller) {
17196: if (document.getElementById(caller)) {
17197: var divitem = document.getElementById(caller);
17198: var optionsElement = domForm.coursecredits;
1.264 raeburn 17199: var checkval = 1;
17200: var dispval = 'block';
1.303 raeburn 17201: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 17202: if (caller == 'emailoptions') {
17203: optionsElement = domForm.cancreate_email;
17204: }
1.257 raeburn 17205: if (caller == 'studentsubmission') {
17206: optionsElement = domForm.postsubmit;
17207: }
1.264 raeburn 17208: if (caller == 'cloneinstcode') {
17209: optionsElement = domForm.canclone;
17210: checkval = 'instcode';
17211: }
1.303 raeburn 17212: if (selfcreateRegExp.test(caller)) {
17213: optionsElement = domForm.elements[caller];
17214: checkval = 'other';
17215: dispval = 'inline'
17216: }
1.236 raeburn 17217: if (optionsElement.length) {
1.192 raeburn 17218: var currval;
1.236 raeburn 17219: for (var i=0; i<optionsElement.length; i++) {
17220: if (optionsElement[i].checked) {
17221: currval = optionsElement[i].value;
1.192 raeburn 17222: }
17223: }
1.264 raeburn 17224: if (currval == checkval) {
17225: divitem.style.display = dispval;
1.192 raeburn 17226: } else {
1.236 raeburn 17227: divitem.style.display = 'none';
1.192 raeburn 17228: }
17229: }
17230: }
17231: return;
17232: }
17233:
17234: // ]]>
17235: </script>
17236:
17237: END
17238:
17239: }
17240:
1.165 raeburn 17241: sub captcha_phrases {
17242: return &Apache::lonlocal::texthash (
17243: priv => 'Private key',
17244: pub => 'Public key',
17245: original => 'original (CAPTCHA)',
17246: recaptcha => 'successor (ReCAPTCHA)',
17247: notused => 'unused',
1.289 raeburn 17248: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 17249: );
17250: }
17251:
1.205 raeburn 17252: sub devalidate_remote_domconfs {
1.212 raeburn 17253: my ($dom,$cachekeys) = @_;
17254: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 17255: my %servers = &Apache::lonnet::internet_dom_servers($dom);
17256: my %thismachine;
17257: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.295 raeburn 17258: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions','directorysrch');
1.260 raeburn 17259: if (keys(%servers)) {
1.205 raeburn 17260: foreach my $server (keys(%servers)) {
17261: next if ($thismachine{$server});
1.212 raeburn 17262: my @cached;
17263: foreach my $name (@posscached) {
17264: if ($cachekeys->{$name}) {
17265: push(@cached,&escape($name).':'.&escape($dom));
17266: }
17267: }
17268: if (@cached) {
17269: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
17270: }
1.205 raeburn 17271: }
17272: }
17273: return;
17274: }
17275:
1.3 raeburn 17276: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>