Annotation of loncom/interface/domainprefs.pm, revision 1.327
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.327 ! raeburn 4: # $Id: domainprefs.pm,v 1.326 2018/05/08 01:48:18 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: }
1.327 ! raeburn 7965: $datatable .= '</span></td></tr>';
1.238 raeburn 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.327 ! raeburn 8051: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 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.327 ! raeburn 8208: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
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"':'';
1.327 ! raeburn 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.327 ! raeburn 8513: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
! 8514: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
! 8515: .'</td></tr>';
1.48 raeburn 8516: return $datatable;
8517: }
8518:
8519: sub build_category_rows {
1.49 raeburn 8520: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
8521: my ($text,$name,$item,$chgstr);
1.48 raeburn 8522: if (ref($cats) eq 'ARRAY') {
8523: my $maxdepth = scalar(@{$cats});
8524: if (ref($cats->[$depth]) eq 'HASH') {
8525: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
8526: my $numchildren = @{$cats->[$depth]{$parent}};
8527: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 8528: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 8529: my ($idxnum,$parent_name,$parent_item);
8530: my $higher = $depth - 1;
8531: if ($higher == 0) {
8532: $parent_name = &escape($parent).'::'.$higher;
8533: } else {
8534: if (ref($path) eq 'ARRAY') {
8535: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8536: }
8537: }
8538: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 8539: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 8540: if ($j < $numchildren) {
1.48 raeburn 8541: $name = $cats->[$depth]{$parent}[$j];
8542: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 8543: $idxnum = $idx->{$item};
8544: } else {
8545: $name = $parent_name;
8546: $item = $parent_item;
1.48 raeburn 8547: }
1.49 raeburn 8548: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
8549: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 8550: for (my $i=0; $i<=$numchildren; $i++) {
8551: my $vpos = $i+1;
8552: my $selstr;
8553: if ($j == $i) {
8554: $selstr = ' selected="selected" ';
8555: }
8556: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
8557: }
8558: $text .= '</select> ';
8559: if ($j < $numchildren) {
8560: my $deeper = $depth+1;
8561: $text .= $name.' '
8562: .'<label><input type="checkbox" name="deletecategory" value="'
8563: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
8564: if(ref($path) eq 'ARRAY') {
8565: push(@{$path},$name);
1.49 raeburn 8566: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 8567: pop(@{$path});
8568: }
8569: } else {
1.59 bisitz 8570: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 8571: if ($j == $numchildren) {
8572: $text .= $name;
8573: } else {
8574: $text .= $item;
8575: }
8576: $text .= '" value="" />';
8577: }
8578: $text .= '</td></tr>';
8579: }
8580: $text .= '</table></td>';
8581: } else {
8582: my $higher = $depth-1;
8583: if ($higher == 0) {
8584: $name = &escape($parent).'::'.$higher;
8585: } else {
8586: if (ref($path) eq 'ARRAY') {
8587: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
8588: }
8589: }
8590: my $colspan;
8591: if ($parent ne 'instcode') {
8592: $colspan = $maxdepth - $depth - 1;
8593: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
8594: }
8595: }
8596: }
8597: }
8598: return $text;
8599: }
8600:
1.33 raeburn 8601: sub modifiable_userdata_row {
1.305 raeburn 8602: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
8603: $rowid,$customcss,$rowstyle) = @_;
1.228 raeburn 8604: my ($role,$rolename,$statustype);
8605: $role = $item;
1.224 raeburn 8606: if ($context eq 'cancreate') {
1.305 raeburn 8607: if ($item =~ /^(emailusername)_(.+)$/) {
8608: $role = $1;
8609: $statustype = $2;
1.228 raeburn 8610: if (ref($usertypes) eq 'HASH') {
8611: if ($usertypes->{$statustype}) {
8612: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
8613: } else {
8614: $rolename = &mt('Data provided by user');
8615: }
8616: }
1.224 raeburn 8617: }
8618: } elsif ($context eq 'selfcreate') {
1.63 raeburn 8619: if (ref($usertypes) eq 'HASH') {
8620: $rolename = $usertypes->{$role};
8621: } else {
8622: $rolename = $role;
8623: }
1.325 raeburn 8624: } elsif ($context eq 'lti') {
8625: $rolename = &mt('Institutional data used (if available)');
1.33 raeburn 8626: } else {
1.63 raeburn 8627: if ($role eq 'cr') {
8628: $rolename = &mt('Custom role');
8629: } else {
8630: $rolename = &Apache::lonnet::plaintext($role);
8631: }
1.33 raeburn 8632: }
1.224 raeburn 8633: my (@fields,%fieldtitles);
8634: if (ref($fieldsref) eq 'ARRAY') {
8635: @fields = @{$fieldsref};
8636: } else {
8637: @fields = ('lastname','firstname','middlename','generation',
8638: 'permanentemail','id');
8639: }
8640: if ((ref($titlesref) eq 'HASH')) {
8641: %fieldtitles = %{$titlesref};
8642: } else {
8643: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8644: }
1.33 raeburn 8645: my $output;
1.305 raeburn 8646: my $css_class;
8647: if ($rowcount%2) {
8648: $css_class = 'LC_odd_row';
8649: }
8650: if ($customcss) {
8651: $css_class .= " $customcss";
8652: }
8653: $css_class =~ s/^\s+//;
8654: if ($css_class) {
8655: $css_class = ' class="'.$css_class.'"';
8656: }
8657: if ($rowstyle) {
8658: $css_class .= ' style="'.$rowstyle.'"';
8659: }
8660: if ($rowid) {
8661: $rowid = ' id="'.$rowid.'"';
8662: }
8663: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 8664: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
8665: '<td class="LC_left_item" colspan="2"><table>';
8666: my $rem;
8667: my %checks;
1.325 raeburn 8668: my %current;
1.33 raeburn 8669: if (ref($settings) eq 'HASH') {
1.325 raeburn 8670: my $hashref;
8671: if ($context eq 'lti') {
8672: if (ref($settings) eq 'HASH') {
8673: $hashref = $settings->{'instdata'};
8674: }
8675: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 8676: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 8677: $hashref = $settings->{'lti_instdata'};
8678: }
8679: if ($role eq 'emailusername') {
8680: if ($statustype) {
8681: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
8682: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 8683: }
1.325 raeburn 8684: }
8685: }
8686: }
8687: if (ref($hashref) eq 'HASH') {
8688: foreach my $field (@fields) {
8689: if ($hashref->{$field}) {
8690: if ($role eq 'emailusername') {
8691: $checks{$field} = $hashref->{$field};
8692: } else {
8693: $checks{$field} = ' checked="checked" ';
1.33 raeburn 8694: }
8695: }
8696: }
8697: }
8698: }
1.305 raeburn 8699:
8700: my $total = scalar(@fields);
8701: for (my $i=0; $i<$total; $i++) {
8702: $rem = $i%($numinrow);
1.33 raeburn 8703: if ($rem == 0) {
8704: if ($i > 0) {
8705: $output .= '</tr>';
8706: }
8707: $output .= '<tr>';
8708: }
8709: my $check = ' ';
1.228 raeburn 8710: unless ($role eq 'emailusername') {
8711: if (exists($checks{$fields[$i]})) {
8712: $check = $checks{$fields[$i]}
1.325 raeburn 8713: } elsif ($context ne 'lti') {
1.228 raeburn 8714: if ($role eq 'st') {
8715: if (ref($settings) ne 'HASH') {
8716: $check = ' checked="checked" ';
8717: }
1.33 raeburn 8718: }
8719: }
8720: }
8721: $output .= '<td class="LC_left_item">'.
1.228 raeburn 8722: '<span class="LC_nobreak">';
1.325 raeburn 8723: my $prefix = 'canmodify';
1.228 raeburn 8724: if ($role eq 'emailusername') {
8725: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
8726: $checks{$fields[$i]} = 'omit';
8727: }
8728: foreach my $option ('required','optional','omit') {
8729: my $checked='';
8730: if ($checks{$fields[$i]} eq $option) {
8731: $checked='checked="checked" ';
8732: }
8733: $output .= '<label>'.
1.325 raeburn 8734: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 8735: &mt($option).'</label>'.(' ' x2);
8736: }
8737: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
8738: } else {
1.325 raeburn 8739: if ($context eq 'lti') {
8740: $prefix = 'lti';
8741: }
1.228 raeburn 8742: $output .= '<label>'.
1.325 raeburn 8743: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 8744: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
8745: '</label>';
8746: }
8747: $output .= '</span></td>';
1.33 raeburn 8748: }
1.305 raeburn 8749: $rem = $total%$numinrow;
8750: my $colsleft;
8751: if ($rem) {
8752: $colsleft = $numinrow - $rem;
8753: }
8754: if ($colsleft > 1) {
1.33 raeburn 8755: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8756: ' </td>';
8757: } elsif ($colsleft == 1) {
8758: $output .= '<td class="LC_left_item"> </td>';
8759: }
8760: $output .= '</tr></table></td></tr>';
8761: return $output;
8762: }
1.28 raeburn 8763:
1.93 raeburn 8764: sub insttypes_row {
1.305 raeburn 8765: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
8766: $customcss,$rowstyle) = @_;
1.93 raeburn 8767: my %lt = &Apache::lonlocal::texthash (
8768: cansearch => 'Users allowed to search',
8769: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 8770: lockablenames => 'User preference to lock name',
1.305 raeburn 8771: selfassign => 'Self-reportable affiliations',
1.315 raeburn 8772: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 8773: );
8774: my $showdom;
8775: if ($context eq 'cansearch') {
8776: $showdom = ' ('.$dom.')';
8777: }
1.165 raeburn 8778: my $class = 'LC_left_item';
8779: if ($context eq 'statustocreate') {
8780: $class = 'LC_right_item';
8781: }
1.305 raeburn 8782: my $css_class;
8783: if ($$rowtotal%2) {
8784: $css_class = 'LC_odd_row';
8785: }
8786: if ($customcss) {
8787: $css_class .= ' '.$customcss;
8788: }
8789: $css_class =~ s/^\s+//;
8790: if ($css_class) {
8791: $css_class = ' class="'.$css_class.'"';
8792: }
8793: if ($rowstyle) {
8794: $css_class .= ' style="'.$rowstyle.'"';
8795: }
8796: if ($onclick) {
8797: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 8798: }
8799: my $output = '<tr'.$css_class.'>'.
8800: '<td>'.$lt{$context}.$showdom.
8801: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 8802: my $rem;
8803: if (ref($types) eq 'ARRAY') {
8804: for (my $i=0; $i<@{$types}; $i++) {
8805: if (defined($usertypes->{$types->[$i]})) {
8806: my $rem = $i%($numinrow);
8807: if ($rem == 0) {
8808: if ($i > 0) {
8809: $output .= '</tr>';
8810: }
8811: $output .= '<tr>';
1.23 raeburn 8812: }
1.26 raeburn 8813: my $check = ' ';
1.99 raeburn 8814: if (ref($settings) eq 'HASH') {
8815: if (ref($settings->{$context}) eq 'ARRAY') {
8816: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
8817: $check = ' checked="checked" ';
8818: }
1.315 raeburn 8819: } elsif (ref($settings->{$context}) eq 'HASH') {
8820: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
8821: $check = ' checked="checked" ';
8822: }
1.99 raeburn 8823: } elsif ($context eq 'statustocreate') {
1.26 raeburn 8824: $check = ' checked="checked" ';
8825: }
1.23 raeburn 8826: }
1.26 raeburn 8827: $output .= '<td class="LC_left_item">'.
8828: '<span class="LC_nobreak"><label>'.
1.93 raeburn 8829: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 8830: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 8831: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 8832: }
8833: }
1.26 raeburn 8834: $rem = @{$types}%($numinrow);
1.23 raeburn 8835: }
8836: my $colsleft = $numinrow - $rem;
1.315 raeburn 8837: if ($context eq 'overrides') {
8838: if ($colsleft > 1) {
8839: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8840: } else {
8841: $output .= '<td class="LC_left_item">';
8842: }
8843: $output .= ' ';
1.23 raeburn 8844: } else {
1.315 raeburn 8845: if (($rem == 0) && (@{$types} > 0)) {
8846: $output .= '<tr>';
8847: }
8848: if ($colsleft > 1) {
8849: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
8850: } else {
8851: $output .= '<td class="LC_left_item">';
8852: }
8853: my $defcheck = ' ';
8854: if (ref($settings) eq 'HASH') {
8855: if (ref($settings->{$context}) eq 'ARRAY') {
8856: if (grep(/^default$/,@{$settings->{$context}})) {
8857: $defcheck = ' checked="checked" ';
8858: }
8859: } elsif ($context eq 'statustocreate') {
1.99 raeburn 8860: $defcheck = ' checked="checked" ';
8861: }
1.26 raeburn 8862: }
1.315 raeburn 8863: $output .= '<span class="LC_nobreak"><label>'.
8864: '<input type="checkbox" name="'.$context.'" '.
8865: 'value="default"'.$defcheck.$onclick.' />'.
8866: $othertitle.'</label></span>';
1.23 raeburn 8867: }
1.315 raeburn 8868: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 8869: return $output;
1.23 raeburn 8870: }
8871:
8872: sub sorted_searchtitles {
8873: my %searchtitles = &Apache::lonlocal::texthash(
8874: 'uname' => 'username',
8875: 'lastname' => 'last name',
8876: 'lastfirst' => 'last name, first name',
8877: );
8878: my @titleorder = ('uname','lastname','lastfirst');
8879: return (\%searchtitles,\@titleorder);
8880: }
8881:
1.25 raeburn 8882: sub sorted_searchtypes {
8883: my %srchtypes_desc = (
8884: exact => 'is exact match',
8885: contains => 'contains ..',
8886: begins => 'begins with ..',
8887: );
8888: my @srchtypeorder = ('exact','begins','contains');
8889: return (\%srchtypes_desc,\@srchtypeorder);
8890: }
8891:
1.3 raeburn 8892: sub usertype_update_row {
8893: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
8894: my $datatable;
8895: my $numinrow = 4;
8896: foreach my $type (@{$types}) {
8897: if (defined($usertypes->{$type})) {
8898: $$rownums ++;
8899: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
8900: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
8901: '</td><td class="LC_left_item"><table>';
8902: for (my $i=0; $i<@{$fields}; $i++) {
8903: my $rem = $i%($numinrow);
8904: if ($rem == 0) {
8905: if ($i > 0) {
8906: $datatable .= '</tr>';
8907: }
8908: $datatable .= '<tr>';
8909: }
8910: my $check = ' ';
1.39 raeburn 8911: if (ref($settings) eq 'HASH') {
8912: if (ref($settings->{'fields'}) eq 'HASH') {
8913: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
8914: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
8915: $check = ' checked="checked" ';
8916: }
1.3 raeburn 8917: }
8918: }
8919: }
8920:
8921: if ($i == @{$fields}-1) {
8922: my $colsleft = $numinrow - $rem;
8923: if ($colsleft > 1) {
8924: $datatable .= '<td colspan="'.$colsleft.'">';
8925: } else {
8926: $datatable .= '<td>';
8927: }
8928: } else {
8929: $datatable .= '<td>';
8930: }
1.8 raeburn 8931: $datatable .= '<span class="LC_nobreak"><label>'.
8932: '<input type="checkbox" name="updateable_'.$type.
8933: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
8934: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 8935: }
8936: $datatable .= '</tr></table></td></tr>';
8937: }
8938: }
8939: return $datatable;
1.1 raeburn 8940: }
8941:
8942: sub modify_login {
1.205 raeburn 8943: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 8944: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
8945: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
8946: %title = ( coursecatalog => 'Display course catalog',
8947: adminmail => 'Display administrator E-mail address',
1.188 raeburn 8948: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 8949: newuser => 'Link for visitors to create a user account',
8950: loginheader => 'Log-in box header');
8951: @offon = ('off','on');
1.112 raeburn 8952: if (ref($domconfig{login}) eq 'HASH') {
8953: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
8954: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
8955: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
8956: }
8957: }
8958: }
1.9 raeburn 8959: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
8960: \%domconfig,\%loginhash);
1.188 raeburn 8961: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 8962: foreach my $item (@toggles) {
8963: $loginhash{login}{$item} = $env{'form.'.$item};
8964: }
1.41 raeburn 8965: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 8966: if (ref($colchanges{'login'}) eq 'HASH') {
8967: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
8968: \%loginhash);
8969: }
1.110 raeburn 8970:
1.149 raeburn 8971: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 8972: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 8973: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 8974: if (keys(%servers) > 1) {
8975: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 8976: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
8977: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
8978: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
8979: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
8980: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
8981: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8982: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
8983: $changes{'loginvia'}{$lonhost} = 1;
8984: } else {
8985: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
8986: $changes{'loginvia'}{$lonhost} = 1;
8987: }
8988: } else {
8989: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8990: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
8991: $changes{'loginvia'}{$lonhost} = 1;
8992: }
8993: }
8994: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
8995: foreach my $item (@loginvia_attribs) {
8996: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
8997: }
8998: } else {
8999: foreach my $item (@loginvia_attribs) {
9000: my $new = $env{'form.'.$lonhost.'_'.$item};
9001: if (($item eq 'serverpath') && ($new eq 'custom')) {
9002: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
9003: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9004: $new = '/';
9005: }
9006: }
9007: if (($item eq 'custompath') &&
9008: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9009: $new = '';
9010: }
9011: if ($new ne $curr_loginvia{$lonhost}{$item}) {
9012: $changes{'loginvia'}{$lonhost} = 1;
9013: }
9014: if ($item eq 'exempt') {
1.256 raeburn 9015: $new = &check_exempt_addresses($new);
1.128 raeburn 9016: }
9017: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9018: }
9019: }
1.112 raeburn 9020: } else {
1.128 raeburn 9021: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9022: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 9023: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 9024: foreach my $item (@loginvia_attribs) {
9025: my $new = $env{'form.'.$lonhost.'_'.$item};
9026: if (($item eq 'serverpath') && ($new eq 'custom')) {
9027: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9028: $new = '/';
9029: }
9030: }
9031: if (($item eq 'custompath') &&
9032: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9033: $new = '';
9034: }
9035: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9036: }
1.110 raeburn 9037: }
9038: }
9039: }
9040: }
1.119 raeburn 9041:
1.168 raeburn 9042: my $servadm = $r->dir_config('lonAdmEMail');
9043: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
9044: if (ref($domconfig{'login'}) eq 'HASH') {
9045: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
9046: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
9047: if ($lang eq 'nolang') {
9048: push(@currlangs,$lang);
9049: } elsif (defined($langchoices{$lang})) {
9050: push(@currlangs,$lang);
9051: } else {
9052: next;
9053: }
9054: }
9055: }
9056: }
9057: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
9058: if (@currlangs > 0) {
9059: foreach my $lang (@currlangs) {
9060: if (grep(/^\Q$lang\E$/,@delurls)) {
9061: $changes{'helpurl'}{$lang} = 1;
9062: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
9063: $changes{'helpurl'}{$lang} = 1;
9064: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
9065: push(@newlangs,$lang);
9066: } else {
9067: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9068: }
9069: }
9070: }
9071: unless (grep(/^nolang$/,@currlangs)) {
9072: if ($env{'form.loginhelpurl_nolang.filename'}) {
9073: $changes{'helpurl'}{'nolang'} = 1;
9074: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
9075: push(@newlangs,'nolang');
9076: }
9077: }
9078: if ($env{'form.loginhelpurl_add_lang'}) {
9079: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
9080: ($env{'form.loginhelpurl_add_file.filename'})) {
9081: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
9082: $addedfile = $env{'form.loginhelpurl_add_lang'};
9083: }
9084: }
9085: if ((@newlangs > 0) || ($addedfile)) {
9086: my $error;
9087: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9088: if ($configuserok eq 'ok') {
9089: if ($switchserver) {
9090: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
9091: } elsif ($author_ok eq 'ok') {
9092: my @allnew = @newlangs;
9093: if ($addedfile ne '') {
9094: push(@allnew,$addedfile);
9095: }
9096: foreach my $lang (@allnew) {
9097: my $formelem = 'loginhelpurl_'.$lang;
9098: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
9099: $formelem = 'loginhelpurl_add_file';
9100: }
9101: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9102: "help/$lang",'','',$newfile{$lang});
9103: if ($result eq 'ok') {
9104: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
9105: $changes{'helpurl'}{$lang} = 1;
9106: } else {
9107: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
9108: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 9109: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 9110: (!grep(/^\Q$lang\E$/,@delurls))) {
9111: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9112: }
9113: }
9114: }
9115: } else {
9116: $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);
9117: }
9118: } else {
9119: $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);
9120: }
9121: if ($error) {
9122: &Apache::lonnet::logthis($error);
9123: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9124: }
9125: }
1.256 raeburn 9126:
9127: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
9128: if (ref($domconfig{'login'}) eq 'HASH') {
9129: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
9130: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
9131: if ($domservers{$lonhost}) {
9132: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9133: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 9134: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 9135: }
9136: }
9137: }
9138: }
9139: }
9140: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
9141: foreach my $lonhost (sort(keys(%domservers))) {
9142: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9143: $changes{'headtag'}{$lonhost} = 1;
9144: } else {
9145: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
9146: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
9147: }
9148: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
9149: push(@newhosts,$lonhost);
9150: } elsif ($currheadtagurls{$lonhost}) {
9151: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
9152: if ($currexempt{$lonhost}) {
1.289 raeburn 9153: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 9154: $changes{'headtag'}{$lonhost} = 1;
9155: }
9156: } elsif ($possexempt{$lonhost}) {
9157: $changes{'headtag'}{$lonhost} = 1;
9158: }
9159: if ($possexempt{$lonhost}) {
9160: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9161: }
9162: }
9163: }
9164: }
9165: if (@newhosts) {
9166: my $error;
9167: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9168: if ($configuserok eq 'ok') {
9169: if ($switchserver) {
9170: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
9171: } elsif ($author_ok eq 'ok') {
9172: foreach my $lonhost (@newhosts) {
9173: my $formelem = 'loginheadtag_'.$lonhost;
9174: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9175: "login/headtag/$lonhost",'','',
9176: $env{'form.loginheadtag_'.$lonhost.'.filename'});
9177: if ($result eq 'ok') {
9178: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
9179: $changes{'headtag'}{$lonhost} = 1;
9180: if ($possexempt{$lonhost}) {
9181: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9182: }
9183: } else {
9184: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
9185: $newheadtagurls{$lonhost},$result);
9186: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
9187: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
9188: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
9189: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
9190: }
9191: }
9192: }
9193: } else {
9194: $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);
9195: }
9196: } else {
9197: $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);
9198: }
9199: if ($error) {
9200: &Apache::lonnet::logthis($error);
9201: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9202: }
9203: }
1.169 raeburn 9204: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 9205:
9206: my $defaulthelpfile = '/adm/loginproblems.html';
9207: my $defaulttext = &mt('Default in use');
9208:
1.1 raeburn 9209: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
9210: $dom);
9211: if ($putresult eq 'ok') {
1.188 raeburn 9212: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 9213: my %defaultchecked = (
9214: 'coursecatalog' => 'on',
1.188 raeburn 9215: 'helpdesk' => 'on',
1.42 raeburn 9216: 'adminmail' => 'off',
1.43 raeburn 9217: 'newuser' => 'off',
1.42 raeburn 9218: );
1.55 raeburn 9219: if (ref($domconfig{'login'}) eq 'HASH') {
9220: foreach my $item (@toggles) {
9221: if ($defaultchecked{$item} eq 'on') {
9222: if (($domconfig{'login'}{$item} eq '0') &&
9223: ($env{'form.'.$item} eq '1')) {
9224: $changes{$item} = 1;
9225: } elsif (($domconfig{'login'}{$item} eq '' ||
9226: $domconfig{'login'}{$item} eq '1') &&
9227: ($env{'form.'.$item} eq '0')) {
9228: $changes{$item} = 1;
9229: }
9230: } elsif ($defaultchecked{$item} eq 'off') {
9231: if (($domconfig{'login'}{$item} eq '1') &&
9232: ($env{'form.'.$item} eq '0')) {
9233: $changes{$item} = 1;
9234: } elsif (($domconfig{'login'}{$item} eq '' ||
9235: $domconfig{'login'}{$item} eq '0') &&
9236: ($env{'form.'.$item} eq '1')) {
9237: $changes{$item} = 1;
9238: }
1.42 raeburn 9239: }
9240: }
1.41 raeburn 9241: }
1.6 raeburn 9242: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 9243: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9244: if (ref($lastactref) eq 'HASH') {
9245: $lastactref->{'domainconfig'} = 1;
9246: }
1.1 raeburn 9247: $resulttext = &mt('Changes made:').'<ul>';
9248: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 9249: if ($item eq 'loginvia') {
1.112 raeburn 9250: if (ref($changes{$item}) eq 'HASH') {
9251: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
9252: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 9253: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
9254: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
9255: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
9256: $protocol = 'http' if ($protocol ne 'https');
9257: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
9258:
9259: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
9260: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
9261: } else {
9262: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
9263: }
9264: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
9265: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
9266: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
9267: }
9268: $resulttext .= '</li>';
9269: } else {
9270: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
9271: }
1.112 raeburn 9272: } else {
1.128 raeburn 9273: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 9274: }
9275: }
1.128 raeburn 9276: $resulttext .= '</ul></li>';
1.112 raeburn 9277: }
1.168 raeburn 9278: } elsif ($item eq 'helpurl') {
9279: if (ref($changes{$item}) eq 'HASH') {
9280: foreach my $lang (sort(keys(%{$changes{$item}}))) {
9281: if (grep(/^\Q$lang\E$/,@delurls)) {
9282: my ($chg,$link);
9283: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
9284: if ($lang eq 'nolang') {
9285: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
9286: } else {
9287: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
9288: }
9289: $resulttext .= '<li>'.$chg.'</li>';
9290: } else {
9291: my $chg;
9292: if ($lang eq 'nolang') {
9293: $chg = &mt('custom log-in help file for no preferred language');
9294: } else {
9295: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
9296: }
9297: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
9298: $loginhash{'login'}{'helpurl'}{$lang}.
9299: '?inhibitmenu=yes',$chg,600,500).
9300: '</li>';
9301: }
9302: }
9303: }
1.256 raeburn 9304: } elsif ($item eq 'headtag') {
9305: if (ref($changes{$item}) eq 'HASH') {
9306: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
9307: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9308: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
9309: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9310: $resulttext .= '<li><a href="'.
9311: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
9312: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
9313: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
9314: if ($possexempt{$lonhost}) {
9315: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
9316: } else {
9317: $resulttext .= &mt('included for any client IP');
9318: }
9319: $resulttext .= '</li>';
9320: }
9321: }
9322: }
1.169 raeburn 9323: } elsif ($item eq 'captcha') {
9324: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 9325: my $chgtxt;
1.169 raeburn 9326: if ($loginhash{'login'}{$item} eq 'notused') {
9327: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
9328: } else {
9329: my %captchas = &captcha_phrases();
9330: if ($captchas{$loginhash{'login'}{$item}}) {
9331: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
9332: } else {
9333: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
9334: }
9335: }
9336: $resulttext .= '<li>'.$chgtxt.'</li>';
9337: }
9338: } elsif ($item eq 'recaptchakeys') {
9339: if (ref($loginhash{'login'}) eq 'HASH') {
9340: my ($privkey,$pubkey);
9341: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
9342: $pubkey = $loginhash{'login'}{$item}{'public'};
9343: $privkey = $loginhash{'login'}{$item}{'private'};
9344: }
9345: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
9346: if (!$pubkey) {
9347: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
9348: } else {
9349: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
9350: }
9351: if (!$privkey) {
9352: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
9353: } else {
1.251 raeburn 9354: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 9355: }
9356: $chgtxt .= '</ul>';
9357: $resulttext .= '<li>'.$chgtxt.'</li>';
9358: }
1.269 raeburn 9359: } elsif ($item eq 'recaptchaversion') {
9360: if (ref($loginhash{'login'}) eq 'HASH') {
9361: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 9362: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 9363: '</li>';
9364: }
9365: }
1.41 raeburn 9366: } else {
9367: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
9368: }
1.1 raeburn 9369: }
1.6 raeburn 9370: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 9371: } else {
9372: $resulttext = &mt('No changes made to log-in page settings');
9373: }
9374: } else {
1.11 albertel 9375: $resulttext = '<span class="LC_error">'.
9376: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9377: }
1.6 raeburn 9378: if ($errors) {
1.9 raeburn 9379: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 9380: $errors.'</ul>';
9381: }
9382: return $resulttext;
9383: }
9384:
1.256 raeburn 9385: sub check_exempt_addresses {
9386: my ($iplist) = @_;
9387: $iplist =~ s/^\s+//;
9388: $iplist =~ s/\s+$//;
9389: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
9390: my (@okips,$new);
9391: foreach my $ip (@poss_ips) {
9392: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
9393: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
9394: push(@okips,$ip);
9395: }
9396: }
9397: }
9398: if (@okips > 0) {
9399: $new = join(',',@okips);
9400: } else {
9401: $new = '';
9402: }
9403: return $new;
9404: }
9405:
1.6 raeburn 9406: sub color_font_choices {
9407: my %choices =
9408: &Apache::lonlocal::texthash (
9409: img => "Header",
9410: bgs => "Background colors",
9411: links => "Link colors",
1.55 raeburn 9412: images => "Images",
1.6 raeburn 9413: font => "Font color",
1.201 raeburn 9414: fontmenu => "Font menu",
1.76 raeburn 9415: pgbg => "Page",
1.6 raeburn 9416: tabbg => "Header",
9417: sidebg => "Border",
9418: link => "Link",
9419: alink => "Active link",
9420: vlink => "Visited link",
9421: );
9422: return %choices;
9423: }
9424:
9425: sub modify_rolecolors {
1.205 raeburn 9426: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 9427: my ($resulttext,%rolehash);
9428: $rolehash{'rolecolors'} = {};
1.55 raeburn 9429: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
9430: if ($domconfig{'rolecolors'} eq '') {
9431: $domconfig{'rolecolors'} = {};
9432: }
9433: }
1.9 raeburn 9434: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 9435: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
9436: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
9437: $dom);
9438: if ($putresult eq 'ok') {
9439: if (keys(%changes) > 0) {
1.41 raeburn 9440: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9441: if (ref($lastactref) eq 'HASH') {
9442: $lastactref->{'domainconfig'} = 1;
9443: }
1.6 raeburn 9444: $resulttext = &display_colorchgs($dom,\%changes,$roles,
9445: $rolehash{'rolecolors'});
9446: } else {
9447: $resulttext = &mt('No changes made to default color schemes');
9448: }
9449: } else {
1.11 albertel 9450: $resulttext = '<span class="LC_error">'.
9451: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 9452: }
9453: if ($errors) {
9454: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9455: $errors.'</ul>';
9456: }
9457: return $resulttext;
9458: }
9459:
9460: sub modify_colors {
1.9 raeburn 9461: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 9462: my (%changes,%choices);
1.51 raeburn 9463: my @bgs;
1.6 raeburn 9464: my @links = ('link','alink','vlink');
1.41 raeburn 9465: my @logintext;
1.6 raeburn 9466: my @images;
9467: my $servadm = $r->dir_config('lonAdmEMail');
9468: my $errors;
1.200 raeburn 9469: my %defaults;
1.6 raeburn 9470: foreach my $role (@{$roles}) {
9471: if ($role eq 'login') {
1.12 raeburn 9472: %choices = &login_choices();
1.41 raeburn 9473: @logintext = ('textcol','bgcol');
1.12 raeburn 9474: } else {
9475: %choices = &color_font_choices();
9476: }
9477: if ($role eq 'login') {
1.41 raeburn 9478: @images = ('img','logo','domlogo','login');
1.51 raeburn 9479: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 9480: } else {
9481: @images = ('img');
1.200 raeburn 9482: @bgs = ('pgbg','tabbg','sidebg');
9483: }
9484: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
9485: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
9486: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
9487: }
9488: if ($role eq 'login') {
9489: foreach my $item (@logintext) {
1.234 raeburn 9490: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9491: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9492: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9493: }
9494: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 9495: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9496: }
9497: }
9498: } else {
1.234 raeburn 9499: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
9500: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
9501: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
9502: }
9503: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 9504: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
9505: }
1.6 raeburn 9506: }
1.200 raeburn 9507: foreach my $item (@bgs) {
1.234 raeburn 9508: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9509: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9510: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9511: }
9512: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 9513: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9514: }
9515: }
9516: foreach my $item (@links) {
1.234 raeburn 9517: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
9518: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
9519: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
9520: }
9521: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 9522: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
9523: }
1.6 raeburn 9524: }
1.46 raeburn 9525: my ($configuserok,$author_ok,$switchserver) =
9526: &config_check($dom,$confname,$servadm);
1.9 raeburn 9527: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 9528: if (ref($domconfig->{$role}) ne 'HASH') {
9529: $domconfig->{$role} = {};
9530: }
1.8 raeburn 9531: foreach my $img (@images) {
1.70 raeburn 9532: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
9533: if (defined($env{'form.login_showlogo_'.$img})) {
9534: $confhash->{$role}{'showlogo'}{$img} = 1;
9535: } else {
9536: $confhash->{$role}{'showlogo'}{$img} = 0;
9537: }
9538: }
1.18 albertel 9539: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
9540: && !defined($domconfig->{$role}{$img})
9541: && !$env{'form.'.$role.'_del_'.$img}
9542: && $env{'form.'.$role.'_import_'.$img}) {
9543: # import the old configured image from the .tab setting
9544: # if they haven't provided a new one
9545: $domconfig->{$role}{$img} =
9546: $env{'form.'.$role.'_import_'.$img};
9547: }
1.6 raeburn 9548: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 9549: my $error;
1.6 raeburn 9550: if ($configuserok eq 'ok') {
1.9 raeburn 9551: if ($switchserver) {
1.12 raeburn 9552: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 9553: } else {
9554: if ($author_ok eq 'ok') {
9555: my ($result,$logourl) =
9556: &publishlogo($r,'upload',$role.'_'.$img,
9557: $dom,$confname,$img,$width,$height);
9558: if ($result eq 'ok') {
9559: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 9560: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 9561: } else {
1.12 raeburn 9562: $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 9563: }
9564: } else {
1.46 raeburn 9565: $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 9566: }
9567: }
9568: } else {
1.46 raeburn 9569: $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 9570: }
9571: if ($error) {
1.8 raeburn 9572: &Apache::lonnet::logthis($error);
1.11 albertel 9573: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 9574: }
9575: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 9576: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
9577: my $error;
9578: if ($configuserok eq 'ok') {
9579: # is confname an author?
9580: if ($switchserver eq '') {
9581: if ($author_ok eq 'ok') {
9582: my ($result,$logourl) =
9583: &publishlogo($r,'copy',$domconfig->{$role}{$img},
9584: $dom,$confname,$img,$width,$height);
9585: if ($result eq 'ok') {
9586: $confhash->{$role}{$img} = $logourl;
1.18 albertel 9587: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 9588: }
9589: }
9590: }
9591: }
1.6 raeburn 9592: }
9593: }
9594: }
9595: if (ref($domconfig) eq 'HASH') {
9596: if (ref($domconfig->{$role}) eq 'HASH') {
9597: foreach my $img (@images) {
9598: if ($domconfig->{$role}{$img} ne '') {
9599: if ($env{'form.'.$role.'_del_'.$img}) {
9600: $confhash->{$role}{$img} = '';
1.12 raeburn 9601: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 9602: } else {
1.9 raeburn 9603: if ($confhash->{$role}{$img} eq '') {
9604: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
9605: }
1.6 raeburn 9606: }
9607: } else {
9608: if ($env{'form.'.$role.'_del_'.$img}) {
9609: $confhash->{$role}{$img} = '';
1.12 raeburn 9610: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 9611: }
9612: }
1.70 raeburn 9613: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
9614: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
9615: if ($confhash->{$role}{'showlogo'}{$img} ne
9616: $domconfig->{$role}{'showlogo'}{$img}) {
9617: $changes{$role}{'showlogo'}{$img} = 1;
9618: }
9619: } else {
9620: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
9621: $changes{$role}{'showlogo'}{$img} = 1;
9622: }
9623: }
9624: }
9625: }
1.6 raeburn 9626: if ($domconfig->{$role}{'font'} ne '') {
9627: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
9628: $changes{$role}{'font'} = 1;
9629: }
9630: } else {
9631: if ($confhash->{$role}{'font'}) {
9632: $changes{$role}{'font'} = 1;
9633: }
9634: }
1.107 raeburn 9635: if ($role ne 'login') {
9636: if ($domconfig->{$role}{'fontmenu'} ne '') {
9637: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
9638: $changes{$role}{'fontmenu'} = 1;
9639: }
9640: } else {
9641: if ($confhash->{$role}{'fontmenu'}) {
9642: $changes{$role}{'fontmenu'} = 1;
9643: }
1.97 tempelho 9644: }
9645: }
1.6 raeburn 9646: foreach my $item (@bgs) {
9647: if ($domconfig->{$role}{$item} ne '') {
9648: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9649: $changes{$role}{'bgs'}{$item} = 1;
9650: }
9651: } else {
9652: if ($confhash->{$role}{$item}) {
9653: $changes{$role}{'bgs'}{$item} = 1;
9654: }
9655: }
9656: }
9657: foreach my $item (@links) {
9658: if ($domconfig->{$role}{$item} ne '') {
9659: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9660: $changes{$role}{'links'}{$item} = 1;
9661: }
9662: } else {
9663: if ($confhash->{$role}{$item}) {
9664: $changes{$role}{'links'}{$item} = 1;
9665: }
9666: }
9667: }
1.41 raeburn 9668: foreach my $item (@logintext) {
9669: if ($domconfig->{$role}{$item} ne '') {
9670: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
9671: $changes{$role}{'logintext'}{$item} = 1;
9672: }
9673: } else {
9674: if ($confhash->{$role}{$item}) {
9675: $changes{$role}{'logintext'}{$item} = 1;
9676: }
9677: }
9678: }
1.6 raeburn 9679: } else {
9680: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 9681: \@logintext,$confhash,\%changes);
1.6 raeburn 9682: }
9683: } else {
9684: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 9685: \@logintext,$confhash,\%changes);
1.6 raeburn 9686: }
9687: }
9688: return ($errors,%changes);
9689: }
9690:
1.46 raeburn 9691: sub config_check {
9692: my ($dom,$confname,$servadm) = @_;
9693: my ($configuserok,$author_ok,$switchserver,%currroles);
9694: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
9695: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
9696: $confname,$servadm);
9697: if ($configuserok eq 'ok') {
9698: $switchserver = &check_switchserver($dom,$confname);
9699: if ($switchserver eq '') {
9700: $author_ok = &check_authorstatus($dom,$confname,%currroles);
9701: }
9702: }
9703: return ($configuserok,$author_ok,$switchserver);
9704: }
9705:
1.6 raeburn 9706: sub default_change_checker {
1.41 raeburn 9707: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 9708: foreach my $item (@{$links}) {
9709: if ($confhash->{$role}{$item}) {
9710: $changes->{$role}{'links'}{$item} = 1;
9711: }
9712: }
9713: foreach my $item (@{$bgs}) {
9714: if ($confhash->{$role}{$item}) {
9715: $changes->{$role}{'bgs'}{$item} = 1;
9716: }
9717: }
1.41 raeburn 9718: foreach my $item (@{$logintext}) {
9719: if ($confhash->{$role}{$item}) {
9720: $changes->{$role}{'logintext'}{$item} = 1;
9721: }
9722: }
1.6 raeburn 9723: foreach my $img (@{$images}) {
9724: if ($env{'form.'.$role.'_del_'.$img}) {
9725: $confhash->{$role}{$img} = '';
1.12 raeburn 9726: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 9727: }
1.70 raeburn 9728: if ($role eq 'login') {
9729: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
9730: $changes->{$role}{'showlogo'}{$img} = 1;
9731: }
9732: }
1.6 raeburn 9733: }
9734: if ($confhash->{$role}{'font'}) {
9735: $changes->{$role}{'font'} = 1;
9736: }
1.48 raeburn 9737: }
1.6 raeburn 9738:
9739: sub display_colorchgs {
9740: my ($dom,$changes,$roles,$confhash) = @_;
9741: my (%choices,$resulttext);
9742: if (!grep(/^login$/,@{$roles})) {
9743: $resulttext = &mt('Changes made:').'<br />';
9744: }
9745: foreach my $role (@{$roles}) {
9746: if ($role eq 'login') {
9747: %choices = &login_choices();
9748: } else {
9749: %choices = &color_font_choices();
9750: }
9751: if (ref($changes->{$role}) eq 'HASH') {
9752: if ($role ne 'login') {
9753: $resulttext .= '<h4>'.&mt($role).'</h4>';
9754: }
9755: foreach my $key (sort(keys(%{$changes->{$role}}))) {
9756: if ($role ne 'login') {
9757: $resulttext .= '<ul>';
9758: }
9759: if (ref($changes->{$role}{$key}) eq 'HASH') {
9760: if ($role ne 'login') {
9761: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
9762: }
9763: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 9764: if (($role eq 'login') && ($key eq 'showlogo')) {
9765: if ($confhash->{$role}{$key}{$item}) {
9766: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
9767: } else {
9768: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
9769: }
9770: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 9771: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
9772: } else {
1.12 raeburn 9773: my $newitem = $confhash->{$role}{$item};
9774: if ($key eq 'images') {
1.306 raeburn 9775: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 9776: }
9777: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 9778: }
9779: }
9780: if ($role ne 'login') {
9781: $resulttext .= '</ul></li>';
9782: }
9783: } else {
9784: if ($confhash->{$role}{$key} eq '') {
9785: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
9786: } else {
9787: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
9788: }
9789: }
9790: if ($role ne 'login') {
9791: $resulttext .= '</ul>';
9792: }
9793: }
9794: }
9795: }
1.3 raeburn 9796: return $resulttext;
1.1 raeburn 9797: }
9798:
1.9 raeburn 9799: sub thumb_dimensions {
9800: return ('200','50');
9801: }
9802:
1.16 raeburn 9803: sub check_dimensions {
9804: my ($inputfile) = @_;
9805: my ($fullwidth,$fullheight);
9806: if ($inputfile =~ m|^[/\w.\-]+$|) {
9807: if (open(PIPE,"identify $inputfile 2>&1 |")) {
9808: my $imageinfo = <PIPE>;
9809: if (!close(PIPE)) {
9810: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
9811: }
9812: chomp($imageinfo);
9813: my ($fullsize) =
1.21 raeburn 9814: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 9815: if ($fullsize) {
9816: ($fullwidth,$fullheight) = split(/x/,$fullsize);
9817: }
9818: }
9819: }
9820: return ($fullwidth,$fullheight);
9821: }
9822:
1.9 raeburn 9823: sub check_configuser {
9824: my ($uhome,$dom,$confname,$servadm) = @_;
9825: my ($configuserok,%currroles);
9826: if ($uhome eq 'no_host') {
9827: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
9828: my $configpass = &LONCAPA::Enrollment::create_password();
9829: $configuserok =
9830: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
9831: $configpass,'','','','','',undef,$servadm);
9832: } else {
9833: $configuserok = 'ok';
9834: %currroles =
9835: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
9836: }
9837: return ($configuserok,%currroles);
9838: }
9839:
9840: sub check_authorstatus {
9841: my ($dom,$confname,%currroles) = @_;
9842: my $author_ok;
1.40 raeburn 9843: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 9844: my $start = time;
9845: my $end = 0;
9846: $author_ok =
9847: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 9848: 'au',$end,$start,'','','domconfig');
1.9 raeburn 9849: } else {
9850: $author_ok = 'ok';
9851: }
9852: return $author_ok;
9853: }
9854:
9855: sub publishlogo {
1.46 raeburn 9856: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 9857: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 9858: if ($action eq 'upload') {
9859: $fname=$env{'form.'.$formname.'.filename'};
9860: chop($env{'form.'.$formname});
9861: } else {
9862: ($fname) = ($formname =~ /([^\/]+)$/);
9863: }
1.46 raeburn 9864: if ($savefileas ne '') {
9865: $fname = $savefileas;
9866: }
1.9 raeburn 9867: $fname=&Apache::lonnet::clean_filename($fname);
9868: # See if there is anything left
9869: unless ($fname) { return ('error: no uploaded file'); }
9870: $fname="$subdir/$fname";
1.210 raeburn 9871: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 9872: my $filepath="$docroot/priv";
9873: my $relpath = "$dom/$confname";
1.9 raeburn 9874: my ($fnamepath,$file,$fetchthumb);
9875: $file=$fname;
9876: if ($fname=~m|/|) {
9877: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
9878: }
1.164 raeburn 9879: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 9880: my $count;
1.164 raeburn 9881: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 9882: $filepath.="/$parts[$count]";
9883: if ((-e $filepath)!=1) {
9884: mkdir($filepath,02770);
9885: }
9886: }
9887: # Check for bad extension and disallow upload
9888: if ($file=~/\.(\w+)$/ &&
9889: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
9890: $output =
1.207 bisitz 9891: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 9892: } elsif ($file=~/\.(\w+)$/ &&
9893: !defined(&Apache::loncommon::fileembstyle($1))) {
9894: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
9895: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 9896: $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 9897: } elsif (-d "$filepath/$file") {
1.195 bisitz 9898: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 9899: } else {
9900: my $source = $filepath.'/'.$file;
9901: my $logfile;
1.316 raeburn 9902: if (!open($logfile,">>",$source.'.log')) {
1.196 raeburn 9903: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 9904: }
9905: print $logfile
9906: "\n================= Publish ".localtime()." ================\n".
9907: $env{'user.name'}.':'.$env{'user.domain'}."\n";
9908: # Save the file
1.316 raeburn 9909: if (!open(FH,">",$source)) {
1.9 raeburn 9910: &Apache::lonnet::logthis('Failed to create '.$source);
9911: return (&mt('Failed to create file'));
9912: }
9913: if ($action eq 'upload') {
9914: if (!print FH ($env{'form.'.$formname})) {
9915: &Apache::lonnet::logthis('Failed to write to '.$source);
9916: return (&mt('Failed to write file'));
9917: }
9918: } else {
9919: my $original = &Apache::lonnet::filelocation('',$formname);
9920: if(!copy($original,$source)) {
9921: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
9922: return (&mt('Failed to write file'));
9923: }
9924: }
9925: close(FH);
9926: chmod(0660, $source); # Permissions to rw-rw---.
9927:
9928: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
9929: my $copyfile=$targetdir.'/'.$file;
9930:
9931: my @parts=split(/\//,$targetdir);
9932: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
9933: for (my $count=5;$count<=$#parts;$count++) {
9934: $path.="/$parts[$count]";
9935: if (!-e $path) {
9936: print $logfile "\nCreating directory ".$path;
9937: mkdir($path,02770);
9938: }
9939: }
9940: my $versionresult;
9941: if (-e $copyfile) {
9942: $versionresult = &logo_versioning($targetdir,$file,$logfile);
9943: } else {
9944: $versionresult = 'ok';
9945: }
9946: if ($versionresult eq 'ok') {
9947: if (copy($source,$copyfile)) {
9948: print $logfile "\nCopied original source to ".$copyfile."\n";
9949: $output = 'ok';
9950: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 9951: push(@{$modified_urls},[$copyfile,$source]);
9952: my $metaoutput =
9953: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
9954: unless ($registered_cleanup) {
9955: my $handlers = $r->get_handlers('PerlCleanupHandler');
9956: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
9957: $registered_cleanup=1;
9958: }
1.9 raeburn 9959: } else {
9960: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
9961: $output = &mt('Failed to copy file to RES space').", $!";
9962: }
9963: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
9964: my $inputfile = $filepath.'/'.$file;
9965: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 9966: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
9967: if ($fullwidth ne '' && $fullheight ne '') {
9968: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
9969: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316 raeburn 9970: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
9971: system({$args[0]} @args);
1.16 raeburn 9972: chmod(0660, $filepath.'/tn-'.$file);
9973: if (-e $outfile) {
9974: my $copyfile=$targetdir.'/tn-'.$file;
9975: if (copy($outfile,$copyfile)) {
9976: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 9977: my $thumb_metaoutput =
9978: &write_metadata($dom,$confname,$formname,
9979: $targetdir,'tn-'.$file,$logfile);
9980: push(@{$modified_urls},[$copyfile,$outfile]);
9981: unless ($registered_cleanup) {
9982: my $handlers = $r->get_handlers('PerlCleanupHandler');
9983: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
9984: $registered_cleanup=1;
9985: }
1.267 raeburn 9986: $madethumb = 1;
1.16 raeburn 9987: } else {
9988: print $logfile "\nUnable to write ".$copyfile.
9989: ':'.$!."\n";
9990: }
9991: }
1.9 raeburn 9992: }
9993: }
9994: }
9995: } else {
9996: $output = $versionresult;
9997: }
9998: }
1.267 raeburn 9999: return ($output,$logourl,$madethumb);
1.9 raeburn 10000: }
10001:
10002: sub logo_versioning {
10003: my ($targetdir,$file,$logfile) = @_;
10004: my $target = $targetdir.'/'.$file;
10005: my ($maxversion,$fn,$extn,$output);
10006: $maxversion = 0;
10007: if ($file =~ /^(.+)\.(\w+)$/) {
10008: $fn=$1;
10009: $extn=$2;
10010: }
10011: opendir(DIR,$targetdir);
10012: while (my $filename=readdir(DIR)) {
10013: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
10014: $maxversion=($1>$maxversion)?$1:$maxversion;
10015: }
10016: }
10017: $maxversion++;
10018: print $logfile "\nCreating old version ".$maxversion."\n";
10019: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
10020: if (copy($target,$copyfile)) {
10021: print $logfile "Copied old target to ".$copyfile."\n";
10022: $copyfile=$copyfile.'.meta';
10023: if (copy($target.'.meta',$copyfile)) {
10024: print $logfile "Copied old target metadata to ".$copyfile."\n";
10025: $output = 'ok';
10026: } else {
10027: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
10028: $output = &mt('Failed to copy old meta').", $!, ";
10029: }
10030: } else {
10031: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
10032: $output = &mt('Failed to copy old target').", $!, ";
10033: }
10034: return $output;
10035: }
10036:
10037: sub write_metadata {
10038: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
10039: my (%metadatafields,%metadatakeys,$output);
10040: $metadatafields{'title'}=$formname;
10041: $metadatafields{'creationdate'}=time;
10042: $metadatafields{'lastrevisiondate'}=time;
10043: $metadatafields{'copyright'}='public';
10044: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
10045: $env{'user.domain'};
10046: $metadatafields{'authorspace'}=$confname.':'.$dom;
10047: $metadatafields{'domain'}=$dom;
10048: {
10049: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
10050: my $mfh;
1.316 raeburn 10051: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 10052: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 10053: unless ($_=~/\./) {
10054: my $unikey=$_;
10055: $unikey=~/^([A-Za-z]+)/;
10056: my $tag=$1;
10057: $tag=~tr/A-Z/a-z/;
10058: print $mfh "\n\<$tag";
10059: foreach (split(/\,/,$metadatakeys{$unikey})) {
10060: my $value=$metadatafields{$unikey.'.'.$_};
10061: $value=~s/\"/\'\'/g;
10062: print $mfh ' '.$_.'="'.$value.'"';
10063: }
10064: print $mfh '>'.
10065: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
10066: .'</'.$tag.'>';
10067: }
10068: }
10069: $output = 'ok';
10070: print $logfile "\nWrote metadata";
10071: close($mfh);
10072: } else {
10073: print $logfile "\nFailed to open metadata file";
1.9 raeburn 10074: $output = &mt('Could not write metadata');
10075: }
10076: }
1.155 raeburn 10077: return $output;
10078: }
10079:
10080: sub notifysubscribed {
10081: foreach my $targetsource (@{$modified_urls}){
10082: next unless (ref($targetsource) eq 'ARRAY');
10083: my ($target,$source)=@{$targetsource};
10084: if ($source ne '') {
1.316 raeburn 10085: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 10086: print $logfh "\nCleanup phase: Notifications\n";
10087: my @subscribed=&subscribed_hosts($target);
10088: foreach my $subhost (@subscribed) {
10089: print $logfh "\nNotifying host ".$subhost.':';
10090: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
10091: print $logfh $reply;
10092: }
10093: my @subscribedmeta=&subscribed_hosts("$target.meta");
10094: foreach my $subhost (@subscribedmeta) {
10095: print $logfh "\nNotifying host for metadata only ".$subhost.':';
10096: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
10097: $subhost);
10098: print $logfh $reply;
10099: }
10100: print $logfh "\n============ Done ============\n";
1.160 raeburn 10101: close($logfh);
1.155 raeburn 10102: }
10103: }
10104: }
10105: return OK;
10106: }
10107:
10108: sub subscribed_hosts {
10109: my ($target) = @_;
10110: my @subscribed;
1.316 raeburn 10111: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 10112: while (my $subline=<$fh>) {
10113: if ($subline =~ /^($match_lonid):/) {
10114: my $host = $1;
10115: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
10116: unless (grep(/^\Q$host\E$/,@subscribed)) {
10117: push(@subscribed,$host);
10118: }
10119: }
10120: }
10121: }
10122: }
10123: return @subscribed;
1.9 raeburn 10124: }
10125:
10126: sub check_switchserver {
10127: my ($dom,$confname) = @_;
10128: my ($allowed,$switchserver);
10129: my $home = &Apache::lonnet::homeserver($confname,$dom);
10130: if ($home eq 'no_host') {
10131: $home = &Apache::lonnet::domain($dom,'primary');
10132: }
10133: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 10134: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
10135: if (!$allowed) {
1.180 raeburn 10136: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 10137: }
10138: return $switchserver;
10139: }
10140:
1.1 raeburn 10141: sub modify_quotas {
1.216 raeburn 10142: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 10143: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 10144: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 10145: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
10146: $validationfieldsref);
1.86 raeburn 10147: if ($action eq 'quotas') {
10148: $context = 'tools';
1.163 raeburn 10149: } else {
1.86 raeburn 10150: $context = $action;
10151: }
10152: if ($context eq 'requestcourses') {
1.325 raeburn 10153: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 10154: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 10155: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
10156: %titles = &courserequest_titles();
10157: $toolregexp = join('|',@usertools);
10158: %conditions = &courserequest_conditions();
1.216 raeburn 10159: $confname = $dom.'-domainconfig';
10160: my $servadm = $r->dir_config('lonAdmEMail');
10161: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 10162: ($validationitemsref,$validationnamesref,$validationfieldsref) =
10163: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 10164: } elsif ($context eq 'requestauthor') {
10165: @usertools = ('author');
10166: %titles = &authorrequest_titles();
1.86 raeburn 10167: } else {
1.162 raeburn 10168: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 10169: %titles = &tool_titles();
1.86 raeburn 10170: }
1.212 raeburn 10171: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 10172: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 10173: foreach my $key (keys(%env)) {
1.101 raeburn 10174: if ($context eq 'requestcourses') {
10175: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
10176: my $item = $1;
10177: my $type = $2;
10178: if ($type =~ /^limit_(.+)/) {
10179: $limithash{$item}{$1} = $env{$key};
10180: } else {
10181: $confhash{$item}{$type} = $env{$key};
10182: }
10183: }
1.163 raeburn 10184: } elsif ($context eq 'requestauthor') {
10185: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
10186: $confhash{$1} = $env{$key};
10187: }
1.101 raeburn 10188: } else {
1.86 raeburn 10189: if ($key =~ /^form\.quota_(.+)$/) {
10190: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 10191: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
10192: $confhash{'authorquota'}{$1} = $env{$key};
10193: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 10194: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
10195: }
1.72 raeburn 10196: }
10197: }
1.163 raeburn 10198: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 10199: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 10200: @approvalnotify = sort(@approvalnotify);
10201: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 10202: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 10203: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
10204: foreach my $type (@hasuniquecode) {
10205: if (grep(/^\Q$type\E$/,@crstypes)) {
10206: $confhash{'uniquecode'}{$type} = 1;
10207: }
1.216 raeburn 10208: }
1.242 raeburn 10209: my (%newbook,%allpos);
1.216 raeburn 10210: if ($context eq 'requestcourses') {
1.242 raeburn 10211: foreach my $type ('textbooks','templates') {
10212: @{$allpos{$type}} = ();
10213: my $invalid;
10214: if ($type eq 'textbooks') {
10215: $invalid = &mt('Invalid LON-CAPA course for textbook');
10216: } else {
10217: $invalid = &mt('Invalid LON-CAPA course for template');
10218: }
10219: if ($env{'form.'.$type.'_addbook'}) {
10220: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
10221: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
10222: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
10223: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
10224: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
10225: } else {
10226: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
10227: my $position = $env{'form.'.$type.'_addbook_pos'};
10228: $position =~ s/\D+//g;
10229: if ($position ne '') {
10230: $allpos{$type}[$position] = $newbook{$type};
10231: }
1.216 raeburn 10232: }
1.242 raeburn 10233: } else {
10234: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 10235: }
10236: }
1.242 raeburn 10237: }
1.216 raeburn 10238: }
1.102 raeburn 10239: if (ref($domconfig{$action}) eq 'HASH') {
10240: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
10241: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
10242: $changes{'notify'}{'approval'} = 1;
10243: }
10244: } else {
1.144 raeburn 10245: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10246: $changes{'notify'}{'approval'} = 1;
10247: }
10248: }
1.218 raeburn 10249: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
10250: if (ref($confhash{'uniquecode'}) eq 'HASH') {
10251: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
10252: unless ($confhash{'uniquecode'}{$crstype}) {
10253: $changes{'uniquecode'} = 1;
10254: }
10255: }
10256: unless ($changes{'uniquecode'}) {
10257: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
10258: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
10259: $changes{'uniquecode'} = 1;
10260: }
10261: }
10262: }
10263: } else {
10264: $changes{'uniquecode'} = 1;
10265: }
10266: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
10267: $changes{'uniquecode'} = 1;
1.216 raeburn 10268: }
10269: if ($context eq 'requestcourses') {
1.242 raeburn 10270: foreach my $type ('textbooks','templates') {
10271: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10272: my %deletions;
10273: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
10274: if (@todelete) {
10275: map { $deletions{$_} = 1; } @todelete;
10276: }
10277: my %imgdeletions;
10278: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
10279: if (@todeleteimages) {
10280: map { $imgdeletions{$_} = 1; } @todeleteimages;
10281: }
10282: my $maxnum = $env{'form.'.$type.'_maxnum'};
10283: for (my $i=0; $i<=$maxnum; $i++) {
10284: my $itemid = $env{'form.'.$type.'_id_'.$i};
10285: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
10286: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
10287: if ($deletions{$key}) {
10288: if ($domconfig{$action}{$type}{$key}{'image'}) {
10289: #FIXME need to obsolete item in RES space
10290: }
10291: next;
10292: } else {
10293: my $newpos = $env{'form.'.$itemid};
10294: $newpos =~ s/\D+//g;
1.243 raeburn 10295: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 10296: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 10297: ($type eq 'templates'));
1.242 raeburn 10298: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
10299: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
10300: $changes{$type}{$key} = 1;
10301: }
10302: }
10303: $allpos{$type}[$newpos] = $key;
10304: }
10305: if ($imgdeletions{$key}) {
10306: $changes{$type}{$key} = 1;
1.216 raeburn 10307: #FIXME need to obsolete item in RES space
1.242 raeburn 10308: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
10309: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 10310: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10311: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10312: } else {
10313: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
10314: $cdom,$cnum,$type,$configuserok,
10315: $switchserver,$author_ok);
10316: if ($imgurl) {
10317: $confhash{$type}{$key}{'image'} = $imgurl;
10318: $changes{$type}{$key} = 1;
10319: }
10320: if ($error) {
10321: &Apache::lonnet::logthis($error);
10322: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10323: }
10324: }
1.242 raeburn 10325: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
10326: $confhash{$type}{$key}{'image'} =
10327: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 10328: }
10329: }
10330: }
10331: }
10332: }
10333: }
1.102 raeburn 10334: } else {
1.144 raeburn 10335: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 10336: $changes{'notify'}{'approval'} = 1;
10337: }
1.218 raeburn 10338: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 10339: $changes{'uniquecode'} = 1;
10340: }
10341: }
10342: if ($context eq 'requestcourses') {
1.242 raeburn 10343: foreach my $type ('textbooks','templates') {
10344: if ($newbook{$type}) {
10345: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 10346: foreach my $item ('subject','title','publisher','author') {
10347: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10348: ($type eq 'template'));
1.242 raeburn 10349: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
10350: if ($env{'form.'.$type.'_addbook_'.$item}) {
10351: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
10352: }
10353: }
10354: if ($type eq 'textbooks') {
10355: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
10356: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 10357: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
10358: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
10359: } else {
10360: my ($imageurl,$error) =
10361: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
10362: $configuserok,$switchserver,$author_ok);
10363: if ($imageurl) {
10364: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
10365: }
10366: if ($error) {
10367: &Apache::lonnet::logthis($error);
10368: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10369: }
1.242 raeburn 10370: }
10371: }
1.216 raeburn 10372: }
10373: }
1.242 raeburn 10374: if (@{$allpos{$type}} > 0) {
10375: my $idx = 0;
10376: foreach my $item (@{$allpos{$type}}) {
10377: if ($item ne '') {
10378: $confhash{$type}{$item}{'order'} = $idx;
10379: if (ref($domconfig{$action}) eq 'HASH') {
10380: if (ref($domconfig{$action}{$type}) eq 'HASH') {
10381: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
10382: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
10383: $changes{$type}{$item} = 1;
10384: }
1.216 raeburn 10385: }
10386: }
10387: }
1.242 raeburn 10388: $idx ++;
1.216 raeburn 10389: }
10390: }
10391: }
10392: }
1.235 raeburn 10393: if (ref($validationitemsref) eq 'ARRAY') {
10394: foreach my $item (@{$validationitemsref}) {
10395: if ($item eq 'fields') {
10396: my @changed;
10397: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
10398: if (@{$confhash{'validation'}{$item}} > 0) {
10399: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
10400: }
1.266 raeburn 10401: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10402: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10403: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
10404: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
10405: $domconfig{'requestcourses'}{'validation'}{$item});
10406: } else {
10407: @changed = @{$confhash{'validation'}{$item}};
10408: }
1.235 raeburn 10409: } else {
10410: @changed = @{$confhash{'validation'}{$item}};
10411: }
10412: } else {
10413: @changed = @{$confhash{'validation'}{$item}};
10414: }
10415: if (@changed) {
10416: if ($confhash{'validation'}{$item}) {
10417: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
10418: } else {
10419: $changes{'validation'}{$item} = &mt('None');
10420: }
10421: }
10422: } else {
10423: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
10424: if ($item eq 'markup') {
10425: if ($env{'form.requestcourses_validation_'.$item}) {
10426: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10427: }
10428: }
1.266 raeburn 10429: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10430: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10431: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
10432: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10433: }
10434: } else {
10435: if ($confhash{'validation'}{$item} ne '') {
10436: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10437: }
1.235 raeburn 10438: }
10439: } else {
10440: if ($confhash{'validation'}{$item} ne '') {
10441: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
10442: }
10443: }
10444: }
10445: }
10446: }
10447: if ($env{'form.validationdc'}) {
10448: my $newval = $env{'form.validationdc'};
1.285 raeburn 10449: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 10450: if (exists($domcoords{$newval})) {
10451: $confhash{'validation'}{'dc'} = $newval;
10452: }
10453: }
10454: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 10455: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10456: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10457: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10458: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
10459: if ($confhash{'validation'}{'dc'} eq '') {
10460: $changes{'validation'}{'dc'} = &mt('None');
10461: } else {
10462: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10463: }
1.235 raeburn 10464: }
1.266 raeburn 10465: } elsif ($confhash{'validation'}{'dc'} ne '') {
10466: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 10467: }
10468: } elsif ($confhash{'validation'}{'dc'} ne '') {
10469: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
10470: }
10471: } elsif ($confhash{'validation'}{'dc'} ne '') {
10472: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 10473: }
1.266 raeburn 10474: } else {
10475: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
10476: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
10477: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
10478: $changes{'validation'}{'dc'} = &mt('None');
10479: }
10480: }
1.235 raeburn 10481: }
10482: }
1.102 raeburn 10483: }
10484: } else {
1.86 raeburn 10485: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 10486: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 10487: }
1.72 raeburn 10488: foreach my $item (@usertools) {
10489: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 10490: my $unset;
1.101 raeburn 10491: if ($context eq 'requestcourses') {
1.104 raeburn 10492: $unset = '0';
10493: if ($type eq '_LC_adv') {
10494: $unset = '';
10495: }
1.101 raeburn 10496: if ($confhash{$item}{$type} eq 'autolimit') {
10497: $confhash{$item}{$type} .= '=';
10498: unless ($limithash{$item}{$type} =~ /\D/) {
10499: $confhash{$item}{$type} .= $limithash{$item}{$type};
10500: }
10501: }
1.163 raeburn 10502: } elsif ($context eq 'requestauthor') {
10503: $unset = '0';
10504: if ($type eq '_LC_adv') {
10505: $unset = '';
10506: }
1.72 raeburn 10507: } else {
1.101 raeburn 10508: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
10509: $confhash{$item}{$type} = 1;
10510: } else {
10511: $confhash{$item}{$type} = 0;
10512: }
1.72 raeburn 10513: }
1.86 raeburn 10514: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 10515: if ($action eq 'requestauthor') {
10516: if ($domconfig{$action}{$type} ne $confhash{$type}) {
10517: $changes{$type} = 1;
10518: }
10519: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 10520: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
10521: $changes{$item}{$type} = 1;
10522: }
10523: } else {
10524: if ($context eq 'requestcourses') {
1.104 raeburn 10525: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 10526: $changes{$item}{$type} = 1;
10527: }
10528: } else {
10529: if (!$confhash{$item}{$type}) {
10530: $changes{$item}{$type} = 1;
10531: }
10532: }
10533: }
10534: } else {
10535: if ($context eq 'requestcourses') {
1.104 raeburn 10536: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 10537: $changes{$item}{$type} = 1;
10538: }
1.163 raeburn 10539: } elsif ($context eq 'requestauthor') {
10540: if ($confhash{$type} ne $unset) {
10541: $changes{$type} = 1;
10542: }
1.72 raeburn 10543: } else {
10544: if (!$confhash{$item}{$type}) {
10545: $changes{$item}{$type} = 1;
10546: }
10547: }
10548: }
1.1 raeburn 10549: }
10550: }
1.163 raeburn 10551: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 10552: if (ref($domconfig{'quotas'}) eq 'HASH') {
10553: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
10554: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
10555: if (exists($confhash{'defaultquota'}{$key})) {
10556: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
10557: $changes{'defaultquota'}{$key} = 1;
10558: }
10559: } else {
10560: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 10561: }
10562: }
1.86 raeburn 10563: } else {
10564: foreach my $key (keys(%{$domconfig{'quotas'}})) {
10565: if (exists($confhash{'defaultquota'}{$key})) {
10566: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
10567: $changes{'defaultquota'}{$key} = 1;
10568: }
10569: } else {
10570: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 10571: }
1.1 raeburn 10572: }
10573: }
1.197 raeburn 10574: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
10575: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
10576: if (exists($confhash{'authorquota'}{$key})) {
10577: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
10578: $changes{'authorquota'}{$key} = 1;
10579: }
10580: } else {
10581: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
10582: }
10583: }
10584: }
1.1 raeburn 10585: }
1.86 raeburn 10586: if (ref($confhash{'defaultquota'}) eq 'HASH') {
10587: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
10588: if (ref($domconfig{'quotas'}) eq 'HASH') {
10589: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
10590: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
10591: $changes{'defaultquota'}{$key} = 1;
10592: }
10593: } else {
10594: if (!exists($domconfig{'quotas'}{$key})) {
10595: $changes{'defaultquota'}{$key} = 1;
10596: }
1.72 raeburn 10597: }
10598: } else {
1.86 raeburn 10599: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 10600: }
1.1 raeburn 10601: }
10602: }
1.197 raeburn 10603: if (ref($confhash{'authorquota'}) eq 'HASH') {
10604: foreach my $key (keys(%{$confhash{'authorquota'}})) {
10605: if (ref($domconfig{'quotas'}) eq 'HASH') {
10606: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
10607: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
10608: $changes{'authorquota'}{$key} = 1;
10609: }
10610: } else {
10611: $changes{'authorquota'}{$key} = 1;
10612: }
10613: } else {
10614: $changes{'authorquota'}{$key} = 1;
10615: }
10616: }
10617: }
1.1 raeburn 10618: }
1.72 raeburn 10619:
1.163 raeburn 10620: if ($context eq 'requestauthor') {
10621: $domdefaults{'requestauthor'} = \%confhash;
10622: } else {
10623: foreach my $key (keys(%confhash)) {
1.242 raeburn 10624: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 10625: $domdefaults{$key} = $confhash{$key};
10626: }
1.163 raeburn 10627: }
1.72 raeburn 10628: }
1.163 raeburn 10629:
1.1 raeburn 10630: my %quotahash = (
1.86 raeburn 10631: $action => { %confhash }
1.1 raeburn 10632: );
10633: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
10634: $dom);
10635: if ($putresult eq 'ok') {
10636: if (keys(%changes) > 0) {
1.72 raeburn 10637: my $cachetime = 24*60*60;
10638: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 10639: if (ref($lastactref) eq 'HASH') {
10640: $lastactref->{'domdefaults'} = 1;
10641: }
1.1 raeburn 10642: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 10643: unless (($context eq 'requestcourses') ||
1.163 raeburn 10644: ($context eq 'requestauthor')) {
1.86 raeburn 10645: if (ref($changes{'defaultquota'}) eq 'HASH') {
10646: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
10647: foreach my $type (@{$types},'default') {
10648: if (defined($changes{'defaultquota'}{$type})) {
10649: my $typetitle = $usertypes->{$type};
10650: if ($type eq 'default') {
10651: $typetitle = $othertitle;
10652: }
1.213 raeburn 10653: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 10654: }
10655: }
1.86 raeburn 10656: $resulttext .= '</ul></li>';
1.72 raeburn 10657: }
1.197 raeburn 10658: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 10659: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 10660: foreach my $type (@{$types},'default') {
10661: if (defined($changes{'authorquota'}{$type})) {
10662: my $typetitle = $usertypes->{$type};
10663: if ($type eq 'default') {
10664: $typetitle = $othertitle;
10665: }
1.213 raeburn 10666: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 10667: }
10668: }
10669: $resulttext .= '</ul></li>';
10670: }
1.72 raeburn 10671: }
1.80 raeburn 10672: my %newenv;
1.72 raeburn 10673: foreach my $item (@usertools) {
1.163 raeburn 10674: my (%haschgs,%inconf);
10675: if ($context eq 'requestauthor') {
10676: %haschgs = %changes;
1.210 raeburn 10677: %inconf = %confhash;
1.163 raeburn 10678: } else {
10679: if (ref($changes{$item}) eq 'HASH') {
10680: %haschgs = %{$changes{$item}};
10681: }
10682: if (ref($confhash{$item}) eq 'HASH') {
10683: %inconf = %{$confhash{$item}};
10684: }
10685: }
10686: if (keys(%haschgs) > 0) {
1.80 raeburn 10687: my $newacc =
10688: &Apache::lonnet::usertools_access($env{'user.name'},
10689: $env{'user.domain'},
1.86 raeburn 10690: $item,'reload',$context);
1.210 raeburn 10691: if (($context eq 'requestcourses') ||
1.163 raeburn 10692: ($context eq 'requestauthor')) {
1.108 raeburn 10693: if ($env{'environment.canrequest.'.$item} ne $newacc) {
10694: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 10695: }
10696: } else {
10697: if ($env{'environment.availabletools.'.$item} ne $newacc) {
10698: $newenv{'environment.availabletools.'.$item} = $newacc;
10699: }
1.80 raeburn 10700: }
1.163 raeburn 10701: unless ($context eq 'requestauthor') {
10702: $resulttext .= '<li>'.$titles{$item}.'<ul>';
10703: }
1.72 raeburn 10704: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 10705: if ($haschgs{$type}) {
1.72 raeburn 10706: my $typetitle = $usertypes->{$type};
10707: if ($type eq 'default') {
10708: $typetitle = $othertitle;
10709: } elsif ($type eq '_LC_adv') {
10710: $typetitle = 'LON-CAPA Advanced Users';
10711: }
1.163 raeburn 10712: if ($inconf{$type}) {
1.101 raeburn 10713: if ($context eq 'requestcourses') {
10714: my $cond;
1.163 raeburn 10715: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 10716: if ($1 eq '') {
10717: $cond = &mt('(Automatic processing of any request).');
10718: } else {
10719: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
10720: }
10721: } else {
1.163 raeburn 10722: $cond = $conditions{$inconf{$type}};
1.101 raeburn 10723: }
10724: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 10725: } elsif ($context eq 'requestauthor') {
10726: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
10727: $titles{$inconf{$type}},$typetitle);
10728:
1.101 raeburn 10729: } else {
10730: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
10731: }
1.72 raeburn 10732: } else {
1.104 raeburn 10733: if ($type eq '_LC_adv') {
1.163 raeburn 10734: if ($inconf{$type} eq '0') {
1.104 raeburn 10735: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
10736: } else {
10737: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
10738: }
10739: } else {
10740: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
10741: }
1.72 raeburn 10742: }
10743: }
1.26 raeburn 10744: }
1.163 raeburn 10745: unless ($context eq 'requestauthor') {
10746: $resulttext .= '</ul></li>';
10747: }
1.26 raeburn 10748: }
1.1 raeburn 10749: }
1.163 raeburn 10750: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 10751: if (ref($changes{'notify'}) eq 'HASH') {
10752: if ($changes{'notify'}{'approval'}) {
10753: if (ref($confhash{'notify'}) eq 'HASH') {
10754: if ($confhash{'notify'}{'approval'}) {
10755: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
10756: } else {
1.163 raeburn 10757: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 10758: }
10759: }
10760: }
10761: }
10762: }
1.216 raeburn 10763: if ($action eq 'requestcourses') {
10764: my @offon = ('off','on');
10765: if ($changes{'uniquecode'}) {
1.218 raeburn 10766: if (ref($confhash{'uniquecode'}) eq 'HASH') {
10767: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
10768: $resulttext .= '<li>'.
10769: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
10770: '</li>';
10771: } else {
10772: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
10773: '</li>';
10774: }
1.216 raeburn 10775: }
1.242 raeburn 10776: foreach my $type ('textbooks','templates') {
10777: if (ref($changes{$type}) eq 'HASH') {
10778: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
10779: foreach my $key (sort(keys(%{$changes{$type}}))) {
10780: my %coursehash = &Apache::lonnet::coursedescription($key);
10781: my $coursetitle = $coursehash{'description'};
10782: my $position = $confhash{$type}{$key}{'order'} + 1;
10783: $resulttext .= '<li>';
1.243 raeburn 10784: foreach my $item ('subject','title','publisher','author') {
10785: next if ((($item eq 'author') || ($item eq 'publisher')) &&
10786: ($type eq 'templates'));
1.242 raeburn 10787: my $name = $item.':';
10788: $name =~ s/^(\w)/\U$1/;
10789: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
10790: }
10791: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
10792: if ($type eq 'textbooks') {
10793: if ($confhash{$type}{$key}{'image'}) {
10794: $resulttext .= ' '.&mt('Image: [_1]',
10795: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
10796: ' alt="Textbook cover" />').'<br />';
10797: }
10798: }
10799: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 10800: }
1.242 raeburn 10801: $resulttext .= '</ul></li>';
1.216 raeburn 10802: }
10803: }
1.235 raeburn 10804: if (ref($changes{'validation'}) eq 'HASH') {
10805: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
10806: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
10807: foreach my $item (@{$validationitemsref}) {
10808: if (exists($changes{'validation'}{$item})) {
10809: if ($item eq 'markup') {
10810: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
10811: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
10812: } else {
10813: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
10814: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
10815: }
10816: }
10817: }
10818: if (exists($changes{'validation'}{'dc'})) {
10819: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
10820: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
10821: }
10822: }
10823: }
1.216 raeburn 10824: }
1.1 raeburn 10825: $resulttext .= '</ul>';
1.80 raeburn 10826: if (keys(%newenv)) {
10827: &Apache::lonnet::appenv(\%newenv);
10828: }
1.1 raeburn 10829: } else {
1.86 raeburn 10830: if ($context eq 'requestcourses') {
10831: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 10832: } elsif ($context eq 'requestauthor') {
10833: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 10834: } else {
1.90 weissno 10835: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 10836: }
1.1 raeburn 10837: }
10838: } else {
1.11 albertel 10839: $resulttext = '<span class="LC_error">'.
10840: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10841: }
1.216 raeburn 10842: if ($errors) {
10843: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
10844: '<ul>'.$errors.'</ul></p>';
10845: }
1.3 raeburn 10846: return $resulttext;
1.1 raeburn 10847: }
10848:
1.216 raeburn 10849: sub process_textbook_image {
1.242 raeburn 10850: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 10851: my $filename = $env{'form.'.$caller.'.filename'};
10852: my ($error,$url);
10853: my ($width,$height) = (50,50);
10854: if ($configuserok eq 'ok') {
10855: if ($switchserver) {
10856: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
10857: $switchserver);
10858: } elsif ($author_ok eq 'ok') {
10859: my ($result,$imageurl) =
10860: &publishlogo($r,'upload',$caller,$dom,$confname,
1.312 raeburn 10861: "$type/$cdom/$cnum/cover",$width,$height);
1.216 raeburn 10862: if ($result eq 'ok') {
10863: $url = $imageurl;
10864: } else {
10865: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
10866: }
10867: } else {
10868: $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);
10869: }
10870: } else {
10871: $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);
10872: }
10873: return ($url,$error);
10874: }
10875:
1.267 raeburn 10876: sub modify_ltitools {
10877: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
10878: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 10879: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 10880: my $confname = $dom.'-domainconfig';
10881: my $servadm = $r->dir_config('lonAdmEMail');
10882: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10883: my (%posslti,%possfield);
10884: my @courseroles = ('cc','in','ta','ep','st');
10885: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
10886: map { $posslti{$_} = 1; } @ltiroles;
10887: my @allfields = ('fullname','firstname','lastname','email','user','roles');
10888: map { $possfield{$_} = 1; } @allfields;
10889: my %lt = <itools_names();
10890: if ($env{'form.ltitools_add'}) {
10891: my $title = $env{'form.ltitools_add_title'};
10892: $title =~ s/(`)/'/g;
10893: ($newid,my $error) = &get_ltitools_id($dom,$title);
10894: if ($newid) {
10895: my $position = $env{'form.ltitools_add_pos'};
10896: $position =~ s/\D+//g;
10897: if ($position ne '') {
10898: $allpos[$position] = $newid;
10899: }
10900: $changes{$newid} = 1;
1.322 raeburn 10901: foreach my $item ('title','url','key','secret','lifetime') {
1.267 raeburn 10902: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1.322 raeburn 10903: if ($item eq 'lifetime') {
10904: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
10905: }
1.267 raeburn 10906: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 10907: if (($item eq 'key') || ($item eq 'secret')) {
10908: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
10909: } else {
10910: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
10911: }
1.267 raeburn 10912: }
10913: }
10914: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
10915: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
10916: }
10917: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
10918: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
10919: }
1.323 raeburn 10920: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
10921: $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
10922: } else {
10923: $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
10924: }
1.296 raeburn 10925: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 10926: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
10927: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 10928: if (($item eq 'width') || ($item eq 'height')) {
10929: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
10930: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
10931: }
10932: } else {
10933: if ($env{'form.ltitools_add_'.$item} ne '') {
10934: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
10935: }
1.267 raeburn 10936: }
10937: }
10938: if ($env{'form.ltitools_add_target'} eq 'window') {
10939: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 10940: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
10941: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 10942: } else {
10943: $confhash{$newid}{'display'}{'target'} = 'iframe';
10944: }
10945: foreach my $item ('passback','roster') {
1.319 raeburn 10946: if ($env{'form.ltitools_'.$item.'_add'}) {
1.267 raeburn 10947: $confhash{$newid}{$item} = 1;
1.319 raeburn 10948: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
10949: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
10950: $lifetime =~ s/^\s+|\s+$//g;
10951: if ($lifetime =~ /^\d+\.?\d*$/) {
10952: $confhash{$newid}{$item.'valid'} = $lifetime;
10953: }
10954: }
1.267 raeburn 10955: }
10956: }
10957: if ($env{'form.ltitools_add_image.filename'} ne '') {
10958: my ($imageurl,$error) =
1.307 raeburn 10959: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267 raeburn 10960: $configuserok,$switchserver,$author_ok);
10961: if ($imageurl) {
10962: $confhash{$newid}{'image'} = $imageurl;
10963: }
10964: if ($error) {
10965: &Apache::lonnet::logthis($error);
10966: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10967: }
10968: }
10969: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
10970: foreach my $field (@fields) {
10971: if ($possfield{$field}) {
10972: if ($field eq 'roles') {
10973: foreach my $role (@courseroles) {
10974: my $choice = $env{'form.ltitools_add_roles_'.$role};
10975: if (($choice ne '') && ($posslti{$choice})) {
10976: $confhash{$newid}{'roles'}{$role} = $choice;
10977: if ($role eq 'cc') {
10978: $confhash{$newid}{'roles'}{'co'} = $choice;
10979: }
10980: }
10981: }
10982: } else {
10983: $confhash{$newid}{'fields'}{$field} = 1;
10984: }
10985: }
10986: }
1.324 raeburn 10987: if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
10988: if ($confhash{$newid}{'fields'}{'user'}) {
10989: if ($env{'form.ltitools_userincdom_add'}) {
10990: $confhash{$newid}{'incdom'} = 1;
10991: }
10992: }
10993: }
1.273 raeburn 10994: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
10995: foreach my $item (@courseconfig) {
10996: $confhash{$newid}{'crsconf'}{$item} = 1;
10997: }
1.267 raeburn 10998: if ($env{'form.ltitools_add_custom'}) {
10999: my $name = $env{'form.ltitools_add_custom_name'};
11000: my $value = $env{'form.ltitools_add_custom_value'};
11001: $value =~ s/(`)/'/g;
11002: $name =~ s/(`)/'/g;
11003: $confhash{$newid}{'custom'}{$name} = $value;
11004: }
11005: } else {
11006: my $error = &mt('Failed to acquire unique ID for new external tool');
11007: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11008: }
11009: }
11010: if (ref($domconfig{$action}) eq 'HASH') {
11011: my %deletions;
11012: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
11013: if (@todelete) {
11014: map { $deletions{$_} = 1; } @todelete;
11015: }
11016: my %customadds;
11017: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
11018: if (@newcustom) {
11019: map { $customadds{$_} = 1; } @newcustom;
11020: }
11021: my %imgdeletions;
11022: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
11023: if (@todeleteimages) {
11024: map { $imgdeletions{$_} = 1; } @todeleteimages;
11025: }
11026: my $maxnum = $env{'form.ltitools_maxnum'};
11027: for (my $i=0; $i<=$maxnum; $i++) {
11028: my $itemid = $env{'form.ltitools_id_'.$i};
1.308 raeburn 11029: $itemid =~ s/\D+//g;
1.267 raeburn 11030: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11031: if ($deletions{$itemid}) {
11032: if ($domconfig{$action}{$itemid}{'image'}) {
11033: #FIXME need to obsolete item in RES space
11034: }
11035: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
11036: next;
11037: } else {
11038: my $newpos = $env{'form.ltitools_'.$itemid};
11039: $newpos =~ s/\D+//g;
1.322 raeburn 11040: foreach my $item ('title','url','lifetime') {
1.267 raeburn 11041: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
11042: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
11043: $changes{$itemid} = 1;
11044: }
11045: }
1.297 raeburn 11046: foreach my $item ('key','secret') {
11047: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
11048: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
11049: $changes{$itemid} = 1;
11050: }
11051: }
1.267 raeburn 11052: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
11053: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
11054: }
11055: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
11056: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
11057: }
1.323 raeburn 11058: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
11059: $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
11060: } else {
11061: $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
11062: }
11063: if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
11064: if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
11065: $changes{$itemid} = 1;
11066: }
11067: } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
11068: $changes{$itemid} = 1;
11069: }
1.267 raeburn 11070: foreach my $size ('width','height') {
11071: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
11072: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
11073: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
11074: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
11075: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11076: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
11077: $changes{$itemid} = 1;
11078: }
11079: } else {
11080: $changes{$itemid} = 1;
11081: }
1.296 raeburn 11082: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11083: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
11084: $changes{$itemid} = 1;
11085: }
11086: }
11087: }
11088: foreach my $item ('linktext','explanation') {
11089: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
11090: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
11091: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
11092: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
11093: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11094: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
11095: $changes{$itemid} = 1;
11096: }
11097: } else {
11098: $changes{$itemid} = 1;
11099: }
11100: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11101: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
11102: $changes{$itemid} = 1;
11103: }
1.267 raeburn 11104: }
11105: }
11106: if ($env{'form.ltitools_target_'.$i} eq 'window') {
11107: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 11108: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
11109: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 11110: } else {
11111: $confhash{$itemid}{'display'}{'target'} = 'iframe';
11112: }
11113: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11114: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
11115: $changes{$itemid} = 1;
11116: }
11117: } else {
11118: $changes{$itemid} = 1;
11119: }
11120: foreach my $extra ('passback','roster') {
11121: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
11122: $confhash{$itemid}{$extra} = 1;
1.319 raeburn 11123: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
11124: my $lifetime = $env{'form.ltitools_'.$extra.'valid_add'};
11125: $lifetime =~ s/^\s+|\s+$//g;
11126: if ($lifetime =~ /^\d+\.?\d*$/) {
11127: $confhash{$itemid}{$extra.'valid'} = $lifetime;
11128: }
11129: }
1.267 raeburn 11130: }
11131: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
11132: $changes{$itemid} = 1;
11133: }
1.319 raeburn 11134: if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
11135: $changes{$itemid} = 1;
11136: }
1.267 raeburn 11137: }
1.273 raeburn 11138: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318 raeburn 11139: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 11140: if (grep(/^\Q$item\E$/,@courseconfig)) {
11141: $confhash{$itemid}{'crsconf'}{$item} = 1;
11142: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
11143: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
11144: $changes{$itemid} = 1;
11145: }
11146: } else {
11147: $changes{$itemid} = 1;
11148: }
11149: }
11150: }
1.267 raeburn 11151: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
11152: foreach my $field (@fields) {
11153: if ($possfield{$field}) {
11154: if ($field eq 'roles') {
11155: foreach my $role (@courseroles) {
11156: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
11157: if (($choice ne '') && ($posslti{$choice})) {
11158: $confhash{$itemid}{'roles'}{$role} = $choice;
11159: if ($role eq 'cc') {
11160: $confhash{$itemid}{'roles'}{'co'} = $choice;
11161: }
11162: }
11163: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
11164: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
11165: $changes{$itemid} = 1;
11166: }
11167: } elsif ($confhash{$itemid}{'roles'}{$role}) {
11168: $changes{$itemid} = 1;
11169: }
11170: }
11171: } else {
11172: $confhash{$itemid}{'fields'}{$field} = 1;
11173: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
11174: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
11175: $changes{$itemid} = 1;
11176: }
11177: } else {
11178: $changes{$itemid} = 1;
11179: }
11180: }
11181: }
11182: }
1.324 raeburn 11183: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
11184: if ($confhash{$itemid}{'fields'}{'user'}) {
11185: if ($env{'form.ltitools_userincdom_'.$i}) {
11186: $confhash{$itemid}{'incdom'} = 1;
11187: }
11188: if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
11189: $changes{$itemid} = 1;
11190: }
11191: }
11192: }
1.267 raeburn 11193: $allpos[$newpos] = $itemid;
11194: }
11195: if ($imgdeletions{$itemid}) {
11196: $changes{$itemid} = 1;
11197: #FIXME need to obsolete item in RES space
11198: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
11199: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
11200: $itemid,$configuserok,$switchserver,
11201: $author_ok);
11202: if ($imgurl) {
11203: $confhash{$itemid}{'image'} = $imgurl;
11204: $changes{$itemid} = 1;
11205: }
11206: if ($error) {
11207: &Apache::lonnet::logthis($error);
11208: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11209: }
11210: } elsif ($domconfig{$action}{$itemid}{'image'}) {
11211: $confhash{$itemid}{'image'} =
11212: $domconfig{$action}{$itemid}{'image'};
11213: }
11214: if ($customadds{$i}) {
11215: my $name = $env{'form.ltitools_custom_name_'.$i};
11216: $name =~ s/(`)/'/g;
11217: $name =~ s/^\s+//;
11218: $name =~ s/\s+$//;
11219: my $value = $env{'form.ltitools_custom_value_'.$i};
11220: $value =~ s/(`)/'/g;
11221: $value =~ s/^\s+//;
11222: $value =~ s/\s+$//;
11223: if ($name ne '') {
11224: $confhash{$itemid}{'custom'}{$name} = $value;
11225: $changes{$itemid} = 1;
11226: }
11227: }
11228: my %customdels;
11229: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
11230: if (@customdeletions) {
11231: $changes{$itemid} = 1;
11232: }
11233: map { $customdels{$_} = 1; } @customdeletions;
11234: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
11235: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
11236: unless ($customdels{$key}) {
11237: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
11238: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
11239: }
11240: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
11241: $changes{$itemid} = 1;
11242: }
11243: }
11244: }
11245: }
11246: unless ($changes{$itemid}) {
11247: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
11248: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
11249: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
11250: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
11251: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
11252: $changes{$itemid} = 1;
11253: last;
11254: }
11255: }
11256: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
11257: $changes{$itemid} = 1;
11258: }
11259: }
11260: last if ($changes{$itemid});
11261: }
11262: }
11263: }
11264: }
11265: }
11266: if (@allpos > 0) {
11267: my $idx = 0;
11268: foreach my $itemid (@allpos) {
11269: if ($itemid ne '') {
11270: $confhash{$itemid}{'order'} = $idx;
11271: if (ref($domconfig{$action}) eq 'HASH') {
11272: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11273: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
11274: $changes{$itemid} = 1;
11275: }
11276: }
11277: }
11278: $idx ++;
11279: }
11280: }
11281: }
11282: my %ltitoolshash = (
11283: $action => { %confhash }
11284: );
11285: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
11286: $dom);
11287: if ($putresult eq 'ok') {
1.297 raeburn 11288: my %ltienchash = (
11289: $action => { %encconfig }
11290: );
11291: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
1.267 raeburn 11292: if (keys(%changes) > 0) {
11293: my $cachetime = 24*60*60;
1.297 raeburn 11294: my %ltiall = %confhash;
11295: foreach my $id (keys(%ltiall)) {
11296: if (ref($encconfig{$id}) eq 'HASH') {
11297: foreach my $item ('key','secret') {
11298: $ltiall{$id}{$item} = $encconfig{$id}{$item};
11299: }
11300: }
11301: }
11302: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 11303: if (ref($lastactref) eq 'HASH') {
11304: $lastactref->{'ltitools'} = 1;
11305: }
11306: $resulttext = &mt('Changes made:').'<ul>';
11307: my %bynum;
11308: foreach my $itemid (sort(keys(%changes))) {
11309: my $position = $confhash{$itemid}{'order'};
11310: $bynum{$position} = $itemid;
11311: }
11312: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
11313: my $itemid = $bynum{$pos};
11314: if (ref($confhash{$itemid}) ne 'HASH') {
11315: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
11316: } else {
11317: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
11318: if ($confhash{$itemid}{'image'}) {
11319: $resulttext .= ' '.
11320: '<img src="'.$confhash{$itemid}{'image'}.'"'.
11321: ' alt="'.&mt('Tool Provider icon').'" />';
11322: }
11323: $resulttext .= '</li><ul>';
11324: my $position = $pos + 1;
11325: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.323 raeburn 11326: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1.267 raeburn 11327: if ($confhash{$itemid}{$item} ne '') {
11328: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
11329: }
11330: }
1.297 raeburn 11331: if ($encconfig{$itemid}{'key'} ne '') {
11332: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
11333: }
11334: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 11335: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 11336: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 11337: $resulttext .= ('*'x$num).'</li>';
11338: }
1.273 raeburn 11339: $resulttext .= '<li>'.&mt('Configurable in course:');
1.318 raeburn 11340: my @possconfig = ('label','title','target','linktext','explanation','append');
1.273 raeburn 11341: my $numconfig = 0;
11342: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
11343: foreach my $item (@possconfig) {
11344: if ($confhash{$itemid}{'crsconf'}{$item}) {
11345: $numconfig ++;
1.296 raeburn 11346: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 11347: }
11348: }
11349: }
11350: if (!$numconfig) {
11351: $resulttext .= &mt('None');
11352: }
11353: $resulttext .= '</li>';
1.267 raeburn 11354: foreach my $item ('passback','roster') {
11355: $resulttext .= '<li>'.$lt{$item}.' ';
11356: if ($confhash{$itemid}{$item}) {
11357: $resulttext .= &mt('Yes');
1.319 raeburn 11358: if ($confhash{$itemid}{$item.'valid'}) {
11359: if ($item eq 'passback') {
11360: $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
11361: $confhash{$itemid}{$item.'valid'});
11362: } else {
11363: $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
11364: $confhash{$itemid}{$item.'valid'});
11365: }
11366: }
1.267 raeburn 11367: } else {
11368: $resulttext .= &mt('No');
11369: }
11370: $resulttext .= '</li>';
11371: }
11372: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
11373: my $displaylist;
11374: if ($confhash{$itemid}{'display'}{'target'}) {
11375: $displaylist = &mt('Display target').': '.
11376: $confhash{$itemid}{'display'}{'target'}.',';
11377: }
11378: foreach my $size ('width','height') {
11379: if ($confhash{$itemid}{'display'}{$size}) {
11380: $displaylist .= (' 'x2).$lt{$size}.': '.
11381: $confhash{$itemid}{'display'}{$size}.',';
11382: }
11383: }
11384: if ($displaylist) {
11385: $displaylist =~ s/,$//;
11386: $resulttext .= '<li>'.$displaylist.'</li>';
11387: }
1.296 raeburn 11388: foreach my $item ('linktext','explanation') {
11389: if ($confhash{$itemid}{'display'}{$item}) {
11390: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
11391: }
11392: }
11393: }
1.267 raeburn 11394: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
11395: my $fieldlist;
11396: foreach my $field (@allfields) {
11397: if ($confhash{$itemid}{'fields'}{$field}) {
11398: $fieldlist .= (' 'x2).$lt{$field}.',';
11399: }
11400: }
11401: if ($fieldlist) {
11402: $fieldlist =~ s/,$//;
1.324 raeburn 11403: if ($confhash{$itemid}{'fields'}{'user'}) {
11404: if ($confhash{$itemid}{'incdom'}) {
11405: $fieldlist .= ' ('.&mt('username:domain').')';
11406: } else {
11407: $fieldlist .= ' ('.&mt('username').')';
11408: }
11409: }
1.267 raeburn 11410: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
11411: }
11412: }
11413: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
11414: my $rolemaps;
11415: foreach my $role (@courseroles) {
11416: if ($confhash{$itemid}{'roles'}{$role}) {
11417: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
11418: $confhash{$itemid}{'roles'}{$role}.',';
11419: }
11420: }
11421: if ($rolemaps) {
11422: $rolemaps =~ s/,$//;
11423: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
11424: }
11425: }
11426: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
11427: my $customlist;
11428: if (keys(%{$confhash{$itemid}{'custom'}})) {
11429: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
11430: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
11431: }
11432: }
11433: if ($customlist) {
1.317 raeburn 11434: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267 raeburn 11435: }
11436: }
11437: $resulttext .= '</ul></li>';
11438: }
11439: }
11440: $resulttext .= '</ul>';
11441: } else {
11442: $resulttext = &mt('No changes made.');
11443: }
11444: } else {
11445: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
11446: }
11447: if ($errors) {
11448: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11449: $errors.'</ul>';
11450: }
11451: return $resulttext;
11452: }
11453:
11454: sub process_ltitools_image {
11455: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
11456: my $filename = $env{'form.'.$caller.'.filename'};
11457: my ($error,$url);
11458: my ($width,$height) = (21,21);
11459: if ($configuserok eq 'ok') {
11460: if ($switchserver) {
11461: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
11462: $switchserver);
11463: } elsif ($author_ok eq 'ok') {
11464: my ($result,$imageurl,$madethumb) =
11465: &publishlogo($r,'upload',$caller,$dom,$confname,
11466: "ltitools/$itemid/icon",$width,$height);
11467: if ($result eq 'ok') {
11468: if ($madethumb) {
11469: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
11470: my $imagethumb = "$path/tn-".$imagefile;
11471: $url = $imagethumb;
11472: } else {
11473: $url = $imageurl;
11474: }
11475: } else {
11476: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
11477: }
11478: } else {
11479: $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);
11480: }
11481: } else {
11482: $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);
11483: }
11484: return ($url,$error);
11485: }
11486:
11487: sub get_ltitools_id {
11488: my ($cdom,$title) = @_;
11489: # get lock on ltitools db
11490: my $lockhash = {
11491: lock => $env{'user.name'}.
11492: ':'.$env{'user.domain'},
11493: };
11494: my $tries = 0;
11495: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
11496: my ($id,$error);
11497:
11498: while (($gotlock ne 'ok') && ($tries<10)) {
11499: $tries ++;
11500: sleep (0.1);
11501: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
11502: }
11503: if ($gotlock eq 'ok') {
11504: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
11505: if ($currids{'lock'}) {
11506: delete($currids{'lock'});
11507: if (keys(%currids)) {
11508: my @curr = sort { $a <=> $b } keys(%currids);
11509: if ($curr[-1] =~ /^\d+$/) {
11510: $id = 1 + $curr[-1];
11511: }
11512: } else {
11513: $id = 1;
11514: }
11515: if ($id) {
11516: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
11517: $error = 'nostore';
11518: }
11519: } else {
11520: $error = 'nonumber';
11521: }
11522: }
11523: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
11524: } else {
11525: $error = 'nolock';
11526: }
11527: return ($id,$error);
11528: }
11529:
1.320 raeburn 11530: sub modify_lti {
11531: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
11532: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11533: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
11534: my (%posslti,%posslticrs,%posscrstype);
11535: my @courseroles = ('cc','in','ta','ep','st');
11536: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
11537: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
11538: my @coursetypes = ('official','unofficial','community','textbook','placement');
11539: my %coursetypetitles = &Apache::lonlocal::texthash (
11540: official => 'Official',
11541: unofficial => 'Unofficial',
11542: community => 'Community',
11543: textbook => 'Textbook',
11544: placement => 'Placement Test',
11545: );
1.325 raeburn 11546: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 11547: my %lt = <i_names();
11548: map { $posslti{$_} = 1; } @ltiroles;
11549: map { $posslticrs{$_} = 1; } @lticourseroles;
11550: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 11551:
1.326 raeburn 11552: my %menutitles = <imenu_titles();
11553:
1.320 raeburn 11554: my (@items,%deletions,%itemids);
11555: if ($env{'form.lti_add'}) {
11556: my $consumer = $env{'form.lti_consumer_add'};
11557: $consumer =~ s/(`)/'/g;
11558: ($newid,my $error) = &get_lti_id($dom,$consumer);
11559: if ($newid) {
11560: $itemids{'add'} = $newid;
11561: push(@items,'add');
11562: $changes{$newid} = 1;
11563: } else {
11564: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
11565: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11566: }
11567: }
11568: if (ref($domconfig{$action}) eq 'HASH') {
11569: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
11570: if (@todelete) {
11571: map { $deletions{$_} = 1; } @todelete;
11572: }
11573: my $maxnum = $env{'form.lti_maxnum'};
11574: for (my $i=0; $i<=$maxnum; $i++) {
11575: my $itemid = $env{'form.lti_id_'.$i};
11576: $itemid =~ s/\D+//g;
11577: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11578: if ($deletions{$itemid}) {
11579: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
11580: } else {
11581: push(@items,$i);
11582: $itemids{$i} = $itemid;
11583: }
11584: }
11585: }
11586: }
11587: foreach my $idx (@items) {
11588: my $itemid = $itemids{$idx};
11589: next unless ($itemid);
11590: my $position = $env{'form.lti_pos_'.$idx};
11591: $position =~ s/\D+//g;
11592: if ($position ne '') {
11593: $allpos[$position] = $itemid;
11594: }
11595: foreach my $item ('consumer','key','secret','lifetime') {
11596: my $formitem = 'form.lti_'.$item.'_'.$idx;
11597: $env{$formitem} =~ s/(`)/'/g;
11598: if ($item eq 'lifetime') {
11599: $env{$formitem} =~ s/[^\d.]//g;
11600: }
11601: if ($env{$formitem} ne '') {
11602: if (($item eq 'key') || ($item eq 'secret')) {
11603: $encconfig{$itemid}{$item} = $env{$formitem};
11604: } else {
11605: $confhash{$itemid}{$item} = $env{$formitem};
11606: unless (($idx eq 'add') || ($changes{$itemid})) {
11607: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
11608: $changes{$itemid} = 1;
11609: }
11610: }
11611: }
11612: }
11613: }
11614: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
11615: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
11616: }
11617: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
11618: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
11619: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
11620: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
11621: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
11622: my $mapuser = $env{'form.lti_customuser_'.$idx};
11623: $mapuser =~ s/(`)/'/g;
11624: $mapuser =~ s/^\s+|\s+$//g;
11625: $confhash{$itemid}{'mapuser'} = $mapuser;
11626: }
11627: foreach my $ltirole (@lticourseroles) {
11628: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
11629: if (grep(/^\Q$possrole\E$/,@courseroles)) {
11630: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
11631: }
11632: }
11633: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
11634: my @makeuser;
11635: foreach my $ltirole (sort(@possmakeuser)) {
11636: if ($posslti{$ltirole}) {
11637: push(@makeuser,$ltirole);
11638: }
11639: }
11640: $confhash{$itemid}{'makeuser'} = \@makeuser;
1.325 raeburn 11641: if (@makeuser) {
11642: my $lcauth = $env{'form.lti_lcauth_'.$idx};
11643: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
11644: $confhash{$itemid}{'lcauth'} = $lcauth;
11645: if ($lcauth ne 'internal') {
11646: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
11647: $lcauthparm =~ s/^(\s+|\s+)$//g;
11648: $lcauthparm =~ s/`//g;
11649: if ($lcauthparm ne '') {
11650: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
11651: }
11652: }
11653: } else {
11654: $confhash{$itemid}{'lcauth'} = 'lti';
11655: }
11656: }
11657: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
11658: if (@possinstdata) {
11659: foreach my $field (@possinstdata) {
11660: if (exists($fieldtitles{$field})) {
11661: push(@{$confhash{$itemid}{'instdata'}});
11662: }
11663: }
11664: }
1.320 raeburn 11665: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
11666: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
11667: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
11668: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
11669: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
11670: $mapcrs =~ s/(`)/'/g;
11671: $mapcrs =~ s/^\s+|\s+$//g;
11672: $confhash{$itemid}{'mapcrs'} = $mapcrs;
11673: }
11674: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
11675: my @crstypes;
11676: foreach my $type (sort(@posstypes)) {
11677: if ($posscrstype{$type}) {
11678: push(@crstypes,$type);
11679: }
11680: }
11681: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
11682: if ($env{'form.lti_makecrs_'.$idx}) {
11683: $confhash{$itemid}{'makecrs'} = 1;
11684: }
11685: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
11686: my @selfenroll;
11687: foreach my $type (sort(@possenroll)) {
11688: if ($posslticrs{$type}) {
11689: push(@selfenroll,$type);
11690: }
11691: }
11692: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
11693: if ($env{'form.lti_crssec_'.$idx}) {
11694: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
11695: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
11696: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
11697: my $section = $env{'form.lti_customsection_'.$idx};
11698: $section =~ s/(`)/'/g;
11699: $section =~ s/^\s+|\s+$//g;
11700: if ($section ne '') {
11701: $confhash{$itemid}{'section'} = $section;
11702: }
11703: }
11704: }
1.326 raeburn 11705: foreach my $field ('passback','roster','topmenu','inlinemenu') {
1.321 raeburn 11706: if ($env{'form.lti_'.$field.'_'.$idx}) {
1.320 raeburn 11707: $confhash{$itemid}{$field} = 1;
11708: }
11709: }
1.326 raeburn 11710:
11711: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
11712: $confhash{$itemid}{lcmenu} = [];
11713: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
11714: foreach my $field (@possmenu) {
11715: if (exists($menutitles{$field})) {
11716: if ($field eq 'grades') {
11717: next unless ($env{'form.lti_inlinemenu_'.$idx});
11718: }
11719: push(@{$confhash{$itemid}{lcmenu}},$field);
11720: }
11721: }
11722: }
1.320 raeburn 11723: unless (($idx eq 'add') || ($changes{$itemid})) {
1.326 raeburn 11724: foreach my $field ('mapuser','mapcrs','makecrs','section','passback','roster','lcauth','lcauthparm','topmenu','inlinemenu') {
1.320 raeburn 11725: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
11726: $changes{$itemid} = 1;
11727: }
11728: }
1.326 raeburn 11729: foreach my $field ('makeuser','mapcrstype','selfenroll','instdata','lcmenu') {
1.320 raeburn 11730: unless ($changes{$itemid}) {
11731: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
11732: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
11733: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
11734: $confhash{$itemid}{$field});
11735: if (@diffs) {
11736: $changes{$itemid} = 1;
11737: }
11738: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
11739: $changes{$itemid} = 1;
11740: }
11741: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
11742: if (@{$confhash{$itemid}{$field}} > 0) {
11743: $changes{$itemid} = 1;
11744: }
11745: }
11746: }
11747: }
11748: unless ($changes{$itemid}) {
11749: if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
11750: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
11751: foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
11752: if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne
11753: $confhash{$itemid}{'maproles'}{$ltirole}) {
11754: $changes{$itemid} = 1;
11755: last;
11756: }
11757: }
11758: unless ($changes{$itemid}) {
11759: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
11760: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
11761: $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
11762: $changes{$itemid} = 1;
11763: last;
11764: }
11765: }
11766: }
11767: } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
11768: $changes{$itemid} = 1;
11769: }
11770: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
11771: unless ($changes{$itemid}) {
11772: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
11773: $changes{$itemid} = 1;
11774: }
11775: }
11776: }
11777: }
11778: }
11779: }
11780: if (@allpos > 0) {
11781: my $idx = 0;
11782: foreach my $itemid (@allpos) {
11783: if ($itemid ne '') {
11784: $confhash{$itemid}{'order'} = $idx;
11785: if (ref($domconfig{$action}) eq 'HASH') {
11786: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11787: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
11788: $changes{$itemid} = 1;
11789: }
11790: }
11791: }
11792: $idx ++;
11793: }
11794: }
11795: }
11796: my %ltihash = (
11797: $action => { %confhash }
11798: );
11799: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,
11800: $dom);
11801: if ($putresult eq 'ok') {
11802: my %ltienchash = (
11803: $action => { %encconfig }
11804: );
11805: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
11806: if (keys(%changes) > 0) {
11807: my $cachetime = 24*60*60;
11808: my %ltiall = %confhash;
11809: foreach my $id (keys(%ltiall)) {
11810: if (ref($encconfig{$id}) eq 'HASH') {
11811: foreach my $item ('key','secret') {
11812: $ltiall{$id}{$item} = $encconfig{$id}{$item};
11813: }
11814: }
11815: }
11816: &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
11817: if (ref($lastactref) eq 'HASH') {
11818: $lastactref->{'lti'} = 1;
11819: }
11820: $resulttext = &mt('Changes made:').'<ul>';
11821: my %bynum;
11822: foreach my $itemid (sort(keys(%changes))) {
11823: my $position = $confhash{$itemid}{'order'};
11824: $bynum{$position} = $itemid;
11825: }
11826: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
11827: my $itemid = $bynum{$pos};
11828: if (ref($confhash{$itemid}) ne 'HASH') {
11829: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
11830: } else {
11831: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b></li><ul>';
11832: my $position = $pos + 1;
11833: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
11834: foreach my $item ('version','lifetime') {
11835: if ($confhash{$itemid}{$item} ne '') {
11836: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
11837: }
11838: }
11839: if ($encconfig{$itemid}{'key'} ne '') {
11840: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
11841: }
11842: if ($encconfig{$itemid}{'secret'} ne '') {
11843: $resulttext .= '<li>'.$lt{'secret'}.': ';
11844: my $num = length($encconfig{$itemid}{'secret'});
11845: $resulttext .= ('*'x$num).'</li>';
11846: }
11847: if ($confhash{$itemid}{'mapuser'}) {
11848: my $shownmapuser;
11849: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
11850: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
11851: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
11852: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
11853: } else {
11854: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
11855: }
11856: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
11857: }
11858: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
11859: my $rolemaps;
11860: foreach my $role (@ltiroles) {
11861: if ($confhash{$itemid}{'maproles'}{$role}) {
11862: $rolemaps .= (' 'x2).$role.'='.
11863: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
11864: 'Course').',';
11865: }
11866: }
11867: if ($rolemaps) {
11868: $rolemaps =~ s/,$//;
11869: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
11870: }
11871: }
11872: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
11873: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
11874: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
1.325 raeburn 11875: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
11876: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
11877: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
11878: } else {
11879: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
11880: $confhash{$itemid}{'lcauth'});
11881: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
11882: $resulttext .= '; '.&mt('a randomly generated password will be created');
11883: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
11884: if ($confhash{$itemid}{'lcauthparm'} ne '') {
11885: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
11886: }
11887: } else {
11888: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
11889: }
11890: }
11891: $resulttext .= '</li>';
1.320 raeburn 11892: } else {
11893: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
11894: }
11895: }
1.325 raeburn 11896: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
11897: if (@{$confhash{$itemid}{'instdata'}} > 0) {
11898: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
11899: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
11900: } else {
11901: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
11902: }
11903: }
1.320 raeburn 11904: if ($confhash{$itemid}{'mapcrs'}) {
11905: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
11906: }
11907: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
11908: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
11909: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
11910: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
11911: '</li>';
11912: } else {
11913: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
11914: }
11915: }
11916: if ($confhash{$itemid}{'makecrs'}) {
11917: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
11918: } else {
11919: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
11920: }
11921: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
11922: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
11923: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
11924: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
11925: '</li>';
11926: } else {
11927: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
11928: }
11929: }
11930: if ($confhash{$itemid}{'section'}) {
11931: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
11932: $resulttext .= '<li>'.&mt('User section from standard field:').
11933: ' (course_section_sourcedid)'.'</li>';
11934: } else {
11935: $resulttext .= '<li>'.&mt('User section from:').' '.
11936: $confhash{$itemid}{'section'}.'</li>';
11937: }
11938: } else {
11939: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
11940: }
1.326 raeburn 11941: foreach my $item ('passback','roster','topmenu','inlinemenu') {
11942: $resulttext .= '<li>'.$lt{$item}.': ';
1.320 raeburn 11943: if ($confhash{$itemid}{$item}) {
11944: $resulttext .= &mt('Yes');
11945: } else {
11946: $resulttext .= &mt('No');
11947: }
11948: $resulttext .= '</li>';
11949: }
1.326 raeburn 11950: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
11951: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
11952: $resulttext .= '<li>'.&mt('Menu items:').' '.
11953: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
11954: } else {
11955: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
11956: }
11957: }
1.320 raeburn 11958: $resulttext .= '</ul></li>';
11959: }
11960: }
11961: $resulttext .= '</ul>';
11962: } else {
11963: $resulttext = &mt('No changes made.');
11964: }
11965: } else {
11966: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
11967: }
11968: if ($errors) {
11969: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11970: $errors.'</ul>';
11971: }
11972: return $resulttext;
11973: }
11974:
11975: sub get_lti_id {
11976: my ($domain,$consumer) = @_;
11977: # get lock on lti db
11978: my $lockhash = {
11979: lock => $env{'user.name'}.
11980: ':'.$env{'user.domain'},
11981: };
11982: my $tries = 0;
11983: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
11984: my ($id,$error);
11985:
11986: while (($gotlock ne 'ok') && ($tries<10)) {
11987: $tries ++;
11988: sleep (0.1);
11989: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
11990: }
11991: if ($gotlock eq 'ok') {
11992: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
11993: if ($currids{'lock'}) {
11994: delete($currids{'lock'});
11995: if (keys(%currids)) {
11996: my @curr = sort { $a <=> $b } keys(%currids);
11997: if ($curr[-1] =~ /^\d+$/) {
11998: $id = 1 + $curr[-1];
11999: }
12000: } else {
12001: $id = 1;
12002: }
12003: if ($id) {
12004: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
12005: $error = 'nostore';
12006: }
12007: } else {
12008: $error = 'nonumber';
12009: }
12010: }
12011: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
12012: } else {
12013: $error = 'nolock';
12014: }
12015: return ($id,$error);
12016: }
12017:
1.3 raeburn 12018: sub modify_autoenroll {
1.205 raeburn 12019: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 12020: my ($resulttext,%changes);
12021: my %currautoenroll;
12022: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
12023: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
12024: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
12025: }
12026: }
12027: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
12028: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 12029: sender => 'Sender for notification messages',
1.274 raeburn 12030: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
12031: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 12032: my @offon = ('off','on');
1.17 raeburn 12033: my $sender_uname = $env{'form.sender_uname'};
12034: my $sender_domain = $env{'form.sender_domain'};
12035: if ($sender_domain eq '') {
12036: $sender_uname = '';
12037: } elsif ($sender_uname eq '') {
12038: $sender_domain = '';
12039: }
1.129 raeburn 12040: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 12041: my $failsafe = $env{'form.autoenroll_failsafe'};
12042: $failsafe =~ s{^\s+|\s+$}{}g;
12043: if ($failsafe =~ /\D/) {
12044: undef($failsafe);
12045: }
1.1 raeburn 12046: my %autoenrollhash = (
1.129 raeburn 12047: autoenroll => { 'run' => $env{'form.autoenroll_run'},
12048: 'sender_uname' => $sender_uname,
12049: 'sender_domain' => $sender_domain,
12050: 'co-owners' => $coowners,
1.274 raeburn 12051: 'autofailsafe' => $failsafe,
1.1 raeburn 12052: }
12053: );
1.4 raeburn 12054: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
12055: $dom);
1.1 raeburn 12056: if ($putresult eq 'ok') {
12057: if (exists($currautoenroll{'run'})) {
12058: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
12059: $changes{'run'} = 1;
12060: }
12061: } elsif ($autorun) {
12062: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 12063: $changes{'run'} = 1;
1.1 raeburn 12064: }
12065: }
1.17 raeburn 12066: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 12067: $changes{'sender'} = 1;
12068: }
1.17 raeburn 12069: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 12070: $changes{'sender'} = 1;
12071: }
1.129 raeburn 12072: if ($currautoenroll{'co-owners'} ne '') {
12073: if ($currautoenroll{'co-owners'} ne $coowners) {
12074: $changes{'coowners'} = 1;
12075: }
12076: } elsif ($coowners) {
12077: $changes{'coowners'} = 1;
1.274 raeburn 12078: }
12079: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
12080: $changes{'autofailsafe'} = 1;
12081: }
1.1 raeburn 12082: if (keys(%changes) > 0) {
12083: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 12084: if ($changes{'run'}) {
1.1 raeburn 12085: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
12086: }
12087: if ($changes{'sender'}) {
1.17 raeburn 12088: if ($sender_uname eq '' || $sender_domain eq '') {
12089: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
12090: } else {
12091: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
12092: }
1.1 raeburn 12093: }
1.129 raeburn 12094: if ($changes{'coowners'}) {
12095: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
12096: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12097: if (ref($lastactref) eq 'HASH') {
12098: $lastactref->{'domainconfig'} = 1;
12099: }
1.129 raeburn 12100: }
1.274 raeburn 12101: if ($changes{'autofailsafe'}) {
12102: if ($failsafe ne '') {
1.299 raeburn 12103: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274 raeburn 12104: } else {
1.299 raeburn 12105: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274 raeburn 12106: }
12107: &Apache::lonnet::get_domain_defaults($dom,1);
12108: if (ref($lastactref) eq 'HASH') {
12109: $lastactref->{'domdefaults'} = 1;
12110: }
12111: }
1.1 raeburn 12112: $resulttext .= '</ul>';
12113: } else {
12114: $resulttext = &mt('No changes made to auto-enrollment settings');
12115: }
12116: } else {
1.11 albertel 12117: $resulttext = '<span class="LC_error">'.
12118: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12119: }
1.3 raeburn 12120: return $resulttext;
1.1 raeburn 12121: }
12122:
12123: sub modify_autoupdate {
1.3 raeburn 12124: my ($dom,%domconfig) = @_;
1.1 raeburn 12125: my ($resulttext,%currautoupdate,%fields,%changes);
12126: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
12127: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
12128: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
12129: }
12130: }
12131: my @offon = ('off','on');
12132: my %title = &Apache::lonlocal::texthash (
12133: run => 'Auto-update:',
12134: classlists => 'Updates to user information in classlists?'
12135: );
1.44 raeburn 12136: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 12137: my %fieldtitles = &Apache::lonlocal::texthash (
12138: id => 'Student/Employee ID',
1.20 raeburn 12139: permanentemail => 'E-mail address',
1.1 raeburn 12140: lastname => 'Last Name',
12141: firstname => 'First Name',
12142: middlename => 'Middle Name',
1.132 raeburn 12143: generation => 'Generation',
1.1 raeburn 12144: );
1.142 raeburn 12145: $othertitle = &mt('All users');
1.1 raeburn 12146: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 12147: $othertitle = &mt('Other users');
1.1 raeburn 12148: }
12149: foreach my $key (keys(%env)) {
12150: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 12151: my ($usertype,$item) = ($1,$2);
12152: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
12153: if ($usertype eq 'default') {
12154: push(@{$fields{$1}},$2);
12155: } elsif (ref($types) eq 'ARRAY') {
12156: if (grep(/^\Q$usertype\E$/,@{$types})) {
12157: push(@{$fields{$1}},$2);
12158: }
12159: }
12160: }
1.1 raeburn 12161: }
12162: }
1.131 raeburn 12163: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
12164: @lockablenames = sort(@lockablenames);
12165: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
12166: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
12167: if (@changed) {
12168: $changes{'lockablenames'} = 1;
12169: }
12170: } else {
12171: if (@lockablenames) {
12172: $changes{'lockablenames'} = 1;
12173: }
12174: }
1.1 raeburn 12175: my %updatehash = (
12176: autoupdate => { run => $env{'form.autoupdate_run'},
12177: classlists => $env{'form.classlists'},
12178: fields => {%fields},
1.131 raeburn 12179: lockablenames => \@lockablenames,
1.1 raeburn 12180: }
12181: );
12182: foreach my $key (keys(%currautoupdate)) {
12183: if (($key eq 'run') || ($key eq 'classlists')) {
12184: if (exists($updatehash{autoupdate}{$key})) {
12185: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
12186: $changes{$key} = 1;
12187: }
12188: }
12189: } elsif ($key eq 'fields') {
12190: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 12191: foreach my $item (@{$types},'default') {
1.1 raeburn 12192: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
12193: my $change = 0;
12194: foreach my $type (@{$currautoupdate{$key}{$item}}) {
12195: if (!exists($fields{$item})) {
12196: $change = 1;
1.132 raeburn 12197: last;
1.1 raeburn 12198: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 12199: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 12200: $change = 1;
1.132 raeburn 12201: last;
1.1 raeburn 12202: }
12203: }
12204: }
12205: if ($change) {
12206: push(@{$changes{$key}},$item);
12207: }
1.26 raeburn 12208: }
1.1 raeburn 12209: }
12210: }
1.131 raeburn 12211: } elsif ($key eq 'lockablenames') {
12212: if (ref($currautoupdate{$key}) eq 'ARRAY') {
12213: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
12214: if (@changed) {
12215: $changes{'lockablenames'} = 1;
12216: }
12217: } else {
12218: if (@lockablenames) {
12219: $changes{'lockablenames'} = 1;
12220: }
12221: }
12222: }
12223: }
12224: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
12225: if (@lockablenames) {
12226: $changes{'lockablenames'} = 1;
1.1 raeburn 12227: }
12228: }
1.26 raeburn 12229: foreach my $item (@{$types},'default') {
12230: if (defined($fields{$item})) {
12231: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 12232: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
12233: my $change = 0;
12234: if (ref($fields{$item}) eq 'ARRAY') {
12235: foreach my $type (@{$fields{$item}}) {
12236: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
12237: $change = 1;
12238: last;
12239: }
12240: }
12241: }
12242: if ($change) {
12243: push(@{$changes{'fields'}},$item);
12244: }
12245: } else {
1.26 raeburn 12246: push(@{$changes{'fields'}},$item);
12247: }
12248: } else {
12249: push(@{$changes{'fields'}},$item);
1.1 raeburn 12250: }
12251: }
12252: }
12253: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
12254: $dom);
12255: if ($putresult eq 'ok') {
12256: if (keys(%changes) > 0) {
12257: $resulttext = &mt('Changes made:').'<ul>';
12258: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 12259: if ($key eq 'lockablenames') {
12260: $resulttext .= '<li>';
12261: if (@lockablenames) {
12262: $usertypes->{'default'} = $othertitle;
12263: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
12264: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
12265: } else {
12266: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
12267: }
12268: $resulttext .= '</li>';
12269: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 12270: foreach my $item (@{$changes{$key}}) {
12271: my @newvalues;
12272: foreach my $type (@{$fields{$item}}) {
12273: push(@newvalues,$fieldtitles{$type});
12274: }
1.3 raeburn 12275: my $newvaluestr;
12276: if (@newvalues > 0) {
12277: $newvaluestr = join(', ',@newvalues);
12278: } else {
12279: $newvaluestr = &mt('none');
1.6 raeburn 12280: }
1.1 raeburn 12281: if ($item eq 'default') {
1.26 raeburn 12282: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 12283: } else {
1.26 raeburn 12284: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 12285: }
12286: }
12287: } else {
12288: my $newvalue;
12289: if ($key eq 'run') {
12290: $newvalue = $offon[$env{'form.autoupdate_run'}];
12291: } else {
12292: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 12293: }
1.1 raeburn 12294: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
12295: }
12296: }
12297: $resulttext .= '</ul>';
12298: } else {
1.3 raeburn 12299: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 12300: }
12301: } else {
1.11 albertel 12302: $resulttext = '<span class="LC_error">'.
12303: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12304: }
1.3 raeburn 12305: return $resulttext;
1.1 raeburn 12306: }
12307:
1.125 raeburn 12308: sub modify_autocreate {
12309: my ($dom,%domconfig) = @_;
12310: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
12311: if (ref($domconfig{'autocreate'}) eq 'HASH') {
12312: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
12313: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
12314: }
12315: }
12316: my %title= ( xml => 'Auto-creation of courses in XML course description files',
12317: req => 'Auto-creation of validated requests for official courses',
12318: xmldc => 'Identity of course creator of courses from XML files',
12319: );
12320: my @types = ('xml','req');
12321: foreach my $item (@types) {
12322: $newvals{$item} = $env{'form.autocreate_'.$item};
12323: $newvals{$item} =~ s/\D//g;
12324: $newvals{$item} = 0 if ($newvals{$item} eq '');
12325: }
12326: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 12327: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 12328: unless (exists($domcoords{$newvals{'xmldc'}})) {
12329: $newvals{'xmldc'} = '';
12330: }
12331: %autocreatehash = (
12332: autocreate => { xml => $newvals{'xml'},
12333: req => $newvals{'req'},
12334: }
12335: );
12336: if ($newvals{'xmldc'} ne '') {
12337: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
12338: }
12339: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
12340: $dom);
12341: if ($putresult eq 'ok') {
12342: my @items = @types;
12343: if ($newvals{'xml'}) {
12344: push(@items,'xmldc');
12345: }
12346: foreach my $item (@items) {
12347: if (exists($currautocreate{$item})) {
12348: if ($currautocreate{$item} ne $newvals{$item}) {
12349: $changes{$item} = 1;
12350: }
12351: } elsif ($newvals{$item}) {
12352: $changes{$item} = 1;
12353: }
12354: }
12355: if (keys(%changes) > 0) {
12356: my @offon = ('off','on');
12357: $resulttext = &mt('Changes made:').'<ul>';
12358: foreach my $item (@types) {
12359: if ($changes{$item}) {
12360: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 12361: $resulttext .= '<li>'.
12362: &mt("$title{$item} set to [_1]$newtxt [_2]",
12363: '<b>','</b>').
12364: '</li>';
1.125 raeburn 12365: }
12366: }
12367: if ($changes{'xmldc'}) {
12368: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
12369: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 12370: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 12371: }
12372: $resulttext .= '</ul>';
12373: } else {
12374: $resulttext = &mt('No changes made to auto-creation settings');
12375: }
12376: } else {
12377: $resulttext = '<span class="LC_error">'.
12378: &mt('An error occurred: [_1]',$putresult).'</span>';
12379: }
12380: return $resulttext;
12381: }
12382:
1.23 raeburn 12383: sub modify_directorysrch {
1.295 raeburn 12384: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 12385: my ($resulttext,%changes);
12386: my %currdirsrch;
12387: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
12388: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
12389: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
12390: }
12391: }
1.277 raeburn 12392: my %title = ( available => 'Institutional directory search available',
12393: localonly => 'Other domains can search institution',
12394: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 12395: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 12396: searchby => 'Search types',
12397: searchtypes => 'Search latitude');
12398: my @offon = ('off','on');
1.24 raeburn 12399: my @otherdoms = ('Yes','No');
1.23 raeburn 12400:
1.25 raeburn 12401: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 12402: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
12403: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
12404:
1.44 raeburn 12405: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 12406: if (keys(%{$usertypes}) == 0) {
12407: @cansearch = ('default');
12408: } else {
12409: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
12410: foreach my $type (@{$currdirsrch{'cansearch'}}) {
12411: if (!grep(/^\Q$type\E$/,@cansearch)) {
12412: push(@{$changes{'cansearch'}},$type);
12413: }
1.23 raeburn 12414: }
1.26 raeburn 12415: foreach my $type (@cansearch) {
12416: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
12417: push(@{$changes{'cansearch'}},$type);
12418: }
1.23 raeburn 12419: }
1.26 raeburn 12420: } else {
12421: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 12422: }
12423: }
12424:
12425: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
12426: foreach my $by (@{$currdirsrch{'searchby'}}) {
12427: if (!grep(/^\Q$by\E$/,@searchby)) {
12428: push(@{$changes{'searchby'}},$by);
12429: }
12430: }
12431: foreach my $by (@searchby) {
12432: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
12433: push(@{$changes{'searchby'}},$by);
12434: }
12435: }
12436: } else {
12437: push(@{$changes{'searchby'}},@searchby);
12438: }
1.25 raeburn 12439:
12440: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
12441: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
12442: if (!grep(/^\Q$type\E$/,@searchtypes)) {
12443: push(@{$changes{'searchtypes'}},$type);
12444: }
12445: }
12446: foreach my $type (@searchtypes) {
12447: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
12448: push(@{$changes{'searchtypes'}},$type);
12449: }
12450: }
12451: } else {
12452: if (exists($currdirsrch{'searchtypes'})) {
12453: foreach my $type (@searchtypes) {
12454: if ($type ne $currdirsrch{'searchtypes'}) {
12455: push(@{$changes{'searchtypes'}},$type);
12456: }
12457: }
12458: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
12459: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
12460: }
12461: } else {
12462: push(@{$changes{'searchtypes'}},@searchtypes);
12463: }
12464: }
12465:
1.23 raeburn 12466: my %dirsrch_hash = (
12467: directorysrch => { available => $env{'form.dirsrch_available'},
12468: cansearch => \@cansearch,
1.277 raeburn 12469: localonly => $env{'form.dirsrch_instlocalonly'},
12470: lclocalonly => $env{'form.dirsrch_domlocalonly'},
12471: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 12472: searchby => \@searchby,
1.25 raeburn 12473: searchtypes => \@searchtypes,
1.23 raeburn 12474: }
12475: );
12476: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
12477: $dom);
12478: if ($putresult eq 'ok') {
12479: if (exists($currdirsrch{'available'})) {
12480: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
12481: $changes{'available'} = 1;
12482: }
12483: } else {
12484: if ($env{'form.dirsrch_available'} eq '1') {
12485: $changes{'available'} = 1;
12486: }
12487: }
1.277 raeburn 12488: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 12489: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
12490: $changes{'lcavailable'} = 1;
12491: }
1.277 raeburn 12492: } else {
12493: if ($env{'form.dirsrch_lcavailable'} eq '1') {
12494: $changes{'lcavailable'} = 1;
12495: }
12496: }
1.24 raeburn 12497: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 12498: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
12499: $changes{'localonly'} = 1;
12500: }
1.24 raeburn 12501: } else {
1.277 raeburn 12502: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 12503: $changes{'localonly'} = 1;
12504: }
12505: }
1.277 raeburn 12506: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 12507: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
12508: $changes{'lclocalonly'} = 1;
12509: }
1.277 raeburn 12510: } else {
12511: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
12512: $changes{'lclocalonly'} = 1;
12513: }
12514: }
1.23 raeburn 12515: if (keys(%changes) > 0) {
12516: $resulttext = &mt('Changes made:').'<ul>';
12517: if ($changes{'available'}) {
12518: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
12519: }
1.277 raeburn 12520: if ($changes{'lcavailable'}) {
12521: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
12522: }
1.24 raeburn 12523: if ($changes{'localonly'}) {
1.277 raeburn 12524: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 12525: }
1.277 raeburn 12526: if ($changes{'lclocalonly'}) {
12527: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 12528: }
1.23 raeburn 12529: if (ref($changes{'cansearch'}) eq 'ARRAY') {
12530: my $chgtext;
1.26 raeburn 12531: if (ref($usertypes) eq 'HASH') {
12532: if (keys(%{$usertypes}) > 0) {
12533: foreach my $type (@{$types}) {
12534: if (grep(/^\Q$type\E$/,@cansearch)) {
12535: $chgtext .= $usertypes->{$type}.'; ';
12536: }
12537: }
12538: if (grep(/^default$/,@cansearch)) {
12539: $chgtext .= $othertitle;
12540: } else {
12541: $chgtext =~ s/\; $//;
12542: }
1.210 raeburn 12543: $resulttext .=
1.178 raeburn 12544: '<li>'.
12545: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
12546: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
12547: '</li>';
1.23 raeburn 12548: }
12549: }
12550: }
12551: if (ref($changes{'searchby'}) eq 'ARRAY') {
12552: my ($searchtitles,$titleorder) = &sorted_searchtitles();
12553: my $chgtext;
12554: foreach my $type (@{$titleorder}) {
12555: if (grep(/^\Q$type\E$/,@searchby)) {
12556: if (defined($searchtitles->{$type})) {
12557: $chgtext .= $searchtitles->{$type}.'; ';
12558: }
12559: }
12560: }
12561: $chgtext =~ s/\; $//;
12562: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
12563: }
1.25 raeburn 12564: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
12565: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
12566: my $chgtext;
12567: foreach my $type (@{$srchtypeorder}) {
12568: if (grep(/^\Q$type\E$/,@searchtypes)) {
12569: if (defined($srchtypes_desc->{$type})) {
12570: $chgtext .= $srchtypes_desc->{$type}.'; ';
12571: }
12572: }
12573: }
12574: $chgtext =~ s/\; $//;
1.178 raeburn 12575: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 12576: }
12577: $resulttext .= '</ul>';
1.295 raeburn 12578: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
12579: if (ref($lastactref) eq 'HASH') {
12580: $lastactref->{'directorysrch'} = 1;
12581: }
1.23 raeburn 12582: } else {
1.277 raeburn 12583: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 12584: }
12585: } else {
12586: $resulttext = '<span class="LC_error">'.
1.27 raeburn 12587: &mt('An error occurred: [_1]',$putresult).'</span>';
12588: }
12589: return $resulttext;
12590: }
12591:
1.28 raeburn 12592: sub modify_contacts {
1.205 raeburn 12593: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 12594: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
12595: if (ref($domconfig{'contacts'}) eq 'HASH') {
12596: foreach my $key (keys(%{$domconfig{'contacts'}})) {
12597: $currsetting{$key} = $domconfig{'contacts'}{$key};
12598: }
12599: }
1.286 raeburn 12600: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 12601: my @contacts = ('supportemail','adminemail');
1.286 raeburn 12602: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
12603: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.203 raeburn 12604: my @toggles = ('reporterrors','reportupdates');
1.286 raeburn 12605: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 12606: foreach my $type (@mailings) {
12607: @{$newsetting{$type}} =
12608: &Apache::loncommon::get_env_multiple('form.'.$type);
12609: foreach my $item (@contacts) {
12610: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
12611: $contacts_hash{contacts}{$type}{$item} = 1;
12612: } else {
12613: $contacts_hash{contacts}{$type}{$item} = 0;
12614: }
1.289 raeburn 12615: }
1.28 raeburn 12616: $others{$type} = $env{'form.'.$type.'_others'};
12617: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 12618: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12619: $bcc{$type} = $env{'form.'.$type.'_bcc'};
12620: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 12621: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
12622: $includestr{$type} = $env{'form.'.$type.'_includestr'};
12623: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
12624: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
12625: }
1.134 raeburn 12626: }
1.28 raeburn 12627: }
12628: foreach my $item (@contacts) {
12629: $to{$item} = $env{'form.'.$item};
12630: $contacts_hash{'contacts'}{$item} = $to{$item};
12631: }
1.203 raeburn 12632: foreach my $item (@toggles) {
12633: if ($env{'form.'.$item} =~ /^(0|1)$/) {
12634: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
12635: }
12636: }
1.286 raeburn 12637: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
12638: foreach my $field (@{$fields}) {
12639: if (ref($possoptions->{$field}) eq 'ARRAY') {
12640: my $value = $env{'form.helpform_'.$field};
12641: $value =~ s/^\s+|\s+$//g;
12642: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 12643: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 12644: if ($field eq 'screenshot') {
12645: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
12646: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 12647: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 12648: }
12649: }
12650: }
12651: }
12652: }
12653: }
1.315 raeburn 12654: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12655: my (@statuses,%usertypeshash,@overrides);
12656: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
12657: @statuses = @{$types};
12658: if (ref($usertypes) eq 'HASH') {
12659: %usertypeshash = %{$usertypes};
12660: }
12661: }
12662: if (@statuses) {
12663: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
12664: foreach my $type (@possoverrides) {
12665: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
12666: push(@overrides,$type);
12667: }
12668: }
12669: if (@overrides) {
12670: foreach my $type (@overrides) {
12671: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
12672: foreach my $item (@contacts) {
12673: if (grep(/^\Q$item\E$/,@standard)) {
12674: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
12675: $newsetting{'override_'.$type}{$item} = 1;
12676: } else {
12677: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
12678: $newsetting{'override_'.$type}{$item} = 0;
12679: }
12680: }
12681: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
12682: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
12683: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
12684: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
12685: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
12686: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
12687: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
12688: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
12689: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
12690: }
12691: }
12692: }
12693: }
1.28 raeburn 12694: if (keys(%currsetting) > 0) {
12695: foreach my $item (@contacts) {
12696: if ($to{$item} ne $currsetting{$item}) {
12697: $changes{$item} = 1;
12698: }
12699: }
12700: foreach my $type (@mailings) {
12701: foreach my $item (@contacts) {
12702: if (ref($currsetting{$type}) eq 'HASH') {
12703: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
12704: push(@{$changes{$type}},$item);
12705: }
12706: } else {
12707: push(@{$changes{$type}},@{$newsetting{$type}});
12708: }
12709: }
12710: if ($others{$type} ne $currsetting{$type}{'others'}) {
12711: push(@{$changes{$type}},'others');
12712: }
1.289 raeburn 12713: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12714: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
12715: push(@{$changes{$type}},'bcc');
12716: }
1.286 raeburn 12717: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
12718: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
12719: push(@{$changes{$type}},'include');
12720: }
12721: }
12722: }
12723: if (ref($fields) eq 'ARRAY') {
12724: if (ref($currsetting{'helpform'}) eq 'HASH') {
12725: foreach my $field (@{$fields}) {
12726: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
12727: push(@{$changes{'helpform'}},$field);
12728: }
12729: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12730: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
12731: push(@{$changes{'helpform'}},'maxsize');
12732: }
12733: }
12734: }
12735: } else {
12736: foreach my $field (@{$fields}) {
12737: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12738: push(@{$changes{'helpform'}},$field);
12739: }
12740: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12741: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12742: push(@{$changes{'helpform'}},'maxsize');
12743: }
12744: }
12745: }
1.134 raeburn 12746: }
1.28 raeburn 12747: }
1.315 raeburn 12748: if (@statuses) {
12749: if (ref($currsetting{'overrides'}) eq 'HASH') {
12750: foreach my $key (keys(%{$currsetting{'overrides'}})) {
12751: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
12752: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
12753: foreach my $item (@contacts,'bcc','others','include') {
12754: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
12755: push(@{$changes{'overrides'}},$key);
12756: last;
12757: }
12758: }
12759: } else {
12760: push(@{$changes{'overrides'}},$key);
12761: }
12762: }
12763: }
12764: foreach my $key (@overrides) {
12765: unless (exists($currsetting{'overrides'}{$key})) {
12766: push(@{$changes{'overrides'}},$key);
12767: }
12768: }
12769: } else {
12770: foreach my $key (@overrides) {
12771: push(@{$changes{'overrides'}},$key);
12772: }
12773: }
12774: }
1.28 raeburn 12775: } else {
12776: my %default;
12777: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
12778: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
12779: $default{'errormail'} = 'adminemail';
12780: $default{'packagesmail'} = 'adminemail';
12781: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 12782: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 12783: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 12784: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 12785: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 12786: foreach my $item (@contacts) {
12787: if ($to{$item} ne $default{$item}) {
1.286 raeburn 12788: $changes{$item} = 1;
1.203 raeburn 12789: }
1.28 raeburn 12790: }
12791: foreach my $type (@mailings) {
12792: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
12793: push(@{$changes{$type}},@{$newsetting{$type}});
12794: }
12795: if ($others{$type} ne '') {
12796: push(@{$changes{$type}},'others');
1.134 raeburn 12797: }
1.286 raeburn 12798: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12799: if ($bcc{$type} ne '') {
12800: push(@{$changes{$type}},'bcc');
12801: }
1.286 raeburn 12802: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
12803: push(@{$changes{$type}},'include');
12804: }
1.134 raeburn 12805: }
1.28 raeburn 12806: }
1.286 raeburn 12807: if (ref($fields) eq 'ARRAY') {
12808: foreach my $field (@{$fields}) {
12809: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
12810: push(@{$changes{'helpform'}},$field);
12811: }
12812: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
12813: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
12814: push(@{$changes{'helpform'}},'maxsize');
12815: }
12816: }
12817: }
1.289 raeburn 12818: }
1.28 raeburn 12819: }
1.203 raeburn 12820: foreach my $item (@toggles) {
12821: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
12822: $changes{$item} = 1;
12823: } elsif ((!$env{'form.'.$item}) &&
12824: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
12825: $changes{$item} = 1;
12826: }
12827: }
1.28 raeburn 12828: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
12829: $dom);
12830: if ($putresult eq 'ok') {
12831: if (keys(%changes) > 0) {
1.205 raeburn 12832: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12833: if (ref($lastactref) eq 'HASH') {
12834: $lastactref->{'domainconfig'} = 1;
12835: }
1.28 raeburn 12836: my ($titles,$short_titles) = &contact_titles();
12837: $resulttext = &mt('Changes made:').'<ul>';
12838: foreach my $item (@contacts) {
12839: if ($changes{$item}) {
12840: $resulttext .= '<li>'.$titles->{$item}.
12841: &mt(' set to: ').
12842: '<span class="LC_cusr_emph">'.
12843: $to{$item}.'</span></li>';
12844: }
12845: }
12846: foreach my $type (@mailings) {
12847: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 12848: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 12849: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 12850: } else {
12851: $resulttext .= '<li>'.$titles->{$type}.': ';
12852: }
1.28 raeburn 12853: my @text;
12854: foreach my $item (@{$newsetting{$type}}) {
12855: push(@text,$short_titles->{$item});
12856: }
12857: if ($others{$type} ne '') {
12858: push(@text,$others{$type});
12859: }
1.286 raeburn 12860: if (@text) {
12861: $resulttext .= '<span class="LC_cusr_emph">'.
12862: join(', ',@text).'</span>';
12863: }
12864: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 12865: if ($bcc{$type} ne '') {
1.286 raeburn 12866: my $bcctext;
12867: if (@text) {
1.289 raeburn 12868: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 12869: } else {
12870: $bcctext = '(Bcc)';
12871: }
12872: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
12873: } elsif (!@text) {
12874: $resulttext .= &mt('No one');
12875: }
1.289 raeburn 12876: if ($includestr{$type} ne '') {
1.286 raeburn 12877: if ($includeloc{$type} eq 'b') {
12878: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
12879: } elsif ($includeloc{$type} eq 's') {
12880: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
12881: }
1.134 raeburn 12882: }
1.286 raeburn 12883: } elsif (!@text) {
12884: $resulttext .= &mt('No recipients');
1.134 raeburn 12885: }
12886: $resulttext .= '</li>';
1.28 raeburn 12887: }
12888: }
1.315 raeburn 12889: if (ref($changes{'overrides'}) eq 'ARRAY') {
12890: my @deletions;
12891: foreach my $type (@{$changes{'overrides'}}) {
12892: if ($usertypeshash{$type}) {
12893: if (grep(/^\Q$type\E/,@overrides)) {
12894: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
12895: $usertypeshash{$type}).'<ul><li>';
12896: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
12897: my @text;
12898: foreach my $item (@contacts) {
12899: if ($newsetting{'override_'.$type}{$item}) {
12900: push(@text,$short_titles->{$item});
12901: }
12902: }
12903: if ($newsetting{'override_'.$type}{'others'} ne '') {
12904: push(@text,$newsetting{'override_'.$type}{'others'});
12905: }
12906:
12907: if (@text) {
12908: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
12909: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
12910: }
12911: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
12912: my $bcctext;
12913: if (@text) {
12914: $bcctext = ' '.&mt('with Bcc to');
12915: } else {
12916: $bcctext = '(Bcc)';
12917: }
12918: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
12919: } elsif (!@text) {
12920: $resulttext .= &mt('Helpdesk e-mail sent to no one');
12921: }
12922: $resulttext .= '</li>';
12923: if ($newsetting{'override_'.$type}{'include'} ne '') {
12924: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
12925: if ($loc eq 'b') {
12926: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
12927: } elsif ($loc eq 's') {
12928: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
12929: }
12930: }
12931: }
12932: $resulttext .= '</li></ul></li>';
12933: } else {
12934: push(@deletions,$usertypeshash{$type});
12935: }
12936: }
12937: }
12938: if (@deletions) {
12939: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
12940: join(', ',@deletions)).'</li>';
12941: }
12942: }
1.203 raeburn 12943: my @offon = ('off','on');
12944: if ($changes{'reporterrors'}) {
12945: $resulttext .= '<li>'.
12946: &mt('E-mail error reports to [_1] set to "'.
12947: $offon[$env{'form.reporterrors'}].'".',
12948: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
12949: &mt('LON-CAPA core group - MSU'),600,500)).
12950: '</li>';
12951: }
12952: if ($changes{'reportupdates'}) {
12953: $resulttext .= '<li>'.
12954: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
12955: $offon[$env{'form.reportupdates'}].'".',
12956: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
12957: &mt('LON-CAPA core group - MSU'),600,500)).
12958: '</li>';
12959: }
1.286 raeburn 12960: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
12961: my (@optional,@required,@unused,$maxsizechg);
12962: foreach my $field (@{$changes{'helpform'}}) {
12963: if ($field eq 'maxsize') {
12964: $maxsizechg = 1;
12965: next;
12966: }
12967: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 12968: push(@optional,$field);
1.286 raeburn 12969: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
12970: push(@unused,$field);
12971: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 12972: push(@required,$field);
1.286 raeburn 12973: }
12974: }
12975: if (@optional) {
12976: $resulttext .= '<li>'.
12977: &mt('Help form fields changed to "Optional": [_1].',
12978: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
12979: '</li>';
12980: }
12981: if (@required) {
12982: $resulttext .= '<li>'.
12983: &mt('Help form fields changed to "Required": [_1].',
12984: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
12985: '</li>';
12986: }
12987: if (@unused) {
12988: $resulttext .= '<li>'.
12989: &mt('Help form fields changed to "Not shown": [_1].',
12990: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
12991: '</li>';
12992: }
12993: if ($maxsizechg) {
12994: $resulttext .= '<li>'.
12995: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
12996: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
12997: '</li>';
12998: }
12999: }
1.28 raeburn 13000: $resulttext .= '</ul>';
13001: } else {
1.288 raeburn 13002: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 13003: }
13004: } else {
13005: $resulttext = '<span class="LC_error">'.
13006: &mt('An error occurred: [_1].',$putresult).'</span>';
13007: }
13008: return $resulttext;
13009: }
13010:
13011: sub modify_usercreation {
1.27 raeburn 13012: my ($dom,%domconfig) = @_;
1.224 raeburn 13013: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 13014: my $warningmsg;
1.27 raeburn 13015: if (ref($domconfig{'usercreation'}) eq 'HASH') {
13016: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 13017: if ($key eq 'cancreate') {
13018: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
13019: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 13020: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
13021: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13022: } else {
1.224 raeburn 13023: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13024: }
13025: }
13026: }
13027: } elsif ($key eq 'email_rule') {
13028: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
13029: } else {
13030: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
13031: }
1.27 raeburn 13032: }
13033: }
13034: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 13035: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 13036: my @contexts = ('author','course','requestcrs');
1.34 raeburn 13037: foreach my $item(@contexts) {
1.224 raeburn 13038: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 13039: }
1.34 raeburn 13040: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13041: foreach my $item (@contexts) {
1.224 raeburn 13042: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
13043: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 13044: }
1.27 raeburn 13045: }
1.34 raeburn 13046: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
13047: foreach my $item (@contexts) {
1.43 raeburn 13048: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 13049: if ($cancreate{$item} ne 'any') {
13050: push(@{$changes{'cancreate'}},$item);
13051: }
13052: } else {
13053: if ($cancreate{$item} ne 'none') {
13054: push(@{$changes{'cancreate'}},$item);
13055: }
1.27 raeburn 13056: }
13057: }
13058: } else {
1.43 raeburn 13059: foreach my $item (@contexts) {
1.34 raeburn 13060: push(@{$changes{'cancreate'}},$item);
13061: }
1.27 raeburn 13062: }
1.34 raeburn 13063:
1.27 raeburn 13064: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
13065: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
13066: if (!grep(/^\Q$type\E$/,@username_rule)) {
13067: push(@{$changes{'username_rule'}},$type);
13068: }
13069: }
13070: foreach my $type (@username_rule) {
13071: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
13072: push(@{$changes{'username_rule'}},$type);
13073: }
13074: }
13075: } else {
13076: push(@{$changes{'username_rule'}},@username_rule);
13077: }
13078:
1.32 raeburn 13079: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
13080: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
13081: if (!grep(/^\Q$type\E$/,@id_rule)) {
13082: push(@{$changes{'id_rule'}},$type);
13083: }
13084: }
13085: foreach my $type (@id_rule) {
13086: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
13087: push(@{$changes{'id_rule'}},$type);
13088: }
13089: }
13090: } else {
13091: push(@{$changes{'id_rule'}},@id_rule);
13092: }
13093:
1.43 raeburn 13094: my @authen_contexts = ('author','course','domain');
1.325 raeburn 13095: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 13096: my %authhash;
1.43 raeburn 13097: foreach my $item (@authen_contexts) {
1.28 raeburn 13098: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
13099: foreach my $auth (@authtypes) {
13100: if (grep(/^\Q$auth\E$/,@authallowed)) {
13101: $authhash{$item}{$auth} = 1;
13102: } else {
13103: $authhash{$item}{$auth} = 0;
13104: }
13105: }
13106: }
13107: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 13108: foreach my $item (@authen_contexts) {
1.28 raeburn 13109: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
13110: foreach my $auth (@authtypes) {
13111: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
13112: push(@{$changes{'authtypes'}},$item);
13113: last;
13114: }
13115: }
13116: }
13117: }
13118: } else {
1.43 raeburn 13119: foreach my $item (@authen_contexts) {
1.28 raeburn 13120: push(@{$changes{'authtypes'}},$item);
13121: }
13122: }
13123:
1.224 raeburn 13124: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
13125: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
13126: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
13127: $save_usercreate{'id_rule'} = \@id_rule;
13128: $save_usercreate{'username_rule'} = \@username_rule,
13129: $save_usercreate{'authtypes'} = \%authhash;
13130:
1.27 raeburn 13131: my %usercreation_hash = (
1.224 raeburn 13132: usercreation => \%save_usercreate,
13133: );
1.27 raeburn 13134:
13135: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
13136: $dom);
1.50 raeburn 13137:
1.224 raeburn 13138: if ($putresult eq 'ok') {
13139: if (keys(%changes) > 0) {
13140: $resulttext = &mt('Changes made:').'<ul>';
13141: if (ref($changes{'cancreate'}) eq 'ARRAY') {
13142: my %lt = &usercreation_types();
13143: foreach my $type (@{$changes{'cancreate'}}) {
13144: my $chgtext = $lt{$type}.', ';
13145: if ($cancreate{$type} eq 'none') {
13146: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
13147: } elsif ($cancreate{$type} eq 'any') {
13148: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
13149: } elsif ($cancreate{$type} eq 'official') {
13150: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
13151: } elsif ($cancreate{$type} eq 'unofficial') {
13152: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
13153: }
13154: $resulttext .= '<li>'.$chgtext.'</li>';
13155: }
13156: }
13157: if (ref($changes{'username_rule'}) eq 'ARRAY') {
13158: my ($rules,$ruleorder) =
13159: &Apache::lonnet::inst_userrules($dom,'username');
13160: my $chgtext = '<ul>';
13161: foreach my $type (@username_rule) {
13162: if (ref($rules->{$type}) eq 'HASH') {
13163: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
13164: }
13165: }
13166: $chgtext .= '</ul>';
13167: if (@username_rule > 0) {
13168: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13169: } else {
13170: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
13171: }
13172: }
13173: if (ref($changes{'id_rule'}) eq 'ARRAY') {
13174: my ($idrules,$idruleorder) =
13175: &Apache::lonnet::inst_userrules($dom,'id');
13176: my $chgtext = '<ul>';
13177: foreach my $type (@id_rule) {
13178: if (ref($idrules->{$type}) eq 'HASH') {
13179: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
13180: }
13181: }
13182: $chgtext .= '</ul>';
13183: if (@id_rule > 0) {
13184: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
13185: } else {
13186: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
13187: }
13188: }
13189: my %authname = &authtype_names();
13190: my %context_title = &context_names();
13191: if (ref($changes{'authtypes'}) eq 'ARRAY') {
13192: my $chgtext = '<ul>';
13193: foreach my $type (@{$changes{'authtypes'}}) {
13194: my @allowed;
13195: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
13196: foreach my $auth (@authtypes) {
13197: if ($authhash{$type}{$auth}) {
13198: push(@allowed,$authname{$auth});
13199: }
13200: }
13201: if (@allowed > 0) {
13202: $chgtext .= join(', ',@allowed).'</li>';
13203: } else {
13204: $chgtext .= &mt('none').'</li>';
13205: }
13206: }
13207: $chgtext .= '</ul>';
13208: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
13209: $resulttext .= '</li>';
13210: }
13211: $resulttext .= '</ul>';
13212: } else {
13213: $resulttext = &mt('No changes made to user creation settings');
13214: }
13215: } else {
13216: $resulttext = '<span class="LC_error">'.
13217: &mt('An error occurred: [_1]',$putresult).'</span>';
13218: }
13219: if ($warningmsg ne '') {
13220: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
13221: }
13222: return $resulttext;
13223: }
13224:
13225: sub modify_selfcreation {
1.305 raeburn 13226: my ($dom,$lastactref,%domconfig) = @_;
13227: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
13228: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
13229: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 13230: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
13231: if (ref($typesref) eq 'ARRAY') {
13232: @types = @{$typesref};
13233: }
13234: if (ref($usertypesref) eq 'HASH') {
13235: %usertypes = %{$usertypesref};
1.228 raeburn 13236: }
1.303 raeburn 13237: $usertypes{'default'} = $othertitle;
1.224 raeburn 13238: #
13239: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
13240: #
13241: if (ref($domconfig{'usercreation'}) eq 'HASH') {
13242: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
13243: if ($key eq 'cancreate') {
13244: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
13245: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
13246: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 13247: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
13248: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
13249: ($item eq 'emailusername') || ($item eq 'shibenv') ||
13250: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 13251: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 13252: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13253: } else {
13254: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
13255: }
13256: }
13257: }
13258: } elsif ($key eq 'email_rule') {
13259: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
13260: } else {
13261: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
13262: }
13263: }
13264: }
13265: #
13266: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
13267: #
13268: if (ref($domconfig{'usermodification'}) eq 'HASH') {
13269: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
13270: if ($key eq 'selfcreate') {
13271: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
13272: } else {
13273: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
13274: }
13275: }
13276: }
1.305 raeburn 13277: #
13278: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
13279: #
13280: if (ref($domconfig{'inststatus'}) eq 'HASH') {
13281: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
13282: if ($key eq 'inststatusguest') {
13283: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
13284: } else {
13285: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
13286: }
13287: }
13288: }
1.224 raeburn 13289:
13290: my @contexts = ('selfcreate');
13291: @{$cancreate{'selfcreate'}} = ();
13292: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 13293: if (@types) {
13294: @{$cancreate{'statustocreate'}} = ();
13295: }
1.236 raeburn 13296: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 13297: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 13298: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 13299: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 13300: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 13301: my %selfcreatetypes = (
13302: sso => 'users authenticated by institutional single sign on',
13303: login => 'users authenticated by institutional log-in',
1.303 raeburn 13304: email => 'users verified by e-mail',
1.50 raeburn 13305: );
1.224 raeburn 13306: #
13307: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
13308: # is permitted.
13309: #
1.305 raeburn 13310: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 13311:
1.305 raeburn 13312: my (@statuses,%email_rule);
1.228 raeburn 13313: foreach my $item ('login','sso','email') {
1.224 raeburn 13314: if ($item eq 'email') {
1.236 raeburn 13315: if ($env{'form.cancreate_email'}) {
1.305 raeburn 13316: if (@types) {
13317: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
13318: foreach my $status (@poss_statuses) {
13319: if (grep(/^\Q$status\E$/,(@types,'default'))) {
13320: push(@statuses,$status);
13321: }
13322: }
13323: $save_inststatus{'inststatusguest'} = \@statuses;
13324: } else {
13325: push(@statuses,'default');
13326: }
13327: if (@statuses) {
13328: my %curr_rule;
13329: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
13330: foreach my $type (@statuses) {
13331: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 13332: }
1.305 raeburn 13333: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
13334: foreach my $type (@statuses) {
13335: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
13336: }
13337: }
13338: push(@{$cancreate{'selfcreate'}},'email');
13339: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
13340: my %curremaildom;
13341: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
13342: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
13343: }
13344: foreach my $type (@statuses) {
13345: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
13346: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
13347: }
13348: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
13349: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
13350: }
13351: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
13352: #
13353: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
13354: #
13355: my $chosen = $1;
13356: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
13357: my $emaildom;
13358: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
13359: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
13360: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
13361: if (ref($curremaildom{$type}) eq 'HASH') {
13362: if (exists($curremaildom{$type}{$chosen})) {
13363: if ($curremaildom{$type}{$chosen} ne $emaildom) {
13364: push(@{$changes{'cancreate'}},'emaildomain');
13365: }
13366: } elsif ($emaildom ne '') {
13367: push(@{$changes{'cancreate'}},'emaildomain');
13368: }
13369: } elsif ($emaildom ne '') {
13370: push(@{$changes{'cancreate'}},'emaildomain');
13371: }
13372: }
13373: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13374: } elsif ($chosen eq 'custom') {
13375: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
13376: $email_rule{$type} = [];
13377: if (ref($emailrules) eq 'HASH') {
13378: foreach my $rule (@possemail_rules) {
13379: if (exists($emailrules->{$rule})) {
13380: push(@{$email_rule{$type}},$rule);
13381: }
13382: }
13383: }
13384: if (@{$email_rule{$type}}) {
13385: $cancreate{'emailoptions'}{$type} = 'custom';
13386: if (ref($curr_rule{$type}) eq 'ARRAY') {
13387: if (@{$curr_rule{$type}} > 0) {
13388: foreach my $rule (@{$curr_rule{$type}}) {
13389: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
13390: push(@{$changes{'email_rule'}},$type);
13391: }
13392: }
13393: }
13394: foreach my $type (@{$email_rule{$type}}) {
13395: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
13396: push(@{$changes{'email_rule'}},$type);
13397: }
13398: }
13399: } else {
13400: push(@{$changes{'email_rule'}},$type);
13401: }
13402: }
13403: } else {
13404: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
13405: }
13406: }
13407: }
13408: if (@types) {
13409: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13410: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
13411: if (@changed) {
13412: push(@{$changes{'inststatus'}},'inststatusguest');
13413: }
13414: } else {
13415: push(@{$changes{'inststatus'}},'inststatusguest');
13416: }
13417: }
13418: } else {
13419: delete($env{'form.cancreate_email'});
13420: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13421: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13422: push(@{$changes{'inststatus'}},'inststatusguest');
13423: }
13424: }
13425: }
13426: } else {
13427: $save_inststatus{'inststatusguest'} = [];
13428: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
13429: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
13430: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 13431: }
13432: }
1.224 raeburn 13433: }
13434: } else {
13435: if ($env{'form.cancreate_'.$item}) {
13436: push(@{$cancreate{'selfcreate'}},$item);
13437: }
13438: }
13439: }
1.305 raeburn 13440: my (%userinfo,%savecaptcha);
1.224 raeburn 13441: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
13442: #
1.228 raeburn 13443: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
13444: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 13445: #
1.236 raeburn 13446:
1.244 raeburn 13447: if ($env{'form.cancreate_email'}) {
1.228 raeburn 13448: push(@contexts,'emailusername');
1.305 raeburn 13449: if (@statuses) {
13450: foreach my $type (@statuses) {
1.228 raeburn 13451: if (ref($infofields) eq 'ARRAY') {
13452: foreach my $field (@{$infofields}) {
13453: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
13454: $cancreate{'emailusername'}{$type}{$field} = $1;
13455: }
13456: }
1.224 raeburn 13457: }
13458: }
13459: }
13460: #
13461: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 13462: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 13463: #
13464:
13465: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
13466: @approvalnotify = sort(@approvalnotify);
13467: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
13468: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13469: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
13470: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
13471: push(@{$changes{'cancreate'}},'notify');
13472: }
13473: } else {
13474: if ($cancreate{'notify'}{'approval'}) {
13475: push(@{$changes{'cancreate'}},'notify');
13476: }
13477: }
13478: } elsif ($cancreate{'notify'}{'approval'}) {
13479: push(@{$changes{'cancreate'}},'notify');
13480: }
13481:
13482: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
13483: }
13484: #
1.236 raeburn 13485: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 13486: # institutional log-in.
13487: #
13488: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
13489: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
13490: ($domdefaults{'auth_def'} eq 'localauth'))) {
13491: $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.').' '.
13492: &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.');
13493: }
13494: }
13495: my @fields = ('lastname','firstname','middlename','generation',
13496: 'permanentemail','id');
1.240 raeburn 13497: my @shibfields = (@fields,'inststatus');
1.224 raeburn 13498: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13499: #
13500: # Where usernames may created for institutional log-in and/or institutional single sign on:
13501: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
13502: # may self-create accounts
13503: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
13504: # which the user may supply, if institutional data is unavailable.
13505: #
13506: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 13507: if (@types) {
1.305 raeburn 13508: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
13509: push(@contexts,'statustocreate');
1.303 raeburn 13510: foreach my $type (@types) {
1.224 raeburn 13511: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
13512: foreach my $field (@fields) {
13513: if (grep(/^\Q$field\E$/,@modifiable)) {
13514: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
13515: } else {
13516: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
13517: }
13518: }
13519: }
13520: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 13521: foreach my $type (@types) {
1.224 raeburn 13522: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
13523: foreach my $field (@fields) {
13524: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
13525: $curr_usermodify{'selfcreate'}{$type}{$field}) {
13526: push(@{$changes{'selfcreate'}},$type);
13527: last;
13528: }
13529: }
13530: }
13531: }
13532: } else {
1.303 raeburn 13533: foreach my $type (@types) {
1.224 raeburn 13534: push(@{$changes{'selfcreate'}},$type);
13535: }
13536: }
13537: }
1.240 raeburn 13538: foreach my $field (@shibfields) {
13539: if ($env{'form.shibenv_'.$field} ne '') {
13540: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
13541: }
13542: }
13543: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
13544: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
13545: foreach my $field (@shibfields) {
13546: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
13547: push(@{$changes{'cancreate'}},'shibenv');
13548: }
13549: }
13550: } else {
13551: foreach my $field (@shibfields) {
13552: if ($env{'form.shibenv_'.$field}) {
13553: push(@{$changes{'cancreate'}},'shibenv');
13554: last;
13555: }
13556: }
13557: }
13558: }
1.224 raeburn 13559: }
13560: foreach my $item (@contexts) {
13561: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
13562: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
13563: if (ref($cancreate{$item}) eq 'ARRAY') {
13564: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
13565: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13566: push(@{$changes{'cancreate'}},$item);
13567: }
13568: }
13569: }
13570: }
13571: if (ref($cancreate{$item}) eq 'ARRAY') {
13572: foreach my $type (@{$cancreate{$item}}) {
13573: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
13574: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13575: push(@{$changes{'cancreate'}},$item);
13576: }
13577: }
13578: }
13579: }
13580: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
13581: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 13582: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
13583: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13584: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
13585: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 13586: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13587: push(@{$changes{'cancreate'}},$item);
13588: }
13589: }
13590: }
1.305 raeburn 13591: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13592: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 13593: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13594: push(@{$changes{'cancreate'}},$item);
13595: }
1.224 raeburn 13596: }
13597: }
13598: }
1.305 raeburn 13599: foreach my $type (keys(%{$cancreate{$item}})) {
13600: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13601: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13602: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
13603: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 13604: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13605: push(@{$changes{'cancreate'}},$item);
13606: }
13607: }
13608: } else {
13609: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13610: push(@{$changes{'cancreate'}},$item);
13611: }
13612: }
13613: }
1.305 raeburn 13614: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13615: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 13616: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13617: push(@{$changes{'cancreate'}},$item);
13618: }
1.224 raeburn 13619: }
13620: }
13621: }
13622: }
13623: } elsif ($curr_usercreation{'cancreate'}{$item}) {
13624: if (ref($cancreate{$item}) eq 'ARRAY') {
13625: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
13626: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13627: push(@{$changes{'cancreate'}},$item);
13628: }
13629: }
1.305 raeburn 13630: }
13631: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
13632: if (ref($cancreate{$item}) eq 'HASH') {
13633: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13634: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 13635: }
13636: }
13637: } elsif ($item eq 'emailusername') {
1.228 raeburn 13638: if (ref($cancreate{$item}) eq 'HASH') {
13639: foreach my $type (keys(%{$cancreate{$item}})) {
13640: if (ref($cancreate{$item}{$type}) eq 'HASH') {
13641: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
13642: if ($cancreate{$item}{$type}{$field}) {
13643: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
13644: push(@{$changes{'cancreate'}},$item);
13645: }
13646: last;
13647: }
13648: }
13649: }
13650: }
1.224 raeburn 13651: }
13652: }
13653: }
13654: #
13655: # Populate %save_usercreate hash with updates to self-creation configuration.
13656: #
13657: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
13658: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 13659: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 13660: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
13661: if (ref($cancreate{'notify'}) eq 'HASH') {
13662: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
13663: }
1.236 raeburn 13664: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
13665: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
13666: }
1.303 raeburn 13667: if (ref($cancreate{'emailverified'}) eq 'HASH') {
13668: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
13669: }
1.305 raeburn 13670: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
13671: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
13672: }
1.303 raeburn 13673: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
13674: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
13675: }
1.224 raeburn 13676: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13677: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
13678: }
1.240 raeburn 13679: if (ref($cancreate{'shibenv'}) eq 'HASH') {
13680: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
13681: }
1.224 raeburn 13682: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 13683: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 13684:
13685: my %userconfig_hash = (
13686: usercreation => \%save_usercreate,
13687: usermodification => \%save_usermodify,
1.305 raeburn 13688: inststatus => \%save_inststatus,
1.224 raeburn 13689: );
1.305 raeburn 13690:
1.224 raeburn 13691: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
13692: $dom);
13693: #
1.305 raeburn 13694: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 13695: #
1.27 raeburn 13696: if ($putresult eq 'ok') {
13697: if (keys(%changes) > 0) {
13698: $resulttext = &mt('Changes made:').'<ul>';
13699: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 13700: my %lt = &selfcreation_types();
1.34 raeburn 13701: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 13702: my $chgtext = '';
1.45 raeburn 13703: if ($type eq 'selfcreate') {
1.50 raeburn 13704: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 13705: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 13706: } else {
1.224 raeburn 13707: $chgtext .= &mt('Self-creation of a new account is permitted for:').
13708: '<ul>';
1.50 raeburn 13709: foreach my $case (@{$cancreate{$type}}) {
13710: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
13711: }
13712: $chgtext .= '</ul>';
1.100 raeburn 13713: if (ref($cancreate{$type}) eq 'ARRAY') {
13714: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
13715: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
13716: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 13717: $chgtext .= '<span class="LC_warning">'.
13718: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
13719: '</span><br />';
13720: }
13721: }
13722: }
13723: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 13724: if (!@statuses) {
13725: $chgtext .= '<span class="LC_warning">'.
13726: &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.").
13727: '</span><br />';
1.303 raeburn 13728:
1.100 raeburn 13729: }
13730: }
13731: }
1.43 raeburn 13732: }
1.240 raeburn 13733: } elsif ($type eq 'shibenv') {
13734: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 13735: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 13736: } else {
13737: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
13738: '<ul>';
13739: foreach my $field (@shibfields) {
13740: next if ($cancreate{$type}{$field} eq '');
13741: if ($field eq 'inststatus') {
13742: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
13743: } else {
13744: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
13745: }
13746: }
13747: $chgtext .= '</ul>';
1.303 raeburn 13748: }
1.93 raeburn 13749: } elsif ($type eq 'statustocreate') {
1.96 raeburn 13750: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
13751: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
13752: if (@{$cancreate{'selfcreate'}} > 0) {
13753: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 13754: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 13755: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 13756: $chgtext .= '<br />'.
13757: '<span class="LC_warning">'.
13758: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
13759: '</span>';
13760: }
1.303 raeburn 13761: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 13762: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 13763: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
13764: } else {
13765: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
13766: }
13767: $chgtext .= '<ul>';
13768: foreach my $case (@{$cancreate{$type}}) {
13769: if ($case eq 'default') {
13770: $chgtext .= '<li>'.$othertitle.'</li>';
13771: } else {
1.303 raeburn 13772: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 13773: }
13774: }
1.100 raeburn 13775: $chgtext .= '</ul>';
13776: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 13777: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 13778: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
13779: '</span>';
1.100 raeburn 13780: }
13781: }
13782: } else {
13783: if (@{$cancreate{$type}} == 0) {
13784: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
13785: } else {
13786: $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 13787: }
13788: }
1.303 raeburn 13789: $chgtext .= '<br />';
1.93 raeburn 13790: }
1.236 raeburn 13791: } elsif ($type eq 'selfcreateprocessing') {
13792: my %choices = &Apache::lonlocal::texthash (
13793: automatic => 'Automatic approval',
13794: approval => 'Queued for approval',
13795: );
1.305 raeburn 13796: if (@types) {
13797: if (@statuses) {
1.303 raeburn 13798: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 13799: '<ul>';
1.305 raeburn 13800: foreach my $status (@statuses) {
13801: if ($status eq 'default') {
13802: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 13803: } else {
1.305 raeburn 13804: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 13805: }
13806: }
13807: $chgtext .= '</ul>';
13808: }
13809: } else {
13810: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
13811: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
13812: }
13813: } elsif ($type eq 'emailverified') {
13814: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 13815: all => 'Same as e-mail',
13816: first => 'Omit @domain',
13817: free => 'Free to choose',
1.303 raeburn 13818: );
1.305 raeburn 13819: if (@types) {
13820: if (@statuses) {
1.303 raeburn 13821: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
13822: '<ul>';
1.305 raeburn 13823: foreach my $status (@statuses) {
1.303 raeburn 13824: if ($type eq 'default') {
1.305 raeburn 13825: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 13826: } else {
1.305 raeburn 13827: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 13828: }
13829: }
13830: $chgtext .= '</ul>';
13831: }
13832: } else {
1.305 raeburn 13833: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 13834: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 13835: }
1.305 raeburn 13836: } elsif ($type eq 'emailoptions') {
13837: my %options = &Apache::lonlocal::texthash (
13838: any => 'Any e-mail',
13839: inst => 'Institutional only',
13840: noninst => 'Non-institutional only',
13841: custom => 'Custom restrictions',
13842: );
13843: if (@types) {
13844: if (@statuses) {
13845: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
13846: '<ul>';
13847: foreach my $status (@statuses) {
13848: if ($type eq 'default') {
13849: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
13850: } else {
13851: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 13852: }
13853: }
1.305 raeburn 13854: $chgtext .= '</ul>';
13855: }
13856: } else {
13857: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
13858: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
13859: } else {
13860: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
13861: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 13862: }
1.305 raeburn 13863: }
13864: } elsif ($type eq 'emaildomain') {
13865: my $output;
13866: if (@statuses) {
13867: foreach my $type (@statuses) {
13868: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
13869: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
13870: if ($type eq 'default') {
13871: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13872: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
13873: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
13874: } else {
13875: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
13876: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
13877: }
1.303 raeburn 13878: } else {
1.305 raeburn 13879: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13880: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
13881: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
13882: } else {
13883: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
13884: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
13885: }
1.303 raeburn 13886: }
1.305 raeburn 13887: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
13888: if ($type eq 'default') {
13889: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13890: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
13891: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
13892: } else {
13893: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
13894: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
13895: }
1.303 raeburn 13896: } else {
1.305 raeburn 13897: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
13898: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
13899: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
13900: } else {
13901: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
13902: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
13903: }
1.303 raeburn 13904: }
13905: }
13906: }
13907: }
1.305 raeburn 13908: }
13909: if ($output ne '') {
13910: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
13911: '<ul>'.$output.'</ul>';
1.236 raeburn 13912: }
1.165 raeburn 13913: } elsif ($type eq 'captcha') {
1.224 raeburn 13914: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 13915: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
13916: } else {
13917: my %captchas = &captcha_phrases();
1.224 raeburn 13918: if ($captchas{$savecaptcha{$type}}) {
13919: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 13920: } else {
1.210 raeburn 13921: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 13922: }
13923: }
13924: } elsif ($type eq 'recaptchakeys') {
13925: my ($privkey,$pubkey);
1.224 raeburn 13926: if (ref($savecaptcha{$type}) eq 'HASH') {
13927: $pubkey = $savecaptcha{$type}{'public'};
13928: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 13929: }
13930: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
13931: if (!$pubkey) {
13932: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
13933: } else {
13934: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
13935: }
13936: if (!$privkey) {
13937: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
13938: } else {
13939: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
13940: }
13941: $chgtext .= '</ul>';
1.269 raeburn 13942: } elsif ($type eq 'recaptchaversion') {
13943: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 13944: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 13945: }
1.224 raeburn 13946: } elsif ($type eq 'emailusername') {
13947: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 13948: if (@statuses) {
13949: foreach my $type (@statuses) {
1.228 raeburn 13950: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
13951: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 13952: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 13953: '<ul>';
13954: foreach my $field (@{$infofields}) {
13955: if ($cancreate{'emailusername'}{$type}{$field}) {
13956: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
13957: }
13958: }
1.245 raeburn 13959: $chgtext .= '</ul>';
13960: } else {
1.303 raeburn 13961: $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 13962: }
13963: } else {
1.303 raeburn 13964: $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 13965: }
13966: }
13967: }
13968: }
13969: } elsif ($type eq 'notify') {
1.303 raeburn 13970: my $numapprove = 0;
1.224 raeburn 13971: if (ref($changes{'cancreate'}) eq 'ARRAY') {
13972: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
13973: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 13974: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
13975: $numapprove ++;
1.224 raeburn 13976: }
13977: }
1.43 raeburn 13978: }
1.303 raeburn 13979: unless ($numapprove) {
13980: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
13981: }
1.34 raeburn 13982: }
1.224 raeburn 13983: if ($chgtext) {
13984: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 13985: }
13986: }
13987: }
1.305 raeburn 13988: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 13989: my ($emailrules,$emailruleorder) =
13990: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 13991: foreach my $type (@{$changes{'email_rule'}}) {
13992: if (ref($email_rule{$type}) eq 'ARRAY') {
13993: my $chgtext = '<ul>';
13994: foreach my $rule (@{$email_rule{$type}}) {
13995: if (ref($emailrules->{$rule}) eq 'HASH') {
13996: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
13997: }
13998: }
13999: $chgtext .= '</ul>';
1.310 raeburn 14000: my $typename;
1.305 raeburn 14001: if (@types) {
14002: if ($type eq 'default') {
14003: $typename = $othertitle;
14004: } else {
14005: $typename = $usertypes{$type};
14006: }
14007: $chgtext .= &mt('(Affiliation: [_1])',$typename);
14008: }
14009: if (@{$email_rule{$type}} > 0) {
14010: $resulttext .= '<li>'.
14011: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
14012: $usertypes{$type}).
14013: $chgtext.
14014: '</li>';
14015: } else {
14016: $resulttext .= '<li>'.
1.310 raeburn 14017: &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 14018: '</li>'.
1.310 raeburn 14019: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 14020: }
1.43 raeburn 14021: }
14022: }
1.305 raeburn 14023: }
14024: if (ref($changes{'inststatus'}) eq 'ARRAY') {
14025: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
14026: if (@{$save_inststatus{'inststatusguest'}} > 0) {
14027: my $chgtext = '<ul>';
14028: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
14029: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
14030: }
14031: $chgtext .= '</ul>';
14032: $resulttext .= '<li>'.
14033: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
14034: $chgtext.
14035: '</li>';
14036: } else {
14037: $resulttext .= '<li>'.
14038: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
14039: '</li>';
14040: }
1.43 raeburn 14041: }
14042: }
1.224 raeburn 14043: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
14044: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
14045: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14046: foreach my $type (@{$changes{'selfcreate'}}) {
14047: my $typename = $type;
1.303 raeburn 14048: if (keys(%usertypes) > 0) {
14049: if ($usertypes{$type} ne '') {
14050: $typename = $usertypes{$type};
1.224 raeburn 14051: }
14052: }
14053: my @modifiable;
14054: $resulttext .= '<li>'.
14055: &mt('Self-creation of account by users with status: [_1]',
14056: '<span class="LC_cusr_emph">'.$typename.'</span>').
14057: ' - '.&mt('modifiable fields (if institutional data blank): ');
14058: foreach my $field (@fields) {
14059: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
14060: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 14061: }
14062: }
1.224 raeburn 14063: if (@modifiable > 0) {
14064: $resulttext .= join(', ',@modifiable);
1.43 raeburn 14065: } else {
1.224 raeburn 14066: $resulttext .= &mt('none');
1.43 raeburn 14067: }
1.224 raeburn 14068: $resulttext .= '</li>';
1.28 raeburn 14069: }
1.224 raeburn 14070: $resulttext .= '</ul></li>';
1.28 raeburn 14071: }
1.27 raeburn 14072: $resulttext .= '</ul>';
1.305 raeburn 14073: my $cachetime = 24*60*60;
14074: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
14075: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14076: if (ref($lastactref) eq 'HASH') {
14077: $lastactref->{'domdefaults'} = 1;
14078: }
1.27 raeburn 14079: } else {
1.224 raeburn 14080: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 14081: }
14082: } else {
14083: $resulttext = '<span class="LC_error">'.
1.23 raeburn 14084: &mt('An error occurred: [_1]',$putresult).'</span>';
14085: }
1.43 raeburn 14086: if ($warningmsg ne '') {
14087: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
14088: }
1.23 raeburn 14089: return $resulttext;
14090: }
14091:
1.165 raeburn 14092: sub process_captcha {
14093: my ($container,$changes,$newsettings,$current) = @_;
14094: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
14095: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
14096: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
14097: $newsettings->{'captcha'} = 'original';
14098: }
14099: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 14100: if ($container eq 'cancreate') {
1.169 raeburn 14101: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14102: push(@{$changes->{'cancreate'}},'captcha');
14103: } elsif (!defined($changes->{'cancreate'})) {
14104: $changes->{'cancreate'} = ['captcha'];
14105: }
14106: } else {
14107: $changes->{'captcha'} = 1;
1.165 raeburn 14108: }
14109: }
1.269 raeburn 14110: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 14111: if ($newsettings->{'captcha'} eq 'recaptcha') {
14112: $newpub = $env{'form.'.$container.'_recaptchapub'};
14113: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 14114: $newpub =~ s/[^\w\-]//g;
14115: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 14116: $newsettings->{'recaptchakeys'} = {
14117: public => $newpub,
14118: private => $newpriv,
14119: };
1.269 raeburn 14120: $newversion = $env{'form.'.$container.'_recaptchaversion'};
14121: $newversion =~ s/\D//g;
14122: if ($newversion ne '2') {
14123: $newversion = 1;
14124: }
14125: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 14126: }
14127: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
14128: $currpub = $current->{'recaptchakeys'}{'public'};
14129: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 14130: unless ($newsettings->{'captcha'} eq 'recaptcha') {
14131: $newsettings->{'recaptchakeys'} = {
14132: public => '',
14133: private => '',
14134: }
14135: }
1.165 raeburn 14136: }
1.269 raeburn 14137: if ($current->{'captcha'} eq 'recaptcha') {
14138: $currversion = $current->{'recaptchaversion'};
14139: if ($currversion ne '2') {
14140: $currversion = 1;
14141: }
14142: }
14143: if ($currversion ne $newversion) {
14144: if ($container eq 'cancreate') {
14145: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14146: push(@{$changes->{'cancreate'}},'recaptchaversion');
14147: } elsif (!defined($changes->{'cancreate'})) {
14148: $changes->{'cancreate'} = ['recaptchaversion'];
14149: }
14150: } else {
14151: $changes->{'recaptchaversion'} = 1;
14152: }
14153: }
1.165 raeburn 14154: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 14155: if ($container eq 'cancreate') {
14156: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
14157: push(@{$changes->{'cancreate'}},'recaptchakeys');
14158: } elsif (!defined($changes->{'cancreate'})) {
14159: $changes->{'cancreate'} = ['recaptchakeys'];
14160: }
14161: } else {
1.210 raeburn 14162: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 14163: }
14164: }
14165: return;
14166: }
14167:
1.33 raeburn 14168: sub modify_usermodification {
14169: my ($dom,%domconfig) = @_;
1.224 raeburn 14170: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 14171: if (ref($domconfig{'usermodification'}) eq 'HASH') {
14172: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 14173: if ($key eq 'selfcreate') {
14174: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
14175: } else {
14176: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
14177: }
1.33 raeburn 14178: }
14179: }
1.224 raeburn 14180: my @contexts = ('author','course');
1.33 raeburn 14181: my %context_title = (
14182: author => 'In author context',
14183: course => 'In course context',
14184: );
14185: my @fields = ('lastname','firstname','middlename','generation',
14186: 'permanentemail','id');
14187: my %roles = (
14188: author => ['ca','aa'],
14189: course => ['st','ep','ta','in','cr'],
14190: );
14191: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14192: foreach my $context (@contexts) {
14193: foreach my $role (@{$roles{$context}}) {
14194: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
14195: foreach my $item (@fields) {
14196: if (grep(/^\Q$item\E$/,@modifiable)) {
14197: $modifyhash{$context}{$role}{$item} = 1;
14198: } else {
14199: $modifyhash{$context}{$role}{$item} = 0;
14200: }
14201: }
14202: }
14203: if (ref($curr_usermodification{$context}) eq 'HASH') {
14204: foreach my $role (@{$roles{$context}}) {
14205: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
14206: foreach my $field (@fields) {
14207: if ($modifyhash{$context}{$role}{$field} ne
14208: $curr_usermodification{$context}{$role}{$field}) {
14209: push(@{$changes{$context}},$role);
14210: last;
14211: }
14212: }
14213: }
14214: }
14215: } else {
14216: foreach my $context (@contexts) {
14217: foreach my $role (@{$roles{$context}}) {
14218: push(@{$changes{$context}},$role);
14219: }
14220: }
14221: }
14222: }
14223: my %usermodification_hash = (
14224: usermodification => \%modifyhash,
14225: );
14226: my $putresult = &Apache::lonnet::put_dom('configuration',
14227: \%usermodification_hash,$dom);
14228: if ($putresult eq 'ok') {
14229: if (keys(%changes) > 0) {
14230: $resulttext = &mt('Changes made: ').'<ul>';
14231: foreach my $context (@contexts) {
14232: if (ref($changes{$context}) eq 'ARRAY') {
14233: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
14234: if (ref($changes{$context}) eq 'ARRAY') {
14235: foreach my $role (@{$changes{$context}}) {
14236: my $rolename;
1.224 raeburn 14237: if ($role eq 'cr') {
14238: $rolename = &mt('Custom');
1.33 raeburn 14239: } else {
1.224 raeburn 14240: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 14241: }
14242: my @modifiable;
1.224 raeburn 14243: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 14244: foreach my $field (@fields) {
14245: if ($modifyhash{$context}{$role}{$field}) {
14246: push(@modifiable,$fieldtitles{$field});
14247: }
14248: }
14249: if (@modifiable > 0) {
14250: $resulttext .= join(', ',@modifiable);
14251: } else {
14252: $resulttext .= &mt('none');
14253: }
14254: $resulttext .= '</li>';
14255: }
14256: $resulttext .= '</ul></li>';
14257: }
14258: }
14259: }
14260: $resulttext .= '</ul>';
14261: } else {
14262: $resulttext = &mt('No changes made to user modification settings');
14263: }
14264: } else {
14265: $resulttext = '<span class="LC_error">'.
14266: &mt('An error occurred: [_1]',$putresult).'</span>';
14267: }
14268: return $resulttext;
14269: }
14270:
1.43 raeburn 14271: sub modify_defaults {
1.212 raeburn 14272: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 14273: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 14274: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 14275: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
14276: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.325 raeburn 14277: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 14278: foreach my $item (@items) {
14279: $newvalues{$item} = $env{'form.'.$item};
14280: if ($item eq 'auth_def') {
14281: if ($newvalues{$item} ne '') {
14282: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
14283: push(@errors,$item);
14284: }
14285: }
14286: } elsif ($item eq 'lang_def') {
14287: if ($newvalues{$item} ne '') {
14288: if ($newvalues{$item} =~ /^(\w+)/) {
14289: my $langcode = $1;
1.103 raeburn 14290: if ($langcode ne 'x_chef') {
14291: if (code2language($langcode) eq '') {
14292: push(@errors,$item);
14293: }
1.43 raeburn 14294: }
14295: } else {
14296: push(@errors,$item);
14297: }
14298: }
1.54 raeburn 14299: } elsif ($item eq 'timezone_def') {
14300: if ($newvalues{$item} ne '') {
1.62 raeburn 14301: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 14302: push(@errors,$item);
14303: }
14304: }
1.68 raeburn 14305: } elsif ($item eq 'datelocale_def') {
14306: if ($newvalues{$item} ne '') {
14307: my @datelocale_ids = DateTime::Locale->ids();
14308: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
14309: push(@errors,$item);
14310: }
14311: }
1.141 raeburn 14312: } elsif ($item eq 'portal_def') {
14313: if ($newvalues{$item} ne '') {
14314: 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])\/?$/) {
14315: push(@errors,$item);
14316: }
14317: }
1.294 raeburn 14318: } elsif ($item eq 'intauth_cost') {
14319: if ($newvalues{$item} ne '') {
14320: if ($newvalues{$item} =~ /\D/) {
14321: push(@errors,$item);
14322: }
14323: }
14324: } elsif ($item eq 'intauth_check') {
14325: if ($newvalues{$item} ne '') {
14326: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
14327: push(@errors,$item);
14328: }
14329: }
14330: } elsif ($item eq 'intauth_switch') {
14331: if ($newvalues{$item} ne '') {
14332: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
14333: push(@errors,$item);
14334: }
14335: }
1.43 raeburn 14336: }
14337: if (grep(/^\Q$item\E$/,@errors)) {
14338: $newvalues{$item} = $domdefaults{$item};
14339: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
14340: $changes{$item} = 1;
14341: }
1.72 raeburn 14342: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 14343: }
14344: my %defaults_hash = (
1.72 raeburn 14345: defaults => \%newvalues,
14346: );
1.43 raeburn 14347: my $title = &defaults_titles();
1.236 raeburn 14348:
14349: my $currinststatus;
14350: if (ref($domconfig{'inststatus'}) eq 'HASH') {
14351: $currinststatus = $domconfig{'inststatus'};
14352: } else {
14353: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
14354: $currinststatus = {
14355: inststatustypes => $usertypes,
14356: inststatusorder => $types,
14357: inststatusguest => [],
14358: };
14359: }
14360: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
14361: my @allpos;
14362: my %alltypes;
1.305 raeburn 14363: my @inststatusguest;
14364: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
14365: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
14366: unless (grep(/^\Q$type\E$/,@todelete)) {
14367: push(@inststatusguest,$type);
14368: }
14369: }
14370: }
14371: my ($currtitles,$currorder);
1.236 raeburn 14372: if (ref($currinststatus) eq 'HASH') {
14373: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
14374: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
14375: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
14376: if ($currinststatus->{inststatustypes}->{$type} ne '') {
14377: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
14378: }
14379: }
14380: unless (grep(/^\Q$type\E$/,@todelete)) {
14381: my $position = $env{'form.inststatus_pos_'.$type};
14382: $position =~ s/\D+//g;
14383: $allpos[$position] = $type;
14384: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
14385: $alltypes{$type} =~ s/`//g;
14386: }
14387: }
14388: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
14389: $currtitles =~ s/,$//;
14390: }
14391: }
14392: if ($env{'form.addinststatus'}) {
14393: my $newtype = $env{'form.addinststatus'};
14394: $newtype =~ s/\W//g;
14395: unless (exists($alltypes{$newtype})) {
14396: $alltypes{$newtype} = $env{'form.addinststatus_title'};
14397: $alltypes{$newtype} =~ s/`//g;
14398: my $position = $env{'form.addinststatus_pos'};
14399: $position =~ s/\D+//g;
14400: if ($position ne '') {
14401: $allpos[$position] = $newtype;
14402: }
14403: }
14404: }
1.305 raeburn 14405: my @orderedstatus;
1.236 raeburn 14406: foreach my $type (@allpos) {
14407: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
14408: push(@orderedstatus,$type);
14409: }
14410: }
14411: foreach my $type (keys(%alltypes)) {
14412: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
14413: delete($alltypes{$type});
14414: }
14415: }
14416: $defaults_hash{'inststatus'} = {
14417: inststatustypes => \%alltypes,
14418: inststatusorder => \@orderedstatus,
1.305 raeburn 14419: inststatusguest => \@inststatusguest,
1.236 raeburn 14420: };
14421: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
14422: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
14423: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
14424: }
14425: }
14426: if ($currorder ne join(',',@orderedstatus)) {
14427: $changes{'inststatus'}{'inststatusorder'} = 1;
14428: }
14429: my $newtitles;
14430: foreach my $item (@orderedstatus) {
14431: $newtitles .= $alltypes{$item}.',';
14432: }
14433: $newtitles =~ s/,$//;
14434: if ($currtitles ne $newtitles) {
14435: $changes{'inststatus'}{'inststatustypes'} = 1;
14436: }
1.43 raeburn 14437: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
14438: $dom);
14439: if ($putresult eq 'ok') {
14440: if (keys(%changes) > 0) {
14441: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 14442: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 14443: 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";
14444: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 14445: if ($item eq 'inststatus') {
14446: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 14447: if (@orderedstatus) {
1.236 raeburn 14448: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
14449: foreach my $type (@orderedstatus) {
14450: $resulttext .= $alltypes{$type}.', ';
14451: }
14452: $resulttext =~ s/, $//;
14453: $resulttext .= '</li>';
1.305 raeburn 14454: } else {
14455: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 14456: }
14457: }
14458: } else {
14459: my $value = $env{'form.'.$item};
14460: if ($value eq '') {
14461: $value = &mt('none');
14462: } elsif ($item eq 'auth_def') {
14463: my %authnames = &authtype_names();
14464: my %shortauth = (
14465: internal => 'int',
14466: krb4 => 'krb4',
14467: krb5 => 'krb5',
14468: localauth => 'loc',
1.325 raeburn 14469: lti => 'lti',
1.236 raeburn 14470: );
14471: $value = $authnames{$shortauth{$value}};
1.294 raeburn 14472: } elsif ($item eq 'intauth_switch') {
14473: my %optiondesc = &Apache::lonlocal::texthash (
14474: 0 => 'No',
14475: 1 => 'Yes',
14476: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
14477: );
14478: if ($value =~ /^(0|1|2)$/) {
14479: $value = $optiondesc{$value};
14480: } else {
14481: $value = &mt('none -- defaults to No');
14482: }
14483: } elsif ($item eq 'intauth_check') {
14484: my %optiondesc = &Apache::lonlocal::texthash (
14485: 0 => 'No',
14486: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
14487: 2 => 'Yes, disallow login if stored cost is less than domain default',
14488: );
14489: if ($value =~ /^(0|1|2)$/) {
14490: $value = $optiondesc{$value};
14491: } else {
14492: $value = &mt('none -- defaults to No');
14493: }
1.236 raeburn 14494: }
14495: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
14496: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 14497: }
14498: }
14499: $resulttext .= '</ul>';
14500: $mailmsgtext .= "\n";
14501: my $cachetime = 24*60*60;
1.72 raeburn 14502: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 14503: if (ref($lastactref) eq 'HASH') {
14504: $lastactref->{'domdefaults'} = 1;
14505: }
1.68 raeburn 14506: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 14507: my $notify = 1;
14508: if (ref($domconfig{'contacts'}) eq 'HASH') {
14509: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
14510: $notify = 0;
14511: }
14512: }
14513: if ($notify) {
14514: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
14515: "LON-CAPA Domain Settings Change - $dom",
14516: $mailmsgtext);
14517: }
1.54 raeburn 14518: }
1.43 raeburn 14519: } else {
1.54 raeburn 14520: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 14521: }
14522: } else {
14523: $resulttext = '<span class="LC_error">'.
14524: &mt('An error occurred: [_1]',$putresult).'</span>';
14525: }
14526: if (@errors > 0) {
14527: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
14528: foreach my $item (@errors) {
14529: $resulttext .= ' "'.$title->{$item}.'",';
14530: }
14531: $resulttext =~ s/,$//;
14532: }
14533: return $resulttext;
14534: }
14535:
1.46 raeburn 14536: sub modify_scantron {
1.205 raeburn 14537: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 14538: my ($resulttext,%confhash,%changes,$errors);
14539: my $custom = 'custom.tab';
14540: my $default = 'default.tab';
14541: my $servadm = $r->dir_config('lonAdmEMail');
14542: my ($configuserok,$author_ok,$switchserver) =
14543: &config_check($dom,$confname,$servadm);
14544: if ($env{'form.scantronformat.filename'} ne '') {
14545: my $error;
14546: if ($configuserok eq 'ok') {
14547: if ($switchserver) {
1.130 raeburn 14548: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 14549: } else {
14550: if ($author_ok eq 'ok') {
14551: my ($result,$scantronurl) =
14552: &publishlogo($r,'upload','scantronformat',$dom,
14553: $confname,'scantron','','',$custom);
14554: if ($result eq 'ok') {
14555: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 14556: $changes{'scantronformat'} = 1;
1.46 raeburn 14557: } else {
14558: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
14559: }
14560: } else {
14561: $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);
14562: }
14563: }
14564: } else {
14565: $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);
14566: }
14567: if ($error) {
14568: &Apache::lonnet::logthis($error);
14569: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14570: }
14571: }
1.48 raeburn 14572: if (ref($domconfig{'scantron'}) eq 'HASH') {
14573: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
14574: if ($env{'form.scantronformat_del'}) {
14575: $confhash{'scantron'}{'scantronformat'} = '';
14576: $changes{'scantronformat'} = 1;
1.46 raeburn 14577: }
14578: }
14579: }
14580: if (keys(%confhash) > 0) {
14581: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
14582: $dom);
14583: if ($putresult eq 'ok') {
14584: if (keys(%changes) > 0) {
1.48 raeburn 14585: if (ref($confhash{'scantron'}) eq 'HASH') {
14586: $resulttext = &mt('Changes made:').'<ul>';
14587: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 14588: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 14589: } else {
1.130 raeburn 14590: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 14591: }
1.48 raeburn 14592: $resulttext .= '</ul>';
14593: } else {
1.130 raeburn 14594: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 14595: }
14596: $resulttext .= '</ul>';
14597: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 14598: if (ref($lastactref) eq 'HASH') {
14599: $lastactref->{'domainconfig'} = 1;
14600: }
1.46 raeburn 14601: } else {
1.130 raeburn 14602: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 14603: }
14604: } else {
14605: $resulttext = '<span class="LC_error">'.
14606: &mt('An error occurred: [_1]',$putresult).'</span>';
14607: }
14608: } else {
1.130 raeburn 14609: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 14610: }
14611: if ($errors) {
14612: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14613: $errors.'</ul>';
14614: }
14615: return $resulttext;
14616: }
14617:
1.48 raeburn 14618: sub modify_coursecategories {
1.239 raeburn 14619: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 14620: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
14621: $cathash);
1.48 raeburn 14622: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 14623: my @catitems = ('unauth','auth');
14624: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 14625: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 14626: $cathash = $domconfig{'coursecategories'}{'cats'};
14627: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
14628: $changes{'togglecats'} = 1;
14629: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
14630: }
14631: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
14632: $changes{'categorize'} = 1;
14633: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
14634: }
1.120 raeburn 14635: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
14636: $changes{'togglecatscomm'} = 1;
14637: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
14638: }
14639: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
14640: $changes{'categorizecomm'} = 1;
14641: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 14642:
14643: }
14644: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
14645: $changes{'togglecatsplace'} = 1;
14646: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
14647: }
14648: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
14649: $changes{'categorizeplace'} = 1;
14650: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 14651: }
1.238 raeburn 14652: foreach my $item (@catitems) {
14653: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
14654: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
14655: $changes{$item} = 1;
14656: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
14657: }
14658: }
14659: }
1.57 raeburn 14660: } else {
14661: $changes{'togglecats'} = 1;
14662: $changes{'categorize'} = 1;
1.124 raeburn 14663: $changes{'togglecatscomm'} = 1;
14664: $changes{'categorizecomm'} = 1;
1.272 raeburn 14665: $changes{'togglecatsplace'} = 1;
14666: $changes{'categorizeplace'} = 1;
1.87 raeburn 14667: $domconfig{'coursecategories'} = {
14668: togglecats => $env{'form.togglecats'},
14669: categorize => $env{'form.categorize'},
1.124 raeburn 14670: togglecatscomm => $env{'form.togglecatscomm'},
14671: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 14672: togglecatsplace => $env{'form.togglecatsplace'},
14673: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 14674: };
1.238 raeburn 14675: foreach my $item (@catitems) {
14676: if ($env{'form.coursecat_'.$item} ne 'std') {
14677: $changes{$item} = 1;
14678: }
14679: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
14680: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
14681: }
14682: }
1.57 raeburn 14683: }
14684: if (ref($cathash) eq 'HASH') {
14685: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 14686: push (@deletecategory,'instcode::0');
14687: }
1.120 raeburn 14688: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
14689: push(@deletecategory,'communities::0');
14690: }
1.272 raeburn 14691: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
14692: push(@deletecategory,'placement::0');
14693: }
1.48 raeburn 14694: }
1.57 raeburn 14695: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
14696: if (ref($cathash) eq 'HASH') {
1.48 raeburn 14697: if (@deletecategory > 0) {
14698: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 14699: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 14700: foreach my $item (@deletecategory) {
1.57 raeburn 14701: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
14702: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 14703: $deletions{$item} = 1;
1.57 raeburn 14704: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 14705: }
14706: }
14707: }
1.57 raeburn 14708: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 14709: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 14710: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 14711: $reorderings{$item} = 1;
1.57 raeburn 14712: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 14713: }
14714: if ($env{'form.addcategory_name_'.$item} ne '') {
14715: my $newcat = $env{'form.addcategory_name_'.$item};
14716: my $newdepth = $depth+1;
14717: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 14718: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 14719: $adds{$newitem} = 1;
14720: }
14721: if ($env{'form.subcat_'.$item} ne '') {
14722: my $newcat = $env{'form.subcat_'.$item};
14723: my $newdepth = $depth+1;
14724: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 14725: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 14726: $adds{$newitem} = 1;
14727: }
14728: }
14729: }
14730: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 14731: if (ref($cathash) eq 'HASH') {
1.48 raeburn 14732: my $newitem = 'instcode::0';
1.57 raeburn 14733: if ($cathash->{$newitem} eq '') {
14734: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 14735: $adds{$newitem} = 1;
14736: }
14737: } else {
14738: my $newitem = 'instcode::0';
1.57 raeburn 14739: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 14740: $adds{$newitem} = 1;
14741: }
14742: }
1.120 raeburn 14743: if ($env{'form.communities'} eq '1') {
14744: if (ref($cathash) eq 'HASH') {
14745: my $newitem = 'communities::0';
14746: if ($cathash->{$newitem} eq '') {
14747: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
14748: $adds{$newitem} = 1;
14749: }
14750: } else {
14751: my $newitem = 'communities::0';
14752: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
14753: $adds{$newitem} = 1;
14754: }
14755: }
1.272 raeburn 14756: if ($env{'form.placement'} eq '1') {
14757: if (ref($cathash) eq 'HASH') {
14758: my $newitem = 'placement::0';
14759: if ($cathash->{$newitem} eq '') {
14760: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
14761: $adds{$newitem} = 1;
14762: }
14763: } else {
14764: my $newitem = 'placement::0';
14765: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
14766: $adds{$newitem} = 1;
14767: }
14768: }
1.48 raeburn 14769: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 14770: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 14771: ($env{'form.addcategory_name'} ne 'communities') &&
14772: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 14773: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
14774: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
14775: $adds{$newitem} = 1;
14776: }
1.48 raeburn 14777: }
1.57 raeburn 14778: my $putresult;
1.48 raeburn 14779: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14780: if (keys(%deletions) > 0) {
14781: foreach my $key (keys(%deletions)) {
14782: if ($predelallitems{$key} ne '') {
14783: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
14784: }
14785: }
14786: }
14787: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 14788: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 14789: if (ref($chkcats[0]) eq 'ARRAY') {
14790: my $depth = 0;
14791: my $chg = 0;
14792: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
14793: my $name = $chkcats[0][$i];
14794: my $item;
14795: if ($name eq '') {
14796: $chg ++;
14797: } else {
14798: $item = &escape($name).'::0';
14799: if ($chg) {
1.57 raeburn 14800: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 14801: }
14802: $depth ++;
1.57 raeburn 14803: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 14804: $depth --;
14805: }
14806: }
14807: }
1.57 raeburn 14808: }
14809: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14810: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 14811: if ($putresult eq 'ok') {
1.57 raeburn 14812: my %title = (
1.120 raeburn 14813: togglecats => 'Show/Hide a course in catalog',
14814: categorize => 'Assign a category to a course',
14815: togglecatscomm => 'Show/Hide a community in catalog',
14816: categorizecomm => 'Assign a category to a community',
1.57 raeburn 14817: );
14818: my %level = (
1.120 raeburn 14819: dom => 'set in Domain ("Modify Course/Community")',
14820: crs => 'set in Course ("Course Configuration")',
14821: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 14822: none => 'No catalog',
14823: std => 'Standard catalog',
14824: domonly => 'Domain-only catalog',
14825: codesrch => 'Code search form',
1.57 raeburn 14826: );
1.48 raeburn 14827: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 14828: if ($changes{'togglecats'}) {
14829: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
14830: }
14831: if ($changes{'categorize'}) {
14832: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 14833: }
1.120 raeburn 14834: if ($changes{'togglecatscomm'}) {
14835: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
14836: }
14837: if ($changes{'categorizecomm'}) {
14838: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
14839: }
1.238 raeburn 14840: if ($changes{'unauth'}) {
14841: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
14842: }
14843: if ($changes{'auth'}) {
14844: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
14845: }
1.57 raeburn 14846: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
14847: my $cathash;
14848: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
14849: $cathash = $domconfig{'coursecategories'}{'cats'};
14850: } else {
14851: $cathash = {};
14852: }
14853: my (@cats,@trails,%allitems);
14854: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
14855: if (keys(%deletions) > 0) {
14856: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
14857: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
14858: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
14859: }
14860: $resulttext .= '</ul></li>';
14861: }
14862: if (keys(%reorderings) > 0) {
14863: my %sort_by_trail;
14864: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
14865: foreach my $key (keys(%reorderings)) {
14866: if ($allitems{$key} ne '') {
14867: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
14868: }
1.48 raeburn 14869: }
1.57 raeburn 14870: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
14871: $resulttext .= '<li>'.$trails[$trail].'</li>';
14872: }
14873: $resulttext .= '</ul></li>';
1.48 raeburn 14874: }
1.57 raeburn 14875: if (keys(%adds) > 0) {
14876: my %sort_by_trail;
14877: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
14878: foreach my $key (keys(%adds)) {
14879: if ($allitems{$key} ne '') {
14880: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
14881: }
14882: }
14883: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
14884: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 14885: }
1.57 raeburn 14886: $resulttext .= '</ul></li>';
1.48 raeburn 14887: }
14888: }
14889: $resulttext .= '</ul>';
1.239 raeburn 14890: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 14891: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
14892: if ($changes{'auth'}) {
14893: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
14894: }
14895: if ($changes{'unauth'}) {
14896: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
14897: }
14898: my $cachetime = 24*60*60;
14899: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 14900: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 14901: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 14902: }
14903: }
1.48 raeburn 14904: } else {
14905: $resulttext = '<span class="LC_error">'.
1.57 raeburn 14906: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 14907: }
14908: } else {
1.120 raeburn 14909: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 14910: }
14911: return $resulttext;
14912: }
14913:
1.69 raeburn 14914: sub modify_serverstatuses {
14915: my ($dom,%domconfig) = @_;
14916: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
14917: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
14918: %currserverstatus = %{$domconfig{'serverstatuses'}};
14919: }
14920: my @pages = &serverstatus_pages();
14921: foreach my $type (@pages) {
14922: $newserverstatus{$type}{'namedusers'} = '';
14923: $newserverstatus{$type}{'machines'} = '';
14924: if (defined($env{'form.'.$type.'_namedusers'})) {
14925: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
14926: my @okusers;
14927: foreach my $user (@users) {
14928: my ($uname,$udom) = split(/:/,$user);
14929: if (($udom =~ /^$match_domain$/) &&
14930: (&Apache::lonnet::domain($udom)) &&
14931: ($uname =~ /^$match_username$/)) {
14932: if (!grep(/^\Q$user\E/,@okusers)) {
14933: push(@okusers,$user);
14934: }
14935: }
14936: }
14937: if (@okusers > 0) {
14938: @okusers = sort(@okusers);
14939: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
14940: }
14941: }
14942: if (defined($env{'form.'.$type.'_machines'})) {
14943: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
14944: my @okmachines;
14945: foreach my $ip (@machines) {
14946: my @parts = split(/\./,$ip);
14947: next if (@parts < 4);
14948: my $badip = 0;
14949: for (my $i=0; $i<4; $i++) {
14950: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
14951: $badip = 1;
14952: last;
14953: }
14954: }
14955: if (!$badip) {
14956: push(@okmachines,$ip);
14957: }
14958: }
14959: @okmachines = sort(@okmachines);
14960: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
14961: }
14962: }
14963: my %serverstatushash = (
14964: serverstatuses => \%newserverstatus,
14965: );
14966: foreach my $type (@pages) {
1.83 raeburn 14967: foreach my $setting ('namedusers','machines') {
1.84 raeburn 14968: my (@current,@new);
1.83 raeburn 14969: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 14970: if ($currserverstatus{$type}{$setting} ne '') {
14971: @current = split(/,/,$currserverstatus{$type}{$setting});
14972: }
14973: }
14974: if ($newserverstatus{$type}{$setting} ne '') {
14975: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 14976: }
14977: if (@current > 0) {
14978: if (@new > 0) {
14979: foreach my $item (@current) {
14980: if (!grep(/^\Q$item\E$/,@new)) {
14981: $changes{$type}{$setting} = 1;
1.82 raeburn 14982: last;
14983: }
14984: }
1.84 raeburn 14985: foreach my $item (@new) {
14986: if (!grep(/^\Q$item\E$/,@current)) {
14987: $changes{$type}{$setting} = 1;
14988: last;
1.82 raeburn 14989: }
14990: }
14991: } else {
1.83 raeburn 14992: $changes{$type}{$setting} = 1;
1.69 raeburn 14993: }
1.83 raeburn 14994: } elsif (@new > 0) {
14995: $changes{$type}{$setting} = 1;
1.69 raeburn 14996: }
14997: }
14998: }
14999: if (keys(%changes) > 0) {
1.81 raeburn 15000: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 15001: my $putresult = &Apache::lonnet::put_dom('configuration',
15002: \%serverstatushash,$dom);
15003: if ($putresult eq 'ok') {
15004: $resulttext .= &mt('Changes made:').'<ul>';
15005: foreach my $type (@pages) {
1.84 raeburn 15006: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 15007: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 15008: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 15009: if ($newserverstatus{$type}{'namedusers'} eq '') {
15010: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
15011: } else {
15012: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
15013: }
1.84 raeburn 15014: }
15015: if ($changes{$type}{'machines'}) {
1.69 raeburn 15016: if ($newserverstatus{$type}{'machines'} eq '') {
15017: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
15018: } else {
15019: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
15020: }
15021:
15022: }
15023: $resulttext .= '</ul></li>';
15024: }
15025: }
15026: $resulttext .= '</ul>';
15027: } else {
15028: $resulttext = '<span class="LC_error">'.
15029: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
15030:
15031: }
15032: } else {
15033: $resulttext = &mt('No changes made to access to server status pages');
15034: }
15035: return $resulttext;
15036: }
15037:
1.118 jms 15038: sub modify_helpsettings {
1.285 raeburn 15039: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 15040: my ($resulttext,$errors,%changes,%helphash);
15041: my %defaultchecked = ('submitbugs' => 'on');
15042: my @offon = ('off','on');
1.118 jms 15043: my @toggles = ('submitbugs');
1.285 raeburn 15044: my %current = ('submitbugs' => '',
15045: 'adhoc' => {},
15046: );
1.118 jms 15047: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 15048: %current = %{$domconfig{'helpsettings'}};
15049: }
1.285 raeburn 15050: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 15051: foreach my $item (@toggles) {
15052: if ($defaultchecked{$item} eq 'on') {
15053: if ($current{$item} eq '') {
15054: if ($env{'form.'.$item} eq '0') {
15055: $changes{$item} = 1;
15056: }
15057: } elsif ($current{$item} ne $env{'form.'.$item}) {
15058: $changes{$item} = 1;
15059: }
15060: } elsif ($defaultchecked{$item} eq 'off') {
15061: if ($current{$item} eq '') {
15062: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 15063: $changes{$item} = 1;
15064: }
1.282 raeburn 15065: } elsif ($current{$item} ne $env{'form.'.$item}) {
15066: $changes{$item} = 1;
15067: }
15068: }
15069: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
15070: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
15071: }
15072: }
1.285 raeburn 15073: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 15074: my $confname = $dom.'-domainconfig';
15075: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 15076: my (@allpos,%newsettings,%changedprivs,$newrole);
15077: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 15078: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 15079: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 15080: my %lt = &Apache::lonlocal::texthash(
15081: s => 'system',
15082: d => 'domain',
15083: order => 'Display order',
15084: access => 'Role usage',
1.291 raeburn 15085: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 15086: dh => 'All with domain helpdesk role',
15087: da => 'All with domain helpdesk assistant role',
1.285 raeburn 15088: none => 'None',
15089: status => 'Determined based on institutional status',
15090: inc => 'Include all, but exclude specific personnel',
15091: exc => 'Exclude all, but include specific personnel',
15092: );
15093: for (my $num=0; $num<=$maxnum; $num++) {
15094: my ($prefix,$identifier,$rolename,%curr);
15095: if ($num == $maxnum) {
15096: next unless ($env{'form.newcusthelp'} == $maxnum);
15097: $identifier = 'custhelp'.$num;
15098: $prefix = 'helproles_'.$num;
15099: $rolename = $env{'form.custhelpname'.$num};
15100: $rolename=~s/[^A-Za-z0-9]//gs;
15101: next if ($rolename eq '');
15102: next if (exists($existing{'rolesdef_'.$rolename}));
15103: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15104: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15105: $newprivs{'c'},$confname,$dom);
15106: if ($result ne 'ok') {
15107: $errors .= '<li><span class="LC_error">'.
15108: &mt('An error occurred storing the new custom role: [_1]',
15109: $result).'</span></li>';
15110: next;
15111: } else {
15112: $changedprivs{$rolename} = \%newprivs;
15113: $newrole = $rolename;
15114: }
15115: } else {
15116: $prefix = 'helproles_'.$num;
15117: $rolename = $env{'form.'.$prefix};
15118: next if ($rolename eq '');
15119: next unless (exists($existing{'rolesdef_'.$rolename}));
15120: $identifier = 'custhelp'.$num;
15121: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
15122: my %currprivs;
1.289 raeburn 15123: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 15124: split(/\_/,$existing{'rolesdef_'.$rolename});
15125: foreach my $level ('c','d','s') {
15126: if ($newprivs{$level} ne $currprivs{$level}) {
15127: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
15128: $newprivs{'c'},$confname,$dom);
15129: if ($result ne 'ok') {
15130: $errors .= '<li><span class="LC_error">'.
15131: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
15132: $rolename,$result).'</span></li>';
15133: } else {
15134: $changedprivs{$rolename} = \%newprivs;
15135: }
15136: last;
15137: }
15138: }
15139: if (ref($current{'adhoc'}) eq 'HASH') {
15140: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15141: %curr = %{$current{'adhoc'}{$rolename}};
15142: }
15143: }
15144: }
15145: my $newpos = $env{'form.'.$prefix.'_pos'};
15146: $newpos =~ s/\D+//g;
15147: $allpos[$newpos] = $rolename;
15148: my $newdesc = $env{'form.'.$prefix.'_desc'};
15149: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
15150: if ($curr{'desc'}) {
15151: if ($curr{'desc'} ne $newdesc) {
15152: $changes{'customrole'}{$rolename}{'desc'} = 1;
15153: $newsettings{$rolename}{'desc'} = $newdesc;
15154: }
15155: } elsif ($newdesc ne '') {
15156: $changes{'customrole'}{$rolename}{'desc'} = 1;
15157: $newsettings{$rolename}{'desc'} = $newdesc;
15158: }
15159: my $access = $env{'form.'.$prefix.'_access'};
15160: if (grep(/^\Q$access\E$/,@accesstypes)) {
15161: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
15162: if ($access eq 'status') {
15163: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
15164: if (scalar(@statuses) == 0) {
1.289 raeburn 15165: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 15166: } else {
15167: my (@shownstatus,$numtypes);
15168: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15169: if (ref($types) eq 'ARRAY') {
15170: $numtypes = scalar(@{$types});
15171: foreach my $type (sort(@statuses)) {
15172: if ($type eq 'default') {
15173: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15174: } elsif (grep(/^\Q$type\E$/,@{$types})) {
15175: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
15176: push(@shownstatus,$usertypes->{$type});
15177: }
15178: }
15179: }
15180: if (grep(/^default$/,@statuses)) {
15181: push(@shownstatus,$othertitle);
15182: }
15183: if (scalar(@shownstatus) == 1+$numtypes) {
15184: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
15185: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
15186: } else {
15187: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
15188: if (ref($curr{'status'}) eq 'ARRAY') {
15189: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15190: if (@diffs) {
15191: $changes{'customrole'}{$rolename}{$access} = 1;
15192: }
15193: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15194: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 15195: }
1.166 raeburn 15196: }
15197: }
1.285 raeburn 15198: } elsif (($access eq 'inc') || ($access eq 'exc')) {
15199: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
15200: my @newspecstaff;
15201: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
15202: foreach my $person (sort(@personnel)) {
15203: if ($domhelpdesk{$person}) {
15204: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
15205: }
15206: }
15207: if (ref($curr{$access}) eq 'ARRAY') {
15208: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
15209: if (@diffs) {
15210: $changes{'customrole'}{$rolename}{$access} = 1;
15211: }
15212: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15213: $changes{'customrole'}{$rolename}{$access} = 1;
15214: }
15215: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
15216: my ($uname,$udom) = split(/:/,$person);
15217: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
15218: }
15219: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 15220: }
1.285 raeburn 15221: } else {
15222: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
15223: }
15224: unless ($curr{'access'} eq $access) {
15225: $changes{'customrole'}{$rolename}{'access'} = 1;
15226: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 15227: }
15228: }
1.285 raeburn 15229: if (@allpos > 0) {
15230: my $idx = 0;
15231: foreach my $rolename (@allpos) {
15232: if ($rolename ne '') {
15233: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
15234: if (ref($current{'adhoc'}) eq 'HASH') {
15235: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
15236: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
15237: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 15238: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 15239: }
15240: }
1.282 raeburn 15241: }
1.285 raeburn 15242: $idx ++;
1.166 raeburn 15243: }
15244: }
1.118 jms 15245: }
1.123 jms 15246: my $putresult;
15247: if (keys(%changes) > 0) {
1.166 raeburn 15248: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 15249: if ($putresult eq 'ok') {
1.285 raeburn 15250: if (ref($helphash{'helpsettings'}) eq 'HASH') {
15251: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
15252: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
15253: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
15254: }
15255: }
15256: my $cachetime = 24*60*60;
15257: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15258: if (ref($lastactref) eq 'HASH') {
15259: $lastactref->{'domdefaults'} = 1;
15260: }
15261: } else {
15262: $errors .= '<li><span class="LC_error">'.
15263: &mt('An error occurred storing the settings: [_1]',
15264: $putresult).'</span></li>';
15265: }
15266: }
15267: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
15268: $resulttext = &mt('Changes made:').'<ul>';
15269: my (%shownprivs,@levelorder);
15270: @levelorder = ('c','d','s');
15271: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 15272: foreach my $item (sort(keys(%changes))) {
15273: if ($item eq 'submitbugs') {
15274: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
15275: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
15276: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 15277: } elsif ($item eq 'customrole') {
15278: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 15279: my @keyorder = ('order','desc','access','status','exc','inc');
15280: my %keytext = &Apache::lonlocal::texthash(
15281: order => 'Order',
15282: desc => 'Role description',
15283: access => 'Role usage',
1.300 droeschl 15284: status => 'Allowed institutional types',
1.285 raeburn 15285: exc => 'Allowed personnel',
15286: inc => 'Disallowed personnel',
15287: );
1.282 raeburn 15288: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 15289: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
15290: if ($role eq $newrole) {
15291: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
15292: $role).'<ul>';
15293: } else {
15294: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15295: $role).'<ul>';
15296: }
15297: foreach my $key (@keyorder) {
15298: if ($changes{'customrole'}{$role}{$key}) {
15299: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
15300: $keytext{$key},$newsettings{$role}{$key}).
15301: '</li>';
15302: }
15303: }
15304: if (ref($changedprivs{$role}) eq 'HASH') {
15305: $shownprivs{$role} = 1;
15306: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
15307: foreach my $level (@levelorder) {
15308: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
15309: next if ($item eq '');
15310: my ($priv) = split(/\&/,$item,2);
15311: if (&Apache::lonnet::plaintext($priv)) {
15312: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
15313: unless ($level eq 'c') {
15314: $resulttext .= ' ('.$lt{$level}.')';
15315: }
15316: $resulttext .= '</li>';
15317: }
15318: }
15319: }
15320: $resulttext .= '</ul>';
15321: }
15322: $resulttext .= '</ul></li>';
15323: }
15324: }
15325: }
15326: }
15327: }
15328: }
15329: if (keys(%changedprivs)) {
15330: foreach my $role (sort(keys(%changedprivs))) {
15331: unless ($shownprivs{$role}) {
15332: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
15333: $role).'<ul>'.
15334: '<li>'.&mt('Privileges set to :').'<ul>';
15335: foreach my $level (@levelorder) {
15336: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
15337: next if ($item eq '');
15338: my ($priv) = split(/\&/,$item,2);
15339: if (&Apache::lonnet::plaintext($priv)) {
15340: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
15341: unless ($level eq 'c') {
15342: $resulttext .= ' ('.$lt{$level}.')';
15343: }
15344: $resulttext .= '</li>';
15345: }
1.282 raeburn 15346: }
15347: }
1.285 raeburn 15348: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 15349: }
15350: }
15351: }
1.285 raeburn 15352: $resulttext .= '</ul>';
15353: } else {
15354: $resulttext = &mt('No changes made to help settings');
1.118 jms 15355: }
15356: if ($errors) {
1.168 raeburn 15357: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 15358: $errors.'</ul>';
1.118 jms 15359: }
15360: return $resulttext;
15361: }
15362:
1.121 raeburn 15363: sub modify_coursedefaults {
1.212 raeburn 15364: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 15365: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 15366: my %defaultchecked = (
15367: 'canuse_pdfforms' => 'off',
15368: 'uselcmath' => 'on',
15369: 'usejsme' => 'on'
15370: );
15371: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 15372: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 15373: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
15374: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
15375: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 15376: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 15377: my %staticdefaults = (
15378: anonsurvey_threshold => 10,
15379: uploadquota => 500,
1.257 raeburn 15380: postsubmit => 60,
1.276 raeburn 15381: mysqltables => 172800,
1.198 raeburn 15382: );
1.314 raeburn 15383: my %texoptions = (
15384: MathJax => 'MathJax',
15385: mimetex => &mt('Convert to Images'),
15386: tth => &mt('TeX to HTML'),
15387: );
1.121 raeburn 15388: $defaultshash{'coursedefaults'} = {};
15389:
15390: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
15391: if ($domconfig{'coursedefaults'} eq '') {
15392: $domconfig{'coursedefaults'} = {};
15393: }
15394: }
15395:
15396: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
15397: foreach my $item (@toggles) {
15398: if ($defaultchecked{$item} eq 'on') {
15399: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15400: ($env{'form.'.$item} eq '0')) {
15401: $changes{$item} = 1;
1.192 raeburn 15402: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 15403: $changes{$item} = 1;
15404: }
15405: } elsif ($defaultchecked{$item} eq 'off') {
15406: if (($domconfig{'coursedefaults'}{$item} eq '') &&
15407: ($env{'form.'.$item} eq '1')) {
15408: $changes{$item} = 1;
15409: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
15410: $changes{$item} = 1;
15411: }
15412: }
15413: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
15414: }
1.198 raeburn 15415: foreach my $item (@numbers) {
15416: my ($currdef,$newdef);
1.208 raeburn 15417: $newdef = $env{'form.'.$item};
1.198 raeburn 15418: if ($item eq 'anonsurvey_threshold') {
15419: $currdef = $domconfig{'coursedefaults'}{$item};
15420: $newdef =~ s/\D//g;
15421: if ($newdef eq '' || $newdef < 1) {
15422: $newdef = 1;
15423: }
15424: $defaultshash{'coursedefaults'}{$item} = $newdef;
15425: } else {
1.276 raeburn 15426: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
15427: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
15428: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 15429: }
15430: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 15431: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 15432: }
15433: if ($currdef ne $newdef) {
15434: my $staticdef;
15435: if ($item eq 'anonsurvey_threshold') {
15436: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
15437: $changes{$item} = 1;
15438: }
1.276 raeburn 15439: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 15440: my $setting = $1;
1.276 raeburn 15441: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
15442: $changes{$setting} = 1;
1.198 raeburn 15443: }
15444: }
1.139 raeburn 15445: }
15446: }
1.314 raeburn 15447: my $texengine;
15448: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
15449: $texengine = $env{'form.texengine'};
15450: if ($defaultshash{'coursedefaults'}{'texengine'} eq '') {
15451: unless ($texengine eq 'MathJax') {
15452: $changes{'texengine'} = 1;
15453: }
15454: } elsif ($defaultshash{'coursedefaults'}{'texengine'} ne $texengine) {
15455: $changes{'texengine'} = 1;
15456: }
15457: }
15458: if ($texengine ne '') {
15459: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
15460: }
1.264 raeburn 15461: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
15462: my @currclonecode;
15463: if (ref($currclone) eq 'HASH') {
15464: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
15465: @currclonecode = @{$currclone->{'instcode'}};
15466: }
15467: }
15468: my $newclone;
1.289 raeburn 15469: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 15470: $newclone = $env{'form.canclone'};
15471: }
15472: if ($newclone eq 'instcode') {
15473: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
15474: my (%codedefaults,@code_order,@clonecode);
15475: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
15476: \@code_order);
15477: foreach my $item (@code_order) {
15478: if (grep(/^\Q$item\E$/,@newcodes)) {
15479: push(@clonecode,$item);
15480: }
15481: }
15482: if (@clonecode) {
15483: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
15484: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
15485: if (@diffs) {
15486: $changes{'canclone'} = 1;
15487: }
15488: } else {
15489: $newclone eq '';
15490: }
15491: } elsif ($newclone ne '') {
1.289 raeburn 15492: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
15493: }
1.264 raeburn 15494: if ($newclone ne $currclone) {
15495: $changes{'canclone'} = 1;
15496: }
1.257 raeburn 15497: my %credits;
15498: foreach my $type (@types) {
15499: unless ($type eq 'community') {
15500: $credits{$type} = $env{'form.'.$type.'_credits'};
15501: $credits{$type} =~ s/[^\d.]+//g;
15502: }
15503: }
15504: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
15505: ($env{'form.coursecredits'} eq '1')) {
15506: $changes{'coursecredits'} = 1;
15507: foreach my $type (keys(%credits)) {
15508: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15509: }
15510: } else {
1.289 raeburn 15511: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 15512: foreach my $type (@types) {
15513: unless ($type eq 'community') {
1.289 raeburn 15514: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 15515: $changes{'coursecredits'} = 1;
15516: }
15517: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
15518: }
15519: }
15520: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15521: foreach my $type (@types) {
15522: unless ($type eq 'community') {
15523: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
15524: $changes{'coursecredits'} = 1;
15525: last;
15526: }
15527: }
15528: }
15529: }
15530: }
15531: if ($env{'form.postsubmit'} eq '1') {
15532: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
15533: my %currtimeout;
15534: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15535: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
15536: $changes{'postsubmit'} = 1;
15537: }
15538: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15539: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
15540: }
15541: } else {
15542: $changes{'postsubmit'} = 1;
15543: }
15544: foreach my $type (@types) {
15545: my $timeout = $env{'form.'.$type.'_timeout'};
15546: $timeout =~ s/\D//g;
15547: if ($timeout == $staticdefaults{'postsubmit'}) {
15548: $timeout = '';
15549: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
15550: $timeout = '0';
15551: }
15552: unless ($timeout eq '') {
15553: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
15554: }
15555: if (exists($currtimeout{$type})) {
15556: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 15557: $changes{'postsubmit'} = 1;
1.257 raeburn 15558: }
15559: } elsif ($timeout ne '') {
15560: $changes{'postsubmit'} = 1;
15561: }
15562: }
15563: } else {
15564: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
15565: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15566: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
15567: $changes{'postsubmit'} = 1;
15568: }
15569: } else {
15570: $changes{'postsubmit'} = 1;
15571: }
1.192 raeburn 15572: }
1.121 raeburn 15573: }
15574: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
15575: $dom);
15576: if ($putresult eq 'ok') {
15577: if (keys(%changes) > 0) {
1.213 raeburn 15578: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 15579: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 15580: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.314 raeburn 15581: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
15582: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','texengine') {
1.257 raeburn 15583: if ($changes{$item}) {
15584: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
15585: }
1.289 raeburn 15586: }
1.192 raeburn 15587: if ($changes{'coursecredits'}) {
15588: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 15589: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
15590: $domdefaults{$type.'credits'} =
15591: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
15592: }
15593: }
15594: }
15595: if ($changes{'postsubmit'}) {
15596: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
15597: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
15598: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15599: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
15600: $domdefaults{$type.'postsubtimeout'} =
15601: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15602: }
15603: }
1.192 raeburn 15604: }
15605: }
1.198 raeburn 15606: if ($changes{'uploadquota'}) {
15607: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15608: foreach my $type (@types) {
15609: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
15610: }
15611: }
15612: }
1.264 raeburn 15613: if ($changes{'canclone'}) {
15614: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15615: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15616: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
15617: if (@clonecodes) {
15618: $domdefaults{'canclone'} = join('+',@clonecodes);
15619: }
15620: }
15621: } else {
15622: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
15623: }
15624: }
1.121 raeburn 15625: my $cachetime = 24*60*60;
15626: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 15627: if (ref($lastactref) eq 'HASH') {
15628: $lastactref->{'domdefaults'} = 1;
15629: }
1.121 raeburn 15630: }
15631: $resulttext = &mt('Changes made:').'<ul>';
15632: foreach my $item (sort(keys(%changes))) {
15633: if ($item eq 'canuse_pdfforms') {
15634: if ($env{'form.'.$item} eq '1') {
15635: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
15636: } else {
15637: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
15638: }
1.257 raeburn 15639: } elsif ($item eq 'uselcmath') {
15640: if ($env{'form.'.$item} eq '1') {
15641: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
15642: } else {
15643: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
15644: }
15645: } elsif ($item eq 'usejsme') {
15646: if ($env{'form.'.$item} eq '1') {
15647: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
15648: } else {
1.289 raeburn 15649: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 15650: }
1.314 raeburn 15651: } elsif ($item eq 'texengine') {
15652: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
15653: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
15654: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
15655: }
1.139 raeburn 15656: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 15657: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 15658: } elsif ($item eq 'uploadquota') {
15659: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
15660: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
15661: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
15662: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 15663: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 15664: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 15665: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
15666: '</ul>'.
15667: '</li>';
15668: } else {
15669: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
15670: }
1.276 raeburn 15671: } elsif ($item eq 'mysqltables') {
15672: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
15673: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
15674: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
15675: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
15676: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
15677: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
15678: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
15679: '</ul>'.
15680: '</li>';
15681: } else {
15682: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
15683: }
1.257 raeburn 15684: } elsif ($item eq 'postsubmit') {
15685: if ($domdefaults{'postsubmit'} eq 'off') {
15686: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
15687: } else {
15688: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 15689: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 15690: $resulttext .= &mt('durations:').'<ul>';
15691: foreach my $type (@types) {
15692: $resulttext .= '<li>';
15693: my $timeout;
15694: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
15695: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
15696: }
15697: my $display;
15698: if ($timeout eq '0') {
15699: $display = &mt('unlimited');
15700: } elsif ($timeout eq '') {
15701: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
15702: } else {
15703: $display = &mt('[quant,_1,second]',$timeout);
15704: }
15705: if ($type eq 'community') {
15706: $resulttext .= &mt('Communities');
15707: } elsif ($type eq 'official') {
15708: $resulttext .= &mt('Official courses');
15709: } elsif ($type eq 'unofficial') {
15710: $resulttext .= &mt('Unofficial courses');
15711: } elsif ($type eq 'textbook') {
15712: $resulttext .= &mt('Textbook courses');
1.271 raeburn 15713: } elsif ($type eq 'placement') {
15714: $resulttext .= &mt('Placement tests');
1.257 raeburn 15715: }
15716: $resulttext .= ' -- '.$display.'</li>';
15717: }
15718: $resulttext .= '</ul>';
15719: }
1.289 raeburn 15720: $resulttext .= '</li>';
1.257 raeburn 15721: }
1.192 raeburn 15722: } elsif ($item eq 'coursecredits') {
15723: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
15724: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 15725: ($domdefaults{'unofficialcredits'} eq '') &&
15726: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 15727: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
15728: } else {
15729: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
15730: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
15731: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 15732: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 15733: '</ul>'.
15734: '</li>';
15735: }
15736: } else {
15737: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
15738: }
1.264 raeburn 15739: } elsif ($item eq 'canclone') {
15740: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
15741: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
15742: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
15743: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
15744: }
15745: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
15746: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
15747: } else {
1.289 raeburn 15748: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 15749: }
1.140 raeburn 15750: }
1.121 raeburn 15751: }
15752: $resulttext .= '</ul>';
15753: } else {
15754: $resulttext = &mt('No changes made to course defaults');
15755: }
15756: } else {
15757: $resulttext = '<span class="LC_error">'.
15758: &mt('An error occurred: [_1]',$putresult).'</span>';
15759: }
15760: return $resulttext;
15761: }
15762:
1.231 raeburn 15763: sub modify_selfenrollment {
15764: my ($dom,$lastactref,%domconfig) = @_;
15765: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 15766: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 15767: my %titles = &tool_titles();
1.232 raeburn 15768: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
15769: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 15770: $ordered{'default'} = ['types','registered','approval','limit'];
15771:
15772: my (%roles,%shown,%toplevel);
15773: $roles{'0'} = &Apache::lonnet::plaintext('dc');
15774:
15775: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
15776: if ($domconfig{'selfenrollment'} eq '') {
15777: $domconfig{'selfenrollment'} = {};
15778: }
15779: }
15780: %toplevel = (
15781: admin => 'Configuration Rights',
15782: default => 'Default settings',
15783: validation => 'Validation of self-enrollment requests',
15784: );
1.233 raeburn 15785: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 15786:
15787: if (ref($ordered{'admin'}) eq 'ARRAY') {
15788: foreach my $item (@{$ordered{'admin'}}) {
15789: foreach my $type (@types) {
15790: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
15791: $selfenrollhash{'admin'}{$type}{$item} = 1;
15792: } else {
15793: $selfenrollhash{'admin'}{$type}{$item} = 0;
15794: }
15795: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
15796: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
15797: if ($selfenrollhash{'admin'}{$type}{$item} ne
15798: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
15799: push(@{$changes{'admin'}{$type}},$item);
15800: }
15801: } else {
15802: if (!$selfenrollhash{'admin'}{$type}{$item}) {
15803: push(@{$changes{'admin'}{$type}},$item);
15804: }
15805: }
15806: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
15807: push(@{$changes{'admin'}{$type}},$item);
15808: }
15809: }
15810: }
15811: }
15812:
15813: foreach my $item (@{$ordered{'default'}}) {
15814: foreach my $type (@types) {
15815: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
15816: if ($item eq 'types') {
15817: unless (($value eq 'all') || ($value eq 'dom')) {
15818: $value = '';
15819: }
15820: } elsif ($item eq 'registered') {
15821: unless ($value eq '1') {
15822: $value = 0;
15823: }
15824: } elsif ($item eq 'approval') {
15825: unless ($value =~ /^[012]$/) {
15826: $value = 0;
15827: }
15828: } else {
15829: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
15830: $value = 'none';
15831: }
15832: }
15833: $selfenrollhash{'default'}{$type}{$item} = $value;
15834: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
15835: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
15836: if ($selfenrollhash{'default'}{$type}{$item} ne
15837: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
15838: push(@{$changes{'default'}{$type}},$item);
15839: }
15840: } else {
15841: push(@{$changes{'default'}{$type}},$item);
15842: }
15843: } else {
15844: push(@{$changes{'default'}{$type}},$item);
15845: }
15846: if ($item eq 'limit') {
15847: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
15848: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
15849: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
15850: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
15851: }
15852: } else {
15853: $selfenrollhash{'default'}{$type}{'cap'} = '';
15854: }
15855: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
15856: if ($selfenrollhash{'default'}{$type}{'cap'} ne
15857: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
15858: push(@{$changes{'default'}{$type}},'cap');
15859: }
15860: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
15861: push(@{$changes{'default'}{$type}},'cap');
15862: }
15863: }
15864: }
15865: }
15866:
15867: foreach my $item (@{$itemsref}) {
15868: if ($item eq 'fields') {
15869: my @changed;
15870: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
15871: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
15872: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
15873: }
15874: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
15875: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
15876: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
15877: $domconfig{'selfenrollment'}{'validation'}{$item});
15878: } else {
15879: @changed = @{$selfenrollhash{'validation'}{$item}};
15880: }
15881: } else {
15882: @changed = @{$selfenrollhash{'validation'}{$item}};
15883: }
15884: if (@changed) {
15885: if ($selfenrollhash{'validation'}{$item}) {
15886: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
15887: } else {
15888: $changes{'validation'}{$item} = &mt('None');
15889: }
15890: }
15891: } else {
15892: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
15893: if ($item eq 'markup') {
15894: if ($env{'form.selfenroll_validation_'.$item}) {
15895: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
15896: }
15897: }
15898: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
15899: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
15900: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
15901: }
15902: }
15903: }
15904: }
15905:
15906: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
15907: $dom);
15908: if ($putresult eq 'ok') {
15909: if (keys(%changes) > 0) {
15910: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15911: $resulttext = &mt('Changes made:').'<ul>';
15912: foreach my $key ('admin','default','validation') {
15913: if (ref($changes{$key}) eq 'HASH') {
15914: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
15915: if ($key eq 'validation') {
15916: foreach my $item (@{$itemsref}) {
15917: if (exists($changes{$key}{$item})) {
15918: if ($item eq 'markup') {
15919: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
15920: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
15921: } else {
15922: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
15923: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
15924: }
15925: }
15926: }
15927: } else {
15928: foreach my $type (@types) {
15929: if ($type eq 'community') {
15930: $roles{'1'} = &mt('Community personnel');
15931: } else {
15932: $roles{'1'} = &mt('Course personnel');
15933: }
15934: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 15935: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
15936: if ($key eq 'admin') {
15937: my @mgrdc = ();
15938: if (ref($ordered{$key}) eq 'ARRAY') {
15939: foreach my $item (@{$ordered{'admin'}}) {
15940: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
15941: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
15942: push(@mgrdc,$item);
15943: }
15944: }
15945: }
15946: if (@mgrdc) {
15947: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
15948: } else {
15949: delete($domdefaults{$type.'selfenrolladmdc'});
15950: }
15951: }
15952: } else {
15953: if (ref($ordered{$key}) eq 'ARRAY') {
15954: foreach my $item (@{$ordered{$key}}) {
15955: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
15956: $domdefaults{$type.'selfenroll'.$item} =
15957: $selfenrollhash{$key}{$type}{$item};
15958: }
15959: }
15960: }
15961: }
15962: }
1.231 raeburn 15963: $resulttext .= '<li>'.$titles{$type}.'<ul>';
15964: foreach my $item (@{$ordered{$key}}) {
15965: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
15966: $resulttext .= '<li>';
15967: if ($key eq 'admin') {
15968: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
15969: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
15970: } else {
15971: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
15972: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
15973: }
15974: $resulttext .= '</li>';
15975: }
15976: }
15977: $resulttext .= '</ul></li>';
15978: }
15979: }
15980: $resulttext .= '</ul></li>';
15981: }
15982: }
1.305 raeburn 15983: }
15984: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
15985: my $cachetime = 24*60*60;
15986: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15987: if (ref($lastactref) eq 'HASH') {
15988: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 15989: }
1.231 raeburn 15990: }
15991: $resulttext .= '</ul>';
15992: } else {
15993: $resulttext = &mt('No changes made to self-enrollment settings');
15994: }
15995: } else {
15996: $resulttext = '<span class="LC_error">'.
15997: &mt('An error occurred: [_1]',$putresult).'</span>';
15998: }
15999: return $resulttext;
16000: }
16001:
1.137 raeburn 16002: sub modify_usersessions {
1.212 raeburn 16003: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 16004: my @hostingtypes = ('version','excludedomain','includedomain');
16005: my @offloadtypes = ('primary','default');
16006: my %types = (
16007: remote => \@hostingtypes,
16008: hosted => \@hostingtypes,
16009: spares => \@offloadtypes,
16010: );
16011: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 16012: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 16013: my (%by_ip,%by_location,@intdoms,@instdoms);
16014: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 16015: my @locations = sort(keys(%by_location));
1.137 raeburn 16016: my (%defaultshash,%changes);
16017: foreach my $prefix (@prefixes) {
16018: $defaultshash{'usersessions'}{$prefix} = {};
16019: }
1.212 raeburn 16020: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 16021: my $resulttext;
1.138 raeburn 16022: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 16023: foreach my $prefix (@prefixes) {
1.145 raeburn 16024: next if ($prefix eq 'spares');
16025: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 16026: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16027: if ($type eq 'version') {
16028: my $value = $env{'form.'.$prefix.'_'.$type};
16029: my $okvalue;
16030: if ($value ne '') {
16031: if (grep(/^\Q$value\E$/,@lcversions)) {
16032: $okvalue = $value;
16033: }
16034: }
16035: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16036: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
16037: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
16038: if ($inuse == 0) {
16039: $changes{$prefix}{$type} = 1;
16040: } else {
16041: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
16042: $changes{$prefix}{$type} = 1;
16043: }
16044: if ($okvalue ne '') {
16045: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16046: }
16047: }
16048: } else {
16049: if (($inuse == 1) && ($okvalue ne '')) {
16050: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16051: $changes{$prefix}{$type} = 1;
16052: }
16053: }
16054: } else {
16055: if (($inuse == 1) && ($okvalue ne '')) {
16056: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16057: $changes{$prefix}{$type} = 1;
16058: }
16059: }
16060: } else {
16061: if (($inuse == 1) && ($okvalue ne '')) {
16062: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
16063: $changes{$prefix}{$type} = 1;
16064: }
16065: }
16066: } else {
16067: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16068: my @okvals;
16069: foreach my $val (@vals) {
1.138 raeburn 16070: if ($val =~ /:/) {
16071: my @items = split(/:/,$val);
16072: foreach my $item (@items) {
16073: if (ref($by_location{$item}) eq 'ARRAY') {
16074: push(@okvals,$item);
16075: }
16076: }
16077: } else {
16078: if (ref($by_location{$val}) eq 'ARRAY') {
16079: push(@okvals,$val);
16080: }
1.137 raeburn 16081: }
16082: }
16083: @okvals = sort(@okvals);
16084: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16085: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
16086: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
16087: if ($inuse == 0) {
16088: $changes{$prefix}{$type} = 1;
16089: } else {
16090: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16091: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
16092: if (@changed > 0) {
16093: $changes{$prefix}{$type} = 1;
16094: }
16095: }
16096: } else {
16097: if ($inuse == 1) {
16098: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16099: $changes{$prefix}{$type} = 1;
16100: }
16101: }
16102: } else {
16103: if ($inuse == 1) {
16104: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16105: $changes{$prefix}{$type} = 1;
16106: }
16107: }
16108: } else {
16109: if ($inuse == 1) {
16110: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
16111: $changes{$prefix}{$type} = 1;
16112: }
16113: }
16114: }
16115: }
16116: }
1.145 raeburn 16117:
16118: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 16119: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 16120: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
16121: my $savespares;
16122:
16123: foreach my $lonhost (sort(keys(%servers))) {
16124: my $serverhomeID =
16125: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 16126: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 16127: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
16128: my %spareschg;
16129: foreach my $type (@{$types{'spares'}}) {
16130: my @okspares;
16131: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
16132: foreach my $server (@checked) {
1.152 raeburn 16133: if (&Apache::lonnet::hostname($server) ne '') {
16134: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
16135: unless (grep(/^\Q$server\E$/,@okspares)) {
16136: push(@okspares,$server);
16137: }
1.145 raeburn 16138: }
16139: }
16140: }
16141: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
16142: my $newspare;
1.152 raeburn 16143: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
16144: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 16145: $newspare = $new;
16146: }
16147: }
1.152 raeburn 16148: my @spares;
16149: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
16150: @spares = sort(@okspares,$newspare);
16151: } else {
16152: @spares = sort(@okspares);
16153: }
16154: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 16155: if (ref($spareid{$lonhost}) eq 'HASH') {
16156: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 16157: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 16158: if (@diffs > 0) {
16159: $spareschg{$type} = 1;
16160: }
16161: }
16162: }
16163: }
16164: if (keys(%spareschg) > 0) {
16165: $changes{'spares'}{$lonhost} = \%spareschg;
16166: }
16167: }
1.261 raeburn 16168: $defaultshash{'usersessions'}{'offloadnow'} = {};
16169: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
16170: my @okoffload;
16171: if (@offloadnow) {
16172: foreach my $server (@offloadnow) {
16173: if (&Apache::lonnet::hostname($server) ne '') {
16174: unless (grep(/^\Q$server\E$/,@okoffload)) {
16175: push(@okoffload,$server);
16176: }
16177: }
16178: }
16179: if (@okoffload) {
16180: foreach my $lonhost (@okoffload) {
16181: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
16182: }
16183: }
16184: }
1.145 raeburn 16185: if (ref($domconfig{'usersessions'}) eq 'HASH') {
16186: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
16187: if (ref($changes{'spares'}) eq 'HASH') {
16188: if (keys(%{$changes{'spares'}}) > 0) {
16189: $savespares = 1;
16190: }
16191: }
16192: } else {
16193: $savespares = 1;
16194: }
1.261 raeburn 16195: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
16196: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
16197: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
16198: $changes{'offloadnow'} = 1;
16199: last;
16200: }
16201: }
16202: unless ($changes{'offloadnow'}) {
1.289 raeburn 16203: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
1.261 raeburn 16204: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
16205: $changes{'offloadnow'} = 1;
16206: last;
16207: }
16208: }
16209: }
16210: } elsif (@okoffload) {
16211: $changes{'offloadnow'} = 1;
16212: }
16213: } elsif (@okoffload) {
16214: $changes{'offloadnow'} = 1;
1.145 raeburn 16215: }
1.147 raeburn 16216: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
16217: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 16218: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16219: $dom);
16220: if ($putresult eq 'ok') {
16221: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
16222: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
16223: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
16224: }
16225: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
16226: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
16227: }
1.261 raeburn 16228: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
16229: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
16230: }
1.137 raeburn 16231: }
16232: my $cachetime = 24*60*60;
16233: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 16234: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 16235: if (ref($lastactref) eq 'HASH') {
16236: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 16237: $lastactref->{'usersessions'} = 1;
1.212 raeburn 16238: }
1.147 raeburn 16239: if (keys(%changes) > 0) {
16240: my %lt = &usersession_titles();
16241: $resulttext = &mt('Changes made:').'<ul>';
16242: foreach my $prefix (@prefixes) {
16243: if (ref($changes{$prefix}) eq 'HASH') {
16244: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
16245: if ($prefix eq 'spares') {
16246: if (ref($changes{$prefix}) eq 'HASH') {
16247: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
16248: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 16249: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 16250: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
16251: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 16252: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
16253: foreach my $type (@{$types{$prefix}}) {
16254: if ($changes{$prefix}{$lonhost}{$type}) {
16255: my $offloadto = &mt('None');
16256: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
16257: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
16258: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
16259: }
1.145 raeburn 16260: }
1.147 raeburn 16261: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 16262: }
1.137 raeburn 16263: }
16264: }
1.147 raeburn 16265: $resulttext .= '</li>';
1.137 raeburn 16266: }
16267: }
1.147 raeburn 16268: } else {
16269: foreach my $type (@{$types{$prefix}}) {
16270: if (defined($changes{$prefix}{$type})) {
16271: my $newvalue;
16272: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
16273: if (ref($defaultshash{'usersessions'}{$prefix})) {
16274: if ($type eq 'version') {
16275: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
16276: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
16277: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
16278: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
16279: }
1.145 raeburn 16280: }
16281: }
16282: }
1.147 raeburn 16283: if ($newvalue eq '') {
16284: if ($type eq 'version') {
16285: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
16286: } else {
16287: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
16288: }
1.145 raeburn 16289: } else {
1.147 raeburn 16290: if ($type eq 'version') {
16291: $newvalue .= ' '.&mt('(or later)');
16292: }
16293: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 16294: }
1.137 raeburn 16295: }
16296: }
16297: }
1.147 raeburn 16298: $resulttext .= '</ul>';
1.137 raeburn 16299: }
16300: }
1.261 raeburn 16301: if ($changes{'offloadnow'}) {
16302: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
16303: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
16304: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
16305: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
16306: $resulttext .= '<li>'.$lonhost.'</li>';
16307: }
16308: $resulttext .= '</ul>';
16309: } else {
16310: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
16311: }
16312: } else {
16313: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
16314: }
16315: }
1.147 raeburn 16316: $resulttext .= '</ul>';
16317: } else {
16318: $resulttext = $nochgmsg;
1.137 raeburn 16319: }
16320: } else {
16321: $resulttext = '<span class="LC_error">'.
16322: &mt('An error occurred: [_1]',$putresult).'</span>';
16323: }
16324: } else {
1.147 raeburn 16325: $resulttext = $nochgmsg;
1.137 raeburn 16326: }
16327: return $resulttext;
16328: }
16329:
1.275 raeburn 16330: sub modify_ssl {
16331: my ($dom,$lastactref,%domconfig) = @_;
16332: my (%by_ip,%by_location,@intdoms,@instdoms);
16333: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
16334: my @locations = sort(keys(%by_location));
16335: my %servers = &Apache::lonnet::internet_dom_servers($dom);
16336: my (%defaultshash,%changes);
16337: my $action = 'ssl';
1.293 raeburn 16338: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 16339: foreach my $prefix (@prefixes) {
16340: $defaultshash{$action}{$prefix} = {};
16341: }
16342: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16343: my $resulttext;
16344: my %iphost = &Apache::lonnet::get_iphost();
16345: my @reptypes = ('certreq','nocertreq');
16346: my @connecttypes = ('dom','intdom','other');
16347: my %types = (
1.293 raeburn 16348: connto => \@connecttypes,
16349: connfrom => \@connecttypes,
16350: replication => \@reptypes,
1.275 raeburn 16351: );
16352: foreach my $prefix (sort(keys(%types))) {
16353: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 16354: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 16355: my $value = 'yes';
16356: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
16357: $value = $env{'form.'.$prefix.'_'.$type};
16358: }
16359: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
16360: if ($domconfig{$action}{$prefix}{$type} ne '') {
16361: if ($value ne $domconfig{$action}{$prefix}{$type}) {
16362: $changes{$prefix}{$type} = 1;
16363: }
16364: $defaultshash{$action}{$prefix}{$type} = $value;
16365: } else {
16366: $defaultshash{$action}{$prefix}{$type} = $value;
16367: $changes{$prefix}{$type} = 1;
16368: }
16369: } else {
16370: $defaultshash{$action}{$prefix}{$type} = $value;
16371: $changes{$prefix}{$type} = 1;
16372: }
16373: if (($type eq 'dom') && (keys(%servers) == 1)) {
16374: delete($changes{$prefix}{$type});
16375: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
16376: delete($changes{$prefix}{$type});
16377: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
16378: delete($changes{$prefix}{$type});
16379: }
16380: } elsif ($prefix eq 'replication') {
16381: if (@locations > 0) {
16382: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16383: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16384: my @okvals;
16385: foreach my $val (@vals) {
16386: if ($val =~ /:/) {
16387: my @items = split(/:/,$val);
16388: foreach my $item (@items) {
16389: if (ref($by_location{$item}) eq 'ARRAY') {
16390: push(@okvals,$item);
16391: }
16392: }
16393: } else {
16394: if (ref($by_location{$val}) eq 'ARRAY') {
16395: push(@okvals,$val);
16396: }
16397: }
16398: }
16399: @okvals = sort(@okvals);
16400: if (ref($domconfig{$action}) eq 'HASH') {
16401: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
16402: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
16403: if ($inuse == 0) {
16404: $changes{$prefix}{$type} = 1;
16405: } else {
16406: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16407: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
16408: if (@changed > 0) {
16409: $changes{$prefix}{$type} = 1;
16410: }
16411: }
16412: } else {
16413: if ($inuse == 1) {
16414: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16415: $changes{$prefix}{$type} = 1;
16416: }
16417: }
16418: } else {
16419: if ($inuse == 1) {
16420: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16421: $changes{$prefix}{$type} = 1;
16422: }
16423: }
16424: } else {
16425: if ($inuse == 1) {
16426: $defaultshash{$action}{$prefix}{$type} = \@okvals;
16427: $changes{$prefix}{$type} = 1;
16428: }
16429: }
16430: }
16431: }
16432: }
16433: }
16434: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
16435: if (keys(%changes) > 0) {
16436: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16437: $dom);
16438: if ($putresult eq 'ok') {
16439: if (ref($defaultshash{$action}) eq 'HASH') {
16440: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
16441: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
16442: }
1.293 raeburn 16443: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
16444: $domdefaults{'connto'} = $domconfig{$action}{'connto'};
16445: }
16446: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
16447: $domdefaults{'connfrom'} = $domconfig{$action}{'connfrom'};
1.275 raeburn 16448: }
16449: }
16450: my $cachetime = 24*60*60;
16451: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16452: if (ref($lastactref) eq 'HASH') {
16453: $lastactref->{'domdefaults'} = 1;
16454: }
16455: if (keys(%changes) > 0) {
16456: my %titles = &ssl_titles();
16457: $resulttext = &mt('Changes made:').'<ul>';
16458: foreach my $prefix (@prefixes) {
16459: if (ref($changes{$prefix}) eq 'HASH') {
16460: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
16461: foreach my $type (@{$types{$prefix}}) {
16462: if (defined($changes{$prefix}{$type})) {
16463: my $newvalue;
16464: if (ref($defaultshash{$action}) eq 'HASH') {
16465: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 16466: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 16467: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
16468: } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
16469: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
16470: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
16471: }
16472: }
16473: }
16474: if ($newvalue eq '') {
16475: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
16476: } else {
16477: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
16478: }
16479: }
16480: }
16481: }
16482: $resulttext .= '</ul>';
16483: }
16484: }
16485: } else {
16486: $resulttext = $nochgmsg;
16487: }
16488: } else {
16489: $resulttext = '<span class="LC_error">'.
16490: &mt('An error occurred: [_1]',$putresult).'</span>';
16491: }
16492: } else {
16493: $resulttext = $nochgmsg;
16494: }
16495: return $resulttext;
16496: }
16497:
1.279 raeburn 16498: sub modify_trust {
16499: my ($dom,$lastactref,%domconfig) = @_;
16500: my (%by_ip,%by_location,@intdoms,@instdoms);
16501: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
16502: my @locations = sort(keys(%by_location));
16503: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
16504: my @types = ('exc','inc');
16505: my (%defaultshash,%changes);
16506: foreach my $prefix (@prefixes) {
16507: $defaultshash{'trust'}{$prefix} = {};
16508: }
16509: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16510: my $resulttext;
16511: foreach my $prefix (@prefixes) {
16512: foreach my $type (@types) {
16513: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
16514: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
16515: my @okvals;
16516: foreach my $val (@vals) {
16517: if ($val =~ /:/) {
16518: my @items = split(/:/,$val);
16519: foreach my $item (@items) {
16520: if (ref($by_location{$item}) eq 'ARRAY') {
16521: push(@okvals,$item);
16522: }
16523: }
16524: } else {
16525: if (ref($by_location{$val}) eq 'ARRAY') {
16526: push(@okvals,$val);
16527: }
16528: }
16529: }
16530: @okvals = sort(@okvals);
16531: if (ref($domconfig{'trust'}) eq 'HASH') {
16532: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
16533: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
16534: if ($inuse == 0) {
16535: $changes{$prefix}{$type} = 1;
16536: } else {
16537: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16538: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
16539: if (@changed > 0) {
16540: $changes{$prefix}{$type} = 1;
16541: }
16542: }
16543: } else {
16544: if ($inuse == 1) {
16545: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16546: $changes{$prefix}{$type} = 1;
16547: }
16548: }
16549: } else {
16550: if ($inuse == 1) {
16551: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16552: $changes{$prefix}{$type} = 1;
16553: }
16554: }
16555: } else {
16556: if ($inuse == 1) {
16557: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
16558: $changes{$prefix}{$type} = 1;
16559: }
16560: }
16561: }
16562: }
16563: my $nochgmsg = &mt('No changes made to trust settings.');
16564: if (keys(%changes) > 0) {
16565: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
16566: $dom);
16567: if ($putresult eq 'ok') {
16568: if (ref($defaultshash{'trust'}) eq 'HASH') {
16569: foreach my $prefix (@prefixes) {
16570: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
16571: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
16572: }
16573: }
16574: }
16575: my $cachetime = 24*60*60;
16576: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16577: if (ref($lastactref) eq 'HASH') {
16578: $lastactref->{'domdefaults'} = 1;
16579: }
16580: if (keys(%changes) > 0) {
16581: my %lt = &trust_titles();
16582: $resulttext = &mt('Changes made:').'<ul>';
16583: foreach my $prefix (@prefixes) {
16584: if (ref($changes{$prefix}) eq 'HASH') {
16585: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
16586: foreach my $type (@types) {
16587: if (defined($changes{$prefix}{$type})) {
16588: my $newvalue;
16589: if (ref($defaultshash{'trust'}) eq 'HASH') {
16590: if (ref($defaultshash{'trust'}{$prefix})) {
16591: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
16592: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
16593: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
16594: }
16595: }
16596: }
16597: }
16598: if ($newvalue eq '') {
16599: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
16600: } else {
16601: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
16602: }
16603: }
16604: }
16605: $resulttext .= '</ul>';
16606: }
16607: }
16608: $resulttext .= '</ul>';
16609: } else {
16610: $resulttext = $nochgmsg;
16611: }
16612: } else {
16613: $resulttext = '<span class="LC_error">'.
16614: &mt('An error occurred: [_1]',$putresult).'</span>';
16615: }
16616: } else {
16617: $resulttext = $nochgmsg;
16618: }
16619: return $resulttext;
16620: }
16621:
1.150 raeburn 16622: sub modify_loadbalancing {
16623: my ($dom,%domconfig) = @_;
16624: my $primary_id = &Apache::lonnet::domain($dom,'primary');
16625: my $intdom = &Apache::lonnet::internet_dom($primary_id);
16626: my ($othertitle,$usertypes,$types) =
16627: &Apache::loncommon::sorted_inst_types($dom);
16628: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 16629: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 16630: my @sparestypes = ('primary','default');
16631: my %typetitles = &sparestype_titles();
16632: my $resulttext;
1.171 raeburn 16633: my (%currbalancer,%currtargets,%currrules,%existing);
16634: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
16635: %existing = %{$domconfig{'loadbalancing'}};
16636: }
16637: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
16638: \%currtargets,\%currrules);
16639: my ($saveloadbalancing,%defaultshash,%changes);
16640: my ($alltypes,$othertypes,$titles) =
16641: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
16642: my %ruletitles = &offloadtype_text();
16643: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
16644: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
16645: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
16646: if ($balancer eq '') {
16647: next;
16648: }
1.210 raeburn 16649: if (!exists($servers{$balancer})) {
1.171 raeburn 16650: if (exists($currbalancer{$balancer})) {
16651: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 16652: }
1.171 raeburn 16653: next;
16654: }
16655: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
16656: push(@{$changes{'delete'}},$balancer);
16657: next;
16658: }
16659: if (!exists($currbalancer{$balancer})) {
16660: push(@{$changes{'add'}},$balancer);
16661: }
16662: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
16663: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
16664: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
16665: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
16666: $saveloadbalancing = 1;
16667: }
16668: foreach my $sparetype (@sparestypes) {
16669: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
16670: my @offloadto;
16671: foreach my $target (@targets) {
16672: if (($servers{$target}) && ($target ne $balancer)) {
16673: if ($sparetype eq 'default') {
16674: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
16675: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 16676: }
16677: }
1.171 raeburn 16678: unless(grep(/^\Q$target\E$/,@offloadto)) {
16679: push(@offloadto,$target);
16680: }
1.150 raeburn 16681: }
16682: }
1.284 raeburn 16683: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
16684: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
16685: push(@offloadto,$balancer);
16686: }
16687: }
16688: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 16689: }
1.171 raeburn 16690: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 16691: foreach my $sparetype (@sparestypes) {
1.171 raeburn 16692: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
16693: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 16694: if (@targetdiffs > 0) {
1.171 raeburn 16695: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 16696: }
1.171 raeburn 16697: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16698: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16699: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 16700: }
16701: }
16702: }
16703: } else {
1.171 raeburn 16704: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 16705: foreach my $sparetype (@sparestypes) {
1.171 raeburn 16706: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16707: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16708: $changes{'curr'}{$balancer}{'targets'} = 1;
16709: }
1.150 raeburn 16710: }
16711: }
1.210 raeburn 16712: }
1.150 raeburn 16713: }
16714: my $ishomedom;
1.171 raeburn 16715: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
16716: $ishomedom = 1;
1.150 raeburn 16717: }
16718: if (ref($alltypes) eq 'ARRAY') {
16719: foreach my $type (@{$alltypes}) {
16720: my $rule;
1.210 raeburn 16721: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 16722: (!$ishomedom)) {
1.171 raeburn 16723: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
16724: }
16725: if ($rule eq 'specific') {
1.255 raeburn 16726: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 16727: if (exists($servers{$specifiedhost})) {
1.255 raeburn 16728: $rule = $specifiedhost;
16729: }
1.150 raeburn 16730: }
1.171 raeburn 16731: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
16732: if (ref($currrules{$balancer}) eq 'HASH') {
16733: if ($rule ne $currrules{$balancer}{$type}) {
16734: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 16735: }
16736: } elsif ($rule ne '') {
1.171 raeburn 16737: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 16738: }
16739: }
16740: }
1.171 raeburn 16741: }
16742: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
16743: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
16744: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
16745: $defaultshash{'loadbalancing'} = {};
16746: }
16747: my $putresult = &Apache::lonnet::put_dom('configuration',
16748: \%defaultshash,$dom);
16749: if ($putresult eq 'ok') {
16750: if (keys(%changes) > 0) {
1.252 raeburn 16751: my %toupdate;
1.171 raeburn 16752: if (ref($changes{'delete'}) eq 'ARRAY') {
16753: foreach my $balancer (sort(@{$changes{'delete'}})) {
16754: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 16755: $toupdate{$balancer} = 1;
1.150 raeburn 16756: }
1.171 raeburn 16757: }
16758: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 16759: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 16760: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 16761: $toupdate{$balancer} = 1;
1.171 raeburn 16762: }
16763: }
16764: if (ref($changes{'curr'}) eq 'HASH') {
16765: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 16766: $toupdate{$balancer} = 1;
1.171 raeburn 16767: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
16768: if ($changes{'curr'}{$balancer}{'targets'}) {
16769: my %offloadstr;
16770: foreach my $sparetype (@sparestypes) {
16771: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16772: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
16773: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
16774: }
16775: }
1.150 raeburn 16776: }
1.171 raeburn 16777: if (keys(%offloadstr) == 0) {
16778: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 16779: } else {
1.171 raeburn 16780: my $showoffload;
16781: foreach my $sparetype (@sparestypes) {
16782: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
16783: if (defined($offloadstr{$sparetype})) {
16784: $showoffload .= $offloadstr{$sparetype};
16785: } else {
16786: $showoffload .= &mt('None');
16787: }
16788: $showoffload .= (' 'x3);
16789: }
16790: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 16791: }
16792: }
16793: }
1.171 raeburn 16794: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
16795: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
16796: foreach my $type (@{$alltypes}) {
16797: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
16798: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
16799: my $balancetext;
16800: if ($rule eq '') {
16801: $balancetext = $ruletitles{'default'};
1.209 raeburn 16802: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 16803: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 16804: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 16805: foreach my $sparetype (@sparestypes) {
16806: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
16807: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
16808: }
16809: }
1.253 raeburn 16810: foreach my $item (@{$alltypes}) {
16811: next if ($item =~ /^_LC_ipchange/);
16812: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
16813: if ($hasrule eq 'homeserver') {
16814: map { $toupdate{$_} = 1; } (keys(%libraryservers));
16815: } else {
16816: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
16817: if ($servers{$hasrule}) {
16818: $toupdate{$hasrule} = 1;
16819: }
16820: }
16821: }
16822: }
1.254 raeburn 16823: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
16824: $balancetext = $ruletitles{$rule};
16825: } else {
16826: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
16827: $balancetext = $ruletitles{'particular'}.' '.$receiver;
16828: if ($receiver) {
16829: $toupdate{$receiver};
16830: }
16831: }
16832: } else {
16833: $balancetext = $ruletitles{$rule};
1.252 raeburn 16834: }
1.171 raeburn 16835: } else {
16836: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
16837: }
1.210 raeburn 16838: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 16839: }
16840: }
16841: }
16842: }
1.252 raeburn 16843: if (keys(%toupdate)) {
16844: my %thismachine;
16845: my $updatedhere;
16846: my $cachetime = 60*60*24;
16847: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
16848: foreach my $lonhost (keys(%toupdate)) {
16849: if ($thismachine{$lonhost}) {
16850: unless ($updatedhere) {
16851: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
16852: $defaultshash{'loadbalancing'},
16853: $cachetime);
16854: $updatedhere = 1;
16855: }
16856: } else {
16857: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
16858: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
16859: }
16860: }
16861: }
1.150 raeburn 16862: }
1.171 raeburn 16863: }
16864: if ($resulttext ne '') {
16865: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 16866: } else {
16867: $resulttext = $nochgmsg;
16868: }
16869: } else {
1.171 raeburn 16870: $resulttext = $nochgmsg;
1.150 raeburn 16871: }
16872: } else {
1.171 raeburn 16873: $resulttext = '<span class="LC_error">'.
16874: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 16875: }
16876: } else {
1.171 raeburn 16877: $resulttext = $nochgmsg;
1.150 raeburn 16878: }
16879: return $resulttext;
16880: }
16881:
1.48 raeburn 16882: sub recurse_check {
16883: my ($chkcats,$categories,$depth,$name) = @_;
16884: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
16885: my $chg = 0;
16886: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
16887: my $category = $chkcats->[$depth]{$name}[$j];
16888: my $item;
16889: if ($category eq '') {
16890: $chg ++;
16891: } else {
16892: my $deeper = $depth + 1;
16893: $item = &escape($category).':'.&escape($name).':'.$depth;
16894: if ($chg) {
16895: $categories->{$item} -= $chg;
16896: }
16897: &recurse_check($chkcats,$categories,$deeper,$category);
16898: $deeper --;
16899: }
16900: }
16901: }
16902: return;
16903: }
16904:
16905: sub recurse_cat_deletes {
16906: my ($item,$coursecategories,$deletions) = @_;
16907: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
16908: my $subdepth = $depth + 1;
16909: if (ref($coursecategories) eq 'HASH') {
16910: foreach my $subitem (keys(%{$coursecategories})) {
16911: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
16912: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
16913: delete($coursecategories->{$subitem});
16914: $deletions->{$subitem} = 1;
16915: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 16916: }
1.48 raeburn 16917: }
16918: }
16919: return;
16920: }
16921:
1.125 raeburn 16922: sub active_dc_picker {
1.191 raeburn 16923: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 16924: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 16925: my @domcoord = keys(%domcoords);
16926: if (keys(%currhash)) {
16927: foreach my $dc (keys(%currhash)) {
16928: unless (exists($domcoords{$dc})) {
16929: push(@domcoord,$dc);
16930: }
16931: }
16932: }
16933: @domcoord = sort(@domcoord);
1.210 raeburn 16934: my $numdcs = scalar(@domcoord);
1.191 raeburn 16935: my $rows = 0;
16936: my $table;
1.125 raeburn 16937: if ($numdcs > 1) {
1.191 raeburn 16938: $table = '<table>';
16939: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 16940: my $rem = $i%($numinrow);
16941: if ($rem == 0) {
16942: if ($i > 0) {
1.191 raeburn 16943: $table .= '</tr>';
1.125 raeburn 16944: }
1.191 raeburn 16945: $table .= '<tr>';
16946: $rows ++;
1.125 raeburn 16947: }
1.191 raeburn 16948: my $check = '';
16949: if ($inputtype eq 'radio') {
16950: if (keys(%currhash) == 0) {
16951: if (!$i) {
16952: $check = ' checked="checked"';
16953: }
16954: } elsif (exists($currhash{$domcoord[$i]})) {
16955: $check = ' checked="checked"';
16956: }
16957: } else {
16958: if (exists($currhash{$domcoord[$i]})) {
16959: $check = ' checked="checked"';
1.125 raeburn 16960: }
16961: }
1.191 raeburn 16962: if ($i == @domcoord - 1) {
1.125 raeburn 16963: my $colsleft = $numinrow - $rem;
16964: if ($colsleft > 1) {
1.191 raeburn 16965: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 16966: } else {
1.191 raeburn 16967: $table .= '<td class="LC_left_item">';
1.125 raeburn 16968: }
16969: } else {
1.191 raeburn 16970: $table .= '<td class="LC_left_item">';
16971: }
16972: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
16973: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
16974: $table .= '<span class="LC_nobreak"><label>'.
16975: '<input type="'.$inputtype.'" name="'.$name.'"'.
16976: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
16977: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 16978: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 16979: }
1.219 raeburn 16980: $table .= '</label></span></td>';
1.191 raeburn 16981: }
16982: $table .= '</tr></table>';
16983: } elsif ($numdcs == 1) {
1.219 raeburn 16984: my ($dcname,$dcdom) = split(':',$domcoord[0]);
16985: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 16986: if ($inputtype eq 'radio') {
1.247 raeburn 16987: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 16988: if ($user ne $dcname.':'.$dcdom) {
16989: $table .= ' ('.$dcname.':'.$dcdom.')';
16990: }
1.191 raeburn 16991: } else {
16992: my $check;
16993: if (exists($currhash{$domcoord[0]})) {
16994: $check = ' checked="checked"';
1.125 raeburn 16995: }
1.247 raeburn 16996: $table = '<span class="LC_nobreak"><label>'.
16997: '<input type="checkbox" name="'.$name.'" '.
16998: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 16999: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 17000: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 17001: }
1.220 raeburn 17002: $table .= '</label></span>';
1.191 raeburn 17003: $rows ++;
1.125 raeburn 17004: }
17005: }
1.191 raeburn 17006: return ($numdcs,$table,$rows);
1.125 raeburn 17007: }
17008:
1.137 raeburn 17009: sub usersession_titles {
17010: return &Apache::lonlocal::texthash(
17011: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
17012: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 17013: spares => 'Servers offloaded to, when busy',
1.137 raeburn 17014: version => 'LON-CAPA version requirement',
1.138 raeburn 17015: excludedomain => 'Allow all, but exclude specific domains',
17016: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 17017: primary => 'Primary (checked first)',
1.154 raeburn 17018: default => 'Default',
1.137 raeburn 17019: );
17020: }
17021:
1.152 raeburn 17022: sub id_for_thisdom {
17023: my (%servers) = @_;
17024: my %altids;
17025: foreach my $server (keys(%servers)) {
17026: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
17027: if ($serverhome ne $server) {
17028: $altids{$serverhome} = $server;
17029: }
17030: }
17031: return %altids;
17032: }
17033:
1.150 raeburn 17034: sub count_servers {
17035: my ($currbalancer,%servers) = @_;
17036: my (@spares,$numspares);
17037: foreach my $lonhost (sort(keys(%servers))) {
17038: next if ($currbalancer eq $lonhost);
17039: push(@spares,$lonhost);
17040: }
17041: if ($currbalancer) {
17042: $numspares = scalar(@spares);
17043: } else {
17044: $numspares = scalar(@spares) - 1;
17045: }
17046: return ($numspares,@spares);
17047: }
17048:
17049: sub lonbalance_targets_js {
1.171 raeburn 17050: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 17051: my $select = &mt('Select');
17052: my ($alltargets,$allishome,$allinsttypes,@alltypes);
17053: if (ref($servers) eq 'HASH') {
17054: $alltargets = join("','",sort(keys(%{$servers})));
17055: my @homedoms;
17056: foreach my $server (sort(keys(%{$servers}))) {
17057: if (&Apache::lonnet::host_domain($server) eq $dom) {
17058: push(@homedoms,'1');
17059: } else {
17060: push(@homedoms,'0');
17061: }
17062: }
17063: $allishome = join("','",@homedoms);
17064: }
17065: if (ref($types) eq 'ARRAY') {
17066: if (@{$types} > 0) {
17067: @alltypes = @{$types};
17068: }
17069: }
17070: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
17071: $allinsttypes = join("','",@alltypes);
1.171 raeburn 17072: my (%currbalancer,%currtargets,%currrules,%existing);
17073: if (ref($settings) eq 'HASH') {
17074: %existing = %{$settings};
17075: }
17076: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
17077: \%currtargets,\%currrules);
1.210 raeburn 17078: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 17079: return <<"END";
17080:
17081: <script type="text/javascript">
17082: // <![CDATA[
17083:
1.171 raeburn 17084: currBalancers = new Array('$balancers');
17085:
17086: function toggleTargets(balnum) {
17087: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
17088: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
17089: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
17090: var prevbalancer = prevhostitem.value;
17091: var baltotal = document.getElementById('loadbalancing_total').value;
17092: prevhostitem.value = balancer;
17093: if (prevbalancer != '') {
17094: var prevIdx = currBalancers.indexOf(prevbalancer);
17095: if (prevIdx != -1) {
17096: currBalancers.splice(prevIdx,1);
17097: }
17098: }
1.150 raeburn 17099: if (balancer == '') {
1.171 raeburn 17100: hideSpares(balnum);
1.150 raeburn 17101: } else {
1.171 raeburn 17102: var currIdx = currBalancers.indexOf(balancer);
17103: if (currIdx == -1) {
17104: currBalancers.push(balancer);
17105: }
1.150 raeburn 17106: var homedoms = new Array('$allishome');
1.171 raeburn 17107: var ishomedom = homedoms[lonhostitem.selectedIndex];
17108: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 17109: }
1.171 raeburn 17110: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 17111: return;
17112: }
17113:
1.171 raeburn 17114: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 17115: var alltargets = new Array('$alltargets');
17116: var insttypes = new Array('$allinsttypes');
1.151 raeburn 17117: var offloadtypes = new Array('primary','default');
17118:
1.171 raeburn 17119: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
17120: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 17121:
1.151 raeburn 17122: for (var i=0; i<offloadtypes.length; i++) {
17123: var count = 0;
17124: for (var j=0; j<alltargets.length; j++) {
17125: if (alltargets[j] != balancer) {
1.171 raeburn 17126: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
17127: item.value = alltargets[j];
17128: item.style.textAlign='left';
17129: item.style.textFace='normal';
17130: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
17131: if (currBalancers.indexOf(alltargets[j]) == -1) {
17132: item.disabled = '';
17133: } else {
17134: item.disabled = 'disabled';
17135: item.checked = false;
17136: }
1.151 raeburn 17137: count ++;
17138: }
1.150 raeburn 17139: }
17140: }
1.151 raeburn 17141: for (var k=0; k<insttypes.length; k++) {
17142: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 17143: if (ishomedom == 1) {
1.171 raeburn 17144: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
17145: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 17146: } else {
1.171 raeburn 17147: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
17148: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 17149: }
17150: } else {
1.171 raeburn 17151: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
17152: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 17153: }
1.151 raeburn 17154: if ((insttypes[k] != '_LC_external') &&
17155: ((insttypes[k] != '_LC_internetdom') ||
17156: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 17157: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
17158: item.options.length = 0;
17159: item.options[0] = new Option("","",true,true);
1.210 raeburn 17160: var idx = 0;
1.151 raeburn 17161: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 17162: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
17163: idx ++;
17164: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 17165: }
17166: }
17167: }
17168: }
17169: return;
17170: }
17171:
1.171 raeburn 17172: function hideSpares(balnum) {
1.150 raeburn 17173: var alltargets = new Array('$alltargets');
17174: var insttypes = new Array('$allinsttypes');
17175: var offloadtypes = new Array('primary','default');
17176:
1.171 raeburn 17177: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
17178: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 17179:
17180: var total = alltargets.length - 1;
17181: for (var i=0; i<offloadtypes; i++) {
17182: for (var j=0; j<total; j++) {
1.171 raeburn 17183: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
17184: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
17185: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 17186: }
1.150 raeburn 17187: }
17188: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 17189: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
17190: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 17191: if (insttypes[k] != '_LC_external') {
1.171 raeburn 17192: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
17193: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 17194: }
17195: }
17196: return;
17197: }
17198:
1.171 raeburn 17199: function checkOffloads(item,balnum,type) {
1.150 raeburn 17200: var alltargets = new Array('$alltargets');
17201: var offloadtypes = new Array('primary','default');
17202: if (item.checked) {
17203: var total = alltargets.length - 1;
17204: var other;
17205: if (type == offloadtypes[0]) {
1.151 raeburn 17206: other = offloadtypes[1];
1.150 raeburn 17207: } else {
1.151 raeburn 17208: other = offloadtypes[0];
1.150 raeburn 17209: }
17210: for (var i=0; i<total; i++) {
1.171 raeburn 17211: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 17212: if (server == item.value) {
1.171 raeburn 17213: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
17214: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 17215: }
17216: }
17217: }
17218: }
17219: return;
17220: }
17221:
1.171 raeburn 17222: function singleServerToggle(balnum,type) {
17223: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 17224: if (offloadtoSelIdx == 0) {
1.171 raeburn 17225: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
17226: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 17227:
17228: } else {
1.171 raeburn 17229: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
17230: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 17231: }
17232: return;
17233: }
17234:
1.171 raeburn 17235: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 17236: if (type == '_LC_external') {
1.171 raeburn 17237: return;
1.150 raeburn 17238: }
1.171 raeburn 17239: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 17240: for (var i=0; i<typesRules.length; i++) {
17241: if (formname.elements[typesRules[i]].checked) {
17242: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 17243: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
17244: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 17245: } else {
1.171 raeburn 17246: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
17247: }
17248: }
17249: }
17250: return;
17251: }
17252:
17253: function balancerDeleteChange(balnum) {
17254: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
17255: var baltotal = document.getElementById('loadbalancing_total').value;
17256: var addtarget;
17257: var removetarget;
17258: var action = 'delete';
17259: if (document.getElementById('loadbalancing_delete_'+balnum)) {
17260: var lonhost = hostitem.value;
17261: var currIdx = currBalancers.indexOf(lonhost);
17262: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
17263: if (currIdx != -1) {
17264: currBalancers.splice(currIdx,1);
17265: }
17266: addtarget = lonhost;
17267: } else {
17268: if (currIdx == -1) {
17269: currBalancers.push(lonhost);
17270: }
17271: removetarget = lonhost;
17272: action = 'undelete';
17273: }
17274: balancerChange(balnum,baltotal,action,addtarget,removetarget);
17275: }
17276: return;
17277: }
17278:
17279: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
17280: if (baltotal > 1) {
17281: var offloadtypes = new Array('primary','default');
17282: var alltargets = new Array('$alltargets');
17283: var insttypes = new Array('$allinsttypes');
17284: for (var i=0; i<baltotal; i++) {
17285: if (i != balnum) {
17286: for (var j=0; j<offloadtypes.length; j++) {
17287: var total = alltargets.length - 1;
17288: for (var k=0; k<total; k++) {
17289: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
17290: var server = serveritem.value;
17291: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
17292: if (server == addtarget) {
17293: serveritem.disabled = '';
17294: }
17295: }
17296: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
17297: if (server == removetarget) {
17298: serveritem.disabled = 'disabled';
17299: serveritem.checked = false;
17300: }
17301: }
17302: }
17303: }
17304: for (var j=0; j<insttypes.length; j++) {
17305: if (insttypes[j] != '_LC_external') {
17306: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
17307: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
17308: var currSel = singleserver.selectedIndex;
17309: var currVal = singleserver.options[currSel].value;
17310: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
17311: var numoptions = singleserver.options.length;
17312: var needsnew = 1;
17313: for (var k=0; k<numoptions; k++) {
17314: if (singleserver.options[k] == addtarget) {
17315: needsnew = 0;
17316: break;
17317: }
17318: }
17319: if (needsnew == 1) {
17320: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
17321: }
17322: }
17323: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
17324: singleserver.options.length = 0;
17325: if ((currVal) && (currVal != removetarget)) {
17326: singleserver.options[0] = new Option("","",false,false);
17327: } else {
17328: singleserver.options[0] = new Option("","",true,true);
17329: }
17330: var idx = 0;
17331: for (var m=0; m<alltargets.length; m++) {
17332: if (currBalancers.indexOf(alltargets[m]) == -1) {
17333: idx ++;
17334: if (currVal == alltargets[m]) {
17335: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
17336: } else {
17337: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
17338: }
17339: }
17340: }
17341: }
17342: }
17343: }
17344: }
1.150 raeburn 17345: }
17346: }
17347: }
17348: return;
17349: }
17350:
1.152 raeburn 17351: // ]]>
17352: </script>
17353:
17354: END
17355: }
17356:
17357: sub new_spares_js {
17358: my @sparestypes = ('primary','default');
17359: my $types = join("','",@sparestypes);
17360: my $select = &mt('Select');
17361: return <<"END";
17362:
17363: <script type="text/javascript">
17364: // <![CDATA[
17365:
17366: function updateNewSpares(formname,lonhost) {
17367: var types = new Array('$types');
17368: var include = new Array();
17369: var exclude = new Array();
17370: for (var i=0; i<types.length; i++) {
17371: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
17372: for (var j=0; j<spareboxes.length; j++) {
17373: if (formname.elements[spareboxes[j]].checked) {
17374: exclude.push(formname.elements[spareboxes[j]].value);
17375: } else {
17376: include.push(formname.elements[spareboxes[j]].value);
17377: }
17378: }
17379: }
17380: for (var i=0; i<types.length; i++) {
17381: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
17382: var selIdx = newSpare.selectedIndex;
17383: var currnew = newSpare.options[selIdx].value;
17384: var okSpares = new Array();
17385: for (var j=0; j<newSpare.options.length; j++) {
17386: var possible = newSpare.options[j].value;
17387: if (possible != '') {
17388: if (exclude.indexOf(possible) == -1) {
17389: okSpares.push(possible);
17390: } else {
17391: if (currnew == possible) {
17392: selIdx = 0;
17393: }
17394: }
17395: }
17396: }
17397: for (var k=0; k<include.length; k++) {
17398: if (okSpares.indexOf(include[k]) == -1) {
17399: okSpares.push(include[k]);
17400: }
17401: }
17402: okSpares.sort();
17403: newSpare.options.length = 0;
17404: if (selIdx == 0) {
17405: newSpare.options[0] = new Option("$select","",true,true);
17406: } else {
17407: newSpare.options[0] = new Option("$select","",false,false);
17408: }
17409: for (var m=0; m<okSpares.length; m++) {
17410: var idx = m+1;
17411: var selThis = 0;
17412: if (selIdx != 0) {
17413: if (okSpares[m] == currnew) {
17414: selThis = 1;
17415: }
17416: }
17417: if (selThis == 1) {
17418: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
17419: } else {
17420: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
17421: }
17422: }
17423: }
17424: return;
17425: }
17426:
17427: function checkNewSpares(lonhost,type) {
17428: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
17429: var chosen = newSpare.options[newSpare.selectedIndex].value;
17430: if (chosen != '') {
17431: var othertype;
17432: var othernewSpare;
17433: if (type == 'primary') {
17434: othernewSpare = document.getElementById('newspare_default_'+lonhost);
17435: }
17436: if (type == 'default') {
17437: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
17438: }
17439: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
17440: othernewSpare.selectedIndex = 0;
17441: }
17442: }
17443: return;
17444: }
17445:
17446: // ]]>
17447: </script>
17448:
17449: END
17450:
17451: }
17452:
17453: sub common_domprefs_js {
17454: return <<"END";
17455:
17456: <script type="text/javascript">
17457: // <![CDATA[
17458:
1.150 raeburn 17459: function getIndicesByName(formname,item) {
1.152 raeburn 17460: var group = new Array();
1.150 raeburn 17461: for (var i=0;i<formname.elements.length;i++) {
17462: if (formname.elements[i].name == item) {
1.152 raeburn 17463: group.push(formname.elements[i].id);
1.150 raeburn 17464: }
17465: }
1.152 raeburn 17466: return group;
1.150 raeburn 17467: }
17468:
17469: // ]]>
17470: </script>
17471:
17472: END
1.152 raeburn 17473:
1.150 raeburn 17474: }
17475:
1.165 raeburn 17476: sub recaptcha_js {
17477: my %lt = &captcha_phrases();
17478: return <<"END";
17479:
17480: <script type="text/javascript">
17481: // <![CDATA[
17482:
17483: function updateCaptcha(caller,context) {
17484: var privitem;
17485: var pubitem;
17486: var privtext;
17487: var pubtext;
1.269 raeburn 17488: var versionitem;
17489: var versiontext;
1.165 raeburn 17490: if (document.getElementById(context+'_recaptchapub')) {
17491: pubitem = document.getElementById(context+'_recaptchapub');
17492: } else {
17493: return;
17494: }
17495: if (document.getElementById(context+'_recaptchapriv')) {
17496: privitem = document.getElementById(context+'_recaptchapriv');
17497: } else {
17498: return;
17499: }
17500: if (document.getElementById(context+'_recaptchapubtxt')) {
17501: pubtext = document.getElementById(context+'_recaptchapubtxt');
17502: } else {
17503: return;
17504: }
17505: if (document.getElementById(context+'_recaptchaprivtxt')) {
17506: privtext = document.getElementById(context+'_recaptchaprivtxt');
17507: } else {
17508: return;
17509: }
1.269 raeburn 17510: if (document.getElementById(context+'_recaptchaversion')) {
17511: versionitem = document.getElementById(context+'_recaptchaversion');
17512: } else {
17513: return;
17514: }
17515: if (document.getElementById(context+'_recaptchavertxt')) {
17516: versiontext = document.getElementById(context+'_recaptchavertxt');
17517: } else {
17518: return;
17519: }
1.165 raeburn 17520: if (caller.checked) {
17521: if (caller.value == 'recaptcha') {
17522: pubitem.type = 'text';
17523: privitem.type = 'text';
17524: pubitem.size = '40';
17525: privitem.size = '40';
17526: pubtext.innerHTML = "$lt{'pub'}";
17527: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 17528: versionitem.type = 'text';
17529: versionitem.size = '3';
1.289 raeburn 17530: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 17531: } else {
17532: pubitem.type = 'hidden';
17533: privitem.type = 'hidden';
1.269 raeburn 17534: versionitem.type = 'hidden';
1.165 raeburn 17535: pubtext.innerHTML = '';
17536: privtext.innerHTML = '';
1.269 raeburn 17537: versiontext.innerHTML = '';
1.165 raeburn 17538: }
17539: }
17540: return;
17541: }
17542:
17543: // ]]>
17544: </script>
17545:
17546: END
17547:
17548: }
17549:
1.236 raeburn 17550: sub toggle_display_js {
1.192 raeburn 17551: return <<"END";
17552:
17553: <script type="text/javascript">
17554: // <![CDATA[
17555:
1.236 raeburn 17556: function toggleDisplay(domForm,caller) {
17557: if (document.getElementById(caller)) {
17558: var divitem = document.getElementById(caller);
17559: var optionsElement = domForm.coursecredits;
1.264 raeburn 17560: var checkval = 1;
17561: var dispval = 'block';
1.303 raeburn 17562: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 17563: if (caller == 'emailoptions') {
17564: optionsElement = domForm.cancreate_email;
17565: }
1.257 raeburn 17566: if (caller == 'studentsubmission') {
17567: optionsElement = domForm.postsubmit;
17568: }
1.264 raeburn 17569: if (caller == 'cloneinstcode') {
17570: optionsElement = domForm.canclone;
17571: checkval = 'instcode';
17572: }
1.303 raeburn 17573: if (selfcreateRegExp.test(caller)) {
17574: optionsElement = domForm.elements[caller];
17575: checkval = 'other';
17576: dispval = 'inline'
17577: }
1.236 raeburn 17578: if (optionsElement.length) {
1.192 raeburn 17579: var currval;
1.236 raeburn 17580: for (var i=0; i<optionsElement.length; i++) {
17581: if (optionsElement[i].checked) {
17582: currval = optionsElement[i].value;
1.192 raeburn 17583: }
17584: }
1.264 raeburn 17585: if (currval == checkval) {
17586: divitem.style.display = dispval;
1.192 raeburn 17587: } else {
1.236 raeburn 17588: divitem.style.display = 'none';
1.192 raeburn 17589: }
17590: }
17591: }
17592: return;
17593: }
17594:
17595: // ]]>
17596: </script>
17597:
17598: END
17599:
17600: }
17601:
1.165 raeburn 17602: sub captcha_phrases {
17603: return &Apache::lonlocal::texthash (
17604: priv => 'Private key',
17605: pub => 'Public key',
17606: original => 'original (CAPTCHA)',
17607: recaptcha => 'successor (ReCAPTCHA)',
17608: notused => 'unused',
1.289 raeburn 17609: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 17610: );
17611: }
17612:
1.205 raeburn 17613: sub devalidate_remote_domconfs {
1.212 raeburn 17614: my ($dom,$cachekeys) = @_;
17615: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 17616: my %servers = &Apache::lonnet::internet_dom_servers($dom);
17617: my %thismachine;
17618: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.295 raeburn 17619: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions','directorysrch');
1.260 raeburn 17620: if (keys(%servers)) {
1.205 raeburn 17621: foreach my $server (keys(%servers)) {
17622: next if ($thismachine{$server});
1.212 raeburn 17623: my @cached;
17624: foreach my $name (@posscached) {
17625: if ($cachekeys->{$name}) {
17626: push(@cached,&escape($name).':'.&escape($dom));
17627: }
17628: }
17629: if (@cached) {
17630: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
17631: }
1.205 raeburn 17632: }
17633: }
17634: return;
17635: }
17636:
1.3 raeburn 17637: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>