Annotation of loncom/interface/domainprefs.pm, revision 1.326
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.326 ! raeburn 4: # $Id: domainprefs.pm,v 1.325 2018/03/23 01:01:20 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
1.286 raeburn 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
1.1 raeburn 24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
1.297 raeburn 30: ###############################################################
1.1 raeburn 31:
1.101 raeburn 32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
1.183 bisitz 49: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 50: may define a default set of logos and a color scheme which can be used to "brand"
51: the LON-CAPA instance. In addition, an institution will typically have a language
52: and timezone which are used for the majority of courses.
53:
54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
55: host of other domain-wide settings which determine the types of functionality
56: available to users and courses in the domain.
57:
58: There is also a mechanism to configure cataloging of courses in the domain, and
59: controls on the operation of automated processes which govern such things as
60: roster updates, user directory updates and processing of course requests.
61:
62: The domain coordination manual which is built dynamically on install/update of
63: LON-CAPA from the relevant help items provides more information about domain
64: configuration.
65:
66: Most of the domain settings are stored in the configuration.db GDBM file which is
67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
68: where $dom is the domain. The configuration.db stores settings in a number of
69: frozen hashes of hashes. In a few cases, domain information must be uploaded to
70: the domain as files (e.g., image files for logos etc., or plain text files for
71: bubblesheet formats). In this case the domainprefs.pm must be running in a user
72: session hosted on the primary library server in the domain, as these files are
73: stored in author space belonging to a special $dom-domainconfig user.
74:
75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
76: the current settings, and provides an interface to make modifications.
77:
78: =head1 SUBROUTINES
79:
80: =over
81:
82: =item print_quotas()
83:
84: Inputs: 4
85:
86: $dom,$settings,$rowtotal,$action.
87:
88: $dom is the domain, $settings is a reference to a hash of current settings for
89: the current context, $rowtotal is a reference to the scalar used to record the
1.210 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.163 raeburn 91: requestcourses or requestauthor).
1.101 raeburn 92:
93: The print_quotas routine was orginally created to display/store information
94: about default quota sizes for portfolio spaces for the different types of
95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
96: but is now also used to manage availability of user tools:
97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.197 raeburn 98: used by course owners to request creation of a course, and to display/store
1.223 bisitz 99: default quota sizes for Authoring Spaces.
1.101 raeburn 100:
101: Outputs: 1
102:
103: $datatable - HTML containing form elements which allow settings to be changed.
104:
105: In the case of course requests, radio buttons are displayed for each institutional
106: affiliate type (and also default, and _LC_adv) for each of the course types
1.325 raeburn 107: (official, unofficial, community, textbook, placement, and lti).
1.271 raeburn 108: In each case the radio buttons allow the selection of one of four values:
1.101 raeburn 109:
1.104 raeburn 110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 111: which have the following effects:
112:
113: 0
114:
115: =over
116:
117: - course requests are not allowed for this course types/affiliation
118:
119: =back
120:
1.104 raeburn 121: approval
1.101 raeburn 122:
123: =over
124:
125: - course requests must be approved by a Doman Coordinator in the
126: course's domain
127:
128: =back
129:
130: validate
131:
132: =over
133:
134: - an institutional validation (e.g., check requestor is instructor
135: of record) needs to be passed before the course will be created. The required
136: validation is in localenroll.pm on the primary library server for the course
137: domain.
138:
139: =back
140:
141: autolimit
142:
143: =over
144:
1.143 raeburn 145: - course requests will be processed automatically up to a limit of
1.101 raeburn 146: N requests for the course type for the particular requestor.
147: If N is undefined, there is no limit to the number of course requests
148: which a course owner may submit and have processed automatically.
149:
150: =back
151:
152: =item modify_quotas()
153:
154: =back
155:
156: =cut
157:
1.1 raeburn 158: package Apache::domainprefs;
159:
160: use strict;
161: use Apache::Constants qw(:common :http);
162: use Apache::lonnet;
163: use Apache::loncommon();
164: use Apache::lonhtmlcommon();
165: use Apache::lonlocal;
1.43 raeburn 166: use Apache::lonmsg();
1.91 raeburn 167: use Apache::lonconfigsettings;
1.232 raeburn 168: use Apache::lonuserutils();
1.235 raeburn 169: use Apache::loncoursequeueadmin();
1.69 raeburn 170: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 171: use LONCAPA::Enrollment;
1.81 raeburn 172: use LONCAPA::lonauthcgi();
1.275 raeburn 173: use LONCAPA::SSL;
1.9 raeburn 174: use File::Copy;
1.43 raeburn 175: use Locale::Language;
1.62 raeburn 176: use DateTime::TimeZone;
1.68 raeburn 177: use DateTime::Locale;
1.267 raeburn 178: use Time::HiRes qw( sleep );
1.1 raeburn 179:
1.155 raeburn 180: my $registered_cleanup;
181: my $modified_urls;
182:
1.1 raeburn 183: sub handler {
184: my $r=shift;
185: if ($r->header_only) {
186: &Apache::loncommon::content_type($r,'text/html');
187: $r->send_http_header;
188: return OK;
189: }
190:
1.91 raeburn 191: my $context = 'domain';
1.1 raeburn 192: my $dom = $env{'request.role.domain'};
1.5 albertel 193: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 194: if (&Apache::lonnet::allowed('mau',$dom)) {
195: &Apache::loncommon::content_type($r,'text/html');
196: $r->send_http_header;
197: } else {
198: $env{'user.error.msg'}=
199: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
200: return HTTP_NOT_ACCEPTABLE;
201: }
1.155 raeburn 202:
203: $registered_cleanup=0;
204: @{$modified_urls}=();
205:
1.1 raeburn 206: &Apache::lonhtmlcommon::clear_breadcrumbs();
207: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 208: ['phase','actions']);
1.30 raeburn 209: my $phase = 'pickactions';
1.3 raeburn 210: if ( exists($env{'form.phase'}) ) {
211: $phase = $env{'form.phase'};
212: }
1.150 raeburn 213: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 214: my %domconfig =
1.6 raeburn 215: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 216: 'quotas','autoenroll','autoupdate','autocreate',
217: 'directorysrch','usercreation','usermodification',
218: 'contacts','defaults','scantron','coursecategories',
219: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 220: 'coursedefaults','usersessions','loadbalancing',
1.267 raeburn 221: 'requestauthor','selfenrollment','inststatus',
1.320 raeburn 222: 'ltitools','ssl','trust','lti'],$dom);
223: my %encconfig =
224: &Apache::lonnet::get_dom('encconfig',['ltitools','lti'],$dom);
1.297 raeburn 225: if (ref($domconfig{'ltitools'}) eq 'HASH') {
226: if (ref($encconfig{'ltitools'}) eq 'HASH') {
227: foreach my $id (keys(%{$domconfig{'ltitools'}})) {
1.320 raeburn 228: if ((ref($domconfig{'ltitools'}{$id}) eq 'HASH') &&
229: (ref($encconfig{'ltitools'}{$id}) eq 'HASH')) {
1.297 raeburn 230: foreach my $item ('key','secret') {
231: $domconfig{'ltitools'}{$id}{$item} = $encconfig{'ltitools'}{$id}{$item};
232: }
233: }
234: }
235: }
236: }
1.320 raeburn 237: if (ref($domconfig{'lti'}) eq 'HASH') {
238: if (ref($encconfig{'lti'}) eq 'HASH') {
239: foreach my $id (keys(%{$domconfig{'lti'}})) {
240: if ((ref($domconfig{'lti'}{$id}) eq 'HASH') &&
241: (ref($encconfig{'lti'}{$id}) eq 'HASH')) {
242: foreach my $item ('key','secret') {
243: $domconfig{'lti'}{$id}{$item} = $encconfig{'lti'}{$id}{$item};
244: }
245: }
246: }
247: }
248: }
1.43 raeburn 249: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 250: 'autoupdate','autocreate','directorysrch','contacts',
1.224 raeburn 251: 'usercreation','selfcreation','usermodification','scantron',
1.163 raeburn 252: 'requestcourses','requestauthor','coursecategories',
1.267 raeburn 253: 'serverstatuses','helpsettings','coursedefaults',
1.320 raeburn 254: 'ltitools','selfenrollment','usersessions','ssl','trust','lti');
1.171 raeburn 255: my %existing;
256: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
257: %existing = %{$domconfig{'loadbalancing'}};
258: }
259: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 260: push(@prefs_order,'loadbalancing');
261: }
1.30 raeburn 262: my %prefs = (
263: 'rolecolors' =>
264: { text => 'Default color schemes',
1.67 raeburn 265: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 266: header => [{col1 => 'Student Settings',
267: col2 => '',},
268: {col1 => 'Coordinator Settings',
269: col2 => '',},
270: {col1 => 'Author Settings',
271: col2 => '',},
272: {col1 => 'Administrator Settings',
273: col2 => '',}],
1.230 raeburn 274: print => \&print_rolecolors,
275: modify => \&modify_rolecolors,
1.30 raeburn 276: },
1.110 raeburn 277: 'login' =>
1.30 raeburn 278: { text => 'Log-in page options',
1.67 raeburn 279: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 280: header => [{col1 => 'Log-in Page Items',
281: col2 => '',},
282: {col1 => 'Log-in Help',
1.256 raeburn 283: col2 => 'Value'},
284: {col1 => 'Custom HTML in document head',
1.168 raeburn 285: col2 => 'Value'}],
1.230 raeburn 286: print => \&print_login,
287: modify => \&modify_login,
1.30 raeburn 288: },
1.43 raeburn 289: 'defaults' =>
1.236 raeburn 290: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 291: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 292: header => [{col1 => 'Setting',
1.236 raeburn 293: col2 => 'Value'},
1.294 raeburn 294: {col1 => 'Internal Authentication',
295: col2 => 'Value'},
1.236 raeburn 296: {col1 => 'Institutional user types',
1.305 raeburn 297: col2 => 'Name displayed'}],
1.230 raeburn 298: print => \&print_defaults,
299: modify => \&modify_defaults,
1.43 raeburn 300: },
1.30 raeburn 301: 'quotas' =>
1.197 raeburn 302: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 303: help => 'Domain_Configuration_Quotas',
1.77 raeburn 304: header => [{col1 => 'User affiliation',
1.72 raeburn 305: col2 => 'Available tools',
1.213 raeburn 306: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230 raeburn 307: print => \&print_quotas,
308: modify => \&modify_quotas,
1.30 raeburn 309: },
310: 'autoenroll' =>
311: { text => 'Auto-enrollment settings',
1.67 raeburn 312: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 313: header => [{col1 => 'Configuration setting',
314: col2 => 'Value(s)'}],
1.230 raeburn 315: print => \&print_autoenroll,
316: modify => \&modify_autoenroll,
1.30 raeburn 317: },
318: 'autoupdate' =>
319: { text => 'Auto-update settings',
1.67 raeburn 320: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 321: header => [{col1 => 'Setting',
322: col2 => 'Value',},
1.131 raeburn 323: {col1 => 'Setting',
324: col2 => 'Affiliation'},
1.43 raeburn 325: {col1 => 'User population',
1.227 bisitz 326: col2 => 'Updatable user data'}],
1.230 raeburn 327: print => \&print_autoupdate,
328: modify => \&modify_autoupdate,
1.30 raeburn 329: },
1.125 raeburn 330: 'autocreate' =>
331: { text => 'Auto-course creation settings',
332: help => 'Domain_Configuration_Auto_Creation',
333: header => [{col1 => 'Configuration Setting',
334: col2 => 'Value',}],
1.230 raeburn 335: print => \&print_autocreate,
336: modify => \&modify_autocreate,
1.125 raeburn 337: },
1.30 raeburn 338: 'directorysrch' =>
1.277 raeburn 339: { text => 'Directory searches',
1.67 raeburn 340: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 341: header => [{col1 => 'Institutional Directory Setting',
342: col2 => 'Value',},
343: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 344: col2 => 'Value',}],
1.230 raeburn 345: print => \&print_directorysrch,
346: modify => \&modify_directorysrch,
1.30 raeburn 347: },
348: 'contacts' =>
1.286 raeburn 349: { text => 'E-mail addresses and helpform',
1.67 raeburn 350: help => 'Domain_Configuration_Contact_Info',
1.286 raeburn 351: header => [{col1 => 'Default e-mail addresses',
352: col2 => 'Value',},
353: {col1 => 'Recipient(s) for notifications',
354: col2 => 'Value',},
355: {col1 => 'Ask helpdesk form settings',
356: col2 => 'Value',},],
1.230 raeburn 357: print => \&print_contacts,
358: modify => \&modify_contacts,
1.30 raeburn 359: },
360: 'usercreation' =>
361: { text => 'User creation',
1.67 raeburn 362: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 363: header => [{col1 => 'Format rule type',
364: col2 => 'Format rules in force'},
1.34 raeburn 365: {col1 => 'User account creation',
366: col2 => 'Usernames which may be created',},
1.30 raeburn 367: {col1 => 'Context',
1.43 raeburn 368: col2 => 'Assignable authentication types'}],
1.230 raeburn 369: print => \&print_usercreation,
370: modify => \&modify_usercreation,
1.30 raeburn 371: },
1.224 raeburn 372: 'selfcreation' =>
373: { text => 'Users self-creating accounts',
374: help => 'Domain_Configuration_Self_Creation',
375: header => [{col1 => 'Self-creation with institutional username',
376: col2 => 'Enabled?'},
377: {col1 => 'Institutional user type (login/SSO self-creation)',
378: col2 => 'Information user can enter'},
1.303 raeburn 379: {col1 => 'Self-creation with e-mail verification',
1.224 raeburn 380: col2 => 'Settings'}],
1.230 raeburn 381: print => \&print_selfcreation,
382: modify => \&modify_selfcreation,
1.224 raeburn 383: },
1.69 raeburn 384: 'usermodification' =>
1.33 raeburn 385: { text => 'User modification',
1.67 raeburn 386: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 387: header => [{col1 => 'Target user has role',
1.227 bisitz 388: col2 => 'User information updatable in author context'},
1.33 raeburn 389: {col1 => 'Target user has role',
1.227 bisitz 390: col2 => 'User information updatable in course context'}],
1.230 raeburn 391: print => \&print_usermodification,
392: modify => \&modify_usermodification,
1.33 raeburn 393: },
1.69 raeburn 394: 'scantron' =>
1.95 www 395: { text => 'Bubblesheet format file',
1.67 raeburn 396: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 397: header => [ {col1 => 'Item',
398: col2 => '',
399: }],
1.230 raeburn 400: print => \&print_scantron,
401: modify => \&modify_scantron,
1.46 raeburn 402: },
1.86 raeburn 403: 'requestcourses' =>
404: {text => 'Request creation of courses',
405: help => 'Domain_Configuration_Request_Courses',
406: header => [{col1 => 'User affiliation',
1.102 raeburn 407: col2 => 'Availability/Processing of requests',},
408: {col1 => 'Setting',
1.216 raeburn 409: col2 => 'Value'},
410: {col1 => 'Available textbooks',
1.235 raeburn 411: col2 => ''},
1.242 raeburn 412: {col1 => 'Available templates',
413: col2 => ''},
1.235 raeburn 414: {col1 => 'Validation (not official courses)',
415: col2 => 'Value'},],
1.230 raeburn 416: print => \&print_quotas,
417: modify => \&modify_quotas,
1.86 raeburn 418: },
1.163 raeburn 419: 'requestauthor' =>
1.223 bisitz 420: {text => 'Request Authoring Space',
1.163 raeburn 421: help => 'Domain_Configuration_Request_Author',
422: header => [{col1 => 'User affiliation',
423: col2 => 'Availability/Processing of requests',},
424: {col1 => 'Setting',
425: col2 => 'Value'}],
1.230 raeburn 426: print => \&print_quotas,
427: modify => \&modify_quotas,
1.163 raeburn 428: },
1.69 raeburn 429: 'coursecategories' =>
1.120 raeburn 430: { text => 'Cataloging of courses/communities',
1.67 raeburn 431: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 432: header => [{col1 => 'Catalog type/availability',
433: col2 => '',},
434: {col1 => 'Category settings for standard catalog',
1.57 raeburn 435: col2 => '',},
436: {col1 => 'Categories',
437: col2 => '',
438: }],
1.230 raeburn 439: print => \&print_coursecategories,
440: modify => \&modify_coursecategories,
1.69 raeburn 441: },
442: 'serverstatuses' =>
1.77 raeburn 443: {text => 'Access to server status pages',
1.69 raeburn 444: help => 'Domain_Configuration_Server_Status',
445: header => [{col1 => 'Status Page',
446: col2 => 'Other named users',
447: col3 => 'Specific IPs',
448: }],
1.230 raeburn 449: print => \&print_serverstatuses,
450: modify => \&modify_serverstatuses,
1.69 raeburn 451: },
1.118 jms 452: 'helpsettings' =>
1.282 raeburn 453: {text => 'Support settings',
1.118 jms 454: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 455: header => [{col1 => 'Help Page Settings (logged-in users)',
456: col2 => 'Value'},
457: {col1 => 'Helpdesk Roles',
458: col2 => 'Settings'},],
1.230 raeburn 459: print => \&print_helpsettings,
460: modify => \&modify_helpsettings,
1.118 jms 461: },
1.121 raeburn 462: 'coursedefaults' =>
463: {text => 'Course/Community defaults',
464: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 465: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
466: col2 => 'Value',},
467: {col1 => 'Defaults which can be overridden for each course by a DC',
468: col2 => 'Value',},],
1.230 raeburn 469: print => \&print_coursedefaults,
470: modify => \&modify_coursedefaults,
1.121 raeburn 471: },
1.231 raeburn 472: 'selfenrollment' =>
473: {text => 'Self-enrollment in Course/Community',
474: help => 'Domain_Configuration_Selfenrollment',
475: header => [{col1 => 'Configuration Rights',
476: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
477: {col1 => 'Defaults',
478: col2 => 'Value'},
479: {col1 => 'Self-enrollment validation (optional)',
480: col2 => 'Value'},],
481: print => \&print_selfenrollment,
482: modify => \&modify_selfenrollment,
483: },
1.120 raeburn 484: 'privacy' =>
485: {text => 'User Privacy',
486: help => 'Domain_Configuration_User_Privacy',
487: header => [{col1 => 'Setting',
488: col2 => 'Value',}],
1.230 raeburn 489: print => \&print_privacy,
490: modify => \&modify_privacy,
1.120 raeburn 491: },
1.141 raeburn 492: 'usersessions' =>
1.145 raeburn 493: {text => 'User session hosting/offloading',
1.137 raeburn 494: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 495: header => [{col1 => 'Domain server',
496: col2 => 'Servers to offload sessions to when busy'},
497: {col1 => 'Hosting of users from other domains',
1.137 raeburn 498: col2 => 'Rules'},
499: {col1 => "Hosting domain's own users elsewhere",
500: col2 => 'Rules'}],
1.230 raeburn 501: print => \&print_usersessions,
502: modify => \&modify_usersessions,
1.137 raeburn 503: },
1.279 raeburn 504: 'loadbalancing' =>
1.185 raeburn 505: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 506: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 507: header => [{col1 => 'Balancers',
1.150 raeburn 508: col2 => 'Default destinations',
1.183 bisitz 509: col3 => 'User affiliation',
1.150 raeburn 510: col4 => 'Overrides'},
511: ],
1.230 raeburn 512: print => \&print_loadbalancing,
513: modify => \&modify_loadbalancing,
1.150 raeburn 514: },
1.279 raeburn 515: 'ltitools' =>
1.267 raeburn 516: {text => 'External Tools (LTI)',
1.296 raeburn 517: help => 'Domain_Configuration_LTI_Tools',
1.267 raeburn 518: header => [{col1 => 'Setting',
519: col2 => 'Value',}],
520: print => \&print_ltitools,
521: modify => \&modify_ltitools,
522: },
1.279 raeburn 523: 'ssl' =>
1.275 raeburn 524: {text => 'LON-CAPA Network (SSL)',
525: help => 'Domain_Configuration_Network_SSL',
526: header => [{col1 => 'Server',
527: col2 => 'Certificate Status'},
528: {col1 => 'Connections to other servers',
529: col2 => 'Rules'},
1.293 raeburn 530: {col1 => 'Connections from other servers',
531: col2 => 'Rules'},
1.275 raeburn 532: {col1 => "Replicating domain's published content",
533: col2 => 'Rules'}],
534: print => \&print_ssl,
535: modify => \&modify_ssl,
536: },
1.279 raeburn 537: 'trust' =>
538: {text => 'Trust Settings',
539: help => 'Domain_Configuration_Trust',
540: header => [{col1 => "Access to this domain's content by others",
541: col2 => 'Rules'},
542: {col1 => "Access to other domain's content by this domain",
543: col2 => 'Rules'},
544: {col1 => "Enrollment in this domain's courses by others",
545: col2 => 'Rules',},
546: {col1 => "Co-author roles in this domain for others",
547: col2 => 'Rules',},
548: {col1 => "Co-author roles for this domain's users elsewhere",
549: col2 => 'Rules',},
550: {col1 => "Domain roles in this domain assignable to others",
551: col2 => 'Rules'},
552: {col1 => "Course catalog for this domain displayed elsewhere",
553: col2 => 'Rules'},
554: {col1 => "Requests for creation of courses in this domain by others",
555: col2 => 'Rules'},
556: {col1 => "Users in other domains can send messages to this domain",
557: col2 => 'Rules'},],
558: print => \&print_trust,
559: modify => \&modify_trust,
560: },
1.320 raeburn 561: 'lti' =>
562: {text => 'LTI Provider',
563: help => 'Domain_Configuration_LTI_Provider',
564: header => [{col1 => 'Setting',
565: col2 => 'Value',}],
566: print => \&print_lti,
567: modify => \&modify_lti,
568: },
1.3 raeburn 569: );
1.110 raeburn 570: if (keys(%servers) > 1) {
571: $prefs{'login'} = { text => 'Log-in page options',
572: help => 'Domain_Configuration_Login_Page',
573: header => [{col1 => 'Log-in Service',
574: col2 => 'Server Setting',},
575: {col1 => 'Log-in Page Items',
1.168 raeburn 576: col2 => ''},
577: {col1 => 'Log-in Help',
1.256 raeburn 578: col2 => 'Value'},
579: {col1 => 'Custom HTML in document head',
1.168 raeburn 580: col2 => 'Value'}],
1.230 raeburn 581: print => \&print_login,
582: modify => \&modify_login,
1.110 raeburn 583: };
584: }
1.174 foxr 585:
1.6 raeburn 586: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 587: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 588: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 589: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 590: text=>"Settings to display/modify"});
1.9 raeburn 591: my $confname = $dom.'-domainconfig';
1.174 foxr 592:
1.3 raeburn 593: if ($phase eq 'process') {
1.212 raeburn 594: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
595: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 596: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 597: $r->rflush();
1.212 raeburn 598: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 599: }
1.30 raeburn 600: } elsif ($phase eq 'display') {
1.192 raeburn 601: my $js = &recaptcha_js().
1.236 raeburn 602: &toggle_display_js();
1.171 raeburn 603: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 604: my ($othertitle,$usertypes,$types) =
605: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 606: $js .= &lonbalance_targets_js($dom,$types,\%servers,
607: $domconfig{'loadbalancing'}).
1.170 raeburn 608: &new_spares_js().
609: &common_domprefs_js().
610: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 611: }
1.216 raeburn 612: if (grep(/^requestcourses$/,@actions)) {
613: my $javascript_validations;
614: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
615: $js .= <<END;
616: <script type="text/javascript">
617: $javascript_validations
618: </script>
619: $coursebrowserjs
620: END
621: }
1.305 raeburn 622: if (grep(/^selfcreation$/,@actions)) {
623: $js .= &selfcreate_javascript();
624: }
1.286 raeburn 625: if (grep(/^contacts$/,@actions)) {
626: $js .= &contacts_javascript();
627: }
1.150 raeburn 628: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 629: } else {
1.180 raeburn 630: # check if domconfig user exists for the domain.
631: my $servadm = $r->dir_config('lonAdmEMail');
632: my ($configuserok,$author_ok,$switchserver) =
633: &config_check($dom,$confname,$servadm);
634: unless ($configuserok eq 'ok') {
1.181 raeburn 635: &Apache::lonconfigsettings::print_header($r,$phase,$context);
636: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 637: $confname).
1.181 raeburn 638: '<br />'
639: );
1.180 raeburn 640: if ($switchserver) {
1.181 raeburn 641: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
642: '<br />'.
643: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
644: '<br />'.
645: &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
646: '<br />'.
647: &mt('To do that now, use the following link: [_1]',$switchserver)
648: );
649: } else {
650: $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
651: '<br />'.
652: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
653: );
1.180 raeburn 654: }
655: $r->print(&Apache::loncommon::end_page());
656: return OK;
657: }
1.21 raeburn 658: if (keys(%domconfig) == 0) {
659: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 660: my @ids=&Apache::lonnet::current_machine_ids();
661: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 662: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 663: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 664: my $custom_img_count = 0;
665: foreach my $img (@loginimages) {
666: if ($designhash{$dom.'.login.'.$img} ne '') {
667: $custom_img_count ++;
668: }
669: }
670: foreach my $role (@roles) {
671: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
672: $custom_img_count ++;
673: }
674: }
675: if ($custom_img_count > 0) {
1.94 raeburn 676: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 677: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 678: $r->print(
679: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
680: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
681: &mt("Thereafter, (with a Domain Coordinator role selected in the domain) you will be able to update settings when logged in to any server in the LON-CAPA network.").'<br />'.
682: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
683: if ($switch_server) {
1.30 raeburn 684: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 685: }
1.91 raeburn 686: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 687: return OK;
688: }
689: }
690: }
1.91 raeburn 691: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 692: }
693: return OK;
694: }
695:
696: sub process_changes {
1.205 raeburn 697: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 698: my %domconfig;
699: if (ref($values) eq 'HASH') {
700: %domconfig = %{$values};
701: }
1.3 raeburn 702: my $output;
703: if ($action eq 'login') {
1.205 raeburn 704: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 705: } elsif ($action eq 'rolecolors') {
1.9 raeburn 706: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 707: $lastactref,%domconfig);
1.3 raeburn 708: } elsif ($action eq 'quotas') {
1.216 raeburn 709: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 710: } elsif ($action eq 'autoenroll') {
1.205 raeburn 711: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 712: } elsif ($action eq 'autoupdate') {
713: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 714: } elsif ($action eq 'autocreate') {
715: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 716: } elsif ($action eq 'directorysrch') {
1.295 raeburn 717: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 718: } elsif ($action eq 'usercreation') {
1.28 raeburn 719: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 720: } elsif ($action eq 'selfcreation') {
1.305 raeburn 721: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 722: } elsif ($action eq 'usermodification') {
723: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 724: } elsif ($action eq 'contacts') {
1.205 raeburn 725: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 726: } elsif ($action eq 'defaults') {
1.212 raeburn 727: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 728: } elsif ($action eq 'scantron') {
1.205 raeburn 729: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 730: } elsif ($action eq 'coursecategories') {
1.239 raeburn 731: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 732: } elsif ($action eq 'serverstatuses') {
733: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 734: } elsif ($action eq 'requestcourses') {
1.216 raeburn 735: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 736: } elsif ($action eq 'requestauthor') {
1.216 raeburn 737: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 738: } elsif ($action eq 'helpsettings') {
1.285 raeburn 739: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 740: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 741: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 742: } elsif ($action eq 'selfenrollment') {
743: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 744: } elsif ($action eq 'usersessions') {
1.212 raeburn 745: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 746: } elsif ($action eq 'loadbalancing') {
747: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 748: } elsif ($action eq 'ltitools') {
749: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 750: } elsif ($action eq 'ssl') {
751: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 752: } elsif ($action eq 'trust') {
753: $output = &modify_trust($dom,$lastactref,%domconfig);
1.320 raeburn 754: } elsif ($action eq 'lti') {
755: $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 756: }
757: return $output;
758: }
759:
760: sub print_config_box {
1.9 raeburn 761: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 762: my $rowtotal = 0;
1.49 raeburn 763: my $output;
764: if ($action eq 'coursecategories') {
765: $output = &coursecategories_javascript($settings);
1.236 raeburn 766: } elsif ($action eq 'defaults') {
767: $output = &defaults_javascript($settings);
1.282 raeburn 768: } elsif ($action eq 'helpsettings') {
769: my (%privs,%levelscurrent);
770: my %full=();
771: my %levels=(
772: course => {},
773: domain => {},
774: system => {},
775: );
776: my $context = 'domain';
777: my $crstype = 'Course';
778: my $formname = 'display';
779: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
780: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
781: $output =
782: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
783: \@templateroles);
1.91 raeburn 784: }
1.236 raeburn 785: $output .=
1.30 raeburn 786: '<table class="LC_nested_outer">
1.3 raeburn 787: <tr>
1.306 raeburn 788: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 789: &mt($item->{text}).' '.
790: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
791: '</tr>';
1.30 raeburn 792: $rowtotal ++;
1.110 raeburn 793: my $numheaders = 1;
794: if (ref($item->{'header'}) eq 'ARRAY') {
795: $numheaders = scalar(@{$item->{'header'}});
796: }
797: if ($numheaders > 1) {
1.64 raeburn 798: my $colspan = '';
1.145 raeburn 799: my $rightcolspan = '';
1.238 raeburn 800: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 801: ($action eq 'directorysrch') ||
1.256 raeburn 802: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 803: $colspan = ' colspan="2"';
804: }
1.145 raeburn 805: if ($action eq 'usersessions') {
806: $rightcolspan = ' colspan="3"';
807: }
1.30 raeburn 808: $output .= '
1.3 raeburn 809: <tr>
810: <td>
811: <table class="LC_nested">
812: <tr class="LC_info_row">
1.59 bisitz 813: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 814: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 815: </tr>';
1.69 raeburn 816: $rowtotal ++;
1.230 raeburn 817: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 818: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 819: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 820: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
821: ($action eq 'contacts')) {
1.230 raeburn 822: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 823: } elsif ($action eq 'coursecategories') {
1.230 raeburn 824: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 825: } elsif ($action eq 'login') {
1.256 raeburn 826: if ($numheaders == 4) {
1.168 raeburn 827: $colspan = ' colspan="2"';
828: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
829: } else {
830: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
831: }
1.230 raeburn 832: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 833: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 834: } elsif ($action eq 'rolecolors') {
1.30 raeburn 835: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 836: }
1.30 raeburn 837: $output .= '
1.6 raeburn 838: </table>
839: </td>
840: </tr>
841: <tr>
842: <td>
843: <table class="LC_nested">
844: <tr class="LC_info_row">
1.230 raeburn 845: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 846: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 847: </tr>';
848: $rowtotal ++;
1.230 raeburn 849: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
850: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 851: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.294 raeburn 852: ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults')) {
1.238 raeburn 853: if ($action eq 'coursecategories') {
854: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
855: $colspan = ' colspan="2"';
1.279 raeburn 856: } elsif ($action eq 'trust') {
857: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.238 raeburn 858: } else {
859: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
860: }
1.279 raeburn 861: if ($action eq 'trust') {
862: $output .= '
863: </table>
864: </td>
865: </tr>';
866: my @trusthdrs = qw(2 3 4 5 6 7);
867: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
868: for (my $i=0; $i<@trusthdrs; $i++) {
869: $output .= '
870: <tr>
871: <td>
872: <table class="LC_nested">
873: <tr class="LC_info_row">
874: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
875: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
876: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
877: </table>
878: </td>
879: </tr>';
880: }
881: $output .= '
882: <tr>
883: <td>
884: <table class="LC_nested">
885: <tr class="LC_info_row">
886: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
887: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
888: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
889: } else {
890: $output .= '
1.63 raeburn 891: </table>
892: </td>
893: </tr>
894: <tr>
895: <td>
896: <table class="LC_nested">
897: <tr class="LC_info_row">
898: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 899: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 900: </tr>'."\n";
1.279 raeburn 901: if ($action eq 'coursecategories') {
902: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
903: } else {
904: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
905: }
1.238 raeburn 906: }
1.63 raeburn 907: $rowtotal ++;
1.236 raeburn 908: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.282 raeburn 909: ($action eq 'defaults') || ($action eq 'directorysrch') ||
910: ($action eq 'helpsettings')) {
1.230 raeburn 911: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.293 raeburn 912: } elsif ($action eq 'ssl') {
913: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
914: </table>
915: </td>
916: </tr>
917: <tr>
918: <td>
919: <table class="LC_nested">
920: <tr class="LC_info_row">
921: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
922: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
923: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
924: </table>
925: </td>
926: </tr>
927: <tr>
928: <td>
929: <table class="LC_nested">
930: <tr class="LC_info_row">
931: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
932: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
933: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 934: } elsif ($action eq 'login') {
1.256 raeburn 935: if ($numheaders == 4) {
1.168 raeburn 936: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
937: </table>
938: </td>
939: </tr>
940: <tr>
941: <td>
942: <table class="LC_nested">
943: <tr class="LC_info_row">
944: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 945: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 946: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
947: $rowtotal ++;
948: } else {
949: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
950: }
1.256 raeburn 951: $output .= '
952: </table>
953: </td>
954: </tr>
955: <tr>
956: <td>
957: <table class="LC_nested">
958: <tr class="LC_info_row">';
959: if ($numheaders == 4) {
960: $output .= '
961: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
962: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
963: </tr>';
964: } else {
965: $output .= '
966: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
967: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
968: </tr>';
969: }
970: $rowtotal ++;
971: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 972: } elsif ($action eq 'requestcourses') {
1.247 raeburn 973: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
974: $rowtotal ++;
975: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 976: </table>
977: </td>
978: </tr>
979: <tr>
980: <td>
981: <table class="LC_nested">
982: <tr class="LC_info_row">
983: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
984: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 985: &textbookcourses_javascript($settings).
986: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
987: </table>
988: </td>
989: </tr>
990: <tr>
991: <td>
992: <table class="LC_nested">
993: <tr class="LC_info_row">
994: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
995: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
996: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 997: </table>
998: </td>
999: </tr>
1000: <tr>
1001: <td>
1002: <table class="LC_nested">
1003: <tr class="LC_info_row">
1.306 raeburn 1004: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1005: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1006: </tr>'.
1007: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1008: } elsif ($action eq 'requestauthor') {
1009: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1010: $rowtotal ++;
1.122 jms 1011: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1012: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1013: </table>
1014: </td>
1015: </tr>
1016: <tr>
1017: <td>
1018: <table class="LC_nested">
1019: <tr class="LC_info_row">
1.306 raeburn 1020: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 1021: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1022: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1023: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1024: </tr>'.
1.30 raeburn 1025: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1026: </table>
1027: </td>
1028: </tr>
1029: <tr>
1030: <td>
1031: <table class="LC_nested">
1032: <tr class="LC_info_row">
1.59 bisitz 1033: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1034: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1035: </tr>'.
1.30 raeburn 1036: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1037: $rowtotal += 2;
1.6 raeburn 1038: }
1.3 raeburn 1039: } else {
1.30 raeburn 1040: $output .= '
1.3 raeburn 1041: <tr>
1042: <td>
1043: <table class="LC_nested">
1.30 raeburn 1044: <tr class="LC_info_row">';
1.277 raeburn 1045: if ($action eq 'login') {
1.30 raeburn 1046: $output .= '
1.59 bisitz 1047: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1048: } elsif ($action eq 'serverstatuses') {
1049: $output .= '
1.306 raeburn 1050: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1051: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1052:
1.6 raeburn 1053: } else {
1.30 raeburn 1054: $output .= '
1.306 raeburn 1055: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1056: }
1.72 raeburn 1057: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1058: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1059: &mt($item->{'header'}->[0]->{'col2'});
1060: if ($action eq 'serverstatuses') {
1061: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1062: }
1.69 raeburn 1063: } else {
1.306 raeburn 1064: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1065: &mt($item->{'header'}->[0]->{'col2'});
1066: }
1067: $output .= '</td>';
1068: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1069: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1070: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1071: &mt($item->{'header'}->[0]->{'col3'});
1072: } else {
1.306 raeburn 1073: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1074: &mt($item->{'header'}->[0]->{'col3'});
1075: }
1.69 raeburn 1076: if ($action eq 'serverstatuses') {
1077: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1078: }
1079: $output .= '</td>';
1.6 raeburn 1080: }
1.150 raeburn 1081: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1082: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1083: &mt($item->{'header'}->[0]->{'col4'});
1084: }
1.69 raeburn 1085: $output .= '</tr>';
1.48 raeburn 1086: $rowtotal ++;
1.168 raeburn 1087: if ($action eq 'quotas') {
1.86 raeburn 1088: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1089: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1090: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.320 raeburn 1091: ($action eq 'ltitools') || ($action eq 'lti')) {
1.230 raeburn 1092: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 1093: } elsif ($action eq 'scantron') {
1094: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.121 raeburn 1095: }
1.3 raeburn 1096: }
1.30 raeburn 1097: $output .= '
1.3 raeburn 1098: </table>
1099: </td>
1100: </tr>
1.30 raeburn 1101: </table><br />';
1102: return ($output,$rowtotal);
1.1 raeburn 1103: }
1104:
1.3 raeburn 1105: sub print_login {
1.168 raeburn 1106: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 1107: my ($css_class,$datatable);
1.6 raeburn 1108: my %choices = &login_choices();
1.110 raeburn 1109:
1.168 raeburn 1110: if ($caller eq 'service') {
1.149 raeburn 1111: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1112: my $choice = $choices{'disallowlogin'};
1113: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1114: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1115: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1116: '<th>'.$choices{'server'}.'</th>'.
1117: '<th>'.$choices{'serverpath'}.'</th>'.
1118: '<th>'.$choices{'custompath'}.'</th>'.
1119: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1120: my %disallowed;
1121: if (ref($settings) eq 'HASH') {
1122: if (ref($settings->{'loginvia'}) eq 'HASH') {
1123: %disallowed = %{$settings->{'loginvia'}};
1124: }
1125: }
1126: foreach my $lonhost (sort(keys(%servers))) {
1127: my $direct = 'selected="selected"';
1.128 raeburn 1128: if (ref($disallowed{$lonhost}) eq 'HASH') {
1129: if ($disallowed{$lonhost}{'server'} ne '') {
1130: $direct = '';
1131: }
1.110 raeburn 1132: }
1.115 raeburn 1133: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1134: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1135: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1136: '</option>';
1.184 raeburn 1137: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1138: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1139: my $selected = '';
1.128 raeburn 1140: if (ref($disallowed{$lonhost}) eq 'HASH') {
1141: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1142: $selected = 'selected="selected"';
1143: }
1.110 raeburn 1144: }
1145: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1146: $servers{$hostid}.'</option>';
1147: }
1.128 raeburn 1148: $datatable .= '</select></td>'.
1149: '<td><select name="'.$lonhost.'_serverpath">';
1150: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1151: my $pathname = $path;
1152: if ($path eq 'custom') {
1153: $pathname = &mt('Custom Path').' ->';
1154: }
1155: my $selected = '';
1156: if (ref($disallowed{$lonhost}) eq 'HASH') {
1157: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1158: $selected = 'selected="selected"';
1159: }
1160: } elsif ($path eq '') {
1161: $selected = 'selected="selected"';
1162: }
1163: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1164: }
1165: $datatable .= '</select></td>';
1166: my ($custom,$exempt);
1167: if (ref($disallowed{$lonhost}) eq 'HASH') {
1168: $custom = $disallowed{$lonhost}{'custompath'};
1169: $exempt = $disallowed{$lonhost}{'exempt'};
1170: }
1171: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1172: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1173: '</tr>';
1.110 raeburn 1174: }
1175: $datatable .= '</table></td></tr>';
1176: return $datatable;
1.168 raeburn 1177: } elsif ($caller eq 'page') {
1178: my %defaultchecked = (
1179: 'coursecatalog' => 'on',
1.188 raeburn 1180: 'helpdesk' => 'on',
1.168 raeburn 1181: 'adminmail' => 'off',
1182: 'newuser' => 'off',
1183: );
1.188 raeburn 1184: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1185: my (%checkedon,%checkedoff);
1.42 raeburn 1186: foreach my $item (@toggles) {
1.168 raeburn 1187: if ($defaultchecked{$item} eq 'on') {
1188: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1189: $checkedoff{$item} = ' ';
1.168 raeburn 1190: } elsif ($defaultchecked{$item} eq 'off') {
1191: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1192: $checkedon{$item} = ' ';
1193: }
1.1 raeburn 1194: }
1.168 raeburn 1195: my @images = ('img','logo','domlogo','login');
1196: my @logintext = ('textcol','bgcol');
1197: my @bgs = ('pgbg','mainbg','sidebg');
1198: my @links = ('link','alink','vlink');
1199: my %designhash = &Apache::loncommon::get_domainconf($dom);
1200: my %defaultdesign = %Apache::loncommon::defaultdesign;
1201: my (%is_custom,%designs);
1202: my %defaults = (
1203: font => $defaultdesign{'login.font'},
1204: );
1.6 raeburn 1205: foreach my $item (@images) {
1.168 raeburn 1206: $defaults{$item} = $defaultdesign{'login.'.$item};
1207: $defaults{'showlogo'}{$item} = 1;
1208: }
1209: foreach my $item (@bgs) {
1210: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1211: }
1.41 raeburn 1212: foreach my $item (@logintext) {
1.168 raeburn 1213: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1214: }
1.168 raeburn 1215: foreach my $item (@links) {
1216: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1217: }
1.168 raeburn 1218: if (ref($settings) eq 'HASH') {
1219: foreach my $item (@toggles) {
1220: if ($settings->{$item} eq '1') {
1221: $checkedon{$item} = ' checked="checked" ';
1222: $checkedoff{$item} = ' ';
1223: } elsif ($settings->{$item} eq '0') {
1224: $checkedoff{$item} = ' checked="checked" ';
1225: $checkedon{$item} = ' ';
1226: }
1227: }
1228: foreach my $item (@images) {
1229: if (defined($settings->{$item})) {
1230: $designs{$item} = $settings->{$item};
1231: $is_custom{$item} = 1;
1232: }
1233: if (defined($settings->{'showlogo'}{$item})) {
1234: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1235: }
1236: }
1237: foreach my $item (@logintext) {
1238: if ($settings->{$item} ne '') {
1239: $designs{'logintext'}{$item} = $settings->{$item};
1240: $is_custom{$item} = 1;
1241: }
1242: }
1243: if ($settings->{'font'} ne '') {
1244: $designs{'font'} = $settings->{'font'};
1245: $is_custom{'font'} = 1;
1246: }
1247: foreach my $item (@bgs) {
1248: if ($settings->{$item} ne '') {
1249: $designs{'bgs'}{$item} = $settings->{$item};
1250: $is_custom{$item} = 1;
1251: }
1252: }
1253: foreach my $item (@links) {
1254: if ($settings->{$item} ne '') {
1255: $designs{'links'}{$item} = $settings->{$item};
1256: $is_custom{$item} = 1;
1257: }
1258: }
1259: } else {
1260: if ($designhash{$dom.'.login.font'} ne '') {
1261: $designs{'font'} = $designhash{$dom.'.login.font'};
1262: $is_custom{'font'} = 1;
1263: }
1264: foreach my $item (@images) {
1265: if ($designhash{$dom.'.login.'.$item} ne '') {
1266: $designs{$item} = $designhash{$dom.'.login.'.$item};
1267: $is_custom{$item} = 1;
1268: }
1269: }
1270: foreach my $item (@bgs) {
1271: if ($designhash{$dom.'.login.'.$item} ne '') {
1272: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1273: $is_custom{$item} = 1;
1274: }
1.6 raeburn 1275: }
1.168 raeburn 1276: foreach my $item (@links) {
1277: if ($designhash{$dom.'.login.'.$item} ne '') {
1278: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1279: $is_custom{$item} = 1;
1280: }
1.6 raeburn 1281: }
1282: }
1.168 raeburn 1283: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1284: logo => 'Institution Logo',
1285: domlogo => 'Domain Logo',
1286: login => 'Login box');
1287: my $itemcount = 1;
1288: foreach my $item (@toggles) {
1289: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1290: $datatable .=
1291: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1292: '</td><td>'.
1293: '<span class="LC_nobreak"><label><input type="radio" name="'.
1294: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1295: '</label> <label><input type="radio" name="'.$item.'"'.
1296: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1297: '</tr>';
1298: $itemcount ++;
1.6 raeburn 1299: }
1.168 raeburn 1300: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1301: $datatable .= '</tr></table></td></tr>';
1302: } elsif ($caller eq 'help') {
1303: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1304: my $switchserver = &check_switchserver($dom,$confname);
1305: my $itemcount = 1;
1306: $defaulturl = '/adm/loginproblems.html';
1307: $defaulttype = 'default';
1308: %lt = &Apache::lonlocal::texthash (
1309: del => 'Delete?',
1310: rep => 'Replace:',
1311: upl => 'Upload:',
1312: default => 'Default',
1313: custom => 'Custom',
1314: );
1315: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1316: my @currlangs;
1317: if (ref($settings) eq 'HASH') {
1318: if (ref($settings->{'helpurl'}) eq 'HASH') {
1319: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1320: next if ($settings->{'helpurl'}{$key} eq '');
1321: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1322: $type{$key} = 'custom';
1323: unless ($key eq 'nolang') {
1324: push(@currlangs,$key);
1325: }
1326: }
1327: } elsif ($settings->{'helpurl'} ne '') {
1328: $type{'nolang'} = 'custom';
1329: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1330: }
1331: }
1.168 raeburn 1332: foreach my $lang ('nolang',sort(@currlangs)) {
1333: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1334: $datatable .= '<tr'.$css_class.'>';
1335: if ($url{$lang} eq '') {
1336: $url{$lang} = $defaulturl;
1337: }
1338: if ($type{$lang} eq '') {
1339: $type{$lang} = $defaulttype;
1340: }
1341: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1342: if ($lang eq 'nolang') {
1343: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1344: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1345: } else {
1346: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1347: $langchoices{$lang},
1348: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1349: }
1350: $datatable .= '</span></td>'."\n".
1351: '<td class="LC_left_item">';
1352: if ($type{$lang} eq 'custom') {
1353: $datatable .= '<span class="LC_nobreak"><label>'.
1354: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1355: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1356: } else {
1357: $datatable .= $lt{'upl'};
1358: }
1359: $datatable .='<br />';
1360: if ($switchserver) {
1361: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1362: } else {
1363: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1364: }
1.168 raeburn 1365: $datatable .= '</td></tr>';
1366: $itemcount ++;
1.6 raeburn 1367: }
1.168 raeburn 1368: my @addlangs;
1369: foreach my $lang (sort(keys(%langchoices))) {
1370: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1371: push(@addlangs,$lang);
1372: }
1373: if (@addlangs > 0) {
1374: my %toadd;
1375: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1376: $toadd{''} = &mt('Select');
1377: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1378: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1379: &mt('Add log-in help page for a specific language:').' '.
1380: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1381: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1382: if ($switchserver) {
1383: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1384: } else {
1385: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1386: }
1.168 raeburn 1387: $datatable .= '</td></tr>';
1.169 raeburn 1388: $itemcount ++;
1.6 raeburn 1389: }
1.169 raeburn 1390: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1391: } elsif ($caller eq 'headtag') {
1392: my %domservers = &Apache::lonnet::get_servers($dom);
1393: my $choice = $choices{'headtag'};
1394: $css_class = ' class="LC_odd_row"';
1395: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1396: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1397: '<th>'.$choices{'current'}.'</th>'.
1398: '<th>'.$choices{'action'}.'</th>'.
1399: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1400: my (%currurls,%currexempt);
1401: if (ref($settings) eq 'HASH') {
1402: if (ref($settings->{'headtag'}) eq 'HASH') {
1403: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1404: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1405: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1406: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1407: }
1408: }
1409: }
1410: }
1411: my %lt = &Apache::lonlocal::texthash(
1412: del => 'Delete?',
1413: rep => 'Replace:',
1414: upl => 'Upload:',
1415: curr => 'View contents',
1416: none => 'None',
1417: );
1418: my $switchserver = &check_switchserver($dom,$confname);
1419: foreach my $lonhost (sort(keys(%domservers))) {
1420: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1421: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1422: if ($currurls{$lonhost}) {
1423: $datatable .= '<td class="LC_right_item"><a href="'.
1424: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1425: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1426: '">'.$lt{'curr'}.'</a></td>'.
1427: '<td><span class="LC_nobreak"><label>'.
1428: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1429: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1430: } else {
1431: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1432: }
1433: $datatable .='<br />';
1434: if ($switchserver) {
1435: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1436: } else {
1437: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1438: }
1439: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1440: }
1441: $datatable .= '</table></td></tr>';
1.1 raeburn 1442: }
1.6 raeburn 1443: return $datatable;
1444: }
1445:
1446: sub login_choices {
1447: my %choices =
1448: &Apache::lonlocal::texthash (
1.116 bisitz 1449: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1450: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1451: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1452: disallowlogin => "Login page requests redirected",
1453: hostid => "Server",
1.128 raeburn 1454: server => "Redirect to:",
1455: serverpath => "Path",
1456: custompath => "Custom",
1457: exempt => "Exempt IP(s)",
1.110 raeburn 1458: directlogin => "No redirect",
1459: newuser => "Link to create a user account",
1460: img => "Header",
1461: logo => "Main Logo",
1462: domlogo => "Domain Logo",
1463: login => "Log-in Header",
1464: textcol => "Text color",
1465: bgcol => "Box color",
1466: bgs => "Background colors",
1467: links => "Link colors",
1468: font => "Font color",
1469: pgbg => "Header",
1470: mainbg => "Page",
1471: sidebg => "Login box",
1472: link => "Link",
1473: alink => "Active link",
1474: vlink => "Visited link",
1.256 raeburn 1475: headtag => "Custom markup",
1476: action => "Action",
1477: current => "Current",
1.6 raeburn 1478: );
1479: return %choices;
1480: }
1481:
1482: sub print_rolecolors {
1.30 raeburn 1483: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1484: my %choices = &color_font_choices();
1485: my @bgs = ('pgbg','tabbg','sidebg');
1486: my @links = ('link','alink','vlink');
1487: my @images = ('img');
1488: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1489: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1490: my %defaultdesign = %Apache::loncommon::defaultdesign;
1491: my (%is_custom,%designs);
1.200 raeburn 1492: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1493: if (ref($settings) eq 'HASH') {
1494: if (ref($settings->{$role}) eq 'HASH') {
1495: if ($settings->{$role}->{'img'} ne '') {
1496: $designs{'img'} = $settings->{$role}->{'img'};
1497: $is_custom{'img'} = 1;
1498: }
1499: if ($settings->{$role}->{'font'} ne '') {
1500: $designs{'font'} = $settings->{$role}->{'font'};
1501: $is_custom{'font'} = 1;
1502: }
1.97 tempelho 1503: if ($settings->{$role}->{'fontmenu'} ne '') {
1504: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1505: $is_custom{'fontmenu'} = 1;
1506: }
1.6 raeburn 1507: foreach my $item (@bgs) {
1508: if ($settings->{$role}->{$item} ne '') {
1509: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1510: $is_custom{$item} = 1;
1511: }
1512: }
1513: foreach my $item (@links) {
1514: if ($settings->{$role}->{$item} ne '') {
1515: $designs{'links'}{$item} = $settings->{$role}->{$item};
1516: $is_custom{$item} = 1;
1517: }
1518: }
1519: }
1520: } else {
1521: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1522: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1523: $is_custom{'img'} = 1;
1524: }
1.97 tempelho 1525: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1526: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1527: $is_custom{'fontmenu'} = 1;
1528: }
1.6 raeburn 1529: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1530: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1531: $is_custom{'font'} = 1;
1532: }
1533: foreach my $item (@bgs) {
1534: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1535: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1536: $is_custom{$item} = 1;
1537:
1538: }
1539: }
1540: foreach my $item (@links) {
1541: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1542: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1543: $is_custom{$item} = 1;
1544: }
1545: }
1546: }
1547: my $itemcount = 1;
1.30 raeburn 1548: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1549: $datatable .= '</tr></table></td></tr>';
1550: return $datatable;
1551: }
1552:
1.200 raeburn 1553: sub role_defaults {
1554: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1555: my %defaults;
1556: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1557: return %defaults;
1558: }
1559: my %defaultdesign = %Apache::loncommon::defaultdesign;
1560: if ($role eq 'login') {
1561: %defaults = (
1562: font => $defaultdesign{$role.'.font'},
1563: );
1564: if (ref($logintext) eq 'ARRAY') {
1565: foreach my $item (@{$logintext}) {
1566: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1567: }
1568: }
1569: foreach my $item (@{$images}) {
1570: $defaults{'showlogo'}{$item} = 1;
1571: }
1572: } else {
1573: %defaults = (
1574: img => $defaultdesign{$role.'.img'},
1575: font => $defaultdesign{$role.'.font'},
1576: fontmenu => $defaultdesign{$role.'.fontmenu'},
1577: );
1578: }
1579: foreach my $item (@{$bgs}) {
1580: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1581: }
1582: foreach my $item (@{$links}) {
1583: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1584: }
1585: foreach my $item (@{$images}) {
1586: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1587: }
1588: return %defaults;
1589: }
1590:
1.6 raeburn 1591: sub display_color_options {
1.9 raeburn 1592: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1593: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1594: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1595: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1596: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1597: '<td>'.$choices->{'font'}.'</td>';
1598: if (!$is_custom->{'font'}) {
1.30 raeburn 1599: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1600: } else {
1601: $datatable .= '<td> </td>';
1602: }
1.174 foxr 1603: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1604:
1.8 raeburn 1605: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1606: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1607: ' value="'.$current_color.'" /> '.
1.174 foxr 1608: ' </td></tr>';
1.107 raeburn 1609: unless ($role eq 'login') {
1610: $datatable .= '<tr'.$css_class.'>'.
1611: '<td>'.$choices->{'fontmenu'}.'</td>';
1612: if (!$is_custom->{'fontmenu'}) {
1613: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1614: } else {
1615: $datatable .= '<td> </td>';
1616: }
1.202 raeburn 1617: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1618: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1619: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1620: '<input class="colorchooser" type="text" size="10" name="'
1621: .$role.'_fontmenu"'.
1622: ' value="'.$current_color.'" /> '.
1623: ' </td></tr>';
1.97 tempelho 1624: }
1.9 raeburn 1625: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1626: foreach my $img (@{$images}) {
1.18 albertel 1627: $itemcount ++;
1.6 raeburn 1628: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1629: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1630: '<td>'.$choices->{$img};
1.41 raeburn 1631: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1632: if ($role eq 'login') {
1633: if ($img eq 'login') {
1634: $login_hdr_pick =
1.135 bisitz 1635: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1636: $logincolors =
1637: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1638: $designs,$defaults);
1.70 raeburn 1639: } elsif ($img ne 'domlogo') {
1640: $datatable.= &logo_display_options($img,$defaults,$designs);
1641: }
1642: }
1643: $datatable .= '</td>';
1.6 raeburn 1644: if ($designs->{$img} ne '') {
1645: $imgfile = $designs->{$img};
1.18 albertel 1646: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1647: } else {
1648: $imgfile = $defaults->{$img};
1649: }
1650: if ($imgfile) {
1.9 raeburn 1651: my ($showfile,$fullsize);
1652: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1653: my $urldir = $1;
1654: my $filename = $2;
1655: my @info = &Apache::lonnet::stat_file($designs->{$img});
1656: if (@info) {
1657: my $thumbfile = 'tn-'.$filename;
1658: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1659: if (@thumb) {
1660: $showfile = $urldir.'/'.$thumbfile;
1661: } else {
1662: $showfile = $imgfile;
1663: }
1664: } else {
1665: $showfile = '';
1666: }
1667: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1668: $showfile = $imgfile;
1.6 raeburn 1669: my $imgdir = $1;
1670: my $filename = $2;
1.159 raeburn 1671: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1672: $showfile = "/$imgdir/tn-".$filename;
1673: } else {
1.159 raeburn 1674: my $input = $londocroot.$imgfile;
1675: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1676: if (!-e $output) {
1.9 raeburn 1677: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1678: my ($fullwidth,$fullheight) = &check_dimensions($input);
1679: if ($fullwidth ne '' && $fullheight ne '') {
1680: if ($fullwidth > $width && $fullheight > $height) {
1681: my $size = $width.'x'.$height;
1.316 raeburn 1682: my @args = ('convert','-sample',$size,$input,$output);
1683: system({$args[0]} @args);
1.159 raeburn 1684: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1685: }
1686: }
1.6 raeburn 1687: }
1688: }
1.16 raeburn 1689: }
1.6 raeburn 1690: if ($showfile) {
1.40 raeburn 1691: if ($showfile =~ m{^/(adm|res)/}) {
1692: if ($showfile =~ m{^/res/}) {
1693: my $local_showfile =
1694: &Apache::lonnet::filelocation('',$showfile);
1695: &Apache::lonnet::repcopy($local_showfile);
1696: }
1697: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1698: }
1699: if ($imgfile) {
1700: if ($imgfile =~ m{^/(adm|res)/}) {
1701: if ($imgfile =~ m{^/res/}) {
1702: my $local_imgfile =
1703: &Apache::lonnet::filelocation('',$imgfile);
1704: &Apache::lonnet::repcopy($local_imgfile);
1705: }
1706: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1707: } else {
1708: $fullsize = $imgfile;
1709: }
1710: }
1.41 raeburn 1711: $datatable .= '<td>';
1712: if ($img eq 'login') {
1.135 bisitz 1713: $datatable .= $login_hdr_pick;
1714: }
1.41 raeburn 1715: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1716: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1717: } else {
1.201 raeburn 1718: $datatable .= '<td> </td><td class="LC_left_item">'.
1719: &mt('Upload:').'<br />';
1.6 raeburn 1720: }
1721: } else {
1.201 raeburn 1722: $datatable .= '<td> </td><td class="LC_left_item">'.
1723: &mt('Upload:').'<br />';
1.6 raeburn 1724: }
1.9 raeburn 1725: if ($switchserver) {
1726: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1727: } else {
1.135 bisitz 1728: if ($img ne 'login') { # suppress file selection for Log-in header
1729: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1730: }
1.9 raeburn 1731: }
1732: $datatable .= '</td></tr>';
1.6 raeburn 1733: }
1734: $itemcount ++;
1735: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1736: $datatable .= '<tr'.$css_class.'>'.
1737: '<td>'.$choices->{'bgs'}.'</td>';
1738: my $bgs_def;
1739: foreach my $item (@{$bgs}) {
1740: if (!$is_custom->{$item}) {
1.70 raeburn 1741: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span id="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 1742: }
1743: }
1744: if ($bgs_def) {
1.8 raeburn 1745: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1746: } else {
1747: $datatable .= '<td> </td>';
1748: }
1749: $datatable .= '<td class="LC_right_item">'.
1750: '<table border="0"><tr>';
1.174 foxr 1751:
1.6 raeburn 1752: foreach my $item (@{$bgs}) {
1.306 raeburn 1753: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 1754: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1755: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1756: $datatable .= ' ';
1.6 raeburn 1757: }
1.174 foxr 1758: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1759: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1760: }
1761: $datatable .= '</tr></table></td></tr>';
1762: $itemcount ++;
1763: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1764: $datatable .= '<tr'.$css_class.'>'.
1765: '<td>'.$choices->{'links'}.'</td>';
1766: my $links_def;
1767: foreach my $item (@{$links}) {
1768: if (!$is_custom->{$item}) {
1.30 raeburn 1769: $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 1770: }
1771: }
1772: if ($links_def) {
1.8 raeburn 1773: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1774: } else {
1775: $datatable .= '<td> </td>';
1776: }
1777: $datatable .= '<td class="LC_right_item">'.
1778: '<table border="0"><tr>';
1779: foreach my $item (@{$links}) {
1.234 raeburn 1780: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 1781: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 1782: if ($designs->{'links'}{$item}) {
1.174 foxr 1783: $datatable.=' ';
1.6 raeburn 1784: }
1.174 foxr 1785: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1786: '" /></td>';
1787: }
1.30 raeburn 1788: $$rowtotal += $itemcount;
1.3 raeburn 1789: return $datatable;
1790: }
1791:
1.70 raeburn 1792: sub logo_display_options {
1793: my ($img,$defaults,$designs) = @_;
1794: my $checkedon;
1795: if (ref($defaults) eq 'HASH') {
1796: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1797: if ($defaults->{'showlogo'}{$img}) {
1798: $checkedon = 'checked="checked" ';
1799: }
1800: }
1801: }
1802: if (ref($designs) eq 'HASH') {
1803: if (ref($designs->{'showlogo'}) eq 'HASH') {
1804: if (defined($designs->{'showlogo'}{$img})) {
1805: if ($designs->{'showlogo'}{$img} == 0) {
1806: $checkedon = '';
1807: } elsif ($designs->{'showlogo'}{$img} == 1) {
1808: $checkedon = 'checked="checked" ';
1809: }
1810: }
1811: }
1812: }
1813: return '<br /><label> <input type="checkbox" name="'.
1814: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1815: &mt('show').'</label>'."\n";
1816: }
1817:
1.41 raeburn 1818: sub login_header_options {
1.135 bisitz 1819: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1820: my $output = '';
1.41 raeburn 1821: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1822: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1823: if (!$is_custom->{'textcol'}) {
1824: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1825: ' ';
1826: }
1827: if (!$is_custom->{'bgcol'}) {
1828: $output .= $choices->{'bgcol'}.': '.
1829: '<span id="css_'.$role.'_font" style="background-color: '.
1830: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1831: }
1832: $output .= '<br />';
1833: }
1834: $output .='<br />';
1835: return $output;
1836: }
1837:
1838: sub login_text_colors {
1.201 raeburn 1839: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1840: my $color_menu = '<table border="0"><tr>';
1841: foreach my $item (@{$logintext}) {
1.306 raeburn 1842: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 1843: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1844: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1845: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1846: }
1847: $color_menu .= '</tr></table><br />';
1848: return $color_menu;
1849: }
1850:
1851: sub image_changes {
1852: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1853: my $output;
1.135 bisitz 1854: if ($img eq 'login') {
1855: # suppress image for Log-in header
1856: } elsif (!$is_custom) {
1.70 raeburn 1857: if ($img ne 'domlogo') {
1.41 raeburn 1858: $output .= &mt('Default image:').'<br />';
1859: } else {
1860: $output .= &mt('Default in use:').'<br />';
1861: }
1862: }
1.135 bisitz 1863: if ($img eq 'login') { # suppress image for Log-in header
1864: $output .= '<td>'.$logincolors;
1.41 raeburn 1865: } else {
1.135 bisitz 1866: if ($img_import) {
1867: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1868: }
1869: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1870: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1871: if ($is_custom) {
1872: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1873: '<input type="checkbox" name="'.
1874: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1875: '</label> '.&mt('Replace:').'</span><br />';
1876: } else {
1.306 raeburn 1877: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1878: }
1.41 raeburn 1879: }
1880: return $output;
1881: }
1882:
1.3 raeburn 1883: sub print_quotas {
1.86 raeburn 1884: my ($dom,$settings,$rowtotal,$action) = @_;
1885: my $context;
1886: if ($action eq 'quotas') {
1887: $context = 'tools';
1888: } else {
1889: $context = $action;
1890: }
1.197 raeburn 1891: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1892: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1893: my $typecount = 0;
1.101 raeburn 1894: my ($css_class,%titles);
1.86 raeburn 1895: if ($context eq 'requestcourses') {
1.325 raeburn 1896: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 1897: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1898: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1899: %titles = &courserequest_titles();
1.163 raeburn 1900: } elsif ($context eq 'requestauthor') {
1901: @usertools = ('author');
1902: @options = ('norequest','approval','automatic');
1.210 raeburn 1903: %titles = &authorrequest_titles();
1.86 raeburn 1904: } else {
1.162 raeburn 1905: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1906: %titles = &tool_titles();
1.86 raeburn 1907: }
1.26 raeburn 1908: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1909: foreach my $type (@{$types}) {
1.197 raeburn 1910: my ($currdefquota,$currauthorquota);
1.163 raeburn 1911: unless (($context eq 'requestcourses') ||
1912: ($context eq 'requestauthor')) {
1.86 raeburn 1913: if (ref($settings) eq 'HASH') {
1914: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1915: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1916: } else {
1917: $currdefquota = $settings->{$type};
1918: }
1.197 raeburn 1919: if (ref($settings->{authorquota}) eq 'HASH') {
1920: $currauthorquota = $settings->{authorquota}->{$type};
1921: }
1.78 raeburn 1922: }
1.72 raeburn 1923: }
1.3 raeburn 1924: if (defined($usertypes->{$type})) {
1925: $typecount ++;
1926: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1927: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1928: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1929: '<td class="LC_left_item">';
1.101 raeburn 1930: if ($context eq 'requestcourses') {
1931: $datatable .= '<table><tr>';
1932: }
1933: my %cell;
1.72 raeburn 1934: foreach my $item (@usertools) {
1.101 raeburn 1935: if ($context eq 'requestcourses') {
1936: my ($curroption,$currlimit);
1937: if (ref($settings) eq 'HASH') {
1938: if (ref($settings->{$item}) eq 'HASH') {
1939: $curroption = $settings->{$item}->{$type};
1940: if ($curroption =~ /^autolimit=(\d*)$/) {
1941: $currlimit = $1;
1942: }
1943: }
1944: }
1945: if (!$curroption) {
1946: $curroption = 'norequest';
1947: }
1948: $datatable .= '<th>'.$titles{$item}.'</th>';
1949: foreach my $option (@options) {
1950: my $val = $option;
1951: if ($option eq 'norequest') {
1952: $val = 0;
1953: }
1954: if ($option eq 'validate') {
1955: my $canvalidate = 0;
1956: if (ref($validations{$item}) eq 'HASH') {
1957: if ($validations{$item}{$type}) {
1958: $canvalidate = 1;
1959: }
1960: }
1961: next if (!$canvalidate);
1962: }
1963: my $checked = '';
1964: if ($option eq $curroption) {
1965: $checked = ' checked="checked"';
1966: } elsif ($option eq 'autolimit') {
1967: if ($curroption =~ /^autolimit/) {
1968: $checked = ' checked="checked"';
1969: }
1970: }
1971: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1972: '<input type="radio" name="crsreq_'.$item.
1973: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1974: $titles{$option}.'</label>';
1.101 raeburn 1975: if ($option eq 'autolimit') {
1.127 raeburn 1976: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1977: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1978: 'value="'.$currlimit.'" />';
1.101 raeburn 1979: }
1.127 raeburn 1980: $cell{$item} .= '</span> ';
1.103 raeburn 1981: if ($option eq 'autolimit') {
1.127 raeburn 1982: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1983: }
1.101 raeburn 1984: }
1.163 raeburn 1985: } elsif ($context eq 'requestauthor') {
1986: my $curroption;
1987: if (ref($settings) eq 'HASH') {
1988: $curroption = $settings->{$type};
1989: }
1990: if (!$curroption) {
1991: $curroption = 'norequest';
1992: }
1993: foreach my $option (@options) {
1994: my $val = $option;
1995: if ($option eq 'norequest') {
1996: $val = 0;
1997: }
1998: my $checked = '';
1999: if ($option eq $curroption) {
2000: $checked = ' checked="checked"';
2001: }
2002: $datatable .= '<span class="LC_nobreak"><label>'.
2003: '<input type="radio" name="authorreq_'.$type.
2004: '" value="'.$val.'"'.$checked.' />'.
2005: $titles{$option}.'</label></span> ';
2006: }
1.101 raeburn 2007: } else {
2008: my $checked = 'checked="checked" ';
2009: if (ref($settings) eq 'HASH') {
2010: if (ref($settings->{$item}) eq 'HASH') {
2011: if ($settings->{$item}->{$type} == 0) {
2012: $checked = '';
2013: } elsif ($settings->{$item}->{$type} == 1) {
2014: $checked = 'checked="checked" ';
2015: }
1.78 raeburn 2016: }
1.72 raeburn 2017: }
1.101 raeburn 2018: $datatable .= '<span class="LC_nobreak"><label>'.
2019: '<input type="checkbox" name="'.$context.'_'.$item.
2020: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2021: '</label></span> ';
1.72 raeburn 2022: }
1.101 raeburn 2023: }
2024: if ($context eq 'requestcourses') {
2025: $datatable .= '</tr><tr>';
2026: foreach my $item (@usertools) {
1.106 raeburn 2027: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2028: }
2029: $datatable .= '</tr></table>';
1.72 raeburn 2030: }
1.86 raeburn 2031: $datatable .= '</td>';
1.163 raeburn 2032: unless (($context eq 'requestcourses') ||
2033: ($context eq 'requestauthor')) {
1.86 raeburn 2034: $datatable .=
1.197 raeburn 2035: '<td class="LC_right_item">'.
2036: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2037: '<input type="text" name="quota_'.$type.
1.72 raeburn 2038: '" value="'.$currdefquota.
1.197 raeburn 2039: '" size="5" /></span>'.(' ' x 2).
2040: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2041: '<input type="text" name="authorquota_'.$type.
2042: '" value="'.$currauthorquota.
2043: '" size="5" /></span></td>';
1.86 raeburn 2044: }
2045: $datatable .= '</tr>';
1.3 raeburn 2046: }
2047: }
2048: }
1.163 raeburn 2049: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2050: $defaultquota = '20';
1.197 raeburn 2051: $authorquota = '500';
1.86 raeburn 2052: if (ref($settings) eq 'HASH') {
2053: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2054: $defaultquota = $settings->{'defaultquota'}->{'default'};
2055: } elsif (defined($settings->{'default'})) {
2056: $defaultquota = $settings->{'default'};
2057: }
1.197 raeburn 2058: if (ref($settings->{'authorquota'}) eq 'HASH') {
2059: $authorquota = $settings->{'authorquota'}->{'default'};
2060: }
1.3 raeburn 2061: }
2062: }
2063: $typecount ++;
2064: $css_class = $typecount%2?' class="LC_odd_row"':'';
2065: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2066: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2067: '<td class="LC_left_item">';
1.101 raeburn 2068: if ($context eq 'requestcourses') {
2069: $datatable .= '<table><tr>';
2070: }
2071: my %defcell;
1.72 raeburn 2072: foreach my $item (@usertools) {
1.101 raeburn 2073: if ($context eq 'requestcourses') {
2074: my ($curroption,$currlimit);
2075: if (ref($settings) eq 'HASH') {
2076: if (ref($settings->{$item}) eq 'HASH') {
2077: $curroption = $settings->{$item}->{'default'};
2078: if ($curroption =~ /^autolimit=(\d*)$/) {
2079: $currlimit = $1;
2080: }
2081: }
2082: }
2083: if (!$curroption) {
2084: $curroption = 'norequest';
2085: }
2086: $datatable .= '<th>'.$titles{$item}.'</th>';
2087: foreach my $option (@options) {
2088: my $val = $option;
2089: if ($option eq 'norequest') {
2090: $val = 0;
2091: }
2092: if ($option eq 'validate') {
2093: my $canvalidate = 0;
2094: if (ref($validations{$item}) eq 'HASH') {
2095: if ($validations{$item}{'default'}) {
2096: $canvalidate = 1;
2097: }
2098: }
2099: next if (!$canvalidate);
2100: }
2101: my $checked = '';
2102: if ($option eq $curroption) {
2103: $checked = ' checked="checked"';
2104: } elsif ($option eq 'autolimit') {
2105: if ($curroption =~ /^autolimit/) {
2106: $checked = ' checked="checked"';
2107: }
2108: }
2109: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2110: '<input type="radio" name="crsreq_'.$item.
2111: '_default" value="'.$val.'"'.$checked.' />'.
2112: $titles{$option}.'</label>';
2113: if ($option eq 'autolimit') {
1.127 raeburn 2114: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2115: $item.'_limit_default" size="1" '.
2116: 'value="'.$currlimit.'" />';
2117: }
1.127 raeburn 2118: $defcell{$item} .= '</span> ';
1.104 raeburn 2119: if ($option eq 'autolimit') {
1.127 raeburn 2120: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2121: }
1.101 raeburn 2122: }
1.163 raeburn 2123: } elsif ($context eq 'requestauthor') {
2124: my $curroption;
2125: if (ref($settings) eq 'HASH') {
1.172 raeburn 2126: $curroption = $settings->{'default'};
1.163 raeburn 2127: }
2128: if (!$curroption) {
2129: $curroption = 'norequest';
2130: }
2131: foreach my $option (@options) {
2132: my $val = $option;
2133: if ($option eq 'norequest') {
2134: $val = 0;
2135: }
2136: my $checked = '';
2137: if ($option eq $curroption) {
2138: $checked = ' checked="checked"';
2139: }
2140: $datatable .= '<span class="LC_nobreak"><label>'.
2141: '<input type="radio" name="authorreq_default"'.
2142: ' value="'.$val.'"'.$checked.' />'.
2143: $titles{$option}.'</label></span> ';
2144: }
1.101 raeburn 2145: } else {
2146: my $checked = 'checked="checked" ';
2147: if (ref($settings) eq 'HASH') {
2148: if (ref($settings->{$item}) eq 'HASH') {
2149: if ($settings->{$item}->{'default'} == 0) {
2150: $checked = '';
2151: } elsif ($settings->{$item}->{'default'} == 1) {
2152: $checked = 'checked="checked" ';
2153: }
1.78 raeburn 2154: }
1.72 raeburn 2155: }
1.101 raeburn 2156: $datatable .= '<span class="LC_nobreak"><label>'.
2157: '<input type="checkbox" name="'.$context.'_'.$item.
2158: '" value="default" '.$checked.'/>'.$titles{$item}.
2159: '</label></span> ';
2160: }
2161: }
2162: if ($context eq 'requestcourses') {
2163: $datatable .= '</tr><tr>';
2164: foreach my $item (@usertools) {
1.106 raeburn 2165: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2166: }
1.101 raeburn 2167: $datatable .= '</tr></table>';
1.72 raeburn 2168: }
1.86 raeburn 2169: $datatable .= '</td>';
1.163 raeburn 2170: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2171: $datatable .= '<td class="LC_right_item">'.
2172: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2173: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2174: $defaultquota.'" size="5" /></span>'.(' ' x2).
2175: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2176: '<input type="text" name="authorquota" value="'.
2177: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2178: }
2179: $datatable .= '</tr>';
1.72 raeburn 2180: $typecount ++;
2181: $css_class = $typecount%2?' class="LC_odd_row"':'';
2182: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2183: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2184: if ($context eq 'requestcourses') {
1.109 raeburn 2185: $datatable .= &mt('(overrides affiliation, if set)').
2186: '</td>'.
2187: '<td class="LC_left_item">'.
2188: '<table><tr>';
1.101 raeburn 2189: } else {
1.109 raeburn 2190: $datatable .= &mt('(overrides affiliation, if checked)').
2191: '</td>'.
2192: '<td class="LC_left_item" colspan="2">'.
2193: '<br />';
1.101 raeburn 2194: }
2195: my %advcell;
1.72 raeburn 2196: foreach my $item (@usertools) {
1.101 raeburn 2197: if ($context eq 'requestcourses') {
2198: my ($curroption,$currlimit);
2199: if (ref($settings) eq 'HASH') {
2200: if (ref($settings->{$item}) eq 'HASH') {
2201: $curroption = $settings->{$item}->{'_LC_adv'};
2202: if ($curroption =~ /^autolimit=(\d*)$/) {
2203: $currlimit = $1;
2204: }
2205: }
2206: }
2207: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2208: my $checked = '';
2209: if ($curroption eq '') {
2210: $checked = ' checked="checked"';
2211: }
2212: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2213: '<input type="radio" name="crsreq_'.$item.
2214: '__LC_adv" value=""'.$checked.' />'.
2215: &mt('No override set').'</label></span> ';
1.101 raeburn 2216: foreach my $option (@options) {
2217: my $val = $option;
2218: if ($option eq 'norequest') {
2219: $val = 0;
2220: }
2221: if ($option eq 'validate') {
2222: my $canvalidate = 0;
2223: if (ref($validations{$item}) eq 'HASH') {
2224: if ($validations{$item}{'_LC_adv'}) {
2225: $canvalidate = 1;
2226: }
2227: }
2228: next if (!$canvalidate);
2229: }
2230: my $checked = '';
1.104 raeburn 2231: if ($val eq $curroption) {
1.101 raeburn 2232: $checked = ' checked="checked"';
2233: } elsif ($option eq 'autolimit') {
2234: if ($curroption =~ /^autolimit/) {
2235: $checked = ' checked="checked"';
2236: }
2237: }
2238: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2239: '<input type="radio" name="crsreq_'.$item.
2240: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2241: $titles{$option}.'</label>';
2242: if ($option eq 'autolimit') {
1.127 raeburn 2243: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2244: $item.'_limit__LC_adv" size="1" '.
2245: 'value="'.$currlimit.'" />';
2246: }
1.127 raeburn 2247: $advcell{$item} .= '</span> ';
1.104 raeburn 2248: if ($option eq 'autolimit') {
1.127 raeburn 2249: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2250: }
1.101 raeburn 2251: }
1.163 raeburn 2252: } elsif ($context eq 'requestauthor') {
2253: my $curroption;
2254: if (ref($settings) eq 'HASH') {
2255: $curroption = $settings->{'_LC_adv'};
2256: }
2257: my $checked = '';
2258: if ($curroption eq '') {
2259: $checked = ' checked="checked"';
2260: }
2261: $datatable .= '<span class="LC_nobreak"><label>'.
2262: '<input type="radio" name="authorreq__LC_adv"'.
2263: ' value=""'.$checked.' />'.
2264: &mt('No override set').'</label></span> ';
2265: foreach my $option (@options) {
2266: my $val = $option;
2267: if ($option eq 'norequest') {
2268: $val = 0;
2269: }
2270: my $checked = '';
2271: if ($val eq $curroption) {
2272: $checked = ' checked="checked"';
2273: }
2274: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2275: '<input type="radio" name="authorreq__LC_adv"'.
2276: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2277: $titles{$option}.'</label></span> ';
2278: }
1.101 raeburn 2279: } else {
2280: my $checked = 'checked="checked" ';
2281: if (ref($settings) eq 'HASH') {
2282: if (ref($settings->{$item}) eq 'HASH') {
2283: if ($settings->{$item}->{'_LC_adv'} == 0) {
2284: $checked = '';
2285: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2286: $checked = 'checked="checked" ';
2287: }
1.79 raeburn 2288: }
1.72 raeburn 2289: }
1.101 raeburn 2290: $datatable .= '<span class="LC_nobreak"><label>'.
2291: '<input type="checkbox" name="'.$context.'_'.$item.
2292: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2293: '</label></span> ';
2294: }
2295: }
2296: if ($context eq 'requestcourses') {
2297: $datatable .= '</tr><tr>';
2298: foreach my $item (@usertools) {
1.106 raeburn 2299: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2300: }
1.101 raeburn 2301: $datatable .= '</tr></table>';
1.72 raeburn 2302: }
1.98 raeburn 2303: $datatable .= '</td></tr>';
1.30 raeburn 2304: $$rowtotal += $typecount;
1.3 raeburn 2305: return $datatable;
2306: }
2307:
1.163 raeburn 2308: sub print_requestmail {
1.305 raeburn 2309: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2310: my ($now,$datatable,%currapp);
1.102 raeburn 2311: $now = time;
2312: if (ref($settings) eq 'HASH') {
2313: if (ref($settings->{'notify'}) eq 'HASH') {
2314: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2315: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2316: }
2317: }
2318: }
1.191 raeburn 2319: my $numinrow = 2;
1.224 raeburn 2320: my $css_class;
1.305 raeburn 2321: if ($$rowtotal%2) {
2322: $css_class = 'LC_odd_row';
2323: }
2324: if ($customcss) {
2325: $css_class .= " $customcss";
2326: }
2327: $css_class =~ s/^\s+//;
2328: if ($css_class) {
2329: $css_class = ' class="'.$css_class.'"';
2330: }
2331: if ($rowstyle) {
2332: $css_class .= ' style="'.$rowstyle.'"';
2333: }
1.163 raeburn 2334: my $text;
2335: if ($action eq 'requestcourses') {
2336: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2337: } elsif ($action eq 'requestauthor') {
2338: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2339: } else {
1.224 raeburn 2340: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2341: }
1.224 raeburn 2342: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2343: ' <td>'.$text.'</td>'.
1.102 raeburn 2344: ' <td class="LC_left_item">';
1.191 raeburn 2345: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2346: $action.'notifyapproval',%currapp);
1.191 raeburn 2347: if ($numdc > 0) {
2348: $datatable .= $table;
1.102 raeburn 2349: } else {
2350: $datatable .= &mt('There are no active Domain Coordinators');
2351: }
2352: $datatable .='</td></tr>';
2353: return $datatable;
2354: }
2355:
1.216 raeburn 2356: sub print_studentcode {
2357: my ($settings,$rowtotal) = @_;
2358: my $rownum = 0;
1.218 raeburn 2359: my ($output,%current);
1.325 raeburn 2360: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2361: if (ref($settings) eq 'HASH') {
2362: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2363: foreach my $type (@crstypes) {
2364: $current{$type} = $settings->{'uniquecode'}{$type};
2365: }
1.218 raeburn 2366: }
2367: }
2368: $output .= '<tr>'.
2369: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2370: '<td class="LC_left_item">';
2371: foreach my $type (@crstypes) {
2372: my $check = ' ';
2373: if ($current{$type}) {
2374: $check = ' checked="checked" ';
2375: }
2376: $output .= '<span class="LC_nobreak"><label>'.
2377: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2378: &mt($type).'</label></span>'.(' 'x2).' ';
2379: }
2380: $output .= '</td></tr>';
2381: $$rowtotal ++;
2382: return $output;
1.216 raeburn 2383: }
2384:
2385: sub print_textbookcourses {
1.242 raeburn 2386: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2387: my $rownum = 0;
2388: my $css_class;
2389: my $itemcount = 1;
2390: my $maxnum = 0;
2391: my $bookshash;
2392: if (ref($settings) eq 'HASH') {
1.242 raeburn 2393: $bookshash = $settings->{$type};
1.216 raeburn 2394: }
2395: my %ordered;
2396: if (ref($bookshash) eq 'HASH') {
2397: foreach my $item (keys(%{$bookshash})) {
2398: if (ref($bookshash->{$item}) eq 'HASH') {
2399: my $num = $bookshash->{$item}{'order'};
2400: $ordered{$num} = $item;
2401: }
2402: }
2403: }
2404: my $confname = $dom.'-domainconfig';
2405: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2406: my $maxnum = scalar(keys(%ordered));
2407: my $datatable;
1.216 raeburn 2408: if (keys(%ordered)) {
2409: my @items = sort { $a <=> $b } keys(%ordered);
2410: for (my $i=0; $i<@items; $i++) {
2411: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2412: my $key = $ordered{$items[$i]};
2413: my %coursehash=&Apache::lonnet::coursedescription($key);
2414: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2415: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2416: if (ref($bookshash->{$key}) eq 'HASH') {
2417: $subject = $bookshash->{$key}->{'subject'};
2418: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2419: if ($type eq 'textbooks') {
1.243 raeburn 2420: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2421: $author = $bookshash->{$key}->{'author'};
2422: $image = $bookshash->{$key}->{'image'};
2423: if ($image ne '') {
2424: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2425: my $imagethumb = "$path/tn-".$imagefile;
2426: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2427: }
1.216 raeburn 2428: }
2429: }
1.242 raeburn 2430: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2431: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2432: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2433: for (my $k=0; $k<=$maxnum; $k++) {
2434: my $vpos = $k+1;
2435: my $selstr;
2436: if ($k == $i) {
2437: $selstr = ' selected="selected" ';
2438: }
2439: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2440: }
2441: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2442: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2443: &mt('Delete?').'</label></span></td>'.
2444: '<td colspan="2">'.
1.242 raeburn 2445: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2446: (' 'x2).
1.242 raeburn 2447: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2448: if ($type eq 'textbooks') {
2449: $datatable .= (' 'x2).
1.243 raeburn 2450: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2451: (' 'x2).
1.242 raeburn 2452: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2453: (' 'x2).
2454: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2455: if ($image) {
1.267 raeburn 2456: $datatable .= $imgsrc.
1.242 raeburn 2457: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2458: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2459: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2460: }
2461: if ($switchserver) {
2462: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2463: } else {
2464: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2465: }
1.216 raeburn 2466: }
1.242 raeburn 2467: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2468: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2469: $coursetitle.'</span></td></tr>'."\n";
2470: $itemcount ++;
2471: }
2472: }
2473: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2474: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2475: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2476: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2477: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2478: for (my $k=0; $k<$maxnum+1; $k++) {
2479: my $vpos = $k+1;
2480: my $selstr;
2481: if ($k == $maxnum) {
2482: $selstr = ' selected="selected" ';
2483: }
2484: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2485: }
2486: $datatable .= '</select> '."\n".
1.242 raeburn 2487: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.216 raeburn 2488: '<td colspan="2">'.
1.242 raeburn 2489: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2490: (' 'x2).
1.242 raeburn 2491: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2492: (' 'x2);
2493: if ($type eq 'textbooks') {
1.243 raeburn 2494: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2495: (' 'x2).
2496: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2497: (' 'x2).
2498: '<span class="LC_nobreak">'.&mt('Image:').' ';
2499: if ($switchserver) {
2500: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2501: } else {
2502: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2503: }
1.216 raeburn 2504: }
2505: $datatable .= '</span>'."\n".
2506: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2507: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2508: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2509: &Apache::loncommon::selectcourse_link
1.242 raeburn 2510: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.216 raeburn 2511: '</span></td>'."\n".
2512: '</tr>'."\n";
2513: $itemcount ++;
2514: return $datatable;
2515: }
2516:
1.217 raeburn 2517: sub textbookcourses_javascript {
1.242 raeburn 2518: my ($settings) = @_;
2519: return unless(ref($settings) eq 'HASH');
2520: my (%ordered,%total,%jstext);
2521: foreach my $type ('textbooks','templates') {
2522: $total{$type} = 0;
2523: if (ref($settings->{$type}) eq 'HASH') {
2524: foreach my $item (keys(%{$settings->{$type}})) {
2525: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2526: my $num = $settings->{$type}->{$item}{'order'};
2527: $ordered{$type}{$num} = $item;
2528: }
2529: }
2530: $total{$type} = scalar(keys(%{$settings->{$type}}));
2531: }
2532: my @jsarray = ();
2533: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2534: push(@jsarray,$ordered{$type}{$item});
2535: }
2536: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2537: }
2538: return <<"ENDSCRIPT";
2539: <script type="text/javascript">
2540: // <![CDATA[
1.242 raeburn 2541: function reorderBooks(form,item,caller) {
1.217 raeburn 2542: var changedVal;
1.242 raeburn 2543: $jstext{'textbooks'};
2544: $jstext{'templates'};
2545: var newpos;
2546: var maxh;
2547: if (caller == 'textbooks') {
2548: newpos = 'textbooks_addbook_pos';
2549: maxh = 1 + $total{'textbooks'};
2550: } else {
2551: newpos = 'templates_addbook_pos';
2552: maxh = 1 + $total{'templates'};
2553: }
1.217 raeburn 2554: var current = new Array;
2555: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2556: if (item == newpos) {
2557: changedVal = newitemVal;
2558: } else {
2559: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2560: current[newitemVal] = newpos;
2561: }
1.242 raeburn 2562: if (caller == 'textbooks') {
2563: for (var i=0; i<textbooks.length; i++) {
2564: var elementName = 'textbooks_'+textbooks[i];
2565: if (elementName != item) {
2566: if (form.elements[elementName]) {
2567: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2568: current[currVal] = elementName;
2569: }
2570: }
2571: }
2572: }
2573: if (caller == 'templates') {
2574: for (var i=0; i<templates.length; i++) {
2575: var elementName = 'templates_'+templates[i];
2576: if (elementName != item) {
2577: if (form.elements[elementName]) {
2578: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2579: current[currVal] = elementName;
2580: }
1.217 raeburn 2581: }
2582: }
2583: }
2584: var oldVal;
2585: for (var j=0; j<maxh; j++) {
2586: if (current[j] == undefined) {
2587: oldVal = j;
2588: }
2589: }
2590: if (oldVal < changedVal) {
2591: for (var k=oldVal+1; k<=changedVal ; k++) {
2592: var elementName = current[k];
2593: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2594: }
2595: } else {
2596: for (var k=changedVal; k<oldVal; k++) {
2597: var elementName = current[k];
2598: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2599: }
2600: }
2601: return;
2602: }
2603:
2604: // ]]>
2605: </script>
2606:
2607: ENDSCRIPT
2608: }
2609:
1.267 raeburn 2610: sub ltitools_javascript {
2611: my ($settings) = @_;
1.319 raeburn 2612: my $togglejs = <itools_toggle_js();
2613: unless (ref($settings) eq 'HASH') {
2614: return $togglejs;
2615: }
1.267 raeburn 2616: my (%ordered,$total,%jstext);
2617: $total = 0;
2618: foreach my $item (keys(%{$settings})) {
2619: if (ref($settings->{$item}) eq 'HASH') {
2620: my $num = $settings->{$item}{'order'};
2621: $ordered{$num} = $item;
2622: }
2623: }
2624: $total = scalar(keys(%{$settings}));
2625: my @jsarray = ();
2626: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2627: push(@jsarray,$ordered{$item});
2628: }
2629: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2630: return <<"ENDSCRIPT";
2631: <script type="text/javascript">
2632: // <![CDATA[
1.319 raeburn 2633: function reorderLTITools(form,item) {
1.267 raeburn 2634: var changedVal;
2635: $jstext
2636: var newpos = 'ltitools_add_pos';
2637: var maxh = 1 + $total;
2638: var current = new Array;
2639: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2640: if (item == newpos) {
2641: changedVal = newitemVal;
2642: } else {
2643: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2644: current[newitemVal] = newpos;
2645: }
2646: for (var i=0; i<ltitools.length; i++) {
2647: var elementName = 'ltitools_'+ltitools[i];
2648: if (elementName != item) {
2649: if (form.elements[elementName]) {
2650: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2651: current[currVal] = elementName;
2652: }
2653: }
2654: }
2655: var oldVal;
2656: for (var j=0; j<maxh; j++) {
2657: if (current[j] == undefined) {
2658: oldVal = j;
2659: }
2660: }
2661: if (oldVal < changedVal) {
2662: for (var k=oldVal+1; k<=changedVal ; k++) {
2663: var elementName = current[k];
2664: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2665: }
2666: } else {
2667: for (var k=changedVal; k<oldVal; k++) {
2668: var elementName = current[k];
2669: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2670: }
2671: }
2672: return;
2673: }
2674:
2675: // ]]>
2676: </script>
2677:
1.319 raeburn 2678: $togglejs
2679:
2680: ENDSCRIPT
2681: }
2682:
2683: sub ltitools_toggle_js {
2684: return <<"ENDSCRIPT";
2685: <script type="text/javascript">
2686: // <![CDATA[
2687:
2688: function toggleLTITools(form,setting,item) {
2689: var radioname = '';
2690: var divid = '';
2691: if ((setting == 'passback') || (setting == 'roster')) {
2692: radioname = 'ltitools_'+setting+'_'+item;
2693: divid = 'ltitools_'+setting+'time_'+item;
2694: var num = form.elements[radioname].length;
2695: if (num) {
2696: var setvis = '';
2697: for (var i=0; i<num; i++) {
2698: if (form.elements[radioname][i].checked) {
2699: if (form.elements[radioname][i].value == '1') {
2700: if (document.getElementById(divid)) {
2701: document.getElementById(divid).style.display = 'inline-block';
2702: }
2703: setvis = 1;
2704: }
2705: break;
2706: }
2707: }
2708: }
2709: if (!setvis) {
2710: if (document.getElementById(divid)) {
2711: document.getElementById(divid).style.display = 'none';
2712: }
2713: }
2714: }
1.324 raeburn 2715: if (setting == 'user') {
2716: divid = 'ltitools_'+setting+'_div_'+item;
2717: var checkid = 'ltitools_'+setting+'_field_'+item;
2718: if (document.getElementById(divid)) {
2719: if (document.getElementById(checkid)) {
2720: if (document.getElementById(checkid).checked) {
2721: document.getElementById(divid).style.display = 'inline-block';
2722: } else {
2723: document.getElementById(divid).style.display = 'none';
2724: }
2725: }
2726: }
2727: }
1.319 raeburn 2728: return;
2729: }
2730: // ]]>
2731: </script>
2732:
1.267 raeburn 2733: ENDSCRIPT
2734: }
2735:
1.320 raeburn 2736: sub lti_javascript {
2737: my ($settings) = @_;
2738: my $togglejs = <i_toggle_js();
2739: unless (ref($settings) eq 'HASH') {
2740: return $togglejs;
2741: }
2742: my (%ordered,$total,%jstext);
2743: $total = 0;
2744: foreach my $item (keys(%{$settings})) {
2745: if (ref($settings->{$item}) eq 'HASH') {
2746: my $num = $settings->{$item}{'order'};
2747: $ordered{$num} = $item;
2748: }
2749: }
2750: $total = scalar(keys(%{$settings}));
2751: my @jsarray = ();
2752: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2753: push(@jsarray,$ordered{$item});
2754: }
2755: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
2756: return <<"ENDSCRIPT";
2757: <script type="text/javascript">
2758: // <![CDATA[
2759: function reorderLTI(form,item) {
2760: var changedVal;
2761: $jstext
2762: var newpos = 'lti_pos_add';
2763: var maxh = 1 + $total;
2764: var current = new Array;
2765: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2766: if (item == newpos) {
2767: changedVal = newitemVal;
2768: } else {
2769: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2770: current[newitemVal] = newpos;
2771: }
2772: for (var i=0; i<lti.length; i++) {
2773: var elementName = 'lti_pos_'+lti[i];
2774: if (elementName != item) {
2775: if (form.elements[elementName]) {
2776: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2777: current[currVal] = elementName;
2778: }
2779: }
2780: }
2781: var oldVal;
2782: for (var j=0; j<maxh; j++) {
2783: if (current[j] == undefined) {
2784: oldVal = j;
2785: }
2786: }
2787: if (oldVal < changedVal) {
2788: for (var k=oldVal+1; k<=changedVal ; k++) {
2789: var elementName = current[k];
2790: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2791: }
2792: } else {
2793: for (var k=changedVal; k<oldVal; k++) {
2794: var elementName = current[k];
2795: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2796: }
2797: }
2798: return;
2799: }
2800: // ]]>
2801: </script>
2802:
2803: $togglejs
2804:
2805: ENDSCRIPT
2806: }
2807:
2808: sub lti_toggle_js {
1.325 raeburn 2809: my %lcauthparmtext = &Apache::lonlocal::texthash (
2810: localauth => 'Local auth argument',
2811: krb => 'Kerberos domain',
2812: );
1.320 raeburn 2813: return <<"ENDSCRIPT";
2814: <script type="text/javascript">
2815: // <![CDATA[
2816:
2817: function toggleLTI(form,setting,item) {
2818: if ((setting == 'user') || (setting == 'crs')) {
2819: var radioname = '';
2820: var divid = '';
2821: if (setting == 'user') {
2822: radioname = 'lti_mapuser_'+item;
2823: divid = 'lti_userfield_'+item;
2824: } else {
2825: radioname = 'lti_mapcrs_'+item;
2826: divid = 'lti_crsfield_'+item;
2827: }
2828: var num = form.elements[radioname].length;
2829: if (num) {
2830: var setvis = '';
2831: for (var i=0; i<num; i++) {
2832: if (form.elements[radioname][i].checked) {
2833: if (form.elements[radioname][i].value == 'other') {
2834: if (document.getElementById(divid)) {
2835: document.getElementById(divid).style.display = 'inline-block';
2836: }
2837: setvis = 1;
2838: break;
2839: }
2840: }
2841: }
2842: if (!setvis) {
2843: if (document.getElementById(divid)) {
2844: document.getElementById(divid).style.display = 'none';
2845: }
2846: }
2847: }
2848: } else if ((setting == 'sec') || (setting == 'secsrc')) {
2849: var numsec = form.elements['lti_crssec_'+item].length;
2850: if (numsec) {
2851: var setvis = '';
2852: for (var i=0; i<numsec; i++) {
2853: if (form.elements['lti_crssec_'+item][i].checked) {
2854: if (form.elements['lti_crssec_'+item][i].value == '1') {
2855: if (document.getElementById('lti_crssecfield_'+item)) {
2856: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
2857: setvis = 1;
2858: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
2859: if (numsrcsec) {
2860: var setsrcvis = '';
2861: for (var j=0; j<numsrcsec; j++) {
2862: if (form.elements['lti_crssecsrc_'+item][j].checked) {
2863: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
2864: if (document.getElementById('lti_secsrcfield_'+item)) {
2865: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
2866: setsrcvis = 1;
2867: }
2868: }
2869: }
2870: }
2871: if (!setsrcvis) {
2872: if (document.getElementById('lti_secsrcfield_'+item)) {
2873: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
2874: }
2875: }
2876: }
2877: }
2878: }
2879: }
2880: }
2881: if (!setvis) {
2882: if (document.getElementById('lti_crssecfield_'+item)) {
2883: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
2884: }
2885: if (document.getElementById('lti_secsrcfield_'+item)) {
2886: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
2887: }
2888: }
2889: }
1.325 raeburn 2890: } else if (setting == 'lcauth') {
2891: var numauth = form.elements['lti_lcauth_'+item].length;
2892: if (numauth) {
2893: for (var i=0; i<numauth; i++) {
2894: if (form.elements['lti_lcauth_'+item][i].checked) {
2895: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
2896: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
2897: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
2898: } else {
2899: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
2900: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
2901: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
2902: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
2903: } else {
2904: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
2905: }
2906: }
2907: }
2908: }
2909: }
2910: }
2911: }
1.326 ! raeburn 2912: } else if (setting == 'lcmenu') {
! 2913: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
! 2914: var divid = 'lti_menufield_'+item;
! 2915: var setvis = '';
! 2916: for (var i=0; i<menus.length; i++) {
! 2917: var radioname = menus[i];
! 2918: var num = form.elements[radioname].length;
! 2919: if (num) {
! 2920: for (var j=0; j<num; j++) {
! 2921: if (form.elements[radioname][j].checked) {
! 2922: if (form.elements[radioname][j].value == '1') {
! 2923: if (document.getElementById(divid)) {
! 2924: document.getElementById(divid).style.display = 'inline-block';
! 2925: }
! 2926: setvis = 1;
! 2927: break;
! 2928: }
! 2929: }
! 2930: }
! 2931: }
! 2932: if (setvis == 1) {
! 2933: break;
! 2934: }
! 2935: }
! 2936: if (!setvis) {
! 2937: if (document.getElementById(divid)) {
! 2938: document.getElementById(divid).style.display = 'none';
! 2939: }
! 2940: }
1.320 raeburn 2941: }
2942: return;
2943: }
2944: // ]]>
2945: </script>
2946:
2947: ENDSCRIPT
2948: }
2949:
1.3 raeburn 2950: sub print_autoenroll {
1.30 raeburn 2951: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2952: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274 raeburn 2953: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2954: if (ref($settings) eq 'HASH') {
2955: if (exists($settings->{'run'})) {
2956: if ($settings->{'run'} eq '0') {
2957: $runoff = ' checked="checked" ';
2958: $runon = ' ';
2959: } else {
2960: $runon = ' checked="checked" ';
2961: $runoff = ' ';
2962: }
2963: } else {
2964: if ($autorun) {
2965: $runon = ' checked="checked" ';
2966: $runoff = ' ';
2967: } else {
2968: $runoff = ' checked="checked" ';
2969: $runon = ' ';
2970: }
2971: }
1.129 raeburn 2972: if (exists($settings->{'co-owners'})) {
2973: if ($settings->{'co-owners'} eq '0') {
2974: $coownersoff = ' checked="checked" ';
2975: $coownerson = ' ';
2976: } else {
2977: $coownerson = ' checked="checked" ';
2978: $coownersoff = ' ';
2979: }
2980: } else {
2981: $coownersoff = ' checked="checked" ';
2982: $coownerson = ' ';
2983: }
1.3 raeburn 2984: if (exists($settings->{'sender_domain'})) {
2985: $defdom = $settings->{'sender_domain'};
2986: }
1.274 raeburn 2987: if (exists($settings->{'autofailsafe'})) {
2988: $failsafe = $settings->{'autofailsafe'};
2989: }
1.14 raeburn 2990: } else {
2991: if ($autorun) {
2992: $runon = ' checked="checked" ';
2993: $runoff = ' ';
2994: } else {
2995: $runoff = ' checked="checked" ';
2996: $runon = ' ';
2997: }
1.3 raeburn 2998: }
2999: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 3000: my $notif_sender;
3001: if (ref($settings) eq 'HASH') {
3002: $notif_sender = $settings->{'sender_uname'};
3003: }
1.3 raeburn 3004: my $datatable='<tr class="LC_odd_row">'.
3005: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 3006: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3007: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 3008: $runon.' value="1" />'.&mt('Yes').'</label> '.
3009: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 3010: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3011: '</tr><tr>'.
3012: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 3013: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 3014: &mt('username').': '.
3015: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 3016: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 3017: ': '.$domform.'</span></td></tr>'.
3018: '<tr class="LC_odd_row">'.
3019: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3020: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3021: '<input type="radio" name="autoassign_coowners"'.
3022: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3023: '<label><input type="radio" name="autoassign_coowners"'.
3024: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 3025: '</tr><tr>'.
3026: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
3027: '<td class="LC_right_item"><span class="LC_nobreak">'.
3028: '<input type="text" name="autoenroll_failsafe"'.
3029: ' value="'.$failsafe.'" size="4" /></td></tr>';
3030: $$rowtotal += 4;
1.3 raeburn 3031: return $datatable;
3032: }
3033:
3034: sub print_autoupdate {
1.30 raeburn 3035: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 3036: my $datatable;
3037: if ($position eq 'top') {
3038: my $updateon = ' ';
3039: my $updateoff = ' checked="checked" ';
3040: my $classlistson = ' ';
3041: my $classlistsoff = ' checked="checked" ';
3042: if (ref($settings) eq 'HASH') {
3043: if ($settings->{'run'} eq '1') {
3044: $updateon = $updateoff;
3045: $updateoff = ' ';
3046: }
3047: if ($settings->{'classlists'} eq '1') {
3048: $classlistson = $classlistsoff;
3049: $classlistsoff = ' ';
3050: }
3051: }
3052: my %title = (
3053: run => 'Auto-update active?',
3054: classlists => 'Update information in classlists?',
3055: );
3056: $datatable = '<tr class="LC_odd_row">'.
3057: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 3058: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3059: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 3060: $updateon.' value="1" />'.&mt('Yes').'</label> '.
3061: '<label><input type="radio" name="autoupdate_run"'.
3062: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3063: '</tr><tr>'.
3064: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 3065: '<td class="LC_right_item"><span class="LC_nobreak">'.
3066: '<label><input type="radio" name="classlists"'.
3067: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
3068: '<label><input type="radio" name="classlists"'.
3069: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3070: '</tr>';
1.30 raeburn 3071: $$rowtotal += 2;
1.131 raeburn 3072: } elsif ($position eq 'middle') {
3073: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3074: my $numinrow = 3;
3075: my $locknamesettings;
3076: $datatable .= &insttypes_row($settings,$types,$usertypes,
3077: $dom,$numinrow,$othertitle,
1.305 raeburn 3078: 'lockablenames',$rowtotal);
1.131 raeburn 3079: $$rowtotal ++;
1.3 raeburn 3080: } else {
1.44 raeburn 3081: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3082: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3083: 'permanentemail','id');
1.33 raeburn 3084: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3085: my $numrows = 0;
1.26 raeburn 3086: if (ref($types) eq 'ARRAY') {
3087: if (@{$types} > 0) {
3088: $datatable =
3089: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3090: \@fields,$types,\$numrows);
1.30 raeburn 3091: $$rowtotal += @{$types};
1.26 raeburn 3092: }
1.3 raeburn 3093: }
3094: $datatable .=
3095: &usertype_update_row($settings,{'default' => $othertitle},
3096: \%fieldtitles,\@fields,['default'],
3097: \$numrows);
1.30 raeburn 3098: $$rowtotal ++;
1.3 raeburn 3099: }
3100: return $datatable;
3101: }
3102:
1.125 raeburn 3103: sub print_autocreate {
3104: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 3105: my (%createon,%createoff,%currhash);
1.125 raeburn 3106: my @types = ('xml','req');
3107: if (ref($settings) eq 'HASH') {
3108: foreach my $item (@types) {
3109: $createoff{$item} = ' checked="checked" ';
3110: $createon{$item} = ' ';
3111: if (exists($settings->{$item})) {
3112: if ($settings->{$item}) {
3113: $createon{$item} = ' checked="checked" ';
3114: $createoff{$item} = ' ';
3115: }
3116: }
3117: }
1.210 raeburn 3118: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 3119: $currhash{$settings->{'xmldc'}} = 1;
3120: }
1.125 raeburn 3121: } else {
3122: foreach my $item (@types) {
3123: $createoff{$item} = ' checked="checked" ';
3124: $createon{$item} = ' ';
3125: }
3126: }
3127: $$rowtotal += 2;
1.191 raeburn 3128: my $numinrow = 2;
1.125 raeburn 3129: my $datatable='<tr class="LC_odd_row">'.
3130: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3131: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3132: '<input type="radio" name="autocreate_xml"'.
3133: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3134: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 3135: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3136: '</td></tr><tr>'.
3137: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3138: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3139: '<input type="radio" name="autocreate_req"'.
3140: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3141: '<label><input type="radio" name="autocreate_req"'.
3142: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 3143: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3144: 'autocreate_xmldc',%currhash);
1.247 raeburn 3145: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 3146: if ($numdc > 1) {
1.247 raeburn 3147: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
3148: '</td><td class="LC_left_item">';
1.125 raeburn 3149: } else {
1.247 raeburn 3150: $datatable .= &mt('Course creation processed as:').
3151: '</td><td class="LC_right_item">';
1.125 raeburn 3152: }
1.247 raeburn 3153: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 3154: $$rowtotal += $rows;
1.125 raeburn 3155: return $datatable;
3156: }
3157:
1.23 raeburn 3158: sub print_directorysrch {
1.277 raeburn 3159: my ($position,$dom,$settings,$rowtotal) = @_;
3160: my $datatable;
3161: if ($position eq 'top') {
3162: my $instsrchon = ' ';
3163: my $instsrchoff = ' checked="checked" ';
3164: my ($exacton,$containson,$beginson);
3165: my $instlocalon = ' ';
3166: my $instlocaloff = ' checked="checked" ';
3167: if (ref($settings) eq 'HASH') {
3168: if ($settings->{'available'} eq '1') {
3169: $instsrchon = $instsrchoff;
3170: $instsrchoff = ' ';
3171: }
3172: if ($settings->{'localonly'} eq '1') {
3173: $instlocalon = $instlocaloff;
3174: $instlocaloff = ' ';
3175: }
3176: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
3177: foreach my $type (@{$settings->{'searchtypes'}}) {
3178: if ($type eq 'exact') {
3179: $exacton = ' checked="checked" ';
3180: } elsif ($type eq 'contains') {
3181: $containson = ' checked="checked" ';
3182: } elsif ($type eq 'begins') {
3183: $beginson = ' checked="checked" ';
3184: }
3185: }
3186: } else {
3187: if ($settings->{'searchtypes'} eq 'exact') {
3188: $exacton = ' checked="checked" ';
3189: } elsif ($settings->{'searchtypes'} eq 'contains') {
3190: $containson = ' checked="checked" ';
3191: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 3192: $exacton = ' checked="checked" ';
3193: $containson = ' checked="checked" ';
3194: }
3195: }
1.277 raeburn 3196: }
3197: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3198: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3199:
3200: my $numinrow = 4;
3201: my $cansrchrow = 0;
3202: $datatable='<tr class="LC_odd_row">'.
3203: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
3204: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3205: '<input type="radio" name="dirsrch_available"'.
3206: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
3207: '<label><input type="radio" name="dirsrch_available"'.
3208: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3209: '</tr><tr>'.
3210: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
3211: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3212: '<input type="radio" name="dirsrch_instlocalonly"'.
3213: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3214: '<label><input type="radio" name="dirsrch_instlocalonly"'.
3215: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3216: '</tr>';
3217: $$rowtotal += 2;
3218: if (ref($usertypes) eq 'HASH') {
3219: if (keys(%{$usertypes}) > 0) {
3220: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 3221: $numinrow,$othertitle,'cansearch',
3222: $rowtotal);
1.277 raeburn 3223: $cansrchrow = 1;
1.25 raeburn 3224: }
1.23 raeburn 3225: }
1.277 raeburn 3226: if ($cansrchrow) {
3227: $$rowtotal ++;
3228: $datatable .= '<tr>';
3229: } else {
3230: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 3231: }
1.277 raeburn 3232: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
3233: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
3234: foreach my $title (@{$titleorder}) {
3235: if (defined($searchtitles->{$title})) {
3236: my $check = ' ';
3237: if (ref($settings) eq 'HASH') {
3238: if (ref($settings->{'searchby'}) eq 'ARRAY') {
3239: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
3240: $check = ' checked="checked" ';
3241: }
1.39 raeburn 3242: }
1.25 raeburn 3243: }
1.277 raeburn 3244: $datatable .= '<td class="LC_left_item">'.
3245: '<span class="LC_nobreak"><label>'.
3246: '<input type="checkbox" name="searchby" '.
3247: 'value="'.$title.'"'.$check.'/>'.
3248: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 3249: }
3250: }
1.277 raeburn 3251: $datatable .= '</tr></table></td></tr>';
3252: $$rowtotal ++;
3253: if ($cansrchrow) {
3254: $datatable .= '<tr class="LC_odd_row">';
3255: } else {
3256: $datatable .= '<tr>';
3257: }
3258: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
3259: '<td class="LC_left_item" colspan="2">'.
3260: '<span class="LC_nobreak"><label>'.
3261: '<input type="checkbox" name="searchtypes" '.
3262: $exacton.' value="exact" />'.&mt('Exact match').
3263: '</label> '.
3264: '<label><input type="checkbox" name="searchtypes" '.
3265: $beginson.' value="begins" />'.&mt('Begins with').
3266: '</label> '.
3267: '<label><input type="checkbox" name="searchtypes" '.
3268: $containson.' value="contains" />'.&mt('Contains').
3269: '</label></span></td></tr>';
3270: $$rowtotal ++;
1.26 raeburn 3271: } else {
1.277 raeburn 3272: my $domsrchon = ' checked="checked" ';
3273: my $domsrchoff = ' ';
3274: my $domlocalon = ' ';
3275: my $domlocaloff = ' checked="checked" ';
3276: if (ref($settings) eq 'HASH') {
3277: if ($settings->{'lclocalonly'} eq '1') {
3278: $domlocalon = $domlocaloff;
3279: $domlocaloff = ' ';
3280: }
3281: if ($settings->{'lcavailable'} eq '0') {
3282: $domsrchoff = $domsrchon;
3283: $domsrchon = ' ';
3284: }
3285: }
3286: $datatable='<tr class="LC_odd_row">'.
3287: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
3288: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3289: '<input type="radio" name="dirsrch_domavailable"'.
3290: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
3291: '<label><input type="radio" name="dirsrch_domavailable"'.
3292: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3293: '</tr><tr>'.
3294: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
3295: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3296: '<input type="radio" name="dirsrch_domlocalonly"'.
3297: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3298: '<label><input type="radio" name="dirsrch_domlocalonly"'.
3299: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3300: '</tr>';
3301: $$rowtotal += 2;
1.26 raeburn 3302: }
1.25 raeburn 3303: return $datatable;
3304: }
3305:
1.28 raeburn 3306: sub print_contacts {
1.286 raeburn 3307: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 3308: my $datatable;
3309: my @contacts = ('adminemail','supportemail');
1.286 raeburn 3310: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
3311: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings);
3312: if ($position eq 'top') {
3313: if (ref($settings) eq 'HASH') {
3314: foreach my $item (@contacts) {
3315: if (exists($settings->{$item})) {
3316: $to{$item} = $settings->{$item};
3317: }
3318: }
3319: }
3320: } elsif ($position eq 'middle') {
3321: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
3322: 'updatesmail','idconflictsmail');
1.288 raeburn 3323: foreach my $type (@mailings) {
3324: $otheremails{$type} = '';
3325: }
1.286 raeburn 3326: } else {
3327: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 3328: foreach my $type (@mailings) {
3329: $otheremails{$type} = '';
3330: }
1.286 raeburn 3331: $bccemails{'helpdeskmail'} = '';
3332: $bccemails{'otherdomsmail'} = '';
3333: $includestr{'helpdeskmail'} = '';
3334: $includestr{'otherdomsmail'} = '';
3335: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3336: }
1.28 raeburn 3337: if (ref($settings) eq 'HASH') {
1.286 raeburn 3338: unless ($position eq 'top') {
3339: foreach my $type (@mailings) {
3340: if (exists($settings->{$type})) {
3341: if (ref($settings->{$type}) eq 'HASH') {
3342: foreach my $item (@contacts) {
3343: if ($settings->{$type}{$item}) {
3344: $checked{$type}{$item} = ' checked="checked" ';
3345: }
3346: }
3347: $otheremails{$type} = $settings->{$type}{'others'};
3348: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3349: $bccemails{$type} = $settings->{$type}{'bcc'};
3350: if ($settings->{$type}{'include'} ne '') {
3351: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3352: $includestr{$type} = &unescape($includestr{$type});
3353: }
3354: }
3355: }
3356: } elsif ($type eq 'lonstatusmail') {
3357: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3358: }
1.28 raeburn 3359: }
3360: }
1.286 raeburn 3361: if ($position eq 'bottom') {
3362: foreach my $type (@mailings) {
3363: $bccemails{$type} = $settings->{$type}{'bcc'};
3364: if ($settings->{$type}{'include'} ne '') {
3365: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3366: $includestr{$type} = &unescape($includestr{$type});
3367: }
3368: }
3369: if (ref($settings->{'helpform'}) eq 'HASH') {
3370: if (ref($fields) eq 'ARRAY') {
3371: foreach my $field (@{$fields}) {
3372: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3373: }
1.286 raeburn 3374: }
3375: if (exists($settings->{'helpform'}{'maxsize'})) {
3376: $maxsize = $settings->{'helpform'}{'maxsize'};
3377: } else {
1.289 raeburn 3378: $maxsize = '1.0';
1.286 raeburn 3379: }
3380: } else {
3381: if (ref($fields) eq 'ARRAY') {
3382: foreach my $field (@{$fields}) {
3383: $currfield{$field} = 'yes';
1.134 raeburn 3384: }
1.28 raeburn 3385: }
1.286 raeburn 3386: $maxsize = '1.0';
1.28 raeburn 3387: }
3388: }
3389: } else {
1.286 raeburn 3390: if ($position eq 'top') {
3391: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3392: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3393: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3394: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 3395: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 3396: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3397: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3398: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
3399: } elsif ($position eq 'bottom') {
3400: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3401: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3402: if (ref($fields) eq 'ARRAY') {
3403: foreach my $field (@{$fields}) {
3404: $currfield{$field} = 'yes';
3405: }
3406: }
3407: $maxsize = '1.0';
3408: }
1.28 raeburn 3409: }
3410: my ($titles,$short_titles) = &contact_titles();
3411: my $rownum = 0;
3412: my $css_class;
1.286 raeburn 3413: if ($position eq 'top') {
3414: foreach my $item (@contacts) {
3415: $css_class = $rownum%2?' class="LC_odd_row"':'';
3416: $datatable .= '<tr'.$css_class.'>'.
3417: '<td><span class="LC_nobreak">'.$titles->{$item}.
3418: '</span></td><td class="LC_right_item">'.
3419: '<input type="text" name="'.$item.'" value="'.
3420: $to{$item}.'" /></td></tr>';
3421: $rownum ++;
3422: }
1.315 raeburn 3423: } elsif ($position eq 'bottom') {
3424: $css_class = $rownum%2?' class="LC_odd_row"':'';
3425: $datatable .= '<tr'.$css_class.'>'.
3426: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3427: &mt('(e-mail, subject, and description always shown)').
3428: '</td><td class="LC_left_item">';
3429: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3430: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3431: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3432: foreach my $field (@{$fields}) {
3433: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3434: if (($field eq 'screenshot') || ($field eq 'cc')) {
3435: $datatable .= ' '.&mt('(logged-in users)');
3436: }
3437: $datatable .='</td><td>';
3438: my $clickaction;
3439: if ($field eq 'screenshot') {
3440: $clickaction = ' onclick="screenshotSize(this);"';
3441: }
3442: if (ref($possoptions->{$field}) eq 'ARRAY') {
3443: foreach my $option (@{$possoptions->{$field}}) {
3444: my $checked;
3445: if ($currfield{$field} eq $option) {
3446: $checked = ' checked="checked"';
3447: }
3448: $datatable .= '<span class="LC_nobreak"><label>'.
3449: '<input type="radio" name="helpform_'.$field.'" '.
3450: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3451: '</label></span>'.(' 'x2);
3452: }
3453: }
3454: if ($field eq 'screenshot') {
3455: my $display;
3456: if ($currfield{$field} eq 'no') {
3457: $display = ' style="display:none"';
3458: }
3459: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.' />'.
3460: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3461: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3462: }
3463: $datatable .= '</td></tr>';
3464: }
3465: $datatable .= '</table>';
3466: }
3467: $datatable .= '</td></tr>'."\n";
3468: $rownum ++;
3469: }
3470: unless ($position eq 'top') {
1.286 raeburn 3471: foreach my $type (@mailings) {
3472: $css_class = $rownum%2?' class="LC_odd_row"':'';
3473: $datatable .= '<tr'.$css_class.'>'.
3474: '<td><span class="LC_nobreak">'.
3475: $titles->{$type}.': </span></td>'.
3476: '<td class="LC_left_item">';
3477: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3478: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3479: }
3480: $datatable .= '<span class="LC_nobreak">';
3481: foreach my $item (@contacts) {
3482: $datatable .= '<label>'.
3483: '<input type="checkbox" name="'.$type.'"'.
3484: $checked{$type}{$item}.
3485: ' value="'.$item.'" />'.$short_titles->{$item}.
3486: '</label> ';
3487: }
3488: $datatable .= '</span><br />'.&mt('Others').': '.
3489: '<input type="text" name="'.$type.'_others" '.
3490: 'value="'.$otheremails{$type}.'" />';
3491: my %locchecked;
3492: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3493: foreach my $loc ('s','b') {
3494: if ($includeloc{$type} eq $loc) {
3495: $locchecked{$loc} = ' checked="checked"';
3496: last;
3497: }
3498: }
3499: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3500: '<input type="text" name="'.$type.'_bcc" '.
3501: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3502: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3503: &mt('Text automatically added to e-mail:').' '.
3504: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br >'.
3505: '<span class="LC_nobreak">'.&mt('Location:').' '.
3506: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3507: (' 'x2).
3508: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3509: '</span></fieldset>';
3510: }
3511: $datatable .= '</td></tr>'."\n";
3512: $rownum ++;
3513: }
1.28 raeburn 3514: }
1.286 raeburn 3515: if ($position eq 'middle') {
3516: my %choices;
3517: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
1.289 raeburn 3518: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3519: &mt('LON-CAPA core group - MSU'),600,500));
1.286 raeburn 3520: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
3521: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3522: &mt('LON-CAPA core group - MSU'),600,500));
3523: my @toggles = ('reporterrors','reportupdates');
3524: my %defaultchecked = ('reporterrors' => 'on',
3525: 'reportupdates' => 'on');
3526: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3527: \%choices,$rownum);
3528: $datatable .= $reports;
3529: } elsif ($position eq 'bottom') {
1.315 raeburn 3530: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3531: my (@posstypes,%usertypeshash);
3532: if (ref($types) eq 'ARRAY') {
3533: @posstypes = @{$types};
3534: }
3535: if (@posstypes) {
3536: if (ref($usertypes) eq 'HASH') {
3537: %usertypeshash = %{$usertypes};
3538: }
3539: my @overridden;
3540: my $numinrow = 4;
3541: if (ref($settings) eq 'HASH') {
3542: if (ref($settings->{'overrides'}) eq 'HASH') {
3543: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
3544: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
3545: push(@overridden,$key);
3546: foreach my $item (@contacts) {
3547: if ($settings->{'overrides'}{$key}{$item}) {
3548: $checked{'override_'.$key}{$item} = ' checked="checked" ';
3549: }
3550: }
3551: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
3552: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
3553: $includeloc{'override_'.$key} = '';
3554: $includestr{'override_'.$key} = '';
3555: if ($settings->{'overrides'}{$key}{'include'} ne '') {
3556: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
3557: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
3558: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
3559: }
1.286 raeburn 3560: }
3561: }
3562: }
1.315 raeburn 3563: }
3564: my $customclass = 'LC_helpdesk_override';
3565: my $optionsprefix = 'LC_options_helpdesk_';
3566:
3567: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
3568:
3569: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
3570: $numinrow,$othertitle,'overrides',
3571: \$rownum,$onclicktypes,$customclass);
3572: $rownum ++;
3573: $usertypeshash{'default'} = $othertitle;
3574: foreach my $status (@posstypes) {
3575: my $css_class;
3576: if ($rownum%2) {
3577: $css_class = 'LC_odd_row ';
3578: }
3579: $css_class .= $customclass;
3580: my $rowid = $optionsprefix.$status;
3581: my $hidden = 1;
3582: my $currstyle = 'display:none';
3583: if (grep(/^\Q$status\E$/,@overridden)) {
3584: $currstyle = 'display:table-row';
3585: $hidden = 0;
3586: }
3587: my $key = 'override_'.$status;
3588: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
3589: $includeloc{$key},$includestr{$key},$status,$rowid,
3590: $usertypeshash{$status},$css_class,$currstyle,
3591: \@contacts,$short_titles);
3592: unless ($hidden) {
3593: $rownum ++;
1.286 raeburn 3594: }
3595: }
1.134 raeburn 3596: }
1.28 raeburn 3597: }
1.30 raeburn 3598: $$rowtotal += $rownum;
1.28 raeburn 3599: return $datatable;
3600: }
3601:
1.315 raeburn 3602: sub overridden_helpdesk {
3603: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
3604: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
3605: my $class = 'LC_left_item';
3606: if ($css_class) {
3607: $css_class = ' class="'.$css_class.'"';
3608: }
3609: if ($rowid) {
3610: $rowid = ' id="'.$rowid.'"';
3611: }
3612: if ($rowstyle) {
3613: $rowstyle = ' style="'.$rowstyle.'"';
3614: }
3615: my ($output,$description);
3616: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
3617: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
3618: "<td>$description</td>\n".
3619: '<td class="'.$class.'" colspan="2">'.
3620: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
3621: '<span class="LC_nobreak">';
3622: if (ref($contacts) eq 'ARRAY') {
3623: foreach my $item (@{$contacts}) {
3624: my $check;
3625: if (ref($checked) eq 'HASH') {
3626: $check = $checked->{$item};
3627: }
3628: my $title;
3629: if (ref($short_titles) eq 'HASH') {
3630: $title = $short_titles->{$item};
3631: }
3632: $output .= '<label>'.
3633: '<input type="checkbox" name="override_'.$type.'"'.$check.
3634: ' value="'.$item.'" />'.$title.'</label> ';
3635: }
3636: }
3637: $output .= '</span><br />'.&mt('Others').': '.
3638: '<input type="text" name="override_'.$type.'_others" '.
3639: 'value="'.$otheremails.'" />';
3640: my %locchecked;
3641: foreach my $loc ('s','b') {
3642: if ($includeloc eq $loc) {
3643: $locchecked{$loc} = ' checked="checked"';
3644: last;
3645: }
3646: }
3647: $output .= '<br />'.&mt('Bcc:').(' 'x6).
3648: '<input type="text" name="override_'.$type.'_bcc" '.
3649: 'value="'.$bccemails.'" /></fieldset>'.
3650: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3651: &mt('Text automatically added to e-mail:').' '.
3652: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br >'.
3653: '<span class="LC_nobreak">'.&mt('Location:').' '.
3654: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3655: (' 'x2).
3656: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3657: '</span></fieldset>'.
3658: '</td></tr>'."\n";
3659: return $output;
3660: }
3661:
1.286 raeburn 3662: sub contacts_javascript {
3663: return <<"ENDSCRIPT";
3664:
3665: <script type="text/javascript">
3666: // <![CDATA[
3667:
3668: function screenshotSize(field) {
3669: if (document.getElementById('help_screenshotsize')) {
3670: if (field.value == 'no') {
1.289 raeburn 3671: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 3672: } else {
3673: document.getElementById('help_screenshotsize').style.display="";
3674: }
3675: }
3676: return;
3677: }
3678:
1.315 raeburn 3679: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
3680: if (form.elements[checkbox].length != undefined) {
3681: var count = 0;
3682: if (docount) {
3683: for (var i=0; i<form.elements[checkbox].length; i++) {
3684: if (form.elements[checkbox][i].checked) {
3685: count ++;
3686: }
3687: }
3688: }
3689: for (var i=0; i<form.elements[checkbox].length; i++) {
3690: var type = form.elements[checkbox][i].value;
3691: if (document.getElementById(prefix+type)) {
3692: if (form.elements[checkbox][i].checked) {
3693: document.getElementById(prefix+type).style.display = 'table-row';
3694: if (count % 2 == 1) {
3695: document.getElementById(prefix+type).className = target+' LC_odd_row';
3696: } else {
3697: document.getElementById(prefix+type).className = target;
3698: }
3699: count ++;
3700: } else {
3701: document.getElementById(prefix+type).style.display = 'none';
3702: }
3703: }
3704: }
3705: }
3706: return;
3707: }
3708:
3709:
1.286 raeburn 3710: // ]]>
3711: </script>
3712:
3713: ENDSCRIPT
3714: }
3715:
1.118 jms 3716: sub print_helpsettings {
1.282 raeburn 3717: my ($position,$dom,$settings,$rowtotal) = @_;
3718: my $confname = $dom.'-domainconfig';
1.285 raeburn 3719: my $formname = 'display';
1.168 raeburn 3720: my ($datatable,$itemcount);
1.282 raeburn 3721: if ($position eq 'top') {
3722: $itemcount = 1;
3723: my (%choices,%defaultchecked,@toggles);
3724: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3725: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3726: &mt('LON-CAPA bug tracker'),600,500));
3727: %defaultchecked = ('submitbugs' => 'on');
3728: @toggles = ('submitbugs');
3729: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3730: \%choices,$itemcount);
3731: $$rowtotal ++;
3732: } else {
3733: my $css_class;
3734: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 3735: my (%customroles,%ordered,%current);
1.301 raeburn 3736: if (ref($settings) eq 'HASH') {
3737: if (ref($settings->{'adhoc'}) eq 'HASH') {
3738: %current = %{$settings->{'adhoc'}};
3739: }
1.285 raeburn 3740: }
3741: my $count = 0;
3742: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 3743: if ($key=~/^rolesdef\_(\w+)$/) {
3744: my $rolename = $1;
1.285 raeburn 3745: my (%privs,$order);
1.282 raeburn 3746: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3747: $customroles{$rolename} = \%privs;
1.285 raeburn 3748: if (ref($current{$rolename}) eq 'HASH') {
3749: $order = $current{$rolename}{'order'};
3750: }
3751: if ($order eq '') {
3752: $order = $count;
3753: }
3754: $ordered{$order} = $rolename;
3755: $count++;
3756: }
3757: }
3758: my $maxnum = scalar(keys(%ordered));
3759: my @roles_by_num = ();
3760: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3761: push(@roles_by_num,$item);
3762: }
3763: my $context = 'domprefs';
3764: my $crstype = 'Course';
3765: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 3766: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 3767: my ($numstatustypes,@jsarray);
3768: if (ref($types) eq 'ARRAY') {
3769: if (@{$types} > 0) {
3770: $numstatustypes = scalar(@{$types});
3771: push(@accesstypes,'status');
3772: @jsarray = ('bystatus');
1.282 raeburn 3773: }
3774: }
1.290 raeburn 3775: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 3776: if (keys(%domhelpdesk)) {
3777: push(@accesstypes,('inc','exc'));
3778: push(@jsarray,('notinc','notexc'));
3779: }
3780: my $hiddenstr = join("','",@jsarray);
3781: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.282 raeburn 3782: my $context = 'domprefs';
3783: my $crstype = 'Course';
1.285 raeburn 3784: my $prefix = 'helproles_';
3785: my $add_class = 'LC_hidden';
3786: foreach my $num (@roles_by_num) {
3787: my $role = $ordered{$num};
3788: my ($desc,$access,@statuses);
3789: if (ref($current{$role}) eq 'HASH') {
3790: $desc = $current{$role}{'desc'};
3791: $access = $current{$role}{'access'};
3792: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3793: @statuses = @{$current{$role}{'insttypes'}};
3794: }
3795: }
3796: if ($desc eq '') {
3797: $desc = $role;
3798: }
3799: my $identifier = 'custhelp'.$num;
1.282 raeburn 3800: my %full=();
3801: my %levels= (
3802: course => {},
3803: domain => {},
3804: system => {},
3805: );
3806: my %levelscurrent=(
3807: course => {},
3808: domain => {},
3809: system => {},
3810: );
3811: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3812: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3813: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 3814: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 3815: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 3816: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3817: for (my $k=0; $k<=$maxnum; $k++) {
3818: my $vpos = $k+1;
3819: my $selstr;
3820: if ($k == $num) {
3821: $selstr = ' selected="selected" ';
3822: }
3823: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3824: }
3825: $datatable .= '</select>'.(' 'x2).
3826: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3827: '</td>'.
3828: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3829: &mt('Name shown to users:').
3830: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3831: '</fieldset>'.
3832: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3833: $othertitle,$usertypes,$types,\%domhelpdesk).
3834: '<fieldset>'.
3835: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 3836: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 3837: \%levelscurrent,$identifier,
3838: 'LC_hidden',$prefix.$num.'_privs').
3839: '</fieldset></td>';
1.282 raeburn 3840: $itemcount ++;
3841: }
3842: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3843: my $newcust = 'custhelp'.$count;
3844: my (%privs,%levelscurrent);
3845: my %full=();
3846: my %levels= (
3847: course => {},
3848: domain => {},
3849: system => {},
3850: );
3851: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3852: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 3853: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 3854: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 3855: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3856: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3857: for (my $k=0; $k<$maxnum+1; $k++) {
3858: my $vpos = $k+1;
3859: my $selstr;
3860: if ($k == $maxnum) {
3861: $selstr = ' selected="selected" ';
3862: }
3863: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3864: }
3865: $datatable .= '</select> '."\n".
1.282 raeburn 3866: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3867: '</label></span></td>'.
1.285 raeburn 3868: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3869: '<span class="LC_nobreak">'.
3870: &mt('Internal name:').
3871: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3872: '</span>'.(' 'x4).
3873: '<span class="LC_nobreak">'.
3874: &mt('Name shown to users:').
3875: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3876: '</span></fieldset>'.
3877: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3878: $usertypes,$types,\%domhelpdesk).
3879: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 3880: &Apache::lonuserutils::custom_role_header($context,$crstype,
3881: \@templateroles,$newcust).
3882: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3883: \%levelscurrent,$newcust).
1.285 raeburn 3884: '</fieldset></td></tr>';
1.282 raeburn 3885: $count ++;
3886: $$rowtotal += $count;
3887: }
1.166 raeburn 3888: return $datatable;
1.121 raeburn 3889: }
3890:
1.285 raeburn 3891: sub adhocbutton {
3892: my ($prefix,$num,$field,$visibility) = @_;
3893: my %lt = &Apache::lonlocal::texthash(
3894: show => 'Show details',
3895: hide => 'Hide details',
3896: );
3897: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3898: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3899: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3900: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3901: }
3902:
3903: sub helpsettings_javascript {
3904: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3905: return unless(ref($roles_by_num) eq 'ARRAY');
3906: my %html_js_lt = &Apache::lonlocal::texthash(
3907: show => 'Show details',
3908: hide => 'Hide details',
3909: );
3910: &html_escape(\%html_js_lt);
3911: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3912: return <<"ENDSCRIPT";
3913: <script type="text/javascript">
3914: // <![CDATA[
3915:
3916: function reorderHelpRoles(form,item) {
3917: var changedVal;
3918: $jstext
3919: var newpos = 'helproles_${total}_pos';
3920: var maxh = 1 + $total;
3921: var current = new Array();
3922: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3923: if (item == newpos) {
3924: changedVal = newitemVal;
3925: } else {
3926: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3927: current[newitemVal] = newpos;
3928: }
3929: for (var i=0; i<helproles.length; i++) {
3930: var elementName = 'helproles_'+helproles[i]+'_pos';
3931: if (elementName != item) {
3932: if (form.elements[elementName]) {
3933: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3934: current[currVal] = elementName;
3935: }
3936: }
3937: }
3938: var oldVal;
3939: for (var j=0; j<maxh; j++) {
3940: if (current[j] == undefined) {
3941: oldVal = j;
3942: }
3943: }
3944: if (oldVal < changedVal) {
3945: for (var k=oldVal+1; k<=changedVal ; k++) {
3946: var elementName = current[k];
3947: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3948: }
3949: } else {
3950: for (var k=changedVal; k<oldVal; k++) {
3951: var elementName = current[k];
3952: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3953: }
3954: }
3955: return;
3956: }
3957:
3958: function helpdeskAccess(num) {
3959: var curraccess = null;
3960: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3961: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3962: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3963: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3964: }
3965: }
3966: }
3967: var shown = Array();
3968: var hidden = Array();
3969: if (curraccess == 'none') {
3970: hidden = Array('$hiddenstr');
3971: } else {
3972: if (curraccess == 'status') {
3973: shown = Array('bystatus');
3974: hidden = Array('notinc','notexc');
3975: } else {
3976: if (curraccess == 'exc') {
3977: shown = Array('notexc');
3978: hidden = Array('notinc','bystatus');
3979: }
3980: if (curraccess == 'inc') {
3981: shown = Array('notinc');
3982: hidden = Array('notexc','bystatus');
3983: }
1.293 raeburn 3984: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 3985: hidden = Array('notinc','notexc','bystatus');
3986: }
3987: }
3988: }
3989: if (hidden.length > 0) {
3990: for (var i=0; i<hidden.length; i++) {
3991: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3992: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3993: }
3994: }
3995: }
3996: if (shown.length > 0) {
3997: for (var i=0; i<shown.length; i++) {
3998: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
3999: if (shown[i] == 'privs') {
4000: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4001: } else {
4002: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4003: }
4004: }
4005: }
4006: }
4007: return;
4008: }
4009:
4010: function toggleHelpdeskItem(num,field) {
4011: if (document.getElementById('helproles_'+num+'_'+field)) {
4012: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 4013: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 4014: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4015: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4016: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4017: }
4018: } else {
4019: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4020: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4021: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4022: }
4023: }
4024: }
4025: return;
4026: }
4027:
4028: // ]]>
4029: </script>
4030:
4031: ENDSCRIPT
4032: }
4033:
4034: sub helpdeskroles_access {
4035: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4036: $usertypes,$types,$domhelpdesk) = @_;
4037: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
4038: my %lt = &Apache::lonlocal::texthash(
4039: 'rou' => 'Role usage',
4040: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 4041: 'all' => 'All with domain helpdesk or helpdesk assistant role',
4042: 'dh' => 'All with domain helpdesk role',
4043: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 4044: 'none' => 'None',
4045: 'status' => 'Determined based on institutional status',
4046: 'inc' => 'Include all, but exclude specific personnel',
4047: 'exc' => 'Exclude all, but include specific personnel',
4048: );
4049: my %usecheck = (
4050: all => ' checked="checked"',
4051: );
4052: my %displaydiv = (
4053: status => 'none',
4054: inc => 'none',
4055: exc => 'none',
4056: priv => 'block',
4057: );
4058: my $output;
4059: if (ref($current) eq 'HASH') {
4060: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
4061: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
4062: $usecheck{$current->{access}} = $usecheck{'all'};
4063: delete($usecheck{'all'});
4064: if ($current->{access} =~ /^(status|inc|exc)$/) {
4065: my $access = $1;
4066: $displaydiv{$access} = 'inline';
4067: } elsif ($current->{access} eq 'none') {
4068: $displaydiv{'priv'} = 'none';
4069: }
4070: }
4071: }
4072: }
4073: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
4074: '<p>'.$lt{'whi'}.'</p>';
4075: foreach my $access (@{$accesstypes}) {
4076: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
4077: ' onclick="helpdeskAccess('."'$num'".');" />'.
4078: $lt{$access}.'</label>';
4079: if ($access eq 'status') {
4080: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
4081: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
4082: $othertitle,$usertypes,$types).
4083: '</div>';
4084: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
4085: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
4086: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4087: '</div>';
4088: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
4089: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
4090: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4091: '</div>';
4092: }
4093: $output .= '</p>';
4094: }
4095: $output .= '</fieldset>';
4096: return $output;
4097: }
4098:
1.121 raeburn 4099: sub radiobutton_prefs {
1.192 raeburn 4100: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 4101: $additional,$align) = @_;
1.121 raeburn 4102: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
4103: (ref($choices) eq 'HASH'));
4104:
1.170 raeburn 4105: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 4106:
4107: foreach my $item (@{$toggles}) {
4108: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 4109: $checkedon{$item} = ' checked="checked" ';
4110: $checkedoff{$item} = ' ';
1.121 raeburn 4111: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 4112: $checkedoff{$item} = ' checked="checked" ';
4113: $checkedon{$item} = ' ';
4114: }
4115: }
4116: if (ref($settings) eq 'HASH') {
1.121 raeburn 4117: foreach my $item (@{$toggles}) {
1.118 jms 4118: if ($settings->{$item} eq '1') {
4119: $checkedon{$item} = ' checked="checked" ';
4120: $checkedoff{$item} = ' ';
4121: } elsif ($settings->{$item} eq '0') {
4122: $checkedoff{$item} = ' checked="checked" ';
4123: $checkedon{$item} = ' ';
4124: }
4125: }
1.121 raeburn 4126: }
1.192 raeburn 4127: if ($onclick) {
4128: $onclick = ' onclick="'.$onclick.'"';
4129: }
1.121 raeburn 4130: foreach my $item (@{$toggles}) {
1.118 jms 4131: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 4132: $datatable .=
1.306 raeburn 4133: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 4134: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 4135: '</span></td>';
4136: if ($align eq 'left') {
4137: $datatable .= '<td class="LC_left_item">';
4138: } else {
4139: $datatable .= '<td class="LC_right_item">';
4140: }
1.289 raeburn 4141: $datatable .=
1.257 raeburn 4142: '<span class="LC_nobreak">'.
1.118 jms 4143: '<label><input type="radio" name="'.
1.192 raeburn 4144: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 4145: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 4146: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
4147: '</span>'.$additional.
4148: '</td>'.
1.118 jms 4149: '</tr>';
4150: $itemcount ++;
1.121 raeburn 4151: }
4152: return ($datatable,$itemcount);
4153: }
4154:
1.267 raeburn 4155: sub print_ltitools {
4156: my ($dom,$settings,$rowtotal) = @_;
4157: my $rownum = 0;
4158: my $css_class;
4159: my $itemcount = 1;
4160: my $maxnum = 0;
4161: my %ordered;
4162: if (ref($settings) eq 'HASH') {
4163: foreach my $item (keys(%{$settings})) {
4164: if (ref($settings->{$item}) eq 'HASH') {
4165: my $num = $settings->{$item}{'order'};
4166: $ordered{$num} = $item;
4167: }
4168: }
4169: }
4170: my $confname = $dom.'-domainconfig';
4171: my $switchserver = &check_switchserver($dom,$confname);
4172: my $maxnum = scalar(keys(%ordered));
4173: my $datatable = <itools_javascript($settings);
4174: my %lt = <itools_names();
4175: my @courseroles = ('cc','in','ta','ep','st');
4176: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1.324 raeburn 4177: my @fields = ('fullname','firstname','lastname','email','roles','user');
1.267 raeburn 4178: if (keys(%ordered)) {
4179: my @items = sort { $a <=> $b } keys(%ordered);
4180: for (my $i=0; $i<@items; $i++) {
4181: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4182: my $item = $ordered{$items[$i]};
1.323 raeburn 4183: my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
1.267 raeburn 4184: if (ref($settings->{$item}) eq 'HASH') {
4185: $title = $settings->{$item}->{'title'};
4186: $url = $settings->{$item}->{'url'};
4187: $key = $settings->{$item}->{'key'};
4188: $secret = $settings->{$item}->{'secret'};
1.322 raeburn 4189: $lifetime = $settings->{$item}->{'lifetime'};
1.267 raeburn 4190: my $image = $settings->{$item}->{'image'};
4191: if ($image ne '') {
4192: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
4193: }
1.323 raeburn 4194: if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
4195: $sigsel{'HMAC-256'} = ' selected="selected"';
4196: } else {
4197: $sigsel{'HMAC-SHA1'} = ' selected="selected"';
4198: }
1.267 raeburn 4199: }
1.319 raeburn 4200: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1.267 raeburn 4201: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4202: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
4203: for (my $k=0; $k<=$maxnum; $k++) {
4204: my $vpos = $k+1;
4205: my $selstr;
4206: if ($k == $i) {
4207: $selstr = ' selected="selected" ';
4208: }
4209: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4210: }
4211: $datatable .= '</select>'.(' 'x2).
4212: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
4213: &mt('Delete?').'</label></span></td>'.
4214: '<td colspan="2">'.
4215: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4216: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
1.267 raeburn 4217: (' 'x2).
4218: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
4219: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4220: (' 'x2).
4221: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
4222: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4223: (' 'x2).
4224: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
4225: '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
4226: '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
1.267 raeburn 4227: '<br /><br />'.
1.323 raeburn 4228: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
1.267 raeburn 4229: ' value="'.$url.'" /></span>'.
4230: (' 'x2).
1.319 raeburn 4231: '<span class="LC_nobreak">'.$lt{'key'}.':'.
1.267 raeburn 4232: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
4233: (' 'x2).
1.322 raeburn 4234: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
4235: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
4236: (' 'x2).
1.267 raeburn 4237: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4238: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
4239: '<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>'.
4240: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
4241: '</fieldset>'.
4242: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4243: '<span class="LC_nobreak">'.&mt('Display target:');
4244: my %currdisp;
4245: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
4246: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
4247: $currdisp{'window'} = ' checked="checked"';
1.298 raeburn 4248: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
4249: $currdisp{'tab'} = ' checked="checked"';
1.267 raeburn 4250: } else {
4251: $currdisp{'iframe'} = ' checked="checked"';
4252: }
4253: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
4254: $currdisp{'width'} = $1;
4255: }
4256: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
4257: $currdisp{'height'} = $1;
4258: }
1.296 raeburn 4259: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
4260: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267 raeburn 4261: } else {
4262: $currdisp{'iframe'} = ' checked="checked"';
4263: }
1.298 raeburn 4264: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4265: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
4266: $lt{$disp}.'</label>'.(' 'x2);
4267: }
4268: $datatable .= (' 'x4);
4269: foreach my $dimen ('width','height') {
4270: $datatable .= '<label>'.$lt{$dimen}.' '.
4271: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
4272: (' 'x2);
4273: }
1.296 raeburn 4274: $datatable .= '<br />'.
4275: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
4276: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></label></div>'.
4277: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4278: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
4279: '</textarea></div><div style=""></div><br />';
1.319 raeburn 4280: my %units = (
4281: 'passback' => 'days',
4282: 'roster' => 'seconds',
4283: );
1.267 raeburn 4284: foreach my $extra ('passback','roster') {
1.319 raeburn 4285: my $validsty = 'none';
4286: my $currvalid;
1.267 raeburn 4287: my $checkedon = '';
4288: my $checkedoff = ' checked="checked"';
4289: if ($settings->{$item}->{$extra}) {
4290: $checkedon = $checkedoff;
4291: $checkedoff = '';
1.319 raeburn 4292: $validsty = 'inline-block';
4293: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
4294: $currvalid = $settings->{$item}->{$extra.'valid'};
4295: }
4296: }
4297: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
4298: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4299: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
4300: &mt('No').'</label>'.(' 'x2).
4301: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
4302: &mt('Yes').'</label></span></div>'.
4303: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
4304: '<span class="LC_nobreak">'.
4305: &mt("at least [_1] $units{$extra} after launch",
4306: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
4307: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4308: }
1.319 raeburn 4309: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
1.267 raeburn 4310: if ($imgsrc) {
4311: $datatable .= $imgsrc.
4312: '<label><input type="checkbox" name="ltitools_image_del"'.
4313: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
4314: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
4315: } else {
4316: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4317: }
4318: if ($switchserver) {
4319: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4320: } else {
4321: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
4322: }
4323: $datatable .= '</span></fieldset>';
1.324 raeburn 4324: my (%checkedfields,%rolemaps,$userincdom);
1.267 raeburn 4325: if (ref($settings->{$item}) eq 'HASH') {
4326: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
4327: %checkedfields = %{$settings->{$item}->{'fields'}};
4328: }
1.324 raeburn 4329: $userincdom = $settings->{$item}->{'incdom'};
1.267 raeburn 4330: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
4331: %rolemaps = %{$settings->{$item}->{'roles'}};
4332: $checkedfields{'roles'} = 1;
4333: }
4334: }
4335: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4336: '<span class="LC_nobreak">';
1.324 raeburn 4337: my $userfieldstyle = 'display:none;';
4338: my $seluserdom = '';
4339: my $unseluserdom = ' selected="selected"';
1.267 raeburn 4340: foreach my $field (@fields) {
1.324 raeburn 4341: my ($checked,$onclick,$id,$spacer);
1.267 raeburn 4342: if ($checkedfields{$field}) {
4343: $checked = ' checked="checked"';
4344: }
1.324 raeburn 4345: if ($field eq 'user') {
4346: $id = ' id="ltitools_user_field_'.$i.'"';
4347: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
4348: if ($checked) {
4349: $userfieldstyle = 'display:inline-block';
4350: if ($userincdom) {
4351: $seluserdom = $unseluserdom;
4352: $unseluserdom = '';
4353: }
4354: }
4355: } else {
4356: $spacer = (' ' x2);
4357: }
1.267 raeburn 4358: $datatable .= '<label>'.
1.324 raeburn 4359: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
4360: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 4361: }
1.324 raeburn 4362: $datatable .= '</span>';
4363: $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
4364: '<span class="LC_nobreak"> : '.
4365: '<select name="ltitools_userincdom_'.$i.'">'.
4366: '<option value="">'.&mt('Select').'</option>'.
4367: '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
4368: '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
4369: '</select></span></div>';
4370: $datatable .= '</fieldset>'.
1.267 raeburn 4371: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4372: foreach my $role (@courseroles) {
4373: my ($selected,$selectnone);
4374: if (!$rolemaps{$role}) {
4375: $selectnone = ' selected="selected"';
4376: }
1.306 raeburn 4377: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4378: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4379: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
4380: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
4381: foreach my $ltirole (@ltiroles) {
4382: unless ($selectnone) {
4383: if ($rolemaps{$role} eq $ltirole) {
4384: $selected = ' selected="selected"';
4385: } else {
4386: $selected = '';
4387: }
4388: }
4389: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
4390: }
4391: $datatable .= '</select></td>';
4392: }
1.273 raeburn 4393: $datatable .= '</tr></table></fieldset>';
4394: my %courseconfig;
4395: if (ref($settings->{$item}) eq 'HASH') {
4396: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
4397: %courseconfig = %{$settings->{$item}->{'crsconf'}};
4398: }
4399: }
4400: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4401: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 4402: my $checked;
4403: if ($courseconfig{$item}) {
4404: $checked = ' checked="checked"';
4405: }
4406: $datatable .= '<label>'.
4407: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
4408: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
4409: }
4410: $datatable .= '</span></fieldset>'.
1.267 raeburn 4411: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4412: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
4413: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
4414: my %custom = %{$settings->{$item}->{'custom'}};
4415: if (keys(%custom) > 0) {
4416: foreach my $key (sort(keys(%custom))) {
4417: $datatable .= '<tr><td><span class="LC_nobreak">'.
4418: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
4419: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
4420: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
4421: ' value="'.$custom{$key}.'" /></td></tr>';
4422: }
4423: }
4424: }
4425: $datatable .= '<tr><td><span class="LC_nobreak">'.
4426: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
4427: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
4428: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
4429: $datatable .= '</table></fieldset></td></tr>'."\n";
4430: $itemcount ++;
4431: }
4432: }
4433: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.319 raeburn 4434: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1.267 raeburn 4435: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4436: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
4437: '<select name="ltitools_add_pos"'.$chgstr.'>';
4438: for (my $k=0; $k<$maxnum+1; $k++) {
4439: my $vpos = $k+1;
4440: my $selstr;
4441: if ($k == $maxnum) {
4442: $selstr = ' selected="selected" ';
4443: }
4444: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4445: }
4446: $datatable .= '</select> '."\n".
4447: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".
4448: '<td colspan="2">'.
4449: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4450: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
1.267 raeburn 4451: (' 'x2).
4452: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
4453: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4454: (' 'x2).
4455: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
4456: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4457: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
4458: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
4459: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
1.267 raeburn 4460: '<br />'.
1.323 raeburn 4461: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
1.267 raeburn 4462: (' 'x2).
4463: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
4464: (' 'x2).
1.322 raeburn 4465: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
4466: (' 'x2).
1.267 raeburn 4467: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
4468: '<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".
4469: '</fieldset>'.
4470: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4471: '<span class="LC_nobreak">'.&mt('Display target:');
4472: my %defaultdisp;
4473: $defaultdisp{'iframe'} = ' checked="checked"';
1.298 raeburn 4474: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4475: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
4476: $lt{$disp}.'</label>'.(' 'x2);
4477: }
4478: $datatable .= (' 'x4);
4479: foreach my $dimen ('width','height') {
4480: $datatable .= '<label>'.$lt{$dimen}.' '.
4481: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
4482: (' 'x2);
4483: }
1.296 raeburn 4484: $datatable .= '<br />'.
4485: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
4486: '<input type="text" name="ltitools_add_linktext" size="5" /></label></div>'.
4487: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4488: '<textarea name=ltitools_add_explanation" rows="5" cols="40"></textarea>'.
4489: '</div><div style=""></div><br />';
1.319 raeburn 4490: my %units = (
4491: 'passback' => 'days',
4492: 'roster' => 'seconds',
4493: );
4494: my %defaulttimes = (
4495: 'passback' => '7',
1.322 raeburn 4496: 'roster' => '300',
1.319 raeburn 4497: );
1.267 raeburn 4498: foreach my $extra ('passback','roster') {
1.319 raeburn 4499: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
4500: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4501: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
4502: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
4503: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
4504: &mt('Yes').'</label></span></div>'.
4505: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
4506: '<span class="LC_nobreak">'.
4507: &mt("at least [_1] $units{$extra} after launch",
4508: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
4509: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4510: }
1.319 raeburn 4511: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
1.267 raeburn 4512: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4513: if ($switchserver) {
4514: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4515: } else {
4516: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
4517: }
4518: $datatable .= '</span></fieldset>'.
4519: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4520: '<span class="LC_nobreak">';
4521: foreach my $field (@fields) {
1.324 raeburn 4522: my ($id,$onclick,$spacer);
4523: if ($field eq 'user') {
4524: $id = ' id="ltitools_user_field_add"';
4525: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
4526: } else {
4527: $spacer = (' ' x2);
4528: }
1.267 raeburn 4529: $datatable .= '<label>'.
1.324 raeburn 4530: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
4531: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 4532: }
1.324 raeburn 4533: $datatable .= '</span>'.
4534: '<div style="display:none;" id="ltitools_user_div_add">'.
4535: '<span class="LC_nobreak"> : '.
4536: '<select name="ltitools_userincdom_add">'.
4537: '<option value="" selected="selected">'.&mt('Select').'</option>'.
4538: '<option value="0">'.&mt('username').'</option>'.
4539: '<option value="1">'.&mt('username:domain').'</option>'.
4540: '</select></span></div></fieldset>';
4541: $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
1.267 raeburn 4542: foreach my $role (@courseroles) {
4543: my ($checked,$checkednone);
1.306 raeburn 4544: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4545: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4546: '<select name="ltitools_add_roles_'.$role.'">'.
4547: '<option value="" selected="selected">'.&mt('Select').'</option>';
4548: foreach my $ltirole (@ltiroles) {
4549: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
4550: }
4551: $datatable .= '</select></td>';
4552: }
4553: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 4554: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4555: foreach my $item ('label','title','target','linktext','explanation','append') {
1.296 raeburn 4556: $datatable .= '<label>'.
4557: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
4558: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
1.273 raeburn 4559: }
4560: $datatable .= '</span></fieldset>'.
1.267 raeburn 4561: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4562: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
4563: '<tr><td><span class="LC_nobreak">'.
4564: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
4565: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
4566: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
4567: '</table></fieldset></td></tr>'."\n".
4568: '</td>'."\n".
4569: '</tr>'."\n";
4570: $itemcount ++;
4571: return $datatable;
4572: }
4573:
4574: sub ltitools_names {
4575: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 4576: 'title' => 'Title',
4577: 'version' => 'Version',
4578: 'msgtype' => 'Message Type',
1.323 raeburn 4579: 'sigmethod' => 'Signature Method',
1.296 raeburn 4580: 'url' => 'URL',
4581: 'key' => 'Key',
1.322 raeburn 4582: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 4583: 'secret' => 'Secret',
4584: 'icon' => 'Icon',
1.324 raeburn 4585: 'user' => 'User',
1.296 raeburn 4586: 'fullname' => 'Full Name',
4587: 'firstname' => 'First Name',
4588: 'lastname' => 'Last Name',
4589: 'email' => 'E-mail',
4590: 'roles' => 'Role',
1.298 raeburn 4591: 'window' => 'Window',
4592: 'tab' => 'Tab',
1.296 raeburn 4593: 'iframe' => 'iFrame',
4594: 'height' => 'Height',
4595: 'width' => 'Width',
4596: 'linktext' => 'Default Link Text',
4597: 'explanation' => 'Default Explanation',
4598: 'passback' => 'Tool can return grades:',
4599: 'roster' => 'Tool can retrieve roster:',
4600: 'crstarget' => 'Display target',
4601: 'crslabel' => 'Course label',
4602: 'crstitle' => 'Course title',
4603: 'crslinktext' => 'Link Text',
4604: 'crsexplanation' => 'Explanation',
1.318 raeburn 4605: 'crsappend' => 'Provider URL',
1.267 raeburn 4606: );
4607: return %lt;
4608: }
4609:
1.320 raeburn 4610: sub print_lti {
4611: my ($dom,$settings,$rowtotal) = @_;
4612: my $itemcount = 1;
4613: my $maxnum = 0;
4614: my $css_class;
4615: my %ordered;
4616: if (ref($settings) eq 'HASH') {
4617: foreach my $item (keys(%{$settings})) {
4618: if (ref($settings->{$item}) eq 'HASH') {
4619: my $num = $settings->{$item}{'order'};
4620: $ordered{$num} = $item;
4621: }
4622: }
4623: }
4624: my $maxnum = scalar(keys(%ordered));
4625: my $datatable = <i_javascript($settings);
4626: my %lt = <i_names();
4627: if (keys(%ordered)) {
4628: my @items = sort { $a <=> $b } keys(%ordered);
4629: for (my $i=0; $i<@items; $i++) {
4630: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4631: my $item = $ordered{$items[$i]};
4632: my ($key,$secret,$lifetime,$consumer,$current);
4633: if (ref($settings->{$item}) eq 'HASH') {
4634: $key = $settings->{$item}->{'key'};
4635: $secret = $settings->{$item}->{'secret'};
4636: $lifetime = $settings->{$item}->{'lifetime'};
4637: $consumer = $settings->{$item}->{'consumer'};
4638: $current = $settings->{$item};
4639: }
4640: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
4641: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4642: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
4643: for (my $k=0; $k<=$maxnum; $k++) {
4644: my $vpos = $k+1;
4645: my $selstr;
4646: if ($k == $i) {
4647: $selstr = ' selected="selected" ';
4648: }
4649: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4650: }
4651: $datatable .= '</select>'.(' 'x2).
4652: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
4653: &mt('Delete?').'</label></span></td>'.
4654: '<td colspan="2">'.
4655: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4656: '<span class="LC_nobreak">'.$lt{'consumer'}.
4657: ':<input type="text" size="20" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
4658: (' 'x2).
4659: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
4660: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4661: (' 'x2).
4662: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
4663: 'value="'.$lifetime.'" size="5" /></span>'.
4664: '<br /><br />'.
4665: '<span class="LC_nobreak">'.$lt{'key'}.
4666: ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
4667: (' 'x2).
4668: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4669: '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
4670: '<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>'.
4671: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
1.325 raeburn 4672: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
1.320 raeburn 4673: $itemcount ++;
4674: }
4675: }
4676: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4677: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
4678: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4679: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
4680: '<select name="lti_pos_add"'.$chgstr.'>';
4681: for (my $k=0; $k<$maxnum+1; $k++) {
4682: my $vpos = $k+1;
4683: my $selstr;
4684: if ($k == $maxnum) {
4685: $selstr = ' selected="selected" ';
4686: }
4687: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4688: }
4689: $datatable .= '</select> '."\n".
4690: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</td>'."\n".
4691: '<td colspan="2">'.
4692: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4693: '<span class="LC_nobreak">'.$lt{'consumer'}.
4694: ':<input type="text" size="20" name="lti_consumer_add" value="" /></span> '."\n".
4695: (' 'x2).
4696: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
4697: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4698: (' 'x2).
1.322 raeburn 4699: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="lti_lifetime_add" value="300" /></span> '."\n".
1.320 raeburn 4700: '<br /><br />'.
4701: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
4702: (' 'x2).
4703: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
4704: '<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 4705: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
1.320 raeburn 4706: '</td>'."\n".
4707: '</tr>'."\n";
4708: $$rowtotal ++;
4709: return $datatable;;
4710: }
4711:
4712: sub lti_names {
4713: my %lt = &Apache::lonlocal::texthash(
4714: 'version' => 'LTI Version',
4715: 'url' => 'URL',
4716: 'key' => 'Key',
1.322 raeburn 4717: 'lifetime' => 'Nonce lifetime (s)',
1.320 raeburn 4718: 'consumer' => 'LTI Consumer',
4719: 'secret' => 'Secret',
4720: 'email' => 'Email address',
4721: 'sourcedid' => 'User ID',
4722: 'other' => 'Other',
4723: 'passback' => 'Can return grades to Consumer:',
4724: 'roster' => 'Can retrieve roster from Consumer:',
1.326 ! raeburn 4725: 'topmenu' => 'Display LON-CAPA page header',
! 4726: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 4727: );
4728: return %lt;
4729: }
4730:
4731: sub lti_options {
1.325 raeburn 4732: my ($num,$current,$itemcount,%lt) = @_;
1.320 raeburn 4733: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield);
4734: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
4735: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
4736: $checked{'makecrs'}{'N'} = ' checked="checked"';
4737: $checked{'mapcrstype'} = {};
4738: $checked{'makeuser'} = {};
4739: $checked{'selfenroll'} = {};
4740: $checked{'crssec'} = {};
4741: $checked{'crssecsrc'} = {};
1.325 raeburn 4742: $checked{'lcauth'} = {};
1.326 ! raeburn 4743: $checked{'menuitem'} = {};
1.325 raeburn 4744: if ($num eq 'add') {
4745: $checked{'lcauth'}{'lti'} = ' checked="checked"';
4746: }
1.320 raeburn 4747: my $userfieldsty = 'none';
4748: my $crsfieldsty = 'none';
4749: my $crssecfieldsty = 'none';
4750: my $secsrcfieldsty = 'none';
1.325 raeburn 4751: my $lcauthparm;
4752: my $lcauthparmstyle = 'display:none';
4753: my $lcauthparmtext;
1.326 ! raeburn 4754: my $menusty;
1.325 raeburn 4755: my $numinrow = 4;
1.326 ! raeburn 4756: my %menutitles = <imenu_titles();
1.320 raeburn 4757:
4758: if (ref($current) eq 'HASH') {
4759: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
4760: $checked{'mapuser'}{'sourcedid'} = '';
4761: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
4762: $checked{'mapuser'}{'email'} = ' checked="checked"';
4763: } else {
4764: $checked{'mapuser'}{'other'} = ' checked="checked"';
4765: $userfield = $current->{'mapuser'};
4766: $userfieldsty = 'inline-block';
4767: }
4768: }
4769: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
4770: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
4771: if ($current->{'mapcrs'} eq 'context_id') {
4772: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
4773: } else {
4774: $checked{'mapcrs'}{'other'} = ' checked="checked"';
4775: $cidfield = $current->{'mapcrs'};
4776: $crsfieldsty = 'inline-block';
4777: }
4778: }
4779: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
4780: foreach my $type (@{$current->{'mapcrstype'}}) {
4781: $checked{'mapcrstype'}{$type} = ' checked="checked"';
4782: }
4783: }
4784: if ($current->{'makecrs'}) {
4785: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 ! raeburn 4786: }
1.320 raeburn 4787: if (ref($current->{'makeuser'}) eq 'ARRAY') {
4788: foreach my $role (@{$current->{'makeuser'}}) {
4789: $checked{'makeuser'}{$role} = ' checked="checked"';
4790: }
4791: }
1.325 raeburn 4792: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
4793: $checked{'lcauth'}{$1} = ' checked="checked"';
4794: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
4795: $lcauthparm = $current->{'lcauthparm'};
4796: $lcauthparmstyle = 'display:table-row';
4797: if ($current->{'lcauth'} eq 'localauth') {
4798: $lcauthparmtext = &mt('Local auth argument');
4799: } else {
4800: $lcauthparmtext = &mt('Kerberos domain');
4801: }
4802: }
4803: }
1.320 raeburn 4804: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
4805: foreach my $role (@{$current->{'selfenroll'}}) {
4806: $checked{'selfenroll'}{$role} = ' checked="checked"';
4807: }
4808: }
4809: if (ref($current->{'maproles'}) eq 'HASH') {
4810: %rolemaps = %{$current->{'maproles'}};
4811: }
4812: if ($current->{'section'} ne '') {
4813: $checked{'crssec'}{'Y'} = ' checked="checked"';
4814: $crssecfieldsty = 'inline-block';
4815: if ($current->{'section'} eq 'course_section_sourcedid') {
4816: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
4817: } else {
4818: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
4819: $crssecsrc = $current->{'section'};
4820: $secsrcfieldsty = 'inline-block';
4821: }
4822: } else {
4823: $checked{'crssec'}{'N'} = ' checked="checked"';
4824: }
1.326 ! raeburn 4825: if ($current->{'topmenu'}) {
! 4826: $checked{'topmenu'}{'Y'} = ' checked="checked"';
! 4827: } else {
! 4828: $checked{'topmenu'}{'N'} = ' checked="checked"';
! 4829: }
! 4830: if ($current->{'inlinemenu'}) {
! 4831: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
! 4832: } else {
! 4833: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
! 4834: }
! 4835: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
! 4836: $menusty = 'inline-block';
! 4837: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
! 4838: foreach my $item (@{$current->{'lcmenu'}}) {
! 4839: if (exists($menutitles{$item})) {
! 4840: $checked{'menuitem'}{$item} = ' checked="checked"';
! 4841: }
! 4842: }
! 4843: }
! 4844: } else {
! 4845: $menusty = 'none';
! 4846: }
1.320 raeburn 4847: } else {
4848: $checked{'makecrs'}{'N'} = ' checked="checked"';
4849: $checked{'crssec'}{'N'} = ' checked="checked"';
1.326 ! raeburn 4850: $checked{'topmenu'}{'N'} = ' checked="checked"';
! 4851: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
! 4852: $checked{'menuitem'}{'grades'} = ' checked="checked"';
! 4853: $menusty = 'inline-block';
1.320 raeburn 4854: }
1.325 raeburn 4855: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 4856: my %coursetypetitles = &Apache::lonlocal::texthash (
4857: official => 'Official',
4858: unofficial => 'Unofficial',
4859: community => 'Community',
4860: textbook => 'Textbook',
4861: placement => 'Placement Test',
1.325 raeburn 4862: lti => 'LTI Provider',
1.320 raeburn 4863: );
1.325 raeburn 4864: my @authtypes = ('internal','krb4','krb5','localauth');
4865: my %shortauth = (
4866: internal => 'int',
4867: krb4 => 'krb4',
4868: krb5 => 'krb5',
4869: localauth => 'loc'
4870: );
4871: my %authnames = &authtype_names();
1.320 raeburn 4872: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
4873: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
4874: my @courseroles = ('cc','in','ta','ep','st');
4875: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
4876: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
4877: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
4878: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 4879: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 ! raeburn 4880: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.320 raeburn 4881: my $output = '<fieldset><legend>'.&mt('Mapping users').'</legend>'.
4882: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
4883: foreach my $option ('sourcedid','email','other') {
4884: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
4885: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
4886: ($option eq 'other' ? '' : (' 'x2) );
4887: }
4888: $output .= '</span></div>'.
4889: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
4890: '<input type="text" name="lti_customuser_'.$num.'" '.
4891: 'value="'.$userfield.'" /></div></fieldset>'.
4892: '<fieldset><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
4893: foreach my $ltirole (@lticourseroles) {
4894: my ($selected,$selectnone);
4895: if ($rolemaps{$ltirole} eq '') {
4896: $selectnone = ' selected="selected"';
4897: }
4898: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
4899: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
4900: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
4901: foreach my $role (@courseroles) {
4902: unless ($selectnone) {
4903: if ($rolemaps{$ltirole} eq $role) {
4904: $selected = ' selected="selected"';
4905: } else {
4906: $selected = '';
4907: }
4908: }
4909: $output .= '<option value="'.$role.'"'.$selected.'>'.
4910: &Apache::lonnet::plaintext($role,'Course').
4911: '</option>';
4912: }
4913: $output .= '</select></td>';
4914: }
4915: $output .= '</tr></table></fieldset>'.
4916: '<fieldset><legend>'.&mt('Roles which may create user accounts').'</legend>';
4917: foreach my $ltirole (@ltiroles) {
4918: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
4919: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
4920: }
4921: $output .= '</fieldset>'.
1.325 raeburn 4922: '<fieldset><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
4923: '<table>'.
4924: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
4925: '</table>'.
4926: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
4927: '<td class="LC_left_item">';
4928: foreach my $auth ('lti',@authtypes) {
4929: my $authtext;
4930: if ($auth eq 'lti') {
4931: $authtext = &mt('None');
4932: } else {
4933: $authtext = $authnames{$shortauth{$auth}};
4934: }
4935: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
4936: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
4937: $authtext.'</label></span> ';
4938: }
4939: $output .= '</td></tr>'.
4940: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
4941: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
4942: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
4943: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
4944: '</table></fieldset>'.
1.320 raeburn 4945: '<fieldset><legend>'.&mt('Mapping courses').'</legend>'.
4946: '<div class="LC_floatleft"><span class="LC_nobreak">'.
4947: &mt('Unique course identifier').': ';
4948: foreach my $option ('course_offering_sourcedid','context_id','other') {
4949: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
4950: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
4951: ($option eq 'other' ? '' : (' 'x2) );
4952: }
4953: $output .= '</div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'".>'.
4954: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
4955: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
4956: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
4957: foreach my $type (@coursetypes) {
4958: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
4959: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
4960: (' 'x2);
4961: }
4962: $output .= '</span></fieldset>'.
4963: '<fieldset><legend>'.&mt('Creating courses').'</legend>'.
4964: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
4965: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
4966: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
4967: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
4968: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
4969: '</fieldset>'.
4970: '<fieldset><legend>'.&mt('Roles which may self-enroll').'</legend>';
4971: foreach my $lticrsrole (@lticourseroles) {
4972: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
4973: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
4974: }
4975: $output .= '</fieldset>'.
4976: '<fieldset><legend>'.&mt('Course options').'</legend>'.
4977: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
4978: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
4979: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
4980: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
4981: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label><span></div>'.
4982: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
4983: '<span class="LC_nobreak">'.&mt('From').':<label>'.
4984: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
4985: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
4986: &mt('Standard field').'</label>'.(' 'x2).
4987: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
4988: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
4989: '</label></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
4990: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
4991: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
4992: foreach my $extra ('passback','roster') {
4993: my $checkedon = '';
4994: my $checkedoff = ' checked="checked"';
4995: if (ref($current) eq 'HASH') {
4996: if (($current->{$extra})) {
4997: $checkedon = $checkedoff;
4998: $checkedoff = '';
4999: }
5000: }
5001: $output .= $lt{$extra}.' '.
5002: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.' />'.
5003: &mt('No').'</label>'.(' 'x2).
5004: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.' />'.
5005: &mt('Yes').'</label><br />';
5006: }
1.326 ! raeburn 5007: $output .= '</span></fieldset>'.
! 5008: '<fieldset><legend>'.&mt('Course defaults (Course Coordinator can override)').'</legend>'.
! 5009: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
! 5010: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
! 5011: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
! 5012: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
! 5013: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label><span></div>'.
! 5014: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
! 5015: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
! 5016: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
! 5017: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
! 5018: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
! 5019: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label><span></div>';
! 5020: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
! 5021: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
! 5022: '<span class="LC_nobreak">'.&mt('Menu items').': ';
! 5023: foreach my $type ('fullname','coursetitle','role','logout','grades') {
! 5024: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
! 5025: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
! 5026: (' 'x2);
! 5027: }
1.320 raeburn 5028: $output .= '</span></fieldset>';
5029: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
5030: #
5031: # $output .= '</fieldset>'.
5032: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
5033: return $output;
5034: }
5035:
1.326 ! raeburn 5036: sub ltimenu_titles {
! 5037: return &Apache::lonlocal::texthash(
! 5038: fullname => 'Full name',
! 5039: coursetitle => 'Course title',
! 5040: role => 'Role',
! 5041: logout => 'Logout',
! 5042: grades => 'Grades',
! 5043: );
! 5044: }
! 5045:
1.121 raeburn 5046: sub print_coursedefaults {
1.139 raeburn 5047: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 5048: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 5049: my $itemcount = 1;
1.192 raeburn 5050: my %choices = &Apache::lonlocal::texthash (
5051: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 5052: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 5053: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
5054: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 5055: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
5056: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.314 raeburn 5057: texengine => 'Default method to display mathematics',
1.257 raeburn 5058: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 5059: canclone => "People who may clone a course (besides course's owner and coordinators)",
5060: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 5061: );
1.198 raeburn 5062: my %staticdefaults = (
1.314 raeburn 5063: texengine => 'MathJax',
1.198 raeburn 5064: anonsurvey_threshold => 10,
5065: uploadquota => 500,
1.257 raeburn 5066: postsubmit => 60,
1.276 raeburn 5067: mysqltables => 172800,
1.198 raeburn 5068: );
1.139 raeburn 5069: if ($position eq 'top') {
1.257 raeburn 5070: %defaultchecked = (
5071: 'canuse_pdfforms' => 'off',
5072: 'uselcmath' => 'on',
5073: 'usejsme' => 'on',
1.289 raeburn 5074: 'canclone' => 'none',
1.257 raeburn 5075: );
5076: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.314 raeburn 5077: my $deftex = $staticdefaults{'texengine'};
5078: if (ref($settings) eq 'HASH') {
5079: if ($settings->{'texengine'}) {
5080: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
5081: $deftex = $settings->{'texengine'};
5082: }
5083: }
5084: }
5085: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5086: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
5087: '<span class="LC_nobreak">'.$choices{'texengine'}.
5088: '</span></td><td class="LC_right_item">'.
5089: '<select name="texengine">'."\n";
5090: my %texoptions = (
5091: MathJax => 'MathJax',
5092: mimetex => &mt('Convert to Images'),
5093: tth => &mt('TeX to HTML'),
5094: );
5095: foreach my $renderer ('MathJax','mimetex','tth') {
5096: my $selected = '';
5097: if ($renderer eq $deftex) {
5098: $selected = ' selected="selected"';
5099: }
5100: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
5101: }
5102: $mathdisp .= '</select></td></tr>'."\n";
5103: $itemcount ++;
1.139 raeburn 5104: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 5105: \%choices,$itemcount);
1.314 raeburn 5106: $datatable = $mathdisp.$datatable;
1.264 raeburn 5107: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5108: $datatable .=
1.306 raeburn 5109: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 5110: '<span class="LC_nobreak">'.$choices{'canclone'}.
5111: '</span></td><td class="LC_left_item">';
5112: my $currcanclone = 'none';
5113: my $onclick;
5114: my @cloneoptions = ('none','domain');
5115: my %clonetitles = (
5116: none => 'No additional course requesters',
5117: domain => "Any course requester in course's domain",
5118: instcode => 'Course requests for official courses ...',
5119: );
5120: my (%codedefaults,@code_order,@posscodes);
5121: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
5122: \@code_order) eq 'ok') {
5123: if (@code_order > 0) {
5124: push(@cloneoptions,'instcode');
5125: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
5126: }
5127: }
5128: if (ref($settings) eq 'HASH') {
5129: if ($settings->{'canclone'}) {
5130: if (ref($settings->{'canclone'}) eq 'HASH') {
5131: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
5132: if (@code_order > 0) {
5133: $currcanclone = 'instcode';
5134: @posscodes = @{$settings->{'canclone'}{'instcode'}};
5135: }
5136: }
5137: } elsif ($settings->{'canclone'} eq 'domain') {
5138: $currcanclone = $settings->{'canclone'};
5139: }
5140: }
1.289 raeburn 5141: }
1.264 raeburn 5142: foreach my $option (@cloneoptions) {
5143: my ($checked,$additional);
5144: if ($currcanclone eq $option) {
5145: $checked = ' checked="checked"';
5146: }
5147: if ($option eq 'instcode') {
5148: if (@code_order) {
5149: my $show = 'none';
5150: if ($checked) {
5151: $show = 'block';
5152: }
1.317 raeburn 5153: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 5154: &mt('Institutional codes for new and cloned course have identical:').
5155: '<br />';
5156: foreach my $item (@code_order) {
5157: my $codechk;
5158: if ($checked) {
5159: if (grep(/^\Q$item\E$/,@posscodes)) {
5160: $codechk = ' checked="checked"';
5161: }
5162: }
5163: $additional .= '<label>'.
5164: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
5165: $item.'</label>';
5166: }
5167: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
5168: }
5169: }
5170: $datatable .=
5171: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
5172: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
5173: '</label> '.$additional.'</span><br />';
5174: }
5175: $datatable .= '</td>'.
5176: '</tr>';
5177: $itemcount ++;
1.139 raeburn 5178: } else {
5179: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 5180: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 5181: my $currusecredits = 0;
1.257 raeburn 5182: my $postsubmitclient = 1;
1.271 raeburn 5183: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 5184: if (ref($settings) eq 'HASH') {
5185: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 5186: if (ref($settings->{'uploadquota'}) eq 'HASH') {
5187: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
5188: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
5189: }
5190: }
1.192 raeburn 5191: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 5192: foreach my $type (@types) {
5193: next if ($type eq 'community');
5194: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
5195: if ($defcredits{$type} ne '') {
5196: $currusecredits = 1;
5197: }
5198: }
5199: }
5200: if (ref($settings->{'postsubmit'}) eq 'HASH') {
5201: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
5202: $postsubmitclient = 0;
5203: foreach my $type (@types) {
5204: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5205: }
5206: } else {
5207: foreach my $type (@types) {
5208: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
5209: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 5210: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 5211: } else {
5212: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5213: }
5214: } else {
5215: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5216: }
5217: }
5218: }
5219: } else {
5220: foreach my $type (@types) {
5221: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 5222: }
5223: }
1.276 raeburn 5224: if (ref($settings->{'mysqltables'}) eq 'HASH') {
5225: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
5226: $currmysql{$type} = $settings->{'mysqltables'}{$type};
5227: }
5228: } else {
5229: foreach my $type (@types) {
5230: $currmysql{$type} = $staticdefaults{'mysqltables'};
5231: }
5232: }
1.258 raeburn 5233: } else {
5234: foreach my $type (@types) {
5235: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5236: }
1.139 raeburn 5237: }
5238: if (!$currdefresponder) {
1.198 raeburn 5239: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 5240: } elsif ($currdefresponder < 1) {
5241: $currdefresponder = 1;
5242: }
1.198 raeburn 5243: foreach my $type (@types) {
5244: if ($curruploadquota{$type} eq '') {
5245: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
5246: }
5247: }
1.139 raeburn 5248: $datatable .=
1.192 raeburn 5249: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5250: $choices{'anonsurvey_threshold'}.
1.139 raeburn 5251: '</span></td>'.
5252: '<td class="LC_right_item"><span class="LC_nobreak">'.
5253: '<input type="text" name="anonsurvey_threshold"'.
5254: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 5255: '</td></tr>'."\n";
5256: $itemcount ++;
5257: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5258: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5259: $choices{'uploadquota'}.
5260: '</span></td>'.
1.306 raeburn 5261: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 5262: '<table><tr>';
1.198 raeburn 5263: foreach my $type (@types) {
1.306 raeburn 5264: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 5265: '<input type="text" name="uploadquota_'.$type.'"'.
5266: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
5267: }
5268: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 5269: $itemcount ++;
1.236 raeburn 5270: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 5271: my $display = 'none';
1.192 raeburn 5272: if ($currusecredits) {
5273: $display = 'block';
5274: }
5275: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 5276: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
5277: foreach my $type (@types) {
5278: next if ($type eq 'community');
1.306 raeburn 5279: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 5280: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 5281: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 5282: }
5283: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 5284: %defaultchecked = ('coursecredits' => 'off');
5285: @toggles = ('coursecredits');
5286: my $current = {
5287: 'coursecredits' => $currusecredits,
5288: };
5289: (my $table,$itemcount) =
5290: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 5291: \%choices,$itemcount,$onclick,$additional,'left');
5292: $datatable .= $table;
5293: $onclick = "toggleDisplay(this.form,'studentsubmission');";
5294: my $display = 'none';
5295: if ($postsubmitclient) {
5296: $display = 'block';
5297: }
5298: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 5299: &mt('Number of seconds submit is disabled').'<br />'.
5300: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
5301: '<table><tr>';
1.257 raeburn 5302: foreach my $type (@types) {
1.306 raeburn 5303: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 5304: '<input type="text" name="'.$type.'_timeout" value="'.
5305: $deftimeout{$type}.'" size="5" /></td>';
5306: }
5307: $additional .= '</tr></table></div>'."\n";
5308: %defaultchecked = ('postsubmit' => 'on');
5309: @toggles = ('postsubmit');
1.280 raeburn 5310: $current = {
5311: 'postsubmit' => $postsubmitclient,
5312: };
1.257 raeburn 5313: ($table,$itemcount) =
5314: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
5315: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 5316: $datatable .= $table;
1.276 raeburn 5317: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5318: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5319: $choices{'mysqltables'}.
5320: '</span></td>'.
1.306 raeburn 5321: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 5322: '<table><tr>';
5323: foreach my $type (@types) {
1.306 raeburn 5324: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 5325: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 5326: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 5327: }
5328: $datatable .= '</tr></table></td></tr>'."\n";
5329: $itemcount ++;
5330:
1.139 raeburn 5331: }
1.192 raeburn 5332: $$rowtotal += $itemcount;
1.121 raeburn 5333: return $datatable;
1.118 jms 5334: }
5335:
1.231 raeburn 5336: sub print_selfenrollment {
5337: my ($position,$dom,$settings,$rowtotal) = @_;
5338: my ($css_class,$datatable);
5339: my $itemcount = 1;
1.271 raeburn 5340: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 5341: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 5342: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
5343: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 5344: my @rows;
5345: my $key;
5346: if ($position eq 'top') {
5347: $key = 'admin';
5348: if (ref($rowsref) eq 'ARRAY') {
5349: @rows = @{$rowsref};
5350: }
5351: } elsif ($position eq 'middle') {
5352: $key = 'default';
5353: @rows = ('types','registered','approval','limit');
5354: }
5355: foreach my $row (@rows) {
5356: if (defined($titlesref->{$row})) {
5357: $itemcount ++;
5358: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5359: $datatable .= '<tr'.$css_class.'>'.
5360: '<td>'.$titlesref->{$row}.'</td>'.
5361: '<td class="LC_left_item">'.
5362: '<table><tr>';
5363: my (%current,%currentcap);
5364: if (ref($settings) eq 'HASH') {
5365: if (ref($settings->{$key}) eq 'HASH') {
5366: foreach my $type (@types) {
5367: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5368: $current{$type} = $settings->{$key}->{$type}->{$row};
5369: }
5370: if (($row eq 'limit') && ($key eq 'default')) {
5371: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5372: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
5373: }
5374: }
5375: }
5376: }
5377: }
5378: my %roles = (
5379: '0' => &Apache::lonnet::plaintext('dc'),
5380: );
5381:
5382: foreach my $type (@types) {
5383: unless (($row eq 'registered') && ($key eq 'default')) {
5384: $datatable .= '<th>'.&mt($type).'</th>';
5385: }
5386: }
5387: unless (($row eq 'registered') && ($key eq 'default')) {
5388: $datatable .= '</tr><tr>';
5389: }
5390: foreach my $type (@types) {
5391: if ($type eq 'community') {
5392: $roles{'1'} = &mt('Community personnel');
5393: } else {
5394: $roles{'1'} = &mt('Course personnel');
5395: }
5396: $datatable .= '<td style="vertical-align: top">';
5397: if ($position eq 'top') {
5398: my %checked;
5399: if ($current{$type} eq '0') {
5400: $checked{'0'} = ' checked="checked"';
5401: } else {
5402: $checked{'1'} = ' checked="checked"';
5403: }
5404: foreach my $role ('1','0') {
5405: $datatable .= '<span class="LC_nobreak"><label>'.
5406: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
5407: 'value="'.$role.'"'.$checked{$role}.' />'.
5408: $roles{$role}.'</label></span> ';
5409: }
5410: } else {
5411: if ($row eq 'types') {
5412: my %checked;
5413: if ($current{$type} =~ /^(all|dom)$/) {
5414: $checked{$1} = ' checked="checked"';
5415: } else {
5416: $checked{''} = ' checked="checked"';
5417: }
5418: foreach my $val ('','dom','all') {
5419: $datatable .= '<span class="LC_nobreak"><label>'.
5420: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5421: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5422: }
5423: } elsif ($row eq 'registered') {
5424: my %checked;
5425: if ($current{$type} eq '1') {
5426: $checked{'1'} = ' checked="checked"';
5427: } else {
5428: $checked{'0'} = ' checked="checked"';
5429: }
5430: foreach my $val ('0','1') {
5431: $datatable .= '<span class="LC_nobreak"><label>'.
5432: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5433: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5434: }
5435: } elsif ($row eq 'approval') {
5436: my %checked;
5437: if ($current{$type} =~ /^([12])$/) {
5438: $checked{$1} = ' checked="checked"';
5439: } else {
5440: $checked{'0'} = ' checked="checked"';
5441: }
5442: for my $val (0..2) {
5443: $datatable .= '<span class="LC_nobreak"><label>'.
5444: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5445: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5446: }
5447: } elsif ($row eq 'limit') {
5448: my %checked;
5449: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
5450: $checked{$1} = ' checked="checked"';
5451: } else {
5452: $checked{'none'} = ' checked="checked"';
5453: }
5454: my $cap;
5455: if ($currentcap{$type} =~ /^\d+$/) {
5456: $cap = $currentcap{$type};
5457: }
5458: foreach my $val ('none','allstudents','selfenrolled') {
5459: $datatable .= '<span class="LC_nobreak"><label>'.
5460: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5461: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5462: }
5463: $datatable .= '<br />'.
5464: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
5465: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
5466: '</span>';
5467: }
5468: }
5469: $datatable .= '</td>';
5470: }
5471: $datatable .= '</tr>';
5472: }
5473: $datatable .= '</table></td></tr>';
5474: }
5475: } elsif ($position eq 'bottom') {
1.235 raeburn 5476: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
5477: }
5478: $$rowtotal += $itemcount;
5479: return $datatable;
5480: }
5481:
5482: sub print_validation_rows {
5483: my ($caller,$dom,$settings,$rowtotal) = @_;
5484: my ($itemsref,$namesref,$fieldsref);
5485: if ($caller eq 'selfenroll') {
5486: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
5487: } elsif ($caller eq 'requestcourses') {
5488: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
5489: }
5490: my %currvalidation;
5491: if (ref($settings) eq 'HASH') {
5492: if (ref($settings->{'validation'}) eq 'HASH') {
5493: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 5494: }
1.235 raeburn 5495: }
5496: my $datatable;
5497: my $itemcount = 0;
5498: foreach my $item (@{$itemsref}) {
5499: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5500: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5501: $namesref->{$item}.
5502: '</span></td>'.
5503: '<td class="LC_left_item">';
5504: if (($item eq 'url') || ($item eq 'button')) {
5505: $datatable .= '<span class="LC_nobreak">'.
5506: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
5507: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
5508: } elsif ($item eq 'fields') {
5509: my @currfields;
5510: if (ref($currvalidation{$item}) eq 'ARRAY') {
5511: @currfields = @{$currvalidation{$item}};
5512: }
5513: foreach my $field (@{$fieldsref}) {
5514: my $check = '';
5515: if (grep(/^\Q$field\E$/,@currfields)) {
5516: $check = ' checked="checked"';
5517: }
5518: $datatable .= '<span class="LC_nobreak"><label>'.
5519: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
5520: ' value="'.$field.'"'.$check.' />'.$field.
5521: '</label></span> ';
5522: }
5523: } elsif ($item eq 'markup') {
5524: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
5525: $currvalidation{$item}.
1.231 raeburn 5526: '</textarea>';
1.235 raeburn 5527: }
5528: $datatable .= '</td></tr>'."\n";
5529: if (ref($rowtotal)) {
1.231 raeburn 5530: $itemcount ++;
5531: }
5532: }
1.235 raeburn 5533: if ($caller eq 'requestcourses') {
5534: my %currhash;
1.248 raeburn 5535: if (ref($settings) eq 'HASH') {
5536: if (ref($settings->{'validation'}) eq 'HASH') {
5537: if ($settings->{'validation'}{'dc'} ne '') {
5538: $currhash{$settings->{'validation'}{'dc'}} = 1;
5539: }
1.235 raeburn 5540: }
5541: }
5542: my $numinrow = 2;
5543: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
5544: 'validationdc',%currhash);
1.247 raeburn 5545: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5546: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.235 raeburn 5547: if ($numdc > 1) {
1.247 raeburn 5548: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 5549: } else {
1.247 raeburn 5550: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 5551: }
1.247 raeburn 5552: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 5553: $itemcount ++;
5554: }
5555: if (ref($rowtotal)) {
5556: $$rowtotal += $itemcount;
5557: }
1.231 raeburn 5558: return $datatable;
5559: }
5560:
1.137 raeburn 5561: sub print_usersessions {
5562: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 5563: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 5564: my (%by_ip,%by_location,@intdoms,@instdoms);
5565: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 5566:
5567: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 5568: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 5569: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 5570: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 5571: if ($position eq 'top') {
1.152 raeburn 5572: if (keys(%serverhomes) > 1) {
1.145 raeburn 5573: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.261 raeburn 5574: my $curroffloadnow;
5575: if (ref($settings) eq 'HASH') {
5576: if (ref($settings->{'offloadnow'}) eq 'HASH') {
5577: $curroffloadnow = $settings->{'offloadnow'};
5578: }
5579: }
5580: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 5581: } else {
1.140 raeburn 5582: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 5583: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
5584: '</td></tr>';
1.140 raeburn 5585: }
1.137 raeburn 5586: } else {
1.279 raeburn 5587: my %titles = &usersession_titles();
5588: my ($prefix,@types);
5589: if ($position eq 'bottom') {
5590: $prefix = 'remote';
5591: @types = ('version','excludedomain','includedomain');
1.145 raeburn 5592: } else {
1.279 raeburn 5593: $prefix = 'hosted';
5594: @types = ('excludedomain','includedomain');
5595: }
5596: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
5597: }
5598: $$rowtotal += $itemcount;
5599: return $datatable;
5600: }
5601:
5602: sub rules_by_location {
5603: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
5604: my ($datatable,$itemcount,$css_class);
5605: if (keys(%{$by_location}) == 0) {
5606: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5607: $datatable = '<tr'.$css_class.'><td colspan="2">'.
5608: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
5609: '</td></tr>';
5610: $itemcount = 1;
5611: } else {
5612: $itemcount = 0;
5613: my $numinrow = 5;
5614: my (%current,%checkedon,%checkedoff);
5615: my @locations = sort(keys(%{$by_location}));
5616: foreach my $type (@{$types}) {
5617: $checkedon{$type} = '';
5618: $checkedoff{$type} = ' checked="checked"';
5619: }
5620: if (ref($settings) eq 'HASH') {
5621: if (ref($settings->{$prefix}) eq 'HASH') {
5622: foreach my $key (keys(%{$settings->{$prefix}})) {
5623: $current{$key} = $settings->{$prefix}{$key};
5624: if ($key eq 'version') {
5625: if ($current{$key} ne '') {
1.145 raeburn 5626: $checkedon{$key} = ' checked="checked"';
5627: $checkedoff{$key} = '';
5628: }
1.279 raeburn 5629: } elsif (ref($current{$key}) eq 'ARRAY') {
5630: $checkedon{$key} = ' checked="checked"';
5631: $checkedoff{$key} = '';
1.137 raeburn 5632: }
5633: }
5634: }
1.279 raeburn 5635: }
5636: foreach my $type (@{$types}) {
5637: next if ($type ne 'version' && !@locations);
5638: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5639: $datatable .= '<tr'.$css_class.'>
5640: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
5641: <span class="LC_nobreak">
5642: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
5643: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
5644: if ($type eq 'version') {
5645: my @lcversions = &Apache::lonnet::all_loncaparevs();
5646: my $selector = '<select name="'.$prefix.'_version">';
5647: foreach my $version (@lcversions) {
5648: my $selected = '';
5649: if ($current{'version'} eq $version) {
5650: $selected = ' selected="selected"';
1.145 raeburn 5651: }
1.279 raeburn 5652: $selector .= ' <option value="'.$version.'"'.
5653: $selected.'>'.$version.'</option>';
5654: }
5655: $selector .= '</select> ';
5656: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
5657: } else {
5658: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
5659: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
5660: ' />'.(' 'x2).
5661: '<input type="button" value="'.&mt('uncheck all').'" '.
5662: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
5663: "\n".
5664: '</div><div><table>';
5665: my $rem;
5666: for (my $i=0; $i<@locations; $i++) {
5667: my ($showloc,$value,$checkedtype);
5668: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
5669: my $ip = $by_location->{$locations[$i]}->[0];
5670: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5671: $value = join(':',@{$by_ip->{$ip}});
5672: $showloc = join(', ',@{$by_ip->{$ip}});
5673: if (ref($current{$type}) eq 'ARRAY') {
5674: foreach my $loc (@{$by_ip->{$ip}}) {
5675: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
5676: $checkedtype = ' checked="checked"';
5677: last;
1.145 raeburn 5678: }
1.138 raeburn 5679: }
5680: }
5681: }
1.137 raeburn 5682: }
1.279 raeburn 5683: $rem = $i%($numinrow);
5684: if ($rem == 0) {
5685: if ($i > 0) {
5686: $datatable .= '</tr>';
5687: }
5688: $datatable .= '<tr>';
5689: }
5690: $datatable .= '<td class="LC_left_item">'.
5691: '<span class="LC_nobreak"><label>'.
5692: '<input type="checkbox" name="'.$prefix.'_'.$type.
5693: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
5694: '</label></span></td>';
5695: }
5696: $rem = @locations%($numinrow);
5697: my $colsleft = $numinrow - $rem;
5698: if ($colsleft > 1 ) {
5699: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5700: ' </td>';
5701: } elsif ($colsleft == 1) {
5702: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 5703: }
1.279 raeburn 5704: $datatable .= '</tr></table>';
1.137 raeburn 5705: }
1.279 raeburn 5706: $datatable .= '</td></tr>';
5707: $itemcount ++;
1.137 raeburn 5708: }
5709: }
1.279 raeburn 5710: return ($datatable,$itemcount);
1.137 raeburn 5711: }
5712:
1.275 raeburn 5713: sub print_ssl {
5714: my ($position,$dom,$settings,$rowtotal) = @_;
5715: my ($css_class,$datatable);
5716: my $itemcount = 1;
5717: if ($position eq 'top') {
1.281 raeburn 5718: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5719: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5720: my $same_institution;
5721: if ($intdom ne '') {
5722: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
5723: if (ref($internet_names) eq 'ARRAY') {
5724: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
5725: $same_institution = 1;
5726: }
5727: }
5728: }
1.275 raeburn 5729: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 5730: $datatable = '<tr'.$css_class.'><td colspan="2">';
5731: if ($same_institution) {
5732: my %domservers = &Apache::lonnet::get_servers($dom);
5733: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
5734: } else {
5735: $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.");
5736: }
5737: $datatable .= '</td></tr>';
1.275 raeburn 5738: $itemcount ++;
5739: } else {
5740: my %titles = &ssl_titles();
5741: my (%by_ip,%by_location,@intdoms,@instdoms);
5742: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
5743: my @alldoms = &Apache::lonnet::all_domains();
5744: my %serverhomes = %Apache::lonnet::serverhomeIDs;
5745: my @domservers = &Apache::lonnet::get_servers($dom);
5746: my %servers = &Apache::lonnet::internet_dom_servers($dom);
5747: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 5748: if (($position eq 'connto') || ($position eq 'connfrom')) {
5749: my $legacy;
5750: unless (ref($settings) eq 'HASH') {
5751: my $name;
5752: if ($position eq 'connto') {
5753: $name = 'loncAllowInsecure';
5754: } else {
5755: $name = 'londAllowInsecure';
5756: }
5757: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
5758: my @ids=&Apache::lonnet::current_machine_ids();
5759: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
5760: my %what = (
5761: $name => 1,
5762: );
5763: my ($result,$returnhash) =
5764: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
5765: if ($result eq 'ok') {
5766: if (ref($returnhash) eq 'HASH') {
5767: $legacy = $returnhash->{$name};
5768: }
5769: }
5770: } else {
5771: $legacy = $Apache::lonnet::perlvar{$name};
5772: }
5773: }
1.275 raeburn 5774: foreach my $type ('dom','intdom','other') {
5775: my %checked;
5776: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5777: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
5778: '<td class="LC_right_item">';
5779: my $skip;
5780: if ($type eq 'dom') {
5781: unless (keys(%servers) > 1) {
5782: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
5783: $skip = 1;
5784: }
5785: }
5786: if ($type eq 'intdom') {
5787: unless (@instdoms > 1) {
5788: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
5789: $skip = 1;
5790: }
5791: } elsif ($type eq 'other') {
5792: if (keys(%by_location) == 0) {
5793: $datatable .= &mt('Nothing to set here, as there are no other institutions');
5794: $skip = 1;
5795: }
5796: }
5797: unless ($skip) {
5798: $checked{'yes'} = ' checked="checked"';
5799: if (ref($settings) eq 'HASH') {
1.293 raeburn 5800: if (ref($settings->{$position}) eq 'HASH') {
5801: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 5802: $checked{$1} = $checked{'yes'};
5803: delete($checked{'yes'});
5804: }
5805: }
1.293 raeburn 5806: } else {
5807: if ($legacy == 0) {
5808: $checked{'req'} = $checked{'yes'};
5809: delete($checked{'yes'});
5810: }
1.275 raeburn 5811: }
5812: foreach my $option ('no','yes','req') {
5813: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 5814: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 5815: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
5816: '</label></span>'.(' 'x2);
5817: }
5818: }
5819: $datatable .= '</td></tr>';
5820: $itemcount ++;
5821: }
5822: } else {
5823: my $prefix = 'replication';
5824: my @types = ('certreq','nocertreq');
1.279 raeburn 5825: if (keys(%by_location) == 0) {
5826: $datatable .= '<tr'.$css_class.'><td>'.
5827: &mt('Nothing to set here, as there are no other institutions').
5828: '</td></tr>';
5829: $itemcount ++;
1.275 raeburn 5830: } else {
1.279 raeburn 5831: ($datatable,$itemcount) =
5832: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 5833: }
5834: }
5835: }
5836: $$rowtotal += $itemcount;
5837: return $datatable;
5838: }
5839:
5840: sub ssl_titles {
5841: return &Apache::lonlocal::texthash (
5842: dom => 'LON-CAPA servers/VMs from same domain',
5843: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
5844: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 5845: connto => 'Connections to other servers',
5846: connfrom => 'Connections from other servers',
1.275 raeburn 5847: replication => 'Replicating content to other institutions',
5848: certreq => 'Client certificate required, but specific domains exempt',
5849: nocertreq => 'No client certificate required, except for specific domains',
5850: no => 'SSL not used',
5851: yes => 'SSL Optional (used if available)',
5852: req => 'SSL Required',
5853: );
1.279 raeburn 5854: }
5855:
5856: sub print_trust {
5857: my ($prefix,$dom,$settings,$rowtotal) = @_;
5858: my ($css_class,$datatable,%checked,%choices);
5859: my (%by_ip,%by_location,@intdoms,@instdoms);
5860: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
5861: my $itemcount = 1;
5862: my %titles = &trust_titles();
5863: my @types = ('exc','inc');
5864: if ($prefix eq 'top') {
5865: $prefix = 'content';
5866: } elsif ($prefix eq 'bottom') {
5867: $prefix = 'msg';
5868: }
5869: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
5870: $$rowtotal += $itemcount;
5871: return $datatable;
5872: }
5873:
5874: sub trust_titles {
5875: return &Apache::lonlocal::texthash(
5876: content => "Access to this domain's content by others",
5877: shared => "Access to other domain's content by this domain",
5878: enroll => "Enrollment in this domain's courses by others",
5879: othcoau => "Co-author roles in this domain for others",
5880: coaurem => "Co-author roles for this domain's users elsewhere",
5881: domroles => "Domain roles in this domain assignable to others",
5882: catalog => "Course Catalog for this domain displayed elsewhere",
5883: reqcrs => "Requests for creation of courses in this domain by others",
5884: msg => "Users in other domains can send messages to this domain",
5885: exc => "Allow all, but exclude specific domains",
5886: inc => "Deny all, but include specific domains",
5887: );
1.275 raeburn 5888: }
5889:
1.138 raeburn 5890: sub build_location_hashes {
1.275 raeburn 5891: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 5892: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 5893: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 5894: my %iphost = &Apache::lonnet::get_iphost();
5895: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
5896: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
5897: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
5898: foreach my $id (@{$iphost{$primary_ip}}) {
5899: my $intdom = &Apache::lonnet::internet_dom($id);
5900: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
5901: push(@{$intdoms},$intdom);
5902: }
5903: }
5904: }
5905: foreach my $ip (keys(%iphost)) {
5906: if (ref($iphost{$ip}) eq 'ARRAY') {
5907: foreach my $id (@{$iphost{$ip}}) {
5908: my $location = &Apache::lonnet::internet_dom($id);
5909: if ($location) {
1.275 raeburn 5910: if (grep(/^\Q$location\E$/,@{$intdoms})) {
5911: my $dom = &Apache::lonnet::host_domain($id);
5912: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
5913: push(@{$instdoms},$dom);
5914: }
5915: next;
5916: }
1.138 raeburn 5917: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5918: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
5919: push(@{$by_ip->{$ip}},$location);
5920: }
5921: } else {
5922: $by_ip->{$ip} = [$location];
5923: }
5924: }
5925: }
5926: }
5927: }
5928: foreach my $ip (sort(keys(%{$by_ip}))) {
5929: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5930: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
5931: my $first = $by_ip->{$ip}->[0];
5932: if (ref($by_location->{$first}) eq 'ARRAY') {
5933: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
5934: push(@{$by_location->{$first}},$ip);
5935: }
5936: } else {
5937: $by_location->{$first} = [$ip];
5938: }
5939: }
5940: }
5941: return;
5942: }
5943:
1.145 raeburn 5944: sub current_offloads_to {
5945: my ($dom,$settings,$servers) = @_;
5946: my (%spareid,%otherdomconfigs);
1.152 raeburn 5947: if (ref($servers) eq 'HASH') {
1.145 raeburn 5948: foreach my $lonhost (sort(keys(%{$servers}))) {
5949: my $gotspares;
1.152 raeburn 5950: if (ref($settings) eq 'HASH') {
5951: if (ref($settings->{'spares'}) eq 'HASH') {
5952: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
5953: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
5954: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
5955: $gotspares = 1;
5956: }
1.145 raeburn 5957: }
5958: }
5959: unless ($gotspares) {
5960: my $gotspares;
5961: my $serverhomeID =
5962: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
5963: my $serverhomedom =
5964: &Apache::lonnet::host_domain($serverhomeID);
5965: if ($serverhomedom ne $dom) {
5966: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
5967: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5968: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5969: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5970: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5971: $gotspares = 1;
5972: }
5973: }
5974: } else {
5975: $otherdomconfigs{$serverhomedom} =
5976: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
5977: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
5978: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5979: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5980: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
5981: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5982: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5983: $gotspares = 1;
5984: }
5985: }
5986: }
5987: }
5988: }
5989: }
5990: }
5991: unless ($gotspares) {
5992: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
5993: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
5994: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
5995: } else {
5996: my $server_hostname = &Apache::lonnet::hostname($lonhost);
5997: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
5998: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
5999: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6000: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6001: } else {
1.150 raeburn 6002: my %what = (
6003: spareid => 1,
6004: );
6005: my ($result,$returnhash) =
6006: &Apache::lonnet::get_remote_globals($lonhost,\%what);
6007: if ($result eq 'ok') {
6008: if (ref($returnhash) eq 'HASH') {
6009: if (ref($returnhash->{'spareid'}) eq 'HASH') {
6010: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
6011: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
6012: }
6013: }
1.145 raeburn 6014: }
6015: }
6016: }
6017: }
6018: }
6019: }
6020: return %spareid;
6021: }
6022:
6023: sub spares_row {
1.261 raeburn 6024: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 6025: my $css_class;
6026: my $numinrow = 4;
6027: my $itemcount = 1;
6028: my $datatable;
1.152 raeburn 6029: my %typetitles = &sparestype_titles();
6030: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 6031: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 6032: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
6033: my ($othercontrol,$serverdom);
6034: if ($serverhome ne $server) {
6035: $serverdom = &Apache::lonnet::host_domain($serverhome);
6036: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6037: } else {
6038: $serverdom = &Apache::lonnet::host_domain($server);
6039: if ($serverdom ne $dom) {
6040: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6041: }
6042: }
6043: next unless (ref($spareid->{$server}) eq 'HASH');
1.261 raeburn 6044: my $checkednow;
6045: if (ref($curroffloadnow) eq 'HASH') {
6046: if ($curroffloadnow->{$server}) {
6047: $checkednow = ' checked="checked"';
6048: }
6049: }
1.145 raeburn 6050: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6051: $datatable .= '<tr'.$css_class.'>
6052: <td rowspan="2">
1.183 bisitz 6053: <span class="LC_nobreak">'.
6054: &mt('[_1] when busy, offloads to:'
1.261 raeburn 6055: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 6056: '<span class="LC_nobreak">'."\n".
1.261 raeburn 6057: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
6058: ' '.&mt('Switch active users on next access').'</label></span>'.
1.183 bisitz 6059: "\n";
1.145 raeburn 6060: my (%current,%canselect);
1.152 raeburn 6061: my @choices =
6062: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
6063: foreach my $type ('primary','default') {
6064: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 6065: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
6066: my @spares = @{$spareid->{$server}{$type}};
6067: if (@spares > 0) {
1.152 raeburn 6068: if ($othercontrol) {
6069: $current{$type} = join(', ',@spares);
6070: } else {
6071: $current{$type} .= '<table>';
6072: my $numspares = scalar(@spares);
6073: for (my $i=0; $i<@spares; $i++) {
6074: my $rem = $i%($numinrow);
6075: if ($rem == 0) {
6076: if ($i > 0) {
6077: $current{$type} .= '</tr>';
6078: }
6079: $current{$type} .= '<tr>';
1.145 raeburn 6080: }
1.152 raeburn 6081: $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'".');" /> '.
6082: $spareid->{$server}{$type}[$i].
6083: '</label></td>'."\n";
6084: }
6085: my $rem = @spares%($numinrow);
6086: my $colsleft = $numinrow - $rem;
6087: if ($colsleft > 1 ) {
6088: $current{$type} .= '<td colspan="'.$colsleft.
6089: '" class="LC_left_item">'.
6090: ' </td>';
6091: } elsif ($colsleft == 1) {
6092: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 6093: }
1.152 raeburn 6094: $current{$type} .= '</tr></table>';
1.150 raeburn 6095: }
1.145 raeburn 6096: }
6097: }
6098: if ($current{$type} eq '') {
6099: $current{$type} = &mt('None specified');
6100: }
1.152 raeburn 6101: if ($othercontrol) {
6102: if ($type eq 'primary') {
6103: $canselect{$type} = $othercontrol;
6104: }
6105: } else {
6106: $canselect{$type} =
6107: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
6108: '<select name="newspare_'.$type.'_'.$server.'" '.
6109: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
6110: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
6111: if (@choices > 0) {
6112: foreach my $lonhost (@choices) {
6113: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
6114: }
6115: }
6116: $canselect{$type} .= '</select>'."\n";
6117: }
6118: } else {
6119: $current{$type} = &mt('Could not be determined');
6120: if ($type eq 'primary') {
6121: $canselect{$type} = $othercontrol;
6122: }
1.145 raeburn 6123: }
1.152 raeburn 6124: if ($type eq 'default') {
6125: $datatable .= '<tr'.$css_class.'>';
6126: }
6127: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
6128: '<td>'.$current{$type}.'</td>'."\n".
6129: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 6130: }
6131: $itemcount ++;
6132: }
6133: }
6134: $$rowtotal += $itemcount;
6135: return $datatable;
6136: }
6137:
1.152 raeburn 6138: sub possible_newspares {
6139: my ($server,$currspares,$serverhomes,$altids) = @_;
6140: my $serverhostname = &Apache::lonnet::hostname($server);
6141: my %excluded;
6142: if ($serverhostname ne '') {
6143: %excluded = (
6144: $serverhostname => 1,
6145: );
6146: }
6147: if (ref($currspares) eq 'HASH') {
6148: foreach my $type (keys(%{$currspares})) {
6149: if (ref($currspares->{$type}) eq 'ARRAY') {
6150: if (@{$currspares->{$type}} > 0) {
6151: foreach my $curr (@{$currspares->{$type}}) {
6152: my $hostname = &Apache::lonnet::hostname($curr);
6153: $excluded{$hostname} = 1;
6154: }
6155: }
6156: }
6157: }
6158: }
6159: my @choices;
6160: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
6161: if (keys(%{$serverhomes}) > 1) {
6162: foreach my $name (sort(keys(%{$serverhomes}))) {
6163: unless ($excluded{$name}) {
6164: if (exists($altids->{$serverhomes->{$name}})) {
6165: push(@choices,$altids->{$serverhomes->{$name}});
6166: } else {
6167: push(@choices,$serverhomes->{$name});
1.145 raeburn 6168: }
6169: }
6170: }
6171: }
6172: }
1.152 raeburn 6173: return sort(@choices);
1.145 raeburn 6174: }
6175:
1.150 raeburn 6176: sub print_loadbalancing {
6177: my ($dom,$settings,$rowtotal) = @_;
6178: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6179: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6180: my $numinrow = 1;
6181: my $datatable;
6182: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 6183: my (%currbalancer,%currtargets,%currrules,%existing);
6184: if (ref($settings) eq 'HASH') {
6185: %existing = %{$settings};
6186: }
6187: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
6188: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
6189: \%currtargets,\%currrules);
1.150 raeburn 6190: } else {
6191: return;
6192: }
6193: my ($othertitle,$usertypes,$types) =
6194: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 6195: my $rownum = 8;
1.150 raeburn 6196: if (ref($types) eq 'ARRAY') {
6197: $rownum += scalar(@{$types});
6198: }
1.171 raeburn 6199: my @css_class = ('LC_odd_row','LC_even_row');
6200: my $balnum = 0;
6201: my $islast;
6202: my (@toshow,$disabledtext);
6203: if (keys(%currbalancer) > 0) {
6204: @toshow = sort(keys(%currbalancer));
6205: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
6206: push(@toshow,'');
6207: }
6208: } else {
6209: @toshow = ('');
6210: $disabledtext = &mt('No existing load balancer');
6211: }
6212: foreach my $lonhost (@toshow) {
6213: if ($balnum == scalar(@toshow)-1) {
6214: $islast = 1;
6215: } else {
6216: $islast = 0;
6217: }
6218: my $cssidx = $balnum%2;
6219: my $targets_div_style = 'display: none';
6220: my $disabled_div_style = 'display: block';
6221: my $homedom_div_style = 'display: none';
6222: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 6223: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 6224: '<p>';
6225: if ($lonhost eq '') {
1.210 raeburn 6226: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 6227: if (keys(%currbalancer) > 0) {
6228: $datatable .= &mt('Add balancer:');
6229: } else {
6230: $datatable .= &mt('Enable balancer:');
6231: }
6232: $datatable .= ' '.
6233: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
6234: ' id="loadbalancing_lonhost_'.$balnum.'"'.
6235: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
6236: '<option value="" selected="selected">'.&mt('None').
6237: '</option>'."\n";
6238: foreach my $server (sort(keys(%servers))) {
6239: next if ($currbalancer{$server});
6240: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
6241: }
1.210 raeburn 6242: $datatable .=
1.171 raeburn 6243: '</select>'."\n".
6244: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
6245: } else {
6246: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
6247: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
6248: &mt('Stop balancing').'</label>'.
6249: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
6250: $targets_div_style = 'display: block';
6251: $disabled_div_style = 'display: none';
6252: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
6253: $homedom_div_style = 'display: block';
6254: }
6255: }
1.306 raeburn 6256: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 6257: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
6258: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
6259: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
6260: my ($numspares,@spares) = &count_servers($lonhost,%servers);
6261: my @sparestypes = ('primary','default');
6262: my %typetitles = &sparestype_titles();
1.284 raeburn 6263: my %hostherechecked = (
6264: no => ' checked="checked"',
6265: );
1.171 raeburn 6266: foreach my $sparetype (@sparestypes) {
6267: my $targettable;
6268: for (my $i=0; $i<$numspares; $i++) {
6269: my $checked;
6270: if (ref($currtargets{$lonhost}) eq 'HASH') {
6271: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6272: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6273: $checked = ' checked="checked"';
6274: }
6275: }
6276: }
6277: my ($chkboxval,$disabled);
6278: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
6279: $chkboxval = $spares[$i];
6280: }
6281: if (exists($currbalancer{$spares[$i]})) {
6282: $disabled = ' disabled="disabled"';
6283: }
1.210 raeburn 6284: $targettable .=
1.253 raeburn 6285: '<td><span class="LC_nobreak"><label>'.
6286: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 6287: $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 6288: '</span></label></span></td>';
1.171 raeburn 6289: my $rem = $i%($numinrow);
6290: if ($rem == 0) {
6291: if (($i > 0) && ($i < $numspares-1)) {
6292: $targettable .= '</tr>';
6293: }
6294: if ($i < $numspares-1) {
6295: $targettable .= '<tr>';
1.150 raeburn 6296: }
6297: }
6298: }
1.171 raeburn 6299: if ($targettable ne '') {
6300: my $rem = $numspares%($numinrow);
6301: my $colsleft = $numinrow - $rem;
6302: if ($colsleft > 1 ) {
6303: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6304: ' </td>';
6305: } elsif ($colsleft == 1) {
6306: $targettable .= '<td class="LC_left_item"> </td>';
6307: }
6308: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
6309: '<table><tr>'.$targettable.'</tr></table><br />';
6310: }
1.284 raeburn 6311: $hostherechecked{$sparetype} = '';
6312: if (ref($currtargets{$lonhost}) eq 'HASH') {
6313: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6314: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6315: $hostherechecked{$sparetype} = ' checked="checked"';
6316: $hostherechecked{'no'} = '';
6317: }
6318: }
6319: }
6320: }
6321: $datatable .= &mt('Hosting on balancer itself').'<br />'.
6322: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
6323: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
6324: foreach my $sparetype (@sparestypes) {
6325: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
6326: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
6327: '</i></label><br />';
1.171 raeburn 6328: }
6329: $datatable .= '</div></td></tr>'.
6330: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
6331: $othertitle,$usertypes,$types,\%servers,
6332: \%currbalancer,$lonhost,
6333: $targets_div_style,$homedom_div_style,
6334: $css_class[$cssidx],$balnum,$islast);
6335: $$rowtotal += $rownum;
6336: $balnum ++;
6337: }
6338: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
6339: return $datatable;
6340: }
6341:
6342: sub get_loadbalancers_config {
6343: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
6344: return unless ((ref($servers) eq 'HASH') &&
6345: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
6346: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
6347: if (keys(%{$existing}) > 0) {
6348: my $oldlonhost;
6349: foreach my $key (sort(keys(%{$existing}))) {
6350: if ($key eq 'lonhost') {
6351: $oldlonhost = $existing->{'lonhost'};
6352: $currbalancer->{$oldlonhost} = 1;
6353: } elsif ($key eq 'targets') {
6354: if ($oldlonhost) {
6355: $currtargets->{$oldlonhost} = $existing->{'targets'};
6356: }
6357: } elsif ($key eq 'rules') {
6358: if ($oldlonhost) {
6359: $currrules->{$oldlonhost} = $existing->{'rules'};
6360: }
6361: } elsif (ref($existing->{$key}) eq 'HASH') {
6362: $currbalancer->{$key} = 1;
6363: $currtargets->{$key} = $existing->{$key}{'targets'};
6364: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 6365: }
6366: }
1.171 raeburn 6367: } else {
6368: my ($balancerref,$targetsref) =
6369: &Apache::lonnet::get_lonbalancer_config($servers);
6370: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
6371: foreach my $server (sort(keys(%{$balancerref}))) {
6372: $currbalancer->{$server} = 1;
6373: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 6374: }
6375: }
6376: }
1.171 raeburn 6377: return;
1.150 raeburn 6378: }
6379:
6380: sub loadbalancing_rules {
6381: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 6382: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
6383: $css_class,$balnum,$islast) = @_;
1.150 raeburn 6384: my $output;
1.171 raeburn 6385: my $num = 0;
1.210 raeburn 6386: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 6387: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
6388: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
6389: foreach my $type (@{$alltypes}) {
1.171 raeburn 6390: $num ++;
1.150 raeburn 6391: my $current;
6392: if (ref($currrules) eq 'HASH') {
6393: $current = $currrules->{$type};
6394: }
1.253 raeburn 6395: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 6396: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 6397: $current = '';
6398: }
6399: }
6400: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 6401: $servers,$currbalancer,$lonhost,$dom,
6402: $targets_div_style,$homedom_div_style,
6403: $css_class,$balnum,$num,$islast);
1.150 raeburn 6404: }
6405: }
6406: return $output;
6407: }
6408:
6409: sub loadbalancing_titles {
6410: my ($dom,$intdom,$usertypes,$types) = @_;
6411: my %othertypes = (
6412: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
6413: '_LC_author' => &mt('Users from [_1] with author role',$dom),
6414: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
6415: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 6416: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
6417: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 6418: );
1.209 raeburn 6419: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 6420: my @available;
1.150 raeburn 6421: if (ref($types) eq 'ARRAY') {
1.302 raeburn 6422: @available = @{$types};
1.150 raeburn 6423: }
1.302 raeburn 6424: unless (grep(/^default$/,@available)) {
6425: push(@available,'default');
6426: }
6427: unshift(@alltypes,@available);
1.150 raeburn 6428: my %titles;
6429: foreach my $type (@alltypes) {
6430: if ($type =~ /^_LC_/) {
6431: $titles{$type} = $othertypes{$type};
6432: } elsif ($type eq 'default') {
6433: $titles{$type} = &mt('All users from [_1]',$dom);
6434: if (ref($types) eq 'ARRAY') {
6435: if (@{$types} > 0) {
6436: $titles{$type} = &mt('Other users from [_1]',$dom);
6437: }
6438: }
6439: } elsif (ref($usertypes) eq 'HASH') {
6440: $titles{$type} = $usertypes->{$type};
6441: }
6442: }
6443: return (\@alltypes,\%othertypes,\%titles);
6444: }
6445:
6446: sub loadbalance_rule_row {
1.171 raeburn 6447: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
6448: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 6449: my @rulenames;
1.150 raeburn 6450: my %ruletitles = &offloadtype_text();
1.209 raeburn 6451: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 6452: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 6453: } else {
1.209 raeburn 6454: @rulenames = ('default','homeserver');
6455: if ($type eq '_LC_external') {
6456: push(@rulenames,'externalbalancer');
6457: } else {
6458: push(@rulenames,'specific');
6459: }
6460: push(@rulenames,'none');
1.150 raeburn 6461: }
6462: my $style = $targets_div_style;
1.253 raeburn 6463: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 6464: $style = $homedom_div_style;
6465: }
1.171 raeburn 6466: my $space;
6467: if ($islast && $num == 1) {
1.317 raeburn 6468: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 6469: }
1.210 raeburn 6470: my $output =
1.306 raeburn 6471: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 6472: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
6473: '<td valaign="top">'.$space.
6474: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 6475: for (my $i=0; $i<@rulenames; $i++) {
6476: my $rule = $rulenames[$i];
6477: my ($checked,$extra);
6478: if ($rulenames[$i] eq 'default') {
6479: $rule = '';
6480: }
6481: if ($rulenames[$i] eq 'specific') {
6482: if (ref($servers) eq 'HASH') {
6483: my $default;
6484: if (($current ne '') && (exists($servers->{$current}))) {
6485: $checked = ' checked="checked"';
6486: }
6487: unless ($checked) {
6488: $default = ' selected="selected"';
6489: }
1.210 raeburn 6490: $extra =
1.171 raeburn 6491: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
6492: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
6493: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
6494: '<option value=""'.$default.'></option>'."\n";
6495: foreach my $server (sort(keys(%{$servers}))) {
6496: if (ref($currbalancer) eq 'HASH') {
6497: next if (exists($currbalancer->{$server}));
6498: }
1.150 raeburn 6499: my $selected;
1.171 raeburn 6500: if ($server eq $current) {
1.150 raeburn 6501: $selected = ' selected="selected"';
6502: }
1.171 raeburn 6503: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 6504: }
6505: $extra .= '</select>';
6506: }
6507: } elsif ($rule eq $current) {
6508: $checked = ' checked="checked"';
6509: }
6510: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 6511: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
6512: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
6513: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 6514: ')"'.$checked.' /> ';
6515: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
6516: $output .= $ruletitles{'particular'};
6517: } else {
6518: $output .= $ruletitles{$rulenames[$i]};
6519: }
6520: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 6521: }
6522: $output .= '</div></td></tr>'."\n";
6523: return $output;
6524: }
6525:
6526: sub offloadtype_text {
6527: my %ruletitles = &Apache::lonlocal::texthash (
6528: 'default' => 'Offloads to default destinations',
6529: 'homeserver' => "Offloads to user's home server",
6530: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
6531: 'specific' => 'Offloads to specific server',
1.161 raeburn 6532: 'none' => 'No offload',
1.209 raeburn 6533: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
6534: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 6535: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 6536: );
6537: return %ruletitles;
6538: }
6539:
6540: sub sparestype_titles {
6541: my %typestitles = &Apache::lonlocal::texthash (
6542: 'primary' => 'primary',
6543: 'default' => 'default',
6544: );
6545: return %typestitles;
6546: }
6547:
1.28 raeburn 6548: sub contact_titles {
6549: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 6550: 'supportemail' => 'Support E-mail address',
6551: 'adminemail' => 'Default Server Admin E-mail address',
6552: 'errormail' => 'Error reports to be e-mailed to',
6553: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 6554: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
6555: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 6556: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
6557: 'requestsmail' => 'E-mail from course requests requiring approval',
6558: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 6559: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 6560: );
6561: my %short_titles = &Apache::lonlocal::texthash (
6562: adminemail => 'Admin E-mail address',
6563: supportemail => 'Support E-mail',
6564: );
6565: return (\%titles,\%short_titles);
6566: }
6567:
1.286 raeburn 6568: sub helpform_fields {
6569: my %titles = &Apache::lonlocal::texthash (
6570: 'username' => 'Name',
6571: 'user' => 'Username/domain',
6572: 'phone' => 'Phone',
6573: 'cc' => 'Cc e-mail',
6574: 'course' => 'Course Details',
6575: 'section' => 'Sections',
1.289 raeburn 6576: 'screenshot' => 'File upload',
1.286 raeburn 6577: );
6578: my @fields = ('username','phone','user','course','section','cc','screenshot');
6579: my %possoptions = (
6580: username => ['yes','no','req'],
1.289 raeburn 6581: phone => ['yes','no','req'],
1.286 raeburn 6582: user => ['yes','no'],
1.289 raeburn 6583: cc => ['yes','no'],
1.286 raeburn 6584: course => ['yes','no'],
6585: section => ['yes','no'],
6586: screenshot => ['yes','no'],
6587: );
6588: my %fieldoptions = &Apache::lonlocal::texthash (
6589: 'yes' => 'Optional',
6590: 'req' => 'Required',
6591: 'no' => "Not shown",
6592: );
6593: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
6594: }
6595:
1.72 raeburn 6596: sub tool_titles {
6597: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 6598: aboutme => 'Personal web page',
1.86 raeburn 6599: blog => 'Blog',
1.162 raeburn 6600: webdav => 'WebDAV',
1.86 raeburn 6601: portfolio => 'Portfolio',
1.88 bisitz 6602: official => 'Official courses (with institutional codes)',
6603: unofficial => 'Unofficial courses',
1.98 raeburn 6604: community => 'Communities',
1.216 raeburn 6605: textbook => 'Textbook courses',
1.271 raeburn 6606: placement => 'Placement tests',
1.86 raeburn 6607: );
1.72 raeburn 6608: return %titles;
6609: }
6610:
1.101 raeburn 6611: sub courserequest_titles {
6612: my %titles = &Apache::lonlocal::texthash (
6613: official => 'Official',
6614: unofficial => 'Unofficial',
6615: community => 'Communities',
1.216 raeburn 6616: textbook => 'Textbook',
1.271 raeburn 6617: placement => 'Placement tests',
1.325 raeburn 6618: lti => 'LTI Provider',
1.101 raeburn 6619: norequest => 'Not allowed',
1.325 raeburn 6620: approval => 'Approval by DC',
1.101 raeburn 6621: validate => 'With validation',
6622: autolimit => 'Numerical limit',
1.103 raeburn 6623: unlimited => '(blank for unlimited)',
1.101 raeburn 6624: );
6625: return %titles;
6626: }
6627:
1.163 raeburn 6628: sub authorrequest_titles {
6629: my %titles = &Apache::lonlocal::texthash (
6630: norequest => 'Not allowed',
6631: approval => 'Approval by Dom. Coord.',
6632: automatic => 'Automatic approval',
6633: );
6634: return %titles;
1.210 raeburn 6635: }
1.163 raeburn 6636:
1.101 raeburn 6637: sub courserequest_conditions {
6638: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 6639: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 6640: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 6641: );
6642: return %conditions;
6643: }
6644:
6645:
1.27 raeburn 6646: sub print_usercreation {
1.30 raeburn 6647: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 6648: my $numinrow = 4;
1.28 raeburn 6649: my $datatable;
6650: if ($position eq 'top') {
1.30 raeburn 6651: $$rowtotal ++;
1.34 raeburn 6652: my $rowcount = 0;
1.32 raeburn 6653: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 6654: if (ref($rules) eq 'HASH') {
6655: if (keys(%{$rules}) > 0) {
1.32 raeburn 6656: $datatable .= &user_formats_row('username',$settings,$rules,
6657: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 6658: $$rowtotal ++;
1.32 raeburn 6659: $rowcount ++;
6660: }
6661: }
6662: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
6663: if (ref($idrules) eq 'HASH') {
6664: if (keys(%{$idrules}) > 0) {
6665: $datatable .= &user_formats_row('id',$settings,$idrules,
6666: $idruleorder,$numinrow,$rowcount);
6667: $$rowtotal ++;
6668: $rowcount ++;
1.28 raeburn 6669: }
6670: }
1.39 raeburn 6671: if ($rowcount == 0) {
6672: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
6673: $$rowtotal ++;
6674: $rowcount ++;
6675: }
1.34 raeburn 6676: } elsif ($position eq 'middle') {
1.224 raeburn 6677: my @creators = ('author','course','requestcrs');
1.37 raeburn 6678: my ($rules,$ruleorder) =
6679: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 6680: my %lt = &usercreation_types();
6681: my %checked;
6682: if (ref($settings) eq 'HASH') {
6683: if (ref($settings->{'cancreate'}) eq 'HASH') {
6684: foreach my $item (@creators) {
6685: $checked{$item} = $settings->{'cancreate'}{$item};
6686: }
6687: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
6688: foreach my $item (@creators) {
6689: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
6690: $checked{$item} = 'none';
6691: }
6692: }
6693: }
6694: }
6695: my $rownum = 0;
6696: foreach my $item (@creators) {
6697: $rownum ++;
1.224 raeburn 6698: if ($checked{$item} eq '') {
6699: $checked{$item} = 'any';
1.34 raeburn 6700: }
6701: my $css_class;
6702: if ($rownum%2) {
6703: $css_class = '';
6704: } else {
6705: $css_class = ' class="LC_odd_row" ';
6706: }
6707: $datatable .= '<tr'.$css_class.'>'.
6708: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 6709: '</span></td><td style="text-align: right">';
1.224 raeburn 6710: my @options = ('any');
6711: if (ref($rules) eq 'HASH') {
6712: if (keys(%{$rules}) > 0) {
6713: push(@options,('official','unofficial'));
1.37 raeburn 6714: }
6715: }
1.224 raeburn 6716: push(@options,'none');
1.37 raeburn 6717: foreach my $option (@options) {
1.50 raeburn 6718: my $type = 'radio';
1.34 raeburn 6719: my $check = ' ';
1.224 raeburn 6720: if ($checked{$item} eq $option) {
6721: $check = ' checked="checked" ';
1.34 raeburn 6722: }
6723: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 6724: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 6725: $item.'" value="'.$option.'"'.$check.'/> '.
6726: $lt{$option}.'</label> </span>';
6727: }
6728: $datatable .= '</td></tr>';
6729: }
1.28 raeburn 6730: } else {
6731: my @contexts = ('author','course','domain');
1.325 raeburn 6732: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 6733: my %checked;
6734: if (ref($settings) eq 'HASH') {
6735: if (ref($settings->{'authtypes'}) eq 'HASH') {
6736: foreach my $item (@contexts) {
6737: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
6738: foreach my $auth (@authtypes) {
6739: if ($settings->{'authtypes'}{$item}{$auth}) {
6740: $checked{$item}{$auth} = ' checked="checked" ';
6741: }
6742: }
6743: }
6744: }
1.27 raeburn 6745: }
1.35 raeburn 6746: } else {
6747: foreach my $item (@contexts) {
1.36 raeburn 6748: foreach my $auth (@authtypes) {
1.35 raeburn 6749: $checked{$item}{$auth} = ' checked="checked" ';
6750: }
6751: }
1.27 raeburn 6752: }
1.28 raeburn 6753: my %title = &context_names();
6754: my %authname = &authtype_names();
6755: my $rownum = 0;
6756: my $css_class;
6757: foreach my $item (@contexts) {
6758: if ($rownum%2) {
6759: $css_class = '';
6760: } else {
6761: $css_class = ' class="LC_odd_row" ';
6762: }
1.30 raeburn 6763: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 6764: '<td>'.$title{$item}.
6765: '</td><td class="LC_left_item">'.
6766: '<span class="LC_nobreak">';
6767: foreach my $auth (@authtypes) {
6768: $datatable .= '<label>'.
6769: '<input type="checkbox" name="'.$item.'_auth" '.
6770: $checked{$item}{$auth}.' value="'.$auth.'" />'.
6771: $authname{$auth}.'</label> ';
6772: }
6773: $datatable .= '</span></td></tr>';
6774: $rownum ++;
1.27 raeburn 6775: }
1.30 raeburn 6776: $$rowtotal += $rownum;
1.27 raeburn 6777: }
6778: return $datatable;
6779: }
6780:
1.224 raeburn 6781: sub print_selfcreation {
6782: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 6783: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
6784: $emaildomain,$datatable);
1.224 raeburn 6785: if (ref($settings) eq 'HASH') {
6786: if (ref($settings->{'cancreate'}) eq 'HASH') {
6787: $createsettings = $settings->{'cancreate'};
1.236 raeburn 6788: if (ref($createsettings) eq 'HASH') {
6789: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
6790: @selfcreate = @{$createsettings->{'selfcreate'}};
6791: } elsif ($createsettings->{'selfcreate'} ne '') {
6792: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
6793: @selfcreate = ('email','login','sso');
6794: } elsif ($createsettings->{'selfcreate'} ne 'none') {
6795: @selfcreate = ($createsettings->{'selfcreate'});
6796: }
6797: }
6798: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
6799: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 6800: }
1.305 raeburn 6801: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
6802: $emailoptions = $createsettings->{'emailoptions'};
6803: }
1.303 raeburn 6804: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
6805: $emailverified = $createsettings->{'emailverified'};
6806: }
6807: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
6808: $emaildomain = $createsettings->{'emaildomain'};
6809: }
1.224 raeburn 6810: }
6811: }
6812: }
6813: my %radiohash;
6814: my $numinrow = 4;
6815: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 6816: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 6817: if ($position eq 'top') {
6818: my %choices = &Apache::lonlocal::texthash (
6819: cancreate_login => 'Institutional Login',
6820: cancreate_sso => 'Institutional Single Sign On',
6821: );
6822: my @toggles = sort(keys(%choices));
6823: my %defaultchecked = (
6824: 'cancreate_login' => 'off',
6825: 'cancreate_sso' => 'off',
6826: );
1.228 raeburn 6827: my ($onclick,$itemcount);
1.224 raeburn 6828: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6829: \%choices,$itemcount,$onclick);
1.228 raeburn 6830: $$rowtotal += $itemcount;
6831:
1.224 raeburn 6832: if (ref($usertypes) eq 'HASH') {
6833: if (keys(%{$usertypes}) > 0) {
6834: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
6835: $dom,$numinrow,$othertitle,
1.305 raeburn 6836: 'statustocreate',$rowtotal);
1.224 raeburn 6837: $$rowtotal ++;
6838: }
6839: }
1.240 raeburn 6840: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
6841: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6842: $fieldtitles{'inststatus'} = &mt('Institutional status');
6843: my $rem;
6844: my $numperrow = 2;
6845: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
6846: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 6847: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 6848: '<td class="LC_left_item">'."\n".
6849: '<table><tr><td>'."\n";
6850: for (my $i=0; $i<@fields; $i++) {
6851: $rem = $i%($numperrow);
6852: if ($rem == 0) {
6853: if ($i > 0) {
6854: $datatable .= '</tr>';
6855: }
6856: $datatable .= '<tr>';
6857: }
6858: my $currval;
1.248 raeburn 6859: if (ref($createsettings) eq 'HASH') {
6860: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
6861: $currval = $createsettings->{'shibenv'}{$fields[$i]};
6862: }
1.240 raeburn 6863: }
6864: $datatable .= '<td class="LC_left_item">'.
6865: '<span class="LC_nobreak">'.
6866: '<input type="text" name="shibenv_'.$fields[$i].'" '.
6867: 'value="'.$currval.'" size="10" /> '.
6868: $fieldtitles{$fields[$i]}.'</span></td>';
6869: }
6870: my $colsleft = $numperrow - $rem;
6871: if ($colsleft > 1 ) {
6872: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6873: ' </td>';
6874: } elsif ($colsleft == 1) {
6875: $datatable .= '<td class="LC_left_item"> </td>';
6876: }
6877: $datatable .= '</tr></table></td></tr>';
6878: $$rowtotal ++;
1.224 raeburn 6879: } elsif ($position eq 'middle') {
6880: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 6881: my @posstypes;
1.224 raeburn 6882: if (ref($types) eq 'ARRAY') {
1.302 raeburn 6883: @posstypes = @{$types};
6884: }
6885: unless (grep(/^default$/,@posstypes)) {
6886: push(@posstypes,'default');
6887: }
6888: my %usertypeshash;
6889: if (ref($usertypes) eq 'HASH') {
6890: %usertypeshash = %{$usertypes};
6891: }
6892: $usertypeshash{'default'} = $othertitle;
6893: foreach my $status (@posstypes) {
6894: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
6895: $numinrow,$$rowtotal,\%usertypeshash);
6896: $$rowtotal ++;
1.224 raeburn 6897: }
6898: } else {
1.236 raeburn 6899: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 6900: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 6901: );
6902: my @toggles = sort(keys(%choices));
6903: my %defaultchecked = (
6904: 'cancreate_email' => 'off',
6905: );
1.305 raeburn 6906: my $customclass = 'LC_selfcreate_email';
6907: my $classprefix = 'LC_canmodify_emailusername_';
6908: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 6909: my $display = 'none';
1.305 raeburn 6910: my $rowstyle = 'display:none';
1.236 raeburn 6911: if (grep(/^\Qemail\E$/,@selfcreate)) {
6912: $display = 'block';
1.305 raeburn 6913: $rowstyle = 'display:table-row';
1.236 raeburn 6914: }
1.305 raeburn 6915: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
6916: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6917: \%choices,$$rowtotal,$onclick);
6918: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
6919: $rowstyle);
6920: $$rowtotal ++;
6921: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
6922: $rowstyle);
6923: $$rowtotal ++;
6924: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 6925: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 6926: my ($emailrules,$emailruleorder) =
6927: &Apache::lonnet::inst_userrules($dom,'email');
6928: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6929: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6930: if (ref($types) eq 'ARRAY') {
6931: @posstypes = @{$types};
6932: }
6933: if (@posstypes) {
6934: unless (grep(/^default$/,@posstypes)) {
6935: push(@posstypes,'default');
1.302 raeburn 6936: }
6937: if (ref($usertypes) eq 'HASH') {
6938: %usertypeshash = %{$usertypes};
6939: }
1.305 raeburn 6940: my $currassign;
6941: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
6942: $currassign = {
6943: selfassign => $domdefaults{'inststatusguest'},
6944: };
6945: @ordered = @{$domdefaults{'inststatusguest'}};
6946: } else {
6947: $currassign = { selfassign => [] };
6948: }
6949: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
6950: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
6951: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
6952: $numinrow,$othertitle,'selfassign',
6953: $rowtotal,$onclicktypes,$customclass,
6954: $rowstyle);
6955: $$rowtotal ++;
1.302 raeburn 6956: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 6957: foreach my $status (@posstypes) {
6958: my $css_class;
6959: if ($$rowtotal%2) {
6960: $css_class = 'LC_odd_row ';
6961: }
6962: $css_class .= $customclass;
6963: my $rowid = $optionsprefix.$status;
6964: my $hidden = 1;
6965: my $currstyle = 'display:none';
6966: if (grep(/^\Q$status\E$/,@ordered)) {
6967: $currstyle = $rowstyle;
6968: $hidden = 0;
6969: }
6970: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
6971: $emailrules,$emailruleorder,$settings,$status,$rowid,
6972: $usertypeshash{$status},$css_class,$currstyle,$intdom);
6973: unless ($hidden) {
6974: $$rowtotal ++;
6975: }
1.224 raeburn 6976: }
1.302 raeburn 6977: } else {
1.305 raeburn 6978: my $css_class;
6979: if ($$rowtotal%2) {
6980: $css_class = 'LC_odd_row ';
6981: }
6982: $css_class .= $customclass;
1.302 raeburn 6983: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 6984: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
6985: $emailrules,$emailruleorder,$settings,'default','',
6986: $othertitle,$css_class,$rowstyle,$intdom);
6987: $$rowtotal ++;
1.224 raeburn 6988: }
6989: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 6990: $numinrow = 1;
1.305 raeburn 6991: if (@posstypes) {
6992: foreach my $status (@posstypes) {
6993: my $rowid = $classprefix.$status;
6994: my $datarowstyle = 'display:none';
6995: if (grep(/^\Q$status\E$/,@ordered)) {
6996: $datarowstyle = $rowstyle;
6997: }
6998: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
6999: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7000: $infotitles,$rowid,$customclass,$datarowstyle);
7001: unless ($datarowstyle eq 'display:none') {
7002: $$rowtotal ++;
7003: }
1.224 raeburn 7004: }
1.305 raeburn 7005: } else {
7006: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
7007: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7008: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 7009: }
7010: }
7011: return $datatable;
7012: }
7013:
1.305 raeburn 7014: sub selfcreate_javascript {
7015: return <<"ENDSCRIPT";
7016:
7017: <script type="text/javascript">
7018: // <![CDATA[
7019:
7020: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
7021: var x = document.getElementsByClassName(target);
7022: var insttypes = 0;
7023: var insttypeRegExp = new RegExp(prefix);
7024: if ((x.length != undefined) && (x.length > 0)) {
7025: if (form.elements[radio].length != undefined) {
7026: for (var i=0; i<form.elements[radio].length; i++) {
7027: if (form.elements[radio][i].checked) {
7028: if (form.elements[radio][i].value == 1) {
7029: for (var j=0; j<x.length; j++) {
7030: if (x[j].id == 'undefined') {
7031: x[j].style.display = 'table-row';
7032: } else if (insttypeRegExp.test(x[j].id)) {
7033: insttypes ++;
7034: } else {
7035: x[j].style.display = 'table-row';
7036: }
7037: }
7038: } else {
7039: for (var j=0; j<x.length; j++) {
7040: x[j].style.display = 'none';
7041: }
1.236 raeburn 7042: }
1.305 raeburn 7043: break;
7044: }
7045: }
7046: if (insttypes > 0) {
7047: toggleDataRow(form,checkbox,target,altprefix);
7048: toggleDataRow(form,checkbox,target,prefix,1);
7049: }
7050: }
7051: }
7052: return;
7053: }
7054:
7055: function toggleDataRow(form,checkbox,target,prefix,docount) {
7056: if (form.elements[checkbox].length != undefined) {
7057: var count = 0;
7058: if (docount) {
7059: for (var i=0; i<form.elements[checkbox].length; i++) {
7060: if (form.elements[checkbox][i].checked) {
7061: count ++;
1.236 raeburn 7062: }
1.305 raeburn 7063: }
7064: }
7065: for (var i=0; i<form.elements[checkbox].length; i++) {
7066: var type = form.elements[checkbox][i].value;
7067: if (document.getElementById(prefix+type)) {
7068: if (form.elements[checkbox][i].checked) {
7069: document.getElementById(prefix+type).style.display = 'table-row';
7070: if (count % 2 == 1) {
7071: document.getElementById(prefix+type).className = target+' LC_odd_row';
7072: } else {
7073: document.getElementById(prefix+type).className = target;
1.236 raeburn 7074: }
1.305 raeburn 7075: count ++;
1.236 raeburn 7076: } else {
1.305 raeburn 7077: document.getElementById(prefix+type).style.display = 'none';
7078: }
7079: }
7080: }
7081: }
7082: return;
7083: }
7084:
7085: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
7086: var caller = radio+'_'+status;
7087: if (form.elements[caller].length != undefined) {
7088: for (var i=0; i<form.elements[caller].length; i++) {
7089: if (form.elements[caller][i].checked) {
7090: if (document.getElementById(altprefix+'_inst_'+status)) {
7091: var curr = form.elements[caller][i].value;
7092: if (prefix) {
7093: document.getElementById(prefix+'_'+status).style.display = 'none';
7094: }
7095: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
7096: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
7097: if (curr == 'custom') {
7098: if (prefix) {
7099: document.getElementById(prefix+'_'+status).style.display = 'inline';
7100: }
7101: } else if (curr == 'inst') {
7102: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
7103: } else if (curr == 'noninst') {
7104: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 7105: }
1.305 raeburn 7106: break;
1.236 raeburn 7107: }
7108: }
7109: }
7110: }
7111: }
7112:
1.305 raeburn 7113: // ]]>
7114: </script>
7115:
7116: ENDSCRIPT
7117: }
7118:
7119: sub noninst_users {
7120: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
7121: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
7122: my $class = 'LC_left_item';
7123: if ($css_class) {
7124: $css_class = ' class="'.$css_class.'"';
7125: }
7126: if ($rowid) {
7127: $rowid = ' id="'.$rowid.'"';
7128: }
7129: if ($rowstyle) {
7130: $rowstyle = ' style="'.$rowstyle.'"';
7131: }
7132: my ($output,$description);
7133: if ($type eq 'default') {
7134: $description = &mt('Requests for: [_1]',$typetitle);
7135: } else {
7136: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
7137: }
7138: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
7139: "<td>$description</td>\n".
7140: '<td class="'.$class.'" colspan="2">'.
7141: '<table><tr>';
7142: my %headers = &Apache::lonlocal::texthash(
7143: approve => 'Processing',
7144: email => 'E-mail',
7145: username => 'Username',
7146: );
7147: foreach my $item ('approve','email','username') {
7148: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 7149: }
1.305 raeburn 7150: $output .= '</tr><tr>';
7151: foreach my $item ('approve','email','username') {
1.306 raeburn 7152: $output .= '<td style="vertical-align: top">';
1.305 raeburn 7153: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
7154: if ($item eq 'approve') {
7155: %choices = &Apache::lonlocal::texthash (
7156: automatic => 'Automatically approved',
7157: approval => 'Queued for approval',
7158: );
7159: @options = ('automatic','approval');
7160: $hashref = $processing;
7161: $defoption = 'automatic';
7162: $name = 'cancreate_emailprocess_'.$type;
7163: } elsif ($item eq 'email') {
7164: %choices = &Apache::lonlocal::texthash (
7165: any => 'Any e-mail',
7166: inst => 'Institutional only',
7167: noninst => 'Non-institutional only',
7168: custom => 'Custom restrictions',
7169: );
7170: @options = ('any','inst','noninst');
7171: my $showcustom;
7172: if (ref($emailrules) eq 'HASH') {
7173: if (keys(%{$emailrules}) > 0) {
7174: push(@options,'custom');
7175: $showcustom = 'cancreate_emailrule';
7176: if (ref($settings) eq 'HASH') {
7177: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
7178: foreach my $rule (@{$settings->{'email_rule'}}) {
7179: if (exists($emailrules->{$rule})) {
7180: $hascustom ++;
7181: }
7182: }
7183: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
7184: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
7185: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
7186: if (exists($emailrules->{$rule})) {
7187: $hascustom ++;
7188: }
7189: }
7190: }
7191: }
7192: }
7193: }
7194: }
7195: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
7196: "'cancreate_emaildomain','$type'".');"';
7197: $hashref = $emailoptions;
7198: $defoption = 'any';
7199: $name = 'cancreate_emailoptions_'.$type;
7200: } elsif ($item eq 'username') {
7201: %choices = &Apache::lonlocal::texthash (
7202: all => 'Same as e-mail',
7203: first => 'Omit @domain',
7204: free => 'Free to choose',
7205: );
7206: @options = ('all','first','free');
7207: $hashref = $emailverified;
7208: $defoption = 'all';
7209: $name = 'cancreate_usernameoptions_'.$type;
7210: }
7211: foreach my $option (@options) {
7212: my $checked;
7213: if (ref($hashref) eq 'HASH') {
7214: if ($type eq '') {
7215: if (!exists($hashref->{'default'})) {
7216: if ($option eq $defoption) {
7217: $checked = ' checked="checked"';
7218: }
7219: } else {
7220: if ($hashref->{'default'} eq $option) {
7221: $checked = ' checked="checked"';
7222: }
1.303 raeburn 7223: }
7224: } else {
1.305 raeburn 7225: if (!exists($hashref->{$type})) {
7226: if ($option eq $defoption) {
7227: $checked = ' checked="checked"';
7228: }
7229: } else {
7230: if ($hashref->{$type} eq $option) {
7231: $checked = ' checked="checked"';
7232: }
1.303 raeburn 7233: }
7234: }
1.305 raeburn 7235: } elsif (($item eq 'email') && ($hascustom)) {
7236: if ($option eq 'custom') {
7237: $checked = ' checked="checked"';
7238: }
7239: } elsif ($option eq $defoption) {
7240: $checked = ' checked="checked"';
7241: }
7242: $output .= '<span class="LC_nobreak"><label>'.
7243: '<input type="radio" name="'.$name.'"'.
7244: $checked.' value="'.$option.'"'.$onclick.' />'.
7245: $choices{$option}.'</label></span><br />';
7246: if ($item eq 'email') {
7247: if ($option eq 'custom') {
7248: my $id = 'cancreate_emailrule_'.$type;
7249: my $display = 'none';
7250: if ($checked) {
7251: $display = 'inline';
1.303 raeburn 7252: }
1.305 raeburn 7253: my $numinrow = 2;
7254: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
7255: '<legend>'.&mt('Disallow').'</legend><table>'.
7256: &user_formats_row('email',$settings,$emailrules,
7257: $emailruleorder,$numinrow,'',$type);
7258: '</table></fieldset>';
7259: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
7260: my %text = &Apache::lonlocal::texthash (
7261: inst => 'must end:',
7262: noninst => 'cannot end:',
7263: );
7264: my $value;
7265: if (ref($emaildomain) eq 'HASH') {
7266: if (ref($emaildomain->{$type}) eq 'HASH') {
7267: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 7268: }
7269: }
1.305 raeburn 7270: if ($value eq '') {
7271: $value = '@'.$intdom;
7272: }
7273: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
7274: my $display = 'none';
7275: if ($checked) {
7276: $display = 'inline';
7277: }
7278: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
7279: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
7280: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
7281: '</div>';
1.303 raeburn 7282: }
7283: }
7284: }
1.305 raeburn 7285: $output .= '</td>'."\n";
1.303 raeburn 7286: }
1.305 raeburn 7287: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 7288: return $output;
7289: }
7290:
1.165 raeburn 7291: sub captcha_choice {
1.305 raeburn 7292: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 7293: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
7294: $vertext,$currver);
1.165 raeburn 7295: my %lt = &captcha_phrases();
7296: $keyentry = 'hidden';
7297: if ($context eq 'cancreate') {
1.224 raeburn 7298: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 7299: } elsif ($context eq 'login') {
7300: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 7301: }
7302: if (ref($settings) eq 'HASH') {
7303: if ($settings->{'captcha'}) {
7304: $checked{$settings->{'captcha'}} = ' checked="checked"';
7305: } else {
7306: $checked{'original'} = ' checked="checked"';
7307: }
7308: if ($settings->{'captcha'} eq 'recaptcha') {
7309: $pubtext = $lt{'pub'};
7310: $privtext = $lt{'priv'};
7311: $keyentry = 'text';
1.269 raeburn 7312: $vertext = $lt{'ver'};
7313: $currver = $settings->{'recaptchaversion'};
7314: if ($currver ne '2') {
7315: $currver = 1;
7316: }
1.165 raeburn 7317: }
7318: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
7319: $currpub = $settings->{'recaptchakeys'}{'public'};
7320: $currpriv = $settings->{'recaptchakeys'}{'private'};
7321: }
7322: } else {
7323: $checked{'original'} = ' checked="checked"';
7324: }
1.305 raeburn 7325: my $css_class;
7326: if ($itemcount%2) {
7327: $css_class = 'LC_odd_row';
7328: }
7329: if ($customcss) {
7330: $css_class .= " $customcss";
7331: }
7332: $css_class =~ s/^\s+//;
7333: if ($css_class) {
7334: $css_class = ' class="'.$css_class.'"';
7335: }
7336: if ($rowstyle) {
7337: $css_class .= ' style="'.$rowstyle.'"';
7338: }
1.169 raeburn 7339: my $output = '<tr'.$css_class.'>'.
7340: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 7341: '<table><tr><td>'."\n";
7342: foreach my $option ('original','recaptcha','notused') {
7343: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
7344: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
7345: $lt{$option}.'</label></span>';
7346: unless ($option eq 'notused') {
7347: $output .= (' 'x2)."\n";
7348: }
7349: }
7350: #
7351: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
7352: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 7353: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 7354: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 7355: #
1.165 raeburn 7356: $output .= '</td></tr>'."\n".
1.305 raeburn 7357: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 7358: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
7359: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
7360: $currpub.'" size="40" /></span><br />'."\n".
7361: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
7362: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 7363: $currpriv.'" size="40" /></span><br />'.
7364: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
7365: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
7366: $currver.'" size="3" /></span><br />'.
7367: '</td></tr></table>'."\n".
1.165 raeburn 7368: '</td></tr>';
7369: return $output;
7370: }
7371:
1.32 raeburn 7372: sub user_formats_row {
1.305 raeburn 7373: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 7374: my $output;
7375: my %text = (
7376: 'username' => 'new usernames',
7377: 'id' => 'IDs',
7378: );
1.305 raeburn 7379: unless ($type eq 'email') {
7380: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
7381: $output = '<tr '.$css_class.'>'.
7382: '<td><span class="LC_nobreak">'.
7383: &mt("Format rules to check for $text{$type}: ").
7384: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 7385: }
1.27 raeburn 7386: my $rem;
7387: if (ref($ruleorder) eq 'ARRAY') {
7388: for (my $i=0; $i<@{$ruleorder}; $i++) {
7389: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
7390: my $rem = $i%($numinrow);
7391: if ($rem == 0) {
7392: if ($i > 0) {
7393: $output .= '</tr>';
7394: }
7395: $output .= '<tr>';
7396: }
7397: my $check = ' ';
1.39 raeburn 7398: if (ref($settings) eq 'HASH') {
7399: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
7400: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
7401: $check = ' checked="checked" ';
7402: }
1.305 raeburn 7403: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
7404: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
7405: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
7406: $check = ' checked="checked" ';
7407: }
7408: }
1.27 raeburn 7409: }
7410: }
1.305 raeburn 7411: my $name = $type.'_rule';
7412: if ($type eq 'email') {
7413: $name .= '_'.$status;
7414: }
1.27 raeburn 7415: $output .= '<td class="LC_left_item">'.
7416: '<span class="LC_nobreak"><label>'.
1.311 raeburn 7417: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 7418: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
7419: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
7420: }
7421: }
7422: $rem = @{$ruleorder}%($numinrow);
7423: }
1.305 raeburn 7424: my $colsleft;
7425: if ($rem) {
7426: $colsleft = $numinrow - $rem;
7427: }
1.27 raeburn 7428: if ($colsleft > 1 ) {
7429: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7430: ' </td>';
7431: } elsif ($colsleft == 1) {
7432: $output .= '<td class="LC_left_item"> </td>';
7433: }
1.305 raeburn 7434: $output .= '</tr></table>';
7435: unless ($type eq 'email') {
7436: $output .= '</td></tr>';
7437: }
1.27 raeburn 7438: return $output;
7439: }
7440:
1.34 raeburn 7441: sub usercreation_types {
7442: my %lt = &Apache::lonlocal::texthash (
7443: author => 'When adding a co-author',
7444: course => 'When adding a user to a course',
1.100 raeburn 7445: requestcrs => 'When requesting a course',
1.34 raeburn 7446: any => 'Any',
7447: official => 'Institutional only ',
7448: unofficial => 'Non-institutional only',
7449: none => 'None',
7450: );
7451: return %lt;
1.48 raeburn 7452: }
1.34 raeburn 7453:
1.224 raeburn 7454: sub selfcreation_types {
7455: my %lt = &Apache::lonlocal::texthash (
7456: selfcreate => 'User creates own account',
7457: any => 'Any',
7458: official => 'Institutional only ',
7459: unofficial => 'Non-institutional only',
7460: email => 'E-mail address',
7461: login => 'Institutional Login',
7462: sso => 'SSO',
7463: );
7464: }
7465:
1.28 raeburn 7466: sub authtype_names {
7467: my %lt = &Apache::lonlocal::texthash(
7468: int => 'Internal',
7469: krb4 => 'Kerberos 4',
7470: krb5 => 'Kerberos 5',
7471: loc => 'Local',
1.325 raeburn 7472: lti => 'LTI',
1.28 raeburn 7473: );
7474: return %lt;
7475: }
7476:
7477: sub context_names {
7478: my %context_title = &Apache::lonlocal::texthash(
7479: author => 'Creating users when an Author',
7480: course => 'Creating users when in a course',
7481: domain => 'Creating users when a Domain Coordinator',
7482: );
7483: return %context_title;
7484: }
7485:
1.33 raeburn 7486: sub print_usermodification {
7487: my ($position,$dom,$settings,$rowtotal) = @_;
7488: my $numinrow = 4;
7489: my ($context,$datatable,$rowcount);
7490: if ($position eq 'top') {
7491: $rowcount = 0;
7492: $context = 'author';
7493: foreach my $role ('ca','aa') {
7494: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7495: $numinrow,$rowcount);
7496: $$rowtotal ++;
7497: $rowcount ++;
7498: }
1.230 raeburn 7499: } elsif ($position eq 'bottom') {
1.33 raeburn 7500: $context = 'course';
7501: $rowcount = 0;
7502: foreach my $role ('st','ep','ta','in','cr') {
7503: $datatable .= &modifiable_userdata_row($context,$role,$settings,
7504: $numinrow,$rowcount);
7505: $$rowtotal ++;
7506: $rowcount ++;
7507: }
7508: }
7509: return $datatable;
7510: }
7511:
1.43 raeburn 7512: sub print_defaults {
1.236 raeburn 7513: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 7514: my $rownum = 0;
1.294 raeburn 7515: my ($datatable,$css_class,$titles);
7516: unless ($position eq 'bottom') {
7517: $titles = &defaults_titles($dom);
7518: }
1.236 raeburn 7519: if ($position eq 'top') {
7520: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
7521: 'datelocale_def','portal_def');
7522: my %defaults;
7523: if (ref($settings) eq 'HASH') {
7524: %defaults = %{$settings};
1.43 raeburn 7525: } else {
1.236 raeburn 7526: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
7527: foreach my $item (@items) {
7528: $defaults{$item} = $domdefaults{$item};
7529: }
1.43 raeburn 7530: }
1.236 raeburn 7531: foreach my $item (@items) {
7532: if ($rownum%2) {
7533: $css_class = '';
7534: } else {
7535: $css_class = ' class="LC_odd_row" ';
7536: }
7537: $datatable .= '<tr'.$css_class.'>'.
7538: '<td><span class="LC_nobreak">'.$titles->{$item}.
7539: '</span></td><td class="LC_right_item" colspan="3">';
7540: if ($item eq 'auth_def') {
1.325 raeburn 7541: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 7542: my %shortauth = (
7543: internal => 'int',
7544: krb4 => 'krb4',
7545: krb5 => 'krb5',
1.325 raeburn 7546: localauth => 'loc',
7547: lti => 'lti',
1.236 raeburn 7548: );
7549: my %authnames = &authtype_names();
7550: foreach my $auth (@authtypes) {
7551: my $checked = ' ';
7552: if ($defaults{$item} eq $auth) {
7553: $checked = ' checked="checked" ';
7554: }
7555: $datatable .= '<label><input type="radio" name="'.$item.
7556: '" value="'.$auth.'"'.$checked.'/>'.
7557: $authnames{$shortauth{$auth}}.'</label> ';
7558: }
7559: } elsif ($item eq 'timezone_def') {
7560: my $includeempty = 1;
7561: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
7562: } elsif ($item eq 'datelocale_def') {
7563: my $includeempty = 1;
7564: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
7565: } elsif ($item eq 'lang_def') {
1.263 raeburn 7566: my $includeempty = 1;
7567: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 7568: } else {
7569: my $size;
7570: if ($item eq 'portal_def') {
7571: $size = ' size="25"';
7572: }
7573: $datatable .= '<input type="text" name="'.$item.'" value="'.
7574: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 7575: }
1.236 raeburn 7576: $datatable .= '</td></tr>';
7577: $rownum ++;
7578: }
1.294 raeburn 7579: } elsif ($position eq 'middle') {
7580: my @items = ('intauth_cost','intauth_check','intauth_switch');
7581: my %defaults;
7582: if (ref($settings) eq 'HASH') {
7583: %defaults = %{$settings};
7584: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
7585: $defaults{'intauth_cost'} = 10;
7586: }
7587: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
7588: $defaults{'intauth_check'} = 0;
7589: }
7590: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
7591: $defaults{'intauth_switch'} = 0;
7592: }
7593: } else {
7594: %defaults = (
7595: 'intauth_cost' => 10,
7596: 'intauth_check' => 0,
7597: 'intauth_switch' => 0,
7598: );
7599: }
7600: foreach my $item (@items) {
7601: if ($rownum%2) {
7602: $css_class = '';
7603: } else {
7604: $css_class = ' class="LC_odd_row" ';
7605: }
7606: $datatable .= '<tr'.$css_class.'>'.
7607: '<td><span class="LC_nobreak">'.$titles->{$item}.
7608: '</span></td><td class="LC_left_item" colspan="3">';
7609: if ($item eq 'intauth_switch') {
7610: my @options = (0,1,2);
7611: my %optiondesc = &Apache::lonlocal::texthash (
7612: 0 => 'No',
7613: 1 => 'Yes',
7614: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
7615: );
7616: $datatable .= '<table width="100%">';
7617: foreach my $option (@options) {
7618: my $checked = ' ';
7619: if ($defaults{$item} eq $option) {
7620: $checked = ' checked="checked"';
7621: }
7622: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7623: '<label><input type="radio" name="'.$item.
7624: '" value="'.$option.'"'.$checked.' />'.
7625: $optiondesc{$option}.'</label></span></td></tr>';
7626: }
7627: $datatable .= '</table>';
7628: } elsif ($item eq 'intauth_check') {
7629: my @options = (0,1,2);
7630: my %optiondesc = &Apache::lonlocal::texthash (
7631: 0 => 'No',
7632: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
7633: 2 => 'Yes, disallow login if stored cost is less than domain default',
7634: );
7635: $datatable .= '<table wisth="100%">';
7636: foreach my $option (@options) {
7637: my $checked = ' ';
7638: my $onclick;
7639: if ($defaults{$item} eq $option) {
7640: $checked = ' checked="checked"';
7641: }
7642: if ($option == 2) {
7643: $onclick = ' onclick="javascript:warnIntAuth(this);"';
7644: }
7645: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7646: '<label><input type="radio" name="'.$item.
7647: '" value="'.$option.'"'.$checked.$onclick.' />'.
7648: $optiondesc{$option}.'</label></span></td></tr>';
7649: }
7650: $datatable .= '</table>';
7651: } else {
7652: $datatable .= '<input type="text" name="'.$item.'" value="'.
7653: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
7654: }
7655: $datatable .= '</td></tr>';
7656: $rownum ++;
7657: }
1.236 raeburn 7658: } else {
1.294 raeburn 7659: my %defaults;
1.236 raeburn 7660: if (ref($settings) eq 'HASH') {
1.305 raeburn 7661: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.236 raeburn 7662: my $maxnum = @{$settings->{'inststatusorder'}};
7663: for (my $i=0; $i<$maxnum; $i++) {
7664: $css_class = $rownum%2?' class="LC_odd_row"':'';
7665: my $item = $settings->{'inststatusorder'}->[$i];
7666: my $title = $settings->{'inststatustypes'}->{$item};
7667: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
7668: $datatable .= '<tr'.$css_class.'>'.
7669: '<td><span class="LC_nobreak">'.
7670: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
7671: for (my $k=0; $k<=$maxnum; $k++) {
7672: my $vpos = $k+1;
7673: my $selstr;
7674: if ($k == $i) {
7675: $selstr = ' selected="selected" ';
7676: }
7677: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7678: }
7679: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
7680: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
7681: &mt('delete').'</span></td>'.
1.305 raeburn 7682: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed:').
1.236 raeburn 7683: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.305 raeburn 7684: '</span></td></tr>';
1.236 raeburn 7685: }
7686: $css_class = $rownum%2?' class="LC_odd_row"':'';
7687: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
7688: $datatable .= '<tr '.$css_class.'>'.
7689: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
7690: for (my $k=0; $k<=$maxnum; $k++) {
7691: my $vpos = $k+1;
7692: my $selstr;
7693: if ($k == $maxnum) {
7694: $selstr = ' selected="selected" ';
7695: }
7696: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7697: }
7698: $datatable .= '</select> '.&mt('Internal ID:').
1.263 raeburn 7699: '<input type="text" size="10" name="addinststatus" value="" />'.
1.236 raeburn 7700: ' '.&mt('(new)').
1.305 raeburn 7701: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.236 raeburn 7702: &mt('Name displayed:').
7703: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
7704: '</tr>'."\n";
7705: $rownum ++;
1.141 raeburn 7706: }
1.43 raeburn 7707: }
7708: }
7709: $$rowtotal += $rownum;
7710: return $datatable;
7711: }
7712:
1.168 raeburn 7713: sub get_languages_hash {
7714: my %langchoices;
7715: foreach my $id (&Apache::loncommon::languageids()) {
7716: my $code = &Apache::loncommon::supportedlanguagecode($id);
7717: if ($code ne '') {
7718: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
7719: }
7720: }
7721: return %langchoices;
7722: }
7723:
1.43 raeburn 7724: sub defaults_titles {
1.141 raeburn 7725: my ($dom) = @_;
1.43 raeburn 7726: my %titles = &Apache::lonlocal::texthash (
7727: 'auth_def' => 'Default authentication type',
7728: 'auth_arg_def' => 'Default authentication argument',
7729: 'lang_def' => 'Default language',
1.54 raeburn 7730: 'timezone_def' => 'Default timezone',
1.68 raeburn 7731: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 7732: 'portal_def' => 'Portal/Default URL',
1.294 raeburn 7733: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
7734: 'intauth_check' => 'Check bcrypt cost if authenticated',
7735: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 7736: );
1.141 raeburn 7737: if ($dom) {
7738: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
7739: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
7740: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
7741: $protocol = 'http' if ($protocol ne 'https');
7742: if ($uint_dom) {
7743: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
7744: $uint_dom);
7745: }
7746: }
1.43 raeburn 7747: return (\%titles);
7748: }
7749:
1.46 raeburn 7750: sub print_scantronformat {
7751: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
7752: my $itemcount = 1;
1.60 raeburn 7753: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
7754: %confhash);
1.46 raeburn 7755: my $switchserver = &check_switchserver($dom,$confname);
7756: my %lt = &Apache::lonlocal::texthash (
1.95 www 7757: default => 'Default bubblesheet format file error',
7758: custom => 'Custom bubblesheet format file error',
1.46 raeburn 7759: );
7760: my %scantronfiles = (
7761: default => 'default.tab',
7762: custom => 'custom.tab',
7763: );
7764: foreach my $key (keys(%scantronfiles)) {
7765: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
7766: .$scantronfiles{$key};
7767: }
7768: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
7769: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
7770: if (!$switchserver) {
7771: my $servadm = $r->dir_config('lonAdmEMail');
7772: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
7773: if ($configuserok eq 'ok') {
7774: if ($author_ok eq 'ok') {
7775: my %legacyfile = (
7776: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
7777: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
7778: );
7779: my %md5chk;
7780: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 7781: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
7782: chomp($md5chk{$type});
1.46 raeburn 7783: }
7784: if ($md5chk{'default'} ne $md5chk{'custom'}) {
7785: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 7786: ($scantronurls{$type},my $error) =
1.46 raeburn 7787: &legacy_scantronformat($r,$dom,$confname,
7788: $type,$legacyfile{$type},
7789: $scantronurls{$type},
7790: $scantronfiles{$type});
1.60 raeburn 7791: if ($error ne '') {
7792: $error{$type} = $error;
7793: }
7794: }
7795: if (keys(%error) == 0) {
7796: $is_custom = 1;
7797: $confhash{'scantron'}{'scantronformat'} =
7798: $scantronurls{'custom'};
7799: my $putresult =
7800: &Apache::lonnet::put_dom('configuration',
7801: \%confhash,$dom);
7802: if ($putresult ne 'ok') {
7803: $error{'custom'} =
7804: '<span class="LC_error">'.
7805: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7806: }
1.46 raeburn 7807: }
7808: } else {
1.60 raeburn 7809: ($scantronurls{'default'},my $error) =
1.46 raeburn 7810: &legacy_scantronformat($r,$dom,$confname,
7811: 'default',$legacyfile{'default'},
7812: $scantronurls{'default'},
7813: $scantronfiles{'default'});
1.60 raeburn 7814: if ($error eq '') {
7815: $confhash{'scantron'}{'scantronformat'} = '';
7816: my $putresult =
7817: &Apache::lonnet::put_dom('configuration',
7818: \%confhash,$dom);
7819: if ($putresult ne 'ok') {
7820: $error{'default'} =
7821: '<span class="LC_error">'.
7822: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
7823: }
7824: } else {
7825: $error{'default'} = $error;
7826: }
1.46 raeburn 7827: }
7828: }
7829: }
7830: } else {
1.95 www 7831: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 7832: }
7833: }
7834: if (ref($settings) eq 'HASH') {
7835: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
7836: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
7837: if ((!@info) || ($info[0] eq 'no_such_dir')) {
7838: $scantronurl = '';
7839: } else {
7840: $scantronurl = $settings->{'scantronformat'};
7841: }
7842: $is_custom = 1;
7843: } else {
7844: $scantronurl = $scantronurls{'default'};
7845: }
7846: } else {
1.60 raeburn 7847: if ($is_custom) {
7848: $scantronurl = $scantronurls{'custom'};
7849: } else {
7850: $scantronurl = $scantronurls{'default'};
7851: }
1.46 raeburn 7852: }
7853: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7854: $datatable .= '<tr'.$css_class.'>';
7855: if (!$is_custom) {
1.65 raeburn 7856: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
7857: '<span class="LC_nobreak">';
1.46 raeburn 7858: if ($scantronurl) {
1.199 raeburn 7859: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
7860: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 7861: } else {
7862: $datatable = &mt('File unavailable for display');
7863: }
1.65 raeburn 7864: $datatable .= '</span></td>';
1.60 raeburn 7865: if (keys(%error) == 0) {
1.306 raeburn 7866: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 7867: if (!$switchserver) {
7868: $datatable .= &mt('Upload:').'<br />';
7869: }
7870: } else {
7871: my $errorstr;
7872: foreach my $key (sort(keys(%error))) {
7873: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7874: }
7875: $datatable .= '<td>'.$errorstr;
7876: }
1.46 raeburn 7877: } else {
7878: if (keys(%error) > 0) {
7879: my $errorstr;
7880: foreach my $key (sort(keys(%error))) {
7881: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7882: }
1.60 raeburn 7883: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 7884: } elsif ($scantronurl) {
1.199 raeburn 7885: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
7886: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 7887: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 7888: $link.
7889: '<label><input type="checkbox" name="scantronformat_del"'.
7890: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 7891: '<td><span class="LC_nobreak"> '.
7892: &mt('Replace:').'</span><br />';
1.46 raeburn 7893: }
7894: }
7895: if (keys(%error) == 0) {
7896: if ($switchserver) {
7897: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
7898: } else {
1.65 raeburn 7899: $datatable .='<span class="LC_nobreak"> '.
7900: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 7901: }
7902: }
7903: $datatable .= '</td></tr>';
7904: $$rowtotal ++;
7905: return $datatable;
7906: }
7907:
7908: sub legacy_scantronformat {
7909: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
7910: my ($url,$error);
7911: my @statinfo = &Apache::lonnet::stat_file($newurl);
7912: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
7913: (my $result,$url) =
7914: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
7915: '','',$newfile);
7916: if ($result ne 'ok') {
1.130 raeburn 7917: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 7918: }
7919: }
7920: return ($url,$error);
7921: }
1.43 raeburn 7922:
1.49 raeburn 7923: sub print_coursecategories {
1.57 raeburn 7924: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
7925: my $datatable;
7926: if ($position eq 'top') {
1.238 raeburn 7927: my (%checked);
7928: my @catitems = ('unauth','auth');
7929: my @cattypes = ('std','domonly','codesrch','none');
7930: $checked{'unauth'} = 'std';
7931: $checked{'auth'} = 'std';
7932: if (ref($settings) eq 'HASH') {
7933: foreach my $type (@cattypes) {
7934: if ($type eq $settings->{'unauth'}) {
7935: $checked{'unauth'} = $type;
7936: }
7937: if ($type eq $settings->{'auth'}) {
7938: $checked{'auth'} = $type;
7939: }
7940: }
7941: }
7942: my %lt = &Apache::lonlocal::texthash (
7943: unauth => 'Catalog type for unauthenticated users',
7944: auth => 'Catalog type for authenticated users',
7945: none => 'No catalog',
7946: std => 'Standard catalog',
7947: domonly => 'Domain-only catalog',
7948: codesrch => "Code search form",
7949: );
7950: my $itemcount = 0;
7951: foreach my $item (@catitems) {
7952: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
7953: $datatable .= '<tr '.$css_class.'>'.
7954: '<td>'.$lt{$item}.'</td>'.
7955: '<td class="LC_right_item"><span class="LC_nobreak">';
7956: foreach my $type (@cattypes) {
7957: my $ischecked;
7958: if ($checked{$item} eq $type) {
7959: $ischecked=' checked="checked"';
7960: }
7961: $datatable .= '<label>'.
7962: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
7963: ' />'.$lt{$type}.'</label> ';
7964: }
7965: $datatable .= '</td></tr>';
7966: $itemcount ++;
7967: }
7968: $$rowtotal += $itemcount;
7969: } elsif ($position eq 'middle') {
1.57 raeburn 7970: my $toggle_cats_crs = ' ';
7971: my $toggle_cats_dom = ' checked="checked" ';
7972: my $can_cat_crs = ' ';
7973: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 7974: my $toggle_catscomm_comm = ' ';
7975: my $toggle_catscomm_dom = ' checked="checked" ';
7976: my $can_catcomm_comm = ' ';
7977: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 7978: my $toggle_catsplace_place = ' ';
7979: my $toggle_catsplace_dom = ' checked="checked" ';
7980: my $can_catplace_place = ' ';
7981: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 7982:
1.57 raeburn 7983: if (ref($settings) eq 'HASH') {
7984: if ($settings->{'togglecats'} eq 'crs') {
7985: $toggle_cats_crs = $toggle_cats_dom;
7986: $toggle_cats_dom = ' ';
7987: }
7988: if ($settings->{'categorize'} eq 'crs') {
7989: $can_cat_crs = $can_cat_dom;
7990: $can_cat_dom = ' ';
7991: }
1.120 raeburn 7992: if ($settings->{'togglecatscomm'} eq 'comm') {
7993: $toggle_catscomm_comm = $toggle_catscomm_dom;
7994: $toggle_catscomm_dom = ' ';
7995: }
7996: if ($settings->{'categorizecomm'} eq 'comm') {
7997: $can_catcomm_comm = $can_catcomm_dom;
7998: $can_catcomm_dom = ' ';
7999: }
1.272 raeburn 8000: if ($settings->{'togglecatsplace'} eq 'place') {
8001: $toggle_catsplace_place = $toggle_catsplace_dom;
8002: $toggle_catsplace_dom = ' ';
8003: }
8004: if ($settings->{'categorizeplace'} eq 'place') {
8005: $can_catplace_place = $can_catplace_dom;
8006: $can_catplace_dom = ' ';
8007: }
1.57 raeburn 8008: }
8009: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 8010: togglecats => 'Show/Hide a course in catalog',
8011: togglecatscomm => 'Show/Hide a community in catalog',
8012: togglecatsplace => 'Show/Hide a placement test in catalog',
8013: categorize => 'Assign a category to a course',
8014: categorizecomm => 'Assign a category to a community',
8015: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 8016: );
8017: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 8018: dom => 'Set in Domain',
8019: crs => 'Set in Course',
8020: comm => 'Set in Community',
8021: place => 'Set in Placement Test',
1.57 raeburn 8022: );
8023: $datatable = '<tr class="LC_odd_row">'.
8024: '<td>'.$title{'togglecats'}.'</td>'.
8025: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8026: '<input type="radio" name="togglecats"'.
8027: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8028: '<label><input type="radio" name="togglecats"'.
8029: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
8030: '</tr><tr>'.
8031: '<td>'.$title{'categorize'}.'</td>'.
8032: '<td class="LC_right_item"><span class="LC_nobreak">'.
8033: '<label><input type="radio" name="categorize"'.
8034: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8035: '<label><input type="radio" name="categorize"'.
8036: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 8037: '</tr><tr class="LC_odd_row">'.
8038: '<td>'.$title{'togglecatscomm'}.'</td>'.
8039: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8040: '<input type="radio" name="togglecatscomm"'.
8041: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8042: '<label><input type="radio" name="togglecatscomm"'.
8043: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
8044: '</tr><tr>'.
8045: '<td>'.$title{'categorizecomm'}.'</td>'.
8046: '<td class="LC_right_item"><span class="LC_nobreak">'.
8047: '<label><input type="radio" name="categorizecomm"'.
8048: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8049: '<label><input type="radio" name="categorizecomm"'.
8050: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.272 raeburn 8051: '</tr><tr>'.
8052: '<td>'.$title{'togglecatsplace'}.'</td>'.
8053: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8054: '<input type="radio" name="togglecatsplace"'.
8055: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8056: '<label><input type="radio" name="togglecatscomm"'.
8057: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
8058: '</tr><tr>'.
8059: '<td>'.$title{'categorizeplace'}.'</td>'.
8060: '<td class="LC_right_item"><span class="LC_nobreak">'.
8061: '<label><input type="radio" name="categorizeplace"'.
8062: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8063: '<label><input type="radio" name="categorizeplace"'.
8064: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 8065: '</tr>';
1.272 raeburn 8066: $$rowtotal += 6;
1.57 raeburn 8067: } else {
8068: my $css_class;
8069: my $itemcount = 1;
8070: my $cathash;
8071: if (ref($settings) eq 'HASH') {
8072: $cathash = $settings->{'cats'};
8073: }
8074: if (ref($cathash) eq 'HASH') {
8075: my (@cats,@trails,%allitems,%idx,@jsarray);
8076: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
8077: \%allitems,\%idx,\@jsarray);
8078: my $maxdepth = scalar(@cats);
8079: my $colattrib = '';
8080: if ($maxdepth > 2) {
8081: $colattrib = ' colspan="2" ';
8082: }
8083: my @path;
8084: if (@cats > 0) {
8085: if (ref($cats[0]) eq 'ARRAY') {
8086: my $numtop = @{$cats[0]};
8087: my $maxnum = $numtop;
1.120 raeburn 8088: my %default_names = (
8089: instcode => &mt('Official courses'),
8090: communities => &mt('Communities'),
1.272 raeburn 8091: placement => &mt('Placement Tests'),
1.120 raeburn 8092: );
8093:
8094: if ((!grep(/^instcode$/,@{$cats[0]})) ||
8095: ($cathash->{'instcode::0'} eq '') ||
8096: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 8097: ($cathash->{'communities::0'} eq '') ||
8098: (!grep(/^placement$/,@{$cats[0]})) ||
8099: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 8100: $maxnum ++;
8101: }
8102: my $lastidx;
8103: for (my $i=0; $i<$numtop; $i++) {
8104: my $parent = $cats[0][$i];
8105: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8106: my $item = &escape($parent).'::0';
8107: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
8108: $lastidx = $idx{$item};
8109: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
8110: .'<select name="'.$item.'"'.$chgstr.'>';
8111: for (my $k=0; $k<=$maxnum; $k++) {
8112: my $vpos = $k+1;
8113: my $selstr;
8114: if ($k == $i) {
8115: $selstr = ' selected="selected" ';
8116: }
8117: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8118: }
1.214 raeburn 8119: $datatable .= '</select></span></td><td>';
1.272 raeburn 8120: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 8121: $datatable .= '<span class="LC_nobreak">'
8122: .$default_names{$parent}.'</span>';
8123: if ($parent eq 'instcode') {
8124: $datatable .= '<br /><span class="LC_nobreak">('
8125: .&mt('with institutional codes')
8126: .')</span></td><td'.$colattrib.'>';
8127: } else {
8128: $datatable .= '<table><tr><td>';
8129: }
8130: $datatable .= '<span class="LC_nobreak">'
8131: .'<label><input type="radio" name="'
8132: .$parent.'" value="1" checked="checked" />'
8133: .&mt('Display').'</label>';
8134: if ($parent eq 'instcode') {
8135: $datatable .= ' ';
8136: } else {
8137: $datatable .= '</span></td></tr><tr><td>'
8138: .'<span class="LC_nobreak">';
8139: }
8140: $datatable .= '<label><input type="radio" name="'
8141: .$parent.'" value="0" />'
8142: .&mt('Do not display').'</label></span>';
1.272 raeburn 8143: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 8144: $datatable .= '</td></tr></table>';
8145: }
8146: $datatable .= '</td>';
1.57 raeburn 8147: } else {
8148: $datatable .= $parent
1.214 raeburn 8149: .' <span class="LC_nobreak"><label>'
8150: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 8151: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
8152: }
8153: my $depth = 1;
8154: push(@path,$parent);
8155: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
8156: pop(@path);
8157: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
8158: $itemcount ++;
8159: }
1.48 raeburn 8160: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 8161: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
8162: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 8163: for (my $k=0; $k<=$maxnum; $k++) {
8164: my $vpos = $k+1;
8165: my $selstr;
1.57 raeburn 8166: if ($k == $numtop) {
1.48 raeburn 8167: $selstr = ' selected="selected" ';
8168: }
8169: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8170: }
1.59 bisitz 8171: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 8172: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
8173: .'</tr>'."\n";
1.48 raeburn 8174: $itemcount ++;
1.272 raeburn 8175: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 8176: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
8177: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8178: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
8179: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
8180: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
8181: for (my $k=0; $k<=$maxnum; $k++) {
8182: my $vpos = $k+1;
8183: my $selstr;
8184: if ($k == $maxnum) {
8185: $selstr = ' selected="selected" ';
8186: }
8187: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 8188: }
1.120 raeburn 8189: $datatable .= '</select></span></td>'.
8190: '<td><span class="LC_nobreak">'.
8191: $default_names{$default}.'</span>';
8192: if ($default eq 'instcode') {
8193: $datatable .= '<br /><span class="LC_nobreak">('
8194: .&mt('with institutional codes').')</span>';
8195: }
8196: $datatable .= '</td>'
8197: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
8198: .&mt('Display').'</label> '
8199: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
8200: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 8201: }
8202: }
8203: }
1.57 raeburn 8204: } else {
8205: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 8206: }
8207: } else {
1.238 raeburn 8208: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 8209: .&initialize_categories($itemcount);
1.48 raeburn 8210: }
1.57 raeburn 8211: $$rowtotal += $itemcount;
1.48 raeburn 8212: }
8213: return $datatable;
8214: }
8215:
1.69 raeburn 8216: sub print_serverstatuses {
8217: my ($dom,$settings,$rowtotal) = @_;
8218: my $datatable;
8219: my @pages = &serverstatus_pages();
8220: my (%namedaccess,%machineaccess);
8221: foreach my $type (@pages) {
8222: $namedaccess{$type} = '';
8223: $machineaccess{$type}= '';
8224: }
8225: if (ref($settings) eq 'HASH') {
8226: foreach my $type (@pages) {
8227: if (exists($settings->{$type})) {
8228: if (ref($settings->{$type}) eq 'HASH') {
8229: foreach my $key (keys(%{$settings->{$type}})) {
8230: if ($key eq 'namedusers') {
8231: $namedaccess{$type} = $settings->{$type}->{$key};
8232: } elsif ($key eq 'machines') {
8233: $machineaccess{$type} = $settings->{$type}->{$key};
8234: }
8235: }
8236: }
8237: }
8238: }
8239: }
1.81 raeburn 8240: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 8241: my $rownum = 0;
8242: my $css_class;
8243: foreach my $type (@pages) {
8244: $rownum ++;
8245: $css_class = $rownum%2?' class="LC_odd_row"':'';
8246: $datatable .= '<tr'.$css_class.'>'.
8247: '<td><span class="LC_nobreak">'.
8248: $titles->{$type}.'</span></td>'.
8249: '<td class="LC_left_item">'.
8250: '<input type="text" name="'.$type.'_namedusers" '.
8251: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
8252: '<td class="LC_right_item">'.
8253: '<span class="LC_nobreak">'.
8254: '<input type="text" name="'.$type.'_machines" '.
8255: 'value="'.$machineaccess{$type}.'" size="10" />'.
8256: '</td></tr>'."\n";
8257: }
8258: $$rowtotal += $rownum;
8259: return $datatable;
8260: }
8261:
8262: sub serverstatus_pages {
8263: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 8264: 'checksums','clusterstatus','certstatus','metadata_keywords',
8265: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
8266: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 8267: }
8268:
1.236 raeburn 8269: sub defaults_javascript {
8270: my ($settings) = @_;
1.294 raeburn 8271: 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.');
8272: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
8273: &js_escape(\$intauthcheck);
8274: &js_escape(\$intauthcost);
8275: my $intauthjs = <<"ENDSCRIPT";
8276:
8277: function warnIntAuth(field) {
8278: if (field.name == 'intauth_check') {
8279: if (field.value == '2') {
8280: alert('$intauthcheck');
8281: }
8282: }
8283: if (field.name == 'intauth_cost') {
8284: field.value.replace(/\s/g,'');
8285: if (field.value != '') {
8286: var regexdigit=/^\\d+\$/;
8287: if (!regexdigit.test(field.value)) {
8288: alert('$intauthcost');
8289: }
8290: }
8291: }
8292: return;
8293: }
8294:
8295: ENDSCRIPT
8296:
8297: if (ref($settings) ne 'HASH') {
8298: return &Apache::lonhtmlcommon::scripttag($intauthjs);
8299: }
1.236 raeburn 8300: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
8301: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
8302: if ($maxnum eq '') {
8303: $maxnum = 0;
8304: }
8305: $maxnum ++;
1.249 raeburn 8306: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 8307: return <<"ENDSCRIPT";
8308: <script type="text/javascript">
8309: // <![CDATA[
8310: function reorderTypes(form,caller) {
8311: var changedVal;
8312: $jstext
8313: var newpos = 'addinststatus_pos';
8314: var current = new Array;
8315: var maxh = $maxnum;
8316: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8317: var oldVal;
8318: if (caller == newpos) {
8319: changedVal = newitemVal;
8320: } else {
8321: var curritem = 'inststatus_pos_'+caller;
8322: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
8323: current[newitemVal] = newpos;
8324: }
8325: for (var i=0; i<inststatuses.length; i++) {
8326: if (inststatuses[i] != caller) {
8327: var elementName = 'inststatus_pos_'+inststatuses[i];
8328: if (form.elements[elementName]) {
8329: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8330: current[currVal] = elementName;
8331: }
8332: }
8333: }
8334: for (var j=0; j<maxh; j++) {
8335: if (current[j] == undefined) {
8336: oldVal = j;
8337: }
8338: }
8339: if (oldVal < changedVal) {
8340: for (var k=oldVal+1; k<=changedVal ; k++) {
8341: var elementName = current[k];
8342: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8343: }
8344: } else {
8345: for (var k=changedVal; k<oldVal; k++) {
8346: var elementName = current[k];
8347: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8348: }
8349: }
8350: return;
8351: }
8352:
1.294 raeburn 8353: $intauthjs
8354:
1.236 raeburn 8355: // ]]>
8356: </script>
8357:
8358: ENDSCRIPT
1.294 raeburn 8359: } else {
8360: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 8361: }
8362: }
8363:
1.49 raeburn 8364: sub coursecategories_javascript {
8365: my ($settings) = @_;
1.57 raeburn 8366: my ($output,$jstext,$cathash);
1.49 raeburn 8367: if (ref($settings) eq 'HASH') {
1.57 raeburn 8368: $cathash = $settings->{'cats'};
8369: }
8370: if (ref($cathash) eq 'HASH') {
1.49 raeburn 8371: my (@cats,@jsarray,%idx);
1.57 raeburn 8372: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 8373: if (@jsarray > 0) {
8374: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
8375: for (my $i=0; $i<@jsarray; $i++) {
8376: if (ref($jsarray[$i]) eq 'ARRAY') {
8377: my $catstr = join('","',@{$jsarray[$i]});
8378: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
8379: }
8380: }
8381: }
8382: } else {
8383: $jstext = ' var categories = Array(1);'."\n".
8384: ' categories[0] = Array("instcode_pos");'."\n";
8385: }
1.237 bisitz 8386: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
8387: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 8388: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 8389: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
8390: &js_escape(\$instcode_reserved);
8391: &js_escape(\$communities_reserved);
1.272 raeburn 8392: &js_escape(\$placement_reserved);
1.265 damieng 8393: &js_escape(\$choose_again);
1.49 raeburn 8394: $output = <<"ENDSCRIPT";
8395: <script type="text/javascript">
1.109 raeburn 8396: // <![CDATA[
1.49 raeburn 8397: function reorderCats(form,parent,item,idx) {
8398: var changedVal;
8399: $jstext
8400: var newpos = 'addcategory_pos';
8401: if (parent == '') {
8402: var has_instcode = 0;
8403: var maxtop = categories[idx].length;
8404: for (var j=0; j<maxtop; j++) {
8405: if (categories[idx][j] == 'instcode::0') {
8406: has_instcode == 1;
8407: }
8408: }
8409: if (has_instcode == 0) {
8410: categories[idx][maxtop] = 'instcode_pos';
8411: }
8412: } else {
8413: newpos += '_'+parent;
8414: }
8415: var maxh = 1 + categories[idx].length;
8416: var current = new Array;
8417: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8418: if (item == newpos) {
8419: changedVal = newitemVal;
8420: } else {
8421: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
8422: current[newitemVal] = newpos;
8423: }
8424: for (var i=0; i<categories[idx].length; i++) {
8425: var elementName = categories[idx][i];
8426: if (elementName != item) {
8427: if (form.elements[elementName]) {
8428: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8429: current[currVal] = elementName;
8430: }
8431: }
8432: }
8433: var oldVal;
8434: for (var j=0; j<maxh; j++) {
8435: if (current[j] == undefined) {
8436: oldVal = j;
8437: }
8438: }
8439: if (oldVal < changedVal) {
8440: for (var k=oldVal+1; k<=changedVal ; k++) {
8441: var elementName = current[k];
8442: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8443: }
8444: } else {
8445: for (var k=changedVal; k<oldVal; k++) {
8446: var elementName = current[k];
8447: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8448: }
8449: }
8450: return;
8451: }
1.120 raeburn 8452:
8453: function categoryCheck(form) {
8454: if (form.elements['addcategory_name'].value == 'instcode') {
8455: alert('$instcode_reserved\\n$choose_again');
8456: return false;
8457: }
8458: if (form.elements['addcategory_name'].value == 'communities') {
8459: alert('$communities_reserved\\n$choose_again');
8460: return false;
8461: }
1.272 raeburn 8462: if (form.elements['addcategory_name'].value == 'placement') {
8463: alert('$placement_reserved\\n$choose_again');
8464: return false;
8465: }
1.120 raeburn 8466: return true;
8467: }
8468:
1.109 raeburn 8469: // ]]>
1.49 raeburn 8470: </script>
8471:
8472: ENDSCRIPT
8473: return $output;
8474: }
8475:
1.48 raeburn 8476: sub initialize_categories {
8477: my ($itemcount) = @_;
1.120 raeburn 8478: my ($datatable,$css_class,$chgstr);
8479: my %default_names = (
8480: instcode => 'Official courses (with institutional codes)',
8481: communities => 'Communities',
1.272 raeburn 8482: placement => 'Placement Tests',
1.120 raeburn 8483: );
8484: my $select0 = ' selected="selected"';
8485: my $select1 = '';
1.272 raeburn 8486: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 8487: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8488: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
1.272 raeburn 8489: if (($default eq 'communities') || ($default eq 'placement')) {
1.120 raeburn 8490: $select1 = $select0;
8491: $select0 = '';
8492: }
8493: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
8494: .'<select name="'.$default.'_pos">'
8495: .'<option value="0"'.$select0.'>1</option>'
8496: .'<option value="1"'.$select1.'>2</option>'
8497: .'<option value="2">3</option></select> '
8498: .$default_names{$default}
8499: .'</span></td><td><span class="LC_nobreak">'
8500: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
8501: .&mt('Display').'</label> <label>'
8502: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 8503: .'</label></span></td></tr>';
1.120 raeburn 8504: $itemcount ++;
8505: }
1.48 raeburn 8506: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 8507: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 8508: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 8509: .'<select name="addcategory_pos"'.$chgstr.'>'
8510: .'<option value="0">1</option>'
8511: .'<option value="1">2</option>'
8512: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 8513: .&mt('Add category').'</td><td>'.&mt('Name:')
8514: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
8515: return $datatable;
8516: }
8517:
8518: sub build_category_rows {
1.49 raeburn 8519: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
8520: my ($text,$name,$item,$chgstr);
1.48 raeburn 8521: if (ref($cats) eq 'ARRAY') {
8522: my $maxdepth = scalar(@{$cats});
8523: if (ref($cats->[$depth]) eq 'HASH') {
8524: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
8525: my $numchildren = @{$cats->[$depth]{$parent}};
8526: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 8527: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 8528: my ($idxnum,$parent_name,$parent_item);
8529: my $higher = $depth - 1;
8530: if ($higher == 0) {
8531: $parent_name = &escape($parent).'::'.$higher;
8532: } else {
8533: if (ref($path) eq 'ARRAY') {
8534: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8535: }
8536: }
8537: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 8538: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 8539: if ($j < $numchildren) {
1.48 raeburn 8540: $name = $cats->[$depth]{$parent}[$j];
8541: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 8542: $idxnum = $idx->{$item};
8543: } else {
8544: $name = $parent_name;
8545: $item = $parent_item;
1.48 raeburn 8546: }
1.49 raeburn 8547: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
8548: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 8549: for (my $i=0; $i<=$numchildren; $i++) {
8550: my $vpos = $i+1;
8551: my $selstr;
8552: if ($j == $i) {
8553: $selstr = ' selected="selected" ';
8554: }
8555: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
8556: }
8557: $text .= '</select> ';
8558: if ($j < $numchildren) {
8559: my $deeper = $depth+1;
8560: $text .= $name.' '
8561: .'<label><input type="checkbox" name="deletecategory" value="'
8562: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
8563: if(ref($path) eq 'ARRAY') {
8564: push(@{$path},$name);
1.49 raeburn 8565: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 8566: pop(@{$path});
8567: }
8568: } else {
1.59 bisitz 8569: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 8570: if ($j == $numchildren) {
8571: $text .= $name;
8572: } else {
8573: $text .= $item;
8574: }
8575: $text .= '" value="" />';
8576: }
8577: $text .= '</td></tr>';
8578: }
8579: $text .= '</table></td>';
8580: } else {
8581: my $higher = $depth-1;
8582: if ($higher == 0) {
8583: $name = &escape($parent).'::'.$higher;
8584: } else {
8585: if (ref($path) eq 'ARRAY') {
8586: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8587: }
8588: }
8589: my $colspan;
8590: if ($parent ne 'instcode') {
8591: $colspan = $maxdepth - $depth - 1;
8592: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
8593: }
8594: }
8595: }
8596: }
8597: return $text;
8598: }
8599:
1.33 raeburn 8600: sub modifiable_userdata_row {
1.305 raeburn 8601: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
8602: $rowid,$customcss,$rowstyle) = @_;
1.228 raeburn 8603: my ($role,$rolename,$statustype);
8604: $role = $item;
1.224 raeburn 8605: if ($context eq 'cancreate') {
1.305 raeburn 8606: if ($item =~ /^(emailusername)_(.+)$/) {
8607: $role = $1;
8608: $statustype = $2;
1.228 raeburn 8609: if (ref($usertypes) eq 'HASH') {
8610: if ($usertypes->{$statustype}) {
8611: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
8612: } else {
8613: $rolename = &mt('Data provided by user');
8614: }
8615: }
1.224 raeburn 8616: }
8617: } elsif ($context eq 'selfcreate') {
1.63 raeburn 8618: if (ref($usertypes) eq 'HASH') {
8619: $rolename = $usertypes->{$role};
8620: } else {
8621: $rolename = $role;
8622: }
1.325 raeburn 8623: } elsif ($context eq 'lti') {
8624: $rolename = &mt('Institutional data used (if available)');
1.33 raeburn 8625: } else {
1.63 raeburn 8626: if ($role eq 'cr') {
8627: $rolename = &mt('Custom role');
8628: } else {
8629: $rolename = &Apache::lonnet::plaintext($role);
8630: }
1.33 raeburn 8631: }
1.224 raeburn 8632: my (@fields,%fieldtitles);
8633: if (ref($fieldsref) eq 'ARRAY') {
8634: @fields = @{$fieldsref};
8635: } else {
8636: @fields = ('lastname','firstname','middlename','generation',
8637: 'permanentemail','id');
8638: }
8639: if ((ref($titlesref) eq 'HASH')) {
8640: %fieldtitles = %{$titlesref};
8641: } else {
8642: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8643: }
1.33 raeburn 8644: my $output;
1.305 raeburn 8645: my $css_class;
8646: if ($rowcount%2) {
8647: $css_class = 'LC_odd_row';
8648: }
8649: if ($customcss) {
8650: $css_class .= " $customcss";
8651: }
8652: $css_class =~ s/^\s+//;
8653: if ($css_class) {
8654: $css_class = ' class="'.$css_class.'"';
8655: }
8656: if ($rowstyle) {
8657: $css_class .= ' style="'.$rowstyle.'"';
8658: }
8659: if ($rowid) {
8660: $rowid = ' id="'.$rowid.'"';
8661: }
8662: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 8663: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
8664: '<td class="LC_left_item" colspan="2"><table>';
8665: my $rem;
8666: my %checks;
1.325 raeburn 8667: my %current;
1.33 raeburn 8668: if (ref($settings) eq 'HASH') {
1.325 raeburn 8669: my $hashref;
8670: if ($context eq 'lti') {
8671: if (ref($settings) eq 'HASH') {
8672: $hashref = $settings->{'instdata'};
8673: }
8674: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 8675: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 8676: $hashref = $settings->{'lti_instdata'};
8677: }
8678: if ($role eq 'emailusername') {
8679: if ($statustype) {
8680: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
8681: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 8682: }
1.325 raeburn 8683: }
8684: }
8685: }
8686: if (ref($hashref) eq 'HASH') {
8687: foreach my $field (@fields) {
8688: if ($hashref->{$field}) {
8689: if ($role eq 'emailusername') {
8690: $checks{$field} = $hashref->{$field};
8691: } else {
8692: $checks{$field} = ' checked="checked" ';
1.33 raeburn 8693: }
8694: }
8695: }
8696: }
8697: }
1.305 raeburn 8698:
8699: my $total = scalar(@fields);
8700: for (my $i=0; $i<$total; $i++) {
8701: $rem = $i%($numinrow);
1.33 raeburn 8702: if ($rem == 0) {
8703: if ($i > 0) {
8704: $output .= '</tr>';
8705: }
8706: $output .= '<tr>';
8707: }
8708: my $check = ' ';
1.228 raeburn 8709: unless ($role eq 'emailusername') {
8710: if (exists($checks{$fields[$i]})) {
8711: $check = $checks{$fields[$i]}
1.325 raeburn 8712: } elsif ($context ne 'lti') {
1.228 raeburn 8713: if ($role eq 'st') {
8714: if (ref($settings) ne 'HASH') {
8715: $check = ' checked="checked" ';
8716: }
1.33 raeburn 8717: }
8718: }
8719: }
8720: $output .= '<td class="LC_left_item">'.
1.228 raeburn 8721: '<span class="LC_nobreak">';
1.325 raeburn 8722: my $prefix = 'canmodify';
1.228 raeburn 8723: if ($role eq 'emailusername') {
8724: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
8725: $checks{$fields[$i]} = 'omit';
8726: }
8727: foreach my $option ('required','optional','omit') {
8728: my $checked='';
8729: if ($checks{$fields[$i]} eq $option) {
8730: $checked='checked="checked" ';
8731: }
8732: $output .= '<label>'.
1.325 raeburn 8733: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 8734: &mt($option).'</label>'.(' ' x2);
8735: }
8736: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
8737: } else {
1.325 raeburn 8738: if ($context eq 'lti') {
8739: $prefix = 'lti';
8740: }
1.228 raeburn 8741: $output .= '<label>'.
1.325 raeburn 8742: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 8743: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
8744: '</label>';
8745: }
8746: $output .= '</span></td>';
1.33 raeburn 8747: }
1.305 raeburn 8748: $rem = $total%$numinrow;
8749: my $colsleft;
8750: if ($rem) {
8751: $colsleft = $numinrow - $rem;
8752: }
8753: if ($colsleft > 1) {
1.33 raeburn 8754: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8755: ' </td>';
8756: } elsif ($colsleft == 1) {
8757: $output .= '<td class="LC_left_item"> </td>';
8758: }
8759: $output .= '</tr></table></td></tr>';
8760: return $output;
8761: }
1.28 raeburn 8762:
1.93 raeburn 8763: sub insttypes_row {
1.305 raeburn 8764: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
8765: $customcss,$rowstyle) = @_;
1.93 raeburn 8766: my %lt = &Apache::lonlocal::texthash (
8767: cansearch => 'Users allowed to search',
8768: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 8769: lockablenames => 'User preference to lock name',
1.305 raeburn 8770: selfassign => 'Self-reportable affiliations',
1.315 raeburn 8771: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 8772: );
8773: my $showdom;
8774: if ($context eq 'cansearch') {
8775: $showdom = ' ('.$dom.')';
8776: }
1.165 raeburn 8777: my $class = 'LC_left_item';
8778: if ($context eq 'statustocreate') {
8779: $class = 'LC_right_item';
8780: }
1.305 raeburn 8781: my $css_class;
8782: if ($$rowtotal%2) {
8783: $css_class = 'LC_odd_row';
8784: }
8785: if ($customcss) {
8786: $css_class .= ' '.$customcss;
8787: }
8788: $css_class =~ s/^\s+//;
8789: if ($css_class) {
8790: $css_class = ' class="'.$css_class.'"';
8791: }
8792: if ($rowstyle) {
8793: $css_class .= ' style="'.$rowstyle.'"';
8794: }
8795: if ($onclick) {
8796: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 8797: }
8798: my $output = '<tr'.$css_class.'>'.
8799: '<td>'.$lt{$context}.$showdom.
8800: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 8801: my $rem;
8802: if (ref($types) eq 'ARRAY') {
8803: for (my $i=0; $i<@{$types}; $i++) {
8804: if (defined($usertypes->{$types->[$i]})) {
8805: my $rem = $i%($numinrow);
8806: if ($rem == 0) {
8807: if ($i > 0) {
8808: $output .= '</tr>';
8809: }
8810: $output .= '<tr>';
1.23 raeburn 8811: }
1.26 raeburn 8812: my $check = ' ';
1.99 raeburn 8813: if (ref($settings) eq 'HASH') {
8814: if (ref($settings->{$context}) eq 'ARRAY') {
8815: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
8816: $check = ' checked="checked" ';
8817: }
1.315 raeburn 8818: } elsif (ref($settings->{$context}) eq 'HASH') {
8819: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
8820: $check = ' checked="checked" ';
8821: }
1.99 raeburn 8822: } elsif ($context eq 'statustocreate') {
1.26 raeburn 8823: $check = ' checked="checked" ';
8824: }
1.23 raeburn 8825: }
1.26 raeburn 8826: $output .= '<td class="LC_left_item">'.
8827: '<span class="LC_nobreak"><label>'.
1.93 raeburn 8828: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 8829: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 8830: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 8831: }
8832: }
1.26 raeburn 8833: $rem = @{$types}%($numinrow);
1.23 raeburn 8834: }
8835: my $colsleft = $numinrow - $rem;
1.315 raeburn 8836: if ($context eq 'overrides') {
8837: if ($colsleft > 1) {
8838: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8839: } else {
8840: $output .= '<td class="LC_left_item">';
8841: }
8842: $output .= ' ';
1.23 raeburn 8843: } else {
1.315 raeburn 8844: if (($rem == 0) && (@{$types} > 0)) {
8845: $output .= '<tr>';
8846: }
8847: if ($colsleft > 1) {
8848: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8849: } else {
8850: $output .= '<td class="LC_left_item">';
8851: }
8852: my $defcheck = ' ';
8853: if (ref($settings) eq 'HASH') {
8854: if (ref($settings->{$context}) eq 'ARRAY') {
8855: if (grep(/^default$/,@{$settings->{$context}})) {
8856: $defcheck = ' checked="checked" ';
8857: }
8858: } elsif ($context eq 'statustocreate') {
1.99 raeburn 8859: $defcheck = ' checked="checked" ';
8860: }
1.26 raeburn 8861: }
1.315 raeburn 8862: $output .= '<span class="LC_nobreak"><label>'.
8863: '<input type="checkbox" name="'.$context.'" '.
8864: 'value="default"'.$defcheck.$onclick.' />'.
8865: $othertitle.'</label></span>';
1.23 raeburn 8866: }
1.315 raeburn 8867: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 8868: return $output;
1.23 raeburn 8869: }
8870:
8871: sub sorted_searchtitles {
8872: my %searchtitles = &Apache::lonlocal::texthash(
8873: 'uname' => 'username',
8874: 'lastname' => 'last name',
8875: 'lastfirst' => 'last name, first name',
8876: );
8877: my @titleorder = ('uname','lastname','lastfirst');
8878: return (\%searchtitles,\@titleorder);
8879: }
8880:
1.25 raeburn 8881: sub sorted_searchtypes {
8882: my %srchtypes_desc = (
8883: exact => 'is exact match',
8884: contains => 'contains ..',
8885: begins => 'begins with ..',
8886: );
8887: my @srchtypeorder = ('exact','begins','contains');
8888: return (\%srchtypes_desc,\@srchtypeorder);
8889: }
8890:
1.3 raeburn 8891: sub usertype_update_row {
8892: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
8893: my $datatable;
8894: my $numinrow = 4;
8895: foreach my $type (@{$types}) {
8896: if (defined($usertypes->{$type})) {
8897: $$rownums ++;
8898: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
8899: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
8900: '</td><td class="LC_left_item"><table>';
8901: for (my $i=0; $i<@{$fields}; $i++) {
8902: my $rem = $i%($numinrow);
8903: if ($rem == 0) {
8904: if ($i > 0) {
8905: $datatable .= '</tr>';
8906: }
8907: $datatable .= '<tr>';
8908: }
8909: my $check = ' ';
1.39 raeburn 8910: if (ref($settings) eq 'HASH') {
8911: if (ref($settings->{'fields'}) eq 'HASH') {
8912: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
8913: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
8914: $check = ' checked="checked" ';
8915: }
1.3 raeburn 8916: }
8917: }
8918: }
8919:
8920: if ($i == @{$fields}-1) {
8921: my $colsleft = $numinrow - $rem;
8922: if ($colsleft > 1) {
8923: $datatable .= '<td colspan="'.$colsleft.'">';
8924: } else {
8925: $datatable .= '<td>';
8926: }
8927: } else {
8928: $datatable .= '<td>';
8929: }
1.8 raeburn 8930: $datatable .= '<span class="LC_nobreak"><label>'.
8931: '<input type="checkbox" name="updateable_'.$type.
8932: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
8933: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 8934: }
8935: $datatable .= '</tr></table></td></tr>';
8936: }
8937: }
8938: return $datatable;
1.1 raeburn 8939: }
8940:
8941: sub modify_login {
1.205 raeburn 8942: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 8943: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
8944: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
8945: %title = ( coursecatalog => 'Display course catalog',
8946: adminmail => 'Display administrator E-mail address',
1.188 raeburn 8947: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 8948: newuser => 'Link for visitors to create a user account',
8949: loginheader => 'Log-in box header');
8950: @offon = ('off','on');
1.112 raeburn 8951: if (ref($domconfig{login}) eq 'HASH') {
8952: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
8953: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
8954: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
8955: }
8956: }
8957: }
1.9 raeburn 8958: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
8959: \%domconfig,\%loginhash);
1.188 raeburn 8960: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 8961: foreach my $item (@toggles) {
8962: $loginhash{login}{$item} = $env{'form.'.$item};
8963: }
1.41 raeburn 8964: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 8965: if (ref($colchanges{'login'}) eq 'HASH') {
8966: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
8967: \%loginhash);
8968: }
1.110 raeburn 8969:
1.149 raeburn 8970: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 8971: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 8972: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 8973: if (keys(%servers) > 1) {
8974: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 8975: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
8976: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
8977: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
8978: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
8979: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
8980: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8981: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
8982: $changes{'loginvia'}{$lonhost} = 1;
8983: } else {
8984: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
8985: $changes{'loginvia'}{$lonhost} = 1;
8986: }
8987: } else {
8988: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8989: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
8990: $changes{'loginvia'}{$lonhost} = 1;
8991: }
8992: }
8993: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
8994: foreach my $item (@loginvia_attribs) {
8995: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
8996: }
8997: } else {
8998: foreach my $item (@loginvia_attribs) {
8999: my $new = $env{'form.'.$lonhost.'_'.$item};
9000: if (($item eq 'serverpath') && ($new eq 'custom')) {
9001: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
9002: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9003: $new = '/';
9004: }
9005: }
9006: if (($item eq 'custompath') &&
9007: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9008: $new = '';
9009: }
9010: if ($new ne $curr_loginvia{$lonhost}{$item}) {
9011: $changes{'loginvia'}{$lonhost} = 1;
9012: }
9013: if ($item eq 'exempt') {
1.256 raeburn 9014: $new = &check_exempt_addresses($new);
1.128 raeburn 9015: }
9016: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9017: }
9018: }
1.112 raeburn 9019: } else {
1.128 raeburn 9020: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9021: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 9022: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 9023: foreach my $item (@loginvia_attribs) {
9024: my $new = $env{'form.'.$lonhost.'_'.$item};
9025: if (($item eq 'serverpath') && ($new eq 'custom')) {
9026: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9027: $new = '/';
9028: }
9029: }
9030: if (($item eq 'custompath') &&
9031: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9032: $new = '';
9033: }
9034: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9035: }
1.110 raeburn 9036: }
9037: }
9038: }
9039: }
1.119 raeburn 9040:
1.168 raeburn 9041: my $servadm = $r->dir_config('lonAdmEMail');
9042: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
9043: if (ref($domconfig{'login'}) eq 'HASH') {
9044: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
9045: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
9046: if ($lang eq 'nolang') {
9047: push(@currlangs,$lang);
9048: } elsif (defined($langchoices{$lang})) {
9049: push(@currlangs,$lang);
9050: } else {
9051: next;
9052: }
9053: }
9054: }
9055: }
9056: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
9057: if (@currlangs > 0) {
9058: foreach my $lang (@currlangs) {
9059: if (grep(/^\Q$lang\E$/,@delurls)) {
9060: $changes{'helpurl'}{$lang} = 1;
9061: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
9062: $changes{'helpurl'}{$lang} = 1;
9063: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
9064: push(@newlangs,$lang);
9065: } else {
9066: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9067: }
9068: }
9069: }
9070: unless (grep(/^nolang$/,@currlangs)) {
9071: if ($env{'form.loginhelpurl_nolang.filename'}) {
9072: $changes{'helpurl'}{'nolang'} = 1;
9073: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
9074: push(@newlangs,'nolang');
9075: }
9076: }
9077: if ($env{'form.loginhelpurl_add_lang'}) {
9078: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
9079: ($env{'form.loginhelpurl_add_file.filename'})) {
9080: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
9081: $addedfile = $env{'form.loginhelpurl_add_lang'};
9082: }
9083: }
9084: if ((@newlangs > 0) || ($addedfile)) {
9085: my $error;
9086: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9087: if ($configuserok eq 'ok') {
9088: if ($switchserver) {
9089: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
9090: } elsif ($author_ok eq 'ok') {
9091: my @allnew = @newlangs;
9092: if ($addedfile ne '') {
9093: push(@allnew,$addedfile);
9094: }
9095: foreach my $lang (@allnew) {
9096: my $formelem = 'loginhelpurl_'.$lang;
9097: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
9098: $formelem = 'loginhelpurl_add_file';
9099: }
9100: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9101: "help/$lang",'','',$newfile{$lang});
9102: if ($result eq 'ok') {
9103: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
9104: $changes{'helpurl'}{$lang} = 1;
9105: } else {
9106: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
9107: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 9108: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 9109: (!grep(/^\Q$lang\E$/,@delurls))) {
9110: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9111: }
9112: }
9113: }
9114: } else {
9115: $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);
9116: }
9117: } else {
9118: $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);
9119: }
9120: if ($error) {
9121: &Apache::lonnet::logthis($error);
9122: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9123: }
9124: }
1.256 raeburn 9125:
9126: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
9127: if (ref($domconfig{'login'}) eq 'HASH') {
9128: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
9129: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
9130: if ($domservers{$lonhost}) {
9131: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9132: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 9133: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 9134: }
9135: }
9136: }
9137: }
9138: }
9139: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
9140: foreach my $lonhost (sort(keys(%domservers))) {
9141: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9142: $changes{'headtag'}{$lonhost} = 1;
9143: } else {
9144: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
9145: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
9146: }
9147: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
9148: push(@newhosts,$lonhost);
9149: } elsif ($currheadtagurls{$lonhost}) {
9150: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
9151: if ($currexempt{$lonhost}) {
1.289 raeburn 9152: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 9153: $changes{'headtag'}{$lonhost} = 1;
9154: }
9155: } elsif ($possexempt{$lonhost}) {
9156: $changes{'headtag'}{$lonhost} = 1;
9157: }
9158: if ($possexempt{$lonhost}) {
9159: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9160: }
9161: }
9162: }
9163: }
9164: if (@newhosts) {
9165: my $error;
9166: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9167: if ($configuserok eq 'ok') {
9168: if ($switchserver) {
9169: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
9170: } elsif ($author_ok eq 'ok') {
9171: foreach my $lonhost (@newhosts) {
9172: my $formelem = 'loginheadtag_'.$lonhost;
9173: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9174: "login/headtag/$lonhost",'','',
9175: $env{'form.loginheadtag_'.$lonhost.'.filename'});
9176: if ($result eq 'ok') {
9177: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
9178: $changes{'headtag'}{$lonhost} = 1;
9179: if ($possexempt{$lonhost}) {
9180: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9181: }
9182: } else {
9183: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
9184: $newheadtagurls{$lonhost},$result);
9185: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
9186: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
9187: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
9188: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
9189: }
9190: }
9191: }
9192: } else {
9193: $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);
9194: }
9195: } else {
9196: $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);
9197: }
9198: if ($error) {
9199: &Apache::lonnet::logthis($error);
9200: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9201: }
9202: }
1.169 raeburn 9203: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 9204:
9205: my $defaulthelpfile = '/adm/loginproblems.html';
9206: my $defaulttext = &mt('Default in use');
9207:
1.1 raeburn 9208: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
9209: $dom);
9210: if ($putresult eq 'ok') {
1.188 raeburn 9211: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 9212: my %defaultchecked = (
9213: 'coursecatalog' => 'on',
1.188 raeburn 9214: 'helpdesk' => 'on',
1.42 raeburn 9215: 'adminmail' => 'off',
1.43 raeburn 9216: 'newuser' => 'off',
1.42 raeburn 9217: );
1.55 raeburn 9218: if (ref($domconfig{'login'}) eq 'HASH') {
9219: foreach my $item (@toggles) {
9220: if ($defaultchecked{$item} eq 'on') {
9221: if (($domconfig{'login'}{$item} eq '0') &&
9222: ($env{'form.'.$item} eq '1')) {
9223: $changes{$item} = 1;
9224: } elsif (($domconfig{'login'}{$item} eq '' ||
9225: $domconfig{'login'}{$item} eq '1') &&
9226: ($env{'form.'.$item} eq '0')) {
9227: $changes{$item} = 1;
9228: }
9229: } elsif ($defaultchecked{$item} eq 'off') {
9230: if (($domconfig{'login'}{$item} eq '1') &&
9231: ($env{'form.'.$item} eq '0')) {
9232: $changes{$item} = 1;
9233: } elsif (($domconfig{'login'}{$item} eq '' ||
9234: $domconfig{'login'}{$item} eq '0') &&
9235: ($env{'form.'.$item} eq '1')) {
9236: $changes{$item} = 1;
9237: }
1.42 raeburn 9238: }
9239: }
1.41 raeburn 9240: }
1.6 raeburn 9241: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 9242: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9243: if (ref($lastactref) eq 'HASH') {
9244: $lastactref->{'domainconfig'} = 1;
9245: }
1.1 raeburn 9246: $resulttext = &mt('Changes made:').'<ul>';
9247: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 9248: if ($item eq 'loginvia') {
1.112 raeburn 9249: if (ref($changes{$item}) eq 'HASH') {
9250: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
9251: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 9252: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
9253: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
9254: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
9255: $protocol = 'http' if ($protocol ne 'https');
9256: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
9257:
9258: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
9259: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
9260: } else {
9261: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
9262: }
9263: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
9264: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
9265: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
9266: }
9267: $resulttext .= '</li>';
9268: } else {
9269: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
9270: }
1.112 raeburn 9271: } else {
1.128 raeburn 9272: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 9273: }
9274: }
1.128 raeburn 9275: $resulttext .= '</ul></li>';
1.112 raeburn 9276: }
1.168 raeburn 9277: } elsif ($item eq 'helpurl') {
9278: if (ref($changes{$item}) eq 'HASH') {
9279: foreach my $lang (sort(keys(%{$changes{$item}}))) {
9280: if (grep(/^\Q$lang\E$/,@delurls)) {
9281: my ($chg,$link);
9282: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
9283: if ($lang eq 'nolang') {
9284: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
9285: } else {
9286: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
9287: }
9288: $resulttext .= '<li>'.$chg.'</li>';
9289: } else {
9290: my $chg;
9291: if ($lang eq 'nolang') {
9292: $chg = &mt('custom log-in help file for no preferred language');
9293: } else {
9294: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
9295: }
9296: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
9297: $loginhash{'login'}{'helpurl'}{$lang}.
9298: '?inhibitmenu=yes',$chg,600,500).
9299: '</li>';
9300: }
9301: }
9302: }
1.256 raeburn 9303: } elsif ($item eq 'headtag') {
9304: if (ref($changes{$item}) eq 'HASH') {
9305: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
9306: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9307: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
9308: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9309: $resulttext .= '<li><a href="'.
9310: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
9311: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
9312: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
9313: if ($possexempt{$lonhost}) {
9314: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
9315: } else {
9316: $resulttext .= &mt('included for any client IP');
9317: }
9318: $resulttext .= '</li>';
9319: }
9320: }
9321: }
1.169 raeburn 9322: } elsif ($item eq 'captcha') {
9323: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 9324: my $chgtxt;
1.169 raeburn 9325: if ($loginhash{'login'}{$item} eq 'notused') {
9326: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
9327: } else {
9328: my %captchas = &captcha_phrases();
9329: if ($captchas{$loginhash{'login'}{$item}}) {
9330: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
9331: } else {
9332: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
9333: }
9334: }
9335: $resulttext .= '<li>'.$chgtxt.'</li>';
9336: }
9337: } elsif ($item eq 'recaptchakeys') {
9338: if (ref($loginhash{'login'}) eq 'HASH') {
9339: my ($privkey,$pubkey);
9340: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
9341: $pubkey = $loginhash{'login'}{$item}{'public'};
9342: $privkey = $loginhash{'login'}{$item}{'private'};
9343: }
9344: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
9345: if (!$pubkey) {
9346: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
9347: } else {
9348: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
9349: }
9350: if (!$privkey) {
9351: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
9352: } else {
1.251 raeburn 9353: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 9354: }
9355: $chgtxt .= '</ul>';
9356: $resulttext .= '<li>'.$chgtxt.'</li>';
9357: }
1.269 raeburn 9358: } elsif ($item eq 'recaptchaversion') {
9359: if (ref($loginhash{'login'}) eq 'HASH') {
9360: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 9361: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 9362: '</li>';
9363: }
9364: }
1.41 raeburn 9365: } else {
9366: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
9367: }
1.1 raeburn 9368: }
1.6 raeburn 9369: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 9370: } else {
9371: $resulttext = &mt('No changes made to log-in page settings');
9372: }
9373: } else {
1.11 albertel 9374: $resulttext = '<span class="LC_error">'.
9375: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9376: }
1.6 raeburn 9377: if ($errors) {
1.9 raeburn 9378: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 9379: $errors.'</ul>';
9380: }
9381: return $resulttext;
9382: }
9383:
1.256 raeburn 9384: sub check_exempt_addresses {
9385: my ($iplist) = @_;
9386: $iplist =~ s/^\s+//;
9387: $iplist =~ s/\s+$//;
9388: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
9389: my (@okips,$new);
9390: foreach my $ip (@poss_ips) {
9391: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
9392: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
9393: push(@okips,$ip);
9394: }
9395: }
9396: }
9397: if (@okips > 0) {
9398: $new = join(',',@okips);
9399: } else {
9400: $new = '';
9401: }
9402: return $new;
9403: }
9404:
1.6 raeburn 9405: sub color_font_choices {
9406: my %choices =
9407: &Apache::lonlocal::texthash (
9408: img => "Header",
9409: bgs => "Background colors",
9410: links => "Link colors",
1.55 raeburn 9411: images => "Images",
1.6 raeburn 9412: font => "Font color",
1.201 raeburn 9413: fontmenu => "Font menu",
1.76 raeburn 9414: pgbg => "Page",
1.6 raeburn 9415: tabbg => "Header",
9416: sidebg => "Border",
9417: link => "Link",
9418: alink => "Active link",
9419: vlink => "Visited link",
9420: );
9421: return %choices;
9422: }
9423:
9424: sub modify_rolecolors {
1.205 raeburn 9425: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 9426: my ($resulttext,%rolehash);
9427: $rolehash{'rolecolors'} = {};
1.55 raeburn 9428: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
9429: if ($domconfig{'rolecolors'} eq '') {
9430: $domconfig{'rolecolors'} = {};
9431: }
9432: }
1.9 raeburn 9433: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 9434: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
9435: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
9436: $dom);
9437: if ($putresult eq 'ok') {
9438: if (keys(%changes) > 0) {
1.41 raeburn 9439: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9440: if (ref($lastactref) eq 'HASH') {
9441: $lastactref->{'domainconfig'} = 1;
9442: }
1.6 raeburn 9443: $resulttext = &display_colorchgs($dom,\%changes,$roles,
9444: $rolehash{'rolecolors'});
9445: } else {
9446: $resulttext = &mt('No changes made to default color schemes');
9447: }
9448: } else {
1.11 albertel 9449: $resulttext = '<span class="LC_error">'.
9450: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 9451: }
9452: if ($errors) {
9453: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9454: $errors.'</ul>';
9455: }
9456: return $resulttext;
9457: }
9458:
9459: sub modify_colors {
1.9 raeburn 9460: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 9461: my (%changes,%choices);
1.51 raeburn 9462: my @bgs;
1.6 raeburn 9463: my @links = ('link','alink','vlink');
1.41 raeburn 9464: my @logintext;
1.6 raeburn 9465: my @images;
9466: my $servadm = $r->dir_config('lonAdmEMail');
9467: my $errors;
1.200 raeburn 9468: my %defaults;
1.6 raeburn 9469: foreach my $role (@{$roles}) {
9470: if ($role eq 'login') {
1.12 raeburn 9471: %choices = &login_choices();
1.41 raeburn 9472: @logintext = ('textcol','bgcol');
1.12 raeburn 9473: } else {
9474: %choices = &color_font_choices();
9475: }
9476: if ($role eq 'login') {
1.41 raeburn 9477: @images = ('img','logo','domlogo','login');
1.51 raeburn 9478: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 9479: } else {
9480: @images = ('img');
1.200 raeburn 9481: @bgs = ('pgbg','tabbg','sidebg');
9482: }
9483: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
9484: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
9485: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
9486: }
9487: if ($role eq 'login') {
9488: foreach my $item (@logintext) {
1.234 raeburn 9489: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9490: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9491: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9492: }
9493: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 9494: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9495: }
9496: }
9497: } else {
1.234 raeburn 9498: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
9499: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
9500: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
9501: }
9502: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 9503: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
9504: }
1.6 raeburn 9505: }
1.200 raeburn 9506: foreach my $item (@bgs) {
1.234 raeburn 9507: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9508: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9509: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9510: }
9511: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 9512: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9513: }
9514: }
9515: foreach my $item (@links) {
1.234 raeburn 9516: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9517: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9518: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9519: }
9520: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 9521: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9522: }
1.6 raeburn 9523: }
1.46 raeburn 9524: my ($configuserok,$author_ok,$switchserver) =
9525: &config_check($dom,$confname,$servadm);
1.9 raeburn 9526: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 9527: if (ref($domconfig->{$role}) ne 'HASH') {
9528: $domconfig->{$role} = {};
9529: }
1.8 raeburn 9530: foreach my $img (@images) {
1.70 raeburn 9531: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
9532: if (defined($env{'form.login_showlogo_'.$img})) {
9533: $confhash->{$role}{'showlogo'}{$img} = 1;
9534: } else {
9535: $confhash->{$role}{'showlogo'}{$img} = 0;
9536: }
9537: }
1.18 albertel 9538: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
9539: && !defined($domconfig->{$role}{$img})
9540: && !$env{'form.'.$role.'_del_'.$img}
9541: && $env{'form.'.$role.'_import_'.$img}) {
9542: # import the old configured image from the .tab setting
9543: # if they haven't provided a new one
9544: $domconfig->{$role}{$img} =
9545: $env{'form.'.$role.'_import_'.$img};
9546: }
1.6 raeburn 9547: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 9548: my $error;
1.6 raeburn 9549: if ($configuserok eq 'ok') {
1.9 raeburn 9550: if ($switchserver) {
1.12 raeburn 9551: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 9552: } else {
9553: if ($author_ok eq 'ok') {
9554: my ($result,$logourl) =
9555: &publishlogo($r,'upload',$role.'_'.$img,
9556: $dom,$confname,$img,$width,$height);
9557: if ($result eq 'ok') {
9558: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 9559: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 9560: } else {
1.12 raeburn 9561: $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 9562: }
9563: } else {
1.46 raeburn 9564: $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 9565: }
9566: }
9567: } else {
1.46 raeburn 9568: $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 9569: }
9570: if ($error) {
1.8 raeburn 9571: &Apache::lonnet::logthis($error);
1.11 albertel 9572: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 9573: }
9574: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 9575: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
9576: my $error;
9577: if ($configuserok eq 'ok') {
9578: # is confname an author?
9579: if ($switchserver eq '') {
9580: if ($author_ok eq 'ok') {
9581: my ($result,$logourl) =
9582: &publishlogo($r,'copy',$domconfig->{$role}{$img},
9583: $dom,$confname,$img,$width,$height);
9584: if ($result eq 'ok') {
9585: $confhash->{$role}{$img} = $logourl;
1.18 albertel 9586: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 9587: }
9588: }
9589: }
9590: }
1.6 raeburn 9591: }
9592: }
9593: }
9594: if (ref($domconfig) eq 'HASH') {
9595: if (ref($domconfig->{$role}) eq 'HASH') {
9596: foreach my $img (@images) {
9597: if ($domconfig->{$role}{$img} ne '') {
9598: if ($env{'form.'.$role.'_del_'.$img}) {
9599: $confhash->{$role}{$img} = '';
1.12 raeburn 9600: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 9601: } else {
1.9 raeburn 9602: if ($confhash->{$role}{$img} eq '') {
9603: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
9604: }
1.6 raeburn 9605: }
9606: } else {
9607: if ($env{'form.'.$role.'_del_'.$img}) {
9608: $confhash->{$role}{$img} = '';
1.12 raeburn 9609: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 9610: }
9611: }
1.70 raeburn 9612: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
9613: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
9614: if ($confhash->{$role}{'showlogo'}{$img} ne
9615: $domconfig->{$role}{'showlogo'}{$img}) {
9616: $changes{$role}{'showlogo'}{$img} = 1;
9617: }
9618: } else {
9619: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
9620: $changes{$role}{'showlogo'}{$img} = 1;
9621: }
9622: }
9623: }
9624: }
1.6 raeburn 9625: if ($domconfig->{$role}{'font'} ne '') {
9626: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
9627: $changes{$role}{'font'} = 1;
9628: }
9629: } else {
9630: if ($confhash->{$role}{'font'}) {
9631: $changes{$role}{'font'} = 1;
9632: }
9633: }
1.107 raeburn 9634: if ($role ne 'login') {
9635: if ($domconfig->{$role}{'fontmenu'} ne '') {
9636: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
9637: $changes{$role}{'fontmenu'} = 1;
9638: }
9639: } else {
9640: if ($confhash->{$role}{'fontmenu'}) {
9641: $changes{$role}{'fontmenu'} = 1;
9642: }
1.97 tempelho 9643: }
9644: }
1.6 raeburn 9645: foreach my $item (@bgs) {
9646: if ($domconfig->{$role}{$item} ne '') {
9647: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9648: $changes{$role}{'bgs'}{$item} = 1;
9649: }
9650: } else {
9651: if ($confhash->{$role}{$item}) {
9652: $changes{$role}{'bgs'}{$item} = 1;
9653: }
9654: }
9655: }
9656: foreach my $item (@links) {
9657: if ($domconfig->{$role}{$item} ne '') {
9658: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9659: $changes{$role}{'links'}{$item} = 1;
9660: }
9661: } else {
9662: if ($confhash->{$role}{$item}) {
9663: $changes{$role}{'links'}{$item} = 1;
9664: }
9665: }
9666: }
1.41 raeburn 9667: foreach my $item (@logintext) {
9668: if ($domconfig->{$role}{$item} ne '') {
9669: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9670: $changes{$role}{'logintext'}{$item} = 1;
9671: }
9672: } else {
9673: if ($confhash->{$role}{$item}) {
9674: $changes{$role}{'logintext'}{$item} = 1;
9675: }
9676: }
9677: }
1.6 raeburn 9678: } else {
9679: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 9680: \@logintext,$confhash,\%changes);
1.6 raeburn 9681: }
9682: } else {
9683: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 9684: \@logintext,$confhash,\%changes);
1.6 raeburn 9685: }
9686: }
9687: return ($errors,%changes);
9688: }
9689:
1.46 raeburn 9690: sub config_check {
9691: my ($dom,$confname,$servadm) = @_;
9692: my ($configuserok,$author_ok,$switchserver,%currroles);
9693: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
9694: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
9695: $confname,$servadm);
9696: if ($configuserok eq 'ok') {
9697: $switchserver = &check_switchserver($dom,$confname);
9698: if ($switchserver eq '') {
9699: $author_ok = &check_authorstatus($dom,$confname,%currroles);
9700: }
9701: }
9702: return ($configuserok,$author_ok,$switchserver);
9703: }
9704:
1.6 raeburn 9705: sub default_change_checker {
1.41 raeburn 9706: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 9707: foreach my $item (@{$links}) {
9708: if ($confhash->{$role}{$item}) {
9709: $changes->{$role}{'links'}{$item} = 1;
9710: }
9711: }
9712: foreach my $item (@{$bgs}) {
9713: if ($confhash->{$role}{$item}) {
9714: $changes->{$role}{'bgs'}{$item} = 1;
9715: }
9716: }
1.41 raeburn 9717: foreach my $item (@{$logintext}) {
9718: if ($confhash->{$role}{$item}) {
9719: $changes->{$role}{'logintext'}{$item} = 1;
9720: }
9721: }
1.6 raeburn 9722: foreach my $img (@{$images}) {
9723: if ($env{'form.'.$role.'_del_'.$img}) {
9724: $confhash->{$role}{$img} = '';
1.12 raeburn 9725: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 9726: }
1.70 raeburn 9727: if ($role eq 'login') {
9728: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
9729: $changes->{$role}{'showlogo'}{$img} = 1;
9730: }
9731: }
1.6 raeburn 9732: }
9733: if ($confhash->{$role}{'font'}) {
9734: $changes->{$role}{'font'} = 1;
9735: }
1.48 raeburn 9736: }
1.6 raeburn 9737:
9738: sub display_colorchgs {
9739: my ($dom,$changes,$roles,$confhash) = @_;
9740: my (%choices,$resulttext);
9741: if (!grep(/^login$/,@{$roles})) {
9742: $resulttext = &mt('Changes made:').'<br />';
9743: }
9744: foreach my $role (@{$roles}) {
9745: if ($role eq 'login') {
9746: %choices = &login_choices();
9747: } else {
9748: %choices = &color_font_choices();
9749: }
9750: if (ref($changes->{$role}) eq 'HASH') {
9751: if ($role ne 'login') {
9752: $resulttext .= '<h4>'.&mt($role).'</h4>';
9753: }
9754: foreach my $key (sort(keys(%{$changes->{$role}}))) {
9755: if ($role ne 'login') {
9756: $resulttext .= '<ul>';
9757: }
9758: if (ref($changes->{$role}{$key}) eq 'HASH') {
9759: if ($role ne 'login') {
9760: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
9761: }
9762: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 9763: if (($role eq 'login') && ($key eq 'showlogo')) {
9764: if ($confhash->{$role}{$key}{$item}) {
9765: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
9766: } else {
9767: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
9768: }
9769: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 9770: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
9771: } else {
1.12 raeburn 9772: my $newitem = $confhash->{$role}{$item};
9773: if ($key eq 'images') {
1.306 raeburn 9774: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 9775: }
9776: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 9777: }
9778: }
9779: if ($role ne 'login') {
9780: $resulttext .= '</ul></li>';
9781: }
9782: } else {
9783: if ($confhash->{$role}{$key} eq '') {
9784: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
9785: } else {
9786: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
9787: }
9788: }
9789: if ($role ne 'login') {
9790: $resulttext .= '</ul>';
9791: }
9792: }
9793: }
9794: }
1.3 raeburn 9795: return $resulttext;
1.1 raeburn 9796: }
9797:
1.9 raeburn 9798: sub thumb_dimensions {
9799: return ('200','50');
9800: }
9801:
1.16 raeburn 9802: sub check_dimensions {
9803: my ($inputfile) = @_;
9804: my ($fullwidth,$fullheight);
9805: if ($inputfile =~ m|^[/\w.\-]+$|) {
9806: if (open(PIPE,"identify $inputfile 2>&1 |")) {
9807: my $imageinfo = <PIPE>;
9808: if (!close(PIPE)) {
9809: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
9810: }
9811: chomp($imageinfo);
9812: my ($fullsize) =
1.21 raeburn 9813: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 9814: if ($fullsize) {
9815: ($fullwidth,$fullheight) = split(/x/,$fullsize);
9816: }
9817: }
9818: }
9819: return ($fullwidth,$fullheight);
9820: }
9821:
1.9 raeburn 9822: sub check_configuser {
9823: my ($uhome,$dom,$confname,$servadm) = @_;
9824: my ($configuserok,%currroles);
9825: if ($uhome eq 'no_host') {
9826: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
9827: my $configpass = &LONCAPA::Enrollment::create_password();
9828: $configuserok =
9829: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
9830: $configpass,'','','','','',undef,$servadm);
9831: } else {
9832: $configuserok = 'ok';
9833: %currroles =
9834: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
9835: }
9836: return ($configuserok,%currroles);
9837: }
9838:
9839: sub check_authorstatus {
9840: my ($dom,$confname,%currroles) = @_;
9841: my $author_ok;
1.40 raeburn 9842: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 9843: my $start = time;
9844: my $end = 0;
9845: $author_ok =
9846: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 9847: 'au',$end,$start,'','','domconfig');
1.9 raeburn 9848: } else {
9849: $author_ok = 'ok';
9850: }
9851: return $author_ok;
9852: }
9853:
9854: sub publishlogo {
1.46 raeburn 9855: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 9856: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 9857: if ($action eq 'upload') {
9858: $fname=$env{'form.'.$formname.'.filename'};
9859: chop($env{'form.'.$formname});
9860: } else {
9861: ($fname) = ($formname =~ /([^\/]+)$/);
9862: }
1.46 raeburn 9863: if ($savefileas ne '') {
9864: $fname = $savefileas;
9865: }
1.9 raeburn 9866: $fname=&Apache::lonnet::clean_filename($fname);
9867: # See if there is anything left
9868: unless ($fname) { return ('error: no uploaded file'); }
9869: $fname="$subdir/$fname";
1.210 raeburn 9870: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 9871: my $filepath="$docroot/priv";
9872: my $relpath = "$dom/$confname";
1.9 raeburn 9873: my ($fnamepath,$file,$fetchthumb);
9874: $file=$fname;
9875: if ($fname=~m|/|) {
9876: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
9877: }
1.164 raeburn 9878: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 9879: my $count;
1.164 raeburn 9880: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 9881: $filepath.="/$parts[$count]";
9882: if ((-e $filepath)!=1) {
9883: mkdir($filepath,02770);
9884: }
9885: }
9886: # Check for bad extension and disallow upload
9887: if ($file=~/\.(\w+)$/ &&
9888: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
9889: $output =
1.207 bisitz 9890: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 9891: } elsif ($file=~/\.(\w+)$/ &&
9892: !defined(&Apache::loncommon::fileembstyle($1))) {
9893: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
9894: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 9895: $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 9896: } elsif (-d "$filepath/$file") {
1.195 bisitz 9897: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 9898: } else {
9899: my $source = $filepath.'/'.$file;
9900: my $logfile;
1.316 raeburn 9901: if (!open($logfile,">>",$source.'.log')) {
1.196 raeburn 9902: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 9903: }
9904: print $logfile
9905: "\n================= Publish ".localtime()." ================\n".
9906: $env{'user.name'}.':'.$env{'user.domain'}."\n";
9907: # Save the file
1.316 raeburn 9908: if (!open(FH,">",$source)) {
1.9 raeburn 9909: &Apache::lonnet::logthis('Failed to create '.$source);
9910: return (&mt('Failed to create file'));
9911: }
9912: if ($action eq 'upload') {
9913: if (!print FH ($env{'form.'.$formname})) {
9914: &Apache::lonnet::logthis('Failed to write to '.$source);
9915: return (&mt('Failed to write file'));
9916: }
9917: } else {
9918: my $original = &Apache::lonnet::filelocation('',$formname);
9919: if(!copy($original,$source)) {
9920: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
9921: return (&mt('Failed to write file'));
9922: }
9923: }
9924: close(FH);
9925: chmod(0660, $source); # Permissions to rw-rw---.
9926:
9927: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
9928: my $copyfile=$targetdir.'/'.$file;
9929:
9930: my @parts=split(/\//,$targetdir);
9931: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
9932: for (my $count=5;$count<=$#parts;$count++) {
9933: $path.="/$parts[$count]";
9934: if (!-e $path) {
9935: print $logfile "\nCreating directory ".$path;
9936: mkdir($path,02770);
9937: }
9938: }
9939: my $versionresult;
9940: if (-e $copyfile) {
9941: $versionresult = &logo_versioning($targetdir,$file,$logfile);
9942: } else {
9943: $versionresult = 'ok';
9944: }
9945: if ($versionresult eq 'ok') {
9946: if (copy($source,$copyfile)) {
9947: print $logfile "\nCopied original source to ".$copyfile."\n";
9948: $output = 'ok';
9949: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 9950: push(@{$modified_urls},[$copyfile,$source]);
9951: my $metaoutput =
9952: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
9953: unless ($registered_cleanup) {
9954: my $handlers = $r->get_handlers('PerlCleanupHandler');
9955: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
9956: $registered_cleanup=1;
9957: }
1.9 raeburn 9958: } else {
9959: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
9960: $output = &mt('Failed to copy file to RES space').", $!";
9961: }
9962: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
9963: my $inputfile = $filepath.'/'.$file;
9964: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 9965: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
9966: if ($fullwidth ne '' && $fullheight ne '') {
9967: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
9968: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316 raeburn 9969: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
9970: system({$args[0]} @args);
1.16 raeburn 9971: chmod(0660, $filepath.'/tn-'.$file);
9972: if (-e $outfile) {
9973: my $copyfile=$targetdir.'/tn-'.$file;
9974: if (copy($outfile,$copyfile)) {
9975: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 9976: my $thumb_metaoutput =
9977: &write_metadata($dom,$confname,$formname,
9978: $targetdir,'tn-'.$file,$logfile);
9979: push(@{$modified_urls},[$copyfile,$outfile]);
9980: unless ($registered_cleanup) {
9981: my $handlers = $r->get_handlers('PerlCleanupHandler');
9982: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
9983: $registered_cleanup=1;
9984: }
1.267 raeburn 9985: $madethumb = 1;
1.16 raeburn 9986: } else {
9987: print $logfile "\nUnable to write ".$copyfile.
9988: ':'.$!."\n";
9989: }
9990: }
1.9 raeburn 9991: }
9992: }
9993: }
9994: } else {
9995: $output = $versionresult;
9996: }
9997: }
1.267 raeburn 9998: return ($output,$logourl,$madethumb);
1.9 raeburn 9999: }
10000:
10001: sub logo_versioning {
10002: my ($targetdir,$file,$logfile) = @_;
10003: my $target = $targetdir.'/'.$file;
10004: my ($maxversion,$fn,$extn,$output);
10005: $maxversion = 0;
10006: if ($file =~ /^(.+)\.(\w+)$/) {
10007: $fn=$1;
10008: $extn=$2;
10009: }
10010: opendir(DIR,$targetdir);
10011: while (my $filename=readdir(DIR)) {
10012: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
10013: $maxversion=($1>$maxversion)?$1:$maxversion;
10014: }
10015: }
10016: $maxversion++;
10017: print $logfile "\nCreating old version ".$maxversion."\n";
10018: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
10019: if (copy($target,$copyfile)) {
10020: print $logfile "Copied old target to ".$copyfile."\n";
10021: $copyfile=$copyfile.'.meta';
10022: if (copy($target.'.meta',$copyfile)) {
10023: print $logfile "Copied old target metadata to ".$copyfile."\n";
10024: $output = 'ok';
10025: } else {
10026: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
10027: $output = &mt('Failed to copy old meta').", $!, ";
10028: }
10029: } else {
10030: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
10031: $output = &mt('Failed to copy old target').", $!, ";
10032: }
10033: return $output;
10034: }
10035:
10036: sub write_metadata {
10037: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
10038: my (%metadatafields,%metadatakeys,$output);
10039: $metadatafields{'title'}=$formname;
10040: $metadatafields{'creationdate'}=time;
10041: $metadatafields{'lastrevisiondate'}=time;
10042: $metadatafields{'copyright'}='public';
10043: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
10044: $env{'user.domain'};
10045: $metadatafields{'authorspace'}=$confname.':'.$dom;
10046: $metadatafields{'domain'}=$dom;
10047: {
10048: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
10049: my $mfh;
1.316 raeburn 10050: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 10051: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 10052: unless ($_=~/\./) {
10053: my $unikey=$_;
10054: $unikey=~/^([A-Za-z]+)/;
10055: my $tag=$1;
10056: $tag=~tr/A-Z/a-z/;
10057: print $mfh "\n\<$tag";
10058: foreach (split(/\,/,$metadatakeys{$unikey})) {
10059: my $value=$metadatafields{$unikey.'.'.$_};
10060: $value=~s/\"/\'\'/g;
10061: print $mfh ' '.$_.'="'.$value.'"';
10062: }
10063: print $mfh '>'.
10064: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
10065: .'</'.$tag.'>';
10066: }
10067: }
10068: $output = 'ok';
10069: print $logfile "\nWrote metadata";
10070: close($mfh);
10071: } else {
10072: print $logfile "\nFailed to open metadata file";
1.9 raeburn 10073: $output = &mt('Could not write metadata');
10074: }
10075: }
1.155 raeburn 10076: return $output;
10077: }
10078:
10079: sub notifysubscribed {
10080: foreach my $targetsource (@{$modified_urls}){
10081: next unless (ref($targetsource) eq 'ARRAY');
10082: my ($target,$source)=@{$targetsource};
10083: if ($source ne '') {
1.316 raeburn 10084: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 10085: print $logfh "\nCleanup phase: Notifications\n";
10086: my @subscribed=&subscribed_hosts($target);
10087: foreach my $subhost (@subscribed) {
10088: print $logfh "\nNotifying host ".$subhost.':';
10089: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
10090: print $logfh $reply;
10091: }
10092: my @subscribedmeta=&subscribed_hosts("$target.meta");
10093: foreach my $subhost (@subscribedmeta) {
10094: print $logfh "\nNotifying host for metadata only ".$subhost.':';
10095: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
10096: $subhost);
10097: print $logfh $reply;
10098: }
10099: print $logfh "\n============ Done ============\n";
1.160 raeburn 10100: close($logfh);
1.155 raeburn 10101: }
10102: }
10103: }
10104: return OK;
10105: }
10106:
10107: sub subscribed_hosts {
10108: my ($target) = @_;
10109: my @subscribed;
1.316 raeburn 10110: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 10111: while (my $subline=<$fh>) {
10112: if ($subline =~ /^($match_lonid):/) {
10113: my $host = $1;
10114: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
10115: unless (grep(/^\Q$host\E$/,@subscribed)) {
10116: push(@subscribed,$host);
10117: }
10118: }
10119: }
10120: }
10121: }
10122: return @subscribed;
1.9 raeburn 10123: }
10124:
10125: sub check_switchserver {
10126: my ($dom,$confname) = @_;
10127: my ($allowed,$switchserver);
10128: my $home = &Apache::lonnet::homeserver($confname,$dom);
10129: if ($home eq 'no_host') {
10130: $home = &Apache::lonnet::domain($dom,'primary');
10131: }
10132: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 10133: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
10134: if (!$allowed) {
1.180 raeburn 10135: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 10136: }
10137: return $switchserver;
10138: }
10139:
1.1 raeburn 10140: sub modify_quotas {
1.216 raeburn 10141: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 10142: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 10143: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 10144: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
10145: $validationfieldsref);
1.86 raeburn 10146: if ($action eq 'quotas') {
10147: $context = 'tools';
1.163 raeburn 10148: } else {
1.86 raeburn 10149: $context = $action;
10150: }
10151: if ($context eq 'requestcourses') {
1.325 raeburn 10152: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 10153: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 10154: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
10155: %titles = &courserequest_titles();
10156: $toolregexp = join('|',@usertools);
10157: %conditions = &courserequest_conditions();
1.216 raeburn 10158: $confname = $dom.'-domainconfig';
10159: my $servadm = $r->dir_config('lonAdmEMail');
10160: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 10161: ($validationitemsref,$validationnamesref,$validationfieldsref) =
10162: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 10163: } elsif ($context eq 'requestauthor') {
10164: @usertools = ('author');
10165: %titles = &authorrequest_titles();
1.86 raeburn 10166: } else {
1.162 raeburn 10167: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 10168: %titles = &tool_titles();
1.86 raeburn 10169: }
1.212 raeburn 10170: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 10171: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 10172: foreach my $key (keys(%env)) {
1.101 raeburn 10173: if ($context eq 'requestcourses') {
10174: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
10175: my $item = $1;
10176: my $type = $2;
10177: if ($type =~ /^limit_(.+)/) {
10178: $limithash{$item}{$1} = $env{$key};
10179: } else {
10180: $confhash{$item}{$type} = $env{$key};
10181: }
10182: }
1.163 raeburn 10183: } elsif ($context eq 'requestauthor') {
10184: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
10185: $confhash{$1} = $env{$key};
10186: }
1.101 raeburn 10187: } else {
1.86 raeburn 10188: if ($key =~ /^form\.quota_(.+)$/) {
10189: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 10190: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
10191: $confhash{'authorquota'}{$1} = $env{$key};
10192: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 10193: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
10194: }
1.72 raeburn 10195: }
10196: }
1.163 raeburn 10197: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 10198: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 10199: @approvalnotify = sort(@approvalnotify);
10200: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 10201: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 10202: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
10203: foreach my $type (@hasuniquecode) {
10204: if (grep(/^\Q$type\E$/,@crstypes)) {
10205: $confhash{'uniquecode'}{$type} = 1;
10206: }
1.216 raeburn 10207: }
1.242 raeburn 10208: my (%newbook,%allpos);
1.216 raeburn 10209: if ($context eq 'requestcourses') {
1.242 raeburn 10210: foreach my $type ('textbooks','templates') {
10211: @{$allpos{$type}} = ();
10212: my $invalid;
10213: if ($type eq 'textbooks') {
10214: $invalid = &mt('Invalid LON-CAPA course for textbook');
10215: } else {
10216: $invalid = &mt('Invalid LON-CAPA course for template');
10217: }
10218: if ($env{'form.'.$type.'_addbook'}) {
10219: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
10220: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
10221: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
10222: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
10223: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
10224: } else {
10225: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
10226: my $position = $env{'form.'.$type.'_addbook_pos'};
10227: $position =~ s/\D+//g;
10228: if ($position ne '') {
10229: $allpos{$type}[$position] = $newbook{$type};
10230: }
1.216 raeburn 10231: }
1.242 raeburn 10232: } else {
10233: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 10234: }
10235: }
1.242 raeburn 10236: }
1.216 raeburn 10237: }
1.102 raeburn 10238: if (ref($domconfig{$action}) eq 'HASH') {
10239: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
10240: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
10241: $changes{'notify'}{'approval'} = 1;
10242: }
10243: } else {
1.144 raeburn 10244: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10245: $changes{'notify'}{'approval'} = 1;
10246: }
10247: }
1.218 raeburn 10248: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
10249: if (ref($confhash{'uniquecode'}) eq 'HASH') {
10250: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
10251: unless ($confhash{'uniquecode'}{$crstype}) {
10252: $changes{'uniquecode'} = 1;
10253: }
10254: }
10255: unless ($changes{'uniquecode'}) {
10256: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
10257: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
10258: $changes{'uniquecode'} = 1;
10259: }
10260: }
10261: }
10262: } else {
10263: $changes{'uniquecode'} = 1;
10264: }
10265: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
10266: $changes{'uniquecode'} = 1;
1.216 raeburn 10267: }
10268: if ($context eq 'requestcourses') {
1.242 raeburn 10269: foreach my $type ('textbooks','templates') {
10270: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10271: my %deletions;
10272: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
10273: if (@todelete) {
10274: map { $deletions{$_} = 1; } @todelete;
10275: }
10276: my %imgdeletions;
10277: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
10278: if (@todeleteimages) {
10279: map { $imgdeletions{$_} = 1; } @todeleteimages;
10280: }
10281: my $maxnum = $env{'form.'.$type.'_maxnum'};
10282: for (my $i=0; $i<=$maxnum; $i++) {
10283: my $itemid = $env{'form.'.$type.'_id_'.$i};
10284: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
10285: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
10286: if ($deletions{$key}) {
10287: if ($domconfig{$action}{$type}{$key}{'image'}) {
10288: #FIXME need to obsolete item in RES space
10289: }
10290: next;
10291: } else {
10292: my $newpos = $env{'form.'.$itemid};
10293: $newpos =~ s/\D+//g;
1.243 raeburn 10294: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 10295: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 10296: ($type eq 'templates'));
1.242 raeburn 10297: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
10298: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
10299: $changes{$type}{$key} = 1;
10300: }
10301: }
10302: $allpos{$type}[$newpos] = $key;
10303: }
10304: if ($imgdeletions{$key}) {
10305: $changes{$type}{$key} = 1;
1.216 raeburn 10306: #FIXME need to obsolete item in RES space
1.242 raeburn 10307: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
10308: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 10309: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10310: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10311: } else {
10312: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
10313: $cdom,$cnum,$type,$configuserok,
10314: $switchserver,$author_ok);
10315: if ($imgurl) {
10316: $confhash{$type}{$key}{'image'} = $imgurl;
10317: $changes{$type}{$key} = 1;
10318: }
10319: if ($error) {
10320: &Apache::lonnet::logthis($error);
10321: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10322: }
10323: }
1.242 raeburn 10324: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
10325: $confhash{$type}{$key}{'image'} =
10326: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 10327: }
10328: }
10329: }
10330: }
10331: }
10332: }
1.102 raeburn 10333: } else {
1.144 raeburn 10334: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10335: $changes{'notify'}{'approval'} = 1;
10336: }
1.218 raeburn 10337: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 10338: $changes{'uniquecode'} = 1;
10339: }
10340: }
10341: if ($context eq 'requestcourses') {
1.242 raeburn 10342: foreach my $type ('textbooks','templates') {
10343: if ($newbook{$type}) {
10344: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 10345: foreach my $item ('subject','title','publisher','author') {
10346: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10347: ($type eq 'template'));
1.242 raeburn 10348: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
10349: if ($env{'form.'.$type.'_addbook_'.$item}) {
10350: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
10351: }
10352: }
10353: if ($type eq 'textbooks') {
10354: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
10355: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 10356: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10357: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10358: } else {
10359: my ($imageurl,$error) =
10360: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
10361: $configuserok,$switchserver,$author_ok);
10362: if ($imageurl) {
10363: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
10364: }
10365: if ($error) {
10366: &Apache::lonnet::logthis($error);
10367: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10368: }
1.242 raeburn 10369: }
10370: }
1.216 raeburn 10371: }
10372: }
1.242 raeburn 10373: if (@{$allpos{$type}} > 0) {
10374: my $idx = 0;
10375: foreach my $item (@{$allpos{$type}}) {
10376: if ($item ne '') {
10377: $confhash{$type}{$item}{'order'} = $idx;
10378: if (ref($domconfig{$action}) eq 'HASH') {
10379: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10380: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
10381: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
10382: $changes{$type}{$item} = 1;
10383: }
1.216 raeburn 10384: }
10385: }
10386: }
1.242 raeburn 10387: $idx ++;
1.216 raeburn 10388: }
10389: }
10390: }
10391: }
1.235 raeburn 10392: if (ref($validationitemsref) eq 'ARRAY') {
10393: foreach my $item (@{$validationitemsref}) {
10394: if ($item eq 'fields') {
10395: my @changed;
10396: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
10397: if (@{$confhash{'validation'}{$item}} > 0) {
10398: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
10399: }
1.266 raeburn 10400: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10401: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10402: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
10403: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
10404: $domconfig{'requestcourses'}{'validation'}{$item});
10405: } else {
10406: @changed = @{$confhash{'validation'}{$item}};
10407: }
1.235 raeburn 10408: } else {
10409: @changed = @{$confhash{'validation'}{$item}};
10410: }
10411: } else {
10412: @changed = @{$confhash{'validation'}{$item}};
10413: }
10414: if (@changed) {
10415: if ($confhash{'validation'}{$item}) {
10416: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
10417: } else {
10418: $changes{'validation'}{$item} = &mt('None');
10419: }
10420: }
10421: } else {
10422: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
10423: if ($item eq 'markup') {
10424: if ($env{'form.requestcourses_validation_'.$item}) {
10425: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10426: }
10427: }
1.266 raeburn 10428: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10429: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10430: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
10431: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10432: }
10433: } else {
10434: if ($confhash{'validation'}{$item} ne '') {
10435: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10436: }
1.235 raeburn 10437: }
10438: } else {
10439: if ($confhash{'validation'}{$item} ne '') {
10440: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10441: }
10442: }
10443: }
10444: }
10445: }
10446: if ($env{'form.validationdc'}) {
10447: my $newval = $env{'form.validationdc'};
1.285 raeburn 10448: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 10449: if (exists($domcoords{$newval})) {
10450: $confhash{'validation'}{'dc'} = $newval;
10451: }
10452: }
10453: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 10454: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10455: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10456: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10457: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
10458: if ($confhash{'validation'}{'dc'} eq '') {
10459: $changes{'validation'}{'dc'} = &mt('None');
10460: } else {
10461: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10462: }
1.235 raeburn 10463: }
1.266 raeburn 10464: } elsif ($confhash{'validation'}{'dc'} ne '') {
10465: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 10466: }
10467: } elsif ($confhash{'validation'}{'dc'} ne '') {
10468: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10469: }
10470: } elsif ($confhash{'validation'}{'dc'} ne '') {
10471: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 10472: }
1.266 raeburn 10473: } else {
10474: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10475: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10476: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10477: $changes{'validation'}{'dc'} = &mt('None');
10478: }
10479: }
1.235 raeburn 10480: }
10481: }
1.102 raeburn 10482: }
10483: } else {
1.86 raeburn 10484: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 10485: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 10486: }
1.72 raeburn 10487: foreach my $item (@usertools) {
10488: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 10489: my $unset;
1.101 raeburn 10490: if ($context eq 'requestcourses') {
1.104 raeburn 10491: $unset = '0';
10492: if ($type eq '_LC_adv') {
10493: $unset = '';
10494: }
1.101 raeburn 10495: if ($confhash{$item}{$type} eq 'autolimit') {
10496: $confhash{$item}{$type} .= '=';
10497: unless ($limithash{$item}{$type} =~ /\D/) {
10498: $confhash{$item}{$type} .= $limithash{$item}{$type};
10499: }
10500: }
1.163 raeburn 10501: } elsif ($context eq 'requestauthor') {
10502: $unset = '0';
10503: if ($type eq '_LC_adv') {
10504: $unset = '';
10505: }
1.72 raeburn 10506: } else {
1.101 raeburn 10507: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
10508: $confhash{$item}{$type} = 1;
10509: } else {
10510: $confhash{$item}{$type} = 0;
10511: }
1.72 raeburn 10512: }
1.86 raeburn 10513: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 10514: if ($action eq 'requestauthor') {
10515: if ($domconfig{$action}{$type} ne $confhash{$type}) {
10516: $changes{$type} = 1;
10517: }
10518: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 10519: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
10520: $changes{$item}{$type} = 1;
10521: }
10522: } else {
10523: if ($context eq 'requestcourses') {
1.104 raeburn 10524: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 10525: $changes{$item}{$type} = 1;
10526: }
10527: } else {
10528: if (!$confhash{$item}{$type}) {
10529: $changes{$item}{$type} = 1;
10530: }
10531: }
10532: }
10533: } else {
10534: if ($context eq 'requestcourses') {
1.104 raeburn 10535: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 10536: $changes{$item}{$type} = 1;
10537: }
1.163 raeburn 10538: } elsif ($context eq 'requestauthor') {
10539: if ($confhash{$type} ne $unset) {
10540: $changes{$type} = 1;
10541: }
1.72 raeburn 10542: } else {
10543: if (!$confhash{$item}{$type}) {
10544: $changes{$item}{$type} = 1;
10545: }
10546: }
10547: }
1.1 raeburn 10548: }
10549: }
1.163 raeburn 10550: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 10551: if (ref($domconfig{'quotas'}) eq 'HASH') {
10552: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
10553: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
10554: if (exists($confhash{'defaultquota'}{$key})) {
10555: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
10556: $changes{'defaultquota'}{$key} = 1;
10557: }
10558: } else {
10559: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 10560: }
10561: }
1.86 raeburn 10562: } else {
10563: foreach my $key (keys(%{$domconfig{'quotas'}})) {
10564: if (exists($confhash{'defaultquota'}{$key})) {
10565: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
10566: $changes{'defaultquota'}{$key} = 1;
10567: }
10568: } else {
10569: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 10570: }
1.1 raeburn 10571: }
10572: }
1.197 raeburn 10573: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
10574: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
10575: if (exists($confhash{'authorquota'}{$key})) {
10576: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
10577: $changes{'authorquota'}{$key} = 1;
10578: }
10579: } else {
10580: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
10581: }
10582: }
10583: }
1.1 raeburn 10584: }
1.86 raeburn 10585: if (ref($confhash{'defaultquota'}) eq 'HASH') {
10586: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
10587: if (ref($domconfig{'quotas'}) eq 'HASH') {
10588: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
10589: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
10590: $changes{'defaultquota'}{$key} = 1;
10591: }
10592: } else {
10593: if (!exists($domconfig{'quotas'}{$key})) {
10594: $changes{'defaultquota'}{$key} = 1;
10595: }
1.72 raeburn 10596: }
10597: } else {
1.86 raeburn 10598: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 10599: }
1.1 raeburn 10600: }
10601: }
1.197 raeburn 10602: if (ref($confhash{'authorquota'}) eq 'HASH') {
10603: foreach my $key (keys(%{$confhash{'authorquota'}})) {
10604: if (ref($domconfig{'quotas'}) eq 'HASH') {
10605: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
10606: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
10607: $changes{'authorquota'}{$key} = 1;
10608: }
10609: } else {
10610: $changes{'authorquota'}{$key} = 1;
10611: }
10612: } else {
10613: $changes{'authorquota'}{$key} = 1;
10614: }
10615: }
10616: }
1.1 raeburn 10617: }
1.72 raeburn 10618:
1.163 raeburn 10619: if ($context eq 'requestauthor') {
10620: $domdefaults{'requestauthor'} = \%confhash;
10621: } else {
10622: foreach my $key (keys(%confhash)) {
1.242 raeburn 10623: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 10624: $domdefaults{$key} = $confhash{$key};
10625: }
1.163 raeburn 10626: }
1.72 raeburn 10627: }
1.163 raeburn 10628:
1.1 raeburn 10629: my %quotahash = (
1.86 raeburn 10630: $action => { %confhash }
1.1 raeburn 10631: );
10632: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
10633: $dom);
10634: if ($putresult eq 'ok') {
10635: if (keys(%changes) > 0) {
1.72 raeburn 10636: my $cachetime = 24*60*60;
10637: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 10638: if (ref($lastactref) eq 'HASH') {
10639: $lastactref->{'domdefaults'} = 1;
10640: }
1.1 raeburn 10641: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 10642: unless (($context eq 'requestcourses') ||
1.163 raeburn 10643: ($context eq 'requestauthor')) {
1.86 raeburn 10644: if (ref($changes{'defaultquota'}) eq 'HASH') {
10645: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
10646: foreach my $type (@{$types},'default') {
10647: if (defined($changes{'defaultquota'}{$type})) {
10648: my $typetitle = $usertypes->{$type};
10649: if ($type eq 'default') {
10650: $typetitle = $othertitle;
10651: }
1.213 raeburn 10652: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 10653: }
10654: }
1.86 raeburn 10655: $resulttext .= '</ul></li>';
1.72 raeburn 10656: }
1.197 raeburn 10657: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 10658: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 10659: foreach my $type (@{$types},'default') {
10660: if (defined($changes{'authorquota'}{$type})) {
10661: my $typetitle = $usertypes->{$type};
10662: if ($type eq 'default') {
10663: $typetitle = $othertitle;
10664: }
1.213 raeburn 10665: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 10666: }
10667: }
10668: $resulttext .= '</ul></li>';
10669: }
1.72 raeburn 10670: }
1.80 raeburn 10671: my %newenv;
1.72 raeburn 10672: foreach my $item (@usertools) {
1.163 raeburn 10673: my (%haschgs,%inconf);
10674: if ($context eq 'requestauthor') {
10675: %haschgs = %changes;
1.210 raeburn 10676: %inconf = %confhash;
1.163 raeburn 10677: } else {
10678: if (ref($changes{$item}) eq 'HASH') {
10679: %haschgs = %{$changes{$item}};
10680: }
10681: if (ref($confhash{$item}) eq 'HASH') {
10682: %inconf = %{$confhash{$item}};
10683: }
10684: }
10685: if (keys(%haschgs) > 0) {
1.80 raeburn 10686: my $newacc =
10687: &Apache::lonnet::usertools_access($env{'user.name'},
10688: $env{'user.domain'},
1.86 raeburn 10689: $item,'reload',$context);
1.210 raeburn 10690: if (($context eq 'requestcourses') ||
1.163 raeburn 10691: ($context eq 'requestauthor')) {
1.108 raeburn 10692: if ($env{'environment.canrequest.'.$item} ne $newacc) {
10693: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 10694: }
10695: } else {
10696: if ($env{'environment.availabletools.'.$item} ne $newacc) {
10697: $newenv{'environment.availabletools.'.$item} = $newacc;
10698: }
1.80 raeburn 10699: }
1.163 raeburn 10700: unless ($context eq 'requestauthor') {
10701: $resulttext .= '<li>'.$titles{$item}.'<ul>';
10702: }
1.72 raeburn 10703: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 10704: if ($haschgs{$type}) {
1.72 raeburn 10705: my $typetitle = $usertypes->{$type};
10706: if ($type eq 'default') {
10707: $typetitle = $othertitle;
10708: } elsif ($type eq '_LC_adv') {
10709: $typetitle = 'LON-CAPA Advanced Users';
10710: }
1.163 raeburn 10711: if ($inconf{$type}) {
1.101 raeburn 10712: if ($context eq 'requestcourses') {
10713: my $cond;
1.163 raeburn 10714: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 10715: if ($1 eq '') {
10716: $cond = &mt('(Automatic processing of any request).');
10717: } else {
10718: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
10719: }
10720: } else {
1.163 raeburn 10721: $cond = $conditions{$inconf{$type}};
1.101 raeburn 10722: }
10723: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 10724: } elsif ($context eq 'requestauthor') {
10725: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
10726: $titles{$inconf{$type}},$typetitle);
10727:
1.101 raeburn 10728: } else {
10729: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
10730: }
1.72 raeburn 10731: } else {
1.104 raeburn 10732: if ($type eq '_LC_adv') {
1.163 raeburn 10733: if ($inconf{$type} eq '0') {
1.104 raeburn 10734: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
10735: } else {
10736: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
10737: }
10738: } else {
10739: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
10740: }
1.72 raeburn 10741: }
10742: }
1.26 raeburn 10743: }
1.163 raeburn 10744: unless ($context eq 'requestauthor') {
10745: $resulttext .= '</ul></li>';
10746: }
1.26 raeburn 10747: }
1.1 raeburn 10748: }
1.163 raeburn 10749: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 10750: if (ref($changes{'notify'}) eq 'HASH') {
10751: if ($changes{'notify'}{'approval'}) {
10752: if (ref($confhash{'notify'}) eq 'HASH') {
10753: if ($confhash{'notify'}{'approval'}) {
10754: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
10755: } else {
1.163 raeburn 10756: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 10757: }
10758: }
10759: }
10760: }
10761: }
1.216 raeburn 10762: if ($action eq 'requestcourses') {
10763: my @offon = ('off','on');
10764: if ($changes{'uniquecode'}) {
1.218 raeburn 10765: if (ref($confhash{'uniquecode'}) eq 'HASH') {
10766: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
10767: $resulttext .= '<li>'.
10768: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
10769: '</li>';
10770: } else {
10771: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
10772: '</li>';
10773: }
1.216 raeburn 10774: }
1.242 raeburn 10775: foreach my $type ('textbooks','templates') {
10776: if (ref($changes{$type}) eq 'HASH') {
10777: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
10778: foreach my $key (sort(keys(%{$changes{$type}}))) {
10779: my %coursehash = &Apache::lonnet::coursedescription($key);
10780: my $coursetitle = $coursehash{'description'};
10781: my $position = $confhash{$type}{$key}{'order'} + 1;
10782: $resulttext .= '<li>';
1.243 raeburn 10783: foreach my $item ('subject','title','publisher','author') {
10784: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10785: ($type eq 'templates'));
1.242 raeburn 10786: my $name = $item.':';
10787: $name =~ s/^(\w)/\U$1/;
10788: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
10789: }
10790: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
10791: if ($type eq 'textbooks') {
10792: if ($confhash{$type}{$key}{'image'}) {
10793: $resulttext .= ' '.&mt('Image: [_1]',
10794: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
10795: ' alt="Textbook cover" />').'<br />';
10796: }
10797: }
10798: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 10799: }
1.242 raeburn 10800: $resulttext .= '</ul></li>';
1.216 raeburn 10801: }
10802: }
1.235 raeburn 10803: if (ref($changes{'validation'}) eq 'HASH') {
10804: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
10805: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
10806: foreach my $item (@{$validationitemsref}) {
10807: if (exists($changes{'validation'}{$item})) {
10808: if ($item eq 'markup') {
10809: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
10810: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
10811: } else {
10812: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
10813: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
10814: }
10815: }
10816: }
10817: if (exists($changes{'validation'}{'dc'})) {
10818: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
10819: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
10820: }
10821: }
10822: }
1.216 raeburn 10823: }
1.1 raeburn 10824: $resulttext .= '</ul>';
1.80 raeburn 10825: if (keys(%newenv)) {
10826: &Apache::lonnet::appenv(\%newenv);
10827: }
1.1 raeburn 10828: } else {
1.86 raeburn 10829: if ($context eq 'requestcourses') {
10830: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 10831: } elsif ($context eq 'requestauthor') {
10832: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 10833: } else {
1.90 weissno 10834: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 10835: }
1.1 raeburn 10836: }
10837: } else {
1.11 albertel 10838: $resulttext = '<span class="LC_error">'.
10839: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10840: }
1.216 raeburn 10841: if ($errors) {
10842: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
10843: '<ul>'.$errors.'</ul></p>';
10844: }
1.3 raeburn 10845: return $resulttext;
1.1 raeburn 10846: }
10847:
1.216 raeburn 10848: sub process_textbook_image {
1.242 raeburn 10849: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 10850: my $filename = $env{'form.'.$caller.'.filename'};
10851: my ($error,$url);
10852: my ($width,$height) = (50,50);
10853: if ($configuserok eq 'ok') {
10854: if ($switchserver) {
10855: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
10856: $switchserver);
10857: } elsif ($author_ok eq 'ok') {
10858: my ($result,$imageurl) =
10859: &publishlogo($r,'upload',$caller,$dom,$confname,
1.312 raeburn 10860: "$type/$cdom/$cnum/cover",$width,$height);
1.216 raeburn 10861: if ($result eq 'ok') {
10862: $url = $imageurl;
10863: } else {
10864: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
10865: }
10866: } else {
10867: $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);
10868: }
10869: } else {
10870: $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);
10871: }
10872: return ($url,$error);
10873: }
10874:
1.267 raeburn 10875: sub modify_ltitools {
10876: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
10877: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 10878: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 10879: my $confname = $dom.'-domainconfig';
10880: my $servadm = $r->dir_config('lonAdmEMail');
10881: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10882: my (%posslti,%possfield);
10883: my @courseroles = ('cc','in','ta','ep','st');
10884: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
10885: map { $posslti{$_} = 1; } @ltiroles;
10886: my @allfields = ('fullname','firstname','lastname','email','user','roles');
10887: map { $possfield{$_} = 1; } @allfields;
10888: my %lt = <itools_names();
10889: if ($env{'form.ltitools_add'}) {
10890: my $title = $env{'form.ltitools_add_title'};
10891: $title =~ s/(`)/'/g;
10892: ($newid,my $error) = &get_ltitools_id($dom,$title);
10893: if ($newid) {
10894: my $position = $env{'form.ltitools_add_pos'};
10895: $position =~ s/\D+//g;
10896: if ($position ne '') {
10897: $allpos[$position] = $newid;
10898: }
10899: $changes{$newid} = 1;
1.322 raeburn 10900: foreach my $item ('title','url','key','secret','lifetime') {
1.267 raeburn 10901: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1.322 raeburn 10902: if ($item eq 'lifetime') {
10903: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
10904: }
1.267 raeburn 10905: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 10906: if (($item eq 'key') || ($item eq 'secret')) {
10907: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
10908: } else {
10909: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
10910: }
1.267 raeburn 10911: }
10912: }
10913: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
10914: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
10915: }
10916: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
10917: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
10918: }
1.323 raeburn 10919: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
10920: $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
10921: } else {
10922: $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
10923: }
1.296 raeburn 10924: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 10925: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
10926: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 10927: if (($item eq 'width') || ($item eq 'height')) {
10928: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
10929: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
10930: }
10931: } else {
10932: if ($env{'form.ltitools_add_'.$item} ne '') {
10933: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
10934: }
1.267 raeburn 10935: }
10936: }
10937: if ($env{'form.ltitools_add_target'} eq 'window') {
10938: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 10939: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
10940: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 10941: } else {
10942: $confhash{$newid}{'display'}{'target'} = 'iframe';
10943: }
10944: foreach my $item ('passback','roster') {
1.319 raeburn 10945: if ($env{'form.ltitools_'.$item.'_add'}) {
1.267 raeburn 10946: $confhash{$newid}{$item} = 1;
1.319 raeburn 10947: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
10948: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
10949: $lifetime =~ s/^\s+|\s+$//g;
10950: if ($lifetime =~ /^\d+\.?\d*$/) {
10951: $confhash{$newid}{$item.'valid'} = $lifetime;
10952: }
10953: }
1.267 raeburn 10954: }
10955: }
10956: if ($env{'form.ltitools_add_image.filename'} ne '') {
10957: my ($imageurl,$error) =
1.307 raeburn 10958: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267 raeburn 10959: $configuserok,$switchserver,$author_ok);
10960: if ($imageurl) {
10961: $confhash{$newid}{'image'} = $imageurl;
10962: }
10963: if ($error) {
10964: &Apache::lonnet::logthis($error);
10965: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10966: }
10967: }
10968: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
10969: foreach my $field (@fields) {
10970: if ($possfield{$field}) {
10971: if ($field eq 'roles') {
10972: foreach my $role (@courseroles) {
10973: my $choice = $env{'form.ltitools_add_roles_'.$role};
10974: if (($choice ne '') && ($posslti{$choice})) {
10975: $confhash{$newid}{'roles'}{$role} = $choice;
10976: if ($role eq 'cc') {
10977: $confhash{$newid}{'roles'}{'co'} = $choice;
10978: }
10979: }
10980: }
10981: } else {
10982: $confhash{$newid}{'fields'}{$field} = 1;
10983: }
10984: }
10985: }
1.324 raeburn 10986: if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
10987: if ($confhash{$newid}{'fields'}{'user'}) {
10988: if ($env{'form.ltitools_userincdom_add'}) {
10989: $confhash{$newid}{'incdom'} = 1;
10990: }
10991: }
10992: }
1.273 raeburn 10993: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
10994: foreach my $item (@courseconfig) {
10995: $confhash{$newid}{'crsconf'}{$item} = 1;
10996: }
1.267 raeburn 10997: if ($env{'form.ltitools_add_custom'}) {
10998: my $name = $env{'form.ltitools_add_custom_name'};
10999: my $value = $env{'form.ltitools_add_custom_value'};
11000: $value =~ s/(`)/'/g;
11001: $name =~ s/(`)/'/g;
11002: $confhash{$newid}{'custom'}{$name} = $value;
11003: }
11004: } else {
11005: my $error = &mt('Failed to acquire unique ID for new external tool');
11006: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11007: }
11008: }
11009: if (ref($domconfig{$action}) eq 'HASH') {
11010: my %deletions;
11011: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
11012: if (@todelete) {
11013: map { $deletions{$_} = 1; } @todelete;
11014: }
11015: my %customadds;
11016: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
11017: if (@newcustom) {
11018: map { $customadds{$_} = 1; } @newcustom;
11019: }
11020: my %imgdeletions;
11021: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
11022: if (@todeleteimages) {
11023: map { $imgdeletions{$_} = 1; } @todeleteimages;
11024: }
11025: my $maxnum = $env{'form.ltitools_maxnum'};
11026: for (my $i=0; $i<=$maxnum; $i++) {
11027: my $itemid = $env{'form.ltitools_id_'.$i};
1.308 raeburn 11028: $itemid =~ s/\D+//g;
1.267 raeburn 11029: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11030: if ($deletions{$itemid}) {
11031: if ($domconfig{$action}{$itemid}{'image'}) {
11032: #FIXME need to obsolete item in RES space
11033: }
11034: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
11035: next;
11036: } else {
11037: my $newpos = $env{'form.ltitools_'.$itemid};
11038: $newpos =~ s/\D+//g;
1.322 raeburn 11039: foreach my $item ('title','url','lifetime') {
1.267 raeburn 11040: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
11041: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
11042: $changes{$itemid} = 1;
11043: }
11044: }
1.297 raeburn 11045: foreach my $item ('key','secret') {
11046: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
11047: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
11048: $changes{$itemid} = 1;
11049: }
11050: }
1.267 raeburn 11051: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
11052: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
11053: }
11054: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
11055: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
11056: }
1.323 raeburn 11057: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
11058: $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
11059: } else {
11060: $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
11061: }
11062: if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
11063: if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
11064: $changes{$itemid} = 1;
11065: }
11066: } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
11067: $changes{$itemid} = 1;
11068: }
1.267 raeburn 11069: foreach my $size ('width','height') {
11070: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
11071: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
11072: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
11073: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
11074: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11075: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
11076: $changes{$itemid} = 1;
11077: }
11078: } else {
11079: $changes{$itemid} = 1;
11080: }
1.296 raeburn 11081: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11082: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
11083: $changes{$itemid} = 1;
11084: }
11085: }
11086: }
11087: foreach my $item ('linktext','explanation') {
11088: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
11089: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
11090: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
11091: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
11092: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11093: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
11094: $changes{$itemid} = 1;
11095: }
11096: } else {
11097: $changes{$itemid} = 1;
11098: }
11099: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11100: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
11101: $changes{$itemid} = 1;
11102: }
1.267 raeburn 11103: }
11104: }
11105: if ($env{'form.ltitools_target_'.$i} eq 'window') {
11106: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 11107: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
11108: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 11109: } else {
11110: $confhash{$itemid}{'display'}{'target'} = 'iframe';
11111: }
11112: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11113: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
11114: $changes{$itemid} = 1;
11115: }
11116: } else {
11117: $changes{$itemid} = 1;
11118: }
11119: foreach my $extra ('passback','roster') {
11120: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
11121: $confhash{$itemid}{$extra} = 1;
1.319 raeburn 11122: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
11123: my $lifetime = $env{'form.ltitools_'.$extra.'valid_add'};
11124: $lifetime =~ s/^\s+|\s+$//g;
11125: if ($lifetime =~ /^\d+\.?\d*$/) {
11126: $confhash{$itemid}{$extra.'valid'} = $lifetime;
11127: }
11128: }
1.267 raeburn 11129: }
11130: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
11131: $changes{$itemid} = 1;
11132: }
1.319 raeburn 11133: if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
11134: $changes{$itemid} = 1;
11135: }
1.267 raeburn 11136: }
1.273 raeburn 11137: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318 raeburn 11138: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 11139: if (grep(/^\Q$item\E$/,@courseconfig)) {
11140: $confhash{$itemid}{'crsconf'}{$item} = 1;
11141: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
11142: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
11143: $changes{$itemid} = 1;
11144: }
11145: } else {
11146: $changes{$itemid} = 1;
11147: }
11148: }
11149: }
1.267 raeburn 11150: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
11151: foreach my $field (@fields) {
11152: if ($possfield{$field}) {
11153: if ($field eq 'roles') {
11154: foreach my $role (@courseroles) {
11155: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
11156: if (($choice ne '') && ($posslti{$choice})) {
11157: $confhash{$itemid}{'roles'}{$role} = $choice;
11158: if ($role eq 'cc') {
11159: $confhash{$itemid}{'roles'}{'co'} = $choice;
11160: }
11161: }
11162: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
11163: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
11164: $changes{$itemid} = 1;
11165: }
11166: } elsif ($confhash{$itemid}{'roles'}{$role}) {
11167: $changes{$itemid} = 1;
11168: }
11169: }
11170: } else {
11171: $confhash{$itemid}{'fields'}{$field} = 1;
11172: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
11173: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
11174: $changes{$itemid} = 1;
11175: }
11176: } else {
11177: $changes{$itemid} = 1;
11178: }
11179: }
11180: }
11181: }
1.324 raeburn 11182: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
11183: if ($confhash{$itemid}{'fields'}{'user'}) {
11184: if ($env{'form.ltitools_userincdom_'.$i}) {
11185: $confhash{$itemid}{'incdom'} = 1;
11186: }
11187: if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
11188: $changes{$itemid} = 1;
11189: }
11190: }
11191: }
1.267 raeburn 11192: $allpos[$newpos] = $itemid;
11193: }
11194: if ($imgdeletions{$itemid}) {
11195: $changes{$itemid} = 1;
11196: #FIXME need to obsolete item in RES space
11197: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
11198: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
11199: $itemid,$configuserok,$switchserver,
11200: $author_ok);
11201: if ($imgurl) {
11202: $confhash{$itemid}{'image'} = $imgurl;
11203: $changes{$itemid} = 1;
11204: }
11205: if ($error) {
11206: &Apache::lonnet::logthis($error);
11207: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11208: }
11209: } elsif ($domconfig{$action}{$itemid}{'image'}) {
11210: $confhash{$itemid}{'image'} =
11211: $domconfig{$action}{$itemid}{'image'};
11212: }
11213: if ($customadds{$i}) {
11214: my $name = $env{'form.ltitools_custom_name_'.$i};
11215: $name =~ s/(`)/'/g;
11216: $name =~ s/^\s+//;
11217: $name =~ s/\s+$//;
11218: my $value = $env{'form.ltitools_custom_value_'.$i};
11219: $value =~ s/(`)/'/g;
11220: $value =~ s/^\s+//;
11221: $value =~ s/\s+$//;
11222: if ($name ne '') {
11223: $confhash{$itemid}{'custom'}{$name} = $value;
11224: $changes{$itemid} = 1;
11225: }
11226: }
11227: my %customdels;
11228: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
11229: if (@customdeletions) {
11230: $changes{$itemid} = 1;
11231: }
11232: map { $customdels{$_} = 1; } @customdeletions;
11233: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
11234: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
11235: unless ($customdels{$key}) {
11236: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
11237: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
11238: }
11239: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
11240: $changes{$itemid} = 1;
11241: }
11242: }
11243: }
11244: }
11245: unless ($changes{$itemid}) {
11246: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
11247: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
11248: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
11249: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
11250: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
11251: $changes{$itemid} = 1;
11252: last;
11253: }
11254: }
11255: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
11256: $changes{$itemid} = 1;
11257: }
11258: }
11259: last if ($changes{$itemid});
11260: }
11261: }
11262: }
11263: }
11264: }
11265: if (@allpos > 0) {
11266: my $idx = 0;
11267: foreach my $itemid (@allpos) {
11268: if ($itemid ne '') {
11269: $confhash{$itemid}{'order'} = $idx;
11270: if (ref($domconfig{$action}) eq 'HASH') {
11271: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11272: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
11273: $changes{$itemid} = 1;
11274: }
11275: }
11276: }
11277: $idx ++;
11278: }
11279: }
11280: }
11281: my %ltitoolshash = (
11282: $action => { %confhash }
11283: );
11284: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
11285: $dom);
11286: if ($putresult eq 'ok') {
1.297 raeburn 11287: my %ltienchash = (
11288: $action => { %encconfig }
11289: );
11290: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
1.267 raeburn 11291: if (keys(%changes) > 0) {
11292: my $cachetime = 24*60*60;
1.297 raeburn 11293: my %ltiall = %confhash;
11294: foreach my $id (keys(%ltiall)) {
11295: if (ref($encconfig{$id}) eq 'HASH') {
11296: foreach my $item ('key','secret') {
11297: $ltiall{$id}{$item} = $encconfig{$id}{$item};
11298: }
11299: }
11300: }
11301: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 11302: if (ref($lastactref) eq 'HASH') {
11303: $lastactref->{'ltitools'} = 1;
11304: }
11305: $resulttext = &mt('Changes made:').'<ul>';
11306: my %bynum;
11307: foreach my $itemid (sort(keys(%changes))) {
11308: my $position = $confhash{$itemid}{'order'};
11309: $bynum{$position} = $itemid;
11310: }
11311: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
11312: my $itemid = $bynum{$pos};
11313: if (ref($confhash{$itemid}) ne 'HASH') {
11314: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
11315: } else {
11316: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
11317: if ($confhash{$itemid}{'image'}) {
11318: $resulttext .= ' '.
11319: '<img src="'.$confhash{$itemid}{'image'}.'"'.
11320: ' alt="'.&mt('Tool Provider icon').'" />';
11321: }
11322: $resulttext .= '</li><ul>';
11323: my $position = $pos + 1;
11324: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.323 raeburn 11325: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1.267 raeburn 11326: if ($confhash{$itemid}{$item} ne '') {
11327: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
11328: }
11329: }
1.297 raeburn 11330: if ($encconfig{$itemid}{'key'} ne '') {
11331: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
11332: }
11333: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 11334: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 11335: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 11336: $resulttext .= ('*'x$num).'</li>';
11337: }
1.273 raeburn 11338: $resulttext .= '<li>'.&mt('Configurable in course:');
1.318 raeburn 11339: my @possconfig = ('label','title','target','linktext','explanation','append');
1.273 raeburn 11340: my $numconfig = 0;
11341: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
11342: foreach my $item (@possconfig) {
11343: if ($confhash{$itemid}{'crsconf'}{$item}) {
11344: $numconfig ++;
1.296 raeburn 11345: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 11346: }
11347: }
11348: }
11349: if (!$numconfig) {
11350: $resulttext .= &mt('None');
11351: }
11352: $resulttext .= '</li>';
1.267 raeburn 11353: foreach my $item ('passback','roster') {
11354: $resulttext .= '<li>'.$lt{$item}.' ';
11355: if ($confhash{$itemid}{$item}) {
11356: $resulttext .= &mt('Yes');
1.319 raeburn 11357: if ($confhash{$itemid}{$item.'valid'}) {
11358: if ($item eq 'passback') {
11359: $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
11360: $confhash{$itemid}{$item.'valid'});
11361: } else {
11362: $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
11363: $confhash{$itemid}{$item.'valid'});
11364: }
11365: }
1.267 raeburn 11366: } else {
11367: $resulttext .= &mt('No');
11368: }
11369: $resulttext .= '</li>';
11370: }
11371: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
11372: my $displaylist;
11373: if ($confhash{$itemid}{'display'}{'target'}) {
11374: $displaylist = &mt('Display target').': '.
11375: $confhash{$itemid}{'display'}{'target'}.',';
11376: }
11377: foreach my $size ('width','height') {
11378: if ($confhash{$itemid}{'display'}{$size}) {
11379: $displaylist .= (' 'x2).$lt{$size}.': '.
11380: $confhash{$itemid}{'display'}{$size}.',';
11381: }
11382: }
11383: if ($displaylist) {
11384: $displaylist =~ s/,$//;
11385: $resulttext .= '<li>'.$displaylist.'</li>';
11386: }
1.296 raeburn 11387: foreach my $item ('linktext','explanation') {
11388: if ($confhash{$itemid}{'display'}{$item}) {
11389: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
11390: }
11391: }
11392: }
1.267 raeburn 11393: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
11394: my $fieldlist;
11395: foreach my $field (@allfields) {
11396: if ($confhash{$itemid}{'fields'}{$field}) {
11397: $fieldlist .= (' 'x2).$lt{$field}.',';
11398: }
11399: }
11400: if ($fieldlist) {
11401: $fieldlist =~ s/,$//;
1.324 raeburn 11402: if ($confhash{$itemid}{'fields'}{'user'}) {
11403: if ($confhash{$itemid}{'incdom'}) {
11404: $fieldlist .= ' ('.&mt('username:domain').')';
11405: } else {
11406: $fieldlist .= ' ('.&mt('username').')';
11407: }
11408: }
1.267 raeburn 11409: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
11410: }
11411: }
11412: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
11413: my $rolemaps;
11414: foreach my $role (@courseroles) {
11415: if ($confhash{$itemid}{'roles'}{$role}) {
11416: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
11417: $confhash{$itemid}{'roles'}{$role}.',';
11418: }
11419: }
11420: if ($rolemaps) {
11421: $rolemaps =~ s/,$//;
11422: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
11423: }
11424: }
11425: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
11426: my $customlist;
11427: if (keys(%{$confhash{$itemid}{'custom'}})) {
11428: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
11429: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
11430: }
11431: }
11432: if ($customlist) {
1.317 raeburn 11433: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267 raeburn 11434: }
11435: }
11436: $resulttext .= '</ul></li>';
11437: }
11438: }
11439: $resulttext .= '</ul>';
11440: } else {
11441: $resulttext = &mt('No changes made.');
11442: }
11443: } else {
11444: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
11445: }
11446: if ($errors) {
11447: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11448: $errors.'</ul>';
11449: }
11450: return $resulttext;
11451: }
11452:
11453: sub process_ltitools_image {
11454: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
11455: my $filename = $env{'form.'.$caller.'.filename'};
11456: my ($error,$url);
11457: my ($width,$height) = (21,21);
11458: if ($configuserok eq 'ok') {
11459: if ($switchserver) {
11460: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
11461: $switchserver);
11462: } elsif ($author_ok eq 'ok') {
11463: my ($result,$imageurl,$madethumb) =
11464: &publishlogo($r,'upload',$caller,$dom,$confname,
11465: "ltitools/$itemid/icon",$width,$height);
11466: if ($result eq 'ok') {
11467: if ($madethumb) {
11468: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
11469: my $imagethumb = "$path/tn-".$imagefile;
11470: $url = $imagethumb;
11471: } else {
11472: $url = $imageurl;
11473: }
11474: } else {
11475: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
11476: }
11477: } else {
11478: $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);
11479: }
11480: } else {
11481: $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);
11482: }
11483: return ($url,$error);
11484: }
11485:
11486: sub get_ltitools_id {
11487: my ($cdom,$title) = @_;
11488: # get lock on ltitools db
11489: my $lockhash = {
11490: lock => $env{'user.name'}.
11491: ':'.$env{'user.domain'},
11492: };
11493: my $tries = 0;
11494: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
11495: my ($id,$error);
11496:
11497: while (($gotlock ne 'ok') && ($tries<10)) {
11498: $tries ++;
11499: sleep (0.1);
11500: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
11501: }
11502: if ($gotlock eq 'ok') {
11503: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
11504: if ($currids{'lock'}) {
11505: delete($currids{'lock'});
11506: if (keys(%currids)) {
11507: my @curr = sort { $a <=> $b } keys(%currids);
11508: if ($curr[-1] =~ /^\d+$/) {
11509: $id = 1 + $curr[-1];
11510: }
11511: } else {
11512: $id = 1;
11513: }
11514: if ($id) {
11515: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
11516: $error = 'nostore';
11517: }
11518: } else {
11519: $error = 'nonumber';
11520: }
11521: }
11522: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
11523: } else {
11524: $error = 'nolock';
11525: }
11526: return ($id,$error);
11527: }
11528:
1.320 raeburn 11529: sub modify_lti {
11530: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
11531: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11532: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
11533: my (%posslti,%posslticrs,%posscrstype);
11534: my @courseroles = ('cc','in','ta','ep','st');
11535: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
11536: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
11537: my @coursetypes = ('official','unofficial','community','textbook','placement');
11538: my %coursetypetitles = &Apache::lonlocal::texthash (
11539: official => 'Official',
11540: unofficial => 'Unofficial',
11541: community => 'Community',
11542: textbook => 'Textbook',
11543: placement => 'Placement Test',
11544: );
1.325 raeburn 11545: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 11546: my %lt = <i_names();
11547: map { $posslti{$_} = 1; } @ltiroles;
11548: map { $posslticrs{$_} = 1; } @lticourseroles;
11549: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 11550:
1.326 ! raeburn 11551: my %menutitles = <imenu_titles();
! 11552:
1.320 raeburn 11553: my (@items,%deletions,%itemids);
11554: if ($env{'form.lti_add'}) {
11555: my $consumer = $env{'form.lti_consumer_add'};
11556: $consumer =~ s/(`)/'/g;
11557: ($newid,my $error) = &get_lti_id($dom,$consumer);
11558: if ($newid) {
11559: $itemids{'add'} = $newid;
11560: push(@items,'add');
11561: $changes{$newid} = 1;
11562: } else {
11563: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
11564: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11565: }
11566: }
11567: if (ref($domconfig{$action}) eq 'HASH') {
11568: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
11569: if (@todelete) {
11570: map { $deletions{$_} = 1; } @todelete;
11571: }
11572: my $maxnum = $env{'form.lti_maxnum'};
11573: for (my $i=0; $i<=$maxnum; $i++) {
11574: my $itemid = $env{'form.lti_id_'.$i};
11575: $itemid =~ s/\D+//g;
11576: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11577: if ($deletions{$itemid}) {
11578: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
11579: } else {
11580: push(@items,$i);
11581: $itemids{$i} = $itemid;
11582: }
11583: }
11584: }
11585: }
11586: foreach my $idx (@items) {
11587: my $itemid = $itemids{$idx};
11588: next unless ($itemid);
11589: my $position = $env{'form.lti_pos_'.$idx};
11590: $position =~ s/\D+//g;
11591: if ($position ne '') {
11592: $allpos[$position] = $itemid;
11593: }
11594: foreach my $item ('consumer','key','secret','lifetime') {
11595: my $formitem = 'form.lti_'.$item.'_'.$idx;
11596: $env{$formitem} =~ s/(`)/'/g;
11597: if ($item eq 'lifetime') {
11598: $env{$formitem} =~ s/[^\d.]//g;
11599: }
11600: if ($env{$formitem} ne '') {
11601: if (($item eq 'key') || ($item eq 'secret')) {
11602: $encconfig{$itemid}{$item} = $env{$formitem};
11603: } else {
11604: $confhash{$itemid}{$item} = $env{$formitem};
11605: unless (($idx eq 'add') || ($changes{$itemid})) {
11606: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
11607: $changes{$itemid} = 1;
11608: }
11609: }
11610: }
11611: }
11612: }
11613: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
11614: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
11615: }
11616: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
11617: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
11618: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
11619: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
11620: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
11621: my $mapuser = $env{'form.lti_customuser_'.$idx};
11622: $mapuser =~ s/(`)/'/g;
11623: $mapuser =~ s/^\s+|\s+$//g;
11624: $confhash{$itemid}{'mapuser'} = $mapuser;
11625: }
11626: foreach my $ltirole (@lticourseroles) {
11627: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
11628: if (grep(/^\Q$possrole\E$/,@courseroles)) {
11629: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
11630: }
11631: }
11632: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
11633: my @makeuser;
11634: foreach my $ltirole (sort(@possmakeuser)) {
11635: if ($posslti{$ltirole}) {
11636: push(@makeuser,$ltirole);
11637: }
11638: }
11639: $confhash{$itemid}{'makeuser'} = \@makeuser;
1.325 raeburn 11640: if (@makeuser) {
11641: my $lcauth = $env{'form.lti_lcauth_'.$idx};
11642: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
11643: $confhash{$itemid}{'lcauth'} = $lcauth;
11644: if ($lcauth ne 'internal') {
11645: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
11646: $lcauthparm =~ s/^(\s+|\s+)$//g;
11647: $lcauthparm =~ s/`//g;
11648: if ($lcauthparm ne '') {
11649: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
11650: }
11651: }
11652: } else {
11653: $confhash{$itemid}{'lcauth'} = 'lti';
11654: }
11655: }
11656: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
11657: if (@possinstdata) {
11658: foreach my $field (@possinstdata) {
11659: if (exists($fieldtitles{$field})) {
11660: push(@{$confhash{$itemid}{'instdata'}});
11661: }
11662: }
11663: }
1.320 raeburn 11664: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
11665: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
11666: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
11667: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
11668: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
11669: $mapcrs =~ s/(`)/'/g;
11670: $mapcrs =~ s/^\s+|\s+$//g;
11671: $confhash{$itemid}{'mapcrs'} = $mapcrs;
11672: }
11673: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
11674: my @crstypes;
11675: foreach my $type (sort(@posstypes)) {
11676: if ($posscrstype{$type}) {
11677: push(@crstypes,$type);
11678: }
11679: }
11680: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
11681: if ($env{'form.lti_makecrs_'.$idx}) {
11682: $confhash{$itemid}{'makecrs'} = 1;
11683: }
11684: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
11685: my @selfenroll;
11686: foreach my $type (sort(@possenroll)) {
11687: if ($posslticrs{$type}) {
11688: push(@selfenroll,$type);
11689: }
11690: }
11691: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
11692: if ($env{'form.lti_crssec_'.$idx}) {
11693: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
11694: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
11695: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
11696: my $section = $env{'form.lti_customsection_'.$idx};
11697: $section =~ s/(`)/'/g;
11698: $section =~ s/^\s+|\s+$//g;
11699: if ($section ne '') {
11700: $confhash{$itemid}{'section'} = $section;
11701: }
11702: }
11703: }
1.326 ! raeburn 11704: foreach my $field ('passback','roster','topmenu','inlinemenu') {
1.321 raeburn 11705: if ($env{'form.lti_'.$field.'_'.$idx}) {
1.320 raeburn 11706: $confhash{$itemid}{$field} = 1;
11707: }
11708: }
1.326 ! raeburn 11709:
! 11710: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
! 11711: $confhash{$itemid}{lcmenu} = [];
! 11712: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
! 11713: foreach my $field (@possmenu) {
! 11714: if (exists($menutitles{$field})) {
! 11715: if ($field eq 'grades') {
! 11716: next unless ($env{'form.lti_inlinemenu_'.$idx});
! 11717: }
! 11718: push(@{$confhash{$itemid}{lcmenu}},$field);
! 11719: }
! 11720: }
! 11721: }
1.320 raeburn 11722: unless (($idx eq 'add') || ($changes{$itemid})) {
1.326 ! raeburn 11723: foreach my $field ('mapuser','mapcrs','makecrs','section','passback','roster','lcauth','lcauthparm','topmenu','inlinemenu') {
1.320 raeburn 11724: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
11725: $changes{$itemid} = 1;
11726: }
11727: }
1.326 ! raeburn 11728: foreach my $field ('makeuser','mapcrstype','selfenroll','instdata','lcmenu') {
1.320 raeburn 11729: unless ($changes{$itemid}) {
11730: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
11731: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
11732: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
11733: $confhash{$itemid}{$field});
11734: if (@diffs) {
11735: $changes{$itemid} = 1;
11736: }
11737: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
11738: $changes{$itemid} = 1;
11739: }
11740: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
11741: if (@{$confhash{$itemid}{$field}} > 0) {
11742: $changes{$itemid} = 1;
11743: }
11744: }
11745: }
11746: }
11747: unless ($changes{$itemid}) {
11748: if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
11749: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
11750: foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
11751: if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne
11752: $confhash{$itemid}{'maproles'}{$ltirole}) {
11753: $changes{$itemid} = 1;
11754: last;
11755: }
11756: }
11757: unless ($changes{$itemid}) {
11758: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
11759: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
11760: $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
11761: $changes{$itemid} = 1;
11762: last;
11763: }
11764: }
11765: }
11766: } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
11767: $changes{$itemid} = 1;
11768: }
11769: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
11770: unless ($changes{$itemid}) {
11771: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
11772: $changes{$itemid} = 1;
11773: }
11774: }
11775: }
11776: }
11777: }
11778: }
11779: if (@allpos > 0) {
11780: my $idx = 0;
11781: foreach my $itemid (@allpos) {
11782: if ($itemid ne '') {
11783: $confhash{$itemid}{'order'} = $idx;
11784: if (ref($domconfig{$action}) eq 'HASH') {
11785: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11786: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
11787: $changes{$itemid} = 1;
11788: }
11789: }
11790: }
11791: $idx ++;
11792: }
11793: }
11794: }
11795: my %ltihash = (
11796: $action => { %confhash }
11797: );
11798: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,
11799: $dom);
11800: if ($putresult eq 'ok') {
11801: my %ltienchash = (
11802: $action => { %encconfig }
11803: );
11804: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
11805: if (keys(%changes) > 0) {
11806: my $cachetime = 24*60*60;
11807: my %ltiall = %confhash;
11808: foreach my $id (keys(%ltiall)) {
11809: if (ref($encconfig{$id}) eq 'HASH') {
11810: foreach my $item ('key','secret') {
11811: $ltiall{$id}{$item} = $encconfig{$id}{$item};
11812: }
11813: }
11814: }
11815: &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
11816: if (ref($lastactref) eq 'HASH') {
11817: $lastactref->{'lti'} = 1;
11818: }
11819: $resulttext = &mt('Changes made:').'<ul>';
11820: my %bynum;
11821: foreach my $itemid (sort(keys(%changes))) {
11822: my $position = $confhash{$itemid}{'order'};
11823: $bynum{$position} = $itemid;
11824: }
11825: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
11826: my $itemid = $bynum{$pos};
11827: if (ref($confhash{$itemid}) ne 'HASH') {
11828: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
11829: } else {
11830: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b></li><ul>';
11831: my $position = $pos + 1;
11832: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
11833: foreach my $item ('version','lifetime') {
11834: if ($confhash{$itemid}{$item} ne '') {
11835: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
11836: }
11837: }
11838: if ($encconfig{$itemid}{'key'} ne '') {
11839: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
11840: }
11841: if ($encconfig{$itemid}{'secret'} ne '') {
11842: $resulttext .= '<li>'.$lt{'secret'}.': ';
11843: my $num = length($encconfig{$itemid}{'secret'});
11844: $resulttext .= ('*'x$num).'</li>';
11845: }
11846: if ($confhash{$itemid}{'mapuser'}) {
11847: my $shownmapuser;
11848: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
11849: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
11850: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
11851: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
11852: } else {
11853: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
11854: }
11855: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
11856: }
11857: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
11858: my $rolemaps;
11859: foreach my $role (@ltiroles) {
11860: if ($confhash{$itemid}{'maproles'}{$role}) {
11861: $rolemaps .= (' 'x2).$role.'='.
11862: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
11863: 'Course').',';
11864: }
11865: }
11866: if ($rolemaps) {
11867: $rolemaps =~ s/,$//;
11868: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
11869: }
11870: }
11871: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
11872: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
11873: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
1.325 raeburn 11874: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
11875: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
11876: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
11877: } else {
11878: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
11879: $confhash{$itemid}{'lcauth'});
11880: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
11881: $resulttext .= '; '.&mt('a randomly generated password will be created');
11882: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
11883: if ($confhash{$itemid}{'lcauthparm'} ne '') {
11884: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
11885: }
11886: } else {
11887: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
11888: }
11889: }
11890: $resulttext .= '</li>';
1.320 raeburn 11891: } else {
11892: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
11893: }
11894: }
1.325 raeburn 11895: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
11896: if (@{$confhash{$itemid}{'instdata'}} > 0) {
11897: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
11898: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
11899: } else {
11900: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
11901: }
11902: }
1.320 raeburn 11903: if ($confhash{$itemid}{'mapcrs'}) {
11904: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
11905: }
11906: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
11907: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
11908: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
11909: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
11910: '</li>';
11911: } else {
11912: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
11913: }
11914: }
11915: if ($confhash{$itemid}{'makecrs'}) {
11916: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
11917: } else {
11918: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
11919: }
11920: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
11921: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
11922: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
11923: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
11924: '</li>';
11925: } else {
11926: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
11927: }
11928: }
11929: if ($confhash{$itemid}{'section'}) {
11930: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
11931: $resulttext .= '<li>'.&mt('User section from standard field:').
11932: ' (course_section_sourcedid)'.'</li>';
11933: } else {
11934: $resulttext .= '<li>'.&mt('User section from:').' '.
11935: $confhash{$itemid}{'section'}.'</li>';
11936: }
11937: } else {
11938: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
11939: }
1.326 ! raeburn 11940: foreach my $item ('passback','roster','topmenu','inlinemenu') {
! 11941: $resulttext .= '<li>'.$lt{$item}.': ';
1.320 raeburn 11942: if ($confhash{$itemid}{$item}) {
11943: $resulttext .= &mt('Yes');
11944: } else {
11945: $resulttext .= &mt('No');
11946: }
11947: $resulttext .= '</li>';
11948: }
1.326 ! raeburn 11949: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
! 11950: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
! 11951: $resulttext .= '<li>'.&mt('Menu items:').' '.
! 11952: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
! 11953: } else {
! 11954: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
! 11955: }
! 11956: }
1.320 raeburn 11957: $resulttext .= '</ul></li>';
11958: }
11959: }
11960: $resulttext .= '</ul>';
11961: } else {
11962: $resulttext = &mt('No changes made.');
11963: }
11964: } else {
11965: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
11966: }
11967: if ($errors) {
11968: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11969: $errors.'</ul>';
11970: }
11971: return $resulttext;
11972: }
11973:
11974: sub get_lti_id {
11975: my ($domain,$consumer) = @_;
11976: # get lock on lti db
11977: my $lockhash = {
11978: lock => $env{'user.name'}.
11979: ':'.$env{'user.domain'},
11980: };
11981: my $tries = 0;
11982: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
11983: my ($id,$error);
11984:
11985: while (($gotlock ne 'ok') && ($tries<10)) {
11986: $tries ++;
11987: sleep (0.1);
11988: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
11989: }
11990: if ($gotlock eq 'ok') {
11991: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
11992: if ($currids{'lock'}) {
11993: delete($currids{'lock'});
11994: if (keys(%currids)) {
11995: my @curr = sort { $a <=> $b } keys(%currids);
11996: if ($curr[-1] =~ /^\d+$/) {
11997: $id = 1 + $curr[-1];
11998: }
11999: } else {
12000: $id = 1;
12001: }
12002: if ($id) {
12003: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
12004: $error = 'nostore';
12005: }
12006: } else {
12007: $error = 'nonumber';
12008: }
12009: }
12010: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
12011: } else {
12012: $error = 'nolock';
12013: }
12014: return ($id,$error);
12015: }
12016:
1.3 raeburn 12017: sub modify_autoenroll {
1.205 raeburn 12018: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 12019: my ($resulttext,%changes);
12020: my %currautoenroll;
12021: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
12022: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
12023: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
12024: }
12025: }
12026: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
12027: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 12028: sender => 'Sender for notification messages',
1.274 raeburn 12029: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
12030: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 12031: my @offon = ('off','on');
1.17 raeburn 12032: my $sender_uname = $env{'form.sender_uname'};
12033: my $sender_domain = $env{'form.sender_domain'};
12034: if ($sender_domain eq '') {
12035: $sender_uname = '';
12036: } elsif ($sender_uname eq '') {
12037: $sender_domain = '';
12038: }
1.129 raeburn 12039: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 12040: my $failsafe = $env{'form.autoenroll_failsafe'};
12041: $failsafe =~ s{^\s+|\s+$}{}g;
12042: if ($failsafe =~ /\D/) {
12043: undef($failsafe);
12044: }
1.1 raeburn 12045: my %autoenrollhash = (
1.129 raeburn 12046: autoenroll => { 'run' => $env{'form.autoenroll_run'},
12047: 'sender_uname' => $sender_uname,
12048: 'sender_domain' => $sender_domain,
12049: 'co-owners' => $coowners,
1.274 raeburn 12050: 'autofailsafe' => $failsafe,
1.1 raeburn 12051: }
12052: );
1.4 raeburn 12053: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
12054: $dom);
1.1 raeburn 12055: if ($putresult eq 'ok') {
12056: if (exists($currautoenroll{'run'})) {
12057: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
12058: $changes{'run'} = 1;
12059: }
12060: } elsif ($autorun) {
12061: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 12062: $changes{'run'} = 1;
1.1 raeburn 12063: }
12064: }
1.17 raeburn 12065: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 12066: $changes{'sender'} = 1;
12067: }
1.17 raeburn 12068: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 12069: $changes{'sender'} = 1;
12070: }
1.129 raeburn 12071: if ($currautoenroll{'co-owners'} ne '') {
12072: if ($currautoenroll{'co-owners'} ne $coowners) {
12073: $changes{'coowners'} = 1;
12074: }
12075: } elsif ($coowners) {
12076: $changes{'coowners'} = 1;
1.274 raeburn 12077: }
12078: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
12079: $changes{'autofailsafe'} = 1;
12080: }
1.1 raeburn 12081: if (keys(%changes) > 0) {
12082: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 12083: if ($changes{'run'}) {
1.1 raeburn 12084: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
12085: }
12086: if ($changes{'sender'}) {
1.17 raeburn 12087: if ($sender_uname eq '' || $sender_domain eq '') {
12088: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
12089: } else {
12090: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
12091: }
1.1 raeburn 12092: }
1.129 raeburn 12093: if ($changes{'coowners'}) {
12094: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
12095: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12096: if (ref($lastactref) eq 'HASH') {
12097: $lastactref->{'domainconfig'} = 1;
12098: }
1.129 raeburn 12099: }
1.274 raeburn 12100: if ($changes{'autofailsafe'}) {
12101: if ($failsafe ne '') {
1.299 raeburn 12102: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274 raeburn 12103: } else {
1.299 raeburn 12104: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274 raeburn 12105: }
12106: &Apache::lonnet::get_domain_defaults($dom,1);
12107: if (ref($lastactref) eq 'HASH') {
12108: $lastactref->{'domdefaults'} = 1;
12109: }
12110: }
1.1 raeburn 12111: $resulttext .= '</ul>';
12112: } else {
12113: $resulttext = &mt('No changes made to auto-enrollment settings');
12114: }
12115: } else {
1.11 albertel 12116: $resulttext = '<span class="LC_error">'.
12117: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12118: }
1.3 raeburn 12119: return $resulttext;
1.1 raeburn 12120: }
12121:
12122: sub modify_autoupdate {
1.3 raeburn 12123: my ($dom,%domconfig) = @_;
1.1 raeburn 12124: my ($resulttext,%currautoupdate,%fields,%changes);
12125: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
12126: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
12127: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
12128: }
12129: }
12130: my @offon = ('off','on');
12131: my %title = &Apache::lonlocal::texthash (
12132: run => 'Auto-update:',
12133: classlists => 'Updates to user information in classlists?'
12134: );
1.44 raeburn 12135: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 12136: my %fieldtitles = &Apache::lonlocal::texthash (
12137: id => 'Student/Employee ID',
1.20 raeburn 12138: permanentemail => 'E-mail address',
1.1 raeburn 12139: lastname => 'Last Name',
12140: firstname => 'First Name',
12141: middlename => 'Middle Name',
1.132 raeburn 12142: generation => 'Generation',
1.1 raeburn 12143: );
1.142 raeburn 12144: $othertitle = &mt('All users');
1.1 raeburn 12145: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 12146: $othertitle = &mt('Other users');
1.1 raeburn 12147: }
12148: foreach my $key (keys(%env)) {
12149: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 12150: my ($usertype,$item) = ($1,$2);
12151: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
12152: if ($usertype eq 'default') {
12153: push(@{$fields{$1}},$2);
12154: } elsif (ref($types) eq 'ARRAY') {
12155: if (grep(/^\Q$usertype\E$/,@{$types})) {
12156: push(@{$fields{$1}},$2);
12157: }
12158: }
12159: }
1.1 raeburn 12160: }
12161: }
1.131 raeburn 12162: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
12163: @lockablenames = sort(@lockablenames);
12164: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
12165: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
12166: if (@changed) {
12167: $changes{'lockablenames'} = 1;
12168: }
12169: } else {
12170: if (@lockablenames) {
12171: $changes{'lockablenames'} = 1;
12172: }
12173: }
1.1 raeburn 12174: my %updatehash = (
12175: autoupdate => { run => $env{'form.autoupdate_run'},
12176: classlists => $env{'form.classlists'},
12177: fields => {%fields},
1.131 raeburn 12178: lockablenames => \@lockablenames,
1.1 raeburn 12179: }
12180: );
12181: foreach my $key (keys(%currautoupdate)) {
12182: if (($key eq 'run') || ($key eq 'classlists')) {
12183: if (exists($updatehash{autoupdate}{$key})) {
12184: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
12185: $changes{$key} = 1;
12186: }
12187: }
12188: } elsif ($key eq 'fields') {
12189: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 12190: foreach my $item (@{$types},'default') {
1.1 raeburn 12191: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
12192: my $change = 0;
12193: foreach my $type (@{$currautoupdate{$key}{$item}}) {
12194: if (!exists($fields{$item})) {
12195: $change = 1;
1.132 raeburn 12196: last;
1.1 raeburn 12197: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 12198: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 12199: $change = 1;
1.132 raeburn 12200: last;
1.1 raeburn 12201: }
12202: }
12203: }
12204: if ($change) {
12205: push(@{$changes{$key}},$item);
12206: }
1.26 raeburn 12207: }
1.1 raeburn 12208: }
12209: }
1.131 raeburn 12210: } elsif ($key eq 'lockablenames') {
12211: if (ref($currautoupdate{$key}) eq 'ARRAY') {
12212: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
12213: if (@changed) {
12214: $changes{'lockablenames'} = 1;
12215: }
12216: } else {
12217: if (@lockablenames) {
12218: $changes{'lockablenames'} = 1;
12219: }
12220: }
12221: }
12222: }
12223: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
12224: if (@lockablenames) {
12225: $changes{'lockablenames'} = 1;
1.1 raeburn 12226: }
12227: }
1.26 raeburn 12228: foreach my $item (@{$types},'default') {
12229: if (defined($fields{$item})) {
12230: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 12231: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
12232: my $change = 0;
12233: if (ref($fields{$item}) eq 'ARRAY') {
12234: foreach my $type (@{$fields{$item}}) {
12235: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
12236: $change = 1;
12237: last;
12238: }
12239: }
12240: }
12241: if ($change) {
12242: push(@{$changes{'fields'}},$item);
12243: }
12244: } else {
1.26 raeburn 12245: push(@{$changes{'fields'}},$item);
12246: }
12247: } else {
12248: push(@{$changes{'fields'}},$item);
1.1 raeburn 12249: }
12250: }
12251: }
12252: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
12253: $dom);
12254: if ($putresult eq 'ok') {
12255: if (keys(%changes) > 0) {
12256: $resulttext = &mt('Changes made:').'<ul>';
12257: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 12258: if ($key eq 'lockablenames') {
12259: $resulttext .= '<li>';
12260: if (@lockablenames) {
12261: $usertypes->{'default'} = $othertitle;
12262: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
12263: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
12264: } else {
12265: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
12266: }
12267: $resulttext .= '</li>';
12268: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 12269: foreach my $item (@{$changes{$key}}) {
12270: my @newvalues;
12271: foreach my $type (@{$fields{$item}}) {
12272: push(@newvalues,$fieldtitles{$type});
12273: }
1.3 raeburn 12274: my $newvaluestr;
12275: if (@newvalues > 0) {
12276: $newvaluestr = join(', ',@newvalues);
12277: } else {
12278: $newvaluestr = &mt('none');
1.6 raeburn 12279: }
1.1 raeburn 12280: if ($item eq 'default') {
1.26 raeburn 12281: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 12282: } else {
1.26 raeburn 12283: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 12284: }
12285: }
12286: } else {
12287: my $newvalue;
12288: if ($key eq 'run') {
12289: $newvalue = $offon[$env{'form.autoupdate_run'}];
12290: } else {
12291: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 12292: }
1.1 raeburn 12293: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
12294: }
12295: }
12296: $resulttext .= '</ul>';
12297: } else {
1.3 raeburn 12298: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 12299: }
12300: } else {
1.11 albertel 12301: $resulttext = '<span class="LC_error">'.
12302: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12303: }
1.3 raeburn 12304: return $resulttext;
1.1 raeburn 12305: }
12306:
1.125 raeburn 12307: sub modify_autocreate {
12308: my ($dom,%domconfig) = @_;
12309: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
12310: if (ref($domconfig{'autocreate'}) eq 'HASH') {
12311: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
12312: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
12313: }
12314: }
12315: my %title= ( xml => 'Auto-creation of courses in XML course description files',
12316: req => 'Auto-creation of validated requests for official courses',
12317: xmldc => 'Identity of course creator of courses from XML files',
12318: );
12319: my @types = ('xml','req');
12320: foreach my $item (@types) {
12321: $newvals{$item} = $env{'form.autocreate_'.$item};
12322: $newvals{$item} =~ s/\D//g;
12323: $newvals{$item} = 0 if ($newvals{$item} eq '');
12324: }
12325: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 12326: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 12327: unless (exists($domcoords{$newvals{'xmldc'}})) {
12328: $newvals{'xmldc'} = '';
12329: }
12330: %autocreatehash = (
12331: autocreate => { xml => $newvals{'xml'},
12332: req => $newvals{'req'},
12333: }
12334: );
12335: if ($newvals{'xmldc'} ne '') {
12336: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
12337: }
12338: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
12339: $dom);
12340: if ($putresult eq 'ok') {
12341: my @items = @types;
12342: if ($newvals{'xml'}) {
12343: push(@items,'xmldc');
12344: }
12345: foreach my $item (@items) {
12346: if (exists($currautocreate{$item})) {
12347: if ($currautocreate{$item} ne $newvals{$item}) {
12348: $changes{$item} = 1;
12349: }
12350: } elsif ($newvals{$item}) {
12351: $changes{$item} = 1;
12352: }
12353: }
12354: if (keys(%changes) > 0) {
12355: my @offon = ('off','on');
12356: $resulttext = &mt('Changes made:').'<ul>';
12357: foreach my $item (@types) {
12358: if ($changes{$item}) {
12359: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 12360: $resulttext .= '<li>'.
12361: &mt("$title{$item} set to [_1]$newtxt [_2]",
12362: '<b>','</b>').
12363: '</li>';
1.125 raeburn 12364: }
12365: }
12366: if ($changes{'xmldc'}) {
12367: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
12368: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 12369: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 12370: }
12371: $resulttext .= '</ul>';
12372: } else {
12373: $resulttext = &mt('No changes made to auto-creation settings');
12374: }
12375: } else {
12376: $resulttext = '<span class="LC_error">'.
12377: &mt('An error occurred: [_1]',$putresult).'</span>';
12378: }
12379: return $resulttext;
12380: }
12381:
1.23 raeburn 12382: sub modify_directorysrch {
1.295 raeburn 12383: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 12384: my ($resulttext,%changes);
12385: my %currdirsrch;
12386: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
12387: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
12388: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
12389: }
12390: }
1.277 raeburn 12391: my %title = ( available => 'Institutional directory search available',
12392: localonly => 'Other domains can search institution',
12393: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 12394: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 12395: searchby => 'Search types',
12396: searchtypes => 'Search latitude');
12397: my @offon = ('off','on');
1.24 raeburn 12398: my @otherdoms = ('Yes','No');
1.23 raeburn 12399:
1.25 raeburn 12400: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 12401: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
12402: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
12403:
1.44 raeburn 12404: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 12405: if (keys(%{$usertypes}) == 0) {
12406: @cansearch = ('default');
12407: } else {
12408: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
12409: foreach my $type (@{$currdirsrch{'cansearch'}}) {
12410: if (!grep(/^\Q$type\E$/,@cansearch)) {
12411: push(@{$changes{'cansearch'}},$type);
12412: }
1.23 raeburn 12413: }
1.26 raeburn 12414: foreach my $type (@cansearch) {
12415: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
12416: push(@{$changes{'cansearch'}},$type);
12417: }
1.23 raeburn 12418: }
1.26 raeburn 12419: } else {
12420: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 12421: }
12422: }
12423:
12424: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
12425: foreach my $by (@{$currdirsrch{'searchby'}}) {
12426: if (!grep(/^\Q$by\E$/,@searchby)) {
12427: push(@{$changes{'searchby'}},$by);
12428: }
12429: }
12430: foreach my $by (@searchby) {
12431: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
12432: push(@{$changes{'searchby'}},$by);
12433: }
12434: }
12435: } else {
12436: push(@{$changes{'searchby'}},@searchby);
12437: }
1.25 raeburn 12438:
12439: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
12440: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
12441: if (!grep(/^\Q$type\E$/,@searchtypes)) {
12442: push(@{$changes{'searchtypes'}},$type);
12443: }
12444: }
12445: foreach my $type (@searchtypes) {
12446: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
12447: push(@{$changes{'searchtypes'}},$type);
12448: }
12449: }
12450: } else {
12451: if (exists($currdirsrch{'searchtypes'})) {
12452: foreach my $type (@searchtypes) {
12453: if ($type ne $currdirsrch{'searchtypes'}) {
12454: push(@{$changes{'searchtypes'}},$type);
12455: }
12456: }
12457: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
12458: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
12459: }
12460: } else {
12461: push(@{$changes{'searchtypes'}},@searchtypes);
12462: }
12463: }
12464:
1.23 raeburn 12465: my %dirsrch_hash = (
12466: directorysrch => { available => $env{'form.dirsrch_available'},
12467: cansearch => \@cansearch,
1.277 raeburn 12468: localonly => $env{'form.dirsrch_instlocalonly'},
12469: lclocalonly => $env{'form.dirsrch_domlocalonly'},
12470: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 12471: searchby => \@searchby,
1.25 raeburn 12472: searchtypes => \@searchtypes,
1.23 raeburn 12473: }
12474: );
12475: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
12476: $dom);
12477: if ($putresult eq 'ok') {
12478: if (exists($currdirsrch{'available'})) {
12479: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
12480: $changes{'available'} = 1;
12481: }
12482: } else {
12483: if ($env{'form.dirsrch_available'} eq '1') {
12484: $changes{'available'} = 1;
12485: }
12486: }
1.277 raeburn 12487: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 12488: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
12489: $changes{'lcavailable'} = 1;
12490: }
1.277 raeburn 12491: } else {
12492: if ($env{'form.dirsrch_lcavailable'} eq '1') {
12493: $changes{'lcavailable'} = 1;
12494: }
12495: }
1.24 raeburn 12496: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 12497: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
12498: $changes{'localonly'} = 1;
12499: }
1.24 raeburn 12500: } else {
1.277 raeburn 12501: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 12502: $changes{'localonly'} = 1;
12503: }
12504: }
1.277 raeburn 12505: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 12506: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
12507: $changes{'lclocalonly'} = 1;
12508: }
1.277 raeburn 12509: } else {
12510: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
12511: $changes{'lclocalonly'} = 1;
12512: }
12513: }
1.23 raeburn 12514: if (keys(%changes) > 0) {
12515: $resulttext = &mt('Changes made:').'<ul>';
12516: if ($changes{'available'}) {
12517: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
12518: }
1.277 raeburn 12519: if ($changes{'lcavailable'}) {
12520: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
12521: }
1.24 raeburn 12522: if ($changes{'localonly'}) {
1.277 raeburn 12523: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 12524: }
1.277 raeburn 12525: if ($changes{'lclocalonly'}) {
12526: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 12527: }
1.23 raeburn 12528: if (ref($changes{'cansearch'}) eq 'ARRAY') {
12529: my $chgtext;
1.26 raeburn 12530: if (ref($usertypes) eq 'HASH') {
12531: if (keys(%{$usertypes}) > 0) {
12532: foreach my $type (@{$types}) {
12533: if (grep(/^\Q$type\E$/,@cansearch)) {
12534: $chgtext .= $usertypes->{$type}.'; ';
12535: }
12536: }
12537: if (grep(/^default$/,@cansearch)) {
12538: $chgtext .= $othertitle;
12539: } else {
12540: $chgtext =~ s/\; $//;
12541: }
1.210 raeburn 12542: $resulttext .=
1.178 raeburn 12543: '<li>'.
12544: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
12545: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
12546: '</li>';
1.23 raeburn 12547: }
12548: }
12549: }
12550: if (ref($changes{'searchby'}) eq 'ARRAY') {
12551: my ($searchtitles,$titleorder) = &sorted_searchtitles();
12552: my $chgtext;
12553: foreach my $type (@{$titleorder}) {
12554: if (grep(/^\Q$type\E$/,@searchby)) {
12555: if (defined($searchtitles->{$type})) {
12556: $chgtext .= $searchtitles->{$type}.'; ';
12557: }
12558: }
12559: }
12560: $chgtext =~ s/\; $//;
12561: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
12562: }
1.25 raeburn 12563: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
12564: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
12565: my $chgtext;
12566: foreach my $type (@{$srchtypeorder}) {
12567: if (grep(/^\Q$type\E$/,@searchtypes)) {
12568: if (defined($srchtypes_desc->{$type})) {
12569: $chgtext .= $srchtypes_desc->{$type}.'; ';
12570: }
12571: }
12572: }
12573: $chgtext =~ s/\; $//;
1.178 raeburn 12574: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 12575: }
12576: $resulttext .= '</ul>';
1.295 raeburn 12577: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
12578: if (ref($lastactref) eq 'HASH') {
12579: $lastactref->{'directorysrch'} = 1;
12580: }
1.23 raeburn 12581: } else {
1.277 raeburn 12582: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 12583: }
12584: } else {
12585: $resulttext = '<span class="LC_error">'.
1.27 raeburn 12586: &mt('An error occurred: [_1]',$putresult).'</span>';
12587: }
12588: return $resulttext;
12589: }
12590:
1.28 raeburn 12591: sub modify_contacts {
1.205 raeburn 12592: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 12593: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
12594: if (ref($domconfig{'contacts'}) eq 'HASH') {
12595: foreach my $key (keys(%{$domconfig{'contacts'}})) {
12596: $currsetting{$key} = $domconfig{'contacts'}{$key};
12597: }
12598: }
1.286 raeburn 12599: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 12600: my @contacts = ('supportemail','adminemail');
1.286 raeburn 12601: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
12602: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.203 raeburn 12603: my @toggles = ('reporterrors','reportupdates');
1.286 raeburn 12604: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 12605: foreach my $type (@mailings) {
12606: @{$newsetting{$type}} =
12607: &Apache::loncommon::get_env_multiple('form.'.$type);
12608: foreach my $item (@contacts) {
12609: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
12610: $contacts_hash{contacts}{$type}{$item} = 1;
12611: } else {
12612: $contacts_hash{contacts}{$type}{$item} = 0;
12613: }
1.289 raeburn 12614: }
1.28 raeburn 12615: $others{$type} = $env{'form.'.$type.'_others'};
12616: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 12617: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12618: $bcc{$type} = $env{'form.'.$type.'_bcc'};
12619: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 12620: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
12621: $includestr{$type} = $env{'form.'.$type.'_includestr'};
12622: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
12623: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
12624: }
1.134 raeburn 12625: }
1.28 raeburn 12626: }
12627: foreach my $item (@contacts) {
12628: $to{$item} = $env{'form.'.$item};
12629: $contacts_hash{'contacts'}{$item} = $to{$item};
12630: }
1.203 raeburn 12631: foreach my $item (@toggles) {
12632: if ($env{'form.'.$item} =~ /^(0|1)$/) {
12633: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
12634: }
12635: }
1.286 raeburn 12636: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
12637: foreach my $field (@{$fields}) {
12638: if (ref($possoptions->{$field}) eq 'ARRAY') {
12639: my $value = $env{'form.helpform_'.$field};
12640: $value =~ s/^\s+|\s+$//g;
12641: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 12642: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 12643: if ($field eq 'screenshot') {
12644: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
12645: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 12646: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 12647: }
12648: }
12649: }
12650: }
12651: }
12652: }
1.315 raeburn 12653: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12654: my (@statuses,%usertypeshash,@overrides);
12655: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
12656: @statuses = @{$types};
12657: if (ref($usertypes) eq 'HASH') {
12658: %usertypeshash = %{$usertypes};
12659: }
12660: }
12661: if (@statuses) {
12662: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
12663: foreach my $type (@possoverrides) {
12664: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
12665: push(@overrides,$type);
12666: }
12667: }
12668: if (@overrides) {
12669: foreach my $type (@overrides) {
12670: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
12671: foreach my $item (@contacts) {
12672: if (grep(/^\Q$item\E$/,@standard)) {
12673: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
12674: $newsetting{'override_'.$type}{$item} = 1;
12675: } else {
12676: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
12677: $newsetting{'override_'.$type}{$item} = 0;
12678: }
12679: }
12680: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
12681: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
12682: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
12683: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
12684: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
12685: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
12686: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
12687: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
12688: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
12689: }
12690: }
12691: }
12692: }
1.28 raeburn 12693: if (keys(%currsetting) > 0) {
12694: foreach my $item (@contacts) {
12695: if ($to{$item} ne $currsetting{$item}) {
12696: $changes{$item} = 1;
12697: }
12698: }
12699: foreach my $type (@mailings) {
12700: foreach my $item (@contacts) {
12701: if (ref($currsetting{$type}) eq 'HASH') {
12702: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
12703: push(@{$changes{$type}},$item);
12704: }
12705: } else {
12706: push(@{$changes{$type}},@{$newsetting{$type}});
12707: }
12708: }
12709: if ($others{$type} ne $currsetting{$type}{'others'}) {
12710: push(@{$changes{$type}},'others');
12711: }
1.289 raeburn 12712: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12713: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
12714: push(@{$changes{$type}},'bcc');
12715: }
1.286 raeburn 12716: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
12717: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
12718: push(@{$changes{$type}},'include');
12719: }
12720: }
12721: }
12722: if (ref($fields) eq 'ARRAY') {
12723: if (ref($currsetting{'helpform'}) eq 'HASH') {
12724: foreach my $field (@{$fields}) {
12725: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
12726: push(@{$changes{'helpform'}},$field);
12727: }
12728: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12729: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
12730: push(@{$changes{'helpform'}},'maxsize');
12731: }
12732: }
12733: }
12734: } else {
12735: foreach my $field (@{$fields}) {
12736: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12737: push(@{$changes{'helpform'}},$field);
12738: }
12739: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12740: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12741: push(@{$changes{'helpform'}},'maxsize');
12742: }
12743: }
12744: }
1.134 raeburn 12745: }
1.28 raeburn 12746: }
1.315 raeburn 12747: if (@statuses) {
12748: if (ref($currsetting{'overrides'}) eq 'HASH') {
12749: foreach my $key (keys(%{$currsetting{'overrides'}})) {
12750: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
12751: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
12752: foreach my $item (@contacts,'bcc','others','include') {
12753: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
12754: push(@{$changes{'overrides'}},$key);
12755: last;
12756: }
12757: }
12758: } else {
12759: push(@{$changes{'overrides'}},$key);
12760: }
12761: }
12762: }
12763: foreach my $key (@overrides) {
12764: unless (exists($currsetting{'overrides'}{$key})) {
12765: push(@{$changes{'overrides'}},$key);
12766: }
12767: }
12768: } else {
12769: foreach my $key (@overrides) {
12770: push(@{$changes{'overrides'}},$key);
12771: }
12772: }
12773: }
1.28 raeburn 12774: } else {
12775: my %default;
12776: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
12777: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
12778: $default{'errormail'} = 'adminemail';
12779: $default{'packagesmail'} = 'adminemail';
12780: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 12781: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 12782: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 12783: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 12784: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 12785: foreach my $item (@contacts) {
12786: if ($to{$item} ne $default{$item}) {
1.286 raeburn 12787: $changes{$item} = 1;
1.203 raeburn 12788: }
1.28 raeburn 12789: }
12790: foreach my $type (@mailings) {
12791: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
12792: push(@{$changes{$type}},@{$newsetting{$type}});
12793: }
12794: if ($others{$type} ne '') {
12795: push(@{$changes{$type}},'others');
1.134 raeburn 12796: }
1.286 raeburn 12797: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12798: if ($bcc{$type} ne '') {
12799: push(@{$changes{$type}},'bcc');
12800: }
1.286 raeburn 12801: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
12802: push(@{$changes{$type}},'include');
12803: }
1.134 raeburn 12804: }
1.28 raeburn 12805: }
1.286 raeburn 12806: if (ref($fields) eq 'ARRAY') {
12807: foreach my $field (@{$fields}) {
12808: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12809: push(@{$changes{'helpform'}},$field);
12810: }
12811: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12812: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12813: push(@{$changes{'helpform'}},'maxsize');
12814: }
12815: }
12816: }
1.289 raeburn 12817: }
1.28 raeburn 12818: }
1.203 raeburn 12819: foreach my $item (@toggles) {
12820: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
12821: $changes{$item} = 1;
12822: } elsif ((!$env{'form.'.$item}) &&
12823: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
12824: $changes{$item} = 1;
12825: }
12826: }
1.28 raeburn 12827: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
12828: $dom);
12829: if ($putresult eq 'ok') {
12830: if (keys(%changes) > 0) {
1.205 raeburn 12831: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12832: if (ref($lastactref) eq 'HASH') {
12833: $lastactref->{'domainconfig'} = 1;
12834: }
1.28 raeburn 12835: my ($titles,$short_titles) = &contact_titles();
12836: $resulttext = &mt('Changes made:').'<ul>';
12837: foreach my $item (@contacts) {
12838: if ($changes{$item}) {
12839: $resulttext .= '<li>'.$titles->{$item}.
12840: &mt(' set to: ').
12841: '<span class="LC_cusr_emph">'.
12842: $to{$item}.'</span></li>';
12843: }
12844: }
12845: foreach my $type (@mailings) {
12846: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 12847: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 12848: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 12849: } else {
12850: $resulttext .= '<li>'.$titles->{$type}.': ';
12851: }
1.28 raeburn 12852: my @text;
12853: foreach my $item (@{$newsetting{$type}}) {
12854: push(@text,$short_titles->{$item});
12855: }
12856: if ($others{$type} ne '') {
12857: push(@text,$others{$type});
12858: }
1.286 raeburn 12859: if (@text) {
12860: $resulttext .= '<span class="LC_cusr_emph">'.
12861: join(', ',@text).'</span>';
12862: }
12863: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12864: if ($bcc{$type} ne '') {
1.286 raeburn 12865: my $bcctext;
12866: if (@text) {
1.289 raeburn 12867: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 12868: } else {
12869: $bcctext = '(Bcc)';
12870: }
12871: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
12872: } elsif (!@text) {
12873: $resulttext .= &mt('No one');
12874: }
1.289 raeburn 12875: if ($includestr{$type} ne '') {
1.286 raeburn 12876: if ($includeloc{$type} eq 'b') {
12877: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
12878: } elsif ($includeloc{$type} eq 's') {
12879: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
12880: }
1.134 raeburn 12881: }
1.286 raeburn 12882: } elsif (!@text) {
12883: $resulttext .= &mt('No recipients');
1.134 raeburn 12884: }
12885: $resulttext .= '</li>';
1.28 raeburn 12886: }
12887: }
1.315 raeburn 12888: if (ref($changes{'overrides'}) eq 'ARRAY') {
12889: my @deletions;
12890: foreach my $type (@{$changes{'overrides'}}) {
12891: if ($usertypeshash{$type}) {
12892: if (grep(/^\Q$type\E/,@overrides)) {
12893: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
12894: $usertypeshash{$type}).'<ul><li>';
12895: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
12896: my @text;
12897: foreach my $item (@contacts) {
12898: if ($newsetting{'override_'.$type}{$item}) {
12899: push(@text,$short_titles->{$item});
12900: }
12901: }
12902: if ($newsetting{'override_'.$type}{'others'} ne '') {
12903: push(@text,$newsetting{'override_'.$type}{'others'});
12904: }
12905:
12906: if (@text) {
12907: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
12908: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
12909: }
12910: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
12911: my $bcctext;
12912: if (@text) {
12913: $bcctext = ' '.&mt('with Bcc to');
12914: } else {
12915: $bcctext = '(Bcc)';
12916: }
12917: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
12918: } elsif (!@text) {
12919: $resulttext .= &mt('Helpdesk e-mail sent to no one');
12920: }
12921: $resulttext .= '</li>';
12922: if ($newsetting{'override_'.$type}{'include'} ne '') {
12923: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
12924: if ($loc eq 'b') {
12925: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
12926: } elsif ($loc eq 's') {
12927: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
12928: }
12929: }
12930: }
12931: $resulttext .= '</li></ul></li>';
12932: } else {
12933: push(@deletions,$usertypeshash{$type});
12934: }
12935: }
12936: }
12937: if (@deletions) {
12938: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
12939: join(', ',@deletions)).'</li>';
12940: }
12941: }
1.203 raeburn 12942: my @offon = ('off','on');
12943: if ($changes{'reporterrors'}) {
12944: $resulttext .= '<li>'.
12945: &mt('E-mail error reports to [_1] set to "'.
12946: $offon[$env{'form.reporterrors'}].'".',
12947: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
12948: &mt('LON-CAPA core group - MSU'),600,500)).
12949: '</li>';
12950: }
12951: if ($changes{'reportupdates'}) {
12952: $resulttext .= '<li>'.
12953: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
12954: $offon[$env{'form.reportupdates'}].'".',
12955: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
12956: &mt('LON-CAPA core group - MSU'),600,500)).
12957: '</li>';
12958: }
1.286 raeburn 12959: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
12960: my (@optional,@required,@unused,$maxsizechg);
12961: foreach my $field (@{$changes{'helpform'}}) {
12962: if ($field eq 'maxsize') {
12963: $maxsizechg = 1;
12964: next;
12965: }
12966: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 12967: push(@optional,$field);
1.286 raeburn 12968: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
12969: push(@unused,$field);
12970: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 12971: push(@required,$field);
1.286 raeburn 12972: }
12973: }
12974: if (@optional) {
12975: $resulttext .= '<li>'.
12976: &mt('Help form fields changed to "Optional": [_1].',
12977: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
12978: '</li>';
12979: }
12980: if (@required) {
12981: $resulttext .= '<li>'.
12982: &mt('Help form fields changed to "Required": [_1].',
12983: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
12984: '</li>';
12985: }
12986: if (@unused) {
12987: $resulttext .= '<li>'.
12988: &mt('Help form fields changed to "Not shown": [_1].',
12989: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
12990: '</li>';
12991: }
12992: if ($maxsizechg) {
12993: $resulttext .= '<li>'.
12994: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
12995: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
12996: '</li>';
12997: }
12998: }
1.28 raeburn 12999: $resulttext .= '</ul>';
13000: } else {
1.288 raeburn 13001: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 13002: }
13003: } else {
13004: $resulttext = '<span class="LC_error">'.
13005: &mt('An error occurred: [_1].',$putresult).'</span>';
13006: }
13007: return $resulttext;
13008: }
13009:
13010: sub modify_usercreation {
1.27 raeburn 13011: my ($dom,%domconfig) = @_;
1.224 raeburn 13012: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 13013: my $warningmsg;
1.27 raeburn 13014: if (ref($domconfig{'usercreation'}) eq 'HASH') {
13015: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 13016: if ($key eq 'cancreate') {
13017: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
13018: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 13019: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
13020: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13021: } else {
1.224 raeburn 13022: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13023: }
13024: }
13025: }
13026: } elsif ($key eq 'email_rule') {
13027: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
13028: } else {
13029: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
13030: }
1.27 raeburn 13031: }
13032: }
13033: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 13034: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 13035: my @contexts = ('author','course','requestcrs');
1.34 raeburn 13036: foreach my $item(@contexts) {
1.224 raeburn 13037: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 13038: }
1.34 raeburn 13039: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13040: foreach my $item (@contexts) {
1.224 raeburn 13041: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
13042: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 13043: }
1.27 raeburn 13044: }
1.34 raeburn 13045: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
13046: foreach my $item (@contexts) {
1.43 raeburn 13047: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 13048: if ($cancreate{$item} ne 'any') {
13049: push(@{$changes{'cancreate'}},$item);
13050: }
13051: } else {
13052: if ($cancreate{$item} ne 'none') {
13053: push(@{$changes{'cancreate'}},$item);
13054: }
1.27 raeburn 13055: }
13056: }
13057: } else {
1.43 raeburn 13058: foreach my $item (@contexts) {
1.34 raeburn 13059: push(@{$changes{'cancreate'}},$item);
13060: }
1.27 raeburn 13061: }
1.34 raeburn 13062:
1.27 raeburn 13063: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
13064: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
13065: if (!grep(/^\Q$type\E$/,@username_rule)) {
13066: push(@{$changes{'username_rule'}},$type);
13067: }
13068: }
13069: foreach my $type (@username_rule) {
13070: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
13071: push(@{$changes{'username_rule'}},$type);
13072: }
13073: }
13074: } else {
13075: push(@{$changes{'username_rule'}},@username_rule);
13076: }
13077:
1.32 raeburn 13078: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
13079: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
13080: if (!grep(/^\Q$type\E$/,@id_rule)) {
13081: push(@{$changes{'id_rule'}},$type);
13082: }
13083: }
13084: foreach my $type (@id_rule) {
13085: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
13086: push(@{$changes{'id_rule'}},$type);
13087: }
13088: }
13089: } else {
13090: push(@{$changes{'id_rule'}},@id_rule);
13091: }
13092:
1.43 raeburn 13093: my @authen_contexts = ('author','course','domain');
1.325 raeburn 13094: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 13095: my %authhash;
1.43 raeburn 13096: foreach my $item (@authen_contexts) {
1.28 raeburn 13097: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
13098: foreach my $auth (@authtypes) {
13099: if (grep(/^\Q$auth\E$/,@authallowed)) {
13100: $authhash{$item}{$auth} = 1;
13101: } else {
13102: $authhash{$item}{$auth} = 0;
13103: }
13104: }
13105: }
13106: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 13107: foreach my $item (@authen_contexts) {
1.28 raeburn 13108: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
13109: foreach my $auth (@authtypes) {
13110: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
13111: push(@{$changes{'authtypes'}},$item);
13112: last;
13113: }
13114: }
13115: }
13116: }
13117: } else {
1.43 raeburn 13118: foreach my $item (@authen_contexts) {
1.28 raeburn 13119: push(@{$changes{'authtypes'}},$item);
13120: }
13121: }
13122:
1.224 raeburn 13123: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
13124: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
13125: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
13126: $save_usercreate{'id_rule'} = \@id_rule;
13127: $save_usercreate{'username_rule'} = \@username_rule,
13128: $save_usercreate{'authtypes'} = \%authhash;
13129:
1.27 raeburn 13130: my %usercreation_hash = (
1.224 raeburn 13131: usercreation => \%save_usercreate,
13132: );
1.27 raeburn 13133:
13134: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
13135: $dom);
1.50 raeburn 13136:
1.224 raeburn 13137: if ($putresult eq 'ok') {
13138: if (keys(%changes) > 0) {
13139: $resulttext = &mt('Changes made:').'<ul>';
13140: if (ref($changes{'cancreate'}) eq 'ARRAY') {
13141: my %lt = &usercreation_types();
13142: foreach my $type (@{$changes{'cancreate'}}) {
13143: my $chgtext = $lt{$type}.', ';
13144: if ($cancreate{$type} eq 'none') {
13145: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
13146: } elsif ($cancreate{$type} eq 'any') {
13147: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
13148: } elsif ($cancreate{$type} eq 'official') {
13149: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
13150: } elsif ($cancreate{$type} eq 'unofficial') {
13151: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
13152: }
13153: $resulttext .= '<li>'.$chgtext.'</li>';
13154: }
13155: }
13156: if (ref($changes{'username_rule'}) eq 'ARRAY') {
13157: my ($rules,$ruleorder) =
13158: &Apache::lonnet::inst_userrules($dom,'username');
13159: my $chgtext = '<ul>';
13160: foreach my $type (@username_rule) {
13161: if (ref($rules->{$type}) eq 'HASH') {
13162: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
13163: }
13164: }
13165: $chgtext .= '</ul>';
13166: if (@username_rule > 0) {
13167: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13168: } else {
13169: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
13170: }
13171: }
13172: if (ref($changes{'id_rule'}) eq 'ARRAY') {
13173: my ($idrules,$idruleorder) =
13174: &Apache::lonnet::inst_userrules($dom,'id');
13175: my $chgtext = '<ul>';
13176: foreach my $type (@id_rule) {
13177: if (ref($idrules->{$type}) eq 'HASH') {
13178: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
13179: }
13180: }
13181: $chgtext .= '</ul>';
13182: if (@id_rule > 0) {
13183: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13184: } else {
13185: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
13186: }
13187: }
13188: my %authname = &authtype_names();
13189: my %context_title = &context_names();
13190: if (ref($changes{'authtypes'}) eq 'ARRAY') {
13191: my $chgtext = '<ul>';
13192: foreach my $type (@{$changes{'authtypes'}}) {
13193: my @allowed;
13194: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
13195: foreach my $auth (@authtypes) {
13196: if ($authhash{$type}{$auth}) {
13197: push(@allowed,$authname{$auth});
13198: }
13199: }
13200: if (@allowed > 0) {
13201: $chgtext .= join(', ',@allowed).'</li>';
13202: } else {
13203: $chgtext .= &mt('none').'</li>';
13204: }
13205: }
13206: $chgtext .= '</ul>';
13207: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
13208: $resulttext .= '</li>';
13209: }
13210: $resulttext .= '</ul>';
13211: } else {
13212: $resulttext = &mt('No changes made to user creation settings');
13213: }
13214: } else {
13215: $resulttext = '<span class="LC_error">'.
13216: &mt('An error occurred: [_1]',$putresult).'</span>';
13217: }
13218: if ($warningmsg ne '') {
13219: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
13220: }
13221: return $resulttext;
13222: }
13223:
13224: sub modify_selfcreation {
1.305 raeburn 13225: my ($dom,$lastactref,%domconfig) = @_;
13226: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
13227: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
13228: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 13229: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
13230: if (ref($typesref) eq 'ARRAY') {
13231: @types = @{$typesref};
13232: }
13233: if (ref($usertypesref) eq 'HASH') {
13234: %usertypes = %{$usertypesref};
1.228 raeburn 13235: }
1.303 raeburn 13236: $usertypes{'default'} = $othertitle;
1.224 raeburn 13237: #
13238: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
13239: #
13240: if (ref($domconfig{'usercreation'}) eq 'HASH') {
13241: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
13242: if ($key eq 'cancreate') {
13243: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
13244: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
13245: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 13246: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
13247: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
13248: ($item eq 'emailusername') || ($item eq 'shibenv') ||
13249: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 13250: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 13251: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13252: } else {
13253: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13254: }
13255: }
13256: }
13257: } elsif ($key eq 'email_rule') {
13258: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
13259: } else {
13260: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
13261: }
13262: }
13263: }
13264: #
13265: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
13266: #
13267: if (ref($domconfig{'usermodification'}) eq 'HASH') {
13268: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
13269: if ($key eq 'selfcreate') {
13270: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
13271: } else {
13272: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
13273: }
13274: }
13275: }
1.305 raeburn 13276: #
13277: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
13278: #
13279: if (ref($domconfig{'inststatus'}) eq 'HASH') {
13280: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
13281: if ($key eq 'inststatusguest') {
13282: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
13283: } else {
13284: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
13285: }
13286: }
13287: }
1.224 raeburn 13288:
13289: my @contexts = ('selfcreate');
13290: @{$cancreate{'selfcreate'}} = ();
13291: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 13292: if (@types) {
13293: @{$cancreate{'statustocreate'}} = ();
13294: }
1.236 raeburn 13295: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 13296: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 13297: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 13298: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 13299: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 13300: my %selfcreatetypes = (
13301: sso => 'users authenticated by institutional single sign on',
13302: login => 'users authenticated by institutional log-in',
1.303 raeburn 13303: email => 'users verified by e-mail',
1.50 raeburn 13304: );
1.224 raeburn 13305: #
13306: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
13307: # is permitted.
13308: #
1.305 raeburn 13309: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 13310:
1.305 raeburn 13311: my (@statuses,%email_rule);
1.228 raeburn 13312: foreach my $item ('login','sso','email') {
1.224 raeburn 13313: if ($item eq 'email') {
1.236 raeburn 13314: if ($env{'form.cancreate_email'}) {
1.305 raeburn 13315: if (@types) {
13316: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
13317: foreach my $status (@poss_statuses) {
13318: if (grep(/^\Q$status\E$/,(@types,'default'))) {
13319: push(@statuses,$status);
13320: }
13321: }
13322: $save_inststatus{'inststatusguest'} = \@statuses;
13323: } else {
13324: push(@statuses,'default');
13325: }
13326: if (@statuses) {
13327: my %curr_rule;
13328: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
13329: foreach my $type (@statuses) {
13330: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 13331: }
1.305 raeburn 13332: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
13333: foreach my $type (@statuses) {
13334: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
13335: }
13336: }
13337: push(@{$cancreate{'selfcreate'}},'email');
13338: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
13339: my %curremaildom;
13340: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
13341: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
13342: }
13343: foreach my $type (@statuses) {
13344: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
13345: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
13346: }
13347: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
13348: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
13349: }
13350: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
13351: #
13352: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
13353: #
13354: my $chosen = $1;
13355: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
13356: my $emaildom;
13357: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
13358: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
13359: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
13360: if (ref($curremaildom{$type}) eq 'HASH') {
13361: if (exists($curremaildom{$type}{$chosen})) {
13362: if ($curremaildom{$type}{$chosen} ne $emaildom) {
13363: push(@{$changes{'cancreate'}},'emaildomain');
13364: }
13365: } elsif ($emaildom ne '') {
13366: push(@{$changes{'cancreate'}},'emaildomain');
13367: }
13368: } elsif ($emaildom ne '') {
13369: push(@{$changes{'cancreate'}},'emaildomain');
13370: }
13371: }
13372: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13373: } elsif ($chosen eq 'custom') {
13374: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
13375: $email_rule{$type} = [];
13376: if (ref($emailrules) eq 'HASH') {
13377: foreach my $rule (@possemail_rules) {
13378: if (exists($emailrules->{$rule})) {
13379: push(@{$email_rule{$type}},$rule);
13380: }
13381: }
13382: }
13383: if (@{$email_rule{$type}}) {
13384: $cancreate{'emailoptions'}{$type} = 'custom';
13385: if (ref($curr_rule{$type}) eq 'ARRAY') {
13386: if (@{$curr_rule{$type}} > 0) {
13387: foreach my $rule (@{$curr_rule{$type}}) {
13388: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
13389: push(@{$changes{'email_rule'}},$type);
13390: }
13391: }
13392: }
13393: foreach my $type (@{$email_rule{$type}}) {
13394: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
13395: push(@{$changes{'email_rule'}},$type);
13396: }
13397: }
13398: } else {
13399: push(@{$changes{'email_rule'}},$type);
13400: }
13401: }
13402: } else {
13403: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13404: }
13405: }
13406: }
13407: if (@types) {
13408: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13409: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
13410: if (@changed) {
13411: push(@{$changes{'inststatus'}},'inststatusguest');
13412: }
13413: } else {
13414: push(@{$changes{'inststatus'}},'inststatusguest');
13415: }
13416: }
13417: } else {
13418: delete($env{'form.cancreate_email'});
13419: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13420: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13421: push(@{$changes{'inststatus'}},'inststatusguest');
13422: }
13423: }
13424: }
13425: } else {
13426: $save_inststatus{'inststatusguest'} = [];
13427: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13428: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13429: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 13430: }
13431: }
1.224 raeburn 13432: }
13433: } else {
13434: if ($env{'form.cancreate_'.$item}) {
13435: push(@{$cancreate{'selfcreate'}},$item);
13436: }
13437: }
13438: }
1.305 raeburn 13439: my (%userinfo,%savecaptcha);
1.224 raeburn 13440: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
13441: #
1.228 raeburn 13442: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
13443: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 13444: #
1.236 raeburn 13445:
1.244 raeburn 13446: if ($env{'form.cancreate_email'}) {
1.228 raeburn 13447: push(@contexts,'emailusername');
1.305 raeburn 13448: if (@statuses) {
13449: foreach my $type (@statuses) {
1.228 raeburn 13450: if (ref($infofields) eq 'ARRAY') {
13451: foreach my $field (@{$infofields}) {
13452: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
13453: $cancreate{'emailusername'}{$type}{$field} = $1;
13454: }
13455: }
1.224 raeburn 13456: }
13457: }
13458: }
13459: #
13460: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 13461: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 13462: #
13463:
13464: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
13465: @approvalnotify = sort(@approvalnotify);
13466: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
13467: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13468: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
13469: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
13470: push(@{$changes{'cancreate'}},'notify');
13471: }
13472: } else {
13473: if ($cancreate{'notify'}{'approval'}) {
13474: push(@{$changes{'cancreate'}},'notify');
13475: }
13476: }
13477: } elsif ($cancreate{'notify'}{'approval'}) {
13478: push(@{$changes{'cancreate'}},'notify');
13479: }
13480:
13481: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
13482: }
13483: #
1.236 raeburn 13484: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 13485: # institutional log-in.
13486: #
13487: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
13488: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
13489: ($domdefaults{'auth_def'} eq 'localauth'))) {
13490: $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.').' '.
13491: &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.');
13492: }
13493: }
13494: my @fields = ('lastname','firstname','middlename','generation',
13495: 'permanentemail','id');
1.240 raeburn 13496: my @shibfields = (@fields,'inststatus');
1.224 raeburn 13497: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13498: #
13499: # Where usernames may created for institutional log-in and/or institutional single sign on:
13500: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
13501: # may self-create accounts
13502: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
13503: # which the user may supply, if institutional data is unavailable.
13504: #
13505: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 13506: if (@types) {
1.305 raeburn 13507: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
13508: push(@contexts,'statustocreate');
1.303 raeburn 13509: foreach my $type (@types) {
1.224 raeburn 13510: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
13511: foreach my $field (@fields) {
13512: if (grep(/^\Q$field\E$/,@modifiable)) {
13513: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
13514: } else {
13515: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
13516: }
13517: }
13518: }
13519: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 13520: foreach my $type (@types) {
1.224 raeburn 13521: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
13522: foreach my $field (@fields) {
13523: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
13524: $curr_usermodify{'selfcreate'}{$type}{$field}) {
13525: push(@{$changes{'selfcreate'}},$type);
13526: last;
13527: }
13528: }
13529: }
13530: }
13531: } else {
1.303 raeburn 13532: foreach my $type (@types) {
1.224 raeburn 13533: push(@{$changes{'selfcreate'}},$type);
13534: }
13535: }
13536: }
1.240 raeburn 13537: foreach my $field (@shibfields) {
13538: if ($env{'form.shibenv_'.$field} ne '') {
13539: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
13540: }
13541: }
13542: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13543: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
13544: foreach my $field (@shibfields) {
13545: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
13546: push(@{$changes{'cancreate'}},'shibenv');
13547: }
13548: }
13549: } else {
13550: foreach my $field (@shibfields) {
13551: if ($env{'form.shibenv_'.$field}) {
13552: push(@{$changes{'cancreate'}},'shibenv');
13553: last;
13554: }
13555: }
13556: }
13557: }
1.224 raeburn 13558: }
13559: foreach my $item (@contexts) {
13560: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
13561: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
13562: if (ref($cancreate{$item}) eq 'ARRAY') {
13563: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
13564: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13565: push(@{$changes{'cancreate'}},$item);
13566: }
13567: }
13568: }
13569: }
13570: if (ref($cancreate{$item}) eq 'ARRAY') {
13571: foreach my $type (@{$cancreate{$item}}) {
13572: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
13573: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13574: push(@{$changes{'cancreate'}},$item);
13575: }
13576: }
13577: }
13578: }
13579: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
13580: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 13581: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
13582: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13583: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
13584: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 13585: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13586: push(@{$changes{'cancreate'}},$item);
13587: }
13588: }
13589: }
1.305 raeburn 13590: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13591: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 13592: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13593: push(@{$changes{'cancreate'}},$item);
13594: }
1.224 raeburn 13595: }
13596: }
13597: }
1.305 raeburn 13598: foreach my $type (keys(%{$cancreate{$item}})) {
13599: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13600: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13601: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13602: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 13603: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13604: push(@{$changes{'cancreate'}},$item);
13605: }
13606: }
13607: } else {
13608: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13609: push(@{$changes{'cancreate'}},$item);
13610: }
13611: }
13612: }
1.305 raeburn 13613: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13614: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 13615: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13616: push(@{$changes{'cancreate'}},$item);
13617: }
1.224 raeburn 13618: }
13619: }
13620: }
13621: }
13622: } elsif ($curr_usercreation{'cancreate'}{$item}) {
13623: if (ref($cancreate{$item}) eq 'ARRAY') {
13624: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
13625: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13626: push(@{$changes{'cancreate'}},$item);
13627: }
13628: }
1.305 raeburn 13629: }
13630: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13631: if (ref($cancreate{$item}) eq 'HASH') {
13632: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13633: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 13634: }
13635: }
13636: } elsif ($item eq 'emailusername') {
1.228 raeburn 13637: if (ref($cancreate{$item}) eq 'HASH') {
13638: foreach my $type (keys(%{$cancreate{$item}})) {
13639: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13640: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13641: if ($cancreate{$item}{$type}{$field}) {
13642: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13643: push(@{$changes{'cancreate'}},$item);
13644: }
13645: last;
13646: }
13647: }
13648: }
13649: }
1.224 raeburn 13650: }
13651: }
13652: }
13653: #
13654: # Populate %save_usercreate hash with updates to self-creation configuration.
13655: #
13656: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
13657: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 13658: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 13659: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
13660: if (ref($cancreate{'notify'}) eq 'HASH') {
13661: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
13662: }
1.236 raeburn 13663: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
13664: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
13665: }
1.303 raeburn 13666: if (ref($cancreate{'emailverified'}) eq 'HASH') {
13667: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
13668: }
1.305 raeburn 13669: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
13670: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
13671: }
1.303 raeburn 13672: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
13673: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
13674: }
1.224 raeburn 13675: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13676: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
13677: }
1.240 raeburn 13678: if (ref($cancreate{'shibenv'}) eq 'HASH') {
13679: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
13680: }
1.224 raeburn 13681: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 13682: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 13683:
13684: my %userconfig_hash = (
13685: usercreation => \%save_usercreate,
13686: usermodification => \%save_usermodify,
1.305 raeburn 13687: inststatus => \%save_inststatus,
1.224 raeburn 13688: );
1.305 raeburn 13689:
1.224 raeburn 13690: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
13691: $dom);
13692: #
1.305 raeburn 13693: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 13694: #
1.27 raeburn 13695: if ($putresult eq 'ok') {
13696: if (keys(%changes) > 0) {
13697: $resulttext = &mt('Changes made:').'<ul>';
13698: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 13699: my %lt = &selfcreation_types();
1.34 raeburn 13700: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 13701: my $chgtext = '';
1.45 raeburn 13702: if ($type eq 'selfcreate') {
1.50 raeburn 13703: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 13704: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 13705: } else {
1.224 raeburn 13706: $chgtext .= &mt('Self-creation of a new account is permitted for:').
13707: '<ul>';
1.50 raeburn 13708: foreach my $case (@{$cancreate{$type}}) {
13709: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
13710: }
13711: $chgtext .= '</ul>';
1.100 raeburn 13712: if (ref($cancreate{$type}) eq 'ARRAY') {
13713: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
13714: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13715: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 13716: $chgtext .= '<span class="LC_warning">'.
13717: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
13718: '</span><br />';
13719: }
13720: }
13721: }
13722: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 13723: if (!@statuses) {
13724: $chgtext .= '<span class="LC_warning">'.
13725: &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.").
13726: '</span><br />';
1.303 raeburn 13727:
1.100 raeburn 13728: }
13729: }
13730: }
1.43 raeburn 13731: }
1.240 raeburn 13732: } elsif ($type eq 'shibenv') {
13733: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 13734: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 13735: } else {
13736: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
13737: '<ul>';
13738: foreach my $field (@shibfields) {
13739: next if ($cancreate{$type}{$field} eq '');
13740: if ($field eq 'inststatus') {
13741: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
13742: } else {
13743: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
13744: }
13745: }
13746: $chgtext .= '</ul>';
1.303 raeburn 13747: }
1.93 raeburn 13748: } elsif ($type eq 'statustocreate') {
1.96 raeburn 13749: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
13750: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
13751: if (@{$cancreate{'selfcreate'}} > 0) {
13752: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 13753: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 13754: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 13755: $chgtext .= '<br />'.
13756: '<span class="LC_warning">'.
13757: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
13758: '</span>';
13759: }
1.303 raeburn 13760: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 13761: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 13762: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
13763: } else {
13764: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
13765: }
13766: $chgtext .= '<ul>';
13767: foreach my $case (@{$cancreate{$type}}) {
13768: if ($case eq 'default') {
13769: $chgtext .= '<li>'.$othertitle.'</li>';
13770: } else {
1.303 raeburn 13771: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 13772: }
13773: }
1.100 raeburn 13774: $chgtext .= '</ul>';
13775: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 13776: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 13777: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
13778: '</span>';
1.100 raeburn 13779: }
13780: }
13781: } else {
13782: if (@{$cancreate{$type}} == 0) {
13783: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
13784: } else {
13785: $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 13786: }
13787: }
1.303 raeburn 13788: $chgtext .= '<br />';
1.93 raeburn 13789: }
1.236 raeburn 13790: } elsif ($type eq 'selfcreateprocessing') {
13791: my %choices = &Apache::lonlocal::texthash (
13792: automatic => 'Automatic approval',
13793: approval => 'Queued for approval',
13794: );
1.305 raeburn 13795: if (@types) {
13796: if (@statuses) {
1.303 raeburn 13797: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 13798: '<ul>';
1.305 raeburn 13799: foreach my $status (@statuses) {
13800: if ($status eq 'default') {
13801: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 13802: } else {
1.305 raeburn 13803: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 13804: }
13805: }
13806: $chgtext .= '</ul>';
13807: }
13808: } else {
13809: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
13810: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
13811: }
13812: } elsif ($type eq 'emailverified') {
13813: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 13814: all => 'Same as e-mail',
13815: first => 'Omit @domain',
13816: free => 'Free to choose',
1.303 raeburn 13817: );
1.305 raeburn 13818: if (@types) {
13819: if (@statuses) {
1.303 raeburn 13820: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
13821: '<ul>';
1.305 raeburn 13822: foreach my $status (@statuses) {
1.303 raeburn 13823: if ($type eq 'default') {
1.305 raeburn 13824: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 13825: } else {
1.305 raeburn 13826: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 13827: }
13828: }
13829: $chgtext .= '</ul>';
13830: }
13831: } else {
1.305 raeburn 13832: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 13833: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 13834: }
1.305 raeburn 13835: } elsif ($type eq 'emailoptions') {
13836: my %options = &Apache::lonlocal::texthash (
13837: any => 'Any e-mail',
13838: inst => 'Institutional only',
13839: noninst => 'Non-institutional only',
13840: custom => 'Custom restrictions',
13841: );
13842: if (@types) {
13843: if (@statuses) {
13844: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
13845: '<ul>';
13846: foreach my $status (@statuses) {
13847: if ($type eq 'default') {
13848: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
13849: } else {
13850: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 13851: }
13852: }
1.305 raeburn 13853: $chgtext .= '</ul>';
13854: }
13855: } else {
13856: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
13857: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
13858: } else {
13859: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
13860: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 13861: }
1.305 raeburn 13862: }
13863: } elsif ($type eq 'emaildomain') {
13864: my $output;
13865: if (@statuses) {
13866: foreach my $type (@statuses) {
13867: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
13868: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
13869: if ($type eq 'default') {
13870: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13871: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
13872: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
13873: } else {
13874: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
13875: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
13876: }
1.303 raeburn 13877: } else {
1.305 raeburn 13878: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13879: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
13880: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
13881: } else {
13882: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
13883: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
13884: }
1.303 raeburn 13885: }
1.305 raeburn 13886: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
13887: if ($type eq 'default') {
13888: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13889: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
13890: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
13891: } else {
13892: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
13893: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
13894: }
1.303 raeburn 13895: } else {
1.305 raeburn 13896: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13897: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
13898: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
13899: } else {
13900: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
13901: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
13902: }
1.303 raeburn 13903: }
13904: }
13905: }
13906: }
1.305 raeburn 13907: }
13908: if ($output ne '') {
13909: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
13910: '<ul>'.$output.'</ul>';
1.236 raeburn 13911: }
1.165 raeburn 13912: } elsif ($type eq 'captcha') {
1.224 raeburn 13913: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 13914: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
13915: } else {
13916: my %captchas = &captcha_phrases();
1.224 raeburn 13917: if ($captchas{$savecaptcha{$type}}) {
13918: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 13919: } else {
1.210 raeburn 13920: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 13921: }
13922: }
13923: } elsif ($type eq 'recaptchakeys') {
13924: my ($privkey,$pubkey);
1.224 raeburn 13925: if (ref($savecaptcha{$type}) eq 'HASH') {
13926: $pubkey = $savecaptcha{$type}{'public'};
13927: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 13928: }
13929: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
13930: if (!$pubkey) {
13931: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
13932: } else {
13933: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
13934: }
13935: if (!$privkey) {
13936: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
13937: } else {
13938: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
13939: }
13940: $chgtext .= '</ul>';
1.269 raeburn 13941: } elsif ($type eq 'recaptchaversion') {
13942: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 13943: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 13944: }
1.224 raeburn 13945: } elsif ($type eq 'emailusername') {
13946: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 13947: if (@statuses) {
13948: foreach my $type (@statuses) {
1.228 raeburn 13949: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
13950: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 13951: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 13952: '<ul>';
13953: foreach my $field (@{$infofields}) {
13954: if ($cancreate{'emailusername'}{$type}{$field}) {
13955: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
13956: }
13957: }
1.245 raeburn 13958: $chgtext .= '</ul>';
13959: } else {
1.303 raeburn 13960: $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 13961: }
13962: } else {
1.303 raeburn 13963: $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
1.224 raeburn 13964: }
13965: }
13966: }
13967: }
13968: } elsif ($type eq 'notify') {
1.303 raeburn 13969: my $numapprove = 0;
1.224 raeburn 13970: if (ref($changes{'cancreate'}) eq 'ARRAY') {
13971: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
13972: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 13973: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
13974: $numapprove ++;
1.224 raeburn 13975: }
13976: }
1.43 raeburn 13977: }
1.303 raeburn 13978: unless ($numapprove) {
13979: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
13980: }
1.34 raeburn 13981: }
1.224 raeburn 13982: if ($chgtext) {
13983: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 13984: }
13985: }
13986: }
1.305 raeburn 13987: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 13988: my ($emailrules,$emailruleorder) =
13989: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 13990: foreach my $type (@{$changes{'email_rule'}}) {
13991: if (ref($email_rule{$type}) eq 'ARRAY') {
13992: my $chgtext = '<ul>';
13993: foreach my $rule (@{$email_rule{$type}}) {
13994: if (ref($emailrules->{$rule}) eq 'HASH') {
13995: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
13996: }
13997: }
13998: $chgtext .= '</ul>';
1.310 raeburn 13999: my $typename;
1.305 raeburn 14000: if (@types) {
14001: if ($type eq 'default') {
14002: $typename = $othertitle;
14003: } else {
14004: $typename = $usertypes{$type};
14005: }
14006: $chgtext .= &mt('(Affiliation: [_1])',$typename);
14007: }
14008: if (@{$email_rule{$type}} > 0) {
14009: $resulttext .= '<li>'.
14010: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
14011: $usertypes{$type}).
14012: $chgtext.
14013: '</li>';
14014: } else {
14015: $resulttext .= '<li>'.
1.310 raeburn 14016: &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 14017: '</li>'.
1.310 raeburn 14018: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 14019: }
1.43 raeburn 14020: }
14021: }
1.305 raeburn 14022: }
14023: if (ref($changes{'inststatus'}) eq 'ARRAY') {
14024: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
14025: if (@{$save_inststatus{'inststatusguest'}} > 0) {
14026: my $chgtext = '<ul>';
14027: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
14028: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
14029: }
14030: $chgtext .= '</ul>';
14031: $resulttext .= '<li>'.
14032: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
14033: $chgtext.
14034: '</li>';
14035: } else {
14036: $resulttext .= '<li>'.
14037: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
14038: '</li>';
14039: }
1.43 raeburn 14040: }
14041: }
1.224 raeburn 14042: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
14043: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
14044: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14045: foreach my $type (@{$changes{'selfcreate'}}) {
14046: my $typename = $type;
1.303 raeburn 14047: if (keys(%usertypes) > 0) {
14048: if ($usertypes{$type} ne '') {
14049: $typename = $usertypes{$type};
1.224 raeburn 14050: }
14051: }
14052: my @modifiable;
14053: $resulttext .= '<li>'.
14054: &mt('Self-creation of account by users with status: [_1]',
14055: '<span class="LC_cusr_emph">'.$typename.'</span>').
14056: ' - '.&mt('modifiable fields (if institutional data blank): ');
14057: foreach my $field (@fields) {
14058: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
14059: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 14060: }
14061: }
1.224 raeburn 14062: if (@modifiable > 0) {
14063: $resulttext .= join(', ',@modifiable);
1.43 raeburn 14064: } else {
1.224 raeburn 14065: $resulttext .= &mt('none');
1.43 raeburn 14066: }
1.224 raeburn 14067: $resulttext .= '</li>';
1.28 raeburn 14068: }
1.224 raeburn 14069: $resulttext .= '</ul></li>';
1.28 raeburn 14070: }
1.27 raeburn 14071: $resulttext .= '</ul>';
1.305 raeburn 14072: my $cachetime = 24*60*60;
14073: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
14074: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14075: if (ref($lastactref) eq 'HASH') {
14076: $lastactref->{'domdefaults'} = 1;
14077: }
1.27 raeburn 14078: } else {
1.224 raeburn 14079: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 14080: }
14081: } else {
14082: $resulttext = '<span class="LC_error">'.
1.23 raeburn 14083: &mt('An error occurred: [_1]',$putresult).'</span>';
14084: }
1.43 raeburn 14085: if ($warningmsg ne '') {
14086: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
14087: }
1.23 raeburn 14088: return $resulttext;
14089: }
14090:
1.165 raeburn 14091: sub process_captcha {
14092: my ($container,$changes,$newsettings,$current) = @_;
14093: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
14094: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
14095: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
14096: $newsettings->{'captcha'} = 'original';
14097: }
14098: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 14099: if ($container eq 'cancreate') {
1.169 raeburn 14100: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14101: push(@{$changes->{'cancreate'}},'captcha');
14102: } elsif (!defined($changes->{'cancreate'})) {
14103: $changes->{'cancreate'} = ['captcha'];
14104: }
14105: } else {
14106: $changes->{'captcha'} = 1;
1.165 raeburn 14107: }
14108: }
1.269 raeburn 14109: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 14110: if ($newsettings->{'captcha'} eq 'recaptcha') {
14111: $newpub = $env{'form.'.$container.'_recaptchapub'};
14112: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 14113: $newpub =~ s/[^\w\-]//g;
14114: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 14115: $newsettings->{'recaptchakeys'} = {
14116: public => $newpub,
14117: private => $newpriv,
14118: };
1.269 raeburn 14119: $newversion = $env{'form.'.$container.'_recaptchaversion'};
14120: $newversion =~ s/\D//g;
14121: if ($newversion ne '2') {
14122: $newversion = 1;
14123: }
14124: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 14125: }
14126: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
14127: $currpub = $current->{'recaptchakeys'}{'public'};
14128: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 14129: unless ($newsettings->{'captcha'} eq 'recaptcha') {
14130: $newsettings->{'recaptchakeys'} = {
14131: public => '',
14132: private => '',
14133: }
14134: }
1.165 raeburn 14135: }
1.269 raeburn 14136: if ($current->{'captcha'} eq 'recaptcha') {
14137: $currversion = $current->{'recaptchaversion'};
14138: if ($currversion ne '2') {
14139: $currversion = 1;
14140: }
14141: }
14142: if ($currversion ne $newversion) {
14143: if ($container eq 'cancreate') {
14144: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14145: push(@{$changes->{'cancreate'}},'recaptchaversion');
14146: } elsif (!defined($changes->{'cancreate'})) {
14147: $changes->{'cancreate'} = ['recaptchaversion'];
14148: }
14149: } else {
14150: $changes->{'recaptchaversion'} = 1;
14151: }
14152: }
1.165 raeburn 14153: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 14154: if ($container eq 'cancreate') {
14155: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14156: push(@{$changes->{'cancreate'}},'recaptchakeys');
14157: } elsif (!defined($changes->{'cancreate'})) {
14158: $changes->{'cancreate'} = ['recaptchakeys'];
14159: }
14160: } else {
1.210 raeburn 14161: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 14162: }
14163: }
14164: return;
14165: }
14166:
1.33 raeburn 14167: sub modify_usermodification {
14168: my ($dom,%domconfig) = @_;
1.224 raeburn 14169: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 14170: if (ref($domconfig{'usermodification'}) eq 'HASH') {
14171: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 14172: if ($key eq 'selfcreate') {
14173: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
14174: } else {
14175: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
14176: }
1.33 raeburn 14177: }
14178: }
1.224 raeburn 14179: my @contexts = ('author','course');
1.33 raeburn 14180: my %context_title = (
14181: author => 'In author context',
14182: course => 'In course context',
14183: );
14184: my @fields = ('lastname','firstname','middlename','generation',
14185: 'permanentemail','id');
14186: my %roles = (
14187: author => ['ca','aa'],
14188: course => ['st','ep','ta','in','cr'],
14189: );
14190: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14191: foreach my $context (@contexts) {
14192: foreach my $role (@{$roles{$context}}) {
14193: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
14194: foreach my $item (@fields) {
14195: if (grep(/^\Q$item\E$/,@modifiable)) {
14196: $modifyhash{$context}{$role}{$item} = 1;
14197: } else {
14198: $modifyhash{$context}{$role}{$item} = 0;
14199: }
14200: }
14201: }
14202: if (ref($curr_usermodification{$context}) eq 'HASH') {
14203: foreach my $role (@{$roles{$context}}) {
14204: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
14205: foreach my $field (@fields) {
14206: if ($modifyhash{$context}{$role}{$field} ne
14207: $curr_usermodification{$context}{$role}{$field}) {
14208: push(@{$changes{$context}},$role);
14209: last;
14210: }
14211: }
14212: }
14213: }
14214: } else {
14215: foreach my $context (@contexts) {
14216: foreach my $role (@{$roles{$context}}) {
14217: push(@{$changes{$context}},$role);
14218: }
14219: }
14220: }
14221: }
14222: my %usermodification_hash = (
14223: usermodification => \%modifyhash,
14224: );
14225: my $putresult = &Apache::lonnet::put_dom('configuration',
14226: \%usermodification_hash,$dom);
14227: if ($putresult eq 'ok') {
14228: if (keys(%changes) > 0) {
14229: $resulttext = &mt('Changes made: ').'<ul>';
14230: foreach my $context (@contexts) {
14231: if (ref($changes{$context}) eq 'ARRAY') {
14232: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
14233: if (ref($changes{$context}) eq 'ARRAY') {
14234: foreach my $role (@{$changes{$context}}) {
14235: my $rolename;
1.224 raeburn 14236: if ($role eq 'cr') {
14237: $rolename = &mt('Custom');
1.33 raeburn 14238: } else {
1.224 raeburn 14239: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 14240: }
14241: my @modifiable;
1.224 raeburn 14242: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 14243: foreach my $field (@fields) {
14244: if ($modifyhash{$context}{$role}{$field}) {
14245: push(@modifiable,$fieldtitles{$field});
14246: }
14247: }
14248: if (@modifiable > 0) {
14249: $resulttext .= join(', ',@modifiable);
14250: } else {
14251: $resulttext .= &mt('none');
14252: }
14253: $resulttext .= '</li>';
14254: }
14255: $resulttext .= '</ul></li>';
14256: }
14257: }
14258: }
14259: $resulttext .= '</ul>';
14260: } else {
14261: $resulttext = &mt('No changes made to user modification settings');
14262: }
14263: } else {
14264: $resulttext = '<span class="LC_error">'.
14265: &mt('An error occurred: [_1]',$putresult).'</span>';
14266: }
14267: return $resulttext;
14268: }
14269:
1.43 raeburn 14270: sub modify_defaults {
1.212 raeburn 14271: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 14272: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 14273: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 14274: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
14275: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.325 raeburn 14276: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 14277: foreach my $item (@items) {
14278: $newvalues{$item} = $env{'form.'.$item};
14279: if ($item eq 'auth_def') {
14280: if ($newvalues{$item} ne '') {
14281: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
14282: push(@errors,$item);
14283: }
14284: }
14285: } elsif ($item eq 'lang_def') {
14286: if ($newvalues{$item} ne '') {
14287: if ($newvalues{$item} =~ /^(\w+)/) {
14288: my $langcode = $1;
1.103 raeburn 14289: if ($langcode ne 'x_chef') {
14290: if (code2language($langcode) eq '') {
14291: push(@errors,$item);
14292: }
1.43 raeburn 14293: }
14294: } else {
14295: push(@errors,$item);
14296: }
14297: }
1.54 raeburn 14298: } elsif ($item eq 'timezone_def') {
14299: if ($newvalues{$item} ne '') {
1.62 raeburn 14300: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 14301: push(@errors,$item);
14302: }
14303: }
1.68 raeburn 14304: } elsif ($item eq 'datelocale_def') {
14305: if ($newvalues{$item} ne '') {
14306: my @datelocale_ids = DateTime::Locale->ids();
14307: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
14308: push(@errors,$item);
14309: }
14310: }
1.141 raeburn 14311: } elsif ($item eq 'portal_def') {
14312: if ($newvalues{$item} ne '') {
14313: 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])\/?$/) {
14314: push(@errors,$item);
14315: }
14316: }
1.294 raeburn 14317: } elsif ($item eq 'intauth_cost') {
14318: if ($newvalues{$item} ne '') {
14319: if ($newvalues{$item} =~ /\D/) {
14320: push(@errors,$item);
14321: }
14322: }
14323: } elsif ($item eq 'intauth_check') {
14324: if ($newvalues{$item} ne '') {
14325: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
14326: push(@errors,$item);
14327: }
14328: }
14329: } elsif ($item eq 'intauth_switch') {
14330: if ($newvalues{$item} ne '') {
14331: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
14332: push(@errors,$item);
14333: }
14334: }
1.43 raeburn 14335: }
14336: if (grep(/^\Q$item\E$/,@errors)) {
14337: $newvalues{$item} = $domdefaults{$item};
14338: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
14339: $changes{$item} = 1;
14340: }
1.72 raeburn 14341: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 14342: }
14343: my %defaults_hash = (
1.72 raeburn 14344: defaults => \%newvalues,
14345: );
1.43 raeburn 14346: my $title = &defaults_titles();
1.236 raeburn 14347:
14348: my $currinststatus;
14349: if (ref($domconfig{'inststatus'}) eq 'HASH') {
14350: $currinststatus = $domconfig{'inststatus'};
14351: } else {
14352: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
14353: $currinststatus = {
14354: inststatustypes => $usertypes,
14355: inststatusorder => $types,
14356: inststatusguest => [],
14357: };
14358: }
14359: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
14360: my @allpos;
14361: my %alltypes;
1.305 raeburn 14362: my @inststatusguest;
14363: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
14364: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
14365: unless (grep(/^\Q$type\E$/,@todelete)) {
14366: push(@inststatusguest,$type);
14367: }
14368: }
14369: }
14370: my ($currtitles,$currorder);
1.236 raeburn 14371: if (ref($currinststatus) eq 'HASH') {
14372: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
14373: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
14374: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
14375: if ($currinststatus->{inststatustypes}->{$type} ne '') {
14376: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
14377: }
14378: }
14379: unless (grep(/^\Q$type\E$/,@todelete)) {
14380: my $position = $env{'form.inststatus_pos_'.$type};
14381: $position =~ s/\D+//g;
14382: $allpos[$position] = $type;
14383: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
14384: $alltypes{$type} =~ s/`//g;
14385: }
14386: }
14387: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
14388: $currtitles =~ s/,$//;
14389: }
14390: }
14391: if ($env{'form.addinststatus'}) {
14392: my $newtype = $env{'form.addinststatus'};
14393: $newtype =~ s/\W//g;
14394: unless (exists($alltypes{$newtype})) {
14395: $alltypes{$newtype} = $env{'form.addinststatus_title'};
14396: $alltypes{$newtype} =~ s/`//g;
14397: my $position = $env{'form.addinststatus_pos'};
14398: $position =~ s/\D+//g;
14399: if ($position ne '') {
14400: $allpos[$position] = $newtype;
14401: }
14402: }
14403: }
1.305 raeburn 14404: my @orderedstatus;
1.236 raeburn 14405: foreach my $type (@allpos) {
14406: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
14407: push(@orderedstatus,$type);
14408: }
14409: }
14410: foreach my $type (keys(%alltypes)) {
14411: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
14412: delete($alltypes{$type});
14413: }
14414: }
14415: $defaults_hash{'inststatus'} = {
14416: inststatustypes => \%alltypes,
14417: inststatusorder => \@orderedstatus,
1.305 raeburn 14418: inststatusguest => \@inststatusguest,
1.236 raeburn 14419: };
14420: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
14421: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
14422: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
14423: }
14424: }
14425: if ($currorder ne join(',',@orderedstatus)) {
14426: $changes{'inststatus'}{'inststatusorder'} = 1;
14427: }
14428: my $newtitles;
14429: foreach my $item (@orderedstatus) {
14430: $newtitles .= $alltypes{$item}.',';
14431: }
14432: $newtitles =~ s/,$//;
14433: if ($currtitles ne $newtitles) {
14434: $changes{'inststatus'}{'inststatustypes'} = 1;
14435: }
1.43 raeburn 14436: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
14437: $dom);
14438: if ($putresult eq 'ok') {
14439: if (keys(%changes) > 0) {
14440: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 14441: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 14442: 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";
14443: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 14444: if ($item eq 'inststatus') {
14445: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 14446: if (@orderedstatus) {
1.236 raeburn 14447: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
14448: foreach my $type (@orderedstatus) {
14449: $resulttext .= $alltypes{$type}.', ';
14450: }
14451: $resulttext =~ s/, $//;
14452: $resulttext .= '</li>';
1.305 raeburn 14453: } else {
14454: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 14455: }
14456: }
14457: } else {
14458: my $value = $env{'form.'.$item};
14459: if ($value eq '') {
14460: $value = &mt('none');
14461: } elsif ($item eq 'auth_def') {
14462: my %authnames = &authtype_names();
14463: my %shortauth = (
14464: internal => 'int',
14465: krb4 => 'krb4',
14466: krb5 => 'krb5',
14467: localauth => 'loc',
1.325 raeburn 14468: lti => 'lti',
1.236 raeburn 14469: );
14470: $value = $authnames{$shortauth{$value}};
1.294 raeburn 14471: } elsif ($item eq 'intauth_switch') {
14472: my %optiondesc = &Apache::lonlocal::texthash (
14473: 0 => 'No',
14474: 1 => 'Yes',
14475: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
14476: );
14477: if ($value =~ /^(0|1|2)$/) {
14478: $value = $optiondesc{$value};
14479: } else {
14480: $value = &mt('none -- defaults to No');
14481: }
14482: } elsif ($item eq 'intauth_check') {
14483: my %optiondesc = &Apache::lonlocal::texthash (
14484: 0 => 'No',
14485: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
14486: 2 => 'Yes, disallow login if stored cost is less than domain default',
14487: );
14488: if ($value =~ /^(0|1|2)$/) {
14489: $value = $optiondesc{$value};
14490: } else {
14491: $value = &mt('none -- defaults to No');
14492: }
1.236 raeburn 14493: }
14494: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
14495: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 14496: }
14497: }
14498: $resulttext .= '</ul>';
14499: $mailmsgtext .= "\n";
14500: my $cachetime = 24*60*60;
1.72 raeburn 14501: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 14502: if (ref($lastactref) eq 'HASH') {
14503: $lastactref->{'domdefaults'} = 1;
14504: }
1.68 raeburn 14505: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 14506: my $notify = 1;
14507: if (ref($domconfig{'contacts'}) eq 'HASH') {
14508: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
14509: $notify = 0;
14510: }
14511: }
14512: if ($notify) {
14513: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
14514: "LON-CAPA Domain Settings Change - $dom",
14515: $mailmsgtext);
14516: }
1.54 raeburn 14517: }
1.43 raeburn 14518: } else {
1.54 raeburn 14519: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 14520: }
14521: } else {
14522: $resulttext = '<span class="LC_error">'.
14523: &mt('An error occurred: [_1]',$putresult).'</span>';
14524: }
14525: if (@errors > 0) {
14526: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
14527: foreach my $item (@errors) {
14528: $resulttext .= ' "'.$title->{$item}.'",';
14529: }
14530: $resulttext =~ s/,$//;
14531: }
14532: return $resulttext;
14533: }
14534:
1.46 raeburn 14535: sub modify_scantron {
1.205 raeburn 14536: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 14537: my ($resulttext,%confhash,%changes,$errors);
14538: my $custom = 'custom.tab';
14539: my $default = 'default.tab';
14540: my $servadm = $r->dir_config('lonAdmEMail');
14541: my ($configuserok,$author_ok,$switchserver) =
14542: &config_check($dom,$confname,$servadm);
14543: if ($env{'form.scantronformat.filename'} ne '') {
14544: my $error;
14545: if ($configuserok eq 'ok') {
14546: if ($switchserver) {
1.130 raeburn 14547: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 14548: } else {
14549: if ($author_ok eq 'ok') {
14550: my ($result,$scantronurl) =
14551: &publishlogo($r,'upload','scantronformat',$dom,
14552: $confname,'scantron','','',$custom);
14553: if ($result eq 'ok') {
14554: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 14555: $changes{'scantronformat'} = 1;
1.46 raeburn 14556: } else {
14557: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
14558: }
14559: } else {
14560: $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);
14561: }
14562: }
14563: } else {
14564: $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);
14565: }
14566: if ($error) {
14567: &Apache::lonnet::logthis($error);
14568: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14569: }
14570: }
1.48 raeburn 14571: if (ref($domconfig{'scantron'}) eq 'HASH') {
14572: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
14573: if ($env{'form.scantronformat_del'}) {
14574: $confhash{'scantron'}{'scantronformat'} = '';
14575: $changes{'scantronformat'} = 1;
1.46 raeburn 14576: }
14577: }
14578: }
14579: if (keys(%confhash) > 0) {
14580: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
14581: $dom);
14582: if ($putresult eq 'ok') {
14583: if (keys(%changes) > 0) {
1.48 raeburn 14584: if (ref($confhash{'scantron'}) eq 'HASH') {
14585: $resulttext = &mt('Changes made:').'<ul>';
14586: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 14587: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 14588: } else {
1.130 raeburn 14589: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 14590: }
1.48 raeburn 14591: $resulttext .= '</ul>';
14592: } else {
1.130 raeburn 14593: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 14594: }
14595: $resulttext .= '</ul>';
14596: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 14597: if (ref($lastactref) eq 'HASH') {
14598: $lastactref->{'domainconfig'} = 1;
14599: }
1.46 raeburn 14600: } else {
1.130 raeburn 14601: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 14602: }
14603: } else {
14604: $resulttext = '<span class="LC_error">'.
14605: &mt('An error occurred: [_1]',$putresult).'</span>';
14606: }
14607: } else {
1.130 raeburn 14608: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 14609: }
14610: if ($errors) {
14611: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14612: $errors.'</ul>';
14613: }
14614: return $resulttext;
14615: }
14616:
1.48 raeburn 14617: sub modify_coursecategories {
1.239 raeburn 14618: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 14619: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
14620: $cathash);
1.48 raeburn 14621: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 14622: my @catitems = ('unauth','auth');
14623: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 14624: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 14625: $cathash = $domconfig{'coursecategories'}{'cats'};
14626: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
14627: $changes{'togglecats'} = 1;
14628: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
14629: }
14630: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
14631: $changes{'categorize'} = 1;
14632: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
14633: }
1.120 raeburn 14634: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
14635: $changes{'togglecatscomm'} = 1;
14636: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
14637: }
14638: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
14639: $changes{'categorizecomm'} = 1;
14640: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 14641:
14642: }
14643: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
14644: $changes{'togglecatsplace'} = 1;
14645: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
14646: }
14647: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
14648: $changes{'categorizeplace'} = 1;
14649: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 14650: }
1.238 raeburn 14651: foreach my $item (@catitems) {
14652: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
14653: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
14654: $changes{$item} = 1;
14655: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
14656: }
14657: }
14658: }
1.57 raeburn 14659: } else {
14660: $changes{'togglecats'} = 1;
14661: $changes{'categorize'} = 1;
1.124 raeburn 14662: $changes{'togglecatscomm'} = 1;
14663: $changes{'categorizecomm'} = 1;
1.272 raeburn 14664: $changes{'togglecatsplace'} = 1;
14665: $changes{'categorizeplace'} = 1;
1.87 raeburn 14666: $domconfig{'coursecategories'} = {
14667: togglecats => $env{'form.togglecats'},
14668: categorize => $env{'form.categorize'},
1.124 raeburn 14669: togglecatscomm => $env{'form.togglecatscomm'},
14670: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 14671: togglecatsplace => $env{'form.togglecatsplace'},
14672: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 14673: };
1.238 raeburn 14674: foreach my $item (@catitems) {
14675: if ($env{'form.coursecat_'.$item} ne 'std') {
14676: $changes{$item} = 1;
14677: }
14678: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
14679: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
14680: }
14681: }
1.57 raeburn 14682: }
14683: if (ref($cathash) eq 'HASH') {
14684: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 14685: push (@deletecategory,'instcode::0');
14686: }
1.120 raeburn 14687: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
14688: push(@deletecategory,'communities::0');
14689: }
1.272 raeburn 14690: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
14691: push(@deletecategory,'placement::0');
14692: }
1.48 raeburn 14693: }
1.57 raeburn 14694: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
14695: if (ref($cathash) eq 'HASH') {
1.48 raeburn 14696: if (@deletecategory > 0) {
14697: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 14698: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 14699: foreach my $item (@deletecategory) {
1.57 raeburn 14700: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
14701: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 14702: $deletions{$item} = 1;
1.57 raeburn 14703: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 14704: }
14705: }
14706: }
1.57 raeburn 14707: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 14708: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 14709: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 14710: $reorderings{$item} = 1;
1.57 raeburn 14711: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 14712: }
14713: if ($env{'form.addcategory_name_'.$item} ne '') {
14714: my $newcat = $env{'form.addcategory_name_'.$item};
14715: my $newdepth = $depth+1;
14716: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 14717: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 14718: $adds{$newitem} = 1;
14719: }
14720: if ($env{'form.subcat_'.$item} ne '') {
14721: my $newcat = $env{'form.subcat_'.$item};
14722: my $newdepth = $depth+1;
14723: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 14724: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 14725: $adds{$newitem} = 1;
14726: }
14727: }
14728: }
14729: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 14730: if (ref($cathash) eq 'HASH') {
1.48 raeburn 14731: my $newitem = 'instcode::0';
1.57 raeburn 14732: if ($cathash->{$newitem} eq '') {
14733: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 14734: $adds{$newitem} = 1;
14735: }
14736: } else {
14737: my $newitem = 'instcode::0';
1.57 raeburn 14738: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 14739: $adds{$newitem} = 1;
14740: }
14741: }
1.120 raeburn 14742: if ($env{'form.communities'} eq '1') {
14743: if (ref($cathash) eq 'HASH') {
14744: my $newitem = 'communities::0';
14745: if ($cathash->{$newitem} eq '') {
14746: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
14747: $adds{$newitem} = 1;
14748: }
14749: } else {
14750: my $newitem = 'communities::0';
14751: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
14752: $adds{$newitem} = 1;
14753: }
14754: }
1.272 raeburn 14755: if ($env{'form.placement'} eq '1') {
14756: if (ref($cathash) eq 'HASH') {
14757: my $newitem = 'placement::0';
14758: if ($cathash->{$newitem} eq '') {
14759: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
14760: $adds{$newitem} = 1;
14761: }
14762: } else {
14763: my $newitem = 'placement::0';
14764: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
14765: $adds{$newitem} = 1;
14766: }
14767: }
1.48 raeburn 14768: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 14769: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 14770: ($env{'form.addcategory_name'} ne 'communities') &&
14771: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 14772: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
14773: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
14774: $adds{$newitem} = 1;
14775: }
1.48 raeburn 14776: }
1.57 raeburn 14777: my $putresult;
1.48 raeburn 14778: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14779: if (keys(%deletions) > 0) {
14780: foreach my $key (keys(%deletions)) {
14781: if ($predelallitems{$key} ne '') {
14782: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
14783: }
14784: }
14785: }
14786: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 14787: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 14788: if (ref($chkcats[0]) eq 'ARRAY') {
14789: my $depth = 0;
14790: my $chg = 0;
14791: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
14792: my $name = $chkcats[0][$i];
14793: my $item;
14794: if ($name eq '') {
14795: $chg ++;
14796: } else {
14797: $item = &escape($name).'::0';
14798: if ($chg) {
1.57 raeburn 14799: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 14800: }
14801: $depth ++;
1.57 raeburn 14802: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 14803: $depth --;
14804: }
14805: }
14806: }
1.57 raeburn 14807: }
14808: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14809: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 14810: if ($putresult eq 'ok') {
1.57 raeburn 14811: my %title = (
1.120 raeburn 14812: togglecats => 'Show/Hide a course in catalog',
14813: categorize => 'Assign a category to a course',
14814: togglecatscomm => 'Show/Hide a community in catalog',
14815: categorizecomm => 'Assign a category to a community',
1.57 raeburn 14816: );
14817: my %level = (
1.120 raeburn 14818: dom => 'set in Domain ("Modify Course/Community")',
14819: crs => 'set in Course ("Course Configuration")',
14820: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 14821: none => 'No catalog',
14822: std => 'Standard catalog',
14823: domonly => 'Domain-only catalog',
14824: codesrch => 'Code search form',
1.57 raeburn 14825: );
1.48 raeburn 14826: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 14827: if ($changes{'togglecats'}) {
14828: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
14829: }
14830: if ($changes{'categorize'}) {
14831: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 14832: }
1.120 raeburn 14833: if ($changes{'togglecatscomm'}) {
14834: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
14835: }
14836: if ($changes{'categorizecomm'}) {
14837: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
14838: }
1.238 raeburn 14839: if ($changes{'unauth'}) {
14840: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
14841: }
14842: if ($changes{'auth'}) {
14843: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
14844: }
1.57 raeburn 14845: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14846: my $cathash;
14847: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
14848: $cathash = $domconfig{'coursecategories'}{'cats'};
14849: } else {
14850: $cathash = {};
14851: }
14852: my (@cats,@trails,%allitems);
14853: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
14854: if (keys(%deletions) > 0) {
14855: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
14856: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
14857: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
14858: }
14859: $resulttext .= '</ul></li>';
14860: }
14861: if (keys(%reorderings) > 0) {
14862: my %sort_by_trail;
14863: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
14864: foreach my $key (keys(%reorderings)) {
14865: if ($allitems{$key} ne '') {
14866: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
14867: }
1.48 raeburn 14868: }
1.57 raeburn 14869: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
14870: $resulttext .= '<li>'.$trails[$trail].'</li>';
14871: }
14872: $resulttext .= '</ul></li>';
1.48 raeburn 14873: }
1.57 raeburn 14874: if (keys(%adds) > 0) {
14875: my %sort_by_trail;
14876: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
14877: foreach my $key (keys(%adds)) {
14878: if ($allitems{$key} ne '') {
14879: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
14880: }
14881: }
14882: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
14883: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 14884: }
1.57 raeburn 14885: $resulttext .= '</ul></li>';
1.48 raeburn 14886: }
14887: }
14888: $resulttext .= '</ul>';
1.239 raeburn 14889: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 14890: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
14891: if ($changes{'auth'}) {
14892: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
14893: }
14894: if ($changes{'unauth'}) {
14895: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
14896: }
14897: my $cachetime = 24*60*60;
14898: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 14899: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 14900: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 14901: }
14902: }
1.48 raeburn 14903: } else {
14904: $resulttext = '<span class="LC_error">'.
1.57 raeburn 14905: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 14906: }
14907: } else {
1.120 raeburn 14908: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 14909: }
14910: return $resulttext;
14911: }
14912:
1.69 raeburn 14913: sub modify_serverstatuses {
14914: my ($dom,%domconfig) = @_;
14915: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
14916: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
14917: %currserverstatus = %{$domconfig{'serverstatuses'}};
14918: }
14919: my @pages = &serverstatus_pages();
14920: foreach my $type (@pages) {
14921: $newserverstatus{$type}{'namedusers'} = '';
14922: $newserverstatus{$type}{'machines'} = '';
14923: if (defined($env{'form.'.$type.'_namedusers'})) {
14924: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
14925: my @okusers;
14926: foreach my $user (@users) {
14927: my ($uname,$udom) = split(/:/,$user);
14928: if (($udom =~ /^$match_domain$/) &&
14929: (&Apache::lonnet::domain($udom)) &&
14930: ($uname =~ /^$match_username$/)) {
14931: if (!grep(/^\Q$user\E/,@okusers)) {
14932: push(@okusers,$user);
14933: }
14934: }
14935: }
14936: if (@okusers > 0) {
14937: @okusers = sort(@okusers);
14938: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
14939: }
14940: }
14941: if (defined($env{'form.'.$type.'_machines'})) {
14942: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
14943: my @okmachines;
14944: foreach my $ip (@machines) {
14945: my @parts = split(/\./,$ip);
14946: next if (@parts < 4);
14947: my $badip = 0;
14948: for (my $i=0; $i<4; $i++) {
14949: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
14950: $badip = 1;
14951: last;
14952: }
14953: }
14954: if (!$badip) {
14955: push(@okmachines,$ip);
14956: }
14957: }
14958: @okmachines = sort(@okmachines);
14959: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
14960: }
14961: }
14962: my %serverstatushash = (
14963: serverstatuses => \%newserverstatus,
14964: );
14965: foreach my $type (@pages) {
1.83 raeburn 14966: foreach my $setting ('namedusers','machines') {
1.84 raeburn 14967: my (@current,@new);
1.83 raeburn 14968: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 14969: if ($currserverstatus{$type}{$setting} ne '') {
14970: @current = split(/,/,$currserverstatus{$type}{$setting});
14971: }
14972: }
14973: if ($newserverstatus{$type}{$setting} ne '') {
14974: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 14975: }
14976: if (@current > 0) {
14977: if (@new > 0) {
14978: foreach my $item (@current) {
14979: if (!grep(/^\Q$item\E$/,@new)) {
14980: $changes{$type}{$setting} = 1;
1.82 raeburn 14981: last;
14982: }
14983: }
1.84 raeburn 14984: foreach my $item (@new) {
14985: if (!grep(/^\Q$item\E$/,@current)) {
14986: $changes{$type}{$setting} = 1;
14987: last;
1.82 raeburn 14988: }
14989: }
14990: } else {
1.83 raeburn 14991: $changes{$type}{$setting} = 1;
1.69 raeburn 14992: }
1.83 raeburn 14993: } elsif (@new > 0) {
14994: $changes{$type}{$setting} = 1;
1.69 raeburn 14995: }
14996: }
14997: }
14998: if (keys(%changes) > 0) {
1.81 raeburn 14999: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 15000: my $putresult = &Apache::lonnet::put_dom('configuration',
15001: \%serverstatushash,$dom);
15002: if ($putresult eq 'ok') {
15003: $resulttext .= &mt('Changes made:').'<ul>';
15004: foreach my $type (@pages) {
1.84 raeburn 15005: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 15006: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 15007: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 15008: if ($newserverstatus{$type}{'namedusers'} eq '') {
15009: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
15010: } else {
15011: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
15012: }
1.84 raeburn 15013: }
15014: if ($changes{$type}{'machines'}) {
1.69 raeburn 15015: if ($newserverstatus{$type}{'machines'} eq '') {
15016: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
15017: } else {
15018: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
15019: }
15020:
15021: }
15022: $resulttext .= '</ul></li>';
15023: }
15024: }
15025: $resulttext .= '</ul>';
15026: } else {
15027: $resulttext = '<span class="LC_error">'.
15028: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
15029:
15030: }
15031: } else {
15032: $resulttext = &mt('No changes made to access to server status pages');
15033: }
15034: return $resulttext;
15035: }
15036:
1.118 jms 15037: sub modify_helpsettings {
1.285 raeburn 15038: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 15039: my ($resulttext,$errors,%changes,%helphash);
15040: my %defaultchecked = ('submitbugs' => 'on');
15041: my @offon = ('off','on');
1.118 jms 15042: my @toggles = ('submitbugs');
1.285 raeburn 15043: my %current = ('submitbugs' => '',
15044: 'adhoc' => {},
15045: );
1.118 jms 15046: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 15047: %current = %{$domconfig{'helpsettings'}};
15048: }
1.285 raeburn 15049: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 15050: foreach my $item (@toggles) {
15051: if ($defaultchecked{$item} eq 'on') {
15052: if ($current{$item} eq '') {
15053: if ($env{'form.'.$item} eq '0') {
15054: $changes{$item} = 1;
15055: }
15056: } elsif ($current{$item} ne $env{'form.'.$item}) {
15057: $changes{$item} = 1;
15058: }
15059: } elsif ($defaultchecked{$item} eq 'off') {
15060: if ($current{$item} eq '') {
15061: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 15062: $changes{$item} = 1;
15063: }
1.282 raeburn 15064: } elsif ($current{$item} ne $env{'form.'.$item}) {
15065: $changes{$item} = 1;
15066: }
15067: }
15068: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
15069: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
15070: }
15071: }
1.285 raeburn 15072: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 15073: my $confname = $dom.'-domainconfig';
15074: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 15075: my (@allpos,%newsettings,%changedprivs,$newrole);
15076: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 15077: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 15078: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 15079: my %lt = &Apache::lonlocal::texthash(
15080: s => 'system',
15081: d => 'domain',
15082: order => 'Display order',
15083: access => 'Role usage',
1.291 raeburn 15084: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 15085: dh => 'All with domain helpdesk role',
15086: da => 'All with domain helpdesk assistant role',
1.285 raeburn 15087: none => 'None',
15088: status => 'Determined based on institutional status',
15089: inc => 'Include all, but exclude specific personnel',
15090: exc => 'Exclude all, but include specific personnel',
15091: );
15092: for (my $num=0; $num<=$maxnum; $num++) {
15093: my ($prefix,$identifier,$rolename,%curr);
15094: if ($num == $maxnum) {
15095: next unless ($env{'form.newcusthelp'} == $maxnum);
15096: $identifier = 'custhelp'.$num;
15097: $prefix = 'helproles_'.$num;
15098: $rolename = $env{'form.custhelpname'.$num};
15099: $rolename=~s/[^A-Za-z0-9]//gs;
15100: next if ($rolename eq '');
15101: next if (exists($existing{'rolesdef_'.$rolename}));
15102: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15103: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15104: $newprivs{'c'},$confname,$dom);
15105: if ($result ne 'ok') {
15106: $errors .= '<li><span class="LC_error">'.
15107: &mt('An error occurred storing the new custom role: [_1]',
15108: $result).'</span></li>';
15109: next;
15110: } else {
15111: $changedprivs{$rolename} = \%newprivs;
15112: $newrole = $rolename;
15113: }
15114: } else {
15115: $prefix = 'helproles_'.$num;
15116: $rolename = $env{'form.'.$prefix};
15117: next if ($rolename eq '');
15118: next unless (exists($existing{'rolesdef_'.$rolename}));
15119: $identifier = 'custhelp'.$num;
15120: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15121: my %currprivs;
1.289 raeburn 15122: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 15123: split(/\_/,$existing{'rolesdef_'.$rolename});
15124: foreach my $level ('c','d','s') {
15125: if ($newprivs{$level} ne $currprivs{$level}) {
15126: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15127: $newprivs{'c'},$confname,$dom);
15128: if ($result ne 'ok') {
15129: $errors .= '<li><span class="LC_error">'.
15130: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
15131: $rolename,$result).'</span></li>';
15132: } else {
15133: $changedprivs{$rolename} = \%newprivs;
15134: }
15135: last;
15136: }
15137: }
15138: if (ref($current{'adhoc'}) eq 'HASH') {
15139: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15140: %curr = %{$current{'adhoc'}{$rolename}};
15141: }
15142: }
15143: }
15144: my $newpos = $env{'form.'.$prefix.'_pos'};
15145: $newpos =~ s/\D+//g;
15146: $allpos[$newpos] = $rolename;
15147: my $newdesc = $env{'form.'.$prefix.'_desc'};
15148: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
15149: if ($curr{'desc'}) {
15150: if ($curr{'desc'} ne $newdesc) {
15151: $changes{'customrole'}{$rolename}{'desc'} = 1;
15152: $newsettings{$rolename}{'desc'} = $newdesc;
15153: }
15154: } elsif ($newdesc ne '') {
15155: $changes{'customrole'}{$rolename}{'desc'} = 1;
15156: $newsettings{$rolename}{'desc'} = $newdesc;
15157: }
15158: my $access = $env{'form.'.$prefix.'_access'};
15159: if (grep(/^\Q$access\E$/,@accesstypes)) {
15160: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
15161: if ($access eq 'status') {
15162: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
15163: if (scalar(@statuses) == 0) {
1.289 raeburn 15164: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 15165: } else {
15166: my (@shownstatus,$numtypes);
15167: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15168: if (ref($types) eq 'ARRAY') {
15169: $numtypes = scalar(@{$types});
15170: foreach my $type (sort(@statuses)) {
15171: if ($type eq 'default') {
15172: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15173: } elsif (grep(/^\Q$type\E$/,@{$types})) {
15174: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15175: push(@shownstatus,$usertypes->{$type});
15176: }
15177: }
15178: }
15179: if (grep(/^default$/,@statuses)) {
15180: push(@shownstatus,$othertitle);
15181: }
15182: if (scalar(@shownstatus) == 1+$numtypes) {
15183: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
15184: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
15185: } else {
15186: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
15187: if (ref($curr{'status'}) eq 'ARRAY') {
15188: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15189: if (@diffs) {
15190: $changes{'customrole'}{$rolename}{$access} = 1;
15191: }
15192: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15193: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 15194: }
1.166 raeburn 15195: }
15196: }
1.285 raeburn 15197: } elsif (($access eq 'inc') || ($access eq 'exc')) {
15198: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
15199: my @newspecstaff;
15200: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15201: foreach my $person (sort(@personnel)) {
15202: if ($domhelpdesk{$person}) {
15203: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
15204: }
15205: }
15206: if (ref($curr{$access}) eq 'ARRAY') {
15207: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15208: if (@diffs) {
15209: $changes{'customrole'}{$rolename}{$access} = 1;
15210: }
15211: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15212: $changes{'customrole'}{$rolename}{$access} = 1;
15213: }
15214: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15215: my ($uname,$udom) = split(/:/,$person);
15216: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
15217: }
15218: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 15219: }
1.285 raeburn 15220: } else {
15221: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
15222: }
15223: unless ($curr{'access'} eq $access) {
15224: $changes{'customrole'}{$rolename}{'access'} = 1;
15225: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 15226: }
15227: }
1.285 raeburn 15228: if (@allpos > 0) {
15229: my $idx = 0;
15230: foreach my $rolename (@allpos) {
15231: if ($rolename ne '') {
15232: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
15233: if (ref($current{'adhoc'}) eq 'HASH') {
15234: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15235: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
15236: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 15237: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 15238: }
15239: }
1.282 raeburn 15240: }
1.285 raeburn 15241: $idx ++;
1.166 raeburn 15242: }
15243: }
1.118 jms 15244: }
1.123 jms 15245: my $putresult;
15246: if (keys(%changes) > 0) {
1.166 raeburn 15247: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 15248: if ($putresult eq 'ok') {
1.285 raeburn 15249: if (ref($helphash{'helpsettings'}) eq 'HASH') {
15250: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
15251: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
15252: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
15253: }
15254: }
15255: my $cachetime = 24*60*60;
15256: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15257: if (ref($lastactref) eq 'HASH') {
15258: $lastactref->{'domdefaults'} = 1;
15259: }
15260: } else {
15261: $errors .= '<li><span class="LC_error">'.
15262: &mt('An error occurred storing the settings: [_1]',
15263: $putresult).'</span></li>';
15264: }
15265: }
15266: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
15267: $resulttext = &mt('Changes made:').'<ul>';
15268: my (%shownprivs,@levelorder);
15269: @levelorder = ('c','d','s');
15270: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 15271: foreach my $item (sort(keys(%changes))) {
15272: if ($item eq 'submitbugs') {
15273: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
15274: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
15275: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 15276: } elsif ($item eq 'customrole') {
15277: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 15278: my @keyorder = ('order','desc','access','status','exc','inc');
15279: my %keytext = &Apache::lonlocal::texthash(
15280: order => 'Order',
15281: desc => 'Role description',
15282: access => 'Role usage',
1.300 droeschl 15283: status => 'Allowed institutional types',
1.285 raeburn 15284: exc => 'Allowed personnel',
15285: inc => 'Disallowed personnel',
15286: );
1.282 raeburn 15287: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 15288: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
15289: if ($role eq $newrole) {
15290: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
15291: $role).'<ul>';
15292: } else {
15293: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15294: $role).'<ul>';
15295: }
15296: foreach my $key (@keyorder) {
15297: if ($changes{'customrole'}{$role}{$key}) {
15298: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
15299: $keytext{$key},$newsettings{$role}{$key}).
15300: '</li>';
15301: }
15302: }
15303: if (ref($changedprivs{$role}) eq 'HASH') {
15304: $shownprivs{$role} = 1;
15305: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
15306: foreach my $level (@levelorder) {
15307: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
15308: next if ($item eq '');
15309: my ($priv) = split(/\&/,$item,2);
15310: if (&Apache::lonnet::plaintext($priv)) {
15311: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
15312: unless ($level eq 'c') {
15313: $resulttext .= ' ('.$lt{$level}.')';
15314: }
15315: $resulttext .= '</li>';
15316: }
15317: }
15318: }
15319: $resulttext .= '</ul>';
15320: }
15321: $resulttext .= '</ul></li>';
15322: }
15323: }
15324: }
15325: }
15326: }
15327: }
15328: if (keys(%changedprivs)) {
15329: foreach my $role (sort(keys(%changedprivs))) {
15330: unless ($shownprivs{$role}) {
15331: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15332: $role).'<ul>'.
15333: '<li>'.&mt('Privileges set to :').'<ul>';
15334: foreach my $level (@levelorder) {
15335: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
15336: next if ($item eq '');
15337: my ($priv) = split(/\&/,$item,2);
15338: if (&Apache::lonnet::plaintext($priv)) {
15339: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
15340: unless ($level eq 'c') {
15341: $resulttext .= ' ('.$lt{$level}.')';
15342: }
15343: $resulttext .= '</li>';
15344: }
1.282 raeburn 15345: }
15346: }
1.285 raeburn 15347: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 15348: }
15349: }
15350: }
1.285 raeburn 15351: $resulttext .= '</ul>';
15352: } else {
15353: $resulttext = &mt('No changes made to help settings');
1.118 jms 15354: }
15355: if ($errors) {
1.168 raeburn 15356: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 15357: $errors.'</ul>';
1.118 jms 15358: }
15359: return $resulttext;
15360: }
15361:
1.121 raeburn 15362: sub modify_coursedefaults {
1.212 raeburn 15363: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 15364: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 15365: my %defaultchecked = (
15366: 'canuse_pdfforms' => 'off',
15367: 'uselcmath' => 'on',
15368: 'usejsme' => 'on'
15369: );
15370: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 15371: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 15372: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
15373: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
15374: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 15375: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 15376: my %staticdefaults = (
15377: anonsurvey_threshold => 10,
15378: uploadquota => 500,
1.257 raeburn 15379: postsubmit => 60,
1.276 raeburn 15380: mysqltables => 172800,
1.198 raeburn 15381: );
1.314 raeburn 15382: my %texoptions = (
15383: MathJax => 'MathJax',
15384: mimetex => &mt('Convert to Images'),
15385: tth => &mt('TeX to HTML'),
15386: );
1.121 raeburn 15387: $defaultshash{'coursedefaults'} = {};
15388:
15389: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
15390: if ($domconfig{'coursedefaults'} eq '') {
15391: $domconfig{'coursedefaults'} = {};
15392: }
15393: }
15394:
15395: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
15396: foreach my $item (@toggles) {
15397: if ($defaultchecked{$item} eq 'on') {
15398: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15399: ($env{'form.'.$item} eq '0')) {
15400: $changes{$item} = 1;
1.192 raeburn 15401: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 15402: $changes{$item} = 1;
15403: }
15404: } elsif ($defaultchecked{$item} eq 'off') {
15405: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15406: ($env{'form.'.$item} eq '1')) {
15407: $changes{$item} = 1;
15408: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
15409: $changes{$item} = 1;
15410: }
15411: }
15412: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
15413: }
1.198 raeburn 15414: foreach my $item (@numbers) {
15415: my ($currdef,$newdef);
1.208 raeburn 15416: $newdef = $env{'form.'.$item};
1.198 raeburn 15417: if ($item eq 'anonsurvey_threshold') {
15418: $currdef = $domconfig{'coursedefaults'}{$item};
15419: $newdef =~ s/\D//g;
15420: if ($newdef eq '' || $newdef < 1) {
15421: $newdef = 1;
15422: }
15423: $defaultshash{'coursedefaults'}{$item} = $newdef;
15424: } else {
1.276 raeburn 15425: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
15426: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
15427: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 15428: }
15429: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 15430: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 15431: }
15432: if ($currdef ne $newdef) {
15433: my $staticdef;
15434: if ($item eq 'anonsurvey_threshold') {
15435: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
15436: $changes{$item} = 1;
15437: }
1.276 raeburn 15438: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 15439: my $setting = $1;
1.276 raeburn 15440: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
15441: $changes{$setting} = 1;
1.198 raeburn 15442: }
15443: }
1.139 raeburn 15444: }
15445: }
1.314 raeburn 15446: my $texengine;
15447: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
15448: $texengine = $env{'form.texengine'};
15449: if ($defaultshash{'coursedefaults'}{'texengine'} eq '') {
15450: unless ($texengine eq 'MathJax') {
15451: $changes{'texengine'} = 1;
15452: }
15453: } elsif ($defaultshash{'coursedefaults'}{'texengine'} ne $texengine) {
15454: $changes{'texengine'} = 1;
15455: }
15456: }
15457: if ($texengine ne '') {
15458: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
15459: }
1.264 raeburn 15460: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
15461: my @currclonecode;
15462: if (ref($currclone) eq 'HASH') {
15463: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
15464: @currclonecode = @{$currclone->{'instcode'}};
15465: }
15466: }
15467: my $newclone;
1.289 raeburn 15468: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 15469: $newclone = $env{'form.canclone'};
15470: }
15471: if ($newclone eq 'instcode') {
15472: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
15473: my (%codedefaults,@code_order,@clonecode);
15474: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
15475: \@code_order);
15476: foreach my $item (@code_order) {
15477: if (grep(/^\Q$item\E$/,@newcodes)) {
15478: push(@clonecode,$item);
15479: }
15480: }
15481: if (@clonecode) {
15482: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
15483: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
15484: if (@diffs) {
15485: $changes{'canclone'} = 1;
15486: }
15487: } else {
15488: $newclone eq '';
15489: }
15490: } elsif ($newclone ne '') {
1.289 raeburn 15491: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
15492: }
1.264 raeburn 15493: if ($newclone ne $currclone) {
15494: $changes{'canclone'} = 1;
15495: }
1.257 raeburn 15496: my %credits;
15497: foreach my $type (@types) {
15498: unless ($type eq 'community') {
15499: $credits{$type} = $env{'form.'.$type.'_credits'};
15500: $credits{$type} =~ s/[^\d.]+//g;
15501: }
15502: }
15503: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
15504: ($env{'form.coursecredits'} eq '1')) {
15505: $changes{'coursecredits'} = 1;
15506: foreach my $type (keys(%credits)) {
15507: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15508: }
15509: } else {
1.289 raeburn 15510: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 15511: foreach my $type (@types) {
15512: unless ($type eq 'community') {
1.289 raeburn 15513: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 15514: $changes{'coursecredits'} = 1;
15515: }
15516: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15517: }
15518: }
15519: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15520: foreach my $type (@types) {
15521: unless ($type eq 'community') {
15522: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
15523: $changes{'coursecredits'} = 1;
15524: last;
15525: }
15526: }
15527: }
15528: }
15529: }
15530: if ($env{'form.postsubmit'} eq '1') {
15531: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
15532: my %currtimeout;
15533: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15534: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
15535: $changes{'postsubmit'} = 1;
15536: }
15537: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15538: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
15539: }
15540: } else {
15541: $changes{'postsubmit'} = 1;
15542: }
15543: foreach my $type (@types) {
15544: my $timeout = $env{'form.'.$type.'_timeout'};
15545: $timeout =~ s/\D//g;
15546: if ($timeout == $staticdefaults{'postsubmit'}) {
15547: $timeout = '';
15548: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
15549: $timeout = '0';
15550: }
15551: unless ($timeout eq '') {
15552: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
15553: }
15554: if (exists($currtimeout{$type})) {
15555: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 15556: $changes{'postsubmit'} = 1;
1.257 raeburn 15557: }
15558: } elsif ($timeout ne '') {
15559: $changes{'postsubmit'} = 1;
15560: }
15561: }
15562: } else {
15563: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
15564: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15565: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
15566: $changes{'postsubmit'} = 1;
15567: }
15568: } else {
15569: $changes{'postsubmit'} = 1;
15570: }
1.192 raeburn 15571: }
1.121 raeburn 15572: }
15573: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
15574: $dom);
15575: if ($putresult eq 'ok') {
15576: if (keys(%changes) > 0) {
1.213 raeburn 15577: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 15578: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 15579: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.314 raeburn 15580: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
15581: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','texengine') {
1.257 raeburn 15582: if ($changes{$item}) {
15583: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
15584: }
1.289 raeburn 15585: }
1.192 raeburn 15586: if ($changes{'coursecredits'}) {
15587: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 15588: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
15589: $domdefaults{$type.'credits'} =
15590: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
15591: }
15592: }
15593: }
15594: if ($changes{'postsubmit'}) {
15595: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15596: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
15597: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15598: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
15599: $domdefaults{$type.'postsubtimeout'} =
15600: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15601: }
15602: }
1.192 raeburn 15603: }
15604: }
1.198 raeburn 15605: if ($changes{'uploadquota'}) {
15606: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15607: foreach my $type (@types) {
15608: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
15609: }
15610: }
15611: }
1.264 raeburn 15612: if ($changes{'canclone'}) {
15613: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15614: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15615: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
15616: if (@clonecodes) {
15617: $domdefaults{'canclone'} = join('+',@clonecodes);
15618: }
15619: }
15620: } else {
15621: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
15622: }
15623: }
1.121 raeburn 15624: my $cachetime = 24*60*60;
15625: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 15626: if (ref($lastactref) eq 'HASH') {
15627: $lastactref->{'domdefaults'} = 1;
15628: }
1.121 raeburn 15629: }
15630: $resulttext = &mt('Changes made:').'<ul>';
15631: foreach my $item (sort(keys(%changes))) {
15632: if ($item eq 'canuse_pdfforms') {
15633: if ($env{'form.'.$item} eq '1') {
15634: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
15635: } else {
15636: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
15637: }
1.257 raeburn 15638: } elsif ($item eq 'uselcmath') {
15639: if ($env{'form.'.$item} eq '1') {
15640: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
15641: } else {
15642: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
15643: }
15644: } elsif ($item eq 'usejsme') {
15645: if ($env{'form.'.$item} eq '1') {
15646: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
15647: } else {
1.289 raeburn 15648: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 15649: }
1.314 raeburn 15650: } elsif ($item eq 'texengine') {
15651: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
15652: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
15653: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
15654: }
1.139 raeburn 15655: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 15656: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 15657: } elsif ($item eq 'uploadquota') {
15658: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15659: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
15660: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
15661: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 15662: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 15663: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 15664: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
15665: '</ul>'.
15666: '</li>';
15667: } else {
15668: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
15669: }
1.276 raeburn 15670: } elsif ($item eq 'mysqltables') {
15671: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
15672: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
15673: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
15674: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
15675: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
15676: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
15677: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
15678: '</ul>'.
15679: '</li>';
15680: } else {
15681: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
15682: }
1.257 raeburn 15683: } elsif ($item eq 'postsubmit') {
15684: if ($domdefaults{'postsubmit'} eq 'off') {
15685: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
15686: } else {
15687: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 15688: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 15689: $resulttext .= &mt('durations:').'<ul>';
15690: foreach my $type (@types) {
15691: $resulttext .= '<li>';
15692: my $timeout;
15693: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15694: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15695: }
15696: my $display;
15697: if ($timeout eq '0') {
15698: $display = &mt('unlimited');
15699: } elsif ($timeout eq '') {
15700: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
15701: } else {
15702: $display = &mt('[quant,_1,second]',$timeout);
15703: }
15704: if ($type eq 'community') {
15705: $resulttext .= &mt('Communities');
15706: } elsif ($type eq 'official') {
15707: $resulttext .= &mt('Official courses');
15708: } elsif ($type eq 'unofficial') {
15709: $resulttext .= &mt('Unofficial courses');
15710: } elsif ($type eq 'textbook') {
15711: $resulttext .= &mt('Textbook courses');
1.271 raeburn 15712: } elsif ($type eq 'placement') {
15713: $resulttext .= &mt('Placement tests');
1.257 raeburn 15714: }
15715: $resulttext .= ' -- '.$display.'</li>';
15716: }
15717: $resulttext .= '</ul>';
15718: }
1.289 raeburn 15719: $resulttext .= '</li>';
1.257 raeburn 15720: }
1.192 raeburn 15721: } elsif ($item eq 'coursecredits') {
15722: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15723: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 15724: ($domdefaults{'unofficialcredits'} eq '') &&
15725: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 15726: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
15727: } else {
15728: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
15729: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
15730: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 15731: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 15732: '</ul>'.
15733: '</li>';
15734: }
15735: } else {
15736: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
15737: }
1.264 raeburn 15738: } elsif ($item eq 'canclone') {
15739: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15740: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15741: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
15742: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
15743: }
15744: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
15745: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
15746: } else {
1.289 raeburn 15747: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 15748: }
1.140 raeburn 15749: }
1.121 raeburn 15750: }
15751: $resulttext .= '</ul>';
15752: } else {
15753: $resulttext = &mt('No changes made to course defaults');
15754: }
15755: } else {
15756: $resulttext = '<span class="LC_error">'.
15757: &mt('An error occurred: [_1]',$putresult).'</span>';
15758: }
15759: return $resulttext;
15760: }
15761:
1.231 raeburn 15762: sub modify_selfenrollment {
15763: my ($dom,$lastactref,%domconfig) = @_;
15764: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 15765: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 15766: my %titles = &tool_titles();
1.232 raeburn 15767: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
15768: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 15769: $ordered{'default'} = ['types','registered','approval','limit'];
15770:
15771: my (%roles,%shown,%toplevel);
15772: $roles{'0'} = &Apache::lonnet::plaintext('dc');
15773:
15774: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
15775: if ($domconfig{'selfenrollment'} eq '') {
15776: $domconfig{'selfenrollment'} = {};
15777: }
15778: }
15779: %toplevel = (
15780: admin => 'Configuration Rights',
15781: default => 'Default settings',
15782: validation => 'Validation of self-enrollment requests',
15783: );
1.233 raeburn 15784: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 15785:
15786: if (ref($ordered{'admin'}) eq 'ARRAY') {
15787: foreach my $item (@{$ordered{'admin'}}) {
15788: foreach my $type (@types) {
15789: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
15790: $selfenrollhash{'admin'}{$type}{$item} = 1;
15791: } else {
15792: $selfenrollhash{'admin'}{$type}{$item} = 0;
15793: }
15794: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
15795: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
15796: if ($selfenrollhash{'admin'}{$type}{$item} ne
15797: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
15798: push(@{$changes{'admin'}{$type}},$item);
15799: }
15800: } else {
15801: if (!$selfenrollhash{'admin'}{$type}{$item}) {
15802: push(@{$changes{'admin'}{$type}},$item);
15803: }
15804: }
15805: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
15806: push(@{$changes{'admin'}{$type}},$item);
15807: }
15808: }
15809: }
15810: }
15811:
15812: foreach my $item (@{$ordered{'default'}}) {
15813: foreach my $type (@types) {
15814: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
15815: if ($item eq 'types') {
15816: unless (($value eq 'all') || ($value eq 'dom')) {
15817: $value = '';
15818: }
15819: } elsif ($item eq 'registered') {
15820: unless ($value eq '1') {
15821: $value = 0;
15822: }
15823: } elsif ($item eq 'approval') {
15824: unless ($value =~ /^[012]$/) {
15825: $value = 0;
15826: }
15827: } else {
15828: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
15829: $value = 'none';
15830: }
15831: }
15832: $selfenrollhash{'default'}{$type}{$item} = $value;
15833: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
15834: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
15835: if ($selfenrollhash{'default'}{$type}{$item} ne
15836: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
15837: push(@{$changes{'default'}{$type}},$item);
15838: }
15839: } else {
15840: push(@{$changes{'default'}{$type}},$item);
15841: }
15842: } else {
15843: push(@{$changes{'default'}{$type}},$item);
15844: }
15845: if ($item eq 'limit') {
15846: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
15847: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
15848: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
15849: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
15850: }
15851: } else {
15852: $selfenrollhash{'default'}{$type}{'cap'} = '';
15853: }
15854: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
15855: if ($selfenrollhash{'default'}{$type}{'cap'} ne
15856: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
15857: push(@{$changes{'default'}{$type}},'cap');
15858: }
15859: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
15860: push(@{$changes{'default'}{$type}},'cap');
15861: }
15862: }
15863: }
15864: }
15865:
15866: foreach my $item (@{$itemsref}) {
15867: if ($item eq 'fields') {
15868: my @changed;
15869: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
15870: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
15871: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
15872: }
15873: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
15874: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
15875: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
15876: $domconfig{'selfenrollment'}{'validation'}{$item});
15877: } else {
15878: @changed = @{$selfenrollhash{'validation'}{$item}};
15879: }
15880: } else {
15881: @changed = @{$selfenrollhash{'validation'}{$item}};
15882: }
15883: if (@changed) {
15884: if ($selfenrollhash{'validation'}{$item}) {
15885: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
15886: } else {
15887: $changes{'validation'}{$item} = &mt('None');
15888: }
15889: }
15890: } else {
15891: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
15892: if ($item eq 'markup') {
15893: if ($env{'form.selfenroll_validation_'.$item}) {
15894: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
15895: }
15896: }
15897: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
15898: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
15899: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
15900: }
15901: }
15902: }
15903: }
15904:
15905: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
15906: $dom);
15907: if ($putresult eq 'ok') {
15908: if (keys(%changes) > 0) {
15909: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15910: $resulttext = &mt('Changes made:').'<ul>';
15911: foreach my $key ('admin','default','validation') {
15912: if (ref($changes{$key}) eq 'HASH') {
15913: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
15914: if ($key eq 'validation') {
15915: foreach my $item (@{$itemsref}) {
15916: if (exists($changes{$key}{$item})) {
15917: if ($item eq 'markup') {
15918: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
15919: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
15920: } else {
15921: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
15922: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
15923: }
15924: }
15925: }
15926: } else {
15927: foreach my $type (@types) {
15928: if ($type eq 'community') {
15929: $roles{'1'} = &mt('Community personnel');
15930: } else {
15931: $roles{'1'} = &mt('Course personnel');
15932: }
15933: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 15934: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
15935: if ($key eq 'admin') {
15936: my @mgrdc = ();
15937: if (ref($ordered{$key}) eq 'ARRAY') {
15938: foreach my $item (@{$ordered{'admin'}}) {
15939: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
15940: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
15941: push(@mgrdc,$item);
15942: }
15943: }
15944: }
15945: if (@mgrdc) {
15946: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
15947: } else {
15948: delete($domdefaults{$type.'selfenrolladmdc'});
15949: }
15950: }
15951: } else {
15952: if (ref($ordered{$key}) eq 'ARRAY') {
15953: foreach my $item (@{$ordered{$key}}) {
15954: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
15955: $domdefaults{$type.'selfenroll'.$item} =
15956: $selfenrollhash{$key}{$type}{$item};
15957: }
15958: }
15959: }
15960: }
15961: }
1.231 raeburn 15962: $resulttext .= '<li>'.$titles{$type}.'<ul>';
15963: foreach my $item (@{$ordered{$key}}) {
15964: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
15965: $resulttext .= '<li>';
15966: if ($key eq 'admin') {
15967: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
15968: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
15969: } else {
15970: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
15971: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
15972: }
15973: $resulttext .= '</li>';
15974: }
15975: }
15976: $resulttext .= '</ul></li>';
15977: }
15978: }
15979: $resulttext .= '</ul></li>';
15980: }
15981: }
1.305 raeburn 15982: }
15983: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
15984: my $cachetime = 24*60*60;
15985: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15986: if (ref($lastactref) eq 'HASH') {
15987: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 15988: }
1.231 raeburn 15989: }
15990: $resulttext .= '</ul>';
15991: } else {
15992: $resulttext = &mt('No changes made to self-enrollment settings');
15993: }
15994: } else {
15995: $resulttext = '<span class="LC_error">'.
15996: &mt('An error occurred: [_1]',$putresult).'</span>';
15997: }
15998: return $resulttext;
15999: }
16000:
1.137 raeburn 16001: sub modify_usersessions {
1.212 raeburn 16002: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 16003: my @hostingtypes = ('version','excludedomain','includedomain');
16004: my @offloadtypes = ('primary','default');
16005: my %types = (
16006: remote => \@hostingtypes,
16007: hosted => \@hostingtypes,
16008: spares => \@offloadtypes,
16009: );
16010: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 16011: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 16012: my (%by_ip,%by_location,@intdoms,@instdoms);
16013: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 16014: my @locations = sort(keys(%by_location));
1.137 raeburn 16015: my (%defaultshash,%changes);
16016: foreach my $prefix (@prefixes) {
16017: $defaultshash{'usersessions'}{$prefix} = {};
16018: }
1.212 raeburn 16019: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 16020: my $resulttext;
1.138 raeburn 16021: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 16022: foreach my $prefix (@prefixes) {
1.145 raeburn 16023: next if ($prefix eq 'spares');
16024: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 16025: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16026: if ($type eq 'version') {
16027: my $value = $env{'form.'.$prefix.'_'.$type};
16028: my $okvalue;
16029: if ($value ne '') {
16030: if (grep(/^\Q$value\E$/,@lcversions)) {
16031: $okvalue = $value;
16032: }
16033: }
16034: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16035: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
16036: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
16037: if ($inuse == 0) {
16038: $changes{$prefix}{$type} = 1;
16039: } else {
16040: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
16041: $changes{$prefix}{$type} = 1;
16042: }
16043: if ($okvalue ne '') {
16044: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16045: }
16046: }
16047: } else {
16048: if (($inuse == 1) && ($okvalue ne '')) {
16049: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16050: $changes{$prefix}{$type} = 1;
16051: }
16052: }
16053: } else {
16054: if (($inuse == 1) && ($okvalue ne '')) {
16055: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16056: $changes{$prefix}{$type} = 1;
16057: }
16058: }
16059: } else {
16060: if (($inuse == 1) && ($okvalue ne '')) {
16061: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16062: $changes{$prefix}{$type} = 1;
16063: }
16064: }
16065: } else {
16066: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16067: my @okvals;
16068: foreach my $val (@vals) {
1.138 raeburn 16069: if ($val =~ /:/) {
16070: my @items = split(/:/,$val);
16071: foreach my $item (@items) {
16072: if (ref($by_location{$item}) eq 'ARRAY') {
16073: push(@okvals,$item);
16074: }
16075: }
16076: } else {
16077: if (ref($by_location{$val}) eq 'ARRAY') {
16078: push(@okvals,$val);
16079: }
1.137 raeburn 16080: }
16081: }
16082: @okvals = sort(@okvals);
16083: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16084: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
16085: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
16086: if ($inuse == 0) {
16087: $changes{$prefix}{$type} = 1;
16088: } else {
16089: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16090: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
16091: if (@changed > 0) {
16092: $changes{$prefix}{$type} = 1;
16093: }
16094: }
16095: } else {
16096: if ($inuse == 1) {
16097: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16098: $changes{$prefix}{$type} = 1;
16099: }
16100: }
16101: } else {
16102: if ($inuse == 1) {
16103: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16104: $changes{$prefix}{$type} = 1;
16105: }
16106: }
16107: } else {
16108: if ($inuse == 1) {
16109: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16110: $changes{$prefix}{$type} = 1;
16111: }
16112: }
16113: }
16114: }
16115: }
1.145 raeburn 16116:
16117: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 16118: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 16119: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
16120: my $savespares;
16121:
16122: foreach my $lonhost (sort(keys(%servers))) {
16123: my $serverhomeID =
16124: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 16125: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 16126: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
16127: my %spareschg;
16128: foreach my $type (@{$types{'spares'}}) {
16129: my @okspares;
16130: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
16131: foreach my $server (@checked) {
1.152 raeburn 16132: if (&Apache::lonnet::hostname($server) ne '') {
16133: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
16134: unless (grep(/^\Q$server\E$/,@okspares)) {
16135: push(@okspares,$server);
16136: }
1.145 raeburn 16137: }
16138: }
16139: }
16140: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
16141: my $newspare;
1.152 raeburn 16142: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
16143: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 16144: $newspare = $new;
16145: }
16146: }
1.152 raeburn 16147: my @spares;
16148: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
16149: @spares = sort(@okspares,$newspare);
16150: } else {
16151: @spares = sort(@okspares);
16152: }
16153: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 16154: if (ref($spareid{$lonhost}) eq 'HASH') {
16155: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 16156: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 16157: if (@diffs > 0) {
16158: $spareschg{$type} = 1;
16159: }
16160: }
16161: }
16162: }
16163: if (keys(%spareschg) > 0) {
16164: $changes{'spares'}{$lonhost} = \%spareschg;
16165: }
16166: }
1.261 raeburn 16167: $defaultshash{'usersessions'}{'offloadnow'} = {};
16168: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
16169: my @okoffload;
16170: if (@offloadnow) {
16171: foreach my $server (@offloadnow) {
16172: if (&Apache::lonnet::hostname($server) ne '') {
16173: unless (grep(/^\Q$server\E$/,@okoffload)) {
16174: push(@okoffload,$server);
16175: }
16176: }
16177: }
16178: if (@okoffload) {
16179: foreach my $lonhost (@okoffload) {
16180: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
16181: }
16182: }
16183: }
1.145 raeburn 16184: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16185: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
16186: if (ref($changes{'spares'}) eq 'HASH') {
16187: if (keys(%{$changes{'spares'}}) > 0) {
16188: $savespares = 1;
16189: }
16190: }
16191: } else {
16192: $savespares = 1;
16193: }
1.261 raeburn 16194: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
16195: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
16196: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
16197: $changes{'offloadnow'} = 1;
16198: last;
16199: }
16200: }
16201: unless ($changes{'offloadnow'}) {
1.289 raeburn 16202: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
1.261 raeburn 16203: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
16204: $changes{'offloadnow'} = 1;
16205: last;
16206: }
16207: }
16208: }
16209: } elsif (@okoffload) {
16210: $changes{'offloadnow'} = 1;
16211: }
16212: } elsif (@okoffload) {
16213: $changes{'offloadnow'} = 1;
1.145 raeburn 16214: }
1.147 raeburn 16215: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
16216: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 16217: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16218: $dom);
16219: if ($putresult eq 'ok') {
16220: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
16221: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
16222: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
16223: }
16224: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
16225: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
16226: }
1.261 raeburn 16227: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
16228: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
16229: }
1.137 raeburn 16230: }
16231: my $cachetime = 24*60*60;
16232: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 16233: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 16234: if (ref($lastactref) eq 'HASH') {
16235: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 16236: $lastactref->{'usersessions'} = 1;
1.212 raeburn 16237: }
1.147 raeburn 16238: if (keys(%changes) > 0) {
16239: my %lt = &usersession_titles();
16240: $resulttext = &mt('Changes made:').'<ul>';
16241: foreach my $prefix (@prefixes) {
16242: if (ref($changes{$prefix}) eq 'HASH') {
16243: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
16244: if ($prefix eq 'spares') {
16245: if (ref($changes{$prefix}) eq 'HASH') {
16246: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
16247: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 16248: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 16249: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
16250: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 16251: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
16252: foreach my $type (@{$types{$prefix}}) {
16253: if ($changes{$prefix}{$lonhost}{$type}) {
16254: my $offloadto = &mt('None');
16255: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
16256: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
16257: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
16258: }
1.145 raeburn 16259: }
1.147 raeburn 16260: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 16261: }
1.137 raeburn 16262: }
16263: }
1.147 raeburn 16264: $resulttext .= '</li>';
1.137 raeburn 16265: }
16266: }
1.147 raeburn 16267: } else {
16268: foreach my $type (@{$types{$prefix}}) {
16269: if (defined($changes{$prefix}{$type})) {
16270: my $newvalue;
16271: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
16272: if (ref($defaultshash{'usersessions'}{$prefix})) {
16273: if ($type eq 'version') {
16274: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
16275: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
16276: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
16277: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
16278: }
1.145 raeburn 16279: }
16280: }
16281: }
1.147 raeburn 16282: if ($newvalue eq '') {
16283: if ($type eq 'version') {
16284: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
16285: } else {
16286: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
16287: }
1.145 raeburn 16288: } else {
1.147 raeburn 16289: if ($type eq 'version') {
16290: $newvalue .= ' '.&mt('(or later)');
16291: }
16292: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 16293: }
1.137 raeburn 16294: }
16295: }
16296: }
1.147 raeburn 16297: $resulttext .= '</ul>';
1.137 raeburn 16298: }
16299: }
1.261 raeburn 16300: if ($changes{'offloadnow'}) {
16301: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
16302: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
16303: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
16304: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
16305: $resulttext .= '<li>'.$lonhost.'</li>';
16306: }
16307: $resulttext .= '</ul>';
16308: } else {
16309: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
16310: }
16311: } else {
16312: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
16313: }
16314: }
1.147 raeburn 16315: $resulttext .= '</ul>';
16316: } else {
16317: $resulttext = $nochgmsg;
1.137 raeburn 16318: }
16319: } else {
16320: $resulttext = '<span class="LC_error">'.
16321: &mt('An error occurred: [_1]',$putresult).'</span>';
16322: }
16323: } else {
1.147 raeburn 16324: $resulttext = $nochgmsg;
1.137 raeburn 16325: }
16326: return $resulttext;
16327: }
16328:
1.275 raeburn 16329: sub modify_ssl {
16330: my ($dom,$lastactref,%domconfig) = @_;
16331: my (%by_ip,%by_location,@intdoms,@instdoms);
16332: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
16333: my @locations = sort(keys(%by_location));
16334: my %servers = &Apache::lonnet::internet_dom_servers($dom);
16335: my (%defaultshash,%changes);
16336: my $action = 'ssl';
1.293 raeburn 16337: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 16338: foreach my $prefix (@prefixes) {
16339: $defaultshash{$action}{$prefix} = {};
16340: }
16341: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16342: my $resulttext;
16343: my %iphost = &Apache::lonnet::get_iphost();
16344: my @reptypes = ('certreq','nocertreq');
16345: my @connecttypes = ('dom','intdom','other');
16346: my %types = (
1.293 raeburn 16347: connto => \@connecttypes,
16348: connfrom => \@connecttypes,
16349: replication => \@reptypes,
1.275 raeburn 16350: );
16351: foreach my $prefix (sort(keys(%types))) {
16352: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 16353: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 16354: my $value = 'yes';
16355: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
16356: $value = $env{'form.'.$prefix.'_'.$type};
16357: }
16358: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
16359: if ($domconfig{$action}{$prefix}{$type} ne '') {
16360: if ($value ne $domconfig{$action}{$prefix}{$type}) {
16361: $changes{$prefix}{$type} = 1;
16362: }
16363: $defaultshash{$action}{$prefix}{$type} = $value;
16364: } else {
16365: $defaultshash{$action}{$prefix}{$type} = $value;
16366: $changes{$prefix}{$type} = 1;
16367: }
16368: } else {
16369: $defaultshash{$action}{$prefix}{$type} = $value;
16370: $changes{$prefix}{$type} = 1;
16371: }
16372: if (($type eq 'dom') && (keys(%servers) == 1)) {
16373: delete($changes{$prefix}{$type});
16374: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
16375: delete($changes{$prefix}{$type});
16376: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
16377: delete($changes{$prefix}{$type});
16378: }
16379: } elsif ($prefix eq 'replication') {
16380: if (@locations > 0) {
16381: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16382: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16383: my @okvals;
16384: foreach my $val (@vals) {
16385: if ($val =~ /:/) {
16386: my @items = split(/:/,$val);
16387: foreach my $item (@items) {
16388: if (ref($by_location{$item}) eq 'ARRAY') {
16389: push(@okvals,$item);
16390: }
16391: }
16392: } else {
16393: if (ref($by_location{$val}) eq 'ARRAY') {
16394: push(@okvals,$val);
16395: }
16396: }
16397: }
16398: @okvals = sort(@okvals);
16399: if (ref($domconfig{$action}) eq 'HASH') {
16400: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
16401: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
16402: if ($inuse == 0) {
16403: $changes{$prefix}{$type} = 1;
16404: } else {
16405: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16406: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
16407: if (@changed > 0) {
16408: $changes{$prefix}{$type} = 1;
16409: }
16410: }
16411: } else {
16412: if ($inuse == 1) {
16413: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16414: $changes{$prefix}{$type} = 1;
16415: }
16416: }
16417: } else {
16418: if ($inuse == 1) {
16419: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16420: $changes{$prefix}{$type} = 1;
16421: }
16422: }
16423: } else {
16424: if ($inuse == 1) {
16425: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16426: $changes{$prefix}{$type} = 1;
16427: }
16428: }
16429: }
16430: }
16431: }
16432: }
16433: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
16434: if (keys(%changes) > 0) {
16435: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16436: $dom);
16437: if ($putresult eq 'ok') {
16438: if (ref($defaultshash{$action}) eq 'HASH') {
16439: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
16440: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
16441: }
1.293 raeburn 16442: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
16443: $domdefaults{'connto'} = $domconfig{$action}{'connto'};
16444: }
16445: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
16446: $domdefaults{'connfrom'} = $domconfig{$action}{'connfrom'};
1.275 raeburn 16447: }
16448: }
16449: my $cachetime = 24*60*60;
16450: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16451: if (ref($lastactref) eq 'HASH') {
16452: $lastactref->{'domdefaults'} = 1;
16453: }
16454: if (keys(%changes) > 0) {
16455: my %titles = &ssl_titles();
16456: $resulttext = &mt('Changes made:').'<ul>';
16457: foreach my $prefix (@prefixes) {
16458: if (ref($changes{$prefix}) eq 'HASH') {
16459: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
16460: foreach my $type (@{$types{$prefix}}) {
16461: if (defined($changes{$prefix}{$type})) {
16462: my $newvalue;
16463: if (ref($defaultshash{$action}) eq 'HASH') {
16464: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 16465: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 16466: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
16467: } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
16468: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
16469: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
16470: }
16471: }
16472: }
16473: if ($newvalue eq '') {
16474: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
16475: } else {
16476: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
16477: }
16478: }
16479: }
16480: }
16481: $resulttext .= '</ul>';
16482: }
16483: }
16484: } else {
16485: $resulttext = $nochgmsg;
16486: }
16487: } else {
16488: $resulttext = '<span class="LC_error">'.
16489: &mt('An error occurred: [_1]',$putresult).'</span>';
16490: }
16491: } else {
16492: $resulttext = $nochgmsg;
16493: }
16494: return $resulttext;
16495: }
16496:
1.279 raeburn 16497: sub modify_trust {
16498: my ($dom,$lastactref,%domconfig) = @_;
16499: my (%by_ip,%by_location,@intdoms,@instdoms);
16500: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
16501: my @locations = sort(keys(%by_location));
16502: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
16503: my @types = ('exc','inc');
16504: my (%defaultshash,%changes);
16505: foreach my $prefix (@prefixes) {
16506: $defaultshash{'trust'}{$prefix} = {};
16507: }
16508: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16509: my $resulttext;
16510: foreach my $prefix (@prefixes) {
16511: foreach my $type (@types) {
16512: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16513: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16514: my @okvals;
16515: foreach my $val (@vals) {
16516: if ($val =~ /:/) {
16517: my @items = split(/:/,$val);
16518: foreach my $item (@items) {
16519: if (ref($by_location{$item}) eq 'ARRAY') {
16520: push(@okvals,$item);
16521: }
16522: }
16523: } else {
16524: if (ref($by_location{$val}) eq 'ARRAY') {
16525: push(@okvals,$val);
16526: }
16527: }
16528: }
16529: @okvals = sort(@okvals);
16530: if (ref($domconfig{'trust'}) eq 'HASH') {
16531: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
16532: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
16533: if ($inuse == 0) {
16534: $changes{$prefix}{$type} = 1;
16535: } else {
16536: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16537: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
16538: if (@changed > 0) {
16539: $changes{$prefix}{$type} = 1;
16540: }
16541: }
16542: } else {
16543: if ($inuse == 1) {
16544: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16545: $changes{$prefix}{$type} = 1;
16546: }
16547: }
16548: } else {
16549: if ($inuse == 1) {
16550: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16551: $changes{$prefix}{$type} = 1;
16552: }
16553: }
16554: } else {
16555: if ($inuse == 1) {
16556: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16557: $changes{$prefix}{$type} = 1;
16558: }
16559: }
16560: }
16561: }
16562: my $nochgmsg = &mt('No changes made to trust settings.');
16563: if (keys(%changes) > 0) {
16564: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16565: $dom);
16566: if ($putresult eq 'ok') {
16567: if (ref($defaultshash{'trust'}) eq 'HASH') {
16568: foreach my $prefix (@prefixes) {
16569: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
16570: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
16571: }
16572: }
16573: }
16574: my $cachetime = 24*60*60;
16575: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16576: if (ref($lastactref) eq 'HASH') {
16577: $lastactref->{'domdefaults'} = 1;
16578: }
16579: if (keys(%changes) > 0) {
16580: my %lt = &trust_titles();
16581: $resulttext = &mt('Changes made:').'<ul>';
16582: foreach my $prefix (@prefixes) {
16583: if (ref($changes{$prefix}) eq 'HASH') {
16584: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
16585: foreach my $type (@types) {
16586: if (defined($changes{$prefix}{$type})) {
16587: my $newvalue;
16588: if (ref($defaultshash{'trust'}) eq 'HASH') {
16589: if (ref($defaultshash{'trust'}{$prefix})) {
16590: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
16591: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
16592: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
16593: }
16594: }
16595: }
16596: }
16597: if ($newvalue eq '') {
16598: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
16599: } else {
16600: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
16601: }
16602: }
16603: }
16604: $resulttext .= '</ul>';
16605: }
16606: }
16607: $resulttext .= '</ul>';
16608: } else {
16609: $resulttext = $nochgmsg;
16610: }
16611: } else {
16612: $resulttext = '<span class="LC_error">'.
16613: &mt('An error occurred: [_1]',$putresult).'</span>';
16614: }
16615: } else {
16616: $resulttext = $nochgmsg;
16617: }
16618: return $resulttext;
16619: }
16620:
1.150 raeburn 16621: sub modify_loadbalancing {
16622: my ($dom,%domconfig) = @_;
16623: my $primary_id = &Apache::lonnet::domain($dom,'primary');
16624: my $intdom = &Apache::lonnet::internet_dom($primary_id);
16625: my ($othertitle,$usertypes,$types) =
16626: &Apache::loncommon::sorted_inst_types($dom);
16627: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 16628: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 16629: my @sparestypes = ('primary','default');
16630: my %typetitles = &sparestype_titles();
16631: my $resulttext;
1.171 raeburn 16632: my (%currbalancer,%currtargets,%currrules,%existing);
16633: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
16634: %existing = %{$domconfig{'loadbalancing'}};
16635: }
16636: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
16637: \%currtargets,\%currrules);
16638: my ($saveloadbalancing,%defaultshash,%changes);
16639: my ($alltypes,$othertypes,$titles) =
16640: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
16641: my %ruletitles = &offloadtype_text();
16642: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
16643: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
16644: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
16645: if ($balancer eq '') {
16646: next;
16647: }
1.210 raeburn 16648: if (!exists($servers{$balancer})) {
1.171 raeburn 16649: if (exists($currbalancer{$balancer})) {
16650: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 16651: }
1.171 raeburn 16652: next;
16653: }
16654: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
16655: push(@{$changes{'delete'}},$balancer);
16656: next;
16657: }
16658: if (!exists($currbalancer{$balancer})) {
16659: push(@{$changes{'add'}},$balancer);
16660: }
16661: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
16662: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
16663: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
16664: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
16665: $saveloadbalancing = 1;
16666: }
16667: foreach my $sparetype (@sparestypes) {
16668: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
16669: my @offloadto;
16670: foreach my $target (@targets) {
16671: if (($servers{$target}) && ($target ne $balancer)) {
16672: if ($sparetype eq 'default') {
16673: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
16674: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 16675: }
16676: }
1.171 raeburn 16677: unless(grep(/^\Q$target\E$/,@offloadto)) {
16678: push(@offloadto,$target);
16679: }
1.150 raeburn 16680: }
16681: }
1.284 raeburn 16682: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
16683: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
16684: push(@offloadto,$balancer);
16685: }
16686: }
16687: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 16688: }
1.171 raeburn 16689: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 16690: foreach my $sparetype (@sparestypes) {
1.171 raeburn 16691: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
16692: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 16693: if (@targetdiffs > 0) {
1.171 raeburn 16694: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 16695: }
1.171 raeburn 16696: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16697: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16698: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 16699: }
16700: }
16701: }
16702: } else {
1.171 raeburn 16703: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 16704: foreach my $sparetype (@sparestypes) {
1.171 raeburn 16705: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16706: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16707: $changes{'curr'}{$balancer}{'targets'} = 1;
16708: }
1.150 raeburn 16709: }
16710: }
1.210 raeburn 16711: }
1.150 raeburn 16712: }
16713: my $ishomedom;
1.171 raeburn 16714: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
16715: $ishomedom = 1;
1.150 raeburn 16716: }
16717: if (ref($alltypes) eq 'ARRAY') {
16718: foreach my $type (@{$alltypes}) {
16719: my $rule;
1.210 raeburn 16720: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 16721: (!$ishomedom)) {
1.171 raeburn 16722: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
16723: }
16724: if ($rule eq 'specific') {
1.255 raeburn 16725: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 16726: if (exists($servers{$specifiedhost})) {
1.255 raeburn 16727: $rule = $specifiedhost;
16728: }
1.150 raeburn 16729: }
1.171 raeburn 16730: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
16731: if (ref($currrules{$balancer}) eq 'HASH') {
16732: if ($rule ne $currrules{$balancer}{$type}) {
16733: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 16734: }
16735: } elsif ($rule ne '') {
1.171 raeburn 16736: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 16737: }
16738: }
16739: }
1.171 raeburn 16740: }
16741: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
16742: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
16743: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
16744: $defaultshash{'loadbalancing'} = {};
16745: }
16746: my $putresult = &Apache::lonnet::put_dom('configuration',
16747: \%defaultshash,$dom);
16748: if ($putresult eq 'ok') {
16749: if (keys(%changes) > 0) {
1.252 raeburn 16750: my %toupdate;
1.171 raeburn 16751: if (ref($changes{'delete'}) eq 'ARRAY') {
16752: foreach my $balancer (sort(@{$changes{'delete'}})) {
16753: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 16754: $toupdate{$balancer} = 1;
1.150 raeburn 16755: }
1.171 raeburn 16756: }
16757: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 16758: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 16759: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 16760: $toupdate{$balancer} = 1;
1.171 raeburn 16761: }
16762: }
16763: if (ref($changes{'curr'}) eq 'HASH') {
16764: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 16765: $toupdate{$balancer} = 1;
1.171 raeburn 16766: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
16767: if ($changes{'curr'}{$balancer}{'targets'}) {
16768: my %offloadstr;
16769: foreach my $sparetype (@sparestypes) {
16770: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16771: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16772: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
16773: }
16774: }
1.150 raeburn 16775: }
1.171 raeburn 16776: if (keys(%offloadstr) == 0) {
16777: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 16778: } else {
1.171 raeburn 16779: my $showoffload;
16780: foreach my $sparetype (@sparestypes) {
16781: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
16782: if (defined($offloadstr{$sparetype})) {
16783: $showoffload .= $offloadstr{$sparetype};
16784: } else {
16785: $showoffload .= &mt('None');
16786: }
16787: $showoffload .= (' 'x3);
16788: }
16789: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 16790: }
16791: }
16792: }
1.171 raeburn 16793: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
16794: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
16795: foreach my $type (@{$alltypes}) {
16796: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
16797: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
16798: my $balancetext;
16799: if ($rule eq '') {
16800: $balancetext = $ruletitles{'default'};
1.209 raeburn 16801: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 16802: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 16803: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 16804: foreach my $sparetype (@sparestypes) {
16805: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16806: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
16807: }
16808: }
1.253 raeburn 16809: foreach my $item (@{$alltypes}) {
16810: next if ($item =~ /^_LC_ipchange/);
16811: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
16812: if ($hasrule eq 'homeserver') {
16813: map { $toupdate{$_} = 1; } (keys(%libraryservers));
16814: } else {
16815: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
16816: if ($servers{$hasrule}) {
16817: $toupdate{$hasrule} = 1;
16818: }
16819: }
16820: }
16821: }
1.254 raeburn 16822: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
16823: $balancetext = $ruletitles{$rule};
16824: } else {
16825: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
16826: $balancetext = $ruletitles{'particular'}.' '.$receiver;
16827: if ($receiver) {
16828: $toupdate{$receiver};
16829: }
16830: }
16831: } else {
16832: $balancetext = $ruletitles{$rule};
1.252 raeburn 16833: }
1.171 raeburn 16834: } else {
16835: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
16836: }
1.210 raeburn 16837: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 16838: }
16839: }
16840: }
16841: }
1.252 raeburn 16842: if (keys(%toupdate)) {
16843: my %thismachine;
16844: my $updatedhere;
16845: my $cachetime = 60*60*24;
16846: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
16847: foreach my $lonhost (keys(%toupdate)) {
16848: if ($thismachine{$lonhost}) {
16849: unless ($updatedhere) {
16850: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
16851: $defaultshash{'loadbalancing'},
16852: $cachetime);
16853: $updatedhere = 1;
16854: }
16855: } else {
16856: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
16857: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
16858: }
16859: }
16860: }
1.150 raeburn 16861: }
1.171 raeburn 16862: }
16863: if ($resulttext ne '') {
16864: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 16865: } else {
16866: $resulttext = $nochgmsg;
16867: }
16868: } else {
1.171 raeburn 16869: $resulttext = $nochgmsg;
1.150 raeburn 16870: }
16871: } else {
1.171 raeburn 16872: $resulttext = '<span class="LC_error">'.
16873: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 16874: }
16875: } else {
1.171 raeburn 16876: $resulttext = $nochgmsg;
1.150 raeburn 16877: }
16878: return $resulttext;
16879: }
16880:
1.48 raeburn 16881: sub recurse_check {
16882: my ($chkcats,$categories,$depth,$name) = @_;
16883: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
16884: my $chg = 0;
16885: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
16886: my $category = $chkcats->[$depth]{$name}[$j];
16887: my $item;
16888: if ($category eq '') {
16889: $chg ++;
16890: } else {
16891: my $deeper = $depth + 1;
16892: $item = &escape($category).':'.&escape($name).':'.$depth;
16893: if ($chg) {
16894: $categories->{$item} -= $chg;
16895: }
16896: &recurse_check($chkcats,$categories,$deeper,$category);
16897: $deeper --;
16898: }
16899: }
16900: }
16901: return;
16902: }
16903:
16904: sub recurse_cat_deletes {
16905: my ($item,$coursecategories,$deletions) = @_;
16906: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
16907: my $subdepth = $depth + 1;
16908: if (ref($coursecategories) eq 'HASH') {
16909: foreach my $subitem (keys(%{$coursecategories})) {
16910: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
16911: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
16912: delete($coursecategories->{$subitem});
16913: $deletions->{$subitem} = 1;
16914: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 16915: }
1.48 raeburn 16916: }
16917: }
16918: return;
16919: }
16920:
1.125 raeburn 16921: sub active_dc_picker {
1.191 raeburn 16922: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 16923: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 16924: my @domcoord = keys(%domcoords);
16925: if (keys(%currhash)) {
16926: foreach my $dc (keys(%currhash)) {
16927: unless (exists($domcoords{$dc})) {
16928: push(@domcoord,$dc);
16929: }
16930: }
16931: }
16932: @domcoord = sort(@domcoord);
1.210 raeburn 16933: my $numdcs = scalar(@domcoord);
1.191 raeburn 16934: my $rows = 0;
16935: my $table;
1.125 raeburn 16936: if ($numdcs > 1) {
1.191 raeburn 16937: $table = '<table>';
16938: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 16939: my $rem = $i%($numinrow);
16940: if ($rem == 0) {
16941: if ($i > 0) {
1.191 raeburn 16942: $table .= '</tr>';
1.125 raeburn 16943: }
1.191 raeburn 16944: $table .= '<tr>';
16945: $rows ++;
1.125 raeburn 16946: }
1.191 raeburn 16947: my $check = '';
16948: if ($inputtype eq 'radio') {
16949: if (keys(%currhash) == 0) {
16950: if (!$i) {
16951: $check = ' checked="checked"';
16952: }
16953: } elsif (exists($currhash{$domcoord[$i]})) {
16954: $check = ' checked="checked"';
16955: }
16956: } else {
16957: if (exists($currhash{$domcoord[$i]})) {
16958: $check = ' checked="checked"';
1.125 raeburn 16959: }
16960: }
1.191 raeburn 16961: if ($i == @domcoord - 1) {
1.125 raeburn 16962: my $colsleft = $numinrow - $rem;
16963: if ($colsleft > 1) {
1.191 raeburn 16964: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 16965: } else {
1.191 raeburn 16966: $table .= '<td class="LC_left_item">';
1.125 raeburn 16967: }
16968: } else {
1.191 raeburn 16969: $table .= '<td class="LC_left_item">';
16970: }
16971: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
16972: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
16973: $table .= '<span class="LC_nobreak"><label>'.
16974: '<input type="'.$inputtype.'" name="'.$name.'"'.
16975: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
16976: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 16977: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 16978: }
1.219 raeburn 16979: $table .= '</label></span></td>';
1.191 raeburn 16980: }
16981: $table .= '</tr></table>';
16982: } elsif ($numdcs == 1) {
1.219 raeburn 16983: my ($dcname,$dcdom) = split(':',$domcoord[0]);
16984: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 16985: if ($inputtype eq 'radio') {
1.247 raeburn 16986: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 16987: if ($user ne $dcname.':'.$dcdom) {
16988: $table .= ' ('.$dcname.':'.$dcdom.')';
16989: }
1.191 raeburn 16990: } else {
16991: my $check;
16992: if (exists($currhash{$domcoord[0]})) {
16993: $check = ' checked="checked"';
1.125 raeburn 16994: }
1.247 raeburn 16995: $table = '<span class="LC_nobreak"><label>'.
16996: '<input type="checkbox" name="'.$name.'" '.
16997: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 16998: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 16999: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 17000: }
1.220 raeburn 17001: $table .= '</label></span>';
1.191 raeburn 17002: $rows ++;
1.125 raeburn 17003: }
17004: }
1.191 raeburn 17005: return ($numdcs,$table,$rows);
1.125 raeburn 17006: }
17007:
1.137 raeburn 17008: sub usersession_titles {
17009: return &Apache::lonlocal::texthash(
17010: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
17011: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 17012: spares => 'Servers offloaded to, when busy',
1.137 raeburn 17013: version => 'LON-CAPA version requirement',
1.138 raeburn 17014: excludedomain => 'Allow all, but exclude specific domains',
17015: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 17016: primary => 'Primary (checked first)',
1.154 raeburn 17017: default => 'Default',
1.137 raeburn 17018: );
17019: }
17020:
1.152 raeburn 17021: sub id_for_thisdom {
17022: my (%servers) = @_;
17023: my %altids;
17024: foreach my $server (keys(%servers)) {
17025: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
17026: if ($serverhome ne $server) {
17027: $altids{$serverhome} = $server;
17028: }
17029: }
17030: return %altids;
17031: }
17032:
1.150 raeburn 17033: sub count_servers {
17034: my ($currbalancer,%servers) = @_;
17035: my (@spares,$numspares);
17036: foreach my $lonhost (sort(keys(%servers))) {
17037: next if ($currbalancer eq $lonhost);
17038: push(@spares,$lonhost);
17039: }
17040: if ($currbalancer) {
17041: $numspares = scalar(@spares);
17042: } else {
17043: $numspares = scalar(@spares) - 1;
17044: }
17045: return ($numspares,@spares);
17046: }
17047:
17048: sub lonbalance_targets_js {
1.171 raeburn 17049: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 17050: my $select = &mt('Select');
17051: my ($alltargets,$allishome,$allinsttypes,@alltypes);
17052: if (ref($servers) eq 'HASH') {
17053: $alltargets = join("','",sort(keys(%{$servers})));
17054: my @homedoms;
17055: foreach my $server (sort(keys(%{$servers}))) {
17056: if (&Apache::lonnet::host_domain($server) eq $dom) {
17057: push(@homedoms,'1');
17058: } else {
17059: push(@homedoms,'0');
17060: }
17061: }
17062: $allishome = join("','",@homedoms);
17063: }
17064: if (ref($types) eq 'ARRAY') {
17065: if (@{$types} > 0) {
17066: @alltypes = @{$types};
17067: }
17068: }
17069: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
17070: $allinsttypes = join("','",@alltypes);
1.171 raeburn 17071: my (%currbalancer,%currtargets,%currrules,%existing);
17072: if (ref($settings) eq 'HASH') {
17073: %existing = %{$settings};
17074: }
17075: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
17076: \%currtargets,\%currrules);
1.210 raeburn 17077: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 17078: return <<"END";
17079:
17080: <script type="text/javascript">
17081: // <![CDATA[
17082:
1.171 raeburn 17083: currBalancers = new Array('$balancers');
17084:
17085: function toggleTargets(balnum) {
17086: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
17087: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
17088: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
17089: var prevbalancer = prevhostitem.value;
17090: var baltotal = document.getElementById('loadbalancing_total').value;
17091: prevhostitem.value = balancer;
17092: if (prevbalancer != '') {
17093: var prevIdx = currBalancers.indexOf(prevbalancer);
17094: if (prevIdx != -1) {
17095: currBalancers.splice(prevIdx,1);
17096: }
17097: }
1.150 raeburn 17098: if (balancer == '') {
1.171 raeburn 17099: hideSpares(balnum);
1.150 raeburn 17100: } else {
1.171 raeburn 17101: var currIdx = currBalancers.indexOf(balancer);
17102: if (currIdx == -1) {
17103: currBalancers.push(balancer);
17104: }
1.150 raeburn 17105: var homedoms = new Array('$allishome');
1.171 raeburn 17106: var ishomedom = homedoms[lonhostitem.selectedIndex];
17107: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 17108: }
1.171 raeburn 17109: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 17110: return;
17111: }
17112:
1.171 raeburn 17113: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 17114: var alltargets = new Array('$alltargets');
17115: var insttypes = new Array('$allinsttypes');
1.151 raeburn 17116: var offloadtypes = new Array('primary','default');
17117:
1.171 raeburn 17118: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
17119: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 17120:
1.151 raeburn 17121: for (var i=0; i<offloadtypes.length; i++) {
17122: var count = 0;
17123: for (var j=0; j<alltargets.length; j++) {
17124: if (alltargets[j] != balancer) {
1.171 raeburn 17125: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
17126: item.value = alltargets[j];
17127: item.style.textAlign='left';
17128: item.style.textFace='normal';
17129: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
17130: if (currBalancers.indexOf(alltargets[j]) == -1) {
17131: item.disabled = '';
17132: } else {
17133: item.disabled = 'disabled';
17134: item.checked = false;
17135: }
1.151 raeburn 17136: count ++;
17137: }
1.150 raeburn 17138: }
17139: }
1.151 raeburn 17140: for (var k=0; k<insttypes.length; k++) {
17141: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 17142: if (ishomedom == 1) {
1.171 raeburn 17143: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
17144: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 17145: } else {
1.171 raeburn 17146: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
17147: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 17148: }
17149: } else {
1.171 raeburn 17150: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
17151: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 17152: }
1.151 raeburn 17153: if ((insttypes[k] != '_LC_external') &&
17154: ((insttypes[k] != '_LC_internetdom') ||
17155: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 17156: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
17157: item.options.length = 0;
17158: item.options[0] = new Option("","",true,true);
1.210 raeburn 17159: var idx = 0;
1.151 raeburn 17160: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 17161: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
17162: idx ++;
17163: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 17164: }
17165: }
17166: }
17167: }
17168: return;
17169: }
17170:
1.171 raeburn 17171: function hideSpares(balnum) {
1.150 raeburn 17172: var alltargets = new Array('$alltargets');
17173: var insttypes = new Array('$allinsttypes');
17174: var offloadtypes = new Array('primary','default');
17175:
1.171 raeburn 17176: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
17177: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 17178:
17179: var total = alltargets.length - 1;
17180: for (var i=0; i<offloadtypes; i++) {
17181: for (var j=0; j<total; j++) {
1.171 raeburn 17182: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
17183: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
17184: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 17185: }
1.150 raeburn 17186: }
17187: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 17188: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
17189: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 17190: if (insttypes[k] != '_LC_external') {
1.171 raeburn 17191: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
17192: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 17193: }
17194: }
17195: return;
17196: }
17197:
1.171 raeburn 17198: function checkOffloads(item,balnum,type) {
1.150 raeburn 17199: var alltargets = new Array('$alltargets');
17200: var offloadtypes = new Array('primary','default');
17201: if (item.checked) {
17202: var total = alltargets.length - 1;
17203: var other;
17204: if (type == offloadtypes[0]) {
1.151 raeburn 17205: other = offloadtypes[1];
1.150 raeburn 17206: } else {
1.151 raeburn 17207: other = offloadtypes[0];
1.150 raeburn 17208: }
17209: for (var i=0; i<total; i++) {
1.171 raeburn 17210: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 17211: if (server == item.value) {
1.171 raeburn 17212: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
17213: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 17214: }
17215: }
17216: }
17217: }
17218: return;
17219: }
17220:
1.171 raeburn 17221: function singleServerToggle(balnum,type) {
17222: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 17223: if (offloadtoSelIdx == 0) {
1.171 raeburn 17224: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
17225: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 17226:
17227: } else {
1.171 raeburn 17228: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
17229: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 17230: }
17231: return;
17232: }
17233:
1.171 raeburn 17234: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 17235: if (type == '_LC_external') {
1.171 raeburn 17236: return;
1.150 raeburn 17237: }
1.171 raeburn 17238: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 17239: for (var i=0; i<typesRules.length; i++) {
17240: if (formname.elements[typesRules[i]].checked) {
17241: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 17242: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
17243: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 17244: } else {
1.171 raeburn 17245: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
17246: }
17247: }
17248: }
17249: return;
17250: }
17251:
17252: function balancerDeleteChange(balnum) {
17253: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
17254: var baltotal = document.getElementById('loadbalancing_total').value;
17255: var addtarget;
17256: var removetarget;
17257: var action = 'delete';
17258: if (document.getElementById('loadbalancing_delete_'+balnum)) {
17259: var lonhost = hostitem.value;
17260: var currIdx = currBalancers.indexOf(lonhost);
17261: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
17262: if (currIdx != -1) {
17263: currBalancers.splice(currIdx,1);
17264: }
17265: addtarget = lonhost;
17266: } else {
17267: if (currIdx == -1) {
17268: currBalancers.push(lonhost);
17269: }
17270: removetarget = lonhost;
17271: action = 'undelete';
17272: }
17273: balancerChange(balnum,baltotal,action,addtarget,removetarget);
17274: }
17275: return;
17276: }
17277:
17278: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
17279: if (baltotal > 1) {
17280: var offloadtypes = new Array('primary','default');
17281: var alltargets = new Array('$alltargets');
17282: var insttypes = new Array('$allinsttypes');
17283: for (var i=0; i<baltotal; i++) {
17284: if (i != balnum) {
17285: for (var j=0; j<offloadtypes.length; j++) {
17286: var total = alltargets.length - 1;
17287: for (var k=0; k<total; k++) {
17288: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
17289: var server = serveritem.value;
17290: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
17291: if (server == addtarget) {
17292: serveritem.disabled = '';
17293: }
17294: }
17295: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
17296: if (server == removetarget) {
17297: serveritem.disabled = 'disabled';
17298: serveritem.checked = false;
17299: }
17300: }
17301: }
17302: }
17303: for (var j=0; j<insttypes.length; j++) {
17304: if (insttypes[j] != '_LC_external') {
17305: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
17306: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
17307: var currSel = singleserver.selectedIndex;
17308: var currVal = singleserver.options[currSel].value;
17309: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
17310: var numoptions = singleserver.options.length;
17311: var needsnew = 1;
17312: for (var k=0; k<numoptions; k++) {
17313: if (singleserver.options[k] == addtarget) {
17314: needsnew = 0;
17315: break;
17316: }
17317: }
17318: if (needsnew == 1) {
17319: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
17320: }
17321: }
17322: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
17323: singleserver.options.length = 0;
17324: if ((currVal) && (currVal != removetarget)) {
17325: singleserver.options[0] = new Option("","",false,false);
17326: } else {
17327: singleserver.options[0] = new Option("","",true,true);
17328: }
17329: var idx = 0;
17330: for (var m=0; m<alltargets.length; m++) {
17331: if (currBalancers.indexOf(alltargets[m]) == -1) {
17332: idx ++;
17333: if (currVal == alltargets[m]) {
17334: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
17335: } else {
17336: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
17337: }
17338: }
17339: }
17340: }
17341: }
17342: }
17343: }
1.150 raeburn 17344: }
17345: }
17346: }
17347: return;
17348: }
17349:
1.152 raeburn 17350: // ]]>
17351: </script>
17352:
17353: END
17354: }
17355:
17356: sub new_spares_js {
17357: my @sparestypes = ('primary','default');
17358: my $types = join("','",@sparestypes);
17359: my $select = &mt('Select');
17360: return <<"END";
17361:
17362: <script type="text/javascript">
17363: // <![CDATA[
17364:
17365: function updateNewSpares(formname,lonhost) {
17366: var types = new Array('$types');
17367: var include = new Array();
17368: var exclude = new Array();
17369: for (var i=0; i<types.length; i++) {
17370: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
17371: for (var j=0; j<spareboxes.length; j++) {
17372: if (formname.elements[spareboxes[j]].checked) {
17373: exclude.push(formname.elements[spareboxes[j]].value);
17374: } else {
17375: include.push(formname.elements[spareboxes[j]].value);
17376: }
17377: }
17378: }
17379: for (var i=0; i<types.length; i++) {
17380: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
17381: var selIdx = newSpare.selectedIndex;
17382: var currnew = newSpare.options[selIdx].value;
17383: var okSpares = new Array();
17384: for (var j=0; j<newSpare.options.length; j++) {
17385: var possible = newSpare.options[j].value;
17386: if (possible != '') {
17387: if (exclude.indexOf(possible) == -1) {
17388: okSpares.push(possible);
17389: } else {
17390: if (currnew == possible) {
17391: selIdx = 0;
17392: }
17393: }
17394: }
17395: }
17396: for (var k=0; k<include.length; k++) {
17397: if (okSpares.indexOf(include[k]) == -1) {
17398: okSpares.push(include[k]);
17399: }
17400: }
17401: okSpares.sort();
17402: newSpare.options.length = 0;
17403: if (selIdx == 0) {
17404: newSpare.options[0] = new Option("$select","",true,true);
17405: } else {
17406: newSpare.options[0] = new Option("$select","",false,false);
17407: }
17408: for (var m=0; m<okSpares.length; m++) {
17409: var idx = m+1;
17410: var selThis = 0;
17411: if (selIdx != 0) {
17412: if (okSpares[m] == currnew) {
17413: selThis = 1;
17414: }
17415: }
17416: if (selThis == 1) {
17417: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
17418: } else {
17419: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
17420: }
17421: }
17422: }
17423: return;
17424: }
17425:
17426: function checkNewSpares(lonhost,type) {
17427: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
17428: var chosen = newSpare.options[newSpare.selectedIndex].value;
17429: if (chosen != '') {
17430: var othertype;
17431: var othernewSpare;
17432: if (type == 'primary') {
17433: othernewSpare = document.getElementById('newspare_default_'+lonhost);
17434: }
17435: if (type == 'default') {
17436: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
17437: }
17438: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
17439: othernewSpare.selectedIndex = 0;
17440: }
17441: }
17442: return;
17443: }
17444:
17445: // ]]>
17446: </script>
17447:
17448: END
17449:
17450: }
17451:
17452: sub common_domprefs_js {
17453: return <<"END";
17454:
17455: <script type="text/javascript">
17456: // <![CDATA[
17457:
1.150 raeburn 17458: function getIndicesByName(formname,item) {
1.152 raeburn 17459: var group = new Array();
1.150 raeburn 17460: for (var i=0;i<formname.elements.length;i++) {
17461: if (formname.elements[i].name == item) {
1.152 raeburn 17462: group.push(formname.elements[i].id);
1.150 raeburn 17463: }
17464: }
1.152 raeburn 17465: return group;
1.150 raeburn 17466: }
17467:
17468: // ]]>
17469: </script>
17470:
17471: END
1.152 raeburn 17472:
1.150 raeburn 17473: }
17474:
1.165 raeburn 17475: sub recaptcha_js {
17476: my %lt = &captcha_phrases();
17477: return <<"END";
17478:
17479: <script type="text/javascript">
17480: // <![CDATA[
17481:
17482: function updateCaptcha(caller,context) {
17483: var privitem;
17484: var pubitem;
17485: var privtext;
17486: var pubtext;
1.269 raeburn 17487: var versionitem;
17488: var versiontext;
1.165 raeburn 17489: if (document.getElementById(context+'_recaptchapub')) {
17490: pubitem = document.getElementById(context+'_recaptchapub');
17491: } else {
17492: return;
17493: }
17494: if (document.getElementById(context+'_recaptchapriv')) {
17495: privitem = document.getElementById(context+'_recaptchapriv');
17496: } else {
17497: return;
17498: }
17499: if (document.getElementById(context+'_recaptchapubtxt')) {
17500: pubtext = document.getElementById(context+'_recaptchapubtxt');
17501: } else {
17502: return;
17503: }
17504: if (document.getElementById(context+'_recaptchaprivtxt')) {
17505: privtext = document.getElementById(context+'_recaptchaprivtxt');
17506: } else {
17507: return;
17508: }
1.269 raeburn 17509: if (document.getElementById(context+'_recaptchaversion')) {
17510: versionitem = document.getElementById(context+'_recaptchaversion');
17511: } else {
17512: return;
17513: }
17514: if (document.getElementById(context+'_recaptchavertxt')) {
17515: versiontext = document.getElementById(context+'_recaptchavertxt');
17516: } else {
17517: return;
17518: }
1.165 raeburn 17519: if (caller.checked) {
17520: if (caller.value == 'recaptcha') {
17521: pubitem.type = 'text';
17522: privitem.type = 'text';
17523: pubitem.size = '40';
17524: privitem.size = '40';
17525: pubtext.innerHTML = "$lt{'pub'}";
17526: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 17527: versionitem.type = 'text';
17528: versionitem.size = '3';
1.289 raeburn 17529: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 17530: } else {
17531: pubitem.type = 'hidden';
17532: privitem.type = 'hidden';
1.269 raeburn 17533: versionitem.type = 'hidden';
1.165 raeburn 17534: pubtext.innerHTML = '';
17535: privtext.innerHTML = '';
1.269 raeburn 17536: versiontext.innerHTML = '';
1.165 raeburn 17537: }
17538: }
17539: return;
17540: }
17541:
17542: // ]]>
17543: </script>
17544:
17545: END
17546:
17547: }
17548:
1.236 raeburn 17549: sub toggle_display_js {
1.192 raeburn 17550: return <<"END";
17551:
17552: <script type="text/javascript">
17553: // <![CDATA[
17554:
1.236 raeburn 17555: function toggleDisplay(domForm,caller) {
17556: if (document.getElementById(caller)) {
17557: var divitem = document.getElementById(caller);
17558: var optionsElement = domForm.coursecredits;
1.264 raeburn 17559: var checkval = 1;
17560: var dispval = 'block';
1.303 raeburn 17561: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 17562: if (caller == 'emailoptions') {
17563: optionsElement = domForm.cancreate_email;
17564: }
1.257 raeburn 17565: if (caller == 'studentsubmission') {
17566: optionsElement = domForm.postsubmit;
17567: }
1.264 raeburn 17568: if (caller == 'cloneinstcode') {
17569: optionsElement = domForm.canclone;
17570: checkval = 'instcode';
17571: }
1.303 raeburn 17572: if (selfcreateRegExp.test(caller)) {
17573: optionsElement = domForm.elements[caller];
17574: checkval = 'other';
17575: dispval = 'inline'
17576: }
1.236 raeburn 17577: if (optionsElement.length) {
1.192 raeburn 17578: var currval;
1.236 raeburn 17579: for (var i=0; i<optionsElement.length; i++) {
17580: if (optionsElement[i].checked) {
17581: currval = optionsElement[i].value;
1.192 raeburn 17582: }
17583: }
1.264 raeburn 17584: if (currval == checkval) {
17585: divitem.style.display = dispval;
1.192 raeburn 17586: } else {
1.236 raeburn 17587: divitem.style.display = 'none';
1.192 raeburn 17588: }
17589: }
17590: }
17591: return;
17592: }
17593:
17594: // ]]>
17595: </script>
17596:
17597: END
17598:
17599: }
17600:
1.165 raeburn 17601: sub captcha_phrases {
17602: return &Apache::lonlocal::texthash (
17603: priv => 'Private key',
17604: pub => 'Public key',
17605: original => 'original (CAPTCHA)',
17606: recaptcha => 'successor (ReCAPTCHA)',
17607: notused => 'unused',
1.289 raeburn 17608: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 17609: );
17610: }
17611:
1.205 raeburn 17612: sub devalidate_remote_domconfs {
1.212 raeburn 17613: my ($dom,$cachekeys) = @_;
17614: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 17615: my %servers = &Apache::lonnet::internet_dom_servers($dom);
17616: my %thismachine;
17617: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.295 raeburn 17618: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions','directorysrch');
1.260 raeburn 17619: if (keys(%servers)) {
1.205 raeburn 17620: foreach my $server (keys(%servers)) {
17621: next if ($thismachine{$server});
1.212 raeburn 17622: my @cached;
17623: foreach my $name (@posscached) {
17624: if ($cachekeys->{$name}) {
17625: push(@cached,&escape($name).':'.&escape($dom));
17626: }
17627: }
17628: if (@cached) {
17629: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
17630: }
1.205 raeburn 17631: }
17632: }
17633: return;
17634: }
17635:
1.3 raeburn 17636: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>