Annotation of loncom/interface/domainprefs.pm, revision 1.332
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.332 ! raeburn 4: # $Id: domainprefs.pm,v 1.331 2018/07/06 13:29:49 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
1.286 raeburn 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
1.1 raeburn 24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
1.297 raeburn 30: ###############################################################
1.1 raeburn 31:
1.101 raeburn 32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
1.183 bisitz 49: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 50: may define a default set of logos and a color scheme which can be used to "brand"
51: the LON-CAPA instance. In addition, an institution will typically have a language
52: and timezone which are used for the majority of courses.
53:
54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
55: host of other domain-wide settings which determine the types of functionality
56: available to users and courses in the domain.
57:
58: There is also a mechanism to configure cataloging of courses in the domain, and
59: controls on the operation of automated processes which govern such things as
60: roster updates, user directory updates and processing of course requests.
61:
62: The domain coordination manual which is built dynamically on install/update of
63: LON-CAPA from the relevant help items provides more information about domain
64: configuration.
65:
66: Most of the domain settings are stored in the configuration.db GDBM file which is
67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
68: where $dom is the domain. The configuration.db stores settings in a number of
69: frozen hashes of hashes. In a few cases, domain information must be uploaded to
70: the domain as files (e.g., image files for logos etc., or plain text files for
71: bubblesheet formats). In this case the domainprefs.pm must be running in a user
72: session hosted on the primary library server in the domain, as these files are
73: stored in author space belonging to a special $dom-domainconfig user.
74:
75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
76: the current settings, and provides an interface to make modifications.
77:
78: =head1 SUBROUTINES
79:
80: =over
81:
82: =item print_quotas()
83:
84: Inputs: 4
85:
86: $dom,$settings,$rowtotal,$action.
87:
88: $dom is the domain, $settings is a reference to a hash of current settings for
89: the current context, $rowtotal is a reference to the scalar used to record the
1.210 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.163 raeburn 91: requestcourses or requestauthor).
1.101 raeburn 92:
93: The print_quotas routine was orginally created to display/store information
94: about default quota sizes for portfolio spaces for the different types of
95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
96: but is now also used to manage availability of user tools:
97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.197 raeburn 98: used by course owners to request creation of a course, and to display/store
1.223 bisitz 99: default quota sizes for Authoring Spaces.
1.101 raeburn 100:
101: Outputs: 1
102:
103: $datatable - HTML containing form elements which allow settings to be changed.
104:
105: In the case of course requests, radio buttons are displayed for each institutional
106: affiliate type (and also default, and _LC_adv) for each of the course types
1.325 raeburn 107: (official, unofficial, community, textbook, placement, and lti).
1.271 raeburn 108: In each case the radio buttons allow the selection of one of four values:
1.101 raeburn 109:
1.104 raeburn 110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 111: which have the following effects:
112:
113: 0
114:
115: =over
116:
117: - course requests are not allowed for this course types/affiliation
118:
119: =back
120:
1.104 raeburn 121: approval
1.101 raeburn 122:
123: =over
124:
125: - course requests must be approved by a Doman Coordinator in the
126: course's domain
127:
128: =back
129:
130: validate
131:
132: =over
133:
134: - an institutional validation (e.g., check requestor is instructor
135: of record) needs to be passed before the course will be created. The required
136: validation is in localenroll.pm on the primary library server for the course
137: domain.
138:
139: =back
140:
141: autolimit
142:
143: =over
144:
1.143 raeburn 145: - course requests will be processed automatically up to a limit of
1.101 raeburn 146: N requests for the course type for the particular requestor.
147: If N is undefined, there is no limit to the number of course requests
148: which a course owner may submit and have processed automatically.
149:
150: =back
151:
152: =item modify_quotas()
153:
154: =back
155:
156: =cut
157:
1.1 raeburn 158: package Apache::domainprefs;
159:
160: use strict;
161: use Apache::Constants qw(:common :http);
162: use Apache::lonnet;
163: use Apache::loncommon();
164: use Apache::lonhtmlcommon();
165: use Apache::lonlocal;
1.43 raeburn 166: use Apache::lonmsg();
1.91 raeburn 167: use Apache::lonconfigsettings;
1.232 raeburn 168: use Apache::lonuserutils();
1.235 raeburn 169: use Apache::loncoursequeueadmin();
1.69 raeburn 170: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 171: use LONCAPA::Enrollment;
1.81 raeburn 172: use LONCAPA::lonauthcgi();
1.275 raeburn 173: use LONCAPA::SSL;
1.9 raeburn 174: use File::Copy;
1.43 raeburn 175: use Locale::Language;
1.62 raeburn 176: use DateTime::TimeZone;
1.68 raeburn 177: use DateTime::Locale;
1.267 raeburn 178: use Time::HiRes qw( sleep );
1.1 raeburn 179:
1.155 raeburn 180: my $registered_cleanup;
181: my $modified_urls;
182:
1.1 raeburn 183: sub handler {
184: my $r=shift;
185: if ($r->header_only) {
186: &Apache::loncommon::content_type($r,'text/html');
187: $r->send_http_header;
188: return OK;
189: }
190:
1.91 raeburn 191: my $context = 'domain';
1.1 raeburn 192: my $dom = $env{'request.role.domain'};
1.5 albertel 193: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 194: if (&Apache::lonnet::allowed('mau',$dom)) {
195: &Apache::loncommon::content_type($r,'text/html');
196: $r->send_http_header;
197: } else {
198: $env{'user.error.msg'}=
199: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
200: return HTTP_NOT_ACCEPTABLE;
201: }
1.155 raeburn 202:
203: $registered_cleanup=0;
204: @{$modified_urls}=();
205:
1.1 raeburn 206: &Apache::lonhtmlcommon::clear_breadcrumbs();
207: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 208: ['phase','actions']);
1.30 raeburn 209: my $phase = 'pickactions';
1.3 raeburn 210: if ( exists($env{'form.phase'}) ) {
211: $phase = $env{'form.phase'};
212: }
1.150 raeburn 213: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 214: my %domconfig =
1.6 raeburn 215: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 216: 'quotas','autoenroll','autoupdate','autocreate',
217: 'directorysrch','usercreation','usermodification',
218: 'contacts','defaults','scantron','coursecategories',
219: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 220: 'coursedefaults','usersessions','loadbalancing',
1.267 raeburn 221: 'requestauthor','selfenrollment','inststatus',
1.320 raeburn 222: 'ltitools','ssl','trust','lti'],$dom);
223: my %encconfig =
224: &Apache::lonnet::get_dom('encconfig',['ltitools','lti'],$dom);
1.297 raeburn 225: if (ref($domconfig{'ltitools'}) eq 'HASH') {
226: if (ref($encconfig{'ltitools'}) eq 'HASH') {
227: foreach my $id (keys(%{$domconfig{'ltitools'}})) {
1.320 raeburn 228: if ((ref($domconfig{'ltitools'}{$id}) eq 'HASH') &&
229: (ref($encconfig{'ltitools'}{$id}) eq 'HASH')) {
1.297 raeburn 230: foreach my $item ('key','secret') {
231: $domconfig{'ltitools'}{$id}{$item} = $encconfig{'ltitools'}{$id}{$item};
232: }
233: }
234: }
235: }
236: }
1.320 raeburn 237: if (ref($domconfig{'lti'}) eq 'HASH') {
238: if (ref($encconfig{'lti'}) eq 'HASH') {
239: foreach my $id (keys(%{$domconfig{'lti'}})) {
240: if ((ref($domconfig{'lti'}{$id}) eq 'HASH') &&
241: (ref($encconfig{'lti'}{$id}) eq 'HASH')) {
242: foreach my $item ('key','secret') {
243: $domconfig{'lti'}{$id}{$item} = $encconfig{'lti'}{$id}{$item};
244: }
245: }
246: }
247: }
248: }
1.43 raeburn 249: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 250: 'autoupdate','autocreate','directorysrch','contacts',
1.224 raeburn 251: 'usercreation','selfcreation','usermodification','scantron',
1.163 raeburn 252: 'requestcourses','requestauthor','coursecategories',
1.267 raeburn 253: 'serverstatuses','helpsettings','coursedefaults',
1.320 raeburn 254: 'ltitools','selfenrollment','usersessions','ssl','trust','lti');
1.171 raeburn 255: my %existing;
256: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
257: %existing = %{$domconfig{'loadbalancing'}};
258: }
259: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 260: push(@prefs_order,'loadbalancing');
261: }
1.30 raeburn 262: my %prefs = (
263: 'rolecolors' =>
264: { text => 'Default color schemes',
1.67 raeburn 265: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 266: header => [{col1 => 'Student Settings',
267: col2 => '',},
268: {col1 => 'Coordinator Settings',
269: col2 => '',},
270: {col1 => 'Author Settings',
271: col2 => '',},
272: {col1 => 'Administrator Settings',
273: col2 => '',}],
1.230 raeburn 274: print => \&print_rolecolors,
275: modify => \&modify_rolecolors,
1.30 raeburn 276: },
1.110 raeburn 277: 'login' =>
1.30 raeburn 278: { text => 'Log-in page options',
1.67 raeburn 279: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 280: header => [{col1 => 'Log-in Page Items',
281: col2 => '',},
282: {col1 => 'Log-in Help',
1.256 raeburn 283: col2 => 'Value'},
284: {col1 => 'Custom HTML in document head',
1.168 raeburn 285: col2 => 'Value'}],
1.230 raeburn 286: print => \&print_login,
287: modify => \&modify_login,
1.30 raeburn 288: },
1.43 raeburn 289: 'defaults' =>
1.236 raeburn 290: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 291: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 292: header => [{col1 => 'Setting',
1.236 raeburn 293: col2 => 'Value'},
1.294 raeburn 294: {col1 => 'Internal Authentication',
295: col2 => 'Value'},
1.236 raeburn 296: {col1 => 'Institutional user types',
1.305 raeburn 297: col2 => 'Name displayed'}],
1.230 raeburn 298: print => \&print_defaults,
299: modify => \&modify_defaults,
1.43 raeburn 300: },
1.30 raeburn 301: 'quotas' =>
1.197 raeburn 302: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 303: help => 'Domain_Configuration_Quotas',
1.77 raeburn 304: header => [{col1 => 'User affiliation',
1.72 raeburn 305: col2 => 'Available tools',
1.213 raeburn 306: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230 raeburn 307: print => \&print_quotas,
308: modify => \&modify_quotas,
1.30 raeburn 309: },
310: 'autoenroll' =>
311: { text => 'Auto-enrollment settings',
1.67 raeburn 312: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 313: header => [{col1 => 'Configuration setting',
314: col2 => 'Value(s)'}],
1.230 raeburn 315: print => \&print_autoenroll,
316: modify => \&modify_autoenroll,
1.30 raeburn 317: },
318: 'autoupdate' =>
319: { text => 'Auto-update settings',
1.67 raeburn 320: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 321: header => [{col1 => 'Setting',
322: col2 => 'Value',},
1.131 raeburn 323: {col1 => 'Setting',
324: col2 => 'Affiliation'},
1.43 raeburn 325: {col1 => 'User population',
1.227 bisitz 326: col2 => 'Updatable user data'}],
1.230 raeburn 327: print => \&print_autoupdate,
328: modify => \&modify_autoupdate,
1.30 raeburn 329: },
1.125 raeburn 330: 'autocreate' =>
331: { text => 'Auto-course creation settings',
332: help => 'Domain_Configuration_Auto_Creation',
333: header => [{col1 => 'Configuration Setting',
334: col2 => 'Value',}],
1.230 raeburn 335: print => \&print_autocreate,
336: modify => \&modify_autocreate,
1.125 raeburn 337: },
1.30 raeburn 338: 'directorysrch' =>
1.277 raeburn 339: { text => 'Directory searches',
1.67 raeburn 340: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 341: header => [{col1 => 'Institutional Directory Setting',
342: col2 => 'Value',},
343: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 344: col2 => 'Value',}],
1.230 raeburn 345: print => \&print_directorysrch,
346: modify => \&modify_directorysrch,
1.30 raeburn 347: },
348: 'contacts' =>
1.286 raeburn 349: { text => 'E-mail addresses and helpform',
1.67 raeburn 350: help => 'Domain_Configuration_Contact_Info',
1.286 raeburn 351: header => [{col1 => 'Default e-mail addresses',
352: col2 => 'Value',},
353: {col1 => 'Recipient(s) for notifications',
354: col2 => 'Value',},
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: }
1.330 raeburn 1439: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256 raeburn 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.329 raeburn 1599: $datatable .= '<td>'.&mt('Default in use:').' <span class="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.329 raeburn 1608: ' </span></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'}) {
1.329 raeburn 1613: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 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.'" /> '.
1.329 raeburn 1623: ' </span></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.329 raeburn 1741: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span class="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 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.329 raeburn 1769: $links_def .= '<td>'.$choices->{$item}.'<br /><span class="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 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') {
1.331 raeburn 1855: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 1856: } elsif (!$is_custom) {
1.70 raeburn 1857: if ($img ne 'domlogo') {
1.331 raeburn 1858: $output = &mt('Default image:').'<br />';
1.41 raeburn 1859: } else {
1.331 raeburn 1860: $output = &mt('Default in use:').'<br />';
1.41 raeburn 1861: }
1862: }
1.331 raeburn 1863: if ($img ne 'login') {
1.135 bisitz 1864: if ($img_import) {
1865: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1866: }
1867: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1868: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1869: if ($is_custom) {
1870: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1871: '<input type="checkbox" name="'.
1872: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1873: '</label> '.&mt('Replace:').'</span><br />';
1874: } else {
1.306 raeburn 1875: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1876: }
1.41 raeburn 1877: }
1878: return $output;
1879: }
1880:
1.3 raeburn 1881: sub print_quotas {
1.86 raeburn 1882: my ($dom,$settings,$rowtotal,$action) = @_;
1883: my $context;
1884: if ($action eq 'quotas') {
1885: $context = 'tools';
1886: } else {
1887: $context = $action;
1888: }
1.197 raeburn 1889: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1890: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1891: my $typecount = 0;
1.101 raeburn 1892: my ($css_class,%titles);
1.86 raeburn 1893: if ($context eq 'requestcourses') {
1.325 raeburn 1894: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 1895: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1896: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1897: %titles = &courserequest_titles();
1.163 raeburn 1898: } elsif ($context eq 'requestauthor') {
1899: @usertools = ('author');
1900: @options = ('norequest','approval','automatic');
1.210 raeburn 1901: %titles = &authorrequest_titles();
1.86 raeburn 1902: } else {
1.162 raeburn 1903: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1904: %titles = &tool_titles();
1.86 raeburn 1905: }
1.26 raeburn 1906: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1907: foreach my $type (@{$types}) {
1.197 raeburn 1908: my ($currdefquota,$currauthorquota);
1.163 raeburn 1909: unless (($context eq 'requestcourses') ||
1910: ($context eq 'requestauthor')) {
1.86 raeburn 1911: if (ref($settings) eq 'HASH') {
1912: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1913: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1914: } else {
1915: $currdefquota = $settings->{$type};
1916: }
1.197 raeburn 1917: if (ref($settings->{authorquota}) eq 'HASH') {
1918: $currauthorquota = $settings->{authorquota}->{$type};
1919: }
1.78 raeburn 1920: }
1.72 raeburn 1921: }
1.3 raeburn 1922: if (defined($usertypes->{$type})) {
1923: $typecount ++;
1924: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1925: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1926: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1927: '<td class="LC_left_item">';
1.101 raeburn 1928: if ($context eq 'requestcourses') {
1929: $datatable .= '<table><tr>';
1930: }
1931: my %cell;
1.72 raeburn 1932: foreach my $item (@usertools) {
1.101 raeburn 1933: if ($context eq 'requestcourses') {
1934: my ($curroption,$currlimit);
1935: if (ref($settings) eq 'HASH') {
1936: if (ref($settings->{$item}) eq 'HASH') {
1937: $curroption = $settings->{$item}->{$type};
1938: if ($curroption =~ /^autolimit=(\d*)$/) {
1939: $currlimit = $1;
1940: }
1941: }
1942: }
1943: if (!$curroption) {
1944: $curroption = 'norequest';
1945: }
1946: $datatable .= '<th>'.$titles{$item}.'</th>';
1947: foreach my $option (@options) {
1948: my $val = $option;
1949: if ($option eq 'norequest') {
1950: $val = 0;
1951: }
1952: if ($option eq 'validate') {
1953: my $canvalidate = 0;
1954: if (ref($validations{$item}) eq 'HASH') {
1955: if ($validations{$item}{$type}) {
1956: $canvalidate = 1;
1957: }
1958: }
1959: next if (!$canvalidate);
1960: }
1961: my $checked = '';
1962: if ($option eq $curroption) {
1963: $checked = ' checked="checked"';
1964: } elsif ($option eq 'autolimit') {
1965: if ($curroption =~ /^autolimit/) {
1966: $checked = ' checked="checked"';
1967: }
1968: }
1969: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1970: '<input type="radio" name="crsreq_'.$item.
1971: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1972: $titles{$option}.'</label>';
1.101 raeburn 1973: if ($option eq 'autolimit') {
1.127 raeburn 1974: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1975: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1976: 'value="'.$currlimit.'" />';
1.101 raeburn 1977: }
1.127 raeburn 1978: $cell{$item} .= '</span> ';
1.103 raeburn 1979: if ($option eq 'autolimit') {
1.127 raeburn 1980: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1981: }
1.101 raeburn 1982: }
1.163 raeburn 1983: } elsif ($context eq 'requestauthor') {
1984: my $curroption;
1985: if (ref($settings) eq 'HASH') {
1986: $curroption = $settings->{$type};
1987: }
1988: if (!$curroption) {
1989: $curroption = 'norequest';
1990: }
1991: foreach my $option (@options) {
1992: my $val = $option;
1993: if ($option eq 'norequest') {
1994: $val = 0;
1995: }
1996: my $checked = '';
1997: if ($option eq $curroption) {
1998: $checked = ' checked="checked"';
1999: }
2000: $datatable .= '<span class="LC_nobreak"><label>'.
2001: '<input type="radio" name="authorreq_'.$type.
2002: '" value="'.$val.'"'.$checked.' />'.
2003: $titles{$option}.'</label></span> ';
2004: }
1.101 raeburn 2005: } else {
2006: my $checked = 'checked="checked" ';
2007: if (ref($settings) eq 'HASH') {
2008: if (ref($settings->{$item}) eq 'HASH') {
2009: if ($settings->{$item}->{$type} == 0) {
2010: $checked = '';
2011: } elsif ($settings->{$item}->{$type} == 1) {
2012: $checked = 'checked="checked" ';
2013: }
1.78 raeburn 2014: }
1.72 raeburn 2015: }
1.101 raeburn 2016: $datatable .= '<span class="LC_nobreak"><label>'.
2017: '<input type="checkbox" name="'.$context.'_'.$item.
2018: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2019: '</label></span> ';
1.72 raeburn 2020: }
1.101 raeburn 2021: }
2022: if ($context eq 'requestcourses') {
2023: $datatable .= '</tr><tr>';
2024: foreach my $item (@usertools) {
1.106 raeburn 2025: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2026: }
2027: $datatable .= '</tr></table>';
1.72 raeburn 2028: }
1.86 raeburn 2029: $datatable .= '</td>';
1.163 raeburn 2030: unless (($context eq 'requestcourses') ||
2031: ($context eq 'requestauthor')) {
1.86 raeburn 2032: $datatable .=
1.197 raeburn 2033: '<td class="LC_right_item">'.
2034: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2035: '<input type="text" name="quota_'.$type.
1.72 raeburn 2036: '" value="'.$currdefquota.
1.197 raeburn 2037: '" size="5" /></span>'.(' ' x 2).
2038: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2039: '<input type="text" name="authorquota_'.$type.
2040: '" value="'.$currauthorquota.
2041: '" size="5" /></span></td>';
1.86 raeburn 2042: }
2043: $datatable .= '</tr>';
1.3 raeburn 2044: }
2045: }
2046: }
1.163 raeburn 2047: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2048: $defaultquota = '20';
1.197 raeburn 2049: $authorquota = '500';
1.86 raeburn 2050: if (ref($settings) eq 'HASH') {
2051: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2052: $defaultquota = $settings->{'defaultquota'}->{'default'};
2053: } elsif (defined($settings->{'default'})) {
2054: $defaultquota = $settings->{'default'};
2055: }
1.197 raeburn 2056: if (ref($settings->{'authorquota'}) eq 'HASH') {
2057: $authorquota = $settings->{'authorquota'}->{'default'};
2058: }
1.3 raeburn 2059: }
2060: }
2061: $typecount ++;
2062: $css_class = $typecount%2?' class="LC_odd_row"':'';
2063: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2064: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2065: '<td class="LC_left_item">';
1.101 raeburn 2066: if ($context eq 'requestcourses') {
2067: $datatable .= '<table><tr>';
2068: }
2069: my %defcell;
1.72 raeburn 2070: foreach my $item (@usertools) {
1.101 raeburn 2071: if ($context eq 'requestcourses') {
2072: my ($curroption,$currlimit);
2073: if (ref($settings) eq 'HASH') {
2074: if (ref($settings->{$item}) eq 'HASH') {
2075: $curroption = $settings->{$item}->{'default'};
2076: if ($curroption =~ /^autolimit=(\d*)$/) {
2077: $currlimit = $1;
2078: }
2079: }
2080: }
2081: if (!$curroption) {
2082: $curroption = 'norequest';
2083: }
2084: $datatable .= '<th>'.$titles{$item}.'</th>';
2085: foreach my $option (@options) {
2086: my $val = $option;
2087: if ($option eq 'norequest') {
2088: $val = 0;
2089: }
2090: if ($option eq 'validate') {
2091: my $canvalidate = 0;
2092: if (ref($validations{$item}) eq 'HASH') {
2093: if ($validations{$item}{'default'}) {
2094: $canvalidate = 1;
2095: }
2096: }
2097: next if (!$canvalidate);
2098: }
2099: my $checked = '';
2100: if ($option eq $curroption) {
2101: $checked = ' checked="checked"';
2102: } elsif ($option eq 'autolimit') {
2103: if ($curroption =~ /^autolimit/) {
2104: $checked = ' checked="checked"';
2105: }
2106: }
2107: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2108: '<input type="radio" name="crsreq_'.$item.
2109: '_default" value="'.$val.'"'.$checked.' />'.
2110: $titles{$option}.'</label>';
2111: if ($option eq 'autolimit') {
1.127 raeburn 2112: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2113: $item.'_limit_default" size="1" '.
2114: 'value="'.$currlimit.'" />';
2115: }
1.127 raeburn 2116: $defcell{$item} .= '</span> ';
1.104 raeburn 2117: if ($option eq 'autolimit') {
1.127 raeburn 2118: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2119: }
1.101 raeburn 2120: }
1.163 raeburn 2121: } elsif ($context eq 'requestauthor') {
2122: my $curroption;
2123: if (ref($settings) eq 'HASH') {
1.172 raeburn 2124: $curroption = $settings->{'default'};
1.163 raeburn 2125: }
2126: if (!$curroption) {
2127: $curroption = 'norequest';
2128: }
2129: foreach my $option (@options) {
2130: my $val = $option;
2131: if ($option eq 'norequest') {
2132: $val = 0;
2133: }
2134: my $checked = '';
2135: if ($option eq $curroption) {
2136: $checked = ' checked="checked"';
2137: }
2138: $datatable .= '<span class="LC_nobreak"><label>'.
2139: '<input type="radio" name="authorreq_default"'.
2140: ' value="'.$val.'"'.$checked.' />'.
2141: $titles{$option}.'</label></span> ';
2142: }
1.101 raeburn 2143: } else {
2144: my $checked = 'checked="checked" ';
2145: if (ref($settings) eq 'HASH') {
2146: if (ref($settings->{$item}) eq 'HASH') {
2147: if ($settings->{$item}->{'default'} == 0) {
2148: $checked = '';
2149: } elsif ($settings->{$item}->{'default'} == 1) {
2150: $checked = 'checked="checked" ';
2151: }
1.78 raeburn 2152: }
1.72 raeburn 2153: }
1.101 raeburn 2154: $datatable .= '<span class="LC_nobreak"><label>'.
2155: '<input type="checkbox" name="'.$context.'_'.$item.
2156: '" value="default" '.$checked.'/>'.$titles{$item}.
2157: '</label></span> ';
2158: }
2159: }
2160: if ($context eq 'requestcourses') {
2161: $datatable .= '</tr><tr>';
2162: foreach my $item (@usertools) {
1.106 raeburn 2163: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2164: }
1.101 raeburn 2165: $datatable .= '</tr></table>';
1.72 raeburn 2166: }
1.86 raeburn 2167: $datatable .= '</td>';
1.163 raeburn 2168: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2169: $datatable .= '<td class="LC_right_item">'.
2170: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2171: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2172: $defaultquota.'" size="5" /></span>'.(' ' x2).
2173: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2174: '<input type="text" name="authorquota" value="'.
2175: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2176: }
2177: $datatable .= '</tr>';
1.72 raeburn 2178: $typecount ++;
2179: $css_class = $typecount%2?' class="LC_odd_row"':'';
2180: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2181: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2182: if ($context eq 'requestcourses') {
1.109 raeburn 2183: $datatable .= &mt('(overrides affiliation, if set)').
2184: '</td>'.
2185: '<td class="LC_left_item">'.
2186: '<table><tr>';
1.101 raeburn 2187: } else {
1.109 raeburn 2188: $datatable .= &mt('(overrides affiliation, if checked)').
2189: '</td>'.
2190: '<td class="LC_left_item" colspan="2">'.
2191: '<br />';
1.101 raeburn 2192: }
2193: my %advcell;
1.72 raeburn 2194: foreach my $item (@usertools) {
1.101 raeburn 2195: if ($context eq 'requestcourses') {
2196: my ($curroption,$currlimit);
2197: if (ref($settings) eq 'HASH') {
2198: if (ref($settings->{$item}) eq 'HASH') {
2199: $curroption = $settings->{$item}->{'_LC_adv'};
2200: if ($curroption =~ /^autolimit=(\d*)$/) {
2201: $currlimit = $1;
2202: }
2203: }
2204: }
2205: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2206: my $checked = '';
2207: if ($curroption eq '') {
2208: $checked = ' checked="checked"';
2209: }
2210: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2211: '<input type="radio" name="crsreq_'.$item.
2212: '__LC_adv" value=""'.$checked.' />'.
2213: &mt('No override set').'</label></span> ';
1.101 raeburn 2214: foreach my $option (@options) {
2215: my $val = $option;
2216: if ($option eq 'norequest') {
2217: $val = 0;
2218: }
2219: if ($option eq 'validate') {
2220: my $canvalidate = 0;
2221: if (ref($validations{$item}) eq 'HASH') {
2222: if ($validations{$item}{'_LC_adv'}) {
2223: $canvalidate = 1;
2224: }
2225: }
2226: next if (!$canvalidate);
2227: }
2228: my $checked = '';
1.104 raeburn 2229: if ($val eq $curroption) {
1.101 raeburn 2230: $checked = ' checked="checked"';
2231: } elsif ($option eq 'autolimit') {
2232: if ($curroption =~ /^autolimit/) {
2233: $checked = ' checked="checked"';
2234: }
2235: }
2236: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2237: '<input type="radio" name="crsreq_'.$item.
2238: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2239: $titles{$option}.'</label>';
2240: if ($option eq 'autolimit') {
1.127 raeburn 2241: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2242: $item.'_limit__LC_adv" size="1" '.
2243: 'value="'.$currlimit.'" />';
2244: }
1.127 raeburn 2245: $advcell{$item} .= '</span> ';
1.104 raeburn 2246: if ($option eq 'autolimit') {
1.127 raeburn 2247: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2248: }
1.101 raeburn 2249: }
1.163 raeburn 2250: } elsif ($context eq 'requestauthor') {
2251: my $curroption;
2252: if (ref($settings) eq 'HASH') {
2253: $curroption = $settings->{'_LC_adv'};
2254: }
2255: my $checked = '';
2256: if ($curroption eq '') {
2257: $checked = ' checked="checked"';
2258: }
2259: $datatable .= '<span class="LC_nobreak"><label>'.
2260: '<input type="radio" name="authorreq__LC_adv"'.
2261: ' value=""'.$checked.' />'.
2262: &mt('No override set').'</label></span> ';
2263: foreach my $option (@options) {
2264: my $val = $option;
2265: if ($option eq 'norequest') {
2266: $val = 0;
2267: }
2268: my $checked = '';
2269: if ($val eq $curroption) {
2270: $checked = ' checked="checked"';
2271: }
2272: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2273: '<input type="radio" name="authorreq__LC_adv"'.
2274: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2275: $titles{$option}.'</label></span> ';
2276: }
1.101 raeburn 2277: } else {
2278: my $checked = 'checked="checked" ';
2279: if (ref($settings) eq 'HASH') {
2280: if (ref($settings->{$item}) eq 'HASH') {
2281: if ($settings->{$item}->{'_LC_adv'} == 0) {
2282: $checked = '';
2283: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2284: $checked = 'checked="checked" ';
2285: }
1.79 raeburn 2286: }
1.72 raeburn 2287: }
1.101 raeburn 2288: $datatable .= '<span class="LC_nobreak"><label>'.
2289: '<input type="checkbox" name="'.$context.'_'.$item.
2290: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2291: '</label></span> ';
2292: }
2293: }
2294: if ($context eq 'requestcourses') {
2295: $datatable .= '</tr><tr>';
2296: foreach my $item (@usertools) {
1.106 raeburn 2297: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2298: }
1.101 raeburn 2299: $datatable .= '</tr></table>';
1.72 raeburn 2300: }
1.98 raeburn 2301: $datatable .= '</td></tr>';
1.30 raeburn 2302: $$rowtotal += $typecount;
1.3 raeburn 2303: return $datatable;
2304: }
2305:
1.163 raeburn 2306: sub print_requestmail {
1.305 raeburn 2307: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2308: my ($now,$datatable,%currapp);
1.102 raeburn 2309: $now = time;
2310: if (ref($settings) eq 'HASH') {
2311: if (ref($settings->{'notify'}) eq 'HASH') {
2312: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2313: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2314: }
2315: }
2316: }
1.191 raeburn 2317: my $numinrow = 2;
1.224 raeburn 2318: my $css_class;
1.305 raeburn 2319: if ($$rowtotal%2) {
2320: $css_class = 'LC_odd_row';
2321: }
2322: if ($customcss) {
2323: $css_class .= " $customcss";
2324: }
2325: $css_class =~ s/^\s+//;
2326: if ($css_class) {
2327: $css_class = ' class="'.$css_class.'"';
2328: }
2329: if ($rowstyle) {
2330: $css_class .= ' style="'.$rowstyle.'"';
2331: }
1.163 raeburn 2332: my $text;
2333: if ($action eq 'requestcourses') {
2334: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2335: } elsif ($action eq 'requestauthor') {
2336: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2337: } else {
1.224 raeburn 2338: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2339: }
1.224 raeburn 2340: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2341: ' <td>'.$text.'</td>'.
1.102 raeburn 2342: ' <td class="LC_left_item">';
1.191 raeburn 2343: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2344: $action.'notifyapproval',%currapp);
1.191 raeburn 2345: if ($numdc > 0) {
2346: $datatable .= $table;
1.102 raeburn 2347: } else {
2348: $datatable .= &mt('There are no active Domain Coordinators');
2349: }
2350: $datatable .='</td></tr>';
2351: return $datatable;
2352: }
2353:
1.216 raeburn 2354: sub print_studentcode {
2355: my ($settings,$rowtotal) = @_;
2356: my $rownum = 0;
1.218 raeburn 2357: my ($output,%current);
1.325 raeburn 2358: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2359: if (ref($settings) eq 'HASH') {
2360: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2361: foreach my $type (@crstypes) {
2362: $current{$type} = $settings->{'uniquecode'}{$type};
2363: }
1.218 raeburn 2364: }
2365: }
2366: $output .= '<tr>'.
2367: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2368: '<td class="LC_left_item">';
2369: foreach my $type (@crstypes) {
2370: my $check = ' ';
2371: if ($current{$type}) {
2372: $check = ' checked="checked" ';
2373: }
2374: $output .= '<span class="LC_nobreak"><label>'.
2375: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2376: &mt($type).'</label></span>'.(' 'x2).' ';
2377: }
2378: $output .= '</td></tr>';
2379: $$rowtotal ++;
2380: return $output;
1.216 raeburn 2381: }
2382:
2383: sub print_textbookcourses {
1.242 raeburn 2384: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2385: my $rownum = 0;
2386: my $css_class;
2387: my $itemcount = 1;
2388: my $maxnum = 0;
2389: my $bookshash;
2390: if (ref($settings) eq 'HASH') {
1.242 raeburn 2391: $bookshash = $settings->{$type};
1.216 raeburn 2392: }
2393: my %ordered;
2394: if (ref($bookshash) eq 'HASH') {
2395: foreach my $item (keys(%{$bookshash})) {
2396: if (ref($bookshash->{$item}) eq 'HASH') {
2397: my $num = $bookshash->{$item}{'order'};
2398: $ordered{$num} = $item;
2399: }
2400: }
2401: }
2402: my $confname = $dom.'-domainconfig';
2403: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2404: my $maxnum = scalar(keys(%ordered));
2405: my $datatable;
1.216 raeburn 2406: if (keys(%ordered)) {
2407: my @items = sort { $a <=> $b } keys(%ordered);
2408: for (my $i=0; $i<@items; $i++) {
2409: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2410: my $key = $ordered{$items[$i]};
2411: my %coursehash=&Apache::lonnet::coursedescription($key);
2412: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2413: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2414: if (ref($bookshash->{$key}) eq 'HASH') {
2415: $subject = $bookshash->{$key}->{'subject'};
2416: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2417: if ($type eq 'textbooks') {
1.243 raeburn 2418: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2419: $author = $bookshash->{$key}->{'author'};
2420: $image = $bookshash->{$key}->{'image'};
2421: if ($image ne '') {
2422: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2423: my $imagethumb = "$path/tn-".$imagefile;
2424: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2425: }
1.216 raeburn 2426: }
2427: }
1.242 raeburn 2428: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2429: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2430: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2431: for (my $k=0; $k<=$maxnum; $k++) {
2432: my $vpos = $k+1;
2433: my $selstr;
2434: if ($k == $i) {
2435: $selstr = ' selected="selected" ';
2436: }
2437: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2438: }
2439: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2440: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2441: &mt('Delete?').'</label></span></td>'.
2442: '<td colspan="2">'.
1.242 raeburn 2443: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2444: (' 'x2).
1.242 raeburn 2445: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2446: if ($type eq 'textbooks') {
2447: $datatable .= (' 'x2).
1.243 raeburn 2448: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2449: (' 'x2).
1.242 raeburn 2450: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2451: (' 'x2).
2452: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2453: if ($image) {
1.267 raeburn 2454: $datatable .= $imgsrc.
1.242 raeburn 2455: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2456: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2457: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2458: }
2459: if ($switchserver) {
2460: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2461: } else {
2462: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2463: }
1.216 raeburn 2464: }
1.242 raeburn 2465: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2466: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2467: $coursetitle.'</span></td></tr>'."\n";
2468: $itemcount ++;
2469: }
2470: }
2471: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2472: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2473: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2474: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2475: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2476: for (my $k=0; $k<$maxnum+1; $k++) {
2477: my $vpos = $k+1;
2478: my $selstr;
2479: if ($k == $maxnum) {
2480: $selstr = ' selected="selected" ';
2481: }
2482: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2483: }
2484: $datatable .= '</select> '."\n".
1.242 raeburn 2485: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.216 raeburn 2486: '<td colspan="2">'.
1.242 raeburn 2487: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2488: (' 'x2).
1.242 raeburn 2489: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2490: (' 'x2);
2491: if ($type eq 'textbooks') {
1.243 raeburn 2492: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2493: (' 'x2).
2494: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2495: (' 'x2).
2496: '<span class="LC_nobreak">'.&mt('Image:').' ';
2497: if ($switchserver) {
2498: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2499: } else {
2500: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2501: }
1.216 raeburn 2502: }
2503: $datatable .= '</span>'."\n".
2504: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2505: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2506: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2507: &Apache::loncommon::selectcourse_link
1.242 raeburn 2508: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.216 raeburn 2509: '</span></td>'."\n".
2510: '</tr>'."\n";
2511: $itemcount ++;
2512: return $datatable;
2513: }
2514:
1.217 raeburn 2515: sub textbookcourses_javascript {
1.242 raeburn 2516: my ($settings) = @_;
2517: return unless(ref($settings) eq 'HASH');
2518: my (%ordered,%total,%jstext);
2519: foreach my $type ('textbooks','templates') {
2520: $total{$type} = 0;
2521: if (ref($settings->{$type}) eq 'HASH') {
2522: foreach my $item (keys(%{$settings->{$type}})) {
2523: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2524: my $num = $settings->{$type}->{$item}{'order'};
2525: $ordered{$type}{$num} = $item;
2526: }
2527: }
2528: $total{$type} = scalar(keys(%{$settings->{$type}}));
2529: }
2530: my @jsarray = ();
2531: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2532: push(@jsarray,$ordered{$type}{$item});
2533: }
2534: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2535: }
2536: return <<"ENDSCRIPT";
2537: <script type="text/javascript">
2538: // <![CDATA[
1.242 raeburn 2539: function reorderBooks(form,item,caller) {
1.217 raeburn 2540: var changedVal;
1.242 raeburn 2541: $jstext{'textbooks'};
2542: $jstext{'templates'};
2543: var newpos;
2544: var maxh;
2545: if (caller == 'textbooks') {
2546: newpos = 'textbooks_addbook_pos';
2547: maxh = 1 + $total{'textbooks'};
2548: } else {
2549: newpos = 'templates_addbook_pos';
2550: maxh = 1 + $total{'templates'};
2551: }
1.217 raeburn 2552: var current = new Array;
2553: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2554: if (item == newpos) {
2555: changedVal = newitemVal;
2556: } else {
2557: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2558: current[newitemVal] = newpos;
2559: }
1.242 raeburn 2560: if (caller == 'textbooks') {
2561: for (var i=0; i<textbooks.length; i++) {
2562: var elementName = 'textbooks_'+textbooks[i];
2563: if (elementName != item) {
2564: if (form.elements[elementName]) {
2565: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2566: current[currVal] = elementName;
2567: }
2568: }
2569: }
2570: }
2571: if (caller == 'templates') {
2572: for (var i=0; i<templates.length; i++) {
2573: var elementName = 'templates_'+templates[i];
2574: if (elementName != item) {
2575: if (form.elements[elementName]) {
2576: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2577: current[currVal] = elementName;
2578: }
1.217 raeburn 2579: }
2580: }
2581: }
2582: var oldVal;
2583: for (var j=0; j<maxh; j++) {
2584: if (current[j] == undefined) {
2585: oldVal = j;
2586: }
2587: }
2588: if (oldVal < changedVal) {
2589: for (var k=oldVal+1; k<=changedVal ; k++) {
2590: var elementName = current[k];
2591: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2592: }
2593: } else {
2594: for (var k=changedVal; k<oldVal; k++) {
2595: var elementName = current[k];
2596: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2597: }
2598: }
2599: return;
2600: }
2601:
2602: // ]]>
2603: </script>
2604:
2605: ENDSCRIPT
2606: }
2607:
1.267 raeburn 2608: sub ltitools_javascript {
2609: my ($settings) = @_;
1.319 raeburn 2610: my $togglejs = <itools_toggle_js();
2611: unless (ref($settings) eq 'HASH') {
2612: return $togglejs;
2613: }
1.267 raeburn 2614: my (%ordered,$total,%jstext);
2615: $total = 0;
2616: foreach my $item (keys(%{$settings})) {
2617: if (ref($settings->{$item}) eq 'HASH') {
2618: my $num = $settings->{$item}{'order'};
2619: $ordered{$num} = $item;
2620: }
2621: }
2622: $total = scalar(keys(%{$settings}));
2623: my @jsarray = ();
2624: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2625: push(@jsarray,$ordered{$item});
2626: }
2627: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2628: return <<"ENDSCRIPT";
2629: <script type="text/javascript">
2630: // <![CDATA[
1.319 raeburn 2631: function reorderLTITools(form,item) {
1.267 raeburn 2632: var changedVal;
2633: $jstext
2634: var newpos = 'ltitools_add_pos';
2635: var maxh = 1 + $total;
2636: var current = new Array;
2637: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2638: if (item == newpos) {
2639: changedVal = newitemVal;
2640: } else {
2641: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2642: current[newitemVal] = newpos;
2643: }
2644: for (var i=0; i<ltitools.length; i++) {
2645: var elementName = 'ltitools_'+ltitools[i];
2646: if (elementName != item) {
2647: if (form.elements[elementName]) {
2648: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2649: current[currVal] = elementName;
2650: }
2651: }
2652: }
2653: var oldVal;
2654: for (var j=0; j<maxh; j++) {
2655: if (current[j] == undefined) {
2656: oldVal = j;
2657: }
2658: }
2659: if (oldVal < changedVal) {
2660: for (var k=oldVal+1; k<=changedVal ; k++) {
2661: var elementName = current[k];
2662: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2663: }
2664: } else {
2665: for (var k=changedVal; k<oldVal; k++) {
2666: var elementName = current[k];
2667: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2668: }
2669: }
2670: return;
2671: }
2672:
2673: // ]]>
2674: </script>
2675:
1.319 raeburn 2676: $togglejs
2677:
2678: ENDSCRIPT
2679: }
2680:
2681: sub ltitools_toggle_js {
2682: return <<"ENDSCRIPT";
2683: <script type="text/javascript">
2684: // <![CDATA[
2685:
2686: function toggleLTITools(form,setting,item) {
2687: var radioname = '';
2688: var divid = '';
2689: if ((setting == 'passback') || (setting == 'roster')) {
2690: radioname = 'ltitools_'+setting+'_'+item;
2691: divid = 'ltitools_'+setting+'time_'+item;
2692: var num = form.elements[radioname].length;
2693: if (num) {
2694: var setvis = '';
2695: for (var i=0; i<num; i++) {
2696: if (form.elements[radioname][i].checked) {
2697: if (form.elements[radioname][i].value == '1') {
2698: if (document.getElementById(divid)) {
2699: document.getElementById(divid).style.display = 'inline-block';
2700: }
2701: setvis = 1;
2702: }
2703: break;
2704: }
2705: }
2706: }
2707: if (!setvis) {
2708: if (document.getElementById(divid)) {
2709: document.getElementById(divid).style.display = 'none';
2710: }
2711: }
2712: }
1.324 raeburn 2713: if (setting == 'user') {
2714: divid = 'ltitools_'+setting+'_div_'+item;
2715: var checkid = 'ltitools_'+setting+'_field_'+item;
2716: if (document.getElementById(divid)) {
2717: if (document.getElementById(checkid)) {
2718: if (document.getElementById(checkid).checked) {
2719: document.getElementById(divid).style.display = 'inline-block';
2720: } else {
2721: document.getElementById(divid).style.display = 'none';
2722: }
2723: }
2724: }
2725: }
1.319 raeburn 2726: return;
2727: }
2728: // ]]>
2729: </script>
2730:
1.267 raeburn 2731: ENDSCRIPT
2732: }
2733:
1.320 raeburn 2734: sub lti_javascript {
2735: my ($settings) = @_;
2736: my $togglejs = <i_toggle_js();
2737: unless (ref($settings) eq 'HASH') {
2738: return $togglejs;
2739: }
2740: my (%ordered,$total,%jstext);
2741: $total = 0;
2742: foreach my $item (keys(%{$settings})) {
2743: if (ref($settings->{$item}) eq 'HASH') {
2744: my $num = $settings->{$item}{'order'};
2745: $ordered{$num} = $item;
2746: }
2747: }
2748: $total = scalar(keys(%{$settings}));
2749: my @jsarray = ();
2750: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2751: push(@jsarray,$ordered{$item});
2752: }
2753: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
2754: return <<"ENDSCRIPT";
2755: <script type="text/javascript">
2756: // <![CDATA[
2757: function reorderLTI(form,item) {
2758: var changedVal;
2759: $jstext
2760: var newpos = 'lti_pos_add';
2761: var maxh = 1 + $total;
2762: var current = new Array;
2763: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2764: if (item == newpos) {
2765: changedVal = newitemVal;
2766: } else {
2767: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2768: current[newitemVal] = newpos;
2769: }
2770: for (var i=0; i<lti.length; i++) {
2771: var elementName = 'lti_pos_'+lti[i];
2772: if (elementName != item) {
2773: if (form.elements[elementName]) {
2774: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2775: current[currVal] = elementName;
2776: }
2777: }
2778: }
2779: var oldVal;
2780: for (var j=0; j<maxh; j++) {
2781: if (current[j] == undefined) {
2782: oldVal = j;
2783: }
2784: }
2785: if (oldVal < changedVal) {
2786: for (var k=oldVal+1; k<=changedVal ; k++) {
2787: var elementName = current[k];
2788: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2789: }
2790: } else {
2791: for (var k=changedVal; k<oldVal; k++) {
2792: var elementName = current[k];
2793: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2794: }
2795: }
2796: return;
2797: }
2798: // ]]>
2799: </script>
2800:
2801: $togglejs
2802:
2803: ENDSCRIPT
2804: }
2805:
2806: sub lti_toggle_js {
1.325 raeburn 2807: my %lcauthparmtext = &Apache::lonlocal::texthash (
2808: localauth => 'Local auth argument',
2809: krb => 'Kerberos domain',
2810: );
1.320 raeburn 2811: return <<"ENDSCRIPT";
2812: <script type="text/javascript">
2813: // <![CDATA[
2814:
2815: function toggleLTI(form,setting,item) {
2816: if ((setting == 'user') || (setting == 'crs')) {
2817: var radioname = '';
2818: var divid = '';
2819: if (setting == 'user') {
2820: radioname = 'lti_mapuser_'+item;
2821: divid = 'lti_userfield_'+item;
2822: } else {
2823: radioname = 'lti_mapcrs_'+item;
2824: divid = 'lti_crsfield_'+item;
2825: }
2826: var num = form.elements[radioname].length;
2827: if (num) {
2828: var setvis = '';
2829: for (var i=0; i<num; i++) {
2830: if (form.elements[radioname][i].checked) {
2831: if (form.elements[radioname][i].value == 'other') {
2832: if (document.getElementById(divid)) {
2833: document.getElementById(divid).style.display = 'inline-block';
2834: }
2835: setvis = 1;
2836: break;
2837: }
2838: }
2839: }
2840: if (!setvis) {
2841: if (document.getElementById(divid)) {
2842: document.getElementById(divid).style.display = 'none';
2843: }
2844: }
2845: }
2846: } else if ((setting == 'sec') || (setting == 'secsrc')) {
2847: var numsec = form.elements['lti_crssec_'+item].length;
2848: if (numsec) {
2849: var setvis = '';
2850: for (var i=0; i<numsec; i++) {
2851: if (form.elements['lti_crssec_'+item][i].checked) {
2852: if (form.elements['lti_crssec_'+item][i].value == '1') {
2853: if (document.getElementById('lti_crssecfield_'+item)) {
2854: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
2855: setvis = 1;
2856: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
2857: if (numsrcsec) {
2858: var setsrcvis = '';
2859: for (var j=0; j<numsrcsec; j++) {
2860: if (form.elements['lti_crssecsrc_'+item][j].checked) {
2861: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
2862: if (document.getElementById('lti_secsrcfield_'+item)) {
2863: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
2864: setsrcvis = 1;
2865: }
2866: }
2867: }
2868: }
2869: if (!setsrcvis) {
2870: if (document.getElementById('lti_secsrcfield_'+item)) {
2871: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
2872: }
2873: }
2874: }
2875: }
2876: }
2877: }
2878: }
2879: if (!setvis) {
2880: if (document.getElementById('lti_crssecfield_'+item)) {
2881: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
2882: }
2883: if (document.getElementById('lti_secsrcfield_'+item)) {
2884: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
2885: }
2886: }
2887: }
1.325 raeburn 2888: } else if (setting == 'lcauth') {
2889: var numauth = form.elements['lti_lcauth_'+item].length;
2890: if (numauth) {
2891: for (var i=0; i<numauth; i++) {
2892: if (form.elements['lti_lcauth_'+item][i].checked) {
2893: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
2894: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
2895: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
2896: } else {
2897: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
2898: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
2899: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
2900: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
2901: } else {
2902: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
2903: }
2904: }
2905: }
2906: }
2907: }
2908: }
2909: }
1.326 raeburn 2910: } else if (setting == 'lcmenu') {
2911: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
2912: var divid = 'lti_menufield_'+item;
2913: var setvis = '';
2914: for (var i=0; i<menus.length; i++) {
2915: var radioname = menus[i];
2916: var num = form.elements[radioname].length;
2917: if (num) {
2918: for (var j=0; j<num; j++) {
2919: if (form.elements[radioname][j].checked) {
2920: if (form.elements[radioname][j].value == '1') {
2921: if (document.getElementById(divid)) {
2922: document.getElementById(divid).style.display = 'inline-block';
2923: }
2924: setvis = 1;
2925: break;
2926: }
2927: }
2928: }
2929: }
2930: if (setvis == 1) {
2931: break;
2932: }
2933: }
2934: if (!setvis) {
2935: if (document.getElementById(divid)) {
2936: document.getElementById(divid).style.display = 'none';
2937: }
2938: }
1.320 raeburn 2939: }
2940: return;
2941: }
2942: // ]]>
2943: </script>
2944:
2945: ENDSCRIPT
2946: }
2947:
1.3 raeburn 2948: sub print_autoenroll {
1.30 raeburn 2949: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2950: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274 raeburn 2951: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2952: if (ref($settings) eq 'HASH') {
2953: if (exists($settings->{'run'})) {
2954: if ($settings->{'run'} eq '0') {
2955: $runoff = ' checked="checked" ';
2956: $runon = ' ';
2957: } else {
2958: $runon = ' checked="checked" ';
2959: $runoff = ' ';
2960: }
2961: } else {
2962: if ($autorun) {
2963: $runon = ' checked="checked" ';
2964: $runoff = ' ';
2965: } else {
2966: $runoff = ' checked="checked" ';
2967: $runon = ' ';
2968: }
2969: }
1.129 raeburn 2970: if (exists($settings->{'co-owners'})) {
2971: if ($settings->{'co-owners'} eq '0') {
2972: $coownersoff = ' checked="checked" ';
2973: $coownerson = ' ';
2974: } else {
2975: $coownerson = ' checked="checked" ';
2976: $coownersoff = ' ';
2977: }
2978: } else {
2979: $coownersoff = ' checked="checked" ';
2980: $coownerson = ' ';
2981: }
1.3 raeburn 2982: if (exists($settings->{'sender_domain'})) {
2983: $defdom = $settings->{'sender_domain'};
2984: }
1.274 raeburn 2985: if (exists($settings->{'autofailsafe'})) {
2986: $failsafe = $settings->{'autofailsafe'};
2987: }
1.14 raeburn 2988: } else {
2989: if ($autorun) {
2990: $runon = ' checked="checked" ';
2991: $runoff = ' ';
2992: } else {
2993: $runoff = ' checked="checked" ';
2994: $runon = ' ';
2995: }
1.3 raeburn 2996: }
2997: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2998: my $notif_sender;
2999: if (ref($settings) eq 'HASH') {
3000: $notif_sender = $settings->{'sender_uname'};
3001: }
1.3 raeburn 3002: my $datatable='<tr class="LC_odd_row">'.
3003: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 3004: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3005: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 3006: $runon.' value="1" />'.&mt('Yes').'</label> '.
3007: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 3008: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3009: '</tr><tr>'.
3010: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 3011: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 3012: &mt('username').': '.
3013: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 3014: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 3015: ': '.$domform.'</span></td></tr>'.
3016: '<tr class="LC_odd_row">'.
3017: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3018: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3019: '<input type="radio" name="autoassign_coowners"'.
3020: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3021: '<label><input type="radio" name="autoassign_coowners"'.
3022: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 3023: '</tr><tr>'.
3024: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
3025: '<td class="LC_right_item"><span class="LC_nobreak">'.
3026: '<input type="text" name="autoenroll_failsafe"'.
3027: ' value="'.$failsafe.'" size="4" /></td></tr>';
3028: $$rowtotal += 4;
1.3 raeburn 3029: return $datatable;
3030: }
3031:
3032: sub print_autoupdate {
1.30 raeburn 3033: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 3034: my $datatable;
3035: if ($position eq 'top') {
3036: my $updateon = ' ';
3037: my $updateoff = ' checked="checked" ';
3038: my $classlistson = ' ';
3039: my $classlistsoff = ' checked="checked" ';
3040: if (ref($settings) eq 'HASH') {
3041: if ($settings->{'run'} eq '1') {
3042: $updateon = $updateoff;
3043: $updateoff = ' ';
3044: }
3045: if ($settings->{'classlists'} eq '1') {
3046: $classlistson = $classlistsoff;
3047: $classlistsoff = ' ';
3048: }
3049: }
3050: my %title = (
3051: run => 'Auto-update active?',
3052: classlists => 'Update information in classlists?',
3053: );
3054: $datatable = '<tr class="LC_odd_row">'.
3055: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 3056: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3057: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 3058: $updateon.' value="1" />'.&mt('Yes').'</label> '.
3059: '<label><input type="radio" name="autoupdate_run"'.
3060: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3061: '</tr><tr>'.
3062: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 3063: '<td class="LC_right_item"><span class="LC_nobreak">'.
3064: '<label><input type="radio" name="classlists"'.
3065: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
3066: '<label><input type="radio" name="classlists"'.
3067: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3068: '</tr>';
1.30 raeburn 3069: $$rowtotal += 2;
1.131 raeburn 3070: } elsif ($position eq 'middle') {
3071: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3072: my $numinrow = 3;
3073: my $locknamesettings;
3074: $datatable .= &insttypes_row($settings,$types,$usertypes,
3075: $dom,$numinrow,$othertitle,
1.305 raeburn 3076: 'lockablenames',$rowtotal);
1.131 raeburn 3077: $$rowtotal ++;
1.3 raeburn 3078: } else {
1.44 raeburn 3079: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3080: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3081: 'permanentemail','id');
1.33 raeburn 3082: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3083: my $numrows = 0;
1.26 raeburn 3084: if (ref($types) eq 'ARRAY') {
3085: if (@{$types} > 0) {
3086: $datatable =
3087: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3088: \@fields,$types,\$numrows);
1.30 raeburn 3089: $$rowtotal += @{$types};
1.26 raeburn 3090: }
1.3 raeburn 3091: }
3092: $datatable .=
3093: &usertype_update_row($settings,{'default' => $othertitle},
3094: \%fieldtitles,\@fields,['default'],
3095: \$numrows);
1.30 raeburn 3096: $$rowtotal ++;
1.3 raeburn 3097: }
3098: return $datatable;
3099: }
3100:
1.125 raeburn 3101: sub print_autocreate {
3102: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 3103: my (%createon,%createoff,%currhash);
1.125 raeburn 3104: my @types = ('xml','req');
3105: if (ref($settings) eq 'HASH') {
3106: foreach my $item (@types) {
3107: $createoff{$item} = ' checked="checked" ';
3108: $createon{$item} = ' ';
3109: if (exists($settings->{$item})) {
3110: if ($settings->{$item}) {
3111: $createon{$item} = ' checked="checked" ';
3112: $createoff{$item} = ' ';
3113: }
3114: }
3115: }
1.210 raeburn 3116: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 3117: $currhash{$settings->{'xmldc'}} = 1;
3118: }
1.125 raeburn 3119: } else {
3120: foreach my $item (@types) {
3121: $createoff{$item} = ' checked="checked" ';
3122: $createon{$item} = ' ';
3123: }
3124: }
3125: $$rowtotal += 2;
1.191 raeburn 3126: my $numinrow = 2;
1.125 raeburn 3127: my $datatable='<tr class="LC_odd_row">'.
3128: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3129: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3130: '<input type="radio" name="autocreate_xml"'.
3131: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3132: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 3133: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3134: '</td></tr><tr>'.
3135: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3136: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3137: '<input type="radio" name="autocreate_req"'.
3138: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3139: '<label><input type="radio" name="autocreate_req"'.
3140: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 3141: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3142: 'autocreate_xmldc',%currhash);
1.247 raeburn 3143: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 3144: if ($numdc > 1) {
1.247 raeburn 3145: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
3146: '</td><td class="LC_left_item">';
1.125 raeburn 3147: } else {
1.247 raeburn 3148: $datatable .= &mt('Course creation processed as:').
3149: '</td><td class="LC_right_item">';
1.125 raeburn 3150: }
1.247 raeburn 3151: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 3152: $$rowtotal += $rows;
1.125 raeburn 3153: return $datatable;
3154: }
3155:
1.23 raeburn 3156: sub print_directorysrch {
1.277 raeburn 3157: my ($position,$dom,$settings,$rowtotal) = @_;
3158: my $datatable;
3159: if ($position eq 'top') {
3160: my $instsrchon = ' ';
3161: my $instsrchoff = ' checked="checked" ';
3162: my ($exacton,$containson,$beginson);
3163: my $instlocalon = ' ';
3164: my $instlocaloff = ' checked="checked" ';
3165: if (ref($settings) eq 'HASH') {
3166: if ($settings->{'available'} eq '1') {
3167: $instsrchon = $instsrchoff;
3168: $instsrchoff = ' ';
3169: }
3170: if ($settings->{'localonly'} eq '1') {
3171: $instlocalon = $instlocaloff;
3172: $instlocaloff = ' ';
3173: }
3174: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
3175: foreach my $type (@{$settings->{'searchtypes'}}) {
3176: if ($type eq 'exact') {
3177: $exacton = ' checked="checked" ';
3178: } elsif ($type eq 'contains') {
3179: $containson = ' checked="checked" ';
3180: } elsif ($type eq 'begins') {
3181: $beginson = ' checked="checked" ';
3182: }
3183: }
3184: } else {
3185: if ($settings->{'searchtypes'} eq 'exact') {
3186: $exacton = ' checked="checked" ';
3187: } elsif ($settings->{'searchtypes'} eq 'contains') {
3188: $containson = ' checked="checked" ';
3189: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 3190: $exacton = ' checked="checked" ';
3191: $containson = ' checked="checked" ';
3192: }
3193: }
1.277 raeburn 3194: }
3195: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3196: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3197:
3198: my $numinrow = 4;
3199: my $cansrchrow = 0;
3200: $datatable='<tr class="LC_odd_row">'.
3201: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
3202: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3203: '<input type="radio" name="dirsrch_available"'.
3204: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
3205: '<label><input type="radio" name="dirsrch_available"'.
3206: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3207: '</tr><tr>'.
3208: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
3209: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3210: '<input type="radio" name="dirsrch_instlocalonly"'.
3211: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3212: '<label><input type="radio" name="dirsrch_instlocalonly"'.
3213: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3214: '</tr>';
3215: $$rowtotal += 2;
3216: if (ref($usertypes) eq 'HASH') {
3217: if (keys(%{$usertypes}) > 0) {
3218: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 3219: $numinrow,$othertitle,'cansearch',
3220: $rowtotal);
1.277 raeburn 3221: $cansrchrow = 1;
1.25 raeburn 3222: }
1.23 raeburn 3223: }
1.277 raeburn 3224: if ($cansrchrow) {
3225: $$rowtotal ++;
3226: $datatable .= '<tr>';
3227: } else {
3228: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 3229: }
1.277 raeburn 3230: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
3231: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
3232: foreach my $title (@{$titleorder}) {
3233: if (defined($searchtitles->{$title})) {
3234: my $check = ' ';
3235: if (ref($settings) eq 'HASH') {
3236: if (ref($settings->{'searchby'}) eq 'ARRAY') {
3237: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
3238: $check = ' checked="checked" ';
3239: }
1.39 raeburn 3240: }
1.25 raeburn 3241: }
1.277 raeburn 3242: $datatable .= '<td class="LC_left_item">'.
3243: '<span class="LC_nobreak"><label>'.
3244: '<input type="checkbox" name="searchby" '.
3245: 'value="'.$title.'"'.$check.'/>'.
3246: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 3247: }
3248: }
1.277 raeburn 3249: $datatable .= '</tr></table></td></tr>';
3250: $$rowtotal ++;
3251: if ($cansrchrow) {
3252: $datatable .= '<tr class="LC_odd_row">';
3253: } else {
3254: $datatable .= '<tr>';
3255: }
3256: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
3257: '<td class="LC_left_item" colspan="2">'.
3258: '<span class="LC_nobreak"><label>'.
3259: '<input type="checkbox" name="searchtypes" '.
3260: $exacton.' value="exact" />'.&mt('Exact match').
3261: '</label> '.
3262: '<label><input type="checkbox" name="searchtypes" '.
3263: $beginson.' value="begins" />'.&mt('Begins with').
3264: '</label> '.
3265: '<label><input type="checkbox" name="searchtypes" '.
3266: $containson.' value="contains" />'.&mt('Contains').
3267: '</label></span></td></tr>';
3268: $$rowtotal ++;
1.26 raeburn 3269: } else {
1.277 raeburn 3270: my $domsrchon = ' checked="checked" ';
3271: my $domsrchoff = ' ';
3272: my $domlocalon = ' ';
3273: my $domlocaloff = ' checked="checked" ';
3274: if (ref($settings) eq 'HASH') {
3275: if ($settings->{'lclocalonly'} eq '1') {
3276: $domlocalon = $domlocaloff;
3277: $domlocaloff = ' ';
3278: }
3279: if ($settings->{'lcavailable'} eq '0') {
3280: $domsrchoff = $domsrchon;
3281: $domsrchon = ' ';
3282: }
3283: }
3284: $datatable='<tr class="LC_odd_row">'.
3285: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
3286: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3287: '<input type="radio" name="dirsrch_domavailable"'.
3288: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
3289: '<label><input type="radio" name="dirsrch_domavailable"'.
3290: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3291: '</tr><tr>'.
3292: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
3293: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3294: '<input type="radio" name="dirsrch_domlocalonly"'.
3295: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3296: '<label><input type="radio" name="dirsrch_domlocalonly"'.
3297: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3298: '</tr>';
3299: $$rowtotal += 2;
1.26 raeburn 3300: }
1.25 raeburn 3301: return $datatable;
3302: }
3303:
1.28 raeburn 3304: sub print_contacts {
1.286 raeburn 3305: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 3306: my $datatable;
3307: my @contacts = ('adminemail','supportemail');
1.286 raeburn 3308: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
3309: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings);
3310: if ($position eq 'top') {
3311: if (ref($settings) eq 'HASH') {
3312: foreach my $item (@contacts) {
3313: if (exists($settings->{$item})) {
3314: $to{$item} = $settings->{$item};
3315: }
3316: }
3317: }
3318: } elsif ($position eq 'middle') {
3319: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
3320: 'updatesmail','idconflictsmail');
1.288 raeburn 3321: foreach my $type (@mailings) {
3322: $otheremails{$type} = '';
3323: }
1.286 raeburn 3324: } else {
3325: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 3326: foreach my $type (@mailings) {
3327: $otheremails{$type} = '';
3328: }
1.286 raeburn 3329: $bccemails{'helpdeskmail'} = '';
3330: $bccemails{'otherdomsmail'} = '';
3331: $includestr{'helpdeskmail'} = '';
3332: $includestr{'otherdomsmail'} = '';
3333: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3334: }
1.28 raeburn 3335: if (ref($settings) eq 'HASH') {
1.286 raeburn 3336: unless ($position eq 'top') {
3337: foreach my $type (@mailings) {
3338: if (exists($settings->{$type})) {
3339: if (ref($settings->{$type}) eq 'HASH') {
3340: foreach my $item (@contacts) {
3341: if ($settings->{$type}{$item}) {
3342: $checked{$type}{$item} = ' checked="checked" ';
3343: }
3344: }
3345: $otheremails{$type} = $settings->{$type}{'others'};
3346: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3347: $bccemails{$type} = $settings->{$type}{'bcc'};
3348: if ($settings->{$type}{'include'} ne '') {
3349: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3350: $includestr{$type} = &unescape($includestr{$type});
3351: }
3352: }
3353: }
3354: } elsif ($type eq 'lonstatusmail') {
3355: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3356: }
1.28 raeburn 3357: }
3358: }
1.286 raeburn 3359: if ($position eq 'bottom') {
3360: foreach my $type (@mailings) {
3361: $bccemails{$type} = $settings->{$type}{'bcc'};
3362: if ($settings->{$type}{'include'} ne '') {
3363: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3364: $includestr{$type} = &unescape($includestr{$type});
3365: }
3366: }
3367: if (ref($settings->{'helpform'}) eq 'HASH') {
3368: if (ref($fields) eq 'ARRAY') {
3369: foreach my $field (@{$fields}) {
3370: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3371: }
1.286 raeburn 3372: }
3373: if (exists($settings->{'helpform'}{'maxsize'})) {
3374: $maxsize = $settings->{'helpform'}{'maxsize'};
3375: } else {
1.289 raeburn 3376: $maxsize = '1.0';
1.286 raeburn 3377: }
3378: } else {
3379: if (ref($fields) eq 'ARRAY') {
3380: foreach my $field (@{$fields}) {
3381: $currfield{$field} = 'yes';
1.134 raeburn 3382: }
1.28 raeburn 3383: }
1.286 raeburn 3384: $maxsize = '1.0';
1.28 raeburn 3385: }
3386: }
3387: } else {
1.286 raeburn 3388: if ($position eq 'top') {
3389: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3390: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3391: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3392: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 3393: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 3394: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3395: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3396: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
3397: } elsif ($position eq 'bottom') {
3398: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3399: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3400: if (ref($fields) eq 'ARRAY') {
3401: foreach my $field (@{$fields}) {
3402: $currfield{$field} = 'yes';
3403: }
3404: }
3405: $maxsize = '1.0';
3406: }
1.28 raeburn 3407: }
3408: my ($titles,$short_titles) = &contact_titles();
3409: my $rownum = 0;
3410: my $css_class;
1.286 raeburn 3411: if ($position eq 'top') {
3412: foreach my $item (@contacts) {
3413: $css_class = $rownum%2?' class="LC_odd_row"':'';
3414: $datatable .= '<tr'.$css_class.'>'.
3415: '<td><span class="LC_nobreak">'.$titles->{$item}.
3416: '</span></td><td class="LC_right_item">'.
3417: '<input type="text" name="'.$item.'" value="'.
3418: $to{$item}.'" /></td></tr>';
3419: $rownum ++;
3420: }
1.315 raeburn 3421: } elsif ($position eq 'bottom') {
3422: $css_class = $rownum%2?' class="LC_odd_row"':'';
3423: $datatable .= '<tr'.$css_class.'>'.
3424: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3425: &mt('(e-mail, subject, and description always shown)').
3426: '</td><td class="LC_left_item">';
3427: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3428: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3429: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3430: foreach my $field (@{$fields}) {
3431: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3432: if (($field eq 'screenshot') || ($field eq 'cc')) {
3433: $datatable .= ' '.&mt('(logged-in users)');
3434: }
3435: $datatable .='</td><td>';
3436: my $clickaction;
3437: if ($field eq 'screenshot') {
3438: $clickaction = ' onclick="screenshotSize(this);"';
3439: }
3440: if (ref($possoptions->{$field}) eq 'ARRAY') {
3441: foreach my $option (@{$possoptions->{$field}}) {
3442: my $checked;
3443: if ($currfield{$field} eq $option) {
3444: $checked = ' checked="checked"';
3445: }
3446: $datatable .= '<span class="LC_nobreak"><label>'.
3447: '<input type="radio" name="helpform_'.$field.'" '.
3448: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3449: '</label></span>'.(' 'x2);
3450: }
3451: }
3452: if ($field eq 'screenshot') {
3453: my $display;
3454: if ($currfield{$field} eq 'no') {
3455: $display = ' style="display:none"';
3456: }
3457: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.' />'.
3458: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3459: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3460: }
3461: $datatable .= '</td></tr>';
3462: }
3463: $datatable .= '</table>';
3464: }
3465: $datatable .= '</td></tr>'."\n";
3466: $rownum ++;
3467: }
3468: unless ($position eq 'top') {
1.286 raeburn 3469: foreach my $type (@mailings) {
3470: $css_class = $rownum%2?' class="LC_odd_row"':'';
3471: $datatable .= '<tr'.$css_class.'>'.
3472: '<td><span class="LC_nobreak">'.
3473: $titles->{$type}.': </span></td>'.
3474: '<td class="LC_left_item">';
3475: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3476: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3477: }
3478: $datatable .= '<span class="LC_nobreak">';
3479: foreach my $item (@contacts) {
3480: $datatable .= '<label>'.
3481: '<input type="checkbox" name="'.$type.'"'.
3482: $checked{$type}{$item}.
3483: ' value="'.$item.'" />'.$short_titles->{$item}.
3484: '</label> ';
3485: }
3486: $datatable .= '</span><br />'.&mt('Others').': '.
3487: '<input type="text" name="'.$type.'_others" '.
3488: 'value="'.$otheremails{$type}.'" />';
3489: my %locchecked;
3490: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3491: foreach my $loc ('s','b') {
3492: if ($includeloc{$type} eq $loc) {
3493: $locchecked{$loc} = ' checked="checked"';
3494: last;
3495: }
3496: }
3497: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3498: '<input type="text" name="'.$type.'_bcc" '.
3499: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3500: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3501: &mt('Text automatically added to e-mail:').' '.
3502: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br >'.
3503: '<span class="LC_nobreak">'.&mt('Location:').' '.
3504: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3505: (' 'x2).
3506: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3507: '</span></fieldset>';
3508: }
3509: $datatable .= '</td></tr>'."\n";
3510: $rownum ++;
3511: }
1.28 raeburn 3512: }
1.286 raeburn 3513: if ($position eq 'middle') {
3514: my %choices;
3515: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
1.289 raeburn 3516: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3517: &mt('LON-CAPA core group - MSU'),600,500));
1.286 raeburn 3518: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
3519: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3520: &mt('LON-CAPA core group - MSU'),600,500));
3521: my @toggles = ('reporterrors','reportupdates');
3522: my %defaultchecked = ('reporterrors' => 'on',
3523: 'reportupdates' => 'on');
3524: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3525: \%choices,$rownum);
3526: $datatable .= $reports;
3527: } elsif ($position eq 'bottom') {
1.315 raeburn 3528: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3529: my (@posstypes,%usertypeshash);
3530: if (ref($types) eq 'ARRAY') {
3531: @posstypes = @{$types};
3532: }
3533: if (@posstypes) {
3534: if (ref($usertypes) eq 'HASH') {
3535: %usertypeshash = %{$usertypes};
3536: }
3537: my @overridden;
3538: my $numinrow = 4;
3539: if (ref($settings) eq 'HASH') {
3540: if (ref($settings->{'overrides'}) eq 'HASH') {
3541: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
3542: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
3543: push(@overridden,$key);
3544: foreach my $item (@contacts) {
3545: if ($settings->{'overrides'}{$key}{$item}) {
3546: $checked{'override_'.$key}{$item} = ' checked="checked" ';
3547: }
3548: }
3549: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
3550: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
3551: $includeloc{'override_'.$key} = '';
3552: $includestr{'override_'.$key} = '';
3553: if ($settings->{'overrides'}{$key}{'include'} ne '') {
3554: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
3555: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
3556: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
3557: }
1.286 raeburn 3558: }
3559: }
3560: }
1.315 raeburn 3561: }
3562: my $customclass = 'LC_helpdesk_override';
3563: my $optionsprefix = 'LC_options_helpdesk_';
3564:
3565: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
3566:
3567: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
3568: $numinrow,$othertitle,'overrides',
3569: \$rownum,$onclicktypes,$customclass);
3570: $rownum ++;
3571: $usertypeshash{'default'} = $othertitle;
3572: foreach my $status (@posstypes) {
3573: my $css_class;
3574: if ($rownum%2) {
3575: $css_class = 'LC_odd_row ';
3576: }
3577: $css_class .= $customclass;
3578: my $rowid = $optionsprefix.$status;
3579: my $hidden = 1;
3580: my $currstyle = 'display:none';
3581: if (grep(/^\Q$status\E$/,@overridden)) {
3582: $currstyle = 'display:table-row';
3583: $hidden = 0;
3584: }
3585: my $key = 'override_'.$status;
3586: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
3587: $includeloc{$key},$includestr{$key},$status,$rowid,
3588: $usertypeshash{$status},$css_class,$currstyle,
3589: \@contacts,$short_titles);
3590: unless ($hidden) {
3591: $rownum ++;
1.286 raeburn 3592: }
3593: }
1.134 raeburn 3594: }
1.28 raeburn 3595: }
1.30 raeburn 3596: $$rowtotal += $rownum;
1.28 raeburn 3597: return $datatable;
3598: }
3599:
1.315 raeburn 3600: sub overridden_helpdesk {
3601: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
3602: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
3603: my $class = 'LC_left_item';
3604: if ($css_class) {
3605: $css_class = ' class="'.$css_class.'"';
3606: }
3607: if ($rowid) {
3608: $rowid = ' id="'.$rowid.'"';
3609: }
3610: if ($rowstyle) {
3611: $rowstyle = ' style="'.$rowstyle.'"';
3612: }
3613: my ($output,$description);
3614: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
3615: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
3616: "<td>$description</td>\n".
3617: '<td class="'.$class.'" colspan="2">'.
3618: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
3619: '<span class="LC_nobreak">';
3620: if (ref($contacts) eq 'ARRAY') {
3621: foreach my $item (@{$contacts}) {
3622: my $check;
3623: if (ref($checked) eq 'HASH') {
3624: $check = $checked->{$item};
3625: }
3626: my $title;
3627: if (ref($short_titles) eq 'HASH') {
3628: $title = $short_titles->{$item};
3629: }
3630: $output .= '<label>'.
3631: '<input type="checkbox" name="override_'.$type.'"'.$check.
3632: ' value="'.$item.'" />'.$title.'</label> ';
3633: }
3634: }
3635: $output .= '</span><br />'.&mt('Others').': '.
3636: '<input type="text" name="override_'.$type.'_others" '.
3637: 'value="'.$otheremails.'" />';
3638: my %locchecked;
3639: foreach my $loc ('s','b') {
3640: if ($includeloc eq $loc) {
3641: $locchecked{$loc} = ' checked="checked"';
3642: last;
3643: }
3644: }
3645: $output .= '<br />'.&mt('Bcc:').(' 'x6).
3646: '<input type="text" name="override_'.$type.'_bcc" '.
3647: 'value="'.$bccemails.'" /></fieldset>'.
3648: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3649: &mt('Text automatically added to e-mail:').' '.
3650: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br >'.
3651: '<span class="LC_nobreak">'.&mt('Location:').' '.
3652: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3653: (' 'x2).
3654: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3655: '</span></fieldset>'.
3656: '</td></tr>'."\n";
3657: return $output;
3658: }
3659:
1.286 raeburn 3660: sub contacts_javascript {
3661: return <<"ENDSCRIPT";
3662:
3663: <script type="text/javascript">
3664: // <![CDATA[
3665:
3666: function screenshotSize(field) {
3667: if (document.getElementById('help_screenshotsize')) {
3668: if (field.value == 'no') {
1.289 raeburn 3669: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 3670: } else {
3671: document.getElementById('help_screenshotsize').style.display="";
3672: }
3673: }
3674: return;
3675: }
3676:
1.315 raeburn 3677: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
3678: if (form.elements[checkbox].length != undefined) {
3679: var count = 0;
3680: if (docount) {
3681: for (var i=0; i<form.elements[checkbox].length; i++) {
3682: if (form.elements[checkbox][i].checked) {
3683: count ++;
3684: }
3685: }
3686: }
3687: for (var i=0; i<form.elements[checkbox].length; i++) {
3688: var type = form.elements[checkbox][i].value;
3689: if (document.getElementById(prefix+type)) {
3690: if (form.elements[checkbox][i].checked) {
3691: document.getElementById(prefix+type).style.display = 'table-row';
3692: if (count % 2 == 1) {
3693: document.getElementById(prefix+type).className = target+' LC_odd_row';
3694: } else {
3695: document.getElementById(prefix+type).className = target;
3696: }
3697: count ++;
3698: } else {
3699: document.getElementById(prefix+type).style.display = 'none';
3700: }
3701: }
3702: }
3703: }
3704: return;
3705: }
3706:
3707:
1.286 raeburn 3708: // ]]>
3709: </script>
3710:
3711: ENDSCRIPT
3712: }
3713:
1.118 jms 3714: sub print_helpsettings {
1.282 raeburn 3715: my ($position,$dom,$settings,$rowtotal) = @_;
3716: my $confname = $dom.'-domainconfig';
1.285 raeburn 3717: my $formname = 'display';
1.168 raeburn 3718: my ($datatable,$itemcount);
1.282 raeburn 3719: if ($position eq 'top') {
3720: $itemcount = 1;
3721: my (%choices,%defaultchecked,@toggles);
3722: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3723: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3724: &mt('LON-CAPA bug tracker'),600,500));
3725: %defaultchecked = ('submitbugs' => 'on');
3726: @toggles = ('submitbugs');
3727: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3728: \%choices,$itemcount);
3729: $$rowtotal ++;
3730: } else {
3731: my $css_class;
3732: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 3733: my (%customroles,%ordered,%current);
1.301 raeburn 3734: if (ref($settings) eq 'HASH') {
3735: if (ref($settings->{'adhoc'}) eq 'HASH') {
3736: %current = %{$settings->{'adhoc'}};
3737: }
1.285 raeburn 3738: }
3739: my $count = 0;
3740: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 3741: if ($key=~/^rolesdef\_(\w+)$/) {
3742: my $rolename = $1;
1.285 raeburn 3743: my (%privs,$order);
1.282 raeburn 3744: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3745: $customroles{$rolename} = \%privs;
1.285 raeburn 3746: if (ref($current{$rolename}) eq 'HASH') {
3747: $order = $current{$rolename}{'order'};
3748: }
3749: if ($order eq '') {
3750: $order = $count;
3751: }
3752: $ordered{$order} = $rolename;
3753: $count++;
3754: }
3755: }
3756: my $maxnum = scalar(keys(%ordered));
3757: my @roles_by_num = ();
3758: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3759: push(@roles_by_num,$item);
3760: }
3761: my $context = 'domprefs';
3762: my $crstype = 'Course';
3763: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 3764: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 3765: my ($numstatustypes,@jsarray);
3766: if (ref($types) eq 'ARRAY') {
3767: if (@{$types} > 0) {
3768: $numstatustypes = scalar(@{$types});
3769: push(@accesstypes,'status');
3770: @jsarray = ('bystatus');
1.282 raeburn 3771: }
3772: }
1.290 raeburn 3773: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 3774: if (keys(%domhelpdesk)) {
3775: push(@accesstypes,('inc','exc'));
3776: push(@jsarray,('notinc','notexc'));
3777: }
3778: my $hiddenstr = join("','",@jsarray);
3779: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.282 raeburn 3780: my $context = 'domprefs';
3781: my $crstype = 'Course';
1.285 raeburn 3782: my $prefix = 'helproles_';
3783: my $add_class = 'LC_hidden';
3784: foreach my $num (@roles_by_num) {
3785: my $role = $ordered{$num};
3786: my ($desc,$access,@statuses);
3787: if (ref($current{$role}) eq 'HASH') {
3788: $desc = $current{$role}{'desc'};
3789: $access = $current{$role}{'access'};
3790: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3791: @statuses = @{$current{$role}{'insttypes'}};
3792: }
3793: }
3794: if ($desc eq '') {
3795: $desc = $role;
3796: }
3797: my $identifier = 'custhelp'.$num;
1.282 raeburn 3798: my %full=();
3799: my %levels= (
3800: course => {},
3801: domain => {},
3802: system => {},
3803: );
3804: my %levelscurrent=(
3805: course => {},
3806: domain => {},
3807: system => {},
3808: );
3809: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3810: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3811: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 3812: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 3813: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 3814: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3815: for (my $k=0; $k<=$maxnum; $k++) {
3816: my $vpos = $k+1;
3817: my $selstr;
3818: if ($k == $num) {
3819: $selstr = ' selected="selected" ';
3820: }
3821: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3822: }
3823: $datatable .= '</select>'.(' 'x2).
3824: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3825: '</td>'.
3826: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3827: &mt('Name shown to users:').
3828: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3829: '</fieldset>'.
3830: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3831: $othertitle,$usertypes,$types,\%domhelpdesk).
3832: '<fieldset>'.
3833: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 3834: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 3835: \%levelscurrent,$identifier,
3836: 'LC_hidden',$prefix.$num.'_privs').
3837: '</fieldset></td>';
1.282 raeburn 3838: $itemcount ++;
3839: }
3840: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3841: my $newcust = 'custhelp'.$count;
3842: my (%privs,%levelscurrent);
3843: my %full=();
3844: my %levels= (
3845: course => {},
3846: domain => {},
3847: system => {},
3848: );
3849: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3850: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 3851: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 3852: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 3853: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3854: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3855: for (my $k=0; $k<$maxnum+1; $k++) {
3856: my $vpos = $k+1;
3857: my $selstr;
3858: if ($k == $maxnum) {
3859: $selstr = ' selected="selected" ';
3860: }
3861: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3862: }
3863: $datatable .= '</select> '."\n".
1.282 raeburn 3864: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3865: '</label></span></td>'.
1.285 raeburn 3866: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3867: '<span class="LC_nobreak">'.
3868: &mt('Internal name:').
3869: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3870: '</span>'.(' 'x4).
3871: '<span class="LC_nobreak">'.
3872: &mt('Name shown to users:').
3873: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3874: '</span></fieldset>'.
3875: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3876: $usertypes,$types,\%domhelpdesk).
3877: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 3878: &Apache::lonuserutils::custom_role_header($context,$crstype,
3879: \@templateroles,$newcust).
3880: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3881: \%levelscurrent,$newcust).
1.285 raeburn 3882: '</fieldset></td></tr>';
1.282 raeburn 3883: $count ++;
3884: $$rowtotal += $count;
3885: }
1.166 raeburn 3886: return $datatable;
1.121 raeburn 3887: }
3888:
1.285 raeburn 3889: sub adhocbutton {
3890: my ($prefix,$num,$field,$visibility) = @_;
3891: my %lt = &Apache::lonlocal::texthash(
3892: show => 'Show details',
3893: hide => 'Hide details',
3894: );
3895: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3896: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3897: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3898: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3899: }
3900:
3901: sub helpsettings_javascript {
3902: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3903: return unless(ref($roles_by_num) eq 'ARRAY');
3904: my %html_js_lt = &Apache::lonlocal::texthash(
3905: show => 'Show details',
3906: hide => 'Hide details',
3907: );
3908: &html_escape(\%html_js_lt);
3909: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3910: return <<"ENDSCRIPT";
3911: <script type="text/javascript">
3912: // <![CDATA[
3913:
3914: function reorderHelpRoles(form,item) {
3915: var changedVal;
3916: $jstext
3917: var newpos = 'helproles_${total}_pos';
3918: var maxh = 1 + $total;
3919: var current = new Array();
3920: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3921: if (item == newpos) {
3922: changedVal = newitemVal;
3923: } else {
3924: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3925: current[newitemVal] = newpos;
3926: }
3927: for (var i=0; i<helproles.length; i++) {
3928: var elementName = 'helproles_'+helproles[i]+'_pos';
3929: if (elementName != item) {
3930: if (form.elements[elementName]) {
3931: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3932: current[currVal] = elementName;
3933: }
3934: }
3935: }
3936: var oldVal;
3937: for (var j=0; j<maxh; j++) {
3938: if (current[j] == undefined) {
3939: oldVal = j;
3940: }
3941: }
3942: if (oldVal < changedVal) {
3943: for (var k=oldVal+1; k<=changedVal ; k++) {
3944: var elementName = current[k];
3945: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3946: }
3947: } else {
3948: for (var k=changedVal; k<oldVal; k++) {
3949: var elementName = current[k];
3950: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3951: }
3952: }
3953: return;
3954: }
3955:
3956: function helpdeskAccess(num) {
3957: var curraccess = null;
3958: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3959: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3960: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3961: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3962: }
3963: }
3964: }
3965: var shown = Array();
3966: var hidden = Array();
3967: if (curraccess == 'none') {
3968: hidden = Array('$hiddenstr');
3969: } else {
3970: if (curraccess == 'status') {
3971: shown = Array('bystatus');
3972: hidden = Array('notinc','notexc');
3973: } else {
3974: if (curraccess == 'exc') {
3975: shown = Array('notexc');
3976: hidden = Array('notinc','bystatus');
3977: }
3978: if (curraccess == 'inc') {
3979: shown = Array('notinc');
3980: hidden = Array('notexc','bystatus');
3981: }
1.293 raeburn 3982: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 3983: hidden = Array('notinc','notexc','bystatus');
3984: }
3985: }
3986: }
3987: if (hidden.length > 0) {
3988: for (var i=0; i<hidden.length; i++) {
3989: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3990: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3991: }
3992: }
3993: }
3994: if (shown.length > 0) {
3995: for (var i=0; i<shown.length; i++) {
3996: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
3997: if (shown[i] == 'privs') {
3998: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
3999: } else {
4000: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4001: }
4002: }
4003: }
4004: }
4005: return;
4006: }
4007:
4008: function toggleHelpdeskItem(num,field) {
4009: if (document.getElementById('helproles_'+num+'_'+field)) {
4010: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 4011: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 4012: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4013: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4014: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4015: }
4016: } else {
4017: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4018: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4019: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4020: }
4021: }
4022: }
4023: return;
4024: }
4025:
4026: // ]]>
4027: </script>
4028:
4029: ENDSCRIPT
4030: }
4031:
4032: sub helpdeskroles_access {
4033: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4034: $usertypes,$types,$domhelpdesk) = @_;
4035: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
4036: my %lt = &Apache::lonlocal::texthash(
4037: 'rou' => 'Role usage',
4038: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 4039: 'all' => 'All with domain helpdesk or helpdesk assistant role',
4040: 'dh' => 'All with domain helpdesk role',
4041: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 4042: 'none' => 'None',
4043: 'status' => 'Determined based on institutional status',
4044: 'inc' => 'Include all, but exclude specific personnel',
4045: 'exc' => 'Exclude all, but include specific personnel',
4046: );
4047: my %usecheck = (
4048: all => ' checked="checked"',
4049: );
4050: my %displaydiv = (
4051: status => 'none',
4052: inc => 'none',
4053: exc => 'none',
4054: priv => 'block',
4055: );
4056: my $output;
4057: if (ref($current) eq 'HASH') {
4058: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
4059: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
4060: $usecheck{$current->{access}} = $usecheck{'all'};
4061: delete($usecheck{'all'});
4062: if ($current->{access} =~ /^(status|inc|exc)$/) {
4063: my $access = $1;
4064: $displaydiv{$access} = 'inline';
4065: } elsif ($current->{access} eq 'none') {
4066: $displaydiv{'priv'} = 'none';
4067: }
4068: }
4069: }
4070: }
4071: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
4072: '<p>'.$lt{'whi'}.'</p>';
4073: foreach my $access (@{$accesstypes}) {
4074: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
4075: ' onclick="helpdeskAccess('."'$num'".');" />'.
4076: $lt{$access}.'</label>';
4077: if ($access eq 'status') {
4078: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
4079: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
4080: $othertitle,$usertypes,$types).
4081: '</div>';
4082: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
4083: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
4084: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4085: '</div>';
4086: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
4087: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
4088: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4089: '</div>';
4090: }
4091: $output .= '</p>';
4092: }
4093: $output .= '</fieldset>';
4094: return $output;
4095: }
4096:
1.121 raeburn 4097: sub radiobutton_prefs {
1.192 raeburn 4098: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 4099: $additional,$align) = @_;
1.121 raeburn 4100: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
4101: (ref($choices) eq 'HASH'));
4102:
1.170 raeburn 4103: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 4104:
4105: foreach my $item (@{$toggles}) {
4106: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 4107: $checkedon{$item} = ' checked="checked" ';
4108: $checkedoff{$item} = ' ';
1.121 raeburn 4109: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 4110: $checkedoff{$item} = ' checked="checked" ';
4111: $checkedon{$item} = ' ';
4112: }
4113: }
4114: if (ref($settings) eq 'HASH') {
1.121 raeburn 4115: foreach my $item (@{$toggles}) {
1.118 jms 4116: if ($settings->{$item} eq '1') {
4117: $checkedon{$item} = ' checked="checked" ';
4118: $checkedoff{$item} = ' ';
4119: } elsif ($settings->{$item} eq '0') {
4120: $checkedoff{$item} = ' checked="checked" ';
4121: $checkedon{$item} = ' ';
4122: }
4123: }
1.121 raeburn 4124: }
1.192 raeburn 4125: if ($onclick) {
4126: $onclick = ' onclick="'.$onclick.'"';
4127: }
1.121 raeburn 4128: foreach my $item (@{$toggles}) {
1.118 jms 4129: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 4130: $datatable .=
1.306 raeburn 4131: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 4132: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 4133: '</span></td>';
4134: if ($align eq 'left') {
4135: $datatable .= '<td class="LC_left_item">';
4136: } else {
4137: $datatable .= '<td class="LC_right_item">';
4138: }
1.289 raeburn 4139: $datatable .=
1.257 raeburn 4140: '<span class="LC_nobreak">'.
1.118 jms 4141: '<label><input type="radio" name="'.
1.192 raeburn 4142: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 4143: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 4144: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
4145: '</span>'.$additional.
4146: '</td>'.
1.118 jms 4147: '</tr>';
4148: $itemcount ++;
1.121 raeburn 4149: }
4150: return ($datatable,$itemcount);
4151: }
4152:
1.267 raeburn 4153: sub print_ltitools {
4154: my ($dom,$settings,$rowtotal) = @_;
4155: my $rownum = 0;
4156: my $css_class;
4157: my $itemcount = 1;
4158: my $maxnum = 0;
4159: my %ordered;
4160: if (ref($settings) eq 'HASH') {
4161: foreach my $item (keys(%{$settings})) {
4162: if (ref($settings->{$item}) eq 'HASH') {
4163: my $num = $settings->{$item}{'order'};
4164: $ordered{$num} = $item;
4165: }
4166: }
4167: }
4168: my $confname = $dom.'-domainconfig';
4169: my $switchserver = &check_switchserver($dom,$confname);
4170: my $maxnum = scalar(keys(%ordered));
4171: my $datatable = <itools_javascript($settings);
4172: my %lt = <itools_names();
4173: my @courseroles = ('cc','in','ta','ep','st');
4174: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1.324 raeburn 4175: my @fields = ('fullname','firstname','lastname','email','roles','user');
1.267 raeburn 4176: if (keys(%ordered)) {
4177: my @items = sort { $a <=> $b } keys(%ordered);
4178: for (my $i=0; $i<@items; $i++) {
4179: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4180: my $item = $ordered{$items[$i]};
1.323 raeburn 4181: my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
1.267 raeburn 4182: if (ref($settings->{$item}) eq 'HASH') {
4183: $title = $settings->{$item}->{'title'};
4184: $url = $settings->{$item}->{'url'};
4185: $key = $settings->{$item}->{'key'};
4186: $secret = $settings->{$item}->{'secret'};
1.322 raeburn 4187: $lifetime = $settings->{$item}->{'lifetime'};
1.267 raeburn 4188: my $image = $settings->{$item}->{'image'};
4189: if ($image ne '') {
4190: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
4191: }
1.323 raeburn 4192: if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
4193: $sigsel{'HMAC-256'} = ' selected="selected"';
4194: } else {
4195: $sigsel{'HMAC-SHA1'} = ' selected="selected"';
4196: }
1.267 raeburn 4197: }
1.319 raeburn 4198: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1.267 raeburn 4199: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4200: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
4201: for (my $k=0; $k<=$maxnum; $k++) {
4202: my $vpos = $k+1;
4203: my $selstr;
4204: if ($k == $i) {
4205: $selstr = ' selected="selected" ';
4206: }
4207: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4208: }
4209: $datatable .= '</select>'.(' 'x2).
4210: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
4211: &mt('Delete?').'</label></span></td>'.
4212: '<td colspan="2">'.
4213: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4214: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
1.267 raeburn 4215: (' 'x2).
4216: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
4217: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4218: (' 'x2).
4219: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
4220: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4221: (' 'x2).
4222: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
4223: '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
4224: '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
1.267 raeburn 4225: '<br /><br />'.
1.323 raeburn 4226: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
1.267 raeburn 4227: ' value="'.$url.'" /></span>'.
4228: (' 'x2).
1.319 raeburn 4229: '<span class="LC_nobreak">'.$lt{'key'}.':'.
1.267 raeburn 4230: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
4231: (' 'x2).
1.322 raeburn 4232: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
4233: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
4234: (' 'x2).
1.267 raeburn 4235: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4236: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
4237: '<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>'.
4238: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
4239: '</fieldset>'.
4240: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4241: '<span class="LC_nobreak">'.&mt('Display target:');
4242: my %currdisp;
4243: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
4244: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
4245: $currdisp{'window'} = ' checked="checked"';
1.298 raeburn 4246: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
4247: $currdisp{'tab'} = ' checked="checked"';
1.267 raeburn 4248: } else {
4249: $currdisp{'iframe'} = ' checked="checked"';
4250: }
4251: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
4252: $currdisp{'width'} = $1;
4253: }
4254: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
4255: $currdisp{'height'} = $1;
4256: }
1.296 raeburn 4257: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
4258: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267 raeburn 4259: } else {
4260: $currdisp{'iframe'} = ' checked="checked"';
4261: }
1.298 raeburn 4262: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4263: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
4264: $lt{$disp}.'</label>'.(' 'x2);
4265: }
4266: $datatable .= (' 'x4);
4267: foreach my $dimen ('width','height') {
4268: $datatable .= '<label>'.$lt{$dimen}.' '.
4269: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
4270: (' 'x2);
4271: }
1.296 raeburn 4272: $datatable .= '<br />'.
4273: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
4274: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></label></div>'.
4275: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4276: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
4277: '</textarea></div><div style=""></div><br />';
1.319 raeburn 4278: my %units = (
4279: 'passback' => 'days',
4280: 'roster' => 'seconds',
4281: );
1.267 raeburn 4282: foreach my $extra ('passback','roster') {
1.319 raeburn 4283: my $validsty = 'none';
4284: my $currvalid;
1.267 raeburn 4285: my $checkedon = '';
4286: my $checkedoff = ' checked="checked"';
4287: if ($settings->{$item}->{$extra}) {
4288: $checkedon = $checkedoff;
4289: $checkedoff = '';
1.319 raeburn 4290: $validsty = 'inline-block';
4291: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
4292: $currvalid = $settings->{$item}->{$extra.'valid'};
4293: }
4294: }
4295: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
4296: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4297: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
4298: &mt('No').'</label>'.(' 'x2).
4299: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
4300: &mt('Yes').'</label></span></div>'.
4301: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
4302: '<span class="LC_nobreak">'.
4303: &mt("at least [_1] $units{$extra} after launch",
4304: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
4305: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4306: }
1.319 raeburn 4307: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
1.267 raeburn 4308: if ($imgsrc) {
4309: $datatable .= $imgsrc.
4310: '<label><input type="checkbox" name="ltitools_image_del"'.
4311: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
4312: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
4313: } else {
4314: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4315: }
4316: if ($switchserver) {
4317: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4318: } else {
4319: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
4320: }
4321: $datatable .= '</span></fieldset>';
1.324 raeburn 4322: my (%checkedfields,%rolemaps,$userincdom);
1.267 raeburn 4323: if (ref($settings->{$item}) eq 'HASH') {
4324: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
4325: %checkedfields = %{$settings->{$item}->{'fields'}};
4326: }
1.324 raeburn 4327: $userincdom = $settings->{$item}->{'incdom'};
1.267 raeburn 4328: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
4329: %rolemaps = %{$settings->{$item}->{'roles'}};
4330: $checkedfields{'roles'} = 1;
4331: }
4332: }
4333: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4334: '<span class="LC_nobreak">';
1.324 raeburn 4335: my $userfieldstyle = 'display:none;';
4336: my $seluserdom = '';
4337: my $unseluserdom = ' selected="selected"';
1.267 raeburn 4338: foreach my $field (@fields) {
1.324 raeburn 4339: my ($checked,$onclick,$id,$spacer);
1.267 raeburn 4340: if ($checkedfields{$field}) {
4341: $checked = ' checked="checked"';
4342: }
1.324 raeburn 4343: if ($field eq 'user') {
4344: $id = ' id="ltitools_user_field_'.$i.'"';
4345: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
4346: if ($checked) {
4347: $userfieldstyle = 'display:inline-block';
4348: if ($userincdom) {
4349: $seluserdom = $unseluserdom;
4350: $unseluserdom = '';
4351: }
4352: }
4353: } else {
4354: $spacer = (' ' x2);
4355: }
1.267 raeburn 4356: $datatable .= '<label>'.
1.324 raeburn 4357: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
4358: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 4359: }
1.324 raeburn 4360: $datatable .= '</span>';
4361: $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
4362: '<span class="LC_nobreak"> : '.
4363: '<select name="ltitools_userincdom_'.$i.'">'.
4364: '<option value="">'.&mt('Select').'</option>'.
4365: '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
4366: '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
4367: '</select></span></div>';
4368: $datatable .= '</fieldset>'.
1.267 raeburn 4369: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4370: foreach my $role (@courseroles) {
4371: my ($selected,$selectnone);
4372: if (!$rolemaps{$role}) {
4373: $selectnone = ' selected="selected"';
4374: }
1.306 raeburn 4375: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4376: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4377: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
4378: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
4379: foreach my $ltirole (@ltiroles) {
4380: unless ($selectnone) {
4381: if ($rolemaps{$role} eq $ltirole) {
4382: $selected = ' selected="selected"';
4383: } else {
4384: $selected = '';
4385: }
4386: }
4387: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
4388: }
4389: $datatable .= '</select></td>';
4390: }
1.273 raeburn 4391: $datatable .= '</tr></table></fieldset>';
4392: my %courseconfig;
4393: if (ref($settings->{$item}) eq 'HASH') {
4394: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
4395: %courseconfig = %{$settings->{$item}->{'crsconf'}};
4396: }
4397: }
4398: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4399: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 4400: my $checked;
4401: if ($courseconfig{$item}) {
4402: $checked = ' checked="checked"';
4403: }
4404: $datatable .= '<label>'.
4405: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
4406: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
4407: }
4408: $datatable .= '</span></fieldset>'.
1.267 raeburn 4409: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4410: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
4411: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
4412: my %custom = %{$settings->{$item}->{'custom'}};
4413: if (keys(%custom) > 0) {
4414: foreach my $key (sort(keys(%custom))) {
4415: $datatable .= '<tr><td><span class="LC_nobreak">'.
4416: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
4417: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
4418: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
4419: ' value="'.$custom{$key}.'" /></td></tr>';
4420: }
4421: }
4422: }
4423: $datatable .= '<tr><td><span class="LC_nobreak">'.
4424: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
4425: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
4426: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
4427: $datatable .= '</table></fieldset></td></tr>'."\n";
4428: $itemcount ++;
4429: }
4430: }
4431: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.319 raeburn 4432: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1.267 raeburn 4433: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4434: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
4435: '<select name="ltitools_add_pos"'.$chgstr.'>';
4436: for (my $k=0; $k<$maxnum+1; $k++) {
4437: my $vpos = $k+1;
4438: my $selstr;
4439: if ($k == $maxnum) {
4440: $selstr = ' selected="selected" ';
4441: }
4442: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4443: }
4444: $datatable .= '</select> '."\n".
4445: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".
4446: '<td colspan="2">'.
4447: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4448: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
1.267 raeburn 4449: (' 'x2).
4450: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
4451: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4452: (' 'x2).
4453: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
4454: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4455: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
4456: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
4457: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
1.267 raeburn 4458: '<br />'.
1.323 raeburn 4459: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
1.267 raeburn 4460: (' 'x2).
4461: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
4462: (' 'x2).
1.322 raeburn 4463: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
4464: (' 'x2).
1.267 raeburn 4465: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
4466: '<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".
4467: '</fieldset>'.
4468: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4469: '<span class="LC_nobreak">'.&mt('Display target:');
4470: my %defaultdisp;
4471: $defaultdisp{'iframe'} = ' checked="checked"';
1.298 raeburn 4472: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4473: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
4474: $lt{$disp}.'</label>'.(' 'x2);
4475: }
4476: $datatable .= (' 'x4);
4477: foreach my $dimen ('width','height') {
4478: $datatable .= '<label>'.$lt{$dimen}.' '.
4479: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
4480: (' 'x2);
4481: }
1.296 raeburn 4482: $datatable .= '<br />'.
4483: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
4484: '<input type="text" name="ltitools_add_linktext" size="5" /></label></div>'.
4485: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4486: '<textarea name=ltitools_add_explanation" rows="5" cols="40"></textarea>'.
4487: '</div><div style=""></div><br />';
1.319 raeburn 4488: my %units = (
4489: 'passback' => 'days',
4490: 'roster' => 'seconds',
4491: );
4492: my %defaulttimes = (
4493: 'passback' => '7',
1.322 raeburn 4494: 'roster' => '300',
1.319 raeburn 4495: );
1.267 raeburn 4496: foreach my $extra ('passback','roster') {
1.319 raeburn 4497: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
4498: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4499: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
4500: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
4501: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
4502: &mt('Yes').'</label></span></div>'.
4503: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
4504: '<span class="LC_nobreak">'.
4505: &mt("at least [_1] $units{$extra} after launch",
4506: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
4507: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4508: }
1.319 raeburn 4509: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
1.267 raeburn 4510: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4511: if ($switchserver) {
4512: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4513: } else {
4514: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
4515: }
4516: $datatable .= '</span></fieldset>'.
4517: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4518: '<span class="LC_nobreak">';
4519: foreach my $field (@fields) {
1.324 raeburn 4520: my ($id,$onclick,$spacer);
4521: if ($field eq 'user') {
4522: $id = ' id="ltitools_user_field_add"';
4523: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
4524: } else {
4525: $spacer = (' ' x2);
4526: }
1.267 raeburn 4527: $datatable .= '<label>'.
1.324 raeburn 4528: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
4529: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 4530: }
1.324 raeburn 4531: $datatable .= '</span>'.
4532: '<div style="display:none;" id="ltitools_user_div_add">'.
4533: '<span class="LC_nobreak"> : '.
4534: '<select name="ltitools_userincdom_add">'.
4535: '<option value="" selected="selected">'.&mt('Select').'</option>'.
4536: '<option value="0">'.&mt('username').'</option>'.
4537: '<option value="1">'.&mt('username:domain').'</option>'.
4538: '</select></span></div></fieldset>';
4539: $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
1.267 raeburn 4540: foreach my $role (@courseroles) {
4541: my ($checked,$checkednone);
1.306 raeburn 4542: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4543: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4544: '<select name="ltitools_add_roles_'.$role.'">'.
4545: '<option value="" selected="selected">'.&mt('Select').'</option>';
4546: foreach my $ltirole (@ltiroles) {
4547: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
4548: }
4549: $datatable .= '</select></td>';
4550: }
4551: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 4552: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4553: foreach my $item ('label','title','target','linktext','explanation','append') {
1.296 raeburn 4554: $datatable .= '<label>'.
4555: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
4556: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
1.273 raeburn 4557: }
4558: $datatable .= '</span></fieldset>'.
1.267 raeburn 4559: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4560: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
4561: '<tr><td><span class="LC_nobreak">'.
4562: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
4563: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
4564: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
4565: '</table></fieldset></td></tr>'."\n".
4566: '</td>'."\n".
4567: '</tr>'."\n";
4568: $itemcount ++;
4569: return $datatable;
4570: }
4571:
4572: sub ltitools_names {
4573: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 4574: 'title' => 'Title',
4575: 'version' => 'Version',
4576: 'msgtype' => 'Message Type',
1.323 raeburn 4577: 'sigmethod' => 'Signature Method',
1.296 raeburn 4578: 'url' => 'URL',
4579: 'key' => 'Key',
1.322 raeburn 4580: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 4581: 'secret' => 'Secret',
4582: 'icon' => 'Icon',
1.324 raeburn 4583: 'user' => 'User',
1.296 raeburn 4584: 'fullname' => 'Full Name',
4585: 'firstname' => 'First Name',
4586: 'lastname' => 'Last Name',
4587: 'email' => 'E-mail',
4588: 'roles' => 'Role',
1.298 raeburn 4589: 'window' => 'Window',
4590: 'tab' => 'Tab',
1.296 raeburn 4591: 'iframe' => 'iFrame',
4592: 'height' => 'Height',
4593: 'width' => 'Width',
4594: 'linktext' => 'Default Link Text',
4595: 'explanation' => 'Default Explanation',
4596: 'passback' => 'Tool can return grades:',
4597: 'roster' => 'Tool can retrieve roster:',
4598: 'crstarget' => 'Display target',
4599: 'crslabel' => 'Course label',
4600: 'crstitle' => 'Course title',
4601: 'crslinktext' => 'Link Text',
4602: 'crsexplanation' => 'Explanation',
1.318 raeburn 4603: 'crsappend' => 'Provider URL',
1.267 raeburn 4604: );
4605: return %lt;
4606: }
4607:
1.320 raeburn 4608: sub print_lti {
4609: my ($dom,$settings,$rowtotal) = @_;
4610: my $itemcount = 1;
4611: my $maxnum = 0;
4612: my $css_class;
4613: my %ordered;
4614: if (ref($settings) eq 'HASH') {
4615: foreach my $item (keys(%{$settings})) {
4616: if (ref($settings->{$item}) eq 'HASH') {
4617: my $num = $settings->{$item}{'order'};
4618: $ordered{$num} = $item;
4619: }
4620: }
4621: }
4622: my $maxnum = scalar(keys(%ordered));
4623: my $datatable = <i_javascript($settings);
4624: my %lt = <i_names();
4625: if (keys(%ordered)) {
4626: my @items = sort { $a <=> $b } keys(%ordered);
4627: for (my $i=0; $i<@items; $i++) {
4628: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4629: my $item = $ordered{$items[$i]};
4630: my ($key,$secret,$lifetime,$consumer,$current);
4631: if (ref($settings->{$item}) eq 'HASH') {
4632: $key = $settings->{$item}->{'key'};
4633: $secret = $settings->{$item}->{'secret'};
4634: $lifetime = $settings->{$item}->{'lifetime'};
4635: $consumer = $settings->{$item}->{'consumer'};
4636: $current = $settings->{$item};
4637: }
4638: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
4639: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4640: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
4641: for (my $k=0; $k<=$maxnum; $k++) {
4642: my $vpos = $k+1;
4643: my $selstr;
4644: if ($k == $i) {
4645: $selstr = ' selected="selected" ';
4646: }
4647: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4648: }
4649: $datatable .= '</select>'.(' 'x2).
4650: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
4651: &mt('Delete?').'</label></span></td>'.
4652: '<td colspan="2">'.
4653: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4654: '<span class="LC_nobreak">'.$lt{'consumer'}.
4655: ':<input type="text" size="20" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
4656: (' 'x2).
4657: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
4658: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4659: (' 'x2).
4660: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
4661: 'value="'.$lifetime.'" size="5" /></span>'.
4662: '<br /><br />'.
4663: '<span class="LC_nobreak">'.$lt{'key'}.
4664: ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
4665: (' 'x2).
4666: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4667: '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
4668: '<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>'.
4669: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
1.325 raeburn 4670: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
1.320 raeburn 4671: $itemcount ++;
4672: }
4673: }
4674: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4675: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
4676: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4677: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
4678: '<select name="lti_pos_add"'.$chgstr.'>';
4679: for (my $k=0; $k<$maxnum+1; $k++) {
4680: my $vpos = $k+1;
4681: my $selstr;
4682: if ($k == $maxnum) {
4683: $selstr = ' selected="selected" ';
4684: }
4685: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4686: }
4687: $datatable .= '</select> '."\n".
4688: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</td>'."\n".
4689: '<td colspan="2">'.
4690: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4691: '<span class="LC_nobreak">'.$lt{'consumer'}.
4692: ':<input type="text" size="20" name="lti_consumer_add" value="" /></span> '."\n".
4693: (' 'x2).
4694: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
4695: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4696: (' 'x2).
1.322 raeburn 4697: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="lti_lifetime_add" value="300" /></span> '."\n".
1.320 raeburn 4698: '<br /><br />'.
4699: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
4700: (' 'x2).
4701: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
4702: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.lti_secret_add.type='."'text'".' } else { this.form.lti_secret_add.type='."'password'".' }" />'.&mt('Visible input').'</label></span> '."\n".
1.325 raeburn 4703: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
1.320 raeburn 4704: '</td>'."\n".
4705: '</tr>'."\n";
4706: $$rowtotal ++;
4707: return $datatable;;
4708: }
4709:
4710: sub lti_names {
4711: my %lt = &Apache::lonlocal::texthash(
4712: 'version' => 'LTI Version',
4713: 'url' => 'URL',
4714: 'key' => 'Key',
1.322 raeburn 4715: 'lifetime' => 'Nonce lifetime (s)',
1.320 raeburn 4716: 'consumer' => 'LTI Consumer',
4717: 'secret' => 'Secret',
4718: 'email' => 'Email address',
4719: 'sourcedid' => 'User ID',
4720: 'other' => 'Other',
4721: 'passback' => 'Can return grades to Consumer:',
4722: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 4723: 'topmenu' => 'Display LON-CAPA page header',
4724: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 4725: );
4726: return %lt;
4727: }
4728:
4729: sub lti_options {
1.325 raeburn 4730: my ($num,$current,$itemcount,%lt) = @_;
1.320 raeburn 4731: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield);
4732: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
4733: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
4734: $checked{'makecrs'}{'N'} = ' checked="checked"';
4735: $checked{'mapcrstype'} = {};
4736: $checked{'makeuser'} = {};
4737: $checked{'selfenroll'} = {};
4738: $checked{'crssec'} = {};
4739: $checked{'crssecsrc'} = {};
1.325 raeburn 4740: $checked{'lcauth'} = {};
1.326 raeburn 4741: $checked{'menuitem'} = {};
1.325 raeburn 4742: if ($num eq 'add') {
4743: $checked{'lcauth'}{'lti'} = ' checked="checked"';
4744: }
1.320 raeburn 4745: my $userfieldsty = 'none';
4746: my $crsfieldsty = 'none';
4747: my $crssecfieldsty = 'none';
4748: my $secsrcfieldsty = 'none';
1.325 raeburn 4749: my $lcauthparm;
4750: my $lcauthparmstyle = 'display:none';
4751: my $lcauthparmtext;
1.326 raeburn 4752: my $menusty;
1.325 raeburn 4753: my $numinrow = 4;
1.326 raeburn 4754: my %menutitles = <imenu_titles();
1.320 raeburn 4755:
4756: if (ref($current) eq 'HASH') {
4757: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
4758: $checked{'mapuser'}{'sourcedid'} = '';
4759: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
4760: $checked{'mapuser'}{'email'} = ' checked="checked"';
4761: } else {
4762: $checked{'mapuser'}{'other'} = ' checked="checked"';
4763: $userfield = $current->{'mapuser'};
4764: $userfieldsty = 'inline-block';
4765: }
4766: }
4767: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
4768: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
4769: if ($current->{'mapcrs'} eq 'context_id') {
4770: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
4771: } else {
4772: $checked{'mapcrs'}{'other'} = ' checked="checked"';
4773: $cidfield = $current->{'mapcrs'};
4774: $crsfieldsty = 'inline-block';
4775: }
4776: }
4777: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
4778: foreach my $type (@{$current->{'mapcrstype'}}) {
4779: $checked{'mapcrstype'}{$type} = ' checked="checked"';
4780: }
4781: }
4782: if ($current->{'makecrs'}) {
4783: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 4784: }
1.320 raeburn 4785: if (ref($current->{'makeuser'}) eq 'ARRAY') {
4786: foreach my $role (@{$current->{'makeuser'}}) {
4787: $checked{'makeuser'}{$role} = ' checked="checked"';
4788: }
4789: }
1.325 raeburn 4790: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
4791: $checked{'lcauth'}{$1} = ' checked="checked"';
4792: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
4793: $lcauthparm = $current->{'lcauthparm'};
4794: $lcauthparmstyle = 'display:table-row';
4795: if ($current->{'lcauth'} eq 'localauth') {
4796: $lcauthparmtext = &mt('Local auth argument');
4797: } else {
4798: $lcauthparmtext = &mt('Kerberos domain');
4799: }
4800: }
4801: }
1.320 raeburn 4802: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
4803: foreach my $role (@{$current->{'selfenroll'}}) {
4804: $checked{'selfenroll'}{$role} = ' checked="checked"';
4805: }
4806: }
4807: if (ref($current->{'maproles'}) eq 'HASH') {
4808: %rolemaps = %{$current->{'maproles'}};
4809: }
4810: if ($current->{'section'} ne '') {
4811: $checked{'crssec'}{'Y'} = ' checked="checked"';
4812: $crssecfieldsty = 'inline-block';
4813: if ($current->{'section'} eq 'course_section_sourcedid') {
4814: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
4815: } else {
4816: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
4817: $crssecsrc = $current->{'section'};
4818: $secsrcfieldsty = 'inline-block';
4819: }
4820: } else {
4821: $checked{'crssec'}{'N'} = ' checked="checked"';
4822: }
1.326 raeburn 4823: if ($current->{'topmenu'}) {
4824: $checked{'topmenu'}{'Y'} = ' checked="checked"';
4825: } else {
4826: $checked{'topmenu'}{'N'} = ' checked="checked"';
4827: }
4828: if ($current->{'inlinemenu'}) {
4829: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
4830: } else {
4831: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
4832: }
4833: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
4834: $menusty = 'inline-block';
4835: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
4836: foreach my $item (@{$current->{'lcmenu'}}) {
4837: if (exists($menutitles{$item})) {
4838: $checked{'menuitem'}{$item} = ' checked="checked"';
4839: }
4840: }
4841: }
4842: } else {
4843: $menusty = 'none';
4844: }
1.320 raeburn 4845: } else {
4846: $checked{'makecrs'}{'N'} = ' checked="checked"';
4847: $checked{'crssec'}{'N'} = ' checked="checked"';
1.326 raeburn 4848: $checked{'topmenu'}{'N'} = ' checked="checked"';
4849: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
4850: $checked{'menuitem'}{'grades'} = ' checked="checked"';
4851: $menusty = 'inline-block';
1.320 raeburn 4852: }
1.325 raeburn 4853: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 4854: my %coursetypetitles = &Apache::lonlocal::texthash (
4855: official => 'Official',
4856: unofficial => 'Unofficial',
4857: community => 'Community',
4858: textbook => 'Textbook',
4859: placement => 'Placement Test',
1.325 raeburn 4860: lti => 'LTI Provider',
1.320 raeburn 4861: );
1.325 raeburn 4862: my @authtypes = ('internal','krb4','krb5','localauth');
4863: my %shortauth = (
4864: internal => 'int',
4865: krb4 => 'krb4',
4866: krb5 => 'krb5',
4867: localauth => 'loc'
4868: );
4869: my %authnames = &authtype_names();
1.320 raeburn 4870: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
4871: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
4872: my @courseroles = ('cc','in','ta','ep','st');
4873: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
4874: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
4875: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
4876: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 4877: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 4878: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.320 raeburn 4879: my $output = '<fieldset><legend>'.&mt('Mapping users').'</legend>'.
4880: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
4881: foreach my $option ('sourcedid','email','other') {
4882: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
4883: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
4884: ($option eq 'other' ? '' : (' 'x2) );
4885: }
4886: $output .= '</span></div>'.
4887: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
4888: '<input type="text" name="lti_customuser_'.$num.'" '.
4889: 'value="'.$userfield.'" /></div></fieldset>'.
4890: '<fieldset><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
4891: foreach my $ltirole (@lticourseroles) {
4892: my ($selected,$selectnone);
4893: if ($rolemaps{$ltirole} eq '') {
4894: $selectnone = ' selected="selected"';
4895: }
4896: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
4897: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
4898: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
4899: foreach my $role (@courseroles) {
4900: unless ($selectnone) {
4901: if ($rolemaps{$ltirole} eq $role) {
4902: $selected = ' selected="selected"';
4903: } else {
4904: $selected = '';
4905: }
4906: }
4907: $output .= '<option value="'.$role.'"'.$selected.'>'.
4908: &Apache::lonnet::plaintext($role,'Course').
4909: '</option>';
4910: }
4911: $output .= '</select></td>';
4912: }
4913: $output .= '</tr></table></fieldset>'.
4914: '<fieldset><legend>'.&mt('Roles which may create user accounts').'</legend>';
4915: foreach my $ltirole (@ltiroles) {
4916: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
4917: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
4918: }
4919: $output .= '</fieldset>'.
1.325 raeburn 4920: '<fieldset><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
4921: '<table>'.
4922: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
4923: '</table>'.
4924: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
4925: '<td class="LC_left_item">';
4926: foreach my $auth ('lti',@authtypes) {
4927: my $authtext;
4928: if ($auth eq 'lti') {
4929: $authtext = &mt('None');
4930: } else {
4931: $authtext = $authnames{$shortauth{$auth}};
4932: }
4933: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
4934: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
4935: $authtext.'</label></span> ';
4936: }
4937: $output .= '</td></tr>'.
4938: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
4939: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
4940: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
4941: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
4942: '</table></fieldset>'.
1.320 raeburn 4943: '<fieldset><legend>'.&mt('Mapping courses').'</legend>'.
4944: '<div class="LC_floatleft"><span class="LC_nobreak">'.
4945: &mt('Unique course identifier').': ';
4946: foreach my $option ('course_offering_sourcedid','context_id','other') {
4947: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
4948: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
4949: ($option eq 'other' ? '' : (' 'x2) );
4950: }
4951: $output .= '</div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'".>'.
4952: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
4953: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
4954: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
4955: foreach my $type (@coursetypes) {
4956: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
4957: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
4958: (' 'x2);
4959: }
4960: $output .= '</span></fieldset>'.
4961: '<fieldset><legend>'.&mt('Creating courses').'</legend>'.
4962: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
4963: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
4964: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
4965: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
4966: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
4967: '</fieldset>'.
4968: '<fieldset><legend>'.&mt('Roles which may self-enroll').'</legend>';
4969: foreach my $lticrsrole (@lticourseroles) {
4970: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
4971: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
4972: }
4973: $output .= '</fieldset>'.
4974: '<fieldset><legend>'.&mt('Course options').'</legend>'.
4975: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
4976: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
4977: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
4978: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
4979: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label><span></div>'.
4980: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
4981: '<span class="LC_nobreak">'.&mt('From').':<label>'.
4982: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
4983: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
4984: &mt('Standard field').'</label>'.(' 'x2).
4985: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
4986: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
4987: '</label></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
4988: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
4989: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
4990: foreach my $extra ('passback','roster') {
4991: my $checkedon = '';
4992: my $checkedoff = ' checked="checked"';
4993: if (ref($current) eq 'HASH') {
4994: if (($current->{$extra})) {
4995: $checkedon = $checkedoff;
4996: $checkedoff = '';
4997: }
4998: }
4999: $output .= $lt{$extra}.' '.
5000: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.' />'.
5001: &mt('No').'</label>'.(' 'x2).
5002: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.' />'.
5003: &mt('Yes').'</label><br />';
5004: }
1.326 raeburn 5005: $output .= '</span></fieldset>'.
5006: '<fieldset><legend>'.&mt('Course defaults (Course Coordinator can override)').'</legend>'.
5007: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
5008: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
5009: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
5010: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
5011: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label><span></div>'.
5012: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
5013: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
5014: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
5015: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
5016: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
5017: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label><span></div>';
5018: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
5019: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
5020: '<span class="LC_nobreak">'.&mt('Menu items').': ';
5021: foreach my $type ('fullname','coursetitle','role','logout','grades') {
5022: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
5023: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
5024: (' 'x2);
5025: }
1.320 raeburn 5026: $output .= '</span></fieldset>';
5027: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
5028: #
5029: # $output .= '</fieldset>'.
5030: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
5031: return $output;
5032: }
5033:
1.326 raeburn 5034: sub ltimenu_titles {
5035: return &Apache::lonlocal::texthash(
5036: fullname => 'Full name',
5037: coursetitle => 'Course title',
5038: role => 'Role',
5039: logout => 'Logout',
5040: grades => 'Grades',
5041: );
5042: }
5043:
1.121 raeburn 5044: sub print_coursedefaults {
1.139 raeburn 5045: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 5046: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 5047: my $itemcount = 1;
1.192 raeburn 5048: my %choices = &Apache::lonlocal::texthash (
5049: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 5050: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 5051: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
5052: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 5053: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
5054: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.314 raeburn 5055: texengine => 'Default method to display mathematics',
1.257 raeburn 5056: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 5057: canclone => "People who may clone a course (besides course's owner and coordinators)",
5058: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 5059: );
1.198 raeburn 5060: my %staticdefaults = (
1.314 raeburn 5061: texengine => 'MathJax',
1.198 raeburn 5062: anonsurvey_threshold => 10,
5063: uploadquota => 500,
1.257 raeburn 5064: postsubmit => 60,
1.276 raeburn 5065: mysqltables => 172800,
1.198 raeburn 5066: );
1.139 raeburn 5067: if ($position eq 'top') {
1.257 raeburn 5068: %defaultchecked = (
5069: 'canuse_pdfforms' => 'off',
5070: 'uselcmath' => 'on',
5071: 'usejsme' => 'on',
1.289 raeburn 5072: 'canclone' => 'none',
1.257 raeburn 5073: );
5074: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.314 raeburn 5075: my $deftex = $staticdefaults{'texengine'};
5076: if (ref($settings) eq 'HASH') {
5077: if ($settings->{'texengine'}) {
5078: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
5079: $deftex = $settings->{'texengine'};
5080: }
5081: }
5082: }
5083: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5084: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
5085: '<span class="LC_nobreak">'.$choices{'texengine'}.
5086: '</span></td><td class="LC_right_item">'.
5087: '<select name="texengine">'."\n";
5088: my %texoptions = (
5089: MathJax => 'MathJax',
5090: mimetex => &mt('Convert to Images'),
5091: tth => &mt('TeX to HTML'),
5092: );
5093: foreach my $renderer ('MathJax','mimetex','tth') {
5094: my $selected = '';
5095: if ($renderer eq $deftex) {
5096: $selected = ' selected="selected"';
5097: }
5098: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
5099: }
5100: $mathdisp .= '</select></td></tr>'."\n";
5101: $itemcount ++;
1.139 raeburn 5102: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 5103: \%choices,$itemcount);
1.314 raeburn 5104: $datatable = $mathdisp.$datatable;
1.264 raeburn 5105: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5106: $datatable .=
1.306 raeburn 5107: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 5108: '<span class="LC_nobreak">'.$choices{'canclone'}.
5109: '</span></td><td class="LC_left_item">';
5110: my $currcanclone = 'none';
5111: my $onclick;
5112: my @cloneoptions = ('none','domain');
5113: my %clonetitles = (
5114: none => 'No additional course requesters',
5115: domain => "Any course requester in course's domain",
5116: instcode => 'Course requests for official courses ...',
5117: );
5118: my (%codedefaults,@code_order,@posscodes);
5119: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
5120: \@code_order) eq 'ok') {
5121: if (@code_order > 0) {
5122: push(@cloneoptions,'instcode');
5123: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
5124: }
5125: }
5126: if (ref($settings) eq 'HASH') {
5127: if ($settings->{'canclone'}) {
5128: if (ref($settings->{'canclone'}) eq 'HASH') {
5129: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
5130: if (@code_order > 0) {
5131: $currcanclone = 'instcode';
5132: @posscodes = @{$settings->{'canclone'}{'instcode'}};
5133: }
5134: }
5135: } elsif ($settings->{'canclone'} eq 'domain') {
5136: $currcanclone = $settings->{'canclone'};
5137: }
5138: }
1.289 raeburn 5139: }
1.264 raeburn 5140: foreach my $option (@cloneoptions) {
5141: my ($checked,$additional);
5142: if ($currcanclone eq $option) {
5143: $checked = ' checked="checked"';
5144: }
5145: if ($option eq 'instcode') {
5146: if (@code_order) {
5147: my $show = 'none';
5148: if ($checked) {
5149: $show = 'block';
5150: }
1.317 raeburn 5151: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 5152: &mt('Institutional codes for new and cloned course have identical:').
5153: '<br />';
5154: foreach my $item (@code_order) {
5155: my $codechk;
5156: if ($checked) {
5157: if (grep(/^\Q$item\E$/,@posscodes)) {
5158: $codechk = ' checked="checked"';
5159: }
5160: }
5161: $additional .= '<label>'.
5162: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
5163: $item.'</label>';
5164: }
5165: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
5166: }
5167: }
5168: $datatable .=
5169: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
5170: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
5171: '</label> '.$additional.'</span><br />';
5172: }
5173: $datatable .= '</td>'.
5174: '</tr>';
5175: $itemcount ++;
1.139 raeburn 5176: } else {
5177: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 5178: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 5179: my $currusecredits = 0;
1.257 raeburn 5180: my $postsubmitclient = 1;
1.271 raeburn 5181: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 5182: if (ref($settings) eq 'HASH') {
5183: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 5184: if (ref($settings->{'uploadquota'}) eq 'HASH') {
5185: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
5186: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
5187: }
5188: }
1.192 raeburn 5189: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 5190: foreach my $type (@types) {
5191: next if ($type eq 'community');
5192: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
5193: if ($defcredits{$type} ne '') {
5194: $currusecredits = 1;
5195: }
5196: }
5197: }
5198: if (ref($settings->{'postsubmit'}) eq 'HASH') {
5199: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
5200: $postsubmitclient = 0;
5201: foreach my $type (@types) {
5202: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5203: }
5204: } else {
5205: foreach my $type (@types) {
5206: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
5207: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 5208: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 5209: } else {
5210: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5211: }
5212: } else {
5213: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5214: }
5215: }
5216: }
5217: } else {
5218: foreach my $type (@types) {
5219: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 5220: }
5221: }
1.276 raeburn 5222: if (ref($settings->{'mysqltables'}) eq 'HASH') {
5223: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
5224: $currmysql{$type} = $settings->{'mysqltables'}{$type};
5225: }
5226: } else {
5227: foreach my $type (@types) {
5228: $currmysql{$type} = $staticdefaults{'mysqltables'};
5229: }
5230: }
1.258 raeburn 5231: } else {
5232: foreach my $type (@types) {
5233: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5234: }
1.139 raeburn 5235: }
5236: if (!$currdefresponder) {
1.198 raeburn 5237: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 5238: } elsif ($currdefresponder < 1) {
5239: $currdefresponder = 1;
5240: }
1.198 raeburn 5241: foreach my $type (@types) {
5242: if ($curruploadquota{$type} eq '') {
5243: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
5244: }
5245: }
1.139 raeburn 5246: $datatable .=
1.192 raeburn 5247: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5248: $choices{'anonsurvey_threshold'}.
1.139 raeburn 5249: '</span></td>'.
5250: '<td class="LC_right_item"><span class="LC_nobreak">'.
5251: '<input type="text" name="anonsurvey_threshold"'.
5252: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 5253: '</td></tr>'."\n";
5254: $itemcount ++;
5255: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5256: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5257: $choices{'uploadquota'}.
5258: '</span></td>'.
1.306 raeburn 5259: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 5260: '<table><tr>';
1.198 raeburn 5261: foreach my $type (@types) {
1.306 raeburn 5262: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 5263: '<input type="text" name="uploadquota_'.$type.'"'.
5264: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
5265: }
5266: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 5267: $itemcount ++;
1.236 raeburn 5268: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 5269: my $display = 'none';
1.192 raeburn 5270: if ($currusecredits) {
5271: $display = 'block';
5272: }
5273: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 5274: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
5275: foreach my $type (@types) {
5276: next if ($type eq 'community');
1.306 raeburn 5277: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 5278: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 5279: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 5280: }
5281: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 5282: %defaultchecked = ('coursecredits' => 'off');
5283: @toggles = ('coursecredits');
5284: my $current = {
5285: 'coursecredits' => $currusecredits,
5286: };
5287: (my $table,$itemcount) =
5288: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 5289: \%choices,$itemcount,$onclick,$additional,'left');
5290: $datatable .= $table;
5291: $onclick = "toggleDisplay(this.form,'studentsubmission');";
5292: my $display = 'none';
5293: if ($postsubmitclient) {
5294: $display = 'block';
5295: }
5296: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 5297: &mt('Number of seconds submit is disabled').'<br />'.
5298: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
5299: '<table><tr>';
1.257 raeburn 5300: foreach my $type (@types) {
1.306 raeburn 5301: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 5302: '<input type="text" name="'.$type.'_timeout" value="'.
5303: $deftimeout{$type}.'" size="5" /></td>';
5304: }
5305: $additional .= '</tr></table></div>'."\n";
5306: %defaultchecked = ('postsubmit' => 'on');
5307: @toggles = ('postsubmit');
1.280 raeburn 5308: $current = {
5309: 'postsubmit' => $postsubmitclient,
5310: };
1.257 raeburn 5311: ($table,$itemcount) =
5312: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
5313: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 5314: $datatable .= $table;
1.276 raeburn 5315: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5316: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5317: $choices{'mysqltables'}.
5318: '</span></td>'.
1.306 raeburn 5319: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 5320: '<table><tr>';
5321: foreach my $type (@types) {
1.306 raeburn 5322: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 5323: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 5324: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 5325: }
5326: $datatable .= '</tr></table></td></tr>'."\n";
5327: $itemcount ++;
5328:
1.139 raeburn 5329: }
1.192 raeburn 5330: $$rowtotal += $itemcount;
1.121 raeburn 5331: return $datatable;
1.118 jms 5332: }
5333:
1.231 raeburn 5334: sub print_selfenrollment {
5335: my ($position,$dom,$settings,$rowtotal) = @_;
5336: my ($css_class,$datatable);
5337: my $itemcount = 1;
1.271 raeburn 5338: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 5339: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 5340: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
5341: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 5342: my @rows;
5343: my $key;
5344: if ($position eq 'top') {
5345: $key = 'admin';
5346: if (ref($rowsref) eq 'ARRAY') {
5347: @rows = @{$rowsref};
5348: }
5349: } elsif ($position eq 'middle') {
5350: $key = 'default';
5351: @rows = ('types','registered','approval','limit');
5352: }
5353: foreach my $row (@rows) {
5354: if (defined($titlesref->{$row})) {
5355: $itemcount ++;
5356: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5357: $datatable .= '<tr'.$css_class.'>'.
5358: '<td>'.$titlesref->{$row}.'</td>'.
5359: '<td class="LC_left_item">'.
5360: '<table><tr>';
5361: my (%current,%currentcap);
5362: if (ref($settings) eq 'HASH') {
5363: if (ref($settings->{$key}) eq 'HASH') {
5364: foreach my $type (@types) {
5365: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5366: $current{$type} = $settings->{$key}->{$type}->{$row};
5367: }
5368: if (($row eq 'limit') && ($key eq 'default')) {
5369: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5370: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
5371: }
5372: }
5373: }
5374: }
5375: }
5376: my %roles = (
5377: '0' => &Apache::lonnet::plaintext('dc'),
5378: );
5379:
5380: foreach my $type (@types) {
5381: unless (($row eq 'registered') && ($key eq 'default')) {
5382: $datatable .= '<th>'.&mt($type).'</th>';
5383: }
5384: }
5385: unless (($row eq 'registered') && ($key eq 'default')) {
5386: $datatable .= '</tr><tr>';
5387: }
5388: foreach my $type (@types) {
5389: if ($type eq 'community') {
5390: $roles{'1'} = &mt('Community personnel');
5391: } else {
5392: $roles{'1'} = &mt('Course personnel');
5393: }
5394: $datatable .= '<td style="vertical-align: top">';
5395: if ($position eq 'top') {
5396: my %checked;
5397: if ($current{$type} eq '0') {
5398: $checked{'0'} = ' checked="checked"';
5399: } else {
5400: $checked{'1'} = ' checked="checked"';
5401: }
5402: foreach my $role ('1','0') {
5403: $datatable .= '<span class="LC_nobreak"><label>'.
5404: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
5405: 'value="'.$role.'"'.$checked{$role}.' />'.
5406: $roles{$role}.'</label></span> ';
5407: }
5408: } else {
5409: if ($row eq 'types') {
5410: my %checked;
5411: if ($current{$type} =~ /^(all|dom)$/) {
5412: $checked{$1} = ' checked="checked"';
5413: } else {
5414: $checked{''} = ' checked="checked"';
5415: }
5416: foreach my $val ('','dom','all') {
5417: $datatable .= '<span class="LC_nobreak"><label>'.
5418: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5419: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5420: }
5421: } elsif ($row eq 'registered') {
5422: my %checked;
5423: if ($current{$type} eq '1') {
5424: $checked{'1'} = ' checked="checked"';
5425: } else {
5426: $checked{'0'} = ' checked="checked"';
5427: }
5428: foreach my $val ('0','1') {
5429: $datatable .= '<span class="LC_nobreak"><label>'.
5430: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5431: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5432: }
5433: } elsif ($row eq 'approval') {
5434: my %checked;
5435: if ($current{$type} =~ /^([12])$/) {
5436: $checked{$1} = ' checked="checked"';
5437: } else {
5438: $checked{'0'} = ' checked="checked"';
5439: }
5440: for my $val (0..2) {
5441: $datatable .= '<span class="LC_nobreak"><label>'.
5442: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5443: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5444: }
5445: } elsif ($row eq 'limit') {
5446: my %checked;
5447: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
5448: $checked{$1} = ' checked="checked"';
5449: } else {
5450: $checked{'none'} = ' checked="checked"';
5451: }
5452: my $cap;
5453: if ($currentcap{$type} =~ /^\d+$/) {
5454: $cap = $currentcap{$type};
5455: }
5456: foreach my $val ('none','allstudents','selfenrolled') {
5457: $datatable .= '<span class="LC_nobreak"><label>'.
5458: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5459: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5460: }
5461: $datatable .= '<br />'.
5462: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
5463: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
5464: '</span>';
5465: }
5466: }
5467: $datatable .= '</td>';
5468: }
5469: $datatable .= '</tr>';
5470: }
5471: $datatable .= '</table></td></tr>';
5472: }
5473: } elsif ($position eq 'bottom') {
1.235 raeburn 5474: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
5475: }
5476: $$rowtotal += $itemcount;
5477: return $datatable;
5478: }
5479:
5480: sub print_validation_rows {
5481: my ($caller,$dom,$settings,$rowtotal) = @_;
5482: my ($itemsref,$namesref,$fieldsref);
5483: if ($caller eq 'selfenroll') {
5484: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
5485: } elsif ($caller eq 'requestcourses') {
5486: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
5487: }
5488: my %currvalidation;
5489: if (ref($settings) eq 'HASH') {
5490: if (ref($settings->{'validation'}) eq 'HASH') {
5491: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 5492: }
1.235 raeburn 5493: }
5494: my $datatable;
5495: my $itemcount = 0;
5496: foreach my $item (@{$itemsref}) {
5497: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5498: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5499: $namesref->{$item}.
5500: '</span></td>'.
5501: '<td class="LC_left_item">';
5502: if (($item eq 'url') || ($item eq 'button')) {
5503: $datatable .= '<span class="LC_nobreak">'.
5504: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
5505: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
5506: } elsif ($item eq 'fields') {
5507: my @currfields;
5508: if (ref($currvalidation{$item}) eq 'ARRAY') {
5509: @currfields = @{$currvalidation{$item}};
5510: }
5511: foreach my $field (@{$fieldsref}) {
5512: my $check = '';
5513: if (grep(/^\Q$field\E$/,@currfields)) {
5514: $check = ' checked="checked"';
5515: }
5516: $datatable .= '<span class="LC_nobreak"><label>'.
5517: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
5518: ' value="'.$field.'"'.$check.' />'.$field.
5519: '</label></span> ';
5520: }
5521: } elsif ($item eq 'markup') {
5522: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
5523: $currvalidation{$item}.
1.231 raeburn 5524: '</textarea>';
1.235 raeburn 5525: }
5526: $datatable .= '</td></tr>'."\n";
5527: if (ref($rowtotal)) {
1.231 raeburn 5528: $itemcount ++;
5529: }
5530: }
1.235 raeburn 5531: if ($caller eq 'requestcourses') {
5532: my %currhash;
1.248 raeburn 5533: if (ref($settings) eq 'HASH') {
5534: if (ref($settings->{'validation'}) eq 'HASH') {
5535: if ($settings->{'validation'}{'dc'} ne '') {
5536: $currhash{$settings->{'validation'}{'dc'}} = 1;
5537: }
1.235 raeburn 5538: }
5539: }
5540: my $numinrow = 2;
5541: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
5542: 'validationdc',%currhash);
1.247 raeburn 5543: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5544: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.235 raeburn 5545: if ($numdc > 1) {
1.247 raeburn 5546: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 5547: } else {
1.247 raeburn 5548: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 5549: }
1.247 raeburn 5550: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 5551: $itemcount ++;
5552: }
5553: if (ref($rowtotal)) {
5554: $$rowtotal += $itemcount;
5555: }
1.231 raeburn 5556: return $datatable;
5557: }
5558:
1.137 raeburn 5559: sub print_usersessions {
5560: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 5561: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 5562: my (%by_ip,%by_location,@intdoms,@instdoms);
5563: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 5564:
5565: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 5566: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 5567: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 5568: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 5569: if ($position eq 'top') {
1.152 raeburn 5570: if (keys(%serverhomes) > 1) {
1.145 raeburn 5571: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.261 raeburn 5572: my $curroffloadnow;
5573: if (ref($settings) eq 'HASH') {
5574: if (ref($settings->{'offloadnow'}) eq 'HASH') {
5575: $curroffloadnow = $settings->{'offloadnow'};
5576: }
5577: }
5578: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 5579: } else {
1.140 raeburn 5580: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 5581: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
5582: '</td></tr>';
1.140 raeburn 5583: }
1.137 raeburn 5584: } else {
1.279 raeburn 5585: my %titles = &usersession_titles();
5586: my ($prefix,@types);
5587: if ($position eq 'bottom') {
5588: $prefix = 'remote';
5589: @types = ('version','excludedomain','includedomain');
1.145 raeburn 5590: } else {
1.279 raeburn 5591: $prefix = 'hosted';
5592: @types = ('excludedomain','includedomain');
5593: }
5594: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
5595: }
5596: $$rowtotal += $itemcount;
5597: return $datatable;
5598: }
5599:
5600: sub rules_by_location {
5601: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
5602: my ($datatable,$itemcount,$css_class);
5603: if (keys(%{$by_location}) == 0) {
5604: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5605: $datatable = '<tr'.$css_class.'><td colspan="2">'.
5606: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
5607: '</td></tr>';
5608: $itemcount = 1;
5609: } else {
5610: $itemcount = 0;
5611: my $numinrow = 5;
5612: my (%current,%checkedon,%checkedoff);
5613: my @locations = sort(keys(%{$by_location}));
5614: foreach my $type (@{$types}) {
5615: $checkedon{$type} = '';
5616: $checkedoff{$type} = ' checked="checked"';
5617: }
5618: if (ref($settings) eq 'HASH') {
5619: if (ref($settings->{$prefix}) eq 'HASH') {
5620: foreach my $key (keys(%{$settings->{$prefix}})) {
5621: $current{$key} = $settings->{$prefix}{$key};
5622: if ($key eq 'version') {
5623: if ($current{$key} ne '') {
1.145 raeburn 5624: $checkedon{$key} = ' checked="checked"';
5625: $checkedoff{$key} = '';
5626: }
1.279 raeburn 5627: } elsif (ref($current{$key}) eq 'ARRAY') {
5628: $checkedon{$key} = ' checked="checked"';
5629: $checkedoff{$key} = '';
1.137 raeburn 5630: }
5631: }
5632: }
1.279 raeburn 5633: }
5634: foreach my $type (@{$types}) {
5635: next if ($type ne 'version' && !@locations);
5636: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5637: $datatable .= '<tr'.$css_class.'>
5638: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
5639: <span class="LC_nobreak">
5640: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
5641: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
5642: if ($type eq 'version') {
5643: my @lcversions = &Apache::lonnet::all_loncaparevs();
5644: my $selector = '<select name="'.$prefix.'_version">';
5645: foreach my $version (@lcversions) {
5646: my $selected = '';
5647: if ($current{'version'} eq $version) {
5648: $selected = ' selected="selected"';
1.145 raeburn 5649: }
1.279 raeburn 5650: $selector .= ' <option value="'.$version.'"'.
5651: $selected.'>'.$version.'</option>';
5652: }
5653: $selector .= '</select> ';
5654: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
5655: } else {
5656: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
5657: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
5658: ' />'.(' 'x2).
5659: '<input type="button" value="'.&mt('uncheck all').'" '.
5660: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
5661: "\n".
5662: '</div><div><table>';
5663: my $rem;
5664: for (my $i=0; $i<@locations; $i++) {
5665: my ($showloc,$value,$checkedtype);
5666: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
5667: my $ip = $by_location->{$locations[$i]}->[0];
5668: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5669: $value = join(':',@{$by_ip->{$ip}});
5670: $showloc = join(', ',@{$by_ip->{$ip}});
5671: if (ref($current{$type}) eq 'ARRAY') {
5672: foreach my $loc (@{$by_ip->{$ip}}) {
5673: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
5674: $checkedtype = ' checked="checked"';
5675: last;
1.145 raeburn 5676: }
1.138 raeburn 5677: }
5678: }
5679: }
1.137 raeburn 5680: }
1.279 raeburn 5681: $rem = $i%($numinrow);
5682: if ($rem == 0) {
5683: if ($i > 0) {
5684: $datatable .= '</tr>';
5685: }
5686: $datatable .= '<tr>';
5687: }
5688: $datatable .= '<td class="LC_left_item">'.
5689: '<span class="LC_nobreak"><label>'.
5690: '<input type="checkbox" name="'.$prefix.'_'.$type.
5691: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
5692: '</label></span></td>';
5693: }
5694: $rem = @locations%($numinrow);
5695: my $colsleft = $numinrow - $rem;
5696: if ($colsleft > 1 ) {
5697: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5698: ' </td>';
5699: } elsif ($colsleft == 1) {
5700: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 5701: }
1.279 raeburn 5702: $datatable .= '</tr></table>';
1.137 raeburn 5703: }
1.279 raeburn 5704: $datatable .= '</td></tr>';
5705: $itemcount ++;
1.137 raeburn 5706: }
5707: }
1.279 raeburn 5708: return ($datatable,$itemcount);
1.137 raeburn 5709: }
5710:
1.275 raeburn 5711: sub print_ssl {
5712: my ($position,$dom,$settings,$rowtotal) = @_;
5713: my ($css_class,$datatable);
5714: my $itemcount = 1;
5715: if ($position eq 'top') {
1.281 raeburn 5716: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5717: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5718: my $same_institution;
5719: if ($intdom ne '') {
5720: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
5721: if (ref($internet_names) eq 'ARRAY') {
5722: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
5723: $same_institution = 1;
5724: }
5725: }
5726: }
1.275 raeburn 5727: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 5728: $datatable = '<tr'.$css_class.'><td colspan="2">';
5729: if ($same_institution) {
5730: my %domservers = &Apache::lonnet::get_servers($dom);
5731: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
5732: } else {
5733: $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.");
5734: }
5735: $datatable .= '</td></tr>';
1.275 raeburn 5736: $itemcount ++;
5737: } else {
5738: my %titles = &ssl_titles();
5739: my (%by_ip,%by_location,@intdoms,@instdoms);
5740: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
5741: my @alldoms = &Apache::lonnet::all_domains();
5742: my %serverhomes = %Apache::lonnet::serverhomeIDs;
5743: my @domservers = &Apache::lonnet::get_servers($dom);
5744: my %servers = &Apache::lonnet::internet_dom_servers($dom);
5745: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 5746: if (($position eq 'connto') || ($position eq 'connfrom')) {
5747: my $legacy;
5748: unless (ref($settings) eq 'HASH') {
5749: my $name;
5750: if ($position eq 'connto') {
5751: $name = 'loncAllowInsecure';
5752: } else {
5753: $name = 'londAllowInsecure';
5754: }
5755: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
5756: my @ids=&Apache::lonnet::current_machine_ids();
5757: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
5758: my %what = (
5759: $name => 1,
5760: );
5761: my ($result,$returnhash) =
5762: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
5763: if ($result eq 'ok') {
5764: if (ref($returnhash) eq 'HASH') {
5765: $legacy = $returnhash->{$name};
5766: }
5767: }
5768: } else {
5769: $legacy = $Apache::lonnet::perlvar{$name};
5770: }
5771: }
1.275 raeburn 5772: foreach my $type ('dom','intdom','other') {
5773: my %checked;
5774: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5775: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
5776: '<td class="LC_right_item">';
5777: my $skip;
5778: if ($type eq 'dom') {
5779: unless (keys(%servers) > 1) {
5780: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
5781: $skip = 1;
5782: }
5783: }
5784: if ($type eq 'intdom') {
5785: unless (@instdoms > 1) {
5786: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
5787: $skip = 1;
5788: }
5789: } elsif ($type eq 'other') {
5790: if (keys(%by_location) == 0) {
5791: $datatable .= &mt('Nothing to set here, as there are no other institutions');
5792: $skip = 1;
5793: }
5794: }
5795: unless ($skip) {
5796: $checked{'yes'} = ' checked="checked"';
5797: if (ref($settings) eq 'HASH') {
1.293 raeburn 5798: if (ref($settings->{$position}) eq 'HASH') {
5799: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 5800: $checked{$1} = $checked{'yes'};
5801: delete($checked{'yes'});
5802: }
5803: }
1.293 raeburn 5804: } else {
5805: if ($legacy == 0) {
5806: $checked{'req'} = $checked{'yes'};
5807: delete($checked{'yes'});
5808: }
1.275 raeburn 5809: }
5810: foreach my $option ('no','yes','req') {
5811: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 5812: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 5813: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
5814: '</label></span>'.(' 'x2);
5815: }
5816: }
5817: $datatable .= '</td></tr>';
5818: $itemcount ++;
5819: }
5820: } else {
5821: my $prefix = 'replication';
5822: my @types = ('certreq','nocertreq');
1.279 raeburn 5823: if (keys(%by_location) == 0) {
5824: $datatable .= '<tr'.$css_class.'><td>'.
5825: &mt('Nothing to set here, as there are no other institutions').
5826: '</td></tr>';
5827: $itemcount ++;
1.275 raeburn 5828: } else {
1.279 raeburn 5829: ($datatable,$itemcount) =
5830: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 5831: }
5832: }
5833: }
5834: $$rowtotal += $itemcount;
5835: return $datatable;
5836: }
5837:
5838: sub ssl_titles {
5839: return &Apache::lonlocal::texthash (
5840: dom => 'LON-CAPA servers/VMs from same domain',
5841: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
5842: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 5843: connto => 'Connections to other servers',
5844: connfrom => 'Connections from other servers',
1.275 raeburn 5845: replication => 'Replicating content to other institutions',
5846: certreq => 'Client certificate required, but specific domains exempt',
5847: nocertreq => 'No client certificate required, except for specific domains',
5848: no => 'SSL not used',
5849: yes => 'SSL Optional (used if available)',
5850: req => 'SSL Required',
5851: );
1.279 raeburn 5852: }
5853:
5854: sub print_trust {
5855: my ($prefix,$dom,$settings,$rowtotal) = @_;
5856: my ($css_class,$datatable,%checked,%choices);
5857: my (%by_ip,%by_location,@intdoms,@instdoms);
5858: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
5859: my $itemcount = 1;
5860: my %titles = &trust_titles();
5861: my @types = ('exc','inc');
5862: if ($prefix eq 'top') {
5863: $prefix = 'content';
5864: } elsif ($prefix eq 'bottom') {
5865: $prefix = 'msg';
5866: }
5867: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
5868: $$rowtotal += $itemcount;
5869: return $datatable;
5870: }
5871:
5872: sub trust_titles {
5873: return &Apache::lonlocal::texthash(
5874: content => "Access to this domain's content by others",
5875: shared => "Access to other domain's content by this domain",
5876: enroll => "Enrollment in this domain's courses by others",
5877: othcoau => "Co-author roles in this domain for others",
5878: coaurem => "Co-author roles for this domain's users elsewhere",
5879: domroles => "Domain roles in this domain assignable to others",
5880: catalog => "Course Catalog for this domain displayed elsewhere",
5881: reqcrs => "Requests for creation of courses in this domain by others",
5882: msg => "Users in other domains can send messages to this domain",
5883: exc => "Allow all, but exclude specific domains",
5884: inc => "Deny all, but include specific domains",
5885: );
1.275 raeburn 5886: }
5887:
1.138 raeburn 5888: sub build_location_hashes {
1.275 raeburn 5889: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 5890: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 5891: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 5892: my %iphost = &Apache::lonnet::get_iphost();
5893: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
5894: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
5895: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
5896: foreach my $id (@{$iphost{$primary_ip}}) {
5897: my $intdom = &Apache::lonnet::internet_dom($id);
5898: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
5899: push(@{$intdoms},$intdom);
5900: }
5901: }
5902: }
5903: foreach my $ip (keys(%iphost)) {
5904: if (ref($iphost{$ip}) eq 'ARRAY') {
5905: foreach my $id (@{$iphost{$ip}}) {
5906: my $location = &Apache::lonnet::internet_dom($id);
5907: if ($location) {
1.275 raeburn 5908: if (grep(/^\Q$location\E$/,@{$intdoms})) {
5909: my $dom = &Apache::lonnet::host_domain($id);
5910: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
5911: push(@{$instdoms},$dom);
5912: }
5913: next;
5914: }
1.138 raeburn 5915: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5916: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
5917: push(@{$by_ip->{$ip}},$location);
5918: }
5919: } else {
5920: $by_ip->{$ip} = [$location];
5921: }
5922: }
5923: }
5924: }
5925: }
5926: foreach my $ip (sort(keys(%{$by_ip}))) {
5927: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5928: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
5929: my $first = $by_ip->{$ip}->[0];
5930: if (ref($by_location->{$first}) eq 'ARRAY') {
5931: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
5932: push(@{$by_location->{$first}},$ip);
5933: }
5934: } else {
5935: $by_location->{$first} = [$ip];
5936: }
5937: }
5938: }
5939: return;
5940: }
5941:
1.145 raeburn 5942: sub current_offloads_to {
5943: my ($dom,$settings,$servers) = @_;
5944: my (%spareid,%otherdomconfigs);
1.152 raeburn 5945: if (ref($servers) eq 'HASH') {
1.145 raeburn 5946: foreach my $lonhost (sort(keys(%{$servers}))) {
5947: my $gotspares;
1.152 raeburn 5948: if (ref($settings) eq 'HASH') {
5949: if (ref($settings->{'spares'}) eq 'HASH') {
5950: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
5951: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
5952: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
5953: $gotspares = 1;
5954: }
1.145 raeburn 5955: }
5956: }
5957: unless ($gotspares) {
5958: my $gotspares;
5959: my $serverhomeID =
5960: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
5961: my $serverhomedom =
5962: &Apache::lonnet::host_domain($serverhomeID);
5963: if ($serverhomedom ne $dom) {
5964: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
5965: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5966: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5967: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5968: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5969: $gotspares = 1;
5970: }
5971: }
5972: } else {
5973: $otherdomconfigs{$serverhomedom} =
5974: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
5975: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
5976: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5977: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5978: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
5979: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5980: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5981: $gotspares = 1;
5982: }
5983: }
5984: }
5985: }
5986: }
5987: }
5988: }
5989: unless ($gotspares) {
5990: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
5991: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
5992: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
5993: } else {
5994: my $server_hostname = &Apache::lonnet::hostname($lonhost);
5995: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
5996: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
5997: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
5998: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
5999: } else {
1.150 raeburn 6000: my %what = (
6001: spareid => 1,
6002: );
6003: my ($result,$returnhash) =
6004: &Apache::lonnet::get_remote_globals($lonhost,\%what);
6005: if ($result eq 'ok') {
6006: if (ref($returnhash) eq 'HASH') {
6007: if (ref($returnhash->{'spareid'}) eq 'HASH') {
6008: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
6009: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
6010: }
6011: }
1.145 raeburn 6012: }
6013: }
6014: }
6015: }
6016: }
6017: }
6018: return %spareid;
6019: }
6020:
6021: sub spares_row {
1.261 raeburn 6022: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 6023: my $css_class;
6024: my $numinrow = 4;
6025: my $itemcount = 1;
6026: my $datatable;
1.152 raeburn 6027: my %typetitles = &sparestype_titles();
6028: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 6029: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 6030: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
6031: my ($othercontrol,$serverdom);
6032: if ($serverhome ne $server) {
6033: $serverdom = &Apache::lonnet::host_domain($serverhome);
6034: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6035: } else {
6036: $serverdom = &Apache::lonnet::host_domain($server);
6037: if ($serverdom ne $dom) {
6038: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6039: }
6040: }
6041: next unless (ref($spareid->{$server}) eq 'HASH');
1.261 raeburn 6042: my $checkednow;
6043: if (ref($curroffloadnow) eq 'HASH') {
6044: if ($curroffloadnow->{$server}) {
6045: $checkednow = ' checked="checked"';
6046: }
6047: }
1.145 raeburn 6048: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6049: $datatable .= '<tr'.$css_class.'>
6050: <td rowspan="2">
1.183 bisitz 6051: <span class="LC_nobreak">'.
6052: &mt('[_1] when busy, offloads to:'
1.261 raeburn 6053: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 6054: '<span class="LC_nobreak">'."\n".
1.261 raeburn 6055: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
6056: ' '.&mt('Switch active users on next access').'</label></span>'.
1.183 bisitz 6057: "\n";
1.145 raeburn 6058: my (%current,%canselect);
1.152 raeburn 6059: my @choices =
6060: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
6061: foreach my $type ('primary','default') {
6062: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 6063: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
6064: my @spares = @{$spareid->{$server}{$type}};
6065: if (@spares > 0) {
1.152 raeburn 6066: if ($othercontrol) {
6067: $current{$type} = join(', ',@spares);
6068: } else {
6069: $current{$type} .= '<table>';
6070: my $numspares = scalar(@spares);
6071: for (my $i=0; $i<@spares; $i++) {
6072: my $rem = $i%($numinrow);
6073: if ($rem == 0) {
6074: if ($i > 0) {
6075: $current{$type} .= '</tr>';
6076: }
6077: $current{$type} .= '<tr>';
1.145 raeburn 6078: }
1.152 raeburn 6079: $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'".');" /> '.
6080: $spareid->{$server}{$type}[$i].
6081: '</label></td>'."\n";
6082: }
6083: my $rem = @spares%($numinrow);
6084: my $colsleft = $numinrow - $rem;
6085: if ($colsleft > 1 ) {
6086: $current{$type} .= '<td colspan="'.$colsleft.
6087: '" class="LC_left_item">'.
6088: ' </td>';
6089: } elsif ($colsleft == 1) {
6090: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 6091: }
1.152 raeburn 6092: $current{$type} .= '</tr></table>';
1.150 raeburn 6093: }
1.145 raeburn 6094: }
6095: }
6096: if ($current{$type} eq '') {
6097: $current{$type} = &mt('None specified');
6098: }
1.152 raeburn 6099: if ($othercontrol) {
6100: if ($type eq 'primary') {
6101: $canselect{$type} = $othercontrol;
6102: }
6103: } else {
6104: $canselect{$type} =
6105: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
6106: '<select name="newspare_'.$type.'_'.$server.'" '.
6107: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
6108: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
6109: if (@choices > 0) {
6110: foreach my $lonhost (@choices) {
6111: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
6112: }
6113: }
6114: $canselect{$type} .= '</select>'."\n";
6115: }
6116: } else {
6117: $current{$type} = &mt('Could not be determined');
6118: if ($type eq 'primary') {
6119: $canselect{$type} = $othercontrol;
6120: }
1.145 raeburn 6121: }
1.152 raeburn 6122: if ($type eq 'default') {
6123: $datatable .= '<tr'.$css_class.'>';
6124: }
6125: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
6126: '<td>'.$current{$type}.'</td>'."\n".
6127: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 6128: }
6129: $itemcount ++;
6130: }
6131: }
6132: $$rowtotal += $itemcount;
6133: return $datatable;
6134: }
6135:
1.152 raeburn 6136: sub possible_newspares {
6137: my ($server,$currspares,$serverhomes,$altids) = @_;
6138: my $serverhostname = &Apache::lonnet::hostname($server);
6139: my %excluded;
6140: if ($serverhostname ne '') {
6141: %excluded = (
6142: $serverhostname => 1,
6143: );
6144: }
6145: if (ref($currspares) eq 'HASH') {
6146: foreach my $type (keys(%{$currspares})) {
6147: if (ref($currspares->{$type}) eq 'ARRAY') {
6148: if (@{$currspares->{$type}} > 0) {
6149: foreach my $curr (@{$currspares->{$type}}) {
6150: my $hostname = &Apache::lonnet::hostname($curr);
6151: $excluded{$hostname} = 1;
6152: }
6153: }
6154: }
6155: }
6156: }
6157: my @choices;
6158: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
6159: if (keys(%{$serverhomes}) > 1) {
6160: foreach my $name (sort(keys(%{$serverhomes}))) {
6161: unless ($excluded{$name}) {
6162: if (exists($altids->{$serverhomes->{$name}})) {
6163: push(@choices,$altids->{$serverhomes->{$name}});
6164: } else {
6165: push(@choices,$serverhomes->{$name});
1.145 raeburn 6166: }
6167: }
6168: }
6169: }
6170: }
1.152 raeburn 6171: return sort(@choices);
1.145 raeburn 6172: }
6173:
1.150 raeburn 6174: sub print_loadbalancing {
6175: my ($dom,$settings,$rowtotal) = @_;
6176: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6177: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6178: my $numinrow = 1;
6179: my $datatable;
6180: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 6181: my (%currbalancer,%currtargets,%currrules,%existing);
6182: if (ref($settings) eq 'HASH') {
6183: %existing = %{$settings};
6184: }
6185: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
6186: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
6187: \%currtargets,\%currrules);
1.150 raeburn 6188: } else {
6189: return;
6190: }
6191: my ($othertitle,$usertypes,$types) =
6192: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 6193: my $rownum = 8;
1.150 raeburn 6194: if (ref($types) eq 'ARRAY') {
6195: $rownum += scalar(@{$types});
6196: }
1.171 raeburn 6197: my @css_class = ('LC_odd_row','LC_even_row');
6198: my $balnum = 0;
6199: my $islast;
6200: my (@toshow,$disabledtext);
6201: if (keys(%currbalancer) > 0) {
6202: @toshow = sort(keys(%currbalancer));
6203: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
6204: push(@toshow,'');
6205: }
6206: } else {
6207: @toshow = ('');
6208: $disabledtext = &mt('No existing load balancer');
6209: }
6210: foreach my $lonhost (@toshow) {
6211: if ($balnum == scalar(@toshow)-1) {
6212: $islast = 1;
6213: } else {
6214: $islast = 0;
6215: }
6216: my $cssidx = $balnum%2;
6217: my $targets_div_style = 'display: none';
6218: my $disabled_div_style = 'display: block';
6219: my $homedom_div_style = 'display: none';
6220: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 6221: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 6222: '<p>';
6223: if ($lonhost eq '') {
1.210 raeburn 6224: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 6225: if (keys(%currbalancer) > 0) {
6226: $datatable .= &mt('Add balancer:');
6227: } else {
6228: $datatable .= &mt('Enable balancer:');
6229: }
6230: $datatable .= ' '.
6231: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
6232: ' id="loadbalancing_lonhost_'.$balnum.'"'.
6233: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
6234: '<option value="" selected="selected">'.&mt('None').
6235: '</option>'."\n";
6236: foreach my $server (sort(keys(%servers))) {
6237: next if ($currbalancer{$server});
6238: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
6239: }
1.210 raeburn 6240: $datatable .=
1.171 raeburn 6241: '</select>'."\n".
6242: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
6243: } else {
6244: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
6245: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
6246: &mt('Stop balancing').'</label>'.
6247: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
6248: $targets_div_style = 'display: block';
6249: $disabled_div_style = 'display: none';
6250: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
6251: $homedom_div_style = 'display: block';
6252: }
6253: }
1.306 raeburn 6254: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 6255: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
6256: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
6257: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
6258: my ($numspares,@spares) = &count_servers($lonhost,%servers);
6259: my @sparestypes = ('primary','default');
6260: my %typetitles = &sparestype_titles();
1.284 raeburn 6261: my %hostherechecked = (
6262: no => ' checked="checked"',
6263: );
1.171 raeburn 6264: foreach my $sparetype (@sparestypes) {
6265: my $targettable;
6266: for (my $i=0; $i<$numspares; $i++) {
6267: my $checked;
6268: if (ref($currtargets{$lonhost}) eq 'HASH') {
6269: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6270: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6271: $checked = ' checked="checked"';
6272: }
6273: }
6274: }
6275: my ($chkboxval,$disabled);
6276: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
6277: $chkboxval = $spares[$i];
6278: }
6279: if (exists($currbalancer{$spares[$i]})) {
6280: $disabled = ' disabled="disabled"';
6281: }
1.210 raeburn 6282: $targettable .=
1.253 raeburn 6283: '<td><span class="LC_nobreak"><label>'.
6284: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 6285: $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 6286: '</span></label></span></td>';
1.171 raeburn 6287: my $rem = $i%($numinrow);
6288: if ($rem == 0) {
6289: if (($i > 0) && ($i < $numspares-1)) {
6290: $targettable .= '</tr>';
6291: }
6292: if ($i < $numspares-1) {
6293: $targettable .= '<tr>';
1.150 raeburn 6294: }
6295: }
6296: }
1.171 raeburn 6297: if ($targettable ne '') {
6298: my $rem = $numspares%($numinrow);
6299: my $colsleft = $numinrow - $rem;
6300: if ($colsleft > 1 ) {
6301: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6302: ' </td>';
6303: } elsif ($colsleft == 1) {
6304: $targettable .= '<td class="LC_left_item"> </td>';
6305: }
6306: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
6307: '<table><tr>'.$targettable.'</tr></table><br />';
6308: }
1.284 raeburn 6309: $hostherechecked{$sparetype} = '';
6310: if (ref($currtargets{$lonhost}) eq 'HASH') {
6311: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6312: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6313: $hostherechecked{$sparetype} = ' checked="checked"';
6314: $hostherechecked{'no'} = '';
6315: }
6316: }
6317: }
6318: }
6319: $datatable .= &mt('Hosting on balancer itself').'<br />'.
6320: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
6321: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
6322: foreach my $sparetype (@sparestypes) {
6323: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
6324: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
6325: '</i></label><br />';
1.171 raeburn 6326: }
6327: $datatable .= '</div></td></tr>'.
6328: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
6329: $othertitle,$usertypes,$types,\%servers,
6330: \%currbalancer,$lonhost,
6331: $targets_div_style,$homedom_div_style,
6332: $css_class[$cssidx],$balnum,$islast);
6333: $$rowtotal += $rownum;
6334: $balnum ++;
6335: }
6336: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
6337: return $datatable;
6338: }
6339:
6340: sub get_loadbalancers_config {
6341: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
6342: return unless ((ref($servers) eq 'HASH') &&
6343: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
6344: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
6345: if (keys(%{$existing}) > 0) {
6346: my $oldlonhost;
6347: foreach my $key (sort(keys(%{$existing}))) {
6348: if ($key eq 'lonhost') {
6349: $oldlonhost = $existing->{'lonhost'};
6350: $currbalancer->{$oldlonhost} = 1;
6351: } elsif ($key eq 'targets') {
6352: if ($oldlonhost) {
6353: $currtargets->{$oldlonhost} = $existing->{'targets'};
6354: }
6355: } elsif ($key eq 'rules') {
6356: if ($oldlonhost) {
6357: $currrules->{$oldlonhost} = $existing->{'rules'};
6358: }
6359: } elsif (ref($existing->{$key}) eq 'HASH') {
6360: $currbalancer->{$key} = 1;
6361: $currtargets->{$key} = $existing->{$key}{'targets'};
6362: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 6363: }
6364: }
1.171 raeburn 6365: } else {
6366: my ($balancerref,$targetsref) =
6367: &Apache::lonnet::get_lonbalancer_config($servers);
6368: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
6369: foreach my $server (sort(keys(%{$balancerref}))) {
6370: $currbalancer->{$server} = 1;
6371: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 6372: }
6373: }
6374: }
1.171 raeburn 6375: return;
1.150 raeburn 6376: }
6377:
6378: sub loadbalancing_rules {
6379: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 6380: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
6381: $css_class,$balnum,$islast) = @_;
1.150 raeburn 6382: my $output;
1.171 raeburn 6383: my $num = 0;
1.210 raeburn 6384: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 6385: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
6386: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
6387: foreach my $type (@{$alltypes}) {
1.171 raeburn 6388: $num ++;
1.150 raeburn 6389: my $current;
6390: if (ref($currrules) eq 'HASH') {
6391: $current = $currrules->{$type};
6392: }
1.253 raeburn 6393: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 6394: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 6395: $current = '';
6396: }
6397: }
6398: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 6399: $servers,$currbalancer,$lonhost,$dom,
6400: $targets_div_style,$homedom_div_style,
6401: $css_class,$balnum,$num,$islast);
1.150 raeburn 6402: }
6403: }
6404: return $output;
6405: }
6406:
6407: sub loadbalancing_titles {
6408: my ($dom,$intdom,$usertypes,$types) = @_;
6409: my %othertypes = (
6410: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
6411: '_LC_author' => &mt('Users from [_1] with author role',$dom),
6412: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
6413: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 6414: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
6415: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 6416: );
1.209 raeburn 6417: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 6418: my @available;
1.150 raeburn 6419: if (ref($types) eq 'ARRAY') {
1.302 raeburn 6420: @available = @{$types};
1.150 raeburn 6421: }
1.302 raeburn 6422: unless (grep(/^default$/,@available)) {
6423: push(@available,'default');
6424: }
6425: unshift(@alltypes,@available);
1.150 raeburn 6426: my %titles;
6427: foreach my $type (@alltypes) {
6428: if ($type =~ /^_LC_/) {
6429: $titles{$type} = $othertypes{$type};
6430: } elsif ($type eq 'default') {
6431: $titles{$type} = &mt('All users from [_1]',$dom);
6432: if (ref($types) eq 'ARRAY') {
6433: if (@{$types} > 0) {
6434: $titles{$type} = &mt('Other users from [_1]',$dom);
6435: }
6436: }
6437: } elsif (ref($usertypes) eq 'HASH') {
6438: $titles{$type} = $usertypes->{$type};
6439: }
6440: }
6441: return (\@alltypes,\%othertypes,\%titles);
6442: }
6443:
6444: sub loadbalance_rule_row {
1.171 raeburn 6445: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
6446: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 6447: my @rulenames;
1.150 raeburn 6448: my %ruletitles = &offloadtype_text();
1.209 raeburn 6449: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 6450: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 6451: } else {
1.209 raeburn 6452: @rulenames = ('default','homeserver');
6453: if ($type eq '_LC_external') {
6454: push(@rulenames,'externalbalancer');
6455: } else {
6456: push(@rulenames,'specific');
6457: }
6458: push(@rulenames,'none');
1.150 raeburn 6459: }
6460: my $style = $targets_div_style;
1.253 raeburn 6461: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 6462: $style = $homedom_div_style;
6463: }
1.171 raeburn 6464: my $space;
6465: if ($islast && $num == 1) {
1.317 raeburn 6466: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 6467: }
1.210 raeburn 6468: my $output =
1.306 raeburn 6469: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 6470: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
6471: '<td valaign="top">'.$space.
6472: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 6473: for (my $i=0; $i<@rulenames; $i++) {
6474: my $rule = $rulenames[$i];
6475: my ($checked,$extra);
6476: if ($rulenames[$i] eq 'default') {
6477: $rule = '';
6478: }
6479: if ($rulenames[$i] eq 'specific') {
6480: if (ref($servers) eq 'HASH') {
6481: my $default;
6482: if (($current ne '') && (exists($servers->{$current}))) {
6483: $checked = ' checked="checked"';
6484: }
6485: unless ($checked) {
6486: $default = ' selected="selected"';
6487: }
1.210 raeburn 6488: $extra =
1.171 raeburn 6489: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
6490: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
6491: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
6492: '<option value=""'.$default.'></option>'."\n";
6493: foreach my $server (sort(keys(%{$servers}))) {
6494: if (ref($currbalancer) eq 'HASH') {
6495: next if (exists($currbalancer->{$server}));
6496: }
1.150 raeburn 6497: my $selected;
1.171 raeburn 6498: if ($server eq $current) {
1.150 raeburn 6499: $selected = ' selected="selected"';
6500: }
1.171 raeburn 6501: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 6502: }
6503: $extra .= '</select>';
6504: }
6505: } elsif ($rule eq $current) {
6506: $checked = ' checked="checked"';
6507: }
6508: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 6509: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
6510: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
6511: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 6512: ')"'.$checked.' /> ';
6513: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
6514: $output .= $ruletitles{'particular'};
6515: } else {
6516: $output .= $ruletitles{$rulenames[$i]};
6517: }
6518: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 6519: }
6520: $output .= '</div></td></tr>'."\n";
6521: return $output;
6522: }
6523:
6524: sub offloadtype_text {
6525: my %ruletitles = &Apache::lonlocal::texthash (
6526: 'default' => 'Offloads to default destinations',
6527: 'homeserver' => "Offloads to user's home server",
6528: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
6529: 'specific' => 'Offloads to specific server',
1.161 raeburn 6530: 'none' => 'No offload',
1.209 raeburn 6531: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
6532: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 6533: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 6534: );
6535: return %ruletitles;
6536: }
6537:
6538: sub sparestype_titles {
6539: my %typestitles = &Apache::lonlocal::texthash (
6540: 'primary' => 'primary',
6541: 'default' => 'default',
6542: );
6543: return %typestitles;
6544: }
6545:
1.28 raeburn 6546: sub contact_titles {
6547: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 6548: 'supportemail' => 'Support E-mail address',
6549: 'adminemail' => 'Default Server Admin E-mail address',
6550: 'errormail' => 'Error reports to be e-mailed to',
6551: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 6552: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
6553: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 6554: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
6555: 'requestsmail' => 'E-mail from course requests requiring approval',
6556: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 6557: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 6558: );
6559: my %short_titles = &Apache::lonlocal::texthash (
6560: adminemail => 'Admin E-mail address',
6561: supportemail => 'Support E-mail',
6562: );
6563: return (\%titles,\%short_titles);
6564: }
6565:
1.286 raeburn 6566: sub helpform_fields {
6567: my %titles = &Apache::lonlocal::texthash (
6568: 'username' => 'Name',
6569: 'user' => 'Username/domain',
6570: 'phone' => 'Phone',
6571: 'cc' => 'Cc e-mail',
6572: 'course' => 'Course Details',
6573: 'section' => 'Sections',
1.289 raeburn 6574: 'screenshot' => 'File upload',
1.286 raeburn 6575: );
6576: my @fields = ('username','phone','user','course','section','cc','screenshot');
6577: my %possoptions = (
6578: username => ['yes','no','req'],
1.289 raeburn 6579: phone => ['yes','no','req'],
1.286 raeburn 6580: user => ['yes','no'],
1.289 raeburn 6581: cc => ['yes','no'],
1.286 raeburn 6582: course => ['yes','no'],
6583: section => ['yes','no'],
6584: screenshot => ['yes','no'],
6585: );
6586: my %fieldoptions = &Apache::lonlocal::texthash (
6587: 'yes' => 'Optional',
6588: 'req' => 'Required',
6589: 'no' => "Not shown",
6590: );
6591: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
6592: }
6593:
1.72 raeburn 6594: sub tool_titles {
6595: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 6596: aboutme => 'Personal web page',
1.86 raeburn 6597: blog => 'Blog',
1.162 raeburn 6598: webdav => 'WebDAV',
1.86 raeburn 6599: portfolio => 'Portfolio',
1.88 bisitz 6600: official => 'Official courses (with institutional codes)',
6601: unofficial => 'Unofficial courses',
1.98 raeburn 6602: community => 'Communities',
1.216 raeburn 6603: textbook => 'Textbook courses',
1.271 raeburn 6604: placement => 'Placement tests',
1.86 raeburn 6605: );
1.72 raeburn 6606: return %titles;
6607: }
6608:
1.101 raeburn 6609: sub courserequest_titles {
6610: my %titles = &Apache::lonlocal::texthash (
6611: official => 'Official',
6612: unofficial => 'Unofficial',
6613: community => 'Communities',
1.216 raeburn 6614: textbook => 'Textbook',
1.271 raeburn 6615: placement => 'Placement tests',
1.325 raeburn 6616: lti => 'LTI Provider',
1.101 raeburn 6617: norequest => 'Not allowed',
1.325 raeburn 6618: approval => 'Approval by DC',
1.101 raeburn 6619: validate => 'With validation',
6620: autolimit => 'Numerical limit',
1.103 raeburn 6621: unlimited => '(blank for unlimited)',
1.101 raeburn 6622: );
6623: return %titles;
6624: }
6625:
1.163 raeburn 6626: sub authorrequest_titles {
6627: my %titles = &Apache::lonlocal::texthash (
6628: norequest => 'Not allowed',
6629: approval => 'Approval by Dom. Coord.',
6630: automatic => 'Automatic approval',
6631: );
6632: return %titles;
1.210 raeburn 6633: }
1.163 raeburn 6634:
1.101 raeburn 6635: sub courserequest_conditions {
6636: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 6637: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 6638: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 6639: );
6640: return %conditions;
6641: }
6642:
6643:
1.27 raeburn 6644: sub print_usercreation {
1.30 raeburn 6645: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 6646: my $numinrow = 4;
1.28 raeburn 6647: my $datatable;
6648: if ($position eq 'top') {
1.30 raeburn 6649: $$rowtotal ++;
1.34 raeburn 6650: my $rowcount = 0;
1.32 raeburn 6651: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 6652: if (ref($rules) eq 'HASH') {
6653: if (keys(%{$rules}) > 0) {
1.32 raeburn 6654: $datatable .= &user_formats_row('username',$settings,$rules,
6655: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 6656: $$rowtotal ++;
1.32 raeburn 6657: $rowcount ++;
6658: }
6659: }
6660: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
6661: if (ref($idrules) eq 'HASH') {
6662: if (keys(%{$idrules}) > 0) {
6663: $datatable .= &user_formats_row('id',$settings,$idrules,
6664: $idruleorder,$numinrow,$rowcount);
6665: $$rowtotal ++;
6666: $rowcount ++;
1.28 raeburn 6667: }
6668: }
1.39 raeburn 6669: if ($rowcount == 0) {
6670: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
6671: $$rowtotal ++;
6672: $rowcount ++;
6673: }
1.34 raeburn 6674: } elsif ($position eq 'middle') {
1.224 raeburn 6675: my @creators = ('author','course','requestcrs');
1.37 raeburn 6676: my ($rules,$ruleorder) =
6677: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 6678: my %lt = &usercreation_types();
6679: my %checked;
6680: if (ref($settings) eq 'HASH') {
6681: if (ref($settings->{'cancreate'}) eq 'HASH') {
6682: foreach my $item (@creators) {
6683: $checked{$item} = $settings->{'cancreate'}{$item};
6684: }
6685: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
6686: foreach my $item (@creators) {
6687: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
6688: $checked{$item} = 'none';
6689: }
6690: }
6691: }
6692: }
6693: my $rownum = 0;
6694: foreach my $item (@creators) {
6695: $rownum ++;
1.224 raeburn 6696: if ($checked{$item} eq '') {
6697: $checked{$item} = 'any';
1.34 raeburn 6698: }
6699: my $css_class;
6700: if ($rownum%2) {
6701: $css_class = '';
6702: } else {
6703: $css_class = ' class="LC_odd_row" ';
6704: }
6705: $datatable .= '<tr'.$css_class.'>'.
6706: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 6707: '</span></td><td style="text-align: right">';
1.224 raeburn 6708: my @options = ('any');
6709: if (ref($rules) eq 'HASH') {
6710: if (keys(%{$rules}) > 0) {
6711: push(@options,('official','unofficial'));
1.37 raeburn 6712: }
6713: }
1.224 raeburn 6714: push(@options,'none');
1.37 raeburn 6715: foreach my $option (@options) {
1.50 raeburn 6716: my $type = 'radio';
1.34 raeburn 6717: my $check = ' ';
1.224 raeburn 6718: if ($checked{$item} eq $option) {
6719: $check = ' checked="checked" ';
1.34 raeburn 6720: }
6721: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 6722: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 6723: $item.'" value="'.$option.'"'.$check.'/> '.
6724: $lt{$option}.'</label> </span>';
6725: }
6726: $datatable .= '</td></tr>';
6727: }
1.28 raeburn 6728: } else {
6729: my @contexts = ('author','course','domain');
1.325 raeburn 6730: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 6731: my %checked;
6732: if (ref($settings) eq 'HASH') {
6733: if (ref($settings->{'authtypes'}) eq 'HASH') {
6734: foreach my $item (@contexts) {
6735: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
6736: foreach my $auth (@authtypes) {
6737: if ($settings->{'authtypes'}{$item}{$auth}) {
6738: $checked{$item}{$auth} = ' checked="checked" ';
6739: }
6740: }
6741: }
6742: }
1.27 raeburn 6743: }
1.35 raeburn 6744: } else {
6745: foreach my $item (@contexts) {
1.36 raeburn 6746: foreach my $auth (@authtypes) {
1.35 raeburn 6747: $checked{$item}{$auth} = ' checked="checked" ';
6748: }
6749: }
1.27 raeburn 6750: }
1.28 raeburn 6751: my %title = &context_names();
6752: my %authname = &authtype_names();
6753: my $rownum = 0;
6754: my $css_class;
6755: foreach my $item (@contexts) {
6756: if ($rownum%2) {
6757: $css_class = '';
6758: } else {
6759: $css_class = ' class="LC_odd_row" ';
6760: }
1.30 raeburn 6761: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 6762: '<td>'.$title{$item}.
6763: '</td><td class="LC_left_item">'.
6764: '<span class="LC_nobreak">';
6765: foreach my $auth (@authtypes) {
6766: $datatable .= '<label>'.
6767: '<input type="checkbox" name="'.$item.'_auth" '.
6768: $checked{$item}{$auth}.' value="'.$auth.'" />'.
6769: $authname{$auth}.'</label> ';
6770: }
6771: $datatable .= '</span></td></tr>';
6772: $rownum ++;
1.27 raeburn 6773: }
1.30 raeburn 6774: $$rowtotal += $rownum;
1.27 raeburn 6775: }
6776: return $datatable;
6777: }
6778:
1.224 raeburn 6779: sub print_selfcreation {
6780: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 6781: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
6782: $emaildomain,$datatable);
1.224 raeburn 6783: if (ref($settings) eq 'HASH') {
6784: if (ref($settings->{'cancreate'}) eq 'HASH') {
6785: $createsettings = $settings->{'cancreate'};
1.236 raeburn 6786: if (ref($createsettings) eq 'HASH') {
6787: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
6788: @selfcreate = @{$createsettings->{'selfcreate'}};
6789: } elsif ($createsettings->{'selfcreate'} ne '') {
6790: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
6791: @selfcreate = ('email','login','sso');
6792: } elsif ($createsettings->{'selfcreate'} ne 'none') {
6793: @selfcreate = ($createsettings->{'selfcreate'});
6794: }
6795: }
6796: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
6797: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 6798: }
1.305 raeburn 6799: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
6800: $emailoptions = $createsettings->{'emailoptions'};
6801: }
1.303 raeburn 6802: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
6803: $emailverified = $createsettings->{'emailverified'};
6804: }
6805: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
6806: $emaildomain = $createsettings->{'emaildomain'};
6807: }
1.224 raeburn 6808: }
6809: }
6810: }
6811: my %radiohash;
6812: my $numinrow = 4;
6813: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 6814: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 6815: if ($position eq 'top') {
6816: my %choices = &Apache::lonlocal::texthash (
6817: cancreate_login => 'Institutional Login',
6818: cancreate_sso => 'Institutional Single Sign On',
6819: );
6820: my @toggles = sort(keys(%choices));
6821: my %defaultchecked = (
6822: 'cancreate_login' => 'off',
6823: 'cancreate_sso' => 'off',
6824: );
1.228 raeburn 6825: my ($onclick,$itemcount);
1.224 raeburn 6826: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6827: \%choices,$itemcount,$onclick);
1.228 raeburn 6828: $$rowtotal += $itemcount;
6829:
1.224 raeburn 6830: if (ref($usertypes) eq 'HASH') {
6831: if (keys(%{$usertypes}) > 0) {
6832: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
6833: $dom,$numinrow,$othertitle,
1.305 raeburn 6834: 'statustocreate',$rowtotal);
1.224 raeburn 6835: $$rowtotal ++;
6836: }
6837: }
1.240 raeburn 6838: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
6839: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6840: $fieldtitles{'inststatus'} = &mt('Institutional status');
6841: my $rem;
6842: my $numperrow = 2;
6843: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
6844: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 6845: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 6846: '<td class="LC_left_item">'."\n".
6847: '<table><tr><td>'."\n";
6848: for (my $i=0; $i<@fields; $i++) {
6849: $rem = $i%($numperrow);
6850: if ($rem == 0) {
6851: if ($i > 0) {
6852: $datatable .= '</tr>';
6853: }
6854: $datatable .= '<tr>';
6855: }
6856: my $currval;
1.248 raeburn 6857: if (ref($createsettings) eq 'HASH') {
6858: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
6859: $currval = $createsettings->{'shibenv'}{$fields[$i]};
6860: }
1.240 raeburn 6861: }
6862: $datatable .= '<td class="LC_left_item">'.
6863: '<span class="LC_nobreak">'.
6864: '<input type="text" name="shibenv_'.$fields[$i].'" '.
6865: 'value="'.$currval.'" size="10" /> '.
6866: $fieldtitles{$fields[$i]}.'</span></td>';
6867: }
6868: my $colsleft = $numperrow - $rem;
6869: if ($colsleft > 1 ) {
6870: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6871: ' </td>';
6872: } elsif ($colsleft == 1) {
6873: $datatable .= '<td class="LC_left_item"> </td>';
6874: }
6875: $datatable .= '</tr></table></td></tr>';
6876: $$rowtotal ++;
1.224 raeburn 6877: } elsif ($position eq 'middle') {
6878: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 6879: my @posstypes;
1.224 raeburn 6880: if (ref($types) eq 'ARRAY') {
1.302 raeburn 6881: @posstypes = @{$types};
6882: }
6883: unless (grep(/^default$/,@posstypes)) {
6884: push(@posstypes,'default');
6885: }
6886: my %usertypeshash;
6887: if (ref($usertypes) eq 'HASH') {
6888: %usertypeshash = %{$usertypes};
6889: }
6890: $usertypeshash{'default'} = $othertitle;
6891: foreach my $status (@posstypes) {
6892: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
6893: $numinrow,$$rowtotal,\%usertypeshash);
6894: $$rowtotal ++;
1.224 raeburn 6895: }
6896: } else {
1.236 raeburn 6897: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 6898: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 6899: );
6900: my @toggles = sort(keys(%choices));
6901: my %defaultchecked = (
6902: 'cancreate_email' => 'off',
6903: );
1.305 raeburn 6904: my $customclass = 'LC_selfcreate_email';
6905: my $classprefix = 'LC_canmodify_emailusername_';
6906: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 6907: my $display = 'none';
1.305 raeburn 6908: my $rowstyle = 'display:none';
1.236 raeburn 6909: if (grep(/^\Qemail\E$/,@selfcreate)) {
6910: $display = 'block';
1.305 raeburn 6911: $rowstyle = 'display:table-row';
1.236 raeburn 6912: }
1.305 raeburn 6913: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
6914: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6915: \%choices,$$rowtotal,$onclick);
6916: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
6917: $rowstyle);
6918: $$rowtotal ++;
6919: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
6920: $rowstyle);
6921: $$rowtotal ++;
6922: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 6923: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 6924: my ($emailrules,$emailruleorder) =
6925: &Apache::lonnet::inst_userrules($dom,'email');
6926: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6927: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6928: if (ref($types) eq 'ARRAY') {
6929: @posstypes = @{$types};
6930: }
6931: if (@posstypes) {
6932: unless (grep(/^default$/,@posstypes)) {
6933: push(@posstypes,'default');
1.302 raeburn 6934: }
6935: if (ref($usertypes) eq 'HASH') {
6936: %usertypeshash = %{$usertypes};
6937: }
1.305 raeburn 6938: my $currassign;
6939: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
6940: $currassign = {
6941: selfassign => $domdefaults{'inststatusguest'},
6942: };
6943: @ordered = @{$domdefaults{'inststatusguest'}};
6944: } else {
6945: $currassign = { selfassign => [] };
6946: }
6947: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
6948: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
6949: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
6950: $numinrow,$othertitle,'selfassign',
6951: $rowtotal,$onclicktypes,$customclass,
6952: $rowstyle);
6953: $$rowtotal ++;
1.302 raeburn 6954: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 6955: foreach my $status (@posstypes) {
6956: my $css_class;
6957: if ($$rowtotal%2) {
6958: $css_class = 'LC_odd_row ';
6959: }
6960: $css_class .= $customclass;
6961: my $rowid = $optionsprefix.$status;
6962: my $hidden = 1;
6963: my $currstyle = 'display:none';
6964: if (grep(/^\Q$status\E$/,@ordered)) {
6965: $currstyle = $rowstyle;
6966: $hidden = 0;
6967: }
6968: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
6969: $emailrules,$emailruleorder,$settings,$status,$rowid,
6970: $usertypeshash{$status},$css_class,$currstyle,$intdom);
6971: unless ($hidden) {
6972: $$rowtotal ++;
6973: }
1.224 raeburn 6974: }
1.302 raeburn 6975: } else {
1.305 raeburn 6976: my $css_class;
6977: if ($$rowtotal%2) {
6978: $css_class = 'LC_odd_row ';
6979: }
6980: $css_class .= $customclass;
1.302 raeburn 6981: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 6982: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
6983: $emailrules,$emailruleorder,$settings,'default','',
6984: $othertitle,$css_class,$rowstyle,$intdom);
6985: $$rowtotal ++;
1.224 raeburn 6986: }
6987: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 6988: $numinrow = 1;
1.305 raeburn 6989: if (@posstypes) {
6990: foreach my $status (@posstypes) {
6991: my $rowid = $classprefix.$status;
6992: my $datarowstyle = 'display:none';
6993: if (grep(/^\Q$status\E$/,@ordered)) {
6994: $datarowstyle = $rowstyle;
6995: }
6996: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
6997: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
6998: $infotitles,$rowid,$customclass,$datarowstyle);
6999: unless ($datarowstyle eq 'display:none') {
7000: $$rowtotal ++;
7001: }
1.224 raeburn 7002: }
1.305 raeburn 7003: } else {
7004: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
7005: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7006: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 7007: }
7008: }
7009: return $datatable;
7010: }
7011:
1.305 raeburn 7012: sub selfcreate_javascript {
7013: return <<"ENDSCRIPT";
7014:
7015: <script type="text/javascript">
7016: // <![CDATA[
7017:
7018: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
7019: var x = document.getElementsByClassName(target);
7020: var insttypes = 0;
7021: var insttypeRegExp = new RegExp(prefix);
7022: if ((x.length != undefined) && (x.length > 0)) {
7023: if (form.elements[radio].length != undefined) {
7024: for (var i=0; i<form.elements[radio].length; i++) {
7025: if (form.elements[radio][i].checked) {
7026: if (form.elements[radio][i].value == 1) {
7027: for (var j=0; j<x.length; j++) {
7028: if (x[j].id == 'undefined') {
7029: x[j].style.display = 'table-row';
7030: } else if (insttypeRegExp.test(x[j].id)) {
7031: insttypes ++;
7032: } else {
7033: x[j].style.display = 'table-row';
7034: }
7035: }
7036: } else {
7037: for (var j=0; j<x.length; j++) {
7038: x[j].style.display = 'none';
7039: }
1.236 raeburn 7040: }
1.305 raeburn 7041: break;
7042: }
7043: }
7044: if (insttypes > 0) {
7045: toggleDataRow(form,checkbox,target,altprefix);
7046: toggleDataRow(form,checkbox,target,prefix,1);
7047: }
7048: }
7049: }
7050: return;
7051: }
7052:
7053: function toggleDataRow(form,checkbox,target,prefix,docount) {
7054: if (form.elements[checkbox].length != undefined) {
7055: var count = 0;
7056: if (docount) {
7057: for (var i=0; i<form.elements[checkbox].length; i++) {
7058: if (form.elements[checkbox][i].checked) {
7059: count ++;
1.236 raeburn 7060: }
1.305 raeburn 7061: }
7062: }
7063: for (var i=0; i<form.elements[checkbox].length; i++) {
7064: var type = form.elements[checkbox][i].value;
7065: if (document.getElementById(prefix+type)) {
7066: if (form.elements[checkbox][i].checked) {
7067: document.getElementById(prefix+type).style.display = 'table-row';
7068: if (count % 2 == 1) {
7069: document.getElementById(prefix+type).className = target+' LC_odd_row';
7070: } else {
7071: document.getElementById(prefix+type).className = target;
1.236 raeburn 7072: }
1.305 raeburn 7073: count ++;
1.236 raeburn 7074: } else {
1.305 raeburn 7075: document.getElementById(prefix+type).style.display = 'none';
7076: }
7077: }
7078: }
7079: }
7080: return;
7081: }
7082:
7083: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
7084: var caller = radio+'_'+status;
7085: if (form.elements[caller].length != undefined) {
7086: for (var i=0; i<form.elements[caller].length; i++) {
7087: if (form.elements[caller][i].checked) {
7088: if (document.getElementById(altprefix+'_inst_'+status)) {
7089: var curr = form.elements[caller][i].value;
7090: if (prefix) {
7091: document.getElementById(prefix+'_'+status).style.display = 'none';
7092: }
7093: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
7094: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
7095: if (curr == 'custom') {
7096: if (prefix) {
7097: document.getElementById(prefix+'_'+status).style.display = 'inline';
7098: }
7099: } else if (curr == 'inst') {
7100: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
7101: } else if (curr == 'noninst') {
7102: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 7103: }
1.305 raeburn 7104: break;
1.236 raeburn 7105: }
7106: }
7107: }
7108: }
7109: }
7110:
1.305 raeburn 7111: // ]]>
7112: </script>
7113:
7114: ENDSCRIPT
7115: }
7116:
7117: sub noninst_users {
7118: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
7119: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
7120: my $class = 'LC_left_item';
7121: if ($css_class) {
7122: $css_class = ' class="'.$css_class.'"';
7123: }
7124: if ($rowid) {
7125: $rowid = ' id="'.$rowid.'"';
7126: }
7127: if ($rowstyle) {
7128: $rowstyle = ' style="'.$rowstyle.'"';
7129: }
7130: my ($output,$description);
7131: if ($type eq 'default') {
7132: $description = &mt('Requests for: [_1]',$typetitle);
7133: } else {
7134: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
7135: }
7136: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
7137: "<td>$description</td>\n".
7138: '<td class="'.$class.'" colspan="2">'.
7139: '<table><tr>';
7140: my %headers = &Apache::lonlocal::texthash(
7141: approve => 'Processing',
7142: email => 'E-mail',
7143: username => 'Username',
7144: );
7145: foreach my $item ('approve','email','username') {
7146: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 7147: }
1.305 raeburn 7148: $output .= '</tr><tr>';
7149: foreach my $item ('approve','email','username') {
1.306 raeburn 7150: $output .= '<td style="vertical-align: top">';
1.305 raeburn 7151: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
7152: if ($item eq 'approve') {
7153: %choices = &Apache::lonlocal::texthash (
7154: automatic => 'Automatically approved',
7155: approval => 'Queued for approval',
7156: );
7157: @options = ('automatic','approval');
7158: $hashref = $processing;
7159: $defoption = 'automatic';
7160: $name = 'cancreate_emailprocess_'.$type;
7161: } elsif ($item eq 'email') {
7162: %choices = &Apache::lonlocal::texthash (
7163: any => 'Any e-mail',
7164: inst => 'Institutional only',
7165: noninst => 'Non-institutional only',
7166: custom => 'Custom restrictions',
7167: );
7168: @options = ('any','inst','noninst');
7169: my $showcustom;
7170: if (ref($emailrules) eq 'HASH') {
7171: if (keys(%{$emailrules}) > 0) {
7172: push(@options,'custom');
7173: $showcustom = 'cancreate_emailrule';
7174: if (ref($settings) eq 'HASH') {
7175: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
7176: foreach my $rule (@{$settings->{'email_rule'}}) {
7177: if (exists($emailrules->{$rule})) {
7178: $hascustom ++;
7179: }
7180: }
7181: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
7182: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
7183: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
7184: if (exists($emailrules->{$rule})) {
7185: $hascustom ++;
7186: }
7187: }
7188: }
7189: }
7190: }
7191: }
7192: }
7193: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
7194: "'cancreate_emaildomain','$type'".');"';
7195: $hashref = $emailoptions;
7196: $defoption = 'any';
7197: $name = 'cancreate_emailoptions_'.$type;
7198: } elsif ($item eq 'username') {
7199: %choices = &Apache::lonlocal::texthash (
7200: all => 'Same as e-mail',
7201: first => 'Omit @domain',
7202: free => 'Free to choose',
7203: );
7204: @options = ('all','first','free');
7205: $hashref = $emailverified;
7206: $defoption = 'all';
7207: $name = 'cancreate_usernameoptions_'.$type;
7208: }
7209: foreach my $option (@options) {
7210: my $checked;
7211: if (ref($hashref) eq 'HASH') {
7212: if ($type eq '') {
7213: if (!exists($hashref->{'default'})) {
7214: if ($option eq $defoption) {
7215: $checked = ' checked="checked"';
7216: }
7217: } else {
7218: if ($hashref->{'default'} eq $option) {
7219: $checked = ' checked="checked"';
7220: }
1.303 raeburn 7221: }
7222: } else {
1.305 raeburn 7223: if (!exists($hashref->{$type})) {
7224: if ($option eq $defoption) {
7225: $checked = ' checked="checked"';
7226: }
7227: } else {
7228: if ($hashref->{$type} eq $option) {
7229: $checked = ' checked="checked"';
7230: }
1.303 raeburn 7231: }
7232: }
1.305 raeburn 7233: } elsif (($item eq 'email') && ($hascustom)) {
7234: if ($option eq 'custom') {
7235: $checked = ' checked="checked"';
7236: }
7237: } elsif ($option eq $defoption) {
7238: $checked = ' checked="checked"';
7239: }
7240: $output .= '<span class="LC_nobreak"><label>'.
7241: '<input type="radio" name="'.$name.'"'.
7242: $checked.' value="'.$option.'"'.$onclick.' />'.
7243: $choices{$option}.'</label></span><br />';
7244: if ($item eq 'email') {
7245: if ($option eq 'custom') {
7246: my $id = 'cancreate_emailrule_'.$type;
7247: my $display = 'none';
7248: if ($checked) {
7249: $display = 'inline';
1.303 raeburn 7250: }
1.305 raeburn 7251: my $numinrow = 2;
7252: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
7253: '<legend>'.&mt('Disallow').'</legend><table>'.
7254: &user_formats_row('email',$settings,$emailrules,
7255: $emailruleorder,$numinrow,'',$type);
7256: '</table></fieldset>';
7257: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
7258: my %text = &Apache::lonlocal::texthash (
7259: inst => 'must end:',
7260: noninst => 'cannot end:',
7261: );
7262: my $value;
7263: if (ref($emaildomain) eq 'HASH') {
7264: if (ref($emaildomain->{$type}) eq 'HASH') {
7265: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 7266: }
7267: }
1.305 raeburn 7268: if ($value eq '') {
7269: $value = '@'.$intdom;
7270: }
7271: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
7272: my $display = 'none';
7273: if ($checked) {
7274: $display = 'inline';
7275: }
7276: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
7277: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
7278: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
7279: '</div>';
1.303 raeburn 7280: }
7281: }
7282: }
1.305 raeburn 7283: $output .= '</td>'."\n";
1.303 raeburn 7284: }
1.305 raeburn 7285: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 7286: return $output;
7287: }
7288:
1.165 raeburn 7289: sub captcha_choice {
1.305 raeburn 7290: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 7291: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
7292: $vertext,$currver);
1.165 raeburn 7293: my %lt = &captcha_phrases();
7294: $keyentry = 'hidden';
7295: if ($context eq 'cancreate') {
1.224 raeburn 7296: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 7297: } elsif ($context eq 'login') {
7298: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 7299: }
7300: if (ref($settings) eq 'HASH') {
7301: if ($settings->{'captcha'}) {
7302: $checked{$settings->{'captcha'}} = ' checked="checked"';
7303: } else {
7304: $checked{'original'} = ' checked="checked"';
7305: }
7306: if ($settings->{'captcha'} eq 'recaptcha') {
7307: $pubtext = $lt{'pub'};
7308: $privtext = $lt{'priv'};
7309: $keyentry = 'text';
1.269 raeburn 7310: $vertext = $lt{'ver'};
7311: $currver = $settings->{'recaptchaversion'};
7312: if ($currver ne '2') {
7313: $currver = 1;
7314: }
1.165 raeburn 7315: }
7316: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
7317: $currpub = $settings->{'recaptchakeys'}{'public'};
7318: $currpriv = $settings->{'recaptchakeys'}{'private'};
7319: }
7320: } else {
7321: $checked{'original'} = ' checked="checked"';
7322: }
1.305 raeburn 7323: my $css_class;
7324: if ($itemcount%2) {
7325: $css_class = 'LC_odd_row';
7326: }
7327: if ($customcss) {
7328: $css_class .= " $customcss";
7329: }
7330: $css_class =~ s/^\s+//;
7331: if ($css_class) {
7332: $css_class = ' class="'.$css_class.'"';
7333: }
7334: if ($rowstyle) {
7335: $css_class .= ' style="'.$rowstyle.'"';
7336: }
1.169 raeburn 7337: my $output = '<tr'.$css_class.'>'.
7338: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 7339: '<table><tr><td>'."\n";
7340: foreach my $option ('original','recaptcha','notused') {
7341: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
7342: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
7343: $lt{$option}.'</label></span>';
7344: unless ($option eq 'notused') {
7345: $output .= (' 'x2)."\n";
7346: }
7347: }
7348: #
7349: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
7350: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 7351: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 7352: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 7353: #
1.165 raeburn 7354: $output .= '</td></tr>'."\n".
1.305 raeburn 7355: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 7356: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
7357: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
7358: $currpub.'" size="40" /></span><br />'."\n".
7359: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
7360: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 7361: $currpriv.'" size="40" /></span><br />'.
7362: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
7363: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
7364: $currver.'" size="3" /></span><br />'.
7365: '</td></tr></table>'."\n".
1.165 raeburn 7366: '</td></tr>';
7367: return $output;
7368: }
7369:
1.32 raeburn 7370: sub user_formats_row {
1.305 raeburn 7371: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 7372: my $output;
7373: my %text = (
7374: 'username' => 'new usernames',
7375: 'id' => 'IDs',
7376: );
1.305 raeburn 7377: unless ($type eq 'email') {
7378: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
7379: $output = '<tr '.$css_class.'>'.
7380: '<td><span class="LC_nobreak">'.
7381: &mt("Format rules to check for $text{$type}: ").
7382: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 7383: }
1.27 raeburn 7384: my $rem;
7385: if (ref($ruleorder) eq 'ARRAY') {
7386: for (my $i=0; $i<@{$ruleorder}; $i++) {
7387: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
7388: my $rem = $i%($numinrow);
7389: if ($rem == 0) {
7390: if ($i > 0) {
7391: $output .= '</tr>';
7392: }
7393: $output .= '<tr>';
7394: }
7395: my $check = ' ';
1.39 raeburn 7396: if (ref($settings) eq 'HASH') {
7397: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
7398: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
7399: $check = ' checked="checked" ';
7400: }
1.305 raeburn 7401: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
7402: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
7403: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
7404: $check = ' checked="checked" ';
7405: }
7406: }
1.27 raeburn 7407: }
7408: }
1.305 raeburn 7409: my $name = $type.'_rule';
7410: if ($type eq 'email') {
7411: $name .= '_'.$status;
7412: }
1.27 raeburn 7413: $output .= '<td class="LC_left_item">'.
7414: '<span class="LC_nobreak"><label>'.
1.311 raeburn 7415: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 7416: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
7417: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
7418: }
7419: }
7420: $rem = @{$ruleorder}%($numinrow);
7421: }
1.305 raeburn 7422: my $colsleft;
7423: if ($rem) {
7424: $colsleft = $numinrow - $rem;
7425: }
1.27 raeburn 7426: if ($colsleft > 1 ) {
7427: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7428: ' </td>';
7429: } elsif ($colsleft == 1) {
7430: $output .= '<td class="LC_left_item"> </td>';
7431: }
1.305 raeburn 7432: $output .= '</tr></table>';
7433: unless ($type eq 'email') {
7434: $output .= '</td></tr>';
7435: }
1.27 raeburn 7436: return $output;
7437: }
7438:
1.34 raeburn 7439: sub usercreation_types {
7440: my %lt = &Apache::lonlocal::texthash (
7441: author => 'When adding a co-author',
7442: course => 'When adding a user to a course',
1.100 raeburn 7443: requestcrs => 'When requesting a course',
1.34 raeburn 7444: any => 'Any',
7445: official => 'Institutional only ',
7446: unofficial => 'Non-institutional only',
7447: none => 'None',
7448: );
7449: return %lt;
1.48 raeburn 7450: }
1.34 raeburn 7451:
1.224 raeburn 7452: sub selfcreation_types {
7453: my %lt = &Apache::lonlocal::texthash (
7454: selfcreate => 'User creates own account',
7455: any => 'Any',
7456: official => 'Institutional only ',
7457: unofficial => 'Non-institutional only',
7458: email => 'E-mail address',
7459: login => 'Institutional Login',
7460: sso => 'SSO',
7461: );
7462: }
7463:
1.28 raeburn 7464: sub authtype_names {
7465: my %lt = &Apache::lonlocal::texthash(
7466: int => 'Internal',
7467: krb4 => 'Kerberos 4',
7468: krb5 => 'Kerberos 5',
7469: loc => 'Local',
1.325 raeburn 7470: lti => 'LTI',
1.28 raeburn 7471: );
7472: return %lt;
7473: }
7474:
7475: sub context_names {
7476: my %context_title = &Apache::lonlocal::texthash(
7477: author => 'Creating users when an Author',
7478: course => 'Creating users when in a course',
7479: domain => 'Creating users when a Domain Coordinator',
7480: );
7481: return %context_title;
7482: }
7483:
1.33 raeburn 7484: sub print_usermodification {
7485: my ($position,$dom,$settings,$rowtotal) = @_;
7486: my $numinrow = 4;
7487: my ($context,$datatable,$rowcount);
7488: if ($position eq 'top') {
7489: $rowcount = 0;
7490: $context = 'author';
7491: foreach my $role ('ca','aa') {
7492: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7493: $numinrow,$rowcount);
7494: $$rowtotal ++;
7495: $rowcount ++;
7496: }
1.230 raeburn 7497: } elsif ($position eq 'bottom') {
1.33 raeburn 7498: $context = 'course';
7499: $rowcount = 0;
7500: foreach my $role ('st','ep','ta','in','cr') {
7501: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7502: $numinrow,$rowcount);
7503: $$rowtotal ++;
7504: $rowcount ++;
7505: }
7506: }
7507: return $datatable;
7508: }
7509:
1.43 raeburn 7510: sub print_defaults {
1.236 raeburn 7511: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 7512: my $rownum = 0;
1.294 raeburn 7513: my ($datatable,$css_class,$titles);
7514: unless ($position eq 'bottom') {
7515: $titles = &defaults_titles($dom);
7516: }
1.236 raeburn 7517: if ($position eq 'top') {
7518: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
7519: 'datelocale_def','portal_def');
7520: my %defaults;
7521: if (ref($settings) eq 'HASH') {
7522: %defaults = %{$settings};
1.43 raeburn 7523: } else {
1.236 raeburn 7524: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
7525: foreach my $item (@items) {
7526: $defaults{$item} = $domdefaults{$item};
7527: }
1.43 raeburn 7528: }
1.236 raeburn 7529: foreach my $item (@items) {
7530: if ($rownum%2) {
7531: $css_class = '';
7532: } else {
7533: $css_class = ' class="LC_odd_row" ';
7534: }
7535: $datatable .= '<tr'.$css_class.'>'.
7536: '<td><span class="LC_nobreak">'.$titles->{$item}.
7537: '</span></td><td class="LC_right_item" colspan="3">';
7538: if ($item eq 'auth_def') {
1.325 raeburn 7539: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 7540: my %shortauth = (
7541: internal => 'int',
7542: krb4 => 'krb4',
7543: krb5 => 'krb5',
1.325 raeburn 7544: localauth => 'loc',
7545: lti => 'lti',
1.236 raeburn 7546: );
7547: my %authnames = &authtype_names();
7548: foreach my $auth (@authtypes) {
7549: my $checked = ' ';
7550: if ($defaults{$item} eq $auth) {
7551: $checked = ' checked="checked" ';
7552: }
7553: $datatable .= '<label><input type="radio" name="'.$item.
7554: '" value="'.$auth.'"'.$checked.'/>'.
7555: $authnames{$shortauth{$auth}}.'</label> ';
7556: }
7557: } elsif ($item eq 'timezone_def') {
7558: my $includeempty = 1;
7559: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
7560: } elsif ($item eq 'datelocale_def') {
7561: my $includeempty = 1;
7562: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
7563: } elsif ($item eq 'lang_def') {
1.263 raeburn 7564: my $includeempty = 1;
7565: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 7566: } else {
7567: my $size;
7568: if ($item eq 'portal_def') {
7569: $size = ' size="25"';
7570: }
7571: $datatable .= '<input type="text" name="'.$item.'" value="'.
7572: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 7573: }
1.236 raeburn 7574: $datatable .= '</td></tr>';
7575: $rownum ++;
7576: }
1.294 raeburn 7577: } elsif ($position eq 'middle') {
7578: my @items = ('intauth_cost','intauth_check','intauth_switch');
7579: my %defaults;
7580: if (ref($settings) eq 'HASH') {
7581: %defaults = %{$settings};
7582: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
7583: $defaults{'intauth_cost'} = 10;
7584: }
7585: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
7586: $defaults{'intauth_check'} = 0;
7587: }
7588: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
7589: $defaults{'intauth_switch'} = 0;
7590: }
7591: } else {
7592: %defaults = (
7593: 'intauth_cost' => 10,
7594: 'intauth_check' => 0,
7595: 'intauth_switch' => 0,
7596: );
7597: }
7598: foreach my $item (@items) {
7599: if ($rownum%2) {
7600: $css_class = '';
7601: } else {
7602: $css_class = ' class="LC_odd_row" ';
7603: }
7604: $datatable .= '<tr'.$css_class.'>'.
7605: '<td><span class="LC_nobreak">'.$titles->{$item}.
7606: '</span></td><td class="LC_left_item" colspan="3">';
7607: if ($item eq 'intauth_switch') {
7608: my @options = (0,1,2);
7609: my %optiondesc = &Apache::lonlocal::texthash (
7610: 0 => 'No',
7611: 1 => 'Yes',
7612: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
7613: );
7614: $datatable .= '<table width="100%">';
7615: foreach my $option (@options) {
7616: my $checked = ' ';
7617: if ($defaults{$item} eq $option) {
7618: $checked = ' checked="checked"';
7619: }
7620: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7621: '<label><input type="radio" name="'.$item.
7622: '" value="'.$option.'"'.$checked.' />'.
7623: $optiondesc{$option}.'</label></span></td></tr>';
7624: }
7625: $datatable .= '</table>';
7626: } elsif ($item eq 'intauth_check') {
7627: my @options = (0,1,2);
7628: my %optiondesc = &Apache::lonlocal::texthash (
7629: 0 => 'No',
7630: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
7631: 2 => 'Yes, disallow login if stored cost is less than domain default',
7632: );
1.332 ! raeburn 7633: $datatable .= '<table width="100%">';
1.294 raeburn 7634: foreach my $option (@options) {
7635: my $checked = ' ';
7636: my $onclick;
7637: if ($defaults{$item} eq $option) {
7638: $checked = ' checked="checked"';
7639: }
7640: if ($option == 2) {
7641: $onclick = ' onclick="javascript:warnIntAuth(this);"';
7642: }
7643: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7644: '<label><input type="radio" name="'.$item.
7645: '" value="'.$option.'"'.$checked.$onclick.' />'.
7646: $optiondesc{$option}.'</label></span></td></tr>';
7647: }
7648: $datatable .= '</table>';
7649: } else {
7650: $datatable .= '<input type="text" name="'.$item.'" value="'.
7651: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
7652: }
7653: $datatable .= '</td></tr>';
7654: $rownum ++;
7655: }
1.236 raeburn 7656: } else {
1.294 raeburn 7657: my %defaults;
1.236 raeburn 7658: if (ref($settings) eq 'HASH') {
1.305 raeburn 7659: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.236 raeburn 7660: my $maxnum = @{$settings->{'inststatusorder'}};
7661: for (my $i=0; $i<$maxnum; $i++) {
7662: $css_class = $rownum%2?' class="LC_odd_row"':'';
7663: my $item = $settings->{'inststatusorder'}->[$i];
7664: my $title = $settings->{'inststatustypes'}->{$item};
7665: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
7666: $datatable .= '<tr'.$css_class.'>'.
7667: '<td><span class="LC_nobreak">'.
7668: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
7669: for (my $k=0; $k<=$maxnum; $k++) {
7670: my $vpos = $k+1;
7671: my $selstr;
7672: if ($k == $i) {
7673: $selstr = ' selected="selected" ';
7674: }
7675: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7676: }
7677: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
7678: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
7679: &mt('delete').'</span></td>'.
1.305 raeburn 7680: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed:').
1.236 raeburn 7681: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.305 raeburn 7682: '</span></td></tr>';
1.236 raeburn 7683: }
7684: $css_class = $rownum%2?' class="LC_odd_row"':'';
7685: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
7686: $datatable .= '<tr '.$css_class.'>'.
7687: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
7688: for (my $k=0; $k<=$maxnum; $k++) {
7689: my $vpos = $k+1;
7690: my $selstr;
7691: if ($k == $maxnum) {
7692: $selstr = ' selected="selected" ';
7693: }
7694: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7695: }
7696: $datatable .= '</select> '.&mt('Internal ID:').
1.263 raeburn 7697: '<input type="text" size="10" name="addinststatus" value="" />'.
1.236 raeburn 7698: ' '.&mt('(new)').
1.305 raeburn 7699: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.236 raeburn 7700: &mt('Name displayed:').
7701: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
7702: '</tr>'."\n";
7703: $rownum ++;
1.141 raeburn 7704: }
1.43 raeburn 7705: }
7706: }
7707: $$rowtotal += $rownum;
7708: return $datatable;
7709: }
7710:
1.168 raeburn 7711: sub get_languages_hash {
7712: my %langchoices;
7713: foreach my $id (&Apache::loncommon::languageids()) {
7714: my $code = &Apache::loncommon::supportedlanguagecode($id);
7715: if ($code ne '') {
7716: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
7717: }
7718: }
7719: return %langchoices;
7720: }
7721:
1.43 raeburn 7722: sub defaults_titles {
1.141 raeburn 7723: my ($dom) = @_;
1.43 raeburn 7724: my %titles = &Apache::lonlocal::texthash (
7725: 'auth_def' => 'Default authentication type',
7726: 'auth_arg_def' => 'Default authentication argument',
7727: 'lang_def' => 'Default language',
1.54 raeburn 7728: 'timezone_def' => 'Default timezone',
1.68 raeburn 7729: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 7730: 'portal_def' => 'Portal/Default URL',
1.294 raeburn 7731: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
7732: 'intauth_check' => 'Check bcrypt cost if authenticated',
7733: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 7734: );
1.141 raeburn 7735: if ($dom) {
7736: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
7737: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
7738: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
7739: $protocol = 'http' if ($protocol ne 'https');
7740: if ($uint_dom) {
7741: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
7742: $uint_dom);
7743: }
7744: }
1.43 raeburn 7745: return (\%titles);
7746: }
7747:
1.46 raeburn 7748: sub print_scantronformat {
7749: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
7750: my $itemcount = 1;
1.60 raeburn 7751: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
7752: %confhash);
1.46 raeburn 7753: my $switchserver = &check_switchserver($dom,$confname);
7754: my %lt = &Apache::lonlocal::texthash (
1.95 www 7755: default => 'Default bubblesheet format file error',
7756: custom => 'Custom bubblesheet format file error',
1.46 raeburn 7757: );
7758: my %scantronfiles = (
7759: default => 'default.tab',
7760: custom => 'custom.tab',
7761: );
7762: foreach my $key (keys(%scantronfiles)) {
7763: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
7764: .$scantronfiles{$key};
7765: }
7766: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
7767: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
7768: if (!$switchserver) {
7769: my $servadm = $r->dir_config('lonAdmEMail');
7770: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
7771: if ($configuserok eq 'ok') {
7772: if ($author_ok eq 'ok') {
7773: my %legacyfile = (
7774: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
7775: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
7776: );
7777: my %md5chk;
7778: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 7779: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
7780: chomp($md5chk{$type});
1.46 raeburn 7781: }
7782: if ($md5chk{'default'} ne $md5chk{'custom'}) {
7783: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 7784: ($scantronurls{$type},my $error) =
1.46 raeburn 7785: &legacy_scantronformat($r,$dom,$confname,
7786: $type,$legacyfile{$type},
7787: $scantronurls{$type},
7788: $scantronfiles{$type});
1.60 raeburn 7789: if ($error ne '') {
7790: $error{$type} = $error;
7791: }
7792: }
7793: if (keys(%error) == 0) {
7794: $is_custom = 1;
7795: $confhash{'scantron'}{'scantronformat'} =
7796: $scantronurls{'custom'};
7797: my $putresult =
7798: &Apache::lonnet::put_dom('configuration',
7799: \%confhash,$dom);
7800: if ($putresult ne 'ok') {
7801: $error{'custom'} =
7802: '<span class="LC_error">'.
7803: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7804: }
1.46 raeburn 7805: }
7806: } else {
1.60 raeburn 7807: ($scantronurls{'default'},my $error) =
1.46 raeburn 7808: &legacy_scantronformat($r,$dom,$confname,
7809: 'default',$legacyfile{'default'},
7810: $scantronurls{'default'},
7811: $scantronfiles{'default'});
1.60 raeburn 7812: if ($error eq '') {
7813: $confhash{'scantron'}{'scantronformat'} = '';
7814: my $putresult =
7815: &Apache::lonnet::put_dom('configuration',
7816: \%confhash,$dom);
7817: if ($putresult ne 'ok') {
7818: $error{'default'} =
7819: '<span class="LC_error">'.
7820: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7821: }
7822: } else {
7823: $error{'default'} = $error;
7824: }
1.46 raeburn 7825: }
7826: }
7827: }
7828: } else {
1.95 www 7829: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 7830: }
7831: }
7832: if (ref($settings) eq 'HASH') {
7833: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
7834: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
7835: if ((!@info) || ($info[0] eq 'no_such_dir')) {
7836: $scantronurl = '';
7837: } else {
7838: $scantronurl = $settings->{'scantronformat'};
7839: }
7840: $is_custom = 1;
7841: } else {
7842: $scantronurl = $scantronurls{'default'};
7843: }
7844: } else {
1.60 raeburn 7845: if ($is_custom) {
7846: $scantronurl = $scantronurls{'custom'};
7847: } else {
7848: $scantronurl = $scantronurls{'default'};
7849: }
1.46 raeburn 7850: }
7851: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7852: $datatable .= '<tr'.$css_class.'>';
7853: if (!$is_custom) {
1.65 raeburn 7854: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
7855: '<span class="LC_nobreak">';
1.46 raeburn 7856: if ($scantronurl) {
1.199 raeburn 7857: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
7858: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 7859: } else {
7860: $datatable = &mt('File unavailable for display');
7861: }
1.65 raeburn 7862: $datatable .= '</span></td>';
1.60 raeburn 7863: if (keys(%error) == 0) {
1.306 raeburn 7864: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 7865: if (!$switchserver) {
7866: $datatable .= &mt('Upload:').'<br />';
7867: }
7868: } else {
7869: my $errorstr;
7870: foreach my $key (sort(keys(%error))) {
7871: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7872: }
7873: $datatable .= '<td>'.$errorstr;
7874: }
1.46 raeburn 7875: } else {
7876: if (keys(%error) > 0) {
7877: my $errorstr;
7878: foreach my $key (sort(keys(%error))) {
7879: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7880: }
1.60 raeburn 7881: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 7882: } elsif ($scantronurl) {
1.199 raeburn 7883: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
7884: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 7885: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 7886: $link.
7887: '<label><input type="checkbox" name="scantronformat_del"'.
7888: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 7889: '<td><span class="LC_nobreak"> '.
7890: &mt('Replace:').'</span><br />';
1.46 raeburn 7891: }
7892: }
7893: if (keys(%error) == 0) {
7894: if ($switchserver) {
7895: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
7896: } else {
1.65 raeburn 7897: $datatable .='<span class="LC_nobreak"> '.
7898: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 7899: }
7900: }
7901: $datatable .= '</td></tr>';
7902: $$rowtotal ++;
7903: return $datatable;
7904: }
7905:
7906: sub legacy_scantronformat {
7907: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
7908: my ($url,$error);
7909: my @statinfo = &Apache::lonnet::stat_file($newurl);
7910: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
7911: (my $result,$url) =
7912: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
7913: '','',$newfile);
7914: if ($result ne 'ok') {
1.130 raeburn 7915: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 7916: }
7917: }
7918: return ($url,$error);
7919: }
1.43 raeburn 7920:
1.49 raeburn 7921: sub print_coursecategories {
1.57 raeburn 7922: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
7923: my $datatable;
7924: if ($position eq 'top') {
1.238 raeburn 7925: my (%checked);
7926: my @catitems = ('unauth','auth');
7927: my @cattypes = ('std','domonly','codesrch','none');
7928: $checked{'unauth'} = 'std';
7929: $checked{'auth'} = 'std';
7930: if (ref($settings) eq 'HASH') {
7931: foreach my $type (@cattypes) {
7932: if ($type eq $settings->{'unauth'}) {
7933: $checked{'unauth'} = $type;
7934: }
7935: if ($type eq $settings->{'auth'}) {
7936: $checked{'auth'} = $type;
7937: }
7938: }
7939: }
7940: my %lt = &Apache::lonlocal::texthash (
7941: unauth => 'Catalog type for unauthenticated users',
7942: auth => 'Catalog type for authenticated users',
7943: none => 'No catalog',
7944: std => 'Standard catalog',
7945: domonly => 'Domain-only catalog',
7946: codesrch => "Code search form",
7947: );
7948: my $itemcount = 0;
7949: foreach my $item (@catitems) {
7950: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
7951: $datatable .= '<tr '.$css_class.'>'.
7952: '<td>'.$lt{$item}.'</td>'.
7953: '<td class="LC_right_item"><span class="LC_nobreak">';
7954: foreach my $type (@cattypes) {
7955: my $ischecked;
7956: if ($checked{$item} eq $type) {
7957: $ischecked=' checked="checked"';
7958: }
7959: $datatable .= '<label>'.
7960: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
7961: ' />'.$lt{$type}.'</label> ';
7962: }
1.327 raeburn 7963: $datatable .= '</span></td></tr>';
1.238 raeburn 7964: $itemcount ++;
7965: }
7966: $$rowtotal += $itemcount;
7967: } elsif ($position eq 'middle') {
1.57 raeburn 7968: my $toggle_cats_crs = ' ';
7969: my $toggle_cats_dom = ' checked="checked" ';
7970: my $can_cat_crs = ' ';
7971: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 7972: my $toggle_catscomm_comm = ' ';
7973: my $toggle_catscomm_dom = ' checked="checked" ';
7974: my $can_catcomm_comm = ' ';
7975: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 7976: my $toggle_catsplace_place = ' ';
7977: my $toggle_catsplace_dom = ' checked="checked" ';
7978: my $can_catplace_place = ' ';
7979: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 7980:
1.57 raeburn 7981: if (ref($settings) eq 'HASH') {
7982: if ($settings->{'togglecats'} eq 'crs') {
7983: $toggle_cats_crs = $toggle_cats_dom;
7984: $toggle_cats_dom = ' ';
7985: }
7986: if ($settings->{'categorize'} eq 'crs') {
7987: $can_cat_crs = $can_cat_dom;
7988: $can_cat_dom = ' ';
7989: }
1.120 raeburn 7990: if ($settings->{'togglecatscomm'} eq 'comm') {
7991: $toggle_catscomm_comm = $toggle_catscomm_dom;
7992: $toggle_catscomm_dom = ' ';
7993: }
7994: if ($settings->{'categorizecomm'} eq 'comm') {
7995: $can_catcomm_comm = $can_catcomm_dom;
7996: $can_catcomm_dom = ' ';
7997: }
1.272 raeburn 7998: if ($settings->{'togglecatsplace'} eq 'place') {
7999: $toggle_catsplace_place = $toggle_catsplace_dom;
8000: $toggle_catsplace_dom = ' ';
8001: }
8002: if ($settings->{'categorizeplace'} eq 'place') {
8003: $can_catplace_place = $can_catplace_dom;
8004: $can_catplace_dom = ' ';
8005: }
1.57 raeburn 8006: }
8007: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 8008: togglecats => 'Show/Hide a course in catalog',
8009: togglecatscomm => 'Show/Hide a community in catalog',
8010: togglecatsplace => 'Show/Hide a placement test in catalog',
8011: categorize => 'Assign a category to a course',
8012: categorizecomm => 'Assign a category to a community',
8013: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 8014: );
8015: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 8016: dom => 'Set in Domain',
8017: crs => 'Set in Course',
8018: comm => 'Set in Community',
8019: place => 'Set in Placement Test',
1.57 raeburn 8020: );
8021: $datatable = '<tr class="LC_odd_row">'.
8022: '<td>'.$title{'togglecats'}.'</td>'.
8023: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8024: '<input type="radio" name="togglecats"'.
8025: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8026: '<label><input type="radio" name="togglecats"'.
8027: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
8028: '</tr><tr>'.
8029: '<td>'.$title{'categorize'}.'</td>'.
8030: '<td class="LC_right_item"><span class="LC_nobreak">'.
8031: '<label><input type="radio" name="categorize"'.
8032: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8033: '<label><input type="radio" name="categorize"'.
8034: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 8035: '</tr><tr class="LC_odd_row">'.
8036: '<td>'.$title{'togglecatscomm'}.'</td>'.
8037: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8038: '<input type="radio" name="togglecatscomm"'.
8039: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8040: '<label><input type="radio" name="togglecatscomm"'.
8041: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
8042: '</tr><tr>'.
8043: '<td>'.$title{'categorizecomm'}.'</td>'.
8044: '<td class="LC_right_item"><span class="LC_nobreak">'.
8045: '<label><input type="radio" name="categorizecomm"'.
8046: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8047: '<label><input type="radio" name="categorizecomm"'.
8048: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 8049: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 8050: '<td>'.$title{'togglecatsplace'}.'</td>'.
8051: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8052: '<input type="radio" name="togglecatsplace"'.
8053: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8054: '<label><input type="radio" name="togglecatscomm"'.
8055: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
8056: '</tr><tr>'.
8057: '<td>'.$title{'categorizeplace'}.'</td>'.
8058: '<td class="LC_right_item"><span class="LC_nobreak">'.
8059: '<label><input type="radio" name="categorizeplace"'.
8060: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8061: '<label><input type="radio" name="categorizeplace"'.
8062: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 8063: '</tr>';
1.272 raeburn 8064: $$rowtotal += 6;
1.57 raeburn 8065: } else {
8066: my $css_class;
8067: my $itemcount = 1;
8068: my $cathash;
8069: if (ref($settings) eq 'HASH') {
8070: $cathash = $settings->{'cats'};
8071: }
8072: if (ref($cathash) eq 'HASH') {
8073: my (@cats,@trails,%allitems,%idx,@jsarray);
8074: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
8075: \%allitems,\%idx,\@jsarray);
8076: my $maxdepth = scalar(@cats);
8077: my $colattrib = '';
8078: if ($maxdepth > 2) {
8079: $colattrib = ' colspan="2" ';
8080: }
8081: my @path;
8082: if (@cats > 0) {
8083: if (ref($cats[0]) eq 'ARRAY') {
8084: my $numtop = @{$cats[0]};
8085: my $maxnum = $numtop;
1.120 raeburn 8086: my %default_names = (
8087: instcode => &mt('Official courses'),
8088: communities => &mt('Communities'),
1.272 raeburn 8089: placement => &mt('Placement Tests'),
1.120 raeburn 8090: );
8091:
8092: if ((!grep(/^instcode$/,@{$cats[0]})) ||
8093: ($cathash->{'instcode::0'} eq '') ||
8094: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 8095: ($cathash->{'communities::0'} eq '') ||
8096: (!grep(/^placement$/,@{$cats[0]})) ||
8097: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 8098: $maxnum ++;
8099: }
8100: my $lastidx;
8101: for (my $i=0; $i<$numtop; $i++) {
8102: my $parent = $cats[0][$i];
8103: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8104: my $item = &escape($parent).'::0';
8105: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
8106: $lastidx = $idx{$item};
8107: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
8108: .'<select name="'.$item.'"'.$chgstr.'>';
8109: for (my $k=0; $k<=$maxnum; $k++) {
8110: my $vpos = $k+1;
8111: my $selstr;
8112: if ($k == $i) {
8113: $selstr = ' selected="selected" ';
8114: }
8115: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8116: }
1.214 raeburn 8117: $datatable .= '</select></span></td><td>';
1.272 raeburn 8118: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 8119: $datatable .= '<span class="LC_nobreak">'
8120: .$default_names{$parent}.'</span>';
8121: if ($parent eq 'instcode') {
8122: $datatable .= '<br /><span class="LC_nobreak">('
8123: .&mt('with institutional codes')
8124: .')</span></td><td'.$colattrib.'>';
8125: } else {
8126: $datatable .= '<table><tr><td>';
8127: }
8128: $datatable .= '<span class="LC_nobreak">'
8129: .'<label><input type="radio" name="'
8130: .$parent.'" value="1" checked="checked" />'
8131: .&mt('Display').'</label>';
8132: if ($parent eq 'instcode') {
8133: $datatable .= ' ';
8134: } else {
8135: $datatable .= '</span></td></tr><tr><td>'
8136: .'<span class="LC_nobreak">';
8137: }
8138: $datatable .= '<label><input type="radio" name="'
8139: .$parent.'" value="0" />'
8140: .&mt('Do not display').'</label></span>';
1.272 raeburn 8141: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 8142: $datatable .= '</td></tr></table>';
8143: }
8144: $datatable .= '</td>';
1.57 raeburn 8145: } else {
8146: $datatable .= $parent
1.214 raeburn 8147: .' <span class="LC_nobreak"><label>'
8148: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 8149: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
8150: }
8151: my $depth = 1;
8152: push(@path,$parent);
8153: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
8154: pop(@path);
8155: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
8156: $itemcount ++;
8157: }
1.48 raeburn 8158: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 8159: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
8160: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 8161: for (my $k=0; $k<=$maxnum; $k++) {
8162: my $vpos = $k+1;
8163: my $selstr;
1.57 raeburn 8164: if ($k == $numtop) {
1.48 raeburn 8165: $selstr = ' selected="selected" ';
8166: }
8167: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8168: }
1.59 bisitz 8169: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 8170: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
8171: .'</tr>'."\n";
1.48 raeburn 8172: $itemcount ++;
1.272 raeburn 8173: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 8174: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
8175: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8176: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
8177: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
8178: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
8179: for (my $k=0; $k<=$maxnum; $k++) {
8180: my $vpos = $k+1;
8181: my $selstr;
8182: if ($k == $maxnum) {
8183: $selstr = ' selected="selected" ';
8184: }
8185: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 8186: }
1.120 raeburn 8187: $datatable .= '</select></span></td>'.
8188: '<td><span class="LC_nobreak">'.
8189: $default_names{$default}.'</span>';
8190: if ($default eq 'instcode') {
8191: $datatable .= '<br /><span class="LC_nobreak">('
8192: .&mt('with institutional codes').')</span>';
8193: }
8194: $datatable .= '</td>'
8195: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
8196: .&mt('Display').'</label> '
8197: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
8198: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 8199: }
8200: }
8201: }
1.57 raeburn 8202: } else {
8203: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 8204: }
8205: } else {
1.327 raeburn 8206: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 8207: .&initialize_categories($itemcount);
1.48 raeburn 8208: }
1.57 raeburn 8209: $$rowtotal += $itemcount;
1.48 raeburn 8210: }
8211: return $datatable;
8212: }
8213:
1.69 raeburn 8214: sub print_serverstatuses {
8215: my ($dom,$settings,$rowtotal) = @_;
8216: my $datatable;
8217: my @pages = &serverstatus_pages();
8218: my (%namedaccess,%machineaccess);
8219: foreach my $type (@pages) {
8220: $namedaccess{$type} = '';
8221: $machineaccess{$type}= '';
8222: }
8223: if (ref($settings) eq 'HASH') {
8224: foreach my $type (@pages) {
8225: if (exists($settings->{$type})) {
8226: if (ref($settings->{$type}) eq 'HASH') {
8227: foreach my $key (keys(%{$settings->{$type}})) {
8228: if ($key eq 'namedusers') {
8229: $namedaccess{$type} = $settings->{$type}->{$key};
8230: } elsif ($key eq 'machines') {
8231: $machineaccess{$type} = $settings->{$type}->{$key};
8232: }
8233: }
8234: }
8235: }
8236: }
8237: }
1.81 raeburn 8238: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 8239: my $rownum = 0;
8240: my $css_class;
8241: foreach my $type (@pages) {
8242: $rownum ++;
8243: $css_class = $rownum%2?' class="LC_odd_row"':'';
8244: $datatable .= '<tr'.$css_class.'>'.
8245: '<td><span class="LC_nobreak">'.
8246: $titles->{$type}.'</span></td>'.
8247: '<td class="LC_left_item">'.
8248: '<input type="text" name="'.$type.'_namedusers" '.
8249: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
8250: '<td class="LC_right_item">'.
8251: '<span class="LC_nobreak">'.
8252: '<input type="text" name="'.$type.'_machines" '.
8253: 'value="'.$machineaccess{$type}.'" size="10" />'.
8254: '</td></tr>'."\n";
8255: }
8256: $$rowtotal += $rownum;
8257: return $datatable;
8258: }
8259:
8260: sub serverstatus_pages {
8261: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 8262: 'checksums','clusterstatus','certstatus','metadata_keywords',
8263: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
8264: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 8265: }
8266:
1.236 raeburn 8267: sub defaults_javascript {
8268: my ($settings) = @_;
1.294 raeburn 8269: 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.');
8270: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
8271: &js_escape(\$intauthcheck);
8272: &js_escape(\$intauthcost);
8273: my $intauthjs = <<"ENDSCRIPT";
8274:
8275: function warnIntAuth(field) {
8276: if (field.name == 'intauth_check') {
8277: if (field.value == '2') {
8278: alert('$intauthcheck');
8279: }
8280: }
8281: if (field.name == 'intauth_cost') {
8282: field.value.replace(/\s/g,'');
8283: if (field.value != '') {
8284: var regexdigit=/^\\d+\$/;
8285: if (!regexdigit.test(field.value)) {
8286: alert('$intauthcost');
8287: }
8288: }
8289: }
8290: return;
8291: }
8292:
8293: ENDSCRIPT
8294:
8295: if (ref($settings) ne 'HASH') {
8296: return &Apache::lonhtmlcommon::scripttag($intauthjs);
8297: }
1.236 raeburn 8298: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
8299: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
8300: if ($maxnum eq '') {
8301: $maxnum = 0;
8302: }
8303: $maxnum ++;
1.249 raeburn 8304: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 8305: return <<"ENDSCRIPT";
8306: <script type="text/javascript">
8307: // <![CDATA[
8308: function reorderTypes(form,caller) {
8309: var changedVal;
8310: $jstext
8311: var newpos = 'addinststatus_pos';
8312: var current = new Array;
8313: var maxh = $maxnum;
8314: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8315: var oldVal;
8316: if (caller == newpos) {
8317: changedVal = newitemVal;
8318: } else {
8319: var curritem = 'inststatus_pos_'+caller;
8320: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
8321: current[newitemVal] = newpos;
8322: }
8323: for (var i=0; i<inststatuses.length; i++) {
8324: if (inststatuses[i] != caller) {
8325: var elementName = 'inststatus_pos_'+inststatuses[i];
8326: if (form.elements[elementName]) {
8327: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8328: current[currVal] = elementName;
8329: }
8330: }
8331: }
8332: for (var j=0; j<maxh; j++) {
8333: if (current[j] == undefined) {
8334: oldVal = j;
8335: }
8336: }
8337: if (oldVal < changedVal) {
8338: for (var k=oldVal+1; k<=changedVal ; k++) {
8339: var elementName = current[k];
8340: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8341: }
8342: } else {
8343: for (var k=changedVal; k<oldVal; k++) {
8344: var elementName = current[k];
8345: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8346: }
8347: }
8348: return;
8349: }
8350:
1.294 raeburn 8351: $intauthjs
8352:
1.236 raeburn 8353: // ]]>
8354: </script>
8355:
8356: ENDSCRIPT
1.294 raeburn 8357: } else {
8358: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 8359: }
8360: }
8361:
1.49 raeburn 8362: sub coursecategories_javascript {
8363: my ($settings) = @_;
1.57 raeburn 8364: my ($output,$jstext,$cathash);
1.49 raeburn 8365: if (ref($settings) eq 'HASH') {
1.57 raeburn 8366: $cathash = $settings->{'cats'};
8367: }
8368: if (ref($cathash) eq 'HASH') {
1.49 raeburn 8369: my (@cats,@jsarray,%idx);
1.57 raeburn 8370: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 8371: if (@jsarray > 0) {
8372: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
8373: for (my $i=0; $i<@jsarray; $i++) {
8374: if (ref($jsarray[$i]) eq 'ARRAY') {
8375: my $catstr = join('","',@{$jsarray[$i]});
8376: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
8377: }
8378: }
8379: }
8380: } else {
8381: $jstext = ' var categories = Array(1);'."\n".
8382: ' categories[0] = Array("instcode_pos");'."\n";
8383: }
1.237 bisitz 8384: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
8385: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 8386: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 8387: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
8388: &js_escape(\$instcode_reserved);
8389: &js_escape(\$communities_reserved);
1.272 raeburn 8390: &js_escape(\$placement_reserved);
1.265 damieng 8391: &js_escape(\$choose_again);
1.49 raeburn 8392: $output = <<"ENDSCRIPT";
8393: <script type="text/javascript">
1.109 raeburn 8394: // <![CDATA[
1.49 raeburn 8395: function reorderCats(form,parent,item,idx) {
8396: var changedVal;
8397: $jstext
8398: var newpos = 'addcategory_pos';
8399: if (parent == '') {
8400: var has_instcode = 0;
8401: var maxtop = categories[idx].length;
8402: for (var j=0; j<maxtop; j++) {
8403: if (categories[idx][j] == 'instcode::0') {
8404: has_instcode == 1;
8405: }
8406: }
8407: if (has_instcode == 0) {
8408: categories[idx][maxtop] = 'instcode_pos';
8409: }
8410: } else {
8411: newpos += '_'+parent;
8412: }
8413: var maxh = 1 + categories[idx].length;
8414: var current = new Array;
8415: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8416: if (item == newpos) {
8417: changedVal = newitemVal;
8418: } else {
8419: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
8420: current[newitemVal] = newpos;
8421: }
8422: for (var i=0; i<categories[idx].length; i++) {
8423: var elementName = categories[idx][i];
8424: if (elementName != item) {
8425: if (form.elements[elementName]) {
8426: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8427: current[currVal] = elementName;
8428: }
8429: }
8430: }
8431: var oldVal;
8432: for (var j=0; j<maxh; j++) {
8433: if (current[j] == undefined) {
8434: oldVal = j;
8435: }
8436: }
8437: if (oldVal < changedVal) {
8438: for (var k=oldVal+1; k<=changedVal ; k++) {
8439: var elementName = current[k];
8440: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8441: }
8442: } else {
8443: for (var k=changedVal; k<oldVal; k++) {
8444: var elementName = current[k];
8445: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8446: }
8447: }
8448: return;
8449: }
1.120 raeburn 8450:
8451: function categoryCheck(form) {
8452: if (form.elements['addcategory_name'].value == 'instcode') {
8453: alert('$instcode_reserved\\n$choose_again');
8454: return false;
8455: }
8456: if (form.elements['addcategory_name'].value == 'communities') {
8457: alert('$communities_reserved\\n$choose_again');
8458: return false;
8459: }
1.272 raeburn 8460: if (form.elements['addcategory_name'].value == 'placement') {
8461: alert('$placement_reserved\\n$choose_again');
8462: return false;
8463: }
1.120 raeburn 8464: return true;
8465: }
8466:
1.109 raeburn 8467: // ]]>
1.49 raeburn 8468: </script>
8469:
8470: ENDSCRIPT
8471: return $output;
8472: }
8473:
1.48 raeburn 8474: sub initialize_categories {
8475: my ($itemcount) = @_;
1.120 raeburn 8476: my ($datatable,$css_class,$chgstr);
8477: my %default_names = (
8478: instcode => 'Official courses (with institutional codes)',
8479: communities => 'Communities',
1.272 raeburn 8480: placement => 'Placement Tests',
1.120 raeburn 8481: );
1.328 raeburn 8482: my %selnum = (
8483: instcode => '0',
8484: communities => '1',
8485: placement => '2',
8486: );
8487: my %selected;
1.272 raeburn 8488: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 8489: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 8490: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 8491: map { $selected{$selnum{$_}} = '' } keys(%selnum);
8492: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 8493: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 8494: .'<select name="'.$default.'_pos"'.$chgstr.'>'
8495: .'<option value="0"'.$selected{'0'}.'>1</option>'
8496: .'<option value="1"'.$selected{'1'}.'>2</option>'
8497: .'<option value="2"'.$selected{'2'}.'>3</option>'
8498: .'<option value="3">4</option></select> '
1.120 raeburn 8499: .$default_names{$default}
8500: .'</span></td><td><span class="LC_nobreak">'
8501: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
8502: .&mt('Display').'</label> <label>'
8503: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 8504: .'</label></span></td></tr>';
1.120 raeburn 8505: $itemcount ++;
8506: }
1.48 raeburn 8507: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 8508: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 8509: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 8510: .'<select name="addcategory_pos"'.$chgstr.'>'
8511: .'<option value="0">1</option>'
8512: .'<option value="1">2</option>'
1.328 raeburn 8513: .'<option value="2">3</option>'
8514: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 8515: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
8516: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
8517: .'</td></tr>';
1.48 raeburn 8518: return $datatable;
8519: }
8520:
8521: sub build_category_rows {
1.49 raeburn 8522: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
8523: my ($text,$name,$item,$chgstr);
1.48 raeburn 8524: if (ref($cats) eq 'ARRAY') {
8525: my $maxdepth = scalar(@{$cats});
8526: if (ref($cats->[$depth]) eq 'HASH') {
8527: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
8528: my $numchildren = @{$cats->[$depth]{$parent}};
8529: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 8530: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 8531: my ($idxnum,$parent_name,$parent_item);
8532: my $higher = $depth - 1;
8533: if ($higher == 0) {
8534: $parent_name = &escape($parent).'::'.$higher;
8535: } else {
8536: if (ref($path) eq 'ARRAY') {
8537: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8538: }
8539: }
8540: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 8541: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 8542: if ($j < $numchildren) {
1.48 raeburn 8543: $name = $cats->[$depth]{$parent}[$j];
8544: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 8545: $idxnum = $idx->{$item};
8546: } else {
8547: $name = $parent_name;
8548: $item = $parent_item;
1.48 raeburn 8549: }
1.49 raeburn 8550: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
8551: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 8552: for (my $i=0; $i<=$numchildren; $i++) {
8553: my $vpos = $i+1;
8554: my $selstr;
8555: if ($j == $i) {
8556: $selstr = ' selected="selected" ';
8557: }
8558: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
8559: }
8560: $text .= '</select> ';
8561: if ($j < $numchildren) {
8562: my $deeper = $depth+1;
8563: $text .= $name.' '
8564: .'<label><input type="checkbox" name="deletecategory" value="'
8565: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
8566: if(ref($path) eq 'ARRAY') {
8567: push(@{$path},$name);
1.49 raeburn 8568: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 8569: pop(@{$path});
8570: }
8571: } else {
1.330 raeburn 8572: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 8573: if ($j == $numchildren) {
8574: $text .= $name;
8575: } else {
8576: $text .= $item;
8577: }
8578: $text .= '" value="" />';
8579: }
8580: $text .= '</td></tr>';
8581: }
8582: $text .= '</table></td>';
8583: } else {
8584: my $higher = $depth-1;
8585: if ($higher == 0) {
8586: $name = &escape($parent).'::'.$higher;
8587: } else {
8588: if (ref($path) eq 'ARRAY') {
8589: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8590: }
8591: }
8592: my $colspan;
8593: if ($parent ne 'instcode') {
8594: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 8595: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 8596: }
8597: }
8598: }
8599: }
8600: return $text;
8601: }
8602:
1.33 raeburn 8603: sub modifiable_userdata_row {
1.305 raeburn 8604: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
8605: $rowid,$customcss,$rowstyle) = @_;
1.228 raeburn 8606: my ($role,$rolename,$statustype);
8607: $role = $item;
1.224 raeburn 8608: if ($context eq 'cancreate') {
1.305 raeburn 8609: if ($item =~ /^(emailusername)_(.+)$/) {
8610: $role = $1;
8611: $statustype = $2;
1.228 raeburn 8612: if (ref($usertypes) eq 'HASH') {
8613: if ($usertypes->{$statustype}) {
8614: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
8615: } else {
8616: $rolename = &mt('Data provided by user');
8617: }
8618: }
1.224 raeburn 8619: }
8620: } elsif ($context eq 'selfcreate') {
1.63 raeburn 8621: if (ref($usertypes) eq 'HASH') {
8622: $rolename = $usertypes->{$role};
8623: } else {
8624: $rolename = $role;
8625: }
1.325 raeburn 8626: } elsif ($context eq 'lti') {
8627: $rolename = &mt('Institutional data used (if available)');
1.33 raeburn 8628: } else {
1.63 raeburn 8629: if ($role eq 'cr') {
8630: $rolename = &mt('Custom role');
8631: } else {
8632: $rolename = &Apache::lonnet::plaintext($role);
8633: }
1.33 raeburn 8634: }
1.224 raeburn 8635: my (@fields,%fieldtitles);
8636: if (ref($fieldsref) eq 'ARRAY') {
8637: @fields = @{$fieldsref};
8638: } else {
8639: @fields = ('lastname','firstname','middlename','generation',
8640: 'permanentemail','id');
8641: }
8642: if ((ref($titlesref) eq 'HASH')) {
8643: %fieldtitles = %{$titlesref};
8644: } else {
8645: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8646: }
1.33 raeburn 8647: my $output;
1.305 raeburn 8648: my $css_class;
8649: if ($rowcount%2) {
8650: $css_class = 'LC_odd_row';
8651: }
8652: if ($customcss) {
8653: $css_class .= " $customcss";
8654: }
8655: $css_class =~ s/^\s+//;
8656: if ($css_class) {
8657: $css_class = ' class="'.$css_class.'"';
8658: }
8659: if ($rowstyle) {
8660: $css_class .= ' style="'.$rowstyle.'"';
8661: }
8662: if ($rowid) {
8663: $rowid = ' id="'.$rowid.'"';
8664: }
8665: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 8666: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
8667: '<td class="LC_left_item" colspan="2"><table>';
8668: my $rem;
8669: my %checks;
1.325 raeburn 8670: my %current;
1.33 raeburn 8671: if (ref($settings) eq 'HASH') {
1.325 raeburn 8672: my $hashref;
8673: if ($context eq 'lti') {
8674: if (ref($settings) eq 'HASH') {
8675: $hashref = $settings->{'instdata'};
8676: }
8677: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 8678: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 8679: $hashref = $settings->{'lti_instdata'};
8680: }
8681: if ($role eq 'emailusername') {
8682: if ($statustype) {
8683: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
8684: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 8685: }
1.325 raeburn 8686: }
8687: }
8688: }
8689: if (ref($hashref) eq 'HASH') {
8690: foreach my $field (@fields) {
8691: if ($hashref->{$field}) {
8692: if ($role eq 'emailusername') {
8693: $checks{$field} = $hashref->{$field};
8694: } else {
8695: $checks{$field} = ' checked="checked" ';
1.33 raeburn 8696: }
8697: }
8698: }
8699: }
8700: }
1.305 raeburn 8701:
8702: my $total = scalar(@fields);
8703: for (my $i=0; $i<$total; $i++) {
8704: $rem = $i%($numinrow);
1.33 raeburn 8705: if ($rem == 0) {
8706: if ($i > 0) {
8707: $output .= '</tr>';
8708: }
8709: $output .= '<tr>';
8710: }
8711: my $check = ' ';
1.228 raeburn 8712: unless ($role eq 'emailusername') {
8713: if (exists($checks{$fields[$i]})) {
8714: $check = $checks{$fields[$i]}
1.325 raeburn 8715: } elsif ($context ne 'lti') {
1.228 raeburn 8716: if ($role eq 'st') {
8717: if (ref($settings) ne 'HASH') {
8718: $check = ' checked="checked" ';
8719: }
1.33 raeburn 8720: }
8721: }
8722: }
8723: $output .= '<td class="LC_left_item">'.
1.228 raeburn 8724: '<span class="LC_nobreak">';
1.325 raeburn 8725: my $prefix = 'canmodify';
1.228 raeburn 8726: if ($role eq 'emailusername') {
8727: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
8728: $checks{$fields[$i]} = 'omit';
8729: }
8730: foreach my $option ('required','optional','omit') {
8731: my $checked='';
8732: if ($checks{$fields[$i]} eq $option) {
8733: $checked='checked="checked" ';
8734: }
8735: $output .= '<label>'.
1.325 raeburn 8736: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 8737: &mt($option).'</label>'.(' ' x2);
8738: }
8739: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
8740: } else {
1.325 raeburn 8741: if ($context eq 'lti') {
8742: $prefix = 'lti';
8743: }
1.228 raeburn 8744: $output .= '<label>'.
1.325 raeburn 8745: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 8746: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
8747: '</label>';
8748: }
8749: $output .= '</span></td>';
1.33 raeburn 8750: }
1.305 raeburn 8751: $rem = $total%$numinrow;
8752: my $colsleft;
8753: if ($rem) {
8754: $colsleft = $numinrow - $rem;
8755: }
8756: if ($colsleft > 1) {
1.33 raeburn 8757: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8758: ' </td>';
8759: } elsif ($colsleft == 1) {
8760: $output .= '<td class="LC_left_item"> </td>';
8761: }
8762: $output .= '</tr></table></td></tr>';
8763: return $output;
8764: }
1.28 raeburn 8765:
1.93 raeburn 8766: sub insttypes_row {
1.305 raeburn 8767: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
8768: $customcss,$rowstyle) = @_;
1.93 raeburn 8769: my %lt = &Apache::lonlocal::texthash (
8770: cansearch => 'Users allowed to search',
8771: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 8772: lockablenames => 'User preference to lock name',
1.305 raeburn 8773: selfassign => 'Self-reportable affiliations',
1.315 raeburn 8774: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 8775: );
8776: my $showdom;
8777: if ($context eq 'cansearch') {
8778: $showdom = ' ('.$dom.')';
8779: }
1.165 raeburn 8780: my $class = 'LC_left_item';
8781: if ($context eq 'statustocreate') {
8782: $class = 'LC_right_item';
8783: }
1.305 raeburn 8784: my $css_class;
8785: if ($$rowtotal%2) {
8786: $css_class = 'LC_odd_row';
8787: }
8788: if ($customcss) {
8789: $css_class .= ' '.$customcss;
8790: }
8791: $css_class =~ s/^\s+//;
8792: if ($css_class) {
8793: $css_class = ' class="'.$css_class.'"';
8794: }
8795: if ($rowstyle) {
8796: $css_class .= ' style="'.$rowstyle.'"';
8797: }
8798: if ($onclick) {
8799: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 8800: }
8801: my $output = '<tr'.$css_class.'>'.
8802: '<td>'.$lt{$context}.$showdom.
8803: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 8804: my $rem;
8805: if (ref($types) eq 'ARRAY') {
8806: for (my $i=0; $i<@{$types}; $i++) {
8807: if (defined($usertypes->{$types->[$i]})) {
8808: my $rem = $i%($numinrow);
8809: if ($rem == 0) {
8810: if ($i > 0) {
8811: $output .= '</tr>';
8812: }
8813: $output .= '<tr>';
1.23 raeburn 8814: }
1.26 raeburn 8815: my $check = ' ';
1.99 raeburn 8816: if (ref($settings) eq 'HASH') {
8817: if (ref($settings->{$context}) eq 'ARRAY') {
8818: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
8819: $check = ' checked="checked" ';
8820: }
1.315 raeburn 8821: } elsif (ref($settings->{$context}) eq 'HASH') {
8822: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
8823: $check = ' checked="checked" ';
8824: }
1.99 raeburn 8825: } elsif ($context eq 'statustocreate') {
1.26 raeburn 8826: $check = ' checked="checked" ';
8827: }
1.23 raeburn 8828: }
1.26 raeburn 8829: $output .= '<td class="LC_left_item">'.
8830: '<span class="LC_nobreak"><label>'.
1.93 raeburn 8831: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 8832: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 8833: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 8834: }
8835: }
1.26 raeburn 8836: $rem = @{$types}%($numinrow);
1.23 raeburn 8837: }
8838: my $colsleft = $numinrow - $rem;
1.315 raeburn 8839: if ($context eq 'overrides') {
8840: if ($colsleft > 1) {
8841: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8842: } else {
8843: $output .= '<td class="LC_left_item">';
8844: }
8845: $output .= ' ';
1.23 raeburn 8846: } else {
1.315 raeburn 8847: if (($rem == 0) && (@{$types} > 0)) {
8848: $output .= '<tr>';
8849: }
8850: if ($colsleft > 1) {
8851: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8852: } else {
8853: $output .= '<td class="LC_left_item">';
8854: }
8855: my $defcheck = ' ';
8856: if (ref($settings) eq 'HASH') {
8857: if (ref($settings->{$context}) eq 'ARRAY') {
8858: if (grep(/^default$/,@{$settings->{$context}})) {
8859: $defcheck = ' checked="checked" ';
8860: }
8861: } elsif ($context eq 'statustocreate') {
1.99 raeburn 8862: $defcheck = ' checked="checked" ';
8863: }
1.26 raeburn 8864: }
1.315 raeburn 8865: $output .= '<span class="LC_nobreak"><label>'.
8866: '<input type="checkbox" name="'.$context.'" '.
8867: 'value="default"'.$defcheck.$onclick.' />'.
8868: $othertitle.'</label></span>';
1.23 raeburn 8869: }
1.315 raeburn 8870: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 8871: return $output;
1.23 raeburn 8872: }
8873:
8874: sub sorted_searchtitles {
8875: my %searchtitles = &Apache::lonlocal::texthash(
8876: 'uname' => 'username',
8877: 'lastname' => 'last name',
8878: 'lastfirst' => 'last name, first name',
8879: );
8880: my @titleorder = ('uname','lastname','lastfirst');
8881: return (\%searchtitles,\@titleorder);
8882: }
8883:
1.25 raeburn 8884: sub sorted_searchtypes {
8885: my %srchtypes_desc = (
8886: exact => 'is exact match',
8887: contains => 'contains ..',
8888: begins => 'begins with ..',
8889: );
8890: my @srchtypeorder = ('exact','begins','contains');
8891: return (\%srchtypes_desc,\@srchtypeorder);
8892: }
8893:
1.3 raeburn 8894: sub usertype_update_row {
8895: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
8896: my $datatable;
8897: my $numinrow = 4;
8898: foreach my $type (@{$types}) {
8899: if (defined($usertypes->{$type})) {
8900: $$rownums ++;
8901: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
8902: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
8903: '</td><td class="LC_left_item"><table>';
8904: for (my $i=0; $i<@{$fields}; $i++) {
8905: my $rem = $i%($numinrow);
8906: if ($rem == 0) {
8907: if ($i > 0) {
8908: $datatable .= '</tr>';
8909: }
8910: $datatable .= '<tr>';
8911: }
8912: my $check = ' ';
1.39 raeburn 8913: if (ref($settings) eq 'HASH') {
8914: if (ref($settings->{'fields'}) eq 'HASH') {
8915: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
8916: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
8917: $check = ' checked="checked" ';
8918: }
1.3 raeburn 8919: }
8920: }
8921: }
8922:
8923: if ($i == @{$fields}-1) {
8924: my $colsleft = $numinrow - $rem;
8925: if ($colsleft > 1) {
8926: $datatable .= '<td colspan="'.$colsleft.'">';
8927: } else {
8928: $datatable .= '<td>';
8929: }
8930: } else {
8931: $datatable .= '<td>';
8932: }
1.8 raeburn 8933: $datatable .= '<span class="LC_nobreak"><label>'.
8934: '<input type="checkbox" name="updateable_'.$type.
8935: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
8936: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 8937: }
8938: $datatable .= '</tr></table></td></tr>';
8939: }
8940: }
8941: return $datatable;
1.1 raeburn 8942: }
8943:
8944: sub modify_login {
1.205 raeburn 8945: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 8946: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
8947: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
8948: %title = ( coursecatalog => 'Display course catalog',
8949: adminmail => 'Display administrator E-mail address',
1.188 raeburn 8950: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 8951: newuser => 'Link for visitors to create a user account',
8952: loginheader => 'Log-in box header');
8953: @offon = ('off','on');
1.112 raeburn 8954: if (ref($domconfig{login}) eq 'HASH') {
8955: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
8956: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
8957: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
8958: }
8959: }
8960: }
1.9 raeburn 8961: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
8962: \%domconfig,\%loginhash);
1.188 raeburn 8963: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 8964: foreach my $item (@toggles) {
8965: $loginhash{login}{$item} = $env{'form.'.$item};
8966: }
1.41 raeburn 8967: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 8968: if (ref($colchanges{'login'}) eq 'HASH') {
8969: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
8970: \%loginhash);
8971: }
1.110 raeburn 8972:
1.149 raeburn 8973: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 8974: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 8975: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 8976: if (keys(%servers) > 1) {
8977: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 8978: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
8979: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
8980: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
8981: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
8982: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
8983: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8984: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
8985: $changes{'loginvia'}{$lonhost} = 1;
8986: } else {
8987: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
8988: $changes{'loginvia'}{$lonhost} = 1;
8989: }
8990: } else {
8991: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8992: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
8993: $changes{'loginvia'}{$lonhost} = 1;
8994: }
8995: }
8996: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
8997: foreach my $item (@loginvia_attribs) {
8998: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
8999: }
9000: } else {
9001: foreach my $item (@loginvia_attribs) {
9002: my $new = $env{'form.'.$lonhost.'_'.$item};
9003: if (($item eq 'serverpath') && ($new eq 'custom')) {
9004: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
9005: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9006: $new = '/';
9007: }
9008: }
9009: if (($item eq 'custompath') &&
9010: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9011: $new = '';
9012: }
9013: if ($new ne $curr_loginvia{$lonhost}{$item}) {
9014: $changes{'loginvia'}{$lonhost} = 1;
9015: }
9016: if ($item eq 'exempt') {
1.256 raeburn 9017: $new = &check_exempt_addresses($new);
1.128 raeburn 9018: }
9019: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9020: }
9021: }
1.112 raeburn 9022: } else {
1.128 raeburn 9023: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9024: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 9025: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 9026: foreach my $item (@loginvia_attribs) {
9027: my $new = $env{'form.'.$lonhost.'_'.$item};
9028: if (($item eq 'serverpath') && ($new eq 'custom')) {
9029: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9030: $new = '/';
9031: }
9032: }
9033: if (($item eq 'custompath') &&
9034: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9035: $new = '';
9036: }
9037: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9038: }
1.110 raeburn 9039: }
9040: }
9041: }
9042: }
1.119 raeburn 9043:
1.168 raeburn 9044: my $servadm = $r->dir_config('lonAdmEMail');
9045: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
9046: if (ref($domconfig{'login'}) eq 'HASH') {
9047: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
9048: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
9049: if ($lang eq 'nolang') {
9050: push(@currlangs,$lang);
9051: } elsif (defined($langchoices{$lang})) {
9052: push(@currlangs,$lang);
9053: } else {
9054: next;
9055: }
9056: }
9057: }
9058: }
9059: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
9060: if (@currlangs > 0) {
9061: foreach my $lang (@currlangs) {
9062: if (grep(/^\Q$lang\E$/,@delurls)) {
9063: $changes{'helpurl'}{$lang} = 1;
9064: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
9065: $changes{'helpurl'}{$lang} = 1;
9066: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
9067: push(@newlangs,$lang);
9068: } else {
9069: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9070: }
9071: }
9072: }
9073: unless (grep(/^nolang$/,@currlangs)) {
9074: if ($env{'form.loginhelpurl_nolang.filename'}) {
9075: $changes{'helpurl'}{'nolang'} = 1;
9076: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
9077: push(@newlangs,'nolang');
9078: }
9079: }
9080: if ($env{'form.loginhelpurl_add_lang'}) {
9081: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
9082: ($env{'form.loginhelpurl_add_file.filename'})) {
9083: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
9084: $addedfile = $env{'form.loginhelpurl_add_lang'};
9085: }
9086: }
9087: if ((@newlangs > 0) || ($addedfile)) {
9088: my $error;
9089: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9090: if ($configuserok eq 'ok') {
9091: if ($switchserver) {
9092: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
9093: } elsif ($author_ok eq 'ok') {
9094: my @allnew = @newlangs;
9095: if ($addedfile ne '') {
9096: push(@allnew,$addedfile);
9097: }
9098: foreach my $lang (@allnew) {
9099: my $formelem = 'loginhelpurl_'.$lang;
9100: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
9101: $formelem = 'loginhelpurl_add_file';
9102: }
9103: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9104: "help/$lang",'','',$newfile{$lang});
9105: if ($result eq 'ok') {
9106: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
9107: $changes{'helpurl'}{$lang} = 1;
9108: } else {
9109: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
9110: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 9111: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 9112: (!grep(/^\Q$lang\E$/,@delurls))) {
9113: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9114: }
9115: }
9116: }
9117: } else {
9118: $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);
9119: }
9120: } else {
9121: $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);
9122: }
9123: if ($error) {
9124: &Apache::lonnet::logthis($error);
9125: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9126: }
9127: }
1.256 raeburn 9128:
9129: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
9130: if (ref($domconfig{'login'}) eq 'HASH') {
9131: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
9132: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
9133: if ($domservers{$lonhost}) {
9134: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9135: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 9136: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 9137: }
9138: }
9139: }
9140: }
9141: }
9142: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
9143: foreach my $lonhost (sort(keys(%domservers))) {
9144: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9145: $changes{'headtag'}{$lonhost} = 1;
9146: } else {
9147: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
9148: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
9149: }
9150: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
9151: push(@newhosts,$lonhost);
9152: } elsif ($currheadtagurls{$lonhost}) {
9153: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
9154: if ($currexempt{$lonhost}) {
1.289 raeburn 9155: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 9156: $changes{'headtag'}{$lonhost} = 1;
9157: }
9158: } elsif ($possexempt{$lonhost}) {
9159: $changes{'headtag'}{$lonhost} = 1;
9160: }
9161: if ($possexempt{$lonhost}) {
9162: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9163: }
9164: }
9165: }
9166: }
9167: if (@newhosts) {
9168: my $error;
9169: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9170: if ($configuserok eq 'ok') {
9171: if ($switchserver) {
9172: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
9173: } elsif ($author_ok eq 'ok') {
9174: foreach my $lonhost (@newhosts) {
9175: my $formelem = 'loginheadtag_'.$lonhost;
9176: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9177: "login/headtag/$lonhost",'','',
9178: $env{'form.loginheadtag_'.$lonhost.'.filename'});
9179: if ($result eq 'ok') {
9180: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
9181: $changes{'headtag'}{$lonhost} = 1;
9182: if ($possexempt{$lonhost}) {
9183: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9184: }
9185: } else {
9186: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
9187: $newheadtagurls{$lonhost},$result);
9188: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
9189: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
9190: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
9191: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
9192: }
9193: }
9194: }
9195: } else {
9196: $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);
9197: }
9198: } else {
9199: $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);
9200: }
9201: if ($error) {
9202: &Apache::lonnet::logthis($error);
9203: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9204: }
9205: }
1.169 raeburn 9206: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 9207:
9208: my $defaulthelpfile = '/adm/loginproblems.html';
9209: my $defaulttext = &mt('Default in use');
9210:
1.1 raeburn 9211: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
9212: $dom);
9213: if ($putresult eq 'ok') {
1.188 raeburn 9214: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 9215: my %defaultchecked = (
9216: 'coursecatalog' => 'on',
1.188 raeburn 9217: 'helpdesk' => 'on',
1.42 raeburn 9218: 'adminmail' => 'off',
1.43 raeburn 9219: 'newuser' => 'off',
1.42 raeburn 9220: );
1.55 raeburn 9221: if (ref($domconfig{'login'}) eq 'HASH') {
9222: foreach my $item (@toggles) {
9223: if ($defaultchecked{$item} eq 'on') {
9224: if (($domconfig{'login'}{$item} eq '0') &&
9225: ($env{'form.'.$item} eq '1')) {
9226: $changes{$item} = 1;
9227: } elsif (($domconfig{'login'}{$item} eq '' ||
9228: $domconfig{'login'}{$item} eq '1') &&
9229: ($env{'form.'.$item} eq '0')) {
9230: $changes{$item} = 1;
9231: }
9232: } elsif ($defaultchecked{$item} eq 'off') {
9233: if (($domconfig{'login'}{$item} eq '1') &&
9234: ($env{'form.'.$item} eq '0')) {
9235: $changes{$item} = 1;
9236: } elsif (($domconfig{'login'}{$item} eq '' ||
9237: $domconfig{'login'}{$item} eq '0') &&
9238: ($env{'form.'.$item} eq '1')) {
9239: $changes{$item} = 1;
9240: }
1.42 raeburn 9241: }
9242: }
1.41 raeburn 9243: }
1.6 raeburn 9244: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 9245: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9246: if (ref($lastactref) eq 'HASH') {
9247: $lastactref->{'domainconfig'} = 1;
9248: }
1.1 raeburn 9249: $resulttext = &mt('Changes made:').'<ul>';
9250: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 9251: if ($item eq 'loginvia') {
1.112 raeburn 9252: if (ref($changes{$item}) eq 'HASH') {
9253: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
9254: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 9255: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
9256: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
9257: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
9258: $protocol = 'http' if ($protocol ne 'https');
9259: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
9260:
9261: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
9262: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
9263: } else {
9264: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
9265: }
9266: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
9267: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
9268: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
9269: }
9270: $resulttext .= '</li>';
9271: } else {
9272: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
9273: }
1.112 raeburn 9274: } else {
1.128 raeburn 9275: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 9276: }
9277: }
1.128 raeburn 9278: $resulttext .= '</ul></li>';
1.112 raeburn 9279: }
1.168 raeburn 9280: } elsif ($item eq 'helpurl') {
9281: if (ref($changes{$item}) eq 'HASH') {
9282: foreach my $lang (sort(keys(%{$changes{$item}}))) {
9283: if (grep(/^\Q$lang\E$/,@delurls)) {
9284: my ($chg,$link);
9285: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
9286: if ($lang eq 'nolang') {
9287: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
9288: } else {
9289: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
9290: }
9291: $resulttext .= '<li>'.$chg.'</li>';
9292: } else {
9293: my $chg;
9294: if ($lang eq 'nolang') {
9295: $chg = &mt('custom log-in help file for no preferred language');
9296: } else {
9297: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
9298: }
9299: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
9300: $loginhash{'login'}{'helpurl'}{$lang}.
9301: '?inhibitmenu=yes',$chg,600,500).
9302: '</li>';
9303: }
9304: }
9305: }
1.256 raeburn 9306: } elsif ($item eq 'headtag') {
9307: if (ref($changes{$item}) eq 'HASH') {
9308: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
9309: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9310: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
9311: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9312: $resulttext .= '<li><a href="'.
9313: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
9314: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
9315: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
9316: if ($possexempt{$lonhost}) {
9317: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
9318: } else {
9319: $resulttext .= &mt('included for any client IP');
9320: }
9321: $resulttext .= '</li>';
9322: }
9323: }
9324: }
1.169 raeburn 9325: } elsif ($item eq 'captcha') {
9326: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 9327: my $chgtxt;
1.169 raeburn 9328: if ($loginhash{'login'}{$item} eq 'notused') {
9329: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
9330: } else {
9331: my %captchas = &captcha_phrases();
9332: if ($captchas{$loginhash{'login'}{$item}}) {
9333: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
9334: } else {
9335: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
9336: }
9337: }
9338: $resulttext .= '<li>'.$chgtxt.'</li>';
9339: }
9340: } elsif ($item eq 'recaptchakeys') {
9341: if (ref($loginhash{'login'}) eq 'HASH') {
9342: my ($privkey,$pubkey);
9343: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
9344: $pubkey = $loginhash{'login'}{$item}{'public'};
9345: $privkey = $loginhash{'login'}{$item}{'private'};
9346: }
9347: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
9348: if (!$pubkey) {
9349: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
9350: } else {
9351: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
9352: }
9353: if (!$privkey) {
9354: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
9355: } else {
1.251 raeburn 9356: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 9357: }
9358: $chgtxt .= '</ul>';
9359: $resulttext .= '<li>'.$chgtxt.'</li>';
9360: }
1.269 raeburn 9361: } elsif ($item eq 'recaptchaversion') {
9362: if (ref($loginhash{'login'}) eq 'HASH') {
9363: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 9364: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 9365: '</li>';
9366: }
9367: }
1.41 raeburn 9368: } else {
9369: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
9370: }
1.1 raeburn 9371: }
1.6 raeburn 9372: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 9373: } else {
9374: $resulttext = &mt('No changes made to log-in page settings');
9375: }
9376: } else {
1.11 albertel 9377: $resulttext = '<span class="LC_error">'.
9378: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9379: }
1.6 raeburn 9380: if ($errors) {
1.9 raeburn 9381: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 9382: $errors.'</ul>';
9383: }
9384: return $resulttext;
9385: }
9386:
1.256 raeburn 9387: sub check_exempt_addresses {
9388: my ($iplist) = @_;
9389: $iplist =~ s/^\s+//;
9390: $iplist =~ s/\s+$//;
9391: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
9392: my (@okips,$new);
9393: foreach my $ip (@poss_ips) {
9394: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
9395: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
9396: push(@okips,$ip);
9397: }
9398: }
9399: }
9400: if (@okips > 0) {
9401: $new = join(',',@okips);
9402: } else {
9403: $new = '';
9404: }
9405: return $new;
9406: }
9407:
1.6 raeburn 9408: sub color_font_choices {
9409: my %choices =
9410: &Apache::lonlocal::texthash (
9411: img => "Header",
9412: bgs => "Background colors",
9413: links => "Link colors",
1.55 raeburn 9414: images => "Images",
1.6 raeburn 9415: font => "Font color",
1.201 raeburn 9416: fontmenu => "Font menu",
1.76 raeburn 9417: pgbg => "Page",
1.6 raeburn 9418: tabbg => "Header",
9419: sidebg => "Border",
9420: link => "Link",
9421: alink => "Active link",
9422: vlink => "Visited link",
9423: );
9424: return %choices;
9425: }
9426:
9427: sub modify_rolecolors {
1.205 raeburn 9428: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 9429: my ($resulttext,%rolehash);
9430: $rolehash{'rolecolors'} = {};
1.55 raeburn 9431: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
9432: if ($domconfig{'rolecolors'} eq '') {
9433: $domconfig{'rolecolors'} = {};
9434: }
9435: }
1.9 raeburn 9436: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 9437: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
9438: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
9439: $dom);
9440: if ($putresult eq 'ok') {
9441: if (keys(%changes) > 0) {
1.41 raeburn 9442: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9443: if (ref($lastactref) eq 'HASH') {
9444: $lastactref->{'domainconfig'} = 1;
9445: }
1.6 raeburn 9446: $resulttext = &display_colorchgs($dom,\%changes,$roles,
9447: $rolehash{'rolecolors'});
9448: } else {
9449: $resulttext = &mt('No changes made to default color schemes');
9450: }
9451: } else {
1.11 albertel 9452: $resulttext = '<span class="LC_error">'.
9453: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 9454: }
9455: if ($errors) {
9456: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9457: $errors.'</ul>';
9458: }
9459: return $resulttext;
9460: }
9461:
9462: sub modify_colors {
1.9 raeburn 9463: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 9464: my (%changes,%choices);
1.51 raeburn 9465: my @bgs;
1.6 raeburn 9466: my @links = ('link','alink','vlink');
1.41 raeburn 9467: my @logintext;
1.6 raeburn 9468: my @images;
9469: my $servadm = $r->dir_config('lonAdmEMail');
9470: my $errors;
1.200 raeburn 9471: my %defaults;
1.6 raeburn 9472: foreach my $role (@{$roles}) {
9473: if ($role eq 'login') {
1.12 raeburn 9474: %choices = &login_choices();
1.41 raeburn 9475: @logintext = ('textcol','bgcol');
1.12 raeburn 9476: } else {
9477: %choices = &color_font_choices();
9478: }
9479: if ($role eq 'login') {
1.41 raeburn 9480: @images = ('img','logo','domlogo','login');
1.51 raeburn 9481: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 9482: } else {
9483: @images = ('img');
1.200 raeburn 9484: @bgs = ('pgbg','tabbg','sidebg');
9485: }
9486: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
9487: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
9488: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
9489: }
9490: if ($role eq 'login') {
9491: foreach my $item (@logintext) {
1.234 raeburn 9492: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9493: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9494: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9495: }
9496: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 9497: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9498: }
9499: }
9500: } else {
1.234 raeburn 9501: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
9502: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
9503: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
9504: }
9505: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 9506: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
9507: }
1.6 raeburn 9508: }
1.200 raeburn 9509: foreach my $item (@bgs) {
1.234 raeburn 9510: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9511: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9512: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9513: }
9514: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 9515: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9516: }
9517: }
9518: foreach my $item (@links) {
1.234 raeburn 9519: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9520: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9521: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9522: }
9523: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 9524: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9525: }
1.6 raeburn 9526: }
1.46 raeburn 9527: my ($configuserok,$author_ok,$switchserver) =
9528: &config_check($dom,$confname,$servadm);
1.9 raeburn 9529: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 9530: if (ref($domconfig->{$role}) ne 'HASH') {
9531: $domconfig->{$role} = {};
9532: }
1.8 raeburn 9533: foreach my $img (@images) {
1.70 raeburn 9534: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
9535: if (defined($env{'form.login_showlogo_'.$img})) {
9536: $confhash->{$role}{'showlogo'}{$img} = 1;
9537: } else {
9538: $confhash->{$role}{'showlogo'}{$img} = 0;
9539: }
9540: }
1.18 albertel 9541: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
9542: && !defined($domconfig->{$role}{$img})
9543: && !$env{'form.'.$role.'_del_'.$img}
9544: && $env{'form.'.$role.'_import_'.$img}) {
9545: # import the old configured image from the .tab setting
9546: # if they haven't provided a new one
9547: $domconfig->{$role}{$img} =
9548: $env{'form.'.$role.'_import_'.$img};
9549: }
1.6 raeburn 9550: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 9551: my $error;
1.6 raeburn 9552: if ($configuserok eq 'ok') {
1.9 raeburn 9553: if ($switchserver) {
1.12 raeburn 9554: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 9555: } else {
9556: if ($author_ok eq 'ok') {
9557: my ($result,$logourl) =
9558: &publishlogo($r,'upload',$role.'_'.$img,
9559: $dom,$confname,$img,$width,$height);
9560: if ($result eq 'ok') {
9561: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 9562: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 9563: } else {
1.12 raeburn 9564: $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 9565: }
9566: } else {
1.46 raeburn 9567: $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 9568: }
9569: }
9570: } else {
1.46 raeburn 9571: $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 9572: }
9573: if ($error) {
1.8 raeburn 9574: &Apache::lonnet::logthis($error);
1.11 albertel 9575: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 9576: }
9577: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 9578: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
9579: my $error;
9580: if ($configuserok eq 'ok') {
9581: # is confname an author?
9582: if ($switchserver eq '') {
9583: if ($author_ok eq 'ok') {
9584: my ($result,$logourl) =
9585: &publishlogo($r,'copy',$domconfig->{$role}{$img},
9586: $dom,$confname,$img,$width,$height);
9587: if ($result eq 'ok') {
9588: $confhash->{$role}{$img} = $logourl;
1.18 albertel 9589: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 9590: }
9591: }
9592: }
9593: }
1.6 raeburn 9594: }
9595: }
9596: }
9597: if (ref($domconfig) eq 'HASH') {
9598: if (ref($domconfig->{$role}) eq 'HASH') {
9599: foreach my $img (@images) {
9600: if ($domconfig->{$role}{$img} ne '') {
9601: if ($env{'form.'.$role.'_del_'.$img}) {
9602: $confhash->{$role}{$img} = '';
1.12 raeburn 9603: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 9604: } else {
1.9 raeburn 9605: if ($confhash->{$role}{$img} eq '') {
9606: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
9607: }
1.6 raeburn 9608: }
9609: } else {
9610: if ($env{'form.'.$role.'_del_'.$img}) {
9611: $confhash->{$role}{$img} = '';
1.12 raeburn 9612: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 9613: }
9614: }
1.70 raeburn 9615: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
9616: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
9617: if ($confhash->{$role}{'showlogo'}{$img} ne
9618: $domconfig->{$role}{'showlogo'}{$img}) {
9619: $changes{$role}{'showlogo'}{$img} = 1;
9620: }
9621: } else {
9622: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
9623: $changes{$role}{'showlogo'}{$img} = 1;
9624: }
9625: }
9626: }
9627: }
1.6 raeburn 9628: if ($domconfig->{$role}{'font'} ne '') {
9629: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
9630: $changes{$role}{'font'} = 1;
9631: }
9632: } else {
9633: if ($confhash->{$role}{'font'}) {
9634: $changes{$role}{'font'} = 1;
9635: }
9636: }
1.107 raeburn 9637: if ($role ne 'login') {
9638: if ($domconfig->{$role}{'fontmenu'} ne '') {
9639: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
9640: $changes{$role}{'fontmenu'} = 1;
9641: }
9642: } else {
9643: if ($confhash->{$role}{'fontmenu'}) {
9644: $changes{$role}{'fontmenu'} = 1;
9645: }
1.97 tempelho 9646: }
9647: }
1.6 raeburn 9648: foreach my $item (@bgs) {
9649: if ($domconfig->{$role}{$item} ne '') {
9650: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9651: $changes{$role}{'bgs'}{$item} = 1;
9652: }
9653: } else {
9654: if ($confhash->{$role}{$item}) {
9655: $changes{$role}{'bgs'}{$item} = 1;
9656: }
9657: }
9658: }
9659: foreach my $item (@links) {
9660: if ($domconfig->{$role}{$item} ne '') {
9661: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9662: $changes{$role}{'links'}{$item} = 1;
9663: }
9664: } else {
9665: if ($confhash->{$role}{$item}) {
9666: $changes{$role}{'links'}{$item} = 1;
9667: }
9668: }
9669: }
1.41 raeburn 9670: foreach my $item (@logintext) {
9671: if ($domconfig->{$role}{$item} ne '') {
9672: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9673: $changes{$role}{'logintext'}{$item} = 1;
9674: }
9675: } else {
9676: if ($confhash->{$role}{$item}) {
9677: $changes{$role}{'logintext'}{$item} = 1;
9678: }
9679: }
9680: }
1.6 raeburn 9681: } else {
9682: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 9683: \@logintext,$confhash,\%changes);
1.6 raeburn 9684: }
9685: } else {
9686: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 9687: \@logintext,$confhash,\%changes);
1.6 raeburn 9688: }
9689: }
9690: return ($errors,%changes);
9691: }
9692:
1.46 raeburn 9693: sub config_check {
9694: my ($dom,$confname,$servadm) = @_;
9695: my ($configuserok,$author_ok,$switchserver,%currroles);
9696: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
9697: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
9698: $confname,$servadm);
9699: if ($configuserok eq 'ok') {
9700: $switchserver = &check_switchserver($dom,$confname);
9701: if ($switchserver eq '') {
9702: $author_ok = &check_authorstatus($dom,$confname,%currroles);
9703: }
9704: }
9705: return ($configuserok,$author_ok,$switchserver);
9706: }
9707:
1.6 raeburn 9708: sub default_change_checker {
1.41 raeburn 9709: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 9710: foreach my $item (@{$links}) {
9711: if ($confhash->{$role}{$item}) {
9712: $changes->{$role}{'links'}{$item} = 1;
9713: }
9714: }
9715: foreach my $item (@{$bgs}) {
9716: if ($confhash->{$role}{$item}) {
9717: $changes->{$role}{'bgs'}{$item} = 1;
9718: }
9719: }
1.41 raeburn 9720: foreach my $item (@{$logintext}) {
9721: if ($confhash->{$role}{$item}) {
9722: $changes->{$role}{'logintext'}{$item} = 1;
9723: }
9724: }
1.6 raeburn 9725: foreach my $img (@{$images}) {
9726: if ($env{'form.'.$role.'_del_'.$img}) {
9727: $confhash->{$role}{$img} = '';
1.12 raeburn 9728: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 9729: }
1.70 raeburn 9730: if ($role eq 'login') {
9731: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
9732: $changes->{$role}{'showlogo'}{$img} = 1;
9733: }
9734: }
1.6 raeburn 9735: }
9736: if ($confhash->{$role}{'font'}) {
9737: $changes->{$role}{'font'} = 1;
9738: }
1.48 raeburn 9739: }
1.6 raeburn 9740:
9741: sub display_colorchgs {
9742: my ($dom,$changes,$roles,$confhash) = @_;
9743: my (%choices,$resulttext);
9744: if (!grep(/^login$/,@{$roles})) {
9745: $resulttext = &mt('Changes made:').'<br />';
9746: }
9747: foreach my $role (@{$roles}) {
9748: if ($role eq 'login') {
9749: %choices = &login_choices();
9750: } else {
9751: %choices = &color_font_choices();
9752: }
9753: if (ref($changes->{$role}) eq 'HASH') {
9754: if ($role ne 'login') {
9755: $resulttext .= '<h4>'.&mt($role).'</h4>';
9756: }
9757: foreach my $key (sort(keys(%{$changes->{$role}}))) {
9758: if ($role ne 'login') {
9759: $resulttext .= '<ul>';
9760: }
9761: if (ref($changes->{$role}{$key}) eq 'HASH') {
9762: if ($role ne 'login') {
9763: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
9764: }
9765: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 9766: if (($role eq 'login') && ($key eq 'showlogo')) {
9767: if ($confhash->{$role}{$key}{$item}) {
9768: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
9769: } else {
9770: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
9771: }
9772: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 9773: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
9774: } else {
1.12 raeburn 9775: my $newitem = $confhash->{$role}{$item};
9776: if ($key eq 'images') {
1.306 raeburn 9777: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 9778: }
9779: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 9780: }
9781: }
9782: if ($role ne 'login') {
9783: $resulttext .= '</ul></li>';
9784: }
9785: } else {
9786: if ($confhash->{$role}{$key} eq '') {
9787: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
9788: } else {
9789: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
9790: }
9791: }
9792: if ($role ne 'login') {
9793: $resulttext .= '</ul>';
9794: }
9795: }
9796: }
9797: }
1.3 raeburn 9798: return $resulttext;
1.1 raeburn 9799: }
9800:
1.9 raeburn 9801: sub thumb_dimensions {
9802: return ('200','50');
9803: }
9804:
1.16 raeburn 9805: sub check_dimensions {
9806: my ($inputfile) = @_;
9807: my ($fullwidth,$fullheight);
9808: if ($inputfile =~ m|^[/\w.\-]+$|) {
9809: if (open(PIPE,"identify $inputfile 2>&1 |")) {
9810: my $imageinfo = <PIPE>;
9811: if (!close(PIPE)) {
9812: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
9813: }
9814: chomp($imageinfo);
9815: my ($fullsize) =
1.21 raeburn 9816: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 9817: if ($fullsize) {
9818: ($fullwidth,$fullheight) = split(/x/,$fullsize);
9819: }
9820: }
9821: }
9822: return ($fullwidth,$fullheight);
9823: }
9824:
1.9 raeburn 9825: sub check_configuser {
9826: my ($uhome,$dom,$confname,$servadm) = @_;
9827: my ($configuserok,%currroles);
9828: if ($uhome eq 'no_host') {
9829: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
9830: my $configpass = &LONCAPA::Enrollment::create_password();
9831: $configuserok =
9832: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
9833: $configpass,'','','','','',undef,$servadm);
9834: } else {
9835: $configuserok = 'ok';
9836: %currroles =
9837: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
9838: }
9839: return ($configuserok,%currroles);
9840: }
9841:
9842: sub check_authorstatus {
9843: my ($dom,$confname,%currroles) = @_;
9844: my $author_ok;
1.40 raeburn 9845: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 9846: my $start = time;
9847: my $end = 0;
9848: $author_ok =
9849: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 9850: 'au',$end,$start,'','','domconfig');
1.9 raeburn 9851: } else {
9852: $author_ok = 'ok';
9853: }
9854: return $author_ok;
9855: }
9856:
9857: sub publishlogo {
1.46 raeburn 9858: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 9859: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 9860: if ($action eq 'upload') {
9861: $fname=$env{'form.'.$formname.'.filename'};
9862: chop($env{'form.'.$formname});
9863: } else {
9864: ($fname) = ($formname =~ /([^\/]+)$/);
9865: }
1.46 raeburn 9866: if ($savefileas ne '') {
9867: $fname = $savefileas;
9868: }
1.9 raeburn 9869: $fname=&Apache::lonnet::clean_filename($fname);
9870: # See if there is anything left
9871: unless ($fname) { return ('error: no uploaded file'); }
9872: $fname="$subdir/$fname";
1.210 raeburn 9873: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 9874: my $filepath="$docroot/priv";
9875: my $relpath = "$dom/$confname";
1.9 raeburn 9876: my ($fnamepath,$file,$fetchthumb);
9877: $file=$fname;
9878: if ($fname=~m|/|) {
9879: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
9880: }
1.164 raeburn 9881: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 9882: my $count;
1.164 raeburn 9883: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 9884: $filepath.="/$parts[$count]";
9885: if ((-e $filepath)!=1) {
9886: mkdir($filepath,02770);
9887: }
9888: }
9889: # Check for bad extension and disallow upload
9890: if ($file=~/\.(\w+)$/ &&
9891: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
9892: $output =
1.207 bisitz 9893: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 9894: } elsif ($file=~/\.(\w+)$/ &&
9895: !defined(&Apache::loncommon::fileembstyle($1))) {
9896: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
9897: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 9898: $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 9899: } elsif (-d "$filepath/$file") {
1.195 bisitz 9900: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 9901: } else {
9902: my $source = $filepath.'/'.$file;
9903: my $logfile;
1.316 raeburn 9904: if (!open($logfile,">>",$source.'.log')) {
1.196 raeburn 9905: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 9906: }
9907: print $logfile
9908: "\n================= Publish ".localtime()." ================\n".
9909: $env{'user.name'}.':'.$env{'user.domain'}."\n";
9910: # Save the file
1.316 raeburn 9911: if (!open(FH,">",$source)) {
1.9 raeburn 9912: &Apache::lonnet::logthis('Failed to create '.$source);
9913: return (&mt('Failed to create file'));
9914: }
9915: if ($action eq 'upload') {
9916: if (!print FH ($env{'form.'.$formname})) {
9917: &Apache::lonnet::logthis('Failed to write to '.$source);
9918: return (&mt('Failed to write file'));
9919: }
9920: } else {
9921: my $original = &Apache::lonnet::filelocation('',$formname);
9922: if(!copy($original,$source)) {
9923: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
9924: return (&mt('Failed to write file'));
9925: }
9926: }
9927: close(FH);
9928: chmod(0660, $source); # Permissions to rw-rw---.
9929:
9930: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
9931: my $copyfile=$targetdir.'/'.$file;
9932:
9933: my @parts=split(/\//,$targetdir);
9934: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
9935: for (my $count=5;$count<=$#parts;$count++) {
9936: $path.="/$parts[$count]";
9937: if (!-e $path) {
9938: print $logfile "\nCreating directory ".$path;
9939: mkdir($path,02770);
9940: }
9941: }
9942: my $versionresult;
9943: if (-e $copyfile) {
9944: $versionresult = &logo_versioning($targetdir,$file,$logfile);
9945: } else {
9946: $versionresult = 'ok';
9947: }
9948: if ($versionresult eq 'ok') {
9949: if (copy($source,$copyfile)) {
9950: print $logfile "\nCopied original source to ".$copyfile."\n";
9951: $output = 'ok';
9952: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 9953: push(@{$modified_urls},[$copyfile,$source]);
9954: my $metaoutput =
9955: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
9956: unless ($registered_cleanup) {
9957: my $handlers = $r->get_handlers('PerlCleanupHandler');
9958: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
9959: $registered_cleanup=1;
9960: }
1.9 raeburn 9961: } else {
9962: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
9963: $output = &mt('Failed to copy file to RES space').", $!";
9964: }
9965: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
9966: my $inputfile = $filepath.'/'.$file;
9967: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 9968: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
9969: if ($fullwidth ne '' && $fullheight ne '') {
9970: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
9971: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316 raeburn 9972: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
9973: system({$args[0]} @args);
1.16 raeburn 9974: chmod(0660, $filepath.'/tn-'.$file);
9975: if (-e $outfile) {
9976: my $copyfile=$targetdir.'/tn-'.$file;
9977: if (copy($outfile,$copyfile)) {
9978: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 9979: my $thumb_metaoutput =
9980: &write_metadata($dom,$confname,$formname,
9981: $targetdir,'tn-'.$file,$logfile);
9982: push(@{$modified_urls},[$copyfile,$outfile]);
9983: unless ($registered_cleanup) {
9984: my $handlers = $r->get_handlers('PerlCleanupHandler');
9985: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
9986: $registered_cleanup=1;
9987: }
1.267 raeburn 9988: $madethumb = 1;
1.16 raeburn 9989: } else {
9990: print $logfile "\nUnable to write ".$copyfile.
9991: ':'.$!."\n";
9992: }
9993: }
1.9 raeburn 9994: }
9995: }
9996: }
9997: } else {
9998: $output = $versionresult;
9999: }
10000: }
1.267 raeburn 10001: return ($output,$logourl,$madethumb);
1.9 raeburn 10002: }
10003:
10004: sub logo_versioning {
10005: my ($targetdir,$file,$logfile) = @_;
10006: my $target = $targetdir.'/'.$file;
10007: my ($maxversion,$fn,$extn,$output);
10008: $maxversion = 0;
10009: if ($file =~ /^(.+)\.(\w+)$/) {
10010: $fn=$1;
10011: $extn=$2;
10012: }
10013: opendir(DIR,$targetdir);
10014: while (my $filename=readdir(DIR)) {
10015: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
10016: $maxversion=($1>$maxversion)?$1:$maxversion;
10017: }
10018: }
10019: $maxversion++;
10020: print $logfile "\nCreating old version ".$maxversion."\n";
10021: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
10022: if (copy($target,$copyfile)) {
10023: print $logfile "Copied old target to ".$copyfile."\n";
10024: $copyfile=$copyfile.'.meta';
10025: if (copy($target.'.meta',$copyfile)) {
10026: print $logfile "Copied old target metadata to ".$copyfile."\n";
10027: $output = 'ok';
10028: } else {
10029: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
10030: $output = &mt('Failed to copy old meta').", $!, ";
10031: }
10032: } else {
10033: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
10034: $output = &mt('Failed to copy old target').", $!, ";
10035: }
10036: return $output;
10037: }
10038:
10039: sub write_metadata {
10040: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
10041: my (%metadatafields,%metadatakeys,$output);
10042: $metadatafields{'title'}=$formname;
10043: $metadatafields{'creationdate'}=time;
10044: $metadatafields{'lastrevisiondate'}=time;
10045: $metadatafields{'copyright'}='public';
10046: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
10047: $env{'user.domain'};
10048: $metadatafields{'authorspace'}=$confname.':'.$dom;
10049: $metadatafields{'domain'}=$dom;
10050: {
10051: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
10052: my $mfh;
1.316 raeburn 10053: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 10054: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 10055: unless ($_=~/\./) {
10056: my $unikey=$_;
10057: $unikey=~/^([A-Za-z]+)/;
10058: my $tag=$1;
10059: $tag=~tr/A-Z/a-z/;
10060: print $mfh "\n\<$tag";
10061: foreach (split(/\,/,$metadatakeys{$unikey})) {
10062: my $value=$metadatafields{$unikey.'.'.$_};
10063: $value=~s/\"/\'\'/g;
10064: print $mfh ' '.$_.'="'.$value.'"';
10065: }
10066: print $mfh '>'.
10067: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
10068: .'</'.$tag.'>';
10069: }
10070: }
10071: $output = 'ok';
10072: print $logfile "\nWrote metadata";
10073: close($mfh);
10074: } else {
10075: print $logfile "\nFailed to open metadata file";
1.9 raeburn 10076: $output = &mt('Could not write metadata');
10077: }
10078: }
1.155 raeburn 10079: return $output;
10080: }
10081:
10082: sub notifysubscribed {
10083: foreach my $targetsource (@{$modified_urls}){
10084: next unless (ref($targetsource) eq 'ARRAY');
10085: my ($target,$source)=@{$targetsource};
10086: if ($source ne '') {
1.316 raeburn 10087: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 10088: print $logfh "\nCleanup phase: Notifications\n";
10089: my @subscribed=&subscribed_hosts($target);
10090: foreach my $subhost (@subscribed) {
10091: print $logfh "\nNotifying host ".$subhost.':';
10092: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
10093: print $logfh $reply;
10094: }
10095: my @subscribedmeta=&subscribed_hosts("$target.meta");
10096: foreach my $subhost (@subscribedmeta) {
10097: print $logfh "\nNotifying host for metadata only ".$subhost.':';
10098: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
10099: $subhost);
10100: print $logfh $reply;
10101: }
10102: print $logfh "\n============ Done ============\n";
1.160 raeburn 10103: close($logfh);
1.155 raeburn 10104: }
10105: }
10106: }
10107: return OK;
10108: }
10109:
10110: sub subscribed_hosts {
10111: my ($target) = @_;
10112: my @subscribed;
1.316 raeburn 10113: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 10114: while (my $subline=<$fh>) {
10115: if ($subline =~ /^($match_lonid):/) {
10116: my $host = $1;
10117: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
10118: unless (grep(/^\Q$host\E$/,@subscribed)) {
10119: push(@subscribed,$host);
10120: }
10121: }
10122: }
10123: }
10124: }
10125: return @subscribed;
1.9 raeburn 10126: }
10127:
10128: sub check_switchserver {
10129: my ($dom,$confname) = @_;
10130: my ($allowed,$switchserver);
10131: my $home = &Apache::lonnet::homeserver($confname,$dom);
10132: if ($home eq 'no_host') {
10133: $home = &Apache::lonnet::domain($dom,'primary');
10134: }
10135: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 10136: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
10137: if (!$allowed) {
1.180 raeburn 10138: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 10139: }
10140: return $switchserver;
10141: }
10142:
1.1 raeburn 10143: sub modify_quotas {
1.216 raeburn 10144: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 10145: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 10146: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 10147: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
10148: $validationfieldsref);
1.86 raeburn 10149: if ($action eq 'quotas') {
10150: $context = 'tools';
1.163 raeburn 10151: } else {
1.86 raeburn 10152: $context = $action;
10153: }
10154: if ($context eq 'requestcourses') {
1.325 raeburn 10155: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 10156: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 10157: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
10158: %titles = &courserequest_titles();
10159: $toolregexp = join('|',@usertools);
10160: %conditions = &courserequest_conditions();
1.216 raeburn 10161: $confname = $dom.'-domainconfig';
10162: my $servadm = $r->dir_config('lonAdmEMail');
10163: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 10164: ($validationitemsref,$validationnamesref,$validationfieldsref) =
10165: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 10166: } elsif ($context eq 'requestauthor') {
10167: @usertools = ('author');
10168: %titles = &authorrequest_titles();
1.86 raeburn 10169: } else {
1.162 raeburn 10170: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 10171: %titles = &tool_titles();
1.86 raeburn 10172: }
1.212 raeburn 10173: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 10174: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 10175: foreach my $key (keys(%env)) {
1.101 raeburn 10176: if ($context eq 'requestcourses') {
10177: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
10178: my $item = $1;
10179: my $type = $2;
10180: if ($type =~ /^limit_(.+)/) {
10181: $limithash{$item}{$1} = $env{$key};
10182: } else {
10183: $confhash{$item}{$type} = $env{$key};
10184: }
10185: }
1.163 raeburn 10186: } elsif ($context eq 'requestauthor') {
10187: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
10188: $confhash{$1} = $env{$key};
10189: }
1.101 raeburn 10190: } else {
1.86 raeburn 10191: if ($key =~ /^form\.quota_(.+)$/) {
10192: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 10193: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
10194: $confhash{'authorquota'}{$1} = $env{$key};
10195: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 10196: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
10197: }
1.72 raeburn 10198: }
10199: }
1.163 raeburn 10200: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 10201: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 10202: @approvalnotify = sort(@approvalnotify);
10203: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 10204: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 10205: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
10206: foreach my $type (@hasuniquecode) {
10207: if (grep(/^\Q$type\E$/,@crstypes)) {
10208: $confhash{'uniquecode'}{$type} = 1;
10209: }
1.216 raeburn 10210: }
1.242 raeburn 10211: my (%newbook,%allpos);
1.216 raeburn 10212: if ($context eq 'requestcourses') {
1.242 raeburn 10213: foreach my $type ('textbooks','templates') {
10214: @{$allpos{$type}} = ();
10215: my $invalid;
10216: if ($type eq 'textbooks') {
10217: $invalid = &mt('Invalid LON-CAPA course for textbook');
10218: } else {
10219: $invalid = &mt('Invalid LON-CAPA course for template');
10220: }
10221: if ($env{'form.'.$type.'_addbook'}) {
10222: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
10223: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
10224: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
10225: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
10226: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
10227: } else {
10228: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
10229: my $position = $env{'form.'.$type.'_addbook_pos'};
10230: $position =~ s/\D+//g;
10231: if ($position ne '') {
10232: $allpos{$type}[$position] = $newbook{$type};
10233: }
1.216 raeburn 10234: }
1.242 raeburn 10235: } else {
10236: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 10237: }
10238: }
1.242 raeburn 10239: }
1.216 raeburn 10240: }
1.102 raeburn 10241: if (ref($domconfig{$action}) eq 'HASH') {
10242: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
10243: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
10244: $changes{'notify'}{'approval'} = 1;
10245: }
10246: } else {
1.144 raeburn 10247: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10248: $changes{'notify'}{'approval'} = 1;
10249: }
10250: }
1.218 raeburn 10251: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
10252: if (ref($confhash{'uniquecode'}) eq 'HASH') {
10253: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
10254: unless ($confhash{'uniquecode'}{$crstype}) {
10255: $changes{'uniquecode'} = 1;
10256: }
10257: }
10258: unless ($changes{'uniquecode'}) {
10259: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
10260: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
10261: $changes{'uniquecode'} = 1;
10262: }
10263: }
10264: }
10265: } else {
10266: $changes{'uniquecode'} = 1;
10267: }
10268: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
10269: $changes{'uniquecode'} = 1;
1.216 raeburn 10270: }
10271: if ($context eq 'requestcourses') {
1.242 raeburn 10272: foreach my $type ('textbooks','templates') {
10273: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10274: my %deletions;
10275: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
10276: if (@todelete) {
10277: map { $deletions{$_} = 1; } @todelete;
10278: }
10279: my %imgdeletions;
10280: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
10281: if (@todeleteimages) {
10282: map { $imgdeletions{$_} = 1; } @todeleteimages;
10283: }
10284: my $maxnum = $env{'form.'.$type.'_maxnum'};
10285: for (my $i=0; $i<=$maxnum; $i++) {
10286: my $itemid = $env{'form.'.$type.'_id_'.$i};
10287: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
10288: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
10289: if ($deletions{$key}) {
10290: if ($domconfig{$action}{$type}{$key}{'image'}) {
10291: #FIXME need to obsolete item in RES space
10292: }
10293: next;
10294: } else {
10295: my $newpos = $env{'form.'.$itemid};
10296: $newpos =~ s/\D+//g;
1.243 raeburn 10297: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 10298: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 10299: ($type eq 'templates'));
1.242 raeburn 10300: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
10301: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
10302: $changes{$type}{$key} = 1;
10303: }
10304: }
10305: $allpos{$type}[$newpos] = $key;
10306: }
10307: if ($imgdeletions{$key}) {
10308: $changes{$type}{$key} = 1;
1.216 raeburn 10309: #FIXME need to obsolete item in RES space
1.242 raeburn 10310: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
10311: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 10312: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10313: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10314: } else {
10315: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
10316: $cdom,$cnum,$type,$configuserok,
10317: $switchserver,$author_ok);
10318: if ($imgurl) {
10319: $confhash{$type}{$key}{'image'} = $imgurl;
10320: $changes{$type}{$key} = 1;
10321: }
10322: if ($error) {
10323: &Apache::lonnet::logthis($error);
10324: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10325: }
10326: }
1.242 raeburn 10327: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
10328: $confhash{$type}{$key}{'image'} =
10329: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 10330: }
10331: }
10332: }
10333: }
10334: }
10335: }
1.102 raeburn 10336: } else {
1.144 raeburn 10337: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10338: $changes{'notify'}{'approval'} = 1;
10339: }
1.218 raeburn 10340: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 10341: $changes{'uniquecode'} = 1;
10342: }
10343: }
10344: if ($context eq 'requestcourses') {
1.242 raeburn 10345: foreach my $type ('textbooks','templates') {
10346: if ($newbook{$type}) {
10347: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 10348: foreach my $item ('subject','title','publisher','author') {
10349: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10350: ($type eq 'template'));
1.242 raeburn 10351: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
10352: if ($env{'form.'.$type.'_addbook_'.$item}) {
10353: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
10354: }
10355: }
10356: if ($type eq 'textbooks') {
10357: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
10358: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 10359: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10360: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10361: } else {
10362: my ($imageurl,$error) =
10363: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
10364: $configuserok,$switchserver,$author_ok);
10365: if ($imageurl) {
10366: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
10367: }
10368: if ($error) {
10369: &Apache::lonnet::logthis($error);
10370: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10371: }
1.242 raeburn 10372: }
10373: }
1.216 raeburn 10374: }
10375: }
1.242 raeburn 10376: if (@{$allpos{$type}} > 0) {
10377: my $idx = 0;
10378: foreach my $item (@{$allpos{$type}}) {
10379: if ($item ne '') {
10380: $confhash{$type}{$item}{'order'} = $idx;
10381: if (ref($domconfig{$action}) eq 'HASH') {
10382: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10383: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
10384: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
10385: $changes{$type}{$item} = 1;
10386: }
1.216 raeburn 10387: }
10388: }
10389: }
1.242 raeburn 10390: $idx ++;
1.216 raeburn 10391: }
10392: }
10393: }
10394: }
1.235 raeburn 10395: if (ref($validationitemsref) eq 'ARRAY') {
10396: foreach my $item (@{$validationitemsref}) {
10397: if ($item eq 'fields') {
10398: my @changed;
10399: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
10400: if (@{$confhash{'validation'}{$item}} > 0) {
10401: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
10402: }
1.266 raeburn 10403: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10404: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10405: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
10406: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
10407: $domconfig{'requestcourses'}{'validation'}{$item});
10408: } else {
10409: @changed = @{$confhash{'validation'}{$item}};
10410: }
1.235 raeburn 10411: } else {
10412: @changed = @{$confhash{'validation'}{$item}};
10413: }
10414: } else {
10415: @changed = @{$confhash{'validation'}{$item}};
10416: }
10417: if (@changed) {
10418: if ($confhash{'validation'}{$item}) {
10419: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
10420: } else {
10421: $changes{'validation'}{$item} = &mt('None');
10422: }
10423: }
10424: } else {
10425: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
10426: if ($item eq 'markup') {
10427: if ($env{'form.requestcourses_validation_'.$item}) {
10428: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10429: }
10430: }
1.266 raeburn 10431: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10432: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10433: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
10434: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10435: }
10436: } else {
10437: if ($confhash{'validation'}{$item} ne '') {
10438: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10439: }
1.235 raeburn 10440: }
10441: } else {
10442: if ($confhash{'validation'}{$item} ne '') {
10443: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10444: }
10445: }
10446: }
10447: }
10448: }
10449: if ($env{'form.validationdc'}) {
10450: my $newval = $env{'form.validationdc'};
1.285 raeburn 10451: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 10452: if (exists($domcoords{$newval})) {
10453: $confhash{'validation'}{'dc'} = $newval;
10454: }
10455: }
10456: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 10457: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10458: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10459: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10460: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
10461: if ($confhash{'validation'}{'dc'} eq '') {
10462: $changes{'validation'}{'dc'} = &mt('None');
10463: } else {
10464: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10465: }
1.235 raeburn 10466: }
1.266 raeburn 10467: } elsif ($confhash{'validation'}{'dc'} ne '') {
10468: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 10469: }
10470: } elsif ($confhash{'validation'}{'dc'} ne '') {
10471: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10472: }
10473: } elsif ($confhash{'validation'}{'dc'} ne '') {
10474: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 10475: }
1.266 raeburn 10476: } else {
10477: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10478: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10479: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10480: $changes{'validation'}{'dc'} = &mt('None');
10481: }
10482: }
1.235 raeburn 10483: }
10484: }
1.102 raeburn 10485: }
10486: } else {
1.86 raeburn 10487: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 10488: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 10489: }
1.72 raeburn 10490: foreach my $item (@usertools) {
10491: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 10492: my $unset;
1.101 raeburn 10493: if ($context eq 'requestcourses') {
1.104 raeburn 10494: $unset = '0';
10495: if ($type eq '_LC_adv') {
10496: $unset = '';
10497: }
1.101 raeburn 10498: if ($confhash{$item}{$type} eq 'autolimit') {
10499: $confhash{$item}{$type} .= '=';
10500: unless ($limithash{$item}{$type} =~ /\D/) {
10501: $confhash{$item}{$type} .= $limithash{$item}{$type};
10502: }
10503: }
1.163 raeburn 10504: } elsif ($context eq 'requestauthor') {
10505: $unset = '0';
10506: if ($type eq '_LC_adv') {
10507: $unset = '';
10508: }
1.72 raeburn 10509: } else {
1.101 raeburn 10510: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
10511: $confhash{$item}{$type} = 1;
10512: } else {
10513: $confhash{$item}{$type} = 0;
10514: }
1.72 raeburn 10515: }
1.86 raeburn 10516: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 10517: if ($action eq 'requestauthor') {
10518: if ($domconfig{$action}{$type} ne $confhash{$type}) {
10519: $changes{$type} = 1;
10520: }
10521: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 10522: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
10523: $changes{$item}{$type} = 1;
10524: }
10525: } else {
10526: if ($context eq 'requestcourses') {
1.104 raeburn 10527: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 10528: $changes{$item}{$type} = 1;
10529: }
10530: } else {
10531: if (!$confhash{$item}{$type}) {
10532: $changes{$item}{$type} = 1;
10533: }
10534: }
10535: }
10536: } else {
10537: if ($context eq 'requestcourses') {
1.104 raeburn 10538: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 10539: $changes{$item}{$type} = 1;
10540: }
1.163 raeburn 10541: } elsif ($context eq 'requestauthor') {
10542: if ($confhash{$type} ne $unset) {
10543: $changes{$type} = 1;
10544: }
1.72 raeburn 10545: } else {
10546: if (!$confhash{$item}{$type}) {
10547: $changes{$item}{$type} = 1;
10548: }
10549: }
10550: }
1.1 raeburn 10551: }
10552: }
1.163 raeburn 10553: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 10554: if (ref($domconfig{'quotas'}) eq 'HASH') {
10555: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
10556: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
10557: if (exists($confhash{'defaultquota'}{$key})) {
10558: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
10559: $changes{'defaultquota'}{$key} = 1;
10560: }
10561: } else {
10562: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 10563: }
10564: }
1.86 raeburn 10565: } else {
10566: foreach my $key (keys(%{$domconfig{'quotas'}})) {
10567: if (exists($confhash{'defaultquota'}{$key})) {
10568: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
10569: $changes{'defaultquota'}{$key} = 1;
10570: }
10571: } else {
10572: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 10573: }
1.1 raeburn 10574: }
10575: }
1.197 raeburn 10576: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
10577: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
10578: if (exists($confhash{'authorquota'}{$key})) {
10579: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
10580: $changes{'authorquota'}{$key} = 1;
10581: }
10582: } else {
10583: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
10584: }
10585: }
10586: }
1.1 raeburn 10587: }
1.86 raeburn 10588: if (ref($confhash{'defaultquota'}) eq 'HASH') {
10589: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
10590: if (ref($domconfig{'quotas'}) eq 'HASH') {
10591: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
10592: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
10593: $changes{'defaultquota'}{$key} = 1;
10594: }
10595: } else {
10596: if (!exists($domconfig{'quotas'}{$key})) {
10597: $changes{'defaultquota'}{$key} = 1;
10598: }
1.72 raeburn 10599: }
10600: } else {
1.86 raeburn 10601: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 10602: }
1.1 raeburn 10603: }
10604: }
1.197 raeburn 10605: if (ref($confhash{'authorquota'}) eq 'HASH') {
10606: foreach my $key (keys(%{$confhash{'authorquota'}})) {
10607: if (ref($domconfig{'quotas'}) eq 'HASH') {
10608: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
10609: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
10610: $changes{'authorquota'}{$key} = 1;
10611: }
10612: } else {
10613: $changes{'authorquota'}{$key} = 1;
10614: }
10615: } else {
10616: $changes{'authorquota'}{$key} = 1;
10617: }
10618: }
10619: }
1.1 raeburn 10620: }
1.72 raeburn 10621:
1.163 raeburn 10622: if ($context eq 'requestauthor') {
10623: $domdefaults{'requestauthor'} = \%confhash;
10624: } else {
10625: foreach my $key (keys(%confhash)) {
1.242 raeburn 10626: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 10627: $domdefaults{$key} = $confhash{$key};
10628: }
1.163 raeburn 10629: }
1.72 raeburn 10630: }
1.163 raeburn 10631:
1.1 raeburn 10632: my %quotahash = (
1.86 raeburn 10633: $action => { %confhash }
1.1 raeburn 10634: );
10635: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
10636: $dom);
10637: if ($putresult eq 'ok') {
10638: if (keys(%changes) > 0) {
1.72 raeburn 10639: my $cachetime = 24*60*60;
10640: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 10641: if (ref($lastactref) eq 'HASH') {
10642: $lastactref->{'domdefaults'} = 1;
10643: }
1.1 raeburn 10644: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 10645: unless (($context eq 'requestcourses') ||
1.163 raeburn 10646: ($context eq 'requestauthor')) {
1.86 raeburn 10647: if (ref($changes{'defaultquota'}) eq 'HASH') {
10648: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
10649: foreach my $type (@{$types},'default') {
10650: if (defined($changes{'defaultquota'}{$type})) {
10651: my $typetitle = $usertypes->{$type};
10652: if ($type eq 'default') {
10653: $typetitle = $othertitle;
10654: }
1.213 raeburn 10655: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 10656: }
10657: }
1.86 raeburn 10658: $resulttext .= '</ul></li>';
1.72 raeburn 10659: }
1.197 raeburn 10660: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 10661: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 10662: foreach my $type (@{$types},'default') {
10663: if (defined($changes{'authorquota'}{$type})) {
10664: my $typetitle = $usertypes->{$type};
10665: if ($type eq 'default') {
10666: $typetitle = $othertitle;
10667: }
1.213 raeburn 10668: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 10669: }
10670: }
10671: $resulttext .= '</ul></li>';
10672: }
1.72 raeburn 10673: }
1.80 raeburn 10674: my %newenv;
1.72 raeburn 10675: foreach my $item (@usertools) {
1.163 raeburn 10676: my (%haschgs,%inconf);
10677: if ($context eq 'requestauthor') {
10678: %haschgs = %changes;
1.210 raeburn 10679: %inconf = %confhash;
1.163 raeburn 10680: } else {
10681: if (ref($changes{$item}) eq 'HASH') {
10682: %haschgs = %{$changes{$item}};
10683: }
10684: if (ref($confhash{$item}) eq 'HASH') {
10685: %inconf = %{$confhash{$item}};
10686: }
10687: }
10688: if (keys(%haschgs) > 0) {
1.80 raeburn 10689: my $newacc =
10690: &Apache::lonnet::usertools_access($env{'user.name'},
10691: $env{'user.domain'},
1.86 raeburn 10692: $item,'reload',$context);
1.210 raeburn 10693: if (($context eq 'requestcourses') ||
1.163 raeburn 10694: ($context eq 'requestauthor')) {
1.108 raeburn 10695: if ($env{'environment.canrequest.'.$item} ne $newacc) {
10696: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 10697: }
10698: } else {
10699: if ($env{'environment.availabletools.'.$item} ne $newacc) {
10700: $newenv{'environment.availabletools.'.$item} = $newacc;
10701: }
1.80 raeburn 10702: }
1.163 raeburn 10703: unless ($context eq 'requestauthor') {
10704: $resulttext .= '<li>'.$titles{$item}.'<ul>';
10705: }
1.72 raeburn 10706: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 10707: if ($haschgs{$type}) {
1.72 raeburn 10708: my $typetitle = $usertypes->{$type};
10709: if ($type eq 'default') {
10710: $typetitle = $othertitle;
10711: } elsif ($type eq '_LC_adv') {
10712: $typetitle = 'LON-CAPA Advanced Users';
10713: }
1.163 raeburn 10714: if ($inconf{$type}) {
1.101 raeburn 10715: if ($context eq 'requestcourses') {
10716: my $cond;
1.163 raeburn 10717: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 10718: if ($1 eq '') {
10719: $cond = &mt('(Automatic processing of any request).');
10720: } else {
10721: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
10722: }
10723: } else {
1.163 raeburn 10724: $cond = $conditions{$inconf{$type}};
1.101 raeburn 10725: }
10726: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 10727: } elsif ($context eq 'requestauthor') {
10728: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
10729: $titles{$inconf{$type}},$typetitle);
10730:
1.101 raeburn 10731: } else {
10732: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
10733: }
1.72 raeburn 10734: } else {
1.104 raeburn 10735: if ($type eq '_LC_adv') {
1.163 raeburn 10736: if ($inconf{$type} eq '0') {
1.104 raeburn 10737: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
10738: } else {
10739: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
10740: }
10741: } else {
10742: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
10743: }
1.72 raeburn 10744: }
10745: }
1.26 raeburn 10746: }
1.163 raeburn 10747: unless ($context eq 'requestauthor') {
10748: $resulttext .= '</ul></li>';
10749: }
1.26 raeburn 10750: }
1.1 raeburn 10751: }
1.163 raeburn 10752: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 10753: if (ref($changes{'notify'}) eq 'HASH') {
10754: if ($changes{'notify'}{'approval'}) {
10755: if (ref($confhash{'notify'}) eq 'HASH') {
10756: if ($confhash{'notify'}{'approval'}) {
10757: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
10758: } else {
1.163 raeburn 10759: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 10760: }
10761: }
10762: }
10763: }
10764: }
1.216 raeburn 10765: if ($action eq 'requestcourses') {
10766: my @offon = ('off','on');
10767: if ($changes{'uniquecode'}) {
1.218 raeburn 10768: if (ref($confhash{'uniquecode'}) eq 'HASH') {
10769: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
10770: $resulttext .= '<li>'.
10771: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
10772: '</li>';
10773: } else {
10774: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
10775: '</li>';
10776: }
1.216 raeburn 10777: }
1.242 raeburn 10778: foreach my $type ('textbooks','templates') {
10779: if (ref($changes{$type}) eq 'HASH') {
10780: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
10781: foreach my $key (sort(keys(%{$changes{$type}}))) {
10782: my %coursehash = &Apache::lonnet::coursedescription($key);
10783: my $coursetitle = $coursehash{'description'};
10784: my $position = $confhash{$type}{$key}{'order'} + 1;
10785: $resulttext .= '<li>';
1.243 raeburn 10786: foreach my $item ('subject','title','publisher','author') {
10787: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10788: ($type eq 'templates'));
1.242 raeburn 10789: my $name = $item.':';
10790: $name =~ s/^(\w)/\U$1/;
10791: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
10792: }
10793: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
10794: if ($type eq 'textbooks') {
10795: if ($confhash{$type}{$key}{'image'}) {
10796: $resulttext .= ' '.&mt('Image: [_1]',
10797: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
10798: ' alt="Textbook cover" />').'<br />';
10799: }
10800: }
10801: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 10802: }
1.242 raeburn 10803: $resulttext .= '</ul></li>';
1.216 raeburn 10804: }
10805: }
1.235 raeburn 10806: if (ref($changes{'validation'}) eq 'HASH') {
10807: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
10808: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
10809: foreach my $item (@{$validationitemsref}) {
10810: if (exists($changes{'validation'}{$item})) {
10811: if ($item eq 'markup') {
10812: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
10813: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
10814: } else {
10815: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
10816: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
10817: }
10818: }
10819: }
10820: if (exists($changes{'validation'}{'dc'})) {
10821: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
10822: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
10823: }
10824: }
10825: }
1.216 raeburn 10826: }
1.1 raeburn 10827: $resulttext .= '</ul>';
1.80 raeburn 10828: if (keys(%newenv)) {
10829: &Apache::lonnet::appenv(\%newenv);
10830: }
1.1 raeburn 10831: } else {
1.86 raeburn 10832: if ($context eq 'requestcourses') {
10833: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 10834: } elsif ($context eq 'requestauthor') {
10835: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 10836: } else {
1.90 weissno 10837: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 10838: }
1.1 raeburn 10839: }
10840: } else {
1.11 albertel 10841: $resulttext = '<span class="LC_error">'.
10842: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10843: }
1.216 raeburn 10844: if ($errors) {
10845: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
10846: '<ul>'.$errors.'</ul></p>';
10847: }
1.3 raeburn 10848: return $resulttext;
1.1 raeburn 10849: }
10850:
1.216 raeburn 10851: sub process_textbook_image {
1.242 raeburn 10852: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 10853: my $filename = $env{'form.'.$caller.'.filename'};
10854: my ($error,$url);
10855: my ($width,$height) = (50,50);
10856: if ($configuserok eq 'ok') {
10857: if ($switchserver) {
10858: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
10859: $switchserver);
10860: } elsif ($author_ok eq 'ok') {
10861: my ($result,$imageurl) =
10862: &publishlogo($r,'upload',$caller,$dom,$confname,
1.312 raeburn 10863: "$type/$cdom/$cnum/cover",$width,$height);
1.216 raeburn 10864: if ($result eq 'ok') {
10865: $url = $imageurl;
10866: } else {
10867: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
10868: }
10869: } else {
10870: $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);
10871: }
10872: } else {
10873: $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);
10874: }
10875: return ($url,$error);
10876: }
10877:
1.267 raeburn 10878: sub modify_ltitools {
10879: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
10880: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 10881: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 10882: my $confname = $dom.'-domainconfig';
10883: my $servadm = $r->dir_config('lonAdmEMail');
10884: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10885: my (%posslti,%possfield);
10886: my @courseroles = ('cc','in','ta','ep','st');
10887: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
10888: map { $posslti{$_} = 1; } @ltiroles;
10889: my @allfields = ('fullname','firstname','lastname','email','user','roles');
10890: map { $possfield{$_} = 1; } @allfields;
10891: my %lt = <itools_names();
10892: if ($env{'form.ltitools_add'}) {
10893: my $title = $env{'form.ltitools_add_title'};
10894: $title =~ s/(`)/'/g;
10895: ($newid,my $error) = &get_ltitools_id($dom,$title);
10896: if ($newid) {
10897: my $position = $env{'form.ltitools_add_pos'};
10898: $position =~ s/\D+//g;
10899: if ($position ne '') {
10900: $allpos[$position] = $newid;
10901: }
10902: $changes{$newid} = 1;
1.322 raeburn 10903: foreach my $item ('title','url','key','secret','lifetime') {
1.267 raeburn 10904: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1.322 raeburn 10905: if ($item eq 'lifetime') {
10906: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
10907: }
1.267 raeburn 10908: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 10909: if (($item eq 'key') || ($item eq 'secret')) {
10910: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
10911: } else {
10912: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
10913: }
1.267 raeburn 10914: }
10915: }
10916: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
10917: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
10918: }
10919: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
10920: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
10921: }
1.323 raeburn 10922: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
10923: $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
10924: } else {
10925: $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
10926: }
1.296 raeburn 10927: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 10928: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
10929: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 10930: if (($item eq 'width') || ($item eq 'height')) {
10931: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
10932: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
10933: }
10934: } else {
10935: if ($env{'form.ltitools_add_'.$item} ne '') {
10936: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
10937: }
1.267 raeburn 10938: }
10939: }
10940: if ($env{'form.ltitools_add_target'} eq 'window') {
10941: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 10942: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
10943: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 10944: } else {
10945: $confhash{$newid}{'display'}{'target'} = 'iframe';
10946: }
10947: foreach my $item ('passback','roster') {
1.319 raeburn 10948: if ($env{'form.ltitools_'.$item.'_add'}) {
1.267 raeburn 10949: $confhash{$newid}{$item} = 1;
1.319 raeburn 10950: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
10951: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
10952: $lifetime =~ s/^\s+|\s+$//g;
10953: if ($lifetime =~ /^\d+\.?\d*$/) {
10954: $confhash{$newid}{$item.'valid'} = $lifetime;
10955: }
10956: }
1.267 raeburn 10957: }
10958: }
10959: if ($env{'form.ltitools_add_image.filename'} ne '') {
10960: my ($imageurl,$error) =
1.307 raeburn 10961: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267 raeburn 10962: $configuserok,$switchserver,$author_ok);
10963: if ($imageurl) {
10964: $confhash{$newid}{'image'} = $imageurl;
10965: }
10966: if ($error) {
10967: &Apache::lonnet::logthis($error);
10968: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10969: }
10970: }
10971: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
10972: foreach my $field (@fields) {
10973: if ($possfield{$field}) {
10974: if ($field eq 'roles') {
10975: foreach my $role (@courseroles) {
10976: my $choice = $env{'form.ltitools_add_roles_'.$role};
10977: if (($choice ne '') && ($posslti{$choice})) {
10978: $confhash{$newid}{'roles'}{$role} = $choice;
10979: if ($role eq 'cc') {
10980: $confhash{$newid}{'roles'}{'co'} = $choice;
10981: }
10982: }
10983: }
10984: } else {
10985: $confhash{$newid}{'fields'}{$field} = 1;
10986: }
10987: }
10988: }
1.324 raeburn 10989: if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
10990: if ($confhash{$newid}{'fields'}{'user'}) {
10991: if ($env{'form.ltitools_userincdom_add'}) {
10992: $confhash{$newid}{'incdom'} = 1;
10993: }
10994: }
10995: }
1.273 raeburn 10996: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
10997: foreach my $item (@courseconfig) {
10998: $confhash{$newid}{'crsconf'}{$item} = 1;
10999: }
1.267 raeburn 11000: if ($env{'form.ltitools_add_custom'}) {
11001: my $name = $env{'form.ltitools_add_custom_name'};
11002: my $value = $env{'form.ltitools_add_custom_value'};
11003: $value =~ s/(`)/'/g;
11004: $name =~ s/(`)/'/g;
11005: $confhash{$newid}{'custom'}{$name} = $value;
11006: }
11007: } else {
11008: my $error = &mt('Failed to acquire unique ID for new external tool');
11009: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11010: }
11011: }
11012: if (ref($domconfig{$action}) eq 'HASH') {
11013: my %deletions;
11014: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
11015: if (@todelete) {
11016: map { $deletions{$_} = 1; } @todelete;
11017: }
11018: my %customadds;
11019: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
11020: if (@newcustom) {
11021: map { $customadds{$_} = 1; } @newcustom;
11022: }
11023: my %imgdeletions;
11024: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
11025: if (@todeleteimages) {
11026: map { $imgdeletions{$_} = 1; } @todeleteimages;
11027: }
11028: my $maxnum = $env{'form.ltitools_maxnum'};
11029: for (my $i=0; $i<=$maxnum; $i++) {
11030: my $itemid = $env{'form.ltitools_id_'.$i};
1.308 raeburn 11031: $itemid =~ s/\D+//g;
1.267 raeburn 11032: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11033: if ($deletions{$itemid}) {
11034: if ($domconfig{$action}{$itemid}{'image'}) {
11035: #FIXME need to obsolete item in RES space
11036: }
11037: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
11038: next;
11039: } else {
11040: my $newpos = $env{'form.ltitools_'.$itemid};
11041: $newpos =~ s/\D+//g;
1.322 raeburn 11042: foreach my $item ('title','url','lifetime') {
1.267 raeburn 11043: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
11044: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
11045: $changes{$itemid} = 1;
11046: }
11047: }
1.297 raeburn 11048: foreach my $item ('key','secret') {
11049: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
11050: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
11051: $changes{$itemid} = 1;
11052: }
11053: }
1.267 raeburn 11054: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
11055: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
11056: }
11057: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
11058: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
11059: }
1.323 raeburn 11060: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
11061: $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
11062: } else {
11063: $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
11064: }
11065: if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
11066: if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
11067: $changes{$itemid} = 1;
11068: }
11069: } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
11070: $changes{$itemid} = 1;
11071: }
1.267 raeburn 11072: foreach my $size ('width','height') {
11073: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
11074: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
11075: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
11076: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
11077: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11078: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
11079: $changes{$itemid} = 1;
11080: }
11081: } else {
11082: $changes{$itemid} = 1;
11083: }
1.296 raeburn 11084: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11085: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
11086: $changes{$itemid} = 1;
11087: }
11088: }
11089: }
11090: foreach my $item ('linktext','explanation') {
11091: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
11092: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
11093: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
11094: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
11095: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11096: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
11097: $changes{$itemid} = 1;
11098: }
11099: } else {
11100: $changes{$itemid} = 1;
11101: }
11102: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11103: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
11104: $changes{$itemid} = 1;
11105: }
1.267 raeburn 11106: }
11107: }
11108: if ($env{'form.ltitools_target_'.$i} eq 'window') {
11109: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 11110: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
11111: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 11112: } else {
11113: $confhash{$itemid}{'display'}{'target'} = 'iframe';
11114: }
11115: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11116: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
11117: $changes{$itemid} = 1;
11118: }
11119: } else {
11120: $changes{$itemid} = 1;
11121: }
11122: foreach my $extra ('passback','roster') {
11123: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
11124: $confhash{$itemid}{$extra} = 1;
1.319 raeburn 11125: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
11126: my $lifetime = $env{'form.ltitools_'.$extra.'valid_add'};
11127: $lifetime =~ s/^\s+|\s+$//g;
11128: if ($lifetime =~ /^\d+\.?\d*$/) {
11129: $confhash{$itemid}{$extra.'valid'} = $lifetime;
11130: }
11131: }
1.267 raeburn 11132: }
11133: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
11134: $changes{$itemid} = 1;
11135: }
1.319 raeburn 11136: if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
11137: $changes{$itemid} = 1;
11138: }
1.267 raeburn 11139: }
1.273 raeburn 11140: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318 raeburn 11141: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 11142: if (grep(/^\Q$item\E$/,@courseconfig)) {
11143: $confhash{$itemid}{'crsconf'}{$item} = 1;
11144: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
11145: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
11146: $changes{$itemid} = 1;
11147: }
11148: } else {
11149: $changes{$itemid} = 1;
11150: }
11151: }
11152: }
1.267 raeburn 11153: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
11154: foreach my $field (@fields) {
11155: if ($possfield{$field}) {
11156: if ($field eq 'roles') {
11157: foreach my $role (@courseroles) {
11158: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
11159: if (($choice ne '') && ($posslti{$choice})) {
11160: $confhash{$itemid}{'roles'}{$role} = $choice;
11161: if ($role eq 'cc') {
11162: $confhash{$itemid}{'roles'}{'co'} = $choice;
11163: }
11164: }
11165: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
11166: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
11167: $changes{$itemid} = 1;
11168: }
11169: } elsif ($confhash{$itemid}{'roles'}{$role}) {
11170: $changes{$itemid} = 1;
11171: }
11172: }
11173: } else {
11174: $confhash{$itemid}{'fields'}{$field} = 1;
11175: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
11176: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
11177: $changes{$itemid} = 1;
11178: }
11179: } else {
11180: $changes{$itemid} = 1;
11181: }
11182: }
11183: }
11184: }
1.324 raeburn 11185: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
11186: if ($confhash{$itemid}{'fields'}{'user'}) {
11187: if ($env{'form.ltitools_userincdom_'.$i}) {
11188: $confhash{$itemid}{'incdom'} = 1;
11189: }
11190: if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
11191: $changes{$itemid} = 1;
11192: }
11193: }
11194: }
1.267 raeburn 11195: $allpos[$newpos] = $itemid;
11196: }
11197: if ($imgdeletions{$itemid}) {
11198: $changes{$itemid} = 1;
11199: #FIXME need to obsolete item in RES space
11200: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
11201: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
11202: $itemid,$configuserok,$switchserver,
11203: $author_ok);
11204: if ($imgurl) {
11205: $confhash{$itemid}{'image'} = $imgurl;
11206: $changes{$itemid} = 1;
11207: }
11208: if ($error) {
11209: &Apache::lonnet::logthis($error);
11210: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11211: }
11212: } elsif ($domconfig{$action}{$itemid}{'image'}) {
11213: $confhash{$itemid}{'image'} =
11214: $domconfig{$action}{$itemid}{'image'};
11215: }
11216: if ($customadds{$i}) {
11217: my $name = $env{'form.ltitools_custom_name_'.$i};
11218: $name =~ s/(`)/'/g;
11219: $name =~ s/^\s+//;
11220: $name =~ s/\s+$//;
11221: my $value = $env{'form.ltitools_custom_value_'.$i};
11222: $value =~ s/(`)/'/g;
11223: $value =~ s/^\s+//;
11224: $value =~ s/\s+$//;
11225: if ($name ne '') {
11226: $confhash{$itemid}{'custom'}{$name} = $value;
11227: $changes{$itemid} = 1;
11228: }
11229: }
11230: my %customdels;
11231: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
11232: if (@customdeletions) {
11233: $changes{$itemid} = 1;
11234: }
11235: map { $customdels{$_} = 1; } @customdeletions;
11236: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
11237: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
11238: unless ($customdels{$key}) {
11239: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
11240: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
11241: }
11242: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
11243: $changes{$itemid} = 1;
11244: }
11245: }
11246: }
11247: }
11248: unless ($changes{$itemid}) {
11249: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
11250: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
11251: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
11252: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
11253: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
11254: $changes{$itemid} = 1;
11255: last;
11256: }
11257: }
11258: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
11259: $changes{$itemid} = 1;
11260: }
11261: }
11262: last if ($changes{$itemid});
11263: }
11264: }
11265: }
11266: }
11267: }
11268: if (@allpos > 0) {
11269: my $idx = 0;
11270: foreach my $itemid (@allpos) {
11271: if ($itemid ne '') {
11272: $confhash{$itemid}{'order'} = $idx;
11273: if (ref($domconfig{$action}) eq 'HASH') {
11274: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11275: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
11276: $changes{$itemid} = 1;
11277: }
11278: }
11279: }
11280: $idx ++;
11281: }
11282: }
11283: }
11284: my %ltitoolshash = (
11285: $action => { %confhash }
11286: );
11287: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
11288: $dom);
11289: if ($putresult eq 'ok') {
1.297 raeburn 11290: my %ltienchash = (
11291: $action => { %encconfig }
11292: );
11293: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
1.267 raeburn 11294: if (keys(%changes) > 0) {
11295: my $cachetime = 24*60*60;
1.297 raeburn 11296: my %ltiall = %confhash;
11297: foreach my $id (keys(%ltiall)) {
11298: if (ref($encconfig{$id}) eq 'HASH') {
11299: foreach my $item ('key','secret') {
11300: $ltiall{$id}{$item} = $encconfig{$id}{$item};
11301: }
11302: }
11303: }
11304: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 11305: if (ref($lastactref) eq 'HASH') {
11306: $lastactref->{'ltitools'} = 1;
11307: }
11308: $resulttext = &mt('Changes made:').'<ul>';
11309: my %bynum;
11310: foreach my $itemid (sort(keys(%changes))) {
11311: my $position = $confhash{$itemid}{'order'};
11312: $bynum{$position} = $itemid;
11313: }
11314: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
11315: my $itemid = $bynum{$pos};
11316: if (ref($confhash{$itemid}) ne 'HASH') {
11317: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
11318: } else {
11319: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
11320: if ($confhash{$itemid}{'image'}) {
11321: $resulttext .= ' '.
11322: '<img src="'.$confhash{$itemid}{'image'}.'"'.
11323: ' alt="'.&mt('Tool Provider icon').'" />';
11324: }
11325: $resulttext .= '</li><ul>';
11326: my $position = $pos + 1;
11327: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.323 raeburn 11328: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1.267 raeburn 11329: if ($confhash{$itemid}{$item} ne '') {
11330: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
11331: }
11332: }
1.297 raeburn 11333: if ($encconfig{$itemid}{'key'} ne '') {
11334: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
11335: }
11336: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 11337: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 11338: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 11339: $resulttext .= ('*'x$num).'</li>';
11340: }
1.273 raeburn 11341: $resulttext .= '<li>'.&mt('Configurable in course:');
1.318 raeburn 11342: my @possconfig = ('label','title','target','linktext','explanation','append');
1.273 raeburn 11343: my $numconfig = 0;
11344: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
11345: foreach my $item (@possconfig) {
11346: if ($confhash{$itemid}{'crsconf'}{$item}) {
11347: $numconfig ++;
1.296 raeburn 11348: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 11349: }
11350: }
11351: }
11352: if (!$numconfig) {
11353: $resulttext .= &mt('None');
11354: }
11355: $resulttext .= '</li>';
1.267 raeburn 11356: foreach my $item ('passback','roster') {
11357: $resulttext .= '<li>'.$lt{$item}.' ';
11358: if ($confhash{$itemid}{$item}) {
11359: $resulttext .= &mt('Yes');
1.319 raeburn 11360: if ($confhash{$itemid}{$item.'valid'}) {
11361: if ($item eq 'passback') {
11362: $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
11363: $confhash{$itemid}{$item.'valid'});
11364: } else {
11365: $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
11366: $confhash{$itemid}{$item.'valid'});
11367: }
11368: }
1.267 raeburn 11369: } else {
11370: $resulttext .= &mt('No');
11371: }
11372: $resulttext .= '</li>';
11373: }
11374: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
11375: my $displaylist;
11376: if ($confhash{$itemid}{'display'}{'target'}) {
11377: $displaylist = &mt('Display target').': '.
11378: $confhash{$itemid}{'display'}{'target'}.',';
11379: }
11380: foreach my $size ('width','height') {
11381: if ($confhash{$itemid}{'display'}{$size}) {
11382: $displaylist .= (' 'x2).$lt{$size}.': '.
11383: $confhash{$itemid}{'display'}{$size}.',';
11384: }
11385: }
11386: if ($displaylist) {
11387: $displaylist =~ s/,$//;
11388: $resulttext .= '<li>'.$displaylist.'</li>';
11389: }
1.296 raeburn 11390: foreach my $item ('linktext','explanation') {
11391: if ($confhash{$itemid}{'display'}{$item}) {
11392: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
11393: }
11394: }
11395: }
1.267 raeburn 11396: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
11397: my $fieldlist;
11398: foreach my $field (@allfields) {
11399: if ($confhash{$itemid}{'fields'}{$field}) {
11400: $fieldlist .= (' 'x2).$lt{$field}.',';
11401: }
11402: }
11403: if ($fieldlist) {
11404: $fieldlist =~ s/,$//;
1.324 raeburn 11405: if ($confhash{$itemid}{'fields'}{'user'}) {
11406: if ($confhash{$itemid}{'incdom'}) {
11407: $fieldlist .= ' ('.&mt('username:domain').')';
11408: } else {
11409: $fieldlist .= ' ('.&mt('username').')';
11410: }
11411: }
1.267 raeburn 11412: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
11413: }
11414: }
11415: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
11416: my $rolemaps;
11417: foreach my $role (@courseroles) {
11418: if ($confhash{$itemid}{'roles'}{$role}) {
11419: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
11420: $confhash{$itemid}{'roles'}{$role}.',';
11421: }
11422: }
11423: if ($rolemaps) {
11424: $rolemaps =~ s/,$//;
11425: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
11426: }
11427: }
11428: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
11429: my $customlist;
11430: if (keys(%{$confhash{$itemid}{'custom'}})) {
11431: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
11432: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
11433: }
11434: }
11435: if ($customlist) {
1.317 raeburn 11436: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267 raeburn 11437: }
11438: }
11439: $resulttext .= '</ul></li>';
11440: }
11441: }
11442: $resulttext .= '</ul>';
11443: } else {
11444: $resulttext = &mt('No changes made.');
11445: }
11446: } else {
11447: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
11448: }
11449: if ($errors) {
11450: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11451: $errors.'</ul>';
11452: }
11453: return $resulttext;
11454: }
11455:
11456: sub process_ltitools_image {
11457: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
11458: my $filename = $env{'form.'.$caller.'.filename'};
11459: my ($error,$url);
11460: my ($width,$height) = (21,21);
11461: if ($configuserok eq 'ok') {
11462: if ($switchserver) {
11463: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
11464: $switchserver);
11465: } elsif ($author_ok eq 'ok') {
11466: my ($result,$imageurl,$madethumb) =
11467: &publishlogo($r,'upload',$caller,$dom,$confname,
11468: "ltitools/$itemid/icon",$width,$height);
11469: if ($result eq 'ok') {
11470: if ($madethumb) {
11471: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
11472: my $imagethumb = "$path/tn-".$imagefile;
11473: $url = $imagethumb;
11474: } else {
11475: $url = $imageurl;
11476: }
11477: } else {
11478: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
11479: }
11480: } else {
11481: $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);
11482: }
11483: } else {
11484: $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);
11485: }
11486: return ($url,$error);
11487: }
11488:
11489: sub get_ltitools_id {
11490: my ($cdom,$title) = @_;
11491: # get lock on ltitools db
11492: my $lockhash = {
11493: lock => $env{'user.name'}.
11494: ':'.$env{'user.domain'},
11495: };
11496: my $tries = 0;
11497: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
11498: my ($id,$error);
11499:
11500: while (($gotlock ne 'ok') && ($tries<10)) {
11501: $tries ++;
11502: sleep (0.1);
11503: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
11504: }
11505: if ($gotlock eq 'ok') {
11506: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
11507: if ($currids{'lock'}) {
11508: delete($currids{'lock'});
11509: if (keys(%currids)) {
11510: my @curr = sort { $a <=> $b } keys(%currids);
11511: if ($curr[-1] =~ /^\d+$/) {
11512: $id = 1 + $curr[-1];
11513: }
11514: } else {
11515: $id = 1;
11516: }
11517: if ($id) {
11518: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
11519: $error = 'nostore';
11520: }
11521: } else {
11522: $error = 'nonumber';
11523: }
11524: }
11525: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
11526: } else {
11527: $error = 'nolock';
11528: }
11529: return ($id,$error);
11530: }
11531:
1.320 raeburn 11532: sub modify_lti {
11533: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
11534: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11535: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
11536: my (%posslti,%posslticrs,%posscrstype);
11537: my @courseroles = ('cc','in','ta','ep','st');
11538: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
11539: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
11540: my @coursetypes = ('official','unofficial','community','textbook','placement');
11541: my %coursetypetitles = &Apache::lonlocal::texthash (
11542: official => 'Official',
11543: unofficial => 'Unofficial',
11544: community => 'Community',
11545: textbook => 'Textbook',
11546: placement => 'Placement Test',
11547: );
1.325 raeburn 11548: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 11549: my %lt = <i_names();
11550: map { $posslti{$_} = 1; } @ltiroles;
11551: map { $posslticrs{$_} = 1; } @lticourseroles;
11552: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 11553:
1.326 raeburn 11554: my %menutitles = <imenu_titles();
11555:
1.320 raeburn 11556: my (@items,%deletions,%itemids);
11557: if ($env{'form.lti_add'}) {
11558: my $consumer = $env{'form.lti_consumer_add'};
11559: $consumer =~ s/(`)/'/g;
11560: ($newid,my $error) = &get_lti_id($dom,$consumer);
11561: if ($newid) {
11562: $itemids{'add'} = $newid;
11563: push(@items,'add');
11564: $changes{$newid} = 1;
11565: } else {
11566: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
11567: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11568: }
11569: }
11570: if (ref($domconfig{$action}) eq 'HASH') {
11571: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
11572: if (@todelete) {
11573: map { $deletions{$_} = 1; } @todelete;
11574: }
11575: my $maxnum = $env{'form.lti_maxnum'};
11576: for (my $i=0; $i<=$maxnum; $i++) {
11577: my $itemid = $env{'form.lti_id_'.$i};
11578: $itemid =~ s/\D+//g;
11579: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11580: if ($deletions{$itemid}) {
11581: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
11582: } else {
11583: push(@items,$i);
11584: $itemids{$i} = $itemid;
11585: }
11586: }
11587: }
11588: }
11589: foreach my $idx (@items) {
11590: my $itemid = $itemids{$idx};
11591: next unless ($itemid);
11592: my $position = $env{'form.lti_pos_'.$idx};
11593: $position =~ s/\D+//g;
11594: if ($position ne '') {
11595: $allpos[$position] = $itemid;
11596: }
11597: foreach my $item ('consumer','key','secret','lifetime') {
11598: my $formitem = 'form.lti_'.$item.'_'.$idx;
11599: $env{$formitem} =~ s/(`)/'/g;
11600: if ($item eq 'lifetime') {
11601: $env{$formitem} =~ s/[^\d.]//g;
11602: }
11603: if ($env{$formitem} ne '') {
11604: if (($item eq 'key') || ($item eq 'secret')) {
11605: $encconfig{$itemid}{$item} = $env{$formitem};
11606: } else {
11607: $confhash{$itemid}{$item} = $env{$formitem};
11608: unless (($idx eq 'add') || ($changes{$itemid})) {
11609: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
11610: $changes{$itemid} = 1;
11611: }
11612: }
11613: }
11614: }
11615: }
11616: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
11617: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
11618: }
11619: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
11620: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
11621: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
11622: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
11623: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
11624: my $mapuser = $env{'form.lti_customuser_'.$idx};
11625: $mapuser =~ s/(`)/'/g;
11626: $mapuser =~ s/^\s+|\s+$//g;
11627: $confhash{$itemid}{'mapuser'} = $mapuser;
11628: }
11629: foreach my $ltirole (@lticourseroles) {
11630: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
11631: if (grep(/^\Q$possrole\E$/,@courseroles)) {
11632: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
11633: }
11634: }
11635: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
11636: my @makeuser;
11637: foreach my $ltirole (sort(@possmakeuser)) {
11638: if ($posslti{$ltirole}) {
11639: push(@makeuser,$ltirole);
11640: }
11641: }
11642: $confhash{$itemid}{'makeuser'} = \@makeuser;
1.325 raeburn 11643: if (@makeuser) {
11644: my $lcauth = $env{'form.lti_lcauth_'.$idx};
11645: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
11646: $confhash{$itemid}{'lcauth'} = $lcauth;
11647: if ($lcauth ne 'internal') {
11648: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
11649: $lcauthparm =~ s/^(\s+|\s+)$//g;
11650: $lcauthparm =~ s/`//g;
11651: if ($lcauthparm ne '') {
11652: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
11653: }
11654: }
11655: } else {
11656: $confhash{$itemid}{'lcauth'} = 'lti';
11657: }
11658: }
11659: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
11660: if (@possinstdata) {
11661: foreach my $field (@possinstdata) {
11662: if (exists($fieldtitles{$field})) {
11663: push(@{$confhash{$itemid}{'instdata'}});
11664: }
11665: }
11666: }
1.320 raeburn 11667: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
11668: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
11669: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
11670: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
11671: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
11672: $mapcrs =~ s/(`)/'/g;
11673: $mapcrs =~ s/^\s+|\s+$//g;
11674: $confhash{$itemid}{'mapcrs'} = $mapcrs;
11675: }
11676: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
11677: my @crstypes;
11678: foreach my $type (sort(@posstypes)) {
11679: if ($posscrstype{$type}) {
11680: push(@crstypes,$type);
11681: }
11682: }
11683: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
11684: if ($env{'form.lti_makecrs_'.$idx}) {
11685: $confhash{$itemid}{'makecrs'} = 1;
11686: }
11687: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
11688: my @selfenroll;
11689: foreach my $type (sort(@possenroll)) {
11690: if ($posslticrs{$type}) {
11691: push(@selfenroll,$type);
11692: }
11693: }
11694: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
11695: if ($env{'form.lti_crssec_'.$idx}) {
11696: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
11697: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
11698: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
11699: my $section = $env{'form.lti_customsection_'.$idx};
11700: $section =~ s/(`)/'/g;
11701: $section =~ s/^\s+|\s+$//g;
11702: if ($section ne '') {
11703: $confhash{$itemid}{'section'} = $section;
11704: }
11705: }
11706: }
1.326 raeburn 11707: foreach my $field ('passback','roster','topmenu','inlinemenu') {
1.321 raeburn 11708: if ($env{'form.lti_'.$field.'_'.$idx}) {
1.320 raeburn 11709: $confhash{$itemid}{$field} = 1;
11710: }
11711: }
1.326 raeburn 11712:
11713: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
11714: $confhash{$itemid}{lcmenu} = [];
11715: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
11716: foreach my $field (@possmenu) {
11717: if (exists($menutitles{$field})) {
11718: if ($field eq 'grades') {
11719: next unless ($env{'form.lti_inlinemenu_'.$idx});
11720: }
11721: push(@{$confhash{$itemid}{lcmenu}},$field);
11722: }
11723: }
11724: }
1.320 raeburn 11725: unless (($idx eq 'add') || ($changes{$itemid})) {
1.326 raeburn 11726: foreach my $field ('mapuser','mapcrs','makecrs','section','passback','roster','lcauth','lcauthparm','topmenu','inlinemenu') {
1.320 raeburn 11727: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
11728: $changes{$itemid} = 1;
11729: }
11730: }
1.326 raeburn 11731: foreach my $field ('makeuser','mapcrstype','selfenroll','instdata','lcmenu') {
1.320 raeburn 11732: unless ($changes{$itemid}) {
11733: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
11734: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
11735: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
11736: $confhash{$itemid}{$field});
11737: if (@diffs) {
11738: $changes{$itemid} = 1;
11739: }
11740: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
11741: $changes{$itemid} = 1;
11742: }
11743: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
11744: if (@{$confhash{$itemid}{$field}} > 0) {
11745: $changes{$itemid} = 1;
11746: }
11747: }
11748: }
11749: }
11750: unless ($changes{$itemid}) {
11751: if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
11752: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
11753: foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
11754: if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne
11755: $confhash{$itemid}{'maproles'}{$ltirole}) {
11756: $changes{$itemid} = 1;
11757: last;
11758: }
11759: }
11760: unless ($changes{$itemid}) {
11761: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
11762: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
11763: $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
11764: $changes{$itemid} = 1;
11765: last;
11766: }
11767: }
11768: }
11769: } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
11770: $changes{$itemid} = 1;
11771: }
11772: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
11773: unless ($changes{$itemid}) {
11774: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
11775: $changes{$itemid} = 1;
11776: }
11777: }
11778: }
11779: }
11780: }
11781: }
11782: if (@allpos > 0) {
11783: my $idx = 0;
11784: foreach my $itemid (@allpos) {
11785: if ($itemid ne '') {
11786: $confhash{$itemid}{'order'} = $idx;
11787: if (ref($domconfig{$action}) eq 'HASH') {
11788: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11789: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
11790: $changes{$itemid} = 1;
11791: }
11792: }
11793: }
11794: $idx ++;
11795: }
11796: }
11797: }
11798: my %ltihash = (
11799: $action => { %confhash }
11800: );
11801: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,
11802: $dom);
11803: if ($putresult eq 'ok') {
11804: my %ltienchash = (
11805: $action => { %encconfig }
11806: );
11807: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
11808: if (keys(%changes) > 0) {
11809: my $cachetime = 24*60*60;
11810: my %ltiall = %confhash;
11811: foreach my $id (keys(%ltiall)) {
11812: if (ref($encconfig{$id}) eq 'HASH') {
11813: foreach my $item ('key','secret') {
11814: $ltiall{$id}{$item} = $encconfig{$id}{$item};
11815: }
11816: }
11817: }
11818: &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
11819: if (ref($lastactref) eq 'HASH') {
11820: $lastactref->{'lti'} = 1;
11821: }
11822: $resulttext = &mt('Changes made:').'<ul>';
11823: my %bynum;
11824: foreach my $itemid (sort(keys(%changes))) {
11825: my $position = $confhash{$itemid}{'order'};
11826: $bynum{$position} = $itemid;
11827: }
11828: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
11829: my $itemid = $bynum{$pos};
11830: if (ref($confhash{$itemid}) ne 'HASH') {
11831: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
11832: } else {
11833: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b></li><ul>';
11834: my $position = $pos + 1;
11835: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
11836: foreach my $item ('version','lifetime') {
11837: if ($confhash{$itemid}{$item} ne '') {
11838: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
11839: }
11840: }
11841: if ($encconfig{$itemid}{'key'} ne '') {
11842: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
11843: }
11844: if ($encconfig{$itemid}{'secret'} ne '') {
11845: $resulttext .= '<li>'.$lt{'secret'}.': ';
11846: my $num = length($encconfig{$itemid}{'secret'});
11847: $resulttext .= ('*'x$num).'</li>';
11848: }
11849: if ($confhash{$itemid}{'mapuser'}) {
11850: my $shownmapuser;
11851: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
11852: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
11853: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
11854: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
11855: } else {
11856: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
11857: }
11858: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
11859: }
11860: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
11861: my $rolemaps;
11862: foreach my $role (@ltiroles) {
11863: if ($confhash{$itemid}{'maproles'}{$role}) {
11864: $rolemaps .= (' 'x2).$role.'='.
11865: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
11866: 'Course').',';
11867: }
11868: }
11869: if ($rolemaps) {
11870: $rolemaps =~ s/,$//;
11871: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
11872: }
11873: }
11874: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
11875: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
11876: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
1.325 raeburn 11877: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
11878: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
11879: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
11880: } else {
11881: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
11882: $confhash{$itemid}{'lcauth'});
11883: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
11884: $resulttext .= '; '.&mt('a randomly generated password will be created');
11885: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
11886: if ($confhash{$itemid}{'lcauthparm'} ne '') {
11887: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
11888: }
11889: } else {
11890: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
11891: }
11892: }
11893: $resulttext .= '</li>';
1.320 raeburn 11894: } else {
11895: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
11896: }
11897: }
1.325 raeburn 11898: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
11899: if (@{$confhash{$itemid}{'instdata'}} > 0) {
11900: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
11901: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
11902: } else {
11903: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
11904: }
11905: }
1.320 raeburn 11906: if ($confhash{$itemid}{'mapcrs'}) {
11907: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
11908: }
11909: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
11910: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
11911: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
11912: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
11913: '</li>';
11914: } else {
11915: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
11916: }
11917: }
11918: if ($confhash{$itemid}{'makecrs'}) {
11919: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
11920: } else {
11921: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
11922: }
11923: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
11924: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
11925: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
11926: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
11927: '</li>';
11928: } else {
11929: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
11930: }
11931: }
11932: if ($confhash{$itemid}{'section'}) {
11933: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
11934: $resulttext .= '<li>'.&mt('User section from standard field:').
11935: ' (course_section_sourcedid)'.'</li>';
11936: } else {
11937: $resulttext .= '<li>'.&mt('User section from:').' '.
11938: $confhash{$itemid}{'section'}.'</li>';
11939: }
11940: } else {
11941: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
11942: }
1.326 raeburn 11943: foreach my $item ('passback','roster','topmenu','inlinemenu') {
11944: $resulttext .= '<li>'.$lt{$item}.': ';
1.320 raeburn 11945: if ($confhash{$itemid}{$item}) {
11946: $resulttext .= &mt('Yes');
11947: } else {
11948: $resulttext .= &mt('No');
11949: }
11950: $resulttext .= '</li>';
11951: }
1.326 raeburn 11952: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
11953: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
11954: $resulttext .= '<li>'.&mt('Menu items:').' '.
11955: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
11956: } else {
11957: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
11958: }
11959: }
1.320 raeburn 11960: $resulttext .= '</ul></li>';
11961: }
11962: }
11963: $resulttext .= '</ul>';
11964: } else {
11965: $resulttext = &mt('No changes made.');
11966: }
11967: } else {
11968: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
11969: }
11970: if ($errors) {
11971: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11972: $errors.'</ul>';
11973: }
11974: return $resulttext;
11975: }
11976:
11977: sub get_lti_id {
11978: my ($domain,$consumer) = @_;
11979: # get lock on lti db
11980: my $lockhash = {
11981: lock => $env{'user.name'}.
11982: ':'.$env{'user.domain'},
11983: };
11984: my $tries = 0;
11985: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
11986: my ($id,$error);
11987:
11988: while (($gotlock ne 'ok') && ($tries<10)) {
11989: $tries ++;
11990: sleep (0.1);
11991: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
11992: }
11993: if ($gotlock eq 'ok') {
11994: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
11995: if ($currids{'lock'}) {
11996: delete($currids{'lock'});
11997: if (keys(%currids)) {
11998: my @curr = sort { $a <=> $b } keys(%currids);
11999: if ($curr[-1] =~ /^\d+$/) {
12000: $id = 1 + $curr[-1];
12001: }
12002: } else {
12003: $id = 1;
12004: }
12005: if ($id) {
12006: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
12007: $error = 'nostore';
12008: }
12009: } else {
12010: $error = 'nonumber';
12011: }
12012: }
12013: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
12014: } else {
12015: $error = 'nolock';
12016: }
12017: return ($id,$error);
12018: }
12019:
1.3 raeburn 12020: sub modify_autoenroll {
1.205 raeburn 12021: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 12022: my ($resulttext,%changes);
12023: my %currautoenroll;
12024: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
12025: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
12026: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
12027: }
12028: }
12029: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
12030: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 12031: sender => 'Sender for notification messages',
1.274 raeburn 12032: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
12033: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 12034: my @offon = ('off','on');
1.17 raeburn 12035: my $sender_uname = $env{'form.sender_uname'};
12036: my $sender_domain = $env{'form.sender_domain'};
12037: if ($sender_domain eq '') {
12038: $sender_uname = '';
12039: } elsif ($sender_uname eq '') {
12040: $sender_domain = '';
12041: }
1.129 raeburn 12042: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 12043: my $failsafe = $env{'form.autoenroll_failsafe'};
12044: $failsafe =~ s{^\s+|\s+$}{}g;
12045: if ($failsafe =~ /\D/) {
12046: undef($failsafe);
12047: }
1.1 raeburn 12048: my %autoenrollhash = (
1.129 raeburn 12049: autoenroll => { 'run' => $env{'form.autoenroll_run'},
12050: 'sender_uname' => $sender_uname,
12051: 'sender_domain' => $sender_domain,
12052: 'co-owners' => $coowners,
1.274 raeburn 12053: 'autofailsafe' => $failsafe,
1.1 raeburn 12054: }
12055: );
1.4 raeburn 12056: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
12057: $dom);
1.1 raeburn 12058: if ($putresult eq 'ok') {
12059: if (exists($currautoenroll{'run'})) {
12060: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
12061: $changes{'run'} = 1;
12062: }
12063: } elsif ($autorun) {
12064: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 12065: $changes{'run'} = 1;
1.1 raeburn 12066: }
12067: }
1.17 raeburn 12068: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 12069: $changes{'sender'} = 1;
12070: }
1.17 raeburn 12071: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 12072: $changes{'sender'} = 1;
12073: }
1.129 raeburn 12074: if ($currautoenroll{'co-owners'} ne '') {
12075: if ($currautoenroll{'co-owners'} ne $coowners) {
12076: $changes{'coowners'} = 1;
12077: }
12078: } elsif ($coowners) {
12079: $changes{'coowners'} = 1;
1.274 raeburn 12080: }
12081: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
12082: $changes{'autofailsafe'} = 1;
12083: }
1.1 raeburn 12084: if (keys(%changes) > 0) {
12085: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 12086: if ($changes{'run'}) {
1.1 raeburn 12087: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
12088: }
12089: if ($changes{'sender'}) {
1.17 raeburn 12090: if ($sender_uname eq '' || $sender_domain eq '') {
12091: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
12092: } else {
12093: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
12094: }
1.1 raeburn 12095: }
1.129 raeburn 12096: if ($changes{'coowners'}) {
12097: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
12098: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12099: if (ref($lastactref) eq 'HASH') {
12100: $lastactref->{'domainconfig'} = 1;
12101: }
1.129 raeburn 12102: }
1.274 raeburn 12103: if ($changes{'autofailsafe'}) {
12104: if ($failsafe ne '') {
1.299 raeburn 12105: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274 raeburn 12106: } else {
1.299 raeburn 12107: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274 raeburn 12108: }
12109: &Apache::lonnet::get_domain_defaults($dom,1);
12110: if (ref($lastactref) eq 'HASH') {
12111: $lastactref->{'domdefaults'} = 1;
12112: }
12113: }
1.1 raeburn 12114: $resulttext .= '</ul>';
12115: } else {
12116: $resulttext = &mt('No changes made to auto-enrollment settings');
12117: }
12118: } else {
1.11 albertel 12119: $resulttext = '<span class="LC_error">'.
12120: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12121: }
1.3 raeburn 12122: return $resulttext;
1.1 raeburn 12123: }
12124:
12125: sub modify_autoupdate {
1.3 raeburn 12126: my ($dom,%domconfig) = @_;
1.1 raeburn 12127: my ($resulttext,%currautoupdate,%fields,%changes);
12128: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
12129: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
12130: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
12131: }
12132: }
12133: my @offon = ('off','on');
12134: my %title = &Apache::lonlocal::texthash (
12135: run => 'Auto-update:',
12136: classlists => 'Updates to user information in classlists?'
12137: );
1.44 raeburn 12138: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 12139: my %fieldtitles = &Apache::lonlocal::texthash (
12140: id => 'Student/Employee ID',
1.20 raeburn 12141: permanentemail => 'E-mail address',
1.1 raeburn 12142: lastname => 'Last Name',
12143: firstname => 'First Name',
12144: middlename => 'Middle Name',
1.132 raeburn 12145: generation => 'Generation',
1.1 raeburn 12146: );
1.142 raeburn 12147: $othertitle = &mt('All users');
1.1 raeburn 12148: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 12149: $othertitle = &mt('Other users');
1.1 raeburn 12150: }
12151: foreach my $key (keys(%env)) {
12152: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 12153: my ($usertype,$item) = ($1,$2);
12154: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
12155: if ($usertype eq 'default') {
12156: push(@{$fields{$1}},$2);
12157: } elsif (ref($types) eq 'ARRAY') {
12158: if (grep(/^\Q$usertype\E$/,@{$types})) {
12159: push(@{$fields{$1}},$2);
12160: }
12161: }
12162: }
1.1 raeburn 12163: }
12164: }
1.131 raeburn 12165: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
12166: @lockablenames = sort(@lockablenames);
12167: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
12168: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
12169: if (@changed) {
12170: $changes{'lockablenames'} = 1;
12171: }
12172: } else {
12173: if (@lockablenames) {
12174: $changes{'lockablenames'} = 1;
12175: }
12176: }
1.1 raeburn 12177: my %updatehash = (
12178: autoupdate => { run => $env{'form.autoupdate_run'},
12179: classlists => $env{'form.classlists'},
12180: fields => {%fields},
1.131 raeburn 12181: lockablenames => \@lockablenames,
1.1 raeburn 12182: }
12183: );
12184: foreach my $key (keys(%currautoupdate)) {
12185: if (($key eq 'run') || ($key eq 'classlists')) {
12186: if (exists($updatehash{autoupdate}{$key})) {
12187: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
12188: $changes{$key} = 1;
12189: }
12190: }
12191: } elsif ($key eq 'fields') {
12192: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 12193: foreach my $item (@{$types},'default') {
1.1 raeburn 12194: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
12195: my $change = 0;
12196: foreach my $type (@{$currautoupdate{$key}{$item}}) {
12197: if (!exists($fields{$item})) {
12198: $change = 1;
1.132 raeburn 12199: last;
1.1 raeburn 12200: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 12201: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 12202: $change = 1;
1.132 raeburn 12203: last;
1.1 raeburn 12204: }
12205: }
12206: }
12207: if ($change) {
12208: push(@{$changes{$key}},$item);
12209: }
1.26 raeburn 12210: }
1.1 raeburn 12211: }
12212: }
1.131 raeburn 12213: } elsif ($key eq 'lockablenames') {
12214: if (ref($currautoupdate{$key}) eq 'ARRAY') {
12215: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
12216: if (@changed) {
12217: $changes{'lockablenames'} = 1;
12218: }
12219: } else {
12220: if (@lockablenames) {
12221: $changes{'lockablenames'} = 1;
12222: }
12223: }
12224: }
12225: }
12226: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
12227: if (@lockablenames) {
12228: $changes{'lockablenames'} = 1;
1.1 raeburn 12229: }
12230: }
1.26 raeburn 12231: foreach my $item (@{$types},'default') {
12232: if (defined($fields{$item})) {
12233: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 12234: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
12235: my $change = 0;
12236: if (ref($fields{$item}) eq 'ARRAY') {
12237: foreach my $type (@{$fields{$item}}) {
12238: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
12239: $change = 1;
12240: last;
12241: }
12242: }
12243: }
12244: if ($change) {
12245: push(@{$changes{'fields'}},$item);
12246: }
12247: } else {
1.26 raeburn 12248: push(@{$changes{'fields'}},$item);
12249: }
12250: } else {
12251: push(@{$changes{'fields'}},$item);
1.1 raeburn 12252: }
12253: }
12254: }
12255: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
12256: $dom);
12257: if ($putresult eq 'ok') {
12258: if (keys(%changes) > 0) {
12259: $resulttext = &mt('Changes made:').'<ul>';
12260: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 12261: if ($key eq 'lockablenames') {
12262: $resulttext .= '<li>';
12263: if (@lockablenames) {
12264: $usertypes->{'default'} = $othertitle;
12265: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
12266: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
12267: } else {
12268: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
12269: }
12270: $resulttext .= '</li>';
12271: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 12272: foreach my $item (@{$changes{$key}}) {
12273: my @newvalues;
12274: foreach my $type (@{$fields{$item}}) {
12275: push(@newvalues,$fieldtitles{$type});
12276: }
1.3 raeburn 12277: my $newvaluestr;
12278: if (@newvalues > 0) {
12279: $newvaluestr = join(', ',@newvalues);
12280: } else {
12281: $newvaluestr = &mt('none');
1.6 raeburn 12282: }
1.1 raeburn 12283: if ($item eq 'default') {
1.26 raeburn 12284: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 12285: } else {
1.26 raeburn 12286: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 12287: }
12288: }
12289: } else {
12290: my $newvalue;
12291: if ($key eq 'run') {
12292: $newvalue = $offon[$env{'form.autoupdate_run'}];
12293: } else {
12294: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 12295: }
1.1 raeburn 12296: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
12297: }
12298: }
12299: $resulttext .= '</ul>';
12300: } else {
1.3 raeburn 12301: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 12302: }
12303: } else {
1.11 albertel 12304: $resulttext = '<span class="LC_error">'.
12305: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12306: }
1.3 raeburn 12307: return $resulttext;
1.1 raeburn 12308: }
12309:
1.125 raeburn 12310: sub modify_autocreate {
12311: my ($dom,%domconfig) = @_;
12312: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
12313: if (ref($domconfig{'autocreate'}) eq 'HASH') {
12314: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
12315: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
12316: }
12317: }
12318: my %title= ( xml => 'Auto-creation of courses in XML course description files',
12319: req => 'Auto-creation of validated requests for official courses',
12320: xmldc => 'Identity of course creator of courses from XML files',
12321: );
12322: my @types = ('xml','req');
12323: foreach my $item (@types) {
12324: $newvals{$item} = $env{'form.autocreate_'.$item};
12325: $newvals{$item} =~ s/\D//g;
12326: $newvals{$item} = 0 if ($newvals{$item} eq '');
12327: }
12328: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 12329: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 12330: unless (exists($domcoords{$newvals{'xmldc'}})) {
12331: $newvals{'xmldc'} = '';
12332: }
12333: %autocreatehash = (
12334: autocreate => { xml => $newvals{'xml'},
12335: req => $newvals{'req'},
12336: }
12337: );
12338: if ($newvals{'xmldc'} ne '') {
12339: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
12340: }
12341: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
12342: $dom);
12343: if ($putresult eq 'ok') {
12344: my @items = @types;
12345: if ($newvals{'xml'}) {
12346: push(@items,'xmldc');
12347: }
12348: foreach my $item (@items) {
12349: if (exists($currautocreate{$item})) {
12350: if ($currautocreate{$item} ne $newvals{$item}) {
12351: $changes{$item} = 1;
12352: }
12353: } elsif ($newvals{$item}) {
12354: $changes{$item} = 1;
12355: }
12356: }
12357: if (keys(%changes) > 0) {
12358: my @offon = ('off','on');
12359: $resulttext = &mt('Changes made:').'<ul>';
12360: foreach my $item (@types) {
12361: if ($changes{$item}) {
12362: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 12363: $resulttext .= '<li>'.
12364: &mt("$title{$item} set to [_1]$newtxt [_2]",
12365: '<b>','</b>').
12366: '</li>';
1.125 raeburn 12367: }
12368: }
12369: if ($changes{'xmldc'}) {
12370: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
12371: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 12372: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 12373: }
12374: $resulttext .= '</ul>';
12375: } else {
12376: $resulttext = &mt('No changes made to auto-creation settings');
12377: }
12378: } else {
12379: $resulttext = '<span class="LC_error">'.
12380: &mt('An error occurred: [_1]',$putresult).'</span>';
12381: }
12382: return $resulttext;
12383: }
12384:
1.23 raeburn 12385: sub modify_directorysrch {
1.295 raeburn 12386: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 12387: my ($resulttext,%changes);
12388: my %currdirsrch;
12389: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
12390: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
12391: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
12392: }
12393: }
1.277 raeburn 12394: my %title = ( available => 'Institutional directory search available',
12395: localonly => 'Other domains can search institution',
12396: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 12397: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 12398: searchby => 'Search types',
12399: searchtypes => 'Search latitude');
12400: my @offon = ('off','on');
1.24 raeburn 12401: my @otherdoms = ('Yes','No');
1.23 raeburn 12402:
1.25 raeburn 12403: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 12404: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
12405: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
12406:
1.44 raeburn 12407: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 12408: if (keys(%{$usertypes}) == 0) {
12409: @cansearch = ('default');
12410: } else {
12411: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
12412: foreach my $type (@{$currdirsrch{'cansearch'}}) {
12413: if (!grep(/^\Q$type\E$/,@cansearch)) {
12414: push(@{$changes{'cansearch'}},$type);
12415: }
1.23 raeburn 12416: }
1.26 raeburn 12417: foreach my $type (@cansearch) {
12418: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
12419: push(@{$changes{'cansearch'}},$type);
12420: }
1.23 raeburn 12421: }
1.26 raeburn 12422: } else {
12423: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 12424: }
12425: }
12426:
12427: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
12428: foreach my $by (@{$currdirsrch{'searchby'}}) {
12429: if (!grep(/^\Q$by\E$/,@searchby)) {
12430: push(@{$changes{'searchby'}},$by);
12431: }
12432: }
12433: foreach my $by (@searchby) {
12434: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
12435: push(@{$changes{'searchby'}},$by);
12436: }
12437: }
12438: } else {
12439: push(@{$changes{'searchby'}},@searchby);
12440: }
1.25 raeburn 12441:
12442: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
12443: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
12444: if (!grep(/^\Q$type\E$/,@searchtypes)) {
12445: push(@{$changes{'searchtypes'}},$type);
12446: }
12447: }
12448: foreach my $type (@searchtypes) {
12449: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
12450: push(@{$changes{'searchtypes'}},$type);
12451: }
12452: }
12453: } else {
12454: if (exists($currdirsrch{'searchtypes'})) {
12455: foreach my $type (@searchtypes) {
12456: if ($type ne $currdirsrch{'searchtypes'}) {
12457: push(@{$changes{'searchtypes'}},$type);
12458: }
12459: }
12460: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
12461: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
12462: }
12463: } else {
12464: push(@{$changes{'searchtypes'}},@searchtypes);
12465: }
12466: }
12467:
1.23 raeburn 12468: my %dirsrch_hash = (
12469: directorysrch => { available => $env{'form.dirsrch_available'},
12470: cansearch => \@cansearch,
1.277 raeburn 12471: localonly => $env{'form.dirsrch_instlocalonly'},
12472: lclocalonly => $env{'form.dirsrch_domlocalonly'},
12473: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 12474: searchby => \@searchby,
1.25 raeburn 12475: searchtypes => \@searchtypes,
1.23 raeburn 12476: }
12477: );
12478: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
12479: $dom);
12480: if ($putresult eq 'ok') {
12481: if (exists($currdirsrch{'available'})) {
12482: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
12483: $changes{'available'} = 1;
12484: }
12485: } else {
12486: if ($env{'form.dirsrch_available'} eq '1') {
12487: $changes{'available'} = 1;
12488: }
12489: }
1.277 raeburn 12490: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 12491: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
12492: $changes{'lcavailable'} = 1;
12493: }
1.277 raeburn 12494: } else {
12495: if ($env{'form.dirsrch_lcavailable'} eq '1') {
12496: $changes{'lcavailable'} = 1;
12497: }
12498: }
1.24 raeburn 12499: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 12500: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
12501: $changes{'localonly'} = 1;
12502: }
1.24 raeburn 12503: } else {
1.277 raeburn 12504: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 12505: $changes{'localonly'} = 1;
12506: }
12507: }
1.277 raeburn 12508: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 12509: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
12510: $changes{'lclocalonly'} = 1;
12511: }
1.277 raeburn 12512: } else {
12513: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
12514: $changes{'lclocalonly'} = 1;
12515: }
12516: }
1.23 raeburn 12517: if (keys(%changes) > 0) {
12518: $resulttext = &mt('Changes made:').'<ul>';
12519: if ($changes{'available'}) {
12520: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
12521: }
1.277 raeburn 12522: if ($changes{'lcavailable'}) {
12523: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
12524: }
1.24 raeburn 12525: if ($changes{'localonly'}) {
1.277 raeburn 12526: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 12527: }
1.277 raeburn 12528: if ($changes{'lclocalonly'}) {
12529: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 12530: }
1.23 raeburn 12531: if (ref($changes{'cansearch'}) eq 'ARRAY') {
12532: my $chgtext;
1.26 raeburn 12533: if (ref($usertypes) eq 'HASH') {
12534: if (keys(%{$usertypes}) > 0) {
12535: foreach my $type (@{$types}) {
12536: if (grep(/^\Q$type\E$/,@cansearch)) {
12537: $chgtext .= $usertypes->{$type}.'; ';
12538: }
12539: }
12540: if (grep(/^default$/,@cansearch)) {
12541: $chgtext .= $othertitle;
12542: } else {
12543: $chgtext =~ s/\; $//;
12544: }
1.210 raeburn 12545: $resulttext .=
1.178 raeburn 12546: '<li>'.
12547: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
12548: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
12549: '</li>';
1.23 raeburn 12550: }
12551: }
12552: }
12553: if (ref($changes{'searchby'}) eq 'ARRAY') {
12554: my ($searchtitles,$titleorder) = &sorted_searchtitles();
12555: my $chgtext;
12556: foreach my $type (@{$titleorder}) {
12557: if (grep(/^\Q$type\E$/,@searchby)) {
12558: if (defined($searchtitles->{$type})) {
12559: $chgtext .= $searchtitles->{$type}.'; ';
12560: }
12561: }
12562: }
12563: $chgtext =~ s/\; $//;
12564: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
12565: }
1.25 raeburn 12566: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
12567: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
12568: my $chgtext;
12569: foreach my $type (@{$srchtypeorder}) {
12570: if (grep(/^\Q$type\E$/,@searchtypes)) {
12571: if (defined($srchtypes_desc->{$type})) {
12572: $chgtext .= $srchtypes_desc->{$type}.'; ';
12573: }
12574: }
12575: }
12576: $chgtext =~ s/\; $//;
1.178 raeburn 12577: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 12578: }
12579: $resulttext .= '</ul>';
1.295 raeburn 12580: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
12581: if (ref($lastactref) eq 'HASH') {
12582: $lastactref->{'directorysrch'} = 1;
12583: }
1.23 raeburn 12584: } else {
1.277 raeburn 12585: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 12586: }
12587: } else {
12588: $resulttext = '<span class="LC_error">'.
1.27 raeburn 12589: &mt('An error occurred: [_1]',$putresult).'</span>';
12590: }
12591: return $resulttext;
12592: }
12593:
1.28 raeburn 12594: sub modify_contacts {
1.205 raeburn 12595: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 12596: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
12597: if (ref($domconfig{'contacts'}) eq 'HASH') {
12598: foreach my $key (keys(%{$domconfig{'contacts'}})) {
12599: $currsetting{$key} = $domconfig{'contacts'}{$key};
12600: }
12601: }
1.286 raeburn 12602: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 12603: my @contacts = ('supportemail','adminemail');
1.286 raeburn 12604: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
12605: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.203 raeburn 12606: my @toggles = ('reporterrors','reportupdates');
1.286 raeburn 12607: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 12608: foreach my $type (@mailings) {
12609: @{$newsetting{$type}} =
12610: &Apache::loncommon::get_env_multiple('form.'.$type);
12611: foreach my $item (@contacts) {
12612: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
12613: $contacts_hash{contacts}{$type}{$item} = 1;
12614: } else {
12615: $contacts_hash{contacts}{$type}{$item} = 0;
12616: }
1.289 raeburn 12617: }
1.28 raeburn 12618: $others{$type} = $env{'form.'.$type.'_others'};
12619: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 12620: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12621: $bcc{$type} = $env{'form.'.$type.'_bcc'};
12622: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 12623: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
12624: $includestr{$type} = $env{'form.'.$type.'_includestr'};
12625: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
12626: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
12627: }
1.134 raeburn 12628: }
1.28 raeburn 12629: }
12630: foreach my $item (@contacts) {
12631: $to{$item} = $env{'form.'.$item};
12632: $contacts_hash{'contacts'}{$item} = $to{$item};
12633: }
1.203 raeburn 12634: foreach my $item (@toggles) {
12635: if ($env{'form.'.$item} =~ /^(0|1)$/) {
12636: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
12637: }
12638: }
1.286 raeburn 12639: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
12640: foreach my $field (@{$fields}) {
12641: if (ref($possoptions->{$field}) eq 'ARRAY') {
12642: my $value = $env{'form.helpform_'.$field};
12643: $value =~ s/^\s+|\s+$//g;
12644: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 12645: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 12646: if ($field eq 'screenshot') {
12647: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
12648: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 12649: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 12650: }
12651: }
12652: }
12653: }
12654: }
12655: }
1.315 raeburn 12656: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12657: my (@statuses,%usertypeshash,@overrides);
12658: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
12659: @statuses = @{$types};
12660: if (ref($usertypes) eq 'HASH') {
12661: %usertypeshash = %{$usertypes};
12662: }
12663: }
12664: if (@statuses) {
12665: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
12666: foreach my $type (@possoverrides) {
12667: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
12668: push(@overrides,$type);
12669: }
12670: }
12671: if (@overrides) {
12672: foreach my $type (@overrides) {
12673: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
12674: foreach my $item (@contacts) {
12675: if (grep(/^\Q$item\E$/,@standard)) {
12676: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
12677: $newsetting{'override_'.$type}{$item} = 1;
12678: } else {
12679: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
12680: $newsetting{'override_'.$type}{$item} = 0;
12681: }
12682: }
12683: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
12684: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
12685: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
12686: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
12687: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
12688: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
12689: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
12690: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
12691: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
12692: }
12693: }
12694: }
12695: }
1.28 raeburn 12696: if (keys(%currsetting) > 0) {
12697: foreach my $item (@contacts) {
12698: if ($to{$item} ne $currsetting{$item}) {
12699: $changes{$item} = 1;
12700: }
12701: }
12702: foreach my $type (@mailings) {
12703: foreach my $item (@contacts) {
12704: if (ref($currsetting{$type}) eq 'HASH') {
12705: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
12706: push(@{$changes{$type}},$item);
12707: }
12708: } else {
12709: push(@{$changes{$type}},@{$newsetting{$type}});
12710: }
12711: }
12712: if ($others{$type} ne $currsetting{$type}{'others'}) {
12713: push(@{$changes{$type}},'others');
12714: }
1.289 raeburn 12715: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12716: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
12717: push(@{$changes{$type}},'bcc');
12718: }
1.286 raeburn 12719: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
12720: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
12721: push(@{$changes{$type}},'include');
12722: }
12723: }
12724: }
12725: if (ref($fields) eq 'ARRAY') {
12726: if (ref($currsetting{'helpform'}) eq 'HASH') {
12727: foreach my $field (@{$fields}) {
12728: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
12729: push(@{$changes{'helpform'}},$field);
12730: }
12731: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12732: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
12733: push(@{$changes{'helpform'}},'maxsize');
12734: }
12735: }
12736: }
12737: } else {
12738: foreach my $field (@{$fields}) {
12739: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12740: push(@{$changes{'helpform'}},$field);
12741: }
12742: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12743: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12744: push(@{$changes{'helpform'}},'maxsize');
12745: }
12746: }
12747: }
1.134 raeburn 12748: }
1.28 raeburn 12749: }
1.315 raeburn 12750: if (@statuses) {
12751: if (ref($currsetting{'overrides'}) eq 'HASH') {
12752: foreach my $key (keys(%{$currsetting{'overrides'}})) {
12753: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
12754: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
12755: foreach my $item (@contacts,'bcc','others','include') {
12756: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
12757: push(@{$changes{'overrides'}},$key);
12758: last;
12759: }
12760: }
12761: } else {
12762: push(@{$changes{'overrides'}},$key);
12763: }
12764: }
12765: }
12766: foreach my $key (@overrides) {
12767: unless (exists($currsetting{'overrides'}{$key})) {
12768: push(@{$changes{'overrides'}},$key);
12769: }
12770: }
12771: } else {
12772: foreach my $key (@overrides) {
12773: push(@{$changes{'overrides'}},$key);
12774: }
12775: }
12776: }
1.28 raeburn 12777: } else {
12778: my %default;
12779: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
12780: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
12781: $default{'errormail'} = 'adminemail';
12782: $default{'packagesmail'} = 'adminemail';
12783: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 12784: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 12785: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 12786: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 12787: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 12788: foreach my $item (@contacts) {
12789: if ($to{$item} ne $default{$item}) {
1.286 raeburn 12790: $changes{$item} = 1;
1.203 raeburn 12791: }
1.28 raeburn 12792: }
12793: foreach my $type (@mailings) {
12794: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
12795: push(@{$changes{$type}},@{$newsetting{$type}});
12796: }
12797: if ($others{$type} ne '') {
12798: push(@{$changes{$type}},'others');
1.134 raeburn 12799: }
1.286 raeburn 12800: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12801: if ($bcc{$type} ne '') {
12802: push(@{$changes{$type}},'bcc');
12803: }
1.286 raeburn 12804: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
12805: push(@{$changes{$type}},'include');
12806: }
1.134 raeburn 12807: }
1.28 raeburn 12808: }
1.286 raeburn 12809: if (ref($fields) eq 'ARRAY') {
12810: foreach my $field (@{$fields}) {
12811: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12812: push(@{$changes{'helpform'}},$field);
12813: }
12814: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12815: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12816: push(@{$changes{'helpform'}},'maxsize');
12817: }
12818: }
12819: }
1.289 raeburn 12820: }
1.28 raeburn 12821: }
1.203 raeburn 12822: foreach my $item (@toggles) {
12823: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
12824: $changes{$item} = 1;
12825: } elsif ((!$env{'form.'.$item}) &&
12826: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
12827: $changes{$item} = 1;
12828: }
12829: }
1.28 raeburn 12830: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
12831: $dom);
12832: if ($putresult eq 'ok') {
12833: if (keys(%changes) > 0) {
1.205 raeburn 12834: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12835: if (ref($lastactref) eq 'HASH') {
12836: $lastactref->{'domainconfig'} = 1;
12837: }
1.28 raeburn 12838: my ($titles,$short_titles) = &contact_titles();
12839: $resulttext = &mt('Changes made:').'<ul>';
12840: foreach my $item (@contacts) {
12841: if ($changes{$item}) {
12842: $resulttext .= '<li>'.$titles->{$item}.
12843: &mt(' set to: ').
12844: '<span class="LC_cusr_emph">'.
12845: $to{$item}.'</span></li>';
12846: }
12847: }
12848: foreach my $type (@mailings) {
12849: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 12850: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 12851: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 12852: } else {
12853: $resulttext .= '<li>'.$titles->{$type}.': ';
12854: }
1.28 raeburn 12855: my @text;
12856: foreach my $item (@{$newsetting{$type}}) {
12857: push(@text,$short_titles->{$item});
12858: }
12859: if ($others{$type} ne '') {
12860: push(@text,$others{$type});
12861: }
1.286 raeburn 12862: if (@text) {
12863: $resulttext .= '<span class="LC_cusr_emph">'.
12864: join(', ',@text).'</span>';
12865: }
12866: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12867: if ($bcc{$type} ne '') {
1.286 raeburn 12868: my $bcctext;
12869: if (@text) {
1.289 raeburn 12870: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 12871: } else {
12872: $bcctext = '(Bcc)';
12873: }
12874: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
12875: } elsif (!@text) {
12876: $resulttext .= &mt('No one');
12877: }
1.289 raeburn 12878: if ($includestr{$type} ne '') {
1.286 raeburn 12879: if ($includeloc{$type} eq 'b') {
12880: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
12881: } elsif ($includeloc{$type} eq 's') {
12882: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
12883: }
1.134 raeburn 12884: }
1.286 raeburn 12885: } elsif (!@text) {
12886: $resulttext .= &mt('No recipients');
1.134 raeburn 12887: }
12888: $resulttext .= '</li>';
1.28 raeburn 12889: }
12890: }
1.315 raeburn 12891: if (ref($changes{'overrides'}) eq 'ARRAY') {
12892: my @deletions;
12893: foreach my $type (@{$changes{'overrides'}}) {
12894: if ($usertypeshash{$type}) {
12895: if (grep(/^\Q$type\E/,@overrides)) {
12896: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
12897: $usertypeshash{$type}).'<ul><li>';
12898: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
12899: my @text;
12900: foreach my $item (@contacts) {
12901: if ($newsetting{'override_'.$type}{$item}) {
12902: push(@text,$short_titles->{$item});
12903: }
12904: }
12905: if ($newsetting{'override_'.$type}{'others'} ne '') {
12906: push(@text,$newsetting{'override_'.$type}{'others'});
12907: }
12908:
12909: if (@text) {
12910: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
12911: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
12912: }
12913: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
12914: my $bcctext;
12915: if (@text) {
12916: $bcctext = ' '.&mt('with Bcc to');
12917: } else {
12918: $bcctext = '(Bcc)';
12919: }
12920: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
12921: } elsif (!@text) {
12922: $resulttext .= &mt('Helpdesk e-mail sent to no one');
12923: }
12924: $resulttext .= '</li>';
12925: if ($newsetting{'override_'.$type}{'include'} ne '') {
12926: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
12927: if ($loc eq 'b') {
12928: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
12929: } elsif ($loc eq 's') {
12930: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
12931: }
12932: }
12933: }
12934: $resulttext .= '</li></ul></li>';
12935: } else {
12936: push(@deletions,$usertypeshash{$type});
12937: }
12938: }
12939: }
12940: if (@deletions) {
12941: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
12942: join(', ',@deletions)).'</li>';
12943: }
12944: }
1.203 raeburn 12945: my @offon = ('off','on');
12946: if ($changes{'reporterrors'}) {
12947: $resulttext .= '<li>'.
12948: &mt('E-mail error reports to [_1] set to "'.
12949: $offon[$env{'form.reporterrors'}].'".',
12950: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
12951: &mt('LON-CAPA core group - MSU'),600,500)).
12952: '</li>';
12953: }
12954: if ($changes{'reportupdates'}) {
12955: $resulttext .= '<li>'.
12956: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
12957: $offon[$env{'form.reportupdates'}].'".',
12958: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
12959: &mt('LON-CAPA core group - MSU'),600,500)).
12960: '</li>';
12961: }
1.286 raeburn 12962: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
12963: my (@optional,@required,@unused,$maxsizechg);
12964: foreach my $field (@{$changes{'helpform'}}) {
12965: if ($field eq 'maxsize') {
12966: $maxsizechg = 1;
12967: next;
12968: }
12969: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 12970: push(@optional,$field);
1.286 raeburn 12971: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
12972: push(@unused,$field);
12973: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 12974: push(@required,$field);
1.286 raeburn 12975: }
12976: }
12977: if (@optional) {
12978: $resulttext .= '<li>'.
12979: &mt('Help form fields changed to "Optional": [_1].',
12980: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
12981: '</li>';
12982: }
12983: if (@required) {
12984: $resulttext .= '<li>'.
12985: &mt('Help form fields changed to "Required": [_1].',
12986: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
12987: '</li>';
12988: }
12989: if (@unused) {
12990: $resulttext .= '<li>'.
12991: &mt('Help form fields changed to "Not shown": [_1].',
12992: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
12993: '</li>';
12994: }
12995: if ($maxsizechg) {
12996: $resulttext .= '<li>'.
12997: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
12998: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
12999: '</li>';
13000: }
13001: }
1.28 raeburn 13002: $resulttext .= '</ul>';
13003: } else {
1.288 raeburn 13004: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 13005: }
13006: } else {
13007: $resulttext = '<span class="LC_error">'.
13008: &mt('An error occurred: [_1].',$putresult).'</span>';
13009: }
13010: return $resulttext;
13011: }
13012:
13013: sub modify_usercreation {
1.27 raeburn 13014: my ($dom,%domconfig) = @_;
1.224 raeburn 13015: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 13016: my $warningmsg;
1.27 raeburn 13017: if (ref($domconfig{'usercreation'}) eq 'HASH') {
13018: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 13019: if ($key eq 'cancreate') {
13020: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
13021: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 13022: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
13023: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13024: } else {
1.224 raeburn 13025: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13026: }
13027: }
13028: }
13029: } elsif ($key eq 'email_rule') {
13030: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
13031: } else {
13032: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
13033: }
1.27 raeburn 13034: }
13035: }
13036: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 13037: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 13038: my @contexts = ('author','course','requestcrs');
1.34 raeburn 13039: foreach my $item(@contexts) {
1.224 raeburn 13040: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 13041: }
1.34 raeburn 13042: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13043: foreach my $item (@contexts) {
1.224 raeburn 13044: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
13045: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 13046: }
1.27 raeburn 13047: }
1.34 raeburn 13048: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
13049: foreach my $item (@contexts) {
1.43 raeburn 13050: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 13051: if ($cancreate{$item} ne 'any') {
13052: push(@{$changes{'cancreate'}},$item);
13053: }
13054: } else {
13055: if ($cancreate{$item} ne 'none') {
13056: push(@{$changes{'cancreate'}},$item);
13057: }
1.27 raeburn 13058: }
13059: }
13060: } else {
1.43 raeburn 13061: foreach my $item (@contexts) {
1.34 raeburn 13062: push(@{$changes{'cancreate'}},$item);
13063: }
1.27 raeburn 13064: }
1.34 raeburn 13065:
1.27 raeburn 13066: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
13067: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
13068: if (!grep(/^\Q$type\E$/,@username_rule)) {
13069: push(@{$changes{'username_rule'}},$type);
13070: }
13071: }
13072: foreach my $type (@username_rule) {
13073: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
13074: push(@{$changes{'username_rule'}},$type);
13075: }
13076: }
13077: } else {
13078: push(@{$changes{'username_rule'}},@username_rule);
13079: }
13080:
1.32 raeburn 13081: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
13082: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
13083: if (!grep(/^\Q$type\E$/,@id_rule)) {
13084: push(@{$changes{'id_rule'}},$type);
13085: }
13086: }
13087: foreach my $type (@id_rule) {
13088: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
13089: push(@{$changes{'id_rule'}},$type);
13090: }
13091: }
13092: } else {
13093: push(@{$changes{'id_rule'}},@id_rule);
13094: }
13095:
1.43 raeburn 13096: my @authen_contexts = ('author','course','domain');
1.325 raeburn 13097: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 13098: my %authhash;
1.43 raeburn 13099: foreach my $item (@authen_contexts) {
1.28 raeburn 13100: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
13101: foreach my $auth (@authtypes) {
13102: if (grep(/^\Q$auth\E$/,@authallowed)) {
13103: $authhash{$item}{$auth} = 1;
13104: } else {
13105: $authhash{$item}{$auth} = 0;
13106: }
13107: }
13108: }
13109: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 13110: foreach my $item (@authen_contexts) {
1.28 raeburn 13111: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
13112: foreach my $auth (@authtypes) {
13113: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
13114: push(@{$changes{'authtypes'}},$item);
13115: last;
13116: }
13117: }
13118: }
13119: }
13120: } else {
1.43 raeburn 13121: foreach my $item (@authen_contexts) {
1.28 raeburn 13122: push(@{$changes{'authtypes'}},$item);
13123: }
13124: }
13125:
1.224 raeburn 13126: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
13127: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
13128: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
13129: $save_usercreate{'id_rule'} = \@id_rule;
13130: $save_usercreate{'username_rule'} = \@username_rule,
13131: $save_usercreate{'authtypes'} = \%authhash;
13132:
1.27 raeburn 13133: my %usercreation_hash = (
1.224 raeburn 13134: usercreation => \%save_usercreate,
13135: );
1.27 raeburn 13136:
13137: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
13138: $dom);
1.50 raeburn 13139:
1.224 raeburn 13140: if ($putresult eq 'ok') {
13141: if (keys(%changes) > 0) {
13142: $resulttext = &mt('Changes made:').'<ul>';
13143: if (ref($changes{'cancreate'}) eq 'ARRAY') {
13144: my %lt = &usercreation_types();
13145: foreach my $type (@{$changes{'cancreate'}}) {
13146: my $chgtext = $lt{$type}.', ';
13147: if ($cancreate{$type} eq 'none') {
13148: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
13149: } elsif ($cancreate{$type} eq 'any') {
13150: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
13151: } elsif ($cancreate{$type} eq 'official') {
13152: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
13153: } elsif ($cancreate{$type} eq 'unofficial') {
13154: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
13155: }
13156: $resulttext .= '<li>'.$chgtext.'</li>';
13157: }
13158: }
13159: if (ref($changes{'username_rule'}) eq 'ARRAY') {
13160: my ($rules,$ruleorder) =
13161: &Apache::lonnet::inst_userrules($dom,'username');
13162: my $chgtext = '<ul>';
13163: foreach my $type (@username_rule) {
13164: if (ref($rules->{$type}) eq 'HASH') {
13165: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
13166: }
13167: }
13168: $chgtext .= '</ul>';
13169: if (@username_rule > 0) {
13170: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13171: } else {
13172: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
13173: }
13174: }
13175: if (ref($changes{'id_rule'}) eq 'ARRAY') {
13176: my ($idrules,$idruleorder) =
13177: &Apache::lonnet::inst_userrules($dom,'id');
13178: my $chgtext = '<ul>';
13179: foreach my $type (@id_rule) {
13180: if (ref($idrules->{$type}) eq 'HASH') {
13181: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
13182: }
13183: }
13184: $chgtext .= '</ul>';
13185: if (@id_rule > 0) {
13186: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13187: } else {
13188: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
13189: }
13190: }
13191: my %authname = &authtype_names();
13192: my %context_title = &context_names();
13193: if (ref($changes{'authtypes'}) eq 'ARRAY') {
13194: my $chgtext = '<ul>';
13195: foreach my $type (@{$changes{'authtypes'}}) {
13196: my @allowed;
13197: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
13198: foreach my $auth (@authtypes) {
13199: if ($authhash{$type}{$auth}) {
13200: push(@allowed,$authname{$auth});
13201: }
13202: }
13203: if (@allowed > 0) {
13204: $chgtext .= join(', ',@allowed).'</li>';
13205: } else {
13206: $chgtext .= &mt('none').'</li>';
13207: }
13208: }
13209: $chgtext .= '</ul>';
13210: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
13211: $resulttext .= '</li>';
13212: }
13213: $resulttext .= '</ul>';
13214: } else {
13215: $resulttext = &mt('No changes made to user creation settings');
13216: }
13217: } else {
13218: $resulttext = '<span class="LC_error">'.
13219: &mt('An error occurred: [_1]',$putresult).'</span>';
13220: }
13221: if ($warningmsg ne '') {
13222: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
13223: }
13224: return $resulttext;
13225: }
13226:
13227: sub modify_selfcreation {
1.305 raeburn 13228: my ($dom,$lastactref,%domconfig) = @_;
13229: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
13230: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
13231: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 13232: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
13233: if (ref($typesref) eq 'ARRAY') {
13234: @types = @{$typesref};
13235: }
13236: if (ref($usertypesref) eq 'HASH') {
13237: %usertypes = %{$usertypesref};
1.228 raeburn 13238: }
1.303 raeburn 13239: $usertypes{'default'} = $othertitle;
1.224 raeburn 13240: #
13241: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
13242: #
13243: if (ref($domconfig{'usercreation'}) eq 'HASH') {
13244: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
13245: if ($key eq 'cancreate') {
13246: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
13247: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
13248: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 13249: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
13250: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
13251: ($item eq 'emailusername') || ($item eq 'shibenv') ||
13252: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 13253: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 13254: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13255: } else {
13256: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13257: }
13258: }
13259: }
13260: } elsif ($key eq 'email_rule') {
13261: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
13262: } else {
13263: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
13264: }
13265: }
13266: }
13267: #
13268: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
13269: #
13270: if (ref($domconfig{'usermodification'}) eq 'HASH') {
13271: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
13272: if ($key eq 'selfcreate') {
13273: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
13274: } else {
13275: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
13276: }
13277: }
13278: }
1.305 raeburn 13279: #
13280: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
13281: #
13282: if (ref($domconfig{'inststatus'}) eq 'HASH') {
13283: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
13284: if ($key eq 'inststatusguest') {
13285: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
13286: } else {
13287: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
13288: }
13289: }
13290: }
1.224 raeburn 13291:
13292: my @contexts = ('selfcreate');
13293: @{$cancreate{'selfcreate'}} = ();
13294: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 13295: if (@types) {
13296: @{$cancreate{'statustocreate'}} = ();
13297: }
1.236 raeburn 13298: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 13299: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 13300: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 13301: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 13302: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 13303: my %selfcreatetypes = (
13304: sso => 'users authenticated by institutional single sign on',
13305: login => 'users authenticated by institutional log-in',
1.303 raeburn 13306: email => 'users verified by e-mail',
1.50 raeburn 13307: );
1.224 raeburn 13308: #
13309: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
13310: # is permitted.
13311: #
1.305 raeburn 13312: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 13313:
1.305 raeburn 13314: my (@statuses,%email_rule);
1.228 raeburn 13315: foreach my $item ('login','sso','email') {
1.224 raeburn 13316: if ($item eq 'email') {
1.236 raeburn 13317: if ($env{'form.cancreate_email'}) {
1.305 raeburn 13318: if (@types) {
13319: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
13320: foreach my $status (@poss_statuses) {
13321: if (grep(/^\Q$status\E$/,(@types,'default'))) {
13322: push(@statuses,$status);
13323: }
13324: }
13325: $save_inststatus{'inststatusguest'} = \@statuses;
13326: } else {
13327: push(@statuses,'default');
13328: }
13329: if (@statuses) {
13330: my %curr_rule;
13331: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
13332: foreach my $type (@statuses) {
13333: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 13334: }
1.305 raeburn 13335: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
13336: foreach my $type (@statuses) {
13337: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
13338: }
13339: }
13340: push(@{$cancreate{'selfcreate'}},'email');
13341: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
13342: my %curremaildom;
13343: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
13344: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
13345: }
13346: foreach my $type (@statuses) {
13347: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
13348: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
13349: }
13350: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
13351: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
13352: }
13353: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
13354: #
13355: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
13356: #
13357: my $chosen = $1;
13358: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
13359: my $emaildom;
13360: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
13361: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
13362: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
13363: if (ref($curremaildom{$type}) eq 'HASH') {
13364: if (exists($curremaildom{$type}{$chosen})) {
13365: if ($curremaildom{$type}{$chosen} ne $emaildom) {
13366: push(@{$changes{'cancreate'}},'emaildomain');
13367: }
13368: } elsif ($emaildom ne '') {
13369: push(@{$changes{'cancreate'}},'emaildomain');
13370: }
13371: } elsif ($emaildom ne '') {
13372: push(@{$changes{'cancreate'}},'emaildomain');
13373: }
13374: }
13375: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13376: } elsif ($chosen eq 'custom') {
13377: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
13378: $email_rule{$type} = [];
13379: if (ref($emailrules) eq 'HASH') {
13380: foreach my $rule (@possemail_rules) {
13381: if (exists($emailrules->{$rule})) {
13382: push(@{$email_rule{$type}},$rule);
13383: }
13384: }
13385: }
13386: if (@{$email_rule{$type}}) {
13387: $cancreate{'emailoptions'}{$type} = 'custom';
13388: if (ref($curr_rule{$type}) eq 'ARRAY') {
13389: if (@{$curr_rule{$type}} > 0) {
13390: foreach my $rule (@{$curr_rule{$type}}) {
13391: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
13392: push(@{$changes{'email_rule'}},$type);
13393: }
13394: }
13395: }
13396: foreach my $type (@{$email_rule{$type}}) {
13397: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
13398: push(@{$changes{'email_rule'}},$type);
13399: }
13400: }
13401: } else {
13402: push(@{$changes{'email_rule'}},$type);
13403: }
13404: }
13405: } else {
13406: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13407: }
13408: }
13409: }
13410: if (@types) {
13411: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13412: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
13413: if (@changed) {
13414: push(@{$changes{'inststatus'}},'inststatusguest');
13415: }
13416: } else {
13417: push(@{$changes{'inststatus'}},'inststatusguest');
13418: }
13419: }
13420: } else {
13421: delete($env{'form.cancreate_email'});
13422: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13423: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13424: push(@{$changes{'inststatus'}},'inststatusguest');
13425: }
13426: }
13427: }
13428: } else {
13429: $save_inststatus{'inststatusguest'} = [];
13430: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13431: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13432: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 13433: }
13434: }
1.224 raeburn 13435: }
13436: } else {
13437: if ($env{'form.cancreate_'.$item}) {
13438: push(@{$cancreate{'selfcreate'}},$item);
13439: }
13440: }
13441: }
1.305 raeburn 13442: my (%userinfo,%savecaptcha);
1.224 raeburn 13443: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
13444: #
1.228 raeburn 13445: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
13446: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 13447: #
1.236 raeburn 13448:
1.244 raeburn 13449: if ($env{'form.cancreate_email'}) {
1.228 raeburn 13450: push(@contexts,'emailusername');
1.305 raeburn 13451: if (@statuses) {
13452: foreach my $type (@statuses) {
1.228 raeburn 13453: if (ref($infofields) eq 'ARRAY') {
13454: foreach my $field (@{$infofields}) {
13455: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
13456: $cancreate{'emailusername'}{$type}{$field} = $1;
13457: }
13458: }
1.224 raeburn 13459: }
13460: }
13461: }
13462: #
13463: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 13464: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 13465: #
13466:
13467: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
13468: @approvalnotify = sort(@approvalnotify);
13469: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
13470: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13471: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
13472: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
13473: push(@{$changes{'cancreate'}},'notify');
13474: }
13475: } else {
13476: if ($cancreate{'notify'}{'approval'}) {
13477: push(@{$changes{'cancreate'}},'notify');
13478: }
13479: }
13480: } elsif ($cancreate{'notify'}{'approval'}) {
13481: push(@{$changes{'cancreate'}},'notify');
13482: }
13483:
13484: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
13485: }
13486: #
1.236 raeburn 13487: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 13488: # institutional log-in.
13489: #
13490: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
13491: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
13492: ($domdefaults{'auth_def'} eq 'localauth'))) {
13493: $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.').' '.
13494: &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.');
13495: }
13496: }
13497: my @fields = ('lastname','firstname','middlename','generation',
13498: 'permanentemail','id');
1.240 raeburn 13499: my @shibfields = (@fields,'inststatus');
1.224 raeburn 13500: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13501: #
13502: # Where usernames may created for institutional log-in and/or institutional single sign on:
13503: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
13504: # may self-create accounts
13505: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
13506: # which the user may supply, if institutional data is unavailable.
13507: #
13508: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 13509: if (@types) {
1.305 raeburn 13510: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
13511: push(@contexts,'statustocreate');
1.303 raeburn 13512: foreach my $type (@types) {
1.224 raeburn 13513: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
13514: foreach my $field (@fields) {
13515: if (grep(/^\Q$field\E$/,@modifiable)) {
13516: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
13517: } else {
13518: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
13519: }
13520: }
13521: }
13522: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 13523: foreach my $type (@types) {
1.224 raeburn 13524: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
13525: foreach my $field (@fields) {
13526: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
13527: $curr_usermodify{'selfcreate'}{$type}{$field}) {
13528: push(@{$changes{'selfcreate'}},$type);
13529: last;
13530: }
13531: }
13532: }
13533: }
13534: } else {
1.303 raeburn 13535: foreach my $type (@types) {
1.224 raeburn 13536: push(@{$changes{'selfcreate'}},$type);
13537: }
13538: }
13539: }
1.240 raeburn 13540: foreach my $field (@shibfields) {
13541: if ($env{'form.shibenv_'.$field} ne '') {
13542: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
13543: }
13544: }
13545: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13546: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
13547: foreach my $field (@shibfields) {
13548: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
13549: push(@{$changes{'cancreate'}},'shibenv');
13550: }
13551: }
13552: } else {
13553: foreach my $field (@shibfields) {
13554: if ($env{'form.shibenv_'.$field}) {
13555: push(@{$changes{'cancreate'}},'shibenv');
13556: last;
13557: }
13558: }
13559: }
13560: }
1.224 raeburn 13561: }
13562: foreach my $item (@contexts) {
13563: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
13564: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
13565: if (ref($cancreate{$item}) eq 'ARRAY') {
13566: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
13567: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13568: push(@{$changes{'cancreate'}},$item);
13569: }
13570: }
13571: }
13572: }
13573: if (ref($cancreate{$item}) eq 'ARRAY') {
13574: foreach my $type (@{$cancreate{$item}}) {
13575: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
13576: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13577: push(@{$changes{'cancreate'}},$item);
13578: }
13579: }
13580: }
13581: }
13582: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
13583: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 13584: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
13585: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13586: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
13587: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 13588: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13589: push(@{$changes{'cancreate'}},$item);
13590: }
13591: }
13592: }
1.305 raeburn 13593: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13594: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 13595: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13596: push(@{$changes{'cancreate'}},$item);
13597: }
1.224 raeburn 13598: }
13599: }
13600: }
1.305 raeburn 13601: foreach my $type (keys(%{$cancreate{$item}})) {
13602: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13603: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13604: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13605: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 13606: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13607: push(@{$changes{'cancreate'}},$item);
13608: }
13609: }
13610: } else {
13611: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13612: push(@{$changes{'cancreate'}},$item);
13613: }
13614: }
13615: }
1.305 raeburn 13616: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13617: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 13618: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13619: push(@{$changes{'cancreate'}},$item);
13620: }
1.224 raeburn 13621: }
13622: }
13623: }
13624: }
13625: } elsif ($curr_usercreation{'cancreate'}{$item}) {
13626: if (ref($cancreate{$item}) eq 'ARRAY') {
13627: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
13628: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13629: push(@{$changes{'cancreate'}},$item);
13630: }
13631: }
1.305 raeburn 13632: }
13633: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13634: if (ref($cancreate{$item}) eq 'HASH') {
13635: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13636: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 13637: }
13638: }
13639: } elsif ($item eq 'emailusername') {
1.228 raeburn 13640: if (ref($cancreate{$item}) eq 'HASH') {
13641: foreach my $type (keys(%{$cancreate{$item}})) {
13642: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13643: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13644: if ($cancreate{$item}{$type}{$field}) {
13645: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13646: push(@{$changes{'cancreate'}},$item);
13647: }
13648: last;
13649: }
13650: }
13651: }
13652: }
1.224 raeburn 13653: }
13654: }
13655: }
13656: #
13657: # Populate %save_usercreate hash with updates to self-creation configuration.
13658: #
13659: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
13660: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 13661: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 13662: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
13663: if (ref($cancreate{'notify'}) eq 'HASH') {
13664: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
13665: }
1.236 raeburn 13666: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
13667: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
13668: }
1.303 raeburn 13669: if (ref($cancreate{'emailverified'}) eq 'HASH') {
13670: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
13671: }
1.305 raeburn 13672: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
13673: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
13674: }
1.303 raeburn 13675: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
13676: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
13677: }
1.224 raeburn 13678: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13679: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
13680: }
1.240 raeburn 13681: if (ref($cancreate{'shibenv'}) eq 'HASH') {
13682: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
13683: }
1.224 raeburn 13684: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 13685: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 13686:
13687: my %userconfig_hash = (
13688: usercreation => \%save_usercreate,
13689: usermodification => \%save_usermodify,
1.305 raeburn 13690: inststatus => \%save_inststatus,
1.224 raeburn 13691: );
1.305 raeburn 13692:
1.224 raeburn 13693: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
13694: $dom);
13695: #
1.305 raeburn 13696: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 13697: #
1.27 raeburn 13698: if ($putresult eq 'ok') {
13699: if (keys(%changes) > 0) {
13700: $resulttext = &mt('Changes made:').'<ul>';
13701: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 13702: my %lt = &selfcreation_types();
1.34 raeburn 13703: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 13704: my $chgtext = '';
1.45 raeburn 13705: if ($type eq 'selfcreate') {
1.50 raeburn 13706: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 13707: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 13708: } else {
1.224 raeburn 13709: $chgtext .= &mt('Self-creation of a new account is permitted for:').
13710: '<ul>';
1.50 raeburn 13711: foreach my $case (@{$cancreate{$type}}) {
13712: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
13713: }
13714: $chgtext .= '</ul>';
1.100 raeburn 13715: if (ref($cancreate{$type}) eq 'ARRAY') {
13716: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
13717: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13718: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 13719: $chgtext .= '<span class="LC_warning">'.
13720: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
13721: '</span><br />';
13722: }
13723: }
13724: }
13725: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 13726: if (!@statuses) {
13727: $chgtext .= '<span class="LC_warning">'.
13728: &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.").
13729: '</span><br />';
1.303 raeburn 13730:
1.100 raeburn 13731: }
13732: }
13733: }
1.43 raeburn 13734: }
1.240 raeburn 13735: } elsif ($type eq 'shibenv') {
13736: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 13737: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 13738: } else {
13739: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
13740: '<ul>';
13741: foreach my $field (@shibfields) {
13742: next if ($cancreate{$type}{$field} eq '');
13743: if ($field eq 'inststatus') {
13744: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
13745: } else {
13746: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
13747: }
13748: }
13749: $chgtext .= '</ul>';
1.303 raeburn 13750: }
1.93 raeburn 13751: } elsif ($type eq 'statustocreate') {
1.96 raeburn 13752: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
13753: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
13754: if (@{$cancreate{'selfcreate'}} > 0) {
13755: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 13756: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 13757: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 13758: $chgtext .= '<br />'.
13759: '<span class="LC_warning">'.
13760: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
13761: '</span>';
13762: }
1.303 raeburn 13763: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 13764: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 13765: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
13766: } else {
13767: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
13768: }
13769: $chgtext .= '<ul>';
13770: foreach my $case (@{$cancreate{$type}}) {
13771: if ($case eq 'default') {
13772: $chgtext .= '<li>'.$othertitle.'</li>';
13773: } else {
1.303 raeburn 13774: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 13775: }
13776: }
1.100 raeburn 13777: $chgtext .= '</ul>';
13778: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 13779: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 13780: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
13781: '</span>';
1.100 raeburn 13782: }
13783: }
13784: } else {
13785: if (@{$cancreate{$type}} == 0) {
13786: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
13787: } else {
13788: $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 13789: }
13790: }
1.303 raeburn 13791: $chgtext .= '<br />';
1.93 raeburn 13792: }
1.236 raeburn 13793: } elsif ($type eq 'selfcreateprocessing') {
13794: my %choices = &Apache::lonlocal::texthash (
13795: automatic => 'Automatic approval',
13796: approval => 'Queued for approval',
13797: );
1.305 raeburn 13798: if (@types) {
13799: if (@statuses) {
1.303 raeburn 13800: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 13801: '<ul>';
1.305 raeburn 13802: foreach my $status (@statuses) {
13803: if ($status eq 'default') {
13804: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 13805: } else {
1.305 raeburn 13806: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 13807: }
13808: }
13809: $chgtext .= '</ul>';
13810: }
13811: } else {
13812: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
13813: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
13814: }
13815: } elsif ($type eq 'emailverified') {
13816: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 13817: all => 'Same as e-mail',
13818: first => 'Omit @domain',
13819: free => 'Free to choose',
1.303 raeburn 13820: );
1.305 raeburn 13821: if (@types) {
13822: if (@statuses) {
1.303 raeburn 13823: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
13824: '<ul>';
1.305 raeburn 13825: foreach my $status (@statuses) {
1.303 raeburn 13826: if ($type eq 'default') {
1.305 raeburn 13827: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 13828: } else {
1.305 raeburn 13829: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 13830: }
13831: }
13832: $chgtext .= '</ul>';
13833: }
13834: } else {
1.305 raeburn 13835: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 13836: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 13837: }
1.305 raeburn 13838: } elsif ($type eq 'emailoptions') {
13839: my %options = &Apache::lonlocal::texthash (
13840: any => 'Any e-mail',
13841: inst => 'Institutional only',
13842: noninst => 'Non-institutional only',
13843: custom => 'Custom restrictions',
13844: );
13845: if (@types) {
13846: if (@statuses) {
13847: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
13848: '<ul>';
13849: foreach my $status (@statuses) {
13850: if ($type eq 'default') {
13851: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
13852: } else {
13853: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 13854: }
13855: }
1.305 raeburn 13856: $chgtext .= '</ul>';
13857: }
13858: } else {
13859: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
13860: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
13861: } else {
13862: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
13863: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 13864: }
1.305 raeburn 13865: }
13866: } elsif ($type eq 'emaildomain') {
13867: my $output;
13868: if (@statuses) {
13869: foreach my $type (@statuses) {
13870: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
13871: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
13872: if ($type eq 'default') {
13873: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13874: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
13875: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
13876: } else {
13877: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
13878: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
13879: }
1.303 raeburn 13880: } else {
1.305 raeburn 13881: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13882: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
13883: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
13884: } else {
13885: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
13886: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
13887: }
1.303 raeburn 13888: }
1.305 raeburn 13889: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
13890: if ($type eq 'default') {
13891: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13892: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
13893: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
13894: } else {
13895: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
13896: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
13897: }
1.303 raeburn 13898: } else {
1.305 raeburn 13899: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13900: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
13901: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
13902: } else {
13903: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
13904: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
13905: }
1.303 raeburn 13906: }
13907: }
13908: }
13909: }
1.305 raeburn 13910: }
13911: if ($output ne '') {
13912: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
13913: '<ul>'.$output.'</ul>';
1.236 raeburn 13914: }
1.165 raeburn 13915: } elsif ($type eq 'captcha') {
1.224 raeburn 13916: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 13917: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
13918: } else {
13919: my %captchas = &captcha_phrases();
1.224 raeburn 13920: if ($captchas{$savecaptcha{$type}}) {
13921: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 13922: } else {
1.210 raeburn 13923: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 13924: }
13925: }
13926: } elsif ($type eq 'recaptchakeys') {
13927: my ($privkey,$pubkey);
1.224 raeburn 13928: if (ref($savecaptcha{$type}) eq 'HASH') {
13929: $pubkey = $savecaptcha{$type}{'public'};
13930: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 13931: }
13932: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
13933: if (!$pubkey) {
13934: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
13935: } else {
13936: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
13937: }
13938: if (!$privkey) {
13939: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
13940: } else {
13941: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
13942: }
13943: $chgtext .= '</ul>';
1.269 raeburn 13944: } elsif ($type eq 'recaptchaversion') {
13945: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 13946: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 13947: }
1.224 raeburn 13948: } elsif ($type eq 'emailusername') {
13949: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 13950: if (@statuses) {
13951: foreach my $type (@statuses) {
1.228 raeburn 13952: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
13953: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 13954: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 13955: '<ul>';
13956: foreach my $field (@{$infofields}) {
13957: if ($cancreate{'emailusername'}{$type}{$field}) {
13958: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
13959: }
13960: }
1.245 raeburn 13961: $chgtext .= '</ul>';
13962: } else {
1.303 raeburn 13963: $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 13964: }
13965: } else {
1.303 raeburn 13966: $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 13967: }
13968: }
13969: }
13970: }
13971: } elsif ($type eq 'notify') {
1.303 raeburn 13972: my $numapprove = 0;
1.224 raeburn 13973: if (ref($changes{'cancreate'}) eq 'ARRAY') {
13974: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
13975: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 13976: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
13977: $numapprove ++;
1.224 raeburn 13978: }
13979: }
1.43 raeburn 13980: }
1.303 raeburn 13981: unless ($numapprove) {
13982: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
13983: }
1.34 raeburn 13984: }
1.224 raeburn 13985: if ($chgtext) {
13986: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 13987: }
13988: }
13989: }
1.305 raeburn 13990: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 13991: my ($emailrules,$emailruleorder) =
13992: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 13993: foreach my $type (@{$changes{'email_rule'}}) {
13994: if (ref($email_rule{$type}) eq 'ARRAY') {
13995: my $chgtext = '<ul>';
13996: foreach my $rule (@{$email_rule{$type}}) {
13997: if (ref($emailrules->{$rule}) eq 'HASH') {
13998: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
13999: }
14000: }
14001: $chgtext .= '</ul>';
1.310 raeburn 14002: my $typename;
1.305 raeburn 14003: if (@types) {
14004: if ($type eq 'default') {
14005: $typename = $othertitle;
14006: } else {
14007: $typename = $usertypes{$type};
14008: }
14009: $chgtext .= &mt('(Affiliation: [_1])',$typename);
14010: }
14011: if (@{$email_rule{$type}} > 0) {
14012: $resulttext .= '<li>'.
14013: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
14014: $usertypes{$type}).
14015: $chgtext.
14016: '</li>';
14017: } else {
14018: $resulttext .= '<li>'.
1.310 raeburn 14019: &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 14020: '</li>'.
1.310 raeburn 14021: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 14022: }
1.43 raeburn 14023: }
14024: }
1.305 raeburn 14025: }
14026: if (ref($changes{'inststatus'}) eq 'ARRAY') {
14027: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
14028: if (@{$save_inststatus{'inststatusguest'}} > 0) {
14029: my $chgtext = '<ul>';
14030: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
14031: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
14032: }
14033: $chgtext .= '</ul>';
14034: $resulttext .= '<li>'.
14035: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
14036: $chgtext.
14037: '</li>';
14038: } else {
14039: $resulttext .= '<li>'.
14040: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
14041: '</li>';
14042: }
1.43 raeburn 14043: }
14044: }
1.224 raeburn 14045: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
14046: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
14047: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14048: foreach my $type (@{$changes{'selfcreate'}}) {
14049: my $typename = $type;
1.303 raeburn 14050: if (keys(%usertypes) > 0) {
14051: if ($usertypes{$type} ne '') {
14052: $typename = $usertypes{$type};
1.224 raeburn 14053: }
14054: }
14055: my @modifiable;
14056: $resulttext .= '<li>'.
14057: &mt('Self-creation of account by users with status: [_1]',
14058: '<span class="LC_cusr_emph">'.$typename.'</span>').
14059: ' - '.&mt('modifiable fields (if institutional data blank): ');
14060: foreach my $field (@fields) {
14061: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
14062: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 14063: }
14064: }
1.224 raeburn 14065: if (@modifiable > 0) {
14066: $resulttext .= join(', ',@modifiable);
1.43 raeburn 14067: } else {
1.224 raeburn 14068: $resulttext .= &mt('none');
1.43 raeburn 14069: }
1.224 raeburn 14070: $resulttext .= '</li>';
1.28 raeburn 14071: }
1.224 raeburn 14072: $resulttext .= '</ul></li>';
1.28 raeburn 14073: }
1.27 raeburn 14074: $resulttext .= '</ul>';
1.305 raeburn 14075: my $cachetime = 24*60*60;
14076: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
14077: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14078: if (ref($lastactref) eq 'HASH') {
14079: $lastactref->{'domdefaults'} = 1;
14080: }
1.27 raeburn 14081: } else {
1.224 raeburn 14082: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 14083: }
14084: } else {
14085: $resulttext = '<span class="LC_error">'.
1.23 raeburn 14086: &mt('An error occurred: [_1]',$putresult).'</span>';
14087: }
1.43 raeburn 14088: if ($warningmsg ne '') {
14089: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
14090: }
1.23 raeburn 14091: return $resulttext;
14092: }
14093:
1.165 raeburn 14094: sub process_captcha {
14095: my ($container,$changes,$newsettings,$current) = @_;
14096: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
14097: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
14098: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
14099: $newsettings->{'captcha'} = 'original';
14100: }
14101: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 14102: if ($container eq 'cancreate') {
1.169 raeburn 14103: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14104: push(@{$changes->{'cancreate'}},'captcha');
14105: } elsif (!defined($changes->{'cancreate'})) {
14106: $changes->{'cancreate'} = ['captcha'];
14107: }
14108: } else {
14109: $changes->{'captcha'} = 1;
1.165 raeburn 14110: }
14111: }
1.269 raeburn 14112: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 14113: if ($newsettings->{'captcha'} eq 'recaptcha') {
14114: $newpub = $env{'form.'.$container.'_recaptchapub'};
14115: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 14116: $newpub =~ s/[^\w\-]//g;
14117: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 14118: $newsettings->{'recaptchakeys'} = {
14119: public => $newpub,
14120: private => $newpriv,
14121: };
1.269 raeburn 14122: $newversion = $env{'form.'.$container.'_recaptchaversion'};
14123: $newversion =~ s/\D//g;
14124: if ($newversion ne '2') {
14125: $newversion = 1;
14126: }
14127: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 14128: }
14129: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
14130: $currpub = $current->{'recaptchakeys'}{'public'};
14131: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 14132: unless ($newsettings->{'captcha'} eq 'recaptcha') {
14133: $newsettings->{'recaptchakeys'} = {
14134: public => '',
14135: private => '',
14136: }
14137: }
1.165 raeburn 14138: }
1.269 raeburn 14139: if ($current->{'captcha'} eq 'recaptcha') {
14140: $currversion = $current->{'recaptchaversion'};
14141: if ($currversion ne '2') {
14142: $currversion = 1;
14143: }
14144: }
14145: if ($currversion ne $newversion) {
14146: if ($container eq 'cancreate') {
14147: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14148: push(@{$changes->{'cancreate'}},'recaptchaversion');
14149: } elsif (!defined($changes->{'cancreate'})) {
14150: $changes->{'cancreate'} = ['recaptchaversion'];
14151: }
14152: } else {
14153: $changes->{'recaptchaversion'} = 1;
14154: }
14155: }
1.165 raeburn 14156: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 14157: if ($container eq 'cancreate') {
14158: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14159: push(@{$changes->{'cancreate'}},'recaptchakeys');
14160: } elsif (!defined($changes->{'cancreate'})) {
14161: $changes->{'cancreate'} = ['recaptchakeys'];
14162: }
14163: } else {
1.210 raeburn 14164: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 14165: }
14166: }
14167: return;
14168: }
14169:
1.33 raeburn 14170: sub modify_usermodification {
14171: my ($dom,%domconfig) = @_;
1.224 raeburn 14172: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 14173: if (ref($domconfig{'usermodification'}) eq 'HASH') {
14174: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 14175: if ($key eq 'selfcreate') {
14176: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
14177: } else {
14178: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
14179: }
1.33 raeburn 14180: }
14181: }
1.224 raeburn 14182: my @contexts = ('author','course');
1.33 raeburn 14183: my %context_title = (
14184: author => 'In author context',
14185: course => 'In course context',
14186: );
14187: my @fields = ('lastname','firstname','middlename','generation',
14188: 'permanentemail','id');
14189: my %roles = (
14190: author => ['ca','aa'],
14191: course => ['st','ep','ta','in','cr'],
14192: );
14193: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14194: foreach my $context (@contexts) {
14195: foreach my $role (@{$roles{$context}}) {
14196: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
14197: foreach my $item (@fields) {
14198: if (grep(/^\Q$item\E$/,@modifiable)) {
14199: $modifyhash{$context}{$role}{$item} = 1;
14200: } else {
14201: $modifyhash{$context}{$role}{$item} = 0;
14202: }
14203: }
14204: }
14205: if (ref($curr_usermodification{$context}) eq 'HASH') {
14206: foreach my $role (@{$roles{$context}}) {
14207: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
14208: foreach my $field (@fields) {
14209: if ($modifyhash{$context}{$role}{$field} ne
14210: $curr_usermodification{$context}{$role}{$field}) {
14211: push(@{$changes{$context}},$role);
14212: last;
14213: }
14214: }
14215: }
14216: }
14217: } else {
14218: foreach my $context (@contexts) {
14219: foreach my $role (@{$roles{$context}}) {
14220: push(@{$changes{$context}},$role);
14221: }
14222: }
14223: }
14224: }
14225: my %usermodification_hash = (
14226: usermodification => \%modifyhash,
14227: );
14228: my $putresult = &Apache::lonnet::put_dom('configuration',
14229: \%usermodification_hash,$dom);
14230: if ($putresult eq 'ok') {
14231: if (keys(%changes) > 0) {
14232: $resulttext = &mt('Changes made: ').'<ul>';
14233: foreach my $context (@contexts) {
14234: if (ref($changes{$context}) eq 'ARRAY') {
14235: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
14236: if (ref($changes{$context}) eq 'ARRAY') {
14237: foreach my $role (@{$changes{$context}}) {
14238: my $rolename;
1.224 raeburn 14239: if ($role eq 'cr') {
14240: $rolename = &mt('Custom');
1.33 raeburn 14241: } else {
1.224 raeburn 14242: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 14243: }
14244: my @modifiable;
1.224 raeburn 14245: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 14246: foreach my $field (@fields) {
14247: if ($modifyhash{$context}{$role}{$field}) {
14248: push(@modifiable,$fieldtitles{$field});
14249: }
14250: }
14251: if (@modifiable > 0) {
14252: $resulttext .= join(', ',@modifiable);
14253: } else {
14254: $resulttext .= &mt('none');
14255: }
14256: $resulttext .= '</li>';
14257: }
14258: $resulttext .= '</ul></li>';
14259: }
14260: }
14261: }
14262: $resulttext .= '</ul>';
14263: } else {
14264: $resulttext = &mt('No changes made to user modification settings');
14265: }
14266: } else {
14267: $resulttext = '<span class="LC_error">'.
14268: &mt('An error occurred: [_1]',$putresult).'</span>';
14269: }
14270: return $resulttext;
14271: }
14272:
1.43 raeburn 14273: sub modify_defaults {
1.212 raeburn 14274: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 14275: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 14276: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 14277: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
14278: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.325 raeburn 14279: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 14280: foreach my $item (@items) {
14281: $newvalues{$item} = $env{'form.'.$item};
14282: if ($item eq 'auth_def') {
14283: if ($newvalues{$item} ne '') {
14284: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
14285: push(@errors,$item);
14286: }
14287: }
14288: } elsif ($item eq 'lang_def') {
14289: if ($newvalues{$item} ne '') {
14290: if ($newvalues{$item} =~ /^(\w+)/) {
14291: my $langcode = $1;
1.103 raeburn 14292: if ($langcode ne 'x_chef') {
14293: if (code2language($langcode) eq '') {
14294: push(@errors,$item);
14295: }
1.43 raeburn 14296: }
14297: } else {
14298: push(@errors,$item);
14299: }
14300: }
1.54 raeburn 14301: } elsif ($item eq 'timezone_def') {
14302: if ($newvalues{$item} ne '') {
1.62 raeburn 14303: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 14304: push(@errors,$item);
14305: }
14306: }
1.68 raeburn 14307: } elsif ($item eq 'datelocale_def') {
14308: if ($newvalues{$item} ne '') {
14309: my @datelocale_ids = DateTime::Locale->ids();
14310: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
14311: push(@errors,$item);
14312: }
14313: }
1.141 raeburn 14314: } elsif ($item eq 'portal_def') {
14315: if ($newvalues{$item} ne '') {
14316: 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])\/?$/) {
14317: push(@errors,$item);
14318: }
14319: }
1.294 raeburn 14320: } elsif ($item eq 'intauth_cost') {
14321: if ($newvalues{$item} ne '') {
14322: if ($newvalues{$item} =~ /\D/) {
14323: push(@errors,$item);
14324: }
14325: }
14326: } elsif ($item eq 'intauth_check') {
14327: if ($newvalues{$item} ne '') {
14328: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
14329: push(@errors,$item);
14330: }
14331: }
14332: } elsif ($item eq 'intauth_switch') {
14333: if ($newvalues{$item} ne '') {
14334: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
14335: push(@errors,$item);
14336: }
14337: }
1.43 raeburn 14338: }
14339: if (grep(/^\Q$item\E$/,@errors)) {
14340: $newvalues{$item} = $domdefaults{$item};
14341: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
14342: $changes{$item} = 1;
14343: }
1.72 raeburn 14344: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 14345: }
14346: my %defaults_hash = (
1.72 raeburn 14347: defaults => \%newvalues,
14348: );
1.43 raeburn 14349: my $title = &defaults_titles();
1.236 raeburn 14350:
14351: my $currinststatus;
14352: if (ref($domconfig{'inststatus'}) eq 'HASH') {
14353: $currinststatus = $domconfig{'inststatus'};
14354: } else {
14355: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
14356: $currinststatus = {
14357: inststatustypes => $usertypes,
14358: inststatusorder => $types,
14359: inststatusguest => [],
14360: };
14361: }
14362: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
14363: my @allpos;
14364: my %alltypes;
1.305 raeburn 14365: my @inststatusguest;
14366: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
14367: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
14368: unless (grep(/^\Q$type\E$/,@todelete)) {
14369: push(@inststatusguest,$type);
14370: }
14371: }
14372: }
14373: my ($currtitles,$currorder);
1.236 raeburn 14374: if (ref($currinststatus) eq 'HASH') {
14375: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
14376: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
14377: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
14378: if ($currinststatus->{inststatustypes}->{$type} ne '') {
14379: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
14380: }
14381: }
14382: unless (grep(/^\Q$type\E$/,@todelete)) {
14383: my $position = $env{'form.inststatus_pos_'.$type};
14384: $position =~ s/\D+//g;
14385: $allpos[$position] = $type;
14386: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
14387: $alltypes{$type} =~ s/`//g;
14388: }
14389: }
14390: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
14391: $currtitles =~ s/,$//;
14392: }
14393: }
14394: if ($env{'form.addinststatus'}) {
14395: my $newtype = $env{'form.addinststatus'};
14396: $newtype =~ s/\W//g;
14397: unless (exists($alltypes{$newtype})) {
14398: $alltypes{$newtype} = $env{'form.addinststatus_title'};
14399: $alltypes{$newtype} =~ s/`//g;
14400: my $position = $env{'form.addinststatus_pos'};
14401: $position =~ s/\D+//g;
14402: if ($position ne '') {
14403: $allpos[$position] = $newtype;
14404: }
14405: }
14406: }
1.305 raeburn 14407: my @orderedstatus;
1.236 raeburn 14408: foreach my $type (@allpos) {
14409: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
14410: push(@orderedstatus,$type);
14411: }
14412: }
14413: foreach my $type (keys(%alltypes)) {
14414: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
14415: delete($alltypes{$type});
14416: }
14417: }
14418: $defaults_hash{'inststatus'} = {
14419: inststatustypes => \%alltypes,
14420: inststatusorder => \@orderedstatus,
1.305 raeburn 14421: inststatusguest => \@inststatusguest,
1.236 raeburn 14422: };
14423: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
14424: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
14425: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
14426: }
14427: }
14428: if ($currorder ne join(',',@orderedstatus)) {
14429: $changes{'inststatus'}{'inststatusorder'} = 1;
14430: }
14431: my $newtitles;
14432: foreach my $item (@orderedstatus) {
14433: $newtitles .= $alltypes{$item}.',';
14434: }
14435: $newtitles =~ s/,$//;
14436: if ($currtitles ne $newtitles) {
14437: $changes{'inststatus'}{'inststatustypes'} = 1;
14438: }
1.43 raeburn 14439: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
14440: $dom);
14441: if ($putresult eq 'ok') {
14442: if (keys(%changes) > 0) {
14443: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 14444: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 14445: 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";
14446: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 14447: if ($item eq 'inststatus') {
14448: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 14449: if (@orderedstatus) {
1.236 raeburn 14450: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
14451: foreach my $type (@orderedstatus) {
14452: $resulttext .= $alltypes{$type}.', ';
14453: }
14454: $resulttext =~ s/, $//;
14455: $resulttext .= '</li>';
1.305 raeburn 14456: } else {
14457: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 14458: }
14459: }
14460: } else {
14461: my $value = $env{'form.'.$item};
14462: if ($value eq '') {
14463: $value = &mt('none');
14464: } elsif ($item eq 'auth_def') {
14465: my %authnames = &authtype_names();
14466: my %shortauth = (
14467: internal => 'int',
14468: krb4 => 'krb4',
14469: krb5 => 'krb5',
14470: localauth => 'loc',
1.325 raeburn 14471: lti => 'lti',
1.236 raeburn 14472: );
14473: $value = $authnames{$shortauth{$value}};
1.294 raeburn 14474: } elsif ($item eq 'intauth_switch') {
14475: my %optiondesc = &Apache::lonlocal::texthash (
14476: 0 => 'No',
14477: 1 => 'Yes',
14478: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
14479: );
14480: if ($value =~ /^(0|1|2)$/) {
14481: $value = $optiondesc{$value};
14482: } else {
14483: $value = &mt('none -- defaults to No');
14484: }
14485: } elsif ($item eq 'intauth_check') {
14486: my %optiondesc = &Apache::lonlocal::texthash (
14487: 0 => 'No',
14488: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
14489: 2 => 'Yes, disallow login if stored cost is less than domain default',
14490: );
14491: if ($value =~ /^(0|1|2)$/) {
14492: $value = $optiondesc{$value};
14493: } else {
14494: $value = &mt('none -- defaults to No');
14495: }
1.236 raeburn 14496: }
14497: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
14498: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 14499: }
14500: }
14501: $resulttext .= '</ul>';
14502: $mailmsgtext .= "\n";
14503: my $cachetime = 24*60*60;
1.72 raeburn 14504: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 14505: if (ref($lastactref) eq 'HASH') {
14506: $lastactref->{'domdefaults'} = 1;
14507: }
1.68 raeburn 14508: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 14509: my $notify = 1;
14510: if (ref($domconfig{'contacts'}) eq 'HASH') {
14511: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
14512: $notify = 0;
14513: }
14514: }
14515: if ($notify) {
14516: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
14517: "LON-CAPA Domain Settings Change - $dom",
14518: $mailmsgtext);
14519: }
1.54 raeburn 14520: }
1.43 raeburn 14521: } else {
1.54 raeburn 14522: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 14523: }
14524: } else {
14525: $resulttext = '<span class="LC_error">'.
14526: &mt('An error occurred: [_1]',$putresult).'</span>';
14527: }
14528: if (@errors > 0) {
14529: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
14530: foreach my $item (@errors) {
14531: $resulttext .= ' "'.$title->{$item}.'",';
14532: }
14533: $resulttext =~ s/,$//;
14534: }
14535: return $resulttext;
14536: }
14537:
1.46 raeburn 14538: sub modify_scantron {
1.205 raeburn 14539: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 14540: my ($resulttext,%confhash,%changes,$errors);
14541: my $custom = 'custom.tab';
14542: my $default = 'default.tab';
14543: my $servadm = $r->dir_config('lonAdmEMail');
14544: my ($configuserok,$author_ok,$switchserver) =
14545: &config_check($dom,$confname,$servadm);
14546: if ($env{'form.scantronformat.filename'} ne '') {
14547: my $error;
14548: if ($configuserok eq 'ok') {
14549: if ($switchserver) {
1.130 raeburn 14550: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 14551: } else {
14552: if ($author_ok eq 'ok') {
14553: my ($result,$scantronurl) =
14554: &publishlogo($r,'upload','scantronformat',$dom,
14555: $confname,'scantron','','',$custom);
14556: if ($result eq 'ok') {
14557: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 14558: $changes{'scantronformat'} = 1;
1.46 raeburn 14559: } else {
14560: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
14561: }
14562: } else {
14563: $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);
14564: }
14565: }
14566: } else {
14567: $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);
14568: }
14569: if ($error) {
14570: &Apache::lonnet::logthis($error);
14571: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14572: }
14573: }
1.48 raeburn 14574: if (ref($domconfig{'scantron'}) eq 'HASH') {
14575: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
14576: if ($env{'form.scantronformat_del'}) {
14577: $confhash{'scantron'}{'scantronformat'} = '';
14578: $changes{'scantronformat'} = 1;
1.46 raeburn 14579: }
14580: }
14581: }
14582: if (keys(%confhash) > 0) {
14583: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
14584: $dom);
14585: if ($putresult eq 'ok') {
14586: if (keys(%changes) > 0) {
1.48 raeburn 14587: if (ref($confhash{'scantron'}) eq 'HASH') {
14588: $resulttext = &mt('Changes made:').'<ul>';
14589: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 14590: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 14591: } else {
1.130 raeburn 14592: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 14593: }
1.48 raeburn 14594: $resulttext .= '</ul>';
14595: } else {
1.130 raeburn 14596: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 14597: }
14598: $resulttext .= '</ul>';
14599: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 14600: if (ref($lastactref) eq 'HASH') {
14601: $lastactref->{'domainconfig'} = 1;
14602: }
1.46 raeburn 14603: } else {
1.130 raeburn 14604: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 14605: }
14606: } else {
14607: $resulttext = '<span class="LC_error">'.
14608: &mt('An error occurred: [_1]',$putresult).'</span>';
14609: }
14610: } else {
1.130 raeburn 14611: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 14612: }
14613: if ($errors) {
14614: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14615: $errors.'</ul>';
14616: }
14617: return $resulttext;
14618: }
14619:
1.48 raeburn 14620: sub modify_coursecategories {
1.239 raeburn 14621: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 14622: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
14623: $cathash);
1.48 raeburn 14624: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 14625: my @catitems = ('unauth','auth');
14626: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 14627: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 14628: $cathash = $domconfig{'coursecategories'}{'cats'};
14629: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
14630: $changes{'togglecats'} = 1;
14631: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
14632: }
14633: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
14634: $changes{'categorize'} = 1;
14635: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
14636: }
1.120 raeburn 14637: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
14638: $changes{'togglecatscomm'} = 1;
14639: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
14640: }
14641: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
14642: $changes{'categorizecomm'} = 1;
14643: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 14644:
14645: }
14646: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
14647: $changes{'togglecatsplace'} = 1;
14648: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
14649: }
14650: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
14651: $changes{'categorizeplace'} = 1;
14652: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 14653: }
1.238 raeburn 14654: foreach my $item (@catitems) {
14655: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
14656: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
14657: $changes{$item} = 1;
14658: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
14659: }
14660: }
14661: }
1.57 raeburn 14662: } else {
14663: $changes{'togglecats'} = 1;
14664: $changes{'categorize'} = 1;
1.124 raeburn 14665: $changes{'togglecatscomm'} = 1;
14666: $changes{'categorizecomm'} = 1;
1.272 raeburn 14667: $changes{'togglecatsplace'} = 1;
14668: $changes{'categorizeplace'} = 1;
1.87 raeburn 14669: $domconfig{'coursecategories'} = {
14670: togglecats => $env{'form.togglecats'},
14671: categorize => $env{'form.categorize'},
1.124 raeburn 14672: togglecatscomm => $env{'form.togglecatscomm'},
14673: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 14674: togglecatsplace => $env{'form.togglecatsplace'},
14675: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 14676: };
1.238 raeburn 14677: foreach my $item (@catitems) {
14678: if ($env{'form.coursecat_'.$item} ne 'std') {
14679: $changes{$item} = 1;
14680: }
14681: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
14682: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
14683: }
14684: }
1.57 raeburn 14685: }
14686: if (ref($cathash) eq 'HASH') {
14687: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 14688: push (@deletecategory,'instcode::0');
14689: }
1.120 raeburn 14690: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
14691: push(@deletecategory,'communities::0');
14692: }
1.272 raeburn 14693: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
14694: push(@deletecategory,'placement::0');
14695: }
1.48 raeburn 14696: }
1.57 raeburn 14697: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
14698: if (ref($cathash) eq 'HASH') {
1.48 raeburn 14699: if (@deletecategory > 0) {
14700: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 14701: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 14702: foreach my $item (@deletecategory) {
1.57 raeburn 14703: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
14704: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 14705: $deletions{$item} = 1;
1.57 raeburn 14706: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 14707: }
14708: }
14709: }
1.57 raeburn 14710: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 14711: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 14712: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 14713: $reorderings{$item} = 1;
1.57 raeburn 14714: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 14715: }
14716: if ($env{'form.addcategory_name_'.$item} ne '') {
14717: my $newcat = $env{'form.addcategory_name_'.$item};
14718: my $newdepth = $depth+1;
14719: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 14720: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 14721: $adds{$newitem} = 1;
14722: }
14723: if ($env{'form.subcat_'.$item} ne '') {
14724: my $newcat = $env{'form.subcat_'.$item};
14725: my $newdepth = $depth+1;
14726: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 14727: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 14728: $adds{$newitem} = 1;
14729: }
14730: }
14731: }
14732: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 14733: if (ref($cathash) eq 'HASH') {
1.48 raeburn 14734: my $newitem = 'instcode::0';
1.57 raeburn 14735: if ($cathash->{$newitem} eq '') {
14736: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 14737: $adds{$newitem} = 1;
14738: }
14739: } else {
14740: my $newitem = 'instcode::0';
1.57 raeburn 14741: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 14742: $adds{$newitem} = 1;
14743: }
14744: }
1.120 raeburn 14745: if ($env{'form.communities'} eq '1') {
14746: if (ref($cathash) eq 'HASH') {
14747: my $newitem = 'communities::0';
14748: if ($cathash->{$newitem} eq '') {
14749: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
14750: $adds{$newitem} = 1;
14751: }
14752: } else {
14753: my $newitem = 'communities::0';
14754: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
14755: $adds{$newitem} = 1;
14756: }
14757: }
1.272 raeburn 14758: if ($env{'form.placement'} eq '1') {
14759: if (ref($cathash) eq 'HASH') {
14760: my $newitem = 'placement::0';
14761: if ($cathash->{$newitem} eq '') {
14762: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
14763: $adds{$newitem} = 1;
14764: }
14765: } else {
14766: my $newitem = 'placement::0';
14767: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
14768: $adds{$newitem} = 1;
14769: }
14770: }
1.48 raeburn 14771: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 14772: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 14773: ($env{'form.addcategory_name'} ne 'communities') &&
14774: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 14775: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
14776: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
14777: $adds{$newitem} = 1;
14778: }
1.48 raeburn 14779: }
1.57 raeburn 14780: my $putresult;
1.48 raeburn 14781: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14782: if (keys(%deletions) > 0) {
14783: foreach my $key (keys(%deletions)) {
14784: if ($predelallitems{$key} ne '') {
14785: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
14786: }
14787: }
14788: }
14789: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 14790: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 14791: if (ref($chkcats[0]) eq 'ARRAY') {
14792: my $depth = 0;
14793: my $chg = 0;
14794: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
14795: my $name = $chkcats[0][$i];
14796: my $item;
14797: if ($name eq '') {
14798: $chg ++;
14799: } else {
14800: $item = &escape($name).'::0';
14801: if ($chg) {
1.57 raeburn 14802: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 14803: }
14804: $depth ++;
1.57 raeburn 14805: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 14806: $depth --;
14807: }
14808: }
14809: }
1.57 raeburn 14810: }
14811: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14812: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 14813: if ($putresult eq 'ok') {
1.57 raeburn 14814: my %title = (
1.120 raeburn 14815: togglecats => 'Show/Hide a course in catalog',
14816: categorize => 'Assign a category to a course',
14817: togglecatscomm => 'Show/Hide a community in catalog',
14818: categorizecomm => 'Assign a category to a community',
1.57 raeburn 14819: );
14820: my %level = (
1.120 raeburn 14821: dom => 'set in Domain ("Modify Course/Community")',
14822: crs => 'set in Course ("Course Configuration")',
14823: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 14824: none => 'No catalog',
14825: std => 'Standard catalog',
14826: domonly => 'Domain-only catalog',
14827: codesrch => 'Code search form',
1.57 raeburn 14828: );
1.48 raeburn 14829: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 14830: if ($changes{'togglecats'}) {
14831: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
14832: }
14833: if ($changes{'categorize'}) {
14834: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 14835: }
1.120 raeburn 14836: if ($changes{'togglecatscomm'}) {
14837: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
14838: }
14839: if ($changes{'categorizecomm'}) {
14840: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
14841: }
1.238 raeburn 14842: if ($changes{'unauth'}) {
14843: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
14844: }
14845: if ($changes{'auth'}) {
14846: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
14847: }
1.57 raeburn 14848: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14849: my $cathash;
14850: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
14851: $cathash = $domconfig{'coursecategories'}{'cats'};
14852: } else {
14853: $cathash = {};
14854: }
14855: my (@cats,@trails,%allitems);
14856: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
14857: if (keys(%deletions) > 0) {
14858: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
14859: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
14860: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
14861: }
14862: $resulttext .= '</ul></li>';
14863: }
14864: if (keys(%reorderings) > 0) {
14865: my %sort_by_trail;
14866: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
14867: foreach my $key (keys(%reorderings)) {
14868: if ($allitems{$key} ne '') {
14869: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
14870: }
1.48 raeburn 14871: }
1.57 raeburn 14872: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
14873: $resulttext .= '<li>'.$trails[$trail].'</li>';
14874: }
14875: $resulttext .= '</ul></li>';
1.48 raeburn 14876: }
1.57 raeburn 14877: if (keys(%adds) > 0) {
14878: my %sort_by_trail;
14879: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
14880: foreach my $key (keys(%adds)) {
14881: if ($allitems{$key} ne '') {
14882: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
14883: }
14884: }
14885: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
14886: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 14887: }
1.57 raeburn 14888: $resulttext .= '</ul></li>';
1.48 raeburn 14889: }
14890: }
14891: $resulttext .= '</ul>';
1.239 raeburn 14892: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 14893: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
14894: if ($changes{'auth'}) {
14895: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
14896: }
14897: if ($changes{'unauth'}) {
14898: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
14899: }
14900: my $cachetime = 24*60*60;
14901: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 14902: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 14903: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 14904: }
14905: }
1.48 raeburn 14906: } else {
14907: $resulttext = '<span class="LC_error">'.
1.57 raeburn 14908: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 14909: }
14910: } else {
1.120 raeburn 14911: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 14912: }
14913: return $resulttext;
14914: }
14915:
1.69 raeburn 14916: sub modify_serverstatuses {
14917: my ($dom,%domconfig) = @_;
14918: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
14919: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
14920: %currserverstatus = %{$domconfig{'serverstatuses'}};
14921: }
14922: my @pages = &serverstatus_pages();
14923: foreach my $type (@pages) {
14924: $newserverstatus{$type}{'namedusers'} = '';
14925: $newserverstatus{$type}{'machines'} = '';
14926: if (defined($env{'form.'.$type.'_namedusers'})) {
14927: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
14928: my @okusers;
14929: foreach my $user (@users) {
14930: my ($uname,$udom) = split(/:/,$user);
14931: if (($udom =~ /^$match_domain$/) &&
14932: (&Apache::lonnet::domain($udom)) &&
14933: ($uname =~ /^$match_username$/)) {
14934: if (!grep(/^\Q$user\E/,@okusers)) {
14935: push(@okusers,$user);
14936: }
14937: }
14938: }
14939: if (@okusers > 0) {
14940: @okusers = sort(@okusers);
14941: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
14942: }
14943: }
14944: if (defined($env{'form.'.$type.'_machines'})) {
14945: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
14946: my @okmachines;
14947: foreach my $ip (@machines) {
14948: my @parts = split(/\./,$ip);
14949: next if (@parts < 4);
14950: my $badip = 0;
14951: for (my $i=0; $i<4; $i++) {
14952: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
14953: $badip = 1;
14954: last;
14955: }
14956: }
14957: if (!$badip) {
14958: push(@okmachines,$ip);
14959: }
14960: }
14961: @okmachines = sort(@okmachines);
14962: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
14963: }
14964: }
14965: my %serverstatushash = (
14966: serverstatuses => \%newserverstatus,
14967: );
14968: foreach my $type (@pages) {
1.83 raeburn 14969: foreach my $setting ('namedusers','machines') {
1.84 raeburn 14970: my (@current,@new);
1.83 raeburn 14971: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 14972: if ($currserverstatus{$type}{$setting} ne '') {
14973: @current = split(/,/,$currserverstatus{$type}{$setting});
14974: }
14975: }
14976: if ($newserverstatus{$type}{$setting} ne '') {
14977: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 14978: }
14979: if (@current > 0) {
14980: if (@new > 0) {
14981: foreach my $item (@current) {
14982: if (!grep(/^\Q$item\E$/,@new)) {
14983: $changes{$type}{$setting} = 1;
1.82 raeburn 14984: last;
14985: }
14986: }
1.84 raeburn 14987: foreach my $item (@new) {
14988: if (!grep(/^\Q$item\E$/,@current)) {
14989: $changes{$type}{$setting} = 1;
14990: last;
1.82 raeburn 14991: }
14992: }
14993: } else {
1.83 raeburn 14994: $changes{$type}{$setting} = 1;
1.69 raeburn 14995: }
1.83 raeburn 14996: } elsif (@new > 0) {
14997: $changes{$type}{$setting} = 1;
1.69 raeburn 14998: }
14999: }
15000: }
15001: if (keys(%changes) > 0) {
1.81 raeburn 15002: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 15003: my $putresult = &Apache::lonnet::put_dom('configuration',
15004: \%serverstatushash,$dom);
15005: if ($putresult eq 'ok') {
15006: $resulttext .= &mt('Changes made:').'<ul>';
15007: foreach my $type (@pages) {
1.84 raeburn 15008: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 15009: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 15010: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 15011: if ($newserverstatus{$type}{'namedusers'} eq '') {
15012: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
15013: } else {
15014: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
15015: }
1.84 raeburn 15016: }
15017: if ($changes{$type}{'machines'}) {
1.69 raeburn 15018: if ($newserverstatus{$type}{'machines'} eq '') {
15019: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
15020: } else {
15021: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
15022: }
15023:
15024: }
15025: $resulttext .= '</ul></li>';
15026: }
15027: }
15028: $resulttext .= '</ul>';
15029: } else {
15030: $resulttext = '<span class="LC_error">'.
15031: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
15032:
15033: }
15034: } else {
15035: $resulttext = &mt('No changes made to access to server status pages');
15036: }
15037: return $resulttext;
15038: }
15039:
1.118 jms 15040: sub modify_helpsettings {
1.285 raeburn 15041: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 15042: my ($resulttext,$errors,%changes,%helphash);
15043: my %defaultchecked = ('submitbugs' => 'on');
15044: my @offon = ('off','on');
1.118 jms 15045: my @toggles = ('submitbugs');
1.285 raeburn 15046: my %current = ('submitbugs' => '',
15047: 'adhoc' => {},
15048: );
1.118 jms 15049: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 15050: %current = %{$domconfig{'helpsettings'}};
15051: }
1.285 raeburn 15052: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 15053: foreach my $item (@toggles) {
15054: if ($defaultchecked{$item} eq 'on') {
15055: if ($current{$item} eq '') {
15056: if ($env{'form.'.$item} eq '0') {
15057: $changes{$item} = 1;
15058: }
15059: } elsif ($current{$item} ne $env{'form.'.$item}) {
15060: $changes{$item} = 1;
15061: }
15062: } elsif ($defaultchecked{$item} eq 'off') {
15063: if ($current{$item} eq '') {
15064: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 15065: $changes{$item} = 1;
15066: }
1.282 raeburn 15067: } elsif ($current{$item} ne $env{'form.'.$item}) {
15068: $changes{$item} = 1;
15069: }
15070: }
15071: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
15072: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
15073: }
15074: }
1.285 raeburn 15075: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 15076: my $confname = $dom.'-domainconfig';
15077: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 15078: my (@allpos,%newsettings,%changedprivs,$newrole);
15079: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 15080: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 15081: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 15082: my %lt = &Apache::lonlocal::texthash(
15083: s => 'system',
15084: d => 'domain',
15085: order => 'Display order',
15086: access => 'Role usage',
1.291 raeburn 15087: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 15088: dh => 'All with domain helpdesk role',
15089: da => 'All with domain helpdesk assistant role',
1.285 raeburn 15090: none => 'None',
15091: status => 'Determined based on institutional status',
15092: inc => 'Include all, but exclude specific personnel',
15093: exc => 'Exclude all, but include specific personnel',
15094: );
15095: for (my $num=0; $num<=$maxnum; $num++) {
15096: my ($prefix,$identifier,$rolename,%curr);
15097: if ($num == $maxnum) {
15098: next unless ($env{'form.newcusthelp'} == $maxnum);
15099: $identifier = 'custhelp'.$num;
15100: $prefix = 'helproles_'.$num;
15101: $rolename = $env{'form.custhelpname'.$num};
15102: $rolename=~s/[^A-Za-z0-9]//gs;
15103: next if ($rolename eq '');
15104: next if (exists($existing{'rolesdef_'.$rolename}));
15105: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15106: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15107: $newprivs{'c'},$confname,$dom);
15108: if ($result ne 'ok') {
15109: $errors .= '<li><span class="LC_error">'.
15110: &mt('An error occurred storing the new custom role: [_1]',
15111: $result).'</span></li>';
15112: next;
15113: } else {
15114: $changedprivs{$rolename} = \%newprivs;
15115: $newrole = $rolename;
15116: }
15117: } else {
15118: $prefix = 'helproles_'.$num;
15119: $rolename = $env{'form.'.$prefix};
15120: next if ($rolename eq '');
15121: next unless (exists($existing{'rolesdef_'.$rolename}));
15122: $identifier = 'custhelp'.$num;
15123: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15124: my %currprivs;
1.289 raeburn 15125: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 15126: split(/\_/,$existing{'rolesdef_'.$rolename});
15127: foreach my $level ('c','d','s') {
15128: if ($newprivs{$level} ne $currprivs{$level}) {
15129: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15130: $newprivs{'c'},$confname,$dom);
15131: if ($result ne 'ok') {
15132: $errors .= '<li><span class="LC_error">'.
15133: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
15134: $rolename,$result).'</span></li>';
15135: } else {
15136: $changedprivs{$rolename} = \%newprivs;
15137: }
15138: last;
15139: }
15140: }
15141: if (ref($current{'adhoc'}) eq 'HASH') {
15142: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15143: %curr = %{$current{'adhoc'}{$rolename}};
15144: }
15145: }
15146: }
15147: my $newpos = $env{'form.'.$prefix.'_pos'};
15148: $newpos =~ s/\D+//g;
15149: $allpos[$newpos] = $rolename;
15150: my $newdesc = $env{'form.'.$prefix.'_desc'};
15151: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
15152: if ($curr{'desc'}) {
15153: if ($curr{'desc'} ne $newdesc) {
15154: $changes{'customrole'}{$rolename}{'desc'} = 1;
15155: $newsettings{$rolename}{'desc'} = $newdesc;
15156: }
15157: } elsif ($newdesc ne '') {
15158: $changes{'customrole'}{$rolename}{'desc'} = 1;
15159: $newsettings{$rolename}{'desc'} = $newdesc;
15160: }
15161: my $access = $env{'form.'.$prefix.'_access'};
15162: if (grep(/^\Q$access\E$/,@accesstypes)) {
15163: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
15164: if ($access eq 'status') {
15165: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
15166: if (scalar(@statuses) == 0) {
1.289 raeburn 15167: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 15168: } else {
15169: my (@shownstatus,$numtypes);
15170: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15171: if (ref($types) eq 'ARRAY') {
15172: $numtypes = scalar(@{$types});
15173: foreach my $type (sort(@statuses)) {
15174: if ($type eq 'default') {
15175: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15176: } elsif (grep(/^\Q$type\E$/,@{$types})) {
15177: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15178: push(@shownstatus,$usertypes->{$type});
15179: }
15180: }
15181: }
15182: if (grep(/^default$/,@statuses)) {
15183: push(@shownstatus,$othertitle);
15184: }
15185: if (scalar(@shownstatus) == 1+$numtypes) {
15186: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
15187: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
15188: } else {
15189: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
15190: if (ref($curr{'status'}) eq 'ARRAY') {
15191: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15192: if (@diffs) {
15193: $changes{'customrole'}{$rolename}{$access} = 1;
15194: }
15195: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15196: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 15197: }
1.166 raeburn 15198: }
15199: }
1.285 raeburn 15200: } elsif (($access eq 'inc') || ($access eq 'exc')) {
15201: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
15202: my @newspecstaff;
15203: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15204: foreach my $person (sort(@personnel)) {
15205: if ($domhelpdesk{$person}) {
15206: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
15207: }
15208: }
15209: if (ref($curr{$access}) eq 'ARRAY') {
15210: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15211: if (@diffs) {
15212: $changes{'customrole'}{$rolename}{$access} = 1;
15213: }
15214: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15215: $changes{'customrole'}{$rolename}{$access} = 1;
15216: }
15217: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15218: my ($uname,$udom) = split(/:/,$person);
15219: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
15220: }
15221: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 15222: }
1.285 raeburn 15223: } else {
15224: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
15225: }
15226: unless ($curr{'access'} eq $access) {
15227: $changes{'customrole'}{$rolename}{'access'} = 1;
15228: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 15229: }
15230: }
1.285 raeburn 15231: if (@allpos > 0) {
15232: my $idx = 0;
15233: foreach my $rolename (@allpos) {
15234: if ($rolename ne '') {
15235: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
15236: if (ref($current{'adhoc'}) eq 'HASH') {
15237: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15238: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
15239: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 15240: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 15241: }
15242: }
1.282 raeburn 15243: }
1.285 raeburn 15244: $idx ++;
1.166 raeburn 15245: }
15246: }
1.118 jms 15247: }
1.123 jms 15248: my $putresult;
15249: if (keys(%changes) > 0) {
1.166 raeburn 15250: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 15251: if ($putresult eq 'ok') {
1.285 raeburn 15252: if (ref($helphash{'helpsettings'}) eq 'HASH') {
15253: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
15254: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
15255: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
15256: }
15257: }
15258: my $cachetime = 24*60*60;
15259: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15260: if (ref($lastactref) eq 'HASH') {
15261: $lastactref->{'domdefaults'} = 1;
15262: }
15263: } else {
15264: $errors .= '<li><span class="LC_error">'.
15265: &mt('An error occurred storing the settings: [_1]',
15266: $putresult).'</span></li>';
15267: }
15268: }
15269: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
15270: $resulttext = &mt('Changes made:').'<ul>';
15271: my (%shownprivs,@levelorder);
15272: @levelorder = ('c','d','s');
15273: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 15274: foreach my $item (sort(keys(%changes))) {
15275: if ($item eq 'submitbugs') {
15276: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
15277: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
15278: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 15279: } elsif ($item eq 'customrole') {
15280: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 15281: my @keyorder = ('order','desc','access','status','exc','inc');
15282: my %keytext = &Apache::lonlocal::texthash(
15283: order => 'Order',
15284: desc => 'Role description',
15285: access => 'Role usage',
1.300 droeschl 15286: status => 'Allowed institutional types',
1.285 raeburn 15287: exc => 'Allowed personnel',
15288: inc => 'Disallowed personnel',
15289: );
1.282 raeburn 15290: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 15291: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
15292: if ($role eq $newrole) {
15293: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
15294: $role).'<ul>';
15295: } else {
15296: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15297: $role).'<ul>';
15298: }
15299: foreach my $key (@keyorder) {
15300: if ($changes{'customrole'}{$role}{$key}) {
15301: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
15302: $keytext{$key},$newsettings{$role}{$key}).
15303: '</li>';
15304: }
15305: }
15306: if (ref($changedprivs{$role}) eq 'HASH') {
15307: $shownprivs{$role} = 1;
15308: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
15309: foreach my $level (@levelorder) {
15310: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
15311: next if ($item eq '');
15312: my ($priv) = split(/\&/,$item,2);
15313: if (&Apache::lonnet::plaintext($priv)) {
15314: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
15315: unless ($level eq 'c') {
15316: $resulttext .= ' ('.$lt{$level}.')';
15317: }
15318: $resulttext .= '</li>';
15319: }
15320: }
15321: }
15322: $resulttext .= '</ul>';
15323: }
15324: $resulttext .= '</ul></li>';
15325: }
15326: }
15327: }
15328: }
15329: }
15330: }
15331: if (keys(%changedprivs)) {
15332: foreach my $role (sort(keys(%changedprivs))) {
15333: unless ($shownprivs{$role}) {
15334: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15335: $role).'<ul>'.
15336: '<li>'.&mt('Privileges set to :').'<ul>';
15337: foreach my $level (@levelorder) {
15338: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
15339: next if ($item eq '');
15340: my ($priv) = split(/\&/,$item,2);
15341: if (&Apache::lonnet::plaintext($priv)) {
15342: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
15343: unless ($level eq 'c') {
15344: $resulttext .= ' ('.$lt{$level}.')';
15345: }
15346: $resulttext .= '</li>';
15347: }
1.282 raeburn 15348: }
15349: }
1.285 raeburn 15350: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 15351: }
15352: }
15353: }
1.285 raeburn 15354: $resulttext .= '</ul>';
15355: } else {
15356: $resulttext = &mt('No changes made to help settings');
1.118 jms 15357: }
15358: if ($errors) {
1.168 raeburn 15359: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 15360: $errors.'</ul>';
1.118 jms 15361: }
15362: return $resulttext;
15363: }
15364:
1.121 raeburn 15365: sub modify_coursedefaults {
1.212 raeburn 15366: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 15367: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 15368: my %defaultchecked = (
15369: 'canuse_pdfforms' => 'off',
15370: 'uselcmath' => 'on',
15371: 'usejsme' => 'on'
15372: );
15373: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 15374: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 15375: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
15376: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
15377: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 15378: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 15379: my %staticdefaults = (
15380: anonsurvey_threshold => 10,
15381: uploadquota => 500,
1.257 raeburn 15382: postsubmit => 60,
1.276 raeburn 15383: mysqltables => 172800,
1.198 raeburn 15384: );
1.314 raeburn 15385: my %texoptions = (
15386: MathJax => 'MathJax',
15387: mimetex => &mt('Convert to Images'),
15388: tth => &mt('TeX to HTML'),
15389: );
1.121 raeburn 15390: $defaultshash{'coursedefaults'} = {};
15391:
15392: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
15393: if ($domconfig{'coursedefaults'} eq '') {
15394: $domconfig{'coursedefaults'} = {};
15395: }
15396: }
15397:
15398: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
15399: foreach my $item (@toggles) {
15400: if ($defaultchecked{$item} eq 'on') {
15401: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15402: ($env{'form.'.$item} eq '0')) {
15403: $changes{$item} = 1;
1.192 raeburn 15404: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 15405: $changes{$item} = 1;
15406: }
15407: } elsif ($defaultchecked{$item} eq 'off') {
15408: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15409: ($env{'form.'.$item} eq '1')) {
15410: $changes{$item} = 1;
15411: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
15412: $changes{$item} = 1;
15413: }
15414: }
15415: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
15416: }
1.198 raeburn 15417: foreach my $item (@numbers) {
15418: my ($currdef,$newdef);
1.208 raeburn 15419: $newdef = $env{'form.'.$item};
1.198 raeburn 15420: if ($item eq 'anonsurvey_threshold') {
15421: $currdef = $domconfig{'coursedefaults'}{$item};
15422: $newdef =~ s/\D//g;
15423: if ($newdef eq '' || $newdef < 1) {
15424: $newdef = 1;
15425: }
15426: $defaultshash{'coursedefaults'}{$item} = $newdef;
15427: } else {
1.276 raeburn 15428: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
15429: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
15430: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 15431: }
15432: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 15433: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 15434: }
15435: if ($currdef ne $newdef) {
15436: my $staticdef;
15437: if ($item eq 'anonsurvey_threshold') {
15438: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
15439: $changes{$item} = 1;
15440: }
1.276 raeburn 15441: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 15442: my $setting = $1;
1.276 raeburn 15443: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
15444: $changes{$setting} = 1;
1.198 raeburn 15445: }
15446: }
1.139 raeburn 15447: }
15448: }
1.314 raeburn 15449: my $texengine;
15450: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
15451: $texengine = $env{'form.texengine'};
15452: if ($defaultshash{'coursedefaults'}{'texengine'} eq '') {
15453: unless ($texengine eq 'MathJax') {
15454: $changes{'texengine'} = 1;
15455: }
15456: } elsif ($defaultshash{'coursedefaults'}{'texengine'} ne $texengine) {
15457: $changes{'texengine'} = 1;
15458: }
15459: }
15460: if ($texengine ne '') {
15461: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
15462: }
1.264 raeburn 15463: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
15464: my @currclonecode;
15465: if (ref($currclone) eq 'HASH') {
15466: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
15467: @currclonecode = @{$currclone->{'instcode'}};
15468: }
15469: }
15470: my $newclone;
1.289 raeburn 15471: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 15472: $newclone = $env{'form.canclone'};
15473: }
15474: if ($newclone eq 'instcode') {
15475: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
15476: my (%codedefaults,@code_order,@clonecode);
15477: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
15478: \@code_order);
15479: foreach my $item (@code_order) {
15480: if (grep(/^\Q$item\E$/,@newcodes)) {
15481: push(@clonecode,$item);
15482: }
15483: }
15484: if (@clonecode) {
15485: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
15486: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
15487: if (@diffs) {
15488: $changes{'canclone'} = 1;
15489: }
15490: } else {
15491: $newclone eq '';
15492: }
15493: } elsif ($newclone ne '') {
1.289 raeburn 15494: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
15495: }
1.264 raeburn 15496: if ($newclone ne $currclone) {
15497: $changes{'canclone'} = 1;
15498: }
1.257 raeburn 15499: my %credits;
15500: foreach my $type (@types) {
15501: unless ($type eq 'community') {
15502: $credits{$type} = $env{'form.'.$type.'_credits'};
15503: $credits{$type} =~ s/[^\d.]+//g;
15504: }
15505: }
15506: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
15507: ($env{'form.coursecredits'} eq '1')) {
15508: $changes{'coursecredits'} = 1;
15509: foreach my $type (keys(%credits)) {
15510: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15511: }
15512: } else {
1.289 raeburn 15513: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 15514: foreach my $type (@types) {
15515: unless ($type eq 'community') {
1.289 raeburn 15516: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 15517: $changes{'coursecredits'} = 1;
15518: }
15519: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15520: }
15521: }
15522: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15523: foreach my $type (@types) {
15524: unless ($type eq 'community') {
15525: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
15526: $changes{'coursecredits'} = 1;
15527: last;
15528: }
15529: }
15530: }
15531: }
15532: }
15533: if ($env{'form.postsubmit'} eq '1') {
15534: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
15535: my %currtimeout;
15536: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15537: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
15538: $changes{'postsubmit'} = 1;
15539: }
15540: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15541: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
15542: }
15543: } else {
15544: $changes{'postsubmit'} = 1;
15545: }
15546: foreach my $type (@types) {
15547: my $timeout = $env{'form.'.$type.'_timeout'};
15548: $timeout =~ s/\D//g;
15549: if ($timeout == $staticdefaults{'postsubmit'}) {
15550: $timeout = '';
15551: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
15552: $timeout = '0';
15553: }
15554: unless ($timeout eq '') {
15555: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
15556: }
15557: if (exists($currtimeout{$type})) {
15558: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 15559: $changes{'postsubmit'} = 1;
1.257 raeburn 15560: }
15561: } elsif ($timeout ne '') {
15562: $changes{'postsubmit'} = 1;
15563: }
15564: }
15565: } else {
15566: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
15567: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15568: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
15569: $changes{'postsubmit'} = 1;
15570: }
15571: } else {
15572: $changes{'postsubmit'} = 1;
15573: }
1.192 raeburn 15574: }
1.121 raeburn 15575: }
15576: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
15577: $dom);
15578: if ($putresult eq 'ok') {
15579: if (keys(%changes) > 0) {
1.213 raeburn 15580: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 15581: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 15582: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.314 raeburn 15583: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
15584: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','texengine') {
1.257 raeburn 15585: if ($changes{$item}) {
15586: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
15587: }
1.289 raeburn 15588: }
1.192 raeburn 15589: if ($changes{'coursecredits'}) {
15590: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 15591: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
15592: $domdefaults{$type.'credits'} =
15593: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
15594: }
15595: }
15596: }
15597: if ($changes{'postsubmit'}) {
15598: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15599: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
15600: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15601: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
15602: $domdefaults{$type.'postsubtimeout'} =
15603: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15604: }
15605: }
1.192 raeburn 15606: }
15607: }
1.198 raeburn 15608: if ($changes{'uploadquota'}) {
15609: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15610: foreach my $type (@types) {
15611: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
15612: }
15613: }
15614: }
1.264 raeburn 15615: if ($changes{'canclone'}) {
15616: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15617: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15618: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
15619: if (@clonecodes) {
15620: $domdefaults{'canclone'} = join('+',@clonecodes);
15621: }
15622: }
15623: } else {
15624: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
15625: }
15626: }
1.121 raeburn 15627: my $cachetime = 24*60*60;
15628: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 15629: if (ref($lastactref) eq 'HASH') {
15630: $lastactref->{'domdefaults'} = 1;
15631: }
1.121 raeburn 15632: }
15633: $resulttext = &mt('Changes made:').'<ul>';
15634: foreach my $item (sort(keys(%changes))) {
15635: if ($item eq 'canuse_pdfforms') {
15636: if ($env{'form.'.$item} eq '1') {
15637: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
15638: } else {
15639: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
15640: }
1.257 raeburn 15641: } elsif ($item eq 'uselcmath') {
15642: if ($env{'form.'.$item} eq '1') {
15643: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
15644: } else {
15645: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
15646: }
15647: } elsif ($item eq 'usejsme') {
15648: if ($env{'form.'.$item} eq '1') {
15649: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
15650: } else {
1.289 raeburn 15651: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 15652: }
1.314 raeburn 15653: } elsif ($item eq 'texengine') {
15654: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
15655: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
15656: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
15657: }
1.139 raeburn 15658: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 15659: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 15660: } elsif ($item eq 'uploadquota') {
15661: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15662: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
15663: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
15664: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 15665: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 15666: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 15667: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
15668: '</ul>'.
15669: '</li>';
15670: } else {
15671: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
15672: }
1.276 raeburn 15673: } elsif ($item eq 'mysqltables') {
15674: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
15675: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
15676: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
15677: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
15678: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
15679: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
15680: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
15681: '</ul>'.
15682: '</li>';
15683: } else {
15684: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
15685: }
1.257 raeburn 15686: } elsif ($item eq 'postsubmit') {
15687: if ($domdefaults{'postsubmit'} eq 'off') {
15688: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
15689: } else {
15690: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 15691: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 15692: $resulttext .= &mt('durations:').'<ul>';
15693: foreach my $type (@types) {
15694: $resulttext .= '<li>';
15695: my $timeout;
15696: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15697: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15698: }
15699: my $display;
15700: if ($timeout eq '0') {
15701: $display = &mt('unlimited');
15702: } elsif ($timeout eq '') {
15703: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
15704: } else {
15705: $display = &mt('[quant,_1,second]',$timeout);
15706: }
15707: if ($type eq 'community') {
15708: $resulttext .= &mt('Communities');
15709: } elsif ($type eq 'official') {
15710: $resulttext .= &mt('Official courses');
15711: } elsif ($type eq 'unofficial') {
15712: $resulttext .= &mt('Unofficial courses');
15713: } elsif ($type eq 'textbook') {
15714: $resulttext .= &mt('Textbook courses');
1.271 raeburn 15715: } elsif ($type eq 'placement') {
15716: $resulttext .= &mt('Placement tests');
1.257 raeburn 15717: }
15718: $resulttext .= ' -- '.$display.'</li>';
15719: }
15720: $resulttext .= '</ul>';
15721: }
1.289 raeburn 15722: $resulttext .= '</li>';
1.257 raeburn 15723: }
1.192 raeburn 15724: } elsif ($item eq 'coursecredits') {
15725: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15726: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 15727: ($domdefaults{'unofficialcredits'} eq '') &&
15728: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 15729: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
15730: } else {
15731: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
15732: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
15733: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 15734: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 15735: '</ul>'.
15736: '</li>';
15737: }
15738: } else {
15739: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
15740: }
1.264 raeburn 15741: } elsif ($item eq 'canclone') {
15742: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15743: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15744: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
15745: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
15746: }
15747: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
15748: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
15749: } else {
1.289 raeburn 15750: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 15751: }
1.140 raeburn 15752: }
1.121 raeburn 15753: }
15754: $resulttext .= '</ul>';
15755: } else {
15756: $resulttext = &mt('No changes made to course defaults');
15757: }
15758: } else {
15759: $resulttext = '<span class="LC_error">'.
15760: &mt('An error occurred: [_1]',$putresult).'</span>';
15761: }
15762: return $resulttext;
15763: }
15764:
1.231 raeburn 15765: sub modify_selfenrollment {
15766: my ($dom,$lastactref,%domconfig) = @_;
15767: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 15768: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 15769: my %titles = &tool_titles();
1.232 raeburn 15770: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
15771: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 15772: $ordered{'default'} = ['types','registered','approval','limit'];
15773:
15774: my (%roles,%shown,%toplevel);
15775: $roles{'0'} = &Apache::lonnet::plaintext('dc');
15776:
15777: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
15778: if ($domconfig{'selfenrollment'} eq '') {
15779: $domconfig{'selfenrollment'} = {};
15780: }
15781: }
15782: %toplevel = (
15783: admin => 'Configuration Rights',
15784: default => 'Default settings',
15785: validation => 'Validation of self-enrollment requests',
15786: );
1.233 raeburn 15787: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 15788:
15789: if (ref($ordered{'admin'}) eq 'ARRAY') {
15790: foreach my $item (@{$ordered{'admin'}}) {
15791: foreach my $type (@types) {
15792: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
15793: $selfenrollhash{'admin'}{$type}{$item} = 1;
15794: } else {
15795: $selfenrollhash{'admin'}{$type}{$item} = 0;
15796: }
15797: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
15798: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
15799: if ($selfenrollhash{'admin'}{$type}{$item} ne
15800: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
15801: push(@{$changes{'admin'}{$type}},$item);
15802: }
15803: } else {
15804: if (!$selfenrollhash{'admin'}{$type}{$item}) {
15805: push(@{$changes{'admin'}{$type}},$item);
15806: }
15807: }
15808: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
15809: push(@{$changes{'admin'}{$type}},$item);
15810: }
15811: }
15812: }
15813: }
15814:
15815: foreach my $item (@{$ordered{'default'}}) {
15816: foreach my $type (@types) {
15817: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
15818: if ($item eq 'types') {
15819: unless (($value eq 'all') || ($value eq 'dom')) {
15820: $value = '';
15821: }
15822: } elsif ($item eq 'registered') {
15823: unless ($value eq '1') {
15824: $value = 0;
15825: }
15826: } elsif ($item eq 'approval') {
15827: unless ($value =~ /^[012]$/) {
15828: $value = 0;
15829: }
15830: } else {
15831: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
15832: $value = 'none';
15833: }
15834: }
15835: $selfenrollhash{'default'}{$type}{$item} = $value;
15836: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
15837: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
15838: if ($selfenrollhash{'default'}{$type}{$item} ne
15839: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
15840: push(@{$changes{'default'}{$type}},$item);
15841: }
15842: } else {
15843: push(@{$changes{'default'}{$type}},$item);
15844: }
15845: } else {
15846: push(@{$changes{'default'}{$type}},$item);
15847: }
15848: if ($item eq 'limit') {
15849: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
15850: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
15851: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
15852: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
15853: }
15854: } else {
15855: $selfenrollhash{'default'}{$type}{'cap'} = '';
15856: }
15857: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
15858: if ($selfenrollhash{'default'}{$type}{'cap'} ne
15859: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
15860: push(@{$changes{'default'}{$type}},'cap');
15861: }
15862: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
15863: push(@{$changes{'default'}{$type}},'cap');
15864: }
15865: }
15866: }
15867: }
15868:
15869: foreach my $item (@{$itemsref}) {
15870: if ($item eq 'fields') {
15871: my @changed;
15872: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
15873: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
15874: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
15875: }
15876: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
15877: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
15878: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
15879: $domconfig{'selfenrollment'}{'validation'}{$item});
15880: } else {
15881: @changed = @{$selfenrollhash{'validation'}{$item}};
15882: }
15883: } else {
15884: @changed = @{$selfenrollhash{'validation'}{$item}};
15885: }
15886: if (@changed) {
15887: if ($selfenrollhash{'validation'}{$item}) {
15888: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
15889: } else {
15890: $changes{'validation'}{$item} = &mt('None');
15891: }
15892: }
15893: } else {
15894: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
15895: if ($item eq 'markup') {
15896: if ($env{'form.selfenroll_validation_'.$item}) {
15897: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
15898: }
15899: }
15900: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
15901: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
15902: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
15903: }
15904: }
15905: }
15906: }
15907:
15908: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
15909: $dom);
15910: if ($putresult eq 'ok') {
15911: if (keys(%changes) > 0) {
15912: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15913: $resulttext = &mt('Changes made:').'<ul>';
15914: foreach my $key ('admin','default','validation') {
15915: if (ref($changes{$key}) eq 'HASH') {
15916: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
15917: if ($key eq 'validation') {
15918: foreach my $item (@{$itemsref}) {
15919: if (exists($changes{$key}{$item})) {
15920: if ($item eq 'markup') {
15921: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
15922: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
15923: } else {
15924: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
15925: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
15926: }
15927: }
15928: }
15929: } else {
15930: foreach my $type (@types) {
15931: if ($type eq 'community') {
15932: $roles{'1'} = &mt('Community personnel');
15933: } else {
15934: $roles{'1'} = &mt('Course personnel');
15935: }
15936: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 15937: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
15938: if ($key eq 'admin') {
15939: my @mgrdc = ();
15940: if (ref($ordered{$key}) eq 'ARRAY') {
15941: foreach my $item (@{$ordered{'admin'}}) {
15942: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
15943: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
15944: push(@mgrdc,$item);
15945: }
15946: }
15947: }
15948: if (@mgrdc) {
15949: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
15950: } else {
15951: delete($domdefaults{$type.'selfenrolladmdc'});
15952: }
15953: }
15954: } else {
15955: if (ref($ordered{$key}) eq 'ARRAY') {
15956: foreach my $item (@{$ordered{$key}}) {
15957: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
15958: $domdefaults{$type.'selfenroll'.$item} =
15959: $selfenrollhash{$key}{$type}{$item};
15960: }
15961: }
15962: }
15963: }
15964: }
1.231 raeburn 15965: $resulttext .= '<li>'.$titles{$type}.'<ul>';
15966: foreach my $item (@{$ordered{$key}}) {
15967: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
15968: $resulttext .= '<li>';
15969: if ($key eq 'admin') {
15970: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
15971: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
15972: } else {
15973: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
15974: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
15975: }
15976: $resulttext .= '</li>';
15977: }
15978: }
15979: $resulttext .= '</ul></li>';
15980: }
15981: }
15982: $resulttext .= '</ul></li>';
15983: }
15984: }
1.305 raeburn 15985: }
15986: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
15987: my $cachetime = 24*60*60;
15988: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15989: if (ref($lastactref) eq 'HASH') {
15990: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 15991: }
1.231 raeburn 15992: }
15993: $resulttext .= '</ul>';
15994: } else {
15995: $resulttext = &mt('No changes made to self-enrollment settings');
15996: }
15997: } else {
15998: $resulttext = '<span class="LC_error">'.
15999: &mt('An error occurred: [_1]',$putresult).'</span>';
16000: }
16001: return $resulttext;
16002: }
16003:
1.137 raeburn 16004: sub modify_usersessions {
1.212 raeburn 16005: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 16006: my @hostingtypes = ('version','excludedomain','includedomain');
16007: my @offloadtypes = ('primary','default');
16008: my %types = (
16009: remote => \@hostingtypes,
16010: hosted => \@hostingtypes,
16011: spares => \@offloadtypes,
16012: );
16013: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 16014: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 16015: my (%by_ip,%by_location,@intdoms,@instdoms);
16016: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 16017: my @locations = sort(keys(%by_location));
1.137 raeburn 16018: my (%defaultshash,%changes);
16019: foreach my $prefix (@prefixes) {
16020: $defaultshash{'usersessions'}{$prefix} = {};
16021: }
1.212 raeburn 16022: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 16023: my $resulttext;
1.138 raeburn 16024: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 16025: foreach my $prefix (@prefixes) {
1.145 raeburn 16026: next if ($prefix eq 'spares');
16027: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 16028: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16029: if ($type eq 'version') {
16030: my $value = $env{'form.'.$prefix.'_'.$type};
16031: my $okvalue;
16032: if ($value ne '') {
16033: if (grep(/^\Q$value\E$/,@lcversions)) {
16034: $okvalue = $value;
16035: }
16036: }
16037: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16038: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
16039: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
16040: if ($inuse == 0) {
16041: $changes{$prefix}{$type} = 1;
16042: } else {
16043: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
16044: $changes{$prefix}{$type} = 1;
16045: }
16046: if ($okvalue ne '') {
16047: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16048: }
16049: }
16050: } else {
16051: if (($inuse == 1) && ($okvalue ne '')) {
16052: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16053: $changes{$prefix}{$type} = 1;
16054: }
16055: }
16056: } else {
16057: if (($inuse == 1) && ($okvalue ne '')) {
16058: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16059: $changes{$prefix}{$type} = 1;
16060: }
16061: }
16062: } else {
16063: if (($inuse == 1) && ($okvalue ne '')) {
16064: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16065: $changes{$prefix}{$type} = 1;
16066: }
16067: }
16068: } else {
16069: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16070: my @okvals;
16071: foreach my $val (@vals) {
1.138 raeburn 16072: if ($val =~ /:/) {
16073: my @items = split(/:/,$val);
16074: foreach my $item (@items) {
16075: if (ref($by_location{$item}) eq 'ARRAY') {
16076: push(@okvals,$item);
16077: }
16078: }
16079: } else {
16080: if (ref($by_location{$val}) eq 'ARRAY') {
16081: push(@okvals,$val);
16082: }
1.137 raeburn 16083: }
16084: }
16085: @okvals = sort(@okvals);
16086: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16087: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
16088: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
16089: if ($inuse == 0) {
16090: $changes{$prefix}{$type} = 1;
16091: } else {
16092: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16093: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
16094: if (@changed > 0) {
16095: $changes{$prefix}{$type} = 1;
16096: }
16097: }
16098: } else {
16099: if ($inuse == 1) {
16100: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16101: $changes{$prefix}{$type} = 1;
16102: }
16103: }
16104: } else {
16105: if ($inuse == 1) {
16106: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16107: $changes{$prefix}{$type} = 1;
16108: }
16109: }
16110: } else {
16111: if ($inuse == 1) {
16112: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16113: $changes{$prefix}{$type} = 1;
16114: }
16115: }
16116: }
16117: }
16118: }
1.145 raeburn 16119:
16120: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 16121: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 16122: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
16123: my $savespares;
16124:
16125: foreach my $lonhost (sort(keys(%servers))) {
16126: my $serverhomeID =
16127: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 16128: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 16129: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
16130: my %spareschg;
16131: foreach my $type (@{$types{'spares'}}) {
16132: my @okspares;
16133: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
16134: foreach my $server (@checked) {
1.152 raeburn 16135: if (&Apache::lonnet::hostname($server) ne '') {
16136: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
16137: unless (grep(/^\Q$server\E$/,@okspares)) {
16138: push(@okspares,$server);
16139: }
1.145 raeburn 16140: }
16141: }
16142: }
16143: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
16144: my $newspare;
1.152 raeburn 16145: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
16146: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 16147: $newspare = $new;
16148: }
16149: }
1.152 raeburn 16150: my @spares;
16151: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
16152: @spares = sort(@okspares,$newspare);
16153: } else {
16154: @spares = sort(@okspares);
16155: }
16156: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 16157: if (ref($spareid{$lonhost}) eq 'HASH') {
16158: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 16159: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 16160: if (@diffs > 0) {
16161: $spareschg{$type} = 1;
16162: }
16163: }
16164: }
16165: }
16166: if (keys(%spareschg) > 0) {
16167: $changes{'spares'}{$lonhost} = \%spareschg;
16168: }
16169: }
1.261 raeburn 16170: $defaultshash{'usersessions'}{'offloadnow'} = {};
16171: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
16172: my @okoffload;
16173: if (@offloadnow) {
16174: foreach my $server (@offloadnow) {
16175: if (&Apache::lonnet::hostname($server) ne '') {
16176: unless (grep(/^\Q$server\E$/,@okoffload)) {
16177: push(@okoffload,$server);
16178: }
16179: }
16180: }
16181: if (@okoffload) {
16182: foreach my $lonhost (@okoffload) {
16183: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
16184: }
16185: }
16186: }
1.145 raeburn 16187: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16188: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
16189: if (ref($changes{'spares'}) eq 'HASH') {
16190: if (keys(%{$changes{'spares'}}) > 0) {
16191: $savespares = 1;
16192: }
16193: }
16194: } else {
16195: $savespares = 1;
16196: }
1.261 raeburn 16197: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
16198: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
16199: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
16200: $changes{'offloadnow'} = 1;
16201: last;
16202: }
16203: }
16204: unless ($changes{'offloadnow'}) {
1.289 raeburn 16205: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
1.261 raeburn 16206: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
16207: $changes{'offloadnow'} = 1;
16208: last;
16209: }
16210: }
16211: }
16212: } elsif (@okoffload) {
16213: $changes{'offloadnow'} = 1;
16214: }
16215: } elsif (@okoffload) {
16216: $changes{'offloadnow'} = 1;
1.145 raeburn 16217: }
1.147 raeburn 16218: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
16219: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 16220: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16221: $dom);
16222: if ($putresult eq 'ok') {
16223: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
16224: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
16225: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
16226: }
16227: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
16228: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
16229: }
1.261 raeburn 16230: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
16231: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
16232: }
1.137 raeburn 16233: }
16234: my $cachetime = 24*60*60;
16235: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 16236: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 16237: if (ref($lastactref) eq 'HASH') {
16238: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 16239: $lastactref->{'usersessions'} = 1;
1.212 raeburn 16240: }
1.147 raeburn 16241: if (keys(%changes) > 0) {
16242: my %lt = &usersession_titles();
16243: $resulttext = &mt('Changes made:').'<ul>';
16244: foreach my $prefix (@prefixes) {
16245: if (ref($changes{$prefix}) eq 'HASH') {
16246: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
16247: if ($prefix eq 'spares') {
16248: if (ref($changes{$prefix}) eq 'HASH') {
16249: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
16250: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 16251: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 16252: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
16253: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 16254: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
16255: foreach my $type (@{$types{$prefix}}) {
16256: if ($changes{$prefix}{$lonhost}{$type}) {
16257: my $offloadto = &mt('None');
16258: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
16259: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
16260: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
16261: }
1.145 raeburn 16262: }
1.147 raeburn 16263: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 16264: }
1.137 raeburn 16265: }
16266: }
1.147 raeburn 16267: $resulttext .= '</li>';
1.137 raeburn 16268: }
16269: }
1.147 raeburn 16270: } else {
16271: foreach my $type (@{$types{$prefix}}) {
16272: if (defined($changes{$prefix}{$type})) {
16273: my $newvalue;
16274: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
16275: if (ref($defaultshash{'usersessions'}{$prefix})) {
16276: if ($type eq 'version') {
16277: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
16278: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
16279: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
16280: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
16281: }
1.145 raeburn 16282: }
16283: }
16284: }
1.147 raeburn 16285: if ($newvalue eq '') {
16286: if ($type eq 'version') {
16287: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
16288: } else {
16289: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
16290: }
1.145 raeburn 16291: } else {
1.147 raeburn 16292: if ($type eq 'version') {
16293: $newvalue .= ' '.&mt('(or later)');
16294: }
16295: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 16296: }
1.137 raeburn 16297: }
16298: }
16299: }
1.147 raeburn 16300: $resulttext .= '</ul>';
1.137 raeburn 16301: }
16302: }
1.261 raeburn 16303: if ($changes{'offloadnow'}) {
16304: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
16305: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
16306: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
16307: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
16308: $resulttext .= '<li>'.$lonhost.'</li>';
16309: }
16310: $resulttext .= '</ul>';
16311: } else {
16312: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
16313: }
16314: } else {
16315: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
16316: }
16317: }
1.147 raeburn 16318: $resulttext .= '</ul>';
16319: } else {
16320: $resulttext = $nochgmsg;
1.137 raeburn 16321: }
16322: } else {
16323: $resulttext = '<span class="LC_error">'.
16324: &mt('An error occurred: [_1]',$putresult).'</span>';
16325: }
16326: } else {
1.147 raeburn 16327: $resulttext = $nochgmsg;
1.137 raeburn 16328: }
16329: return $resulttext;
16330: }
16331:
1.275 raeburn 16332: sub modify_ssl {
16333: my ($dom,$lastactref,%domconfig) = @_;
16334: my (%by_ip,%by_location,@intdoms,@instdoms);
16335: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
16336: my @locations = sort(keys(%by_location));
16337: my %servers = &Apache::lonnet::internet_dom_servers($dom);
16338: my (%defaultshash,%changes);
16339: my $action = 'ssl';
1.293 raeburn 16340: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 16341: foreach my $prefix (@prefixes) {
16342: $defaultshash{$action}{$prefix} = {};
16343: }
16344: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16345: my $resulttext;
16346: my %iphost = &Apache::lonnet::get_iphost();
16347: my @reptypes = ('certreq','nocertreq');
16348: my @connecttypes = ('dom','intdom','other');
16349: my %types = (
1.293 raeburn 16350: connto => \@connecttypes,
16351: connfrom => \@connecttypes,
16352: replication => \@reptypes,
1.275 raeburn 16353: );
16354: foreach my $prefix (sort(keys(%types))) {
16355: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 16356: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 16357: my $value = 'yes';
16358: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
16359: $value = $env{'form.'.$prefix.'_'.$type};
16360: }
16361: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
16362: if ($domconfig{$action}{$prefix}{$type} ne '') {
16363: if ($value ne $domconfig{$action}{$prefix}{$type}) {
16364: $changes{$prefix}{$type} = 1;
16365: }
16366: $defaultshash{$action}{$prefix}{$type} = $value;
16367: } else {
16368: $defaultshash{$action}{$prefix}{$type} = $value;
16369: $changes{$prefix}{$type} = 1;
16370: }
16371: } else {
16372: $defaultshash{$action}{$prefix}{$type} = $value;
16373: $changes{$prefix}{$type} = 1;
16374: }
16375: if (($type eq 'dom') && (keys(%servers) == 1)) {
16376: delete($changes{$prefix}{$type});
16377: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
16378: delete($changes{$prefix}{$type});
16379: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
16380: delete($changes{$prefix}{$type});
16381: }
16382: } elsif ($prefix eq 'replication') {
16383: if (@locations > 0) {
16384: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16385: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16386: my @okvals;
16387: foreach my $val (@vals) {
16388: if ($val =~ /:/) {
16389: my @items = split(/:/,$val);
16390: foreach my $item (@items) {
16391: if (ref($by_location{$item}) eq 'ARRAY') {
16392: push(@okvals,$item);
16393: }
16394: }
16395: } else {
16396: if (ref($by_location{$val}) eq 'ARRAY') {
16397: push(@okvals,$val);
16398: }
16399: }
16400: }
16401: @okvals = sort(@okvals);
16402: if (ref($domconfig{$action}) eq 'HASH') {
16403: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
16404: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
16405: if ($inuse == 0) {
16406: $changes{$prefix}{$type} = 1;
16407: } else {
16408: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16409: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
16410: if (@changed > 0) {
16411: $changes{$prefix}{$type} = 1;
16412: }
16413: }
16414: } else {
16415: if ($inuse == 1) {
16416: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16417: $changes{$prefix}{$type} = 1;
16418: }
16419: }
16420: } else {
16421: if ($inuse == 1) {
16422: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16423: $changes{$prefix}{$type} = 1;
16424: }
16425: }
16426: } else {
16427: if ($inuse == 1) {
16428: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16429: $changes{$prefix}{$type} = 1;
16430: }
16431: }
16432: }
16433: }
16434: }
16435: }
16436: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
16437: if (keys(%changes) > 0) {
16438: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16439: $dom);
16440: if ($putresult eq 'ok') {
16441: if (ref($defaultshash{$action}) eq 'HASH') {
16442: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
16443: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
16444: }
1.293 raeburn 16445: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
16446: $domdefaults{'connto'} = $domconfig{$action}{'connto'};
16447: }
16448: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
16449: $domdefaults{'connfrom'} = $domconfig{$action}{'connfrom'};
1.275 raeburn 16450: }
16451: }
16452: my $cachetime = 24*60*60;
16453: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16454: if (ref($lastactref) eq 'HASH') {
16455: $lastactref->{'domdefaults'} = 1;
16456: }
16457: if (keys(%changes) > 0) {
16458: my %titles = &ssl_titles();
16459: $resulttext = &mt('Changes made:').'<ul>';
16460: foreach my $prefix (@prefixes) {
16461: if (ref($changes{$prefix}) eq 'HASH') {
16462: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
16463: foreach my $type (@{$types{$prefix}}) {
16464: if (defined($changes{$prefix}{$type})) {
16465: my $newvalue;
16466: if (ref($defaultshash{$action}) eq 'HASH') {
16467: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 16468: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 16469: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
16470: } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
16471: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
16472: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
16473: }
16474: }
16475: }
16476: if ($newvalue eq '') {
16477: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
16478: } else {
16479: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
16480: }
16481: }
16482: }
16483: }
16484: $resulttext .= '</ul>';
16485: }
16486: }
16487: } else {
16488: $resulttext = $nochgmsg;
16489: }
16490: } else {
16491: $resulttext = '<span class="LC_error">'.
16492: &mt('An error occurred: [_1]',$putresult).'</span>';
16493: }
16494: } else {
16495: $resulttext = $nochgmsg;
16496: }
16497: return $resulttext;
16498: }
16499:
1.279 raeburn 16500: sub modify_trust {
16501: my ($dom,$lastactref,%domconfig) = @_;
16502: my (%by_ip,%by_location,@intdoms,@instdoms);
16503: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
16504: my @locations = sort(keys(%by_location));
16505: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
16506: my @types = ('exc','inc');
16507: my (%defaultshash,%changes);
16508: foreach my $prefix (@prefixes) {
16509: $defaultshash{'trust'}{$prefix} = {};
16510: }
16511: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16512: my $resulttext;
16513: foreach my $prefix (@prefixes) {
16514: foreach my $type (@types) {
16515: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16516: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16517: my @okvals;
16518: foreach my $val (@vals) {
16519: if ($val =~ /:/) {
16520: my @items = split(/:/,$val);
16521: foreach my $item (@items) {
16522: if (ref($by_location{$item}) eq 'ARRAY') {
16523: push(@okvals,$item);
16524: }
16525: }
16526: } else {
16527: if (ref($by_location{$val}) eq 'ARRAY') {
16528: push(@okvals,$val);
16529: }
16530: }
16531: }
16532: @okvals = sort(@okvals);
16533: if (ref($domconfig{'trust'}) eq 'HASH') {
16534: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
16535: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
16536: if ($inuse == 0) {
16537: $changes{$prefix}{$type} = 1;
16538: } else {
16539: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16540: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
16541: if (@changed > 0) {
16542: $changes{$prefix}{$type} = 1;
16543: }
16544: }
16545: } else {
16546: if ($inuse == 1) {
16547: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16548: $changes{$prefix}{$type} = 1;
16549: }
16550: }
16551: } else {
16552: if ($inuse == 1) {
16553: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16554: $changes{$prefix}{$type} = 1;
16555: }
16556: }
16557: } else {
16558: if ($inuse == 1) {
16559: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16560: $changes{$prefix}{$type} = 1;
16561: }
16562: }
16563: }
16564: }
16565: my $nochgmsg = &mt('No changes made to trust settings.');
16566: if (keys(%changes) > 0) {
16567: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16568: $dom);
16569: if ($putresult eq 'ok') {
16570: if (ref($defaultshash{'trust'}) eq 'HASH') {
16571: foreach my $prefix (@prefixes) {
16572: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
16573: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
16574: }
16575: }
16576: }
16577: my $cachetime = 24*60*60;
16578: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16579: if (ref($lastactref) eq 'HASH') {
16580: $lastactref->{'domdefaults'} = 1;
16581: }
16582: if (keys(%changes) > 0) {
16583: my %lt = &trust_titles();
16584: $resulttext = &mt('Changes made:').'<ul>';
16585: foreach my $prefix (@prefixes) {
16586: if (ref($changes{$prefix}) eq 'HASH') {
16587: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
16588: foreach my $type (@types) {
16589: if (defined($changes{$prefix}{$type})) {
16590: my $newvalue;
16591: if (ref($defaultshash{'trust'}) eq 'HASH') {
16592: if (ref($defaultshash{'trust'}{$prefix})) {
16593: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
16594: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
16595: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
16596: }
16597: }
16598: }
16599: }
16600: if ($newvalue eq '') {
16601: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
16602: } else {
16603: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
16604: }
16605: }
16606: }
16607: $resulttext .= '</ul>';
16608: }
16609: }
16610: $resulttext .= '</ul>';
16611: } else {
16612: $resulttext = $nochgmsg;
16613: }
16614: } else {
16615: $resulttext = '<span class="LC_error">'.
16616: &mt('An error occurred: [_1]',$putresult).'</span>';
16617: }
16618: } else {
16619: $resulttext = $nochgmsg;
16620: }
16621: return $resulttext;
16622: }
16623:
1.150 raeburn 16624: sub modify_loadbalancing {
16625: my ($dom,%domconfig) = @_;
16626: my $primary_id = &Apache::lonnet::domain($dom,'primary');
16627: my $intdom = &Apache::lonnet::internet_dom($primary_id);
16628: my ($othertitle,$usertypes,$types) =
16629: &Apache::loncommon::sorted_inst_types($dom);
16630: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 16631: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 16632: my @sparestypes = ('primary','default');
16633: my %typetitles = &sparestype_titles();
16634: my $resulttext;
1.171 raeburn 16635: my (%currbalancer,%currtargets,%currrules,%existing);
16636: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
16637: %existing = %{$domconfig{'loadbalancing'}};
16638: }
16639: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
16640: \%currtargets,\%currrules);
16641: my ($saveloadbalancing,%defaultshash,%changes);
16642: my ($alltypes,$othertypes,$titles) =
16643: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
16644: my %ruletitles = &offloadtype_text();
16645: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
16646: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
16647: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
16648: if ($balancer eq '') {
16649: next;
16650: }
1.210 raeburn 16651: if (!exists($servers{$balancer})) {
1.171 raeburn 16652: if (exists($currbalancer{$balancer})) {
16653: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 16654: }
1.171 raeburn 16655: next;
16656: }
16657: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
16658: push(@{$changes{'delete'}},$balancer);
16659: next;
16660: }
16661: if (!exists($currbalancer{$balancer})) {
16662: push(@{$changes{'add'}},$balancer);
16663: }
16664: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
16665: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
16666: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
16667: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
16668: $saveloadbalancing = 1;
16669: }
16670: foreach my $sparetype (@sparestypes) {
16671: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
16672: my @offloadto;
16673: foreach my $target (@targets) {
16674: if (($servers{$target}) && ($target ne $balancer)) {
16675: if ($sparetype eq 'default') {
16676: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
16677: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 16678: }
16679: }
1.171 raeburn 16680: unless(grep(/^\Q$target\E$/,@offloadto)) {
16681: push(@offloadto,$target);
16682: }
1.150 raeburn 16683: }
16684: }
1.284 raeburn 16685: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
16686: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
16687: push(@offloadto,$balancer);
16688: }
16689: }
16690: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 16691: }
1.171 raeburn 16692: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 16693: foreach my $sparetype (@sparestypes) {
1.171 raeburn 16694: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
16695: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 16696: if (@targetdiffs > 0) {
1.171 raeburn 16697: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 16698: }
1.171 raeburn 16699: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16700: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16701: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 16702: }
16703: }
16704: }
16705: } else {
1.171 raeburn 16706: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 16707: foreach my $sparetype (@sparestypes) {
1.171 raeburn 16708: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16709: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16710: $changes{'curr'}{$balancer}{'targets'} = 1;
16711: }
1.150 raeburn 16712: }
16713: }
1.210 raeburn 16714: }
1.150 raeburn 16715: }
16716: my $ishomedom;
1.171 raeburn 16717: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
16718: $ishomedom = 1;
1.150 raeburn 16719: }
16720: if (ref($alltypes) eq 'ARRAY') {
16721: foreach my $type (@{$alltypes}) {
16722: my $rule;
1.210 raeburn 16723: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 16724: (!$ishomedom)) {
1.171 raeburn 16725: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
16726: }
16727: if ($rule eq 'specific') {
1.255 raeburn 16728: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 16729: if (exists($servers{$specifiedhost})) {
1.255 raeburn 16730: $rule = $specifiedhost;
16731: }
1.150 raeburn 16732: }
1.171 raeburn 16733: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
16734: if (ref($currrules{$balancer}) eq 'HASH') {
16735: if ($rule ne $currrules{$balancer}{$type}) {
16736: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 16737: }
16738: } elsif ($rule ne '') {
1.171 raeburn 16739: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 16740: }
16741: }
16742: }
1.171 raeburn 16743: }
16744: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
16745: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
16746: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
16747: $defaultshash{'loadbalancing'} = {};
16748: }
16749: my $putresult = &Apache::lonnet::put_dom('configuration',
16750: \%defaultshash,$dom);
16751: if ($putresult eq 'ok') {
16752: if (keys(%changes) > 0) {
1.252 raeburn 16753: my %toupdate;
1.171 raeburn 16754: if (ref($changes{'delete'}) eq 'ARRAY') {
16755: foreach my $balancer (sort(@{$changes{'delete'}})) {
16756: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 16757: $toupdate{$balancer} = 1;
1.150 raeburn 16758: }
1.171 raeburn 16759: }
16760: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 16761: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 16762: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 16763: $toupdate{$balancer} = 1;
1.171 raeburn 16764: }
16765: }
16766: if (ref($changes{'curr'}) eq 'HASH') {
16767: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 16768: $toupdate{$balancer} = 1;
1.171 raeburn 16769: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
16770: if ($changes{'curr'}{$balancer}{'targets'}) {
16771: my %offloadstr;
16772: foreach my $sparetype (@sparestypes) {
16773: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16774: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16775: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
16776: }
16777: }
1.150 raeburn 16778: }
1.171 raeburn 16779: if (keys(%offloadstr) == 0) {
16780: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 16781: } else {
1.171 raeburn 16782: my $showoffload;
16783: foreach my $sparetype (@sparestypes) {
16784: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
16785: if (defined($offloadstr{$sparetype})) {
16786: $showoffload .= $offloadstr{$sparetype};
16787: } else {
16788: $showoffload .= &mt('None');
16789: }
16790: $showoffload .= (' 'x3);
16791: }
16792: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 16793: }
16794: }
16795: }
1.171 raeburn 16796: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
16797: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
16798: foreach my $type (@{$alltypes}) {
16799: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
16800: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
16801: my $balancetext;
16802: if ($rule eq '') {
16803: $balancetext = $ruletitles{'default'};
1.209 raeburn 16804: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 16805: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 16806: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 16807: foreach my $sparetype (@sparestypes) {
16808: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16809: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
16810: }
16811: }
1.253 raeburn 16812: foreach my $item (@{$alltypes}) {
16813: next if ($item =~ /^_LC_ipchange/);
16814: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
16815: if ($hasrule eq 'homeserver') {
16816: map { $toupdate{$_} = 1; } (keys(%libraryservers));
16817: } else {
16818: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
16819: if ($servers{$hasrule}) {
16820: $toupdate{$hasrule} = 1;
16821: }
16822: }
16823: }
16824: }
1.254 raeburn 16825: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
16826: $balancetext = $ruletitles{$rule};
16827: } else {
16828: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
16829: $balancetext = $ruletitles{'particular'}.' '.$receiver;
16830: if ($receiver) {
16831: $toupdate{$receiver};
16832: }
16833: }
16834: } else {
16835: $balancetext = $ruletitles{$rule};
1.252 raeburn 16836: }
1.171 raeburn 16837: } else {
16838: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
16839: }
1.210 raeburn 16840: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 16841: }
16842: }
16843: }
16844: }
1.252 raeburn 16845: if (keys(%toupdate)) {
16846: my %thismachine;
16847: my $updatedhere;
16848: my $cachetime = 60*60*24;
16849: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
16850: foreach my $lonhost (keys(%toupdate)) {
16851: if ($thismachine{$lonhost}) {
16852: unless ($updatedhere) {
16853: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
16854: $defaultshash{'loadbalancing'},
16855: $cachetime);
16856: $updatedhere = 1;
16857: }
16858: } else {
16859: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
16860: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
16861: }
16862: }
16863: }
1.150 raeburn 16864: }
1.171 raeburn 16865: }
16866: if ($resulttext ne '') {
16867: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 16868: } else {
16869: $resulttext = $nochgmsg;
16870: }
16871: } else {
1.171 raeburn 16872: $resulttext = $nochgmsg;
1.150 raeburn 16873: }
16874: } else {
1.171 raeburn 16875: $resulttext = '<span class="LC_error">'.
16876: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 16877: }
16878: } else {
1.171 raeburn 16879: $resulttext = $nochgmsg;
1.150 raeburn 16880: }
16881: return $resulttext;
16882: }
16883:
1.48 raeburn 16884: sub recurse_check {
16885: my ($chkcats,$categories,$depth,$name) = @_;
16886: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
16887: my $chg = 0;
16888: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
16889: my $category = $chkcats->[$depth]{$name}[$j];
16890: my $item;
16891: if ($category eq '') {
16892: $chg ++;
16893: } else {
16894: my $deeper = $depth + 1;
16895: $item = &escape($category).':'.&escape($name).':'.$depth;
16896: if ($chg) {
16897: $categories->{$item} -= $chg;
16898: }
16899: &recurse_check($chkcats,$categories,$deeper,$category);
16900: $deeper --;
16901: }
16902: }
16903: }
16904: return;
16905: }
16906:
16907: sub recurse_cat_deletes {
16908: my ($item,$coursecategories,$deletions) = @_;
16909: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
16910: my $subdepth = $depth + 1;
16911: if (ref($coursecategories) eq 'HASH') {
16912: foreach my $subitem (keys(%{$coursecategories})) {
16913: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
16914: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
16915: delete($coursecategories->{$subitem});
16916: $deletions->{$subitem} = 1;
16917: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 16918: }
1.48 raeburn 16919: }
16920: }
16921: return;
16922: }
16923:
1.125 raeburn 16924: sub active_dc_picker {
1.191 raeburn 16925: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 16926: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 16927: my @domcoord = keys(%domcoords);
16928: if (keys(%currhash)) {
16929: foreach my $dc (keys(%currhash)) {
16930: unless (exists($domcoords{$dc})) {
16931: push(@domcoord,$dc);
16932: }
16933: }
16934: }
16935: @domcoord = sort(@domcoord);
1.210 raeburn 16936: my $numdcs = scalar(@domcoord);
1.191 raeburn 16937: my $rows = 0;
16938: my $table;
1.125 raeburn 16939: if ($numdcs > 1) {
1.191 raeburn 16940: $table = '<table>';
16941: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 16942: my $rem = $i%($numinrow);
16943: if ($rem == 0) {
16944: if ($i > 0) {
1.191 raeburn 16945: $table .= '</tr>';
1.125 raeburn 16946: }
1.191 raeburn 16947: $table .= '<tr>';
16948: $rows ++;
1.125 raeburn 16949: }
1.191 raeburn 16950: my $check = '';
16951: if ($inputtype eq 'radio') {
16952: if (keys(%currhash) == 0) {
16953: if (!$i) {
16954: $check = ' checked="checked"';
16955: }
16956: } elsif (exists($currhash{$domcoord[$i]})) {
16957: $check = ' checked="checked"';
16958: }
16959: } else {
16960: if (exists($currhash{$domcoord[$i]})) {
16961: $check = ' checked="checked"';
1.125 raeburn 16962: }
16963: }
1.191 raeburn 16964: if ($i == @domcoord - 1) {
1.125 raeburn 16965: my $colsleft = $numinrow - $rem;
16966: if ($colsleft > 1) {
1.191 raeburn 16967: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 16968: } else {
1.191 raeburn 16969: $table .= '<td class="LC_left_item">';
1.125 raeburn 16970: }
16971: } else {
1.191 raeburn 16972: $table .= '<td class="LC_left_item">';
16973: }
16974: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
16975: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
16976: $table .= '<span class="LC_nobreak"><label>'.
16977: '<input type="'.$inputtype.'" name="'.$name.'"'.
16978: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
16979: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 16980: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 16981: }
1.219 raeburn 16982: $table .= '</label></span></td>';
1.191 raeburn 16983: }
16984: $table .= '</tr></table>';
16985: } elsif ($numdcs == 1) {
1.219 raeburn 16986: my ($dcname,$dcdom) = split(':',$domcoord[0]);
16987: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 16988: if ($inputtype eq 'radio') {
1.247 raeburn 16989: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 16990: if ($user ne $dcname.':'.$dcdom) {
16991: $table .= ' ('.$dcname.':'.$dcdom.')';
16992: }
1.191 raeburn 16993: } else {
16994: my $check;
16995: if (exists($currhash{$domcoord[0]})) {
16996: $check = ' checked="checked"';
1.125 raeburn 16997: }
1.247 raeburn 16998: $table = '<span class="LC_nobreak"><label>'.
16999: '<input type="checkbox" name="'.$name.'" '.
17000: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 17001: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 17002: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 17003: }
1.220 raeburn 17004: $table .= '</label></span>';
1.191 raeburn 17005: $rows ++;
1.125 raeburn 17006: }
17007: }
1.191 raeburn 17008: return ($numdcs,$table,$rows);
1.125 raeburn 17009: }
17010:
1.137 raeburn 17011: sub usersession_titles {
17012: return &Apache::lonlocal::texthash(
17013: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
17014: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 17015: spares => 'Servers offloaded to, when busy',
1.137 raeburn 17016: version => 'LON-CAPA version requirement',
1.138 raeburn 17017: excludedomain => 'Allow all, but exclude specific domains',
17018: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 17019: primary => 'Primary (checked first)',
1.154 raeburn 17020: default => 'Default',
1.137 raeburn 17021: );
17022: }
17023:
1.152 raeburn 17024: sub id_for_thisdom {
17025: my (%servers) = @_;
17026: my %altids;
17027: foreach my $server (keys(%servers)) {
17028: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
17029: if ($serverhome ne $server) {
17030: $altids{$serverhome} = $server;
17031: }
17032: }
17033: return %altids;
17034: }
17035:
1.150 raeburn 17036: sub count_servers {
17037: my ($currbalancer,%servers) = @_;
17038: my (@spares,$numspares);
17039: foreach my $lonhost (sort(keys(%servers))) {
17040: next if ($currbalancer eq $lonhost);
17041: push(@spares,$lonhost);
17042: }
17043: if ($currbalancer) {
17044: $numspares = scalar(@spares);
17045: } else {
17046: $numspares = scalar(@spares) - 1;
17047: }
17048: return ($numspares,@spares);
17049: }
17050:
17051: sub lonbalance_targets_js {
1.171 raeburn 17052: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 17053: my $select = &mt('Select');
17054: my ($alltargets,$allishome,$allinsttypes,@alltypes);
17055: if (ref($servers) eq 'HASH') {
17056: $alltargets = join("','",sort(keys(%{$servers})));
17057: my @homedoms;
17058: foreach my $server (sort(keys(%{$servers}))) {
17059: if (&Apache::lonnet::host_domain($server) eq $dom) {
17060: push(@homedoms,'1');
17061: } else {
17062: push(@homedoms,'0');
17063: }
17064: }
17065: $allishome = join("','",@homedoms);
17066: }
17067: if (ref($types) eq 'ARRAY') {
17068: if (@{$types} > 0) {
17069: @alltypes = @{$types};
17070: }
17071: }
17072: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
17073: $allinsttypes = join("','",@alltypes);
1.171 raeburn 17074: my (%currbalancer,%currtargets,%currrules,%existing);
17075: if (ref($settings) eq 'HASH') {
17076: %existing = %{$settings};
17077: }
17078: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
17079: \%currtargets,\%currrules);
1.210 raeburn 17080: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 17081: return <<"END";
17082:
17083: <script type="text/javascript">
17084: // <![CDATA[
17085:
1.171 raeburn 17086: currBalancers = new Array('$balancers');
17087:
17088: function toggleTargets(balnum) {
17089: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
17090: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
17091: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
17092: var prevbalancer = prevhostitem.value;
17093: var baltotal = document.getElementById('loadbalancing_total').value;
17094: prevhostitem.value = balancer;
17095: if (prevbalancer != '') {
17096: var prevIdx = currBalancers.indexOf(prevbalancer);
17097: if (prevIdx != -1) {
17098: currBalancers.splice(prevIdx,1);
17099: }
17100: }
1.150 raeburn 17101: if (balancer == '') {
1.171 raeburn 17102: hideSpares(balnum);
1.150 raeburn 17103: } else {
1.171 raeburn 17104: var currIdx = currBalancers.indexOf(balancer);
17105: if (currIdx == -1) {
17106: currBalancers.push(balancer);
17107: }
1.150 raeburn 17108: var homedoms = new Array('$allishome');
1.171 raeburn 17109: var ishomedom = homedoms[lonhostitem.selectedIndex];
17110: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 17111: }
1.171 raeburn 17112: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 17113: return;
17114: }
17115:
1.171 raeburn 17116: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 17117: var alltargets = new Array('$alltargets');
17118: var insttypes = new Array('$allinsttypes');
1.151 raeburn 17119: var offloadtypes = new Array('primary','default');
17120:
1.171 raeburn 17121: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
17122: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 17123:
1.151 raeburn 17124: for (var i=0; i<offloadtypes.length; i++) {
17125: var count = 0;
17126: for (var j=0; j<alltargets.length; j++) {
17127: if (alltargets[j] != balancer) {
1.171 raeburn 17128: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
17129: item.value = alltargets[j];
17130: item.style.textAlign='left';
17131: item.style.textFace='normal';
17132: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
17133: if (currBalancers.indexOf(alltargets[j]) == -1) {
17134: item.disabled = '';
17135: } else {
17136: item.disabled = 'disabled';
17137: item.checked = false;
17138: }
1.151 raeburn 17139: count ++;
17140: }
1.150 raeburn 17141: }
17142: }
1.151 raeburn 17143: for (var k=0; k<insttypes.length; k++) {
17144: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 17145: if (ishomedom == 1) {
1.171 raeburn 17146: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
17147: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 17148: } else {
1.171 raeburn 17149: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
17150: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 17151: }
17152: } else {
1.171 raeburn 17153: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
17154: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 17155: }
1.151 raeburn 17156: if ((insttypes[k] != '_LC_external') &&
17157: ((insttypes[k] != '_LC_internetdom') ||
17158: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 17159: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
17160: item.options.length = 0;
17161: item.options[0] = new Option("","",true,true);
1.210 raeburn 17162: var idx = 0;
1.151 raeburn 17163: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 17164: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
17165: idx ++;
17166: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 17167: }
17168: }
17169: }
17170: }
17171: return;
17172: }
17173:
1.171 raeburn 17174: function hideSpares(balnum) {
1.150 raeburn 17175: var alltargets = new Array('$alltargets');
17176: var insttypes = new Array('$allinsttypes');
17177: var offloadtypes = new Array('primary','default');
17178:
1.171 raeburn 17179: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
17180: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 17181:
17182: var total = alltargets.length - 1;
17183: for (var i=0; i<offloadtypes; i++) {
17184: for (var j=0; j<total; j++) {
1.171 raeburn 17185: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
17186: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
17187: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 17188: }
1.150 raeburn 17189: }
17190: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 17191: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
17192: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 17193: if (insttypes[k] != '_LC_external') {
1.171 raeburn 17194: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
17195: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 17196: }
17197: }
17198: return;
17199: }
17200:
1.171 raeburn 17201: function checkOffloads(item,balnum,type) {
1.150 raeburn 17202: var alltargets = new Array('$alltargets');
17203: var offloadtypes = new Array('primary','default');
17204: if (item.checked) {
17205: var total = alltargets.length - 1;
17206: var other;
17207: if (type == offloadtypes[0]) {
1.151 raeburn 17208: other = offloadtypes[1];
1.150 raeburn 17209: } else {
1.151 raeburn 17210: other = offloadtypes[0];
1.150 raeburn 17211: }
17212: for (var i=0; i<total; i++) {
1.171 raeburn 17213: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 17214: if (server == item.value) {
1.171 raeburn 17215: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
17216: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 17217: }
17218: }
17219: }
17220: }
17221: return;
17222: }
17223:
1.171 raeburn 17224: function singleServerToggle(balnum,type) {
17225: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 17226: if (offloadtoSelIdx == 0) {
1.171 raeburn 17227: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
17228: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 17229:
17230: } else {
1.171 raeburn 17231: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
17232: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 17233: }
17234: return;
17235: }
17236:
1.171 raeburn 17237: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 17238: if (type == '_LC_external') {
1.171 raeburn 17239: return;
1.150 raeburn 17240: }
1.171 raeburn 17241: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 17242: for (var i=0; i<typesRules.length; i++) {
17243: if (formname.elements[typesRules[i]].checked) {
17244: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 17245: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
17246: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 17247: } else {
1.171 raeburn 17248: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
17249: }
17250: }
17251: }
17252: return;
17253: }
17254:
17255: function balancerDeleteChange(balnum) {
17256: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
17257: var baltotal = document.getElementById('loadbalancing_total').value;
17258: var addtarget;
17259: var removetarget;
17260: var action = 'delete';
17261: if (document.getElementById('loadbalancing_delete_'+balnum)) {
17262: var lonhost = hostitem.value;
17263: var currIdx = currBalancers.indexOf(lonhost);
17264: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
17265: if (currIdx != -1) {
17266: currBalancers.splice(currIdx,1);
17267: }
17268: addtarget = lonhost;
17269: } else {
17270: if (currIdx == -1) {
17271: currBalancers.push(lonhost);
17272: }
17273: removetarget = lonhost;
17274: action = 'undelete';
17275: }
17276: balancerChange(balnum,baltotal,action,addtarget,removetarget);
17277: }
17278: return;
17279: }
17280:
17281: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
17282: if (baltotal > 1) {
17283: var offloadtypes = new Array('primary','default');
17284: var alltargets = new Array('$alltargets');
17285: var insttypes = new Array('$allinsttypes');
17286: for (var i=0; i<baltotal; i++) {
17287: if (i != balnum) {
17288: for (var j=0; j<offloadtypes.length; j++) {
17289: var total = alltargets.length - 1;
17290: for (var k=0; k<total; k++) {
17291: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
17292: var server = serveritem.value;
17293: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
17294: if (server == addtarget) {
17295: serveritem.disabled = '';
17296: }
17297: }
17298: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
17299: if (server == removetarget) {
17300: serveritem.disabled = 'disabled';
17301: serveritem.checked = false;
17302: }
17303: }
17304: }
17305: }
17306: for (var j=0; j<insttypes.length; j++) {
17307: if (insttypes[j] != '_LC_external') {
17308: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
17309: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
17310: var currSel = singleserver.selectedIndex;
17311: var currVal = singleserver.options[currSel].value;
17312: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
17313: var numoptions = singleserver.options.length;
17314: var needsnew = 1;
17315: for (var k=0; k<numoptions; k++) {
17316: if (singleserver.options[k] == addtarget) {
17317: needsnew = 0;
17318: break;
17319: }
17320: }
17321: if (needsnew == 1) {
17322: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
17323: }
17324: }
17325: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
17326: singleserver.options.length = 0;
17327: if ((currVal) && (currVal != removetarget)) {
17328: singleserver.options[0] = new Option("","",false,false);
17329: } else {
17330: singleserver.options[0] = new Option("","",true,true);
17331: }
17332: var idx = 0;
17333: for (var m=0; m<alltargets.length; m++) {
17334: if (currBalancers.indexOf(alltargets[m]) == -1) {
17335: idx ++;
17336: if (currVal == alltargets[m]) {
17337: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
17338: } else {
17339: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
17340: }
17341: }
17342: }
17343: }
17344: }
17345: }
17346: }
1.150 raeburn 17347: }
17348: }
17349: }
17350: return;
17351: }
17352:
1.152 raeburn 17353: // ]]>
17354: </script>
17355:
17356: END
17357: }
17358:
17359: sub new_spares_js {
17360: my @sparestypes = ('primary','default');
17361: my $types = join("','",@sparestypes);
17362: my $select = &mt('Select');
17363: return <<"END";
17364:
17365: <script type="text/javascript">
17366: // <![CDATA[
17367:
17368: function updateNewSpares(formname,lonhost) {
17369: var types = new Array('$types');
17370: var include = new Array();
17371: var exclude = new Array();
17372: for (var i=0; i<types.length; i++) {
17373: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
17374: for (var j=0; j<spareboxes.length; j++) {
17375: if (formname.elements[spareboxes[j]].checked) {
17376: exclude.push(formname.elements[spareboxes[j]].value);
17377: } else {
17378: include.push(formname.elements[spareboxes[j]].value);
17379: }
17380: }
17381: }
17382: for (var i=0; i<types.length; i++) {
17383: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
17384: var selIdx = newSpare.selectedIndex;
17385: var currnew = newSpare.options[selIdx].value;
17386: var okSpares = new Array();
17387: for (var j=0; j<newSpare.options.length; j++) {
17388: var possible = newSpare.options[j].value;
17389: if (possible != '') {
17390: if (exclude.indexOf(possible) == -1) {
17391: okSpares.push(possible);
17392: } else {
17393: if (currnew == possible) {
17394: selIdx = 0;
17395: }
17396: }
17397: }
17398: }
17399: for (var k=0; k<include.length; k++) {
17400: if (okSpares.indexOf(include[k]) == -1) {
17401: okSpares.push(include[k]);
17402: }
17403: }
17404: okSpares.sort();
17405: newSpare.options.length = 0;
17406: if (selIdx == 0) {
17407: newSpare.options[0] = new Option("$select","",true,true);
17408: } else {
17409: newSpare.options[0] = new Option("$select","",false,false);
17410: }
17411: for (var m=0; m<okSpares.length; m++) {
17412: var idx = m+1;
17413: var selThis = 0;
17414: if (selIdx != 0) {
17415: if (okSpares[m] == currnew) {
17416: selThis = 1;
17417: }
17418: }
17419: if (selThis == 1) {
17420: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
17421: } else {
17422: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
17423: }
17424: }
17425: }
17426: return;
17427: }
17428:
17429: function checkNewSpares(lonhost,type) {
17430: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
17431: var chosen = newSpare.options[newSpare.selectedIndex].value;
17432: if (chosen != '') {
17433: var othertype;
17434: var othernewSpare;
17435: if (type == 'primary') {
17436: othernewSpare = document.getElementById('newspare_default_'+lonhost);
17437: }
17438: if (type == 'default') {
17439: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
17440: }
17441: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
17442: othernewSpare.selectedIndex = 0;
17443: }
17444: }
17445: return;
17446: }
17447:
17448: // ]]>
17449: </script>
17450:
17451: END
17452:
17453: }
17454:
17455: sub common_domprefs_js {
17456: return <<"END";
17457:
17458: <script type="text/javascript">
17459: // <![CDATA[
17460:
1.150 raeburn 17461: function getIndicesByName(formname,item) {
1.152 raeburn 17462: var group = new Array();
1.150 raeburn 17463: for (var i=0;i<formname.elements.length;i++) {
17464: if (formname.elements[i].name == item) {
1.152 raeburn 17465: group.push(formname.elements[i].id);
1.150 raeburn 17466: }
17467: }
1.152 raeburn 17468: return group;
1.150 raeburn 17469: }
17470:
17471: // ]]>
17472: </script>
17473:
17474: END
1.152 raeburn 17475:
1.150 raeburn 17476: }
17477:
1.165 raeburn 17478: sub recaptcha_js {
17479: my %lt = &captcha_phrases();
17480: return <<"END";
17481:
17482: <script type="text/javascript">
17483: // <![CDATA[
17484:
17485: function updateCaptcha(caller,context) {
17486: var privitem;
17487: var pubitem;
17488: var privtext;
17489: var pubtext;
1.269 raeburn 17490: var versionitem;
17491: var versiontext;
1.165 raeburn 17492: if (document.getElementById(context+'_recaptchapub')) {
17493: pubitem = document.getElementById(context+'_recaptchapub');
17494: } else {
17495: return;
17496: }
17497: if (document.getElementById(context+'_recaptchapriv')) {
17498: privitem = document.getElementById(context+'_recaptchapriv');
17499: } else {
17500: return;
17501: }
17502: if (document.getElementById(context+'_recaptchapubtxt')) {
17503: pubtext = document.getElementById(context+'_recaptchapubtxt');
17504: } else {
17505: return;
17506: }
17507: if (document.getElementById(context+'_recaptchaprivtxt')) {
17508: privtext = document.getElementById(context+'_recaptchaprivtxt');
17509: } else {
17510: return;
17511: }
1.269 raeburn 17512: if (document.getElementById(context+'_recaptchaversion')) {
17513: versionitem = document.getElementById(context+'_recaptchaversion');
17514: } else {
17515: return;
17516: }
17517: if (document.getElementById(context+'_recaptchavertxt')) {
17518: versiontext = document.getElementById(context+'_recaptchavertxt');
17519: } else {
17520: return;
17521: }
1.165 raeburn 17522: if (caller.checked) {
17523: if (caller.value == 'recaptcha') {
17524: pubitem.type = 'text';
17525: privitem.type = 'text';
17526: pubitem.size = '40';
17527: privitem.size = '40';
17528: pubtext.innerHTML = "$lt{'pub'}";
17529: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 17530: versionitem.type = 'text';
17531: versionitem.size = '3';
1.289 raeburn 17532: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 17533: } else {
17534: pubitem.type = 'hidden';
17535: privitem.type = 'hidden';
1.269 raeburn 17536: versionitem.type = 'hidden';
1.165 raeburn 17537: pubtext.innerHTML = '';
17538: privtext.innerHTML = '';
1.269 raeburn 17539: versiontext.innerHTML = '';
1.165 raeburn 17540: }
17541: }
17542: return;
17543: }
17544:
17545: // ]]>
17546: </script>
17547:
17548: END
17549:
17550: }
17551:
1.236 raeburn 17552: sub toggle_display_js {
1.192 raeburn 17553: return <<"END";
17554:
17555: <script type="text/javascript">
17556: // <![CDATA[
17557:
1.236 raeburn 17558: function toggleDisplay(domForm,caller) {
17559: if (document.getElementById(caller)) {
17560: var divitem = document.getElementById(caller);
17561: var optionsElement = domForm.coursecredits;
1.264 raeburn 17562: var checkval = 1;
17563: var dispval = 'block';
1.303 raeburn 17564: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 17565: if (caller == 'emailoptions') {
17566: optionsElement = domForm.cancreate_email;
17567: }
1.257 raeburn 17568: if (caller == 'studentsubmission') {
17569: optionsElement = domForm.postsubmit;
17570: }
1.264 raeburn 17571: if (caller == 'cloneinstcode') {
17572: optionsElement = domForm.canclone;
17573: checkval = 'instcode';
17574: }
1.303 raeburn 17575: if (selfcreateRegExp.test(caller)) {
17576: optionsElement = domForm.elements[caller];
17577: checkval = 'other';
17578: dispval = 'inline'
17579: }
1.236 raeburn 17580: if (optionsElement.length) {
1.192 raeburn 17581: var currval;
1.236 raeburn 17582: for (var i=0; i<optionsElement.length; i++) {
17583: if (optionsElement[i].checked) {
17584: currval = optionsElement[i].value;
1.192 raeburn 17585: }
17586: }
1.264 raeburn 17587: if (currval == checkval) {
17588: divitem.style.display = dispval;
1.192 raeburn 17589: } else {
1.236 raeburn 17590: divitem.style.display = 'none';
1.192 raeburn 17591: }
17592: }
17593: }
17594: return;
17595: }
17596:
17597: // ]]>
17598: </script>
17599:
17600: END
17601:
17602: }
17603:
1.165 raeburn 17604: sub captcha_phrases {
17605: return &Apache::lonlocal::texthash (
17606: priv => 'Private key',
17607: pub => 'Public key',
17608: original => 'original (CAPTCHA)',
17609: recaptcha => 'successor (ReCAPTCHA)',
17610: notused => 'unused',
1.289 raeburn 17611: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 17612: );
17613: }
17614:
1.205 raeburn 17615: sub devalidate_remote_domconfs {
1.212 raeburn 17616: my ($dom,$cachekeys) = @_;
17617: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 17618: my %servers = &Apache::lonnet::internet_dom_servers($dom);
17619: my %thismachine;
17620: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.295 raeburn 17621: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions','directorysrch');
1.260 raeburn 17622: if (keys(%servers)) {
1.205 raeburn 17623: foreach my $server (keys(%servers)) {
17624: next if ($thismachine{$server});
1.212 raeburn 17625: my @cached;
17626: foreach my $name (@posscached) {
17627: if ($cachekeys->{$name}) {
17628: push(@cached,&escape($name).':'.&escape($dom));
17629: }
17630: }
17631: if (@cached) {
17632: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
17633: }
1.205 raeburn 17634: }
17635: }
17636: return;
17637: }
17638:
1.3 raeburn 17639: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>