Annotation of loncom/interface/domainprefs.pm, revision 1.335
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.335 ! raeburn 4: # $Id: domainprefs.pm,v 1.334 2018/07/06 22:39:57 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.334 raeburn 784: } elsif ($action eq 'ltitools') {
785: $output .= <itools_javascript($settings);
786: } elsif ($action eq 'lti') {
787: $output .= <i_javascript($settings);
1.91 raeburn 788: }
1.236 raeburn 789: $output .=
1.30 raeburn 790: '<table class="LC_nested_outer">
1.3 raeburn 791: <tr>
1.306 raeburn 792: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 793: &mt($item->{text}).' '.
794: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
795: '</tr>';
1.30 raeburn 796: $rowtotal ++;
1.110 raeburn 797: my $numheaders = 1;
798: if (ref($item->{'header'}) eq 'ARRAY') {
799: $numheaders = scalar(@{$item->{'header'}});
800: }
801: if ($numheaders > 1) {
1.64 raeburn 802: my $colspan = '';
1.145 raeburn 803: my $rightcolspan = '';
1.238 raeburn 804: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 805: ($action eq 'directorysrch') ||
1.256 raeburn 806: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 807: $colspan = ' colspan="2"';
808: }
1.145 raeburn 809: if ($action eq 'usersessions') {
810: $rightcolspan = ' colspan="3"';
811: }
1.30 raeburn 812: $output .= '
1.3 raeburn 813: <tr>
814: <td>
815: <table class="LC_nested">
816: <tr class="LC_info_row">
1.59 bisitz 817: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 818: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 819: </tr>';
1.69 raeburn 820: $rowtotal ++;
1.230 raeburn 821: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 822: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 823: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 824: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
825: ($action eq 'contacts')) {
1.230 raeburn 826: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 827: } elsif ($action eq 'coursecategories') {
1.230 raeburn 828: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 829: } elsif ($action eq 'login') {
1.256 raeburn 830: if ($numheaders == 4) {
1.168 raeburn 831: $colspan = ' colspan="2"';
832: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
833: } else {
834: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
835: }
1.230 raeburn 836: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 837: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 838: } elsif ($action eq 'rolecolors') {
1.30 raeburn 839: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 840: }
1.30 raeburn 841: $output .= '
1.6 raeburn 842: </table>
843: </td>
844: </tr>
845: <tr>
846: <td>
847: <table class="LC_nested">
848: <tr class="LC_info_row">
1.230 raeburn 849: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 850: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 851: </tr>';
852: $rowtotal ++;
1.230 raeburn 853: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
854: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 855: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.294 raeburn 856: ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults')) {
1.238 raeburn 857: if ($action eq 'coursecategories') {
858: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
859: $colspan = ' colspan="2"';
1.279 raeburn 860: } elsif ($action eq 'trust') {
861: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.238 raeburn 862: } else {
863: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
864: }
1.279 raeburn 865: if ($action eq 'trust') {
866: $output .= '
867: </table>
868: </td>
869: </tr>';
870: my @trusthdrs = qw(2 3 4 5 6 7);
871: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
872: for (my $i=0; $i<@trusthdrs; $i++) {
873: $output .= '
874: <tr>
875: <td>
876: <table class="LC_nested">
877: <tr class="LC_info_row">
878: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
879: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
880: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
881: </table>
882: </td>
883: </tr>';
884: }
885: $output .= '
886: <tr>
887: <td>
888: <table class="LC_nested">
889: <tr class="LC_info_row">
890: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
891: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
892: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
893: } else {
894: $output .= '
1.63 raeburn 895: </table>
896: </td>
897: </tr>
898: <tr>
899: <td>
900: <table class="LC_nested">
901: <tr class="LC_info_row">
902: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 903: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 904: </tr>'."\n";
1.279 raeburn 905: if ($action eq 'coursecategories') {
906: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
907: } else {
908: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
909: }
1.238 raeburn 910: }
1.63 raeburn 911: $rowtotal ++;
1.236 raeburn 912: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.282 raeburn 913: ($action eq 'defaults') || ($action eq 'directorysrch') ||
914: ($action eq 'helpsettings')) {
1.230 raeburn 915: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.293 raeburn 916: } elsif ($action eq 'ssl') {
917: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
918: </table>
919: </td>
920: </tr>
921: <tr>
922: <td>
923: <table class="LC_nested">
924: <tr class="LC_info_row">
925: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
926: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
927: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
928: </table>
929: </td>
930: </tr>
931: <tr>
932: <td>
933: <table class="LC_nested">
934: <tr class="LC_info_row">
935: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
936: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
937: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 938: } elsif ($action eq 'login') {
1.256 raeburn 939: if ($numheaders == 4) {
1.168 raeburn 940: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
941: </table>
942: </td>
943: </tr>
944: <tr>
945: <td>
946: <table class="LC_nested">
947: <tr class="LC_info_row">
948: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 949: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 950: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
951: $rowtotal ++;
952: } else {
953: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
954: }
1.256 raeburn 955: $output .= '
956: </table>
957: </td>
958: </tr>
959: <tr>
960: <td>
961: <table class="LC_nested">
962: <tr class="LC_info_row">';
963: if ($numheaders == 4) {
964: $output .= '
965: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
966: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
967: </tr>';
968: } else {
969: $output .= '
970: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
971: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
972: </tr>';
973: }
974: $rowtotal ++;
975: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 976: } elsif ($action eq 'requestcourses') {
1.247 raeburn 977: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
978: $rowtotal ++;
979: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 980: </table>
981: </td>
982: </tr>
983: <tr>
984: <td>
985: <table class="LC_nested">
986: <tr class="LC_info_row">
987: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
988: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 989: &textbookcourses_javascript($settings).
990: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
991: </table>
992: </td>
993: </tr>
994: <tr>
995: <td>
996: <table class="LC_nested">
997: <tr class="LC_info_row">
998: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
999: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1000: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 1001: </table>
1002: </td>
1003: </tr>
1004: <tr>
1005: <td>
1006: <table class="LC_nested">
1007: <tr class="LC_info_row">
1.306 raeburn 1008: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1009: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1010: </tr>'.
1011: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1012: } elsif ($action eq 'requestauthor') {
1013: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1014: $rowtotal ++;
1.122 jms 1015: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1016: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1017: </table>
1018: </td>
1019: </tr>
1020: <tr>
1021: <td>
1022: <table class="LC_nested">
1023: <tr class="LC_info_row">
1.306 raeburn 1024: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 1025: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1026: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1027: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1028: </tr>'.
1.30 raeburn 1029: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1030: </table>
1031: </td>
1032: </tr>
1033: <tr>
1034: <td>
1035: <table class="LC_nested">
1036: <tr class="LC_info_row">
1.59 bisitz 1037: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1038: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1039: </tr>'.
1.30 raeburn 1040: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1041: $rowtotal += 2;
1.6 raeburn 1042: }
1.3 raeburn 1043: } else {
1.30 raeburn 1044: $output .= '
1.3 raeburn 1045: <tr>
1046: <td>
1047: <table class="LC_nested">
1.30 raeburn 1048: <tr class="LC_info_row">';
1.277 raeburn 1049: if ($action eq 'login') {
1.30 raeburn 1050: $output .= '
1.59 bisitz 1051: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1052: } elsif ($action eq 'serverstatuses') {
1053: $output .= '
1.306 raeburn 1054: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1055: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1056:
1.6 raeburn 1057: } else {
1.30 raeburn 1058: $output .= '
1.306 raeburn 1059: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1060: }
1.72 raeburn 1061: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1062: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1063: &mt($item->{'header'}->[0]->{'col2'});
1064: if ($action eq 'serverstatuses') {
1065: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1066: }
1.69 raeburn 1067: } else {
1.306 raeburn 1068: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1069: &mt($item->{'header'}->[0]->{'col2'});
1070: }
1071: $output .= '</td>';
1072: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1073: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1074: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1075: &mt($item->{'header'}->[0]->{'col3'});
1076: } else {
1.306 raeburn 1077: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1078: &mt($item->{'header'}->[0]->{'col3'});
1079: }
1.69 raeburn 1080: if ($action eq 'serverstatuses') {
1081: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1082: }
1083: $output .= '</td>';
1.6 raeburn 1084: }
1.150 raeburn 1085: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1086: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1087: &mt($item->{'header'}->[0]->{'col4'});
1088: }
1.69 raeburn 1089: $output .= '</tr>';
1.48 raeburn 1090: $rowtotal ++;
1.168 raeburn 1091: if ($action eq 'quotas') {
1.86 raeburn 1092: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1093: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1094: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.320 raeburn 1095: ($action eq 'ltitools') || ($action eq 'lti')) {
1.230 raeburn 1096: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 1097: } elsif ($action eq 'scantron') {
1098: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.121 raeburn 1099: }
1.3 raeburn 1100: }
1.30 raeburn 1101: $output .= '
1.3 raeburn 1102: </table>
1103: </td>
1104: </tr>
1.30 raeburn 1105: </table><br />';
1106: return ($output,$rowtotal);
1.1 raeburn 1107: }
1108:
1.3 raeburn 1109: sub print_login {
1.168 raeburn 1110: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 1111: my ($css_class,$datatable);
1.6 raeburn 1112: my %choices = &login_choices();
1.110 raeburn 1113:
1.168 raeburn 1114: if ($caller eq 'service') {
1.149 raeburn 1115: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1116: my $choice = $choices{'disallowlogin'};
1117: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1118: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1119: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1120: '<th>'.$choices{'server'}.'</th>'.
1121: '<th>'.$choices{'serverpath'}.'</th>'.
1122: '<th>'.$choices{'custompath'}.'</th>'.
1123: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1124: my %disallowed;
1125: if (ref($settings) eq 'HASH') {
1126: if (ref($settings->{'loginvia'}) eq 'HASH') {
1127: %disallowed = %{$settings->{'loginvia'}};
1128: }
1129: }
1130: foreach my $lonhost (sort(keys(%servers))) {
1131: my $direct = 'selected="selected"';
1.128 raeburn 1132: if (ref($disallowed{$lonhost}) eq 'HASH') {
1133: if ($disallowed{$lonhost}{'server'} ne '') {
1134: $direct = '';
1135: }
1.110 raeburn 1136: }
1.115 raeburn 1137: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1138: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1139: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1140: '</option>';
1.184 raeburn 1141: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1142: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1143: my $selected = '';
1.128 raeburn 1144: if (ref($disallowed{$lonhost}) eq 'HASH') {
1145: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1146: $selected = 'selected="selected"';
1147: }
1.110 raeburn 1148: }
1149: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1150: $servers{$hostid}.'</option>';
1151: }
1.128 raeburn 1152: $datatable .= '</select></td>'.
1153: '<td><select name="'.$lonhost.'_serverpath">';
1154: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1155: my $pathname = $path;
1156: if ($path eq 'custom') {
1157: $pathname = &mt('Custom Path').' ->';
1158: }
1159: my $selected = '';
1160: if (ref($disallowed{$lonhost}) eq 'HASH') {
1161: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1162: $selected = 'selected="selected"';
1163: }
1164: } elsif ($path eq '') {
1165: $selected = 'selected="selected"';
1166: }
1167: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1168: }
1169: $datatable .= '</select></td>';
1170: my ($custom,$exempt);
1171: if (ref($disallowed{$lonhost}) eq 'HASH') {
1172: $custom = $disallowed{$lonhost}{'custompath'};
1173: $exempt = $disallowed{$lonhost}{'exempt'};
1174: }
1175: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1176: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1177: '</tr>';
1.110 raeburn 1178: }
1179: $datatable .= '</table></td></tr>';
1180: return $datatable;
1.168 raeburn 1181: } elsif ($caller eq 'page') {
1182: my %defaultchecked = (
1183: 'coursecatalog' => 'on',
1.188 raeburn 1184: 'helpdesk' => 'on',
1.168 raeburn 1185: 'adminmail' => 'off',
1186: 'newuser' => 'off',
1187: );
1.188 raeburn 1188: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1189: my (%checkedon,%checkedoff);
1.42 raeburn 1190: foreach my $item (@toggles) {
1.168 raeburn 1191: if ($defaultchecked{$item} eq 'on') {
1192: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1193: $checkedoff{$item} = ' ';
1.168 raeburn 1194: } elsif ($defaultchecked{$item} eq 'off') {
1195: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1196: $checkedon{$item} = ' ';
1197: }
1.1 raeburn 1198: }
1.168 raeburn 1199: my @images = ('img','logo','domlogo','login');
1200: my @logintext = ('textcol','bgcol');
1201: my @bgs = ('pgbg','mainbg','sidebg');
1202: my @links = ('link','alink','vlink');
1203: my %designhash = &Apache::loncommon::get_domainconf($dom);
1204: my %defaultdesign = %Apache::loncommon::defaultdesign;
1205: my (%is_custom,%designs);
1206: my %defaults = (
1207: font => $defaultdesign{'login.font'},
1208: );
1.6 raeburn 1209: foreach my $item (@images) {
1.168 raeburn 1210: $defaults{$item} = $defaultdesign{'login.'.$item};
1211: $defaults{'showlogo'}{$item} = 1;
1212: }
1213: foreach my $item (@bgs) {
1214: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1215: }
1.41 raeburn 1216: foreach my $item (@logintext) {
1.168 raeburn 1217: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1218: }
1.168 raeburn 1219: foreach my $item (@links) {
1220: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1221: }
1.168 raeburn 1222: if (ref($settings) eq 'HASH') {
1223: foreach my $item (@toggles) {
1224: if ($settings->{$item} eq '1') {
1225: $checkedon{$item} = ' checked="checked" ';
1226: $checkedoff{$item} = ' ';
1227: } elsif ($settings->{$item} eq '0') {
1228: $checkedoff{$item} = ' checked="checked" ';
1229: $checkedon{$item} = ' ';
1230: }
1231: }
1232: foreach my $item (@images) {
1233: if (defined($settings->{$item})) {
1234: $designs{$item} = $settings->{$item};
1235: $is_custom{$item} = 1;
1236: }
1237: if (defined($settings->{'showlogo'}{$item})) {
1238: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1239: }
1240: }
1241: foreach my $item (@logintext) {
1242: if ($settings->{$item} ne '') {
1243: $designs{'logintext'}{$item} = $settings->{$item};
1244: $is_custom{$item} = 1;
1245: }
1246: }
1247: if ($settings->{'font'} ne '') {
1248: $designs{'font'} = $settings->{'font'};
1249: $is_custom{'font'} = 1;
1250: }
1251: foreach my $item (@bgs) {
1252: if ($settings->{$item} ne '') {
1253: $designs{'bgs'}{$item} = $settings->{$item};
1254: $is_custom{$item} = 1;
1255: }
1256: }
1257: foreach my $item (@links) {
1258: if ($settings->{$item} ne '') {
1259: $designs{'links'}{$item} = $settings->{$item};
1260: $is_custom{$item} = 1;
1261: }
1262: }
1263: } else {
1264: if ($designhash{$dom.'.login.font'} ne '') {
1265: $designs{'font'} = $designhash{$dom.'.login.font'};
1266: $is_custom{'font'} = 1;
1267: }
1268: foreach my $item (@images) {
1269: if ($designhash{$dom.'.login.'.$item} ne '') {
1270: $designs{$item} = $designhash{$dom.'.login.'.$item};
1271: $is_custom{$item} = 1;
1272: }
1273: }
1274: foreach my $item (@bgs) {
1275: if ($designhash{$dom.'.login.'.$item} ne '') {
1276: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1277: $is_custom{$item} = 1;
1278: }
1.6 raeburn 1279: }
1.168 raeburn 1280: foreach my $item (@links) {
1281: if ($designhash{$dom.'.login.'.$item} ne '') {
1282: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1283: $is_custom{$item} = 1;
1284: }
1.6 raeburn 1285: }
1286: }
1.168 raeburn 1287: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1288: logo => 'Institution Logo',
1289: domlogo => 'Domain Logo',
1290: login => 'Login box');
1291: my $itemcount = 1;
1292: foreach my $item (@toggles) {
1293: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1294: $datatable .=
1295: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1296: '</td><td>'.
1297: '<span class="LC_nobreak"><label><input type="radio" name="'.
1298: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1299: '</label> <label><input type="radio" name="'.$item.'"'.
1300: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1301: '</tr>';
1302: $itemcount ++;
1.6 raeburn 1303: }
1.168 raeburn 1304: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1305: $datatable .= '</tr></table></td></tr>';
1306: } elsif ($caller eq 'help') {
1307: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1308: my $switchserver = &check_switchserver($dom,$confname);
1309: my $itemcount = 1;
1310: $defaulturl = '/adm/loginproblems.html';
1311: $defaulttype = 'default';
1312: %lt = &Apache::lonlocal::texthash (
1313: del => 'Delete?',
1314: rep => 'Replace:',
1315: upl => 'Upload:',
1316: default => 'Default',
1317: custom => 'Custom',
1318: );
1319: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1320: my @currlangs;
1321: if (ref($settings) eq 'HASH') {
1322: if (ref($settings->{'helpurl'}) eq 'HASH') {
1323: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1324: next if ($settings->{'helpurl'}{$key} eq '');
1325: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1326: $type{$key} = 'custom';
1327: unless ($key eq 'nolang') {
1328: push(@currlangs,$key);
1329: }
1330: }
1331: } elsif ($settings->{'helpurl'} ne '') {
1332: $type{'nolang'} = 'custom';
1333: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1334: }
1335: }
1.168 raeburn 1336: foreach my $lang ('nolang',sort(@currlangs)) {
1337: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1338: $datatable .= '<tr'.$css_class.'>';
1339: if ($url{$lang} eq '') {
1340: $url{$lang} = $defaulturl;
1341: }
1342: if ($type{$lang} eq '') {
1343: $type{$lang} = $defaulttype;
1344: }
1345: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1346: if ($lang eq 'nolang') {
1347: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1348: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1349: } else {
1350: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1351: $langchoices{$lang},
1352: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1353: }
1354: $datatable .= '</span></td>'."\n".
1355: '<td class="LC_left_item">';
1356: if ($type{$lang} eq 'custom') {
1357: $datatable .= '<span class="LC_nobreak"><label>'.
1358: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1359: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1360: } else {
1361: $datatable .= $lt{'upl'};
1362: }
1363: $datatable .='<br />';
1364: if ($switchserver) {
1365: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1366: } else {
1367: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1368: }
1.168 raeburn 1369: $datatable .= '</td></tr>';
1370: $itemcount ++;
1.6 raeburn 1371: }
1.168 raeburn 1372: my @addlangs;
1373: foreach my $lang (sort(keys(%langchoices))) {
1374: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1375: push(@addlangs,$lang);
1376: }
1377: if (@addlangs > 0) {
1378: my %toadd;
1379: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1380: $toadd{''} = &mt('Select');
1381: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1382: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1383: &mt('Add log-in help page for a specific language:').' '.
1384: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1385: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1386: if ($switchserver) {
1387: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1388: } else {
1389: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1390: }
1.168 raeburn 1391: $datatable .= '</td></tr>';
1.169 raeburn 1392: $itemcount ++;
1.6 raeburn 1393: }
1.169 raeburn 1394: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1395: } elsif ($caller eq 'headtag') {
1396: my %domservers = &Apache::lonnet::get_servers($dom);
1397: my $choice = $choices{'headtag'};
1398: $css_class = ' class="LC_odd_row"';
1399: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1400: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1401: '<th>'.$choices{'current'}.'</th>'.
1402: '<th>'.$choices{'action'}.'</th>'.
1403: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1404: my (%currurls,%currexempt);
1405: if (ref($settings) eq 'HASH') {
1406: if (ref($settings->{'headtag'}) eq 'HASH') {
1407: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1408: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1409: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1410: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1411: }
1412: }
1413: }
1414: }
1415: my %lt = &Apache::lonlocal::texthash(
1416: del => 'Delete?',
1417: rep => 'Replace:',
1418: upl => 'Upload:',
1419: curr => 'View contents',
1420: none => 'None',
1421: );
1422: my $switchserver = &check_switchserver($dom,$confname);
1423: foreach my $lonhost (sort(keys(%domservers))) {
1424: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1425: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1426: if ($currurls{$lonhost}) {
1427: $datatable .= '<td class="LC_right_item"><a href="'.
1428: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1429: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1430: '">'.$lt{'curr'}.'</a></td>'.
1431: '<td><span class="LC_nobreak"><label>'.
1432: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1433: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1434: } else {
1435: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1436: }
1437: $datatable .='<br />';
1438: if ($switchserver) {
1439: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1440: } else {
1441: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1442: }
1.330 raeburn 1443: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256 raeburn 1444: }
1445: $datatable .= '</table></td></tr>';
1.1 raeburn 1446: }
1.6 raeburn 1447: return $datatable;
1448: }
1449:
1450: sub login_choices {
1451: my %choices =
1452: &Apache::lonlocal::texthash (
1.116 bisitz 1453: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1454: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1455: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1456: disallowlogin => "Login page requests redirected",
1457: hostid => "Server",
1.128 raeburn 1458: server => "Redirect to:",
1459: serverpath => "Path",
1460: custompath => "Custom",
1461: exempt => "Exempt IP(s)",
1.110 raeburn 1462: directlogin => "No redirect",
1463: newuser => "Link to create a user account",
1464: img => "Header",
1465: logo => "Main Logo",
1466: domlogo => "Domain Logo",
1467: login => "Log-in Header",
1468: textcol => "Text color",
1469: bgcol => "Box color",
1470: bgs => "Background colors",
1471: links => "Link colors",
1472: font => "Font color",
1473: pgbg => "Header",
1474: mainbg => "Page",
1475: sidebg => "Login box",
1476: link => "Link",
1477: alink => "Active link",
1478: vlink => "Visited link",
1.256 raeburn 1479: headtag => "Custom markup",
1480: action => "Action",
1481: current => "Current",
1.6 raeburn 1482: );
1483: return %choices;
1484: }
1485:
1486: sub print_rolecolors {
1.30 raeburn 1487: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1488: my %choices = &color_font_choices();
1489: my @bgs = ('pgbg','tabbg','sidebg');
1490: my @links = ('link','alink','vlink');
1491: my @images = ('img');
1492: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1493: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1494: my %defaultdesign = %Apache::loncommon::defaultdesign;
1495: my (%is_custom,%designs);
1.200 raeburn 1496: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1497: if (ref($settings) eq 'HASH') {
1498: if (ref($settings->{$role}) eq 'HASH') {
1499: if ($settings->{$role}->{'img'} ne '') {
1500: $designs{'img'} = $settings->{$role}->{'img'};
1501: $is_custom{'img'} = 1;
1502: }
1503: if ($settings->{$role}->{'font'} ne '') {
1504: $designs{'font'} = $settings->{$role}->{'font'};
1505: $is_custom{'font'} = 1;
1506: }
1.97 tempelho 1507: if ($settings->{$role}->{'fontmenu'} ne '') {
1508: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1509: $is_custom{'fontmenu'} = 1;
1510: }
1.6 raeburn 1511: foreach my $item (@bgs) {
1512: if ($settings->{$role}->{$item} ne '') {
1513: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1514: $is_custom{$item} = 1;
1515: }
1516: }
1517: foreach my $item (@links) {
1518: if ($settings->{$role}->{$item} ne '') {
1519: $designs{'links'}{$item} = $settings->{$role}->{$item};
1520: $is_custom{$item} = 1;
1521: }
1522: }
1523: }
1524: } else {
1525: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1526: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1527: $is_custom{'img'} = 1;
1528: }
1.97 tempelho 1529: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1530: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1531: $is_custom{'fontmenu'} = 1;
1532: }
1.6 raeburn 1533: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1534: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1535: $is_custom{'font'} = 1;
1536: }
1537: foreach my $item (@bgs) {
1538: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1539: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1540: $is_custom{$item} = 1;
1541:
1542: }
1543: }
1544: foreach my $item (@links) {
1545: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1546: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1547: $is_custom{$item} = 1;
1548: }
1549: }
1550: }
1551: my $itemcount = 1;
1.30 raeburn 1552: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1553: $datatable .= '</tr></table></td></tr>';
1554: return $datatable;
1555: }
1556:
1.200 raeburn 1557: sub role_defaults {
1558: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1559: my %defaults;
1560: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1561: return %defaults;
1562: }
1563: my %defaultdesign = %Apache::loncommon::defaultdesign;
1564: if ($role eq 'login') {
1565: %defaults = (
1566: font => $defaultdesign{$role.'.font'},
1567: );
1568: if (ref($logintext) eq 'ARRAY') {
1569: foreach my $item (@{$logintext}) {
1570: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1571: }
1572: }
1573: foreach my $item (@{$images}) {
1574: $defaults{'showlogo'}{$item} = 1;
1575: }
1576: } else {
1577: %defaults = (
1578: img => $defaultdesign{$role.'.img'},
1579: font => $defaultdesign{$role.'.font'},
1580: fontmenu => $defaultdesign{$role.'.fontmenu'},
1581: );
1582: }
1583: foreach my $item (@{$bgs}) {
1584: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1585: }
1586: foreach my $item (@{$links}) {
1587: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1588: }
1589: foreach my $item (@{$images}) {
1590: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1591: }
1592: return %defaults;
1593: }
1594:
1.6 raeburn 1595: sub display_color_options {
1.9 raeburn 1596: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1597: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1598: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1599: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1600: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1601: '<td>'.$choices->{'font'}.'</td>';
1602: if (!$is_custom->{'font'}) {
1.329 raeburn 1603: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1604: } else {
1605: $datatable .= '<td> </td>';
1606: }
1.174 foxr 1607: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1608:
1.8 raeburn 1609: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1610: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1611: ' value="'.$current_color.'" /> '.
1.329 raeburn 1612: ' </span></td></tr>';
1.107 raeburn 1613: unless ($role eq 'login') {
1614: $datatable .= '<tr'.$css_class.'>'.
1615: '<td>'.$choices->{'fontmenu'}.'</td>';
1616: if (!$is_custom->{'fontmenu'}) {
1.329 raeburn 1617: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 1618: } else {
1619: $datatable .= '<td> </td>';
1620: }
1.202 raeburn 1621: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1622: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1623: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1624: '<input class="colorchooser" type="text" size="10" name="'
1625: .$role.'_fontmenu"'.
1626: ' value="'.$current_color.'" /> '.
1.329 raeburn 1627: ' </span></td></tr>';
1.97 tempelho 1628: }
1.9 raeburn 1629: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1630: foreach my $img (@{$images}) {
1.18 albertel 1631: $itemcount ++;
1.6 raeburn 1632: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1633: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1634: '<td>'.$choices->{$img};
1.41 raeburn 1635: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1636: if ($role eq 'login') {
1637: if ($img eq 'login') {
1638: $login_hdr_pick =
1.135 bisitz 1639: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1640: $logincolors =
1641: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1642: $designs,$defaults);
1.70 raeburn 1643: } elsif ($img ne 'domlogo') {
1644: $datatable.= &logo_display_options($img,$defaults,$designs);
1645: }
1646: }
1647: $datatable .= '</td>';
1.6 raeburn 1648: if ($designs->{$img} ne '') {
1649: $imgfile = $designs->{$img};
1.18 albertel 1650: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1651: } else {
1652: $imgfile = $defaults->{$img};
1653: }
1654: if ($imgfile) {
1.9 raeburn 1655: my ($showfile,$fullsize);
1656: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1657: my $urldir = $1;
1658: my $filename = $2;
1659: my @info = &Apache::lonnet::stat_file($designs->{$img});
1660: if (@info) {
1661: my $thumbfile = 'tn-'.$filename;
1662: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1663: if (@thumb) {
1664: $showfile = $urldir.'/'.$thumbfile;
1665: } else {
1666: $showfile = $imgfile;
1667: }
1668: } else {
1669: $showfile = '';
1670: }
1671: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1672: $showfile = $imgfile;
1.6 raeburn 1673: my $imgdir = $1;
1674: my $filename = $2;
1.159 raeburn 1675: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1676: $showfile = "/$imgdir/tn-".$filename;
1677: } else {
1.159 raeburn 1678: my $input = $londocroot.$imgfile;
1679: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1680: if (!-e $output) {
1.9 raeburn 1681: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1682: my ($fullwidth,$fullheight) = &check_dimensions($input);
1683: if ($fullwidth ne '' && $fullheight ne '') {
1684: if ($fullwidth > $width && $fullheight > $height) {
1685: my $size = $width.'x'.$height;
1.316 raeburn 1686: my @args = ('convert','-sample',$size,$input,$output);
1687: system({$args[0]} @args);
1.159 raeburn 1688: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1689: }
1690: }
1.6 raeburn 1691: }
1692: }
1.16 raeburn 1693: }
1.6 raeburn 1694: if ($showfile) {
1.40 raeburn 1695: if ($showfile =~ m{^/(adm|res)/}) {
1696: if ($showfile =~ m{^/res/}) {
1697: my $local_showfile =
1698: &Apache::lonnet::filelocation('',$showfile);
1699: &Apache::lonnet::repcopy($local_showfile);
1700: }
1701: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1702: }
1703: if ($imgfile) {
1704: if ($imgfile =~ m{^/(adm|res)/}) {
1705: if ($imgfile =~ m{^/res/}) {
1706: my $local_imgfile =
1707: &Apache::lonnet::filelocation('',$imgfile);
1708: &Apache::lonnet::repcopy($local_imgfile);
1709: }
1710: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1711: } else {
1712: $fullsize = $imgfile;
1713: }
1714: }
1.41 raeburn 1715: $datatable .= '<td>';
1716: if ($img eq 'login') {
1.135 bisitz 1717: $datatable .= $login_hdr_pick;
1718: }
1.41 raeburn 1719: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1720: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1721: } else {
1.201 raeburn 1722: $datatable .= '<td> </td><td class="LC_left_item">'.
1723: &mt('Upload:').'<br />';
1.6 raeburn 1724: }
1725: } else {
1.201 raeburn 1726: $datatable .= '<td> </td><td class="LC_left_item">'.
1727: &mt('Upload:').'<br />';
1.6 raeburn 1728: }
1.9 raeburn 1729: if ($switchserver) {
1730: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1731: } else {
1.135 bisitz 1732: if ($img ne 'login') { # suppress file selection for Log-in header
1733: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1734: }
1.9 raeburn 1735: }
1736: $datatable .= '</td></tr>';
1.6 raeburn 1737: }
1738: $itemcount ++;
1739: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1740: $datatable .= '<tr'.$css_class.'>'.
1741: '<td>'.$choices->{'bgs'}.'</td>';
1742: my $bgs_def;
1743: foreach my $item (@{$bgs}) {
1744: if (!$is_custom->{$item}) {
1.329 raeburn 1745: $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 1746: }
1747: }
1748: if ($bgs_def) {
1.8 raeburn 1749: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1750: } else {
1751: $datatable .= '<td> </td>';
1752: }
1753: $datatable .= '<td class="LC_right_item">'.
1754: '<table border="0"><tr>';
1.174 foxr 1755:
1.6 raeburn 1756: foreach my $item (@{$bgs}) {
1.306 raeburn 1757: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 1758: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1759: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1760: $datatable .= ' ';
1.6 raeburn 1761: }
1.174 foxr 1762: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1763: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1764: }
1765: $datatable .= '</tr></table></td></tr>';
1766: $itemcount ++;
1767: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1768: $datatable .= '<tr'.$css_class.'>'.
1769: '<td>'.$choices->{'links'}.'</td>';
1770: my $links_def;
1771: foreach my $item (@{$links}) {
1772: if (!$is_custom->{$item}) {
1.329 raeburn 1773: $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 1774: }
1775: }
1776: if ($links_def) {
1.8 raeburn 1777: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1778: } else {
1779: $datatable .= '<td> </td>';
1780: }
1781: $datatable .= '<td class="LC_right_item">'.
1782: '<table border="0"><tr>';
1783: foreach my $item (@{$links}) {
1.234 raeburn 1784: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 1785: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 1786: if ($designs->{'links'}{$item}) {
1.174 foxr 1787: $datatable.=' ';
1.6 raeburn 1788: }
1.174 foxr 1789: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1790: '" /></td>';
1791: }
1.30 raeburn 1792: $$rowtotal += $itemcount;
1.3 raeburn 1793: return $datatable;
1794: }
1795:
1.70 raeburn 1796: sub logo_display_options {
1797: my ($img,$defaults,$designs) = @_;
1798: my $checkedon;
1799: if (ref($defaults) eq 'HASH') {
1800: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1801: if ($defaults->{'showlogo'}{$img}) {
1802: $checkedon = 'checked="checked" ';
1803: }
1804: }
1805: }
1806: if (ref($designs) eq 'HASH') {
1807: if (ref($designs->{'showlogo'}) eq 'HASH') {
1808: if (defined($designs->{'showlogo'}{$img})) {
1809: if ($designs->{'showlogo'}{$img} == 0) {
1810: $checkedon = '';
1811: } elsif ($designs->{'showlogo'}{$img} == 1) {
1812: $checkedon = 'checked="checked" ';
1813: }
1814: }
1815: }
1816: }
1817: return '<br /><label> <input type="checkbox" name="'.
1818: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1819: &mt('show').'</label>'."\n";
1820: }
1821:
1.41 raeburn 1822: sub login_header_options {
1.135 bisitz 1823: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1824: my $output = '';
1.41 raeburn 1825: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1826: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1827: if (!$is_custom->{'textcol'}) {
1828: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1829: ' ';
1830: }
1831: if (!$is_custom->{'bgcol'}) {
1832: $output .= $choices->{'bgcol'}.': '.
1833: '<span id="css_'.$role.'_font" style="background-color: '.
1834: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1835: }
1836: $output .= '<br />';
1837: }
1838: $output .='<br />';
1839: return $output;
1840: }
1841:
1842: sub login_text_colors {
1.201 raeburn 1843: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1844: my $color_menu = '<table border="0"><tr>';
1845: foreach my $item (@{$logintext}) {
1.306 raeburn 1846: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 1847: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1848: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1849: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1850: }
1851: $color_menu .= '</tr></table><br />';
1852: return $color_menu;
1853: }
1854:
1855: sub image_changes {
1856: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1857: my $output;
1.135 bisitz 1858: if ($img eq 'login') {
1.331 raeburn 1859: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 1860: } elsif (!$is_custom) {
1.70 raeburn 1861: if ($img ne 'domlogo') {
1.331 raeburn 1862: $output = &mt('Default image:').'<br />';
1.41 raeburn 1863: } else {
1.331 raeburn 1864: $output = &mt('Default in use:').'<br />';
1.41 raeburn 1865: }
1866: }
1.331 raeburn 1867: if ($img ne 'login') {
1.135 bisitz 1868: if ($img_import) {
1869: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1870: }
1871: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1872: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1873: if ($is_custom) {
1874: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1875: '<input type="checkbox" name="'.
1876: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1877: '</label> '.&mt('Replace:').'</span><br />';
1878: } else {
1.306 raeburn 1879: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1880: }
1.41 raeburn 1881: }
1882: return $output;
1883: }
1884:
1.3 raeburn 1885: sub print_quotas {
1.86 raeburn 1886: my ($dom,$settings,$rowtotal,$action) = @_;
1887: my $context;
1888: if ($action eq 'quotas') {
1889: $context = 'tools';
1890: } else {
1891: $context = $action;
1892: }
1.197 raeburn 1893: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1894: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1895: my $typecount = 0;
1.101 raeburn 1896: my ($css_class,%titles);
1.86 raeburn 1897: if ($context eq 'requestcourses') {
1.325 raeburn 1898: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 1899: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1900: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1901: %titles = &courserequest_titles();
1.163 raeburn 1902: } elsif ($context eq 'requestauthor') {
1903: @usertools = ('author');
1904: @options = ('norequest','approval','automatic');
1.210 raeburn 1905: %titles = &authorrequest_titles();
1.86 raeburn 1906: } else {
1.162 raeburn 1907: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1908: %titles = &tool_titles();
1.86 raeburn 1909: }
1.26 raeburn 1910: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1911: foreach my $type (@{$types}) {
1.197 raeburn 1912: my ($currdefquota,$currauthorquota);
1.163 raeburn 1913: unless (($context eq 'requestcourses') ||
1914: ($context eq 'requestauthor')) {
1.86 raeburn 1915: if (ref($settings) eq 'HASH') {
1916: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1917: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1918: } else {
1919: $currdefquota = $settings->{$type};
1920: }
1.197 raeburn 1921: if (ref($settings->{authorquota}) eq 'HASH') {
1922: $currauthorquota = $settings->{authorquota}->{$type};
1923: }
1.78 raeburn 1924: }
1.72 raeburn 1925: }
1.3 raeburn 1926: if (defined($usertypes->{$type})) {
1927: $typecount ++;
1928: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1929: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1930: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1931: '<td class="LC_left_item">';
1.101 raeburn 1932: if ($context eq 'requestcourses') {
1933: $datatable .= '<table><tr>';
1934: }
1935: my %cell;
1.72 raeburn 1936: foreach my $item (@usertools) {
1.101 raeburn 1937: if ($context eq 'requestcourses') {
1938: my ($curroption,$currlimit);
1939: if (ref($settings) eq 'HASH') {
1940: if (ref($settings->{$item}) eq 'HASH') {
1941: $curroption = $settings->{$item}->{$type};
1942: if ($curroption =~ /^autolimit=(\d*)$/) {
1943: $currlimit = $1;
1944: }
1945: }
1946: }
1947: if (!$curroption) {
1948: $curroption = 'norequest';
1949: }
1950: $datatable .= '<th>'.$titles{$item}.'</th>';
1951: foreach my $option (@options) {
1952: my $val = $option;
1953: if ($option eq 'norequest') {
1954: $val = 0;
1955: }
1956: if ($option eq 'validate') {
1957: my $canvalidate = 0;
1958: if (ref($validations{$item}) eq 'HASH') {
1959: if ($validations{$item}{$type}) {
1960: $canvalidate = 1;
1961: }
1962: }
1963: next if (!$canvalidate);
1964: }
1965: my $checked = '';
1966: if ($option eq $curroption) {
1967: $checked = ' checked="checked"';
1968: } elsif ($option eq 'autolimit') {
1969: if ($curroption =~ /^autolimit/) {
1970: $checked = ' checked="checked"';
1971: }
1972: }
1973: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1974: '<input type="radio" name="crsreq_'.$item.
1975: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1976: $titles{$option}.'</label>';
1.101 raeburn 1977: if ($option eq 'autolimit') {
1.127 raeburn 1978: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1979: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1980: 'value="'.$currlimit.'" />';
1.101 raeburn 1981: }
1.127 raeburn 1982: $cell{$item} .= '</span> ';
1.103 raeburn 1983: if ($option eq 'autolimit') {
1.127 raeburn 1984: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1985: }
1.101 raeburn 1986: }
1.163 raeburn 1987: } elsif ($context eq 'requestauthor') {
1988: my $curroption;
1989: if (ref($settings) eq 'HASH') {
1990: $curroption = $settings->{$type};
1991: }
1992: if (!$curroption) {
1993: $curroption = 'norequest';
1994: }
1995: foreach my $option (@options) {
1996: my $val = $option;
1997: if ($option eq 'norequest') {
1998: $val = 0;
1999: }
2000: my $checked = '';
2001: if ($option eq $curroption) {
2002: $checked = ' checked="checked"';
2003: }
2004: $datatable .= '<span class="LC_nobreak"><label>'.
2005: '<input type="radio" name="authorreq_'.$type.
2006: '" value="'.$val.'"'.$checked.' />'.
2007: $titles{$option}.'</label></span> ';
2008: }
1.101 raeburn 2009: } else {
2010: my $checked = 'checked="checked" ';
2011: if (ref($settings) eq 'HASH') {
2012: if (ref($settings->{$item}) eq 'HASH') {
2013: if ($settings->{$item}->{$type} == 0) {
2014: $checked = '';
2015: } elsif ($settings->{$item}->{$type} == 1) {
2016: $checked = 'checked="checked" ';
2017: }
1.78 raeburn 2018: }
1.72 raeburn 2019: }
1.101 raeburn 2020: $datatable .= '<span class="LC_nobreak"><label>'.
2021: '<input type="checkbox" name="'.$context.'_'.$item.
2022: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2023: '</label></span> ';
1.72 raeburn 2024: }
1.101 raeburn 2025: }
2026: if ($context eq 'requestcourses') {
2027: $datatable .= '</tr><tr>';
2028: foreach my $item (@usertools) {
1.106 raeburn 2029: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2030: }
2031: $datatable .= '</tr></table>';
1.72 raeburn 2032: }
1.86 raeburn 2033: $datatable .= '</td>';
1.163 raeburn 2034: unless (($context eq 'requestcourses') ||
2035: ($context eq 'requestauthor')) {
1.86 raeburn 2036: $datatable .=
1.197 raeburn 2037: '<td class="LC_right_item">'.
2038: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2039: '<input type="text" name="quota_'.$type.
1.72 raeburn 2040: '" value="'.$currdefquota.
1.197 raeburn 2041: '" size="5" /></span>'.(' ' x 2).
2042: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2043: '<input type="text" name="authorquota_'.$type.
2044: '" value="'.$currauthorquota.
2045: '" size="5" /></span></td>';
1.86 raeburn 2046: }
2047: $datatable .= '</tr>';
1.3 raeburn 2048: }
2049: }
2050: }
1.163 raeburn 2051: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2052: $defaultquota = '20';
1.197 raeburn 2053: $authorquota = '500';
1.86 raeburn 2054: if (ref($settings) eq 'HASH') {
2055: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2056: $defaultquota = $settings->{'defaultquota'}->{'default'};
2057: } elsif (defined($settings->{'default'})) {
2058: $defaultquota = $settings->{'default'};
2059: }
1.197 raeburn 2060: if (ref($settings->{'authorquota'}) eq 'HASH') {
2061: $authorquota = $settings->{'authorquota'}->{'default'};
2062: }
1.3 raeburn 2063: }
2064: }
2065: $typecount ++;
2066: $css_class = $typecount%2?' class="LC_odd_row"':'';
2067: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2068: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2069: '<td class="LC_left_item">';
1.101 raeburn 2070: if ($context eq 'requestcourses') {
2071: $datatable .= '<table><tr>';
2072: }
2073: my %defcell;
1.72 raeburn 2074: foreach my $item (@usertools) {
1.101 raeburn 2075: if ($context eq 'requestcourses') {
2076: my ($curroption,$currlimit);
2077: if (ref($settings) eq 'HASH') {
2078: if (ref($settings->{$item}) eq 'HASH') {
2079: $curroption = $settings->{$item}->{'default'};
2080: if ($curroption =~ /^autolimit=(\d*)$/) {
2081: $currlimit = $1;
2082: }
2083: }
2084: }
2085: if (!$curroption) {
2086: $curroption = 'norequest';
2087: }
2088: $datatable .= '<th>'.$titles{$item}.'</th>';
2089: foreach my $option (@options) {
2090: my $val = $option;
2091: if ($option eq 'norequest') {
2092: $val = 0;
2093: }
2094: if ($option eq 'validate') {
2095: my $canvalidate = 0;
2096: if (ref($validations{$item}) eq 'HASH') {
2097: if ($validations{$item}{'default'}) {
2098: $canvalidate = 1;
2099: }
2100: }
2101: next if (!$canvalidate);
2102: }
2103: my $checked = '';
2104: if ($option eq $curroption) {
2105: $checked = ' checked="checked"';
2106: } elsif ($option eq 'autolimit') {
2107: if ($curroption =~ /^autolimit/) {
2108: $checked = ' checked="checked"';
2109: }
2110: }
2111: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2112: '<input type="radio" name="crsreq_'.$item.
2113: '_default" value="'.$val.'"'.$checked.' />'.
2114: $titles{$option}.'</label>';
2115: if ($option eq 'autolimit') {
1.127 raeburn 2116: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2117: $item.'_limit_default" size="1" '.
2118: 'value="'.$currlimit.'" />';
2119: }
1.127 raeburn 2120: $defcell{$item} .= '</span> ';
1.104 raeburn 2121: if ($option eq 'autolimit') {
1.127 raeburn 2122: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2123: }
1.101 raeburn 2124: }
1.163 raeburn 2125: } elsif ($context eq 'requestauthor') {
2126: my $curroption;
2127: if (ref($settings) eq 'HASH') {
1.172 raeburn 2128: $curroption = $settings->{'default'};
1.163 raeburn 2129: }
2130: if (!$curroption) {
2131: $curroption = 'norequest';
2132: }
2133: foreach my $option (@options) {
2134: my $val = $option;
2135: if ($option eq 'norequest') {
2136: $val = 0;
2137: }
2138: my $checked = '';
2139: if ($option eq $curroption) {
2140: $checked = ' checked="checked"';
2141: }
2142: $datatable .= '<span class="LC_nobreak"><label>'.
2143: '<input type="radio" name="authorreq_default"'.
2144: ' value="'.$val.'"'.$checked.' />'.
2145: $titles{$option}.'</label></span> ';
2146: }
1.101 raeburn 2147: } else {
2148: my $checked = 'checked="checked" ';
2149: if (ref($settings) eq 'HASH') {
2150: if (ref($settings->{$item}) eq 'HASH') {
2151: if ($settings->{$item}->{'default'} == 0) {
2152: $checked = '';
2153: } elsif ($settings->{$item}->{'default'} == 1) {
2154: $checked = 'checked="checked" ';
2155: }
1.78 raeburn 2156: }
1.72 raeburn 2157: }
1.101 raeburn 2158: $datatable .= '<span class="LC_nobreak"><label>'.
2159: '<input type="checkbox" name="'.$context.'_'.$item.
2160: '" value="default" '.$checked.'/>'.$titles{$item}.
2161: '</label></span> ';
2162: }
2163: }
2164: if ($context eq 'requestcourses') {
2165: $datatable .= '</tr><tr>';
2166: foreach my $item (@usertools) {
1.106 raeburn 2167: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2168: }
1.101 raeburn 2169: $datatable .= '</tr></table>';
1.72 raeburn 2170: }
1.86 raeburn 2171: $datatable .= '</td>';
1.163 raeburn 2172: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2173: $datatable .= '<td class="LC_right_item">'.
2174: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2175: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2176: $defaultquota.'" size="5" /></span>'.(' ' x2).
2177: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2178: '<input type="text" name="authorquota" value="'.
2179: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2180: }
2181: $datatable .= '</tr>';
1.72 raeburn 2182: $typecount ++;
2183: $css_class = $typecount%2?' class="LC_odd_row"':'';
2184: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2185: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2186: if ($context eq 'requestcourses') {
1.109 raeburn 2187: $datatable .= &mt('(overrides affiliation, if set)').
2188: '</td>'.
2189: '<td class="LC_left_item">'.
2190: '<table><tr>';
1.101 raeburn 2191: } else {
1.109 raeburn 2192: $datatable .= &mt('(overrides affiliation, if checked)').
2193: '</td>'.
2194: '<td class="LC_left_item" colspan="2">'.
2195: '<br />';
1.101 raeburn 2196: }
2197: my %advcell;
1.72 raeburn 2198: foreach my $item (@usertools) {
1.101 raeburn 2199: if ($context eq 'requestcourses') {
2200: my ($curroption,$currlimit);
2201: if (ref($settings) eq 'HASH') {
2202: if (ref($settings->{$item}) eq 'HASH') {
2203: $curroption = $settings->{$item}->{'_LC_adv'};
2204: if ($curroption =~ /^autolimit=(\d*)$/) {
2205: $currlimit = $1;
2206: }
2207: }
2208: }
2209: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2210: my $checked = '';
2211: if ($curroption eq '') {
2212: $checked = ' checked="checked"';
2213: }
2214: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2215: '<input type="radio" name="crsreq_'.$item.
2216: '__LC_adv" value=""'.$checked.' />'.
2217: &mt('No override set').'</label></span> ';
1.101 raeburn 2218: foreach my $option (@options) {
2219: my $val = $option;
2220: if ($option eq 'norequest') {
2221: $val = 0;
2222: }
2223: if ($option eq 'validate') {
2224: my $canvalidate = 0;
2225: if (ref($validations{$item}) eq 'HASH') {
2226: if ($validations{$item}{'_LC_adv'}) {
2227: $canvalidate = 1;
2228: }
2229: }
2230: next if (!$canvalidate);
2231: }
2232: my $checked = '';
1.104 raeburn 2233: if ($val eq $curroption) {
1.101 raeburn 2234: $checked = ' checked="checked"';
2235: } elsif ($option eq 'autolimit') {
2236: if ($curroption =~ /^autolimit/) {
2237: $checked = ' checked="checked"';
2238: }
2239: }
2240: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2241: '<input type="radio" name="crsreq_'.$item.
2242: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2243: $titles{$option}.'</label>';
2244: if ($option eq 'autolimit') {
1.127 raeburn 2245: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2246: $item.'_limit__LC_adv" size="1" '.
2247: 'value="'.$currlimit.'" />';
2248: }
1.127 raeburn 2249: $advcell{$item} .= '</span> ';
1.104 raeburn 2250: if ($option eq 'autolimit') {
1.127 raeburn 2251: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2252: }
1.101 raeburn 2253: }
1.163 raeburn 2254: } elsif ($context eq 'requestauthor') {
2255: my $curroption;
2256: if (ref($settings) eq 'HASH') {
2257: $curroption = $settings->{'_LC_adv'};
2258: }
2259: my $checked = '';
2260: if ($curroption eq '') {
2261: $checked = ' checked="checked"';
2262: }
2263: $datatable .= '<span class="LC_nobreak"><label>'.
2264: '<input type="radio" name="authorreq__LC_adv"'.
2265: ' value=""'.$checked.' />'.
2266: &mt('No override set').'</label></span> ';
2267: foreach my $option (@options) {
2268: my $val = $option;
2269: if ($option eq 'norequest') {
2270: $val = 0;
2271: }
2272: my $checked = '';
2273: if ($val eq $curroption) {
2274: $checked = ' checked="checked"';
2275: }
2276: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2277: '<input type="radio" name="authorreq__LC_adv"'.
2278: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2279: $titles{$option}.'</label></span> ';
2280: }
1.101 raeburn 2281: } else {
2282: my $checked = 'checked="checked" ';
2283: if (ref($settings) eq 'HASH') {
2284: if (ref($settings->{$item}) eq 'HASH') {
2285: if ($settings->{$item}->{'_LC_adv'} == 0) {
2286: $checked = '';
2287: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2288: $checked = 'checked="checked" ';
2289: }
1.79 raeburn 2290: }
1.72 raeburn 2291: }
1.101 raeburn 2292: $datatable .= '<span class="LC_nobreak"><label>'.
2293: '<input type="checkbox" name="'.$context.'_'.$item.
2294: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2295: '</label></span> ';
2296: }
2297: }
2298: if ($context eq 'requestcourses') {
2299: $datatable .= '</tr><tr>';
2300: foreach my $item (@usertools) {
1.106 raeburn 2301: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2302: }
1.101 raeburn 2303: $datatable .= '</tr></table>';
1.72 raeburn 2304: }
1.98 raeburn 2305: $datatable .= '</td></tr>';
1.30 raeburn 2306: $$rowtotal += $typecount;
1.3 raeburn 2307: return $datatable;
2308: }
2309:
1.163 raeburn 2310: sub print_requestmail {
1.305 raeburn 2311: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2312: my ($now,$datatable,%currapp);
1.102 raeburn 2313: $now = time;
2314: if (ref($settings) eq 'HASH') {
2315: if (ref($settings->{'notify'}) eq 'HASH') {
2316: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2317: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2318: }
2319: }
2320: }
1.191 raeburn 2321: my $numinrow = 2;
1.224 raeburn 2322: my $css_class;
1.305 raeburn 2323: if ($$rowtotal%2) {
2324: $css_class = 'LC_odd_row';
2325: }
2326: if ($customcss) {
2327: $css_class .= " $customcss";
2328: }
2329: $css_class =~ s/^\s+//;
2330: if ($css_class) {
2331: $css_class = ' class="'.$css_class.'"';
2332: }
2333: if ($rowstyle) {
2334: $css_class .= ' style="'.$rowstyle.'"';
2335: }
1.163 raeburn 2336: my $text;
2337: if ($action eq 'requestcourses') {
2338: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2339: } elsif ($action eq 'requestauthor') {
2340: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2341: } else {
1.224 raeburn 2342: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2343: }
1.224 raeburn 2344: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2345: ' <td>'.$text.'</td>'.
1.102 raeburn 2346: ' <td class="LC_left_item">';
1.191 raeburn 2347: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2348: $action.'notifyapproval',%currapp);
1.191 raeburn 2349: if ($numdc > 0) {
2350: $datatable .= $table;
1.102 raeburn 2351: } else {
2352: $datatable .= &mt('There are no active Domain Coordinators');
2353: }
2354: $datatable .='</td></tr>';
2355: return $datatable;
2356: }
2357:
1.216 raeburn 2358: sub print_studentcode {
2359: my ($settings,$rowtotal) = @_;
2360: my $rownum = 0;
1.218 raeburn 2361: my ($output,%current);
1.325 raeburn 2362: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2363: if (ref($settings) eq 'HASH') {
2364: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2365: foreach my $type (@crstypes) {
2366: $current{$type} = $settings->{'uniquecode'}{$type};
2367: }
1.218 raeburn 2368: }
2369: }
2370: $output .= '<tr>'.
2371: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2372: '<td class="LC_left_item">';
2373: foreach my $type (@crstypes) {
2374: my $check = ' ';
2375: if ($current{$type}) {
2376: $check = ' checked="checked" ';
2377: }
2378: $output .= '<span class="LC_nobreak"><label>'.
2379: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2380: &mt($type).'</label></span>'.(' 'x2).' ';
2381: }
2382: $output .= '</td></tr>';
2383: $$rowtotal ++;
2384: return $output;
1.216 raeburn 2385: }
2386:
2387: sub print_textbookcourses {
1.242 raeburn 2388: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2389: my $rownum = 0;
2390: my $css_class;
2391: my $itemcount = 1;
2392: my $maxnum = 0;
2393: my $bookshash;
2394: if (ref($settings) eq 'HASH') {
1.242 raeburn 2395: $bookshash = $settings->{$type};
1.216 raeburn 2396: }
2397: my %ordered;
2398: if (ref($bookshash) eq 'HASH') {
2399: foreach my $item (keys(%{$bookshash})) {
2400: if (ref($bookshash->{$item}) eq 'HASH') {
2401: my $num = $bookshash->{$item}{'order'};
2402: $ordered{$num} = $item;
2403: }
2404: }
2405: }
2406: my $confname = $dom.'-domainconfig';
2407: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2408: my $maxnum = scalar(keys(%ordered));
2409: my $datatable;
1.216 raeburn 2410: if (keys(%ordered)) {
2411: my @items = sort { $a <=> $b } keys(%ordered);
2412: for (my $i=0; $i<@items; $i++) {
2413: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2414: my $key = $ordered{$items[$i]};
2415: my %coursehash=&Apache::lonnet::coursedescription($key);
2416: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2417: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2418: if (ref($bookshash->{$key}) eq 'HASH') {
2419: $subject = $bookshash->{$key}->{'subject'};
2420: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2421: if ($type eq 'textbooks') {
1.243 raeburn 2422: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2423: $author = $bookshash->{$key}->{'author'};
2424: $image = $bookshash->{$key}->{'image'};
2425: if ($image ne '') {
2426: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2427: my $imagethumb = "$path/tn-".$imagefile;
2428: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2429: }
1.216 raeburn 2430: }
2431: }
1.242 raeburn 2432: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2433: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2434: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2435: for (my $k=0; $k<=$maxnum; $k++) {
2436: my $vpos = $k+1;
2437: my $selstr;
2438: if ($k == $i) {
2439: $selstr = ' selected="selected" ';
2440: }
2441: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2442: }
2443: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2444: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2445: &mt('Delete?').'</label></span></td>'.
2446: '<td colspan="2">'.
1.242 raeburn 2447: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2448: (' 'x2).
1.242 raeburn 2449: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2450: if ($type eq 'textbooks') {
2451: $datatable .= (' 'x2).
1.243 raeburn 2452: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2453: (' 'x2).
1.242 raeburn 2454: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2455: (' 'x2).
2456: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2457: if ($image) {
1.267 raeburn 2458: $datatable .= $imgsrc.
1.242 raeburn 2459: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2460: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2461: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2462: }
2463: if ($switchserver) {
2464: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2465: } else {
2466: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2467: }
1.216 raeburn 2468: }
1.242 raeburn 2469: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2470: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2471: $coursetitle.'</span></td></tr>'."\n";
2472: $itemcount ++;
2473: }
2474: }
2475: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2476: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2477: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2478: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2479: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2480: for (my $k=0; $k<$maxnum+1; $k++) {
2481: my $vpos = $k+1;
2482: my $selstr;
2483: if ($k == $maxnum) {
2484: $selstr = ' selected="selected" ';
2485: }
2486: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2487: }
2488: $datatable .= '</select> '."\n".
1.334 raeburn 2489: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216 raeburn 2490: '<td colspan="2">'.
1.242 raeburn 2491: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2492: (' 'x2).
1.242 raeburn 2493: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2494: (' 'x2);
2495: if ($type eq 'textbooks') {
1.243 raeburn 2496: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2497: (' 'x2).
2498: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2499: (' 'x2).
2500: '<span class="LC_nobreak">'.&mt('Image:').' ';
2501: if ($switchserver) {
2502: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2503: } else {
2504: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2505: }
1.334 raeburn 2506: $datatable .= '</span>'."\n";
1.216 raeburn 2507: }
1.334 raeburn 2508: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2509: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2510: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2511: &Apache::loncommon::selectcourse_link
1.334 raeburn 2512: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216 raeburn 2513: '</span></td>'."\n".
2514: '</tr>'."\n";
2515: $itemcount ++;
2516: return $datatable;
2517: }
2518:
1.217 raeburn 2519: sub textbookcourses_javascript {
1.242 raeburn 2520: my ($settings) = @_;
2521: return unless(ref($settings) eq 'HASH');
2522: my (%ordered,%total,%jstext);
2523: foreach my $type ('textbooks','templates') {
2524: $total{$type} = 0;
2525: if (ref($settings->{$type}) eq 'HASH') {
2526: foreach my $item (keys(%{$settings->{$type}})) {
2527: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2528: my $num = $settings->{$type}->{$item}{'order'};
2529: $ordered{$type}{$num} = $item;
2530: }
2531: }
2532: $total{$type} = scalar(keys(%{$settings->{$type}}));
2533: }
2534: my @jsarray = ();
2535: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2536: push(@jsarray,$ordered{$type}{$item});
2537: }
2538: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2539: }
2540: return <<"ENDSCRIPT";
2541: <script type="text/javascript">
2542: // <![CDATA[
1.242 raeburn 2543: function reorderBooks(form,item,caller) {
1.217 raeburn 2544: var changedVal;
1.242 raeburn 2545: $jstext{'textbooks'};
2546: $jstext{'templates'};
2547: var newpos;
2548: var maxh;
2549: if (caller == 'textbooks') {
2550: newpos = 'textbooks_addbook_pos';
2551: maxh = 1 + $total{'textbooks'};
2552: } else {
2553: newpos = 'templates_addbook_pos';
2554: maxh = 1 + $total{'templates'};
2555: }
1.217 raeburn 2556: var current = new Array;
2557: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2558: if (item == newpos) {
2559: changedVal = newitemVal;
2560: } else {
2561: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2562: current[newitemVal] = newpos;
2563: }
1.242 raeburn 2564: if (caller == 'textbooks') {
2565: for (var i=0; i<textbooks.length; i++) {
2566: var elementName = 'textbooks_'+textbooks[i];
2567: if (elementName != item) {
2568: if (form.elements[elementName]) {
2569: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2570: current[currVal] = elementName;
2571: }
2572: }
2573: }
2574: }
2575: if (caller == 'templates') {
2576: for (var i=0; i<templates.length; i++) {
2577: var elementName = 'templates_'+templates[i];
2578: if (elementName != item) {
2579: if (form.elements[elementName]) {
2580: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2581: current[currVal] = elementName;
2582: }
1.217 raeburn 2583: }
2584: }
2585: }
2586: var oldVal;
2587: for (var j=0; j<maxh; j++) {
2588: if (current[j] == undefined) {
2589: oldVal = j;
2590: }
2591: }
2592: if (oldVal < changedVal) {
2593: for (var k=oldVal+1; k<=changedVal ; k++) {
2594: var elementName = current[k];
2595: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2596: }
2597: } else {
2598: for (var k=changedVal; k<oldVal; k++) {
2599: var elementName = current[k];
2600: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2601: }
2602: }
2603: return;
2604: }
2605:
2606: // ]]>
2607: </script>
2608:
2609: ENDSCRIPT
2610: }
2611:
1.267 raeburn 2612: sub ltitools_javascript {
2613: my ($settings) = @_;
1.319 raeburn 2614: my $togglejs = <itools_toggle_js();
2615: unless (ref($settings) eq 'HASH') {
2616: return $togglejs;
2617: }
1.267 raeburn 2618: my (%ordered,$total,%jstext);
2619: $total = 0;
2620: foreach my $item (keys(%{$settings})) {
2621: if (ref($settings->{$item}) eq 'HASH') {
2622: my $num = $settings->{$item}{'order'};
2623: $ordered{$num} = $item;
2624: }
2625: }
2626: $total = scalar(keys(%{$settings}));
2627: my @jsarray = ();
2628: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2629: push(@jsarray,$ordered{$item});
2630: }
2631: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2632: return <<"ENDSCRIPT";
2633: <script type="text/javascript">
2634: // <![CDATA[
1.319 raeburn 2635: function reorderLTITools(form,item) {
1.267 raeburn 2636: var changedVal;
2637: $jstext
2638: var newpos = 'ltitools_add_pos';
2639: var maxh = 1 + $total;
2640: var current = new Array;
2641: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2642: if (item == newpos) {
2643: changedVal = newitemVal;
2644: } else {
2645: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2646: current[newitemVal] = newpos;
2647: }
2648: for (var i=0; i<ltitools.length; i++) {
2649: var elementName = 'ltitools_'+ltitools[i];
2650: if (elementName != item) {
2651: if (form.elements[elementName]) {
2652: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2653: current[currVal] = elementName;
2654: }
2655: }
2656: }
2657: var oldVal;
2658: for (var j=0; j<maxh; j++) {
2659: if (current[j] == undefined) {
2660: oldVal = j;
2661: }
2662: }
2663: if (oldVal < changedVal) {
2664: for (var k=oldVal+1; k<=changedVal ; k++) {
2665: var elementName = current[k];
2666: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2667: }
2668: } else {
2669: for (var k=changedVal; k<oldVal; k++) {
2670: var elementName = current[k];
2671: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2672: }
2673: }
2674: return;
2675: }
2676:
2677: // ]]>
2678: </script>
2679:
1.319 raeburn 2680: $togglejs
2681:
2682: ENDSCRIPT
2683: }
2684:
2685: sub ltitools_toggle_js {
2686: return <<"ENDSCRIPT";
2687: <script type="text/javascript">
2688: // <![CDATA[
2689:
2690: function toggleLTITools(form,setting,item) {
2691: var radioname = '';
2692: var divid = '';
2693: if ((setting == 'passback') || (setting == 'roster')) {
2694: radioname = 'ltitools_'+setting+'_'+item;
2695: divid = 'ltitools_'+setting+'time_'+item;
2696: var num = form.elements[radioname].length;
2697: if (num) {
2698: var setvis = '';
2699: for (var i=0; i<num; i++) {
2700: if (form.elements[radioname][i].checked) {
2701: if (form.elements[radioname][i].value == '1') {
2702: if (document.getElementById(divid)) {
2703: document.getElementById(divid).style.display = 'inline-block';
2704: }
2705: setvis = 1;
2706: }
2707: break;
2708: }
2709: }
2710: }
2711: if (!setvis) {
2712: if (document.getElementById(divid)) {
2713: document.getElementById(divid).style.display = 'none';
2714: }
2715: }
2716: }
1.324 raeburn 2717: if (setting == 'user') {
2718: divid = 'ltitools_'+setting+'_div_'+item;
2719: var checkid = 'ltitools_'+setting+'_field_'+item;
2720: if (document.getElementById(divid)) {
2721: if (document.getElementById(checkid)) {
2722: if (document.getElementById(checkid).checked) {
2723: document.getElementById(divid).style.display = 'inline-block';
2724: } else {
2725: document.getElementById(divid).style.display = 'none';
2726: }
2727: }
2728: }
2729: }
1.319 raeburn 2730: return;
2731: }
2732: // ]]>
2733: </script>
2734:
1.267 raeburn 2735: ENDSCRIPT
2736: }
2737:
1.320 raeburn 2738: sub lti_javascript {
2739: my ($settings) = @_;
2740: my $togglejs = <i_toggle_js();
2741: unless (ref($settings) eq 'HASH') {
2742: return $togglejs;
2743: }
2744: my (%ordered,$total,%jstext);
2745: $total = 0;
2746: foreach my $item (keys(%{$settings})) {
2747: if (ref($settings->{$item}) eq 'HASH') {
2748: my $num = $settings->{$item}{'order'};
2749: $ordered{$num} = $item;
2750: }
2751: }
2752: $total = scalar(keys(%{$settings}));
2753: my @jsarray = ();
2754: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2755: push(@jsarray,$ordered{$item});
2756: }
2757: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
2758: return <<"ENDSCRIPT";
2759: <script type="text/javascript">
2760: // <![CDATA[
2761: function reorderLTI(form,item) {
2762: var changedVal;
2763: $jstext
2764: var newpos = 'lti_pos_add';
2765: var maxh = 1 + $total;
2766: var current = new Array;
2767: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2768: if (item == newpos) {
2769: changedVal = newitemVal;
2770: } else {
2771: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2772: current[newitemVal] = newpos;
2773: }
2774: for (var i=0; i<lti.length; i++) {
2775: var elementName = 'lti_pos_'+lti[i];
2776: if (elementName != item) {
2777: if (form.elements[elementName]) {
2778: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2779: current[currVal] = elementName;
2780: }
2781: }
2782: }
2783: var oldVal;
2784: for (var j=0; j<maxh; j++) {
2785: if (current[j] == undefined) {
2786: oldVal = j;
2787: }
2788: }
2789: if (oldVal < changedVal) {
2790: for (var k=oldVal+1; k<=changedVal ; k++) {
2791: var elementName = current[k];
2792: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2793: }
2794: } else {
2795: for (var k=changedVal; k<oldVal; k++) {
2796: var elementName = current[k];
2797: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2798: }
2799: }
2800: return;
2801: }
2802: // ]]>
2803: </script>
2804:
2805: $togglejs
2806:
2807: ENDSCRIPT
2808: }
2809:
2810: sub lti_toggle_js {
1.325 raeburn 2811: my %lcauthparmtext = &Apache::lonlocal::texthash (
2812: localauth => 'Local auth argument',
2813: krb => 'Kerberos domain',
2814: );
1.320 raeburn 2815: return <<"ENDSCRIPT";
2816: <script type="text/javascript">
2817: // <![CDATA[
2818:
2819: function toggleLTI(form,setting,item) {
2820: if ((setting == 'user') || (setting == 'crs')) {
2821: var radioname = '';
2822: var divid = '';
2823: if (setting == 'user') {
2824: radioname = 'lti_mapuser_'+item;
2825: divid = 'lti_userfield_'+item;
2826: } else {
2827: radioname = 'lti_mapcrs_'+item;
2828: divid = 'lti_crsfield_'+item;
2829: }
2830: var num = form.elements[radioname].length;
2831: if (num) {
2832: var setvis = '';
2833: for (var i=0; i<num; i++) {
2834: if (form.elements[radioname][i].checked) {
2835: if (form.elements[radioname][i].value == 'other') {
2836: if (document.getElementById(divid)) {
2837: document.getElementById(divid).style.display = 'inline-block';
2838: }
2839: setvis = 1;
2840: break;
2841: }
2842: }
2843: }
2844: if (!setvis) {
2845: if (document.getElementById(divid)) {
2846: document.getElementById(divid).style.display = 'none';
2847: }
2848: }
2849: }
2850: } else if ((setting == 'sec') || (setting == 'secsrc')) {
2851: var numsec = form.elements['lti_crssec_'+item].length;
2852: if (numsec) {
2853: var setvis = '';
2854: for (var i=0; i<numsec; i++) {
2855: if (form.elements['lti_crssec_'+item][i].checked) {
2856: if (form.elements['lti_crssec_'+item][i].value == '1') {
2857: if (document.getElementById('lti_crssecfield_'+item)) {
2858: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
2859: setvis = 1;
2860: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
2861: if (numsrcsec) {
2862: var setsrcvis = '';
2863: for (var j=0; j<numsrcsec; j++) {
2864: if (form.elements['lti_crssecsrc_'+item][j].checked) {
2865: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
2866: if (document.getElementById('lti_secsrcfield_'+item)) {
2867: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
2868: setsrcvis = 1;
2869: }
2870: }
2871: }
2872: }
2873: if (!setsrcvis) {
2874: if (document.getElementById('lti_secsrcfield_'+item)) {
2875: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
2876: }
2877: }
2878: }
2879: }
2880: }
2881: }
2882: }
2883: if (!setvis) {
2884: if (document.getElementById('lti_crssecfield_'+item)) {
2885: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
2886: }
2887: if (document.getElementById('lti_secsrcfield_'+item)) {
2888: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
2889: }
2890: }
2891: }
1.325 raeburn 2892: } else if (setting == 'lcauth') {
2893: var numauth = form.elements['lti_lcauth_'+item].length;
2894: if (numauth) {
2895: for (var i=0; i<numauth; i++) {
2896: if (form.elements['lti_lcauth_'+item][i].checked) {
2897: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
2898: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
2899: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
2900: } else {
2901: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
2902: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
2903: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
2904: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
2905: } else {
2906: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
2907: }
2908: }
2909: }
2910: }
2911: }
2912: }
2913: }
1.326 raeburn 2914: } else if (setting == 'lcmenu') {
2915: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
2916: var divid = 'lti_menufield_'+item;
2917: var setvis = '';
2918: for (var i=0; i<menus.length; i++) {
2919: var radioname = menus[i];
2920: var num = form.elements[radioname].length;
2921: if (num) {
2922: for (var j=0; j<num; j++) {
2923: if (form.elements[radioname][j].checked) {
2924: if (form.elements[radioname][j].value == '1') {
2925: if (document.getElementById(divid)) {
2926: document.getElementById(divid).style.display = 'inline-block';
2927: }
2928: setvis = 1;
2929: break;
2930: }
2931: }
2932: }
2933: }
2934: if (setvis == 1) {
2935: break;
2936: }
2937: }
2938: if (!setvis) {
2939: if (document.getElementById(divid)) {
2940: document.getElementById(divid).style.display = 'none';
2941: }
2942: }
1.320 raeburn 2943: }
2944: return;
2945: }
2946: // ]]>
2947: </script>
2948:
2949: ENDSCRIPT
2950: }
2951:
1.3 raeburn 2952: sub print_autoenroll {
1.30 raeburn 2953: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2954: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274 raeburn 2955: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2956: if (ref($settings) eq 'HASH') {
2957: if (exists($settings->{'run'})) {
2958: if ($settings->{'run'} eq '0') {
2959: $runoff = ' checked="checked" ';
2960: $runon = ' ';
2961: } else {
2962: $runon = ' checked="checked" ';
2963: $runoff = ' ';
2964: }
2965: } else {
2966: if ($autorun) {
2967: $runon = ' checked="checked" ';
2968: $runoff = ' ';
2969: } else {
2970: $runoff = ' checked="checked" ';
2971: $runon = ' ';
2972: }
2973: }
1.129 raeburn 2974: if (exists($settings->{'co-owners'})) {
2975: if ($settings->{'co-owners'} eq '0') {
2976: $coownersoff = ' checked="checked" ';
2977: $coownerson = ' ';
2978: } else {
2979: $coownerson = ' checked="checked" ';
2980: $coownersoff = ' ';
2981: }
2982: } else {
2983: $coownersoff = ' checked="checked" ';
2984: $coownerson = ' ';
2985: }
1.3 raeburn 2986: if (exists($settings->{'sender_domain'})) {
2987: $defdom = $settings->{'sender_domain'};
2988: }
1.274 raeburn 2989: if (exists($settings->{'autofailsafe'})) {
2990: $failsafe = $settings->{'autofailsafe'};
2991: }
1.14 raeburn 2992: } else {
2993: if ($autorun) {
2994: $runon = ' checked="checked" ';
2995: $runoff = ' ';
2996: } else {
2997: $runoff = ' checked="checked" ';
2998: $runon = ' ';
2999: }
1.3 raeburn 3000: }
3001: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 3002: my $notif_sender;
3003: if (ref($settings) eq 'HASH') {
3004: $notif_sender = $settings->{'sender_uname'};
3005: }
1.3 raeburn 3006: my $datatable='<tr class="LC_odd_row">'.
3007: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 3008: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3009: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 3010: $runon.' value="1" />'.&mt('Yes').'</label> '.
3011: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 3012: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3013: '</tr><tr>'.
3014: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 3015: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 3016: &mt('username').': '.
3017: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 3018: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 3019: ': '.$domform.'</span></td></tr>'.
3020: '<tr class="LC_odd_row">'.
3021: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3022: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3023: '<input type="radio" name="autoassign_coowners"'.
3024: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3025: '<label><input type="radio" name="autoassign_coowners"'.
3026: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 3027: '</tr><tr>'.
3028: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
3029: '<td class="LC_right_item"><span class="LC_nobreak">'.
3030: '<input type="text" name="autoenroll_failsafe"'.
1.333 raeburn 3031: ' value="'.$failsafe.'" size="4" /></span></td></tr>';
1.274 raeburn 3032: $$rowtotal += 4;
1.3 raeburn 3033: return $datatable;
3034: }
3035:
3036: sub print_autoupdate {
1.30 raeburn 3037: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 3038: my $datatable;
3039: if ($position eq 'top') {
3040: my $updateon = ' ';
3041: my $updateoff = ' checked="checked" ';
3042: my $classlistson = ' ';
3043: my $classlistsoff = ' checked="checked" ';
3044: if (ref($settings) eq 'HASH') {
3045: if ($settings->{'run'} eq '1') {
3046: $updateon = $updateoff;
3047: $updateoff = ' ';
3048: }
3049: if ($settings->{'classlists'} eq '1') {
3050: $classlistson = $classlistsoff;
3051: $classlistsoff = ' ';
3052: }
3053: }
3054: my %title = (
3055: run => 'Auto-update active?',
3056: classlists => 'Update information in classlists?',
3057: );
3058: $datatable = '<tr class="LC_odd_row">'.
3059: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 3060: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3061: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 3062: $updateon.' value="1" />'.&mt('Yes').'</label> '.
3063: '<label><input type="radio" name="autoupdate_run"'.
3064: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3065: '</tr><tr>'.
3066: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 3067: '<td class="LC_right_item"><span class="LC_nobreak">'.
3068: '<label><input type="radio" name="classlists"'.
3069: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
3070: '<label><input type="radio" name="classlists"'.
3071: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3072: '</tr>';
1.30 raeburn 3073: $$rowtotal += 2;
1.131 raeburn 3074: } elsif ($position eq 'middle') {
3075: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3076: my $numinrow = 3;
3077: my $locknamesettings;
3078: $datatable .= &insttypes_row($settings,$types,$usertypes,
3079: $dom,$numinrow,$othertitle,
1.305 raeburn 3080: 'lockablenames',$rowtotal);
1.131 raeburn 3081: $$rowtotal ++;
1.3 raeburn 3082: } else {
1.44 raeburn 3083: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3084: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3085: 'permanentemail','id');
1.33 raeburn 3086: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3087: my $numrows = 0;
1.26 raeburn 3088: if (ref($types) eq 'ARRAY') {
3089: if (@{$types} > 0) {
3090: $datatable =
3091: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3092: \@fields,$types,\$numrows);
1.30 raeburn 3093: $$rowtotal += @{$types};
1.26 raeburn 3094: }
1.3 raeburn 3095: }
3096: $datatable .=
3097: &usertype_update_row($settings,{'default' => $othertitle},
3098: \%fieldtitles,\@fields,['default'],
3099: \$numrows);
1.30 raeburn 3100: $$rowtotal ++;
1.3 raeburn 3101: }
3102: return $datatable;
3103: }
3104:
1.125 raeburn 3105: sub print_autocreate {
3106: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 3107: my (%createon,%createoff,%currhash);
1.125 raeburn 3108: my @types = ('xml','req');
3109: if (ref($settings) eq 'HASH') {
3110: foreach my $item (@types) {
3111: $createoff{$item} = ' checked="checked" ';
3112: $createon{$item} = ' ';
3113: if (exists($settings->{$item})) {
3114: if ($settings->{$item}) {
3115: $createon{$item} = ' checked="checked" ';
3116: $createoff{$item} = ' ';
3117: }
3118: }
3119: }
1.210 raeburn 3120: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 3121: $currhash{$settings->{'xmldc'}} = 1;
3122: }
1.125 raeburn 3123: } else {
3124: foreach my $item (@types) {
3125: $createoff{$item} = ' checked="checked" ';
3126: $createon{$item} = ' ';
3127: }
3128: }
3129: $$rowtotal += 2;
1.191 raeburn 3130: my $numinrow = 2;
1.125 raeburn 3131: my $datatable='<tr class="LC_odd_row">'.
3132: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3133: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3134: '<input type="radio" name="autocreate_xml"'.
3135: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3136: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 3137: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3138: '</td></tr><tr>'.
3139: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3140: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3141: '<input type="radio" name="autocreate_req"'.
3142: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3143: '<label><input type="radio" name="autocreate_req"'.
3144: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 3145: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3146: 'autocreate_xmldc',%currhash);
1.247 raeburn 3147: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 3148: if ($numdc > 1) {
1.247 raeburn 3149: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
3150: '</td><td class="LC_left_item">';
1.125 raeburn 3151: } else {
1.247 raeburn 3152: $datatable .= &mt('Course creation processed as:').
3153: '</td><td class="LC_right_item">';
1.125 raeburn 3154: }
1.247 raeburn 3155: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 3156: $$rowtotal += $rows;
1.125 raeburn 3157: return $datatable;
3158: }
3159:
1.23 raeburn 3160: sub print_directorysrch {
1.277 raeburn 3161: my ($position,$dom,$settings,$rowtotal) = @_;
3162: my $datatable;
3163: if ($position eq 'top') {
3164: my $instsrchon = ' ';
3165: my $instsrchoff = ' checked="checked" ';
3166: my ($exacton,$containson,$beginson);
3167: my $instlocalon = ' ';
3168: my $instlocaloff = ' checked="checked" ';
3169: if (ref($settings) eq 'HASH') {
3170: if ($settings->{'available'} eq '1') {
3171: $instsrchon = $instsrchoff;
3172: $instsrchoff = ' ';
3173: }
3174: if ($settings->{'localonly'} eq '1') {
3175: $instlocalon = $instlocaloff;
3176: $instlocaloff = ' ';
3177: }
3178: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
3179: foreach my $type (@{$settings->{'searchtypes'}}) {
3180: if ($type eq 'exact') {
3181: $exacton = ' checked="checked" ';
3182: } elsif ($type eq 'contains') {
3183: $containson = ' checked="checked" ';
3184: } elsif ($type eq 'begins') {
3185: $beginson = ' checked="checked" ';
3186: }
3187: }
3188: } else {
3189: if ($settings->{'searchtypes'} eq 'exact') {
3190: $exacton = ' checked="checked" ';
3191: } elsif ($settings->{'searchtypes'} eq 'contains') {
3192: $containson = ' checked="checked" ';
3193: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 3194: $exacton = ' checked="checked" ';
3195: $containson = ' checked="checked" ';
3196: }
3197: }
1.277 raeburn 3198: }
3199: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3200: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3201:
3202: my $numinrow = 4;
3203: my $cansrchrow = 0;
3204: $datatable='<tr class="LC_odd_row">'.
3205: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
3206: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3207: '<input type="radio" name="dirsrch_available"'.
3208: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
3209: '<label><input type="radio" name="dirsrch_available"'.
3210: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3211: '</tr><tr>'.
3212: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
3213: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3214: '<input type="radio" name="dirsrch_instlocalonly"'.
3215: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3216: '<label><input type="radio" name="dirsrch_instlocalonly"'.
3217: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3218: '</tr>';
3219: $$rowtotal += 2;
3220: if (ref($usertypes) eq 'HASH') {
3221: if (keys(%{$usertypes}) > 0) {
3222: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 3223: $numinrow,$othertitle,'cansearch',
3224: $rowtotal);
1.277 raeburn 3225: $cansrchrow = 1;
1.25 raeburn 3226: }
1.23 raeburn 3227: }
1.277 raeburn 3228: if ($cansrchrow) {
3229: $$rowtotal ++;
3230: $datatable .= '<tr>';
3231: } else {
3232: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 3233: }
1.277 raeburn 3234: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
3235: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
3236: foreach my $title (@{$titleorder}) {
3237: if (defined($searchtitles->{$title})) {
3238: my $check = ' ';
3239: if (ref($settings) eq 'HASH') {
3240: if (ref($settings->{'searchby'}) eq 'ARRAY') {
3241: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
3242: $check = ' checked="checked" ';
3243: }
1.39 raeburn 3244: }
1.25 raeburn 3245: }
1.277 raeburn 3246: $datatable .= '<td class="LC_left_item">'.
3247: '<span class="LC_nobreak"><label>'.
3248: '<input type="checkbox" name="searchby" '.
3249: 'value="'.$title.'"'.$check.'/>'.
3250: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 3251: }
3252: }
1.277 raeburn 3253: $datatable .= '</tr></table></td></tr>';
3254: $$rowtotal ++;
3255: if ($cansrchrow) {
3256: $datatable .= '<tr class="LC_odd_row">';
3257: } else {
3258: $datatable .= '<tr>';
3259: }
3260: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
3261: '<td class="LC_left_item" colspan="2">'.
3262: '<span class="LC_nobreak"><label>'.
3263: '<input type="checkbox" name="searchtypes" '.
3264: $exacton.' value="exact" />'.&mt('Exact match').
3265: '</label> '.
3266: '<label><input type="checkbox" name="searchtypes" '.
3267: $beginson.' value="begins" />'.&mt('Begins with').
3268: '</label> '.
3269: '<label><input type="checkbox" name="searchtypes" '.
3270: $containson.' value="contains" />'.&mt('Contains').
3271: '</label></span></td></tr>';
3272: $$rowtotal ++;
1.26 raeburn 3273: } else {
1.277 raeburn 3274: my $domsrchon = ' checked="checked" ';
3275: my $domsrchoff = ' ';
3276: my $domlocalon = ' ';
3277: my $domlocaloff = ' checked="checked" ';
3278: if (ref($settings) eq 'HASH') {
3279: if ($settings->{'lclocalonly'} eq '1') {
3280: $domlocalon = $domlocaloff;
3281: $domlocaloff = ' ';
3282: }
3283: if ($settings->{'lcavailable'} eq '0') {
3284: $domsrchoff = $domsrchon;
3285: $domsrchon = ' ';
3286: }
3287: }
3288: $datatable='<tr class="LC_odd_row">'.
3289: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
3290: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3291: '<input type="radio" name="dirsrch_domavailable"'.
3292: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
3293: '<label><input type="radio" name="dirsrch_domavailable"'.
3294: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3295: '</tr><tr>'.
3296: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
3297: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3298: '<input type="radio" name="dirsrch_domlocalonly"'.
3299: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3300: '<label><input type="radio" name="dirsrch_domlocalonly"'.
3301: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3302: '</tr>';
3303: $$rowtotal += 2;
1.26 raeburn 3304: }
1.25 raeburn 3305: return $datatable;
3306: }
3307:
1.28 raeburn 3308: sub print_contacts {
1.286 raeburn 3309: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 3310: my $datatable;
3311: my @contacts = ('adminemail','supportemail');
1.286 raeburn 3312: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
3313: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings);
3314: if ($position eq 'top') {
3315: if (ref($settings) eq 'HASH') {
3316: foreach my $item (@contacts) {
3317: if (exists($settings->{$item})) {
3318: $to{$item} = $settings->{$item};
3319: }
3320: }
3321: }
3322: } elsif ($position eq 'middle') {
3323: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
3324: 'updatesmail','idconflictsmail');
1.288 raeburn 3325: foreach my $type (@mailings) {
3326: $otheremails{$type} = '';
3327: }
1.286 raeburn 3328: } else {
3329: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 3330: foreach my $type (@mailings) {
3331: $otheremails{$type} = '';
3332: }
1.286 raeburn 3333: $bccemails{'helpdeskmail'} = '';
3334: $bccemails{'otherdomsmail'} = '';
3335: $includestr{'helpdeskmail'} = '';
3336: $includestr{'otherdomsmail'} = '';
3337: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3338: }
1.28 raeburn 3339: if (ref($settings) eq 'HASH') {
1.286 raeburn 3340: unless ($position eq 'top') {
3341: foreach my $type (@mailings) {
3342: if (exists($settings->{$type})) {
3343: if (ref($settings->{$type}) eq 'HASH') {
3344: foreach my $item (@contacts) {
3345: if ($settings->{$type}{$item}) {
3346: $checked{$type}{$item} = ' checked="checked" ';
3347: }
3348: }
3349: $otheremails{$type} = $settings->{$type}{'others'};
3350: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3351: $bccemails{$type} = $settings->{$type}{'bcc'};
3352: if ($settings->{$type}{'include'} ne '') {
3353: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3354: $includestr{$type} = &unescape($includestr{$type});
3355: }
3356: }
3357: }
3358: } elsif ($type eq 'lonstatusmail') {
3359: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3360: }
1.28 raeburn 3361: }
3362: }
1.286 raeburn 3363: if ($position eq 'bottom') {
3364: foreach my $type (@mailings) {
3365: $bccemails{$type} = $settings->{$type}{'bcc'};
3366: if ($settings->{$type}{'include'} ne '') {
3367: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3368: $includestr{$type} = &unescape($includestr{$type});
3369: }
3370: }
3371: if (ref($settings->{'helpform'}) eq 'HASH') {
3372: if (ref($fields) eq 'ARRAY') {
3373: foreach my $field (@{$fields}) {
3374: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3375: }
1.286 raeburn 3376: }
3377: if (exists($settings->{'helpform'}{'maxsize'})) {
3378: $maxsize = $settings->{'helpform'}{'maxsize'};
3379: } else {
1.289 raeburn 3380: $maxsize = '1.0';
1.286 raeburn 3381: }
3382: } else {
3383: if (ref($fields) eq 'ARRAY') {
3384: foreach my $field (@{$fields}) {
3385: $currfield{$field} = 'yes';
1.134 raeburn 3386: }
1.28 raeburn 3387: }
1.286 raeburn 3388: $maxsize = '1.0';
1.28 raeburn 3389: }
3390: }
3391: } else {
1.286 raeburn 3392: if ($position eq 'top') {
3393: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3394: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3395: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3396: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 3397: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 3398: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3399: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3400: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
3401: } elsif ($position eq 'bottom') {
3402: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3403: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3404: if (ref($fields) eq 'ARRAY') {
3405: foreach my $field (@{$fields}) {
3406: $currfield{$field} = 'yes';
3407: }
3408: }
3409: $maxsize = '1.0';
3410: }
1.28 raeburn 3411: }
3412: my ($titles,$short_titles) = &contact_titles();
3413: my $rownum = 0;
3414: my $css_class;
1.286 raeburn 3415: if ($position eq 'top') {
3416: foreach my $item (@contacts) {
3417: $css_class = $rownum%2?' class="LC_odd_row"':'';
3418: $datatable .= '<tr'.$css_class.'>'.
3419: '<td><span class="LC_nobreak">'.$titles->{$item}.
3420: '</span></td><td class="LC_right_item">'.
3421: '<input type="text" name="'.$item.'" value="'.
3422: $to{$item}.'" /></td></tr>';
3423: $rownum ++;
3424: }
1.315 raeburn 3425: } elsif ($position eq 'bottom') {
3426: $css_class = $rownum%2?' class="LC_odd_row"':'';
3427: $datatable .= '<tr'.$css_class.'>'.
3428: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3429: &mt('(e-mail, subject, and description always shown)').
3430: '</td><td class="LC_left_item">';
3431: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3432: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3433: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3434: foreach my $field (@{$fields}) {
3435: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3436: if (($field eq 'screenshot') || ($field eq 'cc')) {
3437: $datatable .= ' '.&mt('(logged-in users)');
3438: }
3439: $datatable .='</td><td>';
3440: my $clickaction;
3441: if ($field eq 'screenshot') {
3442: $clickaction = ' onclick="screenshotSize(this);"';
3443: }
3444: if (ref($possoptions->{$field}) eq 'ARRAY') {
3445: foreach my $option (@{$possoptions->{$field}}) {
3446: my $checked;
3447: if ($currfield{$field} eq $option) {
3448: $checked = ' checked="checked"';
3449: }
3450: $datatable .= '<span class="LC_nobreak"><label>'.
3451: '<input type="radio" name="helpform_'.$field.'" '.
3452: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3453: '</label></span>'.(' 'x2);
3454: }
3455: }
3456: if ($field eq 'screenshot') {
3457: my $display;
3458: if ($currfield{$field} eq 'no') {
3459: $display = ' style="display:none"';
3460: }
1.334 raeburn 3461: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 3462: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3463: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3464: }
3465: $datatable .= '</td></tr>';
3466: }
3467: $datatable .= '</table>';
3468: }
3469: $datatable .= '</td></tr>'."\n";
3470: $rownum ++;
3471: }
3472: unless ($position eq 'top') {
1.286 raeburn 3473: foreach my $type (@mailings) {
3474: $css_class = $rownum%2?' class="LC_odd_row"':'';
3475: $datatable .= '<tr'.$css_class.'>'.
3476: '<td><span class="LC_nobreak">'.
3477: $titles->{$type}.': </span></td>'.
3478: '<td class="LC_left_item">';
3479: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3480: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3481: }
3482: $datatable .= '<span class="LC_nobreak">';
3483: foreach my $item (@contacts) {
3484: $datatable .= '<label>'.
3485: '<input type="checkbox" name="'.$type.'"'.
3486: $checked{$type}{$item}.
3487: ' value="'.$item.'" />'.$short_titles->{$item}.
3488: '</label> ';
3489: }
3490: $datatable .= '</span><br />'.&mt('Others').': '.
3491: '<input type="text" name="'.$type.'_others" '.
3492: 'value="'.$otheremails{$type}.'" />';
3493: my %locchecked;
3494: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3495: foreach my $loc ('s','b') {
3496: if ($includeloc{$type} eq $loc) {
3497: $locchecked{$loc} = ' checked="checked"';
3498: last;
3499: }
3500: }
3501: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3502: '<input type="text" name="'.$type.'_bcc" '.
3503: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3504: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3505: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 3506: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 3507: '<span class="LC_nobreak">'.&mt('Location:').' '.
3508: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3509: (' 'x2).
3510: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3511: '</span></fieldset>';
3512: }
3513: $datatable .= '</td></tr>'."\n";
3514: $rownum ++;
3515: }
1.28 raeburn 3516: }
1.286 raeburn 3517: if ($position eq 'middle') {
3518: my %choices;
3519: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
1.289 raeburn 3520: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3521: &mt('LON-CAPA core group - MSU'),600,500));
1.286 raeburn 3522: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
3523: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3524: &mt('LON-CAPA core group - MSU'),600,500));
3525: my @toggles = ('reporterrors','reportupdates');
3526: my %defaultchecked = ('reporterrors' => 'on',
3527: 'reportupdates' => 'on');
3528: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3529: \%choices,$rownum);
3530: $datatable .= $reports;
3531: } elsif ($position eq 'bottom') {
1.315 raeburn 3532: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3533: my (@posstypes,%usertypeshash);
3534: if (ref($types) eq 'ARRAY') {
3535: @posstypes = @{$types};
3536: }
3537: if (@posstypes) {
3538: if (ref($usertypes) eq 'HASH') {
3539: %usertypeshash = %{$usertypes};
3540: }
3541: my @overridden;
3542: my $numinrow = 4;
3543: if (ref($settings) eq 'HASH') {
3544: if (ref($settings->{'overrides'}) eq 'HASH') {
3545: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
3546: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
3547: push(@overridden,$key);
3548: foreach my $item (@contacts) {
3549: if ($settings->{'overrides'}{$key}{$item}) {
3550: $checked{'override_'.$key}{$item} = ' checked="checked" ';
3551: }
3552: }
3553: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
3554: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
3555: $includeloc{'override_'.$key} = '';
3556: $includestr{'override_'.$key} = '';
3557: if ($settings->{'overrides'}{$key}{'include'} ne '') {
3558: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
3559: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
3560: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
3561: }
1.286 raeburn 3562: }
3563: }
3564: }
1.315 raeburn 3565: }
3566: my $customclass = 'LC_helpdesk_override';
3567: my $optionsprefix = 'LC_options_helpdesk_';
3568:
3569: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
3570:
3571: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
3572: $numinrow,$othertitle,'overrides',
3573: \$rownum,$onclicktypes,$customclass);
3574: $rownum ++;
3575: $usertypeshash{'default'} = $othertitle;
3576: foreach my $status (@posstypes) {
3577: my $css_class;
3578: if ($rownum%2) {
3579: $css_class = 'LC_odd_row ';
3580: }
3581: $css_class .= $customclass;
3582: my $rowid = $optionsprefix.$status;
3583: my $hidden = 1;
3584: my $currstyle = 'display:none';
3585: if (grep(/^\Q$status\E$/,@overridden)) {
3586: $currstyle = 'display:table-row';
3587: $hidden = 0;
3588: }
3589: my $key = 'override_'.$status;
3590: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
3591: $includeloc{$key},$includestr{$key},$status,$rowid,
3592: $usertypeshash{$status},$css_class,$currstyle,
3593: \@contacts,$short_titles);
3594: unless ($hidden) {
3595: $rownum ++;
1.286 raeburn 3596: }
3597: }
1.134 raeburn 3598: }
1.28 raeburn 3599: }
1.30 raeburn 3600: $$rowtotal += $rownum;
1.28 raeburn 3601: return $datatable;
3602: }
3603:
1.315 raeburn 3604: sub overridden_helpdesk {
3605: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
3606: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
3607: my $class = 'LC_left_item';
3608: if ($css_class) {
3609: $css_class = ' class="'.$css_class.'"';
3610: }
3611: if ($rowid) {
3612: $rowid = ' id="'.$rowid.'"';
3613: }
3614: if ($rowstyle) {
3615: $rowstyle = ' style="'.$rowstyle.'"';
3616: }
3617: my ($output,$description);
3618: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
3619: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
3620: "<td>$description</td>\n".
3621: '<td class="'.$class.'" colspan="2">'.
3622: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
3623: '<span class="LC_nobreak">';
3624: if (ref($contacts) eq 'ARRAY') {
3625: foreach my $item (@{$contacts}) {
3626: my $check;
3627: if (ref($checked) eq 'HASH') {
3628: $check = $checked->{$item};
3629: }
3630: my $title;
3631: if (ref($short_titles) eq 'HASH') {
3632: $title = $short_titles->{$item};
3633: }
3634: $output .= '<label>'.
3635: '<input type="checkbox" name="override_'.$type.'"'.$check.
3636: ' value="'.$item.'" />'.$title.'</label> ';
3637: }
3638: }
3639: $output .= '</span><br />'.&mt('Others').': '.
3640: '<input type="text" name="override_'.$type.'_others" '.
3641: 'value="'.$otheremails.'" />';
3642: my %locchecked;
3643: foreach my $loc ('s','b') {
3644: if ($includeloc eq $loc) {
3645: $locchecked{$loc} = ' checked="checked"';
3646: last;
3647: }
3648: }
3649: $output .= '<br />'.&mt('Bcc:').(' 'x6).
3650: '<input type="text" name="override_'.$type.'_bcc" '.
3651: 'value="'.$bccemails.'" /></fieldset>'.
3652: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3653: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 3654: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 3655: '<span class="LC_nobreak">'.&mt('Location:').' '.
3656: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3657: (' 'x2).
3658: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3659: '</span></fieldset>'.
3660: '</td></tr>'."\n";
3661: return $output;
3662: }
3663:
1.286 raeburn 3664: sub contacts_javascript {
3665: return <<"ENDSCRIPT";
3666:
3667: <script type="text/javascript">
3668: // <![CDATA[
3669:
3670: function screenshotSize(field) {
3671: if (document.getElementById('help_screenshotsize')) {
3672: if (field.value == 'no') {
1.289 raeburn 3673: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 3674: } else {
3675: document.getElementById('help_screenshotsize').style.display="";
3676: }
3677: }
3678: return;
3679: }
3680:
1.315 raeburn 3681: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
3682: if (form.elements[checkbox].length != undefined) {
3683: var count = 0;
3684: if (docount) {
3685: for (var i=0; i<form.elements[checkbox].length; i++) {
3686: if (form.elements[checkbox][i].checked) {
3687: count ++;
3688: }
3689: }
3690: }
3691: for (var i=0; i<form.elements[checkbox].length; i++) {
3692: var type = form.elements[checkbox][i].value;
3693: if (document.getElementById(prefix+type)) {
3694: if (form.elements[checkbox][i].checked) {
3695: document.getElementById(prefix+type).style.display = 'table-row';
3696: if (count % 2 == 1) {
3697: document.getElementById(prefix+type).className = target+' LC_odd_row';
3698: } else {
3699: document.getElementById(prefix+type).className = target;
3700: }
3701: count ++;
3702: } else {
3703: document.getElementById(prefix+type).style.display = 'none';
3704: }
3705: }
3706: }
3707: }
3708: return;
3709: }
3710:
3711:
1.286 raeburn 3712: // ]]>
3713: </script>
3714:
3715: ENDSCRIPT
3716: }
3717:
1.118 jms 3718: sub print_helpsettings {
1.282 raeburn 3719: my ($position,$dom,$settings,$rowtotal) = @_;
3720: my $confname = $dom.'-domainconfig';
1.285 raeburn 3721: my $formname = 'display';
1.168 raeburn 3722: my ($datatable,$itemcount);
1.282 raeburn 3723: if ($position eq 'top') {
3724: $itemcount = 1;
3725: my (%choices,%defaultchecked,@toggles);
3726: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3727: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3728: &mt('LON-CAPA bug tracker'),600,500));
3729: %defaultchecked = ('submitbugs' => 'on');
3730: @toggles = ('submitbugs');
3731: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3732: \%choices,$itemcount);
3733: $$rowtotal ++;
3734: } else {
3735: my $css_class;
3736: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 3737: my (%customroles,%ordered,%current);
1.301 raeburn 3738: if (ref($settings) eq 'HASH') {
3739: if (ref($settings->{'adhoc'}) eq 'HASH') {
3740: %current = %{$settings->{'adhoc'}};
3741: }
1.285 raeburn 3742: }
3743: my $count = 0;
3744: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 3745: if ($key=~/^rolesdef\_(\w+)$/) {
3746: my $rolename = $1;
1.285 raeburn 3747: my (%privs,$order);
1.282 raeburn 3748: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3749: $customroles{$rolename} = \%privs;
1.285 raeburn 3750: if (ref($current{$rolename}) eq 'HASH') {
3751: $order = $current{$rolename}{'order'};
3752: }
3753: if ($order eq '') {
3754: $order = $count;
3755: }
3756: $ordered{$order} = $rolename;
3757: $count++;
3758: }
3759: }
3760: my $maxnum = scalar(keys(%ordered));
3761: my @roles_by_num = ();
3762: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3763: push(@roles_by_num,$item);
3764: }
3765: my $context = 'domprefs';
3766: my $crstype = 'Course';
3767: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 3768: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 3769: my ($numstatustypes,@jsarray);
3770: if (ref($types) eq 'ARRAY') {
3771: if (@{$types} > 0) {
3772: $numstatustypes = scalar(@{$types});
3773: push(@accesstypes,'status');
3774: @jsarray = ('bystatus');
1.282 raeburn 3775: }
3776: }
1.290 raeburn 3777: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 3778: if (keys(%domhelpdesk)) {
3779: push(@accesstypes,('inc','exc'));
3780: push(@jsarray,('notinc','notexc'));
3781: }
3782: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 3783: my $context = 'domprefs';
3784: my $crstype = 'Course';
1.285 raeburn 3785: my $prefix = 'helproles_';
3786: my $add_class = 'LC_hidden';
3787: foreach my $num (@roles_by_num) {
3788: my $role = $ordered{$num};
3789: my ($desc,$access,@statuses);
3790: if (ref($current{$role}) eq 'HASH') {
3791: $desc = $current{$role}{'desc'};
3792: $access = $current{$role}{'access'};
3793: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3794: @statuses = @{$current{$role}{'insttypes'}};
3795: }
3796: }
3797: if ($desc eq '') {
3798: $desc = $role;
3799: }
3800: my $identifier = 'custhelp'.$num;
1.282 raeburn 3801: my %full=();
3802: my %levels= (
3803: course => {},
3804: domain => {},
3805: system => {},
3806: );
3807: my %levelscurrent=(
3808: course => {},
3809: domain => {},
3810: system => {},
3811: );
3812: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3813: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3814: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 3815: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 3816: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 3817: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3818: for (my $k=0; $k<=$maxnum; $k++) {
3819: my $vpos = $k+1;
3820: my $selstr;
3821: if ($k == $num) {
3822: $selstr = ' selected="selected" ';
3823: }
3824: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3825: }
3826: $datatable .= '</select>'.(' 'x2).
3827: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3828: '</td>'.
3829: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3830: &mt('Name shown to users:').
3831: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3832: '</fieldset>'.
3833: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3834: $othertitle,$usertypes,$types,\%domhelpdesk).
3835: '<fieldset>'.
3836: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 3837: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 3838: \%levelscurrent,$identifier,
3839: 'LC_hidden',$prefix.$num.'_privs').
3840: '</fieldset></td>';
1.282 raeburn 3841: $itemcount ++;
3842: }
3843: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3844: my $newcust = 'custhelp'.$count;
3845: my (%privs,%levelscurrent);
3846: my %full=();
3847: my %levels= (
3848: course => {},
3849: domain => {},
3850: system => {},
3851: );
3852: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3853: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 3854: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 3855: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 3856: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3857: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3858: for (my $k=0; $k<$maxnum+1; $k++) {
3859: my $vpos = $k+1;
3860: my $selstr;
3861: if ($k == $maxnum) {
3862: $selstr = ' selected="selected" ';
3863: }
3864: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3865: }
3866: $datatable .= '</select> '."\n".
1.282 raeburn 3867: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3868: '</label></span></td>'.
1.285 raeburn 3869: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3870: '<span class="LC_nobreak">'.
3871: &mt('Internal name:').
3872: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3873: '</span>'.(' 'x4).
3874: '<span class="LC_nobreak">'.
3875: &mt('Name shown to users:').
3876: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3877: '</span></fieldset>'.
3878: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3879: $usertypes,$types,\%domhelpdesk).
3880: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 3881: &Apache::lonuserutils::custom_role_header($context,$crstype,
3882: \@templateroles,$newcust).
3883: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3884: \%levelscurrent,$newcust).
1.334 raeburn 3885: '</fieldset>'.
3886: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
3887: '</td></tr>';
1.282 raeburn 3888: $count ++;
3889: $$rowtotal += $count;
3890: }
1.166 raeburn 3891: return $datatable;
1.121 raeburn 3892: }
3893:
1.285 raeburn 3894: sub adhocbutton {
3895: my ($prefix,$num,$field,$visibility) = @_;
3896: my %lt = &Apache::lonlocal::texthash(
3897: show => 'Show details',
3898: hide => 'Hide details',
3899: );
3900: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3901: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3902: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3903: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3904: }
3905:
3906: sub helpsettings_javascript {
3907: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3908: return unless(ref($roles_by_num) eq 'ARRAY');
3909: my %html_js_lt = &Apache::lonlocal::texthash(
3910: show => 'Show details',
3911: hide => 'Hide details',
3912: );
3913: &html_escape(\%html_js_lt);
3914: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3915: return <<"ENDSCRIPT";
3916: <script type="text/javascript">
3917: // <![CDATA[
3918:
3919: function reorderHelpRoles(form,item) {
3920: var changedVal;
3921: $jstext
3922: var newpos = 'helproles_${total}_pos';
3923: var maxh = 1 + $total;
3924: var current = new Array();
3925: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3926: if (item == newpos) {
3927: changedVal = newitemVal;
3928: } else {
3929: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3930: current[newitemVal] = newpos;
3931: }
3932: for (var i=0; i<helproles.length; i++) {
3933: var elementName = 'helproles_'+helproles[i]+'_pos';
3934: if (elementName != item) {
3935: if (form.elements[elementName]) {
3936: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3937: current[currVal] = elementName;
3938: }
3939: }
3940: }
3941: var oldVal;
3942: for (var j=0; j<maxh; j++) {
3943: if (current[j] == undefined) {
3944: oldVal = j;
3945: }
3946: }
3947: if (oldVal < changedVal) {
3948: for (var k=oldVal+1; k<=changedVal ; k++) {
3949: var elementName = current[k];
3950: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3951: }
3952: } else {
3953: for (var k=changedVal; k<oldVal; k++) {
3954: var elementName = current[k];
3955: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3956: }
3957: }
3958: return;
3959: }
3960:
3961: function helpdeskAccess(num) {
3962: var curraccess = null;
3963: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3964: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3965: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3966: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3967: }
3968: }
3969: }
3970: var shown = Array();
3971: var hidden = Array();
3972: if (curraccess == 'none') {
3973: hidden = Array('$hiddenstr');
3974: } else {
3975: if (curraccess == 'status') {
3976: shown = Array('bystatus');
3977: hidden = Array('notinc','notexc');
3978: } else {
3979: if (curraccess == 'exc') {
3980: shown = Array('notexc');
3981: hidden = Array('notinc','bystatus');
3982: }
3983: if (curraccess == 'inc') {
3984: shown = Array('notinc');
3985: hidden = Array('notexc','bystatus');
3986: }
1.293 raeburn 3987: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 3988: hidden = Array('notinc','notexc','bystatus');
3989: }
3990: }
3991: }
3992: if (hidden.length > 0) {
3993: for (var i=0; i<hidden.length; i++) {
3994: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3995: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3996: }
3997: }
3998: }
3999: if (shown.length > 0) {
4000: for (var i=0; i<shown.length; i++) {
4001: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
4002: if (shown[i] == 'privs') {
4003: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4004: } else {
4005: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4006: }
4007: }
4008: }
4009: }
4010: return;
4011: }
4012:
4013: function toggleHelpdeskItem(num,field) {
4014: if (document.getElementById('helproles_'+num+'_'+field)) {
4015: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 4016: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 4017: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4018: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4019: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4020: }
4021: } else {
4022: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4023: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4024: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4025: }
4026: }
4027: }
4028: return;
4029: }
4030:
4031: // ]]>
4032: </script>
4033:
4034: ENDSCRIPT
4035: }
4036:
4037: sub helpdeskroles_access {
4038: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4039: $usertypes,$types,$domhelpdesk) = @_;
4040: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
4041: my %lt = &Apache::lonlocal::texthash(
4042: 'rou' => 'Role usage',
4043: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 4044: 'all' => 'All with domain helpdesk or helpdesk assistant role',
4045: 'dh' => 'All with domain helpdesk role',
4046: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 4047: 'none' => 'None',
4048: 'status' => 'Determined based on institutional status',
4049: 'inc' => 'Include all, but exclude specific personnel',
4050: 'exc' => 'Exclude all, but include specific personnel',
4051: );
4052: my %usecheck = (
4053: all => ' checked="checked"',
4054: );
4055: my %displaydiv = (
4056: status => 'none',
4057: inc => 'none',
4058: exc => 'none',
4059: priv => 'block',
4060: );
4061: my $output;
4062: if (ref($current) eq 'HASH') {
4063: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
4064: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
4065: $usecheck{$current->{access}} = $usecheck{'all'};
4066: delete($usecheck{'all'});
4067: if ($current->{access} =~ /^(status|inc|exc)$/) {
4068: my $access = $1;
4069: $displaydiv{$access} = 'inline';
4070: } elsif ($current->{access} eq 'none') {
4071: $displaydiv{'priv'} = 'none';
4072: }
4073: }
4074: }
4075: }
4076: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
4077: '<p>'.$lt{'whi'}.'</p>';
4078: foreach my $access (@{$accesstypes}) {
4079: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
4080: ' onclick="helpdeskAccess('."'$num'".');" />'.
4081: $lt{$access}.'</label>';
4082: if ($access eq 'status') {
4083: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
4084: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
4085: $othertitle,$usertypes,$types).
4086: '</div>';
4087: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
4088: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
4089: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4090: '</div>';
4091: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
4092: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
4093: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4094: '</div>';
4095: }
4096: $output .= '</p>';
4097: }
4098: $output .= '</fieldset>';
4099: return $output;
4100: }
4101:
1.121 raeburn 4102: sub radiobutton_prefs {
1.192 raeburn 4103: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 4104: $additional,$align) = @_;
1.121 raeburn 4105: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
4106: (ref($choices) eq 'HASH'));
4107:
1.170 raeburn 4108: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 4109:
4110: foreach my $item (@{$toggles}) {
4111: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 4112: $checkedon{$item} = ' checked="checked" ';
4113: $checkedoff{$item} = ' ';
1.121 raeburn 4114: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 4115: $checkedoff{$item} = ' checked="checked" ';
4116: $checkedon{$item} = ' ';
4117: }
4118: }
4119: if (ref($settings) eq 'HASH') {
1.121 raeburn 4120: foreach my $item (@{$toggles}) {
1.118 jms 4121: if ($settings->{$item} eq '1') {
4122: $checkedon{$item} = ' checked="checked" ';
4123: $checkedoff{$item} = ' ';
4124: } elsif ($settings->{$item} eq '0') {
4125: $checkedoff{$item} = ' checked="checked" ';
4126: $checkedon{$item} = ' ';
4127: }
4128: }
1.121 raeburn 4129: }
1.192 raeburn 4130: if ($onclick) {
4131: $onclick = ' onclick="'.$onclick.'"';
4132: }
1.121 raeburn 4133: foreach my $item (@{$toggles}) {
1.118 jms 4134: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 4135: $datatable .=
1.306 raeburn 4136: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 4137: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 4138: '</span></td>';
4139: if ($align eq 'left') {
4140: $datatable .= '<td class="LC_left_item">';
4141: } else {
4142: $datatable .= '<td class="LC_right_item">';
4143: }
1.289 raeburn 4144: $datatable .=
1.257 raeburn 4145: '<span class="LC_nobreak">'.
1.118 jms 4146: '<label><input type="radio" name="'.
1.192 raeburn 4147: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 4148: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 4149: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
4150: '</span>'.$additional.
4151: '</td>'.
1.118 jms 4152: '</tr>';
4153: $itemcount ++;
1.121 raeburn 4154: }
4155: return ($datatable,$itemcount);
4156: }
4157:
1.267 raeburn 4158: sub print_ltitools {
4159: my ($dom,$settings,$rowtotal) = @_;
4160: my $rownum = 0;
4161: my $css_class;
4162: my $itemcount = 1;
4163: my $maxnum = 0;
4164: my %ordered;
4165: if (ref($settings) eq 'HASH') {
4166: foreach my $item (keys(%{$settings})) {
4167: if (ref($settings->{$item}) eq 'HASH') {
4168: my $num = $settings->{$item}{'order'};
4169: $ordered{$num} = $item;
4170: }
4171: }
4172: }
4173: my $confname = $dom.'-domainconfig';
4174: my $switchserver = &check_switchserver($dom,$confname);
4175: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 4176: my $datatable;
1.267 raeburn 4177: my %lt = <itools_names();
4178: my @courseroles = ('cc','in','ta','ep','st');
4179: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1.324 raeburn 4180: my @fields = ('fullname','firstname','lastname','email','roles','user');
1.267 raeburn 4181: if (keys(%ordered)) {
4182: my @items = sort { $a <=> $b } keys(%ordered);
4183: for (my $i=0; $i<@items; $i++) {
4184: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4185: my $item = $ordered{$items[$i]};
1.323 raeburn 4186: my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
1.267 raeburn 4187: if (ref($settings->{$item}) eq 'HASH') {
4188: $title = $settings->{$item}->{'title'};
4189: $url = $settings->{$item}->{'url'};
4190: $key = $settings->{$item}->{'key'};
4191: $secret = $settings->{$item}->{'secret'};
1.322 raeburn 4192: $lifetime = $settings->{$item}->{'lifetime'};
1.267 raeburn 4193: my $image = $settings->{$item}->{'image'};
4194: if ($image ne '') {
4195: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
4196: }
1.323 raeburn 4197: if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
4198: $sigsel{'HMAC-256'} = ' selected="selected"';
4199: } else {
4200: $sigsel{'HMAC-SHA1'} = ' selected="selected"';
4201: }
1.267 raeburn 4202: }
1.319 raeburn 4203: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1.267 raeburn 4204: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4205: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
4206: for (my $k=0; $k<=$maxnum; $k++) {
4207: my $vpos = $k+1;
4208: my $selstr;
4209: if ($k == $i) {
4210: $selstr = ' selected="selected" ';
4211: }
4212: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4213: }
4214: $datatable .= '</select>'.(' 'x2).
4215: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
4216: &mt('Delete?').'</label></span></td>'.
4217: '<td colspan="2">'.
4218: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4219: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
1.267 raeburn 4220: (' 'x2).
4221: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
4222: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4223: (' 'x2).
4224: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
4225: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4226: (' 'x2).
4227: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
4228: '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
4229: '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
1.267 raeburn 4230: '<br /><br />'.
1.323 raeburn 4231: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
1.267 raeburn 4232: ' value="'.$url.'" /></span>'.
4233: (' 'x2).
1.319 raeburn 4234: '<span class="LC_nobreak">'.$lt{'key'}.':'.
1.267 raeburn 4235: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
4236: (' 'x2).
1.322 raeburn 4237: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
4238: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
4239: (' 'x2).
1.267 raeburn 4240: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4241: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
4242: '<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>'.
4243: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
4244: '</fieldset>'.
4245: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4246: '<span class="LC_nobreak">'.&mt('Display target:');
4247: my %currdisp;
4248: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
4249: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
4250: $currdisp{'window'} = ' checked="checked"';
1.298 raeburn 4251: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
4252: $currdisp{'tab'} = ' checked="checked"';
1.267 raeburn 4253: } else {
4254: $currdisp{'iframe'} = ' checked="checked"';
4255: }
4256: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
4257: $currdisp{'width'} = $1;
4258: }
4259: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
4260: $currdisp{'height'} = $1;
4261: }
1.296 raeburn 4262: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
4263: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267 raeburn 4264: } else {
4265: $currdisp{'iframe'} = ' checked="checked"';
4266: }
1.298 raeburn 4267: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4268: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
4269: $lt{$disp}.'</label>'.(' 'x2);
4270: }
4271: $datatable .= (' 'x4);
4272: foreach my $dimen ('width','height') {
4273: $datatable .= '<label>'.$lt{$dimen}.' '.
4274: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
4275: (' 'x2);
4276: }
1.334 raeburn 4277: $datatable .= '</span><br />'.
1.296 raeburn 4278: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 4279: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
1.296 raeburn 4280: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4281: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
4282: '</textarea></div><div style=""></div><br />';
1.319 raeburn 4283: my %units = (
4284: 'passback' => 'days',
4285: 'roster' => 'seconds',
4286: );
1.267 raeburn 4287: foreach my $extra ('passback','roster') {
1.319 raeburn 4288: my $validsty = 'none';
4289: my $currvalid;
1.267 raeburn 4290: my $checkedon = '';
4291: my $checkedoff = ' checked="checked"';
4292: if ($settings->{$item}->{$extra}) {
4293: $checkedon = $checkedoff;
4294: $checkedoff = '';
1.319 raeburn 4295: $validsty = 'inline-block';
4296: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
4297: $currvalid = $settings->{$item}->{$extra.'valid'};
4298: }
4299: }
4300: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
4301: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4302: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
4303: &mt('No').'</label>'.(' 'x2).
4304: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
4305: &mt('Yes').'</label></span></div>'.
4306: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
4307: '<span class="LC_nobreak">'.
4308: &mt("at least [_1] $units{$extra} after launch",
4309: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
4310: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4311: }
1.319 raeburn 4312: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
1.267 raeburn 4313: if ($imgsrc) {
4314: $datatable .= $imgsrc.
4315: '<label><input type="checkbox" name="ltitools_image_del"'.
4316: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
4317: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
4318: } else {
4319: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4320: }
4321: if ($switchserver) {
4322: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4323: } else {
4324: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
4325: }
4326: $datatable .= '</span></fieldset>';
1.324 raeburn 4327: my (%checkedfields,%rolemaps,$userincdom);
1.267 raeburn 4328: if (ref($settings->{$item}) eq 'HASH') {
4329: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
4330: %checkedfields = %{$settings->{$item}->{'fields'}};
4331: }
1.324 raeburn 4332: $userincdom = $settings->{$item}->{'incdom'};
1.267 raeburn 4333: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
4334: %rolemaps = %{$settings->{$item}->{'roles'}};
4335: $checkedfields{'roles'} = 1;
4336: }
4337: }
4338: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4339: '<span class="LC_nobreak">';
1.324 raeburn 4340: my $userfieldstyle = 'display:none;';
4341: my $seluserdom = '';
4342: my $unseluserdom = ' selected="selected"';
1.267 raeburn 4343: foreach my $field (@fields) {
1.324 raeburn 4344: my ($checked,$onclick,$id,$spacer);
1.267 raeburn 4345: if ($checkedfields{$field}) {
4346: $checked = ' checked="checked"';
4347: }
1.324 raeburn 4348: if ($field eq 'user') {
4349: $id = ' id="ltitools_user_field_'.$i.'"';
4350: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
4351: if ($checked) {
4352: $userfieldstyle = 'display:inline-block';
4353: if ($userincdom) {
4354: $seluserdom = $unseluserdom;
4355: $unseluserdom = '';
4356: }
4357: }
4358: } else {
4359: $spacer = (' ' x2);
4360: }
1.267 raeburn 4361: $datatable .= '<label>'.
1.324 raeburn 4362: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
4363: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 4364: }
1.324 raeburn 4365: $datatable .= '</span>';
4366: $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
4367: '<span class="LC_nobreak"> : '.
4368: '<select name="ltitools_userincdom_'.$i.'">'.
4369: '<option value="">'.&mt('Select').'</option>'.
4370: '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
4371: '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
4372: '</select></span></div>';
4373: $datatable .= '</fieldset>'.
1.267 raeburn 4374: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4375: foreach my $role (@courseroles) {
4376: my ($selected,$selectnone);
4377: if (!$rolemaps{$role}) {
4378: $selectnone = ' selected="selected"';
4379: }
1.306 raeburn 4380: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4381: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4382: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
4383: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
4384: foreach my $ltirole (@ltiroles) {
4385: unless ($selectnone) {
4386: if ($rolemaps{$role} eq $ltirole) {
4387: $selected = ' selected="selected"';
4388: } else {
4389: $selected = '';
4390: }
4391: }
4392: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
4393: }
4394: $datatable .= '</select></td>';
4395: }
1.273 raeburn 4396: $datatable .= '</tr></table></fieldset>';
4397: my %courseconfig;
4398: if (ref($settings->{$item}) eq 'HASH') {
4399: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
4400: %courseconfig = %{$settings->{$item}->{'crsconf'}};
4401: }
4402: }
4403: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4404: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 4405: my $checked;
4406: if ($courseconfig{$item}) {
4407: $checked = ' checked="checked"';
4408: }
4409: $datatable .= '<label>'.
4410: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
4411: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
4412: }
4413: $datatable .= '</span></fieldset>'.
1.267 raeburn 4414: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4415: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
4416: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
4417: my %custom = %{$settings->{$item}->{'custom'}};
4418: if (keys(%custom) > 0) {
4419: foreach my $key (sort(keys(%custom))) {
4420: $datatable .= '<tr><td><span class="LC_nobreak">'.
4421: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
4422: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
4423: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
4424: ' value="'.$custom{$key}.'" /></td></tr>';
4425: }
4426: }
4427: }
4428: $datatable .= '<tr><td><span class="LC_nobreak">'.
4429: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
4430: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
4431: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
4432: $datatable .= '</table></fieldset></td></tr>'."\n";
4433: $itemcount ++;
4434: }
4435: }
4436: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.319 raeburn 4437: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1.267 raeburn 4438: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4439: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
4440: '<select name="ltitools_add_pos"'.$chgstr.'>';
4441: for (my $k=0; $k<$maxnum+1; $k++) {
4442: my $vpos = $k+1;
4443: my $selstr;
4444: if ($k == $maxnum) {
4445: $selstr = ' selected="selected" ';
4446: }
4447: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4448: }
4449: $datatable .= '</select> '."\n".
1.334 raeburn 4450: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.267 raeburn 4451: '<td colspan="2">'.
4452: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4453: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
1.267 raeburn 4454: (' 'x2).
4455: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
4456: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4457: (' 'x2).
4458: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
4459: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4460: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
4461: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
4462: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
1.267 raeburn 4463: '<br />'.
1.323 raeburn 4464: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
1.267 raeburn 4465: (' 'x2).
4466: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
4467: (' 'x2).
1.322 raeburn 4468: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
4469: (' 'x2).
1.267 raeburn 4470: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
4471: '<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".
4472: '</fieldset>'.
4473: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4474: '<span class="LC_nobreak">'.&mt('Display target:');
4475: my %defaultdisp;
4476: $defaultdisp{'iframe'} = ' checked="checked"';
1.298 raeburn 4477: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4478: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
4479: $lt{$disp}.'</label>'.(' 'x2);
4480: }
4481: $datatable .= (' 'x4);
4482: foreach my $dimen ('width','height') {
4483: $datatable .= '<label>'.$lt{$dimen}.' '.
4484: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
4485: (' 'x2);
4486: }
1.334 raeburn 4487: $datatable .= '</span><br />'.
1.296 raeburn 4488: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 4489: '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
1.296 raeburn 4490: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
1.334 raeburn 4491: '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
1.296 raeburn 4492: '</div><div style=""></div><br />';
1.319 raeburn 4493: my %units = (
4494: 'passback' => 'days',
4495: 'roster' => 'seconds',
4496: );
4497: my %defaulttimes = (
4498: 'passback' => '7',
1.322 raeburn 4499: 'roster' => '300',
1.319 raeburn 4500: );
1.267 raeburn 4501: foreach my $extra ('passback','roster') {
1.319 raeburn 4502: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
4503: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4504: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
4505: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
4506: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
4507: &mt('Yes').'</label></span></div>'.
4508: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
4509: '<span class="LC_nobreak">'.
4510: &mt("at least [_1] $units{$extra} after launch",
4511: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
4512: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4513: }
1.319 raeburn 4514: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
1.267 raeburn 4515: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4516: if ($switchserver) {
4517: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4518: } else {
4519: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
4520: }
4521: $datatable .= '</span></fieldset>'.
4522: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4523: '<span class="LC_nobreak">';
4524: foreach my $field (@fields) {
1.324 raeburn 4525: my ($id,$onclick,$spacer);
4526: if ($field eq 'user') {
4527: $id = ' id="ltitools_user_field_add"';
4528: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
4529: } else {
4530: $spacer = (' ' x2);
4531: }
1.267 raeburn 4532: $datatable .= '<label>'.
1.324 raeburn 4533: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
4534: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 4535: }
1.324 raeburn 4536: $datatable .= '</span>'.
4537: '<div style="display:none;" id="ltitools_user_div_add">'.
4538: '<span class="LC_nobreak"> : '.
4539: '<select name="ltitools_userincdom_add">'.
4540: '<option value="" selected="selected">'.&mt('Select').'</option>'.
4541: '<option value="0">'.&mt('username').'</option>'.
4542: '<option value="1">'.&mt('username:domain').'</option>'.
4543: '</select></span></div></fieldset>';
4544: $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
1.267 raeburn 4545: foreach my $role (@courseroles) {
4546: my ($checked,$checkednone);
1.306 raeburn 4547: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4548: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4549: '<select name="ltitools_add_roles_'.$role.'">'.
4550: '<option value="" selected="selected">'.&mt('Select').'</option>';
4551: foreach my $ltirole (@ltiroles) {
4552: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
4553: }
4554: $datatable .= '</select></td>';
4555: }
4556: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 4557: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4558: foreach my $item ('label','title','target','linktext','explanation','append') {
1.296 raeburn 4559: $datatable .= '<label>'.
4560: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
4561: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
1.273 raeburn 4562: }
4563: $datatable .= '</span></fieldset>'.
1.267 raeburn 4564: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4565: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
4566: '<tr><td><span class="LC_nobreak">'.
4567: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
4568: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
4569: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
1.334 raeburn 4570: '</table></fieldset>'."\n".
1.267 raeburn 4571: '</td>'."\n".
4572: '</tr>'."\n";
4573: $itemcount ++;
4574: return $datatable;
4575: }
4576:
4577: sub ltitools_names {
4578: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 4579: 'title' => 'Title',
4580: 'version' => 'Version',
4581: 'msgtype' => 'Message Type',
1.323 raeburn 4582: 'sigmethod' => 'Signature Method',
1.296 raeburn 4583: 'url' => 'URL',
4584: 'key' => 'Key',
1.322 raeburn 4585: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 4586: 'secret' => 'Secret',
4587: 'icon' => 'Icon',
1.324 raeburn 4588: 'user' => 'User',
1.296 raeburn 4589: 'fullname' => 'Full Name',
4590: 'firstname' => 'First Name',
4591: 'lastname' => 'Last Name',
4592: 'email' => 'E-mail',
4593: 'roles' => 'Role',
1.298 raeburn 4594: 'window' => 'Window',
4595: 'tab' => 'Tab',
1.296 raeburn 4596: 'iframe' => 'iFrame',
4597: 'height' => 'Height',
4598: 'width' => 'Width',
4599: 'linktext' => 'Default Link Text',
4600: 'explanation' => 'Default Explanation',
4601: 'passback' => 'Tool can return grades:',
4602: 'roster' => 'Tool can retrieve roster:',
4603: 'crstarget' => 'Display target',
4604: 'crslabel' => 'Course label',
4605: 'crstitle' => 'Course title',
4606: 'crslinktext' => 'Link Text',
4607: 'crsexplanation' => 'Explanation',
1.318 raeburn 4608: 'crsappend' => 'Provider URL',
1.267 raeburn 4609: );
4610: return %lt;
4611: }
4612:
1.320 raeburn 4613: sub print_lti {
4614: my ($dom,$settings,$rowtotal) = @_;
4615: my $itemcount = 1;
4616: my $maxnum = 0;
4617: my $css_class;
4618: my %ordered;
4619: if (ref($settings) eq 'HASH') {
4620: foreach my $item (keys(%{$settings})) {
4621: if (ref($settings->{$item}) eq 'HASH') {
4622: my $num = $settings->{$item}{'order'};
4623: $ordered{$num} = $item;
4624: }
4625: }
4626: }
4627: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 4628: my $datatable;
1.320 raeburn 4629: my %lt = <i_names();
4630: if (keys(%ordered)) {
4631: my @items = sort { $a <=> $b } keys(%ordered);
4632: for (my $i=0; $i<@items; $i++) {
4633: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4634: my $item = $ordered{$items[$i]};
4635: my ($key,$secret,$lifetime,$consumer,$current);
4636: if (ref($settings->{$item}) eq 'HASH') {
4637: $key = $settings->{$item}->{'key'};
4638: $secret = $settings->{$item}->{'secret'};
4639: $lifetime = $settings->{$item}->{'lifetime'};
4640: $consumer = $settings->{$item}->{'consumer'};
4641: $current = $settings->{$item};
4642: }
4643: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
4644: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4645: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
4646: for (my $k=0; $k<=$maxnum; $k++) {
4647: my $vpos = $k+1;
4648: my $selstr;
4649: if ($k == $i) {
4650: $selstr = ' selected="selected" ';
4651: }
4652: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4653: }
4654: $datatable .= '</select>'.(' 'x2).
4655: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
4656: &mt('Delete?').'</label></span></td>'.
4657: '<td colspan="2">'.
4658: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4659: '<span class="LC_nobreak">'.$lt{'consumer'}.
4660: ':<input type="text" size="20" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
4661: (' 'x2).
4662: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
4663: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4664: (' 'x2).
4665: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
4666: 'value="'.$lifetime.'" size="5" /></span>'.
4667: '<br /><br />'.
4668: '<span class="LC_nobreak">'.$lt{'key'}.
4669: ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
4670: (' 'x2).
4671: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4672: '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
4673: '<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>'.
4674: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
1.325 raeburn 4675: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
1.320 raeburn 4676: $itemcount ++;
4677: }
4678: }
4679: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4680: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
4681: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4682: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
4683: '<select name="lti_pos_add"'.$chgstr.'>';
4684: for (my $k=0; $k<$maxnum+1; $k++) {
4685: my $vpos = $k+1;
4686: my $selstr;
4687: if ($k == $maxnum) {
4688: $selstr = ' selected="selected" ';
4689: }
4690: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4691: }
4692: $datatable .= '</select> '."\n".
1.334 raeburn 4693: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.320 raeburn 4694: '<td colspan="2">'.
4695: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4696: '<span class="LC_nobreak">'.$lt{'consumer'}.
4697: ':<input type="text" size="20" name="lti_consumer_add" value="" /></span> '."\n".
4698: (' 'x2).
4699: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
4700: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4701: (' 'x2).
1.322 raeburn 4702: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="lti_lifetime_add" value="300" /></span> '."\n".
1.320 raeburn 4703: '<br /><br />'.
4704: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
4705: (' 'x2).
4706: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
4707: '<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 4708: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
1.320 raeburn 4709: '</td>'."\n".
4710: '</tr>'."\n";
4711: $$rowtotal ++;
4712: return $datatable;;
4713: }
4714:
4715: sub lti_names {
4716: my %lt = &Apache::lonlocal::texthash(
4717: 'version' => 'LTI Version',
4718: 'url' => 'URL',
4719: 'key' => 'Key',
1.322 raeburn 4720: 'lifetime' => 'Nonce lifetime (s)',
1.320 raeburn 4721: 'consumer' => 'LTI Consumer',
4722: 'secret' => 'Secret',
4723: 'email' => 'Email address',
4724: 'sourcedid' => 'User ID',
4725: 'other' => 'Other',
4726: 'passback' => 'Can return grades to Consumer:',
4727: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 4728: 'topmenu' => 'Display LON-CAPA page header',
4729: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 4730: );
4731: return %lt;
4732: }
4733:
4734: sub lti_options {
1.325 raeburn 4735: my ($num,$current,$itemcount,%lt) = @_;
1.320 raeburn 4736: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield);
4737: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
4738: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
4739: $checked{'makecrs'}{'N'} = ' checked="checked"';
4740: $checked{'mapcrstype'} = {};
4741: $checked{'makeuser'} = {};
4742: $checked{'selfenroll'} = {};
4743: $checked{'crssec'} = {};
4744: $checked{'crssecsrc'} = {};
1.325 raeburn 4745: $checked{'lcauth'} = {};
1.326 raeburn 4746: $checked{'menuitem'} = {};
1.325 raeburn 4747: if ($num eq 'add') {
4748: $checked{'lcauth'}{'lti'} = ' checked="checked"';
4749: }
1.320 raeburn 4750: my $userfieldsty = 'none';
4751: my $crsfieldsty = 'none';
4752: my $crssecfieldsty = 'none';
4753: my $secsrcfieldsty = 'none';
1.325 raeburn 4754: my $lcauthparm;
4755: my $lcauthparmstyle = 'display:none';
4756: my $lcauthparmtext;
1.326 raeburn 4757: my $menusty;
1.325 raeburn 4758: my $numinrow = 4;
1.326 raeburn 4759: my %menutitles = <imenu_titles();
1.320 raeburn 4760:
4761: if (ref($current) eq 'HASH') {
4762: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
4763: $checked{'mapuser'}{'sourcedid'} = '';
4764: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
4765: $checked{'mapuser'}{'email'} = ' checked="checked"';
4766: } else {
4767: $checked{'mapuser'}{'other'} = ' checked="checked"';
4768: $userfield = $current->{'mapuser'};
4769: $userfieldsty = 'inline-block';
4770: }
4771: }
4772: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
4773: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
4774: if ($current->{'mapcrs'} eq 'context_id') {
4775: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
4776: } else {
4777: $checked{'mapcrs'}{'other'} = ' checked="checked"';
4778: $cidfield = $current->{'mapcrs'};
4779: $crsfieldsty = 'inline-block';
4780: }
4781: }
4782: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
4783: foreach my $type (@{$current->{'mapcrstype'}}) {
4784: $checked{'mapcrstype'}{$type} = ' checked="checked"';
4785: }
4786: }
4787: if ($current->{'makecrs'}) {
4788: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 4789: }
1.320 raeburn 4790: if (ref($current->{'makeuser'}) eq 'ARRAY') {
4791: foreach my $role (@{$current->{'makeuser'}}) {
4792: $checked{'makeuser'}{$role} = ' checked="checked"';
4793: }
4794: }
1.325 raeburn 4795: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
4796: $checked{'lcauth'}{$1} = ' checked="checked"';
4797: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
4798: $lcauthparm = $current->{'lcauthparm'};
4799: $lcauthparmstyle = 'display:table-row';
4800: if ($current->{'lcauth'} eq 'localauth') {
4801: $lcauthparmtext = &mt('Local auth argument');
4802: } else {
4803: $lcauthparmtext = &mt('Kerberos domain');
4804: }
4805: }
4806: }
1.320 raeburn 4807: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
4808: foreach my $role (@{$current->{'selfenroll'}}) {
4809: $checked{'selfenroll'}{$role} = ' checked="checked"';
4810: }
4811: }
4812: if (ref($current->{'maproles'}) eq 'HASH') {
4813: %rolemaps = %{$current->{'maproles'}};
4814: }
4815: if ($current->{'section'} ne '') {
4816: $checked{'crssec'}{'Y'} = ' checked="checked"';
4817: $crssecfieldsty = 'inline-block';
4818: if ($current->{'section'} eq 'course_section_sourcedid') {
4819: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
4820: } else {
4821: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
4822: $crssecsrc = $current->{'section'};
4823: $secsrcfieldsty = 'inline-block';
4824: }
4825: } else {
4826: $checked{'crssec'}{'N'} = ' checked="checked"';
4827: }
1.326 raeburn 4828: if ($current->{'topmenu'}) {
4829: $checked{'topmenu'}{'Y'} = ' checked="checked"';
4830: } else {
4831: $checked{'topmenu'}{'N'} = ' checked="checked"';
4832: }
4833: if ($current->{'inlinemenu'}) {
4834: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
4835: } else {
4836: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
4837: }
4838: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
4839: $menusty = 'inline-block';
4840: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
4841: foreach my $item (@{$current->{'lcmenu'}}) {
4842: if (exists($menutitles{$item})) {
4843: $checked{'menuitem'}{$item} = ' checked="checked"';
4844: }
4845: }
4846: }
4847: } else {
4848: $menusty = 'none';
4849: }
1.320 raeburn 4850: } else {
4851: $checked{'makecrs'}{'N'} = ' checked="checked"';
4852: $checked{'crssec'}{'N'} = ' checked="checked"';
1.326 raeburn 4853: $checked{'topmenu'}{'N'} = ' checked="checked"';
4854: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
4855: $checked{'menuitem'}{'grades'} = ' checked="checked"';
4856: $menusty = 'inline-block';
1.320 raeburn 4857: }
1.325 raeburn 4858: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 4859: my %coursetypetitles = &Apache::lonlocal::texthash (
4860: official => 'Official',
4861: unofficial => 'Unofficial',
4862: community => 'Community',
4863: textbook => 'Textbook',
4864: placement => 'Placement Test',
1.325 raeburn 4865: lti => 'LTI Provider',
1.320 raeburn 4866: );
1.325 raeburn 4867: my @authtypes = ('internal','krb4','krb5','localauth');
4868: my %shortauth = (
4869: internal => 'int',
4870: krb4 => 'krb4',
4871: krb5 => 'krb5',
4872: localauth => 'loc'
4873: );
4874: my %authnames = &authtype_names();
1.320 raeburn 4875: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
4876: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
4877: my @courseroles = ('cc','in','ta','ep','st');
4878: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
4879: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
4880: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
4881: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 4882: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 4883: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.320 raeburn 4884: my $output = '<fieldset><legend>'.&mt('Mapping users').'</legend>'.
4885: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
4886: foreach my $option ('sourcedid','email','other') {
4887: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
4888: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
4889: ($option eq 'other' ? '' : (' 'x2) );
4890: }
4891: $output .= '</span></div>'.
4892: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
4893: '<input type="text" name="lti_customuser_'.$num.'" '.
4894: 'value="'.$userfield.'" /></div></fieldset>'.
4895: '<fieldset><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
4896: foreach my $ltirole (@lticourseroles) {
4897: my ($selected,$selectnone);
4898: if ($rolemaps{$ltirole} eq '') {
4899: $selectnone = ' selected="selected"';
4900: }
4901: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
4902: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
4903: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
4904: foreach my $role (@courseroles) {
4905: unless ($selectnone) {
4906: if ($rolemaps{$ltirole} eq $role) {
4907: $selected = ' selected="selected"';
4908: } else {
4909: $selected = '';
4910: }
4911: }
4912: $output .= '<option value="'.$role.'"'.$selected.'>'.
4913: &Apache::lonnet::plaintext($role,'Course').
4914: '</option>';
4915: }
4916: $output .= '</select></td>';
4917: }
4918: $output .= '</tr></table></fieldset>'.
4919: '<fieldset><legend>'.&mt('Roles which may create user accounts').'</legend>';
4920: foreach my $ltirole (@ltiroles) {
4921: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
4922: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
4923: }
4924: $output .= '</fieldset>'.
1.325 raeburn 4925: '<fieldset><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
4926: '<table>'.
4927: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
4928: '</table>'.
4929: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
4930: '<td class="LC_left_item">';
4931: foreach my $auth ('lti',@authtypes) {
4932: my $authtext;
4933: if ($auth eq 'lti') {
4934: $authtext = &mt('None');
4935: } else {
4936: $authtext = $authnames{$shortauth{$auth}};
4937: }
4938: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
4939: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
4940: $authtext.'</label></span> ';
4941: }
4942: $output .= '</td></tr>'.
4943: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
4944: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
4945: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
4946: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
4947: '</table></fieldset>'.
1.320 raeburn 4948: '<fieldset><legend>'.&mt('Mapping courses').'</legend>'.
4949: '<div class="LC_floatleft"><span class="LC_nobreak">'.
4950: &mt('Unique course identifier').': ';
4951: foreach my $option ('course_offering_sourcedid','context_id','other') {
4952: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
4953: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
4954: ($option eq 'other' ? '' : (' 'x2) );
4955: }
1.334 raeburn 4956: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 4957: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
4958: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
4959: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
4960: foreach my $type (@coursetypes) {
4961: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
4962: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
4963: (' 'x2);
4964: }
4965: $output .= '</span></fieldset>'.
4966: '<fieldset><legend>'.&mt('Creating courses').'</legend>'.
4967: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
4968: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
4969: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
4970: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
4971: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
4972: '</fieldset>'.
4973: '<fieldset><legend>'.&mt('Roles which may self-enroll').'</legend>';
4974: foreach my $lticrsrole (@lticourseroles) {
4975: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
4976: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
4977: }
4978: $output .= '</fieldset>'.
4979: '<fieldset><legend>'.&mt('Course options').'</legend>'.
4980: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
4981: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
4982: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
4983: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 4984: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 4985: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
4986: '<span class="LC_nobreak">'.&mt('From').':<label>'.
4987: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
4988: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
4989: &mt('Standard field').'</label>'.(' 'x2).
4990: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
4991: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 4992: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 4993: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
4994: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
4995: foreach my $extra ('passback','roster') {
4996: my $checkedon = '';
4997: my $checkedoff = ' checked="checked"';
4998: if (ref($current) eq 'HASH') {
4999: if (($current->{$extra})) {
5000: $checkedon = $checkedoff;
5001: $checkedoff = '';
5002: }
5003: }
5004: $output .= $lt{$extra}.' '.
5005: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.' />'.
5006: &mt('No').'</label>'.(' 'x2).
5007: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.' />'.
5008: &mt('Yes').'</label><br />';
5009: }
1.334 raeburn 5010: $output .= '</fieldset>'.
1.326 raeburn 5011: '<fieldset><legend>'.&mt('Course defaults (Course Coordinator can override)').'</legend>'.
5012: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
5013: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
5014: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
5015: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
1.334 raeburn 5016: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
1.326 raeburn 5017: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
5018: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
5019: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
5020: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
5021: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
1.334 raeburn 5022: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
1.326 raeburn 5023: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
5024: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
5025: '<span class="LC_nobreak">'.&mt('Menu items').': ';
5026: foreach my $type ('fullname','coursetitle','role','logout','grades') {
5027: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
5028: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
5029: (' 'x2);
5030: }
1.334 raeburn 5031: $output .= '</span></div></fieldset>';
1.320 raeburn 5032: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
5033: #
5034: # $output .= '</fieldset>'.
5035: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
5036: return $output;
5037: }
5038:
1.326 raeburn 5039: sub ltimenu_titles {
5040: return &Apache::lonlocal::texthash(
5041: fullname => 'Full name',
5042: coursetitle => 'Course title',
5043: role => 'Role',
5044: logout => 'Logout',
5045: grades => 'Grades',
5046: );
5047: }
5048:
1.121 raeburn 5049: sub print_coursedefaults {
1.139 raeburn 5050: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 5051: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 5052: my $itemcount = 1;
1.192 raeburn 5053: my %choices = &Apache::lonlocal::texthash (
5054: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 5055: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 5056: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
5057: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 5058: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
5059: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.314 raeburn 5060: texengine => 'Default method to display mathematics',
1.257 raeburn 5061: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 5062: canclone => "People who may clone a course (besides course's owner and coordinators)",
5063: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 5064: );
1.198 raeburn 5065: my %staticdefaults = (
1.314 raeburn 5066: texengine => 'MathJax',
1.198 raeburn 5067: anonsurvey_threshold => 10,
5068: uploadquota => 500,
1.257 raeburn 5069: postsubmit => 60,
1.276 raeburn 5070: mysqltables => 172800,
1.198 raeburn 5071: );
1.139 raeburn 5072: if ($position eq 'top') {
1.257 raeburn 5073: %defaultchecked = (
5074: 'canuse_pdfforms' => 'off',
5075: 'uselcmath' => 'on',
5076: 'usejsme' => 'on',
1.289 raeburn 5077: 'canclone' => 'none',
1.257 raeburn 5078: );
5079: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.314 raeburn 5080: my $deftex = $staticdefaults{'texengine'};
5081: if (ref($settings) eq 'HASH') {
5082: if ($settings->{'texengine'}) {
5083: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
5084: $deftex = $settings->{'texengine'};
5085: }
5086: }
5087: }
5088: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5089: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
5090: '<span class="LC_nobreak">'.$choices{'texengine'}.
5091: '</span></td><td class="LC_right_item">'.
5092: '<select name="texengine">'."\n";
5093: my %texoptions = (
5094: MathJax => 'MathJax',
5095: mimetex => &mt('Convert to Images'),
5096: tth => &mt('TeX to HTML'),
5097: );
5098: foreach my $renderer ('MathJax','mimetex','tth') {
5099: my $selected = '';
5100: if ($renderer eq $deftex) {
5101: $selected = ' selected="selected"';
5102: }
5103: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
5104: }
5105: $mathdisp .= '</select></td></tr>'."\n";
5106: $itemcount ++;
1.139 raeburn 5107: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 5108: \%choices,$itemcount);
1.314 raeburn 5109: $datatable = $mathdisp.$datatable;
1.264 raeburn 5110: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5111: $datatable .=
1.306 raeburn 5112: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 5113: '<span class="LC_nobreak">'.$choices{'canclone'}.
5114: '</span></td><td class="LC_left_item">';
5115: my $currcanclone = 'none';
5116: my $onclick;
5117: my @cloneoptions = ('none','domain');
5118: my %clonetitles = (
5119: none => 'No additional course requesters',
5120: domain => "Any course requester in course's domain",
5121: instcode => 'Course requests for official courses ...',
5122: );
5123: my (%codedefaults,@code_order,@posscodes);
5124: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
5125: \@code_order) eq 'ok') {
5126: if (@code_order > 0) {
5127: push(@cloneoptions,'instcode');
5128: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
5129: }
5130: }
5131: if (ref($settings) eq 'HASH') {
5132: if ($settings->{'canclone'}) {
5133: if (ref($settings->{'canclone'}) eq 'HASH') {
5134: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
5135: if (@code_order > 0) {
5136: $currcanclone = 'instcode';
5137: @posscodes = @{$settings->{'canclone'}{'instcode'}};
5138: }
5139: }
5140: } elsif ($settings->{'canclone'} eq 'domain') {
5141: $currcanclone = $settings->{'canclone'};
5142: }
5143: }
1.289 raeburn 5144: }
1.264 raeburn 5145: foreach my $option (@cloneoptions) {
5146: my ($checked,$additional);
5147: if ($currcanclone eq $option) {
5148: $checked = ' checked="checked"';
5149: }
5150: if ($option eq 'instcode') {
5151: if (@code_order) {
5152: my $show = 'none';
5153: if ($checked) {
5154: $show = 'block';
5155: }
1.317 raeburn 5156: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 5157: &mt('Institutional codes for new and cloned course have identical:').
5158: '<br />';
5159: foreach my $item (@code_order) {
5160: my $codechk;
5161: if ($checked) {
5162: if (grep(/^\Q$item\E$/,@posscodes)) {
5163: $codechk = ' checked="checked"';
5164: }
5165: }
5166: $additional .= '<label>'.
5167: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
5168: $item.'</label>';
5169: }
5170: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
5171: }
5172: }
5173: $datatable .=
5174: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
5175: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
5176: '</label> '.$additional.'</span><br />';
5177: }
5178: $datatable .= '</td>'.
5179: '</tr>';
5180: $itemcount ++;
1.139 raeburn 5181: } else {
5182: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 5183: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 5184: my $currusecredits = 0;
1.257 raeburn 5185: my $postsubmitclient = 1;
1.271 raeburn 5186: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 5187: if (ref($settings) eq 'HASH') {
5188: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 5189: if (ref($settings->{'uploadquota'}) eq 'HASH') {
5190: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
5191: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
5192: }
5193: }
1.192 raeburn 5194: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 5195: foreach my $type (@types) {
5196: next if ($type eq 'community');
5197: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
5198: if ($defcredits{$type} ne '') {
5199: $currusecredits = 1;
5200: }
5201: }
5202: }
5203: if (ref($settings->{'postsubmit'}) eq 'HASH') {
5204: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
5205: $postsubmitclient = 0;
5206: foreach my $type (@types) {
5207: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5208: }
5209: } else {
5210: foreach my $type (@types) {
5211: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
5212: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 5213: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 5214: } else {
5215: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5216: }
5217: } else {
5218: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5219: }
5220: }
5221: }
5222: } else {
5223: foreach my $type (@types) {
5224: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 5225: }
5226: }
1.276 raeburn 5227: if (ref($settings->{'mysqltables'}) eq 'HASH') {
5228: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
5229: $currmysql{$type} = $settings->{'mysqltables'}{$type};
5230: }
5231: } else {
5232: foreach my $type (@types) {
5233: $currmysql{$type} = $staticdefaults{'mysqltables'};
5234: }
5235: }
1.258 raeburn 5236: } else {
5237: foreach my $type (@types) {
5238: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5239: }
1.139 raeburn 5240: }
5241: if (!$currdefresponder) {
1.198 raeburn 5242: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 5243: } elsif ($currdefresponder < 1) {
5244: $currdefresponder = 1;
5245: }
1.198 raeburn 5246: foreach my $type (@types) {
5247: if ($curruploadquota{$type} eq '') {
5248: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
5249: }
5250: }
1.139 raeburn 5251: $datatable .=
1.192 raeburn 5252: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5253: $choices{'anonsurvey_threshold'}.
1.139 raeburn 5254: '</span></td>'.
5255: '<td class="LC_right_item"><span class="LC_nobreak">'.
5256: '<input type="text" name="anonsurvey_threshold"'.
5257: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 5258: '</td></tr>'."\n";
5259: $itemcount ++;
5260: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5261: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5262: $choices{'uploadquota'}.
5263: '</span></td>'.
1.306 raeburn 5264: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 5265: '<table><tr>';
1.198 raeburn 5266: foreach my $type (@types) {
1.306 raeburn 5267: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 5268: '<input type="text" name="uploadquota_'.$type.'"'.
5269: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
5270: }
5271: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 5272: $itemcount ++;
1.236 raeburn 5273: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 5274: my $display = 'none';
1.192 raeburn 5275: if ($currusecredits) {
5276: $display = 'block';
5277: }
5278: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 5279: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
5280: foreach my $type (@types) {
5281: next if ($type eq 'community');
1.306 raeburn 5282: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 5283: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 5284: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 5285: }
5286: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 5287: %defaultchecked = ('coursecredits' => 'off');
5288: @toggles = ('coursecredits');
5289: my $current = {
5290: 'coursecredits' => $currusecredits,
5291: };
5292: (my $table,$itemcount) =
5293: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 5294: \%choices,$itemcount,$onclick,$additional,'left');
5295: $datatable .= $table;
5296: $onclick = "toggleDisplay(this.form,'studentsubmission');";
5297: my $display = 'none';
5298: if ($postsubmitclient) {
5299: $display = 'block';
5300: }
5301: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 5302: &mt('Number of seconds submit is disabled').'<br />'.
5303: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
5304: '<table><tr>';
1.257 raeburn 5305: foreach my $type (@types) {
1.306 raeburn 5306: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 5307: '<input type="text" name="'.$type.'_timeout" value="'.
5308: $deftimeout{$type}.'" size="5" /></td>';
5309: }
5310: $additional .= '</tr></table></div>'."\n";
5311: %defaultchecked = ('postsubmit' => 'on');
5312: @toggles = ('postsubmit');
1.280 raeburn 5313: $current = {
5314: 'postsubmit' => $postsubmitclient,
5315: };
1.257 raeburn 5316: ($table,$itemcount) =
5317: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
5318: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 5319: $datatable .= $table;
1.276 raeburn 5320: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5321: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5322: $choices{'mysqltables'}.
5323: '</span></td>'.
1.306 raeburn 5324: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 5325: '<table><tr>';
5326: foreach my $type (@types) {
1.306 raeburn 5327: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 5328: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 5329: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 5330: }
5331: $datatable .= '</tr></table></td></tr>'."\n";
5332: $itemcount ++;
5333:
1.139 raeburn 5334: }
1.192 raeburn 5335: $$rowtotal += $itemcount;
1.121 raeburn 5336: return $datatable;
1.118 jms 5337: }
5338:
1.231 raeburn 5339: sub print_selfenrollment {
5340: my ($position,$dom,$settings,$rowtotal) = @_;
5341: my ($css_class,$datatable);
5342: my $itemcount = 1;
1.271 raeburn 5343: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 5344: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 5345: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
5346: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 5347: my @rows;
5348: my $key;
5349: if ($position eq 'top') {
5350: $key = 'admin';
5351: if (ref($rowsref) eq 'ARRAY') {
5352: @rows = @{$rowsref};
5353: }
5354: } elsif ($position eq 'middle') {
5355: $key = 'default';
5356: @rows = ('types','registered','approval','limit');
5357: }
5358: foreach my $row (@rows) {
5359: if (defined($titlesref->{$row})) {
5360: $itemcount ++;
5361: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5362: $datatable .= '<tr'.$css_class.'>'.
5363: '<td>'.$titlesref->{$row}.'</td>'.
5364: '<td class="LC_left_item">'.
5365: '<table><tr>';
5366: my (%current,%currentcap);
5367: if (ref($settings) eq 'HASH') {
5368: if (ref($settings->{$key}) eq 'HASH') {
5369: foreach my $type (@types) {
5370: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5371: $current{$type} = $settings->{$key}->{$type}->{$row};
5372: }
5373: if (($row eq 'limit') && ($key eq 'default')) {
5374: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5375: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
5376: }
5377: }
5378: }
5379: }
5380: }
5381: my %roles = (
5382: '0' => &Apache::lonnet::plaintext('dc'),
5383: );
5384:
5385: foreach my $type (@types) {
5386: unless (($row eq 'registered') && ($key eq 'default')) {
5387: $datatable .= '<th>'.&mt($type).'</th>';
5388: }
5389: }
5390: unless (($row eq 'registered') && ($key eq 'default')) {
5391: $datatable .= '</tr><tr>';
5392: }
5393: foreach my $type (@types) {
5394: if ($type eq 'community') {
5395: $roles{'1'} = &mt('Community personnel');
5396: } else {
5397: $roles{'1'} = &mt('Course personnel');
5398: }
5399: $datatable .= '<td style="vertical-align: top">';
5400: if ($position eq 'top') {
5401: my %checked;
5402: if ($current{$type} eq '0') {
5403: $checked{'0'} = ' checked="checked"';
5404: } else {
5405: $checked{'1'} = ' checked="checked"';
5406: }
5407: foreach my $role ('1','0') {
5408: $datatable .= '<span class="LC_nobreak"><label>'.
5409: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
5410: 'value="'.$role.'"'.$checked{$role}.' />'.
5411: $roles{$role}.'</label></span> ';
5412: }
5413: } else {
5414: if ($row eq 'types') {
5415: my %checked;
5416: if ($current{$type} =~ /^(all|dom)$/) {
5417: $checked{$1} = ' checked="checked"';
5418: } else {
5419: $checked{''} = ' checked="checked"';
5420: }
5421: foreach my $val ('','dom','all') {
5422: $datatable .= '<span class="LC_nobreak"><label>'.
5423: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5424: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5425: }
5426: } elsif ($row eq 'registered') {
5427: my %checked;
5428: if ($current{$type} eq '1') {
5429: $checked{'1'} = ' checked="checked"';
5430: } else {
5431: $checked{'0'} = ' checked="checked"';
5432: }
5433: foreach my $val ('0','1') {
5434: $datatable .= '<span class="LC_nobreak"><label>'.
5435: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5436: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5437: }
5438: } elsif ($row eq 'approval') {
5439: my %checked;
5440: if ($current{$type} =~ /^([12])$/) {
5441: $checked{$1} = ' checked="checked"';
5442: } else {
5443: $checked{'0'} = ' checked="checked"';
5444: }
5445: for my $val (0..2) {
5446: $datatable .= '<span class="LC_nobreak"><label>'.
5447: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5448: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5449: }
5450: } elsif ($row eq 'limit') {
5451: my %checked;
5452: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
5453: $checked{$1} = ' checked="checked"';
5454: } else {
5455: $checked{'none'} = ' checked="checked"';
5456: }
5457: my $cap;
5458: if ($currentcap{$type} =~ /^\d+$/) {
5459: $cap = $currentcap{$type};
5460: }
5461: foreach my $val ('none','allstudents','selfenrolled') {
5462: $datatable .= '<span class="LC_nobreak"><label>'.
5463: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5464: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5465: }
5466: $datatable .= '<br />'.
5467: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
5468: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
5469: '</span>';
5470: }
5471: }
5472: $datatable .= '</td>';
5473: }
5474: $datatable .= '</tr>';
5475: }
5476: $datatable .= '</table></td></tr>';
5477: }
5478: } elsif ($position eq 'bottom') {
1.235 raeburn 5479: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
5480: }
5481: $$rowtotal += $itemcount;
5482: return $datatable;
5483: }
5484:
5485: sub print_validation_rows {
5486: my ($caller,$dom,$settings,$rowtotal) = @_;
5487: my ($itemsref,$namesref,$fieldsref);
5488: if ($caller eq 'selfenroll') {
5489: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
5490: } elsif ($caller eq 'requestcourses') {
5491: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
5492: }
5493: my %currvalidation;
5494: if (ref($settings) eq 'HASH') {
5495: if (ref($settings->{'validation'}) eq 'HASH') {
5496: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 5497: }
1.235 raeburn 5498: }
5499: my $datatable;
5500: my $itemcount = 0;
5501: foreach my $item (@{$itemsref}) {
5502: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5503: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5504: $namesref->{$item}.
5505: '</span></td>'.
5506: '<td class="LC_left_item">';
5507: if (($item eq 'url') || ($item eq 'button')) {
5508: $datatable .= '<span class="LC_nobreak">'.
5509: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
5510: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
5511: } elsif ($item eq 'fields') {
5512: my @currfields;
5513: if (ref($currvalidation{$item}) eq 'ARRAY') {
5514: @currfields = @{$currvalidation{$item}};
5515: }
5516: foreach my $field (@{$fieldsref}) {
5517: my $check = '';
5518: if (grep(/^\Q$field\E$/,@currfields)) {
5519: $check = ' checked="checked"';
5520: }
5521: $datatable .= '<span class="LC_nobreak"><label>'.
5522: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
5523: ' value="'.$field.'"'.$check.' />'.$field.
5524: '</label></span> ';
5525: }
5526: } elsif ($item eq 'markup') {
1.334 raeburn 5527: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 5528: $currvalidation{$item}.
1.231 raeburn 5529: '</textarea>';
1.235 raeburn 5530: }
5531: $datatable .= '</td></tr>'."\n";
5532: if (ref($rowtotal)) {
1.231 raeburn 5533: $itemcount ++;
5534: }
5535: }
1.235 raeburn 5536: if ($caller eq 'requestcourses') {
5537: my %currhash;
1.248 raeburn 5538: if (ref($settings) eq 'HASH') {
5539: if (ref($settings->{'validation'}) eq 'HASH') {
5540: if ($settings->{'validation'}{'dc'} ne '') {
5541: $currhash{$settings->{'validation'}{'dc'}} = 1;
5542: }
1.235 raeburn 5543: }
5544: }
5545: my $numinrow = 2;
5546: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
5547: 'validationdc',%currhash);
1.247 raeburn 5548: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 5549: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 5550: if ($numdc > 1) {
1.247 raeburn 5551: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 5552: } else {
1.247 raeburn 5553: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 5554: }
1.247 raeburn 5555: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 5556: $itemcount ++;
5557: }
5558: if (ref($rowtotal)) {
5559: $$rowtotal += $itemcount;
5560: }
1.231 raeburn 5561: return $datatable;
5562: }
5563:
1.137 raeburn 5564: sub print_usersessions {
5565: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 5566: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 5567: my (%by_ip,%by_location,@intdoms,@instdoms);
5568: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 5569:
5570: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 5571: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 5572: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 5573: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 5574: if ($position eq 'top') {
1.152 raeburn 5575: if (keys(%serverhomes) > 1) {
1.145 raeburn 5576: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.261 raeburn 5577: my $curroffloadnow;
5578: if (ref($settings) eq 'HASH') {
5579: if (ref($settings->{'offloadnow'}) eq 'HASH') {
5580: $curroffloadnow = $settings->{'offloadnow'};
5581: }
5582: }
5583: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 5584: } else {
1.140 raeburn 5585: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 5586: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
5587: '</td></tr>';
1.140 raeburn 5588: }
1.137 raeburn 5589: } else {
1.279 raeburn 5590: my %titles = &usersession_titles();
5591: my ($prefix,@types);
5592: if ($position eq 'bottom') {
5593: $prefix = 'remote';
5594: @types = ('version','excludedomain','includedomain');
1.145 raeburn 5595: } else {
1.279 raeburn 5596: $prefix = 'hosted';
5597: @types = ('excludedomain','includedomain');
5598: }
5599: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
5600: }
5601: $$rowtotal += $itemcount;
5602: return $datatable;
5603: }
5604:
5605: sub rules_by_location {
5606: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
5607: my ($datatable,$itemcount,$css_class);
5608: if (keys(%{$by_location}) == 0) {
5609: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5610: $datatable = '<tr'.$css_class.'><td colspan="2">'.
5611: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
5612: '</td></tr>';
5613: $itemcount = 1;
5614: } else {
5615: $itemcount = 0;
5616: my $numinrow = 5;
5617: my (%current,%checkedon,%checkedoff);
5618: my @locations = sort(keys(%{$by_location}));
5619: foreach my $type (@{$types}) {
5620: $checkedon{$type} = '';
5621: $checkedoff{$type} = ' checked="checked"';
5622: }
5623: if (ref($settings) eq 'HASH') {
5624: if (ref($settings->{$prefix}) eq 'HASH') {
5625: foreach my $key (keys(%{$settings->{$prefix}})) {
5626: $current{$key} = $settings->{$prefix}{$key};
5627: if ($key eq 'version') {
5628: if ($current{$key} ne '') {
1.145 raeburn 5629: $checkedon{$key} = ' checked="checked"';
5630: $checkedoff{$key} = '';
5631: }
1.279 raeburn 5632: } elsif (ref($current{$key}) eq 'ARRAY') {
5633: $checkedon{$key} = ' checked="checked"';
5634: $checkedoff{$key} = '';
1.137 raeburn 5635: }
5636: }
5637: }
1.279 raeburn 5638: }
5639: foreach my $type (@{$types}) {
5640: next if ($type ne 'version' && !@locations);
5641: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5642: $datatable .= '<tr'.$css_class.'>
5643: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
5644: <span class="LC_nobreak">
5645: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
5646: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
5647: if ($type eq 'version') {
5648: my @lcversions = &Apache::lonnet::all_loncaparevs();
5649: my $selector = '<select name="'.$prefix.'_version">';
5650: foreach my $version (@lcversions) {
5651: my $selected = '';
5652: if ($current{'version'} eq $version) {
5653: $selected = ' selected="selected"';
1.145 raeburn 5654: }
1.279 raeburn 5655: $selector .= ' <option value="'.$version.'"'.
5656: $selected.'>'.$version.'</option>';
5657: }
5658: $selector .= '</select> ';
5659: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
5660: } else {
5661: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
5662: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
5663: ' />'.(' 'x2).
5664: '<input type="button" value="'.&mt('uncheck all').'" '.
5665: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
5666: "\n".
5667: '</div><div><table>';
5668: my $rem;
5669: for (my $i=0; $i<@locations; $i++) {
5670: my ($showloc,$value,$checkedtype);
5671: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
5672: my $ip = $by_location->{$locations[$i]}->[0];
5673: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5674: $value = join(':',@{$by_ip->{$ip}});
5675: $showloc = join(', ',@{$by_ip->{$ip}});
5676: if (ref($current{$type}) eq 'ARRAY') {
5677: foreach my $loc (@{$by_ip->{$ip}}) {
5678: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
5679: $checkedtype = ' checked="checked"';
5680: last;
1.145 raeburn 5681: }
1.138 raeburn 5682: }
5683: }
5684: }
1.137 raeburn 5685: }
1.279 raeburn 5686: $rem = $i%($numinrow);
5687: if ($rem == 0) {
5688: if ($i > 0) {
5689: $datatable .= '</tr>';
5690: }
5691: $datatable .= '<tr>';
5692: }
5693: $datatable .= '<td class="LC_left_item">'.
5694: '<span class="LC_nobreak"><label>'.
5695: '<input type="checkbox" name="'.$prefix.'_'.$type.
5696: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
5697: '</label></span></td>';
5698: }
5699: $rem = @locations%($numinrow);
5700: my $colsleft = $numinrow - $rem;
5701: if ($colsleft > 1 ) {
5702: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5703: ' </td>';
5704: } elsif ($colsleft == 1) {
5705: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 5706: }
1.279 raeburn 5707: $datatable .= '</tr></table>';
1.137 raeburn 5708: }
1.279 raeburn 5709: $datatable .= '</td></tr>';
5710: $itemcount ++;
1.137 raeburn 5711: }
5712: }
1.279 raeburn 5713: return ($datatable,$itemcount);
1.137 raeburn 5714: }
5715:
1.275 raeburn 5716: sub print_ssl {
5717: my ($position,$dom,$settings,$rowtotal) = @_;
5718: my ($css_class,$datatable);
5719: my $itemcount = 1;
5720: if ($position eq 'top') {
1.281 raeburn 5721: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5722: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5723: my $same_institution;
5724: if ($intdom ne '') {
5725: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
5726: if (ref($internet_names) eq 'ARRAY') {
5727: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
5728: $same_institution = 1;
5729: }
5730: }
5731: }
1.275 raeburn 5732: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 5733: $datatable = '<tr'.$css_class.'><td colspan="2">';
5734: if ($same_institution) {
5735: my %domservers = &Apache::lonnet::get_servers($dom);
5736: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
5737: } else {
5738: $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.");
5739: }
5740: $datatable .= '</td></tr>';
1.275 raeburn 5741: $itemcount ++;
5742: } else {
5743: my %titles = &ssl_titles();
5744: my (%by_ip,%by_location,@intdoms,@instdoms);
5745: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
5746: my @alldoms = &Apache::lonnet::all_domains();
5747: my %serverhomes = %Apache::lonnet::serverhomeIDs;
5748: my @domservers = &Apache::lonnet::get_servers($dom);
5749: my %servers = &Apache::lonnet::internet_dom_servers($dom);
5750: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 5751: if (($position eq 'connto') || ($position eq 'connfrom')) {
5752: my $legacy;
5753: unless (ref($settings) eq 'HASH') {
5754: my $name;
5755: if ($position eq 'connto') {
5756: $name = 'loncAllowInsecure';
5757: } else {
5758: $name = 'londAllowInsecure';
5759: }
5760: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
5761: my @ids=&Apache::lonnet::current_machine_ids();
5762: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
5763: my %what = (
5764: $name => 1,
5765: );
5766: my ($result,$returnhash) =
5767: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
5768: if ($result eq 'ok') {
5769: if (ref($returnhash) eq 'HASH') {
5770: $legacy = $returnhash->{$name};
5771: }
5772: }
5773: } else {
5774: $legacy = $Apache::lonnet::perlvar{$name};
5775: }
5776: }
1.275 raeburn 5777: foreach my $type ('dom','intdom','other') {
5778: my %checked;
5779: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5780: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
5781: '<td class="LC_right_item">';
5782: my $skip;
5783: if ($type eq 'dom') {
5784: unless (keys(%servers) > 1) {
5785: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
5786: $skip = 1;
5787: }
5788: }
5789: if ($type eq 'intdom') {
5790: unless (@instdoms > 1) {
5791: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
5792: $skip = 1;
5793: }
5794: } elsif ($type eq 'other') {
5795: if (keys(%by_location) == 0) {
5796: $datatable .= &mt('Nothing to set here, as there are no other institutions');
5797: $skip = 1;
5798: }
5799: }
5800: unless ($skip) {
5801: $checked{'yes'} = ' checked="checked"';
5802: if (ref($settings) eq 'HASH') {
1.293 raeburn 5803: if (ref($settings->{$position}) eq 'HASH') {
5804: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 5805: $checked{$1} = $checked{'yes'};
5806: delete($checked{'yes'});
5807: }
5808: }
1.293 raeburn 5809: } else {
5810: if ($legacy == 0) {
5811: $checked{'req'} = $checked{'yes'};
5812: delete($checked{'yes'});
5813: }
1.275 raeburn 5814: }
5815: foreach my $option ('no','yes','req') {
5816: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 5817: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 5818: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
5819: '</label></span>'.(' 'x2);
5820: }
5821: }
5822: $datatable .= '</td></tr>';
5823: $itemcount ++;
5824: }
5825: } else {
5826: my $prefix = 'replication';
5827: my @types = ('certreq','nocertreq');
1.279 raeburn 5828: if (keys(%by_location) == 0) {
5829: $datatable .= '<tr'.$css_class.'><td>'.
5830: &mt('Nothing to set here, as there are no other institutions').
5831: '</td></tr>';
5832: $itemcount ++;
1.275 raeburn 5833: } else {
1.279 raeburn 5834: ($datatable,$itemcount) =
5835: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 5836: }
5837: }
5838: }
5839: $$rowtotal += $itemcount;
5840: return $datatable;
5841: }
5842:
5843: sub ssl_titles {
5844: return &Apache::lonlocal::texthash (
5845: dom => 'LON-CAPA servers/VMs from same domain',
5846: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
5847: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 5848: connto => 'Connections to other servers',
5849: connfrom => 'Connections from other servers',
1.275 raeburn 5850: replication => 'Replicating content to other institutions',
5851: certreq => 'Client certificate required, but specific domains exempt',
5852: nocertreq => 'No client certificate required, except for specific domains',
5853: no => 'SSL not used',
5854: yes => 'SSL Optional (used if available)',
5855: req => 'SSL Required',
5856: );
1.279 raeburn 5857: }
5858:
5859: sub print_trust {
5860: my ($prefix,$dom,$settings,$rowtotal) = @_;
5861: my ($css_class,$datatable,%checked,%choices);
5862: my (%by_ip,%by_location,@intdoms,@instdoms);
5863: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
5864: my $itemcount = 1;
5865: my %titles = &trust_titles();
5866: my @types = ('exc','inc');
5867: if ($prefix eq 'top') {
5868: $prefix = 'content';
5869: } elsif ($prefix eq 'bottom') {
5870: $prefix = 'msg';
5871: }
5872: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
5873: $$rowtotal += $itemcount;
5874: return $datatable;
5875: }
5876:
5877: sub trust_titles {
5878: return &Apache::lonlocal::texthash(
5879: content => "Access to this domain's content by others",
5880: shared => "Access to other domain's content by this domain",
5881: enroll => "Enrollment in this domain's courses by others",
5882: othcoau => "Co-author roles in this domain for others",
5883: coaurem => "Co-author roles for this domain's users elsewhere",
5884: domroles => "Domain roles in this domain assignable to others",
5885: catalog => "Course Catalog for this domain displayed elsewhere",
5886: reqcrs => "Requests for creation of courses in this domain by others",
5887: msg => "Users in other domains can send messages to this domain",
5888: exc => "Allow all, but exclude specific domains",
5889: inc => "Deny all, but include specific domains",
5890: );
1.275 raeburn 5891: }
5892:
1.138 raeburn 5893: sub build_location_hashes {
1.275 raeburn 5894: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 5895: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 5896: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 5897: my %iphost = &Apache::lonnet::get_iphost();
5898: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
5899: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
5900: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
5901: foreach my $id (@{$iphost{$primary_ip}}) {
5902: my $intdom = &Apache::lonnet::internet_dom($id);
5903: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
5904: push(@{$intdoms},$intdom);
5905: }
5906: }
5907: }
5908: foreach my $ip (keys(%iphost)) {
5909: if (ref($iphost{$ip}) eq 'ARRAY') {
5910: foreach my $id (@{$iphost{$ip}}) {
5911: my $location = &Apache::lonnet::internet_dom($id);
5912: if ($location) {
1.275 raeburn 5913: if (grep(/^\Q$location\E$/,@{$intdoms})) {
5914: my $dom = &Apache::lonnet::host_domain($id);
5915: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
5916: push(@{$instdoms},$dom);
5917: }
5918: next;
5919: }
1.138 raeburn 5920: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5921: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
5922: push(@{$by_ip->{$ip}},$location);
5923: }
5924: } else {
5925: $by_ip->{$ip} = [$location];
5926: }
5927: }
5928: }
5929: }
5930: }
5931: foreach my $ip (sort(keys(%{$by_ip}))) {
5932: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5933: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
5934: my $first = $by_ip->{$ip}->[0];
5935: if (ref($by_location->{$first}) eq 'ARRAY') {
5936: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
5937: push(@{$by_location->{$first}},$ip);
5938: }
5939: } else {
5940: $by_location->{$first} = [$ip];
5941: }
5942: }
5943: }
5944: return;
5945: }
5946:
1.145 raeburn 5947: sub current_offloads_to {
5948: my ($dom,$settings,$servers) = @_;
5949: my (%spareid,%otherdomconfigs);
1.152 raeburn 5950: if (ref($servers) eq 'HASH') {
1.145 raeburn 5951: foreach my $lonhost (sort(keys(%{$servers}))) {
5952: my $gotspares;
1.152 raeburn 5953: if (ref($settings) eq 'HASH') {
5954: if (ref($settings->{'spares'}) eq 'HASH') {
5955: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
5956: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
5957: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
5958: $gotspares = 1;
5959: }
1.145 raeburn 5960: }
5961: }
5962: unless ($gotspares) {
5963: my $gotspares;
5964: my $serverhomeID =
5965: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
5966: my $serverhomedom =
5967: &Apache::lonnet::host_domain($serverhomeID);
5968: if ($serverhomedom ne $dom) {
5969: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
5970: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5971: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5972: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5973: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5974: $gotspares = 1;
5975: }
5976: }
5977: } else {
5978: $otherdomconfigs{$serverhomedom} =
5979: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
5980: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
5981: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5982: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5983: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
5984: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5985: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5986: $gotspares = 1;
5987: }
5988: }
5989: }
5990: }
5991: }
5992: }
5993: }
5994: unless ($gotspares) {
5995: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
5996: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
5997: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
5998: } else {
5999: my $server_hostname = &Apache::lonnet::hostname($lonhost);
6000: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
6001: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
6002: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6003: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6004: } else {
1.150 raeburn 6005: my %what = (
6006: spareid => 1,
6007: );
6008: my ($result,$returnhash) =
6009: &Apache::lonnet::get_remote_globals($lonhost,\%what);
6010: if ($result eq 'ok') {
6011: if (ref($returnhash) eq 'HASH') {
6012: if (ref($returnhash->{'spareid'}) eq 'HASH') {
6013: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
6014: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
6015: }
6016: }
1.145 raeburn 6017: }
6018: }
6019: }
6020: }
6021: }
6022: }
6023: return %spareid;
6024: }
6025:
6026: sub spares_row {
1.261 raeburn 6027: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 6028: my $css_class;
6029: my $numinrow = 4;
6030: my $itemcount = 1;
6031: my $datatable;
1.152 raeburn 6032: my %typetitles = &sparestype_titles();
6033: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 6034: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 6035: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
6036: my ($othercontrol,$serverdom);
6037: if ($serverhome ne $server) {
6038: $serverdom = &Apache::lonnet::host_domain($serverhome);
6039: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6040: } else {
6041: $serverdom = &Apache::lonnet::host_domain($server);
6042: if ($serverdom ne $dom) {
6043: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6044: }
6045: }
6046: next unless (ref($spareid->{$server}) eq 'HASH');
1.261 raeburn 6047: my $checkednow;
6048: if (ref($curroffloadnow) eq 'HASH') {
6049: if ($curroffloadnow->{$server}) {
6050: $checkednow = ' checked="checked"';
6051: }
6052: }
1.145 raeburn 6053: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6054: $datatable .= '<tr'.$css_class.'>
6055: <td rowspan="2">
1.183 bisitz 6056: <span class="LC_nobreak">'.
6057: &mt('[_1] when busy, offloads to:'
1.261 raeburn 6058: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 6059: '<span class="LC_nobreak">'."\n".
1.261 raeburn 6060: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
6061: ' '.&mt('Switch active users on next access').'</label></span>'.
1.183 bisitz 6062: "\n";
1.145 raeburn 6063: my (%current,%canselect);
1.152 raeburn 6064: my @choices =
6065: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
6066: foreach my $type ('primary','default') {
6067: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 6068: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
6069: my @spares = @{$spareid->{$server}{$type}};
6070: if (@spares > 0) {
1.152 raeburn 6071: if ($othercontrol) {
6072: $current{$type} = join(', ',@spares);
6073: } else {
6074: $current{$type} .= '<table>';
6075: my $numspares = scalar(@spares);
6076: for (my $i=0; $i<@spares; $i++) {
6077: my $rem = $i%($numinrow);
6078: if ($rem == 0) {
6079: if ($i > 0) {
6080: $current{$type} .= '</tr>';
6081: }
6082: $current{$type} .= '<tr>';
1.145 raeburn 6083: }
1.152 raeburn 6084: $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'".');" /> '.
6085: $spareid->{$server}{$type}[$i].
6086: '</label></td>'."\n";
6087: }
6088: my $rem = @spares%($numinrow);
6089: my $colsleft = $numinrow - $rem;
6090: if ($colsleft > 1 ) {
6091: $current{$type} .= '<td colspan="'.$colsleft.
6092: '" class="LC_left_item">'.
6093: ' </td>';
6094: } elsif ($colsleft == 1) {
6095: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 6096: }
1.152 raeburn 6097: $current{$type} .= '</tr></table>';
1.150 raeburn 6098: }
1.145 raeburn 6099: }
6100: }
6101: if ($current{$type} eq '') {
6102: $current{$type} = &mt('None specified');
6103: }
1.152 raeburn 6104: if ($othercontrol) {
6105: if ($type eq 'primary') {
6106: $canselect{$type} = $othercontrol;
6107: }
6108: } else {
6109: $canselect{$type} =
6110: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
6111: '<select name="newspare_'.$type.'_'.$server.'" '.
6112: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
6113: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
6114: if (@choices > 0) {
6115: foreach my $lonhost (@choices) {
6116: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
6117: }
6118: }
6119: $canselect{$type} .= '</select>'."\n";
6120: }
6121: } else {
6122: $current{$type} = &mt('Could not be determined');
6123: if ($type eq 'primary') {
6124: $canselect{$type} = $othercontrol;
6125: }
1.145 raeburn 6126: }
1.152 raeburn 6127: if ($type eq 'default') {
6128: $datatable .= '<tr'.$css_class.'>';
6129: }
6130: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
6131: '<td>'.$current{$type}.'</td>'."\n".
6132: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 6133: }
6134: $itemcount ++;
6135: }
6136: }
6137: $$rowtotal += $itemcount;
6138: return $datatable;
6139: }
6140:
1.152 raeburn 6141: sub possible_newspares {
6142: my ($server,$currspares,$serverhomes,$altids) = @_;
6143: my $serverhostname = &Apache::lonnet::hostname($server);
6144: my %excluded;
6145: if ($serverhostname ne '') {
6146: %excluded = (
6147: $serverhostname => 1,
6148: );
6149: }
6150: if (ref($currspares) eq 'HASH') {
6151: foreach my $type (keys(%{$currspares})) {
6152: if (ref($currspares->{$type}) eq 'ARRAY') {
6153: if (@{$currspares->{$type}} > 0) {
6154: foreach my $curr (@{$currspares->{$type}}) {
6155: my $hostname = &Apache::lonnet::hostname($curr);
6156: $excluded{$hostname} = 1;
6157: }
6158: }
6159: }
6160: }
6161: }
6162: my @choices;
6163: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
6164: if (keys(%{$serverhomes}) > 1) {
6165: foreach my $name (sort(keys(%{$serverhomes}))) {
6166: unless ($excluded{$name}) {
6167: if (exists($altids->{$serverhomes->{$name}})) {
6168: push(@choices,$altids->{$serverhomes->{$name}});
6169: } else {
6170: push(@choices,$serverhomes->{$name});
1.145 raeburn 6171: }
6172: }
6173: }
6174: }
6175: }
1.152 raeburn 6176: return sort(@choices);
1.145 raeburn 6177: }
6178:
1.150 raeburn 6179: sub print_loadbalancing {
6180: my ($dom,$settings,$rowtotal) = @_;
6181: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6182: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6183: my $numinrow = 1;
6184: my $datatable;
6185: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 6186: my (%currbalancer,%currtargets,%currrules,%existing);
6187: if (ref($settings) eq 'HASH') {
6188: %existing = %{$settings};
6189: }
6190: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
6191: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
6192: \%currtargets,\%currrules);
1.150 raeburn 6193: } else {
6194: return;
6195: }
6196: my ($othertitle,$usertypes,$types) =
6197: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 6198: my $rownum = 8;
1.150 raeburn 6199: if (ref($types) eq 'ARRAY') {
6200: $rownum += scalar(@{$types});
6201: }
1.171 raeburn 6202: my @css_class = ('LC_odd_row','LC_even_row');
6203: my $balnum = 0;
6204: my $islast;
6205: my (@toshow,$disabledtext);
6206: if (keys(%currbalancer) > 0) {
6207: @toshow = sort(keys(%currbalancer));
6208: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
6209: push(@toshow,'');
6210: }
6211: } else {
6212: @toshow = ('');
6213: $disabledtext = &mt('No existing load balancer');
6214: }
6215: foreach my $lonhost (@toshow) {
6216: if ($balnum == scalar(@toshow)-1) {
6217: $islast = 1;
6218: } else {
6219: $islast = 0;
6220: }
6221: my $cssidx = $balnum%2;
6222: my $targets_div_style = 'display: none';
6223: my $disabled_div_style = 'display: block';
6224: my $homedom_div_style = 'display: none';
6225: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 6226: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 6227: '<p>';
6228: if ($lonhost eq '') {
1.210 raeburn 6229: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 6230: if (keys(%currbalancer) > 0) {
6231: $datatable .= &mt('Add balancer:');
6232: } else {
6233: $datatable .= &mt('Enable balancer:');
6234: }
6235: $datatable .= ' '.
6236: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
6237: ' id="loadbalancing_lonhost_'.$balnum.'"'.
6238: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
6239: '<option value="" selected="selected">'.&mt('None').
6240: '</option>'."\n";
6241: foreach my $server (sort(keys(%servers))) {
6242: next if ($currbalancer{$server});
6243: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
6244: }
1.210 raeburn 6245: $datatable .=
1.171 raeburn 6246: '</select>'."\n".
6247: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
6248: } else {
6249: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
6250: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
6251: &mt('Stop balancing').'</label>'.
6252: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
6253: $targets_div_style = 'display: block';
6254: $disabled_div_style = 'display: none';
6255: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
6256: $homedom_div_style = 'display: block';
6257: }
6258: }
1.306 raeburn 6259: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 6260: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
6261: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
6262: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
6263: my ($numspares,@spares) = &count_servers($lonhost,%servers);
6264: my @sparestypes = ('primary','default');
6265: my %typetitles = &sparestype_titles();
1.284 raeburn 6266: my %hostherechecked = (
6267: no => ' checked="checked"',
6268: );
1.171 raeburn 6269: foreach my $sparetype (@sparestypes) {
6270: my $targettable;
6271: for (my $i=0; $i<$numspares; $i++) {
6272: my $checked;
6273: if (ref($currtargets{$lonhost}) eq 'HASH') {
6274: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6275: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6276: $checked = ' checked="checked"';
6277: }
6278: }
6279: }
6280: my ($chkboxval,$disabled);
6281: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
6282: $chkboxval = $spares[$i];
6283: }
6284: if (exists($currbalancer{$spares[$i]})) {
6285: $disabled = ' disabled="disabled"';
6286: }
1.210 raeburn 6287: $targettable .=
1.253 raeburn 6288: '<td><span class="LC_nobreak"><label>'.
6289: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 6290: $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 6291: '</span></label></span></td>';
1.171 raeburn 6292: my $rem = $i%($numinrow);
6293: if ($rem == 0) {
6294: if (($i > 0) && ($i < $numspares-1)) {
6295: $targettable .= '</tr>';
6296: }
6297: if ($i < $numspares-1) {
6298: $targettable .= '<tr>';
1.150 raeburn 6299: }
6300: }
6301: }
1.171 raeburn 6302: if ($targettable ne '') {
6303: my $rem = $numspares%($numinrow);
6304: my $colsleft = $numinrow - $rem;
6305: if ($colsleft > 1 ) {
6306: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6307: ' </td>';
6308: } elsif ($colsleft == 1) {
6309: $targettable .= '<td class="LC_left_item"> </td>';
6310: }
6311: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
6312: '<table><tr>'.$targettable.'</tr></table><br />';
6313: }
1.284 raeburn 6314: $hostherechecked{$sparetype} = '';
6315: if (ref($currtargets{$lonhost}) eq 'HASH') {
6316: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6317: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6318: $hostherechecked{$sparetype} = ' checked="checked"';
6319: $hostherechecked{'no'} = '';
6320: }
6321: }
6322: }
6323: }
6324: $datatable .= &mt('Hosting on balancer itself').'<br />'.
6325: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
6326: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
6327: foreach my $sparetype (@sparestypes) {
6328: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
6329: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
6330: '</i></label><br />';
1.171 raeburn 6331: }
6332: $datatable .= '</div></td></tr>'.
6333: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
6334: $othertitle,$usertypes,$types,\%servers,
6335: \%currbalancer,$lonhost,
6336: $targets_div_style,$homedom_div_style,
6337: $css_class[$cssidx],$balnum,$islast);
6338: $$rowtotal += $rownum;
6339: $balnum ++;
6340: }
6341: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
6342: return $datatable;
6343: }
6344:
6345: sub get_loadbalancers_config {
6346: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
6347: return unless ((ref($servers) eq 'HASH') &&
6348: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
6349: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
6350: if (keys(%{$existing}) > 0) {
6351: my $oldlonhost;
6352: foreach my $key (sort(keys(%{$existing}))) {
6353: if ($key eq 'lonhost') {
6354: $oldlonhost = $existing->{'lonhost'};
6355: $currbalancer->{$oldlonhost} = 1;
6356: } elsif ($key eq 'targets') {
6357: if ($oldlonhost) {
6358: $currtargets->{$oldlonhost} = $existing->{'targets'};
6359: }
6360: } elsif ($key eq 'rules') {
6361: if ($oldlonhost) {
6362: $currrules->{$oldlonhost} = $existing->{'rules'};
6363: }
6364: } elsif (ref($existing->{$key}) eq 'HASH') {
6365: $currbalancer->{$key} = 1;
6366: $currtargets->{$key} = $existing->{$key}{'targets'};
6367: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 6368: }
6369: }
1.171 raeburn 6370: } else {
6371: my ($balancerref,$targetsref) =
6372: &Apache::lonnet::get_lonbalancer_config($servers);
6373: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
6374: foreach my $server (sort(keys(%{$balancerref}))) {
6375: $currbalancer->{$server} = 1;
6376: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 6377: }
6378: }
6379: }
1.171 raeburn 6380: return;
1.150 raeburn 6381: }
6382:
6383: sub loadbalancing_rules {
6384: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 6385: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
6386: $css_class,$balnum,$islast) = @_;
1.150 raeburn 6387: my $output;
1.171 raeburn 6388: my $num = 0;
1.210 raeburn 6389: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 6390: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
6391: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
6392: foreach my $type (@{$alltypes}) {
1.171 raeburn 6393: $num ++;
1.150 raeburn 6394: my $current;
6395: if (ref($currrules) eq 'HASH') {
6396: $current = $currrules->{$type};
6397: }
1.253 raeburn 6398: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 6399: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 6400: $current = '';
6401: }
6402: }
6403: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 6404: $servers,$currbalancer,$lonhost,$dom,
6405: $targets_div_style,$homedom_div_style,
6406: $css_class,$balnum,$num,$islast);
1.150 raeburn 6407: }
6408: }
6409: return $output;
6410: }
6411:
6412: sub loadbalancing_titles {
6413: my ($dom,$intdom,$usertypes,$types) = @_;
6414: my %othertypes = (
6415: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
6416: '_LC_author' => &mt('Users from [_1] with author role',$dom),
6417: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
6418: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 6419: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
6420: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 6421: );
1.209 raeburn 6422: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 6423: my @available;
1.150 raeburn 6424: if (ref($types) eq 'ARRAY') {
1.302 raeburn 6425: @available = @{$types};
1.150 raeburn 6426: }
1.302 raeburn 6427: unless (grep(/^default$/,@available)) {
6428: push(@available,'default');
6429: }
6430: unshift(@alltypes,@available);
1.150 raeburn 6431: my %titles;
6432: foreach my $type (@alltypes) {
6433: if ($type =~ /^_LC_/) {
6434: $titles{$type} = $othertypes{$type};
6435: } elsif ($type eq 'default') {
6436: $titles{$type} = &mt('All users from [_1]',$dom);
6437: if (ref($types) eq 'ARRAY') {
6438: if (@{$types} > 0) {
6439: $titles{$type} = &mt('Other users from [_1]',$dom);
6440: }
6441: }
6442: } elsif (ref($usertypes) eq 'HASH') {
6443: $titles{$type} = $usertypes->{$type};
6444: }
6445: }
6446: return (\@alltypes,\%othertypes,\%titles);
6447: }
6448:
6449: sub loadbalance_rule_row {
1.171 raeburn 6450: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
6451: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 6452: my @rulenames;
1.150 raeburn 6453: my %ruletitles = &offloadtype_text();
1.209 raeburn 6454: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 6455: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 6456: } else {
1.209 raeburn 6457: @rulenames = ('default','homeserver');
6458: if ($type eq '_LC_external') {
6459: push(@rulenames,'externalbalancer');
6460: } else {
6461: push(@rulenames,'specific');
6462: }
6463: push(@rulenames,'none');
1.150 raeburn 6464: }
6465: my $style = $targets_div_style;
1.253 raeburn 6466: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 6467: $style = $homedom_div_style;
6468: }
1.171 raeburn 6469: my $space;
6470: if ($islast && $num == 1) {
1.317 raeburn 6471: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 6472: }
1.210 raeburn 6473: my $output =
1.306 raeburn 6474: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 6475: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
6476: '<td valaign="top">'.$space.
6477: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 6478: for (my $i=0; $i<@rulenames; $i++) {
6479: my $rule = $rulenames[$i];
6480: my ($checked,$extra);
6481: if ($rulenames[$i] eq 'default') {
6482: $rule = '';
6483: }
6484: if ($rulenames[$i] eq 'specific') {
6485: if (ref($servers) eq 'HASH') {
6486: my $default;
6487: if (($current ne '') && (exists($servers->{$current}))) {
6488: $checked = ' checked="checked"';
6489: }
6490: unless ($checked) {
6491: $default = ' selected="selected"';
6492: }
1.210 raeburn 6493: $extra =
1.171 raeburn 6494: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
6495: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
6496: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
6497: '<option value=""'.$default.'></option>'."\n";
6498: foreach my $server (sort(keys(%{$servers}))) {
6499: if (ref($currbalancer) eq 'HASH') {
6500: next if (exists($currbalancer->{$server}));
6501: }
1.150 raeburn 6502: my $selected;
1.171 raeburn 6503: if ($server eq $current) {
1.150 raeburn 6504: $selected = ' selected="selected"';
6505: }
1.171 raeburn 6506: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 6507: }
6508: $extra .= '</select>';
6509: }
6510: } elsif ($rule eq $current) {
6511: $checked = ' checked="checked"';
6512: }
6513: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 6514: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
6515: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
6516: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 6517: ')"'.$checked.' /> ';
6518: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
6519: $output .= $ruletitles{'particular'};
6520: } else {
6521: $output .= $ruletitles{$rulenames[$i]};
6522: }
6523: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 6524: }
6525: $output .= '</div></td></tr>'."\n";
6526: return $output;
6527: }
6528:
6529: sub offloadtype_text {
6530: my %ruletitles = &Apache::lonlocal::texthash (
6531: 'default' => 'Offloads to default destinations',
6532: 'homeserver' => "Offloads to user's home server",
6533: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
6534: 'specific' => 'Offloads to specific server',
1.161 raeburn 6535: 'none' => 'No offload',
1.209 raeburn 6536: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
6537: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 6538: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 6539: );
6540: return %ruletitles;
6541: }
6542:
6543: sub sparestype_titles {
6544: my %typestitles = &Apache::lonlocal::texthash (
6545: 'primary' => 'primary',
6546: 'default' => 'default',
6547: );
6548: return %typestitles;
6549: }
6550:
1.28 raeburn 6551: sub contact_titles {
6552: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 6553: 'supportemail' => 'Support E-mail address',
6554: 'adminemail' => 'Default Server Admin E-mail address',
6555: 'errormail' => 'Error reports to be e-mailed to',
6556: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 6557: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
6558: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 6559: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
6560: 'requestsmail' => 'E-mail from course requests requiring approval',
6561: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 6562: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 6563: );
6564: my %short_titles = &Apache::lonlocal::texthash (
6565: adminemail => 'Admin E-mail address',
6566: supportemail => 'Support E-mail',
6567: );
6568: return (\%titles,\%short_titles);
6569: }
6570:
1.286 raeburn 6571: sub helpform_fields {
6572: my %titles = &Apache::lonlocal::texthash (
6573: 'username' => 'Name',
6574: 'user' => 'Username/domain',
6575: 'phone' => 'Phone',
6576: 'cc' => 'Cc e-mail',
6577: 'course' => 'Course Details',
6578: 'section' => 'Sections',
1.289 raeburn 6579: 'screenshot' => 'File upload',
1.286 raeburn 6580: );
6581: my @fields = ('username','phone','user','course','section','cc','screenshot');
6582: my %possoptions = (
6583: username => ['yes','no','req'],
1.289 raeburn 6584: phone => ['yes','no','req'],
1.286 raeburn 6585: user => ['yes','no'],
1.289 raeburn 6586: cc => ['yes','no'],
1.286 raeburn 6587: course => ['yes','no'],
6588: section => ['yes','no'],
6589: screenshot => ['yes','no'],
6590: );
6591: my %fieldoptions = &Apache::lonlocal::texthash (
6592: 'yes' => 'Optional',
6593: 'req' => 'Required',
6594: 'no' => "Not shown",
6595: );
6596: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
6597: }
6598:
1.72 raeburn 6599: sub tool_titles {
6600: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 6601: aboutme => 'Personal web page',
1.86 raeburn 6602: blog => 'Blog',
1.162 raeburn 6603: webdav => 'WebDAV',
1.86 raeburn 6604: portfolio => 'Portfolio',
1.88 bisitz 6605: official => 'Official courses (with institutional codes)',
6606: unofficial => 'Unofficial courses',
1.98 raeburn 6607: community => 'Communities',
1.216 raeburn 6608: textbook => 'Textbook courses',
1.271 raeburn 6609: placement => 'Placement tests',
1.86 raeburn 6610: );
1.72 raeburn 6611: return %titles;
6612: }
6613:
1.101 raeburn 6614: sub courserequest_titles {
6615: my %titles = &Apache::lonlocal::texthash (
6616: official => 'Official',
6617: unofficial => 'Unofficial',
6618: community => 'Communities',
1.216 raeburn 6619: textbook => 'Textbook',
1.271 raeburn 6620: placement => 'Placement tests',
1.325 raeburn 6621: lti => 'LTI Provider',
1.101 raeburn 6622: norequest => 'Not allowed',
1.325 raeburn 6623: approval => 'Approval by DC',
1.101 raeburn 6624: validate => 'With validation',
6625: autolimit => 'Numerical limit',
1.103 raeburn 6626: unlimited => '(blank for unlimited)',
1.101 raeburn 6627: );
6628: return %titles;
6629: }
6630:
1.163 raeburn 6631: sub authorrequest_titles {
6632: my %titles = &Apache::lonlocal::texthash (
6633: norequest => 'Not allowed',
6634: approval => 'Approval by Dom. Coord.',
6635: automatic => 'Automatic approval',
6636: );
6637: return %titles;
1.210 raeburn 6638: }
1.163 raeburn 6639:
1.101 raeburn 6640: sub courserequest_conditions {
6641: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 6642: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 6643: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 6644: );
6645: return %conditions;
6646: }
6647:
6648:
1.27 raeburn 6649: sub print_usercreation {
1.30 raeburn 6650: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 6651: my $numinrow = 4;
1.28 raeburn 6652: my $datatable;
6653: if ($position eq 'top') {
1.30 raeburn 6654: $$rowtotal ++;
1.34 raeburn 6655: my $rowcount = 0;
1.32 raeburn 6656: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 6657: if (ref($rules) eq 'HASH') {
6658: if (keys(%{$rules}) > 0) {
1.32 raeburn 6659: $datatable .= &user_formats_row('username',$settings,$rules,
6660: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 6661: $$rowtotal ++;
1.32 raeburn 6662: $rowcount ++;
6663: }
6664: }
6665: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
6666: if (ref($idrules) eq 'HASH') {
6667: if (keys(%{$idrules}) > 0) {
6668: $datatable .= &user_formats_row('id',$settings,$idrules,
6669: $idruleorder,$numinrow,$rowcount);
6670: $$rowtotal ++;
6671: $rowcount ++;
1.28 raeburn 6672: }
6673: }
1.39 raeburn 6674: if ($rowcount == 0) {
6675: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
6676: $$rowtotal ++;
6677: $rowcount ++;
6678: }
1.34 raeburn 6679: } elsif ($position eq 'middle') {
1.224 raeburn 6680: my @creators = ('author','course','requestcrs');
1.37 raeburn 6681: my ($rules,$ruleorder) =
6682: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 6683: my %lt = &usercreation_types();
6684: my %checked;
6685: if (ref($settings) eq 'HASH') {
6686: if (ref($settings->{'cancreate'}) eq 'HASH') {
6687: foreach my $item (@creators) {
6688: $checked{$item} = $settings->{'cancreate'}{$item};
6689: }
6690: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
6691: foreach my $item (@creators) {
6692: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
6693: $checked{$item} = 'none';
6694: }
6695: }
6696: }
6697: }
6698: my $rownum = 0;
6699: foreach my $item (@creators) {
6700: $rownum ++;
1.224 raeburn 6701: if ($checked{$item} eq '') {
6702: $checked{$item} = 'any';
1.34 raeburn 6703: }
6704: my $css_class;
6705: if ($rownum%2) {
6706: $css_class = '';
6707: } else {
6708: $css_class = ' class="LC_odd_row" ';
6709: }
6710: $datatable .= '<tr'.$css_class.'>'.
6711: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 6712: '</span></td><td style="text-align: right">';
1.224 raeburn 6713: my @options = ('any');
6714: if (ref($rules) eq 'HASH') {
6715: if (keys(%{$rules}) > 0) {
6716: push(@options,('official','unofficial'));
1.37 raeburn 6717: }
6718: }
1.224 raeburn 6719: push(@options,'none');
1.37 raeburn 6720: foreach my $option (@options) {
1.50 raeburn 6721: my $type = 'radio';
1.34 raeburn 6722: my $check = ' ';
1.224 raeburn 6723: if ($checked{$item} eq $option) {
6724: $check = ' checked="checked" ';
1.34 raeburn 6725: }
6726: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 6727: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 6728: $item.'" value="'.$option.'"'.$check.'/> '.
6729: $lt{$option}.'</label> </span>';
6730: }
6731: $datatable .= '</td></tr>';
6732: }
1.28 raeburn 6733: } else {
6734: my @contexts = ('author','course','domain');
1.325 raeburn 6735: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 6736: my %checked;
6737: if (ref($settings) eq 'HASH') {
6738: if (ref($settings->{'authtypes'}) eq 'HASH') {
6739: foreach my $item (@contexts) {
6740: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
6741: foreach my $auth (@authtypes) {
6742: if ($settings->{'authtypes'}{$item}{$auth}) {
6743: $checked{$item}{$auth} = ' checked="checked" ';
6744: }
6745: }
6746: }
6747: }
1.27 raeburn 6748: }
1.35 raeburn 6749: } else {
6750: foreach my $item (@contexts) {
1.36 raeburn 6751: foreach my $auth (@authtypes) {
1.35 raeburn 6752: $checked{$item}{$auth} = ' checked="checked" ';
6753: }
6754: }
1.27 raeburn 6755: }
1.28 raeburn 6756: my %title = &context_names();
6757: my %authname = &authtype_names();
6758: my $rownum = 0;
6759: my $css_class;
6760: foreach my $item (@contexts) {
6761: if ($rownum%2) {
6762: $css_class = '';
6763: } else {
6764: $css_class = ' class="LC_odd_row" ';
6765: }
1.30 raeburn 6766: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 6767: '<td>'.$title{$item}.
6768: '</td><td class="LC_left_item">'.
6769: '<span class="LC_nobreak">';
6770: foreach my $auth (@authtypes) {
6771: $datatable .= '<label>'.
6772: '<input type="checkbox" name="'.$item.'_auth" '.
6773: $checked{$item}{$auth}.' value="'.$auth.'" />'.
6774: $authname{$auth}.'</label> ';
6775: }
6776: $datatable .= '</span></td></tr>';
6777: $rownum ++;
1.27 raeburn 6778: }
1.30 raeburn 6779: $$rowtotal += $rownum;
1.27 raeburn 6780: }
6781: return $datatable;
6782: }
6783:
1.224 raeburn 6784: sub print_selfcreation {
6785: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 6786: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
6787: $emaildomain,$datatable);
1.224 raeburn 6788: if (ref($settings) eq 'HASH') {
6789: if (ref($settings->{'cancreate'}) eq 'HASH') {
6790: $createsettings = $settings->{'cancreate'};
1.236 raeburn 6791: if (ref($createsettings) eq 'HASH') {
6792: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
6793: @selfcreate = @{$createsettings->{'selfcreate'}};
6794: } elsif ($createsettings->{'selfcreate'} ne '') {
6795: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
6796: @selfcreate = ('email','login','sso');
6797: } elsif ($createsettings->{'selfcreate'} ne 'none') {
6798: @selfcreate = ($createsettings->{'selfcreate'});
6799: }
6800: }
6801: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
6802: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 6803: }
1.305 raeburn 6804: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
6805: $emailoptions = $createsettings->{'emailoptions'};
6806: }
1.303 raeburn 6807: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
6808: $emailverified = $createsettings->{'emailverified'};
6809: }
6810: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
6811: $emaildomain = $createsettings->{'emaildomain'};
6812: }
1.224 raeburn 6813: }
6814: }
6815: }
6816: my %radiohash;
6817: my $numinrow = 4;
6818: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 6819: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 6820: if ($position eq 'top') {
6821: my %choices = &Apache::lonlocal::texthash (
6822: cancreate_login => 'Institutional Login',
6823: cancreate_sso => 'Institutional Single Sign On',
6824: );
6825: my @toggles = sort(keys(%choices));
6826: my %defaultchecked = (
6827: 'cancreate_login' => 'off',
6828: 'cancreate_sso' => 'off',
6829: );
1.228 raeburn 6830: my ($onclick,$itemcount);
1.224 raeburn 6831: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6832: \%choices,$itemcount,$onclick);
1.228 raeburn 6833: $$rowtotal += $itemcount;
6834:
1.224 raeburn 6835: if (ref($usertypes) eq 'HASH') {
6836: if (keys(%{$usertypes}) > 0) {
6837: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
6838: $dom,$numinrow,$othertitle,
1.305 raeburn 6839: 'statustocreate',$rowtotal);
1.224 raeburn 6840: $$rowtotal ++;
6841: }
6842: }
1.240 raeburn 6843: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
6844: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6845: $fieldtitles{'inststatus'} = &mt('Institutional status');
6846: my $rem;
6847: my $numperrow = 2;
6848: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
6849: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 6850: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 6851: '<td class="LC_left_item">'."\n".
1.334 raeburn 6852: '<table>'."\n";
1.240 raeburn 6853: for (my $i=0; $i<@fields; $i++) {
6854: $rem = $i%($numperrow);
6855: if ($rem == 0) {
6856: if ($i > 0) {
6857: $datatable .= '</tr>';
6858: }
6859: $datatable .= '<tr>';
6860: }
6861: my $currval;
1.248 raeburn 6862: if (ref($createsettings) eq 'HASH') {
6863: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
6864: $currval = $createsettings->{'shibenv'}{$fields[$i]};
6865: }
1.240 raeburn 6866: }
6867: $datatable .= '<td class="LC_left_item">'.
6868: '<span class="LC_nobreak">'.
6869: '<input type="text" name="shibenv_'.$fields[$i].'" '.
6870: 'value="'.$currval.'" size="10" /> '.
6871: $fieldtitles{$fields[$i]}.'</span></td>';
6872: }
6873: my $colsleft = $numperrow - $rem;
6874: if ($colsleft > 1 ) {
6875: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6876: ' </td>';
6877: } elsif ($colsleft == 1) {
6878: $datatable .= '<td class="LC_left_item"> </td>';
6879: }
6880: $datatable .= '</tr></table></td></tr>';
6881: $$rowtotal ++;
1.224 raeburn 6882: } elsif ($position eq 'middle') {
6883: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 6884: my @posstypes;
1.224 raeburn 6885: if (ref($types) eq 'ARRAY') {
1.302 raeburn 6886: @posstypes = @{$types};
6887: }
6888: unless (grep(/^default$/,@posstypes)) {
6889: push(@posstypes,'default');
6890: }
6891: my %usertypeshash;
6892: if (ref($usertypes) eq 'HASH') {
6893: %usertypeshash = %{$usertypes};
6894: }
6895: $usertypeshash{'default'} = $othertitle;
6896: foreach my $status (@posstypes) {
6897: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
6898: $numinrow,$$rowtotal,\%usertypeshash);
6899: $$rowtotal ++;
1.224 raeburn 6900: }
6901: } else {
1.236 raeburn 6902: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 6903: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 6904: );
6905: my @toggles = sort(keys(%choices));
6906: my %defaultchecked = (
6907: 'cancreate_email' => 'off',
6908: );
1.305 raeburn 6909: my $customclass = 'LC_selfcreate_email';
6910: my $classprefix = 'LC_canmodify_emailusername_';
6911: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 6912: my $display = 'none';
1.305 raeburn 6913: my $rowstyle = 'display:none';
1.236 raeburn 6914: if (grep(/^\Qemail\E$/,@selfcreate)) {
6915: $display = 'block';
1.305 raeburn 6916: $rowstyle = 'display:table-row';
1.236 raeburn 6917: }
1.305 raeburn 6918: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
6919: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6920: \%choices,$$rowtotal,$onclick);
6921: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
6922: $rowstyle);
6923: $$rowtotal ++;
6924: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
6925: $rowstyle);
6926: $$rowtotal ++;
6927: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 6928: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 6929: my ($emailrules,$emailruleorder) =
6930: &Apache::lonnet::inst_userrules($dom,'email');
6931: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6932: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6933: if (ref($types) eq 'ARRAY') {
6934: @posstypes = @{$types};
6935: }
6936: if (@posstypes) {
6937: unless (grep(/^default$/,@posstypes)) {
6938: push(@posstypes,'default');
1.302 raeburn 6939: }
6940: if (ref($usertypes) eq 'HASH') {
6941: %usertypeshash = %{$usertypes};
6942: }
1.305 raeburn 6943: my $currassign;
6944: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
6945: $currassign = {
6946: selfassign => $domdefaults{'inststatusguest'},
6947: };
6948: @ordered = @{$domdefaults{'inststatusguest'}};
6949: } else {
6950: $currassign = { selfassign => [] };
6951: }
6952: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
6953: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
6954: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
6955: $numinrow,$othertitle,'selfassign',
6956: $rowtotal,$onclicktypes,$customclass,
6957: $rowstyle);
6958: $$rowtotal ++;
1.302 raeburn 6959: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 6960: foreach my $status (@posstypes) {
6961: my $css_class;
6962: if ($$rowtotal%2) {
6963: $css_class = 'LC_odd_row ';
6964: }
6965: $css_class .= $customclass;
6966: my $rowid = $optionsprefix.$status;
6967: my $hidden = 1;
6968: my $currstyle = 'display:none';
6969: if (grep(/^\Q$status\E$/,@ordered)) {
6970: $currstyle = $rowstyle;
6971: $hidden = 0;
6972: }
6973: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
6974: $emailrules,$emailruleorder,$settings,$status,$rowid,
6975: $usertypeshash{$status},$css_class,$currstyle,$intdom);
6976: unless ($hidden) {
6977: $$rowtotal ++;
6978: }
1.224 raeburn 6979: }
1.302 raeburn 6980: } else {
1.305 raeburn 6981: my $css_class;
6982: if ($$rowtotal%2) {
6983: $css_class = 'LC_odd_row ';
6984: }
6985: $css_class .= $customclass;
1.302 raeburn 6986: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 6987: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
6988: $emailrules,$emailruleorder,$settings,'default','',
6989: $othertitle,$css_class,$rowstyle,$intdom);
6990: $$rowtotal ++;
1.224 raeburn 6991: }
6992: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 6993: $numinrow = 1;
1.305 raeburn 6994: if (@posstypes) {
6995: foreach my $status (@posstypes) {
6996: my $rowid = $classprefix.$status;
6997: my $datarowstyle = 'display:none';
6998: if (grep(/^\Q$status\E$/,@ordered)) {
6999: $datarowstyle = $rowstyle;
7000: }
7001: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
7002: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7003: $infotitles,$rowid,$customclass,$datarowstyle);
7004: unless ($datarowstyle eq 'display:none') {
7005: $$rowtotal ++;
7006: }
1.224 raeburn 7007: }
1.305 raeburn 7008: } else {
7009: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
7010: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7011: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 7012: }
7013: }
7014: return $datatable;
7015: }
7016:
1.305 raeburn 7017: sub selfcreate_javascript {
7018: return <<"ENDSCRIPT";
7019:
7020: <script type="text/javascript">
7021: // <![CDATA[
7022:
7023: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
7024: var x = document.getElementsByClassName(target);
7025: var insttypes = 0;
7026: var insttypeRegExp = new RegExp(prefix);
7027: if ((x.length != undefined) && (x.length > 0)) {
7028: if (form.elements[radio].length != undefined) {
7029: for (var i=0; i<form.elements[radio].length; i++) {
7030: if (form.elements[radio][i].checked) {
7031: if (form.elements[radio][i].value == 1) {
7032: for (var j=0; j<x.length; j++) {
7033: if (x[j].id == 'undefined') {
7034: x[j].style.display = 'table-row';
7035: } else if (insttypeRegExp.test(x[j].id)) {
7036: insttypes ++;
7037: } else {
7038: x[j].style.display = 'table-row';
7039: }
7040: }
7041: } else {
7042: for (var j=0; j<x.length; j++) {
7043: x[j].style.display = 'none';
7044: }
1.236 raeburn 7045: }
1.305 raeburn 7046: break;
7047: }
7048: }
7049: if (insttypes > 0) {
7050: toggleDataRow(form,checkbox,target,altprefix);
7051: toggleDataRow(form,checkbox,target,prefix,1);
7052: }
7053: }
7054: }
7055: return;
7056: }
7057:
7058: function toggleDataRow(form,checkbox,target,prefix,docount) {
7059: if (form.elements[checkbox].length != undefined) {
7060: var count = 0;
7061: if (docount) {
7062: for (var i=0; i<form.elements[checkbox].length; i++) {
7063: if (form.elements[checkbox][i].checked) {
7064: count ++;
1.236 raeburn 7065: }
1.305 raeburn 7066: }
7067: }
7068: for (var i=0; i<form.elements[checkbox].length; i++) {
7069: var type = form.elements[checkbox][i].value;
7070: if (document.getElementById(prefix+type)) {
7071: if (form.elements[checkbox][i].checked) {
7072: document.getElementById(prefix+type).style.display = 'table-row';
7073: if (count % 2 == 1) {
7074: document.getElementById(prefix+type).className = target+' LC_odd_row';
7075: } else {
7076: document.getElementById(prefix+type).className = target;
1.236 raeburn 7077: }
1.305 raeburn 7078: count ++;
1.236 raeburn 7079: } else {
1.305 raeburn 7080: document.getElementById(prefix+type).style.display = 'none';
7081: }
7082: }
7083: }
7084: }
7085: return;
7086: }
7087:
7088: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
7089: var caller = radio+'_'+status;
7090: if (form.elements[caller].length != undefined) {
7091: for (var i=0; i<form.elements[caller].length; i++) {
7092: if (form.elements[caller][i].checked) {
7093: if (document.getElementById(altprefix+'_inst_'+status)) {
7094: var curr = form.elements[caller][i].value;
7095: if (prefix) {
7096: document.getElementById(prefix+'_'+status).style.display = 'none';
7097: }
7098: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
7099: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
7100: if (curr == 'custom') {
7101: if (prefix) {
7102: document.getElementById(prefix+'_'+status).style.display = 'inline';
7103: }
7104: } else if (curr == 'inst') {
7105: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
7106: } else if (curr == 'noninst') {
7107: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 7108: }
1.305 raeburn 7109: break;
1.236 raeburn 7110: }
7111: }
7112: }
7113: }
7114: }
7115:
1.305 raeburn 7116: // ]]>
7117: </script>
7118:
7119: ENDSCRIPT
7120: }
7121:
7122: sub noninst_users {
7123: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
7124: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
7125: my $class = 'LC_left_item';
7126: if ($css_class) {
7127: $css_class = ' class="'.$css_class.'"';
7128: }
7129: if ($rowid) {
7130: $rowid = ' id="'.$rowid.'"';
7131: }
7132: if ($rowstyle) {
7133: $rowstyle = ' style="'.$rowstyle.'"';
7134: }
7135: my ($output,$description);
7136: if ($type eq 'default') {
7137: $description = &mt('Requests for: [_1]',$typetitle);
7138: } else {
7139: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
7140: }
7141: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
7142: "<td>$description</td>\n".
7143: '<td class="'.$class.'" colspan="2">'.
7144: '<table><tr>';
7145: my %headers = &Apache::lonlocal::texthash(
7146: approve => 'Processing',
7147: email => 'E-mail',
7148: username => 'Username',
7149: );
7150: foreach my $item ('approve','email','username') {
7151: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 7152: }
1.305 raeburn 7153: $output .= '</tr><tr>';
7154: foreach my $item ('approve','email','username') {
1.306 raeburn 7155: $output .= '<td style="vertical-align: top">';
1.305 raeburn 7156: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
7157: if ($item eq 'approve') {
7158: %choices = &Apache::lonlocal::texthash (
7159: automatic => 'Automatically approved',
7160: approval => 'Queued for approval',
7161: );
7162: @options = ('automatic','approval');
7163: $hashref = $processing;
7164: $defoption = 'automatic';
7165: $name = 'cancreate_emailprocess_'.$type;
7166: } elsif ($item eq 'email') {
7167: %choices = &Apache::lonlocal::texthash (
7168: any => 'Any e-mail',
7169: inst => 'Institutional only',
7170: noninst => 'Non-institutional only',
7171: custom => 'Custom restrictions',
7172: );
7173: @options = ('any','inst','noninst');
7174: my $showcustom;
7175: if (ref($emailrules) eq 'HASH') {
7176: if (keys(%{$emailrules}) > 0) {
7177: push(@options,'custom');
7178: $showcustom = 'cancreate_emailrule';
7179: if (ref($settings) eq 'HASH') {
7180: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
7181: foreach my $rule (@{$settings->{'email_rule'}}) {
7182: if (exists($emailrules->{$rule})) {
7183: $hascustom ++;
7184: }
7185: }
7186: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
7187: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
7188: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
7189: if (exists($emailrules->{$rule})) {
7190: $hascustom ++;
7191: }
7192: }
7193: }
7194: }
7195: }
7196: }
7197: }
7198: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
7199: "'cancreate_emaildomain','$type'".');"';
7200: $hashref = $emailoptions;
7201: $defoption = 'any';
7202: $name = 'cancreate_emailoptions_'.$type;
7203: } elsif ($item eq 'username') {
7204: %choices = &Apache::lonlocal::texthash (
7205: all => 'Same as e-mail',
7206: first => 'Omit @domain',
7207: free => 'Free to choose',
7208: );
7209: @options = ('all','first','free');
7210: $hashref = $emailverified;
7211: $defoption = 'all';
7212: $name = 'cancreate_usernameoptions_'.$type;
7213: }
7214: foreach my $option (@options) {
7215: my $checked;
7216: if (ref($hashref) eq 'HASH') {
7217: if ($type eq '') {
7218: if (!exists($hashref->{'default'})) {
7219: if ($option eq $defoption) {
7220: $checked = ' checked="checked"';
7221: }
7222: } else {
7223: if ($hashref->{'default'} eq $option) {
7224: $checked = ' checked="checked"';
7225: }
1.303 raeburn 7226: }
7227: } else {
1.305 raeburn 7228: if (!exists($hashref->{$type})) {
7229: if ($option eq $defoption) {
7230: $checked = ' checked="checked"';
7231: }
7232: } else {
7233: if ($hashref->{$type} eq $option) {
7234: $checked = ' checked="checked"';
7235: }
1.303 raeburn 7236: }
7237: }
1.305 raeburn 7238: } elsif (($item eq 'email') && ($hascustom)) {
7239: if ($option eq 'custom') {
7240: $checked = ' checked="checked"';
7241: }
7242: } elsif ($option eq $defoption) {
7243: $checked = ' checked="checked"';
7244: }
7245: $output .= '<span class="LC_nobreak"><label>'.
7246: '<input type="radio" name="'.$name.'"'.
7247: $checked.' value="'.$option.'"'.$onclick.' />'.
7248: $choices{$option}.'</label></span><br />';
7249: if ($item eq 'email') {
7250: if ($option eq 'custom') {
7251: my $id = 'cancreate_emailrule_'.$type;
7252: my $display = 'none';
7253: if ($checked) {
7254: $display = 'inline';
1.303 raeburn 7255: }
1.305 raeburn 7256: my $numinrow = 2;
7257: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
7258: '<legend>'.&mt('Disallow').'</legend><table>'.
7259: &user_formats_row('email',$settings,$emailrules,
7260: $emailruleorder,$numinrow,'',$type);
7261: '</table></fieldset>';
7262: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
7263: my %text = &Apache::lonlocal::texthash (
7264: inst => 'must end:',
7265: noninst => 'cannot end:',
7266: );
7267: my $value;
7268: if (ref($emaildomain) eq 'HASH') {
7269: if (ref($emaildomain->{$type}) eq 'HASH') {
7270: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 7271: }
7272: }
1.305 raeburn 7273: if ($value eq '') {
7274: $value = '@'.$intdom;
7275: }
7276: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
7277: my $display = 'none';
7278: if ($checked) {
7279: $display = 'inline';
7280: }
7281: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
7282: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
7283: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
7284: '</div>';
1.303 raeburn 7285: }
7286: }
7287: }
1.305 raeburn 7288: $output .= '</td>'."\n";
1.303 raeburn 7289: }
1.305 raeburn 7290: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 7291: return $output;
7292: }
7293:
1.165 raeburn 7294: sub captcha_choice {
1.305 raeburn 7295: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 7296: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
7297: $vertext,$currver);
1.165 raeburn 7298: my %lt = &captcha_phrases();
7299: $keyentry = 'hidden';
7300: if ($context eq 'cancreate') {
1.224 raeburn 7301: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 7302: } elsif ($context eq 'login') {
7303: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 7304: }
7305: if (ref($settings) eq 'HASH') {
7306: if ($settings->{'captcha'}) {
7307: $checked{$settings->{'captcha'}} = ' checked="checked"';
7308: } else {
7309: $checked{'original'} = ' checked="checked"';
7310: }
7311: if ($settings->{'captcha'} eq 'recaptcha') {
7312: $pubtext = $lt{'pub'};
7313: $privtext = $lt{'priv'};
7314: $keyentry = 'text';
1.269 raeburn 7315: $vertext = $lt{'ver'};
7316: $currver = $settings->{'recaptchaversion'};
7317: if ($currver ne '2') {
7318: $currver = 1;
7319: }
1.165 raeburn 7320: }
7321: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
7322: $currpub = $settings->{'recaptchakeys'}{'public'};
7323: $currpriv = $settings->{'recaptchakeys'}{'private'};
7324: }
7325: } else {
7326: $checked{'original'} = ' checked="checked"';
7327: }
1.305 raeburn 7328: my $css_class;
7329: if ($itemcount%2) {
7330: $css_class = 'LC_odd_row';
7331: }
7332: if ($customcss) {
7333: $css_class .= " $customcss";
7334: }
7335: $css_class =~ s/^\s+//;
7336: if ($css_class) {
7337: $css_class = ' class="'.$css_class.'"';
7338: }
7339: if ($rowstyle) {
7340: $css_class .= ' style="'.$rowstyle.'"';
7341: }
1.169 raeburn 7342: my $output = '<tr'.$css_class.'>'.
7343: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 7344: '<table><tr><td>'."\n";
7345: foreach my $option ('original','recaptcha','notused') {
7346: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
7347: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
7348: $lt{$option}.'</label></span>';
7349: unless ($option eq 'notused') {
7350: $output .= (' 'x2)."\n";
7351: }
7352: }
7353: #
7354: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
7355: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 7356: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 7357: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 7358: #
1.165 raeburn 7359: $output .= '</td></tr>'."\n".
1.305 raeburn 7360: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 7361: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
7362: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
7363: $currpub.'" size="40" /></span><br />'."\n".
7364: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
7365: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 7366: $currpriv.'" size="40" /></span><br />'.
7367: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
7368: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
7369: $currver.'" size="3" /></span><br />'.
7370: '</td></tr></table>'."\n".
1.165 raeburn 7371: '</td></tr>';
7372: return $output;
7373: }
7374:
1.32 raeburn 7375: sub user_formats_row {
1.305 raeburn 7376: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 7377: my $output;
7378: my %text = (
7379: 'username' => 'new usernames',
7380: 'id' => 'IDs',
7381: );
1.305 raeburn 7382: unless ($type eq 'email') {
7383: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
7384: $output = '<tr '.$css_class.'>'.
7385: '<td><span class="LC_nobreak">'.
7386: &mt("Format rules to check for $text{$type}: ").
7387: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 7388: }
1.27 raeburn 7389: my $rem;
7390: if (ref($ruleorder) eq 'ARRAY') {
7391: for (my $i=0; $i<@{$ruleorder}; $i++) {
7392: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
7393: my $rem = $i%($numinrow);
7394: if ($rem == 0) {
7395: if ($i > 0) {
7396: $output .= '</tr>';
7397: }
7398: $output .= '<tr>';
7399: }
7400: my $check = ' ';
1.39 raeburn 7401: if (ref($settings) eq 'HASH') {
7402: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
7403: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
7404: $check = ' checked="checked" ';
7405: }
1.305 raeburn 7406: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
7407: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
7408: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
7409: $check = ' checked="checked" ';
7410: }
7411: }
1.27 raeburn 7412: }
7413: }
1.305 raeburn 7414: my $name = $type.'_rule';
7415: if ($type eq 'email') {
7416: $name .= '_'.$status;
7417: }
1.27 raeburn 7418: $output .= '<td class="LC_left_item">'.
7419: '<span class="LC_nobreak"><label>'.
1.311 raeburn 7420: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 7421: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
7422: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
7423: }
7424: }
7425: $rem = @{$ruleorder}%($numinrow);
7426: }
1.305 raeburn 7427: my $colsleft;
7428: if ($rem) {
7429: $colsleft = $numinrow - $rem;
7430: }
1.27 raeburn 7431: if ($colsleft > 1 ) {
7432: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7433: ' </td>';
7434: } elsif ($colsleft == 1) {
7435: $output .= '<td class="LC_left_item"> </td>';
7436: }
1.305 raeburn 7437: $output .= '</tr></table>';
7438: unless ($type eq 'email') {
7439: $output .= '</td></tr>';
7440: }
1.27 raeburn 7441: return $output;
7442: }
7443:
1.34 raeburn 7444: sub usercreation_types {
7445: my %lt = &Apache::lonlocal::texthash (
7446: author => 'When adding a co-author',
7447: course => 'When adding a user to a course',
1.100 raeburn 7448: requestcrs => 'When requesting a course',
1.34 raeburn 7449: any => 'Any',
7450: official => 'Institutional only ',
7451: unofficial => 'Non-institutional only',
7452: none => 'None',
7453: );
7454: return %lt;
1.48 raeburn 7455: }
1.34 raeburn 7456:
1.224 raeburn 7457: sub selfcreation_types {
7458: my %lt = &Apache::lonlocal::texthash (
7459: selfcreate => 'User creates own account',
7460: any => 'Any',
7461: official => 'Institutional only ',
7462: unofficial => 'Non-institutional only',
7463: email => 'E-mail address',
7464: login => 'Institutional Login',
7465: sso => 'SSO',
7466: );
7467: }
7468:
1.28 raeburn 7469: sub authtype_names {
7470: my %lt = &Apache::lonlocal::texthash(
7471: int => 'Internal',
7472: krb4 => 'Kerberos 4',
7473: krb5 => 'Kerberos 5',
7474: loc => 'Local',
1.325 raeburn 7475: lti => 'LTI',
1.28 raeburn 7476: );
7477: return %lt;
7478: }
7479:
7480: sub context_names {
7481: my %context_title = &Apache::lonlocal::texthash(
7482: author => 'Creating users when an Author',
7483: course => 'Creating users when in a course',
7484: domain => 'Creating users when a Domain Coordinator',
7485: );
7486: return %context_title;
7487: }
7488:
1.33 raeburn 7489: sub print_usermodification {
7490: my ($position,$dom,$settings,$rowtotal) = @_;
7491: my $numinrow = 4;
7492: my ($context,$datatable,$rowcount);
7493: if ($position eq 'top') {
7494: $rowcount = 0;
7495: $context = 'author';
7496: foreach my $role ('ca','aa') {
7497: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7498: $numinrow,$rowcount);
7499: $$rowtotal ++;
7500: $rowcount ++;
7501: }
1.230 raeburn 7502: } elsif ($position eq 'bottom') {
1.33 raeburn 7503: $context = 'course';
7504: $rowcount = 0;
7505: foreach my $role ('st','ep','ta','in','cr') {
7506: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7507: $numinrow,$rowcount);
7508: $$rowtotal ++;
7509: $rowcount ++;
7510: }
7511: }
7512: return $datatable;
7513: }
7514:
1.43 raeburn 7515: sub print_defaults {
1.236 raeburn 7516: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 7517: my $rownum = 0;
1.294 raeburn 7518: my ($datatable,$css_class,$titles);
7519: unless ($position eq 'bottom') {
7520: $titles = &defaults_titles($dom);
7521: }
1.236 raeburn 7522: if ($position eq 'top') {
7523: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
7524: 'datelocale_def','portal_def');
7525: my %defaults;
7526: if (ref($settings) eq 'HASH') {
7527: %defaults = %{$settings};
1.43 raeburn 7528: } else {
1.236 raeburn 7529: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
7530: foreach my $item (@items) {
7531: $defaults{$item} = $domdefaults{$item};
7532: }
1.43 raeburn 7533: }
1.236 raeburn 7534: foreach my $item (@items) {
7535: if ($rownum%2) {
7536: $css_class = '';
7537: } else {
7538: $css_class = ' class="LC_odd_row" ';
7539: }
7540: $datatable .= '<tr'.$css_class.'>'.
7541: '<td><span class="LC_nobreak">'.$titles->{$item}.
7542: '</span></td><td class="LC_right_item" colspan="3">';
7543: if ($item eq 'auth_def') {
1.325 raeburn 7544: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 7545: my %shortauth = (
7546: internal => 'int',
7547: krb4 => 'krb4',
7548: krb5 => 'krb5',
1.325 raeburn 7549: localauth => 'loc',
7550: lti => 'lti',
1.236 raeburn 7551: );
7552: my %authnames = &authtype_names();
7553: foreach my $auth (@authtypes) {
7554: my $checked = ' ';
7555: if ($defaults{$item} eq $auth) {
7556: $checked = ' checked="checked" ';
7557: }
7558: $datatable .= '<label><input type="radio" name="'.$item.
7559: '" value="'.$auth.'"'.$checked.'/>'.
7560: $authnames{$shortauth{$auth}}.'</label> ';
7561: }
7562: } elsif ($item eq 'timezone_def') {
7563: my $includeempty = 1;
7564: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
7565: } elsif ($item eq 'datelocale_def') {
7566: my $includeempty = 1;
7567: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
7568: } elsif ($item eq 'lang_def') {
1.263 raeburn 7569: my $includeempty = 1;
7570: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 7571: } else {
7572: my $size;
7573: if ($item eq 'portal_def') {
7574: $size = ' size="25"';
7575: }
7576: $datatable .= '<input type="text" name="'.$item.'" value="'.
7577: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 7578: }
1.236 raeburn 7579: $datatable .= '</td></tr>';
7580: $rownum ++;
7581: }
1.294 raeburn 7582: } elsif ($position eq 'middle') {
7583: my @items = ('intauth_cost','intauth_check','intauth_switch');
7584: my %defaults;
7585: if (ref($settings) eq 'HASH') {
7586: %defaults = %{$settings};
7587: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
7588: $defaults{'intauth_cost'} = 10;
7589: }
7590: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
7591: $defaults{'intauth_check'} = 0;
7592: }
7593: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
7594: $defaults{'intauth_switch'} = 0;
7595: }
7596: } else {
7597: %defaults = (
7598: 'intauth_cost' => 10,
7599: 'intauth_check' => 0,
7600: 'intauth_switch' => 0,
7601: );
7602: }
7603: foreach my $item (@items) {
7604: if ($rownum%2) {
7605: $css_class = '';
7606: } else {
7607: $css_class = ' class="LC_odd_row" ';
7608: }
7609: $datatable .= '<tr'.$css_class.'>'.
7610: '<td><span class="LC_nobreak">'.$titles->{$item}.
7611: '</span></td><td class="LC_left_item" colspan="3">';
7612: if ($item eq 'intauth_switch') {
7613: my @options = (0,1,2);
7614: my %optiondesc = &Apache::lonlocal::texthash (
7615: 0 => 'No',
7616: 1 => 'Yes',
7617: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
7618: );
7619: $datatable .= '<table width="100%">';
7620: foreach my $option (@options) {
7621: my $checked = ' ';
7622: if ($defaults{$item} eq $option) {
7623: $checked = ' checked="checked"';
7624: }
7625: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7626: '<label><input type="radio" name="'.$item.
7627: '" value="'.$option.'"'.$checked.' />'.
7628: $optiondesc{$option}.'</label></span></td></tr>';
7629: }
7630: $datatable .= '</table>';
7631: } elsif ($item eq 'intauth_check') {
7632: my @options = (0,1,2);
7633: my %optiondesc = &Apache::lonlocal::texthash (
7634: 0 => 'No',
7635: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
7636: 2 => 'Yes, disallow login if stored cost is less than domain default',
7637: );
1.332 raeburn 7638: $datatable .= '<table width="100%">';
1.294 raeburn 7639: foreach my $option (@options) {
7640: my $checked = ' ';
7641: my $onclick;
7642: if ($defaults{$item} eq $option) {
7643: $checked = ' checked="checked"';
7644: }
7645: if ($option == 2) {
7646: $onclick = ' onclick="javascript:warnIntAuth(this);"';
7647: }
7648: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7649: '<label><input type="radio" name="'.$item.
7650: '" value="'.$option.'"'.$checked.$onclick.' />'.
7651: $optiondesc{$option}.'</label></span></td></tr>';
7652: }
7653: $datatable .= '</table>';
7654: } else {
7655: $datatable .= '<input type="text" name="'.$item.'" value="'.
7656: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
7657: }
7658: $datatable .= '</td></tr>';
7659: $rownum ++;
7660: }
1.236 raeburn 7661: } else {
1.294 raeburn 7662: my %defaults;
1.236 raeburn 7663: if (ref($settings) eq 'HASH') {
1.305 raeburn 7664: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.236 raeburn 7665: my $maxnum = @{$settings->{'inststatusorder'}};
7666: for (my $i=0; $i<$maxnum; $i++) {
7667: $css_class = $rownum%2?' class="LC_odd_row"':'';
7668: my $item = $settings->{'inststatusorder'}->[$i];
7669: my $title = $settings->{'inststatustypes'}->{$item};
7670: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
7671: $datatable .= '<tr'.$css_class.'>'.
7672: '<td><span class="LC_nobreak">'.
7673: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
7674: for (my $k=0; $k<=$maxnum; $k++) {
7675: my $vpos = $k+1;
7676: my $selstr;
7677: if ($k == $i) {
7678: $selstr = ' selected="selected" ';
7679: }
7680: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7681: }
7682: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
7683: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
7684: &mt('delete').'</span></td>'.
1.305 raeburn 7685: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed:').
1.236 raeburn 7686: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.305 raeburn 7687: '</span></td></tr>';
1.236 raeburn 7688: }
7689: $css_class = $rownum%2?' class="LC_odd_row"':'';
7690: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
7691: $datatable .= '<tr '.$css_class.'>'.
7692: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
7693: for (my $k=0; $k<=$maxnum; $k++) {
7694: my $vpos = $k+1;
7695: my $selstr;
7696: if ($k == $maxnum) {
7697: $selstr = ' selected="selected" ';
7698: }
7699: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7700: }
7701: $datatable .= '</select> '.&mt('Internal ID:').
1.263 raeburn 7702: '<input type="text" size="10" name="addinststatus" value="" />'.
1.236 raeburn 7703: ' '.&mt('(new)').
1.305 raeburn 7704: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.236 raeburn 7705: &mt('Name displayed:').
7706: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
7707: '</tr>'."\n";
7708: $rownum ++;
1.141 raeburn 7709: }
1.43 raeburn 7710: }
7711: }
7712: $$rowtotal += $rownum;
7713: return $datatable;
7714: }
7715:
1.168 raeburn 7716: sub get_languages_hash {
7717: my %langchoices;
7718: foreach my $id (&Apache::loncommon::languageids()) {
7719: my $code = &Apache::loncommon::supportedlanguagecode($id);
7720: if ($code ne '') {
7721: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
7722: }
7723: }
7724: return %langchoices;
7725: }
7726:
1.43 raeburn 7727: sub defaults_titles {
1.141 raeburn 7728: my ($dom) = @_;
1.43 raeburn 7729: my %titles = &Apache::lonlocal::texthash (
7730: 'auth_def' => 'Default authentication type',
7731: 'auth_arg_def' => 'Default authentication argument',
7732: 'lang_def' => 'Default language',
1.54 raeburn 7733: 'timezone_def' => 'Default timezone',
1.68 raeburn 7734: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 7735: 'portal_def' => 'Portal/Default URL',
1.294 raeburn 7736: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
7737: 'intauth_check' => 'Check bcrypt cost if authenticated',
7738: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 7739: );
1.141 raeburn 7740: if ($dom) {
7741: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
7742: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
7743: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
7744: $protocol = 'http' if ($protocol ne 'https');
7745: if ($uint_dom) {
7746: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
7747: $uint_dom);
7748: }
7749: }
1.43 raeburn 7750: return (\%titles);
7751: }
7752:
1.46 raeburn 7753: sub print_scantronformat {
7754: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
7755: my $itemcount = 1;
1.60 raeburn 7756: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
7757: %confhash);
1.46 raeburn 7758: my $switchserver = &check_switchserver($dom,$confname);
7759: my %lt = &Apache::lonlocal::texthash (
1.95 www 7760: default => 'Default bubblesheet format file error',
7761: custom => 'Custom bubblesheet format file error',
1.46 raeburn 7762: );
7763: my %scantronfiles = (
7764: default => 'default.tab',
7765: custom => 'custom.tab',
7766: );
7767: foreach my $key (keys(%scantronfiles)) {
7768: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
7769: .$scantronfiles{$key};
7770: }
7771: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
7772: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
7773: if (!$switchserver) {
7774: my $servadm = $r->dir_config('lonAdmEMail');
7775: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
7776: if ($configuserok eq 'ok') {
7777: if ($author_ok eq 'ok') {
7778: my %legacyfile = (
7779: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
7780: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
7781: );
7782: my %md5chk;
7783: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 7784: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
7785: chomp($md5chk{$type});
1.46 raeburn 7786: }
7787: if ($md5chk{'default'} ne $md5chk{'custom'}) {
7788: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 7789: ($scantronurls{$type},my $error) =
1.46 raeburn 7790: &legacy_scantronformat($r,$dom,$confname,
7791: $type,$legacyfile{$type},
7792: $scantronurls{$type},
7793: $scantronfiles{$type});
1.60 raeburn 7794: if ($error ne '') {
7795: $error{$type} = $error;
7796: }
7797: }
7798: if (keys(%error) == 0) {
7799: $is_custom = 1;
7800: $confhash{'scantron'}{'scantronformat'} =
7801: $scantronurls{'custom'};
7802: my $putresult =
7803: &Apache::lonnet::put_dom('configuration',
7804: \%confhash,$dom);
7805: if ($putresult ne 'ok') {
7806: $error{'custom'} =
7807: '<span class="LC_error">'.
7808: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7809: }
1.46 raeburn 7810: }
7811: } else {
1.60 raeburn 7812: ($scantronurls{'default'},my $error) =
1.46 raeburn 7813: &legacy_scantronformat($r,$dom,$confname,
7814: 'default',$legacyfile{'default'},
7815: $scantronurls{'default'},
7816: $scantronfiles{'default'});
1.60 raeburn 7817: if ($error eq '') {
7818: $confhash{'scantron'}{'scantronformat'} = '';
7819: my $putresult =
7820: &Apache::lonnet::put_dom('configuration',
7821: \%confhash,$dom);
7822: if ($putresult ne 'ok') {
7823: $error{'default'} =
7824: '<span class="LC_error">'.
7825: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7826: }
7827: } else {
7828: $error{'default'} = $error;
7829: }
1.46 raeburn 7830: }
7831: }
7832: }
7833: } else {
1.95 www 7834: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 7835: }
7836: }
7837: if (ref($settings) eq 'HASH') {
7838: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
7839: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
7840: if ((!@info) || ($info[0] eq 'no_such_dir')) {
7841: $scantronurl = '';
7842: } else {
7843: $scantronurl = $settings->{'scantronformat'};
7844: }
7845: $is_custom = 1;
7846: } else {
7847: $scantronurl = $scantronurls{'default'};
7848: }
7849: } else {
1.60 raeburn 7850: if ($is_custom) {
7851: $scantronurl = $scantronurls{'custom'};
7852: } else {
7853: $scantronurl = $scantronurls{'default'};
7854: }
1.46 raeburn 7855: }
7856: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7857: $datatable .= '<tr'.$css_class.'>';
7858: if (!$is_custom) {
1.65 raeburn 7859: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
7860: '<span class="LC_nobreak">';
1.46 raeburn 7861: if ($scantronurl) {
1.199 raeburn 7862: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
7863: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 7864: } else {
7865: $datatable = &mt('File unavailable for display');
7866: }
1.65 raeburn 7867: $datatable .= '</span></td>';
1.60 raeburn 7868: if (keys(%error) == 0) {
1.306 raeburn 7869: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 7870: if (!$switchserver) {
7871: $datatable .= &mt('Upload:').'<br />';
7872: }
7873: } else {
7874: my $errorstr;
7875: foreach my $key (sort(keys(%error))) {
7876: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7877: }
7878: $datatable .= '<td>'.$errorstr;
7879: }
1.46 raeburn 7880: } else {
7881: if (keys(%error) > 0) {
7882: my $errorstr;
7883: foreach my $key (sort(keys(%error))) {
7884: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7885: }
1.60 raeburn 7886: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 7887: } elsif ($scantronurl) {
1.199 raeburn 7888: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
7889: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 7890: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 7891: $link.
7892: '<label><input type="checkbox" name="scantronformat_del"'.
7893: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 7894: '<td><span class="LC_nobreak"> '.
7895: &mt('Replace:').'</span><br />';
1.46 raeburn 7896: }
7897: }
7898: if (keys(%error) == 0) {
7899: if ($switchserver) {
7900: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
7901: } else {
1.65 raeburn 7902: $datatable .='<span class="LC_nobreak"> '.
7903: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 7904: }
7905: }
7906: $datatable .= '</td></tr>';
7907: $$rowtotal ++;
7908: return $datatable;
7909: }
7910:
7911: sub legacy_scantronformat {
7912: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
7913: my ($url,$error);
7914: my @statinfo = &Apache::lonnet::stat_file($newurl);
7915: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
7916: (my $result,$url) =
7917: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
7918: '','',$newfile);
7919: if ($result ne 'ok') {
1.130 raeburn 7920: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 7921: }
7922: }
7923: return ($url,$error);
7924: }
1.43 raeburn 7925:
1.49 raeburn 7926: sub print_coursecategories {
1.57 raeburn 7927: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
7928: my $datatable;
7929: if ($position eq 'top') {
1.238 raeburn 7930: my (%checked);
7931: my @catitems = ('unauth','auth');
7932: my @cattypes = ('std','domonly','codesrch','none');
7933: $checked{'unauth'} = 'std';
7934: $checked{'auth'} = 'std';
7935: if (ref($settings) eq 'HASH') {
7936: foreach my $type (@cattypes) {
7937: if ($type eq $settings->{'unauth'}) {
7938: $checked{'unauth'} = $type;
7939: }
7940: if ($type eq $settings->{'auth'}) {
7941: $checked{'auth'} = $type;
7942: }
7943: }
7944: }
7945: my %lt = &Apache::lonlocal::texthash (
7946: unauth => 'Catalog type for unauthenticated users',
7947: auth => 'Catalog type for authenticated users',
7948: none => 'No catalog',
7949: std => 'Standard catalog',
7950: domonly => 'Domain-only catalog',
7951: codesrch => "Code search form",
7952: );
7953: my $itemcount = 0;
7954: foreach my $item (@catitems) {
7955: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
7956: $datatable .= '<tr '.$css_class.'>'.
7957: '<td>'.$lt{$item}.'</td>'.
7958: '<td class="LC_right_item"><span class="LC_nobreak">';
7959: foreach my $type (@cattypes) {
7960: my $ischecked;
7961: if ($checked{$item} eq $type) {
7962: $ischecked=' checked="checked"';
7963: }
7964: $datatable .= '<label>'.
7965: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
7966: ' />'.$lt{$type}.'</label> ';
7967: }
1.327 raeburn 7968: $datatable .= '</span></td></tr>';
1.238 raeburn 7969: $itemcount ++;
7970: }
7971: $$rowtotal += $itemcount;
7972: } elsif ($position eq 'middle') {
1.57 raeburn 7973: my $toggle_cats_crs = ' ';
7974: my $toggle_cats_dom = ' checked="checked" ';
7975: my $can_cat_crs = ' ';
7976: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 7977: my $toggle_catscomm_comm = ' ';
7978: my $toggle_catscomm_dom = ' checked="checked" ';
7979: my $can_catcomm_comm = ' ';
7980: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 7981: my $toggle_catsplace_place = ' ';
7982: my $toggle_catsplace_dom = ' checked="checked" ';
7983: my $can_catplace_place = ' ';
7984: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 7985:
1.57 raeburn 7986: if (ref($settings) eq 'HASH') {
7987: if ($settings->{'togglecats'} eq 'crs') {
7988: $toggle_cats_crs = $toggle_cats_dom;
7989: $toggle_cats_dom = ' ';
7990: }
7991: if ($settings->{'categorize'} eq 'crs') {
7992: $can_cat_crs = $can_cat_dom;
7993: $can_cat_dom = ' ';
7994: }
1.120 raeburn 7995: if ($settings->{'togglecatscomm'} eq 'comm') {
7996: $toggle_catscomm_comm = $toggle_catscomm_dom;
7997: $toggle_catscomm_dom = ' ';
7998: }
7999: if ($settings->{'categorizecomm'} eq 'comm') {
8000: $can_catcomm_comm = $can_catcomm_dom;
8001: $can_catcomm_dom = ' ';
8002: }
1.272 raeburn 8003: if ($settings->{'togglecatsplace'} eq 'place') {
8004: $toggle_catsplace_place = $toggle_catsplace_dom;
8005: $toggle_catsplace_dom = ' ';
8006: }
8007: if ($settings->{'categorizeplace'} eq 'place') {
8008: $can_catplace_place = $can_catplace_dom;
8009: $can_catplace_dom = ' ';
8010: }
1.57 raeburn 8011: }
8012: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 8013: togglecats => 'Show/Hide a course in catalog',
8014: togglecatscomm => 'Show/Hide a community in catalog',
8015: togglecatsplace => 'Show/Hide a placement test in catalog',
8016: categorize => 'Assign a category to a course',
8017: categorizecomm => 'Assign a category to a community',
8018: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 8019: );
8020: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 8021: dom => 'Set in Domain',
8022: crs => 'Set in Course',
8023: comm => 'Set in Community',
8024: place => 'Set in Placement Test',
1.57 raeburn 8025: );
8026: $datatable = '<tr class="LC_odd_row">'.
8027: '<td>'.$title{'togglecats'}.'</td>'.
8028: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8029: '<input type="radio" name="togglecats"'.
8030: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8031: '<label><input type="radio" name="togglecats"'.
8032: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
8033: '</tr><tr>'.
8034: '<td>'.$title{'categorize'}.'</td>'.
8035: '<td class="LC_right_item"><span class="LC_nobreak">'.
8036: '<label><input type="radio" name="categorize"'.
8037: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8038: '<label><input type="radio" name="categorize"'.
8039: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 8040: '</tr><tr class="LC_odd_row">'.
8041: '<td>'.$title{'togglecatscomm'}.'</td>'.
8042: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8043: '<input type="radio" name="togglecatscomm"'.
8044: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8045: '<label><input type="radio" name="togglecatscomm"'.
8046: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
8047: '</tr><tr>'.
8048: '<td>'.$title{'categorizecomm'}.'</td>'.
8049: '<td class="LC_right_item"><span class="LC_nobreak">'.
8050: '<label><input type="radio" name="categorizecomm"'.
8051: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8052: '<label><input type="radio" name="categorizecomm"'.
8053: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 8054: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 8055: '<td>'.$title{'togglecatsplace'}.'</td>'.
8056: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8057: '<input type="radio" name="togglecatsplace"'.
8058: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8059: '<label><input type="radio" name="togglecatscomm"'.
8060: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
8061: '</tr><tr>'.
8062: '<td>'.$title{'categorizeplace'}.'</td>'.
8063: '<td class="LC_right_item"><span class="LC_nobreak">'.
8064: '<label><input type="radio" name="categorizeplace"'.
8065: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8066: '<label><input type="radio" name="categorizeplace"'.
8067: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 8068: '</tr>';
1.272 raeburn 8069: $$rowtotal += 6;
1.57 raeburn 8070: } else {
8071: my $css_class;
8072: my $itemcount = 1;
8073: my $cathash;
8074: if (ref($settings) eq 'HASH') {
8075: $cathash = $settings->{'cats'};
8076: }
8077: if (ref($cathash) eq 'HASH') {
8078: my (@cats,@trails,%allitems,%idx,@jsarray);
8079: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
8080: \%allitems,\%idx,\@jsarray);
8081: my $maxdepth = scalar(@cats);
8082: my $colattrib = '';
8083: if ($maxdepth > 2) {
8084: $colattrib = ' colspan="2" ';
8085: }
8086: my @path;
8087: if (@cats > 0) {
8088: if (ref($cats[0]) eq 'ARRAY') {
8089: my $numtop = @{$cats[0]};
8090: my $maxnum = $numtop;
1.120 raeburn 8091: my %default_names = (
8092: instcode => &mt('Official courses'),
8093: communities => &mt('Communities'),
1.272 raeburn 8094: placement => &mt('Placement Tests'),
1.120 raeburn 8095: );
8096:
8097: if ((!grep(/^instcode$/,@{$cats[0]})) ||
8098: ($cathash->{'instcode::0'} eq '') ||
8099: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 8100: ($cathash->{'communities::0'} eq '') ||
8101: (!grep(/^placement$/,@{$cats[0]})) ||
8102: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 8103: $maxnum ++;
8104: }
8105: my $lastidx;
8106: for (my $i=0; $i<$numtop; $i++) {
8107: my $parent = $cats[0][$i];
8108: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8109: my $item = &escape($parent).'::0';
8110: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
8111: $lastidx = $idx{$item};
8112: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
8113: .'<select name="'.$item.'"'.$chgstr.'>';
8114: for (my $k=0; $k<=$maxnum; $k++) {
8115: my $vpos = $k+1;
8116: my $selstr;
8117: if ($k == $i) {
8118: $selstr = ' selected="selected" ';
8119: }
8120: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8121: }
1.214 raeburn 8122: $datatable .= '</select></span></td><td>';
1.272 raeburn 8123: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 8124: $datatable .= '<span class="LC_nobreak">'
8125: .$default_names{$parent}.'</span>';
8126: if ($parent eq 'instcode') {
8127: $datatable .= '<br /><span class="LC_nobreak">('
8128: .&mt('with institutional codes')
8129: .')</span></td><td'.$colattrib.'>';
8130: } else {
8131: $datatable .= '<table><tr><td>';
8132: }
8133: $datatable .= '<span class="LC_nobreak">'
8134: .'<label><input type="radio" name="'
8135: .$parent.'" value="1" checked="checked" />'
8136: .&mt('Display').'</label>';
8137: if ($parent eq 'instcode') {
8138: $datatable .= ' ';
8139: } else {
8140: $datatable .= '</span></td></tr><tr><td>'
8141: .'<span class="LC_nobreak">';
8142: }
8143: $datatable .= '<label><input type="radio" name="'
8144: .$parent.'" value="0" />'
8145: .&mt('Do not display').'</label></span>';
1.272 raeburn 8146: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 8147: $datatable .= '</td></tr></table>';
8148: }
8149: $datatable .= '</td>';
1.57 raeburn 8150: } else {
8151: $datatable .= $parent
1.214 raeburn 8152: .' <span class="LC_nobreak"><label>'
8153: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 8154: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
8155: }
8156: my $depth = 1;
8157: push(@path,$parent);
8158: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
8159: pop(@path);
8160: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
8161: $itemcount ++;
8162: }
1.48 raeburn 8163: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 8164: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
8165: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 8166: for (my $k=0; $k<=$maxnum; $k++) {
8167: my $vpos = $k+1;
8168: my $selstr;
1.57 raeburn 8169: if ($k == $numtop) {
1.48 raeburn 8170: $selstr = ' selected="selected" ';
8171: }
8172: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8173: }
1.59 bisitz 8174: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 8175: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
8176: .'</tr>'."\n";
1.48 raeburn 8177: $itemcount ++;
1.272 raeburn 8178: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 8179: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
8180: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8181: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
8182: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
8183: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
8184: for (my $k=0; $k<=$maxnum; $k++) {
8185: my $vpos = $k+1;
8186: my $selstr;
8187: if ($k == $maxnum) {
8188: $selstr = ' selected="selected" ';
8189: }
8190: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 8191: }
1.120 raeburn 8192: $datatable .= '</select></span></td>'.
8193: '<td><span class="LC_nobreak">'.
8194: $default_names{$default}.'</span>';
8195: if ($default eq 'instcode') {
8196: $datatable .= '<br /><span class="LC_nobreak">('
8197: .&mt('with institutional codes').')</span>';
8198: }
8199: $datatable .= '</td>'
8200: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
8201: .&mt('Display').'</label> '
8202: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
8203: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 8204: }
8205: }
8206: }
1.57 raeburn 8207: } else {
8208: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 8209: }
8210: } else {
1.327 raeburn 8211: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 8212: .&initialize_categories($itemcount);
1.48 raeburn 8213: }
1.57 raeburn 8214: $$rowtotal += $itemcount;
1.48 raeburn 8215: }
8216: return $datatable;
8217: }
8218:
1.69 raeburn 8219: sub print_serverstatuses {
8220: my ($dom,$settings,$rowtotal) = @_;
8221: my $datatable;
8222: my @pages = &serverstatus_pages();
8223: my (%namedaccess,%machineaccess);
8224: foreach my $type (@pages) {
8225: $namedaccess{$type} = '';
8226: $machineaccess{$type}= '';
8227: }
8228: if (ref($settings) eq 'HASH') {
8229: foreach my $type (@pages) {
8230: if (exists($settings->{$type})) {
8231: if (ref($settings->{$type}) eq 'HASH') {
8232: foreach my $key (keys(%{$settings->{$type}})) {
8233: if ($key eq 'namedusers') {
8234: $namedaccess{$type} = $settings->{$type}->{$key};
8235: } elsif ($key eq 'machines') {
8236: $machineaccess{$type} = $settings->{$type}->{$key};
8237: }
8238: }
8239: }
8240: }
8241: }
8242: }
1.81 raeburn 8243: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 8244: my $rownum = 0;
8245: my $css_class;
8246: foreach my $type (@pages) {
8247: $rownum ++;
8248: $css_class = $rownum%2?' class="LC_odd_row"':'';
8249: $datatable .= '<tr'.$css_class.'>'.
8250: '<td><span class="LC_nobreak">'.
8251: $titles->{$type}.'</span></td>'.
8252: '<td class="LC_left_item">'.
8253: '<input type="text" name="'.$type.'_namedusers" '.
8254: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
8255: '<td class="LC_right_item">'.
8256: '<span class="LC_nobreak">'.
8257: '<input type="text" name="'.$type.'_machines" '.
8258: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 8259: '</span></td></tr>'."\n";
1.69 raeburn 8260: }
8261: $$rowtotal += $rownum;
8262: return $datatable;
8263: }
8264:
8265: sub serverstatus_pages {
8266: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 8267: 'checksums','clusterstatus','certstatus','metadata_keywords',
8268: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
8269: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 8270: }
8271:
1.236 raeburn 8272: sub defaults_javascript {
8273: my ($settings) = @_;
1.294 raeburn 8274: 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.');
8275: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
8276: &js_escape(\$intauthcheck);
8277: &js_escape(\$intauthcost);
8278: my $intauthjs = <<"ENDSCRIPT";
8279:
8280: function warnIntAuth(field) {
8281: if (field.name == 'intauth_check') {
8282: if (field.value == '2') {
8283: alert('$intauthcheck');
8284: }
8285: }
8286: if (field.name == 'intauth_cost') {
8287: field.value.replace(/\s/g,'');
8288: if (field.value != '') {
8289: var regexdigit=/^\\d+\$/;
8290: if (!regexdigit.test(field.value)) {
8291: alert('$intauthcost');
8292: }
8293: }
8294: }
8295: return;
8296: }
8297:
8298: ENDSCRIPT
8299:
8300: if (ref($settings) ne 'HASH') {
8301: return &Apache::lonhtmlcommon::scripttag($intauthjs);
8302: }
1.236 raeburn 8303: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
8304: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
8305: if ($maxnum eq '') {
8306: $maxnum = 0;
8307: }
8308: $maxnum ++;
1.249 raeburn 8309: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 8310: return <<"ENDSCRIPT";
8311: <script type="text/javascript">
8312: // <![CDATA[
8313: function reorderTypes(form,caller) {
8314: var changedVal;
8315: $jstext
8316: var newpos = 'addinststatus_pos';
8317: var current = new Array;
8318: var maxh = $maxnum;
8319: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8320: var oldVal;
8321: if (caller == newpos) {
8322: changedVal = newitemVal;
8323: } else {
8324: var curritem = 'inststatus_pos_'+caller;
8325: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
8326: current[newitemVal] = newpos;
8327: }
8328: for (var i=0; i<inststatuses.length; i++) {
8329: if (inststatuses[i] != caller) {
8330: var elementName = 'inststatus_pos_'+inststatuses[i];
8331: if (form.elements[elementName]) {
8332: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8333: current[currVal] = elementName;
8334: }
8335: }
8336: }
8337: for (var j=0; j<maxh; j++) {
8338: if (current[j] == undefined) {
8339: oldVal = j;
8340: }
8341: }
8342: if (oldVal < changedVal) {
8343: for (var k=oldVal+1; k<=changedVal ; k++) {
8344: var elementName = current[k];
8345: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8346: }
8347: } else {
8348: for (var k=changedVal; k<oldVal; k++) {
8349: var elementName = current[k];
8350: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8351: }
8352: }
8353: return;
8354: }
8355:
1.294 raeburn 8356: $intauthjs
8357:
1.236 raeburn 8358: // ]]>
8359: </script>
8360:
8361: ENDSCRIPT
1.294 raeburn 8362: } else {
8363: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 8364: }
8365: }
8366:
1.49 raeburn 8367: sub coursecategories_javascript {
8368: my ($settings) = @_;
1.57 raeburn 8369: my ($output,$jstext,$cathash);
1.49 raeburn 8370: if (ref($settings) eq 'HASH') {
1.57 raeburn 8371: $cathash = $settings->{'cats'};
8372: }
8373: if (ref($cathash) eq 'HASH') {
1.49 raeburn 8374: my (@cats,@jsarray,%idx);
1.57 raeburn 8375: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 8376: if (@jsarray > 0) {
8377: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
8378: for (my $i=0; $i<@jsarray; $i++) {
8379: if (ref($jsarray[$i]) eq 'ARRAY') {
8380: my $catstr = join('","',@{$jsarray[$i]});
8381: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
8382: }
8383: }
8384: }
8385: } else {
8386: $jstext = ' var categories = Array(1);'."\n".
8387: ' categories[0] = Array("instcode_pos");'."\n";
8388: }
1.237 bisitz 8389: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
8390: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 8391: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 8392: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
8393: &js_escape(\$instcode_reserved);
8394: &js_escape(\$communities_reserved);
1.272 raeburn 8395: &js_escape(\$placement_reserved);
1.265 damieng 8396: &js_escape(\$choose_again);
1.49 raeburn 8397: $output = <<"ENDSCRIPT";
8398: <script type="text/javascript">
1.109 raeburn 8399: // <![CDATA[
1.49 raeburn 8400: function reorderCats(form,parent,item,idx) {
8401: var changedVal;
8402: $jstext
8403: var newpos = 'addcategory_pos';
8404: if (parent == '') {
8405: var has_instcode = 0;
8406: var maxtop = categories[idx].length;
8407: for (var j=0; j<maxtop; j++) {
8408: if (categories[idx][j] == 'instcode::0') {
8409: has_instcode == 1;
8410: }
8411: }
8412: if (has_instcode == 0) {
8413: categories[idx][maxtop] = 'instcode_pos';
8414: }
8415: } else {
8416: newpos += '_'+parent;
8417: }
8418: var maxh = 1 + categories[idx].length;
8419: var current = new Array;
8420: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8421: if (item == newpos) {
8422: changedVal = newitemVal;
8423: } else {
8424: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
8425: current[newitemVal] = newpos;
8426: }
8427: for (var i=0; i<categories[idx].length; i++) {
8428: var elementName = categories[idx][i];
8429: if (elementName != item) {
8430: if (form.elements[elementName]) {
8431: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8432: current[currVal] = elementName;
8433: }
8434: }
8435: }
8436: var oldVal;
8437: for (var j=0; j<maxh; j++) {
8438: if (current[j] == undefined) {
8439: oldVal = j;
8440: }
8441: }
8442: if (oldVal < changedVal) {
8443: for (var k=oldVal+1; k<=changedVal ; k++) {
8444: var elementName = current[k];
8445: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8446: }
8447: } else {
8448: for (var k=changedVal; k<oldVal; k++) {
8449: var elementName = current[k];
8450: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8451: }
8452: }
8453: return;
8454: }
1.120 raeburn 8455:
8456: function categoryCheck(form) {
8457: if (form.elements['addcategory_name'].value == 'instcode') {
8458: alert('$instcode_reserved\\n$choose_again');
8459: return false;
8460: }
8461: if (form.elements['addcategory_name'].value == 'communities') {
8462: alert('$communities_reserved\\n$choose_again');
8463: return false;
8464: }
1.272 raeburn 8465: if (form.elements['addcategory_name'].value == 'placement') {
8466: alert('$placement_reserved\\n$choose_again');
8467: return false;
8468: }
1.120 raeburn 8469: return true;
8470: }
8471:
1.109 raeburn 8472: // ]]>
1.49 raeburn 8473: </script>
8474:
8475: ENDSCRIPT
8476: return $output;
8477: }
8478:
1.48 raeburn 8479: sub initialize_categories {
8480: my ($itemcount) = @_;
1.120 raeburn 8481: my ($datatable,$css_class,$chgstr);
8482: my %default_names = (
8483: instcode => 'Official courses (with institutional codes)',
8484: communities => 'Communities',
1.272 raeburn 8485: placement => 'Placement Tests',
1.120 raeburn 8486: );
1.328 raeburn 8487: my %selnum = (
8488: instcode => '0',
8489: communities => '1',
8490: placement => '2',
8491: );
8492: my %selected;
1.272 raeburn 8493: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 8494: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 8495: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 8496: map { $selected{$selnum{$_}} = '' } keys(%selnum);
8497: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 8498: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 8499: .'<select name="'.$default.'_pos"'.$chgstr.'>'
8500: .'<option value="0"'.$selected{'0'}.'>1</option>'
8501: .'<option value="1"'.$selected{'1'}.'>2</option>'
8502: .'<option value="2"'.$selected{'2'}.'>3</option>'
8503: .'<option value="3">4</option></select> '
1.120 raeburn 8504: .$default_names{$default}
8505: .'</span></td><td><span class="LC_nobreak">'
8506: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
8507: .&mt('Display').'</label> <label>'
8508: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 8509: .'</label></span></td></tr>';
1.120 raeburn 8510: $itemcount ++;
8511: }
1.48 raeburn 8512: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 8513: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 8514: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 8515: .'<select name="addcategory_pos"'.$chgstr.'>'
8516: .'<option value="0">1</option>'
8517: .'<option value="1">2</option>'
1.328 raeburn 8518: .'<option value="2">3</option>'
8519: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 8520: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
8521: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
8522: .'</td></tr>';
1.48 raeburn 8523: return $datatable;
8524: }
8525:
8526: sub build_category_rows {
1.49 raeburn 8527: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
8528: my ($text,$name,$item,$chgstr);
1.48 raeburn 8529: if (ref($cats) eq 'ARRAY') {
8530: my $maxdepth = scalar(@{$cats});
8531: if (ref($cats->[$depth]) eq 'HASH') {
8532: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
8533: my $numchildren = @{$cats->[$depth]{$parent}};
8534: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 8535: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 8536: my ($idxnum,$parent_name,$parent_item);
8537: my $higher = $depth - 1;
8538: if ($higher == 0) {
8539: $parent_name = &escape($parent).'::'.$higher;
8540: } else {
8541: if (ref($path) eq 'ARRAY') {
8542: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8543: }
8544: }
8545: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 8546: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 8547: if ($j < $numchildren) {
1.48 raeburn 8548: $name = $cats->[$depth]{$parent}[$j];
8549: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 8550: $idxnum = $idx->{$item};
8551: } else {
8552: $name = $parent_name;
8553: $item = $parent_item;
1.48 raeburn 8554: }
1.49 raeburn 8555: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
8556: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 8557: for (my $i=0; $i<=$numchildren; $i++) {
8558: my $vpos = $i+1;
8559: my $selstr;
8560: if ($j == $i) {
8561: $selstr = ' selected="selected" ';
8562: }
8563: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
8564: }
8565: $text .= '</select> ';
8566: if ($j < $numchildren) {
8567: my $deeper = $depth+1;
8568: $text .= $name.' '
8569: .'<label><input type="checkbox" name="deletecategory" value="'
8570: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
8571: if(ref($path) eq 'ARRAY') {
8572: push(@{$path},$name);
1.49 raeburn 8573: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 8574: pop(@{$path});
8575: }
8576: } else {
1.330 raeburn 8577: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 8578: if ($j == $numchildren) {
8579: $text .= $name;
8580: } else {
8581: $text .= $item;
8582: }
8583: $text .= '" value="" />';
8584: }
8585: $text .= '</td></tr>';
8586: }
8587: $text .= '</table></td>';
8588: } else {
8589: my $higher = $depth-1;
8590: if ($higher == 0) {
8591: $name = &escape($parent).'::'.$higher;
8592: } else {
8593: if (ref($path) eq 'ARRAY') {
8594: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8595: }
8596: }
8597: my $colspan;
8598: if ($parent ne 'instcode') {
8599: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 8600: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 8601: }
8602: }
8603: }
8604: }
8605: return $text;
8606: }
8607:
1.33 raeburn 8608: sub modifiable_userdata_row {
1.305 raeburn 8609: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
8610: $rowid,$customcss,$rowstyle) = @_;
1.228 raeburn 8611: my ($role,$rolename,$statustype);
8612: $role = $item;
1.224 raeburn 8613: if ($context eq 'cancreate') {
1.305 raeburn 8614: if ($item =~ /^(emailusername)_(.+)$/) {
8615: $role = $1;
8616: $statustype = $2;
1.228 raeburn 8617: if (ref($usertypes) eq 'HASH') {
8618: if ($usertypes->{$statustype}) {
8619: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
8620: } else {
8621: $rolename = &mt('Data provided by user');
8622: }
8623: }
1.224 raeburn 8624: }
8625: } elsif ($context eq 'selfcreate') {
1.63 raeburn 8626: if (ref($usertypes) eq 'HASH') {
8627: $rolename = $usertypes->{$role};
8628: } else {
8629: $rolename = $role;
8630: }
1.325 raeburn 8631: } elsif ($context eq 'lti') {
8632: $rolename = &mt('Institutional data used (if available)');
1.33 raeburn 8633: } else {
1.63 raeburn 8634: if ($role eq 'cr') {
8635: $rolename = &mt('Custom role');
8636: } else {
8637: $rolename = &Apache::lonnet::plaintext($role);
8638: }
1.33 raeburn 8639: }
1.224 raeburn 8640: my (@fields,%fieldtitles);
8641: if (ref($fieldsref) eq 'ARRAY') {
8642: @fields = @{$fieldsref};
8643: } else {
8644: @fields = ('lastname','firstname','middlename','generation',
8645: 'permanentemail','id');
8646: }
8647: if ((ref($titlesref) eq 'HASH')) {
8648: %fieldtitles = %{$titlesref};
8649: } else {
8650: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8651: }
1.33 raeburn 8652: my $output;
1.305 raeburn 8653: my $css_class;
8654: if ($rowcount%2) {
8655: $css_class = 'LC_odd_row';
8656: }
8657: if ($customcss) {
8658: $css_class .= " $customcss";
8659: }
8660: $css_class =~ s/^\s+//;
8661: if ($css_class) {
8662: $css_class = ' class="'.$css_class.'"';
8663: }
8664: if ($rowstyle) {
8665: $css_class .= ' style="'.$rowstyle.'"';
8666: }
8667: if ($rowid) {
8668: $rowid = ' id="'.$rowid.'"';
8669: }
8670: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 8671: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
8672: '<td class="LC_left_item" colspan="2"><table>';
8673: my $rem;
8674: my %checks;
1.325 raeburn 8675: my %current;
1.33 raeburn 8676: if (ref($settings) eq 'HASH') {
1.325 raeburn 8677: my $hashref;
8678: if ($context eq 'lti') {
8679: if (ref($settings) eq 'HASH') {
8680: $hashref = $settings->{'instdata'};
8681: }
8682: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 8683: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 8684: $hashref = $settings->{'lti_instdata'};
8685: }
8686: if ($role eq 'emailusername') {
8687: if ($statustype) {
8688: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
8689: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 8690: }
1.325 raeburn 8691: }
8692: }
8693: }
8694: if (ref($hashref) eq 'HASH') {
8695: foreach my $field (@fields) {
8696: if ($hashref->{$field}) {
8697: if ($role eq 'emailusername') {
8698: $checks{$field} = $hashref->{$field};
8699: } else {
8700: $checks{$field} = ' checked="checked" ';
1.33 raeburn 8701: }
8702: }
8703: }
8704: }
8705: }
1.305 raeburn 8706:
8707: my $total = scalar(@fields);
8708: for (my $i=0; $i<$total; $i++) {
8709: $rem = $i%($numinrow);
1.33 raeburn 8710: if ($rem == 0) {
8711: if ($i > 0) {
8712: $output .= '</tr>';
8713: }
8714: $output .= '<tr>';
8715: }
8716: my $check = ' ';
1.228 raeburn 8717: unless ($role eq 'emailusername') {
8718: if (exists($checks{$fields[$i]})) {
8719: $check = $checks{$fields[$i]}
1.325 raeburn 8720: } elsif ($context ne 'lti') {
1.228 raeburn 8721: if ($role eq 'st') {
8722: if (ref($settings) ne 'HASH') {
8723: $check = ' checked="checked" ';
8724: }
1.33 raeburn 8725: }
8726: }
8727: }
8728: $output .= '<td class="LC_left_item">'.
1.228 raeburn 8729: '<span class="LC_nobreak">';
1.325 raeburn 8730: my $prefix = 'canmodify';
1.228 raeburn 8731: if ($role eq 'emailusername') {
8732: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
8733: $checks{$fields[$i]} = 'omit';
8734: }
8735: foreach my $option ('required','optional','omit') {
8736: my $checked='';
8737: if ($checks{$fields[$i]} eq $option) {
8738: $checked='checked="checked" ';
8739: }
8740: $output .= '<label>'.
1.325 raeburn 8741: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 8742: &mt($option).'</label>'.(' ' x2);
8743: }
8744: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
8745: } else {
1.325 raeburn 8746: if ($context eq 'lti') {
8747: $prefix = 'lti';
8748: }
1.228 raeburn 8749: $output .= '<label>'.
1.325 raeburn 8750: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 8751: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
8752: '</label>';
8753: }
8754: $output .= '</span></td>';
1.33 raeburn 8755: }
1.305 raeburn 8756: $rem = $total%$numinrow;
8757: my $colsleft;
8758: if ($rem) {
8759: $colsleft = $numinrow - $rem;
8760: }
8761: if ($colsleft > 1) {
1.33 raeburn 8762: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8763: ' </td>';
8764: } elsif ($colsleft == 1) {
8765: $output .= '<td class="LC_left_item"> </td>';
8766: }
8767: $output .= '</tr></table></td></tr>';
8768: return $output;
8769: }
1.28 raeburn 8770:
1.93 raeburn 8771: sub insttypes_row {
1.305 raeburn 8772: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
8773: $customcss,$rowstyle) = @_;
1.93 raeburn 8774: my %lt = &Apache::lonlocal::texthash (
8775: cansearch => 'Users allowed to search',
8776: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 8777: lockablenames => 'User preference to lock name',
1.305 raeburn 8778: selfassign => 'Self-reportable affiliations',
1.315 raeburn 8779: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 8780: );
8781: my $showdom;
8782: if ($context eq 'cansearch') {
8783: $showdom = ' ('.$dom.')';
8784: }
1.165 raeburn 8785: my $class = 'LC_left_item';
8786: if ($context eq 'statustocreate') {
8787: $class = 'LC_right_item';
8788: }
1.305 raeburn 8789: my $css_class;
8790: if ($$rowtotal%2) {
8791: $css_class = 'LC_odd_row';
8792: }
8793: if ($customcss) {
8794: $css_class .= ' '.$customcss;
8795: }
8796: $css_class =~ s/^\s+//;
8797: if ($css_class) {
8798: $css_class = ' class="'.$css_class.'"';
8799: }
8800: if ($rowstyle) {
8801: $css_class .= ' style="'.$rowstyle.'"';
8802: }
8803: if ($onclick) {
8804: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 8805: }
8806: my $output = '<tr'.$css_class.'>'.
8807: '<td>'.$lt{$context}.$showdom.
8808: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 8809: my $rem;
8810: if (ref($types) eq 'ARRAY') {
8811: for (my $i=0; $i<@{$types}; $i++) {
8812: if (defined($usertypes->{$types->[$i]})) {
8813: my $rem = $i%($numinrow);
8814: if ($rem == 0) {
8815: if ($i > 0) {
8816: $output .= '</tr>';
8817: }
8818: $output .= '<tr>';
1.23 raeburn 8819: }
1.26 raeburn 8820: my $check = ' ';
1.99 raeburn 8821: if (ref($settings) eq 'HASH') {
8822: if (ref($settings->{$context}) eq 'ARRAY') {
8823: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
8824: $check = ' checked="checked" ';
8825: }
1.315 raeburn 8826: } elsif (ref($settings->{$context}) eq 'HASH') {
8827: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
8828: $check = ' checked="checked" ';
8829: }
1.99 raeburn 8830: } elsif ($context eq 'statustocreate') {
1.26 raeburn 8831: $check = ' checked="checked" ';
8832: }
1.23 raeburn 8833: }
1.26 raeburn 8834: $output .= '<td class="LC_left_item">'.
8835: '<span class="LC_nobreak"><label>'.
1.93 raeburn 8836: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 8837: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 8838: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 8839: }
8840: }
1.26 raeburn 8841: $rem = @{$types}%($numinrow);
1.23 raeburn 8842: }
8843: my $colsleft = $numinrow - $rem;
1.315 raeburn 8844: if ($context eq 'overrides') {
8845: if ($colsleft > 1) {
8846: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8847: } else {
8848: $output .= '<td class="LC_left_item">';
8849: }
8850: $output .= ' ';
1.23 raeburn 8851: } else {
1.334 raeburn 8852: if ($rem == 0) {
1.315 raeburn 8853: $output .= '<tr>';
8854: }
8855: if ($colsleft > 1) {
8856: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8857: } else {
8858: $output .= '<td class="LC_left_item">';
8859: }
8860: my $defcheck = ' ';
8861: if (ref($settings) eq 'HASH') {
8862: if (ref($settings->{$context}) eq 'ARRAY') {
8863: if (grep(/^default$/,@{$settings->{$context}})) {
8864: $defcheck = ' checked="checked" ';
8865: }
8866: } elsif ($context eq 'statustocreate') {
1.99 raeburn 8867: $defcheck = ' checked="checked" ';
8868: }
1.26 raeburn 8869: }
1.315 raeburn 8870: $output .= '<span class="LC_nobreak"><label>'.
8871: '<input type="checkbox" name="'.$context.'" '.
8872: 'value="default"'.$defcheck.$onclick.' />'.
8873: $othertitle.'</label></span>';
1.23 raeburn 8874: }
1.315 raeburn 8875: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 8876: return $output;
1.23 raeburn 8877: }
8878:
8879: sub sorted_searchtitles {
8880: my %searchtitles = &Apache::lonlocal::texthash(
8881: 'uname' => 'username',
8882: 'lastname' => 'last name',
8883: 'lastfirst' => 'last name, first name',
8884: );
8885: my @titleorder = ('uname','lastname','lastfirst');
8886: return (\%searchtitles,\@titleorder);
8887: }
8888:
1.25 raeburn 8889: sub sorted_searchtypes {
8890: my %srchtypes_desc = (
8891: exact => 'is exact match',
8892: contains => 'contains ..',
8893: begins => 'begins with ..',
8894: );
8895: my @srchtypeorder = ('exact','begins','contains');
8896: return (\%srchtypes_desc,\@srchtypeorder);
8897: }
8898:
1.3 raeburn 8899: sub usertype_update_row {
8900: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
8901: my $datatable;
8902: my $numinrow = 4;
8903: foreach my $type (@{$types}) {
8904: if (defined($usertypes->{$type})) {
8905: $$rownums ++;
8906: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
8907: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
8908: '</td><td class="LC_left_item"><table>';
8909: for (my $i=0; $i<@{$fields}; $i++) {
8910: my $rem = $i%($numinrow);
8911: if ($rem == 0) {
8912: if ($i > 0) {
8913: $datatable .= '</tr>';
8914: }
8915: $datatable .= '<tr>';
8916: }
8917: my $check = ' ';
1.39 raeburn 8918: if (ref($settings) eq 'HASH') {
8919: if (ref($settings->{'fields'}) eq 'HASH') {
8920: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
8921: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
8922: $check = ' checked="checked" ';
8923: }
1.3 raeburn 8924: }
8925: }
8926: }
8927:
8928: if ($i == @{$fields}-1) {
8929: my $colsleft = $numinrow - $rem;
8930: if ($colsleft > 1) {
8931: $datatable .= '<td colspan="'.$colsleft.'">';
8932: } else {
8933: $datatable .= '<td>';
8934: }
8935: } else {
8936: $datatable .= '<td>';
8937: }
1.8 raeburn 8938: $datatable .= '<span class="LC_nobreak"><label>'.
8939: '<input type="checkbox" name="updateable_'.$type.
8940: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
8941: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 8942: }
8943: $datatable .= '</tr></table></td></tr>';
8944: }
8945: }
8946: return $datatable;
1.1 raeburn 8947: }
8948:
8949: sub modify_login {
1.205 raeburn 8950: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 8951: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
8952: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
8953: %title = ( coursecatalog => 'Display course catalog',
8954: adminmail => 'Display administrator E-mail address',
1.188 raeburn 8955: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 8956: newuser => 'Link for visitors to create a user account',
8957: loginheader => 'Log-in box header');
8958: @offon = ('off','on');
1.112 raeburn 8959: if (ref($domconfig{login}) eq 'HASH') {
8960: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
8961: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
8962: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
8963: }
8964: }
8965: }
1.9 raeburn 8966: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
8967: \%domconfig,\%loginhash);
1.188 raeburn 8968: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 8969: foreach my $item (@toggles) {
8970: $loginhash{login}{$item} = $env{'form.'.$item};
8971: }
1.41 raeburn 8972: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 8973: if (ref($colchanges{'login'}) eq 'HASH') {
8974: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
8975: \%loginhash);
8976: }
1.110 raeburn 8977:
1.149 raeburn 8978: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 8979: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 8980: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 8981: if (keys(%servers) > 1) {
8982: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 8983: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
8984: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
8985: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
8986: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
8987: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
8988: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8989: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
8990: $changes{'loginvia'}{$lonhost} = 1;
8991: } else {
8992: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
8993: $changes{'loginvia'}{$lonhost} = 1;
8994: }
8995: } else {
8996: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8997: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
8998: $changes{'loginvia'}{$lonhost} = 1;
8999: }
9000: }
9001: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
9002: foreach my $item (@loginvia_attribs) {
9003: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
9004: }
9005: } else {
9006: foreach my $item (@loginvia_attribs) {
9007: my $new = $env{'form.'.$lonhost.'_'.$item};
9008: if (($item eq 'serverpath') && ($new eq 'custom')) {
9009: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
9010: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9011: $new = '/';
9012: }
9013: }
9014: if (($item eq 'custompath') &&
9015: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9016: $new = '';
9017: }
9018: if ($new ne $curr_loginvia{$lonhost}{$item}) {
9019: $changes{'loginvia'}{$lonhost} = 1;
9020: }
9021: if ($item eq 'exempt') {
1.256 raeburn 9022: $new = &check_exempt_addresses($new);
1.128 raeburn 9023: }
9024: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9025: }
9026: }
1.112 raeburn 9027: } else {
1.128 raeburn 9028: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9029: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 9030: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 9031: foreach my $item (@loginvia_attribs) {
9032: my $new = $env{'form.'.$lonhost.'_'.$item};
9033: if (($item eq 'serverpath') && ($new eq 'custom')) {
9034: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9035: $new = '/';
9036: }
9037: }
9038: if (($item eq 'custompath') &&
9039: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9040: $new = '';
9041: }
9042: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9043: }
1.110 raeburn 9044: }
9045: }
9046: }
9047: }
1.119 raeburn 9048:
1.168 raeburn 9049: my $servadm = $r->dir_config('lonAdmEMail');
9050: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
9051: if (ref($domconfig{'login'}) eq 'HASH') {
9052: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
9053: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
9054: if ($lang eq 'nolang') {
9055: push(@currlangs,$lang);
9056: } elsif (defined($langchoices{$lang})) {
9057: push(@currlangs,$lang);
9058: } else {
9059: next;
9060: }
9061: }
9062: }
9063: }
9064: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
9065: if (@currlangs > 0) {
9066: foreach my $lang (@currlangs) {
9067: if (grep(/^\Q$lang\E$/,@delurls)) {
9068: $changes{'helpurl'}{$lang} = 1;
9069: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
9070: $changes{'helpurl'}{$lang} = 1;
9071: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
9072: push(@newlangs,$lang);
9073: } else {
9074: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9075: }
9076: }
9077: }
9078: unless (grep(/^nolang$/,@currlangs)) {
9079: if ($env{'form.loginhelpurl_nolang.filename'}) {
9080: $changes{'helpurl'}{'nolang'} = 1;
9081: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
9082: push(@newlangs,'nolang');
9083: }
9084: }
9085: if ($env{'form.loginhelpurl_add_lang'}) {
9086: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
9087: ($env{'form.loginhelpurl_add_file.filename'})) {
9088: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
9089: $addedfile = $env{'form.loginhelpurl_add_lang'};
9090: }
9091: }
9092: if ((@newlangs > 0) || ($addedfile)) {
9093: my $error;
9094: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9095: if ($configuserok eq 'ok') {
9096: if ($switchserver) {
9097: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
9098: } elsif ($author_ok eq 'ok') {
9099: my @allnew = @newlangs;
9100: if ($addedfile ne '') {
9101: push(@allnew,$addedfile);
9102: }
9103: foreach my $lang (@allnew) {
9104: my $formelem = 'loginhelpurl_'.$lang;
9105: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
9106: $formelem = 'loginhelpurl_add_file';
9107: }
9108: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9109: "help/$lang",'','',$newfile{$lang});
9110: if ($result eq 'ok') {
9111: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
9112: $changes{'helpurl'}{$lang} = 1;
9113: } else {
9114: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
9115: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 9116: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 9117: (!grep(/^\Q$lang\E$/,@delurls))) {
9118: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9119: }
9120: }
9121: }
9122: } else {
9123: $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);
9124: }
9125: } else {
9126: $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);
9127: }
9128: if ($error) {
9129: &Apache::lonnet::logthis($error);
9130: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9131: }
9132: }
1.256 raeburn 9133:
9134: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
9135: if (ref($domconfig{'login'}) eq 'HASH') {
9136: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
9137: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
9138: if ($domservers{$lonhost}) {
9139: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9140: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 9141: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 9142: }
9143: }
9144: }
9145: }
9146: }
9147: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
9148: foreach my $lonhost (sort(keys(%domservers))) {
9149: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9150: $changes{'headtag'}{$lonhost} = 1;
9151: } else {
9152: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
9153: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
9154: }
9155: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
9156: push(@newhosts,$lonhost);
9157: } elsif ($currheadtagurls{$lonhost}) {
9158: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
9159: if ($currexempt{$lonhost}) {
1.289 raeburn 9160: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 9161: $changes{'headtag'}{$lonhost} = 1;
9162: }
9163: } elsif ($possexempt{$lonhost}) {
9164: $changes{'headtag'}{$lonhost} = 1;
9165: }
9166: if ($possexempt{$lonhost}) {
9167: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9168: }
9169: }
9170: }
9171: }
9172: if (@newhosts) {
9173: my $error;
9174: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9175: if ($configuserok eq 'ok') {
9176: if ($switchserver) {
9177: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
9178: } elsif ($author_ok eq 'ok') {
9179: foreach my $lonhost (@newhosts) {
9180: my $formelem = 'loginheadtag_'.$lonhost;
9181: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9182: "login/headtag/$lonhost",'','',
9183: $env{'form.loginheadtag_'.$lonhost.'.filename'});
9184: if ($result eq 'ok') {
9185: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
9186: $changes{'headtag'}{$lonhost} = 1;
9187: if ($possexempt{$lonhost}) {
9188: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9189: }
9190: } else {
9191: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
9192: $newheadtagurls{$lonhost},$result);
9193: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
9194: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
9195: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
9196: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
9197: }
9198: }
9199: }
9200: } else {
9201: $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);
9202: }
9203: } else {
9204: $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);
9205: }
9206: if ($error) {
9207: &Apache::lonnet::logthis($error);
9208: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9209: }
9210: }
1.169 raeburn 9211: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 9212:
9213: my $defaulthelpfile = '/adm/loginproblems.html';
9214: my $defaulttext = &mt('Default in use');
9215:
1.1 raeburn 9216: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
9217: $dom);
9218: if ($putresult eq 'ok') {
1.188 raeburn 9219: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 9220: my %defaultchecked = (
9221: 'coursecatalog' => 'on',
1.188 raeburn 9222: 'helpdesk' => 'on',
1.42 raeburn 9223: 'adminmail' => 'off',
1.43 raeburn 9224: 'newuser' => 'off',
1.42 raeburn 9225: );
1.55 raeburn 9226: if (ref($domconfig{'login'}) eq 'HASH') {
9227: foreach my $item (@toggles) {
9228: if ($defaultchecked{$item} eq 'on') {
9229: if (($domconfig{'login'}{$item} eq '0') &&
9230: ($env{'form.'.$item} eq '1')) {
9231: $changes{$item} = 1;
9232: } elsif (($domconfig{'login'}{$item} eq '' ||
9233: $domconfig{'login'}{$item} eq '1') &&
9234: ($env{'form.'.$item} eq '0')) {
9235: $changes{$item} = 1;
9236: }
9237: } elsif ($defaultchecked{$item} eq 'off') {
9238: if (($domconfig{'login'}{$item} eq '1') &&
9239: ($env{'form.'.$item} eq '0')) {
9240: $changes{$item} = 1;
9241: } elsif (($domconfig{'login'}{$item} eq '' ||
9242: $domconfig{'login'}{$item} eq '0') &&
9243: ($env{'form.'.$item} eq '1')) {
9244: $changes{$item} = 1;
9245: }
1.42 raeburn 9246: }
9247: }
1.41 raeburn 9248: }
1.6 raeburn 9249: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 9250: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9251: if (ref($lastactref) eq 'HASH') {
9252: $lastactref->{'domainconfig'} = 1;
9253: }
1.1 raeburn 9254: $resulttext = &mt('Changes made:').'<ul>';
9255: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 9256: if ($item eq 'loginvia') {
1.112 raeburn 9257: if (ref($changes{$item}) eq 'HASH') {
9258: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
9259: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 9260: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
9261: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
9262: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
9263: $protocol = 'http' if ($protocol ne 'https');
9264: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
9265:
9266: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
9267: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
9268: } else {
9269: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
9270: }
9271: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
9272: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
9273: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
9274: }
9275: $resulttext .= '</li>';
9276: } else {
9277: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
9278: }
1.112 raeburn 9279: } else {
1.128 raeburn 9280: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 9281: }
9282: }
1.128 raeburn 9283: $resulttext .= '</ul></li>';
1.112 raeburn 9284: }
1.168 raeburn 9285: } elsif ($item eq 'helpurl') {
9286: if (ref($changes{$item}) eq 'HASH') {
9287: foreach my $lang (sort(keys(%{$changes{$item}}))) {
9288: if (grep(/^\Q$lang\E$/,@delurls)) {
9289: my ($chg,$link);
9290: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
9291: if ($lang eq 'nolang') {
9292: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
9293: } else {
9294: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
9295: }
9296: $resulttext .= '<li>'.$chg.'</li>';
9297: } else {
9298: my $chg;
9299: if ($lang eq 'nolang') {
9300: $chg = &mt('custom log-in help file for no preferred language');
9301: } else {
9302: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
9303: }
9304: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
9305: $loginhash{'login'}{'helpurl'}{$lang}.
9306: '?inhibitmenu=yes',$chg,600,500).
9307: '</li>';
9308: }
9309: }
9310: }
1.256 raeburn 9311: } elsif ($item eq 'headtag') {
9312: if (ref($changes{$item}) eq 'HASH') {
9313: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
9314: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9315: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
9316: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9317: $resulttext .= '<li><a href="'.
9318: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
9319: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
9320: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
9321: if ($possexempt{$lonhost}) {
9322: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
9323: } else {
9324: $resulttext .= &mt('included for any client IP');
9325: }
9326: $resulttext .= '</li>';
9327: }
9328: }
9329: }
1.169 raeburn 9330: } elsif ($item eq 'captcha') {
9331: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 9332: my $chgtxt;
1.169 raeburn 9333: if ($loginhash{'login'}{$item} eq 'notused') {
9334: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
9335: } else {
9336: my %captchas = &captcha_phrases();
9337: if ($captchas{$loginhash{'login'}{$item}}) {
9338: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
9339: } else {
9340: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
9341: }
9342: }
9343: $resulttext .= '<li>'.$chgtxt.'</li>';
9344: }
9345: } elsif ($item eq 'recaptchakeys') {
9346: if (ref($loginhash{'login'}) eq 'HASH') {
9347: my ($privkey,$pubkey);
9348: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
9349: $pubkey = $loginhash{'login'}{$item}{'public'};
9350: $privkey = $loginhash{'login'}{$item}{'private'};
9351: }
9352: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
9353: if (!$pubkey) {
9354: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
9355: } else {
9356: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
9357: }
9358: if (!$privkey) {
9359: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
9360: } else {
1.251 raeburn 9361: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 9362: }
9363: $chgtxt .= '</ul>';
9364: $resulttext .= '<li>'.$chgtxt.'</li>';
9365: }
1.269 raeburn 9366: } elsif ($item eq 'recaptchaversion') {
9367: if (ref($loginhash{'login'}) eq 'HASH') {
9368: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 9369: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 9370: '</li>';
9371: }
9372: }
1.41 raeburn 9373: } else {
9374: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
9375: }
1.1 raeburn 9376: }
1.6 raeburn 9377: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 9378: } else {
9379: $resulttext = &mt('No changes made to log-in page settings');
9380: }
9381: } else {
1.11 albertel 9382: $resulttext = '<span class="LC_error">'.
9383: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9384: }
1.6 raeburn 9385: if ($errors) {
1.9 raeburn 9386: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 9387: $errors.'</ul>';
9388: }
9389: return $resulttext;
9390: }
9391:
1.256 raeburn 9392: sub check_exempt_addresses {
9393: my ($iplist) = @_;
9394: $iplist =~ s/^\s+//;
9395: $iplist =~ s/\s+$//;
9396: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
9397: my (@okips,$new);
9398: foreach my $ip (@poss_ips) {
9399: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
9400: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
9401: push(@okips,$ip);
9402: }
9403: }
9404: }
9405: if (@okips > 0) {
9406: $new = join(',',@okips);
9407: } else {
9408: $new = '';
9409: }
9410: return $new;
9411: }
9412:
1.6 raeburn 9413: sub color_font_choices {
9414: my %choices =
9415: &Apache::lonlocal::texthash (
9416: img => "Header",
9417: bgs => "Background colors",
9418: links => "Link colors",
1.55 raeburn 9419: images => "Images",
1.6 raeburn 9420: font => "Font color",
1.201 raeburn 9421: fontmenu => "Font menu",
1.76 raeburn 9422: pgbg => "Page",
1.6 raeburn 9423: tabbg => "Header",
9424: sidebg => "Border",
9425: link => "Link",
9426: alink => "Active link",
9427: vlink => "Visited link",
9428: );
9429: return %choices;
9430: }
9431:
9432: sub modify_rolecolors {
1.205 raeburn 9433: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 9434: my ($resulttext,%rolehash);
9435: $rolehash{'rolecolors'} = {};
1.55 raeburn 9436: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
9437: if ($domconfig{'rolecolors'} eq '') {
9438: $domconfig{'rolecolors'} = {};
9439: }
9440: }
1.9 raeburn 9441: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 9442: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
9443: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
9444: $dom);
9445: if ($putresult eq 'ok') {
9446: if (keys(%changes) > 0) {
1.41 raeburn 9447: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9448: if (ref($lastactref) eq 'HASH') {
9449: $lastactref->{'domainconfig'} = 1;
9450: }
1.6 raeburn 9451: $resulttext = &display_colorchgs($dom,\%changes,$roles,
9452: $rolehash{'rolecolors'});
9453: } else {
9454: $resulttext = &mt('No changes made to default color schemes');
9455: }
9456: } else {
1.11 albertel 9457: $resulttext = '<span class="LC_error">'.
9458: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 9459: }
9460: if ($errors) {
9461: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9462: $errors.'</ul>';
9463: }
9464: return $resulttext;
9465: }
9466:
9467: sub modify_colors {
1.9 raeburn 9468: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 9469: my (%changes,%choices);
1.51 raeburn 9470: my @bgs;
1.6 raeburn 9471: my @links = ('link','alink','vlink');
1.41 raeburn 9472: my @logintext;
1.6 raeburn 9473: my @images;
9474: my $servadm = $r->dir_config('lonAdmEMail');
9475: my $errors;
1.200 raeburn 9476: my %defaults;
1.6 raeburn 9477: foreach my $role (@{$roles}) {
9478: if ($role eq 'login') {
1.12 raeburn 9479: %choices = &login_choices();
1.41 raeburn 9480: @logintext = ('textcol','bgcol');
1.12 raeburn 9481: } else {
9482: %choices = &color_font_choices();
9483: }
9484: if ($role eq 'login') {
1.41 raeburn 9485: @images = ('img','logo','domlogo','login');
1.51 raeburn 9486: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 9487: } else {
9488: @images = ('img');
1.200 raeburn 9489: @bgs = ('pgbg','tabbg','sidebg');
9490: }
9491: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
9492: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
9493: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
9494: }
9495: if ($role eq 'login') {
9496: foreach my $item (@logintext) {
1.234 raeburn 9497: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9498: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9499: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9500: }
9501: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 9502: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9503: }
9504: }
9505: } else {
1.234 raeburn 9506: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
9507: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
9508: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
9509: }
9510: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 9511: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
9512: }
1.6 raeburn 9513: }
1.200 raeburn 9514: foreach my $item (@bgs) {
1.234 raeburn 9515: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9516: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9517: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9518: }
9519: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 9520: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9521: }
9522: }
9523: foreach my $item (@links) {
1.234 raeburn 9524: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9525: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9526: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9527: }
9528: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 9529: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9530: }
1.6 raeburn 9531: }
1.46 raeburn 9532: my ($configuserok,$author_ok,$switchserver) =
9533: &config_check($dom,$confname,$servadm);
1.9 raeburn 9534: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 9535: if (ref($domconfig->{$role}) ne 'HASH') {
9536: $domconfig->{$role} = {};
9537: }
1.8 raeburn 9538: foreach my $img (@images) {
1.70 raeburn 9539: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
9540: if (defined($env{'form.login_showlogo_'.$img})) {
9541: $confhash->{$role}{'showlogo'}{$img} = 1;
9542: } else {
9543: $confhash->{$role}{'showlogo'}{$img} = 0;
9544: }
9545: }
1.18 albertel 9546: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
9547: && !defined($domconfig->{$role}{$img})
9548: && !$env{'form.'.$role.'_del_'.$img}
9549: && $env{'form.'.$role.'_import_'.$img}) {
9550: # import the old configured image from the .tab setting
9551: # if they haven't provided a new one
9552: $domconfig->{$role}{$img} =
9553: $env{'form.'.$role.'_import_'.$img};
9554: }
1.6 raeburn 9555: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 9556: my $error;
1.6 raeburn 9557: if ($configuserok eq 'ok') {
1.9 raeburn 9558: if ($switchserver) {
1.12 raeburn 9559: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 9560: } else {
9561: if ($author_ok eq 'ok') {
9562: my ($result,$logourl) =
9563: &publishlogo($r,'upload',$role.'_'.$img,
9564: $dom,$confname,$img,$width,$height);
9565: if ($result eq 'ok') {
9566: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 9567: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 9568: } else {
1.12 raeburn 9569: $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 9570: }
9571: } else {
1.46 raeburn 9572: $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 9573: }
9574: }
9575: } else {
1.46 raeburn 9576: $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 9577: }
9578: if ($error) {
1.8 raeburn 9579: &Apache::lonnet::logthis($error);
1.11 albertel 9580: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 9581: }
9582: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 9583: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
9584: my $error;
9585: if ($configuserok eq 'ok') {
9586: # is confname an author?
9587: if ($switchserver eq '') {
9588: if ($author_ok eq 'ok') {
9589: my ($result,$logourl) =
9590: &publishlogo($r,'copy',$domconfig->{$role}{$img},
9591: $dom,$confname,$img,$width,$height);
9592: if ($result eq 'ok') {
9593: $confhash->{$role}{$img} = $logourl;
1.18 albertel 9594: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 9595: }
9596: }
9597: }
9598: }
1.6 raeburn 9599: }
9600: }
9601: }
9602: if (ref($domconfig) eq 'HASH') {
9603: if (ref($domconfig->{$role}) eq 'HASH') {
9604: foreach my $img (@images) {
9605: if ($domconfig->{$role}{$img} ne '') {
9606: if ($env{'form.'.$role.'_del_'.$img}) {
9607: $confhash->{$role}{$img} = '';
1.12 raeburn 9608: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 9609: } else {
1.9 raeburn 9610: if ($confhash->{$role}{$img} eq '') {
9611: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
9612: }
1.6 raeburn 9613: }
9614: } else {
9615: if ($env{'form.'.$role.'_del_'.$img}) {
9616: $confhash->{$role}{$img} = '';
1.12 raeburn 9617: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 9618: }
9619: }
1.70 raeburn 9620: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
9621: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
9622: if ($confhash->{$role}{'showlogo'}{$img} ne
9623: $domconfig->{$role}{'showlogo'}{$img}) {
9624: $changes{$role}{'showlogo'}{$img} = 1;
9625: }
9626: } else {
9627: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
9628: $changes{$role}{'showlogo'}{$img} = 1;
9629: }
9630: }
9631: }
9632: }
1.6 raeburn 9633: if ($domconfig->{$role}{'font'} ne '') {
9634: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
9635: $changes{$role}{'font'} = 1;
9636: }
9637: } else {
9638: if ($confhash->{$role}{'font'}) {
9639: $changes{$role}{'font'} = 1;
9640: }
9641: }
1.107 raeburn 9642: if ($role ne 'login') {
9643: if ($domconfig->{$role}{'fontmenu'} ne '') {
9644: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
9645: $changes{$role}{'fontmenu'} = 1;
9646: }
9647: } else {
9648: if ($confhash->{$role}{'fontmenu'}) {
9649: $changes{$role}{'fontmenu'} = 1;
9650: }
1.97 tempelho 9651: }
9652: }
1.6 raeburn 9653: foreach my $item (@bgs) {
9654: if ($domconfig->{$role}{$item} ne '') {
9655: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9656: $changes{$role}{'bgs'}{$item} = 1;
9657: }
9658: } else {
9659: if ($confhash->{$role}{$item}) {
9660: $changes{$role}{'bgs'}{$item} = 1;
9661: }
9662: }
9663: }
9664: foreach my $item (@links) {
9665: if ($domconfig->{$role}{$item} ne '') {
9666: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9667: $changes{$role}{'links'}{$item} = 1;
9668: }
9669: } else {
9670: if ($confhash->{$role}{$item}) {
9671: $changes{$role}{'links'}{$item} = 1;
9672: }
9673: }
9674: }
1.41 raeburn 9675: foreach my $item (@logintext) {
9676: if ($domconfig->{$role}{$item} ne '') {
9677: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9678: $changes{$role}{'logintext'}{$item} = 1;
9679: }
9680: } else {
9681: if ($confhash->{$role}{$item}) {
9682: $changes{$role}{'logintext'}{$item} = 1;
9683: }
9684: }
9685: }
1.6 raeburn 9686: } else {
9687: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 9688: \@logintext,$confhash,\%changes);
1.6 raeburn 9689: }
9690: } else {
9691: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 9692: \@logintext,$confhash,\%changes);
1.6 raeburn 9693: }
9694: }
9695: return ($errors,%changes);
9696: }
9697:
1.46 raeburn 9698: sub config_check {
9699: my ($dom,$confname,$servadm) = @_;
9700: my ($configuserok,$author_ok,$switchserver,%currroles);
9701: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
9702: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
9703: $confname,$servadm);
9704: if ($configuserok eq 'ok') {
9705: $switchserver = &check_switchserver($dom,$confname);
9706: if ($switchserver eq '') {
9707: $author_ok = &check_authorstatus($dom,$confname,%currroles);
9708: }
9709: }
9710: return ($configuserok,$author_ok,$switchserver);
9711: }
9712:
1.6 raeburn 9713: sub default_change_checker {
1.41 raeburn 9714: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 9715: foreach my $item (@{$links}) {
9716: if ($confhash->{$role}{$item}) {
9717: $changes->{$role}{'links'}{$item} = 1;
9718: }
9719: }
9720: foreach my $item (@{$bgs}) {
9721: if ($confhash->{$role}{$item}) {
9722: $changes->{$role}{'bgs'}{$item} = 1;
9723: }
9724: }
1.41 raeburn 9725: foreach my $item (@{$logintext}) {
9726: if ($confhash->{$role}{$item}) {
9727: $changes->{$role}{'logintext'}{$item} = 1;
9728: }
9729: }
1.6 raeburn 9730: foreach my $img (@{$images}) {
9731: if ($env{'form.'.$role.'_del_'.$img}) {
9732: $confhash->{$role}{$img} = '';
1.12 raeburn 9733: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 9734: }
1.70 raeburn 9735: if ($role eq 'login') {
9736: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
9737: $changes->{$role}{'showlogo'}{$img} = 1;
9738: }
9739: }
1.6 raeburn 9740: }
9741: if ($confhash->{$role}{'font'}) {
9742: $changes->{$role}{'font'} = 1;
9743: }
1.48 raeburn 9744: }
1.6 raeburn 9745:
9746: sub display_colorchgs {
9747: my ($dom,$changes,$roles,$confhash) = @_;
9748: my (%choices,$resulttext);
9749: if (!grep(/^login$/,@{$roles})) {
9750: $resulttext = &mt('Changes made:').'<br />';
9751: }
9752: foreach my $role (@{$roles}) {
9753: if ($role eq 'login') {
9754: %choices = &login_choices();
9755: } else {
9756: %choices = &color_font_choices();
9757: }
9758: if (ref($changes->{$role}) eq 'HASH') {
9759: if ($role ne 'login') {
9760: $resulttext .= '<h4>'.&mt($role).'</h4>';
9761: }
9762: foreach my $key (sort(keys(%{$changes->{$role}}))) {
9763: if ($role ne 'login') {
9764: $resulttext .= '<ul>';
9765: }
9766: if (ref($changes->{$role}{$key}) eq 'HASH') {
9767: if ($role ne 'login') {
9768: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
9769: }
9770: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 9771: if (($role eq 'login') && ($key eq 'showlogo')) {
9772: if ($confhash->{$role}{$key}{$item}) {
9773: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
9774: } else {
9775: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
9776: }
9777: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 9778: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
9779: } else {
1.12 raeburn 9780: my $newitem = $confhash->{$role}{$item};
9781: if ($key eq 'images') {
1.306 raeburn 9782: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 9783: }
9784: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 9785: }
9786: }
9787: if ($role ne 'login') {
9788: $resulttext .= '</ul></li>';
9789: }
9790: } else {
9791: if ($confhash->{$role}{$key} eq '') {
9792: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
9793: } else {
9794: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
9795: }
9796: }
9797: if ($role ne 'login') {
9798: $resulttext .= '</ul>';
9799: }
9800: }
9801: }
9802: }
1.3 raeburn 9803: return $resulttext;
1.1 raeburn 9804: }
9805:
1.9 raeburn 9806: sub thumb_dimensions {
9807: return ('200','50');
9808: }
9809:
1.16 raeburn 9810: sub check_dimensions {
9811: my ($inputfile) = @_;
9812: my ($fullwidth,$fullheight);
9813: if ($inputfile =~ m|^[/\w.\-]+$|) {
9814: if (open(PIPE,"identify $inputfile 2>&1 |")) {
9815: my $imageinfo = <PIPE>;
9816: if (!close(PIPE)) {
9817: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
9818: }
9819: chomp($imageinfo);
9820: my ($fullsize) =
1.21 raeburn 9821: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 9822: if ($fullsize) {
9823: ($fullwidth,$fullheight) = split(/x/,$fullsize);
9824: }
9825: }
9826: }
9827: return ($fullwidth,$fullheight);
9828: }
9829:
1.9 raeburn 9830: sub check_configuser {
9831: my ($uhome,$dom,$confname,$servadm) = @_;
9832: my ($configuserok,%currroles);
9833: if ($uhome eq 'no_host') {
9834: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
9835: my $configpass = &LONCAPA::Enrollment::create_password();
9836: $configuserok =
9837: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
9838: $configpass,'','','','','',undef,$servadm);
9839: } else {
9840: $configuserok = 'ok';
9841: %currroles =
9842: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
9843: }
9844: return ($configuserok,%currroles);
9845: }
9846:
9847: sub check_authorstatus {
9848: my ($dom,$confname,%currroles) = @_;
9849: my $author_ok;
1.40 raeburn 9850: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 9851: my $start = time;
9852: my $end = 0;
9853: $author_ok =
9854: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 9855: 'au',$end,$start,'','','domconfig');
1.9 raeburn 9856: } else {
9857: $author_ok = 'ok';
9858: }
9859: return $author_ok;
9860: }
9861:
9862: sub publishlogo {
1.46 raeburn 9863: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 9864: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 9865: if ($action eq 'upload') {
9866: $fname=$env{'form.'.$formname.'.filename'};
9867: chop($env{'form.'.$formname});
9868: } else {
9869: ($fname) = ($formname =~ /([^\/]+)$/);
9870: }
1.46 raeburn 9871: if ($savefileas ne '') {
9872: $fname = $savefileas;
9873: }
1.9 raeburn 9874: $fname=&Apache::lonnet::clean_filename($fname);
9875: # See if there is anything left
9876: unless ($fname) { return ('error: no uploaded file'); }
9877: $fname="$subdir/$fname";
1.210 raeburn 9878: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 9879: my $filepath="$docroot/priv";
9880: my $relpath = "$dom/$confname";
1.9 raeburn 9881: my ($fnamepath,$file,$fetchthumb);
9882: $file=$fname;
9883: if ($fname=~m|/|) {
9884: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
9885: }
1.164 raeburn 9886: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 9887: my $count;
1.164 raeburn 9888: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 9889: $filepath.="/$parts[$count]";
9890: if ((-e $filepath)!=1) {
9891: mkdir($filepath,02770);
9892: }
9893: }
9894: # Check for bad extension and disallow upload
9895: if ($file=~/\.(\w+)$/ &&
9896: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
9897: $output =
1.207 bisitz 9898: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 9899: } elsif ($file=~/\.(\w+)$/ &&
9900: !defined(&Apache::loncommon::fileembstyle($1))) {
9901: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
9902: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 9903: $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 9904: } elsif (-d "$filepath/$file") {
1.195 bisitz 9905: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 9906: } else {
9907: my $source = $filepath.'/'.$file;
9908: my $logfile;
1.316 raeburn 9909: if (!open($logfile,">>",$source.'.log')) {
1.196 raeburn 9910: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 9911: }
9912: print $logfile
9913: "\n================= Publish ".localtime()." ================\n".
9914: $env{'user.name'}.':'.$env{'user.domain'}."\n";
9915: # Save the file
1.316 raeburn 9916: if (!open(FH,">",$source)) {
1.9 raeburn 9917: &Apache::lonnet::logthis('Failed to create '.$source);
9918: return (&mt('Failed to create file'));
9919: }
9920: if ($action eq 'upload') {
9921: if (!print FH ($env{'form.'.$formname})) {
9922: &Apache::lonnet::logthis('Failed to write to '.$source);
9923: return (&mt('Failed to write file'));
9924: }
9925: } else {
9926: my $original = &Apache::lonnet::filelocation('',$formname);
9927: if(!copy($original,$source)) {
9928: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
9929: return (&mt('Failed to write file'));
9930: }
9931: }
9932: close(FH);
9933: chmod(0660, $source); # Permissions to rw-rw---.
9934:
9935: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
9936: my $copyfile=$targetdir.'/'.$file;
9937:
9938: my @parts=split(/\//,$targetdir);
9939: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
9940: for (my $count=5;$count<=$#parts;$count++) {
9941: $path.="/$parts[$count]";
9942: if (!-e $path) {
9943: print $logfile "\nCreating directory ".$path;
9944: mkdir($path,02770);
9945: }
9946: }
9947: my $versionresult;
9948: if (-e $copyfile) {
9949: $versionresult = &logo_versioning($targetdir,$file,$logfile);
9950: } else {
9951: $versionresult = 'ok';
9952: }
9953: if ($versionresult eq 'ok') {
9954: if (copy($source,$copyfile)) {
9955: print $logfile "\nCopied original source to ".$copyfile."\n";
9956: $output = 'ok';
9957: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 9958: push(@{$modified_urls},[$copyfile,$source]);
9959: my $metaoutput =
9960: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
9961: unless ($registered_cleanup) {
9962: my $handlers = $r->get_handlers('PerlCleanupHandler');
9963: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
9964: $registered_cleanup=1;
9965: }
1.9 raeburn 9966: } else {
9967: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
9968: $output = &mt('Failed to copy file to RES space').", $!";
9969: }
9970: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
9971: my $inputfile = $filepath.'/'.$file;
9972: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 9973: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
9974: if ($fullwidth ne '' && $fullheight ne '') {
9975: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
9976: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316 raeburn 9977: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
9978: system({$args[0]} @args);
1.16 raeburn 9979: chmod(0660, $filepath.'/tn-'.$file);
9980: if (-e $outfile) {
9981: my $copyfile=$targetdir.'/tn-'.$file;
9982: if (copy($outfile,$copyfile)) {
9983: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 9984: my $thumb_metaoutput =
9985: &write_metadata($dom,$confname,$formname,
9986: $targetdir,'tn-'.$file,$logfile);
9987: push(@{$modified_urls},[$copyfile,$outfile]);
9988: unless ($registered_cleanup) {
9989: my $handlers = $r->get_handlers('PerlCleanupHandler');
9990: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
9991: $registered_cleanup=1;
9992: }
1.267 raeburn 9993: $madethumb = 1;
1.16 raeburn 9994: } else {
9995: print $logfile "\nUnable to write ".$copyfile.
9996: ':'.$!."\n";
9997: }
9998: }
1.9 raeburn 9999: }
10000: }
10001: }
10002: } else {
10003: $output = $versionresult;
10004: }
10005: }
1.267 raeburn 10006: return ($output,$logourl,$madethumb);
1.9 raeburn 10007: }
10008:
10009: sub logo_versioning {
10010: my ($targetdir,$file,$logfile) = @_;
10011: my $target = $targetdir.'/'.$file;
10012: my ($maxversion,$fn,$extn,$output);
10013: $maxversion = 0;
10014: if ($file =~ /^(.+)\.(\w+)$/) {
10015: $fn=$1;
10016: $extn=$2;
10017: }
10018: opendir(DIR,$targetdir);
10019: while (my $filename=readdir(DIR)) {
10020: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
10021: $maxversion=($1>$maxversion)?$1:$maxversion;
10022: }
10023: }
10024: $maxversion++;
10025: print $logfile "\nCreating old version ".$maxversion."\n";
10026: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
10027: if (copy($target,$copyfile)) {
10028: print $logfile "Copied old target to ".$copyfile."\n";
10029: $copyfile=$copyfile.'.meta';
10030: if (copy($target.'.meta',$copyfile)) {
10031: print $logfile "Copied old target metadata to ".$copyfile."\n";
10032: $output = 'ok';
10033: } else {
10034: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
10035: $output = &mt('Failed to copy old meta').", $!, ";
10036: }
10037: } else {
10038: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
10039: $output = &mt('Failed to copy old target').", $!, ";
10040: }
10041: return $output;
10042: }
10043:
10044: sub write_metadata {
10045: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
10046: my (%metadatafields,%metadatakeys,$output);
10047: $metadatafields{'title'}=$formname;
10048: $metadatafields{'creationdate'}=time;
10049: $metadatafields{'lastrevisiondate'}=time;
10050: $metadatafields{'copyright'}='public';
10051: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
10052: $env{'user.domain'};
10053: $metadatafields{'authorspace'}=$confname.':'.$dom;
10054: $metadatafields{'domain'}=$dom;
10055: {
10056: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
10057: my $mfh;
1.316 raeburn 10058: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 10059: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 10060: unless ($_=~/\./) {
10061: my $unikey=$_;
10062: $unikey=~/^([A-Za-z]+)/;
10063: my $tag=$1;
10064: $tag=~tr/A-Z/a-z/;
10065: print $mfh "\n\<$tag";
10066: foreach (split(/\,/,$metadatakeys{$unikey})) {
10067: my $value=$metadatafields{$unikey.'.'.$_};
10068: $value=~s/\"/\'\'/g;
10069: print $mfh ' '.$_.'="'.$value.'"';
10070: }
10071: print $mfh '>'.
10072: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
10073: .'</'.$tag.'>';
10074: }
10075: }
10076: $output = 'ok';
10077: print $logfile "\nWrote metadata";
10078: close($mfh);
10079: } else {
10080: print $logfile "\nFailed to open metadata file";
1.9 raeburn 10081: $output = &mt('Could not write metadata');
10082: }
10083: }
1.155 raeburn 10084: return $output;
10085: }
10086:
10087: sub notifysubscribed {
10088: foreach my $targetsource (@{$modified_urls}){
10089: next unless (ref($targetsource) eq 'ARRAY');
10090: my ($target,$source)=@{$targetsource};
10091: if ($source ne '') {
1.316 raeburn 10092: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 10093: print $logfh "\nCleanup phase: Notifications\n";
10094: my @subscribed=&subscribed_hosts($target);
10095: foreach my $subhost (@subscribed) {
10096: print $logfh "\nNotifying host ".$subhost.':';
10097: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
10098: print $logfh $reply;
10099: }
10100: my @subscribedmeta=&subscribed_hosts("$target.meta");
10101: foreach my $subhost (@subscribedmeta) {
10102: print $logfh "\nNotifying host for metadata only ".$subhost.':';
10103: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
10104: $subhost);
10105: print $logfh $reply;
10106: }
10107: print $logfh "\n============ Done ============\n";
1.160 raeburn 10108: close($logfh);
1.155 raeburn 10109: }
10110: }
10111: }
10112: return OK;
10113: }
10114:
10115: sub subscribed_hosts {
10116: my ($target) = @_;
10117: my @subscribed;
1.316 raeburn 10118: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 10119: while (my $subline=<$fh>) {
10120: if ($subline =~ /^($match_lonid):/) {
10121: my $host = $1;
10122: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
10123: unless (grep(/^\Q$host\E$/,@subscribed)) {
10124: push(@subscribed,$host);
10125: }
10126: }
10127: }
10128: }
10129: }
10130: return @subscribed;
1.9 raeburn 10131: }
10132:
10133: sub check_switchserver {
10134: my ($dom,$confname) = @_;
10135: my ($allowed,$switchserver);
10136: my $home = &Apache::lonnet::homeserver($confname,$dom);
10137: if ($home eq 'no_host') {
10138: $home = &Apache::lonnet::domain($dom,'primary');
10139: }
10140: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 10141: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
10142: if (!$allowed) {
1.180 raeburn 10143: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 10144: }
10145: return $switchserver;
10146: }
10147:
1.1 raeburn 10148: sub modify_quotas {
1.216 raeburn 10149: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 10150: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 10151: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 10152: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
10153: $validationfieldsref);
1.86 raeburn 10154: if ($action eq 'quotas') {
10155: $context = 'tools';
1.163 raeburn 10156: } else {
1.86 raeburn 10157: $context = $action;
10158: }
10159: if ($context eq 'requestcourses') {
1.325 raeburn 10160: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 10161: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 10162: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
10163: %titles = &courserequest_titles();
10164: $toolregexp = join('|',@usertools);
10165: %conditions = &courserequest_conditions();
1.216 raeburn 10166: $confname = $dom.'-domainconfig';
10167: my $servadm = $r->dir_config('lonAdmEMail');
10168: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 10169: ($validationitemsref,$validationnamesref,$validationfieldsref) =
10170: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 10171: } elsif ($context eq 'requestauthor') {
10172: @usertools = ('author');
10173: %titles = &authorrequest_titles();
1.86 raeburn 10174: } else {
1.162 raeburn 10175: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 10176: %titles = &tool_titles();
1.86 raeburn 10177: }
1.212 raeburn 10178: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 10179: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 10180: foreach my $key (keys(%env)) {
1.101 raeburn 10181: if ($context eq 'requestcourses') {
10182: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
10183: my $item = $1;
10184: my $type = $2;
10185: if ($type =~ /^limit_(.+)/) {
10186: $limithash{$item}{$1} = $env{$key};
10187: } else {
10188: $confhash{$item}{$type} = $env{$key};
10189: }
10190: }
1.163 raeburn 10191: } elsif ($context eq 'requestauthor') {
10192: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
10193: $confhash{$1} = $env{$key};
10194: }
1.101 raeburn 10195: } else {
1.86 raeburn 10196: if ($key =~ /^form\.quota_(.+)$/) {
10197: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 10198: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
10199: $confhash{'authorquota'}{$1} = $env{$key};
10200: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 10201: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
10202: }
1.72 raeburn 10203: }
10204: }
1.163 raeburn 10205: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 10206: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 10207: @approvalnotify = sort(@approvalnotify);
10208: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 10209: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 10210: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
10211: foreach my $type (@hasuniquecode) {
10212: if (grep(/^\Q$type\E$/,@crstypes)) {
10213: $confhash{'uniquecode'}{$type} = 1;
10214: }
1.216 raeburn 10215: }
1.242 raeburn 10216: my (%newbook,%allpos);
1.216 raeburn 10217: if ($context eq 'requestcourses') {
1.242 raeburn 10218: foreach my $type ('textbooks','templates') {
10219: @{$allpos{$type}} = ();
10220: my $invalid;
10221: if ($type eq 'textbooks') {
10222: $invalid = &mt('Invalid LON-CAPA course for textbook');
10223: } else {
10224: $invalid = &mt('Invalid LON-CAPA course for template');
10225: }
10226: if ($env{'form.'.$type.'_addbook'}) {
10227: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
10228: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
10229: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
10230: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
10231: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
10232: } else {
10233: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
10234: my $position = $env{'form.'.$type.'_addbook_pos'};
10235: $position =~ s/\D+//g;
10236: if ($position ne '') {
10237: $allpos{$type}[$position] = $newbook{$type};
10238: }
1.216 raeburn 10239: }
1.242 raeburn 10240: } else {
10241: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 10242: }
10243: }
1.242 raeburn 10244: }
1.216 raeburn 10245: }
1.102 raeburn 10246: if (ref($domconfig{$action}) eq 'HASH') {
10247: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
10248: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
10249: $changes{'notify'}{'approval'} = 1;
10250: }
10251: } else {
1.144 raeburn 10252: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10253: $changes{'notify'}{'approval'} = 1;
10254: }
10255: }
1.218 raeburn 10256: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
10257: if (ref($confhash{'uniquecode'}) eq 'HASH') {
10258: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
10259: unless ($confhash{'uniquecode'}{$crstype}) {
10260: $changes{'uniquecode'} = 1;
10261: }
10262: }
10263: unless ($changes{'uniquecode'}) {
10264: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
10265: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
10266: $changes{'uniquecode'} = 1;
10267: }
10268: }
10269: }
10270: } else {
10271: $changes{'uniquecode'} = 1;
10272: }
10273: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
10274: $changes{'uniquecode'} = 1;
1.216 raeburn 10275: }
10276: if ($context eq 'requestcourses') {
1.242 raeburn 10277: foreach my $type ('textbooks','templates') {
10278: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10279: my %deletions;
10280: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
10281: if (@todelete) {
10282: map { $deletions{$_} = 1; } @todelete;
10283: }
10284: my %imgdeletions;
10285: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
10286: if (@todeleteimages) {
10287: map { $imgdeletions{$_} = 1; } @todeleteimages;
10288: }
10289: my $maxnum = $env{'form.'.$type.'_maxnum'};
10290: for (my $i=0; $i<=$maxnum; $i++) {
10291: my $itemid = $env{'form.'.$type.'_id_'.$i};
10292: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
10293: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
10294: if ($deletions{$key}) {
10295: if ($domconfig{$action}{$type}{$key}{'image'}) {
10296: #FIXME need to obsolete item in RES space
10297: }
10298: next;
10299: } else {
10300: my $newpos = $env{'form.'.$itemid};
10301: $newpos =~ s/\D+//g;
1.243 raeburn 10302: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 10303: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 10304: ($type eq 'templates'));
1.242 raeburn 10305: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
10306: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
10307: $changes{$type}{$key} = 1;
10308: }
10309: }
10310: $allpos{$type}[$newpos] = $key;
10311: }
10312: if ($imgdeletions{$key}) {
10313: $changes{$type}{$key} = 1;
1.216 raeburn 10314: #FIXME need to obsolete item in RES space
1.242 raeburn 10315: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
10316: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 10317: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10318: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10319: } else {
10320: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
10321: $cdom,$cnum,$type,$configuserok,
10322: $switchserver,$author_ok);
10323: if ($imgurl) {
10324: $confhash{$type}{$key}{'image'} = $imgurl;
10325: $changes{$type}{$key} = 1;
10326: }
10327: if ($error) {
10328: &Apache::lonnet::logthis($error);
10329: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10330: }
10331: }
1.242 raeburn 10332: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
10333: $confhash{$type}{$key}{'image'} =
10334: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 10335: }
10336: }
10337: }
10338: }
10339: }
10340: }
1.102 raeburn 10341: } else {
1.144 raeburn 10342: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10343: $changes{'notify'}{'approval'} = 1;
10344: }
1.218 raeburn 10345: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 10346: $changes{'uniquecode'} = 1;
10347: }
10348: }
10349: if ($context eq 'requestcourses') {
1.242 raeburn 10350: foreach my $type ('textbooks','templates') {
10351: if ($newbook{$type}) {
10352: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 10353: foreach my $item ('subject','title','publisher','author') {
10354: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10355: ($type eq 'template'));
1.242 raeburn 10356: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
10357: if ($env{'form.'.$type.'_addbook_'.$item}) {
10358: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
10359: }
10360: }
10361: if ($type eq 'textbooks') {
10362: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
10363: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 10364: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10365: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10366: } else {
10367: my ($imageurl,$error) =
10368: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
10369: $configuserok,$switchserver,$author_ok);
10370: if ($imageurl) {
10371: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
10372: }
10373: if ($error) {
10374: &Apache::lonnet::logthis($error);
10375: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10376: }
1.242 raeburn 10377: }
10378: }
1.216 raeburn 10379: }
10380: }
1.242 raeburn 10381: if (@{$allpos{$type}} > 0) {
10382: my $idx = 0;
10383: foreach my $item (@{$allpos{$type}}) {
10384: if ($item ne '') {
10385: $confhash{$type}{$item}{'order'} = $idx;
10386: if (ref($domconfig{$action}) eq 'HASH') {
10387: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10388: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
10389: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
10390: $changes{$type}{$item} = 1;
10391: }
1.216 raeburn 10392: }
10393: }
10394: }
1.242 raeburn 10395: $idx ++;
1.216 raeburn 10396: }
10397: }
10398: }
10399: }
1.235 raeburn 10400: if (ref($validationitemsref) eq 'ARRAY') {
10401: foreach my $item (@{$validationitemsref}) {
10402: if ($item eq 'fields') {
10403: my @changed;
10404: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
10405: if (@{$confhash{'validation'}{$item}} > 0) {
10406: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
10407: }
1.266 raeburn 10408: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10409: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10410: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
10411: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
10412: $domconfig{'requestcourses'}{'validation'}{$item});
10413: } else {
10414: @changed = @{$confhash{'validation'}{$item}};
10415: }
1.235 raeburn 10416: } else {
10417: @changed = @{$confhash{'validation'}{$item}};
10418: }
10419: } else {
10420: @changed = @{$confhash{'validation'}{$item}};
10421: }
10422: if (@changed) {
10423: if ($confhash{'validation'}{$item}) {
10424: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
10425: } else {
10426: $changes{'validation'}{$item} = &mt('None');
10427: }
10428: }
10429: } else {
10430: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
10431: if ($item eq 'markup') {
10432: if ($env{'form.requestcourses_validation_'.$item}) {
10433: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10434: }
10435: }
1.266 raeburn 10436: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10437: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10438: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
10439: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10440: }
10441: } else {
10442: if ($confhash{'validation'}{$item} ne '') {
10443: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10444: }
1.235 raeburn 10445: }
10446: } else {
10447: if ($confhash{'validation'}{$item} ne '') {
10448: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10449: }
10450: }
10451: }
10452: }
10453: }
10454: if ($env{'form.validationdc'}) {
10455: my $newval = $env{'form.validationdc'};
1.285 raeburn 10456: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 10457: if (exists($domcoords{$newval})) {
10458: $confhash{'validation'}{'dc'} = $newval;
10459: }
10460: }
10461: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 10462: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10463: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10464: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10465: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
10466: if ($confhash{'validation'}{'dc'} eq '') {
10467: $changes{'validation'}{'dc'} = &mt('None');
10468: } else {
10469: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10470: }
1.235 raeburn 10471: }
1.266 raeburn 10472: } elsif ($confhash{'validation'}{'dc'} ne '') {
10473: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 10474: }
10475: } elsif ($confhash{'validation'}{'dc'} ne '') {
10476: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10477: }
10478: } elsif ($confhash{'validation'}{'dc'} ne '') {
10479: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 10480: }
1.266 raeburn 10481: } else {
10482: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10483: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10484: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10485: $changes{'validation'}{'dc'} = &mt('None');
10486: }
10487: }
1.235 raeburn 10488: }
10489: }
1.102 raeburn 10490: }
10491: } else {
1.86 raeburn 10492: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 10493: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 10494: }
1.72 raeburn 10495: foreach my $item (@usertools) {
10496: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 10497: my $unset;
1.101 raeburn 10498: if ($context eq 'requestcourses') {
1.104 raeburn 10499: $unset = '0';
10500: if ($type eq '_LC_adv') {
10501: $unset = '';
10502: }
1.101 raeburn 10503: if ($confhash{$item}{$type} eq 'autolimit') {
10504: $confhash{$item}{$type} .= '=';
10505: unless ($limithash{$item}{$type} =~ /\D/) {
10506: $confhash{$item}{$type} .= $limithash{$item}{$type};
10507: }
10508: }
1.163 raeburn 10509: } elsif ($context eq 'requestauthor') {
10510: $unset = '0';
10511: if ($type eq '_LC_adv') {
10512: $unset = '';
10513: }
1.72 raeburn 10514: } else {
1.101 raeburn 10515: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
10516: $confhash{$item}{$type} = 1;
10517: } else {
10518: $confhash{$item}{$type} = 0;
10519: }
1.72 raeburn 10520: }
1.86 raeburn 10521: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 10522: if ($action eq 'requestauthor') {
10523: if ($domconfig{$action}{$type} ne $confhash{$type}) {
10524: $changes{$type} = 1;
10525: }
10526: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 10527: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
10528: $changes{$item}{$type} = 1;
10529: }
10530: } else {
10531: if ($context eq 'requestcourses') {
1.104 raeburn 10532: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 10533: $changes{$item}{$type} = 1;
10534: }
10535: } else {
10536: if (!$confhash{$item}{$type}) {
10537: $changes{$item}{$type} = 1;
10538: }
10539: }
10540: }
10541: } else {
10542: if ($context eq 'requestcourses') {
1.104 raeburn 10543: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 10544: $changes{$item}{$type} = 1;
10545: }
1.163 raeburn 10546: } elsif ($context eq 'requestauthor') {
10547: if ($confhash{$type} ne $unset) {
10548: $changes{$type} = 1;
10549: }
1.72 raeburn 10550: } else {
10551: if (!$confhash{$item}{$type}) {
10552: $changes{$item}{$type} = 1;
10553: }
10554: }
10555: }
1.1 raeburn 10556: }
10557: }
1.163 raeburn 10558: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 10559: if (ref($domconfig{'quotas'}) eq 'HASH') {
10560: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
10561: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
10562: if (exists($confhash{'defaultquota'}{$key})) {
10563: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
10564: $changes{'defaultquota'}{$key} = 1;
10565: }
10566: } else {
10567: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 10568: }
10569: }
1.86 raeburn 10570: } else {
10571: foreach my $key (keys(%{$domconfig{'quotas'}})) {
10572: if (exists($confhash{'defaultquota'}{$key})) {
10573: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
10574: $changes{'defaultquota'}{$key} = 1;
10575: }
10576: } else {
10577: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 10578: }
1.1 raeburn 10579: }
10580: }
1.197 raeburn 10581: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
10582: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
10583: if (exists($confhash{'authorquota'}{$key})) {
10584: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
10585: $changes{'authorquota'}{$key} = 1;
10586: }
10587: } else {
10588: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
10589: }
10590: }
10591: }
1.1 raeburn 10592: }
1.86 raeburn 10593: if (ref($confhash{'defaultquota'}) eq 'HASH') {
10594: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
10595: if (ref($domconfig{'quotas'}) eq 'HASH') {
10596: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
10597: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
10598: $changes{'defaultquota'}{$key} = 1;
10599: }
10600: } else {
10601: if (!exists($domconfig{'quotas'}{$key})) {
10602: $changes{'defaultquota'}{$key} = 1;
10603: }
1.72 raeburn 10604: }
10605: } else {
1.86 raeburn 10606: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 10607: }
1.1 raeburn 10608: }
10609: }
1.197 raeburn 10610: if (ref($confhash{'authorquota'}) eq 'HASH') {
10611: foreach my $key (keys(%{$confhash{'authorquota'}})) {
10612: if (ref($domconfig{'quotas'}) eq 'HASH') {
10613: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
10614: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
10615: $changes{'authorquota'}{$key} = 1;
10616: }
10617: } else {
10618: $changes{'authorquota'}{$key} = 1;
10619: }
10620: } else {
10621: $changes{'authorquota'}{$key} = 1;
10622: }
10623: }
10624: }
1.1 raeburn 10625: }
1.72 raeburn 10626:
1.163 raeburn 10627: if ($context eq 'requestauthor') {
10628: $domdefaults{'requestauthor'} = \%confhash;
10629: } else {
10630: foreach my $key (keys(%confhash)) {
1.242 raeburn 10631: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 10632: $domdefaults{$key} = $confhash{$key};
10633: }
1.163 raeburn 10634: }
1.72 raeburn 10635: }
1.163 raeburn 10636:
1.1 raeburn 10637: my %quotahash = (
1.86 raeburn 10638: $action => { %confhash }
1.1 raeburn 10639: );
10640: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
10641: $dom);
10642: if ($putresult eq 'ok') {
10643: if (keys(%changes) > 0) {
1.72 raeburn 10644: my $cachetime = 24*60*60;
10645: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 10646: if (ref($lastactref) eq 'HASH') {
10647: $lastactref->{'domdefaults'} = 1;
10648: }
1.1 raeburn 10649: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 10650: unless (($context eq 'requestcourses') ||
1.163 raeburn 10651: ($context eq 'requestauthor')) {
1.86 raeburn 10652: if (ref($changes{'defaultquota'}) eq 'HASH') {
10653: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
10654: foreach my $type (@{$types},'default') {
10655: if (defined($changes{'defaultquota'}{$type})) {
10656: my $typetitle = $usertypes->{$type};
10657: if ($type eq 'default') {
10658: $typetitle = $othertitle;
10659: }
1.213 raeburn 10660: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 10661: }
10662: }
1.86 raeburn 10663: $resulttext .= '</ul></li>';
1.72 raeburn 10664: }
1.197 raeburn 10665: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 10666: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 10667: foreach my $type (@{$types},'default') {
10668: if (defined($changes{'authorquota'}{$type})) {
10669: my $typetitle = $usertypes->{$type};
10670: if ($type eq 'default') {
10671: $typetitle = $othertitle;
10672: }
1.213 raeburn 10673: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 10674: }
10675: }
10676: $resulttext .= '</ul></li>';
10677: }
1.72 raeburn 10678: }
1.80 raeburn 10679: my %newenv;
1.72 raeburn 10680: foreach my $item (@usertools) {
1.163 raeburn 10681: my (%haschgs,%inconf);
10682: if ($context eq 'requestauthor') {
10683: %haschgs = %changes;
1.210 raeburn 10684: %inconf = %confhash;
1.163 raeburn 10685: } else {
10686: if (ref($changes{$item}) eq 'HASH') {
10687: %haschgs = %{$changes{$item}};
10688: }
10689: if (ref($confhash{$item}) eq 'HASH') {
10690: %inconf = %{$confhash{$item}};
10691: }
10692: }
10693: if (keys(%haschgs) > 0) {
1.80 raeburn 10694: my $newacc =
10695: &Apache::lonnet::usertools_access($env{'user.name'},
10696: $env{'user.domain'},
1.86 raeburn 10697: $item,'reload',$context);
1.210 raeburn 10698: if (($context eq 'requestcourses') ||
1.163 raeburn 10699: ($context eq 'requestauthor')) {
1.108 raeburn 10700: if ($env{'environment.canrequest.'.$item} ne $newacc) {
10701: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 10702: }
10703: } else {
10704: if ($env{'environment.availabletools.'.$item} ne $newacc) {
10705: $newenv{'environment.availabletools.'.$item} = $newacc;
10706: }
1.80 raeburn 10707: }
1.163 raeburn 10708: unless ($context eq 'requestauthor') {
10709: $resulttext .= '<li>'.$titles{$item}.'<ul>';
10710: }
1.72 raeburn 10711: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 10712: if ($haschgs{$type}) {
1.72 raeburn 10713: my $typetitle = $usertypes->{$type};
10714: if ($type eq 'default') {
10715: $typetitle = $othertitle;
10716: } elsif ($type eq '_LC_adv') {
10717: $typetitle = 'LON-CAPA Advanced Users';
10718: }
1.163 raeburn 10719: if ($inconf{$type}) {
1.101 raeburn 10720: if ($context eq 'requestcourses') {
10721: my $cond;
1.163 raeburn 10722: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 10723: if ($1 eq '') {
10724: $cond = &mt('(Automatic processing of any request).');
10725: } else {
10726: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
10727: }
10728: } else {
1.163 raeburn 10729: $cond = $conditions{$inconf{$type}};
1.101 raeburn 10730: }
10731: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 10732: } elsif ($context eq 'requestauthor') {
10733: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
10734: $titles{$inconf{$type}},$typetitle);
10735:
1.101 raeburn 10736: } else {
10737: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
10738: }
1.72 raeburn 10739: } else {
1.104 raeburn 10740: if ($type eq '_LC_adv') {
1.163 raeburn 10741: if ($inconf{$type} eq '0') {
1.104 raeburn 10742: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
10743: } else {
10744: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
10745: }
10746: } else {
10747: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
10748: }
1.72 raeburn 10749: }
10750: }
1.26 raeburn 10751: }
1.163 raeburn 10752: unless ($context eq 'requestauthor') {
10753: $resulttext .= '</ul></li>';
10754: }
1.26 raeburn 10755: }
1.1 raeburn 10756: }
1.163 raeburn 10757: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 10758: if (ref($changes{'notify'}) eq 'HASH') {
10759: if ($changes{'notify'}{'approval'}) {
10760: if (ref($confhash{'notify'}) eq 'HASH') {
10761: if ($confhash{'notify'}{'approval'}) {
10762: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
10763: } else {
1.163 raeburn 10764: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 10765: }
10766: }
10767: }
10768: }
10769: }
1.216 raeburn 10770: if ($action eq 'requestcourses') {
10771: my @offon = ('off','on');
10772: if ($changes{'uniquecode'}) {
1.218 raeburn 10773: if (ref($confhash{'uniquecode'}) eq 'HASH') {
10774: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
10775: $resulttext .= '<li>'.
10776: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
10777: '</li>';
10778: } else {
10779: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
10780: '</li>';
10781: }
1.216 raeburn 10782: }
1.242 raeburn 10783: foreach my $type ('textbooks','templates') {
10784: if (ref($changes{$type}) eq 'HASH') {
10785: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
10786: foreach my $key (sort(keys(%{$changes{$type}}))) {
10787: my %coursehash = &Apache::lonnet::coursedescription($key);
10788: my $coursetitle = $coursehash{'description'};
10789: my $position = $confhash{$type}{$key}{'order'} + 1;
10790: $resulttext .= '<li>';
1.243 raeburn 10791: foreach my $item ('subject','title','publisher','author') {
10792: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10793: ($type eq 'templates'));
1.242 raeburn 10794: my $name = $item.':';
10795: $name =~ s/^(\w)/\U$1/;
10796: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
10797: }
10798: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
10799: if ($type eq 'textbooks') {
10800: if ($confhash{$type}{$key}{'image'}) {
10801: $resulttext .= ' '.&mt('Image: [_1]',
10802: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
10803: ' alt="Textbook cover" />').'<br />';
10804: }
10805: }
10806: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 10807: }
1.242 raeburn 10808: $resulttext .= '</ul></li>';
1.216 raeburn 10809: }
10810: }
1.235 raeburn 10811: if (ref($changes{'validation'}) eq 'HASH') {
10812: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
10813: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
10814: foreach my $item (@{$validationitemsref}) {
10815: if (exists($changes{'validation'}{$item})) {
10816: if ($item eq 'markup') {
10817: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
10818: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
10819: } else {
10820: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
10821: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
10822: }
10823: }
10824: }
10825: if (exists($changes{'validation'}{'dc'})) {
10826: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
10827: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
10828: }
10829: }
10830: }
1.216 raeburn 10831: }
1.1 raeburn 10832: $resulttext .= '</ul>';
1.80 raeburn 10833: if (keys(%newenv)) {
10834: &Apache::lonnet::appenv(\%newenv);
10835: }
1.1 raeburn 10836: } else {
1.86 raeburn 10837: if ($context eq 'requestcourses') {
10838: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 10839: } elsif ($context eq 'requestauthor') {
10840: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 10841: } else {
1.90 weissno 10842: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 10843: }
1.1 raeburn 10844: }
10845: } else {
1.11 albertel 10846: $resulttext = '<span class="LC_error">'.
10847: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10848: }
1.216 raeburn 10849: if ($errors) {
10850: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
10851: '<ul>'.$errors.'</ul></p>';
10852: }
1.3 raeburn 10853: return $resulttext;
1.1 raeburn 10854: }
10855:
1.216 raeburn 10856: sub process_textbook_image {
1.242 raeburn 10857: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 10858: my $filename = $env{'form.'.$caller.'.filename'};
10859: my ($error,$url);
10860: my ($width,$height) = (50,50);
10861: if ($configuserok eq 'ok') {
10862: if ($switchserver) {
10863: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
10864: $switchserver);
10865: } elsif ($author_ok eq 'ok') {
10866: my ($result,$imageurl) =
10867: &publishlogo($r,'upload',$caller,$dom,$confname,
1.312 raeburn 10868: "$type/$cdom/$cnum/cover",$width,$height);
1.216 raeburn 10869: if ($result eq 'ok') {
10870: $url = $imageurl;
10871: } else {
10872: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
10873: }
10874: } else {
10875: $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);
10876: }
10877: } else {
10878: $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);
10879: }
10880: return ($url,$error);
10881: }
10882:
1.267 raeburn 10883: sub modify_ltitools {
10884: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
10885: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 10886: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 10887: my $confname = $dom.'-domainconfig';
10888: my $servadm = $r->dir_config('lonAdmEMail');
10889: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10890: my (%posslti,%possfield);
10891: my @courseroles = ('cc','in','ta','ep','st');
10892: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
10893: map { $posslti{$_} = 1; } @ltiroles;
10894: my @allfields = ('fullname','firstname','lastname','email','user','roles');
10895: map { $possfield{$_} = 1; } @allfields;
10896: my %lt = <itools_names();
10897: if ($env{'form.ltitools_add'}) {
10898: my $title = $env{'form.ltitools_add_title'};
10899: $title =~ s/(`)/'/g;
10900: ($newid,my $error) = &get_ltitools_id($dom,$title);
10901: if ($newid) {
10902: my $position = $env{'form.ltitools_add_pos'};
10903: $position =~ s/\D+//g;
10904: if ($position ne '') {
10905: $allpos[$position] = $newid;
10906: }
10907: $changes{$newid} = 1;
1.322 raeburn 10908: foreach my $item ('title','url','key','secret','lifetime') {
1.267 raeburn 10909: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1.322 raeburn 10910: if ($item eq 'lifetime') {
10911: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
10912: }
1.267 raeburn 10913: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 10914: if (($item eq 'key') || ($item eq 'secret')) {
10915: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
10916: } else {
10917: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
10918: }
1.267 raeburn 10919: }
10920: }
10921: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
10922: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
10923: }
10924: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
10925: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
10926: }
1.323 raeburn 10927: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
10928: $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
10929: } else {
10930: $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
10931: }
1.296 raeburn 10932: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 10933: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
10934: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 10935: if (($item eq 'width') || ($item eq 'height')) {
10936: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
10937: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
10938: }
10939: } else {
10940: if ($env{'form.ltitools_add_'.$item} ne '') {
10941: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
10942: }
1.267 raeburn 10943: }
10944: }
10945: if ($env{'form.ltitools_add_target'} eq 'window') {
10946: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 10947: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
10948: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 10949: } else {
10950: $confhash{$newid}{'display'}{'target'} = 'iframe';
10951: }
10952: foreach my $item ('passback','roster') {
1.319 raeburn 10953: if ($env{'form.ltitools_'.$item.'_add'}) {
1.267 raeburn 10954: $confhash{$newid}{$item} = 1;
1.319 raeburn 10955: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
10956: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
10957: $lifetime =~ s/^\s+|\s+$//g;
10958: if ($lifetime =~ /^\d+\.?\d*$/) {
10959: $confhash{$newid}{$item.'valid'} = $lifetime;
10960: }
10961: }
1.267 raeburn 10962: }
10963: }
10964: if ($env{'form.ltitools_add_image.filename'} ne '') {
10965: my ($imageurl,$error) =
1.307 raeburn 10966: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267 raeburn 10967: $configuserok,$switchserver,$author_ok);
10968: if ($imageurl) {
10969: $confhash{$newid}{'image'} = $imageurl;
10970: }
10971: if ($error) {
10972: &Apache::lonnet::logthis($error);
10973: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10974: }
10975: }
10976: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
10977: foreach my $field (@fields) {
10978: if ($possfield{$field}) {
10979: if ($field eq 'roles') {
10980: foreach my $role (@courseroles) {
10981: my $choice = $env{'form.ltitools_add_roles_'.$role};
10982: if (($choice ne '') && ($posslti{$choice})) {
10983: $confhash{$newid}{'roles'}{$role} = $choice;
10984: if ($role eq 'cc') {
10985: $confhash{$newid}{'roles'}{'co'} = $choice;
10986: }
10987: }
10988: }
10989: } else {
10990: $confhash{$newid}{'fields'}{$field} = 1;
10991: }
10992: }
10993: }
1.324 raeburn 10994: if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
10995: if ($confhash{$newid}{'fields'}{'user'}) {
10996: if ($env{'form.ltitools_userincdom_add'}) {
10997: $confhash{$newid}{'incdom'} = 1;
10998: }
10999: }
11000: }
1.273 raeburn 11001: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
11002: foreach my $item (@courseconfig) {
11003: $confhash{$newid}{'crsconf'}{$item} = 1;
11004: }
1.267 raeburn 11005: if ($env{'form.ltitools_add_custom'}) {
11006: my $name = $env{'form.ltitools_add_custom_name'};
11007: my $value = $env{'form.ltitools_add_custom_value'};
11008: $value =~ s/(`)/'/g;
11009: $name =~ s/(`)/'/g;
11010: $confhash{$newid}{'custom'}{$name} = $value;
11011: }
11012: } else {
11013: my $error = &mt('Failed to acquire unique ID for new external tool');
11014: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11015: }
11016: }
11017: if (ref($domconfig{$action}) eq 'HASH') {
11018: my %deletions;
11019: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
11020: if (@todelete) {
11021: map { $deletions{$_} = 1; } @todelete;
11022: }
11023: my %customadds;
11024: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
11025: if (@newcustom) {
11026: map { $customadds{$_} = 1; } @newcustom;
11027: }
11028: my %imgdeletions;
11029: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
11030: if (@todeleteimages) {
11031: map { $imgdeletions{$_} = 1; } @todeleteimages;
11032: }
11033: my $maxnum = $env{'form.ltitools_maxnum'};
11034: for (my $i=0; $i<=$maxnum; $i++) {
11035: my $itemid = $env{'form.ltitools_id_'.$i};
1.308 raeburn 11036: $itemid =~ s/\D+//g;
1.267 raeburn 11037: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11038: if ($deletions{$itemid}) {
11039: if ($domconfig{$action}{$itemid}{'image'}) {
11040: #FIXME need to obsolete item in RES space
11041: }
11042: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
11043: next;
11044: } else {
11045: my $newpos = $env{'form.ltitools_'.$itemid};
11046: $newpos =~ s/\D+//g;
1.322 raeburn 11047: foreach my $item ('title','url','lifetime') {
1.267 raeburn 11048: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
11049: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
11050: $changes{$itemid} = 1;
11051: }
11052: }
1.297 raeburn 11053: foreach my $item ('key','secret') {
11054: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
11055: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
11056: $changes{$itemid} = 1;
11057: }
11058: }
1.267 raeburn 11059: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
11060: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
11061: }
11062: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
11063: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
11064: }
1.323 raeburn 11065: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
11066: $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
11067: } else {
11068: $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
11069: }
11070: if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
11071: if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
11072: $changes{$itemid} = 1;
11073: }
11074: } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
11075: $changes{$itemid} = 1;
11076: }
1.267 raeburn 11077: foreach my $size ('width','height') {
11078: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
11079: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
11080: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
11081: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
11082: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11083: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
11084: $changes{$itemid} = 1;
11085: }
11086: } else {
11087: $changes{$itemid} = 1;
11088: }
1.296 raeburn 11089: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11090: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
11091: $changes{$itemid} = 1;
11092: }
11093: }
11094: }
11095: foreach my $item ('linktext','explanation') {
11096: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
11097: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
11098: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
11099: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
11100: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11101: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
11102: $changes{$itemid} = 1;
11103: }
11104: } else {
11105: $changes{$itemid} = 1;
11106: }
11107: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11108: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
11109: $changes{$itemid} = 1;
11110: }
1.267 raeburn 11111: }
11112: }
11113: if ($env{'form.ltitools_target_'.$i} eq 'window') {
11114: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 11115: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
11116: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 11117: } else {
11118: $confhash{$itemid}{'display'}{'target'} = 'iframe';
11119: }
11120: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11121: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
11122: $changes{$itemid} = 1;
11123: }
11124: } else {
11125: $changes{$itemid} = 1;
11126: }
11127: foreach my $extra ('passback','roster') {
11128: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
11129: $confhash{$itemid}{$extra} = 1;
1.319 raeburn 11130: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
11131: my $lifetime = $env{'form.ltitools_'.$extra.'valid_add'};
11132: $lifetime =~ s/^\s+|\s+$//g;
11133: if ($lifetime =~ /^\d+\.?\d*$/) {
11134: $confhash{$itemid}{$extra.'valid'} = $lifetime;
11135: }
11136: }
1.267 raeburn 11137: }
11138: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
11139: $changes{$itemid} = 1;
11140: }
1.319 raeburn 11141: if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
11142: $changes{$itemid} = 1;
11143: }
1.267 raeburn 11144: }
1.273 raeburn 11145: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318 raeburn 11146: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 11147: if (grep(/^\Q$item\E$/,@courseconfig)) {
11148: $confhash{$itemid}{'crsconf'}{$item} = 1;
11149: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
11150: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
11151: $changes{$itemid} = 1;
11152: }
11153: } else {
11154: $changes{$itemid} = 1;
11155: }
11156: }
11157: }
1.267 raeburn 11158: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
11159: foreach my $field (@fields) {
11160: if ($possfield{$field}) {
11161: if ($field eq 'roles') {
11162: foreach my $role (@courseroles) {
11163: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
11164: if (($choice ne '') && ($posslti{$choice})) {
11165: $confhash{$itemid}{'roles'}{$role} = $choice;
11166: if ($role eq 'cc') {
11167: $confhash{$itemid}{'roles'}{'co'} = $choice;
11168: }
11169: }
11170: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
11171: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
11172: $changes{$itemid} = 1;
11173: }
11174: } elsif ($confhash{$itemid}{'roles'}{$role}) {
11175: $changes{$itemid} = 1;
11176: }
11177: }
11178: } else {
11179: $confhash{$itemid}{'fields'}{$field} = 1;
11180: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
11181: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
11182: $changes{$itemid} = 1;
11183: }
11184: } else {
11185: $changes{$itemid} = 1;
11186: }
11187: }
11188: }
11189: }
1.324 raeburn 11190: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
11191: if ($confhash{$itemid}{'fields'}{'user'}) {
11192: if ($env{'form.ltitools_userincdom_'.$i}) {
11193: $confhash{$itemid}{'incdom'} = 1;
11194: }
11195: if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
11196: $changes{$itemid} = 1;
11197: }
11198: }
11199: }
1.267 raeburn 11200: $allpos[$newpos] = $itemid;
11201: }
11202: if ($imgdeletions{$itemid}) {
11203: $changes{$itemid} = 1;
11204: #FIXME need to obsolete item in RES space
11205: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
11206: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
11207: $itemid,$configuserok,$switchserver,
11208: $author_ok);
11209: if ($imgurl) {
11210: $confhash{$itemid}{'image'} = $imgurl;
11211: $changes{$itemid} = 1;
11212: }
11213: if ($error) {
11214: &Apache::lonnet::logthis($error);
11215: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11216: }
11217: } elsif ($domconfig{$action}{$itemid}{'image'}) {
11218: $confhash{$itemid}{'image'} =
11219: $domconfig{$action}{$itemid}{'image'};
11220: }
11221: if ($customadds{$i}) {
11222: my $name = $env{'form.ltitools_custom_name_'.$i};
11223: $name =~ s/(`)/'/g;
11224: $name =~ s/^\s+//;
11225: $name =~ s/\s+$//;
11226: my $value = $env{'form.ltitools_custom_value_'.$i};
11227: $value =~ s/(`)/'/g;
11228: $value =~ s/^\s+//;
11229: $value =~ s/\s+$//;
11230: if ($name ne '') {
11231: $confhash{$itemid}{'custom'}{$name} = $value;
11232: $changes{$itemid} = 1;
11233: }
11234: }
11235: my %customdels;
11236: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
11237: if (@customdeletions) {
11238: $changes{$itemid} = 1;
11239: }
11240: map { $customdels{$_} = 1; } @customdeletions;
11241: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
11242: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
11243: unless ($customdels{$key}) {
11244: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
11245: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
11246: }
11247: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
11248: $changes{$itemid} = 1;
11249: }
11250: }
11251: }
11252: }
11253: unless ($changes{$itemid}) {
11254: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
11255: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
11256: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
11257: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
11258: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
11259: $changes{$itemid} = 1;
11260: last;
11261: }
11262: }
11263: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
11264: $changes{$itemid} = 1;
11265: }
11266: }
11267: last if ($changes{$itemid});
11268: }
11269: }
11270: }
11271: }
11272: }
11273: if (@allpos > 0) {
11274: my $idx = 0;
11275: foreach my $itemid (@allpos) {
11276: if ($itemid ne '') {
11277: $confhash{$itemid}{'order'} = $idx;
11278: if (ref($domconfig{$action}) eq 'HASH') {
11279: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11280: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
11281: $changes{$itemid} = 1;
11282: }
11283: }
11284: }
11285: $idx ++;
11286: }
11287: }
11288: }
11289: my %ltitoolshash = (
11290: $action => { %confhash }
11291: );
11292: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
11293: $dom);
11294: if ($putresult eq 'ok') {
1.297 raeburn 11295: my %ltienchash = (
11296: $action => { %encconfig }
11297: );
11298: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
1.267 raeburn 11299: if (keys(%changes) > 0) {
11300: my $cachetime = 24*60*60;
1.297 raeburn 11301: my %ltiall = %confhash;
11302: foreach my $id (keys(%ltiall)) {
11303: if (ref($encconfig{$id}) eq 'HASH') {
11304: foreach my $item ('key','secret') {
11305: $ltiall{$id}{$item} = $encconfig{$id}{$item};
11306: }
11307: }
11308: }
11309: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 11310: if (ref($lastactref) eq 'HASH') {
11311: $lastactref->{'ltitools'} = 1;
11312: }
11313: $resulttext = &mt('Changes made:').'<ul>';
11314: my %bynum;
11315: foreach my $itemid (sort(keys(%changes))) {
11316: my $position = $confhash{$itemid}{'order'};
11317: $bynum{$position} = $itemid;
11318: }
11319: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
11320: my $itemid = $bynum{$pos};
11321: if (ref($confhash{$itemid}) ne 'HASH') {
11322: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
11323: } else {
11324: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
11325: if ($confhash{$itemid}{'image'}) {
11326: $resulttext .= ' '.
11327: '<img src="'.$confhash{$itemid}{'image'}.'"'.
11328: ' alt="'.&mt('Tool Provider icon').'" />';
11329: }
11330: $resulttext .= '</li><ul>';
11331: my $position = $pos + 1;
11332: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.323 raeburn 11333: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1.267 raeburn 11334: if ($confhash{$itemid}{$item} ne '') {
11335: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
11336: }
11337: }
1.297 raeburn 11338: if ($encconfig{$itemid}{'key'} ne '') {
11339: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
11340: }
11341: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 11342: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 11343: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 11344: $resulttext .= ('*'x$num).'</li>';
11345: }
1.273 raeburn 11346: $resulttext .= '<li>'.&mt('Configurable in course:');
1.318 raeburn 11347: my @possconfig = ('label','title','target','linktext','explanation','append');
1.273 raeburn 11348: my $numconfig = 0;
11349: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
11350: foreach my $item (@possconfig) {
11351: if ($confhash{$itemid}{'crsconf'}{$item}) {
11352: $numconfig ++;
1.296 raeburn 11353: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 11354: }
11355: }
11356: }
11357: if (!$numconfig) {
11358: $resulttext .= &mt('None');
11359: }
11360: $resulttext .= '</li>';
1.267 raeburn 11361: foreach my $item ('passback','roster') {
11362: $resulttext .= '<li>'.$lt{$item}.' ';
11363: if ($confhash{$itemid}{$item}) {
11364: $resulttext .= &mt('Yes');
1.319 raeburn 11365: if ($confhash{$itemid}{$item.'valid'}) {
11366: if ($item eq 'passback') {
11367: $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
11368: $confhash{$itemid}{$item.'valid'});
11369: } else {
11370: $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
11371: $confhash{$itemid}{$item.'valid'});
11372: }
11373: }
1.267 raeburn 11374: } else {
11375: $resulttext .= &mt('No');
11376: }
11377: $resulttext .= '</li>';
11378: }
11379: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
11380: my $displaylist;
11381: if ($confhash{$itemid}{'display'}{'target'}) {
11382: $displaylist = &mt('Display target').': '.
11383: $confhash{$itemid}{'display'}{'target'}.',';
11384: }
11385: foreach my $size ('width','height') {
11386: if ($confhash{$itemid}{'display'}{$size}) {
11387: $displaylist .= (' 'x2).$lt{$size}.': '.
11388: $confhash{$itemid}{'display'}{$size}.',';
11389: }
11390: }
11391: if ($displaylist) {
11392: $displaylist =~ s/,$//;
11393: $resulttext .= '<li>'.$displaylist.'</li>';
11394: }
1.296 raeburn 11395: foreach my $item ('linktext','explanation') {
11396: if ($confhash{$itemid}{'display'}{$item}) {
11397: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
11398: }
11399: }
11400: }
1.267 raeburn 11401: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
11402: my $fieldlist;
11403: foreach my $field (@allfields) {
11404: if ($confhash{$itemid}{'fields'}{$field}) {
11405: $fieldlist .= (' 'x2).$lt{$field}.',';
11406: }
11407: }
11408: if ($fieldlist) {
11409: $fieldlist =~ s/,$//;
1.324 raeburn 11410: if ($confhash{$itemid}{'fields'}{'user'}) {
11411: if ($confhash{$itemid}{'incdom'}) {
11412: $fieldlist .= ' ('.&mt('username:domain').')';
11413: } else {
11414: $fieldlist .= ' ('.&mt('username').')';
11415: }
11416: }
1.267 raeburn 11417: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
11418: }
11419: }
11420: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
11421: my $rolemaps;
11422: foreach my $role (@courseroles) {
11423: if ($confhash{$itemid}{'roles'}{$role}) {
11424: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
11425: $confhash{$itemid}{'roles'}{$role}.',';
11426: }
11427: }
11428: if ($rolemaps) {
11429: $rolemaps =~ s/,$//;
11430: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
11431: }
11432: }
11433: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
11434: my $customlist;
11435: if (keys(%{$confhash{$itemid}{'custom'}})) {
11436: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
11437: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
11438: }
11439: }
11440: if ($customlist) {
1.317 raeburn 11441: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267 raeburn 11442: }
11443: }
11444: $resulttext .= '</ul></li>';
11445: }
11446: }
11447: $resulttext .= '</ul>';
11448: } else {
11449: $resulttext = &mt('No changes made.');
11450: }
11451: } else {
11452: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
11453: }
11454: if ($errors) {
11455: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11456: $errors.'</ul>';
11457: }
11458: return $resulttext;
11459: }
11460:
11461: sub process_ltitools_image {
11462: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
11463: my $filename = $env{'form.'.$caller.'.filename'};
11464: my ($error,$url);
11465: my ($width,$height) = (21,21);
11466: if ($configuserok eq 'ok') {
11467: if ($switchserver) {
11468: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
11469: $switchserver);
11470: } elsif ($author_ok eq 'ok') {
11471: my ($result,$imageurl,$madethumb) =
11472: &publishlogo($r,'upload',$caller,$dom,$confname,
11473: "ltitools/$itemid/icon",$width,$height);
11474: if ($result eq 'ok') {
11475: if ($madethumb) {
11476: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
11477: my $imagethumb = "$path/tn-".$imagefile;
11478: $url = $imagethumb;
11479: } else {
11480: $url = $imageurl;
11481: }
11482: } else {
11483: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
11484: }
11485: } else {
11486: $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);
11487: }
11488: } else {
11489: $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);
11490: }
11491: return ($url,$error);
11492: }
11493:
11494: sub get_ltitools_id {
11495: my ($cdom,$title) = @_;
11496: # get lock on ltitools db
11497: my $lockhash = {
11498: lock => $env{'user.name'}.
11499: ':'.$env{'user.domain'},
11500: };
11501: my $tries = 0;
11502: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
11503: my ($id,$error);
11504:
11505: while (($gotlock ne 'ok') && ($tries<10)) {
11506: $tries ++;
11507: sleep (0.1);
11508: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
11509: }
11510: if ($gotlock eq 'ok') {
11511: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
11512: if ($currids{'lock'}) {
11513: delete($currids{'lock'});
11514: if (keys(%currids)) {
11515: my @curr = sort { $a <=> $b } keys(%currids);
11516: if ($curr[-1] =~ /^\d+$/) {
11517: $id = 1 + $curr[-1];
11518: }
11519: } else {
11520: $id = 1;
11521: }
11522: if ($id) {
11523: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
11524: $error = 'nostore';
11525: }
11526: } else {
11527: $error = 'nonumber';
11528: }
11529: }
11530: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
11531: } else {
11532: $error = 'nolock';
11533: }
11534: return ($id,$error);
11535: }
11536:
1.320 raeburn 11537: sub modify_lti {
11538: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
11539: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11540: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
11541: my (%posslti,%posslticrs,%posscrstype);
11542: my @courseroles = ('cc','in','ta','ep','st');
11543: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
11544: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
11545: my @coursetypes = ('official','unofficial','community','textbook','placement');
11546: my %coursetypetitles = &Apache::lonlocal::texthash (
11547: official => 'Official',
11548: unofficial => 'Unofficial',
11549: community => 'Community',
11550: textbook => 'Textbook',
11551: placement => 'Placement Test',
11552: );
1.325 raeburn 11553: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 11554: my %lt = <i_names();
11555: map { $posslti{$_} = 1; } @ltiroles;
11556: map { $posslticrs{$_} = 1; } @lticourseroles;
11557: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 11558:
1.326 raeburn 11559: my %menutitles = <imenu_titles();
11560:
1.320 raeburn 11561: my (@items,%deletions,%itemids);
11562: if ($env{'form.lti_add'}) {
11563: my $consumer = $env{'form.lti_consumer_add'};
11564: $consumer =~ s/(`)/'/g;
11565: ($newid,my $error) = &get_lti_id($dom,$consumer);
11566: if ($newid) {
11567: $itemids{'add'} = $newid;
11568: push(@items,'add');
11569: $changes{$newid} = 1;
11570: } else {
11571: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
11572: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11573: }
11574: }
11575: if (ref($domconfig{$action}) eq 'HASH') {
11576: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
11577: if (@todelete) {
11578: map { $deletions{$_} = 1; } @todelete;
11579: }
11580: my $maxnum = $env{'form.lti_maxnum'};
11581: for (my $i=0; $i<=$maxnum; $i++) {
11582: my $itemid = $env{'form.lti_id_'.$i};
11583: $itemid =~ s/\D+//g;
11584: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11585: if ($deletions{$itemid}) {
11586: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
11587: } else {
11588: push(@items,$i);
11589: $itemids{$i} = $itemid;
11590: }
11591: }
11592: }
11593: }
11594: foreach my $idx (@items) {
11595: my $itemid = $itemids{$idx};
11596: next unless ($itemid);
11597: my $position = $env{'form.lti_pos_'.$idx};
11598: $position =~ s/\D+//g;
11599: if ($position ne '') {
11600: $allpos[$position] = $itemid;
11601: }
11602: foreach my $item ('consumer','key','secret','lifetime') {
11603: my $formitem = 'form.lti_'.$item.'_'.$idx;
11604: $env{$formitem} =~ s/(`)/'/g;
11605: if ($item eq 'lifetime') {
11606: $env{$formitem} =~ s/[^\d.]//g;
11607: }
11608: if ($env{$formitem} ne '') {
11609: if (($item eq 'key') || ($item eq 'secret')) {
11610: $encconfig{$itemid}{$item} = $env{$formitem};
11611: } else {
11612: $confhash{$itemid}{$item} = $env{$formitem};
11613: unless (($idx eq 'add') || ($changes{$itemid})) {
11614: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
11615: $changes{$itemid} = 1;
11616: }
11617: }
11618: }
11619: }
11620: }
11621: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
11622: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
11623: }
11624: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
11625: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
11626: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
11627: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
11628: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
11629: my $mapuser = $env{'form.lti_customuser_'.$idx};
11630: $mapuser =~ s/(`)/'/g;
11631: $mapuser =~ s/^\s+|\s+$//g;
11632: $confhash{$itemid}{'mapuser'} = $mapuser;
11633: }
11634: foreach my $ltirole (@lticourseroles) {
11635: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
11636: if (grep(/^\Q$possrole\E$/,@courseroles)) {
11637: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
11638: }
11639: }
11640: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
11641: my @makeuser;
11642: foreach my $ltirole (sort(@possmakeuser)) {
11643: if ($posslti{$ltirole}) {
11644: push(@makeuser,$ltirole);
11645: }
11646: }
11647: $confhash{$itemid}{'makeuser'} = \@makeuser;
1.325 raeburn 11648: if (@makeuser) {
11649: my $lcauth = $env{'form.lti_lcauth_'.$idx};
11650: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
11651: $confhash{$itemid}{'lcauth'} = $lcauth;
11652: if ($lcauth ne 'internal') {
11653: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
11654: $lcauthparm =~ s/^(\s+|\s+)$//g;
11655: $lcauthparm =~ s/`//g;
11656: if ($lcauthparm ne '') {
11657: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
11658: }
11659: }
11660: } else {
11661: $confhash{$itemid}{'lcauth'} = 'lti';
11662: }
11663: }
11664: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
11665: if (@possinstdata) {
11666: foreach my $field (@possinstdata) {
11667: if (exists($fieldtitles{$field})) {
11668: push(@{$confhash{$itemid}{'instdata'}});
11669: }
11670: }
11671: }
1.320 raeburn 11672: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
11673: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
11674: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
11675: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
11676: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
11677: $mapcrs =~ s/(`)/'/g;
11678: $mapcrs =~ s/^\s+|\s+$//g;
11679: $confhash{$itemid}{'mapcrs'} = $mapcrs;
11680: }
11681: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
11682: my @crstypes;
11683: foreach my $type (sort(@posstypes)) {
11684: if ($posscrstype{$type}) {
11685: push(@crstypes,$type);
11686: }
11687: }
11688: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
11689: if ($env{'form.lti_makecrs_'.$idx}) {
11690: $confhash{$itemid}{'makecrs'} = 1;
11691: }
11692: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
11693: my @selfenroll;
11694: foreach my $type (sort(@possenroll)) {
11695: if ($posslticrs{$type}) {
11696: push(@selfenroll,$type);
11697: }
11698: }
11699: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
11700: if ($env{'form.lti_crssec_'.$idx}) {
11701: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
11702: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
11703: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
11704: my $section = $env{'form.lti_customsection_'.$idx};
11705: $section =~ s/(`)/'/g;
11706: $section =~ s/^\s+|\s+$//g;
11707: if ($section ne '') {
11708: $confhash{$itemid}{'section'} = $section;
11709: }
11710: }
11711: }
1.326 raeburn 11712: foreach my $field ('passback','roster','topmenu','inlinemenu') {
1.321 raeburn 11713: if ($env{'form.lti_'.$field.'_'.$idx}) {
1.320 raeburn 11714: $confhash{$itemid}{$field} = 1;
11715: }
11716: }
1.326 raeburn 11717:
11718: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
11719: $confhash{$itemid}{lcmenu} = [];
11720: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
11721: foreach my $field (@possmenu) {
11722: if (exists($menutitles{$field})) {
11723: if ($field eq 'grades') {
11724: next unless ($env{'form.lti_inlinemenu_'.$idx});
11725: }
11726: push(@{$confhash{$itemid}{lcmenu}},$field);
11727: }
11728: }
11729: }
1.320 raeburn 11730: unless (($idx eq 'add') || ($changes{$itemid})) {
1.326 raeburn 11731: foreach my $field ('mapuser','mapcrs','makecrs','section','passback','roster','lcauth','lcauthparm','topmenu','inlinemenu') {
1.320 raeburn 11732: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
11733: $changes{$itemid} = 1;
11734: }
11735: }
1.326 raeburn 11736: foreach my $field ('makeuser','mapcrstype','selfenroll','instdata','lcmenu') {
1.320 raeburn 11737: unless ($changes{$itemid}) {
11738: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
11739: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
11740: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
11741: $confhash{$itemid}{$field});
11742: if (@diffs) {
11743: $changes{$itemid} = 1;
11744: }
11745: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
11746: $changes{$itemid} = 1;
11747: }
11748: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
11749: if (@{$confhash{$itemid}{$field}} > 0) {
11750: $changes{$itemid} = 1;
11751: }
11752: }
11753: }
11754: }
11755: unless ($changes{$itemid}) {
11756: if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
11757: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
11758: foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
11759: if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne
11760: $confhash{$itemid}{'maproles'}{$ltirole}) {
11761: $changes{$itemid} = 1;
11762: last;
11763: }
11764: }
11765: unless ($changes{$itemid}) {
11766: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
11767: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
11768: $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
11769: $changes{$itemid} = 1;
11770: last;
11771: }
11772: }
11773: }
11774: } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
11775: $changes{$itemid} = 1;
11776: }
11777: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
11778: unless ($changes{$itemid}) {
11779: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
11780: $changes{$itemid} = 1;
11781: }
11782: }
11783: }
11784: }
11785: }
11786: }
11787: if (@allpos > 0) {
11788: my $idx = 0;
11789: foreach my $itemid (@allpos) {
11790: if ($itemid ne '') {
11791: $confhash{$itemid}{'order'} = $idx;
11792: if (ref($domconfig{$action}) eq 'HASH') {
11793: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11794: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
11795: $changes{$itemid} = 1;
11796: }
11797: }
11798: }
11799: $idx ++;
11800: }
11801: }
11802: }
11803: my %ltihash = (
11804: $action => { %confhash }
11805: );
11806: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,
11807: $dom);
11808: if ($putresult eq 'ok') {
11809: my %ltienchash = (
11810: $action => { %encconfig }
11811: );
11812: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
11813: if (keys(%changes) > 0) {
11814: my $cachetime = 24*60*60;
11815: my %ltiall = %confhash;
11816: foreach my $id (keys(%ltiall)) {
11817: if (ref($encconfig{$id}) eq 'HASH') {
11818: foreach my $item ('key','secret') {
11819: $ltiall{$id}{$item} = $encconfig{$id}{$item};
11820: }
11821: }
11822: }
11823: &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
11824: if (ref($lastactref) eq 'HASH') {
11825: $lastactref->{'lti'} = 1;
11826: }
11827: $resulttext = &mt('Changes made:').'<ul>';
11828: my %bynum;
11829: foreach my $itemid (sort(keys(%changes))) {
11830: my $position = $confhash{$itemid}{'order'};
11831: $bynum{$position} = $itemid;
11832: }
11833: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
11834: my $itemid = $bynum{$pos};
11835: if (ref($confhash{$itemid}) ne 'HASH') {
11836: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
11837: } else {
11838: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b></li><ul>';
11839: my $position = $pos + 1;
11840: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
11841: foreach my $item ('version','lifetime') {
11842: if ($confhash{$itemid}{$item} ne '') {
11843: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
11844: }
11845: }
11846: if ($encconfig{$itemid}{'key'} ne '') {
11847: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
11848: }
11849: if ($encconfig{$itemid}{'secret'} ne '') {
11850: $resulttext .= '<li>'.$lt{'secret'}.': ';
11851: my $num = length($encconfig{$itemid}{'secret'});
11852: $resulttext .= ('*'x$num).'</li>';
11853: }
11854: if ($confhash{$itemid}{'mapuser'}) {
11855: my $shownmapuser;
11856: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
11857: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
11858: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
11859: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
11860: } else {
11861: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
11862: }
11863: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
11864: }
11865: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
11866: my $rolemaps;
11867: foreach my $role (@ltiroles) {
11868: if ($confhash{$itemid}{'maproles'}{$role}) {
11869: $rolemaps .= (' 'x2).$role.'='.
11870: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
11871: 'Course').',';
11872: }
11873: }
11874: if ($rolemaps) {
11875: $rolemaps =~ s/,$//;
11876: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
11877: }
11878: }
11879: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
11880: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
11881: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
1.325 raeburn 11882: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
11883: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
11884: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
11885: } else {
11886: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
11887: $confhash{$itemid}{'lcauth'});
11888: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
11889: $resulttext .= '; '.&mt('a randomly generated password will be created');
11890: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
11891: if ($confhash{$itemid}{'lcauthparm'} ne '') {
11892: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
11893: }
11894: } else {
11895: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
11896: }
11897: }
11898: $resulttext .= '</li>';
1.320 raeburn 11899: } else {
11900: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
11901: }
11902: }
1.325 raeburn 11903: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
11904: if (@{$confhash{$itemid}{'instdata'}} > 0) {
11905: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
11906: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
11907: } else {
11908: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
11909: }
11910: }
1.320 raeburn 11911: if ($confhash{$itemid}{'mapcrs'}) {
11912: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
11913: }
11914: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
11915: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
11916: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
11917: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
11918: '</li>';
11919: } else {
11920: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
11921: }
11922: }
11923: if ($confhash{$itemid}{'makecrs'}) {
11924: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
11925: } else {
11926: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
11927: }
11928: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
11929: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
11930: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
11931: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
11932: '</li>';
11933: } else {
11934: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
11935: }
11936: }
11937: if ($confhash{$itemid}{'section'}) {
11938: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
11939: $resulttext .= '<li>'.&mt('User section from standard field:').
11940: ' (course_section_sourcedid)'.'</li>';
11941: } else {
11942: $resulttext .= '<li>'.&mt('User section from:').' '.
11943: $confhash{$itemid}{'section'}.'</li>';
11944: }
11945: } else {
11946: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
11947: }
1.326 raeburn 11948: foreach my $item ('passback','roster','topmenu','inlinemenu') {
11949: $resulttext .= '<li>'.$lt{$item}.': ';
1.320 raeburn 11950: if ($confhash{$itemid}{$item}) {
11951: $resulttext .= &mt('Yes');
11952: } else {
11953: $resulttext .= &mt('No');
11954: }
11955: $resulttext .= '</li>';
11956: }
1.326 raeburn 11957: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
11958: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
11959: $resulttext .= '<li>'.&mt('Menu items:').' '.
11960: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
11961: } else {
11962: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
11963: }
11964: }
1.320 raeburn 11965: $resulttext .= '</ul></li>';
11966: }
11967: }
11968: $resulttext .= '</ul>';
11969: } else {
11970: $resulttext = &mt('No changes made.');
11971: }
11972: } else {
11973: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
11974: }
11975: if ($errors) {
11976: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11977: $errors.'</ul>';
11978: }
11979: return $resulttext;
11980: }
11981:
11982: sub get_lti_id {
11983: my ($domain,$consumer) = @_;
11984: # get lock on lti db
11985: my $lockhash = {
11986: lock => $env{'user.name'}.
11987: ':'.$env{'user.domain'},
11988: };
11989: my $tries = 0;
11990: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
11991: my ($id,$error);
11992:
11993: while (($gotlock ne 'ok') && ($tries<10)) {
11994: $tries ++;
11995: sleep (0.1);
11996: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
11997: }
11998: if ($gotlock eq 'ok') {
11999: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
12000: if ($currids{'lock'}) {
12001: delete($currids{'lock'});
12002: if (keys(%currids)) {
12003: my @curr = sort { $a <=> $b } keys(%currids);
12004: if ($curr[-1] =~ /^\d+$/) {
12005: $id = 1 + $curr[-1];
12006: }
12007: } else {
12008: $id = 1;
12009: }
12010: if ($id) {
12011: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
12012: $error = 'nostore';
12013: }
12014: } else {
12015: $error = 'nonumber';
12016: }
12017: }
12018: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
12019: } else {
12020: $error = 'nolock';
12021: }
12022: return ($id,$error);
12023: }
12024:
1.3 raeburn 12025: sub modify_autoenroll {
1.205 raeburn 12026: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 12027: my ($resulttext,%changes);
12028: my %currautoenroll;
12029: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
12030: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
12031: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
12032: }
12033: }
12034: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
12035: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 12036: sender => 'Sender for notification messages',
1.274 raeburn 12037: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
12038: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 12039: my @offon = ('off','on');
1.17 raeburn 12040: my $sender_uname = $env{'form.sender_uname'};
12041: my $sender_domain = $env{'form.sender_domain'};
12042: if ($sender_domain eq '') {
12043: $sender_uname = '';
12044: } elsif ($sender_uname eq '') {
12045: $sender_domain = '';
12046: }
1.129 raeburn 12047: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 12048: my $failsafe = $env{'form.autoenroll_failsafe'};
12049: $failsafe =~ s{^\s+|\s+$}{}g;
12050: if ($failsafe =~ /\D/) {
12051: undef($failsafe);
12052: }
1.1 raeburn 12053: my %autoenrollhash = (
1.129 raeburn 12054: autoenroll => { 'run' => $env{'form.autoenroll_run'},
12055: 'sender_uname' => $sender_uname,
12056: 'sender_domain' => $sender_domain,
12057: 'co-owners' => $coowners,
1.274 raeburn 12058: 'autofailsafe' => $failsafe,
1.1 raeburn 12059: }
12060: );
1.4 raeburn 12061: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
12062: $dom);
1.1 raeburn 12063: if ($putresult eq 'ok') {
12064: if (exists($currautoenroll{'run'})) {
12065: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
12066: $changes{'run'} = 1;
12067: }
12068: } elsif ($autorun) {
12069: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 12070: $changes{'run'} = 1;
1.1 raeburn 12071: }
12072: }
1.17 raeburn 12073: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 12074: $changes{'sender'} = 1;
12075: }
1.17 raeburn 12076: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 12077: $changes{'sender'} = 1;
12078: }
1.129 raeburn 12079: if ($currautoenroll{'co-owners'} ne '') {
12080: if ($currautoenroll{'co-owners'} ne $coowners) {
12081: $changes{'coowners'} = 1;
12082: }
12083: } elsif ($coowners) {
12084: $changes{'coowners'} = 1;
1.274 raeburn 12085: }
12086: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
12087: $changes{'autofailsafe'} = 1;
12088: }
1.1 raeburn 12089: if (keys(%changes) > 0) {
12090: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 12091: if ($changes{'run'}) {
1.1 raeburn 12092: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
12093: }
12094: if ($changes{'sender'}) {
1.17 raeburn 12095: if ($sender_uname eq '' || $sender_domain eq '') {
12096: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
12097: } else {
12098: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
12099: }
1.1 raeburn 12100: }
1.129 raeburn 12101: if ($changes{'coowners'}) {
12102: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
12103: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12104: if (ref($lastactref) eq 'HASH') {
12105: $lastactref->{'domainconfig'} = 1;
12106: }
1.129 raeburn 12107: }
1.274 raeburn 12108: if ($changes{'autofailsafe'}) {
12109: if ($failsafe ne '') {
1.299 raeburn 12110: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274 raeburn 12111: } else {
1.299 raeburn 12112: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274 raeburn 12113: }
12114: &Apache::lonnet::get_domain_defaults($dom,1);
12115: if (ref($lastactref) eq 'HASH') {
12116: $lastactref->{'domdefaults'} = 1;
12117: }
12118: }
1.1 raeburn 12119: $resulttext .= '</ul>';
12120: } else {
12121: $resulttext = &mt('No changes made to auto-enrollment settings');
12122: }
12123: } else {
1.11 albertel 12124: $resulttext = '<span class="LC_error">'.
12125: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12126: }
1.3 raeburn 12127: return $resulttext;
1.1 raeburn 12128: }
12129:
12130: sub modify_autoupdate {
1.3 raeburn 12131: my ($dom,%domconfig) = @_;
1.1 raeburn 12132: my ($resulttext,%currautoupdate,%fields,%changes);
12133: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
12134: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
12135: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
12136: }
12137: }
12138: my @offon = ('off','on');
12139: my %title = &Apache::lonlocal::texthash (
12140: run => 'Auto-update:',
12141: classlists => 'Updates to user information in classlists?'
12142: );
1.44 raeburn 12143: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 12144: my %fieldtitles = &Apache::lonlocal::texthash (
12145: id => 'Student/Employee ID',
1.20 raeburn 12146: permanentemail => 'E-mail address',
1.1 raeburn 12147: lastname => 'Last Name',
12148: firstname => 'First Name',
12149: middlename => 'Middle Name',
1.132 raeburn 12150: generation => 'Generation',
1.1 raeburn 12151: );
1.142 raeburn 12152: $othertitle = &mt('All users');
1.1 raeburn 12153: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 12154: $othertitle = &mt('Other users');
1.1 raeburn 12155: }
12156: foreach my $key (keys(%env)) {
12157: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 12158: my ($usertype,$item) = ($1,$2);
12159: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
12160: if ($usertype eq 'default') {
12161: push(@{$fields{$1}},$2);
12162: } elsif (ref($types) eq 'ARRAY') {
12163: if (grep(/^\Q$usertype\E$/,@{$types})) {
12164: push(@{$fields{$1}},$2);
12165: }
12166: }
12167: }
1.1 raeburn 12168: }
12169: }
1.131 raeburn 12170: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
12171: @lockablenames = sort(@lockablenames);
12172: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
12173: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
12174: if (@changed) {
12175: $changes{'lockablenames'} = 1;
12176: }
12177: } else {
12178: if (@lockablenames) {
12179: $changes{'lockablenames'} = 1;
12180: }
12181: }
1.1 raeburn 12182: my %updatehash = (
12183: autoupdate => { run => $env{'form.autoupdate_run'},
12184: classlists => $env{'form.classlists'},
12185: fields => {%fields},
1.131 raeburn 12186: lockablenames => \@lockablenames,
1.1 raeburn 12187: }
12188: );
12189: foreach my $key (keys(%currautoupdate)) {
12190: if (($key eq 'run') || ($key eq 'classlists')) {
12191: if (exists($updatehash{autoupdate}{$key})) {
12192: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
12193: $changes{$key} = 1;
12194: }
12195: }
12196: } elsif ($key eq 'fields') {
12197: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 12198: foreach my $item (@{$types},'default') {
1.1 raeburn 12199: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
12200: my $change = 0;
12201: foreach my $type (@{$currautoupdate{$key}{$item}}) {
12202: if (!exists($fields{$item})) {
12203: $change = 1;
1.132 raeburn 12204: last;
1.1 raeburn 12205: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 12206: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 12207: $change = 1;
1.132 raeburn 12208: last;
1.1 raeburn 12209: }
12210: }
12211: }
12212: if ($change) {
12213: push(@{$changes{$key}},$item);
12214: }
1.26 raeburn 12215: }
1.1 raeburn 12216: }
12217: }
1.131 raeburn 12218: } elsif ($key eq 'lockablenames') {
12219: if (ref($currautoupdate{$key}) eq 'ARRAY') {
12220: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
12221: if (@changed) {
12222: $changes{'lockablenames'} = 1;
12223: }
12224: } else {
12225: if (@lockablenames) {
12226: $changes{'lockablenames'} = 1;
12227: }
12228: }
12229: }
12230: }
12231: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
12232: if (@lockablenames) {
12233: $changes{'lockablenames'} = 1;
1.1 raeburn 12234: }
12235: }
1.26 raeburn 12236: foreach my $item (@{$types},'default') {
12237: if (defined($fields{$item})) {
12238: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 12239: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
12240: my $change = 0;
12241: if (ref($fields{$item}) eq 'ARRAY') {
12242: foreach my $type (@{$fields{$item}}) {
12243: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
12244: $change = 1;
12245: last;
12246: }
12247: }
12248: }
12249: if ($change) {
12250: push(@{$changes{'fields'}},$item);
12251: }
12252: } else {
1.26 raeburn 12253: push(@{$changes{'fields'}},$item);
12254: }
12255: } else {
12256: push(@{$changes{'fields'}},$item);
1.1 raeburn 12257: }
12258: }
12259: }
12260: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
12261: $dom);
12262: if ($putresult eq 'ok') {
12263: if (keys(%changes) > 0) {
12264: $resulttext = &mt('Changes made:').'<ul>';
12265: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 12266: if ($key eq 'lockablenames') {
12267: $resulttext .= '<li>';
12268: if (@lockablenames) {
12269: $usertypes->{'default'} = $othertitle;
12270: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
12271: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
12272: } else {
12273: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
12274: }
12275: $resulttext .= '</li>';
12276: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 12277: foreach my $item (@{$changes{$key}}) {
12278: my @newvalues;
12279: foreach my $type (@{$fields{$item}}) {
12280: push(@newvalues,$fieldtitles{$type});
12281: }
1.3 raeburn 12282: my $newvaluestr;
12283: if (@newvalues > 0) {
12284: $newvaluestr = join(', ',@newvalues);
12285: } else {
12286: $newvaluestr = &mt('none');
1.6 raeburn 12287: }
1.1 raeburn 12288: if ($item eq 'default') {
1.26 raeburn 12289: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 12290: } else {
1.26 raeburn 12291: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 12292: }
12293: }
12294: } else {
12295: my $newvalue;
12296: if ($key eq 'run') {
12297: $newvalue = $offon[$env{'form.autoupdate_run'}];
12298: } else {
12299: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 12300: }
1.1 raeburn 12301: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
12302: }
12303: }
12304: $resulttext .= '</ul>';
12305: } else {
1.3 raeburn 12306: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 12307: }
12308: } else {
1.11 albertel 12309: $resulttext = '<span class="LC_error">'.
12310: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12311: }
1.3 raeburn 12312: return $resulttext;
1.1 raeburn 12313: }
12314:
1.125 raeburn 12315: sub modify_autocreate {
12316: my ($dom,%domconfig) = @_;
12317: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
12318: if (ref($domconfig{'autocreate'}) eq 'HASH') {
12319: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
12320: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
12321: }
12322: }
12323: my %title= ( xml => 'Auto-creation of courses in XML course description files',
12324: req => 'Auto-creation of validated requests for official courses',
12325: xmldc => 'Identity of course creator of courses from XML files',
12326: );
12327: my @types = ('xml','req');
12328: foreach my $item (@types) {
12329: $newvals{$item} = $env{'form.autocreate_'.$item};
12330: $newvals{$item} =~ s/\D//g;
12331: $newvals{$item} = 0 if ($newvals{$item} eq '');
12332: }
12333: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 12334: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 12335: unless (exists($domcoords{$newvals{'xmldc'}})) {
12336: $newvals{'xmldc'} = '';
12337: }
12338: %autocreatehash = (
12339: autocreate => { xml => $newvals{'xml'},
12340: req => $newvals{'req'},
12341: }
12342: );
12343: if ($newvals{'xmldc'} ne '') {
12344: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
12345: }
12346: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
12347: $dom);
12348: if ($putresult eq 'ok') {
12349: my @items = @types;
12350: if ($newvals{'xml'}) {
12351: push(@items,'xmldc');
12352: }
12353: foreach my $item (@items) {
12354: if (exists($currautocreate{$item})) {
12355: if ($currautocreate{$item} ne $newvals{$item}) {
12356: $changes{$item} = 1;
12357: }
12358: } elsif ($newvals{$item}) {
12359: $changes{$item} = 1;
12360: }
12361: }
12362: if (keys(%changes) > 0) {
12363: my @offon = ('off','on');
12364: $resulttext = &mt('Changes made:').'<ul>';
12365: foreach my $item (@types) {
12366: if ($changes{$item}) {
12367: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 12368: $resulttext .= '<li>'.
12369: &mt("$title{$item} set to [_1]$newtxt [_2]",
12370: '<b>','</b>').
12371: '</li>';
1.125 raeburn 12372: }
12373: }
12374: if ($changes{'xmldc'}) {
12375: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
12376: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 12377: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 12378: }
12379: $resulttext .= '</ul>';
12380: } else {
12381: $resulttext = &mt('No changes made to auto-creation settings');
12382: }
12383: } else {
12384: $resulttext = '<span class="LC_error">'.
12385: &mt('An error occurred: [_1]',$putresult).'</span>';
12386: }
12387: return $resulttext;
12388: }
12389:
1.23 raeburn 12390: sub modify_directorysrch {
1.295 raeburn 12391: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 12392: my ($resulttext,%changes);
12393: my %currdirsrch;
12394: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
12395: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
12396: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
12397: }
12398: }
1.277 raeburn 12399: my %title = ( available => 'Institutional directory search available',
12400: localonly => 'Other domains can search institution',
12401: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 12402: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 12403: searchby => 'Search types',
12404: searchtypes => 'Search latitude');
12405: my @offon = ('off','on');
1.24 raeburn 12406: my @otherdoms = ('Yes','No');
1.23 raeburn 12407:
1.25 raeburn 12408: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 12409: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
12410: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
12411:
1.44 raeburn 12412: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 12413: if (keys(%{$usertypes}) == 0) {
12414: @cansearch = ('default');
12415: } else {
12416: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
12417: foreach my $type (@{$currdirsrch{'cansearch'}}) {
12418: if (!grep(/^\Q$type\E$/,@cansearch)) {
12419: push(@{$changes{'cansearch'}},$type);
12420: }
1.23 raeburn 12421: }
1.26 raeburn 12422: foreach my $type (@cansearch) {
12423: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
12424: push(@{$changes{'cansearch'}},$type);
12425: }
1.23 raeburn 12426: }
1.26 raeburn 12427: } else {
12428: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 12429: }
12430: }
12431:
12432: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
12433: foreach my $by (@{$currdirsrch{'searchby'}}) {
12434: if (!grep(/^\Q$by\E$/,@searchby)) {
12435: push(@{$changes{'searchby'}},$by);
12436: }
12437: }
12438: foreach my $by (@searchby) {
12439: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
12440: push(@{$changes{'searchby'}},$by);
12441: }
12442: }
12443: } else {
12444: push(@{$changes{'searchby'}},@searchby);
12445: }
1.25 raeburn 12446:
12447: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
12448: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
12449: if (!grep(/^\Q$type\E$/,@searchtypes)) {
12450: push(@{$changes{'searchtypes'}},$type);
12451: }
12452: }
12453: foreach my $type (@searchtypes) {
12454: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
12455: push(@{$changes{'searchtypes'}},$type);
12456: }
12457: }
12458: } else {
12459: if (exists($currdirsrch{'searchtypes'})) {
12460: foreach my $type (@searchtypes) {
12461: if ($type ne $currdirsrch{'searchtypes'}) {
12462: push(@{$changes{'searchtypes'}},$type);
12463: }
12464: }
12465: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
12466: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
12467: }
12468: } else {
12469: push(@{$changes{'searchtypes'}},@searchtypes);
12470: }
12471: }
12472:
1.23 raeburn 12473: my %dirsrch_hash = (
12474: directorysrch => { available => $env{'form.dirsrch_available'},
12475: cansearch => \@cansearch,
1.277 raeburn 12476: localonly => $env{'form.dirsrch_instlocalonly'},
12477: lclocalonly => $env{'form.dirsrch_domlocalonly'},
12478: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 12479: searchby => \@searchby,
1.25 raeburn 12480: searchtypes => \@searchtypes,
1.23 raeburn 12481: }
12482: );
12483: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
12484: $dom);
12485: if ($putresult eq 'ok') {
12486: if (exists($currdirsrch{'available'})) {
12487: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
12488: $changes{'available'} = 1;
12489: }
12490: } else {
12491: if ($env{'form.dirsrch_available'} eq '1') {
12492: $changes{'available'} = 1;
12493: }
12494: }
1.277 raeburn 12495: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 12496: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
12497: $changes{'lcavailable'} = 1;
12498: }
1.277 raeburn 12499: } else {
12500: if ($env{'form.dirsrch_lcavailable'} eq '1') {
12501: $changes{'lcavailable'} = 1;
12502: }
12503: }
1.24 raeburn 12504: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 12505: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
12506: $changes{'localonly'} = 1;
12507: }
1.24 raeburn 12508: } else {
1.277 raeburn 12509: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 12510: $changes{'localonly'} = 1;
12511: }
12512: }
1.277 raeburn 12513: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 12514: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
12515: $changes{'lclocalonly'} = 1;
12516: }
1.277 raeburn 12517: } else {
12518: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
12519: $changes{'lclocalonly'} = 1;
12520: }
12521: }
1.23 raeburn 12522: if (keys(%changes) > 0) {
12523: $resulttext = &mt('Changes made:').'<ul>';
12524: if ($changes{'available'}) {
12525: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
12526: }
1.277 raeburn 12527: if ($changes{'lcavailable'}) {
12528: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
12529: }
1.24 raeburn 12530: if ($changes{'localonly'}) {
1.277 raeburn 12531: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 12532: }
1.277 raeburn 12533: if ($changes{'lclocalonly'}) {
12534: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 12535: }
1.23 raeburn 12536: if (ref($changes{'cansearch'}) eq 'ARRAY') {
12537: my $chgtext;
1.26 raeburn 12538: if (ref($usertypes) eq 'HASH') {
12539: if (keys(%{$usertypes}) > 0) {
12540: foreach my $type (@{$types}) {
12541: if (grep(/^\Q$type\E$/,@cansearch)) {
12542: $chgtext .= $usertypes->{$type}.'; ';
12543: }
12544: }
12545: if (grep(/^default$/,@cansearch)) {
12546: $chgtext .= $othertitle;
12547: } else {
12548: $chgtext =~ s/\; $//;
12549: }
1.210 raeburn 12550: $resulttext .=
1.178 raeburn 12551: '<li>'.
12552: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
12553: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
12554: '</li>';
1.23 raeburn 12555: }
12556: }
12557: }
12558: if (ref($changes{'searchby'}) eq 'ARRAY') {
12559: my ($searchtitles,$titleorder) = &sorted_searchtitles();
12560: my $chgtext;
12561: foreach my $type (@{$titleorder}) {
12562: if (grep(/^\Q$type\E$/,@searchby)) {
12563: if (defined($searchtitles->{$type})) {
12564: $chgtext .= $searchtitles->{$type}.'; ';
12565: }
12566: }
12567: }
12568: $chgtext =~ s/\; $//;
12569: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
12570: }
1.25 raeburn 12571: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
12572: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
12573: my $chgtext;
12574: foreach my $type (@{$srchtypeorder}) {
12575: if (grep(/^\Q$type\E$/,@searchtypes)) {
12576: if (defined($srchtypes_desc->{$type})) {
12577: $chgtext .= $srchtypes_desc->{$type}.'; ';
12578: }
12579: }
12580: }
12581: $chgtext =~ s/\; $//;
1.178 raeburn 12582: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 12583: }
12584: $resulttext .= '</ul>';
1.295 raeburn 12585: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
12586: if (ref($lastactref) eq 'HASH') {
12587: $lastactref->{'directorysrch'} = 1;
12588: }
1.23 raeburn 12589: } else {
1.277 raeburn 12590: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 12591: }
12592: } else {
12593: $resulttext = '<span class="LC_error">'.
1.27 raeburn 12594: &mt('An error occurred: [_1]',$putresult).'</span>';
12595: }
12596: return $resulttext;
12597: }
12598:
1.28 raeburn 12599: sub modify_contacts {
1.205 raeburn 12600: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 12601: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
12602: if (ref($domconfig{'contacts'}) eq 'HASH') {
12603: foreach my $key (keys(%{$domconfig{'contacts'}})) {
12604: $currsetting{$key} = $domconfig{'contacts'}{$key};
12605: }
12606: }
1.286 raeburn 12607: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 12608: my @contacts = ('supportemail','adminemail');
1.286 raeburn 12609: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
12610: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.203 raeburn 12611: my @toggles = ('reporterrors','reportupdates');
1.286 raeburn 12612: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 12613: foreach my $type (@mailings) {
12614: @{$newsetting{$type}} =
12615: &Apache::loncommon::get_env_multiple('form.'.$type);
12616: foreach my $item (@contacts) {
12617: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
12618: $contacts_hash{contacts}{$type}{$item} = 1;
12619: } else {
12620: $contacts_hash{contacts}{$type}{$item} = 0;
12621: }
1.289 raeburn 12622: }
1.28 raeburn 12623: $others{$type} = $env{'form.'.$type.'_others'};
12624: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 12625: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12626: $bcc{$type} = $env{'form.'.$type.'_bcc'};
12627: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 12628: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
12629: $includestr{$type} = $env{'form.'.$type.'_includestr'};
12630: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
12631: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
12632: }
1.134 raeburn 12633: }
1.28 raeburn 12634: }
12635: foreach my $item (@contacts) {
12636: $to{$item} = $env{'form.'.$item};
12637: $contacts_hash{'contacts'}{$item} = $to{$item};
12638: }
1.203 raeburn 12639: foreach my $item (@toggles) {
12640: if ($env{'form.'.$item} =~ /^(0|1)$/) {
12641: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
12642: }
12643: }
1.286 raeburn 12644: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
12645: foreach my $field (@{$fields}) {
12646: if (ref($possoptions->{$field}) eq 'ARRAY') {
12647: my $value = $env{'form.helpform_'.$field};
12648: $value =~ s/^\s+|\s+$//g;
12649: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 12650: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 12651: if ($field eq 'screenshot') {
12652: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
12653: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 12654: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 12655: }
12656: }
12657: }
12658: }
12659: }
12660: }
1.315 raeburn 12661: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12662: my (@statuses,%usertypeshash,@overrides);
12663: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
12664: @statuses = @{$types};
12665: if (ref($usertypes) eq 'HASH') {
12666: %usertypeshash = %{$usertypes};
12667: }
12668: }
12669: if (@statuses) {
12670: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
12671: foreach my $type (@possoverrides) {
12672: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
12673: push(@overrides,$type);
12674: }
12675: }
12676: if (@overrides) {
12677: foreach my $type (@overrides) {
12678: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
12679: foreach my $item (@contacts) {
12680: if (grep(/^\Q$item\E$/,@standard)) {
12681: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
12682: $newsetting{'override_'.$type}{$item} = 1;
12683: } else {
12684: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
12685: $newsetting{'override_'.$type}{$item} = 0;
12686: }
12687: }
12688: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
12689: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
12690: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
12691: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
12692: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
12693: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
12694: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
12695: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
12696: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
12697: }
12698: }
12699: }
12700: }
1.28 raeburn 12701: if (keys(%currsetting) > 0) {
12702: foreach my $item (@contacts) {
12703: if ($to{$item} ne $currsetting{$item}) {
12704: $changes{$item} = 1;
12705: }
12706: }
12707: foreach my $type (@mailings) {
12708: foreach my $item (@contacts) {
12709: if (ref($currsetting{$type}) eq 'HASH') {
12710: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
12711: push(@{$changes{$type}},$item);
12712: }
12713: } else {
12714: push(@{$changes{$type}},@{$newsetting{$type}});
12715: }
12716: }
12717: if ($others{$type} ne $currsetting{$type}{'others'}) {
12718: push(@{$changes{$type}},'others');
12719: }
1.289 raeburn 12720: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12721: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
12722: push(@{$changes{$type}},'bcc');
12723: }
1.286 raeburn 12724: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
12725: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
12726: push(@{$changes{$type}},'include');
12727: }
12728: }
12729: }
12730: if (ref($fields) eq 'ARRAY') {
12731: if (ref($currsetting{'helpform'}) eq 'HASH') {
12732: foreach my $field (@{$fields}) {
12733: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
12734: push(@{$changes{'helpform'}},$field);
12735: }
12736: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12737: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
12738: push(@{$changes{'helpform'}},'maxsize');
12739: }
12740: }
12741: }
12742: } else {
12743: foreach my $field (@{$fields}) {
12744: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12745: push(@{$changes{'helpform'}},$field);
12746: }
12747: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12748: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12749: push(@{$changes{'helpform'}},'maxsize');
12750: }
12751: }
12752: }
1.134 raeburn 12753: }
1.28 raeburn 12754: }
1.315 raeburn 12755: if (@statuses) {
12756: if (ref($currsetting{'overrides'}) eq 'HASH') {
12757: foreach my $key (keys(%{$currsetting{'overrides'}})) {
12758: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
12759: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
12760: foreach my $item (@contacts,'bcc','others','include') {
12761: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
12762: push(@{$changes{'overrides'}},$key);
12763: last;
12764: }
12765: }
12766: } else {
12767: push(@{$changes{'overrides'}},$key);
12768: }
12769: }
12770: }
12771: foreach my $key (@overrides) {
12772: unless (exists($currsetting{'overrides'}{$key})) {
12773: push(@{$changes{'overrides'}},$key);
12774: }
12775: }
12776: } else {
12777: foreach my $key (@overrides) {
12778: push(@{$changes{'overrides'}},$key);
12779: }
12780: }
12781: }
1.28 raeburn 12782: } else {
12783: my %default;
12784: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
12785: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
12786: $default{'errormail'} = 'adminemail';
12787: $default{'packagesmail'} = 'adminemail';
12788: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 12789: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 12790: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 12791: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 12792: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 12793: foreach my $item (@contacts) {
12794: if ($to{$item} ne $default{$item}) {
1.286 raeburn 12795: $changes{$item} = 1;
1.203 raeburn 12796: }
1.28 raeburn 12797: }
12798: foreach my $type (@mailings) {
12799: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
12800: push(@{$changes{$type}},@{$newsetting{$type}});
12801: }
12802: if ($others{$type} ne '') {
12803: push(@{$changes{$type}},'others');
1.134 raeburn 12804: }
1.286 raeburn 12805: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12806: if ($bcc{$type} ne '') {
12807: push(@{$changes{$type}},'bcc');
12808: }
1.286 raeburn 12809: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
12810: push(@{$changes{$type}},'include');
12811: }
1.134 raeburn 12812: }
1.28 raeburn 12813: }
1.286 raeburn 12814: if (ref($fields) eq 'ARRAY') {
12815: foreach my $field (@{$fields}) {
12816: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12817: push(@{$changes{'helpform'}},$field);
12818: }
12819: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12820: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12821: push(@{$changes{'helpform'}},'maxsize');
12822: }
12823: }
12824: }
1.289 raeburn 12825: }
1.28 raeburn 12826: }
1.203 raeburn 12827: foreach my $item (@toggles) {
12828: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
12829: $changes{$item} = 1;
12830: } elsif ((!$env{'form.'.$item}) &&
12831: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
12832: $changes{$item} = 1;
12833: }
12834: }
1.28 raeburn 12835: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
12836: $dom);
12837: if ($putresult eq 'ok') {
12838: if (keys(%changes) > 0) {
1.205 raeburn 12839: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12840: if (ref($lastactref) eq 'HASH') {
12841: $lastactref->{'domainconfig'} = 1;
12842: }
1.28 raeburn 12843: my ($titles,$short_titles) = &contact_titles();
12844: $resulttext = &mt('Changes made:').'<ul>';
12845: foreach my $item (@contacts) {
12846: if ($changes{$item}) {
12847: $resulttext .= '<li>'.$titles->{$item}.
12848: &mt(' set to: ').
12849: '<span class="LC_cusr_emph">'.
12850: $to{$item}.'</span></li>';
12851: }
12852: }
12853: foreach my $type (@mailings) {
12854: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 12855: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 12856: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 12857: } else {
12858: $resulttext .= '<li>'.$titles->{$type}.': ';
12859: }
1.28 raeburn 12860: my @text;
12861: foreach my $item (@{$newsetting{$type}}) {
12862: push(@text,$short_titles->{$item});
12863: }
12864: if ($others{$type} ne '') {
12865: push(@text,$others{$type});
12866: }
1.286 raeburn 12867: if (@text) {
12868: $resulttext .= '<span class="LC_cusr_emph">'.
12869: join(', ',@text).'</span>';
12870: }
12871: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12872: if ($bcc{$type} ne '') {
1.286 raeburn 12873: my $bcctext;
12874: if (@text) {
1.289 raeburn 12875: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 12876: } else {
12877: $bcctext = '(Bcc)';
12878: }
12879: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
12880: } elsif (!@text) {
12881: $resulttext .= &mt('No one');
12882: }
1.289 raeburn 12883: if ($includestr{$type} ne '') {
1.286 raeburn 12884: if ($includeloc{$type} eq 'b') {
12885: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
12886: } elsif ($includeloc{$type} eq 's') {
12887: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
12888: }
1.134 raeburn 12889: }
1.286 raeburn 12890: } elsif (!@text) {
12891: $resulttext .= &mt('No recipients');
1.134 raeburn 12892: }
12893: $resulttext .= '</li>';
1.28 raeburn 12894: }
12895: }
1.315 raeburn 12896: if (ref($changes{'overrides'}) eq 'ARRAY') {
12897: my @deletions;
12898: foreach my $type (@{$changes{'overrides'}}) {
12899: if ($usertypeshash{$type}) {
12900: if (grep(/^\Q$type\E/,@overrides)) {
12901: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
12902: $usertypeshash{$type}).'<ul><li>';
12903: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
12904: my @text;
12905: foreach my $item (@contacts) {
12906: if ($newsetting{'override_'.$type}{$item}) {
12907: push(@text,$short_titles->{$item});
12908: }
12909: }
12910: if ($newsetting{'override_'.$type}{'others'} ne '') {
12911: push(@text,$newsetting{'override_'.$type}{'others'});
12912: }
12913:
12914: if (@text) {
12915: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
12916: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
12917: }
12918: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
12919: my $bcctext;
12920: if (@text) {
12921: $bcctext = ' '.&mt('with Bcc to');
12922: } else {
12923: $bcctext = '(Bcc)';
12924: }
12925: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
12926: } elsif (!@text) {
12927: $resulttext .= &mt('Helpdesk e-mail sent to no one');
12928: }
12929: $resulttext .= '</li>';
12930: if ($newsetting{'override_'.$type}{'include'} ne '') {
12931: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
12932: if ($loc eq 'b') {
12933: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
12934: } elsif ($loc eq 's') {
12935: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
12936: }
12937: }
12938: }
12939: $resulttext .= '</li></ul></li>';
12940: } else {
12941: push(@deletions,$usertypeshash{$type});
12942: }
12943: }
12944: }
12945: if (@deletions) {
12946: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
12947: join(', ',@deletions)).'</li>';
12948: }
12949: }
1.203 raeburn 12950: my @offon = ('off','on');
12951: if ($changes{'reporterrors'}) {
12952: $resulttext .= '<li>'.
12953: &mt('E-mail error reports to [_1] set to "'.
12954: $offon[$env{'form.reporterrors'}].'".',
12955: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
12956: &mt('LON-CAPA core group - MSU'),600,500)).
12957: '</li>';
12958: }
12959: if ($changes{'reportupdates'}) {
12960: $resulttext .= '<li>'.
12961: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
12962: $offon[$env{'form.reportupdates'}].'".',
12963: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
12964: &mt('LON-CAPA core group - MSU'),600,500)).
12965: '</li>';
12966: }
1.286 raeburn 12967: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
12968: my (@optional,@required,@unused,$maxsizechg);
12969: foreach my $field (@{$changes{'helpform'}}) {
12970: if ($field eq 'maxsize') {
12971: $maxsizechg = 1;
12972: next;
12973: }
12974: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 12975: push(@optional,$field);
1.286 raeburn 12976: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
12977: push(@unused,$field);
12978: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 12979: push(@required,$field);
1.286 raeburn 12980: }
12981: }
12982: if (@optional) {
12983: $resulttext .= '<li>'.
12984: &mt('Help form fields changed to "Optional": [_1].',
12985: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
12986: '</li>';
12987: }
12988: if (@required) {
12989: $resulttext .= '<li>'.
12990: &mt('Help form fields changed to "Required": [_1].',
12991: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
12992: '</li>';
12993: }
12994: if (@unused) {
12995: $resulttext .= '<li>'.
12996: &mt('Help form fields changed to "Not shown": [_1].',
12997: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
12998: '</li>';
12999: }
13000: if ($maxsizechg) {
13001: $resulttext .= '<li>'.
13002: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
13003: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
13004: '</li>';
13005: }
13006: }
1.28 raeburn 13007: $resulttext .= '</ul>';
13008: } else {
1.288 raeburn 13009: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 13010: }
13011: } else {
13012: $resulttext = '<span class="LC_error">'.
13013: &mt('An error occurred: [_1].',$putresult).'</span>';
13014: }
13015: return $resulttext;
13016: }
13017:
13018: sub modify_usercreation {
1.27 raeburn 13019: my ($dom,%domconfig) = @_;
1.224 raeburn 13020: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 13021: my $warningmsg;
1.27 raeburn 13022: if (ref($domconfig{'usercreation'}) eq 'HASH') {
13023: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 13024: if ($key eq 'cancreate') {
13025: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
13026: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 13027: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
13028: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13029: } else {
1.224 raeburn 13030: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13031: }
13032: }
13033: }
13034: } elsif ($key eq 'email_rule') {
13035: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
13036: } else {
13037: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
13038: }
1.27 raeburn 13039: }
13040: }
13041: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 13042: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 13043: my @contexts = ('author','course','requestcrs');
1.34 raeburn 13044: foreach my $item(@contexts) {
1.224 raeburn 13045: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 13046: }
1.34 raeburn 13047: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13048: foreach my $item (@contexts) {
1.224 raeburn 13049: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
13050: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 13051: }
1.27 raeburn 13052: }
1.34 raeburn 13053: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
13054: foreach my $item (@contexts) {
1.43 raeburn 13055: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 13056: if ($cancreate{$item} ne 'any') {
13057: push(@{$changes{'cancreate'}},$item);
13058: }
13059: } else {
13060: if ($cancreate{$item} ne 'none') {
13061: push(@{$changes{'cancreate'}},$item);
13062: }
1.27 raeburn 13063: }
13064: }
13065: } else {
1.43 raeburn 13066: foreach my $item (@contexts) {
1.34 raeburn 13067: push(@{$changes{'cancreate'}},$item);
13068: }
1.27 raeburn 13069: }
1.34 raeburn 13070:
1.27 raeburn 13071: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
13072: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
13073: if (!grep(/^\Q$type\E$/,@username_rule)) {
13074: push(@{$changes{'username_rule'}},$type);
13075: }
13076: }
13077: foreach my $type (@username_rule) {
13078: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
13079: push(@{$changes{'username_rule'}},$type);
13080: }
13081: }
13082: } else {
13083: push(@{$changes{'username_rule'}},@username_rule);
13084: }
13085:
1.32 raeburn 13086: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
13087: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
13088: if (!grep(/^\Q$type\E$/,@id_rule)) {
13089: push(@{$changes{'id_rule'}},$type);
13090: }
13091: }
13092: foreach my $type (@id_rule) {
13093: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
13094: push(@{$changes{'id_rule'}},$type);
13095: }
13096: }
13097: } else {
13098: push(@{$changes{'id_rule'}},@id_rule);
13099: }
13100:
1.43 raeburn 13101: my @authen_contexts = ('author','course','domain');
1.325 raeburn 13102: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 13103: my %authhash;
1.43 raeburn 13104: foreach my $item (@authen_contexts) {
1.28 raeburn 13105: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
13106: foreach my $auth (@authtypes) {
13107: if (grep(/^\Q$auth\E$/,@authallowed)) {
13108: $authhash{$item}{$auth} = 1;
13109: } else {
13110: $authhash{$item}{$auth} = 0;
13111: }
13112: }
13113: }
13114: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 13115: foreach my $item (@authen_contexts) {
1.28 raeburn 13116: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
13117: foreach my $auth (@authtypes) {
13118: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
13119: push(@{$changes{'authtypes'}},$item);
13120: last;
13121: }
13122: }
13123: }
13124: }
13125: } else {
1.43 raeburn 13126: foreach my $item (@authen_contexts) {
1.28 raeburn 13127: push(@{$changes{'authtypes'}},$item);
13128: }
13129: }
13130:
1.224 raeburn 13131: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
13132: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
13133: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
13134: $save_usercreate{'id_rule'} = \@id_rule;
13135: $save_usercreate{'username_rule'} = \@username_rule,
13136: $save_usercreate{'authtypes'} = \%authhash;
13137:
1.27 raeburn 13138: my %usercreation_hash = (
1.224 raeburn 13139: usercreation => \%save_usercreate,
13140: );
1.27 raeburn 13141:
13142: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
13143: $dom);
1.50 raeburn 13144:
1.224 raeburn 13145: if ($putresult eq 'ok') {
13146: if (keys(%changes) > 0) {
13147: $resulttext = &mt('Changes made:').'<ul>';
13148: if (ref($changes{'cancreate'}) eq 'ARRAY') {
13149: my %lt = &usercreation_types();
13150: foreach my $type (@{$changes{'cancreate'}}) {
13151: my $chgtext = $lt{$type}.', ';
13152: if ($cancreate{$type} eq 'none') {
13153: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
13154: } elsif ($cancreate{$type} eq 'any') {
13155: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
13156: } elsif ($cancreate{$type} eq 'official') {
13157: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
13158: } elsif ($cancreate{$type} eq 'unofficial') {
13159: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
13160: }
13161: $resulttext .= '<li>'.$chgtext.'</li>';
13162: }
13163: }
13164: if (ref($changes{'username_rule'}) eq 'ARRAY') {
13165: my ($rules,$ruleorder) =
13166: &Apache::lonnet::inst_userrules($dom,'username');
13167: my $chgtext = '<ul>';
13168: foreach my $type (@username_rule) {
13169: if (ref($rules->{$type}) eq 'HASH') {
13170: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
13171: }
13172: }
13173: $chgtext .= '</ul>';
13174: if (@username_rule > 0) {
13175: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13176: } else {
13177: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
13178: }
13179: }
13180: if (ref($changes{'id_rule'}) eq 'ARRAY') {
13181: my ($idrules,$idruleorder) =
13182: &Apache::lonnet::inst_userrules($dom,'id');
13183: my $chgtext = '<ul>';
13184: foreach my $type (@id_rule) {
13185: if (ref($idrules->{$type}) eq 'HASH') {
13186: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
13187: }
13188: }
13189: $chgtext .= '</ul>';
13190: if (@id_rule > 0) {
13191: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13192: } else {
13193: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
13194: }
13195: }
13196: my %authname = &authtype_names();
13197: my %context_title = &context_names();
13198: if (ref($changes{'authtypes'}) eq 'ARRAY') {
13199: my $chgtext = '<ul>';
13200: foreach my $type (@{$changes{'authtypes'}}) {
13201: my @allowed;
13202: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
13203: foreach my $auth (@authtypes) {
13204: if ($authhash{$type}{$auth}) {
13205: push(@allowed,$authname{$auth});
13206: }
13207: }
13208: if (@allowed > 0) {
13209: $chgtext .= join(', ',@allowed).'</li>';
13210: } else {
13211: $chgtext .= &mt('none').'</li>';
13212: }
13213: }
13214: $chgtext .= '</ul>';
13215: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
13216: $resulttext .= '</li>';
13217: }
13218: $resulttext .= '</ul>';
13219: } else {
13220: $resulttext = &mt('No changes made to user creation settings');
13221: }
13222: } else {
13223: $resulttext = '<span class="LC_error">'.
13224: &mt('An error occurred: [_1]',$putresult).'</span>';
13225: }
13226: if ($warningmsg ne '') {
13227: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
13228: }
13229: return $resulttext;
13230: }
13231:
13232: sub modify_selfcreation {
1.305 raeburn 13233: my ($dom,$lastactref,%domconfig) = @_;
13234: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
13235: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
13236: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 13237: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
13238: if (ref($typesref) eq 'ARRAY') {
13239: @types = @{$typesref};
13240: }
13241: if (ref($usertypesref) eq 'HASH') {
13242: %usertypes = %{$usertypesref};
1.228 raeburn 13243: }
1.303 raeburn 13244: $usertypes{'default'} = $othertitle;
1.224 raeburn 13245: #
13246: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
13247: #
13248: if (ref($domconfig{'usercreation'}) eq 'HASH') {
13249: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
13250: if ($key eq 'cancreate') {
13251: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
13252: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
13253: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 13254: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
13255: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
13256: ($item eq 'emailusername') || ($item eq 'shibenv') ||
13257: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 13258: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 13259: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13260: } else {
13261: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13262: }
13263: }
13264: }
13265: } elsif ($key eq 'email_rule') {
13266: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
13267: } else {
13268: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
13269: }
13270: }
13271: }
13272: #
13273: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
13274: #
13275: if (ref($domconfig{'usermodification'}) eq 'HASH') {
13276: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
13277: if ($key eq 'selfcreate') {
13278: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
13279: } else {
13280: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
13281: }
13282: }
13283: }
1.305 raeburn 13284: #
13285: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
13286: #
13287: if (ref($domconfig{'inststatus'}) eq 'HASH') {
13288: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
13289: if ($key eq 'inststatusguest') {
13290: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
13291: } else {
13292: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
13293: }
13294: }
13295: }
1.224 raeburn 13296:
13297: my @contexts = ('selfcreate');
13298: @{$cancreate{'selfcreate'}} = ();
13299: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 13300: if (@types) {
13301: @{$cancreate{'statustocreate'}} = ();
13302: }
1.236 raeburn 13303: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 13304: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 13305: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 13306: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 13307: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 13308: my %selfcreatetypes = (
13309: sso => 'users authenticated by institutional single sign on',
13310: login => 'users authenticated by institutional log-in',
1.303 raeburn 13311: email => 'users verified by e-mail',
1.50 raeburn 13312: );
1.224 raeburn 13313: #
13314: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
13315: # is permitted.
13316: #
1.305 raeburn 13317: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 13318:
1.305 raeburn 13319: my (@statuses,%email_rule);
1.228 raeburn 13320: foreach my $item ('login','sso','email') {
1.224 raeburn 13321: if ($item eq 'email') {
1.236 raeburn 13322: if ($env{'form.cancreate_email'}) {
1.305 raeburn 13323: if (@types) {
13324: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
13325: foreach my $status (@poss_statuses) {
13326: if (grep(/^\Q$status\E$/,(@types,'default'))) {
13327: push(@statuses,$status);
13328: }
13329: }
13330: $save_inststatus{'inststatusguest'} = \@statuses;
13331: } else {
13332: push(@statuses,'default');
13333: }
13334: if (@statuses) {
13335: my %curr_rule;
13336: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
13337: foreach my $type (@statuses) {
13338: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 13339: }
1.305 raeburn 13340: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
13341: foreach my $type (@statuses) {
13342: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
13343: }
13344: }
13345: push(@{$cancreate{'selfcreate'}},'email');
13346: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
13347: my %curremaildom;
13348: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
13349: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
13350: }
13351: foreach my $type (@statuses) {
13352: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
13353: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
13354: }
13355: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
13356: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
13357: }
13358: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
13359: #
13360: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
13361: #
13362: my $chosen = $1;
13363: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
13364: my $emaildom;
13365: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
13366: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
13367: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
13368: if (ref($curremaildom{$type}) eq 'HASH') {
13369: if (exists($curremaildom{$type}{$chosen})) {
13370: if ($curremaildom{$type}{$chosen} ne $emaildom) {
13371: push(@{$changes{'cancreate'}},'emaildomain');
13372: }
13373: } elsif ($emaildom ne '') {
13374: push(@{$changes{'cancreate'}},'emaildomain');
13375: }
13376: } elsif ($emaildom ne '') {
13377: push(@{$changes{'cancreate'}},'emaildomain');
13378: }
13379: }
13380: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13381: } elsif ($chosen eq 'custom') {
13382: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
13383: $email_rule{$type} = [];
13384: if (ref($emailrules) eq 'HASH') {
13385: foreach my $rule (@possemail_rules) {
13386: if (exists($emailrules->{$rule})) {
13387: push(@{$email_rule{$type}},$rule);
13388: }
13389: }
13390: }
13391: if (@{$email_rule{$type}}) {
13392: $cancreate{'emailoptions'}{$type} = 'custom';
13393: if (ref($curr_rule{$type}) eq 'ARRAY') {
13394: if (@{$curr_rule{$type}} > 0) {
13395: foreach my $rule (@{$curr_rule{$type}}) {
13396: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
13397: push(@{$changes{'email_rule'}},$type);
13398: }
13399: }
13400: }
13401: foreach my $type (@{$email_rule{$type}}) {
13402: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
13403: push(@{$changes{'email_rule'}},$type);
13404: }
13405: }
13406: } else {
13407: push(@{$changes{'email_rule'}},$type);
13408: }
13409: }
13410: } else {
13411: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13412: }
13413: }
13414: }
13415: if (@types) {
13416: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13417: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
13418: if (@changed) {
13419: push(@{$changes{'inststatus'}},'inststatusguest');
13420: }
13421: } else {
13422: push(@{$changes{'inststatus'}},'inststatusguest');
13423: }
13424: }
13425: } else {
13426: delete($env{'form.cancreate_email'});
13427: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13428: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13429: push(@{$changes{'inststatus'}},'inststatusguest');
13430: }
13431: }
13432: }
13433: } else {
13434: $save_inststatus{'inststatusguest'} = [];
13435: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13436: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13437: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 13438: }
13439: }
1.224 raeburn 13440: }
13441: } else {
13442: if ($env{'form.cancreate_'.$item}) {
13443: push(@{$cancreate{'selfcreate'}},$item);
13444: }
13445: }
13446: }
1.305 raeburn 13447: my (%userinfo,%savecaptcha);
1.224 raeburn 13448: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
13449: #
1.228 raeburn 13450: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
13451: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 13452: #
1.236 raeburn 13453:
1.244 raeburn 13454: if ($env{'form.cancreate_email'}) {
1.228 raeburn 13455: push(@contexts,'emailusername');
1.305 raeburn 13456: if (@statuses) {
13457: foreach my $type (@statuses) {
1.228 raeburn 13458: if (ref($infofields) eq 'ARRAY') {
13459: foreach my $field (@{$infofields}) {
13460: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
13461: $cancreate{'emailusername'}{$type}{$field} = $1;
13462: }
13463: }
1.224 raeburn 13464: }
13465: }
13466: }
13467: #
13468: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 13469: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 13470: #
13471:
13472: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
13473: @approvalnotify = sort(@approvalnotify);
13474: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
13475: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13476: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
13477: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
13478: push(@{$changes{'cancreate'}},'notify');
13479: }
13480: } else {
13481: if ($cancreate{'notify'}{'approval'}) {
13482: push(@{$changes{'cancreate'}},'notify');
13483: }
13484: }
13485: } elsif ($cancreate{'notify'}{'approval'}) {
13486: push(@{$changes{'cancreate'}},'notify');
13487: }
13488:
13489: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
13490: }
13491: #
1.236 raeburn 13492: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 13493: # institutional log-in.
13494: #
13495: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
13496: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
13497: ($domdefaults{'auth_def'} eq 'localauth'))) {
13498: $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.').' '.
13499: &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.');
13500: }
13501: }
13502: my @fields = ('lastname','firstname','middlename','generation',
13503: 'permanentemail','id');
1.240 raeburn 13504: my @shibfields = (@fields,'inststatus');
1.224 raeburn 13505: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13506: #
13507: # Where usernames may created for institutional log-in and/or institutional single sign on:
13508: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
13509: # may self-create accounts
13510: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
13511: # which the user may supply, if institutional data is unavailable.
13512: #
13513: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 13514: if (@types) {
1.305 raeburn 13515: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
13516: push(@contexts,'statustocreate');
1.303 raeburn 13517: foreach my $type (@types) {
1.224 raeburn 13518: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
13519: foreach my $field (@fields) {
13520: if (grep(/^\Q$field\E$/,@modifiable)) {
13521: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
13522: } else {
13523: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
13524: }
13525: }
13526: }
13527: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 13528: foreach my $type (@types) {
1.224 raeburn 13529: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
13530: foreach my $field (@fields) {
13531: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
13532: $curr_usermodify{'selfcreate'}{$type}{$field}) {
13533: push(@{$changes{'selfcreate'}},$type);
13534: last;
13535: }
13536: }
13537: }
13538: }
13539: } else {
1.303 raeburn 13540: foreach my $type (@types) {
1.224 raeburn 13541: push(@{$changes{'selfcreate'}},$type);
13542: }
13543: }
13544: }
1.240 raeburn 13545: foreach my $field (@shibfields) {
13546: if ($env{'form.shibenv_'.$field} ne '') {
13547: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
13548: }
13549: }
13550: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13551: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
13552: foreach my $field (@shibfields) {
13553: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
13554: push(@{$changes{'cancreate'}},'shibenv');
13555: }
13556: }
13557: } else {
13558: foreach my $field (@shibfields) {
13559: if ($env{'form.shibenv_'.$field}) {
13560: push(@{$changes{'cancreate'}},'shibenv');
13561: last;
13562: }
13563: }
13564: }
13565: }
1.224 raeburn 13566: }
13567: foreach my $item (@contexts) {
13568: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
13569: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
13570: if (ref($cancreate{$item}) eq 'ARRAY') {
13571: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
13572: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13573: push(@{$changes{'cancreate'}},$item);
13574: }
13575: }
13576: }
13577: }
13578: if (ref($cancreate{$item}) eq 'ARRAY') {
13579: foreach my $type (@{$cancreate{$item}}) {
13580: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
13581: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13582: push(@{$changes{'cancreate'}},$item);
13583: }
13584: }
13585: }
13586: }
13587: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
13588: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 13589: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
13590: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13591: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
13592: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 13593: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13594: push(@{$changes{'cancreate'}},$item);
13595: }
13596: }
13597: }
1.305 raeburn 13598: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13599: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 13600: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13601: push(@{$changes{'cancreate'}},$item);
13602: }
1.224 raeburn 13603: }
13604: }
13605: }
1.305 raeburn 13606: foreach my $type (keys(%{$cancreate{$item}})) {
13607: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13608: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13609: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13610: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 13611: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13612: push(@{$changes{'cancreate'}},$item);
13613: }
13614: }
13615: } else {
13616: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13617: push(@{$changes{'cancreate'}},$item);
13618: }
13619: }
13620: }
1.305 raeburn 13621: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13622: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 13623: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13624: push(@{$changes{'cancreate'}},$item);
13625: }
1.224 raeburn 13626: }
13627: }
13628: }
13629: }
13630: } elsif ($curr_usercreation{'cancreate'}{$item}) {
13631: if (ref($cancreate{$item}) eq 'ARRAY') {
13632: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
13633: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13634: push(@{$changes{'cancreate'}},$item);
13635: }
13636: }
1.305 raeburn 13637: }
13638: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13639: if (ref($cancreate{$item}) eq 'HASH') {
13640: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13641: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 13642: }
13643: }
13644: } elsif ($item eq 'emailusername') {
1.228 raeburn 13645: if (ref($cancreate{$item}) eq 'HASH') {
13646: foreach my $type (keys(%{$cancreate{$item}})) {
13647: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13648: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13649: if ($cancreate{$item}{$type}{$field}) {
13650: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13651: push(@{$changes{'cancreate'}},$item);
13652: }
13653: last;
13654: }
13655: }
13656: }
13657: }
1.224 raeburn 13658: }
13659: }
13660: }
13661: #
13662: # Populate %save_usercreate hash with updates to self-creation configuration.
13663: #
13664: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
13665: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 13666: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 13667: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
13668: if (ref($cancreate{'notify'}) eq 'HASH') {
13669: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
13670: }
1.236 raeburn 13671: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
13672: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
13673: }
1.303 raeburn 13674: if (ref($cancreate{'emailverified'}) eq 'HASH') {
13675: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
13676: }
1.305 raeburn 13677: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
13678: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
13679: }
1.303 raeburn 13680: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
13681: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
13682: }
1.224 raeburn 13683: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13684: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
13685: }
1.240 raeburn 13686: if (ref($cancreate{'shibenv'}) eq 'HASH') {
13687: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
13688: }
1.224 raeburn 13689: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 13690: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 13691:
13692: my %userconfig_hash = (
13693: usercreation => \%save_usercreate,
13694: usermodification => \%save_usermodify,
1.305 raeburn 13695: inststatus => \%save_inststatus,
1.224 raeburn 13696: );
1.305 raeburn 13697:
1.224 raeburn 13698: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
13699: $dom);
13700: #
1.305 raeburn 13701: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 13702: #
1.27 raeburn 13703: if ($putresult eq 'ok') {
13704: if (keys(%changes) > 0) {
13705: $resulttext = &mt('Changes made:').'<ul>';
13706: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 13707: my %lt = &selfcreation_types();
1.34 raeburn 13708: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 13709: my $chgtext = '';
1.45 raeburn 13710: if ($type eq 'selfcreate') {
1.50 raeburn 13711: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 13712: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 13713: } else {
1.224 raeburn 13714: $chgtext .= &mt('Self-creation of a new account is permitted for:').
13715: '<ul>';
1.50 raeburn 13716: foreach my $case (@{$cancreate{$type}}) {
13717: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
13718: }
13719: $chgtext .= '</ul>';
1.100 raeburn 13720: if (ref($cancreate{$type}) eq 'ARRAY') {
13721: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
13722: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13723: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 13724: $chgtext .= '<span class="LC_warning">'.
13725: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
13726: '</span><br />';
13727: }
13728: }
13729: }
13730: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 13731: if (!@statuses) {
13732: $chgtext .= '<span class="LC_warning">'.
13733: &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.").
13734: '</span><br />';
1.303 raeburn 13735:
1.100 raeburn 13736: }
13737: }
13738: }
1.43 raeburn 13739: }
1.240 raeburn 13740: } elsif ($type eq 'shibenv') {
13741: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 13742: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 13743: } else {
13744: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
13745: '<ul>';
13746: foreach my $field (@shibfields) {
13747: next if ($cancreate{$type}{$field} eq '');
13748: if ($field eq 'inststatus') {
13749: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
13750: } else {
13751: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
13752: }
13753: }
13754: $chgtext .= '</ul>';
1.303 raeburn 13755: }
1.93 raeburn 13756: } elsif ($type eq 'statustocreate') {
1.96 raeburn 13757: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
13758: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
13759: if (@{$cancreate{'selfcreate'}} > 0) {
13760: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 13761: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 13762: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 13763: $chgtext .= '<br />'.
13764: '<span class="LC_warning">'.
13765: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
13766: '</span>';
13767: }
1.303 raeburn 13768: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 13769: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 13770: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
13771: } else {
13772: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
13773: }
13774: $chgtext .= '<ul>';
13775: foreach my $case (@{$cancreate{$type}}) {
13776: if ($case eq 'default') {
13777: $chgtext .= '<li>'.$othertitle.'</li>';
13778: } else {
1.303 raeburn 13779: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 13780: }
13781: }
1.100 raeburn 13782: $chgtext .= '</ul>';
13783: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 13784: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 13785: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
13786: '</span>';
1.100 raeburn 13787: }
13788: }
13789: } else {
13790: if (@{$cancreate{$type}} == 0) {
13791: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
13792: } else {
13793: $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 13794: }
13795: }
1.303 raeburn 13796: $chgtext .= '<br />';
1.93 raeburn 13797: }
1.236 raeburn 13798: } elsif ($type eq 'selfcreateprocessing') {
13799: my %choices = &Apache::lonlocal::texthash (
13800: automatic => 'Automatic approval',
13801: approval => 'Queued for approval',
13802: );
1.305 raeburn 13803: if (@types) {
13804: if (@statuses) {
1.303 raeburn 13805: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 13806: '<ul>';
1.305 raeburn 13807: foreach my $status (@statuses) {
13808: if ($status eq 'default') {
13809: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 13810: } else {
1.305 raeburn 13811: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 13812: }
13813: }
13814: $chgtext .= '</ul>';
13815: }
13816: } else {
13817: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
13818: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
13819: }
13820: } elsif ($type eq 'emailverified') {
13821: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 13822: all => 'Same as e-mail',
13823: first => 'Omit @domain',
13824: free => 'Free to choose',
1.303 raeburn 13825: );
1.305 raeburn 13826: if (@types) {
13827: if (@statuses) {
1.303 raeburn 13828: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
13829: '<ul>';
1.305 raeburn 13830: foreach my $status (@statuses) {
1.303 raeburn 13831: if ($type eq 'default') {
1.305 raeburn 13832: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 13833: } else {
1.305 raeburn 13834: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 13835: }
13836: }
13837: $chgtext .= '</ul>';
13838: }
13839: } else {
1.305 raeburn 13840: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 13841: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 13842: }
1.305 raeburn 13843: } elsif ($type eq 'emailoptions') {
13844: my %options = &Apache::lonlocal::texthash (
13845: any => 'Any e-mail',
13846: inst => 'Institutional only',
13847: noninst => 'Non-institutional only',
13848: custom => 'Custom restrictions',
13849: );
13850: if (@types) {
13851: if (@statuses) {
13852: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
13853: '<ul>';
13854: foreach my $status (@statuses) {
13855: if ($type eq 'default') {
13856: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
13857: } else {
13858: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 13859: }
13860: }
1.305 raeburn 13861: $chgtext .= '</ul>';
13862: }
13863: } else {
13864: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
13865: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
13866: } else {
13867: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
13868: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 13869: }
1.305 raeburn 13870: }
13871: } elsif ($type eq 'emaildomain') {
13872: my $output;
13873: if (@statuses) {
13874: foreach my $type (@statuses) {
13875: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
13876: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
13877: if ($type eq 'default') {
13878: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13879: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
13880: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
13881: } else {
13882: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
13883: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
13884: }
1.303 raeburn 13885: } else {
1.305 raeburn 13886: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13887: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
13888: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
13889: } else {
13890: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
13891: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
13892: }
1.303 raeburn 13893: }
1.305 raeburn 13894: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
13895: if ($type eq 'default') {
13896: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13897: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
13898: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
13899: } else {
13900: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
13901: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
13902: }
1.303 raeburn 13903: } else {
1.305 raeburn 13904: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13905: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
13906: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
13907: } else {
13908: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
13909: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
13910: }
1.303 raeburn 13911: }
13912: }
13913: }
13914: }
1.305 raeburn 13915: }
13916: if ($output ne '') {
13917: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
13918: '<ul>'.$output.'</ul>';
1.236 raeburn 13919: }
1.165 raeburn 13920: } elsif ($type eq 'captcha') {
1.224 raeburn 13921: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 13922: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
13923: } else {
13924: my %captchas = &captcha_phrases();
1.224 raeburn 13925: if ($captchas{$savecaptcha{$type}}) {
13926: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 13927: } else {
1.210 raeburn 13928: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 13929: }
13930: }
13931: } elsif ($type eq 'recaptchakeys') {
13932: my ($privkey,$pubkey);
1.224 raeburn 13933: if (ref($savecaptcha{$type}) eq 'HASH') {
13934: $pubkey = $savecaptcha{$type}{'public'};
13935: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 13936: }
13937: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
13938: if (!$pubkey) {
13939: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
13940: } else {
13941: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
13942: }
13943: if (!$privkey) {
13944: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
13945: } else {
13946: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
13947: }
13948: $chgtext .= '</ul>';
1.269 raeburn 13949: } elsif ($type eq 'recaptchaversion') {
13950: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 13951: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 13952: }
1.224 raeburn 13953: } elsif ($type eq 'emailusername') {
13954: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 13955: if (@statuses) {
13956: foreach my $type (@statuses) {
1.228 raeburn 13957: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
13958: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 13959: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 13960: '<ul>';
13961: foreach my $field (@{$infofields}) {
13962: if ($cancreate{'emailusername'}{$type}{$field}) {
13963: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
13964: }
13965: }
1.245 raeburn 13966: $chgtext .= '</ul>';
13967: } else {
1.303 raeburn 13968: $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 13969: }
13970: } else {
1.303 raeburn 13971: $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 13972: }
13973: }
13974: }
13975: }
13976: } elsif ($type eq 'notify') {
1.303 raeburn 13977: my $numapprove = 0;
1.224 raeburn 13978: if (ref($changes{'cancreate'}) eq 'ARRAY') {
13979: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
13980: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 13981: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
13982: $numapprove ++;
1.224 raeburn 13983: }
13984: }
1.43 raeburn 13985: }
1.303 raeburn 13986: unless ($numapprove) {
13987: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
13988: }
1.34 raeburn 13989: }
1.224 raeburn 13990: if ($chgtext) {
13991: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 13992: }
13993: }
13994: }
1.305 raeburn 13995: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 13996: my ($emailrules,$emailruleorder) =
13997: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 13998: foreach my $type (@{$changes{'email_rule'}}) {
13999: if (ref($email_rule{$type}) eq 'ARRAY') {
14000: my $chgtext = '<ul>';
14001: foreach my $rule (@{$email_rule{$type}}) {
14002: if (ref($emailrules->{$rule}) eq 'HASH') {
14003: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
14004: }
14005: }
14006: $chgtext .= '</ul>';
1.310 raeburn 14007: my $typename;
1.305 raeburn 14008: if (@types) {
14009: if ($type eq 'default') {
14010: $typename = $othertitle;
14011: } else {
14012: $typename = $usertypes{$type};
14013: }
14014: $chgtext .= &mt('(Affiliation: [_1])',$typename);
14015: }
14016: if (@{$email_rule{$type}} > 0) {
14017: $resulttext .= '<li>'.
14018: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
14019: $usertypes{$type}).
14020: $chgtext.
14021: '</li>';
14022: } else {
14023: $resulttext .= '<li>'.
1.310 raeburn 14024: &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 14025: '</li>'.
1.310 raeburn 14026: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 14027: }
1.43 raeburn 14028: }
14029: }
1.305 raeburn 14030: }
14031: if (ref($changes{'inststatus'}) eq 'ARRAY') {
14032: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
14033: if (@{$save_inststatus{'inststatusguest'}} > 0) {
14034: my $chgtext = '<ul>';
14035: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
14036: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
14037: }
14038: $chgtext .= '</ul>';
14039: $resulttext .= '<li>'.
14040: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
14041: $chgtext.
14042: '</li>';
14043: } else {
14044: $resulttext .= '<li>'.
14045: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
14046: '</li>';
14047: }
1.43 raeburn 14048: }
14049: }
1.224 raeburn 14050: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
14051: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
14052: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14053: foreach my $type (@{$changes{'selfcreate'}}) {
14054: my $typename = $type;
1.303 raeburn 14055: if (keys(%usertypes) > 0) {
14056: if ($usertypes{$type} ne '') {
14057: $typename = $usertypes{$type};
1.224 raeburn 14058: }
14059: }
14060: my @modifiable;
14061: $resulttext .= '<li>'.
14062: &mt('Self-creation of account by users with status: [_1]',
14063: '<span class="LC_cusr_emph">'.$typename.'</span>').
14064: ' - '.&mt('modifiable fields (if institutional data blank): ');
14065: foreach my $field (@fields) {
14066: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
14067: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 14068: }
14069: }
1.224 raeburn 14070: if (@modifiable > 0) {
14071: $resulttext .= join(', ',@modifiable);
1.43 raeburn 14072: } else {
1.224 raeburn 14073: $resulttext .= &mt('none');
1.43 raeburn 14074: }
1.224 raeburn 14075: $resulttext .= '</li>';
1.28 raeburn 14076: }
1.224 raeburn 14077: $resulttext .= '</ul></li>';
1.28 raeburn 14078: }
1.27 raeburn 14079: $resulttext .= '</ul>';
1.305 raeburn 14080: my $cachetime = 24*60*60;
14081: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
14082: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14083: if (ref($lastactref) eq 'HASH') {
14084: $lastactref->{'domdefaults'} = 1;
14085: }
1.27 raeburn 14086: } else {
1.224 raeburn 14087: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 14088: }
14089: } else {
14090: $resulttext = '<span class="LC_error">'.
1.23 raeburn 14091: &mt('An error occurred: [_1]',$putresult).'</span>';
14092: }
1.43 raeburn 14093: if ($warningmsg ne '') {
14094: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
14095: }
1.23 raeburn 14096: return $resulttext;
14097: }
14098:
1.165 raeburn 14099: sub process_captcha {
14100: my ($container,$changes,$newsettings,$current) = @_;
14101: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
14102: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
14103: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
14104: $newsettings->{'captcha'} = 'original';
14105: }
14106: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 14107: if ($container eq 'cancreate') {
1.169 raeburn 14108: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14109: push(@{$changes->{'cancreate'}},'captcha');
14110: } elsif (!defined($changes->{'cancreate'})) {
14111: $changes->{'cancreate'} = ['captcha'];
14112: }
14113: } else {
14114: $changes->{'captcha'} = 1;
1.165 raeburn 14115: }
14116: }
1.269 raeburn 14117: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 14118: if ($newsettings->{'captcha'} eq 'recaptcha') {
14119: $newpub = $env{'form.'.$container.'_recaptchapub'};
14120: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 14121: $newpub =~ s/[^\w\-]//g;
14122: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 14123: $newsettings->{'recaptchakeys'} = {
14124: public => $newpub,
14125: private => $newpriv,
14126: };
1.269 raeburn 14127: $newversion = $env{'form.'.$container.'_recaptchaversion'};
14128: $newversion =~ s/\D//g;
14129: if ($newversion ne '2') {
14130: $newversion = 1;
14131: }
14132: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 14133: }
14134: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
14135: $currpub = $current->{'recaptchakeys'}{'public'};
14136: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 14137: unless ($newsettings->{'captcha'} eq 'recaptcha') {
14138: $newsettings->{'recaptchakeys'} = {
14139: public => '',
14140: private => '',
14141: }
14142: }
1.165 raeburn 14143: }
1.269 raeburn 14144: if ($current->{'captcha'} eq 'recaptcha') {
14145: $currversion = $current->{'recaptchaversion'};
14146: if ($currversion ne '2') {
14147: $currversion = 1;
14148: }
14149: }
14150: if ($currversion ne $newversion) {
14151: if ($container eq 'cancreate') {
14152: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14153: push(@{$changes->{'cancreate'}},'recaptchaversion');
14154: } elsif (!defined($changes->{'cancreate'})) {
14155: $changes->{'cancreate'} = ['recaptchaversion'];
14156: }
14157: } else {
14158: $changes->{'recaptchaversion'} = 1;
14159: }
14160: }
1.165 raeburn 14161: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 14162: if ($container eq 'cancreate') {
14163: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14164: push(@{$changes->{'cancreate'}},'recaptchakeys');
14165: } elsif (!defined($changes->{'cancreate'})) {
14166: $changes->{'cancreate'} = ['recaptchakeys'];
14167: }
14168: } else {
1.210 raeburn 14169: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 14170: }
14171: }
14172: return;
14173: }
14174:
1.33 raeburn 14175: sub modify_usermodification {
14176: my ($dom,%domconfig) = @_;
1.224 raeburn 14177: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 14178: if (ref($domconfig{'usermodification'}) eq 'HASH') {
14179: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 14180: if ($key eq 'selfcreate') {
14181: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
14182: } else {
14183: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
14184: }
1.33 raeburn 14185: }
14186: }
1.224 raeburn 14187: my @contexts = ('author','course');
1.33 raeburn 14188: my %context_title = (
14189: author => 'In author context',
14190: course => 'In course context',
14191: );
14192: my @fields = ('lastname','firstname','middlename','generation',
14193: 'permanentemail','id');
14194: my %roles = (
14195: author => ['ca','aa'],
14196: course => ['st','ep','ta','in','cr'],
14197: );
14198: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14199: foreach my $context (@contexts) {
14200: foreach my $role (@{$roles{$context}}) {
14201: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
14202: foreach my $item (@fields) {
14203: if (grep(/^\Q$item\E$/,@modifiable)) {
14204: $modifyhash{$context}{$role}{$item} = 1;
14205: } else {
14206: $modifyhash{$context}{$role}{$item} = 0;
14207: }
14208: }
14209: }
14210: if (ref($curr_usermodification{$context}) eq 'HASH') {
14211: foreach my $role (@{$roles{$context}}) {
14212: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
14213: foreach my $field (@fields) {
14214: if ($modifyhash{$context}{$role}{$field} ne
14215: $curr_usermodification{$context}{$role}{$field}) {
14216: push(@{$changes{$context}},$role);
14217: last;
14218: }
14219: }
14220: }
14221: }
14222: } else {
14223: foreach my $context (@contexts) {
14224: foreach my $role (@{$roles{$context}}) {
14225: push(@{$changes{$context}},$role);
14226: }
14227: }
14228: }
14229: }
14230: my %usermodification_hash = (
14231: usermodification => \%modifyhash,
14232: );
14233: my $putresult = &Apache::lonnet::put_dom('configuration',
14234: \%usermodification_hash,$dom);
14235: if ($putresult eq 'ok') {
14236: if (keys(%changes) > 0) {
14237: $resulttext = &mt('Changes made: ').'<ul>';
14238: foreach my $context (@contexts) {
14239: if (ref($changes{$context}) eq 'ARRAY') {
14240: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
14241: if (ref($changes{$context}) eq 'ARRAY') {
14242: foreach my $role (@{$changes{$context}}) {
14243: my $rolename;
1.224 raeburn 14244: if ($role eq 'cr') {
14245: $rolename = &mt('Custom');
1.33 raeburn 14246: } else {
1.224 raeburn 14247: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 14248: }
14249: my @modifiable;
1.224 raeburn 14250: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 14251: foreach my $field (@fields) {
14252: if ($modifyhash{$context}{$role}{$field}) {
14253: push(@modifiable,$fieldtitles{$field});
14254: }
14255: }
14256: if (@modifiable > 0) {
14257: $resulttext .= join(', ',@modifiable);
14258: } else {
14259: $resulttext .= &mt('none');
14260: }
14261: $resulttext .= '</li>';
14262: }
14263: $resulttext .= '</ul></li>';
14264: }
14265: }
14266: }
14267: $resulttext .= '</ul>';
14268: } else {
14269: $resulttext = &mt('No changes made to user modification settings');
14270: }
14271: } else {
14272: $resulttext = '<span class="LC_error">'.
14273: &mt('An error occurred: [_1]',$putresult).'</span>';
14274: }
14275: return $resulttext;
14276: }
14277:
1.43 raeburn 14278: sub modify_defaults {
1.212 raeburn 14279: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 14280: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 14281: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 14282: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
14283: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.325 raeburn 14284: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 14285: foreach my $item (@items) {
14286: $newvalues{$item} = $env{'form.'.$item};
14287: if ($item eq 'auth_def') {
14288: if ($newvalues{$item} ne '') {
14289: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
14290: push(@errors,$item);
14291: }
14292: }
14293: } elsif ($item eq 'lang_def') {
14294: if ($newvalues{$item} ne '') {
14295: if ($newvalues{$item} =~ /^(\w+)/) {
14296: my $langcode = $1;
1.103 raeburn 14297: if ($langcode ne 'x_chef') {
14298: if (code2language($langcode) eq '') {
14299: push(@errors,$item);
14300: }
1.43 raeburn 14301: }
14302: } else {
14303: push(@errors,$item);
14304: }
14305: }
1.54 raeburn 14306: } elsif ($item eq 'timezone_def') {
14307: if ($newvalues{$item} ne '') {
1.62 raeburn 14308: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 14309: push(@errors,$item);
14310: }
14311: }
1.68 raeburn 14312: } elsif ($item eq 'datelocale_def') {
14313: if ($newvalues{$item} ne '') {
14314: my @datelocale_ids = DateTime::Locale->ids();
14315: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
14316: push(@errors,$item);
14317: }
14318: }
1.141 raeburn 14319: } elsif ($item eq 'portal_def') {
14320: if ($newvalues{$item} ne '') {
14321: 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])\/?$/) {
14322: push(@errors,$item);
14323: }
14324: }
1.294 raeburn 14325: } elsif ($item eq 'intauth_cost') {
14326: if ($newvalues{$item} ne '') {
14327: if ($newvalues{$item} =~ /\D/) {
14328: push(@errors,$item);
14329: }
14330: }
14331: } elsif ($item eq 'intauth_check') {
14332: if ($newvalues{$item} ne '') {
14333: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
14334: push(@errors,$item);
14335: }
14336: }
14337: } elsif ($item eq 'intauth_switch') {
14338: if ($newvalues{$item} ne '') {
14339: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
14340: push(@errors,$item);
14341: }
14342: }
1.43 raeburn 14343: }
14344: if (grep(/^\Q$item\E$/,@errors)) {
14345: $newvalues{$item} = $domdefaults{$item};
14346: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
14347: $changes{$item} = 1;
14348: }
1.72 raeburn 14349: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 14350: }
14351: my %defaults_hash = (
1.72 raeburn 14352: defaults => \%newvalues,
14353: );
1.43 raeburn 14354: my $title = &defaults_titles();
1.236 raeburn 14355:
14356: my $currinststatus;
14357: if (ref($domconfig{'inststatus'}) eq 'HASH') {
14358: $currinststatus = $domconfig{'inststatus'};
14359: } else {
14360: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
14361: $currinststatus = {
14362: inststatustypes => $usertypes,
14363: inststatusorder => $types,
14364: inststatusguest => [],
14365: };
14366: }
14367: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
14368: my @allpos;
14369: my %alltypes;
1.305 raeburn 14370: my @inststatusguest;
14371: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
14372: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
14373: unless (grep(/^\Q$type\E$/,@todelete)) {
14374: push(@inststatusguest,$type);
14375: }
14376: }
14377: }
14378: my ($currtitles,$currorder);
1.236 raeburn 14379: if (ref($currinststatus) eq 'HASH') {
14380: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
14381: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
14382: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
14383: if ($currinststatus->{inststatustypes}->{$type} ne '') {
14384: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
14385: }
14386: }
14387: unless (grep(/^\Q$type\E$/,@todelete)) {
14388: my $position = $env{'form.inststatus_pos_'.$type};
14389: $position =~ s/\D+//g;
14390: $allpos[$position] = $type;
14391: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
14392: $alltypes{$type} =~ s/`//g;
14393: }
14394: }
14395: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
14396: $currtitles =~ s/,$//;
14397: }
14398: }
14399: if ($env{'form.addinststatus'}) {
14400: my $newtype = $env{'form.addinststatus'};
14401: $newtype =~ s/\W//g;
14402: unless (exists($alltypes{$newtype})) {
14403: $alltypes{$newtype} = $env{'form.addinststatus_title'};
14404: $alltypes{$newtype} =~ s/`//g;
14405: my $position = $env{'form.addinststatus_pos'};
14406: $position =~ s/\D+//g;
14407: if ($position ne '') {
14408: $allpos[$position] = $newtype;
14409: }
14410: }
14411: }
1.305 raeburn 14412: my @orderedstatus;
1.236 raeburn 14413: foreach my $type (@allpos) {
14414: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
14415: push(@orderedstatus,$type);
14416: }
14417: }
14418: foreach my $type (keys(%alltypes)) {
14419: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
14420: delete($alltypes{$type});
14421: }
14422: }
14423: $defaults_hash{'inststatus'} = {
14424: inststatustypes => \%alltypes,
14425: inststatusorder => \@orderedstatus,
1.305 raeburn 14426: inststatusguest => \@inststatusguest,
1.236 raeburn 14427: };
14428: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
14429: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
14430: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
14431: }
14432: }
14433: if ($currorder ne join(',',@orderedstatus)) {
14434: $changes{'inststatus'}{'inststatusorder'} = 1;
14435: }
14436: my $newtitles;
14437: foreach my $item (@orderedstatus) {
14438: $newtitles .= $alltypes{$item}.',';
14439: }
14440: $newtitles =~ s/,$//;
14441: if ($currtitles ne $newtitles) {
14442: $changes{'inststatus'}{'inststatustypes'} = 1;
14443: }
1.43 raeburn 14444: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
14445: $dom);
14446: if ($putresult eq 'ok') {
14447: if (keys(%changes) > 0) {
14448: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 14449: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 14450: 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";
14451: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 14452: if ($item eq 'inststatus') {
14453: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 14454: if (@orderedstatus) {
1.236 raeburn 14455: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
14456: foreach my $type (@orderedstatus) {
14457: $resulttext .= $alltypes{$type}.', ';
14458: }
14459: $resulttext =~ s/, $//;
14460: $resulttext .= '</li>';
1.305 raeburn 14461: } else {
14462: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 14463: }
14464: }
14465: } else {
14466: my $value = $env{'form.'.$item};
14467: if ($value eq '') {
14468: $value = &mt('none');
14469: } elsif ($item eq 'auth_def') {
14470: my %authnames = &authtype_names();
14471: my %shortauth = (
14472: internal => 'int',
14473: krb4 => 'krb4',
14474: krb5 => 'krb5',
14475: localauth => 'loc',
1.325 raeburn 14476: lti => 'lti',
1.236 raeburn 14477: );
14478: $value = $authnames{$shortauth{$value}};
1.294 raeburn 14479: } elsif ($item eq 'intauth_switch') {
14480: my %optiondesc = &Apache::lonlocal::texthash (
14481: 0 => 'No',
14482: 1 => 'Yes',
14483: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
14484: );
14485: if ($value =~ /^(0|1|2)$/) {
14486: $value = $optiondesc{$value};
14487: } else {
14488: $value = &mt('none -- defaults to No');
14489: }
14490: } elsif ($item eq 'intauth_check') {
14491: my %optiondesc = &Apache::lonlocal::texthash (
14492: 0 => 'No',
14493: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
14494: 2 => 'Yes, disallow login if stored cost is less than domain default',
14495: );
14496: if ($value =~ /^(0|1|2)$/) {
14497: $value = $optiondesc{$value};
14498: } else {
14499: $value = &mt('none -- defaults to No');
14500: }
1.236 raeburn 14501: }
14502: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
14503: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 14504: }
14505: }
14506: $resulttext .= '</ul>';
14507: $mailmsgtext .= "\n";
14508: my $cachetime = 24*60*60;
1.72 raeburn 14509: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 14510: if (ref($lastactref) eq 'HASH') {
14511: $lastactref->{'domdefaults'} = 1;
14512: }
1.68 raeburn 14513: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 14514: my $notify = 1;
14515: if (ref($domconfig{'contacts'}) eq 'HASH') {
14516: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
14517: $notify = 0;
14518: }
14519: }
14520: if ($notify) {
14521: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
14522: "LON-CAPA Domain Settings Change - $dom",
14523: $mailmsgtext);
14524: }
1.54 raeburn 14525: }
1.43 raeburn 14526: } else {
1.54 raeburn 14527: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 14528: }
14529: } else {
14530: $resulttext = '<span class="LC_error">'.
14531: &mt('An error occurred: [_1]',$putresult).'</span>';
14532: }
14533: if (@errors > 0) {
14534: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
14535: foreach my $item (@errors) {
14536: $resulttext .= ' "'.$title->{$item}.'",';
14537: }
14538: $resulttext =~ s/,$//;
14539: }
14540: return $resulttext;
14541: }
14542:
1.46 raeburn 14543: sub modify_scantron {
1.205 raeburn 14544: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 14545: my ($resulttext,%confhash,%changes,$errors);
14546: my $custom = 'custom.tab';
14547: my $default = 'default.tab';
14548: my $servadm = $r->dir_config('lonAdmEMail');
14549: my ($configuserok,$author_ok,$switchserver) =
14550: &config_check($dom,$confname,$servadm);
14551: if ($env{'form.scantronformat.filename'} ne '') {
14552: my $error;
14553: if ($configuserok eq 'ok') {
14554: if ($switchserver) {
1.130 raeburn 14555: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 14556: } else {
14557: if ($author_ok eq 'ok') {
14558: my ($result,$scantronurl) =
14559: &publishlogo($r,'upload','scantronformat',$dom,
14560: $confname,'scantron','','',$custom);
14561: if ($result eq 'ok') {
14562: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 14563: $changes{'scantronformat'} = 1;
1.46 raeburn 14564: } else {
14565: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
14566: }
14567: } else {
14568: $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);
14569: }
14570: }
14571: } else {
14572: $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);
14573: }
14574: if ($error) {
14575: &Apache::lonnet::logthis($error);
14576: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14577: }
14578: }
1.48 raeburn 14579: if (ref($domconfig{'scantron'}) eq 'HASH') {
14580: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
14581: if ($env{'form.scantronformat_del'}) {
14582: $confhash{'scantron'}{'scantronformat'} = '';
14583: $changes{'scantronformat'} = 1;
1.46 raeburn 14584: }
14585: }
14586: }
14587: if (keys(%confhash) > 0) {
14588: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
14589: $dom);
14590: if ($putresult eq 'ok') {
14591: if (keys(%changes) > 0) {
1.48 raeburn 14592: if (ref($confhash{'scantron'}) eq 'HASH') {
14593: $resulttext = &mt('Changes made:').'<ul>';
14594: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 14595: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 14596: } else {
1.130 raeburn 14597: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 14598: }
1.48 raeburn 14599: $resulttext .= '</ul>';
14600: } else {
1.130 raeburn 14601: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 14602: }
14603: $resulttext .= '</ul>';
14604: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 14605: if (ref($lastactref) eq 'HASH') {
14606: $lastactref->{'domainconfig'} = 1;
14607: }
1.46 raeburn 14608: } else {
1.130 raeburn 14609: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 14610: }
14611: } else {
14612: $resulttext = '<span class="LC_error">'.
14613: &mt('An error occurred: [_1]',$putresult).'</span>';
14614: }
14615: } else {
1.130 raeburn 14616: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 14617: }
14618: if ($errors) {
14619: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14620: $errors.'</ul>';
14621: }
14622: return $resulttext;
14623: }
14624:
1.48 raeburn 14625: sub modify_coursecategories {
1.239 raeburn 14626: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 14627: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
14628: $cathash);
1.48 raeburn 14629: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 14630: my @catitems = ('unauth','auth');
14631: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 14632: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 14633: $cathash = $domconfig{'coursecategories'}{'cats'};
14634: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
14635: $changes{'togglecats'} = 1;
14636: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
14637: }
14638: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
14639: $changes{'categorize'} = 1;
14640: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
14641: }
1.120 raeburn 14642: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
14643: $changes{'togglecatscomm'} = 1;
14644: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
14645: }
14646: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
14647: $changes{'categorizecomm'} = 1;
14648: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 14649:
14650: }
14651: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
14652: $changes{'togglecatsplace'} = 1;
14653: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
14654: }
14655: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
14656: $changes{'categorizeplace'} = 1;
14657: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 14658: }
1.238 raeburn 14659: foreach my $item (@catitems) {
14660: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
14661: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
14662: $changes{$item} = 1;
14663: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
14664: }
14665: }
14666: }
1.57 raeburn 14667: } else {
14668: $changes{'togglecats'} = 1;
14669: $changes{'categorize'} = 1;
1.124 raeburn 14670: $changes{'togglecatscomm'} = 1;
14671: $changes{'categorizecomm'} = 1;
1.272 raeburn 14672: $changes{'togglecatsplace'} = 1;
14673: $changes{'categorizeplace'} = 1;
1.87 raeburn 14674: $domconfig{'coursecategories'} = {
14675: togglecats => $env{'form.togglecats'},
14676: categorize => $env{'form.categorize'},
1.124 raeburn 14677: togglecatscomm => $env{'form.togglecatscomm'},
14678: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 14679: togglecatsplace => $env{'form.togglecatsplace'},
14680: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 14681: };
1.238 raeburn 14682: foreach my $item (@catitems) {
14683: if ($env{'form.coursecat_'.$item} ne 'std') {
14684: $changes{$item} = 1;
14685: }
14686: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
14687: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
14688: }
14689: }
1.57 raeburn 14690: }
14691: if (ref($cathash) eq 'HASH') {
14692: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 14693: push (@deletecategory,'instcode::0');
14694: }
1.120 raeburn 14695: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
14696: push(@deletecategory,'communities::0');
14697: }
1.272 raeburn 14698: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
14699: push(@deletecategory,'placement::0');
14700: }
1.48 raeburn 14701: }
1.57 raeburn 14702: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
14703: if (ref($cathash) eq 'HASH') {
1.48 raeburn 14704: if (@deletecategory > 0) {
14705: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 14706: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 14707: foreach my $item (@deletecategory) {
1.57 raeburn 14708: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
14709: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 14710: $deletions{$item} = 1;
1.57 raeburn 14711: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 14712: }
14713: }
14714: }
1.57 raeburn 14715: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 14716: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 14717: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 14718: $reorderings{$item} = 1;
1.57 raeburn 14719: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 14720: }
14721: if ($env{'form.addcategory_name_'.$item} ne '') {
14722: my $newcat = $env{'form.addcategory_name_'.$item};
14723: my $newdepth = $depth+1;
14724: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 14725: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 14726: $adds{$newitem} = 1;
14727: }
14728: if ($env{'form.subcat_'.$item} ne '') {
14729: my $newcat = $env{'form.subcat_'.$item};
14730: my $newdepth = $depth+1;
14731: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 14732: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 14733: $adds{$newitem} = 1;
14734: }
14735: }
14736: }
14737: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 14738: if (ref($cathash) eq 'HASH') {
1.48 raeburn 14739: my $newitem = 'instcode::0';
1.57 raeburn 14740: if ($cathash->{$newitem} eq '') {
14741: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 14742: $adds{$newitem} = 1;
14743: }
14744: } else {
14745: my $newitem = 'instcode::0';
1.57 raeburn 14746: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 14747: $adds{$newitem} = 1;
14748: }
14749: }
1.120 raeburn 14750: if ($env{'form.communities'} eq '1') {
14751: if (ref($cathash) eq 'HASH') {
14752: my $newitem = 'communities::0';
14753: if ($cathash->{$newitem} eq '') {
14754: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
14755: $adds{$newitem} = 1;
14756: }
14757: } else {
14758: my $newitem = 'communities::0';
14759: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
14760: $adds{$newitem} = 1;
14761: }
14762: }
1.272 raeburn 14763: if ($env{'form.placement'} eq '1') {
14764: if (ref($cathash) eq 'HASH') {
14765: my $newitem = 'placement::0';
14766: if ($cathash->{$newitem} eq '') {
14767: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
14768: $adds{$newitem} = 1;
14769: }
14770: } else {
14771: my $newitem = 'placement::0';
14772: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
14773: $adds{$newitem} = 1;
14774: }
14775: }
1.48 raeburn 14776: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 14777: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 14778: ($env{'form.addcategory_name'} ne 'communities') &&
14779: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 14780: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
14781: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
14782: $adds{$newitem} = 1;
14783: }
1.48 raeburn 14784: }
1.57 raeburn 14785: my $putresult;
1.48 raeburn 14786: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14787: if (keys(%deletions) > 0) {
14788: foreach my $key (keys(%deletions)) {
14789: if ($predelallitems{$key} ne '') {
14790: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
14791: }
14792: }
14793: }
14794: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 14795: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 14796: if (ref($chkcats[0]) eq 'ARRAY') {
14797: my $depth = 0;
14798: my $chg = 0;
14799: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
14800: my $name = $chkcats[0][$i];
14801: my $item;
14802: if ($name eq '') {
14803: $chg ++;
14804: } else {
14805: $item = &escape($name).'::0';
14806: if ($chg) {
1.57 raeburn 14807: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 14808: }
14809: $depth ++;
1.57 raeburn 14810: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 14811: $depth --;
14812: }
14813: }
14814: }
1.57 raeburn 14815: }
14816: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14817: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 14818: if ($putresult eq 'ok') {
1.57 raeburn 14819: my %title = (
1.120 raeburn 14820: togglecats => 'Show/Hide a course in catalog',
14821: categorize => 'Assign a category to a course',
14822: togglecatscomm => 'Show/Hide a community in catalog',
14823: categorizecomm => 'Assign a category to a community',
1.57 raeburn 14824: );
14825: my %level = (
1.120 raeburn 14826: dom => 'set in Domain ("Modify Course/Community")',
14827: crs => 'set in Course ("Course Configuration")',
14828: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 14829: none => 'No catalog',
14830: std => 'Standard catalog',
14831: domonly => 'Domain-only catalog',
14832: codesrch => 'Code search form',
1.57 raeburn 14833: );
1.48 raeburn 14834: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 14835: if ($changes{'togglecats'}) {
14836: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
14837: }
14838: if ($changes{'categorize'}) {
14839: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 14840: }
1.120 raeburn 14841: if ($changes{'togglecatscomm'}) {
14842: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
14843: }
14844: if ($changes{'categorizecomm'}) {
14845: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
14846: }
1.238 raeburn 14847: if ($changes{'unauth'}) {
14848: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
14849: }
14850: if ($changes{'auth'}) {
14851: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
14852: }
1.57 raeburn 14853: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14854: my $cathash;
14855: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
14856: $cathash = $domconfig{'coursecategories'}{'cats'};
14857: } else {
14858: $cathash = {};
14859: }
14860: my (@cats,@trails,%allitems);
14861: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
14862: if (keys(%deletions) > 0) {
14863: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
14864: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
14865: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
14866: }
14867: $resulttext .= '</ul></li>';
14868: }
14869: if (keys(%reorderings) > 0) {
14870: my %sort_by_trail;
14871: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
14872: foreach my $key (keys(%reorderings)) {
14873: if ($allitems{$key} ne '') {
14874: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
14875: }
1.48 raeburn 14876: }
1.57 raeburn 14877: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
14878: $resulttext .= '<li>'.$trails[$trail].'</li>';
14879: }
14880: $resulttext .= '</ul></li>';
1.48 raeburn 14881: }
1.57 raeburn 14882: if (keys(%adds) > 0) {
14883: my %sort_by_trail;
14884: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
14885: foreach my $key (keys(%adds)) {
14886: if ($allitems{$key} ne '') {
14887: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
14888: }
14889: }
14890: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
14891: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 14892: }
1.57 raeburn 14893: $resulttext .= '</ul></li>';
1.48 raeburn 14894: }
14895: }
14896: $resulttext .= '</ul>';
1.239 raeburn 14897: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 14898: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
14899: if ($changes{'auth'}) {
14900: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
14901: }
14902: if ($changes{'unauth'}) {
14903: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
14904: }
14905: my $cachetime = 24*60*60;
14906: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 14907: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 14908: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 14909: }
14910: }
1.48 raeburn 14911: } else {
14912: $resulttext = '<span class="LC_error">'.
1.57 raeburn 14913: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 14914: }
14915: } else {
1.120 raeburn 14916: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 14917: }
14918: return $resulttext;
14919: }
14920:
1.69 raeburn 14921: sub modify_serverstatuses {
14922: my ($dom,%domconfig) = @_;
14923: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
14924: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
14925: %currserverstatus = %{$domconfig{'serverstatuses'}};
14926: }
14927: my @pages = &serverstatus_pages();
14928: foreach my $type (@pages) {
14929: $newserverstatus{$type}{'namedusers'} = '';
14930: $newserverstatus{$type}{'machines'} = '';
14931: if (defined($env{'form.'.$type.'_namedusers'})) {
14932: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
14933: my @okusers;
14934: foreach my $user (@users) {
14935: my ($uname,$udom) = split(/:/,$user);
14936: if (($udom =~ /^$match_domain$/) &&
14937: (&Apache::lonnet::domain($udom)) &&
14938: ($uname =~ /^$match_username$/)) {
14939: if (!grep(/^\Q$user\E/,@okusers)) {
14940: push(@okusers,$user);
14941: }
14942: }
14943: }
14944: if (@okusers > 0) {
14945: @okusers = sort(@okusers);
14946: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
14947: }
14948: }
14949: if (defined($env{'form.'.$type.'_machines'})) {
14950: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
14951: my @okmachines;
14952: foreach my $ip (@machines) {
14953: my @parts = split(/\./,$ip);
14954: next if (@parts < 4);
14955: my $badip = 0;
14956: for (my $i=0; $i<4; $i++) {
14957: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
14958: $badip = 1;
14959: last;
14960: }
14961: }
14962: if (!$badip) {
14963: push(@okmachines,$ip);
14964: }
14965: }
14966: @okmachines = sort(@okmachines);
14967: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
14968: }
14969: }
14970: my %serverstatushash = (
14971: serverstatuses => \%newserverstatus,
14972: );
14973: foreach my $type (@pages) {
1.83 raeburn 14974: foreach my $setting ('namedusers','machines') {
1.84 raeburn 14975: my (@current,@new);
1.83 raeburn 14976: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 14977: if ($currserverstatus{$type}{$setting} ne '') {
14978: @current = split(/,/,$currserverstatus{$type}{$setting});
14979: }
14980: }
14981: if ($newserverstatus{$type}{$setting} ne '') {
14982: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 14983: }
14984: if (@current > 0) {
14985: if (@new > 0) {
14986: foreach my $item (@current) {
14987: if (!grep(/^\Q$item\E$/,@new)) {
14988: $changes{$type}{$setting} = 1;
1.82 raeburn 14989: last;
14990: }
14991: }
1.84 raeburn 14992: foreach my $item (@new) {
14993: if (!grep(/^\Q$item\E$/,@current)) {
14994: $changes{$type}{$setting} = 1;
14995: last;
1.82 raeburn 14996: }
14997: }
14998: } else {
1.83 raeburn 14999: $changes{$type}{$setting} = 1;
1.69 raeburn 15000: }
1.83 raeburn 15001: } elsif (@new > 0) {
15002: $changes{$type}{$setting} = 1;
1.69 raeburn 15003: }
15004: }
15005: }
15006: if (keys(%changes) > 0) {
1.81 raeburn 15007: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 15008: my $putresult = &Apache::lonnet::put_dom('configuration',
15009: \%serverstatushash,$dom);
15010: if ($putresult eq 'ok') {
15011: $resulttext .= &mt('Changes made:').'<ul>';
15012: foreach my $type (@pages) {
1.84 raeburn 15013: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 15014: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 15015: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 15016: if ($newserverstatus{$type}{'namedusers'} eq '') {
15017: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
15018: } else {
15019: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
15020: }
1.84 raeburn 15021: }
15022: if ($changes{$type}{'machines'}) {
1.69 raeburn 15023: if ($newserverstatus{$type}{'machines'} eq '') {
15024: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
15025: } else {
15026: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
15027: }
15028:
15029: }
15030: $resulttext .= '</ul></li>';
15031: }
15032: }
15033: $resulttext .= '</ul>';
15034: } else {
15035: $resulttext = '<span class="LC_error">'.
15036: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
15037:
15038: }
15039: } else {
15040: $resulttext = &mt('No changes made to access to server status pages');
15041: }
15042: return $resulttext;
15043: }
15044:
1.118 jms 15045: sub modify_helpsettings {
1.285 raeburn 15046: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 15047: my ($resulttext,$errors,%changes,%helphash);
15048: my %defaultchecked = ('submitbugs' => 'on');
15049: my @offon = ('off','on');
1.118 jms 15050: my @toggles = ('submitbugs');
1.285 raeburn 15051: my %current = ('submitbugs' => '',
15052: 'adhoc' => {},
15053: );
1.118 jms 15054: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 15055: %current = %{$domconfig{'helpsettings'}};
15056: }
1.285 raeburn 15057: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 15058: foreach my $item (@toggles) {
15059: if ($defaultchecked{$item} eq 'on') {
15060: if ($current{$item} eq '') {
15061: if ($env{'form.'.$item} eq '0') {
15062: $changes{$item} = 1;
15063: }
15064: } elsif ($current{$item} ne $env{'form.'.$item}) {
15065: $changes{$item} = 1;
15066: }
15067: } elsif ($defaultchecked{$item} eq 'off') {
15068: if ($current{$item} eq '') {
15069: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 15070: $changes{$item} = 1;
15071: }
1.282 raeburn 15072: } elsif ($current{$item} ne $env{'form.'.$item}) {
15073: $changes{$item} = 1;
15074: }
15075: }
15076: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
15077: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
15078: }
15079: }
1.285 raeburn 15080: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 15081: my $confname = $dom.'-domainconfig';
15082: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 15083: my (@allpos,%newsettings,%changedprivs,$newrole);
15084: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 15085: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 15086: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 15087: my %lt = &Apache::lonlocal::texthash(
15088: s => 'system',
15089: d => 'domain',
15090: order => 'Display order',
15091: access => 'Role usage',
1.291 raeburn 15092: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 15093: dh => 'All with domain helpdesk role',
15094: da => 'All with domain helpdesk assistant role',
1.285 raeburn 15095: none => 'None',
15096: status => 'Determined based on institutional status',
15097: inc => 'Include all, but exclude specific personnel',
15098: exc => 'Exclude all, but include specific personnel',
15099: );
15100: for (my $num=0; $num<=$maxnum; $num++) {
15101: my ($prefix,$identifier,$rolename,%curr);
15102: if ($num == $maxnum) {
15103: next unless ($env{'form.newcusthelp'} == $maxnum);
15104: $identifier = 'custhelp'.$num;
15105: $prefix = 'helproles_'.$num;
15106: $rolename = $env{'form.custhelpname'.$num};
15107: $rolename=~s/[^A-Za-z0-9]//gs;
15108: next if ($rolename eq '');
15109: next if (exists($existing{'rolesdef_'.$rolename}));
15110: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15111: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15112: $newprivs{'c'},$confname,$dom);
15113: if ($result ne 'ok') {
15114: $errors .= '<li><span class="LC_error">'.
15115: &mt('An error occurred storing the new custom role: [_1]',
15116: $result).'</span></li>';
15117: next;
15118: } else {
15119: $changedprivs{$rolename} = \%newprivs;
15120: $newrole = $rolename;
15121: }
15122: } else {
15123: $prefix = 'helproles_'.$num;
15124: $rolename = $env{'form.'.$prefix};
15125: next if ($rolename eq '');
15126: next unless (exists($existing{'rolesdef_'.$rolename}));
15127: $identifier = 'custhelp'.$num;
15128: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15129: my %currprivs;
1.289 raeburn 15130: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 15131: split(/\_/,$existing{'rolesdef_'.$rolename});
15132: foreach my $level ('c','d','s') {
15133: if ($newprivs{$level} ne $currprivs{$level}) {
15134: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15135: $newprivs{'c'},$confname,$dom);
15136: if ($result ne 'ok') {
15137: $errors .= '<li><span class="LC_error">'.
15138: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
15139: $rolename,$result).'</span></li>';
15140: } else {
15141: $changedprivs{$rolename} = \%newprivs;
15142: }
15143: last;
15144: }
15145: }
15146: if (ref($current{'adhoc'}) eq 'HASH') {
15147: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15148: %curr = %{$current{'adhoc'}{$rolename}};
15149: }
15150: }
15151: }
15152: my $newpos = $env{'form.'.$prefix.'_pos'};
15153: $newpos =~ s/\D+//g;
15154: $allpos[$newpos] = $rolename;
15155: my $newdesc = $env{'form.'.$prefix.'_desc'};
15156: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
15157: if ($curr{'desc'}) {
15158: if ($curr{'desc'} ne $newdesc) {
15159: $changes{'customrole'}{$rolename}{'desc'} = 1;
15160: $newsettings{$rolename}{'desc'} = $newdesc;
15161: }
15162: } elsif ($newdesc ne '') {
15163: $changes{'customrole'}{$rolename}{'desc'} = 1;
15164: $newsettings{$rolename}{'desc'} = $newdesc;
15165: }
15166: my $access = $env{'form.'.$prefix.'_access'};
15167: if (grep(/^\Q$access\E$/,@accesstypes)) {
15168: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
15169: if ($access eq 'status') {
15170: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
15171: if (scalar(@statuses) == 0) {
1.289 raeburn 15172: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 15173: } else {
15174: my (@shownstatus,$numtypes);
15175: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15176: if (ref($types) eq 'ARRAY') {
15177: $numtypes = scalar(@{$types});
15178: foreach my $type (sort(@statuses)) {
15179: if ($type eq 'default') {
15180: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15181: } elsif (grep(/^\Q$type\E$/,@{$types})) {
15182: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15183: push(@shownstatus,$usertypes->{$type});
15184: }
15185: }
15186: }
15187: if (grep(/^default$/,@statuses)) {
15188: push(@shownstatus,$othertitle);
15189: }
15190: if (scalar(@shownstatus) == 1+$numtypes) {
15191: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
15192: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
15193: } else {
15194: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
15195: if (ref($curr{'status'}) eq 'ARRAY') {
15196: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15197: if (@diffs) {
15198: $changes{'customrole'}{$rolename}{$access} = 1;
15199: }
15200: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15201: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 15202: }
1.166 raeburn 15203: }
15204: }
1.285 raeburn 15205: } elsif (($access eq 'inc') || ($access eq 'exc')) {
15206: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
15207: my @newspecstaff;
15208: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15209: foreach my $person (sort(@personnel)) {
15210: if ($domhelpdesk{$person}) {
15211: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
15212: }
15213: }
15214: if (ref($curr{$access}) eq 'ARRAY') {
15215: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15216: if (@diffs) {
15217: $changes{'customrole'}{$rolename}{$access} = 1;
15218: }
15219: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15220: $changes{'customrole'}{$rolename}{$access} = 1;
15221: }
15222: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15223: my ($uname,$udom) = split(/:/,$person);
15224: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
15225: }
15226: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 15227: }
1.285 raeburn 15228: } else {
15229: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
15230: }
15231: unless ($curr{'access'} eq $access) {
15232: $changes{'customrole'}{$rolename}{'access'} = 1;
15233: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 15234: }
15235: }
1.285 raeburn 15236: if (@allpos > 0) {
15237: my $idx = 0;
15238: foreach my $rolename (@allpos) {
15239: if ($rolename ne '') {
15240: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
15241: if (ref($current{'adhoc'}) eq 'HASH') {
15242: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15243: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
15244: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 15245: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 15246: }
15247: }
1.282 raeburn 15248: }
1.285 raeburn 15249: $idx ++;
1.166 raeburn 15250: }
15251: }
1.118 jms 15252: }
1.123 jms 15253: my $putresult;
15254: if (keys(%changes) > 0) {
1.166 raeburn 15255: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 15256: if ($putresult eq 'ok') {
1.285 raeburn 15257: if (ref($helphash{'helpsettings'}) eq 'HASH') {
15258: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
15259: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
15260: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
15261: }
15262: }
15263: my $cachetime = 24*60*60;
15264: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15265: if (ref($lastactref) eq 'HASH') {
15266: $lastactref->{'domdefaults'} = 1;
15267: }
15268: } else {
15269: $errors .= '<li><span class="LC_error">'.
15270: &mt('An error occurred storing the settings: [_1]',
15271: $putresult).'</span></li>';
15272: }
15273: }
15274: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
15275: $resulttext = &mt('Changes made:').'<ul>';
15276: my (%shownprivs,@levelorder);
15277: @levelorder = ('c','d','s');
15278: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 15279: foreach my $item (sort(keys(%changes))) {
15280: if ($item eq 'submitbugs') {
15281: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
15282: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
15283: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 15284: } elsif ($item eq 'customrole') {
15285: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 15286: my @keyorder = ('order','desc','access','status','exc','inc');
15287: my %keytext = &Apache::lonlocal::texthash(
15288: order => 'Order',
15289: desc => 'Role description',
15290: access => 'Role usage',
1.300 droeschl 15291: status => 'Allowed institutional types',
1.285 raeburn 15292: exc => 'Allowed personnel',
15293: inc => 'Disallowed personnel',
15294: );
1.282 raeburn 15295: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 15296: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
15297: if ($role eq $newrole) {
15298: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
15299: $role).'<ul>';
15300: } else {
15301: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15302: $role).'<ul>';
15303: }
15304: foreach my $key (@keyorder) {
15305: if ($changes{'customrole'}{$role}{$key}) {
15306: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
15307: $keytext{$key},$newsettings{$role}{$key}).
15308: '</li>';
15309: }
15310: }
15311: if (ref($changedprivs{$role}) eq 'HASH') {
15312: $shownprivs{$role} = 1;
15313: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
15314: foreach my $level (@levelorder) {
15315: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
15316: next if ($item eq '');
15317: my ($priv) = split(/\&/,$item,2);
15318: if (&Apache::lonnet::plaintext($priv)) {
15319: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
15320: unless ($level eq 'c') {
15321: $resulttext .= ' ('.$lt{$level}.')';
15322: }
15323: $resulttext .= '</li>';
15324: }
15325: }
15326: }
15327: $resulttext .= '</ul>';
15328: }
15329: $resulttext .= '</ul></li>';
15330: }
15331: }
15332: }
15333: }
15334: }
15335: }
15336: if (keys(%changedprivs)) {
15337: foreach my $role (sort(keys(%changedprivs))) {
15338: unless ($shownprivs{$role}) {
15339: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15340: $role).'<ul>'.
15341: '<li>'.&mt('Privileges set to :').'<ul>';
15342: foreach my $level (@levelorder) {
15343: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
15344: next if ($item eq '');
15345: my ($priv) = split(/\&/,$item,2);
15346: if (&Apache::lonnet::plaintext($priv)) {
15347: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
15348: unless ($level eq 'c') {
15349: $resulttext .= ' ('.$lt{$level}.')';
15350: }
15351: $resulttext .= '</li>';
15352: }
1.282 raeburn 15353: }
15354: }
1.285 raeburn 15355: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 15356: }
15357: }
15358: }
1.285 raeburn 15359: $resulttext .= '</ul>';
15360: } else {
15361: $resulttext = &mt('No changes made to help settings');
1.118 jms 15362: }
15363: if ($errors) {
1.168 raeburn 15364: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 15365: $errors.'</ul>';
1.118 jms 15366: }
15367: return $resulttext;
15368: }
15369:
1.121 raeburn 15370: sub modify_coursedefaults {
1.212 raeburn 15371: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 15372: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 15373: my %defaultchecked = (
15374: 'canuse_pdfforms' => 'off',
15375: 'uselcmath' => 'on',
15376: 'usejsme' => 'on'
15377: );
15378: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 15379: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 15380: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
15381: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
15382: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 15383: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 15384: my %staticdefaults = (
15385: anonsurvey_threshold => 10,
15386: uploadquota => 500,
1.257 raeburn 15387: postsubmit => 60,
1.276 raeburn 15388: mysqltables => 172800,
1.198 raeburn 15389: );
1.314 raeburn 15390: my %texoptions = (
15391: MathJax => 'MathJax',
15392: mimetex => &mt('Convert to Images'),
15393: tth => &mt('TeX to HTML'),
15394: );
1.121 raeburn 15395: $defaultshash{'coursedefaults'} = {};
15396:
15397: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
15398: if ($domconfig{'coursedefaults'} eq '') {
15399: $domconfig{'coursedefaults'} = {};
15400: }
15401: }
15402:
15403: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
15404: foreach my $item (@toggles) {
15405: if ($defaultchecked{$item} eq 'on') {
15406: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15407: ($env{'form.'.$item} eq '0')) {
15408: $changes{$item} = 1;
1.192 raeburn 15409: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 15410: $changes{$item} = 1;
15411: }
15412: } elsif ($defaultchecked{$item} eq 'off') {
15413: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15414: ($env{'form.'.$item} eq '1')) {
15415: $changes{$item} = 1;
15416: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
15417: $changes{$item} = 1;
15418: }
15419: }
15420: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
15421: }
1.198 raeburn 15422: foreach my $item (@numbers) {
15423: my ($currdef,$newdef);
1.208 raeburn 15424: $newdef = $env{'form.'.$item};
1.198 raeburn 15425: if ($item eq 'anonsurvey_threshold') {
15426: $currdef = $domconfig{'coursedefaults'}{$item};
15427: $newdef =~ s/\D//g;
15428: if ($newdef eq '' || $newdef < 1) {
15429: $newdef = 1;
15430: }
15431: $defaultshash{'coursedefaults'}{$item} = $newdef;
15432: } else {
1.276 raeburn 15433: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
15434: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
15435: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 15436: }
15437: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 15438: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 15439: }
15440: if ($currdef ne $newdef) {
15441: my $staticdef;
15442: if ($item eq 'anonsurvey_threshold') {
15443: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
15444: $changes{$item} = 1;
15445: }
1.276 raeburn 15446: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 15447: my $setting = $1;
1.276 raeburn 15448: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
15449: $changes{$setting} = 1;
1.198 raeburn 15450: }
15451: }
1.139 raeburn 15452: }
15453: }
1.314 raeburn 15454: my $texengine;
15455: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
15456: $texengine = $env{'form.texengine'};
15457: if ($defaultshash{'coursedefaults'}{'texengine'} eq '') {
15458: unless ($texengine eq 'MathJax') {
15459: $changes{'texengine'} = 1;
15460: }
15461: } elsif ($defaultshash{'coursedefaults'}{'texengine'} ne $texengine) {
15462: $changes{'texengine'} = 1;
15463: }
15464: }
15465: if ($texengine ne '') {
15466: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
15467: }
1.264 raeburn 15468: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
15469: my @currclonecode;
15470: if (ref($currclone) eq 'HASH') {
15471: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
15472: @currclonecode = @{$currclone->{'instcode'}};
15473: }
15474: }
15475: my $newclone;
1.289 raeburn 15476: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 15477: $newclone = $env{'form.canclone'};
15478: }
15479: if ($newclone eq 'instcode') {
15480: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
15481: my (%codedefaults,@code_order,@clonecode);
15482: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
15483: \@code_order);
15484: foreach my $item (@code_order) {
15485: if (grep(/^\Q$item\E$/,@newcodes)) {
15486: push(@clonecode,$item);
15487: }
15488: }
15489: if (@clonecode) {
15490: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
15491: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
15492: if (@diffs) {
15493: $changes{'canclone'} = 1;
15494: }
15495: } else {
15496: $newclone eq '';
15497: }
15498: } elsif ($newclone ne '') {
1.289 raeburn 15499: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
15500: }
1.264 raeburn 15501: if ($newclone ne $currclone) {
15502: $changes{'canclone'} = 1;
15503: }
1.257 raeburn 15504: my %credits;
15505: foreach my $type (@types) {
15506: unless ($type eq 'community') {
15507: $credits{$type} = $env{'form.'.$type.'_credits'};
15508: $credits{$type} =~ s/[^\d.]+//g;
15509: }
15510: }
15511: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
15512: ($env{'form.coursecredits'} eq '1')) {
15513: $changes{'coursecredits'} = 1;
15514: foreach my $type (keys(%credits)) {
15515: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15516: }
15517: } else {
1.289 raeburn 15518: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 15519: foreach my $type (@types) {
15520: unless ($type eq 'community') {
1.289 raeburn 15521: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 15522: $changes{'coursecredits'} = 1;
15523: }
15524: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15525: }
15526: }
15527: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15528: foreach my $type (@types) {
15529: unless ($type eq 'community') {
15530: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
15531: $changes{'coursecredits'} = 1;
15532: last;
15533: }
15534: }
15535: }
15536: }
15537: }
15538: if ($env{'form.postsubmit'} eq '1') {
15539: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
15540: my %currtimeout;
15541: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15542: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
15543: $changes{'postsubmit'} = 1;
15544: }
15545: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15546: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
15547: }
15548: } else {
15549: $changes{'postsubmit'} = 1;
15550: }
15551: foreach my $type (@types) {
15552: my $timeout = $env{'form.'.$type.'_timeout'};
15553: $timeout =~ s/\D//g;
15554: if ($timeout == $staticdefaults{'postsubmit'}) {
15555: $timeout = '';
15556: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
15557: $timeout = '0';
15558: }
15559: unless ($timeout eq '') {
15560: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
15561: }
15562: if (exists($currtimeout{$type})) {
15563: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 15564: $changes{'postsubmit'} = 1;
1.257 raeburn 15565: }
15566: } elsif ($timeout ne '') {
15567: $changes{'postsubmit'} = 1;
15568: }
15569: }
15570: } else {
15571: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
15572: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15573: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
15574: $changes{'postsubmit'} = 1;
15575: }
15576: } else {
15577: $changes{'postsubmit'} = 1;
15578: }
1.192 raeburn 15579: }
1.121 raeburn 15580: }
15581: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
15582: $dom);
15583: if ($putresult eq 'ok') {
15584: if (keys(%changes) > 0) {
1.213 raeburn 15585: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 15586: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 15587: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.314 raeburn 15588: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
15589: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','texengine') {
1.257 raeburn 15590: if ($changes{$item}) {
15591: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
15592: }
1.289 raeburn 15593: }
1.192 raeburn 15594: if ($changes{'coursecredits'}) {
15595: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 15596: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
15597: $domdefaults{$type.'credits'} =
15598: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
15599: }
15600: }
15601: }
15602: if ($changes{'postsubmit'}) {
15603: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15604: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
15605: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15606: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
15607: $domdefaults{$type.'postsubtimeout'} =
15608: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15609: }
15610: }
1.192 raeburn 15611: }
15612: }
1.198 raeburn 15613: if ($changes{'uploadquota'}) {
15614: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15615: foreach my $type (@types) {
15616: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
15617: }
15618: }
15619: }
1.264 raeburn 15620: if ($changes{'canclone'}) {
15621: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15622: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15623: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
15624: if (@clonecodes) {
15625: $domdefaults{'canclone'} = join('+',@clonecodes);
15626: }
15627: }
15628: } else {
15629: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
15630: }
15631: }
1.121 raeburn 15632: my $cachetime = 24*60*60;
15633: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 15634: if (ref($lastactref) eq 'HASH') {
15635: $lastactref->{'domdefaults'} = 1;
15636: }
1.121 raeburn 15637: }
15638: $resulttext = &mt('Changes made:').'<ul>';
15639: foreach my $item (sort(keys(%changes))) {
15640: if ($item eq 'canuse_pdfforms') {
15641: if ($env{'form.'.$item} eq '1') {
15642: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
15643: } else {
15644: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
15645: }
1.257 raeburn 15646: } elsif ($item eq 'uselcmath') {
15647: if ($env{'form.'.$item} eq '1') {
15648: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
15649: } else {
15650: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
15651: }
15652: } elsif ($item eq 'usejsme') {
15653: if ($env{'form.'.$item} eq '1') {
15654: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
15655: } else {
1.289 raeburn 15656: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 15657: }
1.314 raeburn 15658: } elsif ($item eq 'texengine') {
15659: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
15660: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
15661: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
15662: }
1.139 raeburn 15663: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 15664: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 15665: } elsif ($item eq 'uploadquota') {
15666: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15667: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
15668: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
15669: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 15670: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 15671: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 15672: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
15673: '</ul>'.
15674: '</li>';
15675: } else {
15676: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
15677: }
1.276 raeburn 15678: } elsif ($item eq 'mysqltables') {
15679: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
15680: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
15681: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
15682: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
15683: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
15684: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
15685: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
15686: '</ul>'.
15687: '</li>';
15688: } else {
15689: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
15690: }
1.257 raeburn 15691: } elsif ($item eq 'postsubmit') {
15692: if ($domdefaults{'postsubmit'} eq 'off') {
15693: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
15694: } else {
15695: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 15696: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 15697: $resulttext .= &mt('durations:').'<ul>';
15698: foreach my $type (@types) {
15699: $resulttext .= '<li>';
15700: my $timeout;
15701: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15702: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15703: }
15704: my $display;
15705: if ($timeout eq '0') {
15706: $display = &mt('unlimited');
15707: } elsif ($timeout eq '') {
15708: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
15709: } else {
15710: $display = &mt('[quant,_1,second]',$timeout);
15711: }
15712: if ($type eq 'community') {
15713: $resulttext .= &mt('Communities');
15714: } elsif ($type eq 'official') {
15715: $resulttext .= &mt('Official courses');
15716: } elsif ($type eq 'unofficial') {
15717: $resulttext .= &mt('Unofficial courses');
15718: } elsif ($type eq 'textbook') {
15719: $resulttext .= &mt('Textbook courses');
1.271 raeburn 15720: } elsif ($type eq 'placement') {
15721: $resulttext .= &mt('Placement tests');
1.257 raeburn 15722: }
15723: $resulttext .= ' -- '.$display.'</li>';
15724: }
15725: $resulttext .= '</ul>';
15726: }
1.289 raeburn 15727: $resulttext .= '</li>';
1.257 raeburn 15728: }
1.192 raeburn 15729: } elsif ($item eq 'coursecredits') {
15730: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15731: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 15732: ($domdefaults{'unofficialcredits'} eq '') &&
15733: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 15734: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
15735: } else {
15736: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
15737: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
15738: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 15739: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 15740: '</ul>'.
15741: '</li>';
15742: }
15743: } else {
15744: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
15745: }
1.264 raeburn 15746: } elsif ($item eq 'canclone') {
15747: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15748: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15749: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
15750: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
15751: }
15752: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
15753: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
15754: } else {
1.289 raeburn 15755: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 15756: }
1.140 raeburn 15757: }
1.121 raeburn 15758: }
15759: $resulttext .= '</ul>';
15760: } else {
15761: $resulttext = &mt('No changes made to course defaults');
15762: }
15763: } else {
15764: $resulttext = '<span class="LC_error">'.
15765: &mt('An error occurred: [_1]',$putresult).'</span>';
15766: }
15767: return $resulttext;
15768: }
15769:
1.231 raeburn 15770: sub modify_selfenrollment {
15771: my ($dom,$lastactref,%domconfig) = @_;
15772: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 15773: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 15774: my %titles = &tool_titles();
1.232 raeburn 15775: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
15776: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 15777: $ordered{'default'} = ['types','registered','approval','limit'];
15778:
15779: my (%roles,%shown,%toplevel);
15780: $roles{'0'} = &Apache::lonnet::plaintext('dc');
15781:
15782: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
15783: if ($domconfig{'selfenrollment'} eq '') {
15784: $domconfig{'selfenrollment'} = {};
15785: }
15786: }
15787: %toplevel = (
15788: admin => 'Configuration Rights',
15789: default => 'Default settings',
15790: validation => 'Validation of self-enrollment requests',
15791: );
1.233 raeburn 15792: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 15793:
15794: if (ref($ordered{'admin'}) eq 'ARRAY') {
15795: foreach my $item (@{$ordered{'admin'}}) {
15796: foreach my $type (@types) {
15797: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
15798: $selfenrollhash{'admin'}{$type}{$item} = 1;
15799: } else {
15800: $selfenrollhash{'admin'}{$type}{$item} = 0;
15801: }
15802: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
15803: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
15804: if ($selfenrollhash{'admin'}{$type}{$item} ne
15805: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
15806: push(@{$changes{'admin'}{$type}},$item);
15807: }
15808: } else {
15809: if (!$selfenrollhash{'admin'}{$type}{$item}) {
15810: push(@{$changes{'admin'}{$type}},$item);
15811: }
15812: }
15813: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
15814: push(@{$changes{'admin'}{$type}},$item);
15815: }
15816: }
15817: }
15818: }
15819:
15820: foreach my $item (@{$ordered{'default'}}) {
15821: foreach my $type (@types) {
15822: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
15823: if ($item eq 'types') {
15824: unless (($value eq 'all') || ($value eq 'dom')) {
15825: $value = '';
15826: }
15827: } elsif ($item eq 'registered') {
15828: unless ($value eq '1') {
15829: $value = 0;
15830: }
15831: } elsif ($item eq 'approval') {
15832: unless ($value =~ /^[012]$/) {
15833: $value = 0;
15834: }
15835: } else {
15836: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
15837: $value = 'none';
15838: }
15839: }
15840: $selfenrollhash{'default'}{$type}{$item} = $value;
15841: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
15842: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
15843: if ($selfenrollhash{'default'}{$type}{$item} ne
15844: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
15845: push(@{$changes{'default'}{$type}},$item);
15846: }
15847: } else {
15848: push(@{$changes{'default'}{$type}},$item);
15849: }
15850: } else {
15851: push(@{$changes{'default'}{$type}},$item);
15852: }
15853: if ($item eq 'limit') {
15854: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
15855: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
15856: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
15857: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
15858: }
15859: } else {
15860: $selfenrollhash{'default'}{$type}{'cap'} = '';
15861: }
15862: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
15863: if ($selfenrollhash{'default'}{$type}{'cap'} ne
15864: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
15865: push(@{$changes{'default'}{$type}},'cap');
15866: }
15867: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
15868: push(@{$changes{'default'}{$type}},'cap');
15869: }
15870: }
15871: }
15872: }
15873:
15874: foreach my $item (@{$itemsref}) {
15875: if ($item eq 'fields') {
15876: my @changed;
15877: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
15878: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
15879: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
15880: }
15881: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
15882: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
15883: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
15884: $domconfig{'selfenrollment'}{'validation'}{$item});
15885: } else {
15886: @changed = @{$selfenrollhash{'validation'}{$item}};
15887: }
15888: } else {
15889: @changed = @{$selfenrollhash{'validation'}{$item}};
15890: }
15891: if (@changed) {
15892: if ($selfenrollhash{'validation'}{$item}) {
15893: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
15894: } else {
15895: $changes{'validation'}{$item} = &mt('None');
15896: }
15897: }
15898: } else {
15899: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
15900: if ($item eq 'markup') {
15901: if ($env{'form.selfenroll_validation_'.$item}) {
15902: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
15903: }
15904: }
15905: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
15906: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
15907: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
15908: }
15909: }
15910: }
15911: }
15912:
15913: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
15914: $dom);
15915: if ($putresult eq 'ok') {
15916: if (keys(%changes) > 0) {
15917: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15918: $resulttext = &mt('Changes made:').'<ul>';
15919: foreach my $key ('admin','default','validation') {
15920: if (ref($changes{$key}) eq 'HASH') {
15921: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
15922: if ($key eq 'validation') {
15923: foreach my $item (@{$itemsref}) {
15924: if (exists($changes{$key}{$item})) {
15925: if ($item eq 'markup') {
15926: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
15927: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
15928: } else {
15929: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
15930: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
15931: }
15932: }
15933: }
15934: } else {
15935: foreach my $type (@types) {
15936: if ($type eq 'community') {
15937: $roles{'1'} = &mt('Community personnel');
15938: } else {
15939: $roles{'1'} = &mt('Course personnel');
15940: }
15941: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 15942: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
15943: if ($key eq 'admin') {
15944: my @mgrdc = ();
15945: if (ref($ordered{$key}) eq 'ARRAY') {
15946: foreach my $item (@{$ordered{'admin'}}) {
15947: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
15948: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
15949: push(@mgrdc,$item);
15950: }
15951: }
15952: }
15953: if (@mgrdc) {
15954: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
15955: } else {
15956: delete($domdefaults{$type.'selfenrolladmdc'});
15957: }
15958: }
15959: } else {
15960: if (ref($ordered{$key}) eq 'ARRAY') {
15961: foreach my $item (@{$ordered{$key}}) {
15962: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
15963: $domdefaults{$type.'selfenroll'.$item} =
15964: $selfenrollhash{$key}{$type}{$item};
15965: }
15966: }
15967: }
15968: }
15969: }
1.231 raeburn 15970: $resulttext .= '<li>'.$titles{$type}.'<ul>';
15971: foreach my $item (@{$ordered{$key}}) {
15972: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
15973: $resulttext .= '<li>';
15974: if ($key eq 'admin') {
15975: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
15976: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
15977: } else {
15978: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
15979: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
15980: }
15981: $resulttext .= '</li>';
15982: }
15983: }
15984: $resulttext .= '</ul></li>';
15985: }
15986: }
15987: $resulttext .= '</ul></li>';
15988: }
15989: }
1.305 raeburn 15990: }
15991: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
15992: my $cachetime = 24*60*60;
15993: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15994: if (ref($lastactref) eq 'HASH') {
15995: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 15996: }
1.231 raeburn 15997: }
15998: $resulttext .= '</ul>';
15999: } else {
16000: $resulttext = &mt('No changes made to self-enrollment settings');
16001: }
16002: } else {
16003: $resulttext = '<span class="LC_error">'.
16004: &mt('An error occurred: [_1]',$putresult).'</span>';
16005: }
16006: return $resulttext;
16007: }
16008:
1.137 raeburn 16009: sub modify_usersessions {
1.212 raeburn 16010: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 16011: my @hostingtypes = ('version','excludedomain','includedomain');
16012: my @offloadtypes = ('primary','default');
16013: my %types = (
16014: remote => \@hostingtypes,
16015: hosted => \@hostingtypes,
16016: spares => \@offloadtypes,
16017: );
16018: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 16019: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 16020: my (%by_ip,%by_location,@intdoms,@instdoms);
16021: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 16022: my @locations = sort(keys(%by_location));
1.137 raeburn 16023: my (%defaultshash,%changes);
16024: foreach my $prefix (@prefixes) {
16025: $defaultshash{'usersessions'}{$prefix} = {};
16026: }
1.212 raeburn 16027: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 16028: my $resulttext;
1.138 raeburn 16029: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 16030: foreach my $prefix (@prefixes) {
1.145 raeburn 16031: next if ($prefix eq 'spares');
16032: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 16033: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16034: if ($type eq 'version') {
16035: my $value = $env{'form.'.$prefix.'_'.$type};
16036: my $okvalue;
16037: if ($value ne '') {
16038: if (grep(/^\Q$value\E$/,@lcversions)) {
16039: $okvalue = $value;
16040: }
16041: }
16042: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16043: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
16044: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
16045: if ($inuse == 0) {
16046: $changes{$prefix}{$type} = 1;
16047: } else {
16048: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
16049: $changes{$prefix}{$type} = 1;
16050: }
16051: if ($okvalue ne '') {
16052: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16053: }
16054: }
16055: } else {
16056: if (($inuse == 1) && ($okvalue ne '')) {
16057: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16058: $changes{$prefix}{$type} = 1;
16059: }
16060: }
16061: } else {
16062: if (($inuse == 1) && ($okvalue ne '')) {
16063: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16064: $changes{$prefix}{$type} = 1;
16065: }
16066: }
16067: } else {
16068: if (($inuse == 1) && ($okvalue ne '')) {
16069: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16070: $changes{$prefix}{$type} = 1;
16071: }
16072: }
16073: } else {
16074: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16075: my @okvals;
16076: foreach my $val (@vals) {
1.138 raeburn 16077: if ($val =~ /:/) {
16078: my @items = split(/:/,$val);
16079: foreach my $item (@items) {
16080: if (ref($by_location{$item}) eq 'ARRAY') {
16081: push(@okvals,$item);
16082: }
16083: }
16084: } else {
16085: if (ref($by_location{$val}) eq 'ARRAY') {
16086: push(@okvals,$val);
16087: }
1.137 raeburn 16088: }
16089: }
16090: @okvals = sort(@okvals);
16091: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16092: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
16093: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
16094: if ($inuse == 0) {
16095: $changes{$prefix}{$type} = 1;
16096: } else {
16097: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16098: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
16099: if (@changed > 0) {
16100: $changes{$prefix}{$type} = 1;
16101: }
16102: }
16103: } else {
16104: if ($inuse == 1) {
16105: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16106: $changes{$prefix}{$type} = 1;
16107: }
16108: }
16109: } else {
16110: if ($inuse == 1) {
16111: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16112: $changes{$prefix}{$type} = 1;
16113: }
16114: }
16115: } else {
16116: if ($inuse == 1) {
16117: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16118: $changes{$prefix}{$type} = 1;
16119: }
16120: }
16121: }
16122: }
16123: }
1.145 raeburn 16124:
16125: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 16126: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 16127: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
16128: my $savespares;
16129:
16130: foreach my $lonhost (sort(keys(%servers))) {
16131: my $serverhomeID =
16132: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 16133: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 16134: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
16135: my %spareschg;
16136: foreach my $type (@{$types{'spares'}}) {
16137: my @okspares;
16138: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
16139: foreach my $server (@checked) {
1.152 raeburn 16140: if (&Apache::lonnet::hostname($server) ne '') {
16141: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
16142: unless (grep(/^\Q$server\E$/,@okspares)) {
16143: push(@okspares,$server);
16144: }
1.145 raeburn 16145: }
16146: }
16147: }
16148: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
16149: my $newspare;
1.152 raeburn 16150: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
16151: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 16152: $newspare = $new;
16153: }
16154: }
1.152 raeburn 16155: my @spares;
16156: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
16157: @spares = sort(@okspares,$newspare);
16158: } else {
16159: @spares = sort(@okspares);
16160: }
16161: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 16162: if (ref($spareid{$lonhost}) eq 'HASH') {
16163: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 16164: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 16165: if (@diffs > 0) {
16166: $spareschg{$type} = 1;
16167: }
16168: }
16169: }
16170: }
16171: if (keys(%spareschg) > 0) {
16172: $changes{'spares'}{$lonhost} = \%spareschg;
16173: }
16174: }
1.261 raeburn 16175: $defaultshash{'usersessions'}{'offloadnow'} = {};
16176: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
16177: my @okoffload;
16178: if (@offloadnow) {
16179: foreach my $server (@offloadnow) {
16180: if (&Apache::lonnet::hostname($server) ne '') {
16181: unless (grep(/^\Q$server\E$/,@okoffload)) {
16182: push(@okoffload,$server);
16183: }
16184: }
16185: }
16186: if (@okoffload) {
16187: foreach my $lonhost (@okoffload) {
16188: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
16189: }
16190: }
16191: }
1.145 raeburn 16192: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16193: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
16194: if (ref($changes{'spares'}) eq 'HASH') {
16195: if (keys(%{$changes{'spares'}}) > 0) {
16196: $savespares = 1;
16197: }
16198: }
16199: } else {
16200: $savespares = 1;
16201: }
1.261 raeburn 16202: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
16203: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
16204: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
16205: $changes{'offloadnow'} = 1;
16206: last;
16207: }
16208: }
16209: unless ($changes{'offloadnow'}) {
1.289 raeburn 16210: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
1.261 raeburn 16211: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
16212: $changes{'offloadnow'} = 1;
16213: last;
16214: }
16215: }
16216: }
16217: } elsif (@okoffload) {
16218: $changes{'offloadnow'} = 1;
16219: }
16220: } elsif (@okoffload) {
16221: $changes{'offloadnow'} = 1;
1.145 raeburn 16222: }
1.147 raeburn 16223: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
16224: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 16225: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16226: $dom);
16227: if ($putresult eq 'ok') {
16228: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
16229: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
16230: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
16231: }
16232: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
16233: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
16234: }
1.261 raeburn 16235: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
16236: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
16237: }
1.137 raeburn 16238: }
16239: my $cachetime = 24*60*60;
16240: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 16241: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 16242: if (ref($lastactref) eq 'HASH') {
16243: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 16244: $lastactref->{'usersessions'} = 1;
1.212 raeburn 16245: }
1.147 raeburn 16246: if (keys(%changes) > 0) {
16247: my %lt = &usersession_titles();
16248: $resulttext = &mt('Changes made:').'<ul>';
16249: foreach my $prefix (@prefixes) {
16250: if (ref($changes{$prefix}) eq 'HASH') {
16251: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
16252: if ($prefix eq 'spares') {
16253: if (ref($changes{$prefix}) eq 'HASH') {
16254: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
16255: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 16256: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 16257: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
16258: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 16259: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
16260: foreach my $type (@{$types{$prefix}}) {
16261: if ($changes{$prefix}{$lonhost}{$type}) {
16262: my $offloadto = &mt('None');
16263: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
16264: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
16265: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
16266: }
1.145 raeburn 16267: }
1.147 raeburn 16268: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 16269: }
1.137 raeburn 16270: }
16271: }
1.147 raeburn 16272: $resulttext .= '</li>';
1.137 raeburn 16273: }
16274: }
1.147 raeburn 16275: } else {
16276: foreach my $type (@{$types{$prefix}}) {
16277: if (defined($changes{$prefix}{$type})) {
16278: my $newvalue;
16279: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
16280: if (ref($defaultshash{'usersessions'}{$prefix})) {
16281: if ($type eq 'version') {
16282: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
16283: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
16284: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
16285: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
16286: }
1.145 raeburn 16287: }
16288: }
16289: }
1.147 raeburn 16290: if ($newvalue eq '') {
16291: if ($type eq 'version') {
16292: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
16293: } else {
16294: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
16295: }
1.145 raeburn 16296: } else {
1.147 raeburn 16297: if ($type eq 'version') {
16298: $newvalue .= ' '.&mt('(or later)');
16299: }
16300: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 16301: }
1.137 raeburn 16302: }
16303: }
16304: }
1.147 raeburn 16305: $resulttext .= '</ul>';
1.137 raeburn 16306: }
16307: }
1.261 raeburn 16308: if ($changes{'offloadnow'}) {
16309: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
16310: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
16311: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
16312: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
16313: $resulttext .= '<li>'.$lonhost.'</li>';
16314: }
16315: $resulttext .= '</ul>';
16316: } else {
16317: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
16318: }
16319: } else {
16320: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
16321: }
16322: }
1.147 raeburn 16323: $resulttext .= '</ul>';
16324: } else {
16325: $resulttext = $nochgmsg;
1.137 raeburn 16326: }
16327: } else {
16328: $resulttext = '<span class="LC_error">'.
16329: &mt('An error occurred: [_1]',$putresult).'</span>';
16330: }
16331: } else {
1.147 raeburn 16332: $resulttext = $nochgmsg;
1.137 raeburn 16333: }
16334: return $resulttext;
16335: }
16336:
1.275 raeburn 16337: sub modify_ssl {
16338: my ($dom,$lastactref,%domconfig) = @_;
16339: my (%by_ip,%by_location,@intdoms,@instdoms);
16340: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
16341: my @locations = sort(keys(%by_location));
16342: my %servers = &Apache::lonnet::internet_dom_servers($dom);
16343: my (%defaultshash,%changes);
16344: my $action = 'ssl';
1.293 raeburn 16345: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 16346: foreach my $prefix (@prefixes) {
16347: $defaultshash{$action}{$prefix} = {};
16348: }
16349: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16350: my $resulttext;
16351: my %iphost = &Apache::lonnet::get_iphost();
16352: my @reptypes = ('certreq','nocertreq');
16353: my @connecttypes = ('dom','intdom','other');
16354: my %types = (
1.293 raeburn 16355: connto => \@connecttypes,
16356: connfrom => \@connecttypes,
16357: replication => \@reptypes,
1.275 raeburn 16358: );
16359: foreach my $prefix (sort(keys(%types))) {
16360: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 16361: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 16362: my $value = 'yes';
16363: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
16364: $value = $env{'form.'.$prefix.'_'.$type};
16365: }
1.335 ! raeburn 16366: if (ref($domconfig{$action}) eq 'HASH') {
! 16367: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
! 16368: if ($domconfig{$action}{$prefix}{$type} ne '') {
! 16369: if ($value ne $domconfig{$action}{$prefix}{$type}) {
! 16370: $changes{$prefix}{$type} = 1;
! 16371: }
! 16372: $defaultshash{$action}{$prefix}{$type} = $value;
! 16373: } else {
! 16374: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 16375: $changes{$prefix}{$type} = 1;
16376: }
16377: } else {
16378: $defaultshash{$action}{$prefix}{$type} = $value;
16379: $changes{$prefix}{$type} = 1;
16380: }
16381: } else {
16382: $defaultshash{$action}{$prefix}{$type} = $value;
16383: $changes{$prefix}{$type} = 1;
16384: }
16385: if (($type eq 'dom') && (keys(%servers) == 1)) {
16386: delete($changes{$prefix}{$type});
16387: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
16388: delete($changes{$prefix}{$type});
16389: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
16390: delete($changes{$prefix}{$type});
16391: }
16392: } elsif ($prefix eq 'replication') {
16393: if (@locations > 0) {
16394: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16395: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16396: my @okvals;
16397: foreach my $val (@vals) {
16398: if ($val =~ /:/) {
16399: my @items = split(/:/,$val);
16400: foreach my $item (@items) {
16401: if (ref($by_location{$item}) eq 'ARRAY') {
16402: push(@okvals,$item);
16403: }
16404: }
16405: } else {
16406: if (ref($by_location{$val}) eq 'ARRAY') {
16407: push(@okvals,$val);
16408: }
16409: }
16410: }
16411: @okvals = sort(@okvals);
16412: if (ref($domconfig{$action}) eq 'HASH') {
16413: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
16414: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
16415: if ($inuse == 0) {
16416: $changes{$prefix}{$type} = 1;
16417: } else {
16418: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16419: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
16420: if (@changed > 0) {
16421: $changes{$prefix}{$type} = 1;
16422: }
16423: }
16424: } else {
16425: if ($inuse == 1) {
16426: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16427: $changes{$prefix}{$type} = 1;
16428: }
16429: }
16430: } else {
16431: if ($inuse == 1) {
16432: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16433: $changes{$prefix}{$type} = 1;
16434: }
16435: }
16436: } else {
16437: if ($inuse == 1) {
16438: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16439: $changes{$prefix}{$type} = 1;
16440: }
16441: }
16442: }
16443: }
16444: }
16445: }
16446: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
16447: if (keys(%changes) > 0) {
16448: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16449: $dom);
16450: if ($putresult eq 'ok') {
16451: if (ref($defaultshash{$action}) eq 'HASH') {
16452: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
16453: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
16454: }
1.293 raeburn 16455: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 ! raeburn 16456: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 16457: }
16458: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 ! raeburn 16459: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 16460: }
16461: }
16462: my $cachetime = 24*60*60;
16463: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16464: if (ref($lastactref) eq 'HASH') {
16465: $lastactref->{'domdefaults'} = 1;
16466: }
16467: if (keys(%changes) > 0) {
16468: my %titles = &ssl_titles();
16469: $resulttext = &mt('Changes made:').'<ul>';
16470: foreach my $prefix (@prefixes) {
16471: if (ref($changes{$prefix}) eq 'HASH') {
16472: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
16473: foreach my $type (@{$types{$prefix}}) {
16474: if (defined($changes{$prefix}{$type})) {
16475: my $newvalue;
16476: if (ref($defaultshash{$action}) eq 'HASH') {
16477: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 16478: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 16479: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
16480: } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
16481: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
16482: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
16483: }
16484: }
16485: }
16486: if ($newvalue eq '') {
16487: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
16488: } else {
16489: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
16490: }
16491: }
16492: }
16493: }
16494: $resulttext .= '</ul>';
16495: }
16496: }
16497: } else {
16498: $resulttext = $nochgmsg;
16499: }
16500: } else {
16501: $resulttext = '<span class="LC_error">'.
16502: &mt('An error occurred: [_1]',$putresult).'</span>';
16503: }
16504: } else {
16505: $resulttext = $nochgmsg;
16506: }
16507: return $resulttext;
16508: }
16509:
1.279 raeburn 16510: sub modify_trust {
16511: my ($dom,$lastactref,%domconfig) = @_;
16512: my (%by_ip,%by_location,@intdoms,@instdoms);
16513: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
16514: my @locations = sort(keys(%by_location));
16515: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
16516: my @types = ('exc','inc');
16517: my (%defaultshash,%changes);
16518: foreach my $prefix (@prefixes) {
16519: $defaultshash{'trust'}{$prefix} = {};
16520: }
16521: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16522: my $resulttext;
16523: foreach my $prefix (@prefixes) {
16524: foreach my $type (@types) {
16525: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16526: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16527: my @okvals;
16528: foreach my $val (@vals) {
16529: if ($val =~ /:/) {
16530: my @items = split(/:/,$val);
16531: foreach my $item (@items) {
16532: if (ref($by_location{$item}) eq 'ARRAY') {
16533: push(@okvals,$item);
16534: }
16535: }
16536: } else {
16537: if (ref($by_location{$val}) eq 'ARRAY') {
16538: push(@okvals,$val);
16539: }
16540: }
16541: }
16542: @okvals = sort(@okvals);
16543: if (ref($domconfig{'trust'}) eq 'HASH') {
16544: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
16545: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
16546: if ($inuse == 0) {
16547: $changes{$prefix}{$type} = 1;
16548: } else {
16549: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16550: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
16551: if (@changed > 0) {
16552: $changes{$prefix}{$type} = 1;
16553: }
16554: }
16555: } else {
16556: if ($inuse == 1) {
16557: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16558: $changes{$prefix}{$type} = 1;
16559: }
16560: }
16561: } else {
16562: if ($inuse == 1) {
16563: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16564: $changes{$prefix}{$type} = 1;
16565: }
16566: }
16567: } else {
16568: if ($inuse == 1) {
16569: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16570: $changes{$prefix}{$type} = 1;
16571: }
16572: }
16573: }
16574: }
16575: my $nochgmsg = &mt('No changes made to trust settings.');
16576: if (keys(%changes) > 0) {
16577: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16578: $dom);
16579: if ($putresult eq 'ok') {
16580: if (ref($defaultshash{'trust'}) eq 'HASH') {
16581: foreach my $prefix (@prefixes) {
16582: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
16583: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
16584: }
16585: }
16586: }
16587: my $cachetime = 24*60*60;
16588: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16589: if (ref($lastactref) eq 'HASH') {
16590: $lastactref->{'domdefaults'} = 1;
16591: }
16592: if (keys(%changes) > 0) {
16593: my %lt = &trust_titles();
16594: $resulttext = &mt('Changes made:').'<ul>';
16595: foreach my $prefix (@prefixes) {
16596: if (ref($changes{$prefix}) eq 'HASH') {
16597: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
16598: foreach my $type (@types) {
16599: if (defined($changes{$prefix}{$type})) {
16600: my $newvalue;
16601: if (ref($defaultshash{'trust'}) eq 'HASH') {
16602: if (ref($defaultshash{'trust'}{$prefix})) {
16603: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
16604: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
16605: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
16606: }
16607: }
16608: }
16609: }
16610: if ($newvalue eq '') {
16611: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
16612: } else {
16613: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
16614: }
16615: }
16616: }
16617: $resulttext .= '</ul>';
16618: }
16619: }
16620: $resulttext .= '</ul>';
16621: } else {
16622: $resulttext = $nochgmsg;
16623: }
16624: } else {
16625: $resulttext = '<span class="LC_error">'.
16626: &mt('An error occurred: [_1]',$putresult).'</span>';
16627: }
16628: } else {
16629: $resulttext = $nochgmsg;
16630: }
16631: return $resulttext;
16632: }
16633:
1.150 raeburn 16634: sub modify_loadbalancing {
16635: my ($dom,%domconfig) = @_;
16636: my $primary_id = &Apache::lonnet::domain($dom,'primary');
16637: my $intdom = &Apache::lonnet::internet_dom($primary_id);
16638: my ($othertitle,$usertypes,$types) =
16639: &Apache::loncommon::sorted_inst_types($dom);
16640: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 16641: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 16642: my @sparestypes = ('primary','default');
16643: my %typetitles = &sparestype_titles();
16644: my $resulttext;
1.171 raeburn 16645: my (%currbalancer,%currtargets,%currrules,%existing);
16646: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
16647: %existing = %{$domconfig{'loadbalancing'}};
16648: }
16649: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
16650: \%currtargets,\%currrules);
16651: my ($saveloadbalancing,%defaultshash,%changes);
16652: my ($alltypes,$othertypes,$titles) =
16653: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
16654: my %ruletitles = &offloadtype_text();
16655: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
16656: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
16657: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
16658: if ($balancer eq '') {
16659: next;
16660: }
1.210 raeburn 16661: if (!exists($servers{$balancer})) {
1.171 raeburn 16662: if (exists($currbalancer{$balancer})) {
16663: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 16664: }
1.171 raeburn 16665: next;
16666: }
16667: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
16668: push(@{$changes{'delete'}},$balancer);
16669: next;
16670: }
16671: if (!exists($currbalancer{$balancer})) {
16672: push(@{$changes{'add'}},$balancer);
16673: }
16674: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
16675: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
16676: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
16677: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
16678: $saveloadbalancing = 1;
16679: }
16680: foreach my $sparetype (@sparestypes) {
16681: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
16682: my @offloadto;
16683: foreach my $target (@targets) {
16684: if (($servers{$target}) && ($target ne $balancer)) {
16685: if ($sparetype eq 'default') {
16686: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
16687: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 16688: }
16689: }
1.171 raeburn 16690: unless(grep(/^\Q$target\E$/,@offloadto)) {
16691: push(@offloadto,$target);
16692: }
1.150 raeburn 16693: }
16694: }
1.284 raeburn 16695: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
16696: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
16697: push(@offloadto,$balancer);
16698: }
16699: }
16700: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 16701: }
1.171 raeburn 16702: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 16703: foreach my $sparetype (@sparestypes) {
1.171 raeburn 16704: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
16705: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 16706: if (@targetdiffs > 0) {
1.171 raeburn 16707: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 16708: }
1.171 raeburn 16709: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16710: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16711: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 16712: }
16713: }
16714: }
16715: } else {
1.171 raeburn 16716: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 16717: foreach my $sparetype (@sparestypes) {
1.171 raeburn 16718: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16719: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16720: $changes{'curr'}{$balancer}{'targets'} = 1;
16721: }
1.150 raeburn 16722: }
16723: }
1.210 raeburn 16724: }
1.150 raeburn 16725: }
16726: my $ishomedom;
1.171 raeburn 16727: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
16728: $ishomedom = 1;
1.150 raeburn 16729: }
16730: if (ref($alltypes) eq 'ARRAY') {
16731: foreach my $type (@{$alltypes}) {
16732: my $rule;
1.210 raeburn 16733: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 16734: (!$ishomedom)) {
1.171 raeburn 16735: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
16736: }
16737: if ($rule eq 'specific') {
1.255 raeburn 16738: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 16739: if (exists($servers{$specifiedhost})) {
1.255 raeburn 16740: $rule = $specifiedhost;
16741: }
1.150 raeburn 16742: }
1.171 raeburn 16743: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
16744: if (ref($currrules{$balancer}) eq 'HASH') {
16745: if ($rule ne $currrules{$balancer}{$type}) {
16746: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 16747: }
16748: } elsif ($rule ne '') {
1.171 raeburn 16749: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 16750: }
16751: }
16752: }
1.171 raeburn 16753: }
16754: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
16755: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
16756: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
16757: $defaultshash{'loadbalancing'} = {};
16758: }
16759: my $putresult = &Apache::lonnet::put_dom('configuration',
16760: \%defaultshash,$dom);
16761: if ($putresult eq 'ok') {
16762: if (keys(%changes) > 0) {
1.252 raeburn 16763: my %toupdate;
1.171 raeburn 16764: if (ref($changes{'delete'}) eq 'ARRAY') {
16765: foreach my $balancer (sort(@{$changes{'delete'}})) {
16766: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 16767: $toupdate{$balancer} = 1;
1.150 raeburn 16768: }
1.171 raeburn 16769: }
16770: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 16771: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 16772: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 16773: $toupdate{$balancer} = 1;
1.171 raeburn 16774: }
16775: }
16776: if (ref($changes{'curr'}) eq 'HASH') {
16777: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 16778: $toupdate{$balancer} = 1;
1.171 raeburn 16779: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
16780: if ($changes{'curr'}{$balancer}{'targets'}) {
16781: my %offloadstr;
16782: foreach my $sparetype (@sparestypes) {
16783: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16784: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16785: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
16786: }
16787: }
1.150 raeburn 16788: }
1.171 raeburn 16789: if (keys(%offloadstr) == 0) {
16790: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 16791: } else {
1.171 raeburn 16792: my $showoffload;
16793: foreach my $sparetype (@sparestypes) {
16794: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
16795: if (defined($offloadstr{$sparetype})) {
16796: $showoffload .= $offloadstr{$sparetype};
16797: } else {
16798: $showoffload .= &mt('None');
16799: }
16800: $showoffload .= (' 'x3);
16801: }
16802: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 16803: }
16804: }
16805: }
1.171 raeburn 16806: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
16807: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
16808: foreach my $type (@{$alltypes}) {
16809: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
16810: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
16811: my $balancetext;
16812: if ($rule eq '') {
16813: $balancetext = $ruletitles{'default'};
1.209 raeburn 16814: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 16815: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 16816: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 16817: foreach my $sparetype (@sparestypes) {
16818: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16819: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
16820: }
16821: }
1.253 raeburn 16822: foreach my $item (@{$alltypes}) {
16823: next if ($item =~ /^_LC_ipchange/);
16824: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
16825: if ($hasrule eq 'homeserver') {
16826: map { $toupdate{$_} = 1; } (keys(%libraryservers));
16827: } else {
16828: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
16829: if ($servers{$hasrule}) {
16830: $toupdate{$hasrule} = 1;
16831: }
16832: }
16833: }
16834: }
1.254 raeburn 16835: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
16836: $balancetext = $ruletitles{$rule};
16837: } else {
16838: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
16839: $balancetext = $ruletitles{'particular'}.' '.$receiver;
16840: if ($receiver) {
16841: $toupdate{$receiver};
16842: }
16843: }
16844: } else {
16845: $balancetext = $ruletitles{$rule};
1.252 raeburn 16846: }
1.171 raeburn 16847: } else {
16848: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
16849: }
1.210 raeburn 16850: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 16851: }
16852: }
16853: }
16854: }
1.252 raeburn 16855: if (keys(%toupdate)) {
16856: my %thismachine;
16857: my $updatedhere;
16858: my $cachetime = 60*60*24;
16859: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
16860: foreach my $lonhost (keys(%toupdate)) {
16861: if ($thismachine{$lonhost}) {
16862: unless ($updatedhere) {
16863: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
16864: $defaultshash{'loadbalancing'},
16865: $cachetime);
16866: $updatedhere = 1;
16867: }
16868: } else {
16869: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
16870: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
16871: }
16872: }
16873: }
1.150 raeburn 16874: }
1.171 raeburn 16875: }
16876: if ($resulttext ne '') {
16877: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 16878: } else {
16879: $resulttext = $nochgmsg;
16880: }
16881: } else {
1.171 raeburn 16882: $resulttext = $nochgmsg;
1.150 raeburn 16883: }
16884: } else {
1.171 raeburn 16885: $resulttext = '<span class="LC_error">'.
16886: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 16887: }
16888: } else {
1.171 raeburn 16889: $resulttext = $nochgmsg;
1.150 raeburn 16890: }
16891: return $resulttext;
16892: }
16893:
1.48 raeburn 16894: sub recurse_check {
16895: my ($chkcats,$categories,$depth,$name) = @_;
16896: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
16897: my $chg = 0;
16898: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
16899: my $category = $chkcats->[$depth]{$name}[$j];
16900: my $item;
16901: if ($category eq '') {
16902: $chg ++;
16903: } else {
16904: my $deeper = $depth + 1;
16905: $item = &escape($category).':'.&escape($name).':'.$depth;
16906: if ($chg) {
16907: $categories->{$item} -= $chg;
16908: }
16909: &recurse_check($chkcats,$categories,$deeper,$category);
16910: $deeper --;
16911: }
16912: }
16913: }
16914: return;
16915: }
16916:
16917: sub recurse_cat_deletes {
16918: my ($item,$coursecategories,$deletions) = @_;
16919: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
16920: my $subdepth = $depth + 1;
16921: if (ref($coursecategories) eq 'HASH') {
16922: foreach my $subitem (keys(%{$coursecategories})) {
16923: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
16924: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
16925: delete($coursecategories->{$subitem});
16926: $deletions->{$subitem} = 1;
16927: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 16928: }
1.48 raeburn 16929: }
16930: }
16931: return;
16932: }
16933:
1.125 raeburn 16934: sub active_dc_picker {
1.191 raeburn 16935: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 16936: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 16937: my @domcoord = keys(%domcoords);
16938: if (keys(%currhash)) {
16939: foreach my $dc (keys(%currhash)) {
16940: unless (exists($domcoords{$dc})) {
16941: push(@domcoord,$dc);
16942: }
16943: }
16944: }
16945: @domcoord = sort(@domcoord);
1.210 raeburn 16946: my $numdcs = scalar(@domcoord);
1.191 raeburn 16947: my $rows = 0;
16948: my $table;
1.125 raeburn 16949: if ($numdcs > 1) {
1.191 raeburn 16950: $table = '<table>';
16951: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 16952: my $rem = $i%($numinrow);
16953: if ($rem == 0) {
16954: if ($i > 0) {
1.191 raeburn 16955: $table .= '</tr>';
1.125 raeburn 16956: }
1.191 raeburn 16957: $table .= '<tr>';
16958: $rows ++;
1.125 raeburn 16959: }
1.191 raeburn 16960: my $check = '';
16961: if ($inputtype eq 'radio') {
16962: if (keys(%currhash) == 0) {
16963: if (!$i) {
16964: $check = ' checked="checked"';
16965: }
16966: } elsif (exists($currhash{$domcoord[$i]})) {
16967: $check = ' checked="checked"';
16968: }
16969: } else {
16970: if (exists($currhash{$domcoord[$i]})) {
16971: $check = ' checked="checked"';
1.125 raeburn 16972: }
16973: }
1.191 raeburn 16974: if ($i == @domcoord - 1) {
1.125 raeburn 16975: my $colsleft = $numinrow - $rem;
16976: if ($colsleft > 1) {
1.191 raeburn 16977: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 16978: } else {
1.191 raeburn 16979: $table .= '<td class="LC_left_item">';
1.125 raeburn 16980: }
16981: } else {
1.191 raeburn 16982: $table .= '<td class="LC_left_item">';
16983: }
16984: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
16985: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
16986: $table .= '<span class="LC_nobreak"><label>'.
16987: '<input type="'.$inputtype.'" name="'.$name.'"'.
16988: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
16989: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 16990: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 16991: }
1.219 raeburn 16992: $table .= '</label></span></td>';
1.191 raeburn 16993: }
16994: $table .= '</tr></table>';
16995: } elsif ($numdcs == 1) {
1.219 raeburn 16996: my ($dcname,$dcdom) = split(':',$domcoord[0]);
16997: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 16998: if ($inputtype eq 'radio') {
1.247 raeburn 16999: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 17000: if ($user ne $dcname.':'.$dcdom) {
17001: $table .= ' ('.$dcname.':'.$dcdom.')';
17002: }
1.191 raeburn 17003: } else {
17004: my $check;
17005: if (exists($currhash{$domcoord[0]})) {
17006: $check = ' checked="checked"';
1.125 raeburn 17007: }
1.247 raeburn 17008: $table = '<span class="LC_nobreak"><label>'.
17009: '<input type="checkbox" name="'.$name.'" '.
17010: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 17011: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 17012: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 17013: }
1.220 raeburn 17014: $table .= '</label></span>';
1.191 raeburn 17015: $rows ++;
1.125 raeburn 17016: }
17017: }
1.191 raeburn 17018: return ($numdcs,$table,$rows);
1.125 raeburn 17019: }
17020:
1.137 raeburn 17021: sub usersession_titles {
17022: return &Apache::lonlocal::texthash(
17023: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
17024: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 17025: spares => 'Servers offloaded to, when busy',
1.137 raeburn 17026: version => 'LON-CAPA version requirement',
1.138 raeburn 17027: excludedomain => 'Allow all, but exclude specific domains',
17028: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 17029: primary => 'Primary (checked first)',
1.154 raeburn 17030: default => 'Default',
1.137 raeburn 17031: );
17032: }
17033:
1.152 raeburn 17034: sub id_for_thisdom {
17035: my (%servers) = @_;
17036: my %altids;
17037: foreach my $server (keys(%servers)) {
17038: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
17039: if ($serverhome ne $server) {
17040: $altids{$serverhome} = $server;
17041: }
17042: }
17043: return %altids;
17044: }
17045:
1.150 raeburn 17046: sub count_servers {
17047: my ($currbalancer,%servers) = @_;
17048: my (@spares,$numspares);
17049: foreach my $lonhost (sort(keys(%servers))) {
17050: next if ($currbalancer eq $lonhost);
17051: push(@spares,$lonhost);
17052: }
17053: if ($currbalancer) {
17054: $numspares = scalar(@spares);
17055: } else {
17056: $numspares = scalar(@spares) - 1;
17057: }
17058: return ($numspares,@spares);
17059: }
17060:
17061: sub lonbalance_targets_js {
1.171 raeburn 17062: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 17063: my $select = &mt('Select');
17064: my ($alltargets,$allishome,$allinsttypes,@alltypes);
17065: if (ref($servers) eq 'HASH') {
17066: $alltargets = join("','",sort(keys(%{$servers})));
17067: my @homedoms;
17068: foreach my $server (sort(keys(%{$servers}))) {
17069: if (&Apache::lonnet::host_domain($server) eq $dom) {
17070: push(@homedoms,'1');
17071: } else {
17072: push(@homedoms,'0');
17073: }
17074: }
17075: $allishome = join("','",@homedoms);
17076: }
17077: if (ref($types) eq 'ARRAY') {
17078: if (@{$types} > 0) {
17079: @alltypes = @{$types};
17080: }
17081: }
17082: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
17083: $allinsttypes = join("','",@alltypes);
1.171 raeburn 17084: my (%currbalancer,%currtargets,%currrules,%existing);
17085: if (ref($settings) eq 'HASH') {
17086: %existing = %{$settings};
17087: }
17088: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
17089: \%currtargets,\%currrules);
1.210 raeburn 17090: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 17091: return <<"END";
17092:
17093: <script type="text/javascript">
17094: // <![CDATA[
17095:
1.171 raeburn 17096: currBalancers = new Array('$balancers');
17097:
17098: function toggleTargets(balnum) {
17099: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
17100: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
17101: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
17102: var prevbalancer = prevhostitem.value;
17103: var baltotal = document.getElementById('loadbalancing_total').value;
17104: prevhostitem.value = balancer;
17105: if (prevbalancer != '') {
17106: var prevIdx = currBalancers.indexOf(prevbalancer);
17107: if (prevIdx != -1) {
17108: currBalancers.splice(prevIdx,1);
17109: }
17110: }
1.150 raeburn 17111: if (balancer == '') {
1.171 raeburn 17112: hideSpares(balnum);
1.150 raeburn 17113: } else {
1.171 raeburn 17114: var currIdx = currBalancers.indexOf(balancer);
17115: if (currIdx == -1) {
17116: currBalancers.push(balancer);
17117: }
1.150 raeburn 17118: var homedoms = new Array('$allishome');
1.171 raeburn 17119: var ishomedom = homedoms[lonhostitem.selectedIndex];
17120: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 17121: }
1.171 raeburn 17122: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 17123: return;
17124: }
17125:
1.171 raeburn 17126: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 17127: var alltargets = new Array('$alltargets');
17128: var insttypes = new Array('$allinsttypes');
1.151 raeburn 17129: var offloadtypes = new Array('primary','default');
17130:
1.171 raeburn 17131: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
17132: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 17133:
1.151 raeburn 17134: for (var i=0; i<offloadtypes.length; i++) {
17135: var count = 0;
17136: for (var j=0; j<alltargets.length; j++) {
17137: if (alltargets[j] != balancer) {
1.171 raeburn 17138: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
17139: item.value = alltargets[j];
17140: item.style.textAlign='left';
17141: item.style.textFace='normal';
17142: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
17143: if (currBalancers.indexOf(alltargets[j]) == -1) {
17144: item.disabled = '';
17145: } else {
17146: item.disabled = 'disabled';
17147: item.checked = false;
17148: }
1.151 raeburn 17149: count ++;
17150: }
1.150 raeburn 17151: }
17152: }
1.151 raeburn 17153: for (var k=0; k<insttypes.length; k++) {
17154: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 17155: if (ishomedom == 1) {
1.171 raeburn 17156: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
17157: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 17158: } else {
1.171 raeburn 17159: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
17160: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 17161: }
17162: } else {
1.171 raeburn 17163: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
17164: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 17165: }
1.151 raeburn 17166: if ((insttypes[k] != '_LC_external') &&
17167: ((insttypes[k] != '_LC_internetdom') ||
17168: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 17169: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
17170: item.options.length = 0;
17171: item.options[0] = new Option("","",true,true);
1.210 raeburn 17172: var idx = 0;
1.151 raeburn 17173: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 17174: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
17175: idx ++;
17176: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 17177: }
17178: }
17179: }
17180: }
17181: return;
17182: }
17183:
1.171 raeburn 17184: function hideSpares(balnum) {
1.150 raeburn 17185: var alltargets = new Array('$alltargets');
17186: var insttypes = new Array('$allinsttypes');
17187: var offloadtypes = new Array('primary','default');
17188:
1.171 raeburn 17189: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
17190: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 17191:
17192: var total = alltargets.length - 1;
17193: for (var i=0; i<offloadtypes; i++) {
17194: for (var j=0; j<total; j++) {
1.171 raeburn 17195: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
17196: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
17197: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 17198: }
1.150 raeburn 17199: }
17200: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 17201: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
17202: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 17203: if (insttypes[k] != '_LC_external') {
1.171 raeburn 17204: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
17205: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 17206: }
17207: }
17208: return;
17209: }
17210:
1.171 raeburn 17211: function checkOffloads(item,balnum,type) {
1.150 raeburn 17212: var alltargets = new Array('$alltargets');
17213: var offloadtypes = new Array('primary','default');
17214: if (item.checked) {
17215: var total = alltargets.length - 1;
17216: var other;
17217: if (type == offloadtypes[0]) {
1.151 raeburn 17218: other = offloadtypes[1];
1.150 raeburn 17219: } else {
1.151 raeburn 17220: other = offloadtypes[0];
1.150 raeburn 17221: }
17222: for (var i=0; i<total; i++) {
1.171 raeburn 17223: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 17224: if (server == item.value) {
1.171 raeburn 17225: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
17226: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 17227: }
17228: }
17229: }
17230: }
17231: return;
17232: }
17233:
1.171 raeburn 17234: function singleServerToggle(balnum,type) {
17235: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 17236: if (offloadtoSelIdx == 0) {
1.171 raeburn 17237: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
17238: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 17239:
17240: } else {
1.171 raeburn 17241: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
17242: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 17243: }
17244: return;
17245: }
17246:
1.171 raeburn 17247: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 17248: if (type == '_LC_external') {
1.171 raeburn 17249: return;
1.150 raeburn 17250: }
1.171 raeburn 17251: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 17252: for (var i=0; i<typesRules.length; i++) {
17253: if (formname.elements[typesRules[i]].checked) {
17254: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 17255: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
17256: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 17257: } else {
1.171 raeburn 17258: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
17259: }
17260: }
17261: }
17262: return;
17263: }
17264:
17265: function balancerDeleteChange(balnum) {
17266: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
17267: var baltotal = document.getElementById('loadbalancing_total').value;
17268: var addtarget;
17269: var removetarget;
17270: var action = 'delete';
17271: if (document.getElementById('loadbalancing_delete_'+balnum)) {
17272: var lonhost = hostitem.value;
17273: var currIdx = currBalancers.indexOf(lonhost);
17274: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
17275: if (currIdx != -1) {
17276: currBalancers.splice(currIdx,1);
17277: }
17278: addtarget = lonhost;
17279: } else {
17280: if (currIdx == -1) {
17281: currBalancers.push(lonhost);
17282: }
17283: removetarget = lonhost;
17284: action = 'undelete';
17285: }
17286: balancerChange(balnum,baltotal,action,addtarget,removetarget);
17287: }
17288: return;
17289: }
17290:
17291: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
17292: if (baltotal > 1) {
17293: var offloadtypes = new Array('primary','default');
17294: var alltargets = new Array('$alltargets');
17295: var insttypes = new Array('$allinsttypes');
17296: for (var i=0; i<baltotal; i++) {
17297: if (i != balnum) {
17298: for (var j=0; j<offloadtypes.length; j++) {
17299: var total = alltargets.length - 1;
17300: for (var k=0; k<total; k++) {
17301: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
17302: var server = serveritem.value;
17303: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
17304: if (server == addtarget) {
17305: serveritem.disabled = '';
17306: }
17307: }
17308: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
17309: if (server == removetarget) {
17310: serveritem.disabled = 'disabled';
17311: serveritem.checked = false;
17312: }
17313: }
17314: }
17315: }
17316: for (var j=0; j<insttypes.length; j++) {
17317: if (insttypes[j] != '_LC_external') {
17318: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
17319: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
17320: var currSel = singleserver.selectedIndex;
17321: var currVal = singleserver.options[currSel].value;
17322: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
17323: var numoptions = singleserver.options.length;
17324: var needsnew = 1;
17325: for (var k=0; k<numoptions; k++) {
17326: if (singleserver.options[k] == addtarget) {
17327: needsnew = 0;
17328: break;
17329: }
17330: }
17331: if (needsnew == 1) {
17332: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
17333: }
17334: }
17335: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
17336: singleserver.options.length = 0;
17337: if ((currVal) && (currVal != removetarget)) {
17338: singleserver.options[0] = new Option("","",false,false);
17339: } else {
17340: singleserver.options[0] = new Option("","",true,true);
17341: }
17342: var idx = 0;
17343: for (var m=0; m<alltargets.length; m++) {
17344: if (currBalancers.indexOf(alltargets[m]) == -1) {
17345: idx ++;
17346: if (currVal == alltargets[m]) {
17347: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
17348: } else {
17349: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
17350: }
17351: }
17352: }
17353: }
17354: }
17355: }
17356: }
1.150 raeburn 17357: }
17358: }
17359: }
17360: return;
17361: }
17362:
1.152 raeburn 17363: // ]]>
17364: </script>
17365:
17366: END
17367: }
17368:
17369: sub new_spares_js {
17370: my @sparestypes = ('primary','default');
17371: my $types = join("','",@sparestypes);
17372: my $select = &mt('Select');
17373: return <<"END";
17374:
17375: <script type="text/javascript">
17376: // <![CDATA[
17377:
17378: function updateNewSpares(formname,lonhost) {
17379: var types = new Array('$types');
17380: var include = new Array();
17381: var exclude = new Array();
17382: for (var i=0; i<types.length; i++) {
17383: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
17384: for (var j=0; j<spareboxes.length; j++) {
17385: if (formname.elements[spareboxes[j]].checked) {
17386: exclude.push(formname.elements[spareboxes[j]].value);
17387: } else {
17388: include.push(formname.elements[spareboxes[j]].value);
17389: }
17390: }
17391: }
17392: for (var i=0; i<types.length; i++) {
17393: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
17394: var selIdx = newSpare.selectedIndex;
17395: var currnew = newSpare.options[selIdx].value;
17396: var okSpares = new Array();
17397: for (var j=0; j<newSpare.options.length; j++) {
17398: var possible = newSpare.options[j].value;
17399: if (possible != '') {
17400: if (exclude.indexOf(possible) == -1) {
17401: okSpares.push(possible);
17402: } else {
17403: if (currnew == possible) {
17404: selIdx = 0;
17405: }
17406: }
17407: }
17408: }
17409: for (var k=0; k<include.length; k++) {
17410: if (okSpares.indexOf(include[k]) == -1) {
17411: okSpares.push(include[k]);
17412: }
17413: }
17414: okSpares.sort();
17415: newSpare.options.length = 0;
17416: if (selIdx == 0) {
17417: newSpare.options[0] = new Option("$select","",true,true);
17418: } else {
17419: newSpare.options[0] = new Option("$select","",false,false);
17420: }
17421: for (var m=0; m<okSpares.length; m++) {
17422: var idx = m+1;
17423: var selThis = 0;
17424: if (selIdx != 0) {
17425: if (okSpares[m] == currnew) {
17426: selThis = 1;
17427: }
17428: }
17429: if (selThis == 1) {
17430: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
17431: } else {
17432: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
17433: }
17434: }
17435: }
17436: return;
17437: }
17438:
17439: function checkNewSpares(lonhost,type) {
17440: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
17441: var chosen = newSpare.options[newSpare.selectedIndex].value;
17442: if (chosen != '') {
17443: var othertype;
17444: var othernewSpare;
17445: if (type == 'primary') {
17446: othernewSpare = document.getElementById('newspare_default_'+lonhost);
17447: }
17448: if (type == 'default') {
17449: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
17450: }
17451: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
17452: othernewSpare.selectedIndex = 0;
17453: }
17454: }
17455: return;
17456: }
17457:
17458: // ]]>
17459: </script>
17460:
17461: END
17462:
17463: }
17464:
17465: sub common_domprefs_js {
17466: return <<"END";
17467:
17468: <script type="text/javascript">
17469: // <![CDATA[
17470:
1.150 raeburn 17471: function getIndicesByName(formname,item) {
1.152 raeburn 17472: var group = new Array();
1.150 raeburn 17473: for (var i=0;i<formname.elements.length;i++) {
17474: if (formname.elements[i].name == item) {
1.152 raeburn 17475: group.push(formname.elements[i].id);
1.150 raeburn 17476: }
17477: }
1.152 raeburn 17478: return group;
1.150 raeburn 17479: }
17480:
17481: // ]]>
17482: </script>
17483:
17484: END
1.152 raeburn 17485:
1.150 raeburn 17486: }
17487:
1.165 raeburn 17488: sub recaptcha_js {
17489: my %lt = &captcha_phrases();
17490: return <<"END";
17491:
17492: <script type="text/javascript">
17493: // <![CDATA[
17494:
17495: function updateCaptcha(caller,context) {
17496: var privitem;
17497: var pubitem;
17498: var privtext;
17499: var pubtext;
1.269 raeburn 17500: var versionitem;
17501: var versiontext;
1.165 raeburn 17502: if (document.getElementById(context+'_recaptchapub')) {
17503: pubitem = document.getElementById(context+'_recaptchapub');
17504: } else {
17505: return;
17506: }
17507: if (document.getElementById(context+'_recaptchapriv')) {
17508: privitem = document.getElementById(context+'_recaptchapriv');
17509: } else {
17510: return;
17511: }
17512: if (document.getElementById(context+'_recaptchapubtxt')) {
17513: pubtext = document.getElementById(context+'_recaptchapubtxt');
17514: } else {
17515: return;
17516: }
17517: if (document.getElementById(context+'_recaptchaprivtxt')) {
17518: privtext = document.getElementById(context+'_recaptchaprivtxt');
17519: } else {
17520: return;
17521: }
1.269 raeburn 17522: if (document.getElementById(context+'_recaptchaversion')) {
17523: versionitem = document.getElementById(context+'_recaptchaversion');
17524: } else {
17525: return;
17526: }
17527: if (document.getElementById(context+'_recaptchavertxt')) {
17528: versiontext = document.getElementById(context+'_recaptchavertxt');
17529: } else {
17530: return;
17531: }
1.165 raeburn 17532: if (caller.checked) {
17533: if (caller.value == 'recaptcha') {
17534: pubitem.type = 'text';
17535: privitem.type = 'text';
17536: pubitem.size = '40';
17537: privitem.size = '40';
17538: pubtext.innerHTML = "$lt{'pub'}";
17539: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 17540: versionitem.type = 'text';
17541: versionitem.size = '3';
1.289 raeburn 17542: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 17543: } else {
17544: pubitem.type = 'hidden';
17545: privitem.type = 'hidden';
1.269 raeburn 17546: versionitem.type = 'hidden';
1.165 raeburn 17547: pubtext.innerHTML = '';
17548: privtext.innerHTML = '';
1.269 raeburn 17549: versiontext.innerHTML = '';
1.165 raeburn 17550: }
17551: }
17552: return;
17553: }
17554:
17555: // ]]>
17556: </script>
17557:
17558: END
17559:
17560: }
17561:
1.236 raeburn 17562: sub toggle_display_js {
1.192 raeburn 17563: return <<"END";
17564:
17565: <script type="text/javascript">
17566: // <![CDATA[
17567:
1.236 raeburn 17568: function toggleDisplay(domForm,caller) {
17569: if (document.getElementById(caller)) {
17570: var divitem = document.getElementById(caller);
17571: var optionsElement = domForm.coursecredits;
1.264 raeburn 17572: var checkval = 1;
17573: var dispval = 'block';
1.303 raeburn 17574: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 17575: if (caller == 'emailoptions') {
17576: optionsElement = domForm.cancreate_email;
17577: }
1.257 raeburn 17578: if (caller == 'studentsubmission') {
17579: optionsElement = domForm.postsubmit;
17580: }
1.264 raeburn 17581: if (caller == 'cloneinstcode') {
17582: optionsElement = domForm.canclone;
17583: checkval = 'instcode';
17584: }
1.303 raeburn 17585: if (selfcreateRegExp.test(caller)) {
17586: optionsElement = domForm.elements[caller];
17587: checkval = 'other';
17588: dispval = 'inline'
17589: }
1.236 raeburn 17590: if (optionsElement.length) {
1.192 raeburn 17591: var currval;
1.236 raeburn 17592: for (var i=0; i<optionsElement.length; i++) {
17593: if (optionsElement[i].checked) {
17594: currval = optionsElement[i].value;
1.192 raeburn 17595: }
17596: }
1.264 raeburn 17597: if (currval == checkval) {
17598: divitem.style.display = dispval;
1.192 raeburn 17599: } else {
1.236 raeburn 17600: divitem.style.display = 'none';
1.192 raeburn 17601: }
17602: }
17603: }
17604: return;
17605: }
17606:
17607: // ]]>
17608: </script>
17609:
17610: END
17611:
17612: }
17613:
1.165 raeburn 17614: sub captcha_phrases {
17615: return &Apache::lonlocal::texthash (
17616: priv => 'Private key',
17617: pub => 'Public key',
17618: original => 'original (CAPTCHA)',
17619: recaptcha => 'successor (ReCAPTCHA)',
17620: notused => 'unused',
1.289 raeburn 17621: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 17622: );
17623: }
17624:
1.205 raeburn 17625: sub devalidate_remote_domconfs {
1.212 raeburn 17626: my ($dom,$cachekeys) = @_;
17627: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 17628: my %servers = &Apache::lonnet::internet_dom_servers($dom);
17629: my %thismachine;
17630: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.295 raeburn 17631: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions','directorysrch');
1.260 raeburn 17632: if (keys(%servers)) {
1.205 raeburn 17633: foreach my $server (keys(%servers)) {
17634: next if ($thismachine{$server});
1.212 raeburn 17635: my @cached;
17636: foreach my $name (@posscached) {
17637: if ($cachekeys->{$name}) {
17638: push(@cached,&escape($name).':'.&escape($dom));
17639: }
17640: }
17641: if (@cached) {
17642: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
17643: }
1.205 raeburn 17644: }
17645: }
17646: return;
17647: }
17648:
1.3 raeburn 17649: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>