Annotation of loncom/interface/domainprefs.pm, revision 1.337
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.337 ! raeburn 4: # $Id: domainprefs.pm,v 1.336 2018/07/26 14:59:48 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) {
1.337 ! raeburn 2820: if ((setting == 'user') || (setting == 'crs') || (setting == 'passback')) {
1.320 raeburn 2821: var radioname = '';
2822: var divid = '';
2823: if (setting == 'user') {
2824: radioname = 'lti_mapuser_'+item;
2825: divid = 'lti_userfield_'+item;
1.337 ! raeburn 2826: } else if (settings == 'crs') {
1.320 raeburn 2827: radioname = 'lti_mapcrs_'+item;
2828: divid = 'lti_crsfield_'+item;
1.337 ! raeburn 2829: } else {
! 2830: radioname = 'lti_passbackformat_'+item;
! 2831: divid = 'lti_passback_'+item;
1.320 raeburn 2832: }
2833: var num = form.elements[radioname].length;
2834: if (num) {
2835: var setvis = '';
2836: for (var i=0; i<num; i++) {
2837: if (form.elements[radioname][i].checked) {
1.337 ! raeburn 2838: if (setting == 'passback') {
! 2839: if (form.elements[radioname][i].value == '1') {
! 2840: if (document.getElementById(divid)) {
! 2841: document.getElementById(divid).style.display = 'inline-block';
! 2842: }
! 2843: setvis = 1;
! 2844: break;
! 2845: }
! 2846: } else {
! 2847: if (form.elements[radioname][i].value == 'other') {
! 2848: if (document.getElementById(divid)) {
! 2849: document.getElementById(divid).style.display = 'inline-block';
! 2850: }
! 2851: setvis = 1;
! 2852: break;
1.320 raeburn 2853: }
2854: }
2855: }
2856: }
2857: if (!setvis) {
2858: if (document.getElementById(divid)) {
2859: document.getElementById(divid).style.display = 'none';
2860: }
2861: }
2862: }
2863: } else if ((setting == 'sec') || (setting == 'secsrc')) {
2864: var numsec = form.elements['lti_crssec_'+item].length;
2865: if (numsec) {
2866: var setvis = '';
2867: for (var i=0; i<numsec; i++) {
2868: if (form.elements['lti_crssec_'+item][i].checked) {
2869: if (form.elements['lti_crssec_'+item][i].value == '1') {
2870: if (document.getElementById('lti_crssecfield_'+item)) {
2871: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
2872: setvis = 1;
2873: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
2874: if (numsrcsec) {
2875: var setsrcvis = '';
2876: for (var j=0; j<numsrcsec; j++) {
2877: if (form.elements['lti_crssecsrc_'+item][j].checked) {
2878: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
2879: if (document.getElementById('lti_secsrcfield_'+item)) {
2880: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
2881: setsrcvis = 1;
2882: }
2883: }
2884: }
2885: }
2886: if (!setsrcvis) {
2887: if (document.getElementById('lti_secsrcfield_'+item)) {
2888: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
2889: }
2890: }
2891: }
2892: }
2893: }
2894: }
2895: }
2896: if (!setvis) {
2897: if (document.getElementById('lti_crssecfield_'+item)) {
2898: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
2899: }
2900: if (document.getElementById('lti_secsrcfield_'+item)) {
2901: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
2902: }
2903: }
2904: }
1.325 raeburn 2905: } else if (setting == 'lcauth') {
2906: var numauth = form.elements['lti_lcauth_'+item].length;
2907: if (numauth) {
2908: for (var i=0; i<numauth; i++) {
2909: if (form.elements['lti_lcauth_'+item][i].checked) {
2910: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
2911: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
2912: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
2913: } else {
2914: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
2915: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
2916: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
2917: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
2918: } else {
2919: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
2920: }
2921: }
2922: }
2923: }
2924: }
2925: }
2926: }
1.326 raeburn 2927: } else if (setting == 'lcmenu') {
2928: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
2929: var divid = 'lti_menufield_'+item;
2930: var setvis = '';
2931: for (var i=0; i<menus.length; i++) {
2932: var radioname = menus[i];
2933: var num = form.elements[radioname].length;
2934: if (num) {
2935: for (var j=0; j<num; j++) {
2936: if (form.elements[radioname][j].checked) {
2937: if (form.elements[radioname][j].value == '1') {
2938: if (document.getElementById(divid)) {
2939: document.getElementById(divid).style.display = 'inline-block';
2940: }
2941: setvis = 1;
2942: break;
2943: }
2944: }
2945: }
2946: }
2947: if (setvis == 1) {
2948: break;
2949: }
2950: }
2951: if (!setvis) {
2952: if (document.getElementById(divid)) {
2953: document.getElementById(divid).style.display = 'none';
2954: }
2955: }
1.320 raeburn 2956: }
2957: return;
2958: }
2959: // ]]>
2960: </script>
2961:
2962: ENDSCRIPT
2963: }
2964:
1.3 raeburn 2965: sub print_autoenroll {
1.30 raeburn 2966: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2967: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274 raeburn 2968: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2969: if (ref($settings) eq 'HASH') {
2970: if (exists($settings->{'run'})) {
2971: if ($settings->{'run'} eq '0') {
2972: $runoff = ' checked="checked" ';
2973: $runon = ' ';
2974: } else {
2975: $runon = ' checked="checked" ';
2976: $runoff = ' ';
2977: }
2978: } else {
2979: if ($autorun) {
2980: $runon = ' checked="checked" ';
2981: $runoff = ' ';
2982: } else {
2983: $runoff = ' checked="checked" ';
2984: $runon = ' ';
2985: }
2986: }
1.129 raeburn 2987: if (exists($settings->{'co-owners'})) {
2988: if ($settings->{'co-owners'} eq '0') {
2989: $coownersoff = ' checked="checked" ';
2990: $coownerson = ' ';
2991: } else {
2992: $coownerson = ' checked="checked" ';
2993: $coownersoff = ' ';
2994: }
2995: } else {
2996: $coownersoff = ' checked="checked" ';
2997: $coownerson = ' ';
2998: }
1.3 raeburn 2999: if (exists($settings->{'sender_domain'})) {
3000: $defdom = $settings->{'sender_domain'};
3001: }
1.274 raeburn 3002: if (exists($settings->{'autofailsafe'})) {
3003: $failsafe = $settings->{'autofailsafe'};
3004: }
1.14 raeburn 3005: } else {
3006: if ($autorun) {
3007: $runon = ' checked="checked" ';
3008: $runoff = ' ';
3009: } else {
3010: $runoff = ' checked="checked" ';
3011: $runon = ' ';
3012: }
1.3 raeburn 3013: }
3014: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 3015: my $notif_sender;
3016: if (ref($settings) eq 'HASH') {
3017: $notif_sender = $settings->{'sender_uname'};
3018: }
1.3 raeburn 3019: my $datatable='<tr class="LC_odd_row">'.
3020: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 3021: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3022: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 3023: $runon.' value="1" />'.&mt('Yes').'</label> '.
3024: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 3025: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3026: '</tr><tr>'.
3027: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 3028: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 3029: &mt('username').': '.
3030: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 3031: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 3032: ': '.$domform.'</span></td></tr>'.
3033: '<tr class="LC_odd_row">'.
3034: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3035: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3036: '<input type="radio" name="autoassign_coowners"'.
3037: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3038: '<label><input type="radio" name="autoassign_coowners"'.
3039: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 3040: '</tr><tr>'.
3041: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
3042: '<td class="LC_right_item"><span class="LC_nobreak">'.
3043: '<input type="text" name="autoenroll_failsafe"'.
1.333 raeburn 3044: ' value="'.$failsafe.'" size="4" /></span></td></tr>';
1.274 raeburn 3045: $$rowtotal += 4;
1.3 raeburn 3046: return $datatable;
3047: }
3048:
3049: sub print_autoupdate {
1.30 raeburn 3050: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 3051: my $datatable;
3052: if ($position eq 'top') {
3053: my $updateon = ' ';
3054: my $updateoff = ' checked="checked" ';
3055: my $classlistson = ' ';
3056: my $classlistsoff = ' checked="checked" ';
3057: if (ref($settings) eq 'HASH') {
3058: if ($settings->{'run'} eq '1') {
3059: $updateon = $updateoff;
3060: $updateoff = ' ';
3061: }
3062: if ($settings->{'classlists'} eq '1') {
3063: $classlistson = $classlistsoff;
3064: $classlistsoff = ' ';
3065: }
3066: }
3067: my %title = (
3068: run => 'Auto-update active?',
3069: classlists => 'Update information in classlists?',
3070: );
3071: $datatable = '<tr class="LC_odd_row">'.
3072: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 3073: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3074: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 3075: $updateon.' value="1" />'.&mt('Yes').'</label> '.
3076: '<label><input type="radio" name="autoupdate_run"'.
3077: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3078: '</tr><tr>'.
3079: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 3080: '<td class="LC_right_item"><span class="LC_nobreak">'.
3081: '<label><input type="radio" name="classlists"'.
3082: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
3083: '<label><input type="radio" name="classlists"'.
3084: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3085: '</tr>';
1.30 raeburn 3086: $$rowtotal += 2;
1.131 raeburn 3087: } elsif ($position eq 'middle') {
3088: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3089: my $numinrow = 3;
3090: my $locknamesettings;
3091: $datatable .= &insttypes_row($settings,$types,$usertypes,
3092: $dom,$numinrow,$othertitle,
1.305 raeburn 3093: 'lockablenames',$rowtotal);
1.131 raeburn 3094: $$rowtotal ++;
1.3 raeburn 3095: } else {
1.44 raeburn 3096: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3097: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3098: 'permanentemail','id');
1.33 raeburn 3099: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3100: my $numrows = 0;
1.26 raeburn 3101: if (ref($types) eq 'ARRAY') {
3102: if (@{$types} > 0) {
3103: $datatable =
3104: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3105: \@fields,$types,\$numrows);
1.30 raeburn 3106: $$rowtotal += @{$types};
1.26 raeburn 3107: }
1.3 raeburn 3108: }
3109: $datatable .=
3110: &usertype_update_row($settings,{'default' => $othertitle},
3111: \%fieldtitles,\@fields,['default'],
3112: \$numrows);
1.30 raeburn 3113: $$rowtotal ++;
1.3 raeburn 3114: }
3115: return $datatable;
3116: }
3117:
1.125 raeburn 3118: sub print_autocreate {
3119: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 3120: my (%createon,%createoff,%currhash);
1.125 raeburn 3121: my @types = ('xml','req');
3122: if (ref($settings) eq 'HASH') {
3123: foreach my $item (@types) {
3124: $createoff{$item} = ' checked="checked" ';
3125: $createon{$item} = ' ';
3126: if (exists($settings->{$item})) {
3127: if ($settings->{$item}) {
3128: $createon{$item} = ' checked="checked" ';
3129: $createoff{$item} = ' ';
3130: }
3131: }
3132: }
1.210 raeburn 3133: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 3134: $currhash{$settings->{'xmldc'}} = 1;
3135: }
1.125 raeburn 3136: } else {
3137: foreach my $item (@types) {
3138: $createoff{$item} = ' checked="checked" ';
3139: $createon{$item} = ' ';
3140: }
3141: }
3142: $$rowtotal += 2;
1.191 raeburn 3143: my $numinrow = 2;
1.125 raeburn 3144: my $datatable='<tr class="LC_odd_row">'.
3145: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3146: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3147: '<input type="radio" name="autocreate_xml"'.
3148: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3149: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 3150: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3151: '</td></tr><tr>'.
3152: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3153: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3154: '<input type="radio" name="autocreate_req"'.
3155: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3156: '<label><input type="radio" name="autocreate_req"'.
3157: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 3158: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3159: 'autocreate_xmldc',%currhash);
1.247 raeburn 3160: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 3161: if ($numdc > 1) {
1.247 raeburn 3162: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
3163: '</td><td class="LC_left_item">';
1.125 raeburn 3164: } else {
1.247 raeburn 3165: $datatable .= &mt('Course creation processed as:').
3166: '</td><td class="LC_right_item">';
1.125 raeburn 3167: }
1.247 raeburn 3168: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 3169: $$rowtotal += $rows;
1.125 raeburn 3170: return $datatable;
3171: }
3172:
1.23 raeburn 3173: sub print_directorysrch {
1.277 raeburn 3174: my ($position,$dom,$settings,$rowtotal) = @_;
3175: my $datatable;
3176: if ($position eq 'top') {
3177: my $instsrchon = ' ';
3178: my $instsrchoff = ' checked="checked" ';
3179: my ($exacton,$containson,$beginson);
3180: my $instlocalon = ' ';
3181: my $instlocaloff = ' checked="checked" ';
3182: if (ref($settings) eq 'HASH') {
3183: if ($settings->{'available'} eq '1') {
3184: $instsrchon = $instsrchoff;
3185: $instsrchoff = ' ';
3186: }
3187: if ($settings->{'localonly'} eq '1') {
3188: $instlocalon = $instlocaloff;
3189: $instlocaloff = ' ';
3190: }
3191: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
3192: foreach my $type (@{$settings->{'searchtypes'}}) {
3193: if ($type eq 'exact') {
3194: $exacton = ' checked="checked" ';
3195: } elsif ($type eq 'contains') {
3196: $containson = ' checked="checked" ';
3197: } elsif ($type eq 'begins') {
3198: $beginson = ' checked="checked" ';
3199: }
3200: }
3201: } else {
3202: if ($settings->{'searchtypes'} eq 'exact') {
3203: $exacton = ' checked="checked" ';
3204: } elsif ($settings->{'searchtypes'} eq 'contains') {
3205: $containson = ' checked="checked" ';
3206: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 3207: $exacton = ' checked="checked" ';
3208: $containson = ' checked="checked" ';
3209: }
3210: }
1.277 raeburn 3211: }
3212: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3213: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3214:
3215: my $numinrow = 4;
3216: my $cansrchrow = 0;
3217: $datatable='<tr class="LC_odd_row">'.
3218: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
3219: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3220: '<input type="radio" name="dirsrch_available"'.
3221: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
3222: '<label><input type="radio" name="dirsrch_available"'.
3223: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3224: '</tr><tr>'.
3225: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
3226: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3227: '<input type="radio" name="dirsrch_instlocalonly"'.
3228: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3229: '<label><input type="radio" name="dirsrch_instlocalonly"'.
3230: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3231: '</tr>';
3232: $$rowtotal += 2;
3233: if (ref($usertypes) eq 'HASH') {
3234: if (keys(%{$usertypes}) > 0) {
3235: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 3236: $numinrow,$othertitle,'cansearch',
3237: $rowtotal);
1.277 raeburn 3238: $cansrchrow = 1;
1.25 raeburn 3239: }
1.23 raeburn 3240: }
1.277 raeburn 3241: if ($cansrchrow) {
3242: $$rowtotal ++;
3243: $datatable .= '<tr>';
3244: } else {
3245: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 3246: }
1.277 raeburn 3247: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
3248: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
3249: foreach my $title (@{$titleorder}) {
3250: if (defined($searchtitles->{$title})) {
3251: my $check = ' ';
3252: if (ref($settings) eq 'HASH') {
3253: if (ref($settings->{'searchby'}) eq 'ARRAY') {
3254: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
3255: $check = ' checked="checked" ';
3256: }
1.39 raeburn 3257: }
1.25 raeburn 3258: }
1.277 raeburn 3259: $datatable .= '<td class="LC_left_item">'.
3260: '<span class="LC_nobreak"><label>'.
3261: '<input type="checkbox" name="searchby" '.
3262: 'value="'.$title.'"'.$check.'/>'.
3263: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 3264: }
3265: }
1.277 raeburn 3266: $datatable .= '</tr></table></td></tr>';
3267: $$rowtotal ++;
3268: if ($cansrchrow) {
3269: $datatable .= '<tr class="LC_odd_row">';
3270: } else {
3271: $datatable .= '<tr>';
3272: }
3273: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
3274: '<td class="LC_left_item" colspan="2">'.
3275: '<span class="LC_nobreak"><label>'.
3276: '<input type="checkbox" name="searchtypes" '.
3277: $exacton.' value="exact" />'.&mt('Exact match').
3278: '</label> '.
3279: '<label><input type="checkbox" name="searchtypes" '.
3280: $beginson.' value="begins" />'.&mt('Begins with').
3281: '</label> '.
3282: '<label><input type="checkbox" name="searchtypes" '.
3283: $containson.' value="contains" />'.&mt('Contains').
3284: '</label></span></td></tr>';
3285: $$rowtotal ++;
1.26 raeburn 3286: } else {
1.277 raeburn 3287: my $domsrchon = ' checked="checked" ';
3288: my $domsrchoff = ' ';
3289: my $domlocalon = ' ';
3290: my $domlocaloff = ' checked="checked" ';
3291: if (ref($settings) eq 'HASH') {
3292: if ($settings->{'lclocalonly'} eq '1') {
3293: $domlocalon = $domlocaloff;
3294: $domlocaloff = ' ';
3295: }
3296: if ($settings->{'lcavailable'} eq '0') {
3297: $domsrchoff = $domsrchon;
3298: $domsrchon = ' ';
3299: }
3300: }
3301: $datatable='<tr class="LC_odd_row">'.
3302: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
3303: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3304: '<input type="radio" name="dirsrch_domavailable"'.
3305: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
3306: '<label><input type="radio" name="dirsrch_domavailable"'.
3307: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3308: '</tr><tr>'.
3309: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
3310: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3311: '<input type="radio" name="dirsrch_domlocalonly"'.
3312: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3313: '<label><input type="radio" name="dirsrch_domlocalonly"'.
3314: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3315: '</tr>';
3316: $$rowtotal += 2;
1.26 raeburn 3317: }
1.25 raeburn 3318: return $datatable;
3319: }
3320:
1.28 raeburn 3321: sub print_contacts {
1.286 raeburn 3322: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 3323: my $datatable;
3324: my @contacts = ('adminemail','supportemail');
1.286 raeburn 3325: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
3326: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings);
3327: if ($position eq 'top') {
3328: if (ref($settings) eq 'HASH') {
3329: foreach my $item (@contacts) {
3330: if (exists($settings->{$item})) {
3331: $to{$item} = $settings->{$item};
3332: }
3333: }
3334: }
3335: } elsif ($position eq 'middle') {
3336: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
3337: 'updatesmail','idconflictsmail');
1.288 raeburn 3338: foreach my $type (@mailings) {
3339: $otheremails{$type} = '';
3340: }
1.286 raeburn 3341: } else {
3342: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 3343: foreach my $type (@mailings) {
3344: $otheremails{$type} = '';
3345: }
1.286 raeburn 3346: $bccemails{'helpdeskmail'} = '';
3347: $bccemails{'otherdomsmail'} = '';
3348: $includestr{'helpdeskmail'} = '';
3349: $includestr{'otherdomsmail'} = '';
3350: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3351: }
1.28 raeburn 3352: if (ref($settings) eq 'HASH') {
1.286 raeburn 3353: unless ($position eq 'top') {
3354: foreach my $type (@mailings) {
3355: if (exists($settings->{$type})) {
3356: if (ref($settings->{$type}) eq 'HASH') {
3357: foreach my $item (@contacts) {
3358: if ($settings->{$type}{$item}) {
3359: $checked{$type}{$item} = ' checked="checked" ';
3360: }
3361: }
3362: $otheremails{$type} = $settings->{$type}{'others'};
3363: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3364: $bccemails{$type} = $settings->{$type}{'bcc'};
3365: if ($settings->{$type}{'include'} ne '') {
3366: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3367: $includestr{$type} = &unescape($includestr{$type});
3368: }
3369: }
3370: }
3371: } elsif ($type eq 'lonstatusmail') {
3372: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3373: }
1.28 raeburn 3374: }
3375: }
1.286 raeburn 3376: if ($position eq 'bottom') {
3377: foreach my $type (@mailings) {
3378: $bccemails{$type} = $settings->{$type}{'bcc'};
3379: if ($settings->{$type}{'include'} ne '') {
3380: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3381: $includestr{$type} = &unescape($includestr{$type});
3382: }
3383: }
3384: if (ref($settings->{'helpform'}) eq 'HASH') {
3385: if (ref($fields) eq 'ARRAY') {
3386: foreach my $field (@{$fields}) {
3387: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3388: }
1.286 raeburn 3389: }
3390: if (exists($settings->{'helpform'}{'maxsize'})) {
3391: $maxsize = $settings->{'helpform'}{'maxsize'};
3392: } else {
1.289 raeburn 3393: $maxsize = '1.0';
1.286 raeburn 3394: }
3395: } else {
3396: if (ref($fields) eq 'ARRAY') {
3397: foreach my $field (@{$fields}) {
3398: $currfield{$field} = 'yes';
1.134 raeburn 3399: }
1.28 raeburn 3400: }
1.286 raeburn 3401: $maxsize = '1.0';
1.28 raeburn 3402: }
3403: }
3404: } else {
1.286 raeburn 3405: if ($position eq 'top') {
3406: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3407: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3408: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3409: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 3410: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 3411: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3412: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3413: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
3414: } elsif ($position eq 'bottom') {
3415: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3416: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3417: if (ref($fields) eq 'ARRAY') {
3418: foreach my $field (@{$fields}) {
3419: $currfield{$field} = 'yes';
3420: }
3421: }
3422: $maxsize = '1.0';
3423: }
1.28 raeburn 3424: }
3425: my ($titles,$short_titles) = &contact_titles();
3426: my $rownum = 0;
3427: my $css_class;
1.286 raeburn 3428: if ($position eq 'top') {
3429: foreach my $item (@contacts) {
3430: $css_class = $rownum%2?' class="LC_odd_row"':'';
3431: $datatable .= '<tr'.$css_class.'>'.
3432: '<td><span class="LC_nobreak">'.$titles->{$item}.
3433: '</span></td><td class="LC_right_item">'.
3434: '<input type="text" name="'.$item.'" value="'.
3435: $to{$item}.'" /></td></tr>';
3436: $rownum ++;
3437: }
1.315 raeburn 3438: } elsif ($position eq 'bottom') {
3439: $css_class = $rownum%2?' class="LC_odd_row"':'';
3440: $datatable .= '<tr'.$css_class.'>'.
3441: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3442: &mt('(e-mail, subject, and description always shown)').
3443: '</td><td class="LC_left_item">';
3444: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3445: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3446: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3447: foreach my $field (@{$fields}) {
3448: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3449: if (($field eq 'screenshot') || ($field eq 'cc')) {
3450: $datatable .= ' '.&mt('(logged-in users)');
3451: }
3452: $datatable .='</td><td>';
3453: my $clickaction;
3454: if ($field eq 'screenshot') {
3455: $clickaction = ' onclick="screenshotSize(this);"';
3456: }
3457: if (ref($possoptions->{$field}) eq 'ARRAY') {
3458: foreach my $option (@{$possoptions->{$field}}) {
3459: my $checked;
3460: if ($currfield{$field} eq $option) {
3461: $checked = ' checked="checked"';
3462: }
3463: $datatable .= '<span class="LC_nobreak"><label>'.
3464: '<input type="radio" name="helpform_'.$field.'" '.
3465: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3466: '</label></span>'.(' 'x2);
3467: }
3468: }
3469: if ($field eq 'screenshot') {
3470: my $display;
3471: if ($currfield{$field} eq 'no') {
3472: $display = ' style="display:none"';
3473: }
1.334 raeburn 3474: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 3475: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3476: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3477: }
3478: $datatable .= '</td></tr>';
3479: }
3480: $datatable .= '</table>';
3481: }
3482: $datatable .= '</td></tr>'."\n";
3483: $rownum ++;
3484: }
3485: unless ($position eq 'top') {
1.286 raeburn 3486: foreach my $type (@mailings) {
3487: $css_class = $rownum%2?' class="LC_odd_row"':'';
3488: $datatable .= '<tr'.$css_class.'>'.
3489: '<td><span class="LC_nobreak">'.
3490: $titles->{$type}.': </span></td>'.
3491: '<td class="LC_left_item">';
3492: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3493: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3494: }
3495: $datatable .= '<span class="LC_nobreak">';
3496: foreach my $item (@contacts) {
3497: $datatable .= '<label>'.
3498: '<input type="checkbox" name="'.$type.'"'.
3499: $checked{$type}{$item}.
3500: ' value="'.$item.'" />'.$short_titles->{$item}.
3501: '</label> ';
3502: }
3503: $datatable .= '</span><br />'.&mt('Others').': '.
3504: '<input type="text" name="'.$type.'_others" '.
3505: 'value="'.$otheremails{$type}.'" />';
3506: my %locchecked;
3507: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3508: foreach my $loc ('s','b') {
3509: if ($includeloc{$type} eq $loc) {
3510: $locchecked{$loc} = ' checked="checked"';
3511: last;
3512: }
3513: }
3514: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3515: '<input type="text" name="'.$type.'_bcc" '.
3516: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3517: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3518: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 3519: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 3520: '<span class="LC_nobreak">'.&mt('Location:').' '.
3521: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3522: (' 'x2).
3523: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3524: '</span></fieldset>';
3525: }
3526: $datatable .= '</td></tr>'."\n";
3527: $rownum ++;
3528: }
1.28 raeburn 3529: }
1.286 raeburn 3530: if ($position eq 'middle') {
3531: my %choices;
3532: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
1.289 raeburn 3533: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3534: &mt('LON-CAPA core group - MSU'),600,500));
1.286 raeburn 3535: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
3536: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3537: &mt('LON-CAPA core group - MSU'),600,500));
3538: my @toggles = ('reporterrors','reportupdates');
3539: my %defaultchecked = ('reporterrors' => 'on',
3540: 'reportupdates' => 'on');
3541: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3542: \%choices,$rownum);
3543: $datatable .= $reports;
3544: } elsif ($position eq 'bottom') {
1.315 raeburn 3545: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3546: my (@posstypes,%usertypeshash);
3547: if (ref($types) eq 'ARRAY') {
3548: @posstypes = @{$types};
3549: }
3550: if (@posstypes) {
3551: if (ref($usertypes) eq 'HASH') {
3552: %usertypeshash = %{$usertypes};
3553: }
3554: my @overridden;
3555: my $numinrow = 4;
3556: if (ref($settings) eq 'HASH') {
3557: if (ref($settings->{'overrides'}) eq 'HASH') {
3558: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
3559: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
3560: push(@overridden,$key);
3561: foreach my $item (@contacts) {
3562: if ($settings->{'overrides'}{$key}{$item}) {
3563: $checked{'override_'.$key}{$item} = ' checked="checked" ';
3564: }
3565: }
3566: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
3567: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
3568: $includeloc{'override_'.$key} = '';
3569: $includestr{'override_'.$key} = '';
3570: if ($settings->{'overrides'}{$key}{'include'} ne '') {
3571: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
3572: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
3573: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
3574: }
1.286 raeburn 3575: }
3576: }
3577: }
1.315 raeburn 3578: }
3579: my $customclass = 'LC_helpdesk_override';
3580: my $optionsprefix = 'LC_options_helpdesk_';
3581:
3582: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
3583:
3584: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
3585: $numinrow,$othertitle,'overrides',
3586: \$rownum,$onclicktypes,$customclass);
3587: $rownum ++;
3588: $usertypeshash{'default'} = $othertitle;
3589: foreach my $status (@posstypes) {
3590: my $css_class;
3591: if ($rownum%2) {
3592: $css_class = 'LC_odd_row ';
3593: }
3594: $css_class .= $customclass;
3595: my $rowid = $optionsprefix.$status;
3596: my $hidden = 1;
3597: my $currstyle = 'display:none';
3598: if (grep(/^\Q$status\E$/,@overridden)) {
3599: $currstyle = 'display:table-row';
3600: $hidden = 0;
3601: }
3602: my $key = 'override_'.$status;
3603: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
3604: $includeloc{$key},$includestr{$key},$status,$rowid,
3605: $usertypeshash{$status},$css_class,$currstyle,
3606: \@contacts,$short_titles);
3607: unless ($hidden) {
3608: $rownum ++;
1.286 raeburn 3609: }
3610: }
1.134 raeburn 3611: }
1.28 raeburn 3612: }
1.30 raeburn 3613: $$rowtotal += $rownum;
1.28 raeburn 3614: return $datatable;
3615: }
3616:
1.315 raeburn 3617: sub overridden_helpdesk {
3618: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
3619: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
3620: my $class = 'LC_left_item';
3621: if ($css_class) {
3622: $css_class = ' class="'.$css_class.'"';
3623: }
3624: if ($rowid) {
3625: $rowid = ' id="'.$rowid.'"';
3626: }
3627: if ($rowstyle) {
3628: $rowstyle = ' style="'.$rowstyle.'"';
3629: }
3630: my ($output,$description);
3631: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
3632: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
3633: "<td>$description</td>\n".
3634: '<td class="'.$class.'" colspan="2">'.
3635: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
3636: '<span class="LC_nobreak">';
3637: if (ref($contacts) eq 'ARRAY') {
3638: foreach my $item (@{$contacts}) {
3639: my $check;
3640: if (ref($checked) eq 'HASH') {
3641: $check = $checked->{$item};
3642: }
3643: my $title;
3644: if (ref($short_titles) eq 'HASH') {
3645: $title = $short_titles->{$item};
3646: }
3647: $output .= '<label>'.
3648: '<input type="checkbox" name="override_'.$type.'"'.$check.
3649: ' value="'.$item.'" />'.$title.'</label> ';
3650: }
3651: }
3652: $output .= '</span><br />'.&mt('Others').': '.
3653: '<input type="text" name="override_'.$type.'_others" '.
3654: 'value="'.$otheremails.'" />';
3655: my %locchecked;
3656: foreach my $loc ('s','b') {
3657: if ($includeloc eq $loc) {
3658: $locchecked{$loc} = ' checked="checked"';
3659: last;
3660: }
3661: }
3662: $output .= '<br />'.&mt('Bcc:').(' 'x6).
3663: '<input type="text" name="override_'.$type.'_bcc" '.
3664: 'value="'.$bccemails.'" /></fieldset>'.
3665: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3666: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 3667: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 3668: '<span class="LC_nobreak">'.&mt('Location:').' '.
3669: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3670: (' 'x2).
3671: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3672: '</span></fieldset>'.
3673: '</td></tr>'."\n";
3674: return $output;
3675: }
3676:
1.286 raeburn 3677: sub contacts_javascript {
3678: return <<"ENDSCRIPT";
3679:
3680: <script type="text/javascript">
3681: // <![CDATA[
3682:
3683: function screenshotSize(field) {
3684: if (document.getElementById('help_screenshotsize')) {
3685: if (field.value == 'no') {
1.289 raeburn 3686: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 3687: } else {
3688: document.getElementById('help_screenshotsize').style.display="";
3689: }
3690: }
3691: return;
3692: }
3693:
1.315 raeburn 3694: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
3695: if (form.elements[checkbox].length != undefined) {
3696: var count = 0;
3697: if (docount) {
3698: for (var i=0; i<form.elements[checkbox].length; i++) {
3699: if (form.elements[checkbox][i].checked) {
3700: count ++;
3701: }
3702: }
3703: }
3704: for (var i=0; i<form.elements[checkbox].length; i++) {
3705: var type = form.elements[checkbox][i].value;
3706: if (document.getElementById(prefix+type)) {
3707: if (form.elements[checkbox][i].checked) {
3708: document.getElementById(prefix+type).style.display = 'table-row';
3709: if (count % 2 == 1) {
3710: document.getElementById(prefix+type).className = target+' LC_odd_row';
3711: } else {
3712: document.getElementById(prefix+type).className = target;
3713: }
3714: count ++;
3715: } else {
3716: document.getElementById(prefix+type).style.display = 'none';
3717: }
3718: }
3719: }
3720: }
3721: return;
3722: }
3723:
3724:
1.286 raeburn 3725: // ]]>
3726: </script>
3727:
3728: ENDSCRIPT
3729: }
3730:
1.118 jms 3731: sub print_helpsettings {
1.282 raeburn 3732: my ($position,$dom,$settings,$rowtotal) = @_;
3733: my $confname = $dom.'-domainconfig';
1.285 raeburn 3734: my $formname = 'display';
1.168 raeburn 3735: my ($datatable,$itemcount);
1.282 raeburn 3736: if ($position eq 'top') {
3737: $itemcount = 1;
3738: my (%choices,%defaultchecked,@toggles);
3739: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3740: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3741: &mt('LON-CAPA bug tracker'),600,500));
3742: %defaultchecked = ('submitbugs' => 'on');
3743: @toggles = ('submitbugs');
3744: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3745: \%choices,$itemcount);
3746: $$rowtotal ++;
3747: } else {
3748: my $css_class;
3749: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 3750: my (%customroles,%ordered,%current);
1.301 raeburn 3751: if (ref($settings) eq 'HASH') {
3752: if (ref($settings->{'adhoc'}) eq 'HASH') {
3753: %current = %{$settings->{'adhoc'}};
3754: }
1.285 raeburn 3755: }
3756: my $count = 0;
3757: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 3758: if ($key=~/^rolesdef\_(\w+)$/) {
3759: my $rolename = $1;
1.285 raeburn 3760: my (%privs,$order);
1.282 raeburn 3761: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3762: $customroles{$rolename} = \%privs;
1.285 raeburn 3763: if (ref($current{$rolename}) eq 'HASH') {
3764: $order = $current{$rolename}{'order'};
3765: }
3766: if ($order eq '') {
3767: $order = $count;
3768: }
3769: $ordered{$order} = $rolename;
3770: $count++;
3771: }
3772: }
3773: my $maxnum = scalar(keys(%ordered));
3774: my @roles_by_num = ();
3775: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3776: push(@roles_by_num,$item);
3777: }
3778: my $context = 'domprefs';
3779: my $crstype = 'Course';
3780: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 3781: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 3782: my ($numstatustypes,@jsarray);
3783: if (ref($types) eq 'ARRAY') {
3784: if (@{$types} > 0) {
3785: $numstatustypes = scalar(@{$types});
3786: push(@accesstypes,'status');
3787: @jsarray = ('bystatus');
1.282 raeburn 3788: }
3789: }
1.290 raeburn 3790: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 3791: if (keys(%domhelpdesk)) {
3792: push(@accesstypes,('inc','exc'));
3793: push(@jsarray,('notinc','notexc'));
3794: }
3795: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 3796: my $context = 'domprefs';
3797: my $crstype = 'Course';
1.285 raeburn 3798: my $prefix = 'helproles_';
3799: my $add_class = 'LC_hidden';
3800: foreach my $num (@roles_by_num) {
3801: my $role = $ordered{$num};
3802: my ($desc,$access,@statuses);
3803: if (ref($current{$role}) eq 'HASH') {
3804: $desc = $current{$role}{'desc'};
3805: $access = $current{$role}{'access'};
3806: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3807: @statuses = @{$current{$role}{'insttypes'}};
3808: }
3809: }
3810: if ($desc eq '') {
3811: $desc = $role;
3812: }
3813: my $identifier = 'custhelp'.$num;
1.282 raeburn 3814: my %full=();
3815: my %levels= (
3816: course => {},
3817: domain => {},
3818: system => {},
3819: );
3820: my %levelscurrent=(
3821: course => {},
3822: domain => {},
3823: system => {},
3824: );
3825: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3826: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3827: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 3828: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 3829: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 3830: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3831: for (my $k=0; $k<=$maxnum; $k++) {
3832: my $vpos = $k+1;
3833: my $selstr;
3834: if ($k == $num) {
3835: $selstr = ' selected="selected" ';
3836: }
3837: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3838: }
3839: $datatable .= '</select>'.(' 'x2).
3840: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3841: '</td>'.
3842: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3843: &mt('Name shown to users:').
3844: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3845: '</fieldset>'.
3846: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3847: $othertitle,$usertypes,$types,\%domhelpdesk).
3848: '<fieldset>'.
3849: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 3850: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 3851: \%levelscurrent,$identifier,
3852: 'LC_hidden',$prefix.$num.'_privs').
3853: '</fieldset></td>';
1.282 raeburn 3854: $itemcount ++;
3855: }
3856: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3857: my $newcust = 'custhelp'.$count;
3858: my (%privs,%levelscurrent);
3859: my %full=();
3860: my %levels= (
3861: course => {},
3862: domain => {},
3863: system => {},
3864: );
3865: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3866: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 3867: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 3868: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 3869: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3870: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3871: for (my $k=0; $k<$maxnum+1; $k++) {
3872: my $vpos = $k+1;
3873: my $selstr;
3874: if ($k == $maxnum) {
3875: $selstr = ' selected="selected" ';
3876: }
3877: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3878: }
3879: $datatable .= '</select> '."\n".
1.282 raeburn 3880: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3881: '</label></span></td>'.
1.285 raeburn 3882: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3883: '<span class="LC_nobreak">'.
3884: &mt('Internal name:').
3885: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3886: '</span>'.(' 'x4).
3887: '<span class="LC_nobreak">'.
3888: &mt('Name shown to users:').
3889: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3890: '</span></fieldset>'.
3891: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3892: $usertypes,$types,\%domhelpdesk).
3893: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 3894: &Apache::lonuserutils::custom_role_header($context,$crstype,
3895: \@templateroles,$newcust).
3896: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3897: \%levelscurrent,$newcust).
1.334 raeburn 3898: '</fieldset>'.
3899: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
3900: '</td></tr>';
1.282 raeburn 3901: $count ++;
3902: $$rowtotal += $count;
3903: }
1.166 raeburn 3904: return $datatable;
1.121 raeburn 3905: }
3906:
1.285 raeburn 3907: sub adhocbutton {
3908: my ($prefix,$num,$field,$visibility) = @_;
3909: my %lt = &Apache::lonlocal::texthash(
3910: show => 'Show details',
3911: hide => 'Hide details',
3912: );
3913: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3914: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3915: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3916: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3917: }
3918:
3919: sub helpsettings_javascript {
3920: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3921: return unless(ref($roles_by_num) eq 'ARRAY');
3922: my %html_js_lt = &Apache::lonlocal::texthash(
3923: show => 'Show details',
3924: hide => 'Hide details',
3925: );
3926: &html_escape(\%html_js_lt);
3927: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3928: return <<"ENDSCRIPT";
3929: <script type="text/javascript">
3930: // <![CDATA[
3931:
3932: function reorderHelpRoles(form,item) {
3933: var changedVal;
3934: $jstext
3935: var newpos = 'helproles_${total}_pos';
3936: var maxh = 1 + $total;
3937: var current = new Array();
3938: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3939: if (item == newpos) {
3940: changedVal = newitemVal;
3941: } else {
3942: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3943: current[newitemVal] = newpos;
3944: }
3945: for (var i=0; i<helproles.length; i++) {
3946: var elementName = 'helproles_'+helproles[i]+'_pos';
3947: if (elementName != item) {
3948: if (form.elements[elementName]) {
3949: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3950: current[currVal] = elementName;
3951: }
3952: }
3953: }
3954: var oldVal;
3955: for (var j=0; j<maxh; j++) {
3956: if (current[j] == undefined) {
3957: oldVal = j;
3958: }
3959: }
3960: if (oldVal < changedVal) {
3961: for (var k=oldVal+1; k<=changedVal ; k++) {
3962: var elementName = current[k];
3963: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3964: }
3965: } else {
3966: for (var k=changedVal; k<oldVal; k++) {
3967: var elementName = current[k];
3968: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3969: }
3970: }
3971: return;
3972: }
3973:
3974: function helpdeskAccess(num) {
3975: var curraccess = null;
3976: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3977: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3978: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3979: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3980: }
3981: }
3982: }
3983: var shown = Array();
3984: var hidden = Array();
3985: if (curraccess == 'none') {
3986: hidden = Array('$hiddenstr');
3987: } else {
3988: if (curraccess == 'status') {
3989: shown = Array('bystatus');
3990: hidden = Array('notinc','notexc');
3991: } else {
3992: if (curraccess == 'exc') {
3993: shown = Array('notexc');
3994: hidden = Array('notinc','bystatus');
3995: }
3996: if (curraccess == 'inc') {
3997: shown = Array('notinc');
3998: hidden = Array('notexc','bystatus');
3999: }
1.293 raeburn 4000: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 4001: hidden = Array('notinc','notexc','bystatus');
4002: }
4003: }
4004: }
4005: if (hidden.length > 0) {
4006: for (var i=0; i<hidden.length; i++) {
4007: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
4008: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
4009: }
4010: }
4011: }
4012: if (shown.length > 0) {
4013: for (var i=0; i<shown.length; i++) {
4014: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
4015: if (shown[i] == 'privs') {
4016: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4017: } else {
4018: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4019: }
4020: }
4021: }
4022: }
4023: return;
4024: }
4025:
4026: function toggleHelpdeskItem(num,field) {
4027: if (document.getElementById('helproles_'+num+'_'+field)) {
4028: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 4029: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 4030: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4031: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4032: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4033: }
4034: } else {
4035: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4036: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4037: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4038: }
4039: }
4040: }
4041: return;
4042: }
4043:
4044: // ]]>
4045: </script>
4046:
4047: ENDSCRIPT
4048: }
4049:
4050: sub helpdeskroles_access {
4051: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4052: $usertypes,$types,$domhelpdesk) = @_;
4053: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
4054: my %lt = &Apache::lonlocal::texthash(
4055: 'rou' => 'Role usage',
4056: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 4057: 'all' => 'All with domain helpdesk or helpdesk assistant role',
4058: 'dh' => 'All with domain helpdesk role',
4059: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 4060: 'none' => 'None',
4061: 'status' => 'Determined based on institutional status',
4062: 'inc' => 'Include all, but exclude specific personnel',
4063: 'exc' => 'Exclude all, but include specific personnel',
4064: );
4065: my %usecheck = (
4066: all => ' checked="checked"',
4067: );
4068: my %displaydiv = (
4069: status => 'none',
4070: inc => 'none',
4071: exc => 'none',
4072: priv => 'block',
4073: );
4074: my $output;
4075: if (ref($current) eq 'HASH') {
4076: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
4077: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
4078: $usecheck{$current->{access}} = $usecheck{'all'};
4079: delete($usecheck{'all'});
4080: if ($current->{access} =~ /^(status|inc|exc)$/) {
4081: my $access = $1;
4082: $displaydiv{$access} = 'inline';
4083: } elsif ($current->{access} eq 'none') {
4084: $displaydiv{'priv'} = 'none';
4085: }
4086: }
4087: }
4088: }
4089: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
4090: '<p>'.$lt{'whi'}.'</p>';
4091: foreach my $access (@{$accesstypes}) {
4092: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
4093: ' onclick="helpdeskAccess('."'$num'".');" />'.
4094: $lt{$access}.'</label>';
4095: if ($access eq 'status') {
4096: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
4097: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
4098: $othertitle,$usertypes,$types).
4099: '</div>';
4100: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
4101: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
4102: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4103: '</div>';
4104: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
4105: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
4106: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4107: '</div>';
4108: }
4109: $output .= '</p>';
4110: }
4111: $output .= '</fieldset>';
4112: return $output;
4113: }
4114:
1.121 raeburn 4115: sub radiobutton_prefs {
1.192 raeburn 4116: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 4117: $additional,$align) = @_;
1.121 raeburn 4118: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
4119: (ref($choices) eq 'HASH'));
4120:
1.170 raeburn 4121: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 4122:
4123: foreach my $item (@{$toggles}) {
4124: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 4125: $checkedon{$item} = ' checked="checked" ';
4126: $checkedoff{$item} = ' ';
1.121 raeburn 4127: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 4128: $checkedoff{$item} = ' checked="checked" ';
4129: $checkedon{$item} = ' ';
4130: }
4131: }
4132: if (ref($settings) eq 'HASH') {
1.121 raeburn 4133: foreach my $item (@{$toggles}) {
1.118 jms 4134: if ($settings->{$item} eq '1') {
4135: $checkedon{$item} = ' checked="checked" ';
4136: $checkedoff{$item} = ' ';
4137: } elsif ($settings->{$item} eq '0') {
4138: $checkedoff{$item} = ' checked="checked" ';
4139: $checkedon{$item} = ' ';
4140: }
4141: }
1.121 raeburn 4142: }
1.192 raeburn 4143: if ($onclick) {
4144: $onclick = ' onclick="'.$onclick.'"';
4145: }
1.121 raeburn 4146: foreach my $item (@{$toggles}) {
1.118 jms 4147: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 4148: $datatable .=
1.306 raeburn 4149: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 4150: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 4151: '</span></td>';
4152: if ($align eq 'left') {
4153: $datatable .= '<td class="LC_left_item">';
4154: } else {
4155: $datatable .= '<td class="LC_right_item">';
4156: }
1.289 raeburn 4157: $datatable .=
1.257 raeburn 4158: '<span class="LC_nobreak">'.
1.118 jms 4159: '<label><input type="radio" name="'.
1.192 raeburn 4160: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 4161: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 4162: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
4163: '</span>'.$additional.
4164: '</td>'.
1.118 jms 4165: '</tr>';
4166: $itemcount ++;
1.121 raeburn 4167: }
4168: return ($datatable,$itemcount);
4169: }
4170:
1.267 raeburn 4171: sub print_ltitools {
4172: my ($dom,$settings,$rowtotal) = @_;
4173: my $rownum = 0;
4174: my $css_class;
4175: my $itemcount = 1;
4176: my $maxnum = 0;
4177: my %ordered;
4178: if (ref($settings) eq 'HASH') {
4179: foreach my $item (keys(%{$settings})) {
4180: if (ref($settings->{$item}) eq 'HASH') {
4181: my $num = $settings->{$item}{'order'};
4182: $ordered{$num} = $item;
4183: }
4184: }
4185: }
4186: my $confname = $dom.'-domainconfig';
4187: my $switchserver = &check_switchserver($dom,$confname);
4188: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 4189: my $datatable;
1.267 raeburn 4190: my %lt = <itools_names();
4191: my @courseroles = ('cc','in','ta','ep','st');
4192: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1.324 raeburn 4193: my @fields = ('fullname','firstname','lastname','email','roles','user');
1.267 raeburn 4194: if (keys(%ordered)) {
4195: my @items = sort { $a <=> $b } keys(%ordered);
4196: for (my $i=0; $i<@items; $i++) {
4197: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4198: my $item = $ordered{$items[$i]};
1.323 raeburn 4199: my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
1.267 raeburn 4200: if (ref($settings->{$item}) eq 'HASH') {
4201: $title = $settings->{$item}->{'title'};
4202: $url = $settings->{$item}->{'url'};
4203: $key = $settings->{$item}->{'key'};
4204: $secret = $settings->{$item}->{'secret'};
1.322 raeburn 4205: $lifetime = $settings->{$item}->{'lifetime'};
1.267 raeburn 4206: my $image = $settings->{$item}->{'image'};
4207: if ($image ne '') {
4208: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
4209: }
1.323 raeburn 4210: if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
4211: $sigsel{'HMAC-256'} = ' selected="selected"';
4212: } else {
4213: $sigsel{'HMAC-SHA1'} = ' selected="selected"';
4214: }
1.267 raeburn 4215: }
1.319 raeburn 4216: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1.267 raeburn 4217: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4218: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
4219: for (my $k=0; $k<=$maxnum; $k++) {
4220: my $vpos = $k+1;
4221: my $selstr;
4222: if ($k == $i) {
4223: $selstr = ' selected="selected" ';
4224: }
4225: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4226: }
4227: $datatable .= '</select>'.(' 'x2).
4228: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
4229: &mt('Delete?').'</label></span></td>'.
4230: '<td colspan="2">'.
4231: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4232: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
1.267 raeburn 4233: (' 'x2).
4234: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
4235: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4236: (' 'x2).
4237: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
4238: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4239: (' 'x2).
4240: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
4241: '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
4242: '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
1.267 raeburn 4243: '<br /><br />'.
1.323 raeburn 4244: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
1.267 raeburn 4245: ' value="'.$url.'" /></span>'.
4246: (' 'x2).
1.319 raeburn 4247: '<span class="LC_nobreak">'.$lt{'key'}.':'.
1.267 raeburn 4248: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
4249: (' 'x2).
1.322 raeburn 4250: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
4251: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
4252: (' 'x2).
1.267 raeburn 4253: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4254: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
4255: '<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>'.
4256: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
4257: '</fieldset>'.
4258: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4259: '<span class="LC_nobreak">'.&mt('Display target:');
4260: my %currdisp;
4261: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
4262: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
4263: $currdisp{'window'} = ' checked="checked"';
1.298 raeburn 4264: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
4265: $currdisp{'tab'} = ' checked="checked"';
1.267 raeburn 4266: } else {
4267: $currdisp{'iframe'} = ' checked="checked"';
4268: }
4269: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
4270: $currdisp{'width'} = $1;
4271: }
4272: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
4273: $currdisp{'height'} = $1;
4274: }
1.296 raeburn 4275: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
4276: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267 raeburn 4277: } else {
4278: $currdisp{'iframe'} = ' checked="checked"';
4279: }
1.298 raeburn 4280: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4281: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
4282: $lt{$disp}.'</label>'.(' 'x2);
4283: }
4284: $datatable .= (' 'x4);
4285: foreach my $dimen ('width','height') {
4286: $datatable .= '<label>'.$lt{$dimen}.' '.
4287: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
4288: (' 'x2);
4289: }
1.334 raeburn 4290: $datatable .= '</span><br />'.
1.296 raeburn 4291: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 4292: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
1.296 raeburn 4293: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4294: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
4295: '</textarea></div><div style=""></div><br />';
1.319 raeburn 4296: my %units = (
4297: 'passback' => 'days',
4298: 'roster' => 'seconds',
4299: );
1.267 raeburn 4300: foreach my $extra ('passback','roster') {
1.319 raeburn 4301: my $validsty = 'none';
4302: my $currvalid;
1.267 raeburn 4303: my $checkedon = '';
4304: my $checkedoff = ' checked="checked"';
4305: if ($settings->{$item}->{$extra}) {
4306: $checkedon = $checkedoff;
4307: $checkedoff = '';
1.319 raeburn 4308: $validsty = 'inline-block';
4309: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
4310: $currvalid = $settings->{$item}->{$extra.'valid'};
4311: }
4312: }
4313: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
4314: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4315: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
4316: &mt('No').'</label>'.(' 'x2).
4317: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
4318: &mt('Yes').'</label></span></div>'.
4319: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
4320: '<span class="LC_nobreak">'.
4321: &mt("at least [_1] $units{$extra} after launch",
4322: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
4323: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4324: }
1.319 raeburn 4325: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
1.267 raeburn 4326: if ($imgsrc) {
4327: $datatable .= $imgsrc.
4328: '<label><input type="checkbox" name="ltitools_image_del"'.
4329: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
4330: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
4331: } else {
4332: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4333: }
4334: if ($switchserver) {
4335: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4336: } else {
4337: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
4338: }
4339: $datatable .= '</span></fieldset>';
1.324 raeburn 4340: my (%checkedfields,%rolemaps,$userincdom);
1.267 raeburn 4341: if (ref($settings->{$item}) eq 'HASH') {
4342: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
4343: %checkedfields = %{$settings->{$item}->{'fields'}};
4344: }
1.324 raeburn 4345: $userincdom = $settings->{$item}->{'incdom'};
1.267 raeburn 4346: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
4347: %rolemaps = %{$settings->{$item}->{'roles'}};
4348: $checkedfields{'roles'} = 1;
4349: }
4350: }
4351: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4352: '<span class="LC_nobreak">';
1.324 raeburn 4353: my $userfieldstyle = 'display:none;';
4354: my $seluserdom = '';
4355: my $unseluserdom = ' selected="selected"';
1.267 raeburn 4356: foreach my $field (@fields) {
1.324 raeburn 4357: my ($checked,$onclick,$id,$spacer);
1.267 raeburn 4358: if ($checkedfields{$field}) {
4359: $checked = ' checked="checked"';
4360: }
1.324 raeburn 4361: if ($field eq 'user') {
4362: $id = ' id="ltitools_user_field_'.$i.'"';
4363: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
4364: if ($checked) {
4365: $userfieldstyle = 'display:inline-block';
4366: if ($userincdom) {
4367: $seluserdom = $unseluserdom;
4368: $unseluserdom = '';
4369: }
4370: }
4371: } else {
4372: $spacer = (' ' x2);
4373: }
1.267 raeburn 4374: $datatable .= '<label>'.
1.324 raeburn 4375: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
4376: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 4377: }
1.324 raeburn 4378: $datatable .= '</span>';
4379: $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
4380: '<span class="LC_nobreak"> : '.
4381: '<select name="ltitools_userincdom_'.$i.'">'.
4382: '<option value="">'.&mt('Select').'</option>'.
4383: '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
4384: '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
4385: '</select></span></div>';
4386: $datatable .= '</fieldset>'.
1.267 raeburn 4387: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4388: foreach my $role (@courseroles) {
4389: my ($selected,$selectnone);
4390: if (!$rolemaps{$role}) {
4391: $selectnone = ' selected="selected"';
4392: }
1.306 raeburn 4393: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4394: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4395: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
4396: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
4397: foreach my $ltirole (@ltiroles) {
4398: unless ($selectnone) {
4399: if ($rolemaps{$role} eq $ltirole) {
4400: $selected = ' selected="selected"';
4401: } else {
4402: $selected = '';
4403: }
4404: }
4405: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
4406: }
4407: $datatable .= '</select></td>';
4408: }
1.273 raeburn 4409: $datatable .= '</tr></table></fieldset>';
4410: my %courseconfig;
4411: if (ref($settings->{$item}) eq 'HASH') {
4412: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
4413: %courseconfig = %{$settings->{$item}->{'crsconf'}};
4414: }
4415: }
4416: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4417: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 4418: my $checked;
4419: if ($courseconfig{$item}) {
4420: $checked = ' checked="checked"';
4421: }
4422: $datatable .= '<label>'.
4423: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
4424: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
4425: }
4426: $datatable .= '</span></fieldset>'.
1.267 raeburn 4427: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4428: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
4429: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
4430: my %custom = %{$settings->{$item}->{'custom'}};
4431: if (keys(%custom) > 0) {
4432: foreach my $key (sort(keys(%custom))) {
4433: $datatable .= '<tr><td><span class="LC_nobreak">'.
4434: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
4435: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
4436: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
4437: ' value="'.$custom{$key}.'" /></td></tr>';
4438: }
4439: }
4440: }
4441: $datatable .= '<tr><td><span class="LC_nobreak">'.
4442: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
4443: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
4444: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
4445: $datatable .= '</table></fieldset></td></tr>'."\n";
4446: $itemcount ++;
4447: }
4448: }
4449: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.319 raeburn 4450: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1.267 raeburn 4451: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4452: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
4453: '<select name="ltitools_add_pos"'.$chgstr.'>';
4454: for (my $k=0; $k<$maxnum+1; $k++) {
4455: my $vpos = $k+1;
4456: my $selstr;
4457: if ($k == $maxnum) {
4458: $selstr = ' selected="selected" ';
4459: }
4460: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4461: }
4462: $datatable .= '</select> '."\n".
1.334 raeburn 4463: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.267 raeburn 4464: '<td colspan="2">'.
4465: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4466: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
1.267 raeburn 4467: (' 'x2).
4468: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
4469: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4470: (' 'x2).
4471: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
4472: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4473: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
4474: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
4475: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
1.267 raeburn 4476: '<br />'.
1.323 raeburn 4477: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
1.267 raeburn 4478: (' 'x2).
4479: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
4480: (' 'x2).
1.322 raeburn 4481: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
4482: (' 'x2).
1.267 raeburn 4483: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
4484: '<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".
4485: '</fieldset>'.
4486: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4487: '<span class="LC_nobreak">'.&mt('Display target:');
4488: my %defaultdisp;
4489: $defaultdisp{'iframe'} = ' checked="checked"';
1.298 raeburn 4490: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4491: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
4492: $lt{$disp}.'</label>'.(' 'x2);
4493: }
4494: $datatable .= (' 'x4);
4495: foreach my $dimen ('width','height') {
4496: $datatable .= '<label>'.$lt{$dimen}.' '.
4497: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
4498: (' 'x2);
4499: }
1.334 raeburn 4500: $datatable .= '</span><br />'.
1.296 raeburn 4501: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 4502: '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
1.296 raeburn 4503: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
1.334 raeburn 4504: '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
1.296 raeburn 4505: '</div><div style=""></div><br />';
1.319 raeburn 4506: my %units = (
4507: 'passback' => 'days',
4508: 'roster' => 'seconds',
4509: );
4510: my %defaulttimes = (
4511: 'passback' => '7',
1.322 raeburn 4512: 'roster' => '300',
1.319 raeburn 4513: );
1.267 raeburn 4514: foreach my $extra ('passback','roster') {
1.319 raeburn 4515: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
4516: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4517: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
4518: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
4519: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
4520: &mt('Yes').'</label></span></div>'.
4521: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
4522: '<span class="LC_nobreak">'.
4523: &mt("at least [_1] $units{$extra} after launch",
4524: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
4525: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4526: }
1.319 raeburn 4527: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
1.267 raeburn 4528: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4529: if ($switchserver) {
4530: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4531: } else {
4532: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
4533: }
4534: $datatable .= '</span></fieldset>'.
4535: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4536: '<span class="LC_nobreak">';
4537: foreach my $field (@fields) {
1.324 raeburn 4538: my ($id,$onclick,$spacer);
4539: if ($field eq 'user') {
4540: $id = ' id="ltitools_user_field_add"';
4541: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
4542: } else {
4543: $spacer = (' ' x2);
4544: }
1.267 raeburn 4545: $datatable .= '<label>'.
1.324 raeburn 4546: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
4547: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 4548: }
1.324 raeburn 4549: $datatable .= '</span>'.
4550: '<div style="display:none;" id="ltitools_user_div_add">'.
4551: '<span class="LC_nobreak"> : '.
4552: '<select name="ltitools_userincdom_add">'.
4553: '<option value="" selected="selected">'.&mt('Select').'</option>'.
4554: '<option value="0">'.&mt('username').'</option>'.
4555: '<option value="1">'.&mt('username:domain').'</option>'.
4556: '</select></span></div></fieldset>';
4557: $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
1.267 raeburn 4558: foreach my $role (@courseroles) {
4559: my ($checked,$checkednone);
1.306 raeburn 4560: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4561: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4562: '<select name="ltitools_add_roles_'.$role.'">'.
4563: '<option value="" selected="selected">'.&mt('Select').'</option>';
4564: foreach my $ltirole (@ltiroles) {
4565: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
4566: }
4567: $datatable .= '</select></td>';
4568: }
4569: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 4570: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4571: foreach my $item ('label','title','target','linktext','explanation','append') {
1.296 raeburn 4572: $datatable .= '<label>'.
4573: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
4574: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
1.273 raeburn 4575: }
4576: $datatable .= '</span></fieldset>'.
1.267 raeburn 4577: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4578: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
4579: '<tr><td><span class="LC_nobreak">'.
4580: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
4581: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
4582: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
1.334 raeburn 4583: '</table></fieldset>'."\n".
1.267 raeburn 4584: '</td>'."\n".
4585: '</tr>'."\n";
4586: $itemcount ++;
4587: return $datatable;
4588: }
4589:
4590: sub ltitools_names {
4591: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 4592: 'title' => 'Title',
4593: 'version' => 'Version',
4594: 'msgtype' => 'Message Type',
1.323 raeburn 4595: 'sigmethod' => 'Signature Method',
1.296 raeburn 4596: 'url' => 'URL',
4597: 'key' => 'Key',
1.322 raeburn 4598: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 4599: 'secret' => 'Secret',
4600: 'icon' => 'Icon',
1.324 raeburn 4601: 'user' => 'User',
1.296 raeburn 4602: 'fullname' => 'Full Name',
4603: 'firstname' => 'First Name',
4604: 'lastname' => 'Last Name',
4605: 'email' => 'E-mail',
4606: 'roles' => 'Role',
1.298 raeburn 4607: 'window' => 'Window',
4608: 'tab' => 'Tab',
1.296 raeburn 4609: 'iframe' => 'iFrame',
4610: 'height' => 'Height',
4611: 'width' => 'Width',
4612: 'linktext' => 'Default Link Text',
4613: 'explanation' => 'Default Explanation',
4614: 'passback' => 'Tool can return grades:',
4615: 'roster' => 'Tool can retrieve roster:',
4616: 'crstarget' => 'Display target',
4617: 'crslabel' => 'Course label',
4618: 'crstitle' => 'Course title',
4619: 'crslinktext' => 'Link Text',
4620: 'crsexplanation' => 'Explanation',
1.318 raeburn 4621: 'crsappend' => 'Provider URL',
1.267 raeburn 4622: );
4623: return %lt;
4624: }
4625:
1.320 raeburn 4626: sub print_lti {
4627: my ($dom,$settings,$rowtotal) = @_;
4628: my $itemcount = 1;
4629: my $maxnum = 0;
4630: my $css_class;
4631: my %ordered;
4632: if (ref($settings) eq 'HASH') {
4633: foreach my $item (keys(%{$settings})) {
4634: if (ref($settings->{$item}) eq 'HASH') {
4635: my $num = $settings->{$item}{'order'};
4636: $ordered{$num} = $item;
4637: }
4638: }
4639: }
4640: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 4641: my $datatable;
1.320 raeburn 4642: my %lt = <i_names();
4643: if (keys(%ordered)) {
4644: my @items = sort { $a <=> $b } keys(%ordered);
4645: for (my $i=0; $i<@items; $i++) {
4646: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4647: my $item = $ordered{$items[$i]};
4648: my ($key,$secret,$lifetime,$consumer,$current);
4649: if (ref($settings->{$item}) eq 'HASH') {
4650: $key = $settings->{$item}->{'key'};
4651: $secret = $settings->{$item}->{'secret'};
4652: $lifetime = $settings->{$item}->{'lifetime'};
4653: $consumer = $settings->{$item}->{'consumer'};
4654: $current = $settings->{$item};
4655: }
4656: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
4657: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4658: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
4659: for (my $k=0; $k<=$maxnum; $k++) {
4660: my $vpos = $k+1;
4661: my $selstr;
4662: if ($k == $i) {
4663: $selstr = ' selected="selected" ';
4664: }
4665: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4666: }
4667: $datatable .= '</select>'.(' 'x2).
4668: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
4669: &mt('Delete?').'</label></span></td>'.
4670: '<td colspan="2">'.
4671: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4672: '<span class="LC_nobreak">'.$lt{'consumer'}.
4673: ':<input type="text" size="20" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
4674: (' 'x2).
4675: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
4676: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4677: (' 'x2).
4678: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
4679: 'value="'.$lifetime.'" size="5" /></span>'.
4680: '<br /><br />'.
4681: '<span class="LC_nobreak">'.$lt{'key'}.
4682: ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
4683: (' 'x2).
4684: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4685: '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
4686: '<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>'.
4687: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
1.325 raeburn 4688: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
1.320 raeburn 4689: $itemcount ++;
4690: }
4691: }
4692: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4693: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
4694: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4695: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
4696: '<select name="lti_pos_add"'.$chgstr.'>';
4697: for (my $k=0; $k<$maxnum+1; $k++) {
4698: my $vpos = $k+1;
4699: my $selstr;
4700: if ($k == $maxnum) {
4701: $selstr = ' selected="selected" ';
4702: }
4703: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4704: }
4705: $datatable .= '</select> '."\n".
1.334 raeburn 4706: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.320 raeburn 4707: '<td colspan="2">'.
4708: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4709: '<span class="LC_nobreak">'.$lt{'consumer'}.
4710: ':<input type="text" size="20" name="lti_consumer_add" value="" /></span> '."\n".
4711: (' 'x2).
4712: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
4713: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4714: (' 'x2).
1.322 raeburn 4715: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="lti_lifetime_add" value="300" /></span> '."\n".
1.320 raeburn 4716: '<br /><br />'.
4717: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
4718: (' 'x2).
4719: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
4720: '<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 4721: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
1.320 raeburn 4722: '</td>'."\n".
4723: '</tr>'."\n";
4724: $$rowtotal ++;
4725: return $datatable;;
4726: }
4727:
4728: sub lti_names {
4729: my %lt = &Apache::lonlocal::texthash(
4730: 'version' => 'LTI Version',
4731: 'url' => 'URL',
4732: 'key' => 'Key',
1.322 raeburn 4733: 'lifetime' => 'Nonce lifetime (s)',
1.320 raeburn 4734: 'consumer' => 'LTI Consumer',
4735: 'secret' => 'Secret',
4736: 'email' => 'Email address',
4737: 'sourcedid' => 'User ID',
4738: 'other' => 'Other',
4739: 'passback' => 'Can return grades to Consumer:',
4740: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 4741: 'topmenu' => 'Display LON-CAPA page header',
4742: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 4743: );
4744: return %lt;
4745: }
4746:
4747: sub lti_options {
1.325 raeburn 4748: my ($num,$current,$itemcount,%lt) = @_;
1.320 raeburn 4749: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield);
4750: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
4751: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
4752: $checked{'makecrs'}{'N'} = ' checked="checked"';
4753: $checked{'mapcrstype'} = {};
4754: $checked{'makeuser'} = {};
4755: $checked{'selfenroll'} = {};
4756: $checked{'crssec'} = {};
4757: $checked{'crssecsrc'} = {};
1.325 raeburn 4758: $checked{'lcauth'} = {};
1.326 raeburn 4759: $checked{'menuitem'} = {};
1.325 raeburn 4760: if ($num eq 'add') {
4761: $checked{'lcauth'}{'lti'} = ' checked="checked"';
4762: }
1.320 raeburn 4763: my $userfieldsty = 'none';
4764: my $crsfieldsty = 'none';
4765: my $crssecfieldsty = 'none';
4766: my $secsrcfieldsty = 'none';
1.337 ! raeburn 4767: my $passbacksty = 'none';
1.325 raeburn 4768: my $lcauthparm;
4769: my $lcauthparmstyle = 'display:none';
4770: my $lcauthparmtext;
1.326 raeburn 4771: my $menusty;
1.325 raeburn 4772: my $numinrow = 4;
1.326 raeburn 4773: my %menutitles = <imenu_titles();
1.320 raeburn 4774:
4775: if (ref($current) eq 'HASH') {
4776: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
4777: $checked{'mapuser'}{'sourcedid'} = '';
4778: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
4779: $checked{'mapuser'}{'email'} = ' checked="checked"';
4780: } else {
4781: $checked{'mapuser'}{'other'} = ' checked="checked"';
4782: $userfield = $current->{'mapuser'};
4783: $userfieldsty = 'inline-block';
4784: }
4785: }
4786: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
4787: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
4788: if ($current->{'mapcrs'} eq 'context_id') {
4789: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
4790: } else {
4791: $checked{'mapcrs'}{'other'} = ' checked="checked"';
4792: $cidfield = $current->{'mapcrs'};
4793: $crsfieldsty = 'inline-block';
4794: }
4795: }
4796: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
4797: foreach my $type (@{$current->{'mapcrstype'}}) {
4798: $checked{'mapcrstype'}{$type} = ' checked="checked"';
4799: }
4800: }
4801: if ($current->{'makecrs'}) {
4802: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 4803: }
1.320 raeburn 4804: if (ref($current->{'makeuser'}) eq 'ARRAY') {
4805: foreach my $role (@{$current->{'makeuser'}}) {
4806: $checked{'makeuser'}{$role} = ' checked="checked"';
4807: }
4808: }
1.325 raeburn 4809: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
4810: $checked{'lcauth'}{$1} = ' checked="checked"';
4811: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
4812: $lcauthparm = $current->{'lcauthparm'};
4813: $lcauthparmstyle = 'display:table-row';
4814: if ($current->{'lcauth'} eq 'localauth') {
4815: $lcauthparmtext = &mt('Local auth argument');
4816: } else {
4817: $lcauthparmtext = &mt('Kerberos domain');
4818: }
4819: }
4820: }
1.320 raeburn 4821: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
4822: foreach my $role (@{$current->{'selfenroll'}}) {
4823: $checked{'selfenroll'}{$role} = ' checked="checked"';
4824: }
4825: }
4826: if (ref($current->{'maproles'}) eq 'HASH') {
4827: %rolemaps = %{$current->{'maproles'}};
4828: }
4829: if ($current->{'section'} ne '') {
4830: $checked{'crssec'}{'Y'} = ' checked="checked"';
4831: $crssecfieldsty = 'inline-block';
4832: if ($current->{'section'} eq 'course_section_sourcedid') {
4833: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
4834: } else {
4835: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
4836: $crssecsrc = $current->{'section'};
4837: $secsrcfieldsty = 'inline-block';
4838: }
4839: } else {
4840: $checked{'crssec'}{'N'} = ' checked="checked"';
4841: }
1.326 raeburn 4842: if ($current->{'topmenu'}) {
4843: $checked{'topmenu'}{'Y'} = ' checked="checked"';
4844: } else {
4845: $checked{'topmenu'}{'N'} = ' checked="checked"';
4846: }
4847: if ($current->{'inlinemenu'}) {
4848: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
4849: } else {
4850: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
4851: }
4852: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
4853: $menusty = 'inline-block';
4854: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
4855: foreach my $item (@{$current->{'lcmenu'}}) {
4856: if (exists($menutitles{$item})) {
4857: $checked{'menuitem'}{$item} = ' checked="checked"';
4858: }
4859: }
4860: }
4861: } else {
4862: $menusty = 'none';
4863: }
1.320 raeburn 4864: } else {
4865: $checked{'makecrs'}{'N'} = ' checked="checked"';
4866: $checked{'crssec'}{'N'} = ' checked="checked"';
1.326 raeburn 4867: $checked{'topmenu'}{'N'} = ' checked="checked"';
4868: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
4869: $checked{'menuitem'}{'grades'} = ' checked="checked"';
4870: $menusty = 'inline-block';
1.320 raeburn 4871: }
1.325 raeburn 4872: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 4873: my %coursetypetitles = &Apache::lonlocal::texthash (
4874: official => 'Official',
4875: unofficial => 'Unofficial',
4876: community => 'Community',
4877: textbook => 'Textbook',
4878: placement => 'Placement Test',
1.325 raeburn 4879: lti => 'LTI Provider',
1.320 raeburn 4880: );
1.325 raeburn 4881: my @authtypes = ('internal','krb4','krb5','localauth');
4882: my %shortauth = (
4883: internal => 'int',
4884: krb4 => 'krb4',
4885: krb5 => 'krb5',
4886: localauth => 'loc'
4887: );
4888: my %authnames = &authtype_names();
1.320 raeburn 4889: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
4890: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
4891: my @courseroles = ('cc','in','ta','ep','st');
4892: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
4893: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
4894: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
4895: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 4896: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 4897: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.320 raeburn 4898: my $output = '<fieldset><legend>'.&mt('Mapping users').'</legend>'.
4899: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
4900: foreach my $option ('sourcedid','email','other') {
4901: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
4902: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
4903: ($option eq 'other' ? '' : (' 'x2) );
4904: }
4905: $output .= '</span></div>'.
4906: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
4907: '<input type="text" name="lti_customuser_'.$num.'" '.
4908: 'value="'.$userfield.'" /></div></fieldset>'.
4909: '<fieldset><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
4910: foreach my $ltirole (@lticourseroles) {
4911: my ($selected,$selectnone);
4912: if ($rolemaps{$ltirole} eq '') {
4913: $selectnone = ' selected="selected"';
4914: }
4915: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
4916: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
4917: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
4918: foreach my $role (@courseroles) {
4919: unless ($selectnone) {
4920: if ($rolemaps{$ltirole} eq $role) {
4921: $selected = ' selected="selected"';
4922: } else {
4923: $selected = '';
4924: }
4925: }
4926: $output .= '<option value="'.$role.'"'.$selected.'>'.
4927: &Apache::lonnet::plaintext($role,'Course').
4928: '</option>';
4929: }
4930: $output .= '</select></td>';
4931: }
4932: $output .= '</tr></table></fieldset>'.
4933: '<fieldset><legend>'.&mt('Roles which may create user accounts').'</legend>';
4934: foreach my $ltirole (@ltiroles) {
4935: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
4936: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
4937: }
4938: $output .= '</fieldset>'.
1.325 raeburn 4939: '<fieldset><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
4940: '<table>'.
4941: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
4942: '</table>'.
4943: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
4944: '<td class="LC_left_item">';
4945: foreach my $auth ('lti',@authtypes) {
4946: my $authtext;
4947: if ($auth eq 'lti') {
4948: $authtext = &mt('None');
4949: } else {
4950: $authtext = $authnames{$shortauth{$auth}};
4951: }
4952: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
4953: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
4954: $authtext.'</label></span> ';
4955: }
4956: $output .= '</td></tr>'.
4957: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
4958: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
4959: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
4960: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
4961: '</table></fieldset>'.
1.320 raeburn 4962: '<fieldset><legend>'.&mt('Mapping courses').'</legend>'.
4963: '<div class="LC_floatleft"><span class="LC_nobreak">'.
4964: &mt('Unique course identifier').': ';
4965: foreach my $option ('course_offering_sourcedid','context_id','other') {
4966: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
4967: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
4968: ($option eq 'other' ? '' : (' 'x2) );
4969: }
1.334 raeburn 4970: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 4971: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
4972: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
4973: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
4974: foreach my $type (@coursetypes) {
4975: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
4976: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
4977: (' 'x2);
4978: }
4979: $output .= '</span></fieldset>'.
4980: '<fieldset><legend>'.&mt('Creating courses').'</legend>'.
4981: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
4982: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
4983: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
4984: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
4985: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
4986: '</fieldset>'.
4987: '<fieldset><legend>'.&mt('Roles which may self-enroll').'</legend>';
4988: foreach my $lticrsrole (@lticourseroles) {
4989: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
4990: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
4991: }
4992: $output .= '</fieldset>'.
4993: '<fieldset><legend>'.&mt('Course options').'</legend>'.
4994: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
4995: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
4996: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
4997: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 4998: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 4999: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
5000: '<span class="LC_nobreak">'.&mt('From').':<label>'.
5001: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
5002: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
5003: &mt('Standard field').'</label>'.(' 'x2).
5004: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
5005: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 5006: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 5007: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 ! raeburn 5008: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
! 5009: my ($pb1p1chk,$pb1p0chk,$onclickpb);
! 5010: foreach my $extra ('roster','passback') {
1.320 raeburn 5011: my $checkedon = '';
5012: my $checkedoff = ' checked="checked"';
1.337 ! raeburn 5013: if ($extra eq 'passback') {
! 5014: $pb1p1chk = ' checked="checked"';
! 5015: $pb1p0chk = '';
! 5016: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
! 5017: } else {
! 5018: $onclickpb = '';
! 5019: }
1.320 raeburn 5020: if (ref($current) eq 'HASH') {
5021: if (($current->{$extra})) {
5022: $checkedon = $checkedoff;
5023: $checkedoff = '';
1.337 ! raeburn 5024: if ($extra eq 'passback') {
! 5025: $passbacksty = 'inline-block';
! 5026: }
! 5027: if ($current->{'passbackformat'} eq '1.0') {
! 5028: $pb1p0chk = ' checked="checked"';
! 5029: $pb1p1chk = '';
! 5030: }
1.320 raeburn 5031: }
5032: }
5033: $output .= $lt{$extra}.' '.
1.337 ! raeburn 5034: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 5035: &mt('No').'</label>'.(' 'x2).
1.337 ! raeburn 5036: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb' />'.
1.320 raeburn 5037: &mt('Yes').'</label><br />';
5038: }
1.337 ! raeburn 5039: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
! 5040: '<span class="LC_nobreak">'.&mt('Grade format').
! 5041: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
! 5042: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
! 5043: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
! 5044: &mt('Outcomes Extension (1.0)').'</label></span></div></fieldset>'.
1.326 raeburn 5045: '<fieldset><legend>'.&mt('Course defaults (Course Coordinator can override)').'</legend>'.
5046: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
5047: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
5048: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
5049: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
1.334 raeburn 5050: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
1.326 raeburn 5051: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
5052: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
5053: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
5054: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
5055: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
1.334 raeburn 5056: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
1.326 raeburn 5057: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
5058: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
5059: '<span class="LC_nobreak">'.&mt('Menu items').': ';
5060: foreach my $type ('fullname','coursetitle','role','logout','grades') {
5061: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
5062: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
5063: (' 'x2);
5064: }
1.334 raeburn 5065: $output .= '</span></div></fieldset>';
1.320 raeburn 5066: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
5067: #
5068: # $output .= '</fieldset>'.
5069: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
5070: return $output;
5071: }
5072:
1.326 raeburn 5073: sub ltimenu_titles {
5074: return &Apache::lonlocal::texthash(
5075: fullname => 'Full name',
5076: coursetitle => 'Course title',
5077: role => 'Role',
5078: logout => 'Logout',
5079: grades => 'Grades',
5080: );
5081: }
5082:
1.121 raeburn 5083: sub print_coursedefaults {
1.139 raeburn 5084: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 5085: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 5086: my $itemcount = 1;
1.192 raeburn 5087: my %choices = &Apache::lonlocal::texthash (
5088: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 5089: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 5090: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
5091: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 5092: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
5093: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.314 raeburn 5094: texengine => 'Default method to display mathematics',
1.257 raeburn 5095: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 5096: canclone => "People who may clone a course (besides course's owner and coordinators)",
5097: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 5098: );
1.198 raeburn 5099: my %staticdefaults = (
1.314 raeburn 5100: texengine => 'MathJax',
1.198 raeburn 5101: anonsurvey_threshold => 10,
5102: uploadquota => 500,
1.257 raeburn 5103: postsubmit => 60,
1.276 raeburn 5104: mysqltables => 172800,
1.198 raeburn 5105: );
1.139 raeburn 5106: if ($position eq 'top') {
1.257 raeburn 5107: %defaultchecked = (
5108: 'canuse_pdfforms' => 'off',
5109: 'uselcmath' => 'on',
5110: 'usejsme' => 'on',
1.289 raeburn 5111: 'canclone' => 'none',
1.257 raeburn 5112: );
5113: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.314 raeburn 5114: my $deftex = $staticdefaults{'texengine'};
5115: if (ref($settings) eq 'HASH') {
5116: if ($settings->{'texengine'}) {
5117: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
5118: $deftex = $settings->{'texengine'};
5119: }
5120: }
5121: }
5122: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5123: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
5124: '<span class="LC_nobreak">'.$choices{'texengine'}.
5125: '</span></td><td class="LC_right_item">'.
5126: '<select name="texengine">'."\n";
5127: my %texoptions = (
5128: MathJax => 'MathJax',
5129: mimetex => &mt('Convert to Images'),
5130: tth => &mt('TeX to HTML'),
5131: );
5132: foreach my $renderer ('MathJax','mimetex','tth') {
5133: my $selected = '';
5134: if ($renderer eq $deftex) {
5135: $selected = ' selected="selected"';
5136: }
5137: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
5138: }
5139: $mathdisp .= '</select></td></tr>'."\n";
5140: $itemcount ++;
1.139 raeburn 5141: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 5142: \%choices,$itemcount);
1.314 raeburn 5143: $datatable = $mathdisp.$datatable;
1.264 raeburn 5144: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5145: $datatable .=
1.306 raeburn 5146: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 5147: '<span class="LC_nobreak">'.$choices{'canclone'}.
5148: '</span></td><td class="LC_left_item">';
5149: my $currcanclone = 'none';
5150: my $onclick;
5151: my @cloneoptions = ('none','domain');
5152: my %clonetitles = (
5153: none => 'No additional course requesters',
5154: domain => "Any course requester in course's domain",
5155: instcode => 'Course requests for official courses ...',
5156: );
5157: my (%codedefaults,@code_order,@posscodes);
5158: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
5159: \@code_order) eq 'ok') {
5160: if (@code_order > 0) {
5161: push(@cloneoptions,'instcode');
5162: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
5163: }
5164: }
5165: if (ref($settings) eq 'HASH') {
5166: if ($settings->{'canclone'}) {
5167: if (ref($settings->{'canclone'}) eq 'HASH') {
5168: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
5169: if (@code_order > 0) {
5170: $currcanclone = 'instcode';
5171: @posscodes = @{$settings->{'canclone'}{'instcode'}};
5172: }
5173: }
5174: } elsif ($settings->{'canclone'} eq 'domain') {
5175: $currcanclone = $settings->{'canclone'};
5176: }
5177: }
1.289 raeburn 5178: }
1.264 raeburn 5179: foreach my $option (@cloneoptions) {
5180: my ($checked,$additional);
5181: if ($currcanclone eq $option) {
5182: $checked = ' checked="checked"';
5183: }
5184: if ($option eq 'instcode') {
5185: if (@code_order) {
5186: my $show = 'none';
5187: if ($checked) {
5188: $show = 'block';
5189: }
1.317 raeburn 5190: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 5191: &mt('Institutional codes for new and cloned course have identical:').
5192: '<br />';
5193: foreach my $item (@code_order) {
5194: my $codechk;
5195: if ($checked) {
5196: if (grep(/^\Q$item\E$/,@posscodes)) {
5197: $codechk = ' checked="checked"';
5198: }
5199: }
5200: $additional .= '<label>'.
5201: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
5202: $item.'</label>';
5203: }
5204: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
5205: }
5206: }
5207: $datatable .=
5208: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
5209: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
5210: '</label> '.$additional.'</span><br />';
5211: }
5212: $datatable .= '</td>'.
5213: '</tr>';
5214: $itemcount ++;
1.139 raeburn 5215: } else {
5216: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 5217: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 5218: my $currusecredits = 0;
1.257 raeburn 5219: my $postsubmitclient = 1;
1.271 raeburn 5220: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 5221: if (ref($settings) eq 'HASH') {
5222: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 5223: if (ref($settings->{'uploadquota'}) eq 'HASH') {
5224: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
5225: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
5226: }
5227: }
1.192 raeburn 5228: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 5229: foreach my $type (@types) {
5230: next if ($type eq 'community');
5231: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
5232: if ($defcredits{$type} ne '') {
5233: $currusecredits = 1;
5234: }
5235: }
5236: }
5237: if (ref($settings->{'postsubmit'}) eq 'HASH') {
5238: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
5239: $postsubmitclient = 0;
5240: foreach my $type (@types) {
5241: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5242: }
5243: } else {
5244: foreach my $type (@types) {
5245: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
5246: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 5247: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 5248: } else {
5249: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5250: }
5251: } else {
5252: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5253: }
5254: }
5255: }
5256: } else {
5257: foreach my $type (@types) {
5258: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 5259: }
5260: }
1.276 raeburn 5261: if (ref($settings->{'mysqltables'}) eq 'HASH') {
5262: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
5263: $currmysql{$type} = $settings->{'mysqltables'}{$type};
5264: }
5265: } else {
5266: foreach my $type (@types) {
5267: $currmysql{$type} = $staticdefaults{'mysqltables'};
5268: }
5269: }
1.258 raeburn 5270: } else {
5271: foreach my $type (@types) {
5272: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5273: }
1.139 raeburn 5274: }
5275: if (!$currdefresponder) {
1.198 raeburn 5276: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 5277: } elsif ($currdefresponder < 1) {
5278: $currdefresponder = 1;
5279: }
1.198 raeburn 5280: foreach my $type (@types) {
5281: if ($curruploadquota{$type} eq '') {
5282: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
5283: }
5284: }
1.139 raeburn 5285: $datatable .=
1.192 raeburn 5286: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5287: $choices{'anonsurvey_threshold'}.
1.139 raeburn 5288: '</span></td>'.
5289: '<td class="LC_right_item"><span class="LC_nobreak">'.
5290: '<input type="text" name="anonsurvey_threshold"'.
5291: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 5292: '</td></tr>'."\n";
5293: $itemcount ++;
5294: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5295: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5296: $choices{'uploadquota'}.
5297: '</span></td>'.
1.306 raeburn 5298: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 5299: '<table><tr>';
1.198 raeburn 5300: foreach my $type (@types) {
1.306 raeburn 5301: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 5302: '<input type="text" name="uploadquota_'.$type.'"'.
5303: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
5304: }
5305: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 5306: $itemcount ++;
1.236 raeburn 5307: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 5308: my $display = 'none';
1.192 raeburn 5309: if ($currusecredits) {
5310: $display = 'block';
5311: }
5312: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 5313: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
5314: foreach my $type (@types) {
5315: next if ($type eq 'community');
1.306 raeburn 5316: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 5317: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 5318: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 5319: }
5320: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 5321: %defaultchecked = ('coursecredits' => 'off');
5322: @toggles = ('coursecredits');
5323: my $current = {
5324: 'coursecredits' => $currusecredits,
5325: };
5326: (my $table,$itemcount) =
5327: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 5328: \%choices,$itemcount,$onclick,$additional,'left');
5329: $datatable .= $table;
5330: $onclick = "toggleDisplay(this.form,'studentsubmission');";
5331: my $display = 'none';
5332: if ($postsubmitclient) {
5333: $display = 'block';
5334: }
5335: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 5336: &mt('Number of seconds submit is disabled').'<br />'.
5337: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
5338: '<table><tr>';
1.257 raeburn 5339: foreach my $type (@types) {
1.306 raeburn 5340: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 5341: '<input type="text" name="'.$type.'_timeout" value="'.
5342: $deftimeout{$type}.'" size="5" /></td>';
5343: }
5344: $additional .= '</tr></table></div>'."\n";
5345: %defaultchecked = ('postsubmit' => 'on');
5346: @toggles = ('postsubmit');
1.280 raeburn 5347: $current = {
5348: 'postsubmit' => $postsubmitclient,
5349: };
1.257 raeburn 5350: ($table,$itemcount) =
5351: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
5352: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 5353: $datatable .= $table;
1.276 raeburn 5354: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5355: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5356: $choices{'mysqltables'}.
5357: '</span></td>'.
1.306 raeburn 5358: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 5359: '<table><tr>';
5360: foreach my $type (@types) {
1.306 raeburn 5361: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 5362: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 5363: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 5364: }
5365: $datatable .= '</tr></table></td></tr>'."\n";
5366: $itemcount ++;
5367:
1.139 raeburn 5368: }
1.192 raeburn 5369: $$rowtotal += $itemcount;
1.121 raeburn 5370: return $datatable;
1.118 jms 5371: }
5372:
1.231 raeburn 5373: sub print_selfenrollment {
5374: my ($position,$dom,$settings,$rowtotal) = @_;
5375: my ($css_class,$datatable);
5376: my $itemcount = 1;
1.271 raeburn 5377: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 5378: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 5379: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
5380: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 5381: my @rows;
5382: my $key;
5383: if ($position eq 'top') {
5384: $key = 'admin';
5385: if (ref($rowsref) eq 'ARRAY') {
5386: @rows = @{$rowsref};
5387: }
5388: } elsif ($position eq 'middle') {
5389: $key = 'default';
5390: @rows = ('types','registered','approval','limit');
5391: }
5392: foreach my $row (@rows) {
5393: if (defined($titlesref->{$row})) {
5394: $itemcount ++;
5395: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5396: $datatable .= '<tr'.$css_class.'>'.
5397: '<td>'.$titlesref->{$row}.'</td>'.
5398: '<td class="LC_left_item">'.
5399: '<table><tr>';
5400: my (%current,%currentcap);
5401: if (ref($settings) eq 'HASH') {
5402: if (ref($settings->{$key}) eq 'HASH') {
5403: foreach my $type (@types) {
5404: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5405: $current{$type} = $settings->{$key}->{$type}->{$row};
5406: }
5407: if (($row eq 'limit') && ($key eq 'default')) {
5408: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5409: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
5410: }
5411: }
5412: }
5413: }
5414: }
5415: my %roles = (
5416: '0' => &Apache::lonnet::plaintext('dc'),
5417: );
5418:
5419: foreach my $type (@types) {
5420: unless (($row eq 'registered') && ($key eq 'default')) {
5421: $datatable .= '<th>'.&mt($type).'</th>';
5422: }
5423: }
5424: unless (($row eq 'registered') && ($key eq 'default')) {
5425: $datatable .= '</tr><tr>';
5426: }
5427: foreach my $type (@types) {
5428: if ($type eq 'community') {
5429: $roles{'1'} = &mt('Community personnel');
5430: } else {
5431: $roles{'1'} = &mt('Course personnel');
5432: }
5433: $datatable .= '<td style="vertical-align: top">';
5434: if ($position eq 'top') {
5435: my %checked;
5436: if ($current{$type} eq '0') {
5437: $checked{'0'} = ' checked="checked"';
5438: } else {
5439: $checked{'1'} = ' checked="checked"';
5440: }
5441: foreach my $role ('1','0') {
5442: $datatable .= '<span class="LC_nobreak"><label>'.
5443: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
5444: 'value="'.$role.'"'.$checked{$role}.' />'.
5445: $roles{$role}.'</label></span> ';
5446: }
5447: } else {
5448: if ($row eq 'types') {
5449: my %checked;
5450: if ($current{$type} =~ /^(all|dom)$/) {
5451: $checked{$1} = ' checked="checked"';
5452: } else {
5453: $checked{''} = ' checked="checked"';
5454: }
5455: foreach my $val ('','dom','all') {
5456: $datatable .= '<span class="LC_nobreak"><label>'.
5457: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5458: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5459: }
5460: } elsif ($row eq 'registered') {
5461: my %checked;
5462: if ($current{$type} eq '1') {
5463: $checked{'1'} = ' checked="checked"';
5464: } else {
5465: $checked{'0'} = ' checked="checked"';
5466: }
5467: foreach my $val ('0','1') {
5468: $datatable .= '<span class="LC_nobreak"><label>'.
5469: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5470: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5471: }
5472: } elsif ($row eq 'approval') {
5473: my %checked;
5474: if ($current{$type} =~ /^([12])$/) {
5475: $checked{$1} = ' checked="checked"';
5476: } else {
5477: $checked{'0'} = ' checked="checked"';
5478: }
5479: for my $val (0..2) {
5480: $datatable .= '<span class="LC_nobreak"><label>'.
5481: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5482: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5483: }
5484: } elsif ($row eq 'limit') {
5485: my %checked;
5486: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
5487: $checked{$1} = ' checked="checked"';
5488: } else {
5489: $checked{'none'} = ' checked="checked"';
5490: }
5491: my $cap;
5492: if ($currentcap{$type} =~ /^\d+$/) {
5493: $cap = $currentcap{$type};
5494: }
5495: foreach my $val ('none','allstudents','selfenrolled') {
5496: $datatable .= '<span class="LC_nobreak"><label>'.
5497: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5498: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5499: }
5500: $datatable .= '<br />'.
5501: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
5502: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
5503: '</span>';
5504: }
5505: }
5506: $datatable .= '</td>';
5507: }
5508: $datatable .= '</tr>';
5509: }
5510: $datatable .= '</table></td></tr>';
5511: }
5512: } elsif ($position eq 'bottom') {
1.235 raeburn 5513: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
5514: }
5515: $$rowtotal += $itemcount;
5516: return $datatable;
5517: }
5518:
5519: sub print_validation_rows {
5520: my ($caller,$dom,$settings,$rowtotal) = @_;
5521: my ($itemsref,$namesref,$fieldsref);
5522: if ($caller eq 'selfenroll') {
5523: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
5524: } elsif ($caller eq 'requestcourses') {
5525: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
5526: }
5527: my %currvalidation;
5528: if (ref($settings) eq 'HASH') {
5529: if (ref($settings->{'validation'}) eq 'HASH') {
5530: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 5531: }
1.235 raeburn 5532: }
5533: my $datatable;
5534: my $itemcount = 0;
5535: foreach my $item (@{$itemsref}) {
5536: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5537: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5538: $namesref->{$item}.
5539: '</span></td>'.
5540: '<td class="LC_left_item">';
5541: if (($item eq 'url') || ($item eq 'button')) {
5542: $datatable .= '<span class="LC_nobreak">'.
5543: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
5544: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
5545: } elsif ($item eq 'fields') {
5546: my @currfields;
5547: if (ref($currvalidation{$item}) eq 'ARRAY') {
5548: @currfields = @{$currvalidation{$item}};
5549: }
5550: foreach my $field (@{$fieldsref}) {
5551: my $check = '';
5552: if (grep(/^\Q$field\E$/,@currfields)) {
5553: $check = ' checked="checked"';
5554: }
5555: $datatable .= '<span class="LC_nobreak"><label>'.
5556: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
5557: ' value="'.$field.'"'.$check.' />'.$field.
5558: '</label></span> ';
5559: }
5560: } elsif ($item eq 'markup') {
1.334 raeburn 5561: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 5562: $currvalidation{$item}.
1.231 raeburn 5563: '</textarea>';
1.235 raeburn 5564: }
5565: $datatable .= '</td></tr>'."\n";
5566: if (ref($rowtotal)) {
1.231 raeburn 5567: $itemcount ++;
5568: }
5569: }
1.235 raeburn 5570: if ($caller eq 'requestcourses') {
5571: my %currhash;
1.248 raeburn 5572: if (ref($settings) eq 'HASH') {
5573: if (ref($settings->{'validation'}) eq 'HASH') {
5574: if ($settings->{'validation'}{'dc'} ne '') {
5575: $currhash{$settings->{'validation'}{'dc'}} = 1;
5576: }
1.235 raeburn 5577: }
5578: }
5579: my $numinrow = 2;
5580: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
5581: 'validationdc',%currhash);
1.247 raeburn 5582: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 5583: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 5584: if ($numdc > 1) {
1.247 raeburn 5585: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 5586: } else {
1.247 raeburn 5587: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 5588: }
1.247 raeburn 5589: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 5590: $itemcount ++;
5591: }
5592: if (ref($rowtotal)) {
5593: $$rowtotal += $itemcount;
5594: }
1.231 raeburn 5595: return $datatable;
5596: }
5597:
1.137 raeburn 5598: sub print_usersessions {
5599: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 5600: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 5601: my (%by_ip,%by_location,@intdoms,@instdoms);
5602: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 5603:
5604: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 5605: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 5606: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 5607: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 5608: if ($position eq 'top') {
1.152 raeburn 5609: if (keys(%serverhomes) > 1) {
1.145 raeburn 5610: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.261 raeburn 5611: my $curroffloadnow;
5612: if (ref($settings) eq 'HASH') {
5613: if (ref($settings->{'offloadnow'}) eq 'HASH') {
5614: $curroffloadnow = $settings->{'offloadnow'};
5615: }
5616: }
5617: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 5618: } else {
1.140 raeburn 5619: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 5620: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
5621: '</td></tr>';
1.140 raeburn 5622: }
1.137 raeburn 5623: } else {
1.279 raeburn 5624: my %titles = &usersession_titles();
5625: my ($prefix,@types);
5626: if ($position eq 'bottom') {
5627: $prefix = 'remote';
5628: @types = ('version','excludedomain','includedomain');
1.145 raeburn 5629: } else {
1.279 raeburn 5630: $prefix = 'hosted';
5631: @types = ('excludedomain','includedomain');
5632: }
5633: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
5634: }
5635: $$rowtotal += $itemcount;
5636: return $datatable;
5637: }
5638:
5639: sub rules_by_location {
5640: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
5641: my ($datatable,$itemcount,$css_class);
5642: if (keys(%{$by_location}) == 0) {
5643: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5644: $datatable = '<tr'.$css_class.'><td colspan="2">'.
5645: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
5646: '</td></tr>';
5647: $itemcount = 1;
5648: } else {
5649: $itemcount = 0;
5650: my $numinrow = 5;
5651: my (%current,%checkedon,%checkedoff);
5652: my @locations = sort(keys(%{$by_location}));
5653: foreach my $type (@{$types}) {
5654: $checkedon{$type} = '';
5655: $checkedoff{$type} = ' checked="checked"';
5656: }
5657: if (ref($settings) eq 'HASH') {
5658: if (ref($settings->{$prefix}) eq 'HASH') {
5659: foreach my $key (keys(%{$settings->{$prefix}})) {
5660: $current{$key} = $settings->{$prefix}{$key};
5661: if ($key eq 'version') {
5662: if ($current{$key} ne '') {
1.145 raeburn 5663: $checkedon{$key} = ' checked="checked"';
5664: $checkedoff{$key} = '';
5665: }
1.279 raeburn 5666: } elsif (ref($current{$key}) eq 'ARRAY') {
5667: $checkedon{$key} = ' checked="checked"';
5668: $checkedoff{$key} = '';
1.137 raeburn 5669: }
5670: }
5671: }
1.279 raeburn 5672: }
5673: foreach my $type (@{$types}) {
5674: next if ($type ne 'version' && !@locations);
5675: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5676: $datatable .= '<tr'.$css_class.'>
5677: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
5678: <span class="LC_nobreak">
5679: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
5680: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
5681: if ($type eq 'version') {
5682: my @lcversions = &Apache::lonnet::all_loncaparevs();
5683: my $selector = '<select name="'.$prefix.'_version">';
5684: foreach my $version (@lcversions) {
5685: my $selected = '';
5686: if ($current{'version'} eq $version) {
5687: $selected = ' selected="selected"';
1.145 raeburn 5688: }
1.279 raeburn 5689: $selector .= ' <option value="'.$version.'"'.
5690: $selected.'>'.$version.'</option>';
5691: }
5692: $selector .= '</select> ';
5693: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
5694: } else {
5695: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
5696: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
5697: ' />'.(' 'x2).
5698: '<input type="button" value="'.&mt('uncheck all').'" '.
5699: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
5700: "\n".
5701: '</div><div><table>';
5702: my $rem;
5703: for (my $i=0; $i<@locations; $i++) {
5704: my ($showloc,$value,$checkedtype);
5705: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
5706: my $ip = $by_location->{$locations[$i]}->[0];
5707: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5708: $value = join(':',@{$by_ip->{$ip}});
5709: $showloc = join(', ',@{$by_ip->{$ip}});
5710: if (ref($current{$type}) eq 'ARRAY') {
5711: foreach my $loc (@{$by_ip->{$ip}}) {
5712: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
5713: $checkedtype = ' checked="checked"';
5714: last;
1.145 raeburn 5715: }
1.138 raeburn 5716: }
5717: }
5718: }
1.137 raeburn 5719: }
1.279 raeburn 5720: $rem = $i%($numinrow);
5721: if ($rem == 0) {
5722: if ($i > 0) {
5723: $datatable .= '</tr>';
5724: }
5725: $datatable .= '<tr>';
5726: }
5727: $datatable .= '<td class="LC_left_item">'.
5728: '<span class="LC_nobreak"><label>'.
5729: '<input type="checkbox" name="'.$prefix.'_'.$type.
5730: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
5731: '</label></span></td>';
5732: }
5733: $rem = @locations%($numinrow);
5734: my $colsleft = $numinrow - $rem;
5735: if ($colsleft > 1 ) {
5736: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5737: ' </td>';
5738: } elsif ($colsleft == 1) {
5739: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 5740: }
1.279 raeburn 5741: $datatable .= '</tr></table>';
1.137 raeburn 5742: }
1.279 raeburn 5743: $datatable .= '</td></tr>';
5744: $itemcount ++;
1.137 raeburn 5745: }
5746: }
1.279 raeburn 5747: return ($datatable,$itemcount);
1.137 raeburn 5748: }
5749:
1.275 raeburn 5750: sub print_ssl {
5751: my ($position,$dom,$settings,$rowtotal) = @_;
5752: my ($css_class,$datatable);
5753: my $itemcount = 1;
5754: if ($position eq 'top') {
1.281 raeburn 5755: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5756: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5757: my $same_institution;
5758: if ($intdom ne '') {
5759: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
5760: if (ref($internet_names) eq 'ARRAY') {
5761: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
5762: $same_institution = 1;
5763: }
5764: }
5765: }
1.275 raeburn 5766: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 5767: $datatable = '<tr'.$css_class.'><td colspan="2">';
5768: if ($same_institution) {
5769: my %domservers = &Apache::lonnet::get_servers($dom);
5770: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
5771: } else {
5772: $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.");
5773: }
5774: $datatable .= '</td></tr>';
1.275 raeburn 5775: $itemcount ++;
5776: } else {
5777: my %titles = &ssl_titles();
5778: my (%by_ip,%by_location,@intdoms,@instdoms);
5779: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
5780: my @alldoms = &Apache::lonnet::all_domains();
5781: my %serverhomes = %Apache::lonnet::serverhomeIDs;
5782: my @domservers = &Apache::lonnet::get_servers($dom);
5783: my %servers = &Apache::lonnet::internet_dom_servers($dom);
5784: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 5785: if (($position eq 'connto') || ($position eq 'connfrom')) {
5786: my $legacy;
5787: unless (ref($settings) eq 'HASH') {
5788: my $name;
5789: if ($position eq 'connto') {
5790: $name = 'loncAllowInsecure';
5791: } else {
5792: $name = 'londAllowInsecure';
5793: }
5794: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
5795: my @ids=&Apache::lonnet::current_machine_ids();
5796: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
5797: my %what = (
5798: $name => 1,
5799: );
5800: my ($result,$returnhash) =
5801: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
5802: if ($result eq 'ok') {
5803: if (ref($returnhash) eq 'HASH') {
5804: $legacy = $returnhash->{$name};
5805: }
5806: }
5807: } else {
5808: $legacy = $Apache::lonnet::perlvar{$name};
5809: }
5810: }
1.275 raeburn 5811: foreach my $type ('dom','intdom','other') {
5812: my %checked;
5813: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5814: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
5815: '<td class="LC_right_item">';
5816: my $skip;
5817: if ($type eq 'dom') {
5818: unless (keys(%servers) > 1) {
5819: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
5820: $skip = 1;
5821: }
5822: }
5823: if ($type eq 'intdom') {
5824: unless (@instdoms > 1) {
5825: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
5826: $skip = 1;
5827: }
5828: } elsif ($type eq 'other') {
5829: if (keys(%by_location) == 0) {
5830: $datatable .= &mt('Nothing to set here, as there are no other institutions');
5831: $skip = 1;
5832: }
5833: }
5834: unless ($skip) {
5835: $checked{'yes'} = ' checked="checked"';
5836: if (ref($settings) eq 'HASH') {
1.293 raeburn 5837: if (ref($settings->{$position}) eq 'HASH') {
5838: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 5839: $checked{$1} = $checked{'yes'};
5840: delete($checked{'yes'});
5841: }
5842: }
1.293 raeburn 5843: } else {
5844: if ($legacy == 0) {
5845: $checked{'req'} = $checked{'yes'};
5846: delete($checked{'yes'});
5847: }
1.275 raeburn 5848: }
5849: foreach my $option ('no','yes','req') {
5850: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 5851: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 5852: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
5853: '</label></span>'.(' 'x2);
5854: }
5855: }
5856: $datatable .= '</td></tr>';
5857: $itemcount ++;
5858: }
5859: } else {
5860: my $prefix = 'replication';
5861: my @types = ('certreq','nocertreq');
1.279 raeburn 5862: if (keys(%by_location) == 0) {
5863: $datatable .= '<tr'.$css_class.'><td>'.
5864: &mt('Nothing to set here, as there are no other institutions').
5865: '</td></tr>';
5866: $itemcount ++;
1.275 raeburn 5867: } else {
1.279 raeburn 5868: ($datatable,$itemcount) =
5869: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 5870: }
5871: }
5872: }
5873: $$rowtotal += $itemcount;
5874: return $datatable;
5875: }
5876:
5877: sub ssl_titles {
5878: return &Apache::lonlocal::texthash (
5879: dom => 'LON-CAPA servers/VMs from same domain',
5880: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
5881: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 5882: connto => 'Connections to other servers',
5883: connfrom => 'Connections from other servers',
1.275 raeburn 5884: replication => 'Replicating content to other institutions',
5885: certreq => 'Client certificate required, but specific domains exempt',
5886: nocertreq => 'No client certificate required, except for specific domains',
5887: no => 'SSL not used',
5888: yes => 'SSL Optional (used if available)',
5889: req => 'SSL Required',
5890: );
1.279 raeburn 5891: }
5892:
5893: sub print_trust {
5894: my ($prefix,$dom,$settings,$rowtotal) = @_;
5895: my ($css_class,$datatable,%checked,%choices);
5896: my (%by_ip,%by_location,@intdoms,@instdoms);
5897: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
5898: my $itemcount = 1;
5899: my %titles = &trust_titles();
5900: my @types = ('exc','inc');
5901: if ($prefix eq 'top') {
5902: $prefix = 'content';
5903: } elsif ($prefix eq 'bottom') {
5904: $prefix = 'msg';
5905: }
5906: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
5907: $$rowtotal += $itemcount;
5908: return $datatable;
5909: }
5910:
5911: sub trust_titles {
5912: return &Apache::lonlocal::texthash(
5913: content => "Access to this domain's content by others",
5914: shared => "Access to other domain's content by this domain",
5915: enroll => "Enrollment in this domain's courses by others",
5916: othcoau => "Co-author roles in this domain for others",
5917: coaurem => "Co-author roles for this domain's users elsewhere",
5918: domroles => "Domain roles in this domain assignable to others",
5919: catalog => "Course Catalog for this domain displayed elsewhere",
5920: reqcrs => "Requests for creation of courses in this domain by others",
5921: msg => "Users in other domains can send messages to this domain",
5922: exc => "Allow all, but exclude specific domains",
5923: inc => "Deny all, but include specific domains",
5924: );
1.275 raeburn 5925: }
5926:
1.138 raeburn 5927: sub build_location_hashes {
1.275 raeburn 5928: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 5929: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 5930: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 5931: my %iphost = &Apache::lonnet::get_iphost();
5932: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
5933: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
5934: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
5935: foreach my $id (@{$iphost{$primary_ip}}) {
5936: my $intdom = &Apache::lonnet::internet_dom($id);
5937: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
5938: push(@{$intdoms},$intdom);
5939: }
5940: }
5941: }
5942: foreach my $ip (keys(%iphost)) {
5943: if (ref($iphost{$ip}) eq 'ARRAY') {
5944: foreach my $id (@{$iphost{$ip}}) {
5945: my $location = &Apache::lonnet::internet_dom($id);
5946: if ($location) {
1.275 raeburn 5947: if (grep(/^\Q$location\E$/,@{$intdoms})) {
5948: my $dom = &Apache::lonnet::host_domain($id);
5949: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
5950: push(@{$instdoms},$dom);
5951: }
5952: next;
5953: }
1.138 raeburn 5954: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5955: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
5956: push(@{$by_ip->{$ip}},$location);
5957: }
5958: } else {
5959: $by_ip->{$ip} = [$location];
5960: }
5961: }
5962: }
5963: }
5964: }
5965: foreach my $ip (sort(keys(%{$by_ip}))) {
5966: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5967: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
5968: my $first = $by_ip->{$ip}->[0];
5969: if (ref($by_location->{$first}) eq 'ARRAY') {
5970: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
5971: push(@{$by_location->{$first}},$ip);
5972: }
5973: } else {
5974: $by_location->{$first} = [$ip];
5975: }
5976: }
5977: }
5978: return;
5979: }
5980:
1.145 raeburn 5981: sub current_offloads_to {
5982: my ($dom,$settings,$servers) = @_;
5983: my (%spareid,%otherdomconfigs);
1.152 raeburn 5984: if (ref($servers) eq 'HASH') {
1.145 raeburn 5985: foreach my $lonhost (sort(keys(%{$servers}))) {
5986: my $gotspares;
1.152 raeburn 5987: if (ref($settings) eq 'HASH') {
5988: if (ref($settings->{'spares'}) eq 'HASH') {
5989: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
5990: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
5991: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
5992: $gotspares = 1;
5993: }
1.145 raeburn 5994: }
5995: }
5996: unless ($gotspares) {
5997: my $gotspares;
5998: my $serverhomeID =
5999: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
6000: my $serverhomedom =
6001: &Apache::lonnet::host_domain($serverhomeID);
6002: if ($serverhomedom ne $dom) {
6003: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
6004: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
6005: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
6006: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
6007: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
6008: $gotspares = 1;
6009: }
6010: }
6011: } else {
6012: $otherdomconfigs{$serverhomedom} =
6013: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
6014: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
6015: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
6016: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
6017: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
6018: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
6019: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
6020: $gotspares = 1;
6021: }
6022: }
6023: }
6024: }
6025: }
6026: }
6027: }
6028: unless ($gotspares) {
6029: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
6030: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6031: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6032: } else {
6033: my $server_hostname = &Apache::lonnet::hostname($lonhost);
6034: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
6035: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
6036: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6037: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6038: } else {
1.150 raeburn 6039: my %what = (
6040: spareid => 1,
6041: );
6042: my ($result,$returnhash) =
6043: &Apache::lonnet::get_remote_globals($lonhost,\%what);
6044: if ($result eq 'ok') {
6045: if (ref($returnhash) eq 'HASH') {
6046: if (ref($returnhash->{'spareid'}) eq 'HASH') {
6047: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
6048: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
6049: }
6050: }
1.145 raeburn 6051: }
6052: }
6053: }
6054: }
6055: }
6056: }
6057: return %spareid;
6058: }
6059:
6060: sub spares_row {
1.261 raeburn 6061: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 6062: my $css_class;
6063: my $numinrow = 4;
6064: my $itemcount = 1;
6065: my $datatable;
1.152 raeburn 6066: my %typetitles = &sparestype_titles();
6067: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 6068: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 6069: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
6070: my ($othercontrol,$serverdom);
6071: if ($serverhome ne $server) {
6072: $serverdom = &Apache::lonnet::host_domain($serverhome);
6073: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6074: } else {
6075: $serverdom = &Apache::lonnet::host_domain($server);
6076: if ($serverdom ne $dom) {
6077: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6078: }
6079: }
6080: next unless (ref($spareid->{$server}) eq 'HASH');
1.261 raeburn 6081: my $checkednow;
6082: if (ref($curroffloadnow) eq 'HASH') {
6083: if ($curroffloadnow->{$server}) {
6084: $checkednow = ' checked="checked"';
6085: }
6086: }
1.145 raeburn 6087: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6088: $datatable .= '<tr'.$css_class.'>
6089: <td rowspan="2">
1.183 bisitz 6090: <span class="LC_nobreak">'.
6091: &mt('[_1] when busy, offloads to:'
1.261 raeburn 6092: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 6093: '<span class="LC_nobreak">'."\n".
1.261 raeburn 6094: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
6095: ' '.&mt('Switch active users on next access').'</label></span>'.
1.183 bisitz 6096: "\n";
1.145 raeburn 6097: my (%current,%canselect);
1.152 raeburn 6098: my @choices =
6099: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
6100: foreach my $type ('primary','default') {
6101: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 6102: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
6103: my @spares = @{$spareid->{$server}{$type}};
6104: if (@spares > 0) {
1.152 raeburn 6105: if ($othercontrol) {
6106: $current{$type} = join(', ',@spares);
6107: } else {
6108: $current{$type} .= '<table>';
6109: my $numspares = scalar(@spares);
6110: for (my $i=0; $i<@spares; $i++) {
6111: my $rem = $i%($numinrow);
6112: if ($rem == 0) {
6113: if ($i > 0) {
6114: $current{$type} .= '</tr>';
6115: }
6116: $current{$type} .= '<tr>';
1.145 raeburn 6117: }
1.152 raeburn 6118: $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'".');" /> '.
6119: $spareid->{$server}{$type}[$i].
6120: '</label></td>'."\n";
6121: }
6122: my $rem = @spares%($numinrow);
6123: my $colsleft = $numinrow - $rem;
6124: if ($colsleft > 1 ) {
6125: $current{$type} .= '<td colspan="'.$colsleft.
6126: '" class="LC_left_item">'.
6127: ' </td>';
6128: } elsif ($colsleft == 1) {
6129: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 6130: }
1.152 raeburn 6131: $current{$type} .= '</tr></table>';
1.150 raeburn 6132: }
1.145 raeburn 6133: }
6134: }
6135: if ($current{$type} eq '') {
6136: $current{$type} = &mt('None specified');
6137: }
1.152 raeburn 6138: if ($othercontrol) {
6139: if ($type eq 'primary') {
6140: $canselect{$type} = $othercontrol;
6141: }
6142: } else {
6143: $canselect{$type} =
6144: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
6145: '<select name="newspare_'.$type.'_'.$server.'" '.
6146: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
6147: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
6148: if (@choices > 0) {
6149: foreach my $lonhost (@choices) {
6150: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
6151: }
6152: }
6153: $canselect{$type} .= '</select>'."\n";
6154: }
6155: } else {
6156: $current{$type} = &mt('Could not be determined');
6157: if ($type eq 'primary') {
6158: $canselect{$type} = $othercontrol;
6159: }
1.145 raeburn 6160: }
1.152 raeburn 6161: if ($type eq 'default') {
6162: $datatable .= '<tr'.$css_class.'>';
6163: }
6164: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
6165: '<td>'.$current{$type}.'</td>'."\n".
6166: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 6167: }
6168: $itemcount ++;
6169: }
6170: }
6171: $$rowtotal += $itemcount;
6172: return $datatable;
6173: }
6174:
1.152 raeburn 6175: sub possible_newspares {
6176: my ($server,$currspares,$serverhomes,$altids) = @_;
6177: my $serverhostname = &Apache::lonnet::hostname($server);
6178: my %excluded;
6179: if ($serverhostname ne '') {
6180: %excluded = (
6181: $serverhostname => 1,
6182: );
6183: }
6184: if (ref($currspares) eq 'HASH') {
6185: foreach my $type (keys(%{$currspares})) {
6186: if (ref($currspares->{$type}) eq 'ARRAY') {
6187: if (@{$currspares->{$type}} > 0) {
6188: foreach my $curr (@{$currspares->{$type}}) {
6189: my $hostname = &Apache::lonnet::hostname($curr);
6190: $excluded{$hostname} = 1;
6191: }
6192: }
6193: }
6194: }
6195: }
6196: my @choices;
6197: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
6198: if (keys(%{$serverhomes}) > 1) {
6199: foreach my $name (sort(keys(%{$serverhomes}))) {
6200: unless ($excluded{$name}) {
6201: if (exists($altids->{$serverhomes->{$name}})) {
6202: push(@choices,$altids->{$serverhomes->{$name}});
6203: } else {
6204: push(@choices,$serverhomes->{$name});
1.145 raeburn 6205: }
6206: }
6207: }
6208: }
6209: }
1.152 raeburn 6210: return sort(@choices);
1.145 raeburn 6211: }
6212:
1.150 raeburn 6213: sub print_loadbalancing {
6214: my ($dom,$settings,$rowtotal) = @_;
6215: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6216: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6217: my $numinrow = 1;
6218: my $datatable;
6219: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 6220: my (%currbalancer,%currtargets,%currrules,%existing);
6221: if (ref($settings) eq 'HASH') {
6222: %existing = %{$settings};
6223: }
6224: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
6225: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
6226: \%currtargets,\%currrules);
1.150 raeburn 6227: } else {
6228: return;
6229: }
6230: my ($othertitle,$usertypes,$types) =
6231: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 6232: my $rownum = 8;
1.150 raeburn 6233: if (ref($types) eq 'ARRAY') {
6234: $rownum += scalar(@{$types});
6235: }
1.171 raeburn 6236: my @css_class = ('LC_odd_row','LC_even_row');
6237: my $balnum = 0;
6238: my $islast;
6239: my (@toshow,$disabledtext);
6240: if (keys(%currbalancer) > 0) {
6241: @toshow = sort(keys(%currbalancer));
6242: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
6243: push(@toshow,'');
6244: }
6245: } else {
6246: @toshow = ('');
6247: $disabledtext = &mt('No existing load balancer');
6248: }
6249: foreach my $lonhost (@toshow) {
6250: if ($balnum == scalar(@toshow)-1) {
6251: $islast = 1;
6252: } else {
6253: $islast = 0;
6254: }
6255: my $cssidx = $balnum%2;
6256: my $targets_div_style = 'display: none';
6257: my $disabled_div_style = 'display: block';
6258: my $homedom_div_style = 'display: none';
6259: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 6260: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 6261: '<p>';
6262: if ($lonhost eq '') {
1.210 raeburn 6263: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 6264: if (keys(%currbalancer) > 0) {
6265: $datatable .= &mt('Add balancer:');
6266: } else {
6267: $datatable .= &mt('Enable balancer:');
6268: }
6269: $datatable .= ' '.
6270: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
6271: ' id="loadbalancing_lonhost_'.$balnum.'"'.
6272: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
6273: '<option value="" selected="selected">'.&mt('None').
6274: '</option>'."\n";
6275: foreach my $server (sort(keys(%servers))) {
6276: next if ($currbalancer{$server});
6277: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
6278: }
1.210 raeburn 6279: $datatable .=
1.171 raeburn 6280: '</select>'."\n".
6281: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
6282: } else {
6283: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
6284: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
6285: &mt('Stop balancing').'</label>'.
6286: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
6287: $targets_div_style = 'display: block';
6288: $disabled_div_style = 'display: none';
6289: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
6290: $homedom_div_style = 'display: block';
6291: }
6292: }
1.306 raeburn 6293: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 6294: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
6295: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
6296: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
6297: my ($numspares,@spares) = &count_servers($lonhost,%servers);
6298: my @sparestypes = ('primary','default');
6299: my %typetitles = &sparestype_titles();
1.284 raeburn 6300: my %hostherechecked = (
6301: no => ' checked="checked"',
6302: );
1.171 raeburn 6303: foreach my $sparetype (@sparestypes) {
6304: my $targettable;
6305: for (my $i=0; $i<$numspares; $i++) {
6306: my $checked;
6307: if (ref($currtargets{$lonhost}) eq 'HASH') {
6308: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6309: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6310: $checked = ' checked="checked"';
6311: }
6312: }
6313: }
6314: my ($chkboxval,$disabled);
6315: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
6316: $chkboxval = $spares[$i];
6317: }
6318: if (exists($currbalancer{$spares[$i]})) {
6319: $disabled = ' disabled="disabled"';
6320: }
1.210 raeburn 6321: $targettable .=
1.253 raeburn 6322: '<td><span class="LC_nobreak"><label>'.
6323: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 6324: $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 6325: '</span></label></span></td>';
1.171 raeburn 6326: my $rem = $i%($numinrow);
6327: if ($rem == 0) {
6328: if (($i > 0) && ($i < $numspares-1)) {
6329: $targettable .= '</tr>';
6330: }
6331: if ($i < $numspares-1) {
6332: $targettable .= '<tr>';
1.150 raeburn 6333: }
6334: }
6335: }
1.171 raeburn 6336: if ($targettable ne '') {
6337: my $rem = $numspares%($numinrow);
6338: my $colsleft = $numinrow - $rem;
6339: if ($colsleft > 1 ) {
6340: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6341: ' </td>';
6342: } elsif ($colsleft == 1) {
6343: $targettable .= '<td class="LC_left_item"> </td>';
6344: }
6345: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
6346: '<table><tr>'.$targettable.'</tr></table><br />';
6347: }
1.284 raeburn 6348: $hostherechecked{$sparetype} = '';
6349: if (ref($currtargets{$lonhost}) eq 'HASH') {
6350: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6351: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6352: $hostherechecked{$sparetype} = ' checked="checked"';
6353: $hostherechecked{'no'} = '';
6354: }
6355: }
6356: }
6357: }
6358: $datatable .= &mt('Hosting on balancer itself').'<br />'.
6359: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
6360: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
6361: foreach my $sparetype (@sparestypes) {
6362: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
6363: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
6364: '</i></label><br />';
1.171 raeburn 6365: }
6366: $datatable .= '</div></td></tr>'.
6367: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
6368: $othertitle,$usertypes,$types,\%servers,
6369: \%currbalancer,$lonhost,
6370: $targets_div_style,$homedom_div_style,
6371: $css_class[$cssidx],$balnum,$islast);
6372: $$rowtotal += $rownum;
6373: $balnum ++;
6374: }
6375: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
6376: return $datatable;
6377: }
6378:
6379: sub get_loadbalancers_config {
6380: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
6381: return unless ((ref($servers) eq 'HASH') &&
6382: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
6383: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
6384: if (keys(%{$existing}) > 0) {
6385: my $oldlonhost;
6386: foreach my $key (sort(keys(%{$existing}))) {
6387: if ($key eq 'lonhost') {
6388: $oldlonhost = $existing->{'lonhost'};
6389: $currbalancer->{$oldlonhost} = 1;
6390: } elsif ($key eq 'targets') {
6391: if ($oldlonhost) {
6392: $currtargets->{$oldlonhost} = $existing->{'targets'};
6393: }
6394: } elsif ($key eq 'rules') {
6395: if ($oldlonhost) {
6396: $currrules->{$oldlonhost} = $existing->{'rules'};
6397: }
6398: } elsif (ref($existing->{$key}) eq 'HASH') {
6399: $currbalancer->{$key} = 1;
6400: $currtargets->{$key} = $existing->{$key}{'targets'};
6401: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 6402: }
6403: }
1.171 raeburn 6404: } else {
6405: my ($balancerref,$targetsref) =
6406: &Apache::lonnet::get_lonbalancer_config($servers);
6407: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
6408: foreach my $server (sort(keys(%{$balancerref}))) {
6409: $currbalancer->{$server} = 1;
6410: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 6411: }
6412: }
6413: }
1.171 raeburn 6414: return;
1.150 raeburn 6415: }
6416:
6417: sub loadbalancing_rules {
6418: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 6419: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
6420: $css_class,$balnum,$islast) = @_;
1.150 raeburn 6421: my $output;
1.171 raeburn 6422: my $num = 0;
1.210 raeburn 6423: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 6424: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
6425: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
6426: foreach my $type (@{$alltypes}) {
1.171 raeburn 6427: $num ++;
1.150 raeburn 6428: my $current;
6429: if (ref($currrules) eq 'HASH') {
6430: $current = $currrules->{$type};
6431: }
1.253 raeburn 6432: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 6433: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 6434: $current = '';
6435: }
6436: }
6437: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 6438: $servers,$currbalancer,$lonhost,$dom,
6439: $targets_div_style,$homedom_div_style,
6440: $css_class,$balnum,$num,$islast);
1.150 raeburn 6441: }
6442: }
6443: return $output;
6444: }
6445:
6446: sub loadbalancing_titles {
6447: my ($dom,$intdom,$usertypes,$types) = @_;
6448: my %othertypes = (
6449: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
6450: '_LC_author' => &mt('Users from [_1] with author role',$dom),
6451: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
6452: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 6453: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
6454: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 6455: );
1.209 raeburn 6456: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 6457: my @available;
1.150 raeburn 6458: if (ref($types) eq 'ARRAY') {
1.302 raeburn 6459: @available = @{$types};
1.150 raeburn 6460: }
1.302 raeburn 6461: unless (grep(/^default$/,@available)) {
6462: push(@available,'default');
6463: }
6464: unshift(@alltypes,@available);
1.150 raeburn 6465: my %titles;
6466: foreach my $type (@alltypes) {
6467: if ($type =~ /^_LC_/) {
6468: $titles{$type} = $othertypes{$type};
6469: } elsif ($type eq 'default') {
6470: $titles{$type} = &mt('All users from [_1]',$dom);
6471: if (ref($types) eq 'ARRAY') {
6472: if (@{$types} > 0) {
6473: $titles{$type} = &mt('Other users from [_1]',$dom);
6474: }
6475: }
6476: } elsif (ref($usertypes) eq 'HASH') {
6477: $titles{$type} = $usertypes->{$type};
6478: }
6479: }
6480: return (\@alltypes,\%othertypes,\%titles);
6481: }
6482:
6483: sub loadbalance_rule_row {
1.171 raeburn 6484: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
6485: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 6486: my @rulenames;
1.150 raeburn 6487: my %ruletitles = &offloadtype_text();
1.209 raeburn 6488: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 6489: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 6490: } else {
1.209 raeburn 6491: @rulenames = ('default','homeserver');
6492: if ($type eq '_LC_external') {
6493: push(@rulenames,'externalbalancer');
6494: } else {
6495: push(@rulenames,'specific');
6496: }
6497: push(@rulenames,'none');
1.150 raeburn 6498: }
6499: my $style = $targets_div_style;
1.253 raeburn 6500: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 6501: $style = $homedom_div_style;
6502: }
1.171 raeburn 6503: my $space;
6504: if ($islast && $num == 1) {
1.317 raeburn 6505: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 6506: }
1.210 raeburn 6507: my $output =
1.306 raeburn 6508: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 6509: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
6510: '<td valaign="top">'.$space.
6511: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 6512: for (my $i=0; $i<@rulenames; $i++) {
6513: my $rule = $rulenames[$i];
6514: my ($checked,$extra);
6515: if ($rulenames[$i] eq 'default') {
6516: $rule = '';
6517: }
6518: if ($rulenames[$i] eq 'specific') {
6519: if (ref($servers) eq 'HASH') {
6520: my $default;
6521: if (($current ne '') && (exists($servers->{$current}))) {
6522: $checked = ' checked="checked"';
6523: }
6524: unless ($checked) {
6525: $default = ' selected="selected"';
6526: }
1.210 raeburn 6527: $extra =
1.171 raeburn 6528: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
6529: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
6530: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
6531: '<option value=""'.$default.'></option>'."\n";
6532: foreach my $server (sort(keys(%{$servers}))) {
6533: if (ref($currbalancer) eq 'HASH') {
6534: next if (exists($currbalancer->{$server}));
6535: }
1.150 raeburn 6536: my $selected;
1.171 raeburn 6537: if ($server eq $current) {
1.150 raeburn 6538: $selected = ' selected="selected"';
6539: }
1.171 raeburn 6540: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 6541: }
6542: $extra .= '</select>';
6543: }
6544: } elsif ($rule eq $current) {
6545: $checked = ' checked="checked"';
6546: }
6547: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 6548: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
6549: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
6550: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 6551: ')"'.$checked.' /> ';
6552: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
6553: $output .= $ruletitles{'particular'};
6554: } else {
6555: $output .= $ruletitles{$rulenames[$i]};
6556: }
6557: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 6558: }
6559: $output .= '</div></td></tr>'."\n";
6560: return $output;
6561: }
6562:
6563: sub offloadtype_text {
6564: my %ruletitles = &Apache::lonlocal::texthash (
6565: 'default' => 'Offloads to default destinations',
6566: 'homeserver' => "Offloads to user's home server",
6567: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
6568: 'specific' => 'Offloads to specific server',
1.161 raeburn 6569: 'none' => 'No offload',
1.209 raeburn 6570: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
6571: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 6572: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 6573: );
6574: return %ruletitles;
6575: }
6576:
6577: sub sparestype_titles {
6578: my %typestitles = &Apache::lonlocal::texthash (
6579: 'primary' => 'primary',
6580: 'default' => 'default',
6581: );
6582: return %typestitles;
6583: }
6584:
1.28 raeburn 6585: sub contact_titles {
6586: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 6587: 'supportemail' => 'Support E-mail address',
6588: 'adminemail' => 'Default Server Admin E-mail address',
6589: 'errormail' => 'Error reports to be e-mailed to',
6590: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 6591: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
6592: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 6593: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
6594: 'requestsmail' => 'E-mail from course requests requiring approval',
6595: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 6596: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 6597: );
6598: my %short_titles = &Apache::lonlocal::texthash (
6599: adminemail => 'Admin E-mail address',
6600: supportemail => 'Support E-mail',
6601: );
6602: return (\%titles,\%short_titles);
6603: }
6604:
1.286 raeburn 6605: sub helpform_fields {
6606: my %titles = &Apache::lonlocal::texthash (
6607: 'username' => 'Name',
6608: 'user' => 'Username/domain',
6609: 'phone' => 'Phone',
6610: 'cc' => 'Cc e-mail',
6611: 'course' => 'Course Details',
6612: 'section' => 'Sections',
1.289 raeburn 6613: 'screenshot' => 'File upload',
1.286 raeburn 6614: );
6615: my @fields = ('username','phone','user','course','section','cc','screenshot');
6616: my %possoptions = (
6617: username => ['yes','no','req'],
1.289 raeburn 6618: phone => ['yes','no','req'],
1.286 raeburn 6619: user => ['yes','no'],
1.289 raeburn 6620: cc => ['yes','no'],
1.286 raeburn 6621: course => ['yes','no'],
6622: section => ['yes','no'],
6623: screenshot => ['yes','no'],
6624: );
6625: my %fieldoptions = &Apache::lonlocal::texthash (
6626: 'yes' => 'Optional',
6627: 'req' => 'Required',
6628: 'no' => "Not shown",
6629: );
6630: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
6631: }
6632:
1.72 raeburn 6633: sub tool_titles {
6634: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 6635: aboutme => 'Personal web page',
1.86 raeburn 6636: blog => 'Blog',
1.162 raeburn 6637: webdav => 'WebDAV',
1.86 raeburn 6638: portfolio => 'Portfolio',
1.88 bisitz 6639: official => 'Official courses (with institutional codes)',
6640: unofficial => 'Unofficial courses',
1.98 raeburn 6641: community => 'Communities',
1.216 raeburn 6642: textbook => 'Textbook courses',
1.271 raeburn 6643: placement => 'Placement tests',
1.86 raeburn 6644: );
1.72 raeburn 6645: return %titles;
6646: }
6647:
1.101 raeburn 6648: sub courserequest_titles {
6649: my %titles = &Apache::lonlocal::texthash (
6650: official => 'Official',
6651: unofficial => 'Unofficial',
6652: community => 'Communities',
1.216 raeburn 6653: textbook => 'Textbook',
1.271 raeburn 6654: placement => 'Placement tests',
1.325 raeburn 6655: lti => 'LTI Provider',
1.101 raeburn 6656: norequest => 'Not allowed',
1.325 raeburn 6657: approval => 'Approval by DC',
1.101 raeburn 6658: validate => 'With validation',
6659: autolimit => 'Numerical limit',
1.103 raeburn 6660: unlimited => '(blank for unlimited)',
1.101 raeburn 6661: );
6662: return %titles;
6663: }
6664:
1.163 raeburn 6665: sub authorrequest_titles {
6666: my %titles = &Apache::lonlocal::texthash (
6667: norequest => 'Not allowed',
6668: approval => 'Approval by Dom. Coord.',
6669: automatic => 'Automatic approval',
6670: );
6671: return %titles;
1.210 raeburn 6672: }
1.163 raeburn 6673:
1.101 raeburn 6674: sub courserequest_conditions {
6675: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 6676: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 6677: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 6678: );
6679: return %conditions;
6680: }
6681:
6682:
1.27 raeburn 6683: sub print_usercreation {
1.30 raeburn 6684: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 6685: my $numinrow = 4;
1.28 raeburn 6686: my $datatable;
6687: if ($position eq 'top') {
1.30 raeburn 6688: $$rowtotal ++;
1.34 raeburn 6689: my $rowcount = 0;
1.32 raeburn 6690: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 6691: if (ref($rules) eq 'HASH') {
6692: if (keys(%{$rules}) > 0) {
1.32 raeburn 6693: $datatable .= &user_formats_row('username',$settings,$rules,
6694: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 6695: $$rowtotal ++;
1.32 raeburn 6696: $rowcount ++;
6697: }
6698: }
6699: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
6700: if (ref($idrules) eq 'HASH') {
6701: if (keys(%{$idrules}) > 0) {
6702: $datatable .= &user_formats_row('id',$settings,$idrules,
6703: $idruleorder,$numinrow,$rowcount);
6704: $$rowtotal ++;
6705: $rowcount ++;
1.28 raeburn 6706: }
6707: }
1.39 raeburn 6708: if ($rowcount == 0) {
6709: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
6710: $$rowtotal ++;
6711: $rowcount ++;
6712: }
1.34 raeburn 6713: } elsif ($position eq 'middle') {
1.224 raeburn 6714: my @creators = ('author','course','requestcrs');
1.37 raeburn 6715: my ($rules,$ruleorder) =
6716: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 6717: my %lt = &usercreation_types();
6718: my %checked;
6719: if (ref($settings) eq 'HASH') {
6720: if (ref($settings->{'cancreate'}) eq 'HASH') {
6721: foreach my $item (@creators) {
6722: $checked{$item} = $settings->{'cancreate'}{$item};
6723: }
6724: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
6725: foreach my $item (@creators) {
6726: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
6727: $checked{$item} = 'none';
6728: }
6729: }
6730: }
6731: }
6732: my $rownum = 0;
6733: foreach my $item (@creators) {
6734: $rownum ++;
1.224 raeburn 6735: if ($checked{$item} eq '') {
6736: $checked{$item} = 'any';
1.34 raeburn 6737: }
6738: my $css_class;
6739: if ($rownum%2) {
6740: $css_class = '';
6741: } else {
6742: $css_class = ' class="LC_odd_row" ';
6743: }
6744: $datatable .= '<tr'.$css_class.'>'.
6745: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 6746: '</span></td><td style="text-align: right">';
1.224 raeburn 6747: my @options = ('any');
6748: if (ref($rules) eq 'HASH') {
6749: if (keys(%{$rules}) > 0) {
6750: push(@options,('official','unofficial'));
1.37 raeburn 6751: }
6752: }
1.224 raeburn 6753: push(@options,'none');
1.37 raeburn 6754: foreach my $option (@options) {
1.50 raeburn 6755: my $type = 'radio';
1.34 raeburn 6756: my $check = ' ';
1.224 raeburn 6757: if ($checked{$item} eq $option) {
6758: $check = ' checked="checked" ';
1.34 raeburn 6759: }
6760: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 6761: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 6762: $item.'" value="'.$option.'"'.$check.'/> '.
6763: $lt{$option}.'</label> </span>';
6764: }
6765: $datatable .= '</td></tr>';
6766: }
1.28 raeburn 6767: } else {
6768: my @contexts = ('author','course','domain');
1.325 raeburn 6769: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 6770: my %checked;
6771: if (ref($settings) eq 'HASH') {
6772: if (ref($settings->{'authtypes'}) eq 'HASH') {
6773: foreach my $item (@contexts) {
6774: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
6775: foreach my $auth (@authtypes) {
6776: if ($settings->{'authtypes'}{$item}{$auth}) {
6777: $checked{$item}{$auth} = ' checked="checked" ';
6778: }
6779: }
6780: }
6781: }
1.27 raeburn 6782: }
1.35 raeburn 6783: } else {
6784: foreach my $item (@contexts) {
1.36 raeburn 6785: foreach my $auth (@authtypes) {
1.35 raeburn 6786: $checked{$item}{$auth} = ' checked="checked" ';
6787: }
6788: }
1.27 raeburn 6789: }
1.28 raeburn 6790: my %title = &context_names();
6791: my %authname = &authtype_names();
6792: my $rownum = 0;
6793: my $css_class;
6794: foreach my $item (@contexts) {
6795: if ($rownum%2) {
6796: $css_class = '';
6797: } else {
6798: $css_class = ' class="LC_odd_row" ';
6799: }
1.30 raeburn 6800: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 6801: '<td>'.$title{$item}.
6802: '</td><td class="LC_left_item">'.
6803: '<span class="LC_nobreak">';
6804: foreach my $auth (@authtypes) {
6805: $datatable .= '<label>'.
6806: '<input type="checkbox" name="'.$item.'_auth" '.
6807: $checked{$item}{$auth}.' value="'.$auth.'" />'.
6808: $authname{$auth}.'</label> ';
6809: }
6810: $datatable .= '</span></td></tr>';
6811: $rownum ++;
1.27 raeburn 6812: }
1.30 raeburn 6813: $$rowtotal += $rownum;
1.27 raeburn 6814: }
6815: return $datatable;
6816: }
6817:
1.224 raeburn 6818: sub print_selfcreation {
6819: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 6820: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
6821: $emaildomain,$datatable);
1.224 raeburn 6822: if (ref($settings) eq 'HASH') {
6823: if (ref($settings->{'cancreate'}) eq 'HASH') {
6824: $createsettings = $settings->{'cancreate'};
1.236 raeburn 6825: if (ref($createsettings) eq 'HASH') {
6826: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
6827: @selfcreate = @{$createsettings->{'selfcreate'}};
6828: } elsif ($createsettings->{'selfcreate'} ne '') {
6829: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
6830: @selfcreate = ('email','login','sso');
6831: } elsif ($createsettings->{'selfcreate'} ne 'none') {
6832: @selfcreate = ($createsettings->{'selfcreate'});
6833: }
6834: }
6835: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
6836: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 6837: }
1.305 raeburn 6838: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
6839: $emailoptions = $createsettings->{'emailoptions'};
6840: }
1.303 raeburn 6841: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
6842: $emailverified = $createsettings->{'emailverified'};
6843: }
6844: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
6845: $emaildomain = $createsettings->{'emaildomain'};
6846: }
1.224 raeburn 6847: }
6848: }
6849: }
6850: my %radiohash;
6851: my $numinrow = 4;
6852: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 6853: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 6854: if ($position eq 'top') {
6855: my %choices = &Apache::lonlocal::texthash (
6856: cancreate_login => 'Institutional Login',
6857: cancreate_sso => 'Institutional Single Sign On',
6858: );
6859: my @toggles = sort(keys(%choices));
6860: my %defaultchecked = (
6861: 'cancreate_login' => 'off',
6862: 'cancreate_sso' => 'off',
6863: );
1.228 raeburn 6864: my ($onclick,$itemcount);
1.224 raeburn 6865: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6866: \%choices,$itemcount,$onclick);
1.228 raeburn 6867: $$rowtotal += $itemcount;
6868:
1.224 raeburn 6869: if (ref($usertypes) eq 'HASH') {
6870: if (keys(%{$usertypes}) > 0) {
6871: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
6872: $dom,$numinrow,$othertitle,
1.305 raeburn 6873: 'statustocreate',$rowtotal);
1.224 raeburn 6874: $$rowtotal ++;
6875: }
6876: }
1.240 raeburn 6877: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
6878: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6879: $fieldtitles{'inststatus'} = &mt('Institutional status');
6880: my $rem;
6881: my $numperrow = 2;
6882: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
6883: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 6884: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 6885: '<td class="LC_left_item">'."\n".
1.334 raeburn 6886: '<table>'."\n";
1.240 raeburn 6887: for (my $i=0; $i<@fields; $i++) {
6888: $rem = $i%($numperrow);
6889: if ($rem == 0) {
6890: if ($i > 0) {
6891: $datatable .= '</tr>';
6892: }
6893: $datatable .= '<tr>';
6894: }
6895: my $currval;
1.248 raeburn 6896: if (ref($createsettings) eq 'HASH') {
6897: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
6898: $currval = $createsettings->{'shibenv'}{$fields[$i]};
6899: }
1.240 raeburn 6900: }
6901: $datatable .= '<td class="LC_left_item">'.
6902: '<span class="LC_nobreak">'.
6903: '<input type="text" name="shibenv_'.$fields[$i].'" '.
6904: 'value="'.$currval.'" size="10" /> '.
6905: $fieldtitles{$fields[$i]}.'</span></td>';
6906: }
6907: my $colsleft = $numperrow - $rem;
6908: if ($colsleft > 1 ) {
6909: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6910: ' </td>';
6911: } elsif ($colsleft == 1) {
6912: $datatable .= '<td class="LC_left_item"> </td>';
6913: }
6914: $datatable .= '</tr></table></td></tr>';
6915: $$rowtotal ++;
1.224 raeburn 6916: } elsif ($position eq 'middle') {
6917: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 6918: my @posstypes;
1.224 raeburn 6919: if (ref($types) eq 'ARRAY') {
1.302 raeburn 6920: @posstypes = @{$types};
6921: }
6922: unless (grep(/^default$/,@posstypes)) {
6923: push(@posstypes,'default');
6924: }
6925: my %usertypeshash;
6926: if (ref($usertypes) eq 'HASH') {
6927: %usertypeshash = %{$usertypes};
6928: }
6929: $usertypeshash{'default'} = $othertitle;
6930: foreach my $status (@posstypes) {
6931: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
6932: $numinrow,$$rowtotal,\%usertypeshash);
6933: $$rowtotal ++;
1.224 raeburn 6934: }
6935: } else {
1.236 raeburn 6936: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 6937: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 6938: );
6939: my @toggles = sort(keys(%choices));
6940: my %defaultchecked = (
6941: 'cancreate_email' => 'off',
6942: );
1.305 raeburn 6943: my $customclass = 'LC_selfcreate_email';
6944: my $classprefix = 'LC_canmodify_emailusername_';
6945: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 6946: my $display = 'none';
1.305 raeburn 6947: my $rowstyle = 'display:none';
1.236 raeburn 6948: if (grep(/^\Qemail\E$/,@selfcreate)) {
6949: $display = 'block';
1.305 raeburn 6950: $rowstyle = 'display:table-row';
1.236 raeburn 6951: }
1.305 raeburn 6952: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
6953: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6954: \%choices,$$rowtotal,$onclick);
6955: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
6956: $rowstyle);
6957: $$rowtotal ++;
6958: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
6959: $rowstyle);
6960: $$rowtotal ++;
6961: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 6962: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 6963: my ($emailrules,$emailruleorder) =
6964: &Apache::lonnet::inst_userrules($dom,'email');
6965: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6966: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6967: if (ref($types) eq 'ARRAY') {
6968: @posstypes = @{$types};
6969: }
6970: if (@posstypes) {
6971: unless (grep(/^default$/,@posstypes)) {
6972: push(@posstypes,'default');
1.302 raeburn 6973: }
6974: if (ref($usertypes) eq 'HASH') {
6975: %usertypeshash = %{$usertypes};
6976: }
1.305 raeburn 6977: my $currassign;
6978: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
6979: $currassign = {
6980: selfassign => $domdefaults{'inststatusguest'},
6981: };
6982: @ordered = @{$domdefaults{'inststatusguest'}};
6983: } else {
6984: $currassign = { selfassign => [] };
6985: }
6986: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
6987: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
6988: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
6989: $numinrow,$othertitle,'selfassign',
6990: $rowtotal,$onclicktypes,$customclass,
6991: $rowstyle);
6992: $$rowtotal ++;
1.302 raeburn 6993: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 6994: foreach my $status (@posstypes) {
6995: my $css_class;
6996: if ($$rowtotal%2) {
6997: $css_class = 'LC_odd_row ';
6998: }
6999: $css_class .= $customclass;
7000: my $rowid = $optionsprefix.$status;
7001: my $hidden = 1;
7002: my $currstyle = 'display:none';
7003: if (grep(/^\Q$status\E$/,@ordered)) {
7004: $currstyle = $rowstyle;
7005: $hidden = 0;
7006: }
7007: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7008: $emailrules,$emailruleorder,$settings,$status,$rowid,
7009: $usertypeshash{$status},$css_class,$currstyle,$intdom);
7010: unless ($hidden) {
7011: $$rowtotal ++;
7012: }
1.224 raeburn 7013: }
1.302 raeburn 7014: } else {
1.305 raeburn 7015: my $css_class;
7016: if ($$rowtotal%2) {
7017: $css_class = 'LC_odd_row ';
7018: }
7019: $css_class .= $customclass;
1.302 raeburn 7020: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 7021: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7022: $emailrules,$emailruleorder,$settings,'default','',
7023: $othertitle,$css_class,$rowstyle,$intdom);
7024: $$rowtotal ++;
1.224 raeburn 7025: }
7026: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 7027: $numinrow = 1;
1.305 raeburn 7028: if (@posstypes) {
7029: foreach my $status (@posstypes) {
7030: my $rowid = $classprefix.$status;
7031: my $datarowstyle = 'display:none';
7032: if (grep(/^\Q$status\E$/,@ordered)) {
7033: $datarowstyle = $rowstyle;
7034: }
7035: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
7036: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7037: $infotitles,$rowid,$customclass,$datarowstyle);
7038: unless ($datarowstyle eq 'display:none') {
7039: $$rowtotal ++;
7040: }
1.224 raeburn 7041: }
1.305 raeburn 7042: } else {
7043: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
7044: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7045: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 7046: }
7047: }
7048: return $datatable;
7049: }
7050:
1.305 raeburn 7051: sub selfcreate_javascript {
7052: return <<"ENDSCRIPT";
7053:
7054: <script type="text/javascript">
7055: // <![CDATA[
7056:
7057: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
7058: var x = document.getElementsByClassName(target);
7059: var insttypes = 0;
7060: var insttypeRegExp = new RegExp(prefix);
7061: if ((x.length != undefined) && (x.length > 0)) {
7062: if (form.elements[radio].length != undefined) {
7063: for (var i=0; i<form.elements[radio].length; i++) {
7064: if (form.elements[radio][i].checked) {
7065: if (form.elements[radio][i].value == 1) {
7066: for (var j=0; j<x.length; j++) {
7067: if (x[j].id == 'undefined') {
7068: x[j].style.display = 'table-row';
7069: } else if (insttypeRegExp.test(x[j].id)) {
7070: insttypes ++;
7071: } else {
7072: x[j].style.display = 'table-row';
7073: }
7074: }
7075: } else {
7076: for (var j=0; j<x.length; j++) {
7077: x[j].style.display = 'none';
7078: }
1.236 raeburn 7079: }
1.305 raeburn 7080: break;
7081: }
7082: }
7083: if (insttypes > 0) {
7084: toggleDataRow(form,checkbox,target,altprefix);
7085: toggleDataRow(form,checkbox,target,prefix,1);
7086: }
7087: }
7088: }
7089: return;
7090: }
7091:
7092: function toggleDataRow(form,checkbox,target,prefix,docount) {
7093: if (form.elements[checkbox].length != undefined) {
7094: var count = 0;
7095: if (docount) {
7096: for (var i=0; i<form.elements[checkbox].length; i++) {
7097: if (form.elements[checkbox][i].checked) {
7098: count ++;
1.236 raeburn 7099: }
1.305 raeburn 7100: }
7101: }
7102: for (var i=0; i<form.elements[checkbox].length; i++) {
7103: var type = form.elements[checkbox][i].value;
7104: if (document.getElementById(prefix+type)) {
7105: if (form.elements[checkbox][i].checked) {
7106: document.getElementById(prefix+type).style.display = 'table-row';
7107: if (count % 2 == 1) {
7108: document.getElementById(prefix+type).className = target+' LC_odd_row';
7109: } else {
7110: document.getElementById(prefix+type).className = target;
1.236 raeburn 7111: }
1.305 raeburn 7112: count ++;
1.236 raeburn 7113: } else {
1.305 raeburn 7114: document.getElementById(prefix+type).style.display = 'none';
7115: }
7116: }
7117: }
7118: }
7119: return;
7120: }
7121:
7122: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
7123: var caller = radio+'_'+status;
7124: if (form.elements[caller].length != undefined) {
7125: for (var i=0; i<form.elements[caller].length; i++) {
7126: if (form.elements[caller][i].checked) {
7127: if (document.getElementById(altprefix+'_inst_'+status)) {
7128: var curr = form.elements[caller][i].value;
7129: if (prefix) {
7130: document.getElementById(prefix+'_'+status).style.display = 'none';
7131: }
7132: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
7133: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
7134: if (curr == 'custom') {
7135: if (prefix) {
7136: document.getElementById(prefix+'_'+status).style.display = 'inline';
7137: }
7138: } else if (curr == 'inst') {
7139: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
7140: } else if (curr == 'noninst') {
7141: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 7142: }
1.305 raeburn 7143: break;
1.236 raeburn 7144: }
7145: }
7146: }
7147: }
7148: }
7149:
1.305 raeburn 7150: // ]]>
7151: </script>
7152:
7153: ENDSCRIPT
7154: }
7155:
7156: sub noninst_users {
7157: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
7158: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
7159: my $class = 'LC_left_item';
7160: if ($css_class) {
7161: $css_class = ' class="'.$css_class.'"';
7162: }
7163: if ($rowid) {
7164: $rowid = ' id="'.$rowid.'"';
7165: }
7166: if ($rowstyle) {
7167: $rowstyle = ' style="'.$rowstyle.'"';
7168: }
7169: my ($output,$description);
7170: if ($type eq 'default') {
7171: $description = &mt('Requests for: [_1]',$typetitle);
7172: } else {
7173: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
7174: }
7175: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
7176: "<td>$description</td>\n".
7177: '<td class="'.$class.'" colspan="2">'.
7178: '<table><tr>';
7179: my %headers = &Apache::lonlocal::texthash(
7180: approve => 'Processing',
7181: email => 'E-mail',
7182: username => 'Username',
7183: );
7184: foreach my $item ('approve','email','username') {
7185: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 7186: }
1.305 raeburn 7187: $output .= '</tr><tr>';
7188: foreach my $item ('approve','email','username') {
1.306 raeburn 7189: $output .= '<td style="vertical-align: top">';
1.305 raeburn 7190: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
7191: if ($item eq 'approve') {
7192: %choices = &Apache::lonlocal::texthash (
7193: automatic => 'Automatically approved',
7194: approval => 'Queued for approval',
7195: );
7196: @options = ('automatic','approval');
7197: $hashref = $processing;
7198: $defoption = 'automatic';
7199: $name = 'cancreate_emailprocess_'.$type;
7200: } elsif ($item eq 'email') {
7201: %choices = &Apache::lonlocal::texthash (
7202: any => 'Any e-mail',
7203: inst => 'Institutional only',
7204: noninst => 'Non-institutional only',
7205: custom => 'Custom restrictions',
7206: );
7207: @options = ('any','inst','noninst');
7208: my $showcustom;
7209: if (ref($emailrules) eq 'HASH') {
7210: if (keys(%{$emailrules}) > 0) {
7211: push(@options,'custom');
7212: $showcustom = 'cancreate_emailrule';
7213: if (ref($settings) eq 'HASH') {
7214: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
7215: foreach my $rule (@{$settings->{'email_rule'}}) {
7216: if (exists($emailrules->{$rule})) {
7217: $hascustom ++;
7218: }
7219: }
7220: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
7221: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
7222: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
7223: if (exists($emailrules->{$rule})) {
7224: $hascustom ++;
7225: }
7226: }
7227: }
7228: }
7229: }
7230: }
7231: }
7232: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
7233: "'cancreate_emaildomain','$type'".');"';
7234: $hashref = $emailoptions;
7235: $defoption = 'any';
7236: $name = 'cancreate_emailoptions_'.$type;
7237: } elsif ($item eq 'username') {
7238: %choices = &Apache::lonlocal::texthash (
7239: all => 'Same as e-mail',
7240: first => 'Omit @domain',
7241: free => 'Free to choose',
7242: );
7243: @options = ('all','first','free');
7244: $hashref = $emailverified;
7245: $defoption = 'all';
7246: $name = 'cancreate_usernameoptions_'.$type;
7247: }
7248: foreach my $option (@options) {
7249: my $checked;
7250: if (ref($hashref) eq 'HASH') {
7251: if ($type eq '') {
7252: if (!exists($hashref->{'default'})) {
7253: if ($option eq $defoption) {
7254: $checked = ' checked="checked"';
7255: }
7256: } else {
7257: if ($hashref->{'default'} eq $option) {
7258: $checked = ' checked="checked"';
7259: }
1.303 raeburn 7260: }
7261: } else {
1.305 raeburn 7262: if (!exists($hashref->{$type})) {
7263: if ($option eq $defoption) {
7264: $checked = ' checked="checked"';
7265: }
7266: } else {
7267: if ($hashref->{$type} eq $option) {
7268: $checked = ' checked="checked"';
7269: }
1.303 raeburn 7270: }
7271: }
1.305 raeburn 7272: } elsif (($item eq 'email') && ($hascustom)) {
7273: if ($option eq 'custom') {
7274: $checked = ' checked="checked"';
7275: }
7276: } elsif ($option eq $defoption) {
7277: $checked = ' checked="checked"';
7278: }
7279: $output .= '<span class="LC_nobreak"><label>'.
7280: '<input type="radio" name="'.$name.'"'.
7281: $checked.' value="'.$option.'"'.$onclick.' />'.
7282: $choices{$option}.'</label></span><br />';
7283: if ($item eq 'email') {
7284: if ($option eq 'custom') {
7285: my $id = 'cancreate_emailrule_'.$type;
7286: my $display = 'none';
7287: if ($checked) {
7288: $display = 'inline';
1.303 raeburn 7289: }
1.305 raeburn 7290: my $numinrow = 2;
7291: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
7292: '<legend>'.&mt('Disallow').'</legend><table>'.
7293: &user_formats_row('email',$settings,$emailrules,
7294: $emailruleorder,$numinrow,'',$type);
7295: '</table></fieldset>';
7296: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
7297: my %text = &Apache::lonlocal::texthash (
7298: inst => 'must end:',
7299: noninst => 'cannot end:',
7300: );
7301: my $value;
7302: if (ref($emaildomain) eq 'HASH') {
7303: if (ref($emaildomain->{$type}) eq 'HASH') {
7304: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 7305: }
7306: }
1.305 raeburn 7307: if ($value eq '') {
7308: $value = '@'.$intdom;
7309: }
7310: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
7311: my $display = 'none';
7312: if ($checked) {
7313: $display = 'inline';
7314: }
7315: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
7316: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
7317: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
7318: '</div>';
1.303 raeburn 7319: }
7320: }
7321: }
1.305 raeburn 7322: $output .= '</td>'."\n";
1.303 raeburn 7323: }
1.305 raeburn 7324: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 7325: return $output;
7326: }
7327:
1.165 raeburn 7328: sub captcha_choice {
1.305 raeburn 7329: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 7330: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
7331: $vertext,$currver);
1.165 raeburn 7332: my %lt = &captcha_phrases();
7333: $keyentry = 'hidden';
7334: if ($context eq 'cancreate') {
1.224 raeburn 7335: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 7336: } elsif ($context eq 'login') {
7337: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 7338: }
7339: if (ref($settings) eq 'HASH') {
7340: if ($settings->{'captcha'}) {
7341: $checked{$settings->{'captcha'}} = ' checked="checked"';
7342: } else {
7343: $checked{'original'} = ' checked="checked"';
7344: }
7345: if ($settings->{'captcha'} eq 'recaptcha') {
7346: $pubtext = $lt{'pub'};
7347: $privtext = $lt{'priv'};
7348: $keyentry = 'text';
1.269 raeburn 7349: $vertext = $lt{'ver'};
7350: $currver = $settings->{'recaptchaversion'};
7351: if ($currver ne '2') {
7352: $currver = 1;
7353: }
1.165 raeburn 7354: }
7355: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
7356: $currpub = $settings->{'recaptchakeys'}{'public'};
7357: $currpriv = $settings->{'recaptchakeys'}{'private'};
7358: }
7359: } else {
7360: $checked{'original'} = ' checked="checked"';
7361: }
1.305 raeburn 7362: my $css_class;
7363: if ($itemcount%2) {
7364: $css_class = 'LC_odd_row';
7365: }
7366: if ($customcss) {
7367: $css_class .= " $customcss";
7368: }
7369: $css_class =~ s/^\s+//;
7370: if ($css_class) {
7371: $css_class = ' class="'.$css_class.'"';
7372: }
7373: if ($rowstyle) {
7374: $css_class .= ' style="'.$rowstyle.'"';
7375: }
1.169 raeburn 7376: my $output = '<tr'.$css_class.'>'.
7377: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 7378: '<table><tr><td>'."\n";
7379: foreach my $option ('original','recaptcha','notused') {
7380: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
7381: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
7382: $lt{$option}.'</label></span>';
7383: unless ($option eq 'notused') {
7384: $output .= (' 'x2)."\n";
7385: }
7386: }
7387: #
7388: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
7389: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 7390: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 7391: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 7392: #
1.165 raeburn 7393: $output .= '</td></tr>'."\n".
1.305 raeburn 7394: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 7395: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
7396: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
7397: $currpub.'" size="40" /></span><br />'."\n".
7398: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
7399: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 7400: $currpriv.'" size="40" /></span><br />'.
7401: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
7402: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
7403: $currver.'" size="3" /></span><br />'.
7404: '</td></tr></table>'."\n".
1.165 raeburn 7405: '</td></tr>';
7406: return $output;
7407: }
7408:
1.32 raeburn 7409: sub user_formats_row {
1.305 raeburn 7410: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 7411: my $output;
7412: my %text = (
7413: 'username' => 'new usernames',
7414: 'id' => 'IDs',
7415: );
1.305 raeburn 7416: unless ($type eq 'email') {
7417: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
7418: $output = '<tr '.$css_class.'>'.
7419: '<td><span class="LC_nobreak">'.
7420: &mt("Format rules to check for $text{$type}: ").
7421: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 7422: }
1.27 raeburn 7423: my $rem;
7424: if (ref($ruleorder) eq 'ARRAY') {
7425: for (my $i=0; $i<@{$ruleorder}; $i++) {
7426: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
7427: my $rem = $i%($numinrow);
7428: if ($rem == 0) {
7429: if ($i > 0) {
7430: $output .= '</tr>';
7431: }
7432: $output .= '<tr>';
7433: }
7434: my $check = ' ';
1.39 raeburn 7435: if (ref($settings) eq 'HASH') {
7436: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
7437: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
7438: $check = ' checked="checked" ';
7439: }
1.305 raeburn 7440: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
7441: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
7442: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
7443: $check = ' checked="checked" ';
7444: }
7445: }
1.27 raeburn 7446: }
7447: }
1.305 raeburn 7448: my $name = $type.'_rule';
7449: if ($type eq 'email') {
7450: $name .= '_'.$status;
7451: }
1.27 raeburn 7452: $output .= '<td class="LC_left_item">'.
7453: '<span class="LC_nobreak"><label>'.
1.311 raeburn 7454: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 7455: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
7456: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
7457: }
7458: }
7459: $rem = @{$ruleorder}%($numinrow);
7460: }
1.305 raeburn 7461: my $colsleft;
7462: if ($rem) {
7463: $colsleft = $numinrow - $rem;
7464: }
1.27 raeburn 7465: if ($colsleft > 1 ) {
7466: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7467: ' </td>';
7468: } elsif ($colsleft == 1) {
7469: $output .= '<td class="LC_left_item"> </td>';
7470: }
1.305 raeburn 7471: $output .= '</tr></table>';
7472: unless ($type eq 'email') {
7473: $output .= '</td></tr>';
7474: }
1.27 raeburn 7475: return $output;
7476: }
7477:
1.34 raeburn 7478: sub usercreation_types {
7479: my %lt = &Apache::lonlocal::texthash (
7480: author => 'When adding a co-author',
7481: course => 'When adding a user to a course',
1.100 raeburn 7482: requestcrs => 'When requesting a course',
1.34 raeburn 7483: any => 'Any',
7484: official => 'Institutional only ',
7485: unofficial => 'Non-institutional only',
7486: none => 'None',
7487: );
7488: return %lt;
1.48 raeburn 7489: }
1.34 raeburn 7490:
1.224 raeburn 7491: sub selfcreation_types {
7492: my %lt = &Apache::lonlocal::texthash (
7493: selfcreate => 'User creates own account',
7494: any => 'Any',
7495: official => 'Institutional only ',
7496: unofficial => 'Non-institutional only',
7497: email => 'E-mail address',
7498: login => 'Institutional Login',
7499: sso => 'SSO',
7500: );
7501: }
7502:
1.28 raeburn 7503: sub authtype_names {
7504: my %lt = &Apache::lonlocal::texthash(
7505: int => 'Internal',
7506: krb4 => 'Kerberos 4',
7507: krb5 => 'Kerberos 5',
7508: loc => 'Local',
1.325 raeburn 7509: lti => 'LTI',
1.28 raeburn 7510: );
7511: return %lt;
7512: }
7513:
7514: sub context_names {
7515: my %context_title = &Apache::lonlocal::texthash(
7516: author => 'Creating users when an Author',
7517: course => 'Creating users when in a course',
7518: domain => 'Creating users when a Domain Coordinator',
7519: );
7520: return %context_title;
7521: }
7522:
1.33 raeburn 7523: sub print_usermodification {
7524: my ($position,$dom,$settings,$rowtotal) = @_;
7525: my $numinrow = 4;
7526: my ($context,$datatable,$rowcount);
7527: if ($position eq 'top') {
7528: $rowcount = 0;
7529: $context = 'author';
7530: foreach my $role ('ca','aa') {
7531: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7532: $numinrow,$rowcount);
7533: $$rowtotal ++;
7534: $rowcount ++;
7535: }
1.230 raeburn 7536: } elsif ($position eq 'bottom') {
1.33 raeburn 7537: $context = 'course';
7538: $rowcount = 0;
7539: foreach my $role ('st','ep','ta','in','cr') {
7540: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7541: $numinrow,$rowcount);
7542: $$rowtotal ++;
7543: $rowcount ++;
7544: }
7545: }
7546: return $datatable;
7547: }
7548:
1.43 raeburn 7549: sub print_defaults {
1.236 raeburn 7550: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 7551: my $rownum = 0;
1.294 raeburn 7552: my ($datatable,$css_class,$titles);
7553: unless ($position eq 'bottom') {
7554: $titles = &defaults_titles($dom);
7555: }
1.236 raeburn 7556: if ($position eq 'top') {
7557: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
7558: 'datelocale_def','portal_def');
7559: my %defaults;
7560: if (ref($settings) eq 'HASH') {
7561: %defaults = %{$settings};
1.43 raeburn 7562: } else {
1.236 raeburn 7563: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
7564: foreach my $item (@items) {
7565: $defaults{$item} = $domdefaults{$item};
7566: }
1.43 raeburn 7567: }
1.236 raeburn 7568: foreach my $item (@items) {
7569: if ($rownum%2) {
7570: $css_class = '';
7571: } else {
7572: $css_class = ' class="LC_odd_row" ';
7573: }
7574: $datatable .= '<tr'.$css_class.'>'.
7575: '<td><span class="LC_nobreak">'.$titles->{$item}.
7576: '</span></td><td class="LC_right_item" colspan="3">';
7577: if ($item eq 'auth_def') {
1.325 raeburn 7578: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 7579: my %shortauth = (
7580: internal => 'int',
7581: krb4 => 'krb4',
7582: krb5 => 'krb5',
1.325 raeburn 7583: localauth => 'loc',
7584: lti => 'lti',
1.236 raeburn 7585: );
7586: my %authnames = &authtype_names();
7587: foreach my $auth (@authtypes) {
7588: my $checked = ' ';
7589: if ($defaults{$item} eq $auth) {
7590: $checked = ' checked="checked" ';
7591: }
7592: $datatable .= '<label><input type="radio" name="'.$item.
7593: '" value="'.$auth.'"'.$checked.'/>'.
7594: $authnames{$shortauth{$auth}}.'</label> ';
7595: }
7596: } elsif ($item eq 'timezone_def') {
7597: my $includeempty = 1;
7598: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
7599: } elsif ($item eq 'datelocale_def') {
7600: my $includeempty = 1;
7601: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
7602: } elsif ($item eq 'lang_def') {
1.263 raeburn 7603: my $includeempty = 1;
7604: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 7605: } else {
7606: my $size;
7607: if ($item eq 'portal_def') {
7608: $size = ' size="25"';
7609: }
7610: $datatable .= '<input type="text" name="'.$item.'" value="'.
7611: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 7612: }
1.236 raeburn 7613: $datatable .= '</td></tr>';
7614: $rownum ++;
7615: }
1.294 raeburn 7616: } elsif ($position eq 'middle') {
7617: my @items = ('intauth_cost','intauth_check','intauth_switch');
7618: my %defaults;
7619: if (ref($settings) eq 'HASH') {
7620: %defaults = %{$settings};
7621: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
7622: $defaults{'intauth_cost'} = 10;
7623: }
7624: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
7625: $defaults{'intauth_check'} = 0;
7626: }
7627: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
7628: $defaults{'intauth_switch'} = 0;
7629: }
7630: } else {
7631: %defaults = (
7632: 'intauth_cost' => 10,
7633: 'intauth_check' => 0,
7634: 'intauth_switch' => 0,
7635: );
7636: }
7637: foreach my $item (@items) {
7638: if ($rownum%2) {
7639: $css_class = '';
7640: } else {
7641: $css_class = ' class="LC_odd_row" ';
7642: }
7643: $datatable .= '<tr'.$css_class.'>'.
7644: '<td><span class="LC_nobreak">'.$titles->{$item}.
7645: '</span></td><td class="LC_left_item" colspan="3">';
7646: if ($item eq 'intauth_switch') {
7647: my @options = (0,1,2);
7648: my %optiondesc = &Apache::lonlocal::texthash (
7649: 0 => 'No',
7650: 1 => 'Yes',
7651: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
7652: );
7653: $datatable .= '<table width="100%">';
7654: foreach my $option (@options) {
7655: my $checked = ' ';
7656: if ($defaults{$item} eq $option) {
7657: $checked = ' checked="checked"';
7658: }
7659: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7660: '<label><input type="radio" name="'.$item.
7661: '" value="'.$option.'"'.$checked.' />'.
7662: $optiondesc{$option}.'</label></span></td></tr>';
7663: }
7664: $datatable .= '</table>';
7665: } elsif ($item eq 'intauth_check') {
7666: my @options = (0,1,2);
7667: my %optiondesc = &Apache::lonlocal::texthash (
7668: 0 => 'No',
7669: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
7670: 2 => 'Yes, disallow login if stored cost is less than domain default',
7671: );
1.332 raeburn 7672: $datatable .= '<table width="100%">';
1.294 raeburn 7673: foreach my $option (@options) {
7674: my $checked = ' ';
7675: my $onclick;
7676: if ($defaults{$item} eq $option) {
7677: $checked = ' checked="checked"';
7678: }
7679: if ($option == 2) {
7680: $onclick = ' onclick="javascript:warnIntAuth(this);"';
7681: }
7682: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7683: '<label><input type="radio" name="'.$item.
7684: '" value="'.$option.'"'.$checked.$onclick.' />'.
7685: $optiondesc{$option}.'</label></span></td></tr>';
7686: }
7687: $datatable .= '</table>';
7688: } else {
7689: $datatable .= '<input type="text" name="'.$item.'" value="'.
7690: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
7691: }
7692: $datatable .= '</td></tr>';
7693: $rownum ++;
7694: }
1.236 raeburn 7695: } else {
1.294 raeburn 7696: my %defaults;
1.236 raeburn 7697: if (ref($settings) eq 'HASH') {
1.305 raeburn 7698: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.236 raeburn 7699: my $maxnum = @{$settings->{'inststatusorder'}};
7700: for (my $i=0; $i<$maxnum; $i++) {
7701: $css_class = $rownum%2?' class="LC_odd_row"':'';
7702: my $item = $settings->{'inststatusorder'}->[$i];
7703: my $title = $settings->{'inststatustypes'}->{$item};
7704: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
7705: $datatable .= '<tr'.$css_class.'>'.
7706: '<td><span class="LC_nobreak">'.
7707: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
7708: for (my $k=0; $k<=$maxnum; $k++) {
7709: my $vpos = $k+1;
7710: my $selstr;
7711: if ($k == $i) {
7712: $selstr = ' selected="selected" ';
7713: }
7714: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7715: }
7716: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
7717: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
7718: &mt('delete').'</span></td>'.
1.305 raeburn 7719: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed:').
1.236 raeburn 7720: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.305 raeburn 7721: '</span></td></tr>';
1.236 raeburn 7722: }
7723: $css_class = $rownum%2?' class="LC_odd_row"':'';
7724: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
7725: $datatable .= '<tr '.$css_class.'>'.
7726: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
7727: for (my $k=0; $k<=$maxnum; $k++) {
7728: my $vpos = $k+1;
7729: my $selstr;
7730: if ($k == $maxnum) {
7731: $selstr = ' selected="selected" ';
7732: }
7733: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7734: }
7735: $datatable .= '</select> '.&mt('Internal ID:').
1.263 raeburn 7736: '<input type="text" size="10" name="addinststatus" value="" />'.
1.236 raeburn 7737: ' '.&mt('(new)').
1.305 raeburn 7738: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.236 raeburn 7739: &mt('Name displayed:').
7740: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
7741: '</tr>'."\n";
7742: $rownum ++;
1.141 raeburn 7743: }
1.43 raeburn 7744: }
7745: }
7746: $$rowtotal += $rownum;
7747: return $datatable;
7748: }
7749:
1.168 raeburn 7750: sub get_languages_hash {
7751: my %langchoices;
7752: foreach my $id (&Apache::loncommon::languageids()) {
7753: my $code = &Apache::loncommon::supportedlanguagecode($id);
7754: if ($code ne '') {
7755: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
7756: }
7757: }
7758: return %langchoices;
7759: }
7760:
1.43 raeburn 7761: sub defaults_titles {
1.141 raeburn 7762: my ($dom) = @_;
1.43 raeburn 7763: my %titles = &Apache::lonlocal::texthash (
7764: 'auth_def' => 'Default authentication type',
7765: 'auth_arg_def' => 'Default authentication argument',
7766: 'lang_def' => 'Default language',
1.54 raeburn 7767: 'timezone_def' => 'Default timezone',
1.68 raeburn 7768: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 7769: 'portal_def' => 'Portal/Default URL',
1.294 raeburn 7770: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
7771: 'intauth_check' => 'Check bcrypt cost if authenticated',
7772: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 7773: );
1.141 raeburn 7774: if ($dom) {
7775: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
7776: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
7777: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
7778: $protocol = 'http' if ($protocol ne 'https');
7779: if ($uint_dom) {
7780: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
7781: $uint_dom);
7782: }
7783: }
1.43 raeburn 7784: return (\%titles);
7785: }
7786:
1.46 raeburn 7787: sub print_scantronformat {
7788: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
7789: my $itemcount = 1;
1.60 raeburn 7790: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
7791: %confhash);
1.46 raeburn 7792: my $switchserver = &check_switchserver($dom,$confname);
7793: my %lt = &Apache::lonlocal::texthash (
1.95 www 7794: default => 'Default bubblesheet format file error',
7795: custom => 'Custom bubblesheet format file error',
1.46 raeburn 7796: );
7797: my %scantronfiles = (
7798: default => 'default.tab',
7799: custom => 'custom.tab',
7800: );
7801: foreach my $key (keys(%scantronfiles)) {
7802: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
7803: .$scantronfiles{$key};
7804: }
7805: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
7806: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
7807: if (!$switchserver) {
7808: my $servadm = $r->dir_config('lonAdmEMail');
7809: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
7810: if ($configuserok eq 'ok') {
7811: if ($author_ok eq 'ok') {
7812: my %legacyfile = (
7813: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
7814: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
7815: );
7816: my %md5chk;
7817: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 7818: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
7819: chomp($md5chk{$type});
1.46 raeburn 7820: }
7821: if ($md5chk{'default'} ne $md5chk{'custom'}) {
7822: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 7823: ($scantronurls{$type},my $error) =
1.46 raeburn 7824: &legacy_scantronformat($r,$dom,$confname,
7825: $type,$legacyfile{$type},
7826: $scantronurls{$type},
7827: $scantronfiles{$type});
1.60 raeburn 7828: if ($error ne '') {
7829: $error{$type} = $error;
7830: }
7831: }
7832: if (keys(%error) == 0) {
7833: $is_custom = 1;
7834: $confhash{'scantron'}{'scantronformat'} =
7835: $scantronurls{'custom'};
7836: my $putresult =
7837: &Apache::lonnet::put_dom('configuration',
7838: \%confhash,$dom);
7839: if ($putresult ne 'ok') {
7840: $error{'custom'} =
7841: '<span class="LC_error">'.
7842: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7843: }
1.46 raeburn 7844: }
7845: } else {
1.60 raeburn 7846: ($scantronurls{'default'},my $error) =
1.46 raeburn 7847: &legacy_scantronformat($r,$dom,$confname,
7848: 'default',$legacyfile{'default'},
7849: $scantronurls{'default'},
7850: $scantronfiles{'default'});
1.60 raeburn 7851: if ($error eq '') {
7852: $confhash{'scantron'}{'scantronformat'} = '';
7853: my $putresult =
7854: &Apache::lonnet::put_dom('configuration',
7855: \%confhash,$dom);
7856: if ($putresult ne 'ok') {
7857: $error{'default'} =
7858: '<span class="LC_error">'.
7859: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7860: }
7861: } else {
7862: $error{'default'} = $error;
7863: }
1.46 raeburn 7864: }
7865: }
7866: }
7867: } else {
1.95 www 7868: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 7869: }
7870: }
7871: if (ref($settings) eq 'HASH') {
7872: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
7873: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
7874: if ((!@info) || ($info[0] eq 'no_such_dir')) {
7875: $scantronurl = '';
7876: } else {
7877: $scantronurl = $settings->{'scantronformat'};
7878: }
7879: $is_custom = 1;
7880: } else {
7881: $scantronurl = $scantronurls{'default'};
7882: }
7883: } else {
1.60 raeburn 7884: if ($is_custom) {
7885: $scantronurl = $scantronurls{'custom'};
7886: } else {
7887: $scantronurl = $scantronurls{'default'};
7888: }
1.46 raeburn 7889: }
7890: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7891: $datatable .= '<tr'.$css_class.'>';
7892: if (!$is_custom) {
1.65 raeburn 7893: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
7894: '<span class="LC_nobreak">';
1.46 raeburn 7895: if ($scantronurl) {
1.199 raeburn 7896: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
7897: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 7898: } else {
7899: $datatable = &mt('File unavailable for display');
7900: }
1.65 raeburn 7901: $datatable .= '</span></td>';
1.60 raeburn 7902: if (keys(%error) == 0) {
1.306 raeburn 7903: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 7904: if (!$switchserver) {
7905: $datatable .= &mt('Upload:').'<br />';
7906: }
7907: } else {
7908: my $errorstr;
7909: foreach my $key (sort(keys(%error))) {
7910: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7911: }
7912: $datatable .= '<td>'.$errorstr;
7913: }
1.46 raeburn 7914: } else {
7915: if (keys(%error) > 0) {
7916: my $errorstr;
7917: foreach my $key (sort(keys(%error))) {
7918: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7919: }
1.60 raeburn 7920: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 7921: } elsif ($scantronurl) {
1.199 raeburn 7922: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
7923: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 7924: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 7925: $link.
7926: '<label><input type="checkbox" name="scantronformat_del"'.
7927: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 7928: '<td><span class="LC_nobreak"> '.
7929: &mt('Replace:').'</span><br />';
1.46 raeburn 7930: }
7931: }
7932: if (keys(%error) == 0) {
7933: if ($switchserver) {
7934: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
7935: } else {
1.65 raeburn 7936: $datatable .='<span class="LC_nobreak"> '.
7937: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 7938: }
7939: }
7940: $datatable .= '</td></tr>';
7941: $$rowtotal ++;
7942: return $datatable;
7943: }
7944:
7945: sub legacy_scantronformat {
7946: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
7947: my ($url,$error);
7948: my @statinfo = &Apache::lonnet::stat_file($newurl);
7949: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
7950: (my $result,$url) =
7951: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
7952: '','',$newfile);
7953: if ($result ne 'ok') {
1.130 raeburn 7954: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 7955: }
7956: }
7957: return ($url,$error);
7958: }
1.43 raeburn 7959:
1.49 raeburn 7960: sub print_coursecategories {
1.57 raeburn 7961: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
7962: my $datatable;
7963: if ($position eq 'top') {
1.238 raeburn 7964: my (%checked);
7965: my @catitems = ('unauth','auth');
7966: my @cattypes = ('std','domonly','codesrch','none');
7967: $checked{'unauth'} = 'std';
7968: $checked{'auth'} = 'std';
7969: if (ref($settings) eq 'HASH') {
7970: foreach my $type (@cattypes) {
7971: if ($type eq $settings->{'unauth'}) {
7972: $checked{'unauth'} = $type;
7973: }
7974: if ($type eq $settings->{'auth'}) {
7975: $checked{'auth'} = $type;
7976: }
7977: }
7978: }
7979: my %lt = &Apache::lonlocal::texthash (
7980: unauth => 'Catalog type for unauthenticated users',
7981: auth => 'Catalog type for authenticated users',
7982: none => 'No catalog',
7983: std => 'Standard catalog',
7984: domonly => 'Domain-only catalog',
7985: codesrch => "Code search form",
7986: );
7987: my $itemcount = 0;
7988: foreach my $item (@catitems) {
7989: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
7990: $datatable .= '<tr '.$css_class.'>'.
7991: '<td>'.$lt{$item}.'</td>'.
7992: '<td class="LC_right_item"><span class="LC_nobreak">';
7993: foreach my $type (@cattypes) {
7994: my $ischecked;
7995: if ($checked{$item} eq $type) {
7996: $ischecked=' checked="checked"';
7997: }
7998: $datatable .= '<label>'.
7999: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
8000: ' />'.$lt{$type}.'</label> ';
8001: }
1.327 raeburn 8002: $datatable .= '</span></td></tr>';
1.238 raeburn 8003: $itemcount ++;
8004: }
8005: $$rowtotal += $itemcount;
8006: } elsif ($position eq 'middle') {
1.57 raeburn 8007: my $toggle_cats_crs = ' ';
8008: my $toggle_cats_dom = ' checked="checked" ';
8009: my $can_cat_crs = ' ';
8010: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 8011: my $toggle_catscomm_comm = ' ';
8012: my $toggle_catscomm_dom = ' checked="checked" ';
8013: my $can_catcomm_comm = ' ';
8014: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 8015: my $toggle_catsplace_place = ' ';
8016: my $toggle_catsplace_dom = ' checked="checked" ';
8017: my $can_catplace_place = ' ';
8018: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 8019:
1.57 raeburn 8020: if (ref($settings) eq 'HASH') {
8021: if ($settings->{'togglecats'} eq 'crs') {
8022: $toggle_cats_crs = $toggle_cats_dom;
8023: $toggle_cats_dom = ' ';
8024: }
8025: if ($settings->{'categorize'} eq 'crs') {
8026: $can_cat_crs = $can_cat_dom;
8027: $can_cat_dom = ' ';
8028: }
1.120 raeburn 8029: if ($settings->{'togglecatscomm'} eq 'comm') {
8030: $toggle_catscomm_comm = $toggle_catscomm_dom;
8031: $toggle_catscomm_dom = ' ';
8032: }
8033: if ($settings->{'categorizecomm'} eq 'comm') {
8034: $can_catcomm_comm = $can_catcomm_dom;
8035: $can_catcomm_dom = ' ';
8036: }
1.272 raeburn 8037: if ($settings->{'togglecatsplace'} eq 'place') {
8038: $toggle_catsplace_place = $toggle_catsplace_dom;
8039: $toggle_catsplace_dom = ' ';
8040: }
8041: if ($settings->{'categorizeplace'} eq 'place') {
8042: $can_catplace_place = $can_catplace_dom;
8043: $can_catplace_dom = ' ';
8044: }
1.57 raeburn 8045: }
8046: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 8047: togglecats => 'Show/Hide a course in catalog',
8048: togglecatscomm => 'Show/Hide a community in catalog',
8049: togglecatsplace => 'Show/Hide a placement test in catalog',
8050: categorize => 'Assign a category to a course',
8051: categorizecomm => 'Assign a category to a community',
8052: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 8053: );
8054: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 8055: dom => 'Set in Domain',
8056: crs => 'Set in Course',
8057: comm => 'Set in Community',
8058: place => 'Set in Placement Test',
1.57 raeburn 8059: );
8060: $datatable = '<tr class="LC_odd_row">'.
8061: '<td>'.$title{'togglecats'}.'</td>'.
8062: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8063: '<input type="radio" name="togglecats"'.
8064: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8065: '<label><input type="radio" name="togglecats"'.
8066: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
8067: '</tr><tr>'.
8068: '<td>'.$title{'categorize'}.'</td>'.
8069: '<td class="LC_right_item"><span class="LC_nobreak">'.
8070: '<label><input type="radio" name="categorize"'.
8071: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8072: '<label><input type="radio" name="categorize"'.
8073: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 8074: '</tr><tr class="LC_odd_row">'.
8075: '<td>'.$title{'togglecatscomm'}.'</td>'.
8076: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8077: '<input type="radio" name="togglecatscomm"'.
8078: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8079: '<label><input type="radio" name="togglecatscomm"'.
8080: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
8081: '</tr><tr>'.
8082: '<td>'.$title{'categorizecomm'}.'</td>'.
8083: '<td class="LC_right_item"><span class="LC_nobreak">'.
8084: '<label><input type="radio" name="categorizecomm"'.
8085: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8086: '<label><input type="radio" name="categorizecomm"'.
8087: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 8088: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 8089: '<td>'.$title{'togglecatsplace'}.'</td>'.
8090: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8091: '<input type="radio" name="togglecatsplace"'.
8092: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8093: '<label><input type="radio" name="togglecatscomm"'.
8094: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
8095: '</tr><tr>'.
8096: '<td>'.$title{'categorizeplace'}.'</td>'.
8097: '<td class="LC_right_item"><span class="LC_nobreak">'.
8098: '<label><input type="radio" name="categorizeplace"'.
8099: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8100: '<label><input type="radio" name="categorizeplace"'.
8101: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 8102: '</tr>';
1.272 raeburn 8103: $$rowtotal += 6;
1.57 raeburn 8104: } else {
8105: my $css_class;
8106: my $itemcount = 1;
8107: my $cathash;
8108: if (ref($settings) eq 'HASH') {
8109: $cathash = $settings->{'cats'};
8110: }
8111: if (ref($cathash) eq 'HASH') {
8112: my (@cats,@trails,%allitems,%idx,@jsarray);
8113: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
8114: \%allitems,\%idx,\@jsarray);
8115: my $maxdepth = scalar(@cats);
8116: my $colattrib = '';
8117: if ($maxdepth > 2) {
8118: $colattrib = ' colspan="2" ';
8119: }
8120: my @path;
8121: if (@cats > 0) {
8122: if (ref($cats[0]) eq 'ARRAY') {
8123: my $numtop = @{$cats[0]};
8124: my $maxnum = $numtop;
1.120 raeburn 8125: my %default_names = (
8126: instcode => &mt('Official courses'),
8127: communities => &mt('Communities'),
1.272 raeburn 8128: placement => &mt('Placement Tests'),
1.120 raeburn 8129: );
8130:
8131: if ((!grep(/^instcode$/,@{$cats[0]})) ||
8132: ($cathash->{'instcode::0'} eq '') ||
8133: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 8134: ($cathash->{'communities::0'} eq '') ||
8135: (!grep(/^placement$/,@{$cats[0]})) ||
8136: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 8137: $maxnum ++;
8138: }
8139: my $lastidx;
8140: for (my $i=0; $i<$numtop; $i++) {
8141: my $parent = $cats[0][$i];
8142: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8143: my $item = &escape($parent).'::0';
8144: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
8145: $lastidx = $idx{$item};
8146: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
8147: .'<select name="'.$item.'"'.$chgstr.'>';
8148: for (my $k=0; $k<=$maxnum; $k++) {
8149: my $vpos = $k+1;
8150: my $selstr;
8151: if ($k == $i) {
8152: $selstr = ' selected="selected" ';
8153: }
8154: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8155: }
1.214 raeburn 8156: $datatable .= '</select></span></td><td>';
1.272 raeburn 8157: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 8158: $datatable .= '<span class="LC_nobreak">'
8159: .$default_names{$parent}.'</span>';
8160: if ($parent eq 'instcode') {
8161: $datatable .= '<br /><span class="LC_nobreak">('
8162: .&mt('with institutional codes')
8163: .')</span></td><td'.$colattrib.'>';
8164: } else {
8165: $datatable .= '<table><tr><td>';
8166: }
8167: $datatable .= '<span class="LC_nobreak">'
8168: .'<label><input type="radio" name="'
8169: .$parent.'" value="1" checked="checked" />'
8170: .&mt('Display').'</label>';
8171: if ($parent eq 'instcode') {
8172: $datatable .= ' ';
8173: } else {
8174: $datatable .= '</span></td></tr><tr><td>'
8175: .'<span class="LC_nobreak">';
8176: }
8177: $datatable .= '<label><input type="radio" name="'
8178: .$parent.'" value="0" />'
8179: .&mt('Do not display').'</label></span>';
1.272 raeburn 8180: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 8181: $datatable .= '</td></tr></table>';
8182: }
8183: $datatable .= '</td>';
1.57 raeburn 8184: } else {
8185: $datatable .= $parent
1.214 raeburn 8186: .' <span class="LC_nobreak"><label>'
8187: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 8188: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
8189: }
8190: my $depth = 1;
8191: push(@path,$parent);
8192: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
8193: pop(@path);
8194: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
8195: $itemcount ++;
8196: }
1.48 raeburn 8197: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 8198: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
8199: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 8200: for (my $k=0; $k<=$maxnum; $k++) {
8201: my $vpos = $k+1;
8202: my $selstr;
1.57 raeburn 8203: if ($k == $numtop) {
1.48 raeburn 8204: $selstr = ' selected="selected" ';
8205: }
8206: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8207: }
1.59 bisitz 8208: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 8209: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
8210: .'</tr>'."\n";
1.48 raeburn 8211: $itemcount ++;
1.272 raeburn 8212: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 8213: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
8214: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8215: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
8216: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
8217: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
8218: for (my $k=0; $k<=$maxnum; $k++) {
8219: my $vpos = $k+1;
8220: my $selstr;
8221: if ($k == $maxnum) {
8222: $selstr = ' selected="selected" ';
8223: }
8224: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 8225: }
1.120 raeburn 8226: $datatable .= '</select></span></td>'.
8227: '<td><span class="LC_nobreak">'.
8228: $default_names{$default}.'</span>';
8229: if ($default eq 'instcode') {
8230: $datatable .= '<br /><span class="LC_nobreak">('
8231: .&mt('with institutional codes').')</span>';
8232: }
8233: $datatable .= '</td>'
8234: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
8235: .&mt('Display').'</label> '
8236: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
8237: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 8238: }
8239: }
8240: }
1.57 raeburn 8241: } else {
8242: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 8243: }
8244: } else {
1.327 raeburn 8245: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 8246: .&initialize_categories($itemcount);
1.48 raeburn 8247: }
1.57 raeburn 8248: $$rowtotal += $itemcount;
1.48 raeburn 8249: }
8250: return $datatable;
8251: }
8252:
1.69 raeburn 8253: sub print_serverstatuses {
8254: my ($dom,$settings,$rowtotal) = @_;
8255: my $datatable;
8256: my @pages = &serverstatus_pages();
8257: my (%namedaccess,%machineaccess);
8258: foreach my $type (@pages) {
8259: $namedaccess{$type} = '';
8260: $machineaccess{$type}= '';
8261: }
8262: if (ref($settings) eq 'HASH') {
8263: foreach my $type (@pages) {
8264: if (exists($settings->{$type})) {
8265: if (ref($settings->{$type}) eq 'HASH') {
8266: foreach my $key (keys(%{$settings->{$type}})) {
8267: if ($key eq 'namedusers') {
8268: $namedaccess{$type} = $settings->{$type}->{$key};
8269: } elsif ($key eq 'machines') {
8270: $machineaccess{$type} = $settings->{$type}->{$key};
8271: }
8272: }
8273: }
8274: }
8275: }
8276: }
1.81 raeburn 8277: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 8278: my $rownum = 0;
8279: my $css_class;
8280: foreach my $type (@pages) {
8281: $rownum ++;
8282: $css_class = $rownum%2?' class="LC_odd_row"':'';
8283: $datatable .= '<tr'.$css_class.'>'.
8284: '<td><span class="LC_nobreak">'.
8285: $titles->{$type}.'</span></td>'.
8286: '<td class="LC_left_item">'.
8287: '<input type="text" name="'.$type.'_namedusers" '.
8288: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
8289: '<td class="LC_right_item">'.
8290: '<span class="LC_nobreak">'.
8291: '<input type="text" name="'.$type.'_machines" '.
8292: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 8293: '</span></td></tr>'."\n";
1.69 raeburn 8294: }
8295: $$rowtotal += $rownum;
8296: return $datatable;
8297: }
8298:
8299: sub serverstatus_pages {
8300: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 8301: 'checksums','clusterstatus','certstatus','metadata_keywords',
8302: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
8303: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 8304: }
8305:
1.236 raeburn 8306: sub defaults_javascript {
8307: my ($settings) = @_;
1.294 raeburn 8308: 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.');
8309: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
8310: &js_escape(\$intauthcheck);
8311: &js_escape(\$intauthcost);
8312: my $intauthjs = <<"ENDSCRIPT";
8313:
8314: function warnIntAuth(field) {
8315: if (field.name == 'intauth_check') {
8316: if (field.value == '2') {
8317: alert('$intauthcheck');
8318: }
8319: }
8320: if (field.name == 'intauth_cost') {
8321: field.value.replace(/\s/g,'');
8322: if (field.value != '') {
8323: var regexdigit=/^\\d+\$/;
8324: if (!regexdigit.test(field.value)) {
8325: alert('$intauthcost');
8326: }
8327: }
8328: }
8329: return;
8330: }
8331:
8332: ENDSCRIPT
8333:
8334: if (ref($settings) ne 'HASH') {
8335: return &Apache::lonhtmlcommon::scripttag($intauthjs);
8336: }
1.236 raeburn 8337: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
8338: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
8339: if ($maxnum eq '') {
8340: $maxnum = 0;
8341: }
8342: $maxnum ++;
1.249 raeburn 8343: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 8344: return <<"ENDSCRIPT";
8345: <script type="text/javascript">
8346: // <![CDATA[
8347: function reorderTypes(form,caller) {
8348: var changedVal;
8349: $jstext
8350: var newpos = 'addinststatus_pos';
8351: var current = new Array;
8352: var maxh = $maxnum;
8353: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8354: var oldVal;
8355: if (caller == newpos) {
8356: changedVal = newitemVal;
8357: } else {
8358: var curritem = 'inststatus_pos_'+caller;
8359: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
8360: current[newitemVal] = newpos;
8361: }
8362: for (var i=0; i<inststatuses.length; i++) {
8363: if (inststatuses[i] != caller) {
8364: var elementName = 'inststatus_pos_'+inststatuses[i];
8365: if (form.elements[elementName]) {
8366: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8367: current[currVal] = elementName;
8368: }
8369: }
8370: }
8371: for (var j=0; j<maxh; j++) {
8372: if (current[j] == undefined) {
8373: oldVal = j;
8374: }
8375: }
8376: if (oldVal < changedVal) {
8377: for (var k=oldVal+1; k<=changedVal ; k++) {
8378: var elementName = current[k];
8379: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8380: }
8381: } else {
8382: for (var k=changedVal; k<oldVal; k++) {
8383: var elementName = current[k];
8384: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8385: }
8386: }
8387: return;
8388: }
8389:
1.294 raeburn 8390: $intauthjs
8391:
1.236 raeburn 8392: // ]]>
8393: </script>
8394:
8395: ENDSCRIPT
1.294 raeburn 8396: } else {
8397: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 8398: }
8399: }
8400:
1.49 raeburn 8401: sub coursecategories_javascript {
8402: my ($settings) = @_;
1.57 raeburn 8403: my ($output,$jstext,$cathash);
1.49 raeburn 8404: if (ref($settings) eq 'HASH') {
1.57 raeburn 8405: $cathash = $settings->{'cats'};
8406: }
8407: if (ref($cathash) eq 'HASH') {
1.49 raeburn 8408: my (@cats,@jsarray,%idx);
1.57 raeburn 8409: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 8410: if (@jsarray > 0) {
8411: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
8412: for (my $i=0; $i<@jsarray; $i++) {
8413: if (ref($jsarray[$i]) eq 'ARRAY') {
8414: my $catstr = join('","',@{$jsarray[$i]});
8415: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
8416: }
8417: }
8418: }
8419: } else {
8420: $jstext = ' var categories = Array(1);'."\n".
8421: ' categories[0] = Array("instcode_pos");'."\n";
8422: }
1.237 bisitz 8423: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
8424: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 8425: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 8426: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
8427: &js_escape(\$instcode_reserved);
8428: &js_escape(\$communities_reserved);
1.272 raeburn 8429: &js_escape(\$placement_reserved);
1.265 damieng 8430: &js_escape(\$choose_again);
1.49 raeburn 8431: $output = <<"ENDSCRIPT";
8432: <script type="text/javascript">
1.109 raeburn 8433: // <![CDATA[
1.49 raeburn 8434: function reorderCats(form,parent,item,idx) {
8435: var changedVal;
8436: $jstext
8437: var newpos = 'addcategory_pos';
8438: if (parent == '') {
8439: var has_instcode = 0;
8440: var maxtop = categories[idx].length;
8441: for (var j=0; j<maxtop; j++) {
8442: if (categories[idx][j] == 'instcode::0') {
8443: has_instcode == 1;
8444: }
8445: }
8446: if (has_instcode == 0) {
8447: categories[idx][maxtop] = 'instcode_pos';
8448: }
8449: } else {
8450: newpos += '_'+parent;
8451: }
8452: var maxh = 1 + categories[idx].length;
8453: var current = new Array;
8454: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8455: if (item == newpos) {
8456: changedVal = newitemVal;
8457: } else {
8458: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
8459: current[newitemVal] = newpos;
8460: }
8461: for (var i=0; i<categories[idx].length; i++) {
8462: var elementName = categories[idx][i];
8463: if (elementName != item) {
8464: if (form.elements[elementName]) {
8465: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8466: current[currVal] = elementName;
8467: }
8468: }
8469: }
8470: var oldVal;
8471: for (var j=0; j<maxh; j++) {
8472: if (current[j] == undefined) {
8473: oldVal = j;
8474: }
8475: }
8476: if (oldVal < changedVal) {
8477: for (var k=oldVal+1; k<=changedVal ; k++) {
8478: var elementName = current[k];
8479: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8480: }
8481: } else {
8482: for (var k=changedVal; k<oldVal; k++) {
8483: var elementName = current[k];
8484: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8485: }
8486: }
8487: return;
8488: }
1.120 raeburn 8489:
8490: function categoryCheck(form) {
8491: if (form.elements['addcategory_name'].value == 'instcode') {
8492: alert('$instcode_reserved\\n$choose_again');
8493: return false;
8494: }
8495: if (form.elements['addcategory_name'].value == 'communities') {
8496: alert('$communities_reserved\\n$choose_again');
8497: return false;
8498: }
1.272 raeburn 8499: if (form.elements['addcategory_name'].value == 'placement') {
8500: alert('$placement_reserved\\n$choose_again');
8501: return false;
8502: }
1.120 raeburn 8503: return true;
8504: }
8505:
1.109 raeburn 8506: // ]]>
1.49 raeburn 8507: </script>
8508:
8509: ENDSCRIPT
8510: return $output;
8511: }
8512:
1.48 raeburn 8513: sub initialize_categories {
8514: my ($itemcount) = @_;
1.120 raeburn 8515: my ($datatable,$css_class,$chgstr);
8516: my %default_names = (
8517: instcode => 'Official courses (with institutional codes)',
8518: communities => 'Communities',
1.272 raeburn 8519: placement => 'Placement Tests',
1.120 raeburn 8520: );
1.328 raeburn 8521: my %selnum = (
8522: instcode => '0',
8523: communities => '1',
8524: placement => '2',
8525: );
8526: my %selected;
1.272 raeburn 8527: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 8528: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 8529: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 8530: map { $selected{$selnum{$_}} = '' } keys(%selnum);
8531: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 8532: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 8533: .'<select name="'.$default.'_pos"'.$chgstr.'>'
8534: .'<option value="0"'.$selected{'0'}.'>1</option>'
8535: .'<option value="1"'.$selected{'1'}.'>2</option>'
8536: .'<option value="2"'.$selected{'2'}.'>3</option>'
8537: .'<option value="3">4</option></select> '
1.120 raeburn 8538: .$default_names{$default}
8539: .'</span></td><td><span class="LC_nobreak">'
8540: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
8541: .&mt('Display').'</label> <label>'
8542: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 8543: .'</label></span></td></tr>';
1.120 raeburn 8544: $itemcount ++;
8545: }
1.48 raeburn 8546: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 8547: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 8548: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 8549: .'<select name="addcategory_pos"'.$chgstr.'>'
8550: .'<option value="0">1</option>'
8551: .'<option value="1">2</option>'
1.328 raeburn 8552: .'<option value="2">3</option>'
8553: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 8554: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
8555: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
8556: .'</td></tr>';
1.48 raeburn 8557: return $datatable;
8558: }
8559:
8560: sub build_category_rows {
1.49 raeburn 8561: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
8562: my ($text,$name,$item,$chgstr);
1.48 raeburn 8563: if (ref($cats) eq 'ARRAY') {
8564: my $maxdepth = scalar(@{$cats});
8565: if (ref($cats->[$depth]) eq 'HASH') {
8566: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
8567: my $numchildren = @{$cats->[$depth]{$parent}};
8568: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 8569: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 8570: my ($idxnum,$parent_name,$parent_item);
8571: my $higher = $depth - 1;
8572: if ($higher == 0) {
8573: $parent_name = &escape($parent).'::'.$higher;
8574: } else {
8575: if (ref($path) eq 'ARRAY') {
8576: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8577: }
8578: }
8579: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 8580: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 8581: if ($j < $numchildren) {
1.48 raeburn 8582: $name = $cats->[$depth]{$parent}[$j];
8583: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 8584: $idxnum = $idx->{$item};
8585: } else {
8586: $name = $parent_name;
8587: $item = $parent_item;
1.48 raeburn 8588: }
1.49 raeburn 8589: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
8590: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 8591: for (my $i=0; $i<=$numchildren; $i++) {
8592: my $vpos = $i+1;
8593: my $selstr;
8594: if ($j == $i) {
8595: $selstr = ' selected="selected" ';
8596: }
8597: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
8598: }
8599: $text .= '</select> ';
8600: if ($j < $numchildren) {
8601: my $deeper = $depth+1;
8602: $text .= $name.' '
8603: .'<label><input type="checkbox" name="deletecategory" value="'
8604: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
8605: if(ref($path) eq 'ARRAY') {
8606: push(@{$path},$name);
1.49 raeburn 8607: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 8608: pop(@{$path});
8609: }
8610: } else {
1.330 raeburn 8611: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 8612: if ($j == $numchildren) {
8613: $text .= $name;
8614: } else {
8615: $text .= $item;
8616: }
8617: $text .= '" value="" />';
8618: }
8619: $text .= '</td></tr>';
8620: }
8621: $text .= '</table></td>';
8622: } else {
8623: my $higher = $depth-1;
8624: if ($higher == 0) {
8625: $name = &escape($parent).'::'.$higher;
8626: } else {
8627: if (ref($path) eq 'ARRAY') {
8628: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8629: }
8630: }
8631: my $colspan;
8632: if ($parent ne 'instcode') {
8633: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 8634: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 8635: }
8636: }
8637: }
8638: }
8639: return $text;
8640: }
8641:
1.33 raeburn 8642: sub modifiable_userdata_row {
1.305 raeburn 8643: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
8644: $rowid,$customcss,$rowstyle) = @_;
1.228 raeburn 8645: my ($role,$rolename,$statustype);
8646: $role = $item;
1.224 raeburn 8647: if ($context eq 'cancreate') {
1.305 raeburn 8648: if ($item =~ /^(emailusername)_(.+)$/) {
8649: $role = $1;
8650: $statustype = $2;
1.228 raeburn 8651: if (ref($usertypes) eq 'HASH') {
8652: if ($usertypes->{$statustype}) {
8653: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
8654: } else {
8655: $rolename = &mt('Data provided by user');
8656: }
8657: }
1.224 raeburn 8658: }
8659: } elsif ($context eq 'selfcreate') {
1.63 raeburn 8660: if (ref($usertypes) eq 'HASH') {
8661: $rolename = $usertypes->{$role};
8662: } else {
8663: $rolename = $role;
8664: }
1.325 raeburn 8665: } elsif ($context eq 'lti') {
8666: $rolename = &mt('Institutional data used (if available)');
1.33 raeburn 8667: } else {
1.63 raeburn 8668: if ($role eq 'cr') {
8669: $rolename = &mt('Custom role');
8670: } else {
8671: $rolename = &Apache::lonnet::plaintext($role);
8672: }
1.33 raeburn 8673: }
1.224 raeburn 8674: my (@fields,%fieldtitles);
8675: if (ref($fieldsref) eq 'ARRAY') {
8676: @fields = @{$fieldsref};
8677: } else {
8678: @fields = ('lastname','firstname','middlename','generation',
8679: 'permanentemail','id');
8680: }
8681: if ((ref($titlesref) eq 'HASH')) {
8682: %fieldtitles = %{$titlesref};
8683: } else {
8684: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8685: }
1.33 raeburn 8686: my $output;
1.305 raeburn 8687: my $css_class;
8688: if ($rowcount%2) {
8689: $css_class = 'LC_odd_row';
8690: }
8691: if ($customcss) {
8692: $css_class .= " $customcss";
8693: }
8694: $css_class =~ s/^\s+//;
8695: if ($css_class) {
8696: $css_class = ' class="'.$css_class.'"';
8697: }
8698: if ($rowstyle) {
8699: $css_class .= ' style="'.$rowstyle.'"';
8700: }
8701: if ($rowid) {
8702: $rowid = ' id="'.$rowid.'"';
8703: }
8704: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 8705: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
8706: '<td class="LC_left_item" colspan="2"><table>';
8707: my $rem;
8708: my %checks;
1.325 raeburn 8709: my %current;
1.33 raeburn 8710: if (ref($settings) eq 'HASH') {
1.325 raeburn 8711: my $hashref;
8712: if ($context eq 'lti') {
8713: if (ref($settings) eq 'HASH') {
8714: $hashref = $settings->{'instdata'};
8715: }
8716: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 8717: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 8718: $hashref = $settings->{'lti_instdata'};
8719: }
8720: if ($role eq 'emailusername') {
8721: if ($statustype) {
8722: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
8723: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 8724: }
1.325 raeburn 8725: }
8726: }
8727: }
8728: if (ref($hashref) eq 'HASH') {
8729: foreach my $field (@fields) {
8730: if ($hashref->{$field}) {
8731: if ($role eq 'emailusername') {
8732: $checks{$field} = $hashref->{$field};
8733: } else {
8734: $checks{$field} = ' checked="checked" ';
1.33 raeburn 8735: }
8736: }
8737: }
8738: }
8739: }
1.305 raeburn 8740:
8741: my $total = scalar(@fields);
8742: for (my $i=0; $i<$total; $i++) {
8743: $rem = $i%($numinrow);
1.33 raeburn 8744: if ($rem == 0) {
8745: if ($i > 0) {
8746: $output .= '</tr>';
8747: }
8748: $output .= '<tr>';
8749: }
8750: my $check = ' ';
1.228 raeburn 8751: unless ($role eq 'emailusername') {
8752: if (exists($checks{$fields[$i]})) {
8753: $check = $checks{$fields[$i]}
1.325 raeburn 8754: } elsif ($context ne 'lti') {
1.228 raeburn 8755: if ($role eq 'st') {
8756: if (ref($settings) ne 'HASH') {
8757: $check = ' checked="checked" ';
8758: }
1.33 raeburn 8759: }
8760: }
8761: }
8762: $output .= '<td class="LC_left_item">'.
1.228 raeburn 8763: '<span class="LC_nobreak">';
1.325 raeburn 8764: my $prefix = 'canmodify';
1.228 raeburn 8765: if ($role eq 'emailusername') {
8766: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
8767: $checks{$fields[$i]} = 'omit';
8768: }
8769: foreach my $option ('required','optional','omit') {
8770: my $checked='';
8771: if ($checks{$fields[$i]} eq $option) {
8772: $checked='checked="checked" ';
8773: }
8774: $output .= '<label>'.
1.325 raeburn 8775: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 8776: &mt($option).'</label>'.(' ' x2);
8777: }
8778: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
8779: } else {
1.325 raeburn 8780: if ($context eq 'lti') {
8781: $prefix = 'lti';
8782: }
1.228 raeburn 8783: $output .= '<label>'.
1.325 raeburn 8784: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 8785: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
8786: '</label>';
8787: }
8788: $output .= '</span></td>';
1.33 raeburn 8789: }
1.305 raeburn 8790: $rem = $total%$numinrow;
8791: my $colsleft;
8792: if ($rem) {
8793: $colsleft = $numinrow - $rem;
8794: }
8795: if ($colsleft > 1) {
1.33 raeburn 8796: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8797: ' </td>';
8798: } elsif ($colsleft == 1) {
8799: $output .= '<td class="LC_left_item"> </td>';
8800: }
8801: $output .= '</tr></table></td></tr>';
8802: return $output;
8803: }
1.28 raeburn 8804:
1.93 raeburn 8805: sub insttypes_row {
1.305 raeburn 8806: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
8807: $customcss,$rowstyle) = @_;
1.93 raeburn 8808: my %lt = &Apache::lonlocal::texthash (
8809: cansearch => 'Users allowed to search',
8810: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 8811: lockablenames => 'User preference to lock name',
1.305 raeburn 8812: selfassign => 'Self-reportable affiliations',
1.315 raeburn 8813: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 8814: );
8815: my $showdom;
8816: if ($context eq 'cansearch') {
8817: $showdom = ' ('.$dom.')';
8818: }
1.165 raeburn 8819: my $class = 'LC_left_item';
8820: if ($context eq 'statustocreate') {
8821: $class = 'LC_right_item';
8822: }
1.305 raeburn 8823: my $css_class;
8824: if ($$rowtotal%2) {
8825: $css_class = 'LC_odd_row';
8826: }
8827: if ($customcss) {
8828: $css_class .= ' '.$customcss;
8829: }
8830: $css_class =~ s/^\s+//;
8831: if ($css_class) {
8832: $css_class = ' class="'.$css_class.'"';
8833: }
8834: if ($rowstyle) {
8835: $css_class .= ' style="'.$rowstyle.'"';
8836: }
8837: if ($onclick) {
8838: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 8839: }
8840: my $output = '<tr'.$css_class.'>'.
8841: '<td>'.$lt{$context}.$showdom.
8842: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 8843: my $rem;
8844: if (ref($types) eq 'ARRAY') {
8845: for (my $i=0; $i<@{$types}; $i++) {
8846: if (defined($usertypes->{$types->[$i]})) {
8847: my $rem = $i%($numinrow);
8848: if ($rem == 0) {
8849: if ($i > 0) {
8850: $output .= '</tr>';
8851: }
8852: $output .= '<tr>';
1.23 raeburn 8853: }
1.26 raeburn 8854: my $check = ' ';
1.99 raeburn 8855: if (ref($settings) eq 'HASH') {
8856: if (ref($settings->{$context}) eq 'ARRAY') {
8857: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
8858: $check = ' checked="checked" ';
8859: }
1.315 raeburn 8860: } elsif (ref($settings->{$context}) eq 'HASH') {
8861: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
8862: $check = ' checked="checked" ';
8863: }
1.99 raeburn 8864: } elsif ($context eq 'statustocreate') {
1.26 raeburn 8865: $check = ' checked="checked" ';
8866: }
1.23 raeburn 8867: }
1.26 raeburn 8868: $output .= '<td class="LC_left_item">'.
8869: '<span class="LC_nobreak"><label>'.
1.93 raeburn 8870: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 8871: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 8872: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 8873: }
8874: }
1.26 raeburn 8875: $rem = @{$types}%($numinrow);
1.23 raeburn 8876: }
8877: my $colsleft = $numinrow - $rem;
1.315 raeburn 8878: if ($context eq 'overrides') {
8879: if ($colsleft > 1) {
8880: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8881: } else {
8882: $output .= '<td class="LC_left_item">';
8883: }
8884: $output .= ' ';
1.23 raeburn 8885: } else {
1.334 raeburn 8886: if ($rem == 0) {
1.315 raeburn 8887: $output .= '<tr>';
8888: }
8889: if ($colsleft > 1) {
8890: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8891: } else {
8892: $output .= '<td class="LC_left_item">';
8893: }
8894: my $defcheck = ' ';
8895: if (ref($settings) eq 'HASH') {
8896: if (ref($settings->{$context}) eq 'ARRAY') {
8897: if (grep(/^default$/,@{$settings->{$context}})) {
8898: $defcheck = ' checked="checked" ';
8899: }
8900: } elsif ($context eq 'statustocreate') {
1.99 raeburn 8901: $defcheck = ' checked="checked" ';
8902: }
1.26 raeburn 8903: }
1.315 raeburn 8904: $output .= '<span class="LC_nobreak"><label>'.
8905: '<input type="checkbox" name="'.$context.'" '.
8906: 'value="default"'.$defcheck.$onclick.' />'.
8907: $othertitle.'</label></span>';
1.23 raeburn 8908: }
1.315 raeburn 8909: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 8910: return $output;
1.23 raeburn 8911: }
8912:
8913: sub sorted_searchtitles {
8914: my %searchtitles = &Apache::lonlocal::texthash(
8915: 'uname' => 'username',
8916: 'lastname' => 'last name',
8917: 'lastfirst' => 'last name, first name',
8918: );
8919: my @titleorder = ('uname','lastname','lastfirst');
8920: return (\%searchtitles,\@titleorder);
8921: }
8922:
1.25 raeburn 8923: sub sorted_searchtypes {
8924: my %srchtypes_desc = (
8925: exact => 'is exact match',
8926: contains => 'contains ..',
8927: begins => 'begins with ..',
8928: );
8929: my @srchtypeorder = ('exact','begins','contains');
8930: return (\%srchtypes_desc,\@srchtypeorder);
8931: }
8932:
1.3 raeburn 8933: sub usertype_update_row {
8934: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
8935: my $datatable;
8936: my $numinrow = 4;
8937: foreach my $type (@{$types}) {
8938: if (defined($usertypes->{$type})) {
8939: $$rownums ++;
8940: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
8941: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
8942: '</td><td class="LC_left_item"><table>';
8943: for (my $i=0; $i<@{$fields}; $i++) {
8944: my $rem = $i%($numinrow);
8945: if ($rem == 0) {
8946: if ($i > 0) {
8947: $datatable .= '</tr>';
8948: }
8949: $datatable .= '<tr>';
8950: }
8951: my $check = ' ';
1.39 raeburn 8952: if (ref($settings) eq 'HASH') {
8953: if (ref($settings->{'fields'}) eq 'HASH') {
8954: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
8955: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
8956: $check = ' checked="checked" ';
8957: }
1.3 raeburn 8958: }
8959: }
8960: }
8961:
8962: if ($i == @{$fields}-1) {
8963: my $colsleft = $numinrow - $rem;
8964: if ($colsleft > 1) {
8965: $datatable .= '<td colspan="'.$colsleft.'">';
8966: } else {
8967: $datatable .= '<td>';
8968: }
8969: } else {
8970: $datatable .= '<td>';
8971: }
1.8 raeburn 8972: $datatable .= '<span class="LC_nobreak"><label>'.
8973: '<input type="checkbox" name="updateable_'.$type.
8974: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
8975: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 8976: }
8977: $datatable .= '</tr></table></td></tr>';
8978: }
8979: }
8980: return $datatable;
1.1 raeburn 8981: }
8982:
8983: sub modify_login {
1.205 raeburn 8984: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 8985: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
8986: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
8987: %title = ( coursecatalog => 'Display course catalog',
8988: adminmail => 'Display administrator E-mail address',
1.188 raeburn 8989: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 8990: newuser => 'Link for visitors to create a user account',
8991: loginheader => 'Log-in box header');
8992: @offon = ('off','on');
1.112 raeburn 8993: if (ref($domconfig{login}) eq 'HASH') {
8994: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
8995: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
8996: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
8997: }
8998: }
8999: }
1.9 raeburn 9000: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
9001: \%domconfig,\%loginhash);
1.188 raeburn 9002: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 9003: foreach my $item (@toggles) {
9004: $loginhash{login}{$item} = $env{'form.'.$item};
9005: }
1.41 raeburn 9006: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 9007: if (ref($colchanges{'login'}) eq 'HASH') {
9008: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
9009: \%loginhash);
9010: }
1.110 raeburn 9011:
1.149 raeburn 9012: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 9013: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 9014: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 9015: if (keys(%servers) > 1) {
9016: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 9017: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
9018: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
9019: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
9020: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
9021: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
9022: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9023: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
9024: $changes{'loginvia'}{$lonhost} = 1;
9025: } else {
9026: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
9027: $changes{'loginvia'}{$lonhost} = 1;
9028: }
9029: } else {
9030: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9031: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
9032: $changes{'loginvia'}{$lonhost} = 1;
9033: }
9034: }
9035: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
9036: foreach my $item (@loginvia_attribs) {
9037: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
9038: }
9039: } else {
9040: foreach my $item (@loginvia_attribs) {
9041: my $new = $env{'form.'.$lonhost.'_'.$item};
9042: if (($item eq 'serverpath') && ($new eq 'custom')) {
9043: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
9044: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9045: $new = '/';
9046: }
9047: }
9048: if (($item eq 'custompath') &&
9049: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9050: $new = '';
9051: }
9052: if ($new ne $curr_loginvia{$lonhost}{$item}) {
9053: $changes{'loginvia'}{$lonhost} = 1;
9054: }
9055: if ($item eq 'exempt') {
1.256 raeburn 9056: $new = &check_exempt_addresses($new);
1.128 raeburn 9057: }
9058: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9059: }
9060: }
1.112 raeburn 9061: } else {
1.128 raeburn 9062: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9063: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 9064: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 9065: foreach my $item (@loginvia_attribs) {
9066: my $new = $env{'form.'.$lonhost.'_'.$item};
9067: if (($item eq 'serverpath') && ($new eq 'custom')) {
9068: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9069: $new = '/';
9070: }
9071: }
9072: if (($item eq 'custompath') &&
9073: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9074: $new = '';
9075: }
9076: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9077: }
1.110 raeburn 9078: }
9079: }
9080: }
9081: }
1.119 raeburn 9082:
1.168 raeburn 9083: my $servadm = $r->dir_config('lonAdmEMail');
9084: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
9085: if (ref($domconfig{'login'}) eq 'HASH') {
9086: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
9087: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
9088: if ($lang eq 'nolang') {
9089: push(@currlangs,$lang);
9090: } elsif (defined($langchoices{$lang})) {
9091: push(@currlangs,$lang);
9092: } else {
9093: next;
9094: }
9095: }
9096: }
9097: }
9098: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
9099: if (@currlangs > 0) {
9100: foreach my $lang (@currlangs) {
9101: if (grep(/^\Q$lang\E$/,@delurls)) {
9102: $changes{'helpurl'}{$lang} = 1;
9103: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
9104: $changes{'helpurl'}{$lang} = 1;
9105: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
9106: push(@newlangs,$lang);
9107: } else {
9108: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9109: }
9110: }
9111: }
9112: unless (grep(/^nolang$/,@currlangs)) {
9113: if ($env{'form.loginhelpurl_nolang.filename'}) {
9114: $changes{'helpurl'}{'nolang'} = 1;
9115: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
9116: push(@newlangs,'nolang');
9117: }
9118: }
9119: if ($env{'form.loginhelpurl_add_lang'}) {
9120: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
9121: ($env{'form.loginhelpurl_add_file.filename'})) {
9122: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
9123: $addedfile = $env{'form.loginhelpurl_add_lang'};
9124: }
9125: }
9126: if ((@newlangs > 0) || ($addedfile)) {
9127: my $error;
9128: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9129: if ($configuserok eq 'ok') {
9130: if ($switchserver) {
9131: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
9132: } elsif ($author_ok eq 'ok') {
9133: my @allnew = @newlangs;
9134: if ($addedfile ne '') {
9135: push(@allnew,$addedfile);
9136: }
9137: foreach my $lang (@allnew) {
9138: my $formelem = 'loginhelpurl_'.$lang;
9139: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
9140: $formelem = 'loginhelpurl_add_file';
9141: }
9142: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9143: "help/$lang",'','',$newfile{$lang});
9144: if ($result eq 'ok') {
9145: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
9146: $changes{'helpurl'}{$lang} = 1;
9147: } else {
9148: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
9149: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 9150: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 9151: (!grep(/^\Q$lang\E$/,@delurls))) {
9152: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9153: }
9154: }
9155: }
9156: } else {
9157: $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);
9158: }
9159: } else {
9160: $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);
9161: }
9162: if ($error) {
9163: &Apache::lonnet::logthis($error);
9164: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9165: }
9166: }
1.256 raeburn 9167:
9168: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
9169: if (ref($domconfig{'login'}) eq 'HASH') {
9170: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
9171: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
9172: if ($domservers{$lonhost}) {
9173: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9174: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 9175: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 9176: }
9177: }
9178: }
9179: }
9180: }
9181: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
9182: foreach my $lonhost (sort(keys(%domservers))) {
9183: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9184: $changes{'headtag'}{$lonhost} = 1;
9185: } else {
9186: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
9187: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
9188: }
9189: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
9190: push(@newhosts,$lonhost);
9191: } elsif ($currheadtagurls{$lonhost}) {
9192: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
9193: if ($currexempt{$lonhost}) {
1.289 raeburn 9194: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 9195: $changes{'headtag'}{$lonhost} = 1;
9196: }
9197: } elsif ($possexempt{$lonhost}) {
9198: $changes{'headtag'}{$lonhost} = 1;
9199: }
9200: if ($possexempt{$lonhost}) {
9201: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9202: }
9203: }
9204: }
9205: }
9206: if (@newhosts) {
9207: my $error;
9208: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9209: if ($configuserok eq 'ok') {
9210: if ($switchserver) {
9211: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
9212: } elsif ($author_ok eq 'ok') {
9213: foreach my $lonhost (@newhosts) {
9214: my $formelem = 'loginheadtag_'.$lonhost;
9215: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9216: "login/headtag/$lonhost",'','',
9217: $env{'form.loginheadtag_'.$lonhost.'.filename'});
9218: if ($result eq 'ok') {
9219: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
9220: $changes{'headtag'}{$lonhost} = 1;
9221: if ($possexempt{$lonhost}) {
9222: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9223: }
9224: } else {
9225: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
9226: $newheadtagurls{$lonhost},$result);
9227: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
9228: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
9229: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
9230: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
9231: }
9232: }
9233: }
9234: } else {
9235: $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);
9236: }
9237: } else {
9238: $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);
9239: }
9240: if ($error) {
9241: &Apache::lonnet::logthis($error);
9242: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9243: }
9244: }
1.169 raeburn 9245: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 9246:
9247: my $defaulthelpfile = '/adm/loginproblems.html';
9248: my $defaulttext = &mt('Default in use');
9249:
1.1 raeburn 9250: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
9251: $dom);
9252: if ($putresult eq 'ok') {
1.188 raeburn 9253: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 9254: my %defaultchecked = (
9255: 'coursecatalog' => 'on',
1.188 raeburn 9256: 'helpdesk' => 'on',
1.42 raeburn 9257: 'adminmail' => 'off',
1.43 raeburn 9258: 'newuser' => 'off',
1.42 raeburn 9259: );
1.55 raeburn 9260: if (ref($domconfig{'login'}) eq 'HASH') {
9261: foreach my $item (@toggles) {
9262: if ($defaultchecked{$item} eq 'on') {
9263: if (($domconfig{'login'}{$item} eq '0') &&
9264: ($env{'form.'.$item} eq '1')) {
9265: $changes{$item} = 1;
9266: } elsif (($domconfig{'login'}{$item} eq '' ||
9267: $domconfig{'login'}{$item} eq '1') &&
9268: ($env{'form.'.$item} eq '0')) {
9269: $changes{$item} = 1;
9270: }
9271: } elsif ($defaultchecked{$item} eq 'off') {
9272: if (($domconfig{'login'}{$item} eq '1') &&
9273: ($env{'form.'.$item} eq '0')) {
9274: $changes{$item} = 1;
9275: } elsif (($domconfig{'login'}{$item} eq '' ||
9276: $domconfig{'login'}{$item} eq '0') &&
9277: ($env{'form.'.$item} eq '1')) {
9278: $changes{$item} = 1;
9279: }
1.42 raeburn 9280: }
9281: }
1.41 raeburn 9282: }
1.6 raeburn 9283: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 9284: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9285: if (ref($lastactref) eq 'HASH') {
9286: $lastactref->{'domainconfig'} = 1;
9287: }
1.1 raeburn 9288: $resulttext = &mt('Changes made:').'<ul>';
9289: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 9290: if ($item eq 'loginvia') {
1.112 raeburn 9291: if (ref($changes{$item}) eq 'HASH') {
9292: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
9293: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 9294: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
9295: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
9296: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
9297: $protocol = 'http' if ($protocol ne 'https');
9298: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
9299:
9300: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
9301: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
9302: } else {
9303: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
9304: }
9305: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
9306: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
9307: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
9308: }
9309: $resulttext .= '</li>';
9310: } else {
9311: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
9312: }
1.112 raeburn 9313: } else {
1.128 raeburn 9314: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 9315: }
9316: }
1.128 raeburn 9317: $resulttext .= '</ul></li>';
1.112 raeburn 9318: }
1.168 raeburn 9319: } elsif ($item eq 'helpurl') {
9320: if (ref($changes{$item}) eq 'HASH') {
9321: foreach my $lang (sort(keys(%{$changes{$item}}))) {
9322: if (grep(/^\Q$lang\E$/,@delurls)) {
9323: my ($chg,$link);
9324: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
9325: if ($lang eq 'nolang') {
9326: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
9327: } else {
9328: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
9329: }
9330: $resulttext .= '<li>'.$chg.'</li>';
9331: } else {
9332: my $chg;
9333: if ($lang eq 'nolang') {
9334: $chg = &mt('custom log-in help file for no preferred language');
9335: } else {
9336: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
9337: }
9338: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
9339: $loginhash{'login'}{'helpurl'}{$lang}.
9340: '?inhibitmenu=yes',$chg,600,500).
9341: '</li>';
9342: }
9343: }
9344: }
1.256 raeburn 9345: } elsif ($item eq 'headtag') {
9346: if (ref($changes{$item}) eq 'HASH') {
9347: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
9348: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9349: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
9350: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9351: $resulttext .= '<li><a href="'.
9352: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
9353: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
9354: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
9355: if ($possexempt{$lonhost}) {
9356: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
9357: } else {
9358: $resulttext .= &mt('included for any client IP');
9359: }
9360: $resulttext .= '</li>';
9361: }
9362: }
9363: }
1.169 raeburn 9364: } elsif ($item eq 'captcha') {
9365: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 9366: my $chgtxt;
1.169 raeburn 9367: if ($loginhash{'login'}{$item} eq 'notused') {
9368: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
9369: } else {
9370: my %captchas = &captcha_phrases();
9371: if ($captchas{$loginhash{'login'}{$item}}) {
9372: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
9373: } else {
9374: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
9375: }
9376: }
9377: $resulttext .= '<li>'.$chgtxt.'</li>';
9378: }
9379: } elsif ($item eq 'recaptchakeys') {
9380: if (ref($loginhash{'login'}) eq 'HASH') {
9381: my ($privkey,$pubkey);
9382: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
9383: $pubkey = $loginhash{'login'}{$item}{'public'};
9384: $privkey = $loginhash{'login'}{$item}{'private'};
9385: }
9386: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
9387: if (!$pubkey) {
9388: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
9389: } else {
9390: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
9391: }
9392: if (!$privkey) {
9393: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
9394: } else {
1.251 raeburn 9395: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 9396: }
9397: $chgtxt .= '</ul>';
9398: $resulttext .= '<li>'.$chgtxt.'</li>';
9399: }
1.269 raeburn 9400: } elsif ($item eq 'recaptchaversion') {
9401: if (ref($loginhash{'login'}) eq 'HASH') {
9402: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 9403: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 9404: '</li>';
9405: }
9406: }
1.41 raeburn 9407: } else {
9408: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
9409: }
1.1 raeburn 9410: }
1.6 raeburn 9411: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 9412: } else {
9413: $resulttext = &mt('No changes made to log-in page settings');
9414: }
9415: } else {
1.11 albertel 9416: $resulttext = '<span class="LC_error">'.
9417: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9418: }
1.6 raeburn 9419: if ($errors) {
1.9 raeburn 9420: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 9421: $errors.'</ul>';
9422: }
9423: return $resulttext;
9424: }
9425:
1.256 raeburn 9426: sub check_exempt_addresses {
9427: my ($iplist) = @_;
9428: $iplist =~ s/^\s+//;
9429: $iplist =~ s/\s+$//;
9430: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
9431: my (@okips,$new);
9432: foreach my $ip (@poss_ips) {
9433: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
9434: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
9435: push(@okips,$ip);
9436: }
9437: }
9438: }
9439: if (@okips > 0) {
9440: $new = join(',',@okips);
9441: } else {
9442: $new = '';
9443: }
9444: return $new;
9445: }
9446:
1.6 raeburn 9447: sub color_font_choices {
9448: my %choices =
9449: &Apache::lonlocal::texthash (
9450: img => "Header",
9451: bgs => "Background colors",
9452: links => "Link colors",
1.55 raeburn 9453: images => "Images",
1.6 raeburn 9454: font => "Font color",
1.201 raeburn 9455: fontmenu => "Font menu",
1.76 raeburn 9456: pgbg => "Page",
1.6 raeburn 9457: tabbg => "Header",
9458: sidebg => "Border",
9459: link => "Link",
9460: alink => "Active link",
9461: vlink => "Visited link",
9462: );
9463: return %choices;
9464: }
9465:
9466: sub modify_rolecolors {
1.205 raeburn 9467: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 9468: my ($resulttext,%rolehash);
9469: $rolehash{'rolecolors'} = {};
1.55 raeburn 9470: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
9471: if ($domconfig{'rolecolors'} eq '') {
9472: $domconfig{'rolecolors'} = {};
9473: }
9474: }
1.9 raeburn 9475: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 9476: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
9477: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
9478: $dom);
9479: if ($putresult eq 'ok') {
9480: if (keys(%changes) > 0) {
1.41 raeburn 9481: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9482: if (ref($lastactref) eq 'HASH') {
9483: $lastactref->{'domainconfig'} = 1;
9484: }
1.6 raeburn 9485: $resulttext = &display_colorchgs($dom,\%changes,$roles,
9486: $rolehash{'rolecolors'});
9487: } else {
9488: $resulttext = &mt('No changes made to default color schemes');
9489: }
9490: } else {
1.11 albertel 9491: $resulttext = '<span class="LC_error">'.
9492: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 9493: }
9494: if ($errors) {
9495: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9496: $errors.'</ul>';
9497: }
9498: return $resulttext;
9499: }
9500:
9501: sub modify_colors {
1.9 raeburn 9502: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 9503: my (%changes,%choices);
1.51 raeburn 9504: my @bgs;
1.6 raeburn 9505: my @links = ('link','alink','vlink');
1.41 raeburn 9506: my @logintext;
1.6 raeburn 9507: my @images;
9508: my $servadm = $r->dir_config('lonAdmEMail');
9509: my $errors;
1.200 raeburn 9510: my %defaults;
1.6 raeburn 9511: foreach my $role (@{$roles}) {
9512: if ($role eq 'login') {
1.12 raeburn 9513: %choices = &login_choices();
1.41 raeburn 9514: @logintext = ('textcol','bgcol');
1.12 raeburn 9515: } else {
9516: %choices = &color_font_choices();
9517: }
9518: if ($role eq 'login') {
1.41 raeburn 9519: @images = ('img','logo','domlogo','login');
1.51 raeburn 9520: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 9521: } else {
9522: @images = ('img');
1.200 raeburn 9523: @bgs = ('pgbg','tabbg','sidebg');
9524: }
9525: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
9526: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
9527: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
9528: }
9529: if ($role eq 'login') {
9530: foreach my $item (@logintext) {
1.234 raeburn 9531: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9532: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9533: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9534: }
9535: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 9536: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9537: }
9538: }
9539: } else {
1.234 raeburn 9540: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
9541: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
9542: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
9543: }
9544: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 9545: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
9546: }
1.6 raeburn 9547: }
1.200 raeburn 9548: foreach my $item (@bgs) {
1.234 raeburn 9549: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9550: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9551: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9552: }
9553: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 9554: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9555: }
9556: }
9557: foreach my $item (@links) {
1.234 raeburn 9558: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9559: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9560: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9561: }
9562: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 9563: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9564: }
1.6 raeburn 9565: }
1.46 raeburn 9566: my ($configuserok,$author_ok,$switchserver) =
9567: &config_check($dom,$confname,$servadm);
1.9 raeburn 9568: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 9569: if (ref($domconfig->{$role}) ne 'HASH') {
9570: $domconfig->{$role} = {};
9571: }
1.8 raeburn 9572: foreach my $img (@images) {
1.70 raeburn 9573: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
9574: if (defined($env{'form.login_showlogo_'.$img})) {
9575: $confhash->{$role}{'showlogo'}{$img} = 1;
9576: } else {
9577: $confhash->{$role}{'showlogo'}{$img} = 0;
9578: }
9579: }
1.18 albertel 9580: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
9581: && !defined($domconfig->{$role}{$img})
9582: && !$env{'form.'.$role.'_del_'.$img}
9583: && $env{'form.'.$role.'_import_'.$img}) {
9584: # import the old configured image from the .tab setting
9585: # if they haven't provided a new one
9586: $domconfig->{$role}{$img} =
9587: $env{'form.'.$role.'_import_'.$img};
9588: }
1.6 raeburn 9589: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 9590: my $error;
1.6 raeburn 9591: if ($configuserok eq 'ok') {
1.9 raeburn 9592: if ($switchserver) {
1.12 raeburn 9593: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 9594: } else {
9595: if ($author_ok eq 'ok') {
9596: my ($result,$logourl) =
9597: &publishlogo($r,'upload',$role.'_'.$img,
9598: $dom,$confname,$img,$width,$height);
9599: if ($result eq 'ok') {
9600: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 9601: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 9602: } else {
1.12 raeburn 9603: $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 9604: }
9605: } else {
1.46 raeburn 9606: $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 9607: }
9608: }
9609: } else {
1.46 raeburn 9610: $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 9611: }
9612: if ($error) {
1.8 raeburn 9613: &Apache::lonnet::logthis($error);
1.11 albertel 9614: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 9615: }
9616: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 9617: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
9618: my $error;
9619: if ($configuserok eq 'ok') {
9620: # is confname an author?
9621: if ($switchserver eq '') {
9622: if ($author_ok eq 'ok') {
9623: my ($result,$logourl) =
9624: &publishlogo($r,'copy',$domconfig->{$role}{$img},
9625: $dom,$confname,$img,$width,$height);
9626: if ($result eq 'ok') {
9627: $confhash->{$role}{$img} = $logourl;
1.18 albertel 9628: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 9629: }
9630: }
9631: }
9632: }
1.6 raeburn 9633: }
9634: }
9635: }
9636: if (ref($domconfig) eq 'HASH') {
9637: if (ref($domconfig->{$role}) eq 'HASH') {
9638: foreach my $img (@images) {
9639: if ($domconfig->{$role}{$img} ne '') {
9640: if ($env{'form.'.$role.'_del_'.$img}) {
9641: $confhash->{$role}{$img} = '';
1.12 raeburn 9642: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 9643: } else {
1.9 raeburn 9644: if ($confhash->{$role}{$img} eq '') {
9645: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
9646: }
1.6 raeburn 9647: }
9648: } else {
9649: if ($env{'form.'.$role.'_del_'.$img}) {
9650: $confhash->{$role}{$img} = '';
1.12 raeburn 9651: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 9652: }
9653: }
1.70 raeburn 9654: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
9655: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
9656: if ($confhash->{$role}{'showlogo'}{$img} ne
9657: $domconfig->{$role}{'showlogo'}{$img}) {
9658: $changes{$role}{'showlogo'}{$img} = 1;
9659: }
9660: } else {
9661: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
9662: $changes{$role}{'showlogo'}{$img} = 1;
9663: }
9664: }
9665: }
9666: }
1.6 raeburn 9667: if ($domconfig->{$role}{'font'} ne '') {
9668: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
9669: $changes{$role}{'font'} = 1;
9670: }
9671: } else {
9672: if ($confhash->{$role}{'font'}) {
9673: $changes{$role}{'font'} = 1;
9674: }
9675: }
1.107 raeburn 9676: if ($role ne 'login') {
9677: if ($domconfig->{$role}{'fontmenu'} ne '') {
9678: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
9679: $changes{$role}{'fontmenu'} = 1;
9680: }
9681: } else {
9682: if ($confhash->{$role}{'fontmenu'}) {
9683: $changes{$role}{'fontmenu'} = 1;
9684: }
1.97 tempelho 9685: }
9686: }
1.6 raeburn 9687: foreach my $item (@bgs) {
9688: if ($domconfig->{$role}{$item} ne '') {
9689: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9690: $changes{$role}{'bgs'}{$item} = 1;
9691: }
9692: } else {
9693: if ($confhash->{$role}{$item}) {
9694: $changes{$role}{'bgs'}{$item} = 1;
9695: }
9696: }
9697: }
9698: foreach my $item (@links) {
9699: if ($domconfig->{$role}{$item} ne '') {
9700: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9701: $changes{$role}{'links'}{$item} = 1;
9702: }
9703: } else {
9704: if ($confhash->{$role}{$item}) {
9705: $changes{$role}{'links'}{$item} = 1;
9706: }
9707: }
9708: }
1.41 raeburn 9709: foreach my $item (@logintext) {
9710: if ($domconfig->{$role}{$item} ne '') {
9711: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9712: $changes{$role}{'logintext'}{$item} = 1;
9713: }
9714: } else {
9715: if ($confhash->{$role}{$item}) {
9716: $changes{$role}{'logintext'}{$item} = 1;
9717: }
9718: }
9719: }
1.6 raeburn 9720: } else {
9721: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 9722: \@logintext,$confhash,\%changes);
1.6 raeburn 9723: }
9724: } else {
9725: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 9726: \@logintext,$confhash,\%changes);
1.6 raeburn 9727: }
9728: }
9729: return ($errors,%changes);
9730: }
9731:
1.46 raeburn 9732: sub config_check {
9733: my ($dom,$confname,$servadm) = @_;
9734: my ($configuserok,$author_ok,$switchserver,%currroles);
9735: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
9736: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
9737: $confname,$servadm);
9738: if ($configuserok eq 'ok') {
9739: $switchserver = &check_switchserver($dom,$confname);
9740: if ($switchserver eq '') {
9741: $author_ok = &check_authorstatus($dom,$confname,%currroles);
9742: }
9743: }
9744: return ($configuserok,$author_ok,$switchserver);
9745: }
9746:
1.6 raeburn 9747: sub default_change_checker {
1.41 raeburn 9748: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 9749: foreach my $item (@{$links}) {
9750: if ($confhash->{$role}{$item}) {
9751: $changes->{$role}{'links'}{$item} = 1;
9752: }
9753: }
9754: foreach my $item (@{$bgs}) {
9755: if ($confhash->{$role}{$item}) {
9756: $changes->{$role}{'bgs'}{$item} = 1;
9757: }
9758: }
1.41 raeburn 9759: foreach my $item (@{$logintext}) {
9760: if ($confhash->{$role}{$item}) {
9761: $changes->{$role}{'logintext'}{$item} = 1;
9762: }
9763: }
1.6 raeburn 9764: foreach my $img (@{$images}) {
9765: if ($env{'form.'.$role.'_del_'.$img}) {
9766: $confhash->{$role}{$img} = '';
1.12 raeburn 9767: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 9768: }
1.70 raeburn 9769: if ($role eq 'login') {
9770: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
9771: $changes->{$role}{'showlogo'}{$img} = 1;
9772: }
9773: }
1.6 raeburn 9774: }
9775: if ($confhash->{$role}{'font'}) {
9776: $changes->{$role}{'font'} = 1;
9777: }
1.48 raeburn 9778: }
1.6 raeburn 9779:
9780: sub display_colorchgs {
9781: my ($dom,$changes,$roles,$confhash) = @_;
9782: my (%choices,$resulttext);
9783: if (!grep(/^login$/,@{$roles})) {
9784: $resulttext = &mt('Changes made:').'<br />';
9785: }
9786: foreach my $role (@{$roles}) {
9787: if ($role eq 'login') {
9788: %choices = &login_choices();
9789: } else {
9790: %choices = &color_font_choices();
9791: }
9792: if (ref($changes->{$role}) eq 'HASH') {
9793: if ($role ne 'login') {
9794: $resulttext .= '<h4>'.&mt($role).'</h4>';
9795: }
9796: foreach my $key (sort(keys(%{$changes->{$role}}))) {
9797: if ($role ne 'login') {
9798: $resulttext .= '<ul>';
9799: }
9800: if (ref($changes->{$role}{$key}) eq 'HASH') {
9801: if ($role ne 'login') {
9802: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
9803: }
9804: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 9805: if (($role eq 'login') && ($key eq 'showlogo')) {
9806: if ($confhash->{$role}{$key}{$item}) {
9807: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
9808: } else {
9809: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
9810: }
9811: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 9812: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
9813: } else {
1.12 raeburn 9814: my $newitem = $confhash->{$role}{$item};
9815: if ($key eq 'images') {
1.306 raeburn 9816: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 9817: }
9818: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 9819: }
9820: }
9821: if ($role ne 'login') {
9822: $resulttext .= '</ul></li>';
9823: }
9824: } else {
9825: if ($confhash->{$role}{$key} eq '') {
9826: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
9827: } else {
9828: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
9829: }
9830: }
9831: if ($role ne 'login') {
9832: $resulttext .= '</ul>';
9833: }
9834: }
9835: }
9836: }
1.3 raeburn 9837: return $resulttext;
1.1 raeburn 9838: }
9839:
1.9 raeburn 9840: sub thumb_dimensions {
9841: return ('200','50');
9842: }
9843:
1.16 raeburn 9844: sub check_dimensions {
9845: my ($inputfile) = @_;
9846: my ($fullwidth,$fullheight);
9847: if ($inputfile =~ m|^[/\w.\-]+$|) {
9848: if (open(PIPE,"identify $inputfile 2>&1 |")) {
9849: my $imageinfo = <PIPE>;
9850: if (!close(PIPE)) {
9851: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
9852: }
9853: chomp($imageinfo);
9854: my ($fullsize) =
1.21 raeburn 9855: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 9856: if ($fullsize) {
9857: ($fullwidth,$fullheight) = split(/x/,$fullsize);
9858: }
9859: }
9860: }
9861: return ($fullwidth,$fullheight);
9862: }
9863:
1.9 raeburn 9864: sub check_configuser {
9865: my ($uhome,$dom,$confname,$servadm) = @_;
9866: my ($configuserok,%currroles);
9867: if ($uhome eq 'no_host') {
9868: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
9869: my $configpass = &LONCAPA::Enrollment::create_password();
9870: $configuserok =
9871: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
9872: $configpass,'','','','','',undef,$servadm);
9873: } else {
9874: $configuserok = 'ok';
9875: %currroles =
9876: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
9877: }
9878: return ($configuserok,%currroles);
9879: }
9880:
9881: sub check_authorstatus {
9882: my ($dom,$confname,%currroles) = @_;
9883: my $author_ok;
1.40 raeburn 9884: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 9885: my $start = time;
9886: my $end = 0;
9887: $author_ok =
9888: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 9889: 'au',$end,$start,'','','domconfig');
1.9 raeburn 9890: } else {
9891: $author_ok = 'ok';
9892: }
9893: return $author_ok;
9894: }
9895:
9896: sub publishlogo {
1.46 raeburn 9897: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 9898: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 9899: if ($action eq 'upload') {
9900: $fname=$env{'form.'.$formname.'.filename'};
9901: chop($env{'form.'.$formname});
9902: } else {
9903: ($fname) = ($formname =~ /([^\/]+)$/);
9904: }
1.46 raeburn 9905: if ($savefileas ne '') {
9906: $fname = $savefileas;
9907: }
1.9 raeburn 9908: $fname=&Apache::lonnet::clean_filename($fname);
9909: # See if there is anything left
9910: unless ($fname) { return ('error: no uploaded file'); }
9911: $fname="$subdir/$fname";
1.210 raeburn 9912: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 9913: my $filepath="$docroot/priv";
9914: my $relpath = "$dom/$confname";
1.9 raeburn 9915: my ($fnamepath,$file,$fetchthumb);
9916: $file=$fname;
9917: if ($fname=~m|/|) {
9918: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
9919: }
1.164 raeburn 9920: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 9921: my $count;
1.164 raeburn 9922: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 9923: $filepath.="/$parts[$count]";
9924: if ((-e $filepath)!=1) {
9925: mkdir($filepath,02770);
9926: }
9927: }
9928: # Check for bad extension and disallow upload
9929: if ($file=~/\.(\w+)$/ &&
9930: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
9931: $output =
1.207 bisitz 9932: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 9933: } elsif ($file=~/\.(\w+)$/ &&
9934: !defined(&Apache::loncommon::fileembstyle($1))) {
9935: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
9936: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 9937: $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 9938: } elsif (-d "$filepath/$file") {
1.195 bisitz 9939: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 9940: } else {
9941: my $source = $filepath.'/'.$file;
9942: my $logfile;
1.316 raeburn 9943: if (!open($logfile,">>",$source.'.log')) {
1.196 raeburn 9944: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 9945: }
9946: print $logfile
9947: "\n================= Publish ".localtime()." ================\n".
9948: $env{'user.name'}.':'.$env{'user.domain'}."\n";
9949: # Save the file
1.316 raeburn 9950: if (!open(FH,">",$source)) {
1.9 raeburn 9951: &Apache::lonnet::logthis('Failed to create '.$source);
9952: return (&mt('Failed to create file'));
9953: }
9954: if ($action eq 'upload') {
9955: if (!print FH ($env{'form.'.$formname})) {
9956: &Apache::lonnet::logthis('Failed to write to '.$source);
9957: return (&mt('Failed to write file'));
9958: }
9959: } else {
9960: my $original = &Apache::lonnet::filelocation('',$formname);
9961: if(!copy($original,$source)) {
9962: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
9963: return (&mt('Failed to write file'));
9964: }
9965: }
9966: close(FH);
9967: chmod(0660, $source); # Permissions to rw-rw---.
9968:
9969: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
9970: my $copyfile=$targetdir.'/'.$file;
9971:
9972: my @parts=split(/\//,$targetdir);
9973: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
9974: for (my $count=5;$count<=$#parts;$count++) {
9975: $path.="/$parts[$count]";
9976: if (!-e $path) {
9977: print $logfile "\nCreating directory ".$path;
9978: mkdir($path,02770);
9979: }
9980: }
9981: my $versionresult;
9982: if (-e $copyfile) {
9983: $versionresult = &logo_versioning($targetdir,$file,$logfile);
9984: } else {
9985: $versionresult = 'ok';
9986: }
9987: if ($versionresult eq 'ok') {
9988: if (copy($source,$copyfile)) {
9989: print $logfile "\nCopied original source to ".$copyfile."\n";
9990: $output = 'ok';
9991: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 9992: push(@{$modified_urls},[$copyfile,$source]);
9993: my $metaoutput =
9994: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
9995: unless ($registered_cleanup) {
9996: my $handlers = $r->get_handlers('PerlCleanupHandler');
9997: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
9998: $registered_cleanup=1;
9999: }
1.9 raeburn 10000: } else {
10001: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
10002: $output = &mt('Failed to copy file to RES space').", $!";
10003: }
10004: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
10005: my $inputfile = $filepath.'/'.$file;
10006: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 10007: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
10008: if ($fullwidth ne '' && $fullheight ne '') {
10009: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
10010: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316 raeburn 10011: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
10012: system({$args[0]} @args);
1.16 raeburn 10013: chmod(0660, $filepath.'/tn-'.$file);
10014: if (-e $outfile) {
10015: my $copyfile=$targetdir.'/tn-'.$file;
10016: if (copy($outfile,$copyfile)) {
10017: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 10018: my $thumb_metaoutput =
10019: &write_metadata($dom,$confname,$formname,
10020: $targetdir,'tn-'.$file,$logfile);
10021: push(@{$modified_urls},[$copyfile,$outfile]);
10022: unless ($registered_cleanup) {
10023: my $handlers = $r->get_handlers('PerlCleanupHandler');
10024: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
10025: $registered_cleanup=1;
10026: }
1.267 raeburn 10027: $madethumb = 1;
1.16 raeburn 10028: } else {
10029: print $logfile "\nUnable to write ".$copyfile.
10030: ':'.$!."\n";
10031: }
10032: }
1.9 raeburn 10033: }
10034: }
10035: }
10036: } else {
10037: $output = $versionresult;
10038: }
10039: }
1.267 raeburn 10040: return ($output,$logourl,$madethumb);
1.9 raeburn 10041: }
10042:
10043: sub logo_versioning {
10044: my ($targetdir,$file,$logfile) = @_;
10045: my $target = $targetdir.'/'.$file;
10046: my ($maxversion,$fn,$extn,$output);
10047: $maxversion = 0;
10048: if ($file =~ /^(.+)\.(\w+)$/) {
10049: $fn=$1;
10050: $extn=$2;
10051: }
10052: opendir(DIR,$targetdir);
10053: while (my $filename=readdir(DIR)) {
10054: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
10055: $maxversion=($1>$maxversion)?$1:$maxversion;
10056: }
10057: }
10058: $maxversion++;
10059: print $logfile "\nCreating old version ".$maxversion."\n";
10060: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
10061: if (copy($target,$copyfile)) {
10062: print $logfile "Copied old target to ".$copyfile."\n";
10063: $copyfile=$copyfile.'.meta';
10064: if (copy($target.'.meta',$copyfile)) {
10065: print $logfile "Copied old target metadata to ".$copyfile."\n";
10066: $output = 'ok';
10067: } else {
10068: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
10069: $output = &mt('Failed to copy old meta').", $!, ";
10070: }
10071: } else {
10072: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
10073: $output = &mt('Failed to copy old target').", $!, ";
10074: }
10075: return $output;
10076: }
10077:
10078: sub write_metadata {
10079: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
10080: my (%metadatafields,%metadatakeys,$output);
10081: $metadatafields{'title'}=$formname;
10082: $metadatafields{'creationdate'}=time;
10083: $metadatafields{'lastrevisiondate'}=time;
10084: $metadatafields{'copyright'}='public';
10085: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
10086: $env{'user.domain'};
10087: $metadatafields{'authorspace'}=$confname.':'.$dom;
10088: $metadatafields{'domain'}=$dom;
10089: {
10090: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
10091: my $mfh;
1.316 raeburn 10092: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 10093: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 10094: unless ($_=~/\./) {
10095: my $unikey=$_;
10096: $unikey=~/^([A-Za-z]+)/;
10097: my $tag=$1;
10098: $tag=~tr/A-Z/a-z/;
10099: print $mfh "\n\<$tag";
10100: foreach (split(/\,/,$metadatakeys{$unikey})) {
10101: my $value=$metadatafields{$unikey.'.'.$_};
10102: $value=~s/\"/\'\'/g;
10103: print $mfh ' '.$_.'="'.$value.'"';
10104: }
10105: print $mfh '>'.
10106: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
10107: .'</'.$tag.'>';
10108: }
10109: }
10110: $output = 'ok';
10111: print $logfile "\nWrote metadata";
10112: close($mfh);
10113: } else {
10114: print $logfile "\nFailed to open metadata file";
1.9 raeburn 10115: $output = &mt('Could not write metadata');
10116: }
10117: }
1.155 raeburn 10118: return $output;
10119: }
10120:
10121: sub notifysubscribed {
10122: foreach my $targetsource (@{$modified_urls}){
10123: next unless (ref($targetsource) eq 'ARRAY');
10124: my ($target,$source)=@{$targetsource};
10125: if ($source ne '') {
1.316 raeburn 10126: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 10127: print $logfh "\nCleanup phase: Notifications\n";
10128: my @subscribed=&subscribed_hosts($target);
10129: foreach my $subhost (@subscribed) {
10130: print $logfh "\nNotifying host ".$subhost.':';
10131: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
10132: print $logfh $reply;
10133: }
10134: my @subscribedmeta=&subscribed_hosts("$target.meta");
10135: foreach my $subhost (@subscribedmeta) {
10136: print $logfh "\nNotifying host for metadata only ".$subhost.':';
10137: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
10138: $subhost);
10139: print $logfh $reply;
10140: }
10141: print $logfh "\n============ Done ============\n";
1.160 raeburn 10142: close($logfh);
1.155 raeburn 10143: }
10144: }
10145: }
10146: return OK;
10147: }
10148:
10149: sub subscribed_hosts {
10150: my ($target) = @_;
10151: my @subscribed;
1.316 raeburn 10152: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 10153: while (my $subline=<$fh>) {
10154: if ($subline =~ /^($match_lonid):/) {
10155: my $host = $1;
10156: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
10157: unless (grep(/^\Q$host\E$/,@subscribed)) {
10158: push(@subscribed,$host);
10159: }
10160: }
10161: }
10162: }
10163: }
10164: return @subscribed;
1.9 raeburn 10165: }
10166:
10167: sub check_switchserver {
10168: my ($dom,$confname) = @_;
10169: my ($allowed,$switchserver);
10170: my $home = &Apache::lonnet::homeserver($confname,$dom);
10171: if ($home eq 'no_host') {
10172: $home = &Apache::lonnet::domain($dom,'primary');
10173: }
10174: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 10175: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
10176: if (!$allowed) {
1.180 raeburn 10177: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 10178: }
10179: return $switchserver;
10180: }
10181:
1.1 raeburn 10182: sub modify_quotas {
1.216 raeburn 10183: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 10184: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 10185: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 10186: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
10187: $validationfieldsref);
1.86 raeburn 10188: if ($action eq 'quotas') {
10189: $context = 'tools';
1.163 raeburn 10190: } else {
1.86 raeburn 10191: $context = $action;
10192: }
10193: if ($context eq 'requestcourses') {
1.325 raeburn 10194: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 10195: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 10196: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
10197: %titles = &courserequest_titles();
10198: $toolregexp = join('|',@usertools);
10199: %conditions = &courserequest_conditions();
1.216 raeburn 10200: $confname = $dom.'-domainconfig';
10201: my $servadm = $r->dir_config('lonAdmEMail');
10202: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 10203: ($validationitemsref,$validationnamesref,$validationfieldsref) =
10204: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 10205: } elsif ($context eq 'requestauthor') {
10206: @usertools = ('author');
10207: %titles = &authorrequest_titles();
1.86 raeburn 10208: } else {
1.162 raeburn 10209: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 10210: %titles = &tool_titles();
1.86 raeburn 10211: }
1.212 raeburn 10212: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 10213: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 10214: foreach my $key (keys(%env)) {
1.101 raeburn 10215: if ($context eq 'requestcourses') {
10216: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
10217: my $item = $1;
10218: my $type = $2;
10219: if ($type =~ /^limit_(.+)/) {
10220: $limithash{$item}{$1} = $env{$key};
10221: } else {
10222: $confhash{$item}{$type} = $env{$key};
10223: }
10224: }
1.163 raeburn 10225: } elsif ($context eq 'requestauthor') {
10226: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
10227: $confhash{$1} = $env{$key};
10228: }
1.101 raeburn 10229: } else {
1.86 raeburn 10230: if ($key =~ /^form\.quota_(.+)$/) {
10231: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 10232: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
10233: $confhash{'authorquota'}{$1} = $env{$key};
10234: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 10235: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
10236: }
1.72 raeburn 10237: }
10238: }
1.163 raeburn 10239: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 10240: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 10241: @approvalnotify = sort(@approvalnotify);
10242: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 10243: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 10244: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
10245: foreach my $type (@hasuniquecode) {
10246: if (grep(/^\Q$type\E$/,@crstypes)) {
10247: $confhash{'uniquecode'}{$type} = 1;
10248: }
1.216 raeburn 10249: }
1.242 raeburn 10250: my (%newbook,%allpos);
1.216 raeburn 10251: if ($context eq 'requestcourses') {
1.242 raeburn 10252: foreach my $type ('textbooks','templates') {
10253: @{$allpos{$type}} = ();
10254: my $invalid;
10255: if ($type eq 'textbooks') {
10256: $invalid = &mt('Invalid LON-CAPA course for textbook');
10257: } else {
10258: $invalid = &mt('Invalid LON-CAPA course for template');
10259: }
10260: if ($env{'form.'.$type.'_addbook'}) {
10261: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
10262: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
10263: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
10264: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
10265: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
10266: } else {
10267: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
10268: my $position = $env{'form.'.$type.'_addbook_pos'};
10269: $position =~ s/\D+//g;
10270: if ($position ne '') {
10271: $allpos{$type}[$position] = $newbook{$type};
10272: }
1.216 raeburn 10273: }
1.242 raeburn 10274: } else {
10275: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 10276: }
10277: }
1.242 raeburn 10278: }
1.216 raeburn 10279: }
1.102 raeburn 10280: if (ref($domconfig{$action}) eq 'HASH') {
10281: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
10282: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
10283: $changes{'notify'}{'approval'} = 1;
10284: }
10285: } else {
1.144 raeburn 10286: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10287: $changes{'notify'}{'approval'} = 1;
10288: }
10289: }
1.218 raeburn 10290: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
10291: if (ref($confhash{'uniquecode'}) eq 'HASH') {
10292: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
10293: unless ($confhash{'uniquecode'}{$crstype}) {
10294: $changes{'uniquecode'} = 1;
10295: }
10296: }
10297: unless ($changes{'uniquecode'}) {
10298: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
10299: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
10300: $changes{'uniquecode'} = 1;
10301: }
10302: }
10303: }
10304: } else {
10305: $changes{'uniquecode'} = 1;
10306: }
10307: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
10308: $changes{'uniquecode'} = 1;
1.216 raeburn 10309: }
10310: if ($context eq 'requestcourses') {
1.242 raeburn 10311: foreach my $type ('textbooks','templates') {
10312: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10313: my %deletions;
10314: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
10315: if (@todelete) {
10316: map { $deletions{$_} = 1; } @todelete;
10317: }
10318: my %imgdeletions;
10319: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
10320: if (@todeleteimages) {
10321: map { $imgdeletions{$_} = 1; } @todeleteimages;
10322: }
10323: my $maxnum = $env{'form.'.$type.'_maxnum'};
10324: for (my $i=0; $i<=$maxnum; $i++) {
10325: my $itemid = $env{'form.'.$type.'_id_'.$i};
10326: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
10327: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
10328: if ($deletions{$key}) {
10329: if ($domconfig{$action}{$type}{$key}{'image'}) {
10330: #FIXME need to obsolete item in RES space
10331: }
10332: next;
10333: } else {
10334: my $newpos = $env{'form.'.$itemid};
10335: $newpos =~ s/\D+//g;
1.243 raeburn 10336: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 10337: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 10338: ($type eq 'templates'));
1.242 raeburn 10339: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
10340: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
10341: $changes{$type}{$key} = 1;
10342: }
10343: }
10344: $allpos{$type}[$newpos] = $key;
10345: }
10346: if ($imgdeletions{$key}) {
10347: $changes{$type}{$key} = 1;
1.216 raeburn 10348: #FIXME need to obsolete item in RES space
1.242 raeburn 10349: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
10350: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 10351: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10352: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10353: } else {
10354: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
10355: $cdom,$cnum,$type,$configuserok,
10356: $switchserver,$author_ok);
10357: if ($imgurl) {
10358: $confhash{$type}{$key}{'image'} = $imgurl;
10359: $changes{$type}{$key} = 1;
10360: }
10361: if ($error) {
10362: &Apache::lonnet::logthis($error);
10363: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10364: }
10365: }
1.242 raeburn 10366: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
10367: $confhash{$type}{$key}{'image'} =
10368: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 10369: }
10370: }
10371: }
10372: }
10373: }
10374: }
1.102 raeburn 10375: } else {
1.144 raeburn 10376: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10377: $changes{'notify'}{'approval'} = 1;
10378: }
1.218 raeburn 10379: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 10380: $changes{'uniquecode'} = 1;
10381: }
10382: }
10383: if ($context eq 'requestcourses') {
1.242 raeburn 10384: foreach my $type ('textbooks','templates') {
10385: if ($newbook{$type}) {
10386: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 10387: foreach my $item ('subject','title','publisher','author') {
10388: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10389: ($type eq 'template'));
1.242 raeburn 10390: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
10391: if ($env{'form.'.$type.'_addbook_'.$item}) {
10392: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
10393: }
10394: }
10395: if ($type eq 'textbooks') {
10396: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
10397: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 10398: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10399: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10400: } else {
10401: my ($imageurl,$error) =
10402: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
10403: $configuserok,$switchserver,$author_ok);
10404: if ($imageurl) {
10405: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
10406: }
10407: if ($error) {
10408: &Apache::lonnet::logthis($error);
10409: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10410: }
1.242 raeburn 10411: }
10412: }
1.216 raeburn 10413: }
10414: }
1.242 raeburn 10415: if (@{$allpos{$type}} > 0) {
10416: my $idx = 0;
10417: foreach my $item (@{$allpos{$type}}) {
10418: if ($item ne '') {
10419: $confhash{$type}{$item}{'order'} = $idx;
10420: if (ref($domconfig{$action}) eq 'HASH') {
10421: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10422: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
10423: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
10424: $changes{$type}{$item} = 1;
10425: }
1.216 raeburn 10426: }
10427: }
10428: }
1.242 raeburn 10429: $idx ++;
1.216 raeburn 10430: }
10431: }
10432: }
10433: }
1.235 raeburn 10434: if (ref($validationitemsref) eq 'ARRAY') {
10435: foreach my $item (@{$validationitemsref}) {
10436: if ($item eq 'fields') {
10437: my @changed;
10438: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
10439: if (@{$confhash{'validation'}{$item}} > 0) {
10440: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
10441: }
1.266 raeburn 10442: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10443: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10444: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
10445: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
10446: $domconfig{'requestcourses'}{'validation'}{$item});
10447: } else {
10448: @changed = @{$confhash{'validation'}{$item}};
10449: }
1.235 raeburn 10450: } else {
10451: @changed = @{$confhash{'validation'}{$item}};
10452: }
10453: } else {
10454: @changed = @{$confhash{'validation'}{$item}};
10455: }
10456: if (@changed) {
10457: if ($confhash{'validation'}{$item}) {
10458: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
10459: } else {
10460: $changes{'validation'}{$item} = &mt('None');
10461: }
10462: }
10463: } else {
10464: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
10465: if ($item eq 'markup') {
10466: if ($env{'form.requestcourses_validation_'.$item}) {
10467: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10468: }
10469: }
1.266 raeburn 10470: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10471: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10472: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
10473: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10474: }
10475: } else {
10476: if ($confhash{'validation'}{$item} ne '') {
10477: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10478: }
1.235 raeburn 10479: }
10480: } else {
10481: if ($confhash{'validation'}{$item} ne '') {
10482: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10483: }
10484: }
10485: }
10486: }
10487: }
10488: if ($env{'form.validationdc'}) {
10489: my $newval = $env{'form.validationdc'};
1.285 raeburn 10490: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 10491: if (exists($domcoords{$newval})) {
10492: $confhash{'validation'}{'dc'} = $newval;
10493: }
10494: }
10495: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 10496: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10497: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10498: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10499: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
10500: if ($confhash{'validation'}{'dc'} eq '') {
10501: $changes{'validation'}{'dc'} = &mt('None');
10502: } else {
10503: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10504: }
1.235 raeburn 10505: }
1.266 raeburn 10506: } elsif ($confhash{'validation'}{'dc'} ne '') {
10507: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 10508: }
10509: } elsif ($confhash{'validation'}{'dc'} ne '') {
10510: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10511: }
10512: } elsif ($confhash{'validation'}{'dc'} ne '') {
10513: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 10514: }
1.266 raeburn 10515: } else {
10516: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10517: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10518: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10519: $changes{'validation'}{'dc'} = &mt('None');
10520: }
10521: }
1.235 raeburn 10522: }
10523: }
1.102 raeburn 10524: }
10525: } else {
1.86 raeburn 10526: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 10527: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 10528: }
1.72 raeburn 10529: foreach my $item (@usertools) {
10530: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 10531: my $unset;
1.101 raeburn 10532: if ($context eq 'requestcourses') {
1.104 raeburn 10533: $unset = '0';
10534: if ($type eq '_LC_adv') {
10535: $unset = '';
10536: }
1.101 raeburn 10537: if ($confhash{$item}{$type} eq 'autolimit') {
10538: $confhash{$item}{$type} .= '=';
10539: unless ($limithash{$item}{$type} =~ /\D/) {
10540: $confhash{$item}{$type} .= $limithash{$item}{$type};
10541: }
10542: }
1.163 raeburn 10543: } elsif ($context eq 'requestauthor') {
10544: $unset = '0';
10545: if ($type eq '_LC_adv') {
10546: $unset = '';
10547: }
1.72 raeburn 10548: } else {
1.101 raeburn 10549: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
10550: $confhash{$item}{$type} = 1;
10551: } else {
10552: $confhash{$item}{$type} = 0;
10553: }
1.72 raeburn 10554: }
1.86 raeburn 10555: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 10556: if ($action eq 'requestauthor') {
10557: if ($domconfig{$action}{$type} ne $confhash{$type}) {
10558: $changes{$type} = 1;
10559: }
10560: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 10561: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
10562: $changes{$item}{$type} = 1;
10563: }
10564: } else {
10565: if ($context eq 'requestcourses') {
1.104 raeburn 10566: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 10567: $changes{$item}{$type} = 1;
10568: }
10569: } else {
10570: if (!$confhash{$item}{$type}) {
10571: $changes{$item}{$type} = 1;
10572: }
10573: }
10574: }
10575: } else {
10576: if ($context eq 'requestcourses') {
1.104 raeburn 10577: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 10578: $changes{$item}{$type} = 1;
10579: }
1.163 raeburn 10580: } elsif ($context eq 'requestauthor') {
10581: if ($confhash{$type} ne $unset) {
10582: $changes{$type} = 1;
10583: }
1.72 raeburn 10584: } else {
10585: if (!$confhash{$item}{$type}) {
10586: $changes{$item}{$type} = 1;
10587: }
10588: }
10589: }
1.1 raeburn 10590: }
10591: }
1.163 raeburn 10592: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 10593: if (ref($domconfig{'quotas'}) eq 'HASH') {
10594: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
10595: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
10596: if (exists($confhash{'defaultquota'}{$key})) {
10597: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
10598: $changes{'defaultquota'}{$key} = 1;
10599: }
10600: } else {
10601: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 10602: }
10603: }
1.86 raeburn 10604: } else {
10605: foreach my $key (keys(%{$domconfig{'quotas'}})) {
10606: if (exists($confhash{'defaultquota'}{$key})) {
10607: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
10608: $changes{'defaultquota'}{$key} = 1;
10609: }
10610: } else {
10611: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 10612: }
1.1 raeburn 10613: }
10614: }
1.197 raeburn 10615: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
10616: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
10617: if (exists($confhash{'authorquota'}{$key})) {
10618: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
10619: $changes{'authorquota'}{$key} = 1;
10620: }
10621: } else {
10622: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
10623: }
10624: }
10625: }
1.1 raeburn 10626: }
1.86 raeburn 10627: if (ref($confhash{'defaultquota'}) eq 'HASH') {
10628: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
10629: if (ref($domconfig{'quotas'}) eq 'HASH') {
10630: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
10631: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
10632: $changes{'defaultquota'}{$key} = 1;
10633: }
10634: } else {
10635: if (!exists($domconfig{'quotas'}{$key})) {
10636: $changes{'defaultquota'}{$key} = 1;
10637: }
1.72 raeburn 10638: }
10639: } else {
1.86 raeburn 10640: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 10641: }
1.1 raeburn 10642: }
10643: }
1.197 raeburn 10644: if (ref($confhash{'authorquota'}) eq 'HASH') {
10645: foreach my $key (keys(%{$confhash{'authorquota'}})) {
10646: if (ref($domconfig{'quotas'}) eq 'HASH') {
10647: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
10648: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
10649: $changes{'authorquota'}{$key} = 1;
10650: }
10651: } else {
10652: $changes{'authorquota'}{$key} = 1;
10653: }
10654: } else {
10655: $changes{'authorquota'}{$key} = 1;
10656: }
10657: }
10658: }
1.1 raeburn 10659: }
1.72 raeburn 10660:
1.163 raeburn 10661: if ($context eq 'requestauthor') {
10662: $domdefaults{'requestauthor'} = \%confhash;
10663: } else {
10664: foreach my $key (keys(%confhash)) {
1.242 raeburn 10665: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 10666: $domdefaults{$key} = $confhash{$key};
10667: }
1.163 raeburn 10668: }
1.72 raeburn 10669: }
1.163 raeburn 10670:
1.1 raeburn 10671: my %quotahash = (
1.86 raeburn 10672: $action => { %confhash }
1.1 raeburn 10673: );
10674: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
10675: $dom);
10676: if ($putresult eq 'ok') {
10677: if (keys(%changes) > 0) {
1.72 raeburn 10678: my $cachetime = 24*60*60;
10679: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 10680: if (ref($lastactref) eq 'HASH') {
10681: $lastactref->{'domdefaults'} = 1;
10682: }
1.1 raeburn 10683: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 10684: unless (($context eq 'requestcourses') ||
1.163 raeburn 10685: ($context eq 'requestauthor')) {
1.86 raeburn 10686: if (ref($changes{'defaultquota'}) eq 'HASH') {
10687: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
10688: foreach my $type (@{$types},'default') {
10689: if (defined($changes{'defaultquota'}{$type})) {
10690: my $typetitle = $usertypes->{$type};
10691: if ($type eq 'default') {
10692: $typetitle = $othertitle;
10693: }
1.213 raeburn 10694: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 10695: }
10696: }
1.86 raeburn 10697: $resulttext .= '</ul></li>';
1.72 raeburn 10698: }
1.197 raeburn 10699: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 10700: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 10701: foreach my $type (@{$types},'default') {
10702: if (defined($changes{'authorquota'}{$type})) {
10703: my $typetitle = $usertypes->{$type};
10704: if ($type eq 'default') {
10705: $typetitle = $othertitle;
10706: }
1.213 raeburn 10707: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 10708: }
10709: }
10710: $resulttext .= '</ul></li>';
10711: }
1.72 raeburn 10712: }
1.80 raeburn 10713: my %newenv;
1.72 raeburn 10714: foreach my $item (@usertools) {
1.163 raeburn 10715: my (%haschgs,%inconf);
10716: if ($context eq 'requestauthor') {
10717: %haschgs = %changes;
1.210 raeburn 10718: %inconf = %confhash;
1.163 raeburn 10719: } else {
10720: if (ref($changes{$item}) eq 'HASH') {
10721: %haschgs = %{$changes{$item}};
10722: }
10723: if (ref($confhash{$item}) eq 'HASH') {
10724: %inconf = %{$confhash{$item}};
10725: }
10726: }
10727: if (keys(%haschgs) > 0) {
1.80 raeburn 10728: my $newacc =
10729: &Apache::lonnet::usertools_access($env{'user.name'},
10730: $env{'user.domain'},
1.86 raeburn 10731: $item,'reload',$context);
1.210 raeburn 10732: if (($context eq 'requestcourses') ||
1.163 raeburn 10733: ($context eq 'requestauthor')) {
1.108 raeburn 10734: if ($env{'environment.canrequest.'.$item} ne $newacc) {
10735: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 10736: }
10737: } else {
10738: if ($env{'environment.availabletools.'.$item} ne $newacc) {
10739: $newenv{'environment.availabletools.'.$item} = $newacc;
10740: }
1.80 raeburn 10741: }
1.163 raeburn 10742: unless ($context eq 'requestauthor') {
10743: $resulttext .= '<li>'.$titles{$item}.'<ul>';
10744: }
1.72 raeburn 10745: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 10746: if ($haschgs{$type}) {
1.72 raeburn 10747: my $typetitle = $usertypes->{$type};
10748: if ($type eq 'default') {
10749: $typetitle = $othertitle;
10750: } elsif ($type eq '_LC_adv') {
10751: $typetitle = 'LON-CAPA Advanced Users';
10752: }
1.163 raeburn 10753: if ($inconf{$type}) {
1.101 raeburn 10754: if ($context eq 'requestcourses') {
10755: my $cond;
1.163 raeburn 10756: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 10757: if ($1 eq '') {
10758: $cond = &mt('(Automatic processing of any request).');
10759: } else {
10760: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
10761: }
10762: } else {
1.163 raeburn 10763: $cond = $conditions{$inconf{$type}};
1.101 raeburn 10764: }
10765: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 10766: } elsif ($context eq 'requestauthor') {
10767: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
10768: $titles{$inconf{$type}},$typetitle);
10769:
1.101 raeburn 10770: } else {
10771: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
10772: }
1.72 raeburn 10773: } else {
1.104 raeburn 10774: if ($type eq '_LC_adv') {
1.163 raeburn 10775: if ($inconf{$type} eq '0') {
1.104 raeburn 10776: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
10777: } else {
10778: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
10779: }
10780: } else {
10781: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
10782: }
1.72 raeburn 10783: }
10784: }
1.26 raeburn 10785: }
1.163 raeburn 10786: unless ($context eq 'requestauthor') {
10787: $resulttext .= '</ul></li>';
10788: }
1.26 raeburn 10789: }
1.1 raeburn 10790: }
1.163 raeburn 10791: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 10792: if (ref($changes{'notify'}) eq 'HASH') {
10793: if ($changes{'notify'}{'approval'}) {
10794: if (ref($confhash{'notify'}) eq 'HASH') {
10795: if ($confhash{'notify'}{'approval'}) {
10796: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
10797: } else {
1.163 raeburn 10798: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 10799: }
10800: }
10801: }
10802: }
10803: }
1.216 raeburn 10804: if ($action eq 'requestcourses') {
10805: my @offon = ('off','on');
10806: if ($changes{'uniquecode'}) {
1.218 raeburn 10807: if (ref($confhash{'uniquecode'}) eq 'HASH') {
10808: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
10809: $resulttext .= '<li>'.
10810: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
10811: '</li>';
10812: } else {
10813: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
10814: '</li>';
10815: }
1.216 raeburn 10816: }
1.242 raeburn 10817: foreach my $type ('textbooks','templates') {
10818: if (ref($changes{$type}) eq 'HASH') {
10819: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
10820: foreach my $key (sort(keys(%{$changes{$type}}))) {
10821: my %coursehash = &Apache::lonnet::coursedescription($key);
10822: my $coursetitle = $coursehash{'description'};
10823: my $position = $confhash{$type}{$key}{'order'} + 1;
10824: $resulttext .= '<li>';
1.243 raeburn 10825: foreach my $item ('subject','title','publisher','author') {
10826: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10827: ($type eq 'templates'));
1.242 raeburn 10828: my $name = $item.':';
10829: $name =~ s/^(\w)/\U$1/;
10830: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
10831: }
10832: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
10833: if ($type eq 'textbooks') {
10834: if ($confhash{$type}{$key}{'image'}) {
10835: $resulttext .= ' '.&mt('Image: [_1]',
10836: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
10837: ' alt="Textbook cover" />').'<br />';
10838: }
10839: }
10840: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 10841: }
1.242 raeburn 10842: $resulttext .= '</ul></li>';
1.216 raeburn 10843: }
10844: }
1.235 raeburn 10845: if (ref($changes{'validation'}) eq 'HASH') {
10846: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
10847: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
10848: foreach my $item (@{$validationitemsref}) {
10849: if (exists($changes{'validation'}{$item})) {
10850: if ($item eq 'markup') {
10851: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
10852: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
10853: } else {
10854: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
10855: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
10856: }
10857: }
10858: }
10859: if (exists($changes{'validation'}{'dc'})) {
10860: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
10861: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
10862: }
10863: }
10864: }
1.216 raeburn 10865: }
1.1 raeburn 10866: $resulttext .= '</ul>';
1.80 raeburn 10867: if (keys(%newenv)) {
10868: &Apache::lonnet::appenv(\%newenv);
10869: }
1.1 raeburn 10870: } else {
1.86 raeburn 10871: if ($context eq 'requestcourses') {
10872: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 10873: } elsif ($context eq 'requestauthor') {
10874: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 10875: } else {
1.90 weissno 10876: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 10877: }
1.1 raeburn 10878: }
10879: } else {
1.11 albertel 10880: $resulttext = '<span class="LC_error">'.
10881: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10882: }
1.216 raeburn 10883: if ($errors) {
10884: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
10885: '<ul>'.$errors.'</ul></p>';
10886: }
1.3 raeburn 10887: return $resulttext;
1.1 raeburn 10888: }
10889:
1.216 raeburn 10890: sub process_textbook_image {
1.242 raeburn 10891: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 10892: my $filename = $env{'form.'.$caller.'.filename'};
10893: my ($error,$url);
10894: my ($width,$height) = (50,50);
10895: if ($configuserok eq 'ok') {
10896: if ($switchserver) {
10897: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
10898: $switchserver);
10899: } elsif ($author_ok eq 'ok') {
10900: my ($result,$imageurl) =
10901: &publishlogo($r,'upload',$caller,$dom,$confname,
1.312 raeburn 10902: "$type/$cdom/$cnum/cover",$width,$height);
1.216 raeburn 10903: if ($result eq 'ok') {
10904: $url = $imageurl;
10905: } else {
10906: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
10907: }
10908: } else {
10909: $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);
10910: }
10911: } else {
10912: $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);
10913: }
10914: return ($url,$error);
10915: }
10916:
1.267 raeburn 10917: sub modify_ltitools {
10918: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
10919: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 10920: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 10921: my $confname = $dom.'-domainconfig';
10922: my $servadm = $r->dir_config('lonAdmEMail');
10923: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10924: my (%posslti,%possfield);
10925: my @courseroles = ('cc','in','ta','ep','st');
10926: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
10927: map { $posslti{$_} = 1; } @ltiroles;
10928: my @allfields = ('fullname','firstname','lastname','email','user','roles');
10929: map { $possfield{$_} = 1; } @allfields;
10930: my %lt = <itools_names();
10931: if ($env{'form.ltitools_add'}) {
10932: my $title = $env{'form.ltitools_add_title'};
10933: $title =~ s/(`)/'/g;
10934: ($newid,my $error) = &get_ltitools_id($dom,$title);
10935: if ($newid) {
10936: my $position = $env{'form.ltitools_add_pos'};
10937: $position =~ s/\D+//g;
10938: if ($position ne '') {
10939: $allpos[$position] = $newid;
10940: }
10941: $changes{$newid} = 1;
1.322 raeburn 10942: foreach my $item ('title','url','key','secret','lifetime') {
1.267 raeburn 10943: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1.322 raeburn 10944: if ($item eq 'lifetime') {
10945: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
10946: }
1.267 raeburn 10947: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 10948: if (($item eq 'key') || ($item eq 'secret')) {
10949: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
10950: } else {
10951: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
10952: }
1.267 raeburn 10953: }
10954: }
10955: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
10956: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
10957: }
10958: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
10959: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
10960: }
1.323 raeburn 10961: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
10962: $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
10963: } else {
10964: $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
10965: }
1.296 raeburn 10966: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 10967: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
10968: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 10969: if (($item eq 'width') || ($item eq 'height')) {
10970: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
10971: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
10972: }
10973: } else {
10974: if ($env{'form.ltitools_add_'.$item} ne '') {
10975: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
10976: }
1.267 raeburn 10977: }
10978: }
10979: if ($env{'form.ltitools_add_target'} eq 'window') {
10980: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 10981: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
10982: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 10983: } else {
10984: $confhash{$newid}{'display'}{'target'} = 'iframe';
10985: }
10986: foreach my $item ('passback','roster') {
1.319 raeburn 10987: if ($env{'form.ltitools_'.$item.'_add'}) {
1.267 raeburn 10988: $confhash{$newid}{$item} = 1;
1.319 raeburn 10989: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
10990: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
10991: $lifetime =~ s/^\s+|\s+$//g;
10992: if ($lifetime =~ /^\d+\.?\d*$/) {
10993: $confhash{$newid}{$item.'valid'} = $lifetime;
10994: }
10995: }
1.267 raeburn 10996: }
10997: }
10998: if ($env{'form.ltitools_add_image.filename'} ne '') {
10999: my ($imageurl,$error) =
1.307 raeburn 11000: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267 raeburn 11001: $configuserok,$switchserver,$author_ok);
11002: if ($imageurl) {
11003: $confhash{$newid}{'image'} = $imageurl;
11004: }
11005: if ($error) {
11006: &Apache::lonnet::logthis($error);
11007: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11008: }
11009: }
11010: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
11011: foreach my $field (@fields) {
11012: if ($possfield{$field}) {
11013: if ($field eq 'roles') {
11014: foreach my $role (@courseroles) {
11015: my $choice = $env{'form.ltitools_add_roles_'.$role};
11016: if (($choice ne '') && ($posslti{$choice})) {
11017: $confhash{$newid}{'roles'}{$role} = $choice;
11018: if ($role eq 'cc') {
11019: $confhash{$newid}{'roles'}{'co'} = $choice;
11020: }
11021: }
11022: }
11023: } else {
11024: $confhash{$newid}{'fields'}{$field} = 1;
11025: }
11026: }
11027: }
1.324 raeburn 11028: if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
11029: if ($confhash{$newid}{'fields'}{'user'}) {
11030: if ($env{'form.ltitools_userincdom_add'}) {
11031: $confhash{$newid}{'incdom'} = 1;
11032: }
11033: }
11034: }
1.273 raeburn 11035: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
11036: foreach my $item (@courseconfig) {
11037: $confhash{$newid}{'crsconf'}{$item} = 1;
11038: }
1.267 raeburn 11039: if ($env{'form.ltitools_add_custom'}) {
11040: my $name = $env{'form.ltitools_add_custom_name'};
11041: my $value = $env{'form.ltitools_add_custom_value'};
11042: $value =~ s/(`)/'/g;
11043: $name =~ s/(`)/'/g;
11044: $confhash{$newid}{'custom'}{$name} = $value;
11045: }
11046: } else {
11047: my $error = &mt('Failed to acquire unique ID for new external tool');
11048: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11049: }
11050: }
11051: if (ref($domconfig{$action}) eq 'HASH') {
11052: my %deletions;
11053: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
11054: if (@todelete) {
11055: map { $deletions{$_} = 1; } @todelete;
11056: }
11057: my %customadds;
11058: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
11059: if (@newcustom) {
11060: map { $customadds{$_} = 1; } @newcustom;
11061: }
11062: my %imgdeletions;
11063: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
11064: if (@todeleteimages) {
11065: map { $imgdeletions{$_} = 1; } @todeleteimages;
11066: }
11067: my $maxnum = $env{'form.ltitools_maxnum'};
11068: for (my $i=0; $i<=$maxnum; $i++) {
11069: my $itemid = $env{'form.ltitools_id_'.$i};
1.308 raeburn 11070: $itemid =~ s/\D+//g;
1.267 raeburn 11071: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11072: if ($deletions{$itemid}) {
11073: if ($domconfig{$action}{$itemid}{'image'}) {
11074: #FIXME need to obsolete item in RES space
11075: }
11076: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
11077: next;
11078: } else {
11079: my $newpos = $env{'form.ltitools_'.$itemid};
11080: $newpos =~ s/\D+//g;
1.322 raeburn 11081: foreach my $item ('title','url','lifetime') {
1.267 raeburn 11082: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
11083: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
11084: $changes{$itemid} = 1;
11085: }
11086: }
1.297 raeburn 11087: foreach my $item ('key','secret') {
11088: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
11089: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
11090: $changes{$itemid} = 1;
11091: }
11092: }
1.267 raeburn 11093: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
11094: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
11095: }
11096: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
11097: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
11098: }
1.323 raeburn 11099: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
11100: $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
11101: } else {
11102: $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
11103: }
11104: if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
11105: if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
11106: $changes{$itemid} = 1;
11107: }
11108: } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
11109: $changes{$itemid} = 1;
11110: }
1.267 raeburn 11111: foreach my $size ('width','height') {
11112: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
11113: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
11114: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
11115: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
11116: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11117: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
11118: $changes{$itemid} = 1;
11119: }
11120: } else {
11121: $changes{$itemid} = 1;
11122: }
1.296 raeburn 11123: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11124: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
11125: $changes{$itemid} = 1;
11126: }
11127: }
11128: }
11129: foreach my $item ('linktext','explanation') {
11130: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
11131: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
11132: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
11133: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
11134: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11135: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
11136: $changes{$itemid} = 1;
11137: }
11138: } else {
11139: $changes{$itemid} = 1;
11140: }
11141: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11142: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
11143: $changes{$itemid} = 1;
11144: }
1.267 raeburn 11145: }
11146: }
11147: if ($env{'form.ltitools_target_'.$i} eq 'window') {
11148: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 11149: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
11150: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 11151: } else {
11152: $confhash{$itemid}{'display'}{'target'} = 'iframe';
11153: }
11154: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11155: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
11156: $changes{$itemid} = 1;
11157: }
11158: } else {
11159: $changes{$itemid} = 1;
11160: }
11161: foreach my $extra ('passback','roster') {
11162: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
11163: $confhash{$itemid}{$extra} = 1;
1.319 raeburn 11164: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
11165: my $lifetime = $env{'form.ltitools_'.$extra.'valid_add'};
11166: $lifetime =~ s/^\s+|\s+$//g;
11167: if ($lifetime =~ /^\d+\.?\d*$/) {
11168: $confhash{$itemid}{$extra.'valid'} = $lifetime;
11169: }
11170: }
1.267 raeburn 11171: }
11172: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
11173: $changes{$itemid} = 1;
11174: }
1.319 raeburn 11175: if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
11176: $changes{$itemid} = 1;
11177: }
1.267 raeburn 11178: }
1.273 raeburn 11179: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318 raeburn 11180: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 11181: if (grep(/^\Q$item\E$/,@courseconfig)) {
11182: $confhash{$itemid}{'crsconf'}{$item} = 1;
11183: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
11184: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
11185: $changes{$itemid} = 1;
11186: }
11187: } else {
11188: $changes{$itemid} = 1;
11189: }
11190: }
11191: }
1.267 raeburn 11192: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
11193: foreach my $field (@fields) {
11194: if ($possfield{$field}) {
11195: if ($field eq 'roles') {
11196: foreach my $role (@courseroles) {
11197: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
11198: if (($choice ne '') && ($posslti{$choice})) {
11199: $confhash{$itemid}{'roles'}{$role} = $choice;
11200: if ($role eq 'cc') {
11201: $confhash{$itemid}{'roles'}{'co'} = $choice;
11202: }
11203: }
11204: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
11205: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
11206: $changes{$itemid} = 1;
11207: }
11208: } elsif ($confhash{$itemid}{'roles'}{$role}) {
11209: $changes{$itemid} = 1;
11210: }
11211: }
11212: } else {
11213: $confhash{$itemid}{'fields'}{$field} = 1;
11214: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
11215: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
11216: $changes{$itemid} = 1;
11217: }
11218: } else {
11219: $changes{$itemid} = 1;
11220: }
11221: }
11222: }
11223: }
1.324 raeburn 11224: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
11225: if ($confhash{$itemid}{'fields'}{'user'}) {
11226: if ($env{'form.ltitools_userincdom_'.$i}) {
11227: $confhash{$itemid}{'incdom'} = 1;
11228: }
11229: if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
11230: $changes{$itemid} = 1;
11231: }
11232: }
11233: }
1.267 raeburn 11234: $allpos[$newpos] = $itemid;
11235: }
11236: if ($imgdeletions{$itemid}) {
11237: $changes{$itemid} = 1;
11238: #FIXME need to obsolete item in RES space
11239: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
11240: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
11241: $itemid,$configuserok,$switchserver,
11242: $author_ok);
11243: if ($imgurl) {
11244: $confhash{$itemid}{'image'} = $imgurl;
11245: $changes{$itemid} = 1;
11246: }
11247: if ($error) {
11248: &Apache::lonnet::logthis($error);
11249: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11250: }
11251: } elsif ($domconfig{$action}{$itemid}{'image'}) {
11252: $confhash{$itemid}{'image'} =
11253: $domconfig{$action}{$itemid}{'image'};
11254: }
11255: if ($customadds{$i}) {
11256: my $name = $env{'form.ltitools_custom_name_'.$i};
11257: $name =~ s/(`)/'/g;
11258: $name =~ s/^\s+//;
11259: $name =~ s/\s+$//;
11260: my $value = $env{'form.ltitools_custom_value_'.$i};
11261: $value =~ s/(`)/'/g;
11262: $value =~ s/^\s+//;
11263: $value =~ s/\s+$//;
11264: if ($name ne '') {
11265: $confhash{$itemid}{'custom'}{$name} = $value;
11266: $changes{$itemid} = 1;
11267: }
11268: }
11269: my %customdels;
11270: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
11271: if (@customdeletions) {
11272: $changes{$itemid} = 1;
11273: }
11274: map { $customdels{$_} = 1; } @customdeletions;
11275: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
11276: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
11277: unless ($customdels{$key}) {
11278: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
11279: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
11280: }
11281: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
11282: $changes{$itemid} = 1;
11283: }
11284: }
11285: }
11286: }
11287: unless ($changes{$itemid}) {
11288: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
11289: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
11290: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
11291: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
11292: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
11293: $changes{$itemid} = 1;
11294: last;
11295: }
11296: }
11297: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
11298: $changes{$itemid} = 1;
11299: }
11300: }
11301: last if ($changes{$itemid});
11302: }
11303: }
11304: }
11305: }
11306: }
11307: if (@allpos > 0) {
11308: my $idx = 0;
11309: foreach my $itemid (@allpos) {
11310: if ($itemid ne '') {
11311: $confhash{$itemid}{'order'} = $idx;
11312: if (ref($domconfig{$action}) eq 'HASH') {
11313: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11314: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
11315: $changes{$itemid} = 1;
11316: }
11317: }
11318: }
11319: $idx ++;
11320: }
11321: }
11322: }
11323: my %ltitoolshash = (
11324: $action => { %confhash }
11325: );
11326: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
11327: $dom);
11328: if ($putresult eq 'ok') {
1.297 raeburn 11329: my %ltienchash = (
11330: $action => { %encconfig }
11331: );
11332: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
1.267 raeburn 11333: if (keys(%changes) > 0) {
11334: my $cachetime = 24*60*60;
1.297 raeburn 11335: my %ltiall = %confhash;
11336: foreach my $id (keys(%ltiall)) {
11337: if (ref($encconfig{$id}) eq 'HASH') {
11338: foreach my $item ('key','secret') {
11339: $ltiall{$id}{$item} = $encconfig{$id}{$item};
11340: }
11341: }
11342: }
11343: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 11344: if (ref($lastactref) eq 'HASH') {
11345: $lastactref->{'ltitools'} = 1;
11346: }
11347: $resulttext = &mt('Changes made:').'<ul>';
11348: my %bynum;
11349: foreach my $itemid (sort(keys(%changes))) {
11350: my $position = $confhash{$itemid}{'order'};
11351: $bynum{$position} = $itemid;
11352: }
11353: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
11354: my $itemid = $bynum{$pos};
11355: if (ref($confhash{$itemid}) ne 'HASH') {
11356: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
11357: } else {
11358: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
11359: if ($confhash{$itemid}{'image'}) {
11360: $resulttext .= ' '.
11361: '<img src="'.$confhash{$itemid}{'image'}.'"'.
11362: ' alt="'.&mt('Tool Provider icon').'" />';
11363: }
11364: $resulttext .= '</li><ul>';
11365: my $position = $pos + 1;
11366: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.323 raeburn 11367: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1.267 raeburn 11368: if ($confhash{$itemid}{$item} ne '') {
11369: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
11370: }
11371: }
1.297 raeburn 11372: if ($encconfig{$itemid}{'key'} ne '') {
11373: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
11374: }
11375: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 11376: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 11377: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 11378: $resulttext .= ('*'x$num).'</li>';
11379: }
1.273 raeburn 11380: $resulttext .= '<li>'.&mt('Configurable in course:');
1.318 raeburn 11381: my @possconfig = ('label','title','target','linktext','explanation','append');
1.273 raeburn 11382: my $numconfig = 0;
11383: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
11384: foreach my $item (@possconfig) {
11385: if ($confhash{$itemid}{'crsconf'}{$item}) {
11386: $numconfig ++;
1.296 raeburn 11387: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 11388: }
11389: }
11390: }
11391: if (!$numconfig) {
11392: $resulttext .= &mt('None');
11393: }
11394: $resulttext .= '</li>';
1.267 raeburn 11395: foreach my $item ('passback','roster') {
11396: $resulttext .= '<li>'.$lt{$item}.' ';
11397: if ($confhash{$itemid}{$item}) {
11398: $resulttext .= &mt('Yes');
1.319 raeburn 11399: if ($confhash{$itemid}{$item.'valid'}) {
11400: if ($item eq 'passback') {
11401: $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
11402: $confhash{$itemid}{$item.'valid'});
11403: } else {
11404: $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
11405: $confhash{$itemid}{$item.'valid'});
11406: }
11407: }
1.267 raeburn 11408: } else {
11409: $resulttext .= &mt('No');
11410: }
11411: $resulttext .= '</li>';
11412: }
11413: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
11414: my $displaylist;
11415: if ($confhash{$itemid}{'display'}{'target'}) {
11416: $displaylist = &mt('Display target').': '.
11417: $confhash{$itemid}{'display'}{'target'}.',';
11418: }
11419: foreach my $size ('width','height') {
11420: if ($confhash{$itemid}{'display'}{$size}) {
11421: $displaylist .= (' 'x2).$lt{$size}.': '.
11422: $confhash{$itemid}{'display'}{$size}.',';
11423: }
11424: }
11425: if ($displaylist) {
11426: $displaylist =~ s/,$//;
11427: $resulttext .= '<li>'.$displaylist.'</li>';
11428: }
1.296 raeburn 11429: foreach my $item ('linktext','explanation') {
11430: if ($confhash{$itemid}{'display'}{$item}) {
11431: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
11432: }
11433: }
11434: }
1.267 raeburn 11435: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
11436: my $fieldlist;
11437: foreach my $field (@allfields) {
11438: if ($confhash{$itemid}{'fields'}{$field}) {
11439: $fieldlist .= (' 'x2).$lt{$field}.',';
11440: }
11441: }
11442: if ($fieldlist) {
11443: $fieldlist =~ s/,$//;
1.324 raeburn 11444: if ($confhash{$itemid}{'fields'}{'user'}) {
11445: if ($confhash{$itemid}{'incdom'}) {
11446: $fieldlist .= ' ('.&mt('username:domain').')';
11447: } else {
11448: $fieldlist .= ' ('.&mt('username').')';
11449: }
11450: }
1.267 raeburn 11451: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
11452: }
11453: }
11454: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
11455: my $rolemaps;
11456: foreach my $role (@courseroles) {
11457: if ($confhash{$itemid}{'roles'}{$role}) {
11458: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
11459: $confhash{$itemid}{'roles'}{$role}.',';
11460: }
11461: }
11462: if ($rolemaps) {
11463: $rolemaps =~ s/,$//;
11464: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
11465: }
11466: }
11467: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
11468: my $customlist;
11469: if (keys(%{$confhash{$itemid}{'custom'}})) {
11470: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
11471: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
11472: }
11473: }
11474: if ($customlist) {
1.317 raeburn 11475: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267 raeburn 11476: }
11477: }
11478: $resulttext .= '</ul></li>';
11479: }
11480: }
11481: $resulttext .= '</ul>';
11482: } else {
11483: $resulttext = &mt('No changes made.');
11484: }
11485: } else {
11486: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
11487: }
11488: if ($errors) {
11489: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11490: $errors.'</ul>';
11491: }
11492: return $resulttext;
11493: }
11494:
11495: sub process_ltitools_image {
11496: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
11497: my $filename = $env{'form.'.$caller.'.filename'};
11498: my ($error,$url);
11499: my ($width,$height) = (21,21);
11500: if ($configuserok eq 'ok') {
11501: if ($switchserver) {
11502: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
11503: $switchserver);
11504: } elsif ($author_ok eq 'ok') {
11505: my ($result,$imageurl,$madethumb) =
11506: &publishlogo($r,'upload',$caller,$dom,$confname,
11507: "ltitools/$itemid/icon",$width,$height);
11508: if ($result eq 'ok') {
11509: if ($madethumb) {
11510: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
11511: my $imagethumb = "$path/tn-".$imagefile;
11512: $url = $imagethumb;
11513: } else {
11514: $url = $imageurl;
11515: }
11516: } else {
11517: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
11518: }
11519: } else {
11520: $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);
11521: }
11522: } else {
11523: $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);
11524: }
11525: return ($url,$error);
11526: }
11527:
11528: sub get_ltitools_id {
11529: my ($cdom,$title) = @_;
11530: # get lock on ltitools db
11531: my $lockhash = {
11532: lock => $env{'user.name'}.
11533: ':'.$env{'user.domain'},
11534: };
11535: my $tries = 0;
11536: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
11537: my ($id,$error);
11538:
11539: while (($gotlock ne 'ok') && ($tries<10)) {
11540: $tries ++;
11541: sleep (0.1);
11542: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
11543: }
11544: if ($gotlock eq 'ok') {
11545: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
11546: if ($currids{'lock'}) {
11547: delete($currids{'lock'});
11548: if (keys(%currids)) {
11549: my @curr = sort { $a <=> $b } keys(%currids);
11550: if ($curr[-1] =~ /^\d+$/) {
11551: $id = 1 + $curr[-1];
11552: }
11553: } else {
11554: $id = 1;
11555: }
11556: if ($id) {
11557: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
11558: $error = 'nostore';
11559: }
11560: } else {
11561: $error = 'nonumber';
11562: }
11563: }
11564: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
11565: } else {
11566: $error = 'nolock';
11567: }
11568: return ($id,$error);
11569: }
11570:
1.320 raeburn 11571: sub modify_lti {
11572: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
11573: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11574: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
11575: my (%posslti,%posslticrs,%posscrstype);
11576: my @courseroles = ('cc','in','ta','ep','st');
11577: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
11578: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
11579: my @coursetypes = ('official','unofficial','community','textbook','placement');
11580: my %coursetypetitles = &Apache::lonlocal::texthash (
11581: official => 'Official',
11582: unofficial => 'Unofficial',
11583: community => 'Community',
11584: textbook => 'Textbook',
11585: placement => 'Placement Test',
11586: );
1.325 raeburn 11587: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 11588: my %lt = <i_names();
11589: map { $posslti{$_} = 1; } @ltiroles;
11590: map { $posslticrs{$_} = 1; } @lticourseroles;
11591: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 11592:
1.326 raeburn 11593: my %menutitles = <imenu_titles();
11594:
1.320 raeburn 11595: my (@items,%deletions,%itemids);
11596: if ($env{'form.lti_add'}) {
11597: my $consumer = $env{'form.lti_consumer_add'};
11598: $consumer =~ s/(`)/'/g;
11599: ($newid,my $error) = &get_lti_id($dom,$consumer);
11600: if ($newid) {
11601: $itemids{'add'} = $newid;
11602: push(@items,'add');
11603: $changes{$newid} = 1;
11604: } else {
11605: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
11606: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11607: }
11608: }
11609: if (ref($domconfig{$action}) eq 'HASH') {
11610: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
11611: if (@todelete) {
11612: map { $deletions{$_} = 1; } @todelete;
11613: }
11614: my $maxnum = $env{'form.lti_maxnum'};
11615: for (my $i=0; $i<=$maxnum; $i++) {
11616: my $itemid = $env{'form.lti_id_'.$i};
11617: $itemid =~ s/\D+//g;
11618: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11619: if ($deletions{$itemid}) {
11620: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
11621: } else {
11622: push(@items,$i);
11623: $itemids{$i} = $itemid;
11624: }
11625: }
11626: }
11627: }
11628: foreach my $idx (@items) {
11629: my $itemid = $itemids{$idx};
11630: next unless ($itemid);
11631: my $position = $env{'form.lti_pos_'.$idx};
11632: $position =~ s/\D+//g;
11633: if ($position ne '') {
11634: $allpos[$position] = $itemid;
11635: }
11636: foreach my $item ('consumer','key','secret','lifetime') {
11637: my $formitem = 'form.lti_'.$item.'_'.$idx;
11638: $env{$formitem} =~ s/(`)/'/g;
11639: if ($item eq 'lifetime') {
11640: $env{$formitem} =~ s/[^\d.]//g;
11641: }
11642: if ($env{$formitem} ne '') {
11643: if (($item eq 'key') || ($item eq 'secret')) {
11644: $encconfig{$itemid}{$item} = $env{$formitem};
11645: } else {
11646: $confhash{$itemid}{$item} = $env{$formitem};
11647: unless (($idx eq 'add') || ($changes{$itemid})) {
11648: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
11649: $changes{$itemid} = 1;
11650: }
11651: }
11652: }
11653: }
11654: }
11655: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
11656: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
11657: }
11658: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
11659: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
11660: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
11661: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
11662: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
11663: my $mapuser = $env{'form.lti_customuser_'.$idx};
11664: $mapuser =~ s/(`)/'/g;
11665: $mapuser =~ s/^\s+|\s+$//g;
11666: $confhash{$itemid}{'mapuser'} = $mapuser;
11667: }
11668: foreach my $ltirole (@lticourseroles) {
11669: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
11670: if (grep(/^\Q$possrole\E$/,@courseroles)) {
11671: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
11672: }
11673: }
11674: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
11675: my @makeuser;
11676: foreach my $ltirole (sort(@possmakeuser)) {
11677: if ($posslti{$ltirole}) {
11678: push(@makeuser,$ltirole);
11679: }
11680: }
11681: $confhash{$itemid}{'makeuser'} = \@makeuser;
1.325 raeburn 11682: if (@makeuser) {
11683: my $lcauth = $env{'form.lti_lcauth_'.$idx};
11684: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
11685: $confhash{$itemid}{'lcauth'} = $lcauth;
11686: if ($lcauth ne 'internal') {
11687: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
11688: $lcauthparm =~ s/^(\s+|\s+)$//g;
11689: $lcauthparm =~ s/`//g;
11690: if ($lcauthparm ne '') {
11691: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
11692: }
11693: }
11694: } else {
11695: $confhash{$itemid}{'lcauth'} = 'lti';
11696: }
11697: }
11698: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
11699: if (@possinstdata) {
11700: foreach my $field (@possinstdata) {
11701: if (exists($fieldtitles{$field})) {
11702: push(@{$confhash{$itemid}{'instdata'}});
11703: }
11704: }
11705: }
1.320 raeburn 11706: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
11707: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
11708: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
11709: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
11710: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
11711: $mapcrs =~ s/(`)/'/g;
11712: $mapcrs =~ s/^\s+|\s+$//g;
11713: $confhash{$itemid}{'mapcrs'} = $mapcrs;
11714: }
11715: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
11716: my @crstypes;
11717: foreach my $type (sort(@posstypes)) {
11718: if ($posscrstype{$type}) {
11719: push(@crstypes,$type);
11720: }
11721: }
11722: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
11723: if ($env{'form.lti_makecrs_'.$idx}) {
11724: $confhash{$itemid}{'makecrs'} = 1;
11725: }
11726: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
11727: my @selfenroll;
11728: foreach my $type (sort(@possenroll)) {
11729: if ($posslticrs{$type}) {
11730: push(@selfenroll,$type);
11731: }
11732: }
11733: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
11734: if ($env{'form.lti_crssec_'.$idx}) {
11735: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
11736: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
11737: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
11738: my $section = $env{'form.lti_customsection_'.$idx};
11739: $section =~ s/(`)/'/g;
11740: $section =~ s/^\s+|\s+$//g;
11741: if ($section ne '') {
11742: $confhash{$itemid}{'section'} = $section;
11743: }
11744: }
11745: }
1.326 raeburn 11746: foreach my $field ('passback','roster','topmenu','inlinemenu') {
1.321 raeburn 11747: if ($env{'form.lti_'.$field.'_'.$idx}) {
1.320 raeburn 11748: $confhash{$itemid}{$field} = 1;
11749: }
11750: }
1.337 ! raeburn 11751: if ($env{'form.lti_passback_'.$idx}) {
! 11752: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
! 11753: $confhash{$itemid}{'passbackformat'} = '1.0';
! 11754: } else {
! 11755: $confhash{$itemid}{'passbackformat'} = '1.1';
! 11756: }
! 11757: }
1.326 raeburn 11758: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
11759: $confhash{$itemid}{lcmenu} = [];
11760: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
11761: foreach my $field (@possmenu) {
11762: if (exists($menutitles{$field})) {
11763: if ($field eq 'grades') {
11764: next unless ($env{'form.lti_inlinemenu_'.$idx});
11765: }
11766: push(@{$confhash{$itemid}{lcmenu}},$field);
11767: }
11768: }
11769: }
1.320 raeburn 11770: unless (($idx eq 'add') || ($changes{$itemid})) {
1.326 raeburn 11771: foreach my $field ('mapuser','mapcrs','makecrs','section','passback','roster','lcauth','lcauthparm','topmenu','inlinemenu') {
1.320 raeburn 11772: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
11773: $changes{$itemid} = 1;
11774: }
11775: }
1.337 ! raeburn 11776: unless ($changes{$itemid}) {
! 11777: if ($domconfig{$action}{$itemid}{'passback'} eq $confhash{$itemid}{'passback'}) {
! 11778: if ($domconfig{$action}{$itemid}{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
! 11779: $changes{$itemid} = 1;
! 11780: }
! 11781: }
! 11782: }
1.326 raeburn 11783: foreach my $field ('makeuser','mapcrstype','selfenroll','instdata','lcmenu') {
1.320 raeburn 11784: unless ($changes{$itemid}) {
11785: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
11786: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
11787: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
11788: $confhash{$itemid}{$field});
11789: if (@diffs) {
11790: $changes{$itemid} = 1;
11791: }
11792: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
11793: $changes{$itemid} = 1;
11794: }
11795: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
11796: if (@{$confhash{$itemid}{$field}} > 0) {
11797: $changes{$itemid} = 1;
11798: }
11799: }
11800: }
11801: }
11802: unless ($changes{$itemid}) {
11803: if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
11804: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
11805: foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
11806: if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne
11807: $confhash{$itemid}{'maproles'}{$ltirole}) {
11808: $changes{$itemid} = 1;
11809: last;
11810: }
11811: }
11812: unless ($changes{$itemid}) {
11813: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
11814: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
11815: $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
11816: $changes{$itemid} = 1;
11817: last;
11818: }
11819: }
11820: }
11821: } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
11822: $changes{$itemid} = 1;
11823: }
11824: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
11825: unless ($changes{$itemid}) {
11826: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
11827: $changes{$itemid} = 1;
11828: }
11829: }
11830: }
11831: }
11832: }
11833: }
11834: if (@allpos > 0) {
11835: my $idx = 0;
11836: foreach my $itemid (@allpos) {
11837: if ($itemid ne '') {
11838: $confhash{$itemid}{'order'} = $idx;
11839: if (ref($domconfig{$action}) eq 'HASH') {
11840: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11841: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
11842: $changes{$itemid} = 1;
11843: }
11844: }
11845: }
11846: $idx ++;
11847: }
11848: }
11849: }
11850: my %ltihash = (
11851: $action => { %confhash }
11852: );
11853: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,
11854: $dom);
11855: if ($putresult eq 'ok') {
11856: my %ltienchash = (
11857: $action => { %encconfig }
11858: );
11859: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
11860: if (keys(%changes) > 0) {
11861: my $cachetime = 24*60*60;
11862: my %ltiall = %confhash;
11863: foreach my $id (keys(%ltiall)) {
11864: if (ref($encconfig{$id}) eq 'HASH') {
11865: foreach my $item ('key','secret') {
11866: $ltiall{$id}{$item} = $encconfig{$id}{$item};
11867: }
11868: }
11869: }
11870: &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
11871: if (ref($lastactref) eq 'HASH') {
11872: $lastactref->{'lti'} = 1;
11873: }
11874: $resulttext = &mt('Changes made:').'<ul>';
11875: my %bynum;
11876: foreach my $itemid (sort(keys(%changes))) {
11877: my $position = $confhash{$itemid}{'order'};
11878: $bynum{$position} = $itemid;
11879: }
11880: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
11881: my $itemid = $bynum{$pos};
11882: if (ref($confhash{$itemid}) ne 'HASH') {
11883: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
11884: } else {
11885: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b></li><ul>';
11886: my $position = $pos + 1;
11887: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
11888: foreach my $item ('version','lifetime') {
11889: if ($confhash{$itemid}{$item} ne '') {
11890: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
11891: }
11892: }
11893: if ($encconfig{$itemid}{'key'} ne '') {
11894: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
11895: }
11896: if ($encconfig{$itemid}{'secret'} ne '') {
11897: $resulttext .= '<li>'.$lt{'secret'}.': ';
11898: my $num = length($encconfig{$itemid}{'secret'});
11899: $resulttext .= ('*'x$num).'</li>';
11900: }
11901: if ($confhash{$itemid}{'mapuser'}) {
11902: my $shownmapuser;
11903: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
11904: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
11905: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
11906: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
11907: } else {
11908: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
11909: }
11910: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
11911: }
11912: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
11913: my $rolemaps;
11914: foreach my $role (@ltiroles) {
11915: if ($confhash{$itemid}{'maproles'}{$role}) {
11916: $rolemaps .= (' 'x2).$role.'='.
11917: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
11918: 'Course').',';
11919: }
11920: }
11921: if ($rolemaps) {
11922: $rolemaps =~ s/,$//;
11923: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
11924: }
11925: }
11926: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
11927: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
11928: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
1.325 raeburn 11929: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
11930: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
11931: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
11932: } else {
11933: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
11934: $confhash{$itemid}{'lcauth'});
11935: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
11936: $resulttext .= '; '.&mt('a randomly generated password will be created');
11937: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
11938: if ($confhash{$itemid}{'lcauthparm'} ne '') {
11939: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
11940: }
11941: } else {
11942: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
11943: }
11944: }
11945: $resulttext .= '</li>';
1.320 raeburn 11946: } else {
11947: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
11948: }
11949: }
1.325 raeburn 11950: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
11951: if (@{$confhash{$itemid}{'instdata'}} > 0) {
11952: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
11953: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
11954: } else {
11955: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
11956: }
11957: }
1.320 raeburn 11958: if ($confhash{$itemid}{'mapcrs'}) {
11959: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
11960: }
11961: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
11962: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
11963: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
11964: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
11965: '</li>';
11966: } else {
11967: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
11968: }
11969: }
11970: if ($confhash{$itemid}{'makecrs'}) {
11971: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
11972: } else {
11973: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
11974: }
11975: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
11976: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
11977: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
11978: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
11979: '</li>';
11980: } else {
11981: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
11982: }
11983: }
11984: if ($confhash{$itemid}{'section'}) {
11985: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
11986: $resulttext .= '<li>'.&mt('User section from standard field:').
11987: ' (course_section_sourcedid)'.'</li>';
11988: } else {
11989: $resulttext .= '<li>'.&mt('User section from:').' '.
11990: $confhash{$itemid}{'section'}.'</li>';
11991: }
11992: } else {
11993: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
11994: }
1.326 raeburn 11995: foreach my $item ('passback','roster','topmenu','inlinemenu') {
11996: $resulttext .= '<li>'.$lt{$item}.': ';
1.320 raeburn 11997: if ($confhash{$itemid}{$item}) {
11998: $resulttext .= &mt('Yes');
1.337 ! raeburn 11999: if ($item eq 'passback') {
! 12000: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
! 12001: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
! 12002: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
! 12003: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
! 12004: }
! 12005: }
1.320 raeburn 12006: } else {
12007: $resulttext .= &mt('No');
12008: }
12009: $resulttext .= '</li>';
12010: }
1.326 raeburn 12011: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
12012: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
12013: $resulttext .= '<li>'.&mt('Menu items:').' '.
12014: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
12015: } else {
12016: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
12017: }
12018: }
1.320 raeburn 12019: $resulttext .= '</ul></li>';
12020: }
12021: }
12022: $resulttext .= '</ul>';
12023: } else {
12024: $resulttext = &mt('No changes made.');
12025: }
12026: } else {
12027: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
12028: }
12029: if ($errors) {
12030: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12031: $errors.'</ul>';
12032: }
12033: return $resulttext;
12034: }
12035:
12036: sub get_lti_id {
12037: my ($domain,$consumer) = @_;
12038: # get lock on lti db
12039: my $lockhash = {
12040: lock => $env{'user.name'}.
12041: ':'.$env{'user.domain'},
12042: };
12043: my $tries = 0;
12044: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
12045: my ($id,$error);
12046:
12047: while (($gotlock ne 'ok') && ($tries<10)) {
12048: $tries ++;
12049: sleep (0.1);
12050: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
12051: }
12052: if ($gotlock eq 'ok') {
12053: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
12054: if ($currids{'lock'}) {
12055: delete($currids{'lock'});
12056: if (keys(%currids)) {
12057: my @curr = sort { $a <=> $b } keys(%currids);
12058: if ($curr[-1] =~ /^\d+$/) {
12059: $id = 1 + $curr[-1];
12060: }
12061: } else {
12062: $id = 1;
12063: }
12064: if ($id) {
12065: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
12066: $error = 'nostore';
12067: }
12068: } else {
12069: $error = 'nonumber';
12070: }
12071: }
12072: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
12073: } else {
12074: $error = 'nolock';
12075: }
12076: return ($id,$error);
12077: }
12078:
1.3 raeburn 12079: sub modify_autoenroll {
1.205 raeburn 12080: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 12081: my ($resulttext,%changes);
12082: my %currautoenroll;
12083: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
12084: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
12085: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
12086: }
12087: }
12088: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
12089: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 12090: sender => 'Sender for notification messages',
1.274 raeburn 12091: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
12092: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 12093: my @offon = ('off','on');
1.17 raeburn 12094: my $sender_uname = $env{'form.sender_uname'};
12095: my $sender_domain = $env{'form.sender_domain'};
12096: if ($sender_domain eq '') {
12097: $sender_uname = '';
12098: } elsif ($sender_uname eq '') {
12099: $sender_domain = '';
12100: }
1.129 raeburn 12101: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 12102: my $failsafe = $env{'form.autoenroll_failsafe'};
12103: $failsafe =~ s{^\s+|\s+$}{}g;
12104: if ($failsafe =~ /\D/) {
12105: undef($failsafe);
12106: }
1.1 raeburn 12107: my %autoenrollhash = (
1.129 raeburn 12108: autoenroll => { 'run' => $env{'form.autoenroll_run'},
12109: 'sender_uname' => $sender_uname,
12110: 'sender_domain' => $sender_domain,
12111: 'co-owners' => $coowners,
1.274 raeburn 12112: 'autofailsafe' => $failsafe,
1.1 raeburn 12113: }
12114: );
1.4 raeburn 12115: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
12116: $dom);
1.1 raeburn 12117: if ($putresult eq 'ok') {
12118: if (exists($currautoenroll{'run'})) {
12119: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
12120: $changes{'run'} = 1;
12121: }
12122: } elsif ($autorun) {
12123: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 12124: $changes{'run'} = 1;
1.1 raeburn 12125: }
12126: }
1.17 raeburn 12127: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 12128: $changes{'sender'} = 1;
12129: }
1.17 raeburn 12130: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 12131: $changes{'sender'} = 1;
12132: }
1.129 raeburn 12133: if ($currautoenroll{'co-owners'} ne '') {
12134: if ($currautoenroll{'co-owners'} ne $coowners) {
12135: $changes{'coowners'} = 1;
12136: }
12137: } elsif ($coowners) {
12138: $changes{'coowners'} = 1;
1.274 raeburn 12139: }
12140: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
12141: $changes{'autofailsafe'} = 1;
12142: }
1.1 raeburn 12143: if (keys(%changes) > 0) {
12144: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 12145: if ($changes{'run'}) {
1.1 raeburn 12146: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
12147: }
12148: if ($changes{'sender'}) {
1.17 raeburn 12149: if ($sender_uname eq '' || $sender_domain eq '') {
12150: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
12151: } else {
12152: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
12153: }
1.1 raeburn 12154: }
1.129 raeburn 12155: if ($changes{'coowners'}) {
12156: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
12157: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12158: if (ref($lastactref) eq 'HASH') {
12159: $lastactref->{'domainconfig'} = 1;
12160: }
1.129 raeburn 12161: }
1.274 raeburn 12162: if ($changes{'autofailsafe'}) {
12163: if ($failsafe ne '') {
1.299 raeburn 12164: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274 raeburn 12165: } else {
1.299 raeburn 12166: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274 raeburn 12167: }
12168: &Apache::lonnet::get_domain_defaults($dom,1);
12169: if (ref($lastactref) eq 'HASH') {
12170: $lastactref->{'domdefaults'} = 1;
12171: }
12172: }
1.1 raeburn 12173: $resulttext .= '</ul>';
12174: } else {
12175: $resulttext = &mt('No changes made to auto-enrollment settings');
12176: }
12177: } else {
1.11 albertel 12178: $resulttext = '<span class="LC_error">'.
12179: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12180: }
1.3 raeburn 12181: return $resulttext;
1.1 raeburn 12182: }
12183:
12184: sub modify_autoupdate {
1.3 raeburn 12185: my ($dom,%domconfig) = @_;
1.1 raeburn 12186: my ($resulttext,%currautoupdate,%fields,%changes);
12187: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
12188: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
12189: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
12190: }
12191: }
12192: my @offon = ('off','on');
12193: my %title = &Apache::lonlocal::texthash (
12194: run => 'Auto-update:',
12195: classlists => 'Updates to user information in classlists?'
12196: );
1.44 raeburn 12197: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 12198: my %fieldtitles = &Apache::lonlocal::texthash (
12199: id => 'Student/Employee ID',
1.20 raeburn 12200: permanentemail => 'E-mail address',
1.1 raeburn 12201: lastname => 'Last Name',
12202: firstname => 'First Name',
12203: middlename => 'Middle Name',
1.132 raeburn 12204: generation => 'Generation',
1.1 raeburn 12205: );
1.142 raeburn 12206: $othertitle = &mt('All users');
1.1 raeburn 12207: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 12208: $othertitle = &mt('Other users');
1.1 raeburn 12209: }
12210: foreach my $key (keys(%env)) {
12211: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 12212: my ($usertype,$item) = ($1,$2);
12213: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
12214: if ($usertype eq 'default') {
12215: push(@{$fields{$1}},$2);
12216: } elsif (ref($types) eq 'ARRAY') {
12217: if (grep(/^\Q$usertype\E$/,@{$types})) {
12218: push(@{$fields{$1}},$2);
12219: }
12220: }
12221: }
1.1 raeburn 12222: }
12223: }
1.131 raeburn 12224: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
12225: @lockablenames = sort(@lockablenames);
12226: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
12227: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
12228: if (@changed) {
12229: $changes{'lockablenames'} = 1;
12230: }
12231: } else {
12232: if (@lockablenames) {
12233: $changes{'lockablenames'} = 1;
12234: }
12235: }
1.1 raeburn 12236: my %updatehash = (
12237: autoupdate => { run => $env{'form.autoupdate_run'},
12238: classlists => $env{'form.classlists'},
12239: fields => {%fields},
1.131 raeburn 12240: lockablenames => \@lockablenames,
1.1 raeburn 12241: }
12242: );
12243: foreach my $key (keys(%currautoupdate)) {
12244: if (($key eq 'run') || ($key eq 'classlists')) {
12245: if (exists($updatehash{autoupdate}{$key})) {
12246: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
12247: $changes{$key} = 1;
12248: }
12249: }
12250: } elsif ($key eq 'fields') {
12251: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 12252: foreach my $item (@{$types},'default') {
1.1 raeburn 12253: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
12254: my $change = 0;
12255: foreach my $type (@{$currautoupdate{$key}{$item}}) {
12256: if (!exists($fields{$item})) {
12257: $change = 1;
1.132 raeburn 12258: last;
1.1 raeburn 12259: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 12260: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 12261: $change = 1;
1.132 raeburn 12262: last;
1.1 raeburn 12263: }
12264: }
12265: }
12266: if ($change) {
12267: push(@{$changes{$key}},$item);
12268: }
1.26 raeburn 12269: }
1.1 raeburn 12270: }
12271: }
1.131 raeburn 12272: } elsif ($key eq 'lockablenames') {
12273: if (ref($currautoupdate{$key}) eq 'ARRAY') {
12274: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
12275: if (@changed) {
12276: $changes{'lockablenames'} = 1;
12277: }
12278: } else {
12279: if (@lockablenames) {
12280: $changes{'lockablenames'} = 1;
12281: }
12282: }
12283: }
12284: }
12285: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
12286: if (@lockablenames) {
12287: $changes{'lockablenames'} = 1;
1.1 raeburn 12288: }
12289: }
1.26 raeburn 12290: foreach my $item (@{$types},'default') {
12291: if (defined($fields{$item})) {
12292: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 12293: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
12294: my $change = 0;
12295: if (ref($fields{$item}) eq 'ARRAY') {
12296: foreach my $type (@{$fields{$item}}) {
12297: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
12298: $change = 1;
12299: last;
12300: }
12301: }
12302: }
12303: if ($change) {
12304: push(@{$changes{'fields'}},$item);
12305: }
12306: } else {
1.26 raeburn 12307: push(@{$changes{'fields'}},$item);
12308: }
12309: } else {
12310: push(@{$changes{'fields'}},$item);
1.1 raeburn 12311: }
12312: }
12313: }
12314: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
12315: $dom);
12316: if ($putresult eq 'ok') {
12317: if (keys(%changes) > 0) {
12318: $resulttext = &mt('Changes made:').'<ul>';
12319: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 12320: if ($key eq 'lockablenames') {
12321: $resulttext .= '<li>';
12322: if (@lockablenames) {
12323: $usertypes->{'default'} = $othertitle;
12324: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
12325: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
12326: } else {
12327: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
12328: }
12329: $resulttext .= '</li>';
12330: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 12331: foreach my $item (@{$changes{$key}}) {
12332: my @newvalues;
12333: foreach my $type (@{$fields{$item}}) {
12334: push(@newvalues,$fieldtitles{$type});
12335: }
1.3 raeburn 12336: my $newvaluestr;
12337: if (@newvalues > 0) {
12338: $newvaluestr = join(', ',@newvalues);
12339: } else {
12340: $newvaluestr = &mt('none');
1.6 raeburn 12341: }
1.1 raeburn 12342: if ($item eq 'default') {
1.26 raeburn 12343: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 12344: } else {
1.26 raeburn 12345: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 12346: }
12347: }
12348: } else {
12349: my $newvalue;
12350: if ($key eq 'run') {
12351: $newvalue = $offon[$env{'form.autoupdate_run'}];
12352: } else {
12353: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 12354: }
1.1 raeburn 12355: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
12356: }
12357: }
12358: $resulttext .= '</ul>';
12359: } else {
1.3 raeburn 12360: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 12361: }
12362: } else {
1.11 albertel 12363: $resulttext = '<span class="LC_error">'.
12364: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12365: }
1.3 raeburn 12366: return $resulttext;
1.1 raeburn 12367: }
12368:
1.125 raeburn 12369: sub modify_autocreate {
12370: my ($dom,%domconfig) = @_;
12371: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
12372: if (ref($domconfig{'autocreate'}) eq 'HASH') {
12373: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
12374: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
12375: }
12376: }
12377: my %title= ( xml => 'Auto-creation of courses in XML course description files',
12378: req => 'Auto-creation of validated requests for official courses',
12379: xmldc => 'Identity of course creator of courses from XML files',
12380: );
12381: my @types = ('xml','req');
12382: foreach my $item (@types) {
12383: $newvals{$item} = $env{'form.autocreate_'.$item};
12384: $newvals{$item} =~ s/\D//g;
12385: $newvals{$item} = 0 if ($newvals{$item} eq '');
12386: }
12387: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 12388: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 12389: unless (exists($domcoords{$newvals{'xmldc'}})) {
12390: $newvals{'xmldc'} = '';
12391: }
12392: %autocreatehash = (
12393: autocreate => { xml => $newvals{'xml'},
12394: req => $newvals{'req'},
12395: }
12396: );
12397: if ($newvals{'xmldc'} ne '') {
12398: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
12399: }
12400: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
12401: $dom);
12402: if ($putresult eq 'ok') {
12403: my @items = @types;
12404: if ($newvals{'xml'}) {
12405: push(@items,'xmldc');
12406: }
12407: foreach my $item (@items) {
12408: if (exists($currautocreate{$item})) {
12409: if ($currautocreate{$item} ne $newvals{$item}) {
12410: $changes{$item} = 1;
12411: }
12412: } elsif ($newvals{$item}) {
12413: $changes{$item} = 1;
12414: }
12415: }
12416: if (keys(%changes) > 0) {
12417: my @offon = ('off','on');
12418: $resulttext = &mt('Changes made:').'<ul>';
12419: foreach my $item (@types) {
12420: if ($changes{$item}) {
12421: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 12422: $resulttext .= '<li>'.
12423: &mt("$title{$item} set to [_1]$newtxt [_2]",
12424: '<b>','</b>').
12425: '</li>';
1.125 raeburn 12426: }
12427: }
12428: if ($changes{'xmldc'}) {
12429: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
12430: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 12431: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 12432: }
12433: $resulttext .= '</ul>';
12434: } else {
12435: $resulttext = &mt('No changes made to auto-creation settings');
12436: }
12437: } else {
12438: $resulttext = '<span class="LC_error">'.
12439: &mt('An error occurred: [_1]',$putresult).'</span>';
12440: }
12441: return $resulttext;
12442: }
12443:
1.23 raeburn 12444: sub modify_directorysrch {
1.295 raeburn 12445: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 12446: my ($resulttext,%changes);
12447: my %currdirsrch;
12448: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
12449: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
12450: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
12451: }
12452: }
1.277 raeburn 12453: my %title = ( available => 'Institutional directory search available',
12454: localonly => 'Other domains can search institution',
12455: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 12456: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 12457: searchby => 'Search types',
12458: searchtypes => 'Search latitude');
12459: my @offon = ('off','on');
1.24 raeburn 12460: my @otherdoms = ('Yes','No');
1.23 raeburn 12461:
1.25 raeburn 12462: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 12463: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
12464: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
12465:
1.44 raeburn 12466: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 12467: if (keys(%{$usertypes}) == 0) {
12468: @cansearch = ('default');
12469: } else {
12470: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
12471: foreach my $type (@{$currdirsrch{'cansearch'}}) {
12472: if (!grep(/^\Q$type\E$/,@cansearch)) {
12473: push(@{$changes{'cansearch'}},$type);
12474: }
1.23 raeburn 12475: }
1.26 raeburn 12476: foreach my $type (@cansearch) {
12477: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
12478: push(@{$changes{'cansearch'}},$type);
12479: }
1.23 raeburn 12480: }
1.26 raeburn 12481: } else {
12482: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 12483: }
12484: }
12485:
12486: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
12487: foreach my $by (@{$currdirsrch{'searchby'}}) {
12488: if (!grep(/^\Q$by\E$/,@searchby)) {
12489: push(@{$changes{'searchby'}},$by);
12490: }
12491: }
12492: foreach my $by (@searchby) {
12493: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
12494: push(@{$changes{'searchby'}},$by);
12495: }
12496: }
12497: } else {
12498: push(@{$changes{'searchby'}},@searchby);
12499: }
1.25 raeburn 12500:
12501: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
12502: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
12503: if (!grep(/^\Q$type\E$/,@searchtypes)) {
12504: push(@{$changes{'searchtypes'}},$type);
12505: }
12506: }
12507: foreach my $type (@searchtypes) {
12508: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
12509: push(@{$changes{'searchtypes'}},$type);
12510: }
12511: }
12512: } else {
12513: if (exists($currdirsrch{'searchtypes'})) {
12514: foreach my $type (@searchtypes) {
12515: if ($type ne $currdirsrch{'searchtypes'}) {
12516: push(@{$changes{'searchtypes'}},$type);
12517: }
12518: }
12519: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
12520: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
12521: }
12522: } else {
12523: push(@{$changes{'searchtypes'}},@searchtypes);
12524: }
12525: }
12526:
1.23 raeburn 12527: my %dirsrch_hash = (
12528: directorysrch => { available => $env{'form.dirsrch_available'},
12529: cansearch => \@cansearch,
1.277 raeburn 12530: localonly => $env{'form.dirsrch_instlocalonly'},
12531: lclocalonly => $env{'form.dirsrch_domlocalonly'},
12532: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 12533: searchby => \@searchby,
1.25 raeburn 12534: searchtypes => \@searchtypes,
1.23 raeburn 12535: }
12536: );
12537: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
12538: $dom);
12539: if ($putresult eq 'ok') {
12540: if (exists($currdirsrch{'available'})) {
12541: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
12542: $changes{'available'} = 1;
12543: }
12544: } else {
12545: if ($env{'form.dirsrch_available'} eq '1') {
12546: $changes{'available'} = 1;
12547: }
12548: }
1.277 raeburn 12549: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 12550: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
12551: $changes{'lcavailable'} = 1;
12552: }
1.277 raeburn 12553: } else {
12554: if ($env{'form.dirsrch_lcavailable'} eq '1') {
12555: $changes{'lcavailable'} = 1;
12556: }
12557: }
1.24 raeburn 12558: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 12559: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
12560: $changes{'localonly'} = 1;
12561: }
1.24 raeburn 12562: } else {
1.277 raeburn 12563: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 12564: $changes{'localonly'} = 1;
12565: }
12566: }
1.277 raeburn 12567: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 12568: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
12569: $changes{'lclocalonly'} = 1;
12570: }
1.277 raeburn 12571: } else {
12572: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
12573: $changes{'lclocalonly'} = 1;
12574: }
12575: }
1.23 raeburn 12576: if (keys(%changes) > 0) {
12577: $resulttext = &mt('Changes made:').'<ul>';
12578: if ($changes{'available'}) {
12579: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
12580: }
1.277 raeburn 12581: if ($changes{'lcavailable'}) {
12582: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
12583: }
1.24 raeburn 12584: if ($changes{'localonly'}) {
1.277 raeburn 12585: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 12586: }
1.277 raeburn 12587: if ($changes{'lclocalonly'}) {
12588: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 12589: }
1.23 raeburn 12590: if (ref($changes{'cansearch'}) eq 'ARRAY') {
12591: my $chgtext;
1.26 raeburn 12592: if (ref($usertypes) eq 'HASH') {
12593: if (keys(%{$usertypes}) > 0) {
12594: foreach my $type (@{$types}) {
12595: if (grep(/^\Q$type\E$/,@cansearch)) {
12596: $chgtext .= $usertypes->{$type}.'; ';
12597: }
12598: }
12599: if (grep(/^default$/,@cansearch)) {
12600: $chgtext .= $othertitle;
12601: } else {
12602: $chgtext =~ s/\; $//;
12603: }
1.210 raeburn 12604: $resulttext .=
1.178 raeburn 12605: '<li>'.
12606: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
12607: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
12608: '</li>';
1.23 raeburn 12609: }
12610: }
12611: }
12612: if (ref($changes{'searchby'}) eq 'ARRAY') {
12613: my ($searchtitles,$titleorder) = &sorted_searchtitles();
12614: my $chgtext;
12615: foreach my $type (@{$titleorder}) {
12616: if (grep(/^\Q$type\E$/,@searchby)) {
12617: if (defined($searchtitles->{$type})) {
12618: $chgtext .= $searchtitles->{$type}.'; ';
12619: }
12620: }
12621: }
12622: $chgtext =~ s/\; $//;
12623: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
12624: }
1.25 raeburn 12625: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
12626: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
12627: my $chgtext;
12628: foreach my $type (@{$srchtypeorder}) {
12629: if (grep(/^\Q$type\E$/,@searchtypes)) {
12630: if (defined($srchtypes_desc->{$type})) {
12631: $chgtext .= $srchtypes_desc->{$type}.'; ';
12632: }
12633: }
12634: }
12635: $chgtext =~ s/\; $//;
1.178 raeburn 12636: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 12637: }
12638: $resulttext .= '</ul>';
1.295 raeburn 12639: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
12640: if (ref($lastactref) eq 'HASH') {
12641: $lastactref->{'directorysrch'} = 1;
12642: }
1.23 raeburn 12643: } else {
1.277 raeburn 12644: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 12645: }
12646: } else {
12647: $resulttext = '<span class="LC_error">'.
1.27 raeburn 12648: &mt('An error occurred: [_1]',$putresult).'</span>';
12649: }
12650: return $resulttext;
12651: }
12652:
1.28 raeburn 12653: sub modify_contacts {
1.205 raeburn 12654: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 12655: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
12656: if (ref($domconfig{'contacts'}) eq 'HASH') {
12657: foreach my $key (keys(%{$domconfig{'contacts'}})) {
12658: $currsetting{$key} = $domconfig{'contacts'}{$key};
12659: }
12660: }
1.286 raeburn 12661: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 12662: my @contacts = ('supportemail','adminemail');
1.286 raeburn 12663: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
12664: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.203 raeburn 12665: my @toggles = ('reporterrors','reportupdates');
1.286 raeburn 12666: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 12667: foreach my $type (@mailings) {
12668: @{$newsetting{$type}} =
12669: &Apache::loncommon::get_env_multiple('form.'.$type);
12670: foreach my $item (@contacts) {
12671: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
12672: $contacts_hash{contacts}{$type}{$item} = 1;
12673: } else {
12674: $contacts_hash{contacts}{$type}{$item} = 0;
12675: }
1.289 raeburn 12676: }
1.28 raeburn 12677: $others{$type} = $env{'form.'.$type.'_others'};
12678: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 12679: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12680: $bcc{$type} = $env{'form.'.$type.'_bcc'};
12681: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 12682: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
12683: $includestr{$type} = $env{'form.'.$type.'_includestr'};
12684: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
12685: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
12686: }
1.134 raeburn 12687: }
1.28 raeburn 12688: }
12689: foreach my $item (@contacts) {
12690: $to{$item} = $env{'form.'.$item};
12691: $contacts_hash{'contacts'}{$item} = $to{$item};
12692: }
1.203 raeburn 12693: foreach my $item (@toggles) {
12694: if ($env{'form.'.$item} =~ /^(0|1)$/) {
12695: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
12696: }
12697: }
1.286 raeburn 12698: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
12699: foreach my $field (@{$fields}) {
12700: if (ref($possoptions->{$field}) eq 'ARRAY') {
12701: my $value = $env{'form.helpform_'.$field};
12702: $value =~ s/^\s+|\s+$//g;
12703: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 12704: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 12705: if ($field eq 'screenshot') {
12706: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
12707: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 12708: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 12709: }
12710: }
12711: }
12712: }
12713: }
12714: }
1.315 raeburn 12715: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12716: my (@statuses,%usertypeshash,@overrides);
12717: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
12718: @statuses = @{$types};
12719: if (ref($usertypes) eq 'HASH') {
12720: %usertypeshash = %{$usertypes};
12721: }
12722: }
12723: if (@statuses) {
12724: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
12725: foreach my $type (@possoverrides) {
12726: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
12727: push(@overrides,$type);
12728: }
12729: }
12730: if (@overrides) {
12731: foreach my $type (@overrides) {
12732: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
12733: foreach my $item (@contacts) {
12734: if (grep(/^\Q$item\E$/,@standard)) {
12735: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
12736: $newsetting{'override_'.$type}{$item} = 1;
12737: } else {
12738: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
12739: $newsetting{'override_'.$type}{$item} = 0;
12740: }
12741: }
12742: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
12743: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
12744: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
12745: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
12746: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
12747: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
12748: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
12749: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
12750: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
12751: }
12752: }
12753: }
12754: }
1.28 raeburn 12755: if (keys(%currsetting) > 0) {
12756: foreach my $item (@contacts) {
12757: if ($to{$item} ne $currsetting{$item}) {
12758: $changes{$item} = 1;
12759: }
12760: }
12761: foreach my $type (@mailings) {
12762: foreach my $item (@contacts) {
12763: if (ref($currsetting{$type}) eq 'HASH') {
12764: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
12765: push(@{$changes{$type}},$item);
12766: }
12767: } else {
12768: push(@{$changes{$type}},@{$newsetting{$type}});
12769: }
12770: }
12771: if ($others{$type} ne $currsetting{$type}{'others'}) {
12772: push(@{$changes{$type}},'others');
12773: }
1.289 raeburn 12774: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12775: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
12776: push(@{$changes{$type}},'bcc');
12777: }
1.286 raeburn 12778: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
12779: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
12780: push(@{$changes{$type}},'include');
12781: }
12782: }
12783: }
12784: if (ref($fields) eq 'ARRAY') {
12785: if (ref($currsetting{'helpform'}) eq 'HASH') {
12786: foreach my $field (@{$fields}) {
12787: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
12788: push(@{$changes{'helpform'}},$field);
12789: }
12790: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12791: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
12792: push(@{$changes{'helpform'}},'maxsize');
12793: }
12794: }
12795: }
12796: } else {
12797: foreach my $field (@{$fields}) {
12798: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12799: push(@{$changes{'helpform'}},$field);
12800: }
12801: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12802: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12803: push(@{$changes{'helpform'}},'maxsize');
12804: }
12805: }
12806: }
1.134 raeburn 12807: }
1.28 raeburn 12808: }
1.315 raeburn 12809: if (@statuses) {
12810: if (ref($currsetting{'overrides'}) eq 'HASH') {
12811: foreach my $key (keys(%{$currsetting{'overrides'}})) {
12812: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
12813: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
12814: foreach my $item (@contacts,'bcc','others','include') {
12815: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
12816: push(@{$changes{'overrides'}},$key);
12817: last;
12818: }
12819: }
12820: } else {
12821: push(@{$changes{'overrides'}},$key);
12822: }
12823: }
12824: }
12825: foreach my $key (@overrides) {
12826: unless (exists($currsetting{'overrides'}{$key})) {
12827: push(@{$changes{'overrides'}},$key);
12828: }
12829: }
12830: } else {
12831: foreach my $key (@overrides) {
12832: push(@{$changes{'overrides'}},$key);
12833: }
12834: }
12835: }
1.28 raeburn 12836: } else {
12837: my %default;
12838: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
12839: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
12840: $default{'errormail'} = 'adminemail';
12841: $default{'packagesmail'} = 'adminemail';
12842: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 12843: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 12844: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 12845: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 12846: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 12847: foreach my $item (@contacts) {
12848: if ($to{$item} ne $default{$item}) {
1.286 raeburn 12849: $changes{$item} = 1;
1.203 raeburn 12850: }
1.28 raeburn 12851: }
12852: foreach my $type (@mailings) {
12853: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
12854: push(@{$changes{$type}},@{$newsetting{$type}});
12855: }
12856: if ($others{$type} ne '') {
12857: push(@{$changes{$type}},'others');
1.134 raeburn 12858: }
1.286 raeburn 12859: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12860: if ($bcc{$type} ne '') {
12861: push(@{$changes{$type}},'bcc');
12862: }
1.286 raeburn 12863: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
12864: push(@{$changes{$type}},'include');
12865: }
1.134 raeburn 12866: }
1.28 raeburn 12867: }
1.286 raeburn 12868: if (ref($fields) eq 'ARRAY') {
12869: foreach my $field (@{$fields}) {
12870: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12871: push(@{$changes{'helpform'}},$field);
12872: }
12873: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12874: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12875: push(@{$changes{'helpform'}},'maxsize');
12876: }
12877: }
12878: }
1.289 raeburn 12879: }
1.28 raeburn 12880: }
1.203 raeburn 12881: foreach my $item (@toggles) {
12882: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
12883: $changes{$item} = 1;
12884: } elsif ((!$env{'form.'.$item}) &&
12885: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
12886: $changes{$item} = 1;
12887: }
12888: }
1.28 raeburn 12889: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
12890: $dom);
12891: if ($putresult eq 'ok') {
12892: if (keys(%changes) > 0) {
1.205 raeburn 12893: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12894: if (ref($lastactref) eq 'HASH') {
12895: $lastactref->{'domainconfig'} = 1;
12896: }
1.28 raeburn 12897: my ($titles,$short_titles) = &contact_titles();
12898: $resulttext = &mt('Changes made:').'<ul>';
12899: foreach my $item (@contacts) {
12900: if ($changes{$item}) {
12901: $resulttext .= '<li>'.$titles->{$item}.
12902: &mt(' set to: ').
12903: '<span class="LC_cusr_emph">'.
12904: $to{$item}.'</span></li>';
12905: }
12906: }
12907: foreach my $type (@mailings) {
12908: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 12909: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 12910: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 12911: } else {
12912: $resulttext .= '<li>'.$titles->{$type}.': ';
12913: }
1.28 raeburn 12914: my @text;
12915: foreach my $item (@{$newsetting{$type}}) {
12916: push(@text,$short_titles->{$item});
12917: }
12918: if ($others{$type} ne '') {
12919: push(@text,$others{$type});
12920: }
1.286 raeburn 12921: if (@text) {
12922: $resulttext .= '<span class="LC_cusr_emph">'.
12923: join(', ',@text).'</span>';
12924: }
12925: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12926: if ($bcc{$type} ne '') {
1.286 raeburn 12927: my $bcctext;
12928: if (@text) {
1.289 raeburn 12929: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 12930: } else {
12931: $bcctext = '(Bcc)';
12932: }
12933: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
12934: } elsif (!@text) {
12935: $resulttext .= &mt('No one');
12936: }
1.289 raeburn 12937: if ($includestr{$type} ne '') {
1.286 raeburn 12938: if ($includeloc{$type} eq 'b') {
12939: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
12940: } elsif ($includeloc{$type} eq 's') {
12941: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
12942: }
1.134 raeburn 12943: }
1.286 raeburn 12944: } elsif (!@text) {
12945: $resulttext .= &mt('No recipients');
1.134 raeburn 12946: }
12947: $resulttext .= '</li>';
1.28 raeburn 12948: }
12949: }
1.315 raeburn 12950: if (ref($changes{'overrides'}) eq 'ARRAY') {
12951: my @deletions;
12952: foreach my $type (@{$changes{'overrides'}}) {
12953: if ($usertypeshash{$type}) {
12954: if (grep(/^\Q$type\E/,@overrides)) {
12955: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
12956: $usertypeshash{$type}).'<ul><li>';
12957: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
12958: my @text;
12959: foreach my $item (@contacts) {
12960: if ($newsetting{'override_'.$type}{$item}) {
12961: push(@text,$short_titles->{$item});
12962: }
12963: }
12964: if ($newsetting{'override_'.$type}{'others'} ne '') {
12965: push(@text,$newsetting{'override_'.$type}{'others'});
12966: }
12967:
12968: if (@text) {
12969: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
12970: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
12971: }
12972: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
12973: my $bcctext;
12974: if (@text) {
12975: $bcctext = ' '.&mt('with Bcc to');
12976: } else {
12977: $bcctext = '(Bcc)';
12978: }
12979: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
12980: } elsif (!@text) {
12981: $resulttext .= &mt('Helpdesk e-mail sent to no one');
12982: }
12983: $resulttext .= '</li>';
12984: if ($newsetting{'override_'.$type}{'include'} ne '') {
12985: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
12986: if ($loc eq 'b') {
12987: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
12988: } elsif ($loc eq 's') {
12989: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
12990: }
12991: }
12992: }
12993: $resulttext .= '</li></ul></li>';
12994: } else {
12995: push(@deletions,$usertypeshash{$type});
12996: }
12997: }
12998: }
12999: if (@deletions) {
13000: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
13001: join(', ',@deletions)).'</li>';
13002: }
13003: }
1.203 raeburn 13004: my @offon = ('off','on');
13005: if ($changes{'reporterrors'}) {
13006: $resulttext .= '<li>'.
13007: &mt('E-mail error reports to [_1] set to "'.
13008: $offon[$env{'form.reporterrors'}].'".',
13009: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
13010: &mt('LON-CAPA core group - MSU'),600,500)).
13011: '</li>';
13012: }
13013: if ($changes{'reportupdates'}) {
13014: $resulttext .= '<li>'.
13015: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
13016: $offon[$env{'form.reportupdates'}].'".',
13017: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
13018: &mt('LON-CAPA core group - MSU'),600,500)).
13019: '</li>';
13020: }
1.286 raeburn 13021: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
13022: my (@optional,@required,@unused,$maxsizechg);
13023: foreach my $field (@{$changes{'helpform'}}) {
13024: if ($field eq 'maxsize') {
13025: $maxsizechg = 1;
13026: next;
13027: }
13028: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 13029: push(@optional,$field);
1.286 raeburn 13030: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
13031: push(@unused,$field);
13032: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 13033: push(@required,$field);
1.286 raeburn 13034: }
13035: }
13036: if (@optional) {
13037: $resulttext .= '<li>'.
13038: &mt('Help form fields changed to "Optional": [_1].',
13039: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
13040: '</li>';
13041: }
13042: if (@required) {
13043: $resulttext .= '<li>'.
13044: &mt('Help form fields changed to "Required": [_1].',
13045: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
13046: '</li>';
13047: }
13048: if (@unused) {
13049: $resulttext .= '<li>'.
13050: &mt('Help form fields changed to "Not shown": [_1].',
13051: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
13052: '</li>';
13053: }
13054: if ($maxsizechg) {
13055: $resulttext .= '<li>'.
13056: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
13057: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
13058: '</li>';
13059: }
13060: }
1.28 raeburn 13061: $resulttext .= '</ul>';
13062: } else {
1.288 raeburn 13063: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 13064: }
13065: } else {
13066: $resulttext = '<span class="LC_error">'.
13067: &mt('An error occurred: [_1].',$putresult).'</span>';
13068: }
13069: return $resulttext;
13070: }
13071:
13072: sub modify_usercreation {
1.27 raeburn 13073: my ($dom,%domconfig) = @_;
1.224 raeburn 13074: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 13075: my $warningmsg;
1.27 raeburn 13076: if (ref($domconfig{'usercreation'}) eq 'HASH') {
13077: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 13078: if ($key eq 'cancreate') {
13079: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
13080: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 13081: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
13082: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13083: } else {
1.224 raeburn 13084: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13085: }
13086: }
13087: }
13088: } elsif ($key eq 'email_rule') {
13089: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
13090: } else {
13091: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
13092: }
1.27 raeburn 13093: }
13094: }
13095: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 13096: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 13097: my @contexts = ('author','course','requestcrs');
1.34 raeburn 13098: foreach my $item(@contexts) {
1.224 raeburn 13099: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 13100: }
1.34 raeburn 13101: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13102: foreach my $item (@contexts) {
1.224 raeburn 13103: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
13104: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 13105: }
1.27 raeburn 13106: }
1.34 raeburn 13107: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
13108: foreach my $item (@contexts) {
1.43 raeburn 13109: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 13110: if ($cancreate{$item} ne 'any') {
13111: push(@{$changes{'cancreate'}},$item);
13112: }
13113: } else {
13114: if ($cancreate{$item} ne 'none') {
13115: push(@{$changes{'cancreate'}},$item);
13116: }
1.27 raeburn 13117: }
13118: }
13119: } else {
1.43 raeburn 13120: foreach my $item (@contexts) {
1.34 raeburn 13121: push(@{$changes{'cancreate'}},$item);
13122: }
1.27 raeburn 13123: }
1.34 raeburn 13124:
1.27 raeburn 13125: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
13126: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
13127: if (!grep(/^\Q$type\E$/,@username_rule)) {
13128: push(@{$changes{'username_rule'}},$type);
13129: }
13130: }
13131: foreach my $type (@username_rule) {
13132: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
13133: push(@{$changes{'username_rule'}},$type);
13134: }
13135: }
13136: } else {
13137: push(@{$changes{'username_rule'}},@username_rule);
13138: }
13139:
1.32 raeburn 13140: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
13141: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
13142: if (!grep(/^\Q$type\E$/,@id_rule)) {
13143: push(@{$changes{'id_rule'}},$type);
13144: }
13145: }
13146: foreach my $type (@id_rule) {
13147: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
13148: push(@{$changes{'id_rule'}},$type);
13149: }
13150: }
13151: } else {
13152: push(@{$changes{'id_rule'}},@id_rule);
13153: }
13154:
1.43 raeburn 13155: my @authen_contexts = ('author','course','domain');
1.325 raeburn 13156: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 13157: my %authhash;
1.43 raeburn 13158: foreach my $item (@authen_contexts) {
1.28 raeburn 13159: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
13160: foreach my $auth (@authtypes) {
13161: if (grep(/^\Q$auth\E$/,@authallowed)) {
13162: $authhash{$item}{$auth} = 1;
13163: } else {
13164: $authhash{$item}{$auth} = 0;
13165: }
13166: }
13167: }
13168: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 13169: foreach my $item (@authen_contexts) {
1.28 raeburn 13170: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
13171: foreach my $auth (@authtypes) {
13172: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
13173: push(@{$changes{'authtypes'}},$item);
13174: last;
13175: }
13176: }
13177: }
13178: }
13179: } else {
1.43 raeburn 13180: foreach my $item (@authen_contexts) {
1.28 raeburn 13181: push(@{$changes{'authtypes'}},$item);
13182: }
13183: }
13184:
1.224 raeburn 13185: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
13186: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
13187: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
13188: $save_usercreate{'id_rule'} = \@id_rule;
13189: $save_usercreate{'username_rule'} = \@username_rule,
13190: $save_usercreate{'authtypes'} = \%authhash;
13191:
1.27 raeburn 13192: my %usercreation_hash = (
1.224 raeburn 13193: usercreation => \%save_usercreate,
13194: );
1.27 raeburn 13195:
13196: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
13197: $dom);
1.50 raeburn 13198:
1.224 raeburn 13199: if ($putresult eq 'ok') {
13200: if (keys(%changes) > 0) {
13201: $resulttext = &mt('Changes made:').'<ul>';
13202: if (ref($changes{'cancreate'}) eq 'ARRAY') {
13203: my %lt = &usercreation_types();
13204: foreach my $type (@{$changes{'cancreate'}}) {
13205: my $chgtext = $lt{$type}.', ';
13206: if ($cancreate{$type} eq 'none') {
13207: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
13208: } elsif ($cancreate{$type} eq 'any') {
13209: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
13210: } elsif ($cancreate{$type} eq 'official') {
13211: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
13212: } elsif ($cancreate{$type} eq 'unofficial') {
13213: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
13214: }
13215: $resulttext .= '<li>'.$chgtext.'</li>';
13216: }
13217: }
13218: if (ref($changes{'username_rule'}) eq 'ARRAY') {
13219: my ($rules,$ruleorder) =
13220: &Apache::lonnet::inst_userrules($dom,'username');
13221: my $chgtext = '<ul>';
13222: foreach my $type (@username_rule) {
13223: if (ref($rules->{$type}) eq 'HASH') {
13224: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
13225: }
13226: }
13227: $chgtext .= '</ul>';
13228: if (@username_rule > 0) {
13229: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13230: } else {
13231: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
13232: }
13233: }
13234: if (ref($changes{'id_rule'}) eq 'ARRAY') {
13235: my ($idrules,$idruleorder) =
13236: &Apache::lonnet::inst_userrules($dom,'id');
13237: my $chgtext = '<ul>';
13238: foreach my $type (@id_rule) {
13239: if (ref($idrules->{$type}) eq 'HASH') {
13240: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
13241: }
13242: }
13243: $chgtext .= '</ul>';
13244: if (@id_rule > 0) {
13245: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13246: } else {
13247: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
13248: }
13249: }
13250: my %authname = &authtype_names();
13251: my %context_title = &context_names();
13252: if (ref($changes{'authtypes'}) eq 'ARRAY') {
13253: my $chgtext = '<ul>';
13254: foreach my $type (@{$changes{'authtypes'}}) {
13255: my @allowed;
13256: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
13257: foreach my $auth (@authtypes) {
13258: if ($authhash{$type}{$auth}) {
13259: push(@allowed,$authname{$auth});
13260: }
13261: }
13262: if (@allowed > 0) {
13263: $chgtext .= join(', ',@allowed).'</li>';
13264: } else {
13265: $chgtext .= &mt('none').'</li>';
13266: }
13267: }
13268: $chgtext .= '</ul>';
13269: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
13270: $resulttext .= '</li>';
13271: }
13272: $resulttext .= '</ul>';
13273: } else {
13274: $resulttext = &mt('No changes made to user creation settings');
13275: }
13276: } else {
13277: $resulttext = '<span class="LC_error">'.
13278: &mt('An error occurred: [_1]',$putresult).'</span>';
13279: }
13280: if ($warningmsg ne '') {
13281: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
13282: }
13283: return $resulttext;
13284: }
13285:
13286: sub modify_selfcreation {
1.305 raeburn 13287: my ($dom,$lastactref,%domconfig) = @_;
13288: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
13289: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
13290: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 13291: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
13292: if (ref($typesref) eq 'ARRAY') {
13293: @types = @{$typesref};
13294: }
13295: if (ref($usertypesref) eq 'HASH') {
13296: %usertypes = %{$usertypesref};
1.228 raeburn 13297: }
1.303 raeburn 13298: $usertypes{'default'} = $othertitle;
1.224 raeburn 13299: #
13300: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
13301: #
13302: if (ref($domconfig{'usercreation'}) eq 'HASH') {
13303: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
13304: if ($key eq 'cancreate') {
13305: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
13306: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
13307: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 13308: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
13309: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
13310: ($item eq 'emailusername') || ($item eq 'shibenv') ||
13311: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 13312: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 13313: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13314: } else {
13315: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13316: }
13317: }
13318: }
13319: } elsif ($key eq 'email_rule') {
13320: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
13321: } else {
13322: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
13323: }
13324: }
13325: }
13326: #
13327: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
13328: #
13329: if (ref($domconfig{'usermodification'}) eq 'HASH') {
13330: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
13331: if ($key eq 'selfcreate') {
13332: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
13333: } else {
13334: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
13335: }
13336: }
13337: }
1.305 raeburn 13338: #
13339: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
13340: #
13341: if (ref($domconfig{'inststatus'}) eq 'HASH') {
13342: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
13343: if ($key eq 'inststatusguest') {
13344: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
13345: } else {
13346: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
13347: }
13348: }
13349: }
1.224 raeburn 13350:
13351: my @contexts = ('selfcreate');
13352: @{$cancreate{'selfcreate'}} = ();
13353: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 13354: if (@types) {
13355: @{$cancreate{'statustocreate'}} = ();
13356: }
1.236 raeburn 13357: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 13358: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 13359: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 13360: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 13361: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 13362: my %selfcreatetypes = (
13363: sso => 'users authenticated by institutional single sign on',
13364: login => 'users authenticated by institutional log-in',
1.303 raeburn 13365: email => 'users verified by e-mail',
1.50 raeburn 13366: );
1.224 raeburn 13367: #
13368: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
13369: # is permitted.
13370: #
1.305 raeburn 13371: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 13372:
1.305 raeburn 13373: my (@statuses,%email_rule);
1.228 raeburn 13374: foreach my $item ('login','sso','email') {
1.224 raeburn 13375: if ($item eq 'email') {
1.236 raeburn 13376: if ($env{'form.cancreate_email'}) {
1.305 raeburn 13377: if (@types) {
13378: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
13379: foreach my $status (@poss_statuses) {
13380: if (grep(/^\Q$status\E$/,(@types,'default'))) {
13381: push(@statuses,$status);
13382: }
13383: }
13384: $save_inststatus{'inststatusguest'} = \@statuses;
13385: } else {
13386: push(@statuses,'default');
13387: }
13388: if (@statuses) {
13389: my %curr_rule;
13390: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
13391: foreach my $type (@statuses) {
13392: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 13393: }
1.305 raeburn 13394: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
13395: foreach my $type (@statuses) {
13396: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
13397: }
13398: }
13399: push(@{$cancreate{'selfcreate'}},'email');
13400: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
13401: my %curremaildom;
13402: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
13403: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
13404: }
13405: foreach my $type (@statuses) {
13406: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
13407: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
13408: }
13409: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
13410: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
13411: }
13412: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
13413: #
13414: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
13415: #
13416: my $chosen = $1;
13417: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
13418: my $emaildom;
13419: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
13420: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
13421: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
13422: if (ref($curremaildom{$type}) eq 'HASH') {
13423: if (exists($curremaildom{$type}{$chosen})) {
13424: if ($curremaildom{$type}{$chosen} ne $emaildom) {
13425: push(@{$changes{'cancreate'}},'emaildomain');
13426: }
13427: } elsif ($emaildom ne '') {
13428: push(@{$changes{'cancreate'}},'emaildomain');
13429: }
13430: } elsif ($emaildom ne '') {
13431: push(@{$changes{'cancreate'}},'emaildomain');
13432: }
13433: }
13434: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13435: } elsif ($chosen eq 'custom') {
13436: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
13437: $email_rule{$type} = [];
13438: if (ref($emailrules) eq 'HASH') {
13439: foreach my $rule (@possemail_rules) {
13440: if (exists($emailrules->{$rule})) {
13441: push(@{$email_rule{$type}},$rule);
13442: }
13443: }
13444: }
13445: if (@{$email_rule{$type}}) {
13446: $cancreate{'emailoptions'}{$type} = 'custom';
13447: if (ref($curr_rule{$type}) eq 'ARRAY') {
13448: if (@{$curr_rule{$type}} > 0) {
13449: foreach my $rule (@{$curr_rule{$type}}) {
13450: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
13451: push(@{$changes{'email_rule'}},$type);
13452: }
13453: }
13454: }
13455: foreach my $type (@{$email_rule{$type}}) {
13456: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
13457: push(@{$changes{'email_rule'}},$type);
13458: }
13459: }
13460: } else {
13461: push(@{$changes{'email_rule'}},$type);
13462: }
13463: }
13464: } else {
13465: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13466: }
13467: }
13468: }
13469: if (@types) {
13470: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13471: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
13472: if (@changed) {
13473: push(@{$changes{'inststatus'}},'inststatusguest');
13474: }
13475: } else {
13476: push(@{$changes{'inststatus'}},'inststatusguest');
13477: }
13478: }
13479: } else {
13480: delete($env{'form.cancreate_email'});
13481: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13482: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13483: push(@{$changes{'inststatus'}},'inststatusguest');
13484: }
13485: }
13486: }
13487: } else {
13488: $save_inststatus{'inststatusguest'} = [];
13489: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13490: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13491: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 13492: }
13493: }
1.224 raeburn 13494: }
13495: } else {
13496: if ($env{'form.cancreate_'.$item}) {
13497: push(@{$cancreate{'selfcreate'}},$item);
13498: }
13499: }
13500: }
1.305 raeburn 13501: my (%userinfo,%savecaptcha);
1.224 raeburn 13502: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
13503: #
1.228 raeburn 13504: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
13505: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 13506: #
1.236 raeburn 13507:
1.244 raeburn 13508: if ($env{'form.cancreate_email'}) {
1.228 raeburn 13509: push(@contexts,'emailusername');
1.305 raeburn 13510: if (@statuses) {
13511: foreach my $type (@statuses) {
1.228 raeburn 13512: if (ref($infofields) eq 'ARRAY') {
13513: foreach my $field (@{$infofields}) {
13514: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
13515: $cancreate{'emailusername'}{$type}{$field} = $1;
13516: }
13517: }
1.224 raeburn 13518: }
13519: }
13520: }
13521: #
13522: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 13523: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 13524: #
13525:
13526: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
13527: @approvalnotify = sort(@approvalnotify);
13528: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
13529: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13530: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
13531: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
13532: push(@{$changes{'cancreate'}},'notify');
13533: }
13534: } else {
13535: if ($cancreate{'notify'}{'approval'}) {
13536: push(@{$changes{'cancreate'}},'notify');
13537: }
13538: }
13539: } elsif ($cancreate{'notify'}{'approval'}) {
13540: push(@{$changes{'cancreate'}},'notify');
13541: }
13542:
13543: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
13544: }
13545: #
1.236 raeburn 13546: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 13547: # institutional log-in.
13548: #
13549: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
13550: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
13551: ($domdefaults{'auth_def'} eq 'localauth'))) {
13552: $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.').' '.
13553: &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.');
13554: }
13555: }
13556: my @fields = ('lastname','firstname','middlename','generation',
13557: 'permanentemail','id');
1.240 raeburn 13558: my @shibfields = (@fields,'inststatus');
1.224 raeburn 13559: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13560: #
13561: # Where usernames may created for institutional log-in and/or institutional single sign on:
13562: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
13563: # may self-create accounts
13564: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
13565: # which the user may supply, if institutional data is unavailable.
13566: #
13567: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 13568: if (@types) {
1.305 raeburn 13569: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
13570: push(@contexts,'statustocreate');
1.303 raeburn 13571: foreach my $type (@types) {
1.224 raeburn 13572: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
13573: foreach my $field (@fields) {
13574: if (grep(/^\Q$field\E$/,@modifiable)) {
13575: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
13576: } else {
13577: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
13578: }
13579: }
13580: }
13581: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 13582: foreach my $type (@types) {
1.224 raeburn 13583: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
13584: foreach my $field (@fields) {
13585: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
13586: $curr_usermodify{'selfcreate'}{$type}{$field}) {
13587: push(@{$changes{'selfcreate'}},$type);
13588: last;
13589: }
13590: }
13591: }
13592: }
13593: } else {
1.303 raeburn 13594: foreach my $type (@types) {
1.224 raeburn 13595: push(@{$changes{'selfcreate'}},$type);
13596: }
13597: }
13598: }
1.240 raeburn 13599: foreach my $field (@shibfields) {
13600: if ($env{'form.shibenv_'.$field} ne '') {
13601: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
13602: }
13603: }
13604: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13605: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
13606: foreach my $field (@shibfields) {
13607: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
13608: push(@{$changes{'cancreate'}},'shibenv');
13609: }
13610: }
13611: } else {
13612: foreach my $field (@shibfields) {
13613: if ($env{'form.shibenv_'.$field}) {
13614: push(@{$changes{'cancreate'}},'shibenv');
13615: last;
13616: }
13617: }
13618: }
13619: }
1.224 raeburn 13620: }
13621: foreach my $item (@contexts) {
13622: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
13623: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
13624: if (ref($cancreate{$item}) eq 'ARRAY') {
13625: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
13626: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13627: push(@{$changes{'cancreate'}},$item);
13628: }
13629: }
13630: }
13631: }
13632: if (ref($cancreate{$item}) eq 'ARRAY') {
13633: foreach my $type (@{$cancreate{$item}}) {
13634: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
13635: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13636: push(@{$changes{'cancreate'}},$item);
13637: }
13638: }
13639: }
13640: }
13641: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
13642: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 13643: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
13644: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13645: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
13646: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 13647: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13648: push(@{$changes{'cancreate'}},$item);
13649: }
13650: }
13651: }
1.305 raeburn 13652: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13653: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 13654: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13655: push(@{$changes{'cancreate'}},$item);
13656: }
1.224 raeburn 13657: }
13658: }
13659: }
1.305 raeburn 13660: foreach my $type (keys(%{$cancreate{$item}})) {
13661: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13662: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13663: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13664: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 13665: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13666: push(@{$changes{'cancreate'}},$item);
13667: }
13668: }
13669: } else {
13670: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13671: push(@{$changes{'cancreate'}},$item);
13672: }
13673: }
13674: }
1.305 raeburn 13675: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13676: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 13677: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13678: push(@{$changes{'cancreate'}},$item);
13679: }
1.224 raeburn 13680: }
13681: }
13682: }
13683: }
13684: } elsif ($curr_usercreation{'cancreate'}{$item}) {
13685: if (ref($cancreate{$item}) eq 'ARRAY') {
13686: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
13687: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13688: push(@{$changes{'cancreate'}},$item);
13689: }
13690: }
1.305 raeburn 13691: }
13692: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13693: if (ref($cancreate{$item}) eq 'HASH') {
13694: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13695: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 13696: }
13697: }
13698: } elsif ($item eq 'emailusername') {
1.228 raeburn 13699: if (ref($cancreate{$item}) eq 'HASH') {
13700: foreach my $type (keys(%{$cancreate{$item}})) {
13701: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13702: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13703: if ($cancreate{$item}{$type}{$field}) {
13704: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13705: push(@{$changes{'cancreate'}},$item);
13706: }
13707: last;
13708: }
13709: }
13710: }
13711: }
1.224 raeburn 13712: }
13713: }
13714: }
13715: #
13716: # Populate %save_usercreate hash with updates to self-creation configuration.
13717: #
13718: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
13719: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 13720: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 13721: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
13722: if (ref($cancreate{'notify'}) eq 'HASH') {
13723: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
13724: }
1.236 raeburn 13725: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
13726: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
13727: }
1.303 raeburn 13728: if (ref($cancreate{'emailverified'}) eq 'HASH') {
13729: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
13730: }
1.305 raeburn 13731: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
13732: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
13733: }
1.303 raeburn 13734: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
13735: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
13736: }
1.224 raeburn 13737: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13738: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
13739: }
1.240 raeburn 13740: if (ref($cancreate{'shibenv'}) eq 'HASH') {
13741: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
13742: }
1.224 raeburn 13743: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 13744: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 13745:
13746: my %userconfig_hash = (
13747: usercreation => \%save_usercreate,
13748: usermodification => \%save_usermodify,
1.305 raeburn 13749: inststatus => \%save_inststatus,
1.224 raeburn 13750: );
1.305 raeburn 13751:
1.224 raeburn 13752: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
13753: $dom);
13754: #
1.305 raeburn 13755: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 13756: #
1.27 raeburn 13757: if ($putresult eq 'ok') {
13758: if (keys(%changes) > 0) {
13759: $resulttext = &mt('Changes made:').'<ul>';
13760: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 13761: my %lt = &selfcreation_types();
1.34 raeburn 13762: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 13763: my $chgtext = '';
1.45 raeburn 13764: if ($type eq 'selfcreate') {
1.50 raeburn 13765: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 13766: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 13767: } else {
1.224 raeburn 13768: $chgtext .= &mt('Self-creation of a new account is permitted for:').
13769: '<ul>';
1.50 raeburn 13770: foreach my $case (@{$cancreate{$type}}) {
13771: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
13772: }
13773: $chgtext .= '</ul>';
1.100 raeburn 13774: if (ref($cancreate{$type}) eq 'ARRAY') {
13775: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
13776: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13777: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 13778: $chgtext .= '<span class="LC_warning">'.
13779: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
13780: '</span><br />';
13781: }
13782: }
13783: }
13784: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 13785: if (!@statuses) {
13786: $chgtext .= '<span class="LC_warning">'.
13787: &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.").
13788: '</span><br />';
1.303 raeburn 13789:
1.100 raeburn 13790: }
13791: }
13792: }
1.43 raeburn 13793: }
1.240 raeburn 13794: } elsif ($type eq 'shibenv') {
13795: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 13796: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 13797: } else {
13798: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
13799: '<ul>';
13800: foreach my $field (@shibfields) {
13801: next if ($cancreate{$type}{$field} eq '');
13802: if ($field eq 'inststatus') {
13803: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
13804: } else {
13805: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
13806: }
13807: }
13808: $chgtext .= '</ul>';
1.303 raeburn 13809: }
1.93 raeburn 13810: } elsif ($type eq 'statustocreate') {
1.96 raeburn 13811: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
13812: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
13813: if (@{$cancreate{'selfcreate'}} > 0) {
13814: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 13815: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 13816: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 13817: $chgtext .= '<br />'.
13818: '<span class="LC_warning">'.
13819: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
13820: '</span>';
13821: }
1.303 raeburn 13822: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 13823: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 13824: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
13825: } else {
13826: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
13827: }
13828: $chgtext .= '<ul>';
13829: foreach my $case (@{$cancreate{$type}}) {
13830: if ($case eq 'default') {
13831: $chgtext .= '<li>'.$othertitle.'</li>';
13832: } else {
1.303 raeburn 13833: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 13834: }
13835: }
1.100 raeburn 13836: $chgtext .= '</ul>';
13837: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 13838: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 13839: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
13840: '</span>';
1.100 raeburn 13841: }
13842: }
13843: } else {
13844: if (@{$cancreate{$type}} == 0) {
13845: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
13846: } else {
13847: $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 13848: }
13849: }
1.303 raeburn 13850: $chgtext .= '<br />';
1.93 raeburn 13851: }
1.236 raeburn 13852: } elsif ($type eq 'selfcreateprocessing') {
13853: my %choices = &Apache::lonlocal::texthash (
13854: automatic => 'Automatic approval',
13855: approval => 'Queued for approval',
13856: );
1.305 raeburn 13857: if (@types) {
13858: if (@statuses) {
1.303 raeburn 13859: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 13860: '<ul>';
1.305 raeburn 13861: foreach my $status (@statuses) {
13862: if ($status eq 'default') {
13863: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 13864: } else {
1.305 raeburn 13865: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 13866: }
13867: }
13868: $chgtext .= '</ul>';
13869: }
13870: } else {
13871: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
13872: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
13873: }
13874: } elsif ($type eq 'emailverified') {
13875: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 13876: all => 'Same as e-mail',
13877: first => 'Omit @domain',
13878: free => 'Free to choose',
1.303 raeburn 13879: );
1.305 raeburn 13880: if (@types) {
13881: if (@statuses) {
1.303 raeburn 13882: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
13883: '<ul>';
1.305 raeburn 13884: foreach my $status (@statuses) {
1.303 raeburn 13885: if ($type eq 'default') {
1.305 raeburn 13886: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 13887: } else {
1.305 raeburn 13888: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 13889: }
13890: }
13891: $chgtext .= '</ul>';
13892: }
13893: } else {
1.305 raeburn 13894: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 13895: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 13896: }
1.305 raeburn 13897: } elsif ($type eq 'emailoptions') {
13898: my %options = &Apache::lonlocal::texthash (
13899: any => 'Any e-mail',
13900: inst => 'Institutional only',
13901: noninst => 'Non-institutional only',
13902: custom => 'Custom restrictions',
13903: );
13904: if (@types) {
13905: if (@statuses) {
13906: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
13907: '<ul>';
13908: foreach my $status (@statuses) {
13909: if ($type eq 'default') {
13910: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
13911: } else {
13912: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 13913: }
13914: }
1.305 raeburn 13915: $chgtext .= '</ul>';
13916: }
13917: } else {
13918: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
13919: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
13920: } else {
13921: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
13922: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 13923: }
1.305 raeburn 13924: }
13925: } elsif ($type eq 'emaildomain') {
13926: my $output;
13927: if (@statuses) {
13928: foreach my $type (@statuses) {
13929: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
13930: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
13931: if ($type eq 'default') {
13932: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13933: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
13934: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
13935: } else {
13936: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
13937: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
13938: }
1.303 raeburn 13939: } else {
1.305 raeburn 13940: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13941: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
13942: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
13943: } else {
13944: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
13945: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
13946: }
1.303 raeburn 13947: }
1.305 raeburn 13948: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
13949: if ($type eq 'default') {
13950: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13951: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
13952: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
13953: } else {
13954: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
13955: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
13956: }
1.303 raeburn 13957: } else {
1.305 raeburn 13958: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13959: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
13960: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
13961: } else {
13962: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
13963: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
13964: }
1.303 raeburn 13965: }
13966: }
13967: }
13968: }
1.305 raeburn 13969: }
13970: if ($output ne '') {
13971: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
13972: '<ul>'.$output.'</ul>';
1.236 raeburn 13973: }
1.165 raeburn 13974: } elsif ($type eq 'captcha') {
1.224 raeburn 13975: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 13976: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
13977: } else {
13978: my %captchas = &captcha_phrases();
1.224 raeburn 13979: if ($captchas{$savecaptcha{$type}}) {
13980: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 13981: } else {
1.210 raeburn 13982: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 13983: }
13984: }
13985: } elsif ($type eq 'recaptchakeys') {
13986: my ($privkey,$pubkey);
1.224 raeburn 13987: if (ref($savecaptcha{$type}) eq 'HASH') {
13988: $pubkey = $savecaptcha{$type}{'public'};
13989: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 13990: }
13991: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
13992: if (!$pubkey) {
13993: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
13994: } else {
13995: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
13996: }
13997: if (!$privkey) {
13998: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
13999: } else {
14000: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
14001: }
14002: $chgtext .= '</ul>';
1.269 raeburn 14003: } elsif ($type eq 'recaptchaversion') {
14004: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 14005: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 14006: }
1.224 raeburn 14007: } elsif ($type eq 'emailusername') {
14008: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 14009: if (@statuses) {
14010: foreach my $type (@statuses) {
1.228 raeburn 14011: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
14012: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 14013: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 14014: '<ul>';
14015: foreach my $field (@{$infofields}) {
14016: if ($cancreate{'emailusername'}{$type}{$field}) {
14017: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
14018: }
14019: }
1.245 raeburn 14020: $chgtext .= '</ul>';
14021: } else {
1.303 raeburn 14022: $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 14023: }
14024: } else {
1.303 raeburn 14025: $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 14026: }
14027: }
14028: }
14029: }
14030: } elsif ($type eq 'notify') {
1.303 raeburn 14031: my $numapprove = 0;
1.224 raeburn 14032: if (ref($changes{'cancreate'}) eq 'ARRAY') {
14033: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
14034: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 14035: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
14036: $numapprove ++;
1.224 raeburn 14037: }
14038: }
1.43 raeburn 14039: }
1.303 raeburn 14040: unless ($numapprove) {
14041: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
14042: }
1.34 raeburn 14043: }
1.224 raeburn 14044: if ($chgtext) {
14045: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 14046: }
14047: }
14048: }
1.305 raeburn 14049: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 14050: my ($emailrules,$emailruleorder) =
14051: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 14052: foreach my $type (@{$changes{'email_rule'}}) {
14053: if (ref($email_rule{$type}) eq 'ARRAY') {
14054: my $chgtext = '<ul>';
14055: foreach my $rule (@{$email_rule{$type}}) {
14056: if (ref($emailrules->{$rule}) eq 'HASH') {
14057: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
14058: }
14059: }
14060: $chgtext .= '</ul>';
1.310 raeburn 14061: my $typename;
1.305 raeburn 14062: if (@types) {
14063: if ($type eq 'default') {
14064: $typename = $othertitle;
14065: } else {
14066: $typename = $usertypes{$type};
14067: }
14068: $chgtext .= &mt('(Affiliation: [_1])',$typename);
14069: }
14070: if (@{$email_rule{$type}} > 0) {
14071: $resulttext .= '<li>'.
14072: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
14073: $usertypes{$type}).
14074: $chgtext.
14075: '</li>';
14076: } else {
14077: $resulttext .= '<li>'.
1.310 raeburn 14078: &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 14079: '</li>'.
1.310 raeburn 14080: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 14081: }
1.43 raeburn 14082: }
14083: }
1.305 raeburn 14084: }
14085: if (ref($changes{'inststatus'}) eq 'ARRAY') {
14086: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
14087: if (@{$save_inststatus{'inststatusguest'}} > 0) {
14088: my $chgtext = '<ul>';
14089: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
14090: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
14091: }
14092: $chgtext .= '</ul>';
14093: $resulttext .= '<li>'.
14094: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
14095: $chgtext.
14096: '</li>';
14097: } else {
14098: $resulttext .= '<li>'.
14099: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
14100: '</li>';
14101: }
1.43 raeburn 14102: }
14103: }
1.224 raeburn 14104: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
14105: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
14106: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14107: foreach my $type (@{$changes{'selfcreate'}}) {
14108: my $typename = $type;
1.303 raeburn 14109: if (keys(%usertypes) > 0) {
14110: if ($usertypes{$type} ne '') {
14111: $typename = $usertypes{$type};
1.224 raeburn 14112: }
14113: }
14114: my @modifiable;
14115: $resulttext .= '<li>'.
14116: &mt('Self-creation of account by users with status: [_1]',
14117: '<span class="LC_cusr_emph">'.$typename.'</span>').
14118: ' - '.&mt('modifiable fields (if institutional data blank): ');
14119: foreach my $field (@fields) {
14120: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
14121: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 14122: }
14123: }
1.224 raeburn 14124: if (@modifiable > 0) {
14125: $resulttext .= join(', ',@modifiable);
1.43 raeburn 14126: } else {
1.224 raeburn 14127: $resulttext .= &mt('none');
1.43 raeburn 14128: }
1.224 raeburn 14129: $resulttext .= '</li>';
1.28 raeburn 14130: }
1.224 raeburn 14131: $resulttext .= '</ul></li>';
1.28 raeburn 14132: }
1.27 raeburn 14133: $resulttext .= '</ul>';
1.305 raeburn 14134: my $cachetime = 24*60*60;
14135: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
14136: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14137: if (ref($lastactref) eq 'HASH') {
14138: $lastactref->{'domdefaults'} = 1;
14139: }
1.27 raeburn 14140: } else {
1.224 raeburn 14141: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 14142: }
14143: } else {
14144: $resulttext = '<span class="LC_error">'.
1.23 raeburn 14145: &mt('An error occurred: [_1]',$putresult).'</span>';
14146: }
1.43 raeburn 14147: if ($warningmsg ne '') {
14148: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
14149: }
1.23 raeburn 14150: return $resulttext;
14151: }
14152:
1.165 raeburn 14153: sub process_captcha {
14154: my ($container,$changes,$newsettings,$current) = @_;
14155: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
14156: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
14157: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
14158: $newsettings->{'captcha'} = 'original';
14159: }
14160: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 14161: if ($container eq 'cancreate') {
1.169 raeburn 14162: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14163: push(@{$changes->{'cancreate'}},'captcha');
14164: } elsif (!defined($changes->{'cancreate'})) {
14165: $changes->{'cancreate'} = ['captcha'];
14166: }
14167: } else {
14168: $changes->{'captcha'} = 1;
1.165 raeburn 14169: }
14170: }
1.269 raeburn 14171: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 14172: if ($newsettings->{'captcha'} eq 'recaptcha') {
14173: $newpub = $env{'form.'.$container.'_recaptchapub'};
14174: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 14175: $newpub =~ s/[^\w\-]//g;
14176: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 14177: $newsettings->{'recaptchakeys'} = {
14178: public => $newpub,
14179: private => $newpriv,
14180: };
1.269 raeburn 14181: $newversion = $env{'form.'.$container.'_recaptchaversion'};
14182: $newversion =~ s/\D//g;
14183: if ($newversion ne '2') {
14184: $newversion = 1;
14185: }
14186: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 14187: }
14188: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
14189: $currpub = $current->{'recaptchakeys'}{'public'};
14190: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 14191: unless ($newsettings->{'captcha'} eq 'recaptcha') {
14192: $newsettings->{'recaptchakeys'} = {
14193: public => '',
14194: private => '',
14195: }
14196: }
1.165 raeburn 14197: }
1.269 raeburn 14198: if ($current->{'captcha'} eq 'recaptcha') {
14199: $currversion = $current->{'recaptchaversion'};
14200: if ($currversion ne '2') {
14201: $currversion = 1;
14202: }
14203: }
14204: if ($currversion ne $newversion) {
14205: if ($container eq 'cancreate') {
14206: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14207: push(@{$changes->{'cancreate'}},'recaptchaversion');
14208: } elsif (!defined($changes->{'cancreate'})) {
14209: $changes->{'cancreate'} = ['recaptchaversion'];
14210: }
14211: } else {
14212: $changes->{'recaptchaversion'} = 1;
14213: }
14214: }
1.165 raeburn 14215: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 14216: if ($container eq 'cancreate') {
14217: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14218: push(@{$changes->{'cancreate'}},'recaptchakeys');
14219: } elsif (!defined($changes->{'cancreate'})) {
14220: $changes->{'cancreate'} = ['recaptchakeys'];
14221: }
14222: } else {
1.210 raeburn 14223: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 14224: }
14225: }
14226: return;
14227: }
14228:
1.33 raeburn 14229: sub modify_usermodification {
14230: my ($dom,%domconfig) = @_;
1.224 raeburn 14231: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 14232: if (ref($domconfig{'usermodification'}) eq 'HASH') {
14233: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 14234: if ($key eq 'selfcreate') {
14235: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
14236: } else {
14237: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
14238: }
1.33 raeburn 14239: }
14240: }
1.224 raeburn 14241: my @contexts = ('author','course');
1.33 raeburn 14242: my %context_title = (
14243: author => 'In author context',
14244: course => 'In course context',
14245: );
14246: my @fields = ('lastname','firstname','middlename','generation',
14247: 'permanentemail','id');
14248: my %roles = (
14249: author => ['ca','aa'],
14250: course => ['st','ep','ta','in','cr'],
14251: );
14252: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14253: foreach my $context (@contexts) {
14254: foreach my $role (@{$roles{$context}}) {
14255: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
14256: foreach my $item (@fields) {
14257: if (grep(/^\Q$item\E$/,@modifiable)) {
14258: $modifyhash{$context}{$role}{$item} = 1;
14259: } else {
14260: $modifyhash{$context}{$role}{$item} = 0;
14261: }
14262: }
14263: }
14264: if (ref($curr_usermodification{$context}) eq 'HASH') {
14265: foreach my $role (@{$roles{$context}}) {
14266: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
14267: foreach my $field (@fields) {
14268: if ($modifyhash{$context}{$role}{$field} ne
14269: $curr_usermodification{$context}{$role}{$field}) {
14270: push(@{$changes{$context}},$role);
14271: last;
14272: }
14273: }
14274: }
14275: }
14276: } else {
14277: foreach my $context (@contexts) {
14278: foreach my $role (@{$roles{$context}}) {
14279: push(@{$changes{$context}},$role);
14280: }
14281: }
14282: }
14283: }
14284: my %usermodification_hash = (
14285: usermodification => \%modifyhash,
14286: );
14287: my $putresult = &Apache::lonnet::put_dom('configuration',
14288: \%usermodification_hash,$dom);
14289: if ($putresult eq 'ok') {
14290: if (keys(%changes) > 0) {
14291: $resulttext = &mt('Changes made: ').'<ul>';
14292: foreach my $context (@contexts) {
14293: if (ref($changes{$context}) eq 'ARRAY') {
14294: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
14295: if (ref($changes{$context}) eq 'ARRAY') {
14296: foreach my $role (@{$changes{$context}}) {
14297: my $rolename;
1.224 raeburn 14298: if ($role eq 'cr') {
14299: $rolename = &mt('Custom');
1.33 raeburn 14300: } else {
1.224 raeburn 14301: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 14302: }
14303: my @modifiable;
1.224 raeburn 14304: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 14305: foreach my $field (@fields) {
14306: if ($modifyhash{$context}{$role}{$field}) {
14307: push(@modifiable,$fieldtitles{$field});
14308: }
14309: }
14310: if (@modifiable > 0) {
14311: $resulttext .= join(', ',@modifiable);
14312: } else {
14313: $resulttext .= &mt('none');
14314: }
14315: $resulttext .= '</li>';
14316: }
14317: $resulttext .= '</ul></li>';
14318: }
14319: }
14320: }
14321: $resulttext .= '</ul>';
14322: } else {
14323: $resulttext = &mt('No changes made to user modification settings');
14324: }
14325: } else {
14326: $resulttext = '<span class="LC_error">'.
14327: &mt('An error occurred: [_1]',$putresult).'</span>';
14328: }
14329: return $resulttext;
14330: }
14331:
1.43 raeburn 14332: sub modify_defaults {
1.212 raeburn 14333: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 14334: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 14335: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 14336: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
14337: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.325 raeburn 14338: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 14339: foreach my $item (@items) {
14340: $newvalues{$item} = $env{'form.'.$item};
14341: if ($item eq 'auth_def') {
14342: if ($newvalues{$item} ne '') {
14343: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
14344: push(@errors,$item);
14345: }
14346: }
14347: } elsif ($item eq 'lang_def') {
14348: if ($newvalues{$item} ne '') {
14349: if ($newvalues{$item} =~ /^(\w+)/) {
14350: my $langcode = $1;
1.103 raeburn 14351: if ($langcode ne 'x_chef') {
14352: if (code2language($langcode) eq '') {
14353: push(@errors,$item);
14354: }
1.43 raeburn 14355: }
14356: } else {
14357: push(@errors,$item);
14358: }
14359: }
1.54 raeburn 14360: } elsif ($item eq 'timezone_def') {
14361: if ($newvalues{$item} ne '') {
1.62 raeburn 14362: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 14363: push(@errors,$item);
14364: }
14365: }
1.68 raeburn 14366: } elsif ($item eq 'datelocale_def') {
14367: if ($newvalues{$item} ne '') {
14368: my @datelocale_ids = DateTime::Locale->ids();
14369: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
14370: push(@errors,$item);
14371: }
14372: }
1.141 raeburn 14373: } elsif ($item eq 'portal_def') {
14374: if ($newvalues{$item} ne '') {
14375: 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])\/?$/) {
14376: push(@errors,$item);
14377: }
14378: }
1.294 raeburn 14379: } elsif ($item eq 'intauth_cost') {
14380: if ($newvalues{$item} ne '') {
14381: if ($newvalues{$item} =~ /\D/) {
14382: push(@errors,$item);
14383: }
14384: }
14385: } elsif ($item eq 'intauth_check') {
14386: if ($newvalues{$item} ne '') {
14387: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
14388: push(@errors,$item);
14389: }
14390: }
14391: } elsif ($item eq 'intauth_switch') {
14392: if ($newvalues{$item} ne '') {
14393: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
14394: push(@errors,$item);
14395: }
14396: }
1.43 raeburn 14397: }
14398: if (grep(/^\Q$item\E$/,@errors)) {
14399: $newvalues{$item} = $domdefaults{$item};
14400: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
14401: $changes{$item} = 1;
14402: }
1.72 raeburn 14403: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 14404: }
14405: my %defaults_hash = (
1.72 raeburn 14406: defaults => \%newvalues,
14407: );
1.43 raeburn 14408: my $title = &defaults_titles();
1.236 raeburn 14409:
14410: my $currinststatus;
14411: if (ref($domconfig{'inststatus'}) eq 'HASH') {
14412: $currinststatus = $domconfig{'inststatus'};
14413: } else {
14414: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
14415: $currinststatus = {
14416: inststatustypes => $usertypes,
14417: inststatusorder => $types,
14418: inststatusguest => [],
14419: };
14420: }
14421: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
14422: my @allpos;
14423: my %alltypes;
1.305 raeburn 14424: my @inststatusguest;
14425: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
14426: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
14427: unless (grep(/^\Q$type\E$/,@todelete)) {
14428: push(@inststatusguest,$type);
14429: }
14430: }
14431: }
14432: my ($currtitles,$currorder);
1.236 raeburn 14433: if (ref($currinststatus) eq 'HASH') {
14434: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
14435: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
14436: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
14437: if ($currinststatus->{inststatustypes}->{$type} ne '') {
14438: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
14439: }
14440: }
14441: unless (grep(/^\Q$type\E$/,@todelete)) {
14442: my $position = $env{'form.inststatus_pos_'.$type};
14443: $position =~ s/\D+//g;
14444: $allpos[$position] = $type;
14445: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
14446: $alltypes{$type} =~ s/`//g;
14447: }
14448: }
14449: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
14450: $currtitles =~ s/,$//;
14451: }
14452: }
14453: if ($env{'form.addinststatus'}) {
14454: my $newtype = $env{'form.addinststatus'};
14455: $newtype =~ s/\W//g;
14456: unless (exists($alltypes{$newtype})) {
14457: $alltypes{$newtype} = $env{'form.addinststatus_title'};
14458: $alltypes{$newtype} =~ s/`//g;
14459: my $position = $env{'form.addinststatus_pos'};
14460: $position =~ s/\D+//g;
14461: if ($position ne '') {
14462: $allpos[$position] = $newtype;
14463: }
14464: }
14465: }
1.305 raeburn 14466: my @orderedstatus;
1.236 raeburn 14467: foreach my $type (@allpos) {
14468: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
14469: push(@orderedstatus,$type);
14470: }
14471: }
14472: foreach my $type (keys(%alltypes)) {
14473: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
14474: delete($alltypes{$type});
14475: }
14476: }
14477: $defaults_hash{'inststatus'} = {
14478: inststatustypes => \%alltypes,
14479: inststatusorder => \@orderedstatus,
1.305 raeburn 14480: inststatusguest => \@inststatusguest,
1.236 raeburn 14481: };
14482: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
14483: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
14484: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
14485: }
14486: }
14487: if ($currorder ne join(',',@orderedstatus)) {
14488: $changes{'inststatus'}{'inststatusorder'} = 1;
14489: }
14490: my $newtitles;
14491: foreach my $item (@orderedstatus) {
14492: $newtitles .= $alltypes{$item}.',';
14493: }
14494: $newtitles =~ s/,$//;
14495: if ($currtitles ne $newtitles) {
14496: $changes{'inststatus'}{'inststatustypes'} = 1;
14497: }
1.43 raeburn 14498: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
14499: $dom);
14500: if ($putresult eq 'ok') {
14501: if (keys(%changes) > 0) {
14502: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 14503: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 14504: 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";
14505: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 14506: if ($item eq 'inststatus') {
14507: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 14508: if (@orderedstatus) {
1.236 raeburn 14509: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
14510: foreach my $type (@orderedstatus) {
14511: $resulttext .= $alltypes{$type}.', ';
14512: }
14513: $resulttext =~ s/, $//;
14514: $resulttext .= '</li>';
1.305 raeburn 14515: } else {
14516: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 14517: }
14518: }
14519: } else {
14520: my $value = $env{'form.'.$item};
14521: if ($value eq '') {
14522: $value = &mt('none');
14523: } elsif ($item eq 'auth_def') {
14524: my %authnames = &authtype_names();
14525: my %shortauth = (
14526: internal => 'int',
14527: krb4 => 'krb4',
14528: krb5 => 'krb5',
14529: localauth => 'loc',
1.325 raeburn 14530: lti => 'lti',
1.236 raeburn 14531: );
14532: $value = $authnames{$shortauth{$value}};
1.294 raeburn 14533: } elsif ($item eq 'intauth_switch') {
14534: my %optiondesc = &Apache::lonlocal::texthash (
14535: 0 => 'No',
14536: 1 => 'Yes',
14537: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
14538: );
14539: if ($value =~ /^(0|1|2)$/) {
14540: $value = $optiondesc{$value};
14541: } else {
14542: $value = &mt('none -- defaults to No');
14543: }
14544: } elsif ($item eq 'intauth_check') {
14545: my %optiondesc = &Apache::lonlocal::texthash (
14546: 0 => 'No',
14547: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
14548: 2 => 'Yes, disallow login if stored cost is less than domain default',
14549: );
14550: if ($value =~ /^(0|1|2)$/) {
14551: $value = $optiondesc{$value};
14552: } else {
14553: $value = &mt('none -- defaults to No');
14554: }
1.236 raeburn 14555: }
14556: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
14557: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 14558: }
14559: }
14560: $resulttext .= '</ul>';
14561: $mailmsgtext .= "\n";
14562: my $cachetime = 24*60*60;
1.72 raeburn 14563: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 14564: if (ref($lastactref) eq 'HASH') {
14565: $lastactref->{'domdefaults'} = 1;
14566: }
1.68 raeburn 14567: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 14568: my $notify = 1;
14569: if (ref($domconfig{'contacts'}) eq 'HASH') {
14570: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
14571: $notify = 0;
14572: }
14573: }
14574: if ($notify) {
14575: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
14576: "LON-CAPA Domain Settings Change - $dom",
14577: $mailmsgtext);
14578: }
1.54 raeburn 14579: }
1.43 raeburn 14580: } else {
1.54 raeburn 14581: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 14582: }
14583: } else {
14584: $resulttext = '<span class="LC_error">'.
14585: &mt('An error occurred: [_1]',$putresult).'</span>';
14586: }
14587: if (@errors > 0) {
14588: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
14589: foreach my $item (@errors) {
14590: $resulttext .= ' "'.$title->{$item}.'",';
14591: }
14592: $resulttext =~ s/,$//;
14593: }
14594: return $resulttext;
14595: }
14596:
1.46 raeburn 14597: sub modify_scantron {
1.205 raeburn 14598: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 14599: my ($resulttext,%confhash,%changes,$errors);
14600: my $custom = 'custom.tab';
14601: my $default = 'default.tab';
14602: my $servadm = $r->dir_config('lonAdmEMail');
14603: my ($configuserok,$author_ok,$switchserver) =
14604: &config_check($dom,$confname,$servadm);
14605: if ($env{'form.scantronformat.filename'} ne '') {
14606: my $error;
14607: if ($configuserok eq 'ok') {
14608: if ($switchserver) {
1.130 raeburn 14609: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 14610: } else {
14611: if ($author_ok eq 'ok') {
14612: my ($result,$scantronurl) =
14613: &publishlogo($r,'upload','scantronformat',$dom,
14614: $confname,'scantron','','',$custom);
14615: if ($result eq 'ok') {
14616: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 14617: $changes{'scantronformat'} = 1;
1.46 raeburn 14618: } else {
14619: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
14620: }
14621: } else {
14622: $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);
14623: }
14624: }
14625: } else {
14626: $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);
14627: }
14628: if ($error) {
14629: &Apache::lonnet::logthis($error);
14630: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14631: }
14632: }
1.48 raeburn 14633: if (ref($domconfig{'scantron'}) eq 'HASH') {
14634: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
14635: if ($env{'form.scantronformat_del'}) {
14636: $confhash{'scantron'}{'scantronformat'} = '';
14637: $changes{'scantronformat'} = 1;
1.46 raeburn 14638: }
14639: }
14640: }
14641: if (keys(%confhash) > 0) {
14642: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
14643: $dom);
14644: if ($putresult eq 'ok') {
14645: if (keys(%changes) > 0) {
1.48 raeburn 14646: if (ref($confhash{'scantron'}) eq 'HASH') {
14647: $resulttext = &mt('Changes made:').'<ul>';
14648: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 14649: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 14650: } else {
1.130 raeburn 14651: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 14652: }
1.48 raeburn 14653: $resulttext .= '</ul>';
14654: } else {
1.130 raeburn 14655: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 14656: }
14657: $resulttext .= '</ul>';
14658: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 14659: if (ref($lastactref) eq 'HASH') {
14660: $lastactref->{'domainconfig'} = 1;
14661: }
1.46 raeburn 14662: } else {
1.130 raeburn 14663: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 14664: }
14665: } else {
14666: $resulttext = '<span class="LC_error">'.
14667: &mt('An error occurred: [_1]',$putresult).'</span>';
14668: }
14669: } else {
1.130 raeburn 14670: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 14671: }
14672: if ($errors) {
14673: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14674: $errors.'</ul>';
14675: }
14676: return $resulttext;
14677: }
14678:
1.48 raeburn 14679: sub modify_coursecategories {
1.239 raeburn 14680: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 14681: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
14682: $cathash);
1.48 raeburn 14683: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 14684: my @catitems = ('unauth','auth');
14685: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 14686: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 14687: $cathash = $domconfig{'coursecategories'}{'cats'};
14688: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
14689: $changes{'togglecats'} = 1;
14690: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
14691: }
14692: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
14693: $changes{'categorize'} = 1;
14694: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
14695: }
1.120 raeburn 14696: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
14697: $changes{'togglecatscomm'} = 1;
14698: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
14699: }
14700: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
14701: $changes{'categorizecomm'} = 1;
14702: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 14703:
14704: }
14705: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
14706: $changes{'togglecatsplace'} = 1;
14707: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
14708: }
14709: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
14710: $changes{'categorizeplace'} = 1;
14711: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 14712: }
1.238 raeburn 14713: foreach my $item (@catitems) {
14714: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
14715: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
14716: $changes{$item} = 1;
14717: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
14718: }
14719: }
14720: }
1.57 raeburn 14721: } else {
14722: $changes{'togglecats'} = 1;
14723: $changes{'categorize'} = 1;
1.124 raeburn 14724: $changes{'togglecatscomm'} = 1;
14725: $changes{'categorizecomm'} = 1;
1.272 raeburn 14726: $changes{'togglecatsplace'} = 1;
14727: $changes{'categorizeplace'} = 1;
1.87 raeburn 14728: $domconfig{'coursecategories'} = {
14729: togglecats => $env{'form.togglecats'},
14730: categorize => $env{'form.categorize'},
1.124 raeburn 14731: togglecatscomm => $env{'form.togglecatscomm'},
14732: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 14733: togglecatsplace => $env{'form.togglecatsplace'},
14734: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 14735: };
1.238 raeburn 14736: foreach my $item (@catitems) {
14737: if ($env{'form.coursecat_'.$item} ne 'std') {
14738: $changes{$item} = 1;
14739: }
14740: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
14741: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
14742: }
14743: }
1.57 raeburn 14744: }
14745: if (ref($cathash) eq 'HASH') {
14746: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 14747: push (@deletecategory,'instcode::0');
14748: }
1.120 raeburn 14749: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
14750: push(@deletecategory,'communities::0');
14751: }
1.272 raeburn 14752: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
14753: push(@deletecategory,'placement::0');
14754: }
1.48 raeburn 14755: }
1.57 raeburn 14756: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
14757: if (ref($cathash) eq 'HASH') {
1.48 raeburn 14758: if (@deletecategory > 0) {
14759: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 14760: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 14761: foreach my $item (@deletecategory) {
1.57 raeburn 14762: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
14763: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 14764: $deletions{$item} = 1;
1.57 raeburn 14765: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 14766: }
14767: }
14768: }
1.57 raeburn 14769: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 14770: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 14771: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 14772: $reorderings{$item} = 1;
1.57 raeburn 14773: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 14774: }
14775: if ($env{'form.addcategory_name_'.$item} ne '') {
14776: my $newcat = $env{'form.addcategory_name_'.$item};
14777: my $newdepth = $depth+1;
14778: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 14779: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 14780: $adds{$newitem} = 1;
14781: }
14782: if ($env{'form.subcat_'.$item} ne '') {
14783: my $newcat = $env{'form.subcat_'.$item};
14784: my $newdepth = $depth+1;
14785: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 14786: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 14787: $adds{$newitem} = 1;
14788: }
14789: }
14790: }
14791: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 14792: if (ref($cathash) eq 'HASH') {
1.48 raeburn 14793: my $newitem = 'instcode::0';
1.57 raeburn 14794: if ($cathash->{$newitem} eq '') {
14795: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 14796: $adds{$newitem} = 1;
14797: }
14798: } else {
14799: my $newitem = 'instcode::0';
1.57 raeburn 14800: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 14801: $adds{$newitem} = 1;
14802: }
14803: }
1.120 raeburn 14804: if ($env{'form.communities'} eq '1') {
14805: if (ref($cathash) eq 'HASH') {
14806: my $newitem = 'communities::0';
14807: if ($cathash->{$newitem} eq '') {
14808: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
14809: $adds{$newitem} = 1;
14810: }
14811: } else {
14812: my $newitem = 'communities::0';
14813: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
14814: $adds{$newitem} = 1;
14815: }
14816: }
1.272 raeburn 14817: if ($env{'form.placement'} eq '1') {
14818: if (ref($cathash) eq 'HASH') {
14819: my $newitem = 'placement::0';
14820: if ($cathash->{$newitem} eq '') {
14821: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
14822: $adds{$newitem} = 1;
14823: }
14824: } else {
14825: my $newitem = 'placement::0';
14826: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
14827: $adds{$newitem} = 1;
14828: }
14829: }
1.48 raeburn 14830: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 14831: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 14832: ($env{'form.addcategory_name'} ne 'communities') &&
14833: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 14834: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
14835: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
14836: $adds{$newitem} = 1;
14837: }
1.48 raeburn 14838: }
1.57 raeburn 14839: my $putresult;
1.48 raeburn 14840: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14841: if (keys(%deletions) > 0) {
14842: foreach my $key (keys(%deletions)) {
14843: if ($predelallitems{$key} ne '') {
14844: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
14845: }
14846: }
14847: }
14848: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 14849: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 14850: if (ref($chkcats[0]) eq 'ARRAY') {
14851: my $depth = 0;
14852: my $chg = 0;
14853: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
14854: my $name = $chkcats[0][$i];
14855: my $item;
14856: if ($name eq '') {
14857: $chg ++;
14858: } else {
14859: $item = &escape($name).'::0';
14860: if ($chg) {
1.57 raeburn 14861: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 14862: }
14863: $depth ++;
1.57 raeburn 14864: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 14865: $depth --;
14866: }
14867: }
14868: }
1.57 raeburn 14869: }
14870: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14871: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 14872: if ($putresult eq 'ok') {
1.57 raeburn 14873: my %title = (
1.120 raeburn 14874: togglecats => 'Show/Hide a course in catalog',
14875: categorize => 'Assign a category to a course',
14876: togglecatscomm => 'Show/Hide a community in catalog',
14877: categorizecomm => 'Assign a category to a community',
1.57 raeburn 14878: );
14879: my %level = (
1.120 raeburn 14880: dom => 'set in Domain ("Modify Course/Community")',
14881: crs => 'set in Course ("Course Configuration")',
14882: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 14883: none => 'No catalog',
14884: std => 'Standard catalog',
14885: domonly => 'Domain-only catalog',
14886: codesrch => 'Code search form',
1.57 raeburn 14887: );
1.48 raeburn 14888: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 14889: if ($changes{'togglecats'}) {
14890: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
14891: }
14892: if ($changes{'categorize'}) {
14893: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 14894: }
1.120 raeburn 14895: if ($changes{'togglecatscomm'}) {
14896: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
14897: }
14898: if ($changes{'categorizecomm'}) {
14899: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
14900: }
1.238 raeburn 14901: if ($changes{'unauth'}) {
14902: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
14903: }
14904: if ($changes{'auth'}) {
14905: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
14906: }
1.57 raeburn 14907: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14908: my $cathash;
14909: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
14910: $cathash = $domconfig{'coursecategories'}{'cats'};
14911: } else {
14912: $cathash = {};
14913: }
14914: my (@cats,@trails,%allitems);
14915: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
14916: if (keys(%deletions) > 0) {
14917: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
14918: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
14919: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
14920: }
14921: $resulttext .= '</ul></li>';
14922: }
14923: if (keys(%reorderings) > 0) {
14924: my %sort_by_trail;
14925: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
14926: foreach my $key (keys(%reorderings)) {
14927: if ($allitems{$key} ne '') {
14928: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
14929: }
1.48 raeburn 14930: }
1.57 raeburn 14931: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
14932: $resulttext .= '<li>'.$trails[$trail].'</li>';
14933: }
14934: $resulttext .= '</ul></li>';
1.48 raeburn 14935: }
1.57 raeburn 14936: if (keys(%adds) > 0) {
14937: my %sort_by_trail;
14938: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
14939: foreach my $key (keys(%adds)) {
14940: if ($allitems{$key} ne '') {
14941: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
14942: }
14943: }
14944: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
14945: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 14946: }
1.57 raeburn 14947: $resulttext .= '</ul></li>';
1.48 raeburn 14948: }
14949: }
14950: $resulttext .= '</ul>';
1.239 raeburn 14951: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 14952: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
14953: if ($changes{'auth'}) {
14954: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
14955: }
14956: if ($changes{'unauth'}) {
14957: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
14958: }
14959: my $cachetime = 24*60*60;
14960: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 14961: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 14962: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 14963: }
14964: }
1.48 raeburn 14965: } else {
14966: $resulttext = '<span class="LC_error">'.
1.57 raeburn 14967: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 14968: }
14969: } else {
1.120 raeburn 14970: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 14971: }
14972: return $resulttext;
14973: }
14974:
1.69 raeburn 14975: sub modify_serverstatuses {
14976: my ($dom,%domconfig) = @_;
14977: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
14978: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
14979: %currserverstatus = %{$domconfig{'serverstatuses'}};
14980: }
14981: my @pages = &serverstatus_pages();
14982: foreach my $type (@pages) {
14983: $newserverstatus{$type}{'namedusers'} = '';
14984: $newserverstatus{$type}{'machines'} = '';
14985: if (defined($env{'form.'.$type.'_namedusers'})) {
14986: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
14987: my @okusers;
14988: foreach my $user (@users) {
14989: my ($uname,$udom) = split(/:/,$user);
14990: if (($udom =~ /^$match_domain$/) &&
14991: (&Apache::lonnet::domain($udom)) &&
14992: ($uname =~ /^$match_username$/)) {
14993: if (!grep(/^\Q$user\E/,@okusers)) {
14994: push(@okusers,$user);
14995: }
14996: }
14997: }
14998: if (@okusers > 0) {
14999: @okusers = sort(@okusers);
15000: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
15001: }
15002: }
15003: if (defined($env{'form.'.$type.'_machines'})) {
15004: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
15005: my @okmachines;
15006: foreach my $ip (@machines) {
15007: my @parts = split(/\./,$ip);
15008: next if (@parts < 4);
15009: my $badip = 0;
15010: for (my $i=0; $i<4; $i++) {
15011: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
15012: $badip = 1;
15013: last;
15014: }
15015: }
15016: if (!$badip) {
15017: push(@okmachines,$ip);
15018: }
15019: }
15020: @okmachines = sort(@okmachines);
15021: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
15022: }
15023: }
15024: my %serverstatushash = (
15025: serverstatuses => \%newserverstatus,
15026: );
15027: foreach my $type (@pages) {
1.83 raeburn 15028: foreach my $setting ('namedusers','machines') {
1.84 raeburn 15029: my (@current,@new);
1.83 raeburn 15030: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 15031: if ($currserverstatus{$type}{$setting} ne '') {
15032: @current = split(/,/,$currserverstatus{$type}{$setting});
15033: }
15034: }
15035: if ($newserverstatus{$type}{$setting} ne '') {
15036: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 15037: }
15038: if (@current > 0) {
15039: if (@new > 0) {
15040: foreach my $item (@current) {
15041: if (!grep(/^\Q$item\E$/,@new)) {
15042: $changes{$type}{$setting} = 1;
1.82 raeburn 15043: last;
15044: }
15045: }
1.84 raeburn 15046: foreach my $item (@new) {
15047: if (!grep(/^\Q$item\E$/,@current)) {
15048: $changes{$type}{$setting} = 1;
15049: last;
1.82 raeburn 15050: }
15051: }
15052: } else {
1.83 raeburn 15053: $changes{$type}{$setting} = 1;
1.69 raeburn 15054: }
1.83 raeburn 15055: } elsif (@new > 0) {
15056: $changes{$type}{$setting} = 1;
1.69 raeburn 15057: }
15058: }
15059: }
15060: if (keys(%changes) > 0) {
1.81 raeburn 15061: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 15062: my $putresult = &Apache::lonnet::put_dom('configuration',
15063: \%serverstatushash,$dom);
15064: if ($putresult eq 'ok') {
15065: $resulttext .= &mt('Changes made:').'<ul>';
15066: foreach my $type (@pages) {
1.84 raeburn 15067: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 15068: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 15069: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 15070: if ($newserverstatus{$type}{'namedusers'} eq '') {
15071: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
15072: } else {
15073: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
15074: }
1.84 raeburn 15075: }
15076: if ($changes{$type}{'machines'}) {
1.69 raeburn 15077: if ($newserverstatus{$type}{'machines'} eq '') {
15078: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
15079: } else {
15080: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
15081: }
15082:
15083: }
15084: $resulttext .= '</ul></li>';
15085: }
15086: }
15087: $resulttext .= '</ul>';
15088: } else {
15089: $resulttext = '<span class="LC_error">'.
15090: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
15091:
15092: }
15093: } else {
15094: $resulttext = &mt('No changes made to access to server status pages');
15095: }
15096: return $resulttext;
15097: }
15098:
1.118 jms 15099: sub modify_helpsettings {
1.285 raeburn 15100: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 15101: my ($resulttext,$errors,%changes,%helphash);
15102: my %defaultchecked = ('submitbugs' => 'on');
15103: my @offon = ('off','on');
1.118 jms 15104: my @toggles = ('submitbugs');
1.285 raeburn 15105: my %current = ('submitbugs' => '',
15106: 'adhoc' => {},
15107: );
1.118 jms 15108: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 15109: %current = %{$domconfig{'helpsettings'}};
15110: }
1.285 raeburn 15111: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 15112: foreach my $item (@toggles) {
15113: if ($defaultchecked{$item} eq 'on') {
15114: if ($current{$item} eq '') {
15115: if ($env{'form.'.$item} eq '0') {
15116: $changes{$item} = 1;
15117: }
15118: } elsif ($current{$item} ne $env{'form.'.$item}) {
15119: $changes{$item} = 1;
15120: }
15121: } elsif ($defaultchecked{$item} eq 'off') {
15122: if ($current{$item} eq '') {
15123: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 15124: $changes{$item} = 1;
15125: }
1.282 raeburn 15126: } elsif ($current{$item} ne $env{'form.'.$item}) {
15127: $changes{$item} = 1;
15128: }
15129: }
15130: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
15131: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
15132: }
15133: }
1.285 raeburn 15134: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 15135: my $confname = $dom.'-domainconfig';
15136: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 15137: my (@allpos,%newsettings,%changedprivs,$newrole);
15138: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 15139: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 15140: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 15141: my %lt = &Apache::lonlocal::texthash(
15142: s => 'system',
15143: d => 'domain',
15144: order => 'Display order',
15145: access => 'Role usage',
1.291 raeburn 15146: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 15147: dh => 'All with domain helpdesk role',
15148: da => 'All with domain helpdesk assistant role',
1.285 raeburn 15149: none => 'None',
15150: status => 'Determined based on institutional status',
15151: inc => 'Include all, but exclude specific personnel',
15152: exc => 'Exclude all, but include specific personnel',
15153: );
15154: for (my $num=0; $num<=$maxnum; $num++) {
15155: my ($prefix,$identifier,$rolename,%curr);
15156: if ($num == $maxnum) {
15157: next unless ($env{'form.newcusthelp'} == $maxnum);
15158: $identifier = 'custhelp'.$num;
15159: $prefix = 'helproles_'.$num;
15160: $rolename = $env{'form.custhelpname'.$num};
15161: $rolename=~s/[^A-Za-z0-9]//gs;
15162: next if ($rolename eq '');
15163: next if (exists($existing{'rolesdef_'.$rolename}));
15164: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15165: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15166: $newprivs{'c'},$confname,$dom);
15167: if ($result ne 'ok') {
15168: $errors .= '<li><span class="LC_error">'.
15169: &mt('An error occurred storing the new custom role: [_1]',
15170: $result).'</span></li>';
15171: next;
15172: } else {
15173: $changedprivs{$rolename} = \%newprivs;
15174: $newrole = $rolename;
15175: }
15176: } else {
15177: $prefix = 'helproles_'.$num;
15178: $rolename = $env{'form.'.$prefix};
15179: next if ($rolename eq '');
15180: next unless (exists($existing{'rolesdef_'.$rolename}));
15181: $identifier = 'custhelp'.$num;
15182: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15183: my %currprivs;
1.289 raeburn 15184: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 15185: split(/\_/,$existing{'rolesdef_'.$rolename});
15186: foreach my $level ('c','d','s') {
15187: if ($newprivs{$level} ne $currprivs{$level}) {
15188: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15189: $newprivs{'c'},$confname,$dom);
15190: if ($result ne 'ok') {
15191: $errors .= '<li><span class="LC_error">'.
15192: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
15193: $rolename,$result).'</span></li>';
15194: } else {
15195: $changedprivs{$rolename} = \%newprivs;
15196: }
15197: last;
15198: }
15199: }
15200: if (ref($current{'adhoc'}) eq 'HASH') {
15201: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15202: %curr = %{$current{'adhoc'}{$rolename}};
15203: }
15204: }
15205: }
15206: my $newpos = $env{'form.'.$prefix.'_pos'};
15207: $newpos =~ s/\D+//g;
15208: $allpos[$newpos] = $rolename;
15209: my $newdesc = $env{'form.'.$prefix.'_desc'};
15210: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
15211: if ($curr{'desc'}) {
15212: if ($curr{'desc'} ne $newdesc) {
15213: $changes{'customrole'}{$rolename}{'desc'} = 1;
15214: $newsettings{$rolename}{'desc'} = $newdesc;
15215: }
15216: } elsif ($newdesc ne '') {
15217: $changes{'customrole'}{$rolename}{'desc'} = 1;
15218: $newsettings{$rolename}{'desc'} = $newdesc;
15219: }
15220: my $access = $env{'form.'.$prefix.'_access'};
15221: if (grep(/^\Q$access\E$/,@accesstypes)) {
15222: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
15223: if ($access eq 'status') {
15224: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
15225: if (scalar(@statuses) == 0) {
1.289 raeburn 15226: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 15227: } else {
15228: my (@shownstatus,$numtypes);
15229: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15230: if (ref($types) eq 'ARRAY') {
15231: $numtypes = scalar(@{$types});
15232: foreach my $type (sort(@statuses)) {
15233: if ($type eq 'default') {
15234: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15235: } elsif (grep(/^\Q$type\E$/,@{$types})) {
15236: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15237: push(@shownstatus,$usertypes->{$type});
15238: }
15239: }
15240: }
15241: if (grep(/^default$/,@statuses)) {
15242: push(@shownstatus,$othertitle);
15243: }
15244: if (scalar(@shownstatus) == 1+$numtypes) {
15245: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
15246: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
15247: } else {
15248: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
15249: if (ref($curr{'status'}) eq 'ARRAY') {
15250: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15251: if (@diffs) {
15252: $changes{'customrole'}{$rolename}{$access} = 1;
15253: }
15254: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15255: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 15256: }
1.166 raeburn 15257: }
15258: }
1.285 raeburn 15259: } elsif (($access eq 'inc') || ($access eq 'exc')) {
15260: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
15261: my @newspecstaff;
15262: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15263: foreach my $person (sort(@personnel)) {
15264: if ($domhelpdesk{$person}) {
15265: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
15266: }
15267: }
15268: if (ref($curr{$access}) eq 'ARRAY') {
15269: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15270: if (@diffs) {
15271: $changes{'customrole'}{$rolename}{$access} = 1;
15272: }
15273: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15274: $changes{'customrole'}{$rolename}{$access} = 1;
15275: }
15276: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15277: my ($uname,$udom) = split(/:/,$person);
15278: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
15279: }
15280: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 15281: }
1.285 raeburn 15282: } else {
15283: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
15284: }
15285: unless ($curr{'access'} eq $access) {
15286: $changes{'customrole'}{$rolename}{'access'} = 1;
15287: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 15288: }
15289: }
1.285 raeburn 15290: if (@allpos > 0) {
15291: my $idx = 0;
15292: foreach my $rolename (@allpos) {
15293: if ($rolename ne '') {
15294: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
15295: if (ref($current{'adhoc'}) eq 'HASH') {
15296: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15297: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
15298: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 15299: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 15300: }
15301: }
1.282 raeburn 15302: }
1.285 raeburn 15303: $idx ++;
1.166 raeburn 15304: }
15305: }
1.118 jms 15306: }
1.123 jms 15307: my $putresult;
15308: if (keys(%changes) > 0) {
1.166 raeburn 15309: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 15310: if ($putresult eq 'ok') {
1.285 raeburn 15311: if (ref($helphash{'helpsettings'}) eq 'HASH') {
15312: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
15313: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
15314: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
15315: }
15316: }
15317: my $cachetime = 24*60*60;
15318: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15319: if (ref($lastactref) eq 'HASH') {
15320: $lastactref->{'domdefaults'} = 1;
15321: }
15322: } else {
15323: $errors .= '<li><span class="LC_error">'.
15324: &mt('An error occurred storing the settings: [_1]',
15325: $putresult).'</span></li>';
15326: }
15327: }
15328: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
15329: $resulttext = &mt('Changes made:').'<ul>';
15330: my (%shownprivs,@levelorder);
15331: @levelorder = ('c','d','s');
15332: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 15333: foreach my $item (sort(keys(%changes))) {
15334: if ($item eq 'submitbugs') {
15335: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
15336: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
15337: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 15338: } elsif ($item eq 'customrole') {
15339: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 15340: my @keyorder = ('order','desc','access','status','exc','inc');
15341: my %keytext = &Apache::lonlocal::texthash(
15342: order => 'Order',
15343: desc => 'Role description',
15344: access => 'Role usage',
1.300 droeschl 15345: status => 'Allowed institutional types',
1.285 raeburn 15346: exc => 'Allowed personnel',
15347: inc => 'Disallowed personnel',
15348: );
1.282 raeburn 15349: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 15350: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
15351: if ($role eq $newrole) {
15352: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
15353: $role).'<ul>';
15354: } else {
15355: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15356: $role).'<ul>';
15357: }
15358: foreach my $key (@keyorder) {
15359: if ($changes{'customrole'}{$role}{$key}) {
15360: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
15361: $keytext{$key},$newsettings{$role}{$key}).
15362: '</li>';
15363: }
15364: }
15365: if (ref($changedprivs{$role}) eq 'HASH') {
15366: $shownprivs{$role} = 1;
15367: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
15368: foreach my $level (@levelorder) {
15369: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
15370: next if ($item eq '');
15371: my ($priv) = split(/\&/,$item,2);
15372: if (&Apache::lonnet::plaintext($priv)) {
15373: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
15374: unless ($level eq 'c') {
15375: $resulttext .= ' ('.$lt{$level}.')';
15376: }
15377: $resulttext .= '</li>';
15378: }
15379: }
15380: }
15381: $resulttext .= '</ul>';
15382: }
15383: $resulttext .= '</ul></li>';
15384: }
15385: }
15386: }
15387: }
15388: }
15389: }
15390: if (keys(%changedprivs)) {
15391: foreach my $role (sort(keys(%changedprivs))) {
15392: unless ($shownprivs{$role}) {
15393: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15394: $role).'<ul>'.
15395: '<li>'.&mt('Privileges set to :').'<ul>';
15396: foreach my $level (@levelorder) {
15397: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
15398: next if ($item eq '');
15399: my ($priv) = split(/\&/,$item,2);
15400: if (&Apache::lonnet::plaintext($priv)) {
15401: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
15402: unless ($level eq 'c') {
15403: $resulttext .= ' ('.$lt{$level}.')';
15404: }
15405: $resulttext .= '</li>';
15406: }
1.282 raeburn 15407: }
15408: }
1.285 raeburn 15409: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 15410: }
15411: }
15412: }
1.285 raeburn 15413: $resulttext .= '</ul>';
15414: } else {
15415: $resulttext = &mt('No changes made to help settings');
1.118 jms 15416: }
15417: if ($errors) {
1.168 raeburn 15418: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 15419: $errors.'</ul>';
1.118 jms 15420: }
15421: return $resulttext;
15422: }
15423:
1.121 raeburn 15424: sub modify_coursedefaults {
1.212 raeburn 15425: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 15426: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 15427: my %defaultchecked = (
15428: 'canuse_pdfforms' => 'off',
15429: 'uselcmath' => 'on',
15430: 'usejsme' => 'on'
15431: );
15432: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 15433: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 15434: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
15435: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
15436: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 15437: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 15438: my %staticdefaults = (
15439: anonsurvey_threshold => 10,
15440: uploadquota => 500,
1.257 raeburn 15441: postsubmit => 60,
1.276 raeburn 15442: mysqltables => 172800,
1.198 raeburn 15443: );
1.314 raeburn 15444: my %texoptions = (
15445: MathJax => 'MathJax',
15446: mimetex => &mt('Convert to Images'),
15447: tth => &mt('TeX to HTML'),
15448: );
1.121 raeburn 15449: $defaultshash{'coursedefaults'} = {};
15450:
15451: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
15452: if ($domconfig{'coursedefaults'} eq '') {
15453: $domconfig{'coursedefaults'} = {};
15454: }
15455: }
15456:
15457: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
15458: foreach my $item (@toggles) {
15459: if ($defaultchecked{$item} eq 'on') {
15460: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15461: ($env{'form.'.$item} eq '0')) {
15462: $changes{$item} = 1;
1.192 raeburn 15463: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 15464: $changes{$item} = 1;
15465: }
15466: } elsif ($defaultchecked{$item} eq 'off') {
15467: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15468: ($env{'form.'.$item} eq '1')) {
15469: $changes{$item} = 1;
15470: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
15471: $changes{$item} = 1;
15472: }
15473: }
15474: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
15475: }
1.198 raeburn 15476: foreach my $item (@numbers) {
15477: my ($currdef,$newdef);
1.208 raeburn 15478: $newdef = $env{'form.'.$item};
1.198 raeburn 15479: if ($item eq 'anonsurvey_threshold') {
15480: $currdef = $domconfig{'coursedefaults'}{$item};
15481: $newdef =~ s/\D//g;
15482: if ($newdef eq '' || $newdef < 1) {
15483: $newdef = 1;
15484: }
15485: $defaultshash{'coursedefaults'}{$item} = $newdef;
15486: } else {
1.276 raeburn 15487: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
15488: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
15489: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 15490: }
15491: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 15492: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 15493: }
15494: if ($currdef ne $newdef) {
15495: my $staticdef;
15496: if ($item eq 'anonsurvey_threshold') {
15497: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
15498: $changes{$item} = 1;
15499: }
1.276 raeburn 15500: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 15501: my $setting = $1;
1.276 raeburn 15502: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
15503: $changes{$setting} = 1;
1.198 raeburn 15504: }
15505: }
1.139 raeburn 15506: }
15507: }
1.314 raeburn 15508: my $texengine;
15509: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
15510: $texengine = $env{'form.texengine'};
15511: if ($defaultshash{'coursedefaults'}{'texengine'} eq '') {
15512: unless ($texengine eq 'MathJax') {
15513: $changes{'texengine'} = 1;
15514: }
15515: } elsif ($defaultshash{'coursedefaults'}{'texengine'} ne $texengine) {
15516: $changes{'texengine'} = 1;
15517: }
15518: }
15519: if ($texengine ne '') {
15520: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
15521: }
1.264 raeburn 15522: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
15523: my @currclonecode;
15524: if (ref($currclone) eq 'HASH') {
15525: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
15526: @currclonecode = @{$currclone->{'instcode'}};
15527: }
15528: }
15529: my $newclone;
1.289 raeburn 15530: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 15531: $newclone = $env{'form.canclone'};
15532: }
15533: if ($newclone eq 'instcode') {
15534: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
15535: my (%codedefaults,@code_order,@clonecode);
15536: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
15537: \@code_order);
15538: foreach my $item (@code_order) {
15539: if (grep(/^\Q$item\E$/,@newcodes)) {
15540: push(@clonecode,$item);
15541: }
15542: }
15543: if (@clonecode) {
15544: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
15545: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
15546: if (@diffs) {
15547: $changes{'canclone'} = 1;
15548: }
15549: } else {
15550: $newclone eq '';
15551: }
15552: } elsif ($newclone ne '') {
1.289 raeburn 15553: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
15554: }
1.264 raeburn 15555: if ($newclone ne $currclone) {
15556: $changes{'canclone'} = 1;
15557: }
1.257 raeburn 15558: my %credits;
15559: foreach my $type (@types) {
15560: unless ($type eq 'community') {
15561: $credits{$type} = $env{'form.'.$type.'_credits'};
15562: $credits{$type} =~ s/[^\d.]+//g;
15563: }
15564: }
15565: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
15566: ($env{'form.coursecredits'} eq '1')) {
15567: $changes{'coursecredits'} = 1;
15568: foreach my $type (keys(%credits)) {
15569: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15570: }
15571: } else {
1.289 raeburn 15572: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 15573: foreach my $type (@types) {
15574: unless ($type eq 'community') {
1.289 raeburn 15575: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 15576: $changes{'coursecredits'} = 1;
15577: }
15578: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15579: }
15580: }
15581: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15582: foreach my $type (@types) {
15583: unless ($type eq 'community') {
15584: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
15585: $changes{'coursecredits'} = 1;
15586: last;
15587: }
15588: }
15589: }
15590: }
15591: }
15592: if ($env{'form.postsubmit'} eq '1') {
15593: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
15594: my %currtimeout;
15595: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15596: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
15597: $changes{'postsubmit'} = 1;
15598: }
15599: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15600: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
15601: }
15602: } else {
15603: $changes{'postsubmit'} = 1;
15604: }
15605: foreach my $type (@types) {
15606: my $timeout = $env{'form.'.$type.'_timeout'};
15607: $timeout =~ s/\D//g;
15608: if ($timeout == $staticdefaults{'postsubmit'}) {
15609: $timeout = '';
15610: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
15611: $timeout = '0';
15612: }
15613: unless ($timeout eq '') {
15614: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
15615: }
15616: if (exists($currtimeout{$type})) {
15617: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 15618: $changes{'postsubmit'} = 1;
1.257 raeburn 15619: }
15620: } elsif ($timeout ne '') {
15621: $changes{'postsubmit'} = 1;
15622: }
15623: }
15624: } else {
15625: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
15626: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15627: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
15628: $changes{'postsubmit'} = 1;
15629: }
15630: } else {
15631: $changes{'postsubmit'} = 1;
15632: }
1.192 raeburn 15633: }
1.121 raeburn 15634: }
15635: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
15636: $dom);
15637: if ($putresult eq 'ok') {
15638: if (keys(%changes) > 0) {
1.213 raeburn 15639: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 15640: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 15641: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.314 raeburn 15642: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
15643: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','texengine') {
1.257 raeburn 15644: if ($changes{$item}) {
15645: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
15646: }
1.289 raeburn 15647: }
1.192 raeburn 15648: if ($changes{'coursecredits'}) {
15649: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 15650: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
15651: $domdefaults{$type.'credits'} =
15652: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
15653: }
15654: }
15655: }
15656: if ($changes{'postsubmit'}) {
15657: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15658: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
15659: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15660: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
15661: $domdefaults{$type.'postsubtimeout'} =
15662: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15663: }
15664: }
1.192 raeburn 15665: }
15666: }
1.198 raeburn 15667: if ($changes{'uploadquota'}) {
15668: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15669: foreach my $type (@types) {
15670: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
15671: }
15672: }
15673: }
1.264 raeburn 15674: if ($changes{'canclone'}) {
15675: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15676: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15677: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
15678: if (@clonecodes) {
15679: $domdefaults{'canclone'} = join('+',@clonecodes);
15680: }
15681: }
15682: } else {
15683: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
15684: }
15685: }
1.121 raeburn 15686: my $cachetime = 24*60*60;
15687: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 15688: if (ref($lastactref) eq 'HASH') {
15689: $lastactref->{'domdefaults'} = 1;
15690: }
1.121 raeburn 15691: }
15692: $resulttext = &mt('Changes made:').'<ul>';
15693: foreach my $item (sort(keys(%changes))) {
15694: if ($item eq 'canuse_pdfforms') {
15695: if ($env{'form.'.$item} eq '1') {
15696: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
15697: } else {
15698: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
15699: }
1.257 raeburn 15700: } elsif ($item eq 'uselcmath') {
15701: if ($env{'form.'.$item} eq '1') {
15702: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
15703: } else {
15704: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
15705: }
15706: } elsif ($item eq 'usejsme') {
15707: if ($env{'form.'.$item} eq '1') {
15708: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
15709: } else {
1.289 raeburn 15710: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 15711: }
1.314 raeburn 15712: } elsif ($item eq 'texengine') {
15713: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
15714: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
15715: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
15716: }
1.139 raeburn 15717: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 15718: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 15719: } elsif ($item eq 'uploadquota') {
15720: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15721: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
15722: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
15723: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 15724: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 15725: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 15726: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
15727: '</ul>'.
15728: '</li>';
15729: } else {
15730: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
15731: }
1.276 raeburn 15732: } elsif ($item eq 'mysqltables') {
15733: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
15734: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
15735: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
15736: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
15737: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
15738: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
15739: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
15740: '</ul>'.
15741: '</li>';
15742: } else {
15743: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
15744: }
1.257 raeburn 15745: } elsif ($item eq 'postsubmit') {
15746: if ($domdefaults{'postsubmit'} eq 'off') {
15747: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
15748: } else {
15749: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 15750: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 15751: $resulttext .= &mt('durations:').'<ul>';
15752: foreach my $type (@types) {
15753: $resulttext .= '<li>';
15754: my $timeout;
15755: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15756: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15757: }
15758: my $display;
15759: if ($timeout eq '0') {
15760: $display = &mt('unlimited');
15761: } elsif ($timeout eq '') {
15762: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
15763: } else {
15764: $display = &mt('[quant,_1,second]',$timeout);
15765: }
15766: if ($type eq 'community') {
15767: $resulttext .= &mt('Communities');
15768: } elsif ($type eq 'official') {
15769: $resulttext .= &mt('Official courses');
15770: } elsif ($type eq 'unofficial') {
15771: $resulttext .= &mt('Unofficial courses');
15772: } elsif ($type eq 'textbook') {
15773: $resulttext .= &mt('Textbook courses');
1.271 raeburn 15774: } elsif ($type eq 'placement') {
15775: $resulttext .= &mt('Placement tests');
1.257 raeburn 15776: }
15777: $resulttext .= ' -- '.$display.'</li>';
15778: }
15779: $resulttext .= '</ul>';
15780: }
1.289 raeburn 15781: $resulttext .= '</li>';
1.257 raeburn 15782: }
1.192 raeburn 15783: } elsif ($item eq 'coursecredits') {
15784: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15785: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 15786: ($domdefaults{'unofficialcredits'} eq '') &&
15787: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 15788: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
15789: } else {
15790: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
15791: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
15792: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 15793: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 15794: '</ul>'.
15795: '</li>';
15796: }
15797: } else {
15798: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
15799: }
1.264 raeburn 15800: } elsif ($item eq 'canclone') {
15801: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15802: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15803: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
15804: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
15805: }
15806: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
15807: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
15808: } else {
1.289 raeburn 15809: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 15810: }
1.140 raeburn 15811: }
1.121 raeburn 15812: }
15813: $resulttext .= '</ul>';
15814: } else {
15815: $resulttext = &mt('No changes made to course defaults');
15816: }
15817: } else {
15818: $resulttext = '<span class="LC_error">'.
15819: &mt('An error occurred: [_1]',$putresult).'</span>';
15820: }
15821: return $resulttext;
15822: }
15823:
1.231 raeburn 15824: sub modify_selfenrollment {
15825: my ($dom,$lastactref,%domconfig) = @_;
15826: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 15827: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 15828: my %titles = &tool_titles();
1.232 raeburn 15829: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
15830: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 15831: $ordered{'default'} = ['types','registered','approval','limit'];
15832:
15833: my (%roles,%shown,%toplevel);
15834: $roles{'0'} = &Apache::lonnet::plaintext('dc');
15835:
15836: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
15837: if ($domconfig{'selfenrollment'} eq '') {
15838: $domconfig{'selfenrollment'} = {};
15839: }
15840: }
15841: %toplevel = (
15842: admin => 'Configuration Rights',
15843: default => 'Default settings',
15844: validation => 'Validation of self-enrollment requests',
15845: );
1.233 raeburn 15846: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 15847:
15848: if (ref($ordered{'admin'}) eq 'ARRAY') {
15849: foreach my $item (@{$ordered{'admin'}}) {
15850: foreach my $type (@types) {
15851: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
15852: $selfenrollhash{'admin'}{$type}{$item} = 1;
15853: } else {
15854: $selfenrollhash{'admin'}{$type}{$item} = 0;
15855: }
15856: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
15857: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
15858: if ($selfenrollhash{'admin'}{$type}{$item} ne
15859: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
15860: push(@{$changes{'admin'}{$type}},$item);
15861: }
15862: } else {
15863: if (!$selfenrollhash{'admin'}{$type}{$item}) {
15864: push(@{$changes{'admin'}{$type}},$item);
15865: }
15866: }
15867: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
15868: push(@{$changes{'admin'}{$type}},$item);
15869: }
15870: }
15871: }
15872: }
15873:
15874: foreach my $item (@{$ordered{'default'}}) {
15875: foreach my $type (@types) {
15876: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
15877: if ($item eq 'types') {
15878: unless (($value eq 'all') || ($value eq 'dom')) {
15879: $value = '';
15880: }
15881: } elsif ($item eq 'registered') {
15882: unless ($value eq '1') {
15883: $value = 0;
15884: }
15885: } elsif ($item eq 'approval') {
15886: unless ($value =~ /^[012]$/) {
15887: $value = 0;
15888: }
15889: } else {
15890: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
15891: $value = 'none';
15892: }
15893: }
15894: $selfenrollhash{'default'}{$type}{$item} = $value;
15895: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
15896: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
15897: if ($selfenrollhash{'default'}{$type}{$item} ne
15898: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
15899: push(@{$changes{'default'}{$type}},$item);
15900: }
15901: } else {
15902: push(@{$changes{'default'}{$type}},$item);
15903: }
15904: } else {
15905: push(@{$changes{'default'}{$type}},$item);
15906: }
15907: if ($item eq 'limit') {
15908: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
15909: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
15910: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
15911: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
15912: }
15913: } else {
15914: $selfenrollhash{'default'}{$type}{'cap'} = '';
15915: }
15916: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
15917: if ($selfenrollhash{'default'}{$type}{'cap'} ne
15918: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
15919: push(@{$changes{'default'}{$type}},'cap');
15920: }
15921: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
15922: push(@{$changes{'default'}{$type}},'cap');
15923: }
15924: }
15925: }
15926: }
15927:
15928: foreach my $item (@{$itemsref}) {
15929: if ($item eq 'fields') {
15930: my @changed;
15931: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
15932: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
15933: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
15934: }
15935: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
15936: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
15937: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
15938: $domconfig{'selfenrollment'}{'validation'}{$item});
15939: } else {
15940: @changed = @{$selfenrollhash{'validation'}{$item}};
15941: }
15942: } else {
15943: @changed = @{$selfenrollhash{'validation'}{$item}};
15944: }
15945: if (@changed) {
15946: if ($selfenrollhash{'validation'}{$item}) {
15947: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
15948: } else {
15949: $changes{'validation'}{$item} = &mt('None');
15950: }
15951: }
15952: } else {
15953: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
15954: if ($item eq 'markup') {
15955: if ($env{'form.selfenroll_validation_'.$item}) {
15956: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
15957: }
15958: }
15959: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
15960: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
15961: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
15962: }
15963: }
15964: }
15965: }
15966:
15967: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
15968: $dom);
15969: if ($putresult eq 'ok') {
15970: if (keys(%changes) > 0) {
15971: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15972: $resulttext = &mt('Changes made:').'<ul>';
15973: foreach my $key ('admin','default','validation') {
15974: if (ref($changes{$key}) eq 'HASH') {
15975: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
15976: if ($key eq 'validation') {
15977: foreach my $item (@{$itemsref}) {
15978: if (exists($changes{$key}{$item})) {
15979: if ($item eq 'markup') {
15980: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
15981: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
15982: } else {
15983: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
15984: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
15985: }
15986: }
15987: }
15988: } else {
15989: foreach my $type (@types) {
15990: if ($type eq 'community') {
15991: $roles{'1'} = &mt('Community personnel');
15992: } else {
15993: $roles{'1'} = &mt('Course personnel');
15994: }
15995: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 15996: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
15997: if ($key eq 'admin') {
15998: my @mgrdc = ();
15999: if (ref($ordered{$key}) eq 'ARRAY') {
16000: foreach my $item (@{$ordered{'admin'}}) {
16001: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
16002: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
16003: push(@mgrdc,$item);
16004: }
16005: }
16006: }
16007: if (@mgrdc) {
16008: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
16009: } else {
16010: delete($domdefaults{$type.'selfenrolladmdc'});
16011: }
16012: }
16013: } else {
16014: if (ref($ordered{$key}) eq 'ARRAY') {
16015: foreach my $item (@{$ordered{$key}}) {
16016: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
16017: $domdefaults{$type.'selfenroll'.$item} =
16018: $selfenrollhash{$key}{$type}{$item};
16019: }
16020: }
16021: }
16022: }
16023: }
1.231 raeburn 16024: $resulttext .= '<li>'.$titles{$type}.'<ul>';
16025: foreach my $item (@{$ordered{$key}}) {
16026: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
16027: $resulttext .= '<li>';
16028: if ($key eq 'admin') {
16029: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
16030: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
16031: } else {
16032: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
16033: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
16034: }
16035: $resulttext .= '</li>';
16036: }
16037: }
16038: $resulttext .= '</ul></li>';
16039: }
16040: }
16041: $resulttext .= '</ul></li>';
16042: }
16043: }
1.305 raeburn 16044: }
16045: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
16046: my $cachetime = 24*60*60;
16047: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16048: if (ref($lastactref) eq 'HASH') {
16049: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 16050: }
1.231 raeburn 16051: }
16052: $resulttext .= '</ul>';
16053: } else {
16054: $resulttext = &mt('No changes made to self-enrollment settings');
16055: }
16056: } else {
16057: $resulttext = '<span class="LC_error">'.
16058: &mt('An error occurred: [_1]',$putresult).'</span>';
16059: }
16060: return $resulttext;
16061: }
16062:
1.137 raeburn 16063: sub modify_usersessions {
1.212 raeburn 16064: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 16065: my @hostingtypes = ('version','excludedomain','includedomain');
16066: my @offloadtypes = ('primary','default');
16067: my %types = (
16068: remote => \@hostingtypes,
16069: hosted => \@hostingtypes,
16070: spares => \@offloadtypes,
16071: );
16072: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 16073: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 16074: my (%by_ip,%by_location,@intdoms,@instdoms);
16075: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 16076: my @locations = sort(keys(%by_location));
1.137 raeburn 16077: my (%defaultshash,%changes);
16078: foreach my $prefix (@prefixes) {
16079: $defaultshash{'usersessions'}{$prefix} = {};
16080: }
1.212 raeburn 16081: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 16082: my $resulttext;
1.138 raeburn 16083: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 16084: foreach my $prefix (@prefixes) {
1.145 raeburn 16085: next if ($prefix eq 'spares');
16086: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 16087: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16088: if ($type eq 'version') {
16089: my $value = $env{'form.'.$prefix.'_'.$type};
16090: my $okvalue;
16091: if ($value ne '') {
16092: if (grep(/^\Q$value\E$/,@lcversions)) {
16093: $okvalue = $value;
16094: }
16095: }
16096: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16097: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
16098: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
16099: if ($inuse == 0) {
16100: $changes{$prefix}{$type} = 1;
16101: } else {
16102: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
16103: $changes{$prefix}{$type} = 1;
16104: }
16105: if ($okvalue ne '') {
16106: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16107: }
16108: }
16109: } else {
16110: if (($inuse == 1) && ($okvalue ne '')) {
16111: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16112: $changes{$prefix}{$type} = 1;
16113: }
16114: }
16115: } else {
16116: if (($inuse == 1) && ($okvalue ne '')) {
16117: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16118: $changes{$prefix}{$type} = 1;
16119: }
16120: }
16121: } else {
16122: if (($inuse == 1) && ($okvalue ne '')) {
16123: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16124: $changes{$prefix}{$type} = 1;
16125: }
16126: }
16127: } else {
16128: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16129: my @okvals;
16130: foreach my $val (@vals) {
1.138 raeburn 16131: if ($val =~ /:/) {
16132: my @items = split(/:/,$val);
16133: foreach my $item (@items) {
16134: if (ref($by_location{$item}) eq 'ARRAY') {
16135: push(@okvals,$item);
16136: }
16137: }
16138: } else {
16139: if (ref($by_location{$val}) eq 'ARRAY') {
16140: push(@okvals,$val);
16141: }
1.137 raeburn 16142: }
16143: }
16144: @okvals = sort(@okvals);
16145: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16146: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
16147: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
16148: if ($inuse == 0) {
16149: $changes{$prefix}{$type} = 1;
16150: } else {
16151: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16152: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
16153: if (@changed > 0) {
16154: $changes{$prefix}{$type} = 1;
16155: }
16156: }
16157: } else {
16158: if ($inuse == 1) {
16159: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16160: $changes{$prefix}{$type} = 1;
16161: }
16162: }
16163: } else {
16164: if ($inuse == 1) {
16165: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16166: $changes{$prefix}{$type} = 1;
16167: }
16168: }
16169: } else {
16170: if ($inuse == 1) {
16171: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16172: $changes{$prefix}{$type} = 1;
16173: }
16174: }
16175: }
16176: }
16177: }
1.145 raeburn 16178:
16179: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 16180: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 16181: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
16182: my $savespares;
16183:
16184: foreach my $lonhost (sort(keys(%servers))) {
16185: my $serverhomeID =
16186: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 16187: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 16188: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
16189: my %spareschg;
16190: foreach my $type (@{$types{'spares'}}) {
16191: my @okspares;
16192: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
16193: foreach my $server (@checked) {
1.152 raeburn 16194: if (&Apache::lonnet::hostname($server) ne '') {
16195: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
16196: unless (grep(/^\Q$server\E$/,@okspares)) {
16197: push(@okspares,$server);
16198: }
1.145 raeburn 16199: }
16200: }
16201: }
16202: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
16203: my $newspare;
1.152 raeburn 16204: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
16205: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 16206: $newspare = $new;
16207: }
16208: }
1.152 raeburn 16209: my @spares;
16210: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
16211: @spares = sort(@okspares,$newspare);
16212: } else {
16213: @spares = sort(@okspares);
16214: }
16215: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 16216: if (ref($spareid{$lonhost}) eq 'HASH') {
16217: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 16218: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 16219: if (@diffs > 0) {
16220: $spareschg{$type} = 1;
16221: }
16222: }
16223: }
16224: }
16225: if (keys(%spareschg) > 0) {
16226: $changes{'spares'}{$lonhost} = \%spareschg;
16227: }
16228: }
1.261 raeburn 16229: $defaultshash{'usersessions'}{'offloadnow'} = {};
16230: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
16231: my @okoffload;
16232: if (@offloadnow) {
16233: foreach my $server (@offloadnow) {
16234: if (&Apache::lonnet::hostname($server) ne '') {
16235: unless (grep(/^\Q$server\E$/,@okoffload)) {
16236: push(@okoffload,$server);
16237: }
16238: }
16239: }
16240: if (@okoffload) {
16241: foreach my $lonhost (@okoffload) {
16242: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
16243: }
16244: }
16245: }
1.145 raeburn 16246: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16247: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
16248: if (ref($changes{'spares'}) eq 'HASH') {
16249: if (keys(%{$changes{'spares'}}) > 0) {
16250: $savespares = 1;
16251: }
16252: }
16253: } else {
16254: $savespares = 1;
16255: }
1.261 raeburn 16256: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
16257: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
16258: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
16259: $changes{'offloadnow'} = 1;
16260: last;
16261: }
16262: }
16263: unless ($changes{'offloadnow'}) {
1.289 raeburn 16264: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
1.261 raeburn 16265: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
16266: $changes{'offloadnow'} = 1;
16267: last;
16268: }
16269: }
16270: }
16271: } elsif (@okoffload) {
16272: $changes{'offloadnow'} = 1;
16273: }
16274: } elsif (@okoffload) {
16275: $changes{'offloadnow'} = 1;
1.145 raeburn 16276: }
1.147 raeburn 16277: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
16278: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 16279: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16280: $dom);
16281: if ($putresult eq 'ok') {
16282: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
16283: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
16284: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
16285: }
16286: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
16287: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
16288: }
1.261 raeburn 16289: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
16290: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
16291: }
1.137 raeburn 16292: }
16293: my $cachetime = 24*60*60;
16294: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 16295: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 16296: if (ref($lastactref) eq 'HASH') {
16297: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 16298: $lastactref->{'usersessions'} = 1;
1.212 raeburn 16299: }
1.147 raeburn 16300: if (keys(%changes) > 0) {
16301: my %lt = &usersession_titles();
16302: $resulttext = &mt('Changes made:').'<ul>';
16303: foreach my $prefix (@prefixes) {
16304: if (ref($changes{$prefix}) eq 'HASH') {
16305: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
16306: if ($prefix eq 'spares') {
16307: if (ref($changes{$prefix}) eq 'HASH') {
16308: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
16309: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 16310: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 16311: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
16312: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 16313: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
16314: foreach my $type (@{$types{$prefix}}) {
16315: if ($changes{$prefix}{$lonhost}{$type}) {
16316: my $offloadto = &mt('None');
16317: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
16318: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
16319: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
16320: }
1.145 raeburn 16321: }
1.147 raeburn 16322: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 16323: }
1.137 raeburn 16324: }
16325: }
1.147 raeburn 16326: $resulttext .= '</li>';
1.137 raeburn 16327: }
16328: }
1.147 raeburn 16329: } else {
16330: foreach my $type (@{$types{$prefix}}) {
16331: if (defined($changes{$prefix}{$type})) {
16332: my $newvalue;
16333: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
16334: if (ref($defaultshash{'usersessions'}{$prefix})) {
16335: if ($type eq 'version') {
16336: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
16337: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
16338: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
16339: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
16340: }
1.145 raeburn 16341: }
16342: }
16343: }
1.147 raeburn 16344: if ($newvalue eq '') {
16345: if ($type eq 'version') {
16346: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
16347: } else {
16348: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
16349: }
1.145 raeburn 16350: } else {
1.147 raeburn 16351: if ($type eq 'version') {
16352: $newvalue .= ' '.&mt('(or later)');
16353: }
16354: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 16355: }
1.137 raeburn 16356: }
16357: }
16358: }
1.147 raeburn 16359: $resulttext .= '</ul>';
1.137 raeburn 16360: }
16361: }
1.261 raeburn 16362: if ($changes{'offloadnow'}) {
16363: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
16364: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
16365: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
16366: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
16367: $resulttext .= '<li>'.$lonhost.'</li>';
16368: }
16369: $resulttext .= '</ul>';
16370: } else {
16371: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
16372: }
16373: } else {
16374: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
16375: }
16376: }
1.147 raeburn 16377: $resulttext .= '</ul>';
16378: } else {
16379: $resulttext = $nochgmsg;
1.137 raeburn 16380: }
16381: } else {
16382: $resulttext = '<span class="LC_error">'.
16383: &mt('An error occurred: [_1]',$putresult).'</span>';
16384: }
16385: } else {
1.147 raeburn 16386: $resulttext = $nochgmsg;
1.137 raeburn 16387: }
16388: return $resulttext;
16389: }
16390:
1.275 raeburn 16391: sub modify_ssl {
16392: my ($dom,$lastactref,%domconfig) = @_;
16393: my (%by_ip,%by_location,@intdoms,@instdoms);
16394: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
16395: my @locations = sort(keys(%by_location));
16396: my %servers = &Apache::lonnet::internet_dom_servers($dom);
16397: my (%defaultshash,%changes);
16398: my $action = 'ssl';
1.293 raeburn 16399: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 16400: foreach my $prefix (@prefixes) {
16401: $defaultshash{$action}{$prefix} = {};
16402: }
16403: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16404: my $resulttext;
16405: my %iphost = &Apache::lonnet::get_iphost();
16406: my @reptypes = ('certreq','nocertreq');
16407: my @connecttypes = ('dom','intdom','other');
16408: my %types = (
1.293 raeburn 16409: connto => \@connecttypes,
16410: connfrom => \@connecttypes,
16411: replication => \@reptypes,
1.275 raeburn 16412: );
16413: foreach my $prefix (sort(keys(%types))) {
16414: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 16415: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 16416: my $value = 'yes';
16417: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
16418: $value = $env{'form.'.$prefix.'_'.$type};
16419: }
1.335 raeburn 16420: if (ref($domconfig{$action}) eq 'HASH') {
16421: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
16422: if ($domconfig{$action}{$prefix}{$type} ne '') {
16423: if ($value ne $domconfig{$action}{$prefix}{$type}) {
16424: $changes{$prefix}{$type} = 1;
16425: }
16426: $defaultshash{$action}{$prefix}{$type} = $value;
16427: } else {
16428: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 16429: $changes{$prefix}{$type} = 1;
16430: }
16431: } else {
16432: $defaultshash{$action}{$prefix}{$type} = $value;
16433: $changes{$prefix}{$type} = 1;
16434: }
16435: } else {
16436: $defaultshash{$action}{$prefix}{$type} = $value;
16437: $changes{$prefix}{$type} = 1;
16438: }
16439: if (($type eq 'dom') && (keys(%servers) == 1)) {
16440: delete($changes{$prefix}{$type});
16441: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
16442: delete($changes{$prefix}{$type});
16443: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
16444: delete($changes{$prefix}{$type});
16445: }
16446: } elsif ($prefix eq 'replication') {
16447: if (@locations > 0) {
16448: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16449: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16450: my @okvals;
16451: foreach my $val (@vals) {
16452: if ($val =~ /:/) {
16453: my @items = split(/:/,$val);
16454: foreach my $item (@items) {
16455: if (ref($by_location{$item}) eq 'ARRAY') {
16456: push(@okvals,$item);
16457: }
16458: }
16459: } else {
16460: if (ref($by_location{$val}) eq 'ARRAY') {
16461: push(@okvals,$val);
16462: }
16463: }
16464: }
16465: @okvals = sort(@okvals);
16466: if (ref($domconfig{$action}) eq 'HASH') {
16467: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
16468: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
16469: if ($inuse == 0) {
16470: $changes{$prefix}{$type} = 1;
16471: } else {
16472: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16473: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
16474: if (@changed > 0) {
16475: $changes{$prefix}{$type} = 1;
16476: }
16477: }
16478: } else {
16479: if ($inuse == 1) {
16480: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16481: $changes{$prefix}{$type} = 1;
16482: }
16483: }
16484: } else {
16485: if ($inuse == 1) {
16486: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16487: $changes{$prefix}{$type} = 1;
16488: }
16489: }
16490: } else {
16491: if ($inuse == 1) {
16492: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16493: $changes{$prefix}{$type} = 1;
16494: }
16495: }
16496: }
16497: }
16498: }
16499: }
1.336 raeburn 16500: if (keys(%changes)) {
16501: foreach my $prefix (keys(%changes)) {
16502: if (ref($changes{$prefix}) eq 'HASH') {
16503: if (scalar(keys(%{$changes{$prefix}})) == 0) {
16504: delete($changes{$prefix});
16505: }
16506: } else {
16507: delete($changes{$prefix});
16508: }
16509: }
16510: }
1.275 raeburn 16511: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
16512: if (keys(%changes) > 0) {
16513: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16514: $dom);
16515: if ($putresult eq 'ok') {
16516: if (ref($defaultshash{$action}) eq 'HASH') {
16517: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
16518: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
16519: }
1.293 raeburn 16520: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 16521: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 16522: }
16523: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 16524: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 16525: }
16526: }
16527: my $cachetime = 24*60*60;
16528: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16529: if (ref($lastactref) eq 'HASH') {
16530: $lastactref->{'domdefaults'} = 1;
16531: }
16532: if (keys(%changes) > 0) {
16533: my %titles = &ssl_titles();
16534: $resulttext = &mt('Changes made:').'<ul>';
16535: foreach my $prefix (@prefixes) {
16536: if (ref($changes{$prefix}) eq 'HASH') {
16537: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
16538: foreach my $type (@{$types{$prefix}}) {
16539: if (defined($changes{$prefix}{$type})) {
16540: my $newvalue;
16541: if (ref($defaultshash{$action}) eq 'HASH') {
16542: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 16543: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 16544: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
16545: } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
16546: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
16547: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
16548: }
16549: }
16550: }
16551: if ($newvalue eq '') {
16552: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
16553: } else {
16554: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
16555: }
16556: }
16557: }
16558: }
16559: $resulttext .= '</ul>';
16560: }
16561: }
16562: } else {
16563: $resulttext = $nochgmsg;
16564: }
16565: } else {
16566: $resulttext = '<span class="LC_error">'.
16567: &mt('An error occurred: [_1]',$putresult).'</span>';
16568: }
16569: } else {
16570: $resulttext = $nochgmsg;
16571: }
16572: return $resulttext;
16573: }
16574:
1.279 raeburn 16575: sub modify_trust {
16576: my ($dom,$lastactref,%domconfig) = @_;
16577: my (%by_ip,%by_location,@intdoms,@instdoms);
16578: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
16579: my @locations = sort(keys(%by_location));
16580: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
16581: my @types = ('exc','inc');
16582: my (%defaultshash,%changes);
16583: foreach my $prefix (@prefixes) {
16584: $defaultshash{'trust'}{$prefix} = {};
16585: }
16586: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16587: my $resulttext;
16588: foreach my $prefix (@prefixes) {
16589: foreach my $type (@types) {
16590: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16591: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16592: my @okvals;
16593: foreach my $val (@vals) {
16594: if ($val =~ /:/) {
16595: my @items = split(/:/,$val);
16596: foreach my $item (@items) {
16597: if (ref($by_location{$item}) eq 'ARRAY') {
16598: push(@okvals,$item);
16599: }
16600: }
16601: } else {
16602: if (ref($by_location{$val}) eq 'ARRAY') {
16603: push(@okvals,$val);
16604: }
16605: }
16606: }
16607: @okvals = sort(@okvals);
16608: if (ref($domconfig{'trust'}) eq 'HASH') {
16609: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
16610: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
16611: if ($inuse == 0) {
16612: $changes{$prefix}{$type} = 1;
16613: } else {
16614: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16615: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
16616: if (@changed > 0) {
16617: $changes{$prefix}{$type} = 1;
16618: }
16619: }
16620: } else {
16621: if ($inuse == 1) {
16622: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16623: $changes{$prefix}{$type} = 1;
16624: }
16625: }
16626: } else {
16627: if ($inuse == 1) {
16628: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16629: $changes{$prefix}{$type} = 1;
16630: }
16631: }
16632: } else {
16633: if ($inuse == 1) {
16634: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16635: $changes{$prefix}{$type} = 1;
16636: }
16637: }
16638: }
16639: }
16640: my $nochgmsg = &mt('No changes made to trust settings.');
16641: if (keys(%changes) > 0) {
16642: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16643: $dom);
16644: if ($putresult eq 'ok') {
16645: if (ref($defaultshash{'trust'}) eq 'HASH') {
16646: foreach my $prefix (@prefixes) {
16647: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
16648: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
16649: }
16650: }
16651: }
16652: my $cachetime = 24*60*60;
16653: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16654: if (ref($lastactref) eq 'HASH') {
16655: $lastactref->{'domdefaults'} = 1;
16656: }
16657: if (keys(%changes) > 0) {
16658: my %lt = &trust_titles();
16659: $resulttext = &mt('Changes made:').'<ul>';
16660: foreach my $prefix (@prefixes) {
16661: if (ref($changes{$prefix}) eq 'HASH') {
16662: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
16663: foreach my $type (@types) {
16664: if (defined($changes{$prefix}{$type})) {
16665: my $newvalue;
16666: if (ref($defaultshash{'trust'}) eq 'HASH') {
16667: if (ref($defaultshash{'trust'}{$prefix})) {
16668: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
16669: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
16670: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
16671: }
16672: }
16673: }
16674: }
16675: if ($newvalue eq '') {
16676: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
16677: } else {
16678: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
16679: }
16680: }
16681: }
16682: $resulttext .= '</ul>';
16683: }
16684: }
16685: $resulttext .= '</ul>';
16686: } else {
16687: $resulttext = $nochgmsg;
16688: }
16689: } else {
16690: $resulttext = '<span class="LC_error">'.
16691: &mt('An error occurred: [_1]',$putresult).'</span>';
16692: }
16693: } else {
16694: $resulttext = $nochgmsg;
16695: }
16696: return $resulttext;
16697: }
16698:
1.150 raeburn 16699: sub modify_loadbalancing {
16700: my ($dom,%domconfig) = @_;
16701: my $primary_id = &Apache::lonnet::domain($dom,'primary');
16702: my $intdom = &Apache::lonnet::internet_dom($primary_id);
16703: my ($othertitle,$usertypes,$types) =
16704: &Apache::loncommon::sorted_inst_types($dom);
16705: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 16706: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 16707: my @sparestypes = ('primary','default');
16708: my %typetitles = &sparestype_titles();
16709: my $resulttext;
1.171 raeburn 16710: my (%currbalancer,%currtargets,%currrules,%existing);
16711: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
16712: %existing = %{$domconfig{'loadbalancing'}};
16713: }
16714: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
16715: \%currtargets,\%currrules);
16716: my ($saveloadbalancing,%defaultshash,%changes);
16717: my ($alltypes,$othertypes,$titles) =
16718: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
16719: my %ruletitles = &offloadtype_text();
16720: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
16721: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
16722: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
16723: if ($balancer eq '') {
16724: next;
16725: }
1.210 raeburn 16726: if (!exists($servers{$balancer})) {
1.171 raeburn 16727: if (exists($currbalancer{$balancer})) {
16728: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 16729: }
1.171 raeburn 16730: next;
16731: }
16732: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
16733: push(@{$changes{'delete'}},$balancer);
16734: next;
16735: }
16736: if (!exists($currbalancer{$balancer})) {
16737: push(@{$changes{'add'}},$balancer);
16738: }
16739: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
16740: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
16741: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
16742: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
16743: $saveloadbalancing = 1;
16744: }
16745: foreach my $sparetype (@sparestypes) {
16746: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
16747: my @offloadto;
16748: foreach my $target (@targets) {
16749: if (($servers{$target}) && ($target ne $balancer)) {
16750: if ($sparetype eq 'default') {
16751: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
16752: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 16753: }
16754: }
1.171 raeburn 16755: unless(grep(/^\Q$target\E$/,@offloadto)) {
16756: push(@offloadto,$target);
16757: }
1.150 raeburn 16758: }
16759: }
1.284 raeburn 16760: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
16761: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
16762: push(@offloadto,$balancer);
16763: }
16764: }
16765: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 16766: }
1.171 raeburn 16767: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 16768: foreach my $sparetype (@sparestypes) {
1.171 raeburn 16769: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
16770: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 16771: if (@targetdiffs > 0) {
1.171 raeburn 16772: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 16773: }
1.171 raeburn 16774: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16775: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16776: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 16777: }
16778: }
16779: }
16780: } else {
1.171 raeburn 16781: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 16782: foreach my $sparetype (@sparestypes) {
1.171 raeburn 16783: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16784: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16785: $changes{'curr'}{$balancer}{'targets'} = 1;
16786: }
1.150 raeburn 16787: }
16788: }
1.210 raeburn 16789: }
1.150 raeburn 16790: }
16791: my $ishomedom;
1.171 raeburn 16792: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
16793: $ishomedom = 1;
1.150 raeburn 16794: }
16795: if (ref($alltypes) eq 'ARRAY') {
16796: foreach my $type (@{$alltypes}) {
16797: my $rule;
1.210 raeburn 16798: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 16799: (!$ishomedom)) {
1.171 raeburn 16800: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
16801: }
16802: if ($rule eq 'specific') {
1.255 raeburn 16803: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 16804: if (exists($servers{$specifiedhost})) {
1.255 raeburn 16805: $rule = $specifiedhost;
16806: }
1.150 raeburn 16807: }
1.171 raeburn 16808: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
16809: if (ref($currrules{$balancer}) eq 'HASH') {
16810: if ($rule ne $currrules{$balancer}{$type}) {
16811: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 16812: }
16813: } elsif ($rule ne '') {
1.171 raeburn 16814: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 16815: }
16816: }
16817: }
1.171 raeburn 16818: }
16819: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
16820: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
16821: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
16822: $defaultshash{'loadbalancing'} = {};
16823: }
16824: my $putresult = &Apache::lonnet::put_dom('configuration',
16825: \%defaultshash,$dom);
16826: if ($putresult eq 'ok') {
16827: if (keys(%changes) > 0) {
1.252 raeburn 16828: my %toupdate;
1.171 raeburn 16829: if (ref($changes{'delete'}) eq 'ARRAY') {
16830: foreach my $balancer (sort(@{$changes{'delete'}})) {
16831: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 16832: $toupdate{$balancer} = 1;
1.150 raeburn 16833: }
1.171 raeburn 16834: }
16835: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 16836: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 16837: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 16838: $toupdate{$balancer} = 1;
1.171 raeburn 16839: }
16840: }
16841: if (ref($changes{'curr'}) eq 'HASH') {
16842: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 16843: $toupdate{$balancer} = 1;
1.171 raeburn 16844: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
16845: if ($changes{'curr'}{$balancer}{'targets'}) {
16846: my %offloadstr;
16847: foreach my $sparetype (@sparestypes) {
16848: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16849: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16850: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
16851: }
16852: }
1.150 raeburn 16853: }
1.171 raeburn 16854: if (keys(%offloadstr) == 0) {
16855: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 16856: } else {
1.171 raeburn 16857: my $showoffload;
16858: foreach my $sparetype (@sparestypes) {
16859: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
16860: if (defined($offloadstr{$sparetype})) {
16861: $showoffload .= $offloadstr{$sparetype};
16862: } else {
16863: $showoffload .= &mt('None');
16864: }
16865: $showoffload .= (' 'x3);
16866: }
16867: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 16868: }
16869: }
16870: }
1.171 raeburn 16871: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
16872: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
16873: foreach my $type (@{$alltypes}) {
16874: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
16875: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
16876: my $balancetext;
16877: if ($rule eq '') {
16878: $balancetext = $ruletitles{'default'};
1.209 raeburn 16879: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 16880: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 16881: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 16882: foreach my $sparetype (@sparestypes) {
16883: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16884: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
16885: }
16886: }
1.253 raeburn 16887: foreach my $item (@{$alltypes}) {
16888: next if ($item =~ /^_LC_ipchange/);
16889: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
16890: if ($hasrule eq 'homeserver') {
16891: map { $toupdate{$_} = 1; } (keys(%libraryservers));
16892: } else {
16893: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
16894: if ($servers{$hasrule}) {
16895: $toupdate{$hasrule} = 1;
16896: }
16897: }
16898: }
16899: }
1.254 raeburn 16900: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
16901: $balancetext = $ruletitles{$rule};
16902: } else {
16903: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
16904: $balancetext = $ruletitles{'particular'}.' '.$receiver;
16905: if ($receiver) {
16906: $toupdate{$receiver};
16907: }
16908: }
16909: } else {
16910: $balancetext = $ruletitles{$rule};
1.252 raeburn 16911: }
1.171 raeburn 16912: } else {
16913: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
16914: }
1.210 raeburn 16915: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 16916: }
16917: }
16918: }
16919: }
1.252 raeburn 16920: if (keys(%toupdate)) {
16921: my %thismachine;
16922: my $updatedhere;
16923: my $cachetime = 60*60*24;
16924: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
16925: foreach my $lonhost (keys(%toupdate)) {
16926: if ($thismachine{$lonhost}) {
16927: unless ($updatedhere) {
16928: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
16929: $defaultshash{'loadbalancing'},
16930: $cachetime);
16931: $updatedhere = 1;
16932: }
16933: } else {
16934: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
16935: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
16936: }
16937: }
16938: }
1.150 raeburn 16939: }
1.171 raeburn 16940: }
16941: if ($resulttext ne '') {
16942: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 16943: } else {
16944: $resulttext = $nochgmsg;
16945: }
16946: } else {
1.171 raeburn 16947: $resulttext = $nochgmsg;
1.150 raeburn 16948: }
16949: } else {
1.171 raeburn 16950: $resulttext = '<span class="LC_error">'.
16951: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 16952: }
16953: } else {
1.171 raeburn 16954: $resulttext = $nochgmsg;
1.150 raeburn 16955: }
16956: return $resulttext;
16957: }
16958:
1.48 raeburn 16959: sub recurse_check {
16960: my ($chkcats,$categories,$depth,$name) = @_;
16961: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
16962: my $chg = 0;
16963: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
16964: my $category = $chkcats->[$depth]{$name}[$j];
16965: my $item;
16966: if ($category eq '') {
16967: $chg ++;
16968: } else {
16969: my $deeper = $depth + 1;
16970: $item = &escape($category).':'.&escape($name).':'.$depth;
16971: if ($chg) {
16972: $categories->{$item} -= $chg;
16973: }
16974: &recurse_check($chkcats,$categories,$deeper,$category);
16975: $deeper --;
16976: }
16977: }
16978: }
16979: return;
16980: }
16981:
16982: sub recurse_cat_deletes {
16983: my ($item,$coursecategories,$deletions) = @_;
16984: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
16985: my $subdepth = $depth + 1;
16986: if (ref($coursecategories) eq 'HASH') {
16987: foreach my $subitem (keys(%{$coursecategories})) {
16988: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
16989: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
16990: delete($coursecategories->{$subitem});
16991: $deletions->{$subitem} = 1;
16992: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 16993: }
1.48 raeburn 16994: }
16995: }
16996: return;
16997: }
16998:
1.125 raeburn 16999: sub active_dc_picker {
1.191 raeburn 17000: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 17001: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 17002: my @domcoord = keys(%domcoords);
17003: if (keys(%currhash)) {
17004: foreach my $dc (keys(%currhash)) {
17005: unless (exists($domcoords{$dc})) {
17006: push(@domcoord,$dc);
17007: }
17008: }
17009: }
17010: @domcoord = sort(@domcoord);
1.210 raeburn 17011: my $numdcs = scalar(@domcoord);
1.191 raeburn 17012: my $rows = 0;
17013: my $table;
1.125 raeburn 17014: if ($numdcs > 1) {
1.191 raeburn 17015: $table = '<table>';
17016: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 17017: my $rem = $i%($numinrow);
17018: if ($rem == 0) {
17019: if ($i > 0) {
1.191 raeburn 17020: $table .= '</tr>';
1.125 raeburn 17021: }
1.191 raeburn 17022: $table .= '<tr>';
17023: $rows ++;
1.125 raeburn 17024: }
1.191 raeburn 17025: my $check = '';
17026: if ($inputtype eq 'radio') {
17027: if (keys(%currhash) == 0) {
17028: if (!$i) {
17029: $check = ' checked="checked"';
17030: }
17031: } elsif (exists($currhash{$domcoord[$i]})) {
17032: $check = ' checked="checked"';
17033: }
17034: } else {
17035: if (exists($currhash{$domcoord[$i]})) {
17036: $check = ' checked="checked"';
1.125 raeburn 17037: }
17038: }
1.191 raeburn 17039: if ($i == @domcoord - 1) {
1.125 raeburn 17040: my $colsleft = $numinrow - $rem;
17041: if ($colsleft > 1) {
1.191 raeburn 17042: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 17043: } else {
1.191 raeburn 17044: $table .= '<td class="LC_left_item">';
1.125 raeburn 17045: }
17046: } else {
1.191 raeburn 17047: $table .= '<td class="LC_left_item">';
17048: }
17049: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
17050: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
17051: $table .= '<span class="LC_nobreak"><label>'.
17052: '<input type="'.$inputtype.'" name="'.$name.'"'.
17053: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
17054: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 17055: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 17056: }
1.219 raeburn 17057: $table .= '</label></span></td>';
1.191 raeburn 17058: }
17059: $table .= '</tr></table>';
17060: } elsif ($numdcs == 1) {
1.219 raeburn 17061: my ($dcname,$dcdom) = split(':',$domcoord[0]);
17062: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 17063: if ($inputtype eq 'radio') {
1.247 raeburn 17064: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 17065: if ($user ne $dcname.':'.$dcdom) {
17066: $table .= ' ('.$dcname.':'.$dcdom.')';
17067: }
1.191 raeburn 17068: } else {
17069: my $check;
17070: if (exists($currhash{$domcoord[0]})) {
17071: $check = ' checked="checked"';
1.125 raeburn 17072: }
1.247 raeburn 17073: $table = '<span class="LC_nobreak"><label>'.
17074: '<input type="checkbox" name="'.$name.'" '.
17075: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 17076: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 17077: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 17078: }
1.220 raeburn 17079: $table .= '</label></span>';
1.191 raeburn 17080: $rows ++;
1.125 raeburn 17081: }
17082: }
1.191 raeburn 17083: return ($numdcs,$table,$rows);
1.125 raeburn 17084: }
17085:
1.137 raeburn 17086: sub usersession_titles {
17087: return &Apache::lonlocal::texthash(
17088: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
17089: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 17090: spares => 'Servers offloaded to, when busy',
1.137 raeburn 17091: version => 'LON-CAPA version requirement',
1.138 raeburn 17092: excludedomain => 'Allow all, but exclude specific domains',
17093: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 17094: primary => 'Primary (checked first)',
1.154 raeburn 17095: default => 'Default',
1.137 raeburn 17096: );
17097: }
17098:
1.152 raeburn 17099: sub id_for_thisdom {
17100: my (%servers) = @_;
17101: my %altids;
17102: foreach my $server (keys(%servers)) {
17103: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
17104: if ($serverhome ne $server) {
17105: $altids{$serverhome} = $server;
17106: }
17107: }
17108: return %altids;
17109: }
17110:
1.150 raeburn 17111: sub count_servers {
17112: my ($currbalancer,%servers) = @_;
17113: my (@spares,$numspares);
17114: foreach my $lonhost (sort(keys(%servers))) {
17115: next if ($currbalancer eq $lonhost);
17116: push(@spares,$lonhost);
17117: }
17118: if ($currbalancer) {
17119: $numspares = scalar(@spares);
17120: } else {
17121: $numspares = scalar(@spares) - 1;
17122: }
17123: return ($numspares,@spares);
17124: }
17125:
17126: sub lonbalance_targets_js {
1.171 raeburn 17127: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 17128: my $select = &mt('Select');
17129: my ($alltargets,$allishome,$allinsttypes,@alltypes);
17130: if (ref($servers) eq 'HASH') {
17131: $alltargets = join("','",sort(keys(%{$servers})));
17132: my @homedoms;
17133: foreach my $server (sort(keys(%{$servers}))) {
17134: if (&Apache::lonnet::host_domain($server) eq $dom) {
17135: push(@homedoms,'1');
17136: } else {
17137: push(@homedoms,'0');
17138: }
17139: }
17140: $allishome = join("','",@homedoms);
17141: }
17142: if (ref($types) eq 'ARRAY') {
17143: if (@{$types} > 0) {
17144: @alltypes = @{$types};
17145: }
17146: }
17147: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
17148: $allinsttypes = join("','",@alltypes);
1.171 raeburn 17149: my (%currbalancer,%currtargets,%currrules,%existing);
17150: if (ref($settings) eq 'HASH') {
17151: %existing = %{$settings};
17152: }
17153: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
17154: \%currtargets,\%currrules);
1.210 raeburn 17155: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 17156: return <<"END";
17157:
17158: <script type="text/javascript">
17159: // <![CDATA[
17160:
1.171 raeburn 17161: currBalancers = new Array('$balancers');
17162:
17163: function toggleTargets(balnum) {
17164: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
17165: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
17166: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
17167: var prevbalancer = prevhostitem.value;
17168: var baltotal = document.getElementById('loadbalancing_total').value;
17169: prevhostitem.value = balancer;
17170: if (prevbalancer != '') {
17171: var prevIdx = currBalancers.indexOf(prevbalancer);
17172: if (prevIdx != -1) {
17173: currBalancers.splice(prevIdx,1);
17174: }
17175: }
1.150 raeburn 17176: if (balancer == '') {
1.171 raeburn 17177: hideSpares(balnum);
1.150 raeburn 17178: } else {
1.171 raeburn 17179: var currIdx = currBalancers.indexOf(balancer);
17180: if (currIdx == -1) {
17181: currBalancers.push(balancer);
17182: }
1.150 raeburn 17183: var homedoms = new Array('$allishome');
1.171 raeburn 17184: var ishomedom = homedoms[lonhostitem.selectedIndex];
17185: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 17186: }
1.171 raeburn 17187: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 17188: return;
17189: }
17190:
1.171 raeburn 17191: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 17192: var alltargets = new Array('$alltargets');
17193: var insttypes = new Array('$allinsttypes');
1.151 raeburn 17194: var offloadtypes = new Array('primary','default');
17195:
1.171 raeburn 17196: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
17197: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 17198:
1.151 raeburn 17199: for (var i=0; i<offloadtypes.length; i++) {
17200: var count = 0;
17201: for (var j=0; j<alltargets.length; j++) {
17202: if (alltargets[j] != balancer) {
1.171 raeburn 17203: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
17204: item.value = alltargets[j];
17205: item.style.textAlign='left';
17206: item.style.textFace='normal';
17207: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
17208: if (currBalancers.indexOf(alltargets[j]) == -1) {
17209: item.disabled = '';
17210: } else {
17211: item.disabled = 'disabled';
17212: item.checked = false;
17213: }
1.151 raeburn 17214: count ++;
17215: }
1.150 raeburn 17216: }
17217: }
1.151 raeburn 17218: for (var k=0; k<insttypes.length; k++) {
17219: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 17220: if (ishomedom == 1) {
1.171 raeburn 17221: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
17222: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 17223: } else {
1.171 raeburn 17224: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
17225: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 17226: }
17227: } else {
1.171 raeburn 17228: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
17229: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 17230: }
1.151 raeburn 17231: if ((insttypes[k] != '_LC_external') &&
17232: ((insttypes[k] != '_LC_internetdom') ||
17233: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 17234: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
17235: item.options.length = 0;
17236: item.options[0] = new Option("","",true,true);
1.210 raeburn 17237: var idx = 0;
1.151 raeburn 17238: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 17239: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
17240: idx ++;
17241: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 17242: }
17243: }
17244: }
17245: }
17246: return;
17247: }
17248:
1.171 raeburn 17249: function hideSpares(balnum) {
1.150 raeburn 17250: var alltargets = new Array('$alltargets');
17251: var insttypes = new Array('$allinsttypes');
17252: var offloadtypes = new Array('primary','default');
17253:
1.171 raeburn 17254: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
17255: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 17256:
17257: var total = alltargets.length - 1;
17258: for (var i=0; i<offloadtypes; i++) {
17259: for (var j=0; j<total; j++) {
1.171 raeburn 17260: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
17261: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
17262: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 17263: }
1.150 raeburn 17264: }
17265: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 17266: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
17267: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 17268: if (insttypes[k] != '_LC_external') {
1.171 raeburn 17269: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
17270: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 17271: }
17272: }
17273: return;
17274: }
17275:
1.171 raeburn 17276: function checkOffloads(item,balnum,type) {
1.150 raeburn 17277: var alltargets = new Array('$alltargets');
17278: var offloadtypes = new Array('primary','default');
17279: if (item.checked) {
17280: var total = alltargets.length - 1;
17281: var other;
17282: if (type == offloadtypes[0]) {
1.151 raeburn 17283: other = offloadtypes[1];
1.150 raeburn 17284: } else {
1.151 raeburn 17285: other = offloadtypes[0];
1.150 raeburn 17286: }
17287: for (var i=0; i<total; i++) {
1.171 raeburn 17288: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 17289: if (server == item.value) {
1.171 raeburn 17290: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
17291: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 17292: }
17293: }
17294: }
17295: }
17296: return;
17297: }
17298:
1.171 raeburn 17299: function singleServerToggle(balnum,type) {
17300: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 17301: if (offloadtoSelIdx == 0) {
1.171 raeburn 17302: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
17303: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 17304:
17305: } else {
1.171 raeburn 17306: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
17307: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 17308: }
17309: return;
17310: }
17311:
1.171 raeburn 17312: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 17313: if (type == '_LC_external') {
1.171 raeburn 17314: return;
1.150 raeburn 17315: }
1.171 raeburn 17316: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 17317: for (var i=0; i<typesRules.length; i++) {
17318: if (formname.elements[typesRules[i]].checked) {
17319: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 17320: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
17321: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 17322: } else {
1.171 raeburn 17323: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
17324: }
17325: }
17326: }
17327: return;
17328: }
17329:
17330: function balancerDeleteChange(balnum) {
17331: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
17332: var baltotal = document.getElementById('loadbalancing_total').value;
17333: var addtarget;
17334: var removetarget;
17335: var action = 'delete';
17336: if (document.getElementById('loadbalancing_delete_'+balnum)) {
17337: var lonhost = hostitem.value;
17338: var currIdx = currBalancers.indexOf(lonhost);
17339: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
17340: if (currIdx != -1) {
17341: currBalancers.splice(currIdx,1);
17342: }
17343: addtarget = lonhost;
17344: } else {
17345: if (currIdx == -1) {
17346: currBalancers.push(lonhost);
17347: }
17348: removetarget = lonhost;
17349: action = 'undelete';
17350: }
17351: balancerChange(balnum,baltotal,action,addtarget,removetarget);
17352: }
17353: return;
17354: }
17355:
17356: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
17357: if (baltotal > 1) {
17358: var offloadtypes = new Array('primary','default');
17359: var alltargets = new Array('$alltargets');
17360: var insttypes = new Array('$allinsttypes');
17361: for (var i=0; i<baltotal; i++) {
17362: if (i != balnum) {
17363: for (var j=0; j<offloadtypes.length; j++) {
17364: var total = alltargets.length - 1;
17365: for (var k=0; k<total; k++) {
17366: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
17367: var server = serveritem.value;
17368: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
17369: if (server == addtarget) {
17370: serveritem.disabled = '';
17371: }
17372: }
17373: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
17374: if (server == removetarget) {
17375: serveritem.disabled = 'disabled';
17376: serveritem.checked = false;
17377: }
17378: }
17379: }
17380: }
17381: for (var j=0; j<insttypes.length; j++) {
17382: if (insttypes[j] != '_LC_external') {
17383: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
17384: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
17385: var currSel = singleserver.selectedIndex;
17386: var currVal = singleserver.options[currSel].value;
17387: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
17388: var numoptions = singleserver.options.length;
17389: var needsnew = 1;
17390: for (var k=0; k<numoptions; k++) {
17391: if (singleserver.options[k] == addtarget) {
17392: needsnew = 0;
17393: break;
17394: }
17395: }
17396: if (needsnew == 1) {
17397: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
17398: }
17399: }
17400: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
17401: singleserver.options.length = 0;
17402: if ((currVal) && (currVal != removetarget)) {
17403: singleserver.options[0] = new Option("","",false,false);
17404: } else {
17405: singleserver.options[0] = new Option("","",true,true);
17406: }
17407: var idx = 0;
17408: for (var m=0; m<alltargets.length; m++) {
17409: if (currBalancers.indexOf(alltargets[m]) == -1) {
17410: idx ++;
17411: if (currVal == alltargets[m]) {
17412: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
17413: } else {
17414: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
17415: }
17416: }
17417: }
17418: }
17419: }
17420: }
17421: }
1.150 raeburn 17422: }
17423: }
17424: }
17425: return;
17426: }
17427:
1.152 raeburn 17428: // ]]>
17429: </script>
17430:
17431: END
17432: }
17433:
17434: sub new_spares_js {
17435: my @sparestypes = ('primary','default');
17436: my $types = join("','",@sparestypes);
17437: my $select = &mt('Select');
17438: return <<"END";
17439:
17440: <script type="text/javascript">
17441: // <![CDATA[
17442:
17443: function updateNewSpares(formname,lonhost) {
17444: var types = new Array('$types');
17445: var include = new Array();
17446: var exclude = new Array();
17447: for (var i=0; i<types.length; i++) {
17448: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
17449: for (var j=0; j<spareboxes.length; j++) {
17450: if (formname.elements[spareboxes[j]].checked) {
17451: exclude.push(formname.elements[spareboxes[j]].value);
17452: } else {
17453: include.push(formname.elements[spareboxes[j]].value);
17454: }
17455: }
17456: }
17457: for (var i=0; i<types.length; i++) {
17458: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
17459: var selIdx = newSpare.selectedIndex;
17460: var currnew = newSpare.options[selIdx].value;
17461: var okSpares = new Array();
17462: for (var j=0; j<newSpare.options.length; j++) {
17463: var possible = newSpare.options[j].value;
17464: if (possible != '') {
17465: if (exclude.indexOf(possible) == -1) {
17466: okSpares.push(possible);
17467: } else {
17468: if (currnew == possible) {
17469: selIdx = 0;
17470: }
17471: }
17472: }
17473: }
17474: for (var k=0; k<include.length; k++) {
17475: if (okSpares.indexOf(include[k]) == -1) {
17476: okSpares.push(include[k]);
17477: }
17478: }
17479: okSpares.sort();
17480: newSpare.options.length = 0;
17481: if (selIdx == 0) {
17482: newSpare.options[0] = new Option("$select","",true,true);
17483: } else {
17484: newSpare.options[0] = new Option("$select","",false,false);
17485: }
17486: for (var m=0; m<okSpares.length; m++) {
17487: var idx = m+1;
17488: var selThis = 0;
17489: if (selIdx != 0) {
17490: if (okSpares[m] == currnew) {
17491: selThis = 1;
17492: }
17493: }
17494: if (selThis == 1) {
17495: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
17496: } else {
17497: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
17498: }
17499: }
17500: }
17501: return;
17502: }
17503:
17504: function checkNewSpares(lonhost,type) {
17505: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
17506: var chosen = newSpare.options[newSpare.selectedIndex].value;
17507: if (chosen != '') {
17508: var othertype;
17509: var othernewSpare;
17510: if (type == 'primary') {
17511: othernewSpare = document.getElementById('newspare_default_'+lonhost);
17512: }
17513: if (type == 'default') {
17514: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
17515: }
17516: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
17517: othernewSpare.selectedIndex = 0;
17518: }
17519: }
17520: return;
17521: }
17522:
17523: // ]]>
17524: </script>
17525:
17526: END
17527:
17528: }
17529:
17530: sub common_domprefs_js {
17531: return <<"END";
17532:
17533: <script type="text/javascript">
17534: // <![CDATA[
17535:
1.150 raeburn 17536: function getIndicesByName(formname,item) {
1.152 raeburn 17537: var group = new Array();
1.150 raeburn 17538: for (var i=0;i<formname.elements.length;i++) {
17539: if (formname.elements[i].name == item) {
1.152 raeburn 17540: group.push(formname.elements[i].id);
1.150 raeburn 17541: }
17542: }
1.152 raeburn 17543: return group;
1.150 raeburn 17544: }
17545:
17546: // ]]>
17547: </script>
17548:
17549: END
1.152 raeburn 17550:
1.150 raeburn 17551: }
17552:
1.165 raeburn 17553: sub recaptcha_js {
17554: my %lt = &captcha_phrases();
17555: return <<"END";
17556:
17557: <script type="text/javascript">
17558: // <![CDATA[
17559:
17560: function updateCaptcha(caller,context) {
17561: var privitem;
17562: var pubitem;
17563: var privtext;
17564: var pubtext;
1.269 raeburn 17565: var versionitem;
17566: var versiontext;
1.165 raeburn 17567: if (document.getElementById(context+'_recaptchapub')) {
17568: pubitem = document.getElementById(context+'_recaptchapub');
17569: } else {
17570: return;
17571: }
17572: if (document.getElementById(context+'_recaptchapriv')) {
17573: privitem = document.getElementById(context+'_recaptchapriv');
17574: } else {
17575: return;
17576: }
17577: if (document.getElementById(context+'_recaptchapubtxt')) {
17578: pubtext = document.getElementById(context+'_recaptchapubtxt');
17579: } else {
17580: return;
17581: }
17582: if (document.getElementById(context+'_recaptchaprivtxt')) {
17583: privtext = document.getElementById(context+'_recaptchaprivtxt');
17584: } else {
17585: return;
17586: }
1.269 raeburn 17587: if (document.getElementById(context+'_recaptchaversion')) {
17588: versionitem = document.getElementById(context+'_recaptchaversion');
17589: } else {
17590: return;
17591: }
17592: if (document.getElementById(context+'_recaptchavertxt')) {
17593: versiontext = document.getElementById(context+'_recaptchavertxt');
17594: } else {
17595: return;
17596: }
1.165 raeburn 17597: if (caller.checked) {
17598: if (caller.value == 'recaptcha') {
17599: pubitem.type = 'text';
17600: privitem.type = 'text';
17601: pubitem.size = '40';
17602: privitem.size = '40';
17603: pubtext.innerHTML = "$lt{'pub'}";
17604: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 17605: versionitem.type = 'text';
17606: versionitem.size = '3';
1.289 raeburn 17607: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 17608: } else {
17609: pubitem.type = 'hidden';
17610: privitem.type = 'hidden';
1.269 raeburn 17611: versionitem.type = 'hidden';
1.165 raeburn 17612: pubtext.innerHTML = '';
17613: privtext.innerHTML = '';
1.269 raeburn 17614: versiontext.innerHTML = '';
1.165 raeburn 17615: }
17616: }
17617: return;
17618: }
17619:
17620: // ]]>
17621: </script>
17622:
17623: END
17624:
17625: }
17626:
1.236 raeburn 17627: sub toggle_display_js {
1.192 raeburn 17628: return <<"END";
17629:
17630: <script type="text/javascript">
17631: // <![CDATA[
17632:
1.236 raeburn 17633: function toggleDisplay(domForm,caller) {
17634: if (document.getElementById(caller)) {
17635: var divitem = document.getElementById(caller);
17636: var optionsElement = domForm.coursecredits;
1.264 raeburn 17637: var checkval = 1;
17638: var dispval = 'block';
1.303 raeburn 17639: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 17640: if (caller == 'emailoptions') {
17641: optionsElement = domForm.cancreate_email;
17642: }
1.257 raeburn 17643: if (caller == 'studentsubmission') {
17644: optionsElement = domForm.postsubmit;
17645: }
1.264 raeburn 17646: if (caller == 'cloneinstcode') {
17647: optionsElement = domForm.canclone;
17648: checkval = 'instcode';
17649: }
1.303 raeburn 17650: if (selfcreateRegExp.test(caller)) {
17651: optionsElement = domForm.elements[caller];
17652: checkval = 'other';
17653: dispval = 'inline'
17654: }
1.236 raeburn 17655: if (optionsElement.length) {
1.192 raeburn 17656: var currval;
1.236 raeburn 17657: for (var i=0; i<optionsElement.length; i++) {
17658: if (optionsElement[i].checked) {
17659: currval = optionsElement[i].value;
1.192 raeburn 17660: }
17661: }
1.264 raeburn 17662: if (currval == checkval) {
17663: divitem.style.display = dispval;
1.192 raeburn 17664: } else {
1.236 raeburn 17665: divitem.style.display = 'none';
1.192 raeburn 17666: }
17667: }
17668: }
17669: return;
17670: }
17671:
17672: // ]]>
17673: </script>
17674:
17675: END
17676:
17677: }
17678:
1.165 raeburn 17679: sub captcha_phrases {
17680: return &Apache::lonlocal::texthash (
17681: priv => 'Private key',
17682: pub => 'Public key',
17683: original => 'original (CAPTCHA)',
17684: recaptcha => 'successor (ReCAPTCHA)',
17685: notused => 'unused',
1.289 raeburn 17686: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 17687: );
17688: }
17689:
1.205 raeburn 17690: sub devalidate_remote_domconfs {
1.212 raeburn 17691: my ($dom,$cachekeys) = @_;
17692: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 17693: my %servers = &Apache::lonnet::internet_dom_servers($dom);
17694: my %thismachine;
17695: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.295 raeburn 17696: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions','directorysrch');
1.260 raeburn 17697: if (keys(%servers)) {
1.205 raeburn 17698: foreach my $server (keys(%servers)) {
17699: next if ($thismachine{$server});
1.212 raeburn 17700: my @cached;
17701: foreach my $name (@posscached) {
17702: if ($cachekeys->{$name}) {
17703: push(@cached,&escape($name).':'.&escape($dom));
17704: }
17705: }
17706: if (@cached) {
17707: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
17708: }
1.205 raeburn 17709: }
17710: }
17711: return;
17712: }
17713:
1.3 raeburn 17714: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>